@ensocode/server 0.3.8 → 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 (171) hide show
  1. package/out/phone/assets/{abnfDiagram-VCTEODGH-BYULU5bQ.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-B9-XfmwY.js → architectureDiagram-5GKGNRK7-Uwi4Yp3N.js} +1 -1
  4. package/out/phone/assets/{blockDiagram-I7D4REHJ-BDjx5h4I.js → blockDiagram-I7D4REHJ-Dee88kBX.js} +1 -1
  5. package/out/phone/assets/{c4Diagram-7LVT6UL2-BLCrWT5z.js → c4Diagram-7LVT6UL2-CPVctMym.js} +1 -1
  6. package/out/phone/assets/channel-DKcROQS8.js +1 -0
  7. package/out/phone/assets/{chunk-4HAMMTFA-CBLX5PPK.js → chunk-4HAMMTFA-DdHZ8tzu.js} +1 -1
  8. package/out/phone/assets/{chunk-75Z2AOVW-BjNsM64u.js → chunk-75Z2AOVW-CXd1zaQL.js} +1 -1
  9. package/out/phone/assets/{chunk-DU6HZSFF-D32XGmy5.js → chunk-DU6HZSFF-K72dP1XP.js} +1 -1
  10. package/out/phone/assets/{chunk-F27PBJKO-DYrJ0RKS.js → chunk-F27PBJKO-JZyoOZLJ.js} +1 -1
  11. package/out/phone/assets/{chunk-GMAD6QVW-C8yUEx5a.js → chunk-GMAD6QVW-O3x_QcGA.js} +1 -1
  12. package/out/phone/assets/{chunk-GVQU2GXP-nOF6gFr6.js → chunk-GVQU2GXP-g5OZYD2B.js} +1 -1
  13. package/out/phone/assets/{chunk-IMKFNOWR-Bw90xROV.js → chunk-IMKFNOWR-r0ScpN_y.js} +1 -1
  14. package/out/phone/assets/{chunk-L3NEJ4N5-hIXFqCYn.js → chunk-L3NEJ4N5-O-r4RmZJ.js} +1 -1
  15. package/out/phone/assets/{chunk-OSK3NFVY-CDR6cbF7.js → chunk-OSK3NFVY-ramCCXI9.js} +1 -1
  16. package/out/phone/assets/{chunk-P2QGCYS3-B5LBNgEn.js → chunk-P2QGCYS3-DD3uRJ3h.js} +1 -1
  17. package/out/phone/assets/{chunk-POPQ4Y6H-Ctie8lW0.js → chunk-POPQ4Y6H-RiL5jwG6.js} +1 -1
  18. package/out/phone/assets/{chunk-PWAF6VOD-VUQ3ZQa0.js → chunk-PWAF6VOD-YKF2LrOr.js} +1 -1
  19. package/out/phone/assets/{chunk-SHT3W25Y-ThT795xc.js → chunk-SHT3W25Y-NK2MDUJG.js} +1 -1
  20. package/out/phone/assets/{chunk-SVP7TREG-DaLedBcS.js → chunk-SVP7TREG-7bCZBtZP.js} +1 -1
  21. package/out/phone/assets/{chunk-TICWLB2K-EZdof5x9.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-s8d8cA90.js → cynefin-OW5HDTMX-C3bBDDKw.js} +1 -1
  25. package/out/phone/assets/{cynefinDiagram-5FMLGOSQ-BvUrZrEv.js → cynefinDiagram-5FMLGOSQ-B1KRMzP2.js} +1 -1
  26. package/out/phone/assets/{dagre-GXQ25YYZ-Y4KQyhxZ.js → dagre-GXQ25YYZ-NLxwj9wy.js} +1 -1
  27. package/out/phone/assets/{desk-BpEz3CoY.js → desk-DfeUjqmj.js} +1 -1
  28. package/out/phone/assets/{diagram-S7CK7UJ4-BOnQE44W.js → diagram-S7CK7UJ4-DfcfBkAs.js} +1 -1
  29. package/out/phone/assets/{diagram-UQ7AKVKN-DinAxyUq.js → diagram-UQ7AKVKN-DCvI1s7K.js} +1 -1
  30. package/out/phone/assets/{diagram-VSXAHHWV-1SZEAZcR.js → diagram-VSXAHHWV-Bm1zOS5P.js} +1 -1
  31. package/out/phone/assets/{diagram-VX7I27RA-CeqFT5PL.js → diagram-VX7I27RA-BQuZufNO.js} +1 -1
  32. package/out/phone/assets/{diagram-Z3DM3KII-CKUQZLUU.js → diagram-Z3DM3KII-DBIMQQh6.js} +1 -1
  33. package/out/phone/assets/{ebnfDiagram-PWID7BFC-D-vPzzm8.js → ebnfDiagram-PWID7BFC-tVvJnbJ2.js} +1 -1
  34. package/out/phone/assets/{erDiagram-RLTQ6QDP--yabuiWQ.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-DuceHpP7.js → ganttDiagram-EL5Y4UJY-DTQdTWJN.js} +1 -1
  38. package/out/phone/assets/{gitGraph-4MIJSDKK-Dy69JGci.js → gitGraph-4MIJSDKK-DP-rU0q-.js} +1 -1
  39. package/out/phone/assets/{gitGraphDiagram-WWUBYQGX-DAsGy8VO.js → gitGraphDiagram-WWUBYQGX-v56Bt0O6.js} +1 -1
  40. package/out/phone/assets/{info-A6RAGUB7-Bi2rn7zz.js → info-A6RAGUB7-CAQE0Hfy.js} +1 -1
  41. package/out/phone/assets/{infoDiagram-27XIBGKW-DLYnX9vk.js → infoDiagram-27XIBGKW-CSXtf5Fo.js} +1 -1
  42. package/out/phone/assets/{ishikawaDiagram-5VMMS53U-frgoq43k.js → ishikawaDiagram-5VMMS53U-CclPV6gG.js} +1 -1
  43. package/out/phone/assets/{journeyDiagram-3NMN7TZE-LfNbEnHq.js → journeyDiagram-3NMN7TZE-BIkpYm1f.js} +1 -1
  44. package/out/phone/assets/{kanban-definition-UXKFOSKX-BYOUPJHU.js → kanban-definition-UXKFOSKX-yepY9S2l.js} +1 -1
  45. package/out/phone/assets/{line-_FhXTvX4.js → line-BeTXpSNc.js} +1 -1
  46. package/out/phone/assets/main-CGpGZfti.css +1 -0
  47. package/out/phone/assets/{main-CfWT8VXG.js → main-DW3B3ovc.js} +112 -110
  48. package/out/phone/assets/{mermaid-parser.core-ByliMPZm.js → mermaid-parser.core-nw37szCl.js} +3 -3
  49. package/out/phone/assets/{mermaid.core-Mmd8_4Nr.js → mermaid.core-DdSdNZO_.js} +4 -4
  50. package/out/phone/assets/{mindmap-definition-YA3MSWOX-C96rrhDe.js → mindmap-definition-YA3MSWOX-CiQWyjG5.js} +1 -1
  51. package/out/phone/assets/{packet-AYTQ26CC-CMANaRii.js → packet-AYTQ26CC-MFESxWKw.js} +1 -1
  52. package/out/phone/assets/{pegDiagram-XKGWAZYB-CGL6jEdQ.js → pegDiagram-XKGWAZYB-BM9Ofbc8.js} +1 -1
  53. package/out/phone/assets/{pie-WAS4IAKB-Dqr8Yw0J.js → pie-WAS4IAKB-BX8j-oF_.js} +1 -1
  54. package/out/phone/assets/{pieDiagram-E7YTZNPT-CFhX0DbB.js → pieDiagram-E7YTZNPT-1KLqp5sl.js} +1 -1
  55. package/out/phone/assets/{quadrantDiagram-AXDQQJYC-CIy7q7Mf.js → quadrantDiagram-AXDQQJYC-wqwWQyRe.js} +1 -1
  56. package/out/phone/assets/{radar-RG4KPBEZ-Lx6rDXGt.js → radar-RG4KPBEZ-jaQ0-Att.js} +1 -1
  57. package/out/phone/assets/{railroad-74A4TZTK-CFfqCtSc.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-NmlxNdEs.js → railroadDiagram-O6MQD6OU-DJQ-7iWl.js} +1 -1
  62. package/out/phone/assets/{requirementDiagram-BXWQKSXE-C1PDc05u.js → requirementDiagram-BXWQKSXE-D4dveBtm.js} +1 -1
  63. package/out/phone/assets/{sankeyDiagram-P5KCCOFB-CfwTCG6L.js → sankeyDiagram-P5KCCOFB-Xi3vzQcH.js} +1 -1
  64. package/out/phone/assets/{sequenceDiagram-WJ2MYXX4-A-L3mYui.js → sequenceDiagram-WJ2MYXX4-DJu7wXTv.js} +1 -1
  65. package/out/phone/assets/{stateDiagram-D77RDMKH-nRUGxe4_.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-DU47Rb1q.js → storage-dUWOZ2xo.js} +2 -2
  68. package/out/phone/assets/{swimlanes-42K2YHIH-7K-yTToK.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-DXbVHlED.js → timeline-definition-24CTP7MA-e-O3IHwG.js} +1 -1
  71. package/out/phone/assets/{treeView-Q6P3EWNA-M_osDfi3.js → treeView-Q6P3EWNA-Bhtyuzk0.js} +1 -1
  72. package/out/phone/assets/{treemap-WGGIJYW6-BMi5B7KJ.js → treemap-WGGIJYW6-B_tM9CqS.js} +1 -1
  73. package/out/phone/assets/{vennDiagram-4TSXK5OY-D3EpIx9s.js → vennDiagram-4TSXK5OY-9npu53KS.js} +1 -1
  74. package/out/phone/assets/{wardley-WFR3VGLG-nB8yKilO.js → wardley-WFR3VGLG-Dtb3_st-.js} +1 -1
  75. package/out/phone/assets/{wardleyDiagram-VM6X3IG4-DSghcmRr.js → wardleyDiagram-VM6X3IG4-DCBObiQg.js} +1 -1
  76. package/out/phone/assets/{xychartDiagram-S5SC5T6Z-BEl0ProS.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-BB3W0IRN.js → abnfDiagram-VCTEODGH-ClaZATP-.js} +1 -1
  80. package/out/renderer/assets/{arc-r0xtJ5ab.js → arc-B0Ue52gX.js} +1 -1
  81. package/out/renderer/assets/{architectureDiagram-5GKGNRK7-BC8Ww6fQ.js → architectureDiagram-5GKGNRK7-CbmNLvfJ.js} +1 -1
  82. package/out/renderer/assets/{blockDiagram-I7D4REHJ-wup9ZluJ.js → blockDiagram-I7D4REHJ-crBSO4mg.js} +1 -1
  83. package/out/renderer/assets/{c4Diagram-7LVT6UL2-BwWATTxt.js → c4Diagram-7LVT6UL2-BhASES00.js} +1 -1
  84. package/out/renderer/assets/channel-DAEAroq1.js +1 -0
  85. package/out/renderer/assets/{chunk-2Q5K7J3B-Dw4JQaKM.js → chunk-2Q5K7J3B-CCY1-54C.js} +1 -1
  86. package/out/renderer/assets/{chunk-5VM5RSS4-p6eptEa6.js → chunk-5VM5RSS4-MmFztUTQ.js} +1 -1
  87. package/out/renderer/assets/{chunk-F27PBJKO-crFPFXKS.js → chunk-F27PBJKO-CemaMYDJ.js} +1 -1
  88. package/out/renderer/assets/{chunk-IMKFNOWR-Bnu9wgyD.js → chunk-IMKFNOWR-DctUdkub.js} +1 -1
  89. package/out/renderer/assets/{chunk-JWPE2WC7-B8Xhiasd.js → chunk-JWPE2WC7-DCjmZlft.js} +1 -1
  90. package/out/renderer/assets/{chunk-POPQ4Y6H-Cgaq3GTd.js → chunk-POPQ4Y6H-D-KxWwr4.js} +1 -1
  91. package/out/renderer/assets/{chunk-SVP7TREG-Dxz3ENUO.js → chunk-SVP7TREG-CGc3VMbe.js} +1 -1
  92. package/out/renderer/assets/{chunk-TICWLB2K-DKsdmE8K.js → chunk-TICWLB2K-BwI6l28m.js} +1 -1
  93. package/out/renderer/assets/{chunk-XXDRQBXY-D4zS63eZ.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-Cd7k91g4.js → cose-bilkent-JH36ORCC-DqGFhKtY.js} +1 -1
  97. package/out/renderer/assets/{cynefin-OW5HDTMX-qIf7N9zE.js → cynefin-OW5HDTMX-BpknO3Y_.js} +1 -1
  98. package/out/renderer/assets/{cynefinDiagram-5FMLGOSQ-DZq47G9W.js → cynefinDiagram-5FMLGOSQ-DS1vS0h7.js} +1 -1
  99. package/out/renderer/assets/{cytoscape-fcose-BUV0U04U.js → cytoscape-fcose-DeHY1J1u.js} +1 -1
  100. package/out/renderer/assets/{dagre-GXQ25YYZ-jHWFk6Gs.js → dagre-GXQ25YYZ-DxScp9AG.js} +1 -1
  101. package/out/renderer/assets/{diagram-S7CK7UJ4-BM99y_vq.js → diagram-S7CK7UJ4-Djlu9ceY.js} +1 -1
  102. package/out/renderer/assets/{diagram-UQ7AKVKN-DWw2eBQS.js → diagram-UQ7AKVKN-BK3mHHvd.js} +1 -1
  103. package/out/renderer/assets/{diagram-VSXAHHWV-BpQqnXFN.js → diagram-VSXAHHWV-Bg9tDRjc.js} +1 -1
  104. package/out/renderer/assets/{diagram-VX7I27RA-DIwy3ILe.js → diagram-VX7I27RA-DrWUeEXG.js} +1 -1
  105. package/out/renderer/assets/{diagram-Z3DM3KII-CyggPXCP.js → diagram-Z3DM3KII-BxPy8fU9.js} +1 -1
  106. package/out/renderer/assets/{ebnfDiagram-PWID7BFC-BW1zQBfH.js → ebnfDiagram-PWID7BFC-BWqMH4I8.js} +1 -1
  107. package/out/renderer/assets/{erDiagram-RLTQ6QDP-DeBd9wgY.js → erDiagram-RLTQ6QDP-DTdklRgf.js} +1 -1
  108. package/out/renderer/assets/{flowDiagram-HODETNUW-DuHDP4W5.js → flowDiagram-HODETNUW-BKIZ7ju6.js} +1 -1
  109. package/out/renderer/assets/{ganttDiagram-EL5Y4UJY-BWzm5BP7.js → ganttDiagram-EL5Y4UJY-BxvJsq6b.js} +1 -1
  110. package/out/renderer/assets/{gitGraphDiagram-WWUBYQGX-BVW6A1c7.js → gitGraphDiagram-WWUBYQGX-CKYXaYvq.js} +1 -1
  111. package/out/renderer/assets/globals-DoK2OLv9.css +1 -0
  112. package/out/renderer/assets/{globals-BTwoz2I6.js → globals-kfeSrZZh.js} +214 -214
  113. package/out/renderer/assets/index-oWFcXlIg.js +133 -0
  114. package/out/renderer/assets/{infoDiagram-27XIBGKW-BnQ0QqrX.js → infoDiagram-27XIBGKW-B79kbTEz.js} +1 -1
  115. package/out/renderer/assets/{ishikawaDiagram-5VMMS53U-C8Kybb7-.js → ishikawaDiagram-5VMMS53U-7A2txHe5.js} +1 -1
  116. package/out/renderer/assets/{journeyDiagram-3NMN7TZE-BFN7ls5V.js → journeyDiagram-3NMN7TZE-JNKKQMwS.js} +1 -1
  117. package/out/renderer/assets/{kanban-definition-UXKFOSKX-DDNfT2Ap.js → kanban-definition-UXKFOSKX-dK6zSfqM.js} +1 -1
  118. package/out/renderer/assets/{layout-DG726kRG.js → layout-MfkXYuHA.js} +1 -1
  119. package/out/renderer/assets/{linear-CyRBABsR.js → linear-DUiegqFS.js} +1 -1
  120. package/out/renderer/assets/{mermaid.core-DPQo0NhF.js → mermaid.core-Dn6T9UVK.js} +5 -5
  121. package/out/renderer/assets/{mindmap-definition-YA3MSWOX-BKjiHq0N.js → mindmap-definition-YA3MSWOX-Du0yA8rg.js} +1 -1
  122. package/out/renderer/assets/{pegDiagram-XKGWAZYB-cGBsq_Dp.js → pegDiagram-XKGWAZYB-DaRtM-Te.js} +1 -1
  123. package/out/renderer/assets/{pieDiagram-E7YTZNPT-CB8FqRel.js → pieDiagram-E7YTZNPT-Bsf9CqyI.js} +1 -1
  124. package/out/renderer/assets/{quadrantDiagram-AXDQQJYC-CZsQnmHv.js → quadrantDiagram-AXDQQJYC-Diojakd2.js} +1 -1
  125. package/out/renderer/assets/{railroadDiagram-O6MQD6OU-CtHtwIss.js → railroadDiagram-O6MQD6OU-BMREAMLm.js} +1 -1
  126. package/out/renderer/assets/{requirementDiagram-BXWQKSXE-C8IKRBmx.js → requirementDiagram-BXWQKSXE-KYN9y0mn.js} +1 -1
  127. package/out/renderer/assets/{sankeyDiagram-P5KCCOFB-DxIvac4Q.js → sankeyDiagram-P5KCCOFB-BOarV1lP.js} +1 -1
  128. package/out/renderer/assets/{sequenceDiagram-WJ2MYXX4-CW0GnaxQ.js → sequenceDiagram-WJ2MYXX4-CLvIIq-e.js} +1 -1
  129. package/out/renderer/assets/settings-C1ake4C5.js +27 -0
  130. package/out/renderer/assets/{sizeCapture-INFHLROL-CUNNzORL.js → sizeCapture-INFHLROL-BZp_C1e1.js} +1 -1
  131. package/out/renderer/assets/{stateDiagram-D77RDMKH-b6LNqPfN.js → stateDiagram-D77RDMKH-CZYezuvN.js} +1 -1
  132. package/out/renderer/assets/stateDiagram-v2-MP3YSRHH-BZR_zNTR.js +1 -0
  133. package/out/renderer/assets/{swimlanes-42K2YHIH-C2Pjkv6k.js → swimlanes-42K2YHIH-BzLF-RZ8.js} +1 -1
  134. package/out/renderer/assets/swimlanesDiagram-VR7AAH4N-CguqA7f1.js +8 -0
  135. package/out/renderer/assets/{timeline-definition-24CTP7MA-DVo6WWfn.js → timeline-definition-24CTP7MA-uG42f1oC.js} +1 -1
  136. package/out/renderer/assets/{vennDiagram-4TSXK5OY-I_UOGgKE.js → vennDiagram-4TSXK5OY-DTog5Yh9.js} +1 -1
  137. package/out/renderer/assets/{wardleyDiagram-VM6X3IG4-pgaJTE-_.js → wardleyDiagram-VM6X3IG4-BgQ7fmC4.js} +1 -1
  138. package/out/renderer/assets/{xychartDiagram-S5SC5T6Z-C0CTpbX7.js → xychartDiagram-S5SC5T6Z-BerG1RDT.js} +1 -1
  139. package/out/renderer/index.html +3 -3
  140. package/out/renderer/settings.html +4 -4
  141. package/out/renderer/web-preload.js +1 -1
  142. package/out/server/agent.js +62 -15
  143. package/out/server/chunks/{agent-2QNVhuY3.js → agent-BbLTL3oo.js} +175 -164
  144. package/out/server/chunks/conversationsMove-CJZfkj55.js +57 -0
  145. package/out/server/chunks/{gpuBackendInstall-BsVsFpgX.js → gpuBackendInstall-DUOvnlWd.js} +4 -4
  146. package/out/server/chunks/{loadProvider-BdIE3W6z.js → loadProvider-79AJEjnd.js} +2 -2
  147. package/out/server/chunks/{manifest-VLS5iL-K.js → manifest-DjsZzZuh.js} +37 -6
  148. package/out/server/chunks/{workflowPresets-BJwuORhf.js → workflowPresets-Di8u79iQ.js} +175 -144
  149. package/out/server/index.js +2982 -1058
  150. package/out/server/plugin-host.js +53 -2
  151. package/package.json +1 -1
  152. package/out/phone/assets/architecture-7GRP2DOG-2pbpN4eZ.js +0 -1
  153. package/out/phone/assets/channel-D6Jp0e5s.js +0 -1
  154. package/out/phone/assets/classDiagram-ZZMXUADV-DDYMR8uV.js +0 -1
  155. package/out/phone/assets/classDiagram-v2-VYDZK3BY-DDYMR8uV.js +0 -1
  156. package/out/phone/assets/eventmodeling-NTZA5JFV-BVUcXI_2.js +0 -1
  157. package/out/phone/assets/flowDiagram-HODETNUW-lyDnpL9j.js +0 -1
  158. package/out/phone/assets/main-TDCArlgf.css +0 -1
  159. package/out/phone/assets/railroad-abnf-HS5TGJTU-Cc2ok2-H.js +0 -1
  160. package/out/phone/assets/railroad-ebnf-LZEXJU2U-B-egGDno.js +0 -1
  161. package/out/phone/assets/railroad-peg-WCYAUIDC-DGbcDKYr.js +0 -1
  162. package/out/phone/assets/stateDiagram-v2-MP3YSRHH-Bk1aRZ0l.js +0 -1
  163. package/out/phone/assets/swimlanesDiagram-VR7AAH4N-C1bEcwWi.js +0 -8
  164. package/out/renderer/assets/channel-CPp6hdRq.js +0 -1
  165. package/out/renderer/assets/classDiagram-ZZMXUADV-Be_lIO5F.js +0 -1
  166. package/out/renderer/assets/classDiagram-v2-VYDZK3BY-Be_lIO5F.js +0 -1
  167. package/out/renderer/assets/globals-BMp8RrrF.css +0 -1
  168. package/out/renderer/assets/index-DzCbQXPw.js +0 -131
  169. package/out/renderer/assets/settings-C-kHWSQ1.js +0 -27
  170. package/out/renderer/assets/stateDiagram-v2-MP3YSRHH-CwGKVtdP.js +0 -1
  171. package/out/renderer/assets/swimlanesDiagram-VR7AAH4N-BqwKnfw9.js +0 -8
@@ -1,27 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./globals-BTwoz2I6.js","./globals-BMp8RrrF.css"])))=>i.map(i=>d[i]);
2
- import{c as Te,w as gi,D as Qn,j as e,A as ji,r as l,u as Tr,a as Rr,b as vn,d as Or,t as Dr,C as Zn,e as H,I as Y,f as vi,X as vs,h as bi,i as yi,Z as is,k as wi,S as Ni,l as ki,m as Ci,n as Si,o as Ii,p as D,q as g,B as y,s as je,v as ve,x as be,y as ye,z as Ye,E as we,F as Le,G as Ie,H as Lr,J as Pe,K as ea,L as Ai,M as ut,N as mt,O as ne,P as ae,Q as re,R as oe,T as X,U as Ei,V as Ze,W as Pi,Y as Mi,_ as zr,$ as Ti,a0 as Rt,a1 as _r,a2 as Ri,a3 as Fr,a4 as Oi,a5 as sa,a6 as Br,a7 as Di,a8 as Li,a9 as zi,aa as ta,ab as _i,ac as Fi,ad as Bi,ae as $i,af as Ui,ag as Vi,ah as Gi,ai as Ki,aj as Wi,ak as Hi,al as qi,am as Ot,an as Yi,ao as Ji,ap as Xi,aq as Qi,ar as Zi,as as el,at as Ae,au as bn,av as pt,aw as Ve,ax as $r,ay as Ts,az as Ge,aA as We,aB as yn,aC as Ds,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 na,aM as aa,aN as ze,aO as Qe,aP as sl,aQ as tl,aR as Ur,aS as le,aT as ra,aU as Dt,aV as oa,aW as ia,aX as ft,aY as nl,aZ as al,a_ as Lt,a$ as Xs,b0 as Vr,b1 as En,b2 as rl,b3 as Pn,b4 as Gr,b5 as ol,b6 as il,b7 as ll,b8 as Kr,b9 as cl,ba as dl,bb as ul,bc as Wr,bd as zs,be as rt,bf as ml,bg as Mn,bh as xl,bi as hl,bj as Tn,bk as ns,bl as pl,bm as fl,bn as Hr,bo as gl,bp as jl,bq as vl,br as qr,bs as Rn,bt as Me,bu as se,bv as Ee,bw as bl,bx as yl,by as wl,bz as Nl,bA as kl,bB as la,bC as Cl,bD as Sl,bE as Qs,bF as Zs,bG as Je,bH as Ws,bI as tn,bJ as Il,bK as Al,bL as nn,bM as ms,bN as Yr,bO as El,bP as Pl,bQ as On,bR as Ml,bS as ca,bT as Jr,bU as Tl,bV as Rl,bW as Xr,bX as Ke,bY as Ol,bZ as gt,b_ as Dl,b$ as da,c0 as Ll,c1 as zl,c2 as _l,c3 as Xe,c4 as Fl,c5 as ua,c6 as ma,c7 as Bl,c8 as xa,c9 as $l,ca as Ul,cb as Vl,cc as Gl,cd as He,ce as zt,cf as ha,cg as Kl,ch as Wl,ci as Qr,cj as Hl,ck as Zr,cl as ql,cm as Yl,cn as Jl,co as Xl,cp as Dn,cq as Ql,cr as eo,cs as Zl,ct as ec,cu as et,cv as sc,cw as tc,cx as nc,cy as ac,cz as an,cA as so,cB as ot,cC as rc,cD as oc,cE as ic,cF as he,cG as pe,cH as Nt,cI as Ln,cJ as to,cK as zn,cL as no,cM as rn,cN as pa,cO as on,cP as ao,cQ as ro,cR as lc,cS as oo,cT as cc,cU as dc,cV as uc,cW as mc,cX as xc,cY as hc,cZ as pc,c_ as fc,c$ as gc,d0 as jc,d1 as fa,d2 as io,d3 as lo,d4 as co,d5 as uo,d6 as vc,d7 as bc,d8 as ga,d9 as Hs,da as yc,db as mo,dc as xo,dd as ho,de as wc,df as Nc,dg as kc,dh as Cc,di as Sc,dj as Ic,dk as Ac,dl as Ec,dm as Pc,dn as Mc,dp as Tc,dq as Rc,dr as po,ds as xt,dt as Rs,du as fo,dv as Oc,dw as ja,dx as Dc,dy as Lc,dz as zc,dA as _c,dB as Fc,dC as Bc,dD as $c,dE as Uc,dF as Vc,dG as Gc,dH as Kc,dI as ln,dJ as Wc,dK as jt,dL as Hc,dM as _n,dN as go,dO as jo,dP as Fn,dQ as vo,dR as bo,dS as yo,dT as wo,dU as No,dV as qc,dW as Yc,dX as Jc,dY as Xc,dZ as Qc,d_ as Zc,d$ as ed,e0 as sd,e1 as td,e2 as nd,e3 as ad,e4 as rd,e5 as od,e6 as id,e7 as ld,e8 as cd,e9 as dd,ea as ud,eb as md,ec as ko,ed as Co,ee as So,ef as xd,eg as Io,eh as hd,ei as pd,ej as fd,ek as Ao,el as gd,em as jd,en as va,eo as it,ep as vd,eq as bd,er as yd,es as wd,et as Nd,eu as kd,ev as ba,ew as Cd,ex as Sd,ey as Id,ez as Ad,eA as Ed,eB as Pd,eC as Md,eD as Eo,eE as Td,eF as Rd,eG as Od,eH as vt,eI as Dd,eJ as Ld,eK as zd,eL as _d,eM as cs,eN as Fd,eO as Po,eP as Bd,eQ as $d,eR as Ud,eS as Vd,eT as Gd,eU as Kd,eV as Wd,eW as Hd,eX as qd,eY as Mo,eZ as Yd,e_ as Jd,e$ as Xd,f0 as Qd,f1 as Zd,f2 as eu,f3 as su,f4 as tu,f5 as nu,f6 as au,f7 as ru,f8 as ou,f9 as iu,fa as lu,fb as cu,fc as du,fd as uu,fe as ya,ff as mu,fg as xu,fh as wa,fi as Na,fj as hu}from"./globals-BTwoz2I6.js";import{c as To}from"./cytoscape.esm-DzSz-X2X.js";import{f as pu}from"./cytoscape-fcose-BUV0U04U.js";const fu=[["path",{d:"M10 22V7a1 1 0 0 0-1-1H4a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-5a1 1 0 0 0-1-1H2",key:"1ah6g2"}],["rect",{x:"14",y:"2",width:"8",height:"8",rx:"1",key:"88lufb"}]],gu=Te("blocks",fu);const ju=[["path",{d:"M12 5v16",key:"1f6ucr"}],["path",{d:"M20.001 19A2 2 0 0022 17V5a2 2 0 00-1.999-2L16 3.002A5 5 0 0012 5a5 5 0 00-4-2H4a2 2 0 00-2 2v12a2 2 0 001.999 2H8a5 5 0 014 2 5 5 0 014-2z",key:"1fyvmf"}]],vu=Te("book-open",ju);const bu=[["path",{d:"M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z",key:"hh9hay"}],["path",{d:"m3.3 7 8.7 5 8.7-5",key:"g66t2b"}],["path",{d:"M12 22V12",key:"d0xqtd"}]],yu=Te("box",bu);const wu=[["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["path",{d:"M18 17V9",key:"2bz60n"}],["path",{d:"M13 17V5",key:"1frdt8"}],["path",{d:"M8 17v-3",key:"17ska0"}]],Nu=Te("chart-column",wu);const ku=[["path",{d:"M13.659 22H18a2 2 0 0 0 2-2V8a2.4 2.4 0 0 0-.706-1.706l-3.588-3.588A2.4 2.4 0 0 0 14 2H6a2 2 0 0 0-2 2v11.5",key:"4pqfef"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M8 12v-1",key:"1ej8lb"}],["path",{d:"M8 18v-2",key:"qcmpov"}],["path",{d:"M8 7V6",key:"1nbb54"}],["circle",{cx:"8",cy:"20",r:"2",key:"ckkr5m"}]],Cu=Te("file-archive",ku);const Su=[["path",{d:"M14.364 13.634a2 2 0 0 0-.506.854l-.837 2.87a.5.5 0 0 0 .62.62l2.87-.837a2 2 0 0 0 .854-.506l4.013-4.009a1 1 0 0 0-3.004-3.004z",key:"ukzhwg"}],["path",{d:"M14.487 7.858A1 1 0 0 1 14 7V2",key:"1klhew"}],["path",{d:"M20 19.645V20a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l2.516 2.516",key:"rxaxab"}],["path",{d:"M8 18h1",key:"13wk12"}]],Iu=Te("file-pen-line",Su);const Au=[["path",{d:"M4 22V4a1 1 0 0 1 .4-.8A6 6 0 0 1 8 2c3 0 5 2 7.333 2q2 0 3.067-.8A1 1 0 0 1 20 4v10a1 1 0 0 1-.4.8A6 6 0 0 1 16 16c-3 0-5-2-8-2a6 6 0 0 0-4 1.528",key:"1jaruq"}]],Eu=Te("flag",Au);const Pu=[["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"}]],Mu=Te("fold-vertical",Pu);const Tu=[["path",{d:"M2 9.5a5.5 5.5 0 0 1 9.591-3.676.56.56 0 0 0 .818 0A5.49 5.49 0 0 1 22 9.5c0 2.29-1.5 4-3 5.5l-5.492 5.313a2 2 0 0 1-3 .019L5 15c-1.5-1.5-3-3.2-3-5.5",key:"mvr1a0"}]],ka=Te("heart",Tu);const Ru=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}]],Ou=Te("image",Ru);const Du=[["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"}]],Ro=Te("lock-keyhole",Du);const Lu=[["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"}]],zu=Te("palette",Lu);const _u=[["path",{d:"m15 15 6 6m-6-6v4.8m0-4.8h4.8",key:"17vawe"}],["path",{d:"M9 19.8V15m0 0H4.2M9 15l-6 6",key:"chjx8e"}],["path",{d:"M15 4.2V9m0 0h4.8M15 9l6-6",key:"lav6yq"}],["path",{d:"M9 4.2V9m0 0H4.2M9 9 3 3",key:"1pxi2q"}]],Fu=Te("shrink",_u);const Bu=[["path",{d:"M15 21v-5a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v5",key:"slp6dd"}],["path",{d:"M17.774 10.31a1.12 1.12 0 0 0-1.549 0 2.5 2.5 0 0 1-3.451 0 1.12 1.12 0 0 0-1.548 0 2.5 2.5 0 0 1-3.452 0 1.12 1.12 0 0 0-1.549 0 2.5 2.5 0 0 1-3.77-3.248l2.889-4.184A2 2 0 0 1 7 2h10a2 2 0 0 1 1.653.873l2.895 4.192a2.5 2.5 0 0 1-3.774 3.244",key:"o0xfot"}],["path",{d:"M4 10.95V19a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8.05",key:"wn3emo"}]],$u=Te("store",Bu);const Uu=[["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"}]],Vu=Te("sun",Uu);const Gu=[["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"}]],Oo=Te("upload",Gu);function Ku(s){return s&&typeof s=="object"&&!Array.isArray(s)?s:null}function Wu(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 Hu(s){const t=Ku(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"||!Wu(o)||r!=="openai"&&r!=="openai-compatible"&&r!=="gemini"?null:{providerId:n,modelId:a,protocol:r,baseUrl:o,apiKey:i}}function qu(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"?Qn["google-generative-ai"]:n==="openai"?Qn["openai-responses"]:"";let r=s.baseUrl.trim().replace(/\/+$/,"")||a;if(n==="gemini"&&r&&(r=gi(r,"v1beta")),n==="openai"&&r)try{new URL(r).pathname==="/"&&(r=`${r}/v1`)}catch{}return Hu({providerId:s.id,modelId:t,protocol:n,baseUrl:r,apiKey:s.apiKey})}function Yu(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 Ju(s){return s.flatMap(t=>{const n=Yu(t).filter(a=>qu(t,a.id));return n.length?[{...t,models:n}]:[]})}function Xu(s){const{multiple:t=!1,defaultValue:n,value:a,onValueChange:r,autoComplete:o,...i}=s;return e.jsx(ji,{...i,selectionMode:t?"multiple":"single",selectedValue:a,defaultSelectedValue:n,onSelectedValueChange:r,formAutoComplete:o})}const Qu=l.forwardRef(function(t,n){const{selected:a}=Tr();return t.keepMounted||a?e.jsx(Zu,{...t,ref:n}):null}),Zu=l.memo(l.forwardRef((s,t)=>{const{render:n,className:a,style:r,keepMounted:o,...i}=s,{selected:m}=Tr(),d=l.useRef(null),{transitionStatus:h,setMounted:x}=Rr(m),f=vn("span",s,{ref:[t,d],state:{selected:m,transitionStatus:h},props:[{"aria-hidden":!0,children:"✔️"},i],stateAttributesMapping:Dr});return Or({open:m,ref:d,onComplete(){m||x(!1)}}),f})),Bn=l.createContext({chipsRef:null,multiple:!1,rootRef:null});function em(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(Xu,{...s})})})}function sm({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(Zn,{className:H("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(Zn,{className:H(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(Y,{className:"has-disabled:opacity-100",size:m}),...o}),t&&e.jsx(tm,{className:H("-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(vi,{})}),n&&e.jsx(om,{className:H("-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(vs,{})})]})}function tm({className:s,...t}){return e.jsx(Si,{className:s,"data-slot":"combobox-trigger",...t})}function nm({className:s,children:t,sideOffset:n=4,zIndex:a,...r}){const{chipsRef:o,rootRef:i}=l.useContext(Bn);let m=is.DROPDOWN;if(a!==void 0)m=a;else{const d=i?.current;d&&(d.closest('[data-slot="dialog-popup"] [data-slot="dialog-popup"]')?m=is.DROPDOWN_IN_NESTED_MODAL:d.closest('[data-slot="dialog-popup"]')&&(m=is.DROPDOWN_IN_MODAL))}return e.jsx(bi,{children:e.jsx(yi,{anchor:o,className:"select-none",style:{zIndex:m},"data-slot":"combobox-positioner",sideOffset:n,children:e.jsx("span",{className:H("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(wi,{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 am({className:s,children:t,endAddon:n,...a}){return e.jsxs(Ci,{className:H("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(Qu,{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 rm({className:s,...t}){return e.jsx(Ni,{scrollbarGutter:!0,scrollFade:!0,children:e.jsx(ki,{className:H("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 om({className:s,...t}){return e.jsx(Ii,{className:s,"data-slot":"combobox-clear",...t})}function im(){const{t:s}=D(),t=g(u=>u.contextMenuOpen),n=g(u=>u.setContextMenuOpen),[a,r]=l.useState(!1),[o,i]=l.useState(!1),m=u=>u.target==="reveal"?s("File manager"):u.target==="vscode"?s("VS Code"):u.applicationPath.split(/[/\\]/).at(-1)?.replace(/\.(exe|app)$/i,"")||u.applicationPath,d=t.filter(u=>u.enabled).map(m),h=d.length?`${d.slice(0,2).join(", ")}${d.length>2?` +${d.length-2}`:""}`:s("No opening methods enabled"),x=u=>{if(u.length>32){Pe({type:"error",title:s("Context menu opening"),description:s("You can configure up to 32 opening methods.")});return}n(u)},c=(u,p)=>{const j=g.getState().contextMenuOpen;n(j.map(v=>v.id===u.id?{...v,enabled:p}:v))},f=async()=>{i(!0);try{const u=await window.electronAPI.dialog.selectFile();if(!u)return;if(!Lr(u)){Pe({type:"error",title:s("Context menu opening"),description:s("The selected application path is invalid.")});return}const p=g.getState().contextMenuOpen,j=ea(u),v=p.find(I=>I.target==="application"&&ea(I.applicationPath)===j);if(v){x(p.map(I=>I.id===v.id?{...I,enabled:!0}:I));return}x([...p,{id:crypto.randomUUID(),target:"application",applicationPath:u,enabled:!0}])}catch(u){Pe({type:"error",title:s("Context menu opening"),description:u instanceof Error?u.message:String(u)})}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:d.join(", "),children:h}),e.jsx(je,{open:a,onOpenChange:r,children:e.jsxs(ve,{zIndexLevel:"nested",children:[e.jsxs(be,{children:[e.jsx(ye,{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(we,{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(u=>{const p=m(u);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:u.enabled,disabled:o,"aria-label":p,onCheckedChange:j=>c(u,j)}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-sm",title:p,children:p}),u.target==="application"&&e.jsx("span",{className:"block truncate text-xs text-muted-foreground",title:u.applicationPath,children:u.applicationPath})]})]}),e.jsx(y,{variant:"ghost",size:"sm",disabled:o,onClick:()=>n(g.getState().contextMenuOpen.filter(j=>j.id!==u.id)),children:s("Delete")})]},u.id)})]}),e.jsxs(Ie,{children:[e.jsx(y,{variant:"outline",disabled:o,onClick:()=>{f()},children:s("Add application")}),e.jsx(y,{onClick:()=>r(!1),children:s("Close")})]})]})})]})}const Ca=["internal","reveal","system","application"];function Sa({extension:s,value:t,disabled:n,onChange:a}){const{t:r}=D(),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,d=i?m?["internal","reveal"]:["reveal"]:Ca,h=i&&(!m||t==="system"||t==="application")?"reveal":t;return e.jsxs(ne,{items:Object.fromEntries(d.map(x=>[x,o[x]])),value:h,disabled:n,onValueChange:x=>{Ca.includes(x)&&a(x)},children:[e.jsx(ae,{className:"w-52","aria-label":r("File opening"),children:e.jsx(re,{})}),e.jsx(oe,{children:d.map(x=>e.jsx(X,{value:x,disabled:x==="internal"&&!m,children:o[x]},x))})]})}function lm(){const{t:s}=D(),t=g(k=>k.fileOpenRules),n=g(k=>k.setFileOpenRules),[a,r]=l.useState(""),[o,i]=l.useState("internal"),[m,d]=l.useState(),[h,x]=l.useState(null),[c,f]=l.useState(!1),u=Ai([{extension:a,target:"reveal"}])[0]?.extension,p=k=>{Pe({type:"error",title:s("File opening"),description:k})},j=async k=>{f(!0);try{const C=await window.electronAPI.dialog.selectFile();if(C){if(!Lr(C)){p(s("The selected application path is invalid."));return}k(C)}}catch(C){p(C instanceof Error?C.message:String(C))}finally{f(!1)}},v=k=>{const C=Ei(k);return C?(n(C),!0):(p(s("Could not complete the file action.")),!1)},I=(k,C,R)=>{if(C==="internal"&&!mt(`file${k.extension}`)){p(s("This extension does not support internal preview."));return}v(t.map(B=>B.extension===k.extension?{extension:k.extension,target:C,...C==="application"?{applicationPath:R}:{}}:B))},b=()=>{if(!u){x(s("Enter a valid file extension, for example .md."));return}if(t.some(B=>B.extension===u)){x(s("This extension already has an opening rule."));return}const k=ut(`file${u}`),C=mt(`file${u}`)!==null,R=k&&(!C||o==="system"||o==="application")?"reveal":o;if(R==="internal"&&!mt(`file${u}`)){p(s("This extension does not support internal preview."));return}if(R==="application"&&!m){x(s("Choose an application before saving this rule."));return}v([...t,{extension:u,target:R,...R==="application"?{applicationPath:m}:{}}])&&(r(""),d(void 0),x(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(im,{}),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(Sa,{extension:k.extension,value:k.target,disabled:c,onChange:C=>{C==="application"?j(R=>I(k,C,R)):I(k,C)}}),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(C=>I(k,"application",C))},children:s("Choose application")})]}),e.jsx(y,{variant:"ghost",size:"sm",disabled:c,onClick:()=>v(t.filter(C=>C.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(Y,{className:"w-24",value:a,placeholder:".md","aria-label":s("File extension"),disabled:c,onChange:k=>{r(k.target.value),x(null)},onKeyDown:k=>{k.key==="Enter"&&b()}}),e.jsx(Sa,{extension:u??".md",value:o,disabled:c,onChange:k=>{i(k),x(null)}}),e.jsx(y,{variant:"outline",size:"sm",disabled:c,onClick:b,children:s("Add")})]}),o==="application"&&!ut(`file${u??".md"}`)&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{variant:"outline",size:"sm",disabled:c,onClick:()=>{j(k=>{d(k),x(null)})},children:s("Choose application")}),e.jsx("span",{className:"min-w-0 truncate text-xs text-muted-foreground",title:m,children:m})]}),h&&e.jsx("p",{role:"alert",className:"text-xs text-destructive",children:h})]})]})}const cm=["pem","crt","cer"];function dm(s){return/^\//.test(s)||/^[A-Za-z]:[\\/]/.test(s)||/^\\\\[^\\]/.test(s)}const um=16384,Do=4096,Lo=65536;function mm(s){return s===null?null:typeof s=="number"&&Number.isInteger(s)&&s>=Do&&s<=Lo?s:void 0}function xm(s){const t=s.trim();return t?/^\d+$/.test(t)?mm(Number(t)):void 0:null}function hm(){const{t:s}=D(),[t,n]=l.useState(null),[a,r]=l.useState(""),[o,i]=l.useState(null);l.useEffect(()=>{let d=!1;return window.electronAPI.compaction.getReserveTokens().then(h=>{d||(n(h),r(h===null?"":String(h)))}),()=>{d=!0}},[]);const m=async()=>{const d=xm(a);if(d===void 0){i(s("Enter a whole number between {{min}} and {{max}}, or leave it empty.",{min:Do,max:Lo}));return}if(i(null),d===t)return;if(!(await window.electronAPI.compaction.setReserveTokens(d)).ok){i(s("Could not save. Check that pi-agent/settings.json is valid JSON."));return}n(d),r(d===null?"":String(d))};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(Y,{inputMode:"numeric",value:a,placeholder:String(um),"aria-label":s("Compaction reserve tokens"),onChange:d=>r(d.target.value),onBlur:()=>{m()},onKeyDown:d=>{d.key==="Enter"&&m()}}),o&&e.jsx("p",{className:"text-xs text-destructive",children:o})]})]})}function cn({className:s,render:t,...n}){const a={className:H("inline-flex items-center gap-2 text-base/4.5 sm:text-sm/4 font-medium",s),"data-slot":"label"};return Pi({defaultTagName:"label",props:Mi(a,n),render:t})}const dn={checked(s){return s?{"data-checked":""}:{"data-unchecked":""}},...Dr,...zr},zo=l.createContext(void 0);function pm(){return l.useContext(zo)}const _o=l.createContext(void 0);function fm(){const s=l.useContext(_o);if(s===void 0)throw new Error(Ti(52));return s}const gm=l.forwardRef(function(t,n){const{render:a,className:r,disabled:o=!1,readOnly:i=!1,required:m=!1,"aria-labelledby":d,value:h,inputRef:x,nativeButton:c=!1,id:f,style:u,...p}=t,j=pm(),{disabled:v,readOnly:I,required:b,form:k,checkedValue:C,touched:R=!1,validation:B,name:P,setCheckedValue:z=Rt,setTouched:M=Rt,registerInputRef:A=Rt}=j??{},{setTouched:S,setFilled:K,state:q,disabled:N}=_r(),L=Ri(),{labelId:V,getDescriptionProps:$}=Fr(),O=N||L.disabled||v||o,te=I||i,G=b||m,J=k,W=j?C===h:h==="",ce=l.useRef(null),_=l.useRef(null),de=B?.registerInput,T=l.useCallback(fe=>de?.(fe,{controlRef:ce,value:void 0}),[de]),E=Oi(x,_,A,T);sa(()=>{_.current?.checked&&K(!0)},[K]),sa(()=>{if(_.current){if(O&&W){A(null);return}A(_.current)}},[W,O,A]);const Q=Br(),ie=Di({id:f,implicit:!1,controlRef:ce}),Re=c?void 0:ie,Oe=Li(d,V,_,!c,Re),F={role:"radio","aria-checked":W,"aria-labelledby":Oe,[Vi]:W?"":void 0,id:c?ie:Q,onKeyDown(fe){fe.key==="Enter"&&fe.preventDefault()},onClick(fe){if(fe.defaultPrevented||O||te)return;fe.preventDefault();const De=_.current;De&&Ui(De,fe)},onFocus(fe){fe.defaultPrevented||O||te||!R||(_.current?.click(),M(!1))}},{getButtonProps:ee,buttonRef:Z}=zi({disabled:O,native:c,composite:!1}),me={type:"radio",ref:E,form:J,id:Re,name:P,tabIndex:-1,style:P?Bi:$i,"aria-hidden":!0,...h!==void 0?{value:_i(h)}:ta,disabled:O,checked:W,required:G,readOnly:te,onChange(fe){if(fe.nativeEvent.defaultPrevented||O||te||h===void 0)return;const De=Gi(Ki,fe.nativeEvent);z(h,De),!De.isCanceled&&S(!0)},onClick(fe){fe.stopPropagation()},onFocus(){ce.current?.focus()}},ke=l.useMemo(()=>({...q,required:G,disabled:O,readOnly:te,checked:W}),[q,O,te,W,G]),xs=ke,bs=j!==void 0,qe=[n,ce,Z],ys=[F,p,ee,$,B?fe=>B.getValidationProps(O,fe):ta],hs=vn("span",t,{enabled:!bs,state:ke,ref:qe,props:ys,stateAttributesMapping:dn});return e.jsxs(_o.Provider,{value:xs,children:[bs?e.jsx(Fi,{tag:"span",render:a,className:r,style:u,state:ke,refs:qe,props:ys,stateAttributesMapping:dn}):hs,e.jsx("input",{...me,suppressHydrationWarning:!0})]})}),jm=l.forwardRef(function(t,n){const{render:a,className:r,style:o,keepMounted:i=!1,...m}=t,d=fm(),h=d.checked,{mounted:x,transitionStatus:c,setMounted:f}=Rr(h),u={...d,transitionStatus:c},p=l.useRef(null),j=i||x,v=vn("span",t,{ref:[n,p],state:u,props:m,stateAttributesMapping:dn});return Or({open:h,ref:p,onComplete(){h||f(!1)}}),j?v:null}),vm=[Zi],bm=l.forwardRef(function(t,n){const{render:a,className:r,disabled:o,readOnly:i,required:m,onValueChange:d,value:h,defaultValue:x,form:c,name:f,inputRef:u,id:p,style:j,...v}=t,{setTouched:I,setFocused:b,validationMode:k,name:C,disabled:R,state:B,validation:P,setDirty:z,setFilled:M,validityData:A}=_r(),{labelId:S}=Fr(),{clearErrors:K,elementRef:q}=Wi(),N=Hi(!0),L=R||o,V=C??f,$=Br(p),[O,te]=qi({controlled:h,default:x,name:"RadioGroup",state:"value"}),[G,J]=l.useState(!1),W=Ot((Z,me)=>{d?.(Z,me),!me.isCanceled&&te(Z)}),ce=P.getInputControl,_=l.useMemo(()=>({get current(){return ce()}}),[ce]),de=l.useRef(null),T=l.useRef(null);function E(Z){let me;return u&&(typeof u=="function"?me=u(Z):u.current=Z),de.current=Z,me}const Q=Ot(Z=>{if(!Z||Z.disabled)return;T.current||(T.current=Z);const me=de.current,ke=Z.checked||me==null||me.disabled?E(Z):void 0;return()=>{T.current===Z&&(T.current=null),de.current===Z?ke?(ke(),de.current=null):E(null):ke?.()}}),ie=Ot(()=>{const Z=q.current;if(!Z)return O??null;for(const me of P.registeredInputs.keys())if(me.checked&&Yi(me,Z))return O??null;return null});Ji(_,$,O??null,ie,!L,f),Xi(O,()=>{K(V),z(O!==A.initialValue),M(O!=null),P.change(O);const Z=T.current;O==null&&Z&&!Z.disabled&&E(Z)});const Re=S??N?.legendId,Oe={...B,disabled:L??!1,required:m??!1,readOnly:i??!1},F=l.useMemo(()=>({checkedValue:O,disabled:L,form:c,validation:P,name:V,readOnly:i,registerInputRef:Q,required:m,setCheckedValue:W,setTouched:J,touched:G}),[O,L,c,P,V,i,Q,m,W,J,G]),ee={id:p,role:"radiogroup","aria-required":m||void 0,"aria-disabled":L||void 0,"aria-readonly":i||void 0,"aria-labelledby":Re,onFocus(){b(!0)},onBlur(Z){el(Z.currentTarget,Z.relatedTarget)||(I(!0),b(!1),k==="onBlur"&&P.commit(O))},onKeyDownCapture(Z){Z.key.startsWith("Arrow")&&(J(!0),b(!0))}};return e.jsx(zo.Provider,{value:F,children:e.jsx(Qi,{render:a,className:r,style:j,state:Oe,props:[ee,v,Z=>P.getValidationProps(L??!1,Z)],refs:[n],stateAttributesMapping:zr,enableHomeAndEndKeys:!1,modifierKeys:vm})})});function ym({className:s,...t}){return e.jsx(bm,{className:H("flex flex-col gap-3",s),"data-slot":"radio-group",...t})}function Ia({className:s,...t}){return e.jsx(gm,{className:H("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(jm,{className:"-inset-px absolute flex size-4.5 items-center justify-center rounded-full before:size-2 before:rounded-full before:bg-primary-foreground data-unchecked:hidden data-checked:bg-primary sm:size-4 sm:before:size-1.5","data-slot":"radio-indicator"})})}const wm=[{category:"providers",label:"Model Providers"},{category:"presets",label:"Presets"},{category:"agentTypes",label:"Agent types"},{category:"skills",label:"Skills"},{category:"mcpServers",label:"MCP Servers"},{category:"instructions",label:"Instruction Files"},{category:"subagentModels",label:"Subagent Models"},{category:"settings",label:"Scalar settings"}];function Nm(){const{t:s}=D(),[t,n]=l.useState(!1),[a,r]=l.useState(!1),[o,i]=l.useState(null),[m,d]=l.useState(null),h=()=>{i(null),n(!0)},x=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}d(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(Cu,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium",children: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:x,children:[a?e.jsx(Ae,{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:h,children:[e.jsx(Oo,{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(km,{open:t,onOpenChange:n}),m&&e.jsx(Cm,{file:m,onClose:()=>d(null)})]})}function km({open:s,onOpenChange:t}){const{t:n}=D(),[a,r]=l.useState(!1),[o,i]=l.useState(""),[m,d]=l.useState(""),[h,x]=l.useState(!1),[c,f]=l.useState(null),[u,p]=l.useState(!1),[j,v]=l.useState(null),[I,b]=l.useState([]);l.useEffect(()=>{s&&(r(!1),i(""),d(""),x(!1),f(null),p(!1),v(null),b([]))},[s]);const k=()=>{h||(i(""),d(""),t(!1))},C=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}x(!0),f(null),p(!1);try{const R=await window.electronAPI.configSync.exportConfig({includeSecrets:a,...a?{password:o}:{}});if(i(""),d(""),!R.ok){R.cancelled?p(!0):f(n(R.error));return}v(R.filePath),b(R.skippedInstructions??[])}catch{i(""),d(""),f(n("Could not export configuration."))}finally{x(!1)}};return e.jsx(je,{open:s,onOpenChange:R=>!R&&k(),children:e.jsxs(ve,{className:"max-w-xl",showCloseButton:!h,children:[e.jsxs(be,{children:[e.jsx(ye,{children:n("Export configuration")}),e.jsx(Ye,{children:n("Create a portable .enso-config package for another device.")})]}),e.jsx(we,{className:"max-h-[55vh] space-y-4",children:j?e.jsxs(e.Fragment,{children:[e.jsxs(Ve,{variant:"success",children:[e.jsx($r,{}),e.jsx(Ts,{children:n("Configuration exported")}),e.jsxs(Ge,{children:[e.jsx("p",{children:n("Saved package:")}),e.jsx("p",{className:"break-all font-mono text-xs text-foreground",children:j})]})]}),I.length>0&&e.jsxs(Ve,{variant:"warning",children:[e.jsx(We,{}),e.jsxs(Ge,{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:I.join(", ")})]})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs(Ve,{variant:"warning",children:[e.jsx(yn,{}),e.jsx(Ts,{children:n("File contents can be private")}),e.jsx(Ge,{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:R=>{const B=R===!0;r(B),f(null),B||(i(""),d(""))}}),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(Ve,{variant:"info",children:[e.jsx(pt,{}),e.jsx(Ge,{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(Ro,{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(Y,{id:"config-export-password",type:"password",autoComplete:"new-password",value:o,"aria-invalid":!!(c&&o.length<8),onChange:R=>{i(R.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(Y,{id:"config-export-confirmation",type:"password",autoComplete:"new-password",value:m,"aria-invalid":!!(c&&m!==o),onChange:R=>{d(R.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.")})]}),u&&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(Ds,{className:"h-3.5 w-3.5 shrink-0"}),c]})]})}),e.jsx(Ie,{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:h,onClick:k,children:n("Cancel")}),e.jsxs(y,{size:"sm",disabled:h,onClick:()=>{C()},children:[h?e.jsx(Ae,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Oo,{className:"h-3.5 w-3.5"}),n(h?"Exporting…":"Export")]})]})})]})})}function Cm({file:s,onClose:t}){const{t:n}=D(),[a,r]=l.useState(s.encrypted?"password":"preview"),[o,i]=l.useState(""),[m,d]=l.useState("merge"),[h,x]=l.useState(null),[c,f]=l.useState([]),[u,p]=l.useState(null),[j,v]=l.useState(!1),[I,b]=l.useState(null),[k,C]=l.useState(null),[R,B]=l.useState(!1),P=l.useRef(0),z=l.useCallback(async(N,L)=>{const V=++P.current;b("preview"),C(null),x(null),f([]);try{const $=await window.electronAPI.configSync.previewImport({token:s.token,mode:N,...L?{password:L}:{}});if(V!==P.current)return;if(i(""),!$.ok){C(n($.error));return}d($.mode),x($.summary),f($.warnings),r("preview")}catch{V===P.current&&(i(""),C(n("Could not preview configuration package.")))}finally{V===P.current&&b(null)}},[s.token,n]);l.useEffect(()=>{s.encrypted||z("merge")},[s.encrypted,z]);const M=()=>{I||(P.current+=1,B(!1),i(""),window.electronAPI.configSync.cancelImport(s.token).catch(()=>{}),t())},A=N=>{N===m||I||(d(N),z(N))},S=!!h?.some(N=>(N.category==="skills"||N.category==="mcpServers")&&N.added+N.updated+N.skipped>0),K=h!==null,q=async()=>{if(h){b("commit"),C(null);try{const N=await window.electronAPI.configSync.commitImport({token:s.token,mode:m});if(!N.ok){x(null),f([]),C(n(N.error));return}i("");try{await g.persist.rehydrate()}catch{v(!0)}f(N.warnings),p(N.backupPath),r("success")}catch{x(null),f([]),C(n("Could not import configuration."))}finally{b(null)}}};return e.jsxs(je,{open:!0,onOpenChange:N=>!N&&M(),children:[e.jsxs(ve,{className:"max-w-2xl",showCloseButton:I===null,children:[e.jsxs(be,{children:[e.jsx(ye,{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(we,{className:"space-y-4",children:[e.jsxs(Ve,{variant:"info",children:[e.jsx(Ro,{}),e.jsx(Ts,{children:n("Encrypted configuration package")}),e.jsx(Ge,{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(Y,{id:"config-import-password",type:"password",autoFocus:!0,autoComplete:"current-password",value:o,"aria-invalid":!!k,onChange:N=>{i(N.target.value),C(null)},onKeyDown:N=>{N.key==="Enter"&&o.length>0&&!I&&z("merge",o)}})]}),k&&e.jsxs("p",{className:"flex items-center gap-1.5 text-xs text-destructive",role:"alert",children:[e.jsx(Ds,{className:"h-3.5 w-3.5 shrink-0"}),k]})]}),a==="preview"&&e.jsxs(we,{className:"max-h-[58vh] space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium",children:n("Import mode")}),e.jsxs(ym,{value:m,onValueChange:N=>A(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(Ia,{value:"merge",disabled:I!==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(Ia,{value:"replace",disabled:I!==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.")})]})]})]})]}),I==="preview"&&e.jsxs("div",{className:"flex items-center justify-center gap-2 rounded-md border border-dashed py-10",children:[e.jsx(Ae,{className:"h-4 w-4 animate-spin text-muted-foreground"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:n("Preparing preview…")})]}),!I&&h&&e.jsx("div",{className:"overflow-hidden rounded-md border",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted/50 text-xs text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",className:"px-3 py-2 text-left font-medium",children:n("Category")}),e.jsx("th",{scope:"col",className:"px-3 py-2 text-right font-medium",children:n("Added")}),e.jsx("th",{scope:"col",className:"px-3 py-2 text-right font-medium",children:n("Updated")}),e.jsx("th",{scope:"col",className:"px-3 py-2 text-right font-medium",children:n("Skipped")}),e.jsx("th",{scope:"col",className:"px-3 py-2 text-right font-medium",children:n("Removed")})]})}),e.jsx("tbody",{children:wm.map(({category:N,label:L})=>{const V=h.find($=>$.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(L)}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:V?.added??0}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:V?.updated??0}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:V?.skipped??0}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:V?.removed??0})]},N)})})]})}),!I&&h?.find(N=>N.category==="settings")?.fields?.length?e.jsxs("p",{className:"text-xs text-muted-foreground",children:[n("Portable settings changed:")," ",h.find(N=>N.category==="settings")?.fields?.join(", ")]}):null,m==="replace"&&h&&!I&&e.jsxs(Ve,{variant:"error",children:[e.jsx(We,{}),e.jsx(Ts,{children:n("Local-only configuration will be deleted")}),e.jsx(Ge,{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(Ve,{variant:"warning",children:[e.jsx(We,{}),e.jsx(Ge,{children:n(N)})]},N)),h&&!I&&e.jsxs(Ve,{variant:"warning",children:[e.jsx(yn,{}),e.jsx(Ts,{children:n("Only import packages you trust")}),e.jsx(Ge,{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(Ve,{variant:"error",children:[e.jsx(Ds,{}),e.jsx(Ge,{children:k})]})]}),a==="success"&&u&&e.jsxs(we,{className:"space-y-4",children:[e.jsxs(Ve,{variant:"success",children:[e.jsx($r,{}),e.jsx(Ts,{children:n("Import complete")}),e.jsxs(Ge,{children:[e.jsx("p",{children:n("Backup of previous settings:")}),e.jsx("p",{className:"break-all font-mono text-xs text-foreground",children:u})]})]}),j&&e.jsxs(Ve,{variant:"warning",children:[e.jsx(We,{}),e.jsx(Ge,{children:n("Reopen Settings to load the imported configuration in this window.")})]}),c.map(N=>e.jsxs(Ve,{variant:"warning",children:[e.jsx(We,{}),e.jsx(Ge,{children:n(N)})]},N))]}),e.jsxs(Ie,{children:[a==="password"&&e.jsxs(e.Fragment,{children:[e.jsx(y,{variant:"outline",size:"sm",disabled:I!==null,onClick:M,children:n("Cancel")}),e.jsxs(y,{size:"sm",disabled:I!==null||o.length===0,onClick:()=>{z("merge",o)},children:[I==="preview"&&e.jsx(Ae,{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:I!==null,onClick:M,children:n("Cancel")}),k&&!h?e.jsx(y,{size:"sm",disabled:I!==null,onClick:()=>{z(m)},children:n("Refresh preview")}):e.jsxs(y,{variant:m==="replace"?"destructive":"default",size:"sm",disabled:I!==null||!h,onClick:()=>{h&&(K?B(!0):q())},children:[I==="commit"?e.jsx(Ae,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(bn,{className:"h-3.5 w-3.5"}),n(I==="commit"?"Importing…":"Import")]})]}),a==="success"&&e.jsx(y,{size:"sm",onClick:M,children:n("Done")})]})]}),e.jsx(Sm,{open:R,mode:m,hasImportedExecutableResources:S,onOpenChange:B,onConfirm:()=>{q()}})]})}function Sm({open:s,mode:t,hasImportedExecutableResources:n,onOpenChange:a,onConfirm:r}){const{t:o}=D();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(We,{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 Aa={auto:"Auto (by usage)",fast:"Fast",balanced:"Balanced",thorough:"Thorough"},Ea={standard:"Standard",smart:"Smart compaction","codex-native":"Codex native compaction","continuous-memory":"Continuous memory (experimental)"};function Im(){const{t:s}=D(),t=g(u=>u.compactStrategy),n=g(u=>u.smartCompactEnabled),a=sl(t,n),r=g(u=>u.setCompactStrategy),o=a!=="standard",i=g(u=>u.smartCompactModel),m=g(u=>u.setSmartCompactModel),d=g(u=>u.smartCompactMode),h=g(u=>u.setSmartCompactMode),x=es(),c=i?x.find(u=>u.id===i.providerId):void 0,f=c?.models.find(u=>u.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(na.map(u=>[u,s(Ea[u])])),value:a,onValueChange:u=>r(u),children:[e.jsx(ae,{className:"w-52",children:e.jsx(re,{})}),e.jsx(oe,{children:na.map(u=>e.jsx(X,{value:u,children:s(Ea[u])},u))})]})]}),(a==="smart"||a==="codex-native")&&e.jsxs("div",{className:"flex items-center justify-between gap-4","data-smart-compact-mode":d,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(aa.map(u=>[u,s(Aa[u])])),value:d,onValueChange:u=>h(u),children:[e.jsx(ae,{className:"w-36",children:e.jsx(re,{})}),e.jsx(oe,{children:aa.map(u=>e.jsx(X,{value:u,children:s(Aa[u])},u))})]})]}),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")}),x.length>0&&e.jsx("div",{className:"w-full min-w-0",children:e.jsx(ze,{providers:x,providerId:c?.id??"",modelId:f?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:s("Follows the session model"),side:"bottom",triggerClassName:Qe,onSelect:(u,p)=>m({providerId:u,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 Am={cmd:"Command Prompt",powershell:"Windows PowerShell",pwsh:"PowerShell 7 (pwsh)","git-bash":"Git Bash",zsh:"zsh",bash:"bash",fish:"fish"};function Em(){const{language:s,setLanguage:t}=g(),{t:n}=D();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(X,{value:"en",children:"English"}),e.jsx(X,{value:"zh",children:"简体中文"})]})]})]}),e.jsx(Pm,{}),e.jsx(_m,{}),e.jsx(Fm,{}),e.jsx(Nm,{}),e.jsx(Bm,{})]}),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(Mm,{}),e.jsx(Tm,{}),e.jsx(Im,{}),e.jsx(hm,{})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h4",{className:"border-b pb-2 text-base font-semibold",children:n("Sessions & worktrees")}),e.jsx(Om,{}),e.jsx(Rm,{}),e.jsx(Lm,{})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h4",{className:"border-b pb-2 text-base font-semibold",children:n("Terminal")}),e.jsx(zm,{}),e.jsx(Dm,{})]}),window.electronAPI.env.platform==="darwin"&&e.jsxs("section",{className:"space-y-3",children:[e.jsx("h4",{className:"border-b pb-2 text-base font-semibold",children:n("Integrations")}),e.jsx(Pa,{kind:"ensoCommand",title:n("'enso' terminal command"),description:n("Run `enso .` in a terminal to open the current folder in EnsoCode. Links the command into /usr/local/bin and may ask for your password.")}),e.jsx(Pa,{kind:"finderQuickAction",title:n("Finder Quick Action"),description:n("Right-click a folder in Finder and choose Services > Open with EnsoCode.")})]})]})}function Pa({kind:s,title:t,description:n}){const{t:a}=D(),[r,o]=l.useState(!1),[i,m]=l.useState(!1);l.useEffect(()=>{let h=!0;const x=()=>{window.electronAPI.window.shellIntegrationStatus().then(c=>{h&&o(c[s])})};return x(),window.addEventListener("focus",x),()=>{h=!1,window.removeEventListener("focus",x)}},[s]);const d=async()=>{m(!0);try{await window.electronAPI.window.installShellIntegration(s)}finally{try{const h=await window.electronAPI.window.shellIntegrationStatus();o(h[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:()=>{d()},children:a(i?"In progress…":r?"Uninstall":"Install")})]})}function Pm(){const{t:s}=D(),t=g(a=>a.notifyMainAgentOnly),n=g(a=>a.setNotifyMainAgentOnly);return e.jsx(Se,{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 Mm(){const{t:s}=D(),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(ra.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:ra.map(a=>e.jsx(X,{value:String(a),children:a===0?s("Never"):s("{{count}} min",{count:a})},a))})]})]})}function Tm(){const{t:s}=D(),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(X,{value:String(o),children:r(o)},o))})]})]})}function Rm(){const{t:s}=D(),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(X,{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 Om(){const{t:s}=D(),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(oa.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:oa.map(m=>e.jsx(X,{value:String(m),children:lt(s,m)},m))})]})]}),e.jsx(Se,{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(ia.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:ia.map(m=>e.jsx(X,{value:String(m),children:lt(s,m)},m))})]})]})]})}function Dm(){const{t:s}=D(),t=g(o=>o.terminalShell),n=g(o=>o.setTerminalShell),a=nl(window.electronAPI.env.platform),r=Object.fromEntries(a.map(o=>[o,o==="auto"?s("System default"):Am[o]]));return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.terminalShell",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children: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(X,{value:o,children:r[o]},o))})]})]})}function Lm(){const{t:s}=D(),t=g(h=>h.worktreeRoot),n=g(h=>h.setWorktreeRoot),[a,r]=l.useState(t),[o,i]=l.useState(null);l.useEffect(()=>{r(t)},[t]);const m=h=>{const x=h.trim();if(x&&!dm(x)){i(s("Enter an absolute path"));return}i(null),n(x)},d=async()=>{const h=await window.electronAPI.dialog.selectDirectory();h&&(r(h),m(h))};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(Y,{value:a,placeholder:s("Default location"),onChange:h=>r(h.target.value),onBlur:()=>m(a),onKeyDown:h=>{h.key==="Enter"&&m(a)}}),e.jsx(y,{variant:"outline",size:"sm",className:"shrink-0",onClick:()=>{d()},children:s("Browse")})]}),o&&e.jsx("p",{className:"text-xs text-destructive",children:o})]})]})}function zm(){const{t:s}=D(),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(X,{value:r,children:a[r]},r))})]})]})}function Se({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(le,{checked:n,onCheckedChange:i=>a(i===!0)})]}),o?e.jsx("div",{className:"mt-2",children:o}):null]})}function Ma(s,t){window.electronAPI.proxy.apply({mode:s,customUrl:t})}function _m(){const{t:s}=D(),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,d]=l.useState(null);l.useEffect(()=>{i(n)},[n]);const h=c=>{a(c),Ma(c,n)},x=()=>{const c=o.trim();if(c&&!al(c)){d(s("Enter an http(s) proxy URL"));return}d(null),r(c),Ma(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=>h(c),children:[e.jsx(ae,{className:"w-56",children:e.jsx(re,{})}),e.jsxs(oe,{children:[e.jsx(X,{value:"system",children:s("Follow system proxy")}),e.jsx(X,{value:"none",children:s("No proxy")}),e.jsx(X,{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(Y,{value:o,placeholder:"http://127.0.0.1:7890",onChange:c=>i(c.target.value),onBlur:x,onKeyDown:c=>{c.key==="Enter"&&x()}}),m&&e.jsx("p",{className:"text-xs text-destructive",children:m})]})]})]})}function Fm(){const{t:s}=D(),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)}},d=async()=>{const c=await window.electronAPI.dialog.selectFile([...cm]);c&&await m(c)},h={"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")},x=()=>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:()=>{d()},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:h[a.error],path:a.settingPath})}):e.jsx("p",{className:"break-all text-xs text-muted-foreground",children:x()}),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 Bm(){const{t:s}=D(),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,d]=l.useState(null),[h,x]=l.useState(!1),[c,f]=l.useState(!1);l.useEffect(()=>{let k=!0;window.electronAPI.updater.getState().then(R=>{k&&(d(R),R.status&&i(B=>B??R.status))}).catch(()=>{});const C=window.electronAPI.updater.onStatus(i);return()=>{k=!1,C()}},[]);const u=m?.host==="server"?m:null,p=m?.host==="desktop"||u!==null&&u.mode!=="manual",j=(o?.status==="available"||o?.status==="downloaded")&&!!o.info,I=(()=>{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 u&&o.error?s("Update failed: {{error}}",{error:o.error}):s("Update check failed");default:return null}})(),b=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:u?$m(u.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")," · ",Um]}),I&&e.jsx("p",{className:"mt-0.5 truncate text-xs text-muted-foreground",children:I})]}),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:b,onClick:()=>{window.electronAPI.updater.checkForUpdates()},className:"shrink-0",children:s("Check for updates")}),e.jsx(tl,{open:c,onOpenChange:f,status:o,canDownload:p})]}),u?.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:()=>x(!0),className:"shrink-0",children:s("Restart")}),e.jsx(Ur,{open:h,onOpenChange:x,title:s("Restart server?"),description:s("Running tasks are interrupted; this page reconnects after the server is back."),confirmLabel:s("Restart"),onConfirm:()=>{x(!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(le,{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(le,{checked:t&&a,disabled:!t,onCheckedChange:k=>{r(k),window.electronAPI.updater.setAutoRestartWhenIdle(k)}})]})]})}function $m(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 Um="0.3.8",Vm=["100%","100%","70%","100%","55%"],Gm=["100%","85%","60%"];function Km({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}}),Vm.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}}),Gm.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 Ta="overflow-hidden rounded-lg border text-left transition-shadow";function Wm({themes:s,selected:t,mode:n,onSelect:a,onGetMore:r}){const{t:o}=D();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:H(Ta,"bg-card",m?"border-transparent shadow-[0_0_0_2px_var(--brand)]":"hover:border-input"),children:[e.jsx(Km,{palette:i[n]}),e.jsxs("div",{className:"flex items-center gap-1.5 border-t px-2.5 py-[7px] text-sm",children:[e.jsx("span",{className:"truncate font-medium",children:i.name}),e.jsx("span",{className:H("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:H(Ta,"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 Hm({children:s}){return e.jsx("div",{className:"divide-y rounded-lg border bg-card",children:s})}function os({label:s,value:t,onCommit:n,min:a=0,max:r=100,step:o,unit:i="%",formatSuffix:m,onPreview:d,trailing:h,valueClassName:x="w-12"}){const[c,f]=l.useState(t);l.useEffect(()=>{f(t)},[t]);const u=m?.(c);return e.jsxs("div",{className:H("grid items-center gap-4",h?"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(xl,{min:a,max:r,step:o,value:c,onValueChange:p=>{const j=Array.isArray(p)?p[0]:p;f(j),d?.(j)},onValueCommitted:p=>n(Array.isArray(p)?p[0]:p)}),e.jsxs("span",{className:H("shrink-0 text-right text-sm text-muted-foreground tabular-nums",u?"w-28":x),children:[c,i,u?` · ${u}`:""]})]}),h]})}function qm(){const{t:s}=D(),t=g(E=>E.backgroundImageEnabled),n=g(E=>E.setBackgroundImageEnabled),a=g(E=>E.backgroundSourceType),r=g(E=>E.setBackgroundSourceType),o=g(E=>E.backgroundImagePath),i=g(E=>E.setBackgroundImagePath),m=g(E=>E.backgroundFolderPath),d=g(E=>E.setBackgroundFolderPath),h=g(E=>E.backgroundUrlPath),x=g(E=>E.setBackgroundUrlPath),c=g(E=>E.backgroundRandomEnabled),f=g(E=>E.setBackgroundRandomEnabled),u=g(E=>E.backgroundRandomInterval),p=g(E=>E.setBackgroundRandomInterval),j=g(E=>E.backgroundOpacity),v=g(E=>E.setBackgroundOpacity),I=g(E=>E.backgroundBlur),b=g(E=>E.setBackgroundBlur),k=g(E=>E.backgroundBrightness),C=g(E=>E.setBackgroundBrightness),R=g(E=>E.backgroundSaturation),B=g(E=>E.setBackgroundSaturation),P=g(E=>E.backgroundMask),z=g(E=>E.setBackgroundMask),M=g(E=>E.backgroundComposerOpacity),A=g(E=>E.setBackgroundComposerOpacity),S=g(E=>E.backgroundCodeOpacity),K=g(E=>E.setBackgroundCodeOpacity),q=g(E=>E.backgroundSizeMode),N=g(E=>E.setBackgroundSizeMode),L=g(E=>E.bumpBackgroundRefresh),V=hl()?.source==="theme",$=a==="file"?o:a==="folder"?m:h,[O,te]=l.useState($);l.useEffect(()=>{te($)},[$]);const G=l.useCallback(()=>{const E=O.trim();a==="file"?i(E):a==="folder"?d(E):x(E)},[O,a,i,d,x]),[J,W]=l.useState(u);l.useEffect(()=>{W(u)},[u]);const ce=async()=>{if(a==="folder"){const E=await window.electronAPI.dialog.selectDirectory();E&&d(E)}else{const E=await window.electronAPI.dialog.selectFile([...gl,...jl]);E&&i(E)}},_=[{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")}],T=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(le,{checked:t,onCheckedChange:E=>n(E===!0)})]}),V&&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:E=>r(E),children:[e.jsx(ae,{className:"w-48",children:e.jsx(re,{})}),e.jsx(oe,{children:_.map(E=>e.jsx(X,{value:E.value,children:E.label},E.value))})]})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:T}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Y,{value:O,onChange:E=>te(E.target.value),onBlur:G,onKeyDown:E=>{E.nativeEvent.isComposing||E.key==="Enter"&&(G(),E.currentTarget.blur())},placeholder:a==="url"?"https://example.com/image.jpg":"",className:"flex-1"}),a!=="url"&&e.jsx(y,{variant:"outline",size:"icon",onClick:ce,"aria-label":s("Browse"),children:a==="folder"?e.jsx(Tn,{className:"h-4 w-4"}):e.jsx(Ou,{className:"h-4 w-4"})}),a!=="file"&&e.jsx(y,{variant:"outline",size:"icon",onClick:L,"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(le,{checked:c,onCheckedChange:E=>f(E===!0)}),c&&e.jsxs(e.Fragment,{children:[e.jsx(Y,{type:"number",min:5,max:86400,value:J,onChange:E=>W(Number(E.target.value)),onBlur:()=>p(J),onKeyDown:E=>{E.key==="Enter"&&(p(J),E.currentTarget.blur())},className:"w-24"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:s("seconds")})]})]})]}),e.jsx(os,{label:s("Background visibility"),value:Math.round(j*100),onCommit:E=>v(E/100)}),e.jsx(os,{label:s("Blur"),value:I,onCommit:b,max:20,unit:"px"}),e.jsx(os,{label:s("Brightness"),value:Math.round(k*100),onCommit:E=>C(E/100),max:200}),e.jsx(os,{label:s("Saturation"),value:Math.round(R*100),onCommit:E=>B(E/100),max:200}),e.jsx(os,{label:s("Overlay"),value:Math.round(P*100),onCommit:E=>z(E/100)}),e.jsx(os,{label:s("Composer opacity"),value:Math.round(M*100),onCommit:E=>A(E/100)}),e.jsx(os,{label:s("Code block opacity"),value:Math.round(S*100),onCommit:E=>K(E/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:E=>N(E),children:[e.jsx(ae,{className:"w-48",children:e.jsx(re,{})}),e.jsx(oe,{children:de.map(E=>e.jsx(X,{value:E.value,children:E.label},E.value))})]})]})]})]})}function Ym({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 Jm({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(ka,{className:"h-4 w-4 fill-red-500 text-red-500"}):e.jsx(ka,{className:"h-4 w-4"})})}function Xm({value:s,onValueChange:t,themes:n,favoriteThemes:a,onToggleFavorite:r,onThemeHover:o,showFavoritesOnly:i,onShowFavoritesOnlyChange:m,showEmptyFavoritesHint:d}){const{t:h}=D(),[x,c]=l.useState(s),[f,u]=l.useState(s),[p,j]=l.useState(!1),v=l.useRef(void 0),I=l.useRef(null),b=l.useRef(s),k=l.useRef(!1),C=l.useMemo(()=>new Set(a),[a]);l.useEffect(()=>{p||(c(s),u(s))},[s,p]);const R=l.useMemo(()=>{if(!f||f===x)return n;const A=f.toLowerCase();return n.filter(S=>S.toLowerCase().includes(A))},[n,f,x]),B=A=>{A&&(k.current=!0,c(A),u(A)),t(A)},P=A=>{j(A),A?(b.current=s,k.current=!1,c(s),u(s)):k.current||o?.(b.current)},z=A=>{clearTimeout(v.current),v.current=setTimeout(()=>{o?.(A)},50)},M=()=>{clearTimeout(v.current)};return l.useEffect(()=>{if(!p)return;const A=S=>{(S.key==="ArrowDown"||S.key==="ArrowUp")&&requestAnimationFrame(()=>{const K=I.current?.querySelector("[data-highlighted]");if(K){const q=K.getAttribute("data-value");q&&o?.(q)}})};return document.addEventListener("keydown",A,!0),()=>{document.removeEventListener("keydown",A,!0)}},[p,o]),l.useEffect(()=>()=>{clearTimeout(v.current)},[]),e.jsxs(em,{value:x,onValueChange:B,inputValue:f,onInputValueChange:u,open:p,onOpenChange:P,children:[e.jsxs("div",{className:"relative",children:[e.jsx(sm,{placeholder:h("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:A=>m(A===!0),onClick:A=>A.stopPropagation()}),e.jsx("label",{htmlFor:"show-favorites-only-inner",className:"text-xs text-muted-foreground cursor-pointer whitespace-nowrap",onClick:A=>A.stopPropagation(),onKeyDown:A=>A.stopPropagation(),children:h("Show favorites only")})]})]}),e.jsx(nm,{children:e.jsxs(rm,{ref:I,children:[R.length===0&&e.jsx("div",{className:"py-6 text-center text-sm text-muted-foreground",children:h(d?"No favorite themes yet. Click the heart icon to add favorites.":"No themes found")}),R.map(A=>e.jsx(am,{value:A,"data-value":A,onMouseEnter:()=>z(A),onMouseLeave:M,endAddon:e.jsx(Jm,{isFavorite:C.has(A),onClick:()=>r(A),ariaLabel:C.has(A)?h("Remove from favorites"):h("Add to favorites")}),children:A},A))]})})]})}const Qm={theme:"Follow theme",violet:"Violet",indigo:"Indigo",teal:"Teal",amber:"Amber",graphite:"Graphite"},Ra={body:"Body",h1:"Heading 1",h2:"Heading 2",h3:"Heading 3",h4:"Heading 4–6",table:"Table",inlineCode:"Inline code",codeBlock:"Code block"},Oa=Hr.map(s=>({value:String(s),label:String(s)}));function Zm(){const{t:s}=D(),t=g(d=>d.chatTypography),n=g(d=>d.setChatTypography),a=g(d=>d.resetChatTypography),[r,o]=l.useState(t.body.size);l.useEffect(()=>{o(t.body.size)},[t.body.size]);const i=(d,h)=>{const x=g.getState().chatTypography;n({...x,[d]:{...x[d],size:h}})},m=(d,h)=>{const x=g.getState().chatTypography;n({...x,[d]:{...x[d],weight:h}})};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:[pl.map(d=>{const h=fl[d];return e.jsx(os,{label:s(Ra[d]),value:t[d].size,min:h.min,max:h.max,step:h.step,unit:h.unit==="%"?"%":"px",valueClassName:"w-28",formatSuffix:h.unit==="%"?x=>`${(r*x/100).toFixed(1)}px`:void 0,onPreview:d==="body"?o:void 0,onCommit:x=>i(d,x),trailing:e.jsxs(ne,{items:Oa,value:String(t[d].weight),onValueChange:x=>{const c=Number(x);Hr.includes(c)&&m(d,c)},children:[e.jsx(ae,{className:"w-24 min-w-24","aria-label":s(Ra[d]),children:e.jsx(re,{})}),e.jsx(oe,{children:Oa.map(x=>e.jsx(X,{value:x.value,children:x.label},x.value))})]})},d)}),e.jsx("div",{className:"flex justify-end",children:e.jsx(y,{variant:"outline",size:"sm",onClick:()=>a(),children:s("Reset to defaults")})})]})]})}function ex({seconds:s,onCommit:t}){const{t:n}=D(),[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=vl(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(Y,{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 sx(){const{t:s}=D(),t=g(A=>A.openChangesOnFileEdit),n=g(A=>A.setOpenChangesOnFileEdit),a=g(A=>A.compactReadOnlyTools),r=g(A=>A.setCompactReadOnlyTools),o=g(A=>A.expandLiveEdits),i=g(A=>A.setExpandLiveEdits),m=g(A=>A.expandLiveReasoning),d=g(A=>A.setExpandLiveReasoning),h=g(A=>A.autoCollapseTurns),x=g(A=>A.setAutoCollapseTurns),c=g(A=>A.collapseCompletedActivity),f=g(A=>A.setCollapseCompletedActivity),u=g(A=>A.collapseLiveActivity),p=g(A=>A.setCollapseLiveActivity),j=g(A=>A.liveActivityFoldDelaySec),v=g(A=>A.setLiveActivityFoldDelaySec),I=g(A=>A.pinUnfinishedTodos),b=g(A=>A.setPinUnfinishedTodos),k=g(A=>A.headerSessionTabs),C=g(A=>A.setHeaderSessionTabs),R=g(A=>A.headerRecentMinutes),B=g(A=>A.setHeaderRecentMinutes),P=A=>A===0?s("Off"):s("{{count}} min",{count:A}),z=g(A=>A.navRailSide),M=g(A=>A.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(Se,{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(Se,{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(Se,{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(Se,{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:d}),e.jsx(Se,{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:h,onChange:x}),e.jsx(Se,{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(Se,{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:u,onChange:p,children:u?e.jsx(ex,{seconds:j,onCommit:v}):null}),e.jsx(Se,{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:I,onChange:b}),e.jsx(Se,{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:C,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(A=>[String(A),P(A)])),value:String(R),onValueChange:A=>B(Number(A)),children:[e.jsx(ae,{className:"w-28",children:e.jsx(re,{})}),e.jsx(oe,{children:ft.map(A=>e.jsx(X,{value:String(A),children:P(A)},A))})]})]})}),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(Mn,{value:z,options:[{value:"left",label:s("Left")},{value:"right",label:s("Right")},{value:"off",label:s("Off")}],onChange:M})})]})]}),e.jsx(Zm,{}),e.jsx(lm,{})]})}function tx({onOpenPlugins:s}){const{t}=D(),n=g(i=>i.themeId),a=g(i=>i.setThemeId),r=En(i=>i.themes),o=Vr();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(Wm,{themes:Kr(r),selected:n,mode:o,onSelect:a,onGetMore:s})]})}function nx(){const{t:s}=D(),t=g(r=>r.userCssEnabled),n=g(r=>r.setUserCssEnabled),a=async()=>{const r=await window.electronAPI.appearance.openUserCss();r.ok||Pe({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(ml,{}),s("Open user.css")]}),e.jsx(le,{checked:t,onCheckedChange:r=>n(r===!0),"aria-label":s("Custom CSS")})]})}function ax({onOpenPlugins:s}={}){const t=g(_=>_.borderOpacity),n=g(_=>_.setBorderOpacity),{theme:a,setTheme:r,themeId:o,accentColor:i,setAccentColor:m,terminalTheme:d,setTerminalTheme:h,terminalFontSize:x,setTerminalFontSize:c,terminalFontFamily:f,setTerminalFontFamily:u,terminalFontWeight:p,setTerminalFontWeight:j,terminalFontWeightBold:v,setTerminalFontWeightBold:I,favoriteTerminalThemes:b,toggleFavoriteTerminalTheme:k}=g(),{t:C}=D(),R=Vr(),B=En(_=>_.themes),P=[{value:"light",icon:Vu,label:C("Light")},{value:"dark",icon:rl,label:C("Dark")},{value:"system",icon:Pn,label:C("System")},{value:"sync-terminal",icon:Gr,label:C("Sync terminal theme")}],z=ol.map(_=>({value:_,label:C(Qm[_]),swatch:_==="theme"?ll(o,Kr(B))[R].accent:il[_][R]})),[M,A]=l.useState(x),[S,K]=l.useState(f),[q,N]=l.useState(!1);l.useEffect(()=>{A(x)},[x]),l.useEffect(()=>{K(f)},[f]);const L=l.useCallback(()=>{const _=Math.max(8,Math.min(32,M||8));_!==M&&A(_),_!==x&&c(_)},[M,x,c]),V=l.useCallback(()=>{const _=S.trim()||f;_!==S&&K(_),_!==f&&u(_)},[S,f,u]),$=l.useMemo(()=>cl(),[]),O=l.useMemo(()=>{if(!q)return $;const _=$.filter(de=>b.includes(de));return b.includes(d)?_:[d,..._]},[$,q,b,d]),te=q&&b.length===0,G=l.useMemo(()=>ul(d)??dl,[d]),J=_=>{_&&h(_)},W=()=>{const _=q?O:$,de=_.indexOf(d),T=de<=0?_.length-1:de-1;h(_[T])},ce=()=>{const _=q?O:$,de=_.indexOf(d),T=de>=_.length-1?0:de+1;h(_[T])};return e.jsxs("div",{className:"space-y-6",children:[e.jsx(tx,{onOpenPlugins:s}),e.jsxs("section",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:C("Personalization")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C("Applied on top of any theme")})]}),e.jsxs(Hm,{children:[e.jsx(un,{rowId:"appearance.theme",title:C("Theme mode"),children:e.jsx("div",{className:"flex rounded-lg bg-muted p-0.5",children:P.map(_=>e.jsxs("button",{type:"button",onClick:()=>r(_.value),"aria-pressed":a===_.value,className:H("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:C("Accent color"),description:C("Used for running state, checkmarks and plan mode"),children:z.map(_=>_.value==="theme"?e.jsxs("button",{type:"button",onClick:()=>m(_.value),"aria-pressed":i===_.value,className:H("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:H("size-5 rounded-full transition-shadow",i===_.value&&"ring-2 ring-offset-2 ring-offset-card ring-foreground/60")},_.value))}),e.jsx(nx,{})]})]}),e.jsx(sx,{}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:C("Terminal")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C("Terminal appearance")})]}),e.jsx(Ym,{theme:G,fontSize:M,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:C("Color scheme")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{variant:"outline",size:"icon",onClick:W,children:e.jsx(Wr,{className:"h-4 w-4"})}),e.jsx("div",{className:"flex-1",children:e.jsx(Xm,{value:d,onValueChange:J,themes:O,favoriteThemes:b,onToggleFavorite:k,onThemeHover:h,showFavoritesOnly:q,onShowFavoritesOnlyChange:N,showEmptyFavoritesHint:te})}),e.jsx(y,{variant:"outline",size:"icon",onClick:ce,children:e.jsx(zs,{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:C("Font")}),e.jsx(Y,{value:S,onChange:_=>K(_.target.value),onBlur:V,onKeyDown:_=>{_.nativeEvent.isComposing||_.key==="Enter"&&(V(),_.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:C("Font size")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Y,{type:"number",value:M,onChange:_=>A(Number(_.target.value)),onBlur:L,onKeyDown:_=>{_.key==="Enter"&&(L(),_.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:C("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(X,{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:C("Bold font weight")}),e.jsxs(ne,{items:rt,value:v,onValueChange:_=>I(_),children:[e.jsx(ae,{className:"w-48",children:e.jsx(re,{})}),e.jsx(oe,{children:rt.map(_=>e.jsx(X,{value:_.value,children:_.label},_.value))})]})]})]}),e.jsx(os,{label:C("Border opacity"),value:Math.round(t*100),onCommit:_=>n(_/100)}),e.jsx(qm,{})]})}const Da=15e3,rx=3e3;function ox(s){return!s||!s.timeoutSet&&s.timeoutMs===rx?Da:s.timeoutMs}const La=()=>{},_t="off",Ft=s=>({timeoutMs:s?.timeoutMs??bl,...s?.timeoutSet&&{timeoutSet:!0}});function ix({classifier:s,effectiveMs:t,hint:n,onChange:a}){const{t:r}=D(),[o,i]=l.useState(String(t/1e3));l.useEffect(()=>i(String(t/1e3)),[t]);const m=()=>{const d=Number(o);if(!o.trim()||!Number.isFinite(d))return i(String(t/1e3));const h=Nl(d*1e3);i(String(h/1e3)),h!==t&&a({...s,timeoutMs:h,timeoutSet:!0})};return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs",children:r("Timeout")}),e.jsx(Y,{type:"number",value:o,min:wl/1e3,max:yl/1e3,step:.5,className:"h-7 w-20 text-xs",onChange:d=>i(d.target.value),onBlur:m,onKeyDown:d=>{d.key==="Enter"&&d.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:La,onThinkingChange:La})})}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 Fo({value:s,onChange:t,providers:n,classifierProviders:a,offLabel:r,judgeLabel:o,judgeSeed:i,description:m,effectiveTimeoutMs:d,timeoutHint:h}){const{t:x}=D(),c=s,[f,u]=l.useState(!1),p=c?.source??(f?"judge":_t),j=c?.source==="pi-classifier"?c.model.providerId:"",[v,I]=l.useState([]),[b,k]=l.useState(!1);l.useEffect(()=>{if(!j){I([]);return}let P=!1;return window.electronAPI.providers.classifierModels(j).then(z=>{P||I(z)}),()=>{P=!0}},[j]);const C=async P=>{const M=(await window.electronAPI.providers.classifierModels(P))[0];k(!M),M&&t({source:"pi-classifier",model:{providerId:P,modelId:M.id},...Ft(c)})},R=P=>{if(k(!1),u(P==="judge"&&!i),P===_t)return t(void 0);if(P==="judge")return t(i?{source:"judge",model:i,...Ft(c)}:void 0);const z=a[0];z&&C(z.id)},B=[{value:_t,label:r},{value:"judge",label:o},...a.length>0?[{value:"pi-classifier",label:x("Classifier model")}]:[]];return e.jsxs("div",{className:"space-y-1",children:[e.jsxs(ne,{items:B,value:p,onValueChange:P=>R(String(P)),children:[e.jsx(ae,{size:"sm",className:"w-48",children:e.jsx(re,{})}),e.jsx(oe,{children:B.map(P=>e.jsx(X,{value:P.value,children:P.label},P.value))})]}),p==="judge"&&e.jsx(ht,{providers:n,value:c?.source==="judge"?c.model:void 0,emptyLabel:x("Select model"),onSelect:P=>{u(!1),t({source:"judge",model:P,...Ft(c)})}}),c?.source==="pi-classifier"&&e.jsxs("div",{className:"flex gap-1",children:[e.jsxs(ne,{items:a.map(P=>({value:P.id,label:P.name})),value:c.model.providerId,onValueChange:P=>{C(String(P))},children:[e.jsx(ae,{size:"sm",className:"w-40",children:e.jsx(re,{})}),e.jsx(oe,{children:a.map(P=>e.jsx(X,{value:P.id,children:P.name},P.id))})]}),e.jsxs(ne,{items:v.map(P=>({value:P.id,label:P.name})),value:c.model.modelId||null,onValueChange:P=>t({...c,model:{providerId:c.model.providerId,modelId:String(P)}}),children:[e.jsx(ae,{size:"sm",className:"min-w-0 flex-1",children:e.jsx(re,{placeholder:x("Select model")})}),e.jsx(oe,{children:v.map(P=>e.jsx(X,{value:P.id,children:P.name},P.id))})]})]}),b&&e.jsx("p",{className:"text-[10px] text-destructive",children:x("No classifier models available")}),c&&e.jsx(ix,{classifier:c,effectiveMs:d??c.timeoutMs,hint:h,onChange:t}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:m})]})}function lx({entry:s,providers:t,classifierProviders:n,update:a}){const{t:r}=D();return s.fast?e.jsx(Fo,{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 cx({entry:s,providers:t,classifierProviders:n}){const{t:a}=D(),r=g(h=>h.updateVirtualModel),o=g(h=>h.removeVirtualModel),i=[s.primary,...s.fast?[s.fast]:[],...s.fallbacks];let m;for(const h of t){const x=h.models.find(c=>c.enabled!==!1&&!i.some(f=>f.providerId===h.id&&f.modelId===c.id));if(x){m={providerId:h.id,modelId:x.id};break}}const d=h=>r(s.id,h);return e.jsxs("div",{"data-slot":"virtual-model-card",className:H("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(le,{"aria-label":a("Enable virtual model"),checked:s.enabled,onCheckedChange:h=>d({enabled:h})}),e.jsx(Y,{value:s.name,maxLength:60,placeholder:"Auto",className:"h-7 flex-1 text-xs",onChange:h=>d({name:h.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(Ee,{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:h=>d({primary:h,fallbacks:s.fallbacks.filter(x=>x.providerId!==h.providerId||x.modelId!==h.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:h=>d({fast:h})}),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:()=>d({fast:void 0}),children:e.jsx(vs,{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((h,x)=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(ht,{providers:t,value:h,onSelect:c=>d({fallbacks:s.fallbacks.map((f,u)=>u===x?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:()=>d({fallbacks:s.fallbacks.filter((c,f)=>f!==x)}),children:e.jsx(vs,{className:"h-3.5 w-3.5"})})]},`${h.providerId}/${h.modelId}`)),e.jsxs(y,{type:"button",variant:"outline",size:"sm",className:"h-7 text-xs",disabled:!m||s.fallbacks.length>=8,onClick:()=>{m&&d({fallbacks:[...s.fallbacks,m]})},children:[e.jsx(Me,{className:"mr-1 h-3.5 w-3.5"}),a("Add fallback")]})]}),e.jsx(ct,{label:a("Difficulty routing"),children:e.jsx(lx,{entry:s,providers:t,classifierProviders:n,update:d})})]})}function dx(){const{t:s}=D(),t=g(d=>d.virtualModels),n=g(d=>d.addVirtualModel),a=g(d=>d.defaultModel),r=es(),o=l.useMemo(()=>r.filter(qr),[r]),i=Rn(),m=l.useMemo(()=>{if(a&&o.find(h=>h.id===a.providerId)?.models.some(h=>h.id===a.modelId&&h.enabled!==!1))return a;for(const d of o){const h=d.models.find(x=>x.enabled!==!1);if(h)return{providerId:d.id,modelId:h.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(d=>e.jsx(cx,{entry:d,providers:o,classifierProviders:i},d.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(Me,{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 ux(){const{t:s}=D();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(hx,{}),e.jsx(px,{}),e.jsx(mx,{}),e.jsx(xx,{})]})}function mx(){const{t:s}=D(),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(le,{checked:n,onCheckedChange:r=>a(r===!0)})]}):null}const za=Array.from({length:kl-la+1},(s,t)=>la+t);function xx(){const{t:s}=D(),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(za.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:za.map(a=>e.jsx(X,{value:String(a),children:a},a))})]})]})}function hx(){const{t:s}=D(),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 px(){const{t:s}=D(),t=g(m=>m.botRouteClassifier),n=g(m=>m.setBotRouteClassifier),a=g(m=>m.botDiscussModeEnabled),r=es(),o=l.useMemo(()=>r.filter(qr),[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(Fo,{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?ox(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 fx=()=>({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:[]}),gx=()=>({title:"",summary:"",bossKey:"m1",workspace:"chat-home",members:[mn("m1",0),mn("m2",1)]});function jx(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 vx(){const{t:s}=D(),t=Cl(!0),n=Sl(!0),[a,r]=l.useState(null),[o,i]=l.useState(null),m=l.useRef(null),d=async(p,j)=>{const v=await Fl(I=>({...I,[p]:j(I[p])}));return v||Pe({type:"error",title:s("Could not save templates")}),v},h=(p,j)=>d("members",v=>p?ua(v,p,j,Vl):ma(v,j,crypto.randomUUID())),x=(p,j)=>d("teams",v=>p?ua(v,p,j,Gl):ma(v,j,crypto.randomUUID())),c=async p=>{const j=Ml(await p.text());if(!j.ok){Pe({type:"error",title:ca(j.error,s)});return}const v=Jr(Tl(j.team));if(!v){Pe({type:"error",title:ca("invalid",s)});return}await x(void 0,v)&&Pe({type:"success",title:s("Imported as a custom team template")})},f=(p,j)=>d(p==="members"?"members":"teams",j),u=(p,j,v)=>e.jsxs(e.Fragment,{children:[e.jsx(js,{label:s("Edit"),onClick:()=>v({id:j.id,data:j.data}),children:e.jsx(ms,{})}),e.jsx(js,{label:s("Duplicate as custom"),onClick:()=>v({data:j.data}),children:e.jsx(Yr,{})}),j.source==="builtin"&&e.jsx(js,{label:j.hidden?s("Show"):s("Hide"),onClick:()=>{f(p,I=>Bl(I,j.id,!j.hidden))},children:j.hidden?e.jsx(El,{}):e.jsx(Pl,{})}),j.modified&&e.jsx(js,{label:s("Restore default"),onClick:()=>{f(p,I=>xa(I,j.id))},children:e.jsx(On,{})}),j.source==="custom"&&e.jsx(js,{label:s("Delete"),onClick:()=>{f(p,I=>xa(I,j.id))},children:e.jsx(Ee,{})})]});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:fx()}),children:[e.jsx(Me,{}),s("New member template")]}),t.map(p=>e.jsx(_a,{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:u("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:gx()}),children:[e.jsx(Me,{}),s("New team template")]}),e.jsxs(y,{size:"sm",variant:"outline",onClick:()=>m.current?.click(),children:[e.jsx(Il,{}),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(_a,{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(js,{label:s("Export JSON"),onClick:()=>jx(`${p.data.title||"team"}.team.json`,{format:Ul,version:$l,exportedAt:new Date().toISOString(),team:Al(p.data)}),children:e.jsx(bn,{})}),u("teams",p,i)]})},p.id))]})]}),a&&e.jsx(bx,{initial:a.data,onClose:()=>r(null),onSave:async p=>{await h(a.id,p)&&r(null)}}),o&&e.jsx(wx,{initial:o.data,onClose:()=>i(null),onSave:async p=>{await x(o.id,p)&&i(null)}})]})}function js({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 _a({item:s,avatar:t,title:n,subtitle:a,summary:r,actions:o}){const{t:i}=D();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:H("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 Bo({title:s,error:t,onClose:n,onSave:a,children:r}){const{t:o}=D(),[i,m]=l.useState(!1);return e.jsx(je,{open:!0,onOpenChange:d=>!d&&n(),children:e.jsxs(ve,{className:"max-h-[85vh] max-w-2xl",children:[e.jsx(be,{children:e.jsx(ye,{children:s})}),e.jsxs(we,{className:"space-y-3",children:[r,t&&e.jsx("p",{className:"text-destructive text-xs",children:t})]}),e.jsxs(Ie,{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 $o({value:s,onChange:t}){const{t:n}=D(),a=s.name?Xr(s.name,[],n):null;return e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(Ke,{children:n("Name")}),e.jsx(Y,{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(Ke,{children:n("Title")}),e.jsx(Y,{value:s.title,onChange:r=>t({title:r.target.value})})]}),e.jsxs("div",{children:[e.jsx(Ke,{children:n("Avatar color")}),e.jsx(zl,{value:s.color,onChange:r=>t({color:r})})]}),e.jsxs("div",{children:[e.jsx(Ke,{children:n("Tools")}),e.jsx(Mn,{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(Ke,{children:n("Approval mode")}),e.jsx(_l,{value:s.approvalMode,onChange:r=>t({approvalMode:r}),zIndex:is.DROPDOWN_IN_MODAL})]}),s.summary!==void 0&&e.jsxs("div",{className:"col-span-2",children:[e.jsx(Ke,{hint:n("Shown on the template card"),children:n("Summary")}),e.jsx(Y,{value:s.summary,onChange:r=>t({summary:r.target.value})})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(Ke,{children:n("Responsibilities")}),e.jsx(Y,{value:s.scope,onChange:r=>t({scope:r.target.value})})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(Ke,{children:n("Persona")}),e.jsx(Xe,{rows:6,value:s.persona,onChange:r=>t({persona:r.target.value})})]})]})}function bx({initial:s,onClose:t,onSave:n}){const{t:a}=D(),[r,o]=l.useState(s),i=Rl(r);return e.jsx(Bo,{title:a("Member template"),error:Xr(r.name,[],a)??(i?null:a("Check the template fields")),onClose:t,onSave:()=>i?n(i):Promise.resolve(),children:e.jsx($o,{value:r,onChange:m=>o(d=>({...d,...m}))})})}function yx(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 wx({initial:s,onClose:t,onSave:n}){const{t:a}=D(),[r,o]=l.useState(s),[i,m]=l.useState(null),d=p=>r.members.find(j=>j.key===p)?.name||p,h=p=>o(j=>({...j,...p})),x=(p,j)=>o(v=>({...v,members:v.members.map(I=>I.key===p?{...I,...j}:I)})),c=()=>{const p=new Set(r.members.map(I=>I.key));let j=r.members.length+1;for(;p.has(`m${j}`);)j++;const v=`m${j}`;h({members:[...r.members,mn(v,r.members.length)]}),m(v)},f=p=>{const j=v=>v==="any"?"any":v.filter(I=>I!==p);h({members:r.members.filter(v=>v.key!==p).map(v=>({...v,canDelegateTo:j(v.canDelegateTo),acceptFrom:j(v.acceptFrom)}))})},u=Jr(r);return e.jsxs(Bo,{title:a("Team template"),error:yx(Ll(r),a),onClose:t,onSave:()=>u?n(u):Promise.resolve(),children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(Ke,{children:a("Group name")}),e.jsx(Y,{value:r.title,onChange:p=>h({title:p.target.value})})]}),e.jsxs("div",{children:[e.jsx(Ke,{children:a("Owner")}),e.jsxs(ne,{items:r.members.map(p=>({value:p.key,label:d(p.key)})),value:r.bossKey,onValueChange:p=>h({bossKey:p}),children:[e.jsx(ae,{className:"w-full",children:e.jsx(re,{})}),e.jsx(oe,{zIndex:is.DROPDOWN_IN_MODAL,children:r.members.map(p=>e.jsx(X,{value:p.key,children:d(p.key)},p.key))})]})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(Ke,{hint:a("Shown on the template card"),children:a("Summary")}),e.jsx(Y,{value:r.summary,onChange:p=>h({summary:p.target.value})})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(Ke,{children:a("Shared workspace")}),e.jsx(Mn,{value:r.workspace,options:[{value:"chat-home",label:a("Standalone workspace")},{value:"project",label:a("Based on a Code project")}],onChange:p=>h({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>=Ol,onClick:c,children:[e.jsx(Me,{}),a("Add member")]})]}),e.jsx("div",{className:"space-y-1.5",children:r.members.map(p=>{const j=i===p.key,v=p.key===r.bossKey,I=r.members.filter(b=>b.key!==p.key).map(b=>b.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(zs,{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}),v&&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(Dl,{className:"h-3 w-3"}),a("Owner")]})]}),e.jsx(js,{label:a("Remove"),disabled:v||r.members.length<=2,onClick:()=>f(p.key),children:e.jsx(Ee,{})})]}),j&&e.jsxs("div",{className:"space-y-3 border-t p-2.5",children:[e.jsx($o,{value:p,onChange:b=>x(p.key,b)}),e.jsx(da,{label:a("Can delegate to"),value:p.canDelegateTo,options:I,nameOf:d,onChange:b=>x(p.key,{canDelegateTo:b})}),e.jsx(da,{label:a("Accepts delegation from"),value:p.acceptFrom,options:I,nameOf:d,onChange:b=>x(p.key,{acceptFrom:b})})]})]},p.key)})})]})]})}function Uo(s){return s.capturePermission==="unsupported"&&s.axPermission==="unsupported"?"unsupported":s.capturePermission==="granted"&&(s.axPermission==="granted"||s.axPermission==="unsupported")?"ready":"needs-permission"}const Nx=[{id:"collaboration",label:"Collaboration & planning"},{id:"web",label:"Web"},{id:"execution",label:"Execution"},{id:"context",label:"Context & memory"},{id:"safety",label:"Safety"}],Fa={subagent:"collaboration",workflow:"collaboration",todo:"collaboration",plan:"collaboration",ask_user:"collaboration",browser:"web",web:"web",background_tasks:"execution",isolated_sandbox:"execution",computer:"execution",image_generation:"execution",memory:"context",turn_discard:"context"};function kx(s,t){return s.filter(n=>Object.hasOwn(Fa,n.id)?Fa[n.id]===t:!1)}function Ba(s){return s.bundleId||s.path}function Cx(){const{t:s}=D(),[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(Ba(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(le,{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")})]},Ba(i)))}):null]})}function Sx(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}=D(),a=t?"…":s?.tokens==null?"—":He(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:He(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 d=!1;const h=i.length===0?[]:i.split("\0");if(h.length===0){a({}),o(!1);return}return o(!0),m.current(h).then(x=>{d||a(Sx(x))}).finally(()=>{d||o(!1)}),()=>{d=!0}},[i]),{rows:n,pending:r}}const $a={replace:"Text replacement",apply_patch:"Apply patch (default)"},Ix={subagent:Ql,workflow:Dn,todo:Xl,plan:Jl,ask_user:Yl,browser:ql,web:Zr,background_tasks:Hl,memory:Qr,isolated_sandbox:yu,computer:Pn,turn_discard:Wl};function Ms({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 Ax({disabled:s}){const{t}=D(),n=g(c=>c.webSearchChain),a=g(c=>c.setWebSearchChain),r=et(),o=l.useMemo(()=>sc(r),[r]),[i,m]=l.useState(null),d=(c,f)=>{a(n.map((u,p)=>p===c?{...u,...f}:u))},h=c=>a(n.filter((f,u)=>u!==c)),x=(c,f)=>{if(c===f)return;const u=[...n],[p]=u.splice(c,1);p&&(u.splice(f,0,p),a(u))};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:u=>{u.dataTransfer.effectAllowed="move",m(f)},onDragEnd:()=>m(null),onDragOver:u=>{i!==null&&i!==f&&u.preventDefault()},onDrop:u=>{u.preventDefault(),i!==null&&x(i,f),m(null)},children:[e.jsx(tc,{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:(u,p)=>d(f,{providerId:u,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:()=>h(f),"aria-label":t("Remove"),children:e.jsx(Ee,{className:"h-3.5 w-3.5"})})]},`${c.providerId}/${c.modelId}`)),n.length<nc&&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 Ex(){const{t:s}=D(),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),d=g(N=>N.computerPreview),h=g(N=>N.setComputerPreview),x=g(N=>N.openLinksInBuiltinBrowser),c=g(N=>N.setOpenLinksInBuiltinBrowser),f=g(N=>N.setRtkEnabled),u=g(N=>N.protectedActionsInCode),p=g(N=>N.setProtectedActionsInCode),j=g(N=>N.editMode),v=g(N=>N.setEditMode),I=It(zt.map(N=>N.id),()=>window.electronAPI.assets.builtinToolOccupancy()),b=kt(zt.filter(N=>!t.includes(N.id)).map(N=>N.id),I.rows),[k,C]=l.useState(null),R=!t.includes("subagent"),B=(N,L)=>{r(L?[...new Set([...a,N])]:a.filter(V=>V!==N))},P=async N=>{await window.electronAPI.browser.clearData(N),C(N),setTimeout(()=>C(null),2e3)},z=!t.includes("computer"),[M,A]=l.useState(null),[S,K]=l.useState(!1);l.useEffect(()=>{if(!z){A(null);return}let N=!1;return window.electronAPI.computer.capabilities().then(L=>{!N&&L.ok&&A(L.capabilities)}),()=>{N=!0}},[z]),l.useEffect(()=>{if(!S)return;let N=!1;const L=()=>{window.electronAPI.computer.capabilities().then($=>{!N&&$.ok&&A($.capabilities)})};L();const V=window.setInterval(L,2e3);return()=>{N=!0,window.clearInterval(V)}},[S]);const q={collaboration:null,web:null,execution:e.jsx(Ms,{rowId:"tools.editMode",newSession:!0,icon:Iu,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(ha.map(N=>[N,s($a[N])])),value:j,onValueChange:N=>{Kl(N)&&v(N)},children:[e.jsx(ae,{className:"w-44 shrink-0","aria-label":s("File edit mode"),children:e.jsx(re,{})}),e.jsx(oe,{children:ha.map(N=>e.jsx(X,{value:N,children:s($a[N])},N))})]})}),context:e.jsxs(e.Fragment,{children:[e.jsx(Ms,{icon:Mu,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(le,{checked:o,onCheckedChange:i})}),e.jsx(Ms,{rowId:"tools.rtkEnabled",newSession:!0,icon:Fu,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(le,{checked:m,onCheckedChange:f})})]}),safety:e.jsxs(e.Fragment,{children:[e.jsx(Ms,{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(le,{checked:u,onCheckedChange:p})}),e.jsx(Px,{})]})};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:b})]}),e.jsx("p",{className:"text-muted-foreground text-sm",children:s("Toggle the built-in tools available to agents.")})]}),Nx.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)}),kx(zt,N.id).map(L=>e.jsxs(Ms,{icon:Ix[L.id]??eo,title:s(L.name),description:s(L.description),newSession:L.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:I.rows[L.id],pending:I.pending&&!I.rows[L.id]}),e.jsx(le,{checked:!t.includes(L.id),onCheckedChange:V=>{n(L.id,V),L.id==="computer"&&V&&K(!0)}})]}),children:[L.id==="web"?e.jsx(Ax,{disabled:t.includes("web")}):null,L.id==="subagent"?e.jsxs("div",{className:"space-y-2","data-settings-row":"tools.subagentModes",children:[[["task","One-shot task agents"],["coworker","Persistent coworkers"]].map(([V,$])=>e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("span",{className:"text-sm",children:s($)}),e.jsx(le,{checked:a.includes(V),disabled:!R,onCheckedChange:O=>B(V,O)})]},V)),!R&&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,L.id==="computer"&&z?e.jsx("div",{className:"space-y-2","data-settings-row":"tools.computer",children:M&&Uo(M)==="unsupported"?e.jsx("p",{className:"text-muted-foreground text-xs",children:s("This platform cannot operate the desktop yet.")}):e.jsxs(e.Fragment,{children:[M?.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.")}),M&&e.jsxs("p",{className:"text-muted-foreground text-xs",children:[s(M.capturePermission==="granted"?"Capture: granted":"Capture: denied"),M.axPermission!=="unsupported"&&e.jsxs(e.Fragment,{children:[" · ",s(M.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:()=>K(!0),children:s("Show permission guide")}),M?.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")})]})]}),M?.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(le,{checked:d,onCheckedChange:h})]}),e.jsx(Cx,{})]})]})}):null,L.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:Zl?"Cmd":"Ctrl"})})]}),e.jsx(le,{checked:x,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(V=>e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{P(V)},children:s(k===V?"Cleared":V==="cookies"?"Clear cookies":V==="cache"?"Clear cache":"Clear all browsing data")},V))})]}):null]},L.id)),q[N.id]]},N.id)),e.jsx(Mx,{open:S,capabilities:M,onOpenChange:K})]})}function Px(){const{t:s}=D(),t=g(u=>u.dcgEnabled),n=g(u=>u.setDcgEnabled),[a,r]=l.useState(null),[o,i]=l.useState(!1),[m,d]=l.useState(null),[h,x]=l.useState(!1);l.useEffect(()=>{let u=!1;return window.electronAPI.dcg.status().then(p=>{u||r(p)}),()=>{u=!0}},[]);const c=async u=>{x(!1),i(!0),d(null);const p=await window.electronAPI.dcg[u]();r(p.status),p.ok?n(u==="install"):d(p.error??s("Operation failed")),i(!1)},f=a?.installed===!0;return e.jsxs(Ms,{rowId:"tools.dcgEnabled",newSession:!0,icon:ec,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(le,{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:()=>x(!0),children:s(o?"Installing…":"Install")}))]}),m&&e.jsx("p",{className:"text-destructive text-xs",children:m}),e.jsx(je,{open:h,onOpenChange:x,children:e.jsxs(ve,{className:"max-w-md",zIndexLevel:"nested",children:[e.jsxs(be,{children:[e.jsx(ye,{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(we,{children:e.jsxs("div",{className:"flex gap-2 rounded-md border border-destructive/32 bg-destructive/8 p-3 text-sm",children:[e.jsx(We,{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(Ie,{children:[e.jsx(y,{variant:"outline",size:"sm",onClick:()=>x(!1),children:s("Cancel")}),e.jsx(y,{size:"sm",onClick:()=>{c("install")},children:s("Agree and install")})]})]})})]})}function Mx({open:s,capabilities:t,onOpenChange:n}){const{t:a}=D(),r=t?Uo(t):null;return e.jsx(je,{open:s,onOpenChange:n,children:e.jsxs(ve,{className:"max-w-md",zIndexLevel:"nested",children:[e.jsxs(be,{children:[e.jsx(ye,{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(we,{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(We,{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(Ie,{className:"sm:justify-end",children:e.jsx(y,{size:"sm",onClick:()=>n(!1),children:a("Done")})})]})})}function Tx(){return e.jsxs("div",{className:"space-y-10",children:[e.jsx(Rx,{}),!window.electronAPI.remote&&e.jsx(Ox,{}),e.jsx(zx,{})]})}function Rx(){const{t:s}=D(),[t,n]=l.useState(null),[a,r]=l.useState(null),[o,i]=l.useState(!1),[m,d]=l.useState(null),[h,x]=l.useState(null),[c,f]=l.useState(!1),u=t?.pairingExpiresAt;l.useEffect(()=>{if(!u){x(null);return}const I=()=>x(Math.max(0,Math.ceil((u-Date.now())/1e3)));I();const b=setInterval(I,1e3);return()=>clearInterval(b)},[u]);const p=I=>{navigator.clipboard.writeText(I).then(()=>{f(!0),setTimeout(()=>f(!1),1500)})};l.useEffect(()=>(window.electronAPI.pair.status().then(n),window.electronAPI.pair.onStatusChanged(I=>{n(I),(I.pairing||I.devices.length>0)&&d(null)})),[]),l.useEffect(()=>{const I=t?.inviteUri;if(!I){r(null);return}ac.toDataURL(I,{width:320,margin:1}).then(r).catch(()=>{})},[t?.inviteUri]);const j=async()=>{i(!0),d(null);const I=await window.electronAPI.pair.start();i(!1),I.ok||d(I.error??s("Failed to start pairing"))},v=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(Ae,{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(We,{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(Ae,{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:h===null?s("The code expires in 60 seconds and can only be used once."):h>0?s("Expires in {{seconds}}s · single use",{seconds:h}):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(so,{className:"mr-1.5 h-3.5 w-3.5"}):e.jsx(Yr,{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")}),v.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:v.map(I=>e.jsx(Dx,{device:I},I.pairId))})]})]})}function Ox(){const{t:s}=D(),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(Me,{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(We,{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(Pn,{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(Lx,{node:i,onChanged:()=>{a()}},i.nodeId))})]}),e.jsx(rc,{open:r,onOpenChange:o,switchOnSuccess:!1})]})}function Vo({transport:s,rttMs:t}){const{t:n}=D(),a=s==="direct",r=ic(t);return e.jsxs("span",{className:H("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 Dx({device:s}){const{t}=D(),[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:H("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(Vo,{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:H("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(Y,{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(ms,{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(Ee,{className:"h-3.5 w-3.5"})})]})]})}function Lx({node:s,onChanged:t}){const{t:n}=D(),[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(oc,{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(Vo,{transport:s.transport,rttMs:s.rttMs})]}):e.jsx(Y,{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(ms,{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(Ee,{className:"h-3.5 w-3.5"})})]})]})}function zx(){const{t:s}=D(),[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(Y,{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(ms,{className:"h-3.5 w-3.5"})}):e.jsxs(y,{size:"sm",className:"shrink-0",onClick:()=>{o()},children:[e.jsx(so,{className:"mr-1.5 h-3.5 w-3.5"}),s("Save")]})]})]})})}function _x({onOpenBots:s}){const{t}=D(),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),d=g(c=>c.secretaryEnabled),h=g(c=>c.setSecretaryEnabled),x=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(Se,{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(Se,{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}),x&&e.jsx(Se,{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(Se,{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:d,onChange:h})]})]})}function Fx({instruction:s,onClose:t}){const{t:n}=D(),a=g(P=>P.addInstructions),r=g(P=>P.updateInstruction),o=s==="new",i=o||!s?null:s,[m,d]=l.useState(""),[h,x]=l.useState(""),[c,f]=l.useState(!1),[u,p]=l.useState(!1),[j,v]=l.useState(null),[I,b]=l.useState(!1),[k,C]=l.useState(!1);l.useEffect(()=>{if(s){if(s==="new"){d(""),x(""),b(!1),v(null),C(!1),f(!1);return}d(s.name),b(!1),v(null),C(!1),f(!0),window.electronAPI.instructions.read(s.id,s.local,s.sourcePath).then(P=>{P.ok?x(P.content):(x(""),v(P.error??n("Failed to read content")))}).finally(()=>f(!1))}},[s,n]);const R=!!(i&&!i.local&&i.sourcePath),B=async()=>{if(!s||!m.trim())return;if(p(!0),o){const z=crypto.randomUUID(),M=await window.electronAPI.instructions.write(z,h);if(!M.ok){p(!1),v(n("Failed to save"));return}const A=a([{id:z,name:m.trim(),source:"Manual",local:!0,bytes:M.bytes,enabled:!0}]);if(p(!1),A===0){window.electronAPI.instructions.delete(z),v(n("An instruction with this name already exists"));return}t();return}if(!i){p(!1);return}if(R&&k&&i.sourcePath){const z=await window.electronAPI.instructions.writeSource(i.id,i.sourcePath,h);if(p(!1),!z.ok){v(z.error??n("Failed to save"));return}r(i.id,{name:m.trim(),bytes:z.bytes}),t();return}const P=await window.electronAPI.instructions.write(i.id,h);if(p(!1),!P.ok){v(n("Failed to save"));return}r(i.id,{name:m.trim(),local:!0,bytes:P.bytes}),t()};return e.jsx(je,{open:s!==null,onOpenChange:P=>!P&&t(),children:e.jsxs(ve,{className:"max-w-2xl",children:[e.jsx(be,{children:e.jsx(ye,{children:n(o?"Add Instruction":"Edit Instruction")})}),e.jsxs(we,{className:"space-y-4",children:[o?null:R?e.jsxs("div",{className:H("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(We,{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(le,{checked:k,onCheckedChange:C})]}),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(Y,{value:m,onChange:P=>d(P.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(Ae,{className:"h-4 w-4 animate-spin text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground text-xs",children:n("Loading...")})]}):e.jsx(Xe,{value:h,onChange:P=>{x(P.target.value),b(!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(Ds,{className:"h-3.5 w-3.5 shrink-0"}),j]})]}),e.jsxs(Ie,{children:[e.jsx(y,{variant:"outline",size:"sm",onClick:t,children:n("Cancel")}),e.jsxs(y,{size:"sm",variant:R&&k?"destructive":"default",disabled:!m.trim()||c||u,onClick:B,children:[u&&e.jsx(Ae,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}),n(R?k?"Overwrite original":I?"Save as local copy":"Save":"Save")]})]})]})})}const Ua=s=>s<1024?`${s} B`:`${(s/1024).toFixed(1)} KB`;function Bx(){const{t:s}=D(),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),d=t.map(c=>c.id),h=It(d,c=>window.electronAPI.assets.instructionOccupancy(c)),x=kt(t.filter(c=>c.enabled).map(c=>c.id),h.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:x}),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(Me,{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:H("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(to,{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")} · ${Ua(c.bytes)}`:`${c.sourcePath} · ${Ua(c.bytes)}`})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(Ct,{row:h.rows[c.id],pending:h.pending&&!h.rows[c.id]}),e.jsx(le,{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(ms,{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(Ee,{className:"h-3.5 w-3.5"})})]})]},c.id))}),e.jsx(zn,{kind:"instruction",open:r,onOpenChange:o}),e.jsx(Fx,{instruction:i,onClose:()=>m(null)})]})}function $x(){const{t:s}=D();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(Gx,{}),e.jsx(Vx,{})]})}function Ux(){const[s,t]=l.useState([]);return l.useEffect(()=>{const n=window.electronAPI.extensionPlugins;let a=!0;const r=()=>{n.list().then(i=>a&&t(dc(i)))};r();const o=n.onChanged(r);return()=>{a=!1,o()}},[]),s}function Vx(){const{t:s}=D(),t=Ux(),n=g(p=>p.keybindings),a=g(p=>p.setKeybinding),r=g(p=>p.resetKeybinding),[o,i]=l.useState(null),[m,d]=l.useState(null);if(t.length===0)return null;const h=no(n),{rows:x}=lc(t,n,h),c=p=>x.find(j=>j.action===p)?.command.title??s(on[p]??p),f=()=>{i(null),d(null)},u=(p,j,v)=>{if(p.preventDefault(),p.stopPropagation(),p.key==="Escape")return f();if(p.key==="Backspace"||p.key==="Delete")return a(j,""),f();const I=oo(p);if(!I)return;const b=rn.find(k=>h[k]===I)??x.find(k=>k.action!==j&&!k.conflict&&k.binding===I)?.action;if(b)return d(b);I===v?r(j):a(j,I),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:x.map(({action:p,command:j,binding:v,custom:I,conflict:b})=>{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,b&&!k&&e.jsx("span",{className:"ml-2 text-destructive",children:s('Already used by "{{label}}"',{label:c(b)})})]})]}),k&&m&&e.jsx("span",{className:"text-destructive text-xs",children:s('Already used by "{{label}}"',{label:c(m)})}),v&&!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(vs,{className:"h-3.5 w-3.5"})}),I&&!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),d(null)},onKeyDown:k?C=>u(C,p,j.key):void 0,onBlur:()=>k&&f(),autoFocus:k,className:H("rounded-md px-1 py-0.5 transition-colors",k?"ring-1 ring-ring":"hover:bg-muted",b&&!k&&"opacity-50 line-through"),children:k?e.jsx("span",{className:"text-muted-foreground text-xs",children:s("Press shortcut…")}):v?e.jsx(ao,{children:ro(v)}):e.jsx("span",{className:"text-muted-foreground text-xs",children:s("No shortcut")})})]},p)})})]})}function Gx(){const{t:s}=D(),t=g(x=>x.keybindings),n=g(x=>x.setKeybinding),a=g(x=>x.resetKeybinding),[r,o]=l.useState(null),[i,m]=l.useState(null),d=no(t),h=x=>{if(x.preventDefault(),x.stopPropagation(),!r)return;if(x.key==="Escape"){o(null),m(null);return}if(x.key==="Backspace"||x.key==="Delete"){n(r,""),o(null),m(null);return}const c=oo(x,{allowBare:r==="send-message"||r==="voice-hold"});if(!c)return;const f=rn.find(u=>u!==r&&d[u]===c);if(f){m(f);return}c===cc[r]?a(r):n(r,c),o(null),m(null)};return e.jsx("div",{className:"divide-y rounded-md border",children:rn.map(x=>{const c=r===x,f=t[x]!==void 0,u=d[x];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[x])}),pa[x]&&e.jsx("p",{className:"text-muted-foreground text-xs",children:s(pa[x])})]}),c&&i&&e.jsx("span",{className:"text-xs text-destructive",children:s('Already used by "{{label}}"',{label:s(on[i])})}),u&&!c&&e.jsx("button",{type:"button",title:s("Remove shortcut"),onClick:()=>n(x,""),className:"rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:e.jsx(vs,{className:"h-3.5 w-3.5"})}),f&&!c&&e.jsx("button",{type:"button",title:s("Reset to default"),onClick:()=>a(x),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(x),m(null)},onKeyDown:c?h:void 0,onBlur:()=>{c&&(o(null),m(null))},autoFocus:c,className:H("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…")}):u?e.jsx(ao,{children:ro(u)}):e.jsx("span",{className:"text-xs text-muted-foreground",children:s("No shortcut")})})]},x)})})}function Kx(s){return s.serverId??s.serverName}function Go(s,t){const n={...s};return t.serverId&&delete n[t.serverName],n[Kx(t)]={state:t.state,...t.toolCount!==void 0?{toolCount:t.toolCount}:{},...t.error?{error:t.error}:{}},n}function Wx(s){return s.reduce((t,n)=>Go(t,n),{})}function Hx(s,t){return{...s,[t]:{state:"connecting"}}}function qx(s,t,n){return{...s,[t]:{state:"error",...n?{error:n}:{}}}}const Bt=(s,t)=>{const n={...s};return delete n[t],n},gs=uc()((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,...Wx(n)}})).catch(()=>{}),window.electronAPI.mcp.onStatus(n=>{if(n.type==="mcp-status-cleared"){s({statuses:{}});return}s({statuses:Go(t().statuses,n)}),window.electronAPI.mcp.authState().then(a=>s({authorized:a})).catch(()=>{})})),authorize:async n=>{s({statuses:Hx(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:qx(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():"",Yx=s=>Array.isArray(s)?s.filter(t=>typeof t=="string"):[],Ko=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 Jx(s){const t=Ko(s);return delete t[""],Object.keys(t).length>0?t:void 0}function Va(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 Ga=s=>Object.entries(s??{}).map(([t,n])=>`${t}: ${n}`).join(`
12
- `);function Xx(s,t){const n=ts(s).toLowerCase();return n==="sse"?"sse":n==="http"||n==="streamable-http"?"http":n==="stdio"?"stdio":t?"http":"stdio"}function Ka(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:Jx(r.headers);t.push({name:n,transport:Xx(r.type??r.transport,o),command:i||void 0,args:i?Yx(r.args):void 0,env:i?Ko(r.env):void 0,url:o||void 0,...m?{headers:m}:{}})}return t}const Qx=s=>{const t=s.trim();return(t.match(/^```(?:json)?\s*([\s\S]*?)\s*```$/i)?.[1]??t).trim()},Zx=s=>s.startsWith('"')&&!s.startsWith("{")&&!s.startsWith("[")?`{${s}}`:s,eh=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},sh=s=>{if(!s||typeof s!="object"||Array.isArray(s))return!1;const t=s;return!!(ts(t.command)||ts(t.url)||ts(t.serverUrl))},th=s=>{const t=ts(s.command);return t&&t.split(/[\\/]/).pop()?.trim()||"mcp"},xn=s=>{if(Array.isArray(s))return s.flatMap(xn);if(sh(s)){const t=ts(s.name)||ts(s.id)||th(s);return Ka({[t]:s})}return Ka(s)};function $t(s){let t;try{t=JSON.parse(Zx(Qx(s)))}catch{return{ok:!1,error:"invalid-json"}}const n=Array.isArray(t)?t.flatMap(xn):xn(eh(t));return n.length===0?{ok:!1,error:"empty"}:{ok:!0,servers:n}}const nh=1e4,ah=12e4,rh=600,oh=3600;function Wa(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 ih={theme:xc,disableFileHeader:!0,overflow:"scroll",preferredHighlighter:"shiki-js"};function lh(s){return new jc(s)}function Wo({fileName:s,value:t,epoch:n,onChange:a,className:r="h-60"}){const{t:o}=D(),[i,m]=l.useState(!1),d=mc(ih),h=l.useRef(a);h.current=a;const x=l.useMemo(()=>({onChange(c){h.current(c.contents)}}),[]);return l.useEffect(()=>{let c=!0;return hc().then(()=>{c&&m(!0)}),()=>{c=!1}},[]),i?e.jsx("div",{className:H("w-full overflow-hidden rounded-lg border border-input",r),children:e.jsx(pc,{createEditor:lh,children:e.jsx(fc,{style:{height:"100%",overflow:"auto"},children:e.jsx(gc,{file:{name:s,contents:t},disableWorkerPool:!0,edit:!0,editorOptions:x,options:d},n)})})}):e.jsx("div",{className:H("flex w-full items-center justify-center rounded-lg border border-input text-muted-foreground text-xs",r),children:o("Loading...")})}const Ha=s=>{const t=s.split(`
13
- `).map(n=>n.trim()).filter(Boolean);return t.length>0?t:void 0},qa=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},Ya=s=>s?Object.entries(s).map(([t,n])=>`${t}=${n}`).join(`
15
- `):"",Ja=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 ch({server:s,onClose:t}){const{t:n}=D(),a=g(F=>F.addMcpServers),r=g(F=>F.updateMcpServer),o=s==="new",[i,m]=l.useState("form"),[d,h]=l.useState(""),[x,c]=l.useState(""),[f,u]=l.useState(""),[p,j]=l.useState(""),[v,I]=l.useState("stdio"),[b,k]=l.useState(""),[C,R]=l.useState(""),[B,P]=l.useState(""),[z,M]=l.useState(""),[A,S]=l.useState(""),[K,q]=l.useState(""),[N,L]=l.useState(""),[V,$]=l.useState(""),[O,te]=l.useState(0),[G,J]=l.useState(null),W=()=>({description:x.trim()||void 0,oauthClientName:v!=="stdio"&&f.trim()||void 0,oauthMetadataUrl:v!=="stdio"&&p.trim()||void 0,connectTimeoutSec:Wa(K,rh),callTimeoutSec:Wa(N,oh)}),ce=F=>{h(F.name),I(F.transport),k(F.command??""),R((F.args??[]).join(`
16
- `)),P(Ya(F.env&&Object.keys(F.env).length>0?F.env:void 0)),M(F.url??""),S(Ga(F.headers))},_=()=>{const F={type:v};if(v==="stdio"){F.command=b.trim();const ee=Ha(C);ee&&(F.args=ee);const Z=qa(B);Z&&(F.env=Z)}else{F.url=z.trim();const ee=Va(A);ee&&(F.headers=ee)}return JSON.stringify(F,null,2)},de=(F,ee)=>{const Z=(ee??F.name).trim(),me=F.env&&Object.keys(F.env).length>0?F.env:void 0,ke=F.args&&F.args.length>0?F.args:void 0;return F.transport==="stdio"?{name:Z,transport:F.transport,command:(F.command??"").trim(),args:ke,env:me,url:void 0,headers:void 0,...W()}:{name:Z,transport:F.transport,url:(F.url??"").trim(),headers:F.headers&&Object.keys(F.headers).length>0?F.headers:void 0,command:void 0,args:void 0,env:void 0,...W()}};l.useEffect(()=>{if(!s)return;const F=s==="new"?null:s;m("form"),h(F?.name??""),c(F?.description??""),u(F?.oauthClientName??""),j(F?.oauthMetadataUrl??""),I(F?.transport??"stdio"),k(F?.command??""),R((F?.args??[]).join(`
17
- `)),P(Ya(F?.env)),M(F?.url??""),S(Ga(F?.headers)),q(F?.connectTimeoutSec?.toString()??""),L(F?.callTimeoutSec?.toString()??""),$(""),te(ee=>ee+1),J(null)},[s]);const T=F=>n(F==="invalid-json"?"Invalid JSON":"No MCP servers found in JSON"),E=F=>{if(F===i)return;if(F==="json"){$(_()),te(me=>me+1),J(null),m("json");return}const ee=$t(V);if(!ee.ok){if(ee.error==="invalid-json"&&V.trim()){J(T(ee.error));return}J(null),m("form");return}if(ee.servers.length!==1){J(n("JSON must describe a single MCP server to switch to the form"));return}const Z=ee.servers[0];ce({...Z,name:d.trim()||Z.name}),J(null),m("form")},Q=()=>{const F=$t(V);if(!F.ok){J(T(F.error));return}if(F.servers.length===1){const[ee]=F.servers;$(JSON.stringify(Ja(ee),null,2)),te(Z=>Z+1),d.trim()||h(ee.name)}else $(JSON.stringify({mcpServers:Object.fromEntries(F.servers.map(ee=>[ee.name,Ja(ee)]))},null,2)),te(ee=>ee+1);J(null)},ie=!!d.trim()&&(v==="stdio"?!!b.trim():!!z.trim()),Re=i==="json"?!!V.trim():ie,Oe=()=>{if(!s||!Re)return;if(i==="json"){const ee=$t(V);if(!ee.ok){J(T(ee.error));return}if(!o&&ee.servers.length!==1){J(n("JSON must describe a single MCP server"));return}if(o){const Z=ee.servers.length===1;if(a(ee.servers.map(ke=>({...de(ke,Z&&d.trim()?d:ke.name),...Z?{}:{description:void 0},id:crypto.randomUUID(),source:"Manual",enabled:!0})))===0){J(n("This MCP server already exists"));return}}else r(s.id,de(ee.servers[0],d.trim()||ee.servers[0].name));t();return}const F=v==="stdio"?{name:d.trim(),transport:v,command:b.trim(),args:Ha(C),env:qa(B),url:void 0,headers:void 0,...W()}:{name:d.trim(),transport:v,url:z.trim(),headers:Va(A),command:void 0,args:void 0,env:void 0,...W()};if(o){if(a([{...F,id:crypto.randomUUID(),source:"Manual",enabled:!0}])===0){J(n("This MCP server already exists"));return}}else r(s.id,F);t()};return e.jsx(je,{open:s!==null,onOpenChange:F=>!F&&t(),children:e.jsxs(ve,{children:[e.jsx(be,{children:e.jsx(ye,{children:n(o?"Add MCP Server":"Edit MCP Server")})}),e.jsxs(we,{className:"space-y-4",children:[e.jsx(Qs,{value:i,onValueChange:F=>E(F),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(Y,{value:d,onChange:F=>h(F.target.value)})]}),e.jsxs(he,{children:[e.jsx(pe,{children:n("Description (optional)")}),e.jsx(Y,{value:x,onChange:F=>c(F.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:Q,children:n("Format")})]}),e.jsx(Wo,{fileName:"mcp.json",value:V,epoch:O,onChange:$}),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:fa.map(F=>({value:F,label:F})),value:v,onValueChange:F=>I(F),children:[e.jsx(ae,{className:"w-full",children:e.jsx(re,{})}),e.jsx(oe,{zIndex:is.DROPDOWN_IN_MODAL,children:fa.map(F=>e.jsx(X,{value:F,children:F},F))})]})]}),v==="stdio"?e.jsxs(e.Fragment,{children:[e.jsxs(he,{children:[e.jsx(pe,{children:n("Command")}),e.jsx(Y,{value:b,onChange:F=>k(F.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:C,onChange:F=>R(F.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:B,onChange:F=>P(F.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(Y,{value:z,onChange:F=>M(F.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:A,onChange:F=>S(F.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(Y,{value:f,onChange:F=>u(F.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(Y,{value:p,onChange:F=>j(F.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(Y,{inputMode:"numeric",value:K,onChange:F=>q(F.target.value),placeholder:String(nh/1e3)})]}),e.jsxs(he,{children:[e.jsx(pe,{children:n("Tool call timeout (seconds)")}),e.jsx(Y,{inputMode:"numeric",value:N,onChange:F=>L(F.target.value),placeholder:String(ah/1e3)})]})]}),G&&e.jsx("p",{className:"t-shake-in text-destructive text-xs",children:G},G)]}),e.jsxs(Ie,{children:[e.jsx(y,{variant:"outline",size:"sm",onClick:t,children:n("Cancel")}),e.jsx(y,{size:"sm",disabled:!Re,onClick:Oe,children:n("Save")})]})]})})}function dh({status:s}){const{t}=D();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 uh(){const{t:s}=D(),t=g(S=>S.mcpServers),n=g(S=>S.updateMcpServer),a=g(S=>S.setMcpServersEnabled),r=g(S=>S.removeMcpServer),o=gs(S=>S.statuses),i=gs(S=>S.authorized),m=gs(S=>S.pending),d=gs(S=>S.authorize),h=gs(S=>S.revoke);l.useEffect(()=>gs.getState().bind(),[]);const[x,c]=l.useState(!1),[f,u]=l.useState(null),p=async S=>{await d(S),u(gs.getState().authorized[S]===!0?S:null)},[j,v]=l.useState(null),[I,b]=l.useState(""),k=t.filter(S=>io(I,[S.name,S.source,S.transport,S.url,S.command,...S.args??[]])),C=k.map(S=>S.id),R=lo(C),B=t.filter(S=>S.enabled).length,P=t.filter(S=>S.enabled).map(S=>S.id),z=It(P,S=>window.electronAPI.assets.mcpOccupancy(S)),M=t.filter(S=>S.enabled&&S.loadMode!=="deferred").map(S=>S.id),A=kt(M,z.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:B,total:t.length}),e.jsx(St,{tokens:A})]})]}),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:()=>v("new"),children:[e.jsx(Me,{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(co,{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(uo,{query:I,onQueryChange:b,placeholder:s("Filter MCP servers..."),allSelected:R.allSelected,someSelected:R.someSelected,onToggleSelectAll:R.toggleAll,onEnable:()=>a(R.selectedIds,!0),onDisable:()=>a(R.selectedIds,!1),selectDisabled:k.length===0,actionDisabled:R.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 K=o[S.id]??o[S.name],q=m[S.id]===!0,N=S.transport!=="stdio"&&i[S.id]!==!0,L=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:R.isSelected(S.id),onCheckedChange:V=>R.toggleOne(S.id,V)}),e.jsx("span",{className:H("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}),K&&e.jsx(dh,{status:K}),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||K?.state==="unauthorized")&&e.jsxs(y,{variant:"outline",size:"sm",className:"h-7",disabled:q,onClick:()=>{p(S.id)},children:[q?e.jsx(Ae,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):e.jsx(vc,{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:()=>{h(S.id)},children:e.jsx(bc,{className:"h-3.5 w-3.5"})}),e.jsx(Ct,{row:z.rows[S.id],pending:S.enabled&&z.pending&&!z.rows[S.id]}),e.jsx(Qs,{value:L?"deferred":"direct",onValueChange:V=>n(S.id,{loadMode:V==="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(le,{checked:S.enabled,onCheckedChange:V=>n(S.id,{enabled:V})}),e.jsx(y,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",onClick:()=>v(S),children:e.jsx(ms,{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(Ee,{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:x,onOpenChange:c}),e.jsx(ch,{server:j,onClose:()=>v(null)})]})}const Xa={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 Ho(s){if(Xa[s]!==void 0)return Xa[s];let t=0;for(let n=0;n<s.length;n++)t=t*17+s.charCodeAt(n)>>>0;return t%360}const Ut=22,mh=64;function xh(s,t){if(t<=1)return Ut;const n=Math.sqrt(Math.max(1,s))/Math.sqrt(t);return Math.round(Ut+(mh-Ut)*Math.min(1,n))}function hh(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:xh(o.memoryCount,a),color:qo(Ho(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 ph(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:qo(Ho(a),t)})).sort((a,r)=>r.count-a.count||a.entityType.localeCompare(r.entityType))}function fh(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 qo(s,t){return gh(s,t?.62:.68,t?.58:.52)}function gh(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,d]=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],h=x=>Math.round((x+o)*255).toString(16).padStart(2,"0");return`#${h(i)}${h(m)}${h(d)}`}let Qa=!1;function jh(){Qa||(To.use(pu),Qa=!0)}const Za={name:"fcose",animate:!1,randomize:!1,nodeRepulsion:8e3,idealEdgeLength:90,nodeSeparation:90,padding:24,fit:!0};function vh({graph:s,selectedId:t,onSelect:n,memories:a,loading:r,onInterpret:o,interpreting:i}){const{t:m}=D(),d=l.useRef(null),h=l.useRef(null),x=l.useRef(n);x.current=n;const[c,f]=l.useState(null),u=l.useMemo(()=>typeof document<"u"&&document.documentElement.classList.contains("dark"),[]);l.useEffect(()=>{const v=d.current;if(!v||s.nodes.length===0)return;jh();const I=To({container:v,elements:hh(s.nodes,s.edges,u),style:fh(u),minZoom:.2,maxZoom:2.5,wheelSensitivity:.2});return I.layout(Za).run(),I.on("tap","node",b=>x.current(b.target.id())),I.on("tap",b=>{b.target===I&&x.current(null)}),h.current=I,()=>{I.destroy(),h.current=null}},[s.nodes,s.edges,u]),l.useEffect(()=>{const v=h.current;v&&v.batch(()=>{if(v.elements().removeClass("dimmed").unselect(),!t)return;const I=v.getElementById(t);if(I.empty())return;const b=I.closedNeighborhood();v.elements().difference(b).addClass("dimmed"),I.select()})},[t]);const p=l.useMemo(()=>ph(s.nodes,u),[s.nodes,u]),j=s.nodes.find(v=>v.id===t)??null;return l.useEffect(()=>{const v=h.current;!v||t||v.batch(()=>{v.elements().removeClass("dimmed"),c&&v.nodes().filter(I=>I.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:d,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:()=>h.current?.fit(void 0,24),title:m("Fit to view"),children:m("Fit")}),e.jsx(y,{size:"sm",variant:"outline",onClick:()=>h.current?.layout(Za).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(v=>e.jsxs("button",{type:"button",onClick:()=>f(c===v.entityType?null:v.entityType),className:H("inline-flex items-center gap-1.5 rounded-full border px-2 py-0.5 text-xs transition-colors",c===v.entityType?"border-foreground/40 bg-accent":"hover:bg-accent/50"),children:[e.jsx("span",{className:"size-2.5 shrink-0 rounded-full",style:{backgroundColor:v.color}}),e.jsx("span",{className:"text-muted-foreground",children:v.entityType.toLowerCase()}),e.jsx("span",{className:"tabular-nums",children:v.count})]},v.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(v=>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:[v.isCrystal&&e.jsx("span",{title:m("Crystal"),children:"★"}),e.jsx("span",{className:"truncate",children:v.title}),e.jsx(se,{variant:"secondary",children:v.unitType})]}),e.jsx("p",{className:"line-clamp-2 text-muted-foreground text-xs",children:v.contentSummary})]},v.id))]})]})]})}function bh({tree:s,loading:t,selected:n,onToggle:a,onInterpretGroup:r,interpreting:o}){const{t:i}=D(),[m,d]=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(h=>{const x=m.has(h.id),c=(h.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(h.id)||f.add(h.id),d(f)},children:e.jsxs("p",{className:"flex items-center gap-2 text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:x?"▾":"▸"}),e.jsx("span",{className:"truncate",children:h.label}),e.jsx(se,{variant:"secondary",children:h.count})]})}),e.jsx(y,{size:"sm",variant:"ghost",className:"shrink-0",disabled:o||c.length===0,onClick:()=>r(h),children:i("Interpret")})]}),x&&e.jsxs("ul",{className:"divide-y border-t bg-muted/20",children:[(h.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)),h.count>(h.children?.length??0)&&e.jsx("li",{className:"px-3 py-2 text-muted-foreground text-xs",children:i("Showing {{shown}} of {{total}}",{shown:String(h.children?.length??0),total:String(h.count)})})]})]},h.id)})})}const yh=120,wh=30,Nh={nodes:[],edges:[],totalEntities:0};function kh({revision:s=0}={}){const{t}=D(),[n,a]=l.useState("graph"),[r,o]=l.useState("unitType"),[i,m]=l.useState(Nh),[d,h]=l.useState([]),[x,c]=l.useState(!0),[f,u]=l.useState(null),[p,j]=l.useState([]),[v,I]=l.useState(new Set),[b,k]=l.useState(null),[C,R]=l.useState(!1),[B,P]=l.useState(null),[z,M]=l.useState(!1),A=l.useCallback(()=>{c(!0);const O=()=>c(!1);n==="graph"?window.electronAPI.memory.graph({limit:yh,minMemories:1}).then(m).finally(O):window.electronAPI.memory.tree({groupBy:r,limitPerGroup:wh}).then(h).finally(O)},[n,r]);l.useEffect(A,[A]);const S=l.useRef(A);S.current=A,l.useEffect(()=>window.electronAPI.memory.onChanged(()=>S.current()),[]);const K=l.useRef(s);l.useEffect(()=>{K.current!==s&&(K.current=s,A())},[s,A]),l.useEffect(()=>{if(!f){j([]);return}window.electronAPI.memory.graphEntity(f).then(j)},[f]);const q=async O=>{R(!0),k(null);try{k(await window.electronAPI.memory.insight(O))}finally{R(!1)}},N=async()=>{M(!0);try{const O=await window.electronAPI.memory.crystallize({memoryIds:[...v]});P(O),O.ok&&I(new Set)}finally{M(!1)}},L=[{value:"graph",label:t("Graph")},{value:"tree",label:t("Tree")}],V=[{value:"unitType",label:t("By type")},{value:"entity",label:t("By entity")},{value:"time",label:t("By month")}],$=v.size>=ga;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:L,onValueChange:O=>a(O==="tree"?"tree":"graph"),children:[e.jsx(ae,{size:"sm",className:"w-32",children:e.jsx(re,{})}),e.jsx(oe,{children:L.map(O=>e.jsx(X,{value:O.value,children:O.label},O.value))})]}),n==="tree"&&e.jsxs(ne,{value:r,items:V,onValueChange:O=>o(O),children:[e.jsx(ae,{size:"sm",className:"w-36",children:e.jsx(re,{})}),e.jsx(oe,{children:V.map(O=>e.jsx(X,{value:O.value,children:O.label},O.value))})]}),e.jsx("span",{className:"flex-1"}),n==="tree"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:H("text-xs",$?"text-foreground":"text-muted-foreground"),children:t("{{count}} selected",{count:String(v.size)})}),e.jsx(y,{size:"sm",variant:"outline",disabled:!$||z,onClick:()=>{N()},children:z?t("Synthesizing…"):t("Crystallize ({{min}}+)",{min:String(ga)})})]})]}),n==="graph"?e.jsx(vh,{graph:i,loading:x,selectedId:f,onSelect:u,memories:p,interpreting:C,onInterpret:O=>{q({entityId:O})}}):e.jsx(bh,{tree:d,loading:x,selected:v,interpreting:C,onToggle:O=>{const te=new Set(v);te.delete(O)||te.add(O),I(te)},onInterpretGroup:O=>{const te=(O.children??[]).map(G=>G.memoryId).filter(G=>!!G);q({memoryIds:te})}}),e.jsx(je,{open:b!==null,onOpenChange:O=>!O&&k(null),children:e.jsxs(ve,{children:[e.jsxs(be,{children:[e.jsx(ye,{children:t("Interpretation")}),b?.ok&&e.jsx(Ye,{children:t("Based on {{count}} memories",{count:String(b.sourceCount??0)})})]}),e.jsx(we,{children:b?.ok?e.jsx("p",{className:"whitespace-pre-wrap text-sm",children:b.text}):e.jsx("p",{className:"text-destructive text-sm",children:b?.error})}),e.jsx(Ie,{children:e.jsx(Hs,{render:e.jsx(y,{variant:"outline",size:"sm"}),children:t("Close")})})]})}),e.jsx(je,{open:B!==null,onOpenChange:O=>!O&&P(null),children:e.jsxs(ve,{children:[e.jsxs(be,{children:[e.jsx(ye,{children:B?.ok?t("Crystal created"):t("Nothing was written")}),B?.ok&&e.jsx(Ye,{children:B.title})]}),e.jsx(we,{className:"space-y-3",children:B?.ok?e.jsx("p",{className:"whitespace-pre-wrap text-sm",children:B.content}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-destructive text-sm",children:B?.error}),B?.candidates&&B.candidates.length>0&&e.jsx("ul",{className:"divide-y rounded-lg border",children:B.candidates.map(O=>e.jsxs("li",{className:"flex items-center justify-between gap-2 px-3 py-2",children:[e.jsx("span",{className:"truncate text-sm",children:O.title}),e.jsxs(se,{variant:"secondary",children:[(O.similarity*100).toFixed(0),"%"]})]},O.id))})]})}),e.jsx(Ie,{children:e.jsx(Hs,{render:e.jsx(y,{variant:"outline",size:"sm"}),children:t("Close")})})]})})]})}function hn(s){return s==="fast"||s==="deep"}const As=25,Fe="__all__";function Ls(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 er=["global","project","secretary","bot","chat"],Ch={global:"Global",project:"Projects",secretary:"Secretary",bot:"Members",chat:"Group chats"};function Sh(s,t,n){return t?{spaceId:t}:s?{spaceIds:n.filter(a=>a.kind===s).map(a=>a.id)}:{}}function Ih(s){return s.startsWith("bot:")?"bot":s.startsWith("chat:")?"chat":s.startsWith("proj:")?"project":"global"}function Ah(s,t){return s===!1&&!t}function Eh(s,t,n,a){return hn(s)&&!t.trim()?"needs-query":Ah(n,a)?"library-empty":"no-match"}function Ph({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(d=>e.jsxs("li",{className:H(Sc,"flex items-center gap-2 px-3 py-2"),"data-memory-id":d.id,children:[i&&e.jsx(Le,{checked:o?.has(d.id)??!1,onCheckedChange:()=>i(d.id),"aria-label":r("Select memory")}),e.jsxs("button",{type:"button",onClick:()=>t(d.id),className:"min-w-0 flex-1 space-y-0.5 text-left",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[d.isCrystal&&e.jsx("span",{title:r("Crystal"),children:"★"}),e.jsx("span",{className:"truncate text-sm",children:d.title}),e.jsx(se,{variant:"secondary",children:d.unitType}),e.jsx(Th,{importance:d.importance,t:r}),d.lifecycleState==="archived"&&e.jsx(se,{variant:"outline",children:r("Archived")}),d.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:d.contentSummary}),e.jsxs("span",{className:"block text-muted-foreground text-xs",children:[r("Recorded {{date}}",{date:Ls(d.createdAt)})," · ",d.spaceLabel," ","· ",r("Retrieved {{count}} times",{count:String(d.appearances)})]})]}),n&&a&&e.jsx(Cc,{id:d.id,onEdit:n,onDelete:a})]},d.id))]})}const Mh={critical:{variant:"warning",label:"critical"},important:{variant:"info",label:"important"},useful:{variant:"outline",label:"useful"},low:{variant:"outline",label:"low"}};function Th({importance:s,t}){const n=Ec(s),a=Mh[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 Rh=6,Oh=50;function Dh(s){const t=[...s].sort((a,r)=>r.edge.createdAt.localeCompare(a.edge.createdAt)||a.edge.id.localeCompare(r.edge.id));if(t.length<=Rh)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 sr({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 Lh({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(d=>t.has(d.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>Oh&&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")})]})]}),Dh(s).map(d=>e.jsxs("div",{className:"space-y-2",children:[d.label&&e.jsxs("h4",{className:"text-muted-foreground text-xs",children:[d.label," · ",i("{{count}} pending",{count:String(d.items.length)})]}),d.items.map(({edge:h,older:x,newer:c})=>e.jsxs("div",{className:"space-y-1.5 rounded-lg border px-3 py-2","data-memory-review":h.id,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(Le,{checked:t.has(h.id),onCheckedChange:()=>n(h.id),"aria-label":i("Select memory")}),e.jsx(se,{variant:"outline",children:h.relation}),e.jsxs("span",{className:"text-muted-foreground text-xs",children:[x.spaceLabel," · ",Ls(h.createdAt)]})]}),e.jsx(sr,{label:i("Earlier memory"),memory:x,onOpen:o}),e.jsx(sr,{label:i("Newer memory"),memory:c,onOpen:o}),e.jsx("p",{className:"text-muted-foreground text-xs",children:h.reason?`${i("Why they conflict")}: ${h.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([h.id],"accepted"),children:i("Accept")}),e.jsx(y,{size:"sm",variant:"ghost",onClick:()=>r([h.id],"rejected"),children:i("Dismiss")})]})]},h.id))]},d.key))]})}function zh({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 _h({t:s}){const t=Ic(),n=Ac(a=>a.review);return e.jsx(zh,{writes:t,t:s,onReview:(a,r)=>{n(a,r)}})}function Fh({revision:s=0}={}){const{t}=D(),[n,a]=l.useState(""),[r,o]=l.useState(Fe),[i,m]=l.useState(Fe),[d,h]=l.useState(Fe),[x,c]=l.useState(!1),[f,u]=l.useState(!1),[p,j]=l.useState(0),[v,I]=l.useState("exact"),[b,k]=l.useState(!1),[C,R]=l.useState(!0),[B,P]=l.useState([]),[z,M]=l.useState(0),[A,S]=l.useState([]),K=l.useRef(A);K.current=A;const[q,N]=l.useState(null),[L,V]=l.useState(null),[$,O]=l.useState(null),[te,G]=l.useState(null),[J,W]=l.useState(new Set),[ce,_]=l.useState(!1),[de,T]=l.useState([]),[E,Q]=l.useState(new Set),ie=l.useRef(!1),Re=l.useRef(0),Oe=l.useRef(0);l.useEffect(()=>(ie.current=!0,()=>{ie.current=!1,Re.current++,Oe.current++}),[]);const F=l.useCallback(()=>{if(!ie.current)return;const U=++Re.current,ue=()=>ie.current&&U===Re.current;if(hn(v)&&!n.trim()){P([]),M(0),k(!0),R(!0);return}const Be=er.find(Ce=>Ce===r)??null;window.electronAPI.memory.list({query:n.trim()||void 0,...Sh(Be,i===Fe?null:i,K.current),unitType:d===Fe?void 0:d,includeArchived:x,archiveCandidate:f||void 0,limit:As,offset:p,mode:v}).then(Ce=>{ue()&&(P(Ce.items),M(Ce.total),k(Ce.approximate===!0),R(Ce.vectorsUsed!==!1))}),window.electronAPI.memory.stats().then(Ce=>{ie.current&&(S(Object.keys(Ce.bySpace).map(ls=>({id:ls,label:Ce.spaceLabels[ls]??ls,kind:Ce.spaceKinds?.[ls]??Ih(ls)}))),N(Ce.total>0))}),window.electronAPI.memory.evolvesPending().then(Ce=>{ie.current&&T(Ce)})},[n,r,i,d,x,f,p,v]);l.useEffect(()=>(F(),()=>{Re.current++}),[F]);const ee=l.useRef(F);ee.current=F,l.useEffect(()=>window.electronAPI.memory.onChanged(()=>ee.current()),[]);const Z=l.useRef(s);l.useEffect(()=>{Z.current!==s&&(Z.current=s,F())},[s,F]);const me=U=>{const ue=++Oe.current;window.electronAPI.memory.detail(U).then(Be=>{ie.current&&ue===Oe.current&&V(Be)})},ke=()=>{Oe.current++,V(null)},xs=async(U,ue)=>{_(!0);try{for(const Be of U)await ue(Be)}finally{ie.current&&(_(!1),W(new Set),ee.current())}},bs=()=>{xs(J,U=>window.electronAPI.memory.archive(U))},qe=(U,ue)=>{U.length!==0&&(_(!0),(async()=>{try{for(const Be of U)await window.electronAPI.memory.evolvesReview(Be,ue)}finally{ie.current&&(_(!1),Q(new Set),ee.current())}})())},ys=U=>{ie.current&&(W(new Set),L&&U.includes(L.id)&&ke(),ee.current())},hs=U=>{ie.current&&($?.reopen&&me(U),ee.current())},fe=U=>{U.then(()=>{ie.current&&(ke(),ee.current())})},De=n.trim()!==""||r!==Fe||i!==Fe||d!==Fe||x===!0,_s=[{value:Fe,label:t("All space types")},...er.filter(U=>A.some(ue=>ue.kind===U)).map(U=>({value:U,label:t(Ch[U])}))],as=[{value:Fe,label:t("All spaces")},...A.filter(U=>r===Fe||U.kind===r).map(U=>({value:U.id,label:U.label}))],Fs=[{value:Fe,label:t("All types")},...yc.map(U=>({value:U,label:U}))],ps=[{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(mo,{className:"w-full sm:w-96","data-size":"sm",children:[e.jsx(xo,{value:n,placeholder:t("Search memories"),onChange:U=>{j(0),a(U.target.value)}}),e.jsx(ho,{align:"inline-end",className:"pe-1",children:e.jsxs(ne,{value:v,items:ps,onValueChange:U=>{j(0),I(U==="deep"?"deep":U==="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:ps.map(U=>e.jsx(X,{value:U.value,children:U.label},U.value))})]})})]}),e.jsxs(ne,{value:r,items:_s,onValueChange:U=>{j(0),o(String(U)),m(Fe)},children:[e.jsx(ae,{size:"sm",className:"w-36","data-memory-filter":"space-kind",children:e.jsx(re,{})}),e.jsx(oe,{children:_s.map(U=>e.jsx(X,{value:U.value,children:U.label},U.value))})]}),e.jsxs(ne,{value:i,items:as,onValueChange:U=>{j(0),m(String(U))},children:[e.jsx(ae,{size:"sm",className:"w-36","data-memory-filter":"space",children:e.jsx(re,{})}),e.jsx(oe,{children:as.map(U=>e.jsx(X,{value:U.value,children:U.label},U.value))})]}),e.jsxs(ne,{value:d,items:Fs,onValueChange:U=>{j(0),h(String(U))},children:[e.jsx(ae,{size:"sm",className:"w-36",children:e.jsx(re,{})}),e.jsx(oe,{children:Fs.map(U=>e.jsx(X,{value:U.value,children:U.label},U.value))})]}),v==="exact"&&e.jsxs("label",{className:"flex items-center gap-2 text-muted-foreground text-sm",children:[e.jsx(le,{checked:x,onCheckedChange:U=>{j(0),c(U===!0)}}),t("Show archived")]}),v==="exact"&&e.jsxs("label",{className:"flex items-center gap-2 text-muted-foreground text-sm",children:[e.jsx(le,{checked:f,onCheckedChange:U=>{j(0),u(U===!0)}}),t("Archive candidates only")]})]}),hn(v)&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:[t(v==="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."),!C&&` ${t("Embedding model is not ready, so vectors are skipped.")}`]}),J.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(J.size)})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(y,{variant:"ghost",size:"sm",disabled:ce,onClick:()=>W(new Set),children:t("Clear selection")}),e.jsx(y,{variant:"outline",size:"sm",disabled:ce,onClick:()=>bs(),children:t("Archive selected")}),e.jsx(y,{variant:"destructive-outline",size:"sm",disabled:ce,onClick:()=>G([...J]),children:t("Delete permanently")})]})]}),e.jsx(Ph,{items:B,onOpen:me,onEdit:U=>O({id:U,reopen:!1}),onDelete:U=>G([U]),t,selected:J,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.")}[Eh(v,n,q,De)],onToggle:U=>{const ue=new Set(J);ue.delete(U)||ue.add(U),W(ue)}}),!b&&z>As&&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-As)),children:t("Previous")}),e.jsxs("span",{children:[p+1,"–",Math.min(p+As,z)," / ",z]}),e.jsx(y,{variant:"outline",size:"sm",disabled:p+As>=z,onClick:()=>j(p+As),children:t("Next")})]}),e.jsx(_h,{t}),e.jsx(Lh,{items:de,selected:E,onToggle:U=>{const ue=new Set(E);ue.delete(U)||ue.add(U),Q(ue)},onToggleAll:U=>Q(U?new Set(de.map(ue=>ue.edge.id)):new Set),onOpen:me,onReview:qe,t}),e.jsx(je,{open:L!==null,onOpenChange:U=>!U&&ke(),children:e.jsx(ve,{finalFocus:wc,children:L&&e.jsxs(e.Fragment,{children:[e.jsxs(be,{children:[e.jsx(ye,{children:L.title}),e.jsx(Ye,{children:[L.unitType,L.spaceLabel].join(" · ")})]}),e.jsxs(we,{className:"space-y-4","data-memory-detail":L.id,children:[e.jsx("p",{className:"whitespace-pre-wrap text-sm","data-memory-field":"content",children:L.content}),e.jsxs("dl",{className:"grid grid-cols-2 gap-x-4 gap-y-3",children:[e.jsx(Us,{label:t("Importance"),value:L.importance.toFixed(2)}),e.jsx(Us,{label:t("Recorded at"),value:Ls(L.createdAt)}),L.updatedAt!==L.createdAt&&e.jsx(Us,{label:t("Updated at"),value:Ls(L.updatedAt)}),e.jsx(Us,{label:t("Embedding"),value:L.embeddingModel??t("Not vectorized")}),L.eventStart&&e.jsx(Us,{label:t("Event date"),value:`${L.eventStart}${L.eventEnd?` → ${L.eventEnd}`:""}`})]}),L.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:L.entityNames.map(U=>e.jsx(se,{variant:"secondary",children:U},U))})]}),L.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:L.crystalSources.map(U=>e.jsxs("li",{className:"flex items-center justify-between gap-2 px-3 py-2",children:[e.jsx("span",{className:"truncate text-sm",children:U.title}),e.jsxs("span",{className:"shrink-0 text-muted-foreground text-xs",children:[(U.contributionWeight*100).toFixed(0),"%"]})]},U.id))})]}),L.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:L.evolves.map(U=>e.jsxs("li",{className:"flex items-center gap-2 px-3 py-2",children:[e.jsx(se,{variant:"outline",children:U.relation}),e.jsx("span",{className:"text-muted-foreground text-xs",children:U.reviewState})]},U.id))})]})]}),e.jsxs(Ie,{children:[e.jsx(y,{variant:"destructive-outline",size:"sm",className:"sm:me-auto","data-memory-action":"delete",onClick:()=>G([L.id]),children:t("Delete permanently")}),e.jsx(y,{variant:"outline",size:"sm","data-memory-action":"edit",onClick:()=>{ke(),O({id:L.id,reopen:!0})},children:t("Edit")}),L.lifecycleState==="archived"?e.jsx(y,{variant:"outline",size:"sm",onClick:()=>fe(window.electronAPI.memory.restore(L.id)),children:t("Restore")}):e.jsx(y,{variant:"outline",size:"sm",onClick:()=>fe(window.electronAPI.memory.archive(L.id)),children:t("Archive")})]})]})})}),e.jsx(Nc,{memoryId:$?.id??null,onClose:()=>O(null),onSaved:hs}),e.jsx(kc,{ids:te,onClose:()=>G(null),onDeleted:ys})]})}function Us({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 Yo="openai-compatible",Bh=/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 Jo(s){return Bh.test(s)}function Xo(s){return Array.isArray(s.models)?s.models.filter(t=>typeof t?.id=="string"&&Jo(t.id)):[]}function $h(s){return s.flatMap(t=>{if(!t.apiKey||typeof t.baseUrl!="string"||!t.baseUrl.trim())return[];const n=Xo(t);return n.length>0?[{...t,models:n}]:[]})}function Uh(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===Yo?"no-model":Jo(a)?null:Xo(n).length>0?"not-embedding-model":"no-embedding-models":"no-api-key":"provider-missing":"no-provider"}const Vh={"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.'},Gh="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 Kh(s,t,n){return n(Vh[s],{provider:t.provider??"",model:t.model??""})}const tr=s=>s.slice(0,8);function Vt(s,t){return s==="pending"||s==="running"?"running":s==="cancelled"?"cancelled":t?"failed":"done"}const Wh={low_importance:"importance too low",candidates_found:"similar memory already exists",deduplicated:"identical to an existing memory",rejected:"rejected"};function Hh(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||tr(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,Wh[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||tr(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:${Yo}`,bt="remote:";function nr(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 qh(s){return At(s)?qs:s}function Yh(s){return!At(s)||s===qs?null:s.slice(bt.length)}function Jh(s){return`${bt}${s}`}function Xh(s,t){return t===qs?At(s)?s:qs:t}const Qh=4e3,Zh=800,ar=6,ep={distill:"job:distill",kg:"job:entities",reembed:"job:vectors"},rr={distill:[],kg:[],reembed:null,kgFailed:0};function sp(s){return s.some(t=>t.distilled)}function or(s){return!s||s.total===0||s.embedded>=s.total?null:s.embeddingError??null}function ir(s){return s?.downloadable&&(s.state==="missing"||s.state==="downloading")?s.state:null}function tp(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 np(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 ap(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 xe(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 Es({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(le,{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(X,{value:m.value,children:m.label},m.value))})]})]})}function rp({onLibraryChanged:s}={}){const{t}=D(),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),d=g(w=>w.setMemoryModelIdleMinutes),h=g(w=>w.memoryEmbeddingRemoteProviderId),x=g(w=>w.setMemoryEmbeddingRemoteProviderId),c=g(w=>w.providers),f=g(w=>w.memoryDistillEnabled),u=g(w=>w.setMemoryDistillEnabled),p=g(w=>w.memoryKgEnabled),j=g(w=>w.setMemoryKgEnabled),v=g(w=>w.memoryDecayEnabled),I=g(w=>w.setMemoryDecayEnabled),b=g(w=>w.memoryDecayArchiveCandidates),k=g(w=>w.setMemoryDecayArchiveCandidates),C=g(w=>w.memoryDecayAutoArchive),R=g(w=>w.setMemoryDecayAutoArchive),B=g(w=>w.memoryDecayStaleDays),P=g(w=>w.setMemoryDecayStaleDays),z=g(w=>w.memoryDecayMaxImportance),M=g(w=>w.setMemoryDecayMaxImportance),A=g(w=>w.memoryDecayIntervalDays),S=g(w=>w.setMemoryDecayIntervalDays),K=g(w=>w.memoryDistillModel),q=g(w=>w.setMemoryDistillModel),N=g(w=>w.memoryChatModel)||"remote",L=g(w=>w.setMemoryChatModel),V=g(w=>w.memoryLanguage),$=g(w=>w.setMemoryLanguage),O=es(),te=K?O.find(w=>w.id===K.providerId):void 0,G=te?.models.find(w=>w.id===K?.modelId),J=Yh(a),W=l.useMemo(()=>$h(O),[O]),ce=h?W.find(w=>w.id===h):void 0,_=ce?.models.find(w=>w.id===J),de=h?c.find(w=>w.id===h):void 0,T=Uh({providerId:h,provider:de,modelId:J}),E=T&&T!=="no-provider"&&T!=="no-model"?Kh(T,{provider:de?.name||h||"",model:J??""},t):null,Q=!n.includes("memory"),[ie,Re]=l.useState(null),[Oe,F]=l.useState(rr),[ee,Z]=l.useState([]),[me,ke]=l.useState(null),[xs,bs]=l.useState([]),[qe,ys]=l.useState(null),[hs,fe]=l.useState([]),[De,_s]=l.useState(null),[as,Fs]=l.useState(null),[ps,U]=l.useState(null),[ue,Be]=l.useState(null),[Ce,ls]=l.useState(!1),[Et,xi]=l.useState(!1),[$e,Un]=l.useState(null),[ws,Pt]=l.useState(new Set),[st,tt]=l.useState(null),Mt=ie?.forgetting??null,Bs=Mt?.lastRun??null,hi=Bs?t("Last run {{date}}: {{scored}} scored, {{candidates}} candidates, {{archived}} archived",{date:Ls(Bs.ranAt),scored:String(Bs.scored),candidates:String(Bs.candidates),archived:String(Bs.archived)}):t("Never run yet"),Vn=l.useRef(!1);Vn.current=Ce;const Ns=l.useRef(null),Tt=l.useCallback(()=>{window.electronAPI.memory.distillableSessions().then(fe)},[]);l.useEffect(()=>{Q&&Tt()},[Q,Tt]);const ks=l.useCallback(()=>{window.electronAPI.memory.models().then(Z)},[]);l.useEffect(()=>(ks(),window.electronAPI.memory.onModelProgress(w=>{ke(w.done?null:w),w.done&&ks()})),[ks]);const Cs=l.useCallback(()=>{window.electronAPI.memory.chatModels().then(w=>bs(w.filter(ge=>!ge.purpose)))},[]);l.useEffect(()=>(Cs(),window.electronAPI.memory.onChatModelProgress(w=>{ys(w.done?null:w),w.done&&Cs()})),[Cs]),l.useEffect(()=>{if(!Q){Re(null),F(rr);return}let w=!1;const ge=()=>{window.electronAPI.memory.stats().then(rs=>{w||Re(rs)}),window.electronAPI.memory.jobs().then(rs=>{w||(F(rs),Vn.current&&rs.reembed?.status!=="running"&&ls(!1))})};Ns.current=ge,ge();const Ue=window.electronAPI.memory.onChanged(ge),$s=window.setInterval(ge,Ce?Zh:Qh);return()=>{w=!0,Ns.current=null,Ue(),window.clearInterval($s)}},[Q,Ce]);const Gn=ap(hs),Kn=hs.filter(w=>!w.distilled),pi=()=>{tt("run"),window.electronAPI.memory.runForgetting().then(()=>{tt(null),Ns.current?.()})},Wn=()=>{window.electronAPI.memory.archiveCandidates({limit:200,offset:0}).then(w=>{Un(w),Pt(new Set)})},fi=()=>{const w=[...ws];w.length!==0&&(tt("archive"),window.electronAPI.memory.confirmArchiveCandidates(w).then(()=>{tt(null),Wn(),Ns.current?.(),s?.()}))},Hn=(w,ge,Ue)=>{const $s=w.filter(rs=>!rs.distilled);if(!sp(w)){nt(w,ge);return}Be({token:ge,label:Ue,scope:w,pending:$s})},nt=async(w,ge,Ue=!1)=>{const $s=xs.find(Is=>Is.id===N)??null;if(ir($s))return;_s(ge);const rs=Date.now();U({done:0,total:w.length,startedAt:rs});try{for(let Is=0;Is<w.length;Is++)await window.electronAPI.memory.distillSession(w[Is].sessionId,Ue),U({done:Is+1,total:w.length,startedAt:rs})}finally{_s(null),U(null),Tt(),s?.()}},Ne=ee.find(w=>w.id===a)??null,_e=xs.find(w=>w.id===N)??null,fs=ir(_e),qn=xs.map(w=>({value:w.id,label:w.id==="remote"?t("Remote (API model)"):w.label})),Yn=[...ee.map(w=>({value:w.id,label:nr(w)})),{value:qs,label:t("Remote (OpenAI-compatible)")}],Jn=Pc.map(w=>({value:String(w),label:w===0?t("Never"):t("{{count}} min",{count:w})})),Xn=[{value:"en",label:t("English")},{value:"zh",label:t("Simplified Chinese")},{value:"auto",label:t("Follow conversation")}],at=At(a)||Ne?.runtime==="openai-compatible",Ss=l.useMemo(()=>Hh(Oe),[Oe]);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:Jn,onValueChange:w=>{w!==null&&d(Number(w))},disabled:!Q,children:[e.jsx(ae,{className:"w-56 shrink-0","aria-label":t("Unload automatically when idle"),children:e.jsx(re,{})}),e.jsx(oe,{children:Jn.map(w=>e.jsx(X,{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:Ne?nr(Ne):J??(at?t("Remote (OpenAI-compatible)"):a)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:Ne?[Ne.dim?`${Ne.dim}d`:null,Ne.downloadable?xe(Ne.approxBytes):null,Ne.runtime].filter(Boolean).join(" · "):at?"openai-compatible":t("Unknown model; the default is used instead.")})]}),e.jsxs(ne,{value:qh(a),items:Yn,onValueChange:w=>{w!==null&&r(Xh(a,String(w)))},disabled:!Q,children:[e.jsx(ae,{className:"w-56",children:e.jsx(re,{})}),e.jsx(oe,{children:Yn.map(w=>e.jsx(X,{value:w.value,children:w.label},w.value))})]})]}),Ne?.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:Ne.state==="ready"?t("Model downloaded"):Ne.state==="downloading"?t("Downloading…"):t("Model not downloaded")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:me&&me.modelId===Ne.id?`${me.file} · ${xe(me.received)}${me.total?` / ${xe(me.total)}`:""} (${me.fileIndex+1}/${me.fileCount})`:Ne.state==="ready"?xe(Ne.downloadedBytes):t("Semantic search stays off until the model is on disk.")})]}),e.jsx("div",{className:"flex shrink-0 gap-2",children:Ne.state==="downloading"?e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.memory.cancelModelDownload(Ne.id).then(ks)},children:t("Cancel")}):Ne.state==="ready"?e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.memory.deleteModel(Ne.id).then(ks)},children:t("Remove")}):e.jsx(y,{size:"sm",disabled:!Q,onClick:()=>{window.electronAPI.memory.downloadModel(Ne.id).then(ks)},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.")})]}),W.length>0?e.jsx("div",{className:"w-56 shrink-0",children:e.jsx(ze,{providers:W,providerId:ce?.id??h??"",modelId:_?.id??J??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:t("Select model"),side:"bottom",triggerClassName:Qe,onSelect:(w,ge)=>{x(w),r(Jh(ge))},onReasoningChange:()=>{},onThinkingChange:()=>{}})}):e.jsx("p",{className:"w-56 shrink-0 text-xs text-destructive",children:t(Gh)})]}),at&&E&&e.jsx("p",{className:"text-xs text-destructive","data-settings-row":"memory.remoteModelIssue",children:E}),e.jsx(Es,{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:!Q})]}),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:qn,onValueChange:w=>L(String(w)),disabled:!Q,children:[e.jsx(ae,{className:"w-56",children:e.jsx(re,{})}),e.jsx(oe,{children:qn.map(w=>e.jsx(X,{value:w.value,children:w.label},w.value))})]})]}),_e?.downloadable&&e.jsxs("div",{className:H("flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5",fs==="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:qe&&qe.modelId===_e.id?`${qe.file} · ${xe(qe.received)}${qe.total?` / ${xe(qe.total)}`:""}`:_e.state==="ready"?xe(_e.downloadedBytes):xe(_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(Cs)},children:t("Cancel")}):_e.state==="ready"?e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.memory.deleteChatModel(_e.id).then(Cs)},children:t("Remove")}):e.jsx(y,{size:"sm",disabled:!Q,onClick:()=>{window.electronAPI.memory.downloadChatModel(_e.id).then(Cs)},children:t("Download")})})]}),fs==="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.")}),fs==="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.")})]}),O.length>0&&e.jsx("div",{className:"w-56 shrink-0",children:e.jsx(ze,{providers:O,providerId:te?.id??"",modelId:G?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:t("Follows the title-summary model"),side:"bottom",triggerClassName:Qe,onSelect:(w,ge)=>q({providerId:w,modelId:ge}),onReasoningChange:()=>{},onThinkingChange:()=>{}})})]}),K&&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:V,items:Xn,onValueChange:w=>$(String(w)),disabled:!Q,children:[e.jsx(ae,{className:"w-56",children:e.jsx(re,{})}),e.jsx(oe,{children:Xn.map(w=>e.jsx(X,{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(Es,{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:u,disabled:!Q}),f&&fs&&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(Es,{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:!Q})]}),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(Es,{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:v,onChange:I,disabled:!Q}),e.jsx(Es,{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:b,onChange:k,disabled:!Q||!v}),e.jsx(Es,{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:C,onChange:R,disabled:!Q||!v||!b}),v&&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(B),items:Gt(Mc,B,w=>t("{{count}} days",{count:String(w)})),onChange:w=>P(Number(w)),disabled:!Q}),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(z),items:Gt(Tc,z,w=>w.toFixed(2)),onChange:w=>M(Number(w)),disabled:!Q}),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(A),items:Gt(Rc,A,w=>t("{{count}} days",{count:String(w)})),onChange:w=>S(Number(w)),disabled:!Q})]}),v&&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:b||C?t("Archive candidates: {{count}}",{count:String(Mt?.candidates??0)}):t("Archive candidates: marking is off")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:hi})]}),e.jsxs("div",{className:"flex shrink-0 gap-2",children:[e.jsx(y,{size:"sm",variant:"outline",disabled:st!==null||!Q,onClick:pi,children:t(st==="run"?"Running…":"Run now")}),e.jsx(y,{size:"sm",variant:"outline",disabled:!b||(Mt?.candidates??0)===0,onClick:Wn,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")}),ie===null||ie.total===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:t("No memories stored yet.")}):e.jsxs(e.Fragment,{children:[or(ie)&&e.jsx("p",{className:"text-xs text-destructive",children:t("Vectors unavailable: {{reason}}",{reason:or(ie)??""})}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-3",children:[e.jsx(ds,{label:t("Memories"),value:String(ie.total)}),e.jsx(ds,{label:t("Crystals"),value:String(ie.crystals)}),e.jsx(ds,{label:t("Entities"),value:String(ie.entities)}),e.jsx(ds,{label:t("With vectors"),value:`${ie.embedded}/${ie.total}`,action:ie.embedded<ie.total?e.jsx("button",{type:"button",disabled:Ce,className:"text-xs text-muted-foreground underline-offset-2 hover:underline disabled:opacity-60",onClick:()=>{ls(!0),window.electronAPI.memory.reembed().then(()=>Ns.current?.())},children:t(Ce?"Backfilling…":"Backfill")}):null}),e.jsx(ds,{label:t("Database size"),value:xe(ie.databaseBytes)}),e.jsx(ds,{label:t("Spaces"),value:String(Object.keys(ie.bySpace).length)}),e.jsx(ds,{label:t("Never retrieved"),value:`${ie.neverHit}/${ie.total}`,action:e.jsx("span",{className:"text-muted-foreground text-xs",children:t("{{percent}}% of library",{percent:String(ie.total>0?Math.round(ie.neverHit/ie.total*100):0)})})}),e.jsx(ds,{label:t("Added in 7 days"),value:String(ie.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")}),Kn.length>0&&e.jsx(y,{size:"sm",variant:"outline",disabled:!Q||De!==null||fs!==null,onClick:()=>Hn(hs,"all",t("All sessions")),children:De==="all"?t("Distilling…"):t("Distill all ({{count}})",{count:String(Kn.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.")}),ps&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:[t("{{done}}/{{total}} done",{done:String(ps.done),total:String(ps.total)}),(()=>{const w=tp(ps,Date.now());return w===null?"":` · ${t("about {{time}} left",{time:np(w)})}`})()]}),Gn.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:Gn.map(w=>{const ge=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(ge.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:!Q||De!==null||w.sessions.length===0||fs!==null,onClick:()=>Hn(w.sessions,w.key,w.name),children:De===w.key?t("Distilling…"):t("Distill project")})]})]},w.key)})})]}),e.jsx(je,{open:as!==null,onOpenChange:w=>!w&&Fs(null),children:e.jsx(ve,{children:as&&e.jsxs(e.Fragment,{children:[e.jsxs(be,{children:[e.jsx(ye,{children:as.name}),e.jsx(Ye,{children:t("{{total}} sessions · {{pending}} not distilled",{total:String(as.sessions.length),pending:String(as.sessions.filter(w=>!w.distilled).length)})})]}),e.jsx(we,{children:e.jsx("ul",{className:"divide-y rounded-lg border",children:as.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:!Q||De!==null||fs!==null,onClick:()=>{nt([w],w.sessionId,w.distilled)},children:De===w.sessionId?t("Distilling…"):w.distilled?t("Distill again"):t("Distill")})]},w.sessionId))})}),e.jsx(Ie,{children:e.jsx(Hs,{render:e.jsx(y,{variant:"outline",size:"sm"}),children:t("Close")})})]})})}),e.jsx(je,{open:ue!==null,onOpenChange:w=>!w&&Be(null),children:e.jsx(ve,{children:ue&&e.jsxs(e.Fragment,{children:[e.jsxs(be,{children:[e.jsx(ye,{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:ue.label,total:String(ue.scope.length),done:String(ue.scope.length-ue.pending.length)})})]}),e.jsxs(Ie,{children:[e.jsx(Hs,{render:e.jsx(y,{variant:"ghost",size:"sm"}),children:t("Cancel")}),e.jsx(y,{variant:ue.pending.length>0?"default":"outline",size:"sm",disabled:ue.pending.length===0,onClick:()=>{const w=ue;Be(null),nt(w.pending,w.token)},children:t("Only the {{count}} remaining",{count:String(ue.pending.length)})}),e.jsx(y,{variant:ue.pending.length>0?"outline":"default",size:"sm",onClick:()=>{const w=ue;Be(null),nt(w.scope,w.token,!0)},children:t("Re-distill all {{count}}",{count:String(ue.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:[Oe.kgFailed>0&&e.jsx(y,{size:"sm",variant:"ghost",onClick:()=>{window.electronAPI.memory.retryFailedKgJobs().then(()=>Ns.current?.())},children:t("Retry failed extractions ({{count}})",{count:String(Oe.kgFailed)})}),Ss.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")}),Ss.length>ar&&e.jsx(y,{size:"sm",variant:"ghost",onClick:()=>xi(!Et),children:Et?t("Show less"):t("Show all {{count}}",{count:String(Ss.length)})})]})]}),Ss.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?Ss:Ss.slice(0,ar)).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(ep[w.kind])}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-sm",children:w.target}),e.jsx("span",{className:H("shrink-0 text-xs",w.state==="failed"?"text-destructive":"text-muted-foreground"),children:w.state==="running"?`⋯ ${w.detail}`:w.detail})]}),w.notes.map(ge=>e.jsxs("p",{className:"pl-1 text-muted-foreground text-xs",children:["· ",ge]},ge))]},w.key))})]}),e.jsx(je,{open:$e!==null,onOpenChange:w=>!w&&Un(null),children:e.jsxs(ve,{children:[e.jsxs(be,{children:[e.jsx(ye,{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(we,{children:$e&&$e.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(ws.size),total:String($e.items.length)})}),e.jsx(y,{size:"sm",variant:"ghost",onClick:()=>Pt(ws.size===$e.items.length?new Set:new Set($e.items.map(w=>w.id))),children:ws.size===$e.items.length?t("Clear selection"):t("Select all")})]}),e.jsx("ul",{className:"divide-y rounded-lg border",children:$e.items.map(w=>e.jsxs("li",{className:"flex items-start gap-2 px-3 py-2",children:[e.jsx(Le,{checked:ws.has(w.id),onCheckedChange:()=>Pt(ge=>{const Ue=new Set(ge);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:Ls(w.lastHitAt)}):t("Never retrieved")]})]})]},w.id))}),$e.total>$e.items.length&&e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Showing the first {{shown}} of {{total}}.",{shown:String($e.items.length),total:String($e.total)})})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:t("No archive candidates right now.")})}),e.jsxs(Ie,{children:[e.jsx(Hs,{render:e.jsx(y,{variant:"outline",size:"sm"}),children:t("Close")}),e.jsx(y,{size:"sm",disabled:ws.size===0||st!==null,onClick:fi,children:t(st==="archive"?"Archiving…":"Archive selected")})]})]})})]})}function ds({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 op(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"?po(t)?{ok:!0,value:t}:{ok:!1,error:"不是合法的模型选择"}:t.length>4096||t.includes("\0")?{ok:!1,error:"值不合法"}:{ok:!0,value:t}}const ip={"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":"用当前会话的模型运行只读代理(可读项目文件与对话内容,不能修改)"};function Qo(s){return ip[s]??s}const lp=["themes","agent","productivity","integrations","insights","writing","fun"],$n={themes:"主题外观",agent:"Agent 能力",productivity:"效率工作流",integrations:"外部集成",insights:"观测统计",writing:"写作翻译",fun:"休闲娱乐"};function cp(s){return{installedKey:s,refresh:!0}}function dp(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 up({pluginId:s,name:t,from:n,homepage:a,onClose:r}){const{t:o}=D();return e.jsx(je,{open:s!==null,onOpenChange:i=>!i&&r(),children:e.jsxs(ve,{children:[e.jsx(be,{children:e.jsxs(ye,{children:[o("Usage guide"),t?` · ${t}`:""]})}),e.jsx(we,{className:"max-h-[60vh] space-y-3 overflow-y-auto",children:s&&e.jsx(Zo,{pluginId:s,from:n,homepage:a})})]})})}function Zo({pluginId:s,from:t,homepage:n,showLink:a=!0}){const{t:r}=D(),[o,i]=l.useState(null),[m,d]=l.useState(null),[h,x]=l.useState(Gs(n)),[c,f]=l.useState(null);return l.useEffect(()=>{let u=!0;return xt(()=>import("./globals-BTwoz2I6.js").then(p=>p.oi),__vite__mapDeps([0,1]),import.meta.url).then(p=>{u&&f(()=>p.Markdown)}),()=>{u=!1}},[]),l.useEffect(()=>{let u=!1;return i(null),d(null),x(Gs(n)),(async()=>{const p=window.electronAPI.extensionPlugins,j=await p.readme({id:s,from:t});let v=j.ok?j.markdown:null,I=j.ok?null:j.error;if(!j.ok&&t==="installed"){const b=await p.readme({id:s,from:"market"});b.ok&&(v=b.markdown,I=null)}if(!Gs(n)){const b=await p.marketList(!1),k=b.ok?b.plugins.find(C=>C.id===s):void 0;u||x(Gs(k?.homepage))}u||(i(v),d(v?null:I))})(),()=>{u=!0}},[s,t,n]),e.jsxs("div",{className:"space-y-3",children:[a&&h&&e.jsx("a",{href:h,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 ei(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 mp(s){const t=r=>s.filter(o=>ei(o,r)).length,n=["all","installed","updates"],a=[...lp,"other"];return[...n.map(r=>({id:r,count:t(r)})),...a.map(r=>({id:r,count:t(r)})).filter(r=>r.count>0)]}function xp(s,t){const n=t.query.trim().toLowerCase();return s.filter(a=>ei(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 lr={all:"全部",installed:"已安装",updates:"可更新",other:"其他"},hp=s=>s in lr?lr[s]:$n[s];function pp({disabled:s,installedKey:t,onInstall:n}){const{t:a}=D(),r=window.electronAPI.extensionPlugins,[o,i]=l.useState(null),[m,d]=l.useState(!1),[h,x]=l.useState(""),[c,f]=l.useState("all"),[u,p]=l.useState(null),[j,v]=l.useState(()=>cp(t)),I=dp(j,t);I!==j&&v(I);const b=l.useCallback(async M=>{d(!0);try{i(await r.marketList(M))}catch(A){i({ok:!1,error:A instanceof Error?A.message:String(A),chinaMirror:!1})}finally{d(!1)}},[r]);l.useEffect(()=>{b(j.refresh)},[b,j]);const k=async M=>{await r.setMarketChinaMirror(M),await b(!0)},C=o?.ok===!0?o.plugins:[],R=mp(C),B=R.some(M=>M.id===c)?c:"all",P=xp(C,{query:h,section:B}),z=u?C.find(M=>M.id===u):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:R.map(M=>e.jsxs("button",{type:"button","aria-pressed":B===M.id,onClick:()=>{f(M.id),p(null)},className:H("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",B===M.id&&"bg-accent font-medium"),children:[e.jsx("span",{className:"truncate whitespace-nowrap",children:hp(M.id)}),e.jsx("span",{className:"text-muted-foreground text-xs tabular-nums",children:M.count})]},M.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(Y,{className:"min-w-40 flex-1",value:h,placeholder:a("Search plugins"),onChange:M=>{x(M.target.value),p(null)}}),e.jsxs("label",{className:"flex shrink-0 items-center gap-1.5 text-muted-foreground text-xs",children:[e.jsx(le,{checked:o?.chinaMirror??!1,disabled:m,onCheckedChange:M=>{k(M)}}),a("China mirror")]}),e.jsx(y,{size:"sm",variant:"ghost",disabled:m,onClick:()=>{b(!0)},children:m?e.jsx(Rs,{}):a("Refresh")})]}),o?.ok===!1&&e.jsx("p",{className:"text-destructive text-sm",children:o.error}),o?.ok===!0&&o.stale&&e.jsx("p",{className:"text-muted-foreground text-xs",children:a("Could not reach the marketplace; showing the last saved list.")}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto pr-1",children:z?e.jsx(gp,{plugin:z,disabled:s,onBack:()=>p(null),onInstall:n}):o?.ok===!0&&P.length===0?e.jsx("p",{className:"text-muted-foreground text-sm",children:a("No matching plugins")}):e.jsx("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2",children:P.map(M=>e.jsx(fp,{plugin:M,disabled:s,onOpen:()=>p(M.id),onInstall:n},M.id))})})]})]})}function si({plugin:s,disabled:t,onInstall:n}){const{t:a}=D();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 ti({tier:s}){const{t}=D();return e.jsx(se,{variant:s==="official"?"secondary":"outline",className:"text-[11px]",children:t(s==="official"?"Official":"Community")})}function fp({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(ni,{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(ti,{tier:s.tier})]}),e.jsxs("p",{className:"text-muted-foreground text-xs",children:[s.latest,s.category?` · ${$n[s.category]}`:""]})]}),e.jsx(si,{plugin:s,disabled:t,onInstall:a})]}),s.description&&e.jsx("p",{className:"line-clamp-2 text-muted-foreground text-xs",children:s.description})]})}function gp({plugin:s,disabled:t,onBack:n,onInstall:a}){const{t:r}=D(),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(fo,{className:"size-3.5"}),"返回"]}),e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(ni,{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(ti,{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(Oc,{className:"size-3"}),r("Homepage")]})]}),e.jsx(si,{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:Qo(i)})]},i))})]}),e.jsxs("section",{className:"space-y-1",children:[e.jsx("h3",{className:"font-medium text-sm",children:r("Usage guide")}),e.jsx(Zo,{pluginId:s.id,from:"market",homepage:s.homepage,showLink:!1})]})]})}function ni({src:s,large:t}){const[n,a]=l.useState(!1);return e.jsx("div",{className:H("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 cr={session:"跟随当前会话",title:"跟随标题模型",fixed:"指定模型"};function jp({value:s,onChange:t}){const n=es(),a=po(s)??"session",r=typeof a=="string"?a:"fixed",o=typeof a=="string"?null:a,i=o?n.find(d=>d.id===o.providerId):void 0,m=i?.models.find(d=>d.id===o?.modelId);return e.jsxs("div",{className:"space-y-2",children:[e.jsxs(ne,{items:cr,value:r,onValueChange:d=>{if(d==="session"||d==="title")t(d);else if(d==="fixed"&&!o){const h=n[0],x=h?.models[0];h&&x&&t(ja({providerId:h.id,modelId:x.id}))}},children:[e.jsx(ae,{children:e.jsx(re,{})}),e.jsx(oe,{children:Object.entries(cr).map(([d,h])=>e.jsx(X,{value:d,disabled:d==="fixed"&&n.length===0,children:h},d))})]}),o&&e.jsx(ze,{providers:n,providerId:i?.id??"",modelId:m?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:"选择模型",side:"bottom",triggerClassName:Qe,onSelect:(d,h)=>t(ja({providerId:d,modelId:h})),onReasoningChange:()=>{},onThinkingChange:()=>{}}),o&&!m&&e.jsx("p",{className:"text-destructive text-xs",children:"选中的模型已不可用,运行时会失败,请重新选择。"})]})}function vp(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 bp({pluginId:s,plain:t}){const{t:n}=D(),[a,r]=l.useState([]),[o,i]=l.useState({}),[m,d]=l.useState(null),h=l.useCallback(async()=>{const u=await window.electronAPI.extensionPlugins.configGet(s);u.ok?r(u.fields):d({error:!0,text:u.error}),i({})},[s]);l.useEffect(()=>{h()},[h]);const x=async()=>{const u={};for(const[j,v]of Object.entries(o)){const I=a.find(k=>k.key===j);if(!I||I.secret&&v==="")continue;const b=op(I,v);if(!b.ok){d({error:!0,text:`${I.title}:${b.error}`});return}u[j]=b.value}const p=await window.electronAPI.extensionPlugins.configSet(s,u);d(p.ok?{error:!1,text:n("Saved. New calls use it right away.")}:{error:!0,text:p.error??""}),p.ok&&await h()},c=u=>{const p=o[u.key];return typeof p=="string"?p:p===null||u.secret?"":u.value??(u.default!==void 0?String(u.default):"")},f=u=>{const p=o[u.key];return typeof p=="boolean"?p:(u.value??(typeof u.default=="boolean"?String(u.default):"false"))==="true"};return e.jsxs("div",{className:H("space-y-2",t?"":"rounded-md border border-border p-3"),children:[a.map(u=>e.jsxs("div",{className:"space-y-1",children:[e.jsxs("p",{className:"text-sm",children:[u.title,e.jsx("span",{className:"ml-2 font-mono text-muted-foreground text-xs",children:u.key})]}),u.description&&e.jsx("p",{className:"text-muted-foreground text-xs",children:u.description}),u.multiline&&u.type==="string"?e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Xe,{autoComplete:"off",rows:4,value:c(u),placeholder:u.secret&&u.set?n("Set (leave blank to keep)"):n("Not set"),className:"min-w-0 flex-1",onChange:p=>i(j=>({...j,[u.key]:p.target.value}))}),u.set&&e.jsx(y,{size:"sm",variant:"ghost",onClick:()=>i(p=>({...p,[u.key]:null})),children:n("Clear value")})]}):u.secret||u.type==="string"||u.type==="number"||u.type==="path"?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Y,{type:u.secret?"password":u.type==="number"?"number":"text",autoComplete:"off",inputMode:u.type==="number"?"decimal":void 0,min:u.type==="number"?u.min:void 0,max:u.type==="number"?u.max:void 0,value:c(u),placeholder:u.secret&&u.set?n("Set (leave blank to keep)"):n("Not set"),onChange:p=>i(j=>({...j,[u.key]:p.target.value}))}),u.type==="path"&&!u.secret&&!window.electronAPI.remote&&e.jsx(y,{size:"sm",variant:"outline",onClick:()=>{window.electronAPI.extensionPlugins.pickPath(u.pathKind==="directory"?"directory":"file").then(p=>{p.ok&&"path"in p&&i(j=>({...j,[u.key]:p.path}))})},children:u.pathKind==="directory"?"选择文件夹":"选择文件"}),u.set&&e.jsx(y,{size:"sm",variant:"ghost",onClick:()=>i(p=>({...p,[u.key]:null})),children:n("Clear value")})]}):u.type==="boolean"?e.jsx(le,{checked:f(u),onCheckedChange:p=>i(j=>({...j,[u.key]:p}))}):u.type==="model"?e.jsx(jp,{value:c(u),onChange:p=>i(j=>({...j,[u.key]:p}))}):e.jsxs(ne,{items:Object.fromEntries((u.options??[]).map(p=>[p,p])),value:c(u),onValueChange:p=>{typeof p=="string"&&i(j=>({...j,[u.key]:p}))},children:[e.jsx(ae,{children:e.jsx(re,{placeholder:"请选择"})}),e.jsx(oe,{children:(u.options??[]).map(p=>e.jsx(X,{value:p,children:p},p))})]})]},u.key)),m&&e.jsx("p",{className:H("text-xs",m.error?"text-destructive":"text-muted-foreground"),children:m.text}),e.jsx(y,{size:"sm",disabled:Object.keys(o).length===0,onClick:()=>{x()},children:n("Save")})]})}function yp({pluginId:s,plain:t}){const{t:n}=D(),[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:H("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 dr({message:s}){const[t,n]=l.useState(!1);return e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("p",{className:H("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 ai({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:Qo(n)})]},n))})}function wp(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 ur(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 mr({permissions:s,env:t,interop:n,resident:a,running:r,styles:o,trustedUi:i,events:m,schedules:d}){return e.jsxs("div",{className:"space-y-1",children:[e.jsx(ai,{permissions:s,styles:o||i}),i&&e.jsx(Np,{}),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(h=>e.jsxs("p",{className:"text-xs",children:["事件 ",h.event," · ",h.mode==="intercept"?"拦截":"观察",h.failClosed?" · 失败即拒绝":""]},`${h.event}:${h.mode}`)),d?.map(h=>e.jsxs("p",{className:"text-xs",children:["定时任务 ",wp(h)]},h.id))]})}function Np(){return e.jsx("p",{className:"text-amber-700 text-xs dark:text-amber-400",children:"界面代码:运行在主界面里,可读写页面内容、调用界面能力,不受上面权限清单约束;只安装信任的插件"})}function kp({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:H("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(Bc,{artifacts:n??[],onDelete:m=>{window.electronAPI.extensionPlugins.artifactDelete(m).then(d=>{d.ok?i():o(d.error??"删除失败")})}})]})}const Wt=new Set;function Cp({requestedInstallUrl:s=null,onRequestedInstallUrlConsumed:t,focusPluginId:n=null,onFocusPluginConsumed:a}={}){const{t:r}=D(),o=g(T=>T.pluginAutoUpdate!==!1),i=g(T=>T.setPluginAutoUpdate),[m,d]=l.useState([]),h=En(T=>T.errors),[x,c]=l.useState(null),[f,u]=l.useState(null),[p,j]=l.useState([]),[v,I]=l.useState(!1),[b,k]=l.useState(null),[C,R]=l.useState(""),[B,P]=l.useState(!1),[z,M]=l.useState(!1),[A,S]=l.useState(null),[K,q]=l.useState(null),[N,L]=l.useState(!1),[V,$]=l.useState(null),O=l.useCallback(async()=>{try{d(await window.electronAPI.extensionPlugins.list())}catch{d([])}},[]);l.useEffect(()=>(O(),window.electronAPI.extensionPlugins.registryNotice().then(q).catch(()=>q(null)),window.electronAPI.extensionPlugins.onChanged(()=>{O()})),[O]),l.useEffect(()=>{if(!n||(j(E=>E.includes(n)?E:[...E,n]),!m.some(E=>E.id===n)))return;const T=n;window.requestAnimationFrame(()=>{document.querySelector(`[data-plugin-id="${CSS.escape(T)}"]`)?.scrollIntoView({block:"center"})}),a?.()},[n,m,a]);const te=async T=>{k(null),x&&window.electronAPI.extensionPlugins.discard(x.token),c(null);const E=await window.electronAPI.extensionPlugins.pickAndStage(T);E.ok?"cancelled"in E||c(E.preview):k(E.error)},G=async T=>{const E=(T??C).trim();if(!E)return;k(null),P(!0),x&&window.electronAPI.extensionPlugins.discard(x.token),c(null);const Q=await window.electronAPI.extensionPlugins.stageFromUrl(E).finally(()=>{P(!1)});Q.ok?c(Q.preview):k(Q.error)},J=l.useRef(G);J.current=G,l.useEffect(()=>{if(!s)return;const T=s;let E=!1;const Q=window.setTimeout(()=>{E||Wt.has(T)||(Wt.add(T),R(T),t?.(),J.current(T).finally(()=>{Wt.delete(T)}))},0);return()=>{E=!0,window.clearTimeout(Q)}},[s,t]);const W=async(T,E=!1)=>{k(null),x&&window.electronAPI.extensionPlugins.discard(x.token),c(null),P(!0);const Q=window.electronAPI.extensionPlugins,ie=await(E?Q.marketStage(T):Q.restage(T)).finally(()=>{P(!1)});ie.ok?c(ie.preview):k(ie.error)},ce=async()=>{M(!0),S(null);try{const T=await window.electronAPI.extensionPlugins.checkUpdates();S(T.checked===0?r("No plugins installed from GitHub to check"):T.available>0?r("{{count}} update(s) available",{count:T.available}):r("All plugins are up to date"))}finally{M(!1)}},_=async()=>{if(!x)return;I(!0);const T=await window.electronAPI.extensionPlugins.commit(x.token);if(I(!1),!T.ok)k(T.error??r("Install failed"));else{R("");const E=x.existingVersion?{ok:!0}:await window.electronAPI.extensionPlugins.setEnabled(x.id,!0);Pe({type:E.ok?"success":"warning",title:r("{{name}} installed",{name:x.name}),description:E.ok?void 0:E.error})}c(null)},de=()=>{x&&window.electronAPI.extensionPlugins.discard(x.token),c(null)};return e.jsxs("div",{className:"space-y-5","data-settings-row":"plugins.enso",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"font-medium text-lg",children:[r("Enso plugins"),e.jsx(Ze,{})]}),e.jsx("p",{className:"mt-1 text-muted-foreground text-sm",children:r("Installing a plugin lets it run code on this machine. Review what it asks for before confirming.")})]}),e.jsxs("div",{className:"flex shrink-0 gap-2",children:[m.length>0&&e.jsxs(y,{size:"sm",variant:"outline",disabled:z,onClick:()=>{ce()},children:[z?e.jsx(Rs,{}):e.jsx(ns,{className:"size-4"}),r("Check for updates")]}),e.jsxs(y,{size:"sm",onClick:()=>L(!0),children:[e.jsx($u,{className:"size-4"}),r("Marketplace")]})]})]}),e.jsxs("label",{className:"flex items-center justify-between gap-3 text-sm",children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block",children:r("Update plugins automatically")}),e.jsx("span",{className:"block text-muted-foreground text-xs",children:r("Marketplace updates that do not ask for new permissions install on their own.")})]}),e.jsx(le,{className:"shrink-0",checked:o,onCheckedChange:T=>i(T)})]}),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(mo,{className:"flex-1",children:[e.jsx(ho,{children:e.jsx(to,{className:"size-4 text-muted-foreground"})}),e.jsx(xo,{value:C,placeholder:r("https://github.com/owner/repo"),onChange:T=>R(T.target.value),onKeyDown:T=>{T.key==="Enter"&&G()}})]}),e.jsx(y,{size:"sm",variant:"outline",disabled:v||B||C.trim()==="",onClick:()=>{G()},children:B?e.jsx(Rs,{}):r("Install from URL")})]}),e.jsxs("div",{className:"flex items-center gap-1 text-muted-foreground text-xs",children:[e.jsx("span",{className:"mr-1",children:r("Or install from")}),e.jsxs(y,{size:"xs",variant:"ghost",disabled:v||B,onClick:()=>{te("dir")},children:[e.jsx(Tn,{className:"size-3.5"}),r("Install from folder")]}),e.jsxs(y,{size:"xs",variant:"ghost",disabled:v||B,onClick:()=>{te("zip")},children:[e.jsx(Dc,{className:"size-3.5"}),r("Install from zip")]})]})]}),b&&e.jsx("p",{className:"text-destructive text-sm",children:b}),e.jsx(je,{open:N,onOpenChange:L,children:e.jsxs(ve,{className:"max-w-5xl",children:[e.jsx(be,{children:e.jsx(ye,{children:r("Marketplace")})}),e.jsx(we,{children:e.jsx(pp,{disabled:v||B,installedKey:m.map(T=>`${T.id}@${T.version}`).join(","),onInstall:T=>{L(!1),W(T,!0)}})})]})}),A&&e.jsx("p",{className:"text-muted-foreground text-sm",children:A}),K&&e.jsx(vp,{notice:K,remote:!!window.electronAPI.remote,onDismiss:()=>{window.electronAPI.extensionPlugins.dismissRegistryNotice().then(()=>q(null)).catch(T=>k(T instanceof Error?T.message:String(T)))}}),e.jsx(je,{open:x!==null,onOpenChange:T=>!T&&!v&&de(),children:e.jsx(ve,{children:x&&e.jsxs(e.Fragment,{children:[e.jsx(be,{children:e.jsxs(ye,{children:[x.name," ",x.version,x.existingVersion&&e.jsx("span",{className:"ml-2 text-base text-muted-foreground",children:r("updating from {{version}}",{version:x.existingVersion})})]})}),e.jsxs(we,{className:"space-y-3",children:[e.jsx(mr,{permissions:x.permissions,env:x.env,interop:x.interop,resident:x.resident,styles:x.styles,trustedUi:x.hasRenderer,events:x.events,schedules:x.schedules}),x.mcpServers.map(T=>e.jsxs("p",{className:"font-mono text-xs",children:[T.command," ",T.args.join(" ")]},T.name)),x.mcpTools.length>0&&e.jsxs("p",{className:"text-muted-foreground text-xs",children:[r("Host MCP tools it may call"),":",e.jsx("span",{className:"font-mono",children:x.mcpTools.join(", ")})]}),x.warnings.map(T=>e.jsx("p",{className:"text-muted-foreground text-xs",children:T},T))]}),e.jsxs(Ie,{children:[e.jsx(y,{size:"sm",variant:"ghost",disabled:v,onClick:de,children:r("Cancel")}),e.jsx(y,{size:"sm",disabled:v,onClick:()=>{_()},children:v?e.jsx(Rs,{}):r("Install")})]})]})})}),m.length===0&&!x&&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:r("No Enso plugins installed")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:r("Browse the marketplace or install from a GitHub URL, folder or zip.")})]}),e.jsx("div",{className:"space-y-2",children:m.map(T=>e.jsxs("div",{"data-plugin-id":T.id,className:H("overflow-hidden rounded-lg border bg-card transition-colors",T.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:H("flex size-9 shrink-0 items-center justify-center rounded-md bg-muted",T.state==="enabled"?"text-foreground":"text-muted-foreground"),children:e.jsx(Lc,{pluginId:T.id,icon:T.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:T.name}),e.jsx(se,{variant:"outline",className:"text-[11px]",children:T.version}),T.state==="crashed"&&e.jsx(se,{variant:"destructive",className:"text-[11px]",children:r("Stopped after crashes")}),T.availableVersion&&e.jsx(se,{className:"text-[11px]",children:r("Update")}),T.pendingVersion&&e.jsx(se,{variant:"warning",className:"text-[11px]",children:"待授权"}),T.hasRenderer&&e.jsx(se,{variant:"outline",className:"text-[11px]",children:"受信任界面"}),T.devWatch&&e.jsx(se,{variant:"secondary",className:"text-[11px]",children:"开发模式"}),T.resident&&e.jsx(se,{variant:T.running?"secondary":"outline",className:"text-[11px]",children:T.running?"常驻运行中":"常驻未运行"})]}),e.jsx("p",{className:"truncate font-mono text-muted-foreground text-xs",children:T.id}),T.availableVersion&&e.jsxs("p",{className:"mt-1 flex items-center gap-2 text-primary text-xs",children:[r("Version {{version}} is available",{version:T.availableVersion}),e.jsx(y,{size:"xs",disabled:v||B,onClick:()=>{W(T.id,T.source?.kind!=="url")},children:B?e.jsx(Rs,{}):r("Update")})]}),T.updateCheckError&&e.jsx("p",{className:"text-muted-foreground text-xs",children:r("Update check failed: {{reason}}",{reason:T.updateCheckError})}),T.lastError&&e.jsx(dr,{message:T.lastError.message}),h[T.id]?.map(E=>e.jsx(dr,{message:`主题加载失败:${E}`},E)),T.pendingVersion&&e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2 rounded-md border border-amber-500/50 bg-amber-500/10 px-2 py-1.5 text-amber-700 text-xs dark:text-amber-400",children:[r("{{version}} asks for more and is waiting for approval",{version:T.pendingVersion}),e.jsx(y,{size:"xs",onClick:()=>{window.electronAPI.extensionPlugins.approvePending(T.id)},children:r("Allow")}),e.jsx(y,{size:"xs",variant:"ghost",onClick:()=>{window.electronAPI.extensionPlugins.rejectPending(T.id)},children:r("Keep current")})]})]})]}),e.jsxs("div",{className:"ml-auto flex shrink-0 items-center gap-0.5",children:[T.source&&e.jsx(y,{size:"icon",variant:"ghost",disabled:v||B,"aria-label":r("Reinstall from source"),title:T.source.kind==="url"?`${r("Reinstall from source")}: ${T.source.url}`:r("Reinstall from source"),onClick:()=>{W(T.id)},children:e.jsx(zc,{className:"size-4"})}),e.jsx(y,{size:"icon",variant:"ghost","aria-label":"产出文件",title:"产出文件",onClick:()=>u({kind:"artifacts",pluginId:T.id,pluginName:T.name}),children:e.jsx(_c,{className:"size-4"})}),e.jsx(y,{size:"icon",variant:"ghost","aria-label":r("Usage guide"),title:r("Usage guide"),onClick:()=>$({id:T.id,name:T.name,from:"installed"}),children:e.jsx(vu,{className:"size-4"})}),e.jsx(y,{size:"icon",variant:"ghost","aria-label":r("Plugin logs"),title:r("Plugin logs"),onClick:()=>u({kind:"logs",pluginId:T.id,pluginName:T.name}),children:e.jsx(Ln,{className:"size-4"})}),T.configurable&&e.jsx(y,{size:"icon",variant:"ghost","aria-label":r("Configure"),title:r("Configure"),onClick:()=>u({kind:"config",pluginId:T.id,pluginName:T.name}),children:e.jsx(Fc,{className:"size-4"})}),e.jsx(y,{size:"icon",variant:"ghost","aria-label":r("Uninstall"),title:r("Uninstall"),className:"text-muted-foreground hover:text-destructive",onClick:()=>{window.electronAPI.extensionPlugins.uninstall(T.id)},children:e.jsx(Ee,{className:"size-4"})}),e.jsx("div",{className:"mx-1.5 h-5 w-px bg-border"}),e.jsx(le,{checked:T.state==="enabled",onCheckedChange:E=>{window.electronAPI.extensionPlugins.setEnabled(T.id,E)}})]})]}),e.jsxs("button",{type:"button","aria-expanded":p.includes(T.id),className:H("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:()=>j(E=>E.includes(T.id)?E.filter(Q=>Q!==T.id):[...E,T.id]),children:[p.includes(T.id)?e.jsx(gt,{className:"size-3"}):e.jsx(zs,{className:"size-3"}),p.includes(T.id)?"收起详情":"详情",!p.includes(T.id)&&ur(T)&&e.jsx("span",{className:"ml-1 opacity-70",children:ur(T)})]}),p.includes(T.id)&&e.jsxs("div",{className:"space-y-3 border-t px-3 py-3",children:[T.interceptBreakers?.map(E=>e.jsxs("p",{className:"text-amber-600 text-xs dark:text-amber-400",children:[E.event," 检查连续失败,临时放行到"," ",new Date(E.until).toLocaleTimeString()]},E.event)),e.jsx(mr,{permissions:T.permissions,resident:T.resident,running:T.running,styles:T.themes.some(E=>E.css!==void 0),trustedUi:T.hasRenderer,events:T.events,schedules:T.schedules}),T.crossSessionInject!==void 0&&e.jsxs("div",{className:"flex items-center justify-between gap-3 text-xs",children:[e.jsxs("span",{children:[e.jsx("span",{className:"block",children:"允许向任意运行中的会话发送消息"}),e.jsx("span",{className:"block text-muted-foreground",children:"关闭时只能发到发起调用的会话;开启后定时任务、常驻进程也能向其他项目和窗口的会话发消息并触发执行"})]}),e.jsx(le,{"aria-label":"允许向任意运行中的会话发送消息",checked:T.crossSessionInject,onCheckedChange:E=>{window.electronAPI.extensionPlugins.setCrossSessionInject(T.id,E)}})]}),T.devWatch!==void 0&&e.jsxs("div",{className:"flex items-center justify-between gap-3 text-xs",children:[e.jsxs("span",{children:[e.jsx("span",{className:"block",children:"开发模式:目录改动后自动重装"}),e.jsx("span",{className:"block text-muted-foreground",children:"授权没扩大时直接替换;扩大时停下,需要从来源重新安装并同意。重启应用后关闭"})]}),e.jsx(le,{"aria-label":"开发模式:目录改动后自动重装",checked:T.devWatch,onCheckedChange:E=>{window.electronAPI.extensionPlugins.setDevWatch(T.id,E).then(Q=>{!Q.ok&&Q.error&&Pe({title:Q.error})})}})]}),((T.pendingPermissions?.length??0)>0||T.pendingRenderer)&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:"待同意"}),e.jsx(ai,{permissions:T.pendingPermissions??[],styles:T.pendingRenderer}),T.pendingRenderer&&e.jsx("p",{className:"text-amber-700 text-xs dark:text-amber-400",children:"新增界面代码:运行在主界面里,不受权限清单约束"})]})]})]},T.id))}),e.jsx(je,{open:f!==null,onOpenChange:T=>!T&&u(null),children:e.jsxs(ve,{children:[e.jsx(be,{children:e.jsxs(ye,{children:[f?.kind==="config"?r("Configure"):f?.kind==="logs"?r("Plugin logs"):"产出文件",f?` · ${f.pluginName}`:""]})}),e.jsxs(we,{className:"space-y-4",children:[f?.kind==="config"&&e.jsx(bp,{pluginId:f.pluginId,plain:!0}),f?.kind==="logs"&&e.jsx(yp,{pluginId:f.pluginId,plain:!0}),f?.kind==="artifacts"&&e.jsx(kp,{pluginId:f.pluginId,plain:!0})]})]})}),e.jsx(up,{pluginId:V?.id??null,name:V?.name??"",from:V?.from??"installed",homepage:V?.homepage,onClose:()=>$(null)})]})}function Sp(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 Ps({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 Ip({plugin:s,entry:t,onToggle:n}){const{t:a}=D(),[r,o]=l.useState(!1),{components:i}=s,m=Sp(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(d=>!d),children:[e.jsx(zs,{className:H("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(le,{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(Ps,{label:a("Skills"),items:i.skills}),e.jsx(Ps,{label:a("Commands"),items:i.commands.map(d=>`/${d}`)}),e.jsx(Ps,{label:a("Agent types"),items:i.agents}),e.jsx(Ps,{label:a("MCP servers (run when a session starts)"),items:i.mcpServers.map(d=>`${d.name}: ${d.target}`)}),e.jsx(Ps,{label:a("Hooks (run automatically on local sessions)"),items:i.hooks.map(d=>`${d.event}: ${d.command}`)}),e.jsx(Ps,{label:a("Not supported"),items:i.unsupported})]})]})}function Ap(){const{t:s}=D(),t=g(u=>u.plugins),n=g(u=>u.addPlugins),a=g(u=>u.setPluginEnabled),r=g(u=>u.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 d=new Map(t.map(u=>[u.key,u])),h=new Set((o??[]).map(u=>u.key)),x=o?t.filter(u=>!h.has(u.key)):[],c=t.filter(u=>u.enabled).length,f=(u,p)=>{const j=d.get(u.key);if(j){a(j.id,p);return}n([{id:crypto.randomUUID(),key:u.key,name:u.name,description:u.description,...u.version?{version:u.version}:{},source:u.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(Rs,{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(u=>e.jsx(Ip,{plugin:u,entry:d.get(u.key),onToggle:p=>f(u,p)},u.key))}),x.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")}),x.map(u=>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:u.name}),e.jsx(y,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-destructive",onClick:()=>r(u.id),children:e.jsx(Ee,{className:"h-3.5 w-3.5"})})]},u.id))]})]})}const Ys={mask:"Mask",warn:"Warn only",block:"Block"},Ep={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"},Pp=[1,7,30],Mp={1:"Today",7:"7D",30:"30D"};function Tp(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}=D(),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(X,{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 Os({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 Rp({settings:s}){const{t}=D(),[n,a]=l.useState(""),r=l.useMemo(()=>Uc(n,s),[n,s]);return e.jsxs(Os,{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:H("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 Op(){const{t:s}=D(),[t,n]=l.useState(7),[a,r]=l.useState(null),[o,i]=l.useState(!1),m=l.useRef(0),d=Vc(f=>f.conversations),h=l.useCallback(async f=>{const u=++m.current;i(!0);const p=await window.electronAPI.privacyMask.records(f).catch(()=>[]);u===m.current&&(i(!1),r(p))},[]);l.useEffect(()=>{h(t)},[t,h]);const x=l.useMemo(()=>{const f={mask:0,warn:0,block:0},u=new Map;for(const p of a??[]){const j=new Set;for(const v of p.report.hits){const I=`${v.action}:${v.token}`;j.has(I)||(j.add(I),f[v.action]+=1,u.set(v.kind,(u.get(v.kind)??0)+1))}}return{byAction:f,byKind:[...u].sort((p,j)=>j[1]-p[1])}},[a]),c=f=>{if(f.source==="aux")return s("Auxiliary request");const u=f.sessionId?d[f.sessionId]?.title:void 0,p=f.source==="compaction"?s("Compaction"):s("Session");return u?`${p} · ${u}`:p};return e.jsxs(Os,{title:s("Records"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"flex gap-1",children:Pp.map(f=>e.jsx(y,{size:"sm",variant:f===t?"secondary":"ghost",onClick:()=>n(f),children:s(Mp[f])},f))}),e.jsx(y,{variant:"ghost",size:"icon-sm",onClick:()=>{h(t)},disabled:o,"aria-label":s("Refresh"),children:e.jsx(ns,{className:H("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:x.byAction[f]})]},f))}),x.byKind.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 text-xs text-muted-foreground",children:x.byKind.map(([f,u])=>e.jsxs("span",{className:"rounded bg-muted px-1.5 py-0.5",children:[f," ",u]},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 u=Gc(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:H("py-1",u&&pn[u]),children:[Tp(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 Dp(){const{t:s}=D(),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(Se,{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(Os,{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(Se,{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(Se,{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(Os,{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(Se,{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:$c.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(Ep[r])]},r))})]}),e.jsxs(Os,{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(Os,{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(Rp,{settings:t})]}),e.jsx(Op,{})]})}function Lp(){const{t:s}=D(),t=g(u=>u.approvalReviewer),n=g(u=>u.setApprovalReviewer),a=g(u=>u.approvalAutoManage),r=g(u=>u.setApprovalAutoManage),o=Kc(g(u=>u.approvalAllowThreshold)),i=g(u=>u.setApprovalAllowThreshold),m={"0.85":s("0.85 (looser)"),"0.9":s("0.9 (default)"),"0.95":s("0.95 (stricter)")},d=es(),h=Rn(),x=l.useMemo(()=>[...d,...h.filter(ln)],[d,h]),c=t?x.find(u=>u.id===t.providerId):void 0,f=c?.models.find(u=>u.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.")})]}),x.length>0&&e.jsx("div",{className:"w-full min-w-0",children:e.jsx(ze,{providers:x,providerId:c?.id??"",modelId:f?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:s("No assistant approval model selected"),side:"bottom",triggerClassName:Qe,onSelect:(u,p)=>n({providerId:u,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(le,{"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:u=>i(Number(u)),children:[e.jsx(ae,{className:"w-36","aria-label":s("Auto-allow threshold"),children:e.jsx(re,{})}),e.jsx(oe,{children:Wc.map(u=>e.jsx(X,{value:String(u),children:m[String(u)]},u))})]})]}),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 xr(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 zp(){const{t:s}=D(),t=et(),n=g(R=>R.virtualModels),a=g(R=>R.defaultModel),r=g(R=>R.setDefaultModel),o=g(R=>R.defaultModelFollowLast),i=g(R=>R.setDefaultModelFollowLast),m=g(R=>R.defaultReasoningEnabled),d=g(R=>R.defaultThinkingLevel),h=g(R=>R.setDefaultReasoningEnabled),x=g(R=>R.setDefaultThinkingLevel),c=jt(R=>R.snapshot),f=Hc(R=>R.latest),u=es(),p=a?u.find(R=>R.id===a.providerId):void 0,j=p?.models.find(R=>R.id===a?.modelId),v=t.some(R=>!!R.oauthAccountKey),I=v&&(c.availability.status==="unloaded"||c.availability.status==="loading"),b=v&&c.availability.status==="error"?c.availability.error:null,k=f?.notice,C=k?s("Default model changed: {{previous}} → {{next}}",{previous:xr(k.previous,t),next:k.next?xr(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.")})]}),u.length>0&&e.jsx("div",{className:"w-full min-w-0",children:e.jsx(ze,{providers:u,virtualModels:n,providerId:p?.id??a?.providerId??"",modelId:j?.id??a?.modelId??"",reasoningEnabled:m,thinkingLevel:d,emptyLabel:s("Select model"),triggerLabel:o?s("Follow last selection"):void 0,side:"bottom",triggerClassName:Qe,onSelect:(R,B)=>r({providerId:R,modelId:B}),onReasoningChange:h,onThinkingChange:x,showReasoningControls:!o})}),!o&&u.length>0&&e.jsx(y,{type:"button",variant:"ghost",size:"sm",className:"self-start",onClick:()=>i(!0),children:s("Follow last selection")}),u.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.")})]}),(I||b)&&e.jsxs("div",{className:"flex items-start gap-2 rounded-md bg-muted px-2.5 py-2 text-xs",children:[e.jsx(Ds,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:b?s("Subscription credentials could not be loaded: {{error}}",{error:b}):s("Subscription credentials are loading. API-key models remain available.")})]}),C&&e.jsx("p",{className:"rounded-md bg-muted px-2.5 py-2 text-muted-foreground text-xs",children:C})]})}function _p(){const{t:s}=D(),t=Ju(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 Fp({provider:s,onClose:t}){const{t:n}=D(),a=g(j=>j.providers),r=g(j=>j.updateProvider),o=go(j=>j.snapshot),i=l.useMemo(()=>jo([s],o)[0]?.models??s.models,[s,o]),m=jt(j=>j.snapshot.availability),d=jt(j=>j.snapshot.revision),[h,x]=l.useState([]),[c,f]=l.useState(s.oauthAccountPool?.accountKeys??[]);l.useEffect(()=>{let j=!1;return window.electronAPI.providers.listOauth().then(v=>{j||x(v)}).catch(v=>{j||(x([]),console.error("Failed to load OAuth account metadata",v))}),()=>{j=!0}},[d]);const u=No(a),p=[...u.flatMap(j=>j.oauthAccountKey??[]),...c.filter(j=>!u.some(v=>v.oauthAccountKey===j))];return e.jsx(vo,{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,v)=>{const I=u.find(k=>k.oauthAccountKey===j),b=h.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(C=>k?[...C,j]:C.filter(R=>R!==j))}),e.jsxs("span",{className:"shrink-0 text-xs text-muted-foreground",children:[v+1,"."]}),e.jsx("span",{className:"min-w-0 truncate",children:b?.email??j}),!I?.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:bo(j.models,wo(o,s.oauthAccountKey??"")?.models,yo(g.getState(),s.id)),oauthAccountPool:{accountKeys:p.filter(v=>c.includes(v))}}),t())}})}function Bp({provider:s,onClose:t}){const{t:n}=D(),a=g(i=>i.updateProvider),r=go(i=>i.snapshot),o=l.useMemo(()=>s?.oauthAccountKey?jo([s],r)[0]?.models??s.models:s?.models,[s,r]);return e.jsx(je,{open:s!==null,onOpenChange:i=>!i&&t(),children:e.jsxs(ve,{children:[e.jsx(be,{children:e.jsx(ye,{children:s?.oauthAccountPool?Fn(s,n):n("Edit Provider")})}),s?.oauthAccountPool?e.jsx(Fp,{provider:s,onClose:t},s.id):s&&e.jsx(vo,{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:bo(i.models,wo(r,s.oauthAccountKey)?.models,yo(g.getState(),s.id))}:i),t()}},s.id)]})})}const $p=(s,t)=>s.models.some(n=>n.id===t&&n.enabled!==!1),hr=()=>{};function pr(s){return s==="on"||s==="off"}function Yt(s){return typeof s=="string"&&Qc.includes(s)}function Up(){const{t:s}=D(),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),d=g(c=>c.virtualModels),h=es(),x=l.useMemo(()=>{if(m&&qc(m)){const c=Yc(d,h).find(f=>f.id===m.modelId);if(c)return{providerId:Jc,modelId:c.id}}if(m){const c=h.find(f=>f.id===m.providerId);if(c&&$p(c,m.modelId))return m}for(const c of h){const f=c.models.find(u=>u.enabled!==!1);if(f)return{providerId:c.id,modelId:f.id}}return null},[h,m,d]);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(le,{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:H("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(le,{"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:h,virtualModels:d,providerId:c.providerId,modelId:c.modelId,modelCapabilityOverrides:Xc(c),reasoningMode:pr(c.reasoning)?c.reasoning:"follow",reasoningEnabled:c.reasoning==="on",thinkingLevel:Yt(c.thinkingLevel)?c.thinkingLevel:"medium",onReasoningModeChange:(f,u)=>{f==="follow"?o(c.id,{reasoning:void 0,thinkingLevel:void 0}):f==="on"&&!Yt(c.thinkingLevel)?o(c.id,{reasoning:"on",thinkingLevel:u}):o(c.id,{reasoning:f})},onSelect:(f,u)=>o(c.id,{providerId:f,modelId:u}),onReasoningChange:f=>o(c.id,{reasoning:f?"on":"off"}),onThinkingChange:f=>o(c.id,{thinkingLevel:f}),onReasoningNormalize:pr(c.reasoning)?f=>o(c.id,{reasoning:f?"on":"off"}):hr,onThinkingNormalize:Yt(c.thinkingLevel)?f=>o(c.id,{thinkingLevel:f}):hr})}),e.jsx(Y,{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(Ee,{className:"h-3.5 w-3.5"})})]},c.id)),e.jsxs(y,{type:"button",variant:"outline",size:"sm",className:"h-7 text-xs",disabled:!x,onClick:()=>{x&&r({...x,description:""})},children:[e.jsx(Me,{className:"mr-1 h-3.5 w-3.5"}),s("Add model")]}),!x&&e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Enable a model and configure valid provider credentials first.")})]})]})}function Vp(){const{t:s}=D(),t=g(d=>d.titleSummaryEnabled),n=g(d=>d.setTitleSummaryEnabled),a=g(d=>d.titleSummaryModel),r=g(d=>d.setTitleSummaryModel),o=es(),i=a?o.find(d=>d.id===a.providerId):void 0,m=i?.models.find(d=>d.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(le,{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:(d,h)=>r({providerId:d,modelId:h}),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 Gp({accountKey:s}){const t=dd(s);return!t||t.error?null:e.jsx(ud,{info:t})}function Kp(){const{t:s}=D(),t=g($=>$.providers),n=et(),a=g($=>$.updateProvider),r=g($=>$.addProviders),o=g($=>$.removeProvider),[i,m]=l.useState(!1),[d,h]=l.useState(!1),[x,c]=l.useState(null),[f,u]=l.useState(null),[p,j]=l.useState(null),[v,I]=l.useState(null),[b,k]=l.useState(!1),[C,R]=l.useState(!1),[B,P]=l.useState(null),z=jt($=>$.snapshot.revision),[M,A]=l.useState([]);l.useEffect(()=>{let $=!1;return window.electronAPI.providers.listOauth().then(O=>{$||A(O)}),()=>{$=!0}},[z]);const S=l.useMemo(()=>Zc(t,M),[t,M]),K=l.useMemo(()=>{const $=new Map;for(const O of n)$.set(O.id,O.models.length);return $},[n]),q=async($,O)=>{if(j($.id),I(null),$.oauthAccountKey&&!$.oauthAccountPool&&!O?.skipLogout)try{await window.electronAPI.providers.oauthLogout($.oauthAccountKey),await md()}catch(te){j(null),I({providerId:$.id,message:te instanceof Error?te.message:String(te)});return}o($.id),j(null),I(null)},N=()=>{const $=f;$&&q($)},L=async()=>{k(!0),P(null);try{const $=await ld(t);cd($,a),P($);const O=Object.values($).filter(G=>G.status==="failed"),te=Object.keys($).length-O.length;Pe({type:O.length>0?"warning":"success",title:s("Fetched {{count}} providers",{count:te}),...O.length>0?{description:s("{{count}} failed",{count:O.length})}:{}})}finally{k(!1)}},V=async()=>{R(!0);try{const $=await window.electronAPI.providers.refreshModelCatalog();id(),Pe({type:$.ok?"success":"warning",title:$.ok?s("Model info updated"):$.fromCache?s("Model info refresh failed, using cache"):s("Model info refresh failed")})}catch{Pe({type:"error",title:s("Model info refresh failed")})}finally{R(!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:C,onClick:()=>{V()},children:[C?e.jsx(Ae,{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:b||t.length===0,onClick:()=>{L()},children:[b?e.jsx(Ae,{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:()=>h(!0),children:[e.jsx(Me,{className:"h-4 w-4 mr-1.5"}),s("Add model or provider")]})]})]}),e.jsx(zp,{}),e.jsx(_p,{}),e.jsx(dx,{}),e.jsx(Vp,{}),e.jsx(Lp,{}),e.jsx(Up,{}),No(t).length>0&&!t.some($=>$.oauthAccountPool)&&e.jsxs("div",{className:"space-y-1.5 rounded-md border p-3",children:[e.jsxs(y,{variant:"outline",size:"sm",onClick:()=>{const $=ed(t,crypto.randomUUID());$&&r([$])>0&&c($)},children:[e.jsx(Me,{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($=>{const O=M.find(G=>G.id===$.vendorId),te=$.vendorId===sd?s("Custom"):$.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:te}),e.jsx("span",{className:"text-[11px] text-muted-foreground/60",children:$.providers.length})]}),e.jsx("div",{className:"mt-1.5 space-y-1 border-l pl-3",children:$.providers.map(G=>{const J=!!G.oauthAccountKey,W=K.get(G.id)??G.models.length,ce=G.oauthAccountKey&&!G.oauthAccountPool?O?.accounts.find(T=>T.key===G.oauthAccountKey):void 0,_=G.oauthAccountPool?Fn(G,s):J?ce?.email??G.oauthAccountKey??G.name:G.name,de=B?.[G.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.${G.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:[J?e.jsx(td,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}):e.jsx(nd,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx("span",{className:H("truncate text-sm font-medium",!G.enabled&&"text-muted-foreground line-through"),children:_}),J?ce?.plan&&e.jsx(se,{variant:"outline",className:"shrink-0 text-[10px] uppercase",children:ce.plan}):e.jsx(se,{variant:"outline",className:"shrink-0 text-[11px]",children:ad[G.api]??G.api}),G.importedFrom&&e.jsx(se,{variant:"secondary",className:"shrink-0 text-[11px]",children:G.importedFrom}),e.jsx("span",{className:"min-w-0 truncate text-xs text-muted-foreground",children:[J?void 0:G.baseUrl,G.oauthAccountPool?s("{{count}} accounts",{count:G.oauthAccountPool.accountKeys.length}):void 0,W>0?s("{{count}} models",{count:W}):void 0].filter(Boolean).join(" · ")})]}),ln(G)&&e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:s("Classification only, not for chat")}),G.oauthAccountKey&&!G.oauthAccountPool&&e.jsx(Gp,{accountKey:G.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(G),children:e.jsx(ms,{className:"h-3.5 w-3.5"})}),e.jsx(y,{variant:"ghost",size:"icon",disabled:p===G.id,className:H("h-7 w-7 text-muted-foreground opacity-0 transition-opacity hover:text-destructive group-hover:opacity-100",p===G.id&&"opacity-100"),onClick:()=>u(G),children:p===G.id?e.jsx(Ae,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Ee,{className:"h-3.5 w-3.5"})}),e.jsx(le,{checked:G.enabled,onCheckedChange:T=>a(G.id,{enabled:T})})]})]}),v?.providerId===G.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:v.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(G)},children:s("Retry")}),e.jsx(y,{variant:"ghost",size:"sm",className:"h-6 px-2 text-[11px] text-destructive hover:text-destructive",onClick:()=>{q(G,{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]})})]},G.id)})})]},$.vendorId)})}),e.jsx(rd,{open:i,onOpenChange:m}),e.jsx(od,{open:d,onOpenChange:h}),e.jsx(Bp,{provider:x,onClose:()=>c(null)}),e.jsx(Ur,{open:f!==null,onOpenChange:$=>{$||u(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 Wp=2e3,fr=50,Vs="",Hp=[{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 qp(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 Yp(s,t){return s.id==="data"?t("App data"):t("Worktree directory")}function Jp(s,t){return s.role!=="window"?s.name:s.name==="Main window"?t("Main window"):s.name==="Settings"?t("Settings"):s.name}function Xp(s){return`${s.toFixed(1)}%`}function Qp(){const{t:s}=D(),[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(gr,{metric:"cpu"})}),e.jsx(Ws,{value:"memory",className:"pt-4",children:t==="memory"&&e.jsx(gr,{metric:"memory"})}),e.jsx(Ws,{value:"storage",className:"pt-4",children:t==="storage"&&e.jsx(ef,{})})]})]})}function gr({metric:s}){const{t}=D(),[n,a]=l.useState(null),[r,o]=l.useState(null);if(l.useEffect(()=>{let h=!1,x;const c=async()=>{try{const f=await window.electronAPI.resources.sample();if(h)return;a(f),o(null)}catch(f){h||o(f instanceof Error?f.message:String(f))}h||(x=setTimeout(c,Wp))};return c(),()=>{h=!0,clearTimeout(x)}},[]),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"?Xp:xe,m=s==="cpu"?{app:n.cpu.app,system:n.cpu.system,total:100}:n.memory,d=h=>s==="cpu"?h.cpu:h.memory;return e.jsxs("div",{className:"space-y-4",children:[e.jsx(ri,{app:m.app,system:Math.max(m.system,m.app),total:m.total,format:i}),Hp.map(h=>{const x=n.processes.filter(c=>c.group===h.id).sort((c,f)=>d(f)-d(c));return x.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(h.label)}),e.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:i(x.reduce((c,f)=>c+d(f),0))})]}),e.jsx("div",{className:"divide-y",children:x.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:qp(c.role,t)}),e.jsx("span",{className:"min-w-0 flex-1 truncate",title:c.command??c.name,children:Jp(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(d(c))})]},c.pid))})]},h.id)})]})}function ri({app:s,system:t,total:n,format:a}){const{t:r}=D(),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 Zp(s,t){const n=[t("Freed {{size}}",{size:xe(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 ef(){const{t:s}=D(),[t,n]=l.useState(null),[a,r]=l.useState("scan"),[o,i]=l.useState(null),[m,d]=l.useState(null),[h,x]=l.useState(null),[c,f]=l.useState(null),u=l.useCallback(async(b,k)=>{r(b),d(null),i(null);try{n(await k())}catch(C){const R=C instanceof Error?C.message:String(C);R.includes("Scan cancelled")||d(R)}finally{r(null),i(null)}},[]),p=l.useCallback(()=>u("scan",()=>window.electronAPI.resources.scanStorage()),[u]),j=b=>u(b,async()=>{const k=await window.electronAPI.resources.cleanStorage(b);return Pe({type:k.failed>0?"warning":"success",title:s("{{name}} cleaned",{name:s(fn[b][0])}),description:Zp(k,s)}),k.snapshot});l.useEffect(()=>{const b=window.electronAPI.resources.onScanProgress(i);return window.electronAPI.resources.lastStorage().then(k=>{k&&n(C=>C??k)}),p(),()=>{b(),window.electronAPI.resources.cancelScan()}},[p]);const v=t?[...t.categories].filter(b=>b.bytes>0).sort((b,k)=>k.bytes-b.bytes):[],I=l.useMemo(()=>{const b=new Map;for(const k of t?.roots??[])b.set(k.volumeId,[...b.get(k.volumeId)??[],k]);return[...b.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:xe(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(We,{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:[I.map(b=>{const k=b[0]?.volume,C=b.reduce((R,B)=>R+B.bytes,0);return e.jsxs("div",{className:"space-y-2",children:[k?e.jsx(ri,{app:C,system:k.total-k.free,total:k.total,format:xe}):e.jsx("div",{className:"rounded-lg border p-4 font-mono text-2xl font-semibold",children:xe(C)}),b.map(R=>e.jsxs("div",{className:"flex items-center gap-2 px-1 text-xs",children:[e.jsx("span",{className:"shrink-0 text-muted-foreground",children:Yp(R,s)}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono",title:R.path,children:R.path}),e.jsx("span",{className:"font-mono",children:xe(R.bytes)})]},R.id))]},b[0]?.volumeId)}),e.jsx("div",{className:"divide-y rounded-lg border",children:v.map(b=>e.jsx(sf,{category:b,share:t.totalBytes>0?b.bytes/t.totalBytes:0,expanded:h===b.id,onToggle:()=>x(h===b.id?null:b.id),cleaning:a===b.id,disabled:a!==null,onClean:()=>ko[b.id]==="confirm"?f(b.id):void j(b.id)},b.id))}),e.jsx(tf,{sessions:t.sessions,busy:a==="sessions",disabled:a!==null,onClean:b=>u("sessions",async()=>{const k=await window.electronAPI.resources.cleanSessions(b);return Pe({type:"success",title:s("{{count}} conversations deleted",{count:k.removed})}),k.snapshot})})]}),e.jsx(wn,{open:c!==null,onOpenChange:b=>!b&&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 b=c;f(null),b&&j(b)},children:s("Clean")})]})]})})]})}function sf({category:s,share:t,expanded:n,onToggle:a,cleaning:r,disabled:o,onClean:i}){const{t:m}=D(),[d,h]=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(zs,{className:H("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(d)}),e.jsx("span",{className:"font-mono text-xs",children:xe(s.bytes)})]}),e.jsx("p",{className:"truncate text-xs text-muted-foreground",children:m(h)}),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}%`}})})]})]}),ko[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(x=>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:x.root==="data"?x.path:`${m("Worktree directory")}/${x.path}`}),e.jsx("span",{className:"font-mono",children:xe(x.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(x.root,x.path)},children:e.jsx(Tn,{})})]},`${x.root}:${x.path}`))})]})}function tf({sessions:s,busy:t,disabled:n,onClean:a}){const{t:r}=D(),[o,i]=l.useState(!1),[m,d]=l.useState(!1),[h,x]=l.useState(null),[c,f]=l.useState(Vs),u=l.useMemo(()=>new Map(s.map(M=>[M.id,M])),[s]),p=l.useMemo(()=>{const M=new Map;for(const A of s){const S=M.get(A.projectId)??{name:A.projectName,bytes:0,count:0};S.bytes+=A.bytes,S.count+=1,M.set(A.projectId,S)}return[...M].sort((A,S)=>S[1].bytes-A[1].bytes)},[s]),j=p.some(([M])=>M===c)?c:Vs,v=j?s.filter(M=>M.projectId===j):s,I=M=>{const A=gd(s,M,Date.now());return{request:M,count:A.length,bytes:A.reduce((S,K)=>S+(u.get(K)?.bytes??0),0)}},b=M=>I({kind:"stale",days:M,includeUnarchived:o,...j?{projectId:j}:{}}),k=v.reduce((M,A)=>M+A.bytes,0),C=m?v:v.slice(0,fr),R=(M,A)=>A||(M?M.slice(0,8):r("No project")),B=h?.request.kind==="one"?u.get(h.request.id):void 0,P=h?.request.kind==="stale"?h.request.projectId:void 0,z=P===void 0?void 0:R(P,p.find(([M])=>M===P)?.[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:[v.length," · ",xe(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(([M,A])=>[M,R(M,A.name)]))},value:j,onValueChange:M=>f(M??Vs),children:[e.jsx(ae,{size:"sm",className:"w-48 min-w-0",children:e.jsx(re,{})}),e.jsxs(oe,{children:[e.jsx(X,{value:Vs,children:r("All projects")}),p.map(([M,A])=>e.jsx(X,{value:M,children:e.jsxs("span",{className:"flex w-full items-center gap-3",children:[e.jsx("span",{className:"flex-1 truncate",children:R(M,A.name)}),e.jsxs("span",{className:"font-mono text-xs text-muted-foreground",children:[A.count," · ",xe(A.bytes)]})]})},M))]})]}),e.jsxs(Co,{children:[e.jsxs(So,{render:e.jsx(y,{variant:"outline",size:"sm",disabled:n||v.length===0}),children:[e.jsx(xd,{}),r(t?"Cleaning...":"Clean")]}),e.jsxs(Io,{align:"end",className:"min-w-48",children:[e.jsx(hd,{checked:o,onCheckedChange:i,closeOnClick:!1,children:r("Include unarchived")}),e.jsx(pd,{}),[...fd,0].map(M=>{const A=b(M);return e.jsxs(Ao,{variant:"destructive",disabled:A.count===0,onClick:()=>x(A),children:[e.jsx("span",{className:"flex-1",children:M>0?r("Older than {{days}} days",{days:M}):r("All")}),e.jsx("span",{className:"font-mono text-xs opacity-70",children:A.count})]},M)})]})]})]})]}),e.jsx("div",{className:"max-h-96 divide-y overflow-y-auto",children:C.map(M=>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:M.title,children:M.title||r("Untitled")}),e.jsx("div",{className:"truncate text-xs text-muted-foreground",children:[M.projectName,M.archived?r("Archived"):null,new Date(M.lastActiveAt).toLocaleDateString()].filter(Boolean).join(" · ")})]}),e.jsx("span",{className:"font-mono text-xs",children:xe(M.bytes)}),e.jsx(y,{variant:"ghost",size:"icon-sm",className:"opacity-0 group-hover:opacity-100",disabled:n,"aria-label":r("Delete"),onClick:()=>x({request:{kind:"one",id:M.id},count:1,bytes:M.bytes}),children:e.jsx(Ee,{})})]},M.id))}),v.length>fr&&e.jsx("button",{type:"button",onClick:()=>d(!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:h!==null,onOpenChange:M=>!M&&x(null),children:e.jsxs(Nn,{className:"sm:max-w-md",zIndexLevel:"nested",children:[e.jsxs(kn,{children:[e.jsx(Cn,{className:"text-base",children:B?r('Delete "{{title}}"?',{title:B.title||r("Untitled")}):z!==void 0?r("Delete {{count}} conversations in {{project}}?",{count:h?.count??0,project:z}):r("Delete {{count}} conversations?",{count:h?.count??0})}),e.jsxs(Sn,{children:[r("About {{size}} of history, tool output and isolated worktrees will be removed and cannot be restored.",{size:xe(h?.bytes??0)}),!B&&` ${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 M=h?.request;x(null),M&&a(M)},children:r("Delete")})]})]})})]})}const nf=Array.from({length:jd-va+1},(s,t)=>{const n=String(va+t);return{value:n,label:n}});function Ks({value:s,options:t,onChange:n,enso:a}){const{t:r}=D();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:H("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}=D();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 oi(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 af({pluginIds:s,busy:t,onChange:n}){const{t:a}=D(),[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:d=>n(d===!0?[...s,m.id]:s.filter(h=>h!==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 rf({busy:s}){const{t}=D(),[n,a]=l.useState([]),[r,o]=l.useState(null),i=l.useCallback(async()=>{const d=await window.electronAPI.secretary.listSkills();d.ok?a(d.skills.filter(h=>h.source==="own")):o(d.error)},[]);l.useEffect(()=>{i()},[i]);const m=async d=>{o(null);const h=await window.electronAPI.secretary.removeSkill(d);if(!h.ok){o(h.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(d=>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:d.name}),!d.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(d.name)},children:t("Remove")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:d.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:d.body??""})]})]},d.name))})}function of({busy:s}){const{t}=D(),[n,a]=l.useState([]),[r,o]=l.useState(null),i=l.useCallback(async()=>{const d=await window.electronAPI.secretary.listTools();d.ok?a(d.tools):o(d.error)},[]);l.useEffect(()=>{i()},[i]);const m=async d=>{o(null);const h=await window.electronAPI.secretary.removeTool(d);if(!h.ok){o(h.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(d=>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:d.name}),e.jsx("span",{className:"shrink-0 rounded bg-muted px-1.5 text-[10px] text-muted-foreground",children:d.runtime==="python"?"Python":"Node"}),e.jsx("span",{className:"shrink-0 rounded bg-muted px-1.5 text-[10px] text-muted-foreground",children:d.readOnly?t("Read-only"):t("Asks every call")}),e.jsx(y,{variant:"ghost",size:"sm",disabled:s,onClick:()=>{m(d.name)},children:t("Remove")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:d.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:d.code})]})]},d.name))})}function lf({profile:s,busy:t,onChange:n}){const{t:a}=D(),r=g(h=>h.projects),o=s.takeoverScope,i=s.visibleProjectIds,m=r.filter(h=>h.kind!=="secretary"&&h.kind!=="scratch"&&(i==="all"||i.includes(h.id))),d=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:h=>n(h==="all"?{mode:"all"}:h==="explicit"?{mode:"explicit"}:{mode:"projects",projectIds:d})}),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(h=>{const x=d.includes(h.id);return e.jsx("button",{type:"button","aria-pressed":x,disabled:t,onClick:()=>n({mode:"projects",projectIds:x?d.filter(c=>c!==h.id):[...d,h.id]}),className:H("rounded-md border px-2.5 py-1 text-xs transition-colors",x?"border-primary/60 bg-primary/10 text-foreground":"border-border text-muted-foreground hover:bg-muted"),children:h.alias||h.name},h.id)})}):null]})}function cf({locale:s}){const{t}=D(),[n,a]=l.useState([]),[r,o]=l.useState(null),i=l.useCallback(async()=>{const d=await window.electronAPI.secretary.listTakeovers();d.ok?a(d.takeovers):o(d.error)},[]);l.useEffect(()=>(i(),window.electronAPI.secretary.onStateChanged(()=>{i()})),[i]);const m=async d=>{o(null);const h=await window.electronAPI.secretary.revokeTakeover(d);h.ok||o(h.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(d=>e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2","data-enso":"secretary-takeover-row","data-conversation-id":d.conversationId,children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-sm",children:d.title||t("Unnamed")}),e.jsx("p",{className:"truncate text-xs text-muted-foreground",children:[d.projectName,oi(d.grantedAt,s)].filter(Boolean).join(" · ")})]}),e.jsx(y,{variant:"ghost",size:"sm",onClick:()=>{m(d.conversationId)},children:t("Take back")})]},d.conversationId))})]})}function df(){const{t:s}=D(),[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 d=await window.electronAPI.secretary.removeUntracked(m);d.ok||r(d.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 uf({skillIds:s,onChange:t}){const{t:n}=D(),a=g(r=>r.skills);return e.jsx(Md,{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 mf(){const{t:s,locale:t}=D(),[n,a]=l.useState(null),[r,o]=l.useState(""),[i,m]=l.useState(null),[d,h]=l.useState([]),[x,c]=l.useState(!1),[f,u]=l.useState(null),[p,j]=l.useState(null),[v,I]=l.useState(!1),[b,k]=l.useState(null),C=l.useRef(null),R=s("Secretary"),B=l.useCallback(async()=>{const S=await window.electronAPI.secretary.listSchedules();S.ok&&h(S.schedules)},[]),P=l.useCallback(async()=>{const S=await window.electronAPI.secretary.getProfile();if(!S.ok){u(S.error);return}a(S.profile),o(S.persona),m(S.profile?it(S.profile,R):null),await B()},[R,B]);l.useEffect(()=>{P()},[P]);const z=async S=>{c(!0),u(null),j(null);try{const K=await window.electronAPI.secretary.saveProfile(S);if(!K.ok){u(K.error);return}a(K.profile),m(it(K.profile,R)),j(s("Saved")),await B()}catch{u(s("Could not save the secretary profile. Try again."))}finally{c(!1)}},M=async S=>{c(!0),u(null);try{const K=await window.electronAPI.secretary.setAvatar(S);if(!K.ok){u(K.error);return}a(K.profile),m(it(K.profile,R))}catch{u(s("Could not save the secretary profile. Try again."))}finally{c(!1)}},A=async S=>{u(null);const K=await window.electronAPI.secretary.removeSchedule(S);if(!K.ok){u(K.error);return}await B()};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,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:C,type:"file",accept:"image/png,image/jpeg,image/webp,image/gif","data-enso":"secretary-avatar-file",className:"hidden",onChange:S=>{const K=S.target.files?.[0];if(S.target.value="",!K)return;if(vd(K,ba)){u(s("Avatar images must be PNG, JPEG, WebP or GIF, and at most 2 MB."));return}bd(K).then(k,()=>u(s("This image cannot be used as an avatar.")))}}),e.jsx(yd,{name:n.name,color:n.avatar.color,image:n.avatar.imageVersion?wd(n.avatar.imageVersion):void 0,needsYou:0,running:0,enso:"secretary-settings-avatar"}),e.jsx(y,{variant:"outline",size:"sm",disabled:x,onClick:()=>C.current?.click(),"data-enso":"secretary-avatar-upload",children:s("Upload image")}),n.avatar.imageVersion?e.jsx(y,{variant:"ghost",size:"sm",disabled:x,onClick:()=>{M(null)},"data-enso":"secretary-avatar-remove",children:s("Remove image")}):null,e.jsx(Nd,{source:b,onCancel:()=>k(null),onDone:S=>{k(null);const K=kd(S);if(K.byteLength>ba){u(s("Avatar images must be PNG, JPEG, WebP or GIF, and at most 2 MB."));return}M(K)}})]}):e.jsx("p",{className:"text-xs text-muted-foreground",children:s("The secretary has not been set up yet.")}),e.jsx(Cd,{initialDraft:n?it(n,R):Sd(R),submitLabel:s("Save"),busy:x,hideMaxRunning:!0,onSubmit:({maxRunningDispatches:S,...K})=>{z(K)}},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:nf,onChange:S=>{const K=Number(S);x||K===n.maxRunningDispatches||z({maxRunningDispatches:K})}}):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(af,{pluginIds:n.pluginIds??[],busy:x,onChange:S=>{z({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(rf,{busy:x})]}),e.jsx(uf,{skillIds:n.skillIds??[],onChange:S=>{z({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(of,{busy:x}):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(Y,{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:Id[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:Ad[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:Ed[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(Y,{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:x,onClick:()=>{z({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(lf,{profile:n,busy:x,onChange:S=>{z({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(cf,{locale:t}),e.jsx(df,{})]}),e.jsx(ss,{title:"Scheduled tasks",rowId:"secretary.schedules",children:d.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:d.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?` · ${oi(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:()=>{A(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:()=>I(!0),children:s("Re-run setup")}),e.jsx(Pd,{open:v,onOpenChange:I,onReset:()=>{a(null),m(null),o(""),j(null),B()}})]})]})}function xf(){const{t:s}=D(),t=g(C=>C.skills),n=g(C=>C.updateSkill),a=g(C=>C.setSkillsEnabled),r=g(C=>C.removeSkill),o=g(C=>C.loadLocalSkills),i=g(C=>C.setLoadLocalSkills),m=g(C=>C.loadHarnessAssets),d=g(C=>C.setLoadHarnessAssets),[h,x]=l.useState(!1),[c,f]=l.useState(""),u=t.filter(C=>io(c,[C.name,C.source,C.description,C.path])),p=u.map(C=>C.id),j=lo(p),v=t.filter(C=>C.enabled).length,I=t.map(C=>C.id),b=It(I,C=>window.electronAPI.assets.skillOccupancy(C)),k=kt(t.filter(C=>C.enabled).map(C=>C.id),b.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(le,{checked:o,onCheckedChange:i})]}),e.jsxs("div",{className:"flex items-center justify-between gap-4 rounded-lg border px-3 py-2.5",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children: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(le,{checked:m,onCheckedChange:d})]}),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:v,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:()=>x(!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(Eo,{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(uo,{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:u.length===0,actionDisabled:j.selectedIds.length===0}),u.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:u.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":`skills.${C.id}`,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(Le,{checked:j.isSelected(C.id),onCheckedChange:R=>j.toggleOne(C.id,R)}),e.jsx("span",{className:H("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}),e.jsx("span",{className:"min-w-0 truncate text-muted-foreground text-xs",children:C.description||C.path})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(Ct,{row:b.rows[C.id],pending:b.pending&&!b.rows[C.id]}),e.jsx(le,{checked:C.enabled,onCheckedChange:R=>n(C.id,{enabled:R})}),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(C.id),children:e.jsx(Ee,{className:"h-3.5 w-3.5"})})]})]},C.id))})]}),e.jsx(zn,{kind:"skill",open:h,onOpenChange:x})]})}const jr=[10,15,30,60,120,300];function hf(){const{t:s}=D(),[t,n]=l.useState([]),[a,r]=l.useState(!1),[o,i]=l.useState(null),[m,d]=l.useState(""),[h,x]=l.useState(""),[c,f]=l.useState(""),[u,p]=l.useState(""),[j,v]=l.useState("key"),[I,b]=l.useState(""),[k,C]=l.useState(!1),[R,B]=l.useState(null),[P,z]=l.useState(null),[M,A]=l.useState(null),[S,K]=l.useState(null),[q,N]=l.useState(!1),L=l.useCallback(()=>{window.electronAPI.sshConnections.list().then(n)},[]);l.useEffect(()=>{L()},[L]);const V=()=>{i(null),d(""),x(""),f(""),p(""),v("key"),b(""),z(null),r(!0)},$=W=>{i(W),d(W.name),x(W.host),f(W.user??""),p(W.port?String(W.port):""),v(W.auth),b(""),z(null),r(!0)},O=async W=>{W.preventDefault(),C(!0),z(null);const ce=u.trim()?Number(u):void 0,_=await window.electronAPI.sshConnections.upsert({...o?{id:o.id}:{},name:m.trim(),host:h.trim(),...c.trim()?{user:c.trim()}:{},...ce&&Number.isInteger(ce)?{port:ce}:{},auth:j,...j==="password"&&I?{password:I}:{}});if(C(!1),!_.ok){z(_.error);return}r(!1),L()},te=async W=>{const ce=await window.electronAPI.sshConnections.delete(W);if(!ce.ok){A(ce.error);return}A(null),L()},G=async(W,ce=!0)=>{B(W),A(null);const _=await window.electronAPI.sshConnections.test(W);if(B(null),!_.ok){const de=t.find(E=>E.id===W),T=Rd(_,de);if(T&&ce){K({id:W,challenge:T});return}}A(_.ok?s("SSH connection succeeded"):_.error)},J=async()=>{if(!S)return;N(!0);const W=S.id,ce=await window.electronAPI.sshConnections.trustHost(W);if(N(!1),K(null),!ce.ok){A(ce.error||s("Could not save host key."));return}await G(W,!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:V,children:[e.jsx(Me,{className:"h-4 w-4"}),s("Add connection")]})]}),M&&e.jsx("p",{className:"text-sm text-muted-foreground",children:M}),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(W=>e.jsxs("li",{className:"flex items-center gap-2 px-3 py-2","data-settings-row":`ssh.${W.id}`,children:[e.jsxs("button",{type:"button",className:"min-w-0 flex-1 text-left",onClick:()=>$(W),children:[e.jsx("div",{className:"truncate text-sm font-medium",children:W.name}),e.jsxs("div",{className:"truncate text-xs text-muted-foreground",children:[W.user?`${W.user}@`:"",W.host,W.port?`:${W.port}`:""," ·"," ",W.auth==="password"?s("Password"):s("Key / agent")]})]}),e.jsx(y,{size:"sm",variant:"outline",disabled:R===W.id,onClick:()=>{G(W.id)},children:R===W.id?e.jsx(Ae,{className:"h-4 w-4 animate-spin"}):s("Test")}),e.jsx(y,{size:"icon-sm",variant:"ghost",onClick:()=>{te(W.id)},children:e.jsx(Ee,{className:"h-4 w-4"})})]},W.id))]}),e.jsx(pf,{}),e.jsx(je,{open:a,onOpenChange:r,children:e.jsx(ve,{className:"max-w-md",children:e.jsxs("form",{onSubmit:W=>{O(W)},className:"flex flex-col",children:[e.jsx(be,{children:e.jsx(ye,{children:s(o?"Edit SSH connection":"Add SSH connection")})}),e.jsxs(we,{className:"space-y-3",children:[e.jsxs(he,{children:[e.jsx(pe,{children:s("Name")}),e.jsx(Y,{value:m,onChange:W=>d(W.target.value),required:!0})]}),e.jsxs(he,{children:[e.jsx(pe,{children:s("Host")}),e.jsx(Y,{value:h,onChange:W=>x(W.target.value),placeholder:"example.com",required:!0})]}),e.jsxs(he,{children:[e.jsx(pe,{children:s("User (optional)")}),e.jsx(Y,{value:c,onChange:W=>f(W.target.value)})]}),e.jsxs(he,{children:[e.jsx(pe,{children:s("Port (optional)")}),e.jsx(Y,{value:u,onChange:W=>p(W.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:W=>v(W),children:[e.jsx(ae,{className:"w-full",children:e.jsx(re,{})}),e.jsxs(oe,{zIndex:is.DROPDOWN_IN_MODAL,children:[e.jsx(X,{value:"key",children:s("Key / agent")}),e.jsx(X,{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(Y,{type:"password",value:I,onChange:W=>b(W.target.value),required:!o?.hasPassword})]}),P&&e.jsx("p",{className:"text-sm text-destructive",children:P})]}),e.jsxs(Ie,{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(Td,{challenge:S?.challenge??null,busy:q,onTrust:()=>{J()},onDismiss:()=>!q&&K(null)})]})}function pf(){const{t:s}=D(),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(jr.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:jr.map(a=>e.jsx(X,{value:String(a),children:`${a}s`},a))})]})]})}const ff={memory:"memory",workflows:"workflow"},ii=["bots","botTemplates"],li=["secretary"],gf=[{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 jf(s){const t=new Map(s.map(n=>[n.id,n]));return gf.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 ci(s,t,n=!1,a=!1){if(li.includes(s))return a;if(ii.includes(s))return n;if(s==="memory"&&a)return!0;const r=ff[s];return!r||!t.includes(r)}function vf(s,t,n=!1,a=!1){return s.filter(r=>ci(r.id,t,n,a))}function bf(s,t,n=!1,a=!1){return ci(s,t,n,a)?s:ii.includes(s)||li.includes(s)?"experimental":"tools"}function yf(s,t,n,a){const r=n.trim();if(!r)return s.map(d=>({...d,hits:[]}));const o=Od([...t,...s.map(d=>({id:`${d.id}.root`,category:d.id,title:d.label}))],r,{translate:a,limit:Number.POSITIVE_INFINITY}),i=new Set,m=new Map;for(const d of o){if(i.add(d.category),d.id.endsWith(".root"))continue;const h=m.get(d.category);h?h.push(d):m.set(d.category,[d])}return s.flatMap(d=>i.has(d.id)?[{...d,hits:m.get(d.id)??[]}]:[])}const wf=[1,7,30,90],vr=640,dt=180,br=8,yr=18,Nf=.3,kf=2;function Cf(s){const[,t,n]=s.split("-");return`${Number(t)}/${Number(n)}`}const Sf=[{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 If({daily:s}){const{t}=D(),[n,a]=l.useState("tokens"),[r,o]=l.useState(null),[i,m]=l.useState({output:!0,input:!0,cache:!0}),d=b=>{m(k=>{const C={...k,[b]:!k[b]};return!C.output&&!C.input&&!C.cache?k:C})},h=s.map(b=>n==="cost"?b.cost??0:(i.output?b.output:0)+(i.input?b.input:0)+(i.cache?b.cache:0)),x=Math.max(0,...h),c=Math.max(1,s.length),f=vr/c,u=Math.min(f*(1-Nf),64),p=dt-br-yr,j=b=>x>0?b/x*p:0,v=Math.max(1,Math.ceil(c/12)),I=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:()=>d("output")}),e.jsx(Jt,{className:"bg-foreground/45",label:t("Input"),pressed:i.input,onClick:()=>d("input")}),e.jsx(Jt,{className:"bg-foreground/15",label:t("Cache"),pressed:i.cache,onClick:()=>d("cache")})]}),e.jsx(Af,{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"?He(x):vt(x>0?x:null)}),I&&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:[I.day,n==="tokens"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[t("Output")," ",He(I.output)]}),e.jsxs("div",{children:[t("Input")," ",He(I.input)]}),e.jsxs("div",{children:[t("Cache")," ",He(I.cache)]})]}):e.jsxs(e.Fragment,{children:[" · ",vt(I.cost)]})]}),e.jsx("svg",{viewBox:`0 0 ${vr} ${dt}`,className:"mt-4 block h-[180px] w-full",role:"img","aria-label":t("Daily trend"),onMouseLeave:()=>o(null),children:s.map((b,k)=>{const C=k*f+(f-u)/2,R=dt-yr,B=n==="tokens"?Sf.filter(z=>i[z.id]).map(z=>({v:b[z.id],cls:z.cls})):[{v:b.cost??0,cls:"fill-emerald-600 dark:fill-emerald-500"}];let P=R;return e.jsxs("g",{onMouseEnter:()=>o(k),children:[e.jsx("rect",{x:C,y:br,width:u,height:p,className:"fill-transparent"}),B.map(z=>{const M=z.v>0?Math.max(kf,j(z.v)):0;return P-=M,e.jsx("rect",{x:C,y:P,width:u,height:M,rx:1,className:H(z.cls,r===k&&"opacity-80")},z.cls)}),k%v===0&&e.jsx("text",{x:C+u/2,y:dt-4,textAnchor:"middle",className:"fill-muted-foreground font-mono text-[10px]",children:Cf(b.day)})]},b.day)})})]})]})}function Jt({className:s,label:t,pressed:n,onClick:a}){return e.jsxs("button",{type:"button","aria-pressed":n,onClick:a,className:H("flex items-center gap-1 rounded px-0.5 transition-opacity",n?"opacity-100":"opacity-40"),children:[e.jsx("span",{className:H("inline-block h-2.5 w-2.5 rounded-sm",s)}),t]})}function Af({value:s,onChange:t}){const{t:n}=D(),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:H("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"],wr=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 Ef(s,t){return s<=0||t<=0?0:1+Math.min(yt.length-2,Math.floor(s/t*(yt.length-1)))}function Pf({heatmap:s}){const{t}=D(),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:H("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:wr.map((o,i)=>e.jsx("span",{title:`${t(Xt[r])} ${o}:00 · ${He(a[i]??0)}`,className:H("aspect-square rounded-[2px]",yt[Ef(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:wr.map((a,r)=>e.jsx("span",{className:H(r%3!==0&&"invisible"),children:a},a))})]})]})}function Qt({title:s,countLabel:t,rows:n,emptyLabel:a,limit:r=8}){const{t:o}=D(),[i,m]=l.useState(!1),d=n.reduce((c,f)=>c+f.tokens,0),h=n.length>r,x=h&&!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}),h&&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})})]}),x.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:x.map(c=>{const f=d>0?c.tokens/d: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:H("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:[He(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)})})]}),h&&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 Mf({value:s,className:t}){const n=s.split("");return e.jsx("span",{className:H("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 Tf={default:"text-foreground",success:"text-emerald-600 dark:text-emerald-400",info:"text-sky-600 dark:text-sky-400",muted:"text-muted-foreground"};function us({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:H("mt-1 truncate font-mono text-xl font-semibold leading-tight tabular-nums sm:text-2xl",Tf[a]),title:t,children:e.jsx(Mf,{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 Rf(s){return _d({id:Object.fromEntries(wt.map(n=>[n,Number(s[n])]))}).id??null}function Of(s){return s===void 0?"—":String(s)}function Nr({rows:s,editing:t,draft:n,overrides:a,onDraft:r,onEdit:o,onSave:i}){const{t:m}=D();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(d=>e.jsx("th",{className:"pb-2 text-right font-normal",children:d},d)),e.jsx("th",{className:"w-14 pb-2"})]})}),e.jsx("tbody",{children:s.map(d=>{const h=t===d.model,x=d.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:d.model,children:d.model}),x&&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:h?e.jsx(Y,{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:H("font-mono tabular-nums",d.pricing==null&&"text-muted-foreground"),children:Of(d.pricing?.[c])})},c)),e.jsx("td",{className:"py-1.5 text-right align-middle",children:h?e.jsx(y,{size:"sm",className:"h-6 px-1.5 text-[11px]",onClick:()=>i(d.model),children:m("Save")}):e.jsx(y,{variant:"ghost",size:"sm",className:"h-6 px-1.5 text-[11px]",onClick:()=>o(d.model,d.pricing),children:m("Edit")})})]},d.model)})})]})}function Df({models:s,catalog:t,onChanged:n}){const{t:a}=D(),r=g(N=>N.usageModelPricing),o=et(),i=g(N=>N.setUsageModelPricing),[m,d]=l.useState(!1),[h,x]=l.useState(!1),[c,f]=l.useState(null),[u,p]=l.useState(en(Zt)),[j,v]=l.useState(null),[I,b]=l.useState(!1),[k,C]=l.useState(""),[R,B]=l.useState(""),P=new Set(s.map(N=>N.model)),z=new Set;for(const N of o)for(const L of N.models)z.add(L.id);for(const N of Object.keys(r))z.add(N);const M=R.trim().toLowerCase(),A=s.filter(N=>!M||N.model.toLowerCase().includes(M)).map(N=>({model:N.model,pricing:N.pricing})),S=[...z].filter(N=>!P.has(N)&&(!M||N.toLowerCase().includes(M))).sort().map(N=>({model:N,pricing:r[N]??t[N]??null})),K=(N,L)=>{b(!1),f(N),p(en(L??Zt)),v(null)},q=N=>{const L=Rf(u);return!L||!i(N,L)?(v(a("Enter a model id and non-negative rates.")),!1):(v(null),f(null),b(!1),C(""),n(),!0)};return e.jsxs(Dd,{open:m,onOpenChange:d,className:"rounded-lg border bg-card",children:[e.jsxs(Ld,{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:H("h-4 w-4 shrink-0 text-muted-foreground transition-transform",m&&"rotate-180")})]}),e.jsx(zd,{children:e.jsxs("div",{className:"space-y-3 border-t px-4 py-3",children:[e.jsx(Y,{size:"sm",value:R,onChange:N=>B(N.target.value),placeholder:a("Search models")}),A.length===0&&!I?e.jsx("p",{className:"text-xs text-muted-foreground",children:a(M?"No matching models":"No usage in this period")}):e.jsx(Nr,{rows:A,editing:c,draft:u,overrides:r,onDraft:p,onEdit:K,onSave:q}),S.length>0&&(h||!!M)&&e.jsx(Nr,{rows:S,editing:c,draft:u,overrides:r,onDraft:p,onEdit:K,onSave:q}),I?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(Y,{size:"sm",value:k,onChange:N=>C(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(Y,{size:"sm",inputMode:"decimal",value:u[N],onChange:L=>p(V=>({...V,[N]:L.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:()=>{b(!1),C(""),v(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:()=>x(N=>!N),children:[a("Show all"),e.jsx(gt,{className:H("ml-1 h-3.5 w-3.5 transition-transform",h&&"rotate-180")})]}),e.jsx(y,{variant:"ghost",size:"sm",className:"h-7",onClick:()=>{b(!0),p(en(Zt)),v(null)},children:a("Add")})]}),j&&e.jsx("p",{className:"text-xs text-destructive",children:j})]})})]})}const Lf={1:"Today",7:"7D",30:"30D",90:"90D"};function zf(){const{t:s}=D(),[t,n]=l.useState(7),[a,r]=l.useState(null),o=g(p=>p.botModeEnabled),[i,m]=l.useState(null),[d,h]=l.useState(null),[x,c]=l.useState(!1),f=l.useRef(0),u=l.useCallback(async p=>{const j=++f.current;c(!0);const[v,I]=await Promise.all([window.electronAPI.usage.summary(p),o?window.electronAPI.bots.usageSummary(p).catch(()=>null):null]);j===f.current&&(c(!1),m(I?.ok?I.rows:null),v.ok?(r(v.summary),h(null)):(r(null),h(v.error)))},[o]);return l.useEffect(()=>{u(t)},[t,u]),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:()=>{u(t)},disabled:x,"aria-label":s("Refresh"),children:e.jsx(ns,{className:H(x&&"animate-spin")})})]}),e.jsx(_f,{value:t,onChange:n}),d&&e.jsx("p",{className:"text-sm text-destructive",children:d}),a&&e.jsxs(e.Fragment,{children:[e.jsx(Ff,{totals:a.totals,previous:a.previous}),e.jsx(If,{daily:a.daily}),e.jsx(Pf,{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(Df,{models:a?.byModel??[],catalog:a?.pricing??{},onChanged:()=>{u(t)}})]})}function _f({value:s,onChange:t}){const{t:n}=D();return e.jsx("div",{className:"flex items-center gap-1.5",children:wf.map(a=>e.jsx("button",{type:"button",onClick:()=>t(a),className:H("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(Lf[a])},a))})}function Ff({totals:s,previous:t}){const{t:n}=D(),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(us,{label:n("Estimated cost"),value:vt(s.cost),delta:cs(t.cost,s.cost),tone:"success"}),e.jsx(us,{label:n("Total tokens"),value:He(s.tokens),delta:cs(t.tokens,s.tokens)}),e.jsx(us,{label:n("Input tokens"),value:He(s.input),delta:cs(t.input,s.input)}),e.jsx(us,{label:n("Output tokens"),value:He(s.output),delta:cs(t.output,s.output)}),e.jsx(us,{label:n("Cache tokens"),value:He(a),delta:cs(r,a),tone:"muted"}),e.jsx(us,{label:n("Active time"),value:Fd(s.activeMs),delta:cs(t.activeMs,s.activeMs),tone:"info"}),e.jsx(us,{label:n("Sessions"),value:String(s.sessions),delta:cs(t.sessions,s.sessions)}),e.jsx(us,{label:n("Messages"),value:s.messages.toLocaleString(),delta:cs(t.messages,s.messages)})]})}const kr={"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 di({state:s,onDownload:t,onCancel:n,onRemove:a}){const{t:r}=D();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 Bf(){const{t:s}=D(),t=g(x=>x.voiceModel),n=g(x=>x.setVoiceModel),{status:a,progress:r,error:o,refresh:i}=Bd();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,d=x=>{const c=r[x.id];return c?`${c.file} · ${xe(c.received)}${c.total?` / ${xe(c.total)}`:""} (${c.fileIndex+1}/${c.fileCount})`:o?.modelId===x.id?`${s("Download failed")}: ${o.message}`:x.id==="wetype"?s("Audio is uploaded to Tencent WeChat Keyboard servers."):x.remote?x.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:xe(x.approxBytes),memory:xe(x.memoryBytes)})},h=a.models.find(x=>x.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(x=>{const c=x.id===t;return e.jsxs("div",{className:H("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(x.id),className:"flex min-w-0 flex-1 items-start gap-2.5 text-left",children:[e.jsx("span",{className:H("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(kr[x.id].name),x.remote?e.jsx(se,{variant:"warning",size:"sm",children:s("Cloud")}):null,e.jsx(se,{variant:x.streaming?"info":"secondary",size:"sm",children:x.streaming?s("Streaming"):s("Sentence by sentence")}),x.state==="ready"&&!x.remote?e.jsx(se,{variant:"success",size:"sm",children:s("Downloaded")}):null]}),e.jsx("span",{className:"block text-muted-foreground text-xs",children:s(kr[x.id].description)}),e.jsx("span",{className:H("block text-xs",o?.modelId===x.id?"text-destructive":x.remote?"text-warning":"text-muted-foreground"),children:d(x)})]})]}),e.jsx(di,{state:x.remote?"unavailable":x.state,onDownload:()=>{n(x.id),m.download(x.id).then(i)},onCancel:()=>{m.cancelDownload(x.id).then(i)},onRemove:()=>{m.remove(x.id).then(i)}})]},x.id)})}),a.state!=="ready"&&a.state!=="downloading"&&!h?.remote?e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Download the selected model to start using voice input.")}):null,h?.id==="gemini-live"?e.jsxs(e.Fragment,{children:[e.jsx($f,{}),e.jsx(Uf,{})]}):null]})}function $f(){const{t:s}=D(),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(Y,{type:"password",autoComplete:"off",spellCheck:!1,value:t,onChange:a=>n(a.target.value),placeholder:"AIza…",className:"font-mono"})]})}function Uf(){const{t:s}=D(),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 Vf(){const{t:s}=D(),t=g(b=>b.voiceCorrectionEnabled),n=g(b=>b.setVoiceCorrectionEnabled),a=g(b=>b.voiceCorrectionModel)||"remote",r=g(b=>b.setVoiceCorrectionModel),o=g(b=>b.voiceCorrectionRemoteModel),i=g(b=>b.setVoiceCorrectionRemoteModel),m=es(),[d,h]=l.useState([]),[x,c]=l.useState(null),f=l.useCallback(()=>{window.electronAPI.memory.chatModels().then(h)},[]);l.useEffect(()=>(f(),window.electronAPI.memory.onChatModelProgress(b=>{c(b.done?null:b),b.done&&f()})),[f]);const u=d.find(b=>b.id===a)??null,p=d.map(b=>({value:b.id,label:b.id==="remote"?s("Remote (API model)"):`${b.label}${b.purpose?` · ${s("tuned for voice")}`:""} · ${xe(b.approxBytes)}`})),j=o?m.find(b=>b.id===o.providerId):void 0,v=j?.models.find(b=>b.id===o?.modelId),I=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(le,{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:b=>r(String(b)),children:[e.jsx(ae,{className:"w-64",children:e.jsx(re,{})}),e.jsx(oe,{children:p.map(b=>e.jsx(X,{value:b.value,children:b.label},b.value))})]})]}),u?.downloadable?e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:H("text-xs",u.state==="missing"?"text-destructive":"text-muted-foreground"),children:x?.modelId===u.id?`${xe(x.received)}${x.total?` / ${xe(x.total)}`:""}`:u.state==="ready"?s("Model downloaded"):u.state==="downloading"?s("Downloading…"):s("Not downloaded yet. Correction is skipped until it is.")}),e.jsx(di,{state:u.state,onDownload:()=>{I.downloadChatModel(u.id).then(f)},onCancel:()=>{I.cancelChatModelDownload(u.id).then(f)},onRemove:()=>{I.deleteChatModel(u.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:v?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:s("Follows the title-summary model"),side:"bottom",triggerClassName:Qe,onSelect:(b,k)=>i({providerId:b,modelId:k}),onReasoningChange:()=>{},onThinkingChange:()=>{}})})]})]}):null]}):null]})}function Gf(){const{t:s}=D(),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(le,{checked:t,onCheckedChange:n,"aria-label":s("Voice input"),className:"mt-1 shrink-0"})]}),t?e.jsxs(e.Fragment,{children:[e.jsx(Wf,{}),e.jsx(Bf,{}),e.jsx(Vf,{})]}):null]})}function Kf(){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!==Po&&i.deviceId!=="communications"))})};return r(),n.addEventListener("devicechange",r),()=>{a=!1,n.removeEventListener("devicechange",r)}},[]),s}function Wf(){const{t:s}=D(),t=g(o=>o.voiceInputDevice),n=g(o=>o.setVoiceInputDevice),a=Kf(),r=[{value:Po,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(X,{value:o.value,children:o.label},o.value))})]})]})}const Hf=32,qf=/^[A-Za-z0-9][A-Za-z0-9_:-]{0,127}$/,Yf=/^[A-Za-z_][A-Za-z0-9_]{0,31}$/,Jf=/\{\{\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 Xf(s,t){const n=[...new Set(s)].filter(a=>Yf.test(a)).map(a=>({kind:"arg",key:a,token:`{{args.${a}}}`}));return t>0&&n.push({kind:"prev",token:"{{prev}}"}),n}function Qf(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 Zf(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&&!qf.test(r)?null:{label:n,agentType:r,prompt:a}}function eg(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(Zf);return a.every(r=>r!==null)?{title:n,steps:a}:null}function sg(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(eg);return n.every(r=>r!==null)&&n.reduce((r,o)=>r+o.steps.length,0)<=Hf?{phases:n}:null}function ui(s){const t=[];let n=0;for(const a of s.matchAll(Jf))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 tg(s){const t=ui(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 ng({label:s,agentType:t,prompt:n}){const a=[`label: ${JSON.stringify(s)}`];return t&&a.push(`agentType: ${JSON.stringify(t)}`),` () => agent(${tg(n)}, { ${a.join(", ")} }),`}function mi(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(ng),"]));")}return t.push("","return prev;",""),t.join(`
24
- `)}async function ag(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 rg=32,Js=(s,t)=>Math.max(0,Math.min(s,t));function og(s){return s.phases.reduce((t,n)=>t+n.steps.length,0)<rg}function ig(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 lg(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 Cr(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 Sr(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 cg(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__",Ir=(s="scout")=>({label:"",agentType:s,prompt:""});function dg({value:s,tokens:t,args:n,onChange:a}){const{t:r}=D(),o=l.useRef(null),i=()=>o.current?.querySelector("textarea")??null,m=h=>{const x=i(),c=s.length,f=Qf(s,x?.selectionStart??c,x?.selectionEnd??c,h);a(f.text),requestAnimationFrame(()=>{x?.focus(),x?.setSelectionRange(f.cursor,f.cursor)})},d=h=>h.kind==="prev"?r("Previous phase output"):n.find(x=>x.key.trim()===h.key)?.label.trim()||h.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:h=>a(h.target.value)}),e.jsxs(Co,{children:[e.jsxs(So,{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(Vd,{className:"h-3.5 w-3.5"}),r("Insert argument")]}),e.jsx(Io,{align:"start",zIndex:is.DROPDOWN_IN_MODAL,finalFocus:i,children:t.map(h=>e.jsxs(Ao,{onClick:()=>m(h.token),children:[d(h),e.jsx("span",{className:"ml-auto pl-4 font-mono text-muted-foreground text-xs",children:h.token})]},h.token))})]})]})}const Ar=(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 ug(s,t){const[n,a]=l.useState([]);return l.useLayoutEffect(()=>{const r=s.current;if(!r)return;const o=()=>{const m=r.getBoundingClientRect(),d=r.offsetWidth?m.width/r.offsetWidth:1,h=f=>{const u=r.querySelector(f)?.getBoundingClientRect();return u?{left:(u.left-m.left)/d,right:(u.right-m.left)/d,y:(u.top-m.top+u.height/2)/d}:null},x=(f,u)=>f<0||f>=t.phases.length?[`[data-node="${u}"]`]:(t.phases[f]?.steps??[]).map((p,j)=>`[data-node="s-${f}-${j}"]`),c=[];for(let f=0;f<=t.phases.length;f++){const u=h(`[data-gap="${f}"]`);if(u){for(const p of x(f-1,"start")){const j=h(p);j&&c.push({d:Ar(j.right,j.y,u.left,u.y),arrow:!1})}for(const p of x(f,"end")){const j=h(p);j&&c.push({d:Ar(u.right,u.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 Er({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 mg({prompt:s,args:t}){const{t:n}=D(),a=ui(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 xg({design:s,agentTypes:t,args:n,onChange:a}){const{t:r}=D(),[o,i]=l.useState({kind:"step",phase:0,step:0}),m=l.useRef(null),d=l.useId(),h=ug(m,s),x=s.phases,c=cg(s,o),f=x[c.phase],u=c.kind==="step"?f?.steps[c.step]:void 0,p=t.includes("scout")?"scout":"",j=n.map(P=>P.key.trim()).filter(Boolean),v=og(s),I=Cr(s,c)!==null,b=P=>{P&&(a(P.design),i(P.selection))},k=P=>a({phases:x.map((z,M)=>M===c.phase?{...z,...P}:z)}),C=P=>c.kind==="step"&&k({steps:(f?.steps??[]).map((z,M)=>M===c.step?{...z,...P}:z)}),R=P=>{const z=P&&!t.includes(P)?[...t,P]:t;return[{value:sn,label:r("Default (worker)")},...z.map(M=>({value:M,label:M}))]},B=P=>e.jsx("div",{className:"flex w-10 shrink-0 items-center justify-center self-stretch",children:e.jsx("button",{type:"button","data-gap":P,disabled:!v,"aria-label":r("Insert phase here"),title:r("Insert phase here"),onClick:()=>b(lg(s,P,{title:"",steps:[Ir(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(Me,{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:d,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"})})}),h.map(P=>e.jsx("path",{d:P.d,fill:"none",stroke:"currentColor",strokeWidth:1.25,markerEnd:P.arrow?`url(#${d})`:void 0},P.d))]}),e.jsx(Er,{node:"start",icon:e.jsx($d,{className:"h-3 w-3"}),title:r("Start"),detail:j.length>0?j.join(", "):r("No arguments")}),x.map((P,z)=>e.jsxs(l.Fragment,{children:[B(z),e.jsxs("div",{className:H("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===z&&"border-primary border-solid"),children:[e.jsxs("button",{type:"button",onClick:()=>i({kind:"phase",phase:z}),className:H("flex min-w-0 items-center gap-1 rounded px-1 text-left text-[11px] hover:text-foreground",P.title.trim()?"text-muted-foreground":"text-destructive"),children:[e.jsx("span",{className:"shrink-0",children:r("Phase {{n}}",{n:z+1})}),e.jsx("span",{className:"truncate font-medium text-foreground",children:P.title.trim()||r("Untitled phase")})]}),P.steps.map((M,A)=>{const S=c.kind==="step"&&c.phase===z&&c.step===A,K=!M.label.trim()||!M.prompt.trim();return e.jsxs("button",{type:"button","data-node":`s-${z}-${A}`,onClick:()=>i({kind:"step",phase:z,step:A}),className:H("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",K&&!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:M.label.trim()||r("Untitled step")}),e.jsx("span",{className:"ml-auto shrink-0 rounded bg-muted px-1 text-[10px] text-muted-foreground",children:M.agentType||"worker"})]}),e.jsx("span",{className:"mt-0.5 line-clamp-2 break-words text-[11px] text-muted-foreground",children:e.jsx(mg,{prompt:M.prompt,args:n})})]},A)}),e.jsxs("button",{type:"button",disabled:!v,onClick:()=>b(ig(s,z,Ir(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(Me,{className:"h-3 w-3"}),r("Parallel step")]})]})]},z)),B(x.length),e.jsx(Er,{node:"end",icon:e.jsx(Eu,{className:"h-3 w-3"}),title:r("Result"),detail:r("Last phase output")})]})}),e.jsxs("div",{className:"space-y-2 rounded-lg border p-3",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"font-medium text-xs",children: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:()=>b(Sr(s,c.phase,-1)),children:e.jsx(fo,{})}),e.jsx(y,{variant:"ghost",size:"icon-xs","aria-label":r("Move right"),disabled:c.phase===x.length-1,onClick:()=>b(Sr(s,c.phase,1)),children:e.jsx(Ud,{})})]}),e.jsx(y,{variant:"ghost",size:"icon-xs","aria-label":r("Delete"),disabled:!I,onClick:()=>b(Cr(s,c)),children:e.jsx(Ee,{})})]})]}),c.kind==="phase"||!u?e.jsx(Y,{size:"sm",placeholder:r("Phase title"),value:f?.title??"",onChange:P=>k({title:P.target.value})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Y,{size:"sm",className:"min-w-0 flex-1",placeholder:r("Label"),value:u.label,onChange:P=>C({label:P.target.value})}),e.jsxs(ne,{items:R(u.agentType),value:u.agentType||sn,onValueChange:P=>C({agentType:P===sn?"":String(P??"")}),children:[e.jsx(ae,{size:"sm",className:"w-36 min-w-0 shrink-0",children:e.jsx(re,{})}),e.jsx(oe,{zIndex:is.DROPDOWN_IN_MODAL,children:R(u.agentType).map(P=>e.jsx(X,{value:P.value,children:P.label},P.value))})]})]}),e.jsx(dg,{value:u.prompt,tokens:Xf(j,c.phase),args:n,onChange:P=>C({prompt:P})})]})]}),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}}`}]}]},Pr={name:"",description:"",args:[{key:"topic",label:"Topic",required:!0}],design:jn,script:mi(jn)};function hg(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 pg({target:s,onClose:t,onSaved:n}){const{t:a}=D(),[r,o]=l.useState(Pr),[i,m]=l.useState("design"),[d,h]=l.useState(0),x=l.useRef(null),[c,f]=l.useState(!1),[u,p]=l.useState(!1),[j,v]=l.useState(!1),[I,b]=l.useState(null),k=g(N=>N.disabledBuiltinAgentTypes),C=g(N=>N.agentTypes),R=l.useMemo(()=>[...Gd.map(N=>N.name).filter(N=>!k.includes(N)),...C.map(N=>N.name)],[k,C]);l.useEffect(()=>{if(b(null),s===null)return;if(x.current=null,h(L=>L+1),s==="new"){o(Pr),m("design");return}let N=!1;return f(!0),window.electronAPI.workflowPresets.read(s).then(L=>{if(!N)if(L){const{id:V,...$}=L;o($),m($.design?"design":"code"),h(O=>O+1)}else b(a("Failed to read content"))}).finally(()=>{N||f(!1)}),()=>{N=!0}},[s,a]);const B=N=>o(L=>({...L,...N})),P=(N,L)=>B({args:r.args.map((V,$)=>$===N?{...V,...L}:V)}),z=N=>B({design:N,script:mi(N)}),M=N=>{N!==r.script&&(r.design&&(x.current=r.design),o(L=>({...L,script:N,design:void 0})))},A=async()=>{v(!0);const N=await ag(r.script);if(v(!1),!N.ok){b(a("Format failed: {{error}}",{error:N.error}));return}b(null),N.code!==r.script&&(M(N.code),h(L=>L+1))},S=!r.design||sg(r.design)!==null,K=!c&&!u&&r.name.trim()!==""&&r.description.trim()!==""&&S&&r.script.trim()!=="",q=async()=>{if(!K||s===null)return;p(!0);const N=await window.electronAPI.workflowPresets.save({...r,args:hg(r.args)},s==="new"?void 0:s);if(p(!1),!N.ok){b(a(N.error));return}n(),t()};return e.jsx(je,{open:s!==null,onOpenChange:N=>!N&&t(),children:e.jsxs(ve,{className:"max-w-4xl",children:[e.jsx(be,{children:e.jsx(ye,{children:a(s==="new"?"Add workflow preset":"Edit workflow preset")})}),e.jsxs(we,{className:"space-y-4",children:[e.jsxs(he,{children:[e.jsx(pe,{children:a("Name")}),e.jsx(Y,{value:r.name,onChange:N=>B({name:N.target.value})})]}),e.jsxs(he,{children:[e.jsx(pe,{children:a("Description")}),e.jsx(Y,{value:r.description,onChange:N=>B({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,L)=>e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Y,{size:"sm",className:"w-28 font-mono",placeholder:"key",value:N.key,onChange:V=>P(L,{key:V.target.value})}),e.jsx(Y,{size:"sm",className:"flex-1",placeholder:a("Label"),value:N.label,onChange:V=>P(L,{label:V.target.value})}),e.jsx(Y,{size:"sm",className:"flex-1",placeholder:a("Default value"),value:N.default??"",onChange:V=>P(L,{default:V.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:V=>P(L,{required:V===!0})}),a("Required")]}),e.jsx(y,{variant:"ghost",size:"icon-xs","aria-label":a("Remove"),onClick:()=>B({args:r.args.filter((V,$)=>$!==L)}),children:e.jsx(vs,{})})]},L)),e.jsxs(y,{variant:"outline",size:"xs",disabled:r.args.length>=8,onClick:()=>B({args:[...r.args,{key:"",label:""}]}),children:[e.jsx(Me,{}),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:A,children:[j?e.jsx(Ae,{className:"animate-spin"}):e.jsx(Kd,{}),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(Ae,{className:"h-4 w-4 animate-spin text-muted-foreground"})}):i==="design"?r.design?e.jsx(xg,{design:r.design,agentTypes:R,args:r.args,onChange:z}):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:()=>z(x.current??jn),children:a("Use the designer")})]}):e.jsx(Wo,{fileName:"workflow.js",className:"h-80",value:r.script,epoch:d,onChange:M}),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.")})]}),I&&e.jsxs("p",{className:"flex items-center gap-1.5 text-destructive text-xs",children:[e.jsx(Ds,{className:"h-3.5 w-3.5 shrink-0"}),I]})]}),e.jsxs(Ie,{children:[e.jsx(y,{variant:"outline",size:"sm",onClick:t,children:a("Cancel")}),e.jsxs(y,{size:"sm",disabled:!K,onClick:q,children:[u&&e.jsx(Ae,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}),a("Save")]})]})]})})}function fg(){const{t:s}=D(),[t,n]=l.useState([]),[a,r]=l.useState(null),o=g(x=>x.disabledWorkflowPresets),i=g(x=>x.toggleWorkflowPreset),m=l.useCallback(()=>{window.electronAPI.workflowPresets.list().then(n)},[]);l.useEffect(m,[m]);const d=t.filter(x=>x.source!=="builtin"),h=t.filter(x=>x.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(Me,{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")}),d.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:d.map(x=>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.${x.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:x.name}),e.jsx(se,{variant:"secondary",className:"shrink-0 font-mono text-[11px]",children:x.id})]}),e.jsx("p",{className:"truncate text-muted-foreground text-xs",children:x.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(x.id),children:e.jsx(ms,{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(x.id).then(m)},children:e.jsx(Ee,{className:"h-3.5 w-3.5"})})]})]},x.id))})]}),h.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:h.map(x=>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.${x.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(x.name)}),e.jsx(se,{variant:"secondary",className:"shrink-0 font-mono text-[11px]",children:x.id})]}),e.jsx("p",{className:"text-muted-foreground text-xs",children:s(x.description)}),x.args.length>0&&e.jsxs("p",{className:"mt-0.5 text-muted-foreground text-xs",children:[s("Arguments"),":"," ",x.args.map(c=>`${s(c.label)}${c.required?" *":""}`).join(" · ")]})]}),e.jsx(le,{"aria-label":s(x.name),checked:!o.includes(x.id),onCheckedChange:c=>i(x.id,c)})]},x.id))})]}),e.jsx(pg,{target:a,onClose:()=>r(null),onSaved:m})]})}function gg(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 Mr(){const{t:s}=D(),[t,n]=l.useState("general"),[a,r]=l.useState(null),[o,i]=l.useState(null),[m,d]=l.useState(null),[h,x]=l.useState(0),c=Wd(),[f,u]=l.useState(!0),[p,j]=l.useState(""),[v,I]=l.useState([]),b=O=>{n(O),u(!1)},k=g(O=>O.disabledBuiltinTools),C=g(O=>O.botModeEnabled),R=g(O=>O.secretaryEnabled),B=l.useSyncExternalStore(O=>g.persist?.onFinishHydration?.(O)??(()=>{}),()=>g.persist?.hasHydrated?.()??!0),P=l.useCallback(O=>{n(O.category),u(!1),r(O.rowId),O.pluginInstallUrl&&i(O.pluginInstallUrl),d(O.pluginId??null)},[]);l.useEffect(()=>(window.electronAPI.window.consumeSettingsDeepLink().then(O=>{O&&P(O)}),window.electronAPI.window.onSettingsDeepLink(P)),[P]),l.useEffect(()=>{let O=!0;return window.electronAPI.sshConnections.list().then(te=>{O&&I(te.map(G=>({id:G.id,name:G.name})))}).catch(()=>{O&&I([])}),()=>{O=!1}},[]);const z=Hd(v);l.useLayoutEffect(()=>{if(!a)return;gg(a);const O=window.setTimeout(()=>r(null),1600);return()=>window.clearTimeout(O)},[a]);const A=vf([{id:"general",icon:Qd,label:"General"},{id:"shortcuts",icon:Zd,label:"Shortcuts"},{id:"voice",icon:eu,label:"Voice input"},{id:"appearance",icon:zu,label:"Appearance"},{id:"providers",icon:_n,label:"Model Providers"},{id:"presets",icon:su,label:"Presets"},{id:"agents",icon:tu,label:"Agent types"},{id:"tools",icon:eo,label:"Built-in tools"},{id:"workflows",icon:Dn,label:"Workflows"},{id:"memory",icon:Qr,label:"Memory"},{id:"privacy",icon:nu,label:"Privacy"},{id:"skills",icon:Eo,label:"Skills"},{id:"plugins",icon:Xs,label:"Enso plugins"},{id:"claudePlugins",icon:gu,label:"Claude Code plugins"},{id:"mcp",icon:co,label:"MCP Servers"},{id:"instructions",icon:Ln,label:"Instruction Files"},{id:"phone",icon:an,label:"Devices"},{id:"ssh",icon:Gr,label:"SSH"},{id:"usage",icon:Nu,label:"Usage"},{id:"resources",icon:au,label:"Resources"},{id:"experimental",icon:ru,label:"Experimental"},{id:"bots",icon:ou,label:"Bot mode",sub:!0},{id:"botTemplates",icon:iu,label:"Bot templates",sub:!0},{id:"secretary",icon:lu,label:"Secretary",sub:!0}],k,C,R||!B),S=jf(yf(A,z,p,s)),K=bf(t,k,C||!B,R||!B);l.useEffect(()=>{K!==t&&n(K)},[K,t]);const q=!c||f,N=!c||!f,L=A.find(O=>O.id===t)?.label,V=qd(),$=Mo();return e.jsxs("div",{className:"flex h-full w-full",children:[q&&e.jsxs("nav",{"data-enso":"settings-nav",className:H("flex min-h-0 shrink-0 flex-col",c?"w-full":V?"w-56":"w-56 border-r"),children:[V&&$==="mac"&&e.jsx("div",{"aria-hidden":!0,className:"drag-region -mb-2 h-[44px] shrink-0"}),e.jsx("div",{className:H("sticky top-0 z-10 px-2 pt-2",!V&&"bg-background"),children:e.jsxs("div",{className:"relative",children:[e.jsx(Zr,{className:"pointer-events-none absolute top-1/2 left-2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),e.jsx("input",{value:p,onChange:O=>j(O.target.value),onKeyDown:O=>{O.key!=="Escape"||p.length===0||(O.preventDefault(),O.stopPropagation(),j(""))},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:p.trim()&&S.length===0?e.jsx("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:s("No results")}):S.map((O,te)=>e.jsxs("div",{className:H(te>0&&"mt-4"),children:[e.jsx("div",{className:"px-2 pb-1.5 text-xs font-semibold text-foreground/55",children:s(O.label)}),e.jsx("div",{className:"space-y-0.5 rounded-lg bg-muted/60 p-1",children:O.items.map(G=>e.jsxs("div",{children:[e.jsxs("button",{type:"button",onClick:()=>b(G.id),className:H("flex w-full items-center gap-2 rounded-md px-3 text-sm transition-colors",c?"py-3":"py-1.5",G.sub&&"pl-8",t===G.id&&!c?"bg-background text-foreground shadow-xs":"text-muted-foreground hover:bg-background/60 hover:text-foreground"),children:[e.jsx(G.icon,{className:"h-4 w-4"}),s(G.label),c&&e.jsx(zs,{className:"ml-auto h-4 w-4 opacity-60"})]}),G.hits.map(J=>e.jsx("button",{type:"button",onClick:()=>{b(G.id),r(J.id)},className:H("block w-full truncate rounded-md pr-3 text-left text-xs text-muted-foreground hover:bg-background/60 hover:text-foreground",G.sub?"pl-14":"pl-9",c?"py-2":"py-1"),children:s(J.title)},J.id))]},G.id))})]},O.id))})]}),N&&e.jsxs("div",{"data-enso":"settings-content",className:H("flex min-w-0 flex-1 flex-col",V&&"my-[8px] mr-[8px] overflow-hidden rounded-[10px] bg-background shadow-surface"),children:[V&&e.jsx(Yd,{"data-enso":"title-bar"}),e.jsxs("div",{className:H("min-h-0 flex-1 overflow-y-auto",c?"px-4 pb-6":V?"px-6 pb-6":"p-6"),children:[c&&e.jsxs("button",{type:"button",onClick:()=>u(!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(Wr,{className:"h-5 w-5 text-muted-foreground"}),L?s(L):null]}),t==="general"&&e.jsx(Em,{}),t==="shortcuts"&&e.jsx($x,{}),t==="appearance"&&e.jsx(ax,{onOpenPlugins:()=>b("plugins")}),t==="providers"&&e.jsx(Kp,{}),t==="skills"&&e.jsx(xf,{}),t==="plugins"&&e.jsx(Cp,{requestedInstallUrl:o,onRequestedInstallUrlConsumed:()=>i(null),focusPluginId:m,onFocusPluginConsumed:()=>d(null)}),t==="claudePlugins"&&e.jsx(Ap,{}),t==="mcp"&&e.jsx(uh,{}),t==="instructions"&&e.jsx(Bx,{}),t==="presets"&&e.jsx(Jd,{}),t==="agents"&&e.jsx(Xd,{}),t==="workflows"&&e.jsx(fg,{}),t==="tools"&&e.jsx(Ex,{}),t==="memory"&&e.jsxs("div",{className:"space-y-8",children:[e.jsx(rp,{onLibraryChanged:()=>x(O=>O+1)}),e.jsx(kh,{revision:h}),e.jsx(Fh,{revision:h})]}),t==="phone"&&e.jsx(Tx,{}),t==="ssh"&&e.jsx(hf,{}),t==="usage"&&e.jsx(zf,{}),t==="privacy"&&e.jsx(Dp,{}),t==="resources"&&e.jsx(Qp,{}),t==="voice"&&e.jsx(Gf,{}),t==="experimental"&&e.jsx(_x,{onOpenBots:()=>n("bots")}),t==="bots"&&e.jsx(ux,{}),t==="botTemplates"&&e.jsx(vx,{}),t==="secretary"&&e.jsx(mf,{})]})]})]})}cu();du();function jg(){const{t:s}=D(),t=Mo();return t!=="mobile"&&t!=="web"?e.jsxs("div",{"data-enso":"canvas",className:"flex h-screen overflow-hidden bg-canvas",children:[e.jsx(ya,{}),e.jsx(mu.Provider,{value:{trailing:e.jsx(xu,{kind:t,edgeGap:8})},children:e.jsx(Mr,{})}),e.jsx(wa,{}),e.jsx(Na,{})]}):e.jsxs("div",{className:"flex h-screen flex-col overflow-hidden",children:[e.jsx(ya,{}),e.jsx(hu,{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(vs,{className:"h-4 w-4"})})}),e.jsx("main",{className:"min-h-0 flex-1 overflow-hidden",children:e.jsx(Mr,{})}),e.jsx(wa,{}),e.jsx(Na,{})]})}uu.createRoot(document.getElementById("root")).render(e.jsx(l.StrictMode,{children:e.jsx(jg,{})}));