@ensocode/server 0.3.9 → 0.3.10

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 (165) hide show
  1. package/out/phone/assets/{abnfDiagram-VCTEODGH-CBVQuFGg.js → abnfDiagram-VCTEODGH-DEIRKSmB.js} +1 -1
  2. package/out/phone/assets/architecture-7GRP2DOG-BQkxfRkk.js +1 -0
  3. package/out/phone/assets/{architectureDiagram-5GKGNRK7-Uwi4Yp3N.js → architectureDiagram-5GKGNRK7-CFZiReTQ.js} +1 -1
  4. package/out/phone/assets/{blockDiagram-I7D4REHJ-Dee88kBX.js → blockDiagram-I7D4REHJ-CIBal5Ke.js} +1 -1
  5. package/out/phone/assets/{c4Diagram-7LVT6UL2-CPVctMym.js → c4Diagram-7LVT6UL2-Ce7SCOHL.js} +1 -1
  6. package/out/phone/assets/channel-DGPU3seL.js +1 -0
  7. package/out/phone/assets/{chunk-4HAMMTFA-DdHZ8tzu.js → chunk-4HAMMTFA-COlQ1_VX.js} +1 -1
  8. package/out/phone/assets/{chunk-75Z2AOVW-CXd1zaQL.js → chunk-75Z2AOVW-L2CSsdYQ.js} +1 -1
  9. package/out/phone/assets/{chunk-DU6HZSFF-K72dP1XP.js → chunk-DU6HZSFF-juQC0nTX.js} +1 -1
  10. package/out/phone/assets/{chunk-F27PBJKO-JZyoOZLJ.js → chunk-F27PBJKO-CUQNf9_G.js} +1 -1
  11. package/out/phone/assets/{chunk-GMAD6QVW-O3x_QcGA.js → chunk-GMAD6QVW-BzsNlUWy.js} +1 -1
  12. package/out/phone/assets/{chunk-GVQU2GXP-g5OZYD2B.js → chunk-GVQU2GXP-a7Sg14KC.js} +1 -1
  13. package/out/phone/assets/{chunk-IMKFNOWR-r0ScpN_y.js → chunk-IMKFNOWR-B86isBFr.js} +1 -1
  14. package/out/phone/assets/{chunk-L3NEJ4N5-O-r4RmZJ.js → chunk-L3NEJ4N5-D9GQEj7C.js} +1 -1
  15. package/out/phone/assets/{chunk-OSK3NFVY-ramCCXI9.js → chunk-OSK3NFVY-ZHLE_p8D.js} +1 -1
  16. package/out/phone/assets/{chunk-P2QGCYS3-DD3uRJ3h.js → chunk-P2QGCYS3-CIqiw4vs.js} +1 -1
  17. package/out/phone/assets/{chunk-POPQ4Y6H-RiL5jwG6.js → chunk-POPQ4Y6H-pTX0vZo7.js} +1 -1
  18. package/out/phone/assets/{chunk-PWAF6VOD-YKF2LrOr.js → chunk-PWAF6VOD-BXK9ou77.js} +1 -1
  19. package/out/phone/assets/{chunk-SHT3W25Y-NK2MDUJG.js → chunk-SHT3W25Y-BLZNPdt8.js} +1 -1
  20. package/out/phone/assets/{chunk-SVP7TREG-7bCZBtZP.js → chunk-SVP7TREG-wR8iPcjt.js} +1 -1
  21. package/out/phone/assets/{chunk-TICWLB2K-DkVtQtfm.js → chunk-TICWLB2K-CueyYenv.js} +1 -1
  22. package/out/phone/assets/classDiagram-ZZMXUADV-DgtztyWS.js +1 -0
  23. package/out/phone/assets/classDiagram-v2-VYDZK3BY-DgtztyWS.js +1 -0
  24. package/out/phone/assets/{cynefin-OW5HDTMX-C3bBDDKw.js → cynefin-OW5HDTMX-LV70kdIp.js} +1 -1
  25. package/out/phone/assets/{cynefinDiagram-5FMLGOSQ-B1KRMzP2.js → cynefinDiagram-5FMLGOSQ-jSFJ3Ff1.js} +1 -1
  26. package/out/phone/assets/{dagre-GXQ25YYZ-NLxwj9wy.js → dagre-GXQ25YYZ-DnmK3Igj.js} +1 -1
  27. package/out/phone/assets/{desk-DfeUjqmj.js → desk-BLXfa62y.js} +1 -1
  28. package/out/phone/assets/{diagram-S7CK7UJ4-DfcfBkAs.js → diagram-S7CK7UJ4-KdmyjPOb.js} +1 -1
  29. package/out/phone/assets/{diagram-UQ7AKVKN-DCvI1s7K.js → diagram-UQ7AKVKN-D1D-C9ty.js} +1 -1
  30. package/out/phone/assets/{diagram-VSXAHHWV-Bm1zOS5P.js → diagram-VSXAHHWV-CO_oZjy2.js} +1 -1
  31. package/out/phone/assets/{diagram-VX7I27RA-BQuZufNO.js → diagram-VX7I27RA-VLBWCwXT.js} +1 -1
  32. package/out/phone/assets/{diagram-Z3DM3KII-DBIMQQh6.js → diagram-Z3DM3KII-wXmAYt0S.js} +1 -1
  33. package/out/phone/assets/{ebnfDiagram-PWID7BFC-tVvJnbJ2.js → ebnfDiagram-PWID7BFC-COmreC4F.js} +1 -1
  34. package/out/phone/assets/{erDiagram-RLTQ6QDP-BSiTfV80.js → erDiagram-RLTQ6QDP-YD40E3kV.js} +1 -1
  35. package/out/phone/assets/eventmodeling-NTZA5JFV-DdkbB0R7.js +1 -0
  36. package/out/phone/assets/flowDiagram-HODETNUW-B86UG3OY.js +1 -0
  37. package/out/phone/assets/{ganttDiagram-EL5Y4UJY-DTQdTWJN.js → ganttDiagram-EL5Y4UJY-CC0eW0wn.js} +1 -1
  38. package/out/phone/assets/{gitGraph-4MIJSDKK-DP-rU0q-.js → gitGraph-4MIJSDKK-BpKZk8Hu.js} +1 -1
  39. package/out/phone/assets/{gitGraphDiagram-WWUBYQGX-v56Bt0O6.js → gitGraphDiagram-WWUBYQGX-BCK9rLLJ.js} +1 -1
  40. package/out/phone/assets/{info-A6RAGUB7-CAQE0Hfy.js → info-A6RAGUB7-BKUEMrSk.js} +1 -1
  41. package/out/phone/assets/{infoDiagram-27XIBGKW-CSXtf5Fo.js → infoDiagram-27XIBGKW-6kVlxml9.js} +1 -1
  42. package/out/phone/assets/{ishikawaDiagram-5VMMS53U-CclPV6gG.js → ishikawaDiagram-5VMMS53U-36KijlM2.js} +1 -1
  43. package/out/phone/assets/{journeyDiagram-3NMN7TZE-BIkpYm1f.js → journeyDiagram-3NMN7TZE-B3r6-igU.js} +1 -1
  44. package/out/phone/assets/{kanban-definition-UXKFOSKX-yepY9S2l.js → kanban-definition-UXKFOSKX-DDJMJ3eD.js} +1 -1
  45. package/out/phone/assets/{line-BeTXpSNc.js → line-CRvTNHUs.js} +1 -1
  46. package/out/phone/assets/main-BU1pbfVw.css +1 -0
  47. package/out/phone/assets/{main-DW3B3ovc.js → main-C650ZDk2.js} +114 -114
  48. package/out/phone/assets/{mermaid-parser.core-nw37szCl.js → mermaid-parser.core-vpmsl7OW.js} +3 -3
  49. package/out/phone/assets/{mermaid.core-DdSdNZO_.js → mermaid.core-P6wqHn79.js} +4 -4
  50. package/out/phone/assets/{mindmap-definition-YA3MSWOX-CiQWyjG5.js → mindmap-definition-YA3MSWOX-C1Qj4NCg.js} +1 -1
  51. package/out/phone/assets/{packet-AYTQ26CC-MFESxWKw.js → packet-AYTQ26CC-dPa_bCkN.js} +1 -1
  52. package/out/phone/assets/{pegDiagram-XKGWAZYB-BM9Ofbc8.js → pegDiagram-XKGWAZYB-DP29zlwD.js} +1 -1
  53. package/out/phone/assets/{pie-WAS4IAKB-BX8j-oF_.js → pie-WAS4IAKB-B7gaGnZC.js} +1 -1
  54. package/out/phone/assets/{pieDiagram-E7YTZNPT-1KLqp5sl.js → pieDiagram-E7YTZNPT-BIv_DaLU.js} +1 -1
  55. package/out/phone/assets/{quadrantDiagram-AXDQQJYC-wqwWQyRe.js → quadrantDiagram-AXDQQJYC-BRD0SxVe.js} +1 -1
  56. package/out/phone/assets/{radar-RG4KPBEZ-jaQ0-Att.js → radar-RG4KPBEZ-DSXX0eGO.js} +1 -1
  57. package/out/phone/assets/{railroad-74A4TZTK-BBOWTcMX.js → railroad-74A4TZTK-CyBIlVYV.js} +1 -1
  58. package/out/phone/assets/railroad-abnf-HS5TGJTU-Ea30PClf.js +1 -0
  59. package/out/phone/assets/railroad-ebnf-LZEXJU2U-BAOLVW4i.js +1 -0
  60. package/out/phone/assets/railroad-peg-WCYAUIDC-DiLa9rTe.js +1 -0
  61. package/out/phone/assets/{railroadDiagram-O6MQD6OU-DJQ-7iWl.js → railroadDiagram-O6MQD6OU-DqLjIO9E.js} +1 -1
  62. package/out/phone/assets/{requirementDiagram-BXWQKSXE-D4dveBtm.js → requirementDiagram-BXWQKSXE-DXMysPAW.js} +1 -1
  63. package/out/phone/assets/{sankeyDiagram-P5KCCOFB-Xi3vzQcH.js → sankeyDiagram-P5KCCOFB-CvbRufzx.js} +1 -1
  64. package/out/phone/assets/{sequenceDiagram-WJ2MYXX4-DJu7wXTv.js → sequenceDiagram-WJ2MYXX4-CFMJYkK9.js} +1 -1
  65. package/out/phone/assets/{stateDiagram-D77RDMKH-BY7kdvUZ.js → stateDiagram-D77RDMKH-C--GDYGR.js} +1 -1
  66. package/out/phone/assets/stateDiagram-v2-MP3YSRHH-C87lzpXA.js +1 -0
  67. package/out/phone/assets/{swimlanes-42K2YHIH-CIxzAE5G.js → swimlanes-42K2YHIH-C_L9ypxQ.js} +1 -1
  68. package/out/phone/assets/swimlanesDiagram-VR7AAH4N-CPaJpMYE.js +8 -0
  69. package/out/phone/assets/{timeline-definition-24CTP7MA-e-O3IHwG.js → timeline-definition-24CTP7MA-BEk-ED-p.js} +1 -1
  70. package/out/phone/assets/{treeView-Q6P3EWNA-Bhtyuzk0.js → treeView-Q6P3EWNA-rolWZTr4.js} +1 -1
  71. package/out/phone/assets/{treemap-WGGIJYW6-B_tM9CqS.js → treemap-WGGIJYW6-CPWEaY39.js} +1 -1
  72. package/out/phone/assets/{vennDiagram-4TSXK5OY-9npu53KS.js → vennDiagram-4TSXK5OY-CqImR0EN.js} +1 -1
  73. package/out/phone/assets/{wardley-WFR3VGLG-Dtb3_st-.js → wardley-WFR3VGLG-CvTGA92O.js} +1 -1
  74. package/out/phone/assets/{wardleyDiagram-VM6X3IG4-DCBObiQg.js → wardleyDiagram-VM6X3IG4-D9eDqbbx.js} +1 -1
  75. package/out/phone/assets/{xychartDiagram-S5SC5T6Z-BAHqVoN1.js → xychartDiagram-S5SC5T6Z-DSenC7kX.js} +1 -1
  76. package/out/phone/desk.html +1 -1
  77. package/out/phone/index.html +2 -2
  78. package/out/renderer/assets/{abnfDiagram-VCTEODGH-ClaZATP-.js → abnfDiagram-VCTEODGH-D81xzDT1.js} +1 -1
  79. package/out/renderer/assets/{arc-B0Ue52gX.js → arc-ByHjKist.js} +1 -1
  80. package/out/renderer/assets/{architectureDiagram-5GKGNRK7-CbmNLvfJ.js → architectureDiagram-5GKGNRK7-Bw7RgtuP.js} +1 -1
  81. package/out/renderer/assets/{blockDiagram-I7D4REHJ-crBSO4mg.js → blockDiagram-I7D4REHJ-nNM7I115.js} +1 -1
  82. package/out/renderer/assets/{c4Diagram-7LVT6UL2-BhASES00.js → c4Diagram-7LVT6UL2-xixXJMhC.js} +1 -1
  83. package/out/renderer/assets/channel-C9jBFK-_.js +1 -0
  84. package/out/renderer/assets/{chunk-2Q5K7J3B-CCY1-54C.js → chunk-2Q5K7J3B-C0KzftkI.js} +1 -1
  85. package/out/renderer/assets/{chunk-5VM5RSS4-MmFztUTQ.js → chunk-5VM5RSS4-CuqKTpNC.js} +1 -1
  86. package/out/renderer/assets/{chunk-F27PBJKO-CemaMYDJ.js → chunk-F27PBJKO-DyZs2_AC.js} +1 -1
  87. package/out/renderer/assets/{chunk-IMKFNOWR-DctUdkub.js → chunk-IMKFNOWR-C7ktAo0J.js} +1 -1
  88. package/out/renderer/assets/{chunk-JWPE2WC7-DCjmZlft.js → chunk-JWPE2WC7-CZpmOwpA.js} +1 -1
  89. package/out/renderer/assets/{chunk-POPQ4Y6H-D-KxWwr4.js → chunk-POPQ4Y6H-CVFNZRTi.js} +1 -1
  90. package/out/renderer/assets/{chunk-SVP7TREG-CGc3VMbe.js → chunk-SVP7TREG-DhMMCFNi.js} +1 -1
  91. package/out/renderer/assets/{chunk-TICWLB2K-BwI6l28m.js → chunk-TICWLB2K-BsceTDhj.js} +1 -1
  92. package/out/renderer/assets/{chunk-XXDRQBXY-C3lgg1-4.js → chunk-XXDRQBXY-C_grf3wS.js} +1 -1
  93. package/out/renderer/assets/classDiagram-ZZMXUADV-B_o-oRUo.js +1 -0
  94. package/out/renderer/assets/classDiagram-v2-VYDZK3BY-B_o-oRUo.js +1 -0
  95. package/out/renderer/assets/{cose-bilkent-JH36ORCC-DqGFhKtY.js → cose-bilkent-JH36ORCC-wUQVmxx_.js} +1 -1
  96. package/out/renderer/assets/{cynefin-OW5HDTMX-BpknO3Y_.js → cynefin-OW5HDTMX-BR546Wt2.js} +1 -1
  97. package/out/renderer/assets/{cynefinDiagram-5FMLGOSQ-DS1vS0h7.js → cynefinDiagram-5FMLGOSQ-Dp2jJhbH.js} +1 -1
  98. package/out/renderer/assets/{cytoscape-fcose-DeHY1J1u.js → cytoscape-fcose-BJkAlKB8.js} +1 -1
  99. package/out/renderer/assets/{dagre-GXQ25YYZ-DxScp9AG.js → dagre-GXQ25YYZ-XKFl5kxK.js} +1 -1
  100. package/out/renderer/assets/{diagram-S7CK7UJ4-Djlu9ceY.js → diagram-S7CK7UJ4-BBFt2zKx.js} +1 -1
  101. package/out/renderer/assets/{diagram-UQ7AKVKN-BK3mHHvd.js → diagram-UQ7AKVKN-DA2CgkM2.js} +1 -1
  102. package/out/renderer/assets/{diagram-VSXAHHWV-Bg9tDRjc.js → diagram-VSXAHHWV-BL96nDcT.js} +1 -1
  103. package/out/renderer/assets/{diagram-VX7I27RA-DrWUeEXG.js → diagram-VX7I27RA-BYbjhI9j.js} +1 -1
  104. package/out/renderer/assets/{diagram-Z3DM3KII-BxPy8fU9.js → diagram-Z3DM3KII-BShKaR0Y.js} +1 -1
  105. package/out/renderer/assets/{ebnfDiagram-PWID7BFC-BWqMH4I8.js → ebnfDiagram-PWID7BFC-CxCXjhNE.js} +1 -1
  106. package/out/renderer/assets/{erDiagram-RLTQ6QDP-DTdklRgf.js → erDiagram-RLTQ6QDP-D6a85aJz.js} +1 -1
  107. package/out/renderer/assets/{flowDiagram-HODETNUW-BKIZ7ju6.js → flowDiagram-HODETNUW-D7vxYWv_.js} +1 -1
  108. package/out/renderer/assets/{ganttDiagram-EL5Y4UJY-BxvJsq6b.js → ganttDiagram-EL5Y4UJY-D4bniC42.js} +1 -1
  109. package/out/renderer/assets/{gitGraphDiagram-WWUBYQGX-CKYXaYvq.js → gitGraphDiagram-WWUBYQGX-DREOVv8G.js} +1 -1
  110. package/out/renderer/assets/{globals-kfeSrZZh.js → globals-1URrQWJU.js} +192 -192
  111. package/out/renderer/assets/globals-DoPyZAQo.css +1 -0
  112. package/out/renderer/assets/index-8xDwl1RO.js +133 -0
  113. package/out/renderer/assets/{infoDiagram-27XIBGKW-B79kbTEz.js → infoDiagram-27XIBGKW-iQi9WT0H.js} +1 -1
  114. package/out/renderer/assets/{ishikawaDiagram-5VMMS53U-7A2txHe5.js → ishikawaDiagram-5VMMS53U-CqPXH73H.js} +1 -1
  115. package/out/renderer/assets/{journeyDiagram-3NMN7TZE-JNKKQMwS.js → journeyDiagram-3NMN7TZE-DjEyHtge.js} +1 -1
  116. package/out/renderer/assets/{kanban-definition-UXKFOSKX-dK6zSfqM.js → kanban-definition-UXKFOSKX-D-bxhvRO.js} +1 -1
  117. package/out/renderer/assets/{layout-MfkXYuHA.js → layout-O4Dt9JSp.js} +1 -1
  118. package/out/renderer/assets/{linear-DUiegqFS.js → linear-B3fSR3zo.js} +1 -1
  119. package/out/renderer/assets/{mermaid.core-Dn6T9UVK.js → mermaid.core-DKfKek0K.js} +5 -5
  120. package/out/renderer/assets/{mindmap-definition-YA3MSWOX-Du0yA8rg.js → mindmap-definition-YA3MSWOX-CgWelgTn.js} +1 -1
  121. package/out/renderer/assets/{pegDiagram-XKGWAZYB-DaRtM-Te.js → pegDiagram-XKGWAZYB-6YROVnYK.js} +1 -1
  122. package/out/renderer/assets/{pieDiagram-E7YTZNPT-Bsf9CqyI.js → pieDiagram-E7YTZNPT-BboI-zql.js} +1 -1
  123. package/out/renderer/assets/{quadrantDiagram-AXDQQJYC-Diojakd2.js → quadrantDiagram-AXDQQJYC-Ckl9-8_q.js} +1 -1
  124. package/out/renderer/assets/{railroadDiagram-O6MQD6OU-BMREAMLm.js → railroadDiagram-O6MQD6OU-CBmldUiO.js} +1 -1
  125. package/out/renderer/assets/{requirementDiagram-BXWQKSXE-KYN9y0mn.js → requirementDiagram-BXWQKSXE-BhCPsXeE.js} +1 -1
  126. package/out/renderer/assets/{sankeyDiagram-P5KCCOFB-BOarV1lP.js → sankeyDiagram-P5KCCOFB-KCriZNRW.js} +1 -1
  127. package/out/renderer/assets/{sequenceDiagram-WJ2MYXX4-CLvIIq-e.js → sequenceDiagram-WJ2MYXX4-BZRpmnqw.js} +1 -1
  128. package/out/renderer/assets/{settings-C1ake4C5.js → settings-DbHps6fb.js} +3 -3
  129. package/out/renderer/assets/{sizeCapture-INFHLROL-BZp_C1e1.js → sizeCapture-INFHLROL-BHJ5WHSf.js} +1 -1
  130. package/out/renderer/assets/{stateDiagram-D77RDMKH-CZYezuvN.js → stateDiagram-D77RDMKH-DxHudD45.js} +1 -1
  131. package/out/renderer/assets/stateDiagram-v2-MP3YSRHH-C0JE59RO.js +1 -0
  132. package/out/renderer/assets/{swimlanes-42K2YHIH-BzLF-RZ8.js → swimlanes-42K2YHIH-D2ZZdZPU.js} +1 -1
  133. package/out/renderer/assets/swimlanesDiagram-VR7AAH4N-DJJObg42.js +8 -0
  134. package/out/renderer/assets/{timeline-definition-24CTP7MA-uG42f1oC.js → timeline-definition-24CTP7MA-D4FtI5C_.js} +1 -1
  135. package/out/renderer/assets/{vennDiagram-4TSXK5OY-DTog5Yh9.js → vennDiagram-4TSXK5OY-BVq6hKjH.js} +1 -1
  136. package/out/renderer/assets/{wardleyDiagram-VM6X3IG4-BgQ7fmC4.js → wardleyDiagram-VM6X3IG4-39qPSeSF.js} +1 -1
  137. package/out/renderer/assets/{xychartDiagram-S5SC5T6Z-BerG1RDT.js → xychartDiagram-S5SC5T6Z-IjWUG31x.js} +1 -1
  138. package/out/renderer/index.html +3 -3
  139. package/out/renderer/settings.html +4 -4
  140. package/out/renderer/web-preload.js +21 -21
  141. package/out/server/agent.js +2 -2
  142. package/out/server/chunks/{gpuBackendInstall-DUOvnlWd.js → gpuBackendInstall-DdJZ_JTr.js} +2 -2
  143. package/out/server/chunks/{loadProvider-79AJEjnd.js → loadProvider-BOW5-6B-.js} +2 -2
  144. package/out/server/chunks/{workflowPresets-Di8u79iQ.js → workflowPresets-BtFDIu9c.js} +14 -8
  145. package/out/server/index.js +36 -82
  146. package/package.json +1 -1
  147. package/out/phone/assets/architecture-7GRP2DOG-DOA5Bycz.js +0 -1
  148. package/out/phone/assets/channel-DKcROQS8.js +0 -1
  149. package/out/phone/assets/classDiagram-ZZMXUADV-CrpQDbmR.js +0 -1
  150. package/out/phone/assets/classDiagram-v2-VYDZK3BY-CrpQDbmR.js +0 -1
  151. package/out/phone/assets/eventmodeling-NTZA5JFV-DiyOQMrF.js +0 -1
  152. package/out/phone/assets/flowDiagram-HODETNUW-_UpaA-So.js +0 -1
  153. package/out/phone/assets/main-CGpGZfti.css +0 -1
  154. package/out/phone/assets/railroad-abnf-HS5TGJTU-DfD2cpkN.js +0 -1
  155. package/out/phone/assets/railroad-ebnf-LZEXJU2U-BAwl_fDM.js +0 -1
  156. package/out/phone/assets/railroad-peg-WCYAUIDC-MbpAQZum.js +0 -1
  157. package/out/phone/assets/stateDiagram-v2-MP3YSRHH-DDqCllzv.js +0 -1
  158. package/out/phone/assets/swimlanesDiagram-VR7AAH4N-Cu8_tU2m.js +0 -8
  159. package/out/renderer/assets/channel-DAEAroq1.js +0 -1
  160. package/out/renderer/assets/classDiagram-ZZMXUADV-BHNNTKj0.js +0 -1
  161. package/out/renderer/assets/classDiagram-v2-VYDZK3BY-BHNNTKj0.js +0 -1
  162. package/out/renderer/assets/globals-DoK2OLv9.css +0 -1
  163. package/out/renderer/assets/index-oWFcXlIg.js +0 -133
  164. package/out/renderer/assets/stateDiagram-v2-MP3YSRHH-BZR_zNTR.js +0 -1
  165. package/out/renderer/assets/swimlanesDiagram-VR7AAH4N-CguqA7f1.js +0 -8
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./globals-kfeSrZZh.js","./globals-DoK2OLv9.css"])))=>i.map(i=>d[i]);
2
- import{c as Oe,w as vi,D as ea,j as e,A as bi,r as l,u as Or,a as Dr,b as vn,d as Lr,t as zr,C as sa,e as K,I as J,f as yi,X as js,h as wi,i as Ni,Z as cs,k as ki,S as Ci,l as Si,m as Ii,n as Ai,o as Ei,p as R,q as g,B as y,s as ye,v as we,x as Ne,y as ke,z as Ye,E as Ce,F as Le,G as Ee,H as _r,J as Te,K as ta,L as Mi,M as ut,N as mt,O as ne,P as ae,Q as re,R as oe,T as Z,U as Pi,V as Ze,W as Ti,Y as Ri,_ as Fr,$ as Oi,a0 as Rt,a1 as Br,a2 as Di,a3 as Ur,a4 as Li,a5 as na,a6 as $r,a7 as zi,a8 as _i,a9 as Fi,aa,ab as Bi,ac as Ui,ad as $i,ae as Vi,af as Gi,ag as Ki,ah as Wi,ai as Hi,aj as qi,ak as Yi,al as Ji,am as Ot,an as Xi,ao as Qi,ap as Zi,aq as el,ar as sl,as as tl,at as Me,au as bn,av as pt,aw as $e,ax as Vr,ay as Ms,az as Ve,aA as Ke,aB as yn,aC as Rs,aD as wn,aE as Nn,aF as kn,aG as Cn,aH as Sn,aI as In,aJ as An,aK as es,aL as ra,aM as oa,aN as ze,aO as Qe,aP as nl,aQ as al,aR as Gr,aS as ce,aT as ia,aU as Dt,aV as la,aW as ca,aX as ft,aY as rl,aZ as ol,a_ as Lt,a$ as Xs,b0 as Kr,b1 as En,b2 as il,b3 as Mn,b4 as Wr,b5 as ll,b6 as cl,b7 as dl,b8 as Hr,b9 as ul,ba as ml,bb as xl,bc as qr,bd as Ds,be as rt,bf as hl,bg as Pn,bh as pl,bi as fl,bj as Tn,bk as ns,bl as gl,bm as jl,bn as Yr,bo as vl,bp as bl,bq as yl,br as Jr,bs as Rn,bt as Re,bu as se,bv as Pe,bw as wl,bx as Nl,by as kl,bz as Cl,bA as Sl,bB as da,bC as Il,bD as Al,bE as Qs,bF as Zs,bG as Je,bH as Ws,bI as tn,bJ as El,bK as Ml,bL as nn,bM as hs,bN as Xr,bO as Pl,bP as Tl,bQ as On,bR as Rl,bS as ua,bT as Qr,bU as Ol,bV as Dl,bW as Zr,bX as Ge,bY as Ll,bZ as gt,b_ as zl,b$ as ma,c0 as _l,c1 as Fl,c2 as Bl,c3 as Xe,c4 as Ul,c5 as xa,c6 as ha,c7 as $l,c8 as pa,c9 as Vl,ca as Gl,cb as Kl,cc as Wl,cd as We,ce as zt,cf as fa,cg as Hl,ch as ql,ci as eo,cj as Yl,ck as so,cl as Jl,cm as Xl,cn as Ql,co as Zl,cp as Dn,cq as ec,cr as to,cs as sc,ct as tc,cu as et,cv as nc,cw as ac,cx as rc,cy as oc,cz as an,cA as no,cB as ot,cC as ic,cD as lc,cE as cc,cF as he,cG as pe,cH as Nt,cI as Ln,cJ as ao,cK as zn,cL as ro,cM as rn,cN as ga,cO as on,cP as oo,cQ as io,cR as dc,cS as lo,cT as uc,cU as mc,cV as xc,cW as hc,cX as pc,cY as fc,cZ as gc,c_ as jc,c$ as vc,d0 as bc,d1 as ja,d2 as co,d3 as uo,d4 as mo,d5 as xo,d6 as yc,d7 as wc,d8 as va,d9 as Hs,da as Nc,db as ho,dc as po,dd as fo,de as kc,df as Cc,dg as Sc,dh as Ic,di as Ac,dj as Ec,dk as Mc,dl as Pc,dm as Tc,dn as Rc,dp as Oc,dq as Dc,dr as go,ds as xt,dt as Ps,du as jo,dv as Lc,dw as ba,dx as zc,dy as _c,dz as Fc,dA as Bc,dB as Uc,dC as $c,dD as Vc,dE as Gc,dF as Kc,dG as Wc,dH as Hc,dI as ln,dJ as qc,dK as jt,dL as Yc,dM as _n,dN as vo,dO as bo,dP as Fn,dQ as yo,dR as wo,dS as No,dT as ko,dU as Co,dV as Jc,dW as Xc,dX as Qc,dY as Zc,dZ as ed,d_ as sd,d$ as td,e0 as nd,e1 as ad,e2 as rd,e3 as od,e4 as id,e5 as ld,e6 as cd,e7 as dd,e8 as ud,e9 as md,ea as xd,eb as hd,ec as So,ed as Io,ee as Ao,ef as pd,eg as Eo,eh as fd,ei as gd,ej as jd,ek as Mo,el as vd,em as bd,en as ya,eo as it,ep as yd,eq as wd,er as Nd,es as kd,et as Cd,eu as Sd,ev as wa,ew as Id,ex as Ad,ey as Ed,ez as Md,eA as Pd,eB as Td,eC as Rd,eD as Po,eE as Od,eF as Dd,eG as Ld,eH as vt,eI as zd,eJ as _d,eK as Fd,eL as Bd,eM as us,eN as Ud,eO as To,eP as $d,eQ as Vd,eR as Gd,eS as Kd,eT as Wd,eU as Hd,eV as qd,eW as Yd,eX as Jd,eY as Ro,eZ as Xd,e_ as Qd,e$ as Zd,f0 as eu,f1 as su,f2 as tu,f3 as nu,f4 as au,f5 as ru,f6 as ou,f7 as iu,f8 as lu,f9 as cu,fa as du,fb as uu,fc as mu,fd as xu,fe as Na,ff as hu,fg as pu,fh as ka,fi as Ca,fj as fu}from"./globals-kfeSrZZh.js";import{c as Oo}from"./cytoscape.esm-DzSz-X2X.js";import{f as gu}from"./cytoscape-fcose-DeHY1J1u.js";const ju=[["path",{d:"M10 22V7a1 1 0 0 0-1-1H4a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-5a1 1 0 0 0-1-1H2",key:"1ah6g2"}],["rect",{x:"14",y:"2",width:"8",height:"8",rx:"1",key:"88lufb"}]],vu=Oe("blocks",ju);const bu=[["path",{d:"M12 5v16",key:"1f6ucr"}],["path",{d:"M20.001 19A2 2 0 0022 17V5a2 2 0 00-1.999-2L16 3.002A5 5 0 0012 5a5 5 0 00-4-2H4a2 2 0 00-2 2v12a2 2 0 001.999 2H8a5 5 0 014 2 5 5 0 014-2z",key:"1fyvmf"}]],yu=Oe("book-open",bu);const wu=[["path",{d:"M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z",key:"hh9hay"}],["path",{d:"m3.3 7 8.7 5 8.7-5",key:"g66t2b"}],["path",{d:"M12 22V12",key:"d0xqtd"}]],Nu=Oe("box",wu);const ku=[["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["path",{d:"M18 17V9",key:"2bz60n"}],["path",{d:"M13 17V5",key:"1frdt8"}],["path",{d:"M8 17v-3",key:"17ska0"}]],Cu=Oe("chart-column",ku);const Su=[["path",{d:"M13.659 22H18a2 2 0 0 0 2-2V8a2.4 2.4 0 0 0-.706-1.706l-3.588-3.588A2.4 2.4 0 0 0 14 2H6a2 2 0 0 0-2 2v11.5",key:"4pqfef"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M8 12v-1",key:"1ej8lb"}],["path",{d:"M8 18v-2",key:"qcmpov"}],["path",{d:"M8 7V6",key:"1nbb54"}],["circle",{cx:"8",cy:"20",r:"2",key:"ckkr5m"}]],Iu=Oe("file-archive",Su);const Au=[["path",{d:"M14.364 13.634a2 2 0 0 0-.506.854l-.837 2.87a.5.5 0 0 0 .62.62l2.87-.837a2 2 0 0 0 .854-.506l4.013-4.009a1 1 0 0 0-3.004-3.004z",key:"ukzhwg"}],["path",{d:"M14.487 7.858A1 1 0 0 1 14 7V2",key:"1klhew"}],["path",{d:"M20 19.645V20a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l2.516 2.516",key:"rxaxab"}],["path",{d:"M8 18h1",key:"13wk12"}]],Eu=Oe("file-pen-line",Au);const Mu=[["path",{d:"M4 22V4a1 1 0 0 1 .4-.8A6 6 0 0 1 8 2c3 0 5 2 7.333 2q2 0 3.067-.8A1 1 0 0 1 20 4v10a1 1 0 0 1-.4.8A6 6 0 0 1 16 16c-3 0-5-2-8-2a6 6 0 0 0-4 1.528",key:"1jaruq"}]],Pu=Oe("flag",Mu);const Tu=[["path",{d:"M12 22v-6",key:"6o8u61"}],["path",{d:"M12 8V2",key:"1wkif3"}],["path",{d:"M4 12H2",key:"rhcxmi"}],["path",{d:"M10 12H8",key:"s88cx1"}],["path",{d:"M16 12h-2",key:"10asgb"}],["path",{d:"M22 12h-2",key:"14jgyd"}],["path",{d:"m15 19-3-3-3 3",key:"e37ymu"}],["path",{d:"m15 5-3 3-3-3",key:"19d6lf"}]],Ru=Oe("fold-vertical",Tu);const Ou=[["path",{d:"M2 9.5a5.5 5.5 0 0 1 9.591-3.676.56.56 0 0 0 .818 0A5.49 5.49 0 0 1 22 9.5c0 2.29-1.5 4-3 5.5l-5.492 5.313a2 2 0 0 1-3 .019L5 15c-1.5-1.5-3-3.2-3-5.5",key:"mvr1a0"}]],Sa=Oe("heart",Ou);const Du=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}]],Lu=Oe("image",Du);const zu=[["circle",{cx:"12",cy:"16",r:"1",key:"1au0dj"}],["rect",{x:"3",y:"10",width:"18",height:"12",rx:"2",key:"6s8ecr"}],["path",{d:"M7 10V7a5 5 0 0 1 10 0v3",key:"1pqi11"}]],Do=Oe("lock-keyhole",zu);const _u=[["path",{d:"M12 22a1 1 0 0 1 0-20 10 9 0 0 1 10 9 5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z",key:"e79jfc"}],["circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor",key:"1okk4w"}],["circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor",key:"f64h9f"}],["circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor",key:"qy21gx"}],["circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor",key:"fotxhn"}]],Fu=Oe("palette",_u);const Bu=[["path",{d:"m15 15 6 6m-6-6v4.8m0-4.8h4.8",key:"17vawe"}],["path",{d:"M9 19.8V15m0 0H4.2M9 15l-6 6",key:"chjx8e"}],["path",{d:"M15 4.2V9m0 0h4.8M15 9l6-6",key:"lav6yq"}],["path",{d:"M9 4.2V9m0 0H4.2M9 9 3 3",key:"1pxi2q"}]],Uu=Oe("shrink",Bu);const $u=[["path",{d:"M15 21v-5a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v5",key:"slp6dd"}],["path",{d:"M17.774 10.31a1.12 1.12 0 0 0-1.549 0 2.5 2.5 0 0 1-3.451 0 1.12 1.12 0 0 0-1.548 0 2.5 2.5 0 0 1-3.452 0 1.12 1.12 0 0 0-1.549 0 2.5 2.5 0 0 1-3.77-3.248l2.889-4.184A2 2 0 0 1 7 2h10a2 2 0 0 1 1.653.873l2.895 4.192a2.5 2.5 0 0 1-3.774 3.244",key:"o0xfot"}],["path",{d:"M4 10.95V19a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8.05",key:"wn3emo"}]],Vu=Oe("store",$u);const Gu=[["circle",{cx:"12",cy:"12",r:"4",key:"4exip2"}],["path",{d:"M12 2v2",key:"tus03m"}],["path",{d:"M12 20v2",key:"1lh1kg"}],["path",{d:"m4.93 4.93 1.41 1.41",key:"149t6j"}],["path",{d:"m17.66 17.66 1.41 1.41",key:"ptbguv"}],["path",{d:"M2 12h2",key:"1t8f8n"}],["path",{d:"M20 12h2",key:"1q8mjw"}],["path",{d:"m6.34 17.66-1.41 1.41",key:"1m8zz5"}],["path",{d:"m19.07 4.93-1.41 1.41",key:"1shlcs"}]],Ku=Oe("sun",Gu);const Wu=[["path",{d:"M12 3v12",key:"1x0j5s"}],["path",{d:"m17 8-5-5-5 5",key:"7q97r8"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}]],Lo=Oe("upload",Wu);function Hu(s){return s&&typeof s=="object"&&!Array.isArray(s)?s:null}function qu(s){try{const t=new URL(s);return(t.protocol==="http:"||t.protocol==="https:")&&!t.username&&!t.password&&!t.search&&!t.hash&&!s.includes("?")&&!s.includes("#")}catch{return!1}}function Yu(s){const t=Hu(s);if(!t||Object.keys(t).some(m=>!["providerId","modelId","protocol","baseUrl","apiKey"].includes(m)))return null;const{providerId:n,modelId:a,protocol:r,baseUrl:o,apiKey:i}=t;return typeof n!="string"||!n.trim()||typeof a!="string"||!a.trim()||typeof i!="string"||!i.trim()||typeof o!="string"||!qu(o)||r!=="openai"&&r!=="openai-compatible"&&r!=="gemini"?null:{providerId:n,modelId:a,protocol:r,baseUrl:o,apiKey:i}}function Ju(s,t){if(s?.enabled!==!0||s.oauthAccountKey||s.oauthAccountPool||typeof s.apiKey!="string"||!s.apiKey.trim()||typeof s.baseUrl!="string")return null;let n;if(s.api==="google-generative-ai")n="gemini";else if(s.api==="openai-completions"||s.api==="openai-responses"){let o="";try{o=new URL(s.baseUrl).hostname.toLowerCase()}catch{}n=s.catalogId!=="__custom"&&(s.catalogId==="openai"||!s.catalogId&&o==="api.openai.com")?"openai":"openai-compatible"}else return null;const a=n==="gemini"?ea["google-generative-ai"]:n==="openai"?ea["openai-responses"]:"";let r=s.baseUrl.trim().replace(/\/+$/,"")||a;if(n==="gemini"&&r&&(r=vi(r,"v1beta")),n==="openai"&&r)try{new URL(r).pathname==="/"&&(r=`${r}/v1`)}catch{}return Yu({providerId:s.id,modelId:t,protocol:n,baseUrl:r,apiKey:s.apiKey})}function Xu(s){return Array.isArray(s?.models)?s.models.filter(t=>!!t&&typeof t=="object"&&typeof t.id=="string"&&!!t.id.trim()&&t.enabled!==!1&&t.imageGeneration===!0):[]}function Qu(s){return s.flatMap(t=>{const n=Xu(t).filter(a=>Ju(t,a.id));return n.length?[{...t,models:n}]:[]})}function Zu(s){const{multiple:t=!1,defaultValue:n,value:a,onValueChange:r,autoComplete:o,...i}=s;return e.jsx(bi,{...i,selectionMode:t?"multiple":"single",selectedValue:a,defaultSelectedValue:n,onSelectedValueChange:r,formAutoComplete:o})}const em=l.forwardRef(function(t,n){const{selected:a}=Or();return t.keepMounted||a?e.jsx(sm,{...t,ref:n}):null}),sm=l.memo(l.forwardRef((s,t)=>{const{render:n,className:a,style:r,keepMounted:o,...i}=s,{selected:m}=Or(),u=l.useRef(null),{transitionStatus:x,setMounted:h}=Dr(m),f=vn("span",s,{ref:[t,u],state:{selected:m,transitionStatus:x},props:[{"aria-hidden":!0,children:"✔️"},i],stateAttributesMapping:zr});return Lr({open:m,ref:u,onComplete(){m||h(!1)}}),f})),Bn=l.createContext({chipsRef:null,multiple:!1,rootRef:null});function tm(s){const t=l.useRef(null),n=l.useRef(null);return e.jsx(Bn.Provider,{value:{chipsRef:t,multiple:!!s.multiple,rootRef:n},children:e.jsx("div",{ref:n,className:"contents",children:e.jsx(Zu,{...s})})})}function nm({className:s,showTrigger:t=!0,showClear:n=!1,startAddon:a,size:r,...o}){const{multiple:i}=l.useContext(Bn),m=r??"default";return i?e.jsx(sa,{className:K("min-w-12 flex-1 text-base outline-none sm:text-sm [[data-slot=combobox-chip]+&]:ps-0.5",m==="sm"?"ps-1.5":"ps-2",s),"data-size":typeof m=="string"?m:void 0,"data-slot":"combobox-input",size:typeof m=="number"?m:void 0,...o}):e.jsxs("div",{className:"relative w-full has-disabled:opacity-64",children:[a&&e.jsx("div",{"aria-hidden":"true",className:"[&_svg]:-mx-0.5 pointer-events-none absolute inset-y-0 start-px z-10 flex items-center ps-[calc(--spacing(3)-1px)] opacity-80 has-[+[data-size=sm]]:ps-[calc(--spacing(2.5)-1px)] [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4","data-slot":"combobox-start-addon",children:a}),e.jsx(sa,{className:K(a&&"data-[size=sm]:*:data-[slot=combobox-input]:ps-[calc(--spacing(7.5)-1px)] *:data-[slot=combobox-input]:ps-[calc(--spacing(8.5)-1px)] sm:data-[size=sm]:*:data-[slot=combobox-input]:ps-[calc(--spacing(7)-1px)] sm:*:data-[slot=combobox-input]:ps-[calc(--spacing(8)-1px)]",m==="sm"?"has-[+[data-slot=combobox-trigger],+[data-slot=combobox-clear]]:*:data-[slot=combobox-input]:pe-6.5":"has-[+[data-slot=combobox-trigger],+[data-slot=combobox-clear]]:*:data-[slot=combobox-input]:pe-7",s),"data-slot":"combobox-input",render:e.jsx(J,{className:"has-disabled:opacity-100",size:m}),...o}),t&&e.jsx(am,{className:K("-translate-y-1/2 absolute top-1/2 inline-flex size-8 shrink-0 cursor-pointer items-center justify-center rounded-md border border-transparent opacity-80 outline-none transition-opacity pointer-coarse:after:absolute pointer-coarse:after:min-h-11 pointer-coarse:after:min-w-11 hover:opacity-100 has-[+[data-slot=combobox-clear]]:hidden sm:size-7 [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",m==="sm"?"end-0":"end-0.5"),children:e.jsx(yi,{})}),n&&e.jsx(lm,{className:K("-translate-y-1/2 absolute top-1/2 inline-flex size-8 shrink-0 cursor-pointer items-center justify-center rounded-md border border-transparent opacity-80 outline-none transition-opacity pointer-coarse:after:absolute pointer-coarse:after:min-h-11 pointer-coarse:after:min-w-11 hover:opacity-100 has-[+[data-slot=combobox-clear]]:hidden sm:size-7 [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",m==="sm"?"end-0":"end-0.5"),children:e.jsx(js,{})})]})}function am({className:s,...t}){return e.jsx(Ai,{className:s,"data-slot":"combobox-trigger",...t})}function rm({className:s,children:t,sideOffset:n=4,zIndex:a,...r}){const{chipsRef:o,rootRef:i}=l.useContext(Bn);let m=cs.DROPDOWN;if(a!==void 0)m=a;else{const u=i?.current;u&&(u.closest('[data-slot="dialog-popup"] [data-slot="dialog-popup"]')?m=cs.DROPDOWN_IN_NESTED_MODAL:u.closest('[data-slot="dialog-popup"]')&&(m=cs.DROPDOWN_IN_MODAL))}return e.jsx(wi,{children:e.jsx(Ni,{anchor:o,className:"select-none",style:{zIndex:m},"data-slot":"combobox-positioner",sideOffset:n,children:e.jsx("span",{className:K("relative flex max-h-full origin-(--transform-origin) rounded-lg border bg-popover bg-clip-padding transition-[scale,opacity] before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-lg)-1px)] before:shadow-lg has-data-starting-style:scale-98 has-data-starting-style:opacity-0 dark:not-in-data-[slot=group]:bg-clip-border",s),children:e.jsx(ki,{className:"flex max-h-[min(var(--available-height),23rem)] w-(--anchor-width) max-w-(--available-width) flex-col","data-slot":"combobox-popup",...r,children:t})})})})}function om({className:s,children:t,endAddon:n,...a}){return e.jsxs(Ii,{className:K("grid min-h-8 in-data-[side=none]:min-w-[calc(var(--anchor-width)+1.25rem)] cursor-default grid-cols-[1rem_1fr_auto] items-center gap-2 rounded-sm py-1 ps-2 pe-4 text-base outline-none data-disabled:pointer-events-none data-highlighted:bg-accent data-highlighted:text-accent-foreground data-disabled:opacity-64 sm:min-h-7 sm:text-sm [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",s),"data-slot":"combobox-item",...a,children:[e.jsx(em,{className:"col-start-1",children:e.jsx("svg",{"aria-hidden":"true",fill:"none",height:"24",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",viewBox:"0 0 24 24",width:"24",xmlns:"http://www.w3.org/2000/svg",children:e.jsx("path",{d:"M5.252 12.7 10.2 18.63 18.748 5.37"})})}),e.jsx("div",{className:"col-start-2",children:t}),n&&e.jsx("div",{className:"col-start-3 flex items-center",children:n})]})}function im({className:s,...t}){return e.jsx(Ci,{scrollbarGutter:!0,scrollFade:!0,children:e.jsx(Si,{className:K("not-empty:scroll-py-1 not-empty:px-1 not-empty:py-1 in-data-has-overflow-y:pe-3",s),"data-slot":"combobox-list",...t})})}function lm({className:s,...t}){return e.jsx(Ei,{className:s,"data-slot":"combobox-clear",...t})}function cm(){const{t:s}=R(),t=g(d=>d.contextMenuOpen),n=g(d=>d.setContextMenuOpen),[a,r]=l.useState(!1),[o,i]=l.useState(!1),m=d=>d.target==="reveal"?s("File manager"):d.target==="vscode"?s("VS Code"):d.applicationPath.split(/[/\\]/).at(-1)?.replace(/\.(exe|app)$/i,"")||d.applicationPath,u=t.filter(d=>d.enabled).map(m),x=u.length?`${u.slice(0,2).join(", ")}${u.length>2?` +${u.length-2}`:""}`:s("No opening methods enabled"),h=d=>{if(d.length>32){Te({type:"error",title:s("Context menu opening"),description:s("You can configure up to 32 opening methods.")});return}n(d)},c=(d,p)=>{const j=g.getState().contextMenuOpen;n(j.map(b=>b.id===d.id?{...b,enabled:p}:b))},f=async()=>{i(!0);try{const d=await window.electronAPI.dialog.selectFile();if(!d)return;if(!_r(d)){Te({type:"error",title:s("Context menu opening"),description:s("The selected application path is invalid.")});return}const p=g.getState().contextMenuOpen,j=ta(d),b=p.find(A=>A.target==="application"&&ta(A.applicationPath)===j);if(b){h(p.map(A=>A.id===b.id?{...A,enabled:!0}:A));return}h([...p,{id:crypto.randomUUID(),target:"application",applicationPath:d,enabled:!0}])}catch(d){Te({type:"error",title:s("Context menu opening"),description:d instanceof Error?d.message:String(d)})}finally{i(!1)}};return e.jsxs("div",{className:"space-y-2 rounded-md border p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("h5",{className:"text-sm font-medium",children:s("Context menu opening")}),e.jsx(y,{variant:"outline",size:"sm",onClick:()=>r(!0),children:s("Configure list")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Select the opening methods shown in file link context menus. You can add multiple applications.")}),e.jsx("p",{className:"truncate text-xs text-muted-foreground",title:u.join(", "),children:x}),e.jsx(ye,{open:a,onOpenChange:r,children:e.jsxs(we,{zIndexLevel:"nested",children:[e.jsxs(Ne,{children:[e.jsx(ke,{children:s("Context menu opening")}),e.jsx(Ye,{children:s("Select the opening methods shown in file link context menus. You can add multiple applications.")})]}),e.jsxs(Ce,{className:"space-y-2",children:[t.length===0&&e.jsx("p",{className:"py-6 text-center text-sm text-muted-foreground",children:s("No opening methods enabled")}),t.map(d=>{const p=m(d);return e.jsxs("div",{className:"flex items-center gap-3 rounded-md border p-3",children:[e.jsxs("label",{className:"flex min-w-0 flex-1 cursor-pointer items-center gap-3",children:[e.jsx(Le,{checked:d.enabled,disabled:o,"aria-label":p,onCheckedChange:j=>c(d,j)}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-sm",title:p,children:p}),d.target==="application"&&e.jsx("span",{className:"block truncate text-xs text-muted-foreground",title:d.applicationPath,children:d.applicationPath})]})]}),e.jsx(y,{variant:"ghost",size:"sm",disabled:o,onClick:()=>n(g.getState().contextMenuOpen.filter(j=>j.id!==d.id)),children:s("Delete")})]},d.id)})]}),e.jsxs(Ee,{children:[e.jsx(y,{variant:"outline",disabled:o,onClick:()=>{f()},children:s("Add application")}),e.jsx(y,{onClick:()=>r(!1),children:s("Close")})]})]})})]})}const Ia=["internal","reveal","system","application"];function Aa({extension:s,value:t,disabled:n,onChange:a}){const{t:r}=R(),o={internal:r("Open inside EnsoCode"),reveal:r("Reveal in file manager"),system:r("System default application"),application:r("Selected application")},i=ut(`file${s}`),m=mt(`file${s}`)!==null,u=i?m?["internal","reveal"]:["reveal"]:Ia,x=i&&(!m||t==="system"||t==="application")?"reveal":t;return e.jsxs(ne,{items:Object.fromEntries(u.map(h=>[h,o[h]])),value:x,disabled:n,onValueChange:h=>{Ia.includes(h)&&a(h)},children:[e.jsx(ae,{className:"w-52","aria-label":r("File opening"),children:e.jsx(re,{})}),e.jsx(oe,{children:u.map(h=>e.jsx(Z,{value:h,disabled:h==="internal"&&!m,children:o[h]},h))})]})}function dm(){const{t:s}=R(),t=g(k=>k.fileOpenRules),n=g(k=>k.setFileOpenRules),[a,r]=l.useState(""),[o,i]=l.useState("internal"),[m,u]=l.useState(),[x,h]=l.useState(null),[c,f]=l.useState(!1),d=Mi([{extension:a,target:"reveal"}])[0]?.extension,p=k=>{Te({type:"error",title:s("File opening"),description:k})},j=async k=>{f(!0);try{const I=await window.electronAPI.dialog.selectFile();if(I){if(!_r(I)){p(s("The selected application path is invalid."));return}k(I)}}catch(I){p(I instanceof Error?I.message:String(I))}finally{f(!1)}},b=k=>{const I=Pi(k);return I?(n(I),!0):(p(s("Could not complete the file action.")),!1)},A=(k,I,M)=>{if(I==="internal"&&!mt(`file${k.extension}`)){p(s("This extension does not support internal preview."));return}b(t.map($=>$.extension===k.extension?{extension:k.extension,target:I,...I==="application"?{applicationPath:M}:{}}:$))},v=()=>{if(!d){h(s("Enter a valid file extension, for example .md."));return}if(t.some($=>$.extension===d)){h(s("This extension already has an opening rule."));return}const k=ut(`file${d}`),I=mt(`file${d}`)!==null,M=k&&(!I||o==="system"||o==="application")?"reveal":o;if(M==="internal"&&!mt(`file${d}`)){p(s("This extension does not support internal preview."));return}if(M==="application"&&!m){h(s("Choose an application before saving this rule."));return}b([...t,{extension:d,target:M,...M==="application"?{applicationPath:m}:{}}])&&(r(""),u(void 0),h(null))};return e.jsxs("section",{className:"space-y-3","data-settings-row":"appearance.fileOpening",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium",children:s("File opening")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Configure how local workspace file links open by extension.")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("By default, supported files open inside EnsoCode; other files are revealed in the file manager.")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Executable and installer files are always revealed in the file manager.")})]}),e.jsx(cm,{}),t.map(k=>e.jsxs("div",{className:"flex flex-wrap items-center gap-2 rounded-md border px-3 py-2",children:[e.jsx("span",{className:"w-20 shrink-0 font-mono text-sm",children:k.extension}),e.jsx(Aa,{extension:k.extension,value:k.target,disabled:c,onChange:I=>{I==="application"?j(M=>A(k,I,M)):A(k,I)}}),k.target==="application"&&!ut(`file${k.extension}`)&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-xs text-muted-foreground",title:k.applicationPath,children:k.applicationPath}),e.jsx(y,{variant:"outline",size:"sm",disabled:c,onClick:()=>{j(I=>A(k,"application",I))},children:s("Choose application")})]}),e.jsx(y,{variant:"ghost",size:"sm",disabled:c,onClick:()=>b(t.filter(I=>I.extension!==k.extension)),children:s("Delete")})]},k.extension)),e.jsxs("div",{className:"space-y-2 rounded-md border p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(J,{className:"w-24",value:a,placeholder:".md","aria-label":s("File extension"),disabled:c,onChange:k=>{r(k.target.value),h(null)},onKeyDown:k=>{k.key==="Enter"&&v()}}),e.jsx(Aa,{extension:d??".md",value:o,disabled:c,onChange:k=>{i(k),h(null)}}),e.jsx(y,{variant:"outline",size:"sm",disabled:c,onClick:v,children:s("Add")})]}),o==="application"&&!ut(`file${d??".md"}`)&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{variant:"outline",size:"sm",disabled:c,onClick:()=>{j(k=>{u(k),h(null)})},children:s("Choose application")}),e.jsx("span",{className:"min-w-0 truncate text-xs text-muted-foreground",title:m,children:m})]}),x&&e.jsx("p",{role:"alert",className:"text-xs text-destructive",children:x})]})]})}const um=["pem","crt","cer"];function mm(s){return/^\//.test(s)||/^[A-Za-z]:[\\/]/.test(s)||/^\\\\[^\\]/.test(s)}const xm=16384,zo=4096,_o=65536;function hm(s){return s===null?null:typeof s=="number"&&Number.isInteger(s)&&s>=zo&&s<=_o?s:void 0}function pm(s){const t=s.trim();return t?/^\d+$/.test(t)?hm(Number(t)):void 0:null}function fm(){const{t:s}=R(),[t,n]=l.useState(null),[a,r]=l.useState(""),[o,i]=l.useState(null);l.useEffect(()=>{let u=!1;return window.electronAPI.compaction.getReserveTokens().then(x=>{u||(n(x),r(x===null?"":String(x)))}),()=>{u=!0}},[]);const m=async()=>{const u=pm(a);if(u===void 0){i(s("Enter a whole number between {{min}} and {{max}}, or leave it empty.",{min:zo,max:_o}));return}if(i(null),u===t)return;if(!(await window.electronAPI.compaction.setReserveTokens(u)).ok){i(s("Could not save. Check that pi-agent/settings.json is valid JSON."));return}n(u),r(u===null?"":String(u))};return e.jsxs("div",{className:"flex items-start justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.compactReserveTokens",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"text-sm",children:[s("Compaction reserve tokens"),e.jsx(Ze,{})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Compaction runs when context exceeds the model window minus this value. Larger values compact earlier. Do not set it close to the window of small-context models, or every request compacts first. Leave empty for the default.")})]}),e.jsxs("div",{className:"w-32 shrink-0 space-y-1",children:[e.jsx(J,{inputMode:"numeric",value:a,placeholder:String(xm),"aria-label":s("Compaction reserve tokens"),onChange:u=>r(u.target.value),onBlur:()=>{m()},onKeyDown:u=>{u.key==="Enter"&&m()}}),o&&e.jsx("p",{className:"text-xs text-destructive",children:o})]})]})}function cn({className:s,render:t,...n}){const a={className:K("inline-flex items-center gap-2 text-base/4.5 sm:text-sm/4 font-medium",s),"data-slot":"label"};return Ti({defaultTagName:"label",props:Ri(a,n),render:t})}const dn={checked(s){return s?{"data-checked":""}:{"data-unchecked":""}},...zr,...Fr},Fo=l.createContext(void 0);function gm(){return l.useContext(Fo)}const Bo=l.createContext(void 0);function jm(){const s=l.useContext(Bo);if(s===void 0)throw new Error(Oi(52));return s}const vm=l.forwardRef(function(t,n){const{render:a,className:r,disabled:o=!1,readOnly:i=!1,required:m=!1,"aria-labelledby":u,value:x,inputRef:h,nativeButton:c=!1,id:f,style:d,...p}=t,j=gm(),{disabled:b,readOnly:A,required:v,form:k,checkedValue:I,touched:M=!1,validation:$,name:E,setCheckedValue:L=Rt,setTouched:T=Rt,registerInputRef:C=Rt}=j??{},{setTouched:S,setFilled:W,state:q,disabled:N}=Br(),z=Di(),{labelId:H,getDescriptionProps:U}=Ur(),B=N||z.disabled||b||o,ie=A||i,F=v||m,X=k,V=j?I===x:x==="",le=l.useRef(null),_=l.useRef(null),de=$?.registerInput,ue=l.useCallback(ge=>de?.(ge,{controlRef:le,value:void 0}),[de]),O=Li(h,_,C,ue);na(()=>{_.current?.checked&&W(!0)},[W]),na(()=>{if(_.current){if(B&&V){C(null);return}C(_.current)}},[V,B,C]);const De=$r(),te=zi({id:f,implicit:!1,controlRef:le}),P=c?void 0:te,Y=_i(u,H,_,!c,P),D={role:"radio","aria-checked":V,"aria-labelledby":Y,[Ki]:V?"":void 0,id:c?te:De,onKeyDown(ge){ge.key==="Enter"&&ge.preventDefault()},onClick(ge){if(ge.defaultPrevented||B||ie)return;ge.preventDefault();const as=_.current;as&&Gi(as,ge)},onFocus(ge){ge.defaultPrevented||B||ie||!M||(_.current?.click(),T(!1))}},{getButtonProps:Q,buttonRef:ee}=Fi({disabled:B,native:c,composite:!1}),fe={type:"radio",ref:O,form:X,id:P,name:E,tabIndex:-1,style:E?$i:Vi,"aria-hidden":!0,...x!==void 0?{value:Bi(x)}:aa,disabled:B,checked:V,required:F,readOnly:ie,onChange(ge){if(ge.nativeEvent.defaultPrevented||B||ie||x===void 0)return;const as=Wi(Hi,ge.nativeEvent);L(x,as),!as.isCanceled&&S(!0)},onClick(ge){ge.stopPropagation()},onFocus(){le.current?.focus()}},xe=l.useMemo(()=>({...q,required:F,disabled:B,readOnly:ie,checked:V}),[q,B,ie,V,F]),Ls=xe,ds=j!==void 0,vs=[n,le,ee],He=[D,p,Q,U,$?ge=>$.getValidationProps(B,ge):aa],zs=vn("span",t,{enabled:!ds,state:xe,ref:vs,props:He,stateAttributesMapping:dn});return e.jsxs(Bo.Provider,{value:Ls,children:[ds?e.jsx(Ui,{tag:"span",render:a,className:r,style:d,state:xe,refs:vs,props:He,stateAttributesMapping:dn}):zs,e.jsx("input",{...fe,suppressHydrationWarning:!0})]})}),bm=l.forwardRef(function(t,n){const{render:a,className:r,style:o,keepMounted:i=!1,...m}=t,u=jm(),x=u.checked,{mounted:h,transitionStatus:c,setMounted:f}=Dr(x),d={...u,transitionStatus:c},p=l.useRef(null),j=i||h,b=vn("span",t,{ref:[n,p],state:d,props:m,stateAttributesMapping:dn});return Lr({open:x,ref:p,onComplete(){x||f(!1)}}),j?b:null}),ym=[sl],wm=l.forwardRef(function(t,n){const{render:a,className:r,disabled:o,readOnly:i,required:m,onValueChange:u,value:x,defaultValue:h,form:c,name:f,inputRef:d,id:p,style:j,...b}=t,{setTouched:A,setFocused:v,validationMode:k,name:I,disabled:M,state:$,validation:E,setDirty:L,setFilled:T,validityData:C}=Br(),{labelId:S}=Ur(),{clearErrors:W,elementRef:q}=qi(),N=Yi(!0),z=M||o,H=I??f,U=$r(p),[B,ie]=Ji({controlled:x,default:h,name:"RadioGroup",state:"value"}),[F,X]=l.useState(!1),V=Ot((ee,fe)=>{u?.(ee,fe),!fe.isCanceled&&ie(ee)}),le=E.getInputControl,_=l.useMemo(()=>({get current(){return le()}}),[le]),de=l.useRef(null),ue=l.useRef(null);function O(ee){let fe;return d&&(typeof d=="function"?fe=d(ee):d.current=ee),de.current=ee,fe}const De=Ot(ee=>{if(!ee||ee.disabled)return;ue.current||(ue.current=ee);const fe=de.current,xe=ee.checked||fe==null||fe.disabled?O(ee):void 0;return()=>{ue.current===ee&&(ue.current=null),de.current===ee?xe?(xe(),de.current=null):O(null):xe?.()}}),te=Ot(()=>{const ee=q.current;if(!ee)return B??null;for(const fe of E.registeredInputs.keys())if(fe.checked&&Xi(fe,ee))return B??null;return null});Qi(_,U,B??null,te,!z,f),Zi(B,()=>{W(H),L(B!==C.initialValue),T(B!=null),E.change(B);const ee=ue.current;B==null&&ee&&!ee.disabled&&O(ee)});const P=S??N?.legendId,Y={...$,disabled:z??!1,required:m??!1,readOnly:i??!1},D=l.useMemo(()=>({checkedValue:B,disabled:z,form:c,validation:E,name:H,readOnly:i,registerInputRef:De,required:m,setCheckedValue:V,setTouched:X,touched:F}),[B,z,c,E,H,i,De,m,V,X,F]),Q={id:p,role:"radiogroup","aria-required":m||void 0,"aria-disabled":z||void 0,"aria-readonly":i||void 0,"aria-labelledby":P,onFocus(){v(!0)},onBlur(ee){tl(ee.currentTarget,ee.relatedTarget)||(A(!0),v(!1),k==="onBlur"&&E.commit(B))},onKeyDownCapture(ee){ee.key.startsWith("Arrow")&&(X(!0),v(!0))}};return e.jsx(Fo.Provider,{value:D,children:e.jsx(el,{render:a,className:r,style:j,state:Y,props:[Q,b,ee=>E.getValidationProps(z??!1,ee)],refs:[n],stateAttributesMapping:Fr,enableHomeAndEndKeys:!1,modifierKeys:ym})})});function Nm({className:s,...t}){return e.jsx(wm,{className:K("flex flex-col gap-3",s),"data-slot":"radio-group",...t})}function Ea({className:s,...t}){return e.jsx(vm,{className:K("relative inline-flex size-4.5 shrink-0 items-center justify-center rounded-full border border-input bg-background bg-clip-padding shadow-xs outline-none transition-shadow before:pointer-events-none before:absolute before:inset-0 before:rounded-full not-data-disabled:not-data-checked:not-aria-invalid:before:shadow-[0_1px_--theme(--color-black/4%)] focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background aria-invalid:border-destructive/36 focus-visible:aria-invalid:border-destructive/64 focus-visible:aria-invalid:ring-destructive/48 data-disabled:opacity-64 sm:size-4 dark:not-data-checked:bg-input/32 dark:bg-clip-border dark:aria-invalid:ring-destructive/24 dark:not-data-disabled:not-data-checked:not-aria-invalid:before:shadow-[0_-1px_--theme(--color-white/8%)] [[data-disabled],[data-checked],[aria-invalid]]:shadow-none",s),"data-slot":"radio",...t,children:e.jsx(bm,{className:"-inset-px absolute flex size-4.5 items-center justify-center rounded-full before:size-2 before:rounded-full before:bg-primary-foreground data-unchecked:hidden data-checked:bg-primary sm:size-4 sm:before:size-1.5","data-slot":"radio-indicator"})})}const km=[{category:"providers",label:"Model Providers"},{category:"presets",label:"Presets"},{category:"agentTypes",label:"Agent types"},{category:"skills",label:"Skills"},{category:"mcpServers",label:"MCP Servers"},{category:"instructions",label:"Instruction Files"},{category:"subagentModels",label:"Subagent Models"},{category:"settings",label:"Scalar settings"}];function Cm(){const{t:s}=R(),[t,n]=l.useState(!1),[a,r]=l.useState(!1),[o,i]=l.useState(null),[m,u]=l.useState(null),x=()=>{i(null),n(!0)},h=async()=>{r(!0),i(null);try{const c=await window.electronAPI.configSync.openImport();if(!c.ok){i({kind:c.cancelled?"cancelled":"error",text:c.cancelled?s("Import cancelled."):s(c.error)});return}u(c)}catch{i({kind:"error",text:s("Could not open configuration package.")})}finally{r(!1)}};return e.jsxs("section",{className:"space-y-3","data-settings-row":"general.configSync",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium",children:s("Configuration transfer")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Move models, presets, agent types, skills, MCP servers and instruction files between devices.")})]}),e.jsxs("div",{className:"rounded-md border px-3 py-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[e.jsx(Iu,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium",children:s("Portable Enso configuration")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Export a package or preview one before importing it.")})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsxs(y,{variant:"outline",size:"sm",disabled:a,onClick:h,children:[a?e.jsx(Me,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(bn,{className:"h-3.5 w-3.5"}),s("Import configuration")]}),e.jsxs(y,{size:"sm",disabled:a,onClick:x,children:[e.jsx(Lo,{className:"h-3.5 w-3.5"}),s("Export configuration")]})]})]}),e.jsxs("div",{className:"mt-3 flex items-start gap-2 border-t pt-3 text-xs text-muted-foreground",children:[e.jsx(pt,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),e.jsx("p",{children:s("OAuth login sessions are never transferred. Skill, instruction, and system prompt contents require an encrypted export.")})]}),o&&e.jsx("p",{className:o.kind==="error"?"mt-2 text-xs text-destructive":"mt-2 text-xs text-muted-foreground",role:o.kind==="error"?"alert":"status",children:o.text})]}),e.jsx(Sm,{open:t,onOpenChange:n}),m&&e.jsx(Im,{file:m,onClose:()=>u(null)})]})}function Sm({open:s,onOpenChange:t}){const{t:n}=R(),[a,r]=l.useState(!1),[o,i]=l.useState(""),[m,u]=l.useState(""),[x,h]=l.useState(!1),[c,f]=l.useState(null),[d,p]=l.useState(!1),[j,b]=l.useState(null),[A,v]=l.useState([]);l.useEffect(()=>{s&&(r(!1),i(""),u(""),h(!1),f(null),p(!1),b(null),v([]))},[s]);const k=()=>{x||(i(""),u(""),t(!1))},I=async()=>{if(a&&o.length<8){f(n("Password must be at least 8 characters."));return}if(a&&o!==m){f(n("Passwords do not match."));return}h(!0),f(null),p(!1);try{const M=await window.electronAPI.configSync.exportConfig({includeSecrets:a,...a?{password:o}:{}});if(i(""),u(""),!M.ok){M.cancelled?p(!0):f(n(M.error));return}b(M.filePath),v(M.skippedInstructions??[])}catch{i(""),u(""),f(n("Could not export configuration."))}finally{h(!1)}};return e.jsx(ye,{open:s,onOpenChange:M=>!M&&k(),children:e.jsxs(we,{className:"max-w-xl",showCloseButton:!x,children:[e.jsxs(Ne,{children:[e.jsx(ke,{children:n("Export configuration")}),e.jsx(Ye,{children:n("Create a portable .enso-config package for another device.")})]}),e.jsx(Ce,{className:"max-h-[55vh] space-y-4",children:j?e.jsxs(e.Fragment,{children:[e.jsxs($e,{variant:"success",children:[e.jsx(Vr,{}),e.jsx(Ms,{children:n("Configuration exported")}),e.jsxs(Ve,{children:[e.jsx("p",{children:n("Saved package:")}),e.jsx("p",{className:"break-all font-mono text-xs text-foreground",children:j})]})]}),A.length>0&&e.jsxs($e,{variant:"warning",children:[e.jsx(Ke,{}),e.jsxs(Ve,{children:[e.jsx("p",{children:n("These instructions were skipped because their source files are missing or unreadable:")}),e.jsx("p",{className:"break-all text-foreground",children:A.join(", ")})]})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs($e,{variant:"warning",children:[e.jsx(yn,{}),e.jsx(Ms,{children:n("File contents can be private")}),e.jsx(Ve,{children:n("Skill and instruction file contents may contain private data, so configurations containing them can only be exported with encryption.")})]}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-md border px-3 py-2.5",children:[e.jsx(Le,{checked:a,onCheckedChange:M=>{const $=M===!0;r($),f(null),$||(i(""),u(""))}}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-sm font-medium",children:n("Include sensitive configuration")}),e.jsx("span",{className:"mt-0.5 block text-xs text-muted-foreground",children:n("Encrypt the entire package with a password. OAuth login sessions are still excluded.")})]})]}),!a&&e.jsxs($e,{variant:"info",children:[e.jsx(pt,{}),e.jsx(Ve,{children:n("API keys, provider account links, MCP arguments and environment values, plus credentials and private URL parts in MCP endpoints, will be omitted. Configurations containing skill or instruction files require encryption.")})]}),a&&e.jsxs("div",{className:"space-y-3 rounded-md border px-3 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(Do,{className:"h-4 w-4 text-muted-foreground"}),n("Encryption password")]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(cn,{htmlFor:"config-export-password",children:n("Password")}),e.jsx(J,{id:"config-export-password",type:"password",autoComplete:"new-password",value:o,"aria-invalid":!!(c&&o.length<8),onChange:M=>{i(M.target.value),f(null)}})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(cn,{htmlFor:"config-export-confirmation",children:n("Confirm password")}),e.jsx(J,{id:"config-export-confirmation",type:"password",autoComplete:"new-password",value:m,"aria-invalid":!!(c&&m!==o),onChange:M=>{u(M.target.value),f(null)}})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n("Use at least 8 characters. This password cannot be recovered.")})]}),d&&e.jsx("p",{className:"text-xs text-muted-foreground",role:"status",children:n("Export cancelled.")}),c&&e.jsxs("p",{className:"flex items-center gap-1.5 text-xs text-destructive",role:"alert",children:[e.jsx(Rs,{className:"h-3.5 w-3.5 shrink-0"}),c]})]})}),e.jsx(Ee,{children:j?e.jsx(y,{size:"sm",onClick:k,children:n("Done")}):e.jsxs(e.Fragment,{children:[e.jsx(y,{variant:"outline",size:"sm",disabled:x,onClick:k,children:n("Cancel")}),e.jsxs(y,{size:"sm",disabled:x,onClick:()=>{I()},children:[x?e.jsx(Me,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Lo,{className:"h-3.5 w-3.5"}),n(x?"Exporting…":"Export")]})]})})]})})}function Im({file:s,onClose:t}){const{t:n}=R(),[a,r]=l.useState(s.encrypted?"password":"preview"),[o,i]=l.useState(""),[m,u]=l.useState("merge"),[x,h]=l.useState(null),[c,f]=l.useState([]),[d,p]=l.useState(null),[j,b]=l.useState(!1),[A,v]=l.useState(null),[k,I]=l.useState(null),[M,$]=l.useState(!1),E=l.useRef(0),L=l.useCallback(async(N,z)=>{const H=++E.current;v("preview"),I(null),h(null),f([]);try{const U=await window.electronAPI.configSync.previewImport({token:s.token,mode:N,...z?{password:z}:{}});if(H!==E.current)return;if(i(""),!U.ok){I(n(U.error));return}u(U.mode),h(U.summary),f(U.warnings),r("preview")}catch{H===E.current&&(i(""),I(n("Could not preview configuration package.")))}finally{H===E.current&&v(null)}},[s.token,n]);l.useEffect(()=>{s.encrypted||L("merge")},[s.encrypted,L]);const T=()=>{A||(E.current+=1,$(!1),i(""),window.electronAPI.configSync.cancelImport(s.token).catch(()=>{}),t())},C=N=>{N===m||A||(u(N),L(N))},S=!!x?.some(N=>(N.category==="skills"||N.category==="mcpServers")&&N.added+N.updated+N.skipped>0),W=x!==null,q=async()=>{if(x){v("commit"),I(null);try{const N=await window.electronAPI.configSync.commitImport({token:s.token,mode:m});if(!N.ok){h(null),f([]),I(n(N.error));return}i("");try{await g.persist.rehydrate()}catch{b(!0)}f(N.warnings),p(N.backupPath),r("success")}catch{h(null),f([]),I(n("Could not import configuration."))}finally{v(null)}}};return e.jsxs(ye,{open:!0,onOpenChange:N=>!N&&T(),children:[e.jsxs(we,{className:"max-w-2xl",showCloseButton:A===null,children:[e.jsxs(Ne,{children:[e.jsx(ke,{children:n(a==="success"?"Configuration imported":"Import configuration")}),e.jsx(Ye,{children:a==="success"?n(j?"Configuration was imported, but this window could not refresh automatically.":"This window has been refreshed with the imported settings."):n("Review {{fileName}} before changing this device.",{fileName:s.fileName})})]}),a==="password"&&e.jsxs(Ce,{className:"space-y-4",children:[e.jsxs($e,{variant:"info",children:[e.jsx(Do,{}),e.jsx(Ms,{children:n("Encrypted configuration package")}),e.jsx(Ve,{children:n("Enter the export password to decrypt and preview this package.")})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(cn,{htmlFor:"config-import-password",children:n("Password")}),e.jsx(J,{id:"config-import-password",type:"password",autoFocus:!0,autoComplete:"current-password",value:o,"aria-invalid":!!k,onChange:N=>{i(N.target.value),I(null)},onKeyDown:N=>{N.key==="Enter"&&o.length>0&&!A&&L("merge",o)}})]}),k&&e.jsxs("p",{className:"flex items-center gap-1.5 text-xs text-destructive",role:"alert",children:[e.jsx(Rs,{className:"h-3.5 w-3.5 shrink-0"}),k]})]}),a==="preview"&&e.jsxs(Ce,{className:"max-h-[58vh] space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium",children:n("Import mode")}),e.jsxs(Nm,{value:m,onValueChange:N=>C(N),className:"grid gap-2 sm:grid-cols-2","aria-label":n("Import mode"),children:[e.jsxs("label",{className:"flex cursor-pointer items-start gap-2.5 rounded-md border px-3 py-2.5",children:[e.jsx(Ea,{value:"merge",disabled:A!==null}),e.jsxs("span",{children:[e.jsx("span",{className:"block text-sm font-medium",children:n("Merge")}),e.jsx("span",{className:"block text-xs text-muted-foreground",children:n("Add and update matching items while keeping items only on this device.")})]})]}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-2.5 rounded-md border px-3 py-2.5",children:[e.jsx(Ea,{value:"replace",disabled:A!==null}),e.jsxs("span",{children:[e.jsx("span",{className:"block text-sm font-medium",children:n("Replace")}),e.jsx("span",{className:"block text-xs text-muted-foreground",children:n("Replace transferred item categories, removing local-only items in them.")})]})]})]})]}),A==="preview"&&e.jsxs("div",{className:"flex items-center justify-center gap-2 rounded-md border border-dashed py-10",children:[e.jsx(Me,{className:"h-4 w-4 animate-spin text-muted-foreground"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:n("Preparing preview…")})]}),!A&&x&&e.jsx("div",{className:"overflow-hidden rounded-md border",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted/50 text-xs text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",className:"px-3 py-2 text-left font-medium",children:n("Category")}),e.jsx("th",{scope:"col",className:"px-3 py-2 text-right font-medium",children:n("Added")}),e.jsx("th",{scope:"col",className:"px-3 py-2 text-right font-medium",children:n("Updated")}),e.jsx("th",{scope:"col",className:"px-3 py-2 text-right font-medium",children:n("Skipped")}),e.jsx("th",{scope:"col",className:"px-3 py-2 text-right font-medium",children:n("Removed")})]})}),e.jsx("tbody",{children:km.map(({category:N,label:z})=>{const H=x.find(U=>U.category===N);return e.jsxs("tr",{className:"border-t first:border-t-0",children:[e.jsx("th",{scope:"row",className:"px-3 py-2 text-left font-medium",children:n(z)}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:H?.added??0}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:H?.updated??0}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:H?.skipped??0}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:H?.removed??0})]},N)})})]})}),!A&&x?.find(N=>N.category==="settings")?.fields?.length?e.jsxs("p",{className:"text-xs text-muted-foreground",children:[n("Portable settings changed:")," ",x.find(N=>N.category==="settings")?.fields?.join(", ")]}):null,m==="replace"&&x&&!A&&e.jsxs($e,{variant:"error",children:[e.jsx(Ke,{}),e.jsx(Ms,{children:n("Local-only configuration will be deleted")}),e.jsx(Ve,{children:n("Items in transferred collections that exist only on this device will be removed. Removed counts are shown above. Included portable preferences are overwritten. A complete backup is created first.")})]}),c.map(N=>e.jsxs($e,{variant:"warning",children:[e.jsx(Ke,{}),e.jsx(Ve,{children:n(N)})]},N)),x&&!A&&e.jsxs($e,{variant:"warning",children:[e.jsx(yn,{}),e.jsx(Ms,{children:n("Only import packages you trust")}),e.jsx(Ve,{children:n("An imported package can change portable preferences and configuration. Skills and MCP servers may also run commands later when you use them. Previewing does not execute them; continue only if you trust the package.")})]}),k&&e.jsxs($e,{variant:"error",children:[e.jsx(Rs,{}),e.jsx(Ve,{children:k})]})]}),a==="success"&&d&&e.jsxs(Ce,{className:"space-y-4",children:[e.jsxs($e,{variant:"success",children:[e.jsx(Vr,{}),e.jsx(Ms,{children:n("Import complete")}),e.jsxs(Ve,{children:[e.jsx("p",{children:n("Backup of previous settings:")}),e.jsx("p",{className:"break-all font-mono text-xs text-foreground",children:d})]})]}),j&&e.jsxs($e,{variant:"warning",children:[e.jsx(Ke,{}),e.jsx(Ve,{children:n("Reopen Settings to load the imported configuration in this window.")})]}),c.map(N=>e.jsxs($e,{variant:"warning",children:[e.jsx(Ke,{}),e.jsx(Ve,{children:n(N)})]},N))]}),e.jsxs(Ee,{children:[a==="password"&&e.jsxs(e.Fragment,{children:[e.jsx(y,{variant:"outline",size:"sm",disabled:A!==null,onClick:T,children:n("Cancel")}),e.jsxs(y,{size:"sm",disabled:A!==null||o.length===0,onClick:()=>{L("merge",o)},children:[A==="preview"&&e.jsx(Me,{className:"h-3.5 w-3.5 animate-spin"}),n("Preview")]})]}),a==="preview"&&e.jsxs(e.Fragment,{children:[e.jsx(y,{variant:"outline",size:"sm",disabled:A!==null,onClick:T,children:n("Cancel")}),k&&!x?e.jsx(y,{size:"sm",disabled:A!==null,onClick:()=>{L(m)},children:n("Refresh preview")}):e.jsxs(y,{variant:m==="replace"?"destructive":"default",size:"sm",disabled:A!==null||!x,onClick:()=>{x&&(W?$(!0):q())},children:[A==="commit"?e.jsx(Me,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(bn,{className:"h-3.5 w-3.5"}),n(A==="commit"?"Importing…":"Import")]})]}),a==="success"&&e.jsx(y,{size:"sm",onClick:T,children:n("Done")})]})]}),e.jsx(Am,{open:M,mode:m,hasImportedExecutableResources:S,onOpenChange:$,onConfirm:()=>{q()}})]})}function Am({open:s,mode:t,hasImportedExecutableResources:n,onOpenChange:a,onConfirm:r}){const{t:o}=R();return e.jsx(wn,{open:s,onOpenChange:a,children:e.jsxs(Nn,{className:"sm:max-w-md",zIndexLevel:"nested",children:[e.jsxs(kn,{children:[e.jsxs(Cn,{className:"flex items-start gap-2 text-base",children:[e.jsx(Ke,{className:"mt-0.5 h-4 w-4 shrink-0 text-destructive"}),o("Confirm configuration import")]}),e.jsxs(Sn,{className:"space-y-2",children:[e.jsx("span",{className:"block",children:o("This package can change portable preferences and configuration. Continue only if you trust this package.")}),n&&e.jsx("span",{className:"block",children:o("It includes skills or MCP servers that may execute commands when you use them.")}),t==="replace"&&e.jsx("span",{className:"block",children:o("Replace mode removes local-only items from transferred collections and overwrites included portable preferences. A complete backup will be created first.")}),e.jsx("span",{className:"block",children:o("Do you want to continue with this import?")})]})]}),e.jsxs(In,{variant:"bare",children:[e.jsx(An,{render:e.jsx(y,{variant:"outline",size:"sm"}),children:o("Cancel")}),e.jsx(y,{variant:t==="replace"?"destructive":"default",size:"sm",onClick:()=>{a(!1),r()},children:o("Confirm import")})]})]})})}const Ma={auto:"Auto (by usage)",fast:"Fast",balanced:"Balanced",thorough:"Thorough"},Pa={standard:"Standard",smart:"Smart compaction","codex-native":"Codex native compaction","continuous-memory":"Continuous memory (experimental)"};function Em(){const{t:s}=R(),t=g(d=>d.compactStrategy),n=g(d=>d.smartCompactEnabled),a=nl(t,n),r=g(d=>d.setCompactStrategy),o=a!=="standard",i=g(d=>d.smartCompactModel),m=g(d=>d.setSmartCompactModel),u=g(d=>d.smartCompactMode),x=g(d=>d.setSmartCompactMode),h=es(),c=i?h.find(d=>d.id===i.providerId):void 0,f=c?.models.find(d=>d.id===i?.modelId);return e.jsxs("section",{className:"space-y-2 rounded-lg border bg-card p-3","data-settings-row":"general.smartCompactEnabled",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("h4",{className:"font-medium text-sm",children:[s("Context compaction strategy"),e.jsx(Ze,{})]}),e.jsx("p",{className:"mt-0.5 text-muted-foreground text-xs",children:s("Standard uses default compact. Smart compaction uses Enso verified summary at compact time. Codex native compaction additionally stores an official Codex checkpoint on Codex models and uses smart compaction otherwise. Continuous memory records observations in the background so compact keeps more context; all fall back to default compact on failure. Switching strategy takes effect on the next session. The summary model and compaction mode apply to open conversations on the next compaction.")})]}),e.jsxs(ne,{items:Object.fromEntries(ra.map(d=>[d,s(Pa[d])])),value:a,onValueChange:d=>r(d),children:[e.jsx(ae,{className:"w-52",children:e.jsx(re,{})}),e.jsx(oe,{children:ra.map(d=>e.jsx(Z,{value:d,children:s(Pa[d])},d))})]})]}),(a==="smart"||a==="codex-native")&&e.jsxs("div",{className:"flex items-center justify-between gap-4","data-smart-compact-mode":u,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Compaction mode")}),e.jsx("p",{className:"mt-0.5 text-muted-foreground/80 text-[11px]",children:s("Mode changes summary budget and how much recent tail to keep. It does not decide whether compact runs.")})]}),e.jsxs(ne,{items:Object.fromEntries(oa.map(d=>[d,s(Ma[d])])),value:u,onValueChange:d=>x(d),children:[e.jsx(ae,{className:"w-36",children:e.jsx(re,{})}),e.jsx(oe,{children:oa.map(d=>e.jsx(Z,{value:d,children:s(Ma[d])},d))})]})]}),o&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"font-medium text-sm",children:s(a==="continuous-memory"?"Background memory model":"Summary model")}),h.length>0&&e.jsx("div",{className:"w-full min-w-0",children:e.jsx(ze,{providers:h,providerId:c?.id??"",modelId:f?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:s("Follows the session model"),side:"bottom",triggerClassName:Qe,onSelect:(d,p)=>m({providerId:d,modelId:p}),onReasoningChange:()=>{},onThinkingChange:()=>{}})}),i&&(!c||!f)&&e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Selected model is unavailable — falls back to the session model.")}),i&&e.jsx(y,{variant:"ghost",size:"sm",className:"self-start",onClick:()=>m(null),children:s("Follow session model")})]})]})}const Mm={cmd:"Command Prompt",powershell:"Windows PowerShell",pwsh:"PowerShell 7 (pwsh)","git-bash":"Git Bash",zsh:"zsh",bash:"bash",fish:"fish"};function Pm(){const{language:s,setLanguage:t}=g(),{t:n}=R();return e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:n("General")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:n("General application settings")})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h4",{className:"border-b pb-2 text-base font-semibold",children:n("Application")}),e.jsxs("div",{className:"flex items-center gap-3","data-settings-row":"general.language",children:[e.jsx("span",{className:"text-sm font-medium",children:n("Language")}),e.jsxs(ne,{items:{en:"English",zh:"简体中文"},value:s,onValueChange:a=>t(a),children:[e.jsx(ae,{className:"w-48",children:e.jsx(re,{})}),e.jsxs(oe,{children:[e.jsx(Z,{value:"en",children:"English"}),e.jsx(Z,{value:"zh",children:"简体中文"})]})]})]}),e.jsx(Tm,{}),e.jsx(Bm,{}),e.jsx(Um,{}),e.jsx(Cm,{}),e.jsx($m,{})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h4",{className:"border-b pb-2 text-base font-semibold",children:n("Agent runtime")}),e.jsx(Rm,{}),e.jsx(Om,{}),e.jsx(Em,{}),e.jsx(fm,{})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h4",{className:"border-b pb-2 text-base font-semibold",children:n("Sessions & worktrees")}),e.jsx(Lm,{}),e.jsx(Dm,{}),e.jsx(_m,{})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h4",{className:"border-b pb-2 text-base font-semibold",children:n("Terminal")}),e.jsx(Fm,{}),e.jsx(zm,{})]}),window.electronAPI.env.platform==="darwin"&&e.jsxs("section",{className:"space-y-3",children:[e.jsx("h4",{className:"border-b pb-2 text-base font-semibold",children:n("Integrations")}),e.jsx(Ta,{kind:"ensoCommand",title:n("'enso' terminal command"),description:n("Run `enso .` in a terminal to open the current folder in EnsoCode. Links the command into /usr/local/bin and may ask for your password.")}),e.jsx(Ta,{kind:"finderQuickAction",title:n("Finder Quick Action"),description:n("Right-click a folder in Finder and choose Services > Open with EnsoCode.")})]})]})}function Ta({kind:s,title:t,description:n}){const{t:a}=R(),[r,o]=l.useState(!1),[i,m]=l.useState(!1);l.useEffect(()=>{let x=!0;const h=()=>{window.electronAPI.window.shellIntegrationStatus().then(c=>{x&&o(c[s])})};return h(),window.addEventListener("focus",h),()=>{x=!1,window.removeEventListener("focus",h)}},[s]);const u=async()=>{m(!0);try{await window.electronAPI.window.installShellIntegration(s)}finally{try{const x=await window.electronAPI.window.shellIntegrationStatus();o(x[s])}finally{m(!1)}}};return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":`general.${s}`,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n})]}),e.jsx(y,{variant:"outline",size:"sm",className:"shrink-0",disabled:i,onClick:()=>{u()},children:a(i?"In progress…":r?"Uninstall":"Install")})]})}function Tm(){const{t:s}=R(),t=g(a=>a.notifyMainAgentOnly),n=g(a=>a.setNotifyMainAgentOnly);return e.jsx(Ie,{rowId:"general.notifyMainAgentOnly",title:s("Notify only for the main agent"),description:s("Skip coworker completion and failure notifications on this computer and the paired phone. Questions and approvals still notify."),checked:t,onChange:n})}function Rm(){const{t:s}=R(),t=g(a=>a.generationStallTimeoutMin),n=g(a=>a.setGenerationStallTimeoutMin);return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.generationStallTimeout",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s("Stop if no output")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Abort and retry the run when no tokens or tool results arrive for this long. Thinking counts as output.")})]}),e.jsxs(ne,{items:Object.fromEntries(ia.map(a=>[String(a),a===0?s("Never"):s("{{count}} min",{count:a})])),value:String(t),onValueChange:a=>n(Number(a)),children:[e.jsx(ae,{className:"w-28",children:e.jsx(re,{})}),e.jsx(oe,{children:ia.map(a=>e.jsx(Z,{value:String(a),children:a===0?s("Never"):s("{{count}} min",{count:a})},a))})]})]})}function Om(){const{t:s}=R(),t=g(o=>o.autoRetryLimit),n=g(o=>o.setAutoRetryLimit),a=Dt.some(o=>o===t)?[...Dt]:[...Dt,t].sort((o,i)=>o===Lt?1:i===Lt?-1:o-i),r=o=>o===0?s("Off"):o===Lt?s("Unlimited"):s("{{count}} times",{count:o});return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.autoRetryLimit",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s("Auto-retry on transient errors")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Retry with backoff (up to 60s apart) after 429, 5xx or network errors. Quota and billing errors are never retried. Unlimited keeps retrying until you cancel.")})]}),e.jsxs(ne,{items:Object.fromEntries(a.map(o=>[String(o),r(o)])),value:String(t),onValueChange:o=>n(Number(o)),children:[e.jsx(ae,{className:"w-28",children:e.jsx(re,{})}),e.jsx(oe,{children:a.map(o=>e.jsx(Z,{value:String(o),children:r(o)},o))})]})]})}function Dm(){const{t:s}=R(),t=g(r=>r.activeRetentionMinutes),n=g(r=>r.setActiveRetentionMinutes),a=r=>r===0?s("Off"):s("{{count}} min",{count:r});return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.activeRetentionMinutes",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s("Keep in Active after last message")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Viewed conversations stay in Active for this long after their last message or your last open while still in Active, then leave. Unviewed ones stay until you open them.")})]}),e.jsxs(ne,{items:Object.fromEntries(ft.map(r=>[String(r),a(r)])),value:String(t),onValueChange:r=>n(Number(r)),children:[e.jsx(ae,{className:"w-28",children:e.jsx(re,{})}),e.jsx(oe,{children:ft.map(r=>e.jsx(Z,{value:String(r),children:a(r)},r))})]})]})}function lt(s,t){return t===0?s("Never"):t===1?s("{{count}} day",{count:t}):s("{{count}} days",{count:t})}function Lm(){const{t:s}=R(),t=g(m=>m.autoArchiveIdleDays),n=g(m=>m.setAutoArchiveIdleDays),a=g(m=>m.autoArchiveMergedWorktrees),r=g(m=>m.setAutoArchiveMergedWorktrees),o=g(m=>m.autoDeleteArchivedDays),i=g(m=>m.setAutoDeleteArchivedDays);return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.autoArchiveIdleDays",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s("Archive idle conversations")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Move conversations that have been idle this long into Archived. Does not delete them.")})]}),e.jsxs(ne,{items:Object.fromEntries(la.map(m=>[String(m),lt(s,m)])),value:String(t),onValueChange:m=>n(Number(m)),children:[e.jsx(ae,{className:"w-28",children:e.jsx(re,{})}),e.jsx(oe,{children:la.map(m=>e.jsx(Z,{value:String(m),children:lt(s,m)},m))})]})]}),e.jsx(Ie,{rowId:"general.autoArchiveMergedWorktrees",title:s("Clean up merged worktrees"),description:s("When archiving idle conversations, also remove isolated worktrees that are merged and clean."),checked:a,onChange:r}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.autoDeleteArchivedDays",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s("Delete archived conversations after")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Permanently delete conversations that have been archived longer than this. This cannot be undone. Choosing a positive value deletes already-overdue archived conversations immediately.")})]}),e.jsxs(ne,{items:Object.fromEntries(ca.map(m=>[String(m),lt(s,m)])),value:String(o),onValueChange:m=>i(Number(m)),children:[e.jsx(ae,{className:"w-28",children:e.jsx(re,{})}),e.jsx(oe,{children:ca.map(m=>e.jsx(Z,{value:String(m),children:lt(s,m)},m))})]})]})]})}function zm(){const{t:s}=R(),t=g(o=>o.terminalShell),n=g(o=>o.setTerminalShell),a=rl(window.electronAPI.env.platform),r=Object.fromEntries(a.map(o=>[o,o==="auto"?s("System default"):Mm[o]]));return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.terminalShell",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s("Terminal shell")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Applies to new side panel terminals. SSH projects keep the remote login shell.")})]}),e.jsxs(ne,{items:r,value:t,onValueChange:o=>n(o),children:[e.jsx(ae,{className:"w-56",children:e.jsx(re,{})}),e.jsx(oe,{children:a.map(o=>e.jsx(Z,{value:o,children:r[o]},o))})]})]})}function _m(){const{t:s}=R(),t=g(x=>x.worktreeRoot),n=g(x=>x.setWorktreeRoot),[a,r]=l.useState(t),[o,i]=l.useState(null);l.useEffect(()=>{r(t)},[t]);const m=x=>{const h=x.trim();if(h&&!mm(h)){i(s("Enter an absolute path"));return}i(null),n(h)},u=async()=>{const x=await window.electronAPI.dialog.selectDirectory();x&&(r(x),m(x))};return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.worktreeRoot",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s("Worktree root directory")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Where isolated session worktrees are created. Leave empty to use the app data directory. Existing worktrees stay where they are.")})]}),e.jsxs("div",{className:"w-72 shrink-0 space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(J,{value:a,placeholder:s("Default location"),onChange:x=>r(x.target.value),onBlur:()=>m(a),onKeyDown:x=>{x.key==="Enter"&&m(a)}}),e.jsx(y,{variant:"outline",size:"sm",className:"shrink-0",onClick:()=>{u()},children:s("Browse")})]}),o&&e.jsx("p",{className:"text-xs text-destructive",children:o})]})]})}function Fm(){const{t:s}=R(),t=g(r=>r.windowsLocalShell),n=g(r=>r.setWindowsLocalShell),a={auto:s("Windows default (PowerShell)"),powershell:s("PowerShell"),bash:s("Git Bash")};return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.windowsLocalShell",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"text-sm",children:[s("Windows local command shell"),e.jsx(Ze,{})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Only the Windows local agent command tool. SSH and other platforms stay on bash. Takes effect on the next session.")})]}),e.jsxs(ne,{items:a,value:t,onValueChange:r=>n(r),children:[e.jsx(ae,{className:"w-56",children:e.jsx(re,{})}),e.jsx(oe,{children:Object.keys(a).map(r=>e.jsx(Z,{value:r,children:a[r]},r))})]})]})}function Ie({title:s,description:t,checked:n,onChange:a,rowId:r,children:o}){return e.jsxs("div",{className:"rounded-md border px-3 py-2.5","data-settings-row":r,children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t})]}),e.jsx(ce,{checked:n,onCheckedChange:i=>a(i===!0)})]}),o?e.jsx("div",{className:"mt-2",children:o}):null]})}function Ra(s,t){window.electronAPI.proxy.apply({mode:s,customUrl:t})}function Bm(){const{t:s}=R(),t=g(c=>c.proxyMode),n=g(c=>c.customProxyUrl),a=g(c=>c.setProxyMode),r=g(c=>c.setCustomProxyUrl),[o,i]=l.useState(n),[m,u]=l.useState(null);l.useEffect(()=>{i(n)},[n]);const x=c=>{a(c),Ra(c,n)},h=()=>{const c=o.trim();if(c&&!ol(c)){u(s("Enter an http(s) proxy URL"));return}u(null),r(c),Ra(t,c)};return e.jsxs("div",{className:"space-y-3","data-settings-row":"general.proxy",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium",children:s("Network proxy")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Used by model requests, the built-in browser, and agent tools")})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-sm font-medium",children:s("Proxy mode")}),e.jsxs(ne,{items:{system:s("Follow system proxy"),none:s("No proxy"),custom:s("Custom proxy")},value:t,onValueChange:c=>x(c),children:[e.jsx(ae,{className:"w-56",children:e.jsx(re,{})}),e.jsxs(oe,{children:[e.jsx(Z,{value:"system",children:s("Follow system proxy")}),e.jsx(Z,{value:"none",children:s("No proxy")}),e.jsx(Z,{value:"custom",children:s("Custom proxy")})]})]})]}),t==="custom"&&e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"pt-1.5 text-sm font-medium",children:s("Proxy URL")}),e.jsxs("div",{className:"min-w-0 space-y-1",children:[e.jsx(J,{value:o,placeholder:"http://127.0.0.1:7890",onChange:c=>i(c.target.value),onBlur:h,onKeyDown:c=>{c.key==="Enter"&&h()}}),m&&e.jsx("p",{className:"text-xs text-destructive",children:m})]})]})]})}function Um(){const{t:s}=R(),t=g(c=>c.customCaCertPath),n=g(c=>c.setCustomCaCertPath),[a,r]=l.useState(null),[o,i]=l.useState(!1);l.useEffect(()=>{let c=!0;return window.electronAPI.caCert.status().then(f=>{c&&r(f)}).catch(()=>{}),()=>{c=!1}},[]);const m=async c=>{n(c),i(!0);try{r(await window.electronAPI.caCert.apply(c))}catch{}finally{i(!1)}},u=async()=>{const c=await window.electronAPI.dialog.selectFile([...um]);c&&await m(c)},x={"not-absolute":s("Path must be absolute"),"not-found":s("File not found"),"not-file":s("Not a file"),"not-readable":s("File is not readable")},h=()=>a?a.source==="env"?s("Using NODE_EXTRA_CA_CERTS from the launch environment: {{path}}",{path:a.path}):a.source==="setting"?s("Set: {{path}}",{path:a.path}):a.source==="shell"?s("Not set; using NODE_EXTRA_CA_CERTS from the login shell: {{path}}",{path:a.path}):s("Not set"):"";return e.jsxs("div",{className:"space-y-3","data-settings-row":"general.caCert",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium",children:s("Custom CA certificate")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Trust an extra CA (PEM file) for model endpoints signed by a private CA. TLS verification stays on.")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{size:"sm",variant:"outline",disabled:o,onClick:()=>{u()},children:s("Choose certificate file")}),t&&e.jsx(y,{size:"sm",variant:"ghost",disabled:o,onClick:()=>{m("")},children:s("Clear")})]}),a?.error?e.jsx("p",{className:"break-all text-xs text-destructive",children:s("Certificate file unavailable ({{reason}}): {{path}}",{reason:x[a.error],path:a.settingPath})}):e.jsx("p",{className:"break-all text-xs text-muted-foreground",children:h()}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Changes restart the agent process right away (running turns are interrupted). Requests made by the app main process take effect after restarting the app.")})]})}function $m(){const{t:s}=R(),t=g(k=>k.autoUpdate),n=g(k=>k.setAutoUpdate),a=g(k=>k.autoRestartWhenIdle),r=g(k=>k.setAutoRestartWhenIdle),[o,i]=l.useState(null),[m,u]=l.useState(null),[x,h]=l.useState(!1),[c,f]=l.useState(!1);l.useEffect(()=>{let k=!0;window.electronAPI.updater.getState().then(M=>{k&&(u(M),M.status&&i($=>$??M.status))}).catch(()=>{});const I=window.electronAPI.updater.onStatus(i);return()=>{k=!1,I()}},[]);const d=m?.host==="server"?m:null,p=m?.host==="desktop"||d!==null&&d.mode!=="manual",j=(o?.status==="available"||o?.status==="downloaded")&&!!o.info,A=(()=>{if(!o)return null;switch(o.status){case"checking":return s("Checking for updates…");case"available":return s("New version {{version}} found",{version:o.info?.version??""});case"not-available":return s("You are on the latest version");case"downloading":return s("Downloading update… {{percent}}%",{percent:Math.round(o.progress?.percent??0)});case"downloaded":return s("New version {{version}} is ready — restart to update.",{version:o.info?.version??""});case"error":return d&&o.error?s("Update failed: {{error}}",{error:o.error}):s("Update check failed");default:return null}})(),v=o?.status==="checking"||o?.status==="downloading";return e.jsxs("div",{className:"space-y-3","data-settings-row":"general.updates",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium",children:s("Updates")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:d?Vm(d.mode,s):s("Application update settings")})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"text-sm",children:[s("Current version")," · ",Gm]}),A&&e.jsx("p",{className:"mt-0.5 truncate text-xs text-muted-foreground",children:A})]}),j&&e.jsx(y,{variant:"ghost",size:"sm",onClick:()=>f(!0),className:"ml-auto shrink-0",children:s("Release notes")}),o?.status==="downloaded"?e.jsx(y,{size:"sm",onClick:()=>{window.electronAPI.updater.quitAndInstall()},className:"shrink-0",children:s("Restart to update")}):p&&o?.status==="available"?e.jsx(y,{size:"sm",onClick:()=>{window.electronAPI.updater.downloadUpdate()},className:"shrink-0",children:s("Download update")}):e.jsx(y,{variant:"outline",size:"sm",disabled:v,onClick:()=>{window.electronAPI.updater.checkForUpdates()},className:"shrink-0",children:s("Check for updates")}),e.jsx(al,{open:c,onOpenChange:f,status:o,canDownload:p})]}),d?.canRestart&&e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s("Restart server")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Running tasks are interrupted; this page reconnects after the server is back.")})]}),e.jsx(y,{variant:"outline",size:"sm",onClick:()=>h(!0),className:"shrink-0",children:s("Restart")}),e.jsx(Gr,{open:x,onOpenChange:h,title:s("Restart server?"),description:s("Running tasks are interrupted; this page reconnects after the server is back."),confirmLabel:s("Restart"),onConfirm:()=>{h(!1),window.electronAPI.updater.restart()}})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s("Automatic updates")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Download and install updates automatically")})]}),e.jsx(ce,{checked:t,onCheckedChange:k=>{n(k),window.electronAPI.updater.setAutoUpdateEnabled(k)}})]}),e.jsxs("div",{className:`flex items-center justify-between gap-3 rounded-md border px-3 py-2.5 ${t?"":"opacity-60"}`,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s("Restart and apply when idle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("After the update is downloaded, restart automatically if no agent is running, nothing is queued, and there are no pending questions or approvals. The idle state must last 5 minutes, and a focused window also blocks it.")})]}),e.jsx(ce,{checked:t&&a,disabled:!t,onCheckedChange:k=>{r(k),window.electronAPI.updater.setAutoRestartWhenIdle(k)}})]})]})}function Vm(s,t){return t(s==="npm"?"Server updates install the new version with npm and restart.":"This server must be updated on the machine itself.")}const Gm="0.3.9",Km=["100%","100%","70%","100%","55%"],Wm=["100%","85%","60%"];function Hm({palette:s}){return e.jsxs("div",{className:"flex h-[88px] gap-1.5 p-[7px]",style:{background:s.canvas},children:[e.jsxs("div",{className:"flex w-[30%] flex-col gap-[5px] px-0.5 py-1",children:[e.jsx("i",{className:"block h-[9px] rounded-[3px] opacity-[.18]",style:{background:s.text}}),Km.slice(1).map((t,n)=>e.jsx("i",{className:"block h-[5px] rounded-[3px] opacity-55",style:{background:s.textSubtle,width:t}},n))]}),e.jsxs("div",{className:"flex flex-1 flex-col gap-[5px] rounded-md px-2.5 py-2",style:{background:s.surface,boxShadow:`0 0 0 1px ${s.border}`},children:[e.jsx("i",{className:"block h-1 w-[70%] rounded-sm opacity-75",style:{background:s.text}}),Wm.map(t=>e.jsx("i",{className:"block h-1 rounded-sm opacity-50",style:{background:s.textSubtle,width:t}},t)),e.jsx("b",{className:"mt-auto flex h-3.5 justify-end rounded-full p-[3px]",style:{background:s.sunken,boxShadow:`0 0 0 1px ${s.border}`},children:e.jsx("span",{"data-theme-accent":!0,className:"size-2 rounded-full",style:{background:s.accent}})})]})]})}const Oa="overflow-hidden rounded-lg border text-left transition-shadow";function qm({themes:s,selected:t,mode:n,onSelect:a,onGetMore:r}){const{t:o}=R();return e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[s.map(i=>{const m=i.id===t;return e.jsxs("button",{type:"button","data-theme-card":i.id,"aria-pressed":m,onClick:()=>a(i.id),className:K(Oa,"bg-card",m?"border-transparent shadow-[0_0_0_2px_var(--brand)]":"hover:border-input"),children:[e.jsx(Hm,{palette:i[n]}),e.jsxs("div",{className:"flex items-center gap-1.5 border-t px-2.5 py-[7px] text-sm",children:[e.jsx("span",{className:"truncate font-medium",children:i.name}),e.jsx("span",{className:K("ml-auto shrink-0 truncate rounded-full px-1.5 py-px text-[10.5px]",i.source.kind==="plugin"?"max-w-[60%] bg-brand/12 text-brand":"bg-muted text-subtle-foreground"),children:i.source.kind==="plugin"?o("Plugin · {{name}}",{name:i.source.pluginName}):o("Built-in")})]})]},i.id)}),r&&e.jsxs("button",{type:"button",onClick:r,className:K(Oa,"flex min-h-[124px] flex-col items-center justify-center gap-1.5 border-dashed text-sm text-subtle-foreground hover:border-input hover:text-foreground"),children:[e.jsx(Xs,{className:"size-[18px]"}),o("Get more themes")]})]})}function un({rowId:s,title:t,description:n,children:a}){return e.jsxs("div",{"data-settings-row":s,className:"flex min-h-12 items-center justify-between gap-4 px-3.5 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium",children:t}),n&&e.jsx("p",{className:"text-xs text-muted-foreground",children:n})]}),e.jsx("div",{className:"flex shrink-0 items-center gap-2",children:a})]})}function Ym({children:s}){return e.jsx("div",{className:"divide-y rounded-lg border bg-card",children:s})}function ls({label:s,value:t,onCommit:n,min:a=0,max:r=100,step:o,unit:i="%",formatSuffix:m,onPreview:u,trailing:x,valueClassName:h="w-12"}){const[c,f]=l.useState(t);l.useEffect(()=>{f(t)},[t]);const d=m?.(c);return e.jsxs("div",{className:K("grid items-center gap-4",x?"grid-cols-[9.5rem_minmax(0,1fr)_auto]":"grid-cols-[100px_1fr]"),children:[e.jsx("span",{className:"text-sm font-medium",children:s}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(pl,{min:a,max:r,step:o,value:c,onValueChange:p=>{const j=Array.isArray(p)?p[0]:p;f(j),u?.(j)},onValueCommitted:p=>n(Array.isArray(p)?p[0]:p)}),e.jsxs("span",{className:K("shrink-0 text-right text-sm text-muted-foreground tabular-nums",d?"w-28":h),children:[c,i,d?` · ${d}`:""]})]}),x]})}function Jm(){const{t:s}=R(),t=g(O=>O.backgroundImageEnabled),n=g(O=>O.setBackgroundImageEnabled),a=g(O=>O.backgroundSourceType),r=g(O=>O.setBackgroundSourceType),o=g(O=>O.backgroundImagePath),i=g(O=>O.setBackgroundImagePath),m=g(O=>O.backgroundFolderPath),u=g(O=>O.setBackgroundFolderPath),x=g(O=>O.backgroundUrlPath),h=g(O=>O.setBackgroundUrlPath),c=g(O=>O.backgroundRandomEnabled),f=g(O=>O.setBackgroundRandomEnabled),d=g(O=>O.backgroundRandomInterval),p=g(O=>O.setBackgroundRandomInterval),j=g(O=>O.backgroundOpacity),b=g(O=>O.setBackgroundOpacity),A=g(O=>O.backgroundBlur),v=g(O=>O.setBackgroundBlur),k=g(O=>O.backgroundBrightness),I=g(O=>O.setBackgroundBrightness),M=g(O=>O.backgroundSaturation),$=g(O=>O.setBackgroundSaturation),E=g(O=>O.backgroundMask),L=g(O=>O.setBackgroundMask),T=g(O=>O.backgroundComposerOpacity),C=g(O=>O.setBackgroundComposerOpacity),S=g(O=>O.backgroundCodeOpacity),W=g(O=>O.setBackgroundCodeOpacity),q=g(O=>O.backgroundSizeMode),N=g(O=>O.setBackgroundSizeMode),z=g(O=>O.bumpBackgroundRefresh),H=fl()?.source==="theme",U=a==="file"?o:a==="folder"?m:x,[B,ie]=l.useState(U);l.useEffect(()=>{ie(U)},[U]);const F=l.useCallback(()=>{const O=B.trim();a==="file"?i(O):a==="folder"?u(O):h(O)},[B,a,i,u,h]),[X,V]=l.useState(d);l.useEffect(()=>{V(d)},[d]);const le=async()=>{if(a==="folder"){const O=await window.electronAPI.dialog.selectDirectory();O&&u(O)}else{const O=await window.electronAPI.dialog.selectFile([...vl,...bl]);O&&i(O)}},_=[{value:"file",label:s("Single image")},{value:"folder",label:s("Folder (random)")},{value:"url",label:s("Remote URL")}],de=[{value:"cover",label:s("Cover")},{value:"contain",label:s("Contain")},{value:"repeat",label:s("Repeat")},{value:"center",label:s("Center")}],ue=s(a==="file"?"Image path":a==="folder"?"Folder path":"Image URL");return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between border-t pt-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("Background image")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("Show a custom image behind the interface")})]}),e.jsx(ce,{checked:t,onCheckedChange:O=>n(O===!0)})]}),H&&e.jsx("p",{className:"text-sm text-muted-foreground",children:s("The current theme has its own background. Turn this on to replace it with your image.")}),t&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:s("Source type")}),e.jsxs(ne,{items:_,value:a,onValueChange:O=>r(O),children:[e.jsx(ae,{className:"w-48",children:e.jsx(re,{})}),e.jsx(oe,{children:_.map(O=>e.jsx(Z,{value:O.value,children:O.label},O.value))})]})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:ue}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(J,{value:B,onChange:O=>ie(O.target.value),onBlur:F,onKeyDown:O=>{O.nativeEvent.isComposing||O.key==="Enter"&&(F(),O.currentTarget.blur())},placeholder:a==="url"?"https://example.com/image.jpg":"",className:"flex-1"}),a!=="url"&&e.jsx(y,{variant:"outline",size:"icon",onClick:le,"aria-label":s("Browse"),children:a==="folder"?e.jsx(Tn,{className:"h-4 w-4"}):e.jsx(Lu,{className:"h-4 w-4"})}),a!=="file"&&e.jsx(y,{variant:"outline",size:"icon",onClick:z,"aria-label":s("Refresh now"),children:e.jsx(ns,{className:"h-4 w-4"})})]})]}),a!=="file"&&e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:s("Auto switch")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ce,{checked:c,onCheckedChange:O=>f(O===!0)}),c&&e.jsxs(e.Fragment,{children:[e.jsx(J,{type:"number",min:5,max:86400,value:X,onChange:O=>V(Number(O.target.value)),onBlur:()=>p(X),onKeyDown:O=>{O.key==="Enter"&&(p(X),O.currentTarget.blur())},className:"w-24"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:s("seconds")})]})]})]}),e.jsx(ls,{label:s("Background visibility"),value:Math.round(j*100),onCommit:O=>b(O/100)}),e.jsx(ls,{label:s("Blur"),value:A,onCommit:v,max:20,unit:"px"}),e.jsx(ls,{label:s("Brightness"),value:Math.round(k*100),onCommit:O=>I(O/100),max:200}),e.jsx(ls,{label:s("Saturation"),value:Math.round(M*100),onCommit:O=>$(O/100),max:200}),e.jsx(ls,{label:s("Overlay"),value:Math.round(E*100),onCommit:O=>L(O/100)}),e.jsx(ls,{label:s("Composer opacity"),value:Math.round(T*100),onCommit:O=>C(O/100)}),e.jsx(ls,{label:s("Code block opacity"),value:Math.round(S*100),onCommit:O=>W(O/100)}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:s("Size mode")}),e.jsxs(ne,{items:de,value:q,onValueChange:O=>N(O),children:[e.jsx(ae,{className:"w-48",children:e.jsx(re,{})}),e.jsx(oe,{children:de.map(O=>e.jsx(Z,{value:O.value,children:O.label},O.value))})]})]})]})]})}function Xm({theme:s,fontSize:t,fontFamily:n,fontWeight:a}){const r=[{id:"prompt1",text:"$ ",color:s.green},{id:"cmd1",text:"ls -la",color:s.foreground},{id:"nl1",text:`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./globals-1URrQWJU.js","./globals-DoPyZAQo.css"])))=>i.map(i=>d[i]);
2
+ import{c as Oe,w as vi,D as ea,j as e,A as bi,r as l,u as Or,a as Dr,b as vn,d as Lr,t as zr,C as sa,e as K,I as J,f as yi,X as js,h as wi,i as Ni,Z as cs,k as ki,S as Ci,l as Si,m as Ii,n as Ai,o as Ei,p as R,q as g,B as y,s as ye,v as we,x as Ne,y as ke,z as Ye,E as Ce,F as Le,G as Ee,H as _r,J as Te,K as ta,L as Mi,M as ut,N as mt,O as ne,P as ae,Q as re,R as oe,T as Z,U as Pi,V as Ze,W as Ti,Y as Ri,_ as Fr,$ as Oi,a0 as Rt,a1 as Br,a2 as Di,a3 as Ur,a4 as Li,a5 as na,a6 as $r,a7 as zi,a8 as _i,a9 as Fi,aa,ab as Bi,ac as Ui,ad as $i,ae as Vi,af as Gi,ag as Ki,ah as Wi,ai as Hi,aj as qi,ak as Yi,al as Ji,am as Ot,an as Xi,ao as Qi,ap as Zi,aq as el,ar as sl,as as tl,at as Me,au as bn,av as pt,aw as $e,ax as Vr,ay as Ms,az as Ve,aA as Ke,aB as yn,aC as Rs,aD as wn,aE as Nn,aF as kn,aG as Cn,aH as Sn,aI as In,aJ as An,aK as es,aL as ra,aM as oa,aN as ze,aO as Qe,aP as nl,aQ as al,aR as Gr,aS as ce,aT as ia,aU as Dt,aV as la,aW as ca,aX as ft,aY as rl,aZ as ol,a_ as Lt,a$ as Xs,b0 as Kr,b1 as En,b2 as il,b3 as Mn,b4 as Wr,b5 as ll,b6 as cl,b7 as dl,b8 as Hr,b9 as ul,ba as ml,bb as xl,bc as qr,bd as Ds,be as rt,bf as hl,bg as Pn,bh as pl,bi as fl,bj as Tn,bk as ns,bl as gl,bm as jl,bn as Yr,bo as vl,bp as bl,bq as yl,br as Jr,bs as Rn,bt as Re,bu as se,bv as Pe,bw as wl,bx as Nl,by as kl,bz as Cl,bA as Sl,bB as da,bC as Il,bD as Al,bE as Qs,bF as Zs,bG as Je,bH as Ws,bI as tn,bJ as El,bK as Ml,bL as nn,bM as hs,bN as Xr,bO as Pl,bP as Tl,bQ as On,bR as Rl,bS as ua,bT as Qr,bU as Ol,bV as Dl,bW as Zr,bX as Ge,bY as Ll,bZ as gt,b_ as zl,b$ as ma,c0 as _l,c1 as Fl,c2 as Bl,c3 as Xe,c4 as Ul,c5 as xa,c6 as ha,c7 as $l,c8 as pa,c9 as Vl,ca as Gl,cb as Kl,cc as Wl,cd as We,ce as zt,cf as fa,cg as Hl,ch as ql,ci as eo,cj as Yl,ck as so,cl as Jl,cm as Xl,cn as Ql,co as Zl,cp as Dn,cq as ec,cr as to,cs as sc,ct as tc,cu as et,cv as nc,cw as ac,cx as rc,cy as oc,cz as an,cA as no,cB as ot,cC as ic,cD as lc,cE as cc,cF as he,cG as pe,cH as Nt,cI as Ln,cJ as ao,cK as zn,cL as ro,cM as rn,cN as ga,cO as on,cP as oo,cQ as io,cR as dc,cS as lo,cT as uc,cU as mc,cV as xc,cW as hc,cX as pc,cY as fc,cZ as gc,c_ as jc,c$ as vc,d0 as bc,d1 as ja,d2 as co,d3 as uo,d4 as mo,d5 as xo,d6 as yc,d7 as wc,d8 as va,d9 as Hs,da as Nc,db as ho,dc as po,dd as fo,de as kc,df as Cc,dg as Sc,dh as Ic,di as Ac,dj as Ec,dk as Mc,dl as Pc,dm as Tc,dn as Rc,dp as Oc,dq as Dc,dr as go,ds as xt,dt as Ps,du as jo,dv as Lc,dw as ba,dx as zc,dy as _c,dz as Fc,dA as Bc,dB as Uc,dC as $c,dD as Vc,dE as Gc,dF as Kc,dG as Wc,dH as Hc,dI as ln,dJ as qc,dK as jt,dL as Yc,dM as _n,dN as vo,dO as bo,dP as Fn,dQ as yo,dR as wo,dS as No,dT as ko,dU as Co,dV as Jc,dW as Xc,dX as Qc,dY as Zc,dZ as ed,d_ as sd,d$ as td,e0 as nd,e1 as ad,e2 as rd,e3 as od,e4 as id,e5 as ld,e6 as cd,e7 as dd,e8 as ud,e9 as md,ea as xd,eb as hd,ec as So,ed as Io,ee as Ao,ef as pd,eg as Eo,eh as fd,ei as gd,ej as jd,ek as Mo,el as vd,em as bd,en as ya,eo as it,ep as yd,eq as wd,er as Nd,es as kd,et as Cd,eu as Sd,ev as wa,ew as Id,ex as Ad,ey as Ed,ez as Md,eA as Pd,eB as Td,eC as Rd,eD as Po,eE as Od,eF as Dd,eG as Ld,eH as vt,eI as zd,eJ as _d,eK as Fd,eL as Bd,eM as us,eN as Ud,eO as To,eP as $d,eQ as Vd,eR as Gd,eS as Kd,eT as Wd,eU as Hd,eV as qd,eW as Yd,eX as Jd,eY as Ro,eZ as Xd,e_ as Qd,e$ as Zd,f0 as eu,f1 as su,f2 as tu,f3 as nu,f4 as au,f5 as ru,f6 as ou,f7 as iu,f8 as lu,f9 as cu,fa as du,fb as uu,fc as mu,fd as xu,fe as Na,ff as hu,fg as pu,fh as ka,fi as Ca,fj as fu}from"./globals-1URrQWJU.js";import{c as Oo}from"./cytoscape.esm-DzSz-X2X.js";import{f as gu}from"./cytoscape-fcose-BJkAlKB8.js";const ju=[["path",{d:"M10 22V7a1 1 0 0 0-1-1H4a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-5a1 1 0 0 0-1-1H2",key:"1ah6g2"}],["rect",{x:"14",y:"2",width:"8",height:"8",rx:"1",key:"88lufb"}]],vu=Oe("blocks",ju);const bu=[["path",{d:"M12 5v16",key:"1f6ucr"}],["path",{d:"M20.001 19A2 2 0 0022 17V5a2 2 0 00-1.999-2L16 3.002A5 5 0 0012 5a5 5 0 00-4-2H4a2 2 0 00-2 2v12a2 2 0 001.999 2H8a5 5 0 014 2 5 5 0 014-2z",key:"1fyvmf"}]],yu=Oe("book-open",bu);const wu=[["path",{d:"M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z",key:"hh9hay"}],["path",{d:"m3.3 7 8.7 5 8.7-5",key:"g66t2b"}],["path",{d:"M12 22V12",key:"d0xqtd"}]],Nu=Oe("box",wu);const ku=[["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["path",{d:"M18 17V9",key:"2bz60n"}],["path",{d:"M13 17V5",key:"1frdt8"}],["path",{d:"M8 17v-3",key:"17ska0"}]],Cu=Oe("chart-column",ku);const Su=[["path",{d:"M13.659 22H18a2 2 0 0 0 2-2V8a2.4 2.4 0 0 0-.706-1.706l-3.588-3.588A2.4 2.4 0 0 0 14 2H6a2 2 0 0 0-2 2v11.5",key:"4pqfef"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M8 12v-1",key:"1ej8lb"}],["path",{d:"M8 18v-2",key:"qcmpov"}],["path",{d:"M8 7V6",key:"1nbb54"}],["circle",{cx:"8",cy:"20",r:"2",key:"ckkr5m"}]],Iu=Oe("file-archive",Su);const Au=[["path",{d:"M14.364 13.634a2 2 0 0 0-.506.854l-.837 2.87a.5.5 0 0 0 .62.62l2.87-.837a2 2 0 0 0 .854-.506l4.013-4.009a1 1 0 0 0-3.004-3.004z",key:"ukzhwg"}],["path",{d:"M14.487 7.858A1 1 0 0 1 14 7V2",key:"1klhew"}],["path",{d:"M20 19.645V20a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l2.516 2.516",key:"rxaxab"}],["path",{d:"M8 18h1",key:"13wk12"}]],Eu=Oe("file-pen-line",Au);const Mu=[["path",{d:"M4 22V4a1 1 0 0 1 .4-.8A6 6 0 0 1 8 2c3 0 5 2 7.333 2q2 0 3.067-.8A1 1 0 0 1 20 4v10a1 1 0 0 1-.4.8A6 6 0 0 1 16 16c-3 0-5-2-8-2a6 6 0 0 0-4 1.528",key:"1jaruq"}]],Pu=Oe("flag",Mu);const Tu=[["path",{d:"M12 22v-6",key:"6o8u61"}],["path",{d:"M12 8V2",key:"1wkif3"}],["path",{d:"M4 12H2",key:"rhcxmi"}],["path",{d:"M10 12H8",key:"s88cx1"}],["path",{d:"M16 12h-2",key:"10asgb"}],["path",{d:"M22 12h-2",key:"14jgyd"}],["path",{d:"m15 19-3-3-3 3",key:"e37ymu"}],["path",{d:"m15 5-3 3-3-3",key:"19d6lf"}]],Ru=Oe("fold-vertical",Tu);const Ou=[["path",{d:"M2 9.5a5.5 5.5 0 0 1 9.591-3.676.56.56 0 0 0 .818 0A5.49 5.49 0 0 1 22 9.5c0 2.29-1.5 4-3 5.5l-5.492 5.313a2 2 0 0 1-3 .019L5 15c-1.5-1.5-3-3.2-3-5.5",key:"mvr1a0"}]],Sa=Oe("heart",Ou);const Du=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}]],Lu=Oe("image",Du);const zu=[["circle",{cx:"12",cy:"16",r:"1",key:"1au0dj"}],["rect",{x:"3",y:"10",width:"18",height:"12",rx:"2",key:"6s8ecr"}],["path",{d:"M7 10V7a5 5 0 0 1 10 0v3",key:"1pqi11"}]],Do=Oe("lock-keyhole",zu);const _u=[["path",{d:"M12 22a1 1 0 0 1 0-20 10 9 0 0 1 10 9 5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z",key:"e79jfc"}],["circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor",key:"1okk4w"}],["circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor",key:"f64h9f"}],["circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor",key:"qy21gx"}],["circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor",key:"fotxhn"}]],Fu=Oe("palette",_u);const Bu=[["path",{d:"m15 15 6 6m-6-6v4.8m0-4.8h4.8",key:"17vawe"}],["path",{d:"M9 19.8V15m0 0H4.2M9 15l-6 6",key:"chjx8e"}],["path",{d:"M15 4.2V9m0 0h4.8M15 9l6-6",key:"lav6yq"}],["path",{d:"M9 4.2V9m0 0H4.2M9 9 3 3",key:"1pxi2q"}]],Uu=Oe("shrink",Bu);const $u=[["path",{d:"M15 21v-5a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v5",key:"slp6dd"}],["path",{d:"M17.774 10.31a1.12 1.12 0 0 0-1.549 0 2.5 2.5 0 0 1-3.451 0 1.12 1.12 0 0 0-1.548 0 2.5 2.5 0 0 1-3.452 0 1.12 1.12 0 0 0-1.549 0 2.5 2.5 0 0 1-3.77-3.248l2.889-4.184A2 2 0 0 1 7 2h10a2 2 0 0 1 1.653.873l2.895 4.192a2.5 2.5 0 0 1-3.774 3.244",key:"o0xfot"}],["path",{d:"M4 10.95V19a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8.05",key:"wn3emo"}]],Vu=Oe("store",$u);const Gu=[["circle",{cx:"12",cy:"12",r:"4",key:"4exip2"}],["path",{d:"M12 2v2",key:"tus03m"}],["path",{d:"M12 20v2",key:"1lh1kg"}],["path",{d:"m4.93 4.93 1.41 1.41",key:"149t6j"}],["path",{d:"m17.66 17.66 1.41 1.41",key:"ptbguv"}],["path",{d:"M2 12h2",key:"1t8f8n"}],["path",{d:"M20 12h2",key:"1q8mjw"}],["path",{d:"m6.34 17.66-1.41 1.41",key:"1m8zz5"}],["path",{d:"m19.07 4.93-1.41 1.41",key:"1shlcs"}]],Ku=Oe("sun",Gu);const Wu=[["path",{d:"M12 3v12",key:"1x0j5s"}],["path",{d:"m17 8-5-5-5 5",key:"7q97r8"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}]],Lo=Oe("upload",Wu);function Hu(s){return s&&typeof s=="object"&&!Array.isArray(s)?s:null}function qu(s){try{const t=new URL(s);return(t.protocol==="http:"||t.protocol==="https:")&&!t.username&&!t.password&&!t.search&&!t.hash&&!s.includes("?")&&!s.includes("#")}catch{return!1}}function Yu(s){const t=Hu(s);if(!t||Object.keys(t).some(m=>!["providerId","modelId","protocol","baseUrl","apiKey"].includes(m)))return null;const{providerId:n,modelId:a,protocol:r,baseUrl:o,apiKey:i}=t;return typeof n!="string"||!n.trim()||typeof a!="string"||!a.trim()||typeof i!="string"||!i.trim()||typeof o!="string"||!qu(o)||r!=="openai"&&r!=="openai-compatible"&&r!=="gemini"?null:{providerId:n,modelId:a,protocol:r,baseUrl:o,apiKey:i}}function Ju(s,t){if(s?.enabled!==!0||s.oauthAccountKey||s.oauthAccountPool||typeof s.apiKey!="string"||!s.apiKey.trim()||typeof s.baseUrl!="string")return null;let n;if(s.api==="google-generative-ai")n="gemini";else if(s.api==="openai-completions"||s.api==="openai-responses"){let o="";try{o=new URL(s.baseUrl).hostname.toLowerCase()}catch{}n=s.catalogId!=="__custom"&&(s.catalogId==="openai"||!s.catalogId&&o==="api.openai.com")?"openai":"openai-compatible"}else return null;const a=n==="gemini"?ea["google-generative-ai"]:n==="openai"?ea["openai-responses"]:"";let r=s.baseUrl.trim().replace(/\/+$/,"")||a;if(n==="gemini"&&r&&(r=vi(r,"v1beta")),n==="openai"&&r)try{new URL(r).pathname==="/"&&(r=`${r}/v1`)}catch{}return Yu({providerId:s.id,modelId:t,protocol:n,baseUrl:r,apiKey:s.apiKey})}function Xu(s){return Array.isArray(s?.models)?s.models.filter(t=>!!t&&typeof t=="object"&&typeof t.id=="string"&&!!t.id.trim()&&t.enabled!==!1&&t.imageGeneration===!0):[]}function Qu(s){return s.flatMap(t=>{const n=Xu(t).filter(a=>Ju(t,a.id));return n.length?[{...t,models:n}]:[]})}function Zu(s){const{multiple:t=!1,defaultValue:n,value:a,onValueChange:r,autoComplete:o,...i}=s;return e.jsx(bi,{...i,selectionMode:t?"multiple":"single",selectedValue:a,defaultSelectedValue:n,onSelectedValueChange:r,formAutoComplete:o})}const em=l.forwardRef(function(t,n){const{selected:a}=Or();return t.keepMounted||a?e.jsx(sm,{...t,ref:n}):null}),sm=l.memo(l.forwardRef((s,t)=>{const{render:n,className:a,style:r,keepMounted:o,...i}=s,{selected:m}=Or(),u=l.useRef(null),{transitionStatus:x,setMounted:h}=Dr(m),f=vn("span",s,{ref:[t,u],state:{selected:m,transitionStatus:x},props:[{"aria-hidden":!0,children:"✔️"},i],stateAttributesMapping:zr});return Lr({open:m,ref:u,onComplete(){m||h(!1)}}),f})),Bn=l.createContext({chipsRef:null,multiple:!1,rootRef:null});function tm(s){const t=l.useRef(null),n=l.useRef(null);return e.jsx(Bn.Provider,{value:{chipsRef:t,multiple:!!s.multiple,rootRef:n},children:e.jsx("div",{ref:n,className:"contents",children:e.jsx(Zu,{...s})})})}function nm({className:s,showTrigger:t=!0,showClear:n=!1,startAddon:a,size:r,...o}){const{multiple:i}=l.useContext(Bn),m=r??"default";return i?e.jsx(sa,{className:K("min-w-12 flex-1 text-base outline-none sm:text-sm [[data-slot=combobox-chip]+&]:ps-0.5",m==="sm"?"ps-1.5":"ps-2",s),"data-size":typeof m=="string"?m:void 0,"data-slot":"combobox-input",size:typeof m=="number"?m:void 0,...o}):e.jsxs("div",{className:"relative w-full has-disabled:opacity-64",children:[a&&e.jsx("div",{"aria-hidden":"true",className:"[&_svg]:-mx-0.5 pointer-events-none absolute inset-y-0 start-px z-10 flex items-center ps-[calc(--spacing(3)-1px)] opacity-80 has-[+[data-size=sm]]:ps-[calc(--spacing(2.5)-1px)] [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4","data-slot":"combobox-start-addon",children:a}),e.jsx(sa,{className:K(a&&"data-[size=sm]:*:data-[slot=combobox-input]:ps-[calc(--spacing(7.5)-1px)] *:data-[slot=combobox-input]:ps-[calc(--spacing(8.5)-1px)] sm:data-[size=sm]:*:data-[slot=combobox-input]:ps-[calc(--spacing(7)-1px)] sm:*:data-[slot=combobox-input]:ps-[calc(--spacing(8)-1px)]",m==="sm"?"has-[+[data-slot=combobox-trigger],+[data-slot=combobox-clear]]:*:data-[slot=combobox-input]:pe-6.5":"has-[+[data-slot=combobox-trigger],+[data-slot=combobox-clear]]:*:data-[slot=combobox-input]:pe-7",s),"data-slot":"combobox-input",render:e.jsx(J,{className:"has-disabled:opacity-100",size:m}),...o}),t&&e.jsx(am,{className:K("-translate-y-1/2 absolute top-1/2 inline-flex size-8 shrink-0 cursor-pointer items-center justify-center rounded-md border border-transparent opacity-80 outline-none transition-opacity pointer-coarse:after:absolute pointer-coarse:after:min-h-11 pointer-coarse:after:min-w-11 hover:opacity-100 has-[+[data-slot=combobox-clear]]:hidden sm:size-7 [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",m==="sm"?"end-0":"end-0.5"),children:e.jsx(yi,{})}),n&&e.jsx(lm,{className:K("-translate-y-1/2 absolute top-1/2 inline-flex size-8 shrink-0 cursor-pointer items-center justify-center rounded-md border border-transparent opacity-80 outline-none transition-opacity pointer-coarse:after:absolute pointer-coarse:after:min-h-11 pointer-coarse:after:min-w-11 hover:opacity-100 has-[+[data-slot=combobox-clear]]:hidden sm:size-7 [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",m==="sm"?"end-0":"end-0.5"),children:e.jsx(js,{})})]})}function am({className:s,...t}){return e.jsx(Ai,{className:s,"data-slot":"combobox-trigger",...t})}function rm({className:s,children:t,sideOffset:n=4,zIndex:a,...r}){const{chipsRef:o,rootRef:i}=l.useContext(Bn);let m=cs.DROPDOWN;if(a!==void 0)m=a;else{const u=i?.current;u&&(u.closest('[data-slot="dialog-popup"] [data-slot="dialog-popup"]')?m=cs.DROPDOWN_IN_NESTED_MODAL:u.closest('[data-slot="dialog-popup"]')&&(m=cs.DROPDOWN_IN_MODAL))}return e.jsx(wi,{children:e.jsx(Ni,{anchor:o,className:"select-none",style:{zIndex:m},"data-slot":"combobox-positioner",sideOffset:n,children:e.jsx("span",{className:K("relative flex max-h-full origin-(--transform-origin) rounded-lg border bg-popover bg-clip-padding transition-[scale,opacity] before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-lg)-1px)] before:shadow-lg has-data-starting-style:scale-98 has-data-starting-style:opacity-0 dark:not-in-data-[slot=group]:bg-clip-border",s),children:e.jsx(ki,{className:"flex max-h-[min(var(--available-height),23rem)] w-(--anchor-width) max-w-(--available-width) flex-col","data-slot":"combobox-popup",...r,children:t})})})})}function om({className:s,children:t,endAddon:n,...a}){return e.jsxs(Ii,{className:K("grid min-h-8 in-data-[side=none]:min-w-[calc(var(--anchor-width)+1.25rem)] cursor-default grid-cols-[1rem_1fr_auto] items-center gap-2 rounded-sm py-1 ps-2 pe-4 text-base outline-none data-disabled:pointer-events-none data-highlighted:bg-accent data-highlighted:text-accent-foreground data-disabled:opacity-64 sm:min-h-7 sm:text-sm [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",s),"data-slot":"combobox-item",...a,children:[e.jsx(em,{className:"col-start-1",children:e.jsx("svg",{"aria-hidden":"true",fill:"none",height:"24",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",viewBox:"0 0 24 24",width:"24",xmlns:"http://www.w3.org/2000/svg",children:e.jsx("path",{d:"M5.252 12.7 10.2 18.63 18.748 5.37"})})}),e.jsx("div",{className:"col-start-2",children:t}),n&&e.jsx("div",{className:"col-start-3 flex items-center",children:n})]})}function im({className:s,...t}){return e.jsx(Ci,{scrollbarGutter:!0,scrollFade:!0,children:e.jsx(Si,{className:K("not-empty:scroll-py-1 not-empty:px-1 not-empty:py-1 in-data-has-overflow-y:pe-3",s),"data-slot":"combobox-list",...t})})}function lm({className:s,...t}){return e.jsx(Ei,{className:s,"data-slot":"combobox-clear",...t})}function cm(){const{t:s}=R(),t=g(d=>d.contextMenuOpen),n=g(d=>d.setContextMenuOpen),[a,r]=l.useState(!1),[o,i]=l.useState(!1),m=d=>d.target==="reveal"?s("File manager"):d.target==="vscode"?s("VS Code"):d.applicationPath.split(/[/\\]/).at(-1)?.replace(/\.(exe|app)$/i,"")||d.applicationPath,u=t.filter(d=>d.enabled).map(m),x=u.length?`${u.slice(0,2).join(", ")}${u.length>2?` +${u.length-2}`:""}`:s("No opening methods enabled"),h=d=>{if(d.length>32){Te({type:"error",title:s("Context menu opening"),description:s("You can configure up to 32 opening methods.")});return}n(d)},c=(d,p)=>{const j=g.getState().contextMenuOpen;n(j.map(b=>b.id===d.id?{...b,enabled:p}:b))},f=async()=>{i(!0);try{const d=await window.electronAPI.dialog.selectFile();if(!d)return;if(!_r(d)){Te({type:"error",title:s("Context menu opening"),description:s("The selected application path is invalid.")});return}const p=g.getState().contextMenuOpen,j=ta(d),b=p.find(A=>A.target==="application"&&ta(A.applicationPath)===j);if(b){h(p.map(A=>A.id===b.id?{...A,enabled:!0}:A));return}h([...p,{id:crypto.randomUUID(),target:"application",applicationPath:d,enabled:!0}])}catch(d){Te({type:"error",title:s("Context menu opening"),description:d instanceof Error?d.message:String(d)})}finally{i(!1)}};return e.jsxs("div",{className:"space-y-2 rounded-md border p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("h5",{className:"text-sm font-medium",children:s("Context menu opening")}),e.jsx(y,{variant:"outline",size:"sm",onClick:()=>r(!0),children:s("Configure list")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Select the opening methods shown in file link context menus. You can add multiple applications.")}),e.jsx("p",{className:"truncate text-xs text-muted-foreground",title:u.join(", "),children:x}),e.jsx(ye,{open:a,onOpenChange:r,children:e.jsxs(we,{zIndexLevel:"nested",children:[e.jsxs(Ne,{children:[e.jsx(ke,{children:s("Context menu opening")}),e.jsx(Ye,{children:s("Select the opening methods shown in file link context menus. You can add multiple applications.")})]}),e.jsxs(Ce,{className:"space-y-2",children:[t.length===0&&e.jsx("p",{className:"py-6 text-center text-sm text-muted-foreground",children:s("No opening methods enabled")}),t.map(d=>{const p=m(d);return e.jsxs("div",{className:"flex items-center gap-3 rounded-md border p-3",children:[e.jsxs("label",{className:"flex min-w-0 flex-1 cursor-pointer items-center gap-3",children:[e.jsx(Le,{checked:d.enabled,disabled:o,"aria-label":p,onCheckedChange:j=>c(d,j)}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-sm",title:p,children:p}),d.target==="application"&&e.jsx("span",{className:"block truncate text-xs text-muted-foreground",title:d.applicationPath,children:d.applicationPath})]})]}),e.jsx(y,{variant:"ghost",size:"sm",disabled:o,onClick:()=>n(g.getState().contextMenuOpen.filter(j=>j.id!==d.id)),children:s("Delete")})]},d.id)})]}),e.jsxs(Ee,{children:[e.jsx(y,{variant:"outline",disabled:o,onClick:()=>{f()},children:s("Add application")}),e.jsx(y,{onClick:()=>r(!1),children:s("Close")})]})]})})]})}const Ia=["internal","reveal","system","application"];function Aa({extension:s,value:t,disabled:n,onChange:a}){const{t:r}=R(),o={internal:r("Open inside EnsoCode"),reveal:r("Reveal in file manager"),system:r("System default application"),application:r("Selected application")},i=ut(`file${s}`),m=mt(`file${s}`)!==null,u=i?m?["internal","reveal"]:["reveal"]:Ia,x=i&&(!m||t==="system"||t==="application")?"reveal":t;return e.jsxs(ne,{items:Object.fromEntries(u.map(h=>[h,o[h]])),value:x,disabled:n,onValueChange:h=>{Ia.includes(h)&&a(h)},children:[e.jsx(ae,{className:"w-52","aria-label":r("File opening"),children:e.jsx(re,{})}),e.jsx(oe,{children:u.map(h=>e.jsx(Z,{value:h,disabled:h==="internal"&&!m,children:o[h]},h))})]})}function dm(){const{t:s}=R(),t=g(k=>k.fileOpenRules),n=g(k=>k.setFileOpenRules),[a,r]=l.useState(""),[o,i]=l.useState("internal"),[m,u]=l.useState(),[x,h]=l.useState(null),[c,f]=l.useState(!1),d=Mi([{extension:a,target:"reveal"}])[0]?.extension,p=k=>{Te({type:"error",title:s("File opening"),description:k})},j=async k=>{f(!0);try{const I=await window.electronAPI.dialog.selectFile();if(I){if(!_r(I)){p(s("The selected application path is invalid."));return}k(I)}}catch(I){p(I instanceof Error?I.message:String(I))}finally{f(!1)}},b=k=>{const I=Pi(k);return I?(n(I),!0):(p(s("Could not complete the file action.")),!1)},A=(k,I,M)=>{if(I==="internal"&&!mt(`file${k.extension}`)){p(s("This extension does not support internal preview."));return}b(t.map($=>$.extension===k.extension?{extension:k.extension,target:I,...I==="application"?{applicationPath:M}:{}}:$))},v=()=>{if(!d){h(s("Enter a valid file extension, for example .md."));return}if(t.some($=>$.extension===d)){h(s("This extension already has an opening rule."));return}const k=ut(`file${d}`),I=mt(`file${d}`)!==null,M=k&&(!I||o==="system"||o==="application")?"reveal":o;if(M==="internal"&&!mt(`file${d}`)){p(s("This extension does not support internal preview."));return}if(M==="application"&&!m){h(s("Choose an application before saving this rule."));return}b([...t,{extension:d,target:M,...M==="application"?{applicationPath:m}:{}}])&&(r(""),u(void 0),h(null))};return e.jsxs("section",{className:"space-y-3","data-settings-row":"appearance.fileOpening",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium",children:s("File opening")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Configure how local workspace file links open by extension.")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("By default, supported files open inside EnsoCode; other files are revealed in the file manager.")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Executable and installer files are always revealed in the file manager.")})]}),e.jsx(cm,{}),t.map(k=>e.jsxs("div",{className:"flex flex-wrap items-center gap-2 rounded-md border px-3 py-2",children:[e.jsx("span",{className:"w-20 shrink-0 font-mono text-sm",children:k.extension}),e.jsx(Aa,{extension:k.extension,value:k.target,disabled:c,onChange:I=>{I==="application"?j(M=>A(k,I,M)):A(k,I)}}),k.target==="application"&&!ut(`file${k.extension}`)&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-xs text-muted-foreground",title:k.applicationPath,children:k.applicationPath}),e.jsx(y,{variant:"outline",size:"sm",disabled:c,onClick:()=>{j(I=>A(k,"application",I))},children:s("Choose application")})]}),e.jsx(y,{variant:"ghost",size:"sm",disabled:c,onClick:()=>b(t.filter(I=>I.extension!==k.extension)),children:s("Delete")})]},k.extension)),e.jsxs("div",{className:"space-y-2 rounded-md border p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(J,{className:"w-24",value:a,placeholder:".md","aria-label":s("File extension"),disabled:c,onChange:k=>{r(k.target.value),h(null)},onKeyDown:k=>{k.key==="Enter"&&v()}}),e.jsx(Aa,{extension:d??".md",value:o,disabled:c,onChange:k=>{i(k),h(null)}}),e.jsx(y,{variant:"outline",size:"sm",disabled:c,onClick:v,children:s("Add")})]}),o==="application"&&!ut(`file${d??".md"}`)&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{variant:"outline",size:"sm",disabled:c,onClick:()=>{j(k=>{u(k),h(null)})},children:s("Choose application")}),e.jsx("span",{className:"min-w-0 truncate text-xs text-muted-foreground",title:m,children:m})]}),x&&e.jsx("p",{role:"alert",className:"text-xs text-destructive",children:x})]})]})}const um=["pem","crt","cer"];function mm(s){return/^\//.test(s)||/^[A-Za-z]:[\\/]/.test(s)||/^\\\\[^\\]/.test(s)}const xm=16384,zo=4096,_o=65536;function hm(s){return s===null?null:typeof s=="number"&&Number.isInteger(s)&&s>=zo&&s<=_o?s:void 0}function pm(s){const t=s.trim();return t?/^\d+$/.test(t)?hm(Number(t)):void 0:null}function fm(){const{t:s}=R(),[t,n]=l.useState(null),[a,r]=l.useState(""),[o,i]=l.useState(null);l.useEffect(()=>{let u=!1;return window.electronAPI.compaction.getReserveTokens().then(x=>{u||(n(x),r(x===null?"":String(x)))}),()=>{u=!0}},[]);const m=async()=>{const u=pm(a);if(u===void 0){i(s("Enter a whole number between {{min}} and {{max}}, or leave it empty.",{min:zo,max:_o}));return}if(i(null),u===t)return;if(!(await window.electronAPI.compaction.setReserveTokens(u)).ok){i(s("Could not save. Check that pi-agent/settings.json is valid JSON."));return}n(u),r(u===null?"":String(u))};return e.jsxs("div",{className:"flex items-start justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.compactReserveTokens",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"text-sm",children:[s("Compaction reserve tokens"),e.jsx(Ze,{})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Compaction runs when context exceeds the model window minus this value. Larger values compact earlier. Do not set it close to the window of small-context models, or every request compacts first. Leave empty for the default.")})]}),e.jsxs("div",{className:"w-32 shrink-0 space-y-1",children:[e.jsx(J,{inputMode:"numeric",value:a,placeholder:String(xm),"aria-label":s("Compaction reserve tokens"),onChange:u=>r(u.target.value),onBlur:()=>{m()},onKeyDown:u=>{u.key==="Enter"&&m()}}),o&&e.jsx("p",{className:"text-xs text-destructive",children:o})]})]})}function cn({className:s,render:t,...n}){const a={className:K("inline-flex items-center gap-2 text-base/4.5 sm:text-sm/4 font-medium",s),"data-slot":"label"};return Ti({defaultTagName:"label",props:Ri(a,n),render:t})}const dn={checked(s){return s?{"data-checked":""}:{"data-unchecked":""}},...zr,...Fr},Fo=l.createContext(void 0);function gm(){return l.useContext(Fo)}const Bo=l.createContext(void 0);function jm(){const s=l.useContext(Bo);if(s===void 0)throw new Error(Oi(52));return s}const vm=l.forwardRef(function(t,n){const{render:a,className:r,disabled:o=!1,readOnly:i=!1,required:m=!1,"aria-labelledby":u,value:x,inputRef:h,nativeButton:c=!1,id:f,style:d,...p}=t,j=gm(),{disabled:b,readOnly:A,required:v,form:k,checkedValue:I,touched:M=!1,validation:$,name:E,setCheckedValue:L=Rt,setTouched:T=Rt,registerInputRef:C=Rt}=j??{},{setTouched:S,setFilled:W,state:q,disabled:N}=Br(),z=Di(),{labelId:H,getDescriptionProps:U}=Ur(),B=N||z.disabled||b||o,ie=A||i,F=v||m,X=k,V=j?I===x:x==="",le=l.useRef(null),_=l.useRef(null),de=$?.registerInput,ue=l.useCallback(ge=>de?.(ge,{controlRef:le,value:void 0}),[de]),O=Li(h,_,C,ue);na(()=>{_.current?.checked&&W(!0)},[W]),na(()=>{if(_.current){if(B&&V){C(null);return}C(_.current)}},[V,B,C]);const De=$r(),te=zi({id:f,implicit:!1,controlRef:le}),P=c?void 0:te,Y=_i(u,H,_,!c,P),D={role:"radio","aria-checked":V,"aria-labelledby":Y,[Ki]:V?"":void 0,id:c?te:De,onKeyDown(ge){ge.key==="Enter"&&ge.preventDefault()},onClick(ge){if(ge.defaultPrevented||B||ie)return;ge.preventDefault();const as=_.current;as&&Gi(as,ge)},onFocus(ge){ge.defaultPrevented||B||ie||!M||(_.current?.click(),T(!1))}},{getButtonProps:Q,buttonRef:ee}=Fi({disabled:B,native:c,composite:!1}),fe={type:"radio",ref:O,form:X,id:P,name:E,tabIndex:-1,style:E?$i:Vi,"aria-hidden":!0,...x!==void 0?{value:Bi(x)}:aa,disabled:B,checked:V,required:F,readOnly:ie,onChange(ge){if(ge.nativeEvent.defaultPrevented||B||ie||x===void 0)return;const as=Wi(Hi,ge.nativeEvent);L(x,as),!as.isCanceled&&S(!0)},onClick(ge){ge.stopPropagation()},onFocus(){le.current?.focus()}},xe=l.useMemo(()=>({...q,required:F,disabled:B,readOnly:ie,checked:V}),[q,B,ie,V,F]),Ls=xe,ds=j!==void 0,vs=[n,le,ee],He=[D,p,Q,U,$?ge=>$.getValidationProps(B,ge):aa],zs=vn("span",t,{enabled:!ds,state:xe,ref:vs,props:He,stateAttributesMapping:dn});return e.jsxs(Bo.Provider,{value:Ls,children:[ds?e.jsx(Ui,{tag:"span",render:a,className:r,style:d,state:xe,refs:vs,props:He,stateAttributesMapping:dn}):zs,e.jsx("input",{...fe,suppressHydrationWarning:!0})]})}),bm=l.forwardRef(function(t,n){const{render:a,className:r,style:o,keepMounted:i=!1,...m}=t,u=jm(),x=u.checked,{mounted:h,transitionStatus:c,setMounted:f}=Dr(x),d={...u,transitionStatus:c},p=l.useRef(null),j=i||h,b=vn("span",t,{ref:[n,p],state:d,props:m,stateAttributesMapping:dn});return Lr({open:x,ref:p,onComplete(){x||f(!1)}}),j?b:null}),ym=[sl],wm=l.forwardRef(function(t,n){const{render:a,className:r,disabled:o,readOnly:i,required:m,onValueChange:u,value:x,defaultValue:h,form:c,name:f,inputRef:d,id:p,style:j,...b}=t,{setTouched:A,setFocused:v,validationMode:k,name:I,disabled:M,state:$,validation:E,setDirty:L,setFilled:T,validityData:C}=Br(),{labelId:S}=Ur(),{clearErrors:W,elementRef:q}=qi(),N=Yi(!0),z=M||o,H=I??f,U=$r(p),[B,ie]=Ji({controlled:x,default:h,name:"RadioGroup",state:"value"}),[F,X]=l.useState(!1),V=Ot((ee,fe)=>{u?.(ee,fe),!fe.isCanceled&&ie(ee)}),le=E.getInputControl,_=l.useMemo(()=>({get current(){return le()}}),[le]),de=l.useRef(null),ue=l.useRef(null);function O(ee){let fe;return d&&(typeof d=="function"?fe=d(ee):d.current=ee),de.current=ee,fe}const De=Ot(ee=>{if(!ee||ee.disabled)return;ue.current||(ue.current=ee);const fe=de.current,xe=ee.checked||fe==null||fe.disabled?O(ee):void 0;return()=>{ue.current===ee&&(ue.current=null),de.current===ee?xe?(xe(),de.current=null):O(null):xe?.()}}),te=Ot(()=>{const ee=q.current;if(!ee)return B??null;for(const fe of E.registeredInputs.keys())if(fe.checked&&Xi(fe,ee))return B??null;return null});Qi(_,U,B??null,te,!z,f),Zi(B,()=>{W(H),L(B!==C.initialValue),T(B!=null),E.change(B);const ee=ue.current;B==null&&ee&&!ee.disabled&&O(ee)});const P=S??N?.legendId,Y={...$,disabled:z??!1,required:m??!1,readOnly:i??!1},D=l.useMemo(()=>({checkedValue:B,disabled:z,form:c,validation:E,name:H,readOnly:i,registerInputRef:De,required:m,setCheckedValue:V,setTouched:X,touched:F}),[B,z,c,E,H,i,De,m,V,X,F]),Q={id:p,role:"radiogroup","aria-required":m||void 0,"aria-disabled":z||void 0,"aria-readonly":i||void 0,"aria-labelledby":P,onFocus(){v(!0)},onBlur(ee){tl(ee.currentTarget,ee.relatedTarget)||(A(!0),v(!1),k==="onBlur"&&E.commit(B))},onKeyDownCapture(ee){ee.key.startsWith("Arrow")&&(X(!0),v(!0))}};return e.jsx(Fo.Provider,{value:D,children:e.jsx(el,{render:a,className:r,style:j,state:Y,props:[Q,b,ee=>E.getValidationProps(z??!1,ee)],refs:[n],stateAttributesMapping:Fr,enableHomeAndEndKeys:!1,modifierKeys:ym})})});function Nm({className:s,...t}){return e.jsx(wm,{className:K("flex flex-col gap-3",s),"data-slot":"radio-group",...t})}function Ea({className:s,...t}){return e.jsx(vm,{className:K("relative inline-flex size-4.5 shrink-0 items-center justify-center rounded-full border border-input bg-background bg-clip-padding shadow-xs outline-none transition-shadow before:pointer-events-none before:absolute before:inset-0 before:rounded-full not-data-disabled:not-data-checked:not-aria-invalid:before:shadow-[0_1px_--theme(--color-black/4%)] focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background aria-invalid:border-destructive/36 focus-visible:aria-invalid:border-destructive/64 focus-visible:aria-invalid:ring-destructive/48 data-disabled:opacity-64 sm:size-4 dark:not-data-checked:bg-input/32 dark:bg-clip-border dark:aria-invalid:ring-destructive/24 dark:not-data-disabled:not-data-checked:not-aria-invalid:before:shadow-[0_-1px_--theme(--color-white/8%)] [[data-disabled],[data-checked],[aria-invalid]]:shadow-none",s),"data-slot":"radio",...t,children:e.jsx(bm,{className:"-inset-px absolute flex size-4.5 items-center justify-center rounded-full before:size-2 before:rounded-full before:bg-primary-foreground data-unchecked:hidden data-checked:bg-primary sm:size-4 sm:before:size-1.5","data-slot":"radio-indicator"})})}const km=[{category:"providers",label:"Model Providers"},{category:"presets",label:"Presets"},{category:"agentTypes",label:"Agent types"},{category:"skills",label:"Skills"},{category:"mcpServers",label:"MCP Servers"},{category:"instructions",label:"Instruction Files"},{category:"subagentModels",label:"Subagent Models"},{category:"settings",label:"Scalar settings"}];function Cm(){const{t:s}=R(),[t,n]=l.useState(!1),[a,r]=l.useState(!1),[o,i]=l.useState(null),[m,u]=l.useState(null),x=()=>{i(null),n(!0)},h=async()=>{r(!0),i(null);try{const c=await window.electronAPI.configSync.openImport();if(!c.ok){i({kind:c.cancelled?"cancelled":"error",text:c.cancelled?s("Import cancelled."):s(c.error)});return}u(c)}catch{i({kind:"error",text:s("Could not open configuration package.")})}finally{r(!1)}};return e.jsxs("section",{className:"space-y-3","data-settings-row":"general.configSync",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium",children:s("Configuration transfer")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Move models, presets, agent types, skills, MCP servers and instruction files between devices.")})]}),e.jsxs("div",{className:"rounded-md border px-3 py-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[e.jsx(Iu,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium",children:s("Portable Enso configuration")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Export a package or preview one before importing it.")})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsxs(y,{variant:"outline",size:"sm",disabled:a,onClick:h,children:[a?e.jsx(Me,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(bn,{className:"h-3.5 w-3.5"}),s("Import configuration")]}),e.jsxs(y,{size:"sm",disabled:a,onClick:x,children:[e.jsx(Lo,{className:"h-3.5 w-3.5"}),s("Export configuration")]})]})]}),e.jsxs("div",{className:"mt-3 flex items-start gap-2 border-t pt-3 text-xs text-muted-foreground",children:[e.jsx(pt,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),e.jsx("p",{children:s("OAuth login sessions are never transferred. Skill, instruction, and system prompt contents require an encrypted export.")})]}),o&&e.jsx("p",{className:o.kind==="error"?"mt-2 text-xs text-destructive":"mt-2 text-xs text-muted-foreground",role:o.kind==="error"?"alert":"status",children:o.text})]}),e.jsx(Sm,{open:t,onOpenChange:n}),m&&e.jsx(Im,{file:m,onClose:()=>u(null)})]})}function Sm({open:s,onOpenChange:t}){const{t:n}=R(),[a,r]=l.useState(!1),[o,i]=l.useState(""),[m,u]=l.useState(""),[x,h]=l.useState(!1),[c,f]=l.useState(null),[d,p]=l.useState(!1),[j,b]=l.useState(null),[A,v]=l.useState([]);l.useEffect(()=>{s&&(r(!1),i(""),u(""),h(!1),f(null),p(!1),b(null),v([]))},[s]);const k=()=>{x||(i(""),u(""),t(!1))},I=async()=>{if(a&&o.length<8){f(n("Password must be at least 8 characters."));return}if(a&&o!==m){f(n("Passwords do not match."));return}h(!0),f(null),p(!1);try{const M=await window.electronAPI.configSync.exportConfig({includeSecrets:a,...a?{password:o}:{}});if(i(""),u(""),!M.ok){M.cancelled?p(!0):f(n(M.error));return}b(M.filePath),v(M.skippedInstructions??[])}catch{i(""),u(""),f(n("Could not export configuration."))}finally{h(!1)}};return e.jsx(ye,{open:s,onOpenChange:M=>!M&&k(),children:e.jsxs(we,{className:"max-w-xl",showCloseButton:!x,children:[e.jsxs(Ne,{children:[e.jsx(ke,{children:n("Export configuration")}),e.jsx(Ye,{children:n("Create a portable .enso-config package for another device.")})]}),e.jsx(Ce,{className:"max-h-[55vh] space-y-4",children:j?e.jsxs(e.Fragment,{children:[e.jsxs($e,{variant:"success",children:[e.jsx(Vr,{}),e.jsx(Ms,{children:n("Configuration exported")}),e.jsxs(Ve,{children:[e.jsx("p",{children:n("Saved package:")}),e.jsx("p",{className:"break-all font-mono text-xs text-foreground",children:j})]})]}),A.length>0&&e.jsxs($e,{variant:"warning",children:[e.jsx(Ke,{}),e.jsxs(Ve,{children:[e.jsx("p",{children:n("These instructions were skipped because their source files are missing or unreadable:")}),e.jsx("p",{className:"break-all text-foreground",children:A.join(", ")})]})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs($e,{variant:"warning",children:[e.jsx(yn,{}),e.jsx(Ms,{children:n("File contents can be private")}),e.jsx(Ve,{children:n("Skill and instruction file contents may contain private data, so configurations containing them can only be exported with encryption.")})]}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-md border px-3 py-2.5",children:[e.jsx(Le,{checked:a,onCheckedChange:M=>{const $=M===!0;r($),f(null),$||(i(""),u(""))}}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-sm font-medium",children:n("Include sensitive configuration")}),e.jsx("span",{className:"mt-0.5 block text-xs text-muted-foreground",children:n("Encrypt the entire package with a password. OAuth login sessions are still excluded.")})]})]}),!a&&e.jsxs($e,{variant:"info",children:[e.jsx(pt,{}),e.jsx(Ve,{children:n("API keys, provider account links, MCP arguments and environment values, plus credentials and private URL parts in MCP endpoints, will be omitted. Configurations containing skill or instruction files require encryption.")})]}),a&&e.jsxs("div",{className:"space-y-3 rounded-md border px-3 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(Do,{className:"h-4 w-4 text-muted-foreground"}),n("Encryption password")]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(cn,{htmlFor:"config-export-password",children:n("Password")}),e.jsx(J,{id:"config-export-password",type:"password",autoComplete:"new-password",value:o,"aria-invalid":!!(c&&o.length<8),onChange:M=>{i(M.target.value),f(null)}})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(cn,{htmlFor:"config-export-confirmation",children:n("Confirm password")}),e.jsx(J,{id:"config-export-confirmation",type:"password",autoComplete:"new-password",value:m,"aria-invalid":!!(c&&m!==o),onChange:M=>{u(M.target.value),f(null)}})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n("Use at least 8 characters. This password cannot be recovered.")})]}),d&&e.jsx("p",{className:"text-xs text-muted-foreground",role:"status",children:n("Export cancelled.")}),c&&e.jsxs("p",{className:"flex items-center gap-1.5 text-xs text-destructive",role:"alert",children:[e.jsx(Rs,{className:"h-3.5 w-3.5 shrink-0"}),c]})]})}),e.jsx(Ee,{children:j?e.jsx(y,{size:"sm",onClick:k,children:n("Done")}):e.jsxs(e.Fragment,{children:[e.jsx(y,{variant:"outline",size:"sm",disabled:x,onClick:k,children:n("Cancel")}),e.jsxs(y,{size:"sm",disabled:x,onClick:()=>{I()},children:[x?e.jsx(Me,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Lo,{className:"h-3.5 w-3.5"}),n(x?"Exporting…":"Export")]})]})})]})})}function Im({file:s,onClose:t}){const{t:n}=R(),[a,r]=l.useState(s.encrypted?"password":"preview"),[o,i]=l.useState(""),[m,u]=l.useState("merge"),[x,h]=l.useState(null),[c,f]=l.useState([]),[d,p]=l.useState(null),[j,b]=l.useState(!1),[A,v]=l.useState(null),[k,I]=l.useState(null),[M,$]=l.useState(!1),E=l.useRef(0),L=l.useCallback(async(N,z)=>{const H=++E.current;v("preview"),I(null),h(null),f([]);try{const U=await window.electronAPI.configSync.previewImport({token:s.token,mode:N,...z?{password:z}:{}});if(H!==E.current)return;if(i(""),!U.ok){I(n(U.error));return}u(U.mode),h(U.summary),f(U.warnings),r("preview")}catch{H===E.current&&(i(""),I(n("Could not preview configuration package.")))}finally{H===E.current&&v(null)}},[s.token,n]);l.useEffect(()=>{s.encrypted||L("merge")},[s.encrypted,L]);const T=()=>{A||(E.current+=1,$(!1),i(""),window.electronAPI.configSync.cancelImport(s.token).catch(()=>{}),t())},C=N=>{N===m||A||(u(N),L(N))},S=!!x?.some(N=>(N.category==="skills"||N.category==="mcpServers")&&N.added+N.updated+N.skipped>0),W=x!==null,q=async()=>{if(x){v("commit"),I(null);try{const N=await window.electronAPI.configSync.commitImport({token:s.token,mode:m});if(!N.ok){h(null),f([]),I(n(N.error));return}i("");try{await g.persist.rehydrate()}catch{b(!0)}f(N.warnings),p(N.backupPath),r("success")}catch{h(null),f([]),I(n("Could not import configuration."))}finally{v(null)}}};return e.jsxs(ye,{open:!0,onOpenChange:N=>!N&&T(),children:[e.jsxs(we,{className:"max-w-2xl",showCloseButton:A===null,children:[e.jsxs(Ne,{children:[e.jsx(ke,{children:n(a==="success"?"Configuration imported":"Import configuration")}),e.jsx(Ye,{children:a==="success"?n(j?"Configuration was imported, but this window could not refresh automatically.":"This window has been refreshed with the imported settings."):n("Review {{fileName}} before changing this device.",{fileName:s.fileName})})]}),a==="password"&&e.jsxs(Ce,{className:"space-y-4",children:[e.jsxs($e,{variant:"info",children:[e.jsx(Do,{}),e.jsx(Ms,{children:n("Encrypted configuration package")}),e.jsx(Ve,{children:n("Enter the export password to decrypt and preview this package.")})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(cn,{htmlFor:"config-import-password",children:n("Password")}),e.jsx(J,{id:"config-import-password",type:"password",autoFocus:!0,autoComplete:"current-password",value:o,"aria-invalid":!!k,onChange:N=>{i(N.target.value),I(null)},onKeyDown:N=>{N.key==="Enter"&&o.length>0&&!A&&L("merge",o)}})]}),k&&e.jsxs("p",{className:"flex items-center gap-1.5 text-xs text-destructive",role:"alert",children:[e.jsx(Rs,{className:"h-3.5 w-3.5 shrink-0"}),k]})]}),a==="preview"&&e.jsxs(Ce,{className:"max-h-[58vh] space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium",children:n("Import mode")}),e.jsxs(Nm,{value:m,onValueChange:N=>C(N),className:"grid gap-2 sm:grid-cols-2","aria-label":n("Import mode"),children:[e.jsxs("label",{className:"flex cursor-pointer items-start gap-2.5 rounded-md border px-3 py-2.5",children:[e.jsx(Ea,{value:"merge",disabled:A!==null}),e.jsxs("span",{children:[e.jsx("span",{className:"block text-sm font-medium",children:n("Merge")}),e.jsx("span",{className:"block text-xs text-muted-foreground",children:n("Add and update matching items while keeping items only on this device.")})]})]}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-2.5 rounded-md border px-3 py-2.5",children:[e.jsx(Ea,{value:"replace",disabled:A!==null}),e.jsxs("span",{children:[e.jsx("span",{className:"block text-sm font-medium",children:n("Replace")}),e.jsx("span",{className:"block text-xs text-muted-foreground",children:n("Replace transferred item categories, removing local-only items in them.")})]})]})]})]}),A==="preview"&&e.jsxs("div",{className:"flex items-center justify-center gap-2 rounded-md border border-dashed py-10",children:[e.jsx(Me,{className:"h-4 w-4 animate-spin text-muted-foreground"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:n("Preparing preview…")})]}),!A&&x&&e.jsx("div",{className:"overflow-hidden rounded-md border",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted/50 text-xs text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",className:"px-3 py-2 text-left font-medium",children:n("Category")}),e.jsx("th",{scope:"col",className:"px-3 py-2 text-right font-medium",children:n("Added")}),e.jsx("th",{scope:"col",className:"px-3 py-2 text-right font-medium",children:n("Updated")}),e.jsx("th",{scope:"col",className:"px-3 py-2 text-right font-medium",children:n("Skipped")}),e.jsx("th",{scope:"col",className:"px-3 py-2 text-right font-medium",children:n("Removed")})]})}),e.jsx("tbody",{children:km.map(({category:N,label:z})=>{const H=x.find(U=>U.category===N);return e.jsxs("tr",{className:"border-t first:border-t-0",children:[e.jsx("th",{scope:"row",className:"px-3 py-2 text-left font-medium",children:n(z)}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:H?.added??0}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:H?.updated??0}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:H?.skipped??0}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:H?.removed??0})]},N)})})]})}),!A&&x?.find(N=>N.category==="settings")?.fields?.length?e.jsxs("p",{className:"text-xs text-muted-foreground",children:[n("Portable settings changed:")," ",x.find(N=>N.category==="settings")?.fields?.join(", ")]}):null,m==="replace"&&x&&!A&&e.jsxs($e,{variant:"error",children:[e.jsx(Ke,{}),e.jsx(Ms,{children:n("Local-only configuration will be deleted")}),e.jsx(Ve,{children:n("Items in transferred collections that exist only on this device will be removed. Removed counts are shown above. Included portable preferences are overwritten. A complete backup is created first.")})]}),c.map(N=>e.jsxs($e,{variant:"warning",children:[e.jsx(Ke,{}),e.jsx(Ve,{children:n(N)})]},N)),x&&!A&&e.jsxs($e,{variant:"warning",children:[e.jsx(yn,{}),e.jsx(Ms,{children:n("Only import packages you trust")}),e.jsx(Ve,{children:n("An imported package can change portable preferences and configuration. Skills and MCP servers may also run commands later when you use them. Previewing does not execute them; continue only if you trust the package.")})]}),k&&e.jsxs($e,{variant:"error",children:[e.jsx(Rs,{}),e.jsx(Ve,{children:k})]})]}),a==="success"&&d&&e.jsxs(Ce,{className:"space-y-4",children:[e.jsxs($e,{variant:"success",children:[e.jsx(Vr,{}),e.jsx(Ms,{children:n("Import complete")}),e.jsxs(Ve,{children:[e.jsx("p",{children:n("Backup of previous settings:")}),e.jsx("p",{className:"break-all font-mono text-xs text-foreground",children:d})]})]}),j&&e.jsxs($e,{variant:"warning",children:[e.jsx(Ke,{}),e.jsx(Ve,{children:n("Reopen Settings to load the imported configuration in this window.")})]}),c.map(N=>e.jsxs($e,{variant:"warning",children:[e.jsx(Ke,{}),e.jsx(Ve,{children:n(N)})]},N))]}),e.jsxs(Ee,{children:[a==="password"&&e.jsxs(e.Fragment,{children:[e.jsx(y,{variant:"outline",size:"sm",disabled:A!==null,onClick:T,children:n("Cancel")}),e.jsxs(y,{size:"sm",disabled:A!==null||o.length===0,onClick:()=>{L("merge",o)},children:[A==="preview"&&e.jsx(Me,{className:"h-3.5 w-3.5 animate-spin"}),n("Preview")]})]}),a==="preview"&&e.jsxs(e.Fragment,{children:[e.jsx(y,{variant:"outline",size:"sm",disabled:A!==null,onClick:T,children:n("Cancel")}),k&&!x?e.jsx(y,{size:"sm",disabled:A!==null,onClick:()=>{L(m)},children:n("Refresh preview")}):e.jsxs(y,{variant:m==="replace"?"destructive":"default",size:"sm",disabled:A!==null||!x,onClick:()=>{x&&(W?$(!0):q())},children:[A==="commit"?e.jsx(Me,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(bn,{className:"h-3.5 w-3.5"}),n(A==="commit"?"Importing…":"Import")]})]}),a==="success"&&e.jsx(y,{size:"sm",onClick:T,children:n("Done")})]})]}),e.jsx(Am,{open:M,mode:m,hasImportedExecutableResources:S,onOpenChange:$,onConfirm:()=>{q()}})]})}function Am({open:s,mode:t,hasImportedExecutableResources:n,onOpenChange:a,onConfirm:r}){const{t:o}=R();return e.jsx(wn,{open:s,onOpenChange:a,children:e.jsxs(Nn,{className:"sm:max-w-md",zIndexLevel:"nested",children:[e.jsxs(kn,{children:[e.jsxs(Cn,{className:"flex items-start gap-2 text-base",children:[e.jsx(Ke,{className:"mt-0.5 h-4 w-4 shrink-0 text-destructive"}),o("Confirm configuration import")]}),e.jsxs(Sn,{className:"space-y-2",children:[e.jsx("span",{className:"block",children:o("This package can change portable preferences and configuration. Continue only if you trust this package.")}),n&&e.jsx("span",{className:"block",children:o("It includes skills or MCP servers that may execute commands when you use them.")}),t==="replace"&&e.jsx("span",{className:"block",children:o("Replace mode removes local-only items from transferred collections and overwrites included portable preferences. A complete backup will be created first.")}),e.jsx("span",{className:"block",children:o("Do you want to continue with this import?")})]})]}),e.jsxs(In,{variant:"bare",children:[e.jsx(An,{render:e.jsx(y,{variant:"outline",size:"sm"}),children:o("Cancel")}),e.jsx(y,{variant:t==="replace"?"destructive":"default",size:"sm",onClick:()=>{a(!1),r()},children:o("Confirm import")})]})]})})}const Ma={auto:"Auto (by usage)",fast:"Fast",balanced:"Balanced",thorough:"Thorough"},Pa={standard:"Standard",smart:"Smart compaction","codex-native":"Codex native compaction","continuous-memory":"Continuous memory (experimental)"};function Em(){const{t:s}=R(),t=g(d=>d.compactStrategy),n=g(d=>d.smartCompactEnabled),a=nl(t,n),r=g(d=>d.setCompactStrategy),o=a!=="standard",i=g(d=>d.smartCompactModel),m=g(d=>d.setSmartCompactModel),u=g(d=>d.smartCompactMode),x=g(d=>d.setSmartCompactMode),h=es(),c=i?h.find(d=>d.id===i.providerId):void 0,f=c?.models.find(d=>d.id===i?.modelId);return e.jsxs("section",{className:"space-y-2 rounded-lg border bg-card p-3","data-settings-row":"general.smartCompactEnabled",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("h4",{className:"font-medium text-sm",children:[s("Context compaction strategy"),e.jsx(Ze,{})]}),e.jsx("p",{className:"mt-0.5 text-muted-foreground text-xs",children:s("Standard uses default compact. Smart compaction uses Enso verified summary at compact time. Codex native compaction additionally stores an official Codex checkpoint on Codex models and uses smart compaction otherwise. Continuous memory records observations in the background so compact keeps more context; all fall back to default compact on failure. Switching strategy takes effect on the next session. The summary model and compaction mode apply to open conversations on the next compaction.")})]}),e.jsxs(ne,{items:Object.fromEntries(ra.map(d=>[d,s(Pa[d])])),value:a,onValueChange:d=>r(d),children:[e.jsx(ae,{className:"w-52",children:e.jsx(re,{})}),e.jsx(oe,{children:ra.map(d=>e.jsx(Z,{value:d,children:s(Pa[d])},d))})]})]}),(a==="smart"||a==="codex-native")&&e.jsxs("div",{className:"flex items-center justify-between gap-4","data-smart-compact-mode":u,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Compaction mode")}),e.jsx("p",{className:"mt-0.5 text-muted-foreground/80 text-[11px]",children:s("Mode changes summary budget and how much recent tail to keep. It does not decide whether compact runs.")})]}),e.jsxs(ne,{items:Object.fromEntries(oa.map(d=>[d,s(Ma[d])])),value:u,onValueChange:d=>x(d),children:[e.jsx(ae,{className:"w-36",children:e.jsx(re,{})}),e.jsx(oe,{children:oa.map(d=>e.jsx(Z,{value:d,children:s(Ma[d])},d))})]})]}),o&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"font-medium text-sm",children:s(a==="continuous-memory"?"Background memory model":"Summary model")}),h.length>0&&e.jsx("div",{className:"w-full min-w-0",children:e.jsx(ze,{providers:h,providerId:c?.id??"",modelId:f?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:s("Follows the session model"),side:"bottom",triggerClassName:Qe,onSelect:(d,p)=>m({providerId:d,modelId:p}),onReasoningChange:()=>{},onThinkingChange:()=>{}})}),i&&(!c||!f)&&e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Selected model is unavailable — falls back to the session model.")}),i&&e.jsx(y,{variant:"ghost",size:"sm",className:"self-start",onClick:()=>m(null),children:s("Follow session model")})]})]})}const Mm={cmd:"Command Prompt",powershell:"Windows PowerShell",pwsh:"PowerShell 7 (pwsh)","git-bash":"Git Bash",zsh:"zsh",bash:"bash",fish:"fish"};function Pm(){const{language:s,setLanguage:t}=g(),{t:n}=R();return e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:n("General")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:n("General application settings")})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h4",{className:"border-b pb-2 text-base font-semibold",children:n("Application")}),e.jsxs("div",{className:"flex items-center gap-3","data-settings-row":"general.language",children:[e.jsx("span",{className:"text-sm font-medium",children:n("Language")}),e.jsxs(ne,{items:{en:"English",zh:"简体中文"},value:s,onValueChange:a=>t(a),children:[e.jsx(ae,{className:"w-48",children:e.jsx(re,{})}),e.jsxs(oe,{children:[e.jsx(Z,{value:"en",children:"English"}),e.jsx(Z,{value:"zh",children:"简体中文"})]})]})]}),e.jsx(Tm,{}),e.jsx(Bm,{}),e.jsx(Um,{}),e.jsx(Cm,{}),e.jsx($m,{})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h4",{className:"border-b pb-2 text-base font-semibold",children:n("Agent runtime")}),e.jsx(Rm,{}),e.jsx(Om,{}),e.jsx(Em,{}),e.jsx(fm,{})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h4",{className:"border-b pb-2 text-base font-semibold",children:n("Sessions & worktrees")}),e.jsx(Lm,{}),e.jsx(Dm,{}),e.jsx(_m,{})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h4",{className:"border-b pb-2 text-base font-semibold",children:n("Terminal")}),e.jsx(Fm,{}),e.jsx(zm,{})]}),window.electronAPI.env.platform==="darwin"&&e.jsxs("section",{className:"space-y-3",children:[e.jsx("h4",{className:"border-b pb-2 text-base font-semibold",children:n("Integrations")}),e.jsx(Ta,{kind:"ensoCommand",title:n("'enso' terminal command"),description:n("Run `enso .` in a terminal to open the current folder in EnsoCode. Links the command into /usr/local/bin and may ask for your password.")}),e.jsx(Ta,{kind:"finderQuickAction",title:n("Finder Quick Action"),description:n("Right-click a folder in Finder and choose Services > Open with EnsoCode.")})]})]})}function Ta({kind:s,title:t,description:n}){const{t:a}=R(),[r,o]=l.useState(!1),[i,m]=l.useState(!1);l.useEffect(()=>{let x=!0;const h=()=>{window.electronAPI.window.shellIntegrationStatus().then(c=>{x&&o(c[s])})};return h(),window.addEventListener("focus",h),()=>{x=!1,window.removeEventListener("focus",h)}},[s]);const u=async()=>{m(!0);try{await window.electronAPI.window.installShellIntegration(s)}finally{try{const x=await window.electronAPI.window.shellIntegrationStatus();o(x[s])}finally{m(!1)}}};return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":`general.${s}`,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n})]}),e.jsx(y,{variant:"outline",size:"sm",className:"shrink-0",disabled:i,onClick:()=>{u()},children:a(i?"In progress…":r?"Uninstall":"Install")})]})}function Tm(){const{t:s}=R(),t=g(a=>a.notifyMainAgentOnly),n=g(a=>a.setNotifyMainAgentOnly);return e.jsx(Ie,{rowId:"general.notifyMainAgentOnly",title:s("Notify only for the main agent"),description:s("Skip coworker completion and failure notifications on this computer and the paired phone. Questions and approvals still notify."),checked:t,onChange:n})}function Rm(){const{t:s}=R(),t=g(a=>a.generationStallTimeoutMin),n=g(a=>a.setGenerationStallTimeoutMin);return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.generationStallTimeout",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s("Stop if no output")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Abort and retry the run when no tokens or tool results arrive for this long. Thinking counts as output.")})]}),e.jsxs(ne,{items:Object.fromEntries(ia.map(a=>[String(a),a===0?s("Never"):s("{{count}} min",{count:a})])),value:String(t),onValueChange:a=>n(Number(a)),children:[e.jsx(ae,{className:"w-28",children:e.jsx(re,{})}),e.jsx(oe,{children:ia.map(a=>e.jsx(Z,{value:String(a),children:a===0?s("Never"):s("{{count}} min",{count:a})},a))})]})]})}function Om(){const{t:s}=R(),t=g(o=>o.autoRetryLimit),n=g(o=>o.setAutoRetryLimit),a=Dt.some(o=>o===t)?[...Dt]:[...Dt,t].sort((o,i)=>o===Lt?1:i===Lt?-1:o-i),r=o=>o===0?s("Off"):o===Lt?s("Unlimited"):s("{{count}} times",{count:o});return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.autoRetryLimit",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s("Auto-retry on transient errors")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Retry with backoff (up to 60s apart) after 429, 5xx or network errors. Quota and billing errors are never retried. Unlimited keeps retrying until you cancel.")})]}),e.jsxs(ne,{items:Object.fromEntries(a.map(o=>[String(o),r(o)])),value:String(t),onValueChange:o=>n(Number(o)),children:[e.jsx(ae,{className:"w-28",children:e.jsx(re,{})}),e.jsx(oe,{children:a.map(o=>e.jsx(Z,{value:String(o),children:r(o)},o))})]})]})}function Dm(){const{t:s}=R(),t=g(r=>r.activeRetentionMinutes),n=g(r=>r.setActiveRetentionMinutes),a=r=>r===0?s("Off"):s("{{count}} min",{count:r});return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.activeRetentionMinutes",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s("Keep in Active after last message")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Viewed conversations stay in Active for this long after their last message or your last open while still in Active, then leave. Unviewed ones stay until you open them.")})]}),e.jsxs(ne,{items:Object.fromEntries(ft.map(r=>[String(r),a(r)])),value:String(t),onValueChange:r=>n(Number(r)),children:[e.jsx(ae,{className:"w-28",children:e.jsx(re,{})}),e.jsx(oe,{children:ft.map(r=>e.jsx(Z,{value:String(r),children:a(r)},r))})]})]})}function lt(s,t){return t===0?s("Never"):t===1?s("{{count}} day",{count:t}):s("{{count}} days",{count:t})}function Lm(){const{t:s}=R(),t=g(m=>m.autoArchiveIdleDays),n=g(m=>m.setAutoArchiveIdleDays),a=g(m=>m.autoArchiveMergedWorktrees),r=g(m=>m.setAutoArchiveMergedWorktrees),o=g(m=>m.autoDeleteArchivedDays),i=g(m=>m.setAutoDeleteArchivedDays);return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.autoArchiveIdleDays",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s("Archive idle conversations")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Move conversations that have been idle this long into Archived. Does not delete them.")})]}),e.jsxs(ne,{items:Object.fromEntries(la.map(m=>[String(m),lt(s,m)])),value:String(t),onValueChange:m=>n(Number(m)),children:[e.jsx(ae,{className:"w-28",children:e.jsx(re,{})}),e.jsx(oe,{children:la.map(m=>e.jsx(Z,{value:String(m),children:lt(s,m)},m))})]})]}),e.jsx(Ie,{rowId:"general.autoArchiveMergedWorktrees",title:s("Clean up merged worktrees"),description:s("When archiving idle conversations, also remove isolated worktrees that are merged and clean."),checked:a,onChange:r}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.autoDeleteArchivedDays",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s("Delete archived conversations after")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Permanently delete conversations that have been archived longer than this. This cannot be undone. Choosing a positive value deletes already-overdue archived conversations immediately.")})]}),e.jsxs(ne,{items:Object.fromEntries(ca.map(m=>[String(m),lt(s,m)])),value:String(o),onValueChange:m=>i(Number(m)),children:[e.jsx(ae,{className:"w-28",children:e.jsx(re,{})}),e.jsx(oe,{children:ca.map(m=>e.jsx(Z,{value:String(m),children:lt(s,m)},m))})]})]})]})}function zm(){const{t:s}=R(),t=g(o=>o.terminalShell),n=g(o=>o.setTerminalShell),a=rl(window.electronAPI.env.platform),r=Object.fromEntries(a.map(o=>[o,o==="auto"?s("System default"):Mm[o]]));return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.terminalShell",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s("Terminal shell")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Applies to new side panel terminals. SSH projects keep the remote login shell.")})]}),e.jsxs(ne,{items:r,value:t,onValueChange:o=>n(o),children:[e.jsx(ae,{className:"w-56",children:e.jsx(re,{})}),e.jsx(oe,{children:a.map(o=>e.jsx(Z,{value:o,children:r[o]},o))})]})]})}function _m(){const{t:s}=R(),t=g(x=>x.worktreeRoot),n=g(x=>x.setWorktreeRoot),[a,r]=l.useState(t),[o,i]=l.useState(null);l.useEffect(()=>{r(t)},[t]);const m=x=>{const h=x.trim();if(h&&!mm(h)){i(s("Enter an absolute path"));return}i(null),n(h)},u=async()=>{const x=await window.electronAPI.dialog.selectDirectory();x&&(r(x),m(x))};return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.worktreeRoot",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s("Worktree root directory")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Where isolated session worktrees are created. Leave empty to use the app data directory. Existing worktrees stay where they are.")})]}),e.jsxs("div",{className:"w-72 shrink-0 space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(J,{value:a,placeholder:s("Default location"),onChange:x=>r(x.target.value),onBlur:()=>m(a),onKeyDown:x=>{x.key==="Enter"&&m(a)}}),e.jsx(y,{variant:"outline",size:"sm",className:"shrink-0",onClick:()=>{u()},children:s("Browse")})]}),o&&e.jsx("p",{className:"text-xs text-destructive",children:o})]})]})}function Fm(){const{t:s}=R(),t=g(r=>r.windowsLocalShell),n=g(r=>r.setWindowsLocalShell),a={auto:s("Windows default (PowerShell)"),powershell:s("PowerShell"),bash:s("Git Bash")};return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.windowsLocalShell",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"text-sm",children:[s("Windows local command shell"),e.jsx(Ze,{})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Only the Windows local agent command tool. SSH and other platforms stay on bash. Takes effect on the next session.")})]}),e.jsxs(ne,{items:a,value:t,onValueChange:r=>n(r),children:[e.jsx(ae,{className:"w-56",children:e.jsx(re,{})}),e.jsx(oe,{children:Object.keys(a).map(r=>e.jsx(Z,{value:r,children:a[r]},r))})]})]})}function Ie({title:s,description:t,checked:n,onChange:a,rowId:r,children:o}){return e.jsxs("div",{className:"rounded-md border px-3 py-2.5","data-settings-row":r,children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t})]}),e.jsx(ce,{checked:n,onCheckedChange:i=>a(i===!0)})]}),o?e.jsx("div",{className:"mt-2",children:o}):null]})}function Ra(s,t){window.electronAPI.proxy.apply({mode:s,customUrl:t})}function Bm(){const{t:s}=R(),t=g(c=>c.proxyMode),n=g(c=>c.customProxyUrl),a=g(c=>c.setProxyMode),r=g(c=>c.setCustomProxyUrl),[o,i]=l.useState(n),[m,u]=l.useState(null);l.useEffect(()=>{i(n)},[n]);const x=c=>{a(c),Ra(c,n)},h=()=>{const c=o.trim();if(c&&!ol(c)){u(s("Enter an http(s) proxy URL"));return}u(null),r(c),Ra(t,c)};return e.jsxs("div",{className:"space-y-3","data-settings-row":"general.proxy",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium",children:s("Network proxy")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Used by model requests, the built-in browser, and agent tools")})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-sm font-medium",children:s("Proxy mode")}),e.jsxs(ne,{items:{system:s("Follow system proxy"),none:s("No proxy"),custom:s("Custom proxy")},value:t,onValueChange:c=>x(c),children:[e.jsx(ae,{className:"w-56",children:e.jsx(re,{})}),e.jsxs(oe,{children:[e.jsx(Z,{value:"system",children:s("Follow system proxy")}),e.jsx(Z,{value:"none",children:s("No proxy")}),e.jsx(Z,{value:"custom",children:s("Custom proxy")})]})]})]}),t==="custom"&&e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"pt-1.5 text-sm font-medium",children:s("Proxy URL")}),e.jsxs("div",{className:"min-w-0 space-y-1",children:[e.jsx(J,{value:o,placeholder:"http://127.0.0.1:7890",onChange:c=>i(c.target.value),onBlur:h,onKeyDown:c=>{c.key==="Enter"&&h()}}),m&&e.jsx("p",{className:"text-xs text-destructive",children:m})]})]})]})}function Um(){const{t:s}=R(),t=g(c=>c.customCaCertPath),n=g(c=>c.setCustomCaCertPath),[a,r]=l.useState(null),[o,i]=l.useState(!1);l.useEffect(()=>{let c=!0;return window.electronAPI.caCert.status().then(f=>{c&&r(f)}).catch(()=>{}),()=>{c=!1}},[]);const m=async c=>{n(c),i(!0);try{r(await window.electronAPI.caCert.apply(c))}catch{}finally{i(!1)}},u=async()=>{const c=await window.electronAPI.dialog.selectFile([...um]);c&&await m(c)},x={"not-absolute":s("Path must be absolute"),"not-found":s("File not found"),"not-file":s("Not a file"),"not-readable":s("File is not readable")},h=()=>a?a.source==="env"?s("Using NODE_EXTRA_CA_CERTS from the launch environment: {{path}}",{path:a.path}):a.source==="setting"?s("Set: {{path}}",{path:a.path}):a.source==="shell"?s("Not set; using NODE_EXTRA_CA_CERTS from the login shell: {{path}}",{path:a.path}):s("Not set"):"";return e.jsxs("div",{className:"space-y-3","data-settings-row":"general.caCert",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium",children:s("Custom CA certificate")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Trust an extra CA (PEM file) for model endpoints signed by a private CA. TLS verification stays on.")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{size:"sm",variant:"outline",disabled:o,onClick:()=>{u()},children:s("Choose certificate file")}),t&&e.jsx(y,{size:"sm",variant:"ghost",disabled:o,onClick:()=>{m("")},children:s("Clear")})]}),a?.error?e.jsx("p",{className:"break-all text-xs text-destructive",children:s("Certificate file unavailable ({{reason}}): {{path}}",{reason:x[a.error],path:a.settingPath})}):e.jsx("p",{className:"break-all text-xs text-muted-foreground",children:h()}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Changes restart the agent process right away (running turns are interrupted). Requests made by the app main process take effect after restarting the app.")})]})}function $m(){const{t:s}=R(),t=g(k=>k.autoUpdate),n=g(k=>k.setAutoUpdate),a=g(k=>k.autoRestartWhenIdle),r=g(k=>k.setAutoRestartWhenIdle),[o,i]=l.useState(null),[m,u]=l.useState(null),[x,h]=l.useState(!1),[c,f]=l.useState(!1);l.useEffect(()=>{let k=!0;window.electronAPI.updater.getState().then(M=>{k&&(u(M),M.status&&i($=>$??M.status))}).catch(()=>{});const I=window.electronAPI.updater.onStatus(i);return()=>{k=!1,I()}},[]);const d=m?.host==="server"?m:null,p=m?.host==="desktop"||d!==null&&d.mode!=="manual",j=(o?.status==="available"||o?.status==="downloaded")&&!!o.info,A=(()=>{if(!o)return null;switch(o.status){case"checking":return s("Checking for updates…");case"available":return s("New version {{version}} found",{version:o.info?.version??""});case"not-available":return s("You are on the latest version");case"downloading":return s("Downloading update… {{percent}}%",{percent:Math.round(o.progress?.percent??0)});case"downloaded":return s("New version {{version}} is ready — restart to update.",{version:o.info?.version??""});case"error":return d&&o.error?s("Update failed: {{error}}",{error:o.error}):s("Update check failed");default:return null}})(),v=o?.status==="checking"||o?.status==="downloading";return e.jsxs("div",{className:"space-y-3","data-settings-row":"general.updates",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium",children:s("Updates")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:d?Vm(d.mode,s):s("Application update settings")})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"text-sm",children:[s("Current version")," · ",Gm]}),A&&e.jsx("p",{className:"mt-0.5 truncate text-xs text-muted-foreground",children:A})]}),j&&e.jsx(y,{variant:"ghost",size:"sm",onClick:()=>f(!0),className:"ml-auto shrink-0",children:s("Release notes")}),o?.status==="downloaded"?e.jsx(y,{size:"sm",onClick:()=>{window.electronAPI.updater.quitAndInstall()},className:"shrink-0",children:s("Restart to update")}):p&&o?.status==="available"?e.jsx(y,{size:"sm",onClick:()=>{window.electronAPI.updater.downloadUpdate()},className:"shrink-0",children:s("Download update")}):e.jsx(y,{variant:"outline",size:"sm",disabled:v,onClick:()=>{window.electronAPI.updater.checkForUpdates()},className:"shrink-0",children:s("Check for updates")}),e.jsx(al,{open:c,onOpenChange:f,status:o,canDownload:p})]}),d?.canRestart&&e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s("Restart server")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Running tasks are interrupted; this page reconnects after the server is back.")})]}),e.jsx(y,{variant:"outline",size:"sm",onClick:()=>h(!0),className:"shrink-0",children:s("Restart")}),e.jsx(Gr,{open:x,onOpenChange:h,title:s("Restart server?"),description:s("Running tasks are interrupted; this page reconnects after the server is back."),confirmLabel:s("Restart"),onConfirm:()=>{h(!1),window.electronAPI.updater.restart()}})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s("Automatic updates")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Download and install updates automatically")})]}),e.jsx(ce,{checked:t,onCheckedChange:k=>{n(k),window.electronAPI.updater.setAutoUpdateEnabled(k)}})]}),e.jsxs("div",{className:`flex items-center justify-between gap-3 rounded-md border px-3 py-2.5 ${t?"":"opacity-60"}`,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s("Restart and apply when idle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("After the update is downloaded, restart automatically if no agent is running, nothing is queued, and there are no pending questions or approvals. The idle state must last 5 minutes, and a focused window also blocks it.")})]}),e.jsx(ce,{checked:t&&a,disabled:!t,onCheckedChange:k=>{r(k),window.electronAPI.updater.setAutoRestartWhenIdle(k)}})]})]})}function Vm(s,t){return t(s==="npm"?"Server updates install the new version with npm and restart.":"This server must be updated on the machine itself.")}const Gm="0.3.10",Km=["100%","100%","70%","100%","55%"],Wm=["100%","85%","60%"];function Hm({palette:s}){return e.jsxs("div",{className:"flex h-[88px] gap-1.5 p-[7px]",style:{background:s.canvas},children:[e.jsxs("div",{className:"flex w-[30%] flex-col gap-[5px] px-0.5 py-1",children:[e.jsx("i",{className:"block h-[9px] rounded-[3px] opacity-[.18]",style:{background:s.text}}),Km.slice(1).map((t,n)=>e.jsx("i",{className:"block h-[5px] rounded-[3px] opacity-55",style:{background:s.textSubtle,width:t}},n))]}),e.jsxs("div",{className:"flex flex-1 flex-col gap-[5px] rounded-md px-2.5 py-2",style:{background:s.surface,boxShadow:`0 0 0 1px ${s.border}`},children:[e.jsx("i",{className:"block h-1 w-[70%] rounded-sm opacity-75",style:{background:s.text}}),Wm.map(t=>e.jsx("i",{className:"block h-1 rounded-sm opacity-50",style:{background:s.textSubtle,width:t}},t)),e.jsx("b",{className:"mt-auto flex h-3.5 justify-end rounded-full p-[3px]",style:{background:s.sunken,boxShadow:`0 0 0 1px ${s.border}`},children:e.jsx("span",{"data-theme-accent":!0,className:"size-2 rounded-full",style:{background:s.accent}})})]})]})}const Oa="overflow-hidden rounded-lg border text-left transition-shadow";function qm({themes:s,selected:t,mode:n,onSelect:a,onGetMore:r}){const{t:o}=R();return e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[s.map(i=>{const m=i.id===t;return e.jsxs("button",{type:"button","data-theme-card":i.id,"aria-pressed":m,onClick:()=>a(i.id),className:K(Oa,"bg-card",m?"border-transparent shadow-[0_0_0_2px_var(--brand)]":"hover:border-input"),children:[e.jsx(Hm,{palette:i[n]}),e.jsxs("div",{className:"flex items-center gap-1.5 border-t px-2.5 py-[7px] text-sm",children:[e.jsx("span",{className:"truncate font-medium",children:i.name}),e.jsx("span",{className:K("ml-auto shrink-0 truncate rounded-full px-1.5 py-px text-[10.5px]",i.source.kind==="plugin"?"max-w-[60%] bg-brand/12 text-brand":"bg-muted text-subtle-foreground"),children:i.source.kind==="plugin"?o("Plugin · {{name}}",{name:i.source.pluginName}):o("Built-in")})]})]},i.id)}),r&&e.jsxs("button",{type:"button",onClick:r,className:K(Oa,"flex min-h-[124px] flex-col items-center justify-center gap-1.5 border-dashed text-sm text-subtle-foreground hover:border-input hover:text-foreground"),children:[e.jsx(Xs,{className:"size-[18px]"}),o("Get more themes")]})]})}function un({rowId:s,title:t,description:n,children:a}){return e.jsxs("div",{"data-settings-row":s,className:"flex min-h-12 items-center justify-between gap-4 px-3.5 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium",children:t}),n&&e.jsx("p",{className:"text-xs text-muted-foreground",children:n})]}),e.jsx("div",{className:"flex shrink-0 items-center gap-2",children:a})]})}function Ym({children:s}){return e.jsx("div",{className:"divide-y rounded-lg border bg-card",children:s})}function ls({label:s,value:t,onCommit:n,min:a=0,max:r=100,step:o,unit:i="%",formatSuffix:m,onPreview:u,trailing:x,valueClassName:h="w-12"}){const[c,f]=l.useState(t);l.useEffect(()=>{f(t)},[t]);const d=m?.(c);return e.jsxs("div",{className:K("grid items-center gap-4",x?"grid-cols-[9.5rem_minmax(0,1fr)_auto]":"grid-cols-[100px_1fr]"),children:[e.jsx("span",{className:"text-sm font-medium",children:s}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(pl,{min:a,max:r,step:o,value:c,onValueChange:p=>{const j=Array.isArray(p)?p[0]:p;f(j),u?.(j)},onValueCommitted:p=>n(Array.isArray(p)?p[0]:p)}),e.jsxs("span",{className:K("shrink-0 text-right text-sm text-muted-foreground tabular-nums",d?"w-28":h),children:[c,i,d?` · ${d}`:""]})]}),x]})}function Jm(){const{t:s}=R(),t=g(O=>O.backgroundImageEnabled),n=g(O=>O.setBackgroundImageEnabled),a=g(O=>O.backgroundSourceType),r=g(O=>O.setBackgroundSourceType),o=g(O=>O.backgroundImagePath),i=g(O=>O.setBackgroundImagePath),m=g(O=>O.backgroundFolderPath),u=g(O=>O.setBackgroundFolderPath),x=g(O=>O.backgroundUrlPath),h=g(O=>O.setBackgroundUrlPath),c=g(O=>O.backgroundRandomEnabled),f=g(O=>O.setBackgroundRandomEnabled),d=g(O=>O.backgroundRandomInterval),p=g(O=>O.setBackgroundRandomInterval),j=g(O=>O.backgroundOpacity),b=g(O=>O.setBackgroundOpacity),A=g(O=>O.backgroundBlur),v=g(O=>O.setBackgroundBlur),k=g(O=>O.backgroundBrightness),I=g(O=>O.setBackgroundBrightness),M=g(O=>O.backgroundSaturation),$=g(O=>O.setBackgroundSaturation),E=g(O=>O.backgroundMask),L=g(O=>O.setBackgroundMask),T=g(O=>O.backgroundComposerOpacity),C=g(O=>O.setBackgroundComposerOpacity),S=g(O=>O.backgroundCodeOpacity),W=g(O=>O.setBackgroundCodeOpacity),q=g(O=>O.backgroundSizeMode),N=g(O=>O.setBackgroundSizeMode),z=g(O=>O.bumpBackgroundRefresh),H=fl()?.source==="theme",U=a==="file"?o:a==="folder"?m:x,[B,ie]=l.useState(U);l.useEffect(()=>{ie(U)},[U]);const F=l.useCallback(()=>{const O=B.trim();a==="file"?i(O):a==="folder"?u(O):h(O)},[B,a,i,u,h]),[X,V]=l.useState(d);l.useEffect(()=>{V(d)},[d]);const le=async()=>{if(a==="folder"){const O=await window.electronAPI.dialog.selectDirectory();O&&u(O)}else{const O=await window.electronAPI.dialog.selectFile([...vl,...bl]);O&&i(O)}},_=[{value:"file",label:s("Single image")},{value:"folder",label:s("Folder (random)")},{value:"url",label:s("Remote URL")}],de=[{value:"cover",label:s("Cover")},{value:"contain",label:s("Contain")},{value:"repeat",label:s("Repeat")},{value:"center",label:s("Center")}],ue=s(a==="file"?"Image path":a==="folder"?"Folder path":"Image URL");return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between border-t pt-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("Background image")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("Show a custom image behind the interface")})]}),e.jsx(ce,{checked:t,onCheckedChange:O=>n(O===!0)})]}),H&&e.jsx("p",{className:"text-sm text-muted-foreground",children:s("The current theme has its own background. Turn this on to replace it with your image.")}),t&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:s("Source type")}),e.jsxs(ne,{items:_,value:a,onValueChange:O=>r(O),children:[e.jsx(ae,{className:"w-48",children:e.jsx(re,{})}),e.jsx(oe,{children:_.map(O=>e.jsx(Z,{value:O.value,children:O.label},O.value))})]})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:ue}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(J,{value:B,onChange:O=>ie(O.target.value),onBlur:F,onKeyDown:O=>{O.nativeEvent.isComposing||O.key==="Enter"&&(F(),O.currentTarget.blur())},placeholder:a==="url"?"https://example.com/image.jpg":"",className:"flex-1"}),a!=="url"&&e.jsx(y,{variant:"outline",size:"icon",onClick:le,"aria-label":s("Browse"),children:a==="folder"?e.jsx(Tn,{className:"h-4 w-4"}):e.jsx(Lu,{className:"h-4 w-4"})}),a!=="file"&&e.jsx(y,{variant:"outline",size:"icon",onClick:z,"aria-label":s("Refresh now"),children:e.jsx(ns,{className:"h-4 w-4"})})]})]}),a!=="file"&&e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:s("Auto switch")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ce,{checked:c,onCheckedChange:O=>f(O===!0)}),c&&e.jsxs(e.Fragment,{children:[e.jsx(J,{type:"number",min:5,max:86400,value:X,onChange:O=>V(Number(O.target.value)),onBlur:()=>p(X),onKeyDown:O=>{O.key==="Enter"&&(p(X),O.currentTarget.blur())},className:"w-24"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:s("seconds")})]})]})]}),e.jsx(ls,{label:s("Background visibility"),value:Math.round(j*100),onCommit:O=>b(O/100)}),e.jsx(ls,{label:s("Blur"),value:A,onCommit:v,max:20,unit:"px"}),e.jsx(ls,{label:s("Brightness"),value:Math.round(k*100),onCommit:O=>I(O/100),max:200}),e.jsx(ls,{label:s("Saturation"),value:Math.round(M*100),onCommit:O=>$(O/100),max:200}),e.jsx(ls,{label:s("Overlay"),value:Math.round(E*100),onCommit:O=>L(O/100)}),e.jsx(ls,{label:s("Composer opacity"),value:Math.round(T*100),onCommit:O=>C(O/100)}),e.jsx(ls,{label:s("Code block opacity"),value:Math.round(S*100),onCommit:O=>W(O/100)}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:s("Size mode")}),e.jsxs(ne,{items:de,value:q,onValueChange:O=>N(O),children:[e.jsx(ae,{className:"w-48",children:e.jsx(re,{})}),e.jsx(oe,{children:de.map(O=>e.jsx(Z,{value:O.value,children:O.label},O.value))})]})]})]})]})}function Xm({theme:s,fontSize:t,fontFamily:n,fontWeight:a}){const r=[{id:"prompt1",text:"$ ",color:s.green},{id:"cmd1",text:"ls -la",color:s.foreground},{id:"nl1",text:`
3
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
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
5
 
@@ -14,7 +14,7 @@ import{c as Oe,w as vi,D as ea,j as e,A as bi,r as l,u as Or,a as Dr,b as vn,d a
14
14
  `)){const a=n.trim();if(!a)continue;const r=a.indexOf("=");r<=0||(t[a.slice(0,r).trim()]=a.slice(r+1))}return Object.keys(t).length>0?t:void 0},Xa=s=>s?Object.entries(s).map(([t,n])=>`${t}=${n}`).join(`
15
15
  `):"",Qa=s=>{const t={type:s.transport};return s.command&&(t.command=s.command),s.args&&s.args.length>0&&(t.args=s.args),s.env&&Object.keys(s.env).length>0&&(t.env=s.env),s.url&&(t.url=s.url),s.headers&&Object.keys(s.headers).length>0&&(t.headers=s.headers),t};function uh({server:s,onClose:t}){const{t:n}=R(),a=g(D=>D.addMcpServers),r=g(D=>D.updateMcpServer),o=s==="new",[i,m]=l.useState("form"),[u,x]=l.useState(""),[h,c]=l.useState(""),[f,d]=l.useState(""),[p,j]=l.useState(""),[b,A]=l.useState("stdio"),[v,k]=l.useState(""),[I,M]=l.useState(""),[$,E]=l.useState(""),[L,T]=l.useState(""),[C,S]=l.useState(""),[W,q]=l.useState(""),[N,z]=l.useState(""),[H,U]=l.useState(""),[B,ie]=l.useState(0),[F,X]=l.useState(null),V=()=>({description:h.trim()||void 0,oauthClientName:b!=="stdio"&&f.trim()||void 0,oauthMetadataUrl:b!=="stdio"&&p.trim()||void 0,connectTimeoutSec:qa(W,ih),callTimeoutSec:qa(N,lh)}),le=D=>{x(D.name),A(D.transport),k(D.command??""),M((D.args??[]).join(`
16
16
  `)),E(Xa(D.env&&Object.keys(D.env).length>0?D.env:void 0)),T(D.url??""),S(Wa(D.headers))},_=()=>{const D={type:b};if(b==="stdio"){D.command=v.trim();const Q=Ya(I);Q&&(D.args=Q);const ee=Ja($);ee&&(D.env=ee)}else{D.url=L.trim();const Q=Ka(C);Q&&(D.headers=Q)}return JSON.stringify(D,null,2)},de=(D,Q)=>{const ee=(Q??D.name).trim(),fe=D.env&&Object.keys(D.env).length>0?D.env:void 0,xe=D.args&&D.args.length>0?D.args:void 0;return D.transport==="stdio"?{name:ee,transport:D.transport,command:(D.command??"").trim(),args:xe,env:fe,url:void 0,headers:void 0,...V()}:{name:ee,transport:D.transport,url:(D.url??"").trim(),headers:D.headers&&Object.keys(D.headers).length>0?D.headers:void 0,command:void 0,args:void 0,env:void 0,...V()}};l.useEffect(()=>{if(!s)return;const D=s==="new"?null:s;m("form"),x(D?.name??""),c(D?.description??""),d(D?.oauthClientName??""),j(D?.oauthMetadataUrl??""),A(D?.transport??"stdio"),k(D?.command??""),M((D?.args??[]).join(`
17
- `)),E(Xa(D?.env)),T(D?.url??""),S(Wa(D?.headers)),q(D?.connectTimeoutSec?.toString()??""),z(D?.callTimeoutSec?.toString()??""),U(""),ie(Q=>Q+1),X(null)},[s]);const ue=D=>n(D==="invalid-json"?"Invalid JSON":"No MCP servers found in JSON"),O=D=>{if(D===i)return;if(D==="json"){U(_()),ie(fe=>fe+1),X(null),m("json");return}const Q=Ut(H);if(!Q.ok){if(Q.error==="invalid-json"&&H.trim()){X(ue(Q.error));return}X(null),m("form");return}if(Q.servers.length!==1){X(n("JSON must describe a single MCP server to switch to the form"));return}const ee=Q.servers[0];le({...ee,name:u.trim()||ee.name}),X(null),m("form")},De=()=>{const D=Ut(H);if(!D.ok){X(ue(D.error));return}if(D.servers.length===1){const[Q]=D.servers;U(JSON.stringify(Qa(Q),null,2)),ie(ee=>ee+1),u.trim()||x(Q.name)}else U(JSON.stringify({mcpServers:Object.fromEntries(D.servers.map(Q=>[Q.name,Qa(Q)]))},null,2)),ie(Q=>Q+1);X(null)},te=!!u.trim()&&(b==="stdio"?!!v.trim():!!L.trim()),P=i==="json"?!!H.trim():te,Y=()=>{if(!s||!P)return;if(i==="json"){const Q=Ut(H);if(!Q.ok){X(ue(Q.error));return}if(!o&&Q.servers.length!==1){X(n("JSON must describe a single MCP server"));return}if(o){const ee=Q.servers.length===1;if(a(Q.servers.map(xe=>({...de(xe,ee&&u.trim()?u:xe.name),...ee?{}:{description:void 0},id:crypto.randomUUID(),source:"Manual",enabled:!0})))===0){X(n("This MCP server already exists"));return}}else r(s.id,de(Q.servers[0],u.trim()||Q.servers[0].name));t();return}const D=b==="stdio"?{name:u.trim(),transport:b,command:v.trim(),args:Ya(I),env:Ja($),url:void 0,headers:void 0,...V()}:{name:u.trim(),transport:b,url:L.trim(),headers:Ka(C),command:void 0,args:void 0,env:void 0,...V()};if(o){if(a([{...D,id:crypto.randomUUID(),source:"Manual",enabled:!0}])===0){X(n("This MCP server already exists"));return}}else r(s.id,D);t()};return e.jsx(ye,{open:s!==null,onOpenChange:D=>!D&&t(),children:e.jsxs(we,{children:[e.jsx(Ne,{children:e.jsx(ke,{children:n(o?"Add MCP Server":"Edit MCP Server")})}),e.jsxs(Ce,{className:"space-y-4",children:[e.jsx(Qs,{value:i,onValueChange:D=>O(D),children:e.jsxs(Zs,{children:[e.jsx(Je,{value:"form",children:n("Form")}),e.jsx(Je,{value:"json",children:n("JSON")})]})}),e.jsxs(he,{children:[e.jsx(pe,{children:n("Name")}),e.jsx(J,{value:u,onChange:D=>x(D.target.value)})]}),e.jsxs(he,{children:[e.jsx(pe,{children:n("Description (optional)")}),e.jsx(J,{value:h,onChange:D=>c(D.target.value),placeholder:n("One line telling the model what this server is for")})]}),i==="json"?e.jsxs(he,{children:[e.jsxs("div",{className:"flex w-full items-center justify-between",children:[e.jsx(pe,{children:n("JSON configuration")}),e.jsx(y,{variant:"ghost",size:"sm",className:"h-7 px-2",onClick:De,children:n("Format")})]}),e.jsx(qo,{fileName:"mcp.json",value:H,epoch:B,onChange:U}),e.jsx("p",{className:"text-muted-foreground text-xs",children:n("Paste a server object or mcpServers JSON from Cursor / Claude Desktop")})]}):e.jsxs(e.Fragment,{children:[e.jsxs(he,{children:[e.jsx(pe,{children:n("Transport")}),e.jsxs(ne,{items:ja.map(D=>({value:D,label:D})),value:b,onValueChange:D=>A(D),children:[e.jsx(ae,{className:"w-full",children:e.jsx(re,{})}),e.jsx(oe,{zIndex:cs.DROPDOWN_IN_MODAL,children:ja.map(D=>e.jsx(Z,{value:D,children:D},D))})]})]}),b==="stdio"?e.jsxs(e.Fragment,{children:[e.jsxs(he,{children:[e.jsx(pe,{children:n("Command")}),e.jsx(J,{value:v,onChange:D=>k(D.target.value),placeholder:"npx",className:"font-mono text-xs"})]}),e.jsxs(he,{children:[e.jsx(pe,{children:n("Arguments (one per line)")}),e.jsx(Xe,{value:I,onChange:D=>M(D.target.value),rows:3,className:"font-mono text-xs"})]}),e.jsxs(he,{children:[e.jsx(pe,{children:n("Environment variables (KEY=VALUE, one per line)")}),e.jsx(Xe,{value:$,onChange:D=>E(D.target.value),rows:3,className:"font-mono text-xs"})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs(he,{children:[e.jsx(pe,{children:n("URL")}),e.jsx(J,{value:L,onChange:D=>T(D.target.value),placeholder:"https://...",className:"font-mono text-xs"})]}),e.jsxs(he,{children:[e.jsx(pe,{children:n("Headers (Name: value, one per line)")}),e.jsx(Xe,{value:C,onChange:D=>S(D.target.value),rows:2,placeholder:"Authorization: Bearer <token>",className:"font-mono text-xs"})]}),e.jsxs(he,{children:[e.jsx(pe,{children:n("OAuth client name (optional)")}),e.jsx(J,{value:f,onChange:D=>d(D.target.value),placeholder:n("For servers that only accept known OAuth clients")})]}),e.jsxs(he,{children:[e.jsx(pe,{children:n("OAuth authorization server metadata URL (optional)")}),e.jsx(J,{value:p,onChange:D=>j(D.target.value),placeholder:n("Use when the server advertises a wrong authorization server or none"),className:"font-mono text-xs"})]})]}),e.jsxs(he,{children:[e.jsx(pe,{children:n("Connection timeout (seconds)")}),e.jsx(J,{inputMode:"numeric",value:W,onChange:D=>q(D.target.value),placeholder:String(rh/1e3)})]}),e.jsxs(he,{children:[e.jsx(pe,{children:n("Tool call timeout (seconds)")}),e.jsx(J,{inputMode:"numeric",value:N,onChange:D=>z(D.target.value),placeholder:String(oh/1e3)})]})]}),F&&e.jsx("p",{className:"t-shake-in text-destructive text-xs",children:F},F)]}),e.jsxs(Ee,{children:[e.jsx(y,{variant:"outline",size:"sm",onClick:t,children:n("Cancel")}),e.jsx(y,{size:"sm",disabled:!P,onClick:Y,children:n("Save")})]})]})})}function mh({status:s}){const{t}=R();return s.state==="connecting"?e.jsx(se,{variant:"outline",className:"shrink-0 animate-pulse text-[11px] text-muted-foreground",children:t("Connecting")}):s.state==="ready"?e.jsx(se,{variant:"success",className:"shrink-0 text-[11px]",children:t("{{count}} tools",{count:s.toolCount??0})}):s.state==="unauthorized"?e.jsx(se,{variant:"warning",className:"shrink-0 text-[11px]",children:t("Not authorized")}):s.state==="idle"?e.jsx(se,{variant:"outline",className:"shrink-0 text-[11px] text-muted-foreground",children:t("Authorized, pending connection")}):e.jsx(se,{variant:"error",className:"shrink-0 text-[11px]",title:s.error,children:t("Connection failed")})}function xh(){const{t:s}=R(),t=g(S=>S.mcpServers),n=g(S=>S.updateMcpServer),a=g(S=>S.setMcpServersEnabled),r=g(S=>S.removeMcpServer),o=fs(S=>S.statuses),i=fs(S=>S.authorized),m=fs(S=>S.pending),u=fs(S=>S.authorize),x=fs(S=>S.revoke);l.useEffect(()=>fs.getState().bind(),[]);const[h,c]=l.useState(!1),[f,d]=l.useState(null),p=async S=>{await u(S),d(fs.getState().authorized[S]===!0?S:null)},[j,b]=l.useState(null),[A,v]=l.useState(""),k=t.filter(S=>co(A,[S.name,S.source,S.transport,S.url,S.command,...S.args??[]])),I=k.map(S=>S.id),M=uo(I),$=t.filter(S=>S.enabled).length,E=t.filter(S=>S.enabled).map(S=>S.id),L=It(E,S=>window.electronAPI.assets.mcpOccupancy(S)),T=t.filter(S=>S.enabled&&S.loadMode!=="deferred").map(S=>S.id),C=kt(T,L.rows);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-end justify-between gap-4","data-settings-row":"mcp.root",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"font-medium text-lg",children:[s("MCP Servers"),e.jsx(Ze,{}),t.length>0&&e.jsxs("span",{className:"ml-2 font-normal text-muted-foreground text-xs",children:[s("{{enabled}}/{{total}} enabled",{enabled:$,total:t.length}),e.jsx(St,{tokens:C})]})]}),e.jsx("p",{className:"text-muted-foreground text-sm",children:s("Model Context Protocol servers available to this app")})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsxs(y,{variant:"outline",size:"sm",onClick:()=>c(!0),children:[e.jsx(Nt,{className:"mr-1.5 h-4 w-4"}),s("Import from local apps")]}),e.jsxs(y,{variant:"outline",size:"sm",onClick:()=>b("new"),children:[e.jsx(Re,{className:"mr-1.5 h-4 w-4"}),s("Add MCP server")]})]})]}),t.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx(mo,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:s("No MCP servers yet")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:s("Import MCP servers from local apps or add one manually to get started")})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx(xo,{query:A,onQueryChange:v,placeholder:s("Filter MCP servers..."),allSelected:M.allSelected,someSelected:M.someSelected,onToggleSelectAll:M.toggleAll,onEnable:()=>a(M.selectedIds,!0),onDisable:()=>a(M.selectedIds,!1),selectDisabled:k.length===0,actionDisabled:M.selectedIds.length===0}),k.length===0?e.jsx("p",{className:"px-3 py-6 text-center text-muted-foreground text-xs",children:s("No results")}):e.jsx("div",{className:"space-y-1",children:k.map(S=>{const W=o[S.id]??o[S.name],q=m[S.id]===!0,N=S.transport!=="stdio"&&i[S.id]!==!0,z=S.loadMode==="deferred";return e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"group flex items-center justify-between gap-3 rounded-md px-3 py-2 transition-colors hover:bg-accent/50","data-settings-row":`mcp.${S.id}`,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(Le,{checked:M.isSelected(S.id),onCheckedChange:H=>M.toggleOne(S.id,H)}),e.jsx("span",{className:K("shrink-0 font-medium text-sm",!S.enabled&&"text-muted-foreground line-through"),children:S.name}),e.jsx(se,{variant:"outline",className:"shrink-0 text-[11px]",children:S.transport}),e.jsx(se,{variant:"secondary",className:"shrink-0 text-[11px]",children:S.source}),W&&e.jsx(mh,{status:W}),e.jsx("span",{className:"min-w-0 truncate font-mono text-muted-foreground text-xs",children:S.url??[S.command,...S.args??[]].join(" ")})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[(N||W?.state==="unauthorized")&&e.jsxs(y,{variant:"outline",size:"sm",className:"h-7",disabled:q,onClick:()=>{p(S.id)},children:[q?e.jsx(Me,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):e.jsx(yc,{className:"mr-1.5 h-3.5 w-3.5"}),s(q?"Authorizing":"Authorize")]}),i[S.id]===!0&&e.jsx(y,{variant:"ghost",size:"icon",title:s("Revoke authorization"),className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",onClick:()=>{x(S.id)},children:e.jsx(wc,{className:"h-3.5 w-3.5"})}),e.jsx(Ct,{row:L.rows[S.id],pending:S.enabled&&L.pending&&!L.rows[S.id]}),e.jsx(Qs,{value:z?"deferred":"direct",onValueChange:H=>n(S.id,{loadMode:H==="deferred"?"deferred":"direct"}),title:s("On demand: tool descriptions are not preloaded into context; the model connects through the mcp tool when needed. Suits servers with many or rarely used tools. Takes effect in new conversations."),children:e.jsxs(Zs,{"aria-label":s("Load mode"),children:[e.jsx(Je,{value:"direct",className:"h-6 px-2 text-xs sm:h-6 sm:text-xs",children:s("Always loaded")}),e.jsx(Je,{value:"deferred",className:"h-6 px-2 text-xs sm:h-6 sm:text-xs",children:s("On demand")})]})}),e.jsx(ce,{checked:S.enabled,onCheckedChange:H=>n(S.id,{enabled:H})}),e.jsx(y,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",onClick:()=>b(S),children:e.jsx(hs,{className:"h-3.5 w-3.5"})}),e.jsx(y,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity hover:text-destructive group-hover:opacity-100",onClick:()=>r(S.id),children:e.jsx(Pe,{className:"h-3.5 w-3.5"})})]})]}),f===S.id&&e.jsx("p",{className:"px-3 text-muted-foreground text-xs",children:s("Authorized. Conversations that already include this server can use it on the next message.")})]},S.id)})})]}),e.jsx(zn,{kind:"mcp",open:h,onOpenChange:c}),e.jsx(uh,{server:j,onClose:()=>b(null)})]})}const Za={PERSON:340,ORGANIZATION:20,TEAM:20,PRODUCT:210,TOOL:210,SYSTEM:250,SERVICE:250,PLATFORM:250,CONCEPT:160,METHOD:160,TECHNIQUE:160,EVENT:40,PROJECT:280,DOCUMENT:90,TERM:190};function Yo(s){if(Za[s]!==void 0)return Za[s];let t=0;for(let n=0;n<s.length;n++)t=t*17+s.charCodeAt(n)>>>0;return t%360}const $t=22,hh=64;function ph(s,t){if(t<=1)return $t;const n=Math.sqrt(Math.max(1,s))/Math.sqrt(t);return Math.round($t+(hh-$t)*Math.min(1,n))}function fh(s,t,n){const a=Math.max(1,...s.map(o=>o.memoryCount)),r=new Set(s.map(o=>o.id));return[...s.map(o=>({data:{id:o.id,label:o.name,size:ph(o.memoryCount,a),color:Jo(Yo(o.entityType),n),entityType:o.entityType,memoryCount:o.memoryCount,spaceLabel:o.spaceLabel}})),...t.filter(o=>r.has(o.source)&&r.has(o.target)&&o.source!==o.target).map(o=>({data:{id:`${o.source}->${o.target}:${o.relation}`,source:o.source,target:o.target,label:o.relation.replace(/_/g," ").toLowerCase(),width:1+o.strength*2.5}}))]}function gh(s,t){const n=new Map;for(const a of s)n.set(a.entityType,(n.get(a.entityType)??0)+1);return[...n.entries()].map(([a,r])=>({entityType:a,count:r,color:Jo(Yo(a),t)})).sort((a,r)=>r.count-a.count||a.entityType.localeCompare(r.entityType))}function jh(s){const t=s?"#e7e7e9":"#1c1c1f";return[{selector:"node",style:{"background-color":"data(color)","background-opacity":.85,width:"data(size)",height:"data(size)",label:"data(label)","font-size":11,color:t,"text-valign":"bottom","text-margin-y":4,"text-max-width":"120px","text-wrap":"ellipsis","border-width":0,"transition-property":"opacity, border-width","transition-duration":150}},{selector:"edge",style:{width:"data(width)","line-color":s?"#4b4b52":"#c9c9d1","curve-style":"bezier",opacity:.65,"font-size":9,color:t,"text-opacity":0}},{selector:"edge:selected, edge.highlighted",style:{"text-opacity":.85,opacity:1}},{selector:"node:selected",style:{"border-width":3,"border-color":t,"background-opacity":1}},{selector:".dimmed",style:{opacity:.18,"text-opacity":.25}}]}function Jo(s,t){return vh(s,t?.62:.68,t?.58:.52)}function vh(s,t,n){const a=(1-Math.abs(2*n-1))*t,r=a*(1-Math.abs(s/60%2-1)),o=n-a/2,[i,m,u]=s<60?[a,r,0]:s<120?[r,a,0]:s<180?[0,a,r]:s<240?[0,r,a]:s<300?[r,0,a]:[a,0,r],x=h=>Math.round((h+o)*255).toString(16).padStart(2,"0");return`#${x(i)}${x(m)}${x(u)}`}let er=!1;function bh(){er||(Oo.use(gu),er=!0)}const sr={name:"fcose",animate:!1,randomize:!1,nodeRepulsion:8e3,idealEdgeLength:90,nodeSeparation:90,padding:24,fit:!0};function yh({graph:s,selectedId:t,onSelect:n,memories:a,loading:r,onInterpret:o,interpreting:i}){const{t:m}=R(),u=l.useRef(null),x=l.useRef(null),h=l.useRef(n);h.current=n;const[c,f]=l.useState(null),d=l.useMemo(()=>typeof document<"u"&&document.documentElement.classList.contains("dark"),[]);l.useEffect(()=>{const b=u.current;if(!b||s.nodes.length===0)return;bh();const A=Oo({container:b,elements:fh(s.nodes,s.edges,d),style:jh(d),minZoom:.2,maxZoom:2.5,wheelSensitivity:.2});return A.layout(sr).run(),A.on("tap","node",v=>h.current(v.target.id())),A.on("tap",v=>{v.target===A&&h.current(null)}),x.current=A,()=>{A.destroy(),x.current=null}},[s.nodes,s.edges,d]),l.useEffect(()=>{const b=x.current;b&&b.batch(()=>{if(b.elements().removeClass("dimmed").unselect(),!t)return;const A=b.getElementById(t);if(A.empty())return;const v=A.closedNeighborhood();b.elements().difference(v).addClass("dimmed"),A.select()})},[t]);const p=l.useMemo(()=>gh(s.nodes,d),[s.nodes,d]),j=s.nodes.find(b=>b.id===t)??null;return l.useEffect(()=>{const b=x.current;!b||t||b.batch(()=>{b.elements().removeClass("dimmed"),c&&b.nodes().filter(A=>A.data("entityType")!==c).addClass("dimmed")})},[c,t]),s.nodes.length===0?e.jsx("p",{className:"rounded-lg border px-3 py-6 text-muted-foreground text-sm",children:m(r?"Loading…":"No entities yet. Turn on entity extraction and store a few memories first.")}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"relative overflow-hidden rounded-lg border bg-muted/20",children:[e.jsx("div",{ref:u,className:"h-[440px] w-full"}),e.jsxs("div",{className:"absolute right-2 bottom-2 flex gap-1",children:[e.jsx(y,{size:"sm",variant:"outline",onClick:()=>x.current?.fit(void 0,24),title:m("Fit to view"),children:m("Fit")}),e.jsx(y,{size:"sm",variant:"outline",onClick:()=>x.current?.layout(sr).run(),title:m("Re-run layout"),children:m("Relayout")})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:m("Colour = entity type · size = how many memories mention it",{})}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:p.map(b=>e.jsxs("button",{type:"button",onClick:()=>f(c===b.entityType?null:b.entityType),className:K("inline-flex items-center gap-1.5 rounded-full border px-2 py-0.5 text-xs transition-colors",c===b.entityType?"border-foreground/40 bg-accent":"hover:bg-accent/50"),children:[e.jsx("span",{className:"size-2.5 shrink-0 rounded-full",style:{backgroundColor:b.color}}),e.jsx("span",{className:"text-muted-foreground",children:b.entityType.toLowerCase()}),e.jsx("span",{className:"tabular-nums",children:b.count})]},b.entityType))}),e.jsx("p",{className:"text-muted-foreground text-xs",children:m("{{shown}} of {{total}} entities",{shown:String(s.nodes.length),total:String(s.totalEntities)})})]}),j&&e.jsxs("section",{className:"space-y-2 rounded-lg border p-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"flex items-center gap-2 text-sm",children:[e.jsx("span",{className:"truncate font-medium",children:j.name}),e.jsx(se,{variant:"secondary",children:j.entityType})]}),e.jsx("p",{className:"text-muted-foreground text-xs",children:m("{{count}} memories · {{space}}",{count:String(j.memoryCount),space:j.spaceLabel})})]}),e.jsx(y,{size:"sm",variant:"outline",disabled:i,onClick:()=>o(j.id),children:m(i?"Interpreting…":"Interpret")})]}),e.jsxs("ul",{className:"divide-y rounded-lg border",children:[a.length===0&&e.jsx("li",{className:"px-3 py-4 text-muted-foreground text-sm",children:m("Loading…")}),a.map(b=>e.jsxs("li",{className:"space-y-0.5 px-3 py-2",children:[e.jsxs("p",{className:"flex items-center gap-2 text-sm",children:[b.isCrystal&&e.jsx("span",{title:m("Crystal"),children:"★"}),e.jsx("span",{className:"truncate",children:b.title}),e.jsx(se,{variant:"secondary",children:b.unitType})]}),e.jsx("p",{className:"line-clamp-2 text-muted-foreground text-xs",children:b.contentSummary})]},b.id))]})]})]})}function wh({tree:s,loading:t,selected:n,onToggle:a,onInterpretGroup:r,interpreting:o}){const{t:i}=R(),[m,u]=l.useState(new Set);return s.length===0?e.jsx("p",{className:"rounded-lg border px-3 py-6 text-muted-foreground text-sm",children:i(t?"Loading…":"No memories yet.")}):e.jsx("ul",{className:"divide-y rounded-lg border",children:s.map(x=>{const h=m.has(x.id),c=(x.children??[]).map(f=>f.memoryId).filter(f=>!!f);return e.jsxs("li",{children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 px-3 py-2",children:[e.jsx("button",{type:"button",className:"min-w-0 flex-1 text-left",onClick:()=>{const f=new Set(m);f.delete(x.id)||f.add(x.id),u(f)},children:e.jsxs("p",{className:"flex items-center gap-2 text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:h?"▾":"▸"}),e.jsx("span",{className:"truncate",children:x.label}),e.jsx(se,{variant:"secondary",children:x.count})]})}),e.jsx(y,{size:"sm",variant:"ghost",className:"shrink-0",disabled:o||c.length===0,onClick:()=>r(x),children:i("Interpret")})]}),h&&e.jsxs("ul",{className:"divide-y border-t bg-muted/20",children:[(x.children??[]).map(f=>e.jsxs("li",{className:"flex items-center gap-2 px-3 py-2",children:[f.memoryId&&e.jsx(Le,{checked:n.has(f.memoryId),onCheckedChange:()=>f.memoryId&&a(f.memoryId),"aria-label":i("Select memory")}),e.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-2",children:[f.isCrystal&&e.jsx("span",{title:i("Crystal"),children:"★"}),e.jsx("span",{className:"truncate text-sm",children:f.label})]})]},f.id)),x.count>(x.children?.length??0)&&e.jsx("li",{className:"px-3 py-2 text-muted-foreground text-xs",children:i("Showing {{shown}} of {{total}}",{shown:String(x.children?.length??0),total:String(x.count)})})]})]},x.id)})})}const Nh=120,kh=30,Ch={nodes:[],edges:[],totalEntities:0};function Sh({revision:s=0}={}){const{t}=R(),[n,a]=l.useState("graph"),[r,o]=l.useState("unitType"),[i,m]=l.useState(Ch),[u,x]=l.useState([]),[h,c]=l.useState(!0),[f,d]=l.useState(null),[p,j]=l.useState([]),[b,A]=l.useState(new Set),[v,k]=l.useState(null),[I,M]=l.useState(!1),[$,E]=l.useState(null),[L,T]=l.useState(!1),C=l.useCallback(()=>{c(!0);const B=()=>c(!1);n==="graph"?window.electronAPI.memory.graph({limit:Nh,minMemories:1}).then(m).finally(B):window.electronAPI.memory.tree({groupBy:r,limitPerGroup:kh}).then(x).finally(B)},[n,r]);l.useEffect(C,[C]);const S=l.useRef(C);S.current=C,l.useEffect(()=>window.electronAPI.memory.onChanged(()=>S.current()),[]);const W=l.useRef(s);l.useEffect(()=>{W.current!==s&&(W.current=s,C())},[s,C]),l.useEffect(()=>{if(!f){j([]);return}window.electronAPI.memory.graphEntity(f).then(j)},[f]);const q=async B=>{M(!0),k(null);try{k(await window.electronAPI.memory.insight(B))}finally{M(!1)}},N=async()=>{T(!0);try{const B=await window.electronAPI.memory.crystallize({memoryIds:[...b]});E(B),B.ok&&A(new Set)}finally{T(!1)}},z=[{value:"graph",label:t("Graph")},{value:"tree",label:t("Tree")}],H=[{value:"unitType",label:t("By type")},{value:"entity",label:t("By entity")},{value:"time",label:t("By month")}],U=b.size>=va;return e.jsxs("div",{className:"space-y-4","data-settings-row":"memory.knowledge",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-medium text-sm",children:t("Knowledge")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Browse what the agent knows as a graph or a tree, ask for an interpretation, and consolidate related memories into a crystal.")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(ne,{value:n,items:z,onValueChange:B=>a(B==="tree"?"tree":"graph"),children:[e.jsx(ae,{size:"sm",className:"w-32",children:e.jsx(re,{})}),e.jsx(oe,{children:z.map(B=>e.jsx(Z,{value:B.value,children:B.label},B.value))})]}),n==="tree"&&e.jsxs(ne,{value:r,items:H,onValueChange:B=>o(B),children:[e.jsx(ae,{size:"sm",className:"w-36",children:e.jsx(re,{})}),e.jsx(oe,{children:H.map(B=>e.jsx(Z,{value:B.value,children:B.label},B.value))})]}),e.jsx("span",{className:"flex-1"}),n==="tree"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:K("text-xs",U?"text-foreground":"text-muted-foreground"),children:t("{{count}} selected",{count:String(b.size)})}),e.jsx(y,{size:"sm",variant:"outline",disabled:!U||L,onClick:()=>{N()},children:L?t("Synthesizing…"):t("Crystallize ({{min}}+)",{min:String(va)})})]})]}),n==="graph"?e.jsx(yh,{graph:i,loading:h,selectedId:f,onSelect:d,memories:p,interpreting:I,onInterpret:B=>{q({entityId:B})}}):e.jsx(wh,{tree:u,loading:h,selected:b,interpreting:I,onToggle:B=>{const ie=new Set(b);ie.delete(B)||ie.add(B),A(ie)},onInterpretGroup:B=>{const ie=(B.children??[]).map(F=>F.memoryId).filter(F=>!!F);q({memoryIds:ie})}}),e.jsx(ye,{open:v!==null,onOpenChange:B=>!B&&k(null),children:e.jsxs(we,{children:[e.jsxs(Ne,{children:[e.jsx(ke,{children:t("Interpretation")}),v?.ok&&e.jsx(Ye,{children:t("Based on {{count}} memories",{count:String(v.sourceCount??0)})})]}),e.jsx(Ce,{children:v?.ok?e.jsx("p",{className:"whitespace-pre-wrap text-sm",children:v.text}):e.jsx("p",{className:"text-destructive text-sm",children:v?.error})}),e.jsx(Ee,{children:e.jsx(Hs,{render:e.jsx(y,{variant:"outline",size:"sm"}),children:t("Close")})})]})}),e.jsx(ye,{open:$!==null,onOpenChange:B=>!B&&E(null),children:e.jsxs(we,{children:[e.jsxs(Ne,{children:[e.jsx(ke,{children:$?.ok?t("Crystal created"):t("Nothing was written")}),$?.ok&&e.jsx(Ye,{children:$.title})]}),e.jsx(Ce,{className:"space-y-3",children:$?.ok?e.jsx("p",{className:"whitespace-pre-wrap text-sm",children:$.content}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-destructive text-sm",children:$?.error}),$?.candidates&&$.candidates.length>0&&e.jsx("ul",{className:"divide-y rounded-lg border",children:$.candidates.map(B=>e.jsxs("li",{className:"flex items-center justify-between gap-2 px-3 py-2",children:[e.jsx("span",{className:"truncate text-sm",children:B.title}),e.jsxs(se,{variant:"secondary",children:[(B.similarity*100).toFixed(0),"%"]})]},B.id))})]})}),e.jsx(Ee,{children:e.jsx(Hs,{render:e.jsx(y,{variant:"outline",size:"sm"}),children:t("Close")})})]})})]})}function hn(s){return s==="fast"||s==="deep"}const Ss=25,Fe="__all__";function Os(s){const t=new Date(s);if(Number.isNaN(t.getTime()))return s;const n=a=>String(a).padStart(2,"0");return`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())} ${n(t.getHours())}:${n(t.getMinutes())}`}const tr=["global","project","secretary","bot","chat"],Ih={global:"Global",project:"Projects",secretary:"Secretary",bot:"Members",chat:"Group chats"};function Ah(s,t,n){return t?{spaceId:t}:s?{spaceIds:n.filter(a=>a.kind===s).map(a=>a.id)}:{}}function Eh(s){return s.startsWith("bot:")?"bot":s.startsWith("chat:")?"chat":s.startsWith("proj:")?"project":"global"}function Mh(s,t){return s===!1&&!t}function Ph(s,t,n,a){return hn(s)&&!t.trim()?"needs-query":Mh(n,a)?"library-empty":"no-match"}function Th({items:s,onOpen:t,onEdit:n,onDelete:a,t:r,selected:o,onToggle:i,emptyLabel:m}){return e.jsxs("ul",{className:"divide-y overflow-hidden rounded-lg border",children:[s.length===0&&e.jsx("li",{className:"px-3 py-6 text-sm text-muted-foreground",children:m}),s.map(u=>e.jsxs("li",{className:K(Ac,"flex items-center gap-2 px-3 py-2"),"data-memory-id":u.id,children:[i&&e.jsx(Le,{checked:o?.has(u.id)??!1,onCheckedChange:()=>i(u.id),"aria-label":r("Select memory")}),e.jsxs("button",{type:"button",onClick:()=>t(u.id),className:"min-w-0 flex-1 space-y-0.5 text-left",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[u.isCrystal&&e.jsx("span",{title:r("Crystal"),children:"★"}),e.jsx("span",{className:"truncate text-sm",children:u.title}),e.jsx(se,{variant:"secondary",children:u.unitType}),e.jsx(Oh,{importance:u.importance,t:r}),u.lifecycleState==="archived"&&e.jsx(se,{variant:"outline",children:r("Archived")}),u.archiveCandidateAt&&e.jsx(se,{variant:"warning",title:r("Marked by the forgetting pass: cold and low importance"),children:r("Archive candidate")})]}),e.jsx("span",{className:"line-clamp-2 text-muted-foreground text-xs",children:u.contentSummary}),e.jsxs("span",{className:"block text-muted-foreground text-xs",children:[r("Recorded {{date}}",{date:Os(u.createdAt)})," · ",u.spaceLabel," ","· ",r("Retrieved {{count}} times",{count:String(u.appearances)})]})]}),n&&a&&e.jsx(Ic,{id:u.id,onEdit:n,onDelete:a})]},u.id))]})}const Rh={critical:{variant:"warning",label:"critical"},important:{variant:"info",label:"important"},useful:{variant:"outline",label:"useful"},low:{variant:"outline",label:"low"}};function Oh({importance:s,t}){const n=Pc(s),a=Rh[n];return e.jsx(se,{variant:a.variant,className:n==="low"?"text-muted-foreground":void 0,title:t("Importance {{value}}",{value:s.toFixed(2)}),children:t(a.label)})}const Dh=6,Lh=50;function zh(s){const t=[...s].sort((a,r)=>r.edge.createdAt.localeCompare(a.edge.createdAt)||a.edge.id.localeCompare(r.edge.id));if(t.length<=Dh)return[{key:"",label:"",items:t}];const n=new Map;for(const a of t){const r=a.older.spaceId,o=n.get(r)??{key:r,label:a.older.spaceLabel,items:[]};o.items.push(a),n.set(r,o)}return[...n.values()].sort((a,r)=>a.label.localeCompare(r.label))}function nr({label:s,memory:t,onOpen:n}){return e.jsxs("button",{type:"button",onClick:()=>n(t.id),className:"block w-full space-y-0.5 rounded-md px-1 py-0.5 text-left hover:bg-accent/40","data-memory-review-side":t.id,children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"shrink-0 text-muted-foreground text-xs",children:s}),e.jsx("span",{className:"truncate text-sm",children:t.title})]}),e.jsx("span",{className:"line-clamp-2 text-muted-foreground text-xs",children:t.contentSummary})]})}function _h({items:s,selected:t,onToggle:n,onToggleAll:a,onReview:r,onOpen:o,t:i}){if(s.length===0)return e.jsxs("section",{className:"space-y-2","data-settings-row":"memory.review",children:[e.jsx("h3",{className:"text-sm font-medium",children:i("Needs review")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:i("Nothing to review. When a new memory contradicts an existing one, the pair shows up here.")})]});const m=s.every(u=>t.has(u.edge.id));return e.jsxs("section",{className:"space-y-2","data-settings-row":"memory.review",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("h3",{className:"text-sm font-medium",children:i("Needs review")}),e.jsxs("label",{className:"flex items-center gap-2 text-muted-foreground text-xs",children:[e.jsx(Le,{checked:m,onCheckedChange:()=>a(!m),"aria-label":i("Select all")}),i("{{count}} pending",{count:String(s.length)})]})]}),e.jsxs("div",{className:"space-y-0.5 text-muted-foreground text-xs",children:[e.jsx("p",{children:i("Reviewing only records your judgement. Nothing is deleted and no memory is superseded.")}),e.jsx("p",{children:i("Accept: recorded as a confirmed contradiction. Both memories stay and stay searchable — you just stop being asked.")}),e.jsx("p",{children:i("Dismiss: recorded as not a contradiction. Both memories stay unchanged and you stop being asked.")})]}),s.length>Lh&&e.jsx("p",{className:"text-warning text-xs","data-memory-review-alert":!0,children:i("{{count}} contradictions are waiting for review. Clear them in bulk so real conflicts do not get buried.",{count:String(s.length)})}),t.size>0&&e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 rounded-lg border bg-accent/30 px-3 py-2",children:[e.jsx("span",{className:"text-sm",children:i("{{count}} selected",{count:String(t.size)})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(y,{variant:"ghost",size:"sm",onClick:()=>a(!1),children:i("Clear selection")}),e.jsx(y,{variant:"outline",size:"sm",onClick:()=>r([...t],"accepted"),children:i("Accept selected")}),e.jsx(y,{variant:"ghost",size:"sm",onClick:()=>r([...t],"rejected"),children:i("Dismiss selected")})]})]}),zh(s).map(u=>e.jsxs("div",{className:"space-y-2",children:[u.label&&e.jsxs("h4",{className:"text-muted-foreground text-xs",children:[u.label," · ",i("{{count}} pending",{count:String(u.items.length)})]}),u.items.map(({edge:x,older:h,newer:c})=>e.jsxs("div",{className:"space-y-1.5 rounded-lg border px-3 py-2","data-memory-review":x.id,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(Le,{checked:t.has(x.id),onCheckedChange:()=>n(x.id),"aria-label":i("Select memory")}),e.jsx(se,{variant:"outline",children:x.relation}),e.jsxs("span",{className:"text-muted-foreground text-xs",children:[h.spaceLabel," · ",Os(x.createdAt)]})]}),e.jsx(nr,{label:i("Earlier memory"),memory:h,onOpen:o}),e.jsx(nr,{label:i("Newer memory"),memory:c,onOpen:o}),e.jsx("p",{className:"text-muted-foreground text-xs",children:x.reason?`${i("Why they conflict")}: ${x.reason}`:i("No reason recorded for this pair.")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(y,{size:"sm",variant:"outline",onClick:()=>r([x.id],"accepted"),children:i("Accept")}),e.jsx(y,{size:"sm",variant:"ghost",onClick:()=>r([x.id],"rejected"),children:i("Dismiss")})]})]},x.id))]},u.key))]})}function Fh({writes:s,onReview:t,t:n}){return s.length===0?null:e.jsxs("section",{className:"space-y-2","data-settings-row":"memory.pending-writes",children:[e.jsx("h3",{className:"text-sm font-medium",children:n("Memory writes awaiting approval")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n("Bot members need your approval before writing to project or global memory.")}),s.map(a=>e.jsxs("div",{className:"space-y-1 rounded-lg border px-3 py-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-xs text-muted-foreground",children:[a.originLabel&&e.jsx("span",{className:"text-foreground",children:a.originLabel}),e.jsxs("span",{children:["→ ",a.spaceLabel]}),a.redacted&&e.jsxs("span",{children:["· ",n("Secrets redacted")]})]}),a.title&&e.jsx("div",{className:"text-sm font-medium",children:a.title}),e.jsx("p",{className:"whitespace-pre-wrap text-xs",children:a.content}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(y,{size:"sm",variant:"outline",onClick:()=>t(a.id,"approve"),children:n("Approve")}),e.jsx(y,{size:"sm",variant:"ghost",onClick:()=>t(a.id,"reject"),children:n("Reject")})]})]},a.id))]})}function Bh({t:s}){const t=Ec(),n=Mc(a=>a.review);return e.jsx(Fh,{writes:t,t:s,onReview:(a,r)=>{n(a,r)}})}function Uh({revision:s=0}={}){const{t}=R(),[n,a]=l.useState(""),[r,o]=l.useState(Fe),[i,m]=l.useState(Fe),[u,x]=l.useState(Fe),[h,c]=l.useState(!1),[f,d]=l.useState(!1),[p,j]=l.useState(0),[b,A]=l.useState("exact"),[v,k]=l.useState(!1),[I,M]=l.useState(!0),[$,E]=l.useState([]),[L,T]=l.useState(0),[C,S]=l.useState([]),W=l.useRef(C);W.current=C;const[q,N]=l.useState(null),[z,H]=l.useState(null),[U,B]=l.useState(null),[ie,F]=l.useState(null),[X,V]=l.useState(new Set),[le,_]=l.useState(!1),[de,ue]=l.useState([]),[O,De]=l.useState(new Set),te=l.useRef(!1),P=l.useRef(0),Y=l.useRef(0);l.useEffect(()=>(te.current=!0,()=>{te.current=!1,P.current++,Y.current++}),[]);const D=l.useCallback(()=>{if(!te.current)return;const G=++P.current,je=()=>te.current&&G===P.current;if(hn(b)&&!n.trim()){E([]),T(0),k(!0),M(!0);return}const be=tr.find(Ae=>Ae===r)??null;window.electronAPI.memory.list({query:n.trim()||void 0,...Ah(be,i===Fe?null:i,W.current),unitType:u===Fe?void 0:u,includeArchived:h,archiveCandidate:f||void 0,limit:Ss,offset:p,mode:b}).then(Ae=>{je()&&(E(Ae.items),T(Ae.total),k(Ae.approximate===!0),M(Ae.vectorsUsed!==!1))}),window.electronAPI.memory.stats().then(Ae=>{te.current&&(S(Object.keys(Ae.bySpace).map(qe=>({id:qe,label:Ae.spaceLabels[qe]??qe,kind:Ae.spaceKinds?.[qe]??Eh(qe)}))),N(Ae.total>0))}),window.electronAPI.memory.evolvesPending().then(Ae=>{te.current&&ue(Ae)})},[n,r,i,u,h,f,p,b]);l.useEffect(()=>(D(),()=>{P.current++}),[D]);const Q=l.useRef(D);Q.current=D,l.useEffect(()=>window.electronAPI.memory.onChanged(()=>Q.current()),[]);const ee=l.useRef(s);l.useEffect(()=>{ee.current!==s&&(ee.current=s,D())},[s,D]);const fe=G=>{const je=++Y.current;window.electronAPI.memory.detail(G).then(be=>{te.current&&je===Y.current&&H(be)})},xe=()=>{Y.current++,H(null)},Ls=async(G,je)=>{_(!0);try{for(const be of G)await je(be)}finally{te.current&&(_(!1),V(new Set),Q.current())}},ds=()=>{Ls(X,G=>window.electronAPI.memory.archive(G))},vs=(G,je)=>{G.length!==0&&(_(!0),(async()=>{try{for(const be of G)await window.electronAPI.memory.evolvesReview(be,je)}finally{te.current&&(_(!1),De(new Set),Q.current())}})())},He=G=>{te.current&&(V(new Set),z&&G.includes(z.id)&&xe(),Q.current())},zs=G=>{te.current&&(U?.reopen&&fe(G),Q.current())},ge=G=>{G.then(()=>{te.current&&(xe(),Q.current())})},as=n.trim()!==""||r!==Fe||i!==Fe||u!==Fe||h===!0,rs=[{value:Fe,label:t("All space types")},...tr.filter(G=>C.some(je=>je.kind===G)).map(G=>({value:G,label:t(Ih[G])}))],_s=[{value:Fe,label:t("All spaces")},...C.filter(G=>r===Fe||G.kind===r).map(G=>({value:G.id,label:G.label}))],os=[{value:Fe,label:t("All types")},...Nc.map(G=>({value:G,label:G}))],Fs=[{value:"exact",label:t("Exact match")},{value:"fast",label:t("Fast retrieval")},{value:"deep",label:t("Deep retrieval")}];return e.jsxs("div",{className:"space-y-4","data-settings-row":"memory.library",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium",children:t("Stored memories")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Everything the agent has saved. Archiving hides a memory from search but keeps it.")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(ho,{className:"w-full sm:w-96","data-size":"sm",children:[e.jsx(po,{value:n,placeholder:t("Search memories"),onChange:G=>{j(0),a(G.target.value)}}),e.jsx(fo,{align:"inline-end",className:"pe-1",children:e.jsxs(ne,{value:b,items:Fs,onValueChange:G=>{j(0),A(G==="deep"?"deep":G==="fast"?"fast":"exact")},children:[e.jsx(ae,{size:"sm",className:"w-auto min-w-0 gap-1 border-0 bg-transparent px-2 shadow-none before:hidden",children:e.jsx(re,{})}),e.jsx(oe,{children:Fs.map(G=>e.jsx(Z,{value:G.value,children:G.label},G.value))})]})})]}),e.jsxs(ne,{value:r,items:rs,onValueChange:G=>{j(0),o(String(G)),m(Fe)},children:[e.jsx(ae,{size:"sm",className:"w-36","data-memory-filter":"space-kind",children:e.jsx(re,{})}),e.jsx(oe,{children:rs.map(G=>e.jsx(Z,{value:G.value,children:G.label},G.value))})]}),e.jsxs(ne,{value:i,items:_s,onValueChange:G=>{j(0),m(String(G))},children:[e.jsx(ae,{size:"sm",className:"w-36","data-memory-filter":"space",children:e.jsx(re,{})}),e.jsx(oe,{children:_s.map(G=>e.jsx(Z,{value:G.value,children:G.label},G.value))})]}),e.jsxs(ne,{value:u,items:os,onValueChange:G=>{j(0),x(String(G))},children:[e.jsx(ae,{size:"sm",className:"w-36",children:e.jsx(re,{})}),e.jsx(oe,{children:os.map(G=>e.jsx(Z,{value:G.value,children:G.label},G.value))})]}),b==="exact"&&e.jsxs("label",{className:"flex items-center gap-2 text-muted-foreground text-sm",children:[e.jsx(ce,{checked:h,onCheckedChange:G=>{j(0),c(G===!0)}}),t("Show archived")]}),b==="exact"&&e.jsxs("label",{className:"flex items-center gap-2 text-muted-foreground text-sm",children:[e.jsx(ce,{checked:f,onCheckedChange:G=>{j(0),d(G===!0)}}),t("Archive candidates only")]})]}),hn(b)&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:[t(b==="deep"?"Same recall as Fast, plus intent-weighted fusion and an optional short-timeout LLM rerank. Failures fall back; archived memories are excluded.":"Same path the agent uses: full-text, vectors and entities merged by relevance. Shows the top matches only — no exact count, and archived memories are excluded."),!I&&` ${t("Embedding model is not ready, so vectors are skipped.")}`]}),X.size>0&&e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border bg-accent/30 px-3 py-2",children:[e.jsx("span",{className:"text-sm",children:t("{{count}} selected",{count:String(X.size)})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(y,{variant:"ghost",size:"sm",disabled:le,onClick:()=>V(new Set),children:t("Clear selection")}),e.jsx(y,{variant:"outline",size:"sm",disabled:le,onClick:()=>ds(),children:t("Archive selected")}),e.jsx(y,{variant:"destructive-outline",size:"sm",disabled:le,onClick:()=>F([...X]),children:t("Delete permanently")})]})]}),e.jsx(Th,{items:$,onOpen:fe,onEdit:G=>B({id:G,reopen:!1}),onDelete:G=>F([G]),t,selected:X,emptyLabel:{"needs-query":t("Type a query to search by meaning."),"library-empty":t("No memories yet. They appear here once the agent stores something."),"no-match":t("No memories match these filters.")}[Ph(b,n,q,as)],onToggle:G=>{const je=new Set(X);je.delete(G)||je.add(G),V(je)}}),!v&&L>Ss&&e.jsxs("div",{className:"flex items-center justify-between text-xs text-muted-foreground",children:[e.jsx(y,{variant:"outline",size:"sm",disabled:p===0,onClick:()=>j(Math.max(0,p-Ss)),children:t("Previous")}),e.jsxs("span",{children:[p+1,"–",Math.min(p+Ss,L)," / ",L]}),e.jsx(y,{variant:"outline",size:"sm",disabled:p+Ss>=L,onClick:()=>j(p+Ss),children:t("Next")})]}),e.jsx(Bh,{t}),e.jsx(_h,{items:de,selected:O,onToggle:G=>{const je=new Set(O);je.delete(G)||je.add(G),De(je)},onToggleAll:G=>De(G?new Set(de.map(je=>je.edge.id)):new Set),onOpen:fe,onReview:vs,t}),e.jsx(ye,{open:z!==null,onOpenChange:G=>!G&&xe(),children:e.jsx(we,{finalFocus:kc,children:z&&e.jsxs(e.Fragment,{children:[e.jsxs(Ne,{children:[e.jsx(ke,{children:z.title}),e.jsx(Ye,{children:[z.unitType,z.spaceLabel].join(" · ")})]}),e.jsxs(Ce,{className:"space-y-4","data-memory-detail":z.id,children:[e.jsx("p",{className:"whitespace-pre-wrap text-sm","data-memory-field":"content",children:z.content}),e.jsxs("dl",{className:"grid grid-cols-2 gap-x-4 gap-y-3",children:[e.jsx($s,{label:t("Importance"),value:z.importance.toFixed(2)}),e.jsx($s,{label:t("Recorded at"),value:Os(z.createdAt)}),z.updatedAt!==z.createdAt&&e.jsx($s,{label:t("Updated at"),value:Os(z.updatedAt)}),e.jsx($s,{label:t("Embedding"),value:z.embeddingModel??t("Not vectorized")}),z.eventStart&&e.jsx($s,{label:t("Event date"),value:`${z.eventStart}${z.eventEnd?` → ${z.eventEnd}`:""}`})]}),z.entityNames.length>0&&e.jsxs("section",{className:"space-y-1.5",children:[e.jsx("p",{className:"font-medium text-xs",children:t("Entities")}),e.jsx("div",{className:"flex flex-wrap gap-1",children:z.entityNames.map(G=>e.jsx(se,{variant:"secondary",children:G},G))})]}),z.crystalSources.length>0&&e.jsxs("section",{className:"space-y-1.5",children:[e.jsx("p",{className:"font-medium text-xs",children:t("Synthesized from")}),e.jsx("ul",{className:"divide-y rounded-lg border",children:z.crystalSources.map(G=>e.jsxs("li",{className:"flex items-center justify-between gap-2 px-3 py-2",children:[e.jsx("span",{className:"truncate text-sm",children:G.title}),e.jsxs("span",{className:"shrink-0 text-muted-foreground text-xs",children:[(G.contributionWeight*100).toFixed(0),"%"]})]},G.id))})]}),z.evolves.length>0&&e.jsxs("section",{className:"space-y-1.5",children:[e.jsx("p",{className:"font-medium text-xs",children:t("Related versions")}),e.jsx("ul",{className:"divide-y rounded-lg border",children:z.evolves.map(G=>e.jsxs("li",{className:"flex items-center gap-2 px-3 py-2",children:[e.jsx(se,{variant:"outline",children:G.relation}),e.jsx("span",{className:"text-muted-foreground text-xs",children:G.reviewState})]},G.id))})]})]}),e.jsxs(Ee,{children:[e.jsx(y,{variant:"destructive-outline",size:"sm",className:"sm:me-auto","data-memory-action":"delete",onClick:()=>F([z.id]),children:t("Delete permanently")}),e.jsx(y,{variant:"outline",size:"sm","data-memory-action":"edit",onClick:()=>{xe(),B({id:z.id,reopen:!0})},children:t("Edit")}),z.lifecycleState==="archived"?e.jsx(y,{variant:"outline",size:"sm",onClick:()=>ge(window.electronAPI.memory.restore(z.id)),children:t("Restore")}):e.jsx(y,{variant:"outline",size:"sm",onClick:()=>ge(window.electronAPI.memory.archive(z.id)),children:t("Archive")})]})]})})}),e.jsx(Cc,{memoryId:U?.id??null,onClose:()=>B(null),onSaved:zs}),e.jsx(Sc,{ids:ie,onClose:()=>F(null),onDeleted:He})]})}function $s({label:s,value:t}){return e.jsxs("div",{className:"min-w-0",children:[e.jsx("dt",{className:"text-muted-foreground text-xs",children:s}),e.jsx("dd",{className:"truncate text-sm",children:t})]})}const Xo="openai-compatible",$h=/embed|bge|m3e|voyage|jina|nomic|mxbai|stella|conan|acge|retriev|text-(?:similarity|search)|(?:^|[^a-z0-9])(?:e5|gte|bce)(?:[^a-z0-9]|$)/i;function Qo(s){return $h.test(s)}function Un(s){return Array.isArray(s.models)?s.models.filter(t=>typeof t?.id=="string"&&Qo(t.id)):[]}function Vh(s){return s.flatMap(t=>{if(!t.apiKey||typeof t.baseUrl!="string"||!t.baseUrl.trim())return[];const n=Un(t);return n.length>0?[{...t,models:n}]:[]})}function Gh(s){const t=[];for(const n of s){const a=!!n.apiKey,r=typeof n.baseUrl=="string"&&!!n.baseUrl.trim();if(!a&&!r)continue;let o=null;a?r?Un(n).length===0&&(o="no-embedding-models"):o="no-base-url":o="no-api-key",o&&t.push({providerId:n.id,name:n.name,reason:o})}return t}const Kh={"no-api-key":"{{name}}: missing API key","no-base-url":"{{name}}: missing Base URL","no-embedding-models":"{{name}}: no matching embedding model (model names must contain keywords like embed/voyage/bge)"};function Wh(s,t,n){return n(Kh[s],{name:t})}function Hh(s){const{providerId:t,provider:n,modelId:a}=s;return t?n?n.apiKey?typeof n.baseUrl!="string"||!n.baseUrl.trim()?"no-base-url":!a||a===Xo?"no-model":Qo(a)?null:Un(n).length>0?"not-embedding-model":"no-embedding-models":"no-api-key":"provider-missing":"no-provider"}const qh={"no-provider":"No remote embedding provider is selected. Choose a provider with an API key, or switch to a local embedding model.","provider-missing":"The selected embedding provider no longer exists. Choose another provider, or switch to a local embedding model.","no-base-url":'Provider "{{provider}}" has no Base URL. Fill it in, or choose another provider.',"no-api-key":'Provider "{{provider}}" has no API key. Subscription sign-in cannot be used for embeddings; choose a provider with an API key, or switch to a local embedding model.',"no-model":"No remote embedding model is selected. Choose a model that supports /embeddings.","not-embedding-model":'"{{model}}" is a chat model and cannot be used for embeddings. Choose a model that supports /embeddings, or switch to a local embedding model.',"no-embedding-models":'Provider "{{provider}}" has no embedding model ("{{model}}" is a chat model). Add one that supports /embeddings (e.g. text-embedding-3-small), or switch to a local embedding model.'},Yh="No model can be used for embeddings: it needs a provider with an API key and an embedding model (e.g. text-embedding-3-small). Subscription sign-in cannot be used for embeddings.";function Jh(s,t,n){return n(qh[s],{provider:t.provider??"",model:t.model??""})}const ar=s=>s.slice(0,8);function Vt(s,t){return s==="pending"||s==="running"?"running":s==="cancelled"?"cancelled":t?"failed":"done"}const Xh={low_importance:"importance too low",candidates_found:"similar memory already exists",deduplicated:"identical to an existing memory",rejected:"rejected"};function Qh(s){const t=[];for(const r of s.distill){const o=Vt(r.status,r.error);t.push({key:`distill:${r.id}`,kind:"distill",target:r.sessionTitle||ar(r.sessionId),state:o,detail:o==="failed"?r.error??"":o==="cancelled"?"superseded":o==="running"?r.attempts>1?`retry ${r.attempts}`:"queued":`${r.done} stored`,notes:(r.notes??[]).map(i=>[i.title,Xh[i.kind]??i.kind].filter(Boolean).join(" — ")),updatedAt:r.updatedAt})}for(const r of s.kg){const o=Vt(r.status,r.error);t.push({key:`kg:${r.id}`,kind:"kg",target:r.memoryTitle||ar(r.memoryId),state:o,detail:o==="failed"?r.error??"":o==="cancelled"?"memory changed":o==="running"?"extracting":`${r.total} entities · ${r.done} links`,notes:[],updatedAt:r.updatedAt})}const n=s.reembed;if(n){const r=Vt(n.status,n.error);t.push({key:`reembed:${n.id}`,kind:"reembed",target:n.target,state:r,detail:r==="failed"?n.error??"":r==="running"?`${n.done}/${n.total}`:`${n.done} vectorized${n.failed>0?` · ${n.failed} failed`:""}`,notes:[],updatedAt:n.updatedAt})}const a=r=>r.state==="running"?0:r.state==="failed"?1:2;return t.sort((r,o)=>a(r)-a(o)||o.updatedAt.localeCompare(r.updatedAt))}const qs=`remote:${Xo}`,bt="remote:";function rr(s){return s.id==="none"?"None (full-text only)":s.id.replace(/^(local|remote):/,"")}function At(s){return s.startsWith(bt)&&s.length>bt.length}function Zh(s){return At(s)?qs:s}function ep(s){return!At(s)||s===qs?null:s.slice(bt.length)}function sp(s){return`${bt}${s}`}function tp(s,t){return t===qs?At(s)?s:qs:t}const np=4e3,ap=800,or=6,rp={distill:"job:distill",kg:"job:entities",reembed:"job:vectors"},ir={distill:[],kg:[],reembed:null,kgFailed:0};function op(s){return s.some(t=>t.distilled)}function lr(s){return!s||s.total===0||s.embedded>=s.total?null:s.embeddingError??null}function cr(s){return s?.downloadable&&(s.state==="missing"||s.state==="downloading")?s.state:null}function ip(s,t){if(s.done===0||s.done>=s.total)return null;const n=(t-s.startedAt)/s.done;return Math.round(n*(s.total-s.done))}function lp(s){const t=Math.max(1,Math.round(s/1e3));if(t<60)return`${t}s`;const n=Math.floor(t/60);return t%60===0?`${n}m`:`${n}m ${t%60}s`}function cp(s){const t=new Map;for(const a of s){const r=a.projectId??"",o=t.get(r);if(o){o.sessions.push(a);continue}t.set(r,{key:r,name:a.projectName??"No project",sessions:[a]})}const n=[...t.values()];return[...n.filter(a=>a.key),...n.filter(a=>!a.key)]}function me(s){if(s<=0)return"0 B";const t=["B","KB","MB","GB"],n=Math.min(Math.floor(Math.log(s)/Math.log(1024)),t.length-1);return`${(s/1024**n).toFixed(n===0?0:1)} ${t[n]}`}function Gt(s,t,n){return(s.includes(t)?[...s]:[...s,t].sort((r,o)=>r-o)).map(r=>({value:String(r),label:n(r)}))}function Is({title:s,description:t,checked:n,onChange:a,rowId:r,disabled:o}){return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5","data-settings-row":r,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t})]}),e.jsx(ce,{checked:n,disabled:o,onCheckedChange:i=>a(i===!0)})]})}function Kt({title:s,description:t,value:n,items:a,onChange:r,rowId:o,disabled:i}){return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5","data-settings-row":o,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t})]}),e.jsxs(ne,{value:n,items:a,onValueChange:m=>r(String(m)),disabled:i,children:[e.jsx(ae,{className:"w-40 shrink-0",children:e.jsx(re,{})}),e.jsx(oe,{children:a.map(m=>e.jsx(Z,{value:m.value,children:m.label},m.value))})]})]})}function dp({onLibraryChanged:s}={}){const{t}=R(),n=g(w=>w.disabledBuiltinTools),a=g(w=>w.memoryEmbeddingModel),r=g(w=>w.setMemoryEmbeddingModel),o=g(w=>w.memoryEmbeddingAutoDownload),i=g(w=>w.setMemoryEmbeddingAutoDownload),m=g(w=>w.memoryModelIdleMinutes),u=g(w=>w.setMemoryModelIdleMinutes),x=g(w=>w.memoryEmbeddingRemoteProviderId),h=g(w=>w.setMemoryEmbeddingRemoteProviderId),c=g(w=>w.providers),f=g(w=>w.memoryDistillEnabled),d=g(w=>w.setMemoryDistillEnabled),p=g(w=>w.memoryKgEnabled),j=g(w=>w.setMemoryKgEnabled),b=g(w=>w.memoryDecayEnabled),A=g(w=>w.setMemoryDecayEnabled),v=g(w=>w.memoryDecayArchiveCandidates),k=g(w=>w.setMemoryDecayArchiveCandidates),I=g(w=>w.memoryDecayAutoArchive),M=g(w=>w.setMemoryDecayAutoArchive),$=g(w=>w.memoryDecayStaleDays),E=g(w=>w.setMemoryDecayStaleDays),L=g(w=>w.memoryDecayMaxImportance),T=g(w=>w.setMemoryDecayMaxImportance),C=g(w=>w.memoryDecayIntervalDays),S=g(w=>w.setMemoryDecayIntervalDays),W=g(w=>w.memoryDistillModel),q=g(w=>w.setMemoryDistillModel),N=g(w=>w.memoryChatModel)||"remote",z=g(w=>w.setMemoryChatModel),H=g(w=>w.memoryLanguage),U=g(w=>w.setMemoryLanguage),B=es(),ie=W?B.find(w=>w.id===W.providerId):void 0,F=ie?.models.find(w=>w.id===W?.modelId),X=ep(a),V=l.useMemo(()=>Vh(B),[B]),le=l.useMemo(()=>Gh(B),[B]),_=x?V.find(w=>w.id===x):void 0,de=_?.models.find(w=>w.id===X),ue=x?c.find(w=>w.id===x):void 0,O=Hh({providerId:x,provider:ue,modelId:X}),De=O&&O!=="no-provider"&&O!=="no-model"?Jh(O,{provider:ue?.name||x||"",model:X??""},t):null,te=!n.includes("memory"),[P,Y]=l.useState(null),[D,Q]=l.useState(ir),[ee,fe]=l.useState([]),[xe,Ls]=l.useState(null),[ds,vs]=l.useState([]),[He,zs]=l.useState(null),[ge,as]=l.useState([]),[rs,_s]=l.useState(null),[os,Fs]=l.useState(null),[G,je]=l.useState(null),[be,Ae]=l.useState(null),[qe,Vn]=l.useState(!1),[Et,pi]=l.useState(!1),[Be,Gn]=l.useState(null),[bs,Mt]=l.useState(new Set),[st,tt]=l.useState(null),Pt=P?.forgetting??null,Bs=Pt?.lastRun??null,fi=Bs?t("Last run {{date}}: {{scored}} scored, {{candidates}} candidates, {{archived}} archived",{date:Os(Bs.ranAt),scored:String(Bs.scored),candidates:String(Bs.candidates),archived:String(Bs.archived)}):t("Never run yet"),Kn=l.useRef(!1);Kn.current=qe;const ys=l.useRef(null),Tt=l.useCallback(()=>{window.electronAPI.memory.distillableSessions().then(as)},[]);l.useEffect(()=>{te&&Tt()},[te,Tt]);const ws=l.useCallback(()=>{window.electronAPI.memory.models().then(fe)},[]);l.useEffect(()=>(ws(),window.electronAPI.memory.onModelProgress(w=>{Ls(w.done?null:w),w.done&&ws()})),[ws]);const Ns=l.useCallback(()=>{window.electronAPI.memory.chatModels().then(w=>vs(w.filter(ve=>!ve.purpose)))},[]);l.useEffect(()=>(Ns(),window.electronAPI.memory.onChatModelProgress(w=>{zs(w.done?null:w),w.done&&Ns()})),[Ns]),l.useEffect(()=>{if(!te){Y(null),Q(ir);return}let w=!1;const ve=()=>{window.electronAPI.memory.stats().then(is=>{w||Y(is)}),window.electronAPI.memory.jobs().then(is=>{w||(Q(is),Kn.current&&is.reembed?.status!=="running"&&Vn(!1))})};ys.current=ve,ve();const Ue=window.electronAPI.memory.onChanged(ve),Us=window.setInterval(ve,qe?ap:np);return()=>{w=!0,ys.current=null,Ue(),window.clearInterval(Us)}},[te,qe]);const Wn=cp(ge),Hn=ge.filter(w=>!w.distilled),gi=()=>{tt("run"),window.electronAPI.memory.runForgetting().then(()=>{tt(null),ys.current?.()})},qn=()=>{window.electronAPI.memory.archiveCandidates({limit:200,offset:0}).then(w=>{Gn(w),Mt(new Set)})},ji=()=>{const w=[...bs];w.length!==0&&(tt("archive"),window.electronAPI.memory.confirmArchiveCandidates(w).then(()=>{tt(null),qn(),ys.current?.(),s?.()}))},Yn=(w,ve,Ue)=>{const Us=w.filter(is=>!is.distilled);if(!op(w)){nt(w,ve);return}Ae({token:ve,label:Ue,scope:w,pending:Us})},nt=async(w,ve,Ue=!1)=>{const Us=ds.find(Cs=>Cs.id===N)??null;if(cr(Us))return;_s(ve);const is=Date.now();je({done:0,total:w.length,startedAt:is});try{for(let Cs=0;Cs<w.length;Cs++)await window.electronAPI.memory.distillSession(w[Cs].sessionId,Ue),je({done:Cs+1,total:w.length,startedAt:is})}finally{_s(null),je(null),Tt(),s?.()}},Se=ee.find(w=>w.id===a)??null,_e=ds.find(w=>w.id===N)??null,ps=cr(_e),Jn=ds.map(w=>({value:w.id,label:w.id==="remote"?t("Remote (API model)"):w.label})),Xn=[...ee.map(w=>({value:w.id,label:rr(w)})),{value:qs,label:t("Remote (OpenAI-compatible)")}],Qn=Tc.map(w=>({value:String(w),label:w===0?t("Never"):t("{{count}} min",{count:w})})),Zn=[{value:"en",label:t("English")},{value:"zh",label:t("Simplified Chinese")},{value:"auto",label:t("Follow conversation")}],at=At(a)||Se?.runtime==="openai-compatible",ks=l.useMemo(()=>Qh(D),[D]);return e.jsxs("div",{className:"space-y-6","data-settings-row":"memory.root",children:[e.jsxs("section",{className:"space-y-2",children:[e.jsx("h2",{className:"text-base font-medium",children:t("Memory")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("Durable knowledge the agent can search and write across sessions. Stored locally in a SQLite database.")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Turn memory off in Built-in tools.")})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5","data-settings-row":"memory.modelIdleMinutes",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Unload automatically when idle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Release local model memory after this idle period. Models load automatically the next time they are needed.")})]}),e.jsxs(ne,{value:String(m),items:Qn,onValueChange:w=>{w!==null&&u(Number(w))},disabled:!te,children:[e.jsx(ae,{className:"w-56 shrink-0","aria-label":t("Unload automatically when idle"),children:e.jsx(re,{})}),e.jsx(oe,{children:Qn.map(w=>e.jsx(Z,{value:w.value,children:w.label},w.value))})]})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium",children:t("Embedding model")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Used for semantic search and near-duplicate detection. Without it search still works using full-text only.")}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5","data-settings-row":"memory.embeddingModel",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:Se?rr(Se):X??(at?t("Remote (OpenAI-compatible)"):a)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:Se?[Se.dim?`${Se.dim}d`:null,Se.downloadable?me(Se.approxBytes):null,Se.runtime].filter(Boolean).join(" · "):at?"openai-compatible":t("Unknown model; the default is used instead.")})]}),e.jsxs(ne,{value:Zh(a),items:Xn,onValueChange:w=>{w!==null&&r(tp(a,String(w)))},disabled:!te,children:[e.jsx(ae,{className:"w-56",children:e.jsx(re,{})}),e.jsx(oe,{children:Xn.map(w=>e.jsx(Z,{value:w.value,children:w.label},w.value))})]})]}),Se?.downloadable&&e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5","data-settings-row":"memory.download",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:Se.state==="ready"?t("Model downloaded"):Se.state==="downloading"?t("Downloading…"):t("Model not downloaded")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:xe&&xe.modelId===Se.id?`${xe.file} · ${me(xe.received)}${xe.total?` / ${me(xe.total)}`:""} (${xe.fileIndex+1}/${xe.fileCount})`:Se.state==="ready"?me(Se.downloadedBytes):t("Semantic search stays off until the model is on disk.")})]}),e.jsx("div",{className:"flex shrink-0 gap-2",children:Se.state==="downloading"?e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.memory.cancelModelDownload(Se.id).then(ws)},children:t("Cancel")}):Se.state==="ready"?e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.memory.deleteModel(Se.id).then(ws)},children:t("Remove")}):e.jsx(y,{size:"sm",disabled:!te,onClick:()=>{window.electronAPI.memory.downloadModel(Se.id).then(ws)},children:t("Download")})})]}),at&&e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5","data-settings-row":"memory.remoteModel",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Remote model")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Credentials stay in the main process and are never sent to the renderer.")})]}),V.length>0?e.jsx("div",{className:"w-56 shrink-0",children:e.jsx(ze,{providers:V,providerId:_?.id??x??"",modelId:de?.id??X??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:t("Select model"),side:"bottom",triggerClassName:Qe,onSelect:(w,ve)=>{h(w),r(sp(ve))},onReasoningChange:()=>{},onThinkingChange:()=>{}})}):e.jsxs("div",{className:"w-56 shrink-0 space-y-1",children:[e.jsx("p",{className:"text-xs text-destructive",children:t(Yh)}),le.map(w=>e.jsx("p",{className:"text-xs text-muted-foreground",children:Wh(w.reason,w.name,t)},w.providerId))]})]}),at&&De&&e.jsx("p",{className:"text-xs text-destructive","data-settings-row":"memory.remoteModelIssue",children:De}),e.jsx(Is,{rowId:"memory.autoDownload",title:t("Download models automatically"),description:t("Off by default, so a model is only fetched when you press Download. While a model is missing, search degrades to full-text; existing memories are re-embedded once it arrives."),checked:o,onChange:i,disabled:!te})]}),e.jsxs("section",{className:"space-y-2","data-settings-row":"memory.distillModel",children:[e.jsx("h3",{className:"text-sm font-medium",children:t("Distillation")}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Completion backend")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Local GGUF runs on this machine. Remote uses the model below.")})]}),e.jsxs(ne,{value:N,items:Jn,onValueChange:w=>z(String(w)),disabled:!te,children:[e.jsx(ae,{className:"w-56",children:e.jsx(re,{})}),e.jsx(oe,{children:Jn.map(w=>e.jsx(Z,{value:w.value,children:w.label},w.value))})]})]}),_e?.downloadable&&e.jsxs("div",{className:K("flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5",ps==="missing"&&"border-destructive/50"),children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:_e.state==="ready"?t("Model downloaded"):_e.state==="downloading"?t("Downloading…"):t("Model not downloaded")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:He&&He.modelId===_e.id?`${He.file} · ${me(He.received)}${He.total?` / ${me(He.total)}`:""}`:_e.state==="ready"?me(_e.downloadedBytes):me(_e.approxBytes)})]}),e.jsx("div",{className:"flex shrink-0 gap-2",children:_e.state==="downloading"?e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.memory.cancelChatModelDownload(_e.id).then(Ns)},children:t("Cancel")}):_e.state==="ready"?e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.memory.deleteChatModel(_e.id).then(Ns)},children:t("Remove")}):e.jsx(y,{size:"sm",disabled:!te,onClick:()=>{window.electronAPI.memory.downloadChatModel(_e.id).then(Ns)},children:t("Download")})})]}),ps==="missing"&&e.jsx("p",{className:"text-xs text-destructive",children:t("Local model selected but the weights are not on disk. Distillation and interpretation will wait until you click Download.")}),ps==="downloading"&&e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Download in progress. Distillation waits until the model is ready.")}),N==="remote"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Distillation model")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Reads finished sessions and writes the memories.")})]}),B.length>0&&e.jsx("div",{className:"w-56 shrink-0",children:e.jsx(ze,{providers:B,providerId:ie?.id??"",modelId:F?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:t("Follows the title-summary model"),side:"bottom",triggerClassName:Qe,onSelect:(w,ve)=>q({providerId:w,modelId:ve}),onReasoningChange:()=>{},onThinkingChange:()=>{}})})]}),W&&e.jsx(y,{variant:"ghost",size:"sm",onClick:()=>q(null),children:t("Follows the title-summary model")})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5","data-settings-row":"memory.language",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Memory language")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("English keeps retrieval and near-duplicate detection stable across languages. Choose Follow conversation if your team only works in one language.")})]}),e.jsxs(ne,{value:H,items:Zn,onValueChange:w=>U(String(w)),disabled:!te,children:[e.jsx(ae,{className:"w-56",children:e.jsx(re,{})}),e.jsx(oe,{children:Zn.map(w=>e.jsx(Z,{value:w.value,children:w.label},w.value))})]})]})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium",children:t("Background processing")}),e.jsx(Is,{rowId:"memory.distill",title:t("Distill sessions automatically"),description:t("When a session ends, or goes idle for 30 minutes and is reclaimed, extract 1-3 durable memories from it in the background."),checked:f,onChange:d,disabled:!te}),f&&ps&&e.jsx("p",{className:"text-xs text-destructive",children:t("Automatic distillation is on, but the local model is not ready. Sessions will queue until you download it.")}),e.jsx(Is,{rowId:"memory.kg",title:t("Extract entities"),description:t("Build an entity graph so a memory can be recalled by a name it does not literally contain."),checked:p,onChange:j,disabled:!te})]}),e.jsxs("section",{className:"space-y-2","data-settings-row":"memory.forgetting",children:[e.jsx("h3",{className:"text-sm font-medium",children:t("Forgetting")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Decay only changes how search ranks a memory. Archiving keeps it and can be undone; nothing on this page ever deletes a memory.")}),e.jsx(Is,{rowId:"memory.decay",title:t("Rank lower when never retrieved"),description:t("Memories that have not been retrieved for a long time rank lower. This changes ranking only — nothing is archived or deleted."),checked:b,onChange:A,disabled:!te}),e.jsx(Is,{rowId:"memory.decayCandidates",title:t("Mark archive candidates"),description:t("Mark cold, low-importance memories as candidates and show them in the library. Marking alone changes nothing."),checked:v,onChange:k,disabled:!te||!b}),e.jsx(Is,{rowId:"memory.decayAutoArchive",title:t("Archive candidates automatically"),description:t("Archive candidates at the end of each run. Archived memories are hidden from search but kept and can be restored."),checked:I,onChange:M,disabled:!te||!b||!v}),b&&e.jsxs(e.Fragment,{children:[e.jsx(Kt,{rowId:"memory.decayStaleDays",title:t("Not retrieved for"),description:t("Counted from the last retrieval; a memory that was never retrieved counts from creation."),value:String($),items:Gt(Rc,$,w=>t("{{count}} days",{count:String(w)})),onChange:w=>E(Number(w)),disabled:!te}),e.jsx(Kt,{rowId:"memory.decayMaxImportance",title:t("Importance at most"),description:t("Only memories at or below this importance can become candidates. 0.5 is the lowest tier distillation writes."),value:String(L),items:Gt(Oc,L,w=>w.toFixed(2)),onChange:w=>T(Number(w)),disabled:!te}),e.jsx(Kt,{rowId:"memory.decayInterval",title:t("Run every"),description:t("Checked when the library opens; there is no separate background timer."),value:String(C),items:Gt(Dc,C,w=>t("{{count}} days",{count:String(w)})),onChange:w=>S(Number(w)),disabled:!te})]}),b&&e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 rounded-lg border px-3 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:v||I?t("Archive candidates: {{count}}",{count:String(Pt?.candidates??0)}):t("Archive candidates: marking is off")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:fi})]}),e.jsxs("div",{className:"flex shrink-0 gap-2",children:[e.jsx(y,{size:"sm",variant:"outline",disabled:st!==null||!te,onClick:gi,children:t(st==="run"?"Running…":"Run now")}),e.jsx(y,{size:"sm",variant:"outline",disabled:!v||(Pt?.candidates??0)===0,onClick:qn,children:t("Review candidates")})]})]})]}),e.jsxs("section",{className:"space-y-2","data-settings-row":"memory.stats",children:[e.jsx("h3",{className:"text-sm font-medium",children:t("Library")}),P===null||P.total===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:t("No memories stored yet.")}):e.jsxs(e.Fragment,{children:[lr(P)&&e.jsx("p",{className:"text-xs text-destructive",children:t("Vectors unavailable: {{reason}}",{reason:lr(P)??""})}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-3",children:[e.jsx(ms,{label:t("Memories"),value:String(P.total)}),e.jsx(ms,{label:t("Crystals"),value:String(P.crystals)}),e.jsx(ms,{label:t("Entities"),value:String(P.entities)}),e.jsx(ms,{label:t("With vectors"),value:`${P.embedded}/${P.total}`,action:P.embedded<P.total?e.jsx("button",{type:"button",disabled:qe,className:"text-xs text-muted-foreground underline-offset-2 hover:underline disabled:opacity-60",onClick:()=>{Vn(!0),window.electronAPI.memory.reembed().then(()=>ys.current?.())},children:t(qe?"Backfilling…":"Backfill")}):null}),e.jsx(ms,{label:t("Database size"),value:me(P.databaseBytes)}),e.jsx(ms,{label:t("Spaces"),value:String(Object.keys(P.bySpace).length)}),e.jsx(ms,{label:t("Never retrieved"),value:`${P.neverHit}/${P.total}`,action:e.jsx("span",{className:"text-muted-foreground text-xs",children:t("{{percent}}% of library",{percent:String(P.total>0?Math.round(P.neverHit/P.total*100):0)})})}),e.jsx(ms,{label:t("Added in 7 days"),value:String(P.addedLast7Days)})]})]})]}),e.jsxs("section",{className:"space-y-2","data-settings-row":"memory.distillSessions",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("h3",{className:"text-sm font-medium",children:t("Distill past sessions")}),Hn.length>0&&e.jsx(y,{size:"sm",variant:"outline",disabled:!te||rs!==null||ps!==null,onClick:()=>Yn(ge,"all",t("All sessions")),children:rs==="all"?t("Distilling…"):t("Distill all ({{count}})",{count:String(Hn.length)})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("The automatic switch only covers sessions that end from now on. Distill earlier sessions here to fill the library.")}),G&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:[t("{{done}}/{{total}} done",{done:String(G.done),total:String(G.total)}),(()=>{const w=ip(G,Date.now());return w===null?"":` · ${t("about {{time}} left",{time:lp(w)})}`})()]}),Wn.length===0?e.jsx("p",{className:"text-muted-foreground text-sm",children:t("No recorded sessions found.")}):e.jsx("ul",{className:"divide-y rounded-lg border",children:Wn.map(w=>{const ve=w.sessions.filter(Ue=>!Ue.distilled);return e.jsxs("li",{className:"flex items-center justify-between gap-3 px-3 py-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-sm",children:w.name}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("{{total}} sessions · {{pending}} not distilled",{total:String(w.sessions.length),pending:String(ve.length)})})]}),e.jsxs("div",{className:"flex shrink-0 gap-2",children:[e.jsx(y,{size:"sm",variant:"ghost",onClick:()=>Fs(w),children:t("View sessions")}),e.jsx(y,{size:"sm",variant:"outline",disabled:!te||rs!==null||w.sessions.length===0||ps!==null,onClick:()=>Yn(w.sessions,w.key,w.name),children:rs===w.key?t("Distilling…"):t("Distill project")})]})]},w.key)})})]}),e.jsx(ye,{open:os!==null,onOpenChange:w=>!w&&Fs(null),children:e.jsx(we,{children:os&&e.jsxs(e.Fragment,{children:[e.jsxs(Ne,{children:[e.jsx(ke,{children:os.name}),e.jsx(Ye,{children:t("{{total}} sessions · {{pending}} not distilled",{total:String(os.sessions.length),pending:String(os.sessions.filter(w=>!w.distilled).length)})})]}),e.jsx(Ce,{children:e.jsx("ul",{className:"divide-y rounded-lg border",children:os.sessions.map(w=>e.jsxs("li",{className:"flex items-center justify-between gap-3 px-3 py-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-sm",children:w.title}),e.jsxs("p",{className:"text-muted-foreground text-xs",children:[w.updatedAt?w.updatedAt.slice(0,10):"",w.distilled?` · ${t("Already distilled")}`:""]})]}),e.jsx(y,{size:"sm",variant:"ghost",className:"shrink-0",disabled:!te||rs!==null||ps!==null,onClick:()=>{nt([w],w.sessionId,w.distilled)},children:rs===w.sessionId?t("Distilling…"):w.distilled?t("Distill again"):t("Distill")})]},w.sessionId))})}),e.jsx(Ee,{children:e.jsx(Hs,{render:e.jsx(y,{variant:"outline",size:"sm"}),children:t("Close")})})]})})}),e.jsx(ye,{open:be!==null,onOpenChange:w=>!w&&Ae(null),children:e.jsx(we,{children:be&&e.jsxs(e.Fragment,{children:[e.jsxs(Ne,{children:[e.jsx(ke,{children:t("Some sessions were already distilled")}),e.jsx(Ye,{children:t("{{label}}: {{total}} sessions, {{done}} already distilled. Re-distilling runs the model again and may add new memories alongside the existing ones.",{label:be.label,total:String(be.scope.length),done:String(be.scope.length-be.pending.length)})})]}),e.jsxs(Ee,{children:[e.jsx(Hs,{render:e.jsx(y,{variant:"ghost",size:"sm"}),children:t("Cancel")}),e.jsx(y,{variant:be.pending.length>0?"default":"outline",size:"sm",disabled:be.pending.length===0,onClick:()=>{const w=be;Ae(null),nt(w.pending,w.token)},children:t("Only the {{count}} remaining",{count:String(be.pending.length)})}),e.jsx(y,{variant:be.pending.length>0?"outline":"default",size:"sm",onClick:()=>{const w=be;Ae(null),nt(w.scope,w.token,!0)},children:t("Re-distill all {{count}}",{count:String(be.scope.length)})})]})]})})}),e.jsxs("section",{className:"space-y-2","data-settings-row":"memory.jobs",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("h3",{className:"font-medium text-sm",children:t("Background tasks")}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[D.kgFailed>0&&e.jsx(y,{size:"sm",variant:"ghost",onClick:()=>{window.electronAPI.memory.retryFailedKgJobs().then(()=>ys.current?.())},children:t("Retry failed extractions ({{count}})",{count:String(D.kgFailed)})}),ks.some(w=>w.state!=="running")&&e.jsx(y,{size:"sm",variant:"ghost",title:t("Removes completed and cancelled jobs. Running tasks are kept. Sessions will show as not distilled again, since that flag is derived from job history — re-distilling is deduplicated, so it will not create duplicate memories."),onClick:()=>{window.electronAPI.memory.clearJobs()},children:t("Clear finished tasks")}),ks.length>or&&e.jsx(y,{size:"sm",variant:"ghost",onClick:()=>pi(!Et),children:Et?t("Show less"):t("Show all {{count}}",{count:String(ks.length)})})]})]}),ks.length===0?e.jsx("p",{className:"text-muted-foreground text-sm",children:t("Nothing running.")}):e.jsx("ul",{className:"divide-y rounded-lg border",children:(Et?ks:ks.slice(0,or)).map(w=>e.jsxs("li",{className:"space-y-1 px-3 py-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(se,{variant:w.state==="failed"?"destructive":"secondary",children:t(rp[w.kind])}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-sm",children:w.target}),e.jsx("span",{className:K("shrink-0 text-xs",w.state==="failed"?"text-destructive":"text-muted-foreground"),children:w.state==="running"?`⋯ ${w.detail}`:w.detail})]}),w.notes.map(ve=>e.jsxs("p",{className:"pl-1 text-muted-foreground text-xs",children:["· ",ve]},ve))]},w.key))})]}),e.jsx(ye,{open:Be!==null,onOpenChange:w=>!w&&Gn(null),children:e.jsxs(we,{children:[e.jsxs(Ne,{children:[e.jsx(ke,{children:t("Archive candidates")}),e.jsx(Ye,{children:t("Cold and low-importance memories. Archiving keeps them, hides them from search, and can be undone from the library.")})]}),e.jsx(Ce,{children:Be&&Be.items.length>0?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:t("{{selected}} of {{total}} selected",{selected:String(bs.size),total:String(Be.items.length)})}),e.jsx(y,{size:"sm",variant:"ghost",onClick:()=>Mt(bs.size===Be.items.length?new Set:new Set(Be.items.map(w=>w.id))),children:bs.size===Be.items.length?t("Clear selection"):t("Select all")})]}),e.jsx("ul",{className:"divide-y rounded-lg border",children:Be.items.map(w=>e.jsxs("li",{className:"flex items-start gap-2 px-3 py-2",children:[e.jsx(Le,{checked:bs.has(w.id),onCheckedChange:()=>Mt(ve=>{const Ue=new Set(ve);return Ue.has(w.id)?Ue.delete(w.id):Ue.add(w.id),Ue}),"aria-label":t("Select memory")}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-sm",children:w.title}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[w.spaceLabel," ·"," ",t("Importance {{value}}",{value:w.importance.toFixed(2)})," ·"," ",w.lastHitAt?t("Last retrieved {{date}}",{date:Os(w.lastHitAt)}):t("Never retrieved")]})]})]},w.id))}),Be.total>Be.items.length&&e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Showing the first {{shown}} of {{total}}.",{shown:String(Be.items.length),total:String(Be.total)})})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:t("No archive candidates right now.")})}),e.jsxs(Ee,{children:[e.jsx(Hs,{render:e.jsx(y,{variant:"outline",size:"sm"}),children:t("Close")}),e.jsx(y,{size:"sm",disabled:bs.size===0||st!==null,onClick:ji,children:t(st==="archive"?"Archiving…":"Archive selected")})]})]})})]})}function ms({label:s,value:t,action:n}){return e.jsxs("div",{className:"rounded-lg border px-3 py-2",children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:s}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-sm",children:t}),n]})]})}function up(s,t){if(t===null)return{ok:!0,value:null};if(s.type==="boolean")return typeof t=="boolean"?{ok:!0,value:t}:t==="true"||t==="false"?{ok:!0,value:t==="true"}:{ok:!1,error:"需要打开或关闭"};if(typeof t!="string")return{ok:!1,error:"值不合法"};if(s.type==="number"){const n=t.trim();if(!/^-?\d+(\.\d+)?$/.test(n))return{ok:!1,error:"需要数字"};const a=Number(n);return Number.isFinite(a)?s.min!==void 0&&a<s.min?{ok:!1,error:"小于最小值"}:s.max!==void 0&&a>s.max?{ok:!1,error:"大于最大值"}:{ok:!0,value:a}:{ok:!1,error:"需要数字"}}return s.type==="enum"?s.options?.includes(t)?{ok:!0,value:t}:{ok:!1,error:"不在可选项里"}:s.type==="model"?go(t)?{ok:!0,value:t}:{ok:!1,error:"不是合法的模型选择"}:t.length>4096||t.includes("\0")?{ok:!1,error:"值不合法"}:{ok:!0,value:t}}const mp={"agent.tool":"运行 Agent 工具","ui.slot":"在界面挂载组件","ui.view":"打开侧栏页面","ui.notify":"发送系统通知","composer.draft":"读写输入框草稿","fs.read":"读取声明的文件","fs.write":"写入声明的文件","net.fetch":"访问声明的域名","mcp.server":"启动声明的 MCP 服务","mcp.call":"调用宿主 MCP 工具","agent.observe":"观察会话事件","agent.intercept":"拦截并改写会话事件","agent.inject":"向会话发送消息,并可触发该会话继续执行;默认只发到发起调用的会话,允许后可发到任意运行中的会话","process.background":"常驻后台并拉起子进程","plugin.call":"调用其他插件","ui.clipboard":"写入剪贴板","ui.openExternal":"用浏览器打开链接","session.read":"查看本项目的会话列表与运行状态(标题、活动时间、是否在等你)","session.readAll":"查看所有项目的会话列表与运行状态","session.focus":"在你点击时切换到本项目的会话","session.create":"在你点击时于本项目新建会话","agent.run":"用当前会话的模型运行只读代理(可读项目文件与对话内容,不能修改)","secretary.contact":"作为秘书的联系方式:收发你与秘书之间的消息(里程碑、提问、确认卡提示)"};function Zo(s){return mp[s]??s}const xp=["themes","agent","productivity","integrations","insights","writing","fun"],$n={themes:"主题外观",agent:"Agent 能力",productivity:"效率工作流",integrations:"外部集成",insights:"观测统计",writing:"写作翻译",fun:"休闲娱乐"};function hp(s){return{installedKey:s,refresh:!0}}function pp(s,t){return s.installedKey===t?s:{installedKey:t,refresh:!1}}function Gs(s){if(!s)return null;try{const t=new URL(s);return t.protocol==="https:"||t.protocol==="http:"?t.href:null}catch{return null}}function fp({pluginId:s,name:t,from:n,homepage:a,onClose:r}){const{t:o}=R();return e.jsx(ye,{open:s!==null,onOpenChange:i=>!i&&r(),children:e.jsxs(we,{children:[e.jsx(Ne,{children:e.jsxs(ke,{children:[o("Usage guide"),t?` · ${t}`:""]})}),e.jsx(Ce,{className:"max-h-[60vh] space-y-3 overflow-y-auto",children:s&&e.jsx(ei,{pluginId:s,from:n,homepage:a})})]})})}function ei({pluginId:s,from:t,homepage:n,showLink:a=!0}){const{t:r}=R(),[o,i]=l.useState(null),[m,u]=l.useState(null),[x,h]=l.useState(Gs(n)),[c,f]=l.useState(null);return l.useEffect(()=>{let d=!0;return xt(()=>import("./globals-kfeSrZZh.js").then(p=>p.oj),__vite__mapDeps([0,1]),import.meta.url).then(p=>{d&&f(()=>p.Markdown)}),()=>{d=!1}},[]),l.useEffect(()=>{let d=!1;return i(null),u(null),h(Gs(n)),(async()=>{const p=window.electronAPI.extensionPlugins,j=await p.readme({id:s,from:t});let b=j.ok?j.markdown:null,A=j.ok?null:j.error;if(!j.ok&&t==="installed"){const v=await p.readme({id:s,from:"market"});v.ok&&(b=v.markdown,A=null)}if(!Gs(n)){const v=await p.marketList(!1),k=v.ok?v.plugins.find(I=>I.id===s):void 0;d||h(Gs(k?.homepage))}d||(i(b),u(b?null:A))})(),()=>{d=!0}},[s,t,n]),e.jsxs("div",{className:"space-y-3",children:[a&&x&&e.jsx("a",{href:x,target:"_blank",rel:"noreferrer",className:"text-sm underline",children:r("Homepage")}),m&&e.jsx("p",{className:"text-muted-foreground text-sm",children:m}),o===null&&!m&&e.jsx("p",{className:"text-muted-foreground text-sm",children:"…"}),o!==null&&c&&e.jsx(c,{text:o})]})}function si(s,t){return t==="all"?!0:t==="installed"?s.installedVersion!==void 0:t==="updates"?s.updateAvailable:t==="other"?s.category===void 0:s.category===t}function gp(s){const t=r=>s.filter(o=>si(o,r)).length,n=["all","installed","updates"],a=[...xp,"other"];return[...n.map(r=>({id:r,count:t(r)})),...a.map(r=>({id:r,count:t(r)})).filter(r=>r.count>0)]}function jp(s,t){const n=t.query.trim().toLowerCase();return s.filter(a=>si(a,t.section)?n?[a.id,a.name,a.description,...a.tags].some(r=>r.toLowerCase().includes(n)):!0:!1).sort((a,r)=>a.tier!==r.tier?a.tier==="official"?-1:1:a.name.localeCompare(r.name))}const dr={all:"全部",installed:"已安装",updates:"可更新",other:"其他"},vp=s=>s in dr?dr[s]:$n[s];function bp({disabled:s,installedKey:t,onInstall:n,initialQuery:a=""}){const{t:r}=R(),o=window.electronAPI.extensionPlugins,[i,m]=l.useState(null),[u,x]=l.useState(!1),[h,c]=l.useState(a),[f,d]=l.useState("all"),[p,j]=l.useState(null),[b,A]=l.useState(()=>hp(t)),v=pp(b,t);v!==b&&A(v);const k=l.useCallback(async C=>{x(!0);try{m(await o.marketList(C))}catch(S){m({ok:!1,error:S instanceof Error?S.message:String(S),chinaMirror:!1})}finally{x(!1)}},[o]);l.useEffect(()=>{k(b.refresh)},[k,b]);const I=async C=>{await o.setMarketChinaMirror(C),await k(!0)},M=i?.ok===!0?i.plugins:[],$=gp(M),E=$.some(C=>C.id===f)?f:"all",L=jp(M,{query:h,section:E}),T=p?M.find(C=>C.id===p):void 0;return e.jsxs("div",{className:"flex h-[min(72vh,720px)] min-h-0 flex-col gap-3 sm:flex-row sm:gap-4",children:[e.jsx("nav",{"aria-label":"插件分类",className:"flex shrink-0 gap-1 overflow-x-auto pb-1 sm:block sm:w-36 sm:space-y-0.5 sm:overflow-y-auto sm:pb-0",children:$.map(C=>e.jsxs("button",{type:"button","aria-pressed":E===C.id,onClick:()=>{d(C.id),j(null)},className:K("flex shrink-0 items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left text-sm hover:bg-accent sm:w-full",E===C.id&&"bg-accent font-medium"),children:[e.jsx("span",{className:"truncate whitespace-nowrap",children:vp(C.id)}),e.jsx("span",{className:"text-muted-foreground text-xs tabular-nums",children:C.count})]},C.id))}),e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(J,{className:"min-w-40 flex-1",value:h,placeholder:r("Search plugins"),onChange:C=>{c(C.target.value),j(null)}}),e.jsxs("label",{className:"flex shrink-0 items-center gap-1.5 text-muted-foreground text-xs",children:[e.jsx(ce,{checked:i?.chinaMirror??!1,disabled:u,onCheckedChange:C=>{I(C)}}),r("China mirror")]}),e.jsx(y,{size:"sm",variant:"ghost",disabled:u,onClick:()=>{k(!0)},children:u?e.jsx(Ps,{}):r("Refresh")})]}),i?.ok===!1&&e.jsx("p",{className:"text-destructive text-sm",children:i.error}),i?.ok===!0&&i.stale&&e.jsx("p",{className:"text-muted-foreground text-xs",children:r("Could not reach the marketplace; showing the last saved list.")}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto pr-1",children:T?e.jsx(wp,{plugin:T,disabled:s,onBack:()=>j(null),onInstall:n}):i?.ok===!0&&L.length===0?e.jsx("p",{className:"text-muted-foreground text-sm",children:r("No matching plugins")}):e.jsx("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2",children:L.map(C=>e.jsx(yp,{plugin:C,disabled:s,onOpen:()=>j(C.id),onInstall:n},C.id))})})]})]})}function ti({plugin:s,disabled:t,onInstall:n}){const{t:a}=R();return s.installedVersion&&!s.updateAvailable?e.jsx("span",{className:"shrink-0 text-muted-foreground text-xs",children:a("Installed")}):e.jsx(y,{size:"xs",variant:s.updateAvailable?"default":"outline",disabled:t,onClick:r=>{r.stopPropagation(),n(s.id)},children:s.updateAvailable?a("Update"):a("Install")})}function ni({tier:s}){const{t}=R();return e.jsx(se,{variant:s==="official"?"secondary":"outline",className:"text-[11px]",children:t(s==="official"?"Official":"Community")})}function yp({plugin:s,disabled:t,onOpen:n,onInstall:a}){return e.jsxs("div",{role:"button",tabIndex:0,"aria-label":s.name,onClick:n,onKeyDown:r=>{r.target===r.currentTarget&&(r.key==="Enter"||r.key===" ")&&(r.preventDefault(),n())},className:"flex cursor-pointer flex-col gap-2 rounded-lg border p-3 text-left transition-colors hover:bg-accent/50",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(ai,{src:s.icon}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("p",{className:"flex items-center gap-1.5 text-sm",children:[e.jsx("span",{className:"truncate font-medium",children:s.name}),e.jsx(ni,{tier:s.tier})]}),e.jsxs("p",{className:"text-muted-foreground text-xs",children:[s.latest,s.category?` · ${$n[s.category]}`:""]})]}),e.jsx(ti,{plugin:s,disabled:t,onInstall:a})]}),s.description&&e.jsx("p",{className:"line-clamp-2 text-muted-foreground text-xs",children:s.description})]})}function wp({plugin:s,disabled:t,onBack:n,onInstall:a}){const{t:r}=R(),o=Gs(s.homepage);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs(y,{size:"xs",variant:"ghost",onClick:n,children:[e.jsx(jo,{className:"size-3.5"}),"返回"]}),e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(ai,{src:s.icon,large:!0}),e.jsxs("div",{className:"min-w-0 flex-1 space-y-1",children:[e.jsxs("p",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("span",{className:"font-medium text-base",children:s.name}),e.jsx(ni,{tier:s.tier}),s.category&&e.jsx(se,{variant:"outline",className:"text-[11px]",children:$n[s.category]})]}),e.jsxs("p",{className:"font-mono text-muted-foreground text-xs",children:[s.id," · ",s.latest,s.installedVersion?` · 已装 ${s.installedVersion}`:""]}),s.description&&e.jsx("p",{className:"text-sm",children:s.description}),o&&e.jsxs("a",{href:o,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-primary text-xs hover:underline",children:[e.jsx(Lc,{className:"size-3"}),r("Homepage")]})]}),e.jsx(ti,{plugin:s,disabled:t,onInstall:a})]}),s.screenshots&&s.screenshots.length>0&&e.jsx("div",{className:"flex gap-2 overflow-x-auto pb-1",children:s.screenshots.map(i=>e.jsx("img",{src:i.url,alt:i.alt,title:i.alt,loading:"lazy",className:"h-44 shrink-0 rounded-md border object-cover"},i.url))}),e.jsxs("section",{className:"space-y-1",children:[e.jsx("h3",{className:"font-medium text-sm",children:"权限"}),s.permissions.length===0?e.jsx("p",{className:"text-muted-foreground text-xs",children:"无特殊权限"}):e.jsx("ul",{className:"space-y-0.5",children:s.permissions.map(i=>e.jsxs("li",{className:"text-xs",children:[e.jsx("span",{className:"font-mono text-muted-foreground",children:i}),e.jsx("span",{className:"ml-2",children:Zo(i)})]},i))})]}),e.jsxs("section",{className:"space-y-1",children:[e.jsx("h3",{className:"font-medium text-sm",children:r("Usage guide")}),e.jsx(ei,{pluginId:s.id,from:"market",homepage:s.homepage,showLink:!1})]})]})}function ai({src:s,large:t}){const[n,a]=l.useState(!1);return e.jsx("div",{className:K("flex shrink-0 items-center justify-center rounded-md bg-muted",t?"size-12":"size-9"),children:s&&!n?e.jsx("img",{src:s,alt:"",className:t?"size-7 object-contain":"size-5 object-contain",onError:()=>a(!0)}):e.jsx(Xs,{className:"size-4 text-muted-foreground"})})}const ur={session:"跟随当前会话",title:"跟随标题模型",fixed:"指定模型"};function Np({value:s,onChange:t}){const n=es(),a=go(s)??"session",r=typeof a=="string"?a:"fixed",o=typeof a=="string"?null:a,i=o?n.find(u=>u.id===o.providerId):void 0,m=i?.models.find(u=>u.id===o?.modelId);return e.jsxs("div",{className:"space-y-2",children:[e.jsxs(ne,{items:ur,value:r,onValueChange:u=>{if(u==="session"||u==="title")t(u);else if(u==="fixed"&&!o){const x=n[0],h=x?.models[0];x&&h&&t(ba({providerId:x.id,modelId:h.id}))}},children:[e.jsx(ae,{children:e.jsx(re,{})}),e.jsx(oe,{children:Object.entries(ur).map(([u,x])=>e.jsx(Z,{value:u,disabled:u==="fixed"&&n.length===0,children:x},u))})]}),o&&e.jsx(ze,{providers:n,providerId:i?.id??"",modelId:m?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:"选择模型",side:"bottom",triggerClassName:Qe,onSelect:(u,x)=>t(ba({providerId:u,modelId:x})),onReasoningChange:()=>{},onThinkingChange:()=>{}}),o&&!m&&e.jsx("p",{className:"text-destructive text-xs",children:"选中的模型已不可用,运行时会失败,请重新选择。"})]})}function kp(s){const{notice:t,remote:n,onDismiss:a}=s;return e.jsxs("div",{className:"space-y-1 rounded-md border border-amber-500/30 bg-amber-500/5 px-3 py-2 text-amber-700 text-sm dark:text-amber-400",children:[t.unreadable&&e.jsx("p",{children:"插件登记表曾读取失败,下面的列表可能不全。插件文件没有删除,原文保存在数据目录的 extension-plugins/registry.json.unreadable。"}),t.discarded.length>0&&e.jsxs("p",{children:["检测到旧格式的登记记录,已丢弃并清理,请重新安装:",e.jsx("span",{className:"font-mono",children:t.discarded.join(", ")})]}),n?e.jsx("p",{className:"text-muted-foreground",children:"请在桌面端点「知道了」,或运行 enso-server plugin notice-dismiss 清除此提示。"}):e.jsx(y,{size:"sm",variant:"outline",onClick:a,children:"知道了"})]})}function Cp({pluginId:s,plain:t}){const{t:n}=R(),[a,r]=l.useState([]),[o,i]=l.useState({}),[m,u]=l.useState(null),x=l.useCallback(async()=>{const d=await window.electronAPI.extensionPlugins.configGet(s);d.ok?r(d.fields):u({error:!0,text:d.error}),i({})},[s]);l.useEffect(()=>{x()},[x]);const h=async()=>{const d={};for(const[j,b]of Object.entries(o)){const A=a.find(k=>k.key===j);if(!A||A.secret&&b==="")continue;const v=up(A,b);if(!v.ok){u({error:!0,text:`${A.title}:${v.error}`});return}d[j]=v.value}const p=await window.electronAPI.extensionPlugins.configSet(s,d);u(p.ok?{error:!1,text:n("Saved. New calls use it right away.")}:{error:!0,text:p.error??""}),p.ok&&await x()},c=d=>{const p=o[d.key];return typeof p=="string"?p:p===null||d.secret?"":d.value??(d.default!==void 0?String(d.default):"")},f=d=>{const p=o[d.key];return typeof p=="boolean"?p:(d.value??(typeof d.default=="boolean"?String(d.default):"false"))==="true"};return e.jsxs("div",{className:K("space-y-2",t?"":"rounded-md border border-border p-3"),children:[a.map(d=>e.jsxs("div",{className:"space-y-1",children:[e.jsxs("p",{className:"text-sm",children:[d.title,e.jsx("span",{className:"ml-2 font-mono text-muted-foreground text-xs",children:d.key})]}),d.description&&e.jsx("p",{className:"text-muted-foreground text-xs",children:d.description}),d.multiline&&d.type==="string"?e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Xe,{autoComplete:"off",rows:4,value:c(d),placeholder:d.secret&&d.set?n("Set (leave blank to keep)"):n("Not set"),className:"min-w-0 flex-1",onChange:p=>i(j=>({...j,[d.key]:p.target.value}))}),d.set&&e.jsx(y,{size:"sm",variant:"ghost",onClick:()=>i(p=>({...p,[d.key]:null})),children:n("Clear value")})]}):d.secret||d.type==="string"||d.type==="number"||d.type==="path"?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(J,{type:d.secret?"password":d.type==="number"?"number":"text",autoComplete:"off",inputMode:d.type==="number"?"decimal":void 0,min:d.type==="number"?d.min:void 0,max:d.type==="number"?d.max:void 0,value:c(d),placeholder:d.secret&&d.set?n("Set (leave blank to keep)"):n("Not set"),onChange:p=>i(j=>({...j,[d.key]:p.target.value}))}),d.type==="path"&&!d.secret&&!window.electronAPI.remote&&e.jsx(y,{size:"sm",variant:"outline",onClick:()=>{window.electronAPI.extensionPlugins.pickPath(d.pathKind==="directory"?"directory":"file").then(p=>{p.ok&&"path"in p&&i(j=>({...j,[d.key]:p.path}))})},children:d.pathKind==="directory"?"选择文件夹":"选择文件"}),d.set&&e.jsx(y,{size:"sm",variant:"ghost",onClick:()=>i(p=>({...p,[d.key]:null})),children:n("Clear value")})]}):d.type==="boolean"?e.jsx(ce,{checked:f(d),onCheckedChange:p=>i(j=>({...j,[d.key]:p}))}):d.type==="model"?e.jsx(Np,{value:c(d),onChange:p=>i(j=>({...j,[d.key]:p}))}):e.jsxs(ne,{items:Object.fromEntries((d.options??[]).map(p=>[p,p])),value:c(d),onValueChange:p=>{typeof p=="string"&&i(j=>({...j,[d.key]:p}))},children:[e.jsx(ae,{children:e.jsx(re,{placeholder:"请选择"})}),e.jsx(oe,{children:(d.options??[]).map(p=>e.jsx(Z,{value:p,children:p},p))})]})]},d.key)),m&&e.jsx("p",{className:K("text-xs",m.error?"text-destructive":"text-muted-foreground"),children:m.text}),e.jsx(y,{size:"sm",disabled:Object.keys(o).length===0,onClick:()=>{h()},children:n("Save")})]})}function Sp({pluginId:s,plain:t}){const{t:n}=R(),[a,r]=l.useState(null),o=l.useCallback(async()=>{const i=await window.electronAPI.extensionPlugins.logs(s);r(i.ok?i.text:i.error)},[s]);return l.useEffect(()=>{o()},[o]),e.jsxs("div",{className:K("space-y-2",t?"":"rounded-md border border-border p-3"),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-sm",children:n("Plugin logs")}),e.jsx(y,{size:"icon",variant:"ghost","aria-label":n("Refresh"),onClick:()=>{o()},children:e.jsx(ns,{className:"size-4"})})]}),e.jsx("pre",{className:"max-h-64 overflow-auto whitespace-pre-wrap break-all font-mono text-muted-foreground text-xs",children:a===null?"":a||n("No logs yet")})]})}function mr({message:s}){const[t,n]=l.useState(!1);return e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("p",{className:K("select-text break-all font-mono text-destructive text-xs",t?"max-h-48 overflow-auto whitespace-pre-wrap":"line-clamp-2"),children:s}),s.length>120&&e.jsx("button",{type:"button",className:"text-muted-foreground text-xs hover:text-foreground",onClick:()=>n(a=>!a),children:t?"收起":"展开全部"})]})}function ri({permissions:s,styles:t=!1}){return s.length===0?t?null:e.jsx("p",{className:"text-muted-foreground text-xs",children:"无特殊权限"}):e.jsx("ul",{className:"space-y-0.5",children:s.map(n=>e.jsxs("li",{className:"text-xs",children:[e.jsx("span",{className:"font-mono text-muted-foreground",children:n}),e.jsx("span",{className:"ml-2",children:Zo(n)})]},n))})}function Ip(s){const t=s.intervalSeconds>=60&&s.intervalSeconds%60===0?`每 ${s.intervalSeconds/60} 分钟`:`每 ${s.intervalSeconds} 秒`,n=s.lastRunAt?` · 最近 ${new Date(s.lastRunAt).toLocaleString()}`:"";return`${s.id} · ${t}${n}${s.lastError?` · ${s.lastError}`:""}`}function xr(s){return[s.permissions.length>0?`${s.permissions.length} 项权限`:"",(s.events?.length??0)>0?`${s.events?.length} 个事件`:"",(s.schedules?.length??0)>0?`${s.schedules?.length} 个定时任务`:"",s.hasRenderer?"界面代码":"",s.crossSessionInject!==void 0?"跨会话投递开关":""].filter(Boolean).join(" · ")}function hr({permissions:s,env:t,interop:n,resident:a,running:r,styles:o,trustedUi:i,events:m,schedules:u}){return e.jsxs("div",{className:"space-y-1",children:[e.jsx(ri,{permissions:s,styles:o||i}),i&&e.jsx(Ap,{}),a&&e.jsxs("p",{className:"text-xs",children:["常驻进程",r===void 0?"":r?":运行中":":未运行"]}),o&&e.jsx("p",{className:"text-xs",children:"修改界面样式:主题 CSS 可以改变应用的任意界面"}),(t?.length??0)>0&&e.jsxs("p",{className:"text-xs",children:["环境变量:",e.jsx("span",{className:"font-mono",children:t?.join(", ")})]}),(n?.length??0)>0&&e.jsxs("p",{className:"text-xs",children:["可调用插件:",e.jsx("span",{className:"font-mono",children:n?.join(", ")})]}),m?.map(x=>e.jsxs("p",{className:"text-xs",children:["事件 ",x.event," · ",x.mode==="intercept"?"拦截":"观察",x.failClosed?" · 失败即拒绝":""]},`${x.event}:${x.mode}`)),u?.map(x=>e.jsxs("p",{className:"text-xs",children:["定时任务 ",Ip(x)]},x.id))]})}function Ap(){return e.jsx("p",{className:"text-amber-700 text-xs dark:text-amber-400",children:"界面代码:运行在主界面里,可读写页面内容、调用界面能力,不受上面权限清单约束;只安装信任的插件"})}function Ep({pluginId:s,plain:t}){const[n,a]=l.useState(null),[r,o]=l.useState(null),i=l.useCallback(async()=>{const m=await window.electronAPI.extensionPlugins.artifactsList(s);m.ok?(a(m.artifacts),o(null)):o(m.error)},[s]);return l.useEffect(()=>{i()},[i]),e.jsxs("div",{className:K("space-y-2",t?"":"rounded-md border border-border p-3"),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-sm",children:"产出文件"}),e.jsx(y,{size:"icon",variant:"ghost","aria-label":"刷新",onClick:()=>{i()},children:e.jsx(ns,{className:"size-4"})})]}),r&&e.jsx("p",{className:"text-destructive text-xs",children:r}),e.jsx($c,{artifacts:n??[],onDelete:m=>{window.electronAPI.extensionPlugins.artifactDelete(m).then(u=>{u.ok?i():o(u.error??"删除失败")})}})]})}const Wt=new Set;function Mp({requestedInstallUrl:s=null,onRequestedInstallUrlConsumed:t,focusPluginId:n=null,onFocusPluginConsumed:a,requestedMarketQuery:r=null,onRequestedMarketQueryConsumed:o}={}){const{t:i}=R(),m=g(P=>P.pluginAutoUpdate!==!1),u=g(P=>P.setPluginAutoUpdate),[x,h]=l.useState([]),c=En(P=>P.errors),[f,d]=l.useState(null),[p,j]=l.useState(null),[b,A]=l.useState([]),[v,k]=l.useState(!1),[I,M]=l.useState(null),[$,E]=l.useState(""),[L,T]=l.useState(!1),[C,S]=l.useState(!1),[W,q]=l.useState(null),[N,z]=l.useState(null),[H,U]=l.useState(!1),[B,ie]=l.useState("");l.useEffect(()=>{r&&(ie(r),U(!0),o?.())},[r,o]);const[F,X]=l.useState(null),V=l.useCallback(async()=>{try{h(await window.electronAPI.extensionPlugins.list())}catch{h([])}},[]);l.useEffect(()=>(V(),window.electronAPI.extensionPlugins.registryNotice().then(z).catch(()=>z(null)),window.electronAPI.extensionPlugins.onChanged(()=>{V()})),[V]),l.useEffect(()=>{if(!n||(A(Y=>Y.includes(n)?Y:[...Y,n]),!x.some(Y=>Y.id===n)))return;const P=n;window.requestAnimationFrame(()=>{document.querySelector(`[data-plugin-id="${CSS.escape(P)}"]`)?.scrollIntoView({block:"center"})}),a?.()},[n,x,a]);const le=async P=>{M(null),f&&window.electronAPI.extensionPlugins.discard(f.token),d(null);const Y=await window.electronAPI.extensionPlugins.pickAndStage(P);Y.ok?"cancelled"in Y||d(Y.preview):M(Y.error)},_=async P=>{const Y=(P??$).trim();if(!Y)return;M(null),T(!0),f&&window.electronAPI.extensionPlugins.discard(f.token),d(null);const D=await window.electronAPI.extensionPlugins.stageFromUrl(Y).finally(()=>{T(!1)});D.ok?d(D.preview):M(D.error)},de=l.useRef(_);de.current=_,l.useEffect(()=>{if(!s)return;const P=s;let Y=!1;const D=window.setTimeout(()=>{Y||Wt.has(P)||(Wt.add(P),E(P),t?.(),de.current(P).finally(()=>{Wt.delete(P)}))},0);return()=>{Y=!0,window.clearTimeout(D)}},[s,t]);const ue=async(P,Y=!1)=>{M(null),f&&window.electronAPI.extensionPlugins.discard(f.token),d(null),T(!0);const D=window.electronAPI.extensionPlugins,Q=await(Y?D.marketStage(P):D.restage(P)).finally(()=>{T(!1)});Q.ok?d(Q.preview):M(Q.error)},O=async()=>{S(!0),q(null);try{const P=await window.electronAPI.extensionPlugins.checkUpdates();q(P.checked===0?i("No plugins installed from GitHub to check"):P.available>0?i("{{count}} update(s) available",{count:P.available}):i("All plugins are up to date"))}finally{S(!1)}},De=async()=>{if(!f)return;k(!0);const P=await window.electronAPI.extensionPlugins.commit(f.token);if(k(!1),!P.ok)M(P.error??i("Install failed"));else{E("");const Y=f.existingVersion?{ok:!0}:await window.electronAPI.extensionPlugins.setEnabled(f.id,!0);Te({type:Y.ok?"success":"warning",title:i("{{name}} installed",{name:f.name}),description:Y.ok?void 0:Y.error})}d(null)},te=()=>{f&&window.electronAPI.extensionPlugins.discard(f.token),d(null)};return e.jsxs("div",{className:"space-y-5","data-settings-row":"plugins.enso",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"font-medium text-lg",children:[i("Enso plugins"),e.jsx(Ze,{})]}),e.jsx("p",{className:"mt-1 text-muted-foreground text-sm",children:i("Installing a plugin lets it run code on this machine. Review what it asks for before confirming.")})]}),e.jsxs("div",{className:"flex shrink-0 gap-2",children:[x.length>0&&e.jsxs(y,{size:"sm",variant:"outline",disabled:C,onClick:()=>{O()},children:[C?e.jsx(Ps,{}):e.jsx(ns,{className:"size-4"}),i("Check for updates")]}),e.jsxs(y,{size:"sm",onClick:()=>{ie(""),U(!0)},children:[e.jsx(Vu,{className:"size-4"}),i("Marketplace")]})]})]}),e.jsxs("label",{className:"flex items-center justify-between gap-3 text-sm",children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block",children:i("Update plugins automatically")}),e.jsx("span",{className:"block text-muted-foreground text-xs",children:i("Marketplace updates that do not ask for new permissions install on their own.")})]}),e.jsx(ce,{className:"shrink-0",checked:m,onCheckedChange:P=>u(P)})]}),e.jsxs("div",{className:"space-y-2.5 rounded-lg border bg-muted/30 p-3",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(ho,{className:"flex-1",children:[e.jsx(fo,{children:e.jsx(ao,{className:"size-4 text-muted-foreground"})}),e.jsx(po,{value:$,placeholder:i("https://github.com/owner/repo"),onChange:P=>E(P.target.value),onKeyDown:P=>{P.key==="Enter"&&_()}})]}),e.jsx(y,{size:"sm",variant:"outline",disabled:v||L||$.trim()==="",onClick:()=>{_()},children:L?e.jsx(Ps,{}):i("Install from URL")})]}),e.jsxs("div",{className:"flex items-center gap-1 text-muted-foreground text-xs",children:[e.jsx("span",{className:"mr-1",children:i("Or install from")}),e.jsxs(y,{size:"xs",variant:"ghost",disabled:v||L,onClick:()=>{le("dir")},children:[e.jsx(Tn,{className:"size-3.5"}),i("Install from folder")]}),e.jsxs(y,{size:"xs",variant:"ghost",disabled:v||L,onClick:()=>{le("zip")},children:[e.jsx(zc,{className:"size-3.5"}),i("Install from zip")]})]})]}),I&&e.jsx("p",{className:"text-destructive text-sm",children:I}),e.jsx(ye,{open:H,onOpenChange:U,children:e.jsxs(we,{className:"max-w-5xl",children:[e.jsx(Ne,{children:e.jsx(ke,{children:i("Marketplace")})}),e.jsx(Ce,{children:e.jsx(bp,{initialQuery:B,disabled:v||L,installedKey:x.map(P=>`${P.id}@${P.version}`).join(","),onInstall:P=>{U(!1),ue(P,!0)}},B)})]})}),W&&e.jsx("p",{className:"text-muted-foreground text-sm",children:W}),N&&e.jsx(kp,{notice:N,remote:!!window.electronAPI.remote,onDismiss:()=>{window.electronAPI.extensionPlugins.dismissRegistryNotice().then(()=>z(null)).catch(P=>M(P instanceof Error?P.message:String(P)))}}),e.jsx(ye,{open:f!==null,onOpenChange:P=>!P&&!v&&te(),children:e.jsx(we,{children:f&&e.jsxs(e.Fragment,{children:[e.jsx(Ne,{children:e.jsxs(ke,{children:[f.name," ",f.version,f.existingVersion&&e.jsx("span",{className:"ml-2 text-base text-muted-foreground",children:i("updating from {{version}}",{version:f.existingVersion})})]})}),e.jsxs(Ce,{className:"space-y-3",children:[e.jsx(hr,{permissions:f.permissions,env:f.env,interop:f.interop,resident:f.resident,styles:f.styles,trustedUi:f.hasRenderer,events:f.events,schedules:f.schedules}),f.mcpServers.map(P=>e.jsxs("p",{className:"font-mono text-xs",children:[P.command," ",P.args.join(" ")]},P.name)),f.mcpTools.length>0&&e.jsxs("p",{className:"text-muted-foreground text-xs",children:[i("Host MCP tools it may call"),":",e.jsx("span",{className:"font-mono",children:f.mcpTools.join(", ")})]}),f.warnings.map(P=>e.jsx("p",{className:"text-muted-foreground text-xs",children:P},P))]}),e.jsxs(Ee,{children:[e.jsx(y,{size:"sm",variant:"ghost",disabled:v,onClick:te,children:i("Cancel")}),e.jsx(y,{size:"sm",disabled:v,onClick:()=>{De()},children:v?e.jsx(Ps,{}):i("Install")})]})]})})}),x.length===0&&!f&&e.jsxs("div",{className:"rounded-lg border border-dashed px-3 py-10 text-center",children:[e.jsx(Xs,{className:"mx-auto size-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:i("No Enso plugins installed")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:i("Browse the marketplace or install from a GitHub URL, folder or zip.")})]}),e.jsx("div",{className:"space-y-2",children:x.map(P=>e.jsxs("div",{"data-plugin-id":P.id,className:K("overflow-hidden rounded-lg border bg-card transition-colors",P.state==="crashed"&&"border-destructive/50"),children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-x-3 gap-y-2 p-3",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 basis-56 items-start gap-3",children:[e.jsx("div",{className:K("flex size-9 shrink-0 items-center justify-center rounded-md bg-muted",P.state==="enabled"?"text-foreground":"text-muted-foreground"),children:e.jsx(_c,{pluginId:P.id,icon:P.icon,className:"size-4"})}),e.jsxs("div",{className:"min-w-0 flex-1 space-y-0.5",children:[e.jsxs("p",{className:"flex flex-wrap items-center gap-1.5 text-sm",children:[e.jsx("span",{className:"truncate font-medium",children:P.name}),e.jsx(se,{variant:"outline",className:"text-[11px]",children:P.version}),P.state==="crashed"&&e.jsx(se,{variant:"destructive",className:"text-[11px]",children:i("Stopped after crashes")}),P.availableVersion&&e.jsx(se,{className:"text-[11px]",children:i("Update")}),P.pendingVersion&&e.jsx(se,{variant:"warning",className:"text-[11px]",children:"待授权"}),P.hasRenderer&&e.jsx(se,{variant:"outline",className:"text-[11px]",children:"受信任界面"}),P.devWatch&&e.jsx(se,{variant:"secondary",className:"text-[11px]",children:"开发模式"}),P.resident&&e.jsx(se,{variant:P.running?"secondary":"outline",className:"text-[11px]",children:P.running?"常驻运行中":"常驻未运行"})]}),e.jsx("p",{className:"truncate font-mono text-muted-foreground text-xs",children:P.id}),P.availableVersion&&e.jsxs("p",{className:"mt-1 flex items-center gap-2 text-primary text-xs",children:[i("Version {{version}} is available",{version:P.availableVersion}),e.jsx(y,{size:"xs",disabled:v||L,onClick:()=>{ue(P.id,P.source?.kind!=="url")},children:L?e.jsx(Ps,{}):i("Update")})]}),P.updateCheckError&&e.jsx("p",{className:"text-muted-foreground text-xs",children:i("Update check failed: {{reason}}",{reason:P.updateCheckError})}),P.lastError&&e.jsx(mr,{message:P.lastError.message}),c[P.id]?.map(Y=>e.jsx(mr,{message:`主题加载失败:${Y}`},Y)),P.pendingVersion&&e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2 rounded-md border border-amber-500/50 bg-amber-500/10 px-2 py-1.5 text-amber-700 text-xs dark:text-amber-400",children:[i("{{version}} asks for more and is waiting for approval",{version:P.pendingVersion}),e.jsx(y,{size:"xs",onClick:()=>{window.electronAPI.extensionPlugins.approvePending(P.id)},children:i("Allow")}),e.jsx(y,{size:"xs",variant:"ghost",onClick:()=>{window.electronAPI.extensionPlugins.rejectPending(P.id)},children:i("Keep current")})]})]})]}),e.jsxs("div",{className:"ml-auto flex shrink-0 items-center gap-0.5",children:[P.source&&e.jsx(y,{size:"icon",variant:"ghost",disabled:v||L,"aria-label":i("Reinstall from source"),title:P.source.kind==="url"?`${i("Reinstall from source")}: ${P.source.url}`:i("Reinstall from source"),onClick:()=>{ue(P.id)},children:e.jsx(Fc,{className:"size-4"})}),e.jsx(y,{size:"icon",variant:"ghost","aria-label":"产出文件",title:"产出文件",onClick:()=>j({kind:"artifacts",pluginId:P.id,pluginName:P.name}),children:e.jsx(Bc,{className:"size-4"})}),e.jsx(y,{size:"icon",variant:"ghost","aria-label":i("Usage guide"),title:i("Usage guide"),onClick:()=>X({id:P.id,name:P.name,from:"installed"}),children:e.jsx(yu,{className:"size-4"})}),e.jsx(y,{size:"icon",variant:"ghost","aria-label":i("Plugin logs"),title:i("Plugin logs"),onClick:()=>j({kind:"logs",pluginId:P.id,pluginName:P.name}),children:e.jsx(Ln,{className:"size-4"})}),P.configurable&&e.jsx(y,{size:"icon",variant:"ghost","aria-label":i("Configure"),title:i("Configure"),onClick:()=>j({kind:"config",pluginId:P.id,pluginName:P.name}),children:e.jsx(Uc,{className:"size-4"})}),e.jsx(y,{size:"icon",variant:"ghost","aria-label":i("Uninstall"),title:i("Uninstall"),className:"text-muted-foreground hover:text-destructive",onClick:()=>{window.electronAPI.extensionPlugins.uninstall(P.id)},children:e.jsx(Pe,{className:"size-4"})}),e.jsx("div",{className:"mx-1.5 h-5 w-px bg-border"}),e.jsx(ce,{checked:P.state==="enabled",onCheckedChange:Y=>{window.electronAPI.extensionPlugins.setEnabled(P.id,Y)}})]})]}),e.jsxs("button",{type:"button","aria-expanded":b.includes(P.id),className:K("flex w-full items-center gap-1 border-t bg-muted/20 px-3 py-1.5 text-left text-xs","text-muted-foreground transition-colors hover:bg-muted/50 hover:text-foreground"),onClick:()=>A(Y=>Y.includes(P.id)?Y.filter(D=>D!==P.id):[...Y,P.id]),children:[b.includes(P.id)?e.jsx(gt,{className:"size-3"}):e.jsx(Ds,{className:"size-3"}),b.includes(P.id)?"收起详情":"详情",!b.includes(P.id)&&xr(P)&&e.jsx("span",{className:"ml-1 opacity-70",children:xr(P)})]}),b.includes(P.id)&&e.jsxs("div",{className:"space-y-3 border-t px-3 py-3",children:[P.interceptBreakers?.map(Y=>e.jsxs("p",{className:"text-amber-600 text-xs dark:text-amber-400",children:[Y.event," 检查连续失败,临时放行到"," ",new Date(Y.until).toLocaleTimeString()]},Y.event)),e.jsx(hr,{permissions:P.permissions,resident:P.resident,running:P.running,styles:P.themes.some(Y=>Y.css!==void 0),trustedUi:P.hasRenderer,events:P.events,schedules:P.schedules}),P.crossSessionInject!==void 0&&e.jsxs("div",{className:"flex items-center justify-between gap-3 text-xs",children:[e.jsxs("span",{children:[e.jsx("span",{className:"block",children:"允许向任意运行中的会话发送消息"}),e.jsx("span",{className:"block text-muted-foreground",children:"关闭时只能发到发起调用的会话;开启后定时任务、常驻进程也能向其他项目和窗口的会话发消息并触发执行"})]}),e.jsx(ce,{"aria-label":"允许向任意运行中的会话发送消息",checked:P.crossSessionInject,onCheckedChange:Y=>{window.electronAPI.extensionPlugins.setCrossSessionInject(P.id,Y)}})]}),P.devWatch!==void 0&&e.jsxs("div",{className:"flex items-center justify-between gap-3 text-xs",children:[e.jsxs("span",{children:[e.jsx("span",{className:"block",children:"开发模式:目录改动后自动重装"}),e.jsx("span",{className:"block text-muted-foreground",children:"授权没扩大时直接替换;扩大时停下,需要从来源重新安装并同意。重启应用后关闭"})]}),e.jsx(ce,{"aria-label":"开发模式:目录改动后自动重装",checked:P.devWatch,onCheckedChange:Y=>{window.electronAPI.extensionPlugins.setDevWatch(P.id,Y).then(D=>{!D.ok&&D.error&&Te({title:D.error})})}})]}),((P.pendingPermissions?.length??0)>0||P.pendingRenderer)&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:"待同意"}),e.jsx(ri,{permissions:P.pendingPermissions??[],styles:P.pendingRenderer}),P.pendingRenderer&&e.jsx("p",{className:"text-amber-700 text-xs dark:text-amber-400",children:"新增界面代码:运行在主界面里,不受权限清单约束"})]})]})]},P.id))}),e.jsx(ye,{open:p!==null,onOpenChange:P=>!P&&j(null),children:e.jsxs(we,{children:[e.jsx(Ne,{children:e.jsxs(ke,{children:[p?.kind==="config"?i("Configure"):p?.kind==="logs"?i("Plugin logs"):"产出文件",p?` · ${p.pluginName}`:""]})}),e.jsxs(Ce,{className:"space-y-4",children:[p?.kind==="config"&&e.jsx(Cp,{pluginId:p.pluginId,plain:!0}),p?.kind==="logs"&&e.jsx(Sp,{pluginId:p.pluginId,plain:!0}),p?.kind==="artifacts"&&e.jsx(Ep,{pluginId:p.pluginId,plain:!0})]})]})}),e.jsx(fp,{pluginId:F?.id??null,name:F?.name??"",from:F?.from??"installed",homepage:F?.homepage,onClose:()=>X(null)})]})}function Pp(s,t){return[[s.skills.length,t("Skills")],[s.commands.length,t("Commands")],[s.agents.length,t("Agent types")],[s.mcpServers.length,"MCP"],[s.hooks.length,"Hooks"]].filter(([n])=>n>0).map(([n,a])=>`${a} ${n}`).join(" · ")}function As({label:s,items:t}){return t.length===0?null:e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("p",{className:"font-medium text-muted-foreground text-xs",children:s}),t.map(n=>e.jsx("p",{className:"break-all font-mono text-[11px]",children:n},n))]})}function Tp({plugin:s,entry:t,onToggle:n}){const{t:a}=R(),[r,o]=l.useState(!1),{components:i}=s,m=Pp(i,a);return e.jsxs("div",{className:"rounded-md border","data-settings-row":`plugins.${s.key}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 px-3 py-2",children:[e.jsxs("button",{type:"button",className:"flex min-w-0 flex-1 items-center gap-2 text-left",onClick:()=>o(u=>!u),children:[e.jsx(Ds,{className:K("h-4 w-4 shrink-0 text-muted-foreground transition-transform",r&&"rotate-90")}),e.jsx("span",{className:"shrink-0 font-medium text-sm",children:s.name}),s.version&&e.jsx(se,{variant:"outline",className:"shrink-0 text-[11px]",children:s.version}),s.marketplace&&e.jsx(se,{variant:"secondary",className:"shrink-0 text-[11px]",children:s.marketplace}),e.jsx("span",{className:"min-w-0 truncate text-muted-foreground text-xs",children:m||(i.unsupported.length>0?`${a("Not supported")}: ${i.unsupported.join(", ")}`:a("No supported components"))})]}),e.jsx(ce,{checked:t?.enabled===!0,onCheckedChange:n})]}),r&&e.jsxs("div",{className:"space-y-2 border-t px-3 py-2",children:[s.description&&e.jsx("p",{className:"text-muted-foreground text-xs",children:s.description}),e.jsx(As,{label:a("Skills"),items:i.skills}),e.jsx(As,{label:a("Commands"),items:i.commands.map(u=>`/${u}`)}),e.jsx(As,{label:a("Agent types"),items:i.agents}),e.jsx(As,{label:a("MCP servers (run when a session starts)"),items:i.mcpServers.map(u=>`${u.name}: ${u.target}`)}),e.jsx(As,{label:a("Hooks (run automatically on local sessions)"),items:i.hooks.map(u=>`${u.event}: ${u.command}`)}),e.jsx(As,{label:a("Not supported"),items:i.unsupported})]})]})}function Rp(){const{t:s}=R(),t=g(d=>d.plugins),n=g(d=>d.addPlugins),a=g(d=>d.setPluginEnabled),r=g(d=>d.removePlugin),[o,i]=l.useState(null),m=l.useCallback(async()=>{i(null);try{i(await window.electronAPI.assets.listInstalledPlugins())}catch{i([])}},[]);l.useEffect(()=>{m()},[m]);const u=new Map(t.map(d=>[d.key,d])),x=new Set((o??[]).map(d=>d.key)),h=o?t.filter(d=>!x.has(d.key)):[],c=t.filter(d=>d.enabled).length,f=(d,p)=>{const j=u.get(d.key);if(j){a(j.id,p);return}n([{id:crypto.randomUUID(),key:d.key,name:d.name,description:d.description,...d.version?{version:d.version}:{},source:d.marketplace||"Claude Code",enabled:p}])};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-end justify-between gap-4","data-settings-row":"plugins.root",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"font-medium text-lg",children:[s("Claude Code plugins"),e.jsx(Ze,{}),c>0&&e.jsx("span",{className:"ml-2 font-normal text-muted-foreground text-xs",children:s("{{count}} enabled",{count:c})})]}),e.jsx("p",{className:"text-muted-foreground text-sm",children:s("Plugins installed in Claude Code. Each one is switched on or off as a whole here; changes apply to new sessions.")})]}),e.jsxs(y,{variant:"outline",size:"sm",onClick:m,disabled:o===null,children:[e.jsx(ns,{className:"mr-1.5 h-4 w-4"}),s("Rescan")]})]}),o===null?e.jsx("div",{className:"flex justify-center py-10",children:e.jsx(Ps,{className:"size-5"})}):o.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx(Xs,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:s("No Claude Code plugins found")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:s("Install plugins with /plugin in Claude Code, then rescan.")})]}):e.jsx("div",{className:"space-y-2",children:o.map(d=>e.jsx(Tp,{plugin:d,entry:u.get(d.key),onToggle:p=>f(d,p)},d.key))}),h.length>0&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"font-medium text-muted-foreground text-xs",children:s("No longer installed in Claude Code")}),h.map(d=>e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md px-3 py-2 hover:bg-accent/50",children:[e.jsx("span",{className:"text-muted-foreground text-sm line-through",children:d.name}),e.jsx(y,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-destructive",onClick:()=>r(d.id),children:e.jsx(Pe,{className:"h-3.5 w-3.5"})})]},d.id))]})]})}const Ys={mask:"Mask",warn:"Warn only",block:"Block"},Op={email:"Email",phone:"Phone number",idCard:"ID card number",bankCard:"Bank card number",ip:"IP address"},pn={mask:"text-sky-600 dark:text-sky-400",warn:"text-amber-600 dark:text-amber-400",block:"text-red-600 dark:text-red-400"},Dp=[1,7,30],Lp={1:"Today",7:"7D",30:"30D"};function zp(s){const t=new Map;for(const n of s.report.hits){const a=t.get(n.token);a?a.count+=n.count:t.set(n.token,{label:`${n.kind} ${n.preview}`,count:n.count})}return[...t.values()].map(n=>n.count>1?`${n.label} ×${n.count}`:n.label).join(", ")}function Ht({value:s,onChange:t}){const{t:n}=R(),a=Object.fromEntries(Object.keys(Ys).map(r=>[r,n(Ys[r])]));return e.jsxs(ne,{items:a,value:s,onValueChange:r=>t(r),children:[e.jsx(ae,{className:"w-32",children:e.jsx(re,{})}),e.jsx(oe,{children:Object.entries(a).map(([r,o])=>e.jsx(Z,{value:r,children:o},r))})]})}function qt({label:s,hint:t,value:n,onCommit:a,rowId:r}){const[o,i]=l.useState(n.join(`
17
+ `)),E(Xa(D?.env)),T(D?.url??""),S(Wa(D?.headers)),q(D?.connectTimeoutSec?.toString()??""),z(D?.callTimeoutSec?.toString()??""),U(""),ie(Q=>Q+1),X(null)},[s]);const ue=D=>n(D==="invalid-json"?"Invalid JSON":"No MCP servers found in JSON"),O=D=>{if(D===i)return;if(D==="json"){U(_()),ie(fe=>fe+1),X(null),m("json");return}const Q=Ut(H);if(!Q.ok){if(Q.error==="invalid-json"&&H.trim()){X(ue(Q.error));return}X(null),m("form");return}if(Q.servers.length!==1){X(n("JSON must describe a single MCP server to switch to the form"));return}const ee=Q.servers[0];le({...ee,name:u.trim()||ee.name}),X(null),m("form")},De=()=>{const D=Ut(H);if(!D.ok){X(ue(D.error));return}if(D.servers.length===1){const[Q]=D.servers;U(JSON.stringify(Qa(Q),null,2)),ie(ee=>ee+1),u.trim()||x(Q.name)}else U(JSON.stringify({mcpServers:Object.fromEntries(D.servers.map(Q=>[Q.name,Qa(Q)]))},null,2)),ie(Q=>Q+1);X(null)},te=!!u.trim()&&(b==="stdio"?!!v.trim():!!L.trim()),P=i==="json"?!!H.trim():te,Y=()=>{if(!s||!P)return;if(i==="json"){const Q=Ut(H);if(!Q.ok){X(ue(Q.error));return}if(!o&&Q.servers.length!==1){X(n("JSON must describe a single MCP server"));return}if(o){const ee=Q.servers.length===1;if(a(Q.servers.map(xe=>({...de(xe,ee&&u.trim()?u:xe.name),...ee?{}:{description:void 0},id:crypto.randomUUID(),source:"Manual",enabled:!0})))===0){X(n("This MCP server already exists"));return}}else r(s.id,de(Q.servers[0],u.trim()||Q.servers[0].name));t();return}const D=b==="stdio"?{name:u.trim(),transport:b,command:v.trim(),args:Ya(I),env:Ja($),url:void 0,headers:void 0,...V()}:{name:u.trim(),transport:b,url:L.trim(),headers:Ka(C),command:void 0,args:void 0,env:void 0,...V()};if(o){if(a([{...D,id:crypto.randomUUID(),source:"Manual",enabled:!0}])===0){X(n("This MCP server already exists"));return}}else r(s.id,D);t()};return e.jsx(ye,{open:s!==null,onOpenChange:D=>!D&&t(),children:e.jsxs(we,{children:[e.jsx(Ne,{children:e.jsx(ke,{children:n(o?"Add MCP Server":"Edit MCP Server")})}),e.jsxs(Ce,{className:"space-y-4",children:[e.jsx(Qs,{value:i,onValueChange:D=>O(D),children:e.jsxs(Zs,{children:[e.jsx(Je,{value:"form",children:n("Form")}),e.jsx(Je,{value:"json",children:n("JSON")})]})}),e.jsxs(he,{children:[e.jsx(pe,{children:n("Name")}),e.jsx(J,{value:u,onChange:D=>x(D.target.value)})]}),e.jsxs(he,{children:[e.jsx(pe,{children:n("Description (optional)")}),e.jsx(J,{value:h,onChange:D=>c(D.target.value),placeholder:n("One line telling the model what this server is for")})]}),i==="json"?e.jsxs(he,{children:[e.jsxs("div",{className:"flex w-full items-center justify-between",children:[e.jsx(pe,{children:n("JSON configuration")}),e.jsx(y,{variant:"ghost",size:"sm",className:"h-7 px-2",onClick:De,children:n("Format")})]}),e.jsx(qo,{fileName:"mcp.json",value:H,epoch:B,onChange:U}),e.jsx("p",{className:"text-muted-foreground text-xs",children:n("Paste a server object or mcpServers JSON from Cursor / Claude Desktop")})]}):e.jsxs(e.Fragment,{children:[e.jsxs(he,{children:[e.jsx(pe,{children:n("Transport")}),e.jsxs(ne,{items:ja.map(D=>({value:D,label:D})),value:b,onValueChange:D=>A(D),children:[e.jsx(ae,{className:"w-full",children:e.jsx(re,{})}),e.jsx(oe,{zIndex:cs.DROPDOWN_IN_MODAL,children:ja.map(D=>e.jsx(Z,{value:D,children:D},D))})]})]}),b==="stdio"?e.jsxs(e.Fragment,{children:[e.jsxs(he,{children:[e.jsx(pe,{children:n("Command")}),e.jsx(J,{value:v,onChange:D=>k(D.target.value),placeholder:"npx",className:"font-mono text-xs"})]}),e.jsxs(he,{children:[e.jsx(pe,{children:n("Arguments (one per line)")}),e.jsx(Xe,{value:I,onChange:D=>M(D.target.value),rows:3,className:"font-mono text-xs"})]}),e.jsxs(he,{children:[e.jsx(pe,{children:n("Environment variables (KEY=VALUE, one per line)")}),e.jsx(Xe,{value:$,onChange:D=>E(D.target.value),rows:3,className:"font-mono text-xs"})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs(he,{children:[e.jsx(pe,{children:n("URL")}),e.jsx(J,{value:L,onChange:D=>T(D.target.value),placeholder:"https://...",className:"font-mono text-xs"})]}),e.jsxs(he,{children:[e.jsx(pe,{children:n("Headers (Name: value, one per line)")}),e.jsx(Xe,{value:C,onChange:D=>S(D.target.value),rows:2,placeholder:"Authorization: Bearer <token>",className:"font-mono text-xs"})]}),e.jsxs(he,{children:[e.jsx(pe,{children:n("OAuth client name (optional)")}),e.jsx(J,{value:f,onChange:D=>d(D.target.value),placeholder:n("For servers that only accept known OAuth clients")})]}),e.jsxs(he,{children:[e.jsx(pe,{children:n("OAuth authorization server metadata URL (optional)")}),e.jsx(J,{value:p,onChange:D=>j(D.target.value),placeholder:n("Use when the server advertises a wrong authorization server or none"),className:"font-mono text-xs"})]})]}),e.jsxs(he,{children:[e.jsx(pe,{children:n("Connection timeout (seconds)")}),e.jsx(J,{inputMode:"numeric",value:W,onChange:D=>q(D.target.value),placeholder:String(rh/1e3)})]}),e.jsxs(he,{children:[e.jsx(pe,{children:n("Tool call timeout (seconds)")}),e.jsx(J,{inputMode:"numeric",value:N,onChange:D=>z(D.target.value),placeholder:String(oh/1e3)})]})]}),F&&e.jsx("p",{className:"t-shake-in text-destructive text-xs",children:F},F)]}),e.jsxs(Ee,{children:[e.jsx(y,{variant:"outline",size:"sm",onClick:t,children:n("Cancel")}),e.jsx(y,{size:"sm",disabled:!P,onClick:Y,children:n("Save")})]})]})})}function mh({status:s}){const{t}=R();return s.state==="connecting"?e.jsx(se,{variant:"outline",className:"shrink-0 animate-pulse text-[11px] text-muted-foreground",children:t("Connecting")}):s.state==="ready"?e.jsx(se,{variant:"success",className:"shrink-0 text-[11px]",children:t("{{count}} tools",{count:s.toolCount??0})}):s.state==="unauthorized"?e.jsx(se,{variant:"warning",className:"shrink-0 text-[11px]",children:t("Not authorized")}):s.state==="idle"?e.jsx(se,{variant:"outline",className:"shrink-0 text-[11px] text-muted-foreground",children:t("Authorized, pending connection")}):e.jsx(se,{variant:"error",className:"shrink-0 text-[11px]",title:s.error,children:t("Connection failed")})}function xh(){const{t:s}=R(),t=g(S=>S.mcpServers),n=g(S=>S.updateMcpServer),a=g(S=>S.setMcpServersEnabled),r=g(S=>S.removeMcpServer),o=fs(S=>S.statuses),i=fs(S=>S.authorized),m=fs(S=>S.pending),u=fs(S=>S.authorize),x=fs(S=>S.revoke);l.useEffect(()=>fs.getState().bind(),[]);const[h,c]=l.useState(!1),[f,d]=l.useState(null),p=async S=>{await u(S),d(fs.getState().authorized[S]===!0?S:null)},[j,b]=l.useState(null),[A,v]=l.useState(""),k=t.filter(S=>co(A,[S.name,S.source,S.transport,S.url,S.command,...S.args??[]])),I=k.map(S=>S.id),M=uo(I),$=t.filter(S=>S.enabled).length,E=t.filter(S=>S.enabled).map(S=>S.id),L=It(E,S=>window.electronAPI.assets.mcpOccupancy(S)),T=t.filter(S=>S.enabled&&S.loadMode!=="deferred").map(S=>S.id),C=kt(T,L.rows);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-end justify-between gap-4","data-settings-row":"mcp.root",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"font-medium text-lg",children:[s("MCP Servers"),e.jsx(Ze,{}),t.length>0&&e.jsxs("span",{className:"ml-2 font-normal text-muted-foreground text-xs",children:[s("{{enabled}}/{{total}} enabled",{enabled:$,total:t.length}),e.jsx(St,{tokens:C})]})]}),e.jsx("p",{className:"text-muted-foreground text-sm",children:s("Model Context Protocol servers available to this app")})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsxs(y,{variant:"outline",size:"sm",onClick:()=>c(!0),children:[e.jsx(Nt,{className:"mr-1.5 h-4 w-4"}),s("Import from local apps")]}),e.jsxs(y,{variant:"outline",size:"sm",onClick:()=>b("new"),children:[e.jsx(Re,{className:"mr-1.5 h-4 w-4"}),s("Add MCP server")]})]})]}),t.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx(mo,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:s("No MCP servers yet")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:s("Import MCP servers from local apps or add one manually to get started")})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx(xo,{query:A,onQueryChange:v,placeholder:s("Filter MCP servers..."),allSelected:M.allSelected,someSelected:M.someSelected,onToggleSelectAll:M.toggleAll,onEnable:()=>a(M.selectedIds,!0),onDisable:()=>a(M.selectedIds,!1),selectDisabled:k.length===0,actionDisabled:M.selectedIds.length===0}),k.length===0?e.jsx("p",{className:"px-3 py-6 text-center text-muted-foreground text-xs",children:s("No results")}):e.jsx("div",{className:"space-y-1",children:k.map(S=>{const W=o[S.id]??o[S.name],q=m[S.id]===!0,N=S.transport!=="stdio"&&i[S.id]!==!0,z=S.loadMode==="deferred";return e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"group flex items-center justify-between gap-3 rounded-md px-3 py-2 transition-colors hover:bg-accent/50","data-settings-row":`mcp.${S.id}`,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(Le,{checked:M.isSelected(S.id),onCheckedChange:H=>M.toggleOne(S.id,H)}),e.jsx("span",{className:K("shrink-0 font-medium text-sm",!S.enabled&&"text-muted-foreground line-through"),children:S.name}),e.jsx(se,{variant:"outline",className:"shrink-0 text-[11px]",children:S.transport}),e.jsx(se,{variant:"secondary",className:"shrink-0 text-[11px]",children:S.source}),W&&e.jsx(mh,{status:W}),e.jsx("span",{className:"min-w-0 truncate font-mono text-muted-foreground text-xs",children:S.url??[S.command,...S.args??[]].join(" ")})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[(N||W?.state==="unauthorized")&&e.jsxs(y,{variant:"outline",size:"sm",className:"h-7",disabled:q,onClick:()=>{p(S.id)},children:[q?e.jsx(Me,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):e.jsx(yc,{className:"mr-1.5 h-3.5 w-3.5"}),s(q?"Authorizing":"Authorize")]}),i[S.id]===!0&&e.jsx(y,{variant:"ghost",size:"icon",title:s("Revoke authorization"),className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",onClick:()=>{x(S.id)},children:e.jsx(wc,{className:"h-3.5 w-3.5"})}),e.jsx(Ct,{row:L.rows[S.id],pending:S.enabled&&L.pending&&!L.rows[S.id]}),e.jsx(Qs,{value:z?"deferred":"direct",onValueChange:H=>n(S.id,{loadMode:H==="deferred"?"deferred":"direct"}),title:s("On demand: tool descriptions are not preloaded into context; the model connects through the mcp tool when needed. Suits servers with many or rarely used tools. Takes effect in new conversations."),children:e.jsxs(Zs,{"aria-label":s("Load mode"),children:[e.jsx(Je,{value:"direct",className:"h-6 px-2 text-xs sm:h-6 sm:text-xs",children:s("Always loaded")}),e.jsx(Je,{value:"deferred",className:"h-6 px-2 text-xs sm:h-6 sm:text-xs",children:s("On demand")})]})}),e.jsx(ce,{checked:S.enabled,onCheckedChange:H=>n(S.id,{enabled:H})}),e.jsx(y,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",onClick:()=>b(S),children:e.jsx(hs,{className:"h-3.5 w-3.5"})}),e.jsx(y,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity hover:text-destructive group-hover:opacity-100",onClick:()=>r(S.id),children:e.jsx(Pe,{className:"h-3.5 w-3.5"})})]})]}),f===S.id&&e.jsx("p",{className:"px-3 text-muted-foreground text-xs",children:s("Authorized. Conversations that already include this server can use it on the next message.")})]},S.id)})})]}),e.jsx(zn,{kind:"mcp",open:h,onOpenChange:c}),e.jsx(uh,{server:j,onClose:()=>b(null)})]})}const Za={PERSON:340,ORGANIZATION:20,TEAM:20,PRODUCT:210,TOOL:210,SYSTEM:250,SERVICE:250,PLATFORM:250,CONCEPT:160,METHOD:160,TECHNIQUE:160,EVENT:40,PROJECT:280,DOCUMENT:90,TERM:190};function Yo(s){if(Za[s]!==void 0)return Za[s];let t=0;for(let n=0;n<s.length;n++)t=t*17+s.charCodeAt(n)>>>0;return t%360}const $t=22,hh=64;function ph(s,t){if(t<=1)return $t;const n=Math.sqrt(Math.max(1,s))/Math.sqrt(t);return Math.round($t+(hh-$t)*Math.min(1,n))}function fh(s,t,n){const a=Math.max(1,...s.map(o=>o.memoryCount)),r=new Set(s.map(o=>o.id));return[...s.map(o=>({data:{id:o.id,label:o.name,size:ph(o.memoryCount,a),color:Jo(Yo(o.entityType),n),entityType:o.entityType,memoryCount:o.memoryCount,spaceLabel:o.spaceLabel}})),...t.filter(o=>r.has(o.source)&&r.has(o.target)&&o.source!==o.target).map(o=>({data:{id:`${o.source}->${o.target}:${o.relation}`,source:o.source,target:o.target,label:o.relation.replace(/_/g," ").toLowerCase(),width:1+o.strength*2.5}}))]}function gh(s,t){const n=new Map;for(const a of s)n.set(a.entityType,(n.get(a.entityType)??0)+1);return[...n.entries()].map(([a,r])=>({entityType:a,count:r,color:Jo(Yo(a),t)})).sort((a,r)=>r.count-a.count||a.entityType.localeCompare(r.entityType))}function jh(s){const t=s?"#e7e7e9":"#1c1c1f";return[{selector:"node",style:{"background-color":"data(color)","background-opacity":.85,width:"data(size)",height:"data(size)",label:"data(label)","font-size":11,color:t,"text-valign":"bottom","text-margin-y":4,"text-max-width":"120px","text-wrap":"ellipsis","border-width":0,"transition-property":"opacity, border-width","transition-duration":150}},{selector:"edge",style:{width:"data(width)","line-color":s?"#4b4b52":"#c9c9d1","curve-style":"bezier",opacity:.65,"font-size":9,color:t,"text-opacity":0}},{selector:"edge:selected, edge.highlighted",style:{"text-opacity":.85,opacity:1}},{selector:"node:selected",style:{"border-width":3,"border-color":t,"background-opacity":1}},{selector:".dimmed",style:{opacity:.18,"text-opacity":.25}}]}function Jo(s,t){return vh(s,t?.62:.68,t?.58:.52)}function vh(s,t,n){const a=(1-Math.abs(2*n-1))*t,r=a*(1-Math.abs(s/60%2-1)),o=n-a/2,[i,m,u]=s<60?[a,r,0]:s<120?[r,a,0]:s<180?[0,a,r]:s<240?[0,r,a]:s<300?[r,0,a]:[a,0,r],x=h=>Math.round((h+o)*255).toString(16).padStart(2,"0");return`#${x(i)}${x(m)}${x(u)}`}let er=!1;function bh(){er||(Oo.use(gu),er=!0)}const sr={name:"fcose",animate:!1,randomize:!1,nodeRepulsion:8e3,idealEdgeLength:90,nodeSeparation:90,padding:24,fit:!0};function yh({graph:s,selectedId:t,onSelect:n,memories:a,loading:r,onInterpret:o,interpreting:i}){const{t:m}=R(),u=l.useRef(null),x=l.useRef(null),h=l.useRef(n);h.current=n;const[c,f]=l.useState(null),d=l.useMemo(()=>typeof document<"u"&&document.documentElement.classList.contains("dark"),[]);l.useEffect(()=>{const b=u.current;if(!b||s.nodes.length===0)return;bh();const A=Oo({container:b,elements:fh(s.nodes,s.edges,d),style:jh(d),minZoom:.2,maxZoom:2.5,wheelSensitivity:.2});return A.layout(sr).run(),A.on("tap","node",v=>h.current(v.target.id())),A.on("tap",v=>{v.target===A&&h.current(null)}),x.current=A,()=>{A.destroy(),x.current=null}},[s.nodes,s.edges,d]),l.useEffect(()=>{const b=x.current;b&&b.batch(()=>{if(b.elements().removeClass("dimmed").unselect(),!t)return;const A=b.getElementById(t);if(A.empty())return;const v=A.closedNeighborhood();b.elements().difference(v).addClass("dimmed"),A.select()})},[t]);const p=l.useMemo(()=>gh(s.nodes,d),[s.nodes,d]),j=s.nodes.find(b=>b.id===t)??null;return l.useEffect(()=>{const b=x.current;!b||t||b.batch(()=>{b.elements().removeClass("dimmed"),c&&b.nodes().filter(A=>A.data("entityType")!==c).addClass("dimmed")})},[c,t]),s.nodes.length===0?e.jsx("p",{className:"rounded-lg border px-3 py-6 text-muted-foreground text-sm",children:m(r?"Loading…":"No entities yet. Turn on entity extraction and store a few memories first.")}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"relative overflow-hidden rounded-lg border bg-muted/20",children:[e.jsx("div",{ref:u,className:"h-[440px] w-full"}),e.jsxs("div",{className:"absolute right-2 bottom-2 flex gap-1",children:[e.jsx(y,{size:"sm",variant:"outline",onClick:()=>x.current?.fit(void 0,24),title:m("Fit to view"),children:m("Fit")}),e.jsx(y,{size:"sm",variant:"outline",onClick:()=>x.current?.layout(sr).run(),title:m("Re-run layout"),children:m("Relayout")})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:m("Colour = entity type · size = how many memories mention it",{})}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:p.map(b=>e.jsxs("button",{type:"button",onClick:()=>f(c===b.entityType?null:b.entityType),className:K("inline-flex items-center gap-1.5 rounded-full border px-2 py-0.5 text-xs transition-colors",c===b.entityType?"border-foreground/40 bg-accent":"hover:bg-accent/50"),children:[e.jsx("span",{className:"size-2.5 shrink-0 rounded-full",style:{backgroundColor:b.color}}),e.jsx("span",{className:"text-muted-foreground",children:b.entityType.toLowerCase()}),e.jsx("span",{className:"tabular-nums",children:b.count})]},b.entityType))}),e.jsx("p",{className:"text-muted-foreground text-xs",children:m("{{shown}} of {{total}} entities",{shown:String(s.nodes.length),total:String(s.totalEntities)})})]}),j&&e.jsxs("section",{className:"space-y-2 rounded-lg border p-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"flex items-center gap-2 text-sm",children:[e.jsx("span",{className:"truncate font-medium",children:j.name}),e.jsx(se,{variant:"secondary",children:j.entityType})]}),e.jsx("p",{className:"text-muted-foreground text-xs",children:m("{{count}} memories · {{space}}",{count:String(j.memoryCount),space:j.spaceLabel})})]}),e.jsx(y,{size:"sm",variant:"outline",disabled:i,onClick:()=>o(j.id),children:m(i?"Interpreting…":"Interpret")})]}),e.jsxs("ul",{className:"divide-y rounded-lg border",children:[a.length===0&&e.jsx("li",{className:"px-3 py-4 text-muted-foreground text-sm",children:m("Loading…")}),a.map(b=>e.jsxs("li",{className:"space-y-0.5 px-3 py-2",children:[e.jsxs("p",{className:"flex items-center gap-2 text-sm",children:[b.isCrystal&&e.jsx("span",{title:m("Crystal"),children:"★"}),e.jsx("span",{className:"truncate",children:b.title}),e.jsx(se,{variant:"secondary",children:b.unitType})]}),e.jsx("p",{className:"line-clamp-2 text-muted-foreground text-xs",children:b.contentSummary})]},b.id))]})]})]})}function wh({tree:s,loading:t,selected:n,onToggle:a,onInterpretGroup:r,interpreting:o}){const{t:i}=R(),[m,u]=l.useState(new Set);return s.length===0?e.jsx("p",{className:"rounded-lg border px-3 py-6 text-muted-foreground text-sm",children:i(t?"Loading…":"No memories yet.")}):e.jsx("ul",{className:"divide-y rounded-lg border",children:s.map(x=>{const h=m.has(x.id),c=(x.children??[]).map(f=>f.memoryId).filter(f=>!!f);return e.jsxs("li",{children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 px-3 py-2",children:[e.jsx("button",{type:"button",className:"min-w-0 flex-1 text-left",onClick:()=>{const f=new Set(m);f.delete(x.id)||f.add(x.id),u(f)},children:e.jsxs("p",{className:"flex items-center gap-2 text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:h?"▾":"▸"}),e.jsx("span",{className:"truncate",children:x.label}),e.jsx(se,{variant:"secondary",children:x.count})]})}),e.jsx(y,{size:"sm",variant:"ghost",className:"shrink-0",disabled:o||c.length===0,onClick:()=>r(x),children:i("Interpret")})]}),h&&e.jsxs("ul",{className:"divide-y border-t bg-muted/20",children:[(x.children??[]).map(f=>e.jsxs("li",{className:"flex items-center gap-2 px-3 py-2",children:[f.memoryId&&e.jsx(Le,{checked:n.has(f.memoryId),onCheckedChange:()=>f.memoryId&&a(f.memoryId),"aria-label":i("Select memory")}),e.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-2",children:[f.isCrystal&&e.jsx("span",{title:i("Crystal"),children:"★"}),e.jsx("span",{className:"truncate text-sm",children:f.label})]})]},f.id)),x.count>(x.children?.length??0)&&e.jsx("li",{className:"px-3 py-2 text-muted-foreground text-xs",children:i("Showing {{shown}} of {{total}}",{shown:String(x.children?.length??0),total:String(x.count)})})]})]},x.id)})})}const Nh=120,kh=30,Ch={nodes:[],edges:[],totalEntities:0};function Sh({revision:s=0}={}){const{t}=R(),[n,a]=l.useState("graph"),[r,o]=l.useState("unitType"),[i,m]=l.useState(Ch),[u,x]=l.useState([]),[h,c]=l.useState(!0),[f,d]=l.useState(null),[p,j]=l.useState([]),[b,A]=l.useState(new Set),[v,k]=l.useState(null),[I,M]=l.useState(!1),[$,E]=l.useState(null),[L,T]=l.useState(!1),C=l.useCallback(()=>{c(!0);const B=()=>c(!1);n==="graph"?window.electronAPI.memory.graph({limit:Nh,minMemories:1}).then(m).finally(B):window.electronAPI.memory.tree({groupBy:r,limitPerGroup:kh}).then(x).finally(B)},[n,r]);l.useEffect(C,[C]);const S=l.useRef(C);S.current=C,l.useEffect(()=>window.electronAPI.memory.onChanged(()=>S.current()),[]);const W=l.useRef(s);l.useEffect(()=>{W.current!==s&&(W.current=s,C())},[s,C]),l.useEffect(()=>{if(!f){j([]);return}window.electronAPI.memory.graphEntity(f).then(j)},[f]);const q=async B=>{M(!0),k(null);try{k(await window.electronAPI.memory.insight(B))}finally{M(!1)}},N=async()=>{T(!0);try{const B=await window.electronAPI.memory.crystallize({memoryIds:[...b]});E(B),B.ok&&A(new Set)}finally{T(!1)}},z=[{value:"graph",label:t("Graph")},{value:"tree",label:t("Tree")}],H=[{value:"unitType",label:t("By type")},{value:"entity",label:t("By entity")},{value:"time",label:t("By month")}],U=b.size>=va;return e.jsxs("div",{className:"space-y-4","data-settings-row":"memory.knowledge",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-medium text-sm",children:t("Knowledge")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Browse what the agent knows as a graph or a tree, ask for an interpretation, and consolidate related memories into a crystal.")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(ne,{value:n,items:z,onValueChange:B=>a(B==="tree"?"tree":"graph"),children:[e.jsx(ae,{size:"sm",className:"w-32",children:e.jsx(re,{})}),e.jsx(oe,{children:z.map(B=>e.jsx(Z,{value:B.value,children:B.label},B.value))})]}),n==="tree"&&e.jsxs(ne,{value:r,items:H,onValueChange:B=>o(B),children:[e.jsx(ae,{size:"sm",className:"w-36",children:e.jsx(re,{})}),e.jsx(oe,{children:H.map(B=>e.jsx(Z,{value:B.value,children:B.label},B.value))})]}),e.jsx("span",{className:"flex-1"}),n==="tree"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:K("text-xs",U?"text-foreground":"text-muted-foreground"),children:t("{{count}} selected",{count:String(b.size)})}),e.jsx(y,{size:"sm",variant:"outline",disabled:!U||L,onClick:()=>{N()},children:L?t("Synthesizing…"):t("Crystallize ({{min}}+)",{min:String(va)})})]})]}),n==="graph"?e.jsx(yh,{graph:i,loading:h,selectedId:f,onSelect:d,memories:p,interpreting:I,onInterpret:B=>{q({entityId:B})}}):e.jsx(wh,{tree:u,loading:h,selected:b,interpreting:I,onToggle:B=>{const ie=new Set(b);ie.delete(B)||ie.add(B),A(ie)},onInterpretGroup:B=>{const ie=(B.children??[]).map(F=>F.memoryId).filter(F=>!!F);q({memoryIds:ie})}}),e.jsx(ye,{open:v!==null,onOpenChange:B=>!B&&k(null),children:e.jsxs(we,{children:[e.jsxs(Ne,{children:[e.jsx(ke,{children:t("Interpretation")}),v?.ok&&e.jsx(Ye,{children:t("Based on {{count}} memories",{count:String(v.sourceCount??0)})})]}),e.jsx(Ce,{children:v?.ok?e.jsx("p",{className:"whitespace-pre-wrap text-sm",children:v.text}):e.jsx("p",{className:"text-destructive text-sm",children:v?.error})}),e.jsx(Ee,{children:e.jsx(Hs,{render:e.jsx(y,{variant:"outline",size:"sm"}),children:t("Close")})})]})}),e.jsx(ye,{open:$!==null,onOpenChange:B=>!B&&E(null),children:e.jsxs(we,{children:[e.jsxs(Ne,{children:[e.jsx(ke,{children:$?.ok?t("Crystal created"):t("Nothing was written")}),$?.ok&&e.jsx(Ye,{children:$.title})]}),e.jsx(Ce,{className:"space-y-3",children:$?.ok?e.jsx("p",{className:"whitespace-pre-wrap text-sm",children:$.content}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-destructive text-sm",children:$?.error}),$?.candidates&&$.candidates.length>0&&e.jsx("ul",{className:"divide-y rounded-lg border",children:$.candidates.map(B=>e.jsxs("li",{className:"flex items-center justify-between gap-2 px-3 py-2",children:[e.jsx("span",{className:"truncate text-sm",children:B.title}),e.jsxs(se,{variant:"secondary",children:[(B.similarity*100).toFixed(0),"%"]})]},B.id))})]})}),e.jsx(Ee,{children:e.jsx(Hs,{render:e.jsx(y,{variant:"outline",size:"sm"}),children:t("Close")})})]})})]})}function hn(s){return s==="fast"||s==="deep"}const Ss=25,Fe="__all__";function Os(s){const t=new Date(s);if(Number.isNaN(t.getTime()))return s;const n=a=>String(a).padStart(2,"0");return`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())} ${n(t.getHours())}:${n(t.getMinutes())}`}const tr=["global","project","secretary","bot","chat"],Ih={global:"Global",project:"Projects",secretary:"Secretary",bot:"Members",chat:"Group chats"};function Ah(s,t,n){return t?{spaceId:t}:s?{spaceIds:n.filter(a=>a.kind===s).map(a=>a.id)}:{}}function Eh(s){return s.startsWith("bot:")?"bot":s.startsWith("chat:")?"chat":s.startsWith("proj:")?"project":"global"}function Mh(s,t){return s===!1&&!t}function Ph(s,t,n,a){return hn(s)&&!t.trim()?"needs-query":Mh(n,a)?"library-empty":"no-match"}function Th({items:s,onOpen:t,onEdit:n,onDelete:a,t:r,selected:o,onToggle:i,emptyLabel:m}){return e.jsxs("ul",{className:"divide-y overflow-hidden rounded-lg border",children:[s.length===0&&e.jsx("li",{className:"px-3 py-6 text-sm text-muted-foreground",children:m}),s.map(u=>e.jsxs("li",{className:K(Ac,"flex items-center gap-2 px-3 py-2"),"data-memory-id":u.id,children:[i&&e.jsx(Le,{checked:o?.has(u.id)??!1,onCheckedChange:()=>i(u.id),"aria-label":r("Select memory")}),e.jsxs("button",{type:"button",onClick:()=>t(u.id),className:"min-w-0 flex-1 space-y-0.5 text-left",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[u.isCrystal&&e.jsx("span",{title:r("Crystal"),children:"★"}),e.jsx("span",{className:"truncate text-sm",children:u.title}),e.jsx(se,{variant:"secondary",children:u.unitType}),e.jsx(Oh,{importance:u.importance,t:r}),u.lifecycleState==="archived"&&e.jsx(se,{variant:"outline",children:r("Archived")}),u.archiveCandidateAt&&e.jsx(se,{variant:"warning",title:r("Marked by the forgetting pass: cold and low importance"),children:r("Archive candidate")})]}),e.jsx("span",{className:"line-clamp-2 text-muted-foreground text-xs",children:u.contentSummary}),e.jsxs("span",{className:"block text-muted-foreground text-xs",children:[r("Recorded {{date}}",{date:Os(u.createdAt)})," · ",u.spaceLabel," ","· ",r("Retrieved {{count}} times",{count:String(u.appearances)})]})]}),n&&a&&e.jsx(Ic,{id:u.id,onEdit:n,onDelete:a})]},u.id))]})}const Rh={critical:{variant:"warning",label:"critical"},important:{variant:"info",label:"important"},useful:{variant:"outline",label:"useful"},low:{variant:"outline",label:"low"}};function Oh({importance:s,t}){const n=Pc(s),a=Rh[n];return e.jsx(se,{variant:a.variant,className:n==="low"?"text-muted-foreground":void 0,title:t("Importance {{value}}",{value:s.toFixed(2)}),children:t(a.label)})}const Dh=6,Lh=50;function zh(s){const t=[...s].sort((a,r)=>r.edge.createdAt.localeCompare(a.edge.createdAt)||a.edge.id.localeCompare(r.edge.id));if(t.length<=Dh)return[{key:"",label:"",items:t}];const n=new Map;for(const a of t){const r=a.older.spaceId,o=n.get(r)??{key:r,label:a.older.spaceLabel,items:[]};o.items.push(a),n.set(r,o)}return[...n.values()].sort((a,r)=>a.label.localeCompare(r.label))}function nr({label:s,memory:t,onOpen:n}){return e.jsxs("button",{type:"button",onClick:()=>n(t.id),className:"block w-full space-y-0.5 rounded-md px-1 py-0.5 text-left hover:bg-accent/40","data-memory-review-side":t.id,children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"shrink-0 text-muted-foreground text-xs",children:s}),e.jsx("span",{className:"truncate text-sm",children:t.title})]}),e.jsx("span",{className:"line-clamp-2 text-muted-foreground text-xs",children:t.contentSummary})]})}function _h({items:s,selected:t,onToggle:n,onToggleAll:a,onReview:r,onOpen:o,t:i}){if(s.length===0)return e.jsxs("section",{className:"space-y-2","data-settings-row":"memory.review",children:[e.jsx("h3",{className:"text-sm font-medium",children:i("Needs review")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:i("Nothing to review. When a new memory contradicts an existing one, the pair shows up here.")})]});const m=s.every(u=>t.has(u.edge.id));return e.jsxs("section",{className:"space-y-2","data-settings-row":"memory.review",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("h3",{className:"text-sm font-medium",children:i("Needs review")}),e.jsxs("label",{className:"flex items-center gap-2 text-muted-foreground text-xs",children:[e.jsx(Le,{checked:m,onCheckedChange:()=>a(!m),"aria-label":i("Select all")}),i("{{count}} pending",{count:String(s.length)})]})]}),e.jsxs("div",{className:"space-y-0.5 text-muted-foreground text-xs",children:[e.jsx("p",{children:i("Reviewing only records your judgement. Nothing is deleted and no memory is superseded.")}),e.jsx("p",{children:i("Accept: recorded as a confirmed contradiction. Both memories stay and stay searchable — you just stop being asked.")}),e.jsx("p",{children:i("Dismiss: recorded as not a contradiction. Both memories stay unchanged and you stop being asked.")})]}),s.length>Lh&&e.jsx("p",{className:"text-warning text-xs","data-memory-review-alert":!0,children:i("{{count}} contradictions are waiting for review. Clear them in bulk so real conflicts do not get buried.",{count:String(s.length)})}),t.size>0&&e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 rounded-lg border bg-accent/30 px-3 py-2",children:[e.jsx("span",{className:"text-sm",children:i("{{count}} selected",{count:String(t.size)})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(y,{variant:"ghost",size:"sm",onClick:()=>a(!1),children:i("Clear selection")}),e.jsx(y,{variant:"outline",size:"sm",onClick:()=>r([...t],"accepted"),children:i("Accept selected")}),e.jsx(y,{variant:"ghost",size:"sm",onClick:()=>r([...t],"rejected"),children:i("Dismiss selected")})]})]}),zh(s).map(u=>e.jsxs("div",{className:"space-y-2",children:[u.label&&e.jsxs("h4",{className:"text-muted-foreground text-xs",children:[u.label," · ",i("{{count}} pending",{count:String(u.items.length)})]}),u.items.map(({edge:x,older:h,newer:c})=>e.jsxs("div",{className:"space-y-1.5 rounded-lg border px-3 py-2","data-memory-review":x.id,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(Le,{checked:t.has(x.id),onCheckedChange:()=>n(x.id),"aria-label":i("Select memory")}),e.jsx(se,{variant:"outline",children:x.relation}),e.jsxs("span",{className:"text-muted-foreground text-xs",children:[h.spaceLabel," · ",Os(x.createdAt)]})]}),e.jsx(nr,{label:i("Earlier memory"),memory:h,onOpen:o}),e.jsx(nr,{label:i("Newer memory"),memory:c,onOpen:o}),e.jsx("p",{className:"text-muted-foreground text-xs",children:x.reason?`${i("Why they conflict")}: ${x.reason}`:i("No reason recorded for this pair.")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(y,{size:"sm",variant:"outline",onClick:()=>r([x.id],"accepted"),children:i("Accept")}),e.jsx(y,{size:"sm",variant:"ghost",onClick:()=>r([x.id],"rejected"),children:i("Dismiss")})]})]},x.id))]},u.key))]})}function Fh({writes:s,onReview:t,t:n}){return s.length===0?null:e.jsxs("section",{className:"space-y-2","data-settings-row":"memory.pending-writes",children:[e.jsx("h3",{className:"text-sm font-medium",children:n("Memory writes awaiting approval")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n("Bot members need your approval before writing to project or global memory.")}),s.map(a=>e.jsxs("div",{className:"space-y-1 rounded-lg border px-3 py-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-xs text-muted-foreground",children:[a.originLabel&&e.jsx("span",{className:"text-foreground",children:a.originLabel}),e.jsxs("span",{children:["→ ",a.spaceLabel]}),a.redacted&&e.jsxs("span",{children:["· ",n("Secrets redacted")]})]}),a.title&&e.jsx("div",{className:"text-sm font-medium",children:a.title}),e.jsx("p",{className:"whitespace-pre-wrap text-xs",children:a.content}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(y,{size:"sm",variant:"outline",onClick:()=>t(a.id,"approve"),children:n("Approve")}),e.jsx(y,{size:"sm",variant:"ghost",onClick:()=>t(a.id,"reject"),children:n("Reject")})]})]},a.id))]})}function Bh({t:s}){const t=Ec(),n=Mc(a=>a.review);return e.jsx(Fh,{writes:t,t:s,onReview:(a,r)=>{n(a,r)}})}function Uh({revision:s=0}={}){const{t}=R(),[n,a]=l.useState(""),[r,o]=l.useState(Fe),[i,m]=l.useState(Fe),[u,x]=l.useState(Fe),[h,c]=l.useState(!1),[f,d]=l.useState(!1),[p,j]=l.useState(0),[b,A]=l.useState("exact"),[v,k]=l.useState(!1),[I,M]=l.useState(!0),[$,E]=l.useState([]),[L,T]=l.useState(0),[C,S]=l.useState([]),W=l.useRef(C);W.current=C;const[q,N]=l.useState(null),[z,H]=l.useState(null),[U,B]=l.useState(null),[ie,F]=l.useState(null),[X,V]=l.useState(new Set),[le,_]=l.useState(!1),[de,ue]=l.useState([]),[O,De]=l.useState(new Set),te=l.useRef(!1),P=l.useRef(0),Y=l.useRef(0);l.useEffect(()=>(te.current=!0,()=>{te.current=!1,P.current++,Y.current++}),[]);const D=l.useCallback(()=>{if(!te.current)return;const G=++P.current,je=()=>te.current&&G===P.current;if(hn(b)&&!n.trim()){E([]),T(0),k(!0),M(!0);return}const be=tr.find(Ae=>Ae===r)??null;window.electronAPI.memory.list({query:n.trim()||void 0,...Ah(be,i===Fe?null:i,W.current),unitType:u===Fe?void 0:u,includeArchived:h,archiveCandidate:f||void 0,limit:Ss,offset:p,mode:b}).then(Ae=>{je()&&(E(Ae.items),T(Ae.total),k(Ae.approximate===!0),M(Ae.vectorsUsed!==!1))}),window.electronAPI.memory.stats().then(Ae=>{te.current&&(S(Object.keys(Ae.bySpace).map(qe=>({id:qe,label:Ae.spaceLabels[qe]??qe,kind:Ae.spaceKinds?.[qe]??Eh(qe)}))),N(Ae.total>0))}),window.electronAPI.memory.evolvesPending().then(Ae=>{te.current&&ue(Ae)})},[n,r,i,u,h,f,p,b]);l.useEffect(()=>(D(),()=>{P.current++}),[D]);const Q=l.useRef(D);Q.current=D,l.useEffect(()=>window.electronAPI.memory.onChanged(()=>Q.current()),[]);const ee=l.useRef(s);l.useEffect(()=>{ee.current!==s&&(ee.current=s,D())},[s,D]);const fe=G=>{const je=++Y.current;window.electronAPI.memory.detail(G).then(be=>{te.current&&je===Y.current&&H(be)})},xe=()=>{Y.current++,H(null)},Ls=async(G,je)=>{_(!0);try{for(const be of G)await je(be)}finally{te.current&&(_(!1),V(new Set),Q.current())}},ds=()=>{Ls(X,G=>window.electronAPI.memory.archive(G))},vs=(G,je)=>{G.length!==0&&(_(!0),(async()=>{try{for(const be of G)await window.electronAPI.memory.evolvesReview(be,je)}finally{te.current&&(_(!1),De(new Set),Q.current())}})())},He=G=>{te.current&&(V(new Set),z&&G.includes(z.id)&&xe(),Q.current())},zs=G=>{te.current&&(U?.reopen&&fe(G),Q.current())},ge=G=>{G.then(()=>{te.current&&(xe(),Q.current())})},as=n.trim()!==""||r!==Fe||i!==Fe||u!==Fe||h===!0,rs=[{value:Fe,label:t("All space types")},...tr.filter(G=>C.some(je=>je.kind===G)).map(G=>({value:G,label:t(Ih[G])}))],_s=[{value:Fe,label:t("All spaces")},...C.filter(G=>r===Fe||G.kind===r).map(G=>({value:G.id,label:G.label}))],os=[{value:Fe,label:t("All types")},...Nc.map(G=>({value:G,label:G}))],Fs=[{value:"exact",label:t("Exact match")},{value:"fast",label:t("Fast retrieval")},{value:"deep",label:t("Deep retrieval")}];return e.jsxs("div",{className:"space-y-4","data-settings-row":"memory.library",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium",children:t("Stored memories")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Everything the agent has saved. Archiving hides a memory from search but keeps it.")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(ho,{className:"w-full sm:w-96","data-size":"sm",children:[e.jsx(po,{value:n,placeholder:t("Search memories"),onChange:G=>{j(0),a(G.target.value)}}),e.jsx(fo,{align:"inline-end",className:"pe-1",children:e.jsxs(ne,{value:b,items:Fs,onValueChange:G=>{j(0),A(G==="deep"?"deep":G==="fast"?"fast":"exact")},children:[e.jsx(ae,{size:"sm",className:"w-auto min-w-0 gap-1 border-0 bg-transparent px-2 shadow-none before:hidden",children:e.jsx(re,{})}),e.jsx(oe,{children:Fs.map(G=>e.jsx(Z,{value:G.value,children:G.label},G.value))})]})})]}),e.jsxs(ne,{value:r,items:rs,onValueChange:G=>{j(0),o(String(G)),m(Fe)},children:[e.jsx(ae,{size:"sm",className:"w-36","data-memory-filter":"space-kind",children:e.jsx(re,{})}),e.jsx(oe,{children:rs.map(G=>e.jsx(Z,{value:G.value,children:G.label},G.value))})]}),e.jsxs(ne,{value:i,items:_s,onValueChange:G=>{j(0),m(String(G))},children:[e.jsx(ae,{size:"sm",className:"w-36","data-memory-filter":"space",children:e.jsx(re,{})}),e.jsx(oe,{children:_s.map(G=>e.jsx(Z,{value:G.value,children:G.label},G.value))})]}),e.jsxs(ne,{value:u,items:os,onValueChange:G=>{j(0),x(String(G))},children:[e.jsx(ae,{size:"sm",className:"w-36",children:e.jsx(re,{})}),e.jsx(oe,{children:os.map(G=>e.jsx(Z,{value:G.value,children:G.label},G.value))})]}),b==="exact"&&e.jsxs("label",{className:"flex items-center gap-2 text-muted-foreground text-sm",children:[e.jsx(ce,{checked:h,onCheckedChange:G=>{j(0),c(G===!0)}}),t("Show archived")]}),b==="exact"&&e.jsxs("label",{className:"flex items-center gap-2 text-muted-foreground text-sm",children:[e.jsx(ce,{checked:f,onCheckedChange:G=>{j(0),d(G===!0)}}),t("Archive candidates only")]})]}),hn(b)&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:[t(b==="deep"?"Same recall as Fast, plus intent-weighted fusion and an optional short-timeout LLM rerank. Failures fall back; archived memories are excluded.":"Same path the agent uses: full-text, vectors and entities merged by relevance. Shows the top matches only — no exact count, and archived memories are excluded."),!I&&` ${t("Embedding model is not ready, so vectors are skipped.")}`]}),X.size>0&&e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border bg-accent/30 px-3 py-2",children:[e.jsx("span",{className:"text-sm",children:t("{{count}} selected",{count:String(X.size)})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(y,{variant:"ghost",size:"sm",disabled:le,onClick:()=>V(new Set),children:t("Clear selection")}),e.jsx(y,{variant:"outline",size:"sm",disabled:le,onClick:()=>ds(),children:t("Archive selected")}),e.jsx(y,{variant:"destructive-outline",size:"sm",disabled:le,onClick:()=>F([...X]),children:t("Delete permanently")})]})]}),e.jsx(Th,{items:$,onOpen:fe,onEdit:G=>B({id:G,reopen:!1}),onDelete:G=>F([G]),t,selected:X,emptyLabel:{"needs-query":t("Type a query to search by meaning."),"library-empty":t("No memories yet. They appear here once the agent stores something."),"no-match":t("No memories match these filters.")}[Ph(b,n,q,as)],onToggle:G=>{const je=new Set(X);je.delete(G)||je.add(G),V(je)}}),!v&&L>Ss&&e.jsxs("div",{className:"flex items-center justify-between text-xs text-muted-foreground",children:[e.jsx(y,{variant:"outline",size:"sm",disabled:p===0,onClick:()=>j(Math.max(0,p-Ss)),children:t("Previous")}),e.jsxs("span",{children:[p+1,"–",Math.min(p+Ss,L)," / ",L]}),e.jsx(y,{variant:"outline",size:"sm",disabled:p+Ss>=L,onClick:()=>j(p+Ss),children:t("Next")})]}),e.jsx(Bh,{t}),e.jsx(_h,{items:de,selected:O,onToggle:G=>{const je=new Set(O);je.delete(G)||je.add(G),De(je)},onToggleAll:G=>De(G?new Set(de.map(je=>je.edge.id)):new Set),onOpen:fe,onReview:vs,t}),e.jsx(ye,{open:z!==null,onOpenChange:G=>!G&&xe(),children:e.jsx(we,{finalFocus:kc,children:z&&e.jsxs(e.Fragment,{children:[e.jsxs(Ne,{children:[e.jsx(ke,{children:z.title}),e.jsx(Ye,{children:[z.unitType,z.spaceLabel].join(" · ")})]}),e.jsxs(Ce,{className:"space-y-4","data-memory-detail":z.id,children:[e.jsx("p",{className:"whitespace-pre-wrap text-sm","data-memory-field":"content",children:z.content}),e.jsxs("dl",{className:"grid grid-cols-2 gap-x-4 gap-y-3",children:[e.jsx($s,{label:t("Importance"),value:z.importance.toFixed(2)}),e.jsx($s,{label:t("Recorded at"),value:Os(z.createdAt)}),z.updatedAt!==z.createdAt&&e.jsx($s,{label:t("Updated at"),value:Os(z.updatedAt)}),e.jsx($s,{label:t("Embedding"),value:z.embeddingModel??t("Not vectorized")}),z.eventStart&&e.jsx($s,{label:t("Event date"),value:`${z.eventStart}${z.eventEnd?` → ${z.eventEnd}`:""}`})]}),z.entityNames.length>0&&e.jsxs("section",{className:"space-y-1.5",children:[e.jsx("p",{className:"font-medium text-xs",children:t("Entities")}),e.jsx("div",{className:"flex flex-wrap gap-1",children:z.entityNames.map(G=>e.jsx(se,{variant:"secondary",children:G},G))})]}),z.crystalSources.length>0&&e.jsxs("section",{className:"space-y-1.5",children:[e.jsx("p",{className:"font-medium text-xs",children:t("Synthesized from")}),e.jsx("ul",{className:"divide-y rounded-lg border",children:z.crystalSources.map(G=>e.jsxs("li",{className:"flex items-center justify-between gap-2 px-3 py-2",children:[e.jsx("span",{className:"truncate text-sm",children:G.title}),e.jsxs("span",{className:"shrink-0 text-muted-foreground text-xs",children:[(G.contributionWeight*100).toFixed(0),"%"]})]},G.id))})]}),z.evolves.length>0&&e.jsxs("section",{className:"space-y-1.5",children:[e.jsx("p",{className:"font-medium text-xs",children:t("Related versions")}),e.jsx("ul",{className:"divide-y rounded-lg border",children:z.evolves.map(G=>e.jsxs("li",{className:"flex items-center gap-2 px-3 py-2",children:[e.jsx(se,{variant:"outline",children:G.relation}),e.jsx("span",{className:"text-muted-foreground text-xs",children:G.reviewState})]},G.id))})]})]}),e.jsxs(Ee,{children:[e.jsx(y,{variant:"destructive-outline",size:"sm",className:"sm:me-auto","data-memory-action":"delete",onClick:()=>F([z.id]),children:t("Delete permanently")}),e.jsx(y,{variant:"outline",size:"sm","data-memory-action":"edit",onClick:()=>{xe(),B({id:z.id,reopen:!0})},children:t("Edit")}),z.lifecycleState==="archived"?e.jsx(y,{variant:"outline",size:"sm",onClick:()=>ge(window.electronAPI.memory.restore(z.id)),children:t("Restore")}):e.jsx(y,{variant:"outline",size:"sm",onClick:()=>ge(window.electronAPI.memory.archive(z.id)),children:t("Archive")})]})]})})}),e.jsx(Cc,{memoryId:U?.id??null,onClose:()=>B(null),onSaved:zs}),e.jsx(Sc,{ids:ie,onClose:()=>F(null),onDeleted:He})]})}function $s({label:s,value:t}){return e.jsxs("div",{className:"min-w-0",children:[e.jsx("dt",{className:"text-muted-foreground text-xs",children:s}),e.jsx("dd",{className:"truncate text-sm",children:t})]})}const Xo="openai-compatible",$h=/embed|bge|m3e|voyage|jina|nomic|mxbai|stella|conan|acge|retriev|text-(?:similarity|search)|(?:^|[^a-z0-9])(?:e5|gte|bce)(?:[^a-z0-9]|$)/i;function Qo(s){return $h.test(s)}function Un(s){return Array.isArray(s.models)?s.models.filter(t=>typeof t?.id=="string"&&Qo(t.id)):[]}function Vh(s){return s.flatMap(t=>{if(!t.apiKey||typeof t.baseUrl!="string"||!t.baseUrl.trim())return[];const n=Un(t);return n.length>0?[{...t,models:n}]:[]})}function Gh(s){const t=[];for(const n of s){const a=!!n.apiKey,r=typeof n.baseUrl=="string"&&!!n.baseUrl.trim();if(!a&&!r)continue;let o=null;a?r?Un(n).length===0&&(o="no-embedding-models"):o="no-base-url":o="no-api-key",o&&t.push({providerId:n.id,name:n.name,reason:o})}return t}const Kh={"no-api-key":"{{name}}: missing API key","no-base-url":"{{name}}: missing Base URL","no-embedding-models":"{{name}}: no matching embedding model (model names must contain keywords like embed/voyage/bge)"};function Wh(s,t,n){return n(Kh[s],{name:t})}function Hh(s){const{providerId:t,provider:n,modelId:a}=s;return t?n?n.apiKey?typeof n.baseUrl!="string"||!n.baseUrl.trim()?"no-base-url":!a||a===Xo?"no-model":Qo(a)?null:Un(n).length>0?"not-embedding-model":"no-embedding-models":"no-api-key":"provider-missing":"no-provider"}const qh={"no-provider":"No remote embedding provider is selected. Choose a provider with an API key, or switch to a local embedding model.","provider-missing":"The selected embedding provider no longer exists. Choose another provider, or switch to a local embedding model.","no-base-url":'Provider "{{provider}}" has no Base URL. Fill it in, or choose another provider.',"no-api-key":'Provider "{{provider}}" has no API key. Subscription sign-in cannot be used for embeddings; choose a provider with an API key, or switch to a local embedding model.',"no-model":"No remote embedding model is selected. Choose a model that supports /embeddings.","not-embedding-model":'"{{model}}" is a chat model and cannot be used for embeddings. Choose a model that supports /embeddings, or switch to a local embedding model.',"no-embedding-models":'Provider "{{provider}}" has no embedding model ("{{model}}" is a chat model). Add one that supports /embeddings (e.g. text-embedding-3-small), or switch to a local embedding model.'},Yh="No model can be used for embeddings: it needs a provider with an API key and an embedding model (e.g. text-embedding-3-small). Subscription sign-in cannot be used for embeddings.";function Jh(s,t,n){return n(qh[s],{provider:t.provider??"",model:t.model??""})}const ar=s=>s.slice(0,8);function Vt(s,t){return s==="pending"||s==="running"?"running":s==="cancelled"?"cancelled":t?"failed":"done"}const Xh={low_importance:"importance too low",candidates_found:"similar memory already exists",deduplicated:"identical to an existing memory",rejected:"rejected"};function Qh(s){const t=[];for(const r of s.distill){const o=Vt(r.status,r.error);t.push({key:`distill:${r.id}`,kind:"distill",target:r.sessionTitle||ar(r.sessionId),state:o,detail:o==="failed"?r.error??"":o==="cancelled"?"superseded":o==="running"?r.attempts>1?`retry ${r.attempts}`:"queued":`${r.done} stored`,notes:(r.notes??[]).map(i=>[i.title,Xh[i.kind]??i.kind].filter(Boolean).join(" — ")),updatedAt:r.updatedAt})}for(const r of s.kg){const o=Vt(r.status,r.error);t.push({key:`kg:${r.id}`,kind:"kg",target:r.memoryTitle||ar(r.memoryId),state:o,detail:o==="failed"?r.error??"":o==="cancelled"?"memory changed":o==="running"?"extracting":`${r.total} entities · ${r.done} links`,notes:[],updatedAt:r.updatedAt})}const n=s.reembed;if(n){const r=Vt(n.status,n.error);t.push({key:`reembed:${n.id}`,kind:"reembed",target:n.target,state:r,detail:r==="failed"?n.error??"":r==="running"?`${n.done}/${n.total}`:`${n.done} vectorized${n.failed>0?` · ${n.failed} failed`:""}`,notes:[],updatedAt:n.updatedAt})}const a=r=>r.state==="running"?0:r.state==="failed"?1:2;return t.sort((r,o)=>a(r)-a(o)||o.updatedAt.localeCompare(r.updatedAt))}const qs=`remote:${Xo}`,bt="remote:";function rr(s){return s.id==="none"?"None (full-text only)":s.id.replace(/^(local|remote):/,"")}function At(s){return s.startsWith(bt)&&s.length>bt.length}function Zh(s){return At(s)?qs:s}function ep(s){return!At(s)||s===qs?null:s.slice(bt.length)}function sp(s){return`${bt}${s}`}function tp(s,t){return t===qs?At(s)?s:qs:t}const np=4e3,ap=800,or=6,rp={distill:"job:distill",kg:"job:entities",reembed:"job:vectors"},ir={distill:[],kg:[],reembed:null,kgFailed:0};function op(s){return s.some(t=>t.distilled)}function lr(s){return!s||s.total===0||s.embedded>=s.total?null:s.embeddingError??null}function cr(s){return s?.downloadable&&(s.state==="missing"||s.state==="downloading")?s.state:null}function ip(s,t){if(s.done===0||s.done>=s.total)return null;const n=(t-s.startedAt)/s.done;return Math.round(n*(s.total-s.done))}function lp(s){const t=Math.max(1,Math.round(s/1e3));if(t<60)return`${t}s`;const n=Math.floor(t/60);return t%60===0?`${n}m`:`${n}m ${t%60}s`}function cp(s){const t=new Map;for(const a of s){const r=a.projectId??"",o=t.get(r);if(o){o.sessions.push(a);continue}t.set(r,{key:r,name:a.projectName??"No project",sessions:[a]})}const n=[...t.values()];return[...n.filter(a=>a.key),...n.filter(a=>!a.key)]}function me(s){if(s<=0)return"0 B";const t=["B","KB","MB","GB"],n=Math.min(Math.floor(Math.log(s)/Math.log(1024)),t.length-1);return`${(s/1024**n).toFixed(n===0?0:1)} ${t[n]}`}function Gt(s,t,n){return(s.includes(t)?[...s]:[...s,t].sort((r,o)=>r-o)).map(r=>({value:String(r),label:n(r)}))}function Is({title:s,description:t,checked:n,onChange:a,rowId:r,disabled:o}){return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5","data-settings-row":r,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t})]}),e.jsx(ce,{checked:n,disabled:o,onCheckedChange:i=>a(i===!0)})]})}function Kt({title:s,description:t,value:n,items:a,onChange:r,rowId:o,disabled:i}){return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5","data-settings-row":o,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t})]}),e.jsxs(ne,{value:n,items:a,onValueChange:m=>r(String(m)),disabled:i,children:[e.jsx(ae,{className:"w-40 shrink-0",children:e.jsx(re,{})}),e.jsx(oe,{children:a.map(m=>e.jsx(Z,{value:m.value,children:m.label},m.value))})]})]})}function dp({onLibraryChanged:s}={}){const{t}=R(),n=g(w=>w.disabledBuiltinTools),a=g(w=>w.memoryEmbeddingModel),r=g(w=>w.setMemoryEmbeddingModel),o=g(w=>w.memoryEmbeddingAutoDownload),i=g(w=>w.setMemoryEmbeddingAutoDownload),m=g(w=>w.memoryModelIdleMinutes),u=g(w=>w.setMemoryModelIdleMinutes),x=g(w=>w.memoryEmbeddingRemoteProviderId),h=g(w=>w.setMemoryEmbeddingRemoteProviderId),c=g(w=>w.providers),f=g(w=>w.memoryDistillEnabled),d=g(w=>w.setMemoryDistillEnabled),p=g(w=>w.memoryKgEnabled),j=g(w=>w.setMemoryKgEnabled),b=g(w=>w.memoryDecayEnabled),A=g(w=>w.setMemoryDecayEnabled),v=g(w=>w.memoryDecayArchiveCandidates),k=g(w=>w.setMemoryDecayArchiveCandidates),I=g(w=>w.memoryDecayAutoArchive),M=g(w=>w.setMemoryDecayAutoArchive),$=g(w=>w.memoryDecayStaleDays),E=g(w=>w.setMemoryDecayStaleDays),L=g(w=>w.memoryDecayMaxImportance),T=g(w=>w.setMemoryDecayMaxImportance),C=g(w=>w.memoryDecayIntervalDays),S=g(w=>w.setMemoryDecayIntervalDays),W=g(w=>w.memoryDistillModel),q=g(w=>w.setMemoryDistillModel),N=g(w=>w.memoryChatModel)||"remote",z=g(w=>w.setMemoryChatModel),H=g(w=>w.memoryLanguage),U=g(w=>w.setMemoryLanguage),B=es(),ie=W?B.find(w=>w.id===W.providerId):void 0,F=ie?.models.find(w=>w.id===W?.modelId),X=ep(a),V=l.useMemo(()=>Vh(B),[B]),le=l.useMemo(()=>Gh(B),[B]),_=x?V.find(w=>w.id===x):void 0,de=_?.models.find(w=>w.id===X),ue=x?c.find(w=>w.id===x):void 0,O=Hh({providerId:x,provider:ue,modelId:X}),De=O&&O!=="no-provider"&&O!=="no-model"?Jh(O,{provider:ue?.name||x||"",model:X??""},t):null,te=!n.includes("memory"),[P,Y]=l.useState(null),[D,Q]=l.useState(ir),[ee,fe]=l.useState([]),[xe,Ls]=l.useState(null),[ds,vs]=l.useState([]),[He,zs]=l.useState(null),[ge,as]=l.useState([]),[rs,_s]=l.useState(null),[os,Fs]=l.useState(null),[G,je]=l.useState(null),[be,Ae]=l.useState(null),[qe,Vn]=l.useState(!1),[Et,pi]=l.useState(!1),[Be,Gn]=l.useState(null),[bs,Mt]=l.useState(new Set),[st,tt]=l.useState(null),Pt=P?.forgetting??null,Bs=Pt?.lastRun??null,fi=Bs?t("Last run {{date}}: {{scored}} scored, {{candidates}} candidates, {{archived}} archived",{date:Os(Bs.ranAt),scored:String(Bs.scored),candidates:String(Bs.candidates),archived:String(Bs.archived)}):t("Never run yet"),Kn=l.useRef(!1);Kn.current=qe;const ys=l.useRef(null),Tt=l.useCallback(()=>{window.electronAPI.memory.distillableSessions().then(as)},[]);l.useEffect(()=>{te&&Tt()},[te,Tt]);const ws=l.useCallback(()=>{window.electronAPI.memory.models().then(fe)},[]);l.useEffect(()=>(ws(),window.electronAPI.memory.onModelProgress(w=>{Ls(w.done?null:w),w.done&&ws()})),[ws]);const Ns=l.useCallback(()=>{window.electronAPI.memory.chatModels().then(w=>vs(w.filter(ve=>!ve.purpose)))},[]);l.useEffect(()=>(Ns(),window.electronAPI.memory.onChatModelProgress(w=>{zs(w.done?null:w),w.done&&Ns()})),[Ns]),l.useEffect(()=>{if(!te){Y(null),Q(ir);return}let w=!1;const ve=()=>{window.electronAPI.memory.stats().then(is=>{w||Y(is)}),window.electronAPI.memory.jobs().then(is=>{w||(Q(is),Kn.current&&is.reembed?.status!=="running"&&Vn(!1))})};ys.current=ve,ve();const Ue=window.electronAPI.memory.onChanged(ve),Us=window.setInterval(ve,qe?ap:np);return()=>{w=!0,ys.current=null,Ue(),window.clearInterval(Us)}},[te,qe]);const Wn=cp(ge),Hn=ge.filter(w=>!w.distilled),gi=()=>{tt("run"),window.electronAPI.memory.runForgetting().then(()=>{tt(null),ys.current?.()})},qn=()=>{window.electronAPI.memory.archiveCandidates({limit:200,offset:0}).then(w=>{Gn(w),Mt(new Set)})},ji=()=>{const w=[...bs];w.length!==0&&(tt("archive"),window.electronAPI.memory.confirmArchiveCandidates(w).then(()=>{tt(null),qn(),ys.current?.(),s?.()}))},Yn=(w,ve,Ue)=>{const Us=w.filter(is=>!is.distilled);if(!op(w)){nt(w,ve);return}Ae({token:ve,label:Ue,scope:w,pending:Us})},nt=async(w,ve,Ue=!1)=>{const Us=ds.find(Cs=>Cs.id===N)??null;if(cr(Us))return;_s(ve);const is=Date.now();je({done:0,total:w.length,startedAt:is});try{for(let Cs=0;Cs<w.length;Cs++)await window.electronAPI.memory.distillSession(w[Cs].sessionId,Ue),je({done:Cs+1,total:w.length,startedAt:is})}finally{_s(null),je(null),Tt(),s?.()}},Se=ee.find(w=>w.id===a)??null,_e=ds.find(w=>w.id===N)??null,ps=cr(_e),Jn=ds.map(w=>({value:w.id,label:w.id==="remote"?t("Remote (API model)"):w.label})),Xn=[...ee.map(w=>({value:w.id,label:rr(w)})),{value:qs,label:t("Remote (OpenAI-compatible)")}],Qn=Tc.map(w=>({value:String(w),label:w===0?t("Never"):t("{{count}} min",{count:w})})),Zn=[{value:"en",label:t("English")},{value:"zh",label:t("Simplified Chinese")},{value:"auto",label:t("Follow conversation")}],at=At(a)||Se?.runtime==="openai-compatible",ks=l.useMemo(()=>Qh(D),[D]);return e.jsxs("div",{className:"space-y-6","data-settings-row":"memory.root",children:[e.jsxs("section",{className:"space-y-2",children:[e.jsx("h2",{className:"text-base font-medium",children:t("Memory")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("Durable knowledge the agent can search and write across sessions. Stored locally in a SQLite database.")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Turn memory off in Built-in tools.")})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5","data-settings-row":"memory.modelIdleMinutes",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Unload automatically when idle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Release local model memory after this idle period. Models load automatically the next time they are needed.")})]}),e.jsxs(ne,{value:String(m),items:Qn,onValueChange:w=>{w!==null&&u(Number(w))},disabled:!te,children:[e.jsx(ae,{className:"w-56 shrink-0","aria-label":t("Unload automatically when idle"),children:e.jsx(re,{})}),e.jsx(oe,{children:Qn.map(w=>e.jsx(Z,{value:w.value,children:w.label},w.value))})]})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium",children:t("Embedding model")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Used for semantic search and near-duplicate detection. Without it search still works using full-text only.")}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5","data-settings-row":"memory.embeddingModel",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:Se?rr(Se):X??(at?t("Remote (OpenAI-compatible)"):a)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:Se?[Se.dim?`${Se.dim}d`:null,Se.downloadable?me(Se.approxBytes):null,Se.runtime].filter(Boolean).join(" · "):at?"openai-compatible":t("Unknown model; the default is used instead.")})]}),e.jsxs(ne,{value:Zh(a),items:Xn,onValueChange:w=>{w!==null&&r(tp(a,String(w)))},disabled:!te,children:[e.jsx(ae,{className:"w-56",children:e.jsx(re,{})}),e.jsx(oe,{children:Xn.map(w=>e.jsx(Z,{value:w.value,children:w.label},w.value))})]})]}),Se?.downloadable&&e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5","data-settings-row":"memory.download",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:Se.state==="ready"?t("Model downloaded"):Se.state==="downloading"?t("Downloading…"):t("Model not downloaded")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:xe&&xe.modelId===Se.id?`${xe.file} · ${me(xe.received)}${xe.total?` / ${me(xe.total)}`:""} (${xe.fileIndex+1}/${xe.fileCount})`:Se.state==="ready"?me(Se.downloadedBytes):t("Semantic search stays off until the model is on disk.")})]}),e.jsx("div",{className:"flex shrink-0 gap-2",children:Se.state==="downloading"?e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.memory.cancelModelDownload(Se.id).then(ws)},children:t("Cancel")}):Se.state==="ready"?e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.memory.deleteModel(Se.id).then(ws)},children:t("Remove")}):e.jsx(y,{size:"sm",disabled:!te,onClick:()=>{window.electronAPI.memory.downloadModel(Se.id).then(ws)},children:t("Download")})})]}),at&&e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5","data-settings-row":"memory.remoteModel",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Remote model")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Credentials stay in the main process and are never sent to the renderer.")})]}),V.length>0?e.jsx("div",{className:"w-56 shrink-0",children:e.jsx(ze,{providers:V,providerId:_?.id??x??"",modelId:de?.id??X??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:t("Select model"),side:"bottom",triggerClassName:Qe,onSelect:(w,ve)=>{h(w),r(sp(ve))},onReasoningChange:()=>{},onThinkingChange:()=>{}})}):e.jsxs("div",{className:"w-56 shrink-0 space-y-1",children:[e.jsx("p",{className:"text-xs text-destructive",children:t(Yh)}),le.map(w=>e.jsx("p",{className:"text-xs text-muted-foreground",children:Wh(w.reason,w.name,t)},w.providerId))]})]}),at&&De&&e.jsx("p",{className:"text-xs text-destructive","data-settings-row":"memory.remoteModelIssue",children:De}),e.jsx(Is,{rowId:"memory.autoDownload",title:t("Download models automatically"),description:t("Off by default, so a model is only fetched when you press Download. While a model is missing, search degrades to full-text; existing memories are re-embedded once it arrives."),checked:o,onChange:i,disabled:!te})]}),e.jsxs("section",{className:"space-y-2","data-settings-row":"memory.distillModel",children:[e.jsx("h3",{className:"text-sm font-medium",children:t("Distillation")}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Completion backend")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Local GGUF runs on this machine. Remote uses the model below.")})]}),e.jsxs(ne,{value:N,items:Jn,onValueChange:w=>z(String(w)),disabled:!te,children:[e.jsx(ae,{className:"w-56",children:e.jsx(re,{})}),e.jsx(oe,{children:Jn.map(w=>e.jsx(Z,{value:w.value,children:w.label},w.value))})]})]}),_e?.downloadable&&e.jsxs("div",{className:K("flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5",ps==="missing"&&"border-destructive/50"),children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:_e.state==="ready"?t("Model downloaded"):_e.state==="downloading"?t("Downloading…"):t("Model not downloaded")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:He&&He.modelId===_e.id?`${He.file} · ${me(He.received)}${He.total?` / ${me(He.total)}`:""}`:_e.state==="ready"?me(_e.downloadedBytes):me(_e.approxBytes)})]}),e.jsx("div",{className:"flex shrink-0 gap-2",children:_e.state==="downloading"?e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.memory.cancelChatModelDownload(_e.id).then(Ns)},children:t("Cancel")}):_e.state==="ready"?e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.memory.deleteChatModel(_e.id).then(Ns)},children:t("Remove")}):e.jsx(y,{size:"sm",disabled:!te,onClick:()=>{window.electronAPI.memory.downloadChatModel(_e.id).then(Ns)},children:t("Download")})})]}),ps==="missing"&&e.jsx("p",{className:"text-xs text-destructive",children:t("Local model selected but the weights are not on disk. Distillation and interpretation will wait until you click Download.")}),ps==="downloading"&&e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Download in progress. Distillation waits until the model is ready.")}),N==="remote"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Distillation model")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Reads finished sessions and writes the memories.")})]}),B.length>0&&e.jsx("div",{className:"w-56 shrink-0",children:e.jsx(ze,{providers:B,providerId:ie?.id??"",modelId:F?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:t("Follows the title-summary model"),side:"bottom",triggerClassName:Qe,onSelect:(w,ve)=>q({providerId:w,modelId:ve}),onReasoningChange:()=>{},onThinkingChange:()=>{}})})]}),W&&e.jsx(y,{variant:"ghost",size:"sm",onClick:()=>q(null),children:t("Follows the title-summary model")})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5","data-settings-row":"memory.language",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Memory language")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("English keeps retrieval and near-duplicate detection stable across languages. Choose Follow conversation if your team only works in one language.")})]}),e.jsxs(ne,{value:H,items:Zn,onValueChange:w=>U(String(w)),disabled:!te,children:[e.jsx(ae,{className:"w-56",children:e.jsx(re,{})}),e.jsx(oe,{children:Zn.map(w=>e.jsx(Z,{value:w.value,children:w.label},w.value))})]})]})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium",children:t("Background processing")}),e.jsx(Is,{rowId:"memory.distill",title:t("Distill sessions automatically"),description:t("When a session ends, or goes idle for 30 minutes and is reclaimed, extract 1-3 durable memories from it in the background."),checked:f,onChange:d,disabled:!te}),f&&ps&&e.jsx("p",{className:"text-xs text-destructive",children:t("Automatic distillation is on, but the local model is not ready. Sessions will queue until you download it.")}),e.jsx(Is,{rowId:"memory.kg",title:t("Extract entities"),description:t("Build an entity graph so a memory can be recalled by a name it does not literally contain."),checked:p,onChange:j,disabled:!te})]}),e.jsxs("section",{className:"space-y-2","data-settings-row":"memory.forgetting",children:[e.jsx("h3",{className:"text-sm font-medium",children:t("Forgetting")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Decay only changes how search ranks a memory. Archiving keeps it and can be undone; nothing on this page ever deletes a memory.")}),e.jsx(Is,{rowId:"memory.decay",title:t("Rank lower when never retrieved"),description:t("Memories that have not been retrieved for a long time rank lower. This changes ranking only — nothing is archived or deleted."),checked:b,onChange:A,disabled:!te}),e.jsx(Is,{rowId:"memory.decayCandidates",title:t("Mark archive candidates"),description:t("Mark cold, low-importance memories as candidates and show them in the library. Marking alone changes nothing."),checked:v,onChange:k,disabled:!te||!b}),e.jsx(Is,{rowId:"memory.decayAutoArchive",title:t("Archive candidates automatically"),description:t("Archive candidates at the end of each run. Archived memories are hidden from search but kept and can be restored."),checked:I,onChange:M,disabled:!te||!b||!v}),b&&e.jsxs(e.Fragment,{children:[e.jsx(Kt,{rowId:"memory.decayStaleDays",title:t("Not retrieved for"),description:t("Counted from the last retrieval; a memory that was never retrieved counts from creation."),value:String($),items:Gt(Rc,$,w=>t("{{count}} days",{count:String(w)})),onChange:w=>E(Number(w)),disabled:!te}),e.jsx(Kt,{rowId:"memory.decayMaxImportance",title:t("Importance at most"),description:t("Only memories at or below this importance can become candidates. 0.5 is the lowest tier distillation writes."),value:String(L),items:Gt(Oc,L,w=>w.toFixed(2)),onChange:w=>T(Number(w)),disabled:!te}),e.jsx(Kt,{rowId:"memory.decayInterval",title:t("Run every"),description:t("Checked when the library opens; there is no separate background timer."),value:String(C),items:Gt(Dc,C,w=>t("{{count}} days",{count:String(w)})),onChange:w=>S(Number(w)),disabled:!te})]}),b&&e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 rounded-lg border px-3 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:v||I?t("Archive candidates: {{count}}",{count:String(Pt?.candidates??0)}):t("Archive candidates: marking is off")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:fi})]}),e.jsxs("div",{className:"flex shrink-0 gap-2",children:[e.jsx(y,{size:"sm",variant:"outline",disabled:st!==null||!te,onClick:gi,children:t(st==="run"?"Running…":"Run now")}),e.jsx(y,{size:"sm",variant:"outline",disabled:!v||(Pt?.candidates??0)===0,onClick:qn,children:t("Review candidates")})]})]})]}),e.jsxs("section",{className:"space-y-2","data-settings-row":"memory.stats",children:[e.jsx("h3",{className:"text-sm font-medium",children:t("Library")}),P===null||P.total===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:t("No memories stored yet.")}):e.jsxs(e.Fragment,{children:[lr(P)&&e.jsx("p",{className:"text-xs text-destructive",children:t("Vectors unavailable: {{reason}}",{reason:lr(P)??""})}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-3",children:[e.jsx(ms,{label:t("Memories"),value:String(P.total)}),e.jsx(ms,{label:t("Crystals"),value:String(P.crystals)}),e.jsx(ms,{label:t("Entities"),value:String(P.entities)}),e.jsx(ms,{label:t("With vectors"),value:`${P.embedded}/${P.total}`,action:P.embedded<P.total?e.jsx("button",{type:"button",disabled:qe,className:"text-xs text-muted-foreground underline-offset-2 hover:underline disabled:opacity-60",onClick:()=>{Vn(!0),window.electronAPI.memory.reembed().then(()=>ys.current?.())},children:t(qe?"Backfilling…":"Backfill")}):null}),e.jsx(ms,{label:t("Database size"),value:me(P.databaseBytes)}),e.jsx(ms,{label:t("Spaces"),value:String(Object.keys(P.bySpace).length)}),e.jsx(ms,{label:t("Never retrieved"),value:`${P.neverHit}/${P.total}`,action:e.jsx("span",{className:"text-muted-foreground text-xs",children:t("{{percent}}% of library",{percent:String(P.total>0?Math.round(P.neverHit/P.total*100):0)})})}),e.jsx(ms,{label:t("Added in 7 days"),value:String(P.addedLast7Days)})]})]})]}),e.jsxs("section",{className:"space-y-2","data-settings-row":"memory.distillSessions",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("h3",{className:"text-sm font-medium",children:t("Distill past sessions")}),Hn.length>0&&e.jsx(y,{size:"sm",variant:"outline",disabled:!te||rs!==null||ps!==null,onClick:()=>Yn(ge,"all",t("All sessions")),children:rs==="all"?t("Distilling…"):t("Distill all ({{count}})",{count:String(Hn.length)})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("The automatic switch only covers sessions that end from now on. Distill earlier sessions here to fill the library.")}),G&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:[t("{{done}}/{{total}} done",{done:String(G.done),total:String(G.total)}),(()=>{const w=ip(G,Date.now());return w===null?"":` · ${t("about {{time}} left",{time:lp(w)})}`})()]}),Wn.length===0?e.jsx("p",{className:"text-muted-foreground text-sm",children:t("No recorded sessions found.")}):e.jsx("ul",{className:"divide-y rounded-lg border",children:Wn.map(w=>{const ve=w.sessions.filter(Ue=>!Ue.distilled);return e.jsxs("li",{className:"flex items-center justify-between gap-3 px-3 py-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-sm",children:w.name}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("{{total}} sessions · {{pending}} not distilled",{total:String(w.sessions.length),pending:String(ve.length)})})]}),e.jsxs("div",{className:"flex shrink-0 gap-2",children:[e.jsx(y,{size:"sm",variant:"ghost",onClick:()=>Fs(w),children:t("View sessions")}),e.jsx(y,{size:"sm",variant:"outline",disabled:!te||rs!==null||w.sessions.length===0||ps!==null,onClick:()=>Yn(w.sessions,w.key,w.name),children:rs===w.key?t("Distilling…"):t("Distill project")})]})]},w.key)})})]}),e.jsx(ye,{open:os!==null,onOpenChange:w=>!w&&Fs(null),children:e.jsx(we,{children:os&&e.jsxs(e.Fragment,{children:[e.jsxs(Ne,{children:[e.jsx(ke,{children:os.name}),e.jsx(Ye,{children:t("{{total}} sessions · {{pending}} not distilled",{total:String(os.sessions.length),pending:String(os.sessions.filter(w=>!w.distilled).length)})})]}),e.jsx(Ce,{children:e.jsx("ul",{className:"divide-y rounded-lg border",children:os.sessions.map(w=>e.jsxs("li",{className:"flex items-center justify-between gap-3 px-3 py-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-sm",children:w.title}),e.jsxs("p",{className:"text-muted-foreground text-xs",children:[w.updatedAt?w.updatedAt.slice(0,10):"",w.distilled?` · ${t("Already distilled")}`:""]})]}),e.jsx(y,{size:"sm",variant:"ghost",className:"shrink-0",disabled:!te||rs!==null||ps!==null,onClick:()=>{nt([w],w.sessionId,w.distilled)},children:rs===w.sessionId?t("Distilling…"):w.distilled?t("Distill again"):t("Distill")})]},w.sessionId))})}),e.jsx(Ee,{children:e.jsx(Hs,{render:e.jsx(y,{variant:"outline",size:"sm"}),children:t("Close")})})]})})}),e.jsx(ye,{open:be!==null,onOpenChange:w=>!w&&Ae(null),children:e.jsx(we,{children:be&&e.jsxs(e.Fragment,{children:[e.jsxs(Ne,{children:[e.jsx(ke,{children:t("Some sessions were already distilled")}),e.jsx(Ye,{children:t("{{label}}: {{total}} sessions, {{done}} already distilled. Re-distilling runs the model again and may add new memories alongside the existing ones.",{label:be.label,total:String(be.scope.length),done:String(be.scope.length-be.pending.length)})})]}),e.jsxs(Ee,{children:[e.jsx(Hs,{render:e.jsx(y,{variant:"ghost",size:"sm"}),children:t("Cancel")}),e.jsx(y,{variant:be.pending.length>0?"default":"outline",size:"sm",disabled:be.pending.length===0,onClick:()=>{const w=be;Ae(null),nt(w.pending,w.token)},children:t("Only the {{count}} remaining",{count:String(be.pending.length)})}),e.jsx(y,{variant:be.pending.length>0?"outline":"default",size:"sm",onClick:()=>{const w=be;Ae(null),nt(w.scope,w.token,!0)},children:t("Re-distill all {{count}}",{count:String(be.scope.length)})})]})]})})}),e.jsxs("section",{className:"space-y-2","data-settings-row":"memory.jobs",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("h3",{className:"font-medium text-sm",children:t("Background tasks")}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[D.kgFailed>0&&e.jsx(y,{size:"sm",variant:"ghost",onClick:()=>{window.electronAPI.memory.retryFailedKgJobs().then(()=>ys.current?.())},children:t("Retry failed extractions ({{count}})",{count:String(D.kgFailed)})}),ks.some(w=>w.state!=="running")&&e.jsx(y,{size:"sm",variant:"ghost",title:t("Removes completed and cancelled jobs. Running tasks are kept. Sessions will show as not distilled again, since that flag is derived from job history — re-distilling is deduplicated, so it will not create duplicate memories."),onClick:()=>{window.electronAPI.memory.clearJobs()},children:t("Clear finished tasks")}),ks.length>or&&e.jsx(y,{size:"sm",variant:"ghost",onClick:()=>pi(!Et),children:Et?t("Show less"):t("Show all {{count}}",{count:String(ks.length)})})]})]}),ks.length===0?e.jsx("p",{className:"text-muted-foreground text-sm",children:t("Nothing running.")}):e.jsx("ul",{className:"divide-y rounded-lg border",children:(Et?ks:ks.slice(0,or)).map(w=>e.jsxs("li",{className:"space-y-1 px-3 py-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(se,{variant:w.state==="failed"?"destructive":"secondary",children:t(rp[w.kind])}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-sm",children:w.target}),e.jsx("span",{className:K("shrink-0 text-xs",w.state==="failed"?"text-destructive":"text-muted-foreground"),children:w.state==="running"?`⋯ ${w.detail}`:w.detail})]}),w.notes.map(ve=>e.jsxs("p",{className:"pl-1 text-muted-foreground text-xs",children:["· ",ve]},ve))]},w.key))})]}),e.jsx(ye,{open:Be!==null,onOpenChange:w=>!w&&Gn(null),children:e.jsxs(we,{children:[e.jsxs(Ne,{children:[e.jsx(ke,{children:t("Archive candidates")}),e.jsx(Ye,{children:t("Cold and low-importance memories. Archiving keeps them, hides them from search, and can be undone from the library.")})]}),e.jsx(Ce,{children:Be&&Be.items.length>0?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:t("{{selected}} of {{total}} selected",{selected:String(bs.size),total:String(Be.items.length)})}),e.jsx(y,{size:"sm",variant:"ghost",onClick:()=>Mt(bs.size===Be.items.length?new Set:new Set(Be.items.map(w=>w.id))),children:bs.size===Be.items.length?t("Clear selection"):t("Select all")})]}),e.jsx("ul",{className:"divide-y rounded-lg border",children:Be.items.map(w=>e.jsxs("li",{className:"flex items-start gap-2 px-3 py-2",children:[e.jsx(Le,{checked:bs.has(w.id),onCheckedChange:()=>Mt(ve=>{const Ue=new Set(ve);return Ue.has(w.id)?Ue.delete(w.id):Ue.add(w.id),Ue}),"aria-label":t("Select memory")}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-sm",children:w.title}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[w.spaceLabel," ·"," ",t("Importance {{value}}",{value:w.importance.toFixed(2)})," ·"," ",w.lastHitAt?t("Last retrieved {{date}}",{date:Os(w.lastHitAt)}):t("Never retrieved")]})]})]},w.id))}),Be.total>Be.items.length&&e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Showing the first {{shown}} of {{total}}.",{shown:String(Be.items.length),total:String(Be.total)})})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:t("No archive candidates right now.")})}),e.jsxs(Ee,{children:[e.jsx(Hs,{render:e.jsx(y,{variant:"outline",size:"sm"}),children:t("Close")}),e.jsx(y,{size:"sm",disabled:bs.size===0||st!==null,onClick:ji,children:t(st==="archive"?"Archiving…":"Archive selected")})]})]})})]})}function ms({label:s,value:t,action:n}){return e.jsxs("div",{className:"rounded-lg border px-3 py-2",children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:s}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-sm",children:t}),n]})]})}function up(s,t){if(t===null)return{ok:!0,value:null};if(s.type==="boolean")return typeof t=="boolean"?{ok:!0,value:t}:t==="true"||t==="false"?{ok:!0,value:t==="true"}:{ok:!1,error:"需要打开或关闭"};if(typeof t!="string")return{ok:!1,error:"值不合法"};if(s.type==="number"){const n=t.trim();if(!/^-?\d+(\.\d+)?$/.test(n))return{ok:!1,error:"需要数字"};const a=Number(n);return Number.isFinite(a)?s.min!==void 0&&a<s.min?{ok:!1,error:"小于最小值"}:s.max!==void 0&&a>s.max?{ok:!1,error:"大于最大值"}:{ok:!0,value:a}:{ok:!1,error:"需要数字"}}return s.type==="enum"?s.options?.includes(t)?{ok:!0,value:t}:{ok:!1,error:"不在可选项里"}:s.type==="model"?go(t)?{ok:!0,value:t}:{ok:!1,error:"不是合法的模型选择"}:t.length>4096||t.includes("\0")?{ok:!1,error:"值不合法"}:{ok:!0,value:t}}const mp={"agent.tool":"运行 Agent 工具","ui.slot":"在界面挂载组件","ui.view":"打开侧栏页面","ui.notify":"发送系统通知","composer.draft":"读写输入框草稿","fs.read":"读取声明的文件","fs.write":"写入声明的文件","net.fetch":"访问声明的域名","mcp.server":"启动声明的 MCP 服务","mcp.call":"调用宿主 MCP 工具","agent.observe":"观察会话事件","agent.intercept":"拦截并改写会话事件","agent.inject":"向会话发送消息,并可触发该会话继续执行;默认只发到发起调用的会话,允许后可发到任意运行中的会话","process.background":"常驻后台并拉起子进程","plugin.call":"调用其他插件","ui.clipboard":"写入剪贴板","ui.openExternal":"用浏览器打开链接","session.read":"查看本项目的会话列表与运行状态(标题、活动时间、是否在等你)","session.readAll":"查看所有项目的会话列表与运行状态","session.focus":"在你点击时切换到本项目的会话","session.create":"在你点击时于本项目新建会话","agent.run":"用当前会话的模型运行只读代理(可读项目文件与对话内容,不能修改)","secretary.contact":"作为秘书的联系方式:收发你与秘书之间的消息(里程碑、提问、确认卡提示)"};function Zo(s){return mp[s]??s}const xp=["themes","agent","productivity","integrations","insights","writing","fun"],$n={themes:"主题外观",agent:"Agent 能力",productivity:"效率工作流",integrations:"外部集成",insights:"观测统计",writing:"写作翻译",fun:"休闲娱乐"};function hp(s){return{installedKey:s,refresh:!0}}function pp(s,t){return s.installedKey===t?s:{installedKey:t,refresh:!1}}function Gs(s){if(!s)return null;try{const t=new URL(s);return t.protocol==="https:"||t.protocol==="http:"?t.href:null}catch{return null}}function fp({pluginId:s,name:t,from:n,homepage:a,onClose:r}){const{t:o}=R();return e.jsx(ye,{open:s!==null,onOpenChange:i=>!i&&r(),children:e.jsxs(we,{children:[e.jsx(Ne,{children:e.jsxs(ke,{children:[o("Usage guide"),t?` · ${t}`:""]})}),e.jsx(Ce,{className:"max-h-[60vh] space-y-3 overflow-y-auto",children:s&&e.jsx(ei,{pluginId:s,from:n,homepage:a})})]})})}function ei({pluginId:s,from:t,homepage:n,showLink:a=!0}){const{t:r}=R(),[o,i]=l.useState(null),[m,u]=l.useState(null),[x,h]=l.useState(Gs(n)),[c,f]=l.useState(null);return l.useEffect(()=>{let d=!0;return xt(()=>import("./globals-1URrQWJU.js").then(p=>p.og),__vite__mapDeps([0,1]),import.meta.url).then(p=>{d&&f(()=>p.Markdown)}),()=>{d=!1}},[]),l.useEffect(()=>{let d=!1;return i(null),u(null),h(Gs(n)),(async()=>{const p=window.electronAPI.extensionPlugins,j=await p.readme({id:s,from:t});let b=j.ok?j.markdown:null,A=j.ok?null:j.error;if(!j.ok&&t==="installed"){const v=await p.readme({id:s,from:"market"});v.ok&&(b=v.markdown,A=null)}if(!Gs(n)){const v=await p.marketList(!1),k=v.ok?v.plugins.find(I=>I.id===s):void 0;d||h(Gs(k?.homepage))}d||(i(b),u(b?null:A))})(),()=>{d=!0}},[s,t,n]),e.jsxs("div",{className:"space-y-3",children:[a&&x&&e.jsx("a",{href:x,target:"_blank",rel:"noreferrer",className:"text-sm underline",children:r("Homepage")}),m&&e.jsx("p",{className:"text-muted-foreground text-sm",children:m}),o===null&&!m&&e.jsx("p",{className:"text-muted-foreground text-sm",children:"…"}),o!==null&&c&&e.jsx(c,{text:o})]})}function si(s,t){return t==="all"?!0:t==="installed"?s.installedVersion!==void 0:t==="updates"?s.updateAvailable:t==="other"?s.category===void 0:s.category===t}function gp(s){const t=r=>s.filter(o=>si(o,r)).length,n=["all","installed","updates"],a=[...xp,"other"];return[...n.map(r=>({id:r,count:t(r)})),...a.map(r=>({id:r,count:t(r)})).filter(r=>r.count>0)]}function jp(s,t){const n=t.query.trim().toLowerCase();return s.filter(a=>si(a,t.section)?n?[a.id,a.name,a.description,...a.tags].some(r=>r.toLowerCase().includes(n)):!0:!1).sort((a,r)=>a.tier!==r.tier?a.tier==="official"?-1:1:a.name.localeCompare(r.name))}const dr={all:"全部",installed:"已安装",updates:"可更新",other:"其他"},vp=s=>s in dr?dr[s]:$n[s];function bp({disabled:s,installedKey:t,onInstall:n,initialQuery:a=""}){const{t:r}=R(),o=window.electronAPI.extensionPlugins,[i,m]=l.useState(null),[u,x]=l.useState(!1),[h,c]=l.useState(a),[f,d]=l.useState("all"),[p,j]=l.useState(null),[b,A]=l.useState(()=>hp(t)),v=pp(b,t);v!==b&&A(v);const k=l.useCallback(async C=>{x(!0);try{m(await o.marketList(C))}catch(S){m({ok:!1,error:S instanceof Error?S.message:String(S),chinaMirror:!1})}finally{x(!1)}},[o]);l.useEffect(()=>{k(b.refresh)},[k,b]);const I=async C=>{await o.setMarketChinaMirror(C),await k(!0)},M=i?.ok===!0?i.plugins:[],$=gp(M),E=$.some(C=>C.id===f)?f:"all",L=jp(M,{query:h,section:E}),T=p?M.find(C=>C.id===p):void 0;return e.jsxs("div",{className:"flex h-[min(72vh,720px)] min-h-0 flex-col gap-3 sm:flex-row sm:gap-4",children:[e.jsx("nav",{"aria-label":"插件分类",className:"flex shrink-0 gap-1 overflow-x-auto pb-1 sm:block sm:w-36 sm:space-y-0.5 sm:overflow-y-auto sm:pb-0",children:$.map(C=>e.jsxs("button",{type:"button","aria-pressed":E===C.id,onClick:()=>{d(C.id),j(null)},className:K("flex shrink-0 items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left text-sm hover:bg-accent sm:w-full",E===C.id&&"bg-accent font-medium"),children:[e.jsx("span",{className:"truncate whitespace-nowrap",children:vp(C.id)}),e.jsx("span",{className:"text-muted-foreground text-xs tabular-nums",children:C.count})]},C.id))}),e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(J,{className:"min-w-40 flex-1",value:h,placeholder:r("Search plugins"),onChange:C=>{c(C.target.value),j(null)}}),e.jsxs("label",{className:"flex shrink-0 items-center gap-1.5 text-muted-foreground text-xs",children:[e.jsx(ce,{checked:i?.chinaMirror??!1,disabled:u,onCheckedChange:C=>{I(C)}}),r("China mirror")]}),e.jsx(y,{size:"sm",variant:"ghost",disabled:u,onClick:()=>{k(!0)},children:u?e.jsx(Ps,{}):r("Refresh")})]}),i?.ok===!1&&e.jsx("p",{className:"text-destructive text-sm",children:i.error}),i?.ok===!0&&i.stale&&e.jsx("p",{className:"text-muted-foreground text-xs",children:r("Could not reach the marketplace; showing the last saved list.")}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto pr-1",children:T?e.jsx(wp,{plugin:T,disabled:s,onBack:()=>j(null),onInstall:n}):i?.ok===!0&&L.length===0?e.jsx("p",{className:"text-muted-foreground text-sm",children:r("No matching plugins")}):e.jsx("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2",children:L.map(C=>e.jsx(yp,{plugin:C,disabled:s,onOpen:()=>j(C.id),onInstall:n},C.id))})})]})]})}function ti({plugin:s,disabled:t,onInstall:n}){const{t:a}=R();return s.installedVersion&&!s.updateAvailable?e.jsx("span",{className:"shrink-0 text-muted-foreground text-xs",children:a("Installed")}):e.jsx(y,{size:"xs",variant:s.updateAvailable?"default":"outline",disabled:t,onClick:r=>{r.stopPropagation(),n(s.id)},children:s.updateAvailable?a("Update"):a("Install")})}function ni({tier:s}){const{t}=R();return e.jsx(se,{variant:s==="official"?"secondary":"outline",className:"text-[11px]",children:t(s==="official"?"Official":"Community")})}function yp({plugin:s,disabled:t,onOpen:n,onInstall:a}){return e.jsxs("div",{role:"button",tabIndex:0,"aria-label":s.name,onClick:n,onKeyDown:r=>{r.target===r.currentTarget&&(r.key==="Enter"||r.key===" ")&&(r.preventDefault(),n())},className:"flex cursor-pointer flex-col gap-2 rounded-lg border p-3 text-left transition-colors hover:bg-accent/50",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(ai,{src:s.icon}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("p",{className:"flex items-center gap-1.5 text-sm",children:[e.jsx("span",{className:"truncate font-medium",children:s.name}),e.jsx(ni,{tier:s.tier})]}),e.jsxs("p",{className:"text-muted-foreground text-xs",children:[s.latest,s.category?` · ${$n[s.category]}`:""]})]}),e.jsx(ti,{plugin:s,disabled:t,onInstall:a})]}),s.description&&e.jsx("p",{className:"line-clamp-2 text-muted-foreground text-xs",children:s.description})]})}function wp({plugin:s,disabled:t,onBack:n,onInstall:a}){const{t:r}=R(),o=Gs(s.homepage);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs(y,{size:"xs",variant:"ghost",onClick:n,children:[e.jsx(jo,{className:"size-3.5"}),"返回"]}),e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(ai,{src:s.icon,large:!0}),e.jsxs("div",{className:"min-w-0 flex-1 space-y-1",children:[e.jsxs("p",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("span",{className:"font-medium text-base",children:s.name}),e.jsx(ni,{tier:s.tier}),s.category&&e.jsx(se,{variant:"outline",className:"text-[11px]",children:$n[s.category]})]}),e.jsxs("p",{className:"font-mono text-muted-foreground text-xs",children:[s.id," · ",s.latest,s.installedVersion?` · 已装 ${s.installedVersion}`:""]}),s.description&&e.jsx("p",{className:"text-sm",children:s.description}),o&&e.jsxs("a",{href:o,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-primary text-xs hover:underline",children:[e.jsx(Lc,{className:"size-3"}),r("Homepage")]})]}),e.jsx(ti,{plugin:s,disabled:t,onInstall:a})]}),s.screenshots&&s.screenshots.length>0&&e.jsx("div",{className:"flex gap-2 overflow-x-auto pb-1",children:s.screenshots.map(i=>e.jsx("img",{src:i.url,alt:i.alt,title:i.alt,loading:"lazy",className:"h-44 shrink-0 rounded-md border object-cover"},i.url))}),e.jsxs("section",{className:"space-y-1",children:[e.jsx("h3",{className:"font-medium text-sm",children:"权限"}),s.permissions.length===0?e.jsx("p",{className:"text-muted-foreground text-xs",children:"无特殊权限"}):e.jsx("ul",{className:"space-y-0.5",children:s.permissions.map(i=>e.jsxs("li",{className:"text-xs",children:[e.jsx("span",{className:"font-mono text-muted-foreground",children:i}),e.jsx("span",{className:"ml-2",children:Zo(i)})]},i))})]}),e.jsxs("section",{className:"space-y-1",children:[e.jsx("h3",{className:"font-medium text-sm",children:r("Usage guide")}),e.jsx(ei,{pluginId:s.id,from:"market",homepage:s.homepage,showLink:!1})]})]})}function ai({src:s,large:t}){const[n,a]=l.useState(!1);return e.jsx("div",{className:K("flex shrink-0 items-center justify-center rounded-md bg-muted",t?"size-12":"size-9"),children:s&&!n?e.jsx("img",{src:s,alt:"",className:t?"size-7 object-contain":"size-5 object-contain",onError:()=>a(!0)}):e.jsx(Xs,{className:"size-4 text-muted-foreground"})})}const ur={session:"跟随当前会话",title:"跟随标题模型",fixed:"指定模型"};function Np({value:s,onChange:t}){const n=es(),a=go(s)??"session",r=typeof a=="string"?a:"fixed",o=typeof a=="string"?null:a,i=o?n.find(u=>u.id===o.providerId):void 0,m=i?.models.find(u=>u.id===o?.modelId);return e.jsxs("div",{className:"space-y-2",children:[e.jsxs(ne,{items:ur,value:r,onValueChange:u=>{if(u==="session"||u==="title")t(u);else if(u==="fixed"&&!o){const x=n[0],h=x?.models[0];x&&h&&t(ba({providerId:x.id,modelId:h.id}))}},children:[e.jsx(ae,{children:e.jsx(re,{})}),e.jsx(oe,{children:Object.entries(ur).map(([u,x])=>e.jsx(Z,{value:u,disabled:u==="fixed"&&n.length===0,children:x},u))})]}),o&&e.jsx(ze,{providers:n,providerId:i?.id??"",modelId:m?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:"选择模型",side:"bottom",triggerClassName:Qe,onSelect:(u,x)=>t(ba({providerId:u,modelId:x})),onReasoningChange:()=>{},onThinkingChange:()=>{}}),o&&!m&&e.jsx("p",{className:"text-destructive text-xs",children:"选中的模型已不可用,运行时会失败,请重新选择。"})]})}function kp(s){const{notice:t,remote:n,onDismiss:a}=s;return e.jsxs("div",{className:"space-y-1 rounded-md border border-amber-500/30 bg-amber-500/5 px-3 py-2 text-amber-700 text-sm dark:text-amber-400",children:[t.unreadable&&e.jsx("p",{children:"插件登记表曾读取失败,下面的列表可能不全。插件文件没有删除,原文保存在数据目录的 extension-plugins/registry.json.unreadable。"}),t.discarded.length>0&&e.jsxs("p",{children:["检测到旧格式的登记记录,已丢弃并清理,请重新安装:",e.jsx("span",{className:"font-mono",children:t.discarded.join(", ")})]}),n?e.jsx("p",{className:"text-muted-foreground",children:"请在桌面端点「知道了」,或运行 enso-server plugin notice-dismiss 清除此提示。"}):e.jsx(y,{size:"sm",variant:"outline",onClick:a,children:"知道了"})]})}function Cp({pluginId:s,plain:t}){const{t:n}=R(),[a,r]=l.useState([]),[o,i]=l.useState({}),[m,u]=l.useState(null),x=l.useCallback(async()=>{const d=await window.electronAPI.extensionPlugins.configGet(s);d.ok?r(d.fields):u({error:!0,text:d.error}),i({})},[s]);l.useEffect(()=>{x()},[x]);const h=async()=>{const d={};for(const[j,b]of Object.entries(o)){const A=a.find(k=>k.key===j);if(!A||A.secret&&b==="")continue;const v=up(A,b);if(!v.ok){u({error:!0,text:`${A.title}:${v.error}`});return}d[j]=v.value}const p=await window.electronAPI.extensionPlugins.configSet(s,d);u(p.ok?{error:!1,text:n("Saved. New calls use it right away.")}:{error:!0,text:p.error??""}),p.ok&&await x()},c=d=>{const p=o[d.key];return typeof p=="string"?p:p===null||d.secret?"":d.value??(d.default!==void 0?String(d.default):"")},f=d=>{const p=o[d.key];return typeof p=="boolean"?p:(d.value??(typeof d.default=="boolean"?String(d.default):"false"))==="true"};return e.jsxs("div",{className:K("space-y-2",t?"":"rounded-md border border-border p-3"),children:[a.map(d=>e.jsxs("div",{className:"space-y-1",children:[e.jsxs("p",{className:"text-sm",children:[d.title,e.jsx("span",{className:"ml-2 font-mono text-muted-foreground text-xs",children:d.key})]}),d.description&&e.jsx("p",{className:"text-muted-foreground text-xs",children:d.description}),d.multiline&&d.type==="string"?e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Xe,{autoComplete:"off",rows:4,value:c(d),placeholder:d.secret&&d.set?n("Set (leave blank to keep)"):n("Not set"),className:"min-w-0 flex-1",onChange:p=>i(j=>({...j,[d.key]:p.target.value}))}),d.set&&e.jsx(y,{size:"sm",variant:"ghost",onClick:()=>i(p=>({...p,[d.key]:null})),children:n("Clear value")})]}):d.secret||d.type==="string"||d.type==="number"||d.type==="path"?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(J,{type:d.secret?"password":d.type==="number"?"number":"text",autoComplete:"off",inputMode:d.type==="number"?"decimal":void 0,min:d.type==="number"?d.min:void 0,max:d.type==="number"?d.max:void 0,value:c(d),placeholder:d.secret&&d.set?n("Set (leave blank to keep)"):n("Not set"),onChange:p=>i(j=>({...j,[d.key]:p.target.value}))}),d.type==="path"&&!d.secret&&!window.electronAPI.remote&&e.jsx(y,{size:"sm",variant:"outline",onClick:()=>{window.electronAPI.extensionPlugins.pickPath(d.pathKind==="directory"?"directory":"file").then(p=>{p.ok&&"path"in p&&i(j=>({...j,[d.key]:p.path}))})},children:d.pathKind==="directory"?"选择文件夹":"选择文件"}),d.set&&e.jsx(y,{size:"sm",variant:"ghost",onClick:()=>i(p=>({...p,[d.key]:null})),children:n("Clear value")})]}):d.type==="boolean"?e.jsx(ce,{checked:f(d),onCheckedChange:p=>i(j=>({...j,[d.key]:p}))}):d.type==="model"?e.jsx(Np,{value:c(d),onChange:p=>i(j=>({...j,[d.key]:p}))}):e.jsxs(ne,{items:Object.fromEntries((d.options??[]).map(p=>[p,p])),value:c(d),onValueChange:p=>{typeof p=="string"&&i(j=>({...j,[d.key]:p}))},children:[e.jsx(ae,{children:e.jsx(re,{placeholder:"请选择"})}),e.jsx(oe,{children:(d.options??[]).map(p=>e.jsx(Z,{value:p,children:p},p))})]})]},d.key)),m&&e.jsx("p",{className:K("text-xs",m.error?"text-destructive":"text-muted-foreground"),children:m.text}),e.jsx(y,{size:"sm",disabled:Object.keys(o).length===0,onClick:()=>{h()},children:n("Save")})]})}function Sp({pluginId:s,plain:t}){const{t:n}=R(),[a,r]=l.useState(null),o=l.useCallback(async()=>{const i=await window.electronAPI.extensionPlugins.logs(s);r(i.ok?i.text:i.error)},[s]);return l.useEffect(()=>{o()},[o]),e.jsxs("div",{className:K("space-y-2",t?"":"rounded-md border border-border p-3"),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-sm",children:n("Plugin logs")}),e.jsx(y,{size:"icon",variant:"ghost","aria-label":n("Refresh"),onClick:()=>{o()},children:e.jsx(ns,{className:"size-4"})})]}),e.jsx("pre",{className:"max-h-64 overflow-auto whitespace-pre-wrap break-all font-mono text-muted-foreground text-xs",children:a===null?"":a||n("No logs yet")})]})}function mr({message:s}){const[t,n]=l.useState(!1);return e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("p",{className:K("select-text break-all font-mono text-destructive text-xs",t?"max-h-48 overflow-auto whitespace-pre-wrap":"line-clamp-2"),children:s}),s.length>120&&e.jsx("button",{type:"button",className:"text-muted-foreground text-xs hover:text-foreground",onClick:()=>n(a=>!a),children:t?"收起":"展开全部"})]})}function ri({permissions:s,styles:t=!1}){return s.length===0?t?null:e.jsx("p",{className:"text-muted-foreground text-xs",children:"无特殊权限"}):e.jsx("ul",{className:"space-y-0.5",children:s.map(n=>e.jsxs("li",{className:"text-xs",children:[e.jsx("span",{className:"font-mono text-muted-foreground",children:n}),e.jsx("span",{className:"ml-2",children:Zo(n)})]},n))})}function Ip(s){const t=s.intervalSeconds>=60&&s.intervalSeconds%60===0?`每 ${s.intervalSeconds/60} 分钟`:`每 ${s.intervalSeconds} 秒`,n=s.lastRunAt?` · 最近 ${new Date(s.lastRunAt).toLocaleString()}`:"";return`${s.id} · ${t}${n}${s.lastError?` · ${s.lastError}`:""}`}function xr(s){return[s.permissions.length>0?`${s.permissions.length} 项权限`:"",(s.events?.length??0)>0?`${s.events?.length} 个事件`:"",(s.schedules?.length??0)>0?`${s.schedules?.length} 个定时任务`:"",s.hasRenderer?"界面代码":"",s.crossSessionInject!==void 0?"跨会话投递开关":""].filter(Boolean).join(" · ")}function hr({permissions:s,env:t,interop:n,resident:a,running:r,styles:o,trustedUi:i,events:m,schedules:u}){return e.jsxs("div",{className:"space-y-1",children:[e.jsx(ri,{permissions:s,styles:o||i}),i&&e.jsx(Ap,{}),a&&e.jsxs("p",{className:"text-xs",children:["常驻进程",r===void 0?"":r?":运行中":":未运行"]}),o&&e.jsx("p",{className:"text-xs",children:"修改界面样式:主题 CSS 可以改变应用的任意界面"}),(t?.length??0)>0&&e.jsxs("p",{className:"text-xs",children:["环境变量:",e.jsx("span",{className:"font-mono",children:t?.join(", ")})]}),(n?.length??0)>0&&e.jsxs("p",{className:"text-xs",children:["可调用插件:",e.jsx("span",{className:"font-mono",children:n?.join(", ")})]}),m?.map(x=>e.jsxs("p",{className:"text-xs",children:["事件 ",x.event," · ",x.mode==="intercept"?"拦截":"观察",x.failClosed?" · 失败即拒绝":""]},`${x.event}:${x.mode}`)),u?.map(x=>e.jsxs("p",{className:"text-xs",children:["定时任务 ",Ip(x)]},x.id))]})}function Ap(){return e.jsx("p",{className:"text-amber-700 text-xs dark:text-amber-400",children:"界面代码:运行在主界面里,可读写页面内容、调用界面能力,不受上面权限清单约束;只安装信任的插件"})}function Ep({pluginId:s,plain:t}){const[n,a]=l.useState(null),[r,o]=l.useState(null),i=l.useCallback(async()=>{const m=await window.electronAPI.extensionPlugins.artifactsList(s);m.ok?(a(m.artifacts),o(null)):o(m.error)},[s]);return l.useEffect(()=>{i()},[i]),e.jsxs("div",{className:K("space-y-2",t?"":"rounded-md border border-border p-3"),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-sm",children:"产出文件"}),e.jsx(y,{size:"icon",variant:"ghost","aria-label":"刷新",onClick:()=>{i()},children:e.jsx(ns,{className:"size-4"})})]}),r&&e.jsx("p",{className:"text-destructive text-xs",children:r}),e.jsx($c,{artifacts:n??[],onDelete:m=>{window.electronAPI.extensionPlugins.artifactDelete(m).then(u=>{u.ok?i():o(u.error??"删除失败")})}})]})}const Wt=new Set;function Mp({requestedInstallUrl:s=null,onRequestedInstallUrlConsumed:t,focusPluginId:n=null,onFocusPluginConsumed:a,requestedMarketQuery:r=null,onRequestedMarketQueryConsumed:o}={}){const{t:i}=R(),m=g(P=>P.pluginAutoUpdate!==!1),u=g(P=>P.setPluginAutoUpdate),[x,h]=l.useState([]),c=En(P=>P.errors),[f,d]=l.useState(null),[p,j]=l.useState(null),[b,A]=l.useState([]),[v,k]=l.useState(!1),[I,M]=l.useState(null),[$,E]=l.useState(""),[L,T]=l.useState(!1),[C,S]=l.useState(!1),[W,q]=l.useState(null),[N,z]=l.useState(null),[H,U]=l.useState(!1),[B,ie]=l.useState("");l.useEffect(()=>{r&&(ie(r),U(!0),o?.())},[r,o]);const[F,X]=l.useState(null),V=l.useCallback(async()=>{try{h(await window.electronAPI.extensionPlugins.list())}catch{h([])}},[]);l.useEffect(()=>(V(),window.electronAPI.extensionPlugins.registryNotice().then(z).catch(()=>z(null)),window.electronAPI.extensionPlugins.onChanged(()=>{V()})),[V]),l.useEffect(()=>{if(!n||(A(Y=>Y.includes(n)?Y:[...Y,n]),!x.some(Y=>Y.id===n)))return;const P=n;window.requestAnimationFrame(()=>{document.querySelector(`[data-plugin-id="${CSS.escape(P)}"]`)?.scrollIntoView({block:"center"})}),a?.()},[n,x,a]);const le=async P=>{M(null),f&&window.electronAPI.extensionPlugins.discard(f.token),d(null);const Y=await window.electronAPI.extensionPlugins.pickAndStage(P);Y.ok?"cancelled"in Y||d(Y.preview):M(Y.error)},_=async P=>{const Y=(P??$).trim();if(!Y)return;M(null),T(!0),f&&window.electronAPI.extensionPlugins.discard(f.token),d(null);const D=await window.electronAPI.extensionPlugins.stageFromUrl(Y).finally(()=>{T(!1)});D.ok?d(D.preview):M(D.error)},de=l.useRef(_);de.current=_,l.useEffect(()=>{if(!s)return;const P=s;let Y=!1;const D=window.setTimeout(()=>{Y||Wt.has(P)||(Wt.add(P),E(P),t?.(),de.current(P).finally(()=>{Wt.delete(P)}))},0);return()=>{Y=!0,window.clearTimeout(D)}},[s,t]);const ue=async(P,Y=!1)=>{M(null),f&&window.electronAPI.extensionPlugins.discard(f.token),d(null),T(!0);const D=window.electronAPI.extensionPlugins,Q=await(Y?D.marketStage(P):D.restage(P)).finally(()=>{T(!1)});Q.ok?d(Q.preview):M(Q.error)},O=async()=>{S(!0),q(null);try{const P=await window.electronAPI.extensionPlugins.checkUpdates();q(P.checked===0?i("No plugins installed from GitHub to check"):P.available>0?i("{{count}} update(s) available",{count:P.available}):i("All plugins are up to date"))}finally{S(!1)}},De=async()=>{if(!f)return;k(!0);const P=await window.electronAPI.extensionPlugins.commit(f.token);if(k(!1),!P.ok)M(P.error??i("Install failed"));else{E("");const Y=f.existingVersion?{ok:!0}:await window.electronAPI.extensionPlugins.setEnabled(f.id,!0);Te({type:Y.ok?"success":"warning",title:i("{{name}} installed",{name:f.name}),description:Y.ok?void 0:Y.error})}d(null)},te=()=>{f&&window.electronAPI.extensionPlugins.discard(f.token),d(null)};return e.jsxs("div",{className:"space-y-5","data-settings-row":"plugins.enso",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"font-medium text-lg",children:[i("Enso plugins"),e.jsx(Ze,{})]}),e.jsx("p",{className:"mt-1 text-muted-foreground text-sm",children:i("Installing a plugin lets it run code on this machine. Review what it asks for before confirming.")})]}),e.jsxs("div",{className:"flex shrink-0 gap-2",children:[x.length>0&&e.jsxs(y,{size:"sm",variant:"outline",disabled:C,onClick:()=>{O()},children:[C?e.jsx(Ps,{}):e.jsx(ns,{className:"size-4"}),i("Check for updates")]}),e.jsxs(y,{size:"sm",onClick:()=>{ie(""),U(!0)},children:[e.jsx(Vu,{className:"size-4"}),i("Marketplace")]})]})]}),e.jsxs("label",{className:"flex items-center justify-between gap-3 text-sm",children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block",children:i("Update plugins automatically")}),e.jsx("span",{className:"block text-muted-foreground text-xs",children:i("Marketplace updates that do not ask for new permissions install on their own.")})]}),e.jsx(ce,{className:"shrink-0",checked:m,onCheckedChange:P=>u(P)})]}),e.jsxs("div",{className:"space-y-2.5 rounded-lg border bg-muted/30 p-3",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(ho,{className:"flex-1",children:[e.jsx(fo,{children:e.jsx(ao,{className:"size-4 text-muted-foreground"})}),e.jsx(po,{value:$,placeholder:i("https://github.com/owner/repo"),onChange:P=>E(P.target.value),onKeyDown:P=>{P.key==="Enter"&&_()}})]}),e.jsx(y,{size:"sm",variant:"outline",disabled:v||L||$.trim()==="",onClick:()=>{_()},children:L?e.jsx(Ps,{}):i("Install from URL")})]}),e.jsxs("div",{className:"flex items-center gap-1 text-muted-foreground text-xs",children:[e.jsx("span",{className:"mr-1",children:i("Or install from")}),e.jsxs(y,{size:"xs",variant:"ghost",disabled:v||L,onClick:()=>{le("dir")},children:[e.jsx(Tn,{className:"size-3.5"}),i("Install from folder")]}),e.jsxs(y,{size:"xs",variant:"ghost",disabled:v||L,onClick:()=>{le("zip")},children:[e.jsx(zc,{className:"size-3.5"}),i("Install from zip")]})]})]}),I&&e.jsx("p",{className:"text-destructive text-sm",children:I}),e.jsx(ye,{open:H,onOpenChange:U,children:e.jsxs(we,{className:"max-w-5xl",children:[e.jsx(Ne,{children:e.jsx(ke,{children:i("Marketplace")})}),e.jsx(Ce,{children:e.jsx(bp,{initialQuery:B,disabled:v||L,installedKey:x.map(P=>`${P.id}@${P.version}`).join(","),onInstall:P=>{U(!1),ue(P,!0)}},B)})]})}),W&&e.jsx("p",{className:"text-muted-foreground text-sm",children:W}),N&&e.jsx(kp,{notice:N,remote:!!window.electronAPI.remote,onDismiss:()=>{window.electronAPI.extensionPlugins.dismissRegistryNotice().then(()=>z(null)).catch(P=>M(P instanceof Error?P.message:String(P)))}}),e.jsx(ye,{open:f!==null,onOpenChange:P=>!P&&!v&&te(),children:e.jsx(we,{children:f&&e.jsxs(e.Fragment,{children:[e.jsx(Ne,{children:e.jsxs(ke,{children:[f.name," ",f.version,f.existingVersion&&e.jsx("span",{className:"ml-2 text-base text-muted-foreground",children:i("updating from {{version}}",{version:f.existingVersion})})]})}),e.jsxs(Ce,{className:"space-y-3",children:[e.jsx(hr,{permissions:f.permissions,env:f.env,interop:f.interop,resident:f.resident,styles:f.styles,trustedUi:f.hasRenderer,events:f.events,schedules:f.schedules}),f.mcpServers.map(P=>e.jsxs("p",{className:"font-mono text-xs",children:[P.command," ",P.args.join(" ")]},P.name)),f.mcpTools.length>0&&e.jsxs("p",{className:"text-muted-foreground text-xs",children:[i("Host MCP tools it may call"),":",e.jsx("span",{className:"font-mono",children:f.mcpTools.join(", ")})]}),f.warnings.map(P=>e.jsx("p",{className:"text-muted-foreground text-xs",children:P},P))]}),e.jsxs(Ee,{children:[e.jsx(y,{size:"sm",variant:"ghost",disabled:v,onClick:te,children:i("Cancel")}),e.jsx(y,{size:"sm",disabled:v,onClick:()=>{De()},children:v?e.jsx(Ps,{}):i("Install")})]})]})})}),x.length===0&&!f&&e.jsxs("div",{className:"rounded-lg border border-dashed px-3 py-10 text-center",children:[e.jsx(Xs,{className:"mx-auto size-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:i("No Enso plugins installed")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:i("Browse the marketplace or install from a GitHub URL, folder or zip.")})]}),e.jsx("div",{className:"space-y-2",children:x.map(P=>e.jsxs("div",{"data-plugin-id":P.id,className:K("overflow-hidden rounded-lg border bg-card transition-colors",P.state==="crashed"&&"border-destructive/50"),children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-x-3 gap-y-2 p-3",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 basis-56 items-start gap-3",children:[e.jsx("div",{className:K("flex size-9 shrink-0 items-center justify-center rounded-md bg-muted",P.state==="enabled"?"text-foreground":"text-muted-foreground"),children:e.jsx(_c,{pluginId:P.id,icon:P.icon,className:"size-4"})}),e.jsxs("div",{className:"min-w-0 flex-1 space-y-0.5",children:[e.jsxs("p",{className:"flex flex-wrap items-center gap-1.5 text-sm",children:[e.jsx("span",{className:"truncate font-medium",children:P.name}),e.jsx(se,{variant:"outline",className:"text-[11px]",children:P.version}),P.state==="crashed"&&e.jsx(se,{variant:"destructive",className:"text-[11px]",children:i("Stopped after crashes")}),P.availableVersion&&e.jsx(se,{className:"text-[11px]",children:i("Update")}),P.pendingVersion&&e.jsx(se,{variant:"warning",className:"text-[11px]",children:"待授权"}),P.hasRenderer&&e.jsx(se,{variant:"outline",className:"text-[11px]",children:"受信任界面"}),P.devWatch&&e.jsx(se,{variant:"secondary",className:"text-[11px]",children:"开发模式"}),P.resident&&e.jsx(se,{variant:P.running?"secondary":"outline",className:"text-[11px]",children:P.running?"常驻运行中":"常驻未运行"})]}),e.jsx("p",{className:"truncate font-mono text-muted-foreground text-xs",children:P.id}),P.availableVersion&&e.jsxs("p",{className:"mt-1 flex items-center gap-2 text-primary text-xs",children:[i("Version {{version}} is available",{version:P.availableVersion}),e.jsx(y,{size:"xs",disabled:v||L,onClick:()=>{ue(P.id,P.source?.kind!=="url")},children:L?e.jsx(Ps,{}):i("Update")})]}),P.updateCheckError&&e.jsx("p",{className:"text-muted-foreground text-xs",children:i("Update check failed: {{reason}}",{reason:P.updateCheckError})}),P.lastError&&e.jsx(mr,{message:P.lastError.message}),c[P.id]?.map(Y=>e.jsx(mr,{message:`主题加载失败:${Y}`},Y)),P.pendingVersion&&e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2 rounded-md border border-amber-500/50 bg-amber-500/10 px-2 py-1.5 text-amber-700 text-xs dark:text-amber-400",children:[i("{{version}} asks for more and is waiting for approval",{version:P.pendingVersion}),e.jsx(y,{size:"xs",onClick:()=>{window.electronAPI.extensionPlugins.approvePending(P.id)},children:i("Allow")}),e.jsx(y,{size:"xs",variant:"ghost",onClick:()=>{window.electronAPI.extensionPlugins.rejectPending(P.id)},children:i("Keep current")})]})]})]}),e.jsxs("div",{className:"ml-auto flex shrink-0 items-center gap-0.5",children:[P.source&&e.jsx(y,{size:"icon",variant:"ghost",disabled:v||L,"aria-label":i("Reinstall from source"),title:P.source.kind==="url"?`${i("Reinstall from source")}: ${P.source.url}`:i("Reinstall from source"),onClick:()=>{ue(P.id)},children:e.jsx(Fc,{className:"size-4"})}),e.jsx(y,{size:"icon",variant:"ghost","aria-label":"产出文件",title:"产出文件",onClick:()=>j({kind:"artifacts",pluginId:P.id,pluginName:P.name}),children:e.jsx(Bc,{className:"size-4"})}),e.jsx(y,{size:"icon",variant:"ghost","aria-label":i("Usage guide"),title:i("Usage guide"),onClick:()=>X({id:P.id,name:P.name,from:"installed"}),children:e.jsx(yu,{className:"size-4"})}),e.jsx(y,{size:"icon",variant:"ghost","aria-label":i("Plugin logs"),title:i("Plugin logs"),onClick:()=>j({kind:"logs",pluginId:P.id,pluginName:P.name}),children:e.jsx(Ln,{className:"size-4"})}),P.configurable&&e.jsx(y,{size:"icon",variant:"ghost","aria-label":i("Configure"),title:i("Configure"),onClick:()=>j({kind:"config",pluginId:P.id,pluginName:P.name}),children:e.jsx(Uc,{className:"size-4"})}),e.jsx(y,{size:"icon",variant:"ghost","aria-label":i("Uninstall"),title:i("Uninstall"),className:"text-muted-foreground hover:text-destructive",onClick:()=>{window.electronAPI.extensionPlugins.uninstall(P.id)},children:e.jsx(Pe,{className:"size-4"})}),e.jsx("div",{className:"mx-1.5 h-5 w-px bg-border"}),e.jsx(ce,{checked:P.state==="enabled",onCheckedChange:Y=>{window.electronAPI.extensionPlugins.setEnabled(P.id,Y)}})]})]}),e.jsxs("button",{type:"button","aria-expanded":b.includes(P.id),className:K("flex w-full items-center gap-1 border-t bg-muted/20 px-3 py-1.5 text-left text-xs","text-muted-foreground transition-colors hover:bg-muted/50 hover:text-foreground"),onClick:()=>A(Y=>Y.includes(P.id)?Y.filter(D=>D!==P.id):[...Y,P.id]),children:[b.includes(P.id)?e.jsx(gt,{className:"size-3"}):e.jsx(Ds,{className:"size-3"}),b.includes(P.id)?"收起详情":"详情",!b.includes(P.id)&&xr(P)&&e.jsx("span",{className:"ml-1 opacity-70",children:xr(P)})]}),b.includes(P.id)&&e.jsxs("div",{className:"space-y-3 border-t px-3 py-3",children:[P.interceptBreakers?.map(Y=>e.jsxs("p",{className:"text-amber-600 text-xs dark:text-amber-400",children:[Y.event," 检查连续失败,临时放行到"," ",new Date(Y.until).toLocaleTimeString()]},Y.event)),e.jsx(hr,{permissions:P.permissions,resident:P.resident,running:P.running,styles:P.themes.some(Y=>Y.css!==void 0),trustedUi:P.hasRenderer,events:P.events,schedules:P.schedules}),P.crossSessionInject!==void 0&&e.jsxs("div",{className:"flex items-center justify-between gap-3 text-xs",children:[e.jsxs("span",{children:[e.jsx("span",{className:"block",children:"允许向任意运行中的会话发送消息"}),e.jsx("span",{className:"block text-muted-foreground",children:"关闭时只能发到发起调用的会话;开启后定时任务、常驻进程也能向其他项目和窗口的会话发消息并触发执行"})]}),e.jsx(ce,{"aria-label":"允许向任意运行中的会话发送消息",checked:P.crossSessionInject,onCheckedChange:Y=>{window.electronAPI.extensionPlugins.setCrossSessionInject(P.id,Y)}})]}),P.devWatch!==void 0&&e.jsxs("div",{className:"flex items-center justify-between gap-3 text-xs",children:[e.jsxs("span",{children:[e.jsx("span",{className:"block",children:"开发模式:目录改动后自动重装"}),e.jsx("span",{className:"block text-muted-foreground",children:"授权没扩大时直接替换;扩大时停下,需要从来源重新安装并同意。重启应用后关闭"})]}),e.jsx(ce,{"aria-label":"开发模式:目录改动后自动重装",checked:P.devWatch,onCheckedChange:Y=>{window.electronAPI.extensionPlugins.setDevWatch(P.id,Y).then(D=>{!D.ok&&D.error&&Te({title:D.error})})}})]}),((P.pendingPermissions?.length??0)>0||P.pendingRenderer)&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:"待同意"}),e.jsx(ri,{permissions:P.pendingPermissions??[],styles:P.pendingRenderer}),P.pendingRenderer&&e.jsx("p",{className:"text-amber-700 text-xs dark:text-amber-400",children:"新增界面代码:运行在主界面里,不受权限清单约束"})]})]})]},P.id))}),e.jsx(ye,{open:p!==null,onOpenChange:P=>!P&&j(null),children:e.jsxs(we,{children:[e.jsx(Ne,{children:e.jsxs(ke,{children:[p?.kind==="config"?i("Configure"):p?.kind==="logs"?i("Plugin logs"):"产出文件",p?` · ${p.pluginName}`:""]})}),e.jsxs(Ce,{className:"space-y-4",children:[p?.kind==="config"&&e.jsx(Cp,{pluginId:p.pluginId,plain:!0}),p?.kind==="logs"&&e.jsx(Sp,{pluginId:p.pluginId,plain:!0}),p?.kind==="artifacts"&&e.jsx(Ep,{pluginId:p.pluginId,plain:!0})]})]})}),e.jsx(fp,{pluginId:F?.id??null,name:F?.name??"",from:F?.from??"installed",homepage:F?.homepage,onClose:()=>X(null)})]})}function Pp(s,t){return[[s.skills.length,t("Skills")],[s.commands.length,t("Commands")],[s.agents.length,t("Agent types")],[s.mcpServers.length,"MCP"],[s.hooks.length,"Hooks"]].filter(([n])=>n>0).map(([n,a])=>`${a} ${n}`).join(" · ")}function As({label:s,items:t}){return t.length===0?null:e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("p",{className:"font-medium text-muted-foreground text-xs",children:s}),t.map(n=>e.jsx("p",{className:"break-all font-mono text-[11px]",children:n},n))]})}function Tp({plugin:s,entry:t,onToggle:n}){const{t:a}=R(),[r,o]=l.useState(!1),{components:i}=s,m=Pp(i,a);return e.jsxs("div",{className:"rounded-md border","data-settings-row":`plugins.${s.key}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 px-3 py-2",children:[e.jsxs("button",{type:"button",className:"flex min-w-0 flex-1 items-center gap-2 text-left",onClick:()=>o(u=>!u),children:[e.jsx(Ds,{className:K("h-4 w-4 shrink-0 text-muted-foreground transition-transform",r&&"rotate-90")}),e.jsx("span",{className:"shrink-0 font-medium text-sm",children:s.name}),s.version&&e.jsx(se,{variant:"outline",className:"shrink-0 text-[11px]",children:s.version}),s.marketplace&&e.jsx(se,{variant:"secondary",className:"shrink-0 text-[11px]",children:s.marketplace}),e.jsx("span",{className:"min-w-0 truncate text-muted-foreground text-xs",children:m||(i.unsupported.length>0?`${a("Not supported")}: ${i.unsupported.join(", ")}`:a("No supported components"))})]}),e.jsx(ce,{checked:t?.enabled===!0,onCheckedChange:n})]}),r&&e.jsxs("div",{className:"space-y-2 border-t px-3 py-2",children:[s.description&&e.jsx("p",{className:"text-muted-foreground text-xs",children:s.description}),e.jsx(As,{label:a("Skills"),items:i.skills}),e.jsx(As,{label:a("Commands"),items:i.commands.map(u=>`/${u}`)}),e.jsx(As,{label:a("Agent types"),items:i.agents}),e.jsx(As,{label:a("MCP servers (run when a session starts)"),items:i.mcpServers.map(u=>`${u.name}: ${u.target}`)}),e.jsx(As,{label:a("Hooks (run automatically on local sessions)"),items:i.hooks.map(u=>`${u.event}: ${u.command}`)}),e.jsx(As,{label:a("Not supported"),items:i.unsupported})]})]})}function Rp(){const{t:s}=R(),t=g(d=>d.plugins),n=g(d=>d.addPlugins),a=g(d=>d.setPluginEnabled),r=g(d=>d.removePlugin),[o,i]=l.useState(null),m=l.useCallback(async()=>{i(null);try{i(await window.electronAPI.assets.listInstalledPlugins())}catch{i([])}},[]);l.useEffect(()=>{m()},[m]);const u=new Map(t.map(d=>[d.key,d])),x=new Set((o??[]).map(d=>d.key)),h=o?t.filter(d=>!x.has(d.key)):[],c=t.filter(d=>d.enabled).length,f=(d,p)=>{const j=u.get(d.key);if(j){a(j.id,p);return}n([{id:crypto.randomUUID(),key:d.key,name:d.name,description:d.description,...d.version?{version:d.version}:{},source:d.marketplace||"Claude Code",enabled:p}])};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-end justify-between gap-4","data-settings-row":"plugins.root",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"font-medium text-lg",children:[s("Claude Code plugins"),e.jsx(Ze,{}),c>0&&e.jsx("span",{className:"ml-2 font-normal text-muted-foreground text-xs",children:s("{{count}} enabled",{count:c})})]}),e.jsx("p",{className:"text-muted-foreground text-sm",children:s("Plugins installed in Claude Code. Each one is switched on or off as a whole here; changes apply to new sessions.")})]}),e.jsxs(y,{variant:"outline",size:"sm",onClick:m,disabled:o===null,children:[e.jsx(ns,{className:"mr-1.5 h-4 w-4"}),s("Rescan")]})]}),o===null?e.jsx("div",{className:"flex justify-center py-10",children:e.jsx(Ps,{className:"size-5"})}):o.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx(Xs,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:s("No Claude Code plugins found")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:s("Install plugins with /plugin in Claude Code, then rescan.")})]}):e.jsx("div",{className:"space-y-2",children:o.map(d=>e.jsx(Tp,{plugin:d,entry:u.get(d.key),onToggle:p=>f(d,p)},d.key))}),h.length>0&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"font-medium text-muted-foreground text-xs",children:s("No longer installed in Claude Code")}),h.map(d=>e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md px-3 py-2 hover:bg-accent/50",children:[e.jsx("span",{className:"text-muted-foreground text-sm line-through",children:d.name}),e.jsx(y,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-destructive",onClick:()=>r(d.id),children:e.jsx(Pe,{className:"h-3.5 w-3.5"})})]},d.id))]})]})}const Ys={mask:"Mask",warn:"Warn only",block:"Block"},Op={email:"Email",phone:"Phone number",idCard:"ID card number",bankCard:"Bank card number",ip:"IP address"},pn={mask:"text-sky-600 dark:text-sky-400",warn:"text-amber-600 dark:text-amber-400",block:"text-red-600 dark:text-red-400"},Dp=[1,7,30],Lp={1:"Today",7:"7D",30:"30D"};function zp(s){const t=new Map;for(const n of s.report.hits){const a=t.get(n.token);a?a.count+=n.count:t.set(n.token,{label:`${n.kind} ${n.preview}`,count:n.count})}return[...t.values()].map(n=>n.count>1?`${n.label} ×${n.count}`:n.label).join(", ")}function Ht({value:s,onChange:t}){const{t:n}=R(),a=Object.fromEntries(Object.keys(Ys).map(r=>[r,n(Ys[r])]));return e.jsxs(ne,{items:a,value:s,onValueChange:r=>t(r),children:[e.jsx(ae,{className:"w-32",children:e.jsx(re,{})}),e.jsx(oe,{children:Object.entries(a).map(([r,o])=>e.jsx(Z,{value:r,children:o},r))})]})}function qt({label:s,hint:t,value:n,onCommit:a,rowId:r}){const[o,i]=l.useState(n.join(`
18
18
  `));return l.useEffect(()=>i(n.join(`
19
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
20
  `))})]})}function Ts({title:s,children:t}){return e.jsxs("div",{className:"space-y-3 rounded-md border p-3",children:[e.jsx("p",{className:"text-sm font-medium",children:s}),t]})}function _p({settings:s}){const{t}=R(),[n,a]=l.useState(""),r=l.useMemo(()=>Gc(n,s),[n,s]);return e.jsxs(Ts,{title:t("Try it"),children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Runs locally. Nothing is remembered or sent anywhere.")}),e.jsx(Xe,{rows:3,value:n,placeholder:t("Paste some text, e.g. an .env file"),onChange:o=>a(o.target.value)}),n&&e.jsxs(e.Fragment,{children:[e.jsx("pre",{className:"max-h-48 overflow-auto whitespace-pre-wrap rounded bg-muted p-2 text-xs",children:r.text}),e.jsxs("ul",{className:"space-y-0.5 text-xs",children:[r.report.hits.map(o=>e.jsxs("li",{className:"flex gap-2",children:[e.jsx("span",{className:K("font-medium",pn[o.action]),children:t(Ys[o.action])}),e.jsx("span",{children:o.kind}),e.jsx("span",{className:"text-muted-foreground",children:o.preview}),o.count>1&&e.jsxs("span",{className:"text-muted-foreground",children:["×",o.count]})]},`${o.token}-${o.action}`)),r.report.hits.length===0&&e.jsx("li",{className:"text-muted-foreground",children:t("Nothing matched")})]})]})]})}function Fp(){const{t:s}=R(),[t,n]=l.useState(7),[a,r]=l.useState(null),[o,i]=l.useState(!1),m=l.useRef(0),u=Kc(f=>f.conversations),x=l.useCallback(async f=>{const d=++m.current;i(!0);const p=await window.electronAPI.privacyMask.records(f).catch(()=>[]);d===m.current&&(i(!1),r(p))},[]);l.useEffect(()=>{x(t)},[t,x]);const h=l.useMemo(()=>{const f={mask:0,warn:0,block:0},d=new Map;for(const p of a??[]){const j=new Set;for(const b of p.report.hits){const A=`${b.action}:${b.token}`;j.has(A)||(j.add(A),f[b.action]+=1,d.set(b.kind,(d.get(b.kind)??0)+1))}}return{byAction:f,byKind:[...d].sort((p,j)=>j[1]-p[1])}},[a]),c=f=>{if(f.source==="aux")return s("Auxiliary request");const d=f.sessionId?u[f.sessionId]?.title:void 0,p=f.source==="compaction"?s("Compaction"):s("Session");return d?`${p} · ${d}`:p};return e.jsxs(Ts,{title:s("Records"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"flex gap-1",children:Dp.map(f=>e.jsx(y,{size:"sm",variant:f===t?"secondary":"ghost",onClick:()=>n(f),children:s(Lp[f])},f))}),e.jsx(y,{variant:"ghost",size:"icon-sm",onClick:()=>{x(t)},disabled:o,"aria-label":s("Refresh"),children:e.jsx(ns,{className:K("size-4",o&&"animate-spin")})})]}),e.jsx("div",{className:"flex flex-wrap gap-4 text-sm",children:Object.keys(Ys).map(f=>e.jsxs("span",{children:[e.jsx("span",{className:pn[f],children:s(Ys[f])})," ",e.jsx("span",{className:"font-medium tabular-nums",children:h.byAction[f]})]},f))}),h.byKind.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 text-xs text-muted-foreground",children:h.byKind.map(([f,d])=>e.jsxs("span",{className:"rounded bg-muted px-1.5 py-0.5",children:[f," ",d]},f))}),e.jsxs("div",{className:"max-h-80 overflow-auto",children:[e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{className:"text-left text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"py-1 pr-2 font-normal",children:s("Requested at")}),e.jsx("th",{className:"py-1 pr-2 font-normal",children:s("Source")}),e.jsx("th",{className:"py-1 pr-2 font-normal",children:s("Model")}),e.jsx("th",{className:"py-1 font-normal",children:s("Hits")})]})}),e.jsx("tbody",{children:(a??[]).slice(0,200).map(f=>{const d=Wc(f.report),p=`${f.at}:${f.sessionId??f.source}:${f.model}:${f.report.hits.map(j=>j.token).join(",")}`;return e.jsxs("tr",{className:"border-t align-top",children:[e.jsx("td",{className:"py-1 pr-2 whitespace-nowrap tabular-nums",children:new Date(f.at).toLocaleString()}),e.jsx("td",{className:"py-1 pr-2",children:c(f)}),e.jsx("td",{className:"py-1 pr-2 break-all",children:f.model}),e.jsxs("td",{className:K("py-1",d&&pn[d]),children:[zp(f),f.report.blocked&&` · ${s("Request blocked")}`]})]},p)})})]}),a?.length===0&&e.jsx("p",{className:"py-4 text-center text-xs text-muted-foreground",children:s("No records yet")})]})]})}function Bp(){const{t:s}=R(),t=g(r=>r.privacyMasking),n=g(r=>r.setPrivacyMasking),a=r=>n({...t,...r});return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("Privacy")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("Replace API keys and personal data with placeholders before requests leave this device, and restore them in replies. Original values stay in memory on this device only.")})]}),e.jsx(Ie,{rowId:"privacy.enabled",title:s("Privacy masking"),description:s("Applies to chats, compaction, bot members and helper requests."),checked:t.enabled,onChange:r=>a({enabled:r})}),t.enabled&&e.jsxs(e.Fragment,{children:[e.jsxs(Ts,{title:s("Secrets"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:s("API keys, tokens, private keys, passwords in URLs and config files.")}),e.jsx(Ht,{value:t.secrets.action,onChange:r=>a({secrets:{...t.secrets,action:r}})})]}),e.jsx(Ie,{rowId:"privacy.secrets",title:s("Detect secrets"),description:s("Recommended. Covers common vendor key formats."),checked:t.secrets.enabled,onChange:r=>a({secrets:{...t.secrets,enabled:r}})}),e.jsx(Ie,{rowId:"privacy.shape",title:s("Send look-alike keys"),description:s("Replace keys with fake keys of the same format instead of placeholders, so the model treats them as real keys."),checked:t.secrets.shape,onChange:r=>a({secrets:{...t.secrets,shape:r}})})]}),e.jsxs(Ts,{title:s("Personal data"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Emails, phone numbers, ID and bank card numbers, IP addresses.")}),e.jsx(Ht,{value:t.personal.action,onChange:r=>a({personal:{...t.personal,action:r}})})]}),e.jsx(Ie,{rowId:"privacy.personal",title:s("Detect personal data"),description:s("Matches are validated (checksums, real domains) to limit false hits."),checked:t.personal.enabled,onChange:r=>a({personal:{...t.personal,enabled:r}})}),t.personal.enabled&&e.jsx("div",{className:"flex flex-wrap gap-4",children:Vc.map(r=>e.jsxs("label",{className:"flex items-center gap-1.5 text-sm",children:[e.jsx(Le,{checked:t.personal.kinds.includes(r),onCheckedChange:o=>a({personal:{...t.personal,kinds:o?[...t.personal.kinds,r]:t.personal.kinds.filter(i=>i!==r)}})}),s(Op[r])]},r))})]}),e.jsxs(Ts,{title:s("Custom rules"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Words and patterns specific to your work.")}),e.jsx(Ht,{value:t.custom.action,onChange:r=>a({custom:{...t.custom,action:r}})})]}),e.jsx(qt,{rowId:"privacy.words",label:s("Words"),hint:s("One per line, case-insensitive. Project codenames, customer names…"),value:t.custom.words,onCommit:r=>a({custom:{...t.custom,words:r}})}),e.jsx(qt,{rowId:"privacy.rules",label:s("Prefixes or patterns"),hint:s("One per line. A prefix like corp_ or a regex like /INC-\\d{4}/i."),value:t.custom.rules,onCommit:r=>a({custom:{...t.custom,rules:r}})})]}),e.jsx(Ts,{title:s("Allow list"),children:e.jsx(qt,{rowId:"privacy.allow",label:s("Never mask"),hint:s("Exact values, one per line. Team emails, test keys…"),value:t.allow,onCommit:r=>a({allow:r})})}),e.jsx(_p,{settings:t})]}),e.jsx(Fp,{})]})}function Up(){const{t:s}=R(),t=g(d=>d.approvalReviewer),n=g(d=>d.setApprovalReviewer),a=g(d=>d.approvalAutoManage),r=g(d=>d.setApprovalAutoManage),o=Hc(g(d=>d.approvalAllowThreshold)),i=g(d=>d.setApprovalAllowThreshold),m={"0.85":s("0.85 (looser)"),"0.9":s("0.9 (default)"),"0.95":s("0.95 (stricter)")},u=es(),x=Rn(),h=l.useMemo(()=>[...u,...x.filter(ln)],[u,x]),c=t?h.find(d=>d.id===t.providerId):void 0,f=c?.models.find(d=>d.id===t?.modelId);return e.jsxs("section",{className:"space-y-2 rounded-lg border bg-card p-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h4",{className:"font-medium text-sm",children:s("Assistant approval model")}),e.jsx("p",{className:"mt-0.5 text-muted-foreground text-xs",children:s("Required before Assistant approval can be selected. Does not fall back to the chat model.")})]}),h.length>0&&e.jsx("div",{className:"w-full min-w-0",children:e.jsx(ze,{providers:h,providerId:c?.id??"",modelId:f?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:s("No assistant approval model selected"),side:"bottom",triggerClassName:Qe,onSelect:(d,p)=>n({providerId:d,modelId:p}),onReasoningChange:()=>{},onThinkingChange:()=>{}})}),c&&ln(c)&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:s(a?"Auto-managed: runs only when the decision model is highly confident it is safe. Everything else is denied and the agent tries another way. Protected actions still ask you.":"Decision models only allow or block when highly confident. Everything else asks you.")}),e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("span",{className:"text-sm",children:s("Auto-manage approvals")}),e.jsx(ce,{"aria-label":s("Auto-manage approvals"),checked:a,onCheckedChange:r})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("span",{className:"text-sm",children:s("Auto-allow threshold")}),e.jsxs(ne,{items:m,value:String(o),onValueChange:d=>i(Number(d)),children:[e.jsx(ae,{className:"w-36","aria-label":s("Auto-allow threshold"),children:e.jsx(re,{})}),e.jsx(oe,{children:qc.map(d=>e.jsx(Z,{value:String(d),children:m[String(d)]},d))})]})]}),e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Only runs automatically when the allow probability reaches this value. Operations near the threshold may be allowed one time and not the next.")})]}),t&&(!c||!f)&&e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Selected model is unavailable")}),t&&e.jsx(y,{variant:"ghost",size:"sm",className:"self-start",onClick:()=>n(null),children:s("Clear")})]})}function pr(s,t){const n=t.find(r=>r.id===s.providerId),a=n?.models.find(r=>r.id===s.modelId);return`${n?.name??s.providerId} / ${a?.label??s.modelId}`}function $p(){const{t:s}=R(),t=et(),n=g(M=>M.virtualModels),a=g(M=>M.defaultModel),r=g(M=>M.setDefaultModel),o=g(M=>M.defaultModelFollowLast),i=g(M=>M.setDefaultModelFollowLast),m=g(M=>M.defaultReasoningEnabled),u=g(M=>M.defaultThinkingLevel),x=g(M=>M.setDefaultReasoningEnabled),h=g(M=>M.setDefaultThinkingLevel),c=jt(M=>M.snapshot),f=Yc(M=>M.latest),d=es(),p=a?d.find(M=>M.id===a.providerId):void 0,j=p?.models.find(M=>M.id===a?.modelId),b=t.some(M=>!!M.oauthAccountKey),A=b&&(c.availability.status==="unloaded"||c.availability.status==="loading"),v=b&&c.availability.status==="error"?c.availability.error:null,k=f?.notice,I=k?s("Default model changed: {{previous}} → {{next}}",{previous:pr(k.previous,t),next:k.next?pr(k.next,t):s("No default model")}):null;return e.jsxs("section",{className:"space-y-2 rounded-lg border bg-card p-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h4",{className:"font-medium text-sm",children:s("Default model")}),e.jsx("p",{className:"mt-0.5 text-muted-foreground text-xs",children:s(o?"New conversations use the last model you picked.":"Used for new conversations.")})]}),d.length>0&&e.jsx("div",{className:"w-full min-w-0",children:e.jsx(ze,{providers:d,virtualModels:n,providerId:p?.id??a?.providerId??"",modelId:j?.id??a?.modelId??"",reasoningEnabled:m,thinkingLevel:u,emptyLabel:s("Select model"),triggerLabel:o?s("Follow last selection"):void 0,side:"bottom",triggerClassName:Qe,onSelect:(M,$)=>r({providerId:M,modelId:$}),onReasoningChange:x,onThinkingChange:h,showReasoningControls:!o})}),!o&&d.length>0&&e.jsx(y,{type:"button",variant:"ghost",size:"sm",className:"self-start",onClick:()=>i(!0),children:s("Follow last selection")}),d.length===0&&e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-5 text-center",children:[e.jsx(_n,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-2 font-medium text-sm",children:s("No usable models")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:s("Enable a model and configure valid provider credentials first.")})]}),(A||v)&&e.jsxs("div",{className:"flex items-start gap-2 rounded-md bg-muted px-2.5 py-2 text-xs",children:[e.jsx(Rs,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:v?s("Subscription credentials could not be loaded: {{error}}",{error:v}):s("Subscription credentials are loading. API-key models remain available.")})]}),I&&e.jsx("p",{className:"rounded-md bg-muted px-2.5 py-2 text-muted-foreground text-xs",children:I})]})}function Vp(){const{t:s}=R(),t=Qu(et()),n=g(o=>o.imageGenerationModel),a=n===null||t.some(o=>o.id===n.providerId&&o.models.some(i=>i.id===n.modelId)),r=g(o=>o.setImageGenerationModel);return e.jsxs("section",{className:"space-y-2 rounded-lg border bg-card p-3",children:[e.jsx("h4",{className:"font-medium text-sm",children:s("Default image generation model")}),t.length>0?e.jsx(ze,{providers:t,providerId:n?.providerId??"",modelId:n?.modelId??"",reasoningEnabled:!1,thinkingLevel:"medium",emptyLabel:s("Select model"),side:"bottom",triggerClassName:Qe,onSelect:(o,i)=>r({providerId:o,modelId:i}),onReasoningChange:()=>{},onThinkingChange:()=>{},showReasoningControls:!1}):e.jsx("p",{className:"text-muted-foreground text-xs",children:s("No image generation models available")}),!a&&e.jsx("p",{className:"text-destructive text-xs",children:s("Selected image generation model is unavailable")}),n&&e.jsx(y,{type:"button",variant:"ghost",size:"sm",onClick:()=>r(null),children:s("Clear selection")})]})}function Gp({provider:s,onClose:t}){const{t:n}=R(),a=g(j=>j.providers),r=g(j=>j.updateProvider),o=vo(j=>j.snapshot),i=l.useMemo(()=>bo([s],o)[0]?.models??s.models,[s,o]),m=jt(j=>j.snapshot.availability),u=jt(j=>j.snapshot.revision),[x,h]=l.useState([]),[c,f]=l.useState(s.oauthAccountPool?.accountKeys??[]);l.useEffect(()=>{let j=!1;return window.electronAPI.providers.listOauth().then(b=>{j||h(b)}).catch(b=>{j||(h([]),console.error("Failed to load OAuth account metadata",b))}),()=>{j=!0}},[u]);const d=Co(a),p=[...d.flatMap(j=>j.oauthAccountKey??[]),...c.filter(j=>!d.some(b=>b.oauthAccountKey===j))];return e.jsx(yo,{initialValue:{...s,name:Fn(s,n),models:i},oauth:!0,hideName:!0,saveDisabled:c.length===0,oauthAccountKey:s.oauthAccountKey,onCancel:t,extraFields:e.jsxs(he,{children:[e.jsx(pe,{children:n("Pool members")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n("Use enabled, signed-in accounts in the listed order. Model and reasoning stay unchanged. Main agents and subagents share this pool.")}),e.jsx("div",{className:"mt-2 w-full space-y-1 rounded-md border p-1",children:p.map((j,b)=>{const A=d.find(k=>k.oauthAccountKey===j),v=x.flatMap(k=>k.accounts).find(k=>k.key===j);return e.jsxs("label",{className:"flex min-w-0 items-center gap-2 px-2 py-1.5 text-sm",children:[e.jsx(Le,{checked:c.includes(j),onCheckedChange:k=>f(I=>k?[...I,j]:I.filter(M=>M!==j))}),e.jsxs("span",{className:"shrink-0 text-xs text-muted-foreground",children:[b+1,"."]}),e.jsx("span",{className:"min-w-0 truncate",children:v?.email??j}),!A?.enabled&&e.jsx("span",{className:"shrink-0 text-xs text-muted-foreground",children:n("Account disabled")}),m.status==="ready"&&!m.authenticatedAccountKeys.has(j)&&e.jsx("span",{className:"shrink-0 text-xs text-muted-foreground",children:n("Account signed out")})]},j)})})]}),onSave:j=>{c.length!==0&&(r(s.id,{models:wo(j.models,ko(o,s.oauthAccountKey??"")?.models,No(g.getState(),s.id)),oauthAccountPool:{accountKeys:p.filter(b=>c.includes(b))}}),t())}})}function Kp({provider:s,onClose:t}){const{t:n}=R(),a=g(i=>i.updateProvider),r=vo(i=>i.snapshot),o=l.useMemo(()=>s?.oauthAccountKey?bo([s],r)[0]?.models??s.models:s?.models,[s,r]);return e.jsx(ye,{open:s!==null,onOpenChange:i=>!i&&t(),children:e.jsxs(we,{children:[e.jsx(Ne,{children:e.jsx(ke,{children:s?.oauthAccountPool?Fn(s,n):n("Edit Provider")})}),s?.oauthAccountPool?e.jsx(Gp,{provider:s,onClose:t},s.id):s&&e.jsx(yo,{initialValue:{name:s.name,api:s.api,apiKey:s.apiKey,baseUrl:s.baseUrl,models:o??s.models,headers:s.headers},oauth:!!s.oauthAccountKey,oauthAccountKey:s.oauthAccountKey,onCancel:t,onSave:i=>{a(s.id,s.oauthAccountKey?{name:i.name,models:wo(i.models,ko(r,s.oauthAccountKey)?.models,No(g.getState(),s.id))}:i),t()}},s.id)]})})}const Wp=(s,t)=>s.models.some(n=>n.id===t&&n.enabled!==!1),fr=()=>{};function gr(s){return s==="on"||s==="off"}function Yt(s){return typeof s=="string"&&ed.includes(s)}function Hp(){const{t:s}=R(),t=g(c=>c.subagentModelsEnabled),n=g(c=>c.subagentModels),a=g(c=>c.setSubagentModelsEnabled),r=g(c=>c.addSubagentModel),o=g(c=>c.updateSubagentModel),i=g(c=>c.removeSubagentModel),m=g(c=>c.defaultModel),u=g(c=>c.virtualModels),x=es(),h=l.useMemo(()=>{if(m&&Jc(m)){const c=Xc(u,x).find(f=>f.id===m.modelId);if(c)return{providerId:Qc,modelId:c.id}}if(m){const c=x.find(f=>f.id===m.providerId);if(c&&Wp(c,m.modelId))return m}for(const c of x){const f=c.models.find(d=>d.enabled!==!1);if(f)return{providerId:c.id,modelId:f.id}}return null},[x,m,u]);return e.jsxs("section",{"data-slot":"subagent-models",className:"space-y-2 rounded-lg border bg-card p-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h4",{className:"font-medium text-sm",children:s("Let the agent pick subagent models")}),e.jsx("p",{className:"mt-0.5 text-muted-foreground text-xs",children:s("The main agent can pick one of these models when dispatching subagents or coworkers. The description tells it when to use each model.")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:s("Applies to newly started conversations.")})]}),e.jsx(ce,{className:"shrink-0",checked:t,onCheckedChange:a})]}),t&&e.jsxs("div",{className:"space-y-1.5",children:[n.map(c=>e.jsxs("div",{"data-slot":"subagent-model-row",className:K("flex items-center gap-2 rounded-md border px-2 py-1.5",c.enabled===!1&&"bg-muted/50 text-muted-foreground"),children:[e.jsx(ce,{"data-slot":"subagent-model-enabled","aria-label":s("Enable subagent model"),title:s("Make this model available to subagents"),checked:c.enabled!==!1,onCheckedChange:f=>o(c.id,{enabled:f})}),c.enabled===!1&&e.jsx(se,{variant:"outline",className:"shrink-0 text-[10px] text-muted-foreground",children:s("Disabled")}),e.jsx("div",{className:"shrink-0 rounded-md border bg-background",children:e.jsx(ze,{providers:x,virtualModels:u,providerId:c.providerId,modelId:c.modelId,modelCapabilityOverrides:Zc(c),reasoningMode:gr(c.reasoning)?c.reasoning:"follow",reasoningEnabled:c.reasoning==="on",thinkingLevel:Yt(c.thinkingLevel)?c.thinkingLevel:"medium",onReasoningModeChange:(f,d)=>{f==="follow"?o(c.id,{reasoning:void 0,thinkingLevel:void 0}):f==="on"&&!Yt(c.thinkingLevel)?o(c.id,{reasoning:"on",thinkingLevel:d}):o(c.id,{reasoning:f})},onSelect:(f,d)=>o(c.id,{providerId:f,modelId:d}),onReasoningChange:f=>o(c.id,{reasoning:f?"on":"off"}),onThinkingChange:f=>o(c.id,{thinkingLevel:f}),onReasoningNormalize:gr(c.reasoning)?f=>o(c.id,{reasoning:f?"on":"off"}):fr,onThinkingNormalize:Yt(c.thinkingLevel)?f=>o(c.id,{thinkingLevel:f}):fr})}),e.jsx(J,{value:c.description,placeholder:s("When to use it, e.g. cheap and fast for simple subtasks"),className:"h-7 flex-1 text-xs",onChange:f=>o(c.id,{description:f.target.value})}),e.jsx(y,{type:"button",variant:"ghost",size:"icon",className:"h-6 w-6 shrink-0 text-muted-foreground hover:text-destructive",onClick:()=>i(c.id),children:e.jsx(Pe,{className:"h-3.5 w-3.5"})})]},c.id)),e.jsxs(y,{type:"button",variant:"outline",size:"sm",className:"h-7 text-xs",disabled:!h,onClick:()=>{h&&r({...h,description:""})},children:[e.jsx(Re,{className:"mr-1 h-3.5 w-3.5"}),s("Add model")]}),!h&&e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Enable a model and configure valid provider credentials first.")})]})]})}function qp(){const{t:s}=R(),t=g(u=>u.titleSummaryEnabled),n=g(u=>u.setTitleSummaryEnabled),a=g(u=>u.titleSummaryModel),r=g(u=>u.setTitleSummaryModel),o=es(),i=a?o.find(u=>u.id===a.providerId):void 0,m=i?.models.find(u=>u.id===a?.modelId);return e.jsxs("section",{className:"space-y-2 rounded-lg border bg-card p-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h4",{className:"font-medium text-sm",children:s("Conversation title summary")}),e.jsx("p",{className:"mt-0.5 text-muted-foreground text-xs",children:s("Generate a short AI title from the first message of a new conversation.")})]}),e.jsx(ce,{checked:t,onCheckedChange:n})]}),t&&e.jsxs("div",{className:"space-y-2",children:[o.length>0&&e.jsx("div",{className:"w-full min-w-0",children:e.jsx(ze,{providers:o,providerId:i?.id??"",modelId:m?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:s("Follows the default model"),side:"bottom",triggerClassName:Qe,onSelect:(u,x)=>r({providerId:u,modelId:x}),onReasoningChange:()=>{},onThinkingChange:()=>{}})}),a&&(!i||!m)&&e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Selected model is unavailable — falls back to the default model.")}),a&&e.jsx(y,{variant:"ghost",size:"sm",className:"self-start",onClick:()=>r(null),children:s("Follow default model")})]})]})}function Yp({accountKey:s}){const t=md(s);return!t||t.error?null:e.jsx(xd,{info:t})}function Jp(){const{t:s}=R(),t=g(U=>U.providers),n=et(),a=g(U=>U.updateProvider),r=g(U=>U.addProviders),o=g(U=>U.removeProvider),[i,m]=l.useState(!1),[u,x]=l.useState(!1),[h,c]=l.useState(null),[f,d]=l.useState(null),[p,j]=l.useState(null),[b,A]=l.useState(null),[v,k]=l.useState(!1),[I,M]=l.useState(!1),[$,E]=l.useState(null),L=jt(U=>U.snapshot.revision),[T,C]=l.useState([]);l.useEffect(()=>{let U=!1;return window.electronAPI.providers.listOauth().then(B=>{U||C(B)}),()=>{U=!0}},[L]);const S=l.useMemo(()=>sd(t,T),[t,T]),W=l.useMemo(()=>{const U=new Map;for(const B of n)U.set(B.id,B.models.length);return U},[n]),q=async(U,B)=>{if(j(U.id),A(null),U.oauthAccountKey&&!U.oauthAccountPool&&!B?.skipLogout)try{await window.electronAPI.providers.oauthLogout(U.oauthAccountKey),await hd()}catch(ie){j(null),A({providerId:U.id,message:ie instanceof Error?ie.message:String(ie)});return}o(U.id),j(null),A(null)},N=()=>{const U=f;U&&q(U)},z=async()=>{k(!0),E(null);try{const U=await dd(t);ud(U,a),E(U);const B=Object.values(U).filter(F=>F.status==="failed"),ie=Object.keys(U).length-B.length;Te({type:B.length>0?"warning":"success",title:s("Fetched {{count}} providers",{count:ie}),...B.length>0?{description:s("{{count}} failed",{count:B.length})}:{}})}finally{k(!1)}},H=async()=>{M(!0);try{const U=await window.electronAPI.providers.refreshModelCatalog();cd(),Te({type:U.ok?"success":"warning",title:U.ok?s("Model info updated"):U.fromCache?s("Model info refresh failed, using cache"):s("Model info refresh failed")})}catch{Te({type:"error",title:s("Model info refresh failed")})}finally{M(!1)}};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-wrap items-end justify-between gap-x-4 gap-y-3","data-settings-row":"providers.root",children:[e.jsxs("div",{className:"min-w-0 flex-1 basis-56",children:[e.jsxs("h3",{className:"text-lg font-medium",children:[s("Model Providers"),e.jsx(Ze,{note:s("Newly enabled models can be picked right away. After changing a key or address, an open session uses it once you switch its model or start a new session.")})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("Manage model API providers for this app")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(y,{variant:"outline",size:"sm",disabled:I,onClick:()=>{H()},children:[I?e.jsx(Me,{className:"mr-1.5 h-4 w-4 animate-spin"}):e.jsx(ns,{className:"mr-1.5 h-4 w-4"}),s("Refresh model info")]}),e.jsxs(y,{variant:"outline",size:"sm",disabled:v||t.length===0,onClick:()=>{z()},children:[v?e.jsx(Me,{className:"mr-1.5 h-4 w-4 animate-spin"}):e.jsx(ns,{className:"mr-1.5 h-4 w-4"}),s("Fetch all models")]}),e.jsxs(y,{variant:"outline",size:"sm",onClick:()=>m(!0),children:[e.jsx(Nt,{className:"h-4 w-4 mr-1.5"}),s("Import from local apps")]}),e.jsxs(y,{size:"sm",onClick:()=>x(!0),children:[e.jsx(Re,{className:"h-4 w-4 mr-1.5"}),s("Add model or provider")]})]})]}),e.jsx($p,{}),e.jsx(Vp,{}),e.jsx(mx,{}),e.jsx(qp,{}),e.jsx(Up,{}),e.jsx(Hp,{}),Co(t).length>0&&!t.some(U=>U.oauthAccountPool)&&e.jsxs("div",{className:"space-y-1.5 rounded-md border p-3",children:[e.jsxs(y,{variant:"outline",size:"sm",onClick:()=>{const U=td(t,crypto.randomUUID());U&&r([U])>0&&c(U)},children:[e.jsx(Re,{className:"mr-1.5 h-3.5 w-3.5"}),s("Create ChatGPT account pool")]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Pool entries do not show a single account quota. Fixed-account entries remain unchanged.")})]}),t.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx(_n,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 text-sm font-medium",children:s("No providers yet")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:s("Import providers from local apps or use the unified setup to get started")})]}):e.jsx("div",{className:"space-y-1",children:S.map(U=>{const B=T.find(F=>F.id===U.vendorId),ie=U.vendorId===nd?s("Custom"):U.label;return e.jsxs("div",{className:"rounded-md px-3 py-2",children:[e.jsxs("div",{className:"flex items-baseline gap-1.5",children:[e.jsx("span",{className:"text-[11px] font-semibold tracking-wide text-muted-foreground",children:ie}),e.jsx("span",{className:"text-[11px] text-muted-foreground/60",children:U.providers.length})]}),e.jsx("div",{className:"mt-1.5 space-y-1 border-l pl-3",children:U.providers.map(F=>{const X=!!F.oauthAccountKey,V=W.get(F.id)??F.models.length,le=F.oauthAccountKey&&!F.oauthAccountPool?B?.accounts.find(ue=>ue.key===F.oauthAccountKey):void 0,_=F.oauthAccountPool?Fn(F,s):X?le?.email??F.oauthAccountKey??F.name:F.name,de=$?.[F.id];return e.jsxs(l.Fragment,{children:[e.jsxs("div",{className:"group flex items-start justify-between gap-3 rounded-md px-3 py-2 transition-colors hover:bg-accent/50","data-settings-row":`providers.${F.id}`,children:[e.jsxs("div",{className:"min-w-0 flex-1 overflow-hidden",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[X?e.jsx(ad,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}):e.jsx(rd,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx("span",{className:K("truncate text-sm font-medium",!F.enabled&&"text-muted-foreground line-through"),children:_}),X?le?.plan&&e.jsx(se,{variant:"outline",className:"shrink-0 text-[10px] uppercase",children:le.plan}):e.jsx(se,{variant:"outline",className:"shrink-0 text-[11px]",children:od[F.api]??F.api}),F.importedFrom&&e.jsx(se,{variant:"secondary",className:"shrink-0 text-[11px]",children:F.importedFrom}),e.jsx("span",{className:"min-w-0 truncate text-xs text-muted-foreground",children:[X?void 0:F.baseUrl,F.oauthAccountPool?s("{{count}} accounts",{count:F.oauthAccountPool.accountKeys.length}):void 0,V>0?s("{{count}} models",{count:V}):void 0].filter(Boolean).join(" · ")})]}),ln(F)&&e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:s("Classification only, not for chat")}),F.oauthAccountKey&&!F.oauthAccountPool&&e.jsx(Yp,{accountKey:F.oauthAccountKey})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1 pt-0.5",children:[e.jsx(y,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",onClick:()=>c(F),children:e.jsx(hs,{className:"h-3.5 w-3.5"})}),e.jsx(y,{variant:"ghost",size:"icon",disabled:p===F.id,className:K("h-7 w-7 text-muted-foreground opacity-0 transition-opacity hover:text-destructive group-hover:opacity-100",p===F.id&&"opacity-100"),onClick:()=>d(F),children:p===F.id?e.jsx(Me,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Pe,{className:"h-3.5 w-3.5"})}),e.jsx(ce,{checked:F.enabled,onCheckedChange:ue=>a(F.id,{enabled:ue})})]})]}),b?.providerId===F.id&&e.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-md border border-destructive/30 bg-destructive/5 px-3 py-1.5 text-xs text-destructive",children:[e.jsx("span",{className:"min-w-0 truncate",children:s("Sign-out failed: {{message}}",{message:b.message})}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(y,{variant:"outline",size:"sm",className:"h-6 px-2 text-[11px]",onClick:()=>{q(F)},children:s("Retry")}),e.jsx(y,{variant:"ghost",size:"sm",className:"h-6 px-2 text-[11px] text-destructive hover:text-destructive",onClick:()=>{q(F,{skipLogout:!0})},children:s("Delete anyway")})]})]}),de?.status==="failed"&&e.jsx("div",{className:"flex items-center justify-between gap-2 rounded-md border border-destructive/30 bg-destructive/5 px-3 py-1.5 text-xs text-destructive",children:e.jsxs("span",{className:"min-w-0 truncate",children:[s("Fetch failed"),": ",de.message]})})]},F.id)})})]},U.vendorId)})}),e.jsx(id,{open:i,onOpenChange:m}),e.jsx(ld,{open:u,onOpenChange:x}),e.jsx(Kp,{provider:h,onClose:()=>c(null)}),e.jsx(Gr,{open:f!==null,onOpenChange:U=>{U||d(null)},title:s("Remove provider?"),description:f?f.oauthAccountKey&&!f.oauthAccountPool?s("Removing this also signs out {{name}}. Other accounts for the same vendor stay signed in.",{name:f.name}):s('This permanently deletes the "{{name}}" provider configuration.',{name:f.name}):void 0,confirmLabel:s("Remove"),onConfirm:N})]})}const Xp=2e3,jr=50,Vs="",Qp=[{id:"app",label:"App processes"},{id:"agent",label:"Agent and tools"},{id:"child",label:"Other child processes"}],fn={sessions:["Conversation history","Conversation transcripts and usage ledger."],coworkers:["Coworker transcripts","Coworker journals; only those of deleted conversations are cleaned."],toolOutputs:["Tool outputs","Saved long tool outputs; only those of deleted conversations are cleaned."],memory:["Memory","Memory database and working memory."],models:["Local models","Downloaded embedding, chat and speech models."],runtimes:["Runtimes","Bundled tools, speech runtime and GPU backends."],worktrees:["Worktrees","Isolated worktrees created for conversations."],snapshots:["Change snapshots","Baselines for the Changes panel."],browser:["Browser data","Cookies, storage and cache of the built-in browser."],cache:["Cache","Rebuildable caches; cleaning is safe."],logs:["Logs","Task and memory logs; files written in the last 24 hours are kept."],backups:["Backups","Configuration backup files; files from the last 24 hours are kept."],config:["Configuration","Settings, instructions, prompts and credentials."],other:["Other","Chromium profile data and other files."]};function Zp(s,t){switch(s){case"main":return t("Main process");case"window":return t("Window");case"browser":return t("Built-in browser");case"gpu":return"GPU";case"service":return t("Service");case"agent":return"Agent";case"tool":return t("Tool");default:return t("Child process")}}function ef(s,t){return s.id==="data"?t("App data"):t("Worktree directory")}function sf(s,t){return s.role!=="window"?s.name:s.name==="Main window"?t("Main window"):s.name==="Settings"?t("Settings"):s.name}function tf(s){return`${s.toFixed(1)}%`}function nf(){const{t:s}=R(),[t,n]=l.useState("cpu");return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("Resources")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("CPU, memory and disk usage of EnsoCode and the processes it started.")})]}),e.jsxs(Qs,{value:t,onValueChange:a=>n(a),children:[e.jsxs(Zs,{children:[e.jsx(Je,{value:"cpu",children:"CPU"}),e.jsx(Je,{value:"memory",children:s("RAM")}),e.jsx(Je,{value:"storage",children:s("Storage")})]}),e.jsx(Ws,{value:"cpu",className:"pt-4",children:t==="cpu"&&e.jsx(vr,{metric:"cpu"})}),e.jsx(Ws,{value:"memory",className:"pt-4",children:t==="memory"&&e.jsx(vr,{metric:"memory"})}),e.jsx(Ws,{value:"storage",className:"pt-4",children:t==="storage"&&e.jsx(rf,{})})]})]})}function vr({metric:s}){const{t}=R(),[n,a]=l.useState(null),[r,o]=l.useState(null);if(l.useEffect(()=>{let x=!1,h;const c=async()=>{try{const f=await window.electronAPI.resources.sample();if(x)return;a(f),o(null)}catch(f){x||o(f instanceof Error?f.message:String(f))}x||(h=setTimeout(c,Xp))};return c(),()=>{x=!0,clearTimeout(h)}},[]),r&&!n)return e.jsx("p",{className:"text-sm text-destructive",children:r});if(!n)return e.jsx("p",{className:"text-sm text-muted-foreground",children:t("Loading...")});const i=s==="cpu"?tf:me,m=s==="cpu"?{app:n.cpu.app,system:n.cpu.system,total:100}:n.memory,u=x=>s==="cpu"?x.cpu:x.memory;return e.jsxs("div",{className:"space-y-4",children:[e.jsx(oi,{app:m.app,system:Math.max(m.system,m.app),total:m.total,format:i}),Qp.map(x=>{const h=n.processes.filter(c=>c.group===x.id).sort((c,f)=>u(f)-u(c));return h.length===0?null:e.jsxs("div",{className:"rounded-lg border",children:[e.jsxs("div",{className:"flex items-center justify-between border-b px-3 py-2 text-sm font-medium",children:[e.jsx("span",{children:t(x.label)}),e.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:i(h.reduce((c,f)=>c+u(f),0))})]}),e.jsx("div",{className:"divide-y",children:h.map(c=>e.jsxs("div",{className:"flex items-center gap-3 px-3 py-1.5 text-sm",children:[e.jsx("span",{className:"w-20 shrink-0 truncate text-xs text-muted-foreground",children:Zp(c.role,t)}),e.jsx("span",{className:"min-w-0 flex-1 truncate",title:c.command??c.name,children:sf(c,t)}),e.jsx("span",{className:"w-16 text-right font-mono text-xs text-muted-foreground",children:c.pid}),e.jsx("span",{className:"w-20 text-right font-mono text-xs",children:i(u(c))})]},c.pid))})]},x.id)})]})}function oi({app:s,system:t,total:n,format:a}){const{t:r}=R(),o=i=>`${n>0?Math.min(100,i/n*100):0}%`;return e.jsxs("div",{className:"space-y-3 rounded-lg border p-4",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"EnsoCode"}),e.jsx("div",{className:"font-mono text-2xl font-semibold",children:a(s)})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:r("System")}),e.jsxs("div",{className:"font-mono text-sm",children:[a(t)," / ",a(n)]})]})]}),e.jsxs("div",{className:"relative h-2 overflow-hidden rounded-full bg-muted",children:[e.jsx("div",{className:"absolute inset-y-0 left-0 bg-foreground/25",style:{width:o(t)}}),e.jsx("div",{className:"absolute inset-y-0 left-0 bg-foreground",style:{width:o(s)}})]})]})}function af(s,t){const n=[t("Freed {{size}}",{size:me(s.freedBytes)})];return s.removed>0&&n.push(t("{{count}} files removed",{count:s.removed})),s.skipped>0&&n.push(t("{{count}} kept",{count:s.skipped})),s.failed>0&&n.push(t("{{count}} failed",{count:s.failed})),n.join(" · ")}function rf(){const{t:s}=R(),[t,n]=l.useState(null),[a,r]=l.useState("scan"),[o,i]=l.useState(null),[m,u]=l.useState(null),[x,h]=l.useState(null),[c,f]=l.useState(null),d=l.useCallback(async(v,k)=>{r(v),u(null),i(null);try{n(await k())}catch(I){const M=I instanceof Error?I.message:String(I);M.includes("Scan cancelled")||u(M)}finally{r(null),i(null)}},[]),p=l.useCallback(()=>d("scan",()=>window.electronAPI.resources.scanStorage()),[d]),j=v=>d(v,async()=>{const k=await window.electronAPI.resources.cleanStorage(v);return Te({type:k.failed>0?"warning":"success",title:s("{{name}} cleaned",{name:s(fn[v][0])}),description:af(k,s)}),k.snapshot});l.useEffect(()=>{const v=window.electronAPI.resources.onScanProgress(i);return window.electronAPI.resources.lastStorage().then(k=>{k&&n(I=>I??k)}),p(),()=>{v(),window.electronAPI.resources.cancelScan()}},[p]);const b=t?[...t.categories].filter(v=>v.bytes>0).sort((v,k)=>k.bytes-v.bytes):[],A=l.useMemo(()=>{const v=new Map;for(const k of t?.roots??[])v.set(k.volumeId,[...v.get(k.volumeId)??[],k]);return[...v.values()]},[t]);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("p",{className:"min-w-0 truncate text-xs text-muted-foreground",children:a==="scan"?o?s("Scanning {{count}} files · {{size}}",{count:o.files.toLocaleString(),size:me(o.bytes)}):s("Scanning..."):t?s("Scanned at {{time}} · took {{seconds}}s",{time:new Date(t.scannedAt).toLocaleTimeString(),seconds:(t.durationMs/1e3).toFixed(1)}):null}),a==="scan"?e.jsx(y,{variant:"ghost",size:"sm",onClick:()=>{window.electronAPI.resources.cancelScan()},children:s("Cancel")}):e.jsx(y,{variant:"ghost",size:"icon-sm",onClick:()=>{p()},disabled:a!==null,"aria-label":s("Refresh"),children:e.jsx(ns,{})})]}),m&&e.jsx("p",{className:"text-sm text-destructive",children:m}),t&&t.errorCount>0&&e.jsxs("p",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",title:t.errors.join(`