@ensocode/server 0.3.12 → 0.3.13
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.
- package/out/phone/assets/EditDiff-B3HxLrbF.js +28 -0
- package/out/phone/assets/ReadFileView-BFpGH-kK.js +7 -0
- package/out/phone/assets/{abnfDiagram-VCTEODGH-D-9apHOZ.js → abnfDiagram-VCTEODGH-BNvyPGoF.js} +1 -1
- package/out/phone/assets/architecture-7GRP2DOG-Duql1LsL.js +1 -0
- package/out/phone/assets/{architectureDiagram-5GKGNRK7-B7ti5Yuy.js → architectureDiagram-5GKGNRK7-1bhpTEFA.js} +1 -1
- package/out/phone/assets/{blockDiagram-I7D4REHJ-CMg6PHJB.js → blockDiagram-I7D4REHJ-Bo9UMudu.js} +1 -1
- package/out/phone/assets/{c4Diagram-7LVT6UL2-YtDbC01g.js → c4Diagram-7LVT6UL2-YS11cig2.js} +1 -1
- package/out/phone/assets/channel-BPoIHov1.js +1 -0
- package/out/phone/assets/{chunk-4HAMMTFA-Djg6ctlZ.js → chunk-4HAMMTFA-gA-CzNGD.js} +1 -1
- package/out/phone/assets/{chunk-75Z2AOVW-Be2kq0FP.js → chunk-75Z2AOVW-BL_5b1Dw.js} +1 -1
- package/out/phone/assets/{chunk-DU6HZSFF-d5JZiOMy.js → chunk-DU6HZSFF-BpNlAs9R.js} +1 -1
- package/out/phone/assets/{chunk-F27PBJKO-DHBQ6nrV.js → chunk-F27PBJKO-lsKx96Nt.js} +1 -1
- package/out/phone/assets/{chunk-GMAD6QVW-BatU6uXC.js → chunk-GMAD6QVW-CxbljbtE.js} +1 -1
- package/out/phone/assets/{chunk-GVQU2GXP-CiyvoRIy.js → chunk-GVQU2GXP-CTO3kTOF.js} +1 -1
- package/out/phone/assets/{chunk-IMKFNOWR-vOQaK90i.js → chunk-IMKFNOWR-Cq8XlkcB.js} +1 -1
- package/out/phone/assets/{chunk-L3NEJ4N5-CPykFzBy.js → chunk-L3NEJ4N5-CvIm0JX7.js} +1 -1
- package/out/phone/assets/{chunk-OSK3NFVY-q4NiGH59.js → chunk-OSK3NFVY-Cj3ilTL-.js} +1 -1
- package/out/phone/assets/{chunk-P2QGCYS3-DUV9S_qP.js → chunk-P2QGCYS3-B-twI_Fz.js} +1 -1
- package/out/phone/assets/{chunk-POPQ4Y6H-CjycswNE.js → chunk-POPQ4Y6H-lPQttJ5s.js} +1 -1
- package/out/phone/assets/{chunk-PWAF6VOD-Dben6plA.js → chunk-PWAF6VOD-DjwqZuIR.js} +1 -1
- package/out/phone/assets/{chunk-SHT3W25Y-D2hK_jmb.js → chunk-SHT3W25Y-BWRVin1H.js} +1 -1
- package/out/phone/assets/{chunk-SVP7TREG-DLtgLN89.js → chunk-SVP7TREG-CGLhvnsS.js} +1 -1
- package/out/phone/assets/{chunk-TICWLB2K-BeBB0_0w.js → chunk-TICWLB2K-DkFUa03q.js} +1 -1
- package/out/phone/assets/classDiagram-ZZMXUADV-CIR76lHP.js +1 -0
- package/out/phone/assets/classDiagram-v2-VYDZK3BY-CIR76lHP.js +1 -0
- package/out/phone/assets/codeHighlighter-jQti-W31.js +1346 -0
- package/out/phone/assets/{cynefin-OW5HDTMX-CsDdLZPP.js → cynefin-OW5HDTMX-L8oWVu5S.js} +1 -1
- package/out/phone/assets/{cynefinDiagram-5FMLGOSQ-BcaPty-s.js → cynefinDiagram-5FMLGOSQ-DH8-4p4N.js} +1 -1
- package/out/phone/assets/{dagre-GXQ25YYZ-o7dqm5ri.js → dagre-GXQ25YYZ-HhLDmcu9.js} +1 -1
- package/out/phone/assets/desk-CixRGdTk.js +52 -0
- package/out/phone/assets/{diagram-S7CK7UJ4-B5m8q3yP.js → diagram-S7CK7UJ4-CeIbR3Ir.js} +1 -1
- package/out/phone/assets/{diagram-UQ7AKVKN-_lP617OW.js → diagram-UQ7AKVKN-BQ84Qnq6.js} +1 -1
- package/out/phone/assets/{diagram-VSXAHHWV-D16twHR0.js → diagram-VSXAHHWV-aF_J57fD.js} +1 -1
- package/out/phone/assets/{diagram-VX7I27RA-BT8YSil1.js → diagram-VX7I27RA-Bg1ZqM4Y.js} +1 -1
- package/out/phone/assets/{diagram-Z3DM3KII-CiSuhrxd.js → diagram-Z3DM3KII-DjTkPAqa.js} +1 -1
- package/out/phone/assets/{ebnfDiagram-PWID7BFC-BbCXn4HA.js → ebnfDiagram-PWID7BFC-DPsH5Eky.js} +1 -1
- package/out/phone/assets/{erDiagram-RLTQ6QDP-5-xE_bP2.js → erDiagram-RLTQ6QDP-ExvY7e6T.js} +1 -1
- package/out/phone/assets/eventmodeling-NTZA5JFV-DYp-zWcL.js +1 -0
- package/out/phone/assets/flowDiagram-HODETNUW-CIU32By5.js +1 -0
- package/out/phone/assets/{ganttDiagram-EL5Y4UJY-Rqgggqg_.js → ganttDiagram-EL5Y4UJY-hCe06ucl.js} +1 -1
- package/out/phone/assets/{gitGraph-4MIJSDKK-Drt18ZKK.js → gitGraph-4MIJSDKK-BuZ6lDat.js} +1 -1
- package/out/phone/assets/{gitGraphDiagram-WWUBYQGX-BQ5y4d2H.js → gitGraphDiagram-WWUBYQGX-D-8aVxvj.js} +1 -1
- package/out/phone/assets/{info-A6RAGUB7-CpPeSHE0.js → info-A6RAGUB7-CrZtdoYs.js} +1 -1
- package/out/phone/assets/{infoDiagram-27XIBGKW-D3d9S0Y6.js → infoDiagram-27XIBGKW-BLRFHxtO.js} +1 -1
- package/out/phone/assets/{ishikawaDiagram-5VMMS53U-plFMqx62.js → ishikawaDiagram-5VMMS53U-D7SYWKoj.js} +1 -1
- package/out/phone/assets/{journeyDiagram-3NMN7TZE-CX-n-XXx.js → journeyDiagram-3NMN7TZE-BPsg7CQD.js} +1 -1
- package/out/phone/assets/{kanban-definition-UXKFOSKX-DrdTzKIc.js → kanban-definition-UXKFOSKX-CbPuNr-E.js} +1 -1
- package/out/phone/assets/{line-CqyaArNm.js → line-CkpKMiqK.js} +1 -1
- package/out/phone/assets/main-BCnf7dVM.js +264 -0
- package/out/phone/assets/main-nqB-uD3v.css +2 -0
- package/out/phone/assets/{mermaid-parser.core-CERMa6fg.js → mermaid-parser.core-RTq_mEm1.js} +3 -3
- package/out/phone/assets/{mermaid.core-CbGP2wFn.js → mermaid.core-D9LtIKua.js} +4 -4
- package/out/phone/assets/{mindmap-definition-YA3MSWOX-BxaIrov6.js → mindmap-definition-YA3MSWOX-8cGgRiRD.js} +1 -1
- package/out/phone/assets/{packet-AYTQ26CC-DguFQxPm.js → packet-AYTQ26CC-D9-eSn0v.js} +1 -1
- package/out/phone/assets/{pegDiagram-XKGWAZYB-t3td03dz.js → pegDiagram-XKGWAZYB-DztU_rIE.js} +1 -1
- package/out/phone/assets/{pie-WAS4IAKB-DoFu2rhu.js → pie-WAS4IAKB-Bk2Tqaq_.js} +1 -1
- package/out/phone/assets/{pieDiagram-E7YTZNPT-DctHLSL8.js → pieDiagram-E7YTZNPT-Dm_3mJ9_.js} +1 -1
- package/out/phone/assets/{quadrantDiagram-AXDQQJYC-Br7-ImNr.js → quadrantDiagram-AXDQQJYC-lKskzjzu.js} +1 -1
- package/out/phone/assets/{radar-RG4KPBEZ-BDjTOHD8.js → radar-RG4KPBEZ-B2z8Txd8.js} +1 -1
- package/out/phone/assets/{railroad-74A4TZTK-v8vsrpxb.js → railroad-74A4TZTK-11VmdALq.js} +1 -1
- package/out/phone/assets/railroad-abnf-HS5TGJTU-BkSycwye.js +1 -0
- package/out/phone/assets/railroad-ebnf-LZEXJU2U-BsPIU3iV.js +1 -0
- package/out/phone/assets/railroad-peg-WCYAUIDC-Cy8G7u5C.js +1 -0
- package/out/phone/assets/{railroadDiagram-O6MQD6OU-DtH4qQrr.js → railroadDiagram-O6MQD6OU-Dr0NTIA6.js} +1 -1
- package/out/phone/assets/{requirementDiagram-BXWQKSXE-BSqejjZP.js → requirementDiagram-BXWQKSXE-C0W6h_5I.js} +1 -1
- package/out/phone/assets/{sankeyDiagram-P5KCCOFB-DsTWuNtL.js → sankeyDiagram-P5KCCOFB-CVJDathY.js} +1 -1
- package/out/phone/assets/{sequenceDiagram-WJ2MYXX4-zLMvPyPC.js → sequenceDiagram-WJ2MYXX4-BxHQTG6x.js} +1 -1
- package/out/phone/assets/shellUpdate-DPSfgHG3.js +36 -0
- package/out/phone/assets/{stateDiagram-D77RDMKH-DrBC05BN.js → stateDiagram-D77RDMKH-BO5MAjhs.js} +1 -1
- package/out/phone/assets/stateDiagram-v2-MP3YSRHH-B8IHc2bm.js +1 -0
- package/out/phone/assets/{swimlanes-42K2YHIH-B27-qSm5.js → swimlanes-42K2YHIH-DnhDPyy6.js} +1 -1
- package/out/phone/assets/swimlanesDiagram-VR7AAH4N-dmSDAN2F.js +8 -0
- package/out/phone/assets/{timeline-definition-24CTP7MA-8NDkGf5U.js → timeline-definition-24CTP7MA-bLEjS7re.js} +1 -1
- package/out/phone/assets/{treeView-Q6P3EWNA-B9BXwCDC.js → treeView-Q6P3EWNA-Ci-sA9wK.js} +1 -1
- package/out/phone/assets/{treemap-WGGIJYW6-B0IqbwdT.js → treemap-WGGIJYW6-BXCjzK65.js} +1 -1
- package/out/phone/assets/{vennDiagram-4TSXK5OY-Dp-aKgNa.js → vennDiagram-4TSXK5OY-DHsj5dRx.js} +1 -1
- package/out/phone/assets/{wardley-WFR3VGLG-B7FlADZf.js → wardley-WFR3VGLG-d8TdCu-H.js} +1 -1
- package/out/phone/assets/{wardleyDiagram-VM6X3IG4-BVntjQNl.js → wardleyDiagram-VM6X3IG4-DQFVP9qu.js} +1 -1
- package/out/phone/assets/{xychartDiagram-S5SC5T6Z-kgVJvkgO.js → xychartDiagram-S5SC5T6Z-Dni2Y0ov.js} +1 -1
- package/out/phone/desk.html +81 -2
- package/out/phone/index.html +51 -3
- package/out/phone/manifest.webmanifest +1 -0
- package/out/phone/splash/1125x2436-dark.png +0 -0
- package/out/phone/splash/1125x2436-light.png +0 -0
- package/out/phone/splash/1170x2532-dark.png +0 -0
- package/out/phone/splash/1170x2532-light.png +0 -0
- package/out/phone/splash/1179x2556-dark.png +0 -0
- package/out/phone/splash/1179x2556-light.png +0 -0
- package/out/phone/splash/1206x2622-dark.png +0 -0
- package/out/phone/splash/1206x2622-light.png +0 -0
- package/out/phone/splash/1242x2208-dark.png +0 -0
- package/out/phone/splash/1242x2208-light.png +0 -0
- package/out/phone/splash/1242x2688-dark.png +0 -0
- package/out/phone/splash/1242x2688-light.png +0 -0
- package/out/phone/splash/1260x2736-dark.png +0 -0
- package/out/phone/splash/1260x2736-light.png +0 -0
- package/out/phone/splash/1284x2778-dark.png +0 -0
- package/out/phone/splash/1284x2778-light.png +0 -0
- package/out/phone/splash/1290x2796-dark.png +0 -0
- package/out/phone/splash/1290x2796-light.png +0 -0
- package/out/phone/splash/1320x2868-dark.png +0 -0
- package/out/phone/splash/1320x2868-light.png +0 -0
- package/out/phone/splash/750x1334-dark.png +0 -0
- package/out/phone/splash/750x1334-light.png +0 -0
- package/out/phone/splash/828x1792-dark.png +0 -0
- package/out/phone/splash/828x1792-light.png +0 -0
- package/out/phone/sw.js +219 -6
- package/out/renderer/assets/EditDiff-DxxLuCEI.js +1 -0
- package/out/renderer/assets/File-Tz3MUtN6.js +1 -0
- package/out/renderer/assets/ReadFileView-DFoLPU04.js +4 -0
- package/out/renderer/assets/SidePanel-CL40W2RY.js +47 -0
- package/out/renderer/assets/SidePanel-D0m4IYxS.css +1 -0
- package/out/renderer/assets/Virtualizer-B0uwx_XV.js +1345 -0
- package/out/renderer/assets/{abnfDiagram-VCTEODGH-Bp0r3dKm.js → abnfDiagram-VCTEODGH-CJ9nn9eH.js} +1 -1
- package/out/renderer/assets/{arc-BD5HnhIt.js → arc-B8im8n0O.js} +1 -1
- package/out/renderer/assets/{architectureDiagram-5GKGNRK7-CgJHjETB.js → architectureDiagram-5GKGNRK7-BRSi5FBk.js} +1 -1
- package/out/renderer/assets/{blockDiagram-I7D4REHJ-5le9vk4G.js → blockDiagram-I7D4REHJ-CQ1wirIl.js} +1 -1
- package/out/renderer/assets/{c4Diagram-7LVT6UL2-B4DCe-qN.js → c4Diagram-7LVT6UL2-9HyLIioe.js} +1 -1
- package/out/renderer/assets/channel-DjB0ww6b.js +1 -0
- package/out/renderer/assets/{chunk-2Q5K7J3B-DIxWfJHE.js → chunk-2Q5K7J3B-BwC9g3bx.js} +1 -1
- package/out/renderer/assets/{chunk-5VM5RSS4-D9j4om1l.js → chunk-5VM5RSS4-DMtgxPBL.js} +1 -1
- package/out/renderer/assets/{chunk-F27PBJKO-B_tGbKyc.js → chunk-F27PBJKO-DSi_XV5v.js} +1 -1
- package/out/renderer/assets/{chunk-IMKFNOWR-Cfffd1p9.js → chunk-IMKFNOWR-Dctc6Apj.js} +1 -1
- package/out/renderer/assets/{chunk-JWPE2WC7-BABZOPGb.js → chunk-JWPE2WC7-I2BD5qM7.js} +1 -1
- package/out/renderer/assets/{chunk-POPQ4Y6H-D-QyVpSn.js → chunk-POPQ4Y6H-k60pc4eT.js} +1 -1
- package/out/renderer/assets/{chunk-SVP7TREG-BghyPSd6.js → chunk-SVP7TREG-zCGemfqm.js} +1 -1
- package/out/renderer/assets/{chunk-TICWLB2K-CQmthy6z.js → chunk-TICWLB2K-CdDiHIq-.js} +1 -1
- package/out/renderer/assets/{chunk-XXDRQBXY-CDKsbyR7.js → chunk-XXDRQBXY-GYVDxVfN.js} +1 -1
- package/out/renderer/assets/classDiagram-ZZMXUADV-6SiAw1np.js +1 -0
- package/out/renderer/assets/classDiagram-v2-VYDZK3BY-6SiAw1np.js +1 -0
- package/out/renderer/assets/{cose-bilkent-JH36ORCC-oajViFnN.js → cose-bilkent-JH36ORCC-BnSAtUh-.js} +1 -1
- package/out/renderer/assets/{cynefin-OW5HDTMX-DMH1CUmI.js → cynefin-OW5HDTMX-DnQaS9VN.js} +1 -1
- package/out/renderer/assets/{cynefinDiagram-5FMLGOSQ-DVUJf9t0.js → cynefinDiagram-5FMLGOSQ-BNQdw0PV.js} +1 -1
- package/out/renderer/assets/{cytoscape-fcose-adTZ191M.js → cytoscape-fcose-CzkrRInm.js} +1 -1
- package/out/renderer/assets/{dagre-GXQ25YYZ-BXRWWNje.js → dagre-GXQ25YYZ-fG1vMsyn.js} +1 -1
- package/out/renderer/assets/{diagram-S7CK7UJ4-Dg7f2Dan.js → diagram-S7CK7UJ4-BcfAFVc2.js} +1 -1
- package/out/renderer/assets/{diagram-UQ7AKVKN-DsLRyZAt.js → diagram-UQ7AKVKN-D8f3Tsx9.js} +1 -1
- package/out/renderer/assets/{diagram-VSXAHHWV-3_LoodSS.js → diagram-VSXAHHWV-B-U9CIWt.js} +1 -1
- package/out/renderer/assets/{diagram-VX7I27RA-DQeZp2Cz.js → diagram-VX7I27RA-CX6ifTkJ.js} +1 -1
- package/out/renderer/assets/{diagram-Z3DM3KII-Dwil6g5m.js → diagram-Z3DM3KII-49dS9s3L.js} +1 -1
- package/out/renderer/assets/{ebnfDiagram-PWID7BFC-DecVNxpu.js → ebnfDiagram-PWID7BFC-CraGJRI7.js} +1 -1
- package/out/renderer/assets/{erDiagram-RLTQ6QDP-D2rmo2nP.js → erDiagram-RLTQ6QDP-CfMNvEoW.js} +1 -1
- package/out/renderer/assets/{flowDiagram-HODETNUW-_SF2dRBl.js → flowDiagram-HODETNUW-C8XM3p4T.js} +1 -1
- package/out/renderer/assets/{ganttDiagram-EL5Y4UJY-BoYWs5Ev.js → ganttDiagram-EL5Y4UJY-DlJBMKFX.js} +1 -1
- package/out/renderer/assets/{gitGraphDiagram-WWUBYQGX-BqRbZ3V0.js → gitGraphDiagram-WWUBYQGX-DvEzDsKF.js} +1 -1
- package/out/renderer/assets/globals-BFf1P-Y5.js +715 -0
- package/out/renderer/assets/globals-DUBhAVpU.css +1 -0
- package/out/renderer/assets/index-L4TTIP10.js +89 -0
- package/out/renderer/assets/{infoDiagram-27XIBGKW-CFt6xyuD.js → infoDiagram-27XIBGKW-CckfBO-R.js} +1 -1
- package/out/renderer/assets/{ishikawaDiagram-5VMMS53U-CZB8G4dD.js → ishikawaDiagram-5VMMS53U-mUoXchkB.js} +1 -1
- package/out/renderer/assets/{journeyDiagram-3NMN7TZE-CO2VRmpx.js → journeyDiagram-3NMN7TZE-zzLL0HFW.js} +1 -1
- package/out/renderer/assets/{kanban-definition-UXKFOSKX-DIqEnfMM.js → kanban-definition-UXKFOSKX-BJ_9aIhB.js} +1 -1
- package/out/renderer/assets/{layout-DXRKfO_Y.js → layout-3SRMHY7n.js} +1 -1
- package/out/renderer/assets/{linear-Cdx1AdZJ.js → linear-CWpclK_R.js} +1 -1
- package/out/renderer/assets/manifest-DOzTaB8J.js +525 -0
- package/out/renderer/assets/{mermaid.core-DuIO2jsm.js → mermaid.core-DORpmVi3.js} +5 -5
- package/out/renderer/assets/{mindmap-definition-YA3MSWOX-B5lvxG2M.js → mindmap-definition-YA3MSWOX-CYBlCqIB.js} +1 -1
- package/out/renderer/assets/{pegDiagram-XKGWAZYB-DCwHp-K3.js → pegDiagram-XKGWAZYB-DhWwLs4v.js} +1 -1
- package/out/renderer/assets/{pieDiagram-E7YTZNPT-Dq048Wh7.js → pieDiagram-E7YTZNPT-Bzpc57-A.js} +1 -1
- package/out/renderer/assets/{quadrantDiagram-AXDQQJYC-DwkFkAi_.js → quadrantDiagram-AXDQQJYC-spKXEbds.js} +1 -1
- package/out/renderer/assets/{railroadDiagram-O6MQD6OU-2NKvwLP-.js → railroadDiagram-O6MQD6OU-Br553px3.js} +1 -1
- package/out/renderer/assets/{requirementDiagram-BXWQKSXE-Bp44tNQ0.js → requirementDiagram-BXWQKSXE-CX-Dqij_.js} +1 -1
- package/out/renderer/assets/{sankeyDiagram-P5KCCOFB-C3TFp1NK.js → sankeyDiagram-P5KCCOFB-Bgx1W6B9.js} +1 -1
- package/out/renderer/assets/{sequenceDiagram-WJ2MYXX4-BTPoYQeW.js → sequenceDiagram-WJ2MYXX4-CKQv6pcU.js} +1 -1
- package/out/renderer/assets/sessionChanges-BLzNhRuv.js +31 -0
- package/out/renderer/assets/settings-Bsrw4ERp.js +25 -0
- package/out/renderer/assets/{sizeCapture-INFHLROL-DvNj5TDT.js → sizeCapture-INFHLROL-DtRedfRe.js} +1 -1
- package/out/renderer/assets/{stateDiagram-D77RDMKH-DC8YykNp.js → stateDiagram-D77RDMKH-CMP5owem.js} +1 -1
- package/out/renderer/assets/stateDiagram-v2-MP3YSRHH-6-731AqJ.js +1 -0
- package/out/renderer/assets/{swimlanes-42K2YHIH-0yL1nNkg.js → swimlanes-42K2YHIH-D30AvvmW.js} +1 -1
- package/out/renderer/assets/swimlanesDiagram-VR7AAH4N-B8KijqIT.js +8 -0
- package/out/renderer/assets/{timeline-definition-24CTP7MA-Pg-2roGv.js → timeline-definition-24CTP7MA-CsZAMmMZ.js} +1 -1
- package/out/renderer/assets/{vennDiagram-4TSXK5OY-D0af5K4E.js → vennDiagram-4TSXK5OY-COQ7L1f7.js} +1 -1
- package/out/renderer/assets/{wardleyDiagram-VM6X3IG4-CB_nIy_l.js → wardleyDiagram-VM6X3IG4-dqMWLTCs.js} +1 -1
- package/out/renderer/assets/{xychartDiagram-S5SC5T6Z-A26Yld8R.js → xychartDiagram-S5SC5T6Z-DX4clIYP.js} +1 -1
- package/out/renderer/index.html +3 -4
- package/out/renderer/plugin-view.html +37 -0
- package/out/renderer/settings.html +7 -4
- package/out/renderer/web-preload.js +28 -28
- package/out/server/agent.js +663 -124
- package/out/server/chunks/{agent-D33nI7fP.js → agent-BbNq8i9j.js} +909 -592
- package/out/server/chunks/conversationsMove-CvFPFHaa.js +587 -0
- package/out/server/chunks/{gpuBackendInstall-CRzfB150.js → gpuBackendInstall-jAzoFq7U.js} +3 -3
- package/out/server/chunks/{loadProvider-4Y15KP7W.js → loadProvider-NdOVbsHi.js} +2 -2
- package/out/server/chunks/{manifest-wlfh-NN5.js → manifest-BPXFscqI.js} +9 -3
- package/out/server/chunks/registry-BhoHPSKn.js +3353 -0
- package/out/server/chunks/{resources-DzUshg1j.js → resources-BfbTkFP0.js} +21 -10
- package/out/server/chunks/sendImage-BCNW9JRV.js +418 -0
- package/out/server/chunks/{storageScanWorker-CuttDIGS.js → storageScanWorker-CR7HbOWG.js} +2 -2
- package/out/server/chunks/{storageScanWorker-CX8O_DlF.js → storageScanWorker-DjFyHTye.js} +2 -2
- package/out/server/chunks/{workflowPresets-CAA0AY6f.js → workflowPresets-C2T1BzA2.js} +863 -662
- package/out/server/index.js +13584 -15047
- package/out/server/memory-service.js +5008 -0
- package/out/server/plugin-host.js +2 -2
- package/package.json +1 -1
- package/out/phone/assets/EnsoNerdSymbolsMono-Regular-TdeMQojc.ttf +0 -0
- package/out/phone/assets/architecture-7GRP2DOG-ihVIDRRt.js +0 -1
- package/out/phone/assets/channel-BQsoblXW.js +0 -1
- package/out/phone/assets/classDiagram-ZZMXUADV-rwnxFDXp.js +0 -1
- package/out/phone/assets/classDiagram-v2-VYDZK3BY-rwnxFDXp.js +0 -1
- package/out/phone/assets/desk-DNf6lCoq.js +0 -2
- package/out/phone/assets/eventmodeling-NTZA5JFV-BVS2RGt-.js +0 -1
- package/out/phone/assets/flowDiagram-HODETNUW-BSlxj9Uk.js +0 -1
- package/out/phone/assets/main-BGlFv7yA.js +0 -1658
- package/out/phone/assets/main-BS1SSCau.css +0 -1
- package/out/phone/assets/railroad-abnf-HS5TGJTU-CUELjEtC.js +0 -1
- package/out/phone/assets/railroad-ebnf-LZEXJU2U-DdIokM4i.js +0 -1
- package/out/phone/assets/railroad-peg-WCYAUIDC-DYyy0B-_.js +0 -1
- package/out/phone/assets/stateDiagram-v2-MP3YSRHH-DT7BlwvF.js +0 -1
- package/out/phone/assets/storage-BeJvYXAx.js +0 -36
- package/out/phone/assets/swimlanesDiagram-VR7AAH4N-CWnm4v0A.js +0 -8
- package/out/renderer/assets/channel-D-HltTAP.js +0 -1
- package/out/renderer/assets/classDiagram-ZZMXUADV-BCWhgMul.js +0 -1
- package/out/renderer/assets/classDiagram-v2-VYDZK3BY-BCWhgMul.js +0 -1
- package/out/renderer/assets/globals-BEwCf508.css +0 -1
- package/out/renderer/assets/globals-C3zxoqqH.js +0 -2603
- package/out/renderer/assets/index-9vqh4wxi.js +0 -133
- package/out/renderer/assets/index-F_0FxVZ_.css +0 -1
- package/out/renderer/assets/settings-DlDHkOe2.js +0 -25
- package/out/renderer/assets/stateDiagram-v2-MP3YSRHH-B4rCEEYH.js +0 -1
- package/out/renderer/assets/swimlanesDiagram-VR7AAH4N-zQqW8MJ5.js +0 -8
- package/out/server/chunks/conversationsMove-CJZfkj55.js +0 -57
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./globals-C3zxoqqH.js","./globals-BEwCf508.css"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{c as Te,w as Si,D as la,j as e,A as Ii,r as l,u as Ur,a as $r,b as kn,d as Vr,t as Kr,C as ca,e as H,I as Q,f as Ai,X as bs,h as Ei,i as Mi,Z as ls,k as Pi,S as Ti,l as Ri,m as Oi,n as Di,o as Li,p as R,q as g,B as y,s as ve,v as be,x as ye,y as we,z as Ye,E as Ne,F as Le,G as Ie,H as Gr,J as Me,K as da,L as zi,M as xt,N as ht,O as se,P as te,Q as ne,R as ae,T as Z,U as _i,V as ts,W as Fi,Y as Bi,_ as Wr,$ as Ui,a0 as _t,a1 as Hr,a2 as $i,a3 as qr,a4 as Vi,a5 as ua,a6 as Yr,a7 as Ki,a8 as Gi,a9 as Wi,aa as ma,ab as Hi,ac as qi,ad as Yi,ae as Ji,af as Xi,ag as Qi,ah as Zi,ai as el,aj as sl,ak as tl,al as nl,am as Ft,an as al,ao as rl,ap as ol,aq as il,ar as ll,as as cl,at as Ae,au as Cn,av as gt,aw as Ke,ax as Jr,ay as Ps,az as Ge,aA as He,aB as Sn,aC as Rs,aD as In,aE as An,aF as En,aG as Mn,aH as Pn,aI as Tn,aJ as Rn,aK as ns,aL as xa,aM as ha,aN as Ue,aO as ss,aP as dl,aQ as ul,aR as Xr,aS as ce,aT as pa,aU as Bt,aV as fa,aW as ga,aX as jt,aY as ml,aZ as xl,a_ as Ut,a$ as vt,b0 as St,b1 as Qr,b2 as On,b3 as hl,b4 as Dn,b5 as Zr,b6 as pl,b7 as fl,b8 as gl,b9 as eo,ba as jl,bb as vl,bc as bl,bd as so,be as Ys,bf as it,bg as yl,bh as Ln,bi as wl,bj as Nl,bk as zn,bl as cs,bm as kl,bn as Cl,bo as to,bp as Sl,bq as Il,br as Al,bs as no,bt as _n,bu as Pe,bv as ie,bw as Re,bx as El,by as Ml,bz as Pl,bA as Tl,bB as Rl,bC as ja,bD as Ol,bE as Dl,bF as Js,bG as Xs,bH as Je,bI as Ks,bJ as ln,bK as Ll,bL as zl,bM as cn,bN as xs,bO as ao,bP as _l,bQ as Fl,bR as Fn,bS as Bl,bT as va,bU as ro,bV as Ul,bW as $l,bX as oo,bY as We,bZ as Vl,b_ as bt,b$ as Kl,c0 as ba,c1 as Gl,c2 as Wl,c3 as Hl,c4 as Ze,c5 as ql,c6 as ya,c7 as wa,c8 as Yl,c9 as Na,ca as Jl,cb as Xl,cc as Ql,cd as Zl,ce as qe,cf as $t,cg as ka,ch as ec,ci as sc,cj as io,ck as tc,cl as lo,cm as nc,cn as ac,co as rc,cp as oc,cq as Bn,cr as ic,cs as co,ct as lc,cu as cc,cv as Qs,cw as dc,cx as uc,cy as mc,cz as xc,cA as dn,cB as uo,cC as lt,cD as hc,cE as pc,cF as fc,cG as ue,cH as me,cI as It,cJ as Un,cK as mo,cL as $n,cM as xo,cN as un,cO as Ca,cP as mn,cQ as ho,cR as po,cS as gc,cT as fo,cU as jc,cV as vc,cW as bc,cX as yc,cY as wc,cZ as Nc,c_ as kc,c$ as Cc,d0 as Sc,d1 as Ic,d2 as Sa,d3 as go,d4 as jo,d5 as vo,d6 as bo,d7 as Ac,d8 as Ec,d9 as Ia,da as Gs,db as Mc,dc as yo,dd as wo,de as No,df as Pc,dg as Tc,dh as Rc,di as Oc,dj as Dc,dk as Lc,dl as zc,dm as _c,dn as Fc,dp as Bc,dq as Uc,dr as $c,ds as Vc,dt as ko,du as pt,dv as Us,dw as Co,dx as Kc,dy as Aa,dz as Gc,dA as Wc,dB as Hc,dC as qc,dD as Yc,dE as Jc,dF as Xc,dG as Qc,dH as Zc,dI as ed,dJ as sd,dK as xn,dL as td,dM as yt,dN as nd,dO as Vn,dP as So,dQ as Io,dR as Kn,dS as Ao,dT as Eo,dU as Mo,dV as Po,dW as To,dX as ad,dY as rd,dZ as od,d_ as id,d$ as ld,e0 as cd,e1 as dd,e2 as ud,e3 as md,e4 as xd,e5 as hd,e6 as pd,e7 as fd,e8 as gd,e9 as jd,ea as vd,eb as bd,ec as yd,ed as wd,ee as Ro,ef as Oo,eg as Do,eh as Nd,ei as Lo,ej as kd,ek as Cd,el as Sd,em as zo,en as Id,eo as Ad,ep as Ea,eq as ct,er as Ed,es as Md,et as Pd,eu as Td,ev as Rd,ew as Od,ex as Ma,ey as Dd,ez as Ld,eA as zd,eB as _d,eC as _o,eD as Fd,eE as Bd,eF as Ud,eG as wt,eH as $d,eI as Vd,eJ as Kd,eK as Gd,eL as ds,eM as Wd,eN as Hd,eO as qd,eP as Yd,eQ as Jd,eR as Xd,eS as Qd,eT as Zd,eU as eu,eV as Fo,eW as su,eX as tu,eY as nu,eZ as au,e_ as ru,e$ as ou,f0 as iu,f1 as lu,f2 as cu,f3 as du,f4 as uu,f5 as mu,f6 as xu,f7 as hu,f8 as pu,f9 as Pa,fa as fu,fb as gu,fc as Ta,fd as Ra,fe as ju}from"./globals-C3zxoqqH.js";import{c as Bo}from"./cytoscape.esm-DzSz-X2X.js";import{f as vu}from"./cytoscape-fcose-adTZ191M.js";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=Te("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=Te("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=Te("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=Te("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=Te("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=Te("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=Te("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"}]],Oa=Te("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=Te("image",Du);const zu=[["path",{d:"M10 8h.01",key:"1r9ogq"}],["path",{d:"M12 12h.01",key:"1mp3jc"}],["path",{d:"M14 8h.01",key:"1primd"}],["path",{d:"M16 12h.01",key:"1l6xoz"}],["path",{d:"M18 8h.01",key:"emo2bl"}],["path",{d:"M6 8h.01",key:"x9i8wu"}],["path",{d:"M7 16h10",key:"wp8him"}],["path",{d:"M8 12h.01",key:"czm47f"}],["rect",{width:"20",height:"16",x:"2",y:"4",rx:"2",key:"18n3k1"}]],_u=Te("keyboard",zu);const Fu=[["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"}]],Uo=Te("lock-keyhole",Fu);const Bu=[["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"}]],Uu=Te("palette",Bu);const $u=[["path",{d:"m15 15 6 6m-6-6v4.8m0-4.8h4.8",key:"17vawe"}],["path",{d:"M9 19.8V15m0 0H4.2M9 15l-6 6",key:"chjx8e"}],["path",{d:"M15 4.2V9m0 0h4.8M15 9l6-6",key:"lav6yq"}],["path",{d:"M9 4.2V9m0 0H4.2M9 9 3 3",key:"1pxi2q"}]],Vu=Te("shrink",$u);const Ku=[["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"}]],Gu=Te("store",Ku);const Wu=[["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"}]],Hu=Te("sun",Wu);const qu=[["path",{d:"M12 3v12",key:"1x0j5s"}],["path",{d:"m17 8-5-5-5 5",key:"7q97r8"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}]],$o=Te("upload",qu);function Yu(s){return s&&typeof s=="object"&&!Array.isArray(s)?s:null}function Ju(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 Xu(s){const t=Yu(s);if(!t||Object.keys(t).some(u=>!["providerId","modelId","protocol","baseUrl","apiKey"].includes(u)))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"||!Ju(o)||r!=="openai"&&r!=="openai-compatible"&&r!=="gemini"?null:{providerId:n,modelId:a,protocol:r,baseUrl:o,apiKey:i}}function Qu(s,t){if(s?.enabled!==!0||s.oauthAccountKey||s.oauthAccountPool||typeof s.apiKey!="string"||!s.apiKey.trim()||typeof s.baseUrl!="string")return null;let n;if(s.api==="google-generative-ai")n="gemini";else if(s.api==="openai-completions"||s.api==="openai-responses"){let o="";try{o=new URL(s.baseUrl).hostname.toLowerCase()}catch{}n=s.catalogId!=="__custom"&&(s.catalogId==="openai"||!s.catalogId&&o==="api.openai.com")?"openai":"openai-compatible"}else return null;const a=n==="gemini"?la["google-generative-ai"]:n==="openai"?la["openai-responses"]:"";let r=s.baseUrl.trim().replace(/\/+$/,"")||a;if(n==="gemini"&&r&&(r=Si(r,"v1beta")),n==="openai"&&r)try{new URL(r).pathname==="/"&&(r=`${r}/v1`)}catch{}return Xu({providerId:s.id,modelId:t,protocol:n,baseUrl:r,apiKey:s.apiKey})}function Zu(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 em(s){return s.flatMap(t=>{const n=Zu(t).filter(a=>Qu(t,a.id));return n.length?[{...t,models:n}]:[]})}function sm(s){const{multiple:t=!1,defaultValue:n,value:a,onValueChange:r,autoComplete:o,...i}=s;return e.jsx(Ii,{...i,selectionMode:t?"multiple":"single",selectedValue:a,defaultSelectedValue:n,onSelectedValueChange:r,formAutoComplete:o})}const tm=l.forwardRef(function(t,n){const{selected:a}=Ur();return t.keepMounted||a?e.jsx(nm,{...t,ref:n}):null}),nm=l.memo(l.forwardRef((s,t)=>{const{render:n,className:a,style:r,keepMounted:o,...i}=s,{selected:u}=Ur(),d=l.useRef(null),{transitionStatus:x,setMounted:p}=$r(u),f=kn("span",s,{ref:[t,d],state:{selected:u,transitionStatus:x},props:[{"aria-hidden":!0,children:"✔️"},i],stateAttributesMapping:Kr});return Vr({open:u,ref:d,onComplete(){u||p(!1)}}),f})),Gn=l.createContext({chipsRef:null,multiple:!1,rootRef:null});function am(s){const t=l.useRef(null),n=l.useRef(null);return e.jsx(Gn.Provider,{value:{chipsRef:t,multiple:!!s.multiple,rootRef:n},children:e.jsx("div",{ref:n,className:"contents",children:e.jsx(sm,{...s})})})}function rm({className:s,showTrigger:t=!0,showClear:n=!1,startAddon:a,size:r,...o}){const{multiple:i}=l.useContext(Gn),u=r??"default";return i?e.jsx(ca,{className:H("min-w-12 flex-1 text-base outline-none sm:text-sm [[data-slot=combobox-chip]+&]:ps-0.5",u==="sm"?"ps-1.5":"ps-2",s),"data-size":typeof u=="string"?u:void 0,"data-slot":"combobox-input",size:typeof u=="number"?u: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(ca,{className:H(a&&"data-[size=sm]:*:data-[slot=combobox-input]:ps-[calc(--spacing(7.5)-1px)] *:data-[slot=combobox-input]:ps-[calc(--spacing(8.5)-1px)] sm:data-[size=sm]:*:data-[slot=combobox-input]:ps-[calc(--spacing(7)-1px)] sm:*:data-[slot=combobox-input]:ps-[calc(--spacing(8)-1px)]",u==="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(Q,{className:"has-disabled:opacity-100",size:u}),...o}),t&&e.jsx(om,{className:H("-translate-y-1/2 absolute top-1/2 inline-flex size-8 shrink-0 cursor-pointer items-center justify-center rounded-md border border-transparent opacity-80 outline-none transition-opacity pointer-coarse:after:absolute pointer-coarse:after:min-h-11 pointer-coarse:after:min-w-11 hover:opacity-100 has-[+[data-slot=combobox-clear]]:hidden sm:size-7 [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",u==="sm"?"end-0":"end-0.5"),children:e.jsx(Ai,{})}),n&&e.jsx(dm,{className:H("-translate-y-1/2 absolute top-1/2 inline-flex size-8 shrink-0 cursor-pointer items-center justify-center rounded-md border border-transparent opacity-80 outline-none transition-opacity pointer-coarse:after:absolute pointer-coarse:after:min-h-11 pointer-coarse:after:min-w-11 hover:opacity-100 has-[+[data-slot=combobox-clear]]:hidden sm:size-7 [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",u==="sm"?"end-0":"end-0.5"),children:e.jsx(bs,{})})]})}function om({className:s,...t}){return e.jsx(Di,{className:s,"data-slot":"combobox-trigger",...t})}function im({className:s,children:t,sideOffset:n=4,zIndex:a,...r}){const{chipsRef:o,rootRef:i}=l.useContext(Gn);let u=ls.DROPDOWN;if(a!==void 0)u=a;else{const d=i?.current;d&&(d.closest('[data-slot="dialog-popup"] [data-slot="dialog-popup"]')?u=ls.DROPDOWN_IN_NESTED_MODAL:d.closest('[data-slot="dialog-popup"]')&&(u=ls.DROPDOWN_IN_MODAL))}return e.jsx(Ei,{children:e.jsx(Mi,{anchor:o,className:"select-none",style:{zIndex:u},"data-slot":"combobox-positioner",sideOffset:n,children:e.jsx("span",{className:H("relative flex max-h-full origin-(--transform-origin) rounded-lg border bg-popover bg-clip-padding transition-[scale,opacity] before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-lg)-1px)] before:shadow-lg has-data-starting-style:scale-98 has-data-starting-style:opacity-0 dark:not-in-data-[slot=group]:bg-clip-border",s),children:e.jsx(Pi,{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 lm({className:s,children:t,endAddon:n,...a}){return e.jsxs(Oi,{className:H("grid min-h-8 in-data-[side=none]:min-w-[calc(var(--anchor-width)+1.25rem)] cursor-default grid-cols-[1rem_1fr_auto] items-center gap-2 rounded-sm py-1 ps-2 pe-4 text-base outline-none data-disabled:pointer-events-none data-highlighted:bg-accent data-highlighted:text-accent-foreground data-disabled:opacity-64 sm:min-h-7 sm:text-sm [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",s),"data-slot":"combobox-item",...a,children:[e.jsx(tm,{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 cm({className:s,...t}){return e.jsx(Ti,{scrollbarGutter:!0,scrollFade:!0,children:e.jsx(Ri,{className:H("not-empty:scroll-py-1 not-empty:px-1 not-empty:py-1 in-data-has-overflow-y:pe-3",s),"data-slot":"combobox-list",...t})})}function dm({className:s,...t}){return e.jsx(Li,{className:s,"data-slot":"combobox-clear",...t})}function um(){const{t:s}=R(),t=g(m=>m.contextMenuOpen),n=g(m=>m.setContextMenuOpen),[a,r]=l.useState(!1),[o,i]=l.useState(!1),u=m=>m.target==="reveal"?s("File manager"):m.target==="vscode"?s("VS Code"):m.applicationPath.split(/[/\\]/).at(-1)?.replace(/\.(exe|app)$/i,"")||m.applicationPath,d=t.filter(m=>m.enabled).map(u),x=d.length?`${d.slice(0,2).join(", ")}${d.length>2?` +${d.length-2}`:""}`:s("No opening methods enabled"),p=m=>{if(m.length>32){Me({type:"error",title:s("Context menu opening"),description:s("You can configure up to 32 opening methods.")});return}n(m)},c=(m,h)=>{const j=g.getState().contextMenuOpen;n(j.map(b=>b.id===m.id?{...b,enabled:h}:b))},f=async()=>{i(!0);try{const m=await window.electronAPI.dialog.selectFile();if(!m)return;if(!Gr(m)){Me({type:"error",title:s("Context menu opening"),description:s("The selected application path is invalid.")});return}const h=g.getState().contextMenuOpen,j=da(m),b=h.find(A=>A.target==="application"&&da(A.applicationPath)===j);if(b){p(h.map(A=>A.id===b.id?{...A,enabled:!0}:A));return}p([...h,{id:crypto.randomUUID(),target:"application",applicationPath:m,enabled:!0}])}catch(m){Me({type:"error",title:s("Context menu opening"),description:m instanceof Error?m.message:String(m)})}finally{i(!1)}};return e.jsxs("div",{className:"space-y-2 rounded-md border p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("h5",{className:"text-sm font-medium",children:s("Context menu opening")}),e.jsx(y,{variant:"outline",size:"sm",onClick:()=>r(!0),children:s("Configure list")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Select the opening methods shown in file link context menus. You can add multiple applications.")}),e.jsx("p",{className:"truncate text-xs text-muted-foreground",title:d.join(", "),children:x}),e.jsx(ve,{open:a,onOpenChange:r,children:e.jsxs(be,{zIndexLevel:"nested",children:[e.jsxs(ye,{children:[e.jsx(we,{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(Ne,{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(m=>{const h=u(m);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:m.enabled,disabled:o,"aria-label":h,onCheckedChange:j=>c(m,j)}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-sm",title:h,children:h}),m.target==="application"&&e.jsx("span",{className:"block truncate text-xs text-muted-foreground",title:m.applicationPath,children:m.applicationPath})]})]}),e.jsx(y,{variant:"ghost",size:"sm",disabled:o,onClick:()=>n(g.getState().contextMenuOpen.filter(j=>j.id!==m.id)),children:s("Delete")})]},m.id)})]}),e.jsxs(Ie,{children:[e.jsx(y,{variant:"outline",disabled:o,onClick:()=>{f()},children:s("Add application")}),e.jsx(y,{onClick:()=>r(!1),children:s("Close")})]})]})})]})}const Da=["internal","reveal","system","application"];function La({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=xt(`file${s}`),u=ht(`file${s}`)!==null,d=i?u?["internal","reveal"]:["reveal"]:Da,x=i&&(!u||t==="system"||t==="application")?"reveal":t;return e.jsxs(se,{items:Object.fromEntries(d.map(p=>[p,o[p]])),value:x,disabled:n,onValueChange:p=>{Da.includes(p)&&a(p)},children:[e.jsx(te,{className:"w-52","aria-label":r("File opening"),children:e.jsx(ne,{})}),e.jsx(ae,{children:d.map(p=>e.jsx(Z,{value:p,disabled:p==="internal"&&!u,children:o[p]},p))})]})}function mm(){const{t:s}=R(),t=g(N=>N.fileOpenRules),n=g(N=>N.setFileOpenRules),[a,r]=l.useState(""),[o,i]=l.useState("internal"),[u,d]=l.useState(),[x,p]=l.useState(null),[c,f]=l.useState(!1),m=zi([{extension:a,target:"reveal"}])[0]?.extension,h=N=>{Me({type:"error",title:s("File opening"),description:N})},j=async N=>{f(!0);try{const S=await window.electronAPI.dialog.selectFile();if(S){if(!Gr(S)){h(s("The selected application path is invalid."));return}N(S)}}catch(S){h(S instanceof Error?S.message:String(S))}finally{f(!1)}},b=N=>{const S=_i(N);return S?(n(S),!0):(h(s("Could not complete the file action.")),!1)},A=(N,S,M)=>{if(S==="internal"&&!ht(`file${N.extension}`)){h(s("This extension does not support internal preview."));return}b(t.map(V=>V.extension===N.extension?{extension:N.extension,target:S,...S==="application"?{applicationPath:M}:{}}:V))},k=()=>{if(!m){p(s("Enter a valid file extension, for example .md."));return}if(t.some(V=>V.extension===m)){p(s("This extension already has an opening rule."));return}const N=xt(`file${m}`),S=ht(`file${m}`)!==null,M=N&&(!S||o==="system"||o==="application")?"reveal":o;if(M==="internal"&&!ht(`file${m}`)){h(s("This extension does not support internal preview."));return}if(M==="application"&&!u){p(s("Choose an application before saving this rule."));return}b([...t,{extension:m,target:M,...M==="application"?{applicationPath:u}:{}}])&&(r(""),d(void 0),p(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(um,{}),t.map(N=>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:N.extension}),e.jsx(La,{extension:N.extension,value:N.target,disabled:c,onChange:S=>{S==="application"?j(M=>A(N,S,M)):A(N,S)}}),N.target==="application"&&!xt(`file${N.extension}`)&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-xs text-muted-foreground",title:N.applicationPath,children:N.applicationPath}),e.jsx(y,{variant:"outline",size:"sm",disabled:c,onClick:()=>{j(S=>A(N,"application",S))},children:s("Choose application")})]}),e.jsx(y,{variant:"ghost",size:"sm",disabled:c,onClick:()=>b(t.filter(S=>S.extension!==N.extension)),children:s("Delete")})]},N.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(Q,{className:"w-24",value:a,placeholder:".md","aria-label":s("File extension"),disabled:c,onChange:N=>{r(N.target.value),p(null)},onKeyDown:N=>{N.key==="Enter"&&k()}}),e.jsx(La,{extension:m??".md",value:o,disabled:c,onChange:N=>{i(N),p(null)}}),e.jsx(y,{variant:"outline",size:"sm",disabled:c,onClick:k,children:s("Add")})]}),o==="application"&&!xt(`file${m??".md"}`)&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{variant:"outline",size:"sm",disabled:c,onClick:()=>{j(N=>{d(N),p(null)})},children:s("Choose application")}),e.jsx("span",{className:"min-w-0 truncate text-xs text-muted-foreground",title:u,children:u})]}),x&&e.jsx("p",{role:"alert",className:"text-xs text-destructive",children:x})]})]})}const xm=["pem","crt","cer"];function hm(s){return/^\//.test(s)||/^[A-Za-z]:[\\/]/.test(s)||/^\\\\[^\\]/.test(s)}const pm=16384,Vo=4096,Ko=65536;function fm(s){return s===null?null:typeof s=="number"&&Number.isInteger(s)&&s>=Vo&&s<=Ko?s:void 0}function gm(s){const t=s.trim();return t?/^\d+$/.test(t)?fm(Number(t)):void 0:null}function jm(){const{t:s}=R(),[t,n]=l.useState(null),[a,r]=l.useState(""),[o,i]=l.useState(null);l.useEffect(()=>{let d=!1;return window.electronAPI.compaction.getReserveTokens().then(x=>{d||(n(x),r(x===null?"":String(x)))}),()=>{d=!0}},[]);const u=async()=>{const d=gm(a);if(d===void 0){i(s("Enter a whole number between {{min}} and {{max}}, or leave it empty.",{min:Vo,max:Ko}));return}if(i(null),d===t)return;if(!(await window.electronAPI.compaction.setReserveTokens(d)).ok){i(s("Could not save. Check that pi-agent/settings.json is valid JSON."));return}n(d),r(d===null?"":String(d))};return e.jsxs("div",{className:"flex items-start justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.compactReserveTokens",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"text-sm",children:[s("Compaction reserve tokens"),e.jsx(ts,{})]}),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(Q,{inputMode:"numeric",value:a,placeholder:String(pm),"aria-label":s("Compaction reserve tokens"),onChange:d=>r(d.target.value),onBlur:()=>{u()},onKeyDown:d=>{d.key==="Enter"&&u()}}),o&&e.jsx("p",{className:"text-xs text-destructive",children:o})]})]})}function hn({className:s,render:t,...n}){const a={className:H("inline-flex items-center gap-2 text-base/4.5 sm:text-sm/4 font-medium",s),"data-slot":"label"};return Fi({defaultTagName:"label",props:Bi(a,n),render:t})}const pn={checked(s){return s?{"data-checked":""}:{"data-unchecked":""}},...Kr,...Wr},Go=l.createContext(void 0);function vm(){return l.useContext(Go)}const Wo=l.createContext(void 0);function bm(){const s=l.useContext(Wo);if(s===void 0)throw new Error(Ui(52));return s}const ym=l.forwardRef(function(t,n){const{render:a,className:r,disabled:o=!1,readOnly:i=!1,required:u=!1,"aria-labelledby":d,value:x,inputRef:p,nativeButton:c=!1,id:f,style:m,...h}=t,j=vm(),{disabled:b,readOnly:A,required:k,form:N,checkedValue:S,touched:M=!1,validation:V,name:E,setCheckedValue:L=_t,setTouched:P=_t,registerInputRef:C=_t}=j??{},{setTouched:I,setFilled:W,state:J,disabled:w}=Hr(),z=$i(),{labelId:G,getDescriptionProps:B}=qr(),U=w||z.disabled||b||o,re=A||i,F=k||u,ee=N,$=j?S===x:x==="",oe=l.useRef(null),_=l.useRef(null),le=V?.registerInput,de=l.useCallback(pe=>le?.(pe,{controlRef:oe,value:void 0}),[le]),O=Vi(p,_,C,de);ua(()=>{_.current?.checked&&W(!0)},[W]),ua(()=>{if(_.current){if(U&&$){C(null);return}C(_.current)}},[$,U,C]);const Oe=Yr(),he=Ki({id:f,implicit:!1,controlRef:oe}),T=c?void 0:he,X=Gi(d,G,_,!c,T),D={role:"radio","aria-checked":$,"aria-labelledby":X,[Qi]:$?"":void 0,id:c?he:Oe,onKeyDown(pe){pe.key==="Enter"&&pe.preventDefault()},onClick(pe){if(pe.defaultPrevented||U||re)return;pe.preventDefault();const as=_.current;as&&Xi(as,pe)},onFocus(pe){pe.defaultPrevented||U||re||!M||(_.current?.click(),P(!1))}},{getButtonProps:q,buttonRef:Y}=Wi({disabled:U,native:c,composite:!1}),xe={type:"radio",ref:O,form:ee,id:T,name:E,tabIndex:-1,style:E?Yi:Ji,"aria-hidden":!0,...x!==void 0?{value:Hi(x)}:ma,disabled:U,checked:$,required:F,readOnly:re,onChange(pe){if(pe.nativeEvent.defaultPrevented||U||re||x===void 0)return;const as=Zi(el,pe.nativeEvent);L(x,as),!as.isCanceled&&I(!0)},onClick(pe){pe.stopPropagation()},onFocus(){oe.current?.focus()}},fe=l.useMemo(()=>({...J,required:F,disabled:U,readOnly:re,checked:$}),[J,U,re,$,F]),ys=fe,hs=j!==void 0,ws=[n,oe,Y],ze=[D,h,q,B,V?pe=>V.getValidationProps(U,pe):ma],Ds=kn("span",t,{enabled:!hs,state:fe,ref:ws,props:ze,stateAttributesMapping:pn});return e.jsxs(Wo.Provider,{value:ys,children:[hs?e.jsx(qi,{tag:"span",render:a,className:r,style:m,state:fe,refs:ws,props:ze,stateAttributesMapping:pn}):Ds,e.jsx("input",{...xe,suppressHydrationWarning:!0})]})}),wm=l.forwardRef(function(t,n){const{render:a,className:r,style:o,keepMounted:i=!1,...u}=t,d=bm(),x=d.checked,{mounted:p,transitionStatus:c,setMounted:f}=$r(x),m={...d,transitionStatus:c},h=l.useRef(null),j=i||p,b=kn("span",t,{ref:[n,h],state:m,props:u,stateAttributesMapping:pn});return Vr({open:x,ref:h,onComplete(){x||f(!1)}}),j?b:null}),Nm=[ll],km=l.forwardRef(function(t,n){const{render:a,className:r,disabled:o,readOnly:i,required:u,onValueChange:d,value:x,defaultValue:p,form:c,name:f,inputRef:m,id:h,style:j,...b}=t,{setTouched:A,setFocused:k,validationMode:N,name:S,disabled:M,state:V,validation:E,setDirty:L,setFilled:P,validityData:C}=Hr(),{labelId:I}=qr(),{clearErrors:W,elementRef:J}=sl(),w=tl(!0),z=M||o,G=S??f,B=Yr(h),[U,re]=nl({controlled:x,default:p,name:"RadioGroup",state:"value"}),[F,ee]=l.useState(!1),$=Ft((Y,xe)=>{d?.(Y,xe),!xe.isCanceled&&re(Y)}),oe=E.getInputControl,_=l.useMemo(()=>({get current(){return oe()}}),[oe]),le=l.useRef(null),de=l.useRef(null);function O(Y){let xe;return m&&(typeof m=="function"?xe=m(Y):m.current=Y),le.current=Y,xe}const Oe=Ft(Y=>{if(!Y||Y.disabled)return;de.current||(de.current=Y);const xe=le.current,fe=Y.checked||xe==null||xe.disabled?O(Y):void 0;return()=>{de.current===Y&&(de.current=null),le.current===Y?fe?(fe(),le.current=null):O(null):fe?.()}}),he=Ft(()=>{const Y=J.current;if(!Y)return U??null;for(const xe of E.registeredInputs.keys())if(xe.checked&&al(xe,Y))return U??null;return null});rl(_,B,U??null,he,!z,f),ol(U,()=>{W(G),L(U!==C.initialValue),P(U!=null),E.change(U);const Y=de.current;U==null&&Y&&!Y.disabled&&O(Y)});const T=I??w?.legendId,X={...V,disabled:z??!1,required:u??!1,readOnly:i??!1},D=l.useMemo(()=>({checkedValue:U,disabled:z,form:c,validation:E,name:G,readOnly:i,registerInputRef:Oe,required:u,setCheckedValue:$,setTouched:ee,touched:F}),[U,z,c,E,G,i,Oe,u,$,ee,F]),q={id:h,role:"radiogroup","aria-required":u||void 0,"aria-disabled":z||void 0,"aria-readonly":i||void 0,"aria-labelledby":T,onFocus(){k(!0)},onBlur(Y){cl(Y.currentTarget,Y.relatedTarget)||(A(!0),k(!1),N==="onBlur"&&E.commit(U))},onKeyDownCapture(Y){Y.key.startsWith("Arrow")&&(ee(!0),k(!0))}};return e.jsx(Go.Provider,{value:D,children:e.jsx(il,{render:a,className:r,style:j,state:X,props:[q,b,Y=>E.getValidationProps(z??!1,Y)],refs:[n],stateAttributesMapping:Wr,enableHomeAndEndKeys:!1,modifierKeys:Nm})})});function Cm({className:s,...t}){return e.jsx(km,{className:H("flex flex-col gap-3",s),"data-slot":"radio-group",...t})}function za({className:s,...t}){return e.jsx(ym,{className:H("relative inline-flex size-4.5 shrink-0 items-center justify-center rounded-full border border-input bg-background bg-clip-padding shadow-xs outline-none transition-shadow before:pointer-events-none before:absolute before:inset-0 before:rounded-full not-data-disabled:not-data-checked:not-aria-invalid:before:shadow-[0_1px_--theme(--color-black/4%)] focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background aria-invalid:border-destructive/36 focus-visible:aria-invalid:border-destructive/64 focus-visible:aria-invalid:ring-destructive/48 data-disabled:opacity-64 sm:size-4 dark:not-data-checked:bg-input/32 dark:bg-clip-border dark:aria-invalid:ring-destructive/24 dark:not-data-disabled:not-data-checked:not-aria-invalid:before:shadow-[0_-1px_--theme(--color-white/8%)] [[data-disabled],[data-checked],[aria-invalid]]:shadow-none",s),"data-slot":"radio",...t,children:e.jsx(wm,{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 Sm=[{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 Im(){const{t:s}=R(),[t,n]=l.useState(!1),[a,r]=l.useState(!1),[o,i]=l.useState(null),[u,d]=l.useState(null),x=()=>{i(null),n(!0)},p=async()=>{r(!0),i(null);try{const c=await window.electronAPI.configSync.openImport();if(!c.ok){i({kind:c.cancelled?"cancelled":"error",text:c.cancelled?s("Import cancelled."):s(c.error)});return}d(c)}catch{i({kind:"error",text:s("Could not open configuration package.")})}finally{r(!1)}};return e.jsxs("section",{className:"space-y-3","data-settings-row":"general.configSync",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium",children:s("Configuration transfer")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Move models, presets, agent types, skills, MCP servers and instruction files between devices.")})]}),e.jsxs("div",{className:"rounded-md border px-3 py-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[e.jsx(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:p,children:[a?e.jsx(Ae,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Cn,{className:"h-3.5 w-3.5"}),s("Import configuration")]}),e.jsxs(y,{size:"sm",disabled:a,onClick:x,children:[e.jsx($o,{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(gt,{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(Am,{open:t,onOpenChange:n}),u&&e.jsx(Em,{file:u,onClose:()=>d(null)})]})}function Am({open:s,onOpenChange:t}){const{t:n}=R(),[a,r]=l.useState(!1),[o,i]=l.useState(""),[u,d]=l.useState(""),[x,p]=l.useState(!1),[c,f]=l.useState(null),[m,h]=l.useState(!1),[j,b]=l.useState(null),[A,k]=l.useState([]);l.useEffect(()=>{s&&(r(!1),i(""),d(""),p(!1),f(null),h(!1),b(null),k([]))},[s]);const N=()=>{x||(i(""),d(""),t(!1))},S=async()=>{if(a&&o.length<8){f(n("Password must be at least 8 characters."));return}if(a&&o!==u){f(n("Passwords do not match."));return}p(!0),f(null),h(!1);try{const M=await window.electronAPI.configSync.exportConfig({includeSecrets:a,...a?{password:o}:{}});if(i(""),d(""),!M.ok){M.cancelled?h(!0):f(n(M.error));return}b(M.filePath),k(M.skippedInstructions??[])}catch{i(""),d(""),f(n("Could not export configuration."))}finally{p(!1)}};return e.jsx(ve,{open:s,onOpenChange:M=>!M&&N(),children:e.jsxs(be,{className:"max-w-xl",showCloseButton:!x,children:[e.jsxs(ye,{children:[e.jsx(we,{children:n("Export configuration")}),e.jsx(Ye,{children:n("Create a portable .enso-config package for another device.")})]}),e.jsx(Ne,{className:"max-h-[55vh] space-y-4",children:j?e.jsxs(e.Fragment,{children:[e.jsxs(Ke,{variant:"success",children:[e.jsx(Jr,{}),e.jsx(Ps,{children:n("Configuration exported")}),e.jsxs(Ge,{children:[e.jsx("p",{children:n("Saved package:")}),e.jsx("p",{className:"break-all font-mono text-xs text-foreground",children:j})]})]}),A.length>0&&e.jsxs(Ke,{variant:"warning",children:[e.jsx(He,{}),e.jsxs(Ge,{children:[e.jsx("p",{children:n("These instructions were skipped because their source files are missing or unreadable:")}),e.jsx("p",{className:"break-all text-foreground",children:A.join(", ")})]})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs(Ke,{variant:"warning",children:[e.jsx(Sn,{}),e.jsx(Ps,{children:n("File contents can be private")}),e.jsx(Ge,{children:n("Skill and instruction file contents may contain private data, so configurations containing them can only be exported with encryption.")})]}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-md border px-3 py-2.5",children:[e.jsx(Le,{checked:a,onCheckedChange:M=>{const V=M===!0;r(V),f(null),V||(i(""),d(""))}}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-sm font-medium",children:n("Include sensitive configuration")}),e.jsx("span",{className:"mt-0.5 block text-xs text-muted-foreground",children:n("Encrypt the entire package with a password. OAuth login sessions are still excluded.")})]})]}),!a&&e.jsxs(Ke,{variant:"info",children:[e.jsx(gt,{}),e.jsx(Ge,{children:n("API keys, provider account links, MCP arguments and environment values, plus credentials and private URL parts in MCP endpoints, will be omitted. Configurations containing skill or instruction files require encryption.")})]}),a&&e.jsxs("div",{className:"space-y-3 rounded-md border px-3 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(Uo,{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(hn,{htmlFor:"config-export-password",children:n("Password")}),e.jsx(Q,{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(hn,{htmlFor:"config-export-confirmation",children:n("Confirm password")}),e.jsx(Q,{id:"config-export-confirmation",type:"password",autoComplete:"new-password",value:u,"aria-invalid":!!(c&&u!==o),onChange:M=>{d(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.")})]}),m&&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(Ie,{children:j?e.jsx(y,{size:"sm",onClick:N,children:n("Done")}):e.jsxs(e.Fragment,{children:[e.jsx(y,{variant:"outline",size:"sm",disabled:x,onClick:N,children:n("Cancel")}),e.jsxs(y,{size:"sm",disabled:x,onClick:()=>{S()},children:[x?e.jsx(Ae,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx($o,{className:"h-3.5 w-3.5"}),n(x?"Exporting…":"Export")]})]})})]})})}function Em({file:s,onClose:t}){const{t:n}=R(),[a,r]=l.useState(s.encrypted?"password":"preview"),[o,i]=l.useState(""),[u,d]=l.useState("merge"),[x,p]=l.useState(null),[c,f]=l.useState([]),[m,h]=l.useState(null),[j,b]=l.useState(!1),[A,k]=l.useState(null),[N,S]=l.useState(null),[M,V]=l.useState(!1),E=l.useRef(0),L=l.useCallback(async(w,z)=>{const G=++E.current;k("preview"),S(null),p(null),f([]);try{const B=await window.electronAPI.configSync.previewImport({token:s.token,mode:w,...z?{password:z}:{}});if(G!==E.current)return;if(i(""),!B.ok){S(n(B.error));return}d(B.mode),p(B.summary),f(B.warnings),r("preview")}catch{G===E.current&&(i(""),S(n("Could not preview configuration package.")))}finally{G===E.current&&k(null)}},[s.token,n]);l.useEffect(()=>{s.encrypted||L("merge")},[s.encrypted,L]);const P=()=>{A||(E.current+=1,V(!1),i(""),window.electronAPI.configSync.cancelImport(s.token).catch(()=>{}),t())},C=w=>{w===u||A||(d(w),L(w))},I=!!x?.some(w=>(w.category==="skills"||w.category==="mcpServers")&&w.added+w.updated+w.skipped>0),W=x!==null,J=async()=>{if(x){k("commit"),S(null);try{const w=await window.electronAPI.configSync.commitImport({token:s.token,mode:u});if(!w.ok){p(null),f([]),S(n(w.error));return}i("");try{await g.persist.rehydrate()}catch{b(!0)}f(w.warnings),h(w.backupPath),r("success")}catch{p(null),f([]),S(n("Could not import configuration."))}finally{k(null)}}};return e.jsxs(ve,{open:!0,onOpenChange:w=>!w&&P(),children:[e.jsxs(be,{className:"max-w-2xl",showCloseButton:A===null,children:[e.jsxs(ye,{children:[e.jsx(we,{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(Ne,{className:"space-y-4",children:[e.jsxs(Ke,{variant:"info",children:[e.jsx(Uo,{}),e.jsx(Ps,{children:n("Encrypted configuration package")}),e.jsx(Ge,{children:n("Enter the export password to decrypt and preview this package.")})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(hn,{htmlFor:"config-import-password",children:n("Password")}),e.jsx(Q,{id:"config-import-password",type:"password",autoFocus:!0,autoComplete:"current-password",value:o,"aria-invalid":!!N,onChange:w=>{i(w.target.value),S(null)},onKeyDown:w=>{w.key==="Enter"&&o.length>0&&!A&&L("merge",o)}})]}),N&&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"}),N]})]}),a==="preview"&&e.jsxs(Ne,{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(Cm,{value:u,onValueChange:w=>C(w),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(za,{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(za,{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(Ae,{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:Sm.map(({category:w,label:z})=>{const G=x.find(B=>B.category===w);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:G?.added??0}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:G?.updated??0}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:G?.skipped??0}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:G?.removed??0})]},w)})})]})}),!A&&x?.find(w=>w.category==="settings")?.fields?.length?e.jsxs("p",{className:"text-xs text-muted-foreground",children:[n("Portable settings changed:")," ",x.find(w=>w.category==="settings")?.fields?.join(", ")]}):null,u==="replace"&&x&&!A&&e.jsxs(Ke,{variant:"error",children:[e.jsx(He,{}),e.jsx(Ps,{children:n("Local-only configuration will be deleted")}),e.jsx(Ge,{children:n("Items in transferred collections that exist only on this device will be removed. Removed counts are shown above. Included portable preferences are overwritten. A complete backup is created first.")})]}),c.map(w=>e.jsxs(Ke,{variant:"warning",children:[e.jsx(He,{}),e.jsx(Ge,{children:n(w)})]},w)),x&&!A&&e.jsxs(Ke,{variant:"warning",children:[e.jsx(Sn,{}),e.jsx(Ps,{children:n("Only import packages you trust")}),e.jsx(Ge,{children:n("An imported package can change portable preferences and configuration. Skills and MCP servers may also run commands later when you use them. Previewing does not execute them; continue only if you trust the package.")})]}),N&&e.jsxs(Ke,{variant:"error",children:[e.jsx(Rs,{}),e.jsx(Ge,{children:N})]})]}),a==="success"&&m&&e.jsxs(Ne,{className:"space-y-4",children:[e.jsxs(Ke,{variant:"success",children:[e.jsx(Jr,{}),e.jsx(Ps,{children:n("Import complete")}),e.jsxs(Ge,{children:[e.jsx("p",{children:n("Backup of previous settings:")}),e.jsx("p",{className:"break-all font-mono text-xs text-foreground",children:m})]})]}),j&&e.jsxs(Ke,{variant:"warning",children:[e.jsx(He,{}),e.jsx(Ge,{children:n("Reopen Settings to load the imported configuration in this window.")})]}),c.map(w=>e.jsxs(Ke,{variant:"warning",children:[e.jsx(He,{}),e.jsx(Ge,{children:n(w)})]},w))]}),e.jsxs(Ie,{children:[a==="password"&&e.jsxs(e.Fragment,{children:[e.jsx(y,{variant:"outline",size:"sm",disabled:A!==null,onClick:P,children:n("Cancel")}),e.jsxs(y,{size:"sm",disabled:A!==null||o.length===0,onClick:()=>{L("merge",o)},children:[A==="preview"&&e.jsx(Ae,{className:"h-3.5 w-3.5 animate-spin"}),n("Preview")]})]}),a==="preview"&&e.jsxs(e.Fragment,{children:[e.jsx(y,{variant:"outline",size:"sm",disabled:A!==null,onClick:P,children:n("Cancel")}),N&&!x?e.jsx(y,{size:"sm",disabled:A!==null,onClick:()=>{L(u)},children:n("Refresh preview")}):e.jsxs(y,{variant:u==="replace"?"destructive":"default",size:"sm",disabled:A!==null||!x,onClick:()=>{x&&(W?V(!0):J())},children:[A==="commit"?e.jsx(Ae,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Cn,{className:"h-3.5 w-3.5"}),n(A==="commit"?"Importing…":"Import")]})]}),a==="success"&&e.jsx(y,{size:"sm",onClick:P,children:n("Done")})]})]}),e.jsx(Mm,{open:M,mode:u,hasImportedExecutableResources:I,onOpenChange:V,onConfirm:()=>{J()}})]})}function Mm({open:s,mode:t,hasImportedExecutableResources:n,onOpenChange:a,onConfirm:r}){const{t:o}=R();return e.jsx(In,{open:s,onOpenChange:a,children:e.jsxs(An,{className:"sm:max-w-md",zIndexLevel:"nested",children:[e.jsxs(En,{children:[e.jsxs(Mn,{className:"flex items-start gap-2 text-base",children:[e.jsx(He,{className:"mt-0.5 h-4 w-4 shrink-0 text-destructive"}),o("Confirm configuration import")]}),e.jsxs(Pn,{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(Tn,{variant:"bare",children:[e.jsx(Rn,{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 _a={auto:"Auto (by usage)",fast:"Fast",balanced:"Balanced",thorough:"Thorough"},Fa={standard:"Standard",smart:"Smart compaction","codex-native":"Codex native compaction","continuous-memory":"Continuous memory (experimental)"};function Pm(){const{t:s}=R(),t=g(m=>m.compactStrategy),n=g(m=>m.smartCompactEnabled),a=dl(t,n),r=g(m=>m.setCompactStrategy),o=a!=="standard",i=g(m=>m.smartCompactModel),u=g(m=>m.setSmartCompactModel),d=g(m=>m.smartCompactMode),x=g(m=>m.setSmartCompactMode),p=ns(),c=i?p.find(m=>m.id===i.providerId):void 0,f=c?.models.find(m=>m.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(ts,{})]}),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(se,{items:Object.fromEntries(xa.map(m=>[m,s(Fa[m])])),value:a,onValueChange:m=>r(m),children:[e.jsx(te,{className:"w-52",children:e.jsx(ne,{})}),e.jsx(ae,{children:xa.map(m=>e.jsx(Z,{value:m,children:s(Fa[m])},m))})]})]}),(a==="smart"||a==="codex-native")&&e.jsxs("div",{className:"flex items-center justify-between gap-4","data-smart-compact-mode":d,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Compaction mode")}),e.jsx("p",{className:"mt-0.5 text-muted-foreground/80 text-[11px]",children:s("Mode changes summary budget and how much recent tail to keep. It does not decide whether compact runs.")})]}),e.jsxs(se,{items:Object.fromEntries(ha.map(m=>[m,s(_a[m])])),value:d,onValueChange:m=>x(m),children:[e.jsx(te,{className:"w-36",children:e.jsx(ne,{})}),e.jsx(ae,{children:ha.map(m=>e.jsx(Z,{value:m,children:s(_a[m])},m))})]})]}),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")}),p.length>0&&e.jsx("div",{className:"w-full min-w-0",children:e.jsx(Ue,{providers:p,providerId:c?.id??"",modelId:f?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:s("Follows the session model"),side:"bottom",triggerClassName:ss,onSelect:(m,h)=>u({providerId:m,modelId:h}),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:()=>u(null),children:s("Follow session model")})]})]})}const Tm={cmd:"Command Prompt",powershell:"Windows PowerShell",pwsh:"PowerShell 7 (pwsh)","git-bash":"Git Bash",zsh:"zsh",bash:"bash",fish:"fish"};function Rm(){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(se,{items:{en:"English",zh:"简体中文"},value:s,onValueChange:a=>t(a),children:[e.jsx(te,{className:"w-48",children:e.jsx(ne,{})}),e.jsxs(ae,{children:[e.jsx(Z,{value:"en",children:"English"}),e.jsx(Z,{value:"zh",children:"简体中文"})]})]})]}),e.jsx(Om,{}),e.jsx($m,{}),e.jsx(Vm,{}),e.jsx(Im,{}),e.jsx(Km,{})]}),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(Dm,{}),e.jsx(Lm,{}),e.jsx(Pm,{}),e.jsx(jm,{})]}),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(_m,{}),e.jsx(zm,{}),e.jsx(Bm,{})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h4",{className:"border-b pb-2 text-base font-semibold",children:n("Terminal")}),e.jsx(Um,{}),e.jsx(Fm,{})]}),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(Ba,{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(Ba,{kind:"finderQuickAction",title:n("Finder Quick Action"),description:n("Right-click a folder in Finder and choose Services > Open with EnsoCode.")})]})]})}function Ba({kind:s,title:t,description:n}){const{t:a}=R(),[r,o]=l.useState(!1),[i,u]=l.useState(!1);l.useEffect(()=>{let x=!0;const p=()=>{vt()||window.electronAPI.window.shellIntegrationStatus().then(c=>{x&&o(c[s])})};return p(),window.addEventListener("focus",p),()=>{x=!1,window.removeEventListener("focus",p)}},[s]);const d=async()=>{u(!0);try{await window.electronAPI.window.installShellIntegration(s)}finally{try{const x=await window.electronAPI.window.shellIntegrationStatus();o(x[s])}finally{u(!1)}}};return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":`general.${s}`,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n})]}),e.jsx(y,{variant:"outline",size:"sm",className:"shrink-0",disabled:i,onClick:()=>{d()},children:a(i?"In progress…":r?"Uninstall":"Install")})]})}function Om(){const{t:s}=R(),t=g(a=>a.notifyMainAgentOnly),n=g(a=>a.setNotifyMainAgentOnly);return e.jsx(Se,{rowId:"general.notifyMainAgentOnly",title:s("Notify only for the main agent"),description:s("Skip coworker completion and failure notifications on this computer and the paired phone. Questions and approvals still notify."),checked:t,onChange:n})}function Dm(){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(se,{items:Object.fromEntries(pa.map(a=>[String(a),a===0?s("Never"):s("{{count}} min",{count:a})])),value:String(t),onValueChange:a=>n(Number(a)),children:[e.jsx(te,{className:"w-28",children:e.jsx(ne,{})}),e.jsx(ae,{children:pa.map(a=>e.jsx(Z,{value:String(a),children:a===0?s("Never"):s("{{count}} min",{count:a})},a))})]})]})}function Lm(){const{t:s}=R(),t=g(o=>o.autoRetryLimit),n=g(o=>o.setAutoRetryLimit),a=Bt.some(o=>o===t)?[...Bt]:[...Bt,t].sort((o,i)=>o===Ut?1:i===Ut?-1:o-i),r=o=>o===0?s("Off"):o===Ut?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(se,{items:Object.fromEntries(a.map(o=>[String(o),r(o)])),value:String(t),onValueChange:o=>n(Number(o)),children:[e.jsx(te,{className:"w-28",children:e.jsx(ne,{})}),e.jsx(ae,{children:a.map(o=>e.jsx(Z,{value:String(o),children:r(o)},o))})]})]})}function zm(){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(se,{items:Object.fromEntries(jt.map(r=>[String(r),a(r)])),value:String(t),onValueChange:r=>n(Number(r)),children:[e.jsx(te,{className:"w-28",children:e.jsx(ne,{})}),e.jsx(ae,{children:jt.map(r=>e.jsx(Z,{value:String(r),children:a(r)},r))})]})]})}function dt(s,t){return t===0?s("Never"):t===1?s("{{count}} day",{count:t}):s("{{count}} days",{count:t})}function _m(){const{t:s}=R(),t=g(u=>u.autoArchiveIdleDays),n=g(u=>u.setAutoArchiveIdleDays),a=g(u=>u.autoArchiveMergedWorktrees),r=g(u=>u.setAutoArchiveMergedWorktrees),o=g(u=>u.autoDeleteArchivedDays),i=g(u=>u.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(se,{items:Object.fromEntries(fa.map(u=>[String(u),dt(s,u)])),value:String(t),onValueChange:u=>n(Number(u)),children:[e.jsx(te,{className:"w-28",children:e.jsx(ne,{})}),e.jsx(ae,{children:fa.map(u=>e.jsx(Z,{value:String(u),children:dt(s,u)},u))})]})]}),e.jsx(Se,{rowId:"general.autoArchiveMergedWorktrees",title:s("Clean up merged worktrees"),description:s("When archiving idle conversations, also remove isolated worktrees that are merged and clean."),checked:a,onChange:r}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.autoDeleteArchivedDays",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s("Delete archived conversations after")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Permanently delete conversations that have been archived longer than this. This cannot be undone. Choosing a positive value deletes already-overdue archived conversations immediately.")})]}),e.jsxs(se,{items:Object.fromEntries(ga.map(u=>[String(u),dt(s,u)])),value:String(o),onValueChange:u=>i(Number(u)),children:[e.jsx(te,{className:"w-28",children:e.jsx(ne,{})}),e.jsx(ae,{children:ga.map(u=>e.jsx(Z,{value:String(u),children:dt(s,u)},u))})]})]})]})}function Fm(){const{t:s}=R(),t=g(o=>o.terminalShell),n=g(o=>o.setTerminalShell),a=ml(window.electronAPI.env.platform),r=Object.fromEntries(a.map(o=>[o,o==="auto"?s("System default"):Tm[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(se,{items:r,value:t,onValueChange:o=>n(o),children:[e.jsx(te,{className:"w-56",children:e.jsx(ne,{})}),e.jsx(ae,{children:a.map(o=>e.jsx(Z,{value:o,children:r[o]},o))})]})]})}function Bm(){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 u=x=>{const p=x.trim();if(p&&!hm(p)){i(s("Enter an absolute path"));return}i(null),n(p)},d=async()=>{const x=await window.electronAPI.dialog.selectDirectory();x&&(r(x),u(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(Q,{value:a,placeholder:s("Default location"),onChange:x=>r(x.target.value),onBlur:()=>u(a),onKeyDown:x=>{x.key==="Enter"&&u(a)}}),e.jsx(y,{variant:"outline",size:"sm",className:"shrink-0",onClick:()=>{d()},children:s("Browse")})]}),o&&e.jsx("p",{className:"text-xs text-destructive",children:o})]})]})}function Um(){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(ts,{})]}),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(se,{items:a,value:t,onValueChange:r=>n(r),children:[e.jsx(te,{className:"w-56",children:e.jsx(ne,{})}),e.jsx(ae,{children:Object.keys(a).map(r=>e.jsx(Z,{value:r,children:a[r]},r))})]})]})}function Se({title:s,description:t,checked:n,onChange:a,rowId:r,children:o}){return e.jsxs("div",{className:"rounded-md border px-3 py-2.5","data-settings-row":r,children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t})]}),e.jsx(ce,{checked:n,onCheckedChange:i=>a(i===!0)})]}),o?e.jsx("div",{className:"mt-2",children:o}):null]})}function Ua(s,t){window.electronAPI.proxy.apply({mode:s,customUrl:t})}function $m(){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),[u,d]=l.useState(null);l.useEffect(()=>{i(n)},[n]);const x=c=>{a(c),Ua(c,n)},p=()=>{const c=o.trim();if(c&&!xl(c)){d(s("Enter an http(s) proxy URL"));return}d(null),r(c),Ua(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(se,{items:{system:s("Follow system proxy"),none:s("No proxy"),custom:s("Custom proxy")},value:t,onValueChange:c=>x(c),children:[e.jsx(te,{className:"w-56",children:e.jsx(ne,{})}),e.jsxs(ae,{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(Q,{value:o,placeholder:"http://127.0.0.1:7890",onChange:c=>i(c.target.value),onBlur:p,onKeyDown:c=>{c.key==="Enter"&&p()}}),u&&e.jsx("p",{className:"text-xs text-destructive",children:u})]})]})]})}function Vm(){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 u=async c=>{n(c),i(!0);try{r(await window.electronAPI.caCert.apply(c))}catch{}finally{i(!1)}},d=async()=>{const c=await window.electronAPI.dialog.selectFile([...xm]);c&&await u(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")},p=()=>a?a.source==="env"?s("Using NODE_EXTRA_CA_CERTS from the launch environment: {{path}}",{path:a.path}):a.source==="setting"?s("Set: {{path}}",{path:a.path}):a.source==="shell"?s("Not set; using NODE_EXTRA_CA_CERTS from the login shell: {{path}}",{path:a.path}):s("Not set"):"";return e.jsxs("div",{className:"space-y-3","data-settings-row":"general.caCert",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium",children:s("Custom CA certificate")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Trust an extra CA (PEM file) for model endpoints signed by a private CA. TLS verification stays on.")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{size:"sm",variant:"outline",disabled:o,onClick:()=>{d()},children:s("Choose certificate file")}),t&&e.jsx(y,{size:"sm",variant:"ghost",disabled:o,onClick:()=>{u("")},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:p()}),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 Km(){const{t:s}=R(),t=g(N=>N.autoUpdate),n=g(N=>N.setAutoUpdate),a=g(N=>N.autoRestartWhenIdle),r=g(N=>N.setAutoRestartWhenIdle),[o,i]=l.useState(null),[u,d]=l.useState(null),[x,p]=l.useState(!1),[c,f]=l.useState(!1);l.useEffect(()=>{let N=!0;window.electronAPI.updater.getState().then(M=>{N&&(d(M),M.status&&i(V=>V??M.status))}).catch(()=>{});const S=window.electronAPI.updater.onStatus(i);return()=>{N=!1,S()}},[]);const m=u?.host==="server"?u:null,h=u?.host==="desktop"||m!==null&&m.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 m&&o.error?s("Update failed: {{error}}",{error:o.error}):s("Update check failed");default:return null}})(),k=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:m?Gm(m.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")," · ",Wm]}),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")}):h&&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:k,onClick:()=>{window.electronAPI.updater.checkForUpdates()},className:"shrink-0",children:s("Check for updates")}),e.jsx(ul,{open:c,onOpenChange:f,status:o,canDownload:h})]}),m?.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:()=>p(!0),className:"shrink-0",children:s("Restart")}),e.jsx(Xr,{open:x,onOpenChange:p,title:s("Restart server?"),description:s("Running tasks are interrupted; this page reconnects after the server is back."),confirmLabel:s("Restart"),onConfirm:()=>{p(!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:N=>{n(N),window.electronAPI.updater.setAutoUpdateEnabled(N)}})]}),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:N=>{r(N),window.electronAPI.updater.setAutoRestartWhenIdle(N)}})]})]})}function Gm(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 Wm="0.3.12",Hm=["100%","100%","70%","100%","55%"],qm=["100%","85%","60%"];function Ym({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}}),Hm.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}}),qm.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 $a="overflow-hidden rounded-lg border text-left transition-shadow";function Jm({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 u=i.id===t;return e.jsxs("button",{type:"button","data-theme-card":i.id,"aria-pressed":u,onClick:()=>a(i.id),className:H($a,"bg-card",u?"border-transparent shadow-[0_0_0_2px_var(--brand)]":"hover:border-input"),children:[e.jsx(Ym,{palette:i[n]}),e.jsxs("div",{className:"flex items-center gap-1.5 border-t px-2.5 py-[7px] text-sm",children:[e.jsx("span",{className:"truncate font-medium",children:i.name}),e.jsx("span",{className:H("ml-auto shrink-0 truncate rounded-full px-1.5 py-px text-[10.5px]",i.source.kind==="plugin"?"max-w-[60%] bg-brand/12 text-brand":"bg-muted text-subtle-foreground"),children:i.source.kind==="plugin"?o("Plugin · {{name}}",{name:i.source.pluginName}):o("Built-in")})]})]},i.id)}),r&&e.jsxs("button",{type:"button",onClick:r,className:H($a,"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(St,{className:"size-[18px]"}),o("Get more themes")]})]})}function fn({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 Xm({children:s}){return e.jsx("div",{className:"divide-y rounded-lg border bg-card",children:s})}function is({label:s,value:t,onCommit:n,min:a=0,max:r=100,step:o,unit:i="%",formatSuffix:u,onPreview:d,trailing:x,valueClassName:p="w-12"}){const[c,f]=l.useState(t);l.useEffect(()=>{f(t)},[t]);const m=u?.(c);return e.jsxs("div",{className:H("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(wl,{min:a,max:r,step:o,value:c,onValueChange:h=>{const j=Array.isArray(h)?h[0]:h;f(j),d?.(j)},onValueCommitted:h=>n(Array.isArray(h)?h[0]:h)}),e.jsxs("span",{className:H("shrink-0 text-right text-sm text-muted-foreground tabular-nums",m?"w-28":p),children:[c,i,m?` · ${m}`:""]})]}),x]})}function Qm(){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),u=g(O=>O.backgroundFolderPath),d=g(O=>O.setBackgroundFolderPath),x=g(O=>O.backgroundUrlPath),p=g(O=>O.setBackgroundUrlPath),c=g(O=>O.backgroundRandomEnabled),f=g(O=>O.setBackgroundRandomEnabled),m=g(O=>O.backgroundRandomInterval),h=g(O=>O.setBackgroundRandomInterval),j=g(O=>O.backgroundOpacity),b=g(O=>O.setBackgroundOpacity),A=g(O=>O.backgroundBlur),k=g(O=>O.setBackgroundBlur),N=g(O=>O.backgroundBrightness),S=g(O=>O.setBackgroundBrightness),M=g(O=>O.backgroundSaturation),V=g(O=>O.setBackgroundSaturation),E=g(O=>O.backgroundMask),L=g(O=>O.setBackgroundMask),P=g(O=>O.backgroundComposerOpacity),C=g(O=>O.setBackgroundComposerOpacity),I=g(O=>O.backgroundCodeOpacity),W=g(O=>O.setBackgroundCodeOpacity),J=g(O=>O.backgroundSizeMode),w=g(O=>O.setBackgroundSizeMode),z=g(O=>O.bumpBackgroundRefresh),G=Nl()?.source==="theme",B=a==="file"?o:a==="folder"?u:x,[U,re]=l.useState(B);l.useEffect(()=>{re(B)},[B]);const F=l.useCallback(()=>{const O=U.trim();a==="file"?i(O):a==="folder"?d(O):p(O)},[U,a,i,d,p]),[ee,$]=l.useState(m);l.useEffect(()=>{$(m)},[m]);const oe=async()=>{if(a==="folder"){const O=await window.electronAPI.dialog.selectDirectory();O&&d(O)}else{const O=await window.electronAPI.dialog.selectFile([...Sl,...Il]);O&&i(O)}},_=[{value:"file",label:s("Single image")},{value:"folder",label:s("Folder (random)")},{value:"url",label:s("Remote URL")}],le=[{value:"cover",label:s("Cover")},{value:"contain",label:s("Contain")},{value:"repeat",label:s("Repeat")},{value:"center",label:s("Center")}],de=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)})]}),G&&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(se,{items:_,value:a,onValueChange:O=>r(O),children:[e.jsx(te,{className:"w-48",children:e.jsx(ne,{})}),e.jsx(ae,{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:de}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Q,{value:U,onChange:O=>re(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:oe,"aria-label":s("Browse"),children:a==="folder"?e.jsx(zn,{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(cs,{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(Q,{type:"number",min:5,max:86400,value:ee,onChange:O=>$(Number(O.target.value)),onBlur:()=>h(ee),onKeyDown:O=>{O.key==="Enter"&&(h(ee),O.currentTarget.blur())},className:"w-24"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:s("seconds")})]})]})]}),e.jsx(is,{label:s("Background visibility"),value:Math.round(j*100),onCommit:O=>b(O/100)}),e.jsx(is,{label:s("Blur"),value:A,onCommit:k,max:20,unit:"px"}),e.jsx(is,{label:s("Brightness"),value:Math.round(N*100),onCommit:O=>S(O/100),max:200}),e.jsx(is,{label:s("Saturation"),value:Math.round(M*100),onCommit:O=>V(O/100),max:200}),e.jsx(is,{label:s("Overlay"),value:Math.round(E*100),onCommit:O=>L(O/100)}),e.jsx(is,{label:s("Composer opacity"),value:Math.round(P*100),onCommit:O=>C(O/100)}),e.jsx(is,{label:s("Code block opacity"),value:Math.round(I*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(se,{items:le,value:J,onValueChange:O=>w(O),children:[e.jsx(te,{className:"w-48",children:e.jsx(ne,{})}),e.jsx(ae,{children:le.map(O=>e.jsx(Z,{value:O.value,children:O.label},O.value))})]})]})]})]})}function Zm({theme:s,fontSize:t,fontFamily:n,fontWeight:a}){const r=[{id:"prompt1",text:"$ ",color:s.green},{id:"cmd1",text:"ls -la",color:s.foreground},{id:"nl1",text:`
|
|
3
|
-
`},{id:"perm1",text:"drwxr-xr-x ",color:s.blue},{id:"meta1",text:"5 user staff 160 Dec 23 ",color:s.foreground},{id:"dir1",text:"Documents",color:s.cyan},{id:"nl2",text:`
|
|
4
|
-
`},{id:"perm2",text:"-rw-r--r-- ",color:s.foreground},{id:"meta2",text:"1 user staff 2048 Dec 22 ",color:s.foreground},{id:"file1",text:"config.json",color:s.yellow},{id:"nl3",text:`
|
|
5
|
-
|
|
6
|
-
`},{id:"prompt2",text:"$ ",color:s.green},{id:"cmd2",text:'echo "Hello, World!"',color:s.foreground},{id:"nl4",text:`
|
|
7
|
-
`},{id:"output1",text:"Hello, World!",color:s.magenta}];return e.jsxs("div",{className:"rounded-lg border p-4 h-40 overflow-auto",style:{backgroundColor:s.background,fontSize:`${t}px`,fontFamily:n,fontWeight:a},children:[r.map(o=>o.text===`
|
|
8
|
-
`?e.jsx("br",{},o.id):o.text===`
|
|
9
|
-
|
|
10
|
-
`?e.jsxs(l.Fragment,{children:[e.jsx("br",{}),e.jsx("br",{})]},o.id):e.jsx("span",{style:{color:o.color},children:o.text},o.id)),e.jsx("span",{className:"inline-block w-2 h-4 animate-pulse",style:{backgroundColor:s.cursor}})]})}function ex({isFavorite:s,onClick:t,ariaLabel:n}){return e.jsx("button",{type:"button","aria-label":n,"aria-pressed":s,onClick:a=>{a.stopPropagation(),a.preventDefault(),t(a)},className:"p-1 hover:text-red-500 transition-colors",children:s?e.jsx(Oa,{className:"h-4 w-4 fill-red-500 text-red-500"}):e.jsx(Oa,{className:"h-4 w-4"})})}function sx({value:s,onValueChange:t,themes:n,favoriteThemes:a,onToggleFavorite:r,onThemeHover:o,showFavoritesOnly:i,onShowFavoritesOnlyChange:u,showEmptyFavoritesHint:d}){const{t:x}=R(),[p,c]=l.useState(s),[f,m]=l.useState(s),[h,j]=l.useState(!1),b=l.useRef(void 0),A=l.useRef(null),k=l.useRef(s),N=l.useRef(!1),S=l.useMemo(()=>new Set(a),[a]);l.useEffect(()=>{h||(c(s),m(s))},[s,h]);const M=l.useMemo(()=>{if(!f||f===p)return n;const C=f.toLowerCase();return n.filter(I=>I.toLowerCase().includes(C))},[n,f,p]),V=C=>{C&&(N.current=!0,c(C),m(C)),t(C)},E=C=>{j(C),C?(k.current=s,N.current=!1,c(s),m(s)):N.current||o?.(k.current)},L=C=>{clearTimeout(b.current),b.current=setTimeout(()=>{o?.(C)},50)},P=()=>{clearTimeout(b.current)};return l.useEffect(()=>{if(!h)return;const C=I=>{(I.key==="ArrowDown"||I.key==="ArrowUp")&&requestAnimationFrame(()=>{const W=A.current?.querySelector("[data-highlighted]");if(W){const J=W.getAttribute("data-value");J&&o?.(J)}})};return document.addEventListener("keydown",C,!0),()=>{document.removeEventListener("keydown",C,!0)}},[h,o]),l.useEffect(()=>()=>{clearTimeout(b.current)},[]),e.jsxs(am,{value:p,onValueChange:V,inputValue:f,onInputValueChange:m,open:h,onOpenChange:E,children:[e.jsxs("div",{className:"relative",children:[e.jsx(rm,{placeholder:x("Search themes...")}),e.jsxs("div",{className:"absolute right-8 top-1/2 -translate-y-1/2 flex items-center gap-1.5",children:[e.jsx(Le,{id:"show-favorites-only-inner",checked:i,onCheckedChange:C=>u(C===!0),onClick:C=>C.stopPropagation()}),e.jsx("label",{htmlFor:"show-favorites-only-inner",className:"text-xs text-muted-foreground cursor-pointer whitespace-nowrap",onClick:C=>C.stopPropagation(),onKeyDown:C=>C.stopPropagation(),children:x("Show favorites only")})]})]}),e.jsx(im,{children:e.jsxs(cm,{ref:A,children:[M.length===0&&e.jsx("div",{className:"py-6 text-center text-sm text-muted-foreground",children:x(d?"No favorite themes yet. Click the heart icon to add favorites.":"No themes found")}),M.map(C=>e.jsx(lm,{value:C,"data-value":C,onMouseEnter:()=>L(C),onMouseLeave:P,endAddon:e.jsx(ex,{isFavorite:S.has(C),onClick:()=>r(C),ariaLabel:S.has(C)?x("Remove from favorites"):x("Add to favorites")}),children:C},C))]})})]})}const tx={theme:"Follow theme",violet:"Violet",indigo:"Indigo",teal:"Teal",amber:"Amber",graphite:"Graphite"},Va={body:"Body",h1:"Heading 1",h2:"Heading 2",h3:"Heading 3",h4:"Heading 4–6",table:"Table",inlineCode:"Inline code",codeBlock:"Code block"},Ka=to.map(s=>({value:String(s),label:String(s)}));function nx(){const{t:s}=R(),t=g(d=>d.chatTypography),n=g(d=>d.setChatTypography),a=g(d=>d.resetChatTypography),[r,o]=l.useState(t.body.size);l.useEffect(()=>{o(t.body.size)},[t.body.size]);const i=(d,x)=>{const p=g.getState().chatTypography;n({...p,[d]:{...p[d],size:x}})},u=(d,x)=>{const p=g.getState().chatTypography;n({...p,[d]:{...p[d],weight:x}})};return e.jsxs("section",{"data-settings-row":"appearance.chatTypography",className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("Conversation typography")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("Headings, tables and inline code scale with the body text")})]}),e.jsxs("div",{className:"space-y-3 rounded-lg border bg-card p-3.5",children:[kl.map(d=>{const x=Cl[d];return e.jsx(is,{label:s(Va[d]),value:t[d].size,min:x.min,max:x.max,step:x.step,unit:x.unit==="%"?"%":"px",valueClassName:"w-28",formatSuffix:x.unit==="%"?p=>`${(r*p/100).toFixed(1)}px`:void 0,onPreview:d==="body"?o:void 0,onCommit:p=>i(d,p),trailing:e.jsxs(se,{items:Ka,value:String(t[d].weight),onValueChange:p=>{const c=Number(p);to.includes(c)&&u(d,c)},children:[e.jsx(te,{className:"w-24 min-w-24","aria-label":s(Va[d]),children:e.jsx(ne,{})}),e.jsx(ae,{children:Ka.map(p=>e.jsx(Z,{value:p.value,children:p.label},p.value))})]})},d)}),e.jsx("div",{className:"flex justify-end",children:e.jsx(y,{variant:"outline",size:"sm",onClick:()=>a(),children:s("Reset to defaults")})})]})]})}function ax({seconds:s,onCommit:t}){const{t:n}=R(),[a,r]=l.useState(String(s));l.useEffect(()=>r(String(s)),[s]);const o=()=>{const i=Number(a);if(!Number.isInteger(i)){r(String(s));return}const u=Al(i);t(u),r(String(u))};return e.jsxs("div",{className:"flex items-center justify-between gap-3","data-settings-row":"appearance.liveActivityFoldDelaySec",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:n("Wait before folding")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n("Seconds to wait after tools and thinking finish")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Q,{type:"number",min:1,max:60,value:a,onChange:i=>r(i.target.value),onBlur:o,onKeyDown:i=>{i.key==="Enter"&&(o(),i.currentTarget.blur())},className:"w-20"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:n("sec")})]})]})}function rx(){const{t:s}=R(),t=g(C=>C.openChangesOnFileEdit),n=g(C=>C.setOpenChangesOnFileEdit),a=g(C=>C.compactReadOnlyTools),r=g(C=>C.setCompactReadOnlyTools),o=g(C=>C.expandLiveEdits),i=g(C=>C.setExpandLiveEdits),u=g(C=>C.expandLiveReasoning),d=g(C=>C.setExpandLiveReasoning),x=g(C=>C.autoCollapseTurns),p=g(C=>C.setAutoCollapseTurns),c=g(C=>C.collapseCompletedActivity),f=g(C=>C.setCollapseCompletedActivity),m=g(C=>C.collapseLiveActivity),h=g(C=>C.setCollapseLiveActivity),j=g(C=>C.liveActivityFoldDelaySec),b=g(C=>C.setLiveActivityFoldDelaySec),A=g(C=>C.pinUnfinishedTodos),k=g(C=>C.setPinUnfinishedTodos),N=g(C=>C.headerSessionTabs),S=g(C=>C.setHeaderSessionTabs),M=g(C=>C.headerRecentMinutes),V=g(C=>C.setHeaderRecentMinutes),E=C=>C===0?s("Off"):s("{{count}} min",{count:C}),L=g(C=>C.navRailSide),P=g(C=>C.setNavRailSide);return e.jsxs("div",{className:"space-y-6",children:[e.jsx("h3",{className:"text-lg font-medium",children:s("Conversation display")}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Se,{rowId:"appearance.openChangesOnFileEdit",title:s("Open Changes when files are edited"),description:s("Automatically show the side panel Changes tab after the agent edits a file"),checked:t,onChange:n}),e.jsx(Se,{rowId:"appearance.compactReadOnlyTools",title:s("Compact read-only tool calls"),description:s("Show read/grep/find/ls as one-line rows and fold consecutive tool calls while the agent is still running"),checked:a,onChange:r}),e.jsx(Se,{rowId:"appearance.expandLiveEdits",title:s("Expand file edits while running"),description:s("Automatically unfold diffs or written content from file modification tools while the agent is still running"),checked:o,onChange:i}),e.jsx(Se,{rowId:"appearance.expandLiveReasoning",title:s("Expand reasoning while streaming"),description:s("Automatically unfold the thinking block while the model is still reasoning. It collapses again when reasoning ends."),checked:u,onChange:d}),e.jsx(Se,{rowId:"appearance.autoCollapseTurns",title:s("Auto-collapse previous turns"),description:s("After you send a new message, fold earlier turns down to the question, timestamp and duration; the latest turn stays expanded"),checked:x,onChange:p}),e.jsx(Se,{rowId:"appearance.collapseCompletedActivity",title:s("Collapse activity after reply"),description:s("When a reply finishes, fold consecutive thinking and tool calls (including edits and commands) into one summary row; failed calls stay visible"),checked:c,onChange:f}),e.jsx(Se,{rowId:"appearance.collapseLiveActivity",title:s("Collapse finished activity while replying"),description:s("While a reply is still running, wait a moment after tools and thinking finish, then fold that stretch into one row. Calls still running stay visible, and failed calls stay visible"),checked:m,onChange:h,children:m?e.jsx(ax,{seconds:j,onCommit:b}):null}),e.jsx(Se,{rowId:"appearance.pinUnfinishedTodos",title:s("Pin unfinished todos"),description:s("Keep the latest todo list above the input while it has unfinished items, so it does not scroll away with the timeline"),checked:A,onChange:k}),e.jsx(Se,{rowId:"appearance.headerSessionTabs",title:s("Show active sessions in the title bar"),description:s("Show active conversations as tabs above the conversation. Hold ⌘/Ctrl to see number shortcuts. Hidden while Bot mode is enabled."),checked:N,onChange:S,children:N&&e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s("Also show recent conversations")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Conversations with messages within this window. Off shows only Active ones.")})]}),e.jsxs(se,{items:Object.fromEntries(jt.map(C=>[String(C),E(C)])),value:String(M),onValueChange:C=>V(Number(C)),children:[e.jsx(te,{className:"w-28",children:e.jsx(ne,{})}),e.jsx(ae,{children:jt.map(C=>e.jsx(Z,{value:String(C),children:E(C)},C))})]})]})}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"appearance.navRailSide",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s("Turn marks")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Marks along the conversation for each turn. Hover to preview, click to jump. Hidden when the chat uses the full width.")})]}),e.jsx("div",{className:"w-36 shrink-0",children:e.jsx(Ln,{value:L,options:[{value:"left",label:s("Left")},{value:"right",label:s("Right")},{value:"off",label:s("Off")}],onChange:P})})]})]}),e.jsx(nx,{}),e.jsx(mm,{})]})}function ox({onOpenPlugins:s}){const{t}=R(),n=g(i=>i.themeId),a=g(i=>i.setThemeId),r=On(i=>i.themes),o=Qr();return e.jsxs("section",{"data-settings-row":"appearance.themeGallery",className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:t("Theme")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("Built-in and plugin themes; each one is a set of color tokens")})]}),e.jsx(Jm,{themes:eo(r),selected:n,mode:o,onSelect:a,onGetMore:s})]})}function ix(){const{t:s}=R(),t=g(r=>r.userCssEnabled),n=g(r=>r.setUserCssEnabled),a=async()=>{const r=await window.electronAPI.appearance.openUserCss();r.ok||Me({type:"error",title:s("Cannot open user.css"),description:r.error})};return e.jsxs(fn,{rowId:"appearance.userCss",title:s("Custom CSS"),description:s("Inject user.css into every window; saved changes apply immediately"),children:[e.jsxs(y,{variant:"outline",size:"sm",onClick:()=>{a()},children:[e.jsx(yl,{}),s("Open user.css")]}),e.jsx(ce,{checked:t,onCheckedChange:r=>n(r===!0),"aria-label":s("Custom CSS")})]})}function lx({onOpenPlugins:s}={}){const t=g(_=>_.borderOpacity),n=g(_=>_.setBorderOpacity),{theme:a,setTheme:r,themeId:o,accentColor:i,setAccentColor:u,terminalTheme:d,setTerminalTheme:x,terminalFontSize:p,setTerminalFontSize:c,terminalFontFamily:f,setTerminalFontFamily:m,terminalFontWeight:h,setTerminalFontWeight:j,terminalFontWeightBold:b,setTerminalFontWeightBold:A,favoriteTerminalThemes:k,toggleFavoriteTerminalTheme:N}=g(),{t:S}=R(),M=Qr(),V=On(_=>_.themes),E=[{value:"light",icon:Hu,label:S("Light")},{value:"dark",icon:hl,label:S("Dark")},{value:"system",icon:Dn,label:S("System")},{value:"sync-terminal",icon:Zr,label:S("Sync terminal theme")}],L=pl.map(_=>({value:_,label:S(tx[_]),swatch:_==="theme"?gl(o,eo(V))[M].accent:fl[_][M]})),[P,C]=l.useState(p),[I,W]=l.useState(f),[J,w]=l.useState(!1);l.useEffect(()=>{C(p)},[p]),l.useEffect(()=>{W(f)},[f]);const z=l.useCallback(()=>{const _=Math.max(8,Math.min(32,P||8));_!==P&&C(_),_!==p&&c(_)},[P,p,c]),G=l.useCallback(()=>{const _=I.trim()||f;_!==I&&W(_),_!==f&&m(_)},[I,f,m]),B=l.useMemo(()=>jl(),[]),U=l.useMemo(()=>{if(!J)return B;const _=B.filter(le=>k.includes(le));return k.includes(d)?_:[d,..._]},[B,J,k,d]),re=J&&k.length===0,F=l.useMemo(()=>bl(d)??vl,[d]),ee=_=>{_&&x(_)},$=()=>{const _=J?U:B,le=_.indexOf(d),de=le<=0?_.length-1:le-1;x(_[de])},oe=()=>{const _=J?U:B,le=_.indexOf(d),de=le>=_.length-1?0:le+1;x(_[de])};return e.jsxs("div",{className:"space-y-6",children:[e.jsx(ox,{onOpenPlugins:s}),e.jsxs("section",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:S("Personalization")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:S("Applied on top of any theme")})]}),e.jsxs(Xm,{children:[e.jsx(fn,{rowId:"appearance.theme",title:S("Theme mode"),children:e.jsx("div",{className:"flex rounded-lg bg-muted p-0.5",children:E.map(_=>e.jsxs("button",{type:"button",onClick:()=>r(_.value),"aria-pressed":a===_.value,className:H("flex h-7 items-center gap-1.5 rounded-md px-2.5 text-xs transition-colors",a===_.value?"bg-background text-foreground shadow-xs":"text-muted-foreground hover:text-foreground"),children:[e.jsx(_.icon,{className:"size-3.5"}),_.label]},_.value))})}),e.jsx(fn,{rowId:"appearance.accent",title:S("Accent color"),description:S("Used for running state, checkmarks and plan mode"),children:L.map(_=>_.value==="theme"?e.jsxs("button",{type:"button",onClick:()=>u(_.value),"aria-pressed":i===_.value,className:H("flex h-6 items-center gap-1.5 rounded-full border px-2 text-xs transition-shadow",i===_.value&&"border-transparent ring-2 ring-foreground/60"),children:[e.jsx("span",{"data-theme-accent":!0,className:"size-2.5 rounded-full",style:{backgroundColor:_.swatch}}),_.label]},_.value):e.jsx("button",{type:"button",onClick:()=>u(_.value),title:_.label,"aria-label":_.label,"aria-pressed":i===_.value,style:{backgroundColor:_.swatch},className:H("size-5 rounded-full transition-shadow",i===_.value&&"ring-2 ring-offset-2 ring-offset-card ring-foreground/60")},_.value))}),e.jsx(ix,{})]})]}),e.jsx(rx,{}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:S("Terminal")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:S("Terminal appearance")})]}),e.jsx(Zm,{theme:F,fontSize:P,fontFamily:I,fontWeight:h}),e.jsxs("div",{className:"space-y-3 rounded-lg border bg-card p-3.5",children:[e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:S("Color scheme")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{variant:"outline",size:"icon",onClick:$,children:e.jsx(so,{className:"h-4 w-4"})}),e.jsx("div",{className:"flex-1",children:e.jsx(sx,{value:d,onValueChange:ee,themes:U,favoriteThemes:k,onToggleFavorite:N,onThemeHover:x,showFavoritesOnly:J,onShowFavoritesOnlyChange:w,showEmptyFavoritesHint:re})}),e.jsx(y,{variant:"outline",size:"icon",onClick:oe,children:e.jsx(Ys,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:S("Font")}),e.jsx(Q,{value:I,onChange:_=>W(_.target.value),onBlur:G,onKeyDown:_=>{_.nativeEvent.isComposing||_.key==="Enter"&&(G(),_.currentTarget.blur())},placeholder:"JetBrains Mono, monospace"})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:S("Font size")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Q,{type:"number",value:P,onChange:_=>C(Number(_.target.value)),onBlur:z,onKeyDown:_=>{_.key==="Enter"&&(z(),_.currentTarget.blur())},min:8,max:32,className:"w-20"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"px"})]})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:S("Font weight")}),e.jsxs(se,{items:it,value:h,onValueChange:_=>j(_),children:[e.jsx(te,{className:"w-48",children:e.jsx(ne,{})}),e.jsx(ae,{children:it.map(_=>e.jsx(Z,{value:_.value,children:_.label},_.value))})]})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:S("Bold font weight")}),e.jsxs(se,{items:it,value:b,onValueChange:_=>A(_),children:[e.jsx(te,{className:"w-48",children:e.jsx(ne,{})}),e.jsx(ae,{children:it.map(_=>e.jsx(Z,{value:_.value,children:_.label},_.value))})]})]})]}),e.jsx(is,{label:S("Border opacity"),value:Math.round(t*100),onCommit:_=>n(_/100)}),e.jsx(Qm,{})]})}const Ga=15e3,cx=3e3;function dx(s){return!s||!s.timeoutSet&&s.timeoutMs===cx?Ga:s.timeoutMs}const Wa=()=>{},Vt="off",Kt=s=>({timeoutMs:s?.timeoutMs??El,...s?.timeoutSet&&{timeoutSet:!0}});function ux({classifier:s,effectiveMs:t,hint:n,onChange:a}){const{t:r}=R(),[o,i]=l.useState(String(t/1e3));l.useEffect(()=>i(String(t/1e3)),[t]);const u=()=>{const d=Number(o);if(!o.trim()||!Number.isFinite(d))return i(String(t/1e3));const x=Tl(d*1e3);i(String(x/1e3)),x!==t&&a({...s,timeoutMs:x,timeoutSet:!0})};return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs",children:r("Timeout")}),e.jsx(Q,{type:"number",value:o,min:Pl/1e3,max:Ml/1e3,step:.5,className:"h-7 w-20 text-xs",onChange:d=>i(d.target.value),onBlur:u,onKeyDown:d=>{d.key==="Enter"&&d.currentTarget.blur()}}),e.jsx("span",{className:"text-xs text-muted-foreground",children:r("seconds")}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:n})]})}function ft({providers:s,value:t,emptyLabel:n,onSelect:a}){return e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx(Ue,{providers:s,providerId:t?.providerId??"",modelId:t?.modelId??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:n,side:"bottom",triggerClassName:ss,onSelect:(r,o)=>a({providerId:r,modelId:o}),onReasoningChange:Wa,onThinkingChange:Wa})})}function ut({label:s,hint:t,children:n}){return e.jsxs("div",{className:"grid grid-cols-[6rem_1fr] items-start gap-2",children:[e.jsxs("div",{className:"pt-1.5 text-xs",children:[e.jsx("div",{children:s}),t&&e.jsx("div",{className:"text-[10px] text-muted-foreground",children:t})]}),e.jsx("div",{className:"min-w-0 space-y-1",children:n})]})}function Ho({value:s,onChange:t,providers:n,classifierProviders:a,offLabel:r,judgeLabel:o,judgeSeed:i,description:u,effectiveTimeoutMs:d,timeoutHint:x}){const{t:p}=R(),c=s,[f,m]=l.useState(!1),h=c?.source??(f?"judge":Vt),j=c?.source==="pi-classifier"?c.model.providerId:"",[b,A]=l.useState([]),[k,N]=l.useState(!1);l.useEffect(()=>{if(!j){A([]);return}let E=!1;return window.electronAPI.providers.classifierModels(j).then(L=>{E||A(L)}),()=>{E=!0}},[j]);const S=async E=>{const P=(await window.electronAPI.providers.classifierModels(E))[0];N(!P),P&&t({source:"pi-classifier",model:{providerId:E,modelId:P.id},...Kt(c)})},M=E=>{if(N(!1),m(E==="judge"&&!i),E===Vt)return t(void 0);if(E==="judge")return t(i?{source:"judge",model:i,...Kt(c)}:void 0);const L=a[0];L&&S(L.id)},V=[{value:Vt,label:r},{value:"judge",label:o},...a.length>0?[{value:"pi-classifier",label:p("Classifier model")}]:[]];return e.jsxs("div",{className:"space-y-1",children:[e.jsxs(se,{items:V,value:h,onValueChange:E=>M(String(E)),children:[e.jsx(te,{size:"sm",className:"w-48",children:e.jsx(ne,{})}),e.jsx(ae,{children:V.map(E=>e.jsx(Z,{value:E.value,children:E.label},E.value))})]}),h==="judge"&&e.jsx(ft,{providers:n,value:c?.source==="judge"?c.model:void 0,emptyLabel:p("Select model"),onSelect:E=>{m(!1),t({source:"judge",model:E,...Kt(c)})}}),c?.source==="pi-classifier"&&e.jsxs("div",{className:"flex gap-1",children:[e.jsxs(se,{items:a.map(E=>({value:E.id,label:E.name})),value:c.model.providerId,onValueChange:E=>{S(String(E))},children:[e.jsx(te,{size:"sm",className:"w-40",children:e.jsx(ne,{})}),e.jsx(ae,{children:a.map(E=>e.jsx(Z,{value:E.id,children:E.name},E.id))})]}),e.jsxs(se,{items:b.map(E=>({value:E.id,label:E.name})),value:c.model.modelId||null,onValueChange:E=>t({...c,model:{providerId:c.model.providerId,modelId:String(E)}}),children:[e.jsx(te,{size:"sm",className:"min-w-0 flex-1",children:e.jsx(ne,{placeholder:p("Select model")})}),e.jsx(ae,{children:b.map(E=>e.jsx(Z,{value:E.id,children:E.name},E.id))})]})]}),k&&e.jsx("p",{className:"text-[10px] text-destructive",children:p("No classifier models available")}),c&&e.jsx(ux,{classifier:c,effectiveMs:d??c.timeoutMs,hint:x,onChange:t}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:u})]})}function mx({entry:s,providers:t,classifierProviders:n,update:a}){const{t:r}=R();return s.fast?e.jsx(Ho,{value:s.classifier,onChange:o=>a({classifier:o}),providers:t,classifierProviders:n,offLabel:r("Off"),judgeLabel:r("Fast model judges"),judgeSeed:s.fast,description:r("Classifies each new turn: simple turns use the fast model, complex ones the primary model. Adds a short delay before the reply."),timeoutHint:r("Uses the primary model on timeout.")}):e.jsx("p",{className:"pt-1.5 text-[11px] text-muted-foreground",children:r("Set a fast model first")})}function xx({entry:s,providers:t,classifierProviders:n}){const{t:a}=R(),r=g(x=>x.updateVirtualModel),o=g(x=>x.removeVirtualModel),i=[s.primary,...s.fast?[s.fast]:[],...s.fallbacks];let u;for(const x of t){const p=x.models.find(c=>c.enabled!==!1&&!i.some(f=>f.providerId===x.id&&f.modelId===c.id));if(p){u={providerId:x.id,modelId:p.id};break}}const d=x=>r(s.id,x);return e.jsxs("div",{"data-slot":"virtual-model-card",className:H("space-y-2 rounded-md border p-2",!s.enabled&&"bg-muted/50 text-muted-foreground"),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ce,{"aria-label":a("Enable virtual model"),checked:s.enabled,onCheckedChange:x=>d({enabled:x})}),e.jsx(Q,{value:s.name,maxLength:60,placeholder:"Auto",className:"h-7 flex-1 text-xs",onChange:x=>d({name:x.target.value})}),!s.enabled&&e.jsx(ie,{variant:"outline",className:"shrink-0 text-[10px] text-muted-foreground",children:a("Disabled")}),e.jsx(y,{type:"button",variant:"ghost",size:"icon","aria-label":a("Delete"),className:"h-6 w-6 shrink-0 text-muted-foreground hover:text-destructive",onClick:()=>o(s.id),children:e.jsx(Re,{className:"h-3.5 w-3.5"})})]}),e.jsx(ut,{label:a("Primary model"),hint:a("Default for each new turn"),children:e.jsx(ft,{providers:t,value:s.primary,onSelect:x=>d({primary:x,fallbacks:s.fallbacks.filter(p=>p.providerId!==x.providerId||p.modelId!==x.modelId)})})}),e.jsx(ut,{label:a("Fast model"),hint:a("Summaries and simple turns"),children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(ft,{providers:t,value:s.fast,emptyLabel:a("Not used"),onSelect:x=>d({fast:x})}),s.fast&&e.jsx(y,{type:"button",variant:"ghost",size:"icon","aria-label":a("Clear"),className:"h-6 w-6 shrink-0 text-muted-foreground",onClick:()=>d({fast:void 0}),children:e.jsx(bs,{className:"h-3.5 w-3.5"})})]})}),e.jsxs(ut,{label:a("Fallback models"),hint:a("Used in order when a model is rate limited or down"),children:[s.fallbacks.map((x,p)=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(ft,{providers:t,value:x,onSelect:c=>d({fallbacks:s.fallbacks.map((f,m)=>m===p?c:f)})}),e.jsx(y,{type:"button",variant:"ghost",size:"icon","aria-label":a("Delete"),className:"h-6 w-6 shrink-0 text-muted-foreground hover:text-destructive",onClick:()=>d({fallbacks:s.fallbacks.filter((c,f)=>f!==p)}),children:e.jsx(bs,{className:"h-3.5 w-3.5"})})]},`${x.providerId}/${x.modelId}`)),e.jsxs(y,{type:"button",variant:"outline",size:"sm",className:"h-7 text-xs",disabled:!u||s.fallbacks.length>=8,onClick:()=>{u&&d({fallbacks:[...s.fallbacks,u]})},children:[e.jsx(Pe,{className:"mr-1 h-3.5 w-3.5"}),a("Add fallback")]})]}),e.jsx(ut,{label:a("Difficulty routing"),children:e.jsx(mx,{entry:s,providers:t,classifierProviders:n,update:d})})]})}function hx(){const{t:s}=R(),t=g(d=>d.virtualModels),n=g(d=>d.addVirtualModel),a=g(d=>d.defaultModel),r=ns(),o=l.useMemo(()=>r.filter(no),[r]),i=_n(),u=l.useMemo(()=>{if(a&&o.find(x=>x.id===a.providerId)?.models.some(x=>x.id===a.modelId&&x.enabled!==!1))return a;for(const d of o){const x=d.models.find(p=>p.enabled!==!1);if(x)return{providerId:d.id,modelId:x.id}}return null},[o,a]);return e.jsxs("section",{"data-slot":"virtual-models",className:"space-y-2 rounded-lg border bg-card p-3",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium text-sm",children:s("Virtual models")}),e.jsx("p",{className:"mt-0.5 text-muted-foreground text-xs",children:s("A virtual model appears as one model in the picker and routes each request to a real model: fallbacks on rate limits or outages, image-capable or larger-context members when needed, and the fast model for summaries.")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:s("Applies to newly started conversations.")})]}),e.jsxs("div",{className:"space-y-2",children:[t.map(d=>e.jsx(xx,{entry:d,providers:o,classifierProviders:i},d.id)),e.jsxs(y,{type:"button",variant:"outline",size:"sm",className:"h-7 text-xs",disabled:!u,onClick:()=>{u&&n({name:"Auto",enabled:!0,primary:u,fallbacks:[]})},children:[e.jsx(Pe,{className:"mr-1 h-3.5 w-3.5"}),s("New virtual model")]}),!u&&e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Enable a model and configure valid provider credentials first.")})]})]})}function px(){const{t:s}=R();return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("Bot mode")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("Settings shared by all members and group chats.")})]}),e.jsx(jx,{}),e.jsx(vx,{}),e.jsx(fx,{}),e.jsx(gx,{})]})}function fx(){const{t:s}=R(),t=g(r=>r.botModeEnabled),n=g(r=>r.botDiscussModeEnabled),a=g(r=>r.setBotDiscussModeEnabled);return t?e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"bots.discussMode",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("p",{className:"text-sm",children:s("Discussion mode")}),e.jsx(ie,{variant:"warning",size:"sm","data-experimental-badge":"",children:s("Experimental feature")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Off: group chats work the same as the stable release. On: in smart-routing groups, discussion-style messages let the judge model pick who speaks next.")})]}),e.jsx(ce,{checked:n,onCheckedChange:r=>a(r===!0)})]}):null}const Ha=Array.from({length:Rl-ja+1},(s,t)=>ja+t);function gx(){const{t:s}=R(),t=g(a=>a.botMaxRunningTurns),n=g(a=>a.setBotMaxRunningTurns);return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"bots.maxRunningTurns",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s("Bot concurrency limit")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Shared by private chats, group chats, delegations and routines. Lowering it never interrupts running work; raising it may hit model rate limits.")})]}),e.jsxs(se,{items:Object.fromEntries(Ha.map(a=>[String(a),String(a)])),value:String(t),onValueChange:a=>n(Number(a)),children:[e.jsx(te,{className:"w-20",children:e.jsx(ne,{})}),e.jsx(ae,{children:Ha.map(a=>e.jsx(Z,{value:String(a),children:a},a))})]})]})}function jx(){const{t:s}=R(),t=g(i=>i.botAssistantModel),n=g(i=>i.setBotAssistantModel),a=ns(),r=t?a.find(i=>i.id===t.providerId):void 0,o=r?.models.find(i=>i.id===t?.modelId);return e.jsxs("div",{className:"rounded-md border px-3 py-2.5","data-settings-row":"bots.assistantModel",children:[e.jsx("p",{className:"text-sm",children:s("Bot assistant model")}),e.jsx("p",{className:"mb-2 text-xs text-muted-foreground",children:s("Used for helper tasks such as auto-configuring member abilities.")}),e.jsx(Ue,{providers:a,providerId:o?r?.id??"":"",modelId:o?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:s("Follows the default model"),side:"bottom",triggerClassName:ss,onSelect:(i,u)=>n({providerId:i,modelId:u}),onReasoningChange:()=>{},onThinkingChange:()=>{}}),t&&!o&&e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:s("Selected model is unavailable — falls back to the default model.")}),t&&e.jsx(y,{variant:"ghost",size:"sm",className:"mt-1",onClick:()=>n(null),children:s("Follow default model")})]})}function vx(){const{t:s}=R(),t=g(u=>u.botRouteClassifier),n=g(u=>u.setBotRouteClassifier),a=g(u=>u.botDiscussModeEnabled),r=ns(),o=l.useMemo(()=>r.filter(no),[r]),i=_n();return e.jsxs("div",{className:"rounded-md border px-3 py-2.5","data-settings-row":"bots.routeClassifier",children:[e.jsx("p",{className:"text-sm",children:s("Group reply picker model")}),e.jsx("p",{className:"mb-2 text-xs text-muted-foreground",children:s("When nobody is @-mentioned in a smart-routing group, this model picks which member replies.")}),e.jsx(Ho,{value:t??void 0,onChange:u=>n(u??null),providers:o,classifierProviders:i,offLabel:s("Default (title model)"),judgeLabel:s("Fast chat model"),description:s(a?"First pick: the group owner replies on timeout, error or an unclear answer. During a discussion, picking the next speaker ends the discussion in these cases.":"Falls back to the group owner on timeout, error or an unclear answer."),effectiveTimeoutMs:t?dx(t):void 0,timeoutHint:s(a?"First pick: handed to the group owner on timeout. Next speaker in a discussion: the discussion ends on timeout.":"Handed to the group owner on timeout.")})]})}const bx=()=>({name:"",title:"",scope:"",summary:"",persona:"",color:cn[0],tools:"all",approvalMode:"auto-edits"}),gn=(s,t)=>({key:s,name:"",title:"",scope:"",persona:"",color:cn[t%cn.length],tools:"all",approvalMode:"auto-edits",canDelegateTo:[],acceptFrom:[]}),yx=()=>({title:"",summary:"",bossKey:"m1",workspace:"chat-home",members:[gn("m1",0),gn("m2",1)]});function wx(s,t){const n=URL.createObjectURL(new Blob([JSON.stringify(t,null,2)],{type:"application/json"})),a=document.createElement("a");a.href=n,a.download=s,a.click(),URL.revokeObjectURL(n)}function Nx(){const{t:s}=R(),t=Ol(!0),n=Dl(!0),[a,r]=l.useState(null),[o,i]=l.useState(null),u=l.useRef(null),d=async(h,j)=>{const b=await ql(A=>({...A,[h]:j(A[h])}));return b||Me({type:"error",title:s("Could not save templates")}),b},x=(h,j)=>d("members",b=>h?ya(b,h,j,Ql):wa(b,j,crypto.randomUUID())),p=(h,j)=>d("teams",b=>h?ya(b,h,j,Zl):wa(b,j,crypto.randomUUID())),c=async h=>{const j=Bl(await h.text());if(!j.ok){Me({type:"error",title:va(j.error,s)});return}const b=ro(Ul(j.team));if(!b){Me({type:"error",title:va("invalid",s)});return}await p(void 0,b)&&Me({type:"success",title:s("Imported as a custom team template")})},f=(h,j)=>d(h==="members"?"members":"teams",j),m=(h,j,b)=>e.jsxs(e.Fragment,{children:[e.jsx(vs,{label:s("Edit"),onClick:()=>b({id:j.id,data:j.data}),children:e.jsx(xs,{})}),e.jsx(vs,{label:s("Duplicate as custom"),onClick:()=>b({data:j.data}),children:e.jsx(ao,{})}),j.source==="builtin"&&e.jsx(vs,{label:j.hidden?s("Show"):s("Hide"),onClick:()=>{f(h,A=>Yl(A,j.id,!j.hidden))},children:j.hidden?e.jsx(_l,{}):e.jsx(Fl,{})}),j.modified&&e.jsx(vs,{label:s("Restore default"),onClick:()=>{f(h,A=>Na(A,j.id))},children:e.jsx(Fn,{})}),j.source==="custom"&&e.jsx(vs,{label:s("Delete"),onClick:()=>{f(h,A=>Na(A,j.id))},children:e.jsx(Re,{})})]});return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("Bot templates")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("Templates used when creating members and teams. Built-in templates can be edited, hidden or restored.")})]}),e.jsxs(Js,{defaultValue:"members",children:[e.jsxs(Xs,{variant:"underline",children:[e.jsx(Je,{value:"members",children:s("Member templates")}),e.jsx(Je,{value:"teams",children:s("Team templates")})]}),e.jsxs(Ks,{value:"members",className:"space-y-2 pt-3",children:[e.jsxs(y,{size:"sm",variant:"outline",onClick:()=>r({data:bx()}),children:[e.jsx(Pe,{}),s("New member template")]}),t.map(h=>e.jsx(qa,{item:h,avatar:e.jsx(ln,{bot:{name:h.data.name,avatar:{color:h.data.color}}}),title:h.data.name,subtitle:h.data.title,summary:h.data.summary,actions:m("members",h,r)},h.id))]}),e.jsxs(Ks,{value:"teams",className:"space-y-2 pt-3",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(y,{size:"sm",variant:"outline",onClick:()=>i({data:yx()}),children:[e.jsx(Pe,{}),s("New team template")]}),e.jsxs(y,{size:"sm",variant:"outline",onClick:()=>u.current?.click(),children:[e.jsx(Ll,{}),s("Import team (JSON)")]}),e.jsx("input",{ref:u,type:"file",accept:".json,application/json",hidden:!0,onChange:h=>{const j=h.target.files?.[0];h.target.value="",j&&c(j)}})]}),n.map(h=>e.jsx(qa,{item:h,avatar:e.jsx("div",{className:"-space-x-1.5 flex shrink-0",children:h.data.members.slice(0,4).map(j=>e.jsx(ln,{size:"sm",bot:{name:j.name,avatar:{color:j.color}}},j.key))}),title:h.data.title,subtitle:s("{{n}} members",{n:h.data.members.length}),summary:h.data.summary,actions:e.jsxs(e.Fragment,{children:[e.jsx(vs,{label:s("Export JSON"),onClick:()=>wx(`${h.data.title||"team"}.team.json`,{format:Xl,version:Jl,exportedAt:new Date().toISOString(),team:zl(h.data)}),children:e.jsx(Cn,{})}),m("teams",h,i)]})},h.id))]})]}),a&&e.jsx(kx,{initial:a.data,onClose:()=>r(null),onSave:async h=>{await x(a.id,h)&&r(null)}}),o&&e.jsx(Sx,{initial:o.data,onClose:()=>i(null),onSave:async h=>{await p(o.id,h)&&i(null)}})]})}function vs({label:s,onClick:t,disabled:n,children:a}){return e.jsx(y,{variant:"ghost",size:"icon-sm",title:s,"aria-label":s,disabled:n,onClick:t,children:a})}function qa({item:s,avatar:t,title:n,subtitle:a,summary:r,actions:o}){const{t:i}=R();return e.jsxs("div",{className:"flex items-center gap-3 rounded-md border px-3 py-2.5","data-template-id":s.id,children:[e.jsxs("div",{className:H("flex min-w-0 flex-1 items-center gap-3",s.hidden&&"opacity-50"),children:[t,e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("p",{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx("span",{className:"truncate",children:n}),e.jsx("span",{className:"truncate font-normal text-muted-foreground text-xs",children:a}),e.jsx(ie,{variant:"secondary",children:s.source==="custom"?i("Custom"):i("Built-in")}),s.modified&&e.jsx(ie,{variant:"outline",children:i("Modified")}),s.hidden&&e.jsx(ie,{variant:"outline",children:i("Hidden")})]}),e.jsx("p",{className:"truncate text-muted-foreground text-xs",children:r})]})]}),e.jsx("div",{className:"flex shrink-0 items-center",children:o})]})}function qo({title:s,error:t,onClose:n,onSave:a,children:r}){const{t:o}=R(),[i,u]=l.useState(!1);return e.jsx(ve,{open:!0,onOpenChange:d=>!d&&n(),children:e.jsxs(be,{className:"max-h-[85vh] max-w-2xl",children:[e.jsx(ye,{children:e.jsx(we,{children:s})}),e.jsxs(Ne,{className:"space-y-3",children:[r,t&&e.jsx("p",{className:"text-destructive text-xs",children:t})]}),e.jsxs(Ie,{children:[e.jsx(y,{variant:"outline",size:"sm",onClick:n,children:o("Cancel")}),e.jsx(y,{size:"sm",disabled:i||!!t,onClick:()=>{u(!0),a().finally(()=>u(!1))},children:o("Save")})]})]})})}function Yo({value:s,onChange:t}){const{t:n}=R(),a=s.name?oo(s.name,[],n):null;return e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(We,{children:n("Name")}),e.jsx(Q,{value:s.name,onChange:r=>t({name:r.target.value})}),a&&e.jsx("p",{className:"mt-1 text-destructive text-xs",children:a})]}),e.jsxs("div",{children:[e.jsx(We,{children:n("Title")}),e.jsx(Q,{value:s.title,onChange:r=>t({title:r.target.value})})]}),e.jsxs("div",{children:[e.jsx(We,{children:n("Avatar color")}),e.jsx(Wl,{value:s.color,onChange:r=>t({color:r})})]}),e.jsxs("div",{children:[e.jsx(We,{children:n("Tools")}),e.jsx(Ln,{value:s.tools,options:[{value:"all",label:n("All tools")},{value:"readonly",label:n("Read-only")}],onChange:r=>t({tools:r})})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(We,{children:n("Approval mode")}),e.jsx(Hl,{value:s.approvalMode,onChange:r=>t({approvalMode:r}),zIndex:ls.DROPDOWN_IN_MODAL})]}),s.summary!==void 0&&e.jsxs("div",{className:"col-span-2",children:[e.jsx(We,{hint:n("Shown on the template card"),children:n("Summary")}),e.jsx(Q,{value:s.summary,onChange:r=>t({summary:r.target.value})})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(We,{children:n("Responsibilities")}),e.jsx(Q,{value:s.scope,onChange:r=>t({scope:r.target.value})})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(We,{children:n("Persona")}),e.jsx(Ze,{rows:6,value:s.persona,onChange:r=>t({persona:r.target.value})})]})]})}function kx({initial:s,onClose:t,onSave:n}){const{t:a}=R(),[r,o]=l.useState(s),i=$l(r);return e.jsx(qo,{title:a("Member template"),error:oo(r.name,[],a)??(i?null:a("Check the template fields")),onClose:t,onSave:()=>i?n(i):Promise.resolve(),children:e.jsx(Yo,{value:r,onChange:u=>o(d=>({...d,...u}))})})}function Cx(s,t){switch(s){case"title":return t("Enter a team title");case"members":return t("A team needs 2–12 members");case"name":return t("Every member needs a valid name");case"invalid":return t("Check the template fields");default:return null}}function Sx({initial:s,onClose:t,onSave:n}){const{t:a}=R(),[r,o]=l.useState(s),[i,u]=l.useState(null),d=h=>r.members.find(j=>j.key===h)?.name||h,x=h=>o(j=>({...j,...h})),p=(h,j)=>o(b=>({...b,members:b.members.map(A=>A.key===h?{...A,...j}:A)})),c=()=>{const h=new Set(r.members.map(A=>A.key));let j=r.members.length+1;for(;h.has(`m${j}`);)j++;const b=`m${j}`;x({members:[...r.members,gn(b,r.members.length)]}),u(b)},f=h=>{const j=b=>b==="any"?"any":b.filter(A=>A!==h);x({members:r.members.filter(b=>b.key!==h).map(b=>({...b,canDelegateTo:j(b.canDelegateTo),acceptFrom:j(b.acceptFrom)}))})},m=ro(r);return e.jsxs(qo,{title:a("Team template"),error:Cx(Gl(r),a),onClose:t,onSave:()=>m?n(m):Promise.resolve(),children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(We,{children:a("Group name")}),e.jsx(Q,{value:r.title,onChange:h=>x({title:h.target.value})})]}),e.jsxs("div",{children:[e.jsx(We,{children:a("Owner")}),e.jsxs(se,{items:r.members.map(h=>({value:h.key,label:d(h.key)})),value:r.bossKey,onValueChange:h=>x({bossKey:h}),children:[e.jsx(te,{className:"w-full",children:e.jsx(ne,{})}),e.jsx(ae,{zIndex:ls.DROPDOWN_IN_MODAL,children:r.members.map(h=>e.jsx(Z,{value:h.key,children:d(h.key)},h.key))})]})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(We,{hint:a("Shown on the template card"),children:a("Summary")}),e.jsx(Q,{value:r.summary,onChange:h=>x({summary:h.target.value})})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(We,{children:a("Shared workspace")}),e.jsx(Ln,{value:r.workspace,options:[{value:"chat-home",label:a("Standalone workspace")},{value:"project",label:a("Based on a Code project")}],onChange:h=>x({workspace:h})})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1.5 flex items-center justify-between",children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:a("Members")}),e.jsxs(y,{size:"xs",variant:"outline",disabled:r.members.length>=Vl,onClick:c,children:[e.jsx(Pe,{}),a("Add member")]})]}),e.jsx("div",{className:"space-y-1.5",children:r.members.map(h=>{const j=i===h.key,b=h.key===r.bossKey,A=r.members.filter(k=>k.key!==h.key).map(k=>k.key);return e.jsxs("div",{className:"rounded-lg border","data-member-key":h.key,children:[e.jsxs("div",{className:"flex items-center gap-2 px-2.5 py-2",children:[e.jsxs("button",{type:"button",className:"flex min-w-0 flex-1 items-center gap-2 text-left",onClick:()=>u(j?null:h.key),children:[j?e.jsx(bt,{className:"h-3.5 w-3.5 shrink-0"}):e.jsx(Ys,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx(ln,{bot:{name:h.name,avatar:{color:h.color}},size:"sm"}),e.jsx("span",{className:"truncate text-sm",children:h.name||a("Unnamed")}),e.jsx("span",{className:"truncate text-muted-foreground text-xs",children:h.title}),b&&e.jsxs("span",{className:"flex shrink-0 items-center gap-0.5 rounded bg-muted px-1.5 text-[10px] text-muted-foreground",children:[e.jsx(Kl,{className:"h-3 w-3"}),a("Owner")]})]}),e.jsx(vs,{label:a("Remove"),disabled:b||r.members.length<=2,onClick:()=>f(h.key),children:e.jsx(Re,{})})]}),j&&e.jsxs("div",{className:"space-y-3 border-t p-2.5",children:[e.jsx(Yo,{value:h,onChange:k=>p(h.key,k)}),e.jsx(ba,{label:a("Can delegate to"),value:h.canDelegateTo,options:A,nameOf:d,onChange:k=>p(h.key,{canDelegateTo:k})}),e.jsx(ba,{label:a("Accepts delegation from"),value:h.acceptFrom,options:A,nameOf:d,onChange:k=>p(h.key,{acceptFrom:k})})]})]},h.key)})})]})]})}function Jo(s){return s.capturePermission==="unsupported"&&s.axPermission==="unsupported"?"unsupported":s.capturePermission==="granted"&&(s.axPermission==="granted"||s.axPermission==="unsupported")?"ready":"needs-permission"}const Ix=[{id:"collaboration",label:"Collaboration & planning"},{id:"web",label:"Web"},{id:"execution",label:"Execution"},{id:"context",label:"Context & memory"},{id:"safety",label:"Safety"}],Ya={subagent:"collaboration",workflow:"collaboration",todo:"collaboration",plan:"collaboration",ask_user:"collaboration",browser:"web",web:"web",background_tasks:"execution",isolated_sandbox:"execution",computer:"execution",image_generation:"execution",memory:"context",turn_discard:"context"};function Ax(s,t){return s.filter(n=>Object.hasOwn(Ya,n.id)?Ya[n.id]===t:!1)}function Ja(s){return s.bundleId||s.path}function Ex(){const{t:s}=R(),[t,n]=l.useState(null),a=g(i=>i.computerAllowAllApps),r=g(i=>i.setComputerAllowAllApps);l.useEffect(()=>{let i=!1;return window.electronAPI.computer.allowedApps().then(u=>{i||n(u)}),()=>{i=!0}},[]);const o=async i=>{await window.electronAPI.computer.revokeApp(Ja(i)),n(await window.electronAPI.computer.allowedApps())};return e.jsxs("div",{className:"space-y-2","data-settings-row":"tools.computerApps",children:[e.jsx("p",{className:"font-medium text-sm",children:s("Apps the AI may control")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:s("The first time the AI clicks or types in an app, EnsoCode asks you. Apps you always allow are listed here; it can then read everything in their windows.")}),e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium text-sm",children:s("Allow all apps")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:s("The AI can click, type and read in any app without asking. It can see everything in their windows, including chats and passwords.")})]}),e.jsx(ce,{checked:a,onCheckedChange:r})]}),t&&t.length===0?e.jsx("p",{className:"text-muted-foreground text-xs",children:s("No apps are always allowed yet.")}):null,t&&t.length>0?e.jsx("ul",{className:"divide-y rounded-md border",children:t.map(i=>e.jsxs("li",{className:"flex items-center justify-between gap-3 px-3 py-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-sm",children:i.name}),e.jsx("p",{className:"truncate text-muted-foreground text-xs",title:i.path,children:i.bundleId||i.path})]}),e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{o(i)},children:s("Revoke")})]},Ja(i)))}):null]})}function Mx(s){return Object.fromEntries(s.map(t=>[t.id,t]))}function At(s,t){return s.reduce((n,a)=>{const r=t[a]?.tokens;return r==null?n:n+r},0)}function Et({row:s,pending:t}){const{t:n}=R(),a=t?"…":s?.tokens==null?"—":qe(s.tokens);return e.jsx("span",{className:"w-12 shrink-0 text-right text-muted-foreground text-xs tabular-nums",title:s?.error||n("Estimate"),children:a})}function Mt({tokens:s}){return s<=0?null:e.jsx("span",{className:"ml-2 font-normal text-muted-foreground text-xs tabular-nums",children:qe(s)})}function Pt(s,t){const[n,a]=l.useState({}),[r,o]=l.useState(()=>s.length>0),i=s.join("\0"),u=l.useRef(t);return u.current=t,l.useEffect(()=>{let d=!1;const x=i.length===0?[]:i.split("\0");if(x.length===0){a({}),o(!1);return}return o(!0),u.current(x).then(p=>{d||a(Mx(p))}).finally(()=>{d||o(!1)}),()=>{d=!0}},[i]),{rows:n,pending:r}}const Xa={replace:"Text replacement",apply_patch:"Apply patch (default)"},Px={subagent:ic,workflow:Bn,todo:oc,plan:rc,ask_user:ac,browser:nc,web:lo,background_tasks:tc,memory:io,isolated_sandbox:Nu,computer:Dn,turn_discard:sc};function Ms({icon:s,title:t,description:n,control:a,children:r,rowId:o,newSession:i}){return e.jsxs("div",{className:"rounded-md border px-3 py-2.5","data-settings-row":o,children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(s,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("p",{className:"text-sm font-medium",children:[t,i&&e.jsx(ts,{note:typeof i=="string"?i:void 0})]}),e.jsx("p",{className:"text-muted-foreground text-xs",children:n})]}),a]}),r?e.jsx("div",{className:"mt-2 space-y-2 pl-7",children:r}):null]})}function Tx({disabled:s}){const{t}=R(),n=g(c=>c.webSearchChain),a=g(c=>c.setWebSearchChain),r=Qs(),o=l.useMemo(()=>dc(r),[r]),[i,u]=l.useState(null),d=(c,f)=>{a(n.map((m,h)=>h===c?{...m,...f}:m))},x=c=>a(n.filter((f,m)=>m!==c)),p=(c,f)=>{if(c===f)return;const m=[...n],[h]=m.splice(c,1);h&&(m.splice(f,0,h),a(m))};return e.jsxs("div",{className:"space-y-2","data-settings-row":"tools.webSearchChain",children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Try these models' built-in search in order. Credentials resolve at call time; if all fail, the keyless Exa service is the permanent fallback.")}),n.length===0&&e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Default: use the current session model's built-in search when available, otherwise Exa.")}),n.map((c,f)=>e.jsxs("div",{className:"flex items-center gap-2 rounded-md border px-2 py-1.5",draggable:!s,onDragStart:m=>{m.dataTransfer.effectAllowed="move",u(f)},onDragEnd:()=>u(null),onDragOver:m=>{i!==null&&i!==f&&m.preventDefault()},onDrop:m=>{m.preventDefault(),i!==null&&p(i,f),u(null)},children:[e.jsx(uc,{className:"h-3.5 w-3.5 shrink-0 cursor-grab text-muted-foreground"}),e.jsx("span",{className:"w-4 shrink-0 text-center text-muted-foreground text-xs",children:f+1}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx(Ue,{providers:o,providerId:c.providerId,modelId:c.modelId,reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,onSelect:(m,h)=>d(f,{providerId:m,modelId:h}),onReasoningChange:()=>{},onThinkingChange:()=>{}})}),e.jsx(y,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 shrink-0 p-0",disabled:s,onClick:()=>x(f),"aria-label":t("Remove"),children:e.jsx(Re,{className:"h-3.5 w-3.5"})})]},`${c.providerId}/${c.modelId}`)),n.length<mc&&e.jsx("div",{className:"max-w-xs",children:e.jsx(Ue,{providers:o,providerId:"",modelId:"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,triggerLabel:`+ ${t("Add candidate")}`,onSelect:(c,f)=>a([...n,{providerId:c,modelId:f}]),onReasoningChange:()=>{},onThinkingChange:()=>{}})}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Final fallback: Exa (keyless hosted search). Not a chain entry; always last.")})]})}function Rx(){const{t:s}=R(),t=g(w=>w.disabledBuiltinTools),n=g(w=>w.toggleBuiltinTool),a=g(w=>w.subagentAllowedModes),r=g(w=>w.setSubagentAllowedModes),o=g(w=>w.exploreFoldEnabled),i=g(w=>w.setExploreFoldEnabled),u=g(w=>w.rtkEnabled),d=g(w=>w.computerPreview),x=g(w=>w.setComputerPreview),p=g(w=>w.openLinksInBuiltinBrowser),c=g(w=>w.setOpenLinksInBuiltinBrowser),f=g(w=>w.setRtkEnabled),m=g(w=>w.protectedActionsInCode),h=g(w=>w.setProtectedActionsInCode),j=g(w=>w.editMode),b=g(w=>w.setEditMode),A=Pt($t.map(w=>w.id),()=>window.electronAPI.assets.builtinToolOccupancy()),k=At($t.filter(w=>!t.includes(w.id)).map(w=>w.id),A.rows),[N,S]=l.useState(null),M=!t.includes("subagent"),V=(w,z)=>{r(z?[...new Set([...a,w])]:a.filter(G=>G!==w))},E=async w=>{await window.electronAPI.browser.clearData(w),S(w),setTimeout(()=>S(null),2e3)},L=!t.includes("computer"),[P,C]=l.useState(null),[I,W]=l.useState(!1);l.useEffect(()=>{if(!L||vt()){C(null);return}let w=!1;return window.electronAPI.computer.capabilities().then(z=>{!w&&z.ok&&C(z.capabilities)}),()=>{w=!0}},[L]),l.useEffect(()=>{if(!I||vt())return;let w=!1;const z=()=>{window.electronAPI.computer.capabilities().then(B=>{!w&&B.ok&&C(B.capabilities)})};z();const G=window.setInterval(z,2e3);return()=>{w=!0,window.clearInterval(G)}},[I]);const J={collaboration:null,web:null,execution:e.jsx(Ms,{rowId:"tools.editMode",newSession:!0,icon:Eu,title:s("File edit mode"),description:s("Choose how files are modified. Apply patch is the default. New and cold-restored sessions use this mode; already warm sessions keep their current mode."),control:e.jsxs(se,{items:Object.fromEntries(ka.map(w=>[w,s(Xa[w])])),value:j,onValueChange:w=>{ec(w)&&b(w)},children:[e.jsx(te,{className:"w-44 shrink-0","aria-label":s("File edit mode"),children:e.jsx(ne,{})}),e.jsx(ae,{children:ka.map(w=>e.jsx(Z,{value:w,children:s(Xa[w])},w))})]})}),context:e.jsxs(e.Fragment,{children:[e.jsx(Ms,{icon:Ru,newSession:!0,title:s("Explore fold"),description:s("Let the agent mark exploratory reads and keep only a short report in later model context. Timeline stays intact."),control:e.jsx(ce,{checked:o,onCheckedChange:i})}),e.jsx(Ms,{rowId:"tools.rtkEnabled",newSession:!0,icon:Vu,title:s("RTK command compression"),description:s("Compress supported command output before it enters the model context. Takes effect on new conversations."),control:e.jsx(ce,{checked:u,onCheckedChange:f})})]}),safety:e.jsxs(e.Fragment,{children:[e.jsx(Ms,{icon:Sn,newSession:!0,title:s("Protected action confirmation"),description:s("Even in full-access mode, ask before external sends, deletions, payments, deployments and secret-file access. Always on for Bot members not set to Full access. Takes effect on new conversations."),control:e.jsx(ce,{checked:m,onCheckedChange:h})}),e.jsx(Ox,{})]})};return e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{"data-settings-row":"tools.root",children:[e.jsxs("h3",{className:"font-medium text-lg",children:[s("Built-in tools"),e.jsx(Mt,{tokens:k})]}),e.jsx("p",{className:"text-muted-foreground text-sm",children:s("Toggle the built-in tools available to agents.")})]}),Ix.map(w=>e.jsxs("section",{className:"space-y-3",children:[e.jsx("h4",{className:"border-b pb-2 text-base font-semibold",children:s(w.label)}),Ax($t,w.id).map(z=>e.jsxs(Ms,{icon:Px[z.id]??co,title:s(z.name),description:s(z.description),newSession:z.id==="isolated_sandbox"?s("Isolated sandbox switches between script and tool-search mode, so open sessions keep the mode they started with."):void 0,control:e.jsxs(e.Fragment,{children:[e.jsx(Et,{row:A.rows[z.id],pending:A.pending&&!A.rows[z.id]}),e.jsx(ce,{checked:!t.includes(z.id),onCheckedChange:G=>{n(z.id,G),z.id==="computer"&&G&&W(!0)}})]}),children:[z.id==="web"?e.jsx(Tx,{disabled:t.includes("web")}):null,z.id==="subagent"?e.jsxs("div",{className:"space-y-2","data-settings-row":"tools.subagentModes",children:[[["task","One-shot task agents"],["coworker","Persistent coworkers"]].map(([G,B])=>e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("span",{className:"text-sm",children:s(B)}),e.jsx(ce,{checked:a.includes(G),disabled:!M,onCheckedChange:U=>V(G,U)})]},G)),!M&&e.jsx("p",{className:"text-muted-foreground text-xs",children:s("The unified subagent tool is off. Re-enabling it keeps this mode selection.")})]}):null,z.id==="computer"&&L?e.jsx("div",{className:"space-y-2","data-settings-row":"tools.computer",children:P&&Jo(P)==="unsupported"?e.jsx("p",{className:"text-muted-foreground text-xs",children:s("This platform cannot operate the desktop yet.")}):e.jsxs(e.Fragment,{children:[P?.platform==="darwin"&&e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Computer needs Screen Recording to capture windows and Accessibility to inspect or click them. Grant both to EnsoCode, then restart the app.")}),P&&e.jsxs("p",{className:"text-muted-foreground text-xs",children:[s(P.capturePermission==="granted"?"Capture: granted":"Capture: denied"),P.axPermission!=="unsupported"&&e.jsxs(e.Fragment,{children:[" · ",s(P.axPermission==="granted"?"Input/AX: granted":"Input/AX: denied")]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(y,{variant:"outline",size:"sm",onClick:()=>W(!0),children:s("Show permission guide")}),P?.platform==="darwin"&&e.jsxs(e.Fragment,{children:[e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.computer.openPermissions("screen")},children:s("Open Screen Recording settings")}),e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.computer.openPermissions("accessibility")},children:s("Open Accessibility settings")})]})]}),P?.platform==="darwin"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium text-sm",children:s("Show the app being operated")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:s("While the AI works in an app in the background, a small floating window shows that app live. Close it any time.")})]}),e.jsx(ce,{checked:d,onCheckedChange:x})]}),e.jsx(Ex,{})]})]})}):null,z.id==="browser"?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium text-sm",children:s("Open chat links in the built-in browser")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Clicking a web link in chat opens it in the side panel browser. {{key}}+Click opens it in the external browser.",{key:lc?"Cmd":"Ctrl"})})]}),e.jsx(ce,{checked:p,onCheckedChange:c})]}),e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Cookies and site storage of the built-in browser, separate from the app itself.")}),e.jsx("div",{className:"flex flex-wrap gap-2",children:["cookies","cache","all"].map(G=>e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{E(G)},children:s(N===G?"Cleared":G==="cookies"?"Clear cookies":G==="cache"?"Clear cache":"Clear all browsing data")},G))})]}):null]},z.id)),J[w.id]]},w.id)),e.jsx(Dx,{open:I,capabilities:P,onOpenChange:W})]})}function Ox(){const{t:s}=R(),t=g(m=>m.dcgEnabled),n=g(m=>m.setDcgEnabled),[a,r]=l.useState(null),[o,i]=l.useState(!1),[u,d]=l.useState(null),[x,p]=l.useState(!1);l.useEffect(()=>{let m=!1;return window.electronAPI.dcg.status().then(h=>{m||r(h)}),()=>{m=!0}},[]);const c=async m=>{p(!1),i(!0),d(null);const h=await window.electronAPI.dcg[m]();r(h.status),h.ok?n(m==="install"):d(h.error??s("Operation failed")),i(!1)},f=a?.installed===!0;return e.jsxs(Ms,{rowId:"tools.dcgEnabled",newSession:!0,icon:cc,title:s("Destructive command guard (dcg)"),description:s("Check bash and PowerShell commands with dcg before running. Matches such as git reset --hard or recursive deletes always require your confirmation, even in full-access mode. Takes effect on new conversations."),control:e.jsx(ce,{checked:t&&f,disabled:!f,onCheckedChange:n}),children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("span",{className:"text-muted-foreground",children:a?a.supported?f?s("Installed v{{version}}",{version:a.version}):s("Not installed"):s("Not available on this platform"):s("Loading…")}),a?.supported&&(f?e.jsx(y,{variant:"outline",size:"xs",disabled:o,onClick:()=>{c("uninstall")},children:s("Uninstall")}):e.jsx(y,{variant:"outline",size:"xs",disabled:o,onClick:()=>p(!0),children:s(o?"Installing…":"Install")}))]}),u&&e.jsx("p",{className:"text-destructive text-xs",children:u}),e.jsx(ve,{open:x,onOpenChange:p,children:e.jsxs(be,{className:"max-w-md",zIndexLevel:"nested",children:[e.jsxs(ye,{children:[e.jsx(we,{children:s("Install dcg")}),e.jsx(Ye,{children:s("Downloads dcg v{{version}} from its GitHub release and verifies the checksum. dcg is a third-party tool, not part of EnsoCode.",{version:a?.version??""})})]}),e.jsx(Ne,{children:e.jsxs("div",{className:"flex gap-2 rounded-md border border-destructive/32 bg-destructive/8 p-3 text-sm",children:[e.jsx(He,{className:"mt-0.5 h-4 w-4 shrink-0 text-destructive"}),e.jsx("p",{children:s("dcg is licensed under MIT with an additional rider: no rights are granted to OpenAI, Anthropic, their affiliates, or anyone acting on their behalf. Install only if this restriction does not apply to you.")})]})}),e.jsxs(Ie,{children:[e.jsx(y,{variant:"outline",size:"sm",onClick:()=>p(!1),children:s("Cancel")}),e.jsx(y,{size:"sm",onClick:()=>{c("install")},children:s("Agree and install")})]})]})})]})}function Dx({open:s,capabilities:t,onOpenChange:n}){const{t:a}=R(),r=t?Jo(t):null;return e.jsx(ve,{open:s,onOpenChange:n,children:e.jsxs(be,{className:"max-w-md",zIndexLevel:"nested",children:[e.jsxs(ye,{children:[e.jsx(we,{children:a("Grant Computer permissions")}),e.jsx(Ye,{children:a(r==="unsupported"?"This platform cannot operate the desktop yet.":r==="ready"?"Computer is ready. Open sessions can use it from their next step.":"The agent can screenshot windows and control the mouse and keyboard. Grant Screen Recording and Accessibility to EnsoCode, then restart.")})]}),e.jsxs(Ne,{className:"space-y-3",children:[!t&&e.jsx("p",{className:"text-muted-foreground text-sm",children:a("Loading…")}),r==="needs-permission"&&e.jsxs("div",{className:"flex gap-2 rounded-md border border-destructive/32 bg-destructive/8 p-3 text-sm",children:[e.jsx(He,{className:"mt-0.5 h-4 w-4 shrink-0 text-destructive"}),e.jsx("p",{children:a("Computer needs Screen Recording to capture windows and Accessibility to inspect or click them. Grant both to EnsoCode, then restart the app.")})]}),t?.platform==="darwin"&&r!=="unsupported"&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("p",{className:"text-muted-foreground text-xs",children:[a(t.capturePermission==="granted"?"Capture: granted":"Capture: denied")," · ",a(t.axPermission==="granted"?"Input/AX: granted":"Input/AX: denied"),t.detail?` · ${t.detail}`:""]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.computer.openPermissions("screen")},children:a("Open Screen Recording settings")}),e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.computer.openPermissions("accessibility")},children:a("Open Accessibility settings")})]})]})]}),e.jsx(Ie,{className:"sm:justify-end",children:e.jsx(y,{size:"sm",onClick:()=>n(!1),children:a("Done")})})]})})}function Lx(){return e.jsxs("div",{className:"space-y-10",children:[e.jsx(zx,{}),!window.electronAPI.remote&&e.jsx(_x,{}),e.jsx(Ux,{})]})}function zx(){const{t:s}=R(),[t,n]=l.useState(null),[a,r]=l.useState(null),[o,i]=l.useState(!1),[u,d]=l.useState(null),[x,p]=l.useState(null),[c,f]=l.useState(!1),m=t?.pairingExpiresAt;l.useEffect(()=>{if(!m){p(null);return}const A=()=>p(Math.max(0,Math.ceil((m-Date.now())/1e3)));A();const k=setInterval(A,1e3);return()=>clearInterval(k)},[m]);const h=A=>{navigator.clipboard.writeText(A).then(()=>{f(!0),setTimeout(()=>f(!1),1500)})};l.useEffect(()=>{if(!vt())return window.electronAPI.pair.status().then(n),window.electronAPI.pair.onStatusChanged(A=>{n(A),(A.pairing||A.devices.length>0)&&d(null)})},[]),l.useEffect(()=>{const A=t?.inviteUri;if(!A){r(null);return}xc.toDataURL(A,{width:320,margin:1}).then(r).catch(()=>{})},[t?.inviteUri]);const j=async()=>{i(!0),d(null);const A=await window.electronAPI.pair.start();i(!1),A.ok||d(A.error??s("Failed to start pairing"))},b=t?.devices??[];return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-end justify-between gap-4","data-settings-row":"phone.root",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-medium text-lg",children:s("Allow connections")}),e.jsx("p",{className:"text-muted-foreground text-sm",children:s("Let your phone or another EnsoCode desktop connect to this computer. Keep this app running.")})]}),e.jsx("div",{className:"flex shrink-0 items-center gap-2",children:t?.pairing?e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.pair.cancel()},children:s("Cancel pairing")}):e.jsxs(y,{variant:"outline",size:"sm",disabled:o,onClick:()=>{j()},children:[o?e.jsx(Ae,{className:"mr-1.5 h-4 w-4 animate-spin"}):e.jsx(dn,{className:"mr-1.5 h-4 w-4"}),s("Generate pairing code")]})})]}),t&&!t.secureStorage&&e.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-dashed px-3 py-2 text-xs",children:[e.jsx(He,{className:"mt-0.5 h-4 w-4 shrink-0 text-destructive"}),e.jsx("span",{className:"text-muted-foreground",children:s("Secure storage is unavailable on this system, so pairing keys are stored unencrypted.")})]}),u&&e.jsx("p",{className:"text-destructive text-xs",children:u}),t?.pairing&&e.jsxs("div",{className:"space-y-3 rounded-md border border-dashed px-3 py-6",children:[e.jsxs("div",{className:"text-center",children:[a?e.jsx("img",{src:a,alt:s("Pairing QR code"),className:"mx-auto h-52 w-52"}):e.jsx(Ae,{className:"mx-auto h-5 w-5 animate-spin text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:s("Scan with your phone camera")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:s("Scanning opens the app and pairs it. To keep it handy, add it to your home screen.")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:s("On another EnsoCode desktop, paste the link below into Settings → Devices → Connect to a node.")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:x===null?s("The code expires in 60 seconds and can only be used once."):x>0?s("Expires in {{seconds}}s · single use",{seconds:x}):s("Code expired")})]}),t.inviteUri&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"min-w-0 flex-1 truncate rounded bg-muted px-2 py-1.5 font-mono text-[11px] text-muted-foreground",children:t.inviteUri}),e.jsxs(y,{variant:"outline",size:"sm",className:"shrink-0",onClick:()=>h(t.inviteUri),children:[c?e.jsx(uo,{className:"mr-1.5 h-3.5 w-3.5"}):e.jsx(ao,{className:"mr-1.5 h-3.5 w-3.5"}),s(c?"Copied":"Copy")]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"font-medium text-sm",children:s("Paired devices")}),b.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx(dn,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:s("No paired devices")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:s("Generate a pairing code to let a phone or another desktop connect.")})]}):e.jsx("div",{className:"space-y-1",children:b.map(A=>e.jsx(Fx,{device:A},A.pairId))})]})]})}function _x(){const{t:s}=R(),t=lt(i=>i.nodes),n=lt(i=>i.secureStorage),a=lt(i=>i.refresh),[r,o]=l.useState(!1);return l.useEffect(()=>lt.getState().bind(),[]),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-end justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-medium text-lg",children:s("Connect to a node")}),e.jsx("p",{className:"text-muted-foreground text-sm",children:s("Browse and drive conversations on another EnsoCode desktop. Its agent, keys and history stay there.")})]}),e.jsxs(y,{variant:"outline",size:"sm",className:"shrink-0",onClick:()=>o(!0),children:[e.jsx(Pe,{className:"mr-1.5 h-4 w-4"}),s("Connect to a node")]})]}),!n&&e.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-dashed px-3 py-2 text-xs",children:[e.jsx(He,{className:"mt-0.5 h-4 w-4 shrink-0 text-destructive"}),e.jsx("span",{className:"text-muted-foreground",children:s("Secure storage is unavailable on this system, so pairing keys are stored unencrypted.")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"font-medium text-sm",children:s("Connected nodes")}),t.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx(Dn,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:s("No connected nodes")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:s("Each connecting computer needs its own pairing code from the other desktop.")})]}):e.jsx("div",{className:"space-y-1",children:t.map(i=>e.jsx(Bx,{node:i,onChanged:()=>{a()}},i.nodeId))})]}),e.jsx(hc,{open:r,onOpenChange:o,switchOnSuccess:!1})]})}function Xo({transport:s,rttMs:t}){const{t:n}=R(),a=s==="direct",r=fc(t);return e.jsxs("span",{className:H("shrink-0 rounded px-1.5 py-0.5 text-[10px] leading-none",a?"bg-emerald-500/15 text-emerald-600":"bg-muted text-muted-foreground"),children:[n(a?"Direct link":"Via relay"),r?` · ${r}`:""]})}function Fx({device:s}){const{t}=R(),[n,a]=l.useState(null),r=async()=>{n!==null&&(n.trim()&&n.trim()!==s.deviceName&&await window.electronAPI.pair.rename(s.pairId,n),a(null))};return e.jsxs("div",{className:"group flex items-center justify-between gap-3 rounded-md px-3 py-2 transition-colors hover:bg-accent/50",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[e.jsx("span",{className:H("h-2 w-2 shrink-0 rounded-full",s.phoneOnline?"bg-emerald-500":s.connected?"bg-amber-500":"bg-muted-foreground/40")}),n===null?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"truncate font-medium text-sm",children:s.deviceName}),e.jsx("span",{className:"shrink-0 text-muted-foreground text-xs",children:s.phoneOnline?t("Online"):s.connected?t("Waiting for device"):t("Offline")}),s.phoneOnline&&e.jsx(Xo,{transport:s.transport,rttMs:s.rttMs}),e.jsx("button",{type:"button",title:t("Click to switch: view-only devices cannot send, approve or stop."),onClick:()=>{window.electronAPI.pair.setScope(s.pairId,s.scope==="read"?"operate":"read")},className:H("shrink-0 rounded px-1.5 py-0.5 text-[10px] leading-none transition-colors",s.scope==="read"?"bg-amber-500/15 text-amber-600 hover:bg-amber-500/25":"bg-muted text-muted-foreground hover:bg-accent"),children:s.scope==="read"?t("View only"):t("Can operate")})]}):e.jsx(Q,{value:n,autoFocus:!0,onChange:o=>a(o.target.value),onBlur:()=>{r()},onKeyDown:o=>{o.key==="Enter"&&r(),o.key==="Escape"&&a(null)},className:"h-7 text-sm"})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1 opacity-0 transition-opacity group-hover:opacity-100",children:[e.jsx(y,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground",title:t("Rename"),onClick:()=>a(s.deviceName),children:e.jsx(xs,{className:"h-3.5 w-3.5"})}),e.jsx(y,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-destructive",onClick:()=>{window.electronAPI.pair.revoke(s.pairId)},children:e.jsx(Re,{className:"h-3.5 w-3.5"})})]})]})}function Bx({node:s,onChanged:t}){const{t:n}=R(),[a,r]=l.useState(null),o=async()=>{a!==null&&(a.trim()&&a.trim()!==s.label&&(await window.electronAPI.nodes.rename(s.nodeId,a),t()),r(null))};return e.jsxs("div",{className:"group flex items-center justify-between gap-3 rounded-md px-3 py-2 transition-colors hover:bg-accent/50",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[e.jsx(pc,{node:s}),a===null?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"truncate font-medium text-sm",children:s.label}),s.hostname&&s.hostname!==s.label&&e.jsx("span",{className:"shrink-0 truncate font-mono text-[10px] text-muted-foreground",children:s.hostname}),e.jsx("span",{className:"shrink-0 text-muted-foreground text-xs",children:s.hostOnline?n("Online"):s.connected?n("Remote desktop is offline"):n("Offline")}),s.hostOnline&&e.jsx(Xo,{transport:s.transport,rttMs:s.rttMs})]}):e.jsx(Q,{value:a,autoFocus:!0,onChange:i=>r(i.target.value),onBlur:()=>{o()},onKeyDown:i=>{i.key==="Enter"&&o(),i.key==="Escape"&&r(null)},className:"h-7 text-sm"})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1 opacity-0 transition-opacity group-hover:opacity-100",children:[e.jsx(y,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground",title:n("Rename"),onClick:()=>r(s.label),children:e.jsx(xs,{className:"h-3.5 w-3.5"})}),e.jsx(y,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-destructive",title:n("Disconnect"),onClick:()=>{window.electronAPI.nodes.remove(s.nodeId).then(t)},children:e.jsx(Re,{className:"h-3.5 w-3.5"})})]})]})}function Ux(){const{t:s}=R(),[t,n]=l.useState(null),[a,r]=l.useState(null);l.useEffect(()=>(window.electronAPI.pair.status().then(n),window.electronAPI.pair.onStatusChanged(n)),[]);const o=async()=>{a!==null&&(n(await window.electronAPI.pair.setRelayUrl(a)),r(null))};return e.jsx("div",{className:"space-y-6",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"font-medium text-sm",children:s("Relay server")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:s("The relay only forwards encrypted frames and cannot read your messages.")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Q,{value:a??t?.relayUrl??"",onChange:i=>r(i.target.value),placeholder:"https://relay.example.com",className:"font-mono text-xs"}),a===null?e.jsx(y,{variant:"ghost",size:"icon",className:"h-8 w-8 shrink-0 text-muted-foreground",onClick:()=>r(t?.relayUrl??""),children:e.jsx(xs,{className:"h-3.5 w-3.5"})}):e.jsxs(y,{size:"sm",className:"shrink-0",onClick:()=>{o()},children:[e.jsx(uo,{className:"mr-1.5 h-3.5 w-3.5"}),s("Save")]})]})]})})}function $x({onOpenBots:s}){const{t}=R(),n=g(c=>c.botModeEnabled),a=g(c=>c.setBotModeEnabled),r=g(c=>c.scratchSessionsEnabled),o=g(c=>c.setScratchSessionsEnabled),i=g(c=>c.dropShelfEnabled),u=g(c=>c.setDropShelfEnabled),d=g(c=>c.secretaryEnabled),x=g(c=>c.setSecretaryEnabled),p=window.electronAPI.env.platform==="darwin"&&!window.electronAPI.remote;return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:t("Experimental")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("Features still being tested. They may change or be removed.")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Se,{rowId:"experimental.botMode",title:t("Bot mode"),description:t("Adds a Code | Bot switch to the sidebar. Create members with their own persona, model and tools, and chat with them alone or in groups."),checked:n,onChange:a}),n&&e.jsx(y,{variant:"outline",size:"sm",onClick:s,children:t("Bot mode settings")}),e.jsx(Se,{rowId:"experimental.scratchSessions",title:t("Temporary chats"),description:t("Chats that are not tied to a project. Tools follow your global settings."),checked:r,onChange:o}),p&&e.jsx(Se,{rowId:"experimental.dropShelf",title:t("Drop shelf"),description:t("When you drag files in Finder, a small panel appears at the top right of the screen. Drop them on it to reference them in the current conversation, or drop folders to open them as projects, even when EnsoCode is minimized or in the tray."),checked:i,onChange:u}),e.jsx(Se,{rowId:"experimental.secretary",title:t("Secretary"),description:t("A global agent that watches your projects and sessions, creates sessions to do the work, and reports results back to you."),checked:d,onChange:x})]})]})}function Vx({instruction:s,onClose:t}){const{t:n}=R(),a=g(E=>E.addInstructions),r=g(E=>E.updateInstruction),o=s==="new",i=o||!s?null:s,[u,d]=l.useState(""),[x,p]=l.useState(""),[c,f]=l.useState(!1),[m,h]=l.useState(!1),[j,b]=l.useState(null),[A,k]=l.useState(!1),[N,S]=l.useState(!1);l.useEffect(()=>{if(s){if(s==="new"){d(""),p(""),k(!1),b(null),S(!1),f(!1);return}d(s.name),k(!1),b(null),S(!1),f(!0),window.electronAPI.instructions.read(s.id,s.local,s.sourcePath).then(E=>{E.ok?p(E.content):(p(""),b(E.error??n("Failed to read content")))}).finally(()=>f(!1))}},[s,n]);const M=!!(i&&!i.local&&i.sourcePath),V=async()=>{if(!s||!u.trim())return;if(h(!0),o){const L=crypto.randomUUID(),P=await window.electronAPI.instructions.write(L,x);if(!P.ok){h(!1),b(n("Failed to save"));return}const C=a([{id:L,name:u.trim(),source:"Manual",local:!0,bytes:P.bytes,enabled:!0}]);if(h(!1),C===0){window.electronAPI.instructions.delete(L),b(n("An instruction with this name already exists"));return}t();return}if(!i){h(!1);return}if(M&&N&&i.sourcePath){const L=await window.electronAPI.instructions.writeSource(i.id,i.sourcePath,x);if(h(!1),!L.ok){b(L.error??n("Failed to save"));return}r(i.id,{name:u.trim(),bytes:L.bytes}),t();return}const E=await window.electronAPI.instructions.write(i.id,x);if(h(!1),!E.ok){b(n("Failed to save"));return}r(i.id,{name:u.trim(),local:!0,bytes:E.bytes}),t()};return e.jsx(ve,{open:s!==null,onOpenChange:E=>!E&&t(),children:e.jsxs(be,{className:"max-w-2xl",children:[e.jsx(ye,{children:e.jsx(we,{children:n(o?"Add Instruction":"Edit Instruction")})}),e.jsxs(Ne,{className:"space-y-4",children:[o?null:M?e.jsxs("div",{className:H("w-full rounded-md border px-3 py-2.5 transition-colors",N?"border-destructive/32 bg-destructive/8":"border-amber-500/32 bg-amber-500/8"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[N?e.jsx(He,{className:"h-3.5 w-3.5 shrink-0 text-destructive"}):e.jsx(gt,{className:"h-3.5 w-3.5 shrink-0 text-amber-600 dark:text-amber-500"}),e.jsx("span",{className:"font-medium text-xs",children:n("Write back to original file")})]}),e.jsx(ce,{checked:N,onCheckedChange:S})]}),e.jsx("p",{className:"mt-1.5 pl-5.5 text-muted-foreground text-xs leading-relaxed",children:N?n("Saving overwrites {{path}} directly — {{source}} will pick up the change.",{path:i?.sourcePath??"",source:i?.source??""}):n("Saving creates a local copy — {{path}} is left untouched, and this entry stops following its updates.",{path:i?.sourcePath??""})})]}):e.jsxs("div",{className:"flex w-full items-start gap-2 rounded-md border bg-muted/50 px-3 py-2",children:[e.jsx(gt,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx("p",{className:"text-muted-foreground text-xs leading-relaxed",children:n("Local copy — edits stay in this app.")})]}),e.jsxs(ue,{children:[e.jsx(me,{children:n("Name")}),e.jsx(Q,{value:u,onChange:E=>d(E.target.value)})]}),e.jsxs(ue,{children:[e.jsx(me,{children:n("Content")}),c?e.jsxs("div",{className:"flex w-full items-center justify-center gap-2 rounded-md border py-12",children:[e.jsx(Ae,{className:"h-4 w-4 animate-spin text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground text-xs",children:n("Loading...")})]}):e.jsx(Ze,{value:x,onChange:E=>{p(E.target.value),k(!0)},rows:16,className:"font-mono text-xs"})]}),j&&e.jsxs("p",{className:"flex items-center gap-1.5 text-destructive text-xs",children:[e.jsx(Rs,{className:"h-3.5 w-3.5 shrink-0"}),j]})]}),e.jsxs(Ie,{children:[e.jsx(y,{variant:"outline",size:"sm",onClick:t,children:n("Cancel")}),e.jsxs(y,{size:"sm",variant:M&&N?"destructive":"default",disabled:!u.trim()||c||m,onClick:V,children:[m&&e.jsx(Ae,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}),n(M?N?"Overwrite original":A?"Save as local copy":"Save":"Save")]})]})]})})}const Qa=s=>s<1024?`${s} B`:`${(s/1024).toFixed(1)} KB`;function Kx(){const{t:s}=R(),t=g(c=>c.instructions),n=g(c=>c.updateInstruction),a=g(c=>c.removeInstruction),[r,o]=l.useState(!1),[i,u]=l.useState(null),d=t.map(c=>c.id),x=Pt(d,c=>window.electronAPI.assets.instructionOccupancy(c)),p=At(t.filter(c=>c.enabled).map(c=>c.id),x.rows);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-end justify-between gap-4","data-settings-row":"instructions.root",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"font-medium text-lg",children:[s("Instruction Files"),e.jsx(Mt,{tokens:p}),e.jsx(ts,{})]}),e.jsx("p",{className:"text-muted-foreground text-sm",children:s("Global CLAUDE.md / AGENTS.md style files from local AI tools")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Only one file is active at a time; enabling one disables the others")})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsxs(y,{variant:"outline",size:"sm",onClick:()=>o(!0),children:[e.jsx(It,{className:"mr-1.5 h-4 w-4"}),s("Import from local apps")]}),e.jsxs(y,{variant:"outline",size:"sm",onClick:()=>u("new"),children:[e.jsx(Pe,{className:"mr-1.5 h-4 w-4"}),s("Add instruction")]})]})]}),t.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx(Un,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:s("No instruction files yet")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:s("Import instruction files from local apps or add one manually to get started")})]}):e.jsx("div",{className:"space-y-1",children:t.map(c=>e.jsxs("div",{className:"group flex items-center justify-between gap-3 rounded-md px-3 py-2 transition-colors hover:bg-accent/50","data-settings-row":`instructions.${c.id}`,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:H("shrink-0 font-medium text-sm",!c.enabled&&"text-muted-foreground line-through"),children:c.name}),e.jsx(ie,{variant:"secondary",className:"shrink-0 text-[11px]",children:c.source}),!c.local&&e.jsxs(ie,{variant:"outline",className:"shrink-0 gap-1 text-[11px]",children:[e.jsx(mo,{className:"h-3 w-3"}),s("Linked")]}),e.jsx("span",{className:"min-w-0 truncate text-muted-foreground text-xs",children:c.local?`${s("Local copy")} · ${Qa(c.bytes)}`:`${c.sourcePath} · ${Qa(c.bytes)}`})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(Et,{row:x.rows[c.id],pending:x.pending&&!x.rows[c.id]}),e.jsx(ce,{checked:c.enabled,onCheckedChange:f=>n(c.id,{enabled:f})}),e.jsx(y,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",onClick:()=>u(c),children:e.jsx(xs,{className:"h-3.5 w-3.5"})}),e.jsx(y,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity hover:text-destructive group-hover:opacity-100",onClick:()=>a(c.id),children:e.jsx(Re,{className:"h-3.5 w-3.5"})})]})]},c.id))}),e.jsx($n,{kind:"instruction",open:r,onOpenChange:o}),e.jsx(Vx,{instruction:i,onClose:()=>u(null)})]})}function Gx(){const{t:s}=R();return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{"data-settings-row":"shortcuts.root",children:[e.jsx("h3",{className:"text-lg font-medium",children:s("Shortcuts")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("Click a shortcut to rebind it. Backspace removes it; Esc cancels.")})]}),e.jsx(qx,{}),e.jsx(Hx,{})]})}function Wx(){const[s,t]=l.useState([]);return l.useEffect(()=>{const n=window.electronAPI.extensionPlugins;let a=!0;const r=()=>{n.list().then(i=>a&&t(vc(i)))};r();const o=n.onChanged(r);return()=>{a=!1,o()}},[]),s}function Hx(){const{t:s}=R(),t=Wx(),n=g(h=>h.keybindings),a=g(h=>h.setKeybinding),r=g(h=>h.resetKeybinding),[o,i]=l.useState(null),[u,d]=l.useState(null);if(t.length===0)return null;const x=xo(n),{rows:p}=gc(t,n,x),c=h=>p.find(j=>j.action===h)?.command.title??s(mn[h]??h),f=()=>{i(null),d(null)},m=(h,j,b)=>{if(h.preventDefault(),h.stopPropagation(),h.key==="Escape")return f();if(h.key==="Backspace"||h.key==="Delete")return a(j,""),f();const A=fo(h);if(!A)return;const k=un.find(N=>x[N]===A)??p.find(N=>N.action!==j&&!N.conflict&&N.binding===A)?.action;if(k)return d(k);A===b?r(j):a(j,A),f()};return e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium text-sm",children:"插件命令"}),e.jsx("div",{className:"divide-y rounded-md border",children:p.map(({action:h,command:j,binding:b,custom:A,conflict:k})=>{const N=o===h;return e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-sm",children:j.title}),e.jsxs("p",{className:"text-muted-foreground text-xs",children:[j.pluginName,k&&!N&&e.jsx("span",{className:"ml-2 text-destructive",children:s('Already used by "{{label}}"',{label:c(k)})})]})]}),N&&u&&e.jsx("span",{className:"text-destructive text-xs",children:s('Already used by "{{label}}"',{label:c(u)})}),b&&!N&&e.jsx("button",{type:"button",title:s("Remove shortcut"),onClick:()=>a(h,""),className:"rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:e.jsx(bs,{className:"h-3.5 w-3.5"})}),A&&!N&&e.jsx("button",{type:"button",title:s("Reset to default"),onClick:()=>r(h),className:"rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:e.jsx(Fn,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>{i(h),d(null)},onKeyDown:N?S=>m(S,h,j.key):void 0,onBlur:()=>N&&f(),autoFocus:N,className:H("rounded-md px-1 py-0.5 transition-colors",N?"ring-1 ring-ring":"hover:bg-muted",k&&!N&&"opacity-50 line-through"),children:N?e.jsx("span",{className:"text-muted-foreground text-xs",children:s("Press shortcut…")}):b?e.jsx(ho,{children:po(b)}):e.jsx("span",{className:"text-muted-foreground text-xs",children:s("No shortcut")})})]},h)})})]})}function qx(){const{t:s}=R(),t=g(p=>p.keybindings),n=g(p=>p.setKeybinding),a=g(p=>p.resetKeybinding),[r,o]=l.useState(null),[i,u]=l.useState(null),d=xo(t),x=p=>{if(p.preventDefault(),p.stopPropagation(),!r)return;if(p.key==="Escape"){o(null),u(null);return}if(p.key==="Backspace"||p.key==="Delete"){n(r,""),o(null),u(null);return}const c=fo(p,{allowBare:r==="send-message"});if(!c)return;const f=un.find(m=>m!==r&&d[m]===c);if(f){u(f);return}c===jc[r]?a(r):n(r,c),o(null),u(null)};return e.jsx("div",{className:"divide-y rounded-md border",children:un.map(p=>{const c=r===p,f=t[p]!==void 0,m=d[p];return e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-sm",children:s(mn[p])}),Ca[p]&&e.jsx("p",{className:"text-muted-foreground text-xs",children:s(Ca[p])})]}),c&&i&&e.jsx("span",{className:"text-xs text-destructive",children:s('Already used by "{{label}}"',{label:s(mn[i])})}),m&&!c&&e.jsx("button",{type:"button",title:s("Remove shortcut"),onClick:()=>n(p,""),className:"rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:e.jsx(bs,{className:"h-3.5 w-3.5"})}),f&&!c&&e.jsx("button",{type:"button",title:s("Reset to default"),onClick:()=>a(p),className:"rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:e.jsx(Fn,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>{o(p),u(null)},onKeyDown:c?x:void 0,onBlur:()=>{c&&(o(null),u(null))},autoFocus:c,className:H("rounded-md px-1 py-0.5 transition-colors",c?"ring-1 ring-ring":"hover:bg-muted"),children:c?e.jsx("span",{className:"text-xs text-muted-foreground",children:s("Press shortcut…")}):m?e.jsx(ho,{children:po(m)}):e.jsx("span",{className:"text-xs text-muted-foreground",children:s("No shortcut")})})]},p)})})}function Yx(s){return s.serverId??s.serverName}function Qo(s,t){const n={...s};return t.serverId&&delete n[t.serverName],n[Yx(t)]={state:t.state,...t.toolCount!==void 0?{toolCount:t.toolCount}:{},...t.error?{error:t.error}:{}},n}function Jx(s){return s.reduce((t,n)=>Qo(t,n),{})}function Xx(s,t){return{...s,[t]:{state:"connecting"}}}function Qx(s,t,n){return{...s,[t]:{state:"error",...n?{error:n}:{}}}}const Gt=(s,t)=>{const n={...s};return delete n[t],n},gs=bc()((s,t)=>({statuses:{},authorized:{},pending:{},bind:()=>(window.electronAPI.mcp.authState().then(n=>s({authorized:n})).catch(()=>{}),window.electronAPI.mcp.statusSnapshot().then(n=>s({statuses:{...t().statuses,...Jx(n)}})).catch(()=>{}),window.electronAPI.mcp.onStatus(n=>{if(n.type==="mcp-status-cleared"){s({statuses:{}});return}s({statuses:Qo(t().statuses,n)}),window.electronAPI.mcp.authState().then(a=>s({authorized:a})).catch(()=>{})})),authorize:async n=>{s({statuses:Xx(t().statuses,n),pending:{...t().pending,[n]:!0}});let a;try{a=await window.electronAPI.mcp.authorize(n)}catch(r){a={ok:!1,error:r instanceof Error?r.message:String(r)}}s({pending:Gt(t().pending,n),...a.ok?{authorized:{...t().authorized,[n]:!0}}:{statuses:Qx(t().statuses,n,a.error)}})},revoke:async n=>{await window.electronAPI.mcp.revoke(n),s({authorized:Gt(t().authorized,n),statuses:Gt(t().statuses,n)})}})),es=s=>typeof s=="string"?s.trim():"",Zx=s=>Array.isArray(s)?s.filter(t=>typeof t=="string"):[],Zo=s=>{if(!s||typeof s!="object")return{};const t={};for(const[n,a]of Object.entries(s))typeof a=="string"&&(t[n]=a);return t};function eh(s){const t=Zo(s);return delete t[""],Object.keys(t).length>0?t:void 0}function Za(s){const t={};for(const n of s.split(`
|
|
11
|
-
`)){const a=n.indexOf(":"),r=a>0?n.slice(0,a).trim():"";r&&(t[r]=n.slice(a+1).trim())}return Object.keys(t).length>0?t:void 0}const er=s=>Object.entries(s??{}).map(([t,n])=>`${t}: ${n}`).join(`
|
|
12
|
-
`);function sh(s,t){const n=es(s).toLowerCase();return n==="sse"?"sse":n==="http"||n==="streamable-http"?"http":n==="stdio"?"stdio":t?"http":"stdio"}function sr(s){if(!s||typeof s!="object")return[];const t=[];for(const[n,a]of Object.entries(s)){if(!a||typeof a!="object")continue;const r=a,o=es(r.url)||es(r.serverUrl),i=es(r.command);if(!i&&!o)continue;const u=i?void 0:eh(r.headers);t.push({name:n,transport:sh(r.type??r.transport,o),command:i||void 0,args:i?Zx(r.args):void 0,env:i?Zo(r.env):void 0,url:o||void 0,...u?{headers:u}:{}})}return t}const th=s=>{const t=s.trim();return(t.match(/^```(?:json)?\s*([\s\S]*?)\s*```$/i)?.[1]??t).trim()},nh=s=>s.startsWith('"')&&!s.startsWith("{")&&!s.startsWith("[")?`{${s}}`:s,ah=s=>{if(!s||typeof s!="object"||Array.isArray(s))return s;const t=s;if(t.mcpServers!=null)return t.mcpServers;if(t.mcp_servers!=null)return t.mcp_servers;if(t.servers!=null)return t.servers;const n=t.mcp;if(n&&typeof n=="object"&&!Array.isArray(n)){const a=n.servers;if(a!=null)return a}return s},rh=s=>{if(!s||typeof s!="object"||Array.isArray(s))return!1;const t=s;return!!(es(t.command)||es(t.url)||es(t.serverUrl))},oh=s=>{const t=es(s.command);return t&&t.split(/[\\/]/).pop()?.trim()||"mcp"},jn=s=>{if(Array.isArray(s))return s.flatMap(jn);if(rh(s)){const t=es(s.name)||es(s.id)||oh(s);return sr({[t]:s})}return sr(s)};function Wt(s){let t;try{t=JSON.parse(nh(th(s)))}catch{return{ok:!1,error:"invalid-json"}}const n=Array.isArray(t)?t.flatMap(jn):jn(ah(t));return n.length===0?{ok:!1,error:"empty"}:{ok:!0,servers:n}}const ih=1e4,lh=12e4,ch=600,dh=3600;function tr(s,t){let n;if(typeof s=="string"){const a=s.trim();if(!a||!/^\d+$/.test(a))return;n=Number(a)}else if(typeof s=="number")n=s;else return;if(!(!Number.isInteger(n)||n<=0))return t===void 0?n:Math.min(n,t)}const uh={theme:wc,disableFileHeader:!0,overflow:"scroll",preferredHighlighter:"shiki-js"};function mh(s){return new Ic(s)}function ei({fileName:s,value:t,epoch:n,onChange:a,className:r="h-60"}){const{t:o}=R(),[i,u]=l.useState(!1),d=yc(uh),x=l.useRef(a);x.current=a;const p=l.useMemo(()=>({onChange(c){x.current(c.contents)}}),[]);return l.useEffect(()=>{let c=!0;return Nc().then(()=>{c&&u(!0)}),()=>{c=!1}},[]),i?e.jsx("div",{className:H("w-full overflow-hidden rounded-lg border border-input",r),children:e.jsx(kc,{createEditor:mh,children:e.jsx(Cc,{style:{height:"100%",overflow:"auto"},children:e.jsx(Sc,{file:{name:s,contents:t},disableWorkerPool:!0,edit:!0,editorOptions:p,options:d},n)})})}):e.jsx("div",{className:H("flex w-full items-center justify-center rounded-lg border border-input text-muted-foreground text-xs",r),children:o("Loading...")})}const nr=s=>{const t=s.split(`
|
|
13
|
-
`).map(n=>n.trim()).filter(Boolean);return t.length>0?t:void 0},ar=s=>{const t={};for(const n of s.split(`
|
|
14
|
-
`)){const a=n.trim();if(!a)continue;const r=a.indexOf("=");r<=0||(t[a.slice(0,r).trim()]=a.slice(r+1))}return Object.keys(t).length>0?t:void 0},rr=s=>s?Object.entries(s).map(([t,n])=>`${t}=${n}`).join(`
|
|
15
|
-
`):"",or=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 xh({server:s,onClose:t}){const{t:n}=R(),a=g(D=>D.addMcpServers),r=g(D=>D.updateMcpServer),o=s==="new",[i,u]=l.useState("form"),[d,x]=l.useState(""),[p,c]=l.useState(""),[f,m]=l.useState(""),[h,j]=l.useState(""),[b,A]=l.useState("stdio"),[k,N]=l.useState(""),[S,M]=l.useState(""),[V,E]=l.useState(""),[L,P]=l.useState(""),[C,I]=l.useState(""),[W,J]=l.useState(""),[w,z]=l.useState(""),[G,B]=l.useState(""),[U,re]=l.useState(0),[F,ee]=l.useState(null),$=()=>({description:p.trim()||void 0,oauthClientName:b!=="stdio"&&f.trim()||void 0,oauthMetadataUrl:b!=="stdio"&&h.trim()||void 0,connectTimeoutSec:tr(W,ch),callTimeoutSec:tr(w,dh)}),oe=D=>{x(D.name),A(D.transport),N(D.command??""),M((D.args??[]).join(`
|
|
16
|
-
`)),E(rr(D.env&&Object.keys(D.env).length>0?D.env:void 0)),P(D.url??""),I(er(D.headers))},_=()=>{const D={type:b};if(b==="stdio"){D.command=k.trim();const q=nr(S);q&&(D.args=q);const Y=ar(V);Y&&(D.env=Y)}else{D.url=L.trim();const q=Za(C);q&&(D.headers=q)}return JSON.stringify(D,null,2)},le=(D,q)=>{const Y=(q??D.name).trim(),xe=D.env&&Object.keys(D.env).length>0?D.env:void 0,fe=D.args&&D.args.length>0?D.args:void 0;return D.transport==="stdio"?{name:Y,transport:D.transport,command:(D.command??"").trim(),args:fe,env:xe,url:void 0,headers:void 0,...$()}:{name:Y,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,...$()}};l.useEffect(()=>{if(!s)return;const D=s==="new"?null:s;u("form"),x(D?.name??""),c(D?.description??""),m(D?.oauthClientName??""),j(D?.oauthMetadataUrl??""),A(D?.transport??"stdio"),N(D?.command??""),M((D?.args??[]).join(`
|
|
17
|
-
`)),E(rr(D?.env)),P(D?.url??""),I(er(D?.headers)),J(D?.connectTimeoutSec?.toString()??""),z(D?.callTimeoutSec?.toString()??""),B(""),re(q=>q+1),ee(null)},[s]);const de=D=>n(D==="invalid-json"?"Invalid JSON":"No MCP servers found in JSON"),O=D=>{if(D===i)return;if(D==="json"){B(_()),re(xe=>xe+1),ee(null),u("json");return}const q=Wt(G);if(!q.ok){if(q.error==="invalid-json"&&G.trim()){ee(de(q.error));return}ee(null),u("form");return}if(q.servers.length!==1){ee(n("JSON must describe a single MCP server to switch to the form"));return}const Y=q.servers[0];oe({...Y,name:d.trim()||Y.name}),ee(null),u("form")},Oe=()=>{const D=Wt(G);if(!D.ok){ee(de(D.error));return}if(D.servers.length===1){const[q]=D.servers;B(JSON.stringify(or(q),null,2)),re(Y=>Y+1),d.trim()||x(q.name)}else B(JSON.stringify({mcpServers:Object.fromEntries(D.servers.map(q=>[q.name,or(q)]))},null,2)),re(q=>q+1);ee(null)},he=!!d.trim()&&(b==="stdio"?!!k.trim():!!L.trim()),T=i==="json"?!!G.trim():he,X=()=>{if(!s||!T)return;if(i==="json"){const q=Wt(G);if(!q.ok){ee(de(q.error));return}if(!o&&q.servers.length!==1){ee(n("JSON must describe a single MCP server"));return}if(o){const Y=q.servers.length===1;if(a(q.servers.map(fe=>({...le(fe,Y&&d.trim()?d:fe.name),...Y?{}:{description:void 0},id:crypto.randomUUID(),source:"Manual",enabled:!0})))===0){ee(n("This MCP server already exists"));return}}else r(s.id,le(q.servers[0],d.trim()||q.servers[0].name));t();return}const D=b==="stdio"?{name:d.trim(),transport:b,command:k.trim(),args:nr(S),env:ar(V),url:void 0,headers:void 0,...$()}:{name:d.trim(),transport:b,url:L.trim(),headers:Za(C),command:void 0,args:void 0,env:void 0,...$()};if(o){if(a([{...D,id:crypto.randomUUID(),source:"Manual",enabled:!0}])===0){ee(n("This MCP server already exists"));return}}else r(s.id,D);t()};return e.jsx(ve,{open:s!==null,onOpenChange:D=>!D&&t(),children:e.jsxs(be,{children:[e.jsx(ye,{children:e.jsx(we,{children:n(o?"Add MCP Server":"Edit MCP Server")})}),e.jsxs(Ne,{className:"space-y-4",children:[e.jsx(Js,{value:i,onValueChange:D=>O(D),children:e.jsxs(Xs,{children:[e.jsx(Je,{value:"form",children:n("Form")}),e.jsx(Je,{value:"json",children:n("JSON")})]})}),e.jsxs(ue,{children:[e.jsx(me,{children:n("Name")}),e.jsx(Q,{value:d,onChange:D=>x(D.target.value)})]}),e.jsxs(ue,{children:[e.jsx(me,{children:n("Description (optional)")}),e.jsx(Q,{value:p,onChange:D=>c(D.target.value),placeholder:n("One line telling the model what this server is for")})]}),i==="json"?e.jsxs(ue,{children:[e.jsxs("div",{className:"flex w-full items-center justify-between",children:[e.jsx(me,{children:n("JSON configuration")}),e.jsx(y,{variant:"ghost",size:"sm",className:"h-7 px-2",onClick:Oe,children:n("Format")})]}),e.jsx(ei,{fileName:"mcp.json",value:G,epoch:U,onChange:B}),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(ue,{children:[e.jsx(me,{children:n("Transport")}),e.jsxs(se,{items:Sa.map(D=>({value:D,label:D})),value:b,onValueChange:D=>A(D),children:[e.jsx(te,{className:"w-full",children:e.jsx(ne,{})}),e.jsx(ae,{zIndex:ls.DROPDOWN_IN_MODAL,children:Sa.map(D=>e.jsx(Z,{value:D,children:D},D))})]})]}),b==="stdio"?e.jsxs(e.Fragment,{children:[e.jsxs(ue,{children:[e.jsx(me,{children:n("Command")}),e.jsx(Q,{value:k,onChange:D=>N(D.target.value),placeholder:"npx",className:"font-mono text-xs"})]}),e.jsxs(ue,{children:[e.jsx(me,{children:n("Arguments (one per line)")}),e.jsx(Ze,{value:S,onChange:D=>M(D.target.value),rows:3,className:"font-mono text-xs"})]}),e.jsxs(ue,{children:[e.jsx(me,{children:n("Environment variables (KEY=VALUE, one per line)")}),e.jsx(Ze,{value:V,onChange:D=>E(D.target.value),rows:3,className:"font-mono text-xs"})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs(ue,{children:[e.jsx(me,{children:n("URL")}),e.jsx(Q,{value:L,onChange:D=>P(D.target.value),placeholder:"https://...",className:"font-mono text-xs"})]}),e.jsxs(ue,{children:[e.jsx(me,{children:n("Headers (Name: value, one per line)")}),e.jsx(Ze,{value:C,onChange:D=>I(D.target.value),rows:2,placeholder:"Authorization: Bearer <token>",className:"font-mono text-xs"})]}),e.jsxs(ue,{children:[e.jsx(me,{children:n("OAuth client name (optional)")}),e.jsx(Q,{value:f,onChange:D=>m(D.target.value),placeholder:n("For servers that only accept known OAuth clients")})]}),e.jsxs(ue,{children:[e.jsx(me,{children:n("OAuth authorization server metadata URL (optional)")}),e.jsx(Q,{value:h,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(ue,{children:[e.jsx(me,{children:n("Connection timeout (seconds)")}),e.jsx(Q,{inputMode:"numeric",value:W,onChange:D=>J(D.target.value),placeholder:String(ih/1e3)})]}),e.jsxs(ue,{children:[e.jsx(me,{children:n("Tool call timeout (seconds)")}),e.jsx(Q,{inputMode:"numeric",value:w,onChange:D=>z(D.target.value),placeholder:String(lh/1e3)})]})]}),F&&e.jsx("p",{className:"t-shake-in text-destructive text-xs",children:F},F)]}),e.jsxs(Ie,{children:[e.jsx(y,{variant:"outline",size:"sm",onClick:t,children:n("Cancel")}),e.jsx(y,{size:"sm",disabled:!T,onClick:X,children:n("Save")})]})]})})}function hh({status:s}){const{t}=R();return s.state==="connecting"?e.jsx(ie,{variant:"outline",className:"shrink-0 animate-pulse text-[11px] text-muted-foreground",children:t("Connecting")}):s.state==="ready"?e.jsx(ie,{variant:"success",className:"shrink-0 text-[11px]",children:t("{{count}} tools",{count:s.toolCount??0})}):s.state==="unauthorized"?e.jsx(ie,{variant:"warning",className:"shrink-0 text-[11px]",children:t("Not authorized")}):s.state==="idle"?e.jsx(ie,{variant:"outline",className:"shrink-0 text-[11px] text-muted-foreground",children:t("Authorized, pending connection")}):e.jsx(ie,{variant:"error",className:"shrink-0 text-[11px]",title:s.error,children:t("Connection failed")})}function ph(){const{t:s}=R(),t=g(I=>I.mcpServers),n=g(I=>I.updateMcpServer),a=g(I=>I.setMcpServersEnabled),r=g(I=>I.removeMcpServer),o=gs(I=>I.statuses),i=gs(I=>I.authorized),u=gs(I=>I.pending),d=gs(I=>I.authorize),x=gs(I=>I.revoke);l.useEffect(()=>gs.getState().bind(),[]);const[p,c]=l.useState(!1),[f,m]=l.useState(null),h=async I=>{await d(I),m(gs.getState().authorized[I]===!0?I:null)},[j,b]=l.useState(null),[A,k]=l.useState(""),N=t.filter(I=>go(A,[I.name,I.source,I.transport,I.url,I.command,...I.args??[]])),S=N.map(I=>I.id),M=jo(S),V=t.filter(I=>I.enabled).length,E=t.filter(I=>I.enabled).map(I=>I.id),L=Pt(E,I=>window.electronAPI.assets.mcpOccupancy(I)),P=t.filter(I=>I.enabled&&I.loadMode!=="deferred").map(I=>I.id),C=At(P,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(ts,{}),t.length>0&&e.jsxs("span",{className:"ml-2 font-normal text-muted-foreground text-xs",children:[s("{{enabled}}/{{total}} enabled",{enabled:V,total:t.length}),e.jsx(Mt,{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(It,{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(Pe,{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(vo,{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(bo,{query:A,onQueryChange:k,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:N.length===0,actionDisabled:M.selectedIds.length===0}),N.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:N.map(I=>{const W=o[I.id]??o[I.name],J=u[I.id]===!0,w=I.transport!=="stdio"&&i[I.id]!==!0,z=I.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.${I.id}`,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(Le,{checked:M.isSelected(I.id),onCheckedChange:G=>M.toggleOne(I.id,G)}),e.jsx("span",{className:H("shrink-0 font-medium text-sm",!I.enabled&&"text-muted-foreground line-through"),children:I.name}),e.jsx(ie,{variant:"outline",className:"shrink-0 text-[11px]",children:I.transport}),e.jsx(ie,{variant:"secondary",className:"shrink-0 text-[11px]",children:I.source}),W&&e.jsx(hh,{status:W}),e.jsx("span",{className:"min-w-0 truncate font-mono text-muted-foreground text-xs",children:I.url??[I.command,...I.args??[]].join(" ")})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[(w||W?.state==="unauthorized")&&e.jsxs(y,{variant:"outline",size:"sm",className:"h-7",disabled:J,onClick:()=>{h(I.id)},children:[J?e.jsx(Ae,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):e.jsx(Ac,{className:"mr-1.5 h-3.5 w-3.5"}),s(J?"Authorizing":"Authorize")]}),i[I.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(I.id)},children:e.jsx(Ec,{className:"h-3.5 w-3.5"})}),e.jsx(Et,{row:L.rows[I.id],pending:I.enabled&&L.pending&&!L.rows[I.id]}),e.jsx(Js,{value:z?"deferred":"direct",onValueChange:G=>n(I.id,{loadMode:G==="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(Xs,{"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:I.enabled,onCheckedChange:G=>n(I.id,{enabled:G})}),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(I),children:e.jsx(xs,{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(I.id),children:e.jsx(Re,{className:"h-3.5 w-3.5"})})]})]}),f===I.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.")})]},I.id)})})]}),e.jsx($n,{kind:"mcp",open:p,onOpenChange:c}),e.jsx(xh,{server:j,onClose:()=>b(null)})]})}const ir={PERSON:340,ORGANIZATION:20,TEAM:20,PRODUCT:210,TOOL:210,SYSTEM:250,SERVICE:250,PLATFORM:250,CONCEPT:160,METHOD:160,TECHNIQUE:160,EVENT:40,PROJECT:280,DOCUMENT:90,TERM:190};function si(s){if(ir[s]!==void 0)return ir[s];let t=0;for(let n=0;n<s.length;n++)t=t*17+s.charCodeAt(n)>>>0;return t%360}const Ht=22,fh=64;function gh(s,t){if(t<=1)return Ht;const n=Math.sqrt(Math.max(1,s))/Math.sqrt(t);return Math.round(Ht+(fh-Ht)*Math.min(1,n))}function jh(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:gh(o.memoryCount,a),color:ti(si(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 vh(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:ti(si(a),t)})).sort((a,r)=>r.count-a.count||a.entityType.localeCompare(r.entityType))}function bh(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 ti(s,t){return yh(s,t?.62:.68,t?.58:.52)}function yh(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,u,d]=s<60?[a,r,0]:s<120?[r,a,0]:s<180?[0,a,r]:s<240?[0,r,a]:s<300?[r,0,a]:[a,0,r],x=p=>Math.round((p+o)*255).toString(16).padStart(2,"0");return`#${x(i)}${x(u)}${x(d)}`}let lr=!1;function wh(){lr||(Bo.use(vu),lr=!0)}const cr={name:"fcose",animate:!1,randomize:!1,nodeRepulsion:8e3,idealEdgeLength:90,nodeSeparation:90,padding:24,fit:!0};function Nh({graph:s,selectedId:t,onSelect:n,memories:a,loading:r,onInterpret:o,interpreting:i}){const{t:u}=R(),d=l.useRef(null),x=l.useRef(null),p=l.useRef(n);p.current=n;const[c,f]=l.useState(null),m=l.useMemo(()=>typeof document<"u"&&document.documentElement.classList.contains("dark"),[]);l.useEffect(()=>{const b=d.current;if(!b||s.nodes.length===0)return;wh();const A=Bo({container:b,elements:jh(s.nodes,s.edges,m),style:bh(m),minZoom:.2,maxZoom:2.5,wheelSensitivity:.2});return A.layout(cr).run(),A.on("tap","node",k=>p.current(k.target.id())),A.on("tap",k=>{k.target===A&&p.current(null)}),x.current=A,()=>{A.destroy(),x.current=null}},[s.nodes,s.edges,m]),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 k=A.closedNeighborhood();b.elements().difference(k).addClass("dimmed"),A.select()})},[t]);const h=l.useMemo(()=>vh(s.nodes,m),[s.nodes,m]),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:u(r?"Loading…":"No entities yet. Turn on entity extraction and store a few memories first.")}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"relative overflow-hidden rounded-lg border bg-muted/20",children:[e.jsx("div",{ref:d,className:"h-[440px] w-full"}),e.jsxs("div",{className:"absolute right-2 bottom-2 flex gap-1",children:[e.jsx(y,{size:"sm",variant:"outline",onClick:()=>x.current?.fit(void 0,24),title:u("Fit to view"),children:u("Fit")}),e.jsx(y,{size:"sm",variant:"outline",onClick:()=>x.current?.layout(cr).run(),title:u("Re-run layout"),children:u("Relayout")})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:u("Colour = entity type · size = how many memories mention it",{})}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:h.map(b=>e.jsxs("button",{type:"button",onClick:()=>f(c===b.entityType?null:b.entityType),className:H("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:u("{{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(ie,{variant:"secondary",children:j.entityType})]}),e.jsx("p",{className:"text-muted-foreground text-xs",children:u("{{count}} memories · {{space}}",{count:String(j.memoryCount),space:j.spaceLabel})})]}),e.jsx(y,{size:"sm",variant:"outline",disabled:i,onClick:()=>o(j.id),children:u(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:u("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:u("Crystal"),children:"★"}),e.jsx("span",{className:"truncate",children:b.title}),e.jsx(ie,{variant:"secondary",children:b.unitType})]}),e.jsx("p",{className:"line-clamp-2 text-muted-foreground text-xs",children:b.contentSummary})]},b.id))]})]})]})}function kh({tree:s,loading:t,selected:n,onToggle:a,onInterpretGroup:r,interpreting:o}){const{t:i}=R(),[u,d]=l.useState(new Set);return s.length===0?e.jsx("p",{className:"rounded-lg border px-3 py-6 text-muted-foreground text-sm",children:i(t?"Loading…":"No memories yet.")}):e.jsx("ul",{className:"divide-y rounded-lg border",children:s.map(x=>{const p=u.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(u);f.delete(x.id)||f.add(x.id),d(f)},children:e.jsxs("p",{className:"flex items-center gap-2 text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:p?"▾":"▸"}),e.jsx("span",{className:"truncate",children:x.label}),e.jsx(ie,{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")})]}),p&&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 Ch=120,Sh=30,Ih={nodes:[],edges:[],totalEntities:0};function Ah({revision:s=0}={}){const{t}=R(),[n,a]=l.useState("graph"),[r,o]=l.useState("unitType"),[i,u]=l.useState(Ih),[d,x]=l.useState([]),[p,c]=l.useState(!0),[f,m]=l.useState(null),[h,j]=l.useState([]),[b,A]=l.useState(new Set),[k,N]=l.useState(null),[S,M]=l.useState(!1),[V,E]=l.useState(null),[L,P]=l.useState(!1),C=l.useCallback(()=>{c(!0);const U=()=>c(!1);n==="graph"?window.electronAPI.memory.graph({limit:Ch,minMemories:1}).then(u).finally(U):window.electronAPI.memory.tree({groupBy:r,limitPerGroup:Sh}).then(x).finally(U)},[n,r]);l.useEffect(C,[C]);const I=l.useRef(C);I.current=C,l.useEffect(()=>window.electronAPI.memory.onChanged(()=>I.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 J=async U=>{M(!0),N(null);try{N(await window.electronAPI.memory.insight(U))}finally{M(!1)}},w=async()=>{P(!0);try{const U=await window.electronAPI.memory.crystallize({memoryIds:[...b]});E(U),U.ok&&A(new Set)}finally{P(!1)}},z=[{value:"graph",label:t("Graph")},{value:"tree",label:t("Tree")}],G=[{value:"unitType",label:t("By type")},{value:"entity",label:t("By entity")},{value:"time",label:t("By month")}],B=b.size>=Ia;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(se,{value:n,items:z,onValueChange:U=>a(U==="tree"?"tree":"graph"),children:[e.jsx(te,{size:"sm",className:"w-32",children:e.jsx(ne,{})}),e.jsx(ae,{children:z.map(U=>e.jsx(Z,{value:U.value,children:U.label},U.value))})]}),n==="tree"&&e.jsxs(se,{value:r,items:G,onValueChange:U=>o(U),children:[e.jsx(te,{size:"sm",className:"w-36",children:e.jsx(ne,{})}),e.jsx(ae,{children:G.map(U=>e.jsx(Z,{value:U.value,children:U.label},U.value))})]}),e.jsx("span",{className:"flex-1"}),n==="tree"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:H("text-xs",B?"text-foreground":"text-muted-foreground"),children:t("{{count}} selected",{count:String(b.size)})}),e.jsx(y,{size:"sm",variant:"outline",disabled:!B||L,onClick:()=>{w()},children:L?t("Synthesizing…"):t("Crystallize ({{min}}+)",{min:String(Ia)})})]})]}),n==="graph"?e.jsx(Nh,{graph:i,loading:p,selectedId:f,onSelect:m,memories:h,interpreting:S,onInterpret:U=>{J({entityId:U})}}):e.jsx(kh,{tree:d,loading:p,selected:b,interpreting:S,onToggle:U=>{const re=new Set(b);re.delete(U)||re.add(U),A(re)},onInterpretGroup:U=>{const re=(U.children??[]).map(F=>F.memoryId).filter(F=>!!F);J({memoryIds:re})}}),e.jsx(ve,{open:k!==null,onOpenChange:U=>!U&&N(null),children:e.jsxs(be,{children:[e.jsxs(ye,{children:[e.jsx(we,{children:t("Interpretation")}),k?.ok&&e.jsx(Ye,{children:t("Based on {{count}} memories",{count:String(k.sourceCount??0)})})]}),e.jsx(Ne,{children:k?.ok?e.jsx("p",{className:"whitespace-pre-wrap text-sm",children:k.text}):e.jsx("p",{className:"text-destructive text-sm",children:k?.error})}),e.jsx(Ie,{children:e.jsx(Gs,{render:e.jsx(y,{variant:"outline",size:"sm"}),children:t("Close")})})]})}),e.jsx(ve,{open:V!==null,onOpenChange:U=>!U&&E(null),children:e.jsxs(be,{children:[e.jsxs(ye,{children:[e.jsx(we,{children:V?.ok?t("Crystal created"):t("Nothing was written")}),V?.ok&&e.jsx(Ye,{children:V.title})]}),e.jsx(Ne,{className:"space-y-3",children:V?.ok?e.jsx("p",{className:"whitespace-pre-wrap text-sm",children:V.content}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-destructive text-sm",children:V?.error}),V?.candidates&&V.candidates.length>0&&e.jsx("ul",{className:"divide-y rounded-lg border",children:V.candidates.map(U=>e.jsxs("li",{className:"flex items-center justify-between gap-2 px-3 py-2",children:[e.jsx("span",{className:"truncate text-sm",children:U.title}),e.jsxs(ie,{variant:"secondary",children:[(U.similarity*100).toFixed(0),"%"]})]},U.id))})]})}),e.jsx(Ie,{children:e.jsx(Gs,{render:e.jsx(y,{variant:"outline",size:"sm"}),children:t("Close")})})]})})]})}function vn(s){return s==="fast"||s==="deep"}const Es=25,Be="__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 dr=["global","project","secretary","bot","chat"],Eh={global:"Global",project:"Projects",secretary:"Secretary",bot:"Members",chat:"Group chats"};function Mh(s,t,n){return t?{spaceId:t}:s?{spaceIds:n.filter(a=>a.kind===s).map(a=>a.id)}:{}}function Ph(s){return s.startsWith("bot:")?"bot":s.startsWith("chat:")?"chat":s.startsWith("proj:")?"project":"global"}function Th(s,t){return s===!1&&!t}function Rh(s,t,n,a){return vn(s)&&!t.trim()?"needs-query":Th(n,a)?"library-empty":"no-match"}function Oh({items:s,onOpen:t,onEdit:n,onDelete:a,t:r,selected:o,onToggle:i,emptyLabel:u}){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:u}),s.map(d=>e.jsxs("li",{className:H(Dc,"flex items-center gap-2 px-3 py-2"),"data-memory-id":d.id,children:[i&&e.jsx(Le,{checked:o?.has(d.id)??!1,onCheckedChange:()=>i(d.id),"aria-label":r("Select memory")}),e.jsxs("button",{type:"button",onClick:()=>t(d.id),className:"min-w-0 flex-1 space-y-0.5 text-left",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[d.isCrystal&&e.jsx("span",{title:r("Crystal"),children:"★"}),e.jsx("span",{className:"truncate text-sm",children:d.title}),e.jsx(ie,{variant:"secondary",children:d.unitType}),e.jsx(Lh,{importance:d.importance,t:r}),d.lifecycleState==="archived"&&e.jsx(ie,{variant:"outline",children:r("Archived")}),d.archiveCandidateAt&&e.jsx(ie,{variant:"warning",title:r("Marked by the forgetting pass: cold and low importance"),children:r("Archive candidate")})]}),e.jsx("span",{className:"line-clamp-2 text-muted-foreground text-xs",children:d.contentSummary}),e.jsxs("span",{className:"block text-muted-foreground text-xs",children:[r("Recorded {{date}}",{date:Os(d.createdAt)})," · ",d.spaceLabel," ","· ",r("Retrieved {{count}} times",{count:String(d.appearances)})]})]}),n&&a&&e.jsx(Oc,{id:d.id,onEdit:n,onDelete:a})]},d.id))]})}const Dh={critical:{variant:"warning",label:"critical"},important:{variant:"info",label:"important"},useful:{variant:"outline",label:"useful"},low:{variant:"outline",label:"low"}};function Lh({importance:s,t}){const n=_c(s),a=Dh[n];return e.jsx(ie,{variant:a.variant,className:n==="low"?"text-muted-foreground":void 0,title:t("Importance {{value}}",{value:s.toFixed(2)}),children:t(a.label)})}const zh=6,_h=50;function Fh(s){const t=[...s].sort((a,r)=>r.edge.createdAt.localeCompare(a.edge.createdAt)||a.edge.id.localeCompare(r.edge.id));if(t.length<=zh)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 ur({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 Bh({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 u=s.every(d=>t.has(d.edge.id));return e.jsxs("section",{className:"space-y-2","data-settings-row":"memory.review",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("h3",{className:"text-sm font-medium",children:i("Needs review")}),e.jsxs("label",{className:"flex items-center gap-2 text-muted-foreground text-xs",children:[e.jsx(Le,{checked:u,onCheckedChange:()=>a(!u),"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>_h&&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")})]})]}),Fh(s).map(d=>e.jsxs("div",{className:"space-y-2",children:[d.label&&e.jsxs("h4",{className:"text-muted-foreground text-xs",children:[d.label," · ",i("{{count}} pending",{count:String(d.items.length)})]}),d.items.map(({edge:x,older:p,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(ie,{variant:"outline",children:x.relation}),e.jsxs("span",{className:"text-muted-foreground text-xs",children:[p.spaceLabel," · ",Os(x.createdAt)]})]}),e.jsx(ur,{label:i("Earlier memory"),memory:p,onOpen:o}),e.jsx(ur,{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))]},d.key))]})}function Uh({writes:s,onReview:t,t:n}){return s.length===0?null:e.jsxs("section",{className:"space-y-2","data-settings-row":"memory.pending-writes",children:[e.jsx("h3",{className:"text-sm font-medium",children:n("Memory writes awaiting approval")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n("Bot members need your approval before writing to project or global memory.")}),s.map(a=>e.jsxs("div",{className:"space-y-1 rounded-lg border px-3 py-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-xs text-muted-foreground",children:[a.originLabel&&e.jsx("span",{className:"text-foreground",children:a.originLabel}),e.jsxs("span",{children:["→ ",a.spaceLabel]}),a.redacted&&e.jsxs("span",{children:["· ",n("Secrets redacted")]})]}),a.title&&e.jsx("div",{className:"text-sm font-medium",children:a.title}),e.jsx("p",{className:"whitespace-pre-wrap text-xs",children:a.content}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(y,{size:"sm",variant:"outline",onClick:()=>t(a.id,"approve"),children:n("Approve")}),e.jsx(y,{size:"sm",variant:"ghost",onClick:()=>t(a.id,"reject"),children:n("Reject")})]})]},a.id))]})}function $h({t:s}){const t=Lc(),n=zc(a=>a.review);return e.jsx(Uh,{writes:t,t:s,onReview:(a,r)=>{n(a,r)}})}function Vh({revision:s=0}={}){const{t}=R(),[n,a]=l.useState(""),[r,o]=l.useState(Be),[i,u]=l.useState(Be),[d,x]=l.useState(Be),[p,c]=l.useState(!1),[f,m]=l.useState(!1),[h,j]=l.useState(0),[b,A]=l.useState("exact"),[k,N]=l.useState(!1),[S,M]=l.useState(!0),[V,E]=l.useState([]),[L,P]=l.useState(0),[C,I]=l.useState([]),W=l.useRef(C);W.current=C;const[J,w]=l.useState(null),[z,G]=l.useState(null),[B,U]=l.useState(null),[re,F]=l.useState(null),[ee,$]=l.useState(new Set),[oe,_]=l.useState(!1),[le,de]=l.useState([]),[O,Oe]=l.useState(new Set),he=l.useRef(!1),T=l.useRef(0),X=l.useRef(0);l.useEffect(()=>(he.current=!0,()=>{he.current=!1,T.current++,X.current++}),[]);const D=l.useCallback(()=>{if(!he.current)return;const K=++T.current,ge=()=>he.current&&K===T.current;if(vn(b)&&!n.trim()){E([]),P(0),N(!0),M(!0);return}const De=dr.find(Ee=>Ee===r)??null;window.electronAPI.memory.list({query:n.trim()||void 0,...Mh(De,i===Be?null:i,W.current),unitType:d===Be?void 0:d,includeArchived:p,archiveCandidate:f||void 0,limit:Es,offset:h,mode:b}).then(Ee=>{ge()&&(E(Ee.items),P(Ee.total),N(Ee.approximate===!0),M(Ee.vectorsUsed!==!1))}),window.electronAPI.memory.stats().then(Ee=>{he.current&&(I(Object.keys(Ee.bySpace).map(Xe=>({id:Xe,label:Ee.spaceLabels[Xe]??Xe,kind:Ee.spaceKinds?.[Xe]??Ph(Xe)}))),w(Ee.total>0))}),window.electronAPI.memory.evolvesPending().then(Ee=>{he.current&&de(Ee)})},[n,r,i,d,p,f,h,b]);l.useEffect(()=>(D(),()=>{T.current++}),[D]);const q=l.useRef(D);q.current=D,l.useEffect(()=>window.electronAPI.memory.onChanged(()=>q.current()),[]);const Y=l.useRef(s);l.useEffect(()=>{Y.current!==s&&(Y.current=s,D())},[s,D]);const xe=K=>{const ge=++X.current;window.electronAPI.memory.detail(K).then(De=>{he.current&&ge===X.current&&G(De)})},fe=()=>{X.current++,G(null)},ys=async(K,ge)=>{_(!0);try{for(const De of K)await ge(De)}finally{he.current&&(_(!1),$(new Set),q.current())}},hs=()=>{ys(ee,K=>window.electronAPI.memory.archive(K))},ws=(K,ge)=>{K.length!==0&&(_(!0),(async()=>{try{for(const De of K)await window.electronAPI.memory.evolvesReview(De,ge)}finally{he.current&&(_(!1),Oe(new Set),q.current())}})())},ze=K=>{he.current&&($(new Set),z&&K.includes(z.id)&&fe(),q.current())},Ds=K=>{he.current&&(B?.reopen&&xe(K),q.current())},pe=K=>{K.then(()=>{he.current&&(fe(),q.current())})},as=n.trim()!==""||r!==Be||i!==Be||d!==Be||p===!0,rs=[{value:Be,label:t("All space types")},...dr.filter(K=>C.some(ge=>ge.kind===K)).map(K=>({value:K,label:t(Eh[K])}))],Zs=[{value:Be,label:t("All spaces")},...C.filter(K=>r===Be||K.kind===r).map(K=>({value:K.id,label:K.label}))],Ns=[{value:Be,label:t("All types")},...Mc.map(K=>({value:K,label:K}))],et=[{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(yo,{className:"w-full sm:w-96","data-size":"sm",children:[e.jsx(wo,{value:n,placeholder:t("Search memories"),onChange:K=>{j(0),a(K.target.value)}}),e.jsx(No,{align:"inline-end",className:"pe-1",children:e.jsxs(se,{value:b,items:et,onValueChange:K=>{j(0),A(K==="deep"?"deep":K==="fast"?"fast":"exact")},children:[e.jsx(te,{size:"sm",className:"w-auto min-w-0 gap-1 border-0 bg-transparent px-2 shadow-none before:hidden",children:e.jsx(ne,{})}),e.jsx(ae,{children:et.map(K=>e.jsx(Z,{value:K.value,children:K.label},K.value))})]})})]}),e.jsxs(se,{value:r,items:rs,onValueChange:K=>{j(0),o(String(K)),u(Be)},children:[e.jsx(te,{size:"sm",className:"w-36","data-memory-filter":"space-kind",children:e.jsx(ne,{})}),e.jsx(ae,{children:rs.map(K=>e.jsx(Z,{value:K.value,children:K.label},K.value))})]}),e.jsxs(se,{value:i,items:Zs,onValueChange:K=>{j(0),u(String(K))},children:[e.jsx(te,{size:"sm",className:"w-36","data-memory-filter":"space",children:e.jsx(ne,{})}),e.jsx(ae,{children:Zs.map(K=>e.jsx(Z,{value:K.value,children:K.label},K.value))})]}),e.jsxs(se,{value:d,items:Ns,onValueChange:K=>{j(0),x(String(K))},children:[e.jsx(te,{size:"sm",className:"w-36",children:e.jsx(ne,{})}),e.jsx(ae,{children:Ns.map(K=>e.jsx(Z,{value:K.value,children:K.label},K.value))})]}),b==="exact"&&e.jsxs("label",{className:"flex items-center gap-2 text-muted-foreground text-sm",children:[e.jsx(ce,{checked:p,onCheckedChange:K=>{j(0),c(K===!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:K=>{j(0),m(K===!0)}}),t("Archive candidates only")]})]}),vn(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."),!S&&` ${t("Embedding model is not ready, so vectors are skipped.")}`]}),ee.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(ee.size)})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(y,{variant:"ghost",size:"sm",disabled:oe,onClick:()=>$(new Set),children:t("Clear selection")}),e.jsx(y,{variant:"outline",size:"sm",disabled:oe,onClick:()=>hs(),children:t("Archive selected")}),e.jsx(y,{variant:"destructive-outline",size:"sm",disabled:oe,onClick:()=>F([...ee]),children:t("Delete permanently")})]})]}),e.jsx(Oh,{items:V,onOpen:xe,onEdit:K=>U({id:K,reopen:!1}),onDelete:K=>F([K]),t,selected:ee,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.")}[Rh(b,n,J,as)],onToggle:K=>{const ge=new Set(ee);ge.delete(K)||ge.add(K),$(ge)}}),!k&&L>Es&&e.jsxs("div",{className:"flex items-center justify-between text-xs text-muted-foreground",children:[e.jsx(y,{variant:"outline",size:"sm",disabled:h===0,onClick:()=>j(Math.max(0,h-Es)),children:t("Previous")}),e.jsxs("span",{children:[h+1,"–",Math.min(h+Es,L)," / ",L]}),e.jsx(y,{variant:"outline",size:"sm",disabled:h+Es>=L,onClick:()=>j(h+Es),children:t("Next")})]}),e.jsx($h,{t}),e.jsx(Bh,{items:le,selected:O,onToggle:K=>{const ge=new Set(O);ge.delete(K)||ge.add(K),Oe(ge)},onToggleAll:K=>Oe(K?new Set(le.map(ge=>ge.edge.id)):new Set),onOpen:xe,onReview:ws,t}),e.jsx(ve,{open:z!==null,onOpenChange:K=>!K&&fe(),children:e.jsx(be,{finalFocus:Pc,children:z&&e.jsxs(e.Fragment,{children:[e.jsxs(ye,{children:[e.jsx(we,{children:z.title}),e.jsx(Ye,{children:[z.unitType,z.spaceLabel].join(" · ")})]}),e.jsxs(Ne,{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(Fs,{label:t("Importance"),value:z.importance.toFixed(2)}),e.jsx(Fs,{label:t("Recorded at"),value:Os(z.createdAt)}),z.updatedAt!==z.createdAt&&e.jsx(Fs,{label:t("Updated at"),value:Os(z.updatedAt)}),e.jsx(Fs,{label:t("Embedding"),value:z.embeddingModel??t("Not vectorized")}),z.eventStart&&e.jsx(Fs,{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(K=>e.jsx(ie,{variant:"secondary",children:K},K))})]}),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(K=>e.jsxs("li",{className:"flex items-center justify-between gap-2 px-3 py-2",children:[e.jsx("span",{className:"truncate text-sm",children:K.title}),e.jsxs("span",{className:"shrink-0 text-muted-foreground text-xs",children:[(K.contributionWeight*100).toFixed(0),"%"]})]},K.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(K=>e.jsxs("li",{className:"flex items-center gap-2 px-3 py-2",children:[e.jsx(ie,{variant:"outline",children:K.relation}),e.jsx("span",{className:"text-muted-foreground text-xs",children:K.reviewState})]},K.id))})]})]}),e.jsxs(Ie,{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:()=>{fe(),U({id:z.id,reopen:!0})},children:t("Edit")}),z.lifecycleState==="archived"?e.jsx(y,{variant:"outline",size:"sm",onClick:()=>pe(window.electronAPI.memory.restore(z.id)),children:t("Restore")}):e.jsx(y,{variant:"outline",size:"sm",onClick:()=>pe(window.electronAPI.memory.archive(z.id)),children:t("Archive")})]})]})})}),e.jsx(Tc,{memoryId:B?.id??null,onClose:()=>U(null),onSaved:Ds}),e.jsx(Rc,{ids:re,onClose:()=>F(null),onDeleted:ze})]})}function Fs({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 ni="openai-compatible",Kh=/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 ai(s){return Kh.test(s)}function Wn(s){return Array.isArray(s.models)?s.models.filter(t=>typeof t?.id=="string"&&ai(t.id)):[]}function Gh(s){return s.flatMap(t=>{if(!t.apiKey||typeof t.baseUrl!="string"||!t.baseUrl.trim())return[];const n=Wn(t);return n.length>0?[{...t,models:n}]:[]})}function Wh(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?Wn(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 Hh={"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 qh(s,t,n){return n(Hh[s],{name:t})}function Yh(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===ni?"no-model":ai(a)?null:Wn(n).length>0?"not-embedding-model":"no-embedding-models":"no-api-key":"provider-missing":"no-provider"}const Jh={"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.'},Xh="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 Qh(s,t,n){return n(Jh[s],{provider:t.provider??"",model:t.model??""})}const mr=s=>s.slice(0,8);function qt(s,t){return s==="pending"||s==="running"?"running":s==="cancelled"?"cancelled":t?"failed":"done"}const Zh={low_importance:"importance too low",candidates_found:"similar memory already exists",deduplicated:"identical to an existing memory",rejected:"rejected"};function ep(s){const t=[];for(const r of s.distill){const o=qt(r.status,r.error);t.push({key:`distill:${r.id}`,kind:"distill",target:r.sessionTitle||mr(r.sessionId),state:o,detail:o==="failed"?r.error??"":o==="cancelled"?"superseded":o==="running"?r.attempts>1?`retry ${r.attempts}`:"queued":`${r.done} stored`,notes:(r.notes??[]).map(i=>[i.title,Zh[i.kind]??i.kind].filter(Boolean).join(" — ")),updatedAt:r.updatedAt})}for(const r of s.kg){const o=qt(r.status,r.error);t.push({key:`kg:${r.id}`,kind:"kg",target:r.memoryTitle||mr(r.memoryId),state:o,detail:o==="failed"?r.error??"":o==="cancelled"?"memory changed":o==="running"?"extracting":`${r.total} entities · ${r.done} links`,notes:[],updatedAt:r.updatedAt})}const n=s.reembed;if(n){const r=qt(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 Ws=`remote:${ni}`,Nt="remote:";function xr(s){return s.id==="none"?"None (full-text only)":s.id.replace(/^(local|remote):/,"")}function Tt(s){return s.startsWith(Nt)&&s.length>Nt.length}function sp(s){return Tt(s)?Ws:s}function tp(s){return!Tt(s)||s===Ws?null:s.slice(Nt.length)}function np(s){return`${Nt}${s}`}function ap(s,t){return t===Ws?Tt(s)?s:Ws:t}const rp=4e3,op=800,hr=6,ip={distill:"job:distill",kg:"job:entities",reembed:"job:vectors"},pr={distill:[],kg:[],reembed:null,kgFailed:0};function lp(s){return s.some(t=>t.distilled)}function fr(s){return!s||s.total===0||s.embedded>=s.total?null:s.embeddingError??null}function gr(s){return s?.downloadable&&(s.state==="missing"||s.state==="downloading")?s.state:null}function cp(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 dp(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 up(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 je(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 Yt(s,t,n){return(s.includes(t)?[...s]:[...s,t].sort((r,o)=>r-o)).map(r=>({value:String(r),label:n(r)}))}function js({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 Jt({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(se,{value:n,items:a,onValueChange:u=>r(String(u)),disabled:i,children:[e.jsx(te,{className:"w-40 shrink-0",children:e.jsx(ne,{})}),e.jsx(ae,{children:a.map(u=>e.jsx(Z,{value:u.value,children:u.label},u.value))})]})]})}function mp({onLibraryChanged:s}={}){const{t}=R(),n=g(v=>v.disabledBuiltinTools),a=g(v=>v.memoryEmbeddingModel),r=g(v=>v.setMemoryEmbeddingModel),o=g(v=>v.memoryEmbeddingAutoDownload),i=g(v=>v.setMemoryEmbeddingAutoDownload),u=g(v=>v.memoryModelIdleMinutes),d=g(v=>v.setMemoryModelIdleMinutes),x=g(v=>v.memoryEmbeddingRemoteProviderId),p=g(v=>v.setMemoryEmbeddingRemoteProviderId),c=g(v=>v.providers),f=g(v=>v.memoryDistillEnabled),m=g(v=>v.setMemoryDistillEnabled),h=g(v=>v.memoryDistillWindowMinutes),j=g(v=>v.setMemoryDistillWindowMinutes),b=g(v=>v.memoryKgEnabled),A=g(v=>v.setMemoryKgEnabled),k=g(v=>v.memoryReconcileEnabled),N=g(v=>v.setMemoryReconcileEnabled),S=g(v=>v.memoryDecayEnabled),M=g(v=>v.setMemoryDecayEnabled),V=g(v=>v.memoryDecayArchiveCandidates),E=g(v=>v.setMemoryDecayArchiveCandidates),L=g(v=>v.memoryDecayAutoArchive),P=g(v=>v.setMemoryDecayAutoArchive),C=g(v=>v.memoryDecayStaleDays),I=g(v=>v.setMemoryDecayStaleDays),W=g(v=>v.memoryDecayMaxImportance),J=g(v=>v.setMemoryDecayMaxImportance),w=g(v=>v.memoryDecayIntervalDays),z=g(v=>v.setMemoryDecayIntervalDays),G=g(v=>v.memoryDistillModel),B=g(v=>v.setMemoryDistillModel),U=g(v=>v.memoryChatModel)||"remote",re=g(v=>v.setMemoryChatModel),F=g(v=>v.memoryLanguage),ee=g(v=>v.setMemoryLanguage),$=ns(),oe=G?$.find(v=>v.id===G.providerId):void 0,_=oe?.models.find(v=>v.id===G?.modelId),le=tp(a),de=l.useMemo(()=>Gh($),[$]),O=l.useMemo(()=>Wh($),[$]),Oe=x?de.find(v=>v.id===x):void 0,he=Oe?.models.find(v=>v.id===le),T=x?c.find(v=>v.id===x):void 0,X=Yh({providerId:x,provider:T,modelId:le}),D=X&&X!=="no-provider"&&X!=="no-model"?Qh(X,{provider:T?.name||x||"",model:le??""},t):null,q=!n.includes("memory"),[Y,xe]=l.useState(null),[fe,ys]=l.useState(pr),[hs,ws]=l.useState([]),[ze,Ds]=l.useState(null),[pe,as]=l.useState([]),[rs,Zs]=l.useState(null),[Ns,et]=l.useState([]),[K,ge]=l.useState(null),[De,Ee]=l.useState(null),[Xe,Rt]=l.useState(null),[_e,st]=l.useState(null),[Ls,qn]=l.useState(!1),[Ot,bi]=l.useState(!1),[$e,Yn]=l.useState(null),[ks,Dt]=l.useState(new Set),[tt,nt]=l.useState(null),[Jn,Xn]=l.useState(!1),[at,yi]=l.useState(void 0),Lt=Y?.forgetting??null,zs=Lt?.lastRun??null,wi=zs?t("Last run {{date}}: {{scored}} scored, {{candidates}} candidates, {{archived}} archived",{date:Os(zs.ranAt),scored:String(zs.scored),candidates:String(zs.candidates),archived:String(zs.archived)}):t("Never run yet"),Qn=l.useRef(!1);Qn.current=Ls;const ps=l.useRef(null),zt=l.useCallback(()=>{window.electronAPI.memory.distillableSessions().then(et)},[]);l.useEffect(()=>{q&&zt()},[q,zt]);const Cs=l.useCallback(()=>{window.electronAPI.memory.models().then(ws)},[]);l.useEffect(()=>(Cs(),window.electronAPI.memory.onModelProgress(v=>{Ds(v.done?null:v),v.done&&Cs()})),[Cs]);const Ss=l.useCallback(()=>{window.electronAPI.memory.chatModels().then(as)},[]);l.useEffect(()=>(Ss(),window.electronAPI.memory.onChatModelProgress(v=>{Zs(v.done?null:v),v.done&&Ss()})),[Ss]),l.useEffect(()=>{if(!q){xe(null),ys(pr);return}let v=!1;const Ce=()=>{window.electronAPI.memory.stats().then(os=>{v||xe(os)}),window.electronAPI.memory.jobs().then(os=>{v||(ys(os),Qn.current&&os.reembed?.status!=="running"&&qn(!1))})};ps.current=Ce,Ce();const Ve=window.electronAPI.memory.onChanged(Ce),_s=window.setInterval(Ce,Ls?op:rp);return()=>{v=!0,ps.current=null,Ve(),window.clearInterval(_s)}},[q,Ls]);const Zn=up(Ns),ea=Ns.filter(v=>!v.distilled),Ni=()=>{nt("run"),window.electronAPI.memory.runForgetting().then(()=>{nt(null),ps.current?.()})},ki=()=>{Xn(!0),window.electronAPI.memory.runReconcile().then(v=>{Xn(!1),yi(v),ps.current?.()})},sa=()=>{window.electronAPI.memory.archiveCandidates({limit:200,offset:0}).then(v=>{Yn(v),Dt(new Set)})},Ci=()=>{const v=[...ks];v.length!==0&&(nt("archive"),window.electronAPI.memory.confirmArchiveCandidates(v).then(()=>{nt(null),sa(),ps.current?.(),s?.()}))},ta=(v,Ce,Ve)=>{const _s=v.filter(os=>!os.distilled);if(!lp(v)){rt(v,Ce);return}st({token:Ce,label:Ve,scope:v,pending:_s})},rt=async(v,Ce,Ve=!1)=>{const _s=pe.find(As=>As.id===U)??null;if(gr(_s))return;ge(Ce);const os=Date.now();Rt({done:0,total:v.length,startedAt:os});try{for(let As=0;As<v.length;As++)await window.electronAPI.memory.distillSession(v[As].sessionId,Ve),Rt({done:As+1,total:v.length,startedAt:os})}finally{ge(null),Rt(null),zt(),s?.()}},ke=hs.find(v=>v.id===a)??null,Fe=pe.find(v=>v.id===U)??null,fs=gr(Fe),na=pe.map(v=>({value:v.id,label:v.id==="remote"?t("Remote (API model)"):v.label})),aa=[...hs.map(v=>({value:v.id,label:xr(v)})),{value:Ws,label:t("Remote (OpenAI-compatible)")}],ra=Fc.map(v=>({value:String(v),label:v===0?t("Never"):t("{{count}} min",{count:v})})),oa=Bc.map(v=>({value:String(v),label:v===0?t("Immediately"):t("{{count}} min",{count:v})})),ia=[{value:"en",label:t("English")},{value:"zh",label:t("Simplified Chinese")},{value:"auto",label:t("Follow conversation")}],ot=Tt(a)||ke?.runtime==="openai-compatible",Is=l.useMemo(()=>ep(fe),[fe]);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(se,{value:String(u),items:ra,onValueChange:v=>{v!==null&&d(Number(v))},disabled:!q,children:[e.jsx(te,{className:"w-56 shrink-0","aria-label":t("Unload automatically when idle"),children:e.jsx(ne,{})}),e.jsx(ae,{children:ra.map(v=>e.jsx(Z,{value:v.value,children:v.label},v.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:ke?xr(ke):le??(ot?t("Remote (OpenAI-compatible)"):a)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:ke?[ke.dim?`${ke.dim}d`:null,ke.downloadable?je(ke.approxBytes):null,ke.runtime].filter(Boolean).join(" · "):ot?"openai-compatible":t("Unknown model; the default is used instead.")})]}),e.jsxs(se,{value:sp(a),items:aa,onValueChange:v=>{v!==null&&r(ap(a,String(v)))},disabled:!q,children:[e.jsx(te,{className:"w-56",children:e.jsx(ne,{})}),e.jsx(ae,{children:aa.map(v=>e.jsx(Z,{value:v.value,children:v.label},v.value))})]})]}),ke?.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:ke.state==="ready"?t("Model downloaded"):ke.state==="downloading"?t("Downloading…"):t("Model not downloaded")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:ze&&ze.modelId===ke.id?`${ze.file} · ${je(ze.received)}${ze.total?` / ${je(ze.total)}`:""} (${ze.fileIndex+1}/${ze.fileCount})`:ke.state==="ready"?je(ke.downloadedBytes):t("Semantic search stays off until the model is on disk.")})]}),e.jsx("div",{className:"flex shrink-0 gap-2",children:ke.state==="downloading"?e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.memory.cancelModelDownload(ke.id).then(Cs)},children:t("Cancel")}):ke.state==="ready"?e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.memory.deleteModel(ke.id).then(Cs)},children:t("Remove")}):e.jsx(y,{size:"sm",disabled:!q,onClick:()=>{window.electronAPI.memory.downloadModel(ke.id).then(Cs)},children:t("Download")})})]}),ot&&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.")})]}),de.length>0?e.jsx("div",{className:"w-56 shrink-0",children:e.jsx(Ue,{providers:de,providerId:Oe?.id??x??"",modelId:he?.id??le??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:t("Select model"),side:"bottom",triggerClassName:ss,onSelect:(v,Ce)=>{p(v),r(np(Ce))},onReasoningChange:()=>{},onThinkingChange:()=>{}})}):e.jsxs("div",{className:"w-56 shrink-0 space-y-1",children:[e.jsx("p",{className:"text-xs text-destructive",children:t(Xh)}),O.map(v=>e.jsx("p",{className:"text-xs text-muted-foreground",children:qh(v.reason,v.name,t)},v.providerId))]})]}),ot&&D&&e.jsx("p",{className:"text-xs text-destructive","data-settings-row":"memory.remoteModelIssue",children:D}),e.jsx(js,{rowId:"memory.autoDownload",title:t("Download models automatically"),description:t("Off by default, so a model is only fetched when you press Download. While a model is missing, search degrades to full-text; existing memories are re-embedded once it arrives."),checked:o,onChange:i,disabled:!q})]}),e.jsxs("section",{className:"space-y-2","data-settings-row":"memory.distillModel",children:[e.jsx("h3",{className:"text-sm font-medium",children:t("Distillation")}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Completion backend")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Local GGUF runs on this machine. Remote uses the model below.")})]}),e.jsxs(se,{value:U,items:na,onValueChange:v=>re(String(v)),disabled:!q,children:[e.jsx(te,{className:"w-56",children:e.jsx(ne,{})}),e.jsx(ae,{children:na.map(v=>e.jsx(Z,{value:v.value,children:v.label},v.value))})]})]}),Fe?.downloadable&&e.jsxs("div",{className:H("flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5",fs==="missing"&&"border-destructive/50"),children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:Fe.state==="ready"?t("Model downloaded"):Fe.state==="downloading"?t("Downloading…"):t("Model not downloaded")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:rs&&rs.modelId===Fe.id?`${rs.file} · ${je(rs.received)}${rs.total?` / ${je(rs.total)}`:""}`:Fe.state==="ready"?je(Fe.downloadedBytes):je(Fe.approxBytes)})]}),e.jsx("div",{className:"flex shrink-0 gap-2",children:Fe.state==="downloading"?e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.memory.cancelChatModelDownload(Fe.id).then(Ss)},children:t("Cancel")}):Fe.state==="ready"?e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.memory.deleteChatModel(Fe.id).then(Ss)},children:t("Remove")}):e.jsx(y,{size:"sm",disabled:!q,onClick:()=>{window.electronAPI.memory.downloadChatModel(Fe.id).then(Ss)},children:t("Download")})})]}),fs==="missing"&&e.jsx("p",{className:"text-xs text-destructive",children:t("Local model selected but the weights are not on disk. Distillation and interpretation will wait until you click Download.")}),fs==="downloading"&&e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Download in progress. Distillation waits until the model is ready.")}),U==="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.")})]}),$.length>0&&e.jsx("div",{className:"w-56 shrink-0",children:e.jsx(Ue,{providers:$,providerId:oe?.id??"",modelId:_?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:t("Follows the title-summary model"),side:"bottom",triggerClassName:ss,onSelect:(v,Ce)=>B({providerId:v,modelId:Ce}),onReasoningChange:()=>{},onThinkingChange:()=>{}})})]}),G&&e.jsx(y,{variant:"ghost",size:"sm",onClick:()=>B(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(se,{value:F,items:ia,onValueChange:v=>ee(String(v)),disabled:!q,children:[e.jsx(te,{className:"w-56",children:e.jsx(ne,{})}),e.jsx(ae,{children:ia.map(v=>e.jsx(Z,{value:v.value,children:v.label},v.value))})]})]})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium",children:t("Background processing")}),e.jsx(js,{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:m,disabled:!q}),f&&fs&&e.jsx("p",{className:"text-xs text-destructive",children:t("Automatic distillation is on, but the local model is not ready. Sessions will queue until you download it.")}),f&&e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5","data-settings-row":"memory.distillWindow",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Merge sessions in the same project")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Wait this long after a session ends, then distill every session of the same project that ended meanwhile in one run. Immediately distills each session on its own.")})]}),e.jsxs(se,{value:String(h),items:oa,onValueChange:v=>{v!==null&&j(Number(v))},disabled:!q,children:[e.jsx(te,{className:"w-56 shrink-0","aria-label":t("Merge sessions in the same project"),children:e.jsx(ne,{})}),e.jsx(ae,{children:oa.map(v=>e.jsx(Z,{value:v.value,children:v.label},v.value))})]})]}),e.jsx(js,{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:b,onChange:A,disabled:!q}),e.jsx(js,{rowId:"memory.reconcile",title:t("Review conflicting memories"),description:t("After new memories are written, ask the model whether they contradict older ones. Conflicts are only flagged for your review; nothing is hidden or deleted. Up to 20 model calls per run."),checked:k,onChange:N,disabled:!q}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 rounded-lg border px-3 py-2.5",children:[e.jsx("p",{className:"min-w-0 text-xs text-muted-foreground",children:at===void 0?t("Review now runs even when the switch above is off."):at===null?t("No model is available for memory tasks."):t("Checked {{pairs}} pairs, flagged {{count}} conflicts.",{pairs:String(at.judged),count:String(at.challenges)})}),e.jsx(y,{size:"sm",variant:"outline",disabled:Jn||!q,onClick:ki,children:t(Jn?"Running…":"Review now")})]})]}),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(js,{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:S,onChange:M,disabled:!q}),e.jsx(js,{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:E,disabled:!q||!S}),e.jsx(js,{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:L,onChange:P,disabled:!q||!S||!V}),S&&e.jsxs(e.Fragment,{children:[e.jsx(Jt,{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(C),items:Yt(Uc,C,v=>t("{{count}} days",{count:String(v)})),onChange:v=>I(Number(v)),disabled:!q}),e.jsx(Jt,{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(W),items:Yt($c,W,v=>v.toFixed(2)),onChange:v=>J(Number(v)),disabled:!q}),e.jsx(Jt,{rowId:"memory.decayInterval",title:t("Run every"),description:t("Checked when the library opens; there is no separate background timer."),value:String(w),items:Yt(Vc,w,v=>t("{{count}} days",{count:String(v)})),onChange:v=>z(Number(v)),disabled:!q})]}),S&&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||L?t("Archive candidates: {{count}}",{count:String(Lt?.candidates??0)}):t("Archive candidates: marking is off")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:wi})]}),e.jsxs("div",{className:"flex shrink-0 gap-2",children:[e.jsx(y,{size:"sm",variant:"outline",disabled:tt!==null||!q,onClick:Ni,children:t(tt==="run"?"Running…":"Run now")}),e.jsx(y,{size:"sm",variant:"outline",disabled:!V||(Lt?.candidates??0)===0,onClick:sa,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")}),Y===null||Y.total===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:t("No memories stored yet.")}):e.jsxs(e.Fragment,{children:[fr(Y)&&e.jsx("p",{className:"text-xs text-destructive",children:t("Vectors unavailable: {{reason}}",{reason:fr(Y)??""})}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-3",children:[e.jsx(us,{label:t("Memories"),value:String(Y.total)}),e.jsx(us,{label:t("Crystals"),value:String(Y.crystals)}),e.jsx(us,{label:t("Entities"),value:String(Y.entities)}),e.jsx(us,{label:t("With vectors"),value:`${Y.embedded}/${Y.total}`,action:Y.embedded<Y.total?e.jsx("button",{type:"button",disabled:Ls,className:"text-xs text-muted-foreground underline-offset-2 hover:underline disabled:opacity-60",onClick:()=>{qn(!0),window.electronAPI.memory.reembed().then(()=>ps.current?.())},children:t(Ls?"Backfilling…":"Backfill")}):null}),e.jsx(us,{label:t("Database size"),value:je(Y.databaseBytes)}),e.jsx(us,{label:t("Spaces"),value:String(Object.keys(Y.bySpace).length)}),e.jsx(us,{label:t("Never retrieved"),value:`${Y.neverHit}/${Y.total}`,action:e.jsx("span",{className:"text-muted-foreground text-xs",children:t("{{percent}}% of library",{percent:String(Y.total>0?Math.round(Y.neverHit/Y.total*100):0)})})}),e.jsx(us,{label:t("Added in 7 days"),value:String(Y.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")}),ea.length>0&&e.jsx(y,{size:"sm",variant:"outline",disabled:!q||K!==null||fs!==null,onClick:()=>ta(Ns,"all",t("All sessions")),children:K==="all"?t("Distilling…"):t("Distill all ({{count}})",{count:String(ea.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.")}),Xe&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:[t("{{done}}/{{total}} done",{done:String(Xe.done),total:String(Xe.total)}),(()=>{const v=cp(Xe,Date.now());return v===null?"":` · ${t("about {{time}} left",{time:dp(v)})}`})()]}),Zn.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:Zn.map(v=>{const Ce=v.sessions.filter(Ve=>!Ve.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:v.name}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("{{total}} sessions · {{pending}} not distilled",{total:String(v.sessions.length),pending:String(Ce.length)})})]}),e.jsxs("div",{className:"flex shrink-0 gap-2",children:[e.jsx(y,{size:"sm",variant:"ghost",onClick:()=>Ee(v),children:t("View sessions")}),e.jsx(y,{size:"sm",variant:"outline",disabled:!q||K!==null||v.sessions.length===0||fs!==null,onClick:()=>ta(v.sessions,v.key,v.name),children:K===v.key?t("Distilling…"):t("Distill project")})]})]},v.key)})})]}),e.jsx(ve,{open:De!==null,onOpenChange:v=>!v&&Ee(null),children:e.jsx(be,{children:De&&e.jsxs(e.Fragment,{children:[e.jsxs(ye,{children:[e.jsx(we,{children:De.name}),e.jsx(Ye,{children:t("{{total}} sessions · {{pending}} not distilled",{total:String(De.sessions.length),pending:String(De.sessions.filter(v=>!v.distilled).length)})})]}),e.jsx(Ne,{children:e.jsx("ul",{className:"divide-y rounded-lg border",children:De.sessions.map(v=>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:v.title}),e.jsxs("p",{className:"text-muted-foreground text-xs",children:[v.updatedAt?v.updatedAt.slice(0,10):"",v.distilled?` · ${t("Already distilled")}`:""]})]}),e.jsx(y,{size:"sm",variant:"ghost",className:"shrink-0",disabled:!q||K!==null||fs!==null,onClick:()=>{rt([v],v.sessionId,v.distilled)},children:K===v.sessionId?t("Distilling…"):v.distilled?t("Distill again"):t("Distill")})]},v.sessionId))})}),e.jsx(Ie,{children:e.jsx(Gs,{render:e.jsx(y,{variant:"outline",size:"sm"}),children:t("Close")})})]})})}),e.jsx(ve,{open:_e!==null,onOpenChange:v=>!v&&st(null),children:e.jsx(be,{children:_e&&e.jsxs(e.Fragment,{children:[e.jsxs(ye,{children:[e.jsx(we,{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:_e.label,total:String(_e.scope.length),done:String(_e.scope.length-_e.pending.length)})})]}),e.jsxs(Ie,{children:[e.jsx(Gs,{render:e.jsx(y,{variant:"ghost",size:"sm"}),children:t("Cancel")}),e.jsx(y,{variant:_e.pending.length>0?"default":"outline",size:"sm",disabled:_e.pending.length===0,onClick:()=>{const v=_e;st(null),rt(v.pending,v.token)},children:t("Only the {{count}} remaining",{count:String(_e.pending.length)})}),e.jsx(y,{variant:_e.pending.length>0?"outline":"default",size:"sm",onClick:()=>{const v=_e;st(null),rt(v.scope,v.token,!0)},children:t("Re-distill all {{count}}",{count:String(_e.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:[fe.kgFailed>0&&e.jsx(y,{size:"sm",variant:"ghost",onClick:()=>{window.electronAPI.memory.retryFailedKgJobs().then(()=>ps.current?.())},children:t("Retry failed extractions ({{count}})",{count:String(fe.kgFailed)})}),Is.some(v=>v.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")}),Is.length>hr&&e.jsx(y,{size:"sm",variant:"ghost",onClick:()=>bi(!Ot),children:Ot?t("Show less"):t("Show all {{count}}",{count:String(Is.length)})})]})]}),Is.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:(Ot?Is:Is.slice(0,hr)).map(v=>e.jsxs("li",{className:"space-y-1 px-3 py-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ie,{variant:v.state==="failed"?"destructive":"secondary",children:t(ip[v.kind])}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-sm",children:v.target}),e.jsx("span",{className:H("shrink-0 text-xs",v.state==="failed"?"text-destructive":"text-muted-foreground"),children:v.state==="running"?`⋯ ${v.detail}`:v.detail})]}),v.notes.map(Ce=>e.jsxs("p",{className:"pl-1 text-muted-foreground text-xs",children:["· ",Ce]},Ce))]},v.key))})]}),e.jsx(ve,{open:$e!==null,onOpenChange:v=>!v&&Yn(null),children:e.jsxs(be,{children:[e.jsxs(ye,{children:[e.jsx(we,{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(Ne,{children:$e&&$e.items.length>0?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:t("{{selected}} of {{total}} selected",{selected:String(ks.size),total:String($e.items.length)})}),e.jsx(y,{size:"sm",variant:"ghost",onClick:()=>Dt(ks.size===$e.items.length?new Set:new Set($e.items.map(v=>v.id))),children:ks.size===$e.items.length?t("Clear selection"):t("Select all")})]}),e.jsx("ul",{className:"divide-y rounded-lg border",children:$e.items.map(v=>e.jsxs("li",{className:"flex items-start gap-2 px-3 py-2",children:[e.jsx(Le,{checked:ks.has(v.id),onCheckedChange:()=>Dt(Ce=>{const Ve=new Set(Ce);return Ve.has(v.id)?Ve.delete(v.id):Ve.add(v.id),Ve}),"aria-label":t("Select memory")}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-sm",children:v.title}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[v.spaceLabel," ·"," ",t("Importance {{value}}",{value:v.importance.toFixed(2)})," ·"," ",v.lastHitAt?t("Last retrieved {{date}}",{date:Os(v.lastHitAt)}):t("Never retrieved")]})]})]},v.id))}),$e.total>$e.items.length&&e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Showing the first {{shown}} of {{total}}.",{shown:String($e.items.length),total:String($e.total)})})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:t("No archive candidates right now.")})}),e.jsxs(Ie,{children:[e.jsx(Gs,{render:e.jsx(y,{variant:"outline",size:"sm"}),children:t("Close")}),e.jsx(y,{size:"sm",disabled:ks.size===0||tt!==null,onClick:Ci,children:t(tt==="archive"?"Archiving…":"Archive selected")})]})]})})]})}function us({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 xp(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"?ko(t)?{ok:!0,value:t}:{ok:!1,error:"不是合法的模型选择"}:t.length>4096||t.includes("\0")?{ok:!1,error:"值不合法"}:{ok:!0,value:t}}const hp={"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 ri(s){return hp[s]??s}const pp=["themes","agent","productivity","integrations","insights","writing","fun"],Hn={themes:"主题外观",agent:"Agent 能力",productivity:"效率工作流",integrations:"外部集成",insights:"观测统计",writing:"写作翻译",fun:"休闲娱乐"};function fp(s){return{installedKey:s,refresh:!0}}function gp(s,t){return s.installedKey===t?s:{installedKey:t,refresh:!1}}function $s(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 jp({pluginId:s,name:t,from:n,homepage:a,onClose:r}){const{t:o}=R();return e.jsx(ve,{open:s!==null,onOpenChange:i=>!i&&r(),children:e.jsxs(be,{children:[e.jsx(ye,{children:e.jsxs(we,{children:[o("Usage guide"),t?` · ${t}`:""]})}),e.jsx(Ne,{className:"max-h-[60vh] space-y-3 overflow-y-auto",children:s&&e.jsx(oi,{pluginId:s,from:n,homepage:a})})]})})}function oi({pluginId:s,from:t,homepage:n,showLink:a=!0}){const{t:r}=R(),[o,i]=l.useState(null),[u,d]=l.useState(null),[x,p]=l.useState($s(n)),[c,f]=l.useState(null);return l.useEffect(()=>{let m=!0;return pt(()=>import("./globals-C3zxoqqH.js").then(h=>h.o6),__vite__mapDeps([0,1]),import.meta.url).then(h=>{m&&f(()=>h.Markdown)}),()=>{m=!1}},[]),l.useEffect(()=>{let m=!1;return i(null),d(null),p($s(n)),(async()=>{const h=window.electronAPI.extensionPlugins,j=await h.readme({id:s,from:t});let b=j.ok?j.markdown:null,A=j.ok?null:j.error;if(!j.ok&&t==="installed"){const k=await h.readme({id:s,from:"market"});k.ok&&(b=k.markdown,A=null)}if(!$s(n)){const k=await h.marketList(!1),N=k.ok?k.plugins.find(S=>S.id===s):void 0;m||p($s(N?.homepage))}m||(i(b),d(b?null:A))})(),()=>{m=!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")}),u&&e.jsx("p",{className:"text-muted-foreground text-sm",children:u}),o===null&&!u&&e.jsx("p",{className:"text-muted-foreground text-sm",children:"…"}),o!==null&&c&&e.jsx(c,{text:o})]})}function ii(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 vp(s){const t=r=>s.filter(o=>ii(o,r)).length,n=["all","installed","updates"],a=[...pp,"other"];return[...n.map(r=>({id:r,count:t(r)})),...a.map(r=>({id:r,count:t(r)})).filter(r=>r.count>0)]}function bp(s,t){const n=t.query.trim().toLowerCase();return s.filter(a=>ii(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 jr={all:"全部",installed:"已安装",updates:"可更新",other:"其他"},yp=s=>s in jr?jr[s]:Hn[s];function wp({disabled:s,installedKey:t,onInstall:n,initialQuery:a=""}){const{t:r}=R(),o=window.electronAPI.extensionPlugins,[i,u]=l.useState(null),[d,x]=l.useState(!1),[p,c]=l.useState(a),[f,m]=l.useState("all"),[h,j]=l.useState(null),[b,A]=l.useState(()=>fp(t)),k=gp(b,t);k!==b&&A(k);const N=l.useCallback(async C=>{x(!0);try{u(await o.marketList(C))}catch(I){u({ok:!1,error:I instanceof Error?I.message:String(I),chinaMirror:!1})}finally{x(!1)}},[o]);l.useEffect(()=>{N(b.refresh)},[N,b]);const S=async C=>{await o.setMarketChinaMirror(C),await N(!0)},M=i?.ok===!0?i.plugins:[],V=vp(M),E=V.some(C=>C.id===f)?f:"all",L=bp(M,{query:p,section:E}),P=h?M.find(C=>C.id===h):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:V.map(C=>e.jsxs("button",{type:"button","aria-pressed":E===C.id,onClick:()=>{m(C.id),j(null)},className:H("flex shrink-0 items-center justify-between gap-2 rounded-md px-2 py-1.5 text-left text-sm hover:bg-accent sm:w-full",E===C.id&&"bg-accent font-medium"),children:[e.jsx("span",{className:"truncate whitespace-nowrap",children:yp(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(Q,{className:"min-w-40 flex-1",value:p,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:d,onCheckedChange:C=>{S(C)}}),r("China mirror")]}),e.jsx(y,{size:"sm",variant:"ghost",disabled:d,onClick:()=>{N(!0)},children:d?e.jsx(Us,{}):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:P?e.jsx(kp,{plugin:P,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(Np,{plugin:C,disabled:s,onOpen:()=>j(C.id),onInstall:n},C.id))})})]})]})}function li({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 ci({tier:s}){const{t}=R();return e.jsx(ie,{variant:s==="official"?"secondary":"outline",className:"text-[11px]",children:t(s==="official"?"Official":"Community")})}function Np({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(di,{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(ci,{tier:s.tier})]}),e.jsxs("p",{className:"text-muted-foreground text-xs",children:[s.latest,s.category?` · ${Hn[s.category]}`:""]})]}),e.jsx(li,{plugin:s,disabled:t,onInstall:a})]}),s.description&&e.jsx("p",{className:"line-clamp-2 text-muted-foreground text-xs",children:s.description})]})}function kp({plugin:s,disabled:t,onBack:n,onInstall:a}){const{t:r}=R(),o=$s(s.homepage);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs(y,{size:"xs",variant:"ghost",onClick:n,children:[e.jsx(Co,{className:"size-3.5"}),"返回"]}),e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(di,{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(ci,{tier:s.tier}),s.category&&e.jsx(ie,{variant:"outline",className:"text-[11px]",children:Hn[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(Kc,{className:"size-3"}),r("Homepage")]})]}),e.jsx(li,{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:ri(i)})]},i))})]}),e.jsxs("section",{className:"space-y-1",children:[e.jsx("h3",{className:"font-medium text-sm",children:r("Usage guide")}),e.jsx(oi,{pluginId:s.id,from:"market",homepage:s.homepage,showLink:!1})]})]})}function di({src:s,large:t}){const[n,a]=l.useState(!1);return e.jsx("div",{className:H("flex shrink-0 items-center justify-center rounded-md bg-muted",t?"size-12":"size-9"),children:s&&!n?e.jsx("img",{src:s,alt:"",className:t?"size-7 object-contain":"size-5 object-contain",onError:()=>a(!0)}):e.jsx(St,{className:"size-4 text-muted-foreground"})})}const vr={session:"跟随当前会话",title:"跟随标题模型",fixed:"指定模型"};function Cp({value:s,onChange:t}){const n=ns(),a=ko(s)??"session",r=typeof a=="string"?a:"fixed",o=typeof a=="string"?null:a,i=o?n.find(d=>d.id===o.providerId):void 0,u=i?.models.find(d=>d.id===o?.modelId);return e.jsxs("div",{className:"space-y-2",children:[e.jsxs(se,{items:vr,value:r,onValueChange:d=>{if(d==="session"||d==="title")t(d);else if(d==="fixed"&&!o){const x=n[0],p=x?.models[0];x&&p&&t(Aa({providerId:x.id,modelId:p.id}))}},children:[e.jsx(te,{children:e.jsx(ne,{})}),e.jsx(ae,{children:Object.entries(vr).map(([d,x])=>e.jsx(Z,{value:d,disabled:d==="fixed"&&n.length===0,children:x},d))})]}),o&&e.jsx(Ue,{providers:n,providerId:i?.id??"",modelId:u?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:"选择模型",side:"bottom",triggerClassName:ss,onSelect:(d,x)=>t(Aa({providerId:d,modelId:x})),onReasoningChange:()=>{},onThinkingChange:()=>{}}),o&&!u&&e.jsx("p",{className:"text-destructive text-xs",children:"选中的模型已不可用,运行时会失败,请重新选择。"})]})}function Sp(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 Ip({pluginId:s,plain:t}){const{t:n}=R(),[a,r]=l.useState([]),[o,i]=l.useState({}),[u,d]=l.useState(null),x=l.useCallback(async()=>{const m=await window.electronAPI.extensionPlugins.configGet(s);m.ok?r(m.fields):d({error:!0,text:m.error}),i({})},[s]);l.useEffect(()=>{x()},[x]);const p=async()=>{const m={};for(const[j,b]of Object.entries(o)){const A=a.find(N=>N.key===j);if(!A||A.secret&&b==="")continue;const k=xp(A,b);if(!k.ok){d({error:!0,text:`${A.title}:${k.error}`});return}m[j]=k.value}const h=await window.electronAPI.extensionPlugins.configSet(s,m);d(h.ok?{error:!1,text:n("Saved. New calls use it right away.")}:{error:!0,text:h.error??""}),h.ok&&await x()},c=m=>{const h=o[m.key];return typeof h=="string"?h:h===null||m.secret?"":m.value??(m.default!==void 0?String(m.default):"")},f=m=>{const h=o[m.key];return typeof h=="boolean"?h:(m.value??(typeof m.default=="boolean"?String(m.default):"false"))==="true"};return e.jsxs("div",{className:H("space-y-2",t?"":"rounded-md border border-border p-3"),children:[a.map(m=>e.jsxs("div",{className:"space-y-1",children:[e.jsxs("p",{className:"text-sm",children:[m.title,e.jsx("span",{className:"ml-2 font-mono text-muted-foreground text-xs",children:m.key})]}),m.description&&e.jsx("p",{className:"text-muted-foreground text-xs",children:m.description}),m.multiline&&m.type==="string"?e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Ze,{autoComplete:"off",rows:4,value:c(m),placeholder:m.secret&&m.set?n("Set (leave blank to keep)"):n("Not set"),className:"min-w-0 flex-1",onChange:h=>i(j=>({...j,[m.key]:h.target.value}))}),m.set&&e.jsx(y,{size:"sm",variant:"ghost",onClick:()=>i(h=>({...h,[m.key]:null})),children:n("Clear value")})]}):m.secret||m.type==="string"||m.type==="number"||m.type==="path"?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Q,{type:m.secret?"password":m.type==="number"?"number":"text",autoComplete:"off",inputMode:m.type==="number"?"decimal":void 0,min:m.type==="number"?m.min:void 0,max:m.type==="number"?m.max:void 0,value:c(m),placeholder:m.secret&&m.set?n("Set (leave blank to keep)"):n("Not set"),onChange:h=>i(j=>({...j,[m.key]:h.target.value}))}),m.type==="path"&&!m.secret&&!window.electronAPI.remote&&e.jsx(y,{size:"sm",variant:"outline",onClick:()=>{window.electronAPI.extensionPlugins.pickPath(m.pathKind==="directory"?"directory":"file").then(h=>{h.ok&&"path"in h&&i(j=>({...j,[m.key]:h.path}))})},children:m.pathKind==="directory"?"选择文件夹":"选择文件"}),m.set&&e.jsx(y,{size:"sm",variant:"ghost",onClick:()=>i(h=>({...h,[m.key]:null})),children:n("Clear value")})]}):m.type==="boolean"?e.jsx(ce,{checked:f(m),onCheckedChange:h=>i(j=>({...j,[m.key]:h}))}):m.type==="model"?e.jsx(Cp,{value:c(m),onChange:h=>i(j=>({...j,[m.key]:h}))}):e.jsxs(se,{items:Object.fromEntries((m.options??[]).map(h=>[h,h])),value:c(m),onValueChange:h=>{typeof h=="string"&&i(j=>({...j,[m.key]:h}))},children:[e.jsx(te,{children:e.jsx(ne,{placeholder:"请选择"})}),e.jsx(ae,{children:(m.options??[]).map(h=>e.jsx(Z,{value:h,children:h},h))})]})]},m.key)),u&&e.jsx("p",{className:H("text-xs",u.error?"text-destructive":"text-muted-foreground"),children:u.text}),e.jsx(y,{size:"sm",disabled:Object.keys(o).length===0,onClick:()=>{p()},children:n("Save")})]})}function Ap({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:H("space-y-2",t?"":"rounded-md border border-border p-3"),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-sm",children:n("Plugin logs")}),e.jsx(y,{size:"icon",variant:"ghost","aria-label":n("Refresh"),onClick:()=>{o()},children:e.jsx(cs,{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 br({message:s}){const[t,n]=l.useState(!1);return e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("p",{className:H("select-text break-all font-mono text-destructive text-xs",t?"max-h-48 overflow-auto whitespace-pre-wrap":"line-clamp-2"),children:s}),s.length>120&&e.jsx("button",{type:"button",className:"text-muted-foreground text-xs hover:text-foreground",onClick:()=>n(a=>!a),children:t?"收起":"展开全部"})]})}function ui({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:ri(n)})]},n))})}function Ep(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 yr(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 wr({permissions:s,env:t,interop:n,resident:a,running:r,styles:o,trustedUi:i,events:u,schedules:d}){return e.jsxs("div",{className:"space-y-1",children:[e.jsx(ui,{permissions:s,styles:o||i}),i&&e.jsx(Mp,{}),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(", ")})]}),u?.map(x=>e.jsxs("p",{className:"text-xs",children:["事件 ",x.event," · ",x.mode==="intercept"?"拦截":"观察",x.failClosed?" · 失败即拒绝":""]},`${x.event}:${x.mode}`)),d?.map(x=>e.jsxs("p",{className:"text-xs",children:["定时任务 ",Ep(x)]},x.id))]})}function Mp(){return e.jsx("p",{className:"text-amber-700 text-xs dark:text-amber-400",children:"界面代码:运行在主界面里,可读写页面内容、调用界面能力,不受上面权限清单约束;只安装信任的插件"})}function Pp({pluginId:s,plain:t}){const[n,a]=l.useState(null),[r,o]=l.useState(null),i=l.useCallback(async()=>{const u=await window.electronAPI.extensionPlugins.artifactsList(s);u.ok?(a(u.artifacts),o(null)):o(u.error)},[s]);return l.useEffect(()=>{i()},[i]),e.jsxs("div",{className:H("space-y-2",t?"":"rounded-md border border-border p-3"),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-sm",children:"产出文件"}),e.jsx(y,{size:"icon",variant:"ghost","aria-label":"刷新",onClick:()=>{i()},children:e.jsx(cs,{className:"size-4"})})]}),r&&e.jsx("p",{className:"text-destructive text-xs",children:r}),e.jsx(Jc,{artifacts:n??[],onDelete:u=>{window.electronAPI.extensionPlugins.artifactDelete(u).then(d=>{d.ok?i():o(d.error??"删除失败")})}})]})}const Xt=new Set;function Tp({requestedInstallUrl:s=null,onRequestedInstallUrlConsumed:t,focusPluginId:n=null,onFocusPluginConsumed:a,requestedMarketQuery:r=null,onRequestedMarketQueryConsumed:o}={}){const{t:i}=R(),u=g(T=>T.pluginAutoUpdate!==!1),d=g(T=>T.setPluginAutoUpdate),[x,p]=l.useState([]),c=On(T=>T.errors),[f,m]=l.useState(null),[h,j]=l.useState(null),[b,A]=l.useState([]),[k,N]=l.useState(!1),[S,M]=l.useState(null),[V,E]=l.useState(""),[L,P]=l.useState(!1),[C,I]=l.useState(!1),[W,J]=l.useState(null),[w,z]=l.useState(null),[G,B]=l.useState(!1),[U,re]=l.useState("");l.useEffect(()=>{r&&(re(r),B(!0),o?.())},[r,o]);const[F,ee]=l.useState(null),$=l.useCallback(async()=>{try{p(await window.electronAPI.extensionPlugins.list())}catch{p([])}},[]);l.useEffect(()=>($(),window.electronAPI.extensionPlugins.registryNotice().then(z).catch(()=>z(null)),window.electronAPI.extensionPlugins.onChanged(()=>{$()})),[$]),l.useEffect(()=>{if(!n||(A(X=>X.includes(n)?X:[...X,n]),!x.some(X=>X.id===n)))return;const T=n;window.requestAnimationFrame(()=>{document.querySelector(`[data-plugin-id="${CSS.escape(T)}"]`)?.scrollIntoView({block:"center"})}),a?.()},[n,x,a]);const oe=async T=>{M(null),f&&window.electronAPI.extensionPlugins.discard(f.token),m(null);const X=await window.electronAPI.extensionPlugins.pickAndStage(T);X.ok?"cancelled"in X||m(X.preview):M(X.error)},_=async T=>{const X=(T??V).trim();if(!X)return;M(null),P(!0),f&&window.electronAPI.extensionPlugins.discard(f.token),m(null);const D=await window.electronAPI.extensionPlugins.stageFromUrl(X).finally(()=>{P(!1)});D.ok?m(D.preview):M(D.error)},le=l.useRef(_);le.current=_,l.useEffect(()=>{if(!s)return;const T=s;let X=!1;const D=window.setTimeout(()=>{X||Xt.has(T)||(Xt.add(T),E(T),t?.(),le.current(T).finally(()=>{Xt.delete(T)}))},0);return()=>{X=!0,window.clearTimeout(D)}},[s,t]);const de=async(T,X=!1)=>{M(null),f&&window.electronAPI.extensionPlugins.discard(f.token),m(null),P(!0);const D=window.electronAPI.extensionPlugins,q=await(X?D.marketStage(T):D.restage(T)).finally(()=>{P(!1)});q.ok?m(q.preview):M(q.error)},O=async()=>{I(!0),J(null);try{const T=await window.electronAPI.extensionPlugins.checkUpdates();J(T.checked===0?i("No plugins installed from GitHub to check"):T.available>0?i("{{count}} update(s) available",{count:T.available}):i("All plugins are up to date"))}finally{I(!1)}},Oe=async()=>{if(!f)return;N(!0);const T=await window.electronAPI.extensionPlugins.commit(f.token);if(N(!1),!T.ok)M(T.error??i("Install failed"));else{E("");const X=f.existingVersion?{ok:!0}:await window.electronAPI.extensionPlugins.setEnabled(f.id,!0);Me({type:X.ok?"success":"warning",title:i("{{name}} installed",{name:f.name}),description:X.ok?void 0:X.error})}m(null)},he=()=>{f&&window.electronAPI.extensionPlugins.discard(f.token),m(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(ts,{})]}),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(Us,{}):e.jsx(cs,{className:"size-4"}),i("Check for updates")]}),e.jsxs(y,{size:"sm",onClick:()=>{re(""),B(!0)},children:[e.jsx(Gu,{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:u,onCheckedChange:T=>d(T)})]}),e.jsxs("div",{className:"space-y-2.5 rounded-lg border bg-muted/30 p-3",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(yo,{className:"flex-1",children:[e.jsx(No,{children:e.jsx(mo,{className:"size-4 text-muted-foreground"})}),e.jsx(wo,{value:V,placeholder:i("https://github.com/owner/repo"),onChange:T=>E(T.target.value),onKeyDown:T=>{T.key==="Enter"&&_()}})]}),e.jsx(y,{size:"sm",variant:"outline",disabled:k||L||V.trim()==="",onClick:()=>{_()},children:L?e.jsx(Us,{}):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:k||L,onClick:()=>{oe("dir")},children:[e.jsx(zn,{className:"size-3.5"}),i("Install from folder")]}),e.jsxs(y,{size:"xs",variant:"ghost",disabled:k||L,onClick:()=>{oe("zip")},children:[e.jsx(Gc,{className:"size-3.5"}),i("Install from zip")]})]})]}),S&&e.jsx("p",{className:"text-destructive text-sm",children:S}),e.jsx(ve,{open:G,onOpenChange:B,children:e.jsxs(be,{className:"max-w-5xl",children:[e.jsx(ye,{children:e.jsx(we,{children:i("Marketplace")})}),e.jsx(Ne,{children:e.jsx(wp,{initialQuery:U,disabled:k||L,installedKey:x.map(T=>`${T.id}@${T.version}`).join(","),onInstall:T=>{B(!1),de(T,!0)}},U)})]})}),W&&e.jsx("p",{className:"text-muted-foreground text-sm",children:W}),w&&e.jsx(Sp,{notice:w,remote:!!window.electronAPI.remote,onDismiss:()=>{window.electronAPI.extensionPlugins.dismissRegistryNotice().then(()=>z(null)).catch(T=>M(T instanceof Error?T.message:String(T)))}}),e.jsx(ve,{open:f!==null,onOpenChange:T=>!T&&!k&&he(),children:e.jsx(be,{children:f&&e.jsxs(e.Fragment,{children:[e.jsx(ye,{children:e.jsxs(we,{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(Ne,{className:"space-y-3",children:[e.jsx(wr,{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(T=>e.jsxs("p",{className:"font-mono text-xs",children:[T.command," ",T.args.join(" ")]},T.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(T=>e.jsx("p",{className:"text-muted-foreground text-xs",children:T},T))]}),e.jsxs(Ie,{children:[e.jsx(y,{size:"sm",variant:"ghost",disabled:k,onClick:he,children:i("Cancel")}),e.jsx(y,{size:"sm",disabled:k,onClick:()=>{Oe()},children:k?e.jsx(Us,{}):i("Install")})]})]})})}),x.length===0&&!f&&e.jsxs("div",{className:"rounded-lg border border-dashed px-3 py-10 text-center",children:[e.jsx(St,{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(T=>e.jsxs("div",{"data-plugin-id":T.id,className:H("overflow-hidden rounded-lg border bg-card transition-colors",T.state==="crashed"&&"border-destructive/50"),children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-x-3 gap-y-2 p-3",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 basis-56 items-start gap-3",children:[e.jsx("div",{className:H("flex size-9 shrink-0 items-center justify-center rounded-md bg-muted",T.state==="enabled"?"text-foreground":"text-muted-foreground"),children:e.jsx(Wc,{pluginId:T.id,icon:T.icon,className:"size-4"})}),e.jsxs("div",{className:"min-w-0 flex-1 space-y-0.5",children:[e.jsxs("p",{className:"flex flex-wrap items-center gap-1.5 text-sm",children:[e.jsx("span",{className:"truncate font-medium",children:T.name}),e.jsx(ie,{variant:"outline",className:"text-[11px]",children:T.version}),T.state==="crashed"&&e.jsx(ie,{variant:"destructive",className:"text-[11px]",children:i("Stopped after crashes")}),T.availableVersion&&e.jsx(ie,{className:"text-[11px]",children:i("Update")}),T.pendingVersion&&e.jsx(ie,{variant:"warning",className:"text-[11px]",children:"待授权"}),T.hasRenderer&&e.jsx(ie,{variant:"outline",className:"text-[11px]",children:"受信任界面"}),T.devWatch&&e.jsx(ie,{variant:"secondary",className:"text-[11px]",children:"开发模式"}),T.resident&&e.jsx(ie,{variant:T.running?"secondary":"outline",className:"text-[11px]",children:T.running?"常驻运行中":"常驻未运行"})]}),e.jsx("p",{className:"truncate font-mono text-muted-foreground text-xs",children:T.id}),T.availableVersion&&e.jsxs("p",{className:"mt-1 flex items-center gap-2 text-primary text-xs",children:[i("Version {{version}} is available",{version:T.availableVersion}),e.jsx(y,{size:"xs",disabled:k||L,onClick:()=>{de(T.id,T.source?.kind!=="url")},children:L?e.jsx(Us,{}):i("Update")})]}),T.updateCheckError&&e.jsx("p",{className:"text-muted-foreground text-xs",children:i("Update check failed: {{reason}}",{reason:T.updateCheckError})}),T.lastError&&e.jsx(br,{message:T.lastError.message}),c[T.id]?.map(X=>e.jsx(br,{message:`主题加载失败:${X}`},X)),T.pendingVersion&&e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2 rounded-md border border-amber-500/50 bg-amber-500/10 px-2 py-1.5 text-amber-700 text-xs dark:text-amber-400",children:[i("{{version}} asks for more and is waiting for approval",{version:T.pendingVersion}),e.jsx(y,{size:"xs",onClick:()=>{window.electronAPI.extensionPlugins.approvePending(T.id)},children:i("Allow")}),e.jsx(y,{size:"xs",variant:"ghost",onClick:()=>{window.electronAPI.extensionPlugins.rejectPending(T.id)},children:i("Keep current")})]})]})]}),e.jsxs("div",{className:"ml-auto flex shrink-0 items-center gap-0.5",children:[T.source&&e.jsx(y,{size:"icon",variant:"ghost",disabled:k||L,"aria-label":i("Reinstall from source"),title:T.source.kind==="url"?`${i("Reinstall from source")}: ${T.source.url}`:i("Reinstall from source"),onClick:()=>{de(T.id)},children:e.jsx(Hc,{className:"size-4"})}),e.jsx(y,{size:"icon",variant:"ghost","aria-label":"产出文件",title:"产出文件",onClick:()=>j({kind:"artifacts",pluginId:T.id,pluginName:T.name}),children:e.jsx(qc,{className:"size-4"})}),e.jsx(y,{size:"icon",variant:"ghost","aria-label":i("Usage guide"),title:i("Usage guide"),onClick:()=>ee({id:T.id,name:T.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:T.id,pluginName:T.name}),children:e.jsx(Un,{className:"size-4"})}),T.configurable&&e.jsx(y,{size:"icon",variant:"ghost","aria-label":i("Configure"),title:i("Configure"),onClick:()=>j({kind:"config",pluginId:T.id,pluginName:T.name}),children:e.jsx(Yc,{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(T.id)},children:e.jsx(Re,{className:"size-4"})}),e.jsx("div",{className:"mx-1.5 h-5 w-px bg-border"}),e.jsx(ce,{checked:T.state==="enabled",onCheckedChange:X=>{window.electronAPI.extensionPlugins.setEnabled(T.id,X)}})]})]}),e.jsxs("button",{type:"button","aria-expanded":b.includes(T.id),className:H("flex w-full items-center gap-1 border-t bg-muted/20 px-3 py-1.5 text-left text-xs","text-muted-foreground transition-colors hover:bg-muted/50 hover:text-foreground"),onClick:()=>A(X=>X.includes(T.id)?X.filter(D=>D!==T.id):[...X,T.id]),children:[b.includes(T.id)?e.jsx(bt,{className:"size-3"}):e.jsx(Ys,{className:"size-3"}),b.includes(T.id)?"收起详情":"详情",!b.includes(T.id)&&yr(T)&&e.jsx("span",{className:"ml-1 opacity-70",children:yr(T)})]}),b.includes(T.id)&&e.jsxs("div",{className:"space-y-3 border-t px-3 py-3",children:[T.interceptBreakers?.map(X=>e.jsxs("p",{className:"text-amber-600 text-xs dark:text-amber-400",children:[X.event," 检查连续失败,临时放行到"," ",new Date(X.until).toLocaleTimeString()]},X.event)),e.jsx(wr,{permissions:T.permissions,resident:T.resident,running:T.running,styles:T.themes.some(X=>X.css!==void 0),trustedUi:T.hasRenderer,events:T.events,schedules:T.schedules}),T.crossSessionInject!==void 0&&e.jsxs("div",{className:"flex items-center justify-between gap-3 text-xs",children:[e.jsxs("span",{children:[e.jsx("span",{className:"block",children:"允许向任意运行中的会话发送消息"}),e.jsx("span",{className:"block text-muted-foreground",children:"关闭时只能发到发起调用的会话;开启后定时任务、常驻进程也能向其他项目和窗口的会话发消息并触发执行"})]}),e.jsx(ce,{"aria-label":"允许向任意运行中的会话发送消息",checked:T.crossSessionInject,onCheckedChange:X=>{window.electronAPI.extensionPlugins.setCrossSessionInject(T.id,X)}})]}),T.devWatch!==void 0&&e.jsxs("div",{className:"flex items-center justify-between gap-3 text-xs",children:[e.jsxs("span",{children:[e.jsx("span",{className:"block",children:"开发模式:目录改动后自动重装"}),e.jsx("span",{className:"block text-muted-foreground",children:"授权没扩大时直接替换;扩大时停下,需要从来源重新安装并同意。重启应用后关闭"})]}),e.jsx(ce,{"aria-label":"开发模式:目录改动后自动重装",checked:T.devWatch,onCheckedChange:X=>{window.electronAPI.extensionPlugins.setDevWatch(T.id,X).then(D=>{!D.ok&&D.error&&Me({title:D.error})})}})]}),((T.pendingPermissions?.length??0)>0||T.pendingRenderer)&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:"待同意"}),e.jsx(ui,{permissions:T.pendingPermissions??[],styles:T.pendingRenderer}),T.pendingRenderer&&e.jsx("p",{className:"text-amber-700 text-xs dark:text-amber-400",children:"新增界面代码:运行在主界面里,不受权限清单约束"})]})]})]},T.id))}),e.jsx(ve,{open:h!==null,onOpenChange:T=>!T&&j(null),children:e.jsxs(be,{children:[e.jsx(ye,{children:e.jsxs(we,{children:[h?.kind==="config"?i("Configure"):h?.kind==="logs"?i("Plugin logs"):"产出文件",h?` · ${h.pluginName}`:""]})}),e.jsxs(Ne,{className:"space-y-4",children:[h?.kind==="config"&&e.jsx(Ip,{pluginId:h.pluginId,plain:!0}),h?.kind==="logs"&&e.jsx(Ap,{pluginId:h.pluginId,plain:!0}),h?.kind==="artifacts"&&e.jsx(Pp,{pluginId:h.pluginId,plain:!0})]})]})}),e.jsx(jp,{pluginId:F?.id??null,name:F?.name??"",from:F?.from??"installed",homepage:F?.homepage,onClose:()=>ee(null)})]})}const Hs={mask:"Mask",warn:"Warn only",block:"Block"},Rp={email:"Email",phone:"Phone number",idCard:"ID card number",bankCard:"Bank card number",ip:"IP address"},bn={mask:"text-sky-600 dark:text-sky-400",warn:"text-amber-600 dark:text-amber-400",block:"text-red-600 dark:text-red-400"},Op=[1,7,30],Dp={1:"Today",7:"7D",30:"30D"};function Lp(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 Qt({value:s,onChange:t}){const{t:n}=R(),a=Object.fromEntries(Object.keys(Hs).map(r=>[r,n(Hs[r])]));return e.jsxs(se,{items:a,value:s,onValueChange:r=>t(r),children:[e.jsx(te,{className:"w-32",children:e.jsx(ne,{})}),e.jsx(ae,{children:Object.entries(a).map(([r,o])=>e.jsx(Z,{value:r,children:o},r))})]})}function Zt({label:s,hint:t,value:n,onCommit:a,rowId:r}){const[o,i]=l.useState(n.join(`
|
|
18
|
-
`));return l.useEffect(()=>i(n.join(`
|
|
19
|
-
`)),[n]),e.jsxs("div",{className:"space-y-1.5","data-settings-row":r,children:[e.jsx("p",{className:"text-sm",children:s}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t}),e.jsx(Ze,{rows:3,value:o,onChange:u=>i(u.target.value),onBlur:()=>a(o.split(`
|
|
20
|
-
`))})]})}function Ts({title:s,children:t}){return e.jsxs("div",{className:"space-y-3 rounded-md border p-3",children:[e.jsx("p",{className:"text-sm font-medium",children:s}),t]})}function zp({settings:s}){const{t}=R(),[n,a]=l.useState(""),r=l.useMemo(()=>Qc(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(Ze,{rows:3,value:n,placeholder:t("Paste some text, e.g. an .env file"),onChange:o=>a(o.target.value)}),n&&e.jsxs(e.Fragment,{children:[e.jsx("pre",{className:"max-h-48 overflow-auto whitespace-pre-wrap rounded bg-muted p-2 text-xs",children:r.text}),e.jsxs("ul",{className:"space-y-0.5 text-xs",children:[r.report.hits.map(o=>e.jsxs("li",{className:"flex gap-2",children:[e.jsx("span",{className:H("font-medium",bn[o.action]),children:t(Hs[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 _p(){const{t:s}=R(),[t,n]=l.useState(7),[a,r]=l.useState(null),[o,i]=l.useState(!1),u=l.useRef(0),d=Zc(f=>f.conversations),x=l.useCallback(async f=>{const m=++u.current;i(!0);const h=await window.electronAPI.privacyMask.records(f).catch(()=>[]);m===u.current&&(i(!1),r(h))},[]);l.useEffect(()=>{x(t)},[t,x]);const p=l.useMemo(()=>{const f={mask:0,warn:0,block:0},m=new Map;for(const h of a??[]){const j=new Set;for(const b of h.report.hits){const A=`${b.action}:${b.token}`;j.has(A)||(j.add(A),f[b.action]+=1,m.set(b.kind,(m.get(b.kind)??0)+1))}}return{byAction:f,byKind:[...m].sort((h,j)=>j[1]-h[1])}},[a]),c=f=>{if(f.source==="aux")return s("Auxiliary request");const m=f.sessionId?d[f.sessionId]?.title:void 0,h=f.source==="compaction"?s("Compaction"):s("Session");return m?`${h} · ${m}`:h};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:Op.map(f=>e.jsx(y,{size:"sm",variant:f===t?"secondary":"ghost",onClick:()=>n(f),children:s(Dp[f])},f))}),e.jsx(y,{variant:"ghost",size:"icon-sm",onClick:()=>{x(t)},disabled:o,"aria-label":s("Refresh"),children:e.jsx(cs,{className:H("size-4",o&&"animate-spin")})})]}),e.jsx("div",{className:"flex flex-wrap gap-4 text-sm",children:Object.keys(Hs).map(f=>e.jsxs("span",{children:[e.jsx("span",{className:bn[f],children:s(Hs[f])})," ",e.jsx("span",{className:"font-medium tabular-nums",children:p.byAction[f]})]},f))}),p.byKind.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 text-xs text-muted-foreground",children:p.byKind.map(([f,m])=>e.jsxs("span",{className:"rounded bg-muted px-1.5 py-0.5",children:[f," ",m]},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 m=ed(f.report),h=`${f.at}:${f.sessionId??f.source}:${f.model}:${f.report.hits.map(j=>j.token).join(",")}`;return e.jsxs("tr",{className:"border-t align-top",children:[e.jsx("td",{className:"py-1 pr-2 whitespace-nowrap tabular-nums",children:new Date(f.at).toLocaleString()}),e.jsx("td",{className:"py-1 pr-2",children:c(f)}),e.jsx("td",{className:"py-1 pr-2 break-all",children:f.model}),e.jsxs("td",{className:H("py-1",m&&bn[m]),children:[Lp(f),f.report.blocked&&` · ${s("Request blocked")}`]})]},h)})})]}),a?.length===0&&e.jsx("p",{className:"py-4 text-center text-xs text-muted-foreground",children:s("No records yet")})]})]})}function Fp(){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(Se,{rowId:"privacy.enabled",title:s("Privacy masking"),description:s("Applies to chats, compaction, bot members and helper requests."),checked:t.enabled,onChange:r=>a({enabled:r})}),t.enabled&&e.jsxs(e.Fragment,{children:[e.jsxs(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(Qt,{value:t.secrets.action,onChange:r=>a({secrets:{...t.secrets,action:r}})})]}),e.jsx(Se,{rowId:"privacy.secrets",title:s("Detect secrets"),description:s("Recommended. Covers common vendor key formats."),checked:t.secrets.enabled,onChange:r=>a({secrets:{...t.secrets,enabled:r}})}),e.jsx(Se,{rowId:"privacy.shape",title:s("Send look-alike keys"),description:s("Replace keys with fake keys of the same format instead of placeholders, so the model treats them as real keys."),checked:t.secrets.shape,onChange:r=>a({secrets:{...t.secrets,shape:r}})})]}),e.jsxs(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(Qt,{value:t.personal.action,onChange:r=>a({personal:{...t.personal,action:r}})})]}),e.jsx(Se,{rowId:"privacy.personal",title:s("Detect personal data"),description:s("Matches are validated (checksums, real domains) to limit false hits."),checked:t.personal.enabled,onChange:r=>a({personal:{...t.personal,enabled:r}})}),t.personal.enabled&&e.jsx("div",{className:"flex flex-wrap gap-4",children:Xc.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(Rp[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(Qt,{value:t.custom.action,onChange:r=>a({custom:{...t.custom,action:r}})})]}),e.jsx(Zt,{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(Zt,{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(Zt,{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(zp,{settings:t})]}),e.jsx(_p,{})]})}function Bp(){const{t:s}=R(),t=g(m=>m.approvalReviewer),n=g(m=>m.setApprovalReviewer),a=g(m=>m.approvalAutoManage),r=g(m=>m.setApprovalAutoManage),o=sd(g(m=>m.approvalAllowThreshold)),i=g(m=>m.setApprovalAllowThreshold),u={"0.85":s("0.85 (looser)"),"0.9":s("0.9 (default)"),"0.95":s("0.95 (stricter)")},d=ns(),x=_n(),p=l.useMemo(()=>[...d,...x.filter(xn)],[d,x]),c=t?p.find(m=>m.id===t.providerId):void 0,f=c?.models.find(m=>m.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.")})]}),p.length>0&&e.jsx("div",{className:"w-full min-w-0",children:e.jsx(Ue,{providers:p,providerId:c?.id??"",modelId:f?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:s("No assistant approval model selected"),side:"bottom",triggerClassName:ss,onSelect:(m,h)=>n({providerId:m,modelId:h}),onReasoningChange:()=>{},onThinkingChange:()=>{}})}),c&&xn(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(se,{items:u,value:String(o),onValueChange:m=>i(Number(m)),children:[e.jsx(te,{className:"w-36","aria-label":s("Auto-allow threshold"),children:e.jsx(ne,{})}),e.jsx(ae,{children:td.map(m=>e.jsx(Z,{value:String(m),children:u[String(m)]},m))})]})]}),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 Nr(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 Up(){const{t:s}=R(),t=Qs(),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),u=g(M=>M.defaultReasoningEnabled),d=g(M=>M.defaultThinkingLevel),x=g(M=>M.setDefaultReasoningEnabled),p=g(M=>M.setDefaultThinkingLevel),c=yt(M=>M.snapshot),f=nd(M=>M.latest),m=ns(),h=a?m.find(M=>M.id===a.providerId):void 0,j=h?.models.find(M=>M.id===a?.modelId),b=t.some(M=>!!M.oauthAccountKey),A=b&&(c.availability.status==="unloaded"||c.availability.status==="loading"),k=b&&c.availability.status==="error"?c.availability.error:null,N=f?.notice,S=N?s("Default model changed: {{previous}} → {{next}}",{previous:Nr(N.previous,t),next:N.next?Nr(N.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.")})]}),m.length>0&&e.jsx("div",{className:"w-full min-w-0",children:e.jsx(Ue,{providers:m,virtualModels:n,providerId:h?.id??a?.providerId??"",modelId:j?.id??a?.modelId??"",reasoningEnabled:u,thinkingLevel:d,emptyLabel:s("Select model"),triggerLabel:o?s("Follow last selection"):void 0,side:"bottom",triggerClassName:ss,onSelect:(M,V)=>r({providerId:M,modelId:V}),onReasoningChange:x,onThinkingChange:p,showReasoningControls:!o})}),!o&&m.length>0&&e.jsx(y,{type:"button",variant:"ghost",size:"sm",className:"self-start",onClick:()=>i(!0),children:s("Follow last selection")}),m.length===0&&e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-5 text-center",children:[e.jsx(Vn,{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||k)&&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:k?s("Subscription credentials could not be loaded: {{error}}",{error:k}):s("Subscription credentials are loading. API-key models remain available.")})]}),S&&e.jsx("p",{className:"rounded-md bg-muted px-2.5 py-2 text-muted-foreground text-xs",children:S})]})}function $p(){const{t:s}=R(),t=em(Qs()),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(Ue,{providers:t,providerId:n?.providerId??"",modelId:n?.modelId??"",reasoningEnabled:!1,thinkingLevel:"medium",emptyLabel:s("Select model"),side:"bottom",triggerClassName:ss,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 Vp({provider:s,onClose:t}){const{t:n}=R(),a=g(j=>j.providers),r=g(j=>j.updateProvider),o=So(j=>j.snapshot),i=l.useMemo(()=>Io([s],o)[0]?.models??s.models,[s,o]),u=yt(j=>j.snapshot.availability),d=yt(j=>j.snapshot.revision),[x,p]=l.useState([]),[c,f]=l.useState(s.oauthAccountPool?.accountKeys??[]);l.useEffect(()=>{let j=!1;return window.electronAPI.providers.listOauth().then(b=>{j||p(b)}).catch(b=>{j||(p([]),console.error("Failed to load OAuth account metadata",b))}),()=>{j=!0}},[d]);const m=To(a),h=[...m.flatMap(j=>j.oauthAccountKey??[]),...c.filter(j=>!m.some(b=>b.oauthAccountKey===j))];return e.jsx(Ao,{initialValue:{...s,name:Kn(s,n),models:i},oauth:!0,hideName:!0,saveDisabled:c.length===0,oauthAccountKey:s.oauthAccountKey,onCancel:t,extraFields:e.jsxs(ue,{children:[e.jsx(me,{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:h.map((j,b)=>{const A=m.find(N=>N.oauthAccountKey===j),k=x.flatMap(N=>N.accounts).find(N=>N.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:N=>f(S=>N?[...S,j]:S.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:k?.email??j}),!A?.enabled&&e.jsx("span",{className:"shrink-0 text-xs text-muted-foreground",children:n("Account disabled")}),u.status==="ready"&&!u.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:Eo(j.models,Po(o,s.oauthAccountKey??"")?.models,Mo(g.getState(),s.id)),oauthAccountPool:{accountKeys:h.filter(b=>c.includes(b))}}),t())}})}function Kp({provider:s,onClose:t}){const{t:n}=R(),a=g(i=>i.updateProvider),r=So(i=>i.snapshot),o=l.useMemo(()=>s?.oauthAccountKey?Io([s],r)[0]?.models??s.models:s?.models,[s,r]);return e.jsx(ve,{open:s!==null,onOpenChange:i=>!i&&t(),children:e.jsxs(be,{children:[e.jsx(ye,{children:e.jsx(we,{children:s?.oauthAccountPool?Kn(s,n):n("Edit Provider")})}),s?.oauthAccountPool?e.jsx(Vp,{provider:s,onClose:t},s.id):s&&e.jsx(Ao,{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:Eo(i.models,Po(r,s.oauthAccountKey)?.models,Mo(g.getState(),s.id))}:i),t()}},s.id)]})})}const Gp=(s,t)=>s.models.some(n=>n.id===t&&n.enabled!==!1),kr=()=>{};function Cr(s){return s==="on"||s==="off"}function en(s){return typeof s=="string"&&ld.includes(s)}function Wp(){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),u=g(c=>c.defaultModel),d=g(c=>c.virtualModels),x=ns(),p=l.useMemo(()=>{if(u&&ad(u)){const c=rd(d,x).find(f=>f.id===u.modelId);if(c)return{providerId:od,modelId:c.id}}if(u){const c=x.find(f=>f.id===u.providerId);if(c&&Gp(c,u.modelId))return u}for(const c of x){const f=c.models.find(m=>m.enabled!==!1);if(f)return{providerId:c.id,modelId:f.id}}return null},[x,u,d]);return e.jsxs("section",{"data-slot":"subagent-models",className:"space-y-2 rounded-lg border bg-card p-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h4",{className:"font-medium text-sm",children:s("Let the agent pick subagent models")}),e.jsx("p",{className:"mt-0.5 text-muted-foreground text-xs",children:s("The main agent can pick one of these models when dispatching subagents or coworkers. The description tells it when to use each model.")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:s("Applies to newly started conversations.")})]}),e.jsx(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:H("flex items-center gap-2 rounded-md border px-2 py-1.5",c.enabled===!1&&"bg-muted/50 text-muted-foreground"),children:[e.jsx(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(ie,{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(Ue,{providers:x,virtualModels:d,providerId:c.providerId,modelId:c.modelId,modelCapabilityOverrides:id(c),reasoningMode:Cr(c.reasoning)?c.reasoning:"follow",reasoningEnabled:c.reasoning==="on",thinkingLevel:en(c.thinkingLevel)?c.thinkingLevel:"medium",onReasoningModeChange:(f,m)=>{f==="follow"?o(c.id,{reasoning:void 0,thinkingLevel:void 0}):f==="on"&&!en(c.thinkingLevel)?o(c.id,{reasoning:"on",thinkingLevel:m}):o(c.id,{reasoning:f})},onSelect:(f,m)=>o(c.id,{providerId:f,modelId:m}),onReasoningChange:f=>o(c.id,{reasoning:f?"on":"off"}),onThinkingChange:f=>o(c.id,{thinkingLevel:f}),onReasoningNormalize:Cr(c.reasoning)?f=>o(c.id,{reasoning:f?"on":"off"}):kr,onThinkingNormalize:en(c.thinkingLevel)?f=>o(c.id,{thinkingLevel:f}):kr})}),e.jsx(Q,{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(Re,{className:"h-3.5 w-3.5"})})]},c.id)),e.jsxs(y,{type:"button",variant:"outline",size:"sm",className:"h-7 text-xs",disabled:!p,onClick:()=>{p&&r({...p,description:""})},children:[e.jsx(Pe,{className:"mr-1 h-3.5 w-3.5"}),s("Add model")]}),!p&&e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Enable a model and configure valid provider credentials first.")})]})]})}function Hp(){const{t:s}=R(),t=g(d=>d.titleSummaryEnabled),n=g(d=>d.setTitleSummaryEnabled),a=g(d=>d.titleSummaryModel),r=g(d=>d.setTitleSummaryModel),o=ns(),i=a?o.find(d=>d.id===a.providerId):void 0,u=i?.models.find(d=>d.id===a?.modelId);return e.jsxs("section",{className:"space-y-2 rounded-lg border bg-card p-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h4",{className:"font-medium text-sm",children:s("Conversation title summary")}),e.jsx("p",{className:"mt-0.5 text-muted-foreground text-xs",children:s("Generate a short AI title from the first message of a new conversation.")})]}),e.jsx(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(Ue,{providers:o,providerId:i?.id??"",modelId:u?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:s("Follows the default model"),side:"bottom",triggerClassName:ss,onSelect:(d,x)=>r({providerId:d,modelId:x}),onReasoningChange:()=>{},onThinkingChange:()=>{}})}),a&&(!i||!u)&&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 qp({accountKey:s}){const t=bd(s);return!t||t.error?null:e.jsx(yd,{info:t})}function Yp(){const{t:s}=R(),t=g(B=>B.providers),n=Qs(),a=g(B=>B.updateProvider),r=g(B=>B.addProviders),o=g(B=>B.removeProvider),[i,u]=l.useState(!1),[d,x]=l.useState(!1),[p,c]=l.useState(null),[f,m]=l.useState(null),[h,j]=l.useState(null),[b,A]=l.useState(null),[k,N]=l.useState(!1),[S,M]=l.useState(!1),[V,E]=l.useState(null),L=yt(B=>B.snapshot.revision),[P,C]=l.useState([]);l.useEffect(()=>{let B=!1;return window.electronAPI.providers.listOauth().then(U=>{B||C(U)}),()=>{B=!0}},[L]);const I=l.useMemo(()=>cd(t,P),[t,P]),W=l.useMemo(()=>{const B=new Map;for(const U of n)B.set(U.id,U.models.length);return B},[n]),J=async(B,U)=>{if(j(B.id),A(null),B.oauthAccountKey&&!B.oauthAccountPool&&!U?.skipLogout)try{await window.electronAPI.providers.oauthLogout(B.oauthAccountKey),await wd()}catch(re){j(null),A({providerId:B.id,message:re instanceof Error?re.message:String(re)});return}o(B.id),j(null),A(null)},w=()=>{const B=f;B&&J(B)},z=async()=>{N(!0),E(null);try{const B=await jd(t);vd(B,a),E(B);const U=Object.values(B).filter(F=>F.status==="failed"),re=Object.keys(B).length-U.length;Me({type:U.length>0?"warning":"success",title:s("Fetched {{count}} providers",{count:re}),...U.length>0?{description:s("{{count}} failed",{count:U.length})}:{}})}finally{N(!1)}},G=async()=>{M(!0);try{const B=await window.electronAPI.providers.refreshModelCatalog();gd(),Me({type:B.ok?"success":"warning",title:B.ok?s("Model info updated"):B.fromCache?s("Model info refresh failed, using cache"):s("Model info refresh failed")})}catch{Me({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(ts,{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:S,onClick:()=>{G()},children:[S?e.jsx(Ae,{className:"mr-1.5 h-4 w-4 animate-spin"}):e.jsx(cs,{className:"mr-1.5 h-4 w-4"}),s("Refresh model info")]}),e.jsxs(y,{variant:"outline",size:"sm",disabled:k||t.length===0,onClick:()=>{z()},children:[k?e.jsx(Ae,{className:"mr-1.5 h-4 w-4 animate-spin"}):e.jsx(cs,{className:"mr-1.5 h-4 w-4"}),s("Fetch all models")]}),e.jsxs(y,{variant:"outline",size:"sm",onClick:()=>u(!0),children:[e.jsx(It,{className:"h-4 w-4 mr-1.5"}),s("Import from local apps")]}),e.jsxs(y,{size:"sm",onClick:()=>x(!0),children:[e.jsx(Pe,{className:"h-4 w-4 mr-1.5"}),s("Add model or provider")]})]})]}),e.jsx(Up,{}),e.jsx($p,{}),e.jsx(hx,{}),e.jsx(Hp,{}),e.jsx(Bp,{}),e.jsx(Wp,{}),To(t).length>0&&!t.some(B=>B.oauthAccountPool)&&e.jsxs("div",{className:"space-y-1.5 rounded-md border p-3",children:[e.jsxs(y,{variant:"outline",size:"sm",onClick:()=>{const B=dd(t,crypto.randomUUID());B&&r([B])>0&&c(B)},children:[e.jsx(Pe,{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(Vn,{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:I.map(B=>{const U=P.find(F=>F.id===B.vendorId),re=B.vendorId===ud?s("Custom"):B.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:re}),e.jsx("span",{className:"text-[11px] text-muted-foreground/60",children:B.providers.length})]}),e.jsx("div",{className:"mt-1.5 space-y-1 border-l pl-3",children:B.providers.map(F=>{const ee=!!F.oauthAccountKey,$=W.get(F.id)??F.models.length,oe=F.oauthAccountKey&&!F.oauthAccountPool?U?.accounts.find(de=>de.key===F.oauthAccountKey):void 0,_=F.oauthAccountPool?Kn(F,s):ee?oe?.email??F.oauthAccountKey??F.name:F.name,le=V?.[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:[ee?e.jsx(md,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}):e.jsx(xd,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx("span",{className:H("truncate text-sm font-medium",!F.enabled&&"text-muted-foreground line-through"),children:_}),ee?oe?.plan&&e.jsx(ie,{variant:"outline",className:"shrink-0 text-[10px] uppercase",children:oe.plan}):e.jsx(ie,{variant:"outline",className:"shrink-0 text-[11px]",children:hd[F.api]??F.api}),F.importedFrom&&e.jsx(ie,{variant:"secondary",className:"shrink-0 text-[11px]",children:F.importedFrom}),e.jsx("span",{className:"min-w-0 truncate text-xs text-muted-foreground",children:[ee?void 0:F.baseUrl,F.oauthAccountPool?s("{{count}} accounts",{count:F.oauthAccountPool.accountKeys.length}):void 0,$>0?s("{{count}} models",{count:$}):void 0].filter(Boolean).join(" · ")})]}),xn(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(qp,{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(xs,{className:"h-3.5 w-3.5"})}),e.jsx(y,{variant:"ghost",size:"icon",disabled:h===F.id,className:H("h-7 w-7 text-muted-foreground opacity-0 transition-opacity hover:text-destructive group-hover:opacity-100",h===F.id&&"opacity-100"),onClick:()=>m(F),children:h===F.id?e.jsx(Ae,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Re,{className:"h-3.5 w-3.5"})}),e.jsx(ce,{checked:F.enabled,onCheckedChange:de=>a(F.id,{enabled:de})})]})]}),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:()=>{J(F)},children:s("Retry")}),e.jsx(y,{variant:"ghost",size:"sm",className:"h-6 px-2 text-[11px] text-destructive hover:text-destructive",onClick:()=>{J(F,{skipLogout:!0})},children:s("Delete anyway")})]})]}),le?.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"),": ",le.message]})})]},F.id)})})]},B.vendorId)})}),e.jsx(pd,{open:i,onOpenChange:u}),e.jsx(fd,{open:d,onOpenChange:x}),e.jsx(Kp,{provider:p,onClose:()=>c(null)}),e.jsx(Xr,{open:f!==null,onOpenChange:B=>{B||m(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:w})]})}const Jp=2e3,Sr=50,Bs="",Xp=[{id:"app",label:"App processes"},{id:"agent",label:"Agent and tools"},{id:"child",label:"Other child processes"}],yn={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 and chat models."],runtimes:["Runtimes","Bundled tools and GPU backends."],worktrees:["Worktrees","Isolated worktrees created for conversations."],snapshots:["Change snapshots","Baselines for the Changes panel."],browser:["Browser data","Cookies, storage and cache of the built-in browser."],cache:["Cache","Rebuildable caches; cleaning is safe."],logs:["Logs","Task and memory logs; files written in the last 24 hours are kept."],backups:["Backups","Configuration backup files; files from the last 24 hours are kept."],config:["Configuration","Settings, instructions, prompts and credentials."],other:["Other","Chromium profile data and other files."]};function Qp(s,t){switch(s){case"main":return t("Main process");case"window":return t("Window");case"browser":return t("Built-in browser");case"gpu":return"GPU";case"service":return t("Service");case"agent":return"Agent";case"tool":return t("Tool");default:return t("Child process")}}function Zp(s,t){return s.id==="data"?t("App data"):t("Worktree directory")}function ef(s,t){return s.role!=="window"?s.name:s.name==="Main window"?t("Main window"):s.name==="Settings"?t("Settings"):s.name}function sf(s){return`${s.toFixed(1)}%`}function tf(){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(Js,{value:t,onValueChange:a=>n(a),children:[e.jsxs(Xs,{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(Ks,{value:"cpu",className:"pt-4",children:t==="cpu"&&e.jsx(Ir,{metric:"cpu"})}),e.jsx(Ks,{value:"memory",className:"pt-4",children:t==="memory"&&e.jsx(Ir,{metric:"memory"})}),e.jsx(Ks,{value:"storage",className:"pt-4",children:t==="storage"&&e.jsx(af,{})})]})]})}function Ir({metric:s}){const{t}=R(),[n,a]=l.useState(null),[r,o]=l.useState(null);if(l.useEffect(()=>{let x=!1,p;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||(p=setTimeout(c,Jp))};return c(),()=>{x=!0,clearTimeout(p)}},[]),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"?sf:je,u=s==="cpu"?{app:n.cpu.app,system:n.cpu.system,total:100}:n.memory,d=x=>s==="cpu"?x.cpu:x.memory;return e.jsxs("div",{className:"space-y-4",children:[e.jsx(mi,{app:u.app,system:Math.max(u.system,u.app),total:u.total,format:i}),Xp.map(x=>{const p=n.processes.filter(c=>c.group===x.id).sort((c,f)=>d(f)-d(c));return p.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(p.reduce((c,f)=>c+d(f),0))})]}),e.jsx("div",{className:"divide-y",children:p.map(c=>e.jsxs("div",{className:"flex items-center gap-3 px-3 py-1.5 text-sm",children:[e.jsx("span",{className:"w-20 shrink-0 truncate text-xs text-muted-foreground",children:Qp(c.role,t)}),e.jsx("span",{className:"min-w-0 flex-1 truncate",title:c.command??c.name,children:ef(c,t)}),e.jsx("span",{className:"w-16 text-right font-mono text-xs text-muted-foreground",children:c.pid}),e.jsx("span",{className:"w-20 text-right font-mono text-xs",children:i(d(c))})]},c.pid))})]},x.id)})]})}function mi({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 nf(s,t){const n=[t("Freed {{size}}",{size:je(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 af(){const{t:s}=R(),[t,n]=l.useState(null),[a,r]=l.useState("scan"),[o,i]=l.useState(null),[u,d]=l.useState(null),[x,p]=l.useState(null),[c,f]=l.useState(null),m=l.useCallback(async(k,N)=>{r(k),d(null),i(null);try{n(await N())}catch(S){const M=S instanceof Error?S.message:String(S);M.includes("Scan cancelled")||d(M)}finally{r(null),i(null)}},[]),h=l.useCallback(()=>m("scan",()=>window.electronAPI.resources.scanStorage()),[m]),j=k=>m(k,async()=>{const N=await window.electronAPI.resources.cleanStorage(k);return Me({type:N.failed>0?"warning":"success",title:s("{{name}} cleaned",{name:s(yn[k][0])}),description:nf(N,s)}),N.snapshot});l.useEffect(()=>{const k=window.electronAPI.resources.onScanProgress(i);return window.electronAPI.resources.lastStorage().then(N=>{N&&n(S=>S??N)}),h(),()=>{k(),window.electronAPI.resources.cancelScan()}},[h]);const b=t?[...t.categories].filter(k=>k.bytes>0).sort((k,N)=>N.bytes-k.bytes):[],A=l.useMemo(()=>{const k=new Map;for(const N of t?.roots??[])k.set(N.volumeId,[...k.get(N.volumeId)??[],N]);return[...k.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:je(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:()=>{h()},disabled:a!==null,"aria-label":s("Refresh"),children:e.jsx(cs,{})})]}),u&&e.jsx("p",{className:"text-sm text-destructive",children:u}),t&&t.errorCount>0&&e.jsxs("p",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",title:t.errors.join(`
|
|
21
|
-
`),children:[e.jsx(He,{className:"h-3.5 w-3.5"}),s("{{count}} paths could not be read and are not counted.",{count:t.errorCount})]}),t&&e.jsxs(e.Fragment,{children:[A.map(k=>{const N=k[0]?.volume,S=k.reduce((M,V)=>M+V.bytes,0);return e.jsxs("div",{className:"space-y-2",children:[N?e.jsx(mi,{app:S,system:N.total-N.free,total:N.total,format:je}):e.jsx("div",{className:"rounded-lg border p-4 font-mono text-2xl font-semibold",children:je(S)}),k.map(M=>e.jsxs("div",{className:"flex items-center gap-2 px-1 text-xs",children:[e.jsx("span",{className:"shrink-0 text-muted-foreground",children:Zp(M,s)}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono",title:M.path,children:M.path}),e.jsx("span",{className:"font-mono",children:je(M.bytes)})]},M.id))]},k[0]?.volumeId)}),e.jsx("div",{className:"divide-y rounded-lg border",children:b.map(k=>e.jsx(rf,{category:k,share:t.totalBytes>0?k.bytes/t.totalBytes:0,expanded:x===k.id,onToggle:()=>p(x===k.id?null:k.id),cleaning:a===k.id,disabled:a!==null,onClean:()=>Ro[k.id]==="confirm"?f(k.id):void j(k.id)},k.id))}),e.jsx(of,{sessions:t.sessions,busy:a==="sessions",disabled:a!==null,onClean:k=>m("sessions",async()=>{const N=await window.electronAPI.resources.cleanSessions(k);return Me({type:"success",title:s("{{count}} conversations deleted",{count:N.removed})}),N.snapshot})})]}),e.jsx(In,{open:c!==null,onOpenChange:k=>!k&&f(null),children:e.jsxs(An,{className:"sm:max-w-md",zIndexLevel:"nested",children:[e.jsxs(En,{children:[e.jsx(Mn,{className:"text-base",children:s("Clean {{name}}?",{name:c?s(yn[c][0]):""})}),e.jsx(Pn,{children:s(c==="browser"?"You will be signed out of sites opened in the built-in browser.":"Deleted files cannot be restored.")})]}),e.jsxs(Tn,{variant:"bare",children:[e.jsx(Rn,{render:e.jsx(y,{variant:"outline",size:"sm"}),children:s("Cancel")}),e.jsx(y,{variant:"destructive",size:"sm",onClick:()=>{const k=c;f(null),k&&j(k)},children:s("Clean")})]})]})})]})}function rf({category:s,share:t,expanded:n,onToggle:a,cleaning:r,disabled:o,onClean:i}){const{t:u}=R(),[d,x]=yn[s.id];return e.jsxs("div",{className:"px-3 py-2",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{type:"button",onClick:a,className:"flex min-w-0 flex-1 items-center gap-2 text-left",children:[e.jsx(Ys,{className:H("h-4 w-4 shrink-0 transition-transform",n&&"rotate-90")}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-2 text-sm",children:[e.jsx("span",{className:"font-medium",children:u(d)}),e.jsx("span",{className:"font-mono text-xs",children:je(s.bytes)})]}),e.jsx("p",{className:"truncate text-xs text-muted-foreground",children:u(x)}),e.jsx("div",{className:"mt-1 h-1 overflow-hidden rounded-full bg-muted",children:e.jsx("div",{className:"h-full bg-foreground/60",style:{width:`${t*100}%`}})})]})]}),Ro[s.id]!=="none"&&e.jsx(y,{variant:"outline",size:"sm",disabled:o,onClick:i,children:u(r?"Cleaning...":"Clean")})]}),n&&e.jsx("div",{className:"mt-2 space-y-0.5 pl-6",children:s.entries.map(p=>e.jsxs("div",{className:"group flex items-center gap-2 text-xs",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-muted-foreground",children:p.root==="data"?p.path:`${u("Worktree directory")}/${p.path}`}),e.jsx("span",{className:"font-mono",children:je(p.bytes)}),e.jsx(y,{variant:"ghost",size:"icon-sm",className:"opacity-0 group-hover:opacity-100","aria-label":u("Show in folder"),onClick:()=>{window.electronAPI.resources.revealStorage(p.root,p.path)},children:e.jsx(zn,{})})]},`${p.root}:${p.path}`))})]})}function of({sessions:s,busy:t,disabled:n,onClean:a}){const{t:r}=R(),[o,i]=l.useState(!1),[u,d]=l.useState(!1),[x,p]=l.useState(null),[c,f]=l.useState(Bs),m=l.useMemo(()=>new Map(s.map(P=>[P.id,P])),[s]),h=l.useMemo(()=>{const P=new Map;for(const C of s){const I=P.get(C.projectId)??{name:C.projectName,bytes:0,count:0};I.bytes+=C.bytes,I.count+=1,P.set(C.projectId,I)}return[...P].sort((C,I)=>I[1].bytes-C[1].bytes)},[s]),j=h.some(([P])=>P===c)?c:Bs,b=j?s.filter(P=>P.projectId===j):s,A=P=>{const C=Id(s,P,Date.now());return{request:P,count:C.length,bytes:C.reduce((I,W)=>I+(m.get(W)?.bytes??0),0)}},k=P=>A({kind:"stale",days:P,includeUnarchived:o,...j?{projectId:j}:{}}),N=b.reduce((P,C)=>P+C.bytes,0),S=u?b:b.slice(0,Sr),M=(P,C)=>C||(P?P.slice(0,8):r("No project")),V=x?.request.kind==="one"?m.get(x.request.id):void 0,E=x?.request.kind==="stale"?x.request.projectId:void 0,L=E===void 0?void 0:M(E,h.find(([P])=>P===E)?.[1].name??"");return e.jsxs("div",{className:"rounded-lg border",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 border-b px-3 py-2",children:[e.jsxs("div",{className:"shrink-0 text-sm font-medium",children:[r("Conversations"),e.jsxs("span",{className:"ml-2 font-mono text-xs text-muted-foreground",children:[b.length," · ",je(N)]})]}),e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsxs(se,{items:{[Bs]:r("All projects"),...Object.fromEntries(h.map(([P,C])=>[P,M(P,C.name)]))},value:j,onValueChange:P=>f(P??Bs),children:[e.jsx(te,{size:"sm",className:"w-48 min-w-0",children:e.jsx(ne,{})}),e.jsxs(ae,{children:[e.jsx(Z,{value:Bs,children:r("All projects")}),h.map(([P,C])=>e.jsx(Z,{value:P,children:e.jsxs("span",{className:"flex w-full items-center gap-3",children:[e.jsx("span",{className:"flex-1 truncate",children:M(P,C.name)}),e.jsxs("span",{className:"font-mono text-xs text-muted-foreground",children:[C.count," · ",je(C.bytes)]})]})},P))]})]}),e.jsxs(Oo,{children:[e.jsxs(Do,{render:e.jsx(y,{variant:"outline",size:"sm",disabled:n||b.length===0}),children:[e.jsx(Nd,{}),r(t?"Cleaning...":"Clean")]}),e.jsxs(Lo,{align:"end",className:"min-w-48",children:[e.jsx(kd,{checked:o,onCheckedChange:i,closeOnClick:!1,children:r("Include unarchived")}),e.jsx(Cd,{}),[...Sd,0].map(P=>{const C=k(P);return e.jsxs(zo,{variant:"destructive",disabled:C.count===0,onClick:()=>p(C),children:[e.jsx("span",{className:"flex-1",children:P>0?r("Older than {{days}} days",{days:P}):r("All")}),e.jsx("span",{className:"font-mono text-xs opacity-70",children:C.count})]},P)})]})]})]})]}),e.jsx("div",{className:"max-h-96 divide-y overflow-y-auto",children:S.map(P=>e.jsxs("div",{className:"group flex items-center gap-3 px-3 py-1.5 text-sm",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate",title:P.title,children:P.title||r("Untitled")}),e.jsx("div",{className:"truncate text-xs text-muted-foreground",children:[P.projectName,P.archived?r("Archived"):null,new Date(P.lastActiveAt).toLocaleDateString()].filter(Boolean).join(" · ")})]}),e.jsx("span",{className:"font-mono text-xs",children:je(P.bytes)}),e.jsx(y,{variant:"ghost",size:"icon-sm",className:"opacity-0 group-hover:opacity-100",disabled:n,"aria-label":r("Delete"),onClick:()=>p({request:{kind:"one",id:P.id},count:1,bytes:P.bytes}),children:e.jsx(Re,{})})]},P.id))}),b.length>Sr&&e.jsx("button",{type:"button",onClick:()=>d(!u),className:"w-full border-t px-3 py-1.5 text-xs text-muted-foreground hover:text-foreground",children:r(u?"Show less":"Show all")}),e.jsx(In,{open:x!==null,onOpenChange:P=>!P&&p(null),children:e.jsxs(An,{className:"sm:max-w-md",zIndexLevel:"nested",children:[e.jsxs(En,{children:[e.jsx(Mn,{className:"text-base",children:V?r('Delete "{{title}}"?',{title:V.title||r("Untitled")}):L!==void 0?r("Delete {{count}} conversations in {{project}}?",{count:x?.count??0,project:L}):r("Delete {{count}} conversations?",{count:x?.count??0})}),e.jsxs(Pn,{children:[r("About {{size}} of history, tool output and isolated worktrees will be removed and cannot be restored.",{size:je(x?.bytes??0)}),!V&&` ${r("Open, running and waiting conversations are skipped.")}`]})]}),e.jsxs(Tn,{variant:"bare",children:[e.jsx(Rn,{render:e.jsx(y,{variant:"outline",size:"sm"}),children:r("Cancel")}),e.jsx(y,{variant:"destructive",size:"sm",onClick:()=>{const P=x?.request;p(null),P&&a(P)},children:r("Delete")})]})]})})]})}const xi={cropSource:null,busy:!1,problem:null};function lf(s,t){switch(t.type){case"pick":return{...s,cropSource:null,busy:!1,problem:t.problem};case"picked":return{cropSource:t.source,busy:!1,problem:null};case"read-failed":return{cropSource:null,busy:!1,problem:"read"};case"crop-cancelled":return{cropSource:null,busy:!1,problem:null};case"cropped":return t.tooLarge?{cropSource:null,busy:!1,problem:"size"}:{cropSource:null,busy:!0,problem:null};case"saving":return{cropSource:null,busy:!0,problem:null};case"saved":return xi;case"save-failed":return{cropSource:null,busy:!1,problem:"save"}}}const cf={ui:"Follow the interface language",zh:"Chinese",en:"English"},df={concise:"Concise",detailed:"Detailed"},uf={"needs-user":"Only what needs you","with-done":"Include finished work",off:"Off"},mf=Array.from({length:Ad-Ea+1},(s,t)=>{const n=String(Ea+t);return{value:n,label:n}}),xf={type:"Avatar images must be PNG, JPEG, WebP or GIF, and at most 2 MB.",size:"Avatar images must be PNG, JPEG, WebP or GIF, and at most 2 MB.",read:"This image cannot be used as an avatar.",save:"Could not save the secretary profile. Try again."};function Vs({value:s,options:t,onChange:n,enso:a}){const{t:r}=R();return e.jsx("div",{className:"flex flex-wrap gap-1","data-enso":a,children:t.map(o=>e.jsx("button",{type:"button","aria-pressed":o.value===s,onClick:()=>n(o.value),className:H("rounded-md border px-2.5 py-1 text-xs transition-colors",o.value===s?"border-primary/60 bg-primary/10 text-foreground":"border-border text-muted-foreground hover:bg-muted"),children:r(o.label)},o.value))})}function Qe({title:s,description:t,rowId:n,children:a}){const{t:r}=R();return e.jsxs("section",{className:"space-y-3","data-settings-row":n,children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium",children:r(s)}),t?e.jsx("p",{className:"text-xs text-muted-foreground",children:r(t)}):null]}),a]})}function hi(s,t){return s?new Date(s).toLocaleString(t==="zh"?"zh-CN":"en-US",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}):""}function hf({pluginIds:s,busy:t,onChange:n}){const{t:a}=R(),[r,o]=l.useState([]);l.useEffect(()=>{window.electronAPI.extensionPlugins.list().then(u=>o(u)).catch(()=>{})},[]);const i=r.filter(u=>u.state==="enabled");return i.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:a("No plugins enabled")}):e.jsx("div",{className:"divide-y rounded-md border",children:i.map(u=>e.jsxs("label",{className:"flex cursor-pointer items-center gap-2 px-3 py-2 text-sm","data-enso":"secretary-plugin-row","data-plugin-id":u.id,children:[e.jsx(Le,{checked:s.includes(u.id),disabled:t,onCheckedChange:d=>n(d===!0?[...s,u.id]:s.filter(x=>x!==u.id))}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:u.name}),e.jsx("span",{className:"shrink-0 text-xs text-muted-foreground",children:a("{{n}} tools",{n:u.tools.length})}),u.permissions.includes("agent.inject")?e.jsx("span",{className:"shrink-0 rounded bg-muted px-1.5 text-[10px] text-muted-foreground",children:a("Sends messages")}):null]},u.id))})}function pf({busy:s}){const{t}=R(),[n,a]=l.useState([]),[r,o]=l.useState(null),i=l.useCallback(async()=>{const d=await window.electronAPI.secretary.listSkills();d.ok?a(d.skills.filter(x=>x.source==="own")):o(d.error)},[]);l.useEffect(()=>{i()},[i]);const u=async d=>{o(null);const x=await window.electronAPI.secretary.removeSkill(d);if(!x.ok){o(x.error);return}await i()};return r?e.jsx("p",{className:"text-xs text-destructive",children:r}):n.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:t("No skills yet")}):e.jsx("div",{className:"divide-y rounded-md border",children:n.map(d=>e.jsxs("div",{className:"px-3 py-2","data-enso":"secretary-skill-row",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-sm",children:d.name}),!d.enabled&&e.jsx("span",{className:"shrink-0 rounded bg-warning/10 px-1 text-[10px] text-warning",children:t("Disabled")}),e.jsx(y,{variant:"ghost",size:"sm",disabled:s,onClick:()=>{u(d.name)},children:t("Remove")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:d.description}),e.jsxs("details",{className:"mt-1",children:[e.jsx("summary",{className:"cursor-pointer text-[11px] text-muted-foreground",children:t("Show the content")}),e.jsx("pre",{className:"mt-1 max-h-64 overflow-auto whitespace-pre-wrap text-[11px]",children:d.body??""})]})]},d.name))})}function ff({busy:s}){const{t}=R(),[n,a]=l.useState([]),[r,o]=l.useState(null),i=l.useCallback(async()=>{const d=await window.electronAPI.secretary.listTools();d.ok?a(d.tools):o(d.error)},[]);l.useEffect(()=>{i()},[i]);const u=async d=>{o(null);const x=await window.electronAPI.secretary.removeTool(d);if(!x.ok){o(x.error);return}await i()};return r?e.jsx("p",{className:"text-xs text-destructive",children:r}):n.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:t("No tools yet")}):e.jsx("div",{className:"divide-y rounded-md border",children:n.map(d=>e.jsxs("div",{className:"px-3 py-2","data-enso":"secretary-tool-row",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-sm",children:d.name}),e.jsx("span",{className:"shrink-0 rounded bg-muted px-1.5 text-[10px] text-muted-foreground",children:d.runtime==="python"?"Python":"Node"}),e.jsx("span",{className:"shrink-0 rounded bg-muted px-1.5 text-[10px] text-muted-foreground",children:d.readOnly?t("Read-only"):t("Asks every call")}),e.jsx(y,{variant:"ghost",size:"sm",disabled:s,onClick:()=>{u(d.name)},children:t("Remove")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:d.description}),e.jsxs("details",{className:"mt-1",children:[e.jsx("summary",{className:"cursor-pointer text-[11px] text-muted-foreground",children:t("Show the code")}),e.jsx("pre",{className:"mt-1 max-h-64 overflow-auto whitespace-pre font-mono text-[11px]",children:d.code})]})]},d.name))})}function gf({profile:s,busy:t,onChange:n}){const{t:a}=R(),r=g(x=>x.projects),o=s.takeoverScope,i=s.visibleProjectIds,u=r.filter(x=>x.kind!=="secretary"&&x.kind!=="scratch"&&(i==="all"||i.includes(x.id))),d=o.mode==="projects"?o.projectIds:[];return e.jsxs("div",{className:"space-y-2",children:[e.jsx(Vs,{enso:"secretary-takeover-scope",value:o.mode,options:[{value:"explicit",label:"One by one"},{value:"projects",label:"Selected projects"},{value:"all",label:"All visible projects"}],onChange:x=>n(x==="all"?{mode:"all"}:x==="explicit"?{mode:"explicit"}:{mode:"projects",projectIds:d})}),o.mode==="projects"?u.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:a("No project in the takeover scope")}):e.jsx("div",{className:"flex flex-wrap gap-1","data-enso":"secretary-takeover-projects",children:u.map(x=>{const p=d.includes(x.id);return e.jsx("button",{type:"button","aria-pressed":p,disabled:t,onClick:()=>n({mode:"projects",projectIds:p?d.filter(c=>c!==x.id):[...d,x.id]}),className:H("rounded-md border px-2.5 py-1 text-xs transition-colors",p?"border-primary/60 bg-primary/10 text-foreground":"border-border text-muted-foreground hover:bg-muted"),children:x.alias||x.name},x.id)})}):null]})}function jf({locale:s}){const{t}=R(),[n,a]=l.useState([]),[r,o]=l.useState(null),i=l.useCallback(async()=>{const d=await window.electronAPI.secretary.listTakeovers();d.ok?a(d.takeovers):o(d.error)},[]);l.useEffect(()=>(i(),window.electronAPI.secretary.onStateChanged(()=>{i()})),[i]);const u=async d=>{o(null);const x=await window.electronAPI.secretary.revokeTakeover(d);x.ok||o(x.error),await i()};return e.jsxs(e.Fragment,{children:[r?e.jsx("p",{className:"text-xs text-destructive",children:r}):null,n.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:t("No sessions handed over")}):e.jsx("div",{className:"divide-y rounded-md border",children:n.map(d=>e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2","data-enso":"secretary-takeover-row","data-conversation-id":d.conversationId,children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-sm",children:d.title||t("Unnamed")}),e.jsx("p",{className:"truncate text-xs text-muted-foreground",children:[d.projectName,hi(d.grantedAt,s)].filter(Boolean).join(" · ")})]}),e.jsx(y,{variant:"ghost",size:"sm",onClick:()=>{u(d.conversationId)},children:t("Take back")})]},d.conversationId))})]})}function vf(){const{t:s}=R(),[t,n]=l.useState([]),[a,r]=l.useState(null),o=l.useCallback(async()=>{const u=await window.electronAPI.secretary.listUntracked();u.ok?n(u.untracked):r(u.error)},[]);l.useEffect(()=>(o(),window.electronAPI.secretary.onStateChanged(()=>{o()})),[o]);const i=async u=>{r(null);const d=await window.electronAPI.secretary.removeUntracked(u);d.ok||r(d.error),await o()};return t.length===0&&!a?null:e.jsxs("div",{className:"mt-3 space-y-2","data-enso":"secretary-untracked",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Not tracked: the takeover scope no longer covers these sessions. Removing one lets the scope cover it again.")}),a?e.jsx("p",{className:"text-xs text-destructive",children:a}):null,e.jsx("div",{className:"divide-y rounded-md border",children:t.map(u=>e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2","data-enso":"secretary-untracked-row","data-conversation-id":u.conversationId,children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-sm",children:u.title||s("Unnamed")}),e.jsx("p",{className:"truncate text-xs text-muted-foreground",children:u.projectName})]}),e.jsx(y,{variant:"ghost",size:"sm",onClick:()=>{i(u.conversationId)},children:s("Track again")})]},u.conversationId))})]})}function bf({skillIds:s,onChange:t}){const{t:n}=R(),a=g(r=>r.skills);return e.jsx(_d,{title:n("Global skills"),emptyText:n("No skills yet"),items:a,getName:r=>r.name,getSource:r=>r.source,isChecked:r=>s.includes(r.id),onToggle:r=>t(s.includes(r.id)?s.filter(o=>o!==r.id):[...s,r.id]),placeholder:n("Filter skills..."),renderDetail:r=>e.jsx("p",{className:"text-xs",children:r.description||r.path})})}function yf(){const{t:s,locale:t}=R(),[n,a]=l.useState(null),[r,o]=l.useState(""),[i,u]=l.useState(null),[d,x]=l.useState([]),[p,c]=l.useState(!1),[f,m]=l.useState(null),[h,j]=l.useState(null),[b,A]=l.useState(!1),[k,N]=l.useReducer(lf,xi),S=l.useRef(null),M=s("Secretary"),V=l.useCallback(async()=>{const I=await window.electronAPI.secretary.listSchedules();I.ok&&x(I.schedules)},[]),E=l.useCallback(async()=>{const I=await window.electronAPI.secretary.getProfile();if(!I.ok){m(I.error);return}a(I.profile),o(I.persona),u(I.profile?ct(I.profile,M):null),await V()},[M,V]);l.useEffect(()=>{E()},[E]);const L=async I=>{c(!0),m(null),j(null);try{const W=await window.electronAPI.secretary.saveProfile(I);if(!W.ok){m(W.error);return}a(W.profile),u(ct(W.profile,M)),j(s("Saved")),await V()}catch{m(s("Could not save the secretary profile. Try again."))}finally{c(!1)}},P=async I=>{N({type:"saving"}),m(null);try{const W=await window.electronAPI.secretary.setAvatar(I);if(!W.ok){N({type:"save-failed"}),m(W.error);return}a(W.profile),u(ct(W.profile,M)),N({type:"saved"})}catch{N({type:"save-failed"}),m(s("Could not save the secretary profile. Try again."))}},C=async I=>{m(null);const W=await window.electronAPI.secretary.removeSchedule(I);if(!W.ok){m(W.error);return}await V()};return e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("Secretary")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("The secretary is not part of any project. It watches your projects, dispatches sessions and reports results back. It never reads or writes code itself.")})]}),f?e.jsx("p",{className:"text-xs text-destructive",children:f}):null,k.problem?e.jsx("p",{className:"text-xs text-destructive","data-enso":"secretary-avatar-problem",children:s(xf[k.problem])}):null,h?e.jsx("p",{className:"text-xs text-muted-foreground",children:h}):null,e.jsxs(Qe,{title:"Secretary profile",description:"Name, avatar, visible projects and patrol.",rowId:"secretary.profile",children:[n?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{ref:S,type:"file",accept:"image/png,image/jpeg,image/webp,image/gif","data-enso":"secretary-avatar-file",className:"hidden",onChange:I=>{const W=I.target.files?.[0];if(I.target.value="",!W)return;const J=Ed(W,Ma);N({type:"pick",problem:J}),!J&&Md(W).then(w=>N({type:"picked",source:w}),()=>N({type:"read-failed"}))}}),e.jsx(Pd,{name:n.name,color:n.avatar.color,image:n.avatar.imageVersion?Td(n.avatar.imageVersion,n.avatar.imageHash):void 0,needsYou:0,running:0,enso:"secretary-settings-avatar"}),e.jsx(y,{variant:"outline",size:"sm",disabled:k.busy,onClick:()=>S.current?.click(),"data-enso":"secretary-avatar-upload",children:s("Upload image")}),n.avatar.imageVersion?e.jsx(y,{variant:"ghost",size:"sm",disabled:k.busy,onClick:()=>{P(null)},"data-enso":"secretary-avatar-remove",children:s("Remove image")}):null,e.jsx(Rd,{source:k.cropSource,onCancel:()=>N({type:"crop-cancelled"}),onDone:I=>{const W=Od(I),J=W.byteLength>Ma;N({type:"cropped",tooLarge:J}),!J&&P(W)}})]}):e.jsx("p",{className:"text-xs text-muted-foreground",children:s("The secretary has not been set up yet.")}),e.jsx(Dd,{initialDraft:n?ct(n,M):Ld(M),submitLabel:s("Save"),busy:p,hideMaxRunning:!0,onSubmit:({maxRunningDispatches:I,...W})=>{L(W)}},n?.updatedAt??"new")]}),e.jsx(Qe,{title:"Concurrent dispatch limit",description:"The most dispatched sessions the secretary may run at the same time. Once the limit is reached, new dispatches are refused.",rowId:"secretary.dispatchLimit",children:n?e.jsx(Vs,{enso:"secretary-dispatch-limit",value:String(n.maxRunningDispatches),options:mf,onChange:I=>{const W=Number(I);p||W===n.maxRunningDispatches||L({maxRunningDispatches:W})}}):e.jsx("p",{className:"text-xs text-muted-foreground",children:s("The secretary has not been set up yet.")})}),e.jsx(Qe,{title:"Plugins",description:"Check a plugin to give the secretary its agent tools and skills. Tools that are not read-only ask for your approval on every call.",rowId:"secretary.plugins",children:n?e.jsx(hf,{pluginIds:n.pluginIds??[],busy:p,onChange:I=>{L({pluginIds:I})}}):e.jsx("p",{className:"text-xs text-muted-foreground",children:s("The secretary has not been set up yet.")})}),e.jsx(Qe,{title:"Skills",description:"Skills the secretary may use. It proposes new ones in the chat; you confirm before anything is written.",rowId:"secretary.skills",children:n?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"mb-1 text-xs font-semibold tracking-wide text-muted-foreground uppercase",children:s("Secretary skills")}),e.jsx(pf,{busy:p})]}),e.jsx(bf,{skillIds:n.skillIds??[],onChange:I=>{L({skillIds:I})}})]}):e.jsx("p",{className:"text-xs text-muted-foreground",children:s("The secretary has not been set up yet.")})}),e.jsx(Qe,{title:"Tools",description:"Python or Node tools the secretary builds for itself. It proposes them in the chat; you confirm before anything is written. Read-only tools run directly, anything else asks for your approval on every call.",rowId:"secretary.tools",children:n?e.jsx(ff,{busy:p}):e.jsx("p",{className:"text-xs text-muted-foreground",children:s("The secretary has not been set up yet.")})}),i?e.jsx(Qe,{title:"Style and interruptions",description:"What it calls you, reply language, style and system notifications.",rowId:"secretary.style",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-sm",children:s("What to call you")}),e.jsx(Q,{value:i.addressAs??"",placeholder:s("Optional"),onChange:I=>u({...i,addressAs:I.target.value.trim()?I.target.value:null}),className:"max-w-xs"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-sm",children:s("Reply language")}),e.jsx(Vs,{value:i.replyLanguage??"ui",options:["ui","zh","en"].map(I=>({value:I,label:cf[I]})),onChange:I=>u({...i,replyLanguage:I})})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-sm",children:s("Communication style")}),e.jsx(Vs,{value:i.style??"concise",options:["concise","detailed"].map(I=>({value:I,label:df[I]})),onChange:I=>u({...i,style:I})})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-sm",children:s("System notifications")}),e.jsx(Vs,{value:i.notify??"needs-user",options:["needs-user","with-done","off"].map(I=>({value:I,label:uf[I]})),onChange:I=>u({...i,notify:I})})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-sm",children:s("Daily brief time")}),e.jsx(Q,{type:"time",value:i.dailyBriefAt??"",onChange:I=>u({...i,dailyBriefAt:I.target.value||null}),className:"max-w-32"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-sm",children:s("Persona")}),e.jsx(Ze,{value:r,onChange:I=>o(I.target.value),rows:4})]}),e.jsx(y,{size:"sm",disabled:p,onClick:()=>{L({addressAs:i.addressAs??null,replyLanguage:i.replyLanguage,style:i.style,notify:i.notify,dailyBriefAt:i.dailyBriefAt??null,persona:r})},children:s("Save")})]})}):null,e.jsx(Qe,{title:"Sessions it may take over",description:"Which sessions the secretary may message and stop without asking you first. Everything else still needs a confirmation card from the secretary.",rowId:"secretary.takeoverScope",children:n?e.jsx(gf,{profile:n,busy:p,onChange:I=>{L({takeoverScope:I})}}):e.jsx("p",{className:"text-xs text-muted-foreground",children:s("The secretary has not been set up yet.")})}),e.jsxs(Qe,{title:"Sessions handed over",description:"Sessions you started and handed to the secretary. It may message and stop them like the ones it dispatched; take one back to remove that right.",rowId:"secretary.takeovers",children:[e.jsx(jf,{locale:t}),e.jsx(vf,{})]}),e.jsx(Qe,{title:"Scheduled tasks",rowId:"secretary.schedules",children:d.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Nothing scheduled")}):e.jsx("div",{className:"divide-y rounded-md border",children:d.map(I=>e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-sm",children:I.name}),e.jsxs("p",{className:"truncate text-xs text-muted-foreground",children:[I.cron??I.at??"",I.nextRunAt?` · ${hi(I.nextRunAt,t)}`:""]})]}),I.system?e.jsx("span",{className:"shrink-0 rounded bg-muted px-1.5 text-[10px] text-muted-foreground",children:s("Built-in")}):e.jsx(y,{variant:"ghost",size:"sm",onClick:()=>{C(I.id)},children:s("Remove")})]},I.id))})}),e.jsxs(Qe,{title:"Reset the secretary and start over",description:"Sessions and dispatch history are kept either way.",rowId:"secretary.reset",children:[e.jsx(y,{variant:"outline",size:"sm",onClick:()=>A(!0),children:s("Re-run setup")}),e.jsx(zd,{open:b,onOpenChange:A,onReset:()=>{a(null),u(null),o(""),j(null),V()}})]})]})}function wf(){const{t:s}=R(),t=g(S=>S.skills),n=g(S=>S.updateSkill),a=g(S=>S.setSkillsEnabled),r=g(S=>S.removeSkill),o=g(S=>S.loadLocalSkills),i=g(S=>S.setLoadLocalSkills),u=g(S=>S.loadHarnessAssets),d=g(S=>S.setLoadHarnessAssets),[x,p]=l.useState(!1),[c,f]=l.useState(""),m=t.filter(S=>go(c,[S.name,S.source,S.description,S.path])),h=m.map(S=>S.id),j=jo(h),b=t.filter(S=>S.enabled).length,A=t.map(S=>S.id),k=Pt(A,S=>window.electronAPI.assets.skillOccupancy(S)),N=At(t.filter(S=>S.enabled).map(S=>S.id),k.rows);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 rounded-lg border px-3 py-2.5",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:s("Load local skills")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Let the agent auto-discover skills under .agents/skills and .pi/skills")})]}),e.jsx(ce,{checked:o,onCheckedChange:i})]}),e.jsxs("div",{className:"flex items-center justify-between gap-4 rounded-lg border px-3 py-2.5",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:s("Load project harness assets")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Also load skills from .claude/.codex/.cursor and rule files (.cursorrules, .cursor/rules, .claude/rules) in the project")})]}),e.jsx(ce,{checked:u,onCheckedChange:d})]}),e.jsxs("div",{className:"flex items-end justify-between gap-4","data-settings-row":"skills.root",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"font-medium text-lg",children:[s("Skills"),e.jsx(ts,{note:s("The / menu updates right away, but open sessions keep the skills they loaded. Start a new session to load the change.")}),t.length>0&&e.jsxs("span",{className:"ml-2 font-normal text-muted-foreground text-xs",children:[s("{{enabled}}/{{total}} enabled",{enabled:b,total:t.length}),e.jsx(Mt,{tokens:N})]})]}),e.jsx("p",{className:"text-muted-foreground text-sm",children:s("Skills registered by reference; files stay in their original location")})]}),e.jsxs(y,{variant:"outline",size:"sm",onClick:()=>p(!0),children:[e.jsx(It,{className:"mr-1.5 h-4 w-4"}),s("Import from local apps")]})]}),t.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx(_o,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:s("No skills yet")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:s("Import skills from Claude Code, Codex or Cursor to get started")})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx(bo,{query:c,onQueryChange:f,placeholder:s("Filter skills..."),allSelected:j.allSelected,someSelected:j.someSelected,onToggleSelectAll:j.toggleAll,onEnable:()=>a(j.selectedIds,!0),onDisable:()=>a(j.selectedIds,!1),selectDisabled:m.length===0,actionDisabled:j.selectedIds.length===0}),m.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:m.map(S=>e.jsxs("div",{className:"group flex items-center justify-between gap-3 rounded-md px-3 py-2 transition-colors hover:bg-accent/50","data-settings-row":`skills.${S.id}`,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(Le,{checked:j.isSelected(S.id),onCheckedChange:M=>j.toggleOne(S.id,M)}),e.jsx("span",{className:H("shrink-0 font-medium text-sm",!S.enabled&&"text-muted-foreground line-through"),children:S.name}),e.jsx(ie,{variant:"secondary",className:"shrink-0 text-[11px]",children:S.source}),e.jsx("span",{className:"min-w-0 truncate text-muted-foreground text-xs",children:S.description||S.path})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(Et,{row:k.rows[S.id],pending:k.pending&&!k.rows[S.id]}),e.jsx(ce,{checked:S.enabled,onCheckedChange:M=>n(S.id,{enabled:M})}),e.jsx(y,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity hover:text-destructive group-hover:opacity-100",onClick:()=>r(S.id),children:e.jsx(Re,{className:"h-3.5 w-3.5"})})]})]},S.id))})]}),e.jsx($n,{kind:"skill",open:x,onOpenChange:p})]})}const Ar=[10,15,30,60,120,300];function Nf(){const{t:s}=R(),[t,n]=l.useState([]),[a,r]=l.useState(!1),[o,i]=l.useState(null),[u,d]=l.useState(""),[x,p]=l.useState(""),[c,f]=l.useState(""),[m,h]=l.useState(""),[j,b]=l.useState("key"),[A,k]=l.useState(""),[N,S]=l.useState(!1),[M,V]=l.useState(null),[E,L]=l.useState(null),[P,C]=l.useState(null),[I,W]=l.useState(null),[J,w]=l.useState(!1),z=l.useCallback(()=>{window.electronAPI.sshConnections.list().then(n)},[]);l.useEffect(()=>{z()},[z]);const G=()=>{i(null),d(""),p(""),f(""),h(""),b("key"),k(""),L(null),r(!0)},B=$=>{i($),d($.name),p($.host),f($.user??""),h($.port?String($.port):""),b($.auth),k(""),L(null),r(!0)},U=async $=>{$.preventDefault(),S(!0),L(null);const oe=m.trim()?Number(m):void 0,_=await window.electronAPI.sshConnections.upsert({...o?{id:o.id}:{},name:u.trim(),host:x.trim(),...c.trim()?{user:c.trim()}:{},...oe&&Number.isInteger(oe)?{port:oe}:{},auth:j,...j==="password"&&A?{password:A}:{}});if(S(!1),!_.ok){L(_.error);return}r(!1),z()},re=async $=>{const oe=await window.electronAPI.sshConnections.delete($);if(!oe.ok){C(oe.error);return}C(null),z()},F=async($,oe=!0)=>{V($),C(null);const _=await window.electronAPI.sshConnections.test($);if(V(null),!_.ok){const le=t.find(O=>O.id===$),de=Bd(_,le);if(de&&oe){W({id:$,challenge:de});return}}C(_.ok?s("SSH connection succeeded"):_.error)},ee=async()=>{if(!I)return;w(!0);const $=I.id,oe=await window.electronAPI.sshConnections.trustHost($);if(w(!1),W(null),!oe.ok){C(oe.error||s("Could not save host key."));return}await F($,!1)};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-end justify-between gap-4","data-settings-row":"ssh.root",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-lg font-medium",children:[s("SSH"),e.jsx(ts,{note:s("The file panel and terminal use the change right away. Agents in open sessions keep the previous connection settings.")})]}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:s("Saved hosts for remote projects. Passwords stay in the system keychain.")})]}),e.jsxs(y,{size:"sm",onClick:G,children:[e.jsx(Pe,{className:"h-4 w-4"}),s("Add connection")]})]}),P&&e.jsx("p",{className:"text-sm text-muted-foreground",children:P}),e.jsxs("ul",{className:"divide-y rounded-lg border",children:[t.length===0&&e.jsx("li",{className:"px-3 py-6 text-sm text-muted-foreground",children:s("No SSH connections yet")}),t.map($=>e.jsxs("li",{className:"flex items-center gap-2 px-3 py-2","data-settings-row":`ssh.${$.id}`,children:[e.jsxs("button",{type:"button",className:"min-w-0 flex-1 text-left",onClick:()=>B($),children:[e.jsx("div",{className:"truncate text-sm font-medium",children:$.name}),e.jsxs("div",{className:"truncate text-xs text-muted-foreground",children:[$.user?`${$.user}@`:"",$.host,$.port?`:${$.port}`:""," ·"," ",$.auth==="password"?s("Password"):s("Key / agent")]})]}),e.jsx(y,{size:"sm",variant:"outline",disabled:M===$.id,onClick:()=>{F($.id)},children:M===$.id?e.jsx(Ae,{className:"h-4 w-4 animate-spin"}):s("Test")}),e.jsx(y,{size:"icon-sm",variant:"ghost",onClick:()=>{re($.id)},children:e.jsx(Re,{className:"h-4 w-4"})})]},$.id))]}),e.jsx(kf,{}),e.jsx(ve,{open:a,onOpenChange:r,children:e.jsx(be,{className:"max-w-md",children:e.jsxs("form",{onSubmit:$=>{U($)},className:"flex flex-col",children:[e.jsx(ye,{children:e.jsx(we,{children:s(o?"Edit SSH connection":"Add SSH connection")})}),e.jsxs(Ne,{className:"space-y-3",children:[e.jsxs(ue,{children:[e.jsx(me,{children:s("Name")}),e.jsx(Q,{value:u,onChange:$=>d($.target.value),required:!0})]}),e.jsxs(ue,{children:[e.jsx(me,{children:s("Host")}),e.jsx(Q,{value:x,onChange:$=>p($.target.value),placeholder:"example.com",required:!0})]}),e.jsxs(ue,{children:[e.jsx(me,{children:s("User (optional)")}),e.jsx(Q,{value:c,onChange:$=>f($.target.value)})]}),e.jsxs(ue,{children:[e.jsx(me,{children:s("Port (optional)")}),e.jsx(Q,{value:m,onChange:$=>h($.target.value),placeholder:"22"})]}),e.jsxs(ue,{children:[e.jsx(me,{children:s("Authentication")}),e.jsxs(se,{items:[{value:"key",label:s("Key / agent")},{value:"password",label:s("Password")}],value:j,onValueChange:$=>b($),children:[e.jsx(te,{className:"w-full",children:e.jsx(ne,{})}),e.jsxs(ae,{zIndex:ls.DROPDOWN_IN_MODAL,children:[e.jsx(Z,{value:"key",children:s("Key / agent")}),e.jsx(Z,{value:"password",children:s("Password")})]})]})]}),j==="password"&&e.jsxs(ue,{children:[e.jsx(me,{children:o?.hasPassword?s("Password (leave blank to keep)"):s("Password")}),e.jsx(Q,{type:"password",value:A,onChange:$=>k($.target.value),required:!o?.hasPassword})]}),E&&e.jsx("p",{className:"text-sm text-destructive",children:E})]}),e.jsxs(Ie,{children:[e.jsx(y,{type:"button",variant:"outline",size:"sm",onClick:()=>r(!1),children:s("Cancel")}),e.jsx(y,{type:"submit",size:"sm",disabled:N,children:s("Save")})]})]})})}),e.jsx(Fd,{challenge:I?.challenge??null,busy:J,onTrust:()=>{ee()},onDismiss:()=>!J&&W(null)})]})}function kf(){const{t:s}=R(),t=g(a=>a.sshTimeoutSeconds),n=g(a=>a.setSshTimeoutSeconds);return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"ssh.timeout",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s("SSH timeout")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Time limit for connection tests, loading remote AGENTS.md, remote folder browsing and file panel actions. Agent tool commands are not affected.")})]}),e.jsxs(se,{items:Object.fromEntries(Ar.map(a=>[String(a),`${a}s`])),value:String(t),onValueChange:a=>n(Number(a)),children:[e.jsx(te,{className:"w-24",children:e.jsx(ne,{})}),e.jsx(ae,{children:Ar.map(a=>e.jsx(Z,{value:String(a),children:`${a}s`},a))})]})]})}const Cf={memory:"memory",workflows:"workflow"},pi=["bots","botTemplates"],fi=["secretary"],Sf=[{id:"app",label:"Application",categories:["general","appearance","shortcuts","privacy"]},{id:"agent",label:"Models & agents",categories:["providers","presets","agents","instructions","memory"]},{id:"extensions",label:"Tools & extensions",categories:["tools","workflows","skills","mcp","plugins"]},{id:"connections",label:"Connections",categories:["phone","ssh"]},{id:"system",label:"System",categories:["usage","resources","experimental","bots","botTemplates","secretary"]}];function If(s){const t=new Map(s.map(n=>[n.id,n]));return Sf.flatMap(n=>{const a=n.categories.flatMap(r=>{const o=t.get(r);return o?[o]:[]});return a.length>0?[{id:n.id,label:n.label,items:a}]:[]})}function gi(s,t,n=!1,a=!1){if(fi.includes(s))return a;if(pi.includes(s))return n;if(s==="memory"&&a)return!0;const r=Cf[s];return!r||!t.includes(r)}function Af(s,t,n=!1,a=!1){return s.filter(r=>gi(r.id,t,n,a))}function Ef(s,t,n=!1,a=!1){return gi(s,t,n,a)?s:pi.includes(s)||fi.includes(s)?"experimental":"tools"}function Mf(s,t,n,a){const r=n.trim();if(!r)return s.map(d=>({...d,hits:[]}));const o=Ud([...t,...s.map(d=>({id:`${d.id}.root`,category:d.id,title:d.label}))],r,{translate:a,limit:Number.POSITIVE_INFINITY}),i=new Set,u=new Map;for(const d of o){if(i.add(d.category),d.id.endsWith(".root"))continue;const x=u.get(d.category);x?x.push(d):u.set(d.category,[d])}return s.flatMap(d=>i.has(d.id)?[{...d,hits:u.get(d.id)??[]}]:[])}const Pf=[1,7,30,90],Er=640,mt=180,Mr=8,Pr=18,Tf=.3,Rf=2;function Of(s){const[,t,n]=s.split("-");return`${Number(t)}/${Number(n)}`}const Df=[{id:"cache",cls:"fill-foreground/15",swatch:"bg-foreground/15"},{id:"input",cls:"fill-foreground/45",swatch:"bg-foreground/45"},{id:"output",cls:"fill-foreground",swatch:"bg-foreground"}];function Lf({daily:s}){const{t}=R(),[n,a]=l.useState("tokens"),[r,o]=l.useState(null),[i,u]=l.useState({output:!0,input:!0,cache:!0}),d=k=>{u(N=>{const S={...N,[k]:!N[k]};return!S.output&&!S.input&&!S.cache?N:S})},x=s.map(k=>n==="cost"?k.cost??0:(i.output?k.output:0)+(i.input?k.input:0)+(i.cache?k.cache:0)),p=Math.max(0,...x),c=Math.max(1,s.length),f=Er/c,m=Math.min(f*(1-Tf),64),h=mt-Mr-Pr,j=k=>p>0?k/p*h:0,b=Math.max(1,Math.ceil(c/12)),A=r!==null?s[r]:null;return e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-sm font-medium",children:t("Daily trend")}),e.jsxs("div",{className:"flex items-center gap-3",children:[n==="tokens"&&e.jsxs("div",{className:"flex items-center gap-3 text-[11px] text-muted-foreground",children:[e.jsx(sn,{className:"bg-foreground",label:t("Output"),pressed:i.output,onClick:()=>d("output")}),e.jsx(sn,{className:"bg-foreground/45",label:t("Input"),pressed:i.input,onClick:()=>d("input")}),e.jsx(sn,{className:"bg-foreground/15",label:t("Cache"),pressed:i.cache,onClick:()=>d("cache")})]}),e.jsx(zf,{value:n,onChange:a})]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"pointer-events-none absolute left-0 top-0 font-mono text-[10px] text-muted-foreground",children:n==="tokens"?qe(p):wt(p>0?p:null)}),A&&e.jsxs("div",{className:"pointer-events-none absolute right-0 top-0 rounded bg-popover px-2 py-1 font-mono text-[11px] text-popover-foreground shadow-sm ring-1 ring-border",children:[A.day,n==="tokens"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[t("Output")," ",qe(A.output)]}),e.jsxs("div",{children:[t("Input")," ",qe(A.input)]}),e.jsxs("div",{children:[t("Cache")," ",qe(A.cache)]})]}):e.jsxs(e.Fragment,{children:[" · ",wt(A.cost)]})]}),e.jsx("svg",{viewBox:`0 0 ${Er} ${mt}`,className:"mt-4 block h-[180px] w-full",role:"img","aria-label":t("Daily trend"),onMouseLeave:()=>o(null),children:s.map((k,N)=>{const S=N*f+(f-m)/2,M=mt-Pr,V=n==="tokens"?Df.filter(L=>i[L.id]).map(L=>({v:k[L.id],cls:L.cls})):[{v:k.cost??0,cls:"fill-emerald-600 dark:fill-emerald-500"}];let E=M;return e.jsxs("g",{onMouseEnter:()=>o(N),children:[e.jsx("rect",{x:S,y:Mr,width:m,height:h,className:"fill-transparent"}),V.map(L=>{const P=L.v>0?Math.max(Rf,j(L.v)):0;return E-=P,e.jsx("rect",{x:S,y:E,width:m,height:P,rx:1,className:H(L.cls,r===N&&"opacity-80")},L.cls)}),N%b===0&&e.jsx("text",{x:S+m/2,y:mt-4,textAnchor:"middle",className:"fill-muted-foreground font-mono text-[10px]",children:Of(k.day)})]},k.day)})})]})]})}function sn({className:s,label:t,pressed:n,onClick:a}){return e.jsxs("button",{type:"button","aria-pressed":n,onClick:a,className:H("flex items-center gap-1 rounded px-0.5 transition-opacity",n?"opacity-100":"opacity-40"),children:[e.jsx("span",{className:H("inline-block h-2.5 w-2.5 rounded-sm",s)}),t]})}function zf({value:s,onChange:t}){const{t:n}=R(),a=[{id:"tokens",label:n("Token")},{id:"cost",label:n("Cost")}];return e.jsx("div",{className:"flex rounded-md bg-muted p-0.5",children:a.map(r=>e.jsx("button",{type:"button",onClick:()=>t(r.id),className:H("rounded px-2 py-0.5 text-[11px] transition-colors",s===r.id?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:r.label},r.id))})}const tn=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],Tr=Array.from({length:24},(s,t)=>String(t).padStart(2,"0")),kt=["bg-foreground/[0.06]","bg-foreground/20","bg-foreground/40","bg-foreground/60","bg-foreground/80","bg-foreground"];function _f(s,t){return s<=0||t<=0?0:1+Math.min(kt.length-2,Math.floor(s/t*(kt.length-1)))}function Ff({heatmap:s}){const{t}=R(),n=Math.max(0,...s.flat());return e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[e.jsx("span",{className:"text-sm font-medium",children:t("Activity by hour")}),e.jsxs("div",{className:"flex items-center gap-1 text-[10px] text-muted-foreground",children:[e.jsx("span",{children:t("Less")}),kt.map(a=>e.jsx("span",{className:H("inline-block h-2.5 w-2.5 rounded-[2px]",a)},a)),e.jsx("span",{children:t("More")})]})]}),e.jsxs("div",{className:"grid grid-cols-[28px_1fr] gap-x-2 gap-y-1",children:[s.map((a,r)=>e.jsxs("div",{className:"contents",children:[e.jsx("span",{className:"self-center text-[10px] text-muted-foreground",children:t(tn[r])}),e.jsx("div",{className:"grid grid-cols-24 gap-[3px]",children:Tr.map((o,i)=>e.jsx("span",{title:`${t(tn[r])} ${o}:00 · ${qe(a[i]??0)}`,className:H("aspect-square rounded-[2px]",kt[_f(a[i]??0,n)])},o))})]},tn[r])),e.jsx("span",{}),e.jsx("div",{className:"grid grid-cols-24 font-mono text-[10px] text-muted-foreground",children:Tr.map((a,r)=>e.jsx("span",{className:H(r%3!==0&&"invisible"),children:a},a))})]})]})}function nn({title:s,countLabel:t,rows:n,emptyLabel:a,limit:r=8}){const{t:o}=R(),[i,u]=l.useState(!1),d=n.reduce((c,f)=>c+f.tokens,0),x=n.length>r,p=x&&!i?n.slice(0,r):n;return e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[e.jsx("span",{className:"text-sm font-medium",children:s}),x&&e.jsx("span",{className:"text-[11px] text-muted-foreground",children:i?o("{{total}} items",{total:n.length}):o("Top {{count}} of {{total}}",{count:r,total:n.length})})]}),p.length===0?e.jsx("p",{className:"py-6 text-center text-xs text-muted-foreground",children:a}):e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-[11px] text-muted-foreground",children:[e.jsx("th",{className:"pb-2 text-left font-normal",children:o("Name")}),e.jsx("th",{className:"pb-2 text-right font-normal",children:o("Cost")}),e.jsx("th",{className:"pb-2 text-right font-normal",children:o("Token")}),e.jsx("th",{className:"pb-2 text-right font-normal",children:t})]})}),e.jsx("tbody",{children:p.map(c=>{const f=d>0?c.tokens/d:0;return e.jsxs("tr",{className:"border-t border-border/60",children:[e.jsxs("td",{className:"py-2 pr-3",children:[e.jsx("div",{className:"truncate",title:c.name,children:c.name||o("(no project)")}),e.jsx("div",{className:"mt-1 h-1 w-full rounded-full bg-foreground/[0.06]",children:e.jsx("div",{className:"h-1 rounded-full bg-foreground/70",style:{width:`${Math.max(1,f*100)}%`}})})]}),e.jsx("td",{className:H("py-2 text-right font-mono tabular-nums",c.cost===null&&"text-muted-foreground"),children:wt(c.cost)}),e.jsxs("td",{className:"py-2 text-right font-mono tabular-nums",children:[qe(c.tokens),e.jsxs("span",{className:"ml-1 text-muted-foreground",children:[(f*100).toFixed(0),"%"]})]}),e.jsx("td",{className:"py-2 text-right font-mono tabular-nums",children:c.count})]},c.key)})})]}),x&&e.jsx(y,{variant:"ghost",size:"xs",className:"mt-2 w-full text-muted-foreground",onClick:()=>u(c=>!c),children:o(i?"Collapse":"Show all")})]})}function Bf({value:s,className:t}){const n=s.split("");return e.jsx("span",{className:H("t-digit-group is-animating",t),children:n.map((a,r)=>e.jsx("span",{className:"t-digit","data-stagger":r===n.length-2?"1":r===n.length-1?"2":void 0,children:a},`${r}:${a}`))},s)}const Uf={default:"text-foreground",success:"text-emerald-600 dark:text-emerald-400",info:"text-sky-600 dark:text-sky-400",muted:"text-muted-foreground"};function ms({label:s,value:t,delta:n,tone:a="default"}){return e.jsxs("div",{className:"min-w-0 overflow-hidden rounded-lg border bg-card px-4 py-3",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[e.jsx("span",{className:"min-w-0 text-xs text-muted-foreground",children:s}),n&&e.jsx("span",{className:"shrink-0 font-mono text-[11px] tabular-nums text-muted-foreground",children:n})]}),e.jsx("div",{className:H("mt-1 truncate font-mono text-xl font-semibold leading-tight tabular-nums sm:text-2xl",Uf[a]),title:t,children:e.jsx(Bf,{value:t})})]})}const an={input:0,output:0,cacheRead:0,cacheWrite:0},Ct=["input","output","cacheRead","cacheWrite"];function rn(s){return{input:String(s.input),output:String(s.output),cacheRead:String(s.cacheRead),cacheWrite:String(s.cacheWrite)}}function $f(s){return Gd({id:Object.fromEntries(Ct.map(n=>[n,Number(s[n])]))}).id??null}function Vf(s){return s===void 0?"—":String(s)}function Rr({rows:s,editing:t,draft:n,overrides:a,onDraft:r,onEdit:o,onSave:i}){const{t:u}=R();return e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-[11px] text-muted-foreground",children:[e.jsx("th",{className:"pb-2 text-left font-normal",children:u("Name")}),Ct.map(d=>e.jsx("th",{className:"pb-2 text-right font-normal",children:d},d)),e.jsx("th",{className:"w-14 pb-2"})]})}),e.jsx("tbody",{children:s.map(d=>{const x=t===d.model,p=d.model in a;return e.jsxs("tr",{className:"border-t border-border/60",children:[e.jsxs("td",{className:"py-1.5 pr-3 align-middle",children:[e.jsx("span",{className:"font-mono text-xs",title:d.model,children:d.model}),p&&e.jsx("span",{className:"ml-1.5 text-[10px] text-muted-foreground",children:u("Custom")})]}),Ct.map(c=>e.jsx("td",{className:"py-1.5 text-right align-middle",children:x?e.jsx(Q,{size:"sm",inputMode:"decimal",className:"ml-auto w-16 [&_input]:text-right",value:n[c],onChange:f=>r({...n,[c]:f.target.value})}):e.jsx("span",{className:H("font-mono tabular-nums",d.pricing==null&&"text-muted-foreground"),children:Vf(d.pricing?.[c])})},c)),e.jsx("td",{className:"py-1.5 text-right align-middle",children:x?e.jsx(y,{size:"sm",className:"h-6 px-1.5 text-[11px]",onClick:()=>i(d.model),children:u("Save")}):e.jsx(y,{variant:"ghost",size:"sm",className:"h-6 px-1.5 text-[11px]",onClick:()=>o(d.model,d.pricing),children:u("Edit")})})]},d.model)})})]})}function Kf({models:s,catalog:t,onChanged:n}){const{t:a}=R(),r=g(w=>w.usageModelPricing),o=Qs(),i=g(w=>w.setUsageModelPricing),[u,d]=l.useState(!1),[x,p]=l.useState(!1),[c,f]=l.useState(null),[m,h]=l.useState(rn(an)),[j,b]=l.useState(null),[A,k]=l.useState(!1),[N,S]=l.useState(""),[M,V]=l.useState(""),E=new Set(s.map(w=>w.model)),L=new Set;for(const w of o)for(const z of w.models)L.add(z.id);for(const w of Object.keys(r))L.add(w);const P=M.trim().toLowerCase(),C=s.filter(w=>!P||w.model.toLowerCase().includes(P)).map(w=>({model:w.model,pricing:w.pricing})),I=[...L].filter(w=>!E.has(w)&&(!P||w.toLowerCase().includes(P))).sort().map(w=>({model:w,pricing:r[w]??t[w]??null})),W=(w,z)=>{k(!1),f(w),h(rn(z??an)),b(null)},J=w=>{const z=$f(m);return!z||!i(w,z)?(b(a("Enter a model id and non-negative rates.")),!1):(b(null),f(null),k(!1),S(""),n(),!0)};return e.jsxs($d,{open:u,onOpenChange:d,className:"rounded-lg border bg-card",children:[e.jsxs(Vd,{className:"flex w-full items-center justify-between gap-3 px-4 py-3 text-left",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-medium",children:a("Unit prices")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("Rates used for cost estimates ($/M tokens).")})]}),e.jsx(bt,{className:H("h-4 w-4 shrink-0 text-muted-foreground transition-transform",u&&"rotate-180")})]}),e.jsx(Kd,{children:e.jsxs("div",{className:"space-y-3 border-t px-4 py-3",children:[e.jsx(Q,{size:"sm",value:M,onChange:w=>V(w.target.value),placeholder:a("Search models")}),C.length===0&&!A?e.jsx("p",{className:"text-xs text-muted-foreground",children:a(P?"No matching models":"No usage in this period")}):e.jsx(Rr,{rows:C,editing:c,draft:m,overrides:r,onDraft:h,onEdit:W,onSave:J}),I.length>0&&(x||!!P)&&e.jsx(Rr,{rows:I,editing:c,draft:m,overrides:r,onDraft:h,onEdit:W,onSave:J}),A?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-end gap-2",children:[e.jsxs("label",{className:"grid min-w-36 gap-1 text-[11px] text-muted-foreground",children:[a("Model id"),e.jsx(Q,{size:"sm",value:N,onChange:w=>S(w.target.value),placeholder:"qwen-3.8-27b"})]}),Ct.map(w=>e.jsxs("label",{className:"grid min-w-16 gap-1 text-[11px] text-muted-foreground",children:[w,e.jsx(Q,{size:"sm",inputMode:"decimal",value:m[w],onChange:z=>h(G=>({...G,[w]:z.target.value}))})]},w))]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(y,{size:"sm",className:"h-7",onClick:()=>J(N),children:a("Save")}),e.jsx(y,{variant:"ghost",size:"sm",className:"h-7",onClick:()=>{k(!1),S(""),b(null)},children:a("Cancel")})]})]}):e.jsxs("div",{className:"flex justify-end gap-2",children:[I.length>0&&e.jsxs(y,{variant:"ghost",size:"sm",className:"h-7 text-muted-foreground",onClick:()=>p(w=>!w),children:[a("Show all"),e.jsx(bt,{className:H("ml-1 h-3.5 w-3.5 transition-transform",x&&"rotate-180")})]}),e.jsx(y,{variant:"ghost",size:"sm",className:"h-7",onClick:()=>{k(!0),h(rn(an)),b(null)},children:a("Add")})]}),j&&e.jsx("p",{className:"text-xs text-destructive",children:j})]})})]})}const Gf={1:"Today",7:"7D",30:"30D",90:"90D"};function Wf(){const{t:s}=R(),[t,n]=l.useState(7),[a,r]=l.useState(null),o=g(h=>h.botModeEnabled),[i,u]=l.useState(null),[d,x]=l.useState(null),[p,c]=l.useState(!1),f=l.useRef(0),m=l.useCallback(async h=>{const j=++f.current;c(!0);const[b,A]=await Promise.all([window.electronAPI.usage.summary(h),o?window.electronAPI.bots.usageSummary(h).catch(()=>null):null]);j===f.current&&(c(!1),u(A?.ok?A.rows:null),b.ok?(r(b.summary),x(null)):(r(null),x(b.error)))},[o]);return l.useEffect(()=>{m(t)},[t,m]),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("Usage")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("Token usage across all local sessions; cost is estimated from catalog prices.")})]}),e.jsx(y,{variant:"ghost",size:"icon-sm",onClick:()=>{m(t)},disabled:p,"aria-label":s("Refresh"),children:e.jsx(cs,{className:H(p&&"animate-spin")})})]}),e.jsx(Hf,{value:t,onChange:n}),d&&e.jsx("p",{className:"text-sm text-destructive",children:d}),a&&e.jsxs(e.Fragment,{children:[e.jsx(qf,{totals:a.totals,previous:a.previous}),e.jsx(Lf,{daily:a.daily}),e.jsx(Ff,{heatmap:a.heatmap}),e.jsxs("div",{className:"grid gap-4 xl:grid-cols-2",children:[e.jsx(nn,{title:s("By model"),countLabel:s("Messages"),emptyLabel:s("No usage in this period"),rows:a.byModel.map(h=>({key:h.model,name:h.model,cost:h.cost,tokens:h.tokens,count:h.messages}))}),e.jsx(nn,{title:s("By project"),countLabel:s("Sessions"),emptyLabel:s("No usage in this period"),rows:a.byProject.map(h=>({key:h.project||"#",name:h.project,cost:h.cost,tokens:h.tokens,count:h.sessions}))})]}),o&&i&&e.jsx(nn,{title:s("By member"),countLabel:s("Sessions"),emptyLabel:s("No usage in this period"),rows:i.map(h=>({key:h.botId,name:h.name||s("Deleted member"),cost:h.cost,tokens:h.tokens,count:h.sessions}))}),a.unpricedModels.length>0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:s("No catalog price for: {{models}}. Their cost is not included.",{models:a.unpricedModels.join(", ")})})]}),e.jsx(Kf,{models:a?.byModel??[],catalog:a?.pricing??{},onChanged:()=>{m(t)}})]})}function Hf({value:s,onChange:t}){const{t:n}=R();return e.jsx("div",{className:"flex items-center gap-1.5",children:Pf.map(a=>e.jsx("button",{type:"button",onClick:()=>t(a),className:H("rounded-full px-3 py-1 font-mono text-xs transition-colors",s===a?"bg-foreground text-background":"bg-muted text-muted-foreground hover:text-foreground"),children:n(Gf[a])},a))})}function qf({totals:s,previous:t}){const{t:n}=R(),a=s.cacheRead+s.cacheWrite,r=t.cacheRead+t.cacheWrite;return e.jsxs("div",{className:"grid grid-cols-2 gap-3 md:grid-cols-4",children:[e.jsx(ms,{label:n("Estimated cost"),value:wt(s.cost),delta:ds(t.cost,s.cost),tone:"success"}),e.jsx(ms,{label:n("Total tokens"),value:qe(s.tokens),delta:ds(t.tokens,s.tokens)}),e.jsx(ms,{label:n("Input tokens"),value:qe(s.input),delta:ds(t.input,s.input)}),e.jsx(ms,{label:n("Output tokens"),value:qe(s.output),delta:ds(t.output,s.output)}),e.jsx(ms,{label:n("Cache tokens"),value:qe(a),delta:ds(r,a),tone:"muted"}),e.jsx(ms,{label:n("Active time"),value:Wd(s.activeMs),delta:ds(t.activeMs,s.activeMs),tone:"info"}),e.jsx(ms,{label:n("Sessions"),value:String(s.sessions),delta:ds(t.sessions,s.sessions)}),e.jsx(ms,{label:n("Messages"),value:s.messages.toLocaleString(),delta:ds(t.messages,s.messages)})]})}const Yf=32,Jf=/^[A-Za-z0-9][A-Za-z0-9_:-]{0,127}$/,Xf=/^[A-Za-z_][A-Za-z0-9_]{0,31}$/,Qf=/\{\{\s*(?:args\.([A-Za-z_][A-Za-z0-9_]{0,31})|(prev))\s*\}\}/g;function wn(s,t){if(typeof s!="string")return null;const n=s.trim();return n&&n.length<=t?n:null}function Zf(s,t){const n=[...new Set(s)].filter(a=>Xf.test(a)).map(a=>({kind:"arg",key:a,token:`{{args.${a}}}`}));return t>0&&n.push({kind:"prev",token:"{{prev}}"}),n}function eg(s,t,n,a){const r=Math.min(Math.max(t,0),s.length),o=Math.min(Math.max(n,r),s.length);return{text:s.slice(0,r)+a+s.slice(o),cursor:r+a.length}}function sg(s){if(!s||typeof s!="object"||Array.isArray(s))return null;const t=s,n=wn(t.label,80),a=wn(t.prompt,8e3),r=typeof t.agentType=="string"?t.agentType.trim():"";return!n||!a||r&&!Jf.test(r)?null:{label:n,agentType:r,prompt:a}}function tg(s){if(!s||typeof s!="object"||Array.isArray(s))return null;const t=s,n=wn(t.title,80);if(!n||!Array.isArray(t.steps)||t.steps.length===0)return null;const a=t.steps.map(sg);return a.every(r=>r!==null)?{title:n,steps:a}:null}function ng(s){if(!s||typeof s!="object"||Array.isArray(s))return null;const t=s.phases;if(!Array.isArray(t)||t.length===0)return null;const n=t.map(tg);return n.every(r=>r!==null)&&n.reduce((r,o)=>r+o.steps.length,0)<=Yf?{phases:n}:null}function ji(s){const t=[];let n=0;for(const a of s.matchAll(Qf))a.index>n&&t.push({kind:"text",text:s.slice(n,a.index)}),t.push(a[1]?{kind:"arg",key:a[1]}:{kind:"prev"}),n=a.index+a[0].length;return n<s.length&&t.push({kind:"text",text:s.slice(n)}),t}function ag(s){const t=ji(s).map(n=>n.kind==="text"?JSON.stringify(n.text):n.kind==="arg"?`String(args.${n.key} ?? '')`:"prev");return t.length>0?t.join(" + "):'""'}function rg({label:s,agentType:t,prompt:n}){const a=[`label: ${JSON.stringify(s)}`];return t&&a.push(`agentType: ${JSON.stringify(t)}`),` () => agent(${ag(n)}, { ${a.join(", ")} }),`}function vi(s){const t=["// Generated by the workflow designer. Editing this code detaches it from the designer.","const collect = (labels, outputs) =>"," labels.map((label, i) => '## ' + label + '\\n\\n' + (outputs[i] ?? '(failed)')).join('\\n\\n');","let prev = '';"];for(const n of s.phases){const a=JSON.stringify(n.steps.map(r=>r.label));t.push("",`await phase(${JSON.stringify(n.title)});`,`prev = collect(${a}, await parallel([`,...n.steps.map(rg),"]));")}return t.push("","return prev;",""),t.join(`
|
|
22
|
-
`)}async function og(s){const[t,n,a]=await Promise.all([pt(()=>import("./standalone-oyxre9MX.js"),[],import.meta.url),pt(()=>import("./babel-BktJt1uC.js"),[],import.meta.url),pt(()=>import("./estree-C_HWBWad.js"),[],import.meta.url)]);try{return{ok:!0,code:await t.format(s,{parser:"babel",plugins:[n,a],singleQuote:!0,printWidth:100,trailingComma:"es5"})}}catch(r){const o=r instanceof Error?r.message:String(r);return{ok:!1,error:o.split(`
|
|
23
|
-
`)[0]??o}}}const ig=32,qs=(s,t)=>Math.max(0,Math.min(s,t));function lg(s){return s.phases.reduce((t,n)=>t+n.steps.length,0)<ig}function cg(s,t,n){const a=s.phases.map((r,o)=>o===t?{...r,steps:[...r.steps,n]}:r);return{design:{phases:a},selection:{kind:"step",phase:t,step:(a[t]?.steps.length??1)-1}}}function dg(s,t,n){const a=qs(t,s.phases.length),r=[...s.phases];return r.splice(a,0,n),{design:{phases:r},selection:{kind:"phase",phase:a}}}function Or(s,t){const n=s.phases[t.phase];if(!n)return null;if(t.kind==="step"&&n.steps.length>1){const r=n.steps.filter((o,i)=>i!==t.step);return{design:{phases:s.phases.map((o,i)=>i===t.phase?{...o,steps:r}:o)},selection:{kind:"step",phase:t.phase,step:qs(t.step,r.length-1)}}}if(s.phases.length===1)return null;const a=s.phases.filter((r,o)=>o!==t.phase);return{design:{phases:a},selection:{kind:"phase",phase:qs(t.phase,a.length-1)}}}function Dr(s,t,n){const a=t+n;if(a<0||a>=s.phases.length||!s.phases[t])return{design:s,selection:{kind:"phase",phase:t}};const r=[...s.phases],[o]=r.splice(t,1);return o&&r.splice(a,0,o),{design:{phases:r},selection:{kind:"phase",phase:a}}}function ug(s,t){const n=qs(t.phase,s.phases.length-1);if(t.kind==="phase")return{kind:"phase",phase:n};const a=s.phases[n]?.steps.length??1;return{kind:"step",phase:n,step:qs(t.step,a-1)}}const on="__default__",Lr=(s="scout")=>({label:"",agentType:s,prompt:""});function mg({value:s,tokens:t,args:n,onChange:a}){const{t:r}=R(),o=l.useRef(null),i=()=>o.current?.querySelector("textarea")??null,u=x=>{const p=i(),c=s.length,f=eg(s,p?.selectionStart??c,p?.selectionEnd??c,x);a(f.text),requestAnimationFrame(()=>{p?.focus(),p?.setSelectionRange(f.cursor,f.cursor)})},d=x=>x.kind==="prev"?r("Previous phase output"):n.find(p=>p.key.trim()===x.key)?.label.trim()||x.key;return e.jsxs("div",{ref:o,className:"space-y-1",children:[e.jsx(Ze,{rows:5,className:"text-xs",placeholder:r("Prompt"),value:s,onChange:x=>a(x.target.value)}),e.jsxs(Oo,{children:[e.jsxs(Do,{disabled:t.length===0,className:"inline-flex h-6 items-center gap-1 rounded-md px-1.5 text-muted-foreground text-xs hover:bg-accent hover:text-foreground disabled:pointer-events-none disabled:opacity-50",children:[e.jsx(Yd,{className:"h-3.5 w-3.5"}),r("Insert argument")]}),e.jsx(Lo,{align:"start",zIndex:ls.DROPDOWN_IN_MODAL,finalFocus:i,children:t.map(x=>e.jsxs(zo,{onClick:()=>u(x.token),children:[d(x),e.jsx("span",{className:"ml-auto pl-4 font-mono text-muted-foreground text-xs",children:x.token})]},x.token))})]})]})}const zr=(s,t,n,a)=>{const r=Math.max((n-s)/2,8);return`M${s},${t} C${s+r},${t} ${n-r},${a} ${n},${a}`};function xg(s,t){const[n,a]=l.useState([]);return l.useLayoutEffect(()=>{const r=s.current;if(!r)return;const o=()=>{const u=r.getBoundingClientRect(),d=r.offsetWidth?u.width/r.offsetWidth:1,x=f=>{const m=r.querySelector(f)?.getBoundingClientRect();return m?{left:(m.left-u.left)/d,right:(m.right-u.left)/d,y:(m.top-u.top+m.height/2)/d}:null},p=(f,m)=>f<0||f>=t.phases.length?[`[data-node="${m}"]`]:(t.phases[f]?.steps??[]).map((h,j)=>`[data-node="s-${f}-${j}"]`),c=[];for(let f=0;f<=t.phases.length;f++){const m=x(`[data-gap="${f}"]`);if(m){for(const h of p(f-1,"start")){const j=x(h);j&&c.push({d:zr(j.right,j.y,m.left,m.y),arrow:!1})}for(const h of p(f,"end")){const j=x(h);j&&c.push({d:zr(m.right,m.y,j.left-2,j.y),arrow:!0})}}}a(c)};o();const i=new ResizeObserver(o);return i.observe(r),()=>i.disconnect()},[s,t]),n}function _r({node:s,icon:t,title:n,detail:a}){return e.jsxs("div",{"data-node":s,className:"flex w-24 shrink-0 flex-col items-center gap-0.5 rounded-full border bg-background px-3 py-1.5 text-center shadow-xs",children:[e.jsxs("span",{className:"flex items-center gap-1 font-medium text-xs",children:[t,n]}),e.jsx("span",{className:"w-full truncate text-[10px] text-muted-foreground",children:a})]})}function hg({prompt:s,args:t}){const{t:n}=R(),a=ji(s.trim());return a.length===0?e.jsx(e.Fragment,{children:n("No prompt yet")}):e.jsx(e.Fragment,{children:a.map((r,o)=>r.kind==="text"?e.jsx(l.Fragment,{children:r.text},o):e.jsx("span",{className:"rounded bg-primary/10 px-1 font-medium text-primary",children:r.kind==="prev"?n("Previous phase output"):t.find(i=>i.key.trim()===r.key)?.label.trim()||r.key},o))})}function pg({design:s,agentTypes:t,args:n,onChange:a}){const{t:r}=R(),[o,i]=l.useState({kind:"step",phase:0,step:0}),u=l.useRef(null),d=l.useId(),x=xg(u,s),p=s.phases,c=ug(s,o),f=p[c.phase],m=c.kind==="step"?f?.steps[c.step]:void 0,h=t.includes("scout")?"scout":"",j=n.map(E=>E.key.trim()).filter(Boolean),b=lg(s),A=Or(s,c)!==null,k=E=>{E&&(a(E.design),i(E.selection))},N=E=>a({phases:p.map((L,P)=>P===c.phase?{...L,...E}:L)}),S=E=>c.kind==="step"&&N({steps:(f?.steps??[]).map((L,P)=>P===c.step?{...L,...E}:L)}),M=E=>{const L=E&&!t.includes(E)?[...t,E]:t;return[{value:on,label:r("Default (worker)")},...L.map(P=>({value:P,label:P}))]},V=E=>e.jsx("div",{className:"flex w-10 shrink-0 items-center justify-center self-stretch",children:e.jsx("button",{type:"button","data-gap":E,disabled:!b,"aria-label":r("Insert phase here"),title:r("Insert phase here"),onClick:()=>k(dg(s,E,{title:"",steps:[Lr(h)]})),className:"relative z-30 flex h-5 w-5 items-center justify-center rounded-full border bg-background text-muted-foreground transition-colors hover:border-primary hover:text-primary disabled:pointer-events-none disabled:opacity-50",children:e.jsx(Pe,{className:"h-3 w-3"})})});return e.jsxs("div",{className:"w-full space-y-2",children:[e.jsx("div",{className:"overflow-x-auto rounded-lg border bg-muted/30",children:e.jsxs("div",{ref:u,className:"relative flex w-max min-w-full items-center justify-center px-3 py-5",children:[e.jsxs("svg",{"aria-hidden":!0,className:"pointer-events-none absolute inset-0 z-20 h-full w-full overflow-visible text-muted-foreground/50",children:[e.jsx("defs",{children:e.jsx("marker",{id:d,viewBox:"0 0 6 6",refX:"5",refY:"3",markerWidth:"6",markerHeight:"6",orient:"auto",children:e.jsx("path",{d:"M0,0 L6,3 L0,6 z",fill:"currentColor"})})}),x.map(E=>e.jsx("path",{d:E.d,fill:"none",stroke:"currentColor",strokeWidth:1.25,markerEnd:E.arrow?`url(#${d})`:void 0},E.d))]}),e.jsx(_r,{node:"start",icon:e.jsx(Hd,{className:"h-3 w-3"}),title:r("Start"),detail:j.length>0?j.join(", "):r("No arguments")}),p.map((E,L)=>e.jsxs(l.Fragment,{children:[V(L),e.jsxs("div",{className:H("flex w-44 shrink-0 flex-col gap-1.5 rounded-xl border border-dashed bg-background/60 p-2",c.kind==="phase"&&c.phase===L&&"border-primary border-solid"),children:[e.jsxs("button",{type:"button",onClick:()=>i({kind:"phase",phase:L}),className:H("flex min-w-0 items-center gap-1 rounded px-1 text-left text-[11px] hover:text-foreground",E.title.trim()?"text-muted-foreground":"text-destructive"),children:[e.jsx("span",{className:"shrink-0",children:r("Phase {{n}}",{n:L+1})}),e.jsx("span",{className:"truncate font-medium text-foreground",children:E.title.trim()||r("Untitled phase")})]}),E.steps.map((P,C)=>{const I=c.kind==="step"&&c.phase===L&&c.step===C,W=!P.label.trim()||!P.prompt.trim();return e.jsxs("button",{type:"button","data-node":`s-${L}-${C}`,onClick:()=>i({kind:"step",phase:L,step:C}),className:H("block w-full rounded-lg border bg-background px-2.5 py-1.5 text-left shadow-xs transition-colors hover:border-primary/60",I&&"border-primary ring-2 ring-primary/20",W&&!I&&"border-destructive/50"),children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"truncate font-medium text-xs",children:P.label.trim()||r("Untitled step")}),e.jsx("span",{className:"ml-auto shrink-0 rounded bg-muted px-1 text-[10px] text-muted-foreground",children:P.agentType||"worker"})]}),e.jsx("span",{className:"mt-0.5 line-clamp-2 break-words text-[11px] text-muted-foreground",children:e.jsx(hg,{prompt:P.prompt,args:n})})]},C)}),e.jsxs("button",{type:"button",disabled:!b,onClick:()=>k(cg(s,L,Lr(h))),className:"flex items-center justify-center gap-1 rounded-lg border border-dashed py-1 text-[11px] text-muted-foreground transition-colors hover:border-primary hover:text-primary disabled:pointer-events-none disabled:opacity-50",children:[e.jsx(Pe,{className:"h-3 w-3"}),r("Parallel step")]})]})]},L)),V(p.length),e.jsx(_r,{node:"end",icon:e.jsx(Pu,{className:"h-3 w-3"}),title:r("Result"),detail:r("Last phase output")})]})}),e.jsxs("div",{className:"space-y-2 rounded-lg border p-3",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"font-medium text-xs",children:c.kind==="phase"?r("Phase {{n}}",{n:c.phase+1}):r("Phase {{n}} · Step {{m}}",{n:c.phase+1,m:c.step+1})}),e.jsxs("span",{className:"ml-auto flex items-center",children:[c.kind==="phase"&&e.jsxs(e.Fragment,{children:[e.jsx(y,{variant:"ghost",size:"icon-xs","aria-label":r("Move left"),disabled:c.phase===0,onClick:()=>k(Dr(s,c.phase,-1)),children:e.jsx(Co,{})}),e.jsx(y,{variant:"ghost",size:"icon-xs","aria-label":r("Move right"),disabled:c.phase===p.length-1,onClick:()=>k(Dr(s,c.phase,1)),children:e.jsx(qd,{})})]}),e.jsx(y,{variant:"ghost",size:"icon-xs","aria-label":r("Delete"),disabled:!A,onClick:()=>k(Or(s,c)),children:e.jsx(Re,{})})]})]}),c.kind==="phase"||!m?e.jsx(Q,{size:"sm",placeholder:r("Phase title"),value:f?.title??"",onChange:E=>N({title:E.target.value})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Q,{size:"sm",className:"min-w-0 flex-1",placeholder:r("Label"),value:m.label,onChange:E=>S({label:E.target.value})}),e.jsxs(se,{items:M(m.agentType),value:m.agentType||on,onValueChange:E=>S({agentType:E===on?"":String(E??"")}),children:[e.jsx(te,{size:"sm",className:"w-36 min-w-0 shrink-0",children:e.jsx(ne,{})}),e.jsx(ae,{zIndex:ls.DROPDOWN_IN_MODAL,children:M(m.agentType).map(E=>e.jsx(Z,{value:E.value,children:E.label},E.value))})]})]}),e.jsx(mg,{value:m.prompt,tokens:Zf(j,c.phase),args:n,onChange:E=>S({prompt:E})})]})]}),e.jsx("p",{className:"text-muted-foreground text-xs",children:r("Click a node to edit it. Steps in a column run in parallel; columns run from left to right.")})]})}const Nn={phases:[{title:"Investigate",steps:[{label:"code",agentType:"scout",prompt:"Investigate {{args.topic}} in the source code."},{label:"tests",agentType:"scout",prompt:"Investigate {{args.topic}} in the tests."}]},{title:"Summarize",steps:[{label:"summary",agentType:"scout",prompt:`Merge these findings about {{args.topic}} into one short report:
|
|
24
|
-
|
|
25
|
-
{{prev}}`}]}]},Fr={name:"",description:"",args:[{key:"topic",label:"Topic",required:!0}],design:Nn,script:vi(Nn)};function fg(s){return s.map(({key:t,label:n,default:a,required:r})=>({key:t.trim(),label:n.trim()||t.trim(),...a?.trim()?{default:a}:{},...r?{required:!0}:{}}))}function gg({target:s,onClose:t,onSaved:n}){const{t:a}=R(),[r,o]=l.useState(Fr),[i,u]=l.useState("design"),[d,x]=l.useState(0),p=l.useRef(null),[c,f]=l.useState(!1),[m,h]=l.useState(!1),[j,b]=l.useState(!1),[A,k]=l.useState(null),N=g(w=>w.disabledBuiltinAgentTypes),S=g(w=>w.agentTypes),M=l.useMemo(()=>[...Jd.map(w=>w.name).filter(w=>!N.includes(w)),...S.map(w=>w.name)],[N,S]);l.useEffect(()=>{if(k(null),s===null)return;if(p.current=null,x(z=>z+1),s==="new"){o(Fr),u("design");return}let w=!1;return f(!0),window.electronAPI.workflowPresets.read(s).then(z=>{if(!w)if(z){const{id:G,...B}=z;o(B),u(B.design?"design":"code"),x(U=>U+1)}else k(a("Failed to read content"))}).finally(()=>{w||f(!1)}),()=>{w=!0}},[s,a]);const V=w=>o(z=>({...z,...w})),E=(w,z)=>V({args:r.args.map((G,B)=>B===w?{...G,...z}:G)}),L=w=>V({design:w,script:vi(w)}),P=w=>{w!==r.script&&(r.design&&(p.current=r.design),o(z=>({...z,script:w,design:void 0})))},C=async()=>{b(!0);const w=await og(r.script);if(b(!1),!w.ok){k(a("Format failed: {{error}}",{error:w.error}));return}k(null),w.code!==r.script&&(P(w.code),x(z=>z+1))},I=!r.design||ng(r.design)!==null,W=!c&&!m&&r.name.trim()!==""&&r.description.trim()!==""&&I&&r.script.trim()!=="",J=async()=>{if(!W||s===null)return;h(!0);const w=await window.electronAPI.workflowPresets.save({...r,args:fg(r.args)},s==="new"?void 0:s);if(h(!1),!w.ok){k(a(w.error));return}n(),t()};return e.jsx(ve,{open:s!==null,onOpenChange:w=>!w&&t(),children:e.jsxs(be,{className:"max-w-4xl",children:[e.jsx(ye,{children:e.jsx(we,{children:a(s==="new"?"Add workflow preset":"Edit workflow preset")})}),e.jsxs(Ne,{className:"space-y-4",children:[e.jsxs(ue,{children:[e.jsx(me,{children:a("Name")}),e.jsx(Q,{value:r.name,onChange:w=>V({name:w.target.value})})]}),e.jsxs(ue,{children:[e.jsx(me,{children:a("Description")}),e.jsx(Q,{value:r.description,onChange:w=>V({description:w.target.value})})]}),e.jsxs(ue,{children:[e.jsx(me,{children:a("Arguments")}),e.jsxs("div",{className:"w-full space-y-1.5",children:[r.args.map((w,z)=>e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Q,{size:"sm",className:"w-28 font-mono",placeholder:"key",value:w.key,onChange:G=>E(z,{key:G.target.value})}),e.jsx(Q,{size:"sm",className:"flex-1",placeholder:a("Label"),value:w.label,onChange:G=>E(z,{label:G.target.value})}),e.jsx(Q,{size:"sm",className:"flex-1",placeholder:a("Default value"),value:w.default??"",onChange:G=>E(z,{default:G.target.value})}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1 text-muted-foreground text-xs",children:[e.jsx(Le,{checked:w.required===!0,onCheckedChange:G=>E(z,{required:G===!0})}),a("Required")]}),e.jsx(y,{variant:"ghost",size:"icon-xs","aria-label":a("Remove"),onClick:()=>V({args:r.args.filter((G,B)=>B!==z)}),children:e.jsx(bs,{})})]},z)),e.jsxs(y,{variant:"outline",size:"xs",disabled:r.args.length>=8,onClick:()=>V({args:[...r.args,{key:"",label:""}]}),children:[e.jsx(Pe,{}),a("Add argument")]})]})]}),e.jsxs(ue,{children:[e.jsxs("div",{className:"flex w-full items-center justify-between gap-2",children:[e.jsx(me,{children:a("Steps")}),i==="code"&&e.jsxs(y,{variant:"ghost",size:"xs",className:"ml-auto",disabled:c||j||!!r.design||!r.script.trim(),title:r.design?a("Generated code is already formatted"):void 0,onClick:C,children:[j?e.jsx(Ae,{className:"animate-spin"}):e.jsx(Xd,{}),a("Format")]}),e.jsx(Js,{value:i,onValueChange:w=>u(w),children:e.jsxs(Xs,{children:[e.jsx(Je,{value:"design",children:a("Design")}),e.jsx(Je,{value:"code",children:a("Code")})]})})]}),c?e.jsx("div",{className:"flex w-full items-center justify-center rounded-md border py-12",children:e.jsx(Ae,{className:"h-4 w-4 animate-spin text-muted-foreground"})}):i==="design"?r.design?e.jsx(pg,{design:r.design,agentTypes:M,args:r.args,onChange:L}):e.jsxs("div",{className:"flex w-full flex-col items-center gap-2 rounded-md border border-dashed py-8 text-center",children:[e.jsx("p",{className:"max-w-md text-muted-foreground text-xs",children:a("This preset is plain code and cannot be shown in the designer. Using the designer replaces the current script.")}),e.jsx(y,{variant:"outline",size:"xs",onClick:()=>L(p.current??Nn),children:a("Use the designer")})]}):e.jsx(ei,{fileName:"workflow.js",className:"h-80",value:r.script,epoch:d,onChange:P}),e.jsx("p",{className:"text-muted-foreground text-xs",children:i==="design"?!I&&a("Every phase needs a title and every step needs a label and a prompt."):r.design?a("Generated from the design. Editing the code detaches it from the designer."):a("Plain JavaScript with top-level await; end with return. Available: agent(prompt, opts), parallel, pipeline, phase, log, args.")})]}),A&&e.jsxs("p",{className:"flex items-center gap-1.5 text-destructive text-xs",children:[e.jsx(Rs,{className:"h-3.5 w-3.5 shrink-0"}),A]})]}),e.jsxs(Ie,{children:[e.jsx(y,{variant:"outline",size:"sm",onClick:t,children:a("Cancel")}),e.jsxs(y,{size:"sm",disabled:!W,onClick:J,children:[m&&e.jsx(Ae,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}),a("Save")]})]})]})})}function jg(){const{t:s}=R(),[t,n]=l.useState([]),[a,r]=l.useState(null),o=g(p=>p.disabledWorkflowPresets),i=g(p=>p.toggleWorkflowPreset),u=l.useCallback(()=>{window.electronAPI.workflowPresets.list().then(n)},[]);l.useEffect(u,[u]);const d=t.filter(p=>p.source!=="builtin"),x=t.filter(p=>p.source==="builtin");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-end justify-between gap-4","data-settings-row":"workflows.root",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-medium text-lg",children:s("Workflows")}),e.jsx("p",{className:"text-muted-foreground text-sm",children:s("Preset workflows you can run from the Workflow side panel")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Project .agents/workflows files take precedence over these; ~/.agents/workflows and built-in presets come after.")})]}),e.jsxs(y,{variant:"outline",size:"sm",onClick:()=>r("new"),children:[e.jsx(Pe,{className:"mr-1.5 h-4 w-4"}),s("Add workflow preset")]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium text-muted-foreground text-xs",children:s("Custom presets")}),d.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx(Bn,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:s("No custom workflow presets yet")})]}):e.jsx("div",{className:"space-y-1",children:d.map(p=>e.jsxs("div",{className:"group flex items-center justify-between gap-3 rounded-md px-3 py-2 transition-colors hover:bg-accent/50","data-settings-row":`workflows.${p.id}`,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium text-sm",children:p.name}),e.jsx(ie,{variant:"secondary",className:"shrink-0 font-mono text-[11px]",children:p.id})]}),e.jsx("p",{className:"truncate text-muted-foreground text-xs",children:p.description})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(y,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100","aria-label":s("Edit"),onClick:()=>r(p.id),children:e.jsx(xs,{className:"h-3.5 w-3.5"})}),e.jsx(y,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity hover:text-destructive group-hover:opacity-100","aria-label":s("Delete"),onClick:()=>{window.electronAPI.workflowPresets.delete(p.id).then(u)},children:e.jsx(Re,{className:"h-3.5 w-3.5"})})]})]},p.id))})]}),x.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium text-muted-foreground text-xs",children:s("Built-in presets")}),e.jsx("div",{className:"space-y-1",children:x.map(p=>e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md px-3 py-2 transition-colors hover:bg-accent/50","data-settings-row":`workflows.builtin.${p.id}`,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium text-sm",children:s(p.name)}),e.jsx(ie,{variant:"secondary",className:"shrink-0 font-mono text-[11px]",children:p.id})]}),e.jsx("p",{className:"text-muted-foreground text-xs",children:s(p.description)}),p.args.length>0&&e.jsxs("p",{className:"mt-0.5 text-muted-foreground text-xs",children:[s("Arguments"),":"," ",p.args.map(c=>`${s(c.label)}${c.required?" *":""}`).join(" · ")]})]}),e.jsx(ce,{"aria-label":s(p.name),checked:!o.includes(p.id),onCheckedChange:c=>i(p.id,c)})]},p.id))})]}),e.jsx(gg,{target:a,onClose:()=>r(null),onSaved:u})]})}function vg(s){window.requestAnimationFrame(()=>{const t=document.querySelector(`[data-settings-row="${CSS.escape(s)}"]`);t instanceof HTMLElement&&(t.scrollIntoView({block:"center"}),t.dataset.settingsFlash="true",window.setTimeout(()=>{delete t.dataset.settingsFlash},1600))})}function Br(){const{t:s}=R(),[t,n]=l.useState("general"),[a,r]=l.useState(null),[o,i]=l.useState(null),[u,d]=l.useState(null),[x,p]=l.useState(null),[c,f]=l.useState(0),m=Qd(),[h,j]=l.useState(!0),[b,A]=l.useState(""),[k,N]=l.useState([]),S=F=>{n(F),j(!1)},M=g(F=>F.disabledBuiltinTools),V=g(F=>F.botModeEnabled),E=g(F=>F.secretaryEnabled),L=l.useSyncExternalStore(F=>g.persist?.onFinishHydration?.(F)??(()=>{}),()=>g.persist?.hasHydrated?.()??!0),P=l.useCallback(F=>{n(F.category),j(!1),r(F.rowId),F.pluginInstallUrl&&i(F.pluginInstallUrl),d(F.pluginId??null),p(F.marketQuery??null)},[]);l.useEffect(()=>(window.electronAPI.window.consumeSettingsDeepLink().then(F=>{F&&P(F)}),window.electronAPI.window.onSettingsDeepLink(P)),[P]),l.useEffect(()=>{let F=!0;return window.electronAPI.sshConnections.list().then(ee=>{F&&N(ee.map($=>({id:$.id,name:$.name})))}).catch(()=>{F&&N([])}),()=>{F=!1}},[]);const C=Zd(k);l.useLayoutEffect(()=>{if(!a)return;vg(a);const F=window.setTimeout(()=>r(null),1600);return()=>window.clearTimeout(F)},[a]);const W=Af([{id:"general",icon:au,label:"General"},{id:"shortcuts",icon:_u,label:"Shortcuts"},{id:"appearance",icon:Uu,label:"Appearance"},{id:"providers",icon:Vn,label:"Model Providers"},{id:"presets",icon:ru,label:"Presets"},{id:"agents",icon:ou,label:"Agent types"},{id:"tools",icon:co,label:"Built-in tools"},{id:"workflows",icon:Bn,label:"Workflows"},{id:"memory",icon:io,label:"Memory"},{id:"privacy",icon:iu,label:"Privacy"},{id:"skills",icon:_o,label:"Skills"},{id:"plugins",icon:St,label:"Enso plugins"},{id:"mcp",icon:vo,label:"MCP Servers"},{id:"instructions",icon:Un,label:"Instruction Files"},{id:"phone",icon:dn,label:"Devices"},{id:"ssh",icon:Zr,label:"SSH"},{id:"usage",icon:Cu,label:"Usage"},{id:"resources",icon:lu,label:"Resources"},{id:"experimental",icon:cu,label:"Experimental"},{id:"bots",icon:du,label:"Bot mode",sub:!0},{id:"botTemplates",icon:uu,label:"Bot templates",sub:!0},{id:"secretary",icon:mu,label:"Secretary",sub:!0}],M,V,E||!L),J=If(Mf(W,C,b,s)),w=Ef(t,M,V||!L,E||!L);l.useEffect(()=>{w!==t&&n(w)},[w,t]);const z=!m||h,G=!m||!h,B=W.find(F=>F.id===t)?.label,U=eu(),re=Fo();return e.jsxs("div",{className:"flex h-full w-full",children:[z&&e.jsxs("nav",{"data-enso":"settings-nav",className:H("flex min-h-0 shrink-0 flex-col",m?"w-full":U?"w-56":"w-56 border-r"),children:[U&&re==="mac"&&e.jsx("div",{"aria-hidden":!0,className:"drag-region -mb-2 h-[44px] shrink-0"}),e.jsx("div",{className:H("sticky top-0 z-10 px-2 pt-2",!U&&"bg-background"),children:e.jsxs("div",{className:"relative",children:[e.jsx(lo,{className:"pointer-events-none absolute top-1/2 left-2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),e.jsx("input",{value:b,onChange:F=>A(F.target.value),onKeyDown:F=>{F.key!=="Escape"||b.length===0||(F.preventDefault(),F.stopPropagation(),A(""))},placeholder:s("Search settings"),className:"h-8 w-full rounded-md border bg-transparent pr-2 pl-7 text-sm outline-none placeholder:text-muted-foreground focus-visible:ring-2 focus-visible:ring-ring"})]})}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto p-2",children:b.trim()&&J.length===0?e.jsx("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:s("No results")}):J.map((F,ee)=>e.jsxs("div",{className:H(ee>0&&"mt-4"),children:[e.jsx("div",{className:"px-2 pb-1.5 text-xs font-semibold text-foreground/55",children:s(F.label)}),e.jsx("div",{className:"space-y-0.5 rounded-lg bg-muted/60 p-1",children:F.items.map($=>e.jsxs("div",{children:[e.jsxs("button",{type:"button",onClick:()=>S($.id),className:H("flex w-full items-center gap-2 rounded-md px-3 text-sm transition-colors",m?"py-3":"py-1.5",$.sub&&"pl-8",t===$.id&&!m?"bg-background text-foreground shadow-xs":"text-muted-foreground hover:bg-background/60 hover:text-foreground"),children:[e.jsx($.icon,{className:"h-4 w-4"}),s($.label),m&&e.jsx(Ys,{className:"ml-auto h-4 w-4 opacity-60"})]}),$.hits.map(oe=>e.jsx("button",{type:"button",onClick:()=>{S($.id),r(oe.id)},className:H("block w-full truncate rounded-md pr-3 text-left text-xs text-muted-foreground hover:bg-background/60 hover:text-foreground",$.sub?"pl-14":"pl-9",m?"py-2":"py-1"),children:s(oe.title)},oe.id))]},$.id))})]},F.id))})]}),G&&e.jsxs("div",{"data-enso":"settings-content",className:H("flex min-w-0 flex-1 flex-col",U&&"my-[8px] mr-[8px] overflow-hidden rounded-[10px] bg-background shadow-surface"),children:[U&&e.jsx(su,{"data-enso":"title-bar"}),e.jsxs("div",{className:H("min-h-0 flex-1 overflow-y-auto",m?"px-4 pb-6":U?"px-6 pb-6":"p-6"),children:[m&&e.jsxs("button",{type:"button",onClick:()=>j(!0),className:"sticky top-0 z-10 -mx-4 mb-3 flex w-[calc(100%+2rem)] items-center gap-1 border-b bg-background px-2 py-2.5 text-sm font-medium",children:[e.jsx(so,{className:"h-5 w-5 text-muted-foreground"}),B?s(B):null]}),t==="general"&&e.jsx(Rm,{}),t==="shortcuts"&&e.jsx(Gx,{}),t==="appearance"&&e.jsx(lx,{onOpenPlugins:()=>S("plugins")}),t==="providers"&&e.jsx(Yp,{}),t==="skills"&&e.jsx(wf,{}),t==="plugins"&&e.jsx(Tp,{requestedInstallUrl:o,onRequestedInstallUrlConsumed:()=>i(null),focusPluginId:u,onFocusPluginConsumed:()=>d(null),requestedMarketQuery:x,onRequestedMarketQueryConsumed:()=>p(null)}),t==="mcp"&&e.jsx(ph,{}),t==="instructions"&&e.jsx(Kx,{}),t==="presets"&&e.jsx(tu,{}),t==="agents"&&e.jsx(nu,{}),t==="workflows"&&e.jsx(jg,{}),t==="tools"&&e.jsx(Rx,{}),t==="memory"&&e.jsxs("div",{className:"space-y-8",children:[e.jsx(mp,{onLibraryChanged:()=>f(F=>F+1)}),e.jsx(Ah,{revision:c}),e.jsx(Vh,{revision:c})]}),t==="phone"&&e.jsx(Lx,{}),t==="ssh"&&e.jsx(Nf,{}),t==="usage"&&e.jsx(Wf,{}),t==="privacy"&&e.jsx(Fp,{}),t==="resources"&&e.jsx(tf,{}),t==="experimental"&&e.jsx($x,{onOpenBots:()=>n("bots")}),t==="bots"&&e.jsx(px,{}),t==="botTemplates"&&e.jsx(Nx,{}),t==="secretary"&&e.jsx(yf,{})]})]})]})}xu();hu();function bg(){const{t:s}=R(),t=Fo();return t!=="mobile"&&t!=="web"?e.jsxs("div",{"data-enso":"canvas",className:"flex h-screen overflow-hidden bg-canvas",children:[e.jsx(Pa,{}),e.jsx(fu.Provider,{value:{trailing:e.jsx(gu,{kind:t,edgeGap:8})},children:e.jsx(Br,{})}),e.jsx(Ta,{}),e.jsx(Ra,{})]}):e.jsxs("div",{className:"flex h-screen flex-col overflow-hidden",children:[e.jsx(Pa,{}),e.jsx(ju,{title:s("Settings"),actions:window.electronAPI.remote&&e.jsx("button",{type:"button",className:"flex h-7 w-7 items-center justify-center rounded-md hover:bg-muted",onClick:()=>{window.electronAPI.window.close()},"aria-label":s("Close"),title:s("Close"),children:e.jsx(bs,{className:"h-4 w-4"})})}),e.jsx("main",{className:"min-h-0 flex-1 overflow-hidden",children:e.jsx(Br,{})}),e.jsx(Ta,{}),e.jsx(Ra,{})]})}pu.createRoot(document.getElementById("root")).render(e.jsx(l.StrictMode,{children:e.jsx(bg,{})}));
|