@ensocode/server 0.3.7 → 0.3.9

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 (176) hide show
  1. package/out/phone/assets/{abnfDiagram-VCTEODGH-2-rZfXru.js → abnfDiagram-VCTEODGH-CBVQuFGg.js} +1 -1
  2. package/out/phone/assets/architecture-7GRP2DOG-DOA5Bycz.js +1 -0
  3. package/out/phone/assets/{architectureDiagram-5GKGNRK7-vlXme2Q3.js → architectureDiagram-5GKGNRK7-Uwi4Yp3N.js} +1 -1
  4. package/out/phone/assets/{blockDiagram-I7D4REHJ-BD1NeeU7.js → blockDiagram-I7D4REHJ-Dee88kBX.js} +1 -1
  5. package/out/phone/assets/{c4Diagram-7LVT6UL2-BLQd5mqT.js → c4Diagram-7LVT6UL2-CPVctMym.js} +1 -1
  6. package/out/phone/assets/channel-DKcROQS8.js +1 -0
  7. package/out/phone/assets/{chunk-4HAMMTFA-CxF_O9R8.js → chunk-4HAMMTFA-DdHZ8tzu.js} +1 -1
  8. package/out/phone/assets/{chunk-75Z2AOVW-DmshWRC4.js → chunk-75Z2AOVW-CXd1zaQL.js} +1 -1
  9. package/out/phone/assets/{chunk-DU6HZSFF-CZrdwMNN.js → chunk-DU6HZSFF-K72dP1XP.js} +1 -1
  10. package/out/phone/assets/{chunk-F27PBJKO-ColBn-9C.js → chunk-F27PBJKO-JZyoOZLJ.js} +1 -1
  11. package/out/phone/assets/{chunk-GMAD6QVW-CJN3ap1i.js → chunk-GMAD6QVW-O3x_QcGA.js} +1 -1
  12. package/out/phone/assets/{chunk-GVQU2GXP-h3qKgG9R.js → chunk-GVQU2GXP-g5OZYD2B.js} +1 -1
  13. package/out/phone/assets/{chunk-IMKFNOWR-CZRKz_sn.js → chunk-IMKFNOWR-r0ScpN_y.js} +1 -1
  14. package/out/phone/assets/{chunk-L3NEJ4N5-CMO7DEvv.js → chunk-L3NEJ4N5-O-r4RmZJ.js} +1 -1
  15. package/out/phone/assets/{chunk-OSK3NFVY-C5uece6k.js → chunk-OSK3NFVY-ramCCXI9.js} +1 -1
  16. package/out/phone/assets/{chunk-P2QGCYS3-WgQBUDEk.js → chunk-P2QGCYS3-DD3uRJ3h.js} +1 -1
  17. package/out/phone/assets/{chunk-POPQ4Y6H-VHLT_ckM.js → chunk-POPQ4Y6H-RiL5jwG6.js} +1 -1
  18. package/out/phone/assets/{chunk-PWAF6VOD-AIbXljX0.js → chunk-PWAF6VOD-YKF2LrOr.js} +1 -1
  19. package/out/phone/assets/{chunk-SHT3W25Y-Bxg4nJYZ.js → chunk-SHT3W25Y-NK2MDUJG.js} +1 -1
  20. package/out/phone/assets/{chunk-SVP7TREG-C4_nxyeQ.js → chunk-SVP7TREG-7bCZBtZP.js} +1 -1
  21. package/out/phone/assets/{chunk-TICWLB2K-B5wDGVGC.js → chunk-TICWLB2K-DkVtQtfm.js} +1 -1
  22. package/out/phone/assets/classDiagram-ZZMXUADV-CrpQDbmR.js +1 -0
  23. package/out/phone/assets/classDiagram-v2-VYDZK3BY-CrpQDbmR.js +1 -0
  24. package/out/phone/assets/{cynefin-OW5HDTMX-IUYlkNoA.js → cynefin-OW5HDTMX-C3bBDDKw.js} +1 -1
  25. package/out/phone/assets/{cynefinDiagram-5FMLGOSQ-ciimhepC.js → cynefinDiagram-5FMLGOSQ-B1KRMzP2.js} +1 -1
  26. package/out/phone/assets/{dagre-GXQ25YYZ-Dk3tslas.js → dagre-GXQ25YYZ-NLxwj9wy.js} +1 -1
  27. package/out/phone/assets/desk-DfeUjqmj.js +2 -0
  28. package/out/phone/assets/{diagram-S7CK7UJ4-BhDokNwG.js → diagram-S7CK7UJ4-DfcfBkAs.js} +1 -1
  29. package/out/phone/assets/{diagram-UQ7AKVKN-CciyntsZ.js → diagram-UQ7AKVKN-DCvI1s7K.js} +1 -1
  30. package/out/phone/assets/{diagram-VSXAHHWV-BG3YhyOX.js → diagram-VSXAHHWV-Bm1zOS5P.js} +1 -1
  31. package/out/phone/assets/{diagram-VX7I27RA-Wx7x7olQ.js → diagram-VX7I27RA-BQuZufNO.js} +1 -1
  32. package/out/phone/assets/{diagram-Z3DM3KII-CcI8MVzR.js → diagram-Z3DM3KII-DBIMQQh6.js} +1 -1
  33. package/out/phone/assets/{ebnfDiagram-PWID7BFC-Cug1-9Ha.js → ebnfDiagram-PWID7BFC-tVvJnbJ2.js} +1 -1
  34. package/out/phone/assets/{erDiagram-RLTQ6QDP-kjxgMXRS.js → erDiagram-RLTQ6QDP-BSiTfV80.js} +1 -1
  35. package/out/phone/assets/eventmodeling-NTZA5JFV-DiyOQMrF.js +1 -0
  36. package/out/phone/assets/flowDiagram-HODETNUW-_UpaA-So.js +1 -0
  37. package/out/phone/assets/{ganttDiagram-EL5Y4UJY-Ci67p8ni.js → ganttDiagram-EL5Y4UJY-DTQdTWJN.js} +1 -1
  38. package/out/phone/assets/{gitGraph-4MIJSDKK-Bq5w_SFd.js → gitGraph-4MIJSDKK-DP-rU0q-.js} +1 -1
  39. package/out/phone/assets/{gitGraphDiagram-WWUBYQGX-6MPAWIQP.js → gitGraphDiagram-WWUBYQGX-v56Bt0O6.js} +1 -1
  40. package/out/phone/assets/{info-A6RAGUB7-D05oiQx3.js → info-A6RAGUB7-CAQE0Hfy.js} +1 -1
  41. package/out/phone/assets/{infoDiagram-27XIBGKW-DEMR262W.js → infoDiagram-27XIBGKW-CSXtf5Fo.js} +1 -1
  42. package/out/phone/assets/{ishikawaDiagram-5VMMS53U-D54EdxMb.js → ishikawaDiagram-5VMMS53U-CclPV6gG.js} +1 -1
  43. package/out/phone/assets/{journeyDiagram-3NMN7TZE-BIEdfqGB.js → journeyDiagram-3NMN7TZE-BIkpYm1f.js} +1 -1
  44. package/out/phone/assets/{kanban-definition-UXKFOSKX-Ps-NZDsh.js → kanban-definition-UXKFOSKX-yepY9S2l.js} +1 -1
  45. package/out/phone/assets/{line-DGUUioP5.js → line-BeTXpSNc.js} +1 -1
  46. package/out/phone/assets/main-CGpGZfti.css +1 -0
  47. package/out/phone/assets/main-DW3B3ovc.js +1658 -0
  48. package/out/phone/assets/{mermaid-parser.core-BkNZLgza.js → mermaid-parser.core-nw37szCl.js} +3 -3
  49. package/out/phone/assets/{mermaid.core-nEcMItTa.js → mermaid.core-DdSdNZO_.js} +4 -4
  50. package/out/phone/assets/{mindmap-definition-YA3MSWOX-DZvLJVDS.js → mindmap-definition-YA3MSWOX-CiQWyjG5.js} +1 -1
  51. package/out/phone/assets/{packet-AYTQ26CC-BORABWaG.js → packet-AYTQ26CC-MFESxWKw.js} +1 -1
  52. package/out/phone/assets/{pegDiagram-XKGWAZYB-CGyyPNG0.js → pegDiagram-XKGWAZYB-BM9Ofbc8.js} +1 -1
  53. package/out/phone/assets/{pie-WAS4IAKB-DXKTNLO7.js → pie-WAS4IAKB-BX8j-oF_.js} +1 -1
  54. package/out/phone/assets/{pieDiagram-E7YTZNPT-BHlAnBZb.js → pieDiagram-E7YTZNPT-1KLqp5sl.js} +1 -1
  55. package/out/phone/assets/{quadrantDiagram-AXDQQJYC-CYx8zP0Z.js → quadrantDiagram-AXDQQJYC-wqwWQyRe.js} +1 -1
  56. package/out/phone/assets/{radar-RG4KPBEZ-mYzEXGPZ.js → radar-RG4KPBEZ-jaQ0-Att.js} +1 -1
  57. package/out/phone/assets/{railroad-74A4TZTK-BpSoFKZI.js → railroad-74A4TZTK-BBOWTcMX.js} +1 -1
  58. package/out/phone/assets/railroad-abnf-HS5TGJTU-DfD2cpkN.js +1 -0
  59. package/out/phone/assets/railroad-ebnf-LZEXJU2U-BAwl_fDM.js +1 -0
  60. package/out/phone/assets/railroad-peg-WCYAUIDC-MbpAQZum.js +1 -0
  61. package/out/phone/assets/{railroadDiagram-O6MQD6OU-BAlwhvnj.js → railroadDiagram-O6MQD6OU-DJQ-7iWl.js} +1 -1
  62. package/out/phone/assets/{requirementDiagram-BXWQKSXE-C2R7ulaS.js → requirementDiagram-BXWQKSXE-D4dveBtm.js} +1 -1
  63. package/out/phone/assets/{sankeyDiagram-P5KCCOFB-c0sv5hNV.js → sankeyDiagram-P5KCCOFB-Xi3vzQcH.js} +1 -1
  64. package/out/phone/assets/{sequenceDiagram-WJ2MYXX4-Cz6Zq57N.js → sequenceDiagram-WJ2MYXX4-DJu7wXTv.js} +1 -1
  65. package/out/phone/assets/{stateDiagram-D77RDMKH-DZhgDUa6.js → stateDiagram-D77RDMKH-BY7kdvUZ.js} +1 -1
  66. package/out/phone/assets/stateDiagram-v2-MP3YSRHH-DDqCllzv.js +1 -0
  67. package/out/phone/assets/storage-dUWOZ2xo.js +36 -0
  68. package/out/phone/assets/{swimlanes-42K2YHIH-ByNqwNMl.js → swimlanes-42K2YHIH-CIxzAE5G.js} +1 -1
  69. package/out/phone/assets/swimlanesDiagram-VR7AAH4N-Cu8_tU2m.js +8 -0
  70. package/out/phone/assets/{timeline-definition-24CTP7MA-CSFOYvnV.js → timeline-definition-24CTP7MA-e-O3IHwG.js} +1 -1
  71. package/out/phone/assets/{treeView-Q6P3EWNA-CDqEDufz.js → treeView-Q6P3EWNA-Bhtyuzk0.js} +1 -1
  72. package/out/phone/assets/{treemap-WGGIJYW6-DfjCLTFL.js → treemap-WGGIJYW6-B_tM9CqS.js} +1 -1
  73. package/out/phone/assets/{vennDiagram-4TSXK5OY-CjV_vvWy.js → vennDiagram-4TSXK5OY-9npu53KS.js} +1 -1
  74. package/out/phone/assets/{wardley-WFR3VGLG-Df2M8YsO.js → wardley-WFR3VGLG-Dtb3_st-.js} +1 -1
  75. package/out/phone/assets/{wardleyDiagram-VM6X3IG4-B2bcg9of.js → wardleyDiagram-VM6X3IG4-DCBObiQg.js} +1 -1
  76. package/out/phone/assets/{xychartDiagram-S5SC5T6Z-Fq1wBYKM.js → xychartDiagram-S5SC5T6Z-BAHqVoN1.js} +1 -1
  77. package/out/phone/desk.html +2 -2
  78. package/out/phone/index.html +3 -3
  79. package/out/renderer/assets/{abnfDiagram-VCTEODGH-DMPmG_xF.js → abnfDiagram-VCTEODGH-ClaZATP-.js} +1 -1
  80. package/out/renderer/assets/{arc-DjMiWCQZ.js → arc-B0Ue52gX.js} +1 -1
  81. package/out/renderer/assets/{architectureDiagram-5GKGNRK7-Dy1W4IYD.js → architectureDiagram-5GKGNRK7-CbmNLvfJ.js} +1 -1
  82. package/out/renderer/assets/{blockDiagram-I7D4REHJ-B8zx5UuN.js → blockDiagram-I7D4REHJ-crBSO4mg.js} +1 -1
  83. package/out/renderer/assets/{c4Diagram-7LVT6UL2-D7MZ3XeI.js → c4Diagram-7LVT6UL2-BhASES00.js} +1 -1
  84. package/out/renderer/assets/channel-DAEAroq1.js +1 -0
  85. package/out/renderer/assets/{chunk-2Q5K7J3B-BEMGeNvl.js → chunk-2Q5K7J3B-CCY1-54C.js} +1 -1
  86. package/out/renderer/assets/{chunk-5VM5RSS4-CTB_kPAW.js → chunk-5VM5RSS4-MmFztUTQ.js} +1 -1
  87. package/out/renderer/assets/{chunk-F27PBJKO-CDc0IpL4.js → chunk-F27PBJKO-CemaMYDJ.js} +1 -1
  88. package/out/renderer/assets/{chunk-IMKFNOWR-5NElfs8W.js → chunk-IMKFNOWR-DctUdkub.js} +1 -1
  89. package/out/renderer/assets/{chunk-JWPE2WC7-DfZ55eH3.js → chunk-JWPE2WC7-DCjmZlft.js} +1 -1
  90. package/out/renderer/assets/{chunk-POPQ4Y6H-BK1Mb8zQ.js → chunk-POPQ4Y6H-D-KxWwr4.js} +1 -1
  91. package/out/renderer/assets/{chunk-SVP7TREG-BTCzRhBg.js → chunk-SVP7TREG-CGc3VMbe.js} +1 -1
  92. package/out/renderer/assets/{chunk-TICWLB2K-BIdRdQio.js → chunk-TICWLB2K-BwI6l28m.js} +1 -1
  93. package/out/renderer/assets/{chunk-XXDRQBXY-xdEJ7eED.js → chunk-XXDRQBXY-C3lgg1-4.js} +1 -1
  94. package/out/renderer/assets/classDiagram-ZZMXUADV-BHNNTKj0.js +1 -0
  95. package/out/renderer/assets/classDiagram-v2-VYDZK3BY-BHNNTKj0.js +1 -0
  96. package/out/renderer/assets/{cose-bilkent-JH36ORCC-Dbeuy5zT.js → cose-bilkent-JH36ORCC-DqGFhKtY.js} +1 -1
  97. package/out/renderer/assets/{cynefin-OW5HDTMX-DYk68iql.js → cynefin-OW5HDTMX-BpknO3Y_.js} +1 -1
  98. package/out/renderer/assets/{cynefinDiagram-5FMLGOSQ-CW9N3zhw.js → cynefinDiagram-5FMLGOSQ-DS1vS0h7.js} +1 -1
  99. package/out/renderer/assets/{cytoscape-fcose-BtmodGyv.js → cytoscape-fcose-DeHY1J1u.js} +1 -1
  100. package/out/renderer/assets/{dagre-GXQ25YYZ-xTaBduGi.js → dagre-GXQ25YYZ-DxScp9AG.js} +1 -1
  101. package/out/renderer/assets/{diagram-S7CK7UJ4-Okomm8Ap.js → diagram-S7CK7UJ4-Djlu9ceY.js} +1 -1
  102. package/out/renderer/assets/{diagram-UQ7AKVKN-CvzlGwuY.js → diagram-UQ7AKVKN-BK3mHHvd.js} +1 -1
  103. package/out/renderer/assets/{diagram-VSXAHHWV-BJtbgGmH.js → diagram-VSXAHHWV-Bg9tDRjc.js} +1 -1
  104. package/out/renderer/assets/{diagram-VX7I27RA-vefJMKYp.js → diagram-VX7I27RA-DrWUeEXG.js} +1 -1
  105. package/out/renderer/assets/{diagram-Z3DM3KII-ChsgoF9h.js → diagram-Z3DM3KII-BxPy8fU9.js} +1 -1
  106. package/out/renderer/assets/{ebnfDiagram-PWID7BFC-D9X9DUcr.js → ebnfDiagram-PWID7BFC-BWqMH4I8.js} +1 -1
  107. package/out/renderer/assets/{erDiagram-RLTQ6QDP-C024iQV7.js → erDiagram-RLTQ6QDP-DTdklRgf.js} +1 -1
  108. package/out/renderer/assets/{flowDiagram-HODETNUW-CPVYCBuI.js → flowDiagram-HODETNUW-BKIZ7ju6.js} +1 -1
  109. package/out/renderer/assets/{ganttDiagram-EL5Y4UJY-C65Z220Q.js → ganttDiagram-EL5Y4UJY-BxvJsq6b.js} +1 -1
  110. package/out/renderer/assets/{gitGraphDiagram-WWUBYQGX-B2ZCfyVT.js → gitGraphDiagram-WWUBYQGX-CKYXaYvq.js} +1 -1
  111. package/out/renderer/assets/globals-DoK2OLv9.css +1 -0
  112. package/out/renderer/assets/globals-kfeSrZZh.js +2603 -0
  113. package/out/renderer/assets/{index-B49rZgqC.css → index-F_0FxVZ_.css} +1 -1
  114. package/out/renderer/assets/index-oWFcXlIg.js +133 -0
  115. package/out/renderer/assets/{infoDiagram-27XIBGKW-D7RgOT5Z.js → infoDiagram-27XIBGKW-B79kbTEz.js} +1 -1
  116. package/out/renderer/assets/{ishikawaDiagram-5VMMS53U-CEyzfHnV.js → ishikawaDiagram-5VMMS53U-7A2txHe5.js} +1 -1
  117. package/out/renderer/assets/{journeyDiagram-3NMN7TZE-C1GjLzvL.js → journeyDiagram-3NMN7TZE-JNKKQMwS.js} +1 -1
  118. package/out/renderer/assets/{kanban-definition-UXKFOSKX-umALrvd6.js → kanban-definition-UXKFOSKX-dK6zSfqM.js} +1 -1
  119. package/out/renderer/assets/{layout-CPiirD-6.js → layout-MfkXYuHA.js} +1 -1
  120. package/out/renderer/assets/{linear-DeKsEgmD.js → linear-DUiegqFS.js} +1 -1
  121. package/out/renderer/assets/{mermaid.core-upLR8Tou.js → mermaid.core-Dn6T9UVK.js} +5 -5
  122. package/out/renderer/assets/{mindmap-definition-YA3MSWOX-CDpc91To.js → mindmap-definition-YA3MSWOX-Du0yA8rg.js} +1 -1
  123. package/out/renderer/assets/{pegDiagram-XKGWAZYB-ZWCzr3Tm.js → pegDiagram-XKGWAZYB-DaRtM-Te.js} +1 -1
  124. package/out/renderer/assets/{pieDiagram-E7YTZNPT-Cli5NL_V.js → pieDiagram-E7YTZNPT-Bsf9CqyI.js} +1 -1
  125. package/out/renderer/assets/{quadrantDiagram-AXDQQJYC-DyHSkgko.js → quadrantDiagram-AXDQQJYC-Diojakd2.js} +1 -1
  126. package/out/renderer/assets/{railroadDiagram-O6MQD6OU-BifUAJjm.js → railroadDiagram-O6MQD6OU-BMREAMLm.js} +1 -1
  127. package/out/renderer/assets/{requirementDiagram-BXWQKSXE-4vjbe8oI.js → requirementDiagram-BXWQKSXE-KYN9y0mn.js} +1 -1
  128. package/out/renderer/assets/{sankeyDiagram-P5KCCOFB-BDHiusDD.js → sankeyDiagram-P5KCCOFB-BOarV1lP.js} +1 -1
  129. package/out/renderer/assets/{sequenceDiagram-WJ2MYXX4-CfTMNjuO.js → sequenceDiagram-WJ2MYXX4-CLvIIq-e.js} +1 -1
  130. package/out/renderer/assets/settings-C1ake4C5.js +27 -0
  131. package/out/renderer/assets/{sizeCapture-INFHLROL-BInsctow.js → sizeCapture-INFHLROL-BZp_C1e1.js} +1 -1
  132. package/out/renderer/assets/{stateDiagram-D77RDMKH-3R4s4xE6.js → stateDiagram-D77RDMKH-CZYezuvN.js} +1 -1
  133. package/out/renderer/assets/stateDiagram-v2-MP3YSRHH-BZR_zNTR.js +1 -0
  134. package/out/renderer/assets/{swimlanes-42K2YHIH-CHnfm1qW.js → swimlanes-42K2YHIH-BzLF-RZ8.js} +1 -1
  135. package/out/renderer/assets/swimlanesDiagram-VR7AAH4N-CguqA7f1.js +8 -0
  136. package/out/renderer/assets/{timeline-definition-24CTP7MA-BSOSQ438.js → timeline-definition-24CTP7MA-uG42f1oC.js} +1 -1
  137. package/out/renderer/assets/{vennDiagram-4TSXK5OY-Bw_mOynV.js → vennDiagram-4TSXK5OY-DTog5Yh9.js} +1 -1
  138. package/out/renderer/assets/{wardleyDiagram-VM6X3IG4-DZF4RS4h.js → wardleyDiagram-VM6X3IG4-BgQ7fmC4.js} +1 -1
  139. package/out/renderer/assets/{xychartDiagram-S5SC5T6Z-DwVUcf5G.js → xychartDiagram-S5SC5T6Z-BerG1RDT.js} +1 -1
  140. package/out/renderer/index.html +4 -4
  141. package/out/renderer/settings.html +4 -4
  142. package/out/renderer/web-preload.js +51 -1
  143. package/out/server/agent.js +1831 -355
  144. package/out/server/chunks/{agent-BlAuVqNp.js → agent-BbLTL3oo.js} +760 -191
  145. package/out/server/chunks/conversationsMove-CJZfkj55.js +57 -0
  146. package/out/server/chunks/{gpuBackendInstall-C0fP_8jk.js → gpuBackendInstall-DUOvnlWd.js} +5 -5
  147. package/out/server/chunks/{loadProvider-1NxA7GHt.js → loadProvider-79AJEjnd.js} +2 -2
  148. package/out/server/chunks/{manifest-CojWIAHB.js → manifest-DjsZzZuh.js} +63 -6
  149. package/out/server/chunks/{workflowPresets-COTLnY4e.js → workflowPresets-Di8u79iQ.js} +761 -298
  150. package/out/server/index.js +56416 -39536
  151. package/out/server/plugin-host.js +110 -3
  152. package/package.json +1 -1
  153. package/out/phone/assets/architecture-7GRP2DOG-yfAdIxfu.js +0 -1
  154. package/out/phone/assets/channel-D8BkMJGk.js +0 -1
  155. package/out/phone/assets/classDiagram-ZZMXUADV-CIHzXafb.js +0 -1
  156. package/out/phone/assets/classDiagram-v2-VYDZK3BY-CIHzXafb.js +0 -1
  157. package/out/phone/assets/desk-9dPB4fYu.js +0 -2
  158. package/out/phone/assets/eventmodeling-NTZA5JFV-CTu3xjKC.js +0 -1
  159. package/out/phone/assets/flowDiagram-HODETNUW-EMW1nWtZ.js +0 -1
  160. package/out/phone/assets/main-DYdpq0Gx.css +0 -1
  161. package/out/phone/assets/main-Do_3fZm7.js +0 -1643
  162. package/out/phone/assets/railroad-abnf-HS5TGJTU-C8SKwwnT.js +0 -1
  163. package/out/phone/assets/railroad-ebnf-LZEXJU2U-RhLt9QbJ.js +0 -1
  164. package/out/phone/assets/railroad-peg-WCYAUIDC-_H7Uu52_.js +0 -1
  165. package/out/phone/assets/stateDiagram-v2-MP3YSRHH-nNiD0itH.js +0 -1
  166. package/out/phone/assets/storage-p-WxHA1h.js +0 -1
  167. package/out/phone/assets/swimlanesDiagram-VR7AAH4N-Dz8lzRW1.js +0 -8
  168. package/out/renderer/assets/channel-BCPz1zGb.js +0 -1
  169. package/out/renderer/assets/classDiagram-ZZMXUADV-D5itFA4H.js +0 -1
  170. package/out/renderer/assets/classDiagram-v2-VYDZK3BY-D5itFA4H.js +0 -1
  171. package/out/renderer/assets/globals-B4auqknW.js +0 -2539
  172. package/out/renderer/assets/globals-biae1A0_.css +0 -1
  173. package/out/renderer/assets/index-XLAcGpdw.js +0 -117
  174. package/out/renderer/assets/settings-B1-ZqHbd.js +0 -34
  175. package/out/renderer/assets/stateDiagram-v2-MP3YSRHH-DqJbnbM3.js +0 -1
  176. package/out/renderer/assets/swimlanesDiagram-VR7AAH4N-Gz8US82e.js +0 -8
@@ -0,0 +1,27 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./globals-kfeSrZZh.js","./globals-DoK2OLv9.css"])))=>i.map(i=>d[i]);
2
+ import{c as Oe,w as vi,D as ea,j as e,A as bi,r as l,u as Or,a as Dr,b as vn,d as Lr,t as zr,C as sa,e as K,I as J,f as yi,X as js,h as wi,i as Ni,Z as cs,k as ki,S as Ci,l as Si,m as Ii,n as Ai,o as Ei,p as R,q as g,B as y,s as ye,v as we,x as Ne,y as ke,z as Ye,E as Ce,F as Le,G as Ee,H as _r,J as Te,K as ta,L as Mi,M as ut,N as mt,O as ne,P as ae,Q as re,R as oe,T as Z,U as Pi,V as Ze,W as Ti,Y as Ri,_ as Fr,$ as Oi,a0 as Rt,a1 as Br,a2 as Di,a3 as Ur,a4 as Li,a5 as na,a6 as $r,a7 as zi,a8 as _i,a9 as Fi,aa,ab as Bi,ac as Ui,ad as $i,ae as Vi,af as Gi,ag as Ki,ah as Wi,ai as Hi,aj as qi,ak as Yi,al as Ji,am as Ot,an as Xi,ao as Qi,ap as Zi,aq as el,ar as sl,as as tl,at as Me,au as bn,av as pt,aw as $e,ax as Vr,ay as Ms,az as Ve,aA as Ke,aB as yn,aC as Rs,aD as wn,aE as Nn,aF as kn,aG as Cn,aH as Sn,aI as In,aJ as An,aK as es,aL as ra,aM as oa,aN as ze,aO as Qe,aP as nl,aQ as al,aR as Gr,aS as ce,aT as ia,aU as Dt,aV as la,aW as ca,aX as ft,aY as rl,aZ as ol,a_ as Lt,a$ as Xs,b0 as Kr,b1 as En,b2 as il,b3 as Mn,b4 as Wr,b5 as ll,b6 as cl,b7 as dl,b8 as Hr,b9 as ul,ba as ml,bb as xl,bc as qr,bd as Ds,be as rt,bf as hl,bg as Pn,bh as pl,bi as fl,bj as Tn,bk as ns,bl as gl,bm as jl,bn as Yr,bo as vl,bp as bl,bq as yl,br as Jr,bs as Rn,bt as Re,bu as se,bv as Pe,bw as wl,bx as Nl,by as kl,bz as Cl,bA as Sl,bB as da,bC as Il,bD as Al,bE as Qs,bF as Zs,bG as Je,bH as Ws,bI as tn,bJ as El,bK as Ml,bL as nn,bM as hs,bN as Xr,bO as Pl,bP as Tl,bQ as On,bR as Rl,bS as ua,bT as Qr,bU as Ol,bV as Dl,bW as Zr,bX as Ge,bY as Ll,bZ as gt,b_ as zl,b$ as ma,c0 as _l,c1 as Fl,c2 as Bl,c3 as Xe,c4 as Ul,c5 as xa,c6 as ha,c7 as $l,c8 as pa,c9 as Vl,ca as Gl,cb as Kl,cc as Wl,cd as We,ce as zt,cf as fa,cg as Hl,ch as ql,ci as eo,cj as Yl,ck as so,cl as Jl,cm as Xl,cn as Ql,co as Zl,cp as Dn,cq as ec,cr as to,cs as sc,ct as tc,cu as et,cv as nc,cw as ac,cx as rc,cy as oc,cz as an,cA as no,cB as ot,cC as ic,cD as lc,cE as cc,cF as he,cG as pe,cH as Nt,cI as Ln,cJ as ao,cK as zn,cL as ro,cM as rn,cN as ga,cO as on,cP as oo,cQ as io,cR as dc,cS as lo,cT as uc,cU as mc,cV as xc,cW as hc,cX as pc,cY as fc,cZ as gc,c_ as jc,c$ as vc,d0 as bc,d1 as ja,d2 as co,d3 as uo,d4 as mo,d5 as xo,d6 as yc,d7 as wc,d8 as va,d9 as Hs,da as Nc,db as ho,dc as po,dd as fo,de as kc,df as Cc,dg as Sc,dh as Ic,di as Ac,dj as Ec,dk as Mc,dl as Pc,dm as Tc,dn as Rc,dp as Oc,dq as Dc,dr as go,ds as xt,dt as Ps,du as jo,dv as Lc,dw as ba,dx as zc,dy as _c,dz as Fc,dA as Bc,dB as Uc,dC as $c,dD as Vc,dE as Gc,dF as Kc,dG as Wc,dH as Hc,dI as ln,dJ as qc,dK as jt,dL as Yc,dM as _n,dN as vo,dO as bo,dP as Fn,dQ as yo,dR as wo,dS as No,dT as ko,dU as Co,dV as Jc,dW as Xc,dX as Qc,dY as Zc,dZ as ed,d_ as sd,d$ as td,e0 as nd,e1 as ad,e2 as rd,e3 as od,e4 as id,e5 as ld,e6 as cd,e7 as dd,e8 as ud,e9 as md,ea as xd,eb as hd,ec as So,ed as Io,ee as Ao,ef as pd,eg as Eo,eh as fd,ei as gd,ej as jd,ek as Mo,el as vd,em as bd,en as ya,eo as it,ep as yd,eq as wd,er as Nd,es as kd,et as Cd,eu as Sd,ev as wa,ew as Id,ex as Ad,ey as Ed,ez as Md,eA as Pd,eB as Td,eC as Rd,eD as Po,eE as Od,eF as Dd,eG as Ld,eH as vt,eI as zd,eJ as _d,eK as Fd,eL as Bd,eM as us,eN as Ud,eO as To,eP as $d,eQ as Vd,eR as Gd,eS as Kd,eT as Wd,eU as Hd,eV as qd,eW as Yd,eX as Jd,eY as Ro,eZ as Xd,e_ as Qd,e$ as Zd,f0 as eu,f1 as su,f2 as tu,f3 as nu,f4 as au,f5 as ru,f6 as ou,f7 as iu,f8 as lu,f9 as cu,fa as du,fb as uu,fc as mu,fd as xu,fe as Na,ff as hu,fg as pu,fh as ka,fi as Ca,fj as fu}from"./globals-kfeSrZZh.js";import{c as Oo}from"./cytoscape.esm-DzSz-X2X.js";import{f as gu}from"./cytoscape-fcose-DeHY1J1u.js";const ju=[["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"}]],vu=Oe("blocks",ju);const bu=[["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"}]],yu=Oe("book-open",bu);const wu=[["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"}]],Nu=Oe("box",wu);const ku=[["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"}]],Cu=Oe("chart-column",ku);const Su=[["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"}]],Iu=Oe("file-archive",Su);const Au=[["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"}]],Eu=Oe("file-pen-line",Au);const Mu=[["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"}]],Pu=Oe("flag",Mu);const Tu=[["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"}]],Ru=Oe("fold-vertical",Tu);const Ou=[["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"}]],Sa=Oe("heart",Ou);const Du=[["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"}]],Lu=Oe("image",Du);const zu=[["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"}]],Do=Oe("lock-keyhole",zu);const _u=[["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"}]],Fu=Oe("palette",_u);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"}]],Uu=Oe("shrink",Bu);const $u=[["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"}]],Vu=Oe("store",$u);const Gu=[["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=Oe("sun",Gu);const Wu=[["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"}]],Lo=Oe("upload",Wu);function Hu(s){return s&&typeof s=="object"&&!Array.isArray(s)?s:null}function qu(s){try{const t=new URL(s);return(t.protocol==="http:"||t.protocol==="https:")&&!t.username&&!t.password&&!t.search&&!t.hash&&!s.includes("?")&&!s.includes("#")}catch{return!1}}function Yu(s){const t=Hu(s);if(!t||Object.keys(t).some(m=>!["providerId","modelId","protocol","baseUrl","apiKey"].includes(m)))return null;const{providerId:n,modelId:a,protocol:r,baseUrl:o,apiKey:i}=t;return typeof n!="string"||!n.trim()||typeof a!="string"||!a.trim()||typeof i!="string"||!i.trim()||typeof o!="string"||!qu(o)||r!=="openai"&&r!=="openai-compatible"&&r!=="gemini"?null:{providerId:n,modelId:a,protocol:r,baseUrl:o,apiKey:i}}function Ju(s,t){if(s?.enabled!==!0||s.oauthAccountKey||s.oauthAccountPool||typeof s.apiKey!="string"||!s.apiKey.trim()||typeof s.baseUrl!="string")return null;let n;if(s.api==="google-generative-ai")n="gemini";else if(s.api==="openai-completions"||s.api==="openai-responses"){let o="";try{o=new URL(s.baseUrl).hostname.toLowerCase()}catch{}n=s.catalogId!=="__custom"&&(s.catalogId==="openai"||!s.catalogId&&o==="api.openai.com")?"openai":"openai-compatible"}else return null;const a=n==="gemini"?ea["google-generative-ai"]:n==="openai"?ea["openai-responses"]:"";let r=s.baseUrl.trim().replace(/\/+$/,"")||a;if(n==="gemini"&&r&&(r=vi(r,"v1beta")),n==="openai"&&r)try{new URL(r).pathname==="/"&&(r=`${r}/v1`)}catch{}return Yu({providerId:s.id,modelId:t,protocol:n,baseUrl:r,apiKey:s.apiKey})}function Xu(s){return Array.isArray(s?.models)?s.models.filter(t=>!!t&&typeof t=="object"&&typeof t.id=="string"&&!!t.id.trim()&&t.enabled!==!1&&t.imageGeneration===!0):[]}function Qu(s){return s.flatMap(t=>{const n=Xu(t).filter(a=>Ju(t,a.id));return n.length?[{...t,models:n}]:[]})}function Zu(s){const{multiple:t=!1,defaultValue:n,value:a,onValueChange:r,autoComplete:o,...i}=s;return e.jsx(bi,{...i,selectionMode:t?"multiple":"single",selectedValue:a,defaultSelectedValue:n,onSelectedValueChange:r,formAutoComplete:o})}const em=l.forwardRef(function(t,n){const{selected:a}=Or();return t.keepMounted||a?e.jsx(sm,{...t,ref:n}):null}),sm=l.memo(l.forwardRef((s,t)=>{const{render:n,className:a,style:r,keepMounted:o,...i}=s,{selected:m}=Or(),u=l.useRef(null),{transitionStatus:x,setMounted:h}=Dr(m),f=vn("span",s,{ref:[t,u],state:{selected:m,transitionStatus:x},props:[{"aria-hidden":!0,children:"✔️"},i],stateAttributesMapping:zr});return Lr({open:m,ref:u,onComplete(){m||h(!1)}}),f})),Bn=l.createContext({chipsRef:null,multiple:!1,rootRef:null});function tm(s){const t=l.useRef(null),n=l.useRef(null);return e.jsx(Bn.Provider,{value:{chipsRef:t,multiple:!!s.multiple,rootRef:n},children:e.jsx("div",{ref:n,className:"contents",children:e.jsx(Zu,{...s})})})}function nm({className:s,showTrigger:t=!0,showClear:n=!1,startAddon:a,size:r,...o}){const{multiple:i}=l.useContext(Bn),m=r??"default";return i?e.jsx(sa,{className:K("min-w-12 flex-1 text-base outline-none sm:text-sm [[data-slot=combobox-chip]+&]:ps-0.5",m==="sm"?"ps-1.5":"ps-2",s),"data-size":typeof m=="string"?m:void 0,"data-slot":"combobox-input",size:typeof m=="number"?m: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(sa,{className:K(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)]",m==="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",s),"data-slot":"combobox-input",render:e.jsx(J,{className:"has-disabled:opacity-100",size:m}),...o}),t&&e.jsx(am,{className:K("-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",m==="sm"?"end-0":"end-0.5"),children:e.jsx(yi,{})}),n&&e.jsx(lm,{className:K("-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",m==="sm"?"end-0":"end-0.5"),children:e.jsx(js,{})})]})}function am({className:s,...t}){return e.jsx(Ai,{className:s,"data-slot":"combobox-trigger",...t})}function rm({className:s,children:t,sideOffset:n=4,zIndex:a,...r}){const{chipsRef:o,rootRef:i}=l.useContext(Bn);let m=cs.DROPDOWN;if(a!==void 0)m=a;else{const u=i?.current;u&&(u.closest('[data-slot="dialog-popup"] [data-slot="dialog-popup"]')?m=cs.DROPDOWN_IN_NESTED_MODAL:u.closest('[data-slot="dialog-popup"]')&&(m=cs.DROPDOWN_IN_MODAL))}return e.jsx(wi,{children:e.jsx(Ni,{anchor:o,className:"select-none",style:{zIndex:m},"data-slot":"combobox-positioner",sideOffset:n,children:e.jsx("span",{className:K("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",s),children:e.jsx(ki,{className:"flex max-h-[min(var(--available-height),23rem)] w-(--anchor-width) max-w-(--available-width) flex-col","data-slot":"combobox-popup",...r,children:t})})})})}function om({className:s,children:t,endAddon:n,...a}){return e.jsxs(Ii,{className:K("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",s),"data-slot":"combobox-item",...a,children:[e.jsx(em,{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:t}),n&&e.jsx("div",{className:"col-start-3 flex items-center",children:n})]})}function im({className:s,...t}){return e.jsx(Ci,{scrollbarGutter:!0,scrollFade:!0,children:e.jsx(Si,{className:K("not-empty:scroll-py-1 not-empty:px-1 not-empty:py-1 in-data-has-overflow-y:pe-3",s),"data-slot":"combobox-list",...t})})}function lm({className:s,...t}){return e.jsx(Ei,{className:s,"data-slot":"combobox-clear",...t})}function cm(){const{t:s}=R(),t=g(d=>d.contextMenuOpen),n=g(d=>d.setContextMenuOpen),[a,r]=l.useState(!1),[o,i]=l.useState(!1),m=d=>d.target==="reveal"?s("File manager"):d.target==="vscode"?s("VS Code"):d.applicationPath.split(/[/\\]/).at(-1)?.replace(/\.(exe|app)$/i,"")||d.applicationPath,u=t.filter(d=>d.enabled).map(m),x=u.length?`${u.slice(0,2).join(", ")}${u.length>2?` +${u.length-2}`:""}`:s("No opening methods enabled"),h=d=>{if(d.length>32){Te({type:"error",title:s("Context menu opening"),description:s("You can configure up to 32 opening methods.")});return}n(d)},c=(d,p)=>{const j=g.getState().contextMenuOpen;n(j.map(b=>b.id===d.id?{...b,enabled:p}:b))},f=async()=>{i(!0);try{const d=await window.electronAPI.dialog.selectFile();if(!d)return;if(!_r(d)){Te({type:"error",title:s("Context menu opening"),description:s("The selected application path is invalid.")});return}const p=g.getState().contextMenuOpen,j=ta(d),b=p.find(A=>A.target==="application"&&ta(A.applicationPath)===j);if(b){h(p.map(A=>A.id===b.id?{...A,enabled:!0}:A));return}h([...p,{id:crypto.randomUUID(),target:"application",applicationPath:d,enabled:!0}])}catch(d){Te({type:"error",title:s("Context menu opening"),description:d instanceof Error?d.message:String(d)})}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:s("Context menu opening")}),e.jsx(y,{variant:"outline",size:"sm",onClick:()=>r(!0),children:s("Configure list")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("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(ye,{open:a,onOpenChange:r,children:e.jsxs(we,{zIndexLevel:"nested",children:[e.jsxs(Ne,{children:[e.jsx(ke,{children:s("Context menu opening")}),e.jsx(Ye,{children:s("Select the opening methods shown in file link context menus. You can add multiple applications.")})]}),e.jsxs(Ce,{className:"space-y-2",children:[t.length===0&&e.jsx("p",{className:"py-6 text-center text-sm text-muted-foreground",children:s("No opening methods enabled")}),t.map(d=>{const p=m(d);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(Le,{checked:d.enabled,disabled:o,"aria-label":p,onCheckedChange:j=>c(d,j)}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-sm",title:p,children:p}),d.target==="application"&&e.jsx("span",{className:"block truncate text-xs text-muted-foreground",title:d.applicationPath,children:d.applicationPath})]})]}),e.jsx(y,{variant:"ghost",size:"sm",disabled:o,onClick:()=>n(g.getState().contextMenuOpen.filter(j=>j.id!==d.id)),children:s("Delete")})]},d.id)})]}),e.jsxs(Ee,{children:[e.jsx(y,{variant:"outline",disabled:o,onClick:()=>{f()},children:s("Add application")}),e.jsx(y,{onClick:()=>r(!1),children:s("Close")})]})]})})]})}const Ia=["internal","reveal","system","application"];function Aa({extension:s,value:t,disabled:n,onChange:a}){const{t:r}=R(),o={internal:r("Open inside EnsoCode"),reveal:r("Reveal in file manager"),system:r("System default application"),application:r("Selected application")},i=ut(`file${s}`),m=mt(`file${s}`)!==null,u=i?m?["internal","reveal"]:["reveal"]:Ia,x=i&&(!m||t==="system"||t==="application")?"reveal":t;return e.jsxs(ne,{items:Object.fromEntries(u.map(h=>[h,o[h]])),value:x,disabled:n,onValueChange:h=>{Ia.includes(h)&&a(h)},children:[e.jsx(ae,{className:"w-52","aria-label":r("File opening"),children:e.jsx(re,{})}),e.jsx(oe,{children:u.map(h=>e.jsx(Z,{value:h,disabled:h==="internal"&&!m,children:o[h]},h))})]})}function dm(){const{t:s}=R(),t=g(k=>k.fileOpenRules),n=g(k=>k.setFileOpenRules),[a,r]=l.useState(""),[o,i]=l.useState("internal"),[m,u]=l.useState(),[x,h]=l.useState(null),[c,f]=l.useState(!1),d=Mi([{extension:a,target:"reveal"}])[0]?.extension,p=k=>{Te({type:"error",title:s("File opening"),description:k})},j=async k=>{f(!0);try{const I=await window.electronAPI.dialog.selectFile();if(I){if(!_r(I)){p(s("The selected application path is invalid."));return}k(I)}}catch(I){p(I instanceof Error?I.message:String(I))}finally{f(!1)}},b=k=>{const I=Pi(k);return I?(n(I),!0):(p(s("Could not complete the file action.")),!1)},A=(k,I,M)=>{if(I==="internal"&&!mt(`file${k.extension}`)){p(s("This extension does not support internal preview."));return}b(t.map($=>$.extension===k.extension?{extension:k.extension,target:I,...I==="application"?{applicationPath:M}:{}}:$))},v=()=>{if(!d){h(s("Enter a valid file extension, for example .md."));return}if(t.some($=>$.extension===d)){h(s("This extension already has an opening rule."));return}const k=ut(`file${d}`),I=mt(`file${d}`)!==null,M=k&&(!I||o==="system"||o==="application")?"reveal":o;if(M==="internal"&&!mt(`file${d}`)){p(s("This extension does not support internal preview."));return}if(M==="application"&&!m){h(s("Choose an application before saving this rule."));return}b([...t,{extension:d,target:M,...M==="application"?{applicationPath:m}:{}}])&&(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:s("File opening")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Configure how local workspace file links open by extension.")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("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:s("Executable and installer files are always revealed in the file manager.")})]}),e.jsx(cm,{}),t.map(k=>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:k.extension}),e.jsx(Aa,{extension:k.extension,value:k.target,disabled:c,onChange:I=>{I==="application"?j(M=>A(k,I,M)):A(k,I)}}),k.target==="application"&&!ut(`file${k.extension}`)&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-xs text-muted-foreground",title:k.applicationPath,children:k.applicationPath}),e.jsx(y,{variant:"outline",size:"sm",disabled:c,onClick:()=>{j(I=>A(k,"application",I))},children:s("Choose application")})]}),e.jsx(y,{variant:"ghost",size:"sm",disabled:c,onClick:()=>b(t.filter(I=>I.extension!==k.extension)),children:s("Delete")})]},k.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":s("File extension"),disabled:c,onChange:k=>{r(k.target.value),h(null)},onKeyDown:k=>{k.key==="Enter"&&v()}}),e.jsx(Aa,{extension:d??".md",value:o,disabled:c,onChange:k=>{i(k),h(null)}}),e.jsx(y,{variant:"outline",size:"sm",disabled:c,onClick:v,children:s("Add")})]}),o==="application"&&!ut(`file${d??".md"}`)&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{variant:"outline",size:"sm",disabled:c,onClick:()=>{j(k=>{u(k),h(null)})},children:s("Choose application")}),e.jsx("span",{className:"min-w-0 truncate text-xs text-muted-foreground",title:m,children:m})]}),x&&e.jsx("p",{role:"alert",className:"text-xs text-destructive",children:x})]})]})}const um=["pem","crt","cer"];function mm(s){return/^\//.test(s)||/^[A-Za-z]:[\\/]/.test(s)||/^\\\\[^\\]/.test(s)}const xm=16384,zo=4096,_o=65536;function hm(s){return s===null?null:typeof s=="number"&&Number.isInteger(s)&&s>=zo&&s<=_o?s:void 0}function pm(s){const t=s.trim();return t?/^\d+$/.test(t)?hm(Number(t)):void 0:null}function fm(){const{t:s}=R(),[t,n]=l.useState(null),[a,r]=l.useState(""),[o,i]=l.useState(null);l.useEffect(()=>{let u=!1;return window.electronAPI.compaction.getReserveTokens().then(x=>{u||(n(x),r(x===null?"":String(x)))}),()=>{u=!0}},[]);const m=async()=>{const u=pm(a);if(u===void 0){i(s("Enter a whole number between {{min}} and {{max}}, or leave it empty.",{min:zo,max:_o}));return}if(i(null),u===t)return;if(!(await window.electronAPI.compaction.setReserveTokens(u)).ok){i(s("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:[s("Compaction reserve tokens"),e.jsx(Ze,{})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("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(xm),"aria-label":s("Compaction reserve tokens"),onChange:u=>r(u.target.value),onBlur:()=>{m()},onKeyDown:u=>{u.key==="Enter"&&m()}}),o&&e.jsx("p",{className:"text-xs text-destructive",children:o})]})]})}function cn({className:s,render:t,...n}){const a={className:K("inline-flex items-center gap-2 text-base/4.5 sm:text-sm/4 font-medium",s),"data-slot":"label"};return Ti({defaultTagName:"label",props:Ri(a,n),render:t})}const dn={checked(s){return s?{"data-checked":""}:{"data-unchecked":""}},...zr,...Fr},Fo=l.createContext(void 0);function gm(){return l.useContext(Fo)}const Bo=l.createContext(void 0);function jm(){const s=l.useContext(Bo);if(s===void 0)throw new Error(Oi(52));return s}const vm=l.forwardRef(function(t,n){const{render:a,className:r,disabled:o=!1,readOnly:i=!1,required:m=!1,"aria-labelledby":u,value:x,inputRef:h,nativeButton:c=!1,id:f,style:d,...p}=t,j=gm(),{disabled:b,readOnly:A,required:v,form:k,checkedValue:I,touched:M=!1,validation:$,name:E,setCheckedValue:L=Rt,setTouched:T=Rt,registerInputRef:C=Rt}=j??{},{setTouched:S,setFilled:W,state:q,disabled:N}=Br(),z=Di(),{labelId:H,getDescriptionProps:U}=Ur(),B=N||z.disabled||b||o,ie=A||i,F=v||m,X=k,V=j?I===x:x==="",le=l.useRef(null),_=l.useRef(null),de=$?.registerInput,ue=l.useCallback(ge=>de?.(ge,{controlRef:le,value:void 0}),[de]),O=Li(h,_,C,ue);na(()=>{_.current?.checked&&W(!0)},[W]),na(()=>{if(_.current){if(B&&V){C(null);return}C(_.current)}},[V,B,C]);const De=$r(),te=zi({id:f,implicit:!1,controlRef:le}),P=c?void 0:te,Y=_i(u,H,_,!c,P),D={role:"radio","aria-checked":V,"aria-labelledby":Y,[Ki]:V?"":void 0,id:c?te:De,onKeyDown(ge){ge.key==="Enter"&&ge.preventDefault()},onClick(ge){if(ge.defaultPrevented||B||ie)return;ge.preventDefault();const as=_.current;as&&Gi(as,ge)},onFocus(ge){ge.defaultPrevented||B||ie||!M||(_.current?.click(),T(!1))}},{getButtonProps:Q,buttonRef:ee}=Fi({disabled:B,native:c,composite:!1}),fe={type:"radio",ref:O,form:X,id:P,name:E,tabIndex:-1,style:E?$i:Vi,"aria-hidden":!0,...x!==void 0?{value:Bi(x)}:aa,disabled:B,checked:V,required:F,readOnly:ie,onChange(ge){if(ge.nativeEvent.defaultPrevented||B||ie||x===void 0)return;const as=Wi(Hi,ge.nativeEvent);L(x,as),!as.isCanceled&&S(!0)},onClick(ge){ge.stopPropagation()},onFocus(){le.current?.focus()}},xe=l.useMemo(()=>({...q,required:F,disabled:B,readOnly:ie,checked:V}),[q,B,ie,V,F]),Ls=xe,ds=j!==void 0,vs=[n,le,ee],He=[D,p,Q,U,$?ge=>$.getValidationProps(B,ge):aa],zs=vn("span",t,{enabled:!ds,state:xe,ref:vs,props:He,stateAttributesMapping:dn});return e.jsxs(Bo.Provider,{value:Ls,children:[ds?e.jsx(Ui,{tag:"span",render:a,className:r,style:d,state:xe,refs:vs,props:He,stateAttributesMapping:dn}):zs,e.jsx("input",{...fe,suppressHydrationWarning:!0})]})}),bm=l.forwardRef(function(t,n){const{render:a,className:r,style:o,keepMounted:i=!1,...m}=t,u=jm(),x=u.checked,{mounted:h,transitionStatus:c,setMounted:f}=Dr(x),d={...u,transitionStatus:c},p=l.useRef(null),j=i||h,b=vn("span",t,{ref:[n,p],state:d,props:m,stateAttributesMapping:dn});return Lr({open:x,ref:p,onComplete(){x||f(!1)}}),j?b:null}),ym=[sl],wm=l.forwardRef(function(t,n){const{render:a,className:r,disabled:o,readOnly:i,required:m,onValueChange:u,value:x,defaultValue:h,form:c,name:f,inputRef:d,id:p,style:j,...b}=t,{setTouched:A,setFocused:v,validationMode:k,name:I,disabled:M,state:$,validation:E,setDirty:L,setFilled:T,validityData:C}=Br(),{labelId:S}=Ur(),{clearErrors:W,elementRef:q}=qi(),N=Yi(!0),z=M||o,H=I??f,U=$r(p),[B,ie]=Ji({controlled:x,default:h,name:"RadioGroup",state:"value"}),[F,X]=l.useState(!1),V=Ot((ee,fe)=>{u?.(ee,fe),!fe.isCanceled&&ie(ee)}),le=E.getInputControl,_=l.useMemo(()=>({get current(){return le()}}),[le]),de=l.useRef(null),ue=l.useRef(null);function O(ee){let fe;return d&&(typeof d=="function"?fe=d(ee):d.current=ee),de.current=ee,fe}const De=Ot(ee=>{if(!ee||ee.disabled)return;ue.current||(ue.current=ee);const fe=de.current,xe=ee.checked||fe==null||fe.disabled?O(ee):void 0;return()=>{ue.current===ee&&(ue.current=null),de.current===ee?xe?(xe(),de.current=null):O(null):xe?.()}}),te=Ot(()=>{const ee=q.current;if(!ee)return B??null;for(const fe of E.registeredInputs.keys())if(fe.checked&&Xi(fe,ee))return B??null;return null});Qi(_,U,B??null,te,!z,f),Zi(B,()=>{W(H),L(B!==C.initialValue),T(B!=null),E.change(B);const ee=ue.current;B==null&&ee&&!ee.disabled&&O(ee)});const P=S??N?.legendId,Y={...$,disabled:z??!1,required:m??!1,readOnly:i??!1},D=l.useMemo(()=>({checkedValue:B,disabled:z,form:c,validation:E,name:H,readOnly:i,registerInputRef:De,required:m,setCheckedValue:V,setTouched:X,touched:F}),[B,z,c,E,H,i,De,m,V,X,F]),Q={id:p,role:"radiogroup","aria-required":m||void 0,"aria-disabled":z||void 0,"aria-readonly":i||void 0,"aria-labelledby":P,onFocus(){v(!0)},onBlur(ee){tl(ee.currentTarget,ee.relatedTarget)||(A(!0),v(!1),k==="onBlur"&&E.commit(B))},onKeyDownCapture(ee){ee.key.startsWith("Arrow")&&(X(!0),v(!0))}};return e.jsx(Fo.Provider,{value:D,children:e.jsx(el,{render:a,className:r,style:j,state:Y,props:[Q,b,ee=>E.getValidationProps(z??!1,ee)],refs:[n],stateAttributesMapping:Fr,enableHomeAndEndKeys:!1,modifierKeys:ym})})});function Nm({className:s,...t}){return e.jsx(wm,{className:K("flex flex-col gap-3",s),"data-slot":"radio-group",...t})}function Ea({className:s,...t}){return e.jsx(vm,{className:K("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",s),"data-slot":"radio",...t,children:e.jsx(bm,{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 km=[{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 Cm(){const{t:s}=R(),[t,n]=l.useState(!1),[a,r]=l.useState(!1),[o,i]=l.useState(null),[m,u]=l.useState(null),x=()=>{i(null),n(!0)},h=async()=>{r(!0),i(null);try{const c=await window.electronAPI.configSync.openImport();if(!c.ok){i({kind:c.cancelled?"cancelled":"error",text:c.cancelled?s("Import cancelled."):s(c.error)});return}u(c)}catch{i({kind:"error",text:s("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:s("Configuration transfer")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("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(Iu,{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:s("Portable Enso configuration")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Export a package or preview one before importing it.")})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsxs(y,{variant:"outline",size:"sm",disabled:a,onClick:h,children:[a?e.jsx(Me,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(bn,{className:"h-3.5 w-3.5"}),s("Import configuration")]}),e.jsxs(y,{size:"sm",disabled:a,onClick:x,children:[e.jsx(Lo,{className:"h-3.5 w-3.5"}),s("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(pt,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),e.jsx("p",{children:s("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(Sm,{open:t,onOpenChange:n}),m&&e.jsx(Im,{file:m,onClose:()=>u(null)})]})}function Sm({open:s,onOpenChange:t}){const{t:n}=R(),[a,r]=l.useState(!1),[o,i]=l.useState(""),[m,u]=l.useState(""),[x,h]=l.useState(!1),[c,f]=l.useState(null),[d,p]=l.useState(!1),[j,b]=l.useState(null),[A,v]=l.useState([]);l.useEffect(()=>{s&&(r(!1),i(""),u(""),h(!1),f(null),p(!1),b(null),v([]))},[s]);const k=()=>{x||(i(""),u(""),t(!1))},I=async()=>{if(a&&o.length<8){f(n("Password must be at least 8 characters."));return}if(a&&o!==m){f(n("Passwords do not match."));return}h(!0),f(null),p(!1);try{const M=await window.electronAPI.configSync.exportConfig({includeSecrets:a,...a?{password:o}:{}});if(i(""),u(""),!M.ok){M.cancelled?p(!0):f(n(M.error));return}b(M.filePath),v(M.skippedInstructions??[])}catch{i(""),u(""),f(n("Could not export configuration."))}finally{h(!1)}};return e.jsx(ye,{open:s,onOpenChange:M=>!M&&k(),children:e.jsxs(we,{className:"max-w-xl",showCloseButton:!x,children:[e.jsxs(Ne,{children:[e.jsx(ke,{children:n("Export configuration")}),e.jsx(Ye,{children:n("Create a portable .enso-config package for another device.")})]}),e.jsx(Ce,{className:"max-h-[55vh] space-y-4",children:j?e.jsxs(e.Fragment,{children:[e.jsxs($e,{variant:"success",children:[e.jsx(Vr,{}),e.jsx(Ms,{children:n("Configuration exported")}),e.jsxs(Ve,{children:[e.jsx("p",{children:n("Saved package:")}),e.jsx("p",{className:"break-all font-mono text-xs text-foreground",children:j})]})]}),A.length>0&&e.jsxs($e,{variant:"warning",children:[e.jsx(Ke,{}),e.jsxs(Ve,{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:A.join(", ")})]})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs($e,{variant:"warning",children:[e.jsx(yn,{}),e.jsx(Ms,{children:n("File contents can be private")}),e.jsx(Ve,{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(Le,{checked:a,onCheckedChange:M=>{const $=M===!0;r($),f(null),$||(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(pt,{}),e.jsx(Ve,{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(Do,{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(cn,{htmlFor:"config-export-password",children:n("Password")}),e.jsx(J,{id:"config-export-password",type:"password",autoComplete:"new-password",value:o,"aria-invalid":!!(c&&o.length<8),onChange:M=>{i(M.target.value),f(null)}})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(cn,{htmlFor:"config-export-confirmation",children:n("Confirm password")}),e.jsx(J,{id:"config-export-confirmation",type:"password",autoComplete:"new-password",value:m,"aria-invalid":!!(c&&m!==o),onChange:M=>{u(M.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.")})]}),d&&e.jsx("p",{className:"text-xs text-muted-foreground",role:"status",children:n("Export cancelled.")}),c&&e.jsxs("p",{className:"flex items-center gap-1.5 text-xs text-destructive",role:"alert",children:[e.jsx(Rs,{className:"h-3.5 w-3.5 shrink-0"}),c]})]})}),e.jsx(Ee,{children:j?e.jsx(y,{size:"sm",onClick:k,children:n("Done")}):e.jsxs(e.Fragment,{children:[e.jsx(y,{variant:"outline",size:"sm",disabled:x,onClick:k,children:n("Cancel")}),e.jsxs(y,{size:"sm",disabled:x,onClick:()=>{I()},children:[x?e.jsx(Me,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Lo,{className:"h-3.5 w-3.5"}),n(x?"Exporting…":"Export")]})]})})]})})}function Im({file:s,onClose:t}){const{t:n}=R(),[a,r]=l.useState(s.encrypted?"password":"preview"),[o,i]=l.useState(""),[m,u]=l.useState("merge"),[x,h]=l.useState(null),[c,f]=l.useState([]),[d,p]=l.useState(null),[j,b]=l.useState(!1),[A,v]=l.useState(null),[k,I]=l.useState(null),[M,$]=l.useState(!1),E=l.useRef(0),L=l.useCallback(async(N,z)=>{const H=++E.current;v("preview"),I(null),h(null),f([]);try{const U=await window.electronAPI.configSync.previewImport({token:s.token,mode:N,...z?{password:z}:{}});if(H!==E.current)return;if(i(""),!U.ok){I(n(U.error));return}u(U.mode),h(U.summary),f(U.warnings),r("preview")}catch{H===E.current&&(i(""),I(n("Could not preview configuration package.")))}finally{H===E.current&&v(null)}},[s.token,n]);l.useEffect(()=>{s.encrypted||L("merge")},[s.encrypted,L]);const T=()=>{A||(E.current+=1,$(!1),i(""),window.electronAPI.configSync.cancelImport(s.token).catch(()=>{}),t())},C=N=>{N===m||A||(u(N),L(N))},S=!!x?.some(N=>(N.category==="skills"||N.category==="mcpServers")&&N.added+N.updated+N.skipped>0),W=x!==null,q=async()=>{if(x){v("commit"),I(null);try{const N=await window.electronAPI.configSync.commitImport({token:s.token,mode:m});if(!N.ok){h(null),f([]),I(n(N.error));return}i("");try{await g.persist.rehydrate()}catch{b(!0)}f(N.warnings),p(N.backupPath),r("success")}catch{h(null),f([]),I(n("Could not import configuration."))}finally{v(null)}}};return e.jsxs(ye,{open:!0,onOpenChange:N=>!N&&T(),children:[e.jsxs(we,{className:"max-w-2xl",showCloseButton:A===null,children:[e.jsxs(Ne,{children:[e.jsx(ke,{children:n(a==="success"?"Configuration imported":"Import configuration")}),e.jsx(Ye,{children:a==="success"?n(j?"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:s.fileName})})]}),a==="password"&&e.jsxs(Ce,{className:"space-y-4",children:[e.jsxs($e,{variant:"info",children:[e.jsx(Do,{}),e.jsx(Ms,{children:n("Encrypted configuration package")}),e.jsx(Ve,{children:n("Enter the export password to decrypt and preview this package.")})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(cn,{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":!!k,onChange:N=>{i(N.target.value),I(null)},onKeyDown:N=>{N.key==="Enter"&&o.length>0&&!A&&L("merge",o)}})]}),k&&e.jsxs("p",{className:"flex items-center gap-1.5 text-xs text-destructive",role:"alert",children:[e.jsx(Rs,{className:"h-3.5 w-3.5 shrink-0"}),k]})]}),a==="preview"&&e.jsxs(Ce,{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(Nm,{value:m,onValueChange:N=>C(N),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(Ea,{value:"merge",disabled:A!==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(Ea,{value:"replace",disabled:A!==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.")})]})]})]})]}),A==="preview"&&e.jsxs("div",{className:"flex items-center justify-center gap-2 rounded-md border border-dashed py-10",children:[e.jsx(Me,{className:"h-4 w-4 animate-spin text-muted-foreground"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:n("Preparing preview…")})]}),!A&&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:km.map(({category:N,label:z})=>{const H=x.find(U=>U.category===N);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(z)}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:H?.added??0}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:H?.updated??0}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:H?.skipped??0}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:H?.removed??0})]},N)})})]})}),!A&&x?.find(N=>N.category==="settings")?.fields?.length?e.jsxs("p",{className:"text-xs text-muted-foreground",children:[n("Portable settings changed:")," ",x.find(N=>N.category==="settings")?.fields?.join(", ")]}):null,m==="replace"&&x&&!A&&e.jsxs($e,{variant:"error",children:[e.jsx(Ke,{}),e.jsx(Ms,{children:n("Local-only configuration will be deleted")}),e.jsx(Ve,{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.")})]}),c.map(N=>e.jsxs($e,{variant:"warning",children:[e.jsx(Ke,{}),e.jsx(Ve,{children:n(N)})]},N)),x&&!A&&e.jsxs($e,{variant:"warning",children:[e.jsx(yn,{}),e.jsx(Ms,{children:n("Only import packages you trust")}),e.jsx(Ve,{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.")})]}),k&&e.jsxs($e,{variant:"error",children:[e.jsx(Rs,{}),e.jsx(Ve,{children:k})]})]}),a==="success"&&d&&e.jsxs(Ce,{className:"space-y-4",children:[e.jsxs($e,{variant:"success",children:[e.jsx(Vr,{}),e.jsx(Ms,{children:n("Import complete")}),e.jsxs(Ve,{children:[e.jsx("p",{children:n("Backup of previous settings:")}),e.jsx("p",{className:"break-all font-mono text-xs text-foreground",children:d})]})]}),j&&e.jsxs($e,{variant:"warning",children:[e.jsx(Ke,{}),e.jsx(Ve,{children:n("Reopen Settings to load the imported configuration in this window.")})]}),c.map(N=>e.jsxs($e,{variant:"warning",children:[e.jsx(Ke,{}),e.jsx(Ve,{children:n(N)})]},N))]}),e.jsxs(Ee,{children:[a==="password"&&e.jsxs(e.Fragment,{children:[e.jsx(y,{variant:"outline",size:"sm",disabled:A!==null,onClick:T,children:n("Cancel")}),e.jsxs(y,{size:"sm",disabled:A!==null||o.length===0,onClick:()=>{L("merge",o)},children:[A==="preview"&&e.jsx(Me,{className:"h-3.5 w-3.5 animate-spin"}),n("Preview")]})]}),a==="preview"&&e.jsxs(e.Fragment,{children:[e.jsx(y,{variant:"outline",size:"sm",disabled:A!==null,onClick:T,children:n("Cancel")}),k&&!x?e.jsx(y,{size:"sm",disabled:A!==null,onClick:()=>{L(m)},children:n("Refresh preview")}):e.jsxs(y,{variant:m==="replace"?"destructive":"default",size:"sm",disabled:A!==null||!x,onClick:()=>{x&&(W?$(!0):q())},children:[A==="commit"?e.jsx(Me,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(bn,{className:"h-3.5 w-3.5"}),n(A==="commit"?"Importing…":"Import")]})]}),a==="success"&&e.jsx(y,{size:"sm",onClick:T,children:n("Done")})]})]}),e.jsx(Am,{open:M,mode:m,hasImportedExecutableResources:S,onOpenChange:$,onConfirm:()=>{q()}})]})}function Am({open:s,mode:t,hasImportedExecutableResources:n,onOpenChange:a,onConfirm:r}){const{t:o}=R();return e.jsx(wn,{open:s,onOpenChange:a,children:e.jsxs(Nn,{className:"sm:max-w-md",zIndexLevel:"nested",children:[e.jsxs(kn,{children:[e.jsxs(Cn,{className:"flex items-start gap-2 text-base",children:[e.jsx(Ke,{className:"mt-0.5 h-4 w-4 shrink-0 text-destructive"}),o("Confirm configuration import")]}),e.jsxs(Sn,{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.")}),t==="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(In,{variant:"bare",children:[e.jsx(An,{render:e.jsx(y,{variant:"outline",size:"sm"}),children:o("Cancel")}),e.jsx(y,{variant:t==="replace"?"destructive":"default",size:"sm",onClick:()=>{a(!1),r()},children:o("Confirm import")})]})]})})}const Ma={auto:"Auto (by usage)",fast:"Fast",balanced:"Balanced",thorough:"Thorough"},Pa={standard:"Standard",smart:"Smart compaction","codex-native":"Codex native compaction","continuous-memory":"Continuous memory (experimental)"};function Em(){const{t:s}=R(),t=g(d=>d.compactStrategy),n=g(d=>d.smartCompactEnabled),a=nl(t,n),r=g(d=>d.setCompactStrategy),o=a!=="standard",i=g(d=>d.smartCompactModel),m=g(d=>d.setSmartCompactModel),u=g(d=>d.smartCompactMode),x=g(d=>d.setSmartCompactMode),h=es(),c=i?h.find(d=>d.id===i.providerId):void 0,f=c?.models.find(d=>d.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:[s("Context compaction strategy"),e.jsx(Ze,{})]}),e.jsx("p",{className:"mt-0.5 text-muted-foreground text-xs",children:s("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(ne,{items:Object.fromEntries(ra.map(d=>[d,s(Pa[d])])),value:a,onValueChange:d=>r(d),children:[e.jsx(ae,{className:"w-52",children:e.jsx(re,{})}),e.jsx(oe,{children:ra.map(d=>e.jsx(Z,{value:d,children:s(Pa[d])},d))})]})]}),(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:s("Compaction mode")}),e.jsx("p",{className:"mt-0.5 text-muted-foreground/80 text-[11px]",children:s("Mode changes summary budget and how much recent tail to keep. It does not decide whether compact runs.")})]}),e.jsxs(ne,{items:Object.fromEntries(oa.map(d=>[d,s(Ma[d])])),value:u,onValueChange:d=>x(d),children:[e.jsx(ae,{className:"w-36",children:e.jsx(re,{})}),e.jsx(oe,{children:oa.map(d=>e.jsx(Z,{value:d,children:s(Ma[d])},d))})]})]}),o&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"font-medium text-sm",children:s(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:c?.id??"",modelId:f?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:s("Follows the session model"),side:"bottom",triggerClassName:Qe,onSelect:(d,p)=>m({providerId:d,modelId:p}),onReasoningChange:()=>{},onThinkingChange:()=>{}})}),i&&(!c||!f)&&e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Selected model is unavailable — falls back to the session model.")}),i&&e.jsx(y,{variant:"ghost",size:"sm",className:"self-start",onClick:()=>m(null),children:s("Follow session model")})]})]})}const Mm={cmd:"Command Prompt",powershell:"Windows PowerShell",pwsh:"PowerShell 7 (pwsh)","git-bash":"Git Bash",zsh:"zsh",bash:"bash",fish:"fish"};function Pm(){const{language:s,setLanguage:t}=g(),{t:n}=R();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(ne,{items:{en:"English",zh:"简体中文"},value:s,onValueChange:a=>t(a),children:[e.jsx(ae,{className:"w-48",children:e.jsx(re,{})}),e.jsxs(oe,{children:[e.jsx(Z,{value:"en",children:"English"}),e.jsx(Z,{value:"zh",children:"简体中文"})]})]})]}),e.jsx(Tm,{}),e.jsx(Bm,{}),e.jsx(Um,{}),e.jsx(Cm,{}),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(Rm,{}),e.jsx(Om,{}),e.jsx(Em,{}),e.jsx(fm,{})]}),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(Lm,{}),e.jsx(Dm,{}),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("Terminal")}),e.jsx(Fm,{}),e.jsx(zm,{})]}),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(Ta,{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(Ta,{kind:"finderQuickAction",title:n("Finder Quick Action"),description:n("Right-click a folder in Finder and choose Services > Open with EnsoCode.")})]})]})}function Ta({kind:s,title:t,description:n}){const{t:a}=R(),[r,o]=l.useState(!1),[i,m]=l.useState(!1);l.useEffect(()=>{let x=!0;const h=()=>{window.electronAPI.window.shellIntegrationStatus().then(c=>{x&&o(c[s])})};return h(),window.addEventListener("focus",h),()=>{x=!1,window.removeEventListener("focus",h)}},[s]);const u=async()=>{m(!0);try{await window.electronAPI.window.installShellIntegration(s)}finally{try{const x=await window.electronAPI.window.shellIntegrationStatus();o(x[s])}finally{m(!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.${s}`,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:n})]}),e.jsx(y,{variant:"outline",size:"sm",className:"shrink-0",disabled:i,onClick:()=>{u()},children:a(i?"In progress…":r?"Uninstall":"Install")})]})}function Tm(){const{t:s}=R(),t=g(a=>a.notifyMainAgentOnly),n=g(a=>a.setNotifyMainAgentOnly);return e.jsx(Ie,{rowId:"general.notifyMainAgentOnly",title:s("Notify only for the main agent"),description:s("Skip coworker completion and failure notifications on this computer and the paired phone. Questions and approvals still notify."),checked:t,onChange:n})}function Rm(){const{t:s}=R(),t=g(a=>a.generationStallTimeoutMin),n=g(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:s("Stop if no output")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Abort and retry the run when no tokens or tool results arrive for this long. Thinking counts as output.")})]}),e.jsxs(ne,{items:Object.fromEntries(ia.map(a=>[String(a),a===0?s("Never"):s("{{count}} min",{count:a})])),value:String(t),onValueChange:a=>n(Number(a)),children:[e.jsx(ae,{className:"w-28",children:e.jsx(re,{})}),e.jsx(oe,{children:ia.map(a=>e.jsx(Z,{value:String(a),children:a===0?s("Never"):s("{{count}} min",{count:a})},a))})]})]})}function Om(){const{t:s}=R(),t=g(o=>o.autoRetryLimit),n=g(o=>o.setAutoRetryLimit),a=Dt.some(o=>o===t)?[...Dt]:[...Dt,t].sort((o,i)=>o===Lt?1:i===Lt?-1:o-i),r=o=>o===0?s("Off"):o===Lt?s("Unlimited"):s("{{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:s("Auto-retry on transient errors")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("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(ne,{items:Object.fromEntries(a.map(o=>[String(o),r(o)])),value:String(t),onValueChange:o=>n(Number(o)),children:[e.jsx(ae,{className:"w-28",children:e.jsx(re,{})}),e.jsx(oe,{children:a.map(o=>e.jsx(Z,{value:String(o),children:r(o)},o))})]})]})}function Dm(){const{t:s}=R(),t=g(r=>r.activeRetentionMinutes),n=g(r=>r.setActiveRetentionMinutes),a=r=>r===0?s("Off"):s("{{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:s("Keep in Active after last message")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("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(ne,{items:Object.fromEntries(ft.map(r=>[String(r),a(r)])),value:String(t),onValueChange:r=>n(Number(r)),children:[e.jsx(ae,{className:"w-28",children:e.jsx(re,{})}),e.jsx(oe,{children:ft.map(r=>e.jsx(Z,{value:String(r),children:a(r)},r))})]})]})}function lt(s,t){return t===0?s("Never"):t===1?s("{{count}} day",{count:t}):s("{{count}} days",{count:t})}function Lm(){const{t:s}=R(),t=g(m=>m.autoArchiveIdleDays),n=g(m=>m.setAutoArchiveIdleDays),a=g(m=>m.autoArchiveMergedWorktrees),r=g(m=>m.setAutoArchiveMergedWorktrees),o=g(m=>m.autoDeleteArchivedDays),i=g(m=>m.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:s("Archive idle conversations")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Move conversations that have been idle this long into Archived. Does not delete them.")})]}),e.jsxs(ne,{items:Object.fromEntries(la.map(m=>[String(m),lt(s,m)])),value:String(t),onValueChange:m=>n(Number(m)),children:[e.jsx(ae,{className:"w-28",children:e.jsx(re,{})}),e.jsx(oe,{children:la.map(m=>e.jsx(Z,{value:String(m),children:lt(s,m)},m))})]})]}),e.jsx(Ie,{rowId:"general.autoArchiveMergedWorktrees",title:s("Clean up merged worktrees"),description:s("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:s("Delete archived conversations after")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("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(ne,{items:Object.fromEntries(ca.map(m=>[String(m),lt(s,m)])),value:String(o),onValueChange:m=>i(Number(m)),children:[e.jsx(ae,{className:"w-28",children:e.jsx(re,{})}),e.jsx(oe,{children:ca.map(m=>e.jsx(Z,{value:String(m),children:lt(s,m)},m))})]})]})]})}function zm(){const{t:s}=R(),t=g(o=>o.terminalShell),n=g(o=>o.setTerminalShell),a=rl(window.electronAPI.env.platform),r=Object.fromEntries(a.map(o=>[o,o==="auto"?s("System default"):Mm[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:s("Terminal shell")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Applies to new side panel terminals. SSH projects keep the remote login shell.")})]}),e.jsxs(ne,{items:r,value:t,onValueChange:o=>n(o),children:[e.jsx(ae,{className:"w-56",children:e.jsx(re,{})}),e.jsx(oe,{children:a.map(o=>e.jsx(Z,{value:o,children:r[o]},o))})]})]})}function _m(){const{t:s}=R(),t=g(x=>x.worktreeRoot),n=g(x=>x.setWorktreeRoot),[a,r]=l.useState(t),[o,i]=l.useState(null);l.useEffect(()=>{r(t)},[t]);const m=x=>{const h=x.trim();if(h&&!mm(h)){i(s("Enter an absolute path"));return}i(null),n(h)},u=async()=>{const x=await window.electronAPI.dialog.selectDirectory();x&&(r(x),m(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:s("Worktree root directory")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("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:s("Default location"),onChange:x=>r(x.target.value),onBlur:()=>m(a),onKeyDown:x=>{x.key==="Enter"&&m(a)}}),e.jsx(y,{variant:"outline",size:"sm",className:"shrink-0",onClick:()=>{u()},children:s("Browse")})]}),o&&e.jsx("p",{className:"text-xs text-destructive",children:o})]})]})}function Fm(){const{t:s}=R(),t=g(r=>r.windowsLocalShell),n=g(r=>r.setWindowsLocalShell),a={auto:s("Windows default (PowerShell)"),powershell:s("PowerShell"),bash:s("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:[s("Windows local command shell"),e.jsx(Ze,{})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Only the Windows local agent command tool. SSH and other platforms stay on bash. Takes effect on the next session.")})]}),e.jsxs(ne,{items:a,value:t,onValueChange:r=>n(r),children:[e.jsx(ae,{className:"w-56",children:e.jsx(re,{})}),e.jsx(oe,{children:Object.keys(a).map(r=>e.jsx(Z,{value:r,children:a[r]},r))})]})]})}function Ie({title:s,description:t,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:s}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t})]}),e.jsx(ce,{checked:n,onCheckedChange:i=>a(i===!0)})]}),o?e.jsx("div",{className:"mt-2",children:o}):null]})}function Ra(s,t){window.electronAPI.proxy.apply({mode:s,customUrl:t})}function Bm(){const{t:s}=R(),t=g(c=>c.proxyMode),n=g(c=>c.customProxyUrl),a=g(c=>c.setProxyMode),r=g(c=>c.setCustomProxyUrl),[o,i]=l.useState(n),[m,u]=l.useState(null);l.useEffect(()=>{i(n)},[n]);const x=c=>{a(c),Ra(c,n)},h=()=>{const c=o.trim();if(c&&!ol(c)){u(s("Enter an http(s) proxy URL"));return}u(null),r(c),Ra(t,c)};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:s("Network proxy")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("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:s("Proxy mode")}),e.jsxs(ne,{items:{system:s("Follow system proxy"),none:s("No proxy"),custom:s("Custom proxy")},value:t,onValueChange:c=>x(c),children:[e.jsx(ae,{className:"w-56",children:e.jsx(re,{})}),e.jsxs(oe,{children:[e.jsx(Z,{value:"system",children:s("Follow system proxy")}),e.jsx(Z,{value:"none",children:s("No proxy")}),e.jsx(Z,{value:"custom",children:s("Custom proxy")})]})]})]}),t==="custom"&&e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"pt-1.5 text-sm font-medium",children:s("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:c=>i(c.target.value),onBlur:h,onKeyDown:c=>{c.key==="Enter"&&h()}}),m&&e.jsx("p",{className:"text-xs text-destructive",children:m})]})]})]})}function Um(){const{t:s}=R(),t=g(c=>c.customCaCertPath),n=g(c=>c.setCustomCaCertPath),[a,r]=l.useState(null),[o,i]=l.useState(!1);l.useEffect(()=>{let c=!0;return window.electronAPI.caCert.status().then(f=>{c&&r(f)}).catch(()=>{}),()=>{c=!1}},[]);const m=async c=>{n(c),i(!0);try{r(await window.electronAPI.caCert.apply(c))}catch{}finally{i(!1)}},u=async()=>{const c=await window.electronAPI.dialog.selectFile([...um]);c&&await m(c)},x={"not-absolute":s("Path must be absolute"),"not-found":s("File not found"),"not-file":s("Not a file"),"not-readable":s("File is not readable")},h=()=>a?a.source==="env"?s("Using NODE_EXTRA_CA_CERTS from the launch environment: {{path}}",{path:a.path}):a.source==="setting"?s("Set: {{path}}",{path:a.path}):a.source==="shell"?s("Not set; using NODE_EXTRA_CA_CERTS from the login shell: {{path}}",{path:a.path}):s("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:s("Custom CA certificate")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("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(y,{size:"sm",variant:"outline",disabled:o,onClick:()=>{u()},children:s("Choose certificate file")}),t&&e.jsx(y,{size:"sm",variant:"ghost",disabled:o,onClick:()=>{m("")},children:s("Clear")})]}),a?.error?e.jsx("p",{className:"break-all text-xs text-destructive",children:s("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:s("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 $m(){const{t:s}=R(),t=g(k=>k.autoUpdate),n=g(k=>k.setAutoUpdate),a=g(k=>k.autoRestartWhenIdle),r=g(k=>k.setAutoRestartWhenIdle),[o,i]=l.useState(null),[m,u]=l.useState(null),[x,h]=l.useState(!1),[c,f]=l.useState(!1);l.useEffect(()=>{let k=!0;window.electronAPI.updater.getState().then(M=>{k&&(u(M),M.status&&i($=>$??M.status))}).catch(()=>{});const I=window.electronAPI.updater.onStatus(i);return()=>{k=!1,I()}},[]);const d=m?.host==="server"?m:null,p=m?.host==="desktop"||d!==null&&d.mode!=="manual",j=(o?.status==="available"||o?.status==="downloaded")&&!!o.info,A=(()=>{if(!o)return null;switch(o.status){case"checking":return s("Checking for updates…");case"available":return s("New version {{version}} found",{version:o.info?.version??""});case"not-available":return s("You are on the latest version");case"downloading":return s("Downloading update… {{percent}}%",{percent:Math.round(o.progress?.percent??0)});case"downloaded":return s("New version {{version}} is ready — restart to update.",{version:o.info?.version??""});case"error":return d&&o.error?s("Update failed: {{error}}",{error:o.error}):s("Update check failed");default:return null}})(),v=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:s("Updates")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:d?Vm(d.mode,s):s("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:[s("Current version")," · ",Gm]}),A&&e.jsx("p",{className:"mt-0.5 truncate text-xs text-muted-foreground",children:A})]}),j&&e.jsx(y,{variant:"ghost",size:"sm",onClick:()=>f(!0),className:"ml-auto shrink-0",children:s("Release notes")}),o?.status==="downloaded"?e.jsx(y,{size:"sm",onClick:()=>{window.electronAPI.updater.quitAndInstall()},className:"shrink-0",children:s("Restart to update")}):p&&o?.status==="available"?e.jsx(y,{size:"sm",onClick:()=>{window.electronAPI.updater.downloadUpdate()},className:"shrink-0",children:s("Download update")}):e.jsx(y,{variant:"outline",size:"sm",disabled:v,onClick:()=>{window.electronAPI.updater.checkForUpdates()},className:"shrink-0",children:s("Check for updates")}),e.jsx(al,{open:c,onOpenChange:f,status:o,canDownload:p})]}),d?.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:s("Restart server")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Running tasks are interrupted; this page reconnects after the server is back.")})]}),e.jsx(y,{variant:"outline",size:"sm",onClick:()=>h(!0),className:"shrink-0",children:s("Restart")}),e.jsx(Gr,{open:x,onOpenChange:h,title:s("Restart server?"),description:s("Running tasks are interrupted; this page reconnects after the server is back."),confirmLabel:s("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:s("Automatic updates")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Download and install updates automatically")})]}),e.jsx(ce,{checked:t,onCheckedChange:k=>{n(k),window.electronAPI.updater.setAutoUpdateEnabled(k)}})]}),e.jsxs("div",{className:`flex items-center justify-between gap-3 rounded-md border px-3 py-2.5 ${t?"":"opacity-60"}`,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s("Restart and apply when idle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("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(ce,{checked:t&&a,disabled:!t,onCheckedChange:k=>{r(k),window.electronAPI.updater.setAutoRestartWhenIdle(k)}})]})]})}function Vm(s,t){return t(s==="npm"?"Server updates install the new version with npm and restart.":"This server must be updated on the machine itself.")}const Gm="0.3.9",Km=["100%","100%","70%","100%","55%"],Wm=["100%","85%","60%"];function Hm({palette:s}){return e.jsxs("div",{className:"flex h-[88px] gap-1.5 p-[7px]",style:{background:s.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:s.text}}),Km.slice(1).map((t,n)=>e.jsx("i",{className:"block h-[5px] rounded-[3px] opacity-55",style:{background:s.textSubtle,width:t}},n))]}),e.jsxs("div",{className:"flex flex-1 flex-col gap-[5px] rounded-md px-2.5 py-2",style:{background:s.surface,boxShadow:`0 0 0 1px ${s.border}`},children:[e.jsx("i",{className:"block h-1 w-[70%] rounded-sm opacity-75",style:{background:s.text}}),Wm.map(t=>e.jsx("i",{className:"block h-1 rounded-sm opacity-50",style:{background:s.textSubtle,width:t}},t)),e.jsx("b",{className:"mt-auto flex h-3.5 justify-end rounded-full p-[3px]",style:{background:s.sunken,boxShadow:`0 0 0 1px ${s.border}`},children:e.jsx("span",{"data-theme-accent":!0,className:"size-2 rounded-full",style:{background:s.accent}})})]})]})}const Oa="overflow-hidden rounded-lg border text-left transition-shadow";function qm({themes:s,selected:t,mode:n,onSelect:a,onGetMore:r}){const{t:o}=R();return e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[s.map(i=>{const m=i.id===t;return e.jsxs("button",{type:"button","data-theme-card":i.id,"aria-pressed":m,onClick:()=>a(i.id),className:K(Oa,"bg-card",m?"border-transparent shadow-[0_0_0_2px_var(--brand)]":"hover:border-input"),children:[e.jsx(Hm,{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:K("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:K(Oa,"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(Xs,{className:"size-[18px]"}),o("Get more themes")]})]})}function un({rowId:s,title:t,description:n,children:a}){return e.jsxs("div",{"data-settings-row":s,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:t}),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 Ym({children:s}){return e.jsx("div",{className:"divide-y rounded-lg border bg-card",children:s})}function ls({label:s,value:t,onCommit:n,min:a=0,max:r=100,step:o,unit:i="%",formatSuffix:m,onPreview:u,trailing:x,valueClassName:h="w-12"}){const[c,f]=l.useState(t);l.useEffect(()=>{f(t)},[t]);const d=m?.(c);return e.jsxs("div",{className:K("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:s}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(pl,{min:a,max:r,step:o,value:c,onValueChange:p=>{const j=Array.isArray(p)?p[0]:p;f(j),u?.(j)},onValueCommitted:p=>n(Array.isArray(p)?p[0]:p)}),e.jsxs("span",{className:K("shrink-0 text-right text-sm text-muted-foreground tabular-nums",d?"w-28":h),children:[c,i,d?` · ${d}`:""]})]}),x]})}function Jm(){const{t:s}=R(),t=g(O=>O.backgroundImageEnabled),n=g(O=>O.setBackgroundImageEnabled),a=g(O=>O.backgroundSourceType),r=g(O=>O.setBackgroundSourceType),o=g(O=>O.backgroundImagePath),i=g(O=>O.setBackgroundImagePath),m=g(O=>O.backgroundFolderPath),u=g(O=>O.setBackgroundFolderPath),x=g(O=>O.backgroundUrlPath),h=g(O=>O.setBackgroundUrlPath),c=g(O=>O.backgroundRandomEnabled),f=g(O=>O.setBackgroundRandomEnabled),d=g(O=>O.backgroundRandomInterval),p=g(O=>O.setBackgroundRandomInterval),j=g(O=>O.backgroundOpacity),b=g(O=>O.setBackgroundOpacity),A=g(O=>O.backgroundBlur),v=g(O=>O.setBackgroundBlur),k=g(O=>O.backgroundBrightness),I=g(O=>O.setBackgroundBrightness),M=g(O=>O.backgroundSaturation),$=g(O=>O.setBackgroundSaturation),E=g(O=>O.backgroundMask),L=g(O=>O.setBackgroundMask),T=g(O=>O.backgroundComposerOpacity),C=g(O=>O.setBackgroundComposerOpacity),S=g(O=>O.backgroundCodeOpacity),W=g(O=>O.setBackgroundCodeOpacity),q=g(O=>O.backgroundSizeMode),N=g(O=>O.setBackgroundSizeMode),z=g(O=>O.bumpBackgroundRefresh),H=fl()?.source==="theme",U=a==="file"?o:a==="folder"?m:x,[B,ie]=l.useState(U);l.useEffect(()=>{ie(U)},[U]);const F=l.useCallback(()=>{const O=B.trim();a==="file"?i(O):a==="folder"?u(O):h(O)},[B,a,i,u,h]),[X,V]=l.useState(d);l.useEffect(()=>{V(d)},[d]);const le=async()=>{if(a==="folder"){const O=await window.electronAPI.dialog.selectDirectory();O&&u(O)}else{const O=await window.electronAPI.dialog.selectFile([...vl,...bl]);O&&i(O)}},_=[{value:"file",label:s("Single image")},{value:"folder",label:s("Folder (random)")},{value:"url",label:s("Remote URL")}],de=[{value:"cover",label:s("Cover")},{value:"contain",label:s("Contain")},{value:"repeat",label:s("Repeat")},{value:"center",label:s("Center")}],ue=s(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:s("Background image")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("Show a custom image behind the interface")})]}),e.jsx(ce,{checked:t,onCheckedChange:O=>n(O===!0)})]}),H&&e.jsx("p",{className:"text-sm text-muted-foreground",children:s("The current theme has its own background. Turn this on to replace it with your image.")}),t&&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:s("Source type")}),e.jsxs(ne,{items:_,value:a,onValueChange:O=>r(O),children:[e.jsx(ae,{className:"w-48",children:e.jsx(re,{})}),e.jsx(oe,{children:_.map(O=>e.jsx(Z,{value:O.value,children:O.label},O.value))})]})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:ue}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(J,{value:B,onChange:O=>ie(O.target.value),onBlur:F,onKeyDown:O=>{O.nativeEvent.isComposing||O.key==="Enter"&&(F(),O.currentTarget.blur())},placeholder:a==="url"?"https://example.com/image.jpg":"",className:"flex-1"}),a!=="url"&&e.jsx(y,{variant:"outline",size:"icon",onClick:le,"aria-label":s("Browse"),children:a==="folder"?e.jsx(Tn,{className:"h-4 w-4"}):e.jsx(Lu,{className:"h-4 w-4"})}),a!=="file"&&e.jsx(y,{variant:"outline",size:"icon",onClick:z,"aria-label":s("Refresh now"),children:e.jsx(ns,{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:s("Auto switch")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ce,{checked:c,onCheckedChange:O=>f(O===!0)}),c&&e.jsxs(e.Fragment,{children:[e.jsx(J,{type:"number",min:5,max:86400,value:X,onChange:O=>V(Number(O.target.value)),onBlur:()=>p(X),onKeyDown:O=>{O.key==="Enter"&&(p(X),O.currentTarget.blur())},className:"w-24"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:s("seconds")})]})]})]}),e.jsx(ls,{label:s("Background visibility"),value:Math.round(j*100),onCommit:O=>b(O/100)}),e.jsx(ls,{label:s("Blur"),value:A,onCommit:v,max:20,unit:"px"}),e.jsx(ls,{label:s("Brightness"),value:Math.round(k*100),onCommit:O=>I(O/100),max:200}),e.jsx(ls,{label:s("Saturation"),value:Math.round(M*100),onCommit:O=>$(O/100),max:200}),e.jsx(ls,{label:s("Overlay"),value:Math.round(E*100),onCommit:O=>L(O/100)}),e.jsx(ls,{label:s("Composer opacity"),value:Math.round(T*100),onCommit:O=>C(O/100)}),e.jsx(ls,{label:s("Code block opacity"),value:Math.round(S*100),onCommit:O=>W(O/100)}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:s("Size mode")}),e.jsxs(ne,{items:de,value:q,onValueChange:O=>N(O),children:[e.jsx(ae,{className:"w-48",children:e.jsx(re,{})}),e.jsx(oe,{children:de.map(O=>e.jsx(Z,{value:O.value,children:O.label},O.value))})]})]})]})]})}function Xm({theme:s,fontSize:t,fontFamily:n,fontWeight:a}){const r=[{id:"prompt1",text:"$ ",color:s.green},{id:"cmd1",text:"ls -la",color:s.foreground},{id:"nl1",text:`
3
+ `},{id:"perm1",text:"drwxr-xr-x ",color:s.blue},{id:"meta1",text:"5 user staff 160 Dec 23 ",color:s.foreground},{id:"dir1",text:"Documents",color:s.cyan},{id:"nl2",text:`
4
+ `},{id:"perm2",text:"-rw-r--r-- ",color:s.foreground},{id:"meta2",text:"1 user staff 2048 Dec 22 ",color:s.foreground},{id:"file1",text:"config.json",color:s.yellow},{id:"nl3",text:`
5
+
6
+ `},{id:"prompt2",text:"$ ",color:s.green},{id:"cmd2",text:'echo "Hello, World!"',color:s.foreground},{id:"nl4",text:`
7
+ `},{id:"output1",text:"Hello, World!",color:s.magenta}];return e.jsxs("div",{className:"rounded-lg border p-4 h-40 overflow-auto",style:{backgroundColor:s.background,fontSize:`${t}px`,fontFamily:n,fontWeight:a},children:[r.map(o=>o.text===`
8
+ `?e.jsx("br",{},o.id):o.text===`
9
+
10
+ `?e.jsxs(l.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:s.cursor}})]})}function Qm({isFavorite:s,onClick:t,ariaLabel:n}){return e.jsx("button",{type:"button","aria-label":n,"aria-pressed":s,onClick:a=>{a.stopPropagation(),a.preventDefault(),t(a)},className:"p-1 hover:text-red-500 transition-colors",children:s?e.jsx(Sa,{className:"h-4 w-4 fill-red-500 text-red-500"}):e.jsx(Sa,{className:"h-4 w-4"})})}function Zm({value:s,onValueChange:t,themes:n,favoriteThemes:a,onToggleFavorite:r,onThemeHover:o,showFavoritesOnly:i,onShowFavoritesOnlyChange:m,showEmptyFavoritesHint:u}){const{t:x}=R(),[h,c]=l.useState(s),[f,d]=l.useState(s),[p,j]=l.useState(!1),b=l.useRef(void 0),A=l.useRef(null),v=l.useRef(s),k=l.useRef(!1),I=l.useMemo(()=>new Set(a),[a]);l.useEffect(()=>{p||(c(s),d(s))},[s,p]);const M=l.useMemo(()=>{if(!f||f===h)return n;const C=f.toLowerCase();return n.filter(S=>S.toLowerCase().includes(C))},[n,f,h]),$=C=>{C&&(k.current=!0,c(C),d(C)),t(C)},E=C=>{j(C),C?(v.current=s,k.current=!1,c(s),d(s)):k.current||o?.(v.current)},L=C=>{clearTimeout(b.current),b.current=setTimeout(()=>{o?.(C)},50)},T=()=>{clearTimeout(b.current)};return l.useEffect(()=>{if(!p)return;const C=S=>{(S.key==="ArrowDown"||S.key==="ArrowUp")&&requestAnimationFrame(()=>{const W=A.current?.querySelector("[data-highlighted]");if(W){const q=W.getAttribute("data-value");q&&o?.(q)}})};return document.addEventListener("keydown",C,!0),()=>{document.removeEventListener("keydown",C,!0)}},[p,o]),l.useEffect(()=>()=>{clearTimeout(b.current)},[]),e.jsxs(tm,{value:h,onValueChange:$,inputValue:f,onInputValueChange:d,open:p,onOpenChange:E,children:[e.jsxs("div",{className:"relative",children:[e.jsx(nm,{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(Le,{id:"show-favorites-only-inner",checked:i,onCheckedChange:C=>m(C===!0),onClick:C=>C.stopPropagation()}),e.jsx("label",{htmlFor:"show-favorites-only-inner",className:"text-xs text-muted-foreground cursor-pointer whitespace-nowrap",onClick:C=>C.stopPropagation(),onKeyDown:C=>C.stopPropagation(),children:x("Show favorites only")})]})]}),e.jsx(rm,{children:e.jsxs(im,{ref:A,children:[M.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")}),M.map(C=>e.jsx(om,{value:C,"data-value":C,onMouseEnter:()=>L(C),onMouseLeave:T,endAddon:e.jsx(Qm,{isFavorite:I.has(C),onClick:()=>r(C),ariaLabel:I.has(C)?x("Remove from favorites"):x("Add to favorites")}),children:C},C))]})})]})}const ex={theme:"Follow theme",violet:"Violet",indigo:"Indigo",teal:"Teal",amber:"Amber",graphite:"Graphite"},Da={body:"Body",h1:"Heading 1",h2:"Heading 2",h3:"Heading 3",h4:"Heading 4–6",table:"Table",inlineCode:"Inline code",codeBlock:"Code block"},La=Yr.map(s=>({value:String(s),label:String(s)}));function sx(){const{t:s}=R(),t=g(u=>u.chatTypography),n=g(u=>u.setChatTypography),a=g(u=>u.resetChatTypography),[r,o]=l.useState(t.body.size);l.useEffect(()=>{o(t.body.size)},[t.body.size]);const i=(u,x)=>{const h=g.getState().chatTypography;n({...h,[u]:{...h[u],size:x}})},m=(u,x)=>{const h=g.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:s("Conversation typography")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("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:[gl.map(u=>{const x=jl[u];return e.jsx(ls,{label:s(Da[u]),value:t[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(ne,{items:La,value:String(t[u].weight),onValueChange:h=>{const c=Number(h);Yr.includes(c)&&m(u,c)},children:[e.jsx(ae,{className:"w-24 min-w-24","aria-label":s(Da[u]),children:e.jsx(re,{})}),e.jsx(oe,{children:La.map(h=>e.jsx(Z,{value:h.value,children:h.label},h.value))})]})},u)}),e.jsx("div",{className:"flex justify-end",children:e.jsx(y,{variant:"outline",size:"sm",onClick:()=>a(),children:s("Reset to defaults")})})]})]})}function tx({seconds:s,onCommit:t}){const{t:n}=R(),[a,r]=l.useState(String(s));l.useEffect(()=>r(String(s)),[s]);const o=()=>{const i=Number(a);if(!Number.isInteger(i)){r(String(s));return}const m=yl(i);t(m),r(String(m))};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 nx(){const{t:s}=R(),t=g(C=>C.openChangesOnFileEdit),n=g(C=>C.setOpenChangesOnFileEdit),a=g(C=>C.compactReadOnlyTools),r=g(C=>C.setCompactReadOnlyTools),o=g(C=>C.expandLiveEdits),i=g(C=>C.setExpandLiveEdits),m=g(C=>C.expandLiveReasoning),u=g(C=>C.setExpandLiveReasoning),x=g(C=>C.autoCollapseTurns),h=g(C=>C.setAutoCollapseTurns),c=g(C=>C.collapseCompletedActivity),f=g(C=>C.setCollapseCompletedActivity),d=g(C=>C.collapseLiveActivity),p=g(C=>C.setCollapseLiveActivity),j=g(C=>C.liveActivityFoldDelaySec),b=g(C=>C.setLiveActivityFoldDelaySec),A=g(C=>C.pinUnfinishedTodos),v=g(C=>C.setPinUnfinishedTodos),k=g(C=>C.headerSessionTabs),I=g(C=>C.setHeaderSessionTabs),M=g(C=>C.headerRecentMinutes),$=g(C=>C.setHeaderRecentMinutes),E=C=>C===0?s("Off"):s("{{count}} min",{count:C}),L=g(C=>C.navRailSide),T=g(C=>C.setNavRailSide);return e.jsxs("div",{className:"space-y-6",children:[e.jsx("h3",{className:"text-lg font-medium",children:s("Conversation display")}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ie,{rowId:"appearance.openChangesOnFileEdit",title:s("Open Changes when files are edited"),description:s("Automatically show the side panel Changes tab after the agent edits a file"),checked:t,onChange:n}),e.jsx(Ie,{rowId:"appearance.compactReadOnlyTools",title:s("Compact read-only tool calls"),description:s("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(Ie,{rowId:"appearance.expandLiveEdits",title:s("Expand file edits while running"),description:s("Automatically unfold diffs or written content from file modification tools while the agent is still running"),checked:o,onChange:i}),e.jsx(Ie,{rowId:"appearance.expandLiveReasoning",title:s("Expand reasoning while streaming"),description:s("Automatically unfold the thinking block while the model is still reasoning. It collapses again when reasoning ends."),checked:m,onChange:u}),e.jsx(Ie,{rowId:"appearance.autoCollapseTurns",title:s("Auto-collapse previous turns"),description:s("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(Ie,{rowId:"appearance.collapseCompletedActivity",title:s("Collapse activity after reply"),description:s("When a reply finishes, fold consecutive thinking and tool calls (including edits and commands) into one summary row; failed calls stay visible"),checked:c,onChange:f}),e.jsx(Ie,{rowId:"appearance.collapseLiveActivity",title:s("Collapse finished activity while replying"),description:s("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:d,onChange:p,children:d?e.jsx(tx,{seconds:j,onCommit:b}):null}),e.jsx(Ie,{rowId:"appearance.pinUnfinishedTodos",title:s("Pin unfinished todos"),description:s("Keep the latest todo list above the input while it has unfinished items, so it does not scroll away with the timeline"),checked:A,onChange:v}),e.jsx(Ie,{rowId:"appearance.headerSessionTabs",title:s("Show active sessions in the title bar"),description:s("Show active conversations as tabs above the conversation. Hold ⌘/Ctrl to see number shortcuts. Hidden while Bot mode is enabled."),checked:k,onChange:I,children:k&&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:s("Also show recent conversations")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Conversations with messages within this window. Off shows only Active ones.")})]}),e.jsxs(ne,{items:Object.fromEntries(ft.map(C=>[String(C),E(C)])),value:String(M),onValueChange:C=>$(Number(C)),children:[e.jsx(ae,{className:"w-28",children:e.jsx(re,{})}),e.jsx(oe,{children:ft.map(C=>e.jsx(Z,{value:String(C),children:E(C)},C))})]})]})}),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:s("Turn marks")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("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(Pn,{value:L,options:[{value:"left",label:s("Left")},{value:"right",label:s("Right")},{value:"off",label:s("Off")}],onChange:T})})]})]}),e.jsx(sx,{}),e.jsx(dm,{})]})}function ax({onOpenPlugins:s}){const{t}=R(),n=g(i=>i.themeId),a=g(i=>i.setThemeId),r=En(i=>i.themes),o=Kr();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:t("Theme")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("Built-in and plugin themes; each one is a set of color tokens")})]}),e.jsx(qm,{themes:Hr(r),selected:n,mode:o,onSelect:a,onGetMore:s})]})}function rx(){const{t:s}=R(),t=g(r=>r.userCssEnabled),n=g(r=>r.setUserCssEnabled),a=async()=>{const r=await window.electronAPI.appearance.openUserCss();r.ok||Te({type:"error",title:s("Cannot open user.css"),description:r.error})};return e.jsxs(un,{rowId:"appearance.userCss",title:s("Custom CSS"),description:s("Inject user.css into every window; saved changes apply immediately"),children:[e.jsxs(y,{variant:"outline",size:"sm",onClick:()=>{a()},children:[e.jsx(hl,{}),s("Open user.css")]}),e.jsx(ce,{checked:t,onCheckedChange:r=>n(r===!0),"aria-label":s("Custom CSS")})]})}function ox({onOpenPlugins:s}={}){const t=g(_=>_.borderOpacity),n=g(_=>_.setBorderOpacity),{theme:a,setTheme:r,themeId:o,accentColor:i,setAccentColor:m,terminalTheme:u,setTerminalTheme:x,terminalFontSize:h,setTerminalFontSize:c,terminalFontFamily:f,setTerminalFontFamily:d,terminalFontWeight:p,setTerminalFontWeight:j,terminalFontWeightBold:b,setTerminalFontWeightBold:A,favoriteTerminalThemes:v,toggleFavoriteTerminalTheme:k}=g(),{t:I}=R(),M=Kr(),$=En(_=>_.themes),E=[{value:"light",icon:Ku,label:I("Light")},{value:"dark",icon:il,label:I("Dark")},{value:"system",icon:Mn,label:I("System")},{value:"sync-terminal",icon:Wr,label:I("Sync terminal theme")}],L=ll.map(_=>({value:_,label:I(ex[_]),swatch:_==="theme"?dl(o,Hr($))[M].accent:cl[_][M]})),[T,C]=l.useState(h),[S,W]=l.useState(f),[q,N]=l.useState(!1);l.useEffect(()=>{C(h)},[h]),l.useEffect(()=>{W(f)},[f]);const z=l.useCallback(()=>{const _=Math.max(8,Math.min(32,T||8));_!==T&&C(_),_!==h&&c(_)},[T,h,c]),H=l.useCallback(()=>{const _=S.trim()||f;_!==S&&W(_),_!==f&&d(_)},[S,f,d]),U=l.useMemo(()=>ul(),[]),B=l.useMemo(()=>{if(!q)return U;const _=U.filter(de=>v.includes(de));return v.includes(u)?_:[u,..._]},[U,q,v,u]),ie=q&&v.length===0,F=l.useMemo(()=>xl(u)??ml,[u]),X=_=>{_&&x(_)},V=()=>{const _=q?B:U,de=_.indexOf(u),ue=de<=0?_.length-1:de-1;x(_[ue])},le=()=>{const _=q?B:U,de=_.indexOf(u),ue=de>=_.length-1?0:de+1;x(_[ue])};return e.jsxs("div",{className:"space-y-6",children:[e.jsx(ax,{onOpenPlugins:s}),e.jsxs("section",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:I("Personalization")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:I("Applied on top of any theme")})]}),e.jsxs(Ym,{children:[e.jsx(un,{rowId:"appearance.theme",title:I("Theme mode"),children:e.jsx("div",{className:"flex rounded-lg bg-muted p-0.5",children:E.map(_=>e.jsxs("button",{type:"button",onClick:()=>r(_.value),"aria-pressed":a===_.value,className:K("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(un,{rowId:"appearance.accent",title:I("Accent color"),description:I("Used for running state, checkmarks and plan mode"),children:L.map(_=>_.value==="theme"?e.jsxs("button",{type:"button",onClick:()=>m(_.value),"aria-pressed":i===_.value,className:K("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:()=>m(_.value),title:_.label,"aria-label":_.label,"aria-pressed":i===_.value,style:{backgroundColor:_.swatch},className:K("size-5 rounded-full transition-shadow",i===_.value&&"ring-2 ring-offset-2 ring-offset-card ring-foreground/60")},_.value))}),e.jsx(rx,{})]})]}),e.jsx(nx,{}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:I("Terminal")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:I("Terminal appearance")})]}),e.jsx(Xm,{theme:F,fontSize:T,fontFamily:S,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:I("Color scheme")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{variant:"outline",size:"icon",onClick:V,children:e.jsx(qr,{className:"h-4 w-4"})}),e.jsx("div",{className:"flex-1",children:e.jsx(Zm,{value:u,onValueChange:X,themes:B,favoriteThemes:v,onToggleFavorite:k,onThemeHover:x,showFavoritesOnly:q,onShowFavoritesOnlyChange:N,showEmptyFavoritesHint:ie})}),e.jsx(y,{variant:"outline",size:"icon",onClick:le,children:e.jsx(Ds,{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:I("Font")}),e.jsx(J,{value:S,onChange:_=>W(_.target.value),onBlur:H,onKeyDown:_=>{_.nativeEvent.isComposing||_.key==="Enter"&&(H(),_.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:I("Font size")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(J,{type:"number",value:T,onChange:_=>C(Number(_.target.value)),onBlur:z,onKeyDown:_=>{_.key==="Enter"&&(z(),_.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:I("Font weight")}),e.jsxs(ne,{items:rt,value:p,onValueChange:_=>j(_),children:[e.jsx(ae,{className:"w-48",children:e.jsx(re,{})}),e.jsx(oe,{children:rt.map(_=>e.jsx(Z,{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:I("Bold font weight")}),e.jsxs(ne,{items:rt,value:b,onValueChange:_=>A(_),children:[e.jsx(ae,{className:"w-48",children:e.jsx(re,{})}),e.jsx(oe,{children:rt.map(_=>e.jsx(Z,{value:_.value,children:_.label},_.value))})]})]})]}),e.jsx(ls,{label:I("Border opacity"),value:Math.round(t*100),onCommit:_=>n(_/100)}),e.jsx(Jm,{})]})}const za=15e3,ix=3e3;function lx(s){return!s||!s.timeoutSet&&s.timeoutMs===ix?za:s.timeoutMs}const _a=()=>{},_t="off",Ft=s=>({timeoutMs:s?.timeoutMs??wl,...s?.timeoutSet&&{timeoutSet:!0}});function cx({classifier:s,effectiveMs:t,hint:n,onChange:a}){const{t:r}=R(),[o,i]=l.useState(String(t/1e3));l.useEffect(()=>i(String(t/1e3)),[t]);const m=()=>{const u=Number(o);if(!o.trim()||!Number.isFinite(u))return i(String(t/1e3));const x=Cl(u*1e3);i(String(x/1e3)),x!==t&&a({...s,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:kl/1e3,max:Nl/1e3,step:.5,className:"h-7 w-20 text-xs",onChange:u=>i(u.target.value),onBlur:m,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 ht({providers:s,value:t,emptyLabel:n,onSelect:a}){return e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx(ze,{providers:s,providerId:t?.providerId??"",modelId:t?.modelId??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:n,side:"bottom",triggerClassName:Qe,onSelect:(r,o)=>a({providerId:r,modelId:o}),onReasoningChange:_a,onThinkingChange:_a})})}function ct({label:s,hint:t,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:s}),t&&e.jsx("div",{className:"text-[10px] text-muted-foreground",children:t})]}),e.jsx("div",{className:"min-w-0 space-y-1",children:n})]})}function Uo({value:s,onChange:t,providers:n,classifierProviders:a,offLabel:r,judgeLabel:o,judgeSeed:i,description:m,effectiveTimeoutMs:u,timeoutHint:x}){const{t:h}=R(),c=s,[f,d]=l.useState(!1),p=c?.source??(f?"judge":_t),j=c?.source==="pi-classifier"?c.model.providerId:"",[b,A]=l.useState([]),[v,k]=l.useState(!1);l.useEffect(()=>{if(!j){A([]);return}let E=!1;return window.electronAPI.providers.classifierModels(j).then(L=>{E||A(L)}),()=>{E=!0}},[j]);const I=async E=>{const T=(await window.electronAPI.providers.classifierModels(E))[0];k(!T),T&&t({source:"pi-classifier",model:{providerId:E,modelId:T.id},...Ft(c)})},M=E=>{if(k(!1),d(E==="judge"&&!i),E===_t)return t(void 0);if(E==="judge")return t(i?{source:"judge",model:i,...Ft(c)}:void 0);const L=a[0];L&&I(L.id)},$=[{value:_t,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(ne,{items:$,value:p,onValueChange:E=>M(String(E)),children:[e.jsx(ae,{size:"sm",className:"w-48",children:e.jsx(re,{})}),e.jsx(oe,{children:$.map(E=>e.jsx(Z,{value:E.value,children:E.label},E.value))})]}),p==="judge"&&e.jsx(ht,{providers:n,value:c?.source==="judge"?c.model:void 0,emptyLabel:h("Select model"),onSelect:E=>{d(!1),t({source:"judge",model:E,...Ft(c)})}}),c?.source==="pi-classifier"&&e.jsxs("div",{className:"flex gap-1",children:[e.jsxs(ne,{items:a.map(E=>({value:E.id,label:E.name})),value:c.model.providerId,onValueChange:E=>{I(String(E))},children:[e.jsx(ae,{size:"sm",className:"w-40",children:e.jsx(re,{})}),e.jsx(oe,{children:a.map(E=>e.jsx(Z,{value:E.id,children:E.name},E.id))})]}),e.jsxs(ne,{items:b.map(E=>({value:E.id,label:E.name})),value:c.model.modelId||null,onValueChange:E=>t({...c,model:{providerId:c.model.providerId,modelId:String(E)}}),children:[e.jsx(ae,{size:"sm",className:"min-w-0 flex-1",children:e.jsx(re,{placeholder:h("Select model")})}),e.jsx(oe,{children:b.map(E=>e.jsx(Z,{value:E.id,children:E.name},E.id))})]})]}),v&&e.jsx("p",{className:"text-[10px] text-destructive",children:h("No classifier models available")}),c&&e.jsx(cx,{classifier:c,effectiveMs:u??c.timeoutMs,hint:x,onChange:t}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:m})]})}function dx({entry:s,providers:t,classifierProviders:n,update:a}){const{t:r}=R();return s.fast?e.jsx(Uo,{value:s.classifier,onChange:o=>a({classifier:o}),providers:t,classifierProviders:n,offLabel:r("Off"),judgeLabel:r("Fast model judges"),judgeSeed:s.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 ux({entry:s,providers:t,classifierProviders:n}){const{t:a}=R(),r=g(x=>x.updateVirtualModel),o=g(x=>x.removeVirtualModel),i=[s.primary,...s.fast?[s.fast]:[],...s.fallbacks];let m;for(const x of t){const h=x.models.find(c=>c.enabled!==!1&&!i.some(f=>f.providerId===x.id&&f.modelId===c.id));if(h){m={providerId:x.id,modelId:h.id};break}}const u=x=>r(s.id,x);return e.jsxs("div",{"data-slot":"virtual-model-card",className:K("space-y-2 rounded-md border p-2",!s.enabled&&"bg-muted/50 text-muted-foreground"),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ce,{"aria-label":a("Enable virtual model"),checked:s.enabled,onCheckedChange:x=>u({enabled:x})}),e.jsx(J,{value:s.name,maxLength:60,placeholder:"Auto",className:"h-7 flex-1 text-xs",onChange:x=>u({name:x.target.value})}),!s.enabled&&e.jsx(se,{variant:"outline",className:"shrink-0 text-[10px] text-muted-foreground",children:a("Disabled")}),e.jsx(y,{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(s.id),children:e.jsx(Pe,{className:"h-3.5 w-3.5"})})]}),e.jsx(ct,{label:a("Primary model"),hint:a("Default for each new turn"),children:e.jsx(ht,{providers:t,value:s.primary,onSelect:x=>u({primary:x,fallbacks:s.fallbacks.filter(h=>h.providerId!==x.providerId||h.modelId!==x.modelId)})})}),e.jsx(ct,{label:a("Fast model"),hint:a("Summaries and simple turns"),children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(ht,{providers:t,value:s.fast,emptyLabel:a("Not used"),onSelect:x=>u({fast:x})}),s.fast&&e.jsx(y,{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(js,{className:"h-3.5 w-3.5"})})]})}),e.jsxs(ct,{label:a("Fallback models"),hint:a("Used in order when a model is rate limited or down"),children:[s.fallbacks.map((x,h)=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(ht,{providers:t,value:x,onSelect:c=>u({fallbacks:s.fallbacks.map((f,d)=>d===h?c:f)})}),e.jsx(y,{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:s.fallbacks.filter((c,f)=>f!==h)}),children:e.jsx(js,{className:"h-3.5 w-3.5"})})]},`${x.providerId}/${x.modelId}`)),e.jsxs(y,{type:"button",variant:"outline",size:"sm",className:"h-7 text-xs",disabled:!m||s.fallbacks.length>=8,onClick:()=>{m&&u({fallbacks:[...s.fallbacks,m]})},children:[e.jsx(Re,{className:"mr-1 h-3.5 w-3.5"}),a("Add fallback")]})]}),e.jsx(ct,{label:a("Difficulty routing"),children:e.jsx(dx,{entry:s,providers:t,classifierProviders:n,update:u})})]})}function mx(){const{t:s}=R(),t=g(u=>u.virtualModels),n=g(u=>u.addVirtualModel),a=g(u=>u.defaultModel),r=es(),o=l.useMemo(()=>r.filter(Jr),[r]),i=Rn(),m=l.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:s("Virtual models")}),e.jsx("p",{className:"mt-0.5 text-muted-foreground text-xs",children:s("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:s("Applies to newly started conversations.")})]}),e.jsxs("div",{className:"space-y-2",children:[t.map(u=>e.jsx(ux,{entry:u,providers:o,classifierProviders:i},u.id)),e.jsxs(y,{type:"button",variant:"outline",size:"sm",className:"h-7 text-xs",disabled:!m,onClick:()=>{m&&n({name:"Auto",enabled:!0,primary:m,fallbacks:[]})},children:[e.jsx(Re,{className:"mr-1 h-3.5 w-3.5"}),s("New virtual model")]}),!m&&e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Enable a model and configure valid provider credentials first.")})]})]})}function xx(){const{t:s}=R();return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("Bot mode")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("Settings shared by all members and group chats.")})]}),e.jsx(fx,{}),e.jsx(gx,{}),e.jsx(hx,{}),e.jsx(px,{})]})}function hx(){const{t:s}=R(),t=g(r=>r.botModeEnabled),n=g(r=>r.botDiscussModeEnabled),a=g(r=>r.setBotDiscussModeEnabled);return t?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:s("Discussion mode")}),e.jsx(se,{variant:"warning",size:"sm","data-experimental-badge":"",children:s("Experimental feature")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("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(ce,{checked:n,onCheckedChange:r=>a(r===!0)})]}):null}const Fa=Array.from({length:Sl-da+1},(s,t)=>da+t);function px(){const{t:s}=R(),t=g(a=>a.botMaxRunningTurns),n=g(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:s("Bot concurrency limit")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Shared by private chats, group chats, delegations and routines. Lowering it never interrupts running work; raising it may hit model rate limits.")})]}),e.jsxs(ne,{items:Object.fromEntries(Fa.map(a=>[String(a),String(a)])),value:String(t),onValueChange:a=>n(Number(a)),children:[e.jsx(ae,{className:"w-20",children:e.jsx(re,{})}),e.jsx(oe,{children:Fa.map(a=>e.jsx(Z,{value:String(a),children:a},a))})]})]})}function fx(){const{t:s}=R(),t=g(i=>i.botAssistantModel),n=g(i=>i.setBotAssistantModel),a=es(),r=t?a.find(i=>i.id===t.providerId):void 0,o=r?.models.find(i=>i.id===t?.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:s("Bot assistant model")}),e.jsx("p",{className:"mb-2 text-xs text-muted-foreground",children:s("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:s("Follows the default model"),side:"bottom",triggerClassName:Qe,onSelect:(i,m)=>n({providerId:i,modelId:m}),onReasoningChange:()=>{},onThinkingChange:()=>{}}),t&&!o&&e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:s("Selected model is unavailable — falls back to the default model.")}),t&&e.jsx(y,{variant:"ghost",size:"sm",className:"mt-1",onClick:()=>n(null),children:s("Follow default model")})]})}function gx(){const{t:s}=R(),t=g(m=>m.botRouteClassifier),n=g(m=>m.setBotRouteClassifier),a=g(m=>m.botDiscussModeEnabled),r=es(),o=l.useMemo(()=>r.filter(Jr),[r]),i=Rn();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:s("Group reply picker model")}),e.jsx("p",{className:"mb-2 text-xs text-muted-foreground",children:s("When nobody is @-mentioned in a smart-routing group, this model picks which member replies.")}),e.jsx(Uo,{value:t??void 0,onChange:m=>n(m??null),providers:o,classifierProviders:i,offLabel:s("Default (title model)"),judgeLabel:s("Fast chat model"),description:s(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:t?lx(t):void 0,timeoutHint:s(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 jx=()=>({name:"",title:"",scope:"",summary:"",persona:"",color:nn[0],tools:"all",approvalMode:"auto-edits"}),mn=(s,t)=>({key:s,name:"",title:"",scope:"",persona:"",color:nn[t%nn.length],tools:"all",approvalMode:"auto-edits",canDelegateTo:[],acceptFrom:[]}),vx=()=>({title:"",summary:"",bossKey:"m1",workspace:"chat-home",members:[mn("m1",0),mn("m2",1)]});function bx(s,t){const n=URL.createObjectURL(new Blob([JSON.stringify(t,null,2)],{type:"application/json"})),a=document.createElement("a");a.href=n,a.download=s,a.click(),URL.revokeObjectURL(n)}function yx(){const{t:s}=R(),t=Il(!0),n=Al(!0),[a,r]=l.useState(null),[o,i]=l.useState(null),m=l.useRef(null),u=async(p,j)=>{const b=await Ul(A=>({...A,[p]:j(A[p])}));return b||Te({type:"error",title:s("Could not save templates")}),b},x=(p,j)=>u("members",b=>p?xa(b,p,j,Kl):ha(b,j,crypto.randomUUID())),h=(p,j)=>u("teams",b=>p?xa(b,p,j,Wl):ha(b,j,crypto.randomUUID())),c=async p=>{const j=Rl(await p.text());if(!j.ok){Te({type:"error",title:ua(j.error,s)});return}const b=Qr(Ol(j.team));if(!b){Te({type:"error",title:ua("invalid",s)});return}await h(void 0,b)&&Te({type:"success",title:s("Imported as a custom team template")})},f=(p,j)=>u(p==="members"?"members":"teams",j),d=(p,j,b)=>e.jsxs(e.Fragment,{children:[e.jsx(gs,{label:s("Edit"),onClick:()=>b({id:j.id,data:j.data}),children:e.jsx(hs,{})}),e.jsx(gs,{label:s("Duplicate as custom"),onClick:()=>b({data:j.data}),children:e.jsx(Xr,{})}),j.source==="builtin"&&e.jsx(gs,{label:j.hidden?s("Show"):s("Hide"),onClick:()=>{f(p,A=>$l(A,j.id,!j.hidden))},children:j.hidden?e.jsx(Pl,{}):e.jsx(Tl,{})}),j.modified&&e.jsx(gs,{label:s("Restore default"),onClick:()=>{f(p,A=>pa(A,j.id))},children:e.jsx(On,{})}),j.source==="custom"&&e.jsx(gs,{label:s("Delete"),onClick:()=>{f(p,A=>pa(A,j.id))},children:e.jsx(Pe,{})})]});return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("Bot templates")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("Templates used when creating members and teams. Built-in templates can be edited, hidden or restored.")})]}),e.jsxs(Qs,{defaultValue:"members",children:[e.jsxs(Zs,{variant:"underline",children:[e.jsx(Je,{value:"members",children:s("Member templates")}),e.jsx(Je,{value:"teams",children:s("Team templates")})]}),e.jsxs(Ws,{value:"members",className:"space-y-2 pt-3",children:[e.jsxs(y,{size:"sm",variant:"outline",onClick:()=>r({data:jx()}),children:[e.jsx(Re,{}),s("New member template")]}),t.map(p=>e.jsx(Ba,{item:p,avatar:e.jsx(tn,{bot:{name:p.data.name,avatar:{color:p.data.color}}}),title:p.data.name,subtitle:p.data.title,summary:p.data.summary,actions:d("members",p,r)},p.id))]}),e.jsxs(Ws,{value:"teams",className:"space-y-2 pt-3",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(y,{size:"sm",variant:"outline",onClick:()=>i({data:vx()}),children:[e.jsx(Re,{}),s("New team template")]}),e.jsxs(y,{size:"sm",variant:"outline",onClick:()=>m.current?.click(),children:[e.jsx(El,{}),s("Import team (JSON)")]}),e.jsx("input",{ref:m,type:"file",accept:".json,application/json",hidden:!0,onChange:p=>{const j=p.target.files?.[0];p.target.value="",j&&c(j)}})]}),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(j=>e.jsx(tn,{size:"sm",bot:{name:j.name,avatar:{color:j.color}}},j.key))}),title:p.data.title,subtitle:s("{{n}} members",{n:p.data.members.length}),summary:p.data.summary,actions:e.jsxs(e.Fragment,{children:[e.jsx(gs,{label:s("Export JSON"),onClick:()=>bx(`${p.data.title||"team"}.team.json`,{format:Gl,version:Vl,exportedAt:new Date().toISOString(),team:Ml(p.data)}),children:e.jsx(bn,{})}),d("teams",p,i)]})},p.id))]})]}),a&&e.jsx(wx,{initial:a.data,onClose:()=>r(null),onSave:async p=>{await x(a.id,p)&&r(null)}}),o&&e.jsx(kx,{initial:o.data,onClose:()=>i(null),onSave:async p=>{await h(o.id,p)&&i(null)}})]})}function gs({label:s,onClick:t,disabled:n,children:a}){return e.jsx(y,{variant:"ghost",size:"icon-sm",title:s,"aria-label":s,disabled:n,onClick:t,children:a})}function Ba({item:s,avatar:t,title:n,subtitle:a,summary:r,actions:o}){const{t:i}=R();return e.jsxs("div",{className:"flex items-center gap-3 rounded-md border px-3 py-2.5","data-template-id":s.id,children:[e.jsxs("div",{className:K("flex min-w-0 flex-1 items-center gap-3",s.hidden&&"opacity-50"),children:[t,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(se,{variant:"secondary",children:s.source==="custom"?i("Custom"):i("Built-in")}),s.modified&&e.jsx(se,{variant:"outline",children:i("Modified")}),s.hidden&&e.jsx(se,{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 $o({title:s,error:t,onClose:n,onSave:a,children:r}){const{t:o}=R(),[i,m]=l.useState(!1);return e.jsx(ye,{open:!0,onOpenChange:u=>!u&&n(),children:e.jsxs(we,{className:"max-h-[85vh] max-w-2xl",children:[e.jsx(Ne,{children:e.jsx(ke,{children:s})}),e.jsxs(Ce,{className:"space-y-3",children:[r,t&&e.jsx("p",{className:"text-destructive text-xs",children:t})]}),e.jsxs(Ee,{children:[e.jsx(y,{variant:"outline",size:"sm",onClick:n,children:o("Cancel")}),e.jsx(y,{size:"sm",disabled:i||!!t,onClick:()=>{m(!0),a().finally(()=>m(!1))},children:o("Save")})]})]})})}function Vo({value:s,onChange:t}){const{t:n}=R(),a=s.name?Zr(s.name,[],n):null;return e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(Ge,{children:n("Name")}),e.jsx(J,{value:s.name,onChange:r=>t({name:r.target.value})}),a&&e.jsx("p",{className:"mt-1 text-destructive text-xs",children:a})]}),e.jsxs("div",{children:[e.jsx(Ge,{children:n("Title")}),e.jsx(J,{value:s.title,onChange:r=>t({title:r.target.value})})]}),e.jsxs("div",{children:[e.jsx(Ge,{children:n("Avatar color")}),e.jsx(Fl,{value:s.color,onChange:r=>t({color:r})})]}),e.jsxs("div",{children:[e.jsx(Ge,{children:n("Tools")}),e.jsx(Pn,{value:s.tools,options:[{value:"all",label:n("All tools")},{value:"readonly",label:n("Read-only")}],onChange:r=>t({tools:r})})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(Ge,{children:n("Approval mode")}),e.jsx(Bl,{value:s.approvalMode,onChange:r=>t({approvalMode:r}),zIndex:cs.DROPDOWN_IN_MODAL})]}),s.summary!==void 0&&e.jsxs("div",{className:"col-span-2",children:[e.jsx(Ge,{hint:n("Shown on the template card"),children:n("Summary")}),e.jsx(J,{value:s.summary,onChange:r=>t({summary:r.target.value})})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(Ge,{children:n("Responsibilities")}),e.jsx(J,{value:s.scope,onChange:r=>t({scope:r.target.value})})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(Ge,{children:n("Persona")}),e.jsx(Xe,{rows:6,value:s.persona,onChange:r=>t({persona:r.target.value})})]})]})}function wx({initial:s,onClose:t,onSave:n}){const{t:a}=R(),[r,o]=l.useState(s),i=Dl(r);return e.jsx($o,{title:a("Member template"),error:Zr(r.name,[],a)??(i?null:a("Check the template fields")),onClose:t,onSave:()=>i?n(i):Promise.resolve(),children:e.jsx(Vo,{value:r,onChange:m=>o(u=>({...u,...m}))})})}function Nx(s,t){switch(s){case"title":return t("Enter a team title");case"members":return t("A team needs 2–12 members");case"name":return t("Every member needs a valid name");case"invalid":return t("Check the template fields");default:return null}}function kx({initial:s,onClose:t,onSave:n}){const{t:a}=R(),[r,o]=l.useState(s),[i,m]=l.useState(null),u=p=>r.members.find(j=>j.key===p)?.name||p,x=p=>o(j=>({...j,...p})),h=(p,j)=>o(b=>({...b,members:b.members.map(A=>A.key===p?{...A,...j}:A)})),c=()=>{const p=new Set(r.members.map(A=>A.key));let j=r.members.length+1;for(;p.has(`m${j}`);)j++;const b=`m${j}`;x({members:[...r.members,mn(b,r.members.length)]}),m(b)},f=p=>{const j=b=>b==="any"?"any":b.filter(A=>A!==p);x({members:r.members.filter(b=>b.key!==p).map(b=>({...b,canDelegateTo:j(b.canDelegateTo),acceptFrom:j(b.acceptFrom)}))})},d=Qr(r);return e.jsxs($o,{title:a("Team template"),error:Nx(_l(r),a),onClose:t,onSave:()=>d?n(d):Promise.resolve(),children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(Ge,{children:a("Group name")}),e.jsx(J,{value:r.title,onChange:p=>x({title:p.target.value})})]}),e.jsxs("div",{children:[e.jsx(Ge,{children:a("Owner")}),e.jsxs(ne,{items:r.members.map(p=>({value:p.key,label:u(p.key)})),value:r.bossKey,onValueChange:p=>x({bossKey:p}),children:[e.jsx(ae,{className:"w-full",children:e.jsx(re,{})}),e.jsx(oe,{zIndex:cs.DROPDOWN_IN_MODAL,children:r.members.map(p=>e.jsx(Z,{value:p.key,children:u(p.key)},p.key))})]})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(Ge,{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(Ge,{children:a("Shared workspace")}),e.jsx(Pn,{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(y,{size:"xs",variant:"outline",disabled:r.members.length>=Ll,onClick:c,children:[e.jsx(Re,{}),a("Add member")]})]}),e.jsx("div",{className:"space-y-1.5",children:r.members.map(p=>{const j=i===p.key,b=p.key===r.bossKey,A=r.members.filter(v=>v.key!==p.key).map(v=>v.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:()=>m(j?null:p.key),children:[j?e.jsx(gt,{className:"h-3.5 w-3.5 shrink-0"}):e.jsx(Ds,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx(tn,{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}),b&&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(zl,{className:"h-3 w-3"}),a("Owner")]})]}),e.jsx(gs,{label:a("Remove"),disabled:b||r.members.length<=2,onClick:()=>f(p.key),children:e.jsx(Pe,{})})]}),j&&e.jsxs("div",{className:"space-y-3 border-t p-2.5",children:[e.jsx(Vo,{value:p,onChange:v=>h(p.key,v)}),e.jsx(ma,{label:a("Can delegate to"),value:p.canDelegateTo,options:A,nameOf:u,onChange:v=>h(p.key,{canDelegateTo:v})}),e.jsx(ma,{label:a("Accepts delegation from"),value:p.acceptFrom,options:A,nameOf:u,onChange:v=>h(p.key,{acceptFrom:v})})]})]},p.key)})})]})]})}function Go(s){return s.capturePermission==="unsupported"&&s.axPermission==="unsupported"?"unsupported":s.capturePermission==="granted"&&(s.axPermission==="granted"||s.axPermission==="unsupported")?"ready":"needs-permission"}const Cx=[{id:"collaboration",label:"Collaboration & planning"},{id:"web",label:"Web"},{id:"execution",label:"Execution"},{id:"context",label:"Context & memory"},{id:"safety",label:"Safety"}],Ua={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 Sx(s,t){return s.filter(n=>Object.hasOwn(Ua,n.id)?Ua[n.id]===t:!1)}function $a(s){return s.bundleId||s.path}function Ix(){const{t:s}=R(),[t,n]=l.useState(null),a=g(i=>i.computerAllowAllApps),r=g(i=>i.setComputerAllowAllApps);l.useEffect(()=>{let i=!1;return window.electronAPI.computer.allowedApps().then(m=>{i||n(m)}),()=>{i=!0}},[]);const o=async i=>{await window.electronAPI.computer.revokeApp($a(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:s("Apps the AI may control")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:s("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:s("Allow all apps")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:s("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(ce,{checked:a,onCheckedChange:r})]}),t&&t.length===0?e.jsx("p",{className:"text-muted-foreground text-xs",children:s("No apps are always allowed yet.")}):null,t&&t.length>0?e.jsx("ul",{className:"divide-y rounded-md border",children:t.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(y,{variant:"outline",size:"sm",onClick:()=>{o(i)},children:s("Revoke")})]},$a(i)))}):null]})}function Ax(s){return Object.fromEntries(s.map(t=>[t.id,t]))}function kt(s,t){return s.reduce((n,a)=>{const r=t[a]?.tokens;return r==null?n:n+r},0)}function Ct({row:s,pending:t}){const{t:n}=R(),a=t?"…":s?.tokens==null?"—":We(s.tokens);return e.jsx("span",{className:"w-12 shrink-0 text-right text-muted-foreground text-xs tabular-nums",title:s?.error||n("Estimate"),children:a})}function St({tokens:s}){return s<=0?null:e.jsx("span",{className:"ml-2 font-normal text-muted-foreground text-xs tabular-nums",children:We(s)})}function It(s,t){const[n,a]=l.useState({}),[r,o]=l.useState(()=>s.length>0),i=s.join("\0"),m=l.useRef(t);return m.current=t,l.useEffect(()=>{let u=!1;const x=i.length===0?[]:i.split("\0");if(x.length===0){a({}),o(!1);return}return o(!0),m.current(x).then(h=>{u||a(Ax(h))}).finally(()=>{u||o(!1)}),()=>{u=!0}},[i]),{rows:n,pending:r}}const Va={replace:"Text replacement",apply_patch:"Apply patch (default)"},Ex={subagent:ec,workflow:Dn,todo:Zl,plan:Ql,ask_user:Xl,browser:Jl,web:so,background_tasks:Yl,memory:eo,isolated_sandbox:Nu,computer:Mn,turn_discard:ql};function Es({icon:s,title:t,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(s,{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:[t,i&&e.jsx(Ze,{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 Mx({disabled:s}){const{t}=R(),n=g(c=>c.webSearchChain),a=g(c=>c.setWebSearchChain),r=et(),o=l.useMemo(()=>nc(r),[r]),[i,m]=l.useState(null),u=(c,f)=>{a(n.map((d,p)=>p===c?{...d,...f}:d))},x=c=>a(n.filter((f,d)=>d!==c)),h=(c,f)=>{if(c===f)return;const d=[...n],[p]=d.splice(c,1);p&&(d.splice(f,0,p),a(d))};return e.jsxs("div",{className:"space-y-2","data-settings-row":"tools.webSearchChain",children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:t("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:t("Default: use the current session model's built-in search when available, otherwise Exa.")}),n.map((c,f)=>e.jsxs("div",{className:"flex items-center gap-2 rounded-md border px-2 py-1.5",draggable:!s,onDragStart:d=>{d.dataTransfer.effectAllowed="move",m(f)},onDragEnd:()=>m(null),onDragOver:d=>{i!==null&&i!==f&&d.preventDefault()},onDrop:d=>{d.preventDefault(),i!==null&&h(i,f),m(null)},children:[e.jsx(ac,{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:c.providerId,modelId:c.modelId,reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,onSelect:(d,p)=>u(f,{providerId:d,modelId:p}),onReasoningChange:()=>{},onThinkingChange:()=>{}})}),e.jsx(y,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 shrink-0 p-0",disabled:s,onClick:()=>x(f),"aria-label":t("Remove"),children:e.jsx(Pe,{className:"h-3.5 w-3.5"})})]},`${c.providerId}/${c.modelId}`)),n.length<rc&&e.jsx("div",{className:"max-w-xs",children:e.jsx(ze,{providers:o,providerId:"",modelId:"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,triggerLabel:`+ ${t("Add candidate")}`,onSelect:(c,f)=>a([...n,{providerId:c,modelId:f}]),onReasoningChange:()=>{},onThinkingChange:()=>{}})}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Final fallback: Exa (keyless hosted search). Not a chain entry; always last.")})]})}function Px(){const{t:s}=R(),t=g(N=>N.disabledBuiltinTools),n=g(N=>N.toggleBuiltinTool),a=g(N=>N.subagentAllowedModes),r=g(N=>N.setSubagentAllowedModes),o=g(N=>N.exploreFoldEnabled),i=g(N=>N.setExploreFoldEnabled),m=g(N=>N.rtkEnabled),u=g(N=>N.computerPreview),x=g(N=>N.setComputerPreview),h=g(N=>N.openLinksInBuiltinBrowser),c=g(N=>N.setOpenLinksInBuiltinBrowser),f=g(N=>N.setRtkEnabled),d=g(N=>N.protectedActionsInCode),p=g(N=>N.setProtectedActionsInCode),j=g(N=>N.editMode),b=g(N=>N.setEditMode),A=It(zt.map(N=>N.id),()=>window.electronAPI.assets.builtinToolOccupancy()),v=kt(zt.filter(N=>!t.includes(N.id)).map(N=>N.id),A.rows),[k,I]=l.useState(null),M=!t.includes("subagent"),$=(N,z)=>{r(z?[...new Set([...a,N])]:a.filter(H=>H!==N))},E=async N=>{await window.electronAPI.browser.clearData(N),I(N),setTimeout(()=>I(null),2e3)},L=!t.includes("computer"),[T,C]=l.useState(null),[S,W]=l.useState(!1);l.useEffect(()=>{if(!L){C(null);return}let N=!1;return window.electronAPI.computer.capabilities().then(z=>{!N&&z.ok&&C(z.capabilities)}),()=>{N=!0}},[L]),l.useEffect(()=>{if(!S)return;let N=!1;const z=()=>{window.electronAPI.computer.capabilities().then(U=>{!N&&U.ok&&C(U.capabilities)})};z();const H=window.setInterval(z,2e3);return()=>{N=!0,window.clearInterval(H)}},[S]);const q={collaboration:null,web:null,execution:e.jsx(Es,{rowId:"tools.editMode",newSession:!0,icon:Eu,title:s("File edit mode"),description:s("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(ne,{items:Object.fromEntries(fa.map(N=>[N,s(Va[N])])),value:j,onValueChange:N=>{Hl(N)&&b(N)},children:[e.jsx(ae,{className:"w-44 shrink-0","aria-label":s("File edit mode"),children:e.jsx(re,{})}),e.jsx(oe,{children:fa.map(N=>e.jsx(Z,{value:N,children:s(Va[N])},N))})]})}),context:e.jsxs(e.Fragment,{children:[e.jsx(Es,{icon:Ru,newSession:!0,title:s("Explore fold"),description:s("Let the agent mark exploratory reads and keep only a short report in later model context. Timeline stays intact."),control:e.jsx(ce,{checked:o,onCheckedChange:i})}),e.jsx(Es,{rowId:"tools.rtkEnabled",newSession:!0,icon:Uu,title:s("RTK command compression"),description:s("Compress supported command output before it enters the model context. Takes effect on new conversations."),control:e.jsx(ce,{checked:m,onCheckedChange:f})})]}),safety:e.jsxs(e.Fragment,{children:[e.jsx(Es,{icon:yn,newSession:!0,title:s("Protected action confirmation"),description:s("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(ce,{checked:d,onCheckedChange:p})}),e.jsx(Tx,{})]})};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:[s("Built-in tools"),e.jsx(St,{tokens:v})]}),e.jsx("p",{className:"text-muted-foreground text-sm",children:s("Toggle the built-in tools available to agents.")})]}),Cx.map(N=>e.jsxs("section",{className:"space-y-3",children:[e.jsx("h4",{className:"border-b pb-2 text-base font-semibold",children:s(N.label)}),Sx(zt,N.id).map(z=>e.jsxs(Es,{icon:Ex[z.id]??to,title:s(z.name),description:s(z.description),newSession:z.id==="isolated_sandbox"?s("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(Ct,{row:A.rows[z.id],pending:A.pending&&!A.rows[z.id]}),e.jsx(ce,{checked:!t.includes(z.id),onCheckedChange:H=>{n(z.id,H),z.id==="computer"&&H&&W(!0)}})]}),children:[z.id==="web"?e.jsx(Mx,{disabled:t.includes("web")}):null,z.id==="subagent"?e.jsxs("div",{className:"space-y-2","data-settings-row":"tools.subagentModes",children:[[["task","One-shot task agents"],["coworker","Persistent coworkers"]].map(([H,U])=>e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("span",{className:"text-sm",children:s(U)}),e.jsx(ce,{checked:a.includes(H),disabled:!M,onCheckedChange:B=>$(H,B)})]},H)),!M&&e.jsx("p",{className:"text-muted-foreground text-xs",children:s("The unified subagent tool is off. Re-enabling it keeps this mode selection.")})]}):null,z.id==="computer"&&L?e.jsx("div",{className:"space-y-2","data-settings-row":"tools.computer",children:T&&Go(T)==="unsupported"?e.jsx("p",{className:"text-muted-foreground text-xs",children:s("This platform cannot operate the desktop yet.")}):e.jsxs(e.Fragment,{children:[T?.platform==="darwin"&&e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Computer needs Screen Recording to capture windows and Accessibility to inspect or click them. Grant both to EnsoCode, then restart the app.")}),T&&e.jsxs("p",{className:"text-muted-foreground text-xs",children:[s(T.capturePermission==="granted"?"Capture: granted":"Capture: denied"),T.axPermission!=="unsupported"&&e.jsxs(e.Fragment,{children:[" · ",s(T.axPermission==="granted"?"Input/AX: granted":"Input/AX: denied")]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(y,{variant:"outline",size:"sm",onClick:()=>W(!0),children:s("Show permission guide")}),T?.platform==="darwin"&&e.jsxs(e.Fragment,{children:[e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.computer.openPermissions("screen")},children:s("Open Screen Recording settings")}),e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.computer.openPermissions("accessibility")},children:s("Open Accessibility settings")})]})]}),T?.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:s("Show the app being operated")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:s("While the AI works in an app in the background, a small floating window shows that app live. Close it any time.")})]}),e.jsx(ce,{checked:u,onCheckedChange:x})]}),e.jsx(Ix,{})]})]})}):null,z.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:s("Open chat links in the built-in browser")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Clicking a web link in chat opens it in the side panel browser. {{key}}+Click opens it in the external browser.",{key:sc?"Cmd":"Ctrl"})})]}),e.jsx(ce,{checked:h,onCheckedChange:c})]}),e.jsx("p",{className:"text-muted-foreground text-xs",children:s("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(H=>e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{E(H)},children:s(k===H?"Cleared":H==="cookies"?"Clear cookies":H==="cache"?"Clear cache":"Clear all browsing data")},H))})]}):null]},z.id)),q[N.id]]},N.id)),e.jsx(Rx,{open:S,capabilities:T,onOpenChange:W})]})}function Tx(){const{t:s}=R(),t=g(d=>d.dcgEnabled),n=g(d=>d.setDcgEnabled),[a,r]=l.useState(null),[o,i]=l.useState(!1),[m,u]=l.useState(null),[x,h]=l.useState(!1);l.useEffect(()=>{let d=!1;return window.electronAPI.dcg.status().then(p=>{d||r(p)}),()=>{d=!0}},[]);const c=async d=>{h(!1),i(!0),u(null);const p=await window.electronAPI.dcg[d]();r(p.status),p.ok?n(d==="install"):u(p.error??s("Operation failed")),i(!1)},f=a?.installed===!0;return e.jsxs(Es,{rowId:"tools.dcgEnabled",newSession:!0,icon:tc,title:s("Destructive command guard (dcg)"),description:s("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(ce,{checked:t&&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?s("Installed v{{version}}",{version:a.version}):s("Not installed"):s("Not available on this platform"):s("Loading…")}),a?.supported&&(f?e.jsx(y,{variant:"outline",size:"xs",disabled:o,onClick:()=>{c("uninstall")},children:s("Uninstall")}):e.jsx(y,{variant:"outline",size:"xs",disabled:o,onClick:()=>h(!0),children:s(o?"Installing…":"Install")}))]}),m&&e.jsx("p",{className:"text-destructive text-xs",children:m}),e.jsx(ye,{open:x,onOpenChange:h,children:e.jsxs(we,{className:"max-w-md",zIndexLevel:"nested",children:[e.jsxs(Ne,{children:[e.jsx(ke,{children:s("Install dcg")}),e.jsx(Ye,{children:s("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(Ce,{children:e.jsxs("div",{className:"flex gap-2 rounded-md border border-destructive/32 bg-destructive/8 p-3 text-sm",children:[e.jsx(Ke,{className:"mt-0.5 h-4 w-4 shrink-0 text-destructive"}),e.jsx("p",{children:s("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(Ee,{children:[e.jsx(y,{variant:"outline",size:"sm",onClick:()=>h(!1),children:s("Cancel")}),e.jsx(y,{size:"sm",onClick:()=>{c("install")},children:s("Agree and install")})]})]})})]})}function Rx({open:s,capabilities:t,onOpenChange:n}){const{t:a}=R(),r=t?Go(t):null;return e.jsx(ye,{open:s,onOpenChange:n,children:e.jsxs(we,{className:"max-w-md",zIndexLevel:"nested",children:[e.jsxs(Ne,{children:[e.jsx(ke,{children:a("Grant Computer permissions")}),e.jsx(Ye,{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(Ce,{className:"space-y-3",children:[!t&&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(Ke,{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.")})]}),t?.platform==="darwin"&&r!=="unsupported"&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("p",{className:"text-muted-foreground text-xs",children:[a(t.capturePermission==="granted"?"Capture: granted":"Capture: denied")," · ",a(t.axPermission==="granted"?"Input/AX: granted":"Input/AX: denied"),t.detail?` · ${t.detail}`:""]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.computer.openPermissions("screen")},children:a("Open Screen Recording settings")}),e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.computer.openPermissions("accessibility")},children:a("Open Accessibility settings")})]})]})]}),e.jsx(Ee,{className:"sm:justify-end",children:e.jsx(y,{size:"sm",onClick:()=>n(!1),children:a("Done")})})]})})}function Ox(){return e.jsxs("div",{className:"space-y-10",children:[e.jsx(Dx,{}),!window.electronAPI.remote&&e.jsx(Lx,{}),e.jsx(Fx,{})]})}function Dx(){const{t:s}=R(),[t,n]=l.useState(null),[a,r]=l.useState(null),[o,i]=l.useState(!1),[m,u]=l.useState(null),[x,h]=l.useState(null),[c,f]=l.useState(!1),d=t?.pairingExpiresAt;l.useEffect(()=>{if(!d){h(null);return}const A=()=>h(Math.max(0,Math.ceil((d-Date.now())/1e3)));A();const v=setInterval(A,1e3);return()=>clearInterval(v)},[d]);const p=A=>{navigator.clipboard.writeText(A).then(()=>{f(!0),setTimeout(()=>f(!1),1500)})};l.useEffect(()=>(window.electronAPI.pair.status().then(n),window.electronAPI.pair.onStatusChanged(A=>{n(A),(A.pairing||A.devices.length>0)&&u(null)})),[]),l.useEffect(()=>{const A=t?.inviteUri;if(!A){r(null);return}oc.toDataURL(A,{width:320,margin:1}).then(r).catch(()=>{})},[t?.inviteUri]);const j=async()=>{i(!0),u(null);const A=await window.electronAPI.pair.start();i(!1),A.ok||u(A.error??s("Failed to start pairing"))},b=t?.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:s("Allow connections")}),e.jsx("p",{className:"text-muted-foreground text-sm",children:s("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:t?.pairing?e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.pair.cancel()},children:s("Cancel pairing")}):e.jsxs(y,{variant:"outline",size:"sm",disabled:o,onClick:()=>{j()},children:[o?e.jsx(Me,{className:"mr-1.5 h-4 w-4 animate-spin"}):e.jsx(an,{className:"mr-1.5 h-4 w-4"}),s("Generate pairing code")]})})]}),t&&!t.secureStorage&&e.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-dashed px-3 py-2 text-xs",children:[e.jsx(Ke,{className:"mt-0.5 h-4 w-4 shrink-0 text-destructive"}),e.jsx("span",{className:"text-muted-foreground",children:s("Secure storage is unavailable on this system, so pairing keys are stored unencrypted.")})]}),m&&e.jsx("p",{className:"text-destructive text-xs",children:m}),t?.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:s("Pairing QR code"),className:"mx-auto h-52 w-52"}):e.jsx(Me,{className:"mx-auto h-5 w-5 animate-spin text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:s("Scan with your phone camera")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:s("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:s("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?s("The code expires in 60 seconds and can only be used once."):x>0?s("Expires in {{seconds}}s · single use",{seconds:x}):s("Code expired")})]}),t.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:t.inviteUri}),e.jsxs(y,{variant:"outline",size:"sm",className:"shrink-0",onClick:()=>p(t.inviteUri),children:[c?e.jsx(no,{className:"mr-1.5 h-3.5 w-3.5"}):e.jsx(Xr,{className:"mr-1.5 h-3.5 w-3.5"}),s(c?"Copied":"Copy")]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"font-medium text-sm",children:s("Paired devices")}),b.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx(an,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:s("No paired devices")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:s("Generate a pairing code to let a phone or another desktop connect.")})]}):e.jsx("div",{className:"space-y-1",children:b.map(A=>e.jsx(zx,{device:A},A.pairId))})]})]})}function Lx(){const{t:s}=R(),t=ot(i=>i.nodes),n=ot(i=>i.secureStorage),a=ot(i=>i.refresh),[r,o]=l.useState(!1);return l.useEffect(()=>ot.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:s("Connect to a node")}),e.jsx("p",{className:"text-muted-foreground text-sm",children:s("Browse and drive conversations on another EnsoCode desktop. Its agent, keys and history stay there.")})]}),e.jsxs(y,{variant:"outline",size:"sm",className:"shrink-0",onClick:()=>o(!0),children:[e.jsx(Re,{className:"mr-1.5 h-4 w-4"}),s("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(Ke,{className:"mt-0.5 h-4 w-4 shrink-0 text-destructive"}),e.jsx("span",{className:"text-muted-foreground",children:s("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:s("Connected nodes")}),t.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx(Mn,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:s("No connected nodes")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:s("Each connecting computer needs its own pairing code from the other desktop.")})]}):e.jsx("div",{className:"space-y-1",children:t.map(i=>e.jsx(_x,{node:i,onChanged:()=>{a()}},i.nodeId))})]}),e.jsx(ic,{open:r,onOpenChange:o,switchOnSuccess:!1})]})}function Ko({transport:s,rttMs:t}){const{t:n}=R(),a=s==="direct",r=cc(t);return e.jsxs("span",{className:K("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 zx({device:s}){const{t}=R(),[n,a]=l.useState(null),r=async()=>{n!==null&&(n.trim()&&n.trim()!==s.deviceName&&await window.electronAPI.pair.rename(s.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:K("h-2 w-2 shrink-0 rounded-full",s.phoneOnline?"bg-emerald-500":s.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:s.deviceName}),e.jsx("span",{className:"shrink-0 text-muted-foreground text-xs",children:s.phoneOnline?t("Online"):s.connected?t("Waiting for device"):t("Offline")}),s.phoneOnline&&e.jsx(Ko,{transport:s.transport,rttMs:s.rttMs}),e.jsx("button",{type:"button",title:t("Click to switch: view-only devices cannot send, approve or stop."),onClick:()=>{window.electronAPI.pair.setScope(s.pairId,s.scope==="read"?"operate":"read")},className:K("shrink-0 rounded px-1.5 py-0.5 text-[10px] leading-none transition-colors",s.scope==="read"?"bg-amber-500/15 text-amber-600 hover:bg-amber-500/25":"bg-muted text-muted-foreground hover:bg-accent"),children:s.scope==="read"?t("View only"):t("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(y,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground",title:t("Rename"),onClick:()=>a(s.deviceName),children:e.jsx(hs,{className:"h-3.5 w-3.5"})}),e.jsx(y,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-destructive",onClick:()=>{window.electronAPI.pair.revoke(s.pairId)},children:e.jsx(Pe,{className:"h-3.5 w-3.5"})})]})]})}function _x({node:s,onChanged:t}){const{t:n}=R(),[a,r]=l.useState(null),o=async()=>{a!==null&&(a.trim()&&a.trim()!==s.label&&(await window.electronAPI.nodes.rename(s.nodeId,a),t()),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(lc,{node:s}),a===null?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"truncate font-medium text-sm",children:s.label}),s.hostname&&s.hostname!==s.label&&e.jsx("span",{className:"shrink-0 truncate font-mono text-[10px] text-muted-foreground",children:s.hostname}),e.jsx("span",{className:"shrink-0 text-muted-foreground text-xs",children:s.hostOnline?n("Online"):s.connected?n("Remote desktop is offline"):n("Offline")}),s.hostOnline&&e.jsx(Ko,{transport:s.transport,rttMs:s.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(y,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground",title:n("Rename"),onClick:()=>r(s.label),children:e.jsx(hs,{className:"h-3.5 w-3.5"})}),e.jsx(y,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-destructive",title:n("Disconnect"),onClick:()=>{window.electronAPI.nodes.remove(s.nodeId).then(t)},children:e.jsx(Pe,{className:"h-3.5 w-3.5"})})]})]})}function Fx(){const{t:s}=R(),[t,n]=l.useState(null),[a,r]=l.useState(null);l.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:s("Relay server")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:s("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??t?.relayUrl??"",onChange:i=>r(i.target.value),placeholder:"https://relay.example.com",className:"font-mono text-xs"}),a===null?e.jsx(y,{variant:"ghost",size:"icon",className:"h-8 w-8 shrink-0 text-muted-foreground",onClick:()=>r(t?.relayUrl??""),children:e.jsx(hs,{className:"h-3.5 w-3.5"})}):e.jsxs(y,{size:"sm",className:"shrink-0",onClick:()=>{o()},children:[e.jsx(no,{className:"mr-1.5 h-3.5 w-3.5"}),s("Save")]})]})]})})}function Bx({onOpenBots:s}){const{t}=R(),n=g(c=>c.botModeEnabled),a=g(c=>c.setBotModeEnabled),r=g(c=>c.scratchSessionsEnabled),o=g(c=>c.setScratchSessionsEnabled),i=g(c=>c.dropShelfEnabled),m=g(c=>c.setDropShelfEnabled),u=g(c=>c.secretaryEnabled),x=g(c=>c.setSecretaryEnabled),h=window.electronAPI.env.platform==="darwin"&&!window.electronAPI.remote;return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:t("Experimental")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("Features still being tested. They may change or be removed.")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ie,{rowId:"experimental.botMode",title:t("Bot mode"),description:t("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(y,{variant:"outline",size:"sm",onClick:s,children:t("Bot mode settings")}),e.jsx(Ie,{rowId:"experimental.scratchSessions",title:t("Temporary chats"),description:t("Chats that are not tied to a project. Tools follow your global settings."),checked:r,onChange:o}),h&&e.jsx(Ie,{rowId:"experimental.dropShelf",title:t("Drop shelf"),description:t("When you drag files in Finder, a small panel appears at the top right of the screen. Drop them on it to reference them in the current conversation, or drop folders to open them as projects, even when EnsoCode is minimized or in the tray."),checked:i,onChange:m}),e.jsx(Ie,{rowId:"experimental.secretary",title:t("Secretary"),description:t("A global agent that watches your projects and sessions, creates sessions to do the work, and reports results back to you."),checked:u,onChange:x})]})]})}function Ux({instruction:s,onClose:t}){const{t:n}=R(),a=g(E=>E.addInstructions),r=g(E=>E.updateInstruction),o=s==="new",i=o||!s?null:s,[m,u]=l.useState(""),[x,h]=l.useState(""),[c,f]=l.useState(!1),[d,p]=l.useState(!1),[j,b]=l.useState(null),[A,v]=l.useState(!1),[k,I]=l.useState(!1);l.useEffect(()=>{if(s){if(s==="new"){u(""),h(""),v(!1),b(null),I(!1),f(!1);return}u(s.name),v(!1),b(null),I(!1),f(!0),window.electronAPI.instructions.read(s.id,s.local,s.sourcePath).then(E=>{E.ok?h(E.content):(h(""),b(E.error??n("Failed to read content")))}).finally(()=>f(!1))}},[s,n]);const M=!!(i&&!i.local&&i.sourcePath),$=async()=>{if(!s||!m.trim())return;if(p(!0),o){const L=crypto.randomUUID(),T=await window.electronAPI.instructions.write(L,x);if(!T.ok){p(!1),b(n("Failed to save"));return}const C=a([{id:L,name:m.trim(),source:"Manual",local:!0,bytes:T.bytes,enabled:!0}]);if(p(!1),C===0){window.electronAPI.instructions.delete(L),b(n("An instruction with this name already exists"));return}t();return}if(!i){p(!1);return}if(M&&k&&i.sourcePath){const L=await window.electronAPI.instructions.writeSource(i.id,i.sourcePath,x);if(p(!1),!L.ok){b(L.error??n("Failed to save"));return}r(i.id,{name:m.trim(),bytes:L.bytes}),t();return}const E=await window.electronAPI.instructions.write(i.id,x);if(p(!1),!E.ok){b(n("Failed to save"));return}r(i.id,{name:m.trim(),local:!0,bytes:E.bytes}),t()};return e.jsx(ye,{open:s!==null,onOpenChange:E=>!E&&t(),children:e.jsxs(we,{className:"max-w-2xl",children:[e.jsx(Ne,{children:e.jsx(ke,{children:n(o?"Add Instruction":"Edit Instruction")})}),e.jsxs(Ce,{className:"space-y-4",children:[o?null:M?e.jsxs("div",{className:K("w-full rounded-md border px-3 py-2.5 transition-colors",k?"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:[k?e.jsx(Ke,{className:"h-3.5 w-3.5 shrink-0 text-destructive"}):e.jsx(pt,{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(ce,{checked:k,onCheckedChange:I})]}),e.jsx("p",{className:"mt-1.5 pl-5.5 text-muted-foreground text-xs leading-relaxed",children:k?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(pt,{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(he,{children:[e.jsx(pe,{children:n("Name")}),e.jsx(J,{value:m,onChange:E=>u(E.target.value)})]}),e.jsxs(he,{children:[e.jsx(pe,{children:n("Content")}),c?e.jsxs("div",{className:"flex w-full items-center justify-center gap-2 rounded-md border py-12",children:[e.jsx(Me,{className:"h-4 w-4 animate-spin text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground text-xs",children:n("Loading...")})]}):e.jsx(Xe,{value:x,onChange:E=>{h(E.target.value),v(!0)},rows:16,className:"font-mono text-xs"})]}),j&&e.jsxs("p",{className:"flex items-center gap-1.5 text-destructive text-xs",children:[e.jsx(Rs,{className:"h-3.5 w-3.5 shrink-0"}),j]})]}),e.jsxs(Ee,{children:[e.jsx(y,{variant:"outline",size:"sm",onClick:t,children:n("Cancel")}),e.jsxs(y,{size:"sm",variant:M&&k?"destructive":"default",disabled:!m.trim()||c||d,onClick:$,children:[d&&e.jsx(Me,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}),n(M?k?"Overwrite original":A?"Save as local copy":"Save":"Save")]})]})]})})}const Ga=s=>s<1024?`${s} B`:`${(s/1024).toFixed(1)} KB`;function $x(){const{t:s}=R(),t=g(c=>c.instructions),n=g(c=>c.updateInstruction),a=g(c=>c.removeInstruction),[r,o]=l.useState(!1),[i,m]=l.useState(null),u=t.map(c=>c.id),x=It(u,c=>window.electronAPI.assets.instructionOccupancy(c)),h=kt(t.filter(c=>c.enabled).map(c=>c.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:[s("Instruction Files"),e.jsx(St,{tokens:h}),e.jsx(Ze,{})]}),e.jsx("p",{className:"text-muted-foreground text-sm",children:s("Global CLAUDE.md / AGENTS.md style files from local AI tools")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:s("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(y,{variant:"outline",size:"sm",onClick:()=>o(!0),children:[e.jsx(Nt,{className:"mr-1.5 h-4 w-4"}),s("Import from local apps")]}),e.jsxs(y,{variant:"outline",size:"sm",onClick:()=>m("new"),children:[e.jsx(Re,{className:"mr-1.5 h-4 w-4"}),s("Add instruction")]})]})]}),t.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:s("No instruction files yet")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:s("Import instruction files from local apps or add one manually to get started")})]}):e.jsx("div",{className:"space-y-1",children:t.map(c=>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.${c.id}`,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:K("shrink-0 font-medium text-sm",!c.enabled&&"text-muted-foreground line-through"),children:c.name}),e.jsx(se,{variant:"secondary",className:"shrink-0 text-[11px]",children:c.source}),!c.local&&e.jsxs(se,{variant:"outline",className:"shrink-0 gap-1 text-[11px]",children:[e.jsx(ao,{className:"h-3 w-3"}),s("Linked")]}),e.jsx("span",{className:"min-w-0 truncate text-muted-foreground text-xs",children:c.local?`${s("Local copy")} · ${Ga(c.bytes)}`:`${c.sourcePath} · ${Ga(c.bytes)}`})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(Ct,{row:x.rows[c.id],pending:x.pending&&!x.rows[c.id]}),e.jsx(ce,{checked:c.enabled,onCheckedChange:f=>n(c.id,{enabled:f})}),e.jsx(y,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",onClick:()=>m(c),children:e.jsx(hs,{className:"h-3.5 w-3.5"})}),e.jsx(y,{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(c.id),children:e.jsx(Pe,{className:"h-3.5 w-3.5"})})]})]},c.id))}),e.jsx(zn,{kind:"instruction",open:r,onOpenChange:o}),e.jsx(Ux,{instruction:i,onClose:()=>m(null)})]})}function Vx(){const{t:s}=R();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:s("Shortcuts")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("Click a shortcut to rebind it. Backspace removes it; Esc cancels.")})]}),e.jsx(Wx,{}),e.jsx(Kx,{})]})}function Gx(){const[s,t]=l.useState([]);return l.useEffect(()=>{const n=window.electronAPI.extensionPlugins;let a=!0;const r=()=>{n.list().then(i=>a&&t(mc(i)))};r();const o=n.onChanged(r);return()=>{a=!1,o()}},[]),s}function Kx(){const{t:s}=R(),t=Gx(),n=g(p=>p.keybindings),a=g(p=>p.setKeybinding),r=g(p=>p.resetKeybinding),[o,i]=l.useState(null),[m,u]=l.useState(null);if(t.length===0)return null;const x=ro(n),{rows:h}=dc(t,n,x),c=p=>h.find(j=>j.action===p)?.command.title??s(on[p]??p),f=()=>{i(null),u(null)},d=(p,j,b)=>{if(p.preventDefault(),p.stopPropagation(),p.key==="Escape")return f();if(p.key==="Backspace"||p.key==="Delete")return a(j,""),f();const A=lo(p);if(!A)return;const v=rn.find(k=>x[k]===A)??h.find(k=>k.action!==j&&!k.conflict&&k.binding===A)?.action;if(v)return u(v);A===b?r(j):a(j,A),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:j,binding:b,custom:A,conflict:v})=>{const k=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:j.title}),e.jsxs("p",{className:"text-muted-foreground text-xs",children:[j.pluginName,v&&!k&&e.jsx("span",{className:"ml-2 text-destructive",children:s('Already used by "{{label}}"',{label:c(v)})})]})]}),k&&m&&e.jsx("span",{className:"text-destructive text-xs",children:s('Already used by "{{label}}"',{label:c(m)})}),b&&!k&&e.jsx("button",{type:"button",title:s("Remove shortcut"),onClick:()=>a(p,""),className:"rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:e.jsx(js,{className:"h-3.5 w-3.5"})}),A&&!k&&e.jsx("button",{type:"button",title:s("Reset to default"),onClick:()=>r(p),className:"rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:e.jsx(On,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>{i(p),u(null)},onKeyDown:k?I=>d(I,p,j.key):void 0,onBlur:()=>k&&f(),autoFocus:k,className:K("rounded-md px-1 py-0.5 transition-colors",k?"ring-1 ring-ring":"hover:bg-muted",v&&!k&&"opacity-50 line-through"),children:k?e.jsx("span",{className:"text-muted-foreground text-xs",children:s("Press shortcut…")}):b?e.jsx(oo,{children:io(b)}):e.jsx("span",{className:"text-muted-foreground text-xs",children:s("No shortcut")})})]},p)})})]})}function Wx(){const{t:s}=R(),t=g(h=>h.keybindings),n=g(h=>h.setKeybinding),a=g(h=>h.resetKeybinding),[r,o]=l.useState(null),[i,m]=l.useState(null),u=ro(t),x=h=>{if(h.preventDefault(),h.stopPropagation(),!r)return;if(h.key==="Escape"){o(null),m(null);return}if(h.key==="Backspace"||h.key==="Delete"){n(r,""),o(null),m(null);return}const c=lo(h,{allowBare:r==="send-message"||r==="voice-hold"});if(!c)return;const f=rn.find(d=>d!==r&&u[d]===c);if(f){m(f);return}c===uc[r]?a(r):n(r,c),o(null),m(null)};return e.jsx("div",{className:"divide-y rounded-md border",children:rn.map(h=>{const c=r===h,f=t[h]!==void 0,d=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:s(on[h])}),ga[h]&&e.jsx("p",{className:"text-muted-foreground text-xs",children:s(ga[h])})]}),c&&i&&e.jsx("span",{className:"text-xs text-destructive",children:s('Already used by "{{label}}"',{label:s(on[i])})}),d&&!c&&e.jsx("button",{type:"button",title:s("Remove shortcut"),onClick:()=>n(h,""),className:"rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:e.jsx(js,{className:"h-3.5 w-3.5"})}),f&&!c&&e.jsx("button",{type:"button",title:s("Reset to default"),onClick:()=>a(h),className:"rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:e.jsx(On,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>{o(h),m(null)},onKeyDown:c?x:void 0,onBlur:()=>{c&&(o(null),m(null))},autoFocus:c,className:K("rounded-md px-1 py-0.5 transition-colors",c?"ring-1 ring-ring":"hover:bg-muted"),children:c?e.jsx("span",{className:"text-xs text-muted-foreground",children:s("Press shortcut…")}):d?e.jsx(oo,{children:io(d)}):e.jsx("span",{className:"text-xs text-muted-foreground",children:s("No shortcut")})})]},h)})})}function Hx(s){return s.serverId??s.serverName}function Wo(s,t){const n={...s};return t.serverId&&delete n[t.serverName],n[Hx(t)]={state:t.state,...t.toolCount!==void 0?{toolCount:t.toolCount}:{},...t.error?{error:t.error}:{}},n}function qx(s){return s.reduce((t,n)=>Wo(t,n),{})}function Yx(s,t){return{...s,[t]:{state:"connecting"}}}function Jx(s,t,n){return{...s,[t]:{state:"error",...n?{error:n}:{}}}}const Bt=(s,t)=>{const n={...s};return delete n[t],n},fs=xc()((s,t)=>({statuses:{},authorized:{},pending:{},bind:()=>(window.electronAPI.mcp.authState().then(n=>s({authorized:n})).catch(()=>{}),window.electronAPI.mcp.statusSnapshot().then(n=>s({statuses:{...t().statuses,...qx(n)}})).catch(()=>{}),window.electronAPI.mcp.onStatus(n=>{if(n.type==="mcp-status-cleared"){s({statuses:{}});return}s({statuses:Wo(t().statuses,n)}),window.electronAPI.mcp.authState().then(a=>s({authorized:a})).catch(()=>{})})),authorize:async n=>{s({statuses:Yx(t().statuses,n),pending:{...t().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)}}s({pending:Bt(t().pending,n),...a.ok?{authorized:{...t().authorized,[n]:!0}}:{statuses:Jx(t().statuses,n,a.error)}})},revoke:async n=>{await window.electronAPI.mcp.revoke(n),s({authorized:Bt(t().authorized,n),statuses:Bt(t().statuses,n)})}})),ts=s=>typeof s=="string"?s.trim():"",Xx=s=>Array.isArray(s)?s.filter(t=>typeof t=="string"):[],Ho=s=>{if(!s||typeof s!="object")return{};const t={};for(const[n,a]of Object.entries(s))typeof a=="string"&&(t[n]=a);return t};function Qx(s){const t=Ho(s);return delete t[""],Object.keys(t).length>0?t:void 0}function Ka(s){const t={};for(const n of s.split(`
11
+ `)){const a=n.indexOf(":"),r=a>0?n.slice(0,a).trim():"";r&&(t[r]=n.slice(a+1).trim())}return Object.keys(t).length>0?t:void 0}const Wa=s=>Object.entries(s??{}).map(([t,n])=>`${t}: ${n}`).join(`
12
+ `);function Zx(s,t){const n=ts(s).toLowerCase();return n==="sse"?"sse":n==="http"||n==="streamable-http"?"http":n==="stdio"?"stdio":t?"http":"stdio"}function Ha(s){if(!s||typeof s!="object")return[];const t=[];for(const[n,a]of Object.entries(s)){if(!a||typeof a!="object")continue;const r=a,o=ts(r.url)||ts(r.serverUrl),i=ts(r.command);if(!i&&!o)continue;const m=i?void 0:Qx(r.headers);t.push({name:n,transport:Zx(r.type??r.transport,o),command:i||void 0,args:i?Xx(r.args):void 0,env:i?Ho(r.env):void 0,url:o||void 0,...m?{headers:m}:{}})}return t}const eh=s=>{const t=s.trim();return(t.match(/^```(?:json)?\s*([\s\S]*?)\s*```$/i)?.[1]??t).trim()},sh=s=>s.startsWith('"')&&!s.startsWith("{")&&!s.startsWith("[")?`{${s}}`:s,th=s=>{if(!s||typeof s!="object"||Array.isArray(s))return s;const t=s;if(t.mcpServers!=null)return t.mcpServers;if(t.mcp_servers!=null)return t.mcp_servers;if(t.servers!=null)return t.servers;const n=t.mcp;if(n&&typeof n=="object"&&!Array.isArray(n)){const a=n.servers;if(a!=null)return a}return s},nh=s=>{if(!s||typeof s!="object"||Array.isArray(s))return!1;const t=s;return!!(ts(t.command)||ts(t.url)||ts(t.serverUrl))},ah=s=>{const t=ts(s.command);return t&&t.split(/[\\/]/).pop()?.trim()||"mcp"},xn=s=>{if(Array.isArray(s))return s.flatMap(xn);if(nh(s)){const t=ts(s.name)||ts(s.id)||ah(s);return Ha({[t]:s})}return Ha(s)};function Ut(s){let t;try{t=JSON.parse(sh(eh(s)))}catch{return{ok:!1,error:"invalid-json"}}const n=Array.isArray(t)?t.flatMap(xn):xn(th(t));return n.length===0?{ok:!1,error:"empty"}:{ok:!0,servers:n}}const rh=1e4,oh=12e4,ih=600,lh=3600;function qa(s,t){let n;if(typeof s=="string"){const a=s.trim();if(!a||!/^\d+$/.test(a))return;n=Number(a)}else if(typeof s=="number")n=s;else return;if(!(!Number.isInteger(n)||n<=0))return t===void 0?n:Math.min(n,t)}const ch={theme:pc,disableFileHeader:!0,overflow:"scroll",preferredHighlighter:"shiki-js"};function dh(s){return new bc(s)}function qo({fileName:s,value:t,epoch:n,onChange:a,className:r="h-60"}){const{t:o}=R(),[i,m]=l.useState(!1),u=hc(ch),x=l.useRef(a);x.current=a;const h=l.useMemo(()=>({onChange(c){x.current(c.contents)}}),[]);return l.useEffect(()=>{let c=!0;return fc().then(()=>{c&&m(!0)}),()=>{c=!1}},[]),i?e.jsx("div",{className:K("w-full overflow-hidden rounded-lg border border-input",r),children:e.jsx(gc,{createEditor:dh,children:e.jsx(jc,{style:{height:"100%",overflow:"auto"},children:e.jsx(vc,{file:{name:s,contents:t},disableWorkerPool:!0,edit:!0,editorOptions:h,options:u},n)})})}):e.jsx("div",{className:K("flex w-full items-center justify-center rounded-lg border border-input text-muted-foreground text-xs",r),children:o("Loading...")})}const Ya=s=>{const t=s.split(`
13
+ `).map(n=>n.trim()).filter(Boolean);return t.length>0?t:void 0},Ja=s=>{const t={};for(const n of s.split(`
14
+ `)){const a=n.trim();if(!a)continue;const r=a.indexOf("=");r<=0||(t[a.slice(0,r).trim()]=a.slice(r+1))}return Object.keys(t).length>0?t:void 0},Xa=s=>s?Object.entries(s).map(([t,n])=>`${t}=${n}`).join(`
15
+ `):"",Qa=s=>{const t={type:s.transport};return s.command&&(t.command=s.command),s.args&&s.args.length>0&&(t.args=s.args),s.env&&Object.keys(s.env).length>0&&(t.env=s.env),s.url&&(t.url=s.url),s.headers&&Object.keys(s.headers).length>0&&(t.headers=s.headers),t};function uh({server:s,onClose:t}){const{t:n}=R(),a=g(D=>D.addMcpServers),r=g(D=>D.updateMcpServer),o=s==="new",[i,m]=l.useState("form"),[u,x]=l.useState(""),[h,c]=l.useState(""),[f,d]=l.useState(""),[p,j]=l.useState(""),[b,A]=l.useState("stdio"),[v,k]=l.useState(""),[I,M]=l.useState(""),[$,E]=l.useState(""),[L,T]=l.useState(""),[C,S]=l.useState(""),[W,q]=l.useState(""),[N,z]=l.useState(""),[H,U]=l.useState(""),[B,ie]=l.useState(0),[F,X]=l.useState(null),V=()=>({description:h.trim()||void 0,oauthClientName:b!=="stdio"&&f.trim()||void 0,oauthMetadataUrl:b!=="stdio"&&p.trim()||void 0,connectTimeoutSec:qa(W,ih),callTimeoutSec:qa(N,lh)}),le=D=>{x(D.name),A(D.transport),k(D.command??""),M((D.args??[]).join(`
16
+ `)),E(Xa(D.env&&Object.keys(D.env).length>0?D.env:void 0)),T(D.url??""),S(Wa(D.headers))},_=()=>{const D={type:b};if(b==="stdio"){D.command=v.trim();const Q=Ya(I);Q&&(D.args=Q);const ee=Ja($);ee&&(D.env=ee)}else{D.url=L.trim();const Q=Ka(C);Q&&(D.headers=Q)}return JSON.stringify(D,null,2)},de=(D,Q)=>{const ee=(Q??D.name).trim(),fe=D.env&&Object.keys(D.env).length>0?D.env:void 0,xe=D.args&&D.args.length>0?D.args:void 0;return D.transport==="stdio"?{name:ee,transport:D.transport,command:(D.command??"").trim(),args:xe,env:fe,url:void 0,headers:void 0,...V()}:{name:ee,transport:D.transport,url:(D.url??"").trim(),headers:D.headers&&Object.keys(D.headers).length>0?D.headers:void 0,command:void 0,args:void 0,env:void 0,...V()}};l.useEffect(()=>{if(!s)return;const D=s==="new"?null:s;m("form"),x(D?.name??""),c(D?.description??""),d(D?.oauthClientName??""),j(D?.oauthMetadataUrl??""),A(D?.transport??"stdio"),k(D?.command??""),M((D?.args??[]).join(`
17
+ `)),E(Xa(D?.env)),T(D?.url??""),S(Wa(D?.headers)),q(D?.connectTimeoutSec?.toString()??""),z(D?.callTimeoutSec?.toString()??""),U(""),ie(Q=>Q+1),X(null)},[s]);const ue=D=>n(D==="invalid-json"?"Invalid JSON":"No MCP servers found in JSON"),O=D=>{if(D===i)return;if(D==="json"){U(_()),ie(fe=>fe+1),X(null),m("json");return}const Q=Ut(H);if(!Q.ok){if(Q.error==="invalid-json"&&H.trim()){X(ue(Q.error));return}X(null),m("form");return}if(Q.servers.length!==1){X(n("JSON must describe a single MCP server to switch to the form"));return}const ee=Q.servers[0];le({...ee,name:u.trim()||ee.name}),X(null),m("form")},De=()=>{const D=Ut(H);if(!D.ok){X(ue(D.error));return}if(D.servers.length===1){const[Q]=D.servers;U(JSON.stringify(Qa(Q),null,2)),ie(ee=>ee+1),u.trim()||x(Q.name)}else U(JSON.stringify({mcpServers:Object.fromEntries(D.servers.map(Q=>[Q.name,Qa(Q)]))},null,2)),ie(Q=>Q+1);X(null)},te=!!u.trim()&&(b==="stdio"?!!v.trim():!!L.trim()),P=i==="json"?!!H.trim():te,Y=()=>{if(!s||!P)return;if(i==="json"){const Q=Ut(H);if(!Q.ok){X(ue(Q.error));return}if(!o&&Q.servers.length!==1){X(n("JSON must describe a single MCP server"));return}if(o){const ee=Q.servers.length===1;if(a(Q.servers.map(xe=>({...de(xe,ee&&u.trim()?u:xe.name),...ee?{}:{description:void 0},id:crypto.randomUUID(),source:"Manual",enabled:!0})))===0){X(n("This MCP server already exists"));return}}else r(s.id,de(Q.servers[0],u.trim()||Q.servers[0].name));t();return}const D=b==="stdio"?{name:u.trim(),transport:b,command:v.trim(),args:Ya(I),env:Ja($),url:void 0,headers:void 0,...V()}:{name:u.trim(),transport:b,url:L.trim(),headers:Ka(C),command:void 0,args:void 0,env:void 0,...V()};if(o){if(a([{...D,id:crypto.randomUUID(),source:"Manual",enabled:!0}])===0){X(n("This MCP server already exists"));return}}else r(s.id,D);t()};return e.jsx(ye,{open:s!==null,onOpenChange:D=>!D&&t(),children:e.jsxs(we,{children:[e.jsx(Ne,{children:e.jsx(ke,{children:n(o?"Add MCP Server":"Edit MCP Server")})}),e.jsxs(Ce,{className:"space-y-4",children:[e.jsx(Qs,{value:i,onValueChange:D=>O(D),children:e.jsxs(Zs,{children:[e.jsx(Je,{value:"form",children:n("Form")}),e.jsx(Je,{value:"json",children:n("JSON")})]})}),e.jsxs(he,{children:[e.jsx(pe,{children:n("Name")}),e.jsx(J,{value:u,onChange:D=>x(D.target.value)})]}),e.jsxs(he,{children:[e.jsx(pe,{children:n("Description (optional)")}),e.jsx(J,{value:h,onChange:D=>c(D.target.value),placeholder:n("One line telling the model what this server is for")})]}),i==="json"?e.jsxs(he,{children:[e.jsxs("div",{className:"flex w-full items-center justify-between",children:[e.jsx(pe,{children:n("JSON configuration")}),e.jsx(y,{variant:"ghost",size:"sm",className:"h-7 px-2",onClick:De,children:n("Format")})]}),e.jsx(qo,{fileName:"mcp.json",value:H,epoch:B,onChange:U}),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(he,{children:[e.jsx(pe,{children:n("Transport")}),e.jsxs(ne,{items:ja.map(D=>({value:D,label:D})),value:b,onValueChange:D=>A(D),children:[e.jsx(ae,{className:"w-full",children:e.jsx(re,{})}),e.jsx(oe,{zIndex:cs.DROPDOWN_IN_MODAL,children:ja.map(D=>e.jsx(Z,{value:D,children:D},D))})]})]}),b==="stdio"?e.jsxs(e.Fragment,{children:[e.jsxs(he,{children:[e.jsx(pe,{children:n("Command")}),e.jsx(J,{value:v,onChange:D=>k(D.target.value),placeholder:"npx",className:"font-mono text-xs"})]}),e.jsxs(he,{children:[e.jsx(pe,{children:n("Arguments (one per line)")}),e.jsx(Xe,{value:I,onChange:D=>M(D.target.value),rows:3,className:"font-mono text-xs"})]}),e.jsxs(he,{children:[e.jsx(pe,{children:n("Environment variables (KEY=VALUE, one per line)")}),e.jsx(Xe,{value:$,onChange:D=>E(D.target.value),rows:3,className:"font-mono text-xs"})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs(he,{children:[e.jsx(pe,{children:n("URL")}),e.jsx(J,{value:L,onChange:D=>T(D.target.value),placeholder:"https://...",className:"font-mono text-xs"})]}),e.jsxs(he,{children:[e.jsx(pe,{children:n("Headers (Name: value, one per line)")}),e.jsx(Xe,{value:C,onChange:D=>S(D.target.value),rows:2,placeholder:"Authorization: Bearer <token>",className:"font-mono text-xs"})]}),e.jsxs(he,{children:[e.jsx(pe,{children:n("OAuth client name (optional)")}),e.jsx(J,{value:f,onChange:D=>d(D.target.value),placeholder:n("For servers that only accept known OAuth clients")})]}),e.jsxs(he,{children:[e.jsx(pe,{children:n("OAuth authorization server metadata URL (optional)")}),e.jsx(J,{value:p,onChange:D=>j(D.target.value),placeholder:n("Use when the server advertises a wrong authorization server or none"),className:"font-mono text-xs"})]})]}),e.jsxs(he,{children:[e.jsx(pe,{children:n("Connection timeout (seconds)")}),e.jsx(J,{inputMode:"numeric",value:W,onChange:D=>q(D.target.value),placeholder:String(rh/1e3)})]}),e.jsxs(he,{children:[e.jsx(pe,{children:n("Tool call timeout (seconds)")}),e.jsx(J,{inputMode:"numeric",value:N,onChange:D=>z(D.target.value),placeholder:String(oh/1e3)})]})]}),F&&e.jsx("p",{className:"t-shake-in text-destructive text-xs",children:F},F)]}),e.jsxs(Ee,{children:[e.jsx(y,{variant:"outline",size:"sm",onClick:t,children:n("Cancel")}),e.jsx(y,{size:"sm",disabled:!P,onClick:Y,children:n("Save")})]})]})})}function mh({status:s}){const{t}=R();return s.state==="connecting"?e.jsx(se,{variant:"outline",className:"shrink-0 animate-pulse text-[11px] text-muted-foreground",children:t("Connecting")}):s.state==="ready"?e.jsx(se,{variant:"success",className:"shrink-0 text-[11px]",children:t("{{count}} tools",{count:s.toolCount??0})}):s.state==="unauthorized"?e.jsx(se,{variant:"warning",className:"shrink-0 text-[11px]",children:t("Not authorized")}):s.state==="idle"?e.jsx(se,{variant:"outline",className:"shrink-0 text-[11px] text-muted-foreground",children:t("Authorized, pending connection")}):e.jsx(se,{variant:"error",className:"shrink-0 text-[11px]",title:s.error,children:t("Connection failed")})}function xh(){const{t:s}=R(),t=g(S=>S.mcpServers),n=g(S=>S.updateMcpServer),a=g(S=>S.setMcpServersEnabled),r=g(S=>S.removeMcpServer),o=fs(S=>S.statuses),i=fs(S=>S.authorized),m=fs(S=>S.pending),u=fs(S=>S.authorize),x=fs(S=>S.revoke);l.useEffect(()=>fs.getState().bind(),[]);const[h,c]=l.useState(!1),[f,d]=l.useState(null),p=async S=>{await u(S),d(fs.getState().authorized[S]===!0?S:null)},[j,b]=l.useState(null),[A,v]=l.useState(""),k=t.filter(S=>co(A,[S.name,S.source,S.transport,S.url,S.command,...S.args??[]])),I=k.map(S=>S.id),M=uo(I),$=t.filter(S=>S.enabled).length,E=t.filter(S=>S.enabled).map(S=>S.id),L=It(E,S=>window.electronAPI.assets.mcpOccupancy(S)),T=t.filter(S=>S.enabled&&S.loadMode!=="deferred").map(S=>S.id),C=kt(T,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:[s("MCP Servers"),e.jsx(Ze,{}),t.length>0&&e.jsxs("span",{className:"ml-2 font-normal text-muted-foreground text-xs",children:[s("{{enabled}}/{{total}} enabled",{enabled:$,total:t.length}),e.jsx(St,{tokens:C})]})]}),e.jsx("p",{className:"text-muted-foreground text-sm",children:s("Model Context Protocol servers available to this app")})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsxs(y,{variant:"outline",size:"sm",onClick:()=>c(!0),children:[e.jsx(Nt,{className:"mr-1.5 h-4 w-4"}),s("Import from local apps")]}),e.jsxs(y,{variant:"outline",size:"sm",onClick:()=>b("new"),children:[e.jsx(Re,{className:"mr-1.5 h-4 w-4"}),s("Add MCP server")]})]})]}),t.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx(mo,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:s("No MCP servers yet")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:s("Import MCP servers from local apps or add one manually to get started")})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx(xo,{query:A,onQueryChange:v,placeholder:s("Filter MCP servers..."),allSelected:M.allSelected,someSelected:M.someSelected,onToggleSelectAll:M.toggleAll,onEnable:()=>a(M.selectedIds,!0),onDisable:()=>a(M.selectedIds,!1),selectDisabled:k.length===0,actionDisabled:M.selectedIds.length===0}),k.length===0?e.jsx("p",{className:"px-3 py-6 text-center text-muted-foreground text-xs",children:s("No results")}):e.jsx("div",{className:"space-y-1",children:k.map(S=>{const W=o[S.id]??o[S.name],q=m[S.id]===!0,N=S.transport!=="stdio"&&i[S.id]!==!0,z=S.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.${S.id}`,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(Le,{checked:M.isSelected(S.id),onCheckedChange:H=>M.toggleOne(S.id,H)}),e.jsx("span",{className:K("shrink-0 font-medium text-sm",!S.enabled&&"text-muted-foreground line-through"),children:S.name}),e.jsx(se,{variant:"outline",className:"shrink-0 text-[11px]",children:S.transport}),e.jsx(se,{variant:"secondary",className:"shrink-0 text-[11px]",children:S.source}),W&&e.jsx(mh,{status:W}),e.jsx("span",{className:"min-w-0 truncate font-mono text-muted-foreground text-xs",children:S.url??[S.command,...S.args??[]].join(" ")})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[(N||W?.state==="unauthorized")&&e.jsxs(y,{variant:"outline",size:"sm",className:"h-7",disabled:q,onClick:()=>{p(S.id)},children:[q?e.jsx(Me,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):e.jsx(yc,{className:"mr-1.5 h-3.5 w-3.5"}),s(q?"Authorizing":"Authorize")]}),i[S.id]===!0&&e.jsx(y,{variant:"ghost",size:"icon",title:s("Revoke authorization"),className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",onClick:()=>{x(S.id)},children:e.jsx(wc,{className:"h-3.5 w-3.5"})}),e.jsx(Ct,{row:L.rows[S.id],pending:S.enabled&&L.pending&&!L.rows[S.id]}),e.jsx(Qs,{value:z?"deferred":"direct",onValueChange:H=>n(S.id,{loadMode:H==="deferred"?"deferred":"direct"}),title:s("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(Zs,{"aria-label":s("Load mode"),children:[e.jsx(Je,{value:"direct",className:"h-6 px-2 text-xs sm:h-6 sm:text-xs",children:s("Always loaded")}),e.jsx(Je,{value:"deferred",className:"h-6 px-2 text-xs sm:h-6 sm:text-xs",children:s("On demand")})]})}),e.jsx(ce,{checked:S.enabled,onCheckedChange:H=>n(S.id,{enabled:H})}),e.jsx(y,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",onClick:()=>b(S),children:e.jsx(hs,{className:"h-3.5 w-3.5"})}),e.jsx(y,{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(S.id),children:e.jsx(Pe,{className:"h-3.5 w-3.5"})})]})]}),f===S.id&&e.jsx("p",{className:"px-3 text-muted-foreground text-xs",children:s("Authorized. Conversations that already include this server can use it on the next message.")})]},S.id)})})]}),e.jsx(zn,{kind:"mcp",open:h,onOpenChange:c}),e.jsx(uh,{server:j,onClose:()=>b(null)})]})}const Za={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 Yo(s){if(Za[s]!==void 0)return Za[s];let t=0;for(let n=0;n<s.length;n++)t=t*17+s.charCodeAt(n)>>>0;return t%360}const $t=22,hh=64;function ph(s,t){if(t<=1)return $t;const n=Math.sqrt(Math.max(1,s))/Math.sqrt(t);return Math.round($t+(hh-$t)*Math.min(1,n))}function fh(s,t,n){const a=Math.max(1,...s.map(o=>o.memoryCount)),r=new Set(s.map(o=>o.id));return[...s.map(o=>({data:{id:o.id,label:o.name,size:ph(o.memoryCount,a),color:Jo(Yo(o.entityType),n),entityType:o.entityType,memoryCount:o.memoryCount,spaceLabel:o.spaceLabel}})),...t.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 gh(s,t){const n=new Map;for(const a of s)n.set(a.entityType,(n.get(a.entityType)??0)+1);return[...n.entries()].map(([a,r])=>({entityType:a,count:r,color:Jo(Yo(a),t)})).sort((a,r)=>r.count-a.count||a.entityType.localeCompare(r.entityType))}function jh(s){const t=s?"#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:t,"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":s?"#4b4b52":"#c9c9d1","curve-style":"bezier",opacity:.65,"font-size":9,color:t,"text-opacity":0}},{selector:"edge:selected, edge.highlighted",style:{"text-opacity":.85,opacity:1}},{selector:"node:selected",style:{"border-width":3,"border-color":t,"background-opacity":1}},{selector:".dimmed",style:{opacity:.18,"text-opacity":.25}}]}function Jo(s,t){return vh(s,t?.62:.68,t?.58:.52)}function vh(s,t,n){const a=(1-Math.abs(2*n-1))*t,r=a*(1-Math.abs(s/60%2-1)),o=n-a/2,[i,m,u]=s<60?[a,r,0]:s<120?[r,a,0]:s<180?[0,a,r]:s<240?[0,r,a]:s<300?[r,0,a]:[a,0,r],x=h=>Math.round((h+o)*255).toString(16).padStart(2,"0");return`#${x(i)}${x(m)}${x(u)}`}let er=!1;function bh(){er||(Oo.use(gu),er=!0)}const sr={name:"fcose",animate:!1,randomize:!1,nodeRepulsion:8e3,idealEdgeLength:90,nodeSeparation:90,padding:24,fit:!0};function yh({graph:s,selectedId:t,onSelect:n,memories:a,loading:r,onInterpret:o,interpreting:i}){const{t:m}=R(),u=l.useRef(null),x=l.useRef(null),h=l.useRef(n);h.current=n;const[c,f]=l.useState(null),d=l.useMemo(()=>typeof document<"u"&&document.documentElement.classList.contains("dark"),[]);l.useEffect(()=>{const b=u.current;if(!b||s.nodes.length===0)return;bh();const A=Oo({container:b,elements:fh(s.nodes,s.edges,d),style:jh(d),minZoom:.2,maxZoom:2.5,wheelSensitivity:.2});return A.layout(sr).run(),A.on("tap","node",v=>h.current(v.target.id())),A.on("tap",v=>{v.target===A&&h.current(null)}),x.current=A,()=>{A.destroy(),x.current=null}},[s.nodes,s.edges,d]),l.useEffect(()=>{const b=x.current;b&&b.batch(()=>{if(b.elements().removeClass("dimmed").unselect(),!t)return;const A=b.getElementById(t);if(A.empty())return;const v=A.closedNeighborhood();b.elements().difference(v).addClass("dimmed"),A.select()})},[t]);const p=l.useMemo(()=>gh(s.nodes,d),[s.nodes,d]),j=s.nodes.find(b=>b.id===t)??null;return l.useEffect(()=>{const b=x.current;!b||t||b.batch(()=>{b.elements().removeClass("dimmed"),c&&b.nodes().filter(A=>A.data("entityType")!==c).addClass("dimmed")})},[c,t]),s.nodes.length===0?e.jsx("p",{className:"rounded-lg border px-3 py-6 text-muted-foreground text-sm",children:m(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(y,{size:"sm",variant:"outline",onClick:()=>x.current?.fit(void 0,24),title:m("Fit to view"),children:m("Fit")}),e.jsx(y,{size:"sm",variant:"outline",onClick:()=>x.current?.layout(sr).run(),title:m("Re-run layout"),children:m("Relayout")})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:m("Colour = entity type · size = how many memories mention it",{})}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:p.map(b=>e.jsxs("button",{type:"button",onClick:()=>f(c===b.entityType?null:b.entityType),className:K("inline-flex items-center gap-1.5 rounded-full border px-2 py-0.5 text-xs transition-colors",c===b.entityType?"border-foreground/40 bg-accent":"hover:bg-accent/50"),children:[e.jsx("span",{className:"size-2.5 shrink-0 rounded-full",style:{backgroundColor:b.color}}),e.jsx("span",{className:"text-muted-foreground",children:b.entityType.toLowerCase()}),e.jsx("span",{className:"tabular-nums",children:b.count})]},b.entityType))}),e.jsx("p",{className:"text-muted-foreground text-xs",children:m("{{shown}} of {{total}} entities",{shown:String(s.nodes.length),total:String(s.totalEntities)})})]}),j&&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:j.name}),e.jsx(se,{variant:"secondary",children:j.entityType})]}),e.jsx("p",{className:"text-muted-foreground text-xs",children:m("{{count}} memories · {{space}}",{count:String(j.memoryCount),space:j.spaceLabel})})]}),e.jsx(y,{size:"sm",variant:"outline",disabled:i,onClick:()=>o(j.id),children:m(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:m("Loading…")}),a.map(b=>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:[b.isCrystal&&e.jsx("span",{title:m("Crystal"),children:"★"}),e.jsx("span",{className:"truncate",children:b.title}),e.jsx(se,{variant:"secondary",children:b.unitType})]}),e.jsx("p",{className:"line-clamp-2 text-muted-foreground text-xs",children:b.contentSummary})]},b.id))]})]})]})}function wh({tree:s,loading:t,selected:n,onToggle:a,onInterpretGroup:r,interpreting:o}){const{t:i}=R(),[m,u]=l.useState(new Set);return s.length===0?e.jsx("p",{className:"rounded-lg border px-3 py-6 text-muted-foreground text-sm",children:i(t?"Loading…":"No memories yet.")}):e.jsx("ul",{className:"divide-y rounded-lg border",children:s.map(x=>{const h=m.has(x.id),c=(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(m);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(se,{variant:"secondary",children:x.count})]})}),e.jsx(y,{size:"sm",variant:"ghost",className:"shrink-0",disabled:o||c.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(Le,{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 Nh=120,kh=30,Ch={nodes:[],edges:[],totalEntities:0};function Sh({revision:s=0}={}){const{t}=R(),[n,a]=l.useState("graph"),[r,o]=l.useState("unitType"),[i,m]=l.useState(Ch),[u,x]=l.useState([]),[h,c]=l.useState(!0),[f,d]=l.useState(null),[p,j]=l.useState([]),[b,A]=l.useState(new Set),[v,k]=l.useState(null),[I,M]=l.useState(!1),[$,E]=l.useState(null),[L,T]=l.useState(!1),C=l.useCallback(()=>{c(!0);const B=()=>c(!1);n==="graph"?window.electronAPI.memory.graph({limit:Nh,minMemories:1}).then(m).finally(B):window.electronAPI.memory.tree({groupBy:r,limitPerGroup:kh}).then(x).finally(B)},[n,r]);l.useEffect(C,[C]);const S=l.useRef(C);S.current=C,l.useEffect(()=>window.electronAPI.memory.onChanged(()=>S.current()),[]);const W=l.useRef(s);l.useEffect(()=>{W.current!==s&&(W.current=s,C())},[s,C]),l.useEffect(()=>{if(!f){j([]);return}window.electronAPI.memory.graphEntity(f).then(j)},[f]);const q=async B=>{M(!0),k(null);try{k(await window.electronAPI.memory.insight(B))}finally{M(!1)}},N=async()=>{T(!0);try{const B=await window.electronAPI.memory.crystallize({memoryIds:[...b]});E(B),B.ok&&A(new Set)}finally{T(!1)}},z=[{value:"graph",label:t("Graph")},{value:"tree",label:t("Tree")}],H=[{value:"unitType",label:t("By type")},{value:"entity",label:t("By entity")},{value:"time",label:t("By month")}],U=b.size>=va;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:t("Knowledge")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("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(ne,{value:n,items:z,onValueChange:B=>a(B==="tree"?"tree":"graph"),children:[e.jsx(ae,{size:"sm",className:"w-32",children:e.jsx(re,{})}),e.jsx(oe,{children:z.map(B=>e.jsx(Z,{value:B.value,children:B.label},B.value))})]}),n==="tree"&&e.jsxs(ne,{value:r,items:H,onValueChange:B=>o(B),children:[e.jsx(ae,{size:"sm",className:"w-36",children:e.jsx(re,{})}),e.jsx(oe,{children:H.map(B=>e.jsx(Z,{value:B.value,children:B.label},B.value))})]}),e.jsx("span",{className:"flex-1"}),n==="tree"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:K("text-xs",U?"text-foreground":"text-muted-foreground"),children:t("{{count}} selected",{count:String(b.size)})}),e.jsx(y,{size:"sm",variant:"outline",disabled:!U||L,onClick:()=>{N()},children:L?t("Synthesizing…"):t("Crystallize ({{min}}+)",{min:String(va)})})]})]}),n==="graph"?e.jsx(yh,{graph:i,loading:h,selectedId:f,onSelect:d,memories:p,interpreting:I,onInterpret:B=>{q({entityId:B})}}):e.jsx(wh,{tree:u,loading:h,selected:b,interpreting:I,onToggle:B=>{const ie=new Set(b);ie.delete(B)||ie.add(B),A(ie)},onInterpretGroup:B=>{const ie=(B.children??[]).map(F=>F.memoryId).filter(F=>!!F);q({memoryIds:ie})}}),e.jsx(ye,{open:v!==null,onOpenChange:B=>!B&&k(null),children:e.jsxs(we,{children:[e.jsxs(Ne,{children:[e.jsx(ke,{children:t("Interpretation")}),v?.ok&&e.jsx(Ye,{children:t("Based on {{count}} memories",{count:String(v.sourceCount??0)})})]}),e.jsx(Ce,{children:v?.ok?e.jsx("p",{className:"whitespace-pre-wrap text-sm",children:v.text}):e.jsx("p",{className:"text-destructive text-sm",children:v?.error})}),e.jsx(Ee,{children:e.jsx(Hs,{render:e.jsx(y,{variant:"outline",size:"sm"}),children:t("Close")})})]})}),e.jsx(ye,{open:$!==null,onOpenChange:B=>!B&&E(null),children:e.jsxs(we,{children:[e.jsxs(Ne,{children:[e.jsx(ke,{children:$?.ok?t("Crystal created"):t("Nothing was written")}),$?.ok&&e.jsx(Ye,{children:$.title})]}),e.jsx(Ce,{className:"space-y-3",children:$?.ok?e.jsx("p",{className:"whitespace-pre-wrap text-sm",children:$.content}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-destructive text-sm",children:$?.error}),$?.candidates&&$.candidates.length>0&&e.jsx("ul",{className:"divide-y rounded-lg border",children:$.candidates.map(B=>e.jsxs("li",{className:"flex items-center justify-between gap-2 px-3 py-2",children:[e.jsx("span",{className:"truncate text-sm",children:B.title}),e.jsxs(se,{variant:"secondary",children:[(B.similarity*100).toFixed(0),"%"]})]},B.id))})]})}),e.jsx(Ee,{children:e.jsx(Hs,{render:e.jsx(y,{variant:"outline",size:"sm"}),children:t("Close")})})]})})]})}function hn(s){return s==="fast"||s==="deep"}const Ss=25,Fe="__all__";function Os(s){const t=new Date(s);if(Number.isNaN(t.getTime()))return s;const n=a=>String(a).padStart(2,"0");return`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())} ${n(t.getHours())}:${n(t.getMinutes())}`}const tr=["global","project","secretary","bot","chat"],Ih={global:"Global",project:"Projects",secretary:"Secretary",bot:"Members",chat:"Group chats"};function Ah(s,t,n){return t?{spaceId:t}:s?{spaceIds:n.filter(a=>a.kind===s).map(a=>a.id)}:{}}function Eh(s){return s.startsWith("bot:")?"bot":s.startsWith("chat:")?"chat":s.startsWith("proj:")?"project":"global"}function Mh(s,t){return s===!1&&!t}function Ph(s,t,n,a){return hn(s)&&!t.trim()?"needs-query":Mh(n,a)?"library-empty":"no-match"}function Th({items:s,onOpen:t,onEdit:n,onDelete:a,t:r,selected:o,onToggle:i,emptyLabel:m}){return e.jsxs("ul",{className:"divide-y overflow-hidden rounded-lg border",children:[s.length===0&&e.jsx("li",{className:"px-3 py-6 text-sm text-muted-foreground",children:m}),s.map(u=>e.jsxs("li",{className:K(Ac,"flex items-center gap-2 px-3 py-2"),"data-memory-id":u.id,children:[i&&e.jsx(Le,{checked:o?.has(u.id)??!1,onCheckedChange:()=>i(u.id),"aria-label":r("Select memory")}),e.jsxs("button",{type:"button",onClick:()=>t(u.id),className:"min-w-0 flex-1 space-y-0.5 text-left",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[u.isCrystal&&e.jsx("span",{title:r("Crystal"),children:"★"}),e.jsx("span",{className:"truncate text-sm",children:u.title}),e.jsx(se,{variant:"secondary",children:u.unitType}),e.jsx(Oh,{importance:u.importance,t:r}),u.lifecycleState==="archived"&&e.jsx(se,{variant:"outline",children:r("Archived")}),u.archiveCandidateAt&&e.jsx(se,{variant:"warning",title:r("Marked by the forgetting pass: cold and low importance"),children:r("Archive candidate")})]}),e.jsx("span",{className:"line-clamp-2 text-muted-foreground text-xs",children:u.contentSummary}),e.jsxs("span",{className:"block text-muted-foreground text-xs",children:[r("Recorded {{date}}",{date:Os(u.createdAt)})," · ",u.spaceLabel," ","· ",r("Retrieved {{count}} times",{count:String(u.appearances)})]})]}),n&&a&&e.jsx(Ic,{id:u.id,onEdit:n,onDelete:a})]},u.id))]})}const Rh={critical:{variant:"warning",label:"critical"},important:{variant:"info",label:"important"},useful:{variant:"outline",label:"useful"},low:{variant:"outline",label:"low"}};function Oh({importance:s,t}){const n=Pc(s),a=Rh[n];return e.jsx(se,{variant:a.variant,className:n==="low"?"text-muted-foreground":void 0,title:t("Importance {{value}}",{value:s.toFixed(2)}),children:t(a.label)})}const Dh=6,Lh=50;function zh(s){const t=[...s].sort((a,r)=>r.edge.createdAt.localeCompare(a.edge.createdAt)||a.edge.id.localeCompare(r.edge.id));if(t.length<=Dh)return[{key:"",label:"",items:t}];const n=new Map;for(const a of t){const r=a.older.spaceId,o=n.get(r)??{key:r,label:a.older.spaceLabel,items:[]};o.items.push(a),n.set(r,o)}return[...n.values()].sort((a,r)=>a.label.localeCompare(r.label))}function nr({label:s,memory:t,onOpen:n}){return e.jsxs("button",{type:"button",onClick:()=>n(t.id),className:"block w-full space-y-0.5 rounded-md px-1 py-0.5 text-left hover:bg-accent/40","data-memory-review-side":t.id,children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"shrink-0 text-muted-foreground text-xs",children:s}),e.jsx("span",{className:"truncate text-sm",children:t.title})]}),e.jsx("span",{className:"line-clamp-2 text-muted-foreground text-xs",children:t.contentSummary})]})}function _h({items:s,selected:t,onToggle:n,onToggleAll:a,onReview:r,onOpen:o,t:i}){if(s.length===0)return e.jsxs("section",{className:"space-y-2","data-settings-row":"memory.review",children:[e.jsx("h3",{className:"text-sm font-medium",children:i("Needs review")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:i("Nothing to review. When a new memory contradicts an existing one, the pair shows up here.")})]});const m=s.every(u=>t.has(u.edge.id));return e.jsxs("section",{className:"space-y-2","data-settings-row":"memory.review",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("h3",{className:"text-sm font-medium",children:i("Needs review")}),e.jsxs("label",{className:"flex items-center gap-2 text-muted-foreground text-xs",children:[e.jsx(Le,{checked:m,onCheckedChange:()=>a(!m),"aria-label":i("Select all")}),i("{{count}} pending",{count:String(s.length)})]})]}),e.jsxs("div",{className:"space-y-0.5 text-muted-foreground text-xs",children:[e.jsx("p",{children:i("Reviewing only records your judgement. Nothing is deleted and no memory is superseded.")}),e.jsx("p",{children:i("Accept: recorded as a confirmed contradiction. Both memories stay and stay searchable — you just stop being asked.")}),e.jsx("p",{children:i("Dismiss: recorded as not a contradiction. Both memories stay unchanged and you stop being asked.")})]}),s.length>Lh&&e.jsx("p",{className:"text-warning text-xs","data-memory-review-alert":!0,children:i("{{count}} contradictions are waiting for review. Clear them in bulk so real conflicts do not get buried.",{count:String(s.length)})}),t.size>0&&e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 rounded-lg border bg-accent/30 px-3 py-2",children:[e.jsx("span",{className:"text-sm",children:i("{{count}} selected",{count:String(t.size)})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(y,{variant:"ghost",size:"sm",onClick:()=>a(!1),children:i("Clear selection")}),e.jsx(y,{variant:"outline",size:"sm",onClick:()=>r([...t],"accepted"),children:i("Accept selected")}),e.jsx(y,{variant:"ghost",size:"sm",onClick:()=>r([...t],"rejected"),children:i("Dismiss selected")})]})]}),zh(s).map(u=>e.jsxs("div",{className:"space-y-2",children:[u.label&&e.jsxs("h4",{className:"text-muted-foreground text-xs",children:[u.label," · ",i("{{count}} pending",{count:String(u.items.length)})]}),u.items.map(({edge:x,older:h,newer:c})=>e.jsxs("div",{className:"space-y-1.5 rounded-lg border px-3 py-2","data-memory-review":x.id,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(Le,{checked:t.has(x.id),onCheckedChange:()=>n(x.id),"aria-label":i("Select memory")}),e.jsx(se,{variant:"outline",children:x.relation}),e.jsxs("span",{className:"text-muted-foreground text-xs",children:[h.spaceLabel," · ",Os(x.createdAt)]})]}),e.jsx(nr,{label:i("Earlier memory"),memory:h,onOpen:o}),e.jsx(nr,{label:i("Newer memory"),memory:c,onOpen:o}),e.jsx("p",{className:"text-muted-foreground text-xs",children:x.reason?`${i("Why they conflict")}: ${x.reason}`:i("No reason recorded for this pair.")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(y,{size:"sm",variant:"outline",onClick:()=>r([x.id],"accepted"),children:i("Accept")}),e.jsx(y,{size:"sm",variant:"ghost",onClick:()=>r([x.id],"rejected"),children:i("Dismiss")})]})]},x.id))]},u.key))]})}function Fh({writes:s,onReview:t,t:n}){return s.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.")}),s.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(y,{size:"sm",variant:"outline",onClick:()=>t(a.id,"approve"),children:n("Approve")}),e.jsx(y,{size:"sm",variant:"ghost",onClick:()=>t(a.id,"reject"),children:n("Reject")})]})]},a.id))]})}function Bh({t:s}){const t=Ec(),n=Mc(a=>a.review);return e.jsx(Fh,{writes:t,t:s,onReview:(a,r)=>{n(a,r)}})}function Uh({revision:s=0}={}){const{t}=R(),[n,a]=l.useState(""),[r,o]=l.useState(Fe),[i,m]=l.useState(Fe),[u,x]=l.useState(Fe),[h,c]=l.useState(!1),[f,d]=l.useState(!1),[p,j]=l.useState(0),[b,A]=l.useState("exact"),[v,k]=l.useState(!1),[I,M]=l.useState(!0),[$,E]=l.useState([]),[L,T]=l.useState(0),[C,S]=l.useState([]),W=l.useRef(C);W.current=C;const[q,N]=l.useState(null),[z,H]=l.useState(null),[U,B]=l.useState(null),[ie,F]=l.useState(null),[X,V]=l.useState(new Set),[le,_]=l.useState(!1),[de,ue]=l.useState([]),[O,De]=l.useState(new Set),te=l.useRef(!1),P=l.useRef(0),Y=l.useRef(0);l.useEffect(()=>(te.current=!0,()=>{te.current=!1,P.current++,Y.current++}),[]);const D=l.useCallback(()=>{if(!te.current)return;const G=++P.current,je=()=>te.current&&G===P.current;if(hn(b)&&!n.trim()){E([]),T(0),k(!0),M(!0);return}const be=tr.find(Ae=>Ae===r)??null;window.electronAPI.memory.list({query:n.trim()||void 0,...Ah(be,i===Fe?null:i,W.current),unitType:u===Fe?void 0:u,includeArchived:h,archiveCandidate:f||void 0,limit:Ss,offset:p,mode:b}).then(Ae=>{je()&&(E(Ae.items),T(Ae.total),k(Ae.approximate===!0),M(Ae.vectorsUsed!==!1))}),window.electronAPI.memory.stats().then(Ae=>{te.current&&(S(Object.keys(Ae.bySpace).map(qe=>({id:qe,label:Ae.spaceLabels[qe]??qe,kind:Ae.spaceKinds?.[qe]??Eh(qe)}))),N(Ae.total>0))}),window.electronAPI.memory.evolvesPending().then(Ae=>{te.current&&ue(Ae)})},[n,r,i,u,h,f,p,b]);l.useEffect(()=>(D(),()=>{P.current++}),[D]);const Q=l.useRef(D);Q.current=D,l.useEffect(()=>window.electronAPI.memory.onChanged(()=>Q.current()),[]);const ee=l.useRef(s);l.useEffect(()=>{ee.current!==s&&(ee.current=s,D())},[s,D]);const fe=G=>{const je=++Y.current;window.electronAPI.memory.detail(G).then(be=>{te.current&&je===Y.current&&H(be)})},xe=()=>{Y.current++,H(null)},Ls=async(G,je)=>{_(!0);try{for(const be of G)await je(be)}finally{te.current&&(_(!1),V(new Set),Q.current())}},ds=()=>{Ls(X,G=>window.electronAPI.memory.archive(G))},vs=(G,je)=>{G.length!==0&&(_(!0),(async()=>{try{for(const be of G)await window.electronAPI.memory.evolvesReview(be,je)}finally{te.current&&(_(!1),De(new Set),Q.current())}})())},He=G=>{te.current&&(V(new Set),z&&G.includes(z.id)&&xe(),Q.current())},zs=G=>{te.current&&(U?.reopen&&fe(G),Q.current())},ge=G=>{G.then(()=>{te.current&&(xe(),Q.current())})},as=n.trim()!==""||r!==Fe||i!==Fe||u!==Fe||h===!0,rs=[{value:Fe,label:t("All space types")},...tr.filter(G=>C.some(je=>je.kind===G)).map(G=>({value:G,label:t(Ih[G])}))],_s=[{value:Fe,label:t("All spaces")},...C.filter(G=>r===Fe||G.kind===r).map(G=>({value:G.id,label:G.label}))],os=[{value:Fe,label:t("All types")},...Nc.map(G=>({value:G,label:G}))],Fs=[{value:"exact",label:t("Exact match")},{value:"fast",label:t("Fast retrieval")},{value:"deep",label:t("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:t("Stored memories")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("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(ho,{className:"w-full sm:w-96","data-size":"sm",children:[e.jsx(po,{value:n,placeholder:t("Search memories"),onChange:G=>{j(0),a(G.target.value)}}),e.jsx(fo,{align:"inline-end",className:"pe-1",children:e.jsxs(ne,{value:b,items:Fs,onValueChange:G=>{j(0),A(G==="deep"?"deep":G==="fast"?"fast":"exact")},children:[e.jsx(ae,{size:"sm",className:"w-auto min-w-0 gap-1 border-0 bg-transparent px-2 shadow-none before:hidden",children:e.jsx(re,{})}),e.jsx(oe,{children:Fs.map(G=>e.jsx(Z,{value:G.value,children:G.label},G.value))})]})})]}),e.jsxs(ne,{value:r,items:rs,onValueChange:G=>{j(0),o(String(G)),m(Fe)},children:[e.jsx(ae,{size:"sm",className:"w-36","data-memory-filter":"space-kind",children:e.jsx(re,{})}),e.jsx(oe,{children:rs.map(G=>e.jsx(Z,{value:G.value,children:G.label},G.value))})]}),e.jsxs(ne,{value:i,items:_s,onValueChange:G=>{j(0),m(String(G))},children:[e.jsx(ae,{size:"sm",className:"w-36","data-memory-filter":"space",children:e.jsx(re,{})}),e.jsx(oe,{children:_s.map(G=>e.jsx(Z,{value:G.value,children:G.label},G.value))})]}),e.jsxs(ne,{value:u,items:os,onValueChange:G=>{j(0),x(String(G))},children:[e.jsx(ae,{size:"sm",className:"w-36",children:e.jsx(re,{})}),e.jsx(oe,{children:os.map(G=>e.jsx(Z,{value:G.value,children:G.label},G.value))})]}),b==="exact"&&e.jsxs("label",{className:"flex items-center gap-2 text-muted-foreground text-sm",children:[e.jsx(ce,{checked:h,onCheckedChange:G=>{j(0),c(G===!0)}}),t("Show archived")]}),b==="exact"&&e.jsxs("label",{className:"flex items-center gap-2 text-muted-foreground text-sm",children:[e.jsx(ce,{checked:f,onCheckedChange:G=>{j(0),d(G===!0)}}),t("Archive candidates only")]})]}),hn(b)&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:[t(b==="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."),!I&&` ${t("Embedding model is not ready, so vectors are skipped.")}`]}),X.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:t("{{count}} selected",{count:String(X.size)})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(y,{variant:"ghost",size:"sm",disabled:le,onClick:()=>V(new Set),children:t("Clear selection")}),e.jsx(y,{variant:"outline",size:"sm",disabled:le,onClick:()=>ds(),children:t("Archive selected")}),e.jsx(y,{variant:"destructive-outline",size:"sm",disabled:le,onClick:()=>F([...X]),children:t("Delete permanently")})]})]}),e.jsx(Th,{items:$,onOpen:fe,onEdit:G=>B({id:G,reopen:!1}),onDelete:G=>F([G]),t,selected:X,emptyLabel:{"needs-query":t("Type a query to search by meaning."),"library-empty":t("No memories yet. They appear here once the agent stores something."),"no-match":t("No memories match these filters.")}[Ph(b,n,q,as)],onToggle:G=>{const je=new Set(X);je.delete(G)||je.add(G),V(je)}}),!v&&L>Ss&&e.jsxs("div",{className:"flex items-center justify-between text-xs text-muted-foreground",children:[e.jsx(y,{variant:"outline",size:"sm",disabled:p===0,onClick:()=>j(Math.max(0,p-Ss)),children:t("Previous")}),e.jsxs("span",{children:[p+1,"–",Math.min(p+Ss,L)," / ",L]}),e.jsx(y,{variant:"outline",size:"sm",disabled:p+Ss>=L,onClick:()=>j(p+Ss),children:t("Next")})]}),e.jsx(Bh,{t}),e.jsx(_h,{items:de,selected:O,onToggle:G=>{const je=new Set(O);je.delete(G)||je.add(G),De(je)},onToggleAll:G=>De(G?new Set(de.map(je=>je.edge.id)):new Set),onOpen:fe,onReview:vs,t}),e.jsx(ye,{open:z!==null,onOpenChange:G=>!G&&xe(),children:e.jsx(we,{finalFocus:kc,children:z&&e.jsxs(e.Fragment,{children:[e.jsxs(Ne,{children:[e.jsx(ke,{children:z.title}),e.jsx(Ye,{children:[z.unitType,z.spaceLabel].join(" · ")})]}),e.jsxs(Ce,{className:"space-y-4","data-memory-detail":z.id,children:[e.jsx("p",{className:"whitespace-pre-wrap text-sm","data-memory-field":"content",children:z.content}),e.jsxs("dl",{className:"grid grid-cols-2 gap-x-4 gap-y-3",children:[e.jsx($s,{label:t("Importance"),value:z.importance.toFixed(2)}),e.jsx($s,{label:t("Recorded at"),value:Os(z.createdAt)}),z.updatedAt!==z.createdAt&&e.jsx($s,{label:t("Updated at"),value:Os(z.updatedAt)}),e.jsx($s,{label:t("Embedding"),value:z.embeddingModel??t("Not vectorized")}),z.eventStart&&e.jsx($s,{label:t("Event date"),value:`${z.eventStart}${z.eventEnd?` → ${z.eventEnd}`:""}`})]}),z.entityNames.length>0&&e.jsxs("section",{className:"space-y-1.5",children:[e.jsx("p",{className:"font-medium text-xs",children:t("Entities")}),e.jsx("div",{className:"flex flex-wrap gap-1",children:z.entityNames.map(G=>e.jsx(se,{variant:"secondary",children:G},G))})]}),z.crystalSources.length>0&&e.jsxs("section",{className:"space-y-1.5",children:[e.jsx("p",{className:"font-medium text-xs",children:t("Synthesized from")}),e.jsx("ul",{className:"divide-y rounded-lg border",children:z.crystalSources.map(G=>e.jsxs("li",{className:"flex items-center justify-between gap-2 px-3 py-2",children:[e.jsx("span",{className:"truncate text-sm",children:G.title}),e.jsxs("span",{className:"shrink-0 text-muted-foreground text-xs",children:[(G.contributionWeight*100).toFixed(0),"%"]})]},G.id))})]}),z.evolves.length>0&&e.jsxs("section",{className:"space-y-1.5",children:[e.jsx("p",{className:"font-medium text-xs",children:t("Related versions")}),e.jsx("ul",{className:"divide-y rounded-lg border",children:z.evolves.map(G=>e.jsxs("li",{className:"flex items-center gap-2 px-3 py-2",children:[e.jsx(se,{variant:"outline",children:G.relation}),e.jsx("span",{className:"text-muted-foreground text-xs",children:G.reviewState})]},G.id))})]})]}),e.jsxs(Ee,{children:[e.jsx(y,{variant:"destructive-outline",size:"sm",className:"sm:me-auto","data-memory-action":"delete",onClick:()=>F([z.id]),children:t("Delete permanently")}),e.jsx(y,{variant:"outline",size:"sm","data-memory-action":"edit",onClick:()=>{xe(),B({id:z.id,reopen:!0})},children:t("Edit")}),z.lifecycleState==="archived"?e.jsx(y,{variant:"outline",size:"sm",onClick:()=>ge(window.electronAPI.memory.restore(z.id)),children:t("Restore")}):e.jsx(y,{variant:"outline",size:"sm",onClick:()=>ge(window.electronAPI.memory.archive(z.id)),children:t("Archive")})]})]})})}),e.jsx(Cc,{memoryId:U?.id??null,onClose:()=>B(null),onSaved:zs}),e.jsx(Sc,{ids:ie,onClose:()=>F(null),onDeleted:He})]})}function $s({label:s,value:t}){return e.jsxs("div",{className:"min-w-0",children:[e.jsx("dt",{className:"text-muted-foreground text-xs",children:s}),e.jsx("dd",{className:"truncate text-sm",children:t})]})}const Xo="openai-compatible",$h=/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 Qo(s){return $h.test(s)}function Un(s){return Array.isArray(s.models)?s.models.filter(t=>typeof t?.id=="string"&&Qo(t.id)):[]}function Vh(s){return s.flatMap(t=>{if(!t.apiKey||typeof t.baseUrl!="string"||!t.baseUrl.trim())return[];const n=Un(t);return n.length>0?[{...t,models:n}]:[]})}function Gh(s){const t=[];for(const n of s){const a=!!n.apiKey,r=typeof n.baseUrl=="string"&&!!n.baseUrl.trim();if(!a&&!r)continue;let o=null;a?r?Un(n).length===0&&(o="no-embedding-models"):o="no-base-url":o="no-api-key",o&&t.push({providerId:n.id,name:n.name,reason:o})}return t}const Kh={"no-api-key":"{{name}}: missing API key","no-base-url":"{{name}}: missing Base URL","no-embedding-models":"{{name}}: no matching embedding model (model names must contain keywords like embed/voyage/bge)"};function Wh(s,t,n){return n(Kh[s],{name:t})}function Hh(s){const{providerId:t,provider:n,modelId:a}=s;return t?n?n.apiKey?typeof n.baseUrl!="string"||!n.baseUrl.trim()?"no-base-url":!a||a===Xo?"no-model":Qo(a)?null:Un(n).length>0?"not-embedding-model":"no-embedding-models":"no-api-key":"provider-missing":"no-provider"}const qh={"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.'},Yh="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 Jh(s,t,n){return n(qh[s],{provider:t.provider??"",model:t.model??""})}const ar=s=>s.slice(0,8);function Vt(s,t){return s==="pending"||s==="running"?"running":s==="cancelled"?"cancelled":t?"failed":"done"}const Xh={low_importance:"importance too low",candidates_found:"similar memory already exists",deduplicated:"identical to an existing memory",rejected:"rejected"};function Qh(s){const t=[];for(const r of s.distill){const o=Vt(r.status,r.error);t.push({key:`distill:${r.id}`,kind:"distill",target:r.sessionTitle||ar(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,Xh[i.kind]??i.kind].filter(Boolean).join(" — ")),updatedAt:r.updatedAt})}for(const r of s.kg){const o=Vt(r.status,r.error);t.push({key:`kg:${r.id}`,kind:"kg",target:r.memoryTitle||ar(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=s.reembed;if(n){const r=Vt(n.status,n.error);t.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 t.sort((r,o)=>a(r)-a(o)||o.updatedAt.localeCompare(r.updatedAt))}const qs=`remote:${Xo}`,bt="remote:";function rr(s){return s.id==="none"?"None (full-text only)":s.id.replace(/^(local|remote):/,"")}function At(s){return s.startsWith(bt)&&s.length>bt.length}function Zh(s){return At(s)?qs:s}function ep(s){return!At(s)||s===qs?null:s.slice(bt.length)}function sp(s){return`${bt}${s}`}function tp(s,t){return t===qs?At(s)?s:qs:t}const np=4e3,ap=800,or=6,rp={distill:"job:distill",kg:"job:entities",reembed:"job:vectors"},ir={distill:[],kg:[],reembed:null,kgFailed:0};function op(s){return s.some(t=>t.distilled)}function lr(s){return!s||s.total===0||s.embedded>=s.total?null:s.embeddingError??null}function cr(s){return s?.downloadable&&(s.state==="missing"||s.state==="downloading")?s.state:null}function ip(s,t){if(s.done===0||s.done>=s.total)return null;const n=(t-s.startedAt)/s.done;return Math.round(n*(s.total-s.done))}function lp(s){const t=Math.max(1,Math.round(s/1e3));if(t<60)return`${t}s`;const n=Math.floor(t/60);return t%60===0?`${n}m`:`${n}m ${t%60}s`}function cp(s){const t=new Map;for(const a of s){const r=a.projectId??"",o=t.get(r);if(o){o.sessions.push(a);continue}t.set(r,{key:r,name:a.projectName??"No project",sessions:[a]})}const n=[...t.values()];return[...n.filter(a=>a.key),...n.filter(a=>!a.key)]}function me(s){if(s<=0)return"0 B";const t=["B","KB","MB","GB"],n=Math.min(Math.floor(Math.log(s)/Math.log(1024)),t.length-1);return`${(s/1024**n).toFixed(n===0?0:1)} ${t[n]}`}function Gt(s,t,n){return(s.includes(t)?[...s]:[...s,t].sort((r,o)=>r-o)).map(r=>({value:String(r),label:n(r)}))}function Is({title:s,description:t,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:s}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t})]}),e.jsx(ce,{checked:n,disabled:o,onCheckedChange:i=>a(i===!0)})]})}function Kt({title:s,description:t,value:n,items:a,onChange:r,rowId:o,disabled:i}){return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5","data-settings-row":o,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:t})]}),e.jsxs(ne,{value:n,items:a,onValueChange:m=>r(String(m)),disabled:i,children:[e.jsx(ae,{className:"w-40 shrink-0",children:e.jsx(re,{})}),e.jsx(oe,{children:a.map(m=>e.jsx(Z,{value:m.value,children:m.label},m.value))})]})]})}function dp({onLibraryChanged:s}={}){const{t}=R(),n=g(w=>w.disabledBuiltinTools),a=g(w=>w.memoryEmbeddingModel),r=g(w=>w.setMemoryEmbeddingModel),o=g(w=>w.memoryEmbeddingAutoDownload),i=g(w=>w.setMemoryEmbeddingAutoDownload),m=g(w=>w.memoryModelIdleMinutes),u=g(w=>w.setMemoryModelIdleMinutes),x=g(w=>w.memoryEmbeddingRemoteProviderId),h=g(w=>w.setMemoryEmbeddingRemoteProviderId),c=g(w=>w.providers),f=g(w=>w.memoryDistillEnabled),d=g(w=>w.setMemoryDistillEnabled),p=g(w=>w.memoryKgEnabled),j=g(w=>w.setMemoryKgEnabled),b=g(w=>w.memoryDecayEnabled),A=g(w=>w.setMemoryDecayEnabled),v=g(w=>w.memoryDecayArchiveCandidates),k=g(w=>w.setMemoryDecayArchiveCandidates),I=g(w=>w.memoryDecayAutoArchive),M=g(w=>w.setMemoryDecayAutoArchive),$=g(w=>w.memoryDecayStaleDays),E=g(w=>w.setMemoryDecayStaleDays),L=g(w=>w.memoryDecayMaxImportance),T=g(w=>w.setMemoryDecayMaxImportance),C=g(w=>w.memoryDecayIntervalDays),S=g(w=>w.setMemoryDecayIntervalDays),W=g(w=>w.memoryDistillModel),q=g(w=>w.setMemoryDistillModel),N=g(w=>w.memoryChatModel)||"remote",z=g(w=>w.setMemoryChatModel),H=g(w=>w.memoryLanguage),U=g(w=>w.setMemoryLanguage),B=es(),ie=W?B.find(w=>w.id===W.providerId):void 0,F=ie?.models.find(w=>w.id===W?.modelId),X=ep(a),V=l.useMemo(()=>Vh(B),[B]),le=l.useMemo(()=>Gh(B),[B]),_=x?V.find(w=>w.id===x):void 0,de=_?.models.find(w=>w.id===X),ue=x?c.find(w=>w.id===x):void 0,O=Hh({providerId:x,provider:ue,modelId:X}),De=O&&O!=="no-provider"&&O!=="no-model"?Jh(O,{provider:ue?.name||x||"",model:X??""},t):null,te=!n.includes("memory"),[P,Y]=l.useState(null),[D,Q]=l.useState(ir),[ee,fe]=l.useState([]),[xe,Ls]=l.useState(null),[ds,vs]=l.useState([]),[He,zs]=l.useState(null),[ge,as]=l.useState([]),[rs,_s]=l.useState(null),[os,Fs]=l.useState(null),[G,je]=l.useState(null),[be,Ae]=l.useState(null),[qe,Vn]=l.useState(!1),[Et,pi]=l.useState(!1),[Be,Gn]=l.useState(null),[bs,Mt]=l.useState(new Set),[st,tt]=l.useState(null),Pt=P?.forgetting??null,Bs=Pt?.lastRun??null,fi=Bs?t("Last run {{date}}: {{scored}} scored, {{candidates}} candidates, {{archived}} archived",{date:Os(Bs.ranAt),scored:String(Bs.scored),candidates:String(Bs.candidates),archived:String(Bs.archived)}):t("Never run yet"),Kn=l.useRef(!1);Kn.current=qe;const ys=l.useRef(null),Tt=l.useCallback(()=>{window.electronAPI.memory.distillableSessions().then(as)},[]);l.useEffect(()=>{te&&Tt()},[te,Tt]);const ws=l.useCallback(()=>{window.electronAPI.memory.models().then(fe)},[]);l.useEffect(()=>(ws(),window.electronAPI.memory.onModelProgress(w=>{Ls(w.done?null:w),w.done&&ws()})),[ws]);const Ns=l.useCallback(()=>{window.electronAPI.memory.chatModels().then(w=>vs(w.filter(ve=>!ve.purpose)))},[]);l.useEffect(()=>(Ns(),window.electronAPI.memory.onChatModelProgress(w=>{zs(w.done?null:w),w.done&&Ns()})),[Ns]),l.useEffect(()=>{if(!te){Y(null),Q(ir);return}let w=!1;const ve=()=>{window.electronAPI.memory.stats().then(is=>{w||Y(is)}),window.electronAPI.memory.jobs().then(is=>{w||(Q(is),Kn.current&&is.reembed?.status!=="running"&&Vn(!1))})};ys.current=ve,ve();const Ue=window.electronAPI.memory.onChanged(ve),Us=window.setInterval(ve,qe?ap:np);return()=>{w=!0,ys.current=null,Ue(),window.clearInterval(Us)}},[te,qe]);const Wn=cp(ge),Hn=ge.filter(w=>!w.distilled),gi=()=>{tt("run"),window.electronAPI.memory.runForgetting().then(()=>{tt(null),ys.current?.()})},qn=()=>{window.electronAPI.memory.archiveCandidates({limit:200,offset:0}).then(w=>{Gn(w),Mt(new Set)})},ji=()=>{const w=[...bs];w.length!==0&&(tt("archive"),window.electronAPI.memory.confirmArchiveCandidates(w).then(()=>{tt(null),qn(),ys.current?.(),s?.()}))},Yn=(w,ve,Ue)=>{const Us=w.filter(is=>!is.distilled);if(!op(w)){nt(w,ve);return}Ae({token:ve,label:Ue,scope:w,pending:Us})},nt=async(w,ve,Ue=!1)=>{const Us=ds.find(Cs=>Cs.id===N)??null;if(cr(Us))return;_s(ve);const is=Date.now();je({done:0,total:w.length,startedAt:is});try{for(let Cs=0;Cs<w.length;Cs++)await window.electronAPI.memory.distillSession(w[Cs].sessionId,Ue),je({done:Cs+1,total:w.length,startedAt:is})}finally{_s(null),je(null),Tt(),s?.()}},Se=ee.find(w=>w.id===a)??null,_e=ds.find(w=>w.id===N)??null,ps=cr(_e),Jn=ds.map(w=>({value:w.id,label:w.id==="remote"?t("Remote (API model)"):w.label})),Xn=[...ee.map(w=>({value:w.id,label:rr(w)})),{value:qs,label:t("Remote (OpenAI-compatible)")}],Qn=Tc.map(w=>({value:String(w),label:w===0?t("Never"):t("{{count}} min",{count:w})})),Zn=[{value:"en",label:t("English")},{value:"zh",label:t("Simplified Chinese")},{value:"auto",label:t("Follow conversation")}],at=At(a)||Se?.runtime==="openai-compatible",ks=l.useMemo(()=>Qh(D),[D]);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:t("Memory")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("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:t("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:t("Unload automatically when idle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Release local model memory after this idle period. Models load automatically the next time they are needed.")})]}),e.jsxs(ne,{value:String(m),items:Qn,onValueChange:w=>{w!==null&&u(Number(w))},disabled:!te,children:[e.jsx(ae,{className:"w-56 shrink-0","aria-label":t("Unload automatically when idle"),children:e.jsx(re,{})}),e.jsx(oe,{children:Qn.map(w=>e.jsx(Z,{value:w.value,children:w.label},w.value))})]})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium",children:t("Embedding model")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("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:Se?rr(Se):X??(at?t("Remote (OpenAI-compatible)"):a)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:Se?[Se.dim?`${Se.dim}d`:null,Se.downloadable?me(Se.approxBytes):null,Se.runtime].filter(Boolean).join(" · "):at?"openai-compatible":t("Unknown model; the default is used instead.")})]}),e.jsxs(ne,{value:Zh(a),items:Xn,onValueChange:w=>{w!==null&&r(tp(a,String(w)))},disabled:!te,children:[e.jsx(ae,{className:"w-56",children:e.jsx(re,{})}),e.jsx(oe,{children:Xn.map(w=>e.jsx(Z,{value:w.value,children:w.label},w.value))})]})]}),Se?.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:Se.state==="ready"?t("Model downloaded"):Se.state==="downloading"?t("Downloading…"):t("Model not downloaded")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:xe&&xe.modelId===Se.id?`${xe.file} · ${me(xe.received)}${xe.total?` / ${me(xe.total)}`:""} (${xe.fileIndex+1}/${xe.fileCount})`:Se.state==="ready"?me(Se.downloadedBytes):t("Semantic search stays off until the model is on disk.")})]}),e.jsx("div",{className:"flex shrink-0 gap-2",children:Se.state==="downloading"?e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.memory.cancelModelDownload(Se.id).then(ws)},children:t("Cancel")}):Se.state==="ready"?e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.memory.deleteModel(Se.id).then(ws)},children:t("Remove")}):e.jsx(y,{size:"sm",disabled:!te,onClick:()=>{window.electronAPI.memory.downloadModel(Se.id).then(ws)},children:t("Download")})})]}),at&&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:t("Remote model")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Credentials stay in the main process and are never sent to the renderer.")})]}),V.length>0?e.jsx("div",{className:"w-56 shrink-0",children:e.jsx(ze,{providers:V,providerId:_?.id??x??"",modelId:de?.id??X??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:t("Select model"),side:"bottom",triggerClassName:Qe,onSelect:(w,ve)=>{h(w),r(sp(ve))},onReasoningChange:()=>{},onThinkingChange:()=>{}})}):e.jsxs("div",{className:"w-56 shrink-0 space-y-1",children:[e.jsx("p",{className:"text-xs text-destructive",children:t(Yh)}),le.map(w=>e.jsx("p",{className:"text-xs text-muted-foreground",children:Wh(w.reason,w.name,t)},w.providerId))]})]}),at&&De&&e.jsx("p",{className:"text-xs text-destructive","data-settings-row":"memory.remoteModelIssue",children:De}),e.jsx(Is,{rowId:"memory.autoDownload",title:t("Download models automatically"),description:t("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:!te})]}),e.jsxs("section",{className:"space-y-2","data-settings-row":"memory.distillModel",children:[e.jsx("h3",{className:"text-sm font-medium",children:t("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:t("Completion backend")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Local GGUF runs on this machine. Remote uses the model below.")})]}),e.jsxs(ne,{value:N,items:Jn,onValueChange:w=>z(String(w)),disabled:!te,children:[e.jsx(ae,{className:"w-56",children:e.jsx(re,{})}),e.jsx(oe,{children:Jn.map(w=>e.jsx(Z,{value:w.value,children:w.label},w.value))})]})]}),_e?.downloadable&&e.jsxs("div",{className:K("flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5",ps==="missing"&&"border-destructive/50"),children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:_e.state==="ready"?t("Model downloaded"):_e.state==="downloading"?t("Downloading…"):t("Model not downloaded")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:He&&He.modelId===_e.id?`${He.file} · ${me(He.received)}${He.total?` / ${me(He.total)}`:""}`:_e.state==="ready"?me(_e.downloadedBytes):me(_e.approxBytes)})]}),e.jsx("div",{className:"flex shrink-0 gap-2",children:_e.state==="downloading"?e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.memory.cancelChatModelDownload(_e.id).then(Ns)},children:t("Cancel")}):_e.state==="ready"?e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.memory.deleteChatModel(_e.id).then(Ns)},children:t("Remove")}):e.jsx(y,{size:"sm",disabled:!te,onClick:()=>{window.electronAPI.memory.downloadChatModel(_e.id).then(Ns)},children:t("Download")})})]}),ps==="missing"&&e.jsx("p",{className:"text-xs text-destructive",children:t("Local model selected but the weights are not on disk. Distillation and interpretation will wait until you click Download.")}),ps==="downloading"&&e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Download in progress. Distillation waits until the model is ready.")}),N==="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:t("Distillation model")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Reads finished sessions and writes the memories.")})]}),B.length>0&&e.jsx("div",{className:"w-56 shrink-0",children:e.jsx(ze,{providers:B,providerId:ie?.id??"",modelId:F?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:t("Follows the title-summary model"),side:"bottom",triggerClassName:Qe,onSelect:(w,ve)=>q({providerId:w,modelId:ve}),onReasoningChange:()=>{},onThinkingChange:()=>{}})})]}),W&&e.jsx(y,{variant:"ghost",size:"sm",onClick:()=>q(null),children:t("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:t("Memory language")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("English keeps retrieval and near-duplicate detection stable across languages. Choose Follow conversation if your team only works in one language.")})]}),e.jsxs(ne,{value:H,items:Zn,onValueChange:w=>U(String(w)),disabled:!te,children:[e.jsx(ae,{className:"w-56",children:e.jsx(re,{})}),e.jsx(oe,{children:Zn.map(w=>e.jsx(Z,{value:w.value,children:w.label},w.value))})]})]})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium",children:t("Background processing")}),e.jsx(Is,{rowId:"memory.distill",title:t("Distill sessions automatically"),description:t("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:d,disabled:!te}),f&&ps&&e.jsx("p",{className:"text-xs text-destructive",children:t("Automatic distillation is on, but the local model is not ready. Sessions will queue until you download it.")}),e.jsx(Is,{rowId:"memory.kg",title:t("Extract entities"),description:t("Build an entity graph so a memory can be recalled by a name it does not literally contain."),checked:p,onChange:j,disabled:!te})]}),e.jsxs("section",{className:"space-y-2","data-settings-row":"memory.forgetting",children:[e.jsx("h3",{className:"text-sm font-medium",children:t("Forgetting")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Decay only changes how search ranks a memory. Archiving keeps it and can be undone; nothing on this page ever deletes a memory.")}),e.jsx(Is,{rowId:"memory.decay",title:t("Rank lower when never retrieved"),description:t("Memories that have not been retrieved for a long time rank lower. This changes ranking only — nothing is archived or deleted."),checked:b,onChange:A,disabled:!te}),e.jsx(Is,{rowId:"memory.decayCandidates",title:t("Mark archive candidates"),description:t("Mark cold, low-importance memories as candidates and show them in the library. Marking alone changes nothing."),checked:v,onChange:k,disabled:!te||!b}),e.jsx(Is,{rowId:"memory.decayAutoArchive",title:t("Archive candidates automatically"),description:t("Archive candidates at the end of each run. Archived memories are hidden from search but kept and can be restored."),checked:I,onChange:M,disabled:!te||!b||!v}),b&&e.jsxs(e.Fragment,{children:[e.jsx(Kt,{rowId:"memory.decayStaleDays",title:t("Not retrieved for"),description:t("Counted from the last retrieval; a memory that was never retrieved counts from creation."),value:String($),items:Gt(Rc,$,w=>t("{{count}} days",{count:String(w)})),onChange:w=>E(Number(w)),disabled:!te}),e.jsx(Kt,{rowId:"memory.decayMaxImportance",title:t("Importance at most"),description:t("Only memories at or below this importance can become candidates. 0.5 is the lowest tier distillation writes."),value:String(L),items:Gt(Oc,L,w=>w.toFixed(2)),onChange:w=>T(Number(w)),disabled:!te}),e.jsx(Kt,{rowId:"memory.decayInterval",title:t("Run every"),description:t("Checked when the library opens; there is no separate background timer."),value:String(C),items:Gt(Dc,C,w=>t("{{count}} days",{count:String(w)})),onChange:w=>S(Number(w)),disabled:!te})]}),b&&e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 rounded-lg border px-3 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:v||I?t("Archive candidates: {{count}}",{count:String(Pt?.candidates??0)}):t("Archive candidates: marking is off")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:fi})]}),e.jsxs("div",{className:"flex shrink-0 gap-2",children:[e.jsx(y,{size:"sm",variant:"outline",disabled:st!==null||!te,onClick:gi,children:t(st==="run"?"Running…":"Run now")}),e.jsx(y,{size:"sm",variant:"outline",disabled:!v||(Pt?.candidates??0)===0,onClick:qn,children:t("Review candidates")})]})]})]}),e.jsxs("section",{className:"space-y-2","data-settings-row":"memory.stats",children:[e.jsx("h3",{className:"text-sm font-medium",children:t("Library")}),P===null||P.total===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:t("No memories stored yet.")}):e.jsxs(e.Fragment,{children:[lr(P)&&e.jsx("p",{className:"text-xs text-destructive",children:t("Vectors unavailable: {{reason}}",{reason:lr(P)??""})}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-3",children:[e.jsx(ms,{label:t("Memories"),value:String(P.total)}),e.jsx(ms,{label:t("Crystals"),value:String(P.crystals)}),e.jsx(ms,{label:t("Entities"),value:String(P.entities)}),e.jsx(ms,{label:t("With vectors"),value:`${P.embedded}/${P.total}`,action:P.embedded<P.total?e.jsx("button",{type:"button",disabled:qe,className:"text-xs text-muted-foreground underline-offset-2 hover:underline disabled:opacity-60",onClick:()=>{Vn(!0),window.electronAPI.memory.reembed().then(()=>ys.current?.())},children:t(qe?"Backfilling…":"Backfill")}):null}),e.jsx(ms,{label:t("Database size"),value:me(P.databaseBytes)}),e.jsx(ms,{label:t("Spaces"),value:String(Object.keys(P.bySpace).length)}),e.jsx(ms,{label:t("Never retrieved"),value:`${P.neverHit}/${P.total}`,action:e.jsx("span",{className:"text-muted-foreground text-xs",children:t("{{percent}}% of library",{percent:String(P.total>0?Math.round(P.neverHit/P.total*100):0)})})}),e.jsx(ms,{label:t("Added in 7 days"),value:String(P.addedLast7Days)})]})]})]}),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:t("Distill past sessions")}),Hn.length>0&&e.jsx(y,{size:"sm",variant:"outline",disabled:!te||rs!==null||ps!==null,onClick:()=>Yn(ge,"all",t("All sessions")),children:rs==="all"?t("Distilling…"):t("Distill all ({{count}})",{count:String(Hn.length)})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("The automatic switch only covers sessions that end from now on. Distill earlier sessions here to fill the library.")}),G&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:[t("{{done}}/{{total}} done",{done:String(G.done),total:String(G.total)}),(()=>{const w=ip(G,Date.now());return w===null?"":` · ${t("about {{time}} left",{time:lp(w)})}`})()]}),Wn.length===0?e.jsx("p",{className:"text-muted-foreground text-sm",children:t("No recorded sessions found.")}):e.jsx("ul",{className:"divide-y rounded-lg border",children:Wn.map(w=>{const ve=w.sessions.filter(Ue=>!Ue.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:w.name}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("{{total}} sessions · {{pending}} not distilled",{total:String(w.sessions.length),pending:String(ve.length)})})]}),e.jsxs("div",{className:"flex shrink-0 gap-2",children:[e.jsx(y,{size:"sm",variant:"ghost",onClick:()=>Fs(w),children:t("View sessions")}),e.jsx(y,{size:"sm",variant:"outline",disabled:!te||rs!==null||w.sessions.length===0||ps!==null,onClick:()=>Yn(w.sessions,w.key,w.name),children:rs===w.key?t("Distilling…"):t("Distill project")})]})]},w.key)})})]}),e.jsx(ye,{open:os!==null,onOpenChange:w=>!w&&Fs(null),children:e.jsx(we,{children:os&&e.jsxs(e.Fragment,{children:[e.jsxs(Ne,{children:[e.jsx(ke,{children:os.name}),e.jsx(Ye,{children:t("{{total}} sessions · {{pending}} not distilled",{total:String(os.sessions.length),pending:String(os.sessions.filter(w=>!w.distilled).length)})})]}),e.jsx(Ce,{children:e.jsx("ul",{className:"divide-y rounded-lg border",children:os.sessions.map(w=>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:w.title}),e.jsxs("p",{className:"text-muted-foreground text-xs",children:[w.updatedAt?w.updatedAt.slice(0,10):"",w.distilled?` · ${t("Already distilled")}`:""]})]}),e.jsx(y,{size:"sm",variant:"ghost",className:"shrink-0",disabled:!te||rs!==null||ps!==null,onClick:()=>{nt([w],w.sessionId,w.distilled)},children:rs===w.sessionId?t("Distilling…"):w.distilled?t("Distill again"):t("Distill")})]},w.sessionId))})}),e.jsx(Ee,{children:e.jsx(Hs,{render:e.jsx(y,{variant:"outline",size:"sm"}),children:t("Close")})})]})})}),e.jsx(ye,{open:be!==null,onOpenChange:w=>!w&&Ae(null),children:e.jsx(we,{children:be&&e.jsxs(e.Fragment,{children:[e.jsxs(Ne,{children:[e.jsx(ke,{children:t("Some sessions were already distilled")}),e.jsx(Ye,{children:t("{{label}}: {{total}} sessions, {{done}} already distilled. Re-distilling runs the model again and may add new memories alongside the existing ones.",{label:be.label,total:String(be.scope.length),done:String(be.scope.length-be.pending.length)})})]}),e.jsxs(Ee,{children:[e.jsx(Hs,{render:e.jsx(y,{variant:"ghost",size:"sm"}),children:t("Cancel")}),e.jsx(y,{variant:be.pending.length>0?"default":"outline",size:"sm",disabled:be.pending.length===0,onClick:()=>{const w=be;Ae(null),nt(w.pending,w.token)},children:t("Only the {{count}} remaining",{count:String(be.pending.length)})}),e.jsx(y,{variant:be.pending.length>0?"outline":"default",size:"sm",onClick:()=>{const w=be;Ae(null),nt(w.scope,w.token,!0)},children:t("Re-distill all {{count}}",{count:String(be.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:t("Background tasks")}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[D.kgFailed>0&&e.jsx(y,{size:"sm",variant:"ghost",onClick:()=>{window.electronAPI.memory.retryFailedKgJobs().then(()=>ys.current?.())},children:t("Retry failed extractions ({{count}})",{count:String(D.kgFailed)})}),ks.some(w=>w.state!=="running")&&e.jsx(y,{size:"sm",variant:"ghost",title:t("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:t("Clear finished tasks")}),ks.length>or&&e.jsx(y,{size:"sm",variant:"ghost",onClick:()=>pi(!Et),children:Et?t("Show less"):t("Show all {{count}}",{count:String(ks.length)})})]})]}),ks.length===0?e.jsx("p",{className:"text-muted-foreground text-sm",children:t("Nothing running.")}):e.jsx("ul",{className:"divide-y rounded-lg border",children:(Et?ks:ks.slice(0,or)).map(w=>e.jsxs("li",{className:"space-y-1 px-3 py-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(se,{variant:w.state==="failed"?"destructive":"secondary",children:t(rp[w.kind])}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-sm",children:w.target}),e.jsx("span",{className:K("shrink-0 text-xs",w.state==="failed"?"text-destructive":"text-muted-foreground"),children:w.state==="running"?`⋯ ${w.detail}`:w.detail})]}),w.notes.map(ve=>e.jsxs("p",{className:"pl-1 text-muted-foreground text-xs",children:["· ",ve]},ve))]},w.key))})]}),e.jsx(ye,{open:Be!==null,onOpenChange:w=>!w&&Gn(null),children:e.jsxs(we,{children:[e.jsxs(Ne,{children:[e.jsx(ke,{children:t("Archive candidates")}),e.jsx(Ye,{children:t("Cold and low-importance memories. Archiving keeps them, hides them from search, and can be undone from the library.")})]}),e.jsx(Ce,{children:Be&&Be.items.length>0?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:t("{{selected}} of {{total}} selected",{selected:String(bs.size),total:String(Be.items.length)})}),e.jsx(y,{size:"sm",variant:"ghost",onClick:()=>Mt(bs.size===Be.items.length?new Set:new Set(Be.items.map(w=>w.id))),children:bs.size===Be.items.length?t("Clear selection"):t("Select all")})]}),e.jsx("ul",{className:"divide-y rounded-lg border",children:Be.items.map(w=>e.jsxs("li",{className:"flex items-start gap-2 px-3 py-2",children:[e.jsx(Le,{checked:bs.has(w.id),onCheckedChange:()=>Mt(ve=>{const Ue=new Set(ve);return Ue.has(w.id)?Ue.delete(w.id):Ue.add(w.id),Ue}),"aria-label":t("Select memory")}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-sm",children:w.title}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[w.spaceLabel," ·"," ",t("Importance {{value}}",{value:w.importance.toFixed(2)})," ·"," ",w.lastHitAt?t("Last retrieved {{date}}",{date:Os(w.lastHitAt)}):t("Never retrieved")]})]})]},w.id))}),Be.total>Be.items.length&&e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Showing the first {{shown}} of {{total}}.",{shown:String(Be.items.length),total:String(Be.total)})})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:t("No archive candidates right now.")})}),e.jsxs(Ee,{children:[e.jsx(Hs,{render:e.jsx(y,{variant:"outline",size:"sm"}),children:t("Close")}),e.jsx(y,{size:"sm",disabled:bs.size===0||st!==null,onClick:ji,children:t(st==="archive"?"Archiving…":"Archive selected")})]})]})})]})}function ms({label:s,value:t,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:s}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-sm",children:t}),n]})]})}function up(s,t){if(t===null)return{ok:!0,value:null};if(s.type==="boolean")return typeof t=="boolean"?{ok:!0,value:t}:t==="true"||t==="false"?{ok:!0,value:t==="true"}:{ok:!1,error:"需要打开或关闭"};if(typeof t!="string")return{ok:!1,error:"值不合法"};if(s.type==="number"){const n=t.trim();if(!/^-?\d+(\.\d+)?$/.test(n))return{ok:!1,error:"需要数字"};const a=Number(n);return Number.isFinite(a)?s.min!==void 0&&a<s.min?{ok:!1,error:"小于最小值"}:s.max!==void 0&&a>s.max?{ok:!1,error:"大于最大值"}:{ok:!0,value:a}:{ok:!1,error:"需要数字"}}return s.type==="enum"?s.options?.includes(t)?{ok:!0,value:t}:{ok:!1,error:"不在可选项里"}:s.type==="model"?go(t)?{ok:!0,value:t}:{ok:!1,error:"不是合法的模型选择"}:t.length>4096||t.includes("\0")?{ok:!1,error:"值不合法"}:{ok:!0,value:t}}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":"在你点击时于本项目新建会话","agent.run":"用当前会话的模型运行只读代理(可读项目文件与对话内容,不能修改)","secretary.contact":"作为秘书的联系方式:收发你与秘书之间的消息(里程碑、提问、确认卡提示)"};function Zo(s){return mp[s]??s}const xp=["themes","agent","productivity","integrations","insights","writing","fun"],$n={themes:"主题外观",agent:"Agent 能力",productivity:"效率工作流",integrations:"外部集成",insights:"观测统计",writing:"写作翻译",fun:"休闲娱乐"};function hp(s){return{installedKey:s,refresh:!0}}function pp(s,t){return s.installedKey===t?s:{installedKey:t,refresh:!1}}function Gs(s){if(!s)return null;try{const t=new URL(s);return t.protocol==="https:"||t.protocol==="http:"?t.href:null}catch{return null}}function fp({pluginId:s,name:t,from:n,homepage:a,onClose:r}){const{t:o}=R();return e.jsx(ye,{open:s!==null,onOpenChange:i=>!i&&r(),children:e.jsxs(we,{children:[e.jsx(Ne,{children:e.jsxs(ke,{children:[o("Usage guide"),t?` · ${t}`:""]})}),e.jsx(Ce,{className:"max-h-[60vh] space-y-3 overflow-y-auto",children:s&&e.jsx(ei,{pluginId:s,from:n,homepage:a})})]})})}function ei({pluginId:s,from:t,homepage:n,showLink:a=!0}){const{t:r}=R(),[o,i]=l.useState(null),[m,u]=l.useState(null),[x,h]=l.useState(Gs(n)),[c,f]=l.useState(null);return l.useEffect(()=>{let d=!0;return xt(()=>import("./globals-kfeSrZZh.js").then(p=>p.oj),__vite__mapDeps([0,1]),import.meta.url).then(p=>{d&&f(()=>p.Markdown)}),()=>{d=!1}},[]),l.useEffect(()=>{let d=!1;return i(null),u(null),h(Gs(n)),(async()=>{const p=window.electronAPI.extensionPlugins,j=await p.readme({id:s,from:t});let b=j.ok?j.markdown:null,A=j.ok?null:j.error;if(!j.ok&&t==="installed"){const v=await p.readme({id:s,from:"market"});v.ok&&(b=v.markdown,A=null)}if(!Gs(n)){const v=await p.marketList(!1),k=v.ok?v.plugins.find(I=>I.id===s):void 0;d||h(Gs(k?.homepage))}d||(i(b),u(b?null:A))})(),()=>{d=!0}},[s,t,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")}),m&&e.jsx("p",{className:"text-muted-foreground text-sm",children:m}),o===null&&!m&&e.jsx("p",{className:"text-muted-foreground text-sm",children:"…"}),o!==null&&c&&e.jsx(c,{text:o})]})}function si(s,t){return t==="all"?!0:t==="installed"?s.installedVersion!==void 0:t==="updates"?s.updateAvailable:t==="other"?s.category===void 0:s.category===t}function gp(s){const t=r=>s.filter(o=>si(o,r)).length,n=["all","installed","updates"],a=[...xp,"other"];return[...n.map(r=>({id:r,count:t(r)})),...a.map(r=>({id:r,count:t(r)})).filter(r=>r.count>0)]}function jp(s,t){const n=t.query.trim().toLowerCase();return s.filter(a=>si(a,t.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 dr={all:"全部",installed:"已安装",updates:"可更新",other:"其他"},vp=s=>s in dr?dr[s]:$n[s];function bp({disabled:s,installedKey:t,onInstall:n,initialQuery:a=""}){const{t:r}=R(),o=window.electronAPI.extensionPlugins,[i,m]=l.useState(null),[u,x]=l.useState(!1),[h,c]=l.useState(a),[f,d]=l.useState("all"),[p,j]=l.useState(null),[b,A]=l.useState(()=>hp(t)),v=pp(b,t);v!==b&&A(v);const k=l.useCallback(async C=>{x(!0);try{m(await o.marketList(C))}catch(S){m({ok:!1,error:S instanceof Error?S.message:String(S),chinaMirror:!1})}finally{x(!1)}},[o]);l.useEffect(()=>{k(b.refresh)},[k,b]);const I=async C=>{await o.setMarketChinaMirror(C),await k(!0)},M=i?.ok===!0?i.plugins:[],$=gp(M),E=$.some(C=>C.id===f)?f:"all",L=jp(M,{query:h,section:E}),T=p?M.find(C=>C.id===p):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:$.map(C=>e.jsxs("button",{type:"button","aria-pressed":E===C.id,onClick:()=>{d(C.id),j(null)},className:K("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",E===C.id&&"bg-accent font-medium"),children:[e.jsx("span",{className:"truncate whitespace-nowrap",children:vp(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:h,placeholder:r("Search plugins"),onChange:C=>{c(C.target.value),j(null)}}),e.jsxs("label",{className:"flex shrink-0 items-center gap-1.5 text-muted-foreground text-xs",children:[e.jsx(ce,{checked:i?.chinaMirror??!1,disabled:u,onCheckedChange:C=>{I(C)}}),r("China mirror")]}),e.jsx(y,{size:"sm",variant:"ghost",disabled:u,onClick:()=>{k(!0)},children:u?e.jsx(Ps,{}):r("Refresh")})]}),i?.ok===!1&&e.jsx("p",{className:"text-destructive text-sm",children:i.error}),i?.ok===!0&&i.stale&&e.jsx("p",{className:"text-muted-foreground text-xs",children:r("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:T?e.jsx(wp,{plugin:T,disabled:s,onBack:()=>j(null),onInstall:n}):i?.ok===!0&&L.length===0?e.jsx("p",{className:"text-muted-foreground text-sm",children:r("No matching plugins")}):e.jsx("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2",children:L.map(C=>e.jsx(yp,{plugin:C,disabled:s,onOpen:()=>j(C.id),onInstall:n},C.id))})})]})]})}function ti({plugin:s,disabled:t,onInstall:n}){const{t:a}=R();return s.installedVersion&&!s.updateAvailable?e.jsx("span",{className:"shrink-0 text-muted-foreground text-xs",children:a("Installed")}):e.jsx(y,{size:"xs",variant:s.updateAvailable?"default":"outline",disabled:t,onClick:r=>{r.stopPropagation(),n(s.id)},children:s.updateAvailable?a("Update"):a("Install")})}function ni({tier:s}){const{t}=R();return e.jsx(se,{variant:s==="official"?"secondary":"outline",className:"text-[11px]",children:t(s==="official"?"Official":"Community")})}function yp({plugin:s,disabled:t,onOpen:n,onInstall:a}){return e.jsxs("div",{role:"button",tabIndex:0,"aria-label":s.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(ai,{src:s.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:s.name}),e.jsx(ni,{tier:s.tier})]}),e.jsxs("p",{className:"text-muted-foreground text-xs",children:[s.latest,s.category?` · ${$n[s.category]}`:""]})]}),e.jsx(ti,{plugin:s,disabled:t,onInstall:a})]}),s.description&&e.jsx("p",{className:"line-clamp-2 text-muted-foreground text-xs",children:s.description})]})}function wp({plugin:s,disabled:t,onBack:n,onInstall:a}){const{t:r}=R(),o=Gs(s.homepage);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs(y,{size:"xs",variant:"ghost",onClick:n,children:[e.jsx(jo,{className:"size-3.5"}),"返回"]}),e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(ai,{src:s.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:s.name}),e.jsx(ni,{tier:s.tier}),s.category&&e.jsx(se,{variant:"outline",className:"text-[11px]",children:$n[s.category]})]}),e.jsxs("p",{className:"font-mono text-muted-foreground text-xs",children:[s.id," · ",s.latest,s.installedVersion?` · 已装 ${s.installedVersion}`:""]}),s.description&&e.jsx("p",{className:"text-sm",children:s.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(Lc,{className:"size-3"}),r("Homepage")]})]}),e.jsx(ti,{plugin:s,disabled:t,onInstall:a})]}),s.screenshots&&s.screenshots.length>0&&e.jsx("div",{className:"flex gap-2 overflow-x-auto pb-1",children:s.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:"权限"}),s.permissions.length===0?e.jsx("p",{className:"text-muted-foreground text-xs",children:"无特殊权限"}):e.jsx("ul",{className:"space-y-0.5",children:s.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:Zo(i)})]},i))})]}),e.jsxs("section",{className:"space-y-1",children:[e.jsx("h3",{className:"font-medium text-sm",children:r("Usage guide")}),e.jsx(ei,{pluginId:s.id,from:"market",homepage:s.homepage,showLink:!1})]})]})}function ai({src:s,large:t}){const[n,a]=l.useState(!1);return e.jsx("div",{className:K("flex shrink-0 items-center justify-center rounded-md bg-muted",t?"size-12":"size-9"),children:s&&!n?e.jsx("img",{src:s,alt:"",className:t?"size-7 object-contain":"size-5 object-contain",onError:()=>a(!0)}):e.jsx(Xs,{className:"size-4 text-muted-foreground"})})}const ur={session:"跟随当前会话",title:"跟随标题模型",fixed:"指定模型"};function Np({value:s,onChange:t}){const n=es(),a=go(s)??"session",r=typeof a=="string"?a:"fixed",o=typeof a=="string"?null:a,i=o?n.find(u=>u.id===o.providerId):void 0,m=i?.models.find(u=>u.id===o?.modelId);return e.jsxs("div",{className:"space-y-2",children:[e.jsxs(ne,{items:ur,value:r,onValueChange:u=>{if(u==="session"||u==="title")t(u);else if(u==="fixed"&&!o){const x=n[0],h=x?.models[0];x&&h&&t(ba({providerId:x.id,modelId:h.id}))}},children:[e.jsx(ae,{children:e.jsx(re,{})}),e.jsx(oe,{children:Object.entries(ur).map(([u,x])=>e.jsx(Z,{value:u,disabled:u==="fixed"&&n.length===0,children:x},u))})]}),o&&e.jsx(ze,{providers:n,providerId:i?.id??"",modelId:m?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:"选择模型",side:"bottom",triggerClassName:Qe,onSelect:(u,x)=>t(ba({providerId:u,modelId:x})),onReasoningChange:()=>{},onThinkingChange:()=>{}}),o&&!m&&e.jsx("p",{className:"text-destructive text-xs",children:"选中的模型已不可用,运行时会失败,请重新选择。"})]})}function kp(s){const{notice:t,remote:n,onDismiss:a}=s;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:[t.unreadable&&e.jsx("p",{children:"插件登记表曾读取失败,下面的列表可能不全。插件文件没有删除,原文保存在数据目录的 extension-plugins/registry.json.unreadable。"}),t.discarded.length>0&&e.jsxs("p",{children:["检测到旧格式的登记记录,已丢弃并清理,请重新安装:",e.jsx("span",{className:"font-mono",children:t.discarded.join(", ")})]}),n?e.jsx("p",{className:"text-muted-foreground",children:"请在桌面端点「知道了」,或运行 enso-server plugin notice-dismiss 清除此提示。"}):e.jsx(y,{size:"sm",variant:"outline",onClick:a,children:"知道了"})]})}function Cp({pluginId:s,plain:t}){const{t:n}=R(),[a,r]=l.useState([]),[o,i]=l.useState({}),[m,u]=l.useState(null),x=l.useCallback(async()=>{const d=await window.electronAPI.extensionPlugins.configGet(s);d.ok?r(d.fields):u({error:!0,text:d.error}),i({})},[s]);l.useEffect(()=>{x()},[x]);const h=async()=>{const d={};for(const[j,b]of Object.entries(o)){const A=a.find(k=>k.key===j);if(!A||A.secret&&b==="")continue;const v=up(A,b);if(!v.ok){u({error:!0,text:`${A.title}:${v.error}`});return}d[j]=v.value}const p=await window.electronAPI.extensionPlugins.configSet(s,d);u(p.ok?{error:!1,text:n("Saved. New calls use it right away.")}:{error:!0,text:p.error??""}),p.ok&&await x()},c=d=>{const p=o[d.key];return typeof p=="string"?p:p===null||d.secret?"":d.value??(d.default!==void 0?String(d.default):"")},f=d=>{const p=o[d.key];return typeof p=="boolean"?p:(d.value??(typeof d.default=="boolean"?String(d.default):"false"))==="true"};return e.jsxs("div",{className:K("space-y-2",t?"":"rounded-md border border-border p-3"),children:[a.map(d=>e.jsxs("div",{className:"space-y-1",children:[e.jsxs("p",{className:"text-sm",children:[d.title,e.jsx("span",{className:"ml-2 font-mono text-muted-foreground text-xs",children:d.key})]}),d.description&&e.jsx("p",{className:"text-muted-foreground text-xs",children:d.description}),d.multiline&&d.type==="string"?e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Xe,{autoComplete:"off",rows:4,value:c(d),placeholder:d.secret&&d.set?n("Set (leave blank to keep)"):n("Not set"),className:"min-w-0 flex-1",onChange:p=>i(j=>({...j,[d.key]:p.target.value}))}),d.set&&e.jsx(y,{size:"sm",variant:"ghost",onClick:()=>i(p=>({...p,[d.key]:null})),children:n("Clear value")})]}):d.secret||d.type==="string"||d.type==="number"||d.type==="path"?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(J,{type:d.secret?"password":d.type==="number"?"number":"text",autoComplete:"off",inputMode:d.type==="number"?"decimal":void 0,min:d.type==="number"?d.min:void 0,max:d.type==="number"?d.max:void 0,value:c(d),placeholder:d.secret&&d.set?n("Set (leave blank to keep)"):n("Not set"),onChange:p=>i(j=>({...j,[d.key]:p.target.value}))}),d.type==="path"&&!d.secret&&!window.electronAPI.remote&&e.jsx(y,{size:"sm",variant:"outline",onClick:()=>{window.electronAPI.extensionPlugins.pickPath(d.pathKind==="directory"?"directory":"file").then(p=>{p.ok&&"path"in p&&i(j=>({...j,[d.key]:p.path}))})},children:d.pathKind==="directory"?"选择文件夹":"选择文件"}),d.set&&e.jsx(y,{size:"sm",variant:"ghost",onClick:()=>i(p=>({...p,[d.key]:null})),children:n("Clear value")})]}):d.type==="boolean"?e.jsx(ce,{checked:f(d),onCheckedChange:p=>i(j=>({...j,[d.key]:p}))}):d.type==="model"?e.jsx(Np,{value:c(d),onChange:p=>i(j=>({...j,[d.key]:p}))}):e.jsxs(ne,{items:Object.fromEntries((d.options??[]).map(p=>[p,p])),value:c(d),onValueChange:p=>{typeof p=="string"&&i(j=>({...j,[d.key]:p}))},children:[e.jsx(ae,{children:e.jsx(re,{placeholder:"请选择"})}),e.jsx(oe,{children:(d.options??[]).map(p=>e.jsx(Z,{value:p,children:p},p))})]})]},d.key)),m&&e.jsx("p",{className:K("text-xs",m.error?"text-destructive":"text-muted-foreground"),children:m.text}),e.jsx(y,{size:"sm",disabled:Object.keys(o).length===0,onClick:()=>{h()},children:n("Save")})]})}function Sp({pluginId:s,plain:t}){const{t:n}=R(),[a,r]=l.useState(null),o=l.useCallback(async()=>{const i=await window.electronAPI.extensionPlugins.logs(s);r(i.ok?i.text:i.error)},[s]);return l.useEffect(()=>{o()},[o]),e.jsxs("div",{className:K("space-y-2",t?"":"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(y,{size:"icon",variant:"ghost","aria-label":n("Refresh"),onClick:()=>{o()},children:e.jsx(ns,{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 mr({message:s}){const[t,n]=l.useState(!1);return e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("p",{className:K("select-text break-all font-mono text-destructive text-xs",t?"max-h-48 overflow-auto whitespace-pre-wrap":"line-clamp-2"),children:s}),s.length>120&&e.jsx("button",{type:"button",className:"text-muted-foreground text-xs hover:text-foreground",onClick:()=>n(a=>!a),children:t?"收起":"展开全部"})]})}function ri({permissions:s,styles:t=!1}){return s.length===0?t?null:e.jsx("p",{className:"text-muted-foreground text-xs",children:"无特殊权限"}):e.jsx("ul",{className:"space-y-0.5",children:s.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:Zo(n)})]},n))})}function Ip(s){const t=s.intervalSeconds>=60&&s.intervalSeconds%60===0?`每 ${s.intervalSeconds/60} 分钟`:`每 ${s.intervalSeconds} 秒`,n=s.lastRunAt?` · 最近 ${new Date(s.lastRunAt).toLocaleString()}`:"";return`${s.id} · ${t}${n}${s.lastError?` · ${s.lastError}`:""}`}function xr(s){return[s.permissions.length>0?`${s.permissions.length} 项权限`:"",(s.events?.length??0)>0?`${s.events?.length} 个事件`:"",(s.schedules?.length??0)>0?`${s.schedules?.length} 个定时任务`:"",s.hasRenderer?"界面代码":"",s.crossSessionInject!==void 0?"跨会话投递开关":""].filter(Boolean).join(" · ")}function hr({permissions:s,env:t,interop:n,resident:a,running:r,styles:o,trustedUi:i,events:m,schedules:u}){return e.jsxs("div",{className:"space-y-1",children:[e.jsx(ri,{permissions:s,styles:o||i}),i&&e.jsx(Ap,{}),a&&e.jsxs("p",{className:"text-xs",children:["常驻进程",r===void 0?"":r?":运行中":":未运行"]}),o&&e.jsx("p",{className:"text-xs",children:"修改界面样式:主题 CSS 可以改变应用的任意界面"}),(t?.length??0)>0&&e.jsxs("p",{className:"text-xs",children:["环境变量:",e.jsx("span",{className:"font-mono",children:t?.join(", ")})]}),(n?.length??0)>0&&e.jsxs("p",{className:"text-xs",children:["可调用插件:",e.jsx("span",{className:"font-mono",children:n?.join(", ")})]}),m?.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:["定时任务 ",Ip(x)]},x.id))]})}function Ap(){return e.jsx("p",{className:"text-amber-700 text-xs dark:text-amber-400",children:"界面代码:运行在主界面里,可读写页面内容、调用界面能力,不受上面权限清单约束;只安装信任的插件"})}function Ep({pluginId:s,plain:t}){const[n,a]=l.useState(null),[r,o]=l.useState(null),i=l.useCallback(async()=>{const m=await window.electronAPI.extensionPlugins.artifactsList(s);m.ok?(a(m.artifacts),o(null)):o(m.error)},[s]);return l.useEffect(()=>{i()},[i]),e.jsxs("div",{className:K("space-y-2",t?"":"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(y,{size:"icon",variant:"ghost","aria-label":"刷新",onClick:()=>{i()},children:e.jsx(ns,{className:"size-4"})})]}),r&&e.jsx("p",{className:"text-destructive text-xs",children:r}),e.jsx($c,{artifacts:n??[],onDelete:m=>{window.electronAPI.extensionPlugins.artifactDelete(m).then(u=>{u.ok?i():o(u.error??"删除失败")})}})]})}const Wt=new Set;function Mp({requestedInstallUrl:s=null,onRequestedInstallUrlConsumed:t,focusPluginId:n=null,onFocusPluginConsumed:a,requestedMarketQuery:r=null,onRequestedMarketQueryConsumed:o}={}){const{t:i}=R(),m=g(P=>P.pluginAutoUpdate!==!1),u=g(P=>P.setPluginAutoUpdate),[x,h]=l.useState([]),c=En(P=>P.errors),[f,d]=l.useState(null),[p,j]=l.useState(null),[b,A]=l.useState([]),[v,k]=l.useState(!1),[I,M]=l.useState(null),[$,E]=l.useState(""),[L,T]=l.useState(!1),[C,S]=l.useState(!1),[W,q]=l.useState(null),[N,z]=l.useState(null),[H,U]=l.useState(!1),[B,ie]=l.useState("");l.useEffect(()=>{r&&(ie(r),U(!0),o?.())},[r,o]);const[F,X]=l.useState(null),V=l.useCallback(async()=>{try{h(await window.electronAPI.extensionPlugins.list())}catch{h([])}},[]);l.useEffect(()=>(V(),window.electronAPI.extensionPlugins.registryNotice().then(z).catch(()=>z(null)),window.electronAPI.extensionPlugins.onChanged(()=>{V()})),[V]),l.useEffect(()=>{if(!n||(A(Y=>Y.includes(n)?Y:[...Y,n]),!x.some(Y=>Y.id===n)))return;const P=n;window.requestAnimationFrame(()=>{document.querySelector(`[data-plugin-id="${CSS.escape(P)}"]`)?.scrollIntoView({block:"center"})}),a?.()},[n,x,a]);const le=async P=>{M(null),f&&window.electronAPI.extensionPlugins.discard(f.token),d(null);const Y=await window.electronAPI.extensionPlugins.pickAndStage(P);Y.ok?"cancelled"in Y||d(Y.preview):M(Y.error)},_=async P=>{const Y=(P??$).trim();if(!Y)return;M(null),T(!0),f&&window.electronAPI.extensionPlugins.discard(f.token),d(null);const D=await window.electronAPI.extensionPlugins.stageFromUrl(Y).finally(()=>{T(!1)});D.ok?d(D.preview):M(D.error)},de=l.useRef(_);de.current=_,l.useEffect(()=>{if(!s)return;const P=s;let Y=!1;const D=window.setTimeout(()=>{Y||Wt.has(P)||(Wt.add(P),E(P),t?.(),de.current(P).finally(()=>{Wt.delete(P)}))},0);return()=>{Y=!0,window.clearTimeout(D)}},[s,t]);const ue=async(P,Y=!1)=>{M(null),f&&window.electronAPI.extensionPlugins.discard(f.token),d(null),T(!0);const D=window.electronAPI.extensionPlugins,Q=await(Y?D.marketStage(P):D.restage(P)).finally(()=>{T(!1)});Q.ok?d(Q.preview):M(Q.error)},O=async()=>{S(!0),q(null);try{const P=await window.electronAPI.extensionPlugins.checkUpdates();q(P.checked===0?i("No plugins installed from GitHub to check"):P.available>0?i("{{count}} update(s) available",{count:P.available}):i("All plugins are up to date"))}finally{S(!1)}},De=async()=>{if(!f)return;k(!0);const P=await window.electronAPI.extensionPlugins.commit(f.token);if(k(!1),!P.ok)M(P.error??i("Install failed"));else{E("");const Y=f.existingVersion?{ok:!0}:await window.electronAPI.extensionPlugins.setEnabled(f.id,!0);Te({type:Y.ok?"success":"warning",title:i("{{name}} installed",{name:f.name}),description:Y.ok?void 0:Y.error})}d(null)},te=()=>{f&&window.electronAPI.extensionPlugins.discard(f.token),d(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:[i("Enso plugins"),e.jsx(Ze,{})]}),e.jsx("p",{className:"mt-1 text-muted-foreground text-sm",children:i("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:[x.length>0&&e.jsxs(y,{size:"sm",variant:"outline",disabled:C,onClick:()=>{O()},children:[C?e.jsx(Ps,{}):e.jsx(ns,{className:"size-4"}),i("Check for updates")]}),e.jsxs(y,{size:"sm",onClick:()=>{ie(""),U(!0)},children:[e.jsx(Vu,{className:"size-4"}),i("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:i("Update plugins automatically")}),e.jsx("span",{className:"block text-muted-foreground text-xs",children:i("Marketplace updates that do not ask for new permissions install on their own.")})]}),e.jsx(ce,{className:"shrink-0",checked:m,onCheckedChange:P=>u(P)})]}),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(ho,{className:"flex-1",children:[e.jsx(fo,{children:e.jsx(ao,{className:"size-4 text-muted-foreground"})}),e.jsx(po,{value:$,placeholder:i("https://github.com/owner/repo"),onChange:P=>E(P.target.value),onKeyDown:P=>{P.key==="Enter"&&_()}})]}),e.jsx(y,{size:"sm",variant:"outline",disabled:v||L||$.trim()==="",onClick:()=>{_()},children:L?e.jsx(Ps,{}):i("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:i("Or install from")}),e.jsxs(y,{size:"xs",variant:"ghost",disabled:v||L,onClick:()=>{le("dir")},children:[e.jsx(Tn,{className:"size-3.5"}),i("Install from folder")]}),e.jsxs(y,{size:"xs",variant:"ghost",disabled:v||L,onClick:()=>{le("zip")},children:[e.jsx(zc,{className:"size-3.5"}),i("Install from zip")]})]})]}),I&&e.jsx("p",{className:"text-destructive text-sm",children:I}),e.jsx(ye,{open:H,onOpenChange:U,children:e.jsxs(we,{className:"max-w-5xl",children:[e.jsx(Ne,{children:e.jsx(ke,{children:i("Marketplace")})}),e.jsx(Ce,{children:e.jsx(bp,{initialQuery:B,disabled:v||L,installedKey:x.map(P=>`${P.id}@${P.version}`).join(","),onInstall:P=>{U(!1),ue(P,!0)}},B)})]})}),W&&e.jsx("p",{className:"text-muted-foreground text-sm",children:W}),N&&e.jsx(kp,{notice:N,remote:!!window.electronAPI.remote,onDismiss:()=>{window.electronAPI.extensionPlugins.dismissRegistryNotice().then(()=>z(null)).catch(P=>M(P instanceof Error?P.message:String(P)))}}),e.jsx(ye,{open:f!==null,onOpenChange:P=>!P&&!v&&te(),children:e.jsx(we,{children:f&&e.jsxs(e.Fragment,{children:[e.jsx(Ne,{children:e.jsxs(ke,{children:[f.name," ",f.version,f.existingVersion&&e.jsx("span",{className:"ml-2 text-base text-muted-foreground",children:i("updating from {{version}}",{version:f.existingVersion})})]})}),e.jsxs(Ce,{className:"space-y-3",children:[e.jsx(hr,{permissions:f.permissions,env:f.env,interop:f.interop,resident:f.resident,styles:f.styles,trustedUi:f.hasRenderer,events:f.events,schedules:f.schedules}),f.mcpServers.map(P=>e.jsxs("p",{className:"font-mono text-xs",children:[P.command," ",P.args.join(" ")]},P.name)),f.mcpTools.length>0&&e.jsxs("p",{className:"text-muted-foreground text-xs",children:[i("Host MCP tools it may call"),":",e.jsx("span",{className:"font-mono",children:f.mcpTools.join(", ")})]}),f.warnings.map(P=>e.jsx("p",{className:"text-muted-foreground text-xs",children:P},P))]}),e.jsxs(Ee,{children:[e.jsx(y,{size:"sm",variant:"ghost",disabled:v,onClick:te,children:i("Cancel")}),e.jsx(y,{size:"sm",disabled:v,onClick:()=>{De()},children:v?e.jsx(Ps,{}):i("Install")})]})]})})}),x.length===0&&!f&&e.jsxs("div",{className:"rounded-lg border border-dashed px-3 py-10 text-center",children:[e.jsx(Xs,{className:"mx-auto size-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:i("No Enso plugins installed")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:i("Browse the marketplace or install from a GitHub URL, folder or zip.")})]}),e.jsx("div",{className:"space-y-2",children:x.map(P=>e.jsxs("div",{"data-plugin-id":P.id,className:K("overflow-hidden rounded-lg border bg-card transition-colors",P.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:K("flex size-9 shrink-0 items-center justify-center rounded-md bg-muted",P.state==="enabled"?"text-foreground":"text-muted-foreground"),children:e.jsx(_c,{pluginId:P.id,icon:P.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:P.name}),e.jsx(se,{variant:"outline",className:"text-[11px]",children:P.version}),P.state==="crashed"&&e.jsx(se,{variant:"destructive",className:"text-[11px]",children:i("Stopped after crashes")}),P.availableVersion&&e.jsx(se,{className:"text-[11px]",children:i("Update")}),P.pendingVersion&&e.jsx(se,{variant:"warning",className:"text-[11px]",children:"待授权"}),P.hasRenderer&&e.jsx(se,{variant:"outline",className:"text-[11px]",children:"受信任界面"}),P.devWatch&&e.jsx(se,{variant:"secondary",className:"text-[11px]",children:"开发模式"}),P.resident&&e.jsx(se,{variant:P.running?"secondary":"outline",className:"text-[11px]",children:P.running?"常驻运行中":"常驻未运行"})]}),e.jsx("p",{className:"truncate font-mono text-muted-foreground text-xs",children:P.id}),P.availableVersion&&e.jsxs("p",{className:"mt-1 flex items-center gap-2 text-primary text-xs",children:[i("Version {{version}} is available",{version:P.availableVersion}),e.jsx(y,{size:"xs",disabled:v||L,onClick:()=>{ue(P.id,P.source?.kind!=="url")},children:L?e.jsx(Ps,{}):i("Update")})]}),P.updateCheckError&&e.jsx("p",{className:"text-muted-foreground text-xs",children:i("Update check failed: {{reason}}",{reason:P.updateCheckError})}),P.lastError&&e.jsx(mr,{message:P.lastError.message}),c[P.id]?.map(Y=>e.jsx(mr,{message:`主题加载失败:${Y}`},Y)),P.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:[i("{{version}} asks for more and is waiting for approval",{version:P.pendingVersion}),e.jsx(y,{size:"xs",onClick:()=>{window.electronAPI.extensionPlugins.approvePending(P.id)},children:i("Allow")}),e.jsx(y,{size:"xs",variant:"ghost",onClick:()=>{window.electronAPI.extensionPlugins.rejectPending(P.id)},children:i("Keep current")})]})]})]}),e.jsxs("div",{className:"ml-auto flex shrink-0 items-center gap-0.5",children:[P.source&&e.jsx(y,{size:"icon",variant:"ghost",disabled:v||L,"aria-label":i("Reinstall from source"),title:P.source.kind==="url"?`${i("Reinstall from source")}: ${P.source.url}`:i("Reinstall from source"),onClick:()=>{ue(P.id)},children:e.jsx(Fc,{className:"size-4"})}),e.jsx(y,{size:"icon",variant:"ghost","aria-label":"产出文件",title:"产出文件",onClick:()=>j({kind:"artifacts",pluginId:P.id,pluginName:P.name}),children:e.jsx(Bc,{className:"size-4"})}),e.jsx(y,{size:"icon",variant:"ghost","aria-label":i("Usage guide"),title:i("Usage guide"),onClick:()=>X({id:P.id,name:P.name,from:"installed"}),children:e.jsx(yu,{className:"size-4"})}),e.jsx(y,{size:"icon",variant:"ghost","aria-label":i("Plugin logs"),title:i("Plugin logs"),onClick:()=>j({kind:"logs",pluginId:P.id,pluginName:P.name}),children:e.jsx(Ln,{className:"size-4"})}),P.configurable&&e.jsx(y,{size:"icon",variant:"ghost","aria-label":i("Configure"),title:i("Configure"),onClick:()=>j({kind:"config",pluginId:P.id,pluginName:P.name}),children:e.jsx(Uc,{className:"size-4"})}),e.jsx(y,{size:"icon",variant:"ghost","aria-label":i("Uninstall"),title:i("Uninstall"),className:"text-muted-foreground hover:text-destructive",onClick:()=>{window.electronAPI.extensionPlugins.uninstall(P.id)},children:e.jsx(Pe,{className:"size-4"})}),e.jsx("div",{className:"mx-1.5 h-5 w-px bg-border"}),e.jsx(ce,{checked:P.state==="enabled",onCheckedChange:Y=>{window.electronAPI.extensionPlugins.setEnabled(P.id,Y)}})]})]}),e.jsxs("button",{type:"button","aria-expanded":b.includes(P.id),className:K("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:()=>A(Y=>Y.includes(P.id)?Y.filter(D=>D!==P.id):[...Y,P.id]),children:[b.includes(P.id)?e.jsx(gt,{className:"size-3"}):e.jsx(Ds,{className:"size-3"}),b.includes(P.id)?"收起详情":"详情",!b.includes(P.id)&&xr(P)&&e.jsx("span",{className:"ml-1 opacity-70",children:xr(P)})]}),b.includes(P.id)&&e.jsxs("div",{className:"space-y-3 border-t px-3 py-3",children:[P.interceptBreakers?.map(Y=>e.jsxs("p",{className:"text-amber-600 text-xs dark:text-amber-400",children:[Y.event," 检查连续失败,临时放行到"," ",new Date(Y.until).toLocaleTimeString()]},Y.event)),e.jsx(hr,{permissions:P.permissions,resident:P.resident,running:P.running,styles:P.themes.some(Y=>Y.css!==void 0),trustedUi:P.hasRenderer,events:P.events,schedules:P.schedules}),P.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(ce,{"aria-label":"允许向任意运行中的会话发送消息",checked:P.crossSessionInject,onCheckedChange:Y=>{window.electronAPI.extensionPlugins.setCrossSessionInject(P.id,Y)}})]}),P.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(ce,{"aria-label":"开发模式:目录改动后自动重装",checked:P.devWatch,onCheckedChange:Y=>{window.electronAPI.extensionPlugins.setDevWatch(P.id,Y).then(D=>{!D.ok&&D.error&&Te({title:D.error})})}})]}),((P.pendingPermissions?.length??0)>0||P.pendingRenderer)&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:"待同意"}),e.jsx(ri,{permissions:P.pendingPermissions??[],styles:P.pendingRenderer}),P.pendingRenderer&&e.jsx("p",{className:"text-amber-700 text-xs dark:text-amber-400",children:"新增界面代码:运行在主界面里,不受权限清单约束"})]})]})]},P.id))}),e.jsx(ye,{open:p!==null,onOpenChange:P=>!P&&j(null),children:e.jsxs(we,{children:[e.jsx(Ne,{children:e.jsxs(ke,{children:[p?.kind==="config"?i("Configure"):p?.kind==="logs"?i("Plugin logs"):"产出文件",p?` · ${p.pluginName}`:""]})}),e.jsxs(Ce,{className:"space-y-4",children:[p?.kind==="config"&&e.jsx(Cp,{pluginId:p.pluginId,plain:!0}),p?.kind==="logs"&&e.jsx(Sp,{pluginId:p.pluginId,plain:!0}),p?.kind==="artifacts"&&e.jsx(Ep,{pluginId:p.pluginId,plain:!0})]})]})}),e.jsx(fp,{pluginId:F?.id??null,name:F?.name??"",from:F?.from??"installed",homepage:F?.homepage,onClose:()=>X(null)})]})}function Pp(s,t){return[[s.skills.length,t("Skills")],[s.commands.length,t("Commands")],[s.agents.length,t("Agent types")],[s.mcpServers.length,"MCP"],[s.hooks.length,"Hooks"]].filter(([n])=>n>0).map(([n,a])=>`${a} ${n}`).join(" · ")}function As({label:s,items:t}){return t.length===0?null:e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("p",{className:"font-medium text-muted-foreground text-xs",children:s}),t.map(n=>e.jsx("p",{className:"break-all font-mono text-[11px]",children:n},n))]})}function Tp({plugin:s,entry:t,onToggle:n}){const{t:a}=R(),[r,o]=l.useState(!1),{components:i}=s,m=Pp(i,a);return e.jsxs("div",{className:"rounded-md border","data-settings-row":`plugins.${s.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(Ds,{className:K("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:s.name}),s.version&&e.jsx(se,{variant:"outline",className:"shrink-0 text-[11px]",children:s.version}),s.marketplace&&e.jsx(se,{variant:"secondary",className:"shrink-0 text-[11px]",children:s.marketplace}),e.jsx("span",{className:"min-w-0 truncate text-muted-foreground text-xs",children:m||(i.unsupported.length>0?`${a("Not supported")}: ${i.unsupported.join(", ")}`:a("No supported components"))})]}),e.jsx(ce,{checked:t?.enabled===!0,onCheckedChange:n})]}),r&&e.jsxs("div",{className:"space-y-2 border-t px-3 py-2",children:[s.description&&e.jsx("p",{className:"text-muted-foreground text-xs",children:s.description}),e.jsx(As,{label:a("Skills"),items:i.skills}),e.jsx(As,{label:a("Commands"),items:i.commands.map(u=>`/${u}`)}),e.jsx(As,{label:a("Agent types"),items:i.agents}),e.jsx(As,{label:a("MCP servers (run when a session starts)"),items:i.mcpServers.map(u=>`${u.name}: ${u.target}`)}),e.jsx(As,{label:a("Hooks (run automatically on local sessions)"),items:i.hooks.map(u=>`${u.event}: ${u.command}`)}),e.jsx(As,{label:a("Not supported"),items:i.unsupported})]})]})}function Rp(){const{t:s}=R(),t=g(d=>d.plugins),n=g(d=>d.addPlugins),a=g(d=>d.setPluginEnabled),r=g(d=>d.removePlugin),[o,i]=l.useState(null),m=l.useCallback(async()=>{i(null);try{i(await window.electronAPI.assets.listInstalledPlugins())}catch{i([])}},[]);l.useEffect(()=>{m()},[m]);const u=new Map(t.map(d=>[d.key,d])),x=new Set((o??[]).map(d=>d.key)),h=o?t.filter(d=>!x.has(d.key)):[],c=t.filter(d=>d.enabled).length,f=(d,p)=>{const j=u.get(d.key);if(j){a(j.id,p);return}n([{id:crypto.randomUUID(),key:d.key,name:d.name,description:d.description,...d.version?{version:d.version}:{},source:d.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:[s("Claude Code plugins"),e.jsx(Ze,{}),c>0&&e.jsx("span",{className:"ml-2 font-normal text-muted-foreground text-xs",children:s("{{count}} enabled",{count:c})})]}),e.jsx("p",{className:"text-muted-foreground text-sm",children:s("Plugins installed in Claude Code. Each one is switched on or off as a whole here; changes apply to new sessions.")})]}),e.jsxs(y,{variant:"outline",size:"sm",onClick:m,disabled:o===null,children:[e.jsx(ns,{className:"mr-1.5 h-4 w-4"}),s("Rescan")]})]}),o===null?e.jsx("div",{className:"flex justify-center py-10",children:e.jsx(Ps,{className:"size-5"})}):o.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx(Xs,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:s("No Claude Code plugins found")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:s("Install plugins with /plugin in Claude Code, then rescan.")})]}):e.jsx("div",{className:"space-y-2",children:o.map(d=>e.jsx(Tp,{plugin:d,entry:u.get(d.key),onToggle:p=>f(d,p)},d.key))}),h.length>0&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"font-medium text-muted-foreground text-xs",children:s("No longer installed in Claude Code")}),h.map(d=>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:d.name}),e.jsx(y,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-destructive",onClick:()=>r(d.id),children:e.jsx(Pe,{className:"h-3.5 w-3.5"})})]},d.id))]})]})}const Ys={mask:"Mask",warn:"Warn only",block:"Block"},Op={email:"Email",phone:"Phone number",idCard:"ID card number",bankCard:"Bank card number",ip:"IP address"},pn={mask:"text-sky-600 dark:text-sky-400",warn:"text-amber-600 dark:text-amber-400",block:"text-red-600 dark:text-red-400"},Dp=[1,7,30],Lp={1:"Today",7:"7D",30:"30D"};function zp(s){const t=new Map;for(const n of s.report.hits){const a=t.get(n.token);a?a.count+=n.count:t.set(n.token,{label:`${n.kind} ${n.preview}`,count:n.count})}return[...t.values()].map(n=>n.count>1?`${n.label} ×${n.count}`:n.label).join(", ")}function Ht({value:s,onChange:t}){const{t:n}=R(),a=Object.fromEntries(Object.keys(Ys).map(r=>[r,n(Ys[r])]));return e.jsxs(ne,{items:a,value:s,onValueChange:r=>t(r),children:[e.jsx(ae,{className:"w-32",children:e.jsx(re,{})}),e.jsx(oe,{children:Object.entries(a).map(([r,o])=>e.jsx(Z,{value:r,children:o},r))})]})}function qt({label:s,hint:t,value:n,onCommit:a,rowId:r}){const[o,i]=l.useState(n.join(`
18
+ `));return l.useEffect(()=>i(n.join(`
19
+ `)),[n]),e.jsxs("div",{className:"space-y-1.5","data-settings-row":r,children:[e.jsx("p",{className:"text-sm",children:s}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t}),e.jsx(Xe,{rows:3,value:o,onChange:m=>i(m.target.value),onBlur:()=>a(o.split(`
20
+ `))})]})}function Ts({title:s,children:t}){return e.jsxs("div",{className:"space-y-3 rounded-md border p-3",children:[e.jsx("p",{className:"text-sm font-medium",children:s}),t]})}function _p({settings:s}){const{t}=R(),[n,a]=l.useState(""),r=l.useMemo(()=>Gc(n,s),[n,s]);return e.jsxs(Ts,{title:t("Try it"),children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Runs locally. Nothing is remembered or sent anywhere.")}),e.jsx(Xe,{rows:3,value:n,placeholder:t("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:K("font-medium",pn[o.action]),children:t(Ys[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:t("Nothing matched")})]})]})]})}function Fp(){const{t:s}=R(),[t,n]=l.useState(7),[a,r]=l.useState(null),[o,i]=l.useState(!1),m=l.useRef(0),u=Kc(f=>f.conversations),x=l.useCallback(async f=>{const d=++m.current;i(!0);const p=await window.electronAPI.privacyMask.records(f).catch(()=>[]);d===m.current&&(i(!1),r(p))},[]);l.useEffect(()=>{x(t)},[t,x]);const h=l.useMemo(()=>{const f={mask:0,warn:0,block:0},d=new Map;for(const p of a??[]){const j=new Set;for(const b of p.report.hits){const A=`${b.action}:${b.token}`;j.has(A)||(j.add(A),f[b.action]+=1,d.set(b.kind,(d.get(b.kind)??0)+1))}}return{byAction:f,byKind:[...d].sort((p,j)=>j[1]-p[1])}},[a]),c=f=>{if(f.source==="aux")return s("Auxiliary request");const d=f.sessionId?u[f.sessionId]?.title:void 0,p=f.source==="compaction"?s("Compaction"):s("Session");return d?`${p} · ${d}`:p};return e.jsxs(Ts,{title:s("Records"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"flex gap-1",children:Dp.map(f=>e.jsx(y,{size:"sm",variant:f===t?"secondary":"ghost",onClick:()=>n(f),children:s(Lp[f])},f))}),e.jsx(y,{variant:"ghost",size:"icon-sm",onClick:()=>{x(t)},disabled:o,"aria-label":s("Refresh"),children:e.jsx(ns,{className:K("size-4",o&&"animate-spin")})})]}),e.jsx("div",{className:"flex flex-wrap gap-4 text-sm",children:Object.keys(Ys).map(f=>e.jsxs("span",{children:[e.jsx("span",{className:pn[f],children:s(Ys[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,d])=>e.jsxs("span",{className:"rounded bg-muted px-1.5 py-0.5",children:[f," ",d]},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:s("Requested at")}),e.jsx("th",{className:"py-1 pr-2 font-normal",children:s("Source")}),e.jsx("th",{className:"py-1 pr-2 font-normal",children:s("Model")}),e.jsx("th",{className:"py-1 font-normal",children:s("Hits")})]})}),e.jsx("tbody",{children:(a??[]).slice(0,200).map(f=>{const d=Wc(f.report),p=`${f.at}:${f.sessionId??f.source}:${f.model}:${f.report.hits.map(j=>j.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:c(f)}),e.jsx("td",{className:"py-1 pr-2 break-all",children:f.model}),e.jsxs("td",{className:K("py-1",d&&pn[d]),children:[zp(f),f.report.blocked&&` · ${s("Request blocked")}`]})]},p)})})]}),a?.length===0&&e.jsx("p",{className:"py-4 text-center text-xs text-muted-foreground",children:s("No records yet")})]})]})}function Bp(){const{t:s}=R(),t=g(r=>r.privacyMasking),n=g(r=>r.setPrivacyMasking),a=r=>n({...t,...r});return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("Privacy")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("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(Ie,{rowId:"privacy.enabled",title:s("Privacy masking"),description:s("Applies to chats, compaction, bot members and helper requests."),checked:t.enabled,onChange:r=>a({enabled:r})}),t.enabled&&e.jsxs(e.Fragment,{children:[e.jsxs(Ts,{title:s("Secrets"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:s("API keys, tokens, private keys, passwords in URLs and config files.")}),e.jsx(Ht,{value:t.secrets.action,onChange:r=>a({secrets:{...t.secrets,action:r}})})]}),e.jsx(Ie,{rowId:"privacy.secrets",title:s("Detect secrets"),description:s("Recommended. Covers common vendor key formats."),checked:t.secrets.enabled,onChange:r=>a({secrets:{...t.secrets,enabled:r}})}),e.jsx(Ie,{rowId:"privacy.shape",title:s("Send look-alike keys"),description:s("Replace keys with fake keys of the same format instead of placeholders, so the model treats them as real keys."),checked:t.secrets.shape,onChange:r=>a({secrets:{...t.secrets,shape:r}})})]}),e.jsxs(Ts,{title:s("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:s("Emails, phone numbers, ID and bank card numbers, IP addresses.")}),e.jsx(Ht,{value:t.personal.action,onChange:r=>a({personal:{...t.personal,action:r}})})]}),e.jsx(Ie,{rowId:"privacy.personal",title:s("Detect personal data"),description:s("Matches are validated (checksums, real domains) to limit false hits."),checked:t.personal.enabled,onChange:r=>a({personal:{...t.personal,enabled:r}})}),t.personal.enabled&&e.jsx("div",{className:"flex flex-wrap gap-4",children:Vc.map(r=>e.jsxs("label",{className:"flex items-center gap-1.5 text-sm",children:[e.jsx(Le,{checked:t.personal.kinds.includes(r),onCheckedChange:o=>a({personal:{...t.personal,kinds:o?[...t.personal.kinds,r]:t.personal.kinds.filter(i=>i!==r)}})}),s(Op[r])]},r))})]}),e.jsxs(Ts,{title:s("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:s("Words and patterns specific to your work.")}),e.jsx(Ht,{value:t.custom.action,onChange:r=>a({custom:{...t.custom,action:r}})})]}),e.jsx(qt,{rowId:"privacy.words",label:s("Words"),hint:s("One per line, case-insensitive. Project codenames, customer names…"),value:t.custom.words,onCommit:r=>a({custom:{...t.custom,words:r}})}),e.jsx(qt,{rowId:"privacy.rules",label:s("Prefixes or patterns"),hint:s("One per line. A prefix like corp_ or a regex like /INC-\\d{4}/i."),value:t.custom.rules,onCommit:r=>a({custom:{...t.custom,rules:r}})})]}),e.jsx(Ts,{title:s("Allow list"),children:e.jsx(qt,{rowId:"privacy.allow",label:s("Never mask"),hint:s("Exact values, one per line. Team emails, test keys…"),value:t.allow,onCommit:r=>a({allow:r})})}),e.jsx(_p,{settings:t})]}),e.jsx(Fp,{})]})}function Up(){const{t:s}=R(),t=g(d=>d.approvalReviewer),n=g(d=>d.setApprovalReviewer),a=g(d=>d.approvalAutoManage),r=g(d=>d.setApprovalAutoManage),o=Hc(g(d=>d.approvalAllowThreshold)),i=g(d=>d.setApprovalAllowThreshold),m={"0.85":s("0.85 (looser)"),"0.9":s("0.9 (default)"),"0.95":s("0.95 (stricter)")},u=es(),x=Rn(),h=l.useMemo(()=>[...u,...x.filter(ln)],[u,x]),c=t?h.find(d=>d.id===t.providerId):void 0,f=c?.models.find(d=>d.id===t?.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:s("Assistant approval model")}),e.jsx("p",{className:"mt-0.5 text-muted-foreground text-xs",children:s("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:c?.id??"",modelId:f?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:s("No assistant approval model selected"),side:"bottom",triggerClassName:Qe,onSelect:(d,p)=>n({providerId:d,modelId:p}),onReasoningChange:()=>{},onThinkingChange:()=>{}})}),c&&ln(c)&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:s(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:s("Auto-manage approvals")}),e.jsx(ce,{"aria-label":s("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:s("Auto-allow threshold")}),e.jsxs(ne,{items:m,value:String(o),onValueChange:d=>i(Number(d)),children:[e.jsx(ae,{className:"w-36","aria-label":s("Auto-allow threshold"),children:e.jsx(re,{})}),e.jsx(oe,{children:qc.map(d=>e.jsx(Z,{value:String(d),children:m[String(d)]},d))})]})]}),e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Only runs automatically when the allow probability reaches this value. Operations near the threshold may be allowed one time and not the next.")})]}),t&&(!c||!f)&&e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Selected model is unavailable")}),t&&e.jsx(y,{variant:"ghost",size:"sm",className:"self-start",onClick:()=>n(null),children:s("Clear")})]})}function pr(s,t){const n=t.find(r=>r.id===s.providerId),a=n?.models.find(r=>r.id===s.modelId);return`${n?.name??s.providerId} / ${a?.label??s.modelId}`}function $p(){const{t:s}=R(),t=et(),n=g(M=>M.virtualModels),a=g(M=>M.defaultModel),r=g(M=>M.setDefaultModel),o=g(M=>M.defaultModelFollowLast),i=g(M=>M.setDefaultModelFollowLast),m=g(M=>M.defaultReasoningEnabled),u=g(M=>M.defaultThinkingLevel),x=g(M=>M.setDefaultReasoningEnabled),h=g(M=>M.setDefaultThinkingLevel),c=jt(M=>M.snapshot),f=Yc(M=>M.latest),d=es(),p=a?d.find(M=>M.id===a.providerId):void 0,j=p?.models.find(M=>M.id===a?.modelId),b=t.some(M=>!!M.oauthAccountKey),A=b&&(c.availability.status==="unloaded"||c.availability.status==="loading"),v=b&&c.availability.status==="error"?c.availability.error:null,k=f?.notice,I=k?s("Default model changed: {{previous}} → {{next}}",{previous:pr(k.previous,t),next:k.next?pr(k.next,t):s("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:s("Default model")}),e.jsx("p",{className:"mt-0.5 text-muted-foreground text-xs",children:s(o?"New conversations use the last model you picked.":"Used for new conversations.")})]}),d.length>0&&e.jsx("div",{className:"w-full min-w-0",children:e.jsx(ze,{providers:d,virtualModels:n,providerId:p?.id??a?.providerId??"",modelId:j?.id??a?.modelId??"",reasoningEnabled:m,thinkingLevel:u,emptyLabel:s("Select model"),triggerLabel:o?s("Follow last selection"):void 0,side:"bottom",triggerClassName:Qe,onSelect:(M,$)=>r({providerId:M,modelId:$}),onReasoningChange:x,onThinkingChange:h,showReasoningControls:!o})}),!o&&d.length>0&&e.jsx(y,{type:"button",variant:"ghost",size:"sm",className:"self-start",onClick:()=>i(!0),children:s("Follow last selection")}),d.length===0&&e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-5 text-center",children:[e.jsx(_n,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-2 font-medium text-sm",children:s("No usable models")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:s("Enable a model and configure valid provider credentials first.")})]}),(A||v)&&e.jsxs("div",{className:"flex items-start gap-2 rounded-md bg-muted px-2.5 py-2 text-xs",children:[e.jsx(Rs,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:v?s("Subscription credentials could not be loaded: {{error}}",{error:v}):s("Subscription credentials are loading. API-key models remain available.")})]}),I&&e.jsx("p",{className:"rounded-md bg-muted px-2.5 py-2 text-muted-foreground text-xs",children:I})]})}function Vp(){const{t:s}=R(),t=Qu(et()),n=g(o=>o.imageGenerationModel),a=n===null||t.some(o=>o.id===n.providerId&&o.models.some(i=>i.id===n.modelId)),r=g(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:s("Default image generation model")}),t.length>0?e.jsx(ze,{providers:t,providerId:n?.providerId??"",modelId:n?.modelId??"",reasoningEnabled:!1,thinkingLevel:"medium",emptyLabel:s("Select model"),side:"bottom",triggerClassName:Qe,onSelect:(o,i)=>r({providerId:o,modelId:i}),onReasoningChange:()=>{},onThinkingChange:()=>{},showReasoningControls:!1}):e.jsx("p",{className:"text-muted-foreground text-xs",children:s("No image generation models available")}),!a&&e.jsx("p",{className:"text-destructive text-xs",children:s("Selected image generation model is unavailable")}),n&&e.jsx(y,{type:"button",variant:"ghost",size:"sm",onClick:()=>r(null),children:s("Clear selection")})]})}function Gp({provider:s,onClose:t}){const{t:n}=R(),a=g(j=>j.providers),r=g(j=>j.updateProvider),o=vo(j=>j.snapshot),i=l.useMemo(()=>bo([s],o)[0]?.models??s.models,[s,o]),m=jt(j=>j.snapshot.availability),u=jt(j=>j.snapshot.revision),[x,h]=l.useState([]),[c,f]=l.useState(s.oauthAccountPool?.accountKeys??[]);l.useEffect(()=>{let j=!1;return window.electronAPI.providers.listOauth().then(b=>{j||h(b)}).catch(b=>{j||(h([]),console.error("Failed to load OAuth account metadata",b))}),()=>{j=!0}},[u]);const d=Co(a),p=[...d.flatMap(j=>j.oauthAccountKey??[]),...c.filter(j=>!d.some(b=>b.oauthAccountKey===j))];return e.jsx(yo,{initialValue:{...s,name:Fn(s,n),models:i},oauth:!0,hideName:!0,saveDisabled:c.length===0,oauthAccountKey:s.oauthAccountKey,onCancel:t,extraFields:e.jsxs(he,{children:[e.jsx(pe,{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((j,b)=>{const A=d.find(k=>k.oauthAccountKey===j),v=x.flatMap(k=>k.accounts).find(k=>k.key===j);return e.jsxs("label",{className:"flex min-w-0 items-center gap-2 px-2 py-1.5 text-sm",children:[e.jsx(Le,{checked:c.includes(j),onCheckedChange:k=>f(I=>k?[...I,j]:I.filter(M=>M!==j))}),e.jsxs("span",{className:"shrink-0 text-xs text-muted-foreground",children:[b+1,"."]}),e.jsx("span",{className:"min-w-0 truncate",children:v?.email??j}),!A?.enabled&&e.jsx("span",{className:"shrink-0 text-xs text-muted-foreground",children:n("Account disabled")}),m.status==="ready"&&!m.authenticatedAccountKeys.has(j)&&e.jsx("span",{className:"shrink-0 text-xs text-muted-foreground",children:n("Account signed out")})]},j)})})]}),onSave:j=>{c.length!==0&&(r(s.id,{models:wo(j.models,ko(o,s.oauthAccountKey??"")?.models,No(g.getState(),s.id)),oauthAccountPool:{accountKeys:p.filter(b=>c.includes(b))}}),t())}})}function Kp({provider:s,onClose:t}){const{t:n}=R(),a=g(i=>i.updateProvider),r=vo(i=>i.snapshot),o=l.useMemo(()=>s?.oauthAccountKey?bo([s],r)[0]?.models??s.models:s?.models,[s,r]);return e.jsx(ye,{open:s!==null,onOpenChange:i=>!i&&t(),children:e.jsxs(we,{children:[e.jsx(Ne,{children:e.jsx(ke,{children:s?.oauthAccountPool?Fn(s,n):n("Edit Provider")})}),s?.oauthAccountPool?e.jsx(Gp,{provider:s,onClose:t},s.id):s&&e.jsx(yo,{initialValue:{name:s.name,api:s.api,apiKey:s.apiKey,baseUrl:s.baseUrl,models:o??s.models,headers:s.headers},oauth:!!s.oauthAccountKey,oauthAccountKey:s.oauthAccountKey,onCancel:t,onSave:i=>{a(s.id,s.oauthAccountKey?{name:i.name,models:wo(i.models,ko(r,s.oauthAccountKey)?.models,No(g.getState(),s.id))}:i),t()}},s.id)]})})}const Wp=(s,t)=>s.models.some(n=>n.id===t&&n.enabled!==!1),fr=()=>{};function gr(s){return s==="on"||s==="off"}function Yt(s){return typeof s=="string"&&ed.includes(s)}function Hp(){const{t:s}=R(),t=g(c=>c.subagentModelsEnabled),n=g(c=>c.subagentModels),a=g(c=>c.setSubagentModelsEnabled),r=g(c=>c.addSubagentModel),o=g(c=>c.updateSubagentModel),i=g(c=>c.removeSubagentModel),m=g(c=>c.defaultModel),u=g(c=>c.virtualModels),x=es(),h=l.useMemo(()=>{if(m&&Jc(m)){const c=Xc(u,x).find(f=>f.id===m.modelId);if(c)return{providerId:Qc,modelId:c.id}}if(m){const c=x.find(f=>f.id===m.providerId);if(c&&Wp(c,m.modelId))return m}for(const c of x){const f=c.models.find(d=>d.enabled!==!1);if(f)return{providerId:c.id,modelId:f.id}}return null},[x,m,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:s("Let the agent pick subagent models")}),e.jsx("p",{className:"mt-0.5 text-muted-foreground text-xs",children:s("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:s("Applies to newly started conversations.")})]}),e.jsx(ce,{className:"shrink-0",checked:t,onCheckedChange:a})]}),t&&e.jsxs("div",{className:"space-y-1.5",children:[n.map(c=>e.jsxs("div",{"data-slot":"subagent-model-row",className:K("flex items-center gap-2 rounded-md border px-2 py-1.5",c.enabled===!1&&"bg-muted/50 text-muted-foreground"),children:[e.jsx(ce,{"data-slot":"subagent-model-enabled","aria-label":s("Enable subagent model"),title:s("Make this model available to subagents"),checked:c.enabled!==!1,onCheckedChange:f=>o(c.id,{enabled:f})}),c.enabled===!1&&e.jsx(se,{variant:"outline",className:"shrink-0 text-[10px] text-muted-foreground",children:s("Disabled")}),e.jsx("div",{className:"shrink-0 rounded-md border bg-background",children:e.jsx(ze,{providers:x,virtualModels:u,providerId:c.providerId,modelId:c.modelId,modelCapabilityOverrides:Zc(c),reasoningMode:gr(c.reasoning)?c.reasoning:"follow",reasoningEnabled:c.reasoning==="on",thinkingLevel:Yt(c.thinkingLevel)?c.thinkingLevel:"medium",onReasoningModeChange:(f,d)=>{f==="follow"?o(c.id,{reasoning:void 0,thinkingLevel:void 0}):f==="on"&&!Yt(c.thinkingLevel)?o(c.id,{reasoning:"on",thinkingLevel:d}):o(c.id,{reasoning:f})},onSelect:(f,d)=>o(c.id,{providerId:f,modelId:d}),onReasoningChange:f=>o(c.id,{reasoning:f?"on":"off"}),onThinkingChange:f=>o(c.id,{thinkingLevel:f}),onReasoningNormalize:gr(c.reasoning)?f=>o(c.id,{reasoning:f?"on":"off"}):fr,onThinkingNormalize:Yt(c.thinkingLevel)?f=>o(c.id,{thinkingLevel:f}):fr})}),e.jsx(J,{value:c.description,placeholder:s("When to use it, e.g. cheap and fast for simple subtasks"),className:"h-7 flex-1 text-xs",onChange:f=>o(c.id,{description:f.target.value})}),e.jsx(y,{type:"button",variant:"ghost",size:"icon",className:"h-6 w-6 shrink-0 text-muted-foreground hover:text-destructive",onClick:()=>i(c.id),children:e.jsx(Pe,{className:"h-3.5 w-3.5"})})]},c.id)),e.jsxs(y,{type:"button",variant:"outline",size:"sm",className:"h-7 text-xs",disabled:!h,onClick:()=>{h&&r({...h,description:""})},children:[e.jsx(Re,{className:"mr-1 h-3.5 w-3.5"}),s("Add model")]}),!h&&e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Enable a model and configure valid provider credentials first.")})]})]})}function qp(){const{t:s}=R(),t=g(u=>u.titleSummaryEnabled),n=g(u=>u.setTitleSummaryEnabled),a=g(u=>u.titleSummaryModel),r=g(u=>u.setTitleSummaryModel),o=es(),i=a?o.find(u=>u.id===a.providerId):void 0,m=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:s("Conversation title summary")}),e.jsx("p",{className:"mt-0.5 text-muted-foreground text-xs",children:s("Generate a short AI title from the first message of a new conversation.")})]}),e.jsx(ce,{checked:t,onCheckedChange:n})]}),t&&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:m?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:s("Follows the default model"),side:"bottom",triggerClassName:Qe,onSelect:(u,x)=>r({providerId:u,modelId:x}),onReasoningChange:()=>{},onThinkingChange:()=>{}})}),a&&(!i||!m)&&e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Selected model is unavailable — falls back to the default model.")}),a&&e.jsx(y,{variant:"ghost",size:"sm",className:"self-start",onClick:()=>r(null),children:s("Follow default model")})]})]})}function Yp({accountKey:s}){const t=md(s);return!t||t.error?null:e.jsx(xd,{info:t})}function Jp(){const{t:s}=R(),t=g(U=>U.providers),n=et(),a=g(U=>U.updateProvider),r=g(U=>U.addProviders),o=g(U=>U.removeProvider),[i,m]=l.useState(!1),[u,x]=l.useState(!1),[h,c]=l.useState(null),[f,d]=l.useState(null),[p,j]=l.useState(null),[b,A]=l.useState(null),[v,k]=l.useState(!1),[I,M]=l.useState(!1),[$,E]=l.useState(null),L=jt(U=>U.snapshot.revision),[T,C]=l.useState([]);l.useEffect(()=>{let U=!1;return window.electronAPI.providers.listOauth().then(B=>{U||C(B)}),()=>{U=!0}},[L]);const S=l.useMemo(()=>sd(t,T),[t,T]),W=l.useMemo(()=>{const U=new Map;for(const B of n)U.set(B.id,B.models.length);return U},[n]),q=async(U,B)=>{if(j(U.id),A(null),U.oauthAccountKey&&!U.oauthAccountPool&&!B?.skipLogout)try{await window.electronAPI.providers.oauthLogout(U.oauthAccountKey),await hd()}catch(ie){j(null),A({providerId:U.id,message:ie instanceof Error?ie.message:String(ie)});return}o(U.id),j(null),A(null)},N=()=>{const U=f;U&&q(U)},z=async()=>{k(!0),E(null);try{const U=await dd(t);ud(U,a),E(U);const B=Object.values(U).filter(F=>F.status==="failed"),ie=Object.keys(U).length-B.length;Te({type:B.length>0?"warning":"success",title:s("Fetched {{count}} providers",{count:ie}),...B.length>0?{description:s("{{count}} failed",{count:B.length})}:{}})}finally{k(!1)}},H=async()=>{M(!0);try{const U=await window.electronAPI.providers.refreshModelCatalog();cd(),Te({type:U.ok?"success":"warning",title:U.ok?s("Model info updated"):U.fromCache?s("Model info refresh failed, using cache"):s("Model info refresh failed")})}catch{Te({type:"error",title:s("Model info refresh failed")})}finally{M(!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:[s("Model Providers"),e.jsx(Ze,{note:s("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:s("Manage model API providers for this app")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(y,{variant:"outline",size:"sm",disabled:I,onClick:()=>{H()},children:[I?e.jsx(Me,{className:"mr-1.5 h-4 w-4 animate-spin"}):e.jsx(ns,{className:"mr-1.5 h-4 w-4"}),s("Refresh model info")]}),e.jsxs(y,{variant:"outline",size:"sm",disabled:v||t.length===0,onClick:()=>{z()},children:[v?e.jsx(Me,{className:"mr-1.5 h-4 w-4 animate-spin"}):e.jsx(ns,{className:"mr-1.5 h-4 w-4"}),s("Fetch all models")]}),e.jsxs(y,{variant:"outline",size:"sm",onClick:()=>m(!0),children:[e.jsx(Nt,{className:"h-4 w-4 mr-1.5"}),s("Import from local apps")]}),e.jsxs(y,{size:"sm",onClick:()=>x(!0),children:[e.jsx(Re,{className:"h-4 w-4 mr-1.5"}),s("Add model or provider")]})]})]}),e.jsx($p,{}),e.jsx(Vp,{}),e.jsx(mx,{}),e.jsx(qp,{}),e.jsx(Up,{}),e.jsx(Hp,{}),Co(t).length>0&&!t.some(U=>U.oauthAccountPool)&&e.jsxs("div",{className:"space-y-1.5 rounded-md border p-3",children:[e.jsxs(y,{variant:"outline",size:"sm",onClick:()=>{const U=td(t,crypto.randomUUID());U&&r([U])>0&&c(U)},children:[e.jsx(Re,{className:"mr-1.5 h-3.5 w-3.5"}),s("Create ChatGPT account pool")]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Pool entries do not show a single account quota. Fixed-account entries remain unchanged.")})]}),t.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 text-sm font-medium",children:s("No providers yet")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:s("Import providers from local apps or use the unified setup to get started")})]}):e.jsx("div",{className:"space-y-1",children:S.map(U=>{const B=T.find(F=>F.id===U.vendorId),ie=U.vendorId===nd?s("Custom"):U.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:ie}),e.jsx("span",{className:"text-[11px] text-muted-foreground/60",children:U.providers.length})]}),e.jsx("div",{className:"mt-1.5 space-y-1 border-l pl-3",children:U.providers.map(F=>{const X=!!F.oauthAccountKey,V=W.get(F.id)??F.models.length,le=F.oauthAccountKey&&!F.oauthAccountPool?B?.accounts.find(ue=>ue.key===F.oauthAccountKey):void 0,_=F.oauthAccountPool?Fn(F,s):X?le?.email??F.oauthAccountKey??F.name:F.name,de=$?.[F.id];return e.jsxs(l.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.${F.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:[X?e.jsx(ad,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}):e.jsx(rd,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx("span",{className:K("truncate text-sm font-medium",!F.enabled&&"text-muted-foreground line-through"),children:_}),X?le?.plan&&e.jsx(se,{variant:"outline",className:"shrink-0 text-[10px] uppercase",children:le.plan}):e.jsx(se,{variant:"outline",className:"shrink-0 text-[11px]",children:od[F.api]??F.api}),F.importedFrom&&e.jsx(se,{variant:"secondary",className:"shrink-0 text-[11px]",children:F.importedFrom}),e.jsx("span",{className:"min-w-0 truncate text-xs text-muted-foreground",children:[X?void 0:F.baseUrl,F.oauthAccountPool?s("{{count}} accounts",{count:F.oauthAccountPool.accountKeys.length}):void 0,V>0?s("{{count}} models",{count:V}):void 0].filter(Boolean).join(" · ")})]}),ln(F)&&e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:s("Classification only, not for chat")}),F.oauthAccountKey&&!F.oauthAccountPool&&e.jsx(Yp,{accountKey:F.oauthAccountKey})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1 pt-0.5",children:[e.jsx(y,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",onClick:()=>c(F),children:e.jsx(hs,{className:"h-3.5 w-3.5"})}),e.jsx(y,{variant:"ghost",size:"icon",disabled:p===F.id,className:K("h-7 w-7 text-muted-foreground opacity-0 transition-opacity hover:text-destructive group-hover:opacity-100",p===F.id&&"opacity-100"),onClick:()=>d(F),children:p===F.id?e.jsx(Me,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Pe,{className:"h-3.5 w-3.5"})}),e.jsx(ce,{checked:F.enabled,onCheckedChange:ue=>a(F.id,{enabled:ue})})]})]}),b?.providerId===F.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:s("Sign-out failed: {{message}}",{message:b.message})}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(y,{variant:"outline",size:"sm",className:"h-6 px-2 text-[11px]",onClick:()=>{q(F)},children:s("Retry")}),e.jsx(y,{variant:"ghost",size:"sm",className:"h-6 px-2 text-[11px] text-destructive hover:text-destructive",onClick:()=>{q(F,{skipLogout:!0})},children:s("Delete anyway")})]})]}),de?.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:[s("Fetch failed"),": ",de.message]})})]},F.id)})})]},U.vendorId)})}),e.jsx(id,{open:i,onOpenChange:m}),e.jsx(ld,{open:u,onOpenChange:x}),e.jsx(Kp,{provider:h,onClose:()=>c(null)}),e.jsx(Gr,{open:f!==null,onOpenChange:U=>{U||d(null)},title:s("Remove provider?"),description:f?f.oauthAccountKey&&!f.oauthAccountPool?s("Removing this also signs out {{name}}. Other accounts for the same vendor stay signed in.",{name:f.name}):s('This permanently deletes the "{{name}}" provider configuration.',{name:f.name}):void 0,confirmLabel:s("Remove"),onConfirm:N})]})}const Xp=2e3,jr=50,Vs="",Qp=[{id:"app",label:"App processes"},{id:"agent",label:"Agent and tools"},{id:"child",label:"Other child processes"}],fn={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 Zp(s,t){switch(s){case"main":return t("Main process");case"window":return t("Window");case"browser":return t("Built-in browser");case"gpu":return"GPU";case"service":return t("Service");case"agent":return"Agent";case"tool":return t("Tool");default:return t("Child process")}}function ef(s,t){return s.id==="data"?t("App data"):t("Worktree directory")}function sf(s,t){return s.role!=="window"?s.name:s.name==="Main window"?t("Main window"):s.name==="Settings"?t("Settings"):s.name}function tf(s){return`${s.toFixed(1)}%`}function nf(){const{t:s}=R(),[t,n]=l.useState("cpu");return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("Resources")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("CPU, memory and disk usage of EnsoCode and the processes it started.")})]}),e.jsxs(Qs,{value:t,onValueChange:a=>n(a),children:[e.jsxs(Zs,{children:[e.jsx(Je,{value:"cpu",children:"CPU"}),e.jsx(Je,{value:"memory",children:s("RAM")}),e.jsx(Je,{value:"storage",children:s("Storage")})]}),e.jsx(Ws,{value:"cpu",className:"pt-4",children:t==="cpu"&&e.jsx(vr,{metric:"cpu"})}),e.jsx(Ws,{value:"memory",className:"pt-4",children:t==="memory"&&e.jsx(vr,{metric:"memory"})}),e.jsx(Ws,{value:"storage",className:"pt-4",children:t==="storage"&&e.jsx(rf,{})})]})]})}function vr({metric:s}){const{t}=R(),[n,a]=l.useState(null),[r,o]=l.useState(null);if(l.useEffect(()=>{let x=!1,h;const c=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(c,Xp))};return c(),()=>{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:t("Loading...")});const i=s==="cpu"?tf:me,m=s==="cpu"?{app:n.cpu.app,system:n.cpu.system,total:100}:n.memory,u=x=>s==="cpu"?x.cpu:x.memory;return e.jsxs("div",{className:"space-y-4",children:[e.jsx(oi,{app:m.app,system:Math.max(m.system,m.app),total:m.total,format:i}),Qp.map(x=>{const h=n.processes.filter(c=>c.group===x.id).sort((c,f)=>u(f)-u(c));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:t(x.label)}),e.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:i(h.reduce((c,f)=>c+u(f),0))})]}),e.jsx("div",{className:"divide-y",children:h.map(c=>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:Zp(c.role,t)}),e.jsx("span",{className:"min-w-0 flex-1 truncate",title:c.command??c.name,children:sf(c,t)}),e.jsx("span",{className:"w-16 text-right font-mono text-xs text-muted-foreground",children:c.pid}),e.jsx("span",{className:"w-20 text-right font-mono text-xs",children:i(u(c))})]},c.pid))})]},x.id)})]})}function oi({app:s,system:t,total:n,format:a}){const{t:r}=R(),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(s)})]}),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(t)," / ",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(t)}}),e.jsx("div",{className:"absolute inset-y-0 left-0 bg-foreground",style:{width:o(s)}})]})]})}function af(s,t){const n=[t("Freed {{size}}",{size:me(s.freedBytes)})];return s.removed>0&&n.push(t("{{count}} files removed",{count:s.removed})),s.skipped>0&&n.push(t("{{count}} kept",{count:s.skipped})),s.failed>0&&n.push(t("{{count}} failed",{count:s.failed})),n.join(" · ")}function rf(){const{t:s}=R(),[t,n]=l.useState(null),[a,r]=l.useState("scan"),[o,i]=l.useState(null),[m,u]=l.useState(null),[x,h]=l.useState(null),[c,f]=l.useState(null),d=l.useCallback(async(v,k)=>{r(v),u(null),i(null);try{n(await k())}catch(I){const M=I instanceof Error?I.message:String(I);M.includes("Scan cancelled")||u(M)}finally{r(null),i(null)}},[]),p=l.useCallback(()=>d("scan",()=>window.electronAPI.resources.scanStorage()),[d]),j=v=>d(v,async()=>{const k=await window.electronAPI.resources.cleanStorage(v);return Te({type:k.failed>0?"warning":"success",title:s("{{name}} cleaned",{name:s(fn[v][0])}),description:af(k,s)}),k.snapshot});l.useEffect(()=>{const v=window.electronAPI.resources.onScanProgress(i);return window.electronAPI.resources.lastStorage().then(k=>{k&&n(I=>I??k)}),p(),()=>{v(),window.electronAPI.resources.cancelScan()}},[p]);const b=t?[...t.categories].filter(v=>v.bytes>0).sort((v,k)=>k.bytes-v.bytes):[],A=l.useMemo(()=>{const v=new Map;for(const k of t?.roots??[])v.set(k.volumeId,[...v.get(k.volumeId)??[],k]);return[...v.values()]},[t]);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?s("Scanning {{count}} files · {{size}}",{count:o.files.toLocaleString(),size:me(o.bytes)}):s("Scanning..."):t?s("Scanned at {{time}} · took {{seconds}}s",{time:new Date(t.scannedAt).toLocaleTimeString(),seconds:(t.durationMs/1e3).toFixed(1)}):null}),a==="scan"?e.jsx(y,{variant:"ghost",size:"sm",onClick:()=>{window.electronAPI.resources.cancelScan()},children:s("Cancel")}):e.jsx(y,{variant:"ghost",size:"icon-sm",onClick:()=>{p()},disabled:a!==null,"aria-label":s("Refresh"),children:e.jsx(ns,{})})]}),m&&e.jsx("p",{className:"text-sm text-destructive",children:m}),t&&t.errorCount>0&&e.jsxs("p",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",title:t.errors.join(`
21
+ `),children:[e.jsx(Ke,{className:"h-3.5 w-3.5"}),s("{{count}} paths could not be read and are not counted.",{count:t.errorCount})]}),t&&e.jsxs(e.Fragment,{children:[A.map(v=>{const k=v[0]?.volume,I=v.reduce((M,$)=>M+$.bytes,0);return e.jsxs("div",{className:"space-y-2",children:[k?e.jsx(oi,{app:I,system:k.total-k.free,total:k.total,format:me}):e.jsx("div",{className:"rounded-lg border p-4 font-mono text-2xl font-semibold",children:me(I)}),v.map(M=>e.jsxs("div",{className:"flex items-center gap-2 px-1 text-xs",children:[e.jsx("span",{className:"shrink-0 text-muted-foreground",children:ef(M,s)}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono",title:M.path,children:M.path}),e.jsx("span",{className:"font-mono",children:me(M.bytes)})]},M.id))]},v[0]?.volumeId)}),e.jsx("div",{className:"divide-y rounded-lg border",children:b.map(v=>e.jsx(of,{category:v,share:t.totalBytes>0?v.bytes/t.totalBytes:0,expanded:x===v.id,onToggle:()=>h(x===v.id?null:v.id),cleaning:a===v.id,disabled:a!==null,onClean:()=>So[v.id]==="confirm"?f(v.id):void j(v.id)},v.id))}),e.jsx(lf,{sessions:t.sessions,busy:a==="sessions",disabled:a!==null,onClean:v=>d("sessions",async()=>{const k=await window.electronAPI.resources.cleanSessions(v);return Te({type:"success",title:s("{{count}} conversations deleted",{count:k.removed})}),k.snapshot})})]}),e.jsx(wn,{open:c!==null,onOpenChange:v=>!v&&f(null),children:e.jsxs(Nn,{className:"sm:max-w-md",zIndexLevel:"nested",children:[e.jsxs(kn,{children:[e.jsx(Cn,{className:"text-base",children:s("Clean {{name}}?",{name:c?s(fn[c][0]):""})}),e.jsx(Sn,{children:s(c==="browser"?"You will be signed out of sites opened in the built-in browser.":"Deleted files cannot be restored.")})]}),e.jsxs(In,{variant:"bare",children:[e.jsx(An,{render:e.jsx(y,{variant:"outline",size:"sm"}),children:s("Cancel")}),e.jsx(y,{variant:"destructive",size:"sm",onClick:()=>{const v=c;f(null),v&&j(v)},children:s("Clean")})]})]})})]})}function of({category:s,share:t,expanded:n,onToggle:a,cleaning:r,disabled:o,onClean:i}){const{t:m}=R(),[u,x]=fn[s.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(Ds,{className:K("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:m(u)}),e.jsx("span",{className:"font-mono text-xs",children:me(s.bytes)})]}),e.jsx("p",{className:"truncate text-xs text-muted-foreground",children:m(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:`${t*100}%`}})})]})]}),So[s.id]!=="none"&&e.jsx(y,{variant:"outline",size:"sm",disabled:o,onClick:i,children:m(r?"Cleaning...":"Clean")})]}),n&&e.jsx("div",{className:"mt-2 space-y-0.5 pl-6",children:s.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:`${m("Worktree directory")}/${h.path}`}),e.jsx("span",{className:"font-mono",children:me(h.bytes)}),e.jsx(y,{variant:"ghost",size:"icon-sm",className:"opacity-0 group-hover:opacity-100","aria-label":m("Show in folder"),onClick:()=>{window.electronAPI.resources.revealStorage(h.root,h.path)},children:e.jsx(Tn,{})})]},`${h.root}:${h.path}`))})]})}function lf({sessions:s,busy:t,disabled:n,onClean:a}){const{t:r}=R(),[o,i]=l.useState(!1),[m,u]=l.useState(!1),[x,h]=l.useState(null),[c,f]=l.useState(Vs),d=l.useMemo(()=>new Map(s.map(T=>[T.id,T])),[s]),p=l.useMemo(()=>{const T=new Map;for(const C of s){const S=T.get(C.projectId)??{name:C.projectName,bytes:0,count:0};S.bytes+=C.bytes,S.count+=1,T.set(C.projectId,S)}return[...T].sort((C,S)=>S[1].bytes-C[1].bytes)},[s]),j=p.some(([T])=>T===c)?c:Vs,b=j?s.filter(T=>T.projectId===j):s,A=T=>{const C=vd(s,T,Date.now());return{request:T,count:C.length,bytes:C.reduce((S,W)=>S+(d.get(W)?.bytes??0),0)}},v=T=>A({kind:"stale",days:T,includeUnarchived:o,...j?{projectId:j}:{}}),k=b.reduce((T,C)=>T+C.bytes,0),I=m?b:b.slice(0,jr),M=(T,C)=>C||(T?T.slice(0,8):r("No project")),$=x?.request.kind==="one"?d.get(x.request.id):void 0,E=x?.request.kind==="stale"?x.request.projectId:void 0,L=E===void 0?void 0:M(E,p.find(([T])=>T===E)?.[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:[b.length," · ",me(k)]})]}),e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsxs(ne,{items:{[Vs]:r("All projects"),...Object.fromEntries(p.map(([T,C])=>[T,M(T,C.name)]))},value:j,onValueChange:T=>f(T??Vs),children:[e.jsx(ae,{size:"sm",className:"w-48 min-w-0",children:e.jsx(re,{})}),e.jsxs(oe,{children:[e.jsx(Z,{value:Vs,children:r("All projects")}),p.map(([T,C])=>e.jsx(Z,{value:T,children:e.jsxs("span",{className:"flex w-full items-center gap-3",children:[e.jsx("span",{className:"flex-1 truncate",children:M(T,C.name)}),e.jsxs("span",{className:"font-mono text-xs text-muted-foreground",children:[C.count," · ",me(C.bytes)]})]})},T))]})]}),e.jsxs(Io,{children:[e.jsxs(Ao,{render:e.jsx(y,{variant:"outline",size:"sm",disabled:n||b.length===0}),children:[e.jsx(pd,{}),r(t?"Cleaning...":"Clean")]}),e.jsxs(Eo,{align:"end",className:"min-w-48",children:[e.jsx(fd,{checked:o,onCheckedChange:i,closeOnClick:!1,children:r("Include unarchived")}),e.jsx(gd,{}),[...jd,0].map(T=>{const C=v(T);return e.jsxs(Mo,{variant:"destructive",disabled:C.count===0,onClick:()=>h(C),children:[e.jsx("span",{className:"flex-1",children:T>0?r("Older than {{days}} days",{days:T}):r("All")}),e.jsx("span",{className:"font-mono text-xs opacity-70",children:C.count})]},T)})]})]})]})]}),e.jsx("div",{className:"max-h-96 divide-y overflow-y-auto",children:I.map(T=>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:T.title,children:T.title||r("Untitled")}),e.jsx("div",{className:"truncate text-xs text-muted-foreground",children:[T.projectName,T.archived?r("Archived"):null,new Date(T.lastActiveAt).toLocaleDateString()].filter(Boolean).join(" · ")})]}),e.jsx("span",{className:"font-mono text-xs",children:me(T.bytes)}),e.jsx(y,{variant:"ghost",size:"icon-sm",className:"opacity-0 group-hover:opacity-100",disabled:n,"aria-label":r("Delete"),onClick:()=>h({request:{kind:"one",id:T.id},count:1,bytes:T.bytes}),children:e.jsx(Pe,{})})]},T.id))}),b.length>jr&&e.jsx("button",{type:"button",onClick:()=>u(!m),className:"w-full border-t px-3 py-1.5 text-xs text-muted-foreground hover:text-foreground",children:r(m?"Show less":"Show all")}),e.jsx(wn,{open:x!==null,onOpenChange:T=>!T&&h(null),children:e.jsxs(Nn,{className:"sm:max-w-md",zIndexLevel:"nested",children:[e.jsxs(kn,{children:[e.jsx(Cn,{className:"text-base",children:$?r('Delete "{{title}}"?',{title:$.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(Sn,{children:[r("About {{size}} of history, tool output and isolated worktrees will be removed and cannot be restored.",{size:me(x?.bytes??0)}),!$&&` ${r("Open, running and waiting conversations are skipped.")}`]})]}),e.jsxs(In,{variant:"bare",children:[e.jsx(An,{render:e.jsx(y,{variant:"outline",size:"sm"}),children:r("Cancel")}),e.jsx(y,{variant:"destructive",size:"sm",onClick:()=>{const T=x?.request;h(null),T&&a(T)},children:r("Delete")})]})]})})]})}const ii={cropSource:null,busy:!1,problem:null};function cf(s,t){switch(t.type){case"pick":return{...s,cropSource:null,busy:!1,problem:t.problem};case"picked":return{cropSource:t.source,busy:!1,problem:null};case"read-failed":return{cropSource:null,busy:!1,problem:"read"};case"crop-cancelled":return{cropSource:null,busy:!1,problem:null};case"cropped":return t.tooLarge?{cropSource:null,busy:!1,problem:"size"}:{cropSource:null,busy:!0,problem:null};case"saving":return{cropSource:null,busy:!0,problem:null};case"saved":return ii;case"save-failed":return{cropSource:null,busy:!1,problem:"save"}}}const df=Array.from({length:bd-ya+1},(s,t)=>{const n=String(ya+t);return{value:n,label:n}}),uf={type:"Avatar images must be PNG, JPEG, WebP or GIF, and at most 2 MB.",size:"Avatar images must be PNG, JPEG, WebP or GIF, and at most 2 MB.",read:"This image cannot be used as an avatar.",save:"Could not save the secretary profile. Try again."};function Ks({value:s,options:t,onChange:n,enso:a}){const{t:r}=R();return e.jsx("div",{className:"flex flex-wrap gap-1","data-enso":a,children:t.map(o=>e.jsx("button",{type:"button","aria-pressed":o.value===s,onClick:()=>n(o.value),className:K("rounded-md border px-2.5 py-1 text-xs transition-colors",o.value===s?"border-primary/60 bg-primary/10 text-foreground":"border-border text-muted-foreground hover:bg-muted"),children:r(o.label)},o.value))})}function ss({title:s,description:t,rowId:n,children:a}){const{t:r}=R();return e.jsxs("section",{className:"space-y-3","data-settings-row":n,children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium",children:r(s)}),t?e.jsx("p",{className:"text-xs text-muted-foreground",children:r(t)}):null]}),a]})}function li(s,t){return s?new Date(s).toLocaleString(t==="zh"?"zh-CN":"en-US",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}):""}function mf({pluginIds:s,busy:t,onChange:n}){const{t:a}=R(),[r,o]=l.useState([]);l.useEffect(()=>{window.electronAPI.extensionPlugins.list().then(m=>o(m)).catch(()=>{})},[]);const i=r.filter(m=>m.state==="enabled");return i.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:a("No plugins enabled")}):e.jsx("div",{className:"divide-y rounded-md border",children:i.map(m=>e.jsxs("label",{className:"flex cursor-pointer items-center gap-2 px-3 py-2 text-sm","data-enso":"secretary-plugin-row","data-plugin-id":m.id,children:[e.jsx(Le,{checked:s.includes(m.id),disabled:t,onCheckedChange:u=>n(u===!0?[...s,m.id]:s.filter(x=>x!==m.id))}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:m.name}),e.jsx("span",{className:"shrink-0 text-xs text-muted-foreground",children:a("{{n}} tools",{n:m.tools.length})}),m.permissions.includes("agent.inject")?e.jsx("span",{className:"shrink-0 rounded bg-muted px-1.5 text-[10px] text-muted-foreground",children:a("Sends messages")}):null]},m.id))})}function xf({busy:s}){const{t}=R(),[n,a]=l.useState([]),[r,o]=l.useState(null),i=l.useCallback(async()=>{const u=await window.electronAPI.secretary.listSkills();u.ok?a(u.skills.filter(x=>x.source==="own")):o(u.error)},[]);l.useEffect(()=>{i()},[i]);const m=async u=>{o(null);const x=await window.electronAPI.secretary.removeSkill(u);if(!x.ok){o(x.error);return}await i()};return r?e.jsx("p",{className:"text-xs text-destructive",children:r}):n.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:t("No skills yet")}):e.jsx("div",{className:"divide-y rounded-md border",children:n.map(u=>e.jsxs("div",{className:"px-3 py-2","data-enso":"secretary-skill-row",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-sm",children:u.name}),!u.enabled&&e.jsx("span",{className:"shrink-0 rounded bg-warning/10 px-1 text-[10px] text-warning",children:t("Disabled")}),e.jsx(y,{variant:"ghost",size:"sm",disabled:s,onClick:()=>{m(u.name)},children:t("Remove")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:u.description}),e.jsxs("details",{className:"mt-1",children:[e.jsx("summary",{className:"cursor-pointer text-[11px] text-muted-foreground",children:t("Show the content")}),e.jsx("pre",{className:"mt-1 max-h-64 overflow-auto whitespace-pre-wrap text-[11px]",children:u.body??""})]})]},u.name))})}function hf({busy:s}){const{t}=R(),[n,a]=l.useState([]),[r,o]=l.useState(null),i=l.useCallback(async()=>{const u=await window.electronAPI.secretary.listTools();u.ok?a(u.tools):o(u.error)},[]);l.useEffect(()=>{i()},[i]);const m=async u=>{o(null);const x=await window.electronAPI.secretary.removeTool(u);if(!x.ok){o(x.error);return}await i()};return r?e.jsx("p",{className:"text-xs text-destructive",children:r}):n.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:t("No tools yet")}):e.jsx("div",{className:"divide-y rounded-md border",children:n.map(u=>e.jsxs("div",{className:"px-3 py-2","data-enso":"secretary-tool-row",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-sm",children:u.name}),e.jsx("span",{className:"shrink-0 rounded bg-muted px-1.5 text-[10px] text-muted-foreground",children:u.runtime==="python"?"Python":"Node"}),e.jsx("span",{className:"shrink-0 rounded bg-muted px-1.5 text-[10px] text-muted-foreground",children:u.readOnly?t("Read-only"):t("Asks every call")}),e.jsx(y,{variant:"ghost",size:"sm",disabled:s,onClick:()=>{m(u.name)},children:t("Remove")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:u.description}),e.jsxs("details",{className:"mt-1",children:[e.jsx("summary",{className:"cursor-pointer text-[11px] text-muted-foreground",children:t("Show the code")}),e.jsx("pre",{className:"mt-1 max-h-64 overflow-auto whitespace-pre font-mono text-[11px]",children:u.code})]})]},u.name))})}function pf({profile:s,busy:t,onChange:n}){const{t:a}=R(),r=g(x=>x.projects),o=s.takeoverScope,i=s.visibleProjectIds,m=r.filter(x=>x.kind!=="secretary"&&x.kind!=="scratch"&&(i==="all"||i.includes(x.id))),u=o.mode==="projects"?o.projectIds:[];return e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ks,{enso:"secretary-takeover-scope",value:o.mode,options:[{value:"explicit",label:"One by one"},{value:"projects",label:"Selected projects"},{value:"all",label:"All visible projects"}],onChange:x=>n(x==="all"?{mode:"all"}:x==="explicit"?{mode:"explicit"}:{mode:"projects",projectIds:u})}),o.mode==="projects"?m.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:a("No project in the takeover scope")}):e.jsx("div",{className:"flex flex-wrap gap-1","data-enso":"secretary-takeover-projects",children:m.map(x=>{const h=u.includes(x.id);return e.jsx("button",{type:"button","aria-pressed":h,disabled:t,onClick:()=>n({mode:"projects",projectIds:h?u.filter(c=>c!==x.id):[...u,x.id]}),className:K("rounded-md border px-2.5 py-1 text-xs transition-colors",h?"border-primary/60 bg-primary/10 text-foreground":"border-border text-muted-foreground hover:bg-muted"),children:x.alias||x.name},x.id)})}):null]})}function ff({locale:s}){const{t}=R(),[n,a]=l.useState([]),[r,o]=l.useState(null),i=l.useCallback(async()=>{const u=await window.electronAPI.secretary.listTakeovers();u.ok?a(u.takeovers):o(u.error)},[]);l.useEffect(()=>(i(),window.electronAPI.secretary.onStateChanged(()=>{i()})),[i]);const m=async u=>{o(null);const x=await window.electronAPI.secretary.revokeTakeover(u);x.ok||o(x.error),await i()};return e.jsxs(e.Fragment,{children:[r?e.jsx("p",{className:"text-xs text-destructive",children:r}):null,n.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:t("No sessions handed over")}):e.jsx("div",{className:"divide-y rounded-md border",children:n.map(u=>e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2","data-enso":"secretary-takeover-row","data-conversation-id":u.conversationId,children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-sm",children:u.title||t("Unnamed")}),e.jsx("p",{className:"truncate text-xs text-muted-foreground",children:[u.projectName,li(u.grantedAt,s)].filter(Boolean).join(" · ")})]}),e.jsx(y,{variant:"ghost",size:"sm",onClick:()=>{m(u.conversationId)},children:t("Take back")})]},u.conversationId))})]})}function gf(){const{t:s}=R(),[t,n]=l.useState([]),[a,r]=l.useState(null),o=l.useCallback(async()=>{const m=await window.electronAPI.secretary.listUntracked();m.ok?n(m.untracked):r(m.error)},[]);l.useEffect(()=>(o(),window.electronAPI.secretary.onStateChanged(()=>{o()})),[o]);const i=async m=>{r(null);const u=await window.electronAPI.secretary.removeUntracked(m);u.ok||r(u.error),await o()};return t.length===0&&!a?null:e.jsxs("div",{className:"mt-3 space-y-2","data-enso":"secretary-untracked",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Not tracked: the takeover scope no longer covers these sessions. Removing one lets the scope cover it again.")}),a?e.jsx("p",{className:"text-xs text-destructive",children:a}):null,e.jsx("div",{className:"divide-y rounded-md border",children:t.map(m=>e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2","data-enso":"secretary-untracked-row","data-conversation-id":m.conversationId,children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-sm",children:m.title||s("Unnamed")}),e.jsx("p",{className:"truncate text-xs text-muted-foreground",children:m.projectName})]}),e.jsx(y,{variant:"ghost",size:"sm",onClick:()=>{i(m.conversationId)},children:s("Track again")})]},m.conversationId))})]})}function jf({skillIds:s,onChange:t}){const{t:n}=R(),a=g(r=>r.skills);return e.jsx(Rd,{title:n("Global skills"),emptyText:n("No skills yet"),items:a,getName:r=>r.name,getSource:r=>r.source,isChecked:r=>s.includes(r.id),onToggle:r=>t(s.includes(r.id)?s.filter(o=>o!==r.id):[...s,r.id]),placeholder:n("Filter skills..."),renderDetail:r=>e.jsx("p",{className:"text-xs",children:r.description||r.path})})}function vf(){const{t:s,locale:t}=R(),[n,a]=l.useState(null),[r,o]=l.useState(""),[i,m]=l.useState(null),[u,x]=l.useState([]),[h,c]=l.useState(!1),[f,d]=l.useState(null),[p,j]=l.useState(null),[b,A]=l.useState(!1),[v,k]=l.useReducer(cf,ii),I=l.useRef(null),M=s("Secretary"),$=l.useCallback(async()=>{const S=await window.electronAPI.secretary.listSchedules();S.ok&&x(S.schedules)},[]),E=l.useCallback(async()=>{const S=await window.electronAPI.secretary.getProfile();if(!S.ok){d(S.error);return}a(S.profile),o(S.persona),m(S.profile?it(S.profile,M):null),await $()},[M,$]);l.useEffect(()=>{E()},[E]);const L=async S=>{c(!0),d(null),j(null);try{const W=await window.electronAPI.secretary.saveProfile(S);if(!W.ok){d(W.error);return}a(W.profile),m(it(W.profile,M)),j(s("Saved")),await $()}catch{d(s("Could not save the secretary profile. Try again."))}finally{c(!1)}},T=async S=>{k({type:"saving"}),d(null);try{const W=await window.electronAPI.secretary.setAvatar(S);if(!W.ok){k({type:"save-failed"}),d(W.error);return}a(W.profile),m(it(W.profile,M)),k({type:"saved"})}catch{k({type:"save-failed"}),d(s("Could not save the secretary profile. Try again."))}},C=async S=>{d(null);const W=await window.electronAPI.secretary.removeSchedule(S);if(!W.ok){d(W.error);return}await $()};return e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("Secretary")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("The secretary is not part of any project. It watches your projects, dispatches sessions and reports results back. It never reads or writes code itself.")})]}),f?e.jsx("p",{className:"text-xs text-destructive",children:f}):null,v.problem?e.jsx("p",{className:"text-xs text-destructive","data-enso":"secretary-avatar-problem",children:s(uf[v.problem])}):null,p?e.jsx("p",{className:"text-xs text-muted-foreground",children:p}):null,e.jsxs(ss,{title:"Secretary profile",description:"Name, avatar, model and how much the secretary may do on its own.",rowId:"secretary.profile",children:[n?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{ref:I,type:"file",accept:"image/png,image/jpeg,image/webp,image/gif","data-enso":"secretary-avatar-file",className:"hidden",onChange:S=>{const W=S.target.files?.[0];if(S.target.value="",!W)return;const q=yd(W,wa);k({type:"pick",problem:q}),!q&&wd(W).then(N=>k({type:"picked",source:N}),()=>k({type:"read-failed"}))}}),e.jsx(Nd,{name:n.name,color:n.avatar.color,image:n.avatar.imageVersion?kd(n.avatar.imageVersion,n.avatar.imageHash):void 0,needsYou:0,running:0,enso:"secretary-settings-avatar"}),e.jsx(y,{variant:"outline",size:"sm",disabled:v.busy,onClick:()=>I.current?.click(),"data-enso":"secretary-avatar-upload",children:s("Upload image")}),n.avatar.imageVersion?e.jsx(y,{variant:"ghost",size:"sm",disabled:v.busy,onClick:()=>{T(null)},"data-enso":"secretary-avatar-remove",children:s("Remove image")}):null,e.jsx(Cd,{source:v.cropSource,onCancel:()=>k({type:"crop-cancelled"}),onDone:S=>{const W=Sd(S),q=W.byteLength>wa;k({type:"cropped",tooLarge:q}),!q&&T(W)}})]}):e.jsx("p",{className:"text-xs text-muted-foreground",children:s("The secretary has not been set up yet.")}),e.jsx(Id,{initialDraft:n?it(n,M):Ad(M),submitLabel:s("Save"),busy:h,hideMaxRunning:!0,onSubmit:({maxRunningDispatches:S,...W})=>{L(W)}},n?.updatedAt??"new")]}),e.jsx(ss,{title:"Concurrent dispatch limit",description:"The most dispatched sessions the secretary may run at the same time. Once the limit is reached, new dispatches are refused.",rowId:"secretary.dispatchLimit",children:n?e.jsx(Ks,{enso:"secretary-dispatch-limit",value:String(n.maxRunningDispatches),options:df,onChange:S=>{const W=Number(S);h||W===n.maxRunningDispatches||L({maxRunningDispatches:W})}}):e.jsx("p",{className:"text-xs text-muted-foreground",children:s("The secretary has not been set up yet.")})}),e.jsx(ss,{title:"Plugins",description:"Check a plugin to give the secretary its agent tools and skills. Tools that are not read-only ask for your approval on every call.",rowId:"secretary.plugins",children:n?e.jsx(mf,{pluginIds:n.pluginIds??[],busy:h,onChange:S=>{L({pluginIds:S})}}):e.jsx("p",{className:"text-xs text-muted-foreground",children:s("The secretary has not been set up yet.")})}),e.jsx(ss,{title:"Skills",description:"Skills the secretary may use. It proposes new ones in the chat; you confirm before anything is written.",rowId:"secretary.skills",children:n?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"mb-1 text-xs font-semibold tracking-wide text-muted-foreground uppercase",children:s("Secretary skills")}),e.jsx(xf,{busy:h})]}),e.jsx(jf,{skillIds:n.skillIds??[],onChange:S=>{L({skillIds:S})}})]}):e.jsx("p",{className:"text-xs text-muted-foreground",children:s("The secretary has not been set up yet.")})}),e.jsx(ss,{title:"Tools",description:"Python or Node tools the secretary builds for itself. It proposes them in the chat; you confirm before anything is written. Read-only tools run directly, anything else asks for your approval on every call.",rowId:"secretary.tools",children:n?e.jsx(hf,{busy:h}):e.jsx("p",{className:"text-xs text-muted-foreground",children:s("The secretary has not been set up yet.")})}),i?e.jsx(ss,{title:"Style and interruptions",description:"What it calls you, reply language, style and system notifications.",rowId:"secretary.style",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-sm",children:s("What to call you")}),e.jsx(J,{value:i.addressAs??"",placeholder:s("Optional"),onChange:S=>m({...i,addressAs:S.target.value.trim()?S.target.value:null}),className:"max-w-xs"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-sm",children:s("Reply language")}),e.jsx(Ks,{value:i.replyLanguage??"ui",options:["ui","zh","en"].map(S=>({value:S,label:Ed[S]})),onChange:S=>m({...i,replyLanguage:S})})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-sm",children:s("Communication style")}),e.jsx(Ks,{value:i.style??"concise",options:["concise","detailed"].map(S=>({value:S,label:Md[S]})),onChange:S=>m({...i,style:S})})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-sm",children:s("System notifications")}),e.jsx(Ks,{value:i.notify??"needs-user",options:["needs-user","with-done","off"].map(S=>({value:S,label:Pd[S]})),onChange:S=>m({...i,notify:S})})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-sm",children:s("Daily brief time")}),e.jsx(J,{type:"time",value:i.dailyBriefAt??"",onChange:S=>m({...i,dailyBriefAt:S.target.value||null}),className:"max-w-32"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-sm",children:s("Persona")}),e.jsx(Xe,{value:r,onChange:S=>o(S.target.value),rows:4})]}),e.jsx(y,{size:"sm",disabled:h,onClick:()=>{L({addressAs:i.addressAs??null,replyLanguage:i.replyLanguage,style:i.style,notify:i.notify,dailyBriefAt:i.dailyBriefAt??null,persona:r})},children:s("Save")})]})}):null,e.jsx(ss,{title:"Sessions it may take over",description:"Which sessions the secretary may message and stop without asking you first. Everything else still needs a confirmation card from the secretary.",rowId:"secretary.takeoverScope",children:n?e.jsx(pf,{profile:n,busy:h,onChange:S=>{L({takeoverScope:S})}}):e.jsx("p",{className:"text-xs text-muted-foreground",children:s("The secretary has not been set up yet.")})}),e.jsxs(ss,{title:"Sessions handed over",description:"Sessions you started and handed to the secretary. It may message and stop them like the ones it dispatched; take one back to remove that right.",rowId:"secretary.takeovers",children:[e.jsx(ff,{locale:t}),e.jsx(gf,{})]}),e.jsx(ss,{title:"Scheduled tasks",rowId:"secretary.schedules",children:u.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Nothing scheduled")}):e.jsx("div",{className:"divide-y rounded-md border",children:u.map(S=>e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-sm",children:S.name}),e.jsxs("p",{className:"truncate text-xs text-muted-foreground",children:[S.cron??S.at??"",S.nextRunAt?` · ${li(S.nextRunAt,t)}`:""]})]}),S.system?e.jsx("span",{className:"shrink-0 rounded bg-muted px-1.5 text-[10px] text-muted-foreground",children:s("Built-in")}):e.jsx(y,{variant:"ghost",size:"sm",onClick:()=>{C(S.id)},children:s("Remove")})]},S.id))})}),e.jsxs(ss,{title:"Reset the secretary and start over",description:"Sessions and dispatch history are kept either way.",rowId:"secretary.reset",children:[e.jsx(y,{variant:"outline",size:"sm",onClick:()=>A(!0),children:s("Re-run setup")}),e.jsx(Td,{open:b,onOpenChange:A,onReset:()=>{a(null),m(null),o(""),j(null),$()}})]})]})}function bf(){const{t:s}=R(),t=g(I=>I.skills),n=g(I=>I.updateSkill),a=g(I=>I.setSkillsEnabled),r=g(I=>I.removeSkill),o=g(I=>I.loadLocalSkills),i=g(I=>I.setLoadLocalSkills),m=g(I=>I.loadHarnessAssets),u=g(I=>I.setLoadHarnessAssets),[x,h]=l.useState(!1),[c,f]=l.useState(""),d=t.filter(I=>co(c,[I.name,I.source,I.description,I.path])),p=d.map(I=>I.id),j=uo(p),b=t.filter(I=>I.enabled).length,A=t.map(I=>I.id),v=It(A,I=>window.electronAPI.assets.skillOccupancy(I)),k=kt(t.filter(I=>I.enabled).map(I=>I.id),v.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:s("Load local skills")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Let the agent auto-discover skills under .agents/skills and .pi/skills")})]}),e.jsx(ce,{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:s("Load project harness assets")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Also load skills from .claude/.codex/.cursor and rule files (.cursorrules, .cursor/rules, .claude/rules) in the project")})]}),e.jsx(ce,{checked:m,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:[s("Skills"),e.jsx(Ze,{note:s("The / menu updates right away, but open sessions keep the skills they loaded. Start a new session to load the change.")}),t.length>0&&e.jsxs("span",{className:"ml-2 font-normal text-muted-foreground text-xs",children:[s("{{enabled}}/{{total}} enabled",{enabled:b,total:t.length}),e.jsx(St,{tokens:k})]})]}),e.jsx("p",{className:"text-muted-foreground text-sm",children:s("Skills registered by reference; files stay in their original location")})]}),e.jsxs(y,{variant:"outline",size:"sm",onClick:()=>h(!0),children:[e.jsx(Nt,{className:"mr-1.5 h-4 w-4"}),s("Import from local apps")]})]}),t.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx(Po,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:s("No skills yet")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:s("Import skills from Claude Code, Codex or Cursor to get started")})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx(xo,{query:c,onQueryChange:f,placeholder:s("Filter skills..."),allSelected:j.allSelected,someSelected:j.someSelected,onToggleSelectAll:j.toggleAll,onEnable:()=>a(j.selectedIds,!0),onDisable:()=>a(j.selectedIds,!1),selectDisabled:d.length===0,actionDisabled:j.selectedIds.length===0}),d.length===0?e.jsx("p",{className:"px-3 py-6 text-center text-muted-foreground text-xs",children:s("No results")}):e.jsx("div",{className:"space-y-1",children:d.map(I=>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.${I.id}`,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(Le,{checked:j.isSelected(I.id),onCheckedChange:M=>j.toggleOne(I.id,M)}),e.jsx("span",{className:K("shrink-0 font-medium text-sm",!I.enabled&&"text-muted-foreground line-through"),children:I.name}),e.jsx(se,{variant:"secondary",className:"shrink-0 text-[11px]",children:I.source}),e.jsx("span",{className:"min-w-0 truncate text-muted-foreground text-xs",children:I.description||I.path})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(Ct,{row:v.rows[I.id],pending:v.pending&&!v.rows[I.id]}),e.jsx(ce,{checked:I.enabled,onCheckedChange:M=>n(I.id,{enabled:M})}),e.jsx(y,{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(I.id),children:e.jsx(Pe,{className:"h-3.5 w-3.5"})})]})]},I.id))})]}),e.jsx(zn,{kind:"skill",open:x,onOpenChange:h})]})}const br=[10,15,30,60,120,300];function yf(){const{t:s}=R(),[t,n]=l.useState([]),[a,r]=l.useState(!1),[o,i]=l.useState(null),[m,u]=l.useState(""),[x,h]=l.useState(""),[c,f]=l.useState(""),[d,p]=l.useState(""),[j,b]=l.useState("key"),[A,v]=l.useState(""),[k,I]=l.useState(!1),[M,$]=l.useState(null),[E,L]=l.useState(null),[T,C]=l.useState(null),[S,W]=l.useState(null),[q,N]=l.useState(!1),z=l.useCallback(()=>{window.electronAPI.sshConnections.list().then(n)},[]);l.useEffect(()=>{z()},[z]);const H=()=>{i(null),u(""),h(""),f(""),p(""),b("key"),v(""),L(null),r(!0)},U=V=>{i(V),u(V.name),h(V.host),f(V.user??""),p(V.port?String(V.port):""),b(V.auth),v(""),L(null),r(!0)},B=async V=>{V.preventDefault(),I(!0),L(null);const le=d.trim()?Number(d):void 0,_=await window.electronAPI.sshConnections.upsert({...o?{id:o.id}:{},name:m.trim(),host:x.trim(),...c.trim()?{user:c.trim()}:{},...le&&Number.isInteger(le)?{port:le}:{},auth:j,...j==="password"&&A?{password:A}:{}});if(I(!1),!_.ok){L(_.error);return}r(!1),z()},ie=async V=>{const le=await window.electronAPI.sshConnections.delete(V);if(!le.ok){C(le.error);return}C(null),z()},F=async(V,le=!0)=>{$(V),C(null);const _=await window.electronAPI.sshConnections.test(V);if($(null),!_.ok){const de=t.find(O=>O.id===V),ue=Dd(_,de);if(ue&&le){W({id:V,challenge:ue});return}}C(_.ok?s("SSH connection succeeded"):_.error)},X=async()=>{if(!S)return;N(!0);const V=S.id,le=await window.electronAPI.sshConnections.trustHost(V);if(N(!1),W(null),!le.ok){C(le.error||s("Could not save host key."));return}await F(V,!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:[s("SSH"),e.jsx(Ze,{note:s("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:s("Saved hosts for remote projects. Passwords stay in the system keychain.")})]}),e.jsxs(y,{size:"sm",onClick:H,children:[e.jsx(Re,{className:"h-4 w-4"}),s("Add connection")]})]}),T&&e.jsx("p",{className:"text-sm text-muted-foreground",children:T}),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:s("No SSH connections yet")}),t.map(V=>e.jsxs("li",{className:"flex items-center gap-2 px-3 py-2","data-settings-row":`ssh.${V.id}`,children:[e.jsxs("button",{type:"button",className:"min-w-0 flex-1 text-left",onClick:()=>U(V),children:[e.jsx("div",{className:"truncate text-sm font-medium",children:V.name}),e.jsxs("div",{className:"truncate text-xs text-muted-foreground",children:[V.user?`${V.user}@`:"",V.host,V.port?`:${V.port}`:""," ·"," ",V.auth==="password"?s("Password"):s("Key / agent")]})]}),e.jsx(y,{size:"sm",variant:"outline",disabled:M===V.id,onClick:()=>{F(V.id)},children:M===V.id?e.jsx(Me,{className:"h-4 w-4 animate-spin"}):s("Test")}),e.jsx(y,{size:"icon-sm",variant:"ghost",onClick:()=>{ie(V.id)},children:e.jsx(Pe,{className:"h-4 w-4"})})]},V.id))]}),e.jsx(wf,{}),e.jsx(ye,{open:a,onOpenChange:r,children:e.jsx(we,{className:"max-w-md",children:e.jsxs("form",{onSubmit:V=>{B(V)},className:"flex flex-col",children:[e.jsx(Ne,{children:e.jsx(ke,{children:s(o?"Edit SSH connection":"Add SSH connection")})}),e.jsxs(Ce,{className:"space-y-3",children:[e.jsxs(he,{children:[e.jsx(pe,{children:s("Name")}),e.jsx(J,{value:m,onChange:V=>u(V.target.value),required:!0})]}),e.jsxs(he,{children:[e.jsx(pe,{children:s("Host")}),e.jsx(J,{value:x,onChange:V=>h(V.target.value),placeholder:"example.com",required:!0})]}),e.jsxs(he,{children:[e.jsx(pe,{children:s("User (optional)")}),e.jsx(J,{value:c,onChange:V=>f(V.target.value)})]}),e.jsxs(he,{children:[e.jsx(pe,{children:s("Port (optional)")}),e.jsx(J,{value:d,onChange:V=>p(V.target.value),placeholder:"22"})]}),e.jsxs(he,{children:[e.jsx(pe,{children:s("Authentication")}),e.jsxs(ne,{items:[{value:"key",label:s("Key / agent")},{value:"password",label:s("Password")}],value:j,onValueChange:V=>b(V),children:[e.jsx(ae,{className:"w-full",children:e.jsx(re,{})}),e.jsxs(oe,{zIndex:cs.DROPDOWN_IN_MODAL,children:[e.jsx(Z,{value:"key",children:s("Key / agent")}),e.jsx(Z,{value:"password",children:s("Password")})]})]})]}),j==="password"&&e.jsxs(he,{children:[e.jsx(pe,{children:o?.hasPassword?s("Password (leave blank to keep)"):s("Password")}),e.jsx(J,{type:"password",value:A,onChange:V=>v(V.target.value),required:!o?.hasPassword})]}),E&&e.jsx("p",{className:"text-sm text-destructive",children:E})]}),e.jsxs(Ee,{children:[e.jsx(y,{type:"button",variant:"outline",size:"sm",onClick:()=>r(!1),children:s("Cancel")}),e.jsx(y,{type:"submit",size:"sm",disabled:k,children:s("Save")})]})]})})}),e.jsx(Od,{challenge:S?.challenge??null,busy:q,onTrust:()=>{X()},onDismiss:()=>!q&&W(null)})]})}function wf(){const{t:s}=R(),t=g(a=>a.sshTimeoutSeconds),n=g(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:s("SSH timeout")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Time limit for connection tests, loading remote AGENTS.md, remote folder browsing and file panel actions. Agent tool commands are not affected.")})]}),e.jsxs(ne,{items:Object.fromEntries(br.map(a=>[String(a),`${a}s`])),value:String(t),onValueChange:a=>n(Number(a)),children:[e.jsx(ae,{className:"w-24",children:e.jsx(re,{})}),e.jsx(oe,{children:br.map(a=>e.jsx(Z,{value:String(a),children:`${a}s`},a))})]})]})}const Nf={memory:"memory",workflows:"workflow"},ci=["bots","botTemplates"],di=["secretary"],kf=[{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","secretary"]}];function Cf(s){const t=new Map(s.map(n=>[n.id,n]));return kf.flatMap(n=>{const a=n.categories.flatMap(r=>{const o=t.get(r);return o?[o]:[]});return a.length>0?[{id:n.id,label:n.label,items:a}]:[]})}function ui(s,t,n=!1,a=!1){if(di.includes(s))return a;if(ci.includes(s))return n;if(s==="memory"&&a)return!0;const r=Nf[s];return!r||!t.includes(r)}function Sf(s,t,n=!1,a=!1){return s.filter(r=>ui(r.id,t,n,a))}function If(s,t,n=!1,a=!1){return ui(s,t,n,a)?s:ci.includes(s)||di.includes(s)?"experimental":"tools"}function Af(s,t,n,a){const r=n.trim();if(!r)return s.map(u=>({...u,hits:[]}));const o=Ld([...t,...s.map(u=>({id:`${u.id}.root`,category:u.id,title:u.label}))],r,{translate:a,limit:Number.POSITIVE_INFINITY}),i=new Set,m=new Map;for(const u of o){if(i.add(u.category),u.id.endsWith(".root"))continue;const x=m.get(u.category);x?x.push(u):m.set(u.category,[u])}return s.flatMap(u=>i.has(u.id)?[{...u,hits:m.get(u.id)??[]}]:[])}const Ef=[1,7,30,90],yr=640,dt=180,wr=8,Nr=18,Mf=.3,Pf=2;function Tf(s){const[,t,n]=s.split("-");return`${Number(t)}/${Number(n)}`}const Rf=[{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 Of({daily:s}){const{t}=R(),[n,a]=l.useState("tokens"),[r,o]=l.useState(null),[i,m]=l.useState({output:!0,input:!0,cache:!0}),u=v=>{m(k=>{const I={...k,[v]:!k[v]};return!I.output&&!I.input&&!I.cache?k:I})},x=s.map(v=>n==="cost"?v.cost??0:(i.output?v.output:0)+(i.input?v.input:0)+(i.cache?v.cache:0)),h=Math.max(0,...x),c=Math.max(1,s.length),f=yr/c,d=Math.min(f*(1-Mf),64),p=dt-wr-Nr,j=v=>h>0?v/h*p:0,b=Math.max(1,Math.ceil(c/12)),A=r!==null?s[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:t("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(Jt,{className:"bg-foreground",label:t("Output"),pressed:i.output,onClick:()=>u("output")}),e.jsx(Jt,{className:"bg-foreground/45",label:t("Input"),pressed:i.input,onClick:()=>u("input")}),e.jsx(Jt,{className:"bg-foreground/15",label:t("Cache"),pressed:i.cache,onClick:()=>u("cache")})]}),e.jsx(Df,{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"?We(h):vt(h>0?h:null)}),A&&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:[A.day,n==="tokens"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[t("Output")," ",We(A.output)]}),e.jsxs("div",{children:[t("Input")," ",We(A.input)]}),e.jsxs("div",{children:[t("Cache")," ",We(A.cache)]})]}):e.jsxs(e.Fragment,{children:[" · ",vt(A.cost)]})]}),e.jsx("svg",{viewBox:`0 0 ${yr} ${dt}`,className:"mt-4 block h-[180px] w-full",role:"img","aria-label":t("Daily trend"),onMouseLeave:()=>o(null),children:s.map((v,k)=>{const I=k*f+(f-d)/2,M=dt-Nr,$=n==="tokens"?Rf.filter(L=>i[L.id]).map(L=>({v:v[L.id],cls:L.cls})):[{v:v.cost??0,cls:"fill-emerald-600 dark:fill-emerald-500"}];let E=M;return e.jsxs("g",{onMouseEnter:()=>o(k),children:[e.jsx("rect",{x:I,y:wr,width:d,height:p,className:"fill-transparent"}),$.map(L=>{const T=L.v>0?Math.max(Pf,j(L.v)):0;return E-=T,e.jsx("rect",{x:I,y:E,width:d,height:T,rx:1,className:K(L.cls,r===k&&"opacity-80")},L.cls)}),k%b===0&&e.jsx("text",{x:I+d/2,y:dt-4,textAnchor:"middle",className:"fill-muted-foreground font-mono text-[10px]",children:Tf(v.day)})]},v.day)})})]})]})}function Jt({className:s,label:t,pressed:n,onClick:a}){return e.jsxs("button",{type:"button","aria-pressed":n,onClick:a,className:K("flex items-center gap-1 rounded px-0.5 transition-opacity",n?"opacity-100":"opacity-40"),children:[e.jsx("span",{className:K("inline-block h-2.5 w-2.5 rounded-sm",s)}),t]})}function Df({value:s,onChange:t}){const{t:n}=R(),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:()=>t(r.id),className:K("rounded px-2 py-0.5 text-[11px] transition-colors",s===r.id?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:r.label},r.id))})}const Xt=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],kr=Array.from({length:24},(s,t)=>String(t).padStart(2,"0")),yt=["bg-foreground/[0.06]","bg-foreground/20","bg-foreground/40","bg-foreground/60","bg-foreground/80","bg-foreground"];function Lf(s,t){return s<=0||t<=0?0:1+Math.min(yt.length-2,Math.floor(s/t*(yt.length-1)))}function zf({heatmap:s}){const{t}=R(),n=Math.max(0,...s.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:t("Activity by hour")}),e.jsxs("div",{className:"flex items-center gap-1 text-[10px] text-muted-foreground",children:[e.jsx("span",{children:t("Less")}),yt.map(a=>e.jsx("span",{className:K("inline-block h-2.5 w-2.5 rounded-[2px]",a)},a)),e.jsx("span",{children:t("More")})]})]}),e.jsxs("div",{className:"grid grid-cols-[28px_1fr] gap-x-2 gap-y-1",children:[s.map((a,r)=>e.jsxs("div",{className:"contents",children:[e.jsx("span",{className:"self-center text-[10px] text-muted-foreground",children:t(Xt[r])}),e.jsx("div",{className:"grid grid-cols-24 gap-[3px]",children:kr.map((o,i)=>e.jsx("span",{title:`${t(Xt[r])} ${o}:00 · ${We(a[i]??0)}`,className:K("aspect-square rounded-[2px]",yt[Lf(a[i]??0,n)])},o))})]},Xt[r])),e.jsx("span",{}),e.jsx("div",{className:"grid grid-cols-24 font-mono text-[10px] text-muted-foreground",children:kr.map((a,r)=>e.jsx("span",{className:K(r%3!==0&&"invisible"),children:a},a))})]})]})}function Qt({title:s,countLabel:t,rows:n,emptyLabel:a,limit:r=8}){const{t:o}=R(),[i,m]=l.useState(!1),u=n.reduce((c,f)=>c+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:s}),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:t})]})}),e.jsx("tbody",{children:h.map(c=>{const f=u>0?c.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:c.name,children:c.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:K("py-2 text-right font-mono tabular-nums",c.cost===null&&"text-muted-foreground"),children:vt(c.cost)}),e.jsxs("td",{className:"py-2 text-right font-mono tabular-nums",children:[We(c.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:c.count})]},c.key)})})]}),x&&e.jsx(y,{variant:"ghost",size:"xs",className:"mt-2 w-full text-muted-foreground",onClick:()=>m(c=>!c),children:o(i?"Collapse":"Show all")})]})}function _f({value:s,className:t}){const n=s.split("");return e.jsx("span",{className:K("t-digit-group is-animating",t),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}`))},s)}const Ff={default:"text-foreground",success:"text-emerald-600 dark:text-emerald-400",info:"text-sky-600 dark:text-sky-400",muted:"text-muted-foreground"};function xs({label:s,value:t,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:s}),n&&e.jsx("span",{className:"shrink-0 font-mono text-[11px] tabular-nums text-muted-foreground",children:n})]}),e.jsx("div",{className:K("mt-1 truncate font-mono text-xl font-semibold leading-tight tabular-nums sm:text-2xl",Ff[a]),title:t,children:e.jsx(_f,{value:t})})]})}const Zt={input:0,output:0,cacheRead:0,cacheWrite:0},wt=["input","output","cacheRead","cacheWrite"];function en(s){return{input:String(s.input),output:String(s.output),cacheRead:String(s.cacheRead),cacheWrite:String(s.cacheWrite)}}function Bf(s){return Bd({id:Object.fromEntries(wt.map(n=>[n,Number(s[n])]))}).id??null}function Uf(s){return s===void 0?"—":String(s)}function Cr({rows:s,editing:t,draft:n,overrides:a,onDraft:r,onEdit:o,onSave:i}){const{t:m}=R();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:m("Name")}),wt.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:s.map(u=>{const x=t===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:m("Custom")})]}),wt.map(c=>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[c],onChange:f=>r({...n,[c]:f.target.value})}):e.jsx("span",{className:K("font-mono tabular-nums",u.pricing==null&&"text-muted-foreground"),children:Uf(u.pricing?.[c])})},c)),e.jsx("td",{className:"py-1.5 text-right align-middle",children:x?e.jsx(y,{size:"sm",className:"h-6 px-1.5 text-[11px]",onClick:()=>i(u.model),children:m("Save")}):e.jsx(y,{variant:"ghost",size:"sm",className:"h-6 px-1.5 text-[11px]",onClick:()=>o(u.model,u.pricing),children:m("Edit")})})]},u.model)})})]})}function $f({models:s,catalog:t,onChanged:n}){const{t:a}=R(),r=g(N=>N.usageModelPricing),o=et(),i=g(N=>N.setUsageModelPricing),[m,u]=l.useState(!1),[x,h]=l.useState(!1),[c,f]=l.useState(null),[d,p]=l.useState(en(Zt)),[j,b]=l.useState(null),[A,v]=l.useState(!1),[k,I]=l.useState(""),[M,$]=l.useState(""),E=new Set(s.map(N=>N.model)),L=new Set;for(const N of o)for(const z of N.models)L.add(z.id);for(const N of Object.keys(r))L.add(N);const T=M.trim().toLowerCase(),C=s.filter(N=>!T||N.model.toLowerCase().includes(T)).map(N=>({model:N.model,pricing:N.pricing})),S=[...L].filter(N=>!E.has(N)&&(!T||N.toLowerCase().includes(T))).sort().map(N=>({model:N,pricing:r[N]??t[N]??null})),W=(N,z)=>{v(!1),f(N),p(en(z??Zt)),b(null)},q=N=>{const z=Bf(d);return!z||!i(N,z)?(b(a("Enter a model id and non-negative rates.")),!1):(b(null),f(null),v(!1),I(""),n(),!0)};return e.jsxs(zd,{open:m,onOpenChange:u,className:"rounded-lg border bg-card",children:[e.jsxs(_d,{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(gt,{className:K("h-4 w-4 shrink-0 text-muted-foreground transition-transform",m&&"rotate-180")})]}),e.jsx(Fd,{children:e.jsxs("div",{className:"space-y-3 border-t px-4 py-3",children:[e.jsx(J,{size:"sm",value:M,onChange:N=>$(N.target.value),placeholder:a("Search models")}),C.length===0&&!A?e.jsx("p",{className:"text-xs text-muted-foreground",children:a(T?"No matching models":"No usage in this period")}):e.jsx(Cr,{rows:C,editing:c,draft:d,overrides:r,onDraft:p,onEdit:W,onSave:q}),S.length>0&&(x||!!T)&&e.jsx(Cr,{rows:S,editing:c,draft:d,overrides:r,onDraft:p,onEdit:W,onSave:q}),A?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:k,onChange:N=>I(N.target.value),placeholder:"qwen-3.8-27b"})]}),wt.map(N=>e.jsxs("label",{className:"grid min-w-16 gap-1 text-[11px] text-muted-foreground",children:[N,e.jsx(J,{size:"sm",inputMode:"decimal",value:d[N],onChange:z=>p(H=>({...H,[N]:z.target.value}))})]},N))]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(y,{size:"sm",className:"h-7",onClick:()=>q(k),children:a("Save")}),e.jsx(y,{variant:"ghost",size:"sm",className:"h-7",onClick:()=>{v(!1),I(""),b(null)},children:a("Cancel")})]})]}):e.jsxs("div",{className:"flex justify-end gap-2",children:[S.length>0&&e.jsxs(y,{variant:"ghost",size:"sm",className:"h-7 text-muted-foreground",onClick:()=>h(N=>!N),children:[a("Show all"),e.jsx(gt,{className:K("ml-1 h-3.5 w-3.5 transition-transform",x&&"rotate-180")})]}),e.jsx(y,{variant:"ghost",size:"sm",className:"h-7",onClick:()=>{v(!0),p(en(Zt)),b(null)},children:a("Add")})]}),j&&e.jsx("p",{className:"text-xs text-destructive",children:j})]})})]})}const Vf={1:"Today",7:"7D",30:"30D",90:"90D"};function Gf(){const{t:s}=R(),[t,n]=l.useState(7),[a,r]=l.useState(null),o=g(p=>p.botModeEnabled),[i,m]=l.useState(null),[u,x]=l.useState(null),[h,c]=l.useState(!1),f=l.useRef(0),d=l.useCallback(async p=>{const j=++f.current;c(!0);const[b,A]=await Promise.all([window.electronAPI.usage.summary(p),o?window.electronAPI.bots.usageSummary(p).catch(()=>null):null]);j===f.current&&(c(!1),m(A?.ok?A.rows:null),b.ok?(r(b.summary),x(null)):(r(null),x(b.error)))},[o]);return l.useEffect(()=>{d(t)},[t,d]),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:s("Usage")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("Token usage across all local sessions; cost is estimated from catalog prices.")})]}),e.jsx(y,{variant:"ghost",size:"icon-sm",onClick:()=>{d(t)},disabled:h,"aria-label":s("Refresh"),children:e.jsx(ns,{className:K(h&&"animate-spin")})})]}),e.jsx(Kf,{value:t,onChange:n}),u&&e.jsx("p",{className:"text-sm text-destructive",children:u}),a&&e.jsxs(e.Fragment,{children:[e.jsx(Wf,{totals:a.totals,previous:a.previous}),e.jsx(Of,{daily:a.daily}),e.jsx(zf,{heatmap:a.heatmap}),e.jsxs("div",{className:"grid gap-4 xl:grid-cols-2",children:[e.jsx(Qt,{title:s("By model"),countLabel:s("Messages"),emptyLabel:s("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(Qt,{title:s("By project"),countLabel:s("Sessions"),emptyLabel:s("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(Qt,{title:s("By member"),countLabel:s("Sessions"),emptyLabel:s("No usage in this period"),rows:i.map(p=>({key:p.botId,name:p.name||s("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:s("No catalog price for: {{models}}. Their cost is not included.",{models:a.unpricedModels.join(", ")})})]}),e.jsx($f,{models:a?.byModel??[],catalog:a?.pricing??{},onChanged:()=>{d(t)}})]})}function Kf({value:s,onChange:t}){const{t:n}=R();return e.jsx("div",{className:"flex items-center gap-1.5",children:Ef.map(a=>e.jsx("button",{type:"button",onClick:()=>t(a),className:K("rounded-full px-3 py-1 font-mono text-xs transition-colors",s===a?"bg-foreground text-background":"bg-muted text-muted-foreground hover:text-foreground"),children:n(Vf[a])},a))})}function Wf({totals:s,previous:t}){const{t:n}=R(),a=s.cacheRead+s.cacheWrite,r=t.cacheRead+t.cacheWrite;return e.jsxs("div",{className:"grid grid-cols-2 gap-3 md:grid-cols-4",children:[e.jsx(xs,{label:n("Estimated cost"),value:vt(s.cost),delta:us(t.cost,s.cost),tone:"success"}),e.jsx(xs,{label:n("Total tokens"),value:We(s.tokens),delta:us(t.tokens,s.tokens)}),e.jsx(xs,{label:n("Input tokens"),value:We(s.input),delta:us(t.input,s.input)}),e.jsx(xs,{label:n("Output tokens"),value:We(s.output),delta:us(t.output,s.output)}),e.jsx(xs,{label:n("Cache tokens"),value:We(a),delta:us(r,a),tone:"muted"}),e.jsx(xs,{label:n("Active time"),value:Ud(s.activeMs),delta:us(t.activeMs,s.activeMs),tone:"info"}),e.jsx(xs,{label:n("Sessions"),value:String(s.sessions),delta:us(t.sessions,s.sessions)}),e.jsx(xs,{label:n("Messages"),value:s.messages.toLocaleString(),delta:us(t.messages,s.messages)})]})}const Sr={"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 mi({state:s,onDownload:t,onCancel:n,onRemove:a}){const{t:r}=R();return s==="unavailable"?null:s==="downloading"?e.jsx(y,{variant:"outline",size:"sm",onClick:n,children:r("Cancel")}):s==="ready"?e.jsx(y,{variant:"ghost",size:"sm",onClick:a,children:r("Remove")}):e.jsx(y,{variant:"outline",size:"sm",onClick:t,children:r("Download")})}function Hf(){const{t:s}=R(),t=g(h=>h.voiceModel),n=g(h=>h.setVoiceModel),{status:a,progress:r,error:o,refresh:i}=$d();if(!a)return null;if(a.state==="unsupported")return e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Voice input is not available on this platform.")});const m=window.electronAPI.speech,u=h=>{const c=r[h.id];return c?`${c.file} · ${me(c.received)}${c.total?` / ${me(c.total)}`:""} (${c.fileIndex+1}/${c.fileCount})`:o?.modelId===h.id?`${s("Download failed")}: ${o.message}`:h.id==="wetype"?s("Audio is uploaded to Tencent WeChat Keyboard servers."):h.remote?h.state==="ready"?s("Audio is uploaded to Google. On the free tier Google may use it to improve its products."):s("Enter a Gemini API key below first."):s("Download {{size}} · Memory about {{memory}}",{size:me(h.approxBytes),memory:me(h.memoryBytes)})},x=a.models.find(h=>h.id===t);return e.jsxs("div",{className:"space-y-1.5","data-settings-row":"tools.voiceModel",children:[e.jsx("p",{className:"text-sm",children:s("Speech model")}),e.jsx("div",{role:"radiogroup",className:"divide-y rounded-md border",children:a.models.map(h=>{const c=h.id===t;return e.jsxs("div",{className:K("flex items-center gap-3 px-3 py-2",c&&"bg-accent/40"),children:[e.jsxs("button",{type:"button",role:"radio","aria-checked":c,onClick:()=>n(h.id),className:"flex min-w-0 flex-1 items-start gap-2.5 text-left",children:[e.jsx("span",{className:K("mt-1 flex size-3.5 shrink-0 items-center justify-center rounded-full border",c&&"border-primary"),children:c?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:[s(Sr[h.id].name),h.remote?e.jsx(se,{variant:"warning",size:"sm",children:s("Cloud")}):null,e.jsx(se,{variant:h.streaming?"info":"secondary",size:"sm",children:h.streaming?s("Streaming"):s("Sentence by sentence")}),h.state==="ready"&&!h.remote?e.jsx(se,{variant:"success",size:"sm",children:s("Downloaded")}):null]}),e.jsx("span",{className:"block text-muted-foreground text-xs",children:s(Sr[h.id].description)}),e.jsx("span",{className:K("block text-xs",o?.modelId===h.id?"text-destructive":h.remote?"text-warning":"text-muted-foreground"),children:u(h)})]})]}),e.jsx(mi,{state:h.remote?"unavailable":h.state,onDownload:()=>{n(h.id),m.download(h.id).then(i)},onCancel:()=>{m.cancelDownload(h.id).then(i)},onRemove:()=>{m.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:s("Download the selected model to start using voice input.")}):null,x?.id==="gemini-live"?e.jsxs(e.Fragment,{children:[e.jsx(qf,{}),e.jsx(Yf,{})]}):null]})}function qf(){const{t:s}=R(),t=g(a=>a.voiceGeminiApiKey),n=g(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:s("Gemini API key")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Create one for free in Google AI Studio.")}),e.jsx(J,{type:"password",autoComplete:"off",spellCheck:!1,value:t,onChange:a=>n(a.target.value),placeholder:"AIza…",className:"font-mono"})]})}function Yf(){const{t:s}=R(),t=g(a=>a.voiceVocabulary),n=g(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:s("Custom vocabulary")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:s("One term per line, up to 100. Helps with names and code terms such as useEffect or pnpm.")}),e.jsx(Xe,{size:"sm",value:t,onChange:a=>n(a.target.value),placeholder:`useEffect
22
+ pnpm
23
+ TypeScript`,className:"font-mono"})]})}function Jf(){const{t:s}=R(),t=g(v=>v.voiceCorrectionEnabled),n=g(v=>v.setVoiceCorrectionEnabled),a=g(v=>v.voiceCorrectionModel)||"remote",r=g(v=>v.setVoiceCorrectionModel),o=g(v=>v.voiceCorrectionRemoteModel),i=g(v=>v.setVoiceCorrectionRemoteModel),m=es(),[u,x]=l.useState([]),[h,c]=l.useState(null),f=l.useCallback(()=>{window.electronAPI.memory.chatModels().then(x)},[]);l.useEffect(()=>(f(),window.electronAPI.memory.onChatModelProgress(v=>{c(v.done?null:v),v.done&&f()})),[f]);const d=u.find(v=>v.id===a)??null,p=u.map(v=>({value:v.id,label:v.id==="remote"?s("Remote (API model)"):`${v.label}${v.purpose?` · ${s("tuned for voice")}`:""} · ${me(v.approxBytes)}`})),j=o?m.find(v=>v.id===o.providerId):void 0,b=j?.models.find(v=>v.id===o?.modelId),A=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:s("Correct with a language model")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Fixes homophones, code terms and number formats after recognition. Adds about 1-3 seconds; the raw text is kept if it fails.")})]}),e.jsx(ce,{checked:t,onCheckedChange:n})]}),t?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:"text-sm",children:s("Correction model")}),e.jsxs(ne,{value:a,items:p,onValueChange:v=>r(String(v)),children:[e.jsx(ae,{className:"w-64",children:e.jsx(re,{})}),e.jsx(oe,{children:p.map(v=>e.jsx(Z,{value:v.value,children:v.label},v.value))})]})]}),d?.downloadable?e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:K("text-xs",d.state==="missing"?"text-destructive":"text-muted-foreground"),children:h?.modelId===d.id?`${me(h.received)}${h.total?` / ${me(h.total)}`:""}`:d.state==="ready"?s("Model downloaded"):d.state==="downloading"?s("Downloading…"):s("Not downloaded yet. Correction is skipped until it is.")}),e.jsx(mi,{state:d.state,onDownload:()=>{A.downloadChatModel(d.id).then(f)},onCancel:()=>{A.cancelChatModelDownload(d.id).then(f)},onRemove:()=>{A.deleteChatModel(d.id).then(f)}})]}):null,a==="remote"&&m.length>0?e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:s("A fast, inexpensive model is enough.")}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[o?e.jsx(y,{variant:"ghost",size:"sm",onClick:()=>i(null),children:s("Reset")}):null,e.jsx("div",{className:"w-56",children:e.jsx(ze,{providers:m,providerId:j?.id??"",modelId:b?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:s("Follows the title-summary model"),side:"bottom",triggerClassName:Qe,onSelect:(v,k)=>i({providerId:v,modelId:k}),onReasoningChange:()=>{},onThinkingChange:()=>{}})})]})]}):null]}):null]})}function Xf(){const{t:s}=R(),t=g(a=>a.voiceInputEnabled),n=g(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:s("Voice input")}),e.jsx("p",{className:"text-muted-foreground text-sm",children:s("Adds a microphone to the composer on this computer and on paired phones. Local models transcribe speech on this computer.")})]}),e.jsx(ce,{checked:t,onCheckedChange:n,"aria-label":s("Voice input"),className:"mt-1 shrink-0"})]}),t?e.jsxs(e.Fragment,{children:[e.jsx(Zf,{}),e.jsx(Hf,{}),e.jsx(Jf,{})]}):null]})}function Qf(){const[s,t]=l.useState([]);return l.useEffect(()=>{const n=navigator.mediaDevices;if(!n?.enumerateDevices)return;let a=!0;const r=()=>{n.enumerateDevices().then(o=>{a&&t(o.filter(i=>i.kind==="audioinput"&&i.deviceId!==To&&i.deviceId!=="communications"))})};return r(),n.addEventListener("devicechange",r),()=>{a=!1,n.removeEventListener("devicechange",r)}},[]),s}function Zf(){const{t:s}=R(),t=g(o=>o.voiceInputDevice),n=g(o=>o.setVoiceInputDevice),a=Qf(),r=[{value:To,label:s("System default")},...a.map((o,i)=>({value:o.deviceId,label:o.label||s("Microphone {{n}}",{n:i+1})}))];return r.some(o=>o.value===t)||r.push({value:t,label:s("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:s("Microphone")}),e.jsxs(ne,{value:t,items:r,onValueChange:o=>n(String(o)),children:[e.jsx(ae,{className:"w-64",children:e.jsx(re,{})}),e.jsx(oe,{children:r.map(o=>e.jsx(Z,{value:o.value,children:o.label},o.value))})]})]})}const eg=32,sg=/^[A-Za-z0-9][A-Za-z0-9_:-]{0,127}$/,tg=/^[A-Za-z_][A-Za-z0-9_]{0,31}$/,ng=/\{\{\s*(?:args\.([A-Za-z_][A-Za-z0-9_]{0,31})|(prev))\s*\}\}/g;function gn(s,t){if(typeof s!="string")return null;const n=s.trim();return n&&n.length<=t?n:null}function ag(s,t){const n=[...new Set(s)].filter(a=>tg.test(a)).map(a=>({kind:"arg",key:a,token:`{{args.${a}}}`}));return t>0&&n.push({kind:"prev",token:"{{prev}}"}),n}function rg(s,t,n,a){const r=Math.min(Math.max(t,0),s.length),o=Math.min(Math.max(n,r),s.length);return{text:s.slice(0,r)+a+s.slice(o),cursor:r+a.length}}function og(s){if(!s||typeof s!="object"||Array.isArray(s))return null;const t=s,n=gn(t.label,80),a=gn(t.prompt,8e3),r=typeof t.agentType=="string"?t.agentType.trim():"";return!n||!a||r&&!sg.test(r)?null:{label:n,agentType:r,prompt:a}}function ig(s){if(!s||typeof s!="object"||Array.isArray(s))return null;const t=s,n=gn(t.title,80);if(!n||!Array.isArray(t.steps)||t.steps.length===0)return null;const a=t.steps.map(og);return a.every(r=>r!==null)?{title:n,steps:a}:null}function lg(s){if(!s||typeof s!="object"||Array.isArray(s))return null;const t=s.phases;if(!Array.isArray(t)||t.length===0)return null;const n=t.map(ig);return n.every(r=>r!==null)&&n.reduce((r,o)=>r+o.steps.length,0)<=eg?{phases:n}:null}function xi(s){const t=[];let n=0;for(const a of s.matchAll(ng))a.index>n&&t.push({kind:"text",text:s.slice(n,a.index)}),t.push(a[1]?{kind:"arg",key:a[1]}:{kind:"prev"}),n=a.index+a[0].length;return n<s.length&&t.push({kind:"text",text:s.slice(n)}),t}function cg(s){const t=xi(s).map(n=>n.kind==="text"?JSON.stringify(n.text):n.kind==="arg"?`String(args.${n.key} ?? '')`:"prev");return t.length>0?t.join(" + "):'""'}function dg({label:s,agentType:t,prompt:n}){const a=[`label: ${JSON.stringify(s)}`];return t&&a.push(`agentType: ${JSON.stringify(t)}`),` () => agent(${cg(n)}, { ${a.join(", ")} }),`}function hi(s){const t=["// 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 s.phases){const a=JSON.stringify(n.steps.map(r=>r.label));t.push("",`await phase(${JSON.stringify(n.title)});`,`prev = collect(${a}, await parallel([`,...n.steps.map(dg),"]));")}return t.push("","return prev;",""),t.join(`
24
+ `)}async function ug(s){const[t,n,a]=await Promise.all([xt(()=>import("./standalone-oyxre9MX.js"),[],import.meta.url),xt(()=>import("./babel-BktJt1uC.js"),[],import.meta.url),xt(()=>import("./estree-C_HWBWad.js"),[],import.meta.url)]);try{return{ok:!0,code:await t.format(s,{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(`
25
+ `)[0]??o}}}const mg=32,Js=(s,t)=>Math.max(0,Math.min(s,t));function xg(s){return s.phases.reduce((t,n)=>t+n.steps.length,0)<mg}function hg(s,t,n){const a=s.phases.map((r,o)=>o===t?{...r,steps:[...r.steps,n]}:r);return{design:{phases:a},selection:{kind:"step",phase:t,step:(a[t]?.steps.length??1)-1}}}function pg(s,t,n){const a=Js(t,s.phases.length),r=[...s.phases];return r.splice(a,0,n),{design:{phases:r},selection:{kind:"phase",phase:a}}}function Ir(s,t){const n=s.phases[t.phase];if(!n)return null;if(t.kind==="step"&&n.steps.length>1){const r=n.steps.filter((o,i)=>i!==t.step);return{design:{phases:s.phases.map((o,i)=>i===t.phase?{...o,steps:r}:o)},selection:{kind:"step",phase:t.phase,step:Js(t.step,r.length-1)}}}if(s.phases.length===1)return null;const a=s.phases.filter((r,o)=>o!==t.phase);return{design:{phases:a},selection:{kind:"phase",phase:Js(t.phase,a.length-1)}}}function Ar(s,t,n){const a=t+n;if(a<0||a>=s.phases.length||!s.phases[t])return{design:s,selection:{kind:"phase",phase:t}};const r=[...s.phases],[o]=r.splice(t,1);return o&&r.splice(a,0,o),{design:{phases:r},selection:{kind:"phase",phase:a}}}function fg(s,t){const n=Js(t.phase,s.phases.length-1);if(t.kind==="phase")return{kind:"phase",phase:n};const a=s.phases[n]?.steps.length??1;return{kind:"step",phase:n,step:Js(t.step,a-1)}}const sn="__default__",Er=(s="scout")=>({label:"",agentType:s,prompt:""});function gg({value:s,tokens:t,args:n,onChange:a}){const{t:r}=R(),o=l.useRef(null),i=()=>o.current?.querySelector("textarea")??null,m=x=>{const h=i(),c=s.length,f=rg(s,h?.selectionStart??c,h?.selectionEnd??c,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(Xe,{rows:5,className:"text-xs",placeholder:r("Prompt"),value:s,onChange:x=>a(x.target.value)}),e.jsxs(Io,{children:[e.jsxs(Ao,{disabled:t.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(Eo,{align:"start",zIndex:cs.DROPDOWN_IN_MODAL,finalFocus:i,children:t.map(x=>e.jsxs(Mo,{onClick:()=>m(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 Mr=(s,t,n,a)=>{const r=Math.max((n-s)/2,8);return`M${s},${t} C${s+r},${t} ${n-r},${a} ${n},${a}`};function jg(s,t){const[n,a]=l.useState([]);return l.useLayoutEffect(()=>{const r=s.current;if(!r)return;const o=()=>{const m=r.getBoundingClientRect(),u=r.offsetWidth?m.width/r.offsetWidth:1,x=f=>{const d=r.querySelector(f)?.getBoundingClientRect();return d?{left:(d.left-m.left)/u,right:(d.right-m.left)/u,y:(d.top-m.top+d.height/2)/u}:null},h=(f,d)=>f<0||f>=t.phases.length?[`[data-node="${d}"]`]:(t.phases[f]?.steps??[]).map((p,j)=>`[data-node="s-${f}-${j}"]`),c=[];for(let f=0;f<=t.phases.length;f++){const d=x(`[data-gap="${f}"]`);if(d){for(const p of h(f-1,"start")){const j=x(p);j&&c.push({d:Mr(j.right,j.y,d.left,d.y),arrow:!1})}for(const p of h(f,"end")){const j=x(p);j&&c.push({d:Mr(d.right,d.y,j.left-2,j.y),arrow:!0})}}}a(c)};o();const i=new ResizeObserver(o);return i.observe(r),()=>i.disconnect()},[s,t]),n}function Pr({node:s,icon:t,title:n,detail:a}){return e.jsxs("div",{"data-node":s,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:[t,n]}),e.jsx("span",{className:"w-full truncate text-[10px] text-muted-foreground",children:a})]})}function vg({prompt:s,args:t}){const{t:n}=R(),a=xi(s.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(l.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"):t.find(i=>i.key.trim()===r.key)?.label.trim()||r.key},o))})}function bg({design:s,agentTypes:t,args:n,onChange:a}){const{t:r}=R(),[o,i]=l.useState({kind:"step",phase:0,step:0}),m=l.useRef(null),u=l.useId(),x=jg(m,s),h=s.phases,c=fg(s,o),f=h[c.phase],d=c.kind==="step"?f?.steps[c.step]:void 0,p=t.includes("scout")?"scout":"",j=n.map(E=>E.key.trim()).filter(Boolean),b=xg(s),A=Ir(s,c)!==null,v=E=>{E&&(a(E.design),i(E.selection))},k=E=>a({phases:h.map((L,T)=>T===c.phase?{...L,...E}:L)}),I=E=>c.kind==="step"&&k({steps:(f?.steps??[]).map((L,T)=>T===c.step?{...L,...E}:L)}),M=E=>{const L=E&&!t.includes(E)?[...t,E]:t;return[{value:sn,label:r("Default (worker)")},...L.map(T=>({value:T,label:T}))]},$=E=>e.jsx("div",{className:"flex w-10 shrink-0 items-center justify-center self-stretch",children:e.jsx("button",{type:"button","data-gap":E,disabled:!b,"aria-label":r("Insert phase here"),title:r("Insert phase here"),onClick:()=>v(pg(s,E,{title:"",steps:[Er(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(Re,{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:m,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(E=>e.jsx("path",{d:E.d,fill:"none",stroke:"currentColor",strokeWidth:1.25,markerEnd:E.arrow?`url(#${u})`:void 0},E.d))]}),e.jsx(Pr,{node:"start",icon:e.jsx(Vd,{className:"h-3 w-3"}),title:r("Start"),detail:j.length>0?j.join(", "):r("No arguments")}),h.map((E,L)=>e.jsxs(l.Fragment,{children:[$(L),e.jsxs("div",{className:K("flex w-44 shrink-0 flex-col gap-1.5 rounded-xl border border-dashed bg-background/60 p-2",c.kind==="phase"&&c.phase===L&&"border-primary border-solid"),children:[e.jsxs("button",{type:"button",onClick:()=>i({kind:"phase",phase:L}),className:K("flex min-w-0 items-center gap-1 rounded px-1 text-left text-[11px] hover:text-foreground",E.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:E.title.trim()||r("Untitled phase")})]}),E.steps.map((T,C)=>{const S=c.kind==="step"&&c.phase===L&&c.step===C,W=!T.label.trim()||!T.prompt.trim();return e.jsxs("button",{type:"button","data-node":`s-${L}-${C}`,onClick:()=>i({kind:"step",phase:L,step:C}),className:K("block w-full rounded-lg border bg-background px-2.5 py-1.5 text-left shadow-xs transition-colors hover:border-primary/60",S&&"border-primary ring-2 ring-primary/20",W&&!S&&"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:T.label.trim()||r("Untitled step")}),e.jsx("span",{className:"ml-auto shrink-0 rounded bg-muted px-1 text-[10px] text-muted-foreground",children:T.agentType||"worker"})]}),e.jsx("span",{className:"mt-0.5 line-clamp-2 break-words text-[11px] text-muted-foreground",children:e.jsx(vg,{prompt:T.prompt,args:n})})]},C)}),e.jsxs("button",{type:"button",disabled:!b,onClick:()=>v(hg(s,L,Er(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(Re,{className:"h-3 w-3"}),r("Parallel step")]})]})]},L)),$(h.length),e.jsx(Pr,{node:"end",icon:e.jsx(Pu,{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:c.kind==="phase"?r("Phase {{n}}",{n:c.phase+1}):r("Phase {{n}} · Step {{m}}",{n:c.phase+1,m:c.step+1})}),e.jsxs("span",{className:"ml-auto flex items-center",children:[c.kind==="phase"&&e.jsxs(e.Fragment,{children:[e.jsx(y,{variant:"ghost",size:"icon-xs","aria-label":r("Move left"),disabled:c.phase===0,onClick:()=>v(Ar(s,c.phase,-1)),children:e.jsx(jo,{})}),e.jsx(y,{variant:"ghost",size:"icon-xs","aria-label":r("Move right"),disabled:c.phase===h.length-1,onClick:()=>v(Ar(s,c.phase,1)),children:e.jsx(Gd,{})})]}),e.jsx(y,{variant:"ghost",size:"icon-xs","aria-label":r("Delete"),disabled:!A,onClick:()=>v(Ir(s,c)),children:e.jsx(Pe,{})})]})]}),c.kind==="phase"||!d?e.jsx(J,{size:"sm",placeholder:r("Phase title"),value:f?.title??"",onChange:E=>k({title:E.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:d.label,onChange:E=>I({label:E.target.value})}),e.jsxs(ne,{items:M(d.agentType),value:d.agentType||sn,onValueChange:E=>I({agentType:E===sn?"":String(E??"")}),children:[e.jsx(ae,{size:"sm",className:"w-36 min-w-0 shrink-0",children:e.jsx(re,{})}),e.jsx(oe,{zIndex:cs.DROPDOWN_IN_MODAL,children:M(d.agentType).map(E=>e.jsx(Z,{value:E.value,children:E.label},E.value))})]})]}),e.jsx(gg,{value:d.prompt,tokens:ag(j,c.phase),args:n,onChange:E=>I({prompt:E})})]})]}),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 jn={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:
26
+
27
+ {{prev}}`}]}]},Tr={name:"",description:"",args:[{key:"topic",label:"Topic",required:!0}],design:jn,script:hi(jn)};function yg(s){return s.map(({key:t,label:n,default:a,required:r})=>({key:t.trim(),label:n.trim()||t.trim(),...a?.trim()?{default:a}:{},...r?{required:!0}:{}}))}function wg({target:s,onClose:t,onSaved:n}){const{t:a}=R(),[r,o]=l.useState(Tr),[i,m]=l.useState("design"),[u,x]=l.useState(0),h=l.useRef(null),[c,f]=l.useState(!1),[d,p]=l.useState(!1),[j,b]=l.useState(!1),[A,v]=l.useState(null),k=g(N=>N.disabledBuiltinAgentTypes),I=g(N=>N.agentTypes),M=l.useMemo(()=>[...Wd.map(N=>N.name).filter(N=>!k.includes(N)),...I.map(N=>N.name)],[k,I]);l.useEffect(()=>{if(v(null),s===null)return;if(h.current=null,x(z=>z+1),s==="new"){o(Tr),m("design");return}let N=!1;return f(!0),window.electronAPI.workflowPresets.read(s).then(z=>{if(!N)if(z){const{id:H,...U}=z;o(U),m(U.design?"design":"code"),x(B=>B+1)}else v(a("Failed to read content"))}).finally(()=>{N||f(!1)}),()=>{N=!0}},[s,a]);const $=N=>o(z=>({...z,...N})),E=(N,z)=>$({args:r.args.map((H,U)=>U===N?{...H,...z}:H)}),L=N=>$({design:N,script:hi(N)}),T=N=>{N!==r.script&&(r.design&&(h.current=r.design),o(z=>({...z,script:N,design:void 0})))},C=async()=>{b(!0);const N=await ug(r.script);if(b(!1),!N.ok){v(a("Format failed: {{error}}",{error:N.error}));return}v(null),N.code!==r.script&&(T(N.code),x(z=>z+1))},S=!r.design||lg(r.design)!==null,W=!c&&!d&&r.name.trim()!==""&&r.description.trim()!==""&&S&&r.script.trim()!=="",q=async()=>{if(!W||s===null)return;p(!0);const N=await window.electronAPI.workflowPresets.save({...r,args:yg(r.args)},s==="new"?void 0:s);if(p(!1),!N.ok){v(a(N.error));return}n(),t()};return e.jsx(ye,{open:s!==null,onOpenChange:N=>!N&&t(),children:e.jsxs(we,{className:"max-w-4xl",children:[e.jsx(Ne,{children:e.jsx(ke,{children:a(s==="new"?"Add workflow preset":"Edit workflow preset")})}),e.jsxs(Ce,{className:"space-y-4",children:[e.jsxs(he,{children:[e.jsx(pe,{children:a("Name")}),e.jsx(J,{value:r.name,onChange:N=>$({name:N.target.value})})]}),e.jsxs(he,{children:[e.jsx(pe,{children:a("Description")}),e.jsx(J,{value:r.description,onChange:N=>$({description:N.target.value})})]}),e.jsxs(he,{children:[e.jsx(pe,{children:a("Arguments")}),e.jsxs("div",{className:"w-full space-y-1.5",children:[r.args.map((N,z)=>e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(J,{size:"sm",className:"w-28 font-mono",placeholder:"key",value:N.key,onChange:H=>E(z,{key:H.target.value})}),e.jsx(J,{size:"sm",className:"flex-1",placeholder:a("Label"),value:N.label,onChange:H=>E(z,{label:H.target.value})}),e.jsx(J,{size:"sm",className:"flex-1",placeholder:a("Default value"),value:N.default??"",onChange:H=>E(z,{default:H.target.value})}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1 text-muted-foreground text-xs",children:[e.jsx(Le,{checked:N.required===!0,onCheckedChange:H=>E(z,{required:H===!0})}),a("Required")]}),e.jsx(y,{variant:"ghost",size:"icon-xs","aria-label":a("Remove"),onClick:()=>$({args:r.args.filter((H,U)=>U!==z)}),children:e.jsx(js,{})})]},z)),e.jsxs(y,{variant:"outline",size:"xs",disabled:r.args.length>=8,onClick:()=>$({args:[...r.args,{key:"",label:""}]}),children:[e.jsx(Re,{}),a("Add argument")]})]})]}),e.jsxs(he,{children:[e.jsxs("div",{className:"flex w-full items-center justify-between gap-2",children:[e.jsx(pe,{children:a("Steps")}),i==="code"&&e.jsxs(y,{variant:"ghost",size:"xs",className:"ml-auto",disabled:c||j||!!r.design||!r.script.trim(),title:r.design?a("Generated code is already formatted"):void 0,onClick:C,children:[j?e.jsx(Me,{className:"animate-spin"}):e.jsx(Hd,{}),a("Format")]}),e.jsx(Qs,{value:i,onValueChange:N=>m(N),children:e.jsxs(Zs,{children:[e.jsx(Je,{value:"design",children:a("Design")}),e.jsx(Je,{value:"code",children:a("Code")})]})})]}),c?e.jsx("div",{className:"flex w-full items-center justify-center rounded-md border py-12",children:e.jsx(Me,{className:"h-4 w-4 animate-spin text-muted-foreground"})}):i==="design"?r.design?e.jsx(bg,{design:r.design,agentTypes:M,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(y,{variant:"outline",size:"xs",onClick:()=>L(h.current??jn),children:a("Use the designer")})]}):e.jsx(qo,{fileName:"workflow.js",className:"h-80",value:r.script,epoch:u,onChange:T}),e.jsx("p",{className:"text-muted-foreground text-xs",children:i==="design"?!S&&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.")})]}),A&&e.jsxs("p",{className:"flex items-center gap-1.5 text-destructive text-xs",children:[e.jsx(Rs,{className:"h-3.5 w-3.5 shrink-0"}),A]})]}),e.jsxs(Ee,{children:[e.jsx(y,{variant:"outline",size:"sm",onClick:t,children:a("Cancel")}),e.jsxs(y,{size:"sm",disabled:!W,onClick:q,children:[d&&e.jsx(Me,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}),a("Save")]})]})]})})}function Ng(){const{t:s}=R(),[t,n]=l.useState([]),[a,r]=l.useState(null),o=g(h=>h.disabledWorkflowPresets),i=g(h=>h.toggleWorkflowPreset),m=l.useCallback(()=>{window.electronAPI.workflowPresets.list().then(n)},[]);l.useEffect(m,[m]);const u=t.filter(h=>h.source!=="builtin"),x=t.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:s("Workflows")}),e.jsx("p",{className:"text-muted-foreground text-sm",children:s("Preset workflows you can run from the Workflow side panel")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Project .agents/workflows files take precedence over these; ~/.agents/workflows and built-in presets come after.")})]}),e.jsxs(y,{variant:"outline",size:"sm",onClick:()=>r("new"),children:[e.jsx(Re,{className:"mr-1.5 h-4 w-4"}),s("Add workflow preset")]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium text-muted-foreground text-xs",children:s("Custom presets")}),u.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx(Dn,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:s("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(se,{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(y,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100","aria-label":s("Edit"),onClick:()=>r(h.id),children:e.jsx(hs,{className:"h-3.5 w-3.5"})}),e.jsx(y,{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":s("Delete"),onClick:()=>{window.electronAPI.workflowPresets.delete(h.id).then(m)},children:e.jsx(Pe,{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:s("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:s(h.name)}),e.jsx(se,{variant:"secondary",className:"shrink-0 font-mono text-[11px]",children:h.id})]}),e.jsx("p",{className:"text-muted-foreground text-xs",children:s(h.description)}),h.args.length>0&&e.jsxs("p",{className:"mt-0.5 text-muted-foreground text-xs",children:[s("Arguments"),":"," ",h.args.map(c=>`${s(c.label)}${c.required?" *":""}`).join(" · ")]})]}),e.jsx(ce,{"aria-label":s(h.name),checked:!o.includes(h.id),onCheckedChange:c=>i(h.id,c)})]},h.id))})]}),e.jsx(wg,{target:a,onClose:()=>r(null),onSaved:m})]})}function kg(s){window.requestAnimationFrame(()=>{const t=document.querySelector(`[data-settings-row="${CSS.escape(s)}"]`);t instanceof HTMLElement&&(t.scrollIntoView({block:"center"}),t.dataset.settingsFlash="true",window.setTimeout(()=>{delete t.dataset.settingsFlash},1600))})}function Rr(){const{t:s}=R(),[t,n]=l.useState("general"),[a,r]=l.useState(null),[o,i]=l.useState(null),[m,u]=l.useState(null),[x,h]=l.useState(null),[c,f]=l.useState(0),d=qd(),[p,j]=l.useState(!0),[b,A]=l.useState(""),[v,k]=l.useState([]),I=F=>{n(F),j(!1)},M=g(F=>F.disabledBuiltinTools),$=g(F=>F.botModeEnabled),E=g(F=>F.secretaryEnabled),L=l.useSyncExternalStore(F=>g.persist?.onFinishHydration?.(F)??(()=>{}),()=>g.persist?.hasHydrated?.()??!0),T=l.useCallback(F=>{n(F.category),j(!1),r(F.rowId),F.pluginInstallUrl&&i(F.pluginInstallUrl),u(F.pluginId??null),h(F.marketQuery??null)},[]);l.useEffect(()=>(window.electronAPI.window.consumeSettingsDeepLink().then(F=>{F&&T(F)}),window.electronAPI.window.onSettingsDeepLink(T)),[T]),l.useEffect(()=>{let F=!0;return window.electronAPI.sshConnections.list().then(X=>{F&&k(X.map(V=>({id:V.id,name:V.name})))}).catch(()=>{F&&k([])}),()=>{F=!1}},[]);const C=Yd(v);l.useLayoutEffect(()=>{if(!a)return;kg(a);const F=window.setTimeout(()=>r(null),1600);return()=>window.clearTimeout(F)},[a]);const W=Sf([{id:"general",icon:eu,label:"General"},{id:"shortcuts",icon:su,label:"Shortcuts"},{id:"voice",icon:tu,label:"Voice input"},{id:"appearance",icon:Fu,label:"Appearance"},{id:"providers",icon:_n,label:"Model Providers"},{id:"presets",icon:nu,label:"Presets"},{id:"agents",icon:au,label:"Agent types"},{id:"tools",icon:to,label:"Built-in tools"},{id:"workflows",icon:Dn,label:"Workflows"},{id:"memory",icon:eo,label:"Memory"},{id:"privacy",icon:ru,label:"Privacy"},{id:"skills",icon:Po,label:"Skills"},{id:"plugins",icon:Xs,label:"Enso plugins"},{id:"claudePlugins",icon:vu,label:"Claude Code plugins"},{id:"mcp",icon:mo,label:"MCP Servers"},{id:"instructions",icon:Ln,label:"Instruction Files"},{id:"phone",icon:an,label:"Devices"},{id:"ssh",icon:Wr,label:"SSH"},{id:"usage",icon:Cu,label:"Usage"},{id:"resources",icon:ou,label:"Resources"},{id:"experimental",icon:iu,label:"Experimental"},{id:"bots",icon:lu,label:"Bot mode",sub:!0},{id:"botTemplates",icon:cu,label:"Bot templates",sub:!0},{id:"secretary",icon:du,label:"Secretary",sub:!0}],M,$,E||!L),q=Cf(Af(W,C,b,s)),N=If(t,M,$||!L,E||!L);l.useEffect(()=>{N!==t&&n(N)},[N,t]);const z=!d||p,H=!d||!p,U=W.find(F=>F.id===t)?.label,B=Jd(),ie=Ro();return e.jsxs("div",{className:"flex h-full w-full",children:[z&&e.jsxs("nav",{"data-enso":"settings-nav",className:K("flex min-h-0 shrink-0 flex-col",d?"w-full":B?"w-56":"w-56 border-r"),children:[B&&ie==="mac"&&e.jsx("div",{"aria-hidden":!0,className:"drag-region -mb-2 h-[44px] shrink-0"}),e.jsx("div",{className:K("sticky top-0 z-10 px-2 pt-2",!B&&"bg-background"),children:e.jsxs("div",{className:"relative",children:[e.jsx(so,{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:b,onChange:F=>A(F.target.value),onKeyDown:F=>{F.key!=="Escape"||b.length===0||(F.preventDefault(),F.stopPropagation(),A(""))},placeholder:s("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:b.trim()&&q.length===0?e.jsx("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:s("No results")}):q.map((F,X)=>e.jsxs("div",{className:K(X>0&&"mt-4"),children:[e.jsx("div",{className:"px-2 pb-1.5 text-xs font-semibold text-foreground/55",children:s(F.label)}),e.jsx("div",{className:"space-y-0.5 rounded-lg bg-muted/60 p-1",children:F.items.map(V=>e.jsxs("div",{children:[e.jsxs("button",{type:"button",onClick:()=>I(V.id),className:K("flex w-full items-center gap-2 rounded-md px-3 text-sm transition-colors",d?"py-3":"py-1.5",V.sub&&"pl-8",t===V.id&&!d?"bg-background text-foreground shadow-xs":"text-muted-foreground hover:bg-background/60 hover:text-foreground"),children:[e.jsx(V.icon,{className:"h-4 w-4"}),s(V.label),d&&e.jsx(Ds,{className:"ml-auto h-4 w-4 opacity-60"})]}),V.hits.map(le=>e.jsx("button",{type:"button",onClick:()=>{I(V.id),r(le.id)},className:K("block w-full truncate rounded-md pr-3 text-left text-xs text-muted-foreground hover:bg-background/60 hover:text-foreground",V.sub?"pl-14":"pl-9",d?"py-2":"py-1"),children:s(le.title)},le.id))]},V.id))})]},F.id))})]}),H&&e.jsxs("div",{"data-enso":"settings-content",className:K("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(Xd,{"data-enso":"title-bar"}),e.jsxs("div",{className:K("min-h-0 flex-1 overflow-y-auto",d?"px-4 pb-6":B?"px-6 pb-6":"p-6"),children:[d&&e.jsxs("button",{type:"button",onClick:()=>j(!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(qr,{className:"h-5 w-5 text-muted-foreground"}),U?s(U):null]}),t==="general"&&e.jsx(Pm,{}),t==="shortcuts"&&e.jsx(Vx,{}),t==="appearance"&&e.jsx(ox,{onOpenPlugins:()=>I("plugins")}),t==="providers"&&e.jsx(Jp,{}),t==="skills"&&e.jsx(bf,{}),t==="plugins"&&e.jsx(Mp,{requestedInstallUrl:o,onRequestedInstallUrlConsumed:()=>i(null),focusPluginId:m,onFocusPluginConsumed:()=>u(null),requestedMarketQuery:x,onRequestedMarketQueryConsumed:()=>h(null)}),t==="claudePlugins"&&e.jsx(Rp,{}),t==="mcp"&&e.jsx(xh,{}),t==="instructions"&&e.jsx($x,{}),t==="presets"&&e.jsx(Qd,{}),t==="agents"&&e.jsx(Zd,{}),t==="workflows"&&e.jsx(Ng,{}),t==="tools"&&e.jsx(Px,{}),t==="memory"&&e.jsxs("div",{className:"space-y-8",children:[e.jsx(dp,{onLibraryChanged:()=>f(F=>F+1)}),e.jsx(Sh,{revision:c}),e.jsx(Uh,{revision:c})]}),t==="phone"&&e.jsx(Ox,{}),t==="ssh"&&e.jsx(yf,{}),t==="usage"&&e.jsx(Gf,{}),t==="privacy"&&e.jsx(Bp,{}),t==="resources"&&e.jsx(nf,{}),t==="voice"&&e.jsx(Xf,{}),t==="experimental"&&e.jsx(Bx,{onOpenBots:()=>n("bots")}),t==="bots"&&e.jsx(xx,{}),t==="botTemplates"&&e.jsx(yx,{}),t==="secretary"&&e.jsx(vf,{})]})]})]})}uu();mu();function Cg(){const{t:s}=R(),t=Ro();return t!=="mobile"&&t!=="web"?e.jsxs("div",{"data-enso":"canvas",className:"flex h-screen overflow-hidden bg-canvas",children:[e.jsx(Na,{}),e.jsx(hu.Provider,{value:{trailing:e.jsx(pu,{kind:t,edgeGap:8})},children:e.jsx(Rr,{})}),e.jsx(ka,{}),e.jsx(Ca,{})]}):e.jsxs("div",{className:"flex h-screen flex-col overflow-hidden",children:[e.jsx(Na,{}),e.jsx(fu,{title:s("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":s("Close"),title:s("Close"),children:e.jsx(js,{className:"h-4 w-4"})})}),e.jsx("main",{className:"min-h-0 flex-1 overflow-hidden",children:e.jsx(Rr,{})}),e.jsx(ka,{}),e.jsx(Ca,{})]})}xu.createRoot(document.getElementById("root")).render(e.jsx(l.StrictMode,{children:e.jsx(Cg,{})}));