@ensocode/server 0.3.5 → 0.3.6

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 (163) hide show
  1. package/out/phone/assets/{abnfDiagram-VCTEODGH-k76opPl1.js → abnfDiagram-VCTEODGH-CcwMwkZ2.js} +1 -1
  2. package/out/phone/assets/architecture-7GRP2DOG-K5Dyn6vg.js +1 -0
  3. package/out/phone/assets/{architectureDiagram-5GKGNRK7-yxQH9IuZ.js → architectureDiagram-5GKGNRK7-C4vXoVVW.js} +1 -1
  4. package/out/phone/assets/{blockDiagram-I7D4REHJ-DoHteZpO.js → blockDiagram-I7D4REHJ-btZonF7x.js} +1 -1
  5. package/out/phone/assets/{c4Diagram-7LVT6UL2-DQVO6L4q.js → c4Diagram-7LVT6UL2-wbgQC5h_.js} +1 -1
  6. package/out/phone/assets/channel-C0dO6zWg.js +1 -0
  7. package/out/phone/assets/{chunk-4HAMMTFA-N9Rw4SGW.js → chunk-4HAMMTFA-ClL6ufY7.js} +1 -1
  8. package/out/phone/assets/{chunk-75Z2AOVW-DKJ8pOxp.js → chunk-75Z2AOVW-CsGKueom.js} +1 -1
  9. package/out/phone/assets/{chunk-DU6HZSFF-BqGW8Nbd.js → chunk-DU6HZSFF-BOrl8wD9.js} +1 -1
  10. package/out/phone/assets/{chunk-F27PBJKO-PkFmkghF.js → chunk-F27PBJKO-CQYtYMPT.js} +1 -1
  11. package/out/phone/assets/{chunk-GMAD6QVW-C9VeD3Jk.js → chunk-GMAD6QVW-D2uUUIys.js} +1 -1
  12. package/out/phone/assets/{chunk-GVQU2GXP-COhntOeE.js → chunk-GVQU2GXP-k4NEAgCW.js} +1 -1
  13. package/out/phone/assets/{chunk-IMKFNOWR-B87ghLVD.js → chunk-IMKFNOWR-DGBKnQoB.js} +1 -1
  14. package/out/phone/assets/{chunk-L3NEJ4N5-C3N2izjg.js → chunk-L3NEJ4N5-BrOC_Q4h.js} +1 -1
  15. package/out/phone/assets/{chunk-OSK3NFVY-DaAlvVhz.js → chunk-OSK3NFVY-Cpg-5-0Y.js} +1 -1
  16. package/out/phone/assets/{chunk-P2QGCYS3-BQpKr8IZ.js → chunk-P2QGCYS3-Cwbos3wS.js} +1 -1
  17. package/out/phone/assets/{chunk-POPQ4Y6H-B2TZMY6U.js → chunk-POPQ4Y6H-CtPqYixr.js} +1 -1
  18. package/out/phone/assets/{chunk-PWAF6VOD-CgRhpUJy.js → chunk-PWAF6VOD-HDvh5SEv.js} +1 -1
  19. package/out/phone/assets/{chunk-SHT3W25Y-BySMFA99.js → chunk-SHT3W25Y-DKgmKLLr.js} +1 -1
  20. package/out/phone/assets/{chunk-SVP7TREG-EDGanDUX.js → chunk-SVP7TREG-DLVIWYD0.js} +1 -1
  21. package/out/phone/assets/{chunk-TICWLB2K-BtCZ8R2k.js → chunk-TICWLB2K-DzvrdWmw.js} +1 -1
  22. package/out/phone/assets/classDiagram-ZZMXUADV-CWPX0UEe.js +1 -0
  23. package/out/phone/assets/classDiagram-v2-VYDZK3BY-CWPX0UEe.js +1 -0
  24. package/out/phone/assets/{cynefin-OW5HDTMX-CdZmp44V.js → cynefin-OW5HDTMX-Cx32WN9e.js} +1 -1
  25. package/out/phone/assets/{cynefinDiagram-5FMLGOSQ-BCz9KwUb.js → cynefinDiagram-5FMLGOSQ-k3jOnfBl.js} +1 -1
  26. package/out/phone/assets/{dagre-GXQ25YYZ-CgFeNgh6.js → dagre-GXQ25YYZ-CTEzzJig.js} +1 -1
  27. package/out/phone/assets/{desk-C_b7mE6l.js → desk-9dPB4fYu.js} +1 -1
  28. package/out/phone/assets/{diagram-S7CK7UJ4-CwvaZIBf.js → diagram-S7CK7UJ4-BpfiB5rc.js} +1 -1
  29. package/out/phone/assets/{diagram-UQ7AKVKN-DqnD4XoZ.js → diagram-UQ7AKVKN-BpJj6V2i.js} +1 -1
  30. package/out/phone/assets/{diagram-VSXAHHWV-Kqc9GudQ.js → diagram-VSXAHHWV-BXTUks5P.js} +1 -1
  31. package/out/phone/assets/{diagram-VX7I27RA-B_0DLDQ0.js → diagram-VX7I27RA-BGaGiVKW.js} +1 -1
  32. package/out/phone/assets/{diagram-Z3DM3KII-CppKBEPW.js → diagram-Z3DM3KII-DhtDyIq2.js} +1 -1
  33. package/out/phone/assets/{ebnfDiagram-PWID7BFC-DeYPNCu9.js → ebnfDiagram-PWID7BFC-TUM8eXrc.js} +1 -1
  34. package/out/phone/assets/{erDiagram-RLTQ6QDP-MsfxDUmk.js → erDiagram-RLTQ6QDP-DqLrmkHj.js} +1 -1
  35. package/out/phone/assets/eventmodeling-NTZA5JFV-_H7VbKRu.js +1 -0
  36. package/out/phone/assets/flowDiagram-HODETNUW-HeI2O8Jm.js +1 -0
  37. package/out/phone/assets/{ganttDiagram-EL5Y4UJY-DaScS1os.js → ganttDiagram-EL5Y4UJY-Bfx_3wSL.js} +1 -1
  38. package/out/phone/assets/{gitGraph-4MIJSDKK-C-FzqpZm.js → gitGraph-4MIJSDKK-BByrtu13.js} +1 -1
  39. package/out/phone/assets/{gitGraphDiagram-WWUBYQGX-4Yv-hAwf.js → gitGraphDiagram-WWUBYQGX-DX-_HrkV.js} +1 -1
  40. package/out/phone/assets/{info-A6RAGUB7-CGLEP4t7.js → info-A6RAGUB7-B9AtEuqS.js} +1 -1
  41. package/out/phone/assets/{infoDiagram-27XIBGKW-DapEgYQa.js → infoDiagram-27XIBGKW-BlTJ4y54.js} +1 -1
  42. package/out/phone/assets/{ishikawaDiagram-5VMMS53U-D1B2lZSG.js → ishikawaDiagram-5VMMS53U-W8zt5UiH.js} +1 -1
  43. package/out/phone/assets/{journeyDiagram-3NMN7TZE-BSAtMVJw.js → journeyDiagram-3NMN7TZE-ClJSjx26.js} +1 -1
  44. package/out/phone/assets/{kanban-definition-UXKFOSKX-CfZ4oI7A.js → kanban-definition-UXKFOSKX-BPyXsdoL.js} +1 -1
  45. package/out/phone/assets/{line-DAXmUM4p.js → line-DMsvqHhd.js} +1 -1
  46. package/out/phone/assets/{main-B0yD1pMI.js → main-QdYtohlX.js} +4 -4
  47. package/out/phone/assets/{mermaid-parser.core-IObm7oM0.js → mermaid-parser.core-BteiwAAk.js} +3 -3
  48. package/out/phone/assets/{mermaid.core-C1wA-mhD.js → mermaid.core-BLIwkLpP.js} +4 -4
  49. package/out/phone/assets/{mindmap-definition-YA3MSWOX-3ph0EaB9.js → mindmap-definition-YA3MSWOX-CtvOuG70.js} +1 -1
  50. package/out/phone/assets/{packet-AYTQ26CC-BbDAe9Au.js → packet-AYTQ26CC-D9BlJkYf.js} +1 -1
  51. package/out/phone/assets/{pegDiagram-XKGWAZYB-EsuDcX_3.js → pegDiagram-XKGWAZYB-BCIWH2f6.js} +1 -1
  52. package/out/phone/assets/{pie-WAS4IAKB-BQfIj1fu.js → pie-WAS4IAKB-no-EBGVU.js} +1 -1
  53. package/out/phone/assets/{pieDiagram-E7YTZNPT-Cw19z5Ip.js → pieDiagram-E7YTZNPT-CSjCYWAz.js} +1 -1
  54. package/out/phone/assets/{quadrantDiagram-AXDQQJYC-Bqwz_sa8.js → quadrantDiagram-AXDQQJYC-Bh1Jh1q-.js} +1 -1
  55. package/out/phone/assets/{radar-RG4KPBEZ-Dmp-89iD.js → radar-RG4KPBEZ-BVweBCte.js} +1 -1
  56. package/out/phone/assets/{railroad-74A4TZTK-dq2H8w8Y.js → railroad-74A4TZTK-kUK_6AdA.js} +1 -1
  57. package/out/phone/assets/railroad-abnf-HS5TGJTU-Df9jtRyX.js +1 -0
  58. package/out/phone/assets/railroad-ebnf-LZEXJU2U-vjjsvYjl.js +1 -0
  59. package/out/phone/assets/railroad-peg-WCYAUIDC-DrKQG8aR.js +1 -0
  60. package/out/phone/assets/{railroadDiagram-O6MQD6OU-D2Sbc7Wn.js → railroadDiagram-O6MQD6OU-DDKZuEH9.js} +1 -1
  61. package/out/phone/assets/{requirementDiagram-BXWQKSXE-CLNUqxbl.js → requirementDiagram-BXWQKSXE-BAdrpp8Z.js} +1 -1
  62. package/out/phone/assets/{sankeyDiagram-P5KCCOFB-Dme5iwcw.js → sankeyDiagram-P5KCCOFB-Dm0dmnQJ.js} +1 -1
  63. package/out/phone/assets/{sequenceDiagram-WJ2MYXX4-C5dYSwPE.js → sequenceDiagram-WJ2MYXX4-DtN1lgR9.js} +1 -1
  64. package/out/phone/assets/{stateDiagram-D77RDMKH-BuxkPvJ6.js → stateDiagram-D77RDMKH-m5U6QGoM.js} +1 -1
  65. package/out/phone/assets/stateDiagram-v2-MP3YSRHH-g06bNGjI.js +1 -0
  66. package/out/phone/assets/{swimlanes-42K2YHIH-DHyXnytv.js → swimlanes-42K2YHIH-jWtOgaZK.js} +1 -1
  67. package/out/phone/assets/swimlanesDiagram-VR7AAH4N-CwlfCnnJ.js +8 -0
  68. package/out/phone/assets/{timeline-definition-24CTP7MA-Bm8Z0u2Z.js → timeline-definition-24CTP7MA-CncsPQSQ.js} +1 -1
  69. package/out/phone/assets/{treeView-Q6P3EWNA-DFUxvDDO.js → treeView-Q6P3EWNA-BNIDY5fM.js} +1 -1
  70. package/out/phone/assets/{treemap-WGGIJYW6-CMC-hwzt.js → treemap-WGGIJYW6-FkDWRKqS.js} +1 -1
  71. package/out/phone/assets/{vennDiagram-4TSXK5OY-CNL4gZsd.js → vennDiagram-4TSXK5OY-CeyTscuj.js} +1 -1
  72. package/out/phone/assets/{wardley-WFR3VGLG-CHQoq9KJ.js → wardley-WFR3VGLG-CEuN_S8l.js} +1 -1
  73. package/out/phone/assets/{wardleyDiagram-VM6X3IG4-DAuBfK1O.js → wardleyDiagram-VM6X3IG4-DE3tgI7J.js} +1 -1
  74. package/out/phone/assets/{xychartDiagram-S5SC5T6Z-B2T9ECKd.js → xychartDiagram-S5SC5T6Z-Di64LYy0.js} +1 -1
  75. package/out/phone/desk.html +1 -1
  76. package/out/phone/index.html +1 -1
  77. package/out/renderer/assets/{abnfDiagram-VCTEODGH-gdhrQbX6.js → abnfDiagram-VCTEODGH-B7uu_Gw1.js} +1 -1
  78. package/out/renderer/assets/{arc-D6-Q4l2d.js → arc-CkW2-Pr7.js} +1 -1
  79. package/out/renderer/assets/{architectureDiagram-5GKGNRK7-C4y0SbLT.js → architectureDiagram-5GKGNRK7-2E0AYPn5.js} +1 -1
  80. package/out/renderer/assets/{blockDiagram-I7D4REHJ-DrsoSFRK.js → blockDiagram-I7D4REHJ-BsSmBeco.js} +1 -1
  81. package/out/renderer/assets/{c4Diagram-7LVT6UL2-1DD8BlM8.js → c4Diagram-7LVT6UL2-gzVW5Xek.js} +1 -1
  82. package/out/renderer/assets/channel-AuDXnH14.js +1 -0
  83. package/out/renderer/assets/{chunk-2Q5K7J3B-DRyc0B7g.js → chunk-2Q5K7J3B-K_IlhZEX.js} +1 -1
  84. package/out/renderer/assets/{chunk-5VM5RSS4-BJe8SghE.js → chunk-5VM5RSS4-r65AjBn5.js} +1 -1
  85. package/out/renderer/assets/{chunk-F27PBJKO-BIipq4SK.js → chunk-F27PBJKO-CZszqKBI.js} +1 -1
  86. package/out/renderer/assets/{chunk-IMKFNOWR-D5Ak3Xd9.js → chunk-IMKFNOWR-7mYCkNCZ.js} +1 -1
  87. package/out/renderer/assets/{chunk-JWPE2WC7-BcaWCpW-.js → chunk-JWPE2WC7-B-cBpNJA.js} +1 -1
  88. package/out/renderer/assets/{chunk-POPQ4Y6H-C1TwLrrN.js → chunk-POPQ4Y6H-CjWY4_mJ.js} +1 -1
  89. package/out/renderer/assets/{chunk-SVP7TREG-DDOXG_t3.js → chunk-SVP7TREG-g5p-RdlH.js} +1 -1
  90. package/out/renderer/assets/{chunk-TICWLB2K-BqT15hZi.js → chunk-TICWLB2K-BMr5sD7G.js} +1 -1
  91. package/out/renderer/assets/{chunk-XXDRQBXY-D01ts6SC.js → chunk-XXDRQBXY-CNfQgYe3.js} +1 -1
  92. package/out/renderer/assets/classDiagram-ZZMXUADV-D8JIsdAI.js +1 -0
  93. package/out/renderer/assets/classDiagram-v2-VYDZK3BY-D8JIsdAI.js +1 -0
  94. package/out/renderer/assets/{cose-bilkent-JH36ORCC-C7NVrT2_.js → cose-bilkent-JH36ORCC-ByPl0yeB.js} +1 -1
  95. package/out/renderer/assets/{cynefin-OW5HDTMX-2LxdFmSk.js → cynefin-OW5HDTMX-CMTgEepT.js} +1 -1
  96. package/out/renderer/assets/{cynefinDiagram-5FMLGOSQ-_AN_Mulc.js → cynefinDiagram-5FMLGOSQ-DYx_JMNT.js} +1 -1
  97. package/out/renderer/assets/{cytoscape-fcose-COZkZZmX.js → cytoscape-fcose-BcbfusAa.js} +1 -1
  98. package/out/renderer/assets/{dagre-GXQ25YYZ-BUTwlM6j.js → dagre-GXQ25YYZ-p-Meu2Lo.js} +1 -1
  99. package/out/renderer/assets/{diagram-S7CK7UJ4-CseZZ-y2.js → diagram-S7CK7UJ4-1m9BA3xi.js} +1 -1
  100. package/out/renderer/assets/{diagram-UQ7AKVKN-Cb7llS-8.js → diagram-UQ7AKVKN-Cg3zgAxc.js} +1 -1
  101. package/out/renderer/assets/{diagram-VSXAHHWV-CtuGqQvp.js → diagram-VSXAHHWV-B58Hl37z.js} +1 -1
  102. package/out/renderer/assets/{diagram-VX7I27RA-BA8eov-1.js → diagram-VX7I27RA-C7dhzeqr.js} +1 -1
  103. package/out/renderer/assets/{diagram-Z3DM3KII-VZOjj6Hg.js → diagram-Z3DM3KII-C-Bn7OHR.js} +1 -1
  104. package/out/renderer/assets/{ebnfDiagram-PWID7BFC-YBIrle6d.js → ebnfDiagram-PWID7BFC-BcrVBxSI.js} +1 -1
  105. package/out/renderer/assets/{erDiagram-RLTQ6QDP-BiKyPEqW.js → erDiagram-RLTQ6QDP-CZHJHTxr.js} +1 -1
  106. package/out/renderer/assets/{flowDiagram-HODETNUW-7wmZyLHw.js → flowDiagram-HODETNUW-oCdJ784z.js} +1 -1
  107. package/out/renderer/assets/{ganttDiagram-EL5Y4UJY-D4j4GJaT.js → ganttDiagram-EL5Y4UJY-C9TlTohh.js} +1 -1
  108. package/out/renderer/assets/{gitGraphDiagram-WWUBYQGX-BqveM1NI.js → gitGraphDiagram-WWUBYQGX-RVFZsGPP.js} +1 -1
  109. package/out/renderer/assets/{globals-C9M_MZZV.js → globals-BJ2xID1e.js} +136 -136
  110. package/out/renderer/assets/{index-BzSTiwH2.js → index-CHNrHypo.js} +1 -1
  111. package/out/renderer/assets/{infoDiagram-27XIBGKW-DLPLnIFP.js → infoDiagram-27XIBGKW-CxE810pn.js} +1 -1
  112. package/out/renderer/assets/{ishikawaDiagram-5VMMS53U-48drIAMR.js → ishikawaDiagram-5VMMS53U-Osr2JJcF.js} +1 -1
  113. package/out/renderer/assets/{journeyDiagram-3NMN7TZE-vjigqUq_.js → journeyDiagram-3NMN7TZE-Bigxb8hB.js} +1 -1
  114. package/out/renderer/assets/{kanban-definition-UXKFOSKX-CpsYVONZ.js → kanban-definition-UXKFOSKX-DVP3FCG8.js} +1 -1
  115. package/out/renderer/assets/{layout-DqfoORoO.js → layout-Dn80hFs0.js} +1 -1
  116. package/out/renderer/assets/{linear-CJzBBHcp.js → linear-B4dfTk2J.js} +1 -1
  117. package/out/renderer/assets/{mermaid.core-DdrGP-Hn.js → mermaid.core-uI5XQTV1.js} +5 -5
  118. package/out/renderer/assets/{mindmap-definition-YA3MSWOX-D68tLNxp.js → mindmap-definition-YA3MSWOX-BD7FdpQU.js} +1 -1
  119. package/out/renderer/assets/{pegDiagram-XKGWAZYB-DkgLTcrv.js → pegDiagram-XKGWAZYB-DU5iHhXs.js} +1 -1
  120. package/out/renderer/assets/{pieDiagram-E7YTZNPT-bz5NuX1w.js → pieDiagram-E7YTZNPT-DpEVmuWZ.js} +1 -1
  121. package/out/renderer/assets/{quadrantDiagram-AXDQQJYC-o_VKLyJA.js → quadrantDiagram-AXDQQJYC-CcEfCONf.js} +1 -1
  122. package/out/renderer/assets/{railroadDiagram-O6MQD6OU-Dkf03e07.js → railroadDiagram-O6MQD6OU-BWnKKcat.js} +1 -1
  123. package/out/renderer/assets/{requirementDiagram-BXWQKSXE-CBUz_3YU.js → requirementDiagram-BXWQKSXE-B7sPFe0g.js} +1 -1
  124. package/out/renderer/assets/{sankeyDiagram-P5KCCOFB-B0pjUr9g.js → sankeyDiagram-P5KCCOFB-ClwzZmCX.js} +1 -1
  125. package/out/renderer/assets/{sequenceDiagram-WJ2MYXX4-ClugIL0e.js → sequenceDiagram-WJ2MYXX4-Dn8StCfr.js} +1 -1
  126. package/out/renderer/assets/{settings-DvhrDn2q.js → settings-CUBQyINw.js} +18 -18
  127. package/out/renderer/assets/{sizeCapture-INFHLROL-D6y0rctc.js → sizeCapture-INFHLROL-Csrj-WKZ.js} +1 -1
  128. package/out/renderer/assets/{stateDiagram-D77RDMKH-DiftQepS.js → stateDiagram-D77RDMKH-CuJq0aAV.js} +1 -1
  129. package/out/renderer/assets/stateDiagram-v2-MP3YSRHH-CXFPvfab.js +1 -0
  130. package/out/renderer/assets/{swimlanes-42K2YHIH-DhuTjCNj.js → swimlanes-42K2YHIH-CjyTBmUr.js} +1 -1
  131. package/out/renderer/assets/swimlanesDiagram-VR7AAH4N-D83-vEQi.js +8 -0
  132. package/out/renderer/assets/{timeline-definition-24CTP7MA-CrXqgptd.js → timeline-definition-24CTP7MA-BSTk1WRZ.js} +1 -1
  133. package/out/renderer/assets/{vennDiagram-4TSXK5OY-CDm8SO8U.js → vennDiagram-4TSXK5OY-oO2Udqo9.js} +1 -1
  134. package/out/renderer/assets/{wardleyDiagram-VM6X3IG4-CxyunHwQ.js → wardleyDiagram-VM6X3IG4-C27UPHbe.js} +1 -1
  135. package/out/renderer/assets/{xychartDiagram-S5SC5T6Z-CvC5YMSy.js → xychartDiagram-S5SC5T6Z-_SQkHfU0.js} +1 -1
  136. package/out/renderer/index.html +2 -2
  137. package/out/renderer/settings.html +3 -3
  138. package/out/renderer/web-preload.js +1 -1
  139. package/out/server/agent.js +5 -4
  140. package/out/server/chunks/{agent-_G_O-Cpa.js → agent-BlAuVqNp.js} +4 -2
  141. package/out/server/chunks/{gpuBackendInstall-Cb6TFh_8.js → gpuBackendInstall-C-ypqydV.js} +4 -4
  142. package/out/server/chunks/{loadProvider-Be9Lu1Oi.js → loadProvider-CQUR_oho.js} +2 -2
  143. package/out/server/chunks/{manifest-CB63GQ-i.js → manifest-CojWIAHB.js} +2 -2
  144. package/out/server/chunks/{workflowPresets-Djlp5LPV.js → workflowPresets-DQ3QX6Ju.js} +25 -12
  145. package/out/server/index.js +283 -39
  146. package/out/server/plugin-host.js +33 -3
  147. package/package.json +1 -1
  148. package/out/phone/assets/architecture-7GRP2DOG-DFA8x3QF.js +0 -1
  149. package/out/phone/assets/channel-BBjWfdZr.js +0 -1
  150. package/out/phone/assets/classDiagram-ZZMXUADV-CXXjdIIU.js +0 -1
  151. package/out/phone/assets/classDiagram-v2-VYDZK3BY-CXXjdIIU.js +0 -1
  152. package/out/phone/assets/eventmodeling-NTZA5JFV-D4a6gbOs.js +0 -1
  153. package/out/phone/assets/flowDiagram-HODETNUW-BBTtB5oX.js +0 -1
  154. package/out/phone/assets/railroad-abnf-HS5TGJTU-DddVaVQM.js +0 -1
  155. package/out/phone/assets/railroad-ebnf-LZEXJU2U-BjvyqMjh.js +0 -1
  156. package/out/phone/assets/railroad-peg-WCYAUIDC-lBl4CV1_.js +0 -1
  157. package/out/phone/assets/stateDiagram-v2-MP3YSRHH-Exd8xDBD.js +0 -1
  158. package/out/phone/assets/swimlanesDiagram-VR7AAH4N-B62_42fO.js +0 -8
  159. package/out/renderer/assets/channel-Sck-tAAK.js +0 -1
  160. package/out/renderer/assets/classDiagram-ZZMXUADV-DnB4QNNe.js +0 -1
  161. package/out/renderer/assets/classDiagram-v2-VYDZK3BY-DnB4QNNe.js +0 -1
  162. package/out/renderer/assets/stateDiagram-v2-MP3YSRHH-DxB2-9tl.js +0 -1
  163. package/out/renderer/assets/swimlanesDiagram-VR7AAH4N-CYDUqExO.js +0 -8
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./globals-C9M_MZZV.js","./globals-l3kDGoYH.css"])))=>i.map(i=>d[i]);
2
- import{c as Ee,w as $i,D as sa,j as e,A as Vi,r as m,u as ro,a as oo,b as Cn,d as io,t as lo,C as na,e as G,I as J,f as Ki,X as ht,h as qi,i as Gi,Z as st,k as Hi,S as Wi,l as Yi,m as Ji,n as Qi,o as Xi,p as z,q as v,B as S,s as pe,v as fe,x as ge,y as je,z as Ve,E as we,F as Qe,G as Ie,H as co,J as Re,K as aa,L as Zi,M as Xt,N as Zt,O as ae,P as re,Q as oe,R as ie,T as ee,U as el,V as qe,W as tl,Y as sl,_ as uo,$ as nl,a0 as fs,a1 as mo,a2 as al,a3 as ho,a4 as rl,a5 as ra,a6 as xo,a7 as ol,a8 as il,a9 as ll,aa as oa,ab as cl,ac as dl,ad as ul,ae as ml,af as hl,ag as xl,ah as pl,ai as fl,aj as gl,ak as jl,al as vl,am as gs,an as bl,ao as yl,ap as wl,aq as Nl,ar as kl,as as Cl,at as Ae,au as Sn,av as ss,aw as Be,ax as po,ay as Ct,az as _e,aA as Ue,aB as In,aC as At,aD as An,aE as En,aF as Mn,aG as Pn,aH as Tn,aI as Rn,aJ as On,aK as Xe,aL as ia,aM as la,aN as ze,aO as Ye,aP as Sl,aQ as Il,aR as fo,aS as le,aT as ca,aU as js,aV as da,aW as ua,aX as ma,aY as Al,aZ as El,a_ as vs,a$ as _t,b0 as go,b1 as Dn,b2 as Ml,b3 as Ln,b4 as jo,b5 as Pl,b6 as Tl,b7 as Rl,b8 as vo,b9 as Ol,ba as Dl,bb as Ll,bc as bo,bd as Mt,be as Gt,bf as zl,bg as zn,bh as Bl,bi as _l,bj as Bn,bk as Je,bl as Fl,bm as Ul,bn as yo,bo as $l,bp as Vl,bq as Kl,br as wo,bs as _n,bt as Oe,bu as te,bv as Me,bw as ql,bx as Gl,by as Hl,bz as Wl,bA as Yl,bB as ha,bC as Jl,bD as Ql,bE as Ft,bF as Ut,bG as Ke,bH as Dt,bI as cn,bJ as Xl,bK as Zl,bL as dn,bM as lt,bN as No,bO as ec,bP as tc,bQ as Fn,bR as sc,bS as xa,bT as ko,bU as nc,bV as ac,bW as Co,bX as Fe,bY as rc,bZ as ns,b_ as oc,b$ as pa,c0 as ic,c1 as lc,c2 as cc,c3 as He,c4 as dc,c5 as fa,c6 as ga,c7 as uc,c8 as ja,c9 as mc,ca as hc,cb as xc,cc as pc,cd as $e,ce as bs,cf as va,cg as fc,ch as gc,ci as So,cj as jc,ck as Io,cl as vc,cm as bc,cn as yc,co as wc,cp as Un,cq as Nc,cr as Ao,cs as kc,ct as Cc,cu as $t,cv as Sc,cw as Ic,cx as Ac,g as Ec,cy as un,cz as Eo,cA as Ht,cB as Mc,cC as Pc,cD as Tc,cE as me,cF as he,cG as cs,cH as $n,cI as Vn,cJ as Mo,cK as mn,cL as ba,cM as hn,cN as Po,cO as To,cP as Rc,cQ as Ro,cR as Oc,cS as Dc,cT as Lc,cU as zc,cV as Bc,cW as _c,cX as Fc,cY as Uc,cZ as $c,c_ as Vc,c$ as ya,d0 as Oo,d1 as Do,d2 as Lo,d3 as zo,d4 as Kc,d5 as qc,d6 as Et,d7 as Bo,d8 as _o,d9 as Fo,da as Gc,db as Hc,dc as Wc,dd as es,de as St,df as Uo,dg as Yc,dh as Jc,di as Qc,dj as Xc,dk as Zc,dl as ed,dm as td,dn as sd,dp as nd,dq as ad,dr as rd,ds as od,dt as xn,du as id,dv as as,dw as ld,dx as Kn,dy as $o,dz as Vo,dA as qn,dB as Ko,dC as qo,dD as Go,dE as Ho,dF as Wo,dG as cd,dH as dd,dI as ud,dJ as md,dK as hd,dL as xd,dM as pd,dN as fd,dO as gd,dP as jd,dQ as vd,dR as bd,dS as yd,dT as wd,dU as Nd,dV as kd,dW as Cd,dX as Sd,dY as Id,dZ as Yo,d_ as Jo,d$ as Qo,e0 as Ad,e1 as Xo,e2 as Ed,e3 as Md,e4 as Pd,e5 as Zo,e6 as Td,e7 as ei,e8 as Rd,e9 as Od,ea as Dd,eb as rs,ec as Ld,ed as zd,ee as Bd,ef as _d,eg as at,eh as Fd,ei as ti,ej as Ud,ek as $d,el as Vd,em as Kd,en as qd,eo as Gd,ep as Hd,eq as Wd,er as Yd,es as si,et as Jd,eu as Qd,ev as Xd,ew as Zd,ex as eu,ey as tu,ez as su,eA as nu,eB as au,eC as ru,eD as ou,eE as iu,eF as lu,eG as cu,eH as du,eI as uu,eJ as wa,eK as mu,eL as hu,eM as Na,eN as ka,eO as xu}from"./globals-C9M_MZZV.js";import{c as ni}from"./cytoscape.esm-DzSz-X2X.js";import{f as pu}from"./cytoscape-fcose-COZkZZmX.js";const fu=[["path",{d:"M10 22V7a1 1 0 0 0-1-1H4a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-5a1 1 0 0 0-1-1H2",key:"1ah6g2"}],["rect",{x:"14",y:"2",width:"8",height:"8",rx:"1",key:"88lufb"}]],gu=Ee("blocks",fu);const ju=[["path",{d:"M12 5v16",key:"1f6ucr"}],["path",{d:"M20.001 19A2 2 0 0022 17V5a2 2 0 00-1.999-2L16 3.002A5 5 0 0012 5a5 5 0 00-4-2H4a2 2 0 00-2 2v12a2 2 0 001.999 2H8a5 5 0 014 2 5 5 0 014-2z",key:"1fyvmf"}]],vu=Ee("book-open",ju);const bu=[["path",{d:"M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z",key:"hh9hay"}],["path",{d:"m3.3 7 8.7 5 8.7-5",key:"g66t2b"}],["path",{d:"M12 22V12",key:"d0xqtd"}]],yu=Ee("box",bu);const wu=[["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["path",{d:"M18 17V9",key:"2bz60n"}],["path",{d:"M13 17V5",key:"1frdt8"}],["path",{d:"M8 17v-3",key:"17ska0"}]],Nu=Ee("chart-column",wu);const ku=[["path",{d:"M13.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 2v11.5",key:"4pqfef"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M8 12v-1",key:"1ej8lb"}],["path",{d:"M8 18v-2",key:"qcmpov"}],["path",{d:"M8 7V6",key:"1nbb54"}],["circle",{cx:"8",cy:"20",r:"2",key:"ckkr5m"}]],Cu=Ee("file-archive",ku);const Su=[["path",{d:"M14.364 13.634a2 2 0 0 0-.506.854l-.837 2.87a.5.5 0 0 0 .62.62l2.87-.837a2 2 0 0 0 .854-.506l4.013-4.009a1 1 0 0 0-3.004-3.004z",key:"ukzhwg"}],["path",{d:"M14.487 7.858A1 1 0 0 1 14 7V2",key:"1klhew"}],["path",{d:"M20 19.645V20a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l2.516 2.516",key:"rxaxab"}],["path",{d:"M8 18h1",key:"13wk12"}]],Iu=Ee("file-pen-line",Su);const Au=[["path",{d:"M4 22V4a1 1 0 0 1 .4-.8A6 6 0 0 1 8 2c3 0 5 2 7.333 2q2 0 3.067-.8A1 1 0 0 1 20 4v10a1 1 0 0 1-.4.8A6 6 0 0 1 16 16c-3 0-5-2-8-2a6 6 0 0 0-4 1.528",key:"1jaruq"}]],Eu=Ee("flag",Au);const Mu=[["path",{d:"M12 22v-6",key:"6o8u61"}],["path",{d:"M12 8V2",key:"1wkif3"}],["path",{d:"M4 12H2",key:"rhcxmi"}],["path",{d:"M10 12H8",key:"s88cx1"}],["path",{d:"M16 12h-2",key:"10asgb"}],["path",{d:"M22 12h-2",key:"14jgyd"}],["path",{d:"m15 19-3-3-3 3",key:"e37ymu"}],["path",{d:"m15 5-3 3-3-3",key:"19d6lf"}]],Pu=Ee("fold-vertical",Mu);const Tu=[["path",{d:"M2 9.5a5.5 5.5 0 0 1 9.591-3.676.56.56 0 0 0 .818 0A5.49 5.49 0 0 1 22 9.5c0 2.29-1.5 4-3 5.5l-5.492 5.313a2 2 0 0 1-3 .019L5 15c-1.5-1.5-3-3.2-3-5.5",key:"mvr1a0"}]],Ca=Ee("heart",Tu);const Ru=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}]],Ou=Ee("image",Ru);const Du=[["path",{d:"M9 17H7A5 5 0 0 1 7 7h2",key:"8i5ue5"}],["path",{d:"M15 7h2a5 5 0 1 1 0 10h-2",key:"1b9ql8"}],["line",{x1:"8",x2:"16",y1:"12",y2:"12",key:"1jonct"}]],ai=Ee("link-2",Du);const Lu=[["circle",{cx:"12",cy:"16",r:"1",key:"1au0dj"}],["rect",{x:"3",y:"10",width:"18",height:"12",rx:"2",key:"6s8ecr"}],["path",{d:"M7 10V7a5 5 0 0 1 10 0v3",key:"1pqi11"}]],ri=Ee("lock-keyhole",Lu);const zu=[["path",{d:"M12 22a1 1 0 0 1 0-20 10 9 0 0 1 10 9 5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z",key:"e79jfc"}],["circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor",key:"1okk4w"}],["circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor",key:"f64h9f"}],["circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor",key:"qy21gx"}],["circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor",key:"fotxhn"}]],Bu=Ee("palette",zu);const _u=[["path",{d:"m15 15 6 6m-6-6v4.8m0-4.8h4.8",key:"17vawe"}],["path",{d:"M9 19.8V15m0 0H4.2M9 15l-6 6",key:"chjx8e"}],["path",{d:"M15 4.2V9m0 0h4.8M15 9l6-6",key:"lav6yq"}],["path",{d:"M9 4.2V9m0 0H4.2M9 9 3 3",key:"1pxi2q"}]],Fu=Ee("shrink",_u);const Uu=[["path",{d:"M15 21v-5a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v5",key:"slp6dd"}],["path",{d:"M17.774 10.31a1.12 1.12 0 0 0-1.549 0 2.5 2.5 0 0 1-3.451 0 1.12 1.12 0 0 0-1.548 0 2.5 2.5 0 0 1-3.452 0 1.12 1.12 0 0 0-1.549 0 2.5 2.5 0 0 1-3.77-3.248l2.889-4.184A2 2 0 0 1 7 2h10a2 2 0 0 1 1.653.873l2.895 4.192a2.5 2.5 0 0 1-3.774 3.244",key:"o0xfot"}],["path",{d:"M4 10.95V19a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8.05",key:"wn3emo"}]],$u=Ee("store",Uu);const Vu=[["circle",{cx:"12",cy:"12",r:"4",key:"4exip2"}],["path",{d:"M12 2v2",key:"tus03m"}],["path",{d:"M12 20v2",key:"1lh1kg"}],["path",{d:"m4.93 4.93 1.41 1.41",key:"149t6j"}],["path",{d:"m17.66 17.66 1.41 1.41",key:"ptbguv"}],["path",{d:"M2 12h2",key:"1t8f8n"}],["path",{d:"M20 12h2",key:"1q8mjw"}],["path",{d:"m6.34 17.66-1.41 1.41",key:"1m8zz5"}],["path",{d:"m19.07 4.93-1.41 1.41",key:"1shlcs"}]],Ku=Ee("sun",Vu);const qu=[["path",{d:"M12 3v12",key:"1x0j5s"}],["path",{d:"m17 8-5-5-5 5",key:"7q97r8"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}]],oi=Ee("upload",qu);function Gu(t){return t&&typeof t=="object"&&!Array.isArray(t)?t:null}function Hu(t){try{const s=new URL(t);return(s.protocol==="http:"||s.protocol==="https:")&&!s.username&&!s.password&&!s.search&&!s.hash&&!t.includes("?")&&!t.includes("#")}catch{return!1}}function Wu(t){const s=Gu(t);if(!s||Object.keys(s).some(d=>!["providerId","modelId","protocol","baseUrl","apiKey"].includes(d)))return null;const{providerId:n,modelId:a,protocol:r,baseUrl:o,apiKey:i}=s;return typeof n!="string"||!n.trim()||typeof a!="string"||!a.trim()||typeof i!="string"||!i.trim()||typeof o!="string"||!Hu(o)||r!=="openai"&&r!=="openai-compatible"&&r!=="gemini"?null:{providerId:n,modelId:a,protocol:r,baseUrl:o,apiKey:i}}function Yu(t,s){if(t?.enabled!==!0||t.oauthAccountKey||t.oauthAccountPool||typeof t.apiKey!="string"||!t.apiKey.trim()||typeof t.baseUrl!="string")return null;let n;if(t.api==="google-generative-ai")n="gemini";else if(t.api==="openai-completions"||t.api==="openai-responses"){let o="";try{o=new URL(t.baseUrl).hostname.toLowerCase()}catch{}n=t.catalogId!=="__custom"&&(t.catalogId==="openai"||!t.catalogId&&o==="api.openai.com")?"openai":"openai-compatible"}else return null;const a=n==="gemini"?sa["google-generative-ai"]:n==="openai"?sa["openai-responses"]:"";let r=t.baseUrl.trim().replace(/\/+$/,"")||a;if(n==="gemini"&&r&&(r=$i(r,"v1beta")),n==="openai"&&r)try{new URL(r).pathname==="/"&&(r=`${r}/v1`)}catch{}return Wu({providerId:t.id,modelId:s,protocol:n,baseUrl:r,apiKey:t.apiKey})}function Ju(t){return Array.isArray(t?.models)?t.models.filter(s=>!!s&&typeof s=="object"&&typeof s.id=="string"&&!!s.id.trim()&&s.enabled!==!1&&s.imageGeneration===!0):[]}function Qu(t){return t.flatMap(s=>{const n=Ju(s).filter(a=>Yu(s,a.id));return n.length?[{...s,models:n}]:[]})}function Xu(t){const{multiple:s=!1,defaultValue:n,value:a,onValueChange:r,autoComplete:o,...i}=t;return e.jsx(Vi,{...i,selectionMode:s?"multiple":"single",selectedValue:a,defaultSelectedValue:n,onSelectedValueChange:r,formAutoComplete:o})}const Zu=m.forwardRef(function(s,n){const{selected:a}=ro();return s.keepMounted||a?e.jsx(em,{...s,ref:n}):null}),em=m.memo(m.forwardRef((t,s)=>{const{render:n,className:a,style:r,keepMounted:o,...i}=t,{selected:d}=ro(),u=m.useRef(null),{transitionStatus:x,setMounted:h}=oo(d),f=Cn("span",t,{ref:[s,u],state:{selected:d,transitionStatus:x},props:[{"aria-hidden":!0,children:"✔️"},i],stateAttributesMapping:lo});return io({open:d,ref:u,onComplete(){d||h(!1)}}),f})),Gn=m.createContext({chipsRef:null,multiple:!1,rootRef:null});function tm(t){const s=m.useRef(null),n=m.useRef(null);return e.jsx(Gn.Provider,{value:{chipsRef:s,multiple:!!t.multiple,rootRef:n},children:e.jsx("div",{ref:n,className:"contents",children:e.jsx(Xu,{...t})})})}function sm({className:t,showTrigger:s=!0,showClear:n=!1,startAddon:a,size:r,...o}){const{multiple:i}=m.useContext(Gn),d=r??"default";return i?e.jsx(na,{className:G("min-w-12 flex-1 text-base outline-none sm:text-sm [[data-slot=combobox-chip]+&]:ps-0.5",d==="sm"?"ps-1.5":"ps-2",t),"data-size":typeof d=="string"?d:void 0,"data-slot":"combobox-input",size:typeof d=="number"?d:void 0,...o}):e.jsxs("div",{className:"relative w-full has-disabled:opacity-64",children:[a&&e.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":"combobox-start-addon",children:a}),e.jsx(na,{className:G(a&&"data-[size=sm]:*:data-[slot=combobox-input]:ps-[calc(--spacing(7.5)-1px)] *:data-[slot=combobox-input]:ps-[calc(--spacing(8.5)-1px)] sm:data-[size=sm]:*:data-[slot=combobox-input]:ps-[calc(--spacing(7)-1px)] sm:*:data-[slot=combobox-input]:ps-[calc(--spacing(8)-1px)]",d==="sm"?"has-[+[data-slot=combobox-trigger],+[data-slot=combobox-clear]]:*:data-[slot=combobox-input]:pe-6.5":"has-[+[data-slot=combobox-trigger],+[data-slot=combobox-clear]]:*:data-[slot=combobox-input]:pe-7",t),"data-slot":"combobox-input",render:e.jsx(J,{className:"has-disabled:opacity-100",size:d}),...o}),s&&e.jsx(nm,{className:G("-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-opacity pointer-coarse:after:absolute pointer-coarse:after:min-h-11 pointer-coarse:after:min-w-11 hover:opacity-100 has-[+[data-slot=combobox-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",d==="sm"?"end-0":"end-0.5"),children:e.jsx(Ki,{})}),n&&e.jsx(im,{className:G("-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-opacity pointer-coarse:after:absolute pointer-coarse:after:min-h-11 pointer-coarse:after:min-w-11 hover:opacity-100 has-[+[data-slot=combobox-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",d==="sm"?"end-0":"end-0.5"),children:e.jsx(ht,{})})]})}function nm({className:t,...s}){return e.jsx(Qi,{className:t,"data-slot":"combobox-trigger",...s})}function am({className:t,children:s,sideOffset:n=4,zIndex:a,...r}){const{chipsRef:o,rootRef:i}=m.useContext(Gn);let d=st.DROPDOWN;if(a!==void 0)d=a;else{const u=i?.current;u&&(u.closest('[data-slot="dialog-popup"] [data-slot="dialog-popup"]')?d=st.DROPDOWN_IN_NESTED_MODAL:u.closest('[data-slot="dialog-popup"]')&&(d=st.DROPDOWN_IN_MODAL))}return e.jsx(qi,{children:e.jsx(Gi,{anchor:o,className:"select-none",style:{zIndex:d},"data-slot":"combobox-positioner",sideOffset:n,children:e.jsx("span",{className:G("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",t),children:e.jsx(Hi,{className:"flex max-h-[min(var(--available-height),23rem)] w-(--anchor-width) max-w-(--available-width) flex-col","data-slot":"combobox-popup",...r,children:s})})})})}function rm({className:t,children:s,endAddon:n,...a}){return e.jsxs(Ji,{className:G("grid min-h-8 in-data-[side=none]:min-w-[calc(var(--anchor-width)+1.25rem)] cursor-default grid-cols-[1rem_1fr_auto] items-center gap-2 rounded-sm py-1 ps-2 pe-4 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 [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",t),"data-slot":"combobox-item",...a,children:[e.jsx(Zu,{className:"col-start-1",children:e.jsx("svg",{"aria-hidden":"true",fill:"none",height:"24",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",viewBox:"0 0 24 24",width:"24",xmlns:"http://www.w3.org/2000/svg",children:e.jsx("path",{d:"M5.252 12.7 10.2 18.63 18.748 5.37"})})}),e.jsx("div",{className:"col-start-2",children:s}),n&&e.jsx("div",{className:"col-start-3 flex items-center",children:n})]})}function om({className:t,...s}){return e.jsx(Wi,{scrollbarGutter:!0,scrollFade:!0,children:e.jsx(Yi,{className:G("not-empty:scroll-py-1 not-empty:px-1 not-empty:py-1 in-data-has-overflow-y:pe-3",t),"data-slot":"combobox-list",...s})})}function im({className:t,...s}){return e.jsx(Xi,{className:t,"data-slot":"combobox-clear",...s})}function lm(){const{t}=z(),s=v(c=>c.contextMenuOpen),n=v(c=>c.setContextMenuOpen),[a,r]=m.useState(!1),[o,i]=m.useState(!1),d=c=>c.target==="reveal"?t("File manager"):c.target==="vscode"?t("VS Code"):c.applicationPath.split(/[/\\]/).at(-1)?.replace(/\.(exe|app)$/i,"")||c.applicationPath,u=s.filter(c=>c.enabled).map(d),x=u.length?`${u.slice(0,2).join(", ")}${u.length>2?` +${u.length-2}`:""}`:t("No opening methods enabled"),h=c=>{if(c.length>32){Re({type:"error",title:t("Context menu opening"),description:t("You can configure up to 32 opening methods.")});return}n(c)},l=(c,p)=>{const g=v.getState().contextMenuOpen;n(g.map(w=>w.id===c.id?{...w,enabled:p}:w))},f=async()=>{i(!0);try{const c=await window.electronAPI.dialog.selectFile();if(!c)return;if(!co(c)){Re({type:"error",title:t("Context menu opening"),description:t("The selected application path is invalid.")});return}const p=v.getState().contextMenuOpen,g=aa(c),w=p.find(k=>k.target==="application"&&aa(k.applicationPath)===g);if(w){h(p.map(k=>k.id===w.id?{...k,enabled:!0}:k));return}h([...p,{id:crypto.randomUUID(),target:"application",applicationPath:c,enabled:!0}])}catch(c){Re({type:"error",title:t("Context menu opening"),description:c instanceof Error?c.message:String(c)})}finally{i(!1)}};return e.jsxs("div",{className:"space-y-2 rounded-md border p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("h5",{className:"text-sm font-medium",children:t("Context menu opening")}),e.jsx(S,{variant:"outline",size:"sm",onClick:()=>r(!0),children:t("Configure list")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Select the opening methods shown in file link context menus. You can add multiple applications.")}),e.jsx("p",{className:"truncate text-xs text-muted-foreground",title:u.join(", "),children:x}),e.jsx(pe,{open:a,onOpenChange:r,children:e.jsxs(fe,{zIndexLevel:"nested",children:[e.jsxs(ge,{children:[e.jsx(je,{children:t("Context menu opening")}),e.jsx(Ve,{children:t("Select the opening methods shown in file link context menus. You can add multiple applications.")})]}),e.jsxs(we,{className:"space-y-2",children:[s.length===0&&e.jsx("p",{className:"py-6 text-center text-sm text-muted-foreground",children:t("No opening methods enabled")}),s.map(c=>{const p=d(c);return e.jsxs("div",{className:"flex items-center gap-3 rounded-md border p-3",children:[e.jsxs("label",{className:"flex min-w-0 flex-1 cursor-pointer items-center gap-3",children:[e.jsx(Qe,{checked:c.enabled,disabled:o,"aria-label":p,onCheckedChange:g=>l(c,g)}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-sm",title:p,children:p}),c.target==="application"&&e.jsx("span",{className:"block truncate text-xs text-muted-foreground",title:c.applicationPath,children:c.applicationPath})]})]}),e.jsx(S,{variant:"ghost",size:"sm",disabled:o,onClick:()=>n(v.getState().contextMenuOpen.filter(g=>g.id!==c.id)),children:t("Delete")})]},c.id)})]}),e.jsxs(Ie,{children:[e.jsx(S,{variant:"outline",disabled:o,onClick:()=>{f()},children:t("Add application")}),e.jsx(S,{onClick:()=>r(!1),children:t("Close")})]})]})})]})}const Sa=["internal","reveal","system","application"];function Ia({extension:t,value:s,disabled:n,onChange:a}){const{t:r}=z(),o={internal:r("Open inside EnsoCode"),reveal:r("Reveal in file manager"),system:r("System default application"),application:r("Selected application")},i=Xt(`file${t}`),d=Zt(`file${t}`)!==null,u=i?d?["internal","reveal"]:["reveal"]:Sa,x=i&&(!d||s==="system"||s==="application")?"reveal":s;return e.jsxs(ae,{items:Object.fromEntries(u.map(h=>[h,o[h]])),value:x,disabled:n,onValueChange:h=>{Sa.includes(h)&&a(h)},children:[e.jsx(re,{className:"w-52","aria-label":r("File opening"),children:e.jsx(oe,{})}),e.jsx(ie,{children:u.map(h=>e.jsx(ee,{value:h,disabled:h==="internal"&&!d,children:o[h]},h))})]})}function cm(){const{t}=z(),s=v(y=>y.fileOpenRules),n=v(y=>y.setFileOpenRules),[a,r]=m.useState(""),[o,i]=m.useState("internal"),[d,u]=m.useState(),[x,h]=m.useState(null),[l,f]=m.useState(!1),c=Zi([{extension:a,target:"reveal"}])[0]?.extension,p=y=>{Re({type:"error",title:t("File opening"),description:y})},g=async y=>{f(!0);try{const N=await window.electronAPI.dialog.selectFile();if(N){if(!co(N)){p(t("The selected application path is invalid."));return}y(N)}}catch(N){p(N instanceof Error?N.message:String(N))}finally{f(!1)}},w=y=>{const N=el(y);return N?(n(N),!0):(p(t("Could not complete the file action.")),!1)},k=(y,N,A)=>{if(N==="internal"&&!Zt(`file${y.extension}`)){p(t("This extension does not support internal preview."));return}w(s.map(O=>O.extension===y.extension?{extension:y.extension,target:N,...N==="application"?{applicationPath:A}:{}}:O))},j=()=>{if(!c){h(t("Enter a valid file extension, for example .md."));return}if(s.some(O=>O.extension===c)){h(t("This extension already has an opening rule."));return}const y=Xt(`file${c}`),N=Zt(`file${c}`)!==null,A=y&&(!N||o==="system"||o==="application")?"reveal":o;if(A==="internal"&&!Zt(`file${c}`)){p(t("This extension does not support internal preview."));return}if(A==="application"&&!d){h(t("Choose an application before saving this rule."));return}w([...s,{extension:c,target:A,...A==="application"?{applicationPath:d}:{}}])&&(r(""),u(void 0),h(null))};return e.jsxs("section",{className:"space-y-3","data-settings-row":"appearance.fileOpening",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium",children:t("File opening")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Configure how local workspace file links open by extension.")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("By default, supported files open inside EnsoCode; other files are revealed in the file manager.")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Executable and installer files are always revealed in the file manager.")})]}),e.jsx(lm,{}),s.map(y=>e.jsxs("div",{className:"flex flex-wrap items-center gap-2 rounded-md border px-3 py-2",children:[e.jsx("span",{className:"w-20 shrink-0 font-mono text-sm",children:y.extension}),e.jsx(Ia,{extension:y.extension,value:y.target,disabled:l,onChange:N=>{N==="application"?g(A=>k(y,N,A)):k(y,N)}}),y.target==="application"&&!Xt(`file${y.extension}`)&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-xs text-muted-foreground",title:y.applicationPath,children:y.applicationPath}),e.jsx(S,{variant:"outline",size:"sm",disabled:l,onClick:()=>{g(N=>k(y,"application",N))},children:t("Choose application")})]}),e.jsx(S,{variant:"ghost",size:"sm",disabled:l,onClick:()=>w(s.filter(N=>N.extension!==y.extension)),children:t("Delete")})]},y.extension)),e.jsxs("div",{className:"space-y-2 rounded-md border p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(J,{className:"w-24",value:a,placeholder:".md","aria-label":t("File extension"),disabled:l,onChange:y=>{r(y.target.value),h(null)},onKeyDown:y=>{y.key==="Enter"&&j()}}),e.jsx(Ia,{extension:c??".md",value:o,disabled:l,onChange:y=>{i(y),h(null)}}),e.jsx(S,{variant:"outline",size:"sm",disabled:l,onClick:j,children:t("Add")})]}),o==="application"&&!Xt(`file${c??".md"}`)&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(S,{variant:"outline",size:"sm",disabled:l,onClick:()=>{g(y=>{u(y),h(null)})},children:t("Choose application")}),e.jsx("span",{className:"min-w-0 truncate text-xs text-muted-foreground",title:d,children:d})]}),x&&e.jsx("p",{role:"alert",className:"text-xs text-destructive",children:x})]})]})}function dm(t){return/^\//.test(t)||/^[A-Za-z]:[\\/]/.test(t)||/^\\\\[^\\]/.test(t)}const um=16384,ii=4096,li=65536;function mm(t){return t===null?null:typeof t=="number"&&Number.isInteger(t)&&t>=ii&&t<=li?t:void 0}function hm(t){const s=t.trim();return s?/^\d+$/.test(s)?mm(Number(s)):void 0:null}function xm(){const{t}=z(),[s,n]=m.useState(null),[a,r]=m.useState(""),[o,i]=m.useState(null);m.useEffect(()=>{let u=!1;return window.electronAPI.compaction.getReserveTokens().then(x=>{u||(n(x),r(x===null?"":String(x)))}),()=>{u=!0}},[]);const d=async()=>{const u=hm(a);if(u===void 0){i(t("Enter a whole number between {{min}} and {{max}}, or leave it empty.",{min:ii,max:li}));return}if(i(null),u===s)return;if(!(await window.electronAPI.compaction.setReserveTokens(u)).ok){i(t("Could not save. Check that pi-agent/settings.json is valid JSON."));return}n(u),r(u===null?"":String(u))};return e.jsxs("div",{className:"flex items-start justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.compactReserveTokens",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"text-sm",children:[t("Compaction reserve tokens"),e.jsx(qe,{})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Compaction runs when context exceeds the model window minus this value. Larger values compact earlier. Do not set it close to the window of small-context models, or every request compacts first. Leave empty for the default.")})]}),e.jsxs("div",{className:"w-32 shrink-0 space-y-1",children:[e.jsx(J,{inputMode:"numeric",value:a,placeholder:String(um),"aria-label":t("Compaction reserve tokens"),onChange:u=>r(u.target.value),onBlur:()=>{d()},onKeyDown:u=>{u.key==="Enter"&&d()}}),o&&e.jsx("p",{className:"text-xs text-destructive",children:o})]})]})}function pn({className:t,render:s,...n}){const a={className:G("inline-flex items-center gap-2 text-base/4.5 sm:text-sm/4 font-medium",t),"data-slot":"label"};return tl({defaultTagName:"label",props:sl(a,n),render:s})}const fn={checked(t){return t?{"data-checked":""}:{"data-unchecked":""}},...lo,...uo},ci=m.createContext(void 0);function pm(){return m.useContext(ci)}const di=m.createContext(void 0);function fm(){const t=m.useContext(di);if(t===void 0)throw new Error(nl(52));return t}const gm=m.forwardRef(function(s,n){const{render:a,className:r,disabled:o=!1,readOnly:i=!1,required:d=!1,"aria-labelledby":u,value:x,inputRef:h,nativeButton:l=!1,id:f,style:c,...p}=s,g=pm(),{disabled:w,readOnly:k,required:j,form:y,checkedValue:N,touched:A=!1,validation:O,name:I,setCheckedValue:L=fs,setTouched:C=fs,registerInputRef:E=fs}=g??{},{setTouched:M,setFilled:V,state:F,disabled:b}=mo(),_=al(),{labelId:K,getDescriptionProps:D}=ho(),$=b||_.disabled||w||o,Y=k||i,H=j||d,se=y,q=g?N===x:x==="",Q=m.useRef(null),B=m.useRef(null),ne=O?.registerInput,R=m.useCallback(ke=>ne?.(ke,{controlRef:Q,value:void 0}),[ne]),P=rl(h,B,E,R);ra(()=>{B.current?.checked&&V(!0)},[V]),ra(()=>{if(B.current){if($&&q){E(null);return}E(B.current)}},[q,$,E]);const ce=xo(),xe=ol({id:f,implicit:!1,controlRef:Q}),Pe=l?void 0:xe,De=il(u,K,B,!l,Pe),U={role:"radio","aria-checked":q,"aria-labelledby":De,[xl]:q?"":void 0,id:l?xe:ce,onKeyDown(ke){ke.key==="Enter"&&ke.preventDefault()},onClick(ke){if(ke.defaultPrevented||$||Y)return;ke.preventDefault();const nt=B.current;nt&&hl(nt,ke)},onFocus(ke){ke.defaultPrevented||$||Y||!A||(B.current?.click(),C(!1))}},{getButtonProps:Z,buttonRef:X}=ll({disabled:$,native:l,composite:!1}),ue={type:"radio",ref:P,form:se,id:Pe,name:I,tabIndex:-1,style:I?ul:ml,"aria-hidden":!0,...x!==void 0?{value:cl(x)}:oa,disabled:$,checked:q,required:H,readOnly:Y,onChange(ke){if(ke.nativeEvent.defaultPrevented||$||Y||x===void 0)return;const nt=pl(fl,ke.nativeEvent);L(x,nt),!nt.isCanceled&&M(!0)},onClick(ke){ke.stopPropagation()},onFocus(){Q.current?.focus()}},Ne=m.useMemo(()=>({...F,required:H,disabled:$,readOnly:Y,checked:q}),[F,$,Y,q,H]),Ce=Ne,W=g!==void 0,ve=[n,Q,X],Se=[U,p,Z,D,O?ke=>O.getValidationProps($,ke):oa],Ze=Cn("span",s,{enabled:!W,state:Ne,ref:ve,props:Se,stateAttributesMapping:fn});return e.jsxs(di.Provider,{value:Ce,children:[W?e.jsx(dl,{tag:"span",render:a,className:r,style:c,state:Ne,refs:ve,props:Se,stateAttributesMapping:fn}):Ze,e.jsx("input",{...ue,suppressHydrationWarning:!0})]})}),jm=m.forwardRef(function(s,n){const{render:a,className:r,style:o,keepMounted:i=!1,...d}=s,u=fm(),x=u.checked,{mounted:h,transitionStatus:l,setMounted:f}=oo(x),c={...u,transitionStatus:l},p=m.useRef(null),g=i||h,w=Cn("span",s,{ref:[n,p],state:c,props:d,stateAttributesMapping:fn});return io({open:x,ref:p,onComplete(){x||f(!1)}}),g?w:null}),vm=[kl],bm=m.forwardRef(function(s,n){const{render:a,className:r,disabled:o,readOnly:i,required:d,onValueChange:u,value:x,defaultValue:h,form:l,name:f,inputRef:c,id:p,style:g,...w}=s,{setTouched:k,setFocused:j,validationMode:y,name:N,disabled:A,state:O,validation:I,setDirty:L,setFilled:C,validityData:E}=mo(),{labelId:M}=ho(),{clearErrors:V,elementRef:F}=gl(),b=jl(!0),_=A||o,K=N??f,D=xo(p),[$,Y]=vl({controlled:x,default:h,name:"RadioGroup",state:"value"}),[H,se]=m.useState(!1),q=gs((X,ue)=>{u?.(X,ue),!ue.isCanceled&&Y(X)}),Q=I.getInputControl,B=m.useMemo(()=>({get current(){return Q()}}),[Q]),ne=m.useRef(null),R=m.useRef(null);function P(X){let ue;return c&&(typeof c=="function"?ue=c(X):c.current=X),ne.current=X,ue}const ce=gs(X=>{if(!X||X.disabled)return;R.current||(R.current=X);const ue=ne.current,Ne=X.checked||ue==null||ue.disabled?P(X):void 0;return()=>{R.current===X&&(R.current=null),ne.current===X?Ne?(Ne(),ne.current=null):P(null):Ne?.()}}),xe=gs(()=>{const X=F.current;if(!X)return $??null;for(const ue of I.registeredInputs.keys())if(ue.checked&&bl(ue,X))return $??null;return null});yl(B,D,$??null,xe,!_,f),wl($,()=>{V(K),L($!==E.initialValue),C($!=null),I.change($);const X=R.current;$==null&&X&&!X.disabled&&P(X)});const Pe=M??b?.legendId,De={...O,disabled:_??!1,required:d??!1,readOnly:i??!1},U=m.useMemo(()=>({checkedValue:$,disabled:_,form:l,validation:I,name:K,readOnly:i,registerInputRef:ce,required:d,setCheckedValue:q,setTouched:se,touched:H}),[$,_,l,I,K,i,ce,d,q,se,H]),Z={id:p,role:"radiogroup","aria-required":d||void 0,"aria-disabled":_||void 0,"aria-readonly":i||void 0,"aria-labelledby":Pe,onFocus(){j(!0)},onBlur(X){Cl(X.currentTarget,X.relatedTarget)||(k(!0),j(!1),y==="onBlur"&&I.commit($))},onKeyDownCapture(X){X.key.startsWith("Arrow")&&(se(!0),j(!0))}};return e.jsx(ci.Provider,{value:U,children:e.jsx(Nl,{render:a,className:r,style:g,state:De,props:[Z,w,X=>I.getValidationProps(_??!1,X)],refs:[n],stateAttributesMapping:uo,enableHomeAndEndKeys:!1,modifierKeys:vm})})});function ym({className:t,...s}){return e.jsx(bm,{className:G("flex flex-col gap-3",t),"data-slot":"radio-group",...s})}function Aa({className:t,...s}){return e.jsx(gm,{className:G("relative inline-flex size-4.5 shrink-0 items-center justify-center rounded-full border border-input bg-background bg-clip-padding shadow-xs outline-none transition-shadow before:pointer-events-none before:absolute before:inset-0 before:rounded-full not-data-disabled:not-data-checked:not-aria-invalid:before:shadow-[0_1px_--theme(--color-black/4%)] focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background aria-invalid:border-destructive/36 focus-visible:aria-invalid:border-destructive/64 focus-visible:aria-invalid:ring-destructive/48 data-disabled:opacity-64 sm:size-4 dark:not-data-checked:bg-input/32 dark:bg-clip-border dark:aria-invalid:ring-destructive/24 dark:not-data-disabled:not-data-checked:not-aria-invalid:before:shadow-[0_-1px_--theme(--color-white/8%)] [[data-disabled],[data-checked],[aria-invalid]]:shadow-none",t),"data-slot":"radio",...s,children:e.jsx(jm,{className:"-inset-px absolute flex size-4.5 items-center justify-center rounded-full before:size-2 before:rounded-full before:bg-primary-foreground data-unchecked:hidden data-checked:bg-primary sm:size-4 sm:before:size-1.5","data-slot":"radio-indicator"})})}const wm=[{category:"providers",label:"Model Providers"},{category:"presets",label:"Presets"},{category:"agentTypes",label:"Agent types"},{category:"skills",label:"Skills"},{category:"mcpServers",label:"MCP Servers"},{category:"instructions",label:"Instruction Files"},{category:"subagentModels",label:"Subagent Models"},{category:"settings",label:"Scalar settings"}];function Nm(){const{t}=z(),[s,n]=m.useState(!1),[a,r]=m.useState(!1),[o,i]=m.useState(null),[d,u]=m.useState(null),x=()=>{i(null),n(!0)},h=async()=>{r(!0),i(null);try{const l=await window.electronAPI.configSync.openImport();if(!l.ok){i({kind:l.cancelled?"cancelled":"error",text:l.cancelled?t("Import cancelled."):t(l.error)});return}u(l)}catch{i({kind:"error",text:t("Could not open configuration package.")})}finally{r(!1)}};return e.jsxs("section",{className:"space-y-3","data-settings-row":"general.configSync",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium",children:t("Configuration transfer")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Move models, presets, agent types, skills, MCP servers and instruction files between devices.")})]}),e.jsxs("div",{className:"rounded-md border px-3 py-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[e.jsx(Cu,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium",children:t("Portable Enso configuration")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Export a package or preview one before importing it.")})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsxs(S,{variant:"outline",size:"sm",disabled:a,onClick:h,children:[a?e.jsx(Ae,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Sn,{className:"h-3.5 w-3.5"}),t("Import configuration")]}),e.jsxs(S,{size:"sm",disabled:a,onClick:x,children:[e.jsx(oi,{className:"h-3.5 w-3.5"}),t("Export configuration")]})]})]}),e.jsxs("div",{className:"mt-3 flex items-start gap-2 border-t pt-3 text-xs text-muted-foreground",children:[e.jsx(ss,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),e.jsx("p",{children:t("OAuth login sessions are never transferred. Skill, instruction, and system prompt contents require an encrypted export.")})]}),o&&e.jsx("p",{className:o.kind==="error"?"mt-2 text-xs text-destructive":"mt-2 text-xs text-muted-foreground",role:o.kind==="error"?"alert":"status",children:o.text})]}),e.jsx(km,{open:s,onOpenChange:n}),d&&e.jsx(Cm,{file:d,onClose:()=>u(null)})]})}function km({open:t,onOpenChange:s}){const{t:n}=z(),[a,r]=m.useState(!1),[o,i]=m.useState(""),[d,u]=m.useState(""),[x,h]=m.useState(!1),[l,f]=m.useState(null),[c,p]=m.useState(!1),[g,w]=m.useState(null),[k,j]=m.useState([]);m.useEffect(()=>{t&&(r(!1),i(""),u(""),h(!1),f(null),p(!1),w(null),j([]))},[t]);const y=()=>{x||(i(""),u(""),s(!1))},N=async()=>{if(a&&o.length<8){f(n("Password must be at least 8 characters."));return}if(a&&o!==d){f(n("Passwords do not match."));return}h(!0),f(null),p(!1);try{const A=await window.electronAPI.configSync.exportConfig({includeSecrets:a,...a?{password:o}:{}});if(i(""),u(""),!A.ok){A.cancelled?p(!0):f(n(A.error));return}w(A.filePath),j(A.skippedInstructions??[])}catch{i(""),u(""),f(n("Could not export configuration."))}finally{h(!1)}};return e.jsx(pe,{open:t,onOpenChange:A=>!A&&y(),children:e.jsxs(fe,{className:"max-w-xl",showCloseButton:!x,children:[e.jsxs(ge,{children:[e.jsx(je,{children:n("Export configuration")}),e.jsx(Ve,{children:n("Create a portable .enso-config package for another device.")})]}),e.jsx(we,{className:"max-h-[55vh] space-y-4",children:g?e.jsxs(e.Fragment,{children:[e.jsxs(Be,{variant:"success",children:[e.jsx(po,{}),e.jsx(Ct,{children:n("Configuration exported")}),e.jsxs(_e,{children:[e.jsx("p",{children:n("Saved package:")}),e.jsx("p",{className:"break-all font-mono text-xs text-foreground",children:g})]})]}),k.length>0&&e.jsxs(Be,{variant:"warning",children:[e.jsx(Ue,{}),e.jsxs(_e,{children:[e.jsx("p",{children:n("These instructions were skipped because their source files are missing or unreadable:")}),e.jsx("p",{className:"break-all text-foreground",children:k.join(", ")})]})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs(Be,{variant:"warning",children:[e.jsx(In,{}),e.jsx(Ct,{children:n("File contents can be private")}),e.jsx(_e,{children:n("Skill and instruction file contents may contain private data, so configurations containing them can only be exported with encryption.")})]}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-md border px-3 py-2.5",children:[e.jsx(Qe,{checked:a,onCheckedChange:A=>{const O=A===!0;r(O),f(null),O||(i(""),u(""))}}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-sm font-medium",children:n("Include sensitive configuration")}),e.jsx("span",{className:"mt-0.5 block text-xs text-muted-foreground",children:n("Encrypt the entire package with a password. OAuth login sessions are still excluded.")})]})]}),!a&&e.jsxs(Be,{variant:"info",children:[e.jsx(ss,{}),e.jsx(_e,{children:n("API keys, provider account links, MCP arguments and environment values, plus credentials and private URL parts in MCP endpoints, will be omitted. Configurations containing skill or instruction files require encryption.")})]}),a&&e.jsxs("div",{className:"space-y-3 rounded-md border px-3 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(ri,{className:"h-4 w-4 text-muted-foreground"}),n("Encryption password")]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(pn,{htmlFor:"config-export-password",children:n("Password")}),e.jsx(J,{id:"config-export-password",type:"password",autoComplete:"new-password",value:o,"aria-invalid":!!(l&&o.length<8),onChange:A=>{i(A.target.value),f(null)}})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(pn,{htmlFor:"config-export-confirmation",children:n("Confirm password")}),e.jsx(J,{id:"config-export-confirmation",type:"password",autoComplete:"new-password",value:d,"aria-invalid":!!(l&&d!==o),onChange:A=>{u(A.target.value),f(null)}})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n("Use at least 8 characters. This password cannot be recovered.")})]}),c&&e.jsx("p",{className:"text-xs text-muted-foreground",role:"status",children:n("Export cancelled.")}),l&&e.jsxs("p",{className:"flex items-center gap-1.5 text-xs text-destructive",role:"alert",children:[e.jsx(At,{className:"h-3.5 w-3.5 shrink-0"}),l]})]})}),e.jsx(Ie,{children:g?e.jsx(S,{size:"sm",onClick:y,children:n("Done")}):e.jsxs(e.Fragment,{children:[e.jsx(S,{variant:"outline",size:"sm",disabled:x,onClick:y,children:n("Cancel")}),e.jsxs(S,{size:"sm",disabled:x,onClick:()=>{N()},children:[x?e.jsx(Ae,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(oi,{className:"h-3.5 w-3.5"}),n(x?"Exporting…":"Export")]})]})})]})})}function Cm({file:t,onClose:s}){const{t:n}=z(),[a,r]=m.useState(t.encrypted?"password":"preview"),[o,i]=m.useState(""),[d,u]=m.useState("merge"),[x,h]=m.useState(null),[l,f]=m.useState([]),[c,p]=m.useState(null),[g,w]=m.useState(!1),[k,j]=m.useState(null),[y,N]=m.useState(null),[A,O]=m.useState(!1),I=m.useRef(0),L=m.useCallback(async(b,_)=>{const K=++I.current;j("preview"),N(null),h(null),f([]);try{const D=await window.electronAPI.configSync.previewImport({token:t.token,mode:b,..._?{password:_}:{}});if(K!==I.current)return;if(i(""),!D.ok){N(n(D.error));return}u(D.mode),h(D.summary),f(D.warnings),r("preview")}catch{K===I.current&&(i(""),N(n("Could not preview configuration package.")))}finally{K===I.current&&j(null)}},[t.token,n]);m.useEffect(()=>{t.encrypted||L("merge")},[t.encrypted,L]);const C=()=>{k||(I.current+=1,O(!1),i(""),window.electronAPI.configSync.cancelImport(t.token).catch(()=>{}),s())},E=b=>{b===d||k||(u(b),L(b))},M=!!x?.some(b=>(b.category==="skills"||b.category==="mcpServers")&&b.added+b.updated+b.skipped>0),V=x!==null,F=async()=>{if(x){j("commit"),N(null);try{const b=await window.electronAPI.configSync.commitImport({token:t.token,mode:d});if(!b.ok){h(null),f([]),N(n(b.error));return}i("");try{await v.persist.rehydrate()}catch{w(!0)}f(b.warnings),p(b.backupPath),r("success")}catch{h(null),f([]),N(n("Could not import configuration."))}finally{j(null)}}};return e.jsxs(pe,{open:!0,onOpenChange:b=>!b&&C(),children:[e.jsxs(fe,{className:"max-w-2xl",showCloseButton:k===null,children:[e.jsxs(ge,{children:[e.jsx(je,{children:n(a==="success"?"Configuration imported":"Import configuration")}),e.jsx(Ve,{children:a==="success"?n(g?"Configuration was imported, but this window could not refresh automatically.":"This window has been refreshed with the imported settings."):n("Review {{fileName}} before changing this device.",{fileName:t.fileName})})]}),a==="password"&&e.jsxs(we,{className:"space-y-4",children:[e.jsxs(Be,{variant:"info",children:[e.jsx(ri,{}),e.jsx(Ct,{children:n("Encrypted configuration package")}),e.jsx(_e,{children:n("Enter the export password to decrypt and preview this package.")})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(pn,{htmlFor:"config-import-password",children:n("Password")}),e.jsx(J,{id:"config-import-password",type:"password",autoFocus:!0,autoComplete:"current-password",value:o,"aria-invalid":!!y,onChange:b=>{i(b.target.value),N(null)},onKeyDown:b=>{b.key==="Enter"&&o.length>0&&!k&&L("merge",o)}})]}),y&&e.jsxs("p",{className:"flex items-center gap-1.5 text-xs text-destructive",role:"alert",children:[e.jsx(At,{className:"h-3.5 w-3.5 shrink-0"}),y]})]}),a==="preview"&&e.jsxs(we,{className:"max-h-[58vh] space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium",children:n("Import mode")}),e.jsxs(ym,{value:d,onValueChange:b=>E(b),className:"grid gap-2 sm:grid-cols-2","aria-label":n("Import mode"),children:[e.jsxs("label",{className:"flex cursor-pointer items-start gap-2.5 rounded-md border px-3 py-2.5",children:[e.jsx(Aa,{value:"merge",disabled:k!==null}),e.jsxs("span",{children:[e.jsx("span",{className:"block text-sm font-medium",children:n("Merge")}),e.jsx("span",{className:"block text-xs text-muted-foreground",children:n("Add and update matching items while keeping items only on this device.")})]})]}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-2.5 rounded-md border px-3 py-2.5",children:[e.jsx(Aa,{value:"replace",disabled:k!==null}),e.jsxs("span",{children:[e.jsx("span",{className:"block text-sm font-medium",children:n("Replace")}),e.jsx("span",{className:"block text-xs text-muted-foreground",children:n("Replace transferred item categories, removing local-only items in them.")})]})]})]})]}),k==="preview"&&e.jsxs("div",{className:"flex items-center justify-center gap-2 rounded-md border border-dashed py-10",children:[e.jsx(Ae,{className:"h-4 w-4 animate-spin text-muted-foreground"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:n("Preparing preview…")})]}),!k&&x&&e.jsx("div",{className:"overflow-hidden rounded-md border",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted/50 text-xs text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",className:"px-3 py-2 text-left font-medium",children:n("Category")}),e.jsx("th",{scope:"col",className:"px-3 py-2 text-right font-medium",children:n("Added")}),e.jsx("th",{scope:"col",className:"px-3 py-2 text-right font-medium",children:n("Updated")}),e.jsx("th",{scope:"col",className:"px-3 py-2 text-right font-medium",children:n("Skipped")}),e.jsx("th",{scope:"col",className:"px-3 py-2 text-right font-medium",children:n("Removed")})]})}),e.jsx("tbody",{children:wm.map(({category:b,label:_})=>{const K=x.find(D=>D.category===b);return e.jsxs("tr",{className:"border-t first:border-t-0",children:[e.jsx("th",{scope:"row",className:"px-3 py-2 text-left font-medium",children:n(_)}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:K?.added??0}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:K?.updated??0}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:K?.skipped??0}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:K?.removed??0})]},b)})})]})}),!k&&x?.find(b=>b.category==="settings")?.fields?.length?e.jsxs("p",{className:"text-xs text-muted-foreground",children:[n("Portable settings changed:")," ",x.find(b=>b.category==="settings")?.fields?.join(", ")]}):null,d==="replace"&&x&&!k&&e.jsxs(Be,{variant:"error",children:[e.jsx(Ue,{}),e.jsx(Ct,{children:n("Local-only configuration will be deleted")}),e.jsx(_e,{children:n("Items in transferred collections that exist only on this device will be removed. Removed counts are shown above. Included portable preferences are overwritten. A complete backup is created first.")})]}),l.map(b=>e.jsxs(Be,{variant:"warning",children:[e.jsx(Ue,{}),e.jsx(_e,{children:n(b)})]},b)),x&&!k&&e.jsxs(Be,{variant:"warning",children:[e.jsx(In,{}),e.jsx(Ct,{children:n("Only import packages you trust")}),e.jsx(_e,{children:n("An imported package can change portable preferences and configuration. Skills and MCP servers may also run commands later when you use them. Previewing does not execute them; continue only if you trust the package.")})]}),y&&e.jsxs(Be,{variant:"error",children:[e.jsx(At,{}),e.jsx(_e,{children:y})]})]}),a==="success"&&c&&e.jsxs(we,{className:"space-y-4",children:[e.jsxs(Be,{variant:"success",children:[e.jsx(po,{}),e.jsx(Ct,{children:n("Import complete")}),e.jsxs(_e,{children:[e.jsx("p",{children:n("Backup of previous settings:")}),e.jsx("p",{className:"break-all font-mono text-xs text-foreground",children:c})]})]}),g&&e.jsxs(Be,{variant:"warning",children:[e.jsx(Ue,{}),e.jsx(_e,{children:n("Reopen Settings to load the imported configuration in this window.")})]}),l.map(b=>e.jsxs(Be,{variant:"warning",children:[e.jsx(Ue,{}),e.jsx(_e,{children:n(b)})]},b))]}),e.jsxs(Ie,{children:[a==="password"&&e.jsxs(e.Fragment,{children:[e.jsx(S,{variant:"outline",size:"sm",disabled:k!==null,onClick:C,children:n("Cancel")}),e.jsxs(S,{size:"sm",disabled:k!==null||o.length===0,onClick:()=>{L("merge",o)},children:[k==="preview"&&e.jsx(Ae,{className:"h-3.5 w-3.5 animate-spin"}),n("Preview")]})]}),a==="preview"&&e.jsxs(e.Fragment,{children:[e.jsx(S,{variant:"outline",size:"sm",disabled:k!==null,onClick:C,children:n("Cancel")}),y&&!x?e.jsx(S,{size:"sm",disabled:k!==null,onClick:()=>{L(d)},children:n("Refresh preview")}):e.jsxs(S,{variant:d==="replace"?"destructive":"default",size:"sm",disabled:k!==null||!x,onClick:()=>{x&&(V?O(!0):F())},children:[k==="commit"?e.jsx(Ae,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Sn,{className:"h-3.5 w-3.5"}),n(k==="commit"?"Importing…":"Import")]})]}),a==="success"&&e.jsx(S,{size:"sm",onClick:C,children:n("Done")})]})]}),e.jsx(Sm,{open:A,mode:d,hasImportedExecutableResources:M,onOpenChange:O,onConfirm:()=>{F()}})]})}function Sm({open:t,mode:s,hasImportedExecutableResources:n,onOpenChange:a,onConfirm:r}){const{t:o}=z();return e.jsx(An,{open:t,onOpenChange:a,children:e.jsxs(En,{className:"sm:max-w-md",zIndexLevel:"nested",children:[e.jsxs(Mn,{children:[e.jsxs(Pn,{className:"flex items-start gap-2 text-base",children:[e.jsx(Ue,{className:"mt-0.5 h-4 w-4 shrink-0 text-destructive"}),o("Confirm configuration import")]}),e.jsxs(Tn,{className:"space-y-2",children:[e.jsx("span",{className:"block",children:o("This package can change portable preferences and configuration. Continue only if you trust this package.")}),n&&e.jsx("span",{className:"block",children:o("It includes skills or MCP servers that may execute commands when you use them.")}),s==="replace"&&e.jsx("span",{className:"block",children:o("Replace mode removes local-only items from transferred collections and overwrites included portable preferences. A complete backup will be created first.")}),e.jsx("span",{className:"block",children:o("Do you want to continue with this import?")})]})]}),e.jsxs(Rn,{variant:"bare",children:[e.jsx(On,{render:e.jsx(S,{variant:"outline",size:"sm"}),children:o("Cancel")}),e.jsx(S,{variant:s==="replace"?"destructive":"default",size:"sm",onClick:()=>{a(!1),r()},children:o("Confirm import")})]})]})})}const Ea={auto:"Auto (by usage)",fast:"Fast",balanced:"Balanced",thorough:"Thorough"},Ma={standard:"Standard",smart:"Smart compaction","codex-native":"Codex native compaction","continuous-memory":"Continuous memory (experimental)"};function Im(){const{t}=z(),s=v(c=>c.compactStrategy),n=v(c=>c.smartCompactEnabled),a=Sl(s,n),r=v(c=>c.setCompactStrategy),o=a!=="standard",i=v(c=>c.smartCompactModel),d=v(c=>c.setSmartCompactModel),u=v(c=>c.smartCompactMode),x=v(c=>c.setSmartCompactMode),h=Xe(),l=i?h.find(c=>c.id===i.providerId):void 0,f=l?.models.find(c=>c.id===i?.modelId);return e.jsxs("section",{className:"space-y-2 rounded-lg border bg-card p-3","data-settings-row":"general.smartCompactEnabled",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("h4",{className:"font-medium text-sm",children:[t("Context compaction strategy"),e.jsx(qe,{})]}),e.jsx("p",{className:"mt-0.5 text-muted-foreground text-xs",children:t("Standard uses default compact. Smart compaction uses Enso verified summary at compact time. Codex native compaction additionally stores an official Codex checkpoint on Codex models and uses smart compaction otherwise. Continuous memory records observations in the background so compact keeps more context; all fall back to default compact on failure. Switching strategy takes effect on the next session. The summary model and compaction mode apply to open conversations on the next compaction.")})]}),e.jsxs(ae,{items:Object.fromEntries(ia.map(c=>[c,t(Ma[c])])),value:a,onValueChange:c=>r(c),children:[e.jsx(re,{className:"w-52",children:e.jsx(oe,{})}),e.jsx(ie,{children:ia.map(c=>e.jsx(ee,{value:c,children:t(Ma[c])},c))})]})]}),(a==="smart"||a==="codex-native")&&e.jsxs("div",{className:"flex items-center justify-between gap-4","data-smart-compact-mode":u,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Compaction mode")}),e.jsx("p",{className:"mt-0.5 text-muted-foreground/80 text-[11px]",children:t("Mode changes summary budget and how much recent tail to keep. It does not decide whether compact runs.")})]}),e.jsxs(ae,{items:Object.fromEntries(la.map(c=>[c,t(Ea[c])])),value:u,onValueChange:c=>x(c),children:[e.jsx(re,{className:"w-36",children:e.jsx(oe,{})}),e.jsx(ie,{children:la.map(c=>e.jsx(ee,{value:c,children:t(Ea[c])},c))})]})]}),o&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"font-medium text-sm",children:t(a==="continuous-memory"?"Background memory model":"Summary model")}),h.length>0&&e.jsx("div",{className:"w-full min-w-0",children:e.jsx(ze,{providers:h,providerId:l?.id??"",modelId:f?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:t("Follows the session model"),side:"bottom",triggerClassName:Ye,onSelect:(c,p)=>d({providerId:c,modelId:p}),onReasoningChange:()=>{},onThinkingChange:()=>{}})}),i&&(!l||!f)&&e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Selected model is unavailable — falls back to the session model.")}),i&&e.jsx(S,{variant:"ghost",size:"sm",className:"self-start",onClick:()=>d(null),children:t("Follow session model")})]})]})}const Am={cmd:"Command Prompt",powershell:"Windows PowerShell",pwsh:"PowerShell 7 (pwsh)","git-bash":"Git Bash",zsh:"zsh",bash:"bash",fish:"fish"};function Em(){const{language:t,setLanguage:s}=v(),{t:n}=z();return e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:n("General")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:n("General application settings")})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h4",{className:"border-b pb-2 text-base font-semibold",children:n("Application")}),e.jsxs("div",{className:"flex items-center gap-3","data-settings-row":"general.language",children:[e.jsx("span",{className:"text-sm font-medium",children:n("Language")}),e.jsxs(ae,{items:{en:"English",zh:"简体中文"},value:t,onValueChange:a=>s(a),children:[e.jsx(re,{className:"w-48",children:e.jsx(oe,{})}),e.jsxs(ie,{children:[e.jsx(ee,{value:"en",children:"English"}),e.jsx(ee,{value:"zh",children:"简体中文"})]})]})]}),e.jsx(Mm,{}),e.jsx(Bm,{}),e.jsx(Nm,{}),e.jsx(_m,{})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h4",{className:"border-b pb-2 text-base font-semibold",children:n("Agent runtime")}),e.jsx(Pm,{}),e.jsx(Tm,{}),e.jsx(Im,{}),e.jsx(xm,{})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h4",{className:"border-b pb-2 text-base font-semibold",children:n("Sessions & worktrees")}),e.jsx(Om,{}),e.jsx(Rm,{}),e.jsx(Lm,{})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h4",{className:"border-b pb-2 text-base font-semibold",children:n("Terminal")}),e.jsx(zm,{}),e.jsx(Dm,{})]}),window.electronAPI.env.platform==="darwin"&&e.jsxs("section",{className:"space-y-3",children:[e.jsx("h4",{className:"border-b pb-2 text-base font-semibold",children:n("Integrations")}),e.jsx(Pa,{kind:"ensoCommand",title:n("'enso' terminal command"),description:n("Run `enso .` in a terminal to open the current folder in EnsoCode. Links the command into /usr/local/bin and may ask for your password.")}),e.jsx(Pa,{kind:"finderQuickAction",title:n("Finder Quick Action"),description:n("Right-click a folder in Finder and choose Services > Open with EnsoCode.")})]})]})}function Pa({kind:t,title:s,description:n}){const{t:a}=z(),[r,o]=m.useState(!1),[i,d]=m.useState(!1);m.useEffect(()=>{let x=!0;const h=()=>{window.electronAPI.window.shellIntegrationStatus().then(l=>{x&&o(l[t])})};return h(),window.addEventListener("focus",h),()=>{x=!1,window.removeEventListener("focus",h)}},[t]);const u=async()=>{d(!0);try{await window.electronAPI.window.installShellIntegration(t)}finally{try{const x=await window.electronAPI.window.shellIntegrationStatus();o(x[t])}finally{d(!1)}}};return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":`general.${t}`,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n})]}),e.jsx(S,{variant:"outline",size:"sm",className:"shrink-0",disabled:i,onClick:()=>{u()},children:a(i?"In progress…":r?"Uninstall":"Install")})]})}function Mm(){const{t}=z(),s=v(a=>a.notifyMainAgentOnly),n=v(a=>a.setNotifyMainAgentOnly);return e.jsx(Te,{rowId:"general.notifyMainAgentOnly",title:t("Notify only for the main agent"),description:t("Skip coworker completion and failure notifications on this computer and the paired phone. Questions and approvals still notify."),checked:s,onChange:n})}function Pm(){const{t}=z(),s=v(a=>a.generationStallTimeoutMin),n=v(a=>a.setGenerationStallTimeoutMin);return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.generationStallTimeout",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Stop if no output")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Abort and retry the run when no tokens or tool results arrive for this long. Thinking counts as output.")})]}),e.jsxs(ae,{items:Object.fromEntries(ca.map(a=>[String(a),a===0?t("Never"):t("{{count}} min",{count:a})])),value:String(s),onValueChange:a=>n(Number(a)),children:[e.jsx(re,{className:"w-28",children:e.jsx(oe,{})}),e.jsx(ie,{children:ca.map(a=>e.jsx(ee,{value:String(a),children:a===0?t("Never"):t("{{count}} min",{count:a})},a))})]})]})}function Tm(){const{t}=z(),s=v(o=>o.autoRetryLimit),n=v(o=>o.setAutoRetryLimit),a=js.some(o=>o===s)?[...js]:[...js,s].sort((o,i)=>o===vs?1:i===vs?-1:o-i),r=o=>o===0?t("Off"):o===vs?t("Unlimited"):t("{{count}} times",{count:o});return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.autoRetryLimit",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Auto-retry on transient errors")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Retry with backoff (up to 60s apart) after 429, 5xx or network errors. Quota and billing errors are never retried. Unlimited keeps retrying until you cancel.")})]}),e.jsxs(ae,{items:Object.fromEntries(a.map(o=>[String(o),r(o)])),value:String(s),onValueChange:o=>n(Number(o)),children:[e.jsx(re,{className:"w-28",children:e.jsx(oe,{})}),e.jsx(ie,{children:a.map(o=>e.jsx(ee,{value:String(o),children:r(o)},o))})]})]})}function Rm(){const{t}=z(),s=v(r=>r.activeRetentionMinutes),n=v(r=>r.setActiveRetentionMinutes),a=r=>r===0?t("Off"):t("{{count}} min",{count:r});return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.activeRetentionMinutes",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Keep in Active after last message")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Viewed conversations stay in Active for this long after their last message or your last open while still in Active, then leave. Unviewed ones stay until you open them.")})]}),e.jsxs(ae,{items:Object.fromEntries(ma.map(r=>[String(r),a(r)])),value:String(s),onValueChange:r=>n(Number(r)),children:[e.jsx(re,{className:"w-28",children:e.jsx(oe,{})}),e.jsx(ie,{children:ma.map(r=>e.jsx(ee,{value:String(r),children:a(r)},r))})]})]})}function Wt(t,s){return s===0?t("Never"):s===1?t("{{count}} day",{count:s}):t("{{count}} days",{count:s})}function Om(){const{t}=z(),s=v(d=>d.autoArchiveIdleDays),n=v(d=>d.setAutoArchiveIdleDays),a=v(d=>d.autoArchiveMergedWorktrees),r=v(d=>d.setAutoArchiveMergedWorktrees),o=v(d=>d.autoDeleteArchivedDays),i=v(d=>d.setAutoDeleteArchivedDays);return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.autoArchiveIdleDays",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Archive idle conversations")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Move conversations that have been idle this long into Archived. Does not delete them.")})]}),e.jsxs(ae,{items:Object.fromEntries(da.map(d=>[String(d),Wt(t,d)])),value:String(s),onValueChange:d=>n(Number(d)),children:[e.jsx(re,{className:"w-28",children:e.jsx(oe,{})}),e.jsx(ie,{children:da.map(d=>e.jsx(ee,{value:String(d),children:Wt(t,d)},d))})]})]}),e.jsx(Te,{rowId:"general.autoArchiveMergedWorktrees",title:t("Clean up merged worktrees"),description:t("When archiving idle conversations, also remove isolated worktrees that are merged and clean."),checked:a,onChange:r}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.autoDeleteArchivedDays",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Delete archived conversations after")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Permanently delete conversations that have been archived longer than this. This cannot be undone. Choosing a positive value deletes already-overdue archived conversations immediately.")})]}),e.jsxs(ae,{items:Object.fromEntries(ua.map(d=>[String(d),Wt(t,d)])),value:String(o),onValueChange:d=>i(Number(d)),children:[e.jsx(re,{className:"w-28",children:e.jsx(oe,{})}),e.jsx(ie,{children:ua.map(d=>e.jsx(ee,{value:String(d),children:Wt(t,d)},d))})]})]})]})}function Dm(){const{t}=z(),s=v(o=>o.terminalShell),n=v(o=>o.setTerminalShell),a=Al(window.electronAPI.env.platform),r=Object.fromEntries(a.map(o=>[o,o==="auto"?t("System default"):Am[o]]));return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.terminalShell",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Terminal shell")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Applies to new side panel terminals. SSH projects keep the remote login shell.")})]}),e.jsxs(ae,{items:r,value:s,onValueChange:o=>n(o),children:[e.jsx(re,{className:"w-56",children:e.jsx(oe,{})}),e.jsx(ie,{children:a.map(o=>e.jsx(ee,{value:o,children:r[o]},o))})]})]})}function Lm(){const{t}=z(),s=v(x=>x.worktreeRoot),n=v(x=>x.setWorktreeRoot),[a,r]=m.useState(s),[o,i]=m.useState(null);m.useEffect(()=>{r(s)},[s]);const d=x=>{const h=x.trim();if(h&&!dm(h)){i(t("Enter an absolute path"));return}i(null),n(h)},u=async()=>{const x=await window.electronAPI.dialog.selectDirectory();x&&(r(x),d(x))};return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.worktreeRoot",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Worktree root directory")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Where isolated session worktrees are created. Leave empty to use the app data directory. Existing worktrees stay where they are.")})]}),e.jsxs("div",{className:"w-72 shrink-0 space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(J,{value:a,placeholder:t("Default location"),onChange:x=>r(x.target.value),onBlur:()=>d(a),onKeyDown:x=>{x.key==="Enter"&&d(a)}}),e.jsx(S,{variant:"outline",size:"sm",className:"shrink-0",onClick:()=>{u()},children:t("Browse")})]}),o&&e.jsx("p",{className:"text-xs text-destructive",children:o})]})]})}function zm(){const{t}=z(),s=v(r=>r.windowsLocalShell),n=v(r=>r.setWindowsLocalShell),a={auto:t("Windows default (PowerShell)"),powershell:t("PowerShell"),bash:t("Git Bash")};return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.windowsLocalShell",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"text-sm",children:[t("Windows local command shell"),e.jsx(qe,{})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Only the Windows local agent command tool. SSH and other platforms stay on bash. Takes effect on the next session.")})]}),e.jsxs(ae,{items:a,value:s,onValueChange:r=>n(r),children:[e.jsx(re,{className:"w-56",children:e.jsx(oe,{})}),e.jsx(ie,{children:Object.keys(a).map(r=>e.jsx(ee,{value:r,children:a[r]},r))})]})]})}function Te({title:t,description:s,checked:n,onChange:a,rowId:r,children:o}){return e.jsxs("div",{className:"rounded-md border px-3 py-2.5","data-settings-row":r,children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s})]}),e.jsx(le,{checked:n,onCheckedChange:i=>a(i===!0)})]}),o?e.jsx("div",{className:"mt-2",children:o}):null]})}function Ta(t,s){window.electronAPI.proxy.apply({mode:t,customUrl:s})}function Bm(){const{t}=z(),s=v(l=>l.proxyMode),n=v(l=>l.customProxyUrl),a=v(l=>l.setProxyMode),r=v(l=>l.setCustomProxyUrl),[o,i]=m.useState(n),[d,u]=m.useState(null);m.useEffect(()=>{i(n)},[n]);const x=l=>{a(l),Ta(l,n)},h=()=>{const l=o.trim();if(l&&!El(l)){u(t("Enter an http(s) proxy URL"));return}u(null),r(l),Ta(s,l)};return e.jsxs("div",{className:"space-y-3","data-settings-row":"general.proxy",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium",children:t("Network proxy")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Used by model requests, the built-in browser, and agent tools")})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-sm font-medium",children:t("Proxy mode")}),e.jsxs(ae,{items:{system:t("Follow system proxy"),none:t("No proxy"),custom:t("Custom proxy")},value:s,onValueChange:l=>x(l),children:[e.jsx(re,{className:"w-56",children:e.jsx(oe,{})}),e.jsxs(ie,{children:[e.jsx(ee,{value:"system",children:t("Follow system proxy")}),e.jsx(ee,{value:"none",children:t("No proxy")}),e.jsx(ee,{value:"custom",children:t("Custom proxy")})]})]})]}),s==="custom"&&e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"pt-1.5 text-sm font-medium",children:t("Proxy URL")}),e.jsxs("div",{className:"min-w-0 space-y-1",children:[e.jsx(J,{value:o,placeholder:"http://127.0.0.1:7890",onChange:l=>i(l.target.value),onBlur:h,onKeyDown:l=>{l.key==="Enter"&&h()}}),d&&e.jsx("p",{className:"text-xs text-destructive",children:d})]})]})]})}function _m(){const{t}=z(),s=v(y=>y.autoUpdate),n=v(y=>y.setAutoUpdate),a=v(y=>y.autoRestartWhenIdle),r=v(y=>y.setAutoRestartWhenIdle),[o,i]=m.useState(null),[d,u]=m.useState(null),[x,h]=m.useState(!1),[l,f]=m.useState(!1);m.useEffect(()=>{let y=!0;window.electronAPI.updater.getState().then(A=>{y&&(u(A),A.status&&i(O=>O??A.status))}).catch(()=>{});const N=window.electronAPI.updater.onStatus(i);return()=>{y=!1,N()}},[]);const c=d?.host==="server"?d:null,p=d?.host==="desktop"||c!==null&&c.mode!=="manual",g=(o?.status==="available"||o?.status==="downloaded")&&!!o.info,k=(()=>{if(!o)return null;switch(o.status){case"checking":return t("Checking for updates…");case"available":return t("New version {{version}} found",{version:o.info?.version??""});case"not-available":return t("You are on the latest version");case"downloading":return t("Downloading update… {{percent}}%",{percent:Math.round(o.progress?.percent??0)});case"downloaded":return t("New version {{version}} is ready — restart to update.",{version:o.info?.version??""});case"error":return c&&o.error?t("Update failed: {{error}}",{error:o.error}):t("Update check failed");default:return null}})(),j=o?.status==="checking"||o?.status==="downloading";return e.jsxs("div",{className:"space-y-3","data-settings-row":"general.updates",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium",children:t("Updates")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:c?Fm(c.mode,t):t("Application update settings")})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"text-sm",children:[t("Current version")," · ",Um]}),k&&e.jsx("p",{className:"mt-0.5 truncate text-xs text-muted-foreground",children:k})]}),g&&e.jsx(S,{variant:"ghost",size:"sm",onClick:()=>f(!0),className:"ml-auto shrink-0",children:t("Release notes")}),o?.status==="downloaded"?e.jsx(S,{size:"sm",onClick:()=>{window.electronAPI.updater.quitAndInstall()},className:"shrink-0",children:t("Restart to update")}):p&&o?.status==="available"?e.jsx(S,{size:"sm",onClick:()=>{window.electronAPI.updater.downloadUpdate()},className:"shrink-0",children:t("Download update")}):e.jsx(S,{variant:"outline",size:"sm",disabled:j,onClick:()=>{window.electronAPI.updater.checkForUpdates()},className:"shrink-0",children:t("Check for updates")}),e.jsx(Il,{open:l,onOpenChange:f,status:o,canDownload:p})]}),c?.canRestart&&e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Restart server")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Running tasks are interrupted; this page reconnects after the server is back.")})]}),e.jsx(S,{variant:"outline",size:"sm",onClick:()=>h(!0),className:"shrink-0",children:t("Restart")}),e.jsx(fo,{open:x,onOpenChange:h,title:t("Restart server?"),description:t("Running tasks are interrupted; this page reconnects after the server is back."),confirmLabel:t("Restart"),onConfirm:()=>{h(!1),window.electronAPI.updater.restart()}})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Automatic updates")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Download and install updates automatically")})]}),e.jsx(le,{checked:s,onCheckedChange:y=>{n(y),window.electronAPI.updater.setAutoUpdateEnabled(y)}})]}),e.jsxs("div",{className:`flex items-center justify-between gap-3 rounded-md border px-3 py-2.5 ${s?"":"opacity-60"}`,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Restart and apply when idle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("After the update is downloaded, restart automatically if no agent is running, nothing is queued, and there are no pending questions or approvals. The idle state must last 5 minutes, and a focused window also blocks it.")})]}),e.jsx(le,{checked:s&&a,disabled:!s,onCheckedChange:y=>{r(y),window.electronAPI.updater.setAutoRestartWhenIdle(y)}})]})]})}function Fm(t,s){return s(t==="npm"?"Server updates install the new version with npm and restart.":"This server must be updated on the machine itself.")}const Um="0.3.5",$m=["100%","100%","70%","100%","55%"],Vm=["100%","85%","60%"];function Km({palette:t}){return e.jsxs("div",{className:"flex h-[88px] gap-1.5 p-[7px]",style:{background:t.canvas},children:[e.jsxs("div",{className:"flex w-[30%] flex-col gap-[5px] px-0.5 py-1",children:[e.jsx("i",{className:"block h-[9px] rounded-[3px] opacity-[.18]",style:{background:t.text}}),$m.slice(1).map((s,n)=>e.jsx("i",{className:"block h-[5px] rounded-[3px] opacity-55",style:{background:t.textSubtle,width:s}},n))]}),e.jsxs("div",{className:"flex flex-1 flex-col gap-[5px] rounded-md px-2.5 py-2",style:{background:t.surface,boxShadow:`0 0 0 1px ${t.border}`},children:[e.jsx("i",{className:"block h-1 w-[70%] rounded-sm opacity-75",style:{background:t.text}}),Vm.map(s=>e.jsx("i",{className:"block h-1 rounded-sm opacity-50",style:{background:t.textSubtle,width:s}},s)),e.jsx("b",{className:"mt-auto flex h-3.5 justify-end rounded-full p-[3px]",style:{background:t.sunken,boxShadow:`0 0 0 1px ${t.border}`},children:e.jsx("span",{"data-theme-accent":!0,className:"size-2 rounded-full",style:{background:t.accent}})})]})]})}const Ra="overflow-hidden rounded-lg border text-left transition-shadow";function qm({themes:t,selected:s,mode:n,onSelect:a,onGetMore:r}){const{t:o}=z();return e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[t.map(i=>{const d=i.id===s;return e.jsxs("button",{type:"button","data-theme-card":i.id,"aria-pressed":d,onClick:()=>a(i.id),className:G(Ra,"bg-card",d?"border-transparent shadow-[0_0_0_2px_var(--brand)]":"hover:border-input"),children:[e.jsx(Km,{palette:i[n]}),e.jsxs("div",{className:"flex items-center gap-1.5 border-t px-2.5 py-[7px] text-sm",children:[e.jsx("span",{className:"truncate font-medium",children:i.name}),e.jsx("span",{className:G("ml-auto shrink-0 truncate rounded-full px-1.5 py-px text-[10.5px]",i.source.kind==="plugin"?"max-w-[60%] bg-brand/12 text-brand":"bg-muted text-subtle-foreground"),children:i.source.kind==="plugin"?o("Plugin · {{name}}",{name:i.source.pluginName}):o("Built-in")})]})]},i.id)}),r&&e.jsxs("button",{type:"button",onClick:r,className:G(Ra,"flex min-h-[124px] flex-col items-center justify-center gap-1.5 border-dashed text-sm text-subtle-foreground hover:border-input hover:text-foreground"),children:[e.jsx(_t,{className:"size-[18px]"}),o("Get more themes")]})]})}function gn({rowId:t,title:s,description:n,children:a}){return e.jsxs("div",{"data-settings-row":t,className:"flex min-h-12 items-center justify-between gap-4 px-3.5 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium",children:s}),n&&e.jsx("p",{className:"text-xs text-muted-foreground",children:n})]}),e.jsx("div",{className:"flex shrink-0 items-center gap-2",children:a})]})}function Gm({children:t}){return e.jsx("div",{className:"divide-y rounded-lg border bg-card",children:t})}function tt({label:t,value:s,onCommit:n,min:a=0,max:r=100,step:o,unit:i="%",formatSuffix:d,onPreview:u,trailing:x,valueClassName:h="w-12"}){const[l,f]=m.useState(s);m.useEffect(()=>{f(s)},[s]);const c=d?.(l);return e.jsxs("div",{className:G("grid items-center gap-4",x?"grid-cols-[9.5rem_minmax(0,1fr)_auto]":"grid-cols-[100px_1fr]"),children:[e.jsx("span",{className:"text-sm font-medium",children:t}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Bl,{min:a,max:r,step:o,value:l,onValueChange:p=>{const g=Array.isArray(p)?p[0]:p;f(g),u?.(g)},onValueCommitted:p=>n(Array.isArray(p)?p[0]:p)}),e.jsxs("span",{className:G("shrink-0 text-right text-sm text-muted-foreground tabular-nums",c?"w-28":h),children:[l,i,c?` · ${c}`:""]})]}),x]})}function Hm(){const{t}=z(),s=v(P=>P.backgroundImageEnabled),n=v(P=>P.setBackgroundImageEnabled),a=v(P=>P.backgroundSourceType),r=v(P=>P.setBackgroundSourceType),o=v(P=>P.backgroundImagePath),i=v(P=>P.setBackgroundImagePath),d=v(P=>P.backgroundFolderPath),u=v(P=>P.setBackgroundFolderPath),x=v(P=>P.backgroundUrlPath),h=v(P=>P.setBackgroundUrlPath),l=v(P=>P.backgroundRandomEnabled),f=v(P=>P.setBackgroundRandomEnabled),c=v(P=>P.backgroundRandomInterval),p=v(P=>P.setBackgroundRandomInterval),g=v(P=>P.backgroundOpacity),w=v(P=>P.setBackgroundOpacity),k=v(P=>P.backgroundBlur),j=v(P=>P.setBackgroundBlur),y=v(P=>P.backgroundBrightness),N=v(P=>P.setBackgroundBrightness),A=v(P=>P.backgroundSaturation),O=v(P=>P.setBackgroundSaturation),I=v(P=>P.backgroundMask),L=v(P=>P.setBackgroundMask),C=v(P=>P.backgroundComposerOpacity),E=v(P=>P.setBackgroundComposerOpacity),M=v(P=>P.backgroundCodeOpacity),V=v(P=>P.setBackgroundCodeOpacity),F=v(P=>P.backgroundSizeMode),b=v(P=>P.setBackgroundSizeMode),_=v(P=>P.bumpBackgroundRefresh),K=_l()?.source==="theme",D=a==="file"?o:a==="folder"?d:x,[$,Y]=m.useState(D);m.useEffect(()=>{Y(D)},[D]);const H=m.useCallback(()=>{const P=$.trim();a==="file"?i(P):a==="folder"?u(P):h(P)},[$,a,i,u,h]),[se,q]=m.useState(c);m.useEffect(()=>{q(c)},[c]);const Q=async()=>{if(a==="folder"){const P=await window.electronAPI.dialog.selectDirectory();P&&u(P)}else{const P=await window.electronAPI.dialog.selectFile([...$l,...Vl]);P&&i(P)}},B=[{value:"file",label:t("Single image")},{value:"folder",label:t("Folder (random)")},{value:"url",label:t("Remote URL")}],ne=[{value:"cover",label:t("Cover")},{value:"contain",label:t("Contain")},{value:"repeat",label:t("Repeat")},{value:"center",label:t("Center")}],R=t(a==="file"?"Image path":a==="folder"?"Folder path":"Image URL");return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between border-t pt-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:t("Background image")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("Show a custom image behind the interface")})]}),e.jsx(le,{checked:s,onCheckedChange:P=>n(P===!0)})]}),K&&e.jsx("p",{className:"text-sm text-muted-foreground",children:t("The current theme has its own background. Turn this on to replace it with your image.")}),s&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:t("Source type")}),e.jsxs(ae,{items:B,value:a,onValueChange:P=>r(P),children:[e.jsx(re,{className:"w-48",children:e.jsx(oe,{})}),e.jsx(ie,{children:B.map(P=>e.jsx(ee,{value:P.value,children:P.label},P.value))})]})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:R}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(J,{value:$,onChange:P=>Y(P.target.value),onBlur:H,onKeyDown:P=>{P.nativeEvent.isComposing||P.key==="Enter"&&(H(),P.currentTarget.blur())},placeholder:a==="url"?"https://example.com/image.jpg":"",className:"flex-1"}),a!=="url"&&e.jsx(S,{variant:"outline",size:"icon",onClick:Q,"aria-label":t("Browse"),children:a==="folder"?e.jsx(Bn,{className:"h-4 w-4"}):e.jsx(Ou,{className:"h-4 w-4"})}),a!=="file"&&e.jsx(S,{variant:"outline",size:"icon",onClick:_,"aria-label":t("Refresh now"),children:e.jsx(Je,{className:"h-4 w-4"})})]})]}),a!=="file"&&e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:t("Auto switch")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(le,{checked:l,onCheckedChange:P=>f(P===!0)}),l&&e.jsxs(e.Fragment,{children:[e.jsx(J,{type:"number",min:5,max:86400,value:se,onChange:P=>q(Number(P.target.value)),onBlur:()=>p(se),onKeyDown:P=>{P.key==="Enter"&&(p(se),P.currentTarget.blur())},className:"w-24"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:t("seconds")})]})]})]}),e.jsx(tt,{label:t("Background visibility"),value:Math.round(g*100),onCommit:P=>w(P/100)}),e.jsx(tt,{label:t("Blur"),value:k,onCommit:j,max:20,unit:"px"}),e.jsx(tt,{label:t("Brightness"),value:Math.round(y*100),onCommit:P=>N(P/100),max:200}),e.jsx(tt,{label:t("Saturation"),value:Math.round(A*100),onCommit:P=>O(P/100),max:200}),e.jsx(tt,{label:t("Overlay"),value:Math.round(I*100),onCommit:P=>L(P/100)}),e.jsx(tt,{label:t("Composer opacity"),value:Math.round(C*100),onCommit:P=>E(P/100)}),e.jsx(tt,{label:t("Code block opacity"),value:Math.round(M*100),onCommit:P=>V(P/100)}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:t("Size mode")}),e.jsxs(ae,{items:ne,value:F,onValueChange:P=>b(P),children:[e.jsx(re,{className:"w-48",children:e.jsx(oe,{})}),e.jsx(ie,{children:ne.map(P=>e.jsx(ee,{value:P.value,children:P.label},P.value))})]})]})]})]})}function Wm({theme:t,fontSize:s,fontFamily:n,fontWeight:a}){const r=[{id:"prompt1",text:"$ ",color:t.green},{id:"cmd1",text:"ls -la",color:t.foreground},{id:"nl1",text:`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./globals-BJ2xID1e.js","./globals-l3kDGoYH.css"])))=>i.map(i=>d[i]);
2
+ import{c as Ee,w as $i,D as sa,j as e,A as Vi,r as m,u as ro,a as oo,b as Cn,d as io,t as lo,C as na,e as G,I as J,f as Ki,X as ht,h as qi,i as Gi,Z as st,k as Hi,S as Wi,l as Yi,m as Ji,n as Qi,o as Xi,p as z,q as v,B as S,s as pe,v as fe,x as ge,y as je,z as Ve,E as we,F as Qe,G as Ie,H as co,J as Re,K as aa,L as Zi,M as Xt,N as Zt,O as ae,P as re,Q as oe,R as ie,T as ee,U as el,V as qe,W as tl,Y as sl,_ as uo,$ as nl,a0 as fs,a1 as mo,a2 as al,a3 as ho,a4 as rl,a5 as ra,a6 as xo,a7 as ol,a8 as il,a9 as ll,aa as oa,ab as cl,ac as dl,ad as ul,ae as ml,af as hl,ag as xl,ah as pl,ai as fl,aj as gl,ak as jl,al as vl,am as gs,an as bl,ao as yl,ap as wl,aq as Nl,ar as kl,as as Cl,at as Ae,au as Sn,av as ss,aw as _e,ax as po,ay as Ct,az as Be,aA as Ue,aB as In,aC as At,aD as An,aE as En,aF as Mn,aG as Pn,aH as Tn,aI as Rn,aJ as On,aK as Xe,aL as ia,aM as la,aN as ze,aO as Ye,aP as Sl,aQ as Il,aR as fo,aS as le,aT as ca,aU as js,aV as da,aW as ua,aX as ma,aY as Al,aZ as El,a_ as vs,a$ as Bt,b0 as go,b1 as Dn,b2 as Ml,b3 as Ln,b4 as jo,b5 as Pl,b6 as Tl,b7 as Rl,b8 as vo,b9 as Ol,ba as Dl,bb as Ll,bc as bo,bd as Mt,be as Gt,bf as zl,bg as zn,bh as _l,bi as Bl,bj as _n,bk as Je,bl as Fl,bm as Ul,bn as yo,bo as $l,bp as Vl,bq as Kl,br as wo,bs as Bn,bt as Oe,bu as te,bv as Me,bw as ql,bx as Gl,by as Hl,bz as Wl,bA as Yl,bB as ha,bC as Jl,bD as Ql,bE as Ft,bF as Ut,bG as Ke,bH as Dt,bI as cn,bJ as Xl,bK as Zl,bL as dn,bM as lt,bN as No,bO as ec,bP as tc,bQ as Fn,bR as sc,bS as xa,bT as ko,bU as nc,bV as ac,bW as Co,bX as Fe,bY as rc,bZ as ns,b_ as oc,b$ as pa,c0 as ic,c1 as lc,c2 as cc,c3 as He,c4 as dc,c5 as fa,c6 as ga,c7 as uc,c8 as ja,c9 as mc,ca as hc,cb as xc,cc as pc,cd as $e,ce as bs,cf as va,cg as fc,ch as gc,ci as So,cj as jc,ck as Io,cl as vc,cm as bc,cn as yc,co as wc,cp as Un,cq as Nc,cr as Ao,cs as kc,ct as Cc,cu as $t,cv as Sc,cw as Ic,cx as Ac,g as Ec,cy as un,cz as Eo,cA as Ht,cB as Mc,cC as Pc,cD as Tc,cE as me,cF as he,cG as cs,cH as $n,cI as Vn,cJ as Mo,cK as mn,cL as ba,cM as hn,cN as Po,cO as To,cP as Rc,cQ as Ro,cR as Oc,cS as Dc,cT as Lc,cU as zc,cV as _c,cW as Bc,cX as Fc,cY as Uc,cZ as $c,c_ as Vc,c$ as ya,d0 as Oo,d1 as Do,d2 as Lo,d3 as zo,d4 as Kc,d5 as qc,d6 as Et,d7 as _o,d8 as Bo,d9 as Fo,da as Gc,db as Hc,dc as Wc,dd as es,de as St,df as Uo,dg as Yc,dh as Jc,di as Qc,dj as Xc,dk as Zc,dl as ed,dm as td,dn as sd,dp as nd,dq as ad,dr as rd,ds as od,dt as xn,du as id,dv as as,dw as ld,dx as Kn,dy as $o,dz as Vo,dA as qn,dB as Ko,dC as qo,dD as Go,dE as Ho,dF as Wo,dG as cd,dH as dd,dI as ud,dJ as md,dK as hd,dL as xd,dM as pd,dN as fd,dO as gd,dP as jd,dQ as vd,dR as bd,dS as yd,dT as wd,dU as Nd,dV as kd,dW as Cd,dX as Sd,dY as Id,dZ as Yo,d_ as Jo,d$ as Qo,e0 as Ad,e1 as Xo,e2 as Ed,e3 as Md,e4 as Pd,e5 as Zo,e6 as Td,e7 as ei,e8 as Rd,e9 as Od,ea as Dd,eb as rs,ec as Ld,ed as zd,ee as _d,ef as Bd,eg as at,eh as Fd,ei as ti,ej as Ud,ek as $d,el as Vd,em as Kd,en as qd,eo as Gd,ep as Hd,eq as Wd,er as Yd,es as si,et as Jd,eu as Qd,ev as Xd,ew as Zd,ex as eu,ey as tu,ez as su,eA as nu,eB as au,eC as ru,eD as ou,eE as iu,eF as lu,eG as cu,eH as du,eI as uu,eJ as wa,eK as mu,eL as hu,eM as Na,eN as ka,eO as xu}from"./globals-BJ2xID1e.js";import{c as ni}from"./cytoscape.esm-DzSz-X2X.js";import{f as pu}from"./cytoscape-fcose-BcbfusAa.js";const fu=[["path",{d:"M10 22V7a1 1 0 0 0-1-1H4a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-5a1 1 0 0 0-1-1H2",key:"1ah6g2"}],["rect",{x:"14",y:"2",width:"8",height:"8",rx:"1",key:"88lufb"}]],gu=Ee("blocks",fu);const ju=[["path",{d:"M12 5v16",key:"1f6ucr"}],["path",{d:"M20.001 19A2 2 0 0022 17V5a2 2 0 00-1.999-2L16 3.002A5 5 0 0012 5a5 5 0 00-4-2H4a2 2 0 00-2 2v12a2 2 0 001.999 2H8a5 5 0 014 2 5 5 0 014-2z",key:"1fyvmf"}]],vu=Ee("book-open",ju);const bu=[["path",{d:"M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z",key:"hh9hay"}],["path",{d:"m3.3 7 8.7 5 8.7-5",key:"g66t2b"}],["path",{d:"M12 22V12",key:"d0xqtd"}]],yu=Ee("box",bu);const wu=[["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["path",{d:"M18 17V9",key:"2bz60n"}],["path",{d:"M13 17V5",key:"1frdt8"}],["path",{d:"M8 17v-3",key:"17ska0"}]],Nu=Ee("chart-column",wu);const ku=[["path",{d:"M13.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 2v11.5",key:"4pqfef"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M8 12v-1",key:"1ej8lb"}],["path",{d:"M8 18v-2",key:"qcmpov"}],["path",{d:"M8 7V6",key:"1nbb54"}],["circle",{cx:"8",cy:"20",r:"2",key:"ckkr5m"}]],Cu=Ee("file-archive",ku);const Su=[["path",{d:"M14.364 13.634a2 2 0 0 0-.506.854l-.837 2.87a.5.5 0 0 0 .62.62l2.87-.837a2 2 0 0 0 .854-.506l4.013-4.009a1 1 0 0 0-3.004-3.004z",key:"ukzhwg"}],["path",{d:"M14.487 7.858A1 1 0 0 1 14 7V2",key:"1klhew"}],["path",{d:"M20 19.645V20a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l2.516 2.516",key:"rxaxab"}],["path",{d:"M8 18h1",key:"13wk12"}]],Iu=Ee("file-pen-line",Su);const Au=[["path",{d:"M4 22V4a1 1 0 0 1 .4-.8A6 6 0 0 1 8 2c3 0 5 2 7.333 2q2 0 3.067-.8A1 1 0 0 1 20 4v10a1 1 0 0 1-.4.8A6 6 0 0 1 16 16c-3 0-5-2-8-2a6 6 0 0 0-4 1.528",key:"1jaruq"}]],Eu=Ee("flag",Au);const Mu=[["path",{d:"M12 22v-6",key:"6o8u61"}],["path",{d:"M12 8V2",key:"1wkif3"}],["path",{d:"M4 12H2",key:"rhcxmi"}],["path",{d:"M10 12H8",key:"s88cx1"}],["path",{d:"M16 12h-2",key:"10asgb"}],["path",{d:"M22 12h-2",key:"14jgyd"}],["path",{d:"m15 19-3-3-3 3",key:"e37ymu"}],["path",{d:"m15 5-3 3-3-3",key:"19d6lf"}]],Pu=Ee("fold-vertical",Mu);const Tu=[["path",{d:"M2 9.5a5.5 5.5 0 0 1 9.591-3.676.56.56 0 0 0 .818 0A5.49 5.49 0 0 1 22 9.5c0 2.29-1.5 4-3 5.5l-5.492 5.313a2 2 0 0 1-3 .019L5 15c-1.5-1.5-3-3.2-3-5.5",key:"mvr1a0"}]],Ca=Ee("heart",Tu);const Ru=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}]],Ou=Ee("image",Ru);const Du=[["path",{d:"M9 17H7A5 5 0 0 1 7 7h2",key:"8i5ue5"}],["path",{d:"M15 7h2a5 5 0 1 1 0 10h-2",key:"1b9ql8"}],["line",{x1:"8",x2:"16",y1:"12",y2:"12",key:"1jonct"}]],ai=Ee("link-2",Du);const Lu=[["circle",{cx:"12",cy:"16",r:"1",key:"1au0dj"}],["rect",{x:"3",y:"10",width:"18",height:"12",rx:"2",key:"6s8ecr"}],["path",{d:"M7 10V7a5 5 0 0 1 10 0v3",key:"1pqi11"}]],ri=Ee("lock-keyhole",Lu);const zu=[["path",{d:"M12 22a1 1 0 0 1 0-20 10 9 0 0 1 10 9 5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z",key:"e79jfc"}],["circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor",key:"1okk4w"}],["circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor",key:"f64h9f"}],["circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor",key:"qy21gx"}],["circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor",key:"fotxhn"}]],_u=Ee("palette",zu);const Bu=[["path",{d:"m15 15 6 6m-6-6v4.8m0-4.8h4.8",key:"17vawe"}],["path",{d:"M9 19.8V15m0 0H4.2M9 15l-6 6",key:"chjx8e"}],["path",{d:"M15 4.2V9m0 0h4.8M15 9l6-6",key:"lav6yq"}],["path",{d:"M9 4.2V9m0 0H4.2M9 9 3 3",key:"1pxi2q"}]],Fu=Ee("shrink",Bu);const Uu=[["path",{d:"M15 21v-5a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v5",key:"slp6dd"}],["path",{d:"M17.774 10.31a1.12 1.12 0 0 0-1.549 0 2.5 2.5 0 0 1-3.451 0 1.12 1.12 0 0 0-1.548 0 2.5 2.5 0 0 1-3.452 0 1.12 1.12 0 0 0-1.549 0 2.5 2.5 0 0 1-3.77-3.248l2.889-4.184A2 2 0 0 1 7 2h10a2 2 0 0 1 1.653.873l2.895 4.192a2.5 2.5 0 0 1-3.774 3.244",key:"o0xfot"}],["path",{d:"M4 10.95V19a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8.05",key:"wn3emo"}]],$u=Ee("store",Uu);const Vu=[["circle",{cx:"12",cy:"12",r:"4",key:"4exip2"}],["path",{d:"M12 2v2",key:"tus03m"}],["path",{d:"M12 20v2",key:"1lh1kg"}],["path",{d:"m4.93 4.93 1.41 1.41",key:"149t6j"}],["path",{d:"m17.66 17.66 1.41 1.41",key:"ptbguv"}],["path",{d:"M2 12h2",key:"1t8f8n"}],["path",{d:"M20 12h2",key:"1q8mjw"}],["path",{d:"m6.34 17.66-1.41 1.41",key:"1m8zz5"}],["path",{d:"m19.07 4.93-1.41 1.41",key:"1shlcs"}]],Ku=Ee("sun",Vu);const qu=[["path",{d:"M12 3v12",key:"1x0j5s"}],["path",{d:"m17 8-5-5-5 5",key:"7q97r8"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}]],oi=Ee("upload",qu);function Gu(t){return t&&typeof t=="object"&&!Array.isArray(t)?t:null}function Hu(t){try{const s=new URL(t);return(s.protocol==="http:"||s.protocol==="https:")&&!s.username&&!s.password&&!s.search&&!s.hash&&!t.includes("?")&&!t.includes("#")}catch{return!1}}function Wu(t){const s=Gu(t);if(!s||Object.keys(s).some(d=>!["providerId","modelId","protocol","baseUrl","apiKey"].includes(d)))return null;const{providerId:n,modelId:a,protocol:r,baseUrl:o,apiKey:i}=s;return typeof n!="string"||!n.trim()||typeof a!="string"||!a.trim()||typeof i!="string"||!i.trim()||typeof o!="string"||!Hu(o)||r!=="openai"&&r!=="openai-compatible"&&r!=="gemini"?null:{providerId:n,modelId:a,protocol:r,baseUrl:o,apiKey:i}}function Yu(t,s){if(t?.enabled!==!0||t.oauthAccountKey||t.oauthAccountPool||typeof t.apiKey!="string"||!t.apiKey.trim()||typeof t.baseUrl!="string")return null;let n;if(t.api==="google-generative-ai")n="gemini";else if(t.api==="openai-completions"||t.api==="openai-responses"){let o="";try{o=new URL(t.baseUrl).hostname.toLowerCase()}catch{}n=t.catalogId!=="__custom"&&(t.catalogId==="openai"||!t.catalogId&&o==="api.openai.com")?"openai":"openai-compatible"}else return null;const a=n==="gemini"?sa["google-generative-ai"]:n==="openai"?sa["openai-responses"]:"";let r=t.baseUrl.trim().replace(/\/+$/,"")||a;if(n==="gemini"&&r&&(r=$i(r,"v1beta")),n==="openai"&&r)try{new URL(r).pathname==="/"&&(r=`${r}/v1`)}catch{}return Wu({providerId:t.id,modelId:s,protocol:n,baseUrl:r,apiKey:t.apiKey})}function Ju(t){return Array.isArray(t?.models)?t.models.filter(s=>!!s&&typeof s=="object"&&typeof s.id=="string"&&!!s.id.trim()&&s.enabled!==!1&&s.imageGeneration===!0):[]}function Qu(t){return t.flatMap(s=>{const n=Ju(s).filter(a=>Yu(s,a.id));return n.length?[{...s,models:n}]:[]})}function Xu(t){const{multiple:s=!1,defaultValue:n,value:a,onValueChange:r,autoComplete:o,...i}=t;return e.jsx(Vi,{...i,selectionMode:s?"multiple":"single",selectedValue:a,defaultSelectedValue:n,onSelectedValueChange:r,formAutoComplete:o})}const Zu=m.forwardRef(function(s,n){const{selected:a}=ro();return s.keepMounted||a?e.jsx(em,{...s,ref:n}):null}),em=m.memo(m.forwardRef((t,s)=>{const{render:n,className:a,style:r,keepMounted:o,...i}=t,{selected:d}=ro(),u=m.useRef(null),{transitionStatus:x,setMounted:h}=oo(d),f=Cn("span",t,{ref:[s,u],state:{selected:d,transitionStatus:x},props:[{"aria-hidden":!0,children:"✔️"},i],stateAttributesMapping:lo});return io({open:d,ref:u,onComplete(){d||h(!1)}}),f})),Gn=m.createContext({chipsRef:null,multiple:!1,rootRef:null});function tm(t){const s=m.useRef(null),n=m.useRef(null);return e.jsx(Gn.Provider,{value:{chipsRef:s,multiple:!!t.multiple,rootRef:n},children:e.jsx("div",{ref:n,className:"contents",children:e.jsx(Xu,{...t})})})}function sm({className:t,showTrigger:s=!0,showClear:n=!1,startAddon:a,size:r,...o}){const{multiple:i}=m.useContext(Gn),d=r??"default";return i?e.jsx(na,{className:G("min-w-12 flex-1 text-base outline-none sm:text-sm [[data-slot=combobox-chip]+&]:ps-0.5",d==="sm"?"ps-1.5":"ps-2",t),"data-size":typeof d=="string"?d:void 0,"data-slot":"combobox-input",size:typeof d=="number"?d:void 0,...o}):e.jsxs("div",{className:"relative w-full has-disabled:opacity-64",children:[a&&e.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":"combobox-start-addon",children:a}),e.jsx(na,{className:G(a&&"data-[size=sm]:*:data-[slot=combobox-input]:ps-[calc(--spacing(7.5)-1px)] *:data-[slot=combobox-input]:ps-[calc(--spacing(8.5)-1px)] sm:data-[size=sm]:*:data-[slot=combobox-input]:ps-[calc(--spacing(7)-1px)] sm:*:data-[slot=combobox-input]:ps-[calc(--spacing(8)-1px)]",d==="sm"?"has-[+[data-slot=combobox-trigger],+[data-slot=combobox-clear]]:*:data-[slot=combobox-input]:pe-6.5":"has-[+[data-slot=combobox-trigger],+[data-slot=combobox-clear]]:*:data-[slot=combobox-input]:pe-7",t),"data-slot":"combobox-input",render:e.jsx(J,{className:"has-disabled:opacity-100",size:d}),...o}),s&&e.jsx(nm,{className:G("-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-opacity pointer-coarse:after:absolute pointer-coarse:after:min-h-11 pointer-coarse:after:min-w-11 hover:opacity-100 has-[+[data-slot=combobox-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",d==="sm"?"end-0":"end-0.5"),children:e.jsx(Ki,{})}),n&&e.jsx(im,{className:G("-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-opacity pointer-coarse:after:absolute pointer-coarse:after:min-h-11 pointer-coarse:after:min-w-11 hover:opacity-100 has-[+[data-slot=combobox-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",d==="sm"?"end-0":"end-0.5"),children:e.jsx(ht,{})})]})}function nm({className:t,...s}){return e.jsx(Qi,{className:t,"data-slot":"combobox-trigger",...s})}function am({className:t,children:s,sideOffset:n=4,zIndex:a,...r}){const{chipsRef:o,rootRef:i}=m.useContext(Gn);let d=st.DROPDOWN;if(a!==void 0)d=a;else{const u=i?.current;u&&(u.closest('[data-slot="dialog-popup"] [data-slot="dialog-popup"]')?d=st.DROPDOWN_IN_NESTED_MODAL:u.closest('[data-slot="dialog-popup"]')&&(d=st.DROPDOWN_IN_MODAL))}return e.jsx(qi,{children:e.jsx(Gi,{anchor:o,className:"select-none",style:{zIndex:d},"data-slot":"combobox-positioner",sideOffset:n,children:e.jsx("span",{className:G("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",t),children:e.jsx(Hi,{className:"flex max-h-[min(var(--available-height),23rem)] w-(--anchor-width) max-w-(--available-width) flex-col","data-slot":"combobox-popup",...r,children:s})})})})}function rm({className:t,children:s,endAddon:n,...a}){return e.jsxs(Ji,{className:G("grid min-h-8 in-data-[side=none]:min-w-[calc(var(--anchor-width)+1.25rem)] cursor-default grid-cols-[1rem_1fr_auto] items-center gap-2 rounded-sm py-1 ps-2 pe-4 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 [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",t),"data-slot":"combobox-item",...a,children:[e.jsx(Zu,{className:"col-start-1",children:e.jsx("svg",{"aria-hidden":"true",fill:"none",height:"24",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",viewBox:"0 0 24 24",width:"24",xmlns:"http://www.w3.org/2000/svg",children:e.jsx("path",{d:"M5.252 12.7 10.2 18.63 18.748 5.37"})})}),e.jsx("div",{className:"col-start-2",children:s}),n&&e.jsx("div",{className:"col-start-3 flex items-center",children:n})]})}function om({className:t,...s}){return e.jsx(Wi,{scrollbarGutter:!0,scrollFade:!0,children:e.jsx(Yi,{className:G("not-empty:scroll-py-1 not-empty:px-1 not-empty:py-1 in-data-has-overflow-y:pe-3",t),"data-slot":"combobox-list",...s})})}function im({className:t,...s}){return e.jsx(Xi,{className:t,"data-slot":"combobox-clear",...s})}function lm(){const{t}=z(),s=v(c=>c.contextMenuOpen),n=v(c=>c.setContextMenuOpen),[a,r]=m.useState(!1),[o,i]=m.useState(!1),d=c=>c.target==="reveal"?t("File manager"):c.target==="vscode"?t("VS Code"):c.applicationPath.split(/[/\\]/).at(-1)?.replace(/\.(exe|app)$/i,"")||c.applicationPath,u=s.filter(c=>c.enabled).map(d),x=u.length?`${u.slice(0,2).join(", ")}${u.length>2?` +${u.length-2}`:""}`:t("No opening methods enabled"),h=c=>{if(c.length>32){Re({type:"error",title:t("Context menu opening"),description:t("You can configure up to 32 opening methods.")});return}n(c)},l=(c,p)=>{const g=v.getState().contextMenuOpen;n(g.map(w=>w.id===c.id?{...w,enabled:p}:w))},f=async()=>{i(!0);try{const c=await window.electronAPI.dialog.selectFile();if(!c)return;if(!co(c)){Re({type:"error",title:t("Context menu opening"),description:t("The selected application path is invalid.")});return}const p=v.getState().contextMenuOpen,g=aa(c),w=p.find(k=>k.target==="application"&&aa(k.applicationPath)===g);if(w){h(p.map(k=>k.id===w.id?{...k,enabled:!0}:k));return}h([...p,{id:crypto.randomUUID(),target:"application",applicationPath:c,enabled:!0}])}catch(c){Re({type:"error",title:t("Context menu opening"),description:c instanceof Error?c.message:String(c)})}finally{i(!1)}};return e.jsxs("div",{className:"space-y-2 rounded-md border p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("h5",{className:"text-sm font-medium",children:t("Context menu opening")}),e.jsx(S,{variant:"outline",size:"sm",onClick:()=>r(!0),children:t("Configure list")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Select the opening methods shown in file link context menus. You can add multiple applications.")}),e.jsx("p",{className:"truncate text-xs text-muted-foreground",title:u.join(", "),children:x}),e.jsx(pe,{open:a,onOpenChange:r,children:e.jsxs(fe,{zIndexLevel:"nested",children:[e.jsxs(ge,{children:[e.jsx(je,{children:t("Context menu opening")}),e.jsx(Ve,{children:t("Select the opening methods shown in file link context menus. You can add multiple applications.")})]}),e.jsxs(we,{className:"space-y-2",children:[s.length===0&&e.jsx("p",{className:"py-6 text-center text-sm text-muted-foreground",children:t("No opening methods enabled")}),s.map(c=>{const p=d(c);return e.jsxs("div",{className:"flex items-center gap-3 rounded-md border p-3",children:[e.jsxs("label",{className:"flex min-w-0 flex-1 cursor-pointer items-center gap-3",children:[e.jsx(Qe,{checked:c.enabled,disabled:o,"aria-label":p,onCheckedChange:g=>l(c,g)}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-sm",title:p,children:p}),c.target==="application"&&e.jsx("span",{className:"block truncate text-xs text-muted-foreground",title:c.applicationPath,children:c.applicationPath})]})]}),e.jsx(S,{variant:"ghost",size:"sm",disabled:o,onClick:()=>n(v.getState().contextMenuOpen.filter(g=>g.id!==c.id)),children:t("Delete")})]},c.id)})]}),e.jsxs(Ie,{children:[e.jsx(S,{variant:"outline",disabled:o,onClick:()=>{f()},children:t("Add application")}),e.jsx(S,{onClick:()=>r(!1),children:t("Close")})]})]})})]})}const Sa=["internal","reveal","system","application"];function Ia({extension:t,value:s,disabled:n,onChange:a}){const{t:r}=z(),o={internal:r("Open inside EnsoCode"),reveal:r("Reveal in file manager"),system:r("System default application"),application:r("Selected application")},i=Xt(`file${t}`),d=Zt(`file${t}`)!==null,u=i?d?["internal","reveal"]:["reveal"]:Sa,x=i&&(!d||s==="system"||s==="application")?"reveal":s;return e.jsxs(ae,{items:Object.fromEntries(u.map(h=>[h,o[h]])),value:x,disabled:n,onValueChange:h=>{Sa.includes(h)&&a(h)},children:[e.jsx(re,{className:"w-52","aria-label":r("File opening"),children:e.jsx(oe,{})}),e.jsx(ie,{children:u.map(h=>e.jsx(ee,{value:h,disabled:h==="internal"&&!d,children:o[h]},h))})]})}function cm(){const{t}=z(),s=v(y=>y.fileOpenRules),n=v(y=>y.setFileOpenRules),[a,r]=m.useState(""),[o,i]=m.useState("internal"),[d,u]=m.useState(),[x,h]=m.useState(null),[l,f]=m.useState(!1),c=Zi([{extension:a,target:"reveal"}])[0]?.extension,p=y=>{Re({type:"error",title:t("File opening"),description:y})},g=async y=>{f(!0);try{const N=await window.electronAPI.dialog.selectFile();if(N){if(!co(N)){p(t("The selected application path is invalid."));return}y(N)}}catch(N){p(N instanceof Error?N.message:String(N))}finally{f(!1)}},w=y=>{const N=el(y);return N?(n(N),!0):(p(t("Could not complete the file action.")),!1)},k=(y,N,A)=>{if(N==="internal"&&!Zt(`file${y.extension}`)){p(t("This extension does not support internal preview."));return}w(s.map(O=>O.extension===y.extension?{extension:y.extension,target:N,...N==="application"?{applicationPath:A}:{}}:O))},j=()=>{if(!c){h(t("Enter a valid file extension, for example .md."));return}if(s.some(O=>O.extension===c)){h(t("This extension already has an opening rule."));return}const y=Xt(`file${c}`),N=Zt(`file${c}`)!==null,A=y&&(!N||o==="system"||o==="application")?"reveal":o;if(A==="internal"&&!Zt(`file${c}`)){p(t("This extension does not support internal preview."));return}if(A==="application"&&!d){h(t("Choose an application before saving this rule."));return}w([...s,{extension:c,target:A,...A==="application"?{applicationPath:d}:{}}])&&(r(""),u(void 0),h(null))};return e.jsxs("section",{className:"space-y-3","data-settings-row":"appearance.fileOpening",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium",children:t("File opening")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Configure how local workspace file links open by extension.")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("By default, supported files open inside EnsoCode; other files are revealed in the file manager.")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Executable and installer files are always revealed in the file manager.")})]}),e.jsx(lm,{}),s.map(y=>e.jsxs("div",{className:"flex flex-wrap items-center gap-2 rounded-md border px-3 py-2",children:[e.jsx("span",{className:"w-20 shrink-0 font-mono text-sm",children:y.extension}),e.jsx(Ia,{extension:y.extension,value:y.target,disabled:l,onChange:N=>{N==="application"?g(A=>k(y,N,A)):k(y,N)}}),y.target==="application"&&!Xt(`file${y.extension}`)&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-xs text-muted-foreground",title:y.applicationPath,children:y.applicationPath}),e.jsx(S,{variant:"outline",size:"sm",disabled:l,onClick:()=>{g(N=>k(y,"application",N))},children:t("Choose application")})]}),e.jsx(S,{variant:"ghost",size:"sm",disabled:l,onClick:()=>w(s.filter(N=>N.extension!==y.extension)),children:t("Delete")})]},y.extension)),e.jsxs("div",{className:"space-y-2 rounded-md border p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(J,{className:"w-24",value:a,placeholder:".md","aria-label":t("File extension"),disabled:l,onChange:y=>{r(y.target.value),h(null)},onKeyDown:y=>{y.key==="Enter"&&j()}}),e.jsx(Ia,{extension:c??".md",value:o,disabled:l,onChange:y=>{i(y),h(null)}}),e.jsx(S,{variant:"outline",size:"sm",disabled:l,onClick:j,children:t("Add")})]}),o==="application"&&!Xt(`file${c??".md"}`)&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(S,{variant:"outline",size:"sm",disabled:l,onClick:()=>{g(y=>{u(y),h(null)})},children:t("Choose application")}),e.jsx("span",{className:"min-w-0 truncate text-xs text-muted-foreground",title:d,children:d})]}),x&&e.jsx("p",{role:"alert",className:"text-xs text-destructive",children:x})]})]})}const dm=["pem","crt","cer"];function um(t){return/^\//.test(t)||/^[A-Za-z]:[\\/]/.test(t)||/^\\\\[^\\]/.test(t)}const mm=16384,ii=4096,li=65536;function hm(t){return t===null?null:typeof t=="number"&&Number.isInteger(t)&&t>=ii&&t<=li?t:void 0}function xm(t){const s=t.trim();return s?/^\d+$/.test(s)?hm(Number(s)):void 0:null}function pm(){const{t}=z(),[s,n]=m.useState(null),[a,r]=m.useState(""),[o,i]=m.useState(null);m.useEffect(()=>{let u=!1;return window.electronAPI.compaction.getReserveTokens().then(x=>{u||(n(x),r(x===null?"":String(x)))}),()=>{u=!0}},[]);const d=async()=>{const u=xm(a);if(u===void 0){i(t("Enter a whole number between {{min}} and {{max}}, or leave it empty.",{min:ii,max:li}));return}if(i(null),u===s)return;if(!(await window.electronAPI.compaction.setReserveTokens(u)).ok){i(t("Could not save. Check that pi-agent/settings.json is valid JSON."));return}n(u),r(u===null?"":String(u))};return e.jsxs("div",{className:"flex items-start justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.compactReserveTokens",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"text-sm",children:[t("Compaction reserve tokens"),e.jsx(qe,{})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Compaction runs when context exceeds the model window minus this value. Larger values compact earlier. Do not set it close to the window of small-context models, or every request compacts first. Leave empty for the default.")})]}),e.jsxs("div",{className:"w-32 shrink-0 space-y-1",children:[e.jsx(J,{inputMode:"numeric",value:a,placeholder:String(mm),"aria-label":t("Compaction reserve tokens"),onChange:u=>r(u.target.value),onBlur:()=>{d()},onKeyDown:u=>{u.key==="Enter"&&d()}}),o&&e.jsx("p",{className:"text-xs text-destructive",children:o})]})]})}function pn({className:t,render:s,...n}){const a={className:G("inline-flex items-center gap-2 text-base/4.5 sm:text-sm/4 font-medium",t),"data-slot":"label"};return tl({defaultTagName:"label",props:sl(a,n),render:s})}const fn={checked(t){return t?{"data-checked":""}:{"data-unchecked":""}},...lo,...uo},ci=m.createContext(void 0);function fm(){return m.useContext(ci)}const di=m.createContext(void 0);function gm(){const t=m.useContext(di);if(t===void 0)throw new Error(nl(52));return t}const jm=m.forwardRef(function(s,n){const{render:a,className:r,disabled:o=!1,readOnly:i=!1,required:d=!1,"aria-labelledby":u,value:x,inputRef:h,nativeButton:l=!1,id:f,style:c,...p}=s,g=fm(),{disabled:w,readOnly:k,required:j,form:y,checkedValue:N,touched:A=!1,validation:O,name:I,setCheckedValue:L=fs,setTouched:C=fs,registerInputRef:E=fs}=g??{},{setTouched:M,setFilled:V,state:F,disabled:b}=mo(),B=al(),{labelId:K,getDescriptionProps:D}=ho(),$=b||B.disabled||w||o,Y=k||i,H=j||d,se=y,q=g?N===x:x==="",Q=m.useRef(null),_=m.useRef(null),ne=O?.registerInput,R=m.useCallback(ke=>ne?.(ke,{controlRef:Q,value:void 0}),[ne]),P=rl(h,_,E,R);ra(()=>{_.current?.checked&&V(!0)},[V]),ra(()=>{if(_.current){if($&&q){E(null);return}E(_.current)}},[q,$,E]);const ce=xo(),xe=ol({id:f,implicit:!1,controlRef:Q}),Pe=l?void 0:xe,De=il(u,K,_,!l,Pe),U={role:"radio","aria-checked":q,"aria-labelledby":De,[xl]:q?"":void 0,id:l?xe:ce,onKeyDown(ke){ke.key==="Enter"&&ke.preventDefault()},onClick(ke){if(ke.defaultPrevented||$||Y)return;ke.preventDefault();const nt=_.current;nt&&hl(nt,ke)},onFocus(ke){ke.defaultPrevented||$||Y||!A||(_.current?.click(),C(!1))}},{getButtonProps:Z,buttonRef:X}=ll({disabled:$,native:l,composite:!1}),ue={type:"radio",ref:P,form:se,id:Pe,name:I,tabIndex:-1,style:I?ul:ml,"aria-hidden":!0,...x!==void 0?{value:cl(x)}:oa,disabled:$,checked:q,required:H,readOnly:Y,onChange(ke){if(ke.nativeEvent.defaultPrevented||$||Y||x===void 0)return;const nt=pl(fl,ke.nativeEvent);L(x,nt),!nt.isCanceled&&M(!0)},onClick(ke){ke.stopPropagation()},onFocus(){Q.current?.focus()}},Ne=m.useMemo(()=>({...F,required:H,disabled:$,readOnly:Y,checked:q}),[F,$,Y,q,H]),Ce=Ne,W=g!==void 0,ve=[n,Q,X],Se=[U,p,Z,D,O?ke=>O.getValidationProps($,ke):oa],Ze=Cn("span",s,{enabled:!W,state:Ne,ref:ve,props:Se,stateAttributesMapping:fn});return e.jsxs(di.Provider,{value:Ce,children:[W?e.jsx(dl,{tag:"span",render:a,className:r,style:c,state:Ne,refs:ve,props:Se,stateAttributesMapping:fn}):Ze,e.jsx("input",{...ue,suppressHydrationWarning:!0})]})}),vm=m.forwardRef(function(s,n){const{render:a,className:r,style:o,keepMounted:i=!1,...d}=s,u=gm(),x=u.checked,{mounted:h,transitionStatus:l,setMounted:f}=oo(x),c={...u,transitionStatus:l},p=m.useRef(null),g=i||h,w=Cn("span",s,{ref:[n,p],state:c,props:d,stateAttributesMapping:fn});return io({open:x,ref:p,onComplete(){x||f(!1)}}),g?w:null}),bm=[kl],ym=m.forwardRef(function(s,n){const{render:a,className:r,disabled:o,readOnly:i,required:d,onValueChange:u,value:x,defaultValue:h,form:l,name:f,inputRef:c,id:p,style:g,...w}=s,{setTouched:k,setFocused:j,validationMode:y,name:N,disabled:A,state:O,validation:I,setDirty:L,setFilled:C,validityData:E}=mo(),{labelId:M}=ho(),{clearErrors:V,elementRef:F}=gl(),b=jl(!0),B=A||o,K=N??f,D=xo(p),[$,Y]=vl({controlled:x,default:h,name:"RadioGroup",state:"value"}),[H,se]=m.useState(!1),q=gs((X,ue)=>{u?.(X,ue),!ue.isCanceled&&Y(X)}),Q=I.getInputControl,_=m.useMemo(()=>({get current(){return Q()}}),[Q]),ne=m.useRef(null),R=m.useRef(null);function P(X){let ue;return c&&(typeof c=="function"?ue=c(X):c.current=X),ne.current=X,ue}const ce=gs(X=>{if(!X||X.disabled)return;R.current||(R.current=X);const ue=ne.current,Ne=X.checked||ue==null||ue.disabled?P(X):void 0;return()=>{R.current===X&&(R.current=null),ne.current===X?Ne?(Ne(),ne.current=null):P(null):Ne?.()}}),xe=gs(()=>{const X=F.current;if(!X)return $??null;for(const ue of I.registeredInputs.keys())if(ue.checked&&bl(ue,X))return $??null;return null});yl(_,D,$??null,xe,!B,f),wl($,()=>{V(K),L($!==E.initialValue),C($!=null),I.change($);const X=R.current;$==null&&X&&!X.disabled&&P(X)});const Pe=M??b?.legendId,De={...O,disabled:B??!1,required:d??!1,readOnly:i??!1},U=m.useMemo(()=>({checkedValue:$,disabled:B,form:l,validation:I,name:K,readOnly:i,registerInputRef:ce,required:d,setCheckedValue:q,setTouched:se,touched:H}),[$,B,l,I,K,i,ce,d,q,se,H]),Z={id:p,role:"radiogroup","aria-required":d||void 0,"aria-disabled":B||void 0,"aria-readonly":i||void 0,"aria-labelledby":Pe,onFocus(){j(!0)},onBlur(X){Cl(X.currentTarget,X.relatedTarget)||(k(!0),j(!1),y==="onBlur"&&I.commit($))},onKeyDownCapture(X){X.key.startsWith("Arrow")&&(se(!0),j(!0))}};return e.jsx(ci.Provider,{value:U,children:e.jsx(Nl,{render:a,className:r,style:g,state:De,props:[Z,w,X=>I.getValidationProps(B??!1,X)],refs:[n],stateAttributesMapping:uo,enableHomeAndEndKeys:!1,modifierKeys:bm})})});function wm({className:t,...s}){return e.jsx(ym,{className:G("flex flex-col gap-3",t),"data-slot":"radio-group",...s})}function Aa({className:t,...s}){return e.jsx(jm,{className:G("relative inline-flex size-4.5 shrink-0 items-center justify-center rounded-full border border-input bg-background bg-clip-padding shadow-xs outline-none transition-shadow before:pointer-events-none before:absolute before:inset-0 before:rounded-full not-data-disabled:not-data-checked:not-aria-invalid:before:shadow-[0_1px_--theme(--color-black/4%)] focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background aria-invalid:border-destructive/36 focus-visible:aria-invalid:border-destructive/64 focus-visible:aria-invalid:ring-destructive/48 data-disabled:opacity-64 sm:size-4 dark:not-data-checked:bg-input/32 dark:bg-clip-border dark:aria-invalid:ring-destructive/24 dark:not-data-disabled:not-data-checked:not-aria-invalid:before:shadow-[0_-1px_--theme(--color-white/8%)] [[data-disabled],[data-checked],[aria-invalid]]:shadow-none",t),"data-slot":"radio",...s,children:e.jsx(vm,{className:"-inset-px absolute flex size-4.5 items-center justify-center rounded-full before:size-2 before:rounded-full before:bg-primary-foreground data-unchecked:hidden data-checked:bg-primary sm:size-4 sm:before:size-1.5","data-slot":"radio-indicator"})})}const Nm=[{category:"providers",label:"Model Providers"},{category:"presets",label:"Presets"},{category:"agentTypes",label:"Agent types"},{category:"skills",label:"Skills"},{category:"mcpServers",label:"MCP Servers"},{category:"instructions",label:"Instruction Files"},{category:"subagentModels",label:"Subagent Models"},{category:"settings",label:"Scalar settings"}];function km(){const{t}=z(),[s,n]=m.useState(!1),[a,r]=m.useState(!1),[o,i]=m.useState(null),[d,u]=m.useState(null),x=()=>{i(null),n(!0)},h=async()=>{r(!0),i(null);try{const l=await window.electronAPI.configSync.openImport();if(!l.ok){i({kind:l.cancelled?"cancelled":"error",text:l.cancelled?t("Import cancelled."):t(l.error)});return}u(l)}catch{i({kind:"error",text:t("Could not open configuration package.")})}finally{r(!1)}};return e.jsxs("section",{className:"space-y-3","data-settings-row":"general.configSync",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium",children:t("Configuration transfer")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Move models, presets, agent types, skills, MCP servers and instruction files between devices.")})]}),e.jsxs("div",{className:"rounded-md border px-3 py-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[e.jsx(Cu,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium",children:t("Portable Enso configuration")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Export a package or preview one before importing it.")})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsxs(S,{variant:"outline",size:"sm",disabled:a,onClick:h,children:[a?e.jsx(Ae,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Sn,{className:"h-3.5 w-3.5"}),t("Import configuration")]}),e.jsxs(S,{size:"sm",disabled:a,onClick:x,children:[e.jsx(oi,{className:"h-3.5 w-3.5"}),t("Export configuration")]})]})]}),e.jsxs("div",{className:"mt-3 flex items-start gap-2 border-t pt-3 text-xs text-muted-foreground",children:[e.jsx(ss,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),e.jsx("p",{children:t("OAuth login sessions are never transferred. Skill, instruction, and system prompt contents require an encrypted export.")})]}),o&&e.jsx("p",{className:o.kind==="error"?"mt-2 text-xs text-destructive":"mt-2 text-xs text-muted-foreground",role:o.kind==="error"?"alert":"status",children:o.text})]}),e.jsx(Cm,{open:s,onOpenChange:n}),d&&e.jsx(Sm,{file:d,onClose:()=>u(null)})]})}function Cm({open:t,onOpenChange:s}){const{t:n}=z(),[a,r]=m.useState(!1),[o,i]=m.useState(""),[d,u]=m.useState(""),[x,h]=m.useState(!1),[l,f]=m.useState(null),[c,p]=m.useState(!1),[g,w]=m.useState(null),[k,j]=m.useState([]);m.useEffect(()=>{t&&(r(!1),i(""),u(""),h(!1),f(null),p(!1),w(null),j([]))},[t]);const y=()=>{x||(i(""),u(""),s(!1))},N=async()=>{if(a&&o.length<8){f(n("Password must be at least 8 characters."));return}if(a&&o!==d){f(n("Passwords do not match."));return}h(!0),f(null),p(!1);try{const A=await window.electronAPI.configSync.exportConfig({includeSecrets:a,...a?{password:o}:{}});if(i(""),u(""),!A.ok){A.cancelled?p(!0):f(n(A.error));return}w(A.filePath),j(A.skippedInstructions??[])}catch{i(""),u(""),f(n("Could not export configuration."))}finally{h(!1)}};return e.jsx(pe,{open:t,onOpenChange:A=>!A&&y(),children:e.jsxs(fe,{className:"max-w-xl",showCloseButton:!x,children:[e.jsxs(ge,{children:[e.jsx(je,{children:n("Export configuration")}),e.jsx(Ve,{children:n("Create a portable .enso-config package for another device.")})]}),e.jsx(we,{className:"max-h-[55vh] space-y-4",children:g?e.jsxs(e.Fragment,{children:[e.jsxs(_e,{variant:"success",children:[e.jsx(po,{}),e.jsx(Ct,{children:n("Configuration exported")}),e.jsxs(Be,{children:[e.jsx("p",{children:n("Saved package:")}),e.jsx("p",{className:"break-all font-mono text-xs text-foreground",children:g})]})]}),k.length>0&&e.jsxs(_e,{variant:"warning",children:[e.jsx(Ue,{}),e.jsxs(Be,{children:[e.jsx("p",{children:n("These instructions were skipped because their source files are missing or unreadable:")}),e.jsx("p",{className:"break-all text-foreground",children:k.join(", ")})]})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs(_e,{variant:"warning",children:[e.jsx(In,{}),e.jsx(Ct,{children:n("File contents can be private")}),e.jsx(Be,{children:n("Skill and instruction file contents may contain private data, so configurations containing them can only be exported with encryption.")})]}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-md border px-3 py-2.5",children:[e.jsx(Qe,{checked:a,onCheckedChange:A=>{const O=A===!0;r(O),f(null),O||(i(""),u(""))}}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-sm font-medium",children:n("Include sensitive configuration")}),e.jsx("span",{className:"mt-0.5 block text-xs text-muted-foreground",children:n("Encrypt the entire package with a password. OAuth login sessions are still excluded.")})]})]}),!a&&e.jsxs(_e,{variant:"info",children:[e.jsx(ss,{}),e.jsx(Be,{children:n("API keys, provider account links, MCP arguments and environment values, plus credentials and private URL parts in MCP endpoints, will be omitted. Configurations containing skill or instruction files require encryption.")})]}),a&&e.jsxs("div",{className:"space-y-3 rounded-md border px-3 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(ri,{className:"h-4 w-4 text-muted-foreground"}),n("Encryption password")]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(pn,{htmlFor:"config-export-password",children:n("Password")}),e.jsx(J,{id:"config-export-password",type:"password",autoComplete:"new-password",value:o,"aria-invalid":!!(l&&o.length<8),onChange:A=>{i(A.target.value),f(null)}})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(pn,{htmlFor:"config-export-confirmation",children:n("Confirm password")}),e.jsx(J,{id:"config-export-confirmation",type:"password",autoComplete:"new-password",value:d,"aria-invalid":!!(l&&d!==o),onChange:A=>{u(A.target.value),f(null)}})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n("Use at least 8 characters. This password cannot be recovered.")})]}),c&&e.jsx("p",{className:"text-xs text-muted-foreground",role:"status",children:n("Export cancelled.")}),l&&e.jsxs("p",{className:"flex items-center gap-1.5 text-xs text-destructive",role:"alert",children:[e.jsx(At,{className:"h-3.5 w-3.5 shrink-0"}),l]})]})}),e.jsx(Ie,{children:g?e.jsx(S,{size:"sm",onClick:y,children:n("Done")}):e.jsxs(e.Fragment,{children:[e.jsx(S,{variant:"outline",size:"sm",disabled:x,onClick:y,children:n("Cancel")}),e.jsxs(S,{size:"sm",disabled:x,onClick:()=>{N()},children:[x?e.jsx(Ae,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(oi,{className:"h-3.5 w-3.5"}),n(x?"Exporting…":"Export")]})]})})]})})}function Sm({file:t,onClose:s}){const{t:n}=z(),[a,r]=m.useState(t.encrypted?"password":"preview"),[o,i]=m.useState(""),[d,u]=m.useState("merge"),[x,h]=m.useState(null),[l,f]=m.useState([]),[c,p]=m.useState(null),[g,w]=m.useState(!1),[k,j]=m.useState(null),[y,N]=m.useState(null),[A,O]=m.useState(!1),I=m.useRef(0),L=m.useCallback(async(b,B)=>{const K=++I.current;j("preview"),N(null),h(null),f([]);try{const D=await window.electronAPI.configSync.previewImport({token:t.token,mode:b,...B?{password:B}:{}});if(K!==I.current)return;if(i(""),!D.ok){N(n(D.error));return}u(D.mode),h(D.summary),f(D.warnings),r("preview")}catch{K===I.current&&(i(""),N(n("Could not preview configuration package.")))}finally{K===I.current&&j(null)}},[t.token,n]);m.useEffect(()=>{t.encrypted||L("merge")},[t.encrypted,L]);const C=()=>{k||(I.current+=1,O(!1),i(""),window.electronAPI.configSync.cancelImport(t.token).catch(()=>{}),s())},E=b=>{b===d||k||(u(b),L(b))},M=!!x?.some(b=>(b.category==="skills"||b.category==="mcpServers")&&b.added+b.updated+b.skipped>0),V=x!==null,F=async()=>{if(x){j("commit"),N(null);try{const b=await window.electronAPI.configSync.commitImport({token:t.token,mode:d});if(!b.ok){h(null),f([]),N(n(b.error));return}i("");try{await v.persist.rehydrate()}catch{w(!0)}f(b.warnings),p(b.backupPath),r("success")}catch{h(null),f([]),N(n("Could not import configuration."))}finally{j(null)}}};return e.jsxs(pe,{open:!0,onOpenChange:b=>!b&&C(),children:[e.jsxs(fe,{className:"max-w-2xl",showCloseButton:k===null,children:[e.jsxs(ge,{children:[e.jsx(je,{children:n(a==="success"?"Configuration imported":"Import configuration")}),e.jsx(Ve,{children:a==="success"?n(g?"Configuration was imported, but this window could not refresh automatically.":"This window has been refreshed with the imported settings."):n("Review {{fileName}} before changing this device.",{fileName:t.fileName})})]}),a==="password"&&e.jsxs(we,{className:"space-y-4",children:[e.jsxs(_e,{variant:"info",children:[e.jsx(ri,{}),e.jsx(Ct,{children:n("Encrypted configuration package")}),e.jsx(Be,{children:n("Enter the export password to decrypt and preview this package.")})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(pn,{htmlFor:"config-import-password",children:n("Password")}),e.jsx(J,{id:"config-import-password",type:"password",autoFocus:!0,autoComplete:"current-password",value:o,"aria-invalid":!!y,onChange:b=>{i(b.target.value),N(null)},onKeyDown:b=>{b.key==="Enter"&&o.length>0&&!k&&L("merge",o)}})]}),y&&e.jsxs("p",{className:"flex items-center gap-1.5 text-xs text-destructive",role:"alert",children:[e.jsx(At,{className:"h-3.5 w-3.5 shrink-0"}),y]})]}),a==="preview"&&e.jsxs(we,{className:"max-h-[58vh] space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium",children:n("Import mode")}),e.jsxs(wm,{value:d,onValueChange:b=>E(b),className:"grid gap-2 sm:grid-cols-2","aria-label":n("Import mode"),children:[e.jsxs("label",{className:"flex cursor-pointer items-start gap-2.5 rounded-md border px-3 py-2.5",children:[e.jsx(Aa,{value:"merge",disabled:k!==null}),e.jsxs("span",{children:[e.jsx("span",{className:"block text-sm font-medium",children:n("Merge")}),e.jsx("span",{className:"block text-xs text-muted-foreground",children:n("Add and update matching items while keeping items only on this device.")})]})]}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-2.5 rounded-md border px-3 py-2.5",children:[e.jsx(Aa,{value:"replace",disabled:k!==null}),e.jsxs("span",{children:[e.jsx("span",{className:"block text-sm font-medium",children:n("Replace")}),e.jsx("span",{className:"block text-xs text-muted-foreground",children:n("Replace transferred item categories, removing local-only items in them.")})]})]})]})]}),k==="preview"&&e.jsxs("div",{className:"flex items-center justify-center gap-2 rounded-md border border-dashed py-10",children:[e.jsx(Ae,{className:"h-4 w-4 animate-spin text-muted-foreground"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:n("Preparing preview…")})]}),!k&&x&&e.jsx("div",{className:"overflow-hidden rounded-md border",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted/50 text-xs text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",className:"px-3 py-2 text-left font-medium",children:n("Category")}),e.jsx("th",{scope:"col",className:"px-3 py-2 text-right font-medium",children:n("Added")}),e.jsx("th",{scope:"col",className:"px-3 py-2 text-right font-medium",children:n("Updated")}),e.jsx("th",{scope:"col",className:"px-3 py-2 text-right font-medium",children:n("Skipped")}),e.jsx("th",{scope:"col",className:"px-3 py-2 text-right font-medium",children:n("Removed")})]})}),e.jsx("tbody",{children:Nm.map(({category:b,label:B})=>{const K=x.find(D=>D.category===b);return e.jsxs("tr",{className:"border-t first:border-t-0",children:[e.jsx("th",{scope:"row",className:"px-3 py-2 text-left font-medium",children:n(B)}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:K?.added??0}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:K?.updated??0}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:K?.skipped??0}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:K?.removed??0})]},b)})})]})}),!k&&x?.find(b=>b.category==="settings")?.fields?.length?e.jsxs("p",{className:"text-xs text-muted-foreground",children:[n("Portable settings changed:")," ",x.find(b=>b.category==="settings")?.fields?.join(", ")]}):null,d==="replace"&&x&&!k&&e.jsxs(_e,{variant:"error",children:[e.jsx(Ue,{}),e.jsx(Ct,{children:n("Local-only configuration will be deleted")}),e.jsx(Be,{children:n("Items in transferred collections that exist only on this device will be removed. Removed counts are shown above. Included portable preferences are overwritten. A complete backup is created first.")})]}),l.map(b=>e.jsxs(_e,{variant:"warning",children:[e.jsx(Ue,{}),e.jsx(Be,{children:n(b)})]},b)),x&&!k&&e.jsxs(_e,{variant:"warning",children:[e.jsx(In,{}),e.jsx(Ct,{children:n("Only import packages you trust")}),e.jsx(Be,{children:n("An imported package can change portable preferences and configuration. Skills and MCP servers may also run commands later when you use them. Previewing does not execute them; continue only if you trust the package.")})]}),y&&e.jsxs(_e,{variant:"error",children:[e.jsx(At,{}),e.jsx(Be,{children:y})]})]}),a==="success"&&c&&e.jsxs(we,{className:"space-y-4",children:[e.jsxs(_e,{variant:"success",children:[e.jsx(po,{}),e.jsx(Ct,{children:n("Import complete")}),e.jsxs(Be,{children:[e.jsx("p",{children:n("Backup of previous settings:")}),e.jsx("p",{className:"break-all font-mono text-xs text-foreground",children:c})]})]}),g&&e.jsxs(_e,{variant:"warning",children:[e.jsx(Ue,{}),e.jsx(Be,{children:n("Reopen Settings to load the imported configuration in this window.")})]}),l.map(b=>e.jsxs(_e,{variant:"warning",children:[e.jsx(Ue,{}),e.jsx(Be,{children:n(b)})]},b))]}),e.jsxs(Ie,{children:[a==="password"&&e.jsxs(e.Fragment,{children:[e.jsx(S,{variant:"outline",size:"sm",disabled:k!==null,onClick:C,children:n("Cancel")}),e.jsxs(S,{size:"sm",disabled:k!==null||o.length===0,onClick:()=>{L("merge",o)},children:[k==="preview"&&e.jsx(Ae,{className:"h-3.5 w-3.5 animate-spin"}),n("Preview")]})]}),a==="preview"&&e.jsxs(e.Fragment,{children:[e.jsx(S,{variant:"outline",size:"sm",disabled:k!==null,onClick:C,children:n("Cancel")}),y&&!x?e.jsx(S,{size:"sm",disabled:k!==null,onClick:()=>{L(d)},children:n("Refresh preview")}):e.jsxs(S,{variant:d==="replace"?"destructive":"default",size:"sm",disabled:k!==null||!x,onClick:()=>{x&&(V?O(!0):F())},children:[k==="commit"?e.jsx(Ae,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Sn,{className:"h-3.5 w-3.5"}),n(k==="commit"?"Importing…":"Import")]})]}),a==="success"&&e.jsx(S,{size:"sm",onClick:C,children:n("Done")})]})]}),e.jsx(Im,{open:A,mode:d,hasImportedExecutableResources:M,onOpenChange:O,onConfirm:()=>{F()}})]})}function Im({open:t,mode:s,hasImportedExecutableResources:n,onOpenChange:a,onConfirm:r}){const{t:o}=z();return e.jsx(An,{open:t,onOpenChange:a,children:e.jsxs(En,{className:"sm:max-w-md",zIndexLevel:"nested",children:[e.jsxs(Mn,{children:[e.jsxs(Pn,{className:"flex items-start gap-2 text-base",children:[e.jsx(Ue,{className:"mt-0.5 h-4 w-4 shrink-0 text-destructive"}),o("Confirm configuration import")]}),e.jsxs(Tn,{className:"space-y-2",children:[e.jsx("span",{className:"block",children:o("This package can change portable preferences and configuration. Continue only if you trust this package.")}),n&&e.jsx("span",{className:"block",children:o("It includes skills or MCP servers that may execute commands when you use them.")}),s==="replace"&&e.jsx("span",{className:"block",children:o("Replace mode removes local-only items from transferred collections and overwrites included portable preferences. A complete backup will be created first.")}),e.jsx("span",{className:"block",children:o("Do you want to continue with this import?")})]})]}),e.jsxs(Rn,{variant:"bare",children:[e.jsx(On,{render:e.jsx(S,{variant:"outline",size:"sm"}),children:o("Cancel")}),e.jsx(S,{variant:s==="replace"?"destructive":"default",size:"sm",onClick:()=>{a(!1),r()},children:o("Confirm import")})]})]})})}const Ea={auto:"Auto (by usage)",fast:"Fast",balanced:"Balanced",thorough:"Thorough"},Ma={standard:"Standard",smart:"Smart compaction","codex-native":"Codex native compaction","continuous-memory":"Continuous memory (experimental)"};function Am(){const{t}=z(),s=v(c=>c.compactStrategy),n=v(c=>c.smartCompactEnabled),a=Sl(s,n),r=v(c=>c.setCompactStrategy),o=a!=="standard",i=v(c=>c.smartCompactModel),d=v(c=>c.setSmartCompactModel),u=v(c=>c.smartCompactMode),x=v(c=>c.setSmartCompactMode),h=Xe(),l=i?h.find(c=>c.id===i.providerId):void 0,f=l?.models.find(c=>c.id===i?.modelId);return e.jsxs("section",{className:"space-y-2 rounded-lg border bg-card p-3","data-settings-row":"general.smartCompactEnabled",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("h4",{className:"font-medium text-sm",children:[t("Context compaction strategy"),e.jsx(qe,{})]}),e.jsx("p",{className:"mt-0.5 text-muted-foreground text-xs",children:t("Standard uses default compact. Smart compaction uses Enso verified summary at compact time. Codex native compaction additionally stores an official Codex checkpoint on Codex models and uses smart compaction otherwise. Continuous memory records observations in the background so compact keeps more context; all fall back to default compact on failure. Switching strategy takes effect on the next session. The summary model and compaction mode apply to open conversations on the next compaction.")})]}),e.jsxs(ae,{items:Object.fromEntries(ia.map(c=>[c,t(Ma[c])])),value:a,onValueChange:c=>r(c),children:[e.jsx(re,{className:"w-52",children:e.jsx(oe,{})}),e.jsx(ie,{children:ia.map(c=>e.jsx(ee,{value:c,children:t(Ma[c])},c))})]})]}),(a==="smart"||a==="codex-native")&&e.jsxs("div",{className:"flex items-center justify-between gap-4","data-smart-compact-mode":u,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Compaction mode")}),e.jsx("p",{className:"mt-0.5 text-muted-foreground/80 text-[11px]",children:t("Mode changes summary budget and how much recent tail to keep. It does not decide whether compact runs.")})]}),e.jsxs(ae,{items:Object.fromEntries(la.map(c=>[c,t(Ea[c])])),value:u,onValueChange:c=>x(c),children:[e.jsx(re,{className:"w-36",children:e.jsx(oe,{})}),e.jsx(ie,{children:la.map(c=>e.jsx(ee,{value:c,children:t(Ea[c])},c))})]})]}),o&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"font-medium text-sm",children:t(a==="continuous-memory"?"Background memory model":"Summary model")}),h.length>0&&e.jsx("div",{className:"w-full min-w-0",children:e.jsx(ze,{providers:h,providerId:l?.id??"",modelId:f?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:t("Follows the session model"),side:"bottom",triggerClassName:Ye,onSelect:(c,p)=>d({providerId:c,modelId:p}),onReasoningChange:()=>{},onThinkingChange:()=>{}})}),i&&(!l||!f)&&e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Selected model is unavailable — falls back to the session model.")}),i&&e.jsx(S,{variant:"ghost",size:"sm",className:"self-start",onClick:()=>d(null),children:t("Follow session model")})]})]})}const Em={cmd:"Command Prompt",powershell:"Windows PowerShell",pwsh:"PowerShell 7 (pwsh)","git-bash":"Git Bash",zsh:"zsh",bash:"bash",fish:"fish"};function Mm(){const{language:t,setLanguage:s}=v(),{t:n}=z();return e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:n("General")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:n("General application settings")})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h4",{className:"border-b pb-2 text-base font-semibold",children:n("Application")}),e.jsxs("div",{className:"flex items-center gap-3","data-settings-row":"general.language",children:[e.jsx("span",{className:"text-sm font-medium",children:n("Language")}),e.jsxs(ae,{items:{en:"English",zh:"简体中文"},value:t,onValueChange:a=>s(a),children:[e.jsx(re,{className:"w-48",children:e.jsx(oe,{})}),e.jsxs(ie,{children:[e.jsx(ee,{value:"en",children:"English"}),e.jsx(ee,{value:"zh",children:"简体中文"})]})]})]}),e.jsx(Pm,{}),e.jsx(Bm,{}),e.jsx(Fm,{}),e.jsx(km,{}),e.jsx(Um,{})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h4",{className:"border-b pb-2 text-base font-semibold",children:n("Agent runtime")}),e.jsx(Tm,{}),e.jsx(Rm,{}),e.jsx(Am,{}),e.jsx(pm,{})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h4",{className:"border-b pb-2 text-base font-semibold",children:n("Sessions & worktrees")}),e.jsx(Dm,{}),e.jsx(Om,{}),e.jsx(zm,{})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h4",{className:"border-b pb-2 text-base font-semibold",children:n("Terminal")}),e.jsx(_m,{}),e.jsx(Lm,{})]}),window.electronAPI.env.platform==="darwin"&&e.jsxs("section",{className:"space-y-3",children:[e.jsx("h4",{className:"border-b pb-2 text-base font-semibold",children:n("Integrations")}),e.jsx(Pa,{kind:"ensoCommand",title:n("'enso' terminal command"),description:n("Run `enso .` in a terminal to open the current folder in EnsoCode. Links the command into /usr/local/bin and may ask for your password.")}),e.jsx(Pa,{kind:"finderQuickAction",title:n("Finder Quick Action"),description:n("Right-click a folder in Finder and choose Services > Open with EnsoCode.")})]})]})}function Pa({kind:t,title:s,description:n}){const{t:a}=z(),[r,o]=m.useState(!1),[i,d]=m.useState(!1);m.useEffect(()=>{let x=!0;const h=()=>{window.electronAPI.window.shellIntegrationStatus().then(l=>{x&&o(l[t])})};return h(),window.addEventListener("focus",h),()=>{x=!1,window.removeEventListener("focus",h)}},[t]);const u=async()=>{d(!0);try{await window.electronAPI.window.installShellIntegration(t)}finally{try{const x=await window.electronAPI.window.shellIntegrationStatus();o(x[t])}finally{d(!1)}}};return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":`general.${t}`,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n})]}),e.jsx(S,{variant:"outline",size:"sm",className:"shrink-0",disabled:i,onClick:()=>{u()},children:a(i?"In progress…":r?"Uninstall":"Install")})]})}function Pm(){const{t}=z(),s=v(a=>a.notifyMainAgentOnly),n=v(a=>a.setNotifyMainAgentOnly);return e.jsx(Te,{rowId:"general.notifyMainAgentOnly",title:t("Notify only for the main agent"),description:t("Skip coworker completion and failure notifications on this computer and the paired phone. Questions and approvals still notify."),checked:s,onChange:n})}function Tm(){const{t}=z(),s=v(a=>a.generationStallTimeoutMin),n=v(a=>a.setGenerationStallTimeoutMin);return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.generationStallTimeout",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Stop if no output")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Abort and retry the run when no tokens or tool results arrive for this long. Thinking counts as output.")})]}),e.jsxs(ae,{items:Object.fromEntries(ca.map(a=>[String(a),a===0?t("Never"):t("{{count}} min",{count:a})])),value:String(s),onValueChange:a=>n(Number(a)),children:[e.jsx(re,{className:"w-28",children:e.jsx(oe,{})}),e.jsx(ie,{children:ca.map(a=>e.jsx(ee,{value:String(a),children:a===0?t("Never"):t("{{count}} min",{count:a})},a))})]})]})}function Rm(){const{t}=z(),s=v(o=>o.autoRetryLimit),n=v(o=>o.setAutoRetryLimit),a=js.some(o=>o===s)?[...js]:[...js,s].sort((o,i)=>o===vs?1:i===vs?-1:o-i),r=o=>o===0?t("Off"):o===vs?t("Unlimited"):t("{{count}} times",{count:o});return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.autoRetryLimit",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Auto-retry on transient errors")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Retry with backoff (up to 60s apart) after 429, 5xx or network errors. Quota and billing errors are never retried. Unlimited keeps retrying until you cancel.")})]}),e.jsxs(ae,{items:Object.fromEntries(a.map(o=>[String(o),r(o)])),value:String(s),onValueChange:o=>n(Number(o)),children:[e.jsx(re,{className:"w-28",children:e.jsx(oe,{})}),e.jsx(ie,{children:a.map(o=>e.jsx(ee,{value:String(o),children:r(o)},o))})]})]})}function Om(){const{t}=z(),s=v(r=>r.activeRetentionMinutes),n=v(r=>r.setActiveRetentionMinutes),a=r=>r===0?t("Off"):t("{{count}} min",{count:r});return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.activeRetentionMinutes",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Keep in Active after last message")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Viewed conversations stay in Active for this long after their last message or your last open while still in Active, then leave. Unviewed ones stay until you open them.")})]}),e.jsxs(ae,{items:Object.fromEntries(ma.map(r=>[String(r),a(r)])),value:String(s),onValueChange:r=>n(Number(r)),children:[e.jsx(re,{className:"w-28",children:e.jsx(oe,{})}),e.jsx(ie,{children:ma.map(r=>e.jsx(ee,{value:String(r),children:a(r)},r))})]})]})}function Wt(t,s){return s===0?t("Never"):s===1?t("{{count}} day",{count:s}):t("{{count}} days",{count:s})}function Dm(){const{t}=z(),s=v(d=>d.autoArchiveIdleDays),n=v(d=>d.setAutoArchiveIdleDays),a=v(d=>d.autoArchiveMergedWorktrees),r=v(d=>d.setAutoArchiveMergedWorktrees),o=v(d=>d.autoDeleteArchivedDays),i=v(d=>d.setAutoDeleteArchivedDays);return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.autoArchiveIdleDays",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Archive idle conversations")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Move conversations that have been idle this long into Archived. Does not delete them.")})]}),e.jsxs(ae,{items:Object.fromEntries(da.map(d=>[String(d),Wt(t,d)])),value:String(s),onValueChange:d=>n(Number(d)),children:[e.jsx(re,{className:"w-28",children:e.jsx(oe,{})}),e.jsx(ie,{children:da.map(d=>e.jsx(ee,{value:String(d),children:Wt(t,d)},d))})]})]}),e.jsx(Te,{rowId:"general.autoArchiveMergedWorktrees",title:t("Clean up merged worktrees"),description:t("When archiving idle conversations, also remove isolated worktrees that are merged and clean."),checked:a,onChange:r}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.autoDeleteArchivedDays",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Delete archived conversations after")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Permanently delete conversations that have been archived longer than this. This cannot be undone. Choosing a positive value deletes already-overdue archived conversations immediately.")})]}),e.jsxs(ae,{items:Object.fromEntries(ua.map(d=>[String(d),Wt(t,d)])),value:String(o),onValueChange:d=>i(Number(d)),children:[e.jsx(re,{className:"w-28",children:e.jsx(oe,{})}),e.jsx(ie,{children:ua.map(d=>e.jsx(ee,{value:String(d),children:Wt(t,d)},d))})]})]})]})}function Lm(){const{t}=z(),s=v(o=>o.terminalShell),n=v(o=>o.setTerminalShell),a=Al(window.electronAPI.env.platform),r=Object.fromEntries(a.map(o=>[o,o==="auto"?t("System default"):Em[o]]));return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.terminalShell",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Terminal shell")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Applies to new side panel terminals. SSH projects keep the remote login shell.")})]}),e.jsxs(ae,{items:r,value:s,onValueChange:o=>n(o),children:[e.jsx(re,{className:"w-56",children:e.jsx(oe,{})}),e.jsx(ie,{children:a.map(o=>e.jsx(ee,{value:o,children:r[o]},o))})]})]})}function zm(){const{t}=z(),s=v(x=>x.worktreeRoot),n=v(x=>x.setWorktreeRoot),[a,r]=m.useState(s),[o,i]=m.useState(null);m.useEffect(()=>{r(s)},[s]);const d=x=>{const h=x.trim();if(h&&!um(h)){i(t("Enter an absolute path"));return}i(null),n(h)},u=async()=>{const x=await window.electronAPI.dialog.selectDirectory();x&&(r(x),d(x))};return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.worktreeRoot",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Worktree root directory")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Where isolated session worktrees are created. Leave empty to use the app data directory. Existing worktrees stay where they are.")})]}),e.jsxs("div",{className:"w-72 shrink-0 space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(J,{value:a,placeholder:t("Default location"),onChange:x=>r(x.target.value),onBlur:()=>d(a),onKeyDown:x=>{x.key==="Enter"&&d(a)}}),e.jsx(S,{variant:"outline",size:"sm",className:"shrink-0",onClick:()=>{u()},children:t("Browse")})]}),o&&e.jsx("p",{className:"text-xs text-destructive",children:o})]})]})}function _m(){const{t}=z(),s=v(r=>r.windowsLocalShell),n=v(r=>r.setWindowsLocalShell),a={auto:t("Windows default (PowerShell)"),powershell:t("PowerShell"),bash:t("Git Bash")};return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.windowsLocalShell",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"text-sm",children:[t("Windows local command shell"),e.jsx(qe,{})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Only the Windows local agent command tool. SSH and other platforms stay on bash. Takes effect on the next session.")})]}),e.jsxs(ae,{items:a,value:s,onValueChange:r=>n(r),children:[e.jsx(re,{className:"w-56",children:e.jsx(oe,{})}),e.jsx(ie,{children:Object.keys(a).map(r=>e.jsx(ee,{value:r,children:a[r]},r))})]})]})}function Te({title:t,description:s,checked:n,onChange:a,rowId:r,children:o}){return e.jsxs("div",{className:"rounded-md border px-3 py-2.5","data-settings-row":r,children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s})]}),e.jsx(le,{checked:n,onCheckedChange:i=>a(i===!0)})]}),o?e.jsx("div",{className:"mt-2",children:o}):null]})}function Ta(t,s){window.electronAPI.proxy.apply({mode:t,customUrl:s})}function Bm(){const{t}=z(),s=v(l=>l.proxyMode),n=v(l=>l.customProxyUrl),a=v(l=>l.setProxyMode),r=v(l=>l.setCustomProxyUrl),[o,i]=m.useState(n),[d,u]=m.useState(null);m.useEffect(()=>{i(n)},[n]);const x=l=>{a(l),Ta(l,n)},h=()=>{const l=o.trim();if(l&&!El(l)){u(t("Enter an http(s) proxy URL"));return}u(null),r(l),Ta(s,l)};return e.jsxs("div",{className:"space-y-3","data-settings-row":"general.proxy",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium",children:t("Network proxy")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Used by model requests, the built-in browser, and agent tools")})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-sm font-medium",children:t("Proxy mode")}),e.jsxs(ae,{items:{system:t("Follow system proxy"),none:t("No proxy"),custom:t("Custom proxy")},value:s,onValueChange:l=>x(l),children:[e.jsx(re,{className:"w-56",children:e.jsx(oe,{})}),e.jsxs(ie,{children:[e.jsx(ee,{value:"system",children:t("Follow system proxy")}),e.jsx(ee,{value:"none",children:t("No proxy")}),e.jsx(ee,{value:"custom",children:t("Custom proxy")})]})]})]}),s==="custom"&&e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"pt-1.5 text-sm font-medium",children:t("Proxy URL")}),e.jsxs("div",{className:"min-w-0 space-y-1",children:[e.jsx(J,{value:o,placeholder:"http://127.0.0.1:7890",onChange:l=>i(l.target.value),onBlur:h,onKeyDown:l=>{l.key==="Enter"&&h()}}),d&&e.jsx("p",{className:"text-xs text-destructive",children:d})]})]})]})}function Fm(){const{t}=z(),s=v(l=>l.customCaCertPath),n=v(l=>l.setCustomCaCertPath),[a,r]=m.useState(null),[o,i]=m.useState(!1);m.useEffect(()=>{let l=!0;return window.electronAPI.caCert.status().then(f=>{l&&r(f)}).catch(()=>{}),()=>{l=!1}},[]);const d=async l=>{n(l),i(!0);try{r(await window.electronAPI.caCert.apply(l))}catch{}finally{i(!1)}},u=async()=>{const l=await window.electronAPI.dialog.selectFile([...dm]);l&&await d(l)},x={"not-absolute":t("Path must be absolute"),"not-found":t("File not found"),"not-file":t("Not a file"),"not-readable":t("File is not readable")},h=()=>a?a.source==="env"?t("Using NODE_EXTRA_CA_CERTS from the launch environment: {{path}}",{path:a.path}):a.source==="setting"?t("Set: {{path}}",{path:a.path}):a.source==="shell"?t("Not set; using NODE_EXTRA_CA_CERTS from the login shell: {{path}}",{path:a.path}):t("Not set"):"";return e.jsxs("div",{className:"space-y-3","data-settings-row":"general.caCert",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium",children:t("Custom CA certificate")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Trust an extra CA (PEM file) for model endpoints signed by a private CA. TLS verification stays on.")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(S,{size:"sm",variant:"outline",disabled:o,onClick:()=>{u()},children:t("Choose certificate file")}),s&&e.jsx(S,{size:"sm",variant:"ghost",disabled:o,onClick:()=>{d("")},children:t("Clear")})]}),a?.error?e.jsx("p",{className:"break-all text-xs text-destructive",children:t("Certificate file unavailable ({{reason}}): {{path}}",{reason:x[a.error],path:a.settingPath})}):e.jsx("p",{className:"break-all text-xs text-muted-foreground",children:h()}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Changes restart the agent process right away (running turns are interrupted). Requests made by the app main process take effect after restarting the app.")})]})}function Um(){const{t}=z(),s=v(y=>y.autoUpdate),n=v(y=>y.setAutoUpdate),a=v(y=>y.autoRestartWhenIdle),r=v(y=>y.setAutoRestartWhenIdle),[o,i]=m.useState(null),[d,u]=m.useState(null),[x,h]=m.useState(!1),[l,f]=m.useState(!1);m.useEffect(()=>{let y=!0;window.electronAPI.updater.getState().then(A=>{y&&(u(A),A.status&&i(O=>O??A.status))}).catch(()=>{});const N=window.electronAPI.updater.onStatus(i);return()=>{y=!1,N()}},[]);const c=d?.host==="server"?d:null,p=d?.host==="desktop"||c!==null&&c.mode!=="manual",g=(o?.status==="available"||o?.status==="downloaded")&&!!o.info,k=(()=>{if(!o)return null;switch(o.status){case"checking":return t("Checking for updates…");case"available":return t("New version {{version}} found",{version:o.info?.version??""});case"not-available":return t("You are on the latest version");case"downloading":return t("Downloading update… {{percent}}%",{percent:Math.round(o.progress?.percent??0)});case"downloaded":return t("New version {{version}} is ready — restart to update.",{version:o.info?.version??""});case"error":return c&&o.error?t("Update failed: {{error}}",{error:o.error}):t("Update check failed");default:return null}})(),j=o?.status==="checking"||o?.status==="downloading";return e.jsxs("div",{className:"space-y-3","data-settings-row":"general.updates",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium",children:t("Updates")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:c?$m(c.mode,t):t("Application update settings")})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"text-sm",children:[t("Current version")," · ",Vm]}),k&&e.jsx("p",{className:"mt-0.5 truncate text-xs text-muted-foreground",children:k})]}),g&&e.jsx(S,{variant:"ghost",size:"sm",onClick:()=>f(!0),className:"ml-auto shrink-0",children:t("Release notes")}),o?.status==="downloaded"?e.jsx(S,{size:"sm",onClick:()=>{window.electronAPI.updater.quitAndInstall()},className:"shrink-0",children:t("Restart to update")}):p&&o?.status==="available"?e.jsx(S,{size:"sm",onClick:()=>{window.electronAPI.updater.downloadUpdate()},className:"shrink-0",children:t("Download update")}):e.jsx(S,{variant:"outline",size:"sm",disabled:j,onClick:()=>{window.electronAPI.updater.checkForUpdates()},className:"shrink-0",children:t("Check for updates")}),e.jsx(Il,{open:l,onOpenChange:f,status:o,canDownload:p})]}),c?.canRestart&&e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Restart server")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Running tasks are interrupted; this page reconnects after the server is back.")})]}),e.jsx(S,{variant:"outline",size:"sm",onClick:()=>h(!0),className:"shrink-0",children:t("Restart")}),e.jsx(fo,{open:x,onOpenChange:h,title:t("Restart server?"),description:t("Running tasks are interrupted; this page reconnects after the server is back."),confirmLabel:t("Restart"),onConfirm:()=>{h(!1),window.electronAPI.updater.restart()}})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Automatic updates")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Download and install updates automatically")})]}),e.jsx(le,{checked:s,onCheckedChange:y=>{n(y),window.electronAPI.updater.setAutoUpdateEnabled(y)}})]}),e.jsxs("div",{className:`flex items-center justify-between gap-3 rounded-md border px-3 py-2.5 ${s?"":"opacity-60"}`,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Restart and apply when idle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("After the update is downloaded, restart automatically if no agent is running, nothing is queued, and there are no pending questions or approvals. The idle state must last 5 minutes, and a focused window also blocks it.")})]}),e.jsx(le,{checked:s&&a,disabled:!s,onCheckedChange:y=>{r(y),window.electronAPI.updater.setAutoRestartWhenIdle(y)}})]})]})}function $m(t,s){return s(t==="npm"?"Server updates install the new version with npm and restart.":"This server must be updated on the machine itself.")}const Vm="0.3.6",Km=["100%","100%","70%","100%","55%"],qm=["100%","85%","60%"];function Gm({palette:t}){return e.jsxs("div",{className:"flex h-[88px] gap-1.5 p-[7px]",style:{background:t.canvas},children:[e.jsxs("div",{className:"flex w-[30%] flex-col gap-[5px] px-0.5 py-1",children:[e.jsx("i",{className:"block h-[9px] rounded-[3px] opacity-[.18]",style:{background:t.text}}),Km.slice(1).map((s,n)=>e.jsx("i",{className:"block h-[5px] rounded-[3px] opacity-55",style:{background:t.textSubtle,width:s}},n))]}),e.jsxs("div",{className:"flex flex-1 flex-col gap-[5px] rounded-md px-2.5 py-2",style:{background:t.surface,boxShadow:`0 0 0 1px ${t.border}`},children:[e.jsx("i",{className:"block h-1 w-[70%] rounded-sm opacity-75",style:{background:t.text}}),qm.map(s=>e.jsx("i",{className:"block h-1 rounded-sm opacity-50",style:{background:t.textSubtle,width:s}},s)),e.jsx("b",{className:"mt-auto flex h-3.5 justify-end rounded-full p-[3px]",style:{background:t.sunken,boxShadow:`0 0 0 1px ${t.border}`},children:e.jsx("span",{"data-theme-accent":!0,className:"size-2 rounded-full",style:{background:t.accent}})})]})]})}const Ra="overflow-hidden rounded-lg border text-left transition-shadow";function Hm({themes:t,selected:s,mode:n,onSelect:a,onGetMore:r}){const{t:o}=z();return e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[t.map(i=>{const d=i.id===s;return e.jsxs("button",{type:"button","data-theme-card":i.id,"aria-pressed":d,onClick:()=>a(i.id),className:G(Ra,"bg-card",d?"border-transparent shadow-[0_0_0_2px_var(--brand)]":"hover:border-input"),children:[e.jsx(Gm,{palette:i[n]}),e.jsxs("div",{className:"flex items-center gap-1.5 border-t px-2.5 py-[7px] text-sm",children:[e.jsx("span",{className:"truncate font-medium",children:i.name}),e.jsx("span",{className:G("ml-auto shrink-0 truncate rounded-full px-1.5 py-px text-[10.5px]",i.source.kind==="plugin"?"max-w-[60%] bg-brand/12 text-brand":"bg-muted text-subtle-foreground"),children:i.source.kind==="plugin"?o("Plugin · {{name}}",{name:i.source.pluginName}):o("Built-in")})]})]},i.id)}),r&&e.jsxs("button",{type:"button",onClick:r,className:G(Ra,"flex min-h-[124px] flex-col items-center justify-center gap-1.5 border-dashed text-sm text-subtle-foreground hover:border-input hover:text-foreground"),children:[e.jsx(Bt,{className:"size-[18px]"}),o("Get more themes")]})]})}function gn({rowId:t,title:s,description:n,children:a}){return e.jsxs("div",{"data-settings-row":t,className:"flex min-h-12 items-center justify-between gap-4 px-3.5 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium",children:s}),n&&e.jsx("p",{className:"text-xs text-muted-foreground",children:n})]}),e.jsx("div",{className:"flex shrink-0 items-center gap-2",children:a})]})}function Wm({children:t}){return e.jsx("div",{className:"divide-y rounded-lg border bg-card",children:t})}function tt({label:t,value:s,onCommit:n,min:a=0,max:r=100,step:o,unit:i="%",formatSuffix:d,onPreview:u,trailing:x,valueClassName:h="w-12"}){const[l,f]=m.useState(s);m.useEffect(()=>{f(s)},[s]);const c=d?.(l);return e.jsxs("div",{className:G("grid items-center gap-4",x?"grid-cols-[9.5rem_minmax(0,1fr)_auto]":"grid-cols-[100px_1fr]"),children:[e.jsx("span",{className:"text-sm font-medium",children:t}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(_l,{min:a,max:r,step:o,value:l,onValueChange:p=>{const g=Array.isArray(p)?p[0]:p;f(g),u?.(g)},onValueCommitted:p=>n(Array.isArray(p)?p[0]:p)}),e.jsxs("span",{className:G("shrink-0 text-right text-sm text-muted-foreground tabular-nums",c?"w-28":h),children:[l,i,c?` · ${c}`:""]})]}),x]})}function Ym(){const{t}=z(),s=v(P=>P.backgroundImageEnabled),n=v(P=>P.setBackgroundImageEnabled),a=v(P=>P.backgroundSourceType),r=v(P=>P.setBackgroundSourceType),o=v(P=>P.backgroundImagePath),i=v(P=>P.setBackgroundImagePath),d=v(P=>P.backgroundFolderPath),u=v(P=>P.setBackgroundFolderPath),x=v(P=>P.backgroundUrlPath),h=v(P=>P.setBackgroundUrlPath),l=v(P=>P.backgroundRandomEnabled),f=v(P=>P.setBackgroundRandomEnabled),c=v(P=>P.backgroundRandomInterval),p=v(P=>P.setBackgroundRandomInterval),g=v(P=>P.backgroundOpacity),w=v(P=>P.setBackgroundOpacity),k=v(P=>P.backgroundBlur),j=v(P=>P.setBackgroundBlur),y=v(P=>P.backgroundBrightness),N=v(P=>P.setBackgroundBrightness),A=v(P=>P.backgroundSaturation),O=v(P=>P.setBackgroundSaturation),I=v(P=>P.backgroundMask),L=v(P=>P.setBackgroundMask),C=v(P=>P.backgroundComposerOpacity),E=v(P=>P.setBackgroundComposerOpacity),M=v(P=>P.backgroundCodeOpacity),V=v(P=>P.setBackgroundCodeOpacity),F=v(P=>P.backgroundSizeMode),b=v(P=>P.setBackgroundSizeMode),B=v(P=>P.bumpBackgroundRefresh),K=Bl()?.source==="theme",D=a==="file"?o:a==="folder"?d:x,[$,Y]=m.useState(D);m.useEffect(()=>{Y(D)},[D]);const H=m.useCallback(()=>{const P=$.trim();a==="file"?i(P):a==="folder"?u(P):h(P)},[$,a,i,u,h]),[se,q]=m.useState(c);m.useEffect(()=>{q(c)},[c]);const Q=async()=>{if(a==="folder"){const P=await window.electronAPI.dialog.selectDirectory();P&&u(P)}else{const P=await window.electronAPI.dialog.selectFile([...$l,...Vl]);P&&i(P)}},_=[{value:"file",label:t("Single image")},{value:"folder",label:t("Folder (random)")},{value:"url",label:t("Remote URL")}],ne=[{value:"cover",label:t("Cover")},{value:"contain",label:t("Contain")},{value:"repeat",label:t("Repeat")},{value:"center",label:t("Center")}],R=t(a==="file"?"Image path":a==="folder"?"Folder path":"Image URL");return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between border-t pt-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:t("Background image")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("Show a custom image behind the interface")})]}),e.jsx(le,{checked:s,onCheckedChange:P=>n(P===!0)})]}),K&&e.jsx("p",{className:"text-sm text-muted-foreground",children:t("The current theme has its own background. Turn this on to replace it with your image.")}),s&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:t("Source type")}),e.jsxs(ae,{items:_,value:a,onValueChange:P=>r(P),children:[e.jsx(re,{className:"w-48",children:e.jsx(oe,{})}),e.jsx(ie,{children:_.map(P=>e.jsx(ee,{value:P.value,children:P.label},P.value))})]})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:R}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(J,{value:$,onChange:P=>Y(P.target.value),onBlur:H,onKeyDown:P=>{P.nativeEvent.isComposing||P.key==="Enter"&&(H(),P.currentTarget.blur())},placeholder:a==="url"?"https://example.com/image.jpg":"",className:"flex-1"}),a!=="url"&&e.jsx(S,{variant:"outline",size:"icon",onClick:Q,"aria-label":t("Browse"),children:a==="folder"?e.jsx(_n,{className:"h-4 w-4"}):e.jsx(Ou,{className:"h-4 w-4"})}),a!=="file"&&e.jsx(S,{variant:"outline",size:"icon",onClick:B,"aria-label":t("Refresh now"),children:e.jsx(Je,{className:"h-4 w-4"})})]})]}),a!=="file"&&e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:t("Auto switch")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(le,{checked:l,onCheckedChange:P=>f(P===!0)}),l&&e.jsxs(e.Fragment,{children:[e.jsx(J,{type:"number",min:5,max:86400,value:se,onChange:P=>q(Number(P.target.value)),onBlur:()=>p(se),onKeyDown:P=>{P.key==="Enter"&&(p(se),P.currentTarget.blur())},className:"w-24"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:t("seconds")})]})]})]}),e.jsx(tt,{label:t("Background visibility"),value:Math.round(g*100),onCommit:P=>w(P/100)}),e.jsx(tt,{label:t("Blur"),value:k,onCommit:j,max:20,unit:"px"}),e.jsx(tt,{label:t("Brightness"),value:Math.round(y*100),onCommit:P=>N(P/100),max:200}),e.jsx(tt,{label:t("Saturation"),value:Math.round(A*100),onCommit:P=>O(P/100),max:200}),e.jsx(tt,{label:t("Overlay"),value:Math.round(I*100),onCommit:P=>L(P/100)}),e.jsx(tt,{label:t("Composer opacity"),value:Math.round(C*100),onCommit:P=>E(P/100)}),e.jsx(tt,{label:t("Code block opacity"),value:Math.round(M*100),onCommit:P=>V(P/100)}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:t("Size mode")}),e.jsxs(ae,{items:ne,value:F,onValueChange:P=>b(P),children:[e.jsx(re,{className:"w-48",children:e.jsx(oe,{})}),e.jsx(ie,{children:ne.map(P=>e.jsx(ee,{value:P.value,children:P.label},P.value))})]})]})]})]})}function Jm({theme:t,fontSize:s,fontFamily:n,fontWeight:a}){const r=[{id:"prompt1",text:"$ ",color:t.green},{id:"cmd1",text:"ls -la",color:t.foreground},{id:"nl1",text:`
3
3
  `},{id:"perm1",text:"drwxr-xr-x ",color:t.blue},{id:"meta1",text:"5 user staff 160 Dec 23 ",color:t.foreground},{id:"dir1",text:"Documents",color:t.cyan},{id:"nl2",text:`
4
4
  `},{id:"perm2",text:"-rw-r--r-- ",color:t.foreground},{id:"meta2",text:"1 user staff 2048 Dec 22 ",color:t.foreground},{id:"file1",text:"config.json",color:t.yellow},{id:"nl3",text:`
5
5
 
@@ -7,28 +7,28 @@ import{c as Ee,w as $i,D as sa,j as e,A as Vi,r as m,u as ro,a as oo,b as Cn,d a
7
7
  `},{id:"output1",text:"Hello, World!",color:t.magenta}];return e.jsxs("div",{className:"rounded-lg border p-4 h-40 overflow-auto",style:{backgroundColor:t.background,fontSize:`${s}px`,fontFamily:n,fontWeight:a},children:[r.map(o=>o.text===`
8
8
  `?e.jsx("br",{},o.id):o.text===`
9
9
 
10
- `?e.jsxs(m.Fragment,{children:[e.jsx("br",{}),e.jsx("br",{})]},o.id):e.jsx("span",{style:{color:o.color},children:o.text},o.id)),e.jsx("span",{className:"inline-block w-2 h-4 animate-pulse",style:{backgroundColor:t.cursor}})]})}function Ym({isFavorite:t,onClick:s,ariaLabel:n}){return e.jsx("button",{type:"button","aria-label":n,"aria-pressed":t,onClick:a=>{a.stopPropagation(),a.preventDefault(),s(a)},className:"p-1 hover:text-red-500 transition-colors",children:t?e.jsx(Ca,{className:"h-4 w-4 fill-red-500 text-red-500"}):e.jsx(Ca,{className:"h-4 w-4"})})}function Jm({value:t,onValueChange:s,themes:n,favoriteThemes:a,onToggleFavorite:r,onThemeHover:o,showFavoritesOnly:i,onShowFavoritesOnlyChange:d,showEmptyFavoritesHint:u}){const{t:x}=z(),[h,l]=m.useState(t),[f,c]=m.useState(t),[p,g]=m.useState(!1),w=m.useRef(void 0),k=m.useRef(null),j=m.useRef(t),y=m.useRef(!1),N=m.useMemo(()=>new Set(a),[a]);m.useEffect(()=>{p||(l(t),c(t))},[t,p]);const A=m.useMemo(()=>{if(!f||f===h)return n;const E=f.toLowerCase();return n.filter(M=>M.toLowerCase().includes(E))},[n,f,h]),O=E=>{E&&(y.current=!0,l(E),c(E)),s(E)},I=E=>{g(E),E?(j.current=t,y.current=!1,l(t),c(t)):y.current||o?.(j.current)},L=E=>{clearTimeout(w.current),w.current=setTimeout(()=>{o?.(E)},50)},C=()=>{clearTimeout(w.current)};return m.useEffect(()=>{if(!p)return;const E=M=>{(M.key==="ArrowDown"||M.key==="ArrowUp")&&requestAnimationFrame(()=>{const V=k.current?.querySelector("[data-highlighted]");if(V){const F=V.getAttribute("data-value");F&&o?.(F)}})};return document.addEventListener("keydown",E,!0),()=>{document.removeEventListener("keydown",E,!0)}},[p,o]),m.useEffect(()=>()=>{clearTimeout(w.current)},[]),e.jsxs(tm,{value:h,onValueChange:O,inputValue:f,onInputValueChange:c,open:p,onOpenChange:I,children:[e.jsxs("div",{className:"relative",children:[e.jsx(sm,{placeholder:x("Search themes...")}),e.jsxs("div",{className:"absolute right-8 top-1/2 -translate-y-1/2 flex items-center gap-1.5",children:[e.jsx(Qe,{id:"show-favorites-only-inner",checked:i,onCheckedChange:E=>d(E===!0),onClick:E=>E.stopPropagation()}),e.jsx("label",{htmlFor:"show-favorites-only-inner",className:"text-xs text-muted-foreground cursor-pointer whitespace-nowrap",onClick:E=>E.stopPropagation(),onKeyDown:E=>E.stopPropagation(),children:x("Show favorites only")})]})]}),e.jsx(am,{children:e.jsxs(om,{ref:k,children:[A.length===0&&e.jsx("div",{className:"py-6 text-center text-sm text-muted-foreground",children:x(u?"No favorite themes yet. Click the heart icon to add favorites.":"No themes found")}),A.map(E=>e.jsx(rm,{value:E,"data-value":E,onMouseEnter:()=>L(E),onMouseLeave:C,endAddon:e.jsx(Ym,{isFavorite:N.has(E),onClick:()=>r(E),ariaLabel:N.has(E)?x("Remove from favorites"):x("Add to favorites")}),children:E},E))]})})]})}const Qm={theme:"Follow theme",violet:"Violet",indigo:"Indigo",teal:"Teal",amber:"Amber",graphite:"Graphite"},Oa={body:"Body",h1:"Heading 1",h2:"Heading 2",h3:"Heading 3",h4:"Heading 4–6",table:"Table",inlineCode:"Inline code",codeBlock:"Code block"},Da=yo.map(t=>({value:String(t),label:String(t)}));function Xm(){const{t}=z(),s=v(u=>u.chatTypography),n=v(u=>u.setChatTypography),a=v(u=>u.resetChatTypography),[r,o]=m.useState(s.body.size);m.useEffect(()=>{o(s.body.size)},[s.body.size]);const i=(u,x)=>{const h=v.getState().chatTypography;n({...h,[u]:{...h[u],size:x}})},d=(u,x)=>{const h=v.getState().chatTypography;n({...h,[u]:{...h[u],weight:x}})};return e.jsxs("section",{"data-settings-row":"appearance.chatTypography",className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:t("Conversation typography")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("Headings, tables and inline code scale with the body text")})]}),e.jsxs("div",{className:"space-y-3 rounded-lg border bg-card p-3.5",children:[Fl.map(u=>{const x=Ul[u];return e.jsx(tt,{label:t(Oa[u]),value:s[u].size,min:x.min,max:x.max,step:x.step,unit:x.unit==="%"?"%":"px",valueClassName:"w-28",formatSuffix:x.unit==="%"?h=>`${(r*h/100).toFixed(1)}px`:void 0,onPreview:u==="body"?o:void 0,onCommit:h=>i(u,h),trailing:e.jsxs(ae,{items:Da,value:String(s[u].weight),onValueChange:h=>{const l=Number(h);yo.includes(l)&&d(u,l)},children:[e.jsx(re,{className:"w-24 min-w-24","aria-label":t(Oa[u]),children:e.jsx(oe,{})}),e.jsx(ie,{children:Da.map(h=>e.jsx(ee,{value:h.value,children:h.label},h.value))})]})},u)}),e.jsx("div",{className:"flex justify-end",children:e.jsx(S,{variant:"outline",size:"sm",onClick:()=>a(),children:t("Reset to defaults")})})]})]})}function Zm({seconds:t,onCommit:s}){const{t:n}=z(),[a,r]=m.useState(String(t));m.useEffect(()=>r(String(t)),[t]);const o=()=>{const i=Number(a);if(!Number.isInteger(i)){r(String(t));return}const d=Kl(i);s(d),r(String(d))};return e.jsxs("div",{className:"flex items-center justify-between gap-3","data-settings-row":"appearance.liveActivityFoldDelaySec",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:n("Wait before folding")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n("Seconds to wait after tools and thinking finish")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(J,{type:"number",min:1,max:60,value:a,onChange:i=>r(i.target.value),onBlur:o,onKeyDown:i=>{i.key==="Enter"&&(o(),i.currentTarget.blur())},className:"w-20"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:n("sec")})]})]})}function eh(){const{t}=z(),s=v(A=>A.openChangesOnFileEdit),n=v(A=>A.setOpenChangesOnFileEdit),a=v(A=>A.compactReadOnlyTools),r=v(A=>A.setCompactReadOnlyTools),o=v(A=>A.expandLiveEdits),i=v(A=>A.setExpandLiveEdits),d=v(A=>A.expandLiveReasoning),u=v(A=>A.setExpandLiveReasoning),x=v(A=>A.autoCollapseTurns),h=v(A=>A.setAutoCollapseTurns),l=v(A=>A.collapseCompletedActivity),f=v(A=>A.setCollapseCompletedActivity),c=v(A=>A.collapseLiveActivity),p=v(A=>A.setCollapseLiveActivity),g=v(A=>A.liveActivityFoldDelaySec),w=v(A=>A.setLiveActivityFoldDelaySec),k=v(A=>A.pinUnfinishedTodos),j=v(A=>A.setPinUnfinishedTodos),y=v(A=>A.navRailSide),N=v(A=>A.setNavRailSide);return e.jsxs("div",{className:"space-y-6",children:[e.jsx("h3",{className:"text-lg font-medium",children:t("Conversation display")}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Te,{rowId:"appearance.openChangesOnFileEdit",title:t("Open Changes when files are edited"),description:t("Automatically show the side panel Changes tab after the agent edits a file"),checked:s,onChange:n}),e.jsx(Te,{rowId:"appearance.compactReadOnlyTools",title:t("Compact read-only tool calls"),description:t("Show read/grep/find/ls as one-line rows and fold consecutive tool calls while the agent is still running"),checked:a,onChange:r}),e.jsx(Te,{rowId:"appearance.expandLiveEdits",title:t("Expand file edits while running"),description:t("Automatically unfold diffs or written content from file modification tools while the agent is still running"),checked:o,onChange:i}),e.jsx(Te,{rowId:"appearance.expandLiveReasoning",title:t("Expand reasoning while streaming"),description:t("Automatically unfold the thinking block while the model is still reasoning. It collapses again when reasoning ends."),checked:d,onChange:u}),e.jsx(Te,{rowId:"appearance.autoCollapseTurns",title:t("Auto-collapse previous turns"),description:t("After you send a new message, fold earlier turns down to the question, timestamp and duration; the latest turn stays expanded"),checked:x,onChange:h}),e.jsx(Te,{rowId:"appearance.collapseCompletedActivity",title:t("Collapse activity after reply"),description:t("When a reply finishes, fold consecutive thinking and tool calls (including edits and commands) into one summary row; failed calls stay visible"),checked:l,onChange:f}),e.jsx(Te,{rowId:"appearance.collapseLiveActivity",title:t("Collapse finished activity while replying"),description:t("While a reply is still running, wait a moment after tools and thinking finish, then fold that stretch into one row. Calls still running stay visible, and failed calls stay visible"),checked:c,onChange:p,children:c?e.jsx(Zm,{seconds:g,onCommit:w}):null}),e.jsx(Te,{rowId:"appearance.pinUnfinishedTodos",title:t("Pin unfinished todos"),description:t("Keep the latest todo list above the input while it has unfinished items, so it does not scroll away with the timeline"),checked:k,onChange:j}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"appearance.navRailSide",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Turn marks")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Marks along the conversation for each turn. Hover to preview, click to jump. Hidden when the chat uses the full width.")})]}),e.jsx("div",{className:"w-36 shrink-0",children:e.jsx(zn,{value:y,options:[{value:"left",label:t("Left")},{value:"right",label:t("Right")},{value:"off",label:t("Off")}],onChange:N})})]})]}),e.jsx(Xm,{}),e.jsx(cm,{})]})}function th({onOpenPlugins:t}){const{t:s}=z(),n=v(i=>i.themeId),a=v(i=>i.setThemeId),r=Dn(i=>i.themes),o=go();return e.jsxs("section",{"data-settings-row":"appearance.themeGallery",className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("Theme")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("Built-in and plugin themes; each one is a set of color tokens")})]}),e.jsx(qm,{themes:vo(r),selected:n,mode:o,onSelect:a,onGetMore:t})]})}function sh(){const{t}=z(),s=v(r=>r.userCssEnabled),n=v(r=>r.setUserCssEnabled),a=async()=>{const r=await window.electronAPI.appearance.openUserCss();r.ok||Re({type:"error",title:t("Cannot open user.css"),description:r.error})};return e.jsxs(gn,{rowId:"appearance.userCss",title:t("Custom CSS"),description:t("Inject user.css into every window; saved changes apply immediately"),children:[e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>{a()},children:[e.jsx(zl,{}),t("Open user.css")]}),e.jsx(le,{checked:s,onCheckedChange:r=>n(r===!0),"aria-label":t("Custom CSS")})]})}function nh({onOpenPlugins:t}={}){const s=v(B=>B.borderOpacity),n=v(B=>B.setBorderOpacity),{theme:a,setTheme:r,themeId:o,accentColor:i,setAccentColor:d,terminalTheme:u,setTerminalTheme:x,terminalFontSize:h,setTerminalFontSize:l,terminalFontFamily:f,setTerminalFontFamily:c,terminalFontWeight:p,setTerminalFontWeight:g,terminalFontWeightBold:w,setTerminalFontWeightBold:k,favoriteTerminalThemes:j,toggleFavoriteTerminalTheme:y}=v(),{t:N}=z(),A=go(),O=Dn(B=>B.themes),I=[{value:"light",icon:Ku,label:N("Light")},{value:"dark",icon:Ml,label:N("Dark")},{value:"system",icon:Ln,label:N("System")},{value:"sync-terminal",icon:jo,label:N("Sync terminal theme")}],L=Pl.map(B=>({value:B,label:N(Qm[B]),swatch:B==="theme"?Rl(o,vo(O))[A].accent:Tl[B][A]})),[C,E]=m.useState(h),[M,V]=m.useState(f),[F,b]=m.useState(!1);m.useEffect(()=>{E(h)},[h]),m.useEffect(()=>{V(f)},[f]);const _=m.useCallback(()=>{const B=Math.max(8,Math.min(32,C||8));B!==C&&E(B),B!==h&&l(B)},[C,h,l]),K=m.useCallback(()=>{const B=M.trim()||f;B!==M&&V(B),B!==f&&c(B)},[M,f,c]),D=m.useMemo(()=>Ol(),[]),$=m.useMemo(()=>{if(!F)return D;const B=D.filter(ne=>j.includes(ne));return j.includes(u)?B:[u,...B]},[D,F,j,u]),Y=F&&j.length===0,H=m.useMemo(()=>Ll(u)??Dl,[u]),se=B=>{B&&x(B)},q=()=>{const B=F?$:D,ne=B.indexOf(u),R=ne<=0?B.length-1:ne-1;x(B[R])},Q=()=>{const B=F?$:D,ne=B.indexOf(u),R=ne>=B.length-1?0:ne+1;x(B[R])};return e.jsxs("div",{className:"space-y-6",children:[e.jsx(th,{onOpenPlugins:t}),e.jsxs("section",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:N("Personalization")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:N("Applied on top of any theme")})]}),e.jsxs(Gm,{children:[e.jsx(gn,{rowId:"appearance.theme",title:N("Theme mode"),children:e.jsx("div",{className:"flex rounded-lg bg-muted p-0.5",children:I.map(B=>e.jsxs("button",{type:"button",onClick:()=>r(B.value),"aria-pressed":a===B.value,className:G("flex h-7 items-center gap-1.5 rounded-md px-2.5 text-xs transition-colors",a===B.value?"bg-background text-foreground shadow-xs":"text-muted-foreground hover:text-foreground"),children:[e.jsx(B.icon,{className:"size-3.5"}),B.label]},B.value))})}),e.jsx(gn,{rowId:"appearance.accent",title:N("Accent color"),description:N("Used for running state, checkmarks and plan mode"),children:L.map(B=>B.value==="theme"?e.jsxs("button",{type:"button",onClick:()=>d(B.value),"aria-pressed":i===B.value,className:G("flex h-6 items-center gap-1.5 rounded-full border px-2 text-xs transition-shadow",i===B.value&&"border-transparent ring-2 ring-foreground/60"),children:[e.jsx("span",{"data-theme-accent":!0,className:"size-2.5 rounded-full",style:{backgroundColor:B.swatch}}),B.label]},B.value):e.jsx("button",{type:"button",onClick:()=>d(B.value),title:B.label,"aria-label":B.label,"aria-pressed":i===B.value,style:{backgroundColor:B.swatch},className:G("size-5 rounded-full transition-shadow",i===B.value&&"ring-2 ring-offset-2 ring-offset-card ring-foreground/60")},B.value))}),e.jsx(sh,{})]})]}),e.jsx(eh,{}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:N("Terminal")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:N("Terminal appearance")})]}),e.jsx(Wm,{theme:H,fontSize:C,fontFamily:M,fontWeight:p}),e.jsxs("div",{className:"space-y-3 rounded-lg border bg-card p-3.5",children:[e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:N("Color scheme")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(S,{variant:"outline",size:"icon",onClick:q,children:e.jsx(bo,{className:"h-4 w-4"})}),e.jsx("div",{className:"flex-1",children:e.jsx(Jm,{value:u,onValueChange:se,themes:$,favoriteThemes:j,onToggleFavorite:y,onThemeHover:x,showFavoritesOnly:F,onShowFavoritesOnlyChange:b,showEmptyFavoritesHint:Y})}),e.jsx(S,{variant:"outline",size:"icon",onClick:Q,children:e.jsx(Mt,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:N("Font")}),e.jsx(J,{value:M,onChange:B=>V(B.target.value),onBlur:K,onKeyDown:B=>{B.nativeEvent.isComposing||B.key==="Enter"&&(K(),B.currentTarget.blur())},placeholder:"JetBrains Mono, monospace"})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:N("Font size")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(J,{type:"number",value:C,onChange:B=>E(Number(B.target.value)),onBlur:_,onKeyDown:B=>{B.key==="Enter"&&(_(),B.currentTarget.blur())},min:8,max:32,className:"w-20"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"px"})]})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:N("Font weight")}),e.jsxs(ae,{items:Gt,value:p,onValueChange:B=>g(B),children:[e.jsx(re,{className:"w-48",children:e.jsx(oe,{})}),e.jsx(ie,{children:Gt.map(B=>e.jsx(ee,{value:B.value,children:B.label},B.value))})]})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:N("Bold font weight")}),e.jsxs(ae,{items:Gt,value:w,onValueChange:B=>k(B),children:[e.jsx(re,{className:"w-48",children:e.jsx(oe,{})}),e.jsx(ie,{children:Gt.map(B=>e.jsx(ee,{value:B.value,children:B.label},B.value))})]})]})]}),e.jsx(tt,{label:N("Border opacity"),value:Math.round(s*100),onCommit:B=>n(B/100)}),e.jsx(Hm,{})]})}const La=15e3,ah=3e3;function rh(t){return!t||!t.timeoutSet&&t.timeoutMs===ah?La:t.timeoutMs}const za=()=>{},ys="off",ws=t=>({timeoutMs:t?.timeoutMs??ql,...t?.timeoutSet&&{timeoutSet:!0}});function oh({classifier:t,effectiveMs:s,hint:n,onChange:a}){const{t:r}=z(),[o,i]=m.useState(String(s/1e3));m.useEffect(()=>i(String(s/1e3)),[s]);const d=()=>{const u=Number(o);if(!o.trim()||!Number.isFinite(u))return i(String(s/1e3));const x=Wl(u*1e3);i(String(x/1e3)),x!==s&&a({...t,timeoutMs:x,timeoutSet:!0})};return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs",children:r("Timeout")}),e.jsx(J,{type:"number",value:o,min:Hl/1e3,max:Gl/1e3,step:.5,className:"h-7 w-20 text-xs",onChange:u=>i(u.target.value),onBlur:d,onKeyDown:u=>{u.key==="Enter"&&u.currentTarget.blur()}}),e.jsx("span",{className:"text-xs text-muted-foreground",children:r("seconds")}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:n})]})}function ts({providers:t,value:s,emptyLabel:n,onSelect:a}){return e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx(ze,{providers:t,providerId:s?.providerId??"",modelId:s?.modelId??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:n,side:"bottom",triggerClassName:Ye,onSelect:(r,o)=>a({providerId:r,modelId:o}),onReasoningChange:za,onThinkingChange:za})})}function Yt({label:t,hint:s,children:n}){return e.jsxs("div",{className:"grid grid-cols-[6rem_1fr] items-start gap-2",children:[e.jsxs("div",{className:"pt-1.5 text-xs",children:[e.jsx("div",{children:t}),s&&e.jsx("div",{className:"text-[10px] text-muted-foreground",children:s})]}),e.jsx("div",{className:"min-w-0 space-y-1",children:n})]})}function ui({value:t,onChange:s,providers:n,classifierProviders:a,offLabel:r,judgeLabel:o,judgeSeed:i,description:d,effectiveTimeoutMs:u,timeoutHint:x}){const{t:h}=z(),l=t,[f,c]=m.useState(!1),p=l?.source??(f?"judge":ys),g=l?.source==="pi-classifier"?l.model.providerId:"",[w,k]=m.useState([]),[j,y]=m.useState(!1);m.useEffect(()=>{if(!g){k([]);return}let I=!1;return window.electronAPI.providers.classifierModels(g).then(L=>{I||k(L)}),()=>{I=!0}},[g]);const N=async I=>{const C=(await window.electronAPI.providers.classifierModels(I))[0];y(!C),C&&s({source:"pi-classifier",model:{providerId:I,modelId:C.id},...ws(l)})},A=I=>{if(y(!1),c(I==="judge"&&!i),I===ys)return s(void 0);if(I==="judge")return s(i?{source:"judge",model:i,...ws(l)}:void 0);const L=a[0];L&&N(L.id)},O=[{value:ys,label:r},{value:"judge",label:o},...a.length>0?[{value:"pi-classifier",label:h("Classifier model")}]:[]];return e.jsxs("div",{className:"space-y-1",children:[e.jsxs(ae,{items:O,value:p,onValueChange:I=>A(String(I)),children:[e.jsx(re,{size:"sm",className:"w-48",children:e.jsx(oe,{})}),e.jsx(ie,{children:O.map(I=>e.jsx(ee,{value:I.value,children:I.label},I.value))})]}),p==="judge"&&e.jsx(ts,{providers:n,value:l?.source==="judge"?l.model:void 0,emptyLabel:h("Select model"),onSelect:I=>{c(!1),s({source:"judge",model:I,...ws(l)})}}),l?.source==="pi-classifier"&&e.jsxs("div",{className:"flex gap-1",children:[e.jsxs(ae,{items:a.map(I=>({value:I.id,label:I.name})),value:l.model.providerId,onValueChange:I=>{N(String(I))},children:[e.jsx(re,{size:"sm",className:"w-40",children:e.jsx(oe,{})}),e.jsx(ie,{children:a.map(I=>e.jsx(ee,{value:I.id,children:I.name},I.id))})]}),e.jsxs(ae,{items:w.map(I=>({value:I.id,label:I.name})),value:l.model.modelId||null,onValueChange:I=>s({...l,model:{providerId:l.model.providerId,modelId:String(I)}}),children:[e.jsx(re,{size:"sm",className:"min-w-0 flex-1",children:e.jsx(oe,{placeholder:h("Select model")})}),e.jsx(ie,{children:w.map(I=>e.jsx(ee,{value:I.id,children:I.name},I.id))})]})]}),j&&e.jsx("p",{className:"text-[10px] text-destructive",children:h("No classifier models available")}),l&&e.jsx(oh,{classifier:l,effectiveMs:u??l.timeoutMs,hint:x,onChange:s}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:d})]})}function ih({entry:t,providers:s,classifierProviders:n,update:a}){const{t:r}=z();return t.fast?e.jsx(ui,{value:t.classifier,onChange:o=>a({classifier:o}),providers:s,classifierProviders:n,offLabel:r("Off"),judgeLabel:r("Fast model judges"),judgeSeed:t.fast,description:r("Classifies each new turn: simple turns use the fast model, complex ones the primary model. Adds a short delay before the reply."),timeoutHint:r("Uses the primary model on timeout.")}):e.jsx("p",{className:"pt-1.5 text-[11px] text-muted-foreground",children:r("Set a fast model first")})}function lh({entry:t,providers:s,classifierProviders:n}){const{t:a}=z(),r=v(x=>x.updateVirtualModel),o=v(x=>x.removeVirtualModel),i=[t.primary,...t.fast?[t.fast]:[],...t.fallbacks];let d;for(const x of s){const h=x.models.find(l=>l.enabled!==!1&&!i.some(f=>f.providerId===x.id&&f.modelId===l.id));if(h){d={providerId:x.id,modelId:h.id};break}}const u=x=>r(t.id,x);return e.jsxs("div",{"data-slot":"virtual-model-card",className:G("space-y-2 rounded-md border p-2",!t.enabled&&"bg-muted/50 text-muted-foreground"),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(le,{"aria-label":a("Enable virtual model"),checked:t.enabled,onCheckedChange:x=>u({enabled:x})}),e.jsx(J,{value:t.name,maxLength:60,placeholder:"Auto",className:"h-7 flex-1 text-xs",onChange:x=>u({name:x.target.value})}),!t.enabled&&e.jsx(te,{variant:"outline",className:"shrink-0 text-[10px] text-muted-foreground",children:a("Disabled")}),e.jsx(S,{type:"button",variant:"ghost",size:"icon","aria-label":a("Delete"),className:"h-6 w-6 shrink-0 text-muted-foreground hover:text-destructive",onClick:()=>o(t.id),children:e.jsx(Me,{className:"h-3.5 w-3.5"})})]}),e.jsx(Yt,{label:a("Primary model"),hint:a("Default for each new turn"),children:e.jsx(ts,{providers:s,value:t.primary,onSelect:x=>u({primary:x,fallbacks:t.fallbacks.filter(h=>h.providerId!==x.providerId||h.modelId!==x.modelId)})})}),e.jsx(Yt,{label:a("Fast model"),hint:a("Summaries and simple turns"),children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(ts,{providers:s,value:t.fast,emptyLabel:a("Not used"),onSelect:x=>u({fast:x})}),t.fast&&e.jsx(S,{type:"button",variant:"ghost",size:"icon","aria-label":a("Clear"),className:"h-6 w-6 shrink-0 text-muted-foreground",onClick:()=>u({fast:void 0}),children:e.jsx(ht,{className:"h-3.5 w-3.5"})})]})}),e.jsxs(Yt,{label:a("Fallback models"),hint:a("Used in order when a model is rate limited or down"),children:[t.fallbacks.map((x,h)=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(ts,{providers:s,value:x,onSelect:l=>u({fallbacks:t.fallbacks.map((f,c)=>c===h?l:f)})}),e.jsx(S,{type:"button",variant:"ghost",size:"icon","aria-label":a("Delete"),className:"h-6 w-6 shrink-0 text-muted-foreground hover:text-destructive",onClick:()=>u({fallbacks:t.fallbacks.filter((l,f)=>f!==h)}),children:e.jsx(ht,{className:"h-3.5 w-3.5"})})]},`${x.providerId}/${x.modelId}`)),e.jsxs(S,{type:"button",variant:"outline",size:"sm",className:"h-7 text-xs",disabled:!d||t.fallbacks.length>=8,onClick:()=>{d&&u({fallbacks:[...t.fallbacks,d]})},children:[e.jsx(Oe,{className:"mr-1 h-3.5 w-3.5"}),a("Add fallback")]})]}),e.jsx(Yt,{label:a("Difficulty routing"),children:e.jsx(ih,{entry:t,providers:s,classifierProviders:n,update:u})})]})}function ch(){const{t}=z(),s=v(u=>u.virtualModels),n=v(u=>u.addVirtualModel),a=v(u=>u.defaultModel),r=Xe(),o=m.useMemo(()=>r.filter(wo),[r]),i=_n(),d=m.useMemo(()=>{if(a&&o.find(x=>x.id===a.providerId)?.models.some(x=>x.id===a.modelId&&x.enabled!==!1))return a;for(const u of o){const x=u.models.find(h=>h.enabled!==!1);if(x)return{providerId:u.id,modelId:x.id}}return null},[o,a]);return e.jsxs("section",{"data-slot":"virtual-models",className:"space-y-2 rounded-lg border bg-card p-3",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium text-sm",children:t("Virtual models")}),e.jsx("p",{className:"mt-0.5 text-muted-foreground text-xs",children:t("A virtual model appears as one model in the picker and routes each request to a real model: fallbacks on rate limits or outages, image-capable or larger-context members when needed, and the fast model for summaries.")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:t("Applies to newly started conversations.")})]}),e.jsxs("div",{className:"space-y-2",children:[s.map(u=>e.jsx(lh,{entry:u,providers:o,classifierProviders:i},u.id)),e.jsxs(S,{type:"button",variant:"outline",size:"sm",className:"h-7 text-xs",disabled:!d,onClick:()=>{d&&n({name:"Auto",enabled:!0,primary:d,fallbacks:[]})},children:[e.jsx(Oe,{className:"mr-1 h-3.5 w-3.5"}),t("New virtual model")]}),!d&&e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Enable a model and configure valid provider credentials first.")})]})]})}function dh(){const{t}=z();return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:t("Bot mode")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("Settings shared by all members and group chats.")})]}),e.jsx(hh,{}),e.jsx(xh,{}),e.jsx(uh,{}),e.jsx(mh,{})]})}function uh(){const{t}=z(),s=v(r=>r.botModeEnabled),n=v(r=>r.botDiscussModeEnabled),a=v(r=>r.setBotDiscussModeEnabled);return s?e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"bots.discussMode",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("p",{className:"text-sm",children:t("Discussion mode")}),e.jsx(te,{variant:"warning",size:"sm","data-experimental-badge":"",children:t("Experimental feature")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Off: group chats work the same as the stable release. On: in smart-routing groups, discussion-style messages let the judge model pick who speaks next.")})]}),e.jsx(le,{checked:n,onCheckedChange:r=>a(r===!0)})]}):null}const Ba=Array.from({length:Yl-ha+1},(t,s)=>ha+s);function mh(){const{t}=z(),s=v(a=>a.botMaxRunningTurns),n=v(a=>a.setBotMaxRunningTurns);return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"bots.maxRunningTurns",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Bot concurrency limit")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Shared by private chats, group chats, delegations and routines. Lowering it never interrupts running work; raising it may hit model rate limits.")})]}),e.jsxs(ae,{items:Object.fromEntries(Ba.map(a=>[String(a),String(a)])),value:String(s),onValueChange:a=>n(Number(a)),children:[e.jsx(re,{className:"w-20",children:e.jsx(oe,{})}),e.jsx(ie,{children:Ba.map(a=>e.jsx(ee,{value:String(a),children:a},a))})]})]})}function hh(){const{t}=z(),s=v(i=>i.botAssistantModel),n=v(i=>i.setBotAssistantModel),a=Xe(),r=s?a.find(i=>i.id===s.providerId):void 0,o=r?.models.find(i=>i.id===s?.modelId);return e.jsxs("div",{className:"rounded-md border px-3 py-2.5","data-settings-row":"bots.assistantModel",children:[e.jsx("p",{className:"text-sm",children:t("Bot assistant model")}),e.jsx("p",{className:"mb-2 text-xs text-muted-foreground",children:t("Used for helper tasks such as auto-configuring member abilities.")}),e.jsx(ze,{providers:a,providerId:o?r?.id??"":"",modelId:o?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:t("Follows the default model"),side:"bottom",triggerClassName:Ye,onSelect:(i,d)=>n({providerId:i,modelId:d}),onReasoningChange:()=>{},onThinkingChange:()=>{}}),s&&!o&&e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:t("Selected model is unavailable — falls back to the default model.")}),s&&e.jsx(S,{variant:"ghost",size:"sm",className:"mt-1",onClick:()=>n(null),children:t("Follow default model")})]})}function xh(){const{t}=z(),s=v(d=>d.botRouteClassifier),n=v(d=>d.setBotRouteClassifier),a=v(d=>d.botDiscussModeEnabled),r=Xe(),o=m.useMemo(()=>r.filter(wo),[r]),i=_n();return e.jsxs("div",{className:"rounded-md border px-3 py-2.5","data-settings-row":"bots.routeClassifier",children:[e.jsx("p",{className:"text-sm",children:t("Group reply picker model")}),e.jsx("p",{className:"mb-2 text-xs text-muted-foreground",children:t("When nobody is @-mentioned in a smart-routing group, this model picks which member replies.")}),e.jsx(ui,{value:s??void 0,onChange:d=>n(d??null),providers:o,classifierProviders:i,offLabel:t("Default (title model)"),judgeLabel:t("Fast chat model"),description:t(a?"First pick: the group owner replies on timeout, error or an unclear answer. During a discussion, picking the next speaker ends the discussion in these cases.":"Falls back to the group owner on timeout, error or an unclear answer."),effectiveTimeoutMs:s?rh(s):void 0,timeoutHint:t(a?"First pick: handed to the group owner on timeout. Next speaker in a discussion: the discussion ends on timeout.":"Handed to the group owner on timeout.")})]})}const ph=()=>({name:"",title:"",scope:"",summary:"",persona:"",color:dn[0],tools:"all",approvalMode:"auto-edits"}),jn=(t,s)=>({key:t,name:"",title:"",scope:"",persona:"",color:dn[s%dn.length],tools:"all",approvalMode:"auto-edits",canDelegateTo:[],acceptFrom:[]}),fh=()=>({title:"",summary:"",bossKey:"m1",workspace:"chat-home",members:[jn("m1",0),jn("m2",1)]});function gh(t,s){const n=URL.createObjectURL(new Blob([JSON.stringify(s,null,2)],{type:"application/json"})),a=document.createElement("a");a.href=n,a.download=t,a.click(),URL.revokeObjectURL(n)}function jh(){const{t}=z(),s=Jl(!0),n=Ql(!0),[a,r]=m.useState(null),[o,i]=m.useState(null),d=m.useRef(null),u=async(p,g)=>{const w=await dc(k=>({...k,[p]:g(k[p])}));return w||Re({type:"error",title:t("Could not save templates")}),w},x=(p,g)=>u("members",w=>p?fa(w,p,g,xc):ga(w,g,crypto.randomUUID())),h=(p,g)=>u("teams",w=>p?fa(w,p,g,pc):ga(w,g,crypto.randomUUID())),l=async p=>{const g=sc(await p.text());if(!g.ok){Re({type:"error",title:xa(g.error,t)});return}const w=ko(nc(g.team));if(!w){Re({type:"error",title:xa("invalid",t)});return}await h(void 0,w)&&Re({type:"success",title:t("Imported as a custom team template")})},f=(p,g)=>u(p==="members"?"members":"teams",g),c=(p,g,w)=>e.jsxs(e.Fragment,{children:[e.jsx(mt,{label:t("Edit"),onClick:()=>w({id:g.id,data:g.data}),children:e.jsx(lt,{})}),e.jsx(mt,{label:t("Duplicate as custom"),onClick:()=>w({data:g.data}),children:e.jsx(No,{})}),g.source==="builtin"&&e.jsx(mt,{label:g.hidden?t("Show"):t("Hide"),onClick:()=>{f(p,k=>uc(k,g.id,!g.hidden))},children:g.hidden?e.jsx(ec,{}):e.jsx(tc,{})}),g.modified&&e.jsx(mt,{label:t("Restore default"),onClick:()=>{f(p,k=>ja(k,g.id))},children:e.jsx(Fn,{})}),g.source==="custom"&&e.jsx(mt,{label:t("Delete"),onClick:()=>{f(p,k=>ja(k,g.id))},children:e.jsx(Me,{})})]});return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:t("Bot templates")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("Templates used when creating members and teams. Built-in templates can be edited, hidden or restored.")})]}),e.jsxs(Ft,{defaultValue:"members",children:[e.jsxs(Ut,{variant:"underline",children:[e.jsx(Ke,{value:"members",children:t("Member templates")}),e.jsx(Ke,{value:"teams",children:t("Team templates")})]}),e.jsxs(Dt,{value:"members",className:"space-y-2 pt-3",children:[e.jsxs(S,{size:"sm",variant:"outline",onClick:()=>r({data:ph()}),children:[e.jsx(Oe,{}),t("New member template")]}),s.map(p=>e.jsx(_a,{item:p,avatar:e.jsx(cn,{bot:{name:p.data.name,avatar:{color:p.data.color}}}),title:p.data.name,subtitle:p.data.title,summary:p.data.summary,actions:c("members",p,r)},p.id))]}),e.jsxs(Dt,{value:"teams",className:"space-y-2 pt-3",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(S,{size:"sm",variant:"outline",onClick:()=>i({data:fh()}),children:[e.jsx(Oe,{}),t("New team template")]}),e.jsxs(S,{size:"sm",variant:"outline",onClick:()=>d.current?.click(),children:[e.jsx(Xl,{}),t("Import team (JSON)")]}),e.jsx("input",{ref:d,type:"file",accept:".json,application/json",hidden:!0,onChange:p=>{const g=p.target.files?.[0];p.target.value="",g&&l(g)}})]}),n.map(p=>e.jsx(_a,{item:p,avatar:e.jsx("div",{className:"-space-x-1.5 flex shrink-0",children:p.data.members.slice(0,4).map(g=>e.jsx(cn,{size:"sm",bot:{name:g.name,avatar:{color:g.color}}},g.key))}),title:p.data.title,subtitle:t("{{n}} members",{n:p.data.members.length}),summary:p.data.summary,actions:e.jsxs(e.Fragment,{children:[e.jsx(mt,{label:t("Export JSON"),onClick:()=>gh(`${p.data.title||"team"}.team.json`,{format:hc,version:mc,exportedAt:new Date().toISOString(),team:Zl(p.data)}),children:e.jsx(Sn,{})}),c("teams",p,i)]})},p.id))]})]}),a&&e.jsx(vh,{initial:a.data,onClose:()=>r(null),onSave:async p=>{await x(a.id,p)&&r(null)}}),o&&e.jsx(yh,{initial:o.data,onClose:()=>i(null),onSave:async p=>{await h(o.id,p)&&i(null)}})]})}function mt({label:t,onClick:s,disabled:n,children:a}){return e.jsx(S,{variant:"ghost",size:"icon-sm",title:t,"aria-label":t,disabled:n,onClick:s,children:a})}function _a({item:t,avatar:s,title:n,subtitle:a,summary:r,actions:o}){const{t:i}=z();return e.jsxs("div",{className:"flex items-center gap-3 rounded-md border px-3 py-2.5","data-template-id":t.id,children:[e.jsxs("div",{className:G("flex min-w-0 flex-1 items-center gap-3",t.hidden&&"opacity-50"),children:[s,e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("p",{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx("span",{className:"truncate",children:n}),e.jsx("span",{className:"truncate font-normal text-muted-foreground text-xs",children:a}),e.jsx(te,{variant:"secondary",children:t.source==="custom"?i("Custom"):i("Built-in")}),t.modified&&e.jsx(te,{variant:"outline",children:i("Modified")}),t.hidden&&e.jsx(te,{variant:"outline",children:i("Hidden")})]}),e.jsx("p",{className:"truncate text-muted-foreground text-xs",children:r})]})]}),e.jsx("div",{className:"flex shrink-0 items-center",children:o})]})}function mi({title:t,error:s,onClose:n,onSave:a,children:r}){const{t:o}=z(),[i,d]=m.useState(!1);return e.jsx(pe,{open:!0,onOpenChange:u=>!u&&n(),children:e.jsxs(fe,{className:"max-h-[85vh] max-w-2xl",children:[e.jsx(ge,{children:e.jsx(je,{children:t})}),e.jsxs(we,{className:"space-y-3",children:[r,s&&e.jsx("p",{className:"text-destructive text-xs",children:s})]}),e.jsxs(Ie,{children:[e.jsx(S,{variant:"outline",size:"sm",onClick:n,children:o("Cancel")}),e.jsx(S,{size:"sm",disabled:i||!!s,onClick:()=>{d(!0),a().finally(()=>d(!1))},children:o("Save")})]})]})})}function hi({value:t,onChange:s}){const{t:n}=z(),a=t.name?Co(t.name,[],n):null;return e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(Fe,{children:n("Name")}),e.jsx(J,{value:t.name,onChange:r=>s({name:r.target.value})}),a&&e.jsx("p",{className:"mt-1 text-destructive text-xs",children:a})]}),e.jsxs("div",{children:[e.jsx(Fe,{children:n("Title")}),e.jsx(J,{value:t.title,onChange:r=>s({title:r.target.value})})]}),e.jsxs("div",{children:[e.jsx(Fe,{children:n("Avatar color")}),e.jsx(lc,{value:t.color,onChange:r=>s({color:r})})]}),e.jsxs("div",{children:[e.jsx(Fe,{children:n("Tools")}),e.jsx(zn,{value:t.tools,options:[{value:"all",label:n("All tools")},{value:"readonly",label:n("Read-only")}],onChange:r=>s({tools:r})})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(Fe,{children:n("Approval mode")}),e.jsx(cc,{value:t.approvalMode,onChange:r=>s({approvalMode:r}),zIndex:st.DROPDOWN_IN_MODAL})]}),t.summary!==void 0&&e.jsxs("div",{className:"col-span-2",children:[e.jsx(Fe,{hint:n("Shown on the template card"),children:n("Summary")}),e.jsx(J,{value:t.summary,onChange:r=>s({summary:r.target.value})})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(Fe,{children:n("Responsibilities")}),e.jsx(J,{value:t.scope,onChange:r=>s({scope:r.target.value})})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(Fe,{children:n("Persona")}),e.jsx(He,{rows:6,value:t.persona,onChange:r=>s({persona:r.target.value})})]})]})}function vh({initial:t,onClose:s,onSave:n}){const{t:a}=z(),[r,o]=m.useState(t),i=ac(r);return e.jsx(mi,{title:a("Member template"),error:Co(r.name,[],a)??(i?null:a("Check the template fields")),onClose:s,onSave:()=>i?n(i):Promise.resolve(),children:e.jsx(hi,{value:r,onChange:d=>o(u=>({...u,...d}))})})}function bh(t,s){switch(t){case"title":return s("Enter a team title");case"members":return s("A team needs 2–12 members");case"name":return s("Every member needs a valid name");case"invalid":return s("Check the template fields");default:return null}}function yh({initial:t,onClose:s,onSave:n}){const{t:a}=z(),[r,o]=m.useState(t),[i,d]=m.useState(null),u=p=>r.members.find(g=>g.key===p)?.name||p,x=p=>o(g=>({...g,...p})),h=(p,g)=>o(w=>({...w,members:w.members.map(k=>k.key===p?{...k,...g}:k)})),l=()=>{const p=new Set(r.members.map(k=>k.key));let g=r.members.length+1;for(;p.has(`m${g}`);)g++;const w=`m${g}`;x({members:[...r.members,jn(w,r.members.length)]}),d(w)},f=p=>{const g=w=>w==="any"?"any":w.filter(k=>k!==p);x({members:r.members.filter(w=>w.key!==p).map(w=>({...w,canDelegateTo:g(w.canDelegateTo),acceptFrom:g(w.acceptFrom)}))})},c=ko(r);return e.jsxs(mi,{title:a("Team template"),error:bh(ic(r),a),onClose:s,onSave:()=>c?n(c):Promise.resolve(),children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(Fe,{children:a("Group name")}),e.jsx(J,{value:r.title,onChange:p=>x({title:p.target.value})})]}),e.jsxs("div",{children:[e.jsx(Fe,{children:a("Owner")}),e.jsxs(ae,{items:r.members.map(p=>({value:p.key,label:u(p.key)})),value:r.bossKey,onValueChange:p=>x({bossKey:p}),children:[e.jsx(re,{className:"w-full",children:e.jsx(oe,{})}),e.jsx(ie,{zIndex:st.DROPDOWN_IN_MODAL,children:r.members.map(p=>e.jsx(ee,{value:p.key,children:u(p.key)},p.key))})]})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(Fe,{hint:a("Shown on the template card"),children:a("Summary")}),e.jsx(J,{value:r.summary,onChange:p=>x({summary:p.target.value})})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(Fe,{children:a("Shared workspace")}),e.jsx(zn,{value:r.workspace,options:[{value:"chat-home",label:a("Standalone workspace")},{value:"project",label:a("Based on a Code project")}],onChange:p=>x({workspace:p})})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1.5 flex items-center justify-between",children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:a("Members")}),e.jsxs(S,{size:"xs",variant:"outline",disabled:r.members.length>=rc,onClick:l,children:[e.jsx(Oe,{}),a("Add member")]})]}),e.jsx("div",{className:"space-y-1.5",children:r.members.map(p=>{const g=i===p.key,w=p.key===r.bossKey,k=r.members.filter(j=>j.key!==p.key).map(j=>j.key);return e.jsxs("div",{className:"rounded-lg border","data-member-key":p.key,children:[e.jsxs("div",{className:"flex items-center gap-2 px-2.5 py-2",children:[e.jsxs("button",{type:"button",className:"flex min-w-0 flex-1 items-center gap-2 text-left",onClick:()=>d(g?null:p.key),children:[g?e.jsx(ns,{className:"h-3.5 w-3.5 shrink-0"}):e.jsx(Mt,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx(cn,{bot:{name:p.name,avatar:{color:p.color}},size:"sm"}),e.jsx("span",{className:"truncate text-sm",children:p.name||a("Unnamed")}),e.jsx("span",{className:"truncate text-muted-foreground text-xs",children:p.title}),w&&e.jsxs("span",{className:"flex shrink-0 items-center gap-0.5 rounded bg-muted px-1.5 text-[10px] text-muted-foreground",children:[e.jsx(oc,{className:"h-3 w-3"}),a("Owner")]})]}),e.jsx(mt,{label:a("Remove"),disabled:w||r.members.length<=2,onClick:()=>f(p.key),children:e.jsx(Me,{})})]}),g&&e.jsxs("div",{className:"space-y-3 border-t p-2.5",children:[e.jsx(hi,{value:p,onChange:j=>h(p.key,j)}),e.jsx(pa,{label:a("Can delegate to"),value:p.canDelegateTo,options:k,nameOf:u,onChange:j=>h(p.key,{canDelegateTo:j})}),e.jsx(pa,{label:a("Accepts delegation from"),value:p.acceptFrom,options:k,nameOf:u,onChange:j=>h(p.key,{acceptFrom:j})})]})]},p.key)})})]})]})}function xi(t){return t.capturePermission==="unsupported"&&t.axPermission==="unsupported"?"unsupported":t.capturePermission==="granted"&&(t.axPermission==="granted"||t.axPermission==="unsupported")?"ready":"needs-permission"}const wh=[{id:"collaboration",label:"Collaboration & planning"},{id:"web",label:"Web"},{id:"execution",label:"Execution"},{id:"context",label:"Context & memory"},{id:"safety",label:"Safety"}],Fa={subagent:"collaboration",workflow:"collaboration",todo:"collaboration",plan:"collaboration",ask_user:"collaboration",browser:"web",web:"web",background_tasks:"execution",isolated_sandbox:"execution",computer:"execution",image_generation:"execution",memory:"context",turn_discard:"context"};function Nh(t,s){return t.filter(n=>Object.hasOwn(Fa,n.id)?Fa[n.id]===s:!1)}function Ua(t){return t.bundleId||t.path}function kh(){const{t}=z(),[s,n]=m.useState(null),a=v(i=>i.computerAllowAllApps),r=v(i=>i.setComputerAllowAllApps);m.useEffect(()=>{let i=!1;return window.electronAPI.computer.allowedApps().then(d=>{i||n(d)}),()=>{i=!0}},[]);const o=async i=>{await window.electronAPI.computer.revokeApp(Ua(i)),n(await window.electronAPI.computer.allowedApps())};return e.jsxs("div",{className:"space-y-2","data-settings-row":"tools.computerApps",children:[e.jsx("p",{className:"font-medium text-sm",children:t("Apps the AI may control")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("The first time the AI clicks or types in an app, EnsoCode asks you. Apps you always allow are listed here; it can then read everything in their windows.")}),e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium text-sm",children:t("Allow all apps")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("The AI can click, type and read in any app without asking. It can see everything in their windows, including chats and passwords.")})]}),e.jsx(le,{checked:a,onCheckedChange:r})]}),s&&s.length===0?e.jsx("p",{className:"text-muted-foreground text-xs",children:t("No apps are always allowed yet.")}):null,s&&s.length>0?e.jsx("ul",{className:"divide-y rounded-md border",children:s.map(i=>e.jsxs("li",{className:"flex items-center justify-between gap-3 px-3 py-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-sm",children:i.name}),e.jsx("p",{className:"truncate text-muted-foreground text-xs",title:i.path,children:i.bundleId||i.path})]}),e.jsx(S,{variant:"outline",size:"sm",onClick:()=>{o(i)},children:t("Revoke")})]},Ua(i)))}):null]})}function Ch(t){return Object.fromEntries(t.map(s=>[s.id,s]))}function ds(t,s){return t.reduce((n,a)=>{const r=s[a]?.tokens;return r==null?n:n+r},0)}function us({row:t,pending:s}){const{t:n}=z(),a=s?"…":t?.tokens==null?"—":$e(t.tokens);return e.jsx("span",{className:"w-12 shrink-0 text-right text-muted-foreground text-xs tabular-nums",title:t?.error||n("Estimate"),children:a})}function ms({tokens:t}){return t<=0?null:e.jsx("span",{className:"ml-2 font-normal text-muted-foreground text-xs tabular-nums",children:$e(t)})}function hs(t,s){const[n,a]=m.useState({}),[r,o]=m.useState(()=>t.length>0),i=t.join("\0"),d=m.useRef(s);return d.current=s,m.useEffect(()=>{let u=!1;const x=i.length===0?[]:i.split("\0");if(x.length===0){a({}),o(!1);return}return o(!0),d.current(x).then(h=>{u||a(Ch(h))}).finally(()=>{u||o(!1)}),()=>{u=!0}},[i]),{rows:n,pending:r}}const $a={replace:"Text replacement",apply_patch:"Apply patch (default)"},Sh={subagent:Nc,workflow:Un,todo:wc,plan:yc,ask_user:bc,browser:vc,web:Io,background_tasks:jc,memory:So,isolated_sandbox:yu,computer:Ln,turn_discard:gc};function kt({icon:t,title:s,description:n,control:a,children:r,rowId:o,newSession:i}){return e.jsxs("div",{className:"rounded-md border px-3 py-2.5","data-settings-row":o,children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(t,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("p",{className:"text-sm font-medium",children:[s,i&&e.jsx(qe,{note:typeof i=="string"?i:void 0})]}),e.jsx("p",{className:"text-muted-foreground text-xs",children:n})]}),a]}),r?e.jsx("div",{className:"mt-2 space-y-2 pl-7",children:r}):null]})}function Ih({disabled:t}){const{t:s}=z(),n=v(l=>l.webSearchChain),a=v(l=>l.setWebSearchChain),r=$t(),o=m.useMemo(()=>Sc(r),[r]),[i,d]=m.useState(null),u=(l,f)=>{a(n.map((c,p)=>p===l?{...c,...f}:c))},x=l=>a(n.filter((f,c)=>c!==l)),h=(l,f)=>{if(l===f)return;const c=[...n],[p]=c.splice(l,1);p&&(c.splice(f,0,p),a(c))};return e.jsxs("div",{className:"space-y-2","data-settings-row":"tools.webSearchChain",children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Try these models' built-in search in order. Credentials resolve at call time; if all fail, the keyless Exa service is the permanent fallback.")}),n.length===0&&e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Default: use the current session model's built-in search when available, otherwise Exa.")}),n.map((l,f)=>e.jsxs("div",{className:"flex items-center gap-2 rounded-md border px-2 py-1.5",draggable:!t,onDragStart:c=>{c.dataTransfer.effectAllowed="move",d(f)},onDragEnd:()=>d(null),onDragOver:c=>{i!==null&&i!==f&&c.preventDefault()},onDrop:c=>{c.preventDefault(),i!==null&&h(i,f),d(null)},children:[e.jsx(Ic,{className:"h-3.5 w-3.5 shrink-0 cursor-grab text-muted-foreground"}),e.jsx("span",{className:"w-4 shrink-0 text-center text-muted-foreground text-xs",children:f+1}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx(ze,{providers:o,providerId:l.providerId,modelId:l.modelId,reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,onSelect:(c,p)=>u(f,{providerId:c,modelId:p}),onReasoningChange:()=>{},onThinkingChange:()=>{}})}),e.jsx(S,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 shrink-0 p-0",disabled:t,onClick:()=>x(f),"aria-label":s("Remove"),children:e.jsx(Me,{className:"h-3.5 w-3.5"})})]},`${l.providerId}/${l.modelId}`)),n.length<Ac&&e.jsx("div",{className:"max-w-xs",children:e.jsx(ze,{providers:o,providerId:"",modelId:"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,triggerLabel:`+ ${s("Add candidate")}`,onSelect:(l,f)=>a([...n,{providerId:l,modelId:f}]),onReasoningChange:()=>{},onThinkingChange:()=>{}})}),e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Final fallback: Exa (keyless hosted search). Not a chain entry; always last.")})]})}function Ah(){const{t}=z(),s=v(b=>b.disabledBuiltinTools),n=v(b=>b.toggleBuiltinTool),a=v(b=>b.subagentAllowedModes),r=v(b=>b.setSubagentAllowedModes),o=v(b=>b.exploreFoldEnabled),i=v(b=>b.setExploreFoldEnabled),d=v(b=>b.rtkEnabled),u=v(b=>b.computerPreview),x=v(b=>b.setComputerPreview),h=v(b=>b.openLinksInBuiltinBrowser),l=v(b=>b.setOpenLinksInBuiltinBrowser),f=v(b=>b.setRtkEnabled),c=v(b=>b.protectedActionsInCode),p=v(b=>b.setProtectedActionsInCode),g=v(b=>b.editMode),w=v(b=>b.setEditMode),k=hs(bs.map(b=>b.id),()=>window.electronAPI.assets.builtinToolOccupancy()),j=ds(bs.filter(b=>!s.includes(b.id)).map(b=>b.id),k.rows),[y,N]=m.useState(null),A=!s.includes("subagent"),O=(b,_)=>{r(_?[...new Set([...a,b])]:a.filter(K=>K!==b))},I=async b=>{await window.electronAPI.browser.clearData(b),N(b),setTimeout(()=>N(null),2e3)},L=!s.includes("computer"),[C,E]=m.useState(null),[M,V]=m.useState(!1);m.useEffect(()=>{if(!L){E(null);return}let b=!1;return window.electronAPI.computer.capabilities().then(_=>{!b&&_.ok&&E(_.capabilities)}),()=>{b=!0}},[L]),m.useEffect(()=>{if(!M)return;let b=!1;const _=()=>{window.electronAPI.computer.capabilities().then(D=>{!b&&D.ok&&E(D.capabilities)})};_();const K=window.setInterval(_,2e3);return()=>{b=!0,window.clearInterval(K)}},[M]);const F={collaboration:null,web:null,execution:e.jsx(kt,{rowId:"tools.editMode",newSession:!0,icon:Iu,title:t("File edit mode"),description:t("Choose how files are modified. Apply patch is the default. New and cold-restored sessions use this mode; already warm sessions keep their current mode."),control:e.jsxs(ae,{items:Object.fromEntries(va.map(b=>[b,t($a[b])])),value:g,onValueChange:b=>{fc(b)&&w(b)},children:[e.jsx(re,{className:"w-44 shrink-0","aria-label":t("File edit mode"),children:e.jsx(oe,{})}),e.jsx(ie,{children:va.map(b=>e.jsx(ee,{value:b,children:t($a[b])},b))})]})}),context:e.jsxs(e.Fragment,{children:[e.jsx(kt,{icon:Pu,newSession:!0,title:t("Explore fold"),description:t("Let the agent mark exploratory reads and keep only a short report in later model context. Timeline stays intact."),control:e.jsx(le,{checked:o,onCheckedChange:i})}),e.jsx(kt,{rowId:"tools.rtkEnabled",newSession:!0,icon:Fu,title:t("RTK command compression"),description:t("Compress supported command output before it enters the model context. Takes effect on new conversations."),control:e.jsx(le,{checked:d,onCheckedChange:f})})]}),safety:e.jsxs(e.Fragment,{children:[e.jsx(kt,{icon:In,newSession:!0,title:t("Protected action confirmation"),description:t("Even in full-access mode, ask before external sends, deletions, payments, deployments and secret-file access. Always on for Bot members not set to Full access. Takes effect on new conversations."),control:e.jsx(le,{checked:c,onCheckedChange:p})}),e.jsx(Eh,{})]})};return e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{"data-settings-row":"tools.root",children:[e.jsxs("h3",{className:"font-medium text-lg",children:[t("Built-in tools"),e.jsx(ms,{tokens:j})]}),e.jsx("p",{className:"text-muted-foreground text-sm",children:t("Toggle the built-in tools available to agents.")})]}),wh.map(b=>e.jsxs("section",{className:"space-y-3",children:[e.jsx("h4",{className:"border-b pb-2 text-base font-semibold",children:t(b.label)}),Nh(bs,b.id).map(_=>e.jsxs(kt,{icon:Sh[_.id]??Ao,title:t(_.name),description:t(_.description),newSession:_.id==="isolated_sandbox"?t("Isolated sandbox switches between script and tool-search mode, so open sessions keep the mode they started with."):void 0,control:e.jsxs(e.Fragment,{children:[e.jsx(us,{row:k.rows[_.id],pending:k.pending&&!k.rows[_.id]}),e.jsx(le,{checked:!s.includes(_.id),onCheckedChange:K=>{n(_.id,K),_.id==="computer"&&K&&V(!0)}})]}),children:[_.id==="web"?e.jsx(Ih,{disabled:s.includes("web")}):null,_.id==="subagent"?e.jsxs("div",{className:"space-y-2","data-settings-row":"tools.subagentModes",children:[[["task","One-shot task agents"],["coworker","Persistent coworkers"]].map(([K,D])=>e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("span",{className:"text-sm",children:t(D)}),e.jsx(le,{checked:a.includes(K),disabled:!A,onCheckedChange:$=>O(K,$)})]},K)),!A&&e.jsx("p",{className:"text-muted-foreground text-xs",children:t("The unified subagent tool is off. Re-enabling it keeps this mode selection.")})]}):null,_.id==="computer"&&L?e.jsx("div",{className:"space-y-2","data-settings-row":"tools.computer",children:C&&xi(C)==="unsupported"?e.jsx("p",{className:"text-muted-foreground text-xs",children:t("This platform cannot operate the desktop yet.")}):e.jsxs(e.Fragment,{children:[C?.platform==="darwin"&&e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Computer needs Screen Recording to capture windows and Accessibility to inspect or click them. Grant both to EnsoCode, then restart the app.")}),C&&e.jsxs("p",{className:"text-muted-foreground text-xs",children:[t(C.capturePermission==="granted"?"Capture: granted":"Capture: denied"),C.axPermission!=="unsupported"&&e.jsxs(e.Fragment,{children:[" · ",t(C.axPermission==="granted"?"Input/AX: granted":"Input/AX: denied")]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(S,{variant:"outline",size:"sm",onClick:()=>V(!0),children:t("Show permission guide")}),C?.platform==="darwin"&&e.jsxs(e.Fragment,{children:[e.jsx(S,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.computer.openPermissions("screen")},children:t("Open Screen Recording settings")}),e.jsx(S,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.computer.openPermissions("accessibility")},children:t("Open Accessibility settings")})]})]}),C?.platform==="darwin"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium text-sm",children:t("Show the app being operated")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("While the AI works in an app in the background, a small floating window shows that app live. Close it any time.")})]}),e.jsx(le,{checked:u,onCheckedChange:x})]}),e.jsx(kh,{})]})]})}):null,_.id==="browser"?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium text-sm",children:t("Open chat links in the built-in browser")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Clicking a web link in chat opens it in the side panel browser. {{key}}+Click opens it in the external browser.",{key:kc?"Cmd":"Ctrl"})})]}),e.jsx(le,{checked:h,onCheckedChange:l})]}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Cookies and site storage of the built-in browser, separate from the app itself.")}),e.jsx("div",{className:"flex flex-wrap gap-2",children:["cookies","cache","all"].map(K=>e.jsx(S,{variant:"outline",size:"sm",onClick:()=>{I(K)},children:t(y===K?"Cleared":K==="cookies"?"Clear cookies":K==="cache"?"Clear cache":"Clear all browsing data")},K))})]}):null]},_.id)),F[b.id]]},b.id)),e.jsx(Mh,{open:M,capabilities:C,onOpenChange:V})]})}function Eh(){const{t}=z(),s=v(c=>c.dcgEnabled),n=v(c=>c.setDcgEnabled),[a,r]=m.useState(null),[o,i]=m.useState(!1),[d,u]=m.useState(null),[x,h]=m.useState(!1);m.useEffect(()=>{let c=!1;return window.electronAPI.dcg.status().then(p=>{c||r(p)}),()=>{c=!0}},[]);const l=async c=>{h(!1),i(!0),u(null);const p=await window.electronAPI.dcg[c]();r(p.status),p.ok?n(c==="install"):u(p.error??t("Operation failed")),i(!1)},f=a?.installed===!0;return e.jsxs(kt,{rowId:"tools.dcgEnabled",newSession:!0,icon:Cc,title:t("Destructive command guard (dcg)"),description:t("Check bash and PowerShell commands with dcg before running. Matches such as git reset --hard or recursive deletes always require your confirmation, even in full-access mode. Takes effect on new conversations."),control:e.jsx(le,{checked:s&&f,disabled:!f,onCheckedChange:n}),children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("span",{className:"text-muted-foreground",children:a?a.supported?f?t("Installed v{{version}}",{version:a.version}):t("Not installed"):t("Not available on this platform"):t("Loading…")}),a?.supported&&(f?e.jsx(S,{variant:"outline",size:"xs",disabled:o,onClick:()=>{l("uninstall")},children:t("Uninstall")}):e.jsx(S,{variant:"outline",size:"xs",disabled:o,onClick:()=>h(!0),children:t(o?"Installing…":"Install")}))]}),d&&e.jsx("p",{className:"text-destructive text-xs",children:d}),e.jsx(pe,{open:x,onOpenChange:h,children:e.jsxs(fe,{className:"max-w-md",zIndexLevel:"nested",children:[e.jsxs(ge,{children:[e.jsx(je,{children:t("Install dcg")}),e.jsx(Ve,{children:t("Downloads dcg v{{version}} from its GitHub release and verifies the checksum. dcg is a third-party tool, not part of EnsoCode.",{version:a?.version??""})})]}),e.jsx(we,{children:e.jsxs("div",{className:"flex gap-2 rounded-md border border-destructive/32 bg-destructive/8 p-3 text-sm",children:[e.jsx(Ue,{className:"mt-0.5 h-4 w-4 shrink-0 text-destructive"}),e.jsx("p",{children:t("dcg is licensed under MIT with an additional rider: no rights are granted to OpenAI, Anthropic, their affiliates, or anyone acting on their behalf. Install only if this restriction does not apply to you.")})]})}),e.jsxs(Ie,{children:[e.jsx(S,{variant:"outline",size:"sm",onClick:()=>h(!1),children:t("Cancel")}),e.jsx(S,{size:"sm",onClick:()=>{l("install")},children:t("Agree and install")})]})]})})]})}function Mh({open:t,capabilities:s,onOpenChange:n}){const{t:a}=z(),r=s?xi(s):null;return e.jsx(pe,{open:t,onOpenChange:n,children:e.jsxs(fe,{className:"max-w-md",zIndexLevel:"nested",children:[e.jsxs(ge,{children:[e.jsx(je,{children:a("Grant Computer permissions")}),e.jsx(Ve,{children:a(r==="unsupported"?"This platform cannot operate the desktop yet.":r==="ready"?"Computer is ready. Open sessions can use it from their next step.":"The agent can screenshot windows and control the mouse and keyboard. Grant Screen Recording and Accessibility to EnsoCode, then restart.")})]}),e.jsxs(we,{className:"space-y-3",children:[!s&&e.jsx("p",{className:"text-muted-foreground text-sm",children:a("Loading…")}),r==="needs-permission"&&e.jsxs("div",{className:"flex gap-2 rounded-md border border-destructive/32 bg-destructive/8 p-3 text-sm",children:[e.jsx(Ue,{className:"mt-0.5 h-4 w-4 shrink-0 text-destructive"}),e.jsx("p",{children:a("Computer needs Screen Recording to capture windows and Accessibility to inspect or click them. Grant both to EnsoCode, then restart the app.")})]}),s?.platform==="darwin"&&r!=="unsupported"&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("p",{className:"text-muted-foreground text-xs",children:[a(s.capturePermission==="granted"?"Capture: granted":"Capture: denied")," · ",a(s.axPermission==="granted"?"Input/AX: granted":"Input/AX: denied"),s.detail?` · ${s.detail}`:""]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(S,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.computer.openPermissions("screen")},children:a("Open Screen Recording settings")}),e.jsx(S,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.computer.openPermissions("accessibility")},children:a("Open Accessibility settings")})]})]})]}),e.jsx(Ie,{className:"sm:justify-end",children:e.jsx(S,{size:"sm",onClick:()=>n(!1),children:a("Done")})})]})})}var bt={},Ns,Va;function Ph(){return Va||(Va=1,Ns=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then}),Ns}var ks={},rt={},Ka;function xt(){if(Ka)return rt;Ka=1;let t;const s=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706];return rt.getSymbolSize=function(a){if(!a)throw new Error('"version" cannot be null or undefined');if(a<1||a>40)throw new Error('"version" should be in range from 1 to 40');return a*4+17},rt.getSymbolTotalCodewords=function(a){return s[a]},rt.getBCHDigit=function(n){let a=0;for(;n!==0;)a++,n>>>=1;return a},rt.setToSJISFunction=function(a){if(typeof a!="function")throw new Error('"toSJISFunc" is not a valid function.');t=a},rt.isKanjiModeEnabled=function(){return typeof t<"u"},rt.toSJIS=function(a){return t(a)},rt}var Cs={},qa;function Hn(){return qa||(qa=1,(function(t){t.L={bit:1},t.M={bit:0},t.Q={bit:3},t.H={bit:2};function s(n){if(typeof n!="string")throw new Error("Param is not a string");switch(n.toLowerCase()){case"l":case"low":return t.L;case"m":case"medium":return t.M;case"q":case"quartile":return t.Q;case"h":case"high":return t.H;default:throw new Error("Unknown EC Level: "+n)}}t.isValid=function(a){return a&&typeof a.bit<"u"&&a.bit>=0&&a.bit<4},t.from=function(a,r){if(t.isValid(a))return a;try{return s(a)}catch{return r}}})(Cs)),Cs}var Ss,Ga;function Th(){if(Ga)return Ss;Ga=1;function t(){this.buffer=[],this.length=0}return t.prototype={get:function(s){const n=Math.floor(s/8);return(this.buffer[n]>>>7-s%8&1)===1},put:function(s,n){for(let a=0;a<n;a++)this.putBit((s>>>n-a-1&1)===1)},getLengthInBits:function(){return this.length},putBit:function(s){const n=Math.floor(this.length/8);this.buffer.length<=n&&this.buffer.push(0),s&&(this.buffer[n]|=128>>>this.length%8),this.length++}},Ss=t,Ss}var Is,Ha;function Rh(){if(Ha)return Is;Ha=1;function t(s){if(!s||s<1)throw new Error("BitMatrix size must be defined and greater than 0");this.size=s,this.data=new Uint8Array(s*s),this.reservedBit=new Uint8Array(s*s)}return t.prototype.set=function(s,n,a,r){const o=s*this.size+n;this.data[o]=a,r&&(this.reservedBit[o]=!0)},t.prototype.get=function(s,n){return this.data[s*this.size+n]},t.prototype.xor=function(s,n,a){this.data[s*this.size+n]^=a},t.prototype.isReserved=function(s,n){return this.reservedBit[s*this.size+n]},Is=t,Is}var As={},Wa;function Oh(){return Wa||(Wa=1,(function(t){const s=xt().getSymbolSize;t.getRowColCoords=function(a){if(a===1)return[];const r=Math.floor(a/7)+2,o=s(a),i=o===145?26:Math.ceil((o-13)/(2*r-2))*2,d=[o-7];for(let u=1;u<r-1;u++)d[u]=d[u-1]-i;return d.push(6),d.reverse()},t.getPositions=function(a){const r=[],o=t.getRowColCoords(a),i=o.length;for(let d=0;d<i;d++)for(let u=0;u<i;u++)d===0&&u===0||d===0&&u===i-1||d===i-1&&u===0||r.push([o[d],o[u]]);return r}})(As)),As}var Es={},Ya;function Dh(){if(Ya)return Es;Ya=1;const t=xt().getSymbolSize,s=7;return Es.getPositions=function(a){const r=t(a);return[[0,0],[r-s,0],[0,r-s]]},Es}var Ms={},Ja;function Lh(){return Ja||(Ja=1,(function(t){t.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};const s={N1:3,N2:3,N3:40,N4:10};t.isValid=function(r){return r!=null&&r!==""&&!isNaN(r)&&r>=0&&r<=7},t.from=function(r){return t.isValid(r)?parseInt(r,10):void 0},t.getPenaltyN1=function(r){const o=r.size;let i=0,d=0,u=0,x=null,h=null;for(let l=0;l<o;l++){d=u=0,x=h=null;for(let f=0;f<o;f++){let c=r.get(l,f);c===x?d++:(d>=5&&(i+=s.N1+(d-5)),x=c,d=1),c=r.get(f,l),c===h?u++:(u>=5&&(i+=s.N1+(u-5)),h=c,u=1)}d>=5&&(i+=s.N1+(d-5)),u>=5&&(i+=s.N1+(u-5))}return i},t.getPenaltyN2=function(r){const o=r.size;let i=0;for(let d=0;d<o-1;d++)for(let u=0;u<o-1;u++){const x=r.get(d,u)+r.get(d,u+1)+r.get(d+1,u)+r.get(d+1,u+1);(x===4||x===0)&&i++}return i*s.N2},t.getPenaltyN3=function(r){const o=r.size;let i=0,d=0,u=0;for(let x=0;x<o;x++){d=u=0;for(let h=0;h<o;h++)d=d<<1&2047|r.get(x,h),h>=10&&(d===1488||d===93)&&i++,u=u<<1&2047|r.get(h,x),h>=10&&(u===1488||u===93)&&i++}return i*s.N3},t.getPenaltyN4=function(r){let o=0;const i=r.data.length;for(let u=0;u<i;u++)o+=r.data[u];return Math.abs(Math.ceil(o*100/i/5)-10)*s.N4};function n(a,r,o){switch(a){case t.Patterns.PATTERN000:return(r+o)%2===0;case t.Patterns.PATTERN001:return r%2===0;case t.Patterns.PATTERN010:return o%3===0;case t.Patterns.PATTERN011:return(r+o)%3===0;case t.Patterns.PATTERN100:return(Math.floor(r/2)+Math.floor(o/3))%2===0;case t.Patterns.PATTERN101:return r*o%2+r*o%3===0;case t.Patterns.PATTERN110:return(r*o%2+r*o%3)%2===0;case t.Patterns.PATTERN111:return(r*o%3+(r+o)%2)%2===0;default:throw new Error("bad maskPattern:"+a)}}t.applyMask=function(r,o){const i=o.size;for(let d=0;d<i;d++)for(let u=0;u<i;u++)o.isReserved(u,d)||o.xor(u,d,n(r,u,d))},t.getBestMask=function(r,o){const i=Object.keys(t.Patterns).length;let d=0,u=1/0;for(let x=0;x<i;x++){o(x),t.applyMask(x,r);const h=t.getPenaltyN1(r)+t.getPenaltyN2(r)+t.getPenaltyN3(r)+t.getPenaltyN4(r);t.applyMask(x,r),h<u&&(u=h,d=x)}return d}})(Ms)),Ms}var Jt={},Qa;function pi(){if(Qa)return Jt;Qa=1;const t=Hn(),s=[1,1,1,1,1,1,1,1,1,1,2,2,1,2,2,4,1,2,4,4,2,4,4,4,2,4,6,5,2,4,6,6,2,5,8,8,4,5,8,8,4,5,8,11,4,8,10,11,4,9,12,16,4,9,16,16,6,10,12,18,6,10,17,16,6,11,16,19,6,13,18,21,7,14,21,25,8,16,20,25,8,17,23,25,9,17,23,34,9,18,25,30,10,20,27,32,12,21,29,35,12,23,34,37,12,25,34,40,13,26,35,42,14,28,38,45,15,29,40,48,16,31,43,51,17,33,45,54,18,35,48,57,19,37,51,60,19,38,53,63,20,40,56,66,21,43,59,70,22,45,62,74,24,47,65,77,25,49,68,81],n=[7,10,13,17,10,16,22,28,15,26,36,44,20,36,52,64,26,48,72,88,36,64,96,112,40,72,108,130,48,88,132,156,60,110,160,192,72,130,192,224,80,150,224,264,96,176,260,308,104,198,288,352,120,216,320,384,132,240,360,432,144,280,408,480,168,308,448,532,180,338,504,588,196,364,546,650,224,416,600,700,224,442,644,750,252,476,690,816,270,504,750,900,300,560,810,960,312,588,870,1050,336,644,952,1110,360,700,1020,1200,390,728,1050,1260,420,784,1140,1350,450,812,1200,1440,480,868,1290,1530,510,924,1350,1620,540,980,1440,1710,570,1036,1530,1800,570,1064,1590,1890,600,1120,1680,1980,630,1204,1770,2100,660,1260,1860,2220,720,1316,1950,2310,750,1372,2040,2430];return Jt.getBlocksCount=function(r,o){switch(o){case t.L:return s[(r-1)*4+0];case t.M:return s[(r-1)*4+1];case t.Q:return s[(r-1)*4+2];case t.H:return s[(r-1)*4+3];default:return}},Jt.getTotalCodewordsCount=function(r,o){switch(o){case t.L:return n[(r-1)*4+0];case t.M:return n[(r-1)*4+1];case t.Q:return n[(r-1)*4+2];case t.H:return n[(r-1)*4+3];default:return}},Jt}var Ps={},Tt={},Xa;function zh(){if(Xa)return Tt;Xa=1;const t=new Uint8Array(512),s=new Uint8Array(256);return(function(){let a=1;for(let r=0;r<255;r++)t[r]=a,s[a]=r,a<<=1,a&256&&(a^=285);for(let r=255;r<512;r++)t[r]=t[r-255]})(),Tt.log=function(a){if(a<1)throw new Error("log("+a+")");return s[a]},Tt.exp=function(a){return t[a]},Tt.mul=function(a,r){return a===0||r===0?0:t[s[a]+s[r]]},Tt}var Za;function Bh(){return Za||(Za=1,(function(t){const s=zh();t.mul=function(a,r){const o=new Uint8Array(a.length+r.length-1);for(let i=0;i<a.length;i++)for(let d=0;d<r.length;d++)o[i+d]^=s.mul(a[i],r[d]);return o},t.mod=function(a,r){let o=new Uint8Array(a);for(;o.length-r.length>=0;){const i=o[0];for(let u=0;u<r.length;u++)o[u]^=s.mul(r[u],i);let d=0;for(;d<o.length&&o[d]===0;)d++;o=o.slice(d)}return o},t.generateECPolynomial=function(a){let r=new Uint8Array([1]);for(let o=0;o<a;o++)r=t.mul(r,new Uint8Array([1,s.exp(o)]));return r}})(Ps)),Ps}var Ts,er;function _h(){if(er)return Ts;er=1;const t=Bh();function s(n){this.genPoly=void 0,this.degree=n,this.degree&&this.initialize(this.degree)}return s.prototype.initialize=function(a){this.degree=a,this.genPoly=t.generateECPolynomial(this.degree)},s.prototype.encode=function(a){if(!this.genPoly)throw new Error("Encoder not initialized");const r=new Uint8Array(a.length+this.degree);r.set(a);const o=t.mod(r,this.genPoly),i=this.degree-o.length;if(i>0){const d=new Uint8Array(this.degree);return d.set(o,i),d}return o},Ts=s,Ts}var Rs={},Os={},Ds={},tr;function fi(){return tr||(tr=1,Ds.isValid=function(s){return!isNaN(s)&&s>=1&&s<=40}),Ds}var Ge={},sr;function gi(){if(sr)return Ge;sr=1;const t="[0-9]+",s="[A-Z $%*+\\-./:]+";let n="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";n=n.replace(/u/g,"\\u");const a="(?:(?![A-Z0-9 $%*+\\-./:]|"+n+`)(?:.|[\r
11
- ]))+`;Ge.KANJI=new RegExp(n,"g"),Ge.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g"),Ge.BYTE=new RegExp(a,"g"),Ge.NUMERIC=new RegExp(t,"g"),Ge.ALPHANUMERIC=new RegExp(s,"g");const r=new RegExp("^"+n+"$"),o=new RegExp("^"+t+"$"),i=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");return Ge.testKanji=function(u){return r.test(u)},Ge.testNumeric=function(u){return o.test(u)},Ge.testAlphanumeric=function(u){return i.test(u)},Ge}var nr;function pt(){return nr||(nr=1,(function(t){const s=fi(),n=gi();t.NUMERIC={id:"Numeric",bit:1,ccBits:[10,12,14]},t.ALPHANUMERIC={id:"Alphanumeric",bit:2,ccBits:[9,11,13]},t.BYTE={id:"Byte",bit:4,ccBits:[8,16,16]},t.KANJI={id:"Kanji",bit:8,ccBits:[8,10,12]},t.MIXED={bit:-1},t.getCharCountIndicator=function(o,i){if(!o.ccBits)throw new Error("Invalid mode: "+o);if(!s.isValid(i))throw new Error("Invalid version: "+i);return i>=1&&i<10?o.ccBits[0]:i<27?o.ccBits[1]:o.ccBits[2]},t.getBestModeForData=function(o){return n.testNumeric(o)?t.NUMERIC:n.testAlphanumeric(o)?t.ALPHANUMERIC:n.testKanji(o)?t.KANJI:t.BYTE},t.toString=function(o){if(o&&o.id)return o.id;throw new Error("Invalid mode")},t.isValid=function(o){return o&&o.bit&&o.ccBits};function a(r){if(typeof r!="string")throw new Error("Param is not a string");switch(r.toLowerCase()){case"numeric":return t.NUMERIC;case"alphanumeric":return t.ALPHANUMERIC;case"kanji":return t.KANJI;case"byte":return t.BYTE;default:throw new Error("Unknown mode: "+r)}}t.from=function(o,i){if(t.isValid(o))return o;try{return a(o)}catch{return i}}})(Os)),Os}var ar;function Fh(){return ar||(ar=1,(function(t){const s=xt(),n=pi(),a=Hn(),r=pt(),o=fi(),i=7973,d=s.getBCHDigit(i);function u(f,c,p){for(let g=1;g<=40;g++)if(c<=t.getCapacity(g,p,f))return g}function x(f,c){return r.getCharCountIndicator(f,c)+4}function h(f,c){let p=0;return f.forEach(function(g){const w=x(g.mode,c);p+=w+g.getBitsLength()}),p}function l(f,c){for(let p=1;p<=40;p++)if(h(f,p)<=t.getCapacity(p,c,r.MIXED))return p}t.from=function(c,p){return o.isValid(c)?parseInt(c,10):p},t.getCapacity=function(c,p,g){if(!o.isValid(c))throw new Error("Invalid QR Code version");typeof g>"u"&&(g=r.BYTE);const w=s.getSymbolTotalCodewords(c),k=n.getTotalCodewordsCount(c,p),j=(w-k)*8;if(g===r.MIXED)return j;const y=j-x(g,c);switch(g){case r.NUMERIC:return Math.floor(y/10*3);case r.ALPHANUMERIC:return Math.floor(y/11*2);case r.KANJI:return Math.floor(y/13);case r.BYTE:default:return Math.floor(y/8)}},t.getBestVersionForData=function(c,p){let g;const w=a.from(p,a.M);if(Array.isArray(c)){if(c.length>1)return l(c,w);if(c.length===0)return 1;g=c[0]}else g=c;return u(g.mode,g.getLength(),w)},t.getEncodedBits=function(c){if(!o.isValid(c)||c<7)throw new Error("Invalid QR Code version");let p=c<<12;for(;s.getBCHDigit(p)-d>=0;)p^=i<<s.getBCHDigit(p)-d;return c<<12|p}})(Rs)),Rs}var Ls={},rr;function Uh(){if(rr)return Ls;rr=1;const t=xt(),s=1335,n=21522,a=t.getBCHDigit(s);return Ls.getEncodedBits=function(o,i){const d=o.bit<<3|i;let u=d<<10;for(;t.getBCHDigit(u)-a>=0;)u^=s<<t.getBCHDigit(u)-a;return(d<<10|u)^n},Ls}var zs={},Bs,or;function $h(){if(or)return Bs;or=1;const t=pt();function s(n){this.mode=t.NUMERIC,this.data=n.toString()}return s.getBitsLength=function(a){return 10*Math.floor(a/3)+(a%3?a%3*3+1:0)},s.prototype.getLength=function(){return this.data.length},s.prototype.getBitsLength=function(){return s.getBitsLength(this.data.length)},s.prototype.write=function(a){let r,o,i;for(r=0;r+3<=this.data.length;r+=3)o=this.data.substr(r,3),i=parseInt(o,10),a.put(i,10);const d=this.data.length-r;d>0&&(o=this.data.substr(r),i=parseInt(o,10),a.put(i,d*3+1))},Bs=s,Bs}var _s,ir;function Vh(){if(ir)return _s;ir=1;const t=pt(),s=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"," ","$","%","*","+","-",".","/",":"];function n(a){this.mode=t.ALPHANUMERIC,this.data=a}return n.getBitsLength=function(r){return 11*Math.floor(r/2)+6*(r%2)},n.prototype.getLength=function(){return this.data.length},n.prototype.getBitsLength=function(){return n.getBitsLength(this.data.length)},n.prototype.write=function(r){let o;for(o=0;o+2<=this.data.length;o+=2){let i=s.indexOf(this.data[o])*45;i+=s.indexOf(this.data[o+1]),r.put(i,11)}this.data.length%2&&r.put(s.indexOf(this.data[o]),6)},_s=n,_s}var Fs,lr;function Kh(){if(lr)return Fs;lr=1;const t=pt();function s(n){this.mode=t.BYTE,typeof n=="string"?this.data=new TextEncoder().encode(n):this.data=new Uint8Array(n)}return s.getBitsLength=function(a){return a*8},s.prototype.getLength=function(){return this.data.length},s.prototype.getBitsLength=function(){return s.getBitsLength(this.data.length)},s.prototype.write=function(n){for(let a=0,r=this.data.length;a<r;a++)n.put(this.data[a],8)},Fs=s,Fs}var Us,cr;function qh(){if(cr)return Us;cr=1;const t=pt(),s=xt();function n(a){this.mode=t.KANJI,this.data=a}return n.getBitsLength=function(r){return r*13},n.prototype.getLength=function(){return this.data.length},n.prototype.getBitsLength=function(){return n.getBitsLength(this.data.length)},n.prototype.write=function(a){let r;for(r=0;r<this.data.length;r++){let o=s.toSJIS(this.data[r]);if(o>=33088&&o<=40956)o-=33088;else if(o>=57408&&o<=60351)o-=49472;else throw new Error("Invalid SJIS character: "+this.data[r]+`
12
- Make sure your charset is UTF-8`);o=(o>>>8&255)*192+(o&255),a.put(o,13)}},Us=n,Us}var $s={exports:{}},dr;function Gh(){return dr||(dr=1,(function(t){var s={single_source_shortest_paths:function(n,a,r){var o={},i={};i[a]=0;var d=s.PriorityQueue.make();d.push(a,0);for(var u,x,h,l,f,c,p,g,w;!d.empty();){u=d.pop(),x=u.value,l=u.cost,f=n[x]||{};for(h in f)f.hasOwnProperty(h)&&(c=f[h],p=l+c,g=i[h],w=typeof i[h]>"u",(w||g>p)&&(i[h]=p,d.push(h,p),o[h]=x))}if(typeof r<"u"&&typeof i[r]>"u"){var k=["Could not find a path from ",a," to ",r,"."].join("");throw new Error(k)}return o},extract_shortest_path_from_predecessor_list:function(n,a){for(var r=[],o=a;o;)r.push(o),n[o],o=n[o];return r.reverse(),r},find_path:function(n,a,r){var o=s.single_source_shortest_paths(n,a,r);return s.extract_shortest_path_from_predecessor_list(o,r)},PriorityQueue:{make:function(n){var a=s.PriorityQueue,r={},o;n=n||{};for(o in a)a.hasOwnProperty(o)&&(r[o]=a[o]);return r.queue=[],r.sorter=n.sorter||a.default_sorter,r},default_sorter:function(n,a){return n.cost-a.cost},push:function(n,a){var r={value:n,cost:a};this.queue.push(r),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return this.queue.length===0}}};t.exports=s})($s)),$s.exports}var ur;function Hh(){return ur||(ur=1,(function(t){const s=pt(),n=$h(),a=Vh(),r=Kh(),o=qh(),i=gi(),d=xt(),u=Gh();function x(k){return unescape(encodeURIComponent(k)).length}function h(k,j,y){const N=[];let A;for(;(A=k.exec(y))!==null;)N.push({data:A[0],index:A.index,mode:j,length:A[0].length});return N}function l(k){const j=h(i.NUMERIC,s.NUMERIC,k),y=h(i.ALPHANUMERIC,s.ALPHANUMERIC,k);let N,A;return d.isKanjiModeEnabled()?(N=h(i.BYTE,s.BYTE,k),A=h(i.KANJI,s.KANJI,k)):(N=h(i.BYTE_KANJI,s.BYTE,k),A=[]),j.concat(y,N,A).sort(function(I,L){return I.index-L.index}).map(function(I){return{data:I.data,mode:I.mode,length:I.length}})}function f(k,j){switch(j){case s.NUMERIC:return n.getBitsLength(k);case s.ALPHANUMERIC:return a.getBitsLength(k);case s.KANJI:return o.getBitsLength(k);case s.BYTE:return r.getBitsLength(k)}}function c(k){return k.reduce(function(j,y){const N=j.length-1>=0?j[j.length-1]:null;return N&&N.mode===y.mode?(j[j.length-1].data+=y.data,j):(j.push(y),j)},[])}function p(k){const j=[];for(let y=0;y<k.length;y++){const N=k[y];switch(N.mode){case s.NUMERIC:j.push([N,{data:N.data,mode:s.ALPHANUMERIC,length:N.length},{data:N.data,mode:s.BYTE,length:N.length}]);break;case s.ALPHANUMERIC:j.push([N,{data:N.data,mode:s.BYTE,length:N.length}]);break;case s.KANJI:j.push([N,{data:N.data,mode:s.BYTE,length:x(N.data)}]);break;case s.BYTE:j.push([{data:N.data,mode:s.BYTE,length:x(N.data)}])}}return j}function g(k,j){const y={},N={start:{}};let A=["start"];for(let O=0;O<k.length;O++){const I=k[O],L=[];for(let C=0;C<I.length;C++){const E=I[C],M=""+O+C;L.push(M),y[M]={node:E,lastCount:0},N[M]={};for(let V=0;V<A.length;V++){const F=A[V];y[F]&&y[F].node.mode===E.mode?(N[F][M]=f(y[F].lastCount+E.length,E.mode)-f(y[F].lastCount,E.mode),y[F].lastCount+=E.length):(y[F]&&(y[F].lastCount=E.length),N[F][M]=f(E.length,E.mode)+4+s.getCharCountIndicator(E.mode,j))}}A=L}for(let O=0;O<A.length;O++)N[A[O]].end=0;return{map:N,table:y}}function w(k,j){let y;const N=s.getBestModeForData(k);if(y=s.from(j,N),y!==s.BYTE&&y.bit<N.bit)throw new Error('"'+k+'" cannot be encoded with mode '+s.toString(y)+`.
13
- Suggested mode is: `+s.toString(N));switch(y===s.KANJI&&!d.isKanjiModeEnabled()&&(y=s.BYTE),y){case s.NUMERIC:return new n(k);case s.ALPHANUMERIC:return new a(k);case s.KANJI:return new o(k);case s.BYTE:return new r(k)}}t.fromArray=function(j){return j.reduce(function(y,N){return typeof N=="string"?y.push(w(N,null)):N.data&&y.push(w(N.data,N.mode)),y},[])},t.fromString=function(j,y){const N=l(j,d.isKanjiModeEnabled()),A=p(N),O=g(A,y),I=u.find_path(O.map,"start","end"),L=[];for(let C=1;C<I.length-1;C++)L.push(O.table[I[C]].node);return t.fromArray(c(L))},t.rawSplit=function(j){return t.fromArray(l(j,d.isKanjiModeEnabled()))}})(zs)),zs}var mr;function Wh(){if(mr)return ks;mr=1;const t=xt(),s=Hn(),n=Th(),a=Rh(),r=Oh(),o=Dh(),i=Lh(),d=pi(),u=_h(),x=Fh(),h=Uh(),l=pt(),f=Hh();function c(O,I){const L=O.size,C=o.getPositions(I);for(let E=0;E<C.length;E++){const M=C[E][0],V=C[E][1];for(let F=-1;F<=7;F++)if(!(M+F<=-1||L<=M+F))for(let b=-1;b<=7;b++)V+b<=-1||L<=V+b||(F>=0&&F<=6&&(b===0||b===6)||b>=0&&b<=6&&(F===0||F===6)||F>=2&&F<=4&&b>=2&&b<=4?O.set(M+F,V+b,!0,!0):O.set(M+F,V+b,!1,!0))}}function p(O){const I=O.size;for(let L=8;L<I-8;L++){const C=L%2===0;O.set(L,6,C,!0),O.set(6,L,C,!0)}}function g(O,I){const L=r.getPositions(I);for(let C=0;C<L.length;C++){const E=L[C][0],M=L[C][1];for(let V=-2;V<=2;V++)for(let F=-2;F<=2;F++)V===-2||V===2||F===-2||F===2||V===0&&F===0?O.set(E+V,M+F,!0,!0):O.set(E+V,M+F,!1,!0)}}function w(O,I){const L=O.size,C=x.getEncodedBits(I);let E,M,V;for(let F=0;F<18;F++)E=Math.floor(F/3),M=F%3+L-8-3,V=(C>>F&1)===1,O.set(E,M,V,!0),O.set(M,E,V,!0)}function k(O,I,L){const C=O.size,E=h.getEncodedBits(I,L);let M,V;for(M=0;M<15;M++)V=(E>>M&1)===1,M<6?O.set(M,8,V,!0):M<8?O.set(M+1,8,V,!0):O.set(C-15+M,8,V,!0),M<8?O.set(8,C-M-1,V,!0):M<9?O.set(8,15-M-1+1,V,!0):O.set(8,15-M-1,V,!0);O.set(C-8,8,1,!0)}function j(O,I){const L=O.size;let C=-1,E=L-1,M=7,V=0;for(let F=L-1;F>0;F-=2)for(F===6&&F--;;){for(let b=0;b<2;b++)if(!O.isReserved(E,F-b)){let _=!1;V<I.length&&(_=(I[V]>>>M&1)===1),O.set(E,F-b,_),M--,M===-1&&(V++,M=7)}if(E+=C,E<0||L<=E){E-=C,C=-C;break}}}function y(O,I,L){const C=new n;L.forEach(function(b){C.put(b.mode.bit,4),C.put(b.getLength(),l.getCharCountIndicator(b.mode,O)),b.write(C)});const E=t.getSymbolTotalCodewords(O),M=d.getTotalCodewordsCount(O,I),V=(E-M)*8;for(C.getLengthInBits()+4<=V&&C.put(0,4);C.getLengthInBits()%8!==0;)C.putBit(0);const F=(V-C.getLengthInBits())/8;for(let b=0;b<F;b++)C.put(b%2?17:236,8);return N(C,O,I)}function N(O,I,L){const C=t.getSymbolTotalCodewords(I),E=d.getTotalCodewordsCount(I,L),M=C-E,V=d.getBlocksCount(I,L),F=C%V,b=V-F,_=Math.floor(C/V),K=Math.floor(M/V),D=K+1,$=_-K,Y=new u($);let H=0;const se=new Array(V),q=new Array(V);let Q=0;const B=new Uint8Array(O.buffer);for(let xe=0;xe<V;xe++){const Pe=xe<b?K:D;se[xe]=B.slice(H,H+Pe),q[xe]=Y.encode(se[xe]),H+=Pe,Q=Math.max(Q,Pe)}const ne=new Uint8Array(C);let R=0,P,ce;for(P=0;P<Q;P++)for(ce=0;ce<V;ce++)P<se[ce].length&&(ne[R++]=se[ce][P]);for(P=0;P<$;P++)for(ce=0;ce<V;ce++)ne[R++]=q[ce][P];return ne}function A(O,I,L,C){let E;if(Array.isArray(O))E=f.fromArray(O);else if(typeof O=="string"){let _=I;if(!_){const K=f.rawSplit(O);_=x.getBestVersionForData(K,L)}E=f.fromString(O,_||40)}else throw new Error("Invalid data");const M=x.getBestVersionForData(E,L);if(!M)throw new Error("The amount of data is too big to be stored in a QR Code");if(!I)I=M;else if(I<M)throw new Error(`
10
+ `?e.jsxs(m.Fragment,{children:[e.jsx("br",{}),e.jsx("br",{})]},o.id):e.jsx("span",{style:{color:o.color},children:o.text},o.id)),e.jsx("span",{className:"inline-block w-2 h-4 animate-pulse",style:{backgroundColor:t.cursor}})]})}function Qm({isFavorite:t,onClick:s,ariaLabel:n}){return e.jsx("button",{type:"button","aria-label":n,"aria-pressed":t,onClick:a=>{a.stopPropagation(),a.preventDefault(),s(a)},className:"p-1 hover:text-red-500 transition-colors",children:t?e.jsx(Ca,{className:"h-4 w-4 fill-red-500 text-red-500"}):e.jsx(Ca,{className:"h-4 w-4"})})}function Xm({value:t,onValueChange:s,themes:n,favoriteThemes:a,onToggleFavorite:r,onThemeHover:o,showFavoritesOnly:i,onShowFavoritesOnlyChange:d,showEmptyFavoritesHint:u}){const{t:x}=z(),[h,l]=m.useState(t),[f,c]=m.useState(t),[p,g]=m.useState(!1),w=m.useRef(void 0),k=m.useRef(null),j=m.useRef(t),y=m.useRef(!1),N=m.useMemo(()=>new Set(a),[a]);m.useEffect(()=>{p||(l(t),c(t))},[t,p]);const A=m.useMemo(()=>{if(!f||f===h)return n;const E=f.toLowerCase();return n.filter(M=>M.toLowerCase().includes(E))},[n,f,h]),O=E=>{E&&(y.current=!0,l(E),c(E)),s(E)},I=E=>{g(E),E?(j.current=t,y.current=!1,l(t),c(t)):y.current||o?.(j.current)},L=E=>{clearTimeout(w.current),w.current=setTimeout(()=>{o?.(E)},50)},C=()=>{clearTimeout(w.current)};return m.useEffect(()=>{if(!p)return;const E=M=>{(M.key==="ArrowDown"||M.key==="ArrowUp")&&requestAnimationFrame(()=>{const V=k.current?.querySelector("[data-highlighted]");if(V){const F=V.getAttribute("data-value");F&&o?.(F)}})};return document.addEventListener("keydown",E,!0),()=>{document.removeEventListener("keydown",E,!0)}},[p,o]),m.useEffect(()=>()=>{clearTimeout(w.current)},[]),e.jsxs(tm,{value:h,onValueChange:O,inputValue:f,onInputValueChange:c,open:p,onOpenChange:I,children:[e.jsxs("div",{className:"relative",children:[e.jsx(sm,{placeholder:x("Search themes...")}),e.jsxs("div",{className:"absolute right-8 top-1/2 -translate-y-1/2 flex items-center gap-1.5",children:[e.jsx(Qe,{id:"show-favorites-only-inner",checked:i,onCheckedChange:E=>d(E===!0),onClick:E=>E.stopPropagation()}),e.jsx("label",{htmlFor:"show-favorites-only-inner",className:"text-xs text-muted-foreground cursor-pointer whitespace-nowrap",onClick:E=>E.stopPropagation(),onKeyDown:E=>E.stopPropagation(),children:x("Show favorites only")})]})]}),e.jsx(am,{children:e.jsxs(om,{ref:k,children:[A.length===0&&e.jsx("div",{className:"py-6 text-center text-sm text-muted-foreground",children:x(u?"No favorite themes yet. Click the heart icon to add favorites.":"No themes found")}),A.map(E=>e.jsx(rm,{value:E,"data-value":E,onMouseEnter:()=>L(E),onMouseLeave:C,endAddon:e.jsx(Qm,{isFavorite:N.has(E),onClick:()=>r(E),ariaLabel:N.has(E)?x("Remove from favorites"):x("Add to favorites")}),children:E},E))]})})]})}const Zm={theme:"Follow theme",violet:"Violet",indigo:"Indigo",teal:"Teal",amber:"Amber",graphite:"Graphite"},Oa={body:"Body",h1:"Heading 1",h2:"Heading 2",h3:"Heading 3",h4:"Heading 4–6",table:"Table",inlineCode:"Inline code",codeBlock:"Code block"},Da=yo.map(t=>({value:String(t),label:String(t)}));function eh(){const{t}=z(),s=v(u=>u.chatTypography),n=v(u=>u.setChatTypography),a=v(u=>u.resetChatTypography),[r,o]=m.useState(s.body.size);m.useEffect(()=>{o(s.body.size)},[s.body.size]);const i=(u,x)=>{const h=v.getState().chatTypography;n({...h,[u]:{...h[u],size:x}})},d=(u,x)=>{const h=v.getState().chatTypography;n({...h,[u]:{...h[u],weight:x}})};return e.jsxs("section",{"data-settings-row":"appearance.chatTypography",className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:t("Conversation typography")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("Headings, tables and inline code scale with the body text")})]}),e.jsxs("div",{className:"space-y-3 rounded-lg border bg-card p-3.5",children:[Fl.map(u=>{const x=Ul[u];return e.jsx(tt,{label:t(Oa[u]),value:s[u].size,min:x.min,max:x.max,step:x.step,unit:x.unit==="%"?"%":"px",valueClassName:"w-28",formatSuffix:x.unit==="%"?h=>`${(r*h/100).toFixed(1)}px`:void 0,onPreview:u==="body"?o:void 0,onCommit:h=>i(u,h),trailing:e.jsxs(ae,{items:Da,value:String(s[u].weight),onValueChange:h=>{const l=Number(h);yo.includes(l)&&d(u,l)},children:[e.jsx(re,{className:"w-24 min-w-24","aria-label":t(Oa[u]),children:e.jsx(oe,{})}),e.jsx(ie,{children:Da.map(h=>e.jsx(ee,{value:h.value,children:h.label},h.value))})]})},u)}),e.jsx("div",{className:"flex justify-end",children:e.jsx(S,{variant:"outline",size:"sm",onClick:()=>a(),children:t("Reset to defaults")})})]})]})}function th({seconds:t,onCommit:s}){const{t:n}=z(),[a,r]=m.useState(String(t));m.useEffect(()=>r(String(t)),[t]);const o=()=>{const i=Number(a);if(!Number.isInteger(i)){r(String(t));return}const d=Kl(i);s(d),r(String(d))};return e.jsxs("div",{className:"flex items-center justify-between gap-3","data-settings-row":"appearance.liveActivityFoldDelaySec",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:n("Wait before folding")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n("Seconds to wait after tools and thinking finish")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(J,{type:"number",min:1,max:60,value:a,onChange:i=>r(i.target.value),onBlur:o,onKeyDown:i=>{i.key==="Enter"&&(o(),i.currentTarget.blur())},className:"w-20"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:n("sec")})]})]})}function sh(){const{t}=z(),s=v(A=>A.openChangesOnFileEdit),n=v(A=>A.setOpenChangesOnFileEdit),a=v(A=>A.compactReadOnlyTools),r=v(A=>A.setCompactReadOnlyTools),o=v(A=>A.expandLiveEdits),i=v(A=>A.setExpandLiveEdits),d=v(A=>A.expandLiveReasoning),u=v(A=>A.setExpandLiveReasoning),x=v(A=>A.autoCollapseTurns),h=v(A=>A.setAutoCollapseTurns),l=v(A=>A.collapseCompletedActivity),f=v(A=>A.setCollapseCompletedActivity),c=v(A=>A.collapseLiveActivity),p=v(A=>A.setCollapseLiveActivity),g=v(A=>A.liveActivityFoldDelaySec),w=v(A=>A.setLiveActivityFoldDelaySec),k=v(A=>A.pinUnfinishedTodos),j=v(A=>A.setPinUnfinishedTodos),y=v(A=>A.navRailSide),N=v(A=>A.setNavRailSide);return e.jsxs("div",{className:"space-y-6",children:[e.jsx("h3",{className:"text-lg font-medium",children:t("Conversation display")}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Te,{rowId:"appearance.openChangesOnFileEdit",title:t("Open Changes when files are edited"),description:t("Automatically show the side panel Changes tab after the agent edits a file"),checked:s,onChange:n}),e.jsx(Te,{rowId:"appearance.compactReadOnlyTools",title:t("Compact read-only tool calls"),description:t("Show read/grep/find/ls as one-line rows and fold consecutive tool calls while the agent is still running"),checked:a,onChange:r}),e.jsx(Te,{rowId:"appearance.expandLiveEdits",title:t("Expand file edits while running"),description:t("Automatically unfold diffs or written content from file modification tools while the agent is still running"),checked:o,onChange:i}),e.jsx(Te,{rowId:"appearance.expandLiveReasoning",title:t("Expand reasoning while streaming"),description:t("Automatically unfold the thinking block while the model is still reasoning. It collapses again when reasoning ends."),checked:d,onChange:u}),e.jsx(Te,{rowId:"appearance.autoCollapseTurns",title:t("Auto-collapse previous turns"),description:t("After you send a new message, fold earlier turns down to the question, timestamp and duration; the latest turn stays expanded"),checked:x,onChange:h}),e.jsx(Te,{rowId:"appearance.collapseCompletedActivity",title:t("Collapse activity after reply"),description:t("When a reply finishes, fold consecutive thinking and tool calls (including edits and commands) into one summary row; failed calls stay visible"),checked:l,onChange:f}),e.jsx(Te,{rowId:"appearance.collapseLiveActivity",title:t("Collapse finished activity while replying"),description:t("While a reply is still running, wait a moment after tools and thinking finish, then fold that stretch into one row. Calls still running stay visible, and failed calls stay visible"),checked:c,onChange:p,children:c?e.jsx(th,{seconds:g,onCommit:w}):null}),e.jsx(Te,{rowId:"appearance.pinUnfinishedTodos",title:t("Pin unfinished todos"),description:t("Keep the latest todo list above the input while it has unfinished items, so it does not scroll away with the timeline"),checked:k,onChange:j}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"appearance.navRailSide",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Turn marks")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Marks along the conversation for each turn. Hover to preview, click to jump. Hidden when the chat uses the full width.")})]}),e.jsx("div",{className:"w-36 shrink-0",children:e.jsx(zn,{value:y,options:[{value:"left",label:t("Left")},{value:"right",label:t("Right")},{value:"off",label:t("Off")}],onChange:N})})]})]}),e.jsx(eh,{}),e.jsx(cm,{})]})}function nh({onOpenPlugins:t}){const{t:s}=z(),n=v(i=>i.themeId),a=v(i=>i.setThemeId),r=Dn(i=>i.themes),o=go();return e.jsxs("section",{"data-settings-row":"appearance.themeGallery",className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("Theme")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("Built-in and plugin themes; each one is a set of color tokens")})]}),e.jsx(Hm,{themes:vo(r),selected:n,mode:o,onSelect:a,onGetMore:t})]})}function ah(){const{t}=z(),s=v(r=>r.userCssEnabled),n=v(r=>r.setUserCssEnabled),a=async()=>{const r=await window.electronAPI.appearance.openUserCss();r.ok||Re({type:"error",title:t("Cannot open user.css"),description:r.error})};return e.jsxs(gn,{rowId:"appearance.userCss",title:t("Custom CSS"),description:t("Inject user.css into every window; saved changes apply immediately"),children:[e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>{a()},children:[e.jsx(zl,{}),t("Open user.css")]}),e.jsx(le,{checked:s,onCheckedChange:r=>n(r===!0),"aria-label":t("Custom CSS")})]})}function rh({onOpenPlugins:t}={}){const s=v(_=>_.borderOpacity),n=v(_=>_.setBorderOpacity),{theme:a,setTheme:r,themeId:o,accentColor:i,setAccentColor:d,terminalTheme:u,setTerminalTheme:x,terminalFontSize:h,setTerminalFontSize:l,terminalFontFamily:f,setTerminalFontFamily:c,terminalFontWeight:p,setTerminalFontWeight:g,terminalFontWeightBold:w,setTerminalFontWeightBold:k,favoriteTerminalThemes:j,toggleFavoriteTerminalTheme:y}=v(),{t:N}=z(),A=go(),O=Dn(_=>_.themes),I=[{value:"light",icon:Ku,label:N("Light")},{value:"dark",icon:Ml,label:N("Dark")},{value:"system",icon:Ln,label:N("System")},{value:"sync-terminal",icon:jo,label:N("Sync terminal theme")}],L=Pl.map(_=>({value:_,label:N(Zm[_]),swatch:_==="theme"?Rl(o,vo(O))[A].accent:Tl[_][A]})),[C,E]=m.useState(h),[M,V]=m.useState(f),[F,b]=m.useState(!1);m.useEffect(()=>{E(h)},[h]),m.useEffect(()=>{V(f)},[f]);const B=m.useCallback(()=>{const _=Math.max(8,Math.min(32,C||8));_!==C&&E(_),_!==h&&l(_)},[C,h,l]),K=m.useCallback(()=>{const _=M.trim()||f;_!==M&&V(_),_!==f&&c(_)},[M,f,c]),D=m.useMemo(()=>Ol(),[]),$=m.useMemo(()=>{if(!F)return D;const _=D.filter(ne=>j.includes(ne));return j.includes(u)?_:[u,..._]},[D,F,j,u]),Y=F&&j.length===0,H=m.useMemo(()=>Ll(u)??Dl,[u]),se=_=>{_&&x(_)},q=()=>{const _=F?$:D,ne=_.indexOf(u),R=ne<=0?_.length-1:ne-1;x(_[R])},Q=()=>{const _=F?$:D,ne=_.indexOf(u),R=ne>=_.length-1?0:ne+1;x(_[R])};return e.jsxs("div",{className:"space-y-6",children:[e.jsx(nh,{onOpenPlugins:t}),e.jsxs("section",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:N("Personalization")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:N("Applied on top of any theme")})]}),e.jsxs(Wm,{children:[e.jsx(gn,{rowId:"appearance.theme",title:N("Theme mode"),children:e.jsx("div",{className:"flex rounded-lg bg-muted p-0.5",children:I.map(_=>e.jsxs("button",{type:"button",onClick:()=>r(_.value),"aria-pressed":a===_.value,className:G("flex h-7 items-center gap-1.5 rounded-md px-2.5 text-xs transition-colors",a===_.value?"bg-background text-foreground shadow-xs":"text-muted-foreground hover:text-foreground"),children:[e.jsx(_.icon,{className:"size-3.5"}),_.label]},_.value))})}),e.jsx(gn,{rowId:"appearance.accent",title:N("Accent color"),description:N("Used for running state, checkmarks and plan mode"),children:L.map(_=>_.value==="theme"?e.jsxs("button",{type:"button",onClick:()=>d(_.value),"aria-pressed":i===_.value,className:G("flex h-6 items-center gap-1.5 rounded-full border px-2 text-xs transition-shadow",i===_.value&&"border-transparent ring-2 ring-foreground/60"),children:[e.jsx("span",{"data-theme-accent":!0,className:"size-2.5 rounded-full",style:{backgroundColor:_.swatch}}),_.label]},_.value):e.jsx("button",{type:"button",onClick:()=>d(_.value),title:_.label,"aria-label":_.label,"aria-pressed":i===_.value,style:{backgroundColor:_.swatch},className:G("size-5 rounded-full transition-shadow",i===_.value&&"ring-2 ring-offset-2 ring-offset-card ring-foreground/60")},_.value))}),e.jsx(ah,{})]})]}),e.jsx(sh,{}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:N("Terminal")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:N("Terminal appearance")})]}),e.jsx(Jm,{theme:H,fontSize:C,fontFamily:M,fontWeight:p}),e.jsxs("div",{className:"space-y-3 rounded-lg border bg-card p-3.5",children:[e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:N("Color scheme")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(S,{variant:"outline",size:"icon",onClick:q,children:e.jsx(bo,{className:"h-4 w-4"})}),e.jsx("div",{className:"flex-1",children:e.jsx(Xm,{value:u,onValueChange:se,themes:$,favoriteThemes:j,onToggleFavorite:y,onThemeHover:x,showFavoritesOnly:F,onShowFavoritesOnlyChange:b,showEmptyFavoritesHint:Y})}),e.jsx(S,{variant:"outline",size:"icon",onClick:Q,children:e.jsx(Mt,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:N("Font")}),e.jsx(J,{value:M,onChange:_=>V(_.target.value),onBlur:K,onKeyDown:_=>{_.nativeEvent.isComposing||_.key==="Enter"&&(K(),_.currentTarget.blur())},placeholder:"JetBrains Mono, monospace"})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:N("Font size")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(J,{type:"number",value:C,onChange:_=>E(Number(_.target.value)),onBlur:B,onKeyDown:_=>{_.key==="Enter"&&(B(),_.currentTarget.blur())},min:8,max:32,className:"w-20"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"px"})]})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:N("Font weight")}),e.jsxs(ae,{items:Gt,value:p,onValueChange:_=>g(_),children:[e.jsx(re,{className:"w-48",children:e.jsx(oe,{})}),e.jsx(ie,{children:Gt.map(_=>e.jsx(ee,{value:_.value,children:_.label},_.value))})]})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:N("Bold font weight")}),e.jsxs(ae,{items:Gt,value:w,onValueChange:_=>k(_),children:[e.jsx(re,{className:"w-48",children:e.jsx(oe,{})}),e.jsx(ie,{children:Gt.map(_=>e.jsx(ee,{value:_.value,children:_.label},_.value))})]})]})]}),e.jsx(tt,{label:N("Border opacity"),value:Math.round(s*100),onCommit:_=>n(_/100)}),e.jsx(Ym,{})]})}const La=15e3,oh=3e3;function ih(t){return!t||!t.timeoutSet&&t.timeoutMs===oh?La:t.timeoutMs}const za=()=>{},ys="off",ws=t=>({timeoutMs:t?.timeoutMs??ql,...t?.timeoutSet&&{timeoutSet:!0}});function lh({classifier:t,effectiveMs:s,hint:n,onChange:a}){const{t:r}=z(),[o,i]=m.useState(String(s/1e3));m.useEffect(()=>i(String(s/1e3)),[s]);const d=()=>{const u=Number(o);if(!o.trim()||!Number.isFinite(u))return i(String(s/1e3));const x=Wl(u*1e3);i(String(x/1e3)),x!==s&&a({...t,timeoutMs:x,timeoutSet:!0})};return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs",children:r("Timeout")}),e.jsx(J,{type:"number",value:o,min:Hl/1e3,max:Gl/1e3,step:.5,className:"h-7 w-20 text-xs",onChange:u=>i(u.target.value),onBlur:d,onKeyDown:u=>{u.key==="Enter"&&u.currentTarget.blur()}}),e.jsx("span",{className:"text-xs text-muted-foreground",children:r("seconds")}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:n})]})}function ts({providers:t,value:s,emptyLabel:n,onSelect:a}){return e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx(ze,{providers:t,providerId:s?.providerId??"",modelId:s?.modelId??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:n,side:"bottom",triggerClassName:Ye,onSelect:(r,o)=>a({providerId:r,modelId:o}),onReasoningChange:za,onThinkingChange:za})})}function Yt({label:t,hint:s,children:n}){return e.jsxs("div",{className:"grid grid-cols-[6rem_1fr] items-start gap-2",children:[e.jsxs("div",{className:"pt-1.5 text-xs",children:[e.jsx("div",{children:t}),s&&e.jsx("div",{className:"text-[10px] text-muted-foreground",children:s})]}),e.jsx("div",{className:"min-w-0 space-y-1",children:n})]})}function ui({value:t,onChange:s,providers:n,classifierProviders:a,offLabel:r,judgeLabel:o,judgeSeed:i,description:d,effectiveTimeoutMs:u,timeoutHint:x}){const{t:h}=z(),l=t,[f,c]=m.useState(!1),p=l?.source??(f?"judge":ys),g=l?.source==="pi-classifier"?l.model.providerId:"",[w,k]=m.useState([]),[j,y]=m.useState(!1);m.useEffect(()=>{if(!g){k([]);return}let I=!1;return window.electronAPI.providers.classifierModels(g).then(L=>{I||k(L)}),()=>{I=!0}},[g]);const N=async I=>{const C=(await window.electronAPI.providers.classifierModels(I))[0];y(!C),C&&s({source:"pi-classifier",model:{providerId:I,modelId:C.id},...ws(l)})},A=I=>{if(y(!1),c(I==="judge"&&!i),I===ys)return s(void 0);if(I==="judge")return s(i?{source:"judge",model:i,...ws(l)}:void 0);const L=a[0];L&&N(L.id)},O=[{value:ys,label:r},{value:"judge",label:o},...a.length>0?[{value:"pi-classifier",label:h("Classifier model")}]:[]];return e.jsxs("div",{className:"space-y-1",children:[e.jsxs(ae,{items:O,value:p,onValueChange:I=>A(String(I)),children:[e.jsx(re,{size:"sm",className:"w-48",children:e.jsx(oe,{})}),e.jsx(ie,{children:O.map(I=>e.jsx(ee,{value:I.value,children:I.label},I.value))})]}),p==="judge"&&e.jsx(ts,{providers:n,value:l?.source==="judge"?l.model:void 0,emptyLabel:h("Select model"),onSelect:I=>{c(!1),s({source:"judge",model:I,...ws(l)})}}),l?.source==="pi-classifier"&&e.jsxs("div",{className:"flex gap-1",children:[e.jsxs(ae,{items:a.map(I=>({value:I.id,label:I.name})),value:l.model.providerId,onValueChange:I=>{N(String(I))},children:[e.jsx(re,{size:"sm",className:"w-40",children:e.jsx(oe,{})}),e.jsx(ie,{children:a.map(I=>e.jsx(ee,{value:I.id,children:I.name},I.id))})]}),e.jsxs(ae,{items:w.map(I=>({value:I.id,label:I.name})),value:l.model.modelId||null,onValueChange:I=>s({...l,model:{providerId:l.model.providerId,modelId:String(I)}}),children:[e.jsx(re,{size:"sm",className:"min-w-0 flex-1",children:e.jsx(oe,{placeholder:h("Select model")})}),e.jsx(ie,{children:w.map(I=>e.jsx(ee,{value:I.id,children:I.name},I.id))})]})]}),j&&e.jsx("p",{className:"text-[10px] text-destructive",children:h("No classifier models available")}),l&&e.jsx(lh,{classifier:l,effectiveMs:u??l.timeoutMs,hint:x,onChange:s}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:d})]})}function ch({entry:t,providers:s,classifierProviders:n,update:a}){const{t:r}=z();return t.fast?e.jsx(ui,{value:t.classifier,onChange:o=>a({classifier:o}),providers:s,classifierProviders:n,offLabel:r("Off"),judgeLabel:r("Fast model judges"),judgeSeed:t.fast,description:r("Classifies each new turn: simple turns use the fast model, complex ones the primary model. Adds a short delay before the reply."),timeoutHint:r("Uses the primary model on timeout.")}):e.jsx("p",{className:"pt-1.5 text-[11px] text-muted-foreground",children:r("Set a fast model first")})}function dh({entry:t,providers:s,classifierProviders:n}){const{t:a}=z(),r=v(x=>x.updateVirtualModel),o=v(x=>x.removeVirtualModel),i=[t.primary,...t.fast?[t.fast]:[],...t.fallbacks];let d;for(const x of s){const h=x.models.find(l=>l.enabled!==!1&&!i.some(f=>f.providerId===x.id&&f.modelId===l.id));if(h){d={providerId:x.id,modelId:h.id};break}}const u=x=>r(t.id,x);return e.jsxs("div",{"data-slot":"virtual-model-card",className:G("space-y-2 rounded-md border p-2",!t.enabled&&"bg-muted/50 text-muted-foreground"),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(le,{"aria-label":a("Enable virtual model"),checked:t.enabled,onCheckedChange:x=>u({enabled:x})}),e.jsx(J,{value:t.name,maxLength:60,placeholder:"Auto",className:"h-7 flex-1 text-xs",onChange:x=>u({name:x.target.value})}),!t.enabled&&e.jsx(te,{variant:"outline",className:"shrink-0 text-[10px] text-muted-foreground",children:a("Disabled")}),e.jsx(S,{type:"button",variant:"ghost",size:"icon","aria-label":a("Delete"),className:"h-6 w-6 shrink-0 text-muted-foreground hover:text-destructive",onClick:()=>o(t.id),children:e.jsx(Me,{className:"h-3.5 w-3.5"})})]}),e.jsx(Yt,{label:a("Primary model"),hint:a("Default for each new turn"),children:e.jsx(ts,{providers:s,value:t.primary,onSelect:x=>u({primary:x,fallbacks:t.fallbacks.filter(h=>h.providerId!==x.providerId||h.modelId!==x.modelId)})})}),e.jsx(Yt,{label:a("Fast model"),hint:a("Summaries and simple turns"),children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(ts,{providers:s,value:t.fast,emptyLabel:a("Not used"),onSelect:x=>u({fast:x})}),t.fast&&e.jsx(S,{type:"button",variant:"ghost",size:"icon","aria-label":a("Clear"),className:"h-6 w-6 shrink-0 text-muted-foreground",onClick:()=>u({fast:void 0}),children:e.jsx(ht,{className:"h-3.5 w-3.5"})})]})}),e.jsxs(Yt,{label:a("Fallback models"),hint:a("Used in order when a model is rate limited or down"),children:[t.fallbacks.map((x,h)=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(ts,{providers:s,value:x,onSelect:l=>u({fallbacks:t.fallbacks.map((f,c)=>c===h?l:f)})}),e.jsx(S,{type:"button",variant:"ghost",size:"icon","aria-label":a("Delete"),className:"h-6 w-6 shrink-0 text-muted-foreground hover:text-destructive",onClick:()=>u({fallbacks:t.fallbacks.filter((l,f)=>f!==h)}),children:e.jsx(ht,{className:"h-3.5 w-3.5"})})]},`${x.providerId}/${x.modelId}`)),e.jsxs(S,{type:"button",variant:"outline",size:"sm",className:"h-7 text-xs",disabled:!d||t.fallbacks.length>=8,onClick:()=>{d&&u({fallbacks:[...t.fallbacks,d]})},children:[e.jsx(Oe,{className:"mr-1 h-3.5 w-3.5"}),a("Add fallback")]})]}),e.jsx(Yt,{label:a("Difficulty routing"),children:e.jsx(ch,{entry:t,providers:s,classifierProviders:n,update:u})})]})}function uh(){const{t}=z(),s=v(u=>u.virtualModels),n=v(u=>u.addVirtualModel),a=v(u=>u.defaultModel),r=Xe(),o=m.useMemo(()=>r.filter(wo),[r]),i=Bn(),d=m.useMemo(()=>{if(a&&o.find(x=>x.id===a.providerId)?.models.some(x=>x.id===a.modelId&&x.enabled!==!1))return a;for(const u of o){const x=u.models.find(h=>h.enabled!==!1);if(x)return{providerId:u.id,modelId:x.id}}return null},[o,a]);return e.jsxs("section",{"data-slot":"virtual-models",className:"space-y-2 rounded-lg border bg-card p-3",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium text-sm",children:t("Virtual models")}),e.jsx("p",{className:"mt-0.5 text-muted-foreground text-xs",children:t("A virtual model appears as one model in the picker and routes each request to a real model: fallbacks on rate limits or outages, image-capable or larger-context members when needed, and the fast model for summaries.")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:t("Applies to newly started conversations.")})]}),e.jsxs("div",{className:"space-y-2",children:[s.map(u=>e.jsx(dh,{entry:u,providers:o,classifierProviders:i},u.id)),e.jsxs(S,{type:"button",variant:"outline",size:"sm",className:"h-7 text-xs",disabled:!d,onClick:()=>{d&&n({name:"Auto",enabled:!0,primary:d,fallbacks:[]})},children:[e.jsx(Oe,{className:"mr-1 h-3.5 w-3.5"}),t("New virtual model")]}),!d&&e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Enable a model and configure valid provider credentials first.")})]})]})}function mh(){const{t}=z();return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:t("Bot mode")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("Settings shared by all members and group chats.")})]}),e.jsx(ph,{}),e.jsx(fh,{}),e.jsx(hh,{}),e.jsx(xh,{})]})}function hh(){const{t}=z(),s=v(r=>r.botModeEnabled),n=v(r=>r.botDiscussModeEnabled),a=v(r=>r.setBotDiscussModeEnabled);return s?e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"bots.discussMode",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("p",{className:"text-sm",children:t("Discussion mode")}),e.jsx(te,{variant:"warning",size:"sm","data-experimental-badge":"",children:t("Experimental feature")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Off: group chats work the same as the stable release. On: in smart-routing groups, discussion-style messages let the judge model pick who speaks next.")})]}),e.jsx(le,{checked:n,onCheckedChange:r=>a(r===!0)})]}):null}const _a=Array.from({length:Yl-ha+1},(t,s)=>ha+s);function xh(){const{t}=z(),s=v(a=>a.botMaxRunningTurns),n=v(a=>a.setBotMaxRunningTurns);return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"bots.maxRunningTurns",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Bot concurrency limit")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Shared by private chats, group chats, delegations and routines. Lowering it never interrupts running work; raising it may hit model rate limits.")})]}),e.jsxs(ae,{items:Object.fromEntries(_a.map(a=>[String(a),String(a)])),value:String(s),onValueChange:a=>n(Number(a)),children:[e.jsx(re,{className:"w-20",children:e.jsx(oe,{})}),e.jsx(ie,{children:_a.map(a=>e.jsx(ee,{value:String(a),children:a},a))})]})]})}function ph(){const{t}=z(),s=v(i=>i.botAssistantModel),n=v(i=>i.setBotAssistantModel),a=Xe(),r=s?a.find(i=>i.id===s.providerId):void 0,o=r?.models.find(i=>i.id===s?.modelId);return e.jsxs("div",{className:"rounded-md border px-3 py-2.5","data-settings-row":"bots.assistantModel",children:[e.jsx("p",{className:"text-sm",children:t("Bot assistant model")}),e.jsx("p",{className:"mb-2 text-xs text-muted-foreground",children:t("Used for helper tasks such as auto-configuring member abilities.")}),e.jsx(ze,{providers:a,providerId:o?r?.id??"":"",modelId:o?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:t("Follows the default model"),side:"bottom",triggerClassName:Ye,onSelect:(i,d)=>n({providerId:i,modelId:d}),onReasoningChange:()=>{},onThinkingChange:()=>{}}),s&&!o&&e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:t("Selected model is unavailable — falls back to the default model.")}),s&&e.jsx(S,{variant:"ghost",size:"sm",className:"mt-1",onClick:()=>n(null),children:t("Follow default model")})]})}function fh(){const{t}=z(),s=v(d=>d.botRouteClassifier),n=v(d=>d.setBotRouteClassifier),a=v(d=>d.botDiscussModeEnabled),r=Xe(),o=m.useMemo(()=>r.filter(wo),[r]),i=Bn();return e.jsxs("div",{className:"rounded-md border px-3 py-2.5","data-settings-row":"bots.routeClassifier",children:[e.jsx("p",{className:"text-sm",children:t("Group reply picker model")}),e.jsx("p",{className:"mb-2 text-xs text-muted-foreground",children:t("When nobody is @-mentioned in a smart-routing group, this model picks which member replies.")}),e.jsx(ui,{value:s??void 0,onChange:d=>n(d??null),providers:o,classifierProviders:i,offLabel:t("Default (title model)"),judgeLabel:t("Fast chat model"),description:t(a?"First pick: the group owner replies on timeout, error or an unclear answer. During a discussion, picking the next speaker ends the discussion in these cases.":"Falls back to the group owner on timeout, error or an unclear answer."),effectiveTimeoutMs:s?ih(s):void 0,timeoutHint:t(a?"First pick: handed to the group owner on timeout. Next speaker in a discussion: the discussion ends on timeout.":"Handed to the group owner on timeout.")})]})}const gh=()=>({name:"",title:"",scope:"",summary:"",persona:"",color:dn[0],tools:"all",approvalMode:"auto-edits"}),jn=(t,s)=>({key:t,name:"",title:"",scope:"",persona:"",color:dn[s%dn.length],tools:"all",approvalMode:"auto-edits",canDelegateTo:[],acceptFrom:[]}),jh=()=>({title:"",summary:"",bossKey:"m1",workspace:"chat-home",members:[jn("m1",0),jn("m2",1)]});function vh(t,s){const n=URL.createObjectURL(new Blob([JSON.stringify(s,null,2)],{type:"application/json"})),a=document.createElement("a");a.href=n,a.download=t,a.click(),URL.revokeObjectURL(n)}function bh(){const{t}=z(),s=Jl(!0),n=Ql(!0),[a,r]=m.useState(null),[o,i]=m.useState(null),d=m.useRef(null),u=async(p,g)=>{const w=await dc(k=>({...k,[p]:g(k[p])}));return w||Re({type:"error",title:t("Could not save templates")}),w},x=(p,g)=>u("members",w=>p?fa(w,p,g,xc):ga(w,g,crypto.randomUUID())),h=(p,g)=>u("teams",w=>p?fa(w,p,g,pc):ga(w,g,crypto.randomUUID())),l=async p=>{const g=sc(await p.text());if(!g.ok){Re({type:"error",title:xa(g.error,t)});return}const w=ko(nc(g.team));if(!w){Re({type:"error",title:xa("invalid",t)});return}await h(void 0,w)&&Re({type:"success",title:t("Imported as a custom team template")})},f=(p,g)=>u(p==="members"?"members":"teams",g),c=(p,g,w)=>e.jsxs(e.Fragment,{children:[e.jsx(mt,{label:t("Edit"),onClick:()=>w({id:g.id,data:g.data}),children:e.jsx(lt,{})}),e.jsx(mt,{label:t("Duplicate as custom"),onClick:()=>w({data:g.data}),children:e.jsx(No,{})}),g.source==="builtin"&&e.jsx(mt,{label:g.hidden?t("Show"):t("Hide"),onClick:()=>{f(p,k=>uc(k,g.id,!g.hidden))},children:g.hidden?e.jsx(ec,{}):e.jsx(tc,{})}),g.modified&&e.jsx(mt,{label:t("Restore default"),onClick:()=>{f(p,k=>ja(k,g.id))},children:e.jsx(Fn,{})}),g.source==="custom"&&e.jsx(mt,{label:t("Delete"),onClick:()=>{f(p,k=>ja(k,g.id))},children:e.jsx(Me,{})})]});return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:t("Bot templates")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("Templates used when creating members and teams. Built-in templates can be edited, hidden or restored.")})]}),e.jsxs(Ft,{defaultValue:"members",children:[e.jsxs(Ut,{variant:"underline",children:[e.jsx(Ke,{value:"members",children:t("Member templates")}),e.jsx(Ke,{value:"teams",children:t("Team templates")})]}),e.jsxs(Dt,{value:"members",className:"space-y-2 pt-3",children:[e.jsxs(S,{size:"sm",variant:"outline",onClick:()=>r({data:gh()}),children:[e.jsx(Oe,{}),t("New member template")]}),s.map(p=>e.jsx(Ba,{item:p,avatar:e.jsx(cn,{bot:{name:p.data.name,avatar:{color:p.data.color}}}),title:p.data.name,subtitle:p.data.title,summary:p.data.summary,actions:c("members",p,r)},p.id))]}),e.jsxs(Dt,{value:"teams",className:"space-y-2 pt-3",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(S,{size:"sm",variant:"outline",onClick:()=>i({data:jh()}),children:[e.jsx(Oe,{}),t("New team template")]}),e.jsxs(S,{size:"sm",variant:"outline",onClick:()=>d.current?.click(),children:[e.jsx(Xl,{}),t("Import team (JSON)")]}),e.jsx("input",{ref:d,type:"file",accept:".json,application/json",hidden:!0,onChange:p=>{const g=p.target.files?.[0];p.target.value="",g&&l(g)}})]}),n.map(p=>e.jsx(Ba,{item:p,avatar:e.jsx("div",{className:"-space-x-1.5 flex shrink-0",children:p.data.members.slice(0,4).map(g=>e.jsx(cn,{size:"sm",bot:{name:g.name,avatar:{color:g.color}}},g.key))}),title:p.data.title,subtitle:t("{{n}} members",{n:p.data.members.length}),summary:p.data.summary,actions:e.jsxs(e.Fragment,{children:[e.jsx(mt,{label:t("Export JSON"),onClick:()=>vh(`${p.data.title||"team"}.team.json`,{format:hc,version:mc,exportedAt:new Date().toISOString(),team:Zl(p.data)}),children:e.jsx(Sn,{})}),c("teams",p,i)]})},p.id))]})]}),a&&e.jsx(yh,{initial:a.data,onClose:()=>r(null),onSave:async p=>{await x(a.id,p)&&r(null)}}),o&&e.jsx(Nh,{initial:o.data,onClose:()=>i(null),onSave:async p=>{await h(o.id,p)&&i(null)}})]})}function mt({label:t,onClick:s,disabled:n,children:a}){return e.jsx(S,{variant:"ghost",size:"icon-sm",title:t,"aria-label":t,disabled:n,onClick:s,children:a})}function Ba({item:t,avatar:s,title:n,subtitle:a,summary:r,actions:o}){const{t:i}=z();return e.jsxs("div",{className:"flex items-center gap-3 rounded-md border px-3 py-2.5","data-template-id":t.id,children:[e.jsxs("div",{className:G("flex min-w-0 flex-1 items-center gap-3",t.hidden&&"opacity-50"),children:[s,e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("p",{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx("span",{className:"truncate",children:n}),e.jsx("span",{className:"truncate font-normal text-muted-foreground text-xs",children:a}),e.jsx(te,{variant:"secondary",children:t.source==="custom"?i("Custom"):i("Built-in")}),t.modified&&e.jsx(te,{variant:"outline",children:i("Modified")}),t.hidden&&e.jsx(te,{variant:"outline",children:i("Hidden")})]}),e.jsx("p",{className:"truncate text-muted-foreground text-xs",children:r})]})]}),e.jsx("div",{className:"flex shrink-0 items-center",children:o})]})}function mi({title:t,error:s,onClose:n,onSave:a,children:r}){const{t:o}=z(),[i,d]=m.useState(!1);return e.jsx(pe,{open:!0,onOpenChange:u=>!u&&n(),children:e.jsxs(fe,{className:"max-h-[85vh] max-w-2xl",children:[e.jsx(ge,{children:e.jsx(je,{children:t})}),e.jsxs(we,{className:"space-y-3",children:[r,s&&e.jsx("p",{className:"text-destructive text-xs",children:s})]}),e.jsxs(Ie,{children:[e.jsx(S,{variant:"outline",size:"sm",onClick:n,children:o("Cancel")}),e.jsx(S,{size:"sm",disabled:i||!!s,onClick:()=>{d(!0),a().finally(()=>d(!1))},children:o("Save")})]})]})})}function hi({value:t,onChange:s}){const{t:n}=z(),a=t.name?Co(t.name,[],n):null;return e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(Fe,{children:n("Name")}),e.jsx(J,{value:t.name,onChange:r=>s({name:r.target.value})}),a&&e.jsx("p",{className:"mt-1 text-destructive text-xs",children:a})]}),e.jsxs("div",{children:[e.jsx(Fe,{children:n("Title")}),e.jsx(J,{value:t.title,onChange:r=>s({title:r.target.value})})]}),e.jsxs("div",{children:[e.jsx(Fe,{children:n("Avatar color")}),e.jsx(lc,{value:t.color,onChange:r=>s({color:r})})]}),e.jsxs("div",{children:[e.jsx(Fe,{children:n("Tools")}),e.jsx(zn,{value:t.tools,options:[{value:"all",label:n("All tools")},{value:"readonly",label:n("Read-only")}],onChange:r=>s({tools:r})})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(Fe,{children:n("Approval mode")}),e.jsx(cc,{value:t.approvalMode,onChange:r=>s({approvalMode:r}),zIndex:st.DROPDOWN_IN_MODAL})]}),t.summary!==void 0&&e.jsxs("div",{className:"col-span-2",children:[e.jsx(Fe,{hint:n("Shown on the template card"),children:n("Summary")}),e.jsx(J,{value:t.summary,onChange:r=>s({summary:r.target.value})})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(Fe,{children:n("Responsibilities")}),e.jsx(J,{value:t.scope,onChange:r=>s({scope:r.target.value})})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(Fe,{children:n("Persona")}),e.jsx(He,{rows:6,value:t.persona,onChange:r=>s({persona:r.target.value})})]})]})}function yh({initial:t,onClose:s,onSave:n}){const{t:a}=z(),[r,o]=m.useState(t),i=ac(r);return e.jsx(mi,{title:a("Member template"),error:Co(r.name,[],a)??(i?null:a("Check the template fields")),onClose:s,onSave:()=>i?n(i):Promise.resolve(),children:e.jsx(hi,{value:r,onChange:d=>o(u=>({...u,...d}))})})}function wh(t,s){switch(t){case"title":return s("Enter a team title");case"members":return s("A team needs 2–12 members");case"name":return s("Every member needs a valid name");case"invalid":return s("Check the template fields");default:return null}}function Nh({initial:t,onClose:s,onSave:n}){const{t:a}=z(),[r,o]=m.useState(t),[i,d]=m.useState(null),u=p=>r.members.find(g=>g.key===p)?.name||p,x=p=>o(g=>({...g,...p})),h=(p,g)=>o(w=>({...w,members:w.members.map(k=>k.key===p?{...k,...g}:k)})),l=()=>{const p=new Set(r.members.map(k=>k.key));let g=r.members.length+1;for(;p.has(`m${g}`);)g++;const w=`m${g}`;x({members:[...r.members,jn(w,r.members.length)]}),d(w)},f=p=>{const g=w=>w==="any"?"any":w.filter(k=>k!==p);x({members:r.members.filter(w=>w.key!==p).map(w=>({...w,canDelegateTo:g(w.canDelegateTo),acceptFrom:g(w.acceptFrom)}))})},c=ko(r);return e.jsxs(mi,{title:a("Team template"),error:wh(ic(r),a),onClose:s,onSave:()=>c?n(c):Promise.resolve(),children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(Fe,{children:a("Group name")}),e.jsx(J,{value:r.title,onChange:p=>x({title:p.target.value})})]}),e.jsxs("div",{children:[e.jsx(Fe,{children:a("Owner")}),e.jsxs(ae,{items:r.members.map(p=>({value:p.key,label:u(p.key)})),value:r.bossKey,onValueChange:p=>x({bossKey:p}),children:[e.jsx(re,{className:"w-full",children:e.jsx(oe,{})}),e.jsx(ie,{zIndex:st.DROPDOWN_IN_MODAL,children:r.members.map(p=>e.jsx(ee,{value:p.key,children:u(p.key)},p.key))})]})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(Fe,{hint:a("Shown on the template card"),children:a("Summary")}),e.jsx(J,{value:r.summary,onChange:p=>x({summary:p.target.value})})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(Fe,{children:a("Shared workspace")}),e.jsx(zn,{value:r.workspace,options:[{value:"chat-home",label:a("Standalone workspace")},{value:"project",label:a("Based on a Code project")}],onChange:p=>x({workspace:p})})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1.5 flex items-center justify-between",children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:a("Members")}),e.jsxs(S,{size:"xs",variant:"outline",disabled:r.members.length>=rc,onClick:l,children:[e.jsx(Oe,{}),a("Add member")]})]}),e.jsx("div",{className:"space-y-1.5",children:r.members.map(p=>{const g=i===p.key,w=p.key===r.bossKey,k=r.members.filter(j=>j.key!==p.key).map(j=>j.key);return e.jsxs("div",{className:"rounded-lg border","data-member-key":p.key,children:[e.jsxs("div",{className:"flex items-center gap-2 px-2.5 py-2",children:[e.jsxs("button",{type:"button",className:"flex min-w-0 flex-1 items-center gap-2 text-left",onClick:()=>d(g?null:p.key),children:[g?e.jsx(ns,{className:"h-3.5 w-3.5 shrink-0"}):e.jsx(Mt,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx(cn,{bot:{name:p.name,avatar:{color:p.color}},size:"sm"}),e.jsx("span",{className:"truncate text-sm",children:p.name||a("Unnamed")}),e.jsx("span",{className:"truncate text-muted-foreground text-xs",children:p.title}),w&&e.jsxs("span",{className:"flex shrink-0 items-center gap-0.5 rounded bg-muted px-1.5 text-[10px] text-muted-foreground",children:[e.jsx(oc,{className:"h-3 w-3"}),a("Owner")]})]}),e.jsx(mt,{label:a("Remove"),disabled:w||r.members.length<=2,onClick:()=>f(p.key),children:e.jsx(Me,{})})]}),g&&e.jsxs("div",{className:"space-y-3 border-t p-2.5",children:[e.jsx(hi,{value:p,onChange:j=>h(p.key,j)}),e.jsx(pa,{label:a("Can delegate to"),value:p.canDelegateTo,options:k,nameOf:u,onChange:j=>h(p.key,{canDelegateTo:j})}),e.jsx(pa,{label:a("Accepts delegation from"),value:p.acceptFrom,options:k,nameOf:u,onChange:j=>h(p.key,{acceptFrom:j})})]})]},p.key)})})]})]})}function xi(t){return t.capturePermission==="unsupported"&&t.axPermission==="unsupported"?"unsupported":t.capturePermission==="granted"&&(t.axPermission==="granted"||t.axPermission==="unsupported")?"ready":"needs-permission"}const kh=[{id:"collaboration",label:"Collaboration & planning"},{id:"web",label:"Web"},{id:"execution",label:"Execution"},{id:"context",label:"Context & memory"},{id:"safety",label:"Safety"}],Fa={subagent:"collaboration",workflow:"collaboration",todo:"collaboration",plan:"collaboration",ask_user:"collaboration",browser:"web",web:"web",background_tasks:"execution",isolated_sandbox:"execution",computer:"execution",image_generation:"execution",memory:"context",turn_discard:"context"};function Ch(t,s){return t.filter(n=>Object.hasOwn(Fa,n.id)?Fa[n.id]===s:!1)}function Ua(t){return t.bundleId||t.path}function Sh(){const{t}=z(),[s,n]=m.useState(null),a=v(i=>i.computerAllowAllApps),r=v(i=>i.setComputerAllowAllApps);m.useEffect(()=>{let i=!1;return window.electronAPI.computer.allowedApps().then(d=>{i||n(d)}),()=>{i=!0}},[]);const o=async i=>{await window.electronAPI.computer.revokeApp(Ua(i)),n(await window.electronAPI.computer.allowedApps())};return e.jsxs("div",{className:"space-y-2","data-settings-row":"tools.computerApps",children:[e.jsx("p",{className:"font-medium text-sm",children:t("Apps the AI may control")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("The first time the AI clicks or types in an app, EnsoCode asks you. Apps you always allow are listed here; it can then read everything in their windows.")}),e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium text-sm",children:t("Allow all apps")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("The AI can click, type and read in any app without asking. It can see everything in their windows, including chats and passwords.")})]}),e.jsx(le,{checked:a,onCheckedChange:r})]}),s&&s.length===0?e.jsx("p",{className:"text-muted-foreground text-xs",children:t("No apps are always allowed yet.")}):null,s&&s.length>0?e.jsx("ul",{className:"divide-y rounded-md border",children:s.map(i=>e.jsxs("li",{className:"flex items-center justify-between gap-3 px-3 py-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-sm",children:i.name}),e.jsx("p",{className:"truncate text-muted-foreground text-xs",title:i.path,children:i.bundleId||i.path})]}),e.jsx(S,{variant:"outline",size:"sm",onClick:()=>{o(i)},children:t("Revoke")})]},Ua(i)))}):null]})}function Ih(t){return Object.fromEntries(t.map(s=>[s.id,s]))}function ds(t,s){return t.reduce((n,a)=>{const r=s[a]?.tokens;return r==null?n:n+r},0)}function us({row:t,pending:s}){const{t:n}=z(),a=s?"…":t?.tokens==null?"—":$e(t.tokens);return e.jsx("span",{className:"w-12 shrink-0 text-right text-muted-foreground text-xs tabular-nums",title:t?.error||n("Estimate"),children:a})}function ms({tokens:t}){return t<=0?null:e.jsx("span",{className:"ml-2 font-normal text-muted-foreground text-xs tabular-nums",children:$e(t)})}function hs(t,s){const[n,a]=m.useState({}),[r,o]=m.useState(()=>t.length>0),i=t.join("\0"),d=m.useRef(s);return d.current=s,m.useEffect(()=>{let u=!1;const x=i.length===0?[]:i.split("\0");if(x.length===0){a({}),o(!1);return}return o(!0),d.current(x).then(h=>{u||a(Ih(h))}).finally(()=>{u||o(!1)}),()=>{u=!0}},[i]),{rows:n,pending:r}}const $a={replace:"Text replacement",apply_patch:"Apply patch (default)"},Ah={subagent:Nc,workflow:Un,todo:wc,plan:yc,ask_user:bc,browser:vc,web:Io,background_tasks:jc,memory:So,isolated_sandbox:yu,computer:Ln,turn_discard:gc};function kt({icon:t,title:s,description:n,control:a,children:r,rowId:o,newSession:i}){return e.jsxs("div",{className:"rounded-md border px-3 py-2.5","data-settings-row":o,children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(t,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("p",{className:"text-sm font-medium",children:[s,i&&e.jsx(qe,{note:typeof i=="string"?i:void 0})]}),e.jsx("p",{className:"text-muted-foreground text-xs",children:n})]}),a]}),r?e.jsx("div",{className:"mt-2 space-y-2 pl-7",children:r}):null]})}function Eh({disabled:t}){const{t:s}=z(),n=v(l=>l.webSearchChain),a=v(l=>l.setWebSearchChain),r=$t(),o=m.useMemo(()=>Sc(r),[r]),[i,d]=m.useState(null),u=(l,f)=>{a(n.map((c,p)=>p===l?{...c,...f}:c))},x=l=>a(n.filter((f,c)=>c!==l)),h=(l,f)=>{if(l===f)return;const c=[...n],[p]=c.splice(l,1);p&&(c.splice(f,0,p),a(c))};return e.jsxs("div",{className:"space-y-2","data-settings-row":"tools.webSearchChain",children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Try these models' built-in search in order. Credentials resolve at call time; if all fail, the keyless Exa service is the permanent fallback.")}),n.length===0&&e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Default: use the current session model's built-in search when available, otherwise Exa.")}),n.map((l,f)=>e.jsxs("div",{className:"flex items-center gap-2 rounded-md border px-2 py-1.5",draggable:!t,onDragStart:c=>{c.dataTransfer.effectAllowed="move",d(f)},onDragEnd:()=>d(null),onDragOver:c=>{i!==null&&i!==f&&c.preventDefault()},onDrop:c=>{c.preventDefault(),i!==null&&h(i,f),d(null)},children:[e.jsx(Ic,{className:"h-3.5 w-3.5 shrink-0 cursor-grab text-muted-foreground"}),e.jsx("span",{className:"w-4 shrink-0 text-center text-muted-foreground text-xs",children:f+1}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx(ze,{providers:o,providerId:l.providerId,modelId:l.modelId,reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,onSelect:(c,p)=>u(f,{providerId:c,modelId:p}),onReasoningChange:()=>{},onThinkingChange:()=>{}})}),e.jsx(S,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 shrink-0 p-0",disabled:t,onClick:()=>x(f),"aria-label":s("Remove"),children:e.jsx(Me,{className:"h-3.5 w-3.5"})})]},`${l.providerId}/${l.modelId}`)),n.length<Ac&&e.jsx("div",{className:"max-w-xs",children:e.jsx(ze,{providers:o,providerId:"",modelId:"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,triggerLabel:`+ ${s("Add candidate")}`,onSelect:(l,f)=>a([...n,{providerId:l,modelId:f}]),onReasoningChange:()=>{},onThinkingChange:()=>{}})}),e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Final fallback: Exa (keyless hosted search). Not a chain entry; always last.")})]})}function Mh(){const{t}=z(),s=v(b=>b.disabledBuiltinTools),n=v(b=>b.toggleBuiltinTool),a=v(b=>b.subagentAllowedModes),r=v(b=>b.setSubagentAllowedModes),o=v(b=>b.exploreFoldEnabled),i=v(b=>b.setExploreFoldEnabled),d=v(b=>b.rtkEnabled),u=v(b=>b.computerPreview),x=v(b=>b.setComputerPreview),h=v(b=>b.openLinksInBuiltinBrowser),l=v(b=>b.setOpenLinksInBuiltinBrowser),f=v(b=>b.setRtkEnabled),c=v(b=>b.protectedActionsInCode),p=v(b=>b.setProtectedActionsInCode),g=v(b=>b.editMode),w=v(b=>b.setEditMode),k=hs(bs.map(b=>b.id),()=>window.electronAPI.assets.builtinToolOccupancy()),j=ds(bs.filter(b=>!s.includes(b.id)).map(b=>b.id),k.rows),[y,N]=m.useState(null),A=!s.includes("subagent"),O=(b,B)=>{r(B?[...new Set([...a,b])]:a.filter(K=>K!==b))},I=async b=>{await window.electronAPI.browser.clearData(b),N(b),setTimeout(()=>N(null),2e3)},L=!s.includes("computer"),[C,E]=m.useState(null),[M,V]=m.useState(!1);m.useEffect(()=>{if(!L){E(null);return}let b=!1;return window.electronAPI.computer.capabilities().then(B=>{!b&&B.ok&&E(B.capabilities)}),()=>{b=!0}},[L]),m.useEffect(()=>{if(!M)return;let b=!1;const B=()=>{window.electronAPI.computer.capabilities().then(D=>{!b&&D.ok&&E(D.capabilities)})};B();const K=window.setInterval(B,2e3);return()=>{b=!0,window.clearInterval(K)}},[M]);const F={collaboration:null,web:null,execution:e.jsx(kt,{rowId:"tools.editMode",newSession:!0,icon:Iu,title:t("File edit mode"),description:t("Choose how files are modified. Apply patch is the default. New and cold-restored sessions use this mode; already warm sessions keep their current mode."),control:e.jsxs(ae,{items:Object.fromEntries(va.map(b=>[b,t($a[b])])),value:g,onValueChange:b=>{fc(b)&&w(b)},children:[e.jsx(re,{className:"w-44 shrink-0","aria-label":t("File edit mode"),children:e.jsx(oe,{})}),e.jsx(ie,{children:va.map(b=>e.jsx(ee,{value:b,children:t($a[b])},b))})]})}),context:e.jsxs(e.Fragment,{children:[e.jsx(kt,{icon:Pu,newSession:!0,title:t("Explore fold"),description:t("Let the agent mark exploratory reads and keep only a short report in later model context. Timeline stays intact."),control:e.jsx(le,{checked:o,onCheckedChange:i})}),e.jsx(kt,{rowId:"tools.rtkEnabled",newSession:!0,icon:Fu,title:t("RTK command compression"),description:t("Compress supported command output before it enters the model context. Takes effect on new conversations."),control:e.jsx(le,{checked:d,onCheckedChange:f})})]}),safety:e.jsxs(e.Fragment,{children:[e.jsx(kt,{icon:In,newSession:!0,title:t("Protected action confirmation"),description:t("Even in full-access mode, ask before external sends, deletions, payments, deployments and secret-file access. Always on for Bot members not set to Full access. Takes effect on new conversations."),control:e.jsx(le,{checked:c,onCheckedChange:p})}),e.jsx(Ph,{})]})};return e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{"data-settings-row":"tools.root",children:[e.jsxs("h3",{className:"font-medium text-lg",children:[t("Built-in tools"),e.jsx(ms,{tokens:j})]}),e.jsx("p",{className:"text-muted-foreground text-sm",children:t("Toggle the built-in tools available to agents.")})]}),kh.map(b=>e.jsxs("section",{className:"space-y-3",children:[e.jsx("h4",{className:"border-b pb-2 text-base font-semibold",children:t(b.label)}),Ch(bs,b.id).map(B=>e.jsxs(kt,{icon:Ah[B.id]??Ao,title:t(B.name),description:t(B.description),newSession:B.id==="isolated_sandbox"?t("Isolated sandbox switches between script and tool-search mode, so open sessions keep the mode they started with."):void 0,control:e.jsxs(e.Fragment,{children:[e.jsx(us,{row:k.rows[B.id],pending:k.pending&&!k.rows[B.id]}),e.jsx(le,{checked:!s.includes(B.id),onCheckedChange:K=>{n(B.id,K),B.id==="computer"&&K&&V(!0)}})]}),children:[B.id==="web"?e.jsx(Eh,{disabled:s.includes("web")}):null,B.id==="subagent"?e.jsxs("div",{className:"space-y-2","data-settings-row":"tools.subagentModes",children:[[["task","One-shot task agents"],["coworker","Persistent coworkers"]].map(([K,D])=>e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("span",{className:"text-sm",children:t(D)}),e.jsx(le,{checked:a.includes(K),disabled:!A,onCheckedChange:$=>O(K,$)})]},K)),!A&&e.jsx("p",{className:"text-muted-foreground text-xs",children:t("The unified subagent tool is off. Re-enabling it keeps this mode selection.")})]}):null,B.id==="computer"&&L?e.jsx("div",{className:"space-y-2","data-settings-row":"tools.computer",children:C&&xi(C)==="unsupported"?e.jsx("p",{className:"text-muted-foreground text-xs",children:t("This platform cannot operate the desktop yet.")}):e.jsxs(e.Fragment,{children:[C?.platform==="darwin"&&e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Computer needs Screen Recording to capture windows and Accessibility to inspect or click them. Grant both to EnsoCode, then restart the app.")}),C&&e.jsxs("p",{className:"text-muted-foreground text-xs",children:[t(C.capturePermission==="granted"?"Capture: granted":"Capture: denied"),C.axPermission!=="unsupported"&&e.jsxs(e.Fragment,{children:[" · ",t(C.axPermission==="granted"?"Input/AX: granted":"Input/AX: denied")]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(S,{variant:"outline",size:"sm",onClick:()=>V(!0),children:t("Show permission guide")}),C?.platform==="darwin"&&e.jsxs(e.Fragment,{children:[e.jsx(S,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.computer.openPermissions("screen")},children:t("Open Screen Recording settings")}),e.jsx(S,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.computer.openPermissions("accessibility")},children:t("Open Accessibility settings")})]})]}),C?.platform==="darwin"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium text-sm",children:t("Show the app being operated")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("While the AI works in an app in the background, a small floating window shows that app live. Close it any time.")})]}),e.jsx(le,{checked:u,onCheckedChange:x})]}),e.jsx(Sh,{})]})]})}):null,B.id==="browser"?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium text-sm",children:t("Open chat links in the built-in browser")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Clicking a web link in chat opens it in the side panel browser. {{key}}+Click opens it in the external browser.",{key:kc?"Cmd":"Ctrl"})})]}),e.jsx(le,{checked:h,onCheckedChange:l})]}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Cookies and site storage of the built-in browser, separate from the app itself.")}),e.jsx("div",{className:"flex flex-wrap gap-2",children:["cookies","cache","all"].map(K=>e.jsx(S,{variant:"outline",size:"sm",onClick:()=>{I(K)},children:t(y===K?"Cleared":K==="cookies"?"Clear cookies":K==="cache"?"Clear cache":"Clear all browsing data")},K))})]}):null]},B.id)),F[b.id]]},b.id)),e.jsx(Th,{open:M,capabilities:C,onOpenChange:V})]})}function Ph(){const{t}=z(),s=v(c=>c.dcgEnabled),n=v(c=>c.setDcgEnabled),[a,r]=m.useState(null),[o,i]=m.useState(!1),[d,u]=m.useState(null),[x,h]=m.useState(!1);m.useEffect(()=>{let c=!1;return window.electronAPI.dcg.status().then(p=>{c||r(p)}),()=>{c=!0}},[]);const l=async c=>{h(!1),i(!0),u(null);const p=await window.electronAPI.dcg[c]();r(p.status),p.ok?n(c==="install"):u(p.error??t("Operation failed")),i(!1)},f=a?.installed===!0;return e.jsxs(kt,{rowId:"tools.dcgEnabled",newSession:!0,icon:Cc,title:t("Destructive command guard (dcg)"),description:t("Check bash and PowerShell commands with dcg before running. Matches such as git reset --hard or recursive deletes always require your confirmation, even in full-access mode. Takes effect on new conversations."),control:e.jsx(le,{checked:s&&f,disabled:!f,onCheckedChange:n}),children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("span",{className:"text-muted-foreground",children:a?a.supported?f?t("Installed v{{version}}",{version:a.version}):t("Not installed"):t("Not available on this platform"):t("Loading…")}),a?.supported&&(f?e.jsx(S,{variant:"outline",size:"xs",disabled:o,onClick:()=>{l("uninstall")},children:t("Uninstall")}):e.jsx(S,{variant:"outline",size:"xs",disabled:o,onClick:()=>h(!0),children:t(o?"Installing…":"Install")}))]}),d&&e.jsx("p",{className:"text-destructive text-xs",children:d}),e.jsx(pe,{open:x,onOpenChange:h,children:e.jsxs(fe,{className:"max-w-md",zIndexLevel:"nested",children:[e.jsxs(ge,{children:[e.jsx(je,{children:t("Install dcg")}),e.jsx(Ve,{children:t("Downloads dcg v{{version}} from its GitHub release and verifies the checksum. dcg is a third-party tool, not part of EnsoCode.",{version:a?.version??""})})]}),e.jsx(we,{children:e.jsxs("div",{className:"flex gap-2 rounded-md border border-destructive/32 bg-destructive/8 p-3 text-sm",children:[e.jsx(Ue,{className:"mt-0.5 h-4 w-4 shrink-0 text-destructive"}),e.jsx("p",{children:t("dcg is licensed under MIT with an additional rider: no rights are granted to OpenAI, Anthropic, their affiliates, or anyone acting on their behalf. Install only if this restriction does not apply to you.")})]})}),e.jsxs(Ie,{children:[e.jsx(S,{variant:"outline",size:"sm",onClick:()=>h(!1),children:t("Cancel")}),e.jsx(S,{size:"sm",onClick:()=>{l("install")},children:t("Agree and install")})]})]})})]})}function Th({open:t,capabilities:s,onOpenChange:n}){const{t:a}=z(),r=s?xi(s):null;return e.jsx(pe,{open:t,onOpenChange:n,children:e.jsxs(fe,{className:"max-w-md",zIndexLevel:"nested",children:[e.jsxs(ge,{children:[e.jsx(je,{children:a("Grant Computer permissions")}),e.jsx(Ve,{children:a(r==="unsupported"?"This platform cannot operate the desktop yet.":r==="ready"?"Computer is ready. Open sessions can use it from their next step.":"The agent can screenshot windows and control the mouse and keyboard. Grant Screen Recording and Accessibility to EnsoCode, then restart.")})]}),e.jsxs(we,{className:"space-y-3",children:[!s&&e.jsx("p",{className:"text-muted-foreground text-sm",children:a("Loading…")}),r==="needs-permission"&&e.jsxs("div",{className:"flex gap-2 rounded-md border border-destructive/32 bg-destructive/8 p-3 text-sm",children:[e.jsx(Ue,{className:"mt-0.5 h-4 w-4 shrink-0 text-destructive"}),e.jsx("p",{children:a("Computer needs Screen Recording to capture windows and Accessibility to inspect or click them. Grant both to EnsoCode, then restart the app.")})]}),s?.platform==="darwin"&&r!=="unsupported"&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("p",{className:"text-muted-foreground text-xs",children:[a(s.capturePermission==="granted"?"Capture: granted":"Capture: denied")," · ",a(s.axPermission==="granted"?"Input/AX: granted":"Input/AX: denied"),s.detail?` · ${s.detail}`:""]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(S,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.computer.openPermissions("screen")},children:a("Open Screen Recording settings")}),e.jsx(S,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.computer.openPermissions("accessibility")},children:a("Open Accessibility settings")})]})]})]}),e.jsx(Ie,{className:"sm:justify-end",children:e.jsx(S,{size:"sm",onClick:()=>n(!1),children:a("Done")})})]})})}var bt={},Ns,Va;function Rh(){return Va||(Va=1,Ns=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then}),Ns}var ks={},rt={},Ka;function xt(){if(Ka)return rt;Ka=1;let t;const s=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706];return rt.getSymbolSize=function(a){if(!a)throw new Error('"version" cannot be null or undefined');if(a<1||a>40)throw new Error('"version" should be in range from 1 to 40');return a*4+17},rt.getSymbolTotalCodewords=function(a){return s[a]},rt.getBCHDigit=function(n){let a=0;for(;n!==0;)a++,n>>>=1;return a},rt.setToSJISFunction=function(a){if(typeof a!="function")throw new Error('"toSJISFunc" is not a valid function.');t=a},rt.isKanjiModeEnabled=function(){return typeof t<"u"},rt.toSJIS=function(a){return t(a)},rt}var Cs={},qa;function Hn(){return qa||(qa=1,(function(t){t.L={bit:1},t.M={bit:0},t.Q={bit:3},t.H={bit:2};function s(n){if(typeof n!="string")throw new Error("Param is not a string");switch(n.toLowerCase()){case"l":case"low":return t.L;case"m":case"medium":return t.M;case"q":case"quartile":return t.Q;case"h":case"high":return t.H;default:throw new Error("Unknown EC Level: "+n)}}t.isValid=function(a){return a&&typeof a.bit<"u"&&a.bit>=0&&a.bit<4},t.from=function(a,r){if(t.isValid(a))return a;try{return s(a)}catch{return r}}})(Cs)),Cs}var Ss,Ga;function Oh(){if(Ga)return Ss;Ga=1;function t(){this.buffer=[],this.length=0}return t.prototype={get:function(s){const n=Math.floor(s/8);return(this.buffer[n]>>>7-s%8&1)===1},put:function(s,n){for(let a=0;a<n;a++)this.putBit((s>>>n-a-1&1)===1)},getLengthInBits:function(){return this.length},putBit:function(s){const n=Math.floor(this.length/8);this.buffer.length<=n&&this.buffer.push(0),s&&(this.buffer[n]|=128>>>this.length%8),this.length++}},Ss=t,Ss}var Is,Ha;function Dh(){if(Ha)return Is;Ha=1;function t(s){if(!s||s<1)throw new Error("BitMatrix size must be defined and greater than 0");this.size=s,this.data=new Uint8Array(s*s),this.reservedBit=new Uint8Array(s*s)}return t.prototype.set=function(s,n,a,r){const o=s*this.size+n;this.data[o]=a,r&&(this.reservedBit[o]=!0)},t.prototype.get=function(s,n){return this.data[s*this.size+n]},t.prototype.xor=function(s,n,a){this.data[s*this.size+n]^=a},t.prototype.isReserved=function(s,n){return this.reservedBit[s*this.size+n]},Is=t,Is}var As={},Wa;function Lh(){return Wa||(Wa=1,(function(t){const s=xt().getSymbolSize;t.getRowColCoords=function(a){if(a===1)return[];const r=Math.floor(a/7)+2,o=s(a),i=o===145?26:Math.ceil((o-13)/(2*r-2))*2,d=[o-7];for(let u=1;u<r-1;u++)d[u]=d[u-1]-i;return d.push(6),d.reverse()},t.getPositions=function(a){const r=[],o=t.getRowColCoords(a),i=o.length;for(let d=0;d<i;d++)for(let u=0;u<i;u++)d===0&&u===0||d===0&&u===i-1||d===i-1&&u===0||r.push([o[d],o[u]]);return r}})(As)),As}var Es={},Ya;function zh(){if(Ya)return Es;Ya=1;const t=xt().getSymbolSize,s=7;return Es.getPositions=function(a){const r=t(a);return[[0,0],[r-s,0],[0,r-s]]},Es}var Ms={},Ja;function _h(){return Ja||(Ja=1,(function(t){t.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};const s={N1:3,N2:3,N3:40,N4:10};t.isValid=function(r){return r!=null&&r!==""&&!isNaN(r)&&r>=0&&r<=7},t.from=function(r){return t.isValid(r)?parseInt(r,10):void 0},t.getPenaltyN1=function(r){const o=r.size;let i=0,d=0,u=0,x=null,h=null;for(let l=0;l<o;l++){d=u=0,x=h=null;for(let f=0;f<o;f++){let c=r.get(l,f);c===x?d++:(d>=5&&(i+=s.N1+(d-5)),x=c,d=1),c=r.get(f,l),c===h?u++:(u>=5&&(i+=s.N1+(u-5)),h=c,u=1)}d>=5&&(i+=s.N1+(d-5)),u>=5&&(i+=s.N1+(u-5))}return i},t.getPenaltyN2=function(r){const o=r.size;let i=0;for(let d=0;d<o-1;d++)for(let u=0;u<o-1;u++){const x=r.get(d,u)+r.get(d,u+1)+r.get(d+1,u)+r.get(d+1,u+1);(x===4||x===0)&&i++}return i*s.N2},t.getPenaltyN3=function(r){const o=r.size;let i=0,d=0,u=0;for(let x=0;x<o;x++){d=u=0;for(let h=0;h<o;h++)d=d<<1&2047|r.get(x,h),h>=10&&(d===1488||d===93)&&i++,u=u<<1&2047|r.get(h,x),h>=10&&(u===1488||u===93)&&i++}return i*s.N3},t.getPenaltyN4=function(r){let o=0;const i=r.data.length;for(let u=0;u<i;u++)o+=r.data[u];return Math.abs(Math.ceil(o*100/i/5)-10)*s.N4};function n(a,r,o){switch(a){case t.Patterns.PATTERN000:return(r+o)%2===0;case t.Patterns.PATTERN001:return r%2===0;case t.Patterns.PATTERN010:return o%3===0;case t.Patterns.PATTERN011:return(r+o)%3===0;case t.Patterns.PATTERN100:return(Math.floor(r/2)+Math.floor(o/3))%2===0;case t.Patterns.PATTERN101:return r*o%2+r*o%3===0;case t.Patterns.PATTERN110:return(r*o%2+r*o%3)%2===0;case t.Patterns.PATTERN111:return(r*o%3+(r+o)%2)%2===0;default:throw new Error("bad maskPattern:"+a)}}t.applyMask=function(r,o){const i=o.size;for(let d=0;d<i;d++)for(let u=0;u<i;u++)o.isReserved(u,d)||o.xor(u,d,n(r,u,d))},t.getBestMask=function(r,o){const i=Object.keys(t.Patterns).length;let d=0,u=1/0;for(let x=0;x<i;x++){o(x),t.applyMask(x,r);const h=t.getPenaltyN1(r)+t.getPenaltyN2(r)+t.getPenaltyN3(r)+t.getPenaltyN4(r);t.applyMask(x,r),h<u&&(u=h,d=x)}return d}})(Ms)),Ms}var Jt={},Qa;function pi(){if(Qa)return Jt;Qa=1;const t=Hn(),s=[1,1,1,1,1,1,1,1,1,1,2,2,1,2,2,4,1,2,4,4,2,4,4,4,2,4,6,5,2,4,6,6,2,5,8,8,4,5,8,8,4,5,8,11,4,8,10,11,4,9,12,16,4,9,16,16,6,10,12,18,6,10,17,16,6,11,16,19,6,13,18,21,7,14,21,25,8,16,20,25,8,17,23,25,9,17,23,34,9,18,25,30,10,20,27,32,12,21,29,35,12,23,34,37,12,25,34,40,13,26,35,42,14,28,38,45,15,29,40,48,16,31,43,51,17,33,45,54,18,35,48,57,19,37,51,60,19,38,53,63,20,40,56,66,21,43,59,70,22,45,62,74,24,47,65,77,25,49,68,81],n=[7,10,13,17,10,16,22,28,15,26,36,44,20,36,52,64,26,48,72,88,36,64,96,112,40,72,108,130,48,88,132,156,60,110,160,192,72,130,192,224,80,150,224,264,96,176,260,308,104,198,288,352,120,216,320,384,132,240,360,432,144,280,408,480,168,308,448,532,180,338,504,588,196,364,546,650,224,416,600,700,224,442,644,750,252,476,690,816,270,504,750,900,300,560,810,960,312,588,870,1050,336,644,952,1110,360,700,1020,1200,390,728,1050,1260,420,784,1140,1350,450,812,1200,1440,480,868,1290,1530,510,924,1350,1620,540,980,1440,1710,570,1036,1530,1800,570,1064,1590,1890,600,1120,1680,1980,630,1204,1770,2100,660,1260,1860,2220,720,1316,1950,2310,750,1372,2040,2430];return Jt.getBlocksCount=function(r,o){switch(o){case t.L:return s[(r-1)*4+0];case t.M:return s[(r-1)*4+1];case t.Q:return s[(r-1)*4+2];case t.H:return s[(r-1)*4+3];default:return}},Jt.getTotalCodewordsCount=function(r,o){switch(o){case t.L:return n[(r-1)*4+0];case t.M:return n[(r-1)*4+1];case t.Q:return n[(r-1)*4+2];case t.H:return n[(r-1)*4+3];default:return}},Jt}var Ps={},Tt={},Xa;function Bh(){if(Xa)return Tt;Xa=1;const t=new Uint8Array(512),s=new Uint8Array(256);return(function(){let a=1;for(let r=0;r<255;r++)t[r]=a,s[a]=r,a<<=1,a&256&&(a^=285);for(let r=255;r<512;r++)t[r]=t[r-255]})(),Tt.log=function(a){if(a<1)throw new Error("log("+a+")");return s[a]},Tt.exp=function(a){return t[a]},Tt.mul=function(a,r){return a===0||r===0?0:t[s[a]+s[r]]},Tt}var Za;function Fh(){return Za||(Za=1,(function(t){const s=Bh();t.mul=function(a,r){const o=new Uint8Array(a.length+r.length-1);for(let i=0;i<a.length;i++)for(let d=0;d<r.length;d++)o[i+d]^=s.mul(a[i],r[d]);return o},t.mod=function(a,r){let o=new Uint8Array(a);for(;o.length-r.length>=0;){const i=o[0];for(let u=0;u<r.length;u++)o[u]^=s.mul(r[u],i);let d=0;for(;d<o.length&&o[d]===0;)d++;o=o.slice(d)}return o},t.generateECPolynomial=function(a){let r=new Uint8Array([1]);for(let o=0;o<a;o++)r=t.mul(r,new Uint8Array([1,s.exp(o)]));return r}})(Ps)),Ps}var Ts,er;function Uh(){if(er)return Ts;er=1;const t=Fh();function s(n){this.genPoly=void 0,this.degree=n,this.degree&&this.initialize(this.degree)}return s.prototype.initialize=function(a){this.degree=a,this.genPoly=t.generateECPolynomial(this.degree)},s.prototype.encode=function(a){if(!this.genPoly)throw new Error("Encoder not initialized");const r=new Uint8Array(a.length+this.degree);r.set(a);const o=t.mod(r,this.genPoly),i=this.degree-o.length;if(i>0){const d=new Uint8Array(this.degree);return d.set(o,i),d}return o},Ts=s,Ts}var Rs={},Os={},Ds={},tr;function fi(){return tr||(tr=1,Ds.isValid=function(s){return!isNaN(s)&&s>=1&&s<=40}),Ds}var Ge={},sr;function gi(){if(sr)return Ge;sr=1;const t="[0-9]+",s="[A-Z $%*+\\-./:]+";let n="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";n=n.replace(/u/g,"\\u");const a="(?:(?![A-Z0-9 $%*+\\-./:]|"+n+`)(?:.|[\r
11
+ ]))+`;Ge.KANJI=new RegExp(n,"g"),Ge.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g"),Ge.BYTE=new RegExp(a,"g"),Ge.NUMERIC=new RegExp(t,"g"),Ge.ALPHANUMERIC=new RegExp(s,"g");const r=new RegExp("^"+n+"$"),o=new RegExp("^"+t+"$"),i=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");return Ge.testKanji=function(u){return r.test(u)},Ge.testNumeric=function(u){return o.test(u)},Ge.testAlphanumeric=function(u){return i.test(u)},Ge}var nr;function pt(){return nr||(nr=1,(function(t){const s=fi(),n=gi();t.NUMERIC={id:"Numeric",bit:1,ccBits:[10,12,14]},t.ALPHANUMERIC={id:"Alphanumeric",bit:2,ccBits:[9,11,13]},t.BYTE={id:"Byte",bit:4,ccBits:[8,16,16]},t.KANJI={id:"Kanji",bit:8,ccBits:[8,10,12]},t.MIXED={bit:-1},t.getCharCountIndicator=function(o,i){if(!o.ccBits)throw new Error("Invalid mode: "+o);if(!s.isValid(i))throw new Error("Invalid version: "+i);return i>=1&&i<10?o.ccBits[0]:i<27?o.ccBits[1]:o.ccBits[2]},t.getBestModeForData=function(o){return n.testNumeric(o)?t.NUMERIC:n.testAlphanumeric(o)?t.ALPHANUMERIC:n.testKanji(o)?t.KANJI:t.BYTE},t.toString=function(o){if(o&&o.id)return o.id;throw new Error("Invalid mode")},t.isValid=function(o){return o&&o.bit&&o.ccBits};function a(r){if(typeof r!="string")throw new Error("Param is not a string");switch(r.toLowerCase()){case"numeric":return t.NUMERIC;case"alphanumeric":return t.ALPHANUMERIC;case"kanji":return t.KANJI;case"byte":return t.BYTE;default:throw new Error("Unknown mode: "+r)}}t.from=function(o,i){if(t.isValid(o))return o;try{return a(o)}catch{return i}}})(Os)),Os}var ar;function $h(){return ar||(ar=1,(function(t){const s=xt(),n=pi(),a=Hn(),r=pt(),o=fi(),i=7973,d=s.getBCHDigit(i);function u(f,c,p){for(let g=1;g<=40;g++)if(c<=t.getCapacity(g,p,f))return g}function x(f,c){return r.getCharCountIndicator(f,c)+4}function h(f,c){let p=0;return f.forEach(function(g){const w=x(g.mode,c);p+=w+g.getBitsLength()}),p}function l(f,c){for(let p=1;p<=40;p++)if(h(f,p)<=t.getCapacity(p,c,r.MIXED))return p}t.from=function(c,p){return o.isValid(c)?parseInt(c,10):p},t.getCapacity=function(c,p,g){if(!o.isValid(c))throw new Error("Invalid QR Code version");typeof g>"u"&&(g=r.BYTE);const w=s.getSymbolTotalCodewords(c),k=n.getTotalCodewordsCount(c,p),j=(w-k)*8;if(g===r.MIXED)return j;const y=j-x(g,c);switch(g){case r.NUMERIC:return Math.floor(y/10*3);case r.ALPHANUMERIC:return Math.floor(y/11*2);case r.KANJI:return Math.floor(y/13);case r.BYTE:default:return Math.floor(y/8)}},t.getBestVersionForData=function(c,p){let g;const w=a.from(p,a.M);if(Array.isArray(c)){if(c.length>1)return l(c,w);if(c.length===0)return 1;g=c[0]}else g=c;return u(g.mode,g.getLength(),w)},t.getEncodedBits=function(c){if(!o.isValid(c)||c<7)throw new Error("Invalid QR Code version");let p=c<<12;for(;s.getBCHDigit(p)-d>=0;)p^=i<<s.getBCHDigit(p)-d;return c<<12|p}})(Rs)),Rs}var Ls={},rr;function Vh(){if(rr)return Ls;rr=1;const t=xt(),s=1335,n=21522,a=t.getBCHDigit(s);return Ls.getEncodedBits=function(o,i){const d=o.bit<<3|i;let u=d<<10;for(;t.getBCHDigit(u)-a>=0;)u^=s<<t.getBCHDigit(u)-a;return(d<<10|u)^n},Ls}var zs={},_s,or;function Kh(){if(or)return _s;or=1;const t=pt();function s(n){this.mode=t.NUMERIC,this.data=n.toString()}return s.getBitsLength=function(a){return 10*Math.floor(a/3)+(a%3?a%3*3+1:0)},s.prototype.getLength=function(){return this.data.length},s.prototype.getBitsLength=function(){return s.getBitsLength(this.data.length)},s.prototype.write=function(a){let r,o,i;for(r=0;r+3<=this.data.length;r+=3)o=this.data.substr(r,3),i=parseInt(o,10),a.put(i,10);const d=this.data.length-r;d>0&&(o=this.data.substr(r),i=parseInt(o,10),a.put(i,d*3+1))},_s=s,_s}var Bs,ir;function qh(){if(ir)return Bs;ir=1;const t=pt(),s=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"," ","$","%","*","+","-",".","/",":"];function n(a){this.mode=t.ALPHANUMERIC,this.data=a}return n.getBitsLength=function(r){return 11*Math.floor(r/2)+6*(r%2)},n.prototype.getLength=function(){return this.data.length},n.prototype.getBitsLength=function(){return n.getBitsLength(this.data.length)},n.prototype.write=function(r){let o;for(o=0;o+2<=this.data.length;o+=2){let i=s.indexOf(this.data[o])*45;i+=s.indexOf(this.data[o+1]),r.put(i,11)}this.data.length%2&&r.put(s.indexOf(this.data[o]),6)},Bs=n,Bs}var Fs,lr;function Gh(){if(lr)return Fs;lr=1;const t=pt();function s(n){this.mode=t.BYTE,typeof n=="string"?this.data=new TextEncoder().encode(n):this.data=new Uint8Array(n)}return s.getBitsLength=function(a){return a*8},s.prototype.getLength=function(){return this.data.length},s.prototype.getBitsLength=function(){return s.getBitsLength(this.data.length)},s.prototype.write=function(n){for(let a=0,r=this.data.length;a<r;a++)n.put(this.data[a],8)},Fs=s,Fs}var Us,cr;function Hh(){if(cr)return Us;cr=1;const t=pt(),s=xt();function n(a){this.mode=t.KANJI,this.data=a}return n.getBitsLength=function(r){return r*13},n.prototype.getLength=function(){return this.data.length},n.prototype.getBitsLength=function(){return n.getBitsLength(this.data.length)},n.prototype.write=function(a){let r;for(r=0;r<this.data.length;r++){let o=s.toSJIS(this.data[r]);if(o>=33088&&o<=40956)o-=33088;else if(o>=57408&&o<=60351)o-=49472;else throw new Error("Invalid SJIS character: "+this.data[r]+`
12
+ Make sure your charset is UTF-8`);o=(o>>>8&255)*192+(o&255),a.put(o,13)}},Us=n,Us}var $s={exports:{}},dr;function Wh(){return dr||(dr=1,(function(t){var s={single_source_shortest_paths:function(n,a,r){var o={},i={};i[a]=0;var d=s.PriorityQueue.make();d.push(a,0);for(var u,x,h,l,f,c,p,g,w;!d.empty();){u=d.pop(),x=u.value,l=u.cost,f=n[x]||{};for(h in f)f.hasOwnProperty(h)&&(c=f[h],p=l+c,g=i[h],w=typeof i[h]>"u",(w||g>p)&&(i[h]=p,d.push(h,p),o[h]=x))}if(typeof r<"u"&&typeof i[r]>"u"){var k=["Could not find a path from ",a," to ",r,"."].join("");throw new Error(k)}return o},extract_shortest_path_from_predecessor_list:function(n,a){for(var r=[],o=a;o;)r.push(o),n[o],o=n[o];return r.reverse(),r},find_path:function(n,a,r){var o=s.single_source_shortest_paths(n,a,r);return s.extract_shortest_path_from_predecessor_list(o,r)},PriorityQueue:{make:function(n){var a=s.PriorityQueue,r={},o;n=n||{};for(o in a)a.hasOwnProperty(o)&&(r[o]=a[o]);return r.queue=[],r.sorter=n.sorter||a.default_sorter,r},default_sorter:function(n,a){return n.cost-a.cost},push:function(n,a){var r={value:n,cost:a};this.queue.push(r),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return this.queue.length===0}}};t.exports=s})($s)),$s.exports}var ur;function Yh(){return ur||(ur=1,(function(t){const s=pt(),n=Kh(),a=qh(),r=Gh(),o=Hh(),i=gi(),d=xt(),u=Wh();function x(k){return unescape(encodeURIComponent(k)).length}function h(k,j,y){const N=[];let A;for(;(A=k.exec(y))!==null;)N.push({data:A[0],index:A.index,mode:j,length:A[0].length});return N}function l(k){const j=h(i.NUMERIC,s.NUMERIC,k),y=h(i.ALPHANUMERIC,s.ALPHANUMERIC,k);let N,A;return d.isKanjiModeEnabled()?(N=h(i.BYTE,s.BYTE,k),A=h(i.KANJI,s.KANJI,k)):(N=h(i.BYTE_KANJI,s.BYTE,k),A=[]),j.concat(y,N,A).sort(function(I,L){return I.index-L.index}).map(function(I){return{data:I.data,mode:I.mode,length:I.length}})}function f(k,j){switch(j){case s.NUMERIC:return n.getBitsLength(k);case s.ALPHANUMERIC:return a.getBitsLength(k);case s.KANJI:return o.getBitsLength(k);case s.BYTE:return r.getBitsLength(k)}}function c(k){return k.reduce(function(j,y){const N=j.length-1>=0?j[j.length-1]:null;return N&&N.mode===y.mode?(j[j.length-1].data+=y.data,j):(j.push(y),j)},[])}function p(k){const j=[];for(let y=0;y<k.length;y++){const N=k[y];switch(N.mode){case s.NUMERIC:j.push([N,{data:N.data,mode:s.ALPHANUMERIC,length:N.length},{data:N.data,mode:s.BYTE,length:N.length}]);break;case s.ALPHANUMERIC:j.push([N,{data:N.data,mode:s.BYTE,length:N.length}]);break;case s.KANJI:j.push([N,{data:N.data,mode:s.BYTE,length:x(N.data)}]);break;case s.BYTE:j.push([{data:N.data,mode:s.BYTE,length:x(N.data)}])}}return j}function g(k,j){const y={},N={start:{}};let A=["start"];for(let O=0;O<k.length;O++){const I=k[O],L=[];for(let C=0;C<I.length;C++){const E=I[C],M=""+O+C;L.push(M),y[M]={node:E,lastCount:0},N[M]={};for(let V=0;V<A.length;V++){const F=A[V];y[F]&&y[F].node.mode===E.mode?(N[F][M]=f(y[F].lastCount+E.length,E.mode)-f(y[F].lastCount,E.mode),y[F].lastCount+=E.length):(y[F]&&(y[F].lastCount=E.length),N[F][M]=f(E.length,E.mode)+4+s.getCharCountIndicator(E.mode,j))}}A=L}for(let O=0;O<A.length;O++)N[A[O]].end=0;return{map:N,table:y}}function w(k,j){let y;const N=s.getBestModeForData(k);if(y=s.from(j,N),y!==s.BYTE&&y.bit<N.bit)throw new Error('"'+k+'" cannot be encoded with mode '+s.toString(y)+`.
13
+ Suggested mode is: `+s.toString(N));switch(y===s.KANJI&&!d.isKanjiModeEnabled()&&(y=s.BYTE),y){case s.NUMERIC:return new n(k);case s.ALPHANUMERIC:return new a(k);case s.KANJI:return new o(k);case s.BYTE:return new r(k)}}t.fromArray=function(j){return j.reduce(function(y,N){return typeof N=="string"?y.push(w(N,null)):N.data&&y.push(w(N.data,N.mode)),y},[])},t.fromString=function(j,y){const N=l(j,d.isKanjiModeEnabled()),A=p(N),O=g(A,y),I=u.find_path(O.map,"start","end"),L=[];for(let C=1;C<I.length-1;C++)L.push(O.table[I[C]].node);return t.fromArray(c(L))},t.rawSplit=function(j){return t.fromArray(l(j,d.isKanjiModeEnabled()))}})(zs)),zs}var mr;function Jh(){if(mr)return ks;mr=1;const t=xt(),s=Hn(),n=Oh(),a=Dh(),r=Lh(),o=zh(),i=_h(),d=pi(),u=Uh(),x=$h(),h=Vh(),l=pt(),f=Yh();function c(O,I){const L=O.size,C=o.getPositions(I);for(let E=0;E<C.length;E++){const M=C[E][0],V=C[E][1];for(let F=-1;F<=7;F++)if(!(M+F<=-1||L<=M+F))for(let b=-1;b<=7;b++)V+b<=-1||L<=V+b||(F>=0&&F<=6&&(b===0||b===6)||b>=0&&b<=6&&(F===0||F===6)||F>=2&&F<=4&&b>=2&&b<=4?O.set(M+F,V+b,!0,!0):O.set(M+F,V+b,!1,!0))}}function p(O){const I=O.size;for(let L=8;L<I-8;L++){const C=L%2===0;O.set(L,6,C,!0),O.set(6,L,C,!0)}}function g(O,I){const L=r.getPositions(I);for(let C=0;C<L.length;C++){const E=L[C][0],M=L[C][1];for(let V=-2;V<=2;V++)for(let F=-2;F<=2;F++)V===-2||V===2||F===-2||F===2||V===0&&F===0?O.set(E+V,M+F,!0,!0):O.set(E+V,M+F,!1,!0)}}function w(O,I){const L=O.size,C=x.getEncodedBits(I);let E,M,V;for(let F=0;F<18;F++)E=Math.floor(F/3),M=F%3+L-8-3,V=(C>>F&1)===1,O.set(E,M,V,!0),O.set(M,E,V,!0)}function k(O,I,L){const C=O.size,E=h.getEncodedBits(I,L);let M,V;for(M=0;M<15;M++)V=(E>>M&1)===1,M<6?O.set(M,8,V,!0):M<8?O.set(M+1,8,V,!0):O.set(C-15+M,8,V,!0),M<8?O.set(8,C-M-1,V,!0):M<9?O.set(8,15-M-1+1,V,!0):O.set(8,15-M-1,V,!0);O.set(C-8,8,1,!0)}function j(O,I){const L=O.size;let C=-1,E=L-1,M=7,V=0;for(let F=L-1;F>0;F-=2)for(F===6&&F--;;){for(let b=0;b<2;b++)if(!O.isReserved(E,F-b)){let B=!1;V<I.length&&(B=(I[V]>>>M&1)===1),O.set(E,F-b,B),M--,M===-1&&(V++,M=7)}if(E+=C,E<0||L<=E){E-=C,C=-C;break}}}function y(O,I,L){const C=new n;L.forEach(function(b){C.put(b.mode.bit,4),C.put(b.getLength(),l.getCharCountIndicator(b.mode,O)),b.write(C)});const E=t.getSymbolTotalCodewords(O),M=d.getTotalCodewordsCount(O,I),V=(E-M)*8;for(C.getLengthInBits()+4<=V&&C.put(0,4);C.getLengthInBits()%8!==0;)C.putBit(0);const F=(V-C.getLengthInBits())/8;for(let b=0;b<F;b++)C.put(b%2?17:236,8);return N(C,O,I)}function N(O,I,L){const C=t.getSymbolTotalCodewords(I),E=d.getTotalCodewordsCount(I,L),M=C-E,V=d.getBlocksCount(I,L),F=C%V,b=V-F,B=Math.floor(C/V),K=Math.floor(M/V),D=K+1,$=B-K,Y=new u($);let H=0;const se=new Array(V),q=new Array(V);let Q=0;const _=new Uint8Array(O.buffer);for(let xe=0;xe<V;xe++){const Pe=xe<b?K:D;se[xe]=_.slice(H,H+Pe),q[xe]=Y.encode(se[xe]),H+=Pe,Q=Math.max(Q,Pe)}const ne=new Uint8Array(C);let R=0,P,ce;for(P=0;P<Q;P++)for(ce=0;ce<V;ce++)P<se[ce].length&&(ne[R++]=se[ce][P]);for(P=0;P<$;P++)for(ce=0;ce<V;ce++)ne[R++]=q[ce][P];return ne}function A(O,I,L,C){let E;if(Array.isArray(O))E=f.fromArray(O);else if(typeof O=="string"){let B=I;if(!B){const K=f.rawSplit(O);B=x.getBestVersionForData(K,L)}E=f.fromString(O,B||40)}else throw new Error("Invalid data");const M=x.getBestVersionForData(E,L);if(!M)throw new Error("The amount of data is too big to be stored in a QR Code");if(!I)I=M;else if(I<M)throw new Error(`
14
14
  The chosen QR Code version cannot contain this amount of data.
15
15
  Minimum version required to store current data is: `+M+`.
16
- `);const V=y(I,L,E),F=t.getSymbolSize(I),b=new a(F);return c(b,I),p(b),g(b,I),k(b,L,0),I>=7&&w(b,I),j(b,V),isNaN(C)&&(C=i.getBestMask(b,k.bind(null,b,L))),i.applyMask(C,b),k(b,L,C),{modules:b,version:I,errorCorrectionLevel:L,maskPattern:C,segments:E}}return ks.create=function(I,L){if(typeof I>"u"||I==="")throw new Error("No input text");let C=s.M,E,M;return typeof L<"u"&&(C=s.from(L.errorCorrectionLevel,s.M),E=x.from(L.version),M=i.from(L.maskPattern),L.toSJISFunc&&t.setToSJISFunction(L.toSJISFunc)),A(I,E,C,M)},ks}var Vs={},Ks={},hr;function ji(){return hr||(hr=1,(function(t){function s(n){if(typeof n=="number"&&(n=n.toString()),typeof n!="string")throw new Error("Color should be defined as hex string");let a=n.slice().replace("#","").split("");if(a.length<3||a.length===5||a.length>8)throw new Error("Invalid hex color: "+n);(a.length===3||a.length===4)&&(a=Array.prototype.concat.apply([],a.map(function(o){return[o,o]}))),a.length===6&&a.push("F","F");const r=parseInt(a.join(""),16);return{r:r>>24&255,g:r>>16&255,b:r>>8&255,a:r&255,hex:"#"+a.slice(0,6).join("")}}t.getOptions=function(a){a||(a={}),a.color||(a.color={});const r=typeof a.margin>"u"||a.margin===null||a.margin<0?4:a.margin,o=a.width&&a.width>=21?a.width:void 0,i=a.scale||4;return{width:o,scale:o?4:i,margin:r,color:{dark:s(a.color.dark||"#000000ff"),light:s(a.color.light||"#ffffffff")},type:a.type,rendererOpts:a.rendererOpts||{}}},t.getScale=function(a,r){return r.width&&r.width>=a+r.margin*2?r.width/(a+r.margin*2):r.scale},t.getImageWidth=function(a,r){const o=t.getScale(a,r);return Math.floor((a+r.margin*2)*o)},t.qrToImageData=function(a,r,o){const i=r.modules.size,d=r.modules.data,u=t.getScale(i,o),x=Math.floor((i+o.margin*2)*u),h=o.margin*u,l=[o.color.light,o.color.dark];for(let f=0;f<x;f++)for(let c=0;c<x;c++){let p=(f*x+c)*4,g=o.color.light;if(f>=h&&c>=h&&f<x-h&&c<x-h){const w=Math.floor((f-h)/u),k=Math.floor((c-h)/u);g=l[d[w*i+k]?1:0]}a[p++]=g.r,a[p++]=g.g,a[p++]=g.b,a[p]=g.a}}})(Ks)),Ks}var xr;function Yh(){return xr||(xr=1,(function(t){const s=ji();function n(r,o,i){r.clearRect(0,0,o.width,o.height),o.style||(o.style={}),o.height=i,o.width=i,o.style.height=i+"px",o.style.width=i+"px"}function a(){try{return document.createElement("canvas")}catch{throw new Error("You need to specify a canvas element")}}t.render=function(o,i,d){let u=d,x=i;typeof u>"u"&&(!i||!i.getContext)&&(u=i,i=void 0),i||(x=a()),u=s.getOptions(u);const h=s.getImageWidth(o.modules.size,u),l=x.getContext("2d"),f=l.createImageData(h,h);return s.qrToImageData(f.data,o,u),n(l,x,h),l.putImageData(f,0,0),x},t.renderToDataURL=function(o,i,d){let u=d;typeof u>"u"&&(!i||!i.getContext)&&(u=i,i=void 0),u||(u={});const x=t.render(o,i,u),h=u.type||"image/png",l=u.rendererOpts||{};return x.toDataURL(h,l.quality)}})(Vs)),Vs}var qs={},pr;function Jh(){if(pr)return qs;pr=1;const t=ji();function s(r,o){const i=r.a/255,d=o+'="'+r.hex+'"';return i<1?d+" "+o+'-opacity="'+i.toFixed(2).slice(1)+'"':d}function n(r,o,i){let d=r+o;return typeof i<"u"&&(d+=" "+i),d}function a(r,o,i){let d="",u=0,x=!1,h=0;for(let l=0;l<r.length;l++){const f=Math.floor(l%o),c=Math.floor(l/o);!f&&!x&&(x=!0),r[l]?(h++,l>0&&f>0&&r[l-1]||(d+=x?n("M",f+i,.5+c+i):n("m",u,0),u=0,x=!1),f+1<o&&r[l+1]||(d+=n("h",h),h=0)):u++}return d}return qs.render=function(o,i,d){const u=t.getOptions(i),x=o.modules.size,h=o.modules.data,l=x+u.margin*2,f=u.color.light.a?"<path "+s(u.color.light,"fill")+' d="M0 0h'+l+"v"+l+'H0z"/>':"",c="<path "+s(u.color.dark,"stroke")+' d="'+a(h,x,u.margin)+'"/>',p='viewBox="0 0 '+l+" "+l+'"',w='<svg xmlns="http://www.w3.org/2000/svg" '+(u.width?'width="'+u.width+'" height="'+u.width+'" ':"")+p+' shape-rendering="crispEdges">'+f+c+`</svg>
17
- `;return typeof d=="function"&&d(null,w),w},qs}var fr;function Qh(){if(fr)return bt;fr=1;const t=Ph(),s=Wh(),n=Yh(),a=Jh();function r(o,i,d,u,x){const h=[].slice.call(arguments,1),l=h.length,f=typeof h[l-1]=="function";if(!f&&!t())throw new Error("Callback required as last argument");if(f){if(l<2)throw new Error("Too few arguments provided");l===2?(x=d,d=i,i=u=void 0):l===3&&(i.getContext&&typeof x>"u"?(x=u,u=void 0):(x=u,u=d,d=i,i=void 0))}else{if(l<1)throw new Error("Too few arguments provided");return l===1?(d=i,i=u=void 0):l===2&&!i.getContext&&(u=d,d=i,i=void 0),new Promise(function(c,p){try{const g=s.create(d,u);c(o(g,i,u))}catch(g){p(g)}})}try{const c=s.create(d,u);x(null,o(c,i,u))}catch(c){x(c)}}return bt.create=s.create,bt.toCanvas=r.bind(null,n.render),bt.toDataURL=r.bind(null,n.renderToDataURL),bt.toString=r.bind(null,function(o,i,d){return a.render(o,d)}),bt}var Xh=Qh();const Zh=Ec(Xh);function ex(){return e.jsxs("div",{className:"space-y-10",children:[e.jsx(tx,{}),!window.electronAPI.remote&&e.jsx(sx,{}),e.jsx(rx,{})]})}function tx(){const{t}=z(),[s,n]=m.useState(null),[a,r]=m.useState(null),[o,i]=m.useState(!1),[d,u]=m.useState(null),[x,h]=m.useState(null),[l,f]=m.useState(!1),c=s?.pairingExpiresAt;m.useEffect(()=>{if(!c){h(null);return}const k=()=>h(Math.max(0,Math.ceil((c-Date.now())/1e3)));k();const j=setInterval(k,1e3);return()=>clearInterval(j)},[c]);const p=k=>{navigator.clipboard.writeText(k).then(()=>{f(!0),setTimeout(()=>f(!1),1500)})};m.useEffect(()=>(window.electronAPI.pair.status().then(n),window.electronAPI.pair.onStatusChanged(k=>{n(k),(k.pairing||k.devices.length>0)&&u(null)})),[]),m.useEffect(()=>{const k=s?.inviteUri;if(!k){r(null);return}Zh.toDataURL(k,{width:320,margin:1}).then(r).catch(()=>{})},[s?.inviteUri]);const g=async()=>{i(!0),u(null);const k=await window.electronAPI.pair.start();i(!1),k.ok||u(k.error??t("Failed to start pairing"))},w=s?.devices??[];return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-end justify-between gap-4","data-settings-row":"phone.root",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-medium text-lg",children:t("Allow connections")}),e.jsx("p",{className:"text-muted-foreground text-sm",children:t("Let your phone or another EnsoCode desktop connect to this computer. Keep this app running.")})]}),e.jsx("div",{className:"flex shrink-0 items-center gap-2",children:s?.pairing?e.jsx(S,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.pair.cancel()},children:t("Cancel pairing")}):e.jsxs(S,{variant:"outline",size:"sm",disabled:o,onClick:()=>{g()},children:[o?e.jsx(Ae,{className:"mr-1.5 h-4 w-4 animate-spin"}):e.jsx(un,{className:"mr-1.5 h-4 w-4"}),t("Generate pairing code")]})})]}),s&&!s.secureStorage&&e.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-dashed px-3 py-2 text-xs",children:[e.jsx(Ue,{className:"mt-0.5 h-4 w-4 shrink-0 text-destructive"}),e.jsx("span",{className:"text-muted-foreground",children:t("Secure storage is unavailable on this system, so pairing keys are stored unencrypted.")})]}),d&&e.jsx("p",{className:"text-destructive text-xs",children:d}),s?.pairing&&e.jsxs("div",{className:"space-y-3 rounded-md border border-dashed px-3 py-6",children:[e.jsxs("div",{className:"text-center",children:[a?e.jsx("img",{src:a,alt:t("Pairing QR code"),className:"mx-auto h-52 w-52"}):e.jsx(Ae,{className:"mx-auto h-5 w-5 animate-spin text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:t("Scan with your phone camera")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:t("Scanning opens the app and pairs it. To keep it handy, add it to your home screen.")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:t("On another EnsoCode desktop, paste the link below into Settings → Devices → Connect to a node.")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:x===null?t("The code expires in 60 seconds and can only be used once."):x>0?t("Expires in {{seconds}}s · single use",{seconds:x}):t("Code expired")})]}),s.inviteUri&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"min-w-0 flex-1 truncate rounded bg-muted px-2 py-1.5 font-mono text-[11px] text-muted-foreground",children:s.inviteUri}),e.jsxs(S,{variant:"outline",size:"sm",className:"shrink-0",onClick:()=>p(s.inviteUri),children:[l?e.jsx(Eo,{className:"mr-1.5 h-3.5 w-3.5"}):e.jsx(No,{className:"mr-1.5 h-3.5 w-3.5"}),t(l?"Copied":"Copy")]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"font-medium text-sm",children:t("Paired devices")}),w.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx(un,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:t("No paired devices")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:t("Generate a pairing code to let a phone or another desktop connect.")})]}):e.jsx("div",{className:"space-y-1",children:w.map(k=>e.jsx(nx,{device:k},k.pairId))})]})]})}function sx(){const{t}=z(),s=Ht(i=>i.nodes),n=Ht(i=>i.secureStorage),a=Ht(i=>i.refresh),[r,o]=m.useState(!1);return m.useEffect(()=>Ht.getState().bind(),[]),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-end justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-medium text-lg",children:t("Connect to a node")}),e.jsx("p",{className:"text-muted-foreground text-sm",children:t("Browse and drive conversations on another EnsoCode desktop. Its agent, keys and history stay there.")})]}),e.jsxs(S,{variant:"outline",size:"sm",className:"shrink-0",onClick:()=>o(!0),children:[e.jsx(Oe,{className:"mr-1.5 h-4 w-4"}),t("Connect to a node")]})]}),!n&&e.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-dashed px-3 py-2 text-xs",children:[e.jsx(Ue,{className:"mt-0.5 h-4 w-4 shrink-0 text-destructive"}),e.jsx("span",{className:"text-muted-foreground",children:t("Secure storage is unavailable on this system, so pairing keys are stored unencrypted.")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"font-medium text-sm",children:t("Connected nodes")}),s.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx(Ln,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:t("No connected nodes")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:t("Each connecting computer needs its own pairing code from the other desktop.")})]}):e.jsx("div",{className:"space-y-1",children:s.map(i=>e.jsx(ax,{node:i,onChanged:()=>{a()}},i.nodeId))})]}),e.jsx(Mc,{open:r,onOpenChange:o,switchOnSuccess:!1})]})}function vi({transport:t,rttMs:s}){const{t:n}=z(),a=t==="direct",r=Tc(s);return e.jsxs("span",{className:G("shrink-0 rounded px-1.5 py-0.5 text-[10px] leading-none",a?"bg-emerald-500/15 text-emerald-600":"bg-muted text-muted-foreground"),children:[n(a?"Direct link":"Via relay"),r?` · ${r}`:""]})}function nx({device:t}){const{t:s}=z(),[n,a]=m.useState(null),r=async()=>{n!==null&&(n.trim()&&n.trim()!==t.deviceName&&await window.electronAPI.pair.rename(t.pairId,n),a(null))};return e.jsxs("div",{className:"group flex items-center justify-between gap-3 rounded-md px-3 py-2 transition-colors hover:bg-accent/50",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[e.jsx("span",{className:G("h-2 w-2 shrink-0 rounded-full",t.phoneOnline?"bg-emerald-500":t.connected?"bg-amber-500":"bg-muted-foreground/40")}),n===null?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"truncate font-medium text-sm",children:t.deviceName}),e.jsx("span",{className:"shrink-0 text-muted-foreground text-xs",children:t.phoneOnline?s("Online"):t.connected?s("Waiting for device"):s("Offline")}),t.phoneOnline&&e.jsx(vi,{transport:t.transport,rttMs:t.rttMs}),e.jsx("button",{type:"button",title:s("Click to switch: view-only devices cannot send, approve or stop."),onClick:()=>{window.electronAPI.pair.setScope(t.pairId,t.scope==="read"?"operate":"read")},className:G("shrink-0 rounded px-1.5 py-0.5 text-[10px] leading-none transition-colors",t.scope==="read"?"bg-amber-500/15 text-amber-600 hover:bg-amber-500/25":"bg-muted text-muted-foreground hover:bg-accent"),children:t.scope==="read"?s("View only"):s("Can operate")})]}):e.jsx(J,{value:n,autoFocus:!0,onChange:o=>a(o.target.value),onBlur:()=>{r()},onKeyDown:o=>{o.key==="Enter"&&r(),o.key==="Escape"&&a(null)},className:"h-7 text-sm"})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1 opacity-0 transition-opacity group-hover:opacity-100",children:[e.jsx(S,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground",title:s("Rename"),onClick:()=>a(t.deviceName),children:e.jsx(lt,{className:"h-3.5 w-3.5"})}),e.jsx(S,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-destructive",onClick:()=>{window.electronAPI.pair.revoke(t.pairId)},children:e.jsx(Me,{className:"h-3.5 w-3.5"})})]})]})}function ax({node:t,onChanged:s}){const{t:n}=z(),[a,r]=m.useState(null),o=async()=>{a!==null&&(a.trim()&&a.trim()!==t.label&&(await window.electronAPI.nodes.rename(t.nodeId,a),s()),r(null))};return e.jsxs("div",{className:"group flex items-center justify-between gap-3 rounded-md px-3 py-2 transition-colors hover:bg-accent/50",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[e.jsx(Pc,{node:t}),a===null?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"truncate font-medium text-sm",children:t.label}),t.hostname&&t.hostname!==t.label&&e.jsx("span",{className:"shrink-0 truncate font-mono text-[10px] text-muted-foreground",children:t.hostname}),e.jsx("span",{className:"shrink-0 text-muted-foreground text-xs",children:t.hostOnline?n("Online"):t.connected?n("Remote desktop is offline"):n("Offline")}),t.hostOnline&&e.jsx(vi,{transport:t.transport,rttMs:t.rttMs})]}):e.jsx(J,{value:a,autoFocus:!0,onChange:i=>r(i.target.value),onBlur:()=>{o()},onKeyDown:i=>{i.key==="Enter"&&o(),i.key==="Escape"&&r(null)},className:"h-7 text-sm"})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1 opacity-0 transition-opacity group-hover:opacity-100",children:[e.jsx(S,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground",title:n("Rename"),onClick:()=>r(t.label),children:e.jsx(lt,{className:"h-3.5 w-3.5"})}),e.jsx(S,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-destructive",title:n("Disconnect"),onClick:()=>{window.electronAPI.nodes.remove(t.nodeId).then(s)},children:e.jsx(Me,{className:"h-3.5 w-3.5"})})]})]})}function rx(){const{t}=z(),[s,n]=m.useState(null),[a,r]=m.useState(null);m.useEffect(()=>(window.electronAPI.pair.status().then(n),window.electronAPI.pair.onStatusChanged(n)),[]);const o=async()=>{a!==null&&(n(await window.electronAPI.pair.setRelayUrl(a)),r(null))};return e.jsx("div",{className:"space-y-6",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"font-medium text-sm",children:t("Relay server")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("The relay only forwards encrypted frames and cannot read your messages.")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(J,{value:a??s?.relayUrl??"",onChange:i=>r(i.target.value),placeholder:"https://relay.example.com",className:"font-mono text-xs"}),a===null?e.jsx(S,{variant:"ghost",size:"icon",className:"h-8 w-8 shrink-0 text-muted-foreground",onClick:()=>r(s?.relayUrl??""),children:e.jsx(lt,{className:"h-3.5 w-3.5"})}):e.jsxs(S,{size:"sm",className:"shrink-0",onClick:()=>{o()},children:[e.jsx(Eo,{className:"mr-1.5 h-3.5 w-3.5"}),t("Save")]})]})]})})}function ox({onOpenBots:t}){const{t:s}=z(),n=v(i=>i.botModeEnabled),a=v(i=>i.setBotModeEnabled),r=v(i=>i.scratchSessionsEnabled),o=v(i=>i.setScratchSessionsEnabled);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("Experimental")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("Features still being tested. They may change or be removed.")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Te,{rowId:"experimental.botMode",title:s("Bot mode"),description:s("Adds a Code | Bot switch to the sidebar. Create members with their own persona, model and tools, and chat with them alone or in groups."),checked:n,onChange:a}),n&&e.jsx(S,{variant:"outline",size:"sm",onClick:t,children:s("Bot mode settings")}),e.jsx(Te,{rowId:"experimental.scratchSessions",title:s("Temporary chats"),description:s("Chats that are not tied to a project. Tools follow your global settings."),checked:r,onChange:o})]})]})}function ix({instruction:t,onClose:s}){const{t:n}=z(),a=v(I=>I.addInstructions),r=v(I=>I.updateInstruction),o=t==="new",i=o||!t?null:t,[d,u]=m.useState(""),[x,h]=m.useState(""),[l,f]=m.useState(!1),[c,p]=m.useState(!1),[g,w]=m.useState(null),[k,j]=m.useState(!1),[y,N]=m.useState(!1);m.useEffect(()=>{if(t){if(t==="new"){u(""),h(""),j(!1),w(null),N(!1),f(!1);return}u(t.name),j(!1),w(null),N(!1),f(!0),window.electronAPI.instructions.read(t.id,t.local,t.sourcePath).then(I=>{I.ok?h(I.content):(h(""),w(I.error??n("Failed to read content")))}).finally(()=>f(!1))}},[t,n]);const A=!!(i&&!i.local&&i.sourcePath),O=async()=>{if(!t||!d.trim())return;if(p(!0),o){const L=crypto.randomUUID(),C=await window.electronAPI.instructions.write(L,x);if(!C.ok){p(!1),w(n("Failed to save"));return}const E=a([{id:L,name:d.trim(),source:"Manual",local:!0,bytes:C.bytes,enabled:!0}]);if(p(!1),E===0){window.electronAPI.instructions.delete(L),w(n("An instruction with this name already exists"));return}s();return}if(!i){p(!1);return}if(A&&y&&i.sourcePath){const L=await window.electronAPI.instructions.writeSource(i.id,i.sourcePath,x);if(p(!1),!L.ok){w(L.error??n("Failed to save"));return}r(i.id,{name:d.trim(),bytes:L.bytes}),s();return}const I=await window.electronAPI.instructions.write(i.id,x);if(p(!1),!I.ok){w(n("Failed to save"));return}r(i.id,{name:d.trim(),local:!0,bytes:I.bytes}),s()};return e.jsx(pe,{open:t!==null,onOpenChange:I=>!I&&s(),children:e.jsxs(fe,{className:"max-w-2xl",children:[e.jsx(ge,{children:e.jsx(je,{children:n(o?"Add Instruction":"Edit Instruction")})}),e.jsxs(we,{className:"space-y-4",children:[o?null:A?e.jsxs("div",{className:G("w-full rounded-md border px-3 py-2.5 transition-colors",y?"border-destructive/32 bg-destructive/8":"border-amber-500/32 bg-amber-500/8"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[y?e.jsx(Ue,{className:"h-3.5 w-3.5 shrink-0 text-destructive"}):e.jsx(ss,{className:"h-3.5 w-3.5 shrink-0 text-amber-600 dark:text-amber-500"}),e.jsx("span",{className:"font-medium text-xs",children:n("Write back to original file")})]}),e.jsx(le,{checked:y,onCheckedChange:N})]}),e.jsx("p",{className:"mt-1.5 pl-5.5 text-muted-foreground text-xs leading-relaxed",children:y?n("Saving overwrites {{path}} directly — {{source}} will pick up the change.",{path:i?.sourcePath??"",source:i?.source??""}):n("Saving creates a local copy — {{path}} is left untouched, and this entry stops following its updates.",{path:i?.sourcePath??""})})]}):e.jsxs("div",{className:"flex w-full items-start gap-2 rounded-md border bg-muted/50 px-3 py-2",children:[e.jsx(ss,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx("p",{className:"text-muted-foreground text-xs leading-relaxed",children:n("Local copy — edits stay in this app.")})]}),e.jsxs(me,{children:[e.jsx(he,{children:n("Name")}),e.jsx(J,{value:d,onChange:I=>u(I.target.value)})]}),e.jsxs(me,{children:[e.jsx(he,{children:n("Content")}),l?e.jsxs("div",{className:"flex w-full items-center justify-center gap-2 rounded-md border py-12",children:[e.jsx(Ae,{className:"h-4 w-4 animate-spin text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground text-xs",children:n("Loading...")})]}):e.jsx(He,{value:x,onChange:I=>{h(I.target.value),j(!0)},rows:16,className:"font-mono text-xs"})]}),g&&e.jsxs("p",{className:"flex items-center gap-1.5 text-destructive text-xs",children:[e.jsx(At,{className:"h-3.5 w-3.5 shrink-0"}),g]})]}),e.jsxs(Ie,{children:[e.jsx(S,{variant:"outline",size:"sm",onClick:s,children:n("Cancel")}),e.jsxs(S,{size:"sm",variant:A&&y?"destructive":"default",disabled:!d.trim()||l||c,onClick:O,children:[c&&e.jsx(Ae,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}),n(A?y?"Overwrite original":k?"Save as local copy":"Save":"Save")]})]})]})})}const gr=t=>t<1024?`${t} B`:`${(t/1024).toFixed(1)} KB`;function lx(){const{t}=z(),s=v(l=>l.instructions),n=v(l=>l.updateInstruction),a=v(l=>l.removeInstruction),[r,o]=m.useState(!1),[i,d]=m.useState(null),u=s.map(l=>l.id),x=hs(u,l=>window.electronAPI.assets.instructionOccupancy(l)),h=ds(s.filter(l=>l.enabled).map(l=>l.id),x.rows);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-end justify-between gap-4","data-settings-row":"instructions.root",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"font-medium text-lg",children:[t("Instruction Files"),e.jsx(ms,{tokens:h}),e.jsx(qe,{})]}),e.jsx("p",{className:"text-muted-foreground text-sm",children:t("Global CLAUDE.md / AGENTS.md style files from local AI tools")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Only one file is active at a time; enabling one disables the others")})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>o(!0),children:[e.jsx(cs,{className:"mr-1.5 h-4 w-4"}),t("Import from local apps")]}),e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>d("new"),children:[e.jsx(Oe,{className:"mr-1.5 h-4 w-4"}),t("Add instruction")]})]})]}),s.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx($n,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:t("No instruction files yet")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:t("Import instruction files from local apps or add one manually to get started")})]}):e.jsx("div",{className:"space-y-1",children:s.map(l=>e.jsxs("div",{className:"group flex items-center justify-between gap-3 rounded-md px-3 py-2 transition-colors hover:bg-accent/50","data-settings-row":`instructions.${l.id}`,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:G("shrink-0 font-medium text-sm",!l.enabled&&"text-muted-foreground line-through"),children:l.name}),e.jsx(te,{variant:"secondary",className:"shrink-0 text-[11px]",children:l.source}),!l.local&&e.jsxs(te,{variant:"outline",className:"shrink-0 gap-1 text-[11px]",children:[e.jsx(ai,{className:"h-3 w-3"}),t("Linked")]}),e.jsx("span",{className:"min-w-0 truncate text-muted-foreground text-xs",children:l.local?`${t("Local copy")} · ${gr(l.bytes)}`:`${l.sourcePath} · ${gr(l.bytes)}`})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(us,{row:x.rows[l.id],pending:x.pending&&!x.rows[l.id]}),e.jsx(le,{checked:l.enabled,onCheckedChange:f=>n(l.id,{enabled:f})}),e.jsx(S,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",onClick:()=>d(l),children:e.jsx(lt,{className:"h-3.5 w-3.5"})}),e.jsx(S,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity hover:text-destructive group-hover:opacity-100",onClick:()=>a(l.id),children:e.jsx(Me,{className:"h-3.5 w-3.5"})})]})]},l.id))}),e.jsx(Vn,{kind:"instruction",open:r,onOpenChange:o}),e.jsx(ix,{instruction:i,onClose:()=>d(null)})]})}function cx(){const{t}=z();return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{"data-settings-row":"shortcuts.root",children:[e.jsx("h3",{className:"text-lg font-medium",children:t("Shortcuts")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("Click a shortcut to rebind it. Backspace removes it; Esc cancels.")})]}),e.jsx(mx,{}),e.jsx(ux,{})]})}function dx(){const[t,s]=m.useState([]);return m.useEffect(()=>{const n=window.electronAPI.extensionPlugins;let a=!0;const r=()=>{n.list().then(i=>a&&s(Dc(i)))};r();const o=n.onChanged(r);return()=>{a=!1,o()}},[]),t}function ux(){const{t}=z(),s=dx(),n=v(p=>p.keybindings),a=v(p=>p.setKeybinding),r=v(p=>p.resetKeybinding),[o,i]=m.useState(null),[d,u]=m.useState(null);if(s.length===0)return null;const x=Mo(n),{rows:h}=Rc(s,n,x),l=p=>h.find(g=>g.action===p)?.command.title??t(hn[p]??p),f=()=>{i(null),u(null)},c=(p,g,w)=>{if(p.preventDefault(),p.stopPropagation(),p.key==="Escape")return f();if(p.key==="Backspace"||p.key==="Delete")return a(g,""),f();const k=Ro(p);if(!k)return;const j=mn.find(y=>x[y]===k)??h.find(y=>y.action!==g&&!y.conflict&&y.binding===k)?.action;if(j)return u(j);k===w?r(g):a(g,k),f()};return e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium text-sm",children:"插件命令"}),e.jsx("div",{className:"divide-y rounded-md border",children:h.map(({action:p,command:g,binding:w,custom:k,conflict:j})=>{const y=o===p;return e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-sm",children:g.title}),e.jsxs("p",{className:"text-muted-foreground text-xs",children:[g.pluginName,j&&!y&&e.jsx("span",{className:"ml-2 text-destructive",children:t('Already used by "{{label}}"',{label:l(j)})})]})]}),y&&d&&e.jsx("span",{className:"text-destructive text-xs",children:t('Already used by "{{label}}"',{label:l(d)})}),w&&!y&&e.jsx("button",{type:"button",title:t("Remove shortcut"),onClick:()=>a(p,""),className:"rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:e.jsx(ht,{className:"h-3.5 w-3.5"})}),k&&!y&&e.jsx("button",{type:"button",title:t("Reset to default"),onClick:()=>r(p),className:"rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:e.jsx(Fn,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>{i(p),u(null)},onKeyDown:y?N=>c(N,p,g.key):void 0,onBlur:()=>y&&f(),autoFocus:y,className:G("rounded-md px-1 py-0.5 transition-colors",y?"ring-1 ring-ring":"hover:bg-muted",j&&!y&&"opacity-50 line-through"),children:y?e.jsx("span",{className:"text-muted-foreground text-xs",children:t("Press shortcut…")}):w?e.jsx(Po,{children:To(w)}):e.jsx("span",{className:"text-muted-foreground text-xs",children:t("No shortcut")})})]},p)})})]})}function mx(){const{t}=z(),s=v(h=>h.keybindings),n=v(h=>h.setKeybinding),a=v(h=>h.resetKeybinding),[r,o]=m.useState(null),[i,d]=m.useState(null),u=Mo(s),x=h=>{if(h.preventDefault(),h.stopPropagation(),!r)return;if(h.key==="Escape"){o(null),d(null);return}if(h.key==="Backspace"||h.key==="Delete"){n(r,""),o(null),d(null);return}const l=Ro(h,{allowBare:r==="send-message"||r==="voice-hold"});if(!l)return;const f=mn.find(c=>c!==r&&u[c]===l);if(f){d(f);return}l===Oc[r]?a(r):n(r,l),o(null),d(null)};return e.jsx("div",{className:"divide-y rounded-md border",children:mn.map(h=>{const l=r===h,f=s[h]!==void 0,c=u[h];return e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-sm",children:t(hn[h])}),ba[h]&&e.jsx("p",{className:"text-muted-foreground text-xs",children:t(ba[h])})]}),l&&i&&e.jsx("span",{className:"text-xs text-destructive",children:t('Already used by "{{label}}"',{label:t(hn[i])})}),c&&!l&&e.jsx("button",{type:"button",title:t("Remove shortcut"),onClick:()=>n(h,""),className:"rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:e.jsx(ht,{className:"h-3.5 w-3.5"})}),f&&!l&&e.jsx("button",{type:"button",title:t("Reset to default"),onClick:()=>a(h),className:"rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:e.jsx(Fn,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>{o(h),d(null)},onKeyDown:l?x:void 0,onBlur:()=>{l&&(o(null),d(null))},autoFocus:l,className:G("rounded-md px-1 py-0.5 transition-colors",l?"ring-1 ring-ring":"hover:bg-muted"),children:l?e.jsx("span",{className:"text-xs text-muted-foreground",children:t("Press shortcut…")}):c?e.jsx(Po,{children:To(c)}):e.jsx("span",{className:"text-xs text-muted-foreground",children:t("No shortcut")})})]},h)})})}function hx(t){return t.serverId??t.serverName}function bi(t,s){const n={...t};return s.serverId&&delete n[s.serverName],n[hx(s)]={state:s.state,...s.toolCount!==void 0?{toolCount:s.toolCount}:{},...s.error?{error:s.error}:{}},n}function xx(t){return t.reduce((s,n)=>bi(s,n),{})}function px(t,s){return{...t,[s]:{state:"connecting"}}}function fx(t,s,n){return{...t,[s]:{state:"error",...n?{error:n}:{}}}}const Gs=(t,s)=>{const n={...t};return delete n[s],n},ut=Lc()((t,s)=>({statuses:{},authorized:{},pending:{},bind:()=>(window.electronAPI.mcp.authState().then(n=>t({authorized:n})).catch(()=>{}),window.electronAPI.mcp.statusSnapshot().then(n=>t({statuses:{...s().statuses,...xx(n)}})).catch(()=>{}),window.electronAPI.mcp.onStatus(n=>{if(n.type==="mcp-status-cleared"){t({statuses:{}});return}t({statuses:bi(s().statuses,n)}),window.electronAPI.mcp.authState().then(a=>t({authorized:a})).catch(()=>{})})),authorize:async n=>{t({statuses:px(s().statuses,n),pending:{...s().pending,[n]:!0}});let a;try{a=await window.electronAPI.mcp.authorize(n)}catch(r){a={ok:!1,error:r instanceof Error?r.message:String(r)}}t({pending:Gs(s().pending,n),...a.ok?{authorized:{...s().authorized,[n]:!0}}:{statuses:fx(s().statuses,n,a.error)}})},revoke:async n=>{await window.electronAPI.mcp.revoke(n),t({authorized:Gs(s().authorized,n),statuses:Gs(s().statuses,n)})}})),We=t=>typeof t=="string"?t.trim():"",gx=t=>Array.isArray(t)?t.filter(s=>typeof s=="string"):[],yi=t=>{if(!t||typeof t!="object")return{};const s={};for(const[n,a]of Object.entries(t))typeof a=="string"&&(s[n]=a);return s};function jx(t){const s=yi(t);return delete s[""],Object.keys(s).length>0?s:void 0}function jr(t){const s={};for(const n of t.split(`
16
+ `);const V=y(I,L,E),F=t.getSymbolSize(I),b=new a(F);return c(b,I),p(b),g(b,I),k(b,L,0),I>=7&&w(b,I),j(b,V),isNaN(C)&&(C=i.getBestMask(b,k.bind(null,b,L))),i.applyMask(C,b),k(b,L,C),{modules:b,version:I,errorCorrectionLevel:L,maskPattern:C,segments:E}}return ks.create=function(I,L){if(typeof I>"u"||I==="")throw new Error("No input text");let C=s.M,E,M;return typeof L<"u"&&(C=s.from(L.errorCorrectionLevel,s.M),E=x.from(L.version),M=i.from(L.maskPattern),L.toSJISFunc&&t.setToSJISFunction(L.toSJISFunc)),A(I,E,C,M)},ks}var Vs={},Ks={},hr;function ji(){return hr||(hr=1,(function(t){function s(n){if(typeof n=="number"&&(n=n.toString()),typeof n!="string")throw new Error("Color should be defined as hex string");let a=n.slice().replace("#","").split("");if(a.length<3||a.length===5||a.length>8)throw new Error("Invalid hex color: "+n);(a.length===3||a.length===4)&&(a=Array.prototype.concat.apply([],a.map(function(o){return[o,o]}))),a.length===6&&a.push("F","F");const r=parseInt(a.join(""),16);return{r:r>>24&255,g:r>>16&255,b:r>>8&255,a:r&255,hex:"#"+a.slice(0,6).join("")}}t.getOptions=function(a){a||(a={}),a.color||(a.color={});const r=typeof a.margin>"u"||a.margin===null||a.margin<0?4:a.margin,o=a.width&&a.width>=21?a.width:void 0,i=a.scale||4;return{width:o,scale:o?4:i,margin:r,color:{dark:s(a.color.dark||"#000000ff"),light:s(a.color.light||"#ffffffff")},type:a.type,rendererOpts:a.rendererOpts||{}}},t.getScale=function(a,r){return r.width&&r.width>=a+r.margin*2?r.width/(a+r.margin*2):r.scale},t.getImageWidth=function(a,r){const o=t.getScale(a,r);return Math.floor((a+r.margin*2)*o)},t.qrToImageData=function(a,r,o){const i=r.modules.size,d=r.modules.data,u=t.getScale(i,o),x=Math.floor((i+o.margin*2)*u),h=o.margin*u,l=[o.color.light,o.color.dark];for(let f=0;f<x;f++)for(let c=0;c<x;c++){let p=(f*x+c)*4,g=o.color.light;if(f>=h&&c>=h&&f<x-h&&c<x-h){const w=Math.floor((f-h)/u),k=Math.floor((c-h)/u);g=l[d[w*i+k]?1:0]}a[p++]=g.r,a[p++]=g.g,a[p++]=g.b,a[p]=g.a}}})(Ks)),Ks}var xr;function Qh(){return xr||(xr=1,(function(t){const s=ji();function n(r,o,i){r.clearRect(0,0,o.width,o.height),o.style||(o.style={}),o.height=i,o.width=i,o.style.height=i+"px",o.style.width=i+"px"}function a(){try{return document.createElement("canvas")}catch{throw new Error("You need to specify a canvas element")}}t.render=function(o,i,d){let u=d,x=i;typeof u>"u"&&(!i||!i.getContext)&&(u=i,i=void 0),i||(x=a()),u=s.getOptions(u);const h=s.getImageWidth(o.modules.size,u),l=x.getContext("2d"),f=l.createImageData(h,h);return s.qrToImageData(f.data,o,u),n(l,x,h),l.putImageData(f,0,0),x},t.renderToDataURL=function(o,i,d){let u=d;typeof u>"u"&&(!i||!i.getContext)&&(u=i,i=void 0),u||(u={});const x=t.render(o,i,u),h=u.type||"image/png",l=u.rendererOpts||{};return x.toDataURL(h,l.quality)}})(Vs)),Vs}var qs={},pr;function Xh(){if(pr)return qs;pr=1;const t=ji();function s(r,o){const i=r.a/255,d=o+'="'+r.hex+'"';return i<1?d+" "+o+'-opacity="'+i.toFixed(2).slice(1)+'"':d}function n(r,o,i){let d=r+o;return typeof i<"u"&&(d+=" "+i),d}function a(r,o,i){let d="",u=0,x=!1,h=0;for(let l=0;l<r.length;l++){const f=Math.floor(l%o),c=Math.floor(l/o);!f&&!x&&(x=!0),r[l]?(h++,l>0&&f>0&&r[l-1]||(d+=x?n("M",f+i,.5+c+i):n("m",u,0),u=0,x=!1),f+1<o&&r[l+1]||(d+=n("h",h),h=0)):u++}return d}return qs.render=function(o,i,d){const u=t.getOptions(i),x=o.modules.size,h=o.modules.data,l=x+u.margin*2,f=u.color.light.a?"<path "+s(u.color.light,"fill")+' d="M0 0h'+l+"v"+l+'H0z"/>':"",c="<path "+s(u.color.dark,"stroke")+' d="'+a(h,x,u.margin)+'"/>',p='viewBox="0 0 '+l+" "+l+'"',w='<svg xmlns="http://www.w3.org/2000/svg" '+(u.width?'width="'+u.width+'" height="'+u.width+'" ':"")+p+' shape-rendering="crispEdges">'+f+c+`</svg>
17
+ `;return typeof d=="function"&&d(null,w),w},qs}var fr;function Zh(){if(fr)return bt;fr=1;const t=Rh(),s=Jh(),n=Qh(),a=Xh();function r(o,i,d,u,x){const h=[].slice.call(arguments,1),l=h.length,f=typeof h[l-1]=="function";if(!f&&!t())throw new Error("Callback required as last argument");if(f){if(l<2)throw new Error("Too few arguments provided");l===2?(x=d,d=i,i=u=void 0):l===3&&(i.getContext&&typeof x>"u"?(x=u,u=void 0):(x=u,u=d,d=i,i=void 0))}else{if(l<1)throw new Error("Too few arguments provided");return l===1?(d=i,i=u=void 0):l===2&&!i.getContext&&(u=d,d=i,i=void 0),new Promise(function(c,p){try{const g=s.create(d,u);c(o(g,i,u))}catch(g){p(g)}})}try{const c=s.create(d,u);x(null,o(c,i,u))}catch(c){x(c)}}return bt.create=s.create,bt.toCanvas=r.bind(null,n.render),bt.toDataURL=r.bind(null,n.renderToDataURL),bt.toString=r.bind(null,function(o,i,d){return a.render(o,d)}),bt}var ex=Zh();const tx=Ec(ex);function sx(){return e.jsxs("div",{className:"space-y-10",children:[e.jsx(nx,{}),!window.electronAPI.remote&&e.jsx(ax,{}),e.jsx(ix,{})]})}function nx(){const{t}=z(),[s,n]=m.useState(null),[a,r]=m.useState(null),[o,i]=m.useState(!1),[d,u]=m.useState(null),[x,h]=m.useState(null),[l,f]=m.useState(!1),c=s?.pairingExpiresAt;m.useEffect(()=>{if(!c){h(null);return}const k=()=>h(Math.max(0,Math.ceil((c-Date.now())/1e3)));k();const j=setInterval(k,1e3);return()=>clearInterval(j)},[c]);const p=k=>{navigator.clipboard.writeText(k).then(()=>{f(!0),setTimeout(()=>f(!1),1500)})};m.useEffect(()=>(window.electronAPI.pair.status().then(n),window.electronAPI.pair.onStatusChanged(k=>{n(k),(k.pairing||k.devices.length>0)&&u(null)})),[]),m.useEffect(()=>{const k=s?.inviteUri;if(!k){r(null);return}tx.toDataURL(k,{width:320,margin:1}).then(r).catch(()=>{})},[s?.inviteUri]);const g=async()=>{i(!0),u(null);const k=await window.electronAPI.pair.start();i(!1),k.ok||u(k.error??t("Failed to start pairing"))},w=s?.devices??[];return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-end justify-between gap-4","data-settings-row":"phone.root",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-medium text-lg",children:t("Allow connections")}),e.jsx("p",{className:"text-muted-foreground text-sm",children:t("Let your phone or another EnsoCode desktop connect to this computer. Keep this app running.")})]}),e.jsx("div",{className:"flex shrink-0 items-center gap-2",children:s?.pairing?e.jsx(S,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.pair.cancel()},children:t("Cancel pairing")}):e.jsxs(S,{variant:"outline",size:"sm",disabled:o,onClick:()=>{g()},children:[o?e.jsx(Ae,{className:"mr-1.5 h-4 w-4 animate-spin"}):e.jsx(un,{className:"mr-1.5 h-4 w-4"}),t("Generate pairing code")]})})]}),s&&!s.secureStorage&&e.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-dashed px-3 py-2 text-xs",children:[e.jsx(Ue,{className:"mt-0.5 h-4 w-4 shrink-0 text-destructive"}),e.jsx("span",{className:"text-muted-foreground",children:t("Secure storage is unavailable on this system, so pairing keys are stored unencrypted.")})]}),d&&e.jsx("p",{className:"text-destructive text-xs",children:d}),s?.pairing&&e.jsxs("div",{className:"space-y-3 rounded-md border border-dashed px-3 py-6",children:[e.jsxs("div",{className:"text-center",children:[a?e.jsx("img",{src:a,alt:t("Pairing QR code"),className:"mx-auto h-52 w-52"}):e.jsx(Ae,{className:"mx-auto h-5 w-5 animate-spin text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:t("Scan with your phone camera")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:t("Scanning opens the app and pairs it. To keep it handy, add it to your home screen.")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:t("On another EnsoCode desktop, paste the link below into Settings → Devices → Connect to a node.")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:x===null?t("The code expires in 60 seconds and can only be used once."):x>0?t("Expires in {{seconds}}s · single use",{seconds:x}):t("Code expired")})]}),s.inviteUri&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"min-w-0 flex-1 truncate rounded bg-muted px-2 py-1.5 font-mono text-[11px] text-muted-foreground",children:s.inviteUri}),e.jsxs(S,{variant:"outline",size:"sm",className:"shrink-0",onClick:()=>p(s.inviteUri),children:[l?e.jsx(Eo,{className:"mr-1.5 h-3.5 w-3.5"}):e.jsx(No,{className:"mr-1.5 h-3.5 w-3.5"}),t(l?"Copied":"Copy")]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"font-medium text-sm",children:t("Paired devices")}),w.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx(un,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:t("No paired devices")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:t("Generate a pairing code to let a phone or another desktop connect.")})]}):e.jsx("div",{className:"space-y-1",children:w.map(k=>e.jsx(rx,{device:k},k.pairId))})]})]})}function ax(){const{t}=z(),s=Ht(i=>i.nodes),n=Ht(i=>i.secureStorage),a=Ht(i=>i.refresh),[r,o]=m.useState(!1);return m.useEffect(()=>Ht.getState().bind(),[]),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-end justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-medium text-lg",children:t("Connect to a node")}),e.jsx("p",{className:"text-muted-foreground text-sm",children:t("Browse and drive conversations on another EnsoCode desktop. Its agent, keys and history stay there.")})]}),e.jsxs(S,{variant:"outline",size:"sm",className:"shrink-0",onClick:()=>o(!0),children:[e.jsx(Oe,{className:"mr-1.5 h-4 w-4"}),t("Connect to a node")]})]}),!n&&e.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-dashed px-3 py-2 text-xs",children:[e.jsx(Ue,{className:"mt-0.5 h-4 w-4 shrink-0 text-destructive"}),e.jsx("span",{className:"text-muted-foreground",children:t("Secure storage is unavailable on this system, so pairing keys are stored unencrypted.")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"font-medium text-sm",children:t("Connected nodes")}),s.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx(Ln,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:t("No connected nodes")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:t("Each connecting computer needs its own pairing code from the other desktop.")})]}):e.jsx("div",{className:"space-y-1",children:s.map(i=>e.jsx(ox,{node:i,onChanged:()=>{a()}},i.nodeId))})]}),e.jsx(Mc,{open:r,onOpenChange:o,switchOnSuccess:!1})]})}function vi({transport:t,rttMs:s}){const{t:n}=z(),a=t==="direct",r=Tc(s);return e.jsxs("span",{className:G("shrink-0 rounded px-1.5 py-0.5 text-[10px] leading-none",a?"bg-emerald-500/15 text-emerald-600":"bg-muted text-muted-foreground"),children:[n(a?"Direct link":"Via relay"),r?` · ${r}`:""]})}function rx({device:t}){const{t:s}=z(),[n,a]=m.useState(null),r=async()=>{n!==null&&(n.trim()&&n.trim()!==t.deviceName&&await window.electronAPI.pair.rename(t.pairId,n),a(null))};return e.jsxs("div",{className:"group flex items-center justify-between gap-3 rounded-md px-3 py-2 transition-colors hover:bg-accent/50",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[e.jsx("span",{className:G("h-2 w-2 shrink-0 rounded-full",t.phoneOnline?"bg-emerald-500":t.connected?"bg-amber-500":"bg-muted-foreground/40")}),n===null?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"truncate font-medium text-sm",children:t.deviceName}),e.jsx("span",{className:"shrink-0 text-muted-foreground text-xs",children:t.phoneOnline?s("Online"):t.connected?s("Waiting for device"):s("Offline")}),t.phoneOnline&&e.jsx(vi,{transport:t.transport,rttMs:t.rttMs}),e.jsx("button",{type:"button",title:s("Click to switch: view-only devices cannot send, approve or stop."),onClick:()=>{window.electronAPI.pair.setScope(t.pairId,t.scope==="read"?"operate":"read")},className:G("shrink-0 rounded px-1.5 py-0.5 text-[10px] leading-none transition-colors",t.scope==="read"?"bg-amber-500/15 text-amber-600 hover:bg-amber-500/25":"bg-muted text-muted-foreground hover:bg-accent"),children:t.scope==="read"?s("View only"):s("Can operate")})]}):e.jsx(J,{value:n,autoFocus:!0,onChange:o=>a(o.target.value),onBlur:()=>{r()},onKeyDown:o=>{o.key==="Enter"&&r(),o.key==="Escape"&&a(null)},className:"h-7 text-sm"})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1 opacity-0 transition-opacity group-hover:opacity-100",children:[e.jsx(S,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground",title:s("Rename"),onClick:()=>a(t.deviceName),children:e.jsx(lt,{className:"h-3.5 w-3.5"})}),e.jsx(S,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-destructive",onClick:()=>{window.electronAPI.pair.revoke(t.pairId)},children:e.jsx(Me,{className:"h-3.5 w-3.5"})})]})]})}function ox({node:t,onChanged:s}){const{t:n}=z(),[a,r]=m.useState(null),o=async()=>{a!==null&&(a.trim()&&a.trim()!==t.label&&(await window.electronAPI.nodes.rename(t.nodeId,a),s()),r(null))};return e.jsxs("div",{className:"group flex items-center justify-between gap-3 rounded-md px-3 py-2 transition-colors hover:bg-accent/50",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[e.jsx(Pc,{node:t}),a===null?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"truncate font-medium text-sm",children:t.label}),t.hostname&&t.hostname!==t.label&&e.jsx("span",{className:"shrink-0 truncate font-mono text-[10px] text-muted-foreground",children:t.hostname}),e.jsx("span",{className:"shrink-0 text-muted-foreground text-xs",children:t.hostOnline?n("Online"):t.connected?n("Remote desktop is offline"):n("Offline")}),t.hostOnline&&e.jsx(vi,{transport:t.transport,rttMs:t.rttMs})]}):e.jsx(J,{value:a,autoFocus:!0,onChange:i=>r(i.target.value),onBlur:()=>{o()},onKeyDown:i=>{i.key==="Enter"&&o(),i.key==="Escape"&&r(null)},className:"h-7 text-sm"})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1 opacity-0 transition-opacity group-hover:opacity-100",children:[e.jsx(S,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground",title:n("Rename"),onClick:()=>r(t.label),children:e.jsx(lt,{className:"h-3.5 w-3.5"})}),e.jsx(S,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-destructive",title:n("Disconnect"),onClick:()=>{window.electronAPI.nodes.remove(t.nodeId).then(s)},children:e.jsx(Me,{className:"h-3.5 w-3.5"})})]})]})}function ix(){const{t}=z(),[s,n]=m.useState(null),[a,r]=m.useState(null);m.useEffect(()=>(window.electronAPI.pair.status().then(n),window.electronAPI.pair.onStatusChanged(n)),[]);const o=async()=>{a!==null&&(n(await window.electronAPI.pair.setRelayUrl(a)),r(null))};return e.jsx("div",{className:"space-y-6",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"font-medium text-sm",children:t("Relay server")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("The relay only forwards encrypted frames and cannot read your messages.")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(J,{value:a??s?.relayUrl??"",onChange:i=>r(i.target.value),placeholder:"https://relay.example.com",className:"font-mono text-xs"}),a===null?e.jsx(S,{variant:"ghost",size:"icon",className:"h-8 w-8 shrink-0 text-muted-foreground",onClick:()=>r(s?.relayUrl??""),children:e.jsx(lt,{className:"h-3.5 w-3.5"})}):e.jsxs(S,{size:"sm",className:"shrink-0",onClick:()=>{o()},children:[e.jsx(Eo,{className:"mr-1.5 h-3.5 w-3.5"}),t("Save")]})]})]})})}function lx({onOpenBots:t}){const{t:s}=z(),n=v(i=>i.botModeEnabled),a=v(i=>i.setBotModeEnabled),r=v(i=>i.scratchSessionsEnabled),o=v(i=>i.setScratchSessionsEnabled);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("Experimental")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("Features still being tested. They may change or be removed.")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Te,{rowId:"experimental.botMode",title:s("Bot mode"),description:s("Adds a Code | Bot switch to the sidebar. Create members with their own persona, model and tools, and chat with them alone or in groups."),checked:n,onChange:a}),n&&e.jsx(S,{variant:"outline",size:"sm",onClick:t,children:s("Bot mode settings")}),e.jsx(Te,{rowId:"experimental.scratchSessions",title:s("Temporary chats"),description:s("Chats that are not tied to a project. Tools follow your global settings."),checked:r,onChange:o})]})]})}function cx({instruction:t,onClose:s}){const{t:n}=z(),a=v(I=>I.addInstructions),r=v(I=>I.updateInstruction),o=t==="new",i=o||!t?null:t,[d,u]=m.useState(""),[x,h]=m.useState(""),[l,f]=m.useState(!1),[c,p]=m.useState(!1),[g,w]=m.useState(null),[k,j]=m.useState(!1),[y,N]=m.useState(!1);m.useEffect(()=>{if(t){if(t==="new"){u(""),h(""),j(!1),w(null),N(!1),f(!1);return}u(t.name),j(!1),w(null),N(!1),f(!0),window.electronAPI.instructions.read(t.id,t.local,t.sourcePath).then(I=>{I.ok?h(I.content):(h(""),w(I.error??n("Failed to read content")))}).finally(()=>f(!1))}},[t,n]);const A=!!(i&&!i.local&&i.sourcePath),O=async()=>{if(!t||!d.trim())return;if(p(!0),o){const L=crypto.randomUUID(),C=await window.electronAPI.instructions.write(L,x);if(!C.ok){p(!1),w(n("Failed to save"));return}const E=a([{id:L,name:d.trim(),source:"Manual",local:!0,bytes:C.bytes,enabled:!0}]);if(p(!1),E===0){window.electronAPI.instructions.delete(L),w(n("An instruction with this name already exists"));return}s();return}if(!i){p(!1);return}if(A&&y&&i.sourcePath){const L=await window.electronAPI.instructions.writeSource(i.id,i.sourcePath,x);if(p(!1),!L.ok){w(L.error??n("Failed to save"));return}r(i.id,{name:d.trim(),bytes:L.bytes}),s();return}const I=await window.electronAPI.instructions.write(i.id,x);if(p(!1),!I.ok){w(n("Failed to save"));return}r(i.id,{name:d.trim(),local:!0,bytes:I.bytes}),s()};return e.jsx(pe,{open:t!==null,onOpenChange:I=>!I&&s(),children:e.jsxs(fe,{className:"max-w-2xl",children:[e.jsx(ge,{children:e.jsx(je,{children:n(o?"Add Instruction":"Edit Instruction")})}),e.jsxs(we,{className:"space-y-4",children:[o?null:A?e.jsxs("div",{className:G("w-full rounded-md border px-3 py-2.5 transition-colors",y?"border-destructive/32 bg-destructive/8":"border-amber-500/32 bg-amber-500/8"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[y?e.jsx(Ue,{className:"h-3.5 w-3.5 shrink-0 text-destructive"}):e.jsx(ss,{className:"h-3.5 w-3.5 shrink-0 text-amber-600 dark:text-amber-500"}),e.jsx("span",{className:"font-medium text-xs",children:n("Write back to original file")})]}),e.jsx(le,{checked:y,onCheckedChange:N})]}),e.jsx("p",{className:"mt-1.5 pl-5.5 text-muted-foreground text-xs leading-relaxed",children:y?n("Saving overwrites {{path}} directly — {{source}} will pick up the change.",{path:i?.sourcePath??"",source:i?.source??""}):n("Saving creates a local copy — {{path}} is left untouched, and this entry stops following its updates.",{path:i?.sourcePath??""})})]}):e.jsxs("div",{className:"flex w-full items-start gap-2 rounded-md border bg-muted/50 px-3 py-2",children:[e.jsx(ss,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx("p",{className:"text-muted-foreground text-xs leading-relaxed",children:n("Local copy — edits stay in this app.")})]}),e.jsxs(me,{children:[e.jsx(he,{children:n("Name")}),e.jsx(J,{value:d,onChange:I=>u(I.target.value)})]}),e.jsxs(me,{children:[e.jsx(he,{children:n("Content")}),l?e.jsxs("div",{className:"flex w-full items-center justify-center gap-2 rounded-md border py-12",children:[e.jsx(Ae,{className:"h-4 w-4 animate-spin text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground text-xs",children:n("Loading...")})]}):e.jsx(He,{value:x,onChange:I=>{h(I.target.value),j(!0)},rows:16,className:"font-mono text-xs"})]}),g&&e.jsxs("p",{className:"flex items-center gap-1.5 text-destructive text-xs",children:[e.jsx(At,{className:"h-3.5 w-3.5 shrink-0"}),g]})]}),e.jsxs(Ie,{children:[e.jsx(S,{variant:"outline",size:"sm",onClick:s,children:n("Cancel")}),e.jsxs(S,{size:"sm",variant:A&&y?"destructive":"default",disabled:!d.trim()||l||c,onClick:O,children:[c&&e.jsx(Ae,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}),n(A?y?"Overwrite original":k?"Save as local copy":"Save":"Save")]})]})]})})}const gr=t=>t<1024?`${t} B`:`${(t/1024).toFixed(1)} KB`;function dx(){const{t}=z(),s=v(l=>l.instructions),n=v(l=>l.updateInstruction),a=v(l=>l.removeInstruction),[r,o]=m.useState(!1),[i,d]=m.useState(null),u=s.map(l=>l.id),x=hs(u,l=>window.electronAPI.assets.instructionOccupancy(l)),h=ds(s.filter(l=>l.enabled).map(l=>l.id),x.rows);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-end justify-between gap-4","data-settings-row":"instructions.root",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"font-medium text-lg",children:[t("Instruction Files"),e.jsx(ms,{tokens:h}),e.jsx(qe,{})]}),e.jsx("p",{className:"text-muted-foreground text-sm",children:t("Global CLAUDE.md / AGENTS.md style files from local AI tools")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Only one file is active at a time; enabling one disables the others")})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>o(!0),children:[e.jsx(cs,{className:"mr-1.5 h-4 w-4"}),t("Import from local apps")]}),e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>d("new"),children:[e.jsx(Oe,{className:"mr-1.5 h-4 w-4"}),t("Add instruction")]})]})]}),s.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx($n,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:t("No instruction files yet")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:t("Import instruction files from local apps or add one manually to get started")})]}):e.jsx("div",{className:"space-y-1",children:s.map(l=>e.jsxs("div",{className:"group flex items-center justify-between gap-3 rounded-md px-3 py-2 transition-colors hover:bg-accent/50","data-settings-row":`instructions.${l.id}`,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:G("shrink-0 font-medium text-sm",!l.enabled&&"text-muted-foreground line-through"),children:l.name}),e.jsx(te,{variant:"secondary",className:"shrink-0 text-[11px]",children:l.source}),!l.local&&e.jsxs(te,{variant:"outline",className:"shrink-0 gap-1 text-[11px]",children:[e.jsx(ai,{className:"h-3 w-3"}),t("Linked")]}),e.jsx("span",{className:"min-w-0 truncate text-muted-foreground text-xs",children:l.local?`${t("Local copy")} · ${gr(l.bytes)}`:`${l.sourcePath} · ${gr(l.bytes)}`})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(us,{row:x.rows[l.id],pending:x.pending&&!x.rows[l.id]}),e.jsx(le,{checked:l.enabled,onCheckedChange:f=>n(l.id,{enabled:f})}),e.jsx(S,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",onClick:()=>d(l),children:e.jsx(lt,{className:"h-3.5 w-3.5"})}),e.jsx(S,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity hover:text-destructive group-hover:opacity-100",onClick:()=>a(l.id),children:e.jsx(Me,{className:"h-3.5 w-3.5"})})]})]},l.id))}),e.jsx(Vn,{kind:"instruction",open:r,onOpenChange:o}),e.jsx(cx,{instruction:i,onClose:()=>d(null)})]})}function ux(){const{t}=z();return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{"data-settings-row":"shortcuts.root",children:[e.jsx("h3",{className:"text-lg font-medium",children:t("Shortcuts")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("Click a shortcut to rebind it. Backspace removes it; Esc cancels.")})]}),e.jsx(xx,{}),e.jsx(hx,{})]})}function mx(){const[t,s]=m.useState([]);return m.useEffect(()=>{const n=window.electronAPI.extensionPlugins;let a=!0;const r=()=>{n.list().then(i=>a&&s(Dc(i)))};r();const o=n.onChanged(r);return()=>{a=!1,o()}},[]),t}function hx(){const{t}=z(),s=mx(),n=v(p=>p.keybindings),a=v(p=>p.setKeybinding),r=v(p=>p.resetKeybinding),[o,i]=m.useState(null),[d,u]=m.useState(null);if(s.length===0)return null;const x=Mo(n),{rows:h}=Rc(s,n,x),l=p=>h.find(g=>g.action===p)?.command.title??t(hn[p]??p),f=()=>{i(null),u(null)},c=(p,g,w)=>{if(p.preventDefault(),p.stopPropagation(),p.key==="Escape")return f();if(p.key==="Backspace"||p.key==="Delete")return a(g,""),f();const k=Ro(p);if(!k)return;const j=mn.find(y=>x[y]===k)??h.find(y=>y.action!==g&&!y.conflict&&y.binding===k)?.action;if(j)return u(j);k===w?r(g):a(g,k),f()};return e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium text-sm",children:"插件命令"}),e.jsx("div",{className:"divide-y rounded-md border",children:h.map(({action:p,command:g,binding:w,custom:k,conflict:j})=>{const y=o===p;return e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-sm",children:g.title}),e.jsxs("p",{className:"text-muted-foreground text-xs",children:[g.pluginName,j&&!y&&e.jsx("span",{className:"ml-2 text-destructive",children:t('Already used by "{{label}}"',{label:l(j)})})]})]}),y&&d&&e.jsx("span",{className:"text-destructive text-xs",children:t('Already used by "{{label}}"',{label:l(d)})}),w&&!y&&e.jsx("button",{type:"button",title:t("Remove shortcut"),onClick:()=>a(p,""),className:"rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:e.jsx(ht,{className:"h-3.5 w-3.5"})}),k&&!y&&e.jsx("button",{type:"button",title:t("Reset to default"),onClick:()=>r(p),className:"rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:e.jsx(Fn,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>{i(p),u(null)},onKeyDown:y?N=>c(N,p,g.key):void 0,onBlur:()=>y&&f(),autoFocus:y,className:G("rounded-md px-1 py-0.5 transition-colors",y?"ring-1 ring-ring":"hover:bg-muted",j&&!y&&"opacity-50 line-through"),children:y?e.jsx("span",{className:"text-muted-foreground text-xs",children:t("Press shortcut…")}):w?e.jsx(Po,{children:To(w)}):e.jsx("span",{className:"text-muted-foreground text-xs",children:t("No shortcut")})})]},p)})})]})}function xx(){const{t}=z(),s=v(h=>h.keybindings),n=v(h=>h.setKeybinding),a=v(h=>h.resetKeybinding),[r,o]=m.useState(null),[i,d]=m.useState(null),u=Mo(s),x=h=>{if(h.preventDefault(),h.stopPropagation(),!r)return;if(h.key==="Escape"){o(null),d(null);return}if(h.key==="Backspace"||h.key==="Delete"){n(r,""),o(null),d(null);return}const l=Ro(h,{allowBare:r==="send-message"||r==="voice-hold"});if(!l)return;const f=mn.find(c=>c!==r&&u[c]===l);if(f){d(f);return}l===Oc[r]?a(r):n(r,l),o(null),d(null)};return e.jsx("div",{className:"divide-y rounded-md border",children:mn.map(h=>{const l=r===h,f=s[h]!==void 0,c=u[h];return e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-sm",children:t(hn[h])}),ba[h]&&e.jsx("p",{className:"text-muted-foreground text-xs",children:t(ba[h])})]}),l&&i&&e.jsx("span",{className:"text-xs text-destructive",children:t('Already used by "{{label}}"',{label:t(hn[i])})}),c&&!l&&e.jsx("button",{type:"button",title:t("Remove shortcut"),onClick:()=>n(h,""),className:"rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:e.jsx(ht,{className:"h-3.5 w-3.5"})}),f&&!l&&e.jsx("button",{type:"button",title:t("Reset to default"),onClick:()=>a(h),className:"rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:e.jsx(Fn,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>{o(h),d(null)},onKeyDown:l?x:void 0,onBlur:()=>{l&&(o(null),d(null))},autoFocus:l,className:G("rounded-md px-1 py-0.5 transition-colors",l?"ring-1 ring-ring":"hover:bg-muted"),children:l?e.jsx("span",{className:"text-xs text-muted-foreground",children:t("Press shortcut…")}):c?e.jsx(Po,{children:To(c)}):e.jsx("span",{className:"text-xs text-muted-foreground",children:t("No shortcut")})})]},h)})})}function px(t){return t.serverId??t.serverName}function bi(t,s){const n={...t};return s.serverId&&delete n[s.serverName],n[px(s)]={state:s.state,...s.toolCount!==void 0?{toolCount:s.toolCount}:{},...s.error?{error:s.error}:{}},n}function fx(t){return t.reduce((s,n)=>bi(s,n),{})}function gx(t,s){return{...t,[s]:{state:"connecting"}}}function jx(t,s,n){return{...t,[s]:{state:"error",...n?{error:n}:{}}}}const Gs=(t,s)=>{const n={...t};return delete n[s],n},ut=Lc()((t,s)=>({statuses:{},authorized:{},pending:{},bind:()=>(window.electronAPI.mcp.authState().then(n=>t({authorized:n})).catch(()=>{}),window.electronAPI.mcp.statusSnapshot().then(n=>t({statuses:{...s().statuses,...fx(n)}})).catch(()=>{}),window.electronAPI.mcp.onStatus(n=>{if(n.type==="mcp-status-cleared"){t({statuses:{}});return}t({statuses:bi(s().statuses,n)}),window.electronAPI.mcp.authState().then(a=>t({authorized:a})).catch(()=>{})})),authorize:async n=>{t({statuses:gx(s().statuses,n),pending:{...s().pending,[n]:!0}});let a;try{a=await window.electronAPI.mcp.authorize(n)}catch(r){a={ok:!1,error:r instanceof Error?r.message:String(r)}}t({pending:Gs(s().pending,n),...a.ok?{authorized:{...s().authorized,[n]:!0}}:{statuses:jx(s().statuses,n,a.error)}})},revoke:async n=>{await window.electronAPI.mcp.revoke(n),t({authorized:Gs(s().authorized,n),statuses:Gs(s().statuses,n)})}})),We=t=>typeof t=="string"?t.trim():"",vx=t=>Array.isArray(t)?t.filter(s=>typeof s=="string"):[],yi=t=>{if(!t||typeof t!="object")return{};const s={};for(const[n,a]of Object.entries(t))typeof a=="string"&&(s[n]=a);return s};function bx(t){const s=yi(t);return delete s[""],Object.keys(s).length>0?s:void 0}function jr(t){const s={};for(const n of t.split(`
18
18
  `)){const a=n.indexOf(":"),r=a>0?n.slice(0,a).trim():"";r&&(s[r]=n.slice(a+1).trim())}return Object.keys(s).length>0?s:void 0}const vr=t=>Object.entries(t??{}).map(([s,n])=>`${s}: ${n}`).join(`
19
- `);function vx(t,s){const n=We(t).toLowerCase();return n==="sse"?"sse":n==="http"||n==="streamable-http"?"http":n==="stdio"?"stdio":s?"http":"stdio"}function br(t){if(!t||typeof t!="object")return[];const s=[];for(const[n,a]of Object.entries(t)){if(!a||typeof a!="object")continue;const r=a,o=We(r.url)||We(r.serverUrl),i=We(r.command);if(!i&&!o)continue;const d=i?void 0:jx(r.headers);s.push({name:n,transport:vx(r.type??r.transport,o),command:i||void 0,args:i?gx(r.args):void 0,env:i?yi(r.env):void 0,url:o||void 0,...d?{headers:d}:{}})}return s}const bx=t=>{const s=t.trim();return(s.match(/^```(?:json)?\s*([\s\S]*?)\s*```$/i)?.[1]??s).trim()},yx=t=>t.startsWith('"')&&!t.startsWith("{")&&!t.startsWith("[")?`{${t}}`:t,wx=t=>{if(!t||typeof t!="object"||Array.isArray(t))return t;const s=t;if(s.mcpServers!=null)return s.mcpServers;if(s.mcp_servers!=null)return s.mcp_servers;if(s.servers!=null)return s.servers;const n=s.mcp;if(n&&typeof n=="object"&&!Array.isArray(n)){const a=n.servers;if(a!=null)return a}return t},Nx=t=>{if(!t||typeof t!="object"||Array.isArray(t))return!1;const s=t;return!!(We(s.command)||We(s.url)||We(s.serverUrl))},kx=t=>{const s=We(t.command);return s&&s.split(/[\\/]/).pop()?.trim()||"mcp"},vn=t=>{if(Array.isArray(t))return t.flatMap(vn);if(Nx(t)){const s=We(t.name)||We(t.id)||kx(t);return br({[s]:t})}return br(t)};function Hs(t){let s;try{s=JSON.parse(yx(bx(t)))}catch{return{ok:!1,error:"invalid-json"}}const n=Array.isArray(s)?s.flatMap(vn):vn(wx(s));return n.length===0?{ok:!1,error:"empty"}:{ok:!0,servers:n}}const Cx=1e4,Sx=12e4,Ix=600,Ax=3600;function yr(t,s){let n;if(typeof t=="string"){const a=t.trim();if(!a||!/^\d+$/.test(a))return;n=Number(a)}else if(typeof t=="number")n=t;else return;if(!(!Number.isInteger(n)||n<=0))return s===void 0?n:Math.min(n,s)}const Ex={theme:Bc,disableFileHeader:!0,overflow:"scroll",preferredHighlighter:"shiki-js"};function Mx(t){return new Vc(t)}function wi({fileName:t,value:s,epoch:n,onChange:a,className:r="h-60"}){const{t:o}=z(),[i,d]=m.useState(!1),u=zc(Ex),x=m.useRef(a);x.current=a;const h=m.useMemo(()=>({onChange(l){x.current(l.contents)}}),[]);return m.useEffect(()=>{let l=!0;return _c().then(()=>{l&&d(!0)}),()=>{l=!1}},[]),i?e.jsx("div",{className:G("w-full overflow-hidden rounded-lg border border-input",r),children:e.jsx(Fc,{createEditor:Mx,children:e.jsx(Uc,{style:{height:"100%",overflow:"auto"},children:e.jsx($c,{file:{name:t,contents:s},disableWorkerPool:!0,edit:!0,editorOptions:h,options:u},n)})})}):e.jsx("div",{className:G("flex w-full items-center justify-center rounded-lg border border-input text-muted-foreground text-xs",r),children:o("Loading...")})}const wr=t=>{const s=t.split(`
19
+ `);function yx(t,s){const n=We(t).toLowerCase();return n==="sse"?"sse":n==="http"||n==="streamable-http"?"http":n==="stdio"?"stdio":s?"http":"stdio"}function br(t){if(!t||typeof t!="object")return[];const s=[];for(const[n,a]of Object.entries(t)){if(!a||typeof a!="object")continue;const r=a,o=We(r.url)||We(r.serverUrl),i=We(r.command);if(!i&&!o)continue;const d=i?void 0:bx(r.headers);s.push({name:n,transport:yx(r.type??r.transport,o),command:i||void 0,args:i?vx(r.args):void 0,env:i?yi(r.env):void 0,url:o||void 0,...d?{headers:d}:{}})}return s}const wx=t=>{const s=t.trim();return(s.match(/^```(?:json)?\s*([\s\S]*?)\s*```$/i)?.[1]??s).trim()},Nx=t=>t.startsWith('"')&&!t.startsWith("{")&&!t.startsWith("[")?`{${t}}`:t,kx=t=>{if(!t||typeof t!="object"||Array.isArray(t))return t;const s=t;if(s.mcpServers!=null)return s.mcpServers;if(s.mcp_servers!=null)return s.mcp_servers;if(s.servers!=null)return s.servers;const n=s.mcp;if(n&&typeof n=="object"&&!Array.isArray(n)){const a=n.servers;if(a!=null)return a}return t},Cx=t=>{if(!t||typeof t!="object"||Array.isArray(t))return!1;const s=t;return!!(We(s.command)||We(s.url)||We(s.serverUrl))},Sx=t=>{const s=We(t.command);return s&&s.split(/[\\/]/).pop()?.trim()||"mcp"},vn=t=>{if(Array.isArray(t))return t.flatMap(vn);if(Cx(t)){const s=We(t.name)||We(t.id)||Sx(t);return br({[s]:t})}return br(t)};function Hs(t){let s;try{s=JSON.parse(Nx(wx(t)))}catch{return{ok:!1,error:"invalid-json"}}const n=Array.isArray(s)?s.flatMap(vn):vn(kx(s));return n.length===0?{ok:!1,error:"empty"}:{ok:!0,servers:n}}const Ix=1e4,Ax=12e4,Ex=600,Mx=3600;function yr(t,s){let n;if(typeof t=="string"){const a=t.trim();if(!a||!/^\d+$/.test(a))return;n=Number(a)}else if(typeof t=="number")n=t;else return;if(!(!Number.isInteger(n)||n<=0))return s===void 0?n:Math.min(n,s)}const Px={theme:_c,disableFileHeader:!0,overflow:"scroll",preferredHighlighter:"shiki-js"};function Tx(t){return new Vc(t)}function wi({fileName:t,value:s,epoch:n,onChange:a,className:r="h-60"}){const{t:o}=z(),[i,d]=m.useState(!1),u=zc(Px),x=m.useRef(a);x.current=a;const h=m.useMemo(()=>({onChange(l){x.current(l.contents)}}),[]);return m.useEffect(()=>{let l=!0;return Bc().then(()=>{l&&d(!0)}),()=>{l=!1}},[]),i?e.jsx("div",{className:G("w-full overflow-hidden rounded-lg border border-input",r),children:e.jsx(Fc,{createEditor:Tx,children:e.jsx(Uc,{style:{height:"100%",overflow:"auto"},children:e.jsx($c,{file:{name:t,contents:s},disableWorkerPool:!0,edit:!0,editorOptions:h,options:u},n)})})}):e.jsx("div",{className:G("flex w-full items-center justify-center rounded-lg border border-input text-muted-foreground text-xs",r),children:o("Loading...")})}const wr=t=>{const s=t.split(`
20
20
  `).map(n=>n.trim()).filter(Boolean);return s.length>0?s:void 0},Nr=t=>{const s={};for(const n of t.split(`
21
21
  `)){const a=n.trim();if(!a)continue;const r=a.indexOf("=");r<=0||(s[a.slice(0,r).trim()]=a.slice(r+1))}return Object.keys(s).length>0?s:void 0},kr=t=>t?Object.entries(t).map(([s,n])=>`${s}=${n}`).join(`
22
- `):"",Cr=t=>{const s={type:t.transport};return t.command&&(s.command=t.command),t.args&&t.args.length>0&&(s.args=t.args),t.env&&Object.keys(t.env).length>0&&(s.env=t.env),t.url&&(s.url=t.url),t.headers&&Object.keys(t.headers).length>0&&(s.headers=t.headers),s};function Px({server:t,onClose:s}){const{t:n}=z(),a=v(U=>U.addMcpServers),r=v(U=>U.updateMcpServer),o=t==="new",[i,d]=m.useState("form"),[u,x]=m.useState(""),[h,l]=m.useState(""),[f,c]=m.useState(""),[p,g]=m.useState(""),[w,k]=m.useState("stdio"),[j,y]=m.useState(""),[N,A]=m.useState(""),[O,I]=m.useState(""),[L,C]=m.useState(""),[E,M]=m.useState(""),[V,F]=m.useState(""),[b,_]=m.useState(""),[K,D]=m.useState(""),[$,Y]=m.useState(0),[H,se]=m.useState(null),q=()=>({description:h.trim()||void 0,oauthClientName:w!=="stdio"&&f.trim()||void 0,oauthMetadataUrl:w!=="stdio"&&p.trim()||void 0,connectTimeoutSec:yr(V,Ix),callTimeoutSec:yr(b,Ax)}),Q=U=>{x(U.name),k(U.transport),y(U.command??""),A((U.args??[]).join(`
23
- `)),I(kr(U.env&&Object.keys(U.env).length>0?U.env:void 0)),C(U.url??""),M(vr(U.headers))},B=()=>{const U={type:w};if(w==="stdio"){U.command=j.trim();const Z=wr(N);Z&&(U.args=Z);const X=Nr(O);X&&(U.env=X)}else{U.url=L.trim();const Z=jr(E);Z&&(U.headers=Z)}return JSON.stringify(U,null,2)},ne=(U,Z)=>{const X=(Z??U.name).trim(),ue=U.env&&Object.keys(U.env).length>0?U.env:void 0,Ne=U.args&&U.args.length>0?U.args:void 0;return U.transport==="stdio"?{name:X,transport:U.transport,command:(U.command??"").trim(),args:Ne,env:ue,url:void 0,headers:void 0,...q()}:{name:X,transport:U.transport,url:(U.url??"").trim(),headers:U.headers&&Object.keys(U.headers).length>0?U.headers:void 0,command:void 0,args:void 0,env:void 0,...q()}};m.useEffect(()=>{if(!t)return;const U=t==="new"?null:t;d("form"),x(U?.name??""),l(U?.description??""),c(U?.oauthClientName??""),g(U?.oauthMetadataUrl??""),k(U?.transport??"stdio"),y(U?.command??""),A((U?.args??[]).join(`
24
- `)),I(kr(U?.env)),C(U?.url??""),M(vr(U?.headers)),F(U?.connectTimeoutSec?.toString()??""),_(U?.callTimeoutSec?.toString()??""),D(""),Y(Z=>Z+1),se(null)},[t]);const R=U=>n(U==="invalid-json"?"Invalid JSON":"No MCP servers found in JSON"),P=U=>{if(U===i)return;if(U==="json"){D(B()),Y(ue=>ue+1),se(null),d("json");return}const Z=Hs(K);if(!Z.ok){if(Z.error==="invalid-json"&&K.trim()){se(R(Z.error));return}se(null),d("form");return}if(Z.servers.length!==1){se(n("JSON must describe a single MCP server to switch to the form"));return}const X=Z.servers[0];Q({...X,name:u.trim()||X.name}),se(null),d("form")},ce=()=>{const U=Hs(K);if(!U.ok){se(R(U.error));return}if(U.servers.length===1){const[Z]=U.servers;D(JSON.stringify(Cr(Z),null,2)),Y(X=>X+1),u.trim()||x(Z.name)}else D(JSON.stringify({mcpServers:Object.fromEntries(U.servers.map(Z=>[Z.name,Cr(Z)]))},null,2)),Y(Z=>Z+1);se(null)},xe=!!u.trim()&&(w==="stdio"?!!j.trim():!!L.trim()),Pe=i==="json"?!!K.trim():xe,De=()=>{if(!t||!Pe)return;if(i==="json"){const Z=Hs(K);if(!Z.ok){se(R(Z.error));return}if(!o&&Z.servers.length!==1){se(n("JSON must describe a single MCP server"));return}if(o){const X=Z.servers.length===1;if(a(Z.servers.map(Ne=>({...ne(Ne,X&&u.trim()?u:Ne.name),...X?{}:{description:void 0},id:crypto.randomUUID(),source:"Manual",enabled:!0})))===0){se(n("This MCP server already exists"));return}}else r(t.id,ne(Z.servers[0],u.trim()||Z.servers[0].name));s();return}const U=w==="stdio"?{name:u.trim(),transport:w,command:j.trim(),args:wr(N),env:Nr(O),url:void 0,headers:void 0,...q()}:{name:u.trim(),transport:w,url:L.trim(),headers:jr(E),command:void 0,args:void 0,env:void 0,...q()};if(o){if(a([{...U,id:crypto.randomUUID(),source:"Manual",enabled:!0}])===0){se(n("This MCP server already exists"));return}}else r(t.id,U);s()};return e.jsx(pe,{open:t!==null,onOpenChange:U=>!U&&s(),children:e.jsxs(fe,{children:[e.jsx(ge,{children:e.jsx(je,{children:n(o?"Add MCP Server":"Edit MCP Server")})}),e.jsxs(we,{className:"space-y-4",children:[e.jsx(Ft,{value:i,onValueChange:U=>P(U),children:e.jsxs(Ut,{children:[e.jsx(Ke,{value:"form",children:n("Form")}),e.jsx(Ke,{value:"json",children:n("JSON")})]})}),e.jsxs(me,{children:[e.jsx(he,{children:n("Name")}),e.jsx(J,{value:u,onChange:U=>x(U.target.value)})]}),e.jsxs(me,{children:[e.jsx(he,{children:n("Description (optional)")}),e.jsx(J,{value:h,onChange:U=>l(U.target.value),placeholder:n("One line telling the model what this server is for")})]}),i==="json"?e.jsxs(me,{children:[e.jsxs("div",{className:"flex w-full items-center justify-between",children:[e.jsx(he,{children:n("JSON configuration")}),e.jsx(S,{variant:"ghost",size:"sm",className:"h-7 px-2",onClick:ce,children:n("Format")})]}),e.jsx(wi,{fileName:"mcp.json",value:K,epoch:$,onChange:D}),e.jsx("p",{className:"text-muted-foreground text-xs",children:n("Paste a server object or mcpServers JSON from Cursor / Claude Desktop")})]}):e.jsxs(e.Fragment,{children:[e.jsxs(me,{children:[e.jsx(he,{children:n("Transport")}),e.jsxs(ae,{items:ya.map(U=>({value:U,label:U})),value:w,onValueChange:U=>k(U),children:[e.jsx(re,{className:"w-full",children:e.jsx(oe,{})}),e.jsx(ie,{zIndex:st.DROPDOWN_IN_MODAL,children:ya.map(U=>e.jsx(ee,{value:U,children:U},U))})]})]}),w==="stdio"?e.jsxs(e.Fragment,{children:[e.jsxs(me,{children:[e.jsx(he,{children:n("Command")}),e.jsx(J,{value:j,onChange:U=>y(U.target.value),placeholder:"npx",className:"font-mono text-xs"})]}),e.jsxs(me,{children:[e.jsx(he,{children:n("Arguments (one per line)")}),e.jsx(He,{value:N,onChange:U=>A(U.target.value),rows:3,className:"font-mono text-xs"})]}),e.jsxs(me,{children:[e.jsx(he,{children:n("Environment variables (KEY=VALUE, one per line)")}),e.jsx(He,{value:O,onChange:U=>I(U.target.value),rows:3,className:"font-mono text-xs"})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs(me,{children:[e.jsx(he,{children:n("URL")}),e.jsx(J,{value:L,onChange:U=>C(U.target.value),placeholder:"https://...",className:"font-mono text-xs"})]}),e.jsxs(me,{children:[e.jsx(he,{children:n("Headers (Name: value, one per line)")}),e.jsx(He,{value:E,onChange:U=>M(U.target.value),rows:2,placeholder:"Authorization: Bearer <token>",className:"font-mono text-xs"})]}),e.jsxs(me,{children:[e.jsx(he,{children:n("OAuth client name (optional)")}),e.jsx(J,{value:f,onChange:U=>c(U.target.value),placeholder:n("For servers that only accept known OAuth clients")})]}),e.jsxs(me,{children:[e.jsx(he,{children:n("OAuth authorization server metadata URL (optional)")}),e.jsx(J,{value:p,onChange:U=>g(U.target.value),placeholder:n("Use when the server advertises a wrong authorization server or none"),className:"font-mono text-xs"})]})]}),e.jsxs(me,{children:[e.jsx(he,{children:n("Connection timeout (seconds)")}),e.jsx(J,{inputMode:"numeric",value:V,onChange:U=>F(U.target.value),placeholder:String(Cx/1e3)})]}),e.jsxs(me,{children:[e.jsx(he,{children:n("Tool call timeout (seconds)")}),e.jsx(J,{inputMode:"numeric",value:b,onChange:U=>_(U.target.value),placeholder:String(Sx/1e3)})]})]}),H&&e.jsx("p",{className:"t-shake-in text-destructive text-xs",children:H},H)]}),e.jsxs(Ie,{children:[e.jsx(S,{variant:"outline",size:"sm",onClick:s,children:n("Cancel")}),e.jsx(S,{size:"sm",disabled:!Pe,onClick:De,children:n("Save")})]})]})})}function Tx({status:t}){const{t:s}=z();return t.state==="connecting"?e.jsx(te,{variant:"outline",className:"shrink-0 animate-pulse text-[11px] text-muted-foreground",children:s("Connecting")}):t.state==="ready"?e.jsx(te,{variant:"success",className:"shrink-0 text-[11px]",children:s("{{count}} tools",{count:t.toolCount??0})}):t.state==="unauthorized"?e.jsx(te,{variant:"warning",className:"shrink-0 text-[11px]",children:s("Not authorized")}):t.state==="idle"?e.jsx(te,{variant:"outline",className:"shrink-0 text-[11px] text-muted-foreground",children:s("Authorized, pending connection")}):e.jsx(te,{variant:"error",className:"shrink-0 text-[11px]",title:t.error,children:s("Connection failed")})}function Rx(){const{t}=z(),s=v(M=>M.mcpServers),n=v(M=>M.updateMcpServer),a=v(M=>M.setMcpServersEnabled),r=v(M=>M.removeMcpServer),o=ut(M=>M.statuses),i=ut(M=>M.authorized),d=ut(M=>M.pending),u=ut(M=>M.authorize),x=ut(M=>M.revoke);m.useEffect(()=>ut.getState().bind(),[]);const[h,l]=m.useState(!1),[f,c]=m.useState(null),p=async M=>{await u(M),c(ut.getState().authorized[M]===!0?M:null)},[g,w]=m.useState(null),[k,j]=m.useState(""),y=s.filter(M=>Oo(k,[M.name,M.source,M.transport,M.url,M.command,...M.args??[]])),N=y.map(M=>M.id),A=Do(N),O=s.filter(M=>M.enabled).length,I=s.filter(M=>M.enabled).map(M=>M.id),L=hs(I,M=>window.electronAPI.assets.mcpOccupancy(M)),C=s.filter(M=>M.enabled&&M.loadMode!=="deferred").map(M=>M.id),E=ds(C,L.rows);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-end justify-between gap-4","data-settings-row":"mcp.root",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"font-medium text-lg",children:[t("MCP Servers"),e.jsx(qe,{}),s.length>0&&e.jsxs("span",{className:"ml-2 font-normal text-muted-foreground text-xs",children:[t("{{enabled}}/{{total}} enabled",{enabled:O,total:s.length}),e.jsx(ms,{tokens:E})]})]}),e.jsx("p",{className:"text-muted-foreground text-sm",children:t("Model Context Protocol servers available to this app")})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>l(!0),children:[e.jsx(cs,{className:"mr-1.5 h-4 w-4"}),t("Import from local apps")]}),e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>w("new"),children:[e.jsx(Oe,{className:"mr-1.5 h-4 w-4"}),t("Add MCP server")]})]})]}),s.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx(Lo,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:t("No MCP servers yet")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:t("Import MCP servers from local apps or add one manually to get started")})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx(zo,{query:k,onQueryChange:j,placeholder:t("Filter MCP servers..."),allSelected:A.allSelected,someSelected:A.someSelected,onToggleSelectAll:A.toggleAll,onEnable:()=>a(A.selectedIds,!0),onDisable:()=>a(A.selectedIds,!1),selectDisabled:y.length===0,actionDisabled:A.selectedIds.length===0}),y.length===0?e.jsx("p",{className:"px-3 py-6 text-center text-muted-foreground text-xs",children:t("No results")}):e.jsx("div",{className:"space-y-1",children:y.map(M=>{const V=o[M.id]??o[M.name],F=d[M.id]===!0,b=M.transport!=="stdio"&&i[M.id]!==!0,_=M.loadMode==="deferred";return e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"group flex items-center justify-between gap-3 rounded-md px-3 py-2 transition-colors hover:bg-accent/50","data-settings-row":`mcp.${M.id}`,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(Qe,{checked:A.isSelected(M.id),onCheckedChange:K=>A.toggleOne(M.id,K)}),e.jsx("span",{className:G("shrink-0 font-medium text-sm",!M.enabled&&"text-muted-foreground line-through"),children:M.name}),e.jsx(te,{variant:"outline",className:"shrink-0 text-[11px]",children:M.transport}),e.jsx(te,{variant:"secondary",className:"shrink-0 text-[11px]",children:M.source}),V&&e.jsx(Tx,{status:V}),e.jsx("span",{className:"min-w-0 truncate font-mono text-muted-foreground text-xs",children:M.url??[M.command,...M.args??[]].join(" ")})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[(b||V?.state==="unauthorized")&&e.jsxs(S,{variant:"outline",size:"sm",className:"h-7",disabled:F,onClick:()=>{p(M.id)},children:[F?e.jsx(Ae,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):e.jsx(Kc,{className:"mr-1.5 h-3.5 w-3.5"}),t(F?"Authorizing":"Authorize")]}),i[M.id]===!0&&e.jsx(S,{variant:"ghost",size:"icon",title:t("Revoke authorization"),className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",onClick:()=>{x(M.id)},children:e.jsx(qc,{className:"h-3.5 w-3.5"})}),e.jsx(us,{row:L.rows[M.id],pending:M.enabled&&L.pending&&!L.rows[M.id]}),e.jsx(Ft,{value:_?"deferred":"direct",onValueChange:K=>n(M.id,{loadMode:K==="deferred"?"deferred":"direct"}),title:t("On demand: tool descriptions are not preloaded into context; the model connects through the mcp tool when needed. Suits servers with many or rarely used tools. Takes effect in new conversations."),children:e.jsxs(Ut,{"aria-label":t("Load mode"),children:[e.jsx(Ke,{value:"direct",className:"h-6 px-2 text-xs sm:h-6 sm:text-xs",children:t("Always loaded")}),e.jsx(Ke,{value:"deferred",className:"h-6 px-2 text-xs sm:h-6 sm:text-xs",children:t("On demand")})]})}),e.jsx(le,{checked:M.enabled,onCheckedChange:K=>n(M.id,{enabled:K})}),e.jsx(S,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",onClick:()=>w(M),children:e.jsx(lt,{className:"h-3.5 w-3.5"})}),e.jsx(S,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity hover:text-destructive group-hover:opacity-100",onClick:()=>r(M.id),children:e.jsx(Me,{className:"h-3.5 w-3.5"})})]})]}),f===M.id&&e.jsx("p",{className:"px-3 text-muted-foreground text-xs",children:t("Authorized. Conversations that already include this server can use it on the next message.")})]},M.id)})})]}),e.jsx(Vn,{kind:"mcp",open:h,onOpenChange:l}),e.jsx(Px,{server:g,onClose:()=>w(null)})]})}const Ox=["fact","preference","decision","plan","procedure","learning","context","event"],Dx=.9,Lx=.7,zx=.5;function Bx(t){return Number.isFinite(t)?t>=Dx?"critical":t>=Lx?"important":t>=zx?"useful":"low":"low"}const Sr=3,Ir={PERSON:340,ORGANIZATION:20,TEAM:20,PRODUCT:210,TOOL:210,SYSTEM:250,SERVICE:250,PLATFORM:250,CONCEPT:160,METHOD:160,TECHNIQUE:160,EVENT:40,PROJECT:280,DOCUMENT:90,TERM:190};function Ni(t){if(Ir[t]!==void 0)return Ir[t];let s=0;for(let n=0;n<t.length;n++)s=s*17+t.charCodeAt(n)>>>0;return s%360}const Ws=22,_x=64;function Fx(t,s){if(s<=1)return Ws;const n=Math.sqrt(Math.max(1,t))/Math.sqrt(s);return Math.round(Ws+(_x-Ws)*Math.min(1,n))}function Ux(t,s,n){const a=Math.max(1,...t.map(o=>o.memoryCount)),r=new Set(t.map(o=>o.id));return[...t.map(o=>({data:{id:o.id,label:o.name,size:Fx(o.memoryCount,a),color:ki(Ni(o.entityType),n),entityType:o.entityType,memoryCount:o.memoryCount,spaceLabel:o.spaceLabel}})),...s.filter(o=>r.has(o.source)&&r.has(o.target)&&o.source!==o.target).map(o=>({data:{id:`${o.source}->${o.target}:${o.relation}`,source:o.source,target:o.target,label:o.relation.replace(/_/g," ").toLowerCase(),width:1+o.strength*2.5}}))]}function $x(t,s){const n=new Map;for(const a of t)n.set(a.entityType,(n.get(a.entityType)??0)+1);return[...n.entries()].map(([a,r])=>({entityType:a,count:r,color:ki(Ni(a),s)})).sort((a,r)=>r.count-a.count||a.entityType.localeCompare(r.entityType))}function Vx(t){const s=t?"#e7e7e9":"#1c1c1f";return[{selector:"node",style:{"background-color":"data(color)","background-opacity":.85,width:"data(size)",height:"data(size)",label:"data(label)","font-size":11,color:s,"text-valign":"bottom","text-margin-y":4,"text-max-width":"120px","text-wrap":"ellipsis","border-width":0,"transition-property":"opacity, border-width","transition-duration":150}},{selector:"edge",style:{width:"data(width)","line-color":t?"#4b4b52":"#c9c9d1","curve-style":"bezier",opacity:.65,"font-size":9,color:s,"text-opacity":0}},{selector:"edge:selected, edge.highlighted",style:{"text-opacity":.85,opacity:1}},{selector:"node:selected",style:{"border-width":3,"border-color":s,"background-opacity":1}},{selector:".dimmed",style:{opacity:.18,"text-opacity":.25}}]}function ki(t,s){return Kx(t,s?.62:.68,s?.58:.52)}function Kx(t,s,n){const a=(1-Math.abs(2*n-1))*s,r=a*(1-Math.abs(t/60%2-1)),o=n-a/2,[i,d,u]=t<60?[a,r,0]:t<120?[r,a,0]:t<180?[0,a,r]:t<240?[0,r,a]:t<300?[r,0,a]:[a,0,r],x=h=>Math.round((h+o)*255).toString(16).padStart(2,"0");return`#${x(i)}${x(d)}${x(u)}`}let Ar=!1;function qx(){Ar||(ni.use(pu),Ar=!0)}const Er={name:"fcose",animate:!1,randomize:!1,nodeRepulsion:8e3,idealEdgeLength:90,nodeSeparation:90,padding:24,fit:!0};function Gx({graph:t,selectedId:s,onSelect:n,memories:a,loading:r,onInterpret:o,interpreting:i}){const{t:d}=z(),u=m.useRef(null),x=m.useRef(null),h=m.useRef(n);h.current=n;const[l,f]=m.useState(null),c=m.useMemo(()=>typeof document<"u"&&document.documentElement.classList.contains("dark"),[]);m.useEffect(()=>{const w=u.current;if(!w||t.nodes.length===0)return;qx();const k=ni({container:w,elements:Ux(t.nodes,t.edges,c),style:Vx(c),minZoom:.2,maxZoom:2.5,wheelSensitivity:.2});return k.layout(Er).run(),k.on("tap","node",j=>h.current(j.target.id())),k.on("tap",j=>{j.target===k&&h.current(null)}),x.current=k,()=>{k.destroy(),x.current=null}},[t.nodes,t.edges,c]),m.useEffect(()=>{const w=x.current;w&&w.batch(()=>{if(w.elements().removeClass("dimmed").unselect(),!s)return;const k=w.getElementById(s);if(k.empty())return;const j=k.closedNeighborhood();w.elements().difference(j).addClass("dimmed"),k.select()})},[s]);const p=m.useMemo(()=>$x(t.nodes,c),[t.nodes,c]),g=t.nodes.find(w=>w.id===s)??null;return m.useEffect(()=>{const w=x.current;!w||s||w.batch(()=>{w.elements().removeClass("dimmed"),l&&w.nodes().filter(k=>k.data("entityType")!==l).addClass("dimmed")})},[l,s]),t.nodes.length===0?e.jsx("p",{className:"rounded-lg border px-3 py-6 text-muted-foreground text-sm",children:d(r?"Loading…":"No entities yet. Turn on entity extraction and store a few memories first.")}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"relative overflow-hidden rounded-lg border bg-muted/20",children:[e.jsx("div",{ref:u,className:"h-[440px] w-full"}),e.jsxs("div",{className:"absolute right-2 bottom-2 flex gap-1",children:[e.jsx(S,{size:"sm",variant:"outline",onClick:()=>x.current?.fit(void 0,24),title:d("Fit to view"),children:d("Fit")}),e.jsx(S,{size:"sm",variant:"outline",onClick:()=>x.current?.layout(Er).run(),title:d("Re-run layout"),children:d("Relayout")})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:d("Colour = entity type · size = how many memories mention it",{})}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:p.map(w=>e.jsxs("button",{type:"button",onClick:()=>f(l===w.entityType?null:w.entityType),className:G("inline-flex items-center gap-1.5 rounded-full border px-2 py-0.5 text-xs transition-colors",l===w.entityType?"border-foreground/40 bg-accent":"hover:bg-accent/50"),children:[e.jsx("span",{className:"size-2.5 shrink-0 rounded-full",style:{backgroundColor:w.color}}),e.jsx("span",{className:"text-muted-foreground",children:w.entityType.toLowerCase()}),e.jsx("span",{className:"tabular-nums",children:w.count})]},w.entityType))}),e.jsx("p",{className:"text-muted-foreground text-xs",children:d("{{shown}} of {{total}} entities",{shown:String(t.nodes.length),total:String(t.totalEntities)})})]}),g&&e.jsxs("section",{className:"space-y-2 rounded-lg border p-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"flex items-center gap-2 text-sm",children:[e.jsx("span",{className:"truncate font-medium",children:g.name}),e.jsx(te,{variant:"secondary",children:g.entityType})]}),e.jsx("p",{className:"text-muted-foreground text-xs",children:d("{{count}} memories · {{space}}",{count:String(g.memoryCount),space:g.spaceLabel})})]}),e.jsx(S,{size:"sm",variant:"outline",disabled:i,onClick:()=>o(g.id),children:d(i?"Interpreting…":"Interpret")})]}),e.jsxs("ul",{className:"divide-y rounded-lg border",children:[a.length===0&&e.jsx("li",{className:"px-3 py-4 text-muted-foreground text-sm",children:d("Loading…")}),a.map(w=>e.jsxs("li",{className:"space-y-0.5 px-3 py-2",children:[e.jsxs("p",{className:"flex items-center gap-2 text-sm",children:[w.isCrystal&&e.jsx("span",{title:d("Crystal"),children:"★"}),e.jsx("span",{className:"truncate",children:w.title}),e.jsx(te,{variant:"secondary",children:w.unitType})]}),e.jsx("p",{className:"line-clamp-2 text-muted-foreground text-xs",children:w.contentSummary})]},w.id))]})]})]})}function Hx({tree:t,loading:s,selected:n,onToggle:a,onInterpretGroup:r,interpreting:o}){const{t:i}=z(),[d,u]=m.useState(new Set);return t.length===0?e.jsx("p",{className:"rounded-lg border px-3 py-6 text-muted-foreground text-sm",children:i(s?"Loading…":"No memories yet.")}):e.jsx("ul",{className:"divide-y rounded-lg border",children:t.map(x=>{const h=d.has(x.id),l=(x.children??[]).map(f=>f.memoryId).filter(f=>!!f);return e.jsxs("li",{children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 px-3 py-2",children:[e.jsx("button",{type:"button",className:"min-w-0 flex-1 text-left",onClick:()=>{const f=new Set(d);f.delete(x.id)||f.add(x.id),u(f)},children:e.jsxs("p",{className:"flex items-center gap-2 text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:h?"▾":"▸"}),e.jsx("span",{className:"truncate",children:x.label}),e.jsx(te,{variant:"secondary",children:x.count})]})}),e.jsx(S,{size:"sm",variant:"ghost",className:"shrink-0",disabled:o||l.length===0,onClick:()=>r(x),children:i("Interpret")})]}),h&&e.jsxs("ul",{className:"divide-y border-t bg-muted/20",children:[(x.children??[]).map(f=>e.jsxs("li",{className:"flex items-center gap-2 px-3 py-2",children:[f.memoryId&&e.jsx(Qe,{checked:n.has(f.memoryId),onCheckedChange:()=>f.memoryId&&a(f.memoryId),"aria-label":i("Select memory")}),e.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-2",children:[f.isCrystal&&e.jsx("span",{title:i("Crystal"),children:"★"}),e.jsx("span",{className:"truncate text-sm",children:f.label})]})]},f.id)),x.count>(x.children?.length??0)&&e.jsx("li",{className:"px-3 py-2 text-muted-foreground text-xs",children:i("Showing {{shown}} of {{total}}",{shown:String(x.children?.length??0),total:String(x.count)})})]})]},x.id)})})}const Wx=120,Yx=30,Jx={nodes:[],edges:[],totalEntities:0};function Qx({revision:t=0}={}){const{t:s}=z(),[n,a]=m.useState("graph"),[r,o]=m.useState("unitType"),[i,d]=m.useState(Jx),[u,x]=m.useState([]),[h,l]=m.useState(!0),[f,c]=m.useState(null),[p,g]=m.useState([]),[w,k]=m.useState(new Set),[j,y]=m.useState(null),[N,A]=m.useState(!1),[O,I]=m.useState(null),[L,C]=m.useState(!1),E=m.useCallback(()=>{l(!0);const $=()=>l(!1);n==="graph"?window.electronAPI.memory.graph({limit:Wx,minMemories:1}).then(d).finally($):window.electronAPI.memory.tree({groupBy:r,limitPerGroup:Yx}).then(x).finally($)},[n,r]);m.useEffect(E,[E]);const M=m.useRef(E);M.current=E,m.useEffect(()=>window.electronAPI.memory.onChanged(()=>M.current()),[]);const V=m.useRef(t);m.useEffect(()=>{V.current!==t&&(V.current=t,E())},[t,E]),m.useEffect(()=>{if(!f){g([]);return}window.electronAPI.memory.graphEntity(f).then(g)},[f]);const F=async $=>{A(!0),y(null);try{y(await window.electronAPI.memory.insight($))}finally{A(!1)}},b=async()=>{C(!0);try{const $=await window.electronAPI.memory.crystallize({memoryIds:[...w]});I($),$.ok&&k(new Set)}finally{C(!1)}},_=[{value:"graph",label:s("Graph")},{value:"tree",label:s("Tree")}],K=[{value:"unitType",label:s("By type")},{value:"entity",label:s("By entity")},{value:"time",label:s("By month")}],D=w.size>=Sr;return e.jsxs("div",{className:"space-y-4","data-settings-row":"memory.knowledge",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-medium text-sm",children:s("Knowledge")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Browse what the agent knows as a graph or a tree, ask for an interpretation, and consolidate related memories into a crystal.")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(ae,{value:n,items:_,onValueChange:$=>a($==="tree"?"tree":"graph"),children:[e.jsx(re,{size:"sm",className:"w-32",children:e.jsx(oe,{})}),e.jsx(ie,{children:_.map($=>e.jsx(ee,{value:$.value,children:$.label},$.value))})]}),n==="tree"&&e.jsxs(ae,{value:r,items:K,onValueChange:$=>o($),children:[e.jsx(re,{size:"sm",className:"w-36",children:e.jsx(oe,{})}),e.jsx(ie,{children:K.map($=>e.jsx(ee,{value:$.value,children:$.label},$.value))})]}),e.jsx("span",{className:"flex-1"}),n==="tree"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:G("text-xs",D?"text-foreground":"text-muted-foreground"),children:s("{{count}} selected",{count:String(w.size)})}),e.jsx(S,{size:"sm",variant:"outline",disabled:!D||L,onClick:()=>{b()},children:L?s("Synthesizing…"):s("Crystallize ({{min}}+)",{min:String(Sr)})})]})]}),n==="graph"?e.jsx(Gx,{graph:i,loading:h,selectedId:f,onSelect:c,memories:p,interpreting:N,onInterpret:$=>{F({entityId:$})}}):e.jsx(Hx,{tree:u,loading:h,selected:w,interpreting:N,onToggle:$=>{const Y=new Set(w);Y.delete($)||Y.add($),k(Y)},onInterpretGroup:$=>{const Y=($.children??[]).map(H=>H.memoryId).filter(H=>!!H);F({memoryIds:Y})}}),e.jsx(pe,{open:j!==null,onOpenChange:$=>!$&&y(null),children:e.jsxs(fe,{children:[e.jsxs(ge,{children:[e.jsx(je,{children:s("Interpretation")}),j?.ok&&e.jsx(Ve,{children:s("Based on {{count}} memories",{count:String(j.sourceCount??0)})})]}),e.jsx(we,{children:j?.ok?e.jsx("p",{className:"whitespace-pre-wrap text-sm",children:j.text}):e.jsx("p",{className:"text-destructive text-sm",children:j?.error})}),e.jsx(Ie,{children:e.jsx(Et,{render:e.jsx(S,{variant:"outline",size:"sm"}),children:s("Close")})})]})}),e.jsx(pe,{open:O!==null,onOpenChange:$=>!$&&I(null),children:e.jsxs(fe,{children:[e.jsxs(ge,{children:[e.jsx(je,{children:O?.ok?s("Crystal created"):s("Nothing was written")}),O?.ok&&e.jsx(Ve,{children:O.title})]}),e.jsx(we,{className:"space-y-3",children:O?.ok?e.jsx("p",{className:"whitespace-pre-wrap text-sm",children:O.content}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-destructive text-sm",children:O?.error}),O?.candidates&&O.candidates.length>0&&e.jsx("ul",{className:"divide-y rounded-lg border",children:O.candidates.map($=>e.jsxs("li",{className:"flex items-center justify-between gap-2 px-3 py-2",children:[e.jsx("span",{className:"truncate text-sm",children:$.title}),e.jsxs(te,{variant:"secondary",children:[($.similarity*100).toFixed(0),"%"]})]},$.id))})]})}),e.jsx(Ie,{children:e.jsx(Et,{render:e.jsx(S,{variant:"outline",size:"sm"}),children:s("Close")})})]})})]})}function bn(t){return t==="fast"||t==="deep"}const yt=25,ot="__all__";function Ci(t){return t.slice(0,10)}function Xx(t,s){return t===!1&&!s}function Zx(t,s,n,a){return bn(t)&&!s.trim()?"needs-query":Xx(n,a)?"library-empty":"no-match"}function ep({items:t,onOpen:s,t:n,selected:a,onToggle:r,emptyLabel:o}){return e.jsxs("ul",{className:"divide-y rounded-lg border",children:[t.length===0&&e.jsx("li",{className:"px-3 py-6 text-sm text-muted-foreground",children:o}),t.map(i=>e.jsxs("li",{className:"flex items-center gap-2 px-3 py-2",children:[r&&e.jsx(Qe,{checked:a?.has(i.id)??!1,onCheckedChange:()=>r(i.id),"aria-label":n("Select memory")}),e.jsxs("button",{type:"button",onClick:()=>s(i.id),className:"min-w-0 flex-1 space-y-0.5 text-left",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[i.isCrystal&&e.jsx("span",{title:n("Crystal"),children:"★"}),e.jsx("span",{className:"truncate text-sm",children:i.title}),e.jsx(te,{variant:"secondary",children:i.unitType}),e.jsx(sp,{importance:i.importance,t:n}),i.lifecycleState==="archived"&&e.jsx(te,{variant:"outline",children:n("Archived")})]}),e.jsx("span",{className:"line-clamp-2 text-muted-foreground text-xs",children:i.contentSummary}),e.jsxs("span",{className:"block text-muted-foreground text-xs",children:[Ci(i.updatedAt)," · ",i.spaceLabel," ·"," ",n("Retrieved {{count}} times",{count:String(i.appearances)})]})]})]},i.id))]})}const tp={critical:{variant:"warning",label:"critical"},important:{variant:"info",label:"important"},useful:{variant:"outline",label:"useful"},low:{variant:"outline",label:"low"}};function sp({importance:t,t:s}){const n=Bx(t),a=tp[n];return e.jsx(te,{variant:a.variant,className:n==="low"?"text-muted-foreground":void 0,title:s("Importance {{value}}",{value:t.toFixed(2)}),children:s(a.label)})}function np({edges:t,onReview:s,t:n}){return t.length===0?null:e.jsxs("section",{className:"space-y-2","data-settings-row":"memory.review",children:[e.jsx("h3",{className:"text-sm font-medium",children:n("Needs review")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n("Reviewing only records your judgement. Nothing is deleted and no memory is superseded.")}),t.map(a=>e.jsxs("div",{className:"space-y-1 rounded-lg border px-3 py-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(te,{variant:"outline",children:a.relation}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[a.olderId.slice(0,8)," → ",a.newerId.slice(0,8)]})]}),a.reason&&e.jsx("p",{className:"text-xs text-muted-foreground",children:a.reason}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(S,{size:"sm",variant:"outline",onClick:()=>s(a.id,"accepted"),children:n("Accept")}),e.jsx(S,{size:"sm",variant:"ghost",onClick:()=>s(a.id,"rejected"),children:n("Dismiss")})]})]},a.id))]})}function ap({writes:t,onReview:s,t:n}){return t.length===0?null:e.jsxs("section",{className:"space-y-2","data-settings-row":"memory.pending-writes",children:[e.jsx("h3",{className:"text-sm font-medium",children:n("Memory writes awaiting approval")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n("Bot members need your approval before writing to project or global memory.")}),t.map(a=>e.jsxs("div",{className:"space-y-1 rounded-lg border px-3 py-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-xs text-muted-foreground",children:[a.originLabel&&e.jsx("span",{className:"text-foreground",children:a.originLabel}),e.jsxs("span",{children:["→ ",a.spaceLabel]}),a.redacted&&e.jsxs("span",{children:["· ",n("Secrets redacted")]})]}),a.title&&e.jsx("div",{className:"text-sm font-medium",children:a.title}),e.jsx("p",{className:"whitespace-pre-wrap text-xs",children:a.content}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(S,{size:"sm",variant:"outline",onClick:()=>s(a.id,"approve"),children:n("Approve")}),e.jsx(S,{size:"sm",variant:"ghost",onClick:()=>s(a.id,"reject"),children:n("Reject")})]})]},a.id))]})}function rp({t}){const s=Gc(),n=Hc(a=>a.review);return e.jsx(ap,{writes:s,t,onReview:(a,r)=>{n(a,r)}})}function op({revision:t=0}={}){const{t:s}=z(),[n,a]=m.useState(""),[r,o]=m.useState(ot),[i,d]=m.useState(ot),[u,x]=m.useState(!1),[h,l]=m.useState(0),[f,c]=m.useState("exact"),[p,g]=m.useState(!1),[w,k]=m.useState(!0),[j,y]=m.useState([]),[N,A]=m.useState(0),[O,I]=m.useState([]),[L,C]=m.useState(null),[E,M]=m.useState(null),[V,F]=m.useState(null),[b,_]=m.useState(new Set),[K,D]=m.useState(!1),[$,Y]=m.useState(!1),[H,se]=m.useState([]),q=m.useRef(!1),Q=m.useRef(0),B=m.useRef(0);m.useEffect(()=>(q.current=!0,()=>{q.current=!1,Q.current++,B.current++}),[]);const ne=m.useCallback(()=>{if(!q.current)return;const W=++Q.current,ve=()=>q.current&&W===Q.current;if(bn(f)&&!n.trim()){y([]),A(0),g(!0),k(!0);return}window.electronAPI.memory.list({query:n.trim()||void 0,spaceId:r===ot?void 0:r,unitType:i===ot?void 0:i,includeArchived:u,limit:yt,offset:h,mode:f}).then(Se=>{ve()&&(y(Se.items),A(Se.total),g(Se.approximate===!0),k(Se.vectorsUsed!==!1))}),window.electronAPI.memory.stats().then(Se=>{q.current&&(I(Object.keys(Se.bySpace).map(Ze=>({id:Ze,label:Se.spaceLabels[Ze]??Ze}))),C(Se.total>0))}),window.electronAPI.memory.evolvesPending().then(Se=>{q.current&&se(Se)})},[n,r,i,u,h,f]);m.useEffect(()=>(ne(),()=>{Q.current++}),[ne]);const R=m.useRef(ne);R.current=ne,m.useEffect(()=>window.electronAPI.memory.onChanged(()=>R.current()),[]);const P=m.useRef(t);m.useEffect(()=>{P.current!==t&&(P.current=t,ne())},[t,ne]);const ce=W=>{const ve=++B.current;window.electronAPI.memory.detail(W).then(Se=>{q.current&&ve===B.current&&M(Se)})},xe=()=>{B.current++,M(null)},Pe=async W=>{Y(!0);try{for(const ve of b)await W(ve)}finally{q.current&&(Y(!1),_(new Set),D(!1),R.current())}},De=()=>{Pe(W=>window.electronAPI.memory.archive(W))},U=()=>{Pe(W=>window.electronAPI.memory.delete(W))},Z=W=>{W.then(()=>{q.current&&(xe(),F(null),R.current())})},X=n.trim()!==""||r!==ot||i!==ot||u===!0,ue=[{value:ot,label:s("All spaces")},...O.map(W=>({value:W.id,label:W.label}))],Ne=[{value:ot,label:s("All types")},...Ox.map(W=>({value:W,label:W}))],Ce=[{value:"exact",label:s("Exact match")},{value:"fast",label:s("Fast retrieval")},{value:"deep",label:s("Deep retrieval")}];return e.jsxs("div",{className:"space-y-4","data-settings-row":"memory.library",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium",children:s("Stored memories")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Everything the agent has saved. Archiving hides a memory from search but keeps it.")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(Bo,{className:"w-full sm:w-96","data-size":"sm",children:[e.jsx(_o,{value:n,placeholder:s("Search memories"),onChange:W=>{l(0),a(W.target.value)}}),e.jsx(Fo,{align:"inline-end",className:"pe-1",children:e.jsxs(ae,{value:f,items:Ce,onValueChange:W=>{l(0),c(W==="deep"?"deep":W==="fast"?"fast":"exact")},children:[e.jsx(re,{size:"sm",className:"w-auto min-w-0 gap-1 border-0 bg-transparent px-2 shadow-none before:hidden",children:e.jsx(oe,{})}),e.jsx(ie,{children:Ce.map(W=>e.jsx(ee,{value:W.value,children:W.label},W.value))})]})})]}),e.jsxs(ae,{value:r,items:ue,onValueChange:W=>{l(0),o(String(W))},children:[e.jsx(re,{size:"sm",className:"w-36",children:e.jsx(oe,{})}),e.jsx(ie,{children:ue.map(W=>e.jsx(ee,{value:W.value,children:W.label},W.value))})]}),e.jsxs(ae,{value:i,items:Ne,onValueChange:W=>{l(0),d(String(W))},children:[e.jsx(re,{size:"sm",className:"w-36",children:e.jsx(oe,{})}),e.jsx(ie,{children:Ne.map(W=>e.jsx(ee,{value:W.value,children:W.label},W.value))})]}),f==="exact"&&e.jsxs("label",{className:"flex items-center gap-2 text-muted-foreground text-sm",children:[e.jsx(le,{checked:u,onCheckedChange:W=>{l(0),x(W===!0)}}),s("Show archived")]})]}),bn(f)&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:[s(f==="deep"?"Same recall as Fast, plus intent-weighted fusion and an optional short-timeout LLM rerank. Failures fall back; archived memories are excluded.":"Same path the agent uses: full-text, vectors and entities merged by relevance. Shows the top matches only — no exact count, and archived memories are excluded."),!w&&` ${s("Embedding model is not ready, so vectors are skipped.")}`]}),b.size>0&&e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border bg-accent/30 px-3 py-2",children:[e.jsx("span",{className:"text-sm",children:s("{{count}} selected",{count:String(b.size)})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(S,{variant:"ghost",size:"sm",disabled:$,onClick:()=>_(new Set),children:s("Clear selection")}),e.jsx(S,{variant:"outline",size:"sm",disabled:$,onClick:()=>De(),children:s("Archive selected")}),e.jsx("button",{type:"button",disabled:$,className:"text-xs text-muted-foreground underline-offset-2 hover:underline disabled:opacity-50",onClick:()=>D(!0),children:s("Delete permanently")})]})]}),e.jsx(ep,{items:j,onOpen:ce,t:s,selected:b,emptyLabel:{"needs-query":s("Type a query to search by meaning."),"library-empty":s("No memories yet. They appear here once the agent stores something."),"no-match":s("No memories match these filters.")}[Zx(f,n,L,X)],onToggle:W=>{const ve=new Set(b);ve.delete(W)||ve.add(W),_(ve)}}),!p&&N>yt&&e.jsxs("div",{className:"flex items-center justify-between text-xs text-muted-foreground",children:[e.jsx(S,{variant:"outline",size:"sm",disabled:h===0,onClick:()=>l(Math.max(0,h-yt)),children:s("Previous")}),e.jsxs("span",{children:[h+1,"–",Math.min(h+yt,N)," / ",N]}),e.jsx(S,{variant:"outline",size:"sm",disabled:h+yt>=N,onClick:()=>l(h+yt),children:s("Next")})]}),e.jsx(rp,{t:s}),e.jsx(np,{edges:H,t:s,onReview:(W,ve)=>Z(window.electronAPI.memory.evolvesReview(W,ve))}),e.jsx(pe,{open:E!==null,onOpenChange:W=>!W&&xe(),children:e.jsx(fe,{children:E&&e.jsxs(e.Fragment,{children:[e.jsxs(ge,{children:[e.jsx(je,{children:E.title}),e.jsx(Ve,{children:[E.unitType,E.spaceLabel,Ci(E.createdAt)].join(" · ")})]}),e.jsxs(we,{className:"space-y-4",children:[e.jsx("p",{className:"whitespace-pre-wrap text-sm",children:E.content}),e.jsxs("dl",{className:"grid grid-cols-2 gap-x-4 gap-y-3",children:[e.jsx(Ys,{label:s("Importance"),value:E.importance.toFixed(2)}),e.jsx(Ys,{label:s("Embedding"),value:E.embeddingModel??s("Not vectorized")}),E.eventStart&&e.jsx(Ys,{label:s("Event date"),value:`${E.eventStart}${E.eventEnd?` → ${E.eventEnd}`:""}`})]}),E.entityNames.length>0&&e.jsxs("section",{className:"space-y-1.5",children:[e.jsx("p",{className:"font-medium text-xs",children:s("Entities")}),e.jsx("div",{className:"flex flex-wrap gap-1",children:E.entityNames.map(W=>e.jsx(te,{variant:"secondary",children:W},W))})]}),E.crystalSources.length>0&&e.jsxs("section",{className:"space-y-1.5",children:[e.jsx("p",{className:"font-medium text-xs",children:s("Synthesized from")}),e.jsx("ul",{className:"divide-y rounded-lg border",children:E.crystalSources.map(W=>e.jsxs("li",{className:"flex items-center justify-between gap-2 px-3 py-2",children:[e.jsx("span",{className:"truncate text-sm",children:W.title}),e.jsxs("span",{className:"shrink-0 text-muted-foreground text-xs",children:[(W.contributionWeight*100).toFixed(0),"%"]})]},W.id))})]}),E.evolves.length>0&&e.jsxs("section",{className:"space-y-1.5",children:[e.jsx("p",{className:"font-medium text-xs",children:s("Related versions")}),e.jsx("ul",{className:"divide-y rounded-lg border",children:E.evolves.map(W=>e.jsxs("li",{className:"flex items-center gap-2 px-3 py-2",children:[e.jsx(te,{variant:"outline",children:W.relation}),e.jsx("span",{className:"text-muted-foreground text-xs",children:W.reviewState})]},W.id))})]})]}),e.jsxs(Ie,{children:[e.jsx(S,{variant:"ghost",size:"sm",className:"sm:me-auto",onClick:()=>F(E.id),children:s("Delete permanently")}),E.lifecycleState==="archived"?e.jsx(S,{variant:"outline",size:"sm",onClick:()=>Z(window.electronAPI.memory.restore(E.id)),children:s("Restore")}):e.jsx(S,{variant:"outline",size:"sm",onClick:()=>Z(window.electronAPI.memory.archive(E.id)),children:s("Archive")})]})]})})}),e.jsx(pe,{open:K,onOpenChange:W=>!W&&D(!1),children:e.jsxs(fe,{children:[e.jsxs(ge,{children:[e.jsx(je,{children:s("Delete {{count}} memories permanently?",{count:String(b.size)})}),e.jsx(Ve,{children:s("This cannot be undone. Archiving keeps the memory out of search while preserving it.")})]}),e.jsxs(Ie,{children:[e.jsx(Et,{render:e.jsx(S,{variant:"outline",size:"sm"}),children:s("Cancel")}),e.jsx(S,{variant:"destructive",size:"sm",disabled:$,onClick:U,children:s("Delete permanently")})]})]})}),e.jsx(pe,{open:V!==null,onOpenChange:W=>!W&&F(null),children:e.jsxs(fe,{children:[e.jsxs(ge,{children:[e.jsx(je,{children:s("Delete this memory permanently?")}),e.jsx(Ve,{children:s("This cannot be undone. Archiving keeps the memory out of search while preserving it.")})]}),e.jsxs(Ie,{children:[e.jsx(Et,{render:e.jsx(S,{variant:"outline",size:"sm"}),children:s("Cancel")}),e.jsx(S,{variant:"destructive",size:"sm",onClick:()=>V&&Z(window.electronAPI.memory.delete(V)),children:s("Delete permanently")})]})]})})]})}function Ys({label:t,value:s}){return e.jsxs("div",{className:"min-w-0",children:[e.jsx("dt",{className:"text-muted-foreground text-xs",children:t}),e.jsx("dd",{className:"truncate text-sm",children:s})]})}const Si="openai-compatible",ip=/embed|bge|m3e|voyage|jina|nomic|mxbai|stella|conan|acge|retriev|text-(?:similarity|search)|(?:^|[^a-z0-9])(?:e5|gte|bce)(?:[^a-z0-9]|$)/i;function Ii(t){return ip.test(t)}function Ai(t){return Array.isArray(t.models)?t.models.filter(s=>typeof s?.id=="string"&&Ii(s.id)):[]}function lp(t){return t.flatMap(s=>{if(!s.apiKey||typeof s.baseUrl!="string"||!s.baseUrl.trim())return[];const n=Ai(s);return n.length>0?[{...s,models:n}]:[]})}function cp(t){const{providerId:s,provider:n,modelId:a}=t;return s?n?n.apiKey?typeof n.baseUrl!="string"||!n.baseUrl.trim()?"no-base-url":!a||a===Si?"no-model":Ii(a)?null:Ai(n).length>0?"not-embedding-model":"no-embedding-models":"no-api-key":"provider-missing":"no-provider"}const dp={"no-provider":"No remote embedding provider is selected. Choose a provider with an API key, or switch to a local embedding model.","provider-missing":"The selected embedding provider no longer exists. Choose another provider, or switch to a local embedding model.","no-base-url":'Provider "{{provider}}" has no Base URL. Fill it in, or choose another provider.',"no-api-key":'Provider "{{provider}}" has no API key. Subscription sign-in cannot be used for embeddings; choose a provider with an API key, or switch to a local embedding model.',"no-model":"No remote embedding model is selected. Choose a model that supports /embeddings.","not-embedding-model":'"{{model}}" is a chat model and cannot be used for embeddings. Choose a model that supports /embeddings, or switch to a local embedding model.',"no-embedding-models":'Provider "{{provider}}" has no embedding model ("{{model}}" is a chat model). Add one that supports /embeddings (e.g. text-embedding-3-small), or switch to a local embedding model.'},up="No model can be used for embeddings: it needs a provider with an API key and an embedding model (e.g. text-embedding-3-small). Subscription sign-in cannot be used for embeddings.";function mp(t,s,n){return n(dp[t],{provider:s.provider??"",model:s.model??""})}const Mr=t=>t.slice(0,8);function Js(t,s){return t==="pending"||t==="running"?"running":t==="cancelled"?"cancelled":s?"failed":"done"}const hp={low_importance:"importance too low",candidates_found:"similar memory already exists",deduplicated:"identical to an existing memory",rejected:"rejected"};function xp(t){const s=[];for(const r of t.distill){const o=Js(r.status,r.error);s.push({key:`distill:${r.id}`,kind:"distill",target:r.sessionTitle||Mr(r.sessionId),state:o,detail:o==="failed"?r.error??"":o==="cancelled"?"superseded":o==="running"?r.attempts>1?`retry ${r.attempts}`:"queued":`${r.done} stored`,notes:(r.notes??[]).map(i=>[i.title,hp[i.kind]??i.kind].filter(Boolean).join(" — ")),updatedAt:r.updatedAt})}for(const r of t.kg){const o=Js(r.status,r.error);s.push({key:`kg:${r.id}`,kind:"kg",target:r.memoryTitle||Mr(r.memoryId),state:o,detail:o==="failed"?r.error??"":o==="cancelled"?"memory changed":o==="running"?"extracting":`${r.total} entities · ${r.done} links`,notes:[],updatedAt:r.updatedAt})}const n=t.reembed;if(n){const r=Js(n.status,n.error);s.push({key:`reembed:${n.id}`,kind:"reembed",target:n.target,state:r,detail:r==="failed"?n.error??"":r==="running"?`${n.done}/${n.total}`:`${n.done} vectorized${n.failed>0?` · ${n.failed} failed`:""}`,notes:[],updatedAt:n.updatedAt})}const a=r=>r.state==="running"?0:r.state==="failed"?1:2;return s.sort((r,o)=>a(r)-a(o)||o.updatedAt.localeCompare(r.updatedAt))}const Lt=`remote:${Si}`,os="remote:";function Pr(t){return t.id==="none"?"None (full-text only)":t.id.replace(/^(local|remote):/,"")}function xs(t){return t.startsWith(os)&&t.length>os.length}function pp(t){return xs(t)?Lt:t}function fp(t){return!xs(t)||t===Lt?null:t.slice(os.length)}function gp(t){return`${os}${t}`}function jp(t,s){return s===Lt?xs(t)?t:Lt:s}const vp=4e3,bp=800,Tr=6,yp={distill:"job:distill",kg:"job:entities",reembed:"job:vectors"},Rr={distill:[],kg:[],reembed:null,kgFailed:0};function wp(t){return t.some(s=>s.distilled)}function Or(t){return!t||t.total===0||t.embedded>=t.total?null:t.embeddingError??null}function Dr(t){return t?.downloadable&&(t.state==="missing"||t.state==="downloading")?t.state:null}function Np(t,s){if(t.done===0||t.done>=t.total)return null;const n=(s-t.startedAt)/t.done;return Math.round(n*(t.total-t.done))}function kp(t){const s=Math.max(1,Math.round(t/1e3));if(s<60)return`${s}s`;const n=Math.floor(s/60);return s%60===0?`${n}m`:`${n}m ${s%60}s`}function Cp(t){const s=new Map;for(const a of t){const r=a.projectId??"",o=s.get(r);if(o){o.sessions.push(a);continue}s.set(r,{key:r,name:a.projectName??"No project",sessions:[a]})}const n=[...s.values()];return[...n.filter(a=>a.key),...n.filter(a=>!a.key)]}function de(t){if(t<=0)return"0 B";const s=["B","KB","MB","GB"],n=Math.min(Math.floor(Math.log(t)/Math.log(1024)),s.length-1);return`${(t/1024**n).toFixed(n===0?0:1)} ${s[n]}`}function Qs({title:t,description:s,checked:n,onChange:a,rowId:r,disabled:o}){return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5","data-settings-row":r,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s})]}),e.jsx(le,{checked:n,disabled:o,onCheckedChange:i=>a(i===!0)})]})}function Sp({onLibraryChanged:t}={}){const{t:s}=z(),n=v(T=>T.disabledBuiltinTools),a=v(T=>T.memoryEmbeddingModel),r=v(T=>T.setMemoryEmbeddingModel),o=v(T=>T.memoryEmbeddingAutoDownload),i=v(T=>T.setMemoryEmbeddingAutoDownload),d=v(T=>T.memoryModelIdleMinutes),u=v(T=>T.setMemoryModelIdleMinutes),x=v(T=>T.memoryEmbeddingRemoteProviderId),h=v(T=>T.setMemoryEmbeddingRemoteProviderId),l=v(T=>T.providers),f=v(T=>T.memoryDistillEnabled),c=v(T=>T.setMemoryDistillEnabled),p=v(T=>T.memoryKgEnabled),g=v(T=>T.setMemoryKgEnabled),w=v(T=>T.memoryDistillModel),k=v(T=>T.setMemoryDistillModel),j=v(T=>T.memoryChatModel)||"remote",y=v(T=>T.setMemoryChatModel),N=v(T=>T.memoryLanguage),A=v(T=>T.setMemoryLanguage),O=Xe(),I=w?O.find(T=>T.id===w.providerId):void 0,L=I?.models.find(T=>T.id===w?.modelId),C=fp(a),E=m.useMemo(()=>lp(O),[O]),M=x?E.find(T=>T.id===x):void 0,V=M?.models.find(T=>T.id===C),F=x?l.find(T=>T.id===x):void 0,b=cp({providerId:x,provider:F,modelId:C}),_=b&&b!=="no-provider"&&b!=="no-model"?mp(b,{provider:F?.name||x||"",model:C??""},s):null,K=!n.includes("memory"),[D,$]=m.useState(null),[Y,H]=m.useState(Rr),[se,q]=m.useState([]),[Q,B]=m.useState(null),[ne,R]=m.useState([]),[P,ce]=m.useState(null),[xe,Pe]=m.useState([]),[De,U]=m.useState(null),[Z,X]=m.useState(null),[ue,Ne]=m.useState(null),[Ce,W]=m.useState(null),[ve,Se]=m.useState(!1),[Ze,ke]=m.useState(!1),nt=m.useRef(!1);nt.current=ve;const Vt=m.useRef(null),ps=m.useCallback(()=>{window.electronAPI.memory.distillableSessions().then(Pe)},[]);m.useEffect(()=>{K&&ps()},[K,ps]);const ft=m.useCallback(()=>{window.electronAPI.memory.models().then(q)},[]);m.useEffect(()=>(ft(),window.electronAPI.memory.onModelProgress(T=>{B(T.done?null:T),T.done&&ft()})),[ft]);const gt=m.useCallback(()=>{window.electronAPI.memory.chatModels().then(T=>R(T.filter(ye=>!ye.purpose)))},[]);m.useEffect(()=>(gt(),window.electronAPI.memory.onChatModelProgress(T=>{ce(T.done?null:T),T.done&&gt()})),[gt]),m.useEffect(()=>{if(!K){$(null),H(Rr);return}let T=!1;const ye=()=>{window.electronAPI.memory.stats().then(et=>{T||$(et)}),window.electronAPI.memory.jobs().then(et=>{T||(H(et),nt.current&&et.reembed?.status!=="running"&&Se(!1))})};Vt.current=ye,ye();const dt=window.electronAPI.memory.onChanged(ye),Pt=window.setInterval(ye,ve?bp:vp);return()=>{T=!0,Vt.current=null,dt(),window.clearInterval(Pt)}},[K,ve]);const Yn=Cp(xe),Jn=xe.filter(T=>!T.distilled),Qn=(T,ye,dt)=>{const Pt=T.filter(et=>!et.distilled);if(!wp(T)){Kt(T,ye);return}W({token:ye,label:dt,scope:T,pending:Pt})},Kt=async(T,ye,dt=!1)=>{const Pt=ne.find(vt=>vt.id===j)??null;if(Dr(Pt))return;U(ye);const et=Date.now();Ne({done:0,total:T.length,startedAt:et});try{for(let vt=0;vt<T.length;vt++)await window.electronAPI.memory.distillSession(T[vt].sessionId,dt),Ne({done:vt+1,total:T.length,startedAt:et})}finally{U(null),Ne(null),ps(),t?.()}},be=se.find(T=>T.id===a)??null,Le=ne.find(T=>T.id===j)??null,ct=Dr(Le),Xn=ne.map(T=>({value:T.id,label:T.id==="remote"?s("Remote (API model)"):T.label})),Zn=[...se.map(T=>({value:T.id,label:Pr(T)})),{value:Lt,label:s("Remote (OpenAI-compatible)")}],ea=Wc.map(T=>({value:String(T),label:T===0?s("Never"):s("{{count}} min",{count:T})})),ta=[{value:"en",label:s("English")},{value:"zh",label:s("Simplified Chinese")},{value:"auto",label:s("Follow conversation")}],qt=xs(a)||be?.runtime==="openai-compatible",jt=m.useMemo(()=>xp(Y),[Y]);return e.jsxs("div",{className:"space-y-6","data-settings-row":"memory.root",children:[e.jsxs("section",{className:"space-y-2",children:[e.jsx("h2",{className:"text-base font-medium",children:s("Memory")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("Durable knowledge the agent can search and write across sessions. Stored locally in a SQLite database.")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Turn memory off in Built-in tools.")})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5","data-settings-row":"memory.modelIdleMinutes",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s("Unload automatically when idle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Release local model memory after this idle period. Models load automatically the next time they are needed.")})]}),e.jsxs(ae,{value:String(d),items:ea,onValueChange:T=>{T!==null&&u(Number(T))},disabled:!K,children:[e.jsx(re,{className:"w-56 shrink-0","aria-label":s("Unload automatically when idle"),children:e.jsx(oe,{})}),e.jsx(ie,{children:ea.map(T=>e.jsx(ee,{value:T.value,children:T.label},T.value))})]})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium",children:s("Embedding model")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Used for semantic search and near-duplicate detection. Without it search still works using full-text only.")}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5","data-settings-row":"memory.embeddingModel",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:be?Pr(be):C??(qt?s("Remote (OpenAI-compatible)"):a)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:be?[be.dim?`${be.dim}d`:null,be.downloadable?de(be.approxBytes):null,be.runtime].filter(Boolean).join(" · "):qt?"openai-compatible":s("Unknown model; the default is used instead.")})]}),e.jsxs(ae,{value:pp(a),items:Zn,onValueChange:T=>{T!==null&&r(jp(a,String(T)))},disabled:!K,children:[e.jsx(re,{className:"w-56",children:e.jsx(oe,{})}),e.jsx(ie,{children:Zn.map(T=>e.jsx(ee,{value:T.value,children:T.label},T.value))})]})]}),be?.downloadable&&e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5","data-settings-row":"memory.download",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:be.state==="ready"?s("Model downloaded"):be.state==="downloading"?s("Downloading…"):s("Model not downloaded")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:Q&&Q.modelId===be.id?`${Q.file} · ${de(Q.received)}${Q.total?` / ${de(Q.total)}`:""} (${Q.fileIndex+1}/${Q.fileCount})`:be.state==="ready"?de(be.downloadedBytes):s("Semantic search stays off until the model is on disk.")})]}),e.jsx("div",{className:"flex shrink-0 gap-2",children:be.state==="downloading"?e.jsx(S,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.memory.cancelModelDownload(be.id).then(ft)},children:s("Cancel")}):be.state==="ready"?e.jsx(S,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.memory.deleteModel(be.id).then(ft)},children:s("Remove")}):e.jsx(S,{size:"sm",disabled:!K,onClick:()=>{window.electronAPI.memory.downloadModel(be.id).then(ft)},children:s("Download")})})]}),qt&&e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5","data-settings-row":"memory.remoteModel",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s("Remote model")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Credentials stay in the main process and are never sent to the renderer.")})]}),E.length>0?e.jsx("div",{className:"w-56 shrink-0",children:e.jsx(ze,{providers:E,providerId:M?.id??x??"",modelId:V?.id??C??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:s("Select model"),side:"bottom",triggerClassName:Ye,onSelect:(T,ye)=>{h(T),r(gp(ye))},onReasoningChange:()=>{},onThinkingChange:()=>{}})}):e.jsx("p",{className:"w-56 shrink-0 text-xs text-destructive",children:s(up)})]}),qt&&_&&e.jsx("p",{className:"text-xs text-destructive","data-settings-row":"memory.remoteModelIssue",children:_}),e.jsx(Qs,{rowId:"memory.autoDownload",title:s("Download models automatically"),description:s("Off by default, so a model is only fetched when you press Download. While a model is missing, search degrades to full-text; existing memories are re-embedded once it arrives."),checked:o,onChange:i,disabled:!K})]}),e.jsxs("section",{className:"space-y-2","data-settings-row":"memory.distillModel",children:[e.jsx("h3",{className:"text-sm font-medium",children:s("Distillation")}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s("Completion backend")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Local GGUF runs on this machine. Remote uses the model below.")})]}),e.jsxs(ae,{value:j,items:Xn,onValueChange:T=>y(String(T)),disabled:!K,children:[e.jsx(re,{className:"w-56",children:e.jsx(oe,{})}),e.jsx(ie,{children:Xn.map(T=>e.jsx(ee,{value:T.value,children:T.label},T.value))})]})]}),Le?.downloadable&&e.jsxs("div",{className:G("flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5",ct==="missing"&&"border-destructive/50"),children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:Le.state==="ready"?s("Model downloaded"):Le.state==="downloading"?s("Downloading…"):s("Model not downloaded")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:P&&P.modelId===Le.id?`${P.file} · ${de(P.received)}${P.total?` / ${de(P.total)}`:""}`:Le.state==="ready"?de(Le.downloadedBytes):de(Le.approxBytes)})]}),e.jsx("div",{className:"flex shrink-0 gap-2",children:Le.state==="downloading"?e.jsx(S,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.memory.cancelChatModelDownload(Le.id).then(gt)},children:s("Cancel")}):Le.state==="ready"?e.jsx(S,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.memory.deleteChatModel(Le.id).then(gt)},children:s("Remove")}):e.jsx(S,{size:"sm",disabled:!K,onClick:()=>{window.electronAPI.memory.downloadChatModel(Le.id).then(gt)},children:s("Download")})})]}),ct==="missing"&&e.jsx("p",{className:"text-xs text-destructive",children:s("Local model selected but the weights are not on disk. Distillation and interpretation will wait until you click Download.")}),ct==="downloading"&&e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Download in progress. Distillation waits until the model is ready.")}),j==="remote"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s("Distillation model")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Reads finished sessions and writes the memories.")})]}),O.length>0&&e.jsx("div",{className:"w-56 shrink-0",children:e.jsx(ze,{providers:O,providerId:I?.id??"",modelId:L?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:s("Follows the title-summary model"),side:"bottom",triggerClassName:Ye,onSelect:(T,ye)=>k({providerId:T,modelId:ye}),onReasoningChange:()=>{},onThinkingChange:()=>{}})})]}),w&&e.jsx(S,{variant:"ghost",size:"sm",onClick:()=>k(null),children:s("Follows the title-summary model")})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5","data-settings-row":"memory.language",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s("Memory language")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("English keeps retrieval and near-duplicate detection stable across languages. Choose Follow conversation if your team only works in one language.")})]}),e.jsxs(ae,{value:N,items:ta,onValueChange:T=>A(String(T)),disabled:!K,children:[e.jsx(re,{className:"w-56",children:e.jsx(oe,{})}),e.jsx(ie,{children:ta.map(T=>e.jsx(ee,{value:T.value,children:T.label},T.value))})]})]})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium",children:s("Background processing")}),e.jsx(Qs,{rowId:"memory.distill",title:s("Distill sessions automatically"),description:s("When a session ends, or goes idle for 30 minutes and is reclaimed, extract 1-3 durable memories from it in the background."),checked:f,onChange:c,disabled:!K}),f&&ct&&e.jsx("p",{className:"text-xs text-destructive",children:s("Automatic distillation is on, but the local model is not ready. Sessions will queue until you download it.")}),e.jsx(Qs,{rowId:"memory.kg",title:s("Extract entities"),description:s("Build an entity graph so a memory can be recalled by a name it does not literally contain."),checked:p,onChange:g,disabled:!K})]}),e.jsxs("section",{className:"space-y-2","data-settings-row":"memory.stats",children:[e.jsx("h3",{className:"text-sm font-medium",children:s("Library")}),D===null||D.total===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:s("No memories stored yet.")}):e.jsxs(e.Fragment,{children:[Or(D)&&e.jsx("p",{className:"text-xs text-destructive",children:s("Vectors unavailable: {{reason}}",{reason:Or(D)??""})}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-3",children:[e.jsx(wt,{label:s("Memories"),value:String(D.total)}),e.jsx(wt,{label:s("Crystals"),value:String(D.crystals)}),e.jsx(wt,{label:s("Entities"),value:String(D.entities)}),e.jsx(wt,{label:s("With vectors"),value:`${D.embedded}/${D.total}`,action:D.embedded<D.total?e.jsx("button",{type:"button",disabled:ve,className:"text-xs text-muted-foreground underline-offset-2 hover:underline disabled:opacity-60",onClick:()=>{Se(!0),window.electronAPI.memory.reembed().then(()=>Vt.current?.())},children:s(ve?"Backfilling…":"Backfill")}):null}),e.jsx(wt,{label:s("Database size"),value:de(D.databaseBytes)}),e.jsx(wt,{label:s("Spaces"),value:String(Object.keys(D.bySpace).length)})]})]})]}),e.jsxs("section",{className:"space-y-2","data-settings-row":"memory.distillSessions",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("h3",{className:"text-sm font-medium",children:s("Distill past sessions")}),Jn.length>0&&e.jsx(S,{size:"sm",variant:"outline",disabled:!K||De!==null||ct!==null,onClick:()=>Qn(xe,"all",s("All sessions")),children:De==="all"?s("Distilling…"):s("Distill all ({{count}})",{count:String(Jn.length)})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("The automatic switch only covers sessions that end from now on. Distill earlier sessions here to fill the library.")}),ue&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:[s("{{done}}/{{total}} done",{done:String(ue.done),total:String(ue.total)}),(()=>{const T=Np(ue,Date.now());return T===null?"":` · ${s("about {{time}} left",{time:kp(T)})}`})()]}),Yn.length===0?e.jsx("p",{className:"text-muted-foreground text-sm",children:s("No recorded sessions found.")}):e.jsx("ul",{className:"divide-y rounded-lg border",children:Yn.map(T=>{const ye=T.sessions.filter(dt=>!dt.distilled);return e.jsxs("li",{className:"flex items-center justify-between gap-3 px-3 py-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-sm",children:T.name}),e.jsx("p",{className:"text-muted-foreground text-xs",children:s("{{total}} sessions · {{pending}} not distilled",{total:String(T.sessions.length),pending:String(ye.length)})})]}),e.jsxs("div",{className:"flex shrink-0 gap-2",children:[e.jsx(S,{size:"sm",variant:"ghost",onClick:()=>X(T),children:s("View sessions")}),e.jsx(S,{size:"sm",variant:"outline",disabled:!K||De!==null||T.sessions.length===0||ct!==null,onClick:()=>Qn(T.sessions,T.key,T.name),children:De===T.key?s("Distilling…"):s("Distill project")})]})]},T.key)})})]}),e.jsx(pe,{open:Z!==null,onOpenChange:T=>!T&&X(null),children:e.jsx(fe,{children:Z&&e.jsxs(e.Fragment,{children:[e.jsxs(ge,{children:[e.jsx(je,{children:Z.name}),e.jsx(Ve,{children:s("{{total}} sessions · {{pending}} not distilled",{total:String(Z.sessions.length),pending:String(Z.sessions.filter(T=>!T.distilled).length)})})]}),e.jsx(we,{children:e.jsx("ul",{className:"divide-y rounded-lg border",children:Z.sessions.map(T=>e.jsxs("li",{className:"flex items-center justify-between gap-3 px-3 py-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-sm",children:T.title}),e.jsxs("p",{className:"text-muted-foreground text-xs",children:[T.updatedAt?T.updatedAt.slice(0,10):"",T.distilled?` · ${s("Already distilled")}`:""]})]}),e.jsx(S,{size:"sm",variant:"ghost",className:"shrink-0",disabled:!K||De!==null||ct!==null,onClick:()=>{Kt([T],T.sessionId,T.distilled)},children:De===T.sessionId?s("Distilling…"):T.distilled?s("Distill again"):s("Distill")})]},T.sessionId))})}),e.jsx(Ie,{children:e.jsx(Et,{render:e.jsx(S,{variant:"outline",size:"sm"}),children:s("Close")})})]})})}),e.jsx(pe,{open:Ce!==null,onOpenChange:T=>!T&&W(null),children:e.jsx(fe,{children:Ce&&e.jsxs(e.Fragment,{children:[e.jsxs(ge,{children:[e.jsx(je,{children:s("Some sessions were already distilled")}),e.jsx(Ve,{children:s("{{label}}: {{total}} sessions, {{done}} already distilled. Re-distilling runs the model again and may add new memories alongside the existing ones.",{label:Ce.label,total:String(Ce.scope.length),done:String(Ce.scope.length-Ce.pending.length)})})]}),e.jsxs(Ie,{children:[e.jsx(Et,{render:e.jsx(S,{variant:"ghost",size:"sm"}),children:s("Cancel")}),e.jsx(S,{variant:Ce.pending.length>0?"default":"outline",size:"sm",disabled:Ce.pending.length===0,onClick:()=>{const T=Ce;W(null),Kt(T.pending,T.token)},children:s("Only the {{count}} remaining",{count:String(Ce.pending.length)})}),e.jsx(S,{variant:Ce.pending.length>0?"outline":"default",size:"sm",onClick:()=>{const T=Ce;W(null),Kt(T.scope,T.token,!0)},children:s("Re-distill all {{count}}",{count:String(Ce.scope.length)})})]})]})})}),e.jsxs("section",{className:"space-y-2","data-settings-row":"memory.jobs",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("h3",{className:"font-medium text-sm",children:s("Background tasks")}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[Y.kgFailed>0&&e.jsx(S,{size:"sm",variant:"ghost",onClick:()=>{window.electronAPI.memory.retryFailedKgJobs().then(()=>Vt.current?.())},children:s("Retry failed extractions ({{count}})",{count:String(Y.kgFailed)})}),jt.some(T=>T.state!=="running")&&e.jsx(S,{size:"sm",variant:"ghost",title:s("Removes completed and cancelled jobs. Running tasks are kept. Sessions will show as not distilled again, since that flag is derived from job history — re-distilling is deduplicated, so it will not create duplicate memories."),onClick:()=>{window.electronAPI.memory.clearJobs()},children:s("Clear finished tasks")}),jt.length>Tr&&e.jsx(S,{size:"sm",variant:"ghost",onClick:()=>ke(!Ze),children:Ze?s("Show less"):s("Show all {{count}}",{count:String(jt.length)})})]})]}),jt.length===0?e.jsx("p",{className:"text-muted-foreground text-sm",children:s("Nothing running.")}):e.jsx("ul",{className:"divide-y rounded-lg border",children:(Ze?jt:jt.slice(0,Tr)).map(T=>e.jsxs("li",{className:"space-y-1 px-3 py-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(te,{variant:T.state==="failed"?"destructive":"secondary",children:s(yp[T.kind])}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-sm",children:T.target}),e.jsx("span",{className:G("shrink-0 text-xs",T.state==="failed"?"text-destructive":"text-muted-foreground"),children:T.state==="running"?`⋯ ${T.detail}`:T.detail})]}),T.notes.map(ye=>e.jsxs("p",{className:"pl-1 text-muted-foreground text-xs",children:["· ",ye]},ye))]},T.key))})]})]})}function wt({label:t,value:s,action:n}){return e.jsxs("div",{className:"rounded-lg border px-3 py-2",children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:t}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-sm",children:s}),n]})]})}function Ip(t,s){if(s===null)return{ok:!0,value:null};if(t.type==="boolean")return typeof s=="boolean"?{ok:!0,value:s}:s==="true"||s==="false"?{ok:!0,value:s==="true"}:{ok:!1,error:"需要打开或关闭"};if(typeof s!="string")return{ok:!1,error:"值不合法"};if(t.type==="number"){const n=s.trim();if(!/^-?\d+(\.\d+)?$/.test(n))return{ok:!1,error:"需要数字"};const a=Number(n);return Number.isFinite(a)?t.min!==void 0&&a<t.min?{ok:!1,error:"小于最小值"}:t.max!==void 0&&a>t.max?{ok:!1,error:"大于最大值"}:{ok:!0,value:a}:{ok:!1,error:"需要数字"}}return t.type==="enum"?t.options?.includes(s)?{ok:!0,value:s}:{ok:!1,error:"不在可选项里"}:s.length>4096||s.includes("\0")?{ok:!1,error:"值不合法"}:{ok:!0,value:s}}const Ap={"agent.tool":"运行 Agent 工具","ui.slot":"在界面挂载组件","ui.view":"打开侧栏页面","ui.notify":"发送系统通知","composer.draft":"读写输入框草稿","fs.read":"读取声明的文件","fs.write":"写入声明的文件","net.fetch":"访问声明的域名","mcp.server":"启动声明的 MCP 服务","mcp.call":"调用宿主 MCP 工具","agent.observe":"观察会话事件","agent.intercept":"拦截并改写会话事件","agent.inject":"向会话发送消息,并可触发该会话继续执行;默认只发到发起调用的会话,允许后可发到任意运行中的会话","process.background":"常驻后台并拉起子进程","plugin.call":"调用其他插件","ui.clipboard":"写入剪贴板","ui.openExternal":"用浏览器打开链接","session.read":"查看本项目的会话列表与运行状态(标题、活动时间、是否在等你)","session.readAll":"查看所有项目的会话列表与运行状态","session.focus":"在你点击时切换到本项目的会话","session.create":"在你点击时于本项目新建会话"};function Ei(t){return Ap[t]??t}const Ep=["themes","agent","productivity","integrations","insights","writing","fun"],Wn={themes:"主题外观",agent:"Agent 能力",productivity:"效率工作流",integrations:"外部集成",insights:"观测统计",writing:"写作翻译",fun:"休闲娱乐"};function Mp(t){return{installedKey:t,refresh:!0}}function Pp(t,s){return t.installedKey===s?t:{installedKey:s,refresh:!1}}function Ot(t){if(!t)return null;try{const s=new URL(t);return s.protocol==="https:"||s.protocol==="http:"?s.href:null}catch{return null}}function Tp({pluginId:t,name:s,from:n,homepage:a,onClose:r}){const{t:o}=z();return e.jsx(pe,{open:t!==null,onOpenChange:i=>!i&&r(),children:e.jsxs(fe,{children:[e.jsx(ge,{children:e.jsxs(je,{children:[o("Usage guide"),s?` · ${s}`:""]})}),e.jsx(we,{className:"max-h-[60vh] space-y-3 overflow-y-auto",children:t&&e.jsx(Mi,{pluginId:t,from:n,homepage:a})})]})})}function Mi({pluginId:t,from:s,homepage:n,showLink:a=!0}){const{t:r}=z(),[o,i]=m.useState(null),[d,u]=m.useState(null),[x,h]=m.useState(Ot(n)),[l,f]=m.useState(null);return m.useEffect(()=>{let c=!0;return es(()=>import("./globals-C9M_MZZV.js").then(p=>p.np),__vite__mapDeps([0,1]),import.meta.url).then(p=>{c&&f(()=>p.Markdown)}),()=>{c=!1}},[]),m.useEffect(()=>{let c=!1;return i(null),u(null),h(Ot(n)),(async()=>{const p=window.electronAPI.extensionPlugins,g=await p.readme({id:t,from:s});let w=g.ok?g.markdown:null,k=g.ok?null:g.error;if(!g.ok&&s==="installed"){const j=await p.readme({id:t,from:"market"});j.ok&&(w=j.markdown,k=null)}if(!Ot(n)){const j=await p.marketList(!1),y=j.ok?j.plugins.find(N=>N.id===t):void 0;c||h(Ot(y?.homepage))}c||(i(w),u(w?null:k))})(),()=>{c=!0}},[t,s,n]),e.jsxs("div",{className:"space-y-3",children:[a&&x&&e.jsx("a",{href:x,target:"_blank",rel:"noreferrer",className:"text-sm underline",children:r("Homepage")}),d&&e.jsx("p",{className:"text-muted-foreground text-sm",children:d}),o===null&&!d&&e.jsx("p",{className:"text-muted-foreground text-sm",children:"…"}),o!==null&&l&&e.jsx(l,{text:o})]})}function Pi(t,s){return s==="all"?!0:s==="installed"?t.installedVersion!==void 0:s==="updates"?t.updateAvailable:s==="other"?t.category===void 0:t.category===s}function Rp(t){const s=r=>t.filter(o=>Pi(o,r)).length,n=["all","installed","updates"],a=[...Ep,"other"];return[...n.map(r=>({id:r,count:s(r)})),...a.map(r=>({id:r,count:s(r)})).filter(r=>r.count>0)]}function Op(t,s){const n=s.query.trim().toLowerCase();return t.filter(a=>Pi(a,s.section)?n?[a.id,a.name,a.description,...a.tags].some(r=>r.toLowerCase().includes(n)):!0:!1).sort((a,r)=>a.tier!==r.tier?a.tier==="official"?-1:1:a.name.localeCompare(r.name))}const Lr={all:"全部",installed:"已安装",updates:"可更新",other:"其他"},Dp=t=>t in Lr?Lr[t]:Wn[t];function Lp({disabled:t,installedKey:s,onInstall:n}){const{t:a}=z(),r=window.electronAPI.extensionPlugins,[o,i]=m.useState(null),[d,u]=m.useState(!1),[x,h]=m.useState(""),[l,f]=m.useState("all"),[c,p]=m.useState(null),[g,w]=m.useState(()=>Mp(s)),k=Pp(g,s);k!==g&&w(k);const j=m.useCallback(async C=>{u(!0);try{i(await r.marketList(C))}catch(E){i({ok:!1,error:E instanceof Error?E.message:String(E),chinaMirror:!1})}finally{u(!1)}},[r]);m.useEffect(()=>{j(g.refresh)},[j,g]);const y=async C=>{await r.setMarketChinaMirror(C),await j(!0)},N=o?.ok===!0?o.plugins:[],A=Rp(N),O=A.some(C=>C.id===l)?l:"all",I=Op(N,{query:x,section:O}),L=c?N.find(C=>C.id===c):void 0;return e.jsxs("div",{className:"flex h-[min(72vh,720px)] min-h-0 flex-col gap-3 sm:flex-row sm:gap-4",children:[e.jsx("nav",{"aria-label":"插件分类",className:"flex shrink-0 gap-1 overflow-x-auto pb-1 sm:block sm:w-36 sm:space-y-0.5 sm:overflow-y-auto sm:pb-0",children:A.map(C=>e.jsxs("button",{type:"button","aria-pressed":O===C.id,onClick:()=>{f(C.id),p(null)},className:G("flex shrink-0 items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left text-sm hover:bg-accent sm:w-full",O===C.id&&"bg-accent font-medium"),children:[e.jsx("span",{className:"truncate whitespace-nowrap",children:Dp(C.id)}),e.jsx("span",{className:"text-muted-foreground text-xs tabular-nums",children:C.count})]},C.id))}),e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(J,{className:"min-w-40 flex-1",value:x,placeholder:a("Search plugins"),onChange:C=>{h(C.target.value),p(null)}}),e.jsxs("label",{className:"flex shrink-0 items-center gap-1.5 text-muted-foreground text-xs",children:[e.jsx(le,{checked:o?.chinaMirror??!1,disabled:d,onCheckedChange:C=>{y(C)}}),a("China mirror")]}),e.jsx(S,{size:"sm",variant:"ghost",disabled:d,onClick:()=>{j(!0)},children:d?e.jsx(St,{}):a("Refresh")})]}),o?.ok===!1&&e.jsx("p",{className:"text-destructive text-sm",children:o.error}),o?.ok===!0&&o.stale&&e.jsx("p",{className:"text-muted-foreground text-xs",children:a("Could not reach the marketplace; showing the last saved list.")}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto pr-1",children:L?e.jsx(Bp,{plugin:L,disabled:t,onBack:()=>p(null),onInstall:n}):o?.ok===!0&&I.length===0?e.jsx("p",{className:"text-muted-foreground text-sm",children:a("No matching plugins")}):e.jsx("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2",children:I.map(C=>e.jsx(zp,{plugin:C,disabled:t,onOpen:()=>p(C.id),onInstall:n},C.id))})})]})]})}function Ti({plugin:t,disabled:s,onInstall:n}){const{t:a}=z();return t.installedVersion&&!t.updateAvailable?e.jsx("span",{className:"shrink-0 text-muted-foreground text-xs",children:a("Installed")}):e.jsx(S,{size:"xs",variant:t.updateAvailable?"default":"outline",disabled:s,onClick:r=>{r.stopPropagation(),n(t.id)},children:t.updateAvailable?a("Update"):a("Install")})}function Ri({tier:t}){const{t:s}=z();return e.jsx(te,{variant:t==="official"?"secondary":"outline",className:"text-[11px]",children:s(t==="official"?"Official":"Community")})}function zp({plugin:t,disabled:s,onOpen:n,onInstall:a}){return e.jsxs("div",{role:"button",tabIndex:0,"aria-label":t.name,onClick:n,onKeyDown:r=>{r.target===r.currentTarget&&(r.key==="Enter"||r.key===" ")&&(r.preventDefault(),n())},className:"flex cursor-pointer flex-col gap-2 rounded-lg border p-3 text-left transition-colors hover:bg-accent/50",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Oi,{src:t.icon}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("p",{className:"flex items-center gap-1.5 text-sm",children:[e.jsx("span",{className:"truncate font-medium",children:t.name}),e.jsx(Ri,{tier:t.tier})]}),e.jsxs("p",{className:"text-muted-foreground text-xs",children:[t.latest,t.category?` · ${Wn[t.category]}`:""]})]}),e.jsx(Ti,{plugin:t,disabled:s,onInstall:a})]}),t.description&&e.jsx("p",{className:"line-clamp-2 text-muted-foreground text-xs",children:t.description})]})}function Bp({plugin:t,disabled:s,onBack:n,onInstall:a}){const{t:r}=z(),o=Ot(t.homepage);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs(S,{size:"xs",variant:"ghost",onClick:n,children:[e.jsx(Uo,{className:"size-3.5"}),"返回"]}),e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Oi,{src:t.icon,large:!0}),e.jsxs("div",{className:"min-w-0 flex-1 space-y-1",children:[e.jsxs("p",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("span",{className:"font-medium text-base",children:t.name}),e.jsx(Ri,{tier:t.tier}),t.category&&e.jsx(te,{variant:"outline",className:"text-[11px]",children:Wn[t.category]})]}),e.jsxs("p",{className:"font-mono text-muted-foreground text-xs",children:[t.id," · ",t.latest,t.installedVersion?` · 已装 ${t.installedVersion}`:""]}),t.description&&e.jsx("p",{className:"text-sm",children:t.description}),o&&e.jsxs("a",{href:o,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-primary text-xs hover:underline",children:[e.jsx(Yc,{className:"size-3"}),r("Homepage")]})]}),e.jsx(Ti,{plugin:t,disabled:s,onInstall:a})]}),t.screenshots&&t.screenshots.length>0&&e.jsx("div",{className:"flex gap-2 overflow-x-auto pb-1",children:t.screenshots.map(i=>e.jsx("img",{src:i.url,alt:i.alt,title:i.alt,loading:"lazy",className:"h-44 shrink-0 rounded-md border object-cover"},i.url))}),e.jsxs("section",{className:"space-y-1",children:[e.jsx("h3",{className:"font-medium text-sm",children:"权限"}),t.permissions.length===0?e.jsx("p",{className:"text-muted-foreground text-xs",children:"无特殊权限"}):e.jsx("ul",{className:"space-y-0.5",children:t.permissions.map(i=>e.jsxs("li",{className:"text-xs",children:[e.jsx("span",{className:"font-mono text-muted-foreground",children:i}),e.jsx("span",{className:"ml-2",children:Ei(i)})]},i))})]}),e.jsxs("section",{className:"space-y-1",children:[e.jsx("h3",{className:"font-medium text-sm",children:r("Usage guide")}),e.jsx(Mi,{pluginId:t.id,from:"market",homepage:t.homepage,showLink:!1})]})]})}function Oi({src:t,large:s}){const[n,a]=m.useState(!1);return e.jsx("div",{className:G("flex shrink-0 items-center justify-center rounded-md bg-muted",s?"size-12":"size-9"),children:t&&!n?e.jsx("img",{src:t,alt:"",className:s?"size-7 object-contain":"size-5 object-contain",onError:()=>a(!0)}):e.jsx(_t,{className:"size-4 text-muted-foreground"})})}function _p(t){const{notice:s,remote:n,onDismiss:a}=t;return e.jsxs("div",{className:"space-y-1 rounded-md border border-amber-500/30 bg-amber-500/5 px-3 py-2 text-amber-700 text-sm dark:text-amber-400",children:[s.unreadable&&e.jsx("p",{children:"插件登记表曾读取失败,下面的列表可能不全。插件文件没有删除,原文保存在数据目录的 extension-plugins/registry.json.unreadable。"}),s.discarded.length>0&&e.jsxs("p",{children:["检测到旧格式的登记记录,已丢弃并清理,请重新安装:",e.jsx("span",{className:"font-mono",children:s.discarded.join(", ")})]}),n?e.jsx("p",{className:"text-muted-foreground",children:"请在桌面端点「知道了」,或运行 enso-server plugin notice-dismiss 清除此提示。"}):e.jsx(S,{size:"sm",variant:"outline",onClick:a,children:"知道了"})]})}function Fp({pluginId:t,plain:s}){const{t:n}=z(),[a,r]=m.useState([]),[o,i]=m.useState({}),[d,u]=m.useState(null),x=m.useCallback(async()=>{const c=await window.electronAPI.extensionPlugins.configGet(t);c.ok?r(c.fields):u({error:!0,text:c.error}),i({})},[t]);m.useEffect(()=>{x()},[x]);const h=async()=>{const c={};for(const[g,w]of Object.entries(o)){const k=a.find(y=>y.key===g);if(!k||k.secret&&w==="")continue;const j=Ip(k,w);if(!j.ok){u({error:!0,text:`${k.title}:${j.error}`});return}c[g]=j.value}const p=await window.electronAPI.extensionPlugins.configSet(t,c);u(p.ok?{error:!1,text:n("Saved. New calls use it right away.")}:{error:!0,text:p.error??""}),p.ok&&await x()},l=c=>{const p=o[c.key];return typeof p=="string"?p:p===null||c.secret?"":c.value??(c.default!==void 0?String(c.default):"")},f=c=>{const p=o[c.key];return typeof p=="boolean"?p:(c.value??(typeof c.default=="boolean"?String(c.default):"false"))==="true"};return e.jsxs("div",{className:G("space-y-2",s?"":"rounded-md border border-border p-3"),children:[a.map(c=>e.jsxs("div",{className:"space-y-1",children:[e.jsxs("p",{className:"text-sm",children:[c.title,e.jsx("span",{className:"ml-2 font-mono text-muted-foreground text-xs",children:c.key})]}),c.description&&e.jsx("p",{className:"text-muted-foreground text-xs",children:c.description}),c.multiline&&c.type==="string"?e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(He,{autoComplete:"off",rows:4,value:l(c),placeholder:c.secret&&c.set?n("Set (leave blank to keep)"):n("Not set"),className:"min-w-0 flex-1",onChange:p=>i(g=>({...g,[c.key]:p.target.value}))}),c.set&&e.jsx(S,{size:"sm",variant:"ghost",onClick:()=>i(p=>({...p,[c.key]:null})),children:n("Clear value")})]}):c.secret||c.type==="string"||c.type==="number"||c.type==="path"?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(J,{type:c.secret?"password":c.type==="number"?"number":"text",autoComplete:"off",inputMode:c.type==="number"?"decimal":void 0,min:c.type==="number"?c.min:void 0,max:c.type==="number"?c.max:void 0,value:l(c),placeholder:c.secret&&c.set?n("Set (leave blank to keep)"):n("Not set"),onChange:p=>i(g=>({...g,[c.key]:p.target.value}))}),c.type==="path"&&!c.secret&&!window.electronAPI.remote&&e.jsx(S,{size:"sm",variant:"outline",onClick:()=>{window.electronAPI.extensionPlugins.pickPath(c.pathKind==="directory"?"directory":"file").then(p=>{p.ok&&"path"in p&&i(g=>({...g,[c.key]:p.path}))})},children:c.pathKind==="directory"?"选择文件夹":"选择文件"}),c.set&&e.jsx(S,{size:"sm",variant:"ghost",onClick:()=>i(p=>({...p,[c.key]:null})),children:n("Clear value")})]}):c.type==="boolean"?e.jsx(le,{checked:f(c),onCheckedChange:p=>i(g=>({...g,[c.key]:p}))}):e.jsxs(ae,{items:Object.fromEntries((c.options??[]).map(p=>[p,p])),value:l(c),onValueChange:p=>{typeof p=="string"&&i(g=>({...g,[c.key]:p}))},children:[e.jsx(re,{children:e.jsx(oe,{placeholder:"请选择"})}),e.jsx(ie,{children:(c.options??[]).map(p=>e.jsx(ee,{value:p,children:p},p))})]})]},c.key)),d&&e.jsx("p",{className:G("text-xs",d.error?"text-destructive":"text-muted-foreground"),children:d.text}),e.jsx(S,{size:"sm",disabled:Object.keys(o).length===0,onClick:()=>{h()},children:n("Save")})]})}function Up({pluginId:t,plain:s}){const{t:n}=z(),[a,r]=m.useState(null),o=m.useCallback(async()=>{const i=await window.electronAPI.extensionPlugins.logs(t);r(i.ok?i.text:i.error)},[t]);return m.useEffect(()=>{o()},[o]),e.jsxs("div",{className:G("space-y-2",s?"":"rounded-md border border-border p-3"),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-sm",children:n("Plugin logs")}),e.jsx(S,{size:"icon",variant:"ghost","aria-label":n("Refresh"),onClick:()=>{o()},children:e.jsx(Je,{className:"size-4"})})]}),e.jsx("pre",{className:"max-h-64 overflow-auto whitespace-pre-wrap break-all font-mono text-muted-foreground text-xs",children:a===null?"":a||n("No logs yet")})]})}function zr({message:t}){const[s,n]=m.useState(!1);return e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("p",{className:G("select-text break-all font-mono text-destructive text-xs",s?"max-h-48 overflow-auto whitespace-pre-wrap":"line-clamp-2"),children:t}),t.length>120&&e.jsx("button",{type:"button",className:"text-muted-foreground text-xs hover:text-foreground",onClick:()=>n(a=>!a),children:s?"收起":"展开全部"})]})}function Di({permissions:t,styles:s=!1}){return t.length===0?s?null:e.jsx("p",{className:"text-muted-foreground text-xs",children:"无特殊权限"}):e.jsx("ul",{className:"space-y-0.5",children:t.map(n=>e.jsxs("li",{className:"text-xs",children:[e.jsx("span",{className:"font-mono text-muted-foreground",children:n}),e.jsx("span",{className:"ml-2",children:Ei(n)})]},n))})}function $p(t){const s=t.intervalSeconds>=60&&t.intervalSeconds%60===0?`每 ${t.intervalSeconds/60} 分钟`:`每 ${t.intervalSeconds} 秒`,n=t.lastRunAt?` · 最近 ${new Date(t.lastRunAt).toLocaleString()}`:"";return`${t.id} · ${s}${n}${t.lastError?` · ${t.lastError}`:""}`}function Br(t){return[t.permissions.length>0?`${t.permissions.length} 项权限`:"",(t.events?.length??0)>0?`${t.events?.length} 个事件`:"",(t.schedules?.length??0)>0?`${t.schedules?.length} 个定时任务`:"",t.hasRenderer?"界面代码":"",t.crossSessionInject!==void 0?"跨会话投递开关":""].filter(Boolean).join(" · ")}function _r({permissions:t,env:s,interop:n,resident:a,running:r,styles:o,trustedUi:i,events:d,schedules:u}){return e.jsxs("div",{className:"space-y-1",children:[e.jsx(Di,{permissions:t,styles:o||i}),i&&e.jsx(Vp,{}),a&&e.jsxs("p",{className:"text-xs",children:["常驻进程",r===void 0?"":r?":运行中":":未运行"]}),o&&e.jsx("p",{className:"text-xs",children:"修改界面样式:主题 CSS 可以改变应用的任意界面"}),(s?.length??0)>0&&e.jsxs("p",{className:"text-xs",children:["环境变量:",e.jsx("span",{className:"font-mono",children:s?.join(", ")})]}),(n?.length??0)>0&&e.jsxs("p",{className:"text-xs",children:["可调用插件:",e.jsx("span",{className:"font-mono",children:n?.join(", ")})]}),d?.map(x=>e.jsxs("p",{className:"text-xs",children:["事件 ",x.event," · ",x.mode==="intercept"?"拦截":"观察",x.failClosed?" · 失败即拒绝":""]},`${x.event}:${x.mode}`)),u?.map(x=>e.jsxs("p",{className:"text-xs",children:["定时任务 ",$p(x)]},x.id))]})}function Vp(){return e.jsx("p",{className:"text-amber-700 text-xs dark:text-amber-400",children:"界面代码:运行在主界面里,可读写页面内容、调用界面能力,不受上面权限清单约束;只安装信任的插件"})}function Kp({pluginId:t,plain:s}){const[n,a]=m.useState(null),[r,o]=m.useState(null),i=m.useCallback(async()=>{const d=await window.electronAPI.extensionPlugins.artifactsList(t);d.ok?(a(d.artifacts),o(null)):o(d.error)},[t]);return m.useEffect(()=>{i()},[i]),e.jsxs("div",{className:G("space-y-2",s?"":"rounded-md border border-border p-3"),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-sm",children:"产出文件"}),e.jsx(S,{size:"icon",variant:"ghost","aria-label":"刷新",onClick:()=>{i()},children:e.jsx(Je,{className:"size-4"})})]}),r&&e.jsx("p",{className:"text-destructive text-xs",children:r}),e.jsx(td,{artifacts:n??[],onDelete:d=>{window.electronAPI.extensionPlugins.artifactDelete(d).then(u=>{u.ok?i():o(u.error??"删除失败")})}})]})}const Xs=new Set;function qp({requestedInstallUrl:t=null,onRequestedInstallUrlConsumed:s,focusPluginId:n=null,onFocusPluginConsumed:a}={}){const{t:r}=z(),o=v(R=>R.pluginAutoUpdate!==!1),i=v(R=>R.setPluginAutoUpdate),[d,u]=m.useState([]),x=Dn(R=>R.errors),[h,l]=m.useState(null),[f,c]=m.useState(null),[p,g]=m.useState([]),[w,k]=m.useState(!1),[j,y]=m.useState(null),[N,A]=m.useState(""),[O,I]=m.useState(!1),[L,C]=m.useState(!1),[E,M]=m.useState(null),[V,F]=m.useState(null),[b,_]=m.useState(!1),[K,D]=m.useState(null),$=m.useCallback(async()=>{try{u(await window.electronAPI.extensionPlugins.list())}catch{u([])}},[]);m.useEffect(()=>($(),window.electronAPI.extensionPlugins.registryNotice().then(F).catch(()=>F(null)),window.electronAPI.extensionPlugins.onChanged(()=>{$()})),[$]),m.useEffect(()=>{if(!n||(g(P=>P.includes(n)?P:[...P,n]),!d.some(P=>P.id===n)))return;const R=n;window.requestAnimationFrame(()=>{document.querySelector(`[data-plugin-id="${CSS.escape(R)}"]`)?.scrollIntoView({block:"center"})}),a?.()},[n,d,a]);const Y=async R=>{y(null),h&&window.electronAPI.extensionPlugins.discard(h.token),l(null);const P=await window.electronAPI.extensionPlugins.pickAndStage(R);P.ok?"cancelled"in P||l(P.preview):y(P.error)},H=async R=>{const P=(R??N).trim();if(!P)return;y(null),I(!0),h&&window.electronAPI.extensionPlugins.discard(h.token),l(null);const ce=await window.electronAPI.extensionPlugins.stageFromUrl(P).finally(()=>{I(!1)});ce.ok?l(ce.preview):y(ce.error)},se=m.useRef(H);se.current=H,m.useEffect(()=>{if(!t)return;const R=t;let P=!1;const ce=window.setTimeout(()=>{P||Xs.has(R)||(Xs.add(R),A(R),s?.(),se.current(R).finally(()=>{Xs.delete(R)}))},0);return()=>{P=!0,window.clearTimeout(ce)}},[t,s]);const q=async(R,P=!1)=>{y(null),h&&window.electronAPI.extensionPlugins.discard(h.token),l(null),I(!0);const ce=window.electronAPI.extensionPlugins,xe=await(P?ce.marketStage(R):ce.restage(R)).finally(()=>{I(!1)});xe.ok?l(xe.preview):y(xe.error)},Q=async()=>{C(!0),M(null);try{const R=await window.electronAPI.extensionPlugins.checkUpdates();M(R.checked===0?r("No plugins installed from GitHub to check"):R.available>0?r("{{count}} update(s) available",{count:R.available}):r("All plugins are up to date"))}finally{C(!1)}},B=async()=>{if(!h)return;k(!0);const R=await window.electronAPI.extensionPlugins.commit(h.token);if(k(!1),!R.ok)y(R.error??r("Install failed"));else{A("");const P=h.existingVersion?{ok:!0}:await window.electronAPI.extensionPlugins.setEnabled(h.id,!0);Re({type:P.ok?"success":"warning",title:r("{{name}} installed",{name:h.name}),description:P.ok?void 0:P.error})}l(null)},ne=()=>{h&&window.electronAPI.extensionPlugins.discard(h.token),l(null)};return e.jsxs("div",{className:"space-y-5","data-settings-row":"plugins.enso",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"font-medium text-lg",children:[r("Enso plugins"),e.jsx(qe,{})]}),e.jsx("p",{className:"mt-1 text-muted-foreground text-sm",children:r("Installing a plugin lets it run code on this machine. Review what it asks for before confirming.")})]}),e.jsxs("div",{className:"flex shrink-0 gap-2",children:[d.length>0&&e.jsxs(S,{size:"sm",variant:"outline",disabled:L,onClick:()=>{Q()},children:[L?e.jsx(St,{}):e.jsx(Je,{className:"size-4"}),r("Check for updates")]}),e.jsxs(S,{size:"sm",onClick:()=>_(!0),children:[e.jsx($u,{className:"size-4"}),r("Marketplace")]})]})]}),e.jsxs("label",{className:"flex items-center justify-between gap-3 text-sm",children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block",children:r("Update plugins automatically")}),e.jsx("span",{className:"block text-muted-foreground text-xs",children:r("Marketplace updates that do not ask for new permissions install on their own.")})]}),e.jsx(le,{className:"shrink-0",checked:o,onCheckedChange:R=>i(R)})]}),e.jsxs("div",{className:"space-y-2.5 rounded-lg border bg-muted/30 p-3",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(Bo,{className:"flex-1",children:[e.jsx(Fo,{children:e.jsx(ai,{className:"size-4 text-muted-foreground"})}),e.jsx(_o,{value:N,placeholder:r("https://github.com/owner/repo"),onChange:R=>A(R.target.value),onKeyDown:R=>{R.key==="Enter"&&H()}})]}),e.jsx(S,{size:"sm",variant:"outline",disabled:w||O||N.trim()==="",onClick:()=>{H()},children:O?e.jsx(St,{}):r("Install from URL")})]}),e.jsxs("div",{className:"flex items-center gap-1 text-muted-foreground text-xs",children:[e.jsx("span",{className:"mr-1",children:r("Or install from")}),e.jsxs(S,{size:"xs",variant:"ghost",disabled:w||O,onClick:()=>{Y("dir")},children:[e.jsx(Bn,{className:"size-3.5"}),r("Install from folder")]}),e.jsxs(S,{size:"xs",variant:"ghost",disabled:w||O,onClick:()=>{Y("zip")},children:[e.jsx(Jc,{className:"size-3.5"}),r("Install from zip")]})]})]}),j&&e.jsx("p",{className:"text-destructive text-sm",children:j}),e.jsx(pe,{open:b,onOpenChange:_,children:e.jsxs(fe,{className:"max-w-5xl",children:[e.jsx(ge,{children:e.jsx(je,{children:r("Marketplace")})}),e.jsx(we,{children:e.jsx(Lp,{disabled:w||O,installedKey:d.map(R=>`${R.id}@${R.version}`).join(","),onInstall:R=>{_(!1),q(R,!0)}})})]})}),E&&e.jsx("p",{className:"text-muted-foreground text-sm",children:E}),V&&e.jsx(_p,{notice:V,remote:!!window.electronAPI.remote,onDismiss:()=>{window.electronAPI.extensionPlugins.dismissRegistryNotice().then(()=>F(null)).catch(R=>y(R instanceof Error?R.message:String(R)))}}),e.jsx(pe,{open:h!==null,onOpenChange:R=>!R&&!w&&ne(),children:e.jsx(fe,{children:h&&e.jsxs(e.Fragment,{children:[e.jsx(ge,{children:e.jsxs(je,{children:[h.name," ",h.version,h.existingVersion&&e.jsx("span",{className:"ml-2 text-base text-muted-foreground",children:r("updating from {{version}}",{version:h.existingVersion})})]})}),e.jsxs(we,{className:"space-y-3",children:[e.jsx(_r,{permissions:h.permissions,env:h.env,interop:h.interop,resident:h.resident,styles:h.styles,trustedUi:h.hasRenderer,events:h.events,schedules:h.schedules}),h.mcpServers.map(R=>e.jsxs("p",{className:"font-mono text-xs",children:[R.command," ",R.args.join(" ")]},R.name)),h.mcpTools.length>0&&e.jsxs("p",{className:"text-muted-foreground text-xs",children:[r("Host MCP tools it may call"),":",e.jsx("span",{className:"font-mono",children:h.mcpTools.join(", ")})]}),h.warnings.map(R=>e.jsx("p",{className:"text-muted-foreground text-xs",children:R},R))]}),e.jsxs(Ie,{children:[e.jsx(S,{size:"sm",variant:"ghost",disabled:w,onClick:ne,children:r("Cancel")}),e.jsx(S,{size:"sm",disabled:w,onClick:()=>{B()},children:w?e.jsx(St,{}):r("Install")})]})]})})}),d.length===0&&!h&&e.jsxs("div",{className:"rounded-lg border border-dashed px-3 py-10 text-center",children:[e.jsx(_t,{className:"mx-auto size-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:r("No Enso plugins installed")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:r("Browse the marketplace or install from a GitHub URL, folder or zip.")})]}),e.jsx("div",{className:"space-y-2",children:d.map(R=>e.jsxs("div",{"data-plugin-id":R.id,className:G("overflow-hidden rounded-lg border bg-card transition-colors",R.state==="crashed"&&"border-destructive/50"),children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-x-3 gap-y-2 p-3",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 basis-56 items-start gap-3",children:[e.jsx("div",{className:G("flex size-9 shrink-0 items-center justify-center rounded-md bg-muted",R.state==="enabled"?"text-foreground":"text-muted-foreground"),children:e.jsx(Qc,{pluginId:R.id,icon:R.icon,className:"size-4"})}),e.jsxs("div",{className:"min-w-0 flex-1 space-y-0.5",children:[e.jsxs("p",{className:"flex flex-wrap items-center gap-1.5 text-sm",children:[e.jsx("span",{className:"truncate font-medium",children:R.name}),e.jsx(te,{variant:"outline",className:"text-[11px]",children:R.version}),R.state==="crashed"&&e.jsx(te,{variant:"destructive",className:"text-[11px]",children:r("Stopped after crashes")}),R.availableVersion&&e.jsx(te,{className:"text-[11px]",children:r("Update")}),R.pendingVersion&&e.jsx(te,{variant:"warning",className:"text-[11px]",children:"待授权"}),R.hasRenderer&&e.jsx(te,{variant:"outline",className:"text-[11px]",children:"受信任界面"}),R.devWatch&&e.jsx(te,{variant:"secondary",className:"text-[11px]",children:"开发模式"}),R.resident&&e.jsx(te,{variant:R.running?"secondary":"outline",className:"text-[11px]",children:R.running?"常驻运行中":"常驻未运行"})]}),e.jsx("p",{className:"truncate font-mono text-muted-foreground text-xs",children:R.id}),R.availableVersion&&e.jsxs("p",{className:"mt-1 flex items-center gap-2 text-primary text-xs",children:[r("Version {{version}} is available",{version:R.availableVersion}),e.jsx(S,{size:"xs",disabled:w||O,onClick:()=>{q(R.id,R.source?.kind!=="url")},children:O?e.jsx(St,{}):r("Update")})]}),R.updateCheckError&&e.jsx("p",{className:"text-muted-foreground text-xs",children:r("Update check failed: {{reason}}",{reason:R.updateCheckError})}),R.lastError&&e.jsx(zr,{message:R.lastError.message}),x[R.id]?.map(P=>e.jsx(zr,{message:`主题加载失败:${P}`},P)),R.pendingVersion&&e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2 rounded-md border border-amber-500/50 bg-amber-500/10 px-2 py-1.5 text-amber-700 text-xs dark:text-amber-400",children:[r("{{version}} asks for more and is waiting for approval",{version:R.pendingVersion}),e.jsx(S,{size:"xs",onClick:()=>{window.electronAPI.extensionPlugins.approvePending(R.id)},children:r("Allow")}),e.jsx(S,{size:"xs",variant:"ghost",onClick:()=>{window.electronAPI.extensionPlugins.rejectPending(R.id)},children:r("Keep current")})]})]})]}),e.jsxs("div",{className:"ml-auto flex shrink-0 items-center gap-0.5",children:[R.source&&e.jsx(S,{size:"icon",variant:"ghost",disabled:w||O,"aria-label":r("Reinstall from source"),title:R.source.kind==="url"?`${r("Reinstall from source")}: ${R.source.url}`:r("Reinstall from source"),onClick:()=>{q(R.id)},children:e.jsx(Xc,{className:"size-4"})}),e.jsx(S,{size:"icon",variant:"ghost","aria-label":"产出文件",title:"产出文件",onClick:()=>c({kind:"artifacts",pluginId:R.id,pluginName:R.name}),children:e.jsx(Zc,{className:"size-4"})}),e.jsx(S,{size:"icon",variant:"ghost","aria-label":r("Usage guide"),title:r("Usage guide"),onClick:()=>D({id:R.id,name:R.name,from:"installed"}),children:e.jsx(vu,{className:"size-4"})}),e.jsx(S,{size:"icon",variant:"ghost","aria-label":r("Plugin logs"),title:r("Plugin logs"),onClick:()=>c({kind:"logs",pluginId:R.id,pluginName:R.name}),children:e.jsx($n,{className:"size-4"})}),R.configurable&&e.jsx(S,{size:"icon",variant:"ghost","aria-label":r("Configure"),title:r("Configure"),onClick:()=>c({kind:"config",pluginId:R.id,pluginName:R.name}),children:e.jsx(ed,{className:"size-4"})}),e.jsx(S,{size:"icon",variant:"ghost","aria-label":r("Uninstall"),title:r("Uninstall"),className:"text-muted-foreground hover:text-destructive",onClick:()=>{window.electronAPI.extensionPlugins.uninstall(R.id)},children:e.jsx(Me,{className:"size-4"})}),e.jsx("div",{className:"mx-1.5 h-5 w-px bg-border"}),e.jsx(le,{checked:R.state==="enabled",onCheckedChange:P=>{window.electronAPI.extensionPlugins.setEnabled(R.id,P)}})]})]}),e.jsxs("button",{type:"button","aria-expanded":p.includes(R.id),className:G("flex w-full items-center gap-1 border-t bg-muted/20 px-3 py-1.5 text-left text-xs","text-muted-foreground transition-colors hover:bg-muted/50 hover:text-foreground"),onClick:()=>g(P=>P.includes(R.id)?P.filter(ce=>ce!==R.id):[...P,R.id]),children:[p.includes(R.id)?e.jsx(ns,{className:"size-3"}):e.jsx(Mt,{className:"size-3"}),p.includes(R.id)?"收起详情":"详情",!p.includes(R.id)&&Br(R)&&e.jsx("span",{className:"ml-1 opacity-70",children:Br(R)})]}),p.includes(R.id)&&e.jsxs("div",{className:"space-y-3 border-t px-3 py-3",children:[R.interceptBreakers?.map(P=>e.jsxs("p",{className:"text-amber-600 text-xs dark:text-amber-400",children:[P.event," 检查连续失败,临时放行到"," ",new Date(P.until).toLocaleTimeString()]},P.event)),e.jsx(_r,{permissions:R.permissions,resident:R.resident,running:R.running,styles:R.themes.some(P=>P.css!==void 0),trustedUi:R.hasRenderer,events:R.events,schedules:R.schedules}),R.crossSessionInject!==void 0&&e.jsxs("div",{className:"flex items-center justify-between gap-3 text-xs",children:[e.jsxs("span",{children:[e.jsx("span",{className:"block",children:"允许向任意运行中的会话发送消息"}),e.jsx("span",{className:"block text-muted-foreground",children:"关闭时只能发到发起调用的会话;开启后定时任务、常驻进程也能向其他项目和窗口的会话发消息并触发执行"})]}),e.jsx(le,{"aria-label":"允许向任意运行中的会话发送消息",checked:R.crossSessionInject,onCheckedChange:P=>{window.electronAPI.extensionPlugins.setCrossSessionInject(R.id,P)}})]}),R.devWatch!==void 0&&e.jsxs("div",{className:"flex items-center justify-between gap-3 text-xs",children:[e.jsxs("span",{children:[e.jsx("span",{className:"block",children:"开发模式:目录改动后自动重装"}),e.jsx("span",{className:"block text-muted-foreground",children:"授权没扩大时直接替换;扩大时停下,需要从来源重新安装并同意。重启应用后关闭"})]}),e.jsx(le,{"aria-label":"开发模式:目录改动后自动重装",checked:R.devWatch,onCheckedChange:P=>{window.electronAPI.extensionPlugins.setDevWatch(R.id,P).then(ce=>{!ce.ok&&ce.error&&Re({title:ce.error})})}})]}),((R.pendingPermissions?.length??0)>0||R.pendingRenderer)&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:"待同意"}),e.jsx(Di,{permissions:R.pendingPermissions??[],styles:R.pendingRenderer}),R.pendingRenderer&&e.jsx("p",{className:"text-amber-700 text-xs dark:text-amber-400",children:"新增界面代码:运行在主界面里,不受权限清单约束"})]})]})]},R.id))}),e.jsx(pe,{open:f!==null,onOpenChange:R=>!R&&c(null),children:e.jsxs(fe,{children:[e.jsx(ge,{children:e.jsxs(je,{children:[f?.kind==="config"?r("Configure"):f?.kind==="logs"?r("Plugin logs"):"产出文件",f?` · ${f.pluginName}`:""]})}),e.jsxs(we,{className:"space-y-4",children:[f?.kind==="config"&&e.jsx(Fp,{pluginId:f.pluginId,plain:!0}),f?.kind==="logs"&&e.jsx(Up,{pluginId:f.pluginId,plain:!0}),f?.kind==="artifacts"&&e.jsx(Kp,{pluginId:f.pluginId,plain:!0})]})]})}),e.jsx(Tp,{pluginId:K?.id??null,name:K?.name??"",from:K?.from??"installed",homepage:K?.homepage,onClose:()=>D(null)})]})}function Gp(t,s){return[[t.skills.length,s("Skills")],[t.commands.length,s("Commands")],[t.agents.length,s("Agent types")],[t.mcpServers.length,"MCP"],[t.hooks.length,"Hooks"]].filter(([n])=>n>0).map(([n,a])=>`${a} ${n}`).join(" · ")}function Nt({label:t,items:s}){return s.length===0?null:e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("p",{className:"font-medium text-muted-foreground text-xs",children:t}),s.map(n=>e.jsx("p",{className:"break-all font-mono text-[11px]",children:n},n))]})}function Hp({plugin:t,entry:s,onToggle:n}){const{t:a}=z(),[r,o]=m.useState(!1),{components:i}=t,d=Gp(i,a);return e.jsxs("div",{className:"rounded-md border","data-settings-row":`plugins.${t.key}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 px-3 py-2",children:[e.jsxs("button",{type:"button",className:"flex min-w-0 flex-1 items-center gap-2 text-left",onClick:()=>o(u=>!u),children:[e.jsx(Mt,{className:G("h-4 w-4 shrink-0 text-muted-foreground transition-transform",r&&"rotate-90")}),e.jsx("span",{className:"shrink-0 font-medium text-sm",children:t.name}),t.version&&e.jsx(te,{variant:"outline",className:"shrink-0 text-[11px]",children:t.version}),t.marketplace&&e.jsx(te,{variant:"secondary",className:"shrink-0 text-[11px]",children:t.marketplace}),e.jsx("span",{className:"min-w-0 truncate text-muted-foreground text-xs",children:d||(i.unsupported.length>0?`${a("Not supported")}: ${i.unsupported.join(", ")}`:a("No supported components"))})]}),e.jsx(le,{checked:s?.enabled===!0,onCheckedChange:n})]}),r&&e.jsxs("div",{className:"space-y-2 border-t px-3 py-2",children:[t.description&&e.jsx("p",{className:"text-muted-foreground text-xs",children:t.description}),e.jsx(Nt,{label:a("Skills"),items:i.skills}),e.jsx(Nt,{label:a("Commands"),items:i.commands.map(u=>`/${u}`)}),e.jsx(Nt,{label:a("Agent types"),items:i.agents}),e.jsx(Nt,{label:a("MCP servers (run when a session starts)"),items:i.mcpServers.map(u=>`${u.name}: ${u.target}`)}),e.jsx(Nt,{label:a("Hooks (run automatically on local sessions)"),items:i.hooks.map(u=>`${u.event}: ${u.command}`)}),e.jsx(Nt,{label:a("Not supported"),items:i.unsupported})]})]})}function Wp(){const{t}=z(),s=v(c=>c.plugins),n=v(c=>c.addPlugins),a=v(c=>c.setPluginEnabled),r=v(c=>c.removePlugin),[o,i]=m.useState(null),d=m.useCallback(async()=>{i(null);try{i(await window.electronAPI.assets.listInstalledPlugins())}catch{i([])}},[]);m.useEffect(()=>{d()},[d]);const u=new Map(s.map(c=>[c.key,c])),x=new Set((o??[]).map(c=>c.key)),h=o?s.filter(c=>!x.has(c.key)):[],l=s.filter(c=>c.enabled).length,f=(c,p)=>{const g=u.get(c.key);if(g){a(g.id,p);return}n([{id:crypto.randomUUID(),key:c.key,name:c.name,description:c.description,...c.version?{version:c.version}:{},source:c.marketplace||"Claude Code",enabled:p}])};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-end justify-between gap-4","data-settings-row":"plugins.root",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"font-medium text-lg",children:[t("Claude Code plugins"),e.jsx(qe,{}),l>0&&e.jsx("span",{className:"ml-2 font-normal text-muted-foreground text-xs",children:t("{{count}} enabled",{count:l})})]}),e.jsx("p",{className:"text-muted-foreground text-sm",children:t("Plugins installed in Claude Code. Each one is switched on or off as a whole here; changes apply to new sessions.")})]}),e.jsxs(S,{variant:"outline",size:"sm",onClick:d,disabled:o===null,children:[e.jsx(Je,{className:"mr-1.5 h-4 w-4"}),t("Rescan")]})]}),o===null?e.jsx("div",{className:"flex justify-center py-10",children:e.jsx(St,{className:"size-5"})}):o.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx(_t,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:t("No Claude Code plugins found")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:t("Install plugins with /plugin in Claude Code, then rescan.")})]}):e.jsx("div",{className:"space-y-2",children:o.map(c=>e.jsx(Hp,{plugin:c,entry:u.get(c.key),onToggle:p=>f(c,p)},c.key))}),h.length>0&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"font-medium text-muted-foreground text-xs",children:t("No longer installed in Claude Code")}),h.map(c=>e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md px-3 py-2 hover:bg-accent/50",children:[e.jsx("span",{className:"text-muted-foreground text-sm line-through",children:c.name}),e.jsx(S,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-destructive",onClick:()=>r(c.id),children:e.jsx(Me,{className:"h-3.5 w-3.5"})})]},c.id))]})]})}const zt={mask:"Mask",warn:"Warn only",block:"Block"},Yp={email:"Email",phone:"Phone number",idCard:"ID card number",bankCard:"Bank card number",ip:"IP address"},yn={mask:"text-sky-600 dark:text-sky-400",warn:"text-amber-600 dark:text-amber-400",block:"text-red-600 dark:text-red-400"},Jp=[1,7,30],Qp={1:"Today",7:"7D",30:"30D"};function Xp(t){const s=new Map;for(const n of t.report.hits){const a=s.get(n.token);a?a.count+=n.count:s.set(n.token,{label:`${n.kind} ${n.preview}`,count:n.count})}return[...s.values()].map(n=>n.count>1?`${n.label} ×${n.count}`:n.label).join(", ")}function Zs({value:t,onChange:s}){const{t:n}=z(),a=Object.fromEntries(Object.keys(zt).map(r=>[r,n(zt[r])]));return e.jsxs(ae,{items:a,value:t,onValueChange:r=>s(r),children:[e.jsx(re,{className:"w-32",children:e.jsx(oe,{})}),e.jsx(ie,{children:Object.entries(a).map(([r,o])=>e.jsx(ee,{value:r,children:o},r))})]})}function en({label:t,hint:s,value:n,onCommit:a,rowId:r}){const[o,i]=m.useState(n.join(`
22
+ `):"",Cr=t=>{const s={type:t.transport};return t.command&&(s.command=t.command),t.args&&t.args.length>0&&(s.args=t.args),t.env&&Object.keys(t.env).length>0&&(s.env=t.env),t.url&&(s.url=t.url),t.headers&&Object.keys(t.headers).length>0&&(s.headers=t.headers),s};function Rx({server:t,onClose:s}){const{t:n}=z(),a=v(U=>U.addMcpServers),r=v(U=>U.updateMcpServer),o=t==="new",[i,d]=m.useState("form"),[u,x]=m.useState(""),[h,l]=m.useState(""),[f,c]=m.useState(""),[p,g]=m.useState(""),[w,k]=m.useState("stdio"),[j,y]=m.useState(""),[N,A]=m.useState(""),[O,I]=m.useState(""),[L,C]=m.useState(""),[E,M]=m.useState(""),[V,F]=m.useState(""),[b,B]=m.useState(""),[K,D]=m.useState(""),[$,Y]=m.useState(0),[H,se]=m.useState(null),q=()=>({description:h.trim()||void 0,oauthClientName:w!=="stdio"&&f.trim()||void 0,oauthMetadataUrl:w!=="stdio"&&p.trim()||void 0,connectTimeoutSec:yr(V,Ex),callTimeoutSec:yr(b,Mx)}),Q=U=>{x(U.name),k(U.transport),y(U.command??""),A((U.args??[]).join(`
23
+ `)),I(kr(U.env&&Object.keys(U.env).length>0?U.env:void 0)),C(U.url??""),M(vr(U.headers))},_=()=>{const U={type:w};if(w==="stdio"){U.command=j.trim();const Z=wr(N);Z&&(U.args=Z);const X=Nr(O);X&&(U.env=X)}else{U.url=L.trim();const Z=jr(E);Z&&(U.headers=Z)}return JSON.stringify(U,null,2)},ne=(U,Z)=>{const X=(Z??U.name).trim(),ue=U.env&&Object.keys(U.env).length>0?U.env:void 0,Ne=U.args&&U.args.length>0?U.args:void 0;return U.transport==="stdio"?{name:X,transport:U.transport,command:(U.command??"").trim(),args:Ne,env:ue,url:void 0,headers:void 0,...q()}:{name:X,transport:U.transport,url:(U.url??"").trim(),headers:U.headers&&Object.keys(U.headers).length>0?U.headers:void 0,command:void 0,args:void 0,env:void 0,...q()}};m.useEffect(()=>{if(!t)return;const U=t==="new"?null:t;d("form"),x(U?.name??""),l(U?.description??""),c(U?.oauthClientName??""),g(U?.oauthMetadataUrl??""),k(U?.transport??"stdio"),y(U?.command??""),A((U?.args??[]).join(`
24
+ `)),I(kr(U?.env)),C(U?.url??""),M(vr(U?.headers)),F(U?.connectTimeoutSec?.toString()??""),B(U?.callTimeoutSec?.toString()??""),D(""),Y(Z=>Z+1),se(null)},[t]);const R=U=>n(U==="invalid-json"?"Invalid JSON":"No MCP servers found in JSON"),P=U=>{if(U===i)return;if(U==="json"){D(_()),Y(ue=>ue+1),se(null),d("json");return}const Z=Hs(K);if(!Z.ok){if(Z.error==="invalid-json"&&K.trim()){se(R(Z.error));return}se(null),d("form");return}if(Z.servers.length!==1){se(n("JSON must describe a single MCP server to switch to the form"));return}const X=Z.servers[0];Q({...X,name:u.trim()||X.name}),se(null),d("form")},ce=()=>{const U=Hs(K);if(!U.ok){se(R(U.error));return}if(U.servers.length===1){const[Z]=U.servers;D(JSON.stringify(Cr(Z),null,2)),Y(X=>X+1),u.trim()||x(Z.name)}else D(JSON.stringify({mcpServers:Object.fromEntries(U.servers.map(Z=>[Z.name,Cr(Z)]))},null,2)),Y(Z=>Z+1);se(null)},xe=!!u.trim()&&(w==="stdio"?!!j.trim():!!L.trim()),Pe=i==="json"?!!K.trim():xe,De=()=>{if(!t||!Pe)return;if(i==="json"){const Z=Hs(K);if(!Z.ok){se(R(Z.error));return}if(!o&&Z.servers.length!==1){se(n("JSON must describe a single MCP server"));return}if(o){const X=Z.servers.length===1;if(a(Z.servers.map(Ne=>({...ne(Ne,X&&u.trim()?u:Ne.name),...X?{}:{description:void 0},id:crypto.randomUUID(),source:"Manual",enabled:!0})))===0){se(n("This MCP server already exists"));return}}else r(t.id,ne(Z.servers[0],u.trim()||Z.servers[0].name));s();return}const U=w==="stdio"?{name:u.trim(),transport:w,command:j.trim(),args:wr(N),env:Nr(O),url:void 0,headers:void 0,...q()}:{name:u.trim(),transport:w,url:L.trim(),headers:jr(E),command:void 0,args:void 0,env:void 0,...q()};if(o){if(a([{...U,id:crypto.randomUUID(),source:"Manual",enabled:!0}])===0){se(n("This MCP server already exists"));return}}else r(t.id,U);s()};return e.jsx(pe,{open:t!==null,onOpenChange:U=>!U&&s(),children:e.jsxs(fe,{children:[e.jsx(ge,{children:e.jsx(je,{children:n(o?"Add MCP Server":"Edit MCP Server")})}),e.jsxs(we,{className:"space-y-4",children:[e.jsx(Ft,{value:i,onValueChange:U=>P(U),children:e.jsxs(Ut,{children:[e.jsx(Ke,{value:"form",children:n("Form")}),e.jsx(Ke,{value:"json",children:n("JSON")})]})}),e.jsxs(me,{children:[e.jsx(he,{children:n("Name")}),e.jsx(J,{value:u,onChange:U=>x(U.target.value)})]}),e.jsxs(me,{children:[e.jsx(he,{children:n("Description (optional)")}),e.jsx(J,{value:h,onChange:U=>l(U.target.value),placeholder:n("One line telling the model what this server is for")})]}),i==="json"?e.jsxs(me,{children:[e.jsxs("div",{className:"flex w-full items-center justify-between",children:[e.jsx(he,{children:n("JSON configuration")}),e.jsx(S,{variant:"ghost",size:"sm",className:"h-7 px-2",onClick:ce,children:n("Format")})]}),e.jsx(wi,{fileName:"mcp.json",value:K,epoch:$,onChange:D}),e.jsx("p",{className:"text-muted-foreground text-xs",children:n("Paste a server object or mcpServers JSON from Cursor / Claude Desktop")})]}):e.jsxs(e.Fragment,{children:[e.jsxs(me,{children:[e.jsx(he,{children:n("Transport")}),e.jsxs(ae,{items:ya.map(U=>({value:U,label:U})),value:w,onValueChange:U=>k(U),children:[e.jsx(re,{className:"w-full",children:e.jsx(oe,{})}),e.jsx(ie,{zIndex:st.DROPDOWN_IN_MODAL,children:ya.map(U=>e.jsx(ee,{value:U,children:U},U))})]})]}),w==="stdio"?e.jsxs(e.Fragment,{children:[e.jsxs(me,{children:[e.jsx(he,{children:n("Command")}),e.jsx(J,{value:j,onChange:U=>y(U.target.value),placeholder:"npx",className:"font-mono text-xs"})]}),e.jsxs(me,{children:[e.jsx(he,{children:n("Arguments (one per line)")}),e.jsx(He,{value:N,onChange:U=>A(U.target.value),rows:3,className:"font-mono text-xs"})]}),e.jsxs(me,{children:[e.jsx(he,{children:n("Environment variables (KEY=VALUE, one per line)")}),e.jsx(He,{value:O,onChange:U=>I(U.target.value),rows:3,className:"font-mono text-xs"})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs(me,{children:[e.jsx(he,{children:n("URL")}),e.jsx(J,{value:L,onChange:U=>C(U.target.value),placeholder:"https://...",className:"font-mono text-xs"})]}),e.jsxs(me,{children:[e.jsx(he,{children:n("Headers (Name: value, one per line)")}),e.jsx(He,{value:E,onChange:U=>M(U.target.value),rows:2,placeholder:"Authorization: Bearer <token>",className:"font-mono text-xs"})]}),e.jsxs(me,{children:[e.jsx(he,{children:n("OAuth client name (optional)")}),e.jsx(J,{value:f,onChange:U=>c(U.target.value),placeholder:n("For servers that only accept known OAuth clients")})]}),e.jsxs(me,{children:[e.jsx(he,{children:n("OAuth authorization server metadata URL (optional)")}),e.jsx(J,{value:p,onChange:U=>g(U.target.value),placeholder:n("Use when the server advertises a wrong authorization server or none"),className:"font-mono text-xs"})]})]}),e.jsxs(me,{children:[e.jsx(he,{children:n("Connection timeout (seconds)")}),e.jsx(J,{inputMode:"numeric",value:V,onChange:U=>F(U.target.value),placeholder:String(Ix/1e3)})]}),e.jsxs(me,{children:[e.jsx(he,{children:n("Tool call timeout (seconds)")}),e.jsx(J,{inputMode:"numeric",value:b,onChange:U=>B(U.target.value),placeholder:String(Ax/1e3)})]})]}),H&&e.jsx("p",{className:"t-shake-in text-destructive text-xs",children:H},H)]}),e.jsxs(Ie,{children:[e.jsx(S,{variant:"outline",size:"sm",onClick:s,children:n("Cancel")}),e.jsx(S,{size:"sm",disabled:!Pe,onClick:De,children:n("Save")})]})]})})}function Ox({status:t}){const{t:s}=z();return t.state==="connecting"?e.jsx(te,{variant:"outline",className:"shrink-0 animate-pulse text-[11px] text-muted-foreground",children:s("Connecting")}):t.state==="ready"?e.jsx(te,{variant:"success",className:"shrink-0 text-[11px]",children:s("{{count}} tools",{count:t.toolCount??0})}):t.state==="unauthorized"?e.jsx(te,{variant:"warning",className:"shrink-0 text-[11px]",children:s("Not authorized")}):t.state==="idle"?e.jsx(te,{variant:"outline",className:"shrink-0 text-[11px] text-muted-foreground",children:s("Authorized, pending connection")}):e.jsx(te,{variant:"error",className:"shrink-0 text-[11px]",title:t.error,children:s("Connection failed")})}function Dx(){const{t}=z(),s=v(M=>M.mcpServers),n=v(M=>M.updateMcpServer),a=v(M=>M.setMcpServersEnabled),r=v(M=>M.removeMcpServer),o=ut(M=>M.statuses),i=ut(M=>M.authorized),d=ut(M=>M.pending),u=ut(M=>M.authorize),x=ut(M=>M.revoke);m.useEffect(()=>ut.getState().bind(),[]);const[h,l]=m.useState(!1),[f,c]=m.useState(null),p=async M=>{await u(M),c(ut.getState().authorized[M]===!0?M:null)},[g,w]=m.useState(null),[k,j]=m.useState(""),y=s.filter(M=>Oo(k,[M.name,M.source,M.transport,M.url,M.command,...M.args??[]])),N=y.map(M=>M.id),A=Do(N),O=s.filter(M=>M.enabled).length,I=s.filter(M=>M.enabled).map(M=>M.id),L=hs(I,M=>window.electronAPI.assets.mcpOccupancy(M)),C=s.filter(M=>M.enabled&&M.loadMode!=="deferred").map(M=>M.id),E=ds(C,L.rows);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-end justify-between gap-4","data-settings-row":"mcp.root",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"font-medium text-lg",children:[t("MCP Servers"),e.jsx(qe,{}),s.length>0&&e.jsxs("span",{className:"ml-2 font-normal text-muted-foreground text-xs",children:[t("{{enabled}}/{{total}} enabled",{enabled:O,total:s.length}),e.jsx(ms,{tokens:E})]})]}),e.jsx("p",{className:"text-muted-foreground text-sm",children:t("Model Context Protocol servers available to this app")})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>l(!0),children:[e.jsx(cs,{className:"mr-1.5 h-4 w-4"}),t("Import from local apps")]}),e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>w("new"),children:[e.jsx(Oe,{className:"mr-1.5 h-4 w-4"}),t("Add MCP server")]})]})]}),s.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx(Lo,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:t("No MCP servers yet")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:t("Import MCP servers from local apps or add one manually to get started")})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx(zo,{query:k,onQueryChange:j,placeholder:t("Filter MCP servers..."),allSelected:A.allSelected,someSelected:A.someSelected,onToggleSelectAll:A.toggleAll,onEnable:()=>a(A.selectedIds,!0),onDisable:()=>a(A.selectedIds,!1),selectDisabled:y.length===0,actionDisabled:A.selectedIds.length===0}),y.length===0?e.jsx("p",{className:"px-3 py-6 text-center text-muted-foreground text-xs",children:t("No results")}):e.jsx("div",{className:"space-y-1",children:y.map(M=>{const V=o[M.id]??o[M.name],F=d[M.id]===!0,b=M.transport!=="stdio"&&i[M.id]!==!0,B=M.loadMode==="deferred";return e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"group flex items-center justify-between gap-3 rounded-md px-3 py-2 transition-colors hover:bg-accent/50","data-settings-row":`mcp.${M.id}`,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(Qe,{checked:A.isSelected(M.id),onCheckedChange:K=>A.toggleOne(M.id,K)}),e.jsx("span",{className:G("shrink-0 font-medium text-sm",!M.enabled&&"text-muted-foreground line-through"),children:M.name}),e.jsx(te,{variant:"outline",className:"shrink-0 text-[11px]",children:M.transport}),e.jsx(te,{variant:"secondary",className:"shrink-0 text-[11px]",children:M.source}),V&&e.jsx(Ox,{status:V}),e.jsx("span",{className:"min-w-0 truncate font-mono text-muted-foreground text-xs",children:M.url??[M.command,...M.args??[]].join(" ")})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[(b||V?.state==="unauthorized")&&e.jsxs(S,{variant:"outline",size:"sm",className:"h-7",disabled:F,onClick:()=>{p(M.id)},children:[F?e.jsx(Ae,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):e.jsx(Kc,{className:"mr-1.5 h-3.5 w-3.5"}),t(F?"Authorizing":"Authorize")]}),i[M.id]===!0&&e.jsx(S,{variant:"ghost",size:"icon",title:t("Revoke authorization"),className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",onClick:()=>{x(M.id)},children:e.jsx(qc,{className:"h-3.5 w-3.5"})}),e.jsx(us,{row:L.rows[M.id],pending:M.enabled&&L.pending&&!L.rows[M.id]}),e.jsx(Ft,{value:B?"deferred":"direct",onValueChange:K=>n(M.id,{loadMode:K==="deferred"?"deferred":"direct"}),title:t("On demand: tool descriptions are not preloaded into context; the model connects through the mcp tool when needed. Suits servers with many or rarely used tools. Takes effect in new conversations."),children:e.jsxs(Ut,{"aria-label":t("Load mode"),children:[e.jsx(Ke,{value:"direct",className:"h-6 px-2 text-xs sm:h-6 sm:text-xs",children:t("Always loaded")}),e.jsx(Ke,{value:"deferred",className:"h-6 px-2 text-xs sm:h-6 sm:text-xs",children:t("On demand")})]})}),e.jsx(le,{checked:M.enabled,onCheckedChange:K=>n(M.id,{enabled:K})}),e.jsx(S,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",onClick:()=>w(M),children:e.jsx(lt,{className:"h-3.5 w-3.5"})}),e.jsx(S,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity hover:text-destructive group-hover:opacity-100",onClick:()=>r(M.id),children:e.jsx(Me,{className:"h-3.5 w-3.5"})})]})]}),f===M.id&&e.jsx("p",{className:"px-3 text-muted-foreground text-xs",children:t("Authorized. Conversations that already include this server can use it on the next message.")})]},M.id)})})]}),e.jsx(Vn,{kind:"mcp",open:h,onOpenChange:l}),e.jsx(Rx,{server:g,onClose:()=>w(null)})]})}const Lx=["fact","preference","decision","plan","procedure","learning","context","event"],zx=.9,_x=.7,Bx=.5;function Fx(t){return Number.isFinite(t)?t>=zx?"critical":t>=_x?"important":t>=Bx?"useful":"low":"low"}const Sr=3,Ir={PERSON:340,ORGANIZATION:20,TEAM:20,PRODUCT:210,TOOL:210,SYSTEM:250,SERVICE:250,PLATFORM:250,CONCEPT:160,METHOD:160,TECHNIQUE:160,EVENT:40,PROJECT:280,DOCUMENT:90,TERM:190};function Ni(t){if(Ir[t]!==void 0)return Ir[t];let s=0;for(let n=0;n<t.length;n++)s=s*17+t.charCodeAt(n)>>>0;return s%360}const Ws=22,Ux=64;function $x(t,s){if(s<=1)return Ws;const n=Math.sqrt(Math.max(1,t))/Math.sqrt(s);return Math.round(Ws+(Ux-Ws)*Math.min(1,n))}function Vx(t,s,n){const a=Math.max(1,...t.map(o=>o.memoryCount)),r=new Set(t.map(o=>o.id));return[...t.map(o=>({data:{id:o.id,label:o.name,size:$x(o.memoryCount,a),color:ki(Ni(o.entityType),n),entityType:o.entityType,memoryCount:o.memoryCount,spaceLabel:o.spaceLabel}})),...s.filter(o=>r.has(o.source)&&r.has(o.target)&&o.source!==o.target).map(o=>({data:{id:`${o.source}->${o.target}:${o.relation}`,source:o.source,target:o.target,label:o.relation.replace(/_/g," ").toLowerCase(),width:1+o.strength*2.5}}))]}function Kx(t,s){const n=new Map;for(const a of t)n.set(a.entityType,(n.get(a.entityType)??0)+1);return[...n.entries()].map(([a,r])=>({entityType:a,count:r,color:ki(Ni(a),s)})).sort((a,r)=>r.count-a.count||a.entityType.localeCompare(r.entityType))}function qx(t){const s=t?"#e7e7e9":"#1c1c1f";return[{selector:"node",style:{"background-color":"data(color)","background-opacity":.85,width:"data(size)",height:"data(size)",label:"data(label)","font-size":11,color:s,"text-valign":"bottom","text-margin-y":4,"text-max-width":"120px","text-wrap":"ellipsis","border-width":0,"transition-property":"opacity, border-width","transition-duration":150}},{selector:"edge",style:{width:"data(width)","line-color":t?"#4b4b52":"#c9c9d1","curve-style":"bezier",opacity:.65,"font-size":9,color:s,"text-opacity":0}},{selector:"edge:selected, edge.highlighted",style:{"text-opacity":.85,opacity:1}},{selector:"node:selected",style:{"border-width":3,"border-color":s,"background-opacity":1}},{selector:".dimmed",style:{opacity:.18,"text-opacity":.25}}]}function ki(t,s){return Gx(t,s?.62:.68,s?.58:.52)}function Gx(t,s,n){const a=(1-Math.abs(2*n-1))*s,r=a*(1-Math.abs(t/60%2-1)),o=n-a/2,[i,d,u]=t<60?[a,r,0]:t<120?[r,a,0]:t<180?[0,a,r]:t<240?[0,r,a]:t<300?[r,0,a]:[a,0,r],x=h=>Math.round((h+o)*255).toString(16).padStart(2,"0");return`#${x(i)}${x(d)}${x(u)}`}let Ar=!1;function Hx(){Ar||(ni.use(pu),Ar=!0)}const Er={name:"fcose",animate:!1,randomize:!1,nodeRepulsion:8e3,idealEdgeLength:90,nodeSeparation:90,padding:24,fit:!0};function Wx({graph:t,selectedId:s,onSelect:n,memories:a,loading:r,onInterpret:o,interpreting:i}){const{t:d}=z(),u=m.useRef(null),x=m.useRef(null),h=m.useRef(n);h.current=n;const[l,f]=m.useState(null),c=m.useMemo(()=>typeof document<"u"&&document.documentElement.classList.contains("dark"),[]);m.useEffect(()=>{const w=u.current;if(!w||t.nodes.length===0)return;Hx();const k=ni({container:w,elements:Vx(t.nodes,t.edges,c),style:qx(c),minZoom:.2,maxZoom:2.5,wheelSensitivity:.2});return k.layout(Er).run(),k.on("tap","node",j=>h.current(j.target.id())),k.on("tap",j=>{j.target===k&&h.current(null)}),x.current=k,()=>{k.destroy(),x.current=null}},[t.nodes,t.edges,c]),m.useEffect(()=>{const w=x.current;w&&w.batch(()=>{if(w.elements().removeClass("dimmed").unselect(),!s)return;const k=w.getElementById(s);if(k.empty())return;const j=k.closedNeighborhood();w.elements().difference(j).addClass("dimmed"),k.select()})},[s]);const p=m.useMemo(()=>Kx(t.nodes,c),[t.nodes,c]),g=t.nodes.find(w=>w.id===s)??null;return m.useEffect(()=>{const w=x.current;!w||s||w.batch(()=>{w.elements().removeClass("dimmed"),l&&w.nodes().filter(k=>k.data("entityType")!==l).addClass("dimmed")})},[l,s]),t.nodes.length===0?e.jsx("p",{className:"rounded-lg border px-3 py-6 text-muted-foreground text-sm",children:d(r?"Loading…":"No entities yet. Turn on entity extraction and store a few memories first.")}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"relative overflow-hidden rounded-lg border bg-muted/20",children:[e.jsx("div",{ref:u,className:"h-[440px] w-full"}),e.jsxs("div",{className:"absolute right-2 bottom-2 flex gap-1",children:[e.jsx(S,{size:"sm",variant:"outline",onClick:()=>x.current?.fit(void 0,24),title:d("Fit to view"),children:d("Fit")}),e.jsx(S,{size:"sm",variant:"outline",onClick:()=>x.current?.layout(Er).run(),title:d("Re-run layout"),children:d("Relayout")})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:d("Colour = entity type · size = how many memories mention it",{})}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:p.map(w=>e.jsxs("button",{type:"button",onClick:()=>f(l===w.entityType?null:w.entityType),className:G("inline-flex items-center gap-1.5 rounded-full border px-2 py-0.5 text-xs transition-colors",l===w.entityType?"border-foreground/40 bg-accent":"hover:bg-accent/50"),children:[e.jsx("span",{className:"size-2.5 shrink-0 rounded-full",style:{backgroundColor:w.color}}),e.jsx("span",{className:"text-muted-foreground",children:w.entityType.toLowerCase()}),e.jsx("span",{className:"tabular-nums",children:w.count})]},w.entityType))}),e.jsx("p",{className:"text-muted-foreground text-xs",children:d("{{shown}} of {{total}} entities",{shown:String(t.nodes.length),total:String(t.totalEntities)})})]}),g&&e.jsxs("section",{className:"space-y-2 rounded-lg border p-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"flex items-center gap-2 text-sm",children:[e.jsx("span",{className:"truncate font-medium",children:g.name}),e.jsx(te,{variant:"secondary",children:g.entityType})]}),e.jsx("p",{className:"text-muted-foreground text-xs",children:d("{{count}} memories · {{space}}",{count:String(g.memoryCount),space:g.spaceLabel})})]}),e.jsx(S,{size:"sm",variant:"outline",disabled:i,onClick:()=>o(g.id),children:d(i?"Interpreting…":"Interpret")})]}),e.jsxs("ul",{className:"divide-y rounded-lg border",children:[a.length===0&&e.jsx("li",{className:"px-3 py-4 text-muted-foreground text-sm",children:d("Loading…")}),a.map(w=>e.jsxs("li",{className:"space-y-0.5 px-3 py-2",children:[e.jsxs("p",{className:"flex items-center gap-2 text-sm",children:[w.isCrystal&&e.jsx("span",{title:d("Crystal"),children:"★"}),e.jsx("span",{className:"truncate",children:w.title}),e.jsx(te,{variant:"secondary",children:w.unitType})]}),e.jsx("p",{className:"line-clamp-2 text-muted-foreground text-xs",children:w.contentSummary})]},w.id))]})]})]})}function Yx({tree:t,loading:s,selected:n,onToggle:a,onInterpretGroup:r,interpreting:o}){const{t:i}=z(),[d,u]=m.useState(new Set);return t.length===0?e.jsx("p",{className:"rounded-lg border px-3 py-6 text-muted-foreground text-sm",children:i(s?"Loading…":"No memories yet.")}):e.jsx("ul",{className:"divide-y rounded-lg border",children:t.map(x=>{const h=d.has(x.id),l=(x.children??[]).map(f=>f.memoryId).filter(f=>!!f);return e.jsxs("li",{children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 px-3 py-2",children:[e.jsx("button",{type:"button",className:"min-w-0 flex-1 text-left",onClick:()=>{const f=new Set(d);f.delete(x.id)||f.add(x.id),u(f)},children:e.jsxs("p",{className:"flex items-center gap-2 text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:h?"▾":"▸"}),e.jsx("span",{className:"truncate",children:x.label}),e.jsx(te,{variant:"secondary",children:x.count})]})}),e.jsx(S,{size:"sm",variant:"ghost",className:"shrink-0",disabled:o||l.length===0,onClick:()=>r(x),children:i("Interpret")})]}),h&&e.jsxs("ul",{className:"divide-y border-t bg-muted/20",children:[(x.children??[]).map(f=>e.jsxs("li",{className:"flex items-center gap-2 px-3 py-2",children:[f.memoryId&&e.jsx(Qe,{checked:n.has(f.memoryId),onCheckedChange:()=>f.memoryId&&a(f.memoryId),"aria-label":i("Select memory")}),e.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-2",children:[f.isCrystal&&e.jsx("span",{title:i("Crystal"),children:"★"}),e.jsx("span",{className:"truncate text-sm",children:f.label})]})]},f.id)),x.count>(x.children?.length??0)&&e.jsx("li",{className:"px-3 py-2 text-muted-foreground text-xs",children:i("Showing {{shown}} of {{total}}",{shown:String(x.children?.length??0),total:String(x.count)})})]})]},x.id)})})}const Jx=120,Qx=30,Xx={nodes:[],edges:[],totalEntities:0};function Zx({revision:t=0}={}){const{t:s}=z(),[n,a]=m.useState("graph"),[r,o]=m.useState("unitType"),[i,d]=m.useState(Xx),[u,x]=m.useState([]),[h,l]=m.useState(!0),[f,c]=m.useState(null),[p,g]=m.useState([]),[w,k]=m.useState(new Set),[j,y]=m.useState(null),[N,A]=m.useState(!1),[O,I]=m.useState(null),[L,C]=m.useState(!1),E=m.useCallback(()=>{l(!0);const $=()=>l(!1);n==="graph"?window.electronAPI.memory.graph({limit:Jx,minMemories:1}).then(d).finally($):window.electronAPI.memory.tree({groupBy:r,limitPerGroup:Qx}).then(x).finally($)},[n,r]);m.useEffect(E,[E]);const M=m.useRef(E);M.current=E,m.useEffect(()=>window.electronAPI.memory.onChanged(()=>M.current()),[]);const V=m.useRef(t);m.useEffect(()=>{V.current!==t&&(V.current=t,E())},[t,E]),m.useEffect(()=>{if(!f){g([]);return}window.electronAPI.memory.graphEntity(f).then(g)},[f]);const F=async $=>{A(!0),y(null);try{y(await window.electronAPI.memory.insight($))}finally{A(!1)}},b=async()=>{C(!0);try{const $=await window.electronAPI.memory.crystallize({memoryIds:[...w]});I($),$.ok&&k(new Set)}finally{C(!1)}},B=[{value:"graph",label:s("Graph")},{value:"tree",label:s("Tree")}],K=[{value:"unitType",label:s("By type")},{value:"entity",label:s("By entity")},{value:"time",label:s("By month")}],D=w.size>=Sr;return e.jsxs("div",{className:"space-y-4","data-settings-row":"memory.knowledge",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-medium text-sm",children:s("Knowledge")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Browse what the agent knows as a graph or a tree, ask for an interpretation, and consolidate related memories into a crystal.")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(ae,{value:n,items:B,onValueChange:$=>a($==="tree"?"tree":"graph"),children:[e.jsx(re,{size:"sm",className:"w-32",children:e.jsx(oe,{})}),e.jsx(ie,{children:B.map($=>e.jsx(ee,{value:$.value,children:$.label},$.value))})]}),n==="tree"&&e.jsxs(ae,{value:r,items:K,onValueChange:$=>o($),children:[e.jsx(re,{size:"sm",className:"w-36",children:e.jsx(oe,{})}),e.jsx(ie,{children:K.map($=>e.jsx(ee,{value:$.value,children:$.label},$.value))})]}),e.jsx("span",{className:"flex-1"}),n==="tree"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:G("text-xs",D?"text-foreground":"text-muted-foreground"),children:s("{{count}} selected",{count:String(w.size)})}),e.jsx(S,{size:"sm",variant:"outline",disabled:!D||L,onClick:()=>{b()},children:L?s("Synthesizing…"):s("Crystallize ({{min}}+)",{min:String(Sr)})})]})]}),n==="graph"?e.jsx(Wx,{graph:i,loading:h,selectedId:f,onSelect:c,memories:p,interpreting:N,onInterpret:$=>{F({entityId:$})}}):e.jsx(Yx,{tree:u,loading:h,selected:w,interpreting:N,onToggle:$=>{const Y=new Set(w);Y.delete($)||Y.add($),k(Y)},onInterpretGroup:$=>{const Y=($.children??[]).map(H=>H.memoryId).filter(H=>!!H);F({memoryIds:Y})}}),e.jsx(pe,{open:j!==null,onOpenChange:$=>!$&&y(null),children:e.jsxs(fe,{children:[e.jsxs(ge,{children:[e.jsx(je,{children:s("Interpretation")}),j?.ok&&e.jsx(Ve,{children:s("Based on {{count}} memories",{count:String(j.sourceCount??0)})})]}),e.jsx(we,{children:j?.ok?e.jsx("p",{className:"whitespace-pre-wrap text-sm",children:j.text}):e.jsx("p",{className:"text-destructive text-sm",children:j?.error})}),e.jsx(Ie,{children:e.jsx(Et,{render:e.jsx(S,{variant:"outline",size:"sm"}),children:s("Close")})})]})}),e.jsx(pe,{open:O!==null,onOpenChange:$=>!$&&I(null),children:e.jsxs(fe,{children:[e.jsxs(ge,{children:[e.jsx(je,{children:O?.ok?s("Crystal created"):s("Nothing was written")}),O?.ok&&e.jsx(Ve,{children:O.title})]}),e.jsx(we,{className:"space-y-3",children:O?.ok?e.jsx("p",{className:"whitespace-pre-wrap text-sm",children:O.content}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-destructive text-sm",children:O?.error}),O?.candidates&&O.candidates.length>0&&e.jsx("ul",{className:"divide-y rounded-lg border",children:O.candidates.map($=>e.jsxs("li",{className:"flex items-center justify-between gap-2 px-3 py-2",children:[e.jsx("span",{className:"truncate text-sm",children:$.title}),e.jsxs(te,{variant:"secondary",children:[($.similarity*100).toFixed(0),"%"]})]},$.id))})]})}),e.jsx(Ie,{children:e.jsx(Et,{render:e.jsx(S,{variant:"outline",size:"sm"}),children:s("Close")})})]})})]})}function bn(t){return t==="fast"||t==="deep"}const yt=25,ot="__all__";function Ci(t){return t.slice(0,10)}function ep(t,s){return t===!1&&!s}function tp(t,s,n,a){return bn(t)&&!s.trim()?"needs-query":ep(n,a)?"library-empty":"no-match"}function sp({items:t,onOpen:s,t:n,selected:a,onToggle:r,emptyLabel:o}){return e.jsxs("ul",{className:"divide-y rounded-lg border",children:[t.length===0&&e.jsx("li",{className:"px-3 py-6 text-sm text-muted-foreground",children:o}),t.map(i=>e.jsxs("li",{className:"flex items-center gap-2 px-3 py-2",children:[r&&e.jsx(Qe,{checked:a?.has(i.id)??!1,onCheckedChange:()=>r(i.id),"aria-label":n("Select memory")}),e.jsxs("button",{type:"button",onClick:()=>s(i.id),className:"min-w-0 flex-1 space-y-0.5 text-left",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[i.isCrystal&&e.jsx("span",{title:n("Crystal"),children:"★"}),e.jsx("span",{className:"truncate text-sm",children:i.title}),e.jsx(te,{variant:"secondary",children:i.unitType}),e.jsx(ap,{importance:i.importance,t:n}),i.lifecycleState==="archived"&&e.jsx(te,{variant:"outline",children:n("Archived")})]}),e.jsx("span",{className:"line-clamp-2 text-muted-foreground text-xs",children:i.contentSummary}),e.jsxs("span",{className:"block text-muted-foreground text-xs",children:[Ci(i.updatedAt)," · ",i.spaceLabel," ·"," ",n("Retrieved {{count}} times",{count:String(i.appearances)})]})]})]},i.id))]})}const np={critical:{variant:"warning",label:"critical"},important:{variant:"info",label:"important"},useful:{variant:"outline",label:"useful"},low:{variant:"outline",label:"low"}};function ap({importance:t,t:s}){const n=Fx(t),a=np[n];return e.jsx(te,{variant:a.variant,className:n==="low"?"text-muted-foreground":void 0,title:s("Importance {{value}}",{value:t.toFixed(2)}),children:s(a.label)})}function rp({edges:t,onReview:s,t:n}){return t.length===0?null:e.jsxs("section",{className:"space-y-2","data-settings-row":"memory.review",children:[e.jsx("h3",{className:"text-sm font-medium",children:n("Needs review")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n("Reviewing only records your judgement. Nothing is deleted and no memory is superseded.")}),t.map(a=>e.jsxs("div",{className:"space-y-1 rounded-lg border px-3 py-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(te,{variant:"outline",children:a.relation}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[a.olderId.slice(0,8)," → ",a.newerId.slice(0,8)]})]}),a.reason&&e.jsx("p",{className:"text-xs text-muted-foreground",children:a.reason}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(S,{size:"sm",variant:"outline",onClick:()=>s(a.id,"accepted"),children:n("Accept")}),e.jsx(S,{size:"sm",variant:"ghost",onClick:()=>s(a.id,"rejected"),children:n("Dismiss")})]})]},a.id))]})}function op({writes:t,onReview:s,t:n}){return t.length===0?null:e.jsxs("section",{className:"space-y-2","data-settings-row":"memory.pending-writes",children:[e.jsx("h3",{className:"text-sm font-medium",children:n("Memory writes awaiting approval")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n("Bot members need your approval before writing to project or global memory.")}),t.map(a=>e.jsxs("div",{className:"space-y-1 rounded-lg border px-3 py-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-xs text-muted-foreground",children:[a.originLabel&&e.jsx("span",{className:"text-foreground",children:a.originLabel}),e.jsxs("span",{children:["→ ",a.spaceLabel]}),a.redacted&&e.jsxs("span",{children:["· ",n("Secrets redacted")]})]}),a.title&&e.jsx("div",{className:"text-sm font-medium",children:a.title}),e.jsx("p",{className:"whitespace-pre-wrap text-xs",children:a.content}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(S,{size:"sm",variant:"outline",onClick:()=>s(a.id,"approve"),children:n("Approve")}),e.jsx(S,{size:"sm",variant:"ghost",onClick:()=>s(a.id,"reject"),children:n("Reject")})]})]},a.id))]})}function ip({t}){const s=Gc(),n=Hc(a=>a.review);return e.jsx(op,{writes:s,t,onReview:(a,r)=>{n(a,r)}})}function lp({revision:t=0}={}){const{t:s}=z(),[n,a]=m.useState(""),[r,o]=m.useState(ot),[i,d]=m.useState(ot),[u,x]=m.useState(!1),[h,l]=m.useState(0),[f,c]=m.useState("exact"),[p,g]=m.useState(!1),[w,k]=m.useState(!0),[j,y]=m.useState([]),[N,A]=m.useState(0),[O,I]=m.useState([]),[L,C]=m.useState(null),[E,M]=m.useState(null),[V,F]=m.useState(null),[b,B]=m.useState(new Set),[K,D]=m.useState(!1),[$,Y]=m.useState(!1),[H,se]=m.useState([]),q=m.useRef(!1),Q=m.useRef(0),_=m.useRef(0);m.useEffect(()=>(q.current=!0,()=>{q.current=!1,Q.current++,_.current++}),[]);const ne=m.useCallback(()=>{if(!q.current)return;const W=++Q.current,ve=()=>q.current&&W===Q.current;if(bn(f)&&!n.trim()){y([]),A(0),g(!0),k(!0);return}window.electronAPI.memory.list({query:n.trim()||void 0,spaceId:r===ot?void 0:r,unitType:i===ot?void 0:i,includeArchived:u,limit:yt,offset:h,mode:f}).then(Se=>{ve()&&(y(Se.items),A(Se.total),g(Se.approximate===!0),k(Se.vectorsUsed!==!1))}),window.electronAPI.memory.stats().then(Se=>{q.current&&(I(Object.keys(Se.bySpace).map(Ze=>({id:Ze,label:Se.spaceLabels[Ze]??Ze}))),C(Se.total>0))}),window.electronAPI.memory.evolvesPending().then(Se=>{q.current&&se(Se)})},[n,r,i,u,h,f]);m.useEffect(()=>(ne(),()=>{Q.current++}),[ne]);const R=m.useRef(ne);R.current=ne,m.useEffect(()=>window.electronAPI.memory.onChanged(()=>R.current()),[]);const P=m.useRef(t);m.useEffect(()=>{P.current!==t&&(P.current=t,ne())},[t,ne]);const ce=W=>{const ve=++_.current;window.electronAPI.memory.detail(W).then(Se=>{q.current&&ve===_.current&&M(Se)})},xe=()=>{_.current++,M(null)},Pe=async W=>{Y(!0);try{for(const ve of b)await W(ve)}finally{q.current&&(Y(!1),B(new Set),D(!1),R.current())}},De=()=>{Pe(W=>window.electronAPI.memory.archive(W))},U=()=>{Pe(W=>window.electronAPI.memory.delete(W))},Z=W=>{W.then(()=>{q.current&&(xe(),F(null),R.current())})},X=n.trim()!==""||r!==ot||i!==ot||u===!0,ue=[{value:ot,label:s("All spaces")},...O.map(W=>({value:W.id,label:W.label}))],Ne=[{value:ot,label:s("All types")},...Lx.map(W=>({value:W,label:W}))],Ce=[{value:"exact",label:s("Exact match")},{value:"fast",label:s("Fast retrieval")},{value:"deep",label:s("Deep retrieval")}];return e.jsxs("div",{className:"space-y-4","data-settings-row":"memory.library",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium",children:s("Stored memories")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Everything the agent has saved. Archiving hides a memory from search but keeps it.")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(_o,{className:"w-full sm:w-96","data-size":"sm",children:[e.jsx(Bo,{value:n,placeholder:s("Search memories"),onChange:W=>{l(0),a(W.target.value)}}),e.jsx(Fo,{align:"inline-end",className:"pe-1",children:e.jsxs(ae,{value:f,items:Ce,onValueChange:W=>{l(0),c(W==="deep"?"deep":W==="fast"?"fast":"exact")},children:[e.jsx(re,{size:"sm",className:"w-auto min-w-0 gap-1 border-0 bg-transparent px-2 shadow-none before:hidden",children:e.jsx(oe,{})}),e.jsx(ie,{children:Ce.map(W=>e.jsx(ee,{value:W.value,children:W.label},W.value))})]})})]}),e.jsxs(ae,{value:r,items:ue,onValueChange:W=>{l(0),o(String(W))},children:[e.jsx(re,{size:"sm",className:"w-36",children:e.jsx(oe,{})}),e.jsx(ie,{children:ue.map(W=>e.jsx(ee,{value:W.value,children:W.label},W.value))})]}),e.jsxs(ae,{value:i,items:Ne,onValueChange:W=>{l(0),d(String(W))},children:[e.jsx(re,{size:"sm",className:"w-36",children:e.jsx(oe,{})}),e.jsx(ie,{children:Ne.map(W=>e.jsx(ee,{value:W.value,children:W.label},W.value))})]}),f==="exact"&&e.jsxs("label",{className:"flex items-center gap-2 text-muted-foreground text-sm",children:[e.jsx(le,{checked:u,onCheckedChange:W=>{l(0),x(W===!0)}}),s("Show archived")]})]}),bn(f)&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:[s(f==="deep"?"Same recall as Fast, plus intent-weighted fusion and an optional short-timeout LLM rerank. Failures fall back; archived memories are excluded.":"Same path the agent uses: full-text, vectors and entities merged by relevance. Shows the top matches only — no exact count, and archived memories are excluded."),!w&&` ${s("Embedding model is not ready, so vectors are skipped.")}`]}),b.size>0&&e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border bg-accent/30 px-3 py-2",children:[e.jsx("span",{className:"text-sm",children:s("{{count}} selected",{count:String(b.size)})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(S,{variant:"ghost",size:"sm",disabled:$,onClick:()=>B(new Set),children:s("Clear selection")}),e.jsx(S,{variant:"outline",size:"sm",disabled:$,onClick:()=>De(),children:s("Archive selected")}),e.jsx("button",{type:"button",disabled:$,className:"text-xs text-muted-foreground underline-offset-2 hover:underline disabled:opacity-50",onClick:()=>D(!0),children:s("Delete permanently")})]})]}),e.jsx(sp,{items:j,onOpen:ce,t:s,selected:b,emptyLabel:{"needs-query":s("Type a query to search by meaning."),"library-empty":s("No memories yet. They appear here once the agent stores something."),"no-match":s("No memories match these filters.")}[tp(f,n,L,X)],onToggle:W=>{const ve=new Set(b);ve.delete(W)||ve.add(W),B(ve)}}),!p&&N>yt&&e.jsxs("div",{className:"flex items-center justify-between text-xs text-muted-foreground",children:[e.jsx(S,{variant:"outline",size:"sm",disabled:h===0,onClick:()=>l(Math.max(0,h-yt)),children:s("Previous")}),e.jsxs("span",{children:[h+1,"–",Math.min(h+yt,N)," / ",N]}),e.jsx(S,{variant:"outline",size:"sm",disabled:h+yt>=N,onClick:()=>l(h+yt),children:s("Next")})]}),e.jsx(ip,{t:s}),e.jsx(rp,{edges:H,t:s,onReview:(W,ve)=>Z(window.electronAPI.memory.evolvesReview(W,ve))}),e.jsx(pe,{open:E!==null,onOpenChange:W=>!W&&xe(),children:e.jsx(fe,{children:E&&e.jsxs(e.Fragment,{children:[e.jsxs(ge,{children:[e.jsx(je,{children:E.title}),e.jsx(Ve,{children:[E.unitType,E.spaceLabel,Ci(E.createdAt)].join(" · ")})]}),e.jsxs(we,{className:"space-y-4",children:[e.jsx("p",{className:"whitespace-pre-wrap text-sm",children:E.content}),e.jsxs("dl",{className:"grid grid-cols-2 gap-x-4 gap-y-3",children:[e.jsx(Ys,{label:s("Importance"),value:E.importance.toFixed(2)}),e.jsx(Ys,{label:s("Embedding"),value:E.embeddingModel??s("Not vectorized")}),E.eventStart&&e.jsx(Ys,{label:s("Event date"),value:`${E.eventStart}${E.eventEnd?` → ${E.eventEnd}`:""}`})]}),E.entityNames.length>0&&e.jsxs("section",{className:"space-y-1.5",children:[e.jsx("p",{className:"font-medium text-xs",children:s("Entities")}),e.jsx("div",{className:"flex flex-wrap gap-1",children:E.entityNames.map(W=>e.jsx(te,{variant:"secondary",children:W},W))})]}),E.crystalSources.length>0&&e.jsxs("section",{className:"space-y-1.5",children:[e.jsx("p",{className:"font-medium text-xs",children:s("Synthesized from")}),e.jsx("ul",{className:"divide-y rounded-lg border",children:E.crystalSources.map(W=>e.jsxs("li",{className:"flex items-center justify-between gap-2 px-3 py-2",children:[e.jsx("span",{className:"truncate text-sm",children:W.title}),e.jsxs("span",{className:"shrink-0 text-muted-foreground text-xs",children:[(W.contributionWeight*100).toFixed(0),"%"]})]},W.id))})]}),E.evolves.length>0&&e.jsxs("section",{className:"space-y-1.5",children:[e.jsx("p",{className:"font-medium text-xs",children:s("Related versions")}),e.jsx("ul",{className:"divide-y rounded-lg border",children:E.evolves.map(W=>e.jsxs("li",{className:"flex items-center gap-2 px-3 py-2",children:[e.jsx(te,{variant:"outline",children:W.relation}),e.jsx("span",{className:"text-muted-foreground text-xs",children:W.reviewState})]},W.id))})]})]}),e.jsxs(Ie,{children:[e.jsx(S,{variant:"ghost",size:"sm",className:"sm:me-auto",onClick:()=>F(E.id),children:s("Delete permanently")}),E.lifecycleState==="archived"?e.jsx(S,{variant:"outline",size:"sm",onClick:()=>Z(window.electronAPI.memory.restore(E.id)),children:s("Restore")}):e.jsx(S,{variant:"outline",size:"sm",onClick:()=>Z(window.electronAPI.memory.archive(E.id)),children:s("Archive")})]})]})})}),e.jsx(pe,{open:K,onOpenChange:W=>!W&&D(!1),children:e.jsxs(fe,{children:[e.jsxs(ge,{children:[e.jsx(je,{children:s("Delete {{count}} memories permanently?",{count:String(b.size)})}),e.jsx(Ve,{children:s("This cannot be undone. Archiving keeps the memory out of search while preserving it.")})]}),e.jsxs(Ie,{children:[e.jsx(Et,{render:e.jsx(S,{variant:"outline",size:"sm"}),children:s("Cancel")}),e.jsx(S,{variant:"destructive",size:"sm",disabled:$,onClick:U,children:s("Delete permanently")})]})]})}),e.jsx(pe,{open:V!==null,onOpenChange:W=>!W&&F(null),children:e.jsxs(fe,{children:[e.jsxs(ge,{children:[e.jsx(je,{children:s("Delete this memory permanently?")}),e.jsx(Ve,{children:s("This cannot be undone. Archiving keeps the memory out of search while preserving it.")})]}),e.jsxs(Ie,{children:[e.jsx(Et,{render:e.jsx(S,{variant:"outline",size:"sm"}),children:s("Cancel")}),e.jsx(S,{variant:"destructive",size:"sm",onClick:()=>V&&Z(window.electronAPI.memory.delete(V)),children:s("Delete permanently")})]})]})})]})}function Ys({label:t,value:s}){return e.jsxs("div",{className:"min-w-0",children:[e.jsx("dt",{className:"text-muted-foreground text-xs",children:t}),e.jsx("dd",{className:"truncate text-sm",children:s})]})}const Si="openai-compatible",cp=/embed|bge|m3e|voyage|jina|nomic|mxbai|stella|conan|acge|retriev|text-(?:similarity|search)|(?:^|[^a-z0-9])(?:e5|gte|bce)(?:[^a-z0-9]|$)/i;function Ii(t){return cp.test(t)}function Ai(t){return Array.isArray(t.models)?t.models.filter(s=>typeof s?.id=="string"&&Ii(s.id)):[]}function dp(t){return t.flatMap(s=>{if(!s.apiKey||typeof s.baseUrl!="string"||!s.baseUrl.trim())return[];const n=Ai(s);return n.length>0?[{...s,models:n}]:[]})}function up(t){const{providerId:s,provider:n,modelId:a}=t;return s?n?n.apiKey?typeof n.baseUrl!="string"||!n.baseUrl.trim()?"no-base-url":!a||a===Si?"no-model":Ii(a)?null:Ai(n).length>0?"not-embedding-model":"no-embedding-models":"no-api-key":"provider-missing":"no-provider"}const mp={"no-provider":"No remote embedding provider is selected. Choose a provider with an API key, or switch to a local embedding model.","provider-missing":"The selected embedding provider no longer exists. Choose another provider, or switch to a local embedding model.","no-base-url":'Provider "{{provider}}" has no Base URL. Fill it in, or choose another provider.',"no-api-key":'Provider "{{provider}}" has no API key. Subscription sign-in cannot be used for embeddings; choose a provider with an API key, or switch to a local embedding model.',"no-model":"No remote embedding model is selected. Choose a model that supports /embeddings.","not-embedding-model":'"{{model}}" is a chat model and cannot be used for embeddings. Choose a model that supports /embeddings, or switch to a local embedding model.',"no-embedding-models":'Provider "{{provider}}" has no embedding model ("{{model}}" is a chat model). Add one that supports /embeddings (e.g. text-embedding-3-small), or switch to a local embedding model.'},hp="No model can be used for embeddings: it needs a provider with an API key and an embedding model (e.g. text-embedding-3-small). Subscription sign-in cannot be used for embeddings.";function xp(t,s,n){return n(mp[t],{provider:s.provider??"",model:s.model??""})}const Mr=t=>t.slice(0,8);function Js(t,s){return t==="pending"||t==="running"?"running":t==="cancelled"?"cancelled":s?"failed":"done"}const pp={low_importance:"importance too low",candidates_found:"similar memory already exists",deduplicated:"identical to an existing memory",rejected:"rejected"};function fp(t){const s=[];for(const r of t.distill){const o=Js(r.status,r.error);s.push({key:`distill:${r.id}`,kind:"distill",target:r.sessionTitle||Mr(r.sessionId),state:o,detail:o==="failed"?r.error??"":o==="cancelled"?"superseded":o==="running"?r.attempts>1?`retry ${r.attempts}`:"queued":`${r.done} stored`,notes:(r.notes??[]).map(i=>[i.title,pp[i.kind]??i.kind].filter(Boolean).join(" — ")),updatedAt:r.updatedAt})}for(const r of t.kg){const o=Js(r.status,r.error);s.push({key:`kg:${r.id}`,kind:"kg",target:r.memoryTitle||Mr(r.memoryId),state:o,detail:o==="failed"?r.error??"":o==="cancelled"?"memory changed":o==="running"?"extracting":`${r.total} entities · ${r.done} links`,notes:[],updatedAt:r.updatedAt})}const n=t.reembed;if(n){const r=Js(n.status,n.error);s.push({key:`reembed:${n.id}`,kind:"reembed",target:n.target,state:r,detail:r==="failed"?n.error??"":r==="running"?`${n.done}/${n.total}`:`${n.done} vectorized${n.failed>0?` · ${n.failed} failed`:""}`,notes:[],updatedAt:n.updatedAt})}const a=r=>r.state==="running"?0:r.state==="failed"?1:2;return s.sort((r,o)=>a(r)-a(o)||o.updatedAt.localeCompare(r.updatedAt))}const Lt=`remote:${Si}`,os="remote:";function Pr(t){return t.id==="none"?"None (full-text only)":t.id.replace(/^(local|remote):/,"")}function xs(t){return t.startsWith(os)&&t.length>os.length}function gp(t){return xs(t)?Lt:t}function jp(t){return!xs(t)||t===Lt?null:t.slice(os.length)}function vp(t){return`${os}${t}`}function bp(t,s){return s===Lt?xs(t)?t:Lt:s}const yp=4e3,wp=800,Tr=6,Np={distill:"job:distill",kg:"job:entities",reembed:"job:vectors"},Rr={distill:[],kg:[],reembed:null,kgFailed:0};function kp(t){return t.some(s=>s.distilled)}function Or(t){return!t||t.total===0||t.embedded>=t.total?null:t.embeddingError??null}function Dr(t){return t?.downloadable&&(t.state==="missing"||t.state==="downloading")?t.state:null}function Cp(t,s){if(t.done===0||t.done>=t.total)return null;const n=(s-t.startedAt)/t.done;return Math.round(n*(t.total-t.done))}function Sp(t){const s=Math.max(1,Math.round(t/1e3));if(s<60)return`${s}s`;const n=Math.floor(s/60);return s%60===0?`${n}m`:`${n}m ${s%60}s`}function Ip(t){const s=new Map;for(const a of t){const r=a.projectId??"",o=s.get(r);if(o){o.sessions.push(a);continue}s.set(r,{key:r,name:a.projectName??"No project",sessions:[a]})}const n=[...s.values()];return[...n.filter(a=>a.key),...n.filter(a=>!a.key)]}function de(t){if(t<=0)return"0 B";const s=["B","KB","MB","GB"],n=Math.min(Math.floor(Math.log(t)/Math.log(1024)),s.length-1);return`${(t/1024**n).toFixed(n===0?0:1)} ${s[n]}`}function Qs({title:t,description:s,checked:n,onChange:a,rowId:r,disabled:o}){return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5","data-settings-row":r,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s})]}),e.jsx(le,{checked:n,disabled:o,onCheckedChange:i=>a(i===!0)})]})}function Ap({onLibraryChanged:t}={}){const{t:s}=z(),n=v(T=>T.disabledBuiltinTools),a=v(T=>T.memoryEmbeddingModel),r=v(T=>T.setMemoryEmbeddingModel),o=v(T=>T.memoryEmbeddingAutoDownload),i=v(T=>T.setMemoryEmbeddingAutoDownload),d=v(T=>T.memoryModelIdleMinutes),u=v(T=>T.setMemoryModelIdleMinutes),x=v(T=>T.memoryEmbeddingRemoteProviderId),h=v(T=>T.setMemoryEmbeddingRemoteProviderId),l=v(T=>T.providers),f=v(T=>T.memoryDistillEnabled),c=v(T=>T.setMemoryDistillEnabled),p=v(T=>T.memoryKgEnabled),g=v(T=>T.setMemoryKgEnabled),w=v(T=>T.memoryDistillModel),k=v(T=>T.setMemoryDistillModel),j=v(T=>T.memoryChatModel)||"remote",y=v(T=>T.setMemoryChatModel),N=v(T=>T.memoryLanguage),A=v(T=>T.setMemoryLanguage),O=Xe(),I=w?O.find(T=>T.id===w.providerId):void 0,L=I?.models.find(T=>T.id===w?.modelId),C=jp(a),E=m.useMemo(()=>dp(O),[O]),M=x?E.find(T=>T.id===x):void 0,V=M?.models.find(T=>T.id===C),F=x?l.find(T=>T.id===x):void 0,b=up({providerId:x,provider:F,modelId:C}),B=b&&b!=="no-provider"&&b!=="no-model"?xp(b,{provider:F?.name||x||"",model:C??""},s):null,K=!n.includes("memory"),[D,$]=m.useState(null),[Y,H]=m.useState(Rr),[se,q]=m.useState([]),[Q,_]=m.useState(null),[ne,R]=m.useState([]),[P,ce]=m.useState(null),[xe,Pe]=m.useState([]),[De,U]=m.useState(null),[Z,X]=m.useState(null),[ue,Ne]=m.useState(null),[Ce,W]=m.useState(null),[ve,Se]=m.useState(!1),[Ze,ke]=m.useState(!1),nt=m.useRef(!1);nt.current=ve;const Vt=m.useRef(null),ps=m.useCallback(()=>{window.electronAPI.memory.distillableSessions().then(Pe)},[]);m.useEffect(()=>{K&&ps()},[K,ps]);const ft=m.useCallback(()=>{window.electronAPI.memory.models().then(q)},[]);m.useEffect(()=>(ft(),window.electronAPI.memory.onModelProgress(T=>{_(T.done?null:T),T.done&&ft()})),[ft]);const gt=m.useCallback(()=>{window.electronAPI.memory.chatModels().then(T=>R(T.filter(ye=>!ye.purpose)))},[]);m.useEffect(()=>(gt(),window.electronAPI.memory.onChatModelProgress(T=>{ce(T.done?null:T),T.done&&gt()})),[gt]),m.useEffect(()=>{if(!K){$(null),H(Rr);return}let T=!1;const ye=()=>{window.electronAPI.memory.stats().then(et=>{T||$(et)}),window.electronAPI.memory.jobs().then(et=>{T||(H(et),nt.current&&et.reembed?.status!=="running"&&Se(!1))})};Vt.current=ye,ye();const dt=window.electronAPI.memory.onChanged(ye),Pt=window.setInterval(ye,ve?wp:yp);return()=>{T=!0,Vt.current=null,dt(),window.clearInterval(Pt)}},[K,ve]);const Yn=Ip(xe),Jn=xe.filter(T=>!T.distilled),Qn=(T,ye,dt)=>{const Pt=T.filter(et=>!et.distilled);if(!kp(T)){Kt(T,ye);return}W({token:ye,label:dt,scope:T,pending:Pt})},Kt=async(T,ye,dt=!1)=>{const Pt=ne.find(vt=>vt.id===j)??null;if(Dr(Pt))return;U(ye);const et=Date.now();Ne({done:0,total:T.length,startedAt:et});try{for(let vt=0;vt<T.length;vt++)await window.electronAPI.memory.distillSession(T[vt].sessionId,dt),Ne({done:vt+1,total:T.length,startedAt:et})}finally{U(null),Ne(null),ps(),t?.()}},be=se.find(T=>T.id===a)??null,Le=ne.find(T=>T.id===j)??null,ct=Dr(Le),Xn=ne.map(T=>({value:T.id,label:T.id==="remote"?s("Remote (API model)"):T.label})),Zn=[...se.map(T=>({value:T.id,label:Pr(T)})),{value:Lt,label:s("Remote (OpenAI-compatible)")}],ea=Wc.map(T=>({value:String(T),label:T===0?s("Never"):s("{{count}} min",{count:T})})),ta=[{value:"en",label:s("English")},{value:"zh",label:s("Simplified Chinese")},{value:"auto",label:s("Follow conversation")}],qt=xs(a)||be?.runtime==="openai-compatible",jt=m.useMemo(()=>fp(Y),[Y]);return e.jsxs("div",{className:"space-y-6","data-settings-row":"memory.root",children:[e.jsxs("section",{className:"space-y-2",children:[e.jsx("h2",{className:"text-base font-medium",children:s("Memory")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("Durable knowledge the agent can search and write across sessions. Stored locally in a SQLite database.")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Turn memory off in Built-in tools.")})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5","data-settings-row":"memory.modelIdleMinutes",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s("Unload automatically when idle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Release local model memory after this idle period. Models load automatically the next time they are needed.")})]}),e.jsxs(ae,{value:String(d),items:ea,onValueChange:T=>{T!==null&&u(Number(T))},disabled:!K,children:[e.jsx(re,{className:"w-56 shrink-0","aria-label":s("Unload automatically when idle"),children:e.jsx(oe,{})}),e.jsx(ie,{children:ea.map(T=>e.jsx(ee,{value:T.value,children:T.label},T.value))})]})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium",children:s("Embedding model")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Used for semantic search and near-duplicate detection. Without it search still works using full-text only.")}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5","data-settings-row":"memory.embeddingModel",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:be?Pr(be):C??(qt?s("Remote (OpenAI-compatible)"):a)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:be?[be.dim?`${be.dim}d`:null,be.downloadable?de(be.approxBytes):null,be.runtime].filter(Boolean).join(" · "):qt?"openai-compatible":s("Unknown model; the default is used instead.")})]}),e.jsxs(ae,{value:gp(a),items:Zn,onValueChange:T=>{T!==null&&r(bp(a,String(T)))},disabled:!K,children:[e.jsx(re,{className:"w-56",children:e.jsx(oe,{})}),e.jsx(ie,{children:Zn.map(T=>e.jsx(ee,{value:T.value,children:T.label},T.value))})]})]}),be?.downloadable&&e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5","data-settings-row":"memory.download",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:be.state==="ready"?s("Model downloaded"):be.state==="downloading"?s("Downloading…"):s("Model not downloaded")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:Q&&Q.modelId===be.id?`${Q.file} · ${de(Q.received)}${Q.total?` / ${de(Q.total)}`:""} (${Q.fileIndex+1}/${Q.fileCount})`:be.state==="ready"?de(be.downloadedBytes):s("Semantic search stays off until the model is on disk.")})]}),e.jsx("div",{className:"flex shrink-0 gap-2",children:be.state==="downloading"?e.jsx(S,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.memory.cancelModelDownload(be.id).then(ft)},children:s("Cancel")}):be.state==="ready"?e.jsx(S,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.memory.deleteModel(be.id).then(ft)},children:s("Remove")}):e.jsx(S,{size:"sm",disabled:!K,onClick:()=>{window.electronAPI.memory.downloadModel(be.id).then(ft)},children:s("Download")})})]}),qt&&e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5","data-settings-row":"memory.remoteModel",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s("Remote model")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Credentials stay in the main process and are never sent to the renderer.")})]}),E.length>0?e.jsx("div",{className:"w-56 shrink-0",children:e.jsx(ze,{providers:E,providerId:M?.id??x??"",modelId:V?.id??C??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:s("Select model"),side:"bottom",triggerClassName:Ye,onSelect:(T,ye)=>{h(T),r(vp(ye))},onReasoningChange:()=>{},onThinkingChange:()=>{}})}):e.jsx("p",{className:"w-56 shrink-0 text-xs text-destructive",children:s(hp)})]}),qt&&B&&e.jsx("p",{className:"text-xs text-destructive","data-settings-row":"memory.remoteModelIssue",children:B}),e.jsx(Qs,{rowId:"memory.autoDownload",title:s("Download models automatically"),description:s("Off by default, so a model is only fetched when you press Download. While a model is missing, search degrades to full-text; existing memories are re-embedded once it arrives."),checked:o,onChange:i,disabled:!K})]}),e.jsxs("section",{className:"space-y-2","data-settings-row":"memory.distillModel",children:[e.jsx("h3",{className:"text-sm font-medium",children:s("Distillation")}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s("Completion backend")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Local GGUF runs on this machine. Remote uses the model below.")})]}),e.jsxs(ae,{value:j,items:Xn,onValueChange:T=>y(String(T)),disabled:!K,children:[e.jsx(re,{className:"w-56",children:e.jsx(oe,{})}),e.jsx(ie,{children:Xn.map(T=>e.jsx(ee,{value:T.value,children:T.label},T.value))})]})]}),Le?.downloadable&&e.jsxs("div",{className:G("flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5",ct==="missing"&&"border-destructive/50"),children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:Le.state==="ready"?s("Model downloaded"):Le.state==="downloading"?s("Downloading…"):s("Model not downloaded")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:P&&P.modelId===Le.id?`${P.file} · ${de(P.received)}${P.total?` / ${de(P.total)}`:""}`:Le.state==="ready"?de(Le.downloadedBytes):de(Le.approxBytes)})]}),e.jsx("div",{className:"flex shrink-0 gap-2",children:Le.state==="downloading"?e.jsx(S,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.memory.cancelChatModelDownload(Le.id).then(gt)},children:s("Cancel")}):Le.state==="ready"?e.jsx(S,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.memory.deleteChatModel(Le.id).then(gt)},children:s("Remove")}):e.jsx(S,{size:"sm",disabled:!K,onClick:()=>{window.electronAPI.memory.downloadChatModel(Le.id).then(gt)},children:s("Download")})})]}),ct==="missing"&&e.jsx("p",{className:"text-xs text-destructive",children:s("Local model selected but the weights are not on disk. Distillation and interpretation will wait until you click Download.")}),ct==="downloading"&&e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Download in progress. Distillation waits until the model is ready.")}),j==="remote"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s("Distillation model")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Reads finished sessions and writes the memories.")})]}),O.length>0&&e.jsx("div",{className:"w-56 shrink-0",children:e.jsx(ze,{providers:O,providerId:I?.id??"",modelId:L?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:s("Follows the title-summary model"),side:"bottom",triggerClassName:Ye,onSelect:(T,ye)=>k({providerId:T,modelId:ye}),onReasoningChange:()=>{},onThinkingChange:()=>{}})})]}),w&&e.jsx(S,{variant:"ghost",size:"sm",onClick:()=>k(null),children:s("Follows the title-summary model")})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5","data-settings-row":"memory.language",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s("Memory language")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("English keeps retrieval and near-duplicate detection stable across languages. Choose Follow conversation if your team only works in one language.")})]}),e.jsxs(ae,{value:N,items:ta,onValueChange:T=>A(String(T)),disabled:!K,children:[e.jsx(re,{className:"w-56",children:e.jsx(oe,{})}),e.jsx(ie,{children:ta.map(T=>e.jsx(ee,{value:T.value,children:T.label},T.value))})]})]})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium",children:s("Background processing")}),e.jsx(Qs,{rowId:"memory.distill",title:s("Distill sessions automatically"),description:s("When a session ends, or goes idle for 30 minutes and is reclaimed, extract 1-3 durable memories from it in the background."),checked:f,onChange:c,disabled:!K}),f&&ct&&e.jsx("p",{className:"text-xs text-destructive",children:s("Automatic distillation is on, but the local model is not ready. Sessions will queue until you download it.")}),e.jsx(Qs,{rowId:"memory.kg",title:s("Extract entities"),description:s("Build an entity graph so a memory can be recalled by a name it does not literally contain."),checked:p,onChange:g,disabled:!K})]}),e.jsxs("section",{className:"space-y-2","data-settings-row":"memory.stats",children:[e.jsx("h3",{className:"text-sm font-medium",children:s("Library")}),D===null||D.total===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:s("No memories stored yet.")}):e.jsxs(e.Fragment,{children:[Or(D)&&e.jsx("p",{className:"text-xs text-destructive",children:s("Vectors unavailable: {{reason}}",{reason:Or(D)??""})}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-3",children:[e.jsx(wt,{label:s("Memories"),value:String(D.total)}),e.jsx(wt,{label:s("Crystals"),value:String(D.crystals)}),e.jsx(wt,{label:s("Entities"),value:String(D.entities)}),e.jsx(wt,{label:s("With vectors"),value:`${D.embedded}/${D.total}`,action:D.embedded<D.total?e.jsx("button",{type:"button",disabled:ve,className:"text-xs text-muted-foreground underline-offset-2 hover:underline disabled:opacity-60",onClick:()=>{Se(!0),window.electronAPI.memory.reembed().then(()=>Vt.current?.())},children:s(ve?"Backfilling…":"Backfill")}):null}),e.jsx(wt,{label:s("Database size"),value:de(D.databaseBytes)}),e.jsx(wt,{label:s("Spaces"),value:String(Object.keys(D.bySpace).length)})]})]})]}),e.jsxs("section",{className:"space-y-2","data-settings-row":"memory.distillSessions",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("h3",{className:"text-sm font-medium",children:s("Distill past sessions")}),Jn.length>0&&e.jsx(S,{size:"sm",variant:"outline",disabled:!K||De!==null||ct!==null,onClick:()=>Qn(xe,"all",s("All sessions")),children:De==="all"?s("Distilling…"):s("Distill all ({{count}})",{count:String(Jn.length)})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("The automatic switch only covers sessions that end from now on. Distill earlier sessions here to fill the library.")}),ue&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:[s("{{done}}/{{total}} done",{done:String(ue.done),total:String(ue.total)}),(()=>{const T=Cp(ue,Date.now());return T===null?"":` · ${s("about {{time}} left",{time:Sp(T)})}`})()]}),Yn.length===0?e.jsx("p",{className:"text-muted-foreground text-sm",children:s("No recorded sessions found.")}):e.jsx("ul",{className:"divide-y rounded-lg border",children:Yn.map(T=>{const ye=T.sessions.filter(dt=>!dt.distilled);return e.jsxs("li",{className:"flex items-center justify-between gap-3 px-3 py-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-sm",children:T.name}),e.jsx("p",{className:"text-muted-foreground text-xs",children:s("{{total}} sessions · {{pending}} not distilled",{total:String(T.sessions.length),pending:String(ye.length)})})]}),e.jsxs("div",{className:"flex shrink-0 gap-2",children:[e.jsx(S,{size:"sm",variant:"ghost",onClick:()=>X(T),children:s("View sessions")}),e.jsx(S,{size:"sm",variant:"outline",disabled:!K||De!==null||T.sessions.length===0||ct!==null,onClick:()=>Qn(T.sessions,T.key,T.name),children:De===T.key?s("Distilling…"):s("Distill project")})]})]},T.key)})})]}),e.jsx(pe,{open:Z!==null,onOpenChange:T=>!T&&X(null),children:e.jsx(fe,{children:Z&&e.jsxs(e.Fragment,{children:[e.jsxs(ge,{children:[e.jsx(je,{children:Z.name}),e.jsx(Ve,{children:s("{{total}} sessions · {{pending}} not distilled",{total:String(Z.sessions.length),pending:String(Z.sessions.filter(T=>!T.distilled).length)})})]}),e.jsx(we,{children:e.jsx("ul",{className:"divide-y rounded-lg border",children:Z.sessions.map(T=>e.jsxs("li",{className:"flex items-center justify-between gap-3 px-3 py-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-sm",children:T.title}),e.jsxs("p",{className:"text-muted-foreground text-xs",children:[T.updatedAt?T.updatedAt.slice(0,10):"",T.distilled?` · ${s("Already distilled")}`:""]})]}),e.jsx(S,{size:"sm",variant:"ghost",className:"shrink-0",disabled:!K||De!==null||ct!==null,onClick:()=>{Kt([T],T.sessionId,T.distilled)},children:De===T.sessionId?s("Distilling…"):T.distilled?s("Distill again"):s("Distill")})]},T.sessionId))})}),e.jsx(Ie,{children:e.jsx(Et,{render:e.jsx(S,{variant:"outline",size:"sm"}),children:s("Close")})})]})})}),e.jsx(pe,{open:Ce!==null,onOpenChange:T=>!T&&W(null),children:e.jsx(fe,{children:Ce&&e.jsxs(e.Fragment,{children:[e.jsxs(ge,{children:[e.jsx(je,{children:s("Some sessions were already distilled")}),e.jsx(Ve,{children:s("{{label}}: {{total}} sessions, {{done}} already distilled. Re-distilling runs the model again and may add new memories alongside the existing ones.",{label:Ce.label,total:String(Ce.scope.length),done:String(Ce.scope.length-Ce.pending.length)})})]}),e.jsxs(Ie,{children:[e.jsx(Et,{render:e.jsx(S,{variant:"ghost",size:"sm"}),children:s("Cancel")}),e.jsx(S,{variant:Ce.pending.length>0?"default":"outline",size:"sm",disabled:Ce.pending.length===0,onClick:()=>{const T=Ce;W(null),Kt(T.pending,T.token)},children:s("Only the {{count}} remaining",{count:String(Ce.pending.length)})}),e.jsx(S,{variant:Ce.pending.length>0?"outline":"default",size:"sm",onClick:()=>{const T=Ce;W(null),Kt(T.scope,T.token,!0)},children:s("Re-distill all {{count}}",{count:String(Ce.scope.length)})})]})]})})}),e.jsxs("section",{className:"space-y-2","data-settings-row":"memory.jobs",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("h3",{className:"font-medium text-sm",children:s("Background tasks")}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[Y.kgFailed>0&&e.jsx(S,{size:"sm",variant:"ghost",onClick:()=>{window.electronAPI.memory.retryFailedKgJobs().then(()=>Vt.current?.())},children:s("Retry failed extractions ({{count}})",{count:String(Y.kgFailed)})}),jt.some(T=>T.state!=="running")&&e.jsx(S,{size:"sm",variant:"ghost",title:s("Removes completed and cancelled jobs. Running tasks are kept. Sessions will show as not distilled again, since that flag is derived from job history — re-distilling is deduplicated, so it will not create duplicate memories."),onClick:()=>{window.electronAPI.memory.clearJobs()},children:s("Clear finished tasks")}),jt.length>Tr&&e.jsx(S,{size:"sm",variant:"ghost",onClick:()=>ke(!Ze),children:Ze?s("Show less"):s("Show all {{count}}",{count:String(jt.length)})})]})]}),jt.length===0?e.jsx("p",{className:"text-muted-foreground text-sm",children:s("Nothing running.")}):e.jsx("ul",{className:"divide-y rounded-lg border",children:(Ze?jt:jt.slice(0,Tr)).map(T=>e.jsxs("li",{className:"space-y-1 px-3 py-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(te,{variant:T.state==="failed"?"destructive":"secondary",children:s(Np[T.kind])}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-sm",children:T.target}),e.jsx("span",{className:G("shrink-0 text-xs",T.state==="failed"?"text-destructive":"text-muted-foreground"),children:T.state==="running"?`⋯ ${T.detail}`:T.detail})]}),T.notes.map(ye=>e.jsxs("p",{className:"pl-1 text-muted-foreground text-xs",children:["· ",ye]},ye))]},T.key))})]})]})}function wt({label:t,value:s,action:n}){return e.jsxs("div",{className:"rounded-lg border px-3 py-2",children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:t}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-sm",children:s}),n]})]})}function Ep(t,s){if(s===null)return{ok:!0,value:null};if(t.type==="boolean")return typeof s=="boolean"?{ok:!0,value:s}:s==="true"||s==="false"?{ok:!0,value:s==="true"}:{ok:!1,error:"需要打开或关闭"};if(typeof s!="string")return{ok:!1,error:"值不合法"};if(t.type==="number"){const n=s.trim();if(!/^-?\d+(\.\d+)?$/.test(n))return{ok:!1,error:"需要数字"};const a=Number(n);return Number.isFinite(a)?t.min!==void 0&&a<t.min?{ok:!1,error:"小于最小值"}:t.max!==void 0&&a>t.max?{ok:!1,error:"大于最大值"}:{ok:!0,value:a}:{ok:!1,error:"需要数字"}}return t.type==="enum"?t.options?.includes(s)?{ok:!0,value:s}:{ok:!1,error:"不在可选项里"}:s.length>4096||s.includes("\0")?{ok:!1,error:"值不合法"}:{ok:!0,value:s}}const Mp={"agent.tool":"运行 Agent 工具","ui.slot":"在界面挂载组件","ui.view":"打开侧栏页面","ui.notify":"发送系统通知","composer.draft":"读写输入框草稿","fs.read":"读取声明的文件","fs.write":"写入声明的文件","net.fetch":"访问声明的域名","mcp.server":"启动声明的 MCP 服务","mcp.call":"调用宿主 MCP 工具","agent.observe":"观察会话事件","agent.intercept":"拦截并改写会话事件","agent.inject":"向会话发送消息,并可触发该会话继续执行;默认只发到发起调用的会话,允许后可发到任意运行中的会话","process.background":"常驻后台并拉起子进程","plugin.call":"调用其他插件","ui.clipboard":"写入剪贴板","ui.openExternal":"用浏览器打开链接","session.read":"查看本项目的会话列表与运行状态(标题、活动时间、是否在等你)","session.readAll":"查看所有项目的会话列表与运行状态","session.focus":"在你点击时切换到本项目的会话","session.create":"在你点击时于本项目新建会话"};function Ei(t){return Mp[t]??t}const Pp=["themes","agent","productivity","integrations","insights","writing","fun"],Wn={themes:"主题外观",agent:"Agent 能力",productivity:"效率工作流",integrations:"外部集成",insights:"观测统计",writing:"写作翻译",fun:"休闲娱乐"};function Tp(t){return{installedKey:t,refresh:!0}}function Rp(t,s){return t.installedKey===s?t:{installedKey:s,refresh:!1}}function Ot(t){if(!t)return null;try{const s=new URL(t);return s.protocol==="https:"||s.protocol==="http:"?s.href:null}catch{return null}}function Op({pluginId:t,name:s,from:n,homepage:a,onClose:r}){const{t:o}=z();return e.jsx(pe,{open:t!==null,onOpenChange:i=>!i&&r(),children:e.jsxs(fe,{children:[e.jsx(ge,{children:e.jsxs(je,{children:[o("Usage guide"),s?` · ${s}`:""]})}),e.jsx(we,{className:"max-h-[60vh] space-y-3 overflow-y-auto",children:t&&e.jsx(Mi,{pluginId:t,from:n,homepage:a})})]})})}function Mi({pluginId:t,from:s,homepage:n,showLink:a=!0}){const{t:r}=z(),[o,i]=m.useState(null),[d,u]=m.useState(null),[x,h]=m.useState(Ot(n)),[l,f]=m.useState(null);return m.useEffect(()=>{let c=!0;return es(()=>import("./globals-BJ2xID1e.js").then(p=>p.np),__vite__mapDeps([0,1]),import.meta.url).then(p=>{c&&f(()=>p.Markdown)}),()=>{c=!1}},[]),m.useEffect(()=>{let c=!1;return i(null),u(null),h(Ot(n)),(async()=>{const p=window.electronAPI.extensionPlugins,g=await p.readme({id:t,from:s});let w=g.ok?g.markdown:null,k=g.ok?null:g.error;if(!g.ok&&s==="installed"){const j=await p.readme({id:t,from:"market"});j.ok&&(w=j.markdown,k=null)}if(!Ot(n)){const j=await p.marketList(!1),y=j.ok?j.plugins.find(N=>N.id===t):void 0;c||h(Ot(y?.homepage))}c||(i(w),u(w?null:k))})(),()=>{c=!0}},[t,s,n]),e.jsxs("div",{className:"space-y-3",children:[a&&x&&e.jsx("a",{href:x,target:"_blank",rel:"noreferrer",className:"text-sm underline",children:r("Homepage")}),d&&e.jsx("p",{className:"text-muted-foreground text-sm",children:d}),o===null&&!d&&e.jsx("p",{className:"text-muted-foreground text-sm",children:"…"}),o!==null&&l&&e.jsx(l,{text:o})]})}function Pi(t,s){return s==="all"?!0:s==="installed"?t.installedVersion!==void 0:s==="updates"?t.updateAvailable:s==="other"?t.category===void 0:t.category===s}function Dp(t){const s=r=>t.filter(o=>Pi(o,r)).length,n=["all","installed","updates"],a=[...Pp,"other"];return[...n.map(r=>({id:r,count:s(r)})),...a.map(r=>({id:r,count:s(r)})).filter(r=>r.count>0)]}function Lp(t,s){const n=s.query.trim().toLowerCase();return t.filter(a=>Pi(a,s.section)?n?[a.id,a.name,a.description,...a.tags].some(r=>r.toLowerCase().includes(n)):!0:!1).sort((a,r)=>a.tier!==r.tier?a.tier==="official"?-1:1:a.name.localeCompare(r.name))}const Lr={all:"全部",installed:"已安装",updates:"可更新",other:"其他"},zp=t=>t in Lr?Lr[t]:Wn[t];function _p({disabled:t,installedKey:s,onInstall:n}){const{t:a}=z(),r=window.electronAPI.extensionPlugins,[o,i]=m.useState(null),[d,u]=m.useState(!1),[x,h]=m.useState(""),[l,f]=m.useState("all"),[c,p]=m.useState(null),[g,w]=m.useState(()=>Tp(s)),k=Rp(g,s);k!==g&&w(k);const j=m.useCallback(async C=>{u(!0);try{i(await r.marketList(C))}catch(E){i({ok:!1,error:E instanceof Error?E.message:String(E),chinaMirror:!1})}finally{u(!1)}},[r]);m.useEffect(()=>{j(g.refresh)},[j,g]);const y=async C=>{await r.setMarketChinaMirror(C),await j(!0)},N=o?.ok===!0?o.plugins:[],A=Dp(N),O=A.some(C=>C.id===l)?l:"all",I=Lp(N,{query:x,section:O}),L=c?N.find(C=>C.id===c):void 0;return e.jsxs("div",{className:"flex h-[min(72vh,720px)] min-h-0 flex-col gap-3 sm:flex-row sm:gap-4",children:[e.jsx("nav",{"aria-label":"插件分类",className:"flex shrink-0 gap-1 overflow-x-auto pb-1 sm:block sm:w-36 sm:space-y-0.5 sm:overflow-y-auto sm:pb-0",children:A.map(C=>e.jsxs("button",{type:"button","aria-pressed":O===C.id,onClick:()=>{f(C.id),p(null)},className:G("flex shrink-0 items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left text-sm hover:bg-accent sm:w-full",O===C.id&&"bg-accent font-medium"),children:[e.jsx("span",{className:"truncate whitespace-nowrap",children:zp(C.id)}),e.jsx("span",{className:"text-muted-foreground text-xs tabular-nums",children:C.count})]},C.id))}),e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(J,{className:"min-w-40 flex-1",value:x,placeholder:a("Search plugins"),onChange:C=>{h(C.target.value),p(null)}}),e.jsxs("label",{className:"flex shrink-0 items-center gap-1.5 text-muted-foreground text-xs",children:[e.jsx(le,{checked:o?.chinaMirror??!1,disabled:d,onCheckedChange:C=>{y(C)}}),a("China mirror")]}),e.jsx(S,{size:"sm",variant:"ghost",disabled:d,onClick:()=>{j(!0)},children:d?e.jsx(St,{}):a("Refresh")})]}),o?.ok===!1&&e.jsx("p",{className:"text-destructive text-sm",children:o.error}),o?.ok===!0&&o.stale&&e.jsx("p",{className:"text-muted-foreground text-xs",children:a("Could not reach the marketplace; showing the last saved list.")}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto pr-1",children:L?e.jsx(Fp,{plugin:L,disabled:t,onBack:()=>p(null),onInstall:n}):o?.ok===!0&&I.length===0?e.jsx("p",{className:"text-muted-foreground text-sm",children:a("No matching plugins")}):e.jsx("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2",children:I.map(C=>e.jsx(Bp,{plugin:C,disabled:t,onOpen:()=>p(C.id),onInstall:n},C.id))})})]})]})}function Ti({plugin:t,disabled:s,onInstall:n}){const{t:a}=z();return t.installedVersion&&!t.updateAvailable?e.jsx("span",{className:"shrink-0 text-muted-foreground text-xs",children:a("Installed")}):e.jsx(S,{size:"xs",variant:t.updateAvailable?"default":"outline",disabled:s,onClick:r=>{r.stopPropagation(),n(t.id)},children:t.updateAvailable?a("Update"):a("Install")})}function Ri({tier:t}){const{t:s}=z();return e.jsx(te,{variant:t==="official"?"secondary":"outline",className:"text-[11px]",children:s(t==="official"?"Official":"Community")})}function Bp({plugin:t,disabled:s,onOpen:n,onInstall:a}){return e.jsxs("div",{role:"button",tabIndex:0,"aria-label":t.name,onClick:n,onKeyDown:r=>{r.target===r.currentTarget&&(r.key==="Enter"||r.key===" ")&&(r.preventDefault(),n())},className:"flex cursor-pointer flex-col gap-2 rounded-lg border p-3 text-left transition-colors hover:bg-accent/50",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Oi,{src:t.icon}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("p",{className:"flex items-center gap-1.5 text-sm",children:[e.jsx("span",{className:"truncate font-medium",children:t.name}),e.jsx(Ri,{tier:t.tier})]}),e.jsxs("p",{className:"text-muted-foreground text-xs",children:[t.latest,t.category?` · ${Wn[t.category]}`:""]})]}),e.jsx(Ti,{plugin:t,disabled:s,onInstall:a})]}),t.description&&e.jsx("p",{className:"line-clamp-2 text-muted-foreground text-xs",children:t.description})]})}function Fp({plugin:t,disabled:s,onBack:n,onInstall:a}){const{t:r}=z(),o=Ot(t.homepage);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs(S,{size:"xs",variant:"ghost",onClick:n,children:[e.jsx(Uo,{className:"size-3.5"}),"返回"]}),e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Oi,{src:t.icon,large:!0}),e.jsxs("div",{className:"min-w-0 flex-1 space-y-1",children:[e.jsxs("p",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("span",{className:"font-medium text-base",children:t.name}),e.jsx(Ri,{tier:t.tier}),t.category&&e.jsx(te,{variant:"outline",className:"text-[11px]",children:Wn[t.category]})]}),e.jsxs("p",{className:"font-mono text-muted-foreground text-xs",children:[t.id," · ",t.latest,t.installedVersion?` · 已装 ${t.installedVersion}`:""]}),t.description&&e.jsx("p",{className:"text-sm",children:t.description}),o&&e.jsxs("a",{href:o,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-primary text-xs hover:underline",children:[e.jsx(Yc,{className:"size-3"}),r("Homepage")]})]}),e.jsx(Ti,{plugin:t,disabled:s,onInstall:a})]}),t.screenshots&&t.screenshots.length>0&&e.jsx("div",{className:"flex gap-2 overflow-x-auto pb-1",children:t.screenshots.map(i=>e.jsx("img",{src:i.url,alt:i.alt,title:i.alt,loading:"lazy",className:"h-44 shrink-0 rounded-md border object-cover"},i.url))}),e.jsxs("section",{className:"space-y-1",children:[e.jsx("h3",{className:"font-medium text-sm",children:"权限"}),t.permissions.length===0?e.jsx("p",{className:"text-muted-foreground text-xs",children:"无特殊权限"}):e.jsx("ul",{className:"space-y-0.5",children:t.permissions.map(i=>e.jsxs("li",{className:"text-xs",children:[e.jsx("span",{className:"font-mono text-muted-foreground",children:i}),e.jsx("span",{className:"ml-2",children:Ei(i)})]},i))})]}),e.jsxs("section",{className:"space-y-1",children:[e.jsx("h3",{className:"font-medium text-sm",children:r("Usage guide")}),e.jsx(Mi,{pluginId:t.id,from:"market",homepage:t.homepage,showLink:!1})]})]})}function Oi({src:t,large:s}){const[n,a]=m.useState(!1);return e.jsx("div",{className:G("flex shrink-0 items-center justify-center rounded-md bg-muted",s?"size-12":"size-9"),children:t&&!n?e.jsx("img",{src:t,alt:"",className:s?"size-7 object-contain":"size-5 object-contain",onError:()=>a(!0)}):e.jsx(Bt,{className:"size-4 text-muted-foreground"})})}function Up(t){const{notice:s,remote:n,onDismiss:a}=t;return e.jsxs("div",{className:"space-y-1 rounded-md border border-amber-500/30 bg-amber-500/5 px-3 py-2 text-amber-700 text-sm dark:text-amber-400",children:[s.unreadable&&e.jsx("p",{children:"插件登记表曾读取失败,下面的列表可能不全。插件文件没有删除,原文保存在数据目录的 extension-plugins/registry.json.unreadable。"}),s.discarded.length>0&&e.jsxs("p",{children:["检测到旧格式的登记记录,已丢弃并清理,请重新安装:",e.jsx("span",{className:"font-mono",children:s.discarded.join(", ")})]}),n?e.jsx("p",{className:"text-muted-foreground",children:"请在桌面端点「知道了」,或运行 enso-server plugin notice-dismiss 清除此提示。"}):e.jsx(S,{size:"sm",variant:"outline",onClick:a,children:"知道了"})]})}function $p({pluginId:t,plain:s}){const{t:n}=z(),[a,r]=m.useState([]),[o,i]=m.useState({}),[d,u]=m.useState(null),x=m.useCallback(async()=>{const c=await window.electronAPI.extensionPlugins.configGet(t);c.ok?r(c.fields):u({error:!0,text:c.error}),i({})},[t]);m.useEffect(()=>{x()},[x]);const h=async()=>{const c={};for(const[g,w]of Object.entries(o)){const k=a.find(y=>y.key===g);if(!k||k.secret&&w==="")continue;const j=Ep(k,w);if(!j.ok){u({error:!0,text:`${k.title}:${j.error}`});return}c[g]=j.value}const p=await window.electronAPI.extensionPlugins.configSet(t,c);u(p.ok?{error:!1,text:n("Saved. New calls use it right away.")}:{error:!0,text:p.error??""}),p.ok&&await x()},l=c=>{const p=o[c.key];return typeof p=="string"?p:p===null||c.secret?"":c.value??(c.default!==void 0?String(c.default):"")},f=c=>{const p=o[c.key];return typeof p=="boolean"?p:(c.value??(typeof c.default=="boolean"?String(c.default):"false"))==="true"};return e.jsxs("div",{className:G("space-y-2",s?"":"rounded-md border border-border p-3"),children:[a.map(c=>e.jsxs("div",{className:"space-y-1",children:[e.jsxs("p",{className:"text-sm",children:[c.title,e.jsx("span",{className:"ml-2 font-mono text-muted-foreground text-xs",children:c.key})]}),c.description&&e.jsx("p",{className:"text-muted-foreground text-xs",children:c.description}),c.multiline&&c.type==="string"?e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(He,{autoComplete:"off",rows:4,value:l(c),placeholder:c.secret&&c.set?n("Set (leave blank to keep)"):n("Not set"),className:"min-w-0 flex-1",onChange:p=>i(g=>({...g,[c.key]:p.target.value}))}),c.set&&e.jsx(S,{size:"sm",variant:"ghost",onClick:()=>i(p=>({...p,[c.key]:null})),children:n("Clear value")})]}):c.secret||c.type==="string"||c.type==="number"||c.type==="path"?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(J,{type:c.secret?"password":c.type==="number"?"number":"text",autoComplete:"off",inputMode:c.type==="number"?"decimal":void 0,min:c.type==="number"?c.min:void 0,max:c.type==="number"?c.max:void 0,value:l(c),placeholder:c.secret&&c.set?n("Set (leave blank to keep)"):n("Not set"),onChange:p=>i(g=>({...g,[c.key]:p.target.value}))}),c.type==="path"&&!c.secret&&!window.electronAPI.remote&&e.jsx(S,{size:"sm",variant:"outline",onClick:()=>{window.electronAPI.extensionPlugins.pickPath(c.pathKind==="directory"?"directory":"file").then(p=>{p.ok&&"path"in p&&i(g=>({...g,[c.key]:p.path}))})},children:c.pathKind==="directory"?"选择文件夹":"选择文件"}),c.set&&e.jsx(S,{size:"sm",variant:"ghost",onClick:()=>i(p=>({...p,[c.key]:null})),children:n("Clear value")})]}):c.type==="boolean"?e.jsx(le,{checked:f(c),onCheckedChange:p=>i(g=>({...g,[c.key]:p}))}):e.jsxs(ae,{items:Object.fromEntries((c.options??[]).map(p=>[p,p])),value:l(c),onValueChange:p=>{typeof p=="string"&&i(g=>({...g,[c.key]:p}))},children:[e.jsx(re,{children:e.jsx(oe,{placeholder:"请选择"})}),e.jsx(ie,{children:(c.options??[]).map(p=>e.jsx(ee,{value:p,children:p},p))})]})]},c.key)),d&&e.jsx("p",{className:G("text-xs",d.error?"text-destructive":"text-muted-foreground"),children:d.text}),e.jsx(S,{size:"sm",disabled:Object.keys(o).length===0,onClick:()=>{h()},children:n("Save")})]})}function Vp({pluginId:t,plain:s}){const{t:n}=z(),[a,r]=m.useState(null),o=m.useCallback(async()=>{const i=await window.electronAPI.extensionPlugins.logs(t);r(i.ok?i.text:i.error)},[t]);return m.useEffect(()=>{o()},[o]),e.jsxs("div",{className:G("space-y-2",s?"":"rounded-md border border-border p-3"),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-sm",children:n("Plugin logs")}),e.jsx(S,{size:"icon",variant:"ghost","aria-label":n("Refresh"),onClick:()=>{o()},children:e.jsx(Je,{className:"size-4"})})]}),e.jsx("pre",{className:"max-h-64 overflow-auto whitespace-pre-wrap break-all font-mono text-muted-foreground text-xs",children:a===null?"":a||n("No logs yet")})]})}function zr({message:t}){const[s,n]=m.useState(!1);return e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("p",{className:G("select-text break-all font-mono text-destructive text-xs",s?"max-h-48 overflow-auto whitespace-pre-wrap":"line-clamp-2"),children:t}),t.length>120&&e.jsx("button",{type:"button",className:"text-muted-foreground text-xs hover:text-foreground",onClick:()=>n(a=>!a),children:s?"收起":"展开全部"})]})}function Di({permissions:t,styles:s=!1}){return t.length===0?s?null:e.jsx("p",{className:"text-muted-foreground text-xs",children:"无特殊权限"}):e.jsx("ul",{className:"space-y-0.5",children:t.map(n=>e.jsxs("li",{className:"text-xs",children:[e.jsx("span",{className:"font-mono text-muted-foreground",children:n}),e.jsx("span",{className:"ml-2",children:Ei(n)})]},n))})}function Kp(t){const s=t.intervalSeconds>=60&&t.intervalSeconds%60===0?`每 ${t.intervalSeconds/60} 分钟`:`每 ${t.intervalSeconds} 秒`,n=t.lastRunAt?` · 最近 ${new Date(t.lastRunAt).toLocaleString()}`:"";return`${t.id} · ${s}${n}${t.lastError?` · ${t.lastError}`:""}`}function _r(t){return[t.permissions.length>0?`${t.permissions.length} 项权限`:"",(t.events?.length??0)>0?`${t.events?.length} 个事件`:"",(t.schedules?.length??0)>0?`${t.schedules?.length} 个定时任务`:"",t.hasRenderer?"界面代码":"",t.crossSessionInject!==void 0?"跨会话投递开关":""].filter(Boolean).join(" · ")}function Br({permissions:t,env:s,interop:n,resident:a,running:r,styles:o,trustedUi:i,events:d,schedules:u}){return e.jsxs("div",{className:"space-y-1",children:[e.jsx(Di,{permissions:t,styles:o||i}),i&&e.jsx(qp,{}),a&&e.jsxs("p",{className:"text-xs",children:["常驻进程",r===void 0?"":r?":运行中":":未运行"]}),o&&e.jsx("p",{className:"text-xs",children:"修改界面样式:主题 CSS 可以改变应用的任意界面"}),(s?.length??0)>0&&e.jsxs("p",{className:"text-xs",children:["环境变量:",e.jsx("span",{className:"font-mono",children:s?.join(", ")})]}),(n?.length??0)>0&&e.jsxs("p",{className:"text-xs",children:["可调用插件:",e.jsx("span",{className:"font-mono",children:n?.join(", ")})]}),d?.map(x=>e.jsxs("p",{className:"text-xs",children:["事件 ",x.event," · ",x.mode==="intercept"?"拦截":"观察",x.failClosed?" · 失败即拒绝":""]},`${x.event}:${x.mode}`)),u?.map(x=>e.jsxs("p",{className:"text-xs",children:["定时任务 ",Kp(x)]},x.id))]})}function qp(){return e.jsx("p",{className:"text-amber-700 text-xs dark:text-amber-400",children:"界面代码:运行在主界面里,可读写页面内容、调用界面能力,不受上面权限清单约束;只安装信任的插件"})}function Gp({pluginId:t,plain:s}){const[n,a]=m.useState(null),[r,o]=m.useState(null),i=m.useCallback(async()=>{const d=await window.electronAPI.extensionPlugins.artifactsList(t);d.ok?(a(d.artifacts),o(null)):o(d.error)},[t]);return m.useEffect(()=>{i()},[i]),e.jsxs("div",{className:G("space-y-2",s?"":"rounded-md border border-border p-3"),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-sm",children:"产出文件"}),e.jsx(S,{size:"icon",variant:"ghost","aria-label":"刷新",onClick:()=>{i()},children:e.jsx(Je,{className:"size-4"})})]}),r&&e.jsx("p",{className:"text-destructive text-xs",children:r}),e.jsx(td,{artifacts:n??[],onDelete:d=>{window.electronAPI.extensionPlugins.artifactDelete(d).then(u=>{u.ok?i():o(u.error??"删除失败")})}})]})}const Xs=new Set;function Hp({requestedInstallUrl:t=null,onRequestedInstallUrlConsumed:s,focusPluginId:n=null,onFocusPluginConsumed:a}={}){const{t:r}=z(),o=v(R=>R.pluginAutoUpdate!==!1),i=v(R=>R.setPluginAutoUpdate),[d,u]=m.useState([]),x=Dn(R=>R.errors),[h,l]=m.useState(null),[f,c]=m.useState(null),[p,g]=m.useState([]),[w,k]=m.useState(!1),[j,y]=m.useState(null),[N,A]=m.useState(""),[O,I]=m.useState(!1),[L,C]=m.useState(!1),[E,M]=m.useState(null),[V,F]=m.useState(null),[b,B]=m.useState(!1),[K,D]=m.useState(null),$=m.useCallback(async()=>{try{u(await window.electronAPI.extensionPlugins.list())}catch{u([])}},[]);m.useEffect(()=>($(),window.electronAPI.extensionPlugins.registryNotice().then(F).catch(()=>F(null)),window.electronAPI.extensionPlugins.onChanged(()=>{$()})),[$]),m.useEffect(()=>{if(!n||(g(P=>P.includes(n)?P:[...P,n]),!d.some(P=>P.id===n)))return;const R=n;window.requestAnimationFrame(()=>{document.querySelector(`[data-plugin-id="${CSS.escape(R)}"]`)?.scrollIntoView({block:"center"})}),a?.()},[n,d,a]);const Y=async R=>{y(null),h&&window.electronAPI.extensionPlugins.discard(h.token),l(null);const P=await window.electronAPI.extensionPlugins.pickAndStage(R);P.ok?"cancelled"in P||l(P.preview):y(P.error)},H=async R=>{const P=(R??N).trim();if(!P)return;y(null),I(!0),h&&window.electronAPI.extensionPlugins.discard(h.token),l(null);const ce=await window.electronAPI.extensionPlugins.stageFromUrl(P).finally(()=>{I(!1)});ce.ok?l(ce.preview):y(ce.error)},se=m.useRef(H);se.current=H,m.useEffect(()=>{if(!t)return;const R=t;let P=!1;const ce=window.setTimeout(()=>{P||Xs.has(R)||(Xs.add(R),A(R),s?.(),se.current(R).finally(()=>{Xs.delete(R)}))},0);return()=>{P=!0,window.clearTimeout(ce)}},[t,s]);const q=async(R,P=!1)=>{y(null),h&&window.electronAPI.extensionPlugins.discard(h.token),l(null),I(!0);const ce=window.electronAPI.extensionPlugins,xe=await(P?ce.marketStage(R):ce.restage(R)).finally(()=>{I(!1)});xe.ok?l(xe.preview):y(xe.error)},Q=async()=>{C(!0),M(null);try{const R=await window.electronAPI.extensionPlugins.checkUpdates();M(R.checked===0?r("No plugins installed from GitHub to check"):R.available>0?r("{{count}} update(s) available",{count:R.available}):r("All plugins are up to date"))}finally{C(!1)}},_=async()=>{if(!h)return;k(!0);const R=await window.electronAPI.extensionPlugins.commit(h.token);if(k(!1),!R.ok)y(R.error??r("Install failed"));else{A("");const P=h.existingVersion?{ok:!0}:await window.electronAPI.extensionPlugins.setEnabled(h.id,!0);Re({type:P.ok?"success":"warning",title:r("{{name}} installed",{name:h.name}),description:P.ok?void 0:P.error})}l(null)},ne=()=>{h&&window.electronAPI.extensionPlugins.discard(h.token),l(null)};return e.jsxs("div",{className:"space-y-5","data-settings-row":"plugins.enso",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"font-medium text-lg",children:[r("Enso plugins"),e.jsx(qe,{})]}),e.jsx("p",{className:"mt-1 text-muted-foreground text-sm",children:r("Installing a plugin lets it run code on this machine. Review what it asks for before confirming.")})]}),e.jsxs("div",{className:"flex shrink-0 gap-2",children:[d.length>0&&e.jsxs(S,{size:"sm",variant:"outline",disabled:L,onClick:()=>{Q()},children:[L?e.jsx(St,{}):e.jsx(Je,{className:"size-4"}),r("Check for updates")]}),e.jsxs(S,{size:"sm",onClick:()=>B(!0),children:[e.jsx($u,{className:"size-4"}),r("Marketplace")]})]})]}),e.jsxs("label",{className:"flex items-center justify-between gap-3 text-sm",children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block",children:r("Update plugins automatically")}),e.jsx("span",{className:"block text-muted-foreground text-xs",children:r("Marketplace updates that do not ask for new permissions install on their own.")})]}),e.jsx(le,{className:"shrink-0",checked:o,onCheckedChange:R=>i(R)})]}),e.jsxs("div",{className:"space-y-2.5 rounded-lg border bg-muted/30 p-3",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(_o,{className:"flex-1",children:[e.jsx(Fo,{children:e.jsx(ai,{className:"size-4 text-muted-foreground"})}),e.jsx(Bo,{value:N,placeholder:r("https://github.com/owner/repo"),onChange:R=>A(R.target.value),onKeyDown:R=>{R.key==="Enter"&&H()}})]}),e.jsx(S,{size:"sm",variant:"outline",disabled:w||O||N.trim()==="",onClick:()=>{H()},children:O?e.jsx(St,{}):r("Install from URL")})]}),e.jsxs("div",{className:"flex items-center gap-1 text-muted-foreground text-xs",children:[e.jsx("span",{className:"mr-1",children:r("Or install from")}),e.jsxs(S,{size:"xs",variant:"ghost",disabled:w||O,onClick:()=>{Y("dir")},children:[e.jsx(_n,{className:"size-3.5"}),r("Install from folder")]}),e.jsxs(S,{size:"xs",variant:"ghost",disabled:w||O,onClick:()=>{Y("zip")},children:[e.jsx(Jc,{className:"size-3.5"}),r("Install from zip")]})]})]}),j&&e.jsx("p",{className:"text-destructive text-sm",children:j}),e.jsx(pe,{open:b,onOpenChange:B,children:e.jsxs(fe,{className:"max-w-5xl",children:[e.jsx(ge,{children:e.jsx(je,{children:r("Marketplace")})}),e.jsx(we,{children:e.jsx(_p,{disabled:w||O,installedKey:d.map(R=>`${R.id}@${R.version}`).join(","),onInstall:R=>{B(!1),q(R,!0)}})})]})}),E&&e.jsx("p",{className:"text-muted-foreground text-sm",children:E}),V&&e.jsx(Up,{notice:V,remote:!!window.electronAPI.remote,onDismiss:()=>{window.electronAPI.extensionPlugins.dismissRegistryNotice().then(()=>F(null)).catch(R=>y(R instanceof Error?R.message:String(R)))}}),e.jsx(pe,{open:h!==null,onOpenChange:R=>!R&&!w&&ne(),children:e.jsx(fe,{children:h&&e.jsxs(e.Fragment,{children:[e.jsx(ge,{children:e.jsxs(je,{children:[h.name," ",h.version,h.existingVersion&&e.jsx("span",{className:"ml-2 text-base text-muted-foreground",children:r("updating from {{version}}",{version:h.existingVersion})})]})}),e.jsxs(we,{className:"space-y-3",children:[e.jsx(Br,{permissions:h.permissions,env:h.env,interop:h.interop,resident:h.resident,styles:h.styles,trustedUi:h.hasRenderer,events:h.events,schedules:h.schedules}),h.mcpServers.map(R=>e.jsxs("p",{className:"font-mono text-xs",children:[R.command," ",R.args.join(" ")]},R.name)),h.mcpTools.length>0&&e.jsxs("p",{className:"text-muted-foreground text-xs",children:[r("Host MCP tools it may call"),":",e.jsx("span",{className:"font-mono",children:h.mcpTools.join(", ")})]}),h.warnings.map(R=>e.jsx("p",{className:"text-muted-foreground text-xs",children:R},R))]}),e.jsxs(Ie,{children:[e.jsx(S,{size:"sm",variant:"ghost",disabled:w,onClick:ne,children:r("Cancel")}),e.jsx(S,{size:"sm",disabled:w,onClick:()=>{_()},children:w?e.jsx(St,{}):r("Install")})]})]})})}),d.length===0&&!h&&e.jsxs("div",{className:"rounded-lg border border-dashed px-3 py-10 text-center",children:[e.jsx(Bt,{className:"mx-auto size-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:r("No Enso plugins installed")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:r("Browse the marketplace or install from a GitHub URL, folder or zip.")})]}),e.jsx("div",{className:"space-y-2",children:d.map(R=>e.jsxs("div",{"data-plugin-id":R.id,className:G("overflow-hidden rounded-lg border bg-card transition-colors",R.state==="crashed"&&"border-destructive/50"),children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-x-3 gap-y-2 p-3",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 basis-56 items-start gap-3",children:[e.jsx("div",{className:G("flex size-9 shrink-0 items-center justify-center rounded-md bg-muted",R.state==="enabled"?"text-foreground":"text-muted-foreground"),children:e.jsx(Qc,{pluginId:R.id,icon:R.icon,className:"size-4"})}),e.jsxs("div",{className:"min-w-0 flex-1 space-y-0.5",children:[e.jsxs("p",{className:"flex flex-wrap items-center gap-1.5 text-sm",children:[e.jsx("span",{className:"truncate font-medium",children:R.name}),e.jsx(te,{variant:"outline",className:"text-[11px]",children:R.version}),R.state==="crashed"&&e.jsx(te,{variant:"destructive",className:"text-[11px]",children:r("Stopped after crashes")}),R.availableVersion&&e.jsx(te,{className:"text-[11px]",children:r("Update")}),R.pendingVersion&&e.jsx(te,{variant:"warning",className:"text-[11px]",children:"待授权"}),R.hasRenderer&&e.jsx(te,{variant:"outline",className:"text-[11px]",children:"受信任界面"}),R.devWatch&&e.jsx(te,{variant:"secondary",className:"text-[11px]",children:"开发模式"}),R.resident&&e.jsx(te,{variant:R.running?"secondary":"outline",className:"text-[11px]",children:R.running?"常驻运行中":"常驻未运行"})]}),e.jsx("p",{className:"truncate font-mono text-muted-foreground text-xs",children:R.id}),R.availableVersion&&e.jsxs("p",{className:"mt-1 flex items-center gap-2 text-primary text-xs",children:[r("Version {{version}} is available",{version:R.availableVersion}),e.jsx(S,{size:"xs",disabled:w||O,onClick:()=>{q(R.id,R.source?.kind!=="url")},children:O?e.jsx(St,{}):r("Update")})]}),R.updateCheckError&&e.jsx("p",{className:"text-muted-foreground text-xs",children:r("Update check failed: {{reason}}",{reason:R.updateCheckError})}),R.lastError&&e.jsx(zr,{message:R.lastError.message}),x[R.id]?.map(P=>e.jsx(zr,{message:`主题加载失败:${P}`},P)),R.pendingVersion&&e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2 rounded-md border border-amber-500/50 bg-amber-500/10 px-2 py-1.5 text-amber-700 text-xs dark:text-amber-400",children:[r("{{version}} asks for more and is waiting for approval",{version:R.pendingVersion}),e.jsx(S,{size:"xs",onClick:()=>{window.electronAPI.extensionPlugins.approvePending(R.id)},children:r("Allow")}),e.jsx(S,{size:"xs",variant:"ghost",onClick:()=>{window.electronAPI.extensionPlugins.rejectPending(R.id)},children:r("Keep current")})]})]})]}),e.jsxs("div",{className:"ml-auto flex shrink-0 items-center gap-0.5",children:[R.source&&e.jsx(S,{size:"icon",variant:"ghost",disabled:w||O,"aria-label":r("Reinstall from source"),title:R.source.kind==="url"?`${r("Reinstall from source")}: ${R.source.url}`:r("Reinstall from source"),onClick:()=>{q(R.id)},children:e.jsx(Xc,{className:"size-4"})}),e.jsx(S,{size:"icon",variant:"ghost","aria-label":"产出文件",title:"产出文件",onClick:()=>c({kind:"artifacts",pluginId:R.id,pluginName:R.name}),children:e.jsx(Zc,{className:"size-4"})}),e.jsx(S,{size:"icon",variant:"ghost","aria-label":r("Usage guide"),title:r("Usage guide"),onClick:()=>D({id:R.id,name:R.name,from:"installed"}),children:e.jsx(vu,{className:"size-4"})}),e.jsx(S,{size:"icon",variant:"ghost","aria-label":r("Plugin logs"),title:r("Plugin logs"),onClick:()=>c({kind:"logs",pluginId:R.id,pluginName:R.name}),children:e.jsx($n,{className:"size-4"})}),R.configurable&&e.jsx(S,{size:"icon",variant:"ghost","aria-label":r("Configure"),title:r("Configure"),onClick:()=>c({kind:"config",pluginId:R.id,pluginName:R.name}),children:e.jsx(ed,{className:"size-4"})}),e.jsx(S,{size:"icon",variant:"ghost","aria-label":r("Uninstall"),title:r("Uninstall"),className:"text-muted-foreground hover:text-destructive",onClick:()=>{window.electronAPI.extensionPlugins.uninstall(R.id)},children:e.jsx(Me,{className:"size-4"})}),e.jsx("div",{className:"mx-1.5 h-5 w-px bg-border"}),e.jsx(le,{checked:R.state==="enabled",onCheckedChange:P=>{window.electronAPI.extensionPlugins.setEnabled(R.id,P)}})]})]}),e.jsxs("button",{type:"button","aria-expanded":p.includes(R.id),className:G("flex w-full items-center gap-1 border-t bg-muted/20 px-3 py-1.5 text-left text-xs","text-muted-foreground transition-colors hover:bg-muted/50 hover:text-foreground"),onClick:()=>g(P=>P.includes(R.id)?P.filter(ce=>ce!==R.id):[...P,R.id]),children:[p.includes(R.id)?e.jsx(ns,{className:"size-3"}):e.jsx(Mt,{className:"size-3"}),p.includes(R.id)?"收起详情":"详情",!p.includes(R.id)&&_r(R)&&e.jsx("span",{className:"ml-1 opacity-70",children:_r(R)})]}),p.includes(R.id)&&e.jsxs("div",{className:"space-y-3 border-t px-3 py-3",children:[R.interceptBreakers?.map(P=>e.jsxs("p",{className:"text-amber-600 text-xs dark:text-amber-400",children:[P.event," 检查连续失败,临时放行到"," ",new Date(P.until).toLocaleTimeString()]},P.event)),e.jsx(Br,{permissions:R.permissions,resident:R.resident,running:R.running,styles:R.themes.some(P=>P.css!==void 0),trustedUi:R.hasRenderer,events:R.events,schedules:R.schedules}),R.crossSessionInject!==void 0&&e.jsxs("div",{className:"flex items-center justify-between gap-3 text-xs",children:[e.jsxs("span",{children:[e.jsx("span",{className:"block",children:"允许向任意运行中的会话发送消息"}),e.jsx("span",{className:"block text-muted-foreground",children:"关闭时只能发到发起调用的会话;开启后定时任务、常驻进程也能向其他项目和窗口的会话发消息并触发执行"})]}),e.jsx(le,{"aria-label":"允许向任意运行中的会话发送消息",checked:R.crossSessionInject,onCheckedChange:P=>{window.electronAPI.extensionPlugins.setCrossSessionInject(R.id,P)}})]}),R.devWatch!==void 0&&e.jsxs("div",{className:"flex items-center justify-between gap-3 text-xs",children:[e.jsxs("span",{children:[e.jsx("span",{className:"block",children:"开发模式:目录改动后自动重装"}),e.jsx("span",{className:"block text-muted-foreground",children:"授权没扩大时直接替换;扩大时停下,需要从来源重新安装并同意。重启应用后关闭"})]}),e.jsx(le,{"aria-label":"开发模式:目录改动后自动重装",checked:R.devWatch,onCheckedChange:P=>{window.electronAPI.extensionPlugins.setDevWatch(R.id,P).then(ce=>{!ce.ok&&ce.error&&Re({title:ce.error})})}})]}),((R.pendingPermissions?.length??0)>0||R.pendingRenderer)&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:"待同意"}),e.jsx(Di,{permissions:R.pendingPermissions??[],styles:R.pendingRenderer}),R.pendingRenderer&&e.jsx("p",{className:"text-amber-700 text-xs dark:text-amber-400",children:"新增界面代码:运行在主界面里,不受权限清单约束"})]})]})]},R.id))}),e.jsx(pe,{open:f!==null,onOpenChange:R=>!R&&c(null),children:e.jsxs(fe,{children:[e.jsx(ge,{children:e.jsxs(je,{children:[f?.kind==="config"?r("Configure"):f?.kind==="logs"?r("Plugin logs"):"产出文件",f?` · ${f.pluginName}`:""]})}),e.jsxs(we,{className:"space-y-4",children:[f?.kind==="config"&&e.jsx($p,{pluginId:f.pluginId,plain:!0}),f?.kind==="logs"&&e.jsx(Vp,{pluginId:f.pluginId,plain:!0}),f?.kind==="artifacts"&&e.jsx(Gp,{pluginId:f.pluginId,plain:!0})]})]})}),e.jsx(Op,{pluginId:K?.id??null,name:K?.name??"",from:K?.from??"installed",homepage:K?.homepage,onClose:()=>D(null)})]})}function Wp(t,s){return[[t.skills.length,s("Skills")],[t.commands.length,s("Commands")],[t.agents.length,s("Agent types")],[t.mcpServers.length,"MCP"],[t.hooks.length,"Hooks"]].filter(([n])=>n>0).map(([n,a])=>`${a} ${n}`).join(" · ")}function Nt({label:t,items:s}){return s.length===0?null:e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("p",{className:"font-medium text-muted-foreground text-xs",children:t}),s.map(n=>e.jsx("p",{className:"break-all font-mono text-[11px]",children:n},n))]})}function Yp({plugin:t,entry:s,onToggle:n}){const{t:a}=z(),[r,o]=m.useState(!1),{components:i}=t,d=Wp(i,a);return e.jsxs("div",{className:"rounded-md border","data-settings-row":`plugins.${t.key}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 px-3 py-2",children:[e.jsxs("button",{type:"button",className:"flex min-w-0 flex-1 items-center gap-2 text-left",onClick:()=>o(u=>!u),children:[e.jsx(Mt,{className:G("h-4 w-4 shrink-0 text-muted-foreground transition-transform",r&&"rotate-90")}),e.jsx("span",{className:"shrink-0 font-medium text-sm",children:t.name}),t.version&&e.jsx(te,{variant:"outline",className:"shrink-0 text-[11px]",children:t.version}),t.marketplace&&e.jsx(te,{variant:"secondary",className:"shrink-0 text-[11px]",children:t.marketplace}),e.jsx("span",{className:"min-w-0 truncate text-muted-foreground text-xs",children:d||(i.unsupported.length>0?`${a("Not supported")}: ${i.unsupported.join(", ")}`:a("No supported components"))})]}),e.jsx(le,{checked:s?.enabled===!0,onCheckedChange:n})]}),r&&e.jsxs("div",{className:"space-y-2 border-t px-3 py-2",children:[t.description&&e.jsx("p",{className:"text-muted-foreground text-xs",children:t.description}),e.jsx(Nt,{label:a("Skills"),items:i.skills}),e.jsx(Nt,{label:a("Commands"),items:i.commands.map(u=>`/${u}`)}),e.jsx(Nt,{label:a("Agent types"),items:i.agents}),e.jsx(Nt,{label:a("MCP servers (run when a session starts)"),items:i.mcpServers.map(u=>`${u.name}: ${u.target}`)}),e.jsx(Nt,{label:a("Hooks (run automatically on local sessions)"),items:i.hooks.map(u=>`${u.event}: ${u.command}`)}),e.jsx(Nt,{label:a("Not supported"),items:i.unsupported})]})]})}function Jp(){const{t}=z(),s=v(c=>c.plugins),n=v(c=>c.addPlugins),a=v(c=>c.setPluginEnabled),r=v(c=>c.removePlugin),[o,i]=m.useState(null),d=m.useCallback(async()=>{i(null);try{i(await window.electronAPI.assets.listInstalledPlugins())}catch{i([])}},[]);m.useEffect(()=>{d()},[d]);const u=new Map(s.map(c=>[c.key,c])),x=new Set((o??[]).map(c=>c.key)),h=o?s.filter(c=>!x.has(c.key)):[],l=s.filter(c=>c.enabled).length,f=(c,p)=>{const g=u.get(c.key);if(g){a(g.id,p);return}n([{id:crypto.randomUUID(),key:c.key,name:c.name,description:c.description,...c.version?{version:c.version}:{},source:c.marketplace||"Claude Code",enabled:p}])};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-end justify-between gap-4","data-settings-row":"plugins.root",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"font-medium text-lg",children:[t("Claude Code plugins"),e.jsx(qe,{}),l>0&&e.jsx("span",{className:"ml-2 font-normal text-muted-foreground text-xs",children:t("{{count}} enabled",{count:l})})]}),e.jsx("p",{className:"text-muted-foreground text-sm",children:t("Plugins installed in Claude Code. Each one is switched on or off as a whole here; changes apply to new sessions.")})]}),e.jsxs(S,{variant:"outline",size:"sm",onClick:d,disabled:o===null,children:[e.jsx(Je,{className:"mr-1.5 h-4 w-4"}),t("Rescan")]})]}),o===null?e.jsx("div",{className:"flex justify-center py-10",children:e.jsx(St,{className:"size-5"})}):o.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx(Bt,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:t("No Claude Code plugins found")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:t("Install plugins with /plugin in Claude Code, then rescan.")})]}):e.jsx("div",{className:"space-y-2",children:o.map(c=>e.jsx(Yp,{plugin:c,entry:u.get(c.key),onToggle:p=>f(c,p)},c.key))}),h.length>0&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"font-medium text-muted-foreground text-xs",children:t("No longer installed in Claude Code")}),h.map(c=>e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md px-3 py-2 hover:bg-accent/50",children:[e.jsx("span",{className:"text-muted-foreground text-sm line-through",children:c.name}),e.jsx(S,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-destructive",onClick:()=>r(c.id),children:e.jsx(Me,{className:"h-3.5 w-3.5"})})]},c.id))]})]})}const zt={mask:"Mask",warn:"Warn only",block:"Block"},Qp={email:"Email",phone:"Phone number",idCard:"ID card number",bankCard:"Bank card number",ip:"IP address"},yn={mask:"text-sky-600 dark:text-sky-400",warn:"text-amber-600 dark:text-amber-400",block:"text-red-600 dark:text-red-400"},Xp=[1,7,30],Zp={1:"Today",7:"7D",30:"30D"};function ef(t){const s=new Map;for(const n of t.report.hits){const a=s.get(n.token);a?a.count+=n.count:s.set(n.token,{label:`${n.kind} ${n.preview}`,count:n.count})}return[...s.values()].map(n=>n.count>1?`${n.label} ×${n.count}`:n.label).join(", ")}function Zs({value:t,onChange:s}){const{t:n}=z(),a=Object.fromEntries(Object.keys(zt).map(r=>[r,n(zt[r])]));return e.jsxs(ae,{items:a,value:t,onValueChange:r=>s(r),children:[e.jsx(re,{className:"w-32",children:e.jsx(oe,{})}),e.jsx(ie,{children:Object.entries(a).map(([r,o])=>e.jsx(ee,{value:r,children:o},r))})]})}function en({label:t,hint:s,value:n,onCommit:a,rowId:r}){const[o,i]=m.useState(n.join(`
25
25
  `));return m.useEffect(()=>i(n.join(`
26
26
  `)),[n]),e.jsxs("div",{className:"space-y-1.5","data-settings-row":r,children:[e.jsx("p",{className:"text-sm",children:t}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s}),e.jsx(He,{rows:3,value:o,onChange:d=>i(d.target.value),onBlur:()=>a(o.split(`
27
- `))})]})}function It({title:t,children:s}){return e.jsxs("div",{className:"space-y-3 rounded-md border p-3",children:[e.jsx("p",{className:"text-sm font-medium",children:t}),s]})}function Zp({settings:t}){const{t:s}=z(),[n,a]=m.useState(""),r=m.useMemo(()=>nd(n,t),[n,t]);return e.jsxs(It,{title:s("Try it"),children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Runs locally. Nothing is remembered or sent anywhere.")}),e.jsx(He,{rows:3,value:n,placeholder:s("Paste some text, e.g. an .env file"),onChange:o=>a(o.target.value)}),n&&e.jsxs(e.Fragment,{children:[e.jsx("pre",{className:"max-h-48 overflow-auto whitespace-pre-wrap rounded bg-muted p-2 text-xs",children:r.text}),e.jsxs("ul",{className:"space-y-0.5 text-xs",children:[r.report.hits.map(o=>e.jsxs("li",{className:"flex gap-2",children:[e.jsx("span",{className:G("font-medium",yn[o.action]),children:s(zt[o.action])}),e.jsx("span",{children:o.kind}),e.jsx("span",{className:"text-muted-foreground",children:o.preview}),o.count>1&&e.jsxs("span",{className:"text-muted-foreground",children:["×",o.count]})]},`${o.token}-${o.action}`)),r.report.hits.length===0&&e.jsx("li",{className:"text-muted-foreground",children:s("Nothing matched")})]})]})]})}function ef(){const{t}=z(),[s,n]=m.useState(7),[a,r]=m.useState(null),[o,i]=m.useState(!1),d=m.useRef(0),u=ad(f=>f.conversations),x=m.useCallback(async f=>{const c=++d.current;i(!0);const p=await window.electronAPI.privacyMask.records(f).catch(()=>[]);c===d.current&&(i(!1),r(p))},[]);m.useEffect(()=>{x(s)},[s,x]);const h=m.useMemo(()=>{const f={mask:0,warn:0,block:0},c=new Map;for(const p of a??[]){const g=new Set;for(const w of p.report.hits){const k=`${w.action}:${w.token}`;g.has(k)||(g.add(k),f[w.action]+=1,c.set(w.kind,(c.get(w.kind)??0)+1))}}return{byAction:f,byKind:[...c].sort((p,g)=>g[1]-p[1])}},[a]),l=f=>{if(f.source==="aux")return t("Auxiliary request");const c=f.sessionId?u[f.sessionId]?.title:void 0,p=f.source==="compaction"?t("Compaction"):t("Session");return c?`${p} · ${c}`:p};return e.jsxs(It,{title:t("Records"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"flex gap-1",children:Jp.map(f=>e.jsx(S,{size:"sm",variant:f===s?"secondary":"ghost",onClick:()=>n(f),children:t(Qp[f])},f))}),e.jsx(S,{variant:"ghost",size:"icon-sm",onClick:()=>{x(s)},disabled:o,"aria-label":t("Refresh"),children:e.jsx(Je,{className:G("size-4",o&&"animate-spin")})})]}),e.jsx("div",{className:"flex flex-wrap gap-4 text-sm",children:Object.keys(zt).map(f=>e.jsxs("span",{children:[e.jsx("span",{className:yn[f],children:t(zt[f])})," ",e.jsx("span",{className:"font-medium tabular-nums",children:h.byAction[f]})]},f))}),h.byKind.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 text-xs text-muted-foreground",children:h.byKind.map(([f,c])=>e.jsxs("span",{className:"rounded bg-muted px-1.5 py-0.5",children:[f," ",c]},f))}),e.jsxs("div",{className:"max-h-80 overflow-auto",children:[e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{className:"text-left text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"py-1 pr-2 font-normal",children:t("Requested at")}),e.jsx("th",{className:"py-1 pr-2 font-normal",children:t("Source")}),e.jsx("th",{className:"py-1 pr-2 font-normal",children:t("Model")}),e.jsx("th",{className:"py-1 font-normal",children:t("Hits")})]})}),e.jsx("tbody",{children:(a??[]).slice(0,200).map(f=>{const c=rd(f.report),p=`${f.at}:${f.sessionId??f.source}:${f.model}:${f.report.hits.map(g=>g.token).join(",")}`;return e.jsxs("tr",{className:"border-t align-top",children:[e.jsx("td",{className:"py-1 pr-2 whitespace-nowrap tabular-nums",children:new Date(f.at).toLocaleString()}),e.jsx("td",{className:"py-1 pr-2",children:l(f)}),e.jsx("td",{className:"py-1 pr-2 break-all",children:f.model}),e.jsxs("td",{className:G("py-1",c&&yn[c]),children:[Xp(f),f.report.blocked&&` · ${t("Request blocked")}`]})]},p)})})]}),a?.length===0&&e.jsx("p",{className:"py-4 text-center text-xs text-muted-foreground",children:t("No records yet")})]})]})}function tf(){const{t}=z(),s=v(r=>r.privacyMasking),n=v(r=>r.setPrivacyMasking),a=r=>n({...s,...r});return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:t("Privacy")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("Replace API keys and personal data with placeholders before requests leave this device, and restore them in replies. Original values stay in memory on this device only.")})]}),e.jsx(Te,{rowId:"privacy.enabled",title:t("Privacy masking"),description:t("Applies to chats, compaction, bot members and helper requests."),checked:s.enabled,onChange:r=>a({enabled:r})}),s.enabled&&e.jsxs(e.Fragment,{children:[e.jsxs(It,{title:t("Secrets"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:t("API keys, tokens, private keys, passwords in URLs and config files.")}),e.jsx(Zs,{value:s.secrets.action,onChange:r=>a({secrets:{...s.secrets,action:r}})})]}),e.jsx(Te,{rowId:"privacy.secrets",title:t("Detect secrets"),description:t("Recommended. Covers common vendor key formats."),checked:s.secrets.enabled,onChange:r=>a({secrets:{...s.secrets,enabled:r}})}),e.jsx(Te,{rowId:"privacy.shape",title:t("Send look-alike keys"),description:t("Replace keys with fake keys of the same format instead of placeholders, so the model treats them as real keys."),checked:s.secrets.shape,onChange:r=>a({secrets:{...s.secrets,shape:r}})})]}),e.jsxs(It,{title:t("Personal data"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Emails, phone numbers, ID and bank card numbers, IP addresses.")}),e.jsx(Zs,{value:s.personal.action,onChange:r=>a({personal:{...s.personal,action:r}})})]}),e.jsx(Te,{rowId:"privacy.personal",title:t("Detect personal data"),description:t("Matches are validated (checksums, real domains) to limit false hits."),checked:s.personal.enabled,onChange:r=>a({personal:{...s.personal,enabled:r}})}),s.personal.enabled&&e.jsx("div",{className:"flex flex-wrap gap-4",children:sd.map(r=>e.jsxs("label",{className:"flex items-center gap-1.5 text-sm",children:[e.jsx(Qe,{checked:s.personal.kinds.includes(r),onCheckedChange:o=>a({personal:{...s.personal,kinds:o?[...s.personal.kinds,r]:s.personal.kinds.filter(i=>i!==r)}})}),t(Yp[r])]},r))})]}),e.jsxs(It,{title:t("Custom rules"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Words and patterns specific to your work.")}),e.jsx(Zs,{value:s.custom.action,onChange:r=>a({custom:{...s.custom,action:r}})})]}),e.jsx(en,{rowId:"privacy.words",label:t("Words"),hint:t("One per line, case-insensitive. Project codenames, customer names…"),value:s.custom.words,onCommit:r=>a({custom:{...s.custom,words:r}})}),e.jsx(en,{rowId:"privacy.rules",label:t("Prefixes or patterns"),hint:t("One per line. A prefix like corp_ or a regex like /INC-\\d{4}/i."),value:s.custom.rules,onCommit:r=>a({custom:{...s.custom,rules:r}})})]}),e.jsx(It,{title:t("Allow list"),children:e.jsx(en,{rowId:"privacy.allow",label:t("Never mask"),hint:t("Exact values, one per line. Team emails, test keys…"),value:s.allow,onCommit:r=>a({allow:r})})}),e.jsx(Zp,{settings:s})]}),e.jsx(ef,{})]})}function sf(){const{t}=z(),s=v(c=>c.approvalReviewer),n=v(c=>c.setApprovalReviewer),a=v(c=>c.approvalAutoManage),r=v(c=>c.setApprovalAutoManage),o=od(v(c=>c.approvalAllowThreshold)),i=v(c=>c.setApprovalAllowThreshold),d={"0.85":t("0.85 (looser)"),"0.9":t("0.9 (default)"),"0.95":t("0.95 (stricter)")},u=Xe(),x=_n(),h=m.useMemo(()=>[...u,...x.filter(xn)],[u,x]),l=s?h.find(c=>c.id===s.providerId):void 0,f=l?.models.find(c=>c.id===s?.modelId);return e.jsxs("section",{className:"space-y-2 rounded-lg border bg-card p-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h4",{className:"font-medium text-sm",children:t("Assistant approval model")}),e.jsx("p",{className:"mt-0.5 text-muted-foreground text-xs",children:t("Required before Assistant approval can be selected. Does not fall back to the chat model.")})]}),h.length>0&&e.jsx("div",{className:"w-full min-w-0",children:e.jsx(ze,{providers:h,providerId:l?.id??"",modelId:f?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:t("No assistant approval model selected"),side:"bottom",triggerClassName:Ye,onSelect:(c,p)=>n({providerId:c,modelId:p}),onReasoningChange:()=>{},onThinkingChange:()=>{}})}),l&&xn(l)&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:t(a?"Auto-managed: runs only when the decision model is highly confident it is safe. Everything else is denied and the agent tries another way. Protected actions still ask you.":"Decision models only allow or block when highly confident. Everything else asks you.")}),e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("span",{className:"text-sm",children:t("Auto-manage approvals")}),e.jsx(le,{"aria-label":t("Auto-manage approvals"),checked:a,onCheckedChange:r})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("span",{className:"text-sm",children:t("Auto-allow threshold")}),e.jsxs(ae,{items:d,value:String(o),onValueChange:c=>i(Number(c)),children:[e.jsx(re,{className:"w-36","aria-label":t("Auto-allow threshold"),children:e.jsx(oe,{})}),e.jsx(ie,{children:id.map(c=>e.jsx(ee,{value:String(c),children:d[String(c)]},c))})]})]}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Only runs automatically when the allow probability reaches this value. Operations near the threshold may be allowed one time and not the next.")})]}),s&&(!l||!f)&&e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Selected model is unavailable")}),s&&e.jsx(S,{variant:"ghost",size:"sm",className:"self-start",onClick:()=>n(null),children:t("Clear")})]})}function Fr(t,s){const n=s.find(r=>r.id===t.providerId),a=n?.models.find(r=>r.id===t.modelId);return`${n?.name??t.providerId} / ${a?.label??t.modelId}`}function nf(){const{t}=z(),s=$t(),n=v(A=>A.virtualModels),a=v(A=>A.defaultModel),r=v(A=>A.setDefaultModel),o=v(A=>A.defaultModelFollowLast),i=v(A=>A.setDefaultModelFollowLast),d=v(A=>A.defaultReasoningEnabled),u=v(A=>A.defaultThinkingLevel),x=v(A=>A.setDefaultReasoningEnabled),h=v(A=>A.setDefaultThinkingLevel),l=as(A=>A.snapshot),f=ld(A=>A.latest),c=Xe(),p=a?c.find(A=>A.id===a.providerId):void 0,g=p?.models.find(A=>A.id===a?.modelId),w=s.some(A=>!!A.oauthAccountKey),k=w&&(l.availability.status==="unloaded"||l.availability.status==="loading"),j=w&&l.availability.status==="error"?l.availability.error:null,y=f?.notice,N=y?t("Default model changed: {{previous}} → {{next}}",{previous:Fr(y.previous,s),next:y.next?Fr(y.next,s):t("No default model")}):null;return e.jsxs("section",{className:"space-y-2 rounded-lg border bg-card p-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h4",{className:"font-medium text-sm",children:t("Default model")}),e.jsx("p",{className:"mt-0.5 text-muted-foreground text-xs",children:t(o?"New conversations use the last model you picked.":"Used for new conversations.")})]}),c.length>0&&e.jsx("div",{className:"w-full min-w-0",children:e.jsx(ze,{providers:c,virtualModels:n,providerId:p?.id??a?.providerId??"",modelId:g?.id??a?.modelId??"",reasoningEnabled:d,thinkingLevel:u,emptyLabel:t("Select model"),triggerLabel:o?t("Follow last selection"):void 0,side:"bottom",triggerClassName:Ye,onSelect:(A,O)=>r({providerId:A,modelId:O}),onReasoningChange:x,onThinkingChange:h,showReasoningControls:!o})}),!o&&c.length>0&&e.jsx(S,{type:"button",variant:"ghost",size:"sm",className:"self-start",onClick:()=>i(!0),children:t("Follow last selection")}),c.length===0&&e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-5 text-center",children:[e.jsx(Kn,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-2 font-medium text-sm",children:t("No usable models")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:t("Enable a model and configure valid provider credentials first.")})]}),(k||j)&&e.jsxs("div",{className:"flex items-start gap-2 rounded-md bg-muted px-2.5 py-2 text-xs",children:[e.jsx(At,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:j?t("Subscription credentials could not be loaded: {{error}}",{error:j}):t("Subscription credentials are loading. API-key models remain available.")})]}),N&&e.jsx("p",{className:"rounded-md bg-muted px-2.5 py-2 text-muted-foreground text-xs",children:N})]})}function af(){const{t}=z(),s=Qu($t()),n=v(o=>o.imageGenerationModel),a=n===null||s.some(o=>o.id===n.providerId&&o.models.some(i=>i.id===n.modelId)),r=v(o=>o.setImageGenerationModel);return e.jsxs("section",{className:"space-y-2 rounded-lg border bg-card p-3",children:[e.jsx("h4",{className:"font-medium text-sm",children:t("Default image generation model")}),s.length>0?e.jsx(ze,{providers:s,providerId:n?.providerId??"",modelId:n?.modelId??"",reasoningEnabled:!1,thinkingLevel:"medium",emptyLabel:t("Select model"),side:"bottom",triggerClassName:Ye,onSelect:(o,i)=>r({providerId:o,modelId:i}),onReasoningChange:()=>{},onThinkingChange:()=>{},showReasoningControls:!1}):e.jsx("p",{className:"text-muted-foreground text-xs",children:t("No image generation models available")}),!a&&e.jsx("p",{className:"text-destructive text-xs",children:t("Selected image generation model is unavailable")}),n&&e.jsx(S,{type:"button",variant:"ghost",size:"sm",onClick:()=>r(null),children:t("Clear selection")})]})}function rf({provider:t,onClose:s}){const{t:n}=z(),a=v(g=>g.providers),r=v(g=>g.updateProvider),o=$o(g=>g.snapshot),i=m.useMemo(()=>Vo([t],o)[0]?.models??t.models,[t,o]),d=as(g=>g.snapshot.availability),u=as(g=>g.snapshot.revision),[x,h]=m.useState([]),[l,f]=m.useState(t.oauthAccountPool?.accountKeys??[]);m.useEffect(()=>{let g=!1;return window.electronAPI.providers.listOauth().then(w=>{g||h(w)}).catch(w=>{g||(h([]),console.error("Failed to load OAuth account metadata",w))}),()=>{g=!0}},[u]);const c=Wo(a),p=[...c.flatMap(g=>g.oauthAccountKey??[]),...l.filter(g=>!c.some(w=>w.oauthAccountKey===g))];return e.jsx(Ko,{initialValue:{...t,name:qn(t,n),models:i},oauth:!0,hideName:!0,saveDisabled:l.length===0,oauthAccountKey:t.oauthAccountKey,onCancel:s,extraFields:e.jsxs(me,{children:[e.jsx(he,{children:n("Pool members")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n("Use enabled, signed-in accounts in the listed order. Model and reasoning stay unchanged. Main agents and subagents share this pool.")}),e.jsx("div",{className:"mt-2 w-full space-y-1 rounded-md border p-1",children:p.map((g,w)=>{const k=c.find(y=>y.oauthAccountKey===g),j=x.flatMap(y=>y.accounts).find(y=>y.key===g);return e.jsxs("label",{className:"flex min-w-0 items-center gap-2 px-2 py-1.5 text-sm",children:[e.jsx(Qe,{checked:l.includes(g),onCheckedChange:y=>f(N=>y?[...N,g]:N.filter(A=>A!==g))}),e.jsxs("span",{className:"shrink-0 text-xs text-muted-foreground",children:[w+1,"."]}),e.jsx("span",{className:"min-w-0 truncate",children:j?.email??g}),!k?.enabled&&e.jsx("span",{className:"shrink-0 text-xs text-muted-foreground",children:n("Account disabled")}),d.status==="ready"&&!d.authenticatedAccountKeys.has(g)&&e.jsx("span",{className:"shrink-0 text-xs text-muted-foreground",children:n("Account signed out")})]},g)})})]}),onSave:g=>{l.length!==0&&(r(t.id,{models:qo(g.models,Ho(o,t.oauthAccountKey??"")?.models,Go(v.getState(),t.id)),oauthAccountPool:{accountKeys:p.filter(w=>l.includes(w))}}),s())}})}function of({provider:t,onClose:s}){const{t:n}=z(),a=v(i=>i.updateProvider),r=$o(i=>i.snapshot),o=m.useMemo(()=>t?.oauthAccountKey?Vo([t],r)[0]?.models??t.models:t?.models,[t,r]);return e.jsx(pe,{open:t!==null,onOpenChange:i=>!i&&s(),children:e.jsxs(fe,{children:[e.jsx(ge,{children:e.jsx(je,{children:t?.oauthAccountPool?qn(t,n):n("Edit Provider")})}),t?.oauthAccountPool?e.jsx(rf,{provider:t,onClose:s},t.id):t&&e.jsx(Ko,{initialValue:{name:t.name,api:t.api,apiKey:t.apiKey,baseUrl:t.baseUrl,models:o??t.models,headers:t.headers},oauth:!!t.oauthAccountKey,oauthAccountKey:t.oauthAccountKey,onCancel:s,onSave:i=>{a(t.id,t.oauthAccountKey?{name:i.name,models:qo(i.models,Ho(r,t.oauthAccountKey)?.models,Go(v.getState(),t.id))}:i),s()}},t.id)]})})}const lf=(t,s)=>t.models.some(n=>n.id===s&&n.enabled!==!1),Ur=()=>{};function $r(t){return t==="on"||t==="off"}function tn(t){return typeof t=="string"&&hd.includes(t)}function cf(){const{t}=z(),s=v(l=>l.subagentModelsEnabled),n=v(l=>l.subagentModels),a=v(l=>l.setSubagentModelsEnabled),r=v(l=>l.addSubagentModel),o=v(l=>l.updateSubagentModel),i=v(l=>l.removeSubagentModel),d=v(l=>l.defaultModel),u=v(l=>l.virtualModels),x=Xe(),h=m.useMemo(()=>{if(d&&cd(d)){const l=dd(u,x).find(f=>f.id===d.modelId);if(l)return{providerId:ud,modelId:l.id}}if(d){const l=x.find(f=>f.id===d.providerId);if(l&&lf(l,d.modelId))return d}for(const l of x){const f=l.models.find(c=>c.enabled!==!1);if(f)return{providerId:l.id,modelId:f.id}}return null},[x,d,u]);return e.jsxs("section",{"data-slot":"subagent-models",className:"space-y-2 rounded-lg border bg-card p-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h4",{className:"font-medium text-sm",children:t("Let the agent pick subagent models")}),e.jsx("p",{className:"mt-0.5 text-muted-foreground text-xs",children:t("The main agent can pick one of these models when dispatching subagents or coworkers. The description tells it when to use each model.")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:t("Applies to newly started conversations.")})]}),e.jsx(le,{className:"shrink-0",checked:s,onCheckedChange:a})]}),s&&e.jsxs("div",{className:"space-y-1.5",children:[n.map(l=>e.jsxs("div",{"data-slot":"subagent-model-row",className:G("flex items-center gap-2 rounded-md border px-2 py-1.5",l.enabled===!1&&"bg-muted/50 text-muted-foreground"),children:[e.jsx(le,{"data-slot":"subagent-model-enabled","aria-label":t("Enable subagent model"),title:t("Make this model available to subagents"),checked:l.enabled!==!1,onCheckedChange:f=>o(l.id,{enabled:f})}),l.enabled===!1&&e.jsx(te,{variant:"outline",className:"shrink-0 text-[10px] text-muted-foreground",children:t("Disabled")}),e.jsx("div",{className:"shrink-0 rounded-md border bg-background",children:e.jsx(ze,{providers:x,virtualModels:u,providerId:l.providerId,modelId:l.modelId,modelCapabilityOverrides:md(l),reasoningMode:$r(l.reasoning)?l.reasoning:"follow",reasoningEnabled:l.reasoning==="on",thinkingLevel:tn(l.thinkingLevel)?l.thinkingLevel:"medium",onReasoningModeChange:(f,c)=>{f==="follow"?o(l.id,{reasoning:void 0,thinkingLevel:void 0}):f==="on"&&!tn(l.thinkingLevel)?o(l.id,{reasoning:"on",thinkingLevel:c}):o(l.id,{reasoning:f})},onSelect:(f,c)=>o(l.id,{providerId:f,modelId:c}),onReasoningChange:f=>o(l.id,{reasoning:f?"on":"off"}),onThinkingChange:f=>o(l.id,{thinkingLevel:f}),onReasoningNormalize:$r(l.reasoning)?f=>o(l.id,{reasoning:f?"on":"off"}):Ur,onThinkingNormalize:tn(l.thinkingLevel)?f=>o(l.id,{thinkingLevel:f}):Ur})}),e.jsx(J,{value:l.description,placeholder:t("When to use it, e.g. cheap and fast for simple subtasks"),className:"h-7 flex-1 text-xs",onChange:f=>o(l.id,{description:f.target.value})}),e.jsx(S,{type:"button",variant:"ghost",size:"icon",className:"h-6 w-6 shrink-0 text-muted-foreground hover:text-destructive",onClick:()=>i(l.id),children:e.jsx(Me,{className:"h-3.5 w-3.5"})})]},l.id)),e.jsxs(S,{type:"button",variant:"outline",size:"sm",className:"h-7 text-xs",disabled:!h,onClick:()=>{h&&r({...h,description:""})},children:[e.jsx(Oe,{className:"mr-1 h-3.5 w-3.5"}),t("Add model")]}),!h&&e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Enable a model and configure valid provider credentials first.")})]})]})}function df(){const{t}=z(),s=v(u=>u.titleSummaryEnabled),n=v(u=>u.setTitleSummaryEnabled),a=v(u=>u.titleSummaryModel),r=v(u=>u.setTitleSummaryModel),o=Xe(),i=a?o.find(u=>u.id===a.providerId):void 0,d=i?.models.find(u=>u.id===a?.modelId);return e.jsxs("section",{className:"space-y-2 rounded-lg border bg-card p-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h4",{className:"font-medium text-sm",children:t("Conversation title summary")}),e.jsx("p",{className:"mt-0.5 text-muted-foreground text-xs",children:t("Generate a short AI title from the first message of a new conversation.")})]}),e.jsx(le,{checked:s,onCheckedChange:n})]}),s&&e.jsxs("div",{className:"space-y-2",children:[o.length>0&&e.jsx("div",{className:"w-full min-w-0",children:e.jsx(ze,{providers:o,providerId:i?.id??"",modelId:d?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:t("Follows the default model"),side:"bottom",triggerClassName:Ye,onSelect:(u,x)=>r({providerId:u,modelId:x}),onReasoningChange:()=>{},onThinkingChange:()=>{}})}),a&&(!i||!d)&&e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Selected model is unavailable — falls back to the default model.")}),a&&e.jsx(S,{variant:"ghost",size:"sm",className:"self-start",onClick:()=>r(null),children:t("Follow default model")})]})]})}function uf({accountKey:t}){const s=Cd(t);return!s||s.error?null:e.jsx(Sd,{info:s})}function mf(){const{t}=z(),s=v(D=>D.providers),n=$t(),a=v(D=>D.updateProvider),r=v(D=>D.addProviders),o=v(D=>D.removeProvider),[i,d]=m.useState(!1),[u,x]=m.useState(!1),[h,l]=m.useState(null),[f,c]=m.useState(null),[p,g]=m.useState(null),[w,k]=m.useState(null),[j,y]=m.useState(!1),[N,A]=m.useState(!1),[O,I]=m.useState(null),L=as(D=>D.snapshot.revision),[C,E]=m.useState([]);m.useEffect(()=>{let D=!1;return window.electronAPI.providers.listOauth().then($=>{D||E($)}),()=>{D=!0}},[L]);const M=m.useMemo(()=>xd(s,C),[s,C]),V=m.useMemo(()=>{const D=new Map;for(const $ of n)D.set($.id,$.models.length);return D},[n]),F=async(D,$)=>{if(g(D.id),k(null),D.oauthAccountKey&&!D.oauthAccountPool&&!$?.skipLogout)try{await window.electronAPI.providers.oauthLogout(D.oauthAccountKey),await Id()}catch(Y){g(null),k({providerId:D.id,message:Y instanceof Error?Y.message:String(Y)});return}o(D.id),g(null),k(null)},b=()=>{const D=f;D&&F(D)},_=async()=>{y(!0),I(null);try{const D=await Nd(s);kd(D,a),I(D);const $=Object.values(D).filter(H=>H.status==="failed"),Y=Object.keys(D).length-$.length;Re({type:$.length>0?"warning":"success",title:t("Fetched {{count}} providers",{count:Y}),...$.length>0?{description:t("{{count}} failed",{count:$.length})}:{}})}finally{y(!1)}},K=async()=>{A(!0);try{const D=await window.electronAPI.providers.refreshModelCatalog();wd(),Re({type:D.ok?"success":"warning",title:D.ok?t("Model info updated"):D.fromCache?t("Model info refresh failed, using cache"):t("Model info refresh failed")})}catch{Re({type:"error",title:t("Model info refresh failed")})}finally{A(!1)}};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-wrap items-end justify-between gap-x-4 gap-y-3","data-settings-row":"providers.root",children:[e.jsxs("div",{className:"min-w-0 flex-1 basis-56",children:[e.jsxs("h3",{className:"text-lg font-medium",children:[t("Model Providers"),e.jsx(qe,{note:t("Newly enabled models can be picked right away. After changing a key or address, an open session uses it once you switch its model or start a new session.")})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("Manage model API providers for this app")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(S,{variant:"outline",size:"sm",disabled:N,onClick:()=>{K()},children:[N?e.jsx(Ae,{className:"mr-1.5 h-4 w-4 animate-spin"}):e.jsx(Je,{className:"mr-1.5 h-4 w-4"}),t("Refresh model info")]}),e.jsxs(S,{variant:"outline",size:"sm",disabled:j||s.length===0,onClick:()=>{_()},children:[j?e.jsx(Ae,{className:"mr-1.5 h-4 w-4 animate-spin"}):e.jsx(Je,{className:"mr-1.5 h-4 w-4"}),t("Fetch all models")]}),e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>d(!0),children:[e.jsx(cs,{className:"h-4 w-4 mr-1.5"}),t("Import from local apps")]}),e.jsxs(S,{size:"sm",onClick:()=>x(!0),children:[e.jsx(Oe,{className:"h-4 w-4 mr-1.5"}),t("Add model or provider")]})]})]}),e.jsx(nf,{}),e.jsx(af,{}),e.jsx(ch,{}),e.jsx(df,{}),e.jsx(sf,{}),e.jsx(cf,{}),Wo(s).length>0&&!s.some(D=>D.oauthAccountPool)&&e.jsxs("div",{className:"space-y-1.5 rounded-md border p-3",children:[e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>{const D=pd(s,crypto.randomUUID());D&&r([D])>0&&l(D)},children:[e.jsx(Oe,{className:"mr-1.5 h-3.5 w-3.5"}),t("Create ChatGPT account pool")]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Pool entries do not show a single account quota. Fixed-account entries remain unchanged.")})]}),s.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx(Kn,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 text-sm font-medium",children:t("No providers yet")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:t("Import providers from local apps or use the unified setup to get started")})]}):e.jsx("div",{className:"space-y-1",children:M.map(D=>{const $=C.find(H=>H.id===D.vendorId),Y=D.vendorId===fd?t("Custom"):D.label;return e.jsxs("div",{className:"rounded-md px-3 py-2",children:[e.jsxs("div",{className:"flex items-baseline gap-1.5",children:[e.jsx("span",{className:"text-[11px] font-semibold tracking-wide text-muted-foreground",children:Y}),e.jsx("span",{className:"text-[11px] text-muted-foreground/60",children:D.providers.length})]}),e.jsx("div",{className:"mt-1.5 space-y-1 border-l pl-3",children:D.providers.map(H=>{const se=!!H.oauthAccountKey,q=V.get(H.id)??H.models.length,Q=H.oauthAccountKey&&!H.oauthAccountPool?$?.accounts.find(R=>R.key===H.oauthAccountKey):void 0,B=H.oauthAccountPool?qn(H,t):se?Q?.email??H.oauthAccountKey??H.name:H.name,ne=O?.[H.id];return e.jsxs(m.Fragment,{children:[e.jsxs("div",{className:"group flex items-start justify-between gap-3 rounded-md px-3 py-2 transition-colors hover:bg-accent/50","data-settings-row":`providers.${H.id}`,children:[e.jsxs("div",{className:"min-w-0 flex-1 overflow-hidden",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[se?e.jsx(gd,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}):e.jsx(jd,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx("span",{className:G("truncate text-sm font-medium",!H.enabled&&"text-muted-foreground line-through"),children:B}),se?Q?.plan&&e.jsx(te,{variant:"outline",className:"shrink-0 text-[10px] uppercase",children:Q.plan}):e.jsx(te,{variant:"outline",className:"shrink-0 text-[11px]",children:vd[H.api]??H.api}),H.importedFrom&&e.jsx(te,{variant:"secondary",className:"shrink-0 text-[11px]",children:H.importedFrom}),e.jsx("span",{className:"min-w-0 truncate text-xs text-muted-foreground",children:[se?void 0:H.baseUrl,H.oauthAccountPool?t("{{count}} accounts",{count:H.oauthAccountPool.accountKeys.length}):void 0,q>0?t("{{count}} models",{count:q}):void 0].filter(Boolean).join(" · ")})]}),xn(H)&&e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:t("Classification only, not for chat")}),H.oauthAccountKey&&!H.oauthAccountPool&&e.jsx(uf,{accountKey:H.oauthAccountKey})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1 pt-0.5",children:[e.jsx(S,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",onClick:()=>l(H),children:e.jsx(lt,{className:"h-3.5 w-3.5"})}),e.jsx(S,{variant:"ghost",size:"icon",disabled:p===H.id,className:G("h-7 w-7 text-muted-foreground opacity-0 transition-opacity hover:text-destructive group-hover:opacity-100",p===H.id&&"opacity-100"),onClick:()=>c(H),children:p===H.id?e.jsx(Ae,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Me,{className:"h-3.5 w-3.5"})}),e.jsx(le,{checked:H.enabled,onCheckedChange:R=>a(H.id,{enabled:R})})]})]}),w?.providerId===H.id&&e.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-md border border-destructive/30 bg-destructive/5 px-3 py-1.5 text-xs text-destructive",children:[e.jsx("span",{className:"min-w-0 truncate",children:t("Sign-out failed: {{message}}",{message:w.message})}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(S,{variant:"outline",size:"sm",className:"h-6 px-2 text-[11px]",onClick:()=>{F(H)},children:t("Retry")}),e.jsx(S,{variant:"ghost",size:"sm",className:"h-6 px-2 text-[11px] text-destructive hover:text-destructive",onClick:()=>{F(H,{skipLogout:!0})},children:t("Delete anyway")})]})]}),ne?.status==="failed"&&e.jsx("div",{className:"flex items-center justify-between gap-2 rounded-md border border-destructive/30 bg-destructive/5 px-3 py-1.5 text-xs text-destructive",children:e.jsxs("span",{className:"min-w-0 truncate",children:[t("Fetch failed"),": ",ne.message]})})]},H.id)})})]},D.vendorId)})}),e.jsx(bd,{open:i,onOpenChange:d}),e.jsx(yd,{open:u,onOpenChange:x}),e.jsx(of,{provider:h,onClose:()=>l(null)}),e.jsx(fo,{open:f!==null,onOpenChange:D=>{D||c(null)},title:t("Remove provider?"),description:f?f.oauthAccountKey&&!f.oauthAccountPool?t("Removing this also signs out {{name}}. Other accounts for the same vendor stay signed in.",{name:f.name}):t('This permanently deletes the "{{name}}" provider configuration.',{name:f.name}):void 0,confirmLabel:t("Remove"),onConfirm:b})]})}const hf=2e3,Vr=50,Rt="",xf=[{id:"app",label:"App processes"},{id:"agent",label:"Agent and tools"},{id:"child",label:"Other child processes"}],wn={sessions:["Conversation history","Conversation transcripts and usage ledger."],coworkers:["Coworker transcripts","Coworker journals; only those of deleted conversations are cleaned."],toolOutputs:["Tool outputs","Saved long tool outputs; only those of deleted conversations are cleaned."],memory:["Memory","Memory database and working memory."],models:["Local models","Downloaded embedding, chat and speech models."],runtimes:["Runtimes","Bundled tools, speech runtime and GPU backends."],worktrees:["Worktrees","Isolated worktrees created for conversations."],snapshots:["Change snapshots","Baselines for the Changes panel."],browser:["Browser data","Cookies, storage and cache of the built-in browser."],cache:["Cache","Rebuildable caches; cleaning is safe."],logs:["Logs","Task and memory logs; files written in the last 24 hours are kept."],backups:["Backups","Configuration backup files; files from the last 24 hours are kept."],config:["Configuration","Settings, instructions, prompts and credentials."],other:["Other","Chromium profile data and other files."]};function pf(t,s){switch(t){case"main":return s("Main process");case"window":return s("Window");case"browser":return s("Built-in browser");case"gpu":return"GPU";case"service":return s("Service");case"agent":return"Agent";case"tool":return s("Tool");default:return s("Child process")}}function ff(t,s){return t.id==="data"?s("App data"):s("Worktree directory")}function gf(t,s){return t.role!=="window"?t.name:t.name==="Main window"?s("Main window"):t.name==="Settings"?s("Settings"):t.name}function jf(t){return`${t.toFixed(1)}%`}function vf(){const{t}=z(),[s,n]=m.useState("cpu");return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:t("Resources")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("CPU, memory and disk usage of EnsoCode and the processes it started.")})]}),e.jsxs(Ft,{value:s,onValueChange:a=>n(a),children:[e.jsxs(Ut,{children:[e.jsx(Ke,{value:"cpu",children:"CPU"}),e.jsx(Ke,{value:"memory",children:t("RAM")}),e.jsx(Ke,{value:"storage",children:t("Storage")})]}),e.jsx(Dt,{value:"cpu",className:"pt-4",children:s==="cpu"&&e.jsx(Kr,{metric:"cpu"})}),e.jsx(Dt,{value:"memory",className:"pt-4",children:s==="memory"&&e.jsx(Kr,{metric:"memory"})}),e.jsx(Dt,{value:"storage",className:"pt-4",children:s==="storage"&&e.jsx(yf,{})})]})]})}function Kr({metric:t}){const{t:s}=z(),[n,a]=m.useState(null),[r,o]=m.useState(null);if(m.useEffect(()=>{let x=!1,h;const l=async()=>{try{const f=await window.electronAPI.resources.sample();if(x)return;a(f),o(null)}catch(f){x||o(f instanceof Error?f.message:String(f))}x||(h=setTimeout(l,hf))};return l(),()=>{x=!0,clearTimeout(h)}},[]),r&&!n)return e.jsx("p",{className:"text-sm text-destructive",children:r});if(!n)return e.jsx("p",{className:"text-sm text-muted-foreground",children:s("Loading...")});const i=t==="cpu"?jf:de,d=t==="cpu"?{app:n.cpu.app,system:n.cpu.system,total:100}:n.memory,u=x=>t==="cpu"?x.cpu:x.memory;return e.jsxs("div",{className:"space-y-4",children:[e.jsx(Li,{app:d.app,system:Math.max(d.system,d.app),total:d.total,format:i}),xf.map(x=>{const h=n.processes.filter(l=>l.group===x.id).sort((l,f)=>u(f)-u(l));return h.length===0?null:e.jsxs("div",{className:"rounded-lg border",children:[e.jsxs("div",{className:"flex items-center justify-between border-b px-3 py-2 text-sm font-medium",children:[e.jsx("span",{children:s(x.label)}),e.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:i(h.reduce((l,f)=>l+u(f),0))})]}),e.jsx("div",{className:"divide-y",children:h.map(l=>e.jsxs("div",{className:"flex items-center gap-3 px-3 py-1.5 text-sm",children:[e.jsx("span",{className:"w-20 shrink-0 truncate text-xs text-muted-foreground",children:pf(l.role,s)}),e.jsx("span",{className:"min-w-0 flex-1 truncate",title:l.command??l.name,children:gf(l,s)}),e.jsx("span",{className:"w-16 text-right font-mono text-xs text-muted-foreground",children:l.pid}),e.jsx("span",{className:"w-20 text-right font-mono text-xs",children:i(u(l))})]},l.pid))})]},x.id)})]})}function Li({app:t,system:s,total:n,format:a}){const{t:r}=z(),o=i=>`${n>0?Math.min(100,i/n*100):0}%`;return e.jsxs("div",{className:"space-y-3 rounded-lg border p-4",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"EnsoCode"}),e.jsx("div",{className:"font-mono text-2xl font-semibold",children:a(t)})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:r("System")}),e.jsxs("div",{className:"font-mono text-sm",children:[a(s)," / ",a(n)]})]})]}),e.jsxs("div",{className:"relative h-2 overflow-hidden rounded-full bg-muted",children:[e.jsx("div",{className:"absolute inset-y-0 left-0 bg-foreground/25",style:{width:o(s)}}),e.jsx("div",{className:"absolute inset-y-0 left-0 bg-foreground",style:{width:o(t)}})]})]})}function bf(t,s){const n=[s("Freed {{size}}",{size:de(t.freedBytes)})];return t.removed>0&&n.push(s("{{count}} files removed",{count:t.removed})),t.skipped>0&&n.push(s("{{count}} kept",{count:t.skipped})),t.failed>0&&n.push(s("{{count}} failed",{count:t.failed})),n.join(" · ")}function yf(){const{t}=z(),[s,n]=m.useState(null),[a,r]=m.useState("scan"),[o,i]=m.useState(null),[d,u]=m.useState(null),[x,h]=m.useState(null),[l,f]=m.useState(null),c=m.useCallback(async(j,y)=>{r(j),u(null),i(null);try{n(await y())}catch(N){const A=N instanceof Error?N.message:String(N);A.includes("Scan cancelled")||u(A)}finally{r(null),i(null)}},[]),p=m.useCallback(()=>c("scan",()=>window.electronAPI.resources.scanStorage()),[c]),g=j=>c(j,async()=>{const y=await window.electronAPI.resources.cleanStorage(j);return Re({type:y.failed>0?"warning":"success",title:t("{{name}} cleaned",{name:t(wn[j][0])}),description:bf(y,t)}),y.snapshot});m.useEffect(()=>{const j=window.electronAPI.resources.onScanProgress(i);return window.electronAPI.resources.lastStorage().then(y=>{y&&n(N=>N??y)}),p(),()=>{j(),window.electronAPI.resources.cancelScan()}},[p]);const w=s?[...s.categories].filter(j=>j.bytes>0).sort((j,y)=>y.bytes-j.bytes):[],k=m.useMemo(()=>{const j=new Map;for(const y of s?.roots??[])j.set(y.volumeId,[...j.get(y.volumeId)??[],y]);return[...j.values()]},[s]);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("p",{className:"min-w-0 truncate text-xs text-muted-foreground",children:a==="scan"?o?t("Scanning {{count}} files · {{size}}",{count:o.files.toLocaleString(),size:de(o.bytes)}):t("Scanning..."):s?t("Scanned at {{time}} · took {{seconds}}s",{time:new Date(s.scannedAt).toLocaleTimeString(),seconds:(s.durationMs/1e3).toFixed(1)}):null}),a==="scan"?e.jsx(S,{variant:"ghost",size:"sm",onClick:()=>{window.electronAPI.resources.cancelScan()},children:t("Cancel")}):e.jsx(S,{variant:"ghost",size:"icon-sm",onClick:()=>{p()},disabled:a!==null,"aria-label":t("Refresh"),children:e.jsx(Je,{})})]}),d&&e.jsx("p",{className:"text-sm text-destructive",children:d}),s&&s.errorCount>0&&e.jsxs("p",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",title:s.errors.join(`
28
- `),children:[e.jsx(Ue,{className:"h-3.5 w-3.5"}),t("{{count}} paths could not be read and are not counted.",{count:s.errorCount})]}),s&&e.jsxs(e.Fragment,{children:[k.map(j=>{const y=j[0]?.volume,N=j.reduce((A,O)=>A+O.bytes,0);return e.jsxs("div",{className:"space-y-2",children:[y?e.jsx(Li,{app:N,system:y.total-y.free,total:y.total,format:de}):e.jsx("div",{className:"rounded-lg border p-4 font-mono text-2xl font-semibold",children:de(N)}),j.map(A=>e.jsxs("div",{className:"flex items-center gap-2 px-1 text-xs",children:[e.jsx("span",{className:"shrink-0 text-muted-foreground",children:ff(A,t)}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono",title:A.path,children:A.path}),e.jsx("span",{className:"font-mono",children:de(A.bytes)})]},A.id))]},j[0]?.volumeId)}),e.jsx("div",{className:"divide-y rounded-lg border",children:w.map(j=>e.jsx(wf,{category:j,share:s.totalBytes>0?j.bytes/s.totalBytes:0,expanded:x===j.id,onToggle:()=>h(x===j.id?null:j.id),cleaning:a===j.id,disabled:a!==null,onClean:()=>Yo[j.id]==="confirm"?f(j.id):void g(j.id)},j.id))}),e.jsx(Nf,{sessions:s.sessions,busy:a==="sessions",disabled:a!==null,onClean:j=>c("sessions",async()=>{const y=await window.electronAPI.resources.cleanSessions(j);return Re({type:"success",title:t("{{count}} conversations deleted",{count:y.removed})}),y.snapshot})})]}),e.jsx(An,{open:l!==null,onOpenChange:j=>!j&&f(null),children:e.jsxs(En,{className:"sm:max-w-md",zIndexLevel:"nested",children:[e.jsxs(Mn,{children:[e.jsx(Pn,{className:"text-base",children:t("Clean {{name}}?",{name:l?t(wn[l][0]):""})}),e.jsx(Tn,{children:t(l==="browser"?"You will be signed out of sites opened in the built-in browser.":"Deleted files cannot be restored.")})]}),e.jsxs(Rn,{variant:"bare",children:[e.jsx(On,{render:e.jsx(S,{variant:"outline",size:"sm"}),children:t("Cancel")}),e.jsx(S,{variant:"destructive",size:"sm",onClick:()=>{const j=l;f(null),j&&g(j)},children:t("Clean")})]})]})})]})}function wf({category:t,share:s,expanded:n,onToggle:a,cleaning:r,disabled:o,onClean:i}){const{t:d}=z(),[u,x]=wn[t.id];return e.jsxs("div",{className:"px-3 py-2",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{type:"button",onClick:a,className:"flex min-w-0 flex-1 items-center gap-2 text-left",children:[e.jsx(Mt,{className:G("h-4 w-4 shrink-0 transition-transform",n&&"rotate-90")}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-2 text-sm",children:[e.jsx("span",{className:"font-medium",children:d(u)}),e.jsx("span",{className:"font-mono text-xs",children:de(t.bytes)})]}),e.jsx("p",{className:"truncate text-xs text-muted-foreground",children:d(x)}),e.jsx("div",{className:"mt-1 h-1 overflow-hidden rounded-full bg-muted",children:e.jsx("div",{className:"h-full bg-foreground/60",style:{width:`${s*100}%`}})})]})]}),Yo[t.id]!=="none"&&e.jsx(S,{variant:"outline",size:"sm",disabled:o,onClick:i,children:d(r?"Cleaning...":"Clean")})]}),n&&e.jsx("div",{className:"mt-2 space-y-0.5 pl-6",children:t.entries.map(h=>e.jsxs("div",{className:"group flex items-center gap-2 text-xs",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-muted-foreground",children:h.root==="data"?h.path:`${d("Worktree directory")}/${h.path}`}),e.jsx("span",{className:"font-mono",children:de(h.bytes)}),e.jsx(S,{variant:"ghost",size:"icon-sm",className:"opacity-0 group-hover:opacity-100","aria-label":d("Show in folder"),onClick:()=>{window.electronAPI.resources.revealStorage(h.root,h.path)},children:e.jsx(Bn,{})})]},`${h.root}:${h.path}`))})]})}function Nf({sessions:t,busy:s,disabled:n,onClean:a}){const{t:r}=z(),[o,i]=m.useState(!1),[d,u]=m.useState(!1),[x,h]=m.useState(null),[l,f]=m.useState(Rt),c=m.useMemo(()=>new Map(t.map(C=>[C.id,C])),[t]),p=m.useMemo(()=>{const C=new Map;for(const E of t){const M=C.get(E.projectId)??{name:E.projectName,bytes:0,count:0};M.bytes+=E.bytes,M.count+=1,C.set(E.projectId,M)}return[...C].sort((E,M)=>M[1].bytes-E[1].bytes)},[t]),g=p.some(([C])=>C===l)?l:Rt,w=g?t.filter(C=>C.projectId===g):t,k=C=>{const E=Td(t,C,Date.now());return{request:C,count:E.length,bytes:E.reduce((M,V)=>M+(c.get(V)?.bytes??0),0)}},j=C=>k({kind:"stale",days:C,includeUnarchived:o,...g?{projectId:g}:{}}),y=w.reduce((C,E)=>C+E.bytes,0),N=d?w:w.slice(0,Vr),A=(C,E)=>E||(C?C.slice(0,8):r("No project")),O=x?.request.kind==="one"?c.get(x.request.id):void 0,I=x?.request.kind==="stale"?x.request.projectId:void 0,L=I===void 0?void 0:A(I,p.find(([C])=>C===I)?.[1].name??"");return e.jsxs("div",{className:"rounded-lg border",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 border-b px-3 py-2",children:[e.jsxs("div",{className:"shrink-0 text-sm font-medium",children:[r("Conversations"),e.jsxs("span",{className:"ml-2 font-mono text-xs text-muted-foreground",children:[w.length," · ",de(y)]})]}),e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsxs(ae,{items:{[Rt]:r("All projects"),...Object.fromEntries(p.map(([C,E])=>[C,A(C,E.name)]))},value:g,onValueChange:C=>f(C??Rt),children:[e.jsx(re,{size:"sm",className:"w-48 min-w-0",children:e.jsx(oe,{})}),e.jsxs(ie,{children:[e.jsx(ee,{value:Rt,children:r("All projects")}),p.map(([C,E])=>e.jsx(ee,{value:C,children:e.jsxs("span",{className:"flex w-full items-center gap-3",children:[e.jsx("span",{className:"flex-1 truncate",children:A(C,E.name)}),e.jsxs("span",{className:"font-mono text-xs text-muted-foreground",children:[E.count," · ",de(E.bytes)]})]})},C))]})]}),e.jsxs(Jo,{children:[e.jsxs(Qo,{render:e.jsx(S,{variant:"outline",size:"sm",disabled:n||w.length===0}),children:[e.jsx(Ad,{}),r(s?"Cleaning...":"Clean")]}),e.jsxs(Xo,{align:"end",className:"min-w-48",children:[e.jsx(Ed,{checked:o,onCheckedChange:i,closeOnClick:!1,children:r("Include unarchived")}),e.jsx(Md,{}),[...Pd,0].map(C=>{const E=j(C);return e.jsxs(Zo,{variant:"destructive",disabled:E.count===0,onClick:()=>h(E),children:[e.jsx("span",{className:"flex-1",children:C>0?r("Older than {{days}} days",{days:C}):r("All")}),e.jsx("span",{className:"font-mono text-xs opacity-70",children:E.count})]},C)})]})]})]})]}),e.jsx("div",{className:"max-h-96 divide-y overflow-y-auto",children:N.map(C=>e.jsxs("div",{className:"group flex items-center gap-3 px-3 py-1.5 text-sm",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate",title:C.title,children:C.title||r("Untitled")}),e.jsx("div",{className:"truncate text-xs text-muted-foreground",children:[C.projectName,C.archived?r("Archived"):null,new Date(C.lastActiveAt).toLocaleDateString()].filter(Boolean).join(" · ")})]}),e.jsx("span",{className:"font-mono text-xs",children:de(C.bytes)}),e.jsx(S,{variant:"ghost",size:"icon-sm",className:"opacity-0 group-hover:opacity-100",disabled:n,"aria-label":r("Delete"),onClick:()=>h({request:{kind:"one",id:C.id},count:1,bytes:C.bytes}),children:e.jsx(Me,{})})]},C.id))}),w.length>Vr&&e.jsx("button",{type:"button",onClick:()=>u(!d),className:"w-full border-t px-3 py-1.5 text-xs text-muted-foreground hover:text-foreground",children:r(d?"Show less":"Show all")}),e.jsx(An,{open:x!==null,onOpenChange:C=>!C&&h(null),children:e.jsxs(En,{className:"sm:max-w-md",zIndexLevel:"nested",children:[e.jsxs(Mn,{children:[e.jsx(Pn,{className:"text-base",children:O?r('Delete "{{title}}"?',{title:O.title||r("Untitled")}):L!==void 0?r("Delete {{count}} conversations in {{project}}?",{count:x?.count??0,project:L}):r("Delete {{count}} conversations?",{count:x?.count??0})}),e.jsxs(Tn,{children:[r("About {{size}} of history, tool output and isolated worktrees will be removed and cannot be restored.",{size:de(x?.bytes??0)}),!O&&` ${r("Open, running and waiting conversations are skipped.")}`]})]}),e.jsxs(Rn,{variant:"bare",children:[e.jsx(On,{render:e.jsx(S,{variant:"outline",size:"sm"}),children:r("Cancel")}),e.jsx(S,{variant:"destructive",size:"sm",onClick:()=>{const C=x?.request;h(null),C&&a(C)},children:r("Delete")})]})]})})]})}function kf(){const{t}=z(),s=v(N=>N.skills),n=v(N=>N.updateSkill),a=v(N=>N.setSkillsEnabled),r=v(N=>N.removeSkill),o=v(N=>N.loadLocalSkills),i=v(N=>N.setLoadLocalSkills),d=v(N=>N.loadHarnessAssets),u=v(N=>N.setLoadHarnessAssets),[x,h]=m.useState(!1),[l,f]=m.useState(""),c=s.filter(N=>Oo(l,[N.name,N.source,N.description,N.path])),p=c.map(N=>N.id),g=Do(p),w=s.filter(N=>N.enabled).length,k=s.map(N=>N.id),j=hs(k,N=>window.electronAPI.assets.skillOccupancy(N)),y=ds(s.filter(N=>N.enabled).map(N=>N.id),j.rows);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 rounded-lg border px-3 py-2.5",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:t("Load local skills")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Let the agent auto-discover skills under .agents/skills and .pi/skills")})]}),e.jsx(le,{checked:o,onCheckedChange:i})]}),e.jsxs("div",{className:"flex items-center justify-between gap-4 rounded-lg border px-3 py-2.5",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:t("Load project harness assets")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Also load skills from .claude/.codex/.cursor and rule files (.cursorrules, .cursor/rules, .claude/rules) in the project")})]}),e.jsx(le,{checked:d,onCheckedChange:u})]}),e.jsxs("div",{className:"flex items-end justify-between gap-4","data-settings-row":"skills.root",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"font-medium text-lg",children:[t("Skills"),e.jsx(qe,{note:t("The / menu updates right away, but open sessions keep the skills they loaded. Start a new session to load the change.")}),s.length>0&&e.jsxs("span",{className:"ml-2 font-normal text-muted-foreground text-xs",children:[t("{{enabled}}/{{total}} enabled",{enabled:w,total:s.length}),e.jsx(ms,{tokens:y})]})]}),e.jsx("p",{className:"text-muted-foreground text-sm",children:t("Skills registered by reference; files stay in their original location")})]}),e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>h(!0),children:[e.jsx(cs,{className:"mr-1.5 h-4 w-4"}),t("Import from local apps")]})]}),s.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx(ei,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:t("No skills yet")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:t("Import skills from Claude Code, Codex or Cursor to get started")})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx(zo,{query:l,onQueryChange:f,placeholder:t("Filter skills..."),allSelected:g.allSelected,someSelected:g.someSelected,onToggleSelectAll:g.toggleAll,onEnable:()=>a(g.selectedIds,!0),onDisable:()=>a(g.selectedIds,!1),selectDisabled:c.length===0,actionDisabled:g.selectedIds.length===0}),c.length===0?e.jsx("p",{className:"px-3 py-6 text-center text-muted-foreground text-xs",children:t("No results")}):e.jsx("div",{className:"space-y-1",children:c.map(N=>e.jsxs("div",{className:"group flex items-center justify-between gap-3 rounded-md px-3 py-2 transition-colors hover:bg-accent/50","data-settings-row":`skills.${N.id}`,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(Qe,{checked:g.isSelected(N.id),onCheckedChange:A=>g.toggleOne(N.id,A)}),e.jsx("span",{className:G("shrink-0 font-medium text-sm",!N.enabled&&"text-muted-foreground line-through"),children:N.name}),e.jsx(te,{variant:"secondary",className:"shrink-0 text-[11px]",children:N.source}),e.jsx("span",{className:"min-w-0 truncate text-muted-foreground text-xs",children:N.description||N.path})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(us,{row:j.rows[N.id],pending:j.pending&&!j.rows[N.id]}),e.jsx(le,{checked:N.enabled,onCheckedChange:A=>n(N.id,{enabled:A})}),e.jsx(S,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity hover:text-destructive group-hover:opacity-100",onClick:()=>r(N.id),children:e.jsx(Me,{className:"h-3.5 w-3.5"})})]})]},N.id))})]}),e.jsx(Vn,{kind:"skill",open:x,onOpenChange:h})]})}const qr=[10,15,30,60,120,300];function Cf(){const{t}=z(),[s,n]=m.useState([]),[a,r]=m.useState(!1),[o,i]=m.useState(null),[d,u]=m.useState(""),[x,h]=m.useState(""),[l,f]=m.useState(""),[c,p]=m.useState(""),[g,w]=m.useState("key"),[k,j]=m.useState(""),[y,N]=m.useState(!1),[A,O]=m.useState(null),[I,L]=m.useState(null),[C,E]=m.useState(null),[M,V]=m.useState(null),[F,b]=m.useState(!1),_=m.useCallback(()=>{window.electronAPI.sshConnections.list().then(n)},[]);m.useEffect(()=>{_()},[_]);const K=()=>{i(null),u(""),h(""),f(""),p(""),w("key"),j(""),L(null),r(!0)},D=q=>{i(q),u(q.name),h(q.host),f(q.user??""),p(q.port?String(q.port):""),w(q.auth),j(""),L(null),r(!0)},$=async q=>{q.preventDefault(),N(!0),L(null);const Q=c.trim()?Number(c):void 0,B=await window.electronAPI.sshConnections.upsert({...o?{id:o.id}:{},name:d.trim(),host:x.trim(),...l.trim()?{user:l.trim()}:{},...Q&&Number.isInteger(Q)?{port:Q}:{},auth:g,...g==="password"&&k?{password:k}:{}});if(N(!1),!B.ok){L(B.error);return}r(!1),_()},Y=async q=>{const Q=await window.electronAPI.sshConnections.delete(q);if(!Q.ok){E(Q.error);return}E(null),_()},H=async(q,Q=!0)=>{O(q),E(null);const B=await window.electronAPI.sshConnections.test(q);if(O(null),!B.ok){const ne=s.find(P=>P.id===q),R=Od(B,ne);if(R&&Q){V({id:q,challenge:R});return}}E(B.ok?t("SSH connection succeeded"):B.error)},se=async()=>{if(!M)return;b(!0);const q=M.id,Q=await window.electronAPI.sshConnections.trustHost(q);if(b(!1),V(null),!Q.ok){E(Q.error||t("Could not save host key."));return}await H(q,!1)};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-end justify-between gap-4","data-settings-row":"ssh.root",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-lg font-medium",children:[t("SSH"),e.jsx(qe,{note:t("The file panel and terminal use the change right away. Agents in open sessions keep the previous connection settings.")})]}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:t("Saved hosts for remote projects. Passwords stay in the system keychain.")})]}),e.jsxs(S,{size:"sm",onClick:K,children:[e.jsx(Oe,{className:"h-4 w-4"}),t("Add connection")]})]}),C&&e.jsx("p",{className:"text-sm text-muted-foreground",children:C}),e.jsxs("ul",{className:"divide-y rounded-lg border",children:[s.length===0&&e.jsx("li",{className:"px-3 py-6 text-sm text-muted-foreground",children:t("No SSH connections yet")}),s.map(q=>e.jsxs("li",{className:"flex items-center gap-2 px-3 py-2","data-settings-row":`ssh.${q.id}`,children:[e.jsxs("button",{type:"button",className:"min-w-0 flex-1 text-left",onClick:()=>D(q),children:[e.jsx("div",{className:"truncate text-sm font-medium",children:q.name}),e.jsxs("div",{className:"truncate text-xs text-muted-foreground",children:[q.user?`${q.user}@`:"",q.host,q.port?`:${q.port}`:""," ·"," ",q.auth==="password"?t("Password"):t("Key / agent")]})]}),e.jsx(S,{size:"sm",variant:"outline",disabled:A===q.id,onClick:()=>{H(q.id)},children:A===q.id?e.jsx(Ae,{className:"h-4 w-4 animate-spin"}):t("Test")}),e.jsx(S,{size:"icon-sm",variant:"ghost",onClick:()=>{Y(q.id)},children:e.jsx(Me,{className:"h-4 w-4"})})]},q.id))]}),e.jsx(Sf,{}),e.jsx(pe,{open:a,onOpenChange:r,children:e.jsx(fe,{className:"max-w-md",children:e.jsxs("form",{onSubmit:q=>{$(q)},className:"flex flex-col",children:[e.jsx(ge,{children:e.jsx(je,{children:t(o?"Edit SSH connection":"Add SSH connection")})}),e.jsxs(we,{className:"space-y-3",children:[e.jsxs(me,{children:[e.jsx(he,{children:t("Name")}),e.jsx(J,{value:d,onChange:q=>u(q.target.value),required:!0})]}),e.jsxs(me,{children:[e.jsx(he,{children:t("Host")}),e.jsx(J,{value:x,onChange:q=>h(q.target.value),placeholder:"example.com",required:!0})]}),e.jsxs(me,{children:[e.jsx(he,{children:t("User (optional)")}),e.jsx(J,{value:l,onChange:q=>f(q.target.value)})]}),e.jsxs(me,{children:[e.jsx(he,{children:t("Port (optional)")}),e.jsx(J,{value:c,onChange:q=>p(q.target.value),placeholder:"22"})]}),e.jsxs(me,{children:[e.jsx(he,{children:t("Authentication")}),e.jsxs(ae,{items:[{value:"key",label:t("Key / agent")},{value:"password",label:t("Password")}],value:g,onValueChange:q=>w(q),children:[e.jsx(re,{className:"w-full",children:e.jsx(oe,{})}),e.jsxs(ie,{zIndex:st.DROPDOWN_IN_MODAL,children:[e.jsx(ee,{value:"key",children:t("Key / agent")}),e.jsx(ee,{value:"password",children:t("Password")})]})]})]}),g==="password"&&e.jsxs(me,{children:[e.jsx(he,{children:o?.hasPassword?t("Password (leave blank to keep)"):t("Password")}),e.jsx(J,{type:"password",value:k,onChange:q=>j(q.target.value),required:!o?.hasPassword})]}),I&&e.jsx("p",{className:"text-sm text-destructive",children:I})]}),e.jsxs(Ie,{children:[e.jsx(S,{type:"button",variant:"outline",size:"sm",onClick:()=>r(!1),children:t("Cancel")}),e.jsx(S,{type:"submit",size:"sm",disabled:y,children:t("Save")})]})]})})}),e.jsx(Rd,{challenge:M?.challenge??null,busy:F,onTrust:()=>{se()},onDismiss:()=>!F&&V(null)})]})}function Sf(){const{t}=z(),s=v(a=>a.sshTimeoutSeconds),n=v(a=>a.setSshTimeoutSeconds);return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"ssh.timeout",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("SSH timeout")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Time limit for connection tests, loading remote AGENTS.md, remote folder browsing and file panel actions. Agent tool commands are not affected.")})]}),e.jsxs(ae,{items:Object.fromEntries(qr.map(a=>[String(a),`${a}s`])),value:String(s),onValueChange:a=>n(Number(a)),children:[e.jsx(re,{className:"w-24",children:e.jsx(oe,{})}),e.jsx(ie,{children:qr.map(a=>e.jsx(ee,{value:String(a),children:`${a}s`},a))})]})]})}const If={memory:"memory",workflows:"workflow"},zi=["bots","botTemplates"],Af=[{id:"app",label:"Application",categories:["general","appearance","shortcuts","voice","privacy"]},{id:"agent",label:"Models & agents",categories:["providers","presets","agents","instructions","memory"]},{id:"extensions",label:"Tools & extensions",categories:["tools","workflows","skills","mcp","plugins","claudePlugins"]},{id:"connections",label:"Connections",categories:["phone","ssh"]},{id:"system",label:"System",categories:["usage","resources","experimental","bots","botTemplates"]}];function Ef(t){const s=new Map(t.map(n=>[n.id,n]));return Af.flatMap(n=>{const a=n.categories.flatMap(r=>{const o=s.get(r);return o?[o]:[]});return a.length>0?[{id:n.id,label:n.label,items:a}]:[]})}function Bi(t,s,n=!1){if(zi.includes(t))return n;const a=If[t];return!a||!s.includes(a)}function Mf(t,s,n=!1){return t.filter(a=>Bi(a.id,s,n))}function Pf(t,s,n=!1){return Bi(t,s,n)?t:zi.includes(t)?"experimental":"tools"}function Tf(t,s,n,a){const r=n.trim();if(!r)return t.map(u=>({...u,hits:[]}));const o=Dd([...s,...t.map(u=>({id:`${u.id}.root`,category:u.id,title:u.label}))],r,{translate:a,limit:Number.POSITIVE_INFINITY}),i=new Set,d=new Map;for(const u of o){if(i.add(u.category),u.id.endsWith(".root"))continue;const x=d.get(u.category);x?x.push(u):d.set(u.category,[u])}return t.flatMap(u=>i.has(u.id)?[{...u,hits:d.get(u.id)??[]}]:[])}const Rf=[1,7,30,90],Gr=640,Qt=180,Hr=8,Wr=18,Of=.3,Df=2;function Lf(t){const[,s,n]=t.split("-");return`${Number(s)}/${Number(n)}`}const zf=[{id:"cache",cls:"fill-foreground/15",swatch:"bg-foreground/15"},{id:"input",cls:"fill-foreground/45",swatch:"bg-foreground/45"},{id:"output",cls:"fill-foreground",swatch:"bg-foreground"}];function Bf({daily:t}){const{t:s}=z(),[n,a]=m.useState("tokens"),[r,o]=m.useState(null),[i,d]=m.useState({output:!0,input:!0,cache:!0}),u=j=>{d(y=>{const N={...y,[j]:!y[j]};return!N.output&&!N.input&&!N.cache?y:N})},x=t.map(j=>n==="cost"?j.cost??0:(i.output?j.output:0)+(i.input?j.input:0)+(i.cache?j.cache:0)),h=Math.max(0,...x),l=Math.max(1,t.length),f=Gr/l,c=Math.min(f*(1-Of),64),p=Qt-Hr-Wr,g=j=>h>0?j/h*p:0,w=Math.max(1,Math.ceil(l/12)),k=r!==null?t[r]:null;return e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-sm font-medium",children:s("Daily trend")}),e.jsxs("div",{className:"flex items-center gap-3",children:[n==="tokens"&&e.jsxs("div",{className:"flex items-center gap-3 text-[11px] text-muted-foreground",children:[e.jsx(sn,{className:"bg-foreground",label:s("Output"),pressed:i.output,onClick:()=>u("output")}),e.jsx(sn,{className:"bg-foreground/45",label:s("Input"),pressed:i.input,onClick:()=>u("input")}),e.jsx(sn,{className:"bg-foreground/15",label:s("Cache"),pressed:i.cache,onClick:()=>u("cache")})]}),e.jsx(_f,{value:n,onChange:a})]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"pointer-events-none absolute left-0 top-0 font-mono text-[10px] text-muted-foreground",children:n==="tokens"?$e(h):rs(h>0?h:null)}),k&&e.jsxs("div",{className:"pointer-events-none absolute right-0 top-0 rounded bg-popover px-2 py-1 font-mono text-[11px] text-popover-foreground shadow-sm ring-1 ring-border",children:[k.day,n==="tokens"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[s("Output")," ",$e(k.output)]}),e.jsxs("div",{children:[s("Input")," ",$e(k.input)]}),e.jsxs("div",{children:[s("Cache")," ",$e(k.cache)]})]}):e.jsxs(e.Fragment,{children:[" · ",rs(k.cost)]})]}),e.jsx("svg",{viewBox:`0 0 ${Gr} ${Qt}`,className:"mt-4 block h-[180px] w-full",role:"img","aria-label":s("Daily trend"),onMouseLeave:()=>o(null),children:t.map((j,y)=>{const N=y*f+(f-c)/2,A=Qt-Wr,O=n==="tokens"?zf.filter(L=>i[L.id]).map(L=>({v:j[L.id],cls:L.cls})):[{v:j.cost??0,cls:"fill-emerald-600 dark:fill-emerald-500"}];let I=A;return e.jsxs("g",{onMouseEnter:()=>o(y),children:[e.jsx("rect",{x:N,y:Hr,width:c,height:p,className:"fill-transparent"}),O.map(L=>{const C=L.v>0?Math.max(Df,g(L.v)):0;return I-=C,e.jsx("rect",{x:N,y:I,width:c,height:C,rx:1,className:G(L.cls,r===y&&"opacity-80")},L.cls)}),y%w===0&&e.jsx("text",{x:N+c/2,y:Qt-4,textAnchor:"middle",className:"fill-muted-foreground font-mono text-[10px]",children:Lf(j.day)})]},j.day)})})]})]})}function sn({className:t,label:s,pressed:n,onClick:a}){return e.jsxs("button",{type:"button","aria-pressed":n,onClick:a,className:G("flex items-center gap-1 rounded px-0.5 transition-opacity",n?"opacity-100":"opacity-40"),children:[e.jsx("span",{className:G("inline-block h-2.5 w-2.5 rounded-sm",t)}),s]})}function _f({value:t,onChange:s}){const{t:n}=z(),a=[{id:"tokens",label:n("Token")},{id:"cost",label:n("Cost")}];return e.jsx("div",{className:"flex rounded-md bg-muted p-0.5",children:a.map(r=>e.jsx("button",{type:"button",onClick:()=>s(r.id),className:G("rounded px-2 py-0.5 text-[11px] transition-colors",t===r.id?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:r.label},r.id))})}const nn=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],Yr=Array.from({length:24},(t,s)=>String(s).padStart(2,"0")),is=["bg-foreground/[0.06]","bg-foreground/20","bg-foreground/40","bg-foreground/60","bg-foreground/80","bg-foreground"];function Ff(t,s){return t<=0||s<=0?0:1+Math.min(is.length-2,Math.floor(t/s*(is.length-1)))}function Uf({heatmap:t}){const{t:s}=z(),n=Math.max(0,...t.flat());return e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[e.jsx("span",{className:"text-sm font-medium",children:s("Activity by hour")}),e.jsxs("div",{className:"flex items-center gap-1 text-[10px] text-muted-foreground",children:[e.jsx("span",{children:s("Less")}),is.map(a=>e.jsx("span",{className:G("inline-block h-2.5 w-2.5 rounded-[2px]",a)},a)),e.jsx("span",{children:s("More")})]})]}),e.jsxs("div",{className:"grid grid-cols-[28px_1fr] gap-x-2 gap-y-1",children:[t.map((a,r)=>e.jsxs("div",{className:"contents",children:[e.jsx("span",{className:"self-center text-[10px] text-muted-foreground",children:s(nn[r])}),e.jsx("div",{className:"grid grid-cols-24 gap-[3px]",children:Yr.map((o,i)=>e.jsx("span",{title:`${s(nn[r])} ${o}:00 · ${$e(a[i]??0)}`,className:G("aspect-square rounded-[2px]",is[Ff(a[i]??0,n)])},o))})]},nn[r])),e.jsx("span",{}),e.jsx("div",{className:"grid grid-cols-24 font-mono text-[10px] text-muted-foreground",children:Yr.map((a,r)=>e.jsx("span",{className:G(r%3!==0&&"invisible"),children:a},a))})]})]})}function an({title:t,countLabel:s,rows:n,emptyLabel:a,limit:r=8}){const{t:o}=z(),[i,d]=m.useState(!1),u=n.reduce((l,f)=>l+f.tokens,0),x=n.length>r,h=x&&!i?n.slice(0,r):n;return e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[e.jsx("span",{className:"text-sm font-medium",children:t}),x&&e.jsx("span",{className:"text-[11px] text-muted-foreground",children:i?o("{{total}} items",{total:n.length}):o("Top {{count}} of {{total}}",{count:r,total:n.length})})]}),h.length===0?e.jsx("p",{className:"py-6 text-center text-xs text-muted-foreground",children:a}):e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-[11px] text-muted-foreground",children:[e.jsx("th",{className:"pb-2 text-left font-normal",children:o("Name")}),e.jsx("th",{className:"pb-2 text-right font-normal",children:o("Cost")}),e.jsx("th",{className:"pb-2 text-right font-normal",children:o("Token")}),e.jsx("th",{className:"pb-2 text-right font-normal",children:s})]})}),e.jsx("tbody",{children:h.map(l=>{const f=u>0?l.tokens/u:0;return e.jsxs("tr",{className:"border-t border-border/60",children:[e.jsxs("td",{className:"py-2 pr-3",children:[e.jsx("div",{className:"truncate",title:l.name,children:l.name||o("(no project)")}),e.jsx("div",{className:"mt-1 h-1 w-full rounded-full bg-foreground/[0.06]",children:e.jsx("div",{className:"h-1 rounded-full bg-foreground/70",style:{width:`${Math.max(1,f*100)}%`}})})]}),e.jsx("td",{className:G("py-2 text-right font-mono tabular-nums",l.cost===null&&"text-muted-foreground"),children:rs(l.cost)}),e.jsxs("td",{className:"py-2 text-right font-mono tabular-nums",children:[$e(l.tokens),e.jsxs("span",{className:"ml-1 text-muted-foreground",children:[(f*100).toFixed(0),"%"]})]}),e.jsx("td",{className:"py-2 text-right font-mono tabular-nums",children:l.count})]},l.key)})})]}),x&&e.jsx(S,{variant:"ghost",size:"xs",className:"mt-2 w-full text-muted-foreground",onClick:()=>d(l=>!l),children:o(i?"Collapse":"Show all")})]})}function $f({value:t,className:s}){const n=t.split("");return e.jsx("span",{className:G("t-digit-group is-animating",s),children:n.map((a,r)=>e.jsx("span",{className:"t-digit","data-stagger":r===n.length-2?"1":r===n.length-1?"2":void 0,children:a},`${r}:${a}`))},t)}const Vf={default:"text-foreground",success:"text-emerald-600 dark:text-emerald-400",info:"text-sky-600 dark:text-sky-400",muted:"text-muted-foreground"};function it({label:t,value:s,delta:n,tone:a="default"}){return e.jsxs("div",{className:"min-w-0 overflow-hidden rounded-lg border bg-card px-4 py-3",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[e.jsx("span",{className:"min-w-0 text-xs text-muted-foreground",children:t}),n&&e.jsx("span",{className:"shrink-0 font-mono text-[11px] tabular-nums text-muted-foreground",children:n})]}),e.jsx("div",{className:G("mt-1 truncate font-mono text-xl font-semibold leading-tight tabular-nums sm:text-2xl",Vf[a]),title:s,children:e.jsx($f,{value:s})})]})}const rn={input:0,output:0,cacheRead:0,cacheWrite:0},ls=["input","output","cacheRead","cacheWrite"];function on(t){return{input:String(t.input),output:String(t.output),cacheRead:String(t.cacheRead),cacheWrite:String(t.cacheWrite)}}function Kf(t){return _d({id:Object.fromEntries(ls.map(n=>[n,Number(t[n])]))}).id??null}function qf(t){return t===void 0?"—":String(t)}function Jr({rows:t,editing:s,draft:n,overrides:a,onDraft:r,onEdit:o,onSave:i}){const{t:d}=z();return e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-[11px] text-muted-foreground",children:[e.jsx("th",{className:"pb-2 text-left font-normal",children:d("Name")}),ls.map(u=>e.jsx("th",{className:"pb-2 text-right font-normal",children:u},u)),e.jsx("th",{className:"w-14 pb-2"})]})}),e.jsx("tbody",{children:t.map(u=>{const x=s===u.model,h=u.model in a;return e.jsxs("tr",{className:"border-t border-border/60",children:[e.jsxs("td",{className:"py-1.5 pr-3 align-middle",children:[e.jsx("span",{className:"font-mono text-xs",title:u.model,children:u.model}),h&&e.jsx("span",{className:"ml-1.5 text-[10px] text-muted-foreground",children:d("Custom")})]}),ls.map(l=>e.jsx("td",{className:"py-1.5 text-right align-middle",children:x?e.jsx(J,{size:"sm",inputMode:"decimal",className:"ml-auto w-16 [&_input]:text-right",value:n[l],onChange:f=>r({...n,[l]:f.target.value})}):e.jsx("span",{className:G("font-mono tabular-nums",u.pricing==null&&"text-muted-foreground"),children:qf(u.pricing?.[l])})},l)),e.jsx("td",{className:"py-1.5 text-right align-middle",children:x?e.jsx(S,{size:"sm",className:"h-6 px-1.5 text-[11px]",onClick:()=>i(u.model),children:d("Save")}):e.jsx(S,{variant:"ghost",size:"sm",className:"h-6 px-1.5 text-[11px]",onClick:()=>o(u.model,u.pricing),children:d("Edit")})})]},u.model)})})]})}function Gf({models:t,catalog:s,onChanged:n}){const{t:a}=z(),r=v(b=>b.usageModelPricing),o=$t(),i=v(b=>b.setUsageModelPricing),[d,u]=m.useState(!1),[x,h]=m.useState(!1),[l,f]=m.useState(null),[c,p]=m.useState(on(rn)),[g,w]=m.useState(null),[k,j]=m.useState(!1),[y,N]=m.useState(""),[A,O]=m.useState(""),I=new Set(t.map(b=>b.model)),L=new Set;for(const b of o)for(const _ of b.models)L.add(_.id);for(const b of Object.keys(r))L.add(b);const C=A.trim().toLowerCase(),E=t.filter(b=>!C||b.model.toLowerCase().includes(C)).map(b=>({model:b.model,pricing:b.pricing})),M=[...L].filter(b=>!I.has(b)&&(!C||b.toLowerCase().includes(C))).sort().map(b=>({model:b,pricing:r[b]??s[b]??null})),V=(b,_)=>{j(!1),f(b),p(on(_??rn)),w(null)},F=b=>{const _=Kf(c);return!_||!i(b,_)?(w(a("Enter a model id and non-negative rates.")),!1):(w(null),f(null),j(!1),N(""),n(),!0)};return e.jsxs(Ld,{open:d,onOpenChange:u,className:"rounded-lg border bg-card",children:[e.jsxs(zd,{className:"flex w-full items-center justify-between gap-3 px-4 py-3 text-left",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-medium",children:a("Unit prices")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("Rates used for cost estimates ($/M tokens).")})]}),e.jsx(ns,{className:G("h-4 w-4 shrink-0 text-muted-foreground transition-transform",d&&"rotate-180")})]}),e.jsx(Bd,{children:e.jsxs("div",{className:"space-y-3 border-t px-4 py-3",children:[e.jsx(J,{size:"sm",value:A,onChange:b=>O(b.target.value),placeholder:a("Search models")}),E.length===0&&!k?e.jsx("p",{className:"text-xs text-muted-foreground",children:a(C?"No matching models":"No usage in this period")}):e.jsx(Jr,{rows:E,editing:l,draft:c,overrides:r,onDraft:p,onEdit:V,onSave:F}),M.length>0&&(x||!!C)&&e.jsx(Jr,{rows:M,editing:l,draft:c,overrides:r,onDraft:p,onEdit:V,onSave:F}),k?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-end gap-2",children:[e.jsxs("label",{className:"grid min-w-36 gap-1 text-[11px] text-muted-foreground",children:[a("Model id"),e.jsx(J,{size:"sm",value:y,onChange:b=>N(b.target.value),placeholder:"qwen-3.8-27b"})]}),ls.map(b=>e.jsxs("label",{className:"grid min-w-16 gap-1 text-[11px] text-muted-foreground",children:[b,e.jsx(J,{size:"sm",inputMode:"decimal",value:c[b],onChange:_=>p(K=>({...K,[b]:_.target.value}))})]},b))]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(S,{size:"sm",className:"h-7",onClick:()=>F(y),children:a("Save")}),e.jsx(S,{variant:"ghost",size:"sm",className:"h-7",onClick:()=>{j(!1),N(""),w(null)},children:a("Cancel")})]})]}):e.jsxs("div",{className:"flex justify-end gap-2",children:[M.length>0&&e.jsxs(S,{variant:"ghost",size:"sm",className:"h-7 text-muted-foreground",onClick:()=>h(b=>!b),children:[a("Show all"),e.jsx(ns,{className:G("ml-1 h-3.5 w-3.5 transition-transform",x&&"rotate-180")})]}),e.jsx(S,{variant:"ghost",size:"sm",className:"h-7",onClick:()=>{j(!0),p(on(rn)),w(null)},children:a("Add")})]}),g&&e.jsx("p",{className:"text-xs text-destructive",children:g})]})})]})}const Hf={1:"Today",7:"7D",30:"30D",90:"90D"};function Wf(){const{t}=z(),[s,n]=m.useState(7),[a,r]=m.useState(null),o=v(p=>p.botModeEnabled),[i,d]=m.useState(null),[u,x]=m.useState(null),[h,l]=m.useState(!1),f=m.useRef(0),c=m.useCallback(async p=>{const g=++f.current;l(!0);const[w,k]=await Promise.all([window.electronAPI.usage.summary(p),o?window.electronAPI.bots.usageSummary(p).catch(()=>null):null]);g===f.current&&(l(!1),d(k?.ok?k.rows:null),w.ok?(r(w.summary),x(null)):(r(null),x(w.error)))},[o]);return m.useEffect(()=>{c(s)},[s,c]),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:t("Usage")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("Token usage across all local sessions; cost is estimated from catalog prices.")})]}),e.jsx(S,{variant:"ghost",size:"icon-sm",onClick:()=>{c(s)},disabled:h,"aria-label":t("Refresh"),children:e.jsx(Je,{className:G(h&&"animate-spin")})})]}),e.jsx(Yf,{value:s,onChange:n}),u&&e.jsx("p",{className:"text-sm text-destructive",children:u}),a&&e.jsxs(e.Fragment,{children:[e.jsx(Jf,{totals:a.totals,previous:a.previous}),e.jsx(Bf,{daily:a.daily}),e.jsx(Uf,{heatmap:a.heatmap}),e.jsxs("div",{className:"grid gap-4 xl:grid-cols-2",children:[e.jsx(an,{title:t("By model"),countLabel:t("Messages"),emptyLabel:t("No usage in this period"),rows:a.byModel.map(p=>({key:p.model,name:p.model,cost:p.cost,tokens:p.tokens,count:p.messages}))}),e.jsx(an,{title:t("By project"),countLabel:t("Sessions"),emptyLabel:t("No usage in this period"),rows:a.byProject.map(p=>({key:p.project||"#",name:p.project,cost:p.cost,tokens:p.tokens,count:p.sessions}))})]}),o&&i&&e.jsx(an,{title:t("By member"),countLabel:t("Sessions"),emptyLabel:t("No usage in this period"),rows:i.map(p=>({key:p.botId,name:p.name||t("Deleted member"),cost:p.cost,tokens:p.tokens,count:p.sessions}))}),a.unpricedModels.length>0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:t("No catalog price for: {{models}}. Their cost is not included.",{models:a.unpricedModels.join(", ")})})]}),e.jsx(Gf,{models:a?.byModel??[],catalog:a?.pricing??{},onChanged:()=>{c(s)}})]})}function Yf({value:t,onChange:s}){const{t:n}=z();return e.jsx("div",{className:"flex items-center gap-1.5",children:Rf.map(a=>e.jsx("button",{type:"button",onClick:()=>s(a),className:G("rounded-full px-3 py-1 font-mono text-xs transition-colors",t===a?"bg-foreground text-background":"bg-muted text-muted-foreground hover:text-foreground"),children:n(Hf[a])},a))})}function Jf({totals:t,previous:s}){const{t:n}=z(),a=t.cacheRead+t.cacheWrite,r=s.cacheRead+s.cacheWrite;return e.jsxs("div",{className:"grid grid-cols-2 gap-3 md:grid-cols-4",children:[e.jsx(it,{label:n("Estimated cost"),value:rs(t.cost),delta:at(s.cost,t.cost),tone:"success"}),e.jsx(it,{label:n("Total tokens"),value:$e(t.tokens),delta:at(s.tokens,t.tokens)}),e.jsx(it,{label:n("Input tokens"),value:$e(t.input),delta:at(s.input,t.input)}),e.jsx(it,{label:n("Output tokens"),value:$e(t.output),delta:at(s.output,t.output)}),e.jsx(it,{label:n("Cache tokens"),value:$e(a),delta:at(r,a),tone:"muted"}),e.jsx(it,{label:n("Active time"),value:Fd(t.activeMs),delta:at(s.activeMs,t.activeMs),tone:"info"}),e.jsx(it,{label:n("Sessions"),value:String(t.sessions),delta:at(s.sessions,t.sessions)}),e.jsx(it,{label:n("Messages"),value:t.messages.toLocaleString(),delta:at(s.messages,t.messages)})]})}const Qr={"x-asr-streaming":{name:"X-ASR Streaming",description:"Text appears while you speak. Chinese and English."},"x-asr":{name:"X-ASR",description:"Most accurate on everyday speech. Chinese and English."},"qwen3-asr":{name:"Qwen3-ASR 0.6B",description:"Best with mixed Chinese-English and code terms. Slower and uses more memory."},"sense-voice":{name:"SenseVoice",description:"Chinese, English, Japanese, Korean and Cantonese."},hanbao:{name:"Hanbao",description:"Runs fully offline. Chinese and English."},"gemini-live":{name:"Gemini Transcribe Live",description:"Google cloud recognition, most accurate with mixed Chinese-English and code terms. Needs a Gemini API key."},wetype:{name:"WeType",description:"WeChat Keyboard cloud recognition. Chinese and English, no setup needed."}};function _i({state:t,onDownload:s,onCancel:n,onRemove:a}){const{t:r}=z();return t==="unavailable"?null:t==="downloading"?e.jsx(S,{variant:"outline",size:"sm",onClick:n,children:r("Cancel")}):t==="ready"?e.jsx(S,{variant:"ghost",size:"sm",onClick:a,children:r("Remove")}):e.jsx(S,{variant:"outline",size:"sm",onClick:s,children:r("Download")})}function Qf(){const{t}=z(),s=v(h=>h.voiceModel),n=v(h=>h.setVoiceModel),{status:a,progress:r,error:o,refresh:i}=Ud();if(!a)return null;if(a.state==="unsupported")return e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Voice input is not available on this platform.")});const d=window.electronAPI.speech,u=h=>{const l=r[h.id];return l?`${l.file} · ${de(l.received)}${l.total?` / ${de(l.total)}`:""} (${l.fileIndex+1}/${l.fileCount})`:o?.modelId===h.id?`${t("Download failed")}: ${o.message}`:h.id==="wetype"?t("Audio is uploaded to Tencent WeChat Keyboard servers."):h.remote?h.state==="ready"?t("Audio is uploaded to Google. On the free tier Google may use it to improve its products."):t("Enter a Gemini API key below first."):t("Download {{size}} · Memory about {{memory}}",{size:de(h.approxBytes),memory:de(h.memoryBytes)})},x=a.models.find(h=>h.id===s);return e.jsxs("div",{className:"space-y-1.5","data-settings-row":"tools.voiceModel",children:[e.jsx("p",{className:"text-sm",children:t("Speech model")}),e.jsx("div",{role:"radiogroup",className:"divide-y rounded-md border",children:a.models.map(h=>{const l=h.id===s;return e.jsxs("div",{className:G("flex items-center gap-3 px-3 py-2",l&&"bg-accent/40"),children:[e.jsxs("button",{type:"button",role:"radio","aria-checked":l,onClick:()=>n(h.id),className:"flex min-w-0 flex-1 items-start gap-2.5 text-left",children:[e.jsx("span",{className:G("mt-1 flex size-3.5 shrink-0 items-center justify-center rounded-full border",l&&"border-primary"),children:l?e.jsx("span",{className:"size-2 rounded-full bg-primary"}):null}),e.jsxs("span",{className:"min-w-0",children:[e.jsxs("span",{className:"flex flex-wrap items-center gap-1.5 text-sm",children:[t(Qr[h.id].name),h.remote?e.jsx(te,{variant:"warning",size:"sm",children:t("Cloud")}):null,e.jsx(te,{variant:h.streaming?"info":"secondary",size:"sm",children:h.streaming?t("Streaming"):t("Sentence by sentence")}),h.state==="ready"&&!h.remote?e.jsx(te,{variant:"success",size:"sm",children:t("Downloaded")}):null]}),e.jsx("span",{className:"block text-muted-foreground text-xs",children:t(Qr[h.id].description)}),e.jsx("span",{className:G("block text-xs",o?.modelId===h.id?"text-destructive":h.remote?"text-warning":"text-muted-foreground"),children:u(h)})]})]}),e.jsx(_i,{state:h.remote?"unavailable":h.state,onDownload:()=>{n(h.id),d.download(h.id).then(i)},onCancel:()=>{d.cancelDownload(h.id).then(i)},onRemove:()=>{d.remove(h.id).then(i)}})]},h.id)})}),a.state!=="ready"&&a.state!=="downloading"&&!x?.remote?e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Download the selected model to start using voice input.")}):null,x?.id==="gemini-live"?e.jsxs(e.Fragment,{children:[e.jsx(Xf,{}),e.jsx(Zf,{})]}):null]})}function Xf(){const{t}=z(),s=v(a=>a.voiceGeminiApiKey),n=v(a=>a.setVoiceGeminiApiKey);return e.jsxs("div",{className:"space-y-1.5 pt-2","data-settings-row":"voice.geminiApiKey",children:[e.jsx("p",{className:"text-sm",children:t("Gemini API key")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Create one for free in Google AI Studio.")}),e.jsx(J,{type:"password",autoComplete:"off",spellCheck:!1,value:s,onChange:a=>n(a.target.value),placeholder:"AIza…",className:"font-mono"})]})}function Zf(){const{t}=z(),s=v(a=>a.voiceVocabulary),n=v(a=>a.setVoiceVocabulary);return e.jsxs("div",{className:"space-y-1.5 pt-2","data-settings-row":"voice.vocabulary",children:[e.jsx("p",{className:"text-sm",children:t("Custom vocabulary")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("One term per line, up to 100. Helps with names and code terms such as useEffect or pnpm.")}),e.jsx(He,{size:"sm",value:s,onChange:a=>n(a.target.value),placeholder:`useEffect
27
+ `))})]})}function It({title:t,children:s}){return e.jsxs("div",{className:"space-y-3 rounded-md border p-3",children:[e.jsx("p",{className:"text-sm font-medium",children:t}),s]})}function tf({settings:t}){const{t:s}=z(),[n,a]=m.useState(""),r=m.useMemo(()=>nd(n,t),[n,t]);return e.jsxs(It,{title:s("Try it"),children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Runs locally. Nothing is remembered or sent anywhere.")}),e.jsx(He,{rows:3,value:n,placeholder:s("Paste some text, e.g. an .env file"),onChange:o=>a(o.target.value)}),n&&e.jsxs(e.Fragment,{children:[e.jsx("pre",{className:"max-h-48 overflow-auto whitespace-pre-wrap rounded bg-muted p-2 text-xs",children:r.text}),e.jsxs("ul",{className:"space-y-0.5 text-xs",children:[r.report.hits.map(o=>e.jsxs("li",{className:"flex gap-2",children:[e.jsx("span",{className:G("font-medium",yn[o.action]),children:s(zt[o.action])}),e.jsx("span",{children:o.kind}),e.jsx("span",{className:"text-muted-foreground",children:o.preview}),o.count>1&&e.jsxs("span",{className:"text-muted-foreground",children:["×",o.count]})]},`${o.token}-${o.action}`)),r.report.hits.length===0&&e.jsx("li",{className:"text-muted-foreground",children:s("Nothing matched")})]})]})]})}function sf(){const{t}=z(),[s,n]=m.useState(7),[a,r]=m.useState(null),[o,i]=m.useState(!1),d=m.useRef(0),u=ad(f=>f.conversations),x=m.useCallback(async f=>{const c=++d.current;i(!0);const p=await window.electronAPI.privacyMask.records(f).catch(()=>[]);c===d.current&&(i(!1),r(p))},[]);m.useEffect(()=>{x(s)},[s,x]);const h=m.useMemo(()=>{const f={mask:0,warn:0,block:0},c=new Map;for(const p of a??[]){const g=new Set;for(const w of p.report.hits){const k=`${w.action}:${w.token}`;g.has(k)||(g.add(k),f[w.action]+=1,c.set(w.kind,(c.get(w.kind)??0)+1))}}return{byAction:f,byKind:[...c].sort((p,g)=>g[1]-p[1])}},[a]),l=f=>{if(f.source==="aux")return t("Auxiliary request");const c=f.sessionId?u[f.sessionId]?.title:void 0,p=f.source==="compaction"?t("Compaction"):t("Session");return c?`${p} · ${c}`:p};return e.jsxs(It,{title:t("Records"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"flex gap-1",children:Xp.map(f=>e.jsx(S,{size:"sm",variant:f===s?"secondary":"ghost",onClick:()=>n(f),children:t(Zp[f])},f))}),e.jsx(S,{variant:"ghost",size:"icon-sm",onClick:()=>{x(s)},disabled:o,"aria-label":t("Refresh"),children:e.jsx(Je,{className:G("size-4",o&&"animate-spin")})})]}),e.jsx("div",{className:"flex flex-wrap gap-4 text-sm",children:Object.keys(zt).map(f=>e.jsxs("span",{children:[e.jsx("span",{className:yn[f],children:t(zt[f])})," ",e.jsx("span",{className:"font-medium tabular-nums",children:h.byAction[f]})]},f))}),h.byKind.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 text-xs text-muted-foreground",children:h.byKind.map(([f,c])=>e.jsxs("span",{className:"rounded bg-muted px-1.5 py-0.5",children:[f," ",c]},f))}),e.jsxs("div",{className:"max-h-80 overflow-auto",children:[e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{className:"text-left text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"py-1 pr-2 font-normal",children:t("Requested at")}),e.jsx("th",{className:"py-1 pr-2 font-normal",children:t("Source")}),e.jsx("th",{className:"py-1 pr-2 font-normal",children:t("Model")}),e.jsx("th",{className:"py-1 font-normal",children:t("Hits")})]})}),e.jsx("tbody",{children:(a??[]).slice(0,200).map(f=>{const c=rd(f.report),p=`${f.at}:${f.sessionId??f.source}:${f.model}:${f.report.hits.map(g=>g.token).join(",")}`;return e.jsxs("tr",{className:"border-t align-top",children:[e.jsx("td",{className:"py-1 pr-2 whitespace-nowrap tabular-nums",children:new Date(f.at).toLocaleString()}),e.jsx("td",{className:"py-1 pr-2",children:l(f)}),e.jsx("td",{className:"py-1 pr-2 break-all",children:f.model}),e.jsxs("td",{className:G("py-1",c&&yn[c]),children:[ef(f),f.report.blocked&&` · ${t("Request blocked")}`]})]},p)})})]}),a?.length===0&&e.jsx("p",{className:"py-4 text-center text-xs text-muted-foreground",children:t("No records yet")})]})]})}function nf(){const{t}=z(),s=v(r=>r.privacyMasking),n=v(r=>r.setPrivacyMasking),a=r=>n({...s,...r});return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:t("Privacy")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("Replace API keys and personal data with placeholders before requests leave this device, and restore them in replies. Original values stay in memory on this device only.")})]}),e.jsx(Te,{rowId:"privacy.enabled",title:t("Privacy masking"),description:t("Applies to chats, compaction, bot members and helper requests."),checked:s.enabled,onChange:r=>a({enabled:r})}),s.enabled&&e.jsxs(e.Fragment,{children:[e.jsxs(It,{title:t("Secrets"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:t("API keys, tokens, private keys, passwords in URLs and config files.")}),e.jsx(Zs,{value:s.secrets.action,onChange:r=>a({secrets:{...s.secrets,action:r}})})]}),e.jsx(Te,{rowId:"privacy.secrets",title:t("Detect secrets"),description:t("Recommended. Covers common vendor key formats."),checked:s.secrets.enabled,onChange:r=>a({secrets:{...s.secrets,enabled:r}})}),e.jsx(Te,{rowId:"privacy.shape",title:t("Send look-alike keys"),description:t("Replace keys with fake keys of the same format instead of placeholders, so the model treats them as real keys."),checked:s.secrets.shape,onChange:r=>a({secrets:{...s.secrets,shape:r}})})]}),e.jsxs(It,{title:t("Personal data"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Emails, phone numbers, ID and bank card numbers, IP addresses.")}),e.jsx(Zs,{value:s.personal.action,onChange:r=>a({personal:{...s.personal,action:r}})})]}),e.jsx(Te,{rowId:"privacy.personal",title:t("Detect personal data"),description:t("Matches are validated (checksums, real domains) to limit false hits."),checked:s.personal.enabled,onChange:r=>a({personal:{...s.personal,enabled:r}})}),s.personal.enabled&&e.jsx("div",{className:"flex flex-wrap gap-4",children:sd.map(r=>e.jsxs("label",{className:"flex items-center gap-1.5 text-sm",children:[e.jsx(Qe,{checked:s.personal.kinds.includes(r),onCheckedChange:o=>a({personal:{...s.personal,kinds:o?[...s.personal.kinds,r]:s.personal.kinds.filter(i=>i!==r)}})}),t(Qp[r])]},r))})]}),e.jsxs(It,{title:t("Custom rules"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Words and patterns specific to your work.")}),e.jsx(Zs,{value:s.custom.action,onChange:r=>a({custom:{...s.custom,action:r}})})]}),e.jsx(en,{rowId:"privacy.words",label:t("Words"),hint:t("One per line, case-insensitive. Project codenames, customer names…"),value:s.custom.words,onCommit:r=>a({custom:{...s.custom,words:r}})}),e.jsx(en,{rowId:"privacy.rules",label:t("Prefixes or patterns"),hint:t("One per line. A prefix like corp_ or a regex like /INC-\\d{4}/i."),value:s.custom.rules,onCommit:r=>a({custom:{...s.custom,rules:r}})})]}),e.jsx(It,{title:t("Allow list"),children:e.jsx(en,{rowId:"privacy.allow",label:t("Never mask"),hint:t("Exact values, one per line. Team emails, test keys…"),value:s.allow,onCommit:r=>a({allow:r})})}),e.jsx(tf,{settings:s})]}),e.jsx(sf,{})]})}function af(){const{t}=z(),s=v(c=>c.approvalReviewer),n=v(c=>c.setApprovalReviewer),a=v(c=>c.approvalAutoManage),r=v(c=>c.setApprovalAutoManage),o=od(v(c=>c.approvalAllowThreshold)),i=v(c=>c.setApprovalAllowThreshold),d={"0.85":t("0.85 (looser)"),"0.9":t("0.9 (default)"),"0.95":t("0.95 (stricter)")},u=Xe(),x=Bn(),h=m.useMemo(()=>[...u,...x.filter(xn)],[u,x]),l=s?h.find(c=>c.id===s.providerId):void 0,f=l?.models.find(c=>c.id===s?.modelId);return e.jsxs("section",{className:"space-y-2 rounded-lg border bg-card p-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h4",{className:"font-medium text-sm",children:t("Assistant approval model")}),e.jsx("p",{className:"mt-0.5 text-muted-foreground text-xs",children:t("Required before Assistant approval can be selected. Does not fall back to the chat model.")})]}),h.length>0&&e.jsx("div",{className:"w-full min-w-0",children:e.jsx(ze,{providers:h,providerId:l?.id??"",modelId:f?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:t("No assistant approval model selected"),side:"bottom",triggerClassName:Ye,onSelect:(c,p)=>n({providerId:c,modelId:p}),onReasoningChange:()=>{},onThinkingChange:()=>{}})}),l&&xn(l)&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:t(a?"Auto-managed: runs only when the decision model is highly confident it is safe. Everything else is denied and the agent tries another way. Protected actions still ask you.":"Decision models only allow or block when highly confident. Everything else asks you.")}),e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("span",{className:"text-sm",children:t("Auto-manage approvals")}),e.jsx(le,{"aria-label":t("Auto-manage approvals"),checked:a,onCheckedChange:r})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("span",{className:"text-sm",children:t("Auto-allow threshold")}),e.jsxs(ae,{items:d,value:String(o),onValueChange:c=>i(Number(c)),children:[e.jsx(re,{className:"w-36","aria-label":t("Auto-allow threshold"),children:e.jsx(oe,{})}),e.jsx(ie,{children:id.map(c=>e.jsx(ee,{value:String(c),children:d[String(c)]},c))})]})]}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Only runs automatically when the allow probability reaches this value. Operations near the threshold may be allowed one time and not the next.")})]}),s&&(!l||!f)&&e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Selected model is unavailable")}),s&&e.jsx(S,{variant:"ghost",size:"sm",className:"self-start",onClick:()=>n(null),children:t("Clear")})]})}function Fr(t,s){const n=s.find(r=>r.id===t.providerId),a=n?.models.find(r=>r.id===t.modelId);return`${n?.name??t.providerId} / ${a?.label??t.modelId}`}function rf(){const{t}=z(),s=$t(),n=v(A=>A.virtualModels),a=v(A=>A.defaultModel),r=v(A=>A.setDefaultModel),o=v(A=>A.defaultModelFollowLast),i=v(A=>A.setDefaultModelFollowLast),d=v(A=>A.defaultReasoningEnabled),u=v(A=>A.defaultThinkingLevel),x=v(A=>A.setDefaultReasoningEnabled),h=v(A=>A.setDefaultThinkingLevel),l=as(A=>A.snapshot),f=ld(A=>A.latest),c=Xe(),p=a?c.find(A=>A.id===a.providerId):void 0,g=p?.models.find(A=>A.id===a?.modelId),w=s.some(A=>!!A.oauthAccountKey),k=w&&(l.availability.status==="unloaded"||l.availability.status==="loading"),j=w&&l.availability.status==="error"?l.availability.error:null,y=f?.notice,N=y?t("Default model changed: {{previous}} → {{next}}",{previous:Fr(y.previous,s),next:y.next?Fr(y.next,s):t("No default model")}):null;return e.jsxs("section",{className:"space-y-2 rounded-lg border bg-card p-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h4",{className:"font-medium text-sm",children:t("Default model")}),e.jsx("p",{className:"mt-0.5 text-muted-foreground text-xs",children:t(o?"New conversations use the last model you picked.":"Used for new conversations.")})]}),c.length>0&&e.jsx("div",{className:"w-full min-w-0",children:e.jsx(ze,{providers:c,virtualModels:n,providerId:p?.id??a?.providerId??"",modelId:g?.id??a?.modelId??"",reasoningEnabled:d,thinkingLevel:u,emptyLabel:t("Select model"),triggerLabel:o?t("Follow last selection"):void 0,side:"bottom",triggerClassName:Ye,onSelect:(A,O)=>r({providerId:A,modelId:O}),onReasoningChange:x,onThinkingChange:h,showReasoningControls:!o})}),!o&&c.length>0&&e.jsx(S,{type:"button",variant:"ghost",size:"sm",className:"self-start",onClick:()=>i(!0),children:t("Follow last selection")}),c.length===0&&e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-5 text-center",children:[e.jsx(Kn,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-2 font-medium text-sm",children:t("No usable models")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:t("Enable a model and configure valid provider credentials first.")})]}),(k||j)&&e.jsxs("div",{className:"flex items-start gap-2 rounded-md bg-muted px-2.5 py-2 text-xs",children:[e.jsx(At,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:j?t("Subscription credentials could not be loaded: {{error}}",{error:j}):t("Subscription credentials are loading. API-key models remain available.")})]}),N&&e.jsx("p",{className:"rounded-md bg-muted px-2.5 py-2 text-muted-foreground text-xs",children:N})]})}function of(){const{t}=z(),s=Qu($t()),n=v(o=>o.imageGenerationModel),a=n===null||s.some(o=>o.id===n.providerId&&o.models.some(i=>i.id===n.modelId)),r=v(o=>o.setImageGenerationModel);return e.jsxs("section",{className:"space-y-2 rounded-lg border bg-card p-3",children:[e.jsx("h4",{className:"font-medium text-sm",children:t("Default image generation model")}),s.length>0?e.jsx(ze,{providers:s,providerId:n?.providerId??"",modelId:n?.modelId??"",reasoningEnabled:!1,thinkingLevel:"medium",emptyLabel:t("Select model"),side:"bottom",triggerClassName:Ye,onSelect:(o,i)=>r({providerId:o,modelId:i}),onReasoningChange:()=>{},onThinkingChange:()=>{},showReasoningControls:!1}):e.jsx("p",{className:"text-muted-foreground text-xs",children:t("No image generation models available")}),!a&&e.jsx("p",{className:"text-destructive text-xs",children:t("Selected image generation model is unavailable")}),n&&e.jsx(S,{type:"button",variant:"ghost",size:"sm",onClick:()=>r(null),children:t("Clear selection")})]})}function lf({provider:t,onClose:s}){const{t:n}=z(),a=v(g=>g.providers),r=v(g=>g.updateProvider),o=$o(g=>g.snapshot),i=m.useMemo(()=>Vo([t],o)[0]?.models??t.models,[t,o]),d=as(g=>g.snapshot.availability),u=as(g=>g.snapshot.revision),[x,h]=m.useState([]),[l,f]=m.useState(t.oauthAccountPool?.accountKeys??[]);m.useEffect(()=>{let g=!1;return window.electronAPI.providers.listOauth().then(w=>{g||h(w)}).catch(w=>{g||(h([]),console.error("Failed to load OAuth account metadata",w))}),()=>{g=!0}},[u]);const c=Wo(a),p=[...c.flatMap(g=>g.oauthAccountKey??[]),...l.filter(g=>!c.some(w=>w.oauthAccountKey===g))];return e.jsx(Ko,{initialValue:{...t,name:qn(t,n),models:i},oauth:!0,hideName:!0,saveDisabled:l.length===0,oauthAccountKey:t.oauthAccountKey,onCancel:s,extraFields:e.jsxs(me,{children:[e.jsx(he,{children:n("Pool members")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n("Use enabled, signed-in accounts in the listed order. Model and reasoning stay unchanged. Main agents and subagents share this pool.")}),e.jsx("div",{className:"mt-2 w-full space-y-1 rounded-md border p-1",children:p.map((g,w)=>{const k=c.find(y=>y.oauthAccountKey===g),j=x.flatMap(y=>y.accounts).find(y=>y.key===g);return e.jsxs("label",{className:"flex min-w-0 items-center gap-2 px-2 py-1.5 text-sm",children:[e.jsx(Qe,{checked:l.includes(g),onCheckedChange:y=>f(N=>y?[...N,g]:N.filter(A=>A!==g))}),e.jsxs("span",{className:"shrink-0 text-xs text-muted-foreground",children:[w+1,"."]}),e.jsx("span",{className:"min-w-0 truncate",children:j?.email??g}),!k?.enabled&&e.jsx("span",{className:"shrink-0 text-xs text-muted-foreground",children:n("Account disabled")}),d.status==="ready"&&!d.authenticatedAccountKeys.has(g)&&e.jsx("span",{className:"shrink-0 text-xs text-muted-foreground",children:n("Account signed out")})]},g)})})]}),onSave:g=>{l.length!==0&&(r(t.id,{models:qo(g.models,Ho(o,t.oauthAccountKey??"")?.models,Go(v.getState(),t.id)),oauthAccountPool:{accountKeys:p.filter(w=>l.includes(w))}}),s())}})}function cf({provider:t,onClose:s}){const{t:n}=z(),a=v(i=>i.updateProvider),r=$o(i=>i.snapshot),o=m.useMemo(()=>t?.oauthAccountKey?Vo([t],r)[0]?.models??t.models:t?.models,[t,r]);return e.jsx(pe,{open:t!==null,onOpenChange:i=>!i&&s(),children:e.jsxs(fe,{children:[e.jsx(ge,{children:e.jsx(je,{children:t?.oauthAccountPool?qn(t,n):n("Edit Provider")})}),t?.oauthAccountPool?e.jsx(lf,{provider:t,onClose:s},t.id):t&&e.jsx(Ko,{initialValue:{name:t.name,api:t.api,apiKey:t.apiKey,baseUrl:t.baseUrl,models:o??t.models,headers:t.headers},oauth:!!t.oauthAccountKey,oauthAccountKey:t.oauthAccountKey,onCancel:s,onSave:i=>{a(t.id,t.oauthAccountKey?{name:i.name,models:qo(i.models,Ho(r,t.oauthAccountKey)?.models,Go(v.getState(),t.id))}:i),s()}},t.id)]})})}const df=(t,s)=>t.models.some(n=>n.id===s&&n.enabled!==!1),Ur=()=>{};function $r(t){return t==="on"||t==="off"}function tn(t){return typeof t=="string"&&hd.includes(t)}function uf(){const{t}=z(),s=v(l=>l.subagentModelsEnabled),n=v(l=>l.subagentModels),a=v(l=>l.setSubagentModelsEnabled),r=v(l=>l.addSubagentModel),o=v(l=>l.updateSubagentModel),i=v(l=>l.removeSubagentModel),d=v(l=>l.defaultModel),u=v(l=>l.virtualModels),x=Xe(),h=m.useMemo(()=>{if(d&&cd(d)){const l=dd(u,x).find(f=>f.id===d.modelId);if(l)return{providerId:ud,modelId:l.id}}if(d){const l=x.find(f=>f.id===d.providerId);if(l&&df(l,d.modelId))return d}for(const l of x){const f=l.models.find(c=>c.enabled!==!1);if(f)return{providerId:l.id,modelId:f.id}}return null},[x,d,u]);return e.jsxs("section",{"data-slot":"subagent-models",className:"space-y-2 rounded-lg border bg-card p-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h4",{className:"font-medium text-sm",children:t("Let the agent pick subagent models")}),e.jsx("p",{className:"mt-0.5 text-muted-foreground text-xs",children:t("The main agent can pick one of these models when dispatching subagents or coworkers. The description tells it when to use each model.")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:t("Applies to newly started conversations.")})]}),e.jsx(le,{className:"shrink-0",checked:s,onCheckedChange:a})]}),s&&e.jsxs("div",{className:"space-y-1.5",children:[n.map(l=>e.jsxs("div",{"data-slot":"subagent-model-row",className:G("flex items-center gap-2 rounded-md border px-2 py-1.5",l.enabled===!1&&"bg-muted/50 text-muted-foreground"),children:[e.jsx(le,{"data-slot":"subagent-model-enabled","aria-label":t("Enable subagent model"),title:t("Make this model available to subagents"),checked:l.enabled!==!1,onCheckedChange:f=>o(l.id,{enabled:f})}),l.enabled===!1&&e.jsx(te,{variant:"outline",className:"shrink-0 text-[10px] text-muted-foreground",children:t("Disabled")}),e.jsx("div",{className:"shrink-0 rounded-md border bg-background",children:e.jsx(ze,{providers:x,virtualModels:u,providerId:l.providerId,modelId:l.modelId,modelCapabilityOverrides:md(l),reasoningMode:$r(l.reasoning)?l.reasoning:"follow",reasoningEnabled:l.reasoning==="on",thinkingLevel:tn(l.thinkingLevel)?l.thinkingLevel:"medium",onReasoningModeChange:(f,c)=>{f==="follow"?o(l.id,{reasoning:void 0,thinkingLevel:void 0}):f==="on"&&!tn(l.thinkingLevel)?o(l.id,{reasoning:"on",thinkingLevel:c}):o(l.id,{reasoning:f})},onSelect:(f,c)=>o(l.id,{providerId:f,modelId:c}),onReasoningChange:f=>o(l.id,{reasoning:f?"on":"off"}),onThinkingChange:f=>o(l.id,{thinkingLevel:f}),onReasoningNormalize:$r(l.reasoning)?f=>o(l.id,{reasoning:f?"on":"off"}):Ur,onThinkingNormalize:tn(l.thinkingLevel)?f=>o(l.id,{thinkingLevel:f}):Ur})}),e.jsx(J,{value:l.description,placeholder:t("When to use it, e.g. cheap and fast for simple subtasks"),className:"h-7 flex-1 text-xs",onChange:f=>o(l.id,{description:f.target.value})}),e.jsx(S,{type:"button",variant:"ghost",size:"icon",className:"h-6 w-6 shrink-0 text-muted-foreground hover:text-destructive",onClick:()=>i(l.id),children:e.jsx(Me,{className:"h-3.5 w-3.5"})})]},l.id)),e.jsxs(S,{type:"button",variant:"outline",size:"sm",className:"h-7 text-xs",disabled:!h,onClick:()=>{h&&r({...h,description:""})},children:[e.jsx(Oe,{className:"mr-1 h-3.5 w-3.5"}),t("Add model")]}),!h&&e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Enable a model and configure valid provider credentials first.")})]})]})}function mf(){const{t}=z(),s=v(u=>u.titleSummaryEnabled),n=v(u=>u.setTitleSummaryEnabled),a=v(u=>u.titleSummaryModel),r=v(u=>u.setTitleSummaryModel),o=Xe(),i=a?o.find(u=>u.id===a.providerId):void 0,d=i?.models.find(u=>u.id===a?.modelId);return e.jsxs("section",{className:"space-y-2 rounded-lg border bg-card p-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h4",{className:"font-medium text-sm",children:t("Conversation title summary")}),e.jsx("p",{className:"mt-0.5 text-muted-foreground text-xs",children:t("Generate a short AI title from the first message of a new conversation.")})]}),e.jsx(le,{checked:s,onCheckedChange:n})]}),s&&e.jsxs("div",{className:"space-y-2",children:[o.length>0&&e.jsx("div",{className:"w-full min-w-0",children:e.jsx(ze,{providers:o,providerId:i?.id??"",modelId:d?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:t("Follows the default model"),side:"bottom",triggerClassName:Ye,onSelect:(u,x)=>r({providerId:u,modelId:x}),onReasoningChange:()=>{},onThinkingChange:()=>{}})}),a&&(!i||!d)&&e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Selected model is unavailable — falls back to the default model.")}),a&&e.jsx(S,{variant:"ghost",size:"sm",className:"self-start",onClick:()=>r(null),children:t("Follow default model")})]})]})}function hf({accountKey:t}){const s=Cd(t);return!s||s.error?null:e.jsx(Sd,{info:s})}function xf(){const{t}=z(),s=v(D=>D.providers),n=$t(),a=v(D=>D.updateProvider),r=v(D=>D.addProviders),o=v(D=>D.removeProvider),[i,d]=m.useState(!1),[u,x]=m.useState(!1),[h,l]=m.useState(null),[f,c]=m.useState(null),[p,g]=m.useState(null),[w,k]=m.useState(null),[j,y]=m.useState(!1),[N,A]=m.useState(!1),[O,I]=m.useState(null),L=as(D=>D.snapshot.revision),[C,E]=m.useState([]);m.useEffect(()=>{let D=!1;return window.electronAPI.providers.listOauth().then($=>{D||E($)}),()=>{D=!0}},[L]);const M=m.useMemo(()=>xd(s,C),[s,C]),V=m.useMemo(()=>{const D=new Map;for(const $ of n)D.set($.id,$.models.length);return D},[n]),F=async(D,$)=>{if(g(D.id),k(null),D.oauthAccountKey&&!D.oauthAccountPool&&!$?.skipLogout)try{await window.electronAPI.providers.oauthLogout(D.oauthAccountKey),await Id()}catch(Y){g(null),k({providerId:D.id,message:Y instanceof Error?Y.message:String(Y)});return}o(D.id),g(null),k(null)},b=()=>{const D=f;D&&F(D)},B=async()=>{y(!0),I(null);try{const D=await Nd(s);kd(D,a),I(D);const $=Object.values(D).filter(H=>H.status==="failed"),Y=Object.keys(D).length-$.length;Re({type:$.length>0?"warning":"success",title:t("Fetched {{count}} providers",{count:Y}),...$.length>0?{description:t("{{count}} failed",{count:$.length})}:{}})}finally{y(!1)}},K=async()=>{A(!0);try{const D=await window.electronAPI.providers.refreshModelCatalog();wd(),Re({type:D.ok?"success":"warning",title:D.ok?t("Model info updated"):D.fromCache?t("Model info refresh failed, using cache"):t("Model info refresh failed")})}catch{Re({type:"error",title:t("Model info refresh failed")})}finally{A(!1)}};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-wrap items-end justify-between gap-x-4 gap-y-3","data-settings-row":"providers.root",children:[e.jsxs("div",{className:"min-w-0 flex-1 basis-56",children:[e.jsxs("h3",{className:"text-lg font-medium",children:[t("Model Providers"),e.jsx(qe,{note:t("Newly enabled models can be picked right away. After changing a key or address, an open session uses it once you switch its model or start a new session.")})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("Manage model API providers for this app")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(S,{variant:"outline",size:"sm",disabled:N,onClick:()=>{K()},children:[N?e.jsx(Ae,{className:"mr-1.5 h-4 w-4 animate-spin"}):e.jsx(Je,{className:"mr-1.5 h-4 w-4"}),t("Refresh model info")]}),e.jsxs(S,{variant:"outline",size:"sm",disabled:j||s.length===0,onClick:()=>{B()},children:[j?e.jsx(Ae,{className:"mr-1.5 h-4 w-4 animate-spin"}):e.jsx(Je,{className:"mr-1.5 h-4 w-4"}),t("Fetch all models")]}),e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>d(!0),children:[e.jsx(cs,{className:"h-4 w-4 mr-1.5"}),t("Import from local apps")]}),e.jsxs(S,{size:"sm",onClick:()=>x(!0),children:[e.jsx(Oe,{className:"h-4 w-4 mr-1.5"}),t("Add model or provider")]})]})]}),e.jsx(rf,{}),e.jsx(of,{}),e.jsx(uh,{}),e.jsx(mf,{}),e.jsx(af,{}),e.jsx(uf,{}),Wo(s).length>0&&!s.some(D=>D.oauthAccountPool)&&e.jsxs("div",{className:"space-y-1.5 rounded-md border p-3",children:[e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>{const D=pd(s,crypto.randomUUID());D&&r([D])>0&&l(D)},children:[e.jsx(Oe,{className:"mr-1.5 h-3.5 w-3.5"}),t("Create ChatGPT account pool")]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Pool entries do not show a single account quota. Fixed-account entries remain unchanged.")})]}),s.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx(Kn,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 text-sm font-medium",children:t("No providers yet")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:t("Import providers from local apps or use the unified setup to get started")})]}):e.jsx("div",{className:"space-y-1",children:M.map(D=>{const $=C.find(H=>H.id===D.vendorId),Y=D.vendorId===fd?t("Custom"):D.label;return e.jsxs("div",{className:"rounded-md px-3 py-2",children:[e.jsxs("div",{className:"flex items-baseline gap-1.5",children:[e.jsx("span",{className:"text-[11px] font-semibold tracking-wide text-muted-foreground",children:Y}),e.jsx("span",{className:"text-[11px] text-muted-foreground/60",children:D.providers.length})]}),e.jsx("div",{className:"mt-1.5 space-y-1 border-l pl-3",children:D.providers.map(H=>{const se=!!H.oauthAccountKey,q=V.get(H.id)??H.models.length,Q=H.oauthAccountKey&&!H.oauthAccountPool?$?.accounts.find(R=>R.key===H.oauthAccountKey):void 0,_=H.oauthAccountPool?qn(H,t):se?Q?.email??H.oauthAccountKey??H.name:H.name,ne=O?.[H.id];return e.jsxs(m.Fragment,{children:[e.jsxs("div",{className:"group flex items-start justify-between gap-3 rounded-md px-3 py-2 transition-colors hover:bg-accent/50","data-settings-row":`providers.${H.id}`,children:[e.jsxs("div",{className:"min-w-0 flex-1 overflow-hidden",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[se?e.jsx(gd,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}):e.jsx(jd,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx("span",{className:G("truncate text-sm font-medium",!H.enabled&&"text-muted-foreground line-through"),children:_}),se?Q?.plan&&e.jsx(te,{variant:"outline",className:"shrink-0 text-[10px] uppercase",children:Q.plan}):e.jsx(te,{variant:"outline",className:"shrink-0 text-[11px]",children:vd[H.api]??H.api}),H.importedFrom&&e.jsx(te,{variant:"secondary",className:"shrink-0 text-[11px]",children:H.importedFrom}),e.jsx("span",{className:"min-w-0 truncate text-xs text-muted-foreground",children:[se?void 0:H.baseUrl,H.oauthAccountPool?t("{{count}} accounts",{count:H.oauthAccountPool.accountKeys.length}):void 0,q>0?t("{{count}} models",{count:q}):void 0].filter(Boolean).join(" · ")})]}),xn(H)&&e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:t("Classification only, not for chat")}),H.oauthAccountKey&&!H.oauthAccountPool&&e.jsx(hf,{accountKey:H.oauthAccountKey})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1 pt-0.5",children:[e.jsx(S,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",onClick:()=>l(H),children:e.jsx(lt,{className:"h-3.5 w-3.5"})}),e.jsx(S,{variant:"ghost",size:"icon",disabled:p===H.id,className:G("h-7 w-7 text-muted-foreground opacity-0 transition-opacity hover:text-destructive group-hover:opacity-100",p===H.id&&"opacity-100"),onClick:()=>c(H),children:p===H.id?e.jsx(Ae,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Me,{className:"h-3.5 w-3.5"})}),e.jsx(le,{checked:H.enabled,onCheckedChange:R=>a(H.id,{enabled:R})})]})]}),w?.providerId===H.id&&e.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-md border border-destructive/30 bg-destructive/5 px-3 py-1.5 text-xs text-destructive",children:[e.jsx("span",{className:"min-w-0 truncate",children:t("Sign-out failed: {{message}}",{message:w.message})}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(S,{variant:"outline",size:"sm",className:"h-6 px-2 text-[11px]",onClick:()=>{F(H)},children:t("Retry")}),e.jsx(S,{variant:"ghost",size:"sm",className:"h-6 px-2 text-[11px] text-destructive hover:text-destructive",onClick:()=>{F(H,{skipLogout:!0})},children:t("Delete anyway")})]})]}),ne?.status==="failed"&&e.jsx("div",{className:"flex items-center justify-between gap-2 rounded-md border border-destructive/30 bg-destructive/5 px-3 py-1.5 text-xs text-destructive",children:e.jsxs("span",{className:"min-w-0 truncate",children:[t("Fetch failed"),": ",ne.message]})})]},H.id)})})]},D.vendorId)})}),e.jsx(bd,{open:i,onOpenChange:d}),e.jsx(yd,{open:u,onOpenChange:x}),e.jsx(cf,{provider:h,onClose:()=>l(null)}),e.jsx(fo,{open:f!==null,onOpenChange:D=>{D||c(null)},title:t("Remove provider?"),description:f?f.oauthAccountKey&&!f.oauthAccountPool?t("Removing this also signs out {{name}}. Other accounts for the same vendor stay signed in.",{name:f.name}):t('This permanently deletes the "{{name}}" provider configuration.',{name:f.name}):void 0,confirmLabel:t("Remove"),onConfirm:b})]})}const pf=2e3,Vr=50,Rt="",ff=[{id:"app",label:"App processes"},{id:"agent",label:"Agent and tools"},{id:"child",label:"Other child processes"}],wn={sessions:["Conversation history","Conversation transcripts and usage ledger."],coworkers:["Coworker transcripts","Coworker journals; only those of deleted conversations are cleaned."],toolOutputs:["Tool outputs","Saved long tool outputs; only those of deleted conversations are cleaned."],memory:["Memory","Memory database and working memory."],models:["Local models","Downloaded embedding, chat and speech models."],runtimes:["Runtimes","Bundled tools, speech runtime and GPU backends."],worktrees:["Worktrees","Isolated worktrees created for conversations."],snapshots:["Change snapshots","Baselines for the Changes panel."],browser:["Browser data","Cookies, storage and cache of the built-in browser."],cache:["Cache","Rebuildable caches; cleaning is safe."],logs:["Logs","Task and memory logs; files written in the last 24 hours are kept."],backups:["Backups","Configuration backup files; files from the last 24 hours are kept."],config:["Configuration","Settings, instructions, prompts and credentials."],other:["Other","Chromium profile data and other files."]};function gf(t,s){switch(t){case"main":return s("Main process");case"window":return s("Window");case"browser":return s("Built-in browser");case"gpu":return"GPU";case"service":return s("Service");case"agent":return"Agent";case"tool":return s("Tool");default:return s("Child process")}}function jf(t,s){return t.id==="data"?s("App data"):s("Worktree directory")}function vf(t,s){return t.role!=="window"?t.name:t.name==="Main window"?s("Main window"):t.name==="Settings"?s("Settings"):t.name}function bf(t){return`${t.toFixed(1)}%`}function yf(){const{t}=z(),[s,n]=m.useState("cpu");return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:t("Resources")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("CPU, memory and disk usage of EnsoCode and the processes it started.")})]}),e.jsxs(Ft,{value:s,onValueChange:a=>n(a),children:[e.jsxs(Ut,{children:[e.jsx(Ke,{value:"cpu",children:"CPU"}),e.jsx(Ke,{value:"memory",children:t("RAM")}),e.jsx(Ke,{value:"storage",children:t("Storage")})]}),e.jsx(Dt,{value:"cpu",className:"pt-4",children:s==="cpu"&&e.jsx(Kr,{metric:"cpu"})}),e.jsx(Dt,{value:"memory",className:"pt-4",children:s==="memory"&&e.jsx(Kr,{metric:"memory"})}),e.jsx(Dt,{value:"storage",className:"pt-4",children:s==="storage"&&e.jsx(Nf,{})})]})]})}function Kr({metric:t}){const{t:s}=z(),[n,a]=m.useState(null),[r,o]=m.useState(null);if(m.useEffect(()=>{let x=!1,h;const l=async()=>{try{const f=await window.electronAPI.resources.sample();if(x)return;a(f),o(null)}catch(f){x||o(f instanceof Error?f.message:String(f))}x||(h=setTimeout(l,pf))};return l(),()=>{x=!0,clearTimeout(h)}},[]),r&&!n)return e.jsx("p",{className:"text-sm text-destructive",children:r});if(!n)return e.jsx("p",{className:"text-sm text-muted-foreground",children:s("Loading...")});const i=t==="cpu"?bf:de,d=t==="cpu"?{app:n.cpu.app,system:n.cpu.system,total:100}:n.memory,u=x=>t==="cpu"?x.cpu:x.memory;return e.jsxs("div",{className:"space-y-4",children:[e.jsx(Li,{app:d.app,system:Math.max(d.system,d.app),total:d.total,format:i}),ff.map(x=>{const h=n.processes.filter(l=>l.group===x.id).sort((l,f)=>u(f)-u(l));return h.length===0?null:e.jsxs("div",{className:"rounded-lg border",children:[e.jsxs("div",{className:"flex items-center justify-between border-b px-3 py-2 text-sm font-medium",children:[e.jsx("span",{children:s(x.label)}),e.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:i(h.reduce((l,f)=>l+u(f),0))})]}),e.jsx("div",{className:"divide-y",children:h.map(l=>e.jsxs("div",{className:"flex items-center gap-3 px-3 py-1.5 text-sm",children:[e.jsx("span",{className:"w-20 shrink-0 truncate text-xs text-muted-foreground",children:gf(l.role,s)}),e.jsx("span",{className:"min-w-0 flex-1 truncate",title:l.command??l.name,children:vf(l,s)}),e.jsx("span",{className:"w-16 text-right font-mono text-xs text-muted-foreground",children:l.pid}),e.jsx("span",{className:"w-20 text-right font-mono text-xs",children:i(u(l))})]},l.pid))})]},x.id)})]})}function Li({app:t,system:s,total:n,format:a}){const{t:r}=z(),o=i=>`${n>0?Math.min(100,i/n*100):0}%`;return e.jsxs("div",{className:"space-y-3 rounded-lg border p-4",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"EnsoCode"}),e.jsx("div",{className:"font-mono text-2xl font-semibold",children:a(t)})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:r("System")}),e.jsxs("div",{className:"font-mono text-sm",children:[a(s)," / ",a(n)]})]})]}),e.jsxs("div",{className:"relative h-2 overflow-hidden rounded-full bg-muted",children:[e.jsx("div",{className:"absolute inset-y-0 left-0 bg-foreground/25",style:{width:o(s)}}),e.jsx("div",{className:"absolute inset-y-0 left-0 bg-foreground",style:{width:o(t)}})]})]})}function wf(t,s){const n=[s("Freed {{size}}",{size:de(t.freedBytes)})];return t.removed>0&&n.push(s("{{count}} files removed",{count:t.removed})),t.skipped>0&&n.push(s("{{count}} kept",{count:t.skipped})),t.failed>0&&n.push(s("{{count}} failed",{count:t.failed})),n.join(" · ")}function Nf(){const{t}=z(),[s,n]=m.useState(null),[a,r]=m.useState("scan"),[o,i]=m.useState(null),[d,u]=m.useState(null),[x,h]=m.useState(null),[l,f]=m.useState(null),c=m.useCallback(async(j,y)=>{r(j),u(null),i(null);try{n(await y())}catch(N){const A=N instanceof Error?N.message:String(N);A.includes("Scan cancelled")||u(A)}finally{r(null),i(null)}},[]),p=m.useCallback(()=>c("scan",()=>window.electronAPI.resources.scanStorage()),[c]),g=j=>c(j,async()=>{const y=await window.electronAPI.resources.cleanStorage(j);return Re({type:y.failed>0?"warning":"success",title:t("{{name}} cleaned",{name:t(wn[j][0])}),description:wf(y,t)}),y.snapshot});m.useEffect(()=>{const j=window.electronAPI.resources.onScanProgress(i);return window.electronAPI.resources.lastStorage().then(y=>{y&&n(N=>N??y)}),p(),()=>{j(),window.electronAPI.resources.cancelScan()}},[p]);const w=s?[...s.categories].filter(j=>j.bytes>0).sort((j,y)=>y.bytes-j.bytes):[],k=m.useMemo(()=>{const j=new Map;for(const y of s?.roots??[])j.set(y.volumeId,[...j.get(y.volumeId)??[],y]);return[...j.values()]},[s]);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("p",{className:"min-w-0 truncate text-xs text-muted-foreground",children:a==="scan"?o?t("Scanning {{count}} files · {{size}}",{count:o.files.toLocaleString(),size:de(o.bytes)}):t("Scanning..."):s?t("Scanned at {{time}} · took {{seconds}}s",{time:new Date(s.scannedAt).toLocaleTimeString(),seconds:(s.durationMs/1e3).toFixed(1)}):null}),a==="scan"?e.jsx(S,{variant:"ghost",size:"sm",onClick:()=>{window.electronAPI.resources.cancelScan()},children:t("Cancel")}):e.jsx(S,{variant:"ghost",size:"icon-sm",onClick:()=>{p()},disabled:a!==null,"aria-label":t("Refresh"),children:e.jsx(Je,{})})]}),d&&e.jsx("p",{className:"text-sm text-destructive",children:d}),s&&s.errorCount>0&&e.jsxs("p",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",title:s.errors.join(`
28
+ `),children:[e.jsx(Ue,{className:"h-3.5 w-3.5"}),t("{{count}} paths could not be read and are not counted.",{count:s.errorCount})]}),s&&e.jsxs(e.Fragment,{children:[k.map(j=>{const y=j[0]?.volume,N=j.reduce((A,O)=>A+O.bytes,0);return e.jsxs("div",{className:"space-y-2",children:[y?e.jsx(Li,{app:N,system:y.total-y.free,total:y.total,format:de}):e.jsx("div",{className:"rounded-lg border p-4 font-mono text-2xl font-semibold",children:de(N)}),j.map(A=>e.jsxs("div",{className:"flex items-center gap-2 px-1 text-xs",children:[e.jsx("span",{className:"shrink-0 text-muted-foreground",children:jf(A,t)}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono",title:A.path,children:A.path}),e.jsx("span",{className:"font-mono",children:de(A.bytes)})]},A.id))]},j[0]?.volumeId)}),e.jsx("div",{className:"divide-y rounded-lg border",children:w.map(j=>e.jsx(kf,{category:j,share:s.totalBytes>0?j.bytes/s.totalBytes:0,expanded:x===j.id,onToggle:()=>h(x===j.id?null:j.id),cleaning:a===j.id,disabled:a!==null,onClean:()=>Yo[j.id]==="confirm"?f(j.id):void g(j.id)},j.id))}),e.jsx(Cf,{sessions:s.sessions,busy:a==="sessions",disabled:a!==null,onClean:j=>c("sessions",async()=>{const y=await window.electronAPI.resources.cleanSessions(j);return Re({type:"success",title:t("{{count}} conversations deleted",{count:y.removed})}),y.snapshot})})]}),e.jsx(An,{open:l!==null,onOpenChange:j=>!j&&f(null),children:e.jsxs(En,{className:"sm:max-w-md",zIndexLevel:"nested",children:[e.jsxs(Mn,{children:[e.jsx(Pn,{className:"text-base",children:t("Clean {{name}}?",{name:l?t(wn[l][0]):""})}),e.jsx(Tn,{children:t(l==="browser"?"You will be signed out of sites opened in the built-in browser.":"Deleted files cannot be restored.")})]}),e.jsxs(Rn,{variant:"bare",children:[e.jsx(On,{render:e.jsx(S,{variant:"outline",size:"sm"}),children:t("Cancel")}),e.jsx(S,{variant:"destructive",size:"sm",onClick:()=>{const j=l;f(null),j&&g(j)},children:t("Clean")})]})]})})]})}function kf({category:t,share:s,expanded:n,onToggle:a,cleaning:r,disabled:o,onClean:i}){const{t:d}=z(),[u,x]=wn[t.id];return e.jsxs("div",{className:"px-3 py-2",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{type:"button",onClick:a,className:"flex min-w-0 flex-1 items-center gap-2 text-left",children:[e.jsx(Mt,{className:G("h-4 w-4 shrink-0 transition-transform",n&&"rotate-90")}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-2 text-sm",children:[e.jsx("span",{className:"font-medium",children:d(u)}),e.jsx("span",{className:"font-mono text-xs",children:de(t.bytes)})]}),e.jsx("p",{className:"truncate text-xs text-muted-foreground",children:d(x)}),e.jsx("div",{className:"mt-1 h-1 overflow-hidden rounded-full bg-muted",children:e.jsx("div",{className:"h-full bg-foreground/60",style:{width:`${s*100}%`}})})]})]}),Yo[t.id]!=="none"&&e.jsx(S,{variant:"outline",size:"sm",disabled:o,onClick:i,children:d(r?"Cleaning...":"Clean")})]}),n&&e.jsx("div",{className:"mt-2 space-y-0.5 pl-6",children:t.entries.map(h=>e.jsxs("div",{className:"group flex items-center gap-2 text-xs",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-muted-foreground",children:h.root==="data"?h.path:`${d("Worktree directory")}/${h.path}`}),e.jsx("span",{className:"font-mono",children:de(h.bytes)}),e.jsx(S,{variant:"ghost",size:"icon-sm",className:"opacity-0 group-hover:opacity-100","aria-label":d("Show in folder"),onClick:()=>{window.electronAPI.resources.revealStorage(h.root,h.path)},children:e.jsx(_n,{})})]},`${h.root}:${h.path}`))})]})}function Cf({sessions:t,busy:s,disabled:n,onClean:a}){const{t:r}=z(),[o,i]=m.useState(!1),[d,u]=m.useState(!1),[x,h]=m.useState(null),[l,f]=m.useState(Rt),c=m.useMemo(()=>new Map(t.map(C=>[C.id,C])),[t]),p=m.useMemo(()=>{const C=new Map;for(const E of t){const M=C.get(E.projectId)??{name:E.projectName,bytes:0,count:0};M.bytes+=E.bytes,M.count+=1,C.set(E.projectId,M)}return[...C].sort((E,M)=>M[1].bytes-E[1].bytes)},[t]),g=p.some(([C])=>C===l)?l:Rt,w=g?t.filter(C=>C.projectId===g):t,k=C=>{const E=Td(t,C,Date.now());return{request:C,count:E.length,bytes:E.reduce((M,V)=>M+(c.get(V)?.bytes??0),0)}},j=C=>k({kind:"stale",days:C,includeUnarchived:o,...g?{projectId:g}:{}}),y=w.reduce((C,E)=>C+E.bytes,0),N=d?w:w.slice(0,Vr),A=(C,E)=>E||(C?C.slice(0,8):r("No project")),O=x?.request.kind==="one"?c.get(x.request.id):void 0,I=x?.request.kind==="stale"?x.request.projectId:void 0,L=I===void 0?void 0:A(I,p.find(([C])=>C===I)?.[1].name??"");return e.jsxs("div",{className:"rounded-lg border",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 border-b px-3 py-2",children:[e.jsxs("div",{className:"shrink-0 text-sm font-medium",children:[r("Conversations"),e.jsxs("span",{className:"ml-2 font-mono text-xs text-muted-foreground",children:[w.length," · ",de(y)]})]}),e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsxs(ae,{items:{[Rt]:r("All projects"),...Object.fromEntries(p.map(([C,E])=>[C,A(C,E.name)]))},value:g,onValueChange:C=>f(C??Rt),children:[e.jsx(re,{size:"sm",className:"w-48 min-w-0",children:e.jsx(oe,{})}),e.jsxs(ie,{children:[e.jsx(ee,{value:Rt,children:r("All projects")}),p.map(([C,E])=>e.jsx(ee,{value:C,children:e.jsxs("span",{className:"flex w-full items-center gap-3",children:[e.jsx("span",{className:"flex-1 truncate",children:A(C,E.name)}),e.jsxs("span",{className:"font-mono text-xs text-muted-foreground",children:[E.count," · ",de(E.bytes)]})]})},C))]})]}),e.jsxs(Jo,{children:[e.jsxs(Qo,{render:e.jsx(S,{variant:"outline",size:"sm",disabled:n||w.length===0}),children:[e.jsx(Ad,{}),r(s?"Cleaning...":"Clean")]}),e.jsxs(Xo,{align:"end",className:"min-w-48",children:[e.jsx(Ed,{checked:o,onCheckedChange:i,closeOnClick:!1,children:r("Include unarchived")}),e.jsx(Md,{}),[...Pd,0].map(C=>{const E=j(C);return e.jsxs(Zo,{variant:"destructive",disabled:E.count===0,onClick:()=>h(E),children:[e.jsx("span",{className:"flex-1",children:C>0?r("Older than {{days}} days",{days:C}):r("All")}),e.jsx("span",{className:"font-mono text-xs opacity-70",children:E.count})]},C)})]})]})]})]}),e.jsx("div",{className:"max-h-96 divide-y overflow-y-auto",children:N.map(C=>e.jsxs("div",{className:"group flex items-center gap-3 px-3 py-1.5 text-sm",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate",title:C.title,children:C.title||r("Untitled")}),e.jsx("div",{className:"truncate text-xs text-muted-foreground",children:[C.projectName,C.archived?r("Archived"):null,new Date(C.lastActiveAt).toLocaleDateString()].filter(Boolean).join(" · ")})]}),e.jsx("span",{className:"font-mono text-xs",children:de(C.bytes)}),e.jsx(S,{variant:"ghost",size:"icon-sm",className:"opacity-0 group-hover:opacity-100",disabled:n,"aria-label":r("Delete"),onClick:()=>h({request:{kind:"one",id:C.id},count:1,bytes:C.bytes}),children:e.jsx(Me,{})})]},C.id))}),w.length>Vr&&e.jsx("button",{type:"button",onClick:()=>u(!d),className:"w-full border-t px-3 py-1.5 text-xs text-muted-foreground hover:text-foreground",children:r(d?"Show less":"Show all")}),e.jsx(An,{open:x!==null,onOpenChange:C=>!C&&h(null),children:e.jsxs(En,{className:"sm:max-w-md",zIndexLevel:"nested",children:[e.jsxs(Mn,{children:[e.jsx(Pn,{className:"text-base",children:O?r('Delete "{{title}}"?',{title:O.title||r("Untitled")}):L!==void 0?r("Delete {{count}} conversations in {{project}}?",{count:x?.count??0,project:L}):r("Delete {{count}} conversations?",{count:x?.count??0})}),e.jsxs(Tn,{children:[r("About {{size}} of history, tool output and isolated worktrees will be removed and cannot be restored.",{size:de(x?.bytes??0)}),!O&&` ${r("Open, running and waiting conversations are skipped.")}`]})]}),e.jsxs(Rn,{variant:"bare",children:[e.jsx(On,{render:e.jsx(S,{variant:"outline",size:"sm"}),children:r("Cancel")}),e.jsx(S,{variant:"destructive",size:"sm",onClick:()=>{const C=x?.request;h(null),C&&a(C)},children:r("Delete")})]})]})})]})}function Sf(){const{t}=z(),s=v(N=>N.skills),n=v(N=>N.updateSkill),a=v(N=>N.setSkillsEnabled),r=v(N=>N.removeSkill),o=v(N=>N.loadLocalSkills),i=v(N=>N.setLoadLocalSkills),d=v(N=>N.loadHarnessAssets),u=v(N=>N.setLoadHarnessAssets),[x,h]=m.useState(!1),[l,f]=m.useState(""),c=s.filter(N=>Oo(l,[N.name,N.source,N.description,N.path])),p=c.map(N=>N.id),g=Do(p),w=s.filter(N=>N.enabled).length,k=s.map(N=>N.id),j=hs(k,N=>window.electronAPI.assets.skillOccupancy(N)),y=ds(s.filter(N=>N.enabled).map(N=>N.id),j.rows);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 rounded-lg border px-3 py-2.5",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:t("Load local skills")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Let the agent auto-discover skills under .agents/skills and .pi/skills")})]}),e.jsx(le,{checked:o,onCheckedChange:i})]}),e.jsxs("div",{className:"flex items-center justify-between gap-4 rounded-lg border px-3 py-2.5",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:t("Load project harness assets")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Also load skills from .claude/.codex/.cursor and rule files (.cursorrules, .cursor/rules, .claude/rules) in the project")})]}),e.jsx(le,{checked:d,onCheckedChange:u})]}),e.jsxs("div",{className:"flex items-end justify-between gap-4","data-settings-row":"skills.root",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"font-medium text-lg",children:[t("Skills"),e.jsx(qe,{note:t("The / menu updates right away, but open sessions keep the skills they loaded. Start a new session to load the change.")}),s.length>0&&e.jsxs("span",{className:"ml-2 font-normal text-muted-foreground text-xs",children:[t("{{enabled}}/{{total}} enabled",{enabled:w,total:s.length}),e.jsx(ms,{tokens:y})]})]}),e.jsx("p",{className:"text-muted-foreground text-sm",children:t("Skills registered by reference; files stay in their original location")})]}),e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>h(!0),children:[e.jsx(cs,{className:"mr-1.5 h-4 w-4"}),t("Import from local apps")]})]}),s.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx(ei,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:t("No skills yet")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:t("Import skills from Claude Code, Codex or Cursor to get started")})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx(zo,{query:l,onQueryChange:f,placeholder:t("Filter skills..."),allSelected:g.allSelected,someSelected:g.someSelected,onToggleSelectAll:g.toggleAll,onEnable:()=>a(g.selectedIds,!0),onDisable:()=>a(g.selectedIds,!1),selectDisabled:c.length===0,actionDisabled:g.selectedIds.length===0}),c.length===0?e.jsx("p",{className:"px-3 py-6 text-center text-muted-foreground text-xs",children:t("No results")}):e.jsx("div",{className:"space-y-1",children:c.map(N=>e.jsxs("div",{className:"group flex items-center justify-between gap-3 rounded-md px-3 py-2 transition-colors hover:bg-accent/50","data-settings-row":`skills.${N.id}`,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(Qe,{checked:g.isSelected(N.id),onCheckedChange:A=>g.toggleOne(N.id,A)}),e.jsx("span",{className:G("shrink-0 font-medium text-sm",!N.enabled&&"text-muted-foreground line-through"),children:N.name}),e.jsx(te,{variant:"secondary",className:"shrink-0 text-[11px]",children:N.source}),e.jsx("span",{className:"min-w-0 truncate text-muted-foreground text-xs",children:N.description||N.path})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(us,{row:j.rows[N.id],pending:j.pending&&!j.rows[N.id]}),e.jsx(le,{checked:N.enabled,onCheckedChange:A=>n(N.id,{enabled:A})}),e.jsx(S,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity hover:text-destructive group-hover:opacity-100",onClick:()=>r(N.id),children:e.jsx(Me,{className:"h-3.5 w-3.5"})})]})]},N.id))})]}),e.jsx(Vn,{kind:"skill",open:x,onOpenChange:h})]})}const qr=[10,15,30,60,120,300];function If(){const{t}=z(),[s,n]=m.useState([]),[a,r]=m.useState(!1),[o,i]=m.useState(null),[d,u]=m.useState(""),[x,h]=m.useState(""),[l,f]=m.useState(""),[c,p]=m.useState(""),[g,w]=m.useState("key"),[k,j]=m.useState(""),[y,N]=m.useState(!1),[A,O]=m.useState(null),[I,L]=m.useState(null),[C,E]=m.useState(null),[M,V]=m.useState(null),[F,b]=m.useState(!1),B=m.useCallback(()=>{window.electronAPI.sshConnections.list().then(n)},[]);m.useEffect(()=>{B()},[B]);const K=()=>{i(null),u(""),h(""),f(""),p(""),w("key"),j(""),L(null),r(!0)},D=q=>{i(q),u(q.name),h(q.host),f(q.user??""),p(q.port?String(q.port):""),w(q.auth),j(""),L(null),r(!0)},$=async q=>{q.preventDefault(),N(!0),L(null);const Q=c.trim()?Number(c):void 0,_=await window.electronAPI.sshConnections.upsert({...o?{id:o.id}:{},name:d.trim(),host:x.trim(),...l.trim()?{user:l.trim()}:{},...Q&&Number.isInteger(Q)?{port:Q}:{},auth:g,...g==="password"&&k?{password:k}:{}});if(N(!1),!_.ok){L(_.error);return}r(!1),B()},Y=async q=>{const Q=await window.electronAPI.sshConnections.delete(q);if(!Q.ok){E(Q.error);return}E(null),B()},H=async(q,Q=!0)=>{O(q),E(null);const _=await window.electronAPI.sshConnections.test(q);if(O(null),!_.ok){const ne=s.find(P=>P.id===q),R=Od(_,ne);if(R&&Q){V({id:q,challenge:R});return}}E(_.ok?t("SSH connection succeeded"):_.error)},se=async()=>{if(!M)return;b(!0);const q=M.id,Q=await window.electronAPI.sshConnections.trustHost(q);if(b(!1),V(null),!Q.ok){E(Q.error||t("Could not save host key."));return}await H(q,!1)};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-end justify-between gap-4","data-settings-row":"ssh.root",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-lg font-medium",children:[t("SSH"),e.jsx(qe,{note:t("The file panel and terminal use the change right away. Agents in open sessions keep the previous connection settings.")})]}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:t("Saved hosts for remote projects. Passwords stay in the system keychain.")})]}),e.jsxs(S,{size:"sm",onClick:K,children:[e.jsx(Oe,{className:"h-4 w-4"}),t("Add connection")]})]}),C&&e.jsx("p",{className:"text-sm text-muted-foreground",children:C}),e.jsxs("ul",{className:"divide-y rounded-lg border",children:[s.length===0&&e.jsx("li",{className:"px-3 py-6 text-sm text-muted-foreground",children:t("No SSH connections yet")}),s.map(q=>e.jsxs("li",{className:"flex items-center gap-2 px-3 py-2","data-settings-row":`ssh.${q.id}`,children:[e.jsxs("button",{type:"button",className:"min-w-0 flex-1 text-left",onClick:()=>D(q),children:[e.jsx("div",{className:"truncate text-sm font-medium",children:q.name}),e.jsxs("div",{className:"truncate text-xs text-muted-foreground",children:[q.user?`${q.user}@`:"",q.host,q.port?`:${q.port}`:""," ·"," ",q.auth==="password"?t("Password"):t("Key / agent")]})]}),e.jsx(S,{size:"sm",variant:"outline",disabled:A===q.id,onClick:()=>{H(q.id)},children:A===q.id?e.jsx(Ae,{className:"h-4 w-4 animate-spin"}):t("Test")}),e.jsx(S,{size:"icon-sm",variant:"ghost",onClick:()=>{Y(q.id)},children:e.jsx(Me,{className:"h-4 w-4"})})]},q.id))]}),e.jsx(Af,{}),e.jsx(pe,{open:a,onOpenChange:r,children:e.jsx(fe,{className:"max-w-md",children:e.jsxs("form",{onSubmit:q=>{$(q)},className:"flex flex-col",children:[e.jsx(ge,{children:e.jsx(je,{children:t(o?"Edit SSH connection":"Add SSH connection")})}),e.jsxs(we,{className:"space-y-3",children:[e.jsxs(me,{children:[e.jsx(he,{children:t("Name")}),e.jsx(J,{value:d,onChange:q=>u(q.target.value),required:!0})]}),e.jsxs(me,{children:[e.jsx(he,{children:t("Host")}),e.jsx(J,{value:x,onChange:q=>h(q.target.value),placeholder:"example.com",required:!0})]}),e.jsxs(me,{children:[e.jsx(he,{children:t("User (optional)")}),e.jsx(J,{value:l,onChange:q=>f(q.target.value)})]}),e.jsxs(me,{children:[e.jsx(he,{children:t("Port (optional)")}),e.jsx(J,{value:c,onChange:q=>p(q.target.value),placeholder:"22"})]}),e.jsxs(me,{children:[e.jsx(he,{children:t("Authentication")}),e.jsxs(ae,{items:[{value:"key",label:t("Key / agent")},{value:"password",label:t("Password")}],value:g,onValueChange:q=>w(q),children:[e.jsx(re,{className:"w-full",children:e.jsx(oe,{})}),e.jsxs(ie,{zIndex:st.DROPDOWN_IN_MODAL,children:[e.jsx(ee,{value:"key",children:t("Key / agent")}),e.jsx(ee,{value:"password",children:t("Password")})]})]})]}),g==="password"&&e.jsxs(me,{children:[e.jsx(he,{children:o?.hasPassword?t("Password (leave blank to keep)"):t("Password")}),e.jsx(J,{type:"password",value:k,onChange:q=>j(q.target.value),required:!o?.hasPassword})]}),I&&e.jsx("p",{className:"text-sm text-destructive",children:I})]}),e.jsxs(Ie,{children:[e.jsx(S,{type:"button",variant:"outline",size:"sm",onClick:()=>r(!1),children:t("Cancel")}),e.jsx(S,{type:"submit",size:"sm",disabled:y,children:t("Save")})]})]})})}),e.jsx(Rd,{challenge:M?.challenge??null,busy:F,onTrust:()=>{se()},onDismiss:()=>!F&&V(null)})]})}function Af(){const{t}=z(),s=v(a=>a.sshTimeoutSeconds),n=v(a=>a.setSshTimeoutSeconds);return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"ssh.timeout",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("SSH timeout")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Time limit for connection tests, loading remote AGENTS.md, remote folder browsing and file panel actions. Agent tool commands are not affected.")})]}),e.jsxs(ae,{items:Object.fromEntries(qr.map(a=>[String(a),`${a}s`])),value:String(s),onValueChange:a=>n(Number(a)),children:[e.jsx(re,{className:"w-24",children:e.jsx(oe,{})}),e.jsx(ie,{children:qr.map(a=>e.jsx(ee,{value:String(a),children:`${a}s`},a))})]})]})}const Ef={memory:"memory",workflows:"workflow"},zi=["bots","botTemplates"],Mf=[{id:"app",label:"Application",categories:["general","appearance","shortcuts","voice","privacy"]},{id:"agent",label:"Models & agents",categories:["providers","presets","agents","instructions","memory"]},{id:"extensions",label:"Tools & extensions",categories:["tools","workflows","skills","mcp","plugins","claudePlugins"]},{id:"connections",label:"Connections",categories:["phone","ssh"]},{id:"system",label:"System",categories:["usage","resources","experimental","bots","botTemplates"]}];function Pf(t){const s=new Map(t.map(n=>[n.id,n]));return Mf.flatMap(n=>{const a=n.categories.flatMap(r=>{const o=s.get(r);return o?[o]:[]});return a.length>0?[{id:n.id,label:n.label,items:a}]:[]})}function _i(t,s,n=!1){if(zi.includes(t))return n;const a=Ef[t];return!a||!s.includes(a)}function Tf(t,s,n=!1){return t.filter(a=>_i(a.id,s,n))}function Rf(t,s,n=!1){return _i(t,s,n)?t:zi.includes(t)?"experimental":"tools"}function Of(t,s,n,a){const r=n.trim();if(!r)return t.map(u=>({...u,hits:[]}));const o=Dd([...s,...t.map(u=>({id:`${u.id}.root`,category:u.id,title:u.label}))],r,{translate:a,limit:Number.POSITIVE_INFINITY}),i=new Set,d=new Map;for(const u of o){if(i.add(u.category),u.id.endsWith(".root"))continue;const x=d.get(u.category);x?x.push(u):d.set(u.category,[u])}return t.flatMap(u=>i.has(u.id)?[{...u,hits:d.get(u.id)??[]}]:[])}const Df=[1,7,30,90],Gr=640,Qt=180,Hr=8,Wr=18,Lf=.3,zf=2;function _f(t){const[,s,n]=t.split("-");return`${Number(s)}/${Number(n)}`}const Bf=[{id:"cache",cls:"fill-foreground/15",swatch:"bg-foreground/15"},{id:"input",cls:"fill-foreground/45",swatch:"bg-foreground/45"},{id:"output",cls:"fill-foreground",swatch:"bg-foreground"}];function Ff({daily:t}){const{t:s}=z(),[n,a]=m.useState("tokens"),[r,o]=m.useState(null),[i,d]=m.useState({output:!0,input:!0,cache:!0}),u=j=>{d(y=>{const N={...y,[j]:!y[j]};return!N.output&&!N.input&&!N.cache?y:N})},x=t.map(j=>n==="cost"?j.cost??0:(i.output?j.output:0)+(i.input?j.input:0)+(i.cache?j.cache:0)),h=Math.max(0,...x),l=Math.max(1,t.length),f=Gr/l,c=Math.min(f*(1-Lf),64),p=Qt-Hr-Wr,g=j=>h>0?j/h*p:0,w=Math.max(1,Math.ceil(l/12)),k=r!==null?t[r]:null;return e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-sm font-medium",children:s("Daily trend")}),e.jsxs("div",{className:"flex items-center gap-3",children:[n==="tokens"&&e.jsxs("div",{className:"flex items-center gap-3 text-[11px] text-muted-foreground",children:[e.jsx(sn,{className:"bg-foreground",label:s("Output"),pressed:i.output,onClick:()=>u("output")}),e.jsx(sn,{className:"bg-foreground/45",label:s("Input"),pressed:i.input,onClick:()=>u("input")}),e.jsx(sn,{className:"bg-foreground/15",label:s("Cache"),pressed:i.cache,onClick:()=>u("cache")})]}),e.jsx(Uf,{value:n,onChange:a})]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"pointer-events-none absolute left-0 top-0 font-mono text-[10px] text-muted-foreground",children:n==="tokens"?$e(h):rs(h>0?h:null)}),k&&e.jsxs("div",{className:"pointer-events-none absolute right-0 top-0 rounded bg-popover px-2 py-1 font-mono text-[11px] text-popover-foreground shadow-sm ring-1 ring-border",children:[k.day,n==="tokens"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[s("Output")," ",$e(k.output)]}),e.jsxs("div",{children:[s("Input")," ",$e(k.input)]}),e.jsxs("div",{children:[s("Cache")," ",$e(k.cache)]})]}):e.jsxs(e.Fragment,{children:[" · ",rs(k.cost)]})]}),e.jsx("svg",{viewBox:`0 0 ${Gr} ${Qt}`,className:"mt-4 block h-[180px] w-full",role:"img","aria-label":s("Daily trend"),onMouseLeave:()=>o(null),children:t.map((j,y)=>{const N=y*f+(f-c)/2,A=Qt-Wr,O=n==="tokens"?Bf.filter(L=>i[L.id]).map(L=>({v:j[L.id],cls:L.cls})):[{v:j.cost??0,cls:"fill-emerald-600 dark:fill-emerald-500"}];let I=A;return e.jsxs("g",{onMouseEnter:()=>o(y),children:[e.jsx("rect",{x:N,y:Hr,width:c,height:p,className:"fill-transparent"}),O.map(L=>{const C=L.v>0?Math.max(zf,g(L.v)):0;return I-=C,e.jsx("rect",{x:N,y:I,width:c,height:C,rx:1,className:G(L.cls,r===y&&"opacity-80")},L.cls)}),y%w===0&&e.jsx("text",{x:N+c/2,y:Qt-4,textAnchor:"middle",className:"fill-muted-foreground font-mono text-[10px]",children:_f(j.day)})]},j.day)})})]})]})}function sn({className:t,label:s,pressed:n,onClick:a}){return e.jsxs("button",{type:"button","aria-pressed":n,onClick:a,className:G("flex items-center gap-1 rounded px-0.5 transition-opacity",n?"opacity-100":"opacity-40"),children:[e.jsx("span",{className:G("inline-block h-2.5 w-2.5 rounded-sm",t)}),s]})}function Uf({value:t,onChange:s}){const{t:n}=z(),a=[{id:"tokens",label:n("Token")},{id:"cost",label:n("Cost")}];return e.jsx("div",{className:"flex rounded-md bg-muted p-0.5",children:a.map(r=>e.jsx("button",{type:"button",onClick:()=>s(r.id),className:G("rounded px-2 py-0.5 text-[11px] transition-colors",t===r.id?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:r.label},r.id))})}const nn=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],Yr=Array.from({length:24},(t,s)=>String(s).padStart(2,"0")),is=["bg-foreground/[0.06]","bg-foreground/20","bg-foreground/40","bg-foreground/60","bg-foreground/80","bg-foreground"];function $f(t,s){return t<=0||s<=0?0:1+Math.min(is.length-2,Math.floor(t/s*(is.length-1)))}function Vf({heatmap:t}){const{t:s}=z(),n=Math.max(0,...t.flat());return e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[e.jsx("span",{className:"text-sm font-medium",children:s("Activity by hour")}),e.jsxs("div",{className:"flex items-center gap-1 text-[10px] text-muted-foreground",children:[e.jsx("span",{children:s("Less")}),is.map(a=>e.jsx("span",{className:G("inline-block h-2.5 w-2.5 rounded-[2px]",a)},a)),e.jsx("span",{children:s("More")})]})]}),e.jsxs("div",{className:"grid grid-cols-[28px_1fr] gap-x-2 gap-y-1",children:[t.map((a,r)=>e.jsxs("div",{className:"contents",children:[e.jsx("span",{className:"self-center text-[10px] text-muted-foreground",children:s(nn[r])}),e.jsx("div",{className:"grid grid-cols-24 gap-[3px]",children:Yr.map((o,i)=>e.jsx("span",{title:`${s(nn[r])} ${o}:00 · ${$e(a[i]??0)}`,className:G("aspect-square rounded-[2px]",is[$f(a[i]??0,n)])},o))})]},nn[r])),e.jsx("span",{}),e.jsx("div",{className:"grid grid-cols-24 font-mono text-[10px] text-muted-foreground",children:Yr.map((a,r)=>e.jsx("span",{className:G(r%3!==0&&"invisible"),children:a},a))})]})]})}function an({title:t,countLabel:s,rows:n,emptyLabel:a,limit:r=8}){const{t:o}=z(),[i,d]=m.useState(!1),u=n.reduce((l,f)=>l+f.tokens,0),x=n.length>r,h=x&&!i?n.slice(0,r):n;return e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[e.jsx("span",{className:"text-sm font-medium",children:t}),x&&e.jsx("span",{className:"text-[11px] text-muted-foreground",children:i?o("{{total}} items",{total:n.length}):o("Top {{count}} of {{total}}",{count:r,total:n.length})})]}),h.length===0?e.jsx("p",{className:"py-6 text-center text-xs text-muted-foreground",children:a}):e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-[11px] text-muted-foreground",children:[e.jsx("th",{className:"pb-2 text-left font-normal",children:o("Name")}),e.jsx("th",{className:"pb-2 text-right font-normal",children:o("Cost")}),e.jsx("th",{className:"pb-2 text-right font-normal",children:o("Token")}),e.jsx("th",{className:"pb-2 text-right font-normal",children:s})]})}),e.jsx("tbody",{children:h.map(l=>{const f=u>0?l.tokens/u:0;return e.jsxs("tr",{className:"border-t border-border/60",children:[e.jsxs("td",{className:"py-2 pr-3",children:[e.jsx("div",{className:"truncate",title:l.name,children:l.name||o("(no project)")}),e.jsx("div",{className:"mt-1 h-1 w-full rounded-full bg-foreground/[0.06]",children:e.jsx("div",{className:"h-1 rounded-full bg-foreground/70",style:{width:`${Math.max(1,f*100)}%`}})})]}),e.jsx("td",{className:G("py-2 text-right font-mono tabular-nums",l.cost===null&&"text-muted-foreground"),children:rs(l.cost)}),e.jsxs("td",{className:"py-2 text-right font-mono tabular-nums",children:[$e(l.tokens),e.jsxs("span",{className:"ml-1 text-muted-foreground",children:[(f*100).toFixed(0),"%"]})]}),e.jsx("td",{className:"py-2 text-right font-mono tabular-nums",children:l.count})]},l.key)})})]}),x&&e.jsx(S,{variant:"ghost",size:"xs",className:"mt-2 w-full text-muted-foreground",onClick:()=>d(l=>!l),children:o(i?"Collapse":"Show all")})]})}function Kf({value:t,className:s}){const n=t.split("");return e.jsx("span",{className:G("t-digit-group is-animating",s),children:n.map((a,r)=>e.jsx("span",{className:"t-digit","data-stagger":r===n.length-2?"1":r===n.length-1?"2":void 0,children:a},`${r}:${a}`))},t)}const qf={default:"text-foreground",success:"text-emerald-600 dark:text-emerald-400",info:"text-sky-600 dark:text-sky-400",muted:"text-muted-foreground"};function it({label:t,value:s,delta:n,tone:a="default"}){return e.jsxs("div",{className:"min-w-0 overflow-hidden rounded-lg border bg-card px-4 py-3",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[e.jsx("span",{className:"min-w-0 text-xs text-muted-foreground",children:t}),n&&e.jsx("span",{className:"shrink-0 font-mono text-[11px] tabular-nums text-muted-foreground",children:n})]}),e.jsx("div",{className:G("mt-1 truncate font-mono text-xl font-semibold leading-tight tabular-nums sm:text-2xl",qf[a]),title:s,children:e.jsx(Kf,{value:s})})]})}const rn={input:0,output:0,cacheRead:0,cacheWrite:0},ls=["input","output","cacheRead","cacheWrite"];function on(t){return{input:String(t.input),output:String(t.output),cacheRead:String(t.cacheRead),cacheWrite:String(t.cacheWrite)}}function Gf(t){return Bd({id:Object.fromEntries(ls.map(n=>[n,Number(t[n])]))}).id??null}function Hf(t){return t===void 0?"—":String(t)}function Jr({rows:t,editing:s,draft:n,overrides:a,onDraft:r,onEdit:o,onSave:i}){const{t:d}=z();return e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-[11px] text-muted-foreground",children:[e.jsx("th",{className:"pb-2 text-left font-normal",children:d("Name")}),ls.map(u=>e.jsx("th",{className:"pb-2 text-right font-normal",children:u},u)),e.jsx("th",{className:"w-14 pb-2"})]})}),e.jsx("tbody",{children:t.map(u=>{const x=s===u.model,h=u.model in a;return e.jsxs("tr",{className:"border-t border-border/60",children:[e.jsxs("td",{className:"py-1.5 pr-3 align-middle",children:[e.jsx("span",{className:"font-mono text-xs",title:u.model,children:u.model}),h&&e.jsx("span",{className:"ml-1.5 text-[10px] text-muted-foreground",children:d("Custom")})]}),ls.map(l=>e.jsx("td",{className:"py-1.5 text-right align-middle",children:x?e.jsx(J,{size:"sm",inputMode:"decimal",className:"ml-auto w-16 [&_input]:text-right",value:n[l],onChange:f=>r({...n,[l]:f.target.value})}):e.jsx("span",{className:G("font-mono tabular-nums",u.pricing==null&&"text-muted-foreground"),children:Hf(u.pricing?.[l])})},l)),e.jsx("td",{className:"py-1.5 text-right align-middle",children:x?e.jsx(S,{size:"sm",className:"h-6 px-1.5 text-[11px]",onClick:()=>i(u.model),children:d("Save")}):e.jsx(S,{variant:"ghost",size:"sm",className:"h-6 px-1.5 text-[11px]",onClick:()=>o(u.model,u.pricing),children:d("Edit")})})]},u.model)})})]})}function Wf({models:t,catalog:s,onChanged:n}){const{t:a}=z(),r=v(b=>b.usageModelPricing),o=$t(),i=v(b=>b.setUsageModelPricing),[d,u]=m.useState(!1),[x,h]=m.useState(!1),[l,f]=m.useState(null),[c,p]=m.useState(on(rn)),[g,w]=m.useState(null),[k,j]=m.useState(!1),[y,N]=m.useState(""),[A,O]=m.useState(""),I=new Set(t.map(b=>b.model)),L=new Set;for(const b of o)for(const B of b.models)L.add(B.id);for(const b of Object.keys(r))L.add(b);const C=A.trim().toLowerCase(),E=t.filter(b=>!C||b.model.toLowerCase().includes(C)).map(b=>({model:b.model,pricing:b.pricing})),M=[...L].filter(b=>!I.has(b)&&(!C||b.toLowerCase().includes(C))).sort().map(b=>({model:b,pricing:r[b]??s[b]??null})),V=(b,B)=>{j(!1),f(b),p(on(B??rn)),w(null)},F=b=>{const B=Gf(c);return!B||!i(b,B)?(w(a("Enter a model id and non-negative rates.")),!1):(w(null),f(null),j(!1),N(""),n(),!0)};return e.jsxs(Ld,{open:d,onOpenChange:u,className:"rounded-lg border bg-card",children:[e.jsxs(zd,{className:"flex w-full items-center justify-between gap-3 px-4 py-3 text-left",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-medium",children:a("Unit prices")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("Rates used for cost estimates ($/M tokens).")})]}),e.jsx(ns,{className:G("h-4 w-4 shrink-0 text-muted-foreground transition-transform",d&&"rotate-180")})]}),e.jsx(_d,{children:e.jsxs("div",{className:"space-y-3 border-t px-4 py-3",children:[e.jsx(J,{size:"sm",value:A,onChange:b=>O(b.target.value),placeholder:a("Search models")}),E.length===0&&!k?e.jsx("p",{className:"text-xs text-muted-foreground",children:a(C?"No matching models":"No usage in this period")}):e.jsx(Jr,{rows:E,editing:l,draft:c,overrides:r,onDraft:p,onEdit:V,onSave:F}),M.length>0&&(x||!!C)&&e.jsx(Jr,{rows:M,editing:l,draft:c,overrides:r,onDraft:p,onEdit:V,onSave:F}),k?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-end gap-2",children:[e.jsxs("label",{className:"grid min-w-36 gap-1 text-[11px] text-muted-foreground",children:[a("Model id"),e.jsx(J,{size:"sm",value:y,onChange:b=>N(b.target.value),placeholder:"qwen-3.8-27b"})]}),ls.map(b=>e.jsxs("label",{className:"grid min-w-16 gap-1 text-[11px] text-muted-foreground",children:[b,e.jsx(J,{size:"sm",inputMode:"decimal",value:c[b],onChange:B=>p(K=>({...K,[b]:B.target.value}))})]},b))]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(S,{size:"sm",className:"h-7",onClick:()=>F(y),children:a("Save")}),e.jsx(S,{variant:"ghost",size:"sm",className:"h-7",onClick:()=>{j(!1),N(""),w(null)},children:a("Cancel")})]})]}):e.jsxs("div",{className:"flex justify-end gap-2",children:[M.length>0&&e.jsxs(S,{variant:"ghost",size:"sm",className:"h-7 text-muted-foreground",onClick:()=>h(b=>!b),children:[a("Show all"),e.jsx(ns,{className:G("ml-1 h-3.5 w-3.5 transition-transform",x&&"rotate-180")})]}),e.jsx(S,{variant:"ghost",size:"sm",className:"h-7",onClick:()=>{j(!0),p(on(rn)),w(null)},children:a("Add")})]}),g&&e.jsx("p",{className:"text-xs text-destructive",children:g})]})})]})}const Yf={1:"Today",7:"7D",30:"30D",90:"90D"};function Jf(){const{t}=z(),[s,n]=m.useState(7),[a,r]=m.useState(null),o=v(p=>p.botModeEnabled),[i,d]=m.useState(null),[u,x]=m.useState(null),[h,l]=m.useState(!1),f=m.useRef(0),c=m.useCallback(async p=>{const g=++f.current;l(!0);const[w,k]=await Promise.all([window.electronAPI.usage.summary(p),o?window.electronAPI.bots.usageSummary(p).catch(()=>null):null]);g===f.current&&(l(!1),d(k?.ok?k.rows:null),w.ok?(r(w.summary),x(null)):(r(null),x(w.error)))},[o]);return m.useEffect(()=>{c(s)},[s,c]),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:t("Usage")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("Token usage across all local sessions; cost is estimated from catalog prices.")})]}),e.jsx(S,{variant:"ghost",size:"icon-sm",onClick:()=>{c(s)},disabled:h,"aria-label":t("Refresh"),children:e.jsx(Je,{className:G(h&&"animate-spin")})})]}),e.jsx(Qf,{value:s,onChange:n}),u&&e.jsx("p",{className:"text-sm text-destructive",children:u}),a&&e.jsxs(e.Fragment,{children:[e.jsx(Xf,{totals:a.totals,previous:a.previous}),e.jsx(Ff,{daily:a.daily}),e.jsx(Vf,{heatmap:a.heatmap}),e.jsxs("div",{className:"grid gap-4 xl:grid-cols-2",children:[e.jsx(an,{title:t("By model"),countLabel:t("Messages"),emptyLabel:t("No usage in this period"),rows:a.byModel.map(p=>({key:p.model,name:p.model,cost:p.cost,tokens:p.tokens,count:p.messages}))}),e.jsx(an,{title:t("By project"),countLabel:t("Sessions"),emptyLabel:t("No usage in this period"),rows:a.byProject.map(p=>({key:p.project||"#",name:p.project,cost:p.cost,tokens:p.tokens,count:p.sessions}))})]}),o&&i&&e.jsx(an,{title:t("By member"),countLabel:t("Sessions"),emptyLabel:t("No usage in this period"),rows:i.map(p=>({key:p.botId,name:p.name||t("Deleted member"),cost:p.cost,tokens:p.tokens,count:p.sessions}))}),a.unpricedModels.length>0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:t("No catalog price for: {{models}}. Their cost is not included.",{models:a.unpricedModels.join(", ")})})]}),e.jsx(Wf,{models:a?.byModel??[],catalog:a?.pricing??{},onChanged:()=>{c(s)}})]})}function Qf({value:t,onChange:s}){const{t:n}=z();return e.jsx("div",{className:"flex items-center gap-1.5",children:Df.map(a=>e.jsx("button",{type:"button",onClick:()=>s(a),className:G("rounded-full px-3 py-1 font-mono text-xs transition-colors",t===a?"bg-foreground text-background":"bg-muted text-muted-foreground hover:text-foreground"),children:n(Yf[a])},a))})}function Xf({totals:t,previous:s}){const{t:n}=z(),a=t.cacheRead+t.cacheWrite,r=s.cacheRead+s.cacheWrite;return e.jsxs("div",{className:"grid grid-cols-2 gap-3 md:grid-cols-4",children:[e.jsx(it,{label:n("Estimated cost"),value:rs(t.cost),delta:at(s.cost,t.cost),tone:"success"}),e.jsx(it,{label:n("Total tokens"),value:$e(t.tokens),delta:at(s.tokens,t.tokens)}),e.jsx(it,{label:n("Input tokens"),value:$e(t.input),delta:at(s.input,t.input)}),e.jsx(it,{label:n("Output tokens"),value:$e(t.output),delta:at(s.output,t.output)}),e.jsx(it,{label:n("Cache tokens"),value:$e(a),delta:at(r,a),tone:"muted"}),e.jsx(it,{label:n("Active time"),value:Fd(t.activeMs),delta:at(s.activeMs,t.activeMs),tone:"info"}),e.jsx(it,{label:n("Sessions"),value:String(t.sessions),delta:at(s.sessions,t.sessions)}),e.jsx(it,{label:n("Messages"),value:t.messages.toLocaleString(),delta:at(s.messages,t.messages)})]})}const Qr={"x-asr-streaming":{name:"X-ASR Streaming",description:"Text appears while you speak. Chinese and English."},"x-asr":{name:"X-ASR",description:"Most accurate on everyday speech. Chinese and English."},"qwen3-asr":{name:"Qwen3-ASR 0.6B",description:"Best with mixed Chinese-English and code terms. Slower and uses more memory."},"sense-voice":{name:"SenseVoice",description:"Chinese, English, Japanese, Korean and Cantonese."},hanbao:{name:"Hanbao",description:"Runs fully offline. Chinese and English."},"gemini-live":{name:"Gemini Transcribe Live",description:"Google cloud recognition, most accurate with mixed Chinese-English and code terms. Needs a Gemini API key."},wetype:{name:"WeType",description:"WeChat Keyboard cloud recognition. Chinese and English, no setup needed."}};function Bi({state:t,onDownload:s,onCancel:n,onRemove:a}){const{t:r}=z();return t==="unavailable"?null:t==="downloading"?e.jsx(S,{variant:"outline",size:"sm",onClick:n,children:r("Cancel")}):t==="ready"?e.jsx(S,{variant:"ghost",size:"sm",onClick:a,children:r("Remove")}):e.jsx(S,{variant:"outline",size:"sm",onClick:s,children:r("Download")})}function Zf(){const{t}=z(),s=v(h=>h.voiceModel),n=v(h=>h.setVoiceModel),{status:a,progress:r,error:o,refresh:i}=Ud();if(!a)return null;if(a.state==="unsupported")return e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Voice input is not available on this platform.")});const d=window.electronAPI.speech,u=h=>{const l=r[h.id];return l?`${l.file} · ${de(l.received)}${l.total?` / ${de(l.total)}`:""} (${l.fileIndex+1}/${l.fileCount})`:o?.modelId===h.id?`${t("Download failed")}: ${o.message}`:h.id==="wetype"?t("Audio is uploaded to Tencent WeChat Keyboard servers."):h.remote?h.state==="ready"?t("Audio is uploaded to Google. On the free tier Google may use it to improve its products."):t("Enter a Gemini API key below first."):t("Download {{size}} · Memory about {{memory}}",{size:de(h.approxBytes),memory:de(h.memoryBytes)})},x=a.models.find(h=>h.id===s);return e.jsxs("div",{className:"space-y-1.5","data-settings-row":"tools.voiceModel",children:[e.jsx("p",{className:"text-sm",children:t("Speech model")}),e.jsx("div",{role:"radiogroup",className:"divide-y rounded-md border",children:a.models.map(h=>{const l=h.id===s;return e.jsxs("div",{className:G("flex items-center gap-3 px-3 py-2",l&&"bg-accent/40"),children:[e.jsxs("button",{type:"button",role:"radio","aria-checked":l,onClick:()=>n(h.id),className:"flex min-w-0 flex-1 items-start gap-2.5 text-left",children:[e.jsx("span",{className:G("mt-1 flex size-3.5 shrink-0 items-center justify-center rounded-full border",l&&"border-primary"),children:l?e.jsx("span",{className:"size-2 rounded-full bg-primary"}):null}),e.jsxs("span",{className:"min-w-0",children:[e.jsxs("span",{className:"flex flex-wrap items-center gap-1.5 text-sm",children:[t(Qr[h.id].name),h.remote?e.jsx(te,{variant:"warning",size:"sm",children:t("Cloud")}):null,e.jsx(te,{variant:h.streaming?"info":"secondary",size:"sm",children:h.streaming?t("Streaming"):t("Sentence by sentence")}),h.state==="ready"&&!h.remote?e.jsx(te,{variant:"success",size:"sm",children:t("Downloaded")}):null]}),e.jsx("span",{className:"block text-muted-foreground text-xs",children:t(Qr[h.id].description)}),e.jsx("span",{className:G("block text-xs",o?.modelId===h.id?"text-destructive":h.remote?"text-warning":"text-muted-foreground"),children:u(h)})]})]}),e.jsx(Bi,{state:h.remote?"unavailable":h.state,onDownload:()=>{n(h.id),d.download(h.id).then(i)},onCancel:()=>{d.cancelDownload(h.id).then(i)},onRemove:()=>{d.remove(h.id).then(i)}})]},h.id)})}),a.state!=="ready"&&a.state!=="downloading"&&!x?.remote?e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Download the selected model to start using voice input.")}):null,x?.id==="gemini-live"?e.jsxs(e.Fragment,{children:[e.jsx(eg,{}),e.jsx(tg,{})]}):null]})}function eg(){const{t}=z(),s=v(a=>a.voiceGeminiApiKey),n=v(a=>a.setVoiceGeminiApiKey);return e.jsxs("div",{className:"space-y-1.5 pt-2","data-settings-row":"voice.geminiApiKey",children:[e.jsx("p",{className:"text-sm",children:t("Gemini API key")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Create one for free in Google AI Studio.")}),e.jsx(J,{type:"password",autoComplete:"off",spellCheck:!1,value:s,onChange:a=>n(a.target.value),placeholder:"AIza…",className:"font-mono"})]})}function tg(){const{t}=z(),s=v(a=>a.voiceVocabulary),n=v(a=>a.setVoiceVocabulary);return e.jsxs("div",{className:"space-y-1.5 pt-2","data-settings-row":"voice.vocabulary",children:[e.jsx("p",{className:"text-sm",children:t("Custom vocabulary")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("One term per line, up to 100. Helps with names and code terms such as useEffect or pnpm.")}),e.jsx(He,{size:"sm",value:s,onChange:a=>n(a.target.value),placeholder:`useEffect
29
29
  pnpm
30
- TypeScript`,className:"font-mono"})]})}function eg(){const{t}=z(),s=v(j=>j.voiceCorrectionEnabled),n=v(j=>j.setVoiceCorrectionEnabled),a=v(j=>j.voiceCorrectionModel)||"remote",r=v(j=>j.setVoiceCorrectionModel),o=v(j=>j.voiceCorrectionRemoteModel),i=v(j=>j.setVoiceCorrectionRemoteModel),d=Xe(),[u,x]=m.useState([]),[h,l]=m.useState(null),f=m.useCallback(()=>{window.electronAPI.memory.chatModels().then(x)},[]);m.useEffect(()=>(f(),window.electronAPI.memory.onChatModelProgress(j=>{l(j.done?null:j),j.done&&f()})),[f]);const c=u.find(j=>j.id===a)??null,p=u.map(j=>({value:j.id,label:j.id==="remote"?t("Remote (API model)"):`${j.label}${j.purpose?` · ${t("tuned for voice")}`:""} · ${de(j.approxBytes)}`})),g=o?d.find(j=>j.id===o.providerId):void 0,w=g?.models.find(j=>j.id===o?.modelId),k=window.electronAPI.memory;return e.jsxs("div",{className:"space-y-2","data-settings-row":"tools.voiceCorrection",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Correct with a language model")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Fixes homophones, code terms and number formats after recognition. Adds about 1-3 seconds; the raw text is kept if it fails.")})]}),e.jsx(le,{checked:s,onCheckedChange:n})]}),s?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:"text-sm",children:t("Correction model")}),e.jsxs(ae,{value:a,items:p,onValueChange:j=>r(String(j)),children:[e.jsx(re,{className:"w-64",children:e.jsx(oe,{})}),e.jsx(ie,{children:p.map(j=>e.jsx(ee,{value:j.value,children:j.label},j.value))})]})]}),c?.downloadable?e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:G("text-xs",c.state==="missing"?"text-destructive":"text-muted-foreground"),children:h?.modelId===c.id?`${de(h.received)}${h.total?` / ${de(h.total)}`:""}`:c.state==="ready"?t("Model downloaded"):c.state==="downloading"?t("Downloading…"):t("Not downloaded yet. Correction is skipped until it is.")}),e.jsx(_i,{state:c.state,onDownload:()=>{k.downloadChatModel(c.id).then(f)},onCancel:()=>{k.cancelChatModelDownload(c.id).then(f)},onRemove:()=>{k.deleteChatModel(c.id).then(f)}})]}):null,a==="remote"&&d.length>0?e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:t("A fast, inexpensive model is enough.")}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[o?e.jsx(S,{variant:"ghost",size:"sm",onClick:()=>i(null),children:t("Reset")}):null,e.jsx("div",{className:"w-56",children:e.jsx(ze,{providers:d,providerId:g?.id??"",modelId:w?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:t("Follows the title-summary model"),side:"bottom",triggerClassName:Ye,onSelect:(j,y)=>i({providerId:j,modelId:y}),onReasoningChange:()=>{},onThinkingChange:()=>{}})})]})]}):null]}):null]})}function tg(){const{t}=z(),s=v(a=>a.voiceInputEnabled),n=v(a=>a.setVoiceInputEnabled);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4","data-settings-row":"voice.root",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-medium text-lg",children:t("Voice input")}),e.jsx("p",{className:"text-muted-foreground text-sm",children:t("Adds a microphone to the composer on this computer and on paired phones. Local models transcribe speech on this computer.")})]}),e.jsx(le,{checked:s,onCheckedChange:n,"aria-label":t("Voice input"),className:"mt-1 shrink-0"})]}),s?e.jsxs(e.Fragment,{children:[e.jsx(ng,{}),e.jsx(Qf,{}),e.jsx(eg,{})]}):null]})}function sg(){const[t,s]=m.useState([]);return m.useEffect(()=>{const n=navigator.mediaDevices;if(!n?.enumerateDevices)return;let a=!0;const r=()=>{n.enumerateDevices().then(o=>{a&&s(o.filter(i=>i.kind==="audioinput"&&i.deviceId!==ti&&i.deviceId!=="communications"))})};return r(),n.addEventListener("devicechange",r),()=>{a=!1,n.removeEventListener("devicechange",r)}},[]),t}function ng(){const{t}=z(),s=v(o=>o.voiceInputDevice),n=v(o=>o.setVoiceInputDevice),a=sg(),r=[{value:ti,label:t("System default")},...a.map((o,i)=>({value:o.deviceId,label:o.label||t("Microphone {{n}}",{n:i+1})}))];return r.some(o=>o.value===s)||r.push({value:s,label:t("Disconnected, using the system default")}),e.jsxs("div",{className:"flex items-center justify-between gap-3","data-settings-row":"voice.microphone",children:[e.jsx("p",{className:"text-sm",children:t("Microphone")}),e.jsxs(ae,{value:s,items:r,onValueChange:o=>n(String(o)),children:[e.jsx(re,{className:"w-64",children:e.jsx(oe,{})}),e.jsx(ie,{children:r.map(o=>e.jsx(ee,{value:o.value,children:o.label},o.value))})]})]})}const ag=32,rg=/^[A-Za-z0-9][A-Za-z0-9_:-]{0,127}$/,og=/^[A-Za-z_][A-Za-z0-9_]{0,31}$/,ig=/\{\{\s*(?:args\.([A-Za-z_][A-Za-z0-9_]{0,31})|(prev))\s*\}\}/g;function Nn(t,s){if(typeof t!="string")return null;const n=t.trim();return n&&n.length<=s?n:null}function lg(t,s){const n=[...new Set(t)].filter(a=>og.test(a)).map(a=>({kind:"arg",key:a,token:`{{args.${a}}}`}));return s>0&&n.push({kind:"prev",token:"{{prev}}"}),n}function cg(t,s,n,a){const r=Math.min(Math.max(s,0),t.length),o=Math.min(Math.max(n,r),t.length);return{text:t.slice(0,r)+a+t.slice(o),cursor:r+a.length}}function dg(t){if(!t||typeof t!="object"||Array.isArray(t))return null;const s=t,n=Nn(s.label,80),a=Nn(s.prompt,8e3),r=typeof s.agentType=="string"?s.agentType.trim():"";return!n||!a||r&&!rg.test(r)?null:{label:n,agentType:r,prompt:a}}function ug(t){if(!t||typeof t!="object"||Array.isArray(t))return null;const s=t,n=Nn(s.title,80);if(!n||!Array.isArray(s.steps)||s.steps.length===0)return null;const a=s.steps.map(dg);return a.every(r=>r!==null)?{title:n,steps:a}:null}function mg(t){if(!t||typeof t!="object"||Array.isArray(t))return null;const s=t.phases;if(!Array.isArray(s)||s.length===0)return null;const n=s.map(ug);return n.every(r=>r!==null)&&n.reduce((r,o)=>r+o.steps.length,0)<=ag?{phases:n}:null}function Fi(t){const s=[];let n=0;for(const a of t.matchAll(ig))a.index>n&&s.push({kind:"text",text:t.slice(n,a.index)}),s.push(a[1]?{kind:"arg",key:a[1]}:{kind:"prev"}),n=a.index+a[0].length;return n<t.length&&s.push({kind:"text",text:t.slice(n)}),s}function hg(t){const s=Fi(t).map(n=>n.kind==="text"?JSON.stringify(n.text):n.kind==="arg"?`String(args.${n.key} ?? '')`:"prev");return s.length>0?s.join(" + "):'""'}function xg({label:t,agentType:s,prompt:n}){const a=[`label: ${JSON.stringify(t)}`];return s&&a.push(`agentType: ${JSON.stringify(s)}`),` () => agent(${hg(n)}, { ${a.join(", ")} }),`}function Ui(t){const s=["// Generated by the workflow designer. Editing this code detaches it from the designer.","const collect = (labels, outputs) =>"," labels.map((label, i) => '## ' + label + '\\n\\n' + (outputs[i] ?? '(failed)')).join('\\n\\n');","let prev = '';"];for(const n of t.phases){const a=JSON.stringify(n.steps.map(r=>r.label));s.push("",`await phase(${JSON.stringify(n.title)});`,`prev = collect(${a}, await parallel([`,...n.steps.map(xg),"]));")}return s.push("","return prev;",""),s.join(`
31
- `)}async function pg(t){const[s,n,a]=await Promise.all([es(()=>import("./standalone-oyxre9MX.js"),[],import.meta.url),es(()=>import("./babel-BktJt1uC.js"),[],import.meta.url),es(()=>import("./estree-C_HWBWad.js"),[],import.meta.url)]);try{return{ok:!0,code:await s.format(t,{parser:"babel",plugins:[n,a],singleQuote:!0,printWidth:100,trailingComma:"es5"})}}catch(r){const o=r instanceof Error?r.message:String(r);return{ok:!1,error:o.split(`
32
- `)[0]??o}}}const fg=32,Bt=(t,s)=>Math.max(0,Math.min(t,s));function gg(t){return t.phases.reduce((s,n)=>s+n.steps.length,0)<fg}function jg(t,s,n){const a=t.phases.map((r,o)=>o===s?{...r,steps:[...r.steps,n]}:r);return{design:{phases:a},selection:{kind:"step",phase:s,step:(a[s]?.steps.length??1)-1}}}function vg(t,s,n){const a=Bt(s,t.phases.length),r=[...t.phases];return r.splice(a,0,n),{design:{phases:r},selection:{kind:"phase",phase:a}}}function Xr(t,s){const n=t.phases[s.phase];if(!n)return null;if(s.kind==="step"&&n.steps.length>1){const r=n.steps.filter((o,i)=>i!==s.step);return{design:{phases:t.phases.map((o,i)=>i===s.phase?{...o,steps:r}:o)},selection:{kind:"step",phase:s.phase,step:Bt(s.step,r.length-1)}}}if(t.phases.length===1)return null;const a=t.phases.filter((r,o)=>o!==s.phase);return{design:{phases:a},selection:{kind:"phase",phase:Bt(s.phase,a.length-1)}}}function Zr(t,s,n){const a=s+n;if(a<0||a>=t.phases.length||!t.phases[s])return{design:t,selection:{kind:"phase",phase:s}};const r=[...t.phases],[o]=r.splice(s,1);return o&&r.splice(a,0,o),{design:{phases:r},selection:{kind:"phase",phase:a}}}function bg(t,s){const n=Bt(s.phase,t.phases.length-1);if(s.kind==="phase")return{kind:"phase",phase:n};const a=t.phases[n]?.steps.length??1;return{kind:"step",phase:n,step:Bt(s.step,a-1)}}const ln="__default__",eo=(t="scout")=>({label:"",agentType:t,prompt:""});function yg({value:t,tokens:s,args:n,onChange:a}){const{t:r}=z(),o=m.useRef(null),i=()=>o.current?.querySelector("textarea")??null,d=x=>{const h=i(),l=t.length,f=cg(t,h?.selectionStart??l,h?.selectionEnd??l,x);a(f.text),requestAnimationFrame(()=>{h?.focus(),h?.setSelectionRange(f.cursor,f.cursor)})},u=x=>x.kind==="prev"?r("Previous phase output"):n.find(h=>h.key.trim()===x.key)?.label.trim()||x.key;return e.jsxs("div",{ref:o,className:"space-y-1",children:[e.jsx(He,{rows:5,className:"text-xs",placeholder:r("Prompt"),value:t,onChange:x=>a(x.target.value)}),e.jsxs(Jo,{children:[e.jsxs(Qo,{disabled:s.length===0,className:"inline-flex h-6 items-center gap-1 rounded-md px-1.5 text-muted-foreground text-xs hover:bg-accent hover:text-foreground disabled:pointer-events-none disabled:opacity-50",children:[e.jsx(Kd,{className:"h-3.5 w-3.5"}),r("Insert argument")]}),e.jsx(Xo,{align:"start",zIndex:st.DROPDOWN_IN_MODAL,finalFocus:i,children:s.map(x=>e.jsxs(Zo,{onClick:()=>d(x.token),children:[u(x),e.jsx("span",{className:"ml-auto pl-4 font-mono text-muted-foreground text-xs",children:x.token})]},x.token))})]})]})}const to=(t,s,n,a)=>{const r=Math.max((n-t)/2,8);return`M${t},${s} C${t+r},${s} ${n-r},${a} ${n},${a}`};function wg(t,s){const[n,a]=m.useState([]);return m.useLayoutEffect(()=>{const r=t.current;if(!r)return;const o=()=>{const d=r.getBoundingClientRect(),u=r.offsetWidth?d.width/r.offsetWidth:1,x=f=>{const c=r.querySelector(f)?.getBoundingClientRect();return c?{left:(c.left-d.left)/u,right:(c.right-d.left)/u,y:(c.top-d.top+c.height/2)/u}:null},h=(f,c)=>f<0||f>=s.phases.length?[`[data-node="${c}"]`]:(s.phases[f]?.steps??[]).map((p,g)=>`[data-node="s-${f}-${g}"]`),l=[];for(let f=0;f<=s.phases.length;f++){const c=x(`[data-gap="${f}"]`);if(c){for(const p of h(f-1,"start")){const g=x(p);g&&l.push({d:to(g.right,g.y,c.left,c.y),arrow:!1})}for(const p of h(f,"end")){const g=x(p);g&&l.push({d:to(c.right,c.y,g.left-2,g.y),arrow:!0})}}}a(l)};o();const i=new ResizeObserver(o);return i.observe(r),()=>i.disconnect()},[t,s]),n}function so({node:t,icon:s,title:n,detail:a}){return e.jsxs("div",{"data-node":t,className:"flex w-24 shrink-0 flex-col items-center gap-0.5 rounded-full border bg-background px-3 py-1.5 text-center shadow-xs",children:[e.jsxs("span",{className:"flex items-center gap-1 font-medium text-xs",children:[s,n]}),e.jsx("span",{className:"w-full truncate text-[10px] text-muted-foreground",children:a})]})}function Ng({prompt:t,args:s}){const{t:n}=z(),a=Fi(t.trim());return a.length===0?e.jsx(e.Fragment,{children:n("No prompt yet")}):e.jsx(e.Fragment,{children:a.map((r,o)=>r.kind==="text"?e.jsx(m.Fragment,{children:r.text},o):e.jsx("span",{className:"rounded bg-primary/10 px-1 font-medium text-primary",children:r.kind==="prev"?n("Previous phase output"):s.find(i=>i.key.trim()===r.key)?.label.trim()||r.key},o))})}function kg({design:t,agentTypes:s,args:n,onChange:a}){const{t:r}=z(),[o,i]=m.useState({kind:"step",phase:0,step:0}),d=m.useRef(null),u=m.useId(),x=wg(d,t),h=t.phases,l=bg(t,o),f=h[l.phase],c=l.kind==="step"?f?.steps[l.step]:void 0,p=s.includes("scout")?"scout":"",g=n.map(I=>I.key.trim()).filter(Boolean),w=gg(t),k=Xr(t,l)!==null,j=I=>{I&&(a(I.design),i(I.selection))},y=I=>a({phases:h.map((L,C)=>C===l.phase?{...L,...I}:L)}),N=I=>l.kind==="step"&&y({steps:(f?.steps??[]).map((L,C)=>C===l.step?{...L,...I}:L)}),A=I=>{const L=I&&!s.includes(I)?[...s,I]:s;return[{value:ln,label:r("Default (worker)")},...L.map(C=>({value:C,label:C}))]},O=I=>e.jsx("div",{className:"flex w-10 shrink-0 items-center justify-center self-stretch",children:e.jsx("button",{type:"button","data-gap":I,disabled:!w,"aria-label":r("Insert phase here"),title:r("Insert phase here"),onClick:()=>j(vg(t,I,{title:"",steps:[eo(p)]})),className:"relative z-30 flex h-5 w-5 items-center justify-center rounded-full border bg-background text-muted-foreground transition-colors hover:border-primary hover:text-primary disabled:pointer-events-none disabled:opacity-50",children:e.jsx(Oe,{className:"h-3 w-3"})})});return e.jsxs("div",{className:"w-full space-y-2",children:[e.jsx("div",{className:"overflow-x-auto rounded-lg border bg-muted/30",children:e.jsxs("div",{ref:d,className:"relative flex w-max min-w-full items-center justify-center px-3 py-5",children:[e.jsxs("svg",{"aria-hidden":!0,className:"pointer-events-none absolute inset-0 z-20 h-full w-full overflow-visible text-muted-foreground/50",children:[e.jsx("defs",{children:e.jsx("marker",{id:u,viewBox:"0 0 6 6",refX:"5",refY:"3",markerWidth:"6",markerHeight:"6",orient:"auto",children:e.jsx("path",{d:"M0,0 L6,3 L0,6 z",fill:"currentColor"})})}),x.map(I=>e.jsx("path",{d:I.d,fill:"none",stroke:"currentColor",strokeWidth:1.25,markerEnd:I.arrow?`url(#${u})`:void 0},I.d))]}),e.jsx(so,{node:"start",icon:e.jsx($d,{className:"h-3 w-3"}),title:r("Start"),detail:g.length>0?g.join(", "):r("No arguments")}),h.map((I,L)=>e.jsxs(m.Fragment,{children:[O(L),e.jsxs("div",{className:G("flex w-44 shrink-0 flex-col gap-1.5 rounded-xl border border-dashed bg-background/60 p-2",l.kind==="phase"&&l.phase===L&&"border-primary border-solid"),children:[e.jsxs("button",{type:"button",onClick:()=>i({kind:"phase",phase:L}),className:G("flex min-w-0 items-center gap-1 rounded px-1 text-left text-[11px] hover:text-foreground",I.title.trim()?"text-muted-foreground":"text-destructive"),children:[e.jsx("span",{className:"shrink-0",children:r("Phase {{n}}",{n:L+1})}),e.jsx("span",{className:"truncate font-medium text-foreground",children:I.title.trim()||r("Untitled phase")})]}),I.steps.map((C,E)=>{const M=l.kind==="step"&&l.phase===L&&l.step===E,V=!C.label.trim()||!C.prompt.trim();return e.jsxs("button",{type:"button","data-node":`s-${L}-${E}`,onClick:()=>i({kind:"step",phase:L,step:E}),className:G("block w-full rounded-lg border bg-background px-2.5 py-1.5 text-left shadow-xs transition-colors hover:border-primary/60",M&&"border-primary ring-2 ring-primary/20",V&&!M&&"border-destructive/50"),children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"truncate font-medium text-xs",children:C.label.trim()||r("Untitled step")}),e.jsx("span",{className:"ml-auto shrink-0 rounded bg-muted px-1 text-[10px] text-muted-foreground",children:C.agentType||"worker"})]}),e.jsx("span",{className:"mt-0.5 line-clamp-2 break-words text-[11px] text-muted-foreground",children:e.jsx(Ng,{prompt:C.prompt,args:n})})]},E)}),e.jsxs("button",{type:"button",disabled:!w,onClick:()=>j(jg(t,L,eo(p))),className:"flex items-center justify-center gap-1 rounded-lg border border-dashed py-1 text-[11px] text-muted-foreground transition-colors hover:border-primary hover:text-primary disabled:pointer-events-none disabled:opacity-50",children:[e.jsx(Oe,{className:"h-3 w-3"}),r("Parallel step")]})]})]},L)),O(h.length),e.jsx(so,{node:"end",icon:e.jsx(Eu,{className:"h-3 w-3"}),title:r("Result"),detail:r("Last phase output")})]})}),e.jsxs("div",{className:"space-y-2 rounded-lg border p-3",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"font-medium text-xs",children:l.kind==="phase"?r("Phase {{n}}",{n:l.phase+1}):r("Phase {{n}} · Step {{m}}",{n:l.phase+1,m:l.step+1})}),e.jsxs("span",{className:"ml-auto flex items-center",children:[l.kind==="phase"&&e.jsxs(e.Fragment,{children:[e.jsx(S,{variant:"ghost",size:"icon-xs","aria-label":r("Move left"),disabled:l.phase===0,onClick:()=>j(Zr(t,l.phase,-1)),children:e.jsx(Uo,{})}),e.jsx(S,{variant:"ghost",size:"icon-xs","aria-label":r("Move right"),disabled:l.phase===h.length-1,onClick:()=>j(Zr(t,l.phase,1)),children:e.jsx(Vd,{})})]}),e.jsx(S,{variant:"ghost",size:"icon-xs","aria-label":r("Delete"),disabled:!k,onClick:()=>j(Xr(t,l)),children:e.jsx(Me,{})})]})]}),l.kind==="phase"||!c?e.jsx(J,{size:"sm",placeholder:r("Phase title"),value:f?.title??"",onChange:I=>y({title:I.target.value})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(J,{size:"sm",className:"min-w-0 flex-1",placeholder:r("Label"),value:c.label,onChange:I=>N({label:I.target.value})}),e.jsxs(ae,{items:A(c.agentType),value:c.agentType||ln,onValueChange:I=>N({agentType:I===ln?"":String(I??"")}),children:[e.jsx(re,{size:"sm",className:"w-36 min-w-0 shrink-0",children:e.jsx(oe,{})}),e.jsx(ie,{zIndex:st.DROPDOWN_IN_MODAL,children:A(c.agentType).map(I=>e.jsx(ee,{value:I.value,children:I.label},I.value))})]})]}),e.jsx(yg,{value:c.prompt,tokens:lg(g,l.phase),args:n,onChange:I=>N({prompt:I})})]})]}),e.jsx("p",{className:"text-muted-foreground text-xs",children:r("Click a node to edit it. Steps in a column run in parallel; columns run from left to right.")})]})}const kn={phases:[{title:"Investigate",steps:[{label:"code",agentType:"scout",prompt:"Investigate {{args.topic}} in the source code."},{label:"tests",agentType:"scout",prompt:"Investigate {{args.topic}} in the tests."}]},{title:"Summarize",steps:[{label:"summary",agentType:"scout",prompt:`Merge these findings about {{args.topic}} into one short report:
30
+ TypeScript`,className:"font-mono"})]})}function sg(){const{t}=z(),s=v(j=>j.voiceCorrectionEnabled),n=v(j=>j.setVoiceCorrectionEnabled),a=v(j=>j.voiceCorrectionModel)||"remote",r=v(j=>j.setVoiceCorrectionModel),o=v(j=>j.voiceCorrectionRemoteModel),i=v(j=>j.setVoiceCorrectionRemoteModel),d=Xe(),[u,x]=m.useState([]),[h,l]=m.useState(null),f=m.useCallback(()=>{window.electronAPI.memory.chatModels().then(x)},[]);m.useEffect(()=>(f(),window.electronAPI.memory.onChatModelProgress(j=>{l(j.done?null:j),j.done&&f()})),[f]);const c=u.find(j=>j.id===a)??null,p=u.map(j=>({value:j.id,label:j.id==="remote"?t("Remote (API model)"):`${j.label}${j.purpose?` · ${t("tuned for voice")}`:""} · ${de(j.approxBytes)}`})),g=o?d.find(j=>j.id===o.providerId):void 0,w=g?.models.find(j=>j.id===o?.modelId),k=window.electronAPI.memory;return e.jsxs("div",{className:"space-y-2","data-settings-row":"tools.voiceCorrection",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Correct with a language model")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Fixes homophones, code terms and number formats after recognition. Adds about 1-3 seconds; the raw text is kept if it fails.")})]}),e.jsx(le,{checked:s,onCheckedChange:n})]}),s?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:"text-sm",children:t("Correction model")}),e.jsxs(ae,{value:a,items:p,onValueChange:j=>r(String(j)),children:[e.jsx(re,{className:"w-64",children:e.jsx(oe,{})}),e.jsx(ie,{children:p.map(j=>e.jsx(ee,{value:j.value,children:j.label},j.value))})]})]}),c?.downloadable?e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:G("text-xs",c.state==="missing"?"text-destructive":"text-muted-foreground"),children:h?.modelId===c.id?`${de(h.received)}${h.total?` / ${de(h.total)}`:""}`:c.state==="ready"?t("Model downloaded"):c.state==="downloading"?t("Downloading…"):t("Not downloaded yet. Correction is skipped until it is.")}),e.jsx(Bi,{state:c.state,onDownload:()=>{k.downloadChatModel(c.id).then(f)},onCancel:()=>{k.cancelChatModelDownload(c.id).then(f)},onRemove:()=>{k.deleteChatModel(c.id).then(f)}})]}):null,a==="remote"&&d.length>0?e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:t("A fast, inexpensive model is enough.")}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[o?e.jsx(S,{variant:"ghost",size:"sm",onClick:()=>i(null),children:t("Reset")}):null,e.jsx("div",{className:"w-56",children:e.jsx(ze,{providers:d,providerId:g?.id??"",modelId:w?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:t("Follows the title-summary model"),side:"bottom",triggerClassName:Ye,onSelect:(j,y)=>i({providerId:j,modelId:y}),onReasoningChange:()=>{},onThinkingChange:()=>{}})})]})]}):null]}):null]})}function ng(){const{t}=z(),s=v(a=>a.voiceInputEnabled),n=v(a=>a.setVoiceInputEnabled);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4","data-settings-row":"voice.root",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-medium text-lg",children:t("Voice input")}),e.jsx("p",{className:"text-muted-foreground text-sm",children:t("Adds a microphone to the composer on this computer and on paired phones. Local models transcribe speech on this computer.")})]}),e.jsx(le,{checked:s,onCheckedChange:n,"aria-label":t("Voice input"),className:"mt-1 shrink-0"})]}),s?e.jsxs(e.Fragment,{children:[e.jsx(rg,{}),e.jsx(Zf,{}),e.jsx(sg,{})]}):null]})}function ag(){const[t,s]=m.useState([]);return m.useEffect(()=>{const n=navigator.mediaDevices;if(!n?.enumerateDevices)return;let a=!0;const r=()=>{n.enumerateDevices().then(o=>{a&&s(o.filter(i=>i.kind==="audioinput"&&i.deviceId!==ti&&i.deviceId!=="communications"))})};return r(),n.addEventListener("devicechange",r),()=>{a=!1,n.removeEventListener("devicechange",r)}},[]),t}function rg(){const{t}=z(),s=v(o=>o.voiceInputDevice),n=v(o=>o.setVoiceInputDevice),a=ag(),r=[{value:ti,label:t("System default")},...a.map((o,i)=>({value:o.deviceId,label:o.label||t("Microphone {{n}}",{n:i+1})}))];return r.some(o=>o.value===s)||r.push({value:s,label:t("Disconnected, using the system default")}),e.jsxs("div",{className:"flex items-center justify-between gap-3","data-settings-row":"voice.microphone",children:[e.jsx("p",{className:"text-sm",children:t("Microphone")}),e.jsxs(ae,{value:s,items:r,onValueChange:o=>n(String(o)),children:[e.jsx(re,{className:"w-64",children:e.jsx(oe,{})}),e.jsx(ie,{children:r.map(o=>e.jsx(ee,{value:o.value,children:o.label},o.value))})]})]})}const og=32,ig=/^[A-Za-z0-9][A-Za-z0-9_:-]{0,127}$/,lg=/^[A-Za-z_][A-Za-z0-9_]{0,31}$/,cg=/\{\{\s*(?:args\.([A-Za-z_][A-Za-z0-9_]{0,31})|(prev))\s*\}\}/g;function Nn(t,s){if(typeof t!="string")return null;const n=t.trim();return n&&n.length<=s?n:null}function dg(t,s){const n=[...new Set(t)].filter(a=>lg.test(a)).map(a=>({kind:"arg",key:a,token:`{{args.${a}}}`}));return s>0&&n.push({kind:"prev",token:"{{prev}}"}),n}function ug(t,s,n,a){const r=Math.min(Math.max(s,0),t.length),o=Math.min(Math.max(n,r),t.length);return{text:t.slice(0,r)+a+t.slice(o),cursor:r+a.length}}function mg(t){if(!t||typeof t!="object"||Array.isArray(t))return null;const s=t,n=Nn(s.label,80),a=Nn(s.prompt,8e3),r=typeof s.agentType=="string"?s.agentType.trim():"";return!n||!a||r&&!ig.test(r)?null:{label:n,agentType:r,prompt:a}}function hg(t){if(!t||typeof t!="object"||Array.isArray(t))return null;const s=t,n=Nn(s.title,80);if(!n||!Array.isArray(s.steps)||s.steps.length===0)return null;const a=s.steps.map(mg);return a.every(r=>r!==null)?{title:n,steps:a}:null}function xg(t){if(!t||typeof t!="object"||Array.isArray(t))return null;const s=t.phases;if(!Array.isArray(s)||s.length===0)return null;const n=s.map(hg);return n.every(r=>r!==null)&&n.reduce((r,o)=>r+o.steps.length,0)<=og?{phases:n}:null}function Fi(t){const s=[];let n=0;for(const a of t.matchAll(cg))a.index>n&&s.push({kind:"text",text:t.slice(n,a.index)}),s.push(a[1]?{kind:"arg",key:a[1]}:{kind:"prev"}),n=a.index+a[0].length;return n<t.length&&s.push({kind:"text",text:t.slice(n)}),s}function pg(t){const s=Fi(t).map(n=>n.kind==="text"?JSON.stringify(n.text):n.kind==="arg"?`String(args.${n.key} ?? '')`:"prev");return s.length>0?s.join(" + "):'""'}function fg({label:t,agentType:s,prompt:n}){const a=[`label: ${JSON.stringify(t)}`];return s&&a.push(`agentType: ${JSON.stringify(s)}`),` () => agent(${pg(n)}, { ${a.join(", ")} }),`}function Ui(t){const s=["// Generated by the workflow designer. Editing this code detaches it from the designer.","const collect = (labels, outputs) =>"," labels.map((label, i) => '## ' + label + '\\n\\n' + (outputs[i] ?? '(failed)')).join('\\n\\n');","let prev = '';"];for(const n of t.phases){const a=JSON.stringify(n.steps.map(r=>r.label));s.push("",`await phase(${JSON.stringify(n.title)});`,`prev = collect(${a}, await parallel([`,...n.steps.map(fg),"]));")}return s.push("","return prev;",""),s.join(`
31
+ `)}async function gg(t){const[s,n,a]=await Promise.all([es(()=>import("./standalone-oyxre9MX.js"),[],import.meta.url),es(()=>import("./babel-BktJt1uC.js"),[],import.meta.url),es(()=>import("./estree-C_HWBWad.js"),[],import.meta.url)]);try{return{ok:!0,code:await s.format(t,{parser:"babel",plugins:[n,a],singleQuote:!0,printWidth:100,trailingComma:"es5"})}}catch(r){const o=r instanceof Error?r.message:String(r);return{ok:!1,error:o.split(`
32
+ `)[0]??o}}}const jg=32,_t=(t,s)=>Math.max(0,Math.min(t,s));function vg(t){return t.phases.reduce((s,n)=>s+n.steps.length,0)<jg}function bg(t,s,n){const a=t.phases.map((r,o)=>o===s?{...r,steps:[...r.steps,n]}:r);return{design:{phases:a},selection:{kind:"step",phase:s,step:(a[s]?.steps.length??1)-1}}}function yg(t,s,n){const a=_t(s,t.phases.length),r=[...t.phases];return r.splice(a,0,n),{design:{phases:r},selection:{kind:"phase",phase:a}}}function Xr(t,s){const n=t.phases[s.phase];if(!n)return null;if(s.kind==="step"&&n.steps.length>1){const r=n.steps.filter((o,i)=>i!==s.step);return{design:{phases:t.phases.map((o,i)=>i===s.phase?{...o,steps:r}:o)},selection:{kind:"step",phase:s.phase,step:_t(s.step,r.length-1)}}}if(t.phases.length===1)return null;const a=t.phases.filter((r,o)=>o!==s.phase);return{design:{phases:a},selection:{kind:"phase",phase:_t(s.phase,a.length-1)}}}function Zr(t,s,n){const a=s+n;if(a<0||a>=t.phases.length||!t.phases[s])return{design:t,selection:{kind:"phase",phase:s}};const r=[...t.phases],[o]=r.splice(s,1);return o&&r.splice(a,0,o),{design:{phases:r},selection:{kind:"phase",phase:a}}}function wg(t,s){const n=_t(s.phase,t.phases.length-1);if(s.kind==="phase")return{kind:"phase",phase:n};const a=t.phases[n]?.steps.length??1;return{kind:"step",phase:n,step:_t(s.step,a-1)}}const ln="__default__",eo=(t="scout")=>({label:"",agentType:t,prompt:""});function Ng({value:t,tokens:s,args:n,onChange:a}){const{t:r}=z(),o=m.useRef(null),i=()=>o.current?.querySelector("textarea")??null,d=x=>{const h=i(),l=t.length,f=ug(t,h?.selectionStart??l,h?.selectionEnd??l,x);a(f.text),requestAnimationFrame(()=>{h?.focus(),h?.setSelectionRange(f.cursor,f.cursor)})},u=x=>x.kind==="prev"?r("Previous phase output"):n.find(h=>h.key.trim()===x.key)?.label.trim()||x.key;return e.jsxs("div",{ref:o,className:"space-y-1",children:[e.jsx(He,{rows:5,className:"text-xs",placeholder:r("Prompt"),value:t,onChange:x=>a(x.target.value)}),e.jsxs(Jo,{children:[e.jsxs(Qo,{disabled:s.length===0,className:"inline-flex h-6 items-center gap-1 rounded-md px-1.5 text-muted-foreground text-xs hover:bg-accent hover:text-foreground disabled:pointer-events-none disabled:opacity-50",children:[e.jsx(Kd,{className:"h-3.5 w-3.5"}),r("Insert argument")]}),e.jsx(Xo,{align:"start",zIndex:st.DROPDOWN_IN_MODAL,finalFocus:i,children:s.map(x=>e.jsxs(Zo,{onClick:()=>d(x.token),children:[u(x),e.jsx("span",{className:"ml-auto pl-4 font-mono text-muted-foreground text-xs",children:x.token})]},x.token))})]})]})}const to=(t,s,n,a)=>{const r=Math.max((n-t)/2,8);return`M${t},${s} C${t+r},${s} ${n-r},${a} ${n},${a}`};function kg(t,s){const[n,a]=m.useState([]);return m.useLayoutEffect(()=>{const r=t.current;if(!r)return;const o=()=>{const d=r.getBoundingClientRect(),u=r.offsetWidth?d.width/r.offsetWidth:1,x=f=>{const c=r.querySelector(f)?.getBoundingClientRect();return c?{left:(c.left-d.left)/u,right:(c.right-d.left)/u,y:(c.top-d.top+c.height/2)/u}:null},h=(f,c)=>f<0||f>=s.phases.length?[`[data-node="${c}"]`]:(s.phases[f]?.steps??[]).map((p,g)=>`[data-node="s-${f}-${g}"]`),l=[];for(let f=0;f<=s.phases.length;f++){const c=x(`[data-gap="${f}"]`);if(c){for(const p of h(f-1,"start")){const g=x(p);g&&l.push({d:to(g.right,g.y,c.left,c.y),arrow:!1})}for(const p of h(f,"end")){const g=x(p);g&&l.push({d:to(c.right,c.y,g.left-2,g.y),arrow:!0})}}}a(l)};o();const i=new ResizeObserver(o);return i.observe(r),()=>i.disconnect()},[t,s]),n}function so({node:t,icon:s,title:n,detail:a}){return e.jsxs("div",{"data-node":t,className:"flex w-24 shrink-0 flex-col items-center gap-0.5 rounded-full border bg-background px-3 py-1.5 text-center shadow-xs",children:[e.jsxs("span",{className:"flex items-center gap-1 font-medium text-xs",children:[s,n]}),e.jsx("span",{className:"w-full truncate text-[10px] text-muted-foreground",children:a})]})}function Cg({prompt:t,args:s}){const{t:n}=z(),a=Fi(t.trim());return a.length===0?e.jsx(e.Fragment,{children:n("No prompt yet")}):e.jsx(e.Fragment,{children:a.map((r,o)=>r.kind==="text"?e.jsx(m.Fragment,{children:r.text},o):e.jsx("span",{className:"rounded bg-primary/10 px-1 font-medium text-primary",children:r.kind==="prev"?n("Previous phase output"):s.find(i=>i.key.trim()===r.key)?.label.trim()||r.key},o))})}function Sg({design:t,agentTypes:s,args:n,onChange:a}){const{t:r}=z(),[o,i]=m.useState({kind:"step",phase:0,step:0}),d=m.useRef(null),u=m.useId(),x=kg(d,t),h=t.phases,l=wg(t,o),f=h[l.phase],c=l.kind==="step"?f?.steps[l.step]:void 0,p=s.includes("scout")?"scout":"",g=n.map(I=>I.key.trim()).filter(Boolean),w=vg(t),k=Xr(t,l)!==null,j=I=>{I&&(a(I.design),i(I.selection))},y=I=>a({phases:h.map((L,C)=>C===l.phase?{...L,...I}:L)}),N=I=>l.kind==="step"&&y({steps:(f?.steps??[]).map((L,C)=>C===l.step?{...L,...I}:L)}),A=I=>{const L=I&&!s.includes(I)?[...s,I]:s;return[{value:ln,label:r("Default (worker)")},...L.map(C=>({value:C,label:C}))]},O=I=>e.jsx("div",{className:"flex w-10 shrink-0 items-center justify-center self-stretch",children:e.jsx("button",{type:"button","data-gap":I,disabled:!w,"aria-label":r("Insert phase here"),title:r("Insert phase here"),onClick:()=>j(yg(t,I,{title:"",steps:[eo(p)]})),className:"relative z-30 flex h-5 w-5 items-center justify-center rounded-full border bg-background text-muted-foreground transition-colors hover:border-primary hover:text-primary disabled:pointer-events-none disabled:opacity-50",children:e.jsx(Oe,{className:"h-3 w-3"})})});return e.jsxs("div",{className:"w-full space-y-2",children:[e.jsx("div",{className:"overflow-x-auto rounded-lg border bg-muted/30",children:e.jsxs("div",{ref:d,className:"relative flex w-max min-w-full items-center justify-center px-3 py-5",children:[e.jsxs("svg",{"aria-hidden":!0,className:"pointer-events-none absolute inset-0 z-20 h-full w-full overflow-visible text-muted-foreground/50",children:[e.jsx("defs",{children:e.jsx("marker",{id:u,viewBox:"0 0 6 6",refX:"5",refY:"3",markerWidth:"6",markerHeight:"6",orient:"auto",children:e.jsx("path",{d:"M0,0 L6,3 L0,6 z",fill:"currentColor"})})}),x.map(I=>e.jsx("path",{d:I.d,fill:"none",stroke:"currentColor",strokeWidth:1.25,markerEnd:I.arrow?`url(#${u})`:void 0},I.d))]}),e.jsx(so,{node:"start",icon:e.jsx($d,{className:"h-3 w-3"}),title:r("Start"),detail:g.length>0?g.join(", "):r("No arguments")}),h.map((I,L)=>e.jsxs(m.Fragment,{children:[O(L),e.jsxs("div",{className:G("flex w-44 shrink-0 flex-col gap-1.5 rounded-xl border border-dashed bg-background/60 p-2",l.kind==="phase"&&l.phase===L&&"border-primary border-solid"),children:[e.jsxs("button",{type:"button",onClick:()=>i({kind:"phase",phase:L}),className:G("flex min-w-0 items-center gap-1 rounded px-1 text-left text-[11px] hover:text-foreground",I.title.trim()?"text-muted-foreground":"text-destructive"),children:[e.jsx("span",{className:"shrink-0",children:r("Phase {{n}}",{n:L+1})}),e.jsx("span",{className:"truncate font-medium text-foreground",children:I.title.trim()||r("Untitled phase")})]}),I.steps.map((C,E)=>{const M=l.kind==="step"&&l.phase===L&&l.step===E,V=!C.label.trim()||!C.prompt.trim();return e.jsxs("button",{type:"button","data-node":`s-${L}-${E}`,onClick:()=>i({kind:"step",phase:L,step:E}),className:G("block w-full rounded-lg border bg-background px-2.5 py-1.5 text-left shadow-xs transition-colors hover:border-primary/60",M&&"border-primary ring-2 ring-primary/20",V&&!M&&"border-destructive/50"),children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"truncate font-medium text-xs",children:C.label.trim()||r("Untitled step")}),e.jsx("span",{className:"ml-auto shrink-0 rounded bg-muted px-1 text-[10px] text-muted-foreground",children:C.agentType||"worker"})]}),e.jsx("span",{className:"mt-0.5 line-clamp-2 break-words text-[11px] text-muted-foreground",children:e.jsx(Cg,{prompt:C.prompt,args:n})})]},E)}),e.jsxs("button",{type:"button",disabled:!w,onClick:()=>j(bg(t,L,eo(p))),className:"flex items-center justify-center gap-1 rounded-lg border border-dashed py-1 text-[11px] text-muted-foreground transition-colors hover:border-primary hover:text-primary disabled:pointer-events-none disabled:opacity-50",children:[e.jsx(Oe,{className:"h-3 w-3"}),r("Parallel step")]})]})]},L)),O(h.length),e.jsx(so,{node:"end",icon:e.jsx(Eu,{className:"h-3 w-3"}),title:r("Result"),detail:r("Last phase output")})]})}),e.jsxs("div",{className:"space-y-2 rounded-lg border p-3",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"font-medium text-xs",children:l.kind==="phase"?r("Phase {{n}}",{n:l.phase+1}):r("Phase {{n}} · Step {{m}}",{n:l.phase+1,m:l.step+1})}),e.jsxs("span",{className:"ml-auto flex items-center",children:[l.kind==="phase"&&e.jsxs(e.Fragment,{children:[e.jsx(S,{variant:"ghost",size:"icon-xs","aria-label":r("Move left"),disabled:l.phase===0,onClick:()=>j(Zr(t,l.phase,-1)),children:e.jsx(Uo,{})}),e.jsx(S,{variant:"ghost",size:"icon-xs","aria-label":r("Move right"),disabled:l.phase===h.length-1,onClick:()=>j(Zr(t,l.phase,1)),children:e.jsx(Vd,{})})]}),e.jsx(S,{variant:"ghost",size:"icon-xs","aria-label":r("Delete"),disabled:!k,onClick:()=>j(Xr(t,l)),children:e.jsx(Me,{})})]})]}),l.kind==="phase"||!c?e.jsx(J,{size:"sm",placeholder:r("Phase title"),value:f?.title??"",onChange:I=>y({title:I.target.value})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(J,{size:"sm",className:"min-w-0 flex-1",placeholder:r("Label"),value:c.label,onChange:I=>N({label:I.target.value})}),e.jsxs(ae,{items:A(c.agentType),value:c.agentType||ln,onValueChange:I=>N({agentType:I===ln?"":String(I??"")}),children:[e.jsx(re,{size:"sm",className:"w-36 min-w-0 shrink-0",children:e.jsx(oe,{})}),e.jsx(ie,{zIndex:st.DROPDOWN_IN_MODAL,children:A(c.agentType).map(I=>e.jsx(ee,{value:I.value,children:I.label},I.value))})]})]}),e.jsx(Ng,{value:c.prompt,tokens:dg(g,l.phase),args:n,onChange:I=>N({prompt:I})})]})]}),e.jsx("p",{className:"text-muted-foreground text-xs",children:r("Click a node to edit it. Steps in a column run in parallel; columns run from left to right.")})]})}const kn={phases:[{title:"Investigate",steps:[{label:"code",agentType:"scout",prompt:"Investigate {{args.topic}} in the source code."},{label:"tests",agentType:"scout",prompt:"Investigate {{args.topic}} in the tests."}]},{title:"Summarize",steps:[{label:"summary",agentType:"scout",prompt:`Merge these findings about {{args.topic}} into one short report:
33
33
 
34
- {{prev}}`}]}]},no={name:"",description:"",args:[{key:"topic",label:"Topic",required:!0}],design:kn,script:Ui(kn)};function Cg(t){return t.map(({key:s,label:n,default:a,required:r})=>({key:s.trim(),label:n.trim()||s.trim(),...a?.trim()?{default:a}:{},...r?{required:!0}:{}}))}function Sg({target:t,onClose:s,onSaved:n}){const{t:a}=z(),[r,o]=m.useState(no),[i,d]=m.useState("design"),[u,x]=m.useState(0),h=m.useRef(null),[l,f]=m.useState(!1),[c,p]=m.useState(!1),[g,w]=m.useState(!1),[k,j]=m.useState(null),y=v(b=>b.disabledBuiltinAgentTypes),N=v(b=>b.agentTypes),A=m.useMemo(()=>[...qd.map(b=>b.name).filter(b=>!y.includes(b)),...N.map(b=>b.name)],[y,N]);m.useEffect(()=>{if(j(null),t===null)return;if(h.current=null,x(_=>_+1),t==="new"){o(no),d("design");return}let b=!1;return f(!0),window.electronAPI.workflowPresets.read(t).then(_=>{if(!b)if(_){const{id:K,...D}=_;o(D),d(D.design?"design":"code"),x($=>$+1)}else j(a("Failed to read content"))}).finally(()=>{b||f(!1)}),()=>{b=!0}},[t,a]);const O=b=>o(_=>({..._,...b})),I=(b,_)=>O({args:r.args.map((K,D)=>D===b?{...K,..._}:K)}),L=b=>O({design:b,script:Ui(b)}),C=b=>{b!==r.script&&(r.design&&(h.current=r.design),o(_=>({..._,script:b,design:void 0})))},E=async()=>{w(!0);const b=await pg(r.script);if(w(!1),!b.ok){j(a("Format failed: {{error}}",{error:b.error}));return}j(null),b.code!==r.script&&(C(b.code),x(_=>_+1))},M=!r.design||mg(r.design)!==null,V=!l&&!c&&r.name.trim()!==""&&r.description.trim()!==""&&M&&r.script.trim()!=="",F=async()=>{if(!V||t===null)return;p(!0);const b=await window.electronAPI.workflowPresets.save({...r,args:Cg(r.args)},t==="new"?void 0:t);if(p(!1),!b.ok){j(a(b.error));return}n(),s()};return e.jsx(pe,{open:t!==null,onOpenChange:b=>!b&&s(),children:e.jsxs(fe,{className:"max-w-4xl",children:[e.jsx(ge,{children:e.jsx(je,{children:a(t==="new"?"Add workflow preset":"Edit workflow preset")})}),e.jsxs(we,{className:"space-y-4",children:[e.jsxs(me,{children:[e.jsx(he,{children:a("Name")}),e.jsx(J,{value:r.name,onChange:b=>O({name:b.target.value})})]}),e.jsxs(me,{children:[e.jsx(he,{children:a("Description")}),e.jsx(J,{value:r.description,onChange:b=>O({description:b.target.value})})]}),e.jsxs(me,{children:[e.jsx(he,{children:a("Arguments")}),e.jsxs("div",{className:"w-full space-y-1.5",children:[r.args.map((b,_)=>e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(J,{size:"sm",className:"w-28 font-mono",placeholder:"key",value:b.key,onChange:K=>I(_,{key:K.target.value})}),e.jsx(J,{size:"sm",className:"flex-1",placeholder:a("Label"),value:b.label,onChange:K=>I(_,{label:K.target.value})}),e.jsx(J,{size:"sm",className:"flex-1",placeholder:a("Default value"),value:b.default??"",onChange:K=>I(_,{default:K.target.value})}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1 text-muted-foreground text-xs",children:[e.jsx(Qe,{checked:b.required===!0,onCheckedChange:K=>I(_,{required:K===!0})}),a("Required")]}),e.jsx(S,{variant:"ghost",size:"icon-xs","aria-label":a("Remove"),onClick:()=>O({args:r.args.filter((K,D)=>D!==_)}),children:e.jsx(ht,{})})]},_)),e.jsxs(S,{variant:"outline",size:"xs",disabled:r.args.length>=8,onClick:()=>O({args:[...r.args,{key:"",label:""}]}),children:[e.jsx(Oe,{}),a("Add argument")]})]})]}),e.jsxs(me,{children:[e.jsxs("div",{className:"flex w-full items-center justify-between gap-2",children:[e.jsx(he,{children:a("Steps")}),i==="code"&&e.jsxs(S,{variant:"ghost",size:"xs",className:"ml-auto",disabled:l||g||!!r.design||!r.script.trim(),title:r.design?a("Generated code is already formatted"):void 0,onClick:E,children:[g?e.jsx(Ae,{className:"animate-spin"}):e.jsx(Gd,{}),a("Format")]}),e.jsx(Ft,{value:i,onValueChange:b=>d(b),children:e.jsxs(Ut,{children:[e.jsx(Ke,{value:"design",children:a("Design")}),e.jsx(Ke,{value:"code",children:a("Code")})]})})]}),l?e.jsx("div",{className:"flex w-full items-center justify-center rounded-md border py-12",children:e.jsx(Ae,{className:"h-4 w-4 animate-spin text-muted-foreground"})}):i==="design"?r.design?e.jsx(kg,{design:r.design,agentTypes:A,args:r.args,onChange:L}):e.jsxs("div",{className:"flex w-full flex-col items-center gap-2 rounded-md border border-dashed py-8 text-center",children:[e.jsx("p",{className:"max-w-md text-muted-foreground text-xs",children:a("This preset is plain code and cannot be shown in the designer. Using the designer replaces the current script.")}),e.jsx(S,{variant:"outline",size:"xs",onClick:()=>L(h.current??kn),children:a("Use the designer")})]}):e.jsx(wi,{fileName:"workflow.js",className:"h-80",value:r.script,epoch:u,onChange:C}),e.jsx("p",{className:"text-muted-foreground text-xs",children:i==="design"?!M&&a("Every phase needs a title and every step needs a label and a prompt."):r.design?a("Generated from the design. Editing the code detaches it from the designer."):a("Plain JavaScript with top-level await; end with return. Available: agent(prompt, opts), parallel, pipeline, phase, log, args.")})]}),k&&e.jsxs("p",{className:"flex items-center gap-1.5 text-destructive text-xs",children:[e.jsx(At,{className:"h-3.5 w-3.5 shrink-0"}),k]})]}),e.jsxs(Ie,{children:[e.jsx(S,{variant:"outline",size:"sm",onClick:s,children:a("Cancel")}),e.jsxs(S,{size:"sm",disabled:!V,onClick:F,children:[c&&e.jsx(Ae,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}),a("Save")]})]})]})})}function Ig(){const{t}=z(),[s,n]=m.useState([]),[a,r]=m.useState(null),o=v(h=>h.disabledWorkflowPresets),i=v(h=>h.toggleWorkflowPreset),d=m.useCallback(()=>{window.electronAPI.workflowPresets.list().then(n)},[]);m.useEffect(d,[d]);const u=s.filter(h=>h.source!=="builtin"),x=s.filter(h=>h.source==="builtin");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-end justify-between gap-4","data-settings-row":"workflows.root",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-medium text-lg",children:t("Workflows")}),e.jsx("p",{className:"text-muted-foreground text-sm",children:t("Preset workflows you can run from the Workflow side panel")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Project .agents/workflows files take precedence over these; ~/.agents/workflows and built-in presets come after.")})]}),e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>r("new"),children:[e.jsx(Oe,{className:"mr-1.5 h-4 w-4"}),t("Add workflow preset")]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium text-muted-foreground text-xs",children:t("Custom presets")}),u.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx(Un,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:t("No custom workflow presets yet")})]}):e.jsx("div",{className:"space-y-1",children:u.map(h=>e.jsxs("div",{className:"group flex items-center justify-between gap-3 rounded-md px-3 py-2 transition-colors hover:bg-accent/50","data-settings-row":`workflows.${h.id}`,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium text-sm",children:h.name}),e.jsx(te,{variant:"secondary",className:"shrink-0 font-mono text-[11px]",children:h.id})]}),e.jsx("p",{className:"truncate text-muted-foreground text-xs",children:h.description})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(S,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100","aria-label":t("Edit"),onClick:()=>r(h.id),children:e.jsx(lt,{className:"h-3.5 w-3.5"})}),e.jsx(S,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity hover:text-destructive group-hover:opacity-100","aria-label":t("Delete"),onClick:()=>{window.electronAPI.workflowPresets.delete(h.id).then(d)},children:e.jsx(Me,{className:"h-3.5 w-3.5"})})]})]},h.id))})]}),x.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium text-muted-foreground text-xs",children:t("Built-in presets")}),e.jsx("div",{className:"space-y-1",children:x.map(h=>e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md px-3 py-2 transition-colors hover:bg-accent/50","data-settings-row":`workflows.builtin.${h.id}`,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium text-sm",children:t(h.name)}),e.jsx(te,{variant:"secondary",className:"shrink-0 font-mono text-[11px]",children:h.id})]}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t(h.description)}),h.args.length>0&&e.jsxs("p",{className:"mt-0.5 text-muted-foreground text-xs",children:[t("Arguments"),":"," ",h.args.map(l=>`${t(l.label)}${l.required?" *":""}`).join(" · ")]})]}),e.jsx(le,{"aria-label":t(h.name),checked:!o.includes(h.id),onCheckedChange:l=>i(h.id,l)})]},h.id))})]}),e.jsx(Sg,{target:a,onClose:()=>r(null),onSaved:d})]})}function Ag(t){window.requestAnimationFrame(()=>{const s=document.querySelector(`[data-settings-row="${CSS.escape(t)}"]`);s instanceof HTMLElement&&(s.scrollIntoView({block:"center"}),s.dataset.settingsFlash="true",window.setTimeout(()=>{delete s.dataset.settingsFlash},1600))})}function ao(){const{t}=z(),[s,n]=m.useState("general"),[a,r]=m.useState(null),[o,i]=m.useState(null),[d,u]=m.useState(null),[x,h]=m.useState(0),l=Hd(),[f,c]=m.useState(!0),[p,g]=m.useState(""),[w,k]=m.useState([]),j=D=>{n(D),c(!1)},y=v(D=>D.disabledBuiltinTools),N=v(D=>D.botModeEnabled),A=m.useSyncExternalStore(D=>v.persist?.onFinishHydration?.(D)??(()=>{}),()=>v.persist?.hasHydrated?.()??!0),O=m.useCallback(D=>{n(D.category),c(!1),r(D.rowId),D.pluginInstallUrl&&i(D.pluginInstallUrl),u(D.pluginId??null)},[]);m.useEffect(()=>(window.electronAPI.window.consumeSettingsDeepLink().then(D=>{D&&O(D)}),window.electronAPI.window.onSettingsDeepLink(O)),[O]),m.useEffect(()=>{let D=!0;return window.electronAPI.sshConnections.list().then($=>{D&&k($.map(Y=>({id:Y.id,name:Y.name})))}).catch(()=>{D&&k([])}),()=>{D=!1}},[]);const I=Wd(w);m.useLayoutEffect(()=>{if(!a)return;Ag(a);const D=window.setTimeout(()=>r(null),1600);return()=>window.clearTimeout(D)},[a]);const C=Mf([{id:"general",icon:Zd,label:"General"},{id:"shortcuts",icon:eu,label:"Shortcuts"},{id:"voice",icon:tu,label:"Voice input"},{id:"appearance",icon:Bu,label:"Appearance"},{id:"providers",icon:Kn,label:"Model Providers"},{id:"presets",icon:su,label:"Presets"},{id:"agents",icon:nu,label:"Agent types"},{id:"tools",icon:Ao,label:"Built-in tools"},{id:"workflows",icon:Un,label:"Workflows"},{id:"memory",icon:So,label:"Memory"},{id:"privacy",icon:au,label:"Privacy"},{id:"skills",icon:ei,label:"Skills"},{id:"plugins",icon:_t,label:"Enso plugins"},{id:"claudePlugins",icon:gu,label:"Claude Code plugins"},{id:"mcp",icon:Lo,label:"MCP Servers"},{id:"instructions",icon:$n,label:"Instruction Files"},{id:"phone",icon:un,label:"Devices"},{id:"ssh",icon:jo,label:"SSH"},{id:"usage",icon:Nu,label:"Usage"},{id:"resources",icon:ru,label:"Resources"},{id:"experimental",icon:ou,label:"Experimental"},{id:"bots",icon:iu,label:"Bot mode",sub:!0},{id:"botTemplates",icon:lu,label:"Bot templates",sub:!0}],y,N),E=Ef(Tf(C,I,p,t)),M=Pf(s,y,N||!A);m.useEffect(()=>{M!==s&&n(M)},[M,s]);const V=!l||f,F=!l||!f,b=C.find(D=>D.id===s)?.label,_=Yd(),K=si();return e.jsxs("div",{className:"flex h-full w-full",children:[V&&e.jsxs("nav",{"data-enso":"settings-nav",className:G("flex min-h-0 shrink-0 flex-col",l?"w-full":_?"w-56":"w-56 border-r"),children:[_&&K==="mac"&&e.jsx("div",{"aria-hidden":!0,className:"drag-region -mb-2 h-[44px] shrink-0"}),e.jsx("div",{className:G("sticky top-0 z-10 px-2 pt-2",!_&&"bg-background"),children:e.jsxs("div",{className:"relative",children:[e.jsx(Io,{className:"pointer-events-none absolute top-1/2 left-2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),e.jsx("input",{value:p,onChange:D=>g(D.target.value),onKeyDown:D=>{D.key!=="Escape"||p.length===0||(D.preventDefault(),D.stopPropagation(),g(""))},placeholder:t("Search settings"),className:"h-8 w-full rounded-md border bg-transparent pr-2 pl-7 text-sm outline-none placeholder:text-muted-foreground focus-visible:ring-2 focus-visible:ring-ring"})]})}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto p-2",children:p.trim()&&E.length===0?e.jsx("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:t("No results")}):E.map((D,$)=>e.jsxs("div",{className:G($>0&&"mt-4"),children:[e.jsx("div",{className:"px-2 pb-1.5 text-xs font-semibold text-foreground/55",children:t(D.label)}),e.jsx("div",{className:"space-y-0.5 rounded-lg bg-muted/60 p-1",children:D.items.map(Y=>e.jsxs("div",{children:[e.jsxs("button",{type:"button",onClick:()=>j(Y.id),className:G("flex w-full items-center gap-2 rounded-md px-3 text-sm transition-colors",l?"py-3":"py-1.5",Y.sub&&"pl-8",s===Y.id&&!l?"bg-background text-foreground shadow-xs":"text-muted-foreground hover:bg-background/60 hover:text-foreground"),children:[e.jsx(Y.icon,{className:"h-4 w-4"}),t(Y.label),l&&e.jsx(Mt,{className:"ml-auto h-4 w-4 opacity-60"})]}),Y.hits.map(H=>e.jsx("button",{type:"button",onClick:()=>{j(Y.id),r(H.id)},className:G("block w-full truncate rounded-md pr-3 text-left text-xs text-muted-foreground hover:bg-background/60 hover:text-foreground",Y.sub?"pl-14":"pl-9",l?"py-2":"py-1"),children:t(H.title)},H.id))]},Y.id))})]},D.id))})]}),F&&e.jsxs("div",{"data-enso":"settings-content",className:G("flex min-w-0 flex-1 flex-col",_&&"my-[8px] mr-[8px] overflow-hidden rounded-[10px] bg-background shadow-surface"),children:[_&&e.jsx(Jd,{"data-enso":"title-bar"}),e.jsxs("div",{className:G("min-h-0 flex-1 overflow-y-auto",l?"px-4 pb-6":_?"px-6 pb-6":"p-6"),children:[l&&e.jsxs("button",{type:"button",onClick:()=>c(!0),className:"sticky top-0 z-10 -mx-4 mb-3 flex w-[calc(100%+2rem)] items-center gap-1 border-b bg-background px-2 py-2.5 text-sm font-medium",children:[e.jsx(bo,{className:"h-5 w-5 text-muted-foreground"}),b?t(b):null]}),s==="general"&&e.jsx(Em,{}),s==="shortcuts"&&e.jsx(cx,{}),s==="appearance"&&e.jsx(nh,{onOpenPlugins:()=>j("plugins")}),s==="providers"&&e.jsx(mf,{}),s==="skills"&&e.jsx(kf,{}),s==="plugins"&&e.jsx(qp,{requestedInstallUrl:o,onRequestedInstallUrlConsumed:()=>i(null),focusPluginId:d,onFocusPluginConsumed:()=>u(null)}),s==="claudePlugins"&&e.jsx(Wp,{}),s==="mcp"&&e.jsx(Rx,{}),s==="instructions"&&e.jsx(lx,{}),s==="presets"&&e.jsx(Qd,{}),s==="agents"&&e.jsx(Xd,{}),s==="workflows"&&e.jsx(Ig,{}),s==="tools"&&e.jsx(Ah,{}),s==="memory"&&e.jsxs("div",{className:"space-y-8",children:[e.jsx(Sp,{onLibraryChanged:()=>h(D=>D+1)}),e.jsx(Qx,{revision:x}),e.jsx(op,{revision:x})]}),s==="phone"&&e.jsx(ex,{}),s==="ssh"&&e.jsx(Cf,{}),s==="usage"&&e.jsx(Wf,{}),s==="privacy"&&e.jsx(tf,{}),s==="resources"&&e.jsx(vf,{}),s==="voice"&&e.jsx(tg,{}),s==="experimental"&&e.jsx(ox,{onOpenBots:()=>n("bots")}),s==="bots"&&e.jsx(dh,{}),s==="botTemplates"&&e.jsx(jh,{})]})]})]})}cu();du();function Eg(){const{t}=z(),s=si();return s!=="mobile"&&s!=="web"?e.jsxs("div",{"data-enso":"canvas",className:"flex h-screen overflow-hidden bg-canvas",children:[e.jsx(wa,{}),e.jsx(mu.Provider,{value:{trailing:e.jsx(hu,{kind:s,edgeGap:8})},children:e.jsx(ao,{})}),e.jsx(Na,{}),e.jsx(ka,{})]}):e.jsxs("div",{className:"flex h-screen flex-col overflow-hidden",children:[e.jsx(wa,{}),e.jsx(xu,{title:t("Settings"),actions:window.electronAPI.remote&&e.jsx("button",{type:"button",className:"flex h-7 w-7 items-center justify-center rounded-md hover:bg-muted",onClick:()=>{window.electronAPI.window.close()},"aria-label":t("Close"),title:t("Close"),children:e.jsx(ht,{className:"h-4 w-4"})})}),e.jsx("main",{className:"min-h-0 flex-1 overflow-hidden",children:e.jsx(ao,{})}),e.jsx(Na,{}),e.jsx(ka,{})]})}uu.createRoot(document.getElementById("root")).render(e.jsx(m.StrictMode,{children:e.jsx(Eg,{})}));
34
+ {{prev}}`}]}]},no={name:"",description:"",args:[{key:"topic",label:"Topic",required:!0}],design:kn,script:Ui(kn)};function Ig(t){return t.map(({key:s,label:n,default:a,required:r})=>({key:s.trim(),label:n.trim()||s.trim(),...a?.trim()?{default:a}:{},...r?{required:!0}:{}}))}function Ag({target:t,onClose:s,onSaved:n}){const{t:a}=z(),[r,o]=m.useState(no),[i,d]=m.useState("design"),[u,x]=m.useState(0),h=m.useRef(null),[l,f]=m.useState(!1),[c,p]=m.useState(!1),[g,w]=m.useState(!1),[k,j]=m.useState(null),y=v(b=>b.disabledBuiltinAgentTypes),N=v(b=>b.agentTypes),A=m.useMemo(()=>[...qd.map(b=>b.name).filter(b=>!y.includes(b)),...N.map(b=>b.name)],[y,N]);m.useEffect(()=>{if(j(null),t===null)return;if(h.current=null,x(B=>B+1),t==="new"){o(no),d("design");return}let b=!1;return f(!0),window.electronAPI.workflowPresets.read(t).then(B=>{if(!b)if(B){const{id:K,...D}=B;o(D),d(D.design?"design":"code"),x($=>$+1)}else j(a("Failed to read content"))}).finally(()=>{b||f(!1)}),()=>{b=!0}},[t,a]);const O=b=>o(B=>({...B,...b})),I=(b,B)=>O({args:r.args.map((K,D)=>D===b?{...K,...B}:K)}),L=b=>O({design:b,script:Ui(b)}),C=b=>{b!==r.script&&(r.design&&(h.current=r.design),o(B=>({...B,script:b,design:void 0})))},E=async()=>{w(!0);const b=await gg(r.script);if(w(!1),!b.ok){j(a("Format failed: {{error}}",{error:b.error}));return}j(null),b.code!==r.script&&(C(b.code),x(B=>B+1))},M=!r.design||xg(r.design)!==null,V=!l&&!c&&r.name.trim()!==""&&r.description.trim()!==""&&M&&r.script.trim()!=="",F=async()=>{if(!V||t===null)return;p(!0);const b=await window.electronAPI.workflowPresets.save({...r,args:Ig(r.args)},t==="new"?void 0:t);if(p(!1),!b.ok){j(a(b.error));return}n(),s()};return e.jsx(pe,{open:t!==null,onOpenChange:b=>!b&&s(),children:e.jsxs(fe,{className:"max-w-4xl",children:[e.jsx(ge,{children:e.jsx(je,{children:a(t==="new"?"Add workflow preset":"Edit workflow preset")})}),e.jsxs(we,{className:"space-y-4",children:[e.jsxs(me,{children:[e.jsx(he,{children:a("Name")}),e.jsx(J,{value:r.name,onChange:b=>O({name:b.target.value})})]}),e.jsxs(me,{children:[e.jsx(he,{children:a("Description")}),e.jsx(J,{value:r.description,onChange:b=>O({description:b.target.value})})]}),e.jsxs(me,{children:[e.jsx(he,{children:a("Arguments")}),e.jsxs("div",{className:"w-full space-y-1.5",children:[r.args.map((b,B)=>e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(J,{size:"sm",className:"w-28 font-mono",placeholder:"key",value:b.key,onChange:K=>I(B,{key:K.target.value})}),e.jsx(J,{size:"sm",className:"flex-1",placeholder:a("Label"),value:b.label,onChange:K=>I(B,{label:K.target.value})}),e.jsx(J,{size:"sm",className:"flex-1",placeholder:a("Default value"),value:b.default??"",onChange:K=>I(B,{default:K.target.value})}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1 text-muted-foreground text-xs",children:[e.jsx(Qe,{checked:b.required===!0,onCheckedChange:K=>I(B,{required:K===!0})}),a("Required")]}),e.jsx(S,{variant:"ghost",size:"icon-xs","aria-label":a("Remove"),onClick:()=>O({args:r.args.filter((K,D)=>D!==B)}),children:e.jsx(ht,{})})]},B)),e.jsxs(S,{variant:"outline",size:"xs",disabled:r.args.length>=8,onClick:()=>O({args:[...r.args,{key:"",label:""}]}),children:[e.jsx(Oe,{}),a("Add argument")]})]})]}),e.jsxs(me,{children:[e.jsxs("div",{className:"flex w-full items-center justify-between gap-2",children:[e.jsx(he,{children:a("Steps")}),i==="code"&&e.jsxs(S,{variant:"ghost",size:"xs",className:"ml-auto",disabled:l||g||!!r.design||!r.script.trim(),title:r.design?a("Generated code is already formatted"):void 0,onClick:E,children:[g?e.jsx(Ae,{className:"animate-spin"}):e.jsx(Gd,{}),a("Format")]}),e.jsx(Ft,{value:i,onValueChange:b=>d(b),children:e.jsxs(Ut,{children:[e.jsx(Ke,{value:"design",children:a("Design")}),e.jsx(Ke,{value:"code",children:a("Code")})]})})]}),l?e.jsx("div",{className:"flex w-full items-center justify-center rounded-md border py-12",children:e.jsx(Ae,{className:"h-4 w-4 animate-spin text-muted-foreground"})}):i==="design"?r.design?e.jsx(Sg,{design:r.design,agentTypes:A,args:r.args,onChange:L}):e.jsxs("div",{className:"flex w-full flex-col items-center gap-2 rounded-md border border-dashed py-8 text-center",children:[e.jsx("p",{className:"max-w-md text-muted-foreground text-xs",children:a("This preset is plain code and cannot be shown in the designer. Using the designer replaces the current script.")}),e.jsx(S,{variant:"outline",size:"xs",onClick:()=>L(h.current??kn),children:a("Use the designer")})]}):e.jsx(wi,{fileName:"workflow.js",className:"h-80",value:r.script,epoch:u,onChange:C}),e.jsx("p",{className:"text-muted-foreground text-xs",children:i==="design"?!M&&a("Every phase needs a title and every step needs a label and a prompt."):r.design?a("Generated from the design. Editing the code detaches it from the designer."):a("Plain JavaScript with top-level await; end with return. Available: agent(prompt, opts), parallel, pipeline, phase, log, args.")})]}),k&&e.jsxs("p",{className:"flex items-center gap-1.5 text-destructive text-xs",children:[e.jsx(At,{className:"h-3.5 w-3.5 shrink-0"}),k]})]}),e.jsxs(Ie,{children:[e.jsx(S,{variant:"outline",size:"sm",onClick:s,children:a("Cancel")}),e.jsxs(S,{size:"sm",disabled:!V,onClick:F,children:[c&&e.jsx(Ae,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}),a("Save")]})]})]})})}function Eg(){const{t}=z(),[s,n]=m.useState([]),[a,r]=m.useState(null),o=v(h=>h.disabledWorkflowPresets),i=v(h=>h.toggleWorkflowPreset),d=m.useCallback(()=>{window.electronAPI.workflowPresets.list().then(n)},[]);m.useEffect(d,[d]);const u=s.filter(h=>h.source!=="builtin"),x=s.filter(h=>h.source==="builtin");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-end justify-between gap-4","data-settings-row":"workflows.root",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-medium text-lg",children:t("Workflows")}),e.jsx("p",{className:"text-muted-foreground text-sm",children:t("Preset workflows you can run from the Workflow side panel")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Project .agents/workflows files take precedence over these; ~/.agents/workflows and built-in presets come after.")})]}),e.jsxs(S,{variant:"outline",size:"sm",onClick:()=>r("new"),children:[e.jsx(Oe,{className:"mr-1.5 h-4 w-4"}),t("Add workflow preset")]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium text-muted-foreground text-xs",children:t("Custom presets")}),u.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx(Un,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:t("No custom workflow presets yet")})]}):e.jsx("div",{className:"space-y-1",children:u.map(h=>e.jsxs("div",{className:"group flex items-center justify-between gap-3 rounded-md px-3 py-2 transition-colors hover:bg-accent/50","data-settings-row":`workflows.${h.id}`,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium text-sm",children:h.name}),e.jsx(te,{variant:"secondary",className:"shrink-0 font-mono text-[11px]",children:h.id})]}),e.jsx("p",{className:"truncate text-muted-foreground text-xs",children:h.description})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(S,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100","aria-label":t("Edit"),onClick:()=>r(h.id),children:e.jsx(lt,{className:"h-3.5 w-3.5"})}),e.jsx(S,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity hover:text-destructive group-hover:opacity-100","aria-label":t("Delete"),onClick:()=>{window.electronAPI.workflowPresets.delete(h.id).then(d)},children:e.jsx(Me,{className:"h-3.5 w-3.5"})})]})]},h.id))})]}),x.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium text-muted-foreground text-xs",children:t("Built-in presets")}),e.jsx("div",{className:"space-y-1",children:x.map(h=>e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md px-3 py-2 transition-colors hover:bg-accent/50","data-settings-row":`workflows.builtin.${h.id}`,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium text-sm",children:t(h.name)}),e.jsx(te,{variant:"secondary",className:"shrink-0 font-mono text-[11px]",children:h.id})]}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t(h.description)}),h.args.length>0&&e.jsxs("p",{className:"mt-0.5 text-muted-foreground text-xs",children:[t("Arguments"),":"," ",h.args.map(l=>`${t(l.label)}${l.required?" *":""}`).join(" · ")]})]}),e.jsx(le,{"aria-label":t(h.name),checked:!o.includes(h.id),onCheckedChange:l=>i(h.id,l)})]},h.id))})]}),e.jsx(Ag,{target:a,onClose:()=>r(null),onSaved:d})]})}function Mg(t){window.requestAnimationFrame(()=>{const s=document.querySelector(`[data-settings-row="${CSS.escape(t)}"]`);s instanceof HTMLElement&&(s.scrollIntoView({block:"center"}),s.dataset.settingsFlash="true",window.setTimeout(()=>{delete s.dataset.settingsFlash},1600))})}function ao(){const{t}=z(),[s,n]=m.useState("general"),[a,r]=m.useState(null),[o,i]=m.useState(null),[d,u]=m.useState(null),[x,h]=m.useState(0),l=Hd(),[f,c]=m.useState(!0),[p,g]=m.useState(""),[w,k]=m.useState([]),j=D=>{n(D),c(!1)},y=v(D=>D.disabledBuiltinTools),N=v(D=>D.botModeEnabled),A=m.useSyncExternalStore(D=>v.persist?.onFinishHydration?.(D)??(()=>{}),()=>v.persist?.hasHydrated?.()??!0),O=m.useCallback(D=>{n(D.category),c(!1),r(D.rowId),D.pluginInstallUrl&&i(D.pluginInstallUrl),u(D.pluginId??null)},[]);m.useEffect(()=>(window.electronAPI.window.consumeSettingsDeepLink().then(D=>{D&&O(D)}),window.electronAPI.window.onSettingsDeepLink(O)),[O]),m.useEffect(()=>{let D=!0;return window.electronAPI.sshConnections.list().then($=>{D&&k($.map(Y=>({id:Y.id,name:Y.name})))}).catch(()=>{D&&k([])}),()=>{D=!1}},[]);const I=Wd(w);m.useLayoutEffect(()=>{if(!a)return;Mg(a);const D=window.setTimeout(()=>r(null),1600);return()=>window.clearTimeout(D)},[a]);const C=Tf([{id:"general",icon:Zd,label:"General"},{id:"shortcuts",icon:eu,label:"Shortcuts"},{id:"voice",icon:tu,label:"Voice input"},{id:"appearance",icon:_u,label:"Appearance"},{id:"providers",icon:Kn,label:"Model Providers"},{id:"presets",icon:su,label:"Presets"},{id:"agents",icon:nu,label:"Agent types"},{id:"tools",icon:Ao,label:"Built-in tools"},{id:"workflows",icon:Un,label:"Workflows"},{id:"memory",icon:So,label:"Memory"},{id:"privacy",icon:au,label:"Privacy"},{id:"skills",icon:ei,label:"Skills"},{id:"plugins",icon:Bt,label:"Enso plugins"},{id:"claudePlugins",icon:gu,label:"Claude Code plugins"},{id:"mcp",icon:Lo,label:"MCP Servers"},{id:"instructions",icon:$n,label:"Instruction Files"},{id:"phone",icon:un,label:"Devices"},{id:"ssh",icon:jo,label:"SSH"},{id:"usage",icon:Nu,label:"Usage"},{id:"resources",icon:ru,label:"Resources"},{id:"experimental",icon:ou,label:"Experimental"},{id:"bots",icon:iu,label:"Bot mode",sub:!0},{id:"botTemplates",icon:lu,label:"Bot templates",sub:!0}],y,N),E=Pf(Of(C,I,p,t)),M=Rf(s,y,N||!A);m.useEffect(()=>{M!==s&&n(M)},[M,s]);const V=!l||f,F=!l||!f,b=C.find(D=>D.id===s)?.label,B=Yd(),K=si();return e.jsxs("div",{className:"flex h-full w-full",children:[V&&e.jsxs("nav",{"data-enso":"settings-nav",className:G("flex min-h-0 shrink-0 flex-col",l?"w-full":B?"w-56":"w-56 border-r"),children:[B&&K==="mac"&&e.jsx("div",{"aria-hidden":!0,className:"drag-region -mb-2 h-[44px] shrink-0"}),e.jsx("div",{className:G("sticky top-0 z-10 px-2 pt-2",!B&&"bg-background"),children:e.jsxs("div",{className:"relative",children:[e.jsx(Io,{className:"pointer-events-none absolute top-1/2 left-2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),e.jsx("input",{value:p,onChange:D=>g(D.target.value),onKeyDown:D=>{D.key!=="Escape"||p.length===0||(D.preventDefault(),D.stopPropagation(),g(""))},placeholder:t("Search settings"),className:"h-8 w-full rounded-md border bg-transparent pr-2 pl-7 text-sm outline-none placeholder:text-muted-foreground focus-visible:ring-2 focus-visible:ring-ring"})]})}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto p-2",children:p.trim()&&E.length===0?e.jsx("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:t("No results")}):E.map((D,$)=>e.jsxs("div",{className:G($>0&&"mt-4"),children:[e.jsx("div",{className:"px-2 pb-1.5 text-xs font-semibold text-foreground/55",children:t(D.label)}),e.jsx("div",{className:"space-y-0.5 rounded-lg bg-muted/60 p-1",children:D.items.map(Y=>e.jsxs("div",{children:[e.jsxs("button",{type:"button",onClick:()=>j(Y.id),className:G("flex w-full items-center gap-2 rounded-md px-3 text-sm transition-colors",l?"py-3":"py-1.5",Y.sub&&"pl-8",s===Y.id&&!l?"bg-background text-foreground shadow-xs":"text-muted-foreground hover:bg-background/60 hover:text-foreground"),children:[e.jsx(Y.icon,{className:"h-4 w-4"}),t(Y.label),l&&e.jsx(Mt,{className:"ml-auto h-4 w-4 opacity-60"})]}),Y.hits.map(H=>e.jsx("button",{type:"button",onClick:()=>{j(Y.id),r(H.id)},className:G("block w-full truncate rounded-md pr-3 text-left text-xs text-muted-foreground hover:bg-background/60 hover:text-foreground",Y.sub?"pl-14":"pl-9",l?"py-2":"py-1"),children:t(H.title)},H.id))]},Y.id))})]},D.id))})]}),F&&e.jsxs("div",{"data-enso":"settings-content",className:G("flex min-w-0 flex-1 flex-col",B&&"my-[8px] mr-[8px] overflow-hidden rounded-[10px] bg-background shadow-surface"),children:[B&&e.jsx(Jd,{"data-enso":"title-bar"}),e.jsxs("div",{className:G("min-h-0 flex-1 overflow-y-auto",l?"px-4 pb-6":B?"px-6 pb-6":"p-6"),children:[l&&e.jsxs("button",{type:"button",onClick:()=>c(!0),className:"sticky top-0 z-10 -mx-4 mb-3 flex w-[calc(100%+2rem)] items-center gap-1 border-b bg-background px-2 py-2.5 text-sm font-medium",children:[e.jsx(bo,{className:"h-5 w-5 text-muted-foreground"}),b?t(b):null]}),s==="general"&&e.jsx(Mm,{}),s==="shortcuts"&&e.jsx(ux,{}),s==="appearance"&&e.jsx(rh,{onOpenPlugins:()=>j("plugins")}),s==="providers"&&e.jsx(xf,{}),s==="skills"&&e.jsx(Sf,{}),s==="plugins"&&e.jsx(Hp,{requestedInstallUrl:o,onRequestedInstallUrlConsumed:()=>i(null),focusPluginId:d,onFocusPluginConsumed:()=>u(null)}),s==="claudePlugins"&&e.jsx(Jp,{}),s==="mcp"&&e.jsx(Dx,{}),s==="instructions"&&e.jsx(dx,{}),s==="presets"&&e.jsx(Qd,{}),s==="agents"&&e.jsx(Xd,{}),s==="workflows"&&e.jsx(Eg,{}),s==="tools"&&e.jsx(Mh,{}),s==="memory"&&e.jsxs("div",{className:"space-y-8",children:[e.jsx(Ap,{onLibraryChanged:()=>h(D=>D+1)}),e.jsx(Zx,{revision:x}),e.jsx(lp,{revision:x})]}),s==="phone"&&e.jsx(sx,{}),s==="ssh"&&e.jsx(If,{}),s==="usage"&&e.jsx(Jf,{}),s==="privacy"&&e.jsx(nf,{}),s==="resources"&&e.jsx(yf,{}),s==="voice"&&e.jsx(ng,{}),s==="experimental"&&e.jsx(lx,{onOpenBots:()=>n("bots")}),s==="bots"&&e.jsx(mh,{}),s==="botTemplates"&&e.jsx(bh,{})]})]})]})}cu();du();function Pg(){const{t}=z(),s=si();return s!=="mobile"&&s!=="web"?e.jsxs("div",{"data-enso":"canvas",className:"flex h-screen overflow-hidden bg-canvas",children:[e.jsx(wa,{}),e.jsx(mu.Provider,{value:{trailing:e.jsx(hu,{kind:s,edgeGap:8})},children:e.jsx(ao,{})}),e.jsx(Na,{}),e.jsx(ka,{})]}):e.jsxs("div",{className:"flex h-screen flex-col overflow-hidden",children:[e.jsx(wa,{}),e.jsx(xu,{title:t("Settings"),actions:window.electronAPI.remote&&e.jsx("button",{type:"button",className:"flex h-7 w-7 items-center justify-center rounded-md hover:bg-muted",onClick:()=>{window.electronAPI.window.close()},"aria-label":t("Close"),title:t("Close"),children:e.jsx(ht,{className:"h-4 w-4"})})}),e.jsx("main",{className:"min-h-0 flex-1 overflow-hidden",children:e.jsx(ao,{})}),e.jsx(Na,{}),e.jsx(ka,{})]})}uu.createRoot(document.getElementById("root")).render(e.jsx(m.StrictMode,{children:e.jsx(Pg,{})}));