@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
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./globals-BFf1P-Y5.js","./globals-DUBhAVpU.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{aj as Me,da as fi,db as oa,j as e,dc as gi,r as l,dd as Br,de as ji,df as vi,dg as bi,dh as yi,di as ia,ax as W,aE as X,b_ as wi,b8 as gs,dj as Ni,dk as ki,dl as os,dm as Ci,dn as Si,dp as Ii,dq as Ai,dr as Ei,ds as Mi,u as R,br as g,aO as y,ay as pe,az as fe,aA as ge,aB as je,aC as We,aD as ve,dt as Re,aM as ke,du as Ur,bJ as Ie,dv as la,dw as Pi,dx as ut,dy as xt,aG as Z,aH as ee,aI as se,aJ as te,aL as J,dz as Ti,dA as ss,dB as Ri,dC as Oi,b9 as Ce,bO as Mn,dD as ft,dE as Be,dF as $r,dG as Is,dH as Ue,bf as Ve,bj as Pn,b$ as Es,dI as Di,dJ as ca,dK as Ct,dL as St,dM as It,dN as At,dO as Et,dP as Mt,dQ as Pt,bA as ts,dR as da,dS as ma,bH as ze,dT as es,dU as Li,dV as zi,dW as _i,dX as Fi,bV as Vr,bi as oe,dY as Bi,dZ as Ui,d_ as ua,d$ as Ht,e0 as xa,e1 as ha,e2 as gt,e3 as $i,e4 as Vi,e5 as qt,bK as jt,e6 as Tt,e7 as Kr,e8 as Tn,e9 as Ki,ea as Rn,eb as Gr,ec as Gi,ed as Wi,ee as Hi,ef as Wr,eg as qi,eh as Yi,cA as Ji,bo as Hr,bl as Gs,ei as rt,ej as Xi,ek as On,el as Qi,cz as Zi,bL as Dn,em as el,ba as is,en as sl,eo as tl,ep as qr,eq as nl,er as al,es as rl,et as Yr,eu as Ln,bh as Ae,ev as ne,aQ as Ee,ew as ol,ex as il,ey as ll,ez as cl,eA as dl,eB as pa,eC as ml,eD as ul,eE as Ws,eF as Hs,eG as He,eH as Bs,eI as pn,eJ as xl,eK as hl,eL as fn,aP as ms,bd as Jr,ct as pl,eM as fl,eN as zn,eO as gl,eP as fa,eQ as Xr,eR as jl,eS as vl,eT as Qr,eU as $e,eV as bl,bm as vt,eW as yl,eX as ga,eY as wl,eZ as Nl,e_ as kl,aF as Qe,e$ as Cl,f0 as ja,f1 as va,f2 as Sl,f3 as ba,f4 as Il,f5 as Al,f6 as El,f7 as Ml,f8 as Ke,f9 as Yt,fa as ya,fb as Pl,fc as Tl,fd as Zr,d2 as Rl,bk as eo,d1 as Ol,fe as Dl,ff as Ll,fg as zl,d0 as _n,bg as _l,fh as so,cu as Fl,fi as Bl,by as qs,fj as Ul,fk as $l,fl as Vl,fm as gn,bb as to,fn as ot,fo as Kl,fp as Gl,fq as Wl,fr as me,fs as ue,ft as Rt,bM as Fn,fu as Bn,fv as no,fw as jn,fx as wa,fy as vn,fz as ao,fA as ro,fB as Hl,fC as oo,fD as ql,fE as Yl,fF as Jl,a as Xl,C as Ql,e as Zl,fG as Na,fH as io,fI as lo,fJ as co,fK as mo,fL as ec,fM as sc,fN as ka,aN as Us,aK as tc,bR as uo,bS as xo,bT as ho,fO as nc,fP as ac,fQ as rc,fR as oc,fS as ic,fT as lc,fU as cc,fV as dc,fW as ht,fX as zs,fY as po,bc as mc,fZ as uc,bn as xc,f_ as hc,cE as pc,f$ as fc,g0 as gc,g1 as jc,a_ as vc,g2 as bc,g3 as yc,g4 as bn,g5 as wc,bz as bt,g6 as Nc,g7 as Un,g8 as fo,g9 as go,ga as $n,gb as jo,gc as vo,gd as bo,ge as yo,gf as kc,gg as Cc,gh as wo,bF as Sc,gi as Ic,gj as Ac,gk as Ec,gl as Mc,gm as Pc,gn as Tc,go as Rc,gp as Oc,be as Dc,gq as Lc,gr as zc,gs as _c,gt as Fc,gu as Bc,gv as Uc,gw as $c,gx as Vc,gy as Kc,gz as No,d5 as ko,d6 as Co,cD as Gc,d7 as So,gA as Wc,gB as Hc,gC as qc,d8 as Io,gD as Yc,gE as Jc,gF as Ca,gG as Sa,gH as it,gI as Xc,gJ as Qc,gK as Zc,bv as ed,gL as sd,gM as td,gN as nd,gO as Ia,gP as ad,gQ as rd,gR as od,gS as id,gT as ld,gU as Ao,gV as cd,gW as dd,gX as md,gY as yt,gZ as ud,g_ as xd,g$ as hd,h0 as pd,h1 as ls,h2 as fd,cF as gd,h3 as jd,h4 as vd,h5 as bd,h6 as yd,cg as wd,h7 as Nd,h8 as kd,d3 as Eo,h9 as Cd,ha as Sd,hb as Id,bw as Ad,hc as Ed,hd as Md,he as Pd,hf as Td,hg as Rd,hh as Od,hi as Dd,hj as Ld,hk as zd,hl as _d,hm as Fd,hn as Aa,ho as Bd,hp as Ud,hq as Ea,hr as Ma,hs as $d}from"./globals-BFf1P-Y5.js";import{Q as Vd,L as Mo,E as Kd,r as Gd,M as Wd,a as Hd,b as qd,c as Yd,p as Po,f as Pa,F as Jd}from"./manifest-DOzTaB8J.js";import{X as Xd,Y as Qd}from"./Virtualizer-B0uwx_XV.js";import{F as Zd}from"./File-Tz3MUtN6.js";import{c as To}from"./cytoscape.esm-DzSz-X2X.js";import{f as em}from"./cytoscape-fcose-CzkrRInm.js";const sm=[["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"}]],tm=Me("book-open",sm);const nm=[["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"}]],am=Me("box",nm);const rm=[["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"}]],om=Me("chart-column",rm);const im=[["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"}]],lm=Me("file-archive",im);const cm=[["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"}]],dm=Me("file-pen-line",cm);const mm=[["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"}]],um=Me("flag",mm);const xm=[["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"}]],hm=Me("fold-vertical",xm);const pm=[["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"}]],Ta=Me("heart",pm);const fm=[["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"}]],gm=Me("keyboard",fm);const jm=[["circle",{cx:"12",cy:"16",r:"1",key:"1au0dj"}],["rect",{x:"3",y:"10",width:"18",height:"12",rx:"2",key:"6s8ecr"}],["path",{d:"M7 10V7a5 5 0 0 1 10 0v3",key:"1pqi11"}]],Ro=Me("lock-keyhole",jm);const vm=[["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"}]],bm=Me("palette",vm);const ym=[["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"}]],wm=Me("shrink",ym);const Nm=[["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"}]],km=Me("store",Nm);const Cm=[["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"}]],Sm=Me("sun",Cm);const Im=[["path",{d:"M12 3v12",key:"1x0j5s"}],["path",{d:"m17 8-5-5-5 5",key:"7q97r8"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}]],Oo=Me("upload",Im);function Am(s){return s&&typeof s=="object"&&!Array.isArray(s)?s:null}function Em(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 Mm(s){const t=Am(s);if(!t||Object.keys(t).some(d=>!["providerId","modelId","protocol","baseUrl","apiKey"].includes(d)))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"||!Em(o)||r!=="openai"&&r!=="openai-compatible"&&r!=="gemini"?null:{providerId:n,modelId:a,protocol:r,baseUrl:o,apiKey:i}}function Pm(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"?oa["google-generative-ai"]:n==="openai"?oa["openai-responses"]:"";let r=s.baseUrl.trim().replace(/\/+$/,"")||a;if(n==="gemini"&&r&&(r=fi(r,"v1beta")),n==="openai"&&r)try{new URL(r).pathname==="/"&&(r=`${r}/v1`)}catch{}return Mm({providerId:s.id,modelId:t,protocol:n,baseUrl:r,apiKey:s.apiKey})}function Tm(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 Rm(s){return s.flatMap(t=>{const n=Tm(t).filter(a=>Pm(t,a.id));return n.length?[{...t,models:n}]:[]})}function Om(s){const{multiple:t=!1,defaultValue:n,value:a,onValueChange:r,autoComplete:o,...i}=s;return e.jsx(gi,{...i,selectionMode:t?"multiple":"single",selectedValue:a,defaultSelectedValue:n,onSelectedValueChange:r,formAutoComplete:o})}const Dm=l.forwardRef(function(t,n){const{selected:a}=Br();return t.keepMounted||a?e.jsx(Lm,{...t,ref:n}):null}),Lm=l.memo(l.forwardRef((s,t)=>{const{render:n,className:a,style:r,keepMounted:o,...i}=s,{selected:d}=Br(),u=l.useRef(null),{transitionStatus:m,setMounted:p}=ji(d),f=vi("span",s,{ref:[t,u],state:{selected:d,transitionStatus:m},props:[{"aria-hidden":!0,children:"✔️"},i],stateAttributesMapping:yi});return bi({open:d,ref:u,onComplete(){d||p(!1)}}),f})),Vn=l.createContext({chipsRef:null,multiple:!1,rootRef:null});function zm(s){const t=l.useRef(null),n=l.useRef(null);return e.jsx(Vn.Provider,{value:{chipsRef:t,multiple:!!s.multiple,rootRef:n},children:e.jsx("div",{ref:n,className:"contents",children:e.jsx(Om,{...s})})})}function _m({className:s,showTrigger:t=!0,showClear:n=!1,startAddon:a,size:r,...o}){const{multiple:i}=l.useContext(Vn),d=r??"default";return i?e.jsx(ia,{className:W("min-w-12 flex-1 text-base outline-none sm:text-sm [[data-slot=combobox-chip]+&]:ps-0.5",d==="sm"?"ps-1.5":"ps-2",s),"data-size":typeof d=="string"?d:void 0,"data-slot":"combobox-input",size:typeof d=="number"?d:void 0,...o}):e.jsxs("div",{className:"relative w-full has-disabled:opacity-64",children:[a&&e.jsx("div",{"aria-hidden":"true",className:"[&_svg]:-mx-0.5 pointer-events-none absolute inset-y-0 start-px z-10 flex items-center ps-[calc(--spacing(3)-1px)] opacity-80 has-[+[data-size=sm]]:ps-[calc(--spacing(2.5)-1px)] [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4","data-slot":"combobox-start-addon",children:a}),e.jsx(ia,{className:W(a&&"data-[size=sm]:*:data-[slot=combobox-input]:ps-[calc(--spacing(7.5)-1px)] *:data-[slot=combobox-input]:ps-[calc(--spacing(8.5)-1px)] sm:data-[size=sm]:*:data-[slot=combobox-input]:ps-[calc(--spacing(7)-1px)] sm:*:data-[slot=combobox-input]:ps-[calc(--spacing(8)-1px)]",d==="sm"?"has-[+[data-slot=combobox-trigger],+[data-slot=combobox-clear]]:*:data-[slot=combobox-input]:pe-6.5":"has-[+[data-slot=combobox-trigger],+[data-slot=combobox-clear]]:*:data-[slot=combobox-input]:pe-7",s),"data-slot":"combobox-input",render:e.jsx(X,{className:"has-disabled:opacity-100",size:d}),...o}),t&&e.jsx(Fm,{className:W("-translate-y-1/2 absolute top-1/2 inline-flex size-8 shrink-0 cursor-pointer items-center justify-center rounded-md border border-transparent opacity-80 outline-none transition-opacity pointer-coarse:after:absolute pointer-coarse:after:min-h-11 pointer-coarse:after:min-w-11 hover:opacity-100 has-[+[data-slot=combobox-clear]]:hidden sm:size-7 [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",d==="sm"?"end-0":"end-0.5"),children:e.jsx(wi,{})}),n&&e.jsx(Vm,{className:W("-translate-y-1/2 absolute top-1/2 inline-flex size-8 shrink-0 cursor-pointer items-center justify-center rounded-md border border-transparent opacity-80 outline-none transition-opacity pointer-coarse:after:absolute pointer-coarse:after:min-h-11 pointer-coarse:after:min-w-11 hover:opacity-100 has-[+[data-slot=combobox-clear]]:hidden sm:size-7 [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",d==="sm"?"end-0":"end-0.5"),children:e.jsx(gs,{})})]})}function Fm({className:s,...t}){return e.jsx(Ei,{className:s,"data-slot":"combobox-trigger",...t})}function Bm({className:s,children:t,sideOffset:n=4,zIndex:a,...r}){const{chipsRef:o,rootRef:i}=l.useContext(Vn);let d=os.DROPDOWN;if(a!==void 0)d=a;else{const u=i?.current;u&&(u.closest('[data-slot="dialog-popup"] [data-slot="dialog-popup"]')?d=os.DROPDOWN_IN_NESTED_MODAL:u.closest('[data-slot="dialog-popup"]')&&(d=os.DROPDOWN_IN_MODAL))}return e.jsx(Ni,{children:e.jsx(ki,{anchor:o,className:"select-none",style:{zIndex:d},"data-slot":"combobox-positioner",sideOffset:n,children:e.jsx("span",{className:W("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(Ci,{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 Um({className:s,children:t,endAddon:n,...a}){return e.jsxs(Ai,{className:W("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(Dm,{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 $m({className:s,...t}){return e.jsx(Si,{scrollbarGutter:!0,scrollFade:!0,children:e.jsx(Ii,{className:W("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 Vm({className:s,...t}){return e.jsx(Mi,{className:s,"data-slot":"combobox-clear",...t})}function Km(){const{t:s}=R(),t=g(x=>x.contextMenuOpen),n=g(x=>x.setContextMenuOpen),[a,r]=l.useState(!1),[o,i]=l.useState(!1),d=x=>x.target==="reveal"?s("File manager"):x.target==="vscode"?s("VS Code"):x.applicationPath.split(/[/\\]/).at(-1)?.replace(/\.(exe|app)$/i,"")||x.applicationPath,u=t.filter(x=>x.enabled).map(d),m=u.length?`${u.slice(0,2).join(", ")}${u.length>2?` +${u.length-2}`:""}`:s("No opening methods enabled"),p=x=>{if(x.length>32){Ie({type:"error",title:s("Context menu opening"),description:s("You can configure up to 32 opening methods.")});return}n(x)},c=(x,h)=>{const j=g.getState().contextMenuOpen;n(j.map(b=>b.id===x.id?{...b,enabled:h}:b))},f=async()=>{i(!0);try{const x=await window.electronAPI.dialog.selectFile();if(!x)return;if(!Ur(x)){Ie({type:"error",title:s("Context menu opening"),description:s("The selected application path is invalid.")});return}const h=g.getState().contextMenuOpen,j=la(x),b=h.find(I=>I.target==="application"&&la(I.applicationPath)===j);if(b){p(h.map(I=>I.id===b.id?{...I,enabled:!0}:I));return}p([...h,{id:crypto.randomUUID(),target:"application",applicationPath:x,enabled:!0}])}catch(x){Ie({type:"error",title:s("Context menu opening"),description:x instanceof Error?x.message:String(x)})}finally{i(!1)}};return e.jsxs("div",{className:"space-y-2 rounded-md border p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("h5",{className:"text-sm font-medium",children:s("Context menu opening")}),e.jsx(y,{variant:"outline",size:"sm",onClick:()=>r(!0),children:s("Configure list")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Select the opening methods shown in file link context menus. You can add multiple applications.")}),e.jsx("p",{className:"truncate text-xs text-muted-foreground",title:u.join(", "),children:m}),e.jsx(pe,{open:a,onOpenChange:r,children:e.jsxs(fe,{zIndexLevel:"nested",children:[e.jsxs(ge,{children:[e.jsx(je,{children:s("Context menu opening")}),e.jsx(We,{children:s("Select the opening methods shown in file link context menus. You can add multiple applications.")})]}),e.jsxs(ve,{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(x=>{const h=d(x);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(Re,{checked:x.enabled,disabled:o,"aria-label":h,onCheckedChange:j=>c(x,j)}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-sm",title:h,children:h}),x.target==="application"&&e.jsx("span",{className:"block truncate text-xs text-muted-foreground",title:x.applicationPath,children:x.applicationPath})]})]}),e.jsx(y,{variant:"ghost",size:"sm",disabled:o,onClick:()=>n(g.getState().contextMenuOpen.filter(j=>j.id!==x.id)),children:s("Delete")})]},x.id)})]}),e.jsxs(ke,{children:[e.jsx(y,{variant:"outline",disabled:o,onClick:()=>{f()},children:s("Add application")}),e.jsx(y,{onClick:()=>r(!1),children:s("Close")})]})]})})]})}const Ra=["internal","reveal","system","application"];function Oa({extension:s,value:t,disabled:n,onChange:a}){const{t:r}=R(),o={internal:r("Open inside EnsoCode"),reveal:r("Reveal in file manager"),system:r("System default application"),application:r("Selected application")},i=ut(`file${s}`),d=xt(`file${s}`)!==null,u=i?d?["internal","reveal"]:["reveal"]:Ra,m=i&&(!d||t==="system"||t==="application")?"reveal":t;return e.jsxs(Z,{items:Object.fromEntries(u.map(p=>[p,o[p]])),value:m,disabled:n,onValueChange:p=>{Ra.includes(p)&&a(p)},children:[e.jsx(ee,{className:"w-52","aria-label":r("File opening"),children:e.jsx(se,{})}),e.jsx(te,{children:u.map(p=>e.jsx(J,{value:p,disabled:p==="internal"&&!d,children:o[p]},p))})]})}function Gm(){const{t:s}=R(),t=g(S=>S.fileOpenRules),n=g(S=>S.setFileOpenRules),[a,r]=l.useState(""),[o,i]=l.useState("internal"),[d,u]=l.useState(),[m,p]=l.useState(null),[c,f]=l.useState(!1),x=Pi([{extension:a,target:"reveal"}])[0]?.extension,h=S=>{Ie({type:"error",title:s("File opening"),description:S})},j=async S=>{f(!0);try{const N=await window.electronAPI.dialog.selectFile();if(N){if(!Ur(N)){h(s("The selected application path is invalid."));return}S(N)}}catch(N){h(N instanceof Error?N.message:String(N))}finally{f(!1)}},b=S=>{const N=Ti(S);return N?(n(N),!0):(h(s("Could not complete the file action.")),!1)},I=(S,N,A)=>{if(N==="internal"&&!xt(`file${S.extension}`)){h(s("This extension does not support internal preview."));return}b(t.map($=>$.extension===S.extension?{extension:S.extension,target:N,...N==="application"?{applicationPath:A}:{}}:$))},C=()=>{if(!x){p(s("Enter a valid file extension, for example .md."));return}if(t.some($=>$.extension===x)){p(s("This extension already has an opening rule."));return}const S=ut(`file${x}`),N=xt(`file${x}`)!==null,A=S&&(!N||o==="system"||o==="application")?"reveal":o;if(A==="internal"&&!xt(`file${x}`)){h(s("This extension does not support internal preview."));return}if(A==="application"&&!d){p(s("Choose an application before saving this rule."));return}b([...t,{extension:x,target:A,...A==="application"?{applicationPath:d}:{}}])&&(r(""),u(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(Km,{}),t.map(S=>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:S.extension}),e.jsx(Oa,{extension:S.extension,value:S.target,disabled:c,onChange:N=>{N==="application"?j(A=>I(S,N,A)):I(S,N)}}),S.target==="application"&&!ut(`file${S.extension}`)&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-xs text-muted-foreground",title:S.applicationPath,children:S.applicationPath}),e.jsx(y,{variant:"outline",size:"sm",disabled:c,onClick:()=>{j(N=>I(S,"application",N))},children:s("Choose application")})]}),e.jsx(y,{variant:"ghost",size:"sm",disabled:c,onClick:()=>b(t.filter(N=>N.extension!==S.extension)),children:s("Delete")})]},S.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(X,{className:"w-24",value:a,placeholder:".md","aria-label":s("File extension"),disabled:c,onChange:S=>{r(S.target.value),p(null)},onKeyDown:S=>{S.key==="Enter"&&C()}}),e.jsx(Oa,{extension:x??".md",value:o,disabled:c,onChange:S=>{i(S),p(null)}}),e.jsx(y,{variant:"outline",size:"sm",disabled:c,onClick:C,children:s("Add")})]}),o==="application"&&!ut(`file${x??".md"}`)&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{variant:"outline",size:"sm",disabled:c,onClick:()=>{j(S=>{u(S),p(null)})},children:s("Choose application")}),e.jsx("span",{className:"min-w-0 truncate text-xs text-muted-foreground",title:d,children:d})]}),m&&e.jsx("p",{role:"alert",className:"text-xs text-destructive",children:m})]})]})}const Wm=["pem","crt","cer"];function Hm(s){return/^\//.test(s)||/^[A-Za-z]:[\\/]/.test(s)||/^\\\\[^\\]/.test(s)}const qm=16384,Do=4096,Lo=65536;function Ym(s){return s===null?null:typeof s=="number"&&Number.isInteger(s)&&s>=Do&&s<=Lo?s:void 0}function Jm(s){const t=s.trim();return t?/^\d+$/.test(t)?Ym(Number(t)):void 0:null}function Xm(){const{t:s}=R(),[t,n]=l.useState(null),[a,r]=l.useState(""),[o,i]=l.useState(null);l.useEffect(()=>{let u=!1;return window.electronAPI.compaction.getReserveTokens().then(m=>{u||(n(m),r(m===null?"":String(m)))}),()=>{u=!0}},[]);const d=async()=>{const u=Jm(a);if(u===void 0){i(s("Enter a whole number between {{min}} and {{max}}, or leave it empty.",{min:Do,max:Lo}));return}if(i(null),u===t)return;if(!(await window.electronAPI.compaction.setReserveTokens(u)).ok){i(s("Could not save. Check that pi-agent/settings.json is valid JSON."));return}n(u),r(u===null?"":String(u))};return e.jsxs("div",{className:"flex items-start justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.compactReserveTokens",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"text-sm",children:[s("Compaction reserve tokens"),e.jsx(ss,{})]}),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(X,{inputMode:"numeric",value:a,placeholder:String(qm),"aria-label":s("Compaction reserve tokens"),onChange:u=>r(u.target.value),onBlur:()=>{d()},onKeyDown:u=>{u.key==="Enter"&&d()}}),o&&e.jsx("p",{className:"text-xs text-destructive",children:o})]})]})}function yn({className:s,render:t,...n}){const a={className:W("inline-flex items-center gap-2 text-base/4.5 sm:text-sm/4 font-medium",s),"data-slot":"label"};return Ri({defaultTagName:"label",props:Oi(a,n),render:t})}const Qm=[{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 Zm(){const{t:s}=R(),[t,n]=l.useState(!1),[a,r]=l.useState(!1),[o,i]=l.useState(null),[d,u]=l.useState(null),m=()=>{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}u(c)}catch{i({kind:"error",text:s("Could not open configuration package.")})}finally{r(!1)}};return e.jsxs("section",{className:"space-y-3","data-settings-row":"general.configSync",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium",children:s("Configuration transfer")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Move models, presets, agent types, skills, MCP servers and instruction files between devices.")})]}),e.jsxs("div",{className:"rounded-md border px-3 py-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[e.jsx(lm,{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(Ce,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Mn,{className:"h-3.5 w-3.5"}),s("Import configuration")]}),e.jsxs(y,{size:"sm",disabled:a,onClick:m,children:[e.jsx(Oo,{className:"h-3.5 w-3.5"}),s("Export configuration")]})]})]}),e.jsxs("div",{className:"mt-3 flex items-start gap-2 border-t pt-3 text-xs text-muted-foreground",children:[e.jsx(ft,{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(eu,{open:t,onOpenChange:n}),d&&e.jsx(su,{file:d,onClose:()=>u(null)})]})}function eu({open:s,onOpenChange:t}){const{t:n}=R(),[a,r]=l.useState(!1),[o,i]=l.useState(""),[d,u]=l.useState(""),[m,p]=l.useState(!1),[c,f]=l.useState(null),[x,h]=l.useState(!1),[j,b]=l.useState(null),[I,C]=l.useState([]);l.useEffect(()=>{s&&(r(!1),i(""),u(""),p(!1),f(null),h(!1),b(null),C([]))},[s]);const S=()=>{m||(i(""),u(""),t(!1))},N=async()=>{if(a&&o.length<8){f(n("Password must be at least 8 characters."));return}if(a&&o!==d){f(n("Passwords do not match."));return}p(!0),f(null),h(!1);try{const A=await window.electronAPI.configSync.exportConfig({includeSecrets:a,...a?{password:o}:{}});if(i(""),u(""),!A.ok){A.cancelled?h(!0):f(n(A.error));return}b(A.filePath),C(A.skippedInstructions??[])}catch{i(""),u(""),f(n("Could not export configuration."))}finally{p(!1)}};return e.jsx(pe,{open:s,onOpenChange:A=>!A&&S(),children:e.jsxs(fe,{className:"max-w-xl",showCloseButton:!m,children:[e.jsxs(ge,{children:[e.jsx(je,{children:n("Export configuration")}),e.jsx(We,{children:n("Create a portable .enso-config package for another device.")})]}),e.jsx(ve,{className:"max-h-[55vh] space-y-4",children:j?e.jsxs(e.Fragment,{children:[e.jsxs(Be,{variant:"success",children:[e.jsx($r,{}),e.jsx(Is,{children:n("Configuration exported")}),e.jsxs(Ue,{children:[e.jsx("p",{children:n("Saved package:")}),e.jsx("p",{className:"break-all font-mono text-xs text-foreground",children:j})]})]}),I.length>0&&e.jsxs(Be,{variant:"warning",children:[e.jsx(Ve,{}),e.jsxs(Ue,{children:[e.jsx("p",{children:n("These instructions were skipped because their source files are missing or unreadable:")}),e.jsx("p",{className:"break-all text-foreground",children:I.join(", ")})]})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs(Be,{variant:"warning",children:[e.jsx(Pn,{}),e.jsx(Is,{children:n("File contents can be private")}),e.jsx(Ue,{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(Re,{checked:a,onCheckedChange:A=>{const $=A===!0;r($),f(null),$||(i(""),u(""))}}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-sm font-medium",children:n("Include sensitive configuration")}),e.jsx("span",{className:"mt-0.5 block text-xs text-muted-foreground",children:n("Encrypt the entire package with a password. OAuth login sessions are still excluded.")})]})]}),!a&&e.jsxs(Be,{variant:"info",children:[e.jsx(ft,{}),e.jsx(Ue,{children:n("API keys, provider account links, MCP arguments and environment values, plus credentials and private URL parts in MCP endpoints, will be omitted. Configurations containing skill or instruction files require encryption.")})]}),a&&e.jsxs("div",{className:"space-y-3 rounded-md border px-3 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(Ro,{className:"h-4 w-4 text-muted-foreground"}),n("Encryption password")]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(yn,{htmlFor:"config-export-password",children:n("Password")}),e.jsx(X,{id:"config-export-password",type:"password",autoComplete:"new-password",value:o,"aria-invalid":!!(c&&o.length<8),onChange:A=>{i(A.target.value),f(null)}})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(yn,{htmlFor:"config-export-confirmation",children:n("Confirm password")}),e.jsx(X,{id:"config-export-confirmation",type:"password",autoComplete:"new-password",value:d,"aria-invalid":!!(c&&d!==o),onChange:A=>{u(A.target.value),f(null)}})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n("Use at least 8 characters. This password cannot be recovered.")})]}),x&&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(Es,{className:"h-3.5 w-3.5 shrink-0"}),c]})]})}),e.jsx(ke,{children:j?e.jsx(y,{size:"sm",onClick:S,children:n("Done")}):e.jsxs(e.Fragment,{children:[e.jsx(y,{variant:"outline",size:"sm",disabled:m,onClick:S,children:n("Cancel")}),e.jsxs(y,{size:"sm",disabled:m,onClick:()=>{N()},children:[m?e.jsx(Ce,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Oo,{className:"h-3.5 w-3.5"}),n(m?"Exporting…":"Export")]})]})})]})})}function su({file:s,onClose:t}){const{t:n}=R(),[a,r]=l.useState(s.encrypted?"password":"preview"),[o,i]=l.useState(""),[d,u]=l.useState("merge"),[m,p]=l.useState(null),[c,f]=l.useState([]),[x,h]=l.useState(null),[j,b]=l.useState(!1),[I,C]=l.useState(null),[S,N]=l.useState(null),[A,$]=l.useState(!1),E=l.useRef(0),L=l.useCallback(async(w,z)=>{const H=++E.current;C("preview"),N(null),p(null),f([]);try{const F=await window.electronAPI.configSync.previewImport({token:s.token,mode:w,...z?{password:z}:{}});if(H!==E.current)return;if(i(""),!F.ok){N(n(F.error));return}u(F.mode),p(F.summary),f(F.warnings),r("preview")}catch{H===E.current&&(i(""),N(n("Could not preview configuration package.")))}finally{H===E.current&&C(null)}},[s.token,n]);l.useEffect(()=>{s.encrypted||L("merge")},[s.encrypted,L]);const M=()=>{I||(E.current+=1,$(!1),i(""),window.electronAPI.configSync.cancelImport(s.token).catch(()=>{}),t())},k=w=>{w===d||I||(u(w),L(w))},T=!!m?.some(w=>(w.category==="skills"||w.category==="mcpServers")&&w.added+w.updated+w.skipped>0),_=m!==null,q=async()=>{if(m){C("commit"),N(null);try{const w=await window.electronAPI.configSync.commitImport({token:s.token,mode:d});if(!w.ok){p(null),f([]),N(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([]),N(n("Could not import configuration."))}finally{C(null)}}};return e.jsxs(pe,{open:!0,onOpenChange:w=>!w&&M(),children:[e.jsxs(fe,{className:"max-w-2xl",showCloseButton:I===null,children:[e.jsxs(ge,{children:[e.jsx(je,{children:n(a==="success"?"Configuration imported":"Import configuration")}),e.jsx(We,{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(ve,{className:"space-y-4",children:[e.jsxs(Be,{variant:"info",children:[e.jsx(Ro,{}),e.jsx(Is,{children:n("Encrypted configuration package")}),e.jsx(Ue,{children:n("Enter the export password to decrypt and preview this package.")})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(yn,{htmlFor:"config-import-password",children:n("Password")}),e.jsx(X,{id:"config-import-password",type:"password",autoFocus:!0,autoComplete:"current-password",value:o,"aria-invalid":!!S,onChange:w=>{i(w.target.value),N(null)},onKeyDown:w=>{w.key==="Enter"&&o.length>0&&!I&&L("merge",o)}})]}),S&&e.jsxs("p",{className:"flex items-center gap-1.5 text-xs text-destructive",role:"alert",children:[e.jsx(Es,{className:"h-3.5 w-3.5 shrink-0"}),S]})]}),a==="preview"&&e.jsxs(ve,{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(Di,{value:d,onValueChange:w=>k(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(ca,{value:"merge",disabled:I!==null}),e.jsxs("span",{children:[e.jsx("span",{className:"block text-sm font-medium",children:n("Merge")}),e.jsx("span",{className:"block text-xs text-muted-foreground",children:n("Add and update matching items while keeping items only on this device.")})]})]}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-2.5 rounded-md border px-3 py-2.5",children:[e.jsx(ca,{value:"replace",disabled:I!==null}),e.jsxs("span",{children:[e.jsx("span",{className:"block text-sm font-medium",children:n("Replace")}),e.jsx("span",{className:"block text-xs text-muted-foreground",children:n("Replace transferred item categories, removing local-only items in them.")})]})]})]})]}),I==="preview"&&e.jsxs("div",{className:"flex items-center justify-center gap-2 rounded-md border border-dashed py-10",children:[e.jsx(Ce,{className:"h-4 w-4 animate-spin text-muted-foreground"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:n("Preparing preview…")})]}),!I&&m&&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:Qm.map(({category:w,label:z})=>{const H=m.find(F=>F.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:H?.added??0}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:H?.updated??0}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:H?.skipped??0}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:H?.removed??0})]},w)})})]})}),!I&&m?.find(w=>w.category==="settings")?.fields?.length?e.jsxs("p",{className:"text-xs text-muted-foreground",children:[n("Portable settings changed:")," ",m.find(w=>w.category==="settings")?.fields?.join(", ")]}):null,d==="replace"&&m&&!I&&e.jsxs(Be,{variant:"error",children:[e.jsx(Ve,{}),e.jsx(Is,{children:n("Local-only configuration will be deleted")}),e.jsx(Ue,{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(Be,{variant:"warning",children:[e.jsx(Ve,{}),e.jsx(Ue,{children:n(w)})]},w)),m&&!I&&e.jsxs(Be,{variant:"warning",children:[e.jsx(Pn,{}),e.jsx(Is,{children:n("Only import packages you trust")}),e.jsx(Ue,{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.")})]}),S&&e.jsxs(Be,{variant:"error",children:[e.jsx(Es,{}),e.jsx(Ue,{children:S})]})]}),a==="success"&&x&&e.jsxs(ve,{className:"space-y-4",children:[e.jsxs(Be,{variant:"success",children:[e.jsx($r,{}),e.jsx(Is,{children:n("Import complete")}),e.jsxs(Ue,{children:[e.jsx("p",{children:n("Backup of previous settings:")}),e.jsx("p",{className:"break-all font-mono text-xs text-foreground",children:x})]})]}),j&&e.jsxs(Be,{variant:"warning",children:[e.jsx(Ve,{}),e.jsx(Ue,{children:n("Reopen Settings to load the imported configuration in this window.")})]}),c.map(w=>e.jsxs(Be,{variant:"warning",children:[e.jsx(Ve,{}),e.jsx(Ue,{children:n(w)})]},w))]}),e.jsxs(ke,{children:[a==="password"&&e.jsxs(e.Fragment,{children:[e.jsx(y,{variant:"outline",size:"sm",disabled:I!==null,onClick:M,children:n("Cancel")}),e.jsxs(y,{size:"sm",disabled:I!==null||o.length===0,onClick:()=>{L("merge",o)},children:[I==="preview"&&e.jsx(Ce,{className:"h-3.5 w-3.5 animate-spin"}),n("Preview")]})]}),a==="preview"&&e.jsxs(e.Fragment,{children:[e.jsx(y,{variant:"outline",size:"sm",disabled:I!==null,onClick:M,children:n("Cancel")}),S&&!m?e.jsx(y,{size:"sm",disabled:I!==null,onClick:()=>{L(d)},children:n("Refresh preview")}):e.jsxs(y,{variant:d==="replace"?"destructive":"default",size:"sm",disabled:I!==null||!m,onClick:()=>{m&&(_?$(!0):q())},children:[I==="commit"?e.jsx(Ce,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Mn,{className:"h-3.5 w-3.5"}),n(I==="commit"?"Importing…":"Import")]})]}),a==="success"&&e.jsx(y,{size:"sm",onClick:M,children:n("Done")})]})]}),e.jsx(tu,{open:A,mode:d,hasImportedExecutableResources:T,onOpenChange:$,onConfirm:()=>{q()}})]})}function tu({open:s,mode:t,hasImportedExecutableResources:n,onOpenChange:a,onConfirm:r}){const{t:o}=R();return e.jsx(Ct,{open:s,onOpenChange:a,children:e.jsxs(St,{className:"sm:max-w-md",zIndexLevel:"nested",children:[e.jsxs(It,{children:[e.jsxs(At,{className:"flex items-start gap-2 text-base",children:[e.jsx(Ve,{className:"mt-0.5 h-4 w-4 shrink-0 text-destructive"}),o("Confirm configuration import")]}),e.jsxs(Et,{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(Mt,{variant:"bare",children:[e.jsx(Pt,{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 Da={auto:"Auto (by usage)",fast:"Fast",balanced:"Balanced",thorough:"Thorough"},La={standard:"Standard",smart:"Smart compaction","codex-native":"Codex native compaction","continuous-memory":"Continuous memory (experimental)"};function nu(){const{t:s}=R(),t=g(x=>x.compactStrategy),n=g(x=>x.smartCompactEnabled),a=Li(t,n),r=g(x=>x.setCompactStrategy),o=a!=="standard",i=g(x=>x.smartCompactModel),d=g(x=>x.setSmartCompactModel),u=g(x=>x.smartCompactMode),m=g(x=>x.setSmartCompactMode),p=ts(),c=i?p.find(x=>x.id===i.providerId):void 0,f=c?.models.find(x=>x.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(ss,{})]}),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(Z,{items:Object.fromEntries(da.map(x=>[x,s(La[x])])),value:a,onValueChange:x=>r(x),children:[e.jsx(ee,{className:"w-52",children:e.jsx(se,{})}),e.jsx(te,{children:da.map(x=>e.jsx(J,{value:x,children:s(La[x])},x))})]})]}),(a==="smart"||a==="codex-native")&&e.jsxs("div",{className:"flex items-center justify-between gap-4","data-smart-compact-mode":u,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Compaction mode")}),e.jsx("p",{className:"mt-0.5 text-muted-foreground/80 text-[11px]",children:s("Mode changes summary budget and how much recent tail to keep. It does not decide whether compact runs.")})]}),e.jsxs(Z,{items:Object.fromEntries(ma.map(x=>[x,s(Da[x])])),value:u,onValueChange:x=>m(x),children:[e.jsx(ee,{className:"w-36",children:e.jsx(se,{})}),e.jsx(te,{children:ma.map(x=>e.jsx(J,{value:x,children:s(Da[x])},x))})]})]}),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(ze,{providers:p,providerId:c?.id??"",modelId:f?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:s("Follows the session model"),side:"bottom",triggerClassName:es,onSelect:(x,h)=>d({providerId:x,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:()=>d(null),children:s("Follow session model")})]})]})}const au={cmd:"Command Prompt",powershell:"Windows PowerShell",pwsh:"PowerShell 7 (pwsh)","git-bash":"Git Bash",zsh:"zsh",bash:"bash",fish:"fish"};function ru(){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(Z,{items:{en:"English",zh:"简体中文"},value:s,onValueChange:a=>t(a),children:[e.jsx(ee,{className:"w-48",children:e.jsx(se,{})}),e.jsxs(te,{children:[e.jsx(J,{value:"en",children:"English"}),e.jsx(J,{value:"zh",children:"简体中文"})]})]})]}),e.jsx(ou,{}),e.jsx(pu,{}),e.jsx(fu,{}),e.jsx(Zm,{}),e.jsx(gu,{})]}),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(iu,{}),e.jsx(lu,{}),e.jsx(cu,{}),e.jsx(nu,{}),e.jsx(Xm,{})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h4",{className:"border-b pb-2 text-base font-semibold",children:n("Sessions & worktrees")}),e.jsx(mu,{}),e.jsx(du,{}),e.jsx(xu,{})]}),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(hu,{}),e.jsx(uu,{})]}),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(za,{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(za,{kind:"finderQuickAction",title:n("Finder Quick Action"),description:n("Right-click a folder in Finder and choose Services > Open with EnsoCode.")})]})]})}function za({kind:s,title:t,description:n}){const{t:a}=R(),[r,o]=l.useState(!1),[i,d]=l.useState(!1);l.useEffect(()=>{let m=!0;const p=()=>{jt()||window.electronAPI.window.shellIntegrationStatus().then(c=>{m&&o(c[s])})};return p(),window.addEventListener("focus",p),()=>{m=!1,window.removeEventListener("focus",p)}},[s]);const u=async()=>{d(!0);try{await window.electronAPI.window.installShellIntegration(s)}finally{try{const m=await window.electronAPI.window.shellIntegrationStatus();o(m[s])}finally{d(!1)}}};return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":`general.${s}`,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n})]}),e.jsx(y,{variant:"outline",size:"sm",className:"shrink-0",disabled:i,onClick:()=>{u()},children:a(i?"In progress…":r?"Uninstall":"Install")})]})}function ou(){const{t:s}=R(),t=g(a=>a.notifyMainAgentOnly),n=g(a=>a.setNotifyMainAgentOnly);return e.jsx(we,{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 iu(){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(Z,{items:Object.fromEntries(ua.map(a=>[String(a),a===0?s("Never"):s("{{count}} min",{count:a})])),value:String(t),onValueChange:a=>n(Number(a)),children:[e.jsx(ee,{className:"w-28",children:e.jsx(se,{})}),e.jsx(te,{children:ua.map(a=>e.jsx(J,{value:String(a),children:a===0?s("Never"):s("{{count}} min",{count:a})},a))})]})]})}function lu(){const{t:s}=R(),t=g(o=>o.autoRetryLimit),n=g(o=>o.setAutoRetryLimit),a=Ht.some(o=>o===t)?[...Ht]:[...Ht,t].sort((o,i)=>o===qt?1:i===qt?-1:o-i),r=o=>o===0?s("Off"):o===qt?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(Z,{items:Object.fromEntries(a.map(o=>[String(o),r(o)])),value:String(t),onValueChange:o=>n(Number(o)),children:[e.jsx(ee,{className:"w-28",children:e.jsx(se,{})}),e.jsx(te,{children:a.map(o=>e.jsx(J,{value:String(o),children:r(o)},o))})]})]})}function cu(){const{t:s}=R(),t=g(a=>a.longCacheRetention),n=g(a=>a.setLongCacheRetention);return e.jsx(we,{rowId:"general.longCacheRetention",title:s("Long prompt cache (1 hour)"),description:s("Keep the prompt cache for 1 hour instead of 5 minutes. Saves a lot when turns are more than 5 minutes apart, since the cache no longer expires and gets rewritten every turn, but cache writes cost 2× instead of 1.25×, so rapid follow-ups tens of seconds apart cost more. Anthropic models only. Applies from the next request."),checked:t,onChange:n})}function du(){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(Z,{items:Object.fromEntries(gt.map(r=>[String(r),a(r)])),value:String(t),onValueChange:r=>n(Number(r)),children:[e.jsx(ee,{className:"w-28",children:e.jsx(se,{})}),e.jsx(te,{children:gt.map(r=>e.jsx(J,{value:String(r),children:a(r)},r))})]})]})}function lt(s,t){return t===0?s("Never"):t===1?s("{{count}} day",{count:t}):s("{{count}} days",{count:t})}function mu(){const{t:s}=R(),t=g(d=>d.autoArchiveIdleDays),n=g(d=>d.setAutoArchiveIdleDays),a=g(d=>d.autoArchiveMergedWorktrees),r=g(d=>d.setAutoArchiveMergedWorktrees),o=g(d=>d.autoDeleteArchivedDays),i=g(d=>d.setAutoDeleteArchivedDays);return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.autoArchiveIdleDays",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children: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(Z,{items:Object.fromEntries(xa.map(d=>[String(d),lt(s,d)])),value:String(t),onValueChange:d=>n(Number(d)),children:[e.jsx(ee,{className:"w-28",children:e.jsx(se,{})}),e.jsx(te,{children:xa.map(d=>e.jsx(J,{value:String(d),children:lt(s,d)},d))})]})]}),e.jsx(we,{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(Z,{items:Object.fromEntries(ha.map(d=>[String(d),lt(s,d)])),value:String(o),onValueChange:d=>i(Number(d)),children:[e.jsx(ee,{className:"w-28",children:e.jsx(se,{})}),e.jsx(te,{children:ha.map(d=>e.jsx(J,{value:String(d),children:lt(s,d)},d))})]})]})]})}function uu(){const{t:s}=R(),t=g(o=>o.terminalShell),n=g(o=>o.setTerminalShell),a=$i(window.electronAPI.env.platform),r=Object.fromEntries(a.map(o=>[o,o==="auto"?s("System default"):au[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(Z,{items:r,value:t,onValueChange:o=>n(o),children:[e.jsx(ee,{className:"w-56",children:e.jsx(se,{})}),e.jsx(te,{children:a.map(o=>e.jsx(J,{value:o,children:r[o]},o))})]})]})}function xu(){const{t:s}=R(),t=g(m=>m.worktreeRoot),n=g(m=>m.setWorktreeRoot),[a,r]=l.useState(t),[o,i]=l.useState(null);l.useEffect(()=>{r(t)},[t]);const d=m=>{const p=m.trim();if(p&&!Hm(p)){i(s("Enter an absolute path"));return}i(null),n(p)},u=async()=>{const m=await window.electronAPI.dialog.selectDirectory();m&&(r(m),d(m))};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(X,{value:a,placeholder:s("Default location"),onChange:m=>r(m.target.value),onBlur:()=>d(a),onKeyDown:m=>{m.key==="Enter"&&d(a)}}),e.jsx(y,{variant:"outline",size:"sm",className:"shrink-0",onClick:()=>{u()},children:s("Browse")})]}),o&&e.jsx("p",{className:"text-xs text-destructive",children:o})]})]})}function hu(){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(ss,{})]}),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(Z,{items:a,value:t,onValueChange:r=>n(r),children:[e.jsx(ee,{className:"w-56",children:e.jsx(se,{})}),e.jsx(te,{children:Object.keys(a).map(r=>e.jsx(J,{value:r,children:a[r]},r))})]})]})}function we({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(oe,{checked:n,onCheckedChange:i=>a(i===!0)})]}),o?e.jsx("div",{className:"mt-2",children:o}):null]})}function _a(s,t){window.electronAPI.proxy.apply({mode:s,customUrl:t})}function pu(){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),[d,u]=l.useState(null);l.useEffect(()=>{i(n)},[n]);const m=c=>{a(c),_a(c,n)},p=()=>{const c=o.trim();if(c&&!Vi(c)){u(s("Enter an http(s) proxy URL"));return}u(null),r(c),_a(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(Z,{items:{system:s("Follow system proxy"),none:s("No proxy"),custom:s("Custom proxy")},value:t,onValueChange:c=>m(c),children:[e.jsx(ee,{className:"w-56",children:e.jsx(se,{})}),e.jsxs(te,{children:[e.jsx(J,{value:"system",children:s("Follow system proxy")}),e.jsx(J,{value:"none",children:s("No proxy")}),e.jsx(J,{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(X,{value:o,placeholder:"http://127.0.0.1:7890",onChange:c=>i(c.target.value),onBlur:p,onKeyDown:c=>{c.key==="Enter"&&p()}}),d&&e.jsx("p",{className:"text-xs text-destructive",children:d})]})]})]})}function fu(){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 d=async c=>{n(c),i(!0);try{r(await window.electronAPI.caCert.apply(c))}catch{}finally{i(!1)}},u=async()=>{const c=await window.electronAPI.dialog.selectFile([...Wm]);c&&await d(c)},m={"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:()=>{u()},children:s("Choose certificate file")}),t&&e.jsx(y,{size:"sm",variant:"ghost",disabled:o,onClick:()=>{d("")},children:s("Clear")})]}),a?.error?e.jsx("p",{className:"break-all text-xs text-destructive",children:s("Certificate file unavailable ({{reason}}): {{path}}",{reason:m[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 gu(){const{t:s}=R(),t=g(A=>A.autoUpdate),n=g(A=>A.setAutoUpdate),a=g(A=>A.autoRestartForUpdate),r=g(A=>A.setAutoRestartForUpdate),o=g(A=>A.updateChannel==="beta"?"beta":"stable"),i=g(A=>A.setUpdateChannel),[d,u]=l.useState(null),[m,p]=l.useState(null),[c,f]=l.useState(!1),[x,h]=l.useState(!1);l.useEffect(()=>{let A=!0;window.electronAPI.updater.getState().then(E=>{A&&(p(E),E.status&&u(L=>L??E.status))}).catch(()=>{});const $=window.electronAPI.updater.onStatus(u);return()=>{A=!1,$()}},[]);const j=m?.host==="server"?m:null,b=m?.host==="desktop"||j!==null&&j.mode!=="manual",I=(d?.status==="available"||d?.status==="downloaded")&&!!d.info,S=(()=>{if(!d)return null;switch(d.status){case"checking":return s("Checking for updates…");case"available":return d.manualInstall?s("New version {{version}} found. This local build can't install it automatically.",{version:d.info?.version??""}):s("New version {{version}} found",{version:d.info?.version??""});case"not-available":return s("You are on the latest version");case"downloading":return s("Downloading update… {{percent}}%",{percent:Math.round(d.progress?.percent??0)});case"downloaded":return s("New version {{version}} is downloaded. Restarting waits for the current tool to finish; background commands keep running.",{version:d.info?.version??""});case"error":return d.manualInstall?s("This local build is signed differently from the release and can't install updates automatically. Download it manually."):j&&d.error?s("Update failed: {{error}}",{error:d.error}):s("Update check failed");default:return null}})(),N=d?.status==="checking"||d?.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:j?ju(j.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")," · ",Fa]}),S&&e.jsx("p",{className:W("mt-0.5 text-xs text-muted-foreground",!d?.manualInstall&&"truncate"),children:S})]}),I&&e.jsx(y,{variant:"ghost",size:"sm",onClick:()=>h(!0),className:"ml-auto shrink-0",children:s("Release notes")}),d?.manualInstall?e.jsx(zi,{manualInstall:d.manualInstall}):d?.status==="downloaded"?e.jsx(y,{size:"sm",onClick:()=>{_i(s)},className:"shrink-0",children:s("Restart to update")}):b&&d?.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:N,onClick:()=>{window.electronAPI.updater.checkForUpdates()},className:"shrink-0",children:s("Check for updates")}),e.jsx(Fi,{open:x,onOpenChange:h,status:d,canDownload:b})]}),j?.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:()=>f(!0),className:"shrink-0",children:s("Restart")}),e.jsx(Vr,{open:c,onOpenChange:f,title:s("Restart server?"),description:s("Running tasks are interrupted; this page reconnects after the server is back."),confirmLabel:s("Restart"),onConfirm:()=>{f(!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(oe,{checked:t,onCheckedChange:A=>{n(A),window.electronAPI.updater.setAutoUpdateEnabled(A)}})]}),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 automatically to apply updates")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s(a==="immediate"?"Restart as soon as the update is downloaded, even while agents are running or messages are queued. The restart happens after the current tool finishes, and running sessions keep going afterwards. It still waits while you're using the window (input in the last 2 minutes), while an input box has an unsent draft, or while a question or approval is pending.":a==="idle"?"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.":"Only notify when an update is ready; never restart automatically.")})]}),e.jsxs(Z,{items:{off:s("Off"),idle:s("When idle"),immediate:s("Don't wait for idle")},value:a,disabled:!t,onValueChange:A=>{Bi(A)&&(r(A),window.electronAPI.updater.setAutoRestartMode(A))},children:[e.jsx(ee,{className:"w-32 shrink-0",children:e.jsx(se,{})}),e.jsxs(te,{children:[e.jsx(J,{value:"off",children:s("Off")}),e.jsx(J,{value:"idle",children:s("When idle")}),e.jsx(J,{value:"immediate",children:s("Don't wait for idle")})]})]})]}),m?.host==="desktop"&&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("Update channel")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s(o==="beta"?"Beta builds come from the latest main branch and may be unstable. You get whichever of beta and stable is newer.":"Only stable releases.")}),o==="stable"&&Ui(Fa)&&e.jsx("p",{className:"mt-0.5 text-xs text-muted-foreground",children:s("You're on a beta build. Switching to stable doesn't downgrade; you'll move to the next stable release once it's out.")})]}),e.jsxs(Z,{items:{stable:s("Stable"),beta:s("Beta")},value:o,onValueChange:A=>{const $=A==="beta"?"beta":"stable";i($),window.electronAPI.updater.setChannel($)},children:[e.jsx(ee,{className:"w-32 shrink-0",children:e.jsx(se,{})}),e.jsxs(te,{children:[e.jsx(J,{value:"stable",children:s("Stable")}),e.jsx(J,{value:"beta",children:s("Beta")})]})]})]})]})}function ju(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 Fa="0.3.13",vu=["100%","100%","70%","100%","55%"],bu=["100%","85%","60%"];function yu({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}}),vu.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}}),bu.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 Ba="overflow-hidden rounded-lg border text-left transition-shadow";function wu({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 d=i.id===t;return e.jsxs("button",{type:"button","data-theme-card":i.id,"aria-pressed":d,onClick:()=>a(i.id),className:W(Ba,"bg-card",d?"border-transparent shadow-[0_0_0_2px_var(--brand)]":"hover:border-input"),children:[e.jsx(yu,{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:W("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:W(Ba,"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(Tt,{className:"size-[18px]"}),o("Get more themes")]})]})}function wn({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 Nu({children:s}){return e.jsx("div",{className:"divide-y rounded-lg border bg-card",children:s})}function rs({label:s,value:t,onCommit:n,min:a=0,max:r=100,step:o,unit:i="%",formatSuffix:d,onPreview:u,trailing:m,valueClassName:p="w-12"}){const[c,f]=l.useState(t);l.useEffect(()=>{f(t)},[t]);const x=d?.(c);return e.jsxs("div",{className:W("grid items-center gap-4",m?"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(Qi,{min:a,max:r,step:o,value:c,onValueChange:h=>{const j=Array.isArray(h)?h[0]:h;f(j),u?.(j)},onValueCommitted:h=>n(Array.isArray(h)?h[0]:h)}),e.jsxs("span",{className:W("shrink-0 text-right text-sm text-muted-foreground tabular-nums",x?"w-28":p),children:[c,i,x?` · ${x}`:""]})]}),m]})}function ku(){const{t:s}=R(),t=g(D=>D.backgroundImageEnabled),n=g(D=>D.setBackgroundImageEnabled),a=g(D=>D.backgroundSourceType),r=g(D=>D.setBackgroundSourceType),o=g(D=>D.backgroundImagePath),i=g(D=>D.setBackgroundImagePath),d=g(D=>D.backgroundFolderPath),u=g(D=>D.setBackgroundFolderPath),m=g(D=>D.backgroundUrlPath),p=g(D=>D.setBackgroundUrlPath),c=g(D=>D.backgroundRandomEnabled),f=g(D=>D.setBackgroundRandomEnabled),x=g(D=>D.backgroundRandomInterval),h=g(D=>D.setBackgroundRandomInterval),j=g(D=>D.backgroundOpacity),b=g(D=>D.setBackgroundOpacity),I=g(D=>D.backgroundBlur),C=g(D=>D.setBackgroundBlur),S=g(D=>D.backgroundBrightness),N=g(D=>D.setBackgroundBrightness),A=g(D=>D.backgroundSaturation),$=g(D=>D.setBackgroundSaturation),E=g(D=>D.backgroundMask),L=g(D=>D.setBackgroundMask),M=g(D=>D.backgroundComposerOpacity),k=g(D=>D.setBackgroundComposerOpacity),T=g(D=>D.backgroundCodeOpacity),_=g(D=>D.setBackgroundCodeOpacity),q=g(D=>D.backgroundSizeMode),w=g(D=>D.setBackgroundSizeMode),z=g(D=>D.bumpBackgroundRefresh),H=Zi()?.source==="theme",F=a==="file"?o:a==="folder"?d:m,[G,le]=l.useState(F);l.useEffect(()=>{le(F)},[F]);const B=l.useCallback(()=>{const D=G.trim();a==="file"?i(D):a==="folder"?u(D):p(D)},[G,a,i,u,p]),[ae,K]=l.useState(x);l.useEffect(()=>{K(x)},[x]);const ie=async()=>{if(a==="folder"){const D=await window.electronAPI.dialog.selectDirectory();D&&u(D)}else{const D=await window.electronAPI.dialog.selectFile([...nl,...al]);D&&i(D)}},U=[{value:"file",label:s("Single image")},{value:"folder",label:s("Folder (random)")},{value:"url",label:s("Remote URL")}],ce=[{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(oe,{checked:t,onCheckedChange:D=>n(D===!0)})]}),H&&e.jsx("p",{className:"text-sm text-muted-foreground",children:s("The current theme has its own background. Turn this on to replace it with your image.")}),t&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:s("Source type")}),e.jsxs(Z,{items:U,value:a,onValueChange:D=>r(D),children:[e.jsx(ee,{className:"w-48",children:e.jsx(se,{})}),e.jsx(te,{children:U.map(D=>e.jsx(J,{value:D.value,children:D.label},D.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(X,{value:G,onChange:D=>le(D.target.value),onBlur:B,onKeyDown:D=>{D.nativeEvent.isComposing||D.key==="Enter"&&(B(),D.currentTarget.blur())},placeholder:a==="url"?"https://example.com/image.jpg":"",className:"flex-1"}),a!=="url"&&e.jsx(y,{variant:"outline",size:"icon",onClick:ie,"aria-label":s("Browse"),children:a==="folder"?e.jsx(Dn,{className:"h-4 w-4"}):e.jsx(el,{className:"h-4 w-4"})}),a!=="file"&&e.jsx(y,{variant:"outline",size:"icon",onClick:z,"aria-label":s("Refresh now"),children:e.jsx(is,{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(oe,{checked:c,onCheckedChange:D=>f(D===!0)}),c&&e.jsxs(e.Fragment,{children:[e.jsx(X,{type:"number",min:5,max:86400,value:ae,onChange:D=>K(Number(D.target.value)),onBlur:()=>h(ae),onKeyDown:D=>{D.key==="Enter"&&(h(ae),D.currentTarget.blur())},className:"w-24"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:s("seconds")})]})]})]}),e.jsx(rs,{label:s("Background visibility"),value:Math.round(j*100),onCommit:D=>b(D/100)}),e.jsx(rs,{label:s("Blur"),value:I,onCommit:C,max:20,unit:"px"}),e.jsx(rs,{label:s("Brightness"),value:Math.round(S*100),onCommit:D=>N(D/100),max:200}),e.jsx(rs,{label:s("Saturation"),value:Math.round(A*100),onCommit:D=>$(D/100),max:200}),e.jsx(rs,{label:s("Overlay"),value:Math.round(E*100),onCommit:D=>L(D/100)}),e.jsx(rs,{label:s("Composer opacity"),value:Math.round(M*100),onCommit:D=>k(D/100)}),e.jsx(rs,{label:s("Code block opacity"),value:Math.round(T*100),onCommit:D=>_(D/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(Z,{items:ce,value:q,onValueChange:D=>w(D),children:[e.jsx(ee,{className:"w-48",children:e.jsx(se,{})}),e.jsx(te,{children:ce.map(D=>e.jsx(J,{value:D.value,children:D.label},D.value))})]})]})]})]})}function Cu({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 Su({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(Ta,{className:"h-4 w-4 fill-red-500 text-red-500"}):e.jsx(Ta,{className:"h-4 w-4"})})}function Iu({value:s,onValueChange:t,themes:n,favoriteThemes:a,onToggleFavorite:r,onThemeHover:o,showFavoritesOnly:i,onShowFavoritesOnlyChange:d,showEmptyFavoritesHint:u}){const{t:m}=R(),[p,c]=l.useState(s),[f,x]=l.useState(s),[h,j]=l.useState(!1),b=l.useRef(void 0),I=l.useRef(null),C=l.useRef(s),S=l.useRef(!1),N=l.useMemo(()=>new Set(a),[a]);l.useEffect(()=>{h||(c(s),x(s))},[s,h]);const A=l.useMemo(()=>{if(!f||f===p)return n;const k=f.toLowerCase();return n.filter(T=>T.toLowerCase().includes(k))},[n,f,p]),$=k=>{k&&(S.current=!0,c(k),x(k)),t(k)},E=k=>{j(k),k?(C.current=s,S.current=!1,c(s),x(s)):S.current||o?.(C.current)},L=k=>{clearTimeout(b.current),b.current=setTimeout(()=>{o?.(k)},50)},M=()=>{clearTimeout(b.current)};return l.useEffect(()=>{if(!h)return;const k=T=>{(T.key==="ArrowDown"||T.key==="ArrowUp")&&requestAnimationFrame(()=>{const _=I.current?.querySelector("[data-highlighted]");if(_){const q=_.getAttribute("data-value");q&&o?.(q)}})};return document.addEventListener("keydown",k,!0),()=>{document.removeEventListener("keydown",k,!0)}},[h,o]),l.useEffect(()=>()=>{clearTimeout(b.current)},[]),e.jsxs(zm,{value:p,onValueChange:$,inputValue:f,onInputValueChange:x,open:h,onOpenChange:E,children:[e.jsxs("div",{className:"relative",children:[e.jsx(_m,{placeholder:m("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(Re,{id:"show-favorites-only-inner",checked:i,onCheckedChange:k=>d(k===!0),onClick:k=>k.stopPropagation()}),e.jsx("label",{htmlFor:"show-favorites-only-inner",className:"text-xs text-muted-foreground cursor-pointer whitespace-nowrap",onClick:k=>k.stopPropagation(),onKeyDown:k=>k.stopPropagation(),children:m("Show favorites only")})]})]}),e.jsx(Bm,{children:e.jsxs($m,{ref:I,children:[A.length===0&&e.jsx("div",{className:"py-6 text-center text-sm text-muted-foreground",children:m(u?"No favorite themes yet. Click the heart icon to add favorites.":"No themes found")}),A.map(k=>e.jsx(Um,{value:k,"data-value":k,onMouseEnter:()=>L(k),onMouseLeave:M,endAddon:e.jsx(Su,{isFavorite:N.has(k),onClick:()=>r(k),ariaLabel:N.has(k)?m("Remove from favorites"):m("Add to favorites")}),children:k},k))]})})]})}const Au={theme:"Follow theme",violet:"Violet",indigo:"Indigo",teal:"Teal",amber:"Amber",graphite:"Graphite"},Ua={body:"Body",h1:"Heading 1",h2:"Heading 2",h3:"Heading 3",h4:"Heading 4–6",table:"Table",inlineCode:"Inline code",codeBlock:"Code block"},$a=qr.map(s=>({value:String(s),label:String(s)}));function Eu(){const{t:s}=R(),t=g(u=>u.chatTypography),n=g(u=>u.setChatTypography),a=g(u=>u.resetChatTypography),[r,o]=l.useState(t.body.size);l.useEffect(()=>{o(t.body.size)},[t.body.size]);const i=(u,m)=>{const p=g.getState().chatTypography;n({...p,[u]:{...p[u],size:m}})},d=(u,m)=>{const p=g.getState().chatTypography;n({...p,[u]:{...p[u],weight:m}})};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:[sl.map(u=>{const m=tl[u];return e.jsx(rs,{label:s(Ua[u]),value:t[u].size,min:m.min,max:m.max,step:m.step,unit:m.unit==="%"?"%":"px",valueClassName:"w-28",formatSuffix:m.unit==="%"?p=>`${(r*p/100).toFixed(1)}px`:void 0,onPreview:u==="body"?o:void 0,onCommit:p=>i(u,p),trailing:e.jsxs(Z,{items:$a,value:String(t[u].weight),onValueChange:p=>{const c=Number(p);qr.includes(c)&&d(u,c)},children:[e.jsx(ee,{className:"w-24 min-w-24","aria-label":s(Ua[u]),children:e.jsx(se,{})}),e.jsx(te,{children:$a.map(p=>e.jsx(J,{value:p.value,children:p.label},p.value))})]})},u)}),e.jsx("div",{className:"flex justify-end",children:e.jsx(y,{variant:"outline",size:"sm",onClick:()=>a(),children:s("Reset to defaults")})})]})]})}function Mu({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 d=rl(i);t(d),r(String(d))};return e.jsxs("div",{className:"flex items-center justify-between gap-3","data-settings-row":"appearance.liveActivityFoldDelaySec",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:n("Wait before folding")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n("Seconds to wait after tools and thinking finish")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(X,{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 Pu(){const{t:s}=R(),t=g(k=>k.openChangesOnFileEdit),n=g(k=>k.setOpenChangesOnFileEdit),a=g(k=>k.compactReadOnlyTools),r=g(k=>k.setCompactReadOnlyTools),o=g(k=>k.expandLiveEdits),i=g(k=>k.setExpandLiveEdits),d=g(k=>k.expandLiveReasoning),u=g(k=>k.setExpandLiveReasoning),m=g(k=>k.autoCollapseTurns),p=g(k=>k.setAutoCollapseTurns),c=g(k=>k.collapseCompletedActivity),f=g(k=>k.setCollapseCompletedActivity),x=g(k=>k.collapseLiveActivity),h=g(k=>k.setCollapseLiveActivity),j=g(k=>k.liveActivityFoldDelaySec),b=g(k=>k.setLiveActivityFoldDelaySec),I=g(k=>k.pinUnfinishedTodos),C=g(k=>k.setPinUnfinishedTodos),S=g(k=>k.headerSessionTabs),N=g(k=>k.setHeaderSessionTabs),A=g(k=>k.headerRecentMinutes),$=g(k=>k.setHeaderRecentMinutes),E=k=>k===0?s("Off"):s("{{count}} min",{count:k}),L=g(k=>k.navRailSide),M=g(k=>k.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(we,{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(we,{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(we,{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(we,{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:d,onChange:u}),e.jsx(we,{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:m,onChange:p}),e.jsx(we,{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(we,{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:x,onChange:h,children:x?e.jsx(Mu,{seconds:j,onCommit:b}):null}),e.jsx(we,{rowId:"appearance.pinUnfinishedTodos",title:s("Pin unfinished todos"),description:s("Keep the latest todo list above the input while it has unfinished items, so it does not scroll away with the timeline"),checked:I,onChange:C}),e.jsx(we,{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:S,onChange:N,children:S&&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(Z,{items:Object.fromEntries(gt.map(k=>[String(k),E(k)])),value:String(A),onValueChange:k=>$(Number(k)),children:[e.jsx(ee,{className:"w-28",children:e.jsx(se,{})}),e.jsx(te,{children:gt.map(k=>e.jsx(J,{value:String(k),children:E(k)},k))})]})]})}),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(On,{value:L,options:[{value:"left",label:s("Left")},{value:"right",label:s("Right")},{value:"off",label:s("Off")}],onChange:M})})]})]}),e.jsx(Eu,{}),e.jsx(Gm,{})]})}function Tu({onOpenPlugins:s}){const{t}=R(),n=g(i=>i.themeId),a=g(i=>i.setThemeId),r=Tn(i=>i.themes),o=Kr();return e.jsxs("section",{"data-settings-row":"appearance.themeGallery",className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:t("Theme")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("Built-in and plugin themes; each one is a set of color tokens")})]}),e.jsx(wu,{themes:Wr(r),selected:n,mode:o,onSelect:a,onGetMore:s})]})}function Ru(){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||Ie({type:"error",title:s("Cannot open user.css"),description:r.error})};return e.jsxs(wn,{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(Xi,{}),s("Open user.css")]}),e.jsx(oe,{checked:t,onCheckedChange:r=>n(r===!0),"aria-label":s("Custom CSS")})]})}function Ou({onOpenPlugins:s}={}){const t=g(U=>U.borderOpacity),n=g(U=>U.setBorderOpacity),{theme:a,setTheme:r,themeId:o,accentColor:i,setAccentColor:d,terminalTheme:u,setTerminalTheme:m,terminalFontSize:p,setTerminalFontSize:c,terminalFontFamily:f,setTerminalFontFamily:x,terminalFontWeight:h,setTerminalFontWeight:j,terminalFontWeightBold:b,setTerminalFontWeightBold:I,favoriteTerminalThemes:C,toggleFavoriteTerminalTheme:S}=g(),{t:N}=R(),A=Kr(),$=Tn(U=>U.themes),E=[{value:"light",icon:Sm,label:N("Light")},{value:"dark",icon:Ki,label:N("Dark")},{value:"system",icon:Rn,label:N("System")},{value:"sync-terminal",icon:Gr,label:N("Sync terminal theme")}],L=Gi.map(U=>({value:U,label:N(Au[U]),swatch:U==="theme"?Hi(o,Wr($))[A].accent:Wi[U][A]})),[M,k]=l.useState(p),[T,_]=l.useState(f),[q,w]=l.useState(!1);l.useEffect(()=>{k(p)},[p]),l.useEffect(()=>{_(f)},[f]);const z=l.useCallback(()=>{const U=Math.max(8,Math.min(32,M||8));U!==M&&k(U),U!==p&&c(U)},[M,p,c]),H=l.useCallback(()=>{const U=T.trim()||f;U!==T&&_(U),U!==f&&x(U)},[T,f,x]),F=l.useMemo(()=>qi(),[]),G=l.useMemo(()=>{if(!q)return F;const U=F.filter(ce=>C.includes(ce));return C.includes(u)?U:[u,...U]},[F,q,C,u]),le=q&&C.length===0,B=l.useMemo(()=>Ji(u)??Yi,[u]),ae=U=>{U&&m(U)},K=()=>{const U=q?G:F,ce=U.indexOf(u),de=ce<=0?U.length-1:ce-1;m(U[de])},ie=()=>{const U=q?G:F,ce=U.indexOf(u),de=ce>=U.length-1?0:ce+1;m(U[de])};return e.jsxs("div",{className:"space-y-6",children:[e.jsx(Tu,{onOpenPlugins:s}),e.jsxs("section",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:N("Personalization")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:N("Applied on top of any theme")})]}),e.jsxs(Nu,{children:[e.jsx(wn,{rowId:"appearance.theme",title:N("Theme mode"),children:e.jsx("div",{className:"flex rounded-lg bg-muted p-0.5",children:E.map(U=>e.jsxs("button",{type:"button",onClick:()=>r(U.value),"aria-pressed":a===U.value,className:W("flex h-7 items-center gap-1.5 rounded-md px-2.5 text-xs transition-colors",a===U.value?"bg-background text-foreground shadow-xs":"text-muted-foreground hover:text-foreground"),children:[e.jsx(U.icon,{className:"size-3.5"}),U.label]},U.value))})}),e.jsx(wn,{rowId:"appearance.accent",title:N("Accent color"),description:N("Used for running state, checkmarks and plan mode"),children:L.map(U=>U.value==="theme"?e.jsxs("button",{type:"button",onClick:()=>d(U.value),"aria-pressed":i===U.value,className:W("flex h-6 items-center gap-1.5 rounded-full border px-2 text-xs transition-shadow",i===U.value&&"border-transparent ring-2 ring-foreground/60"),children:[e.jsx("span",{"data-theme-accent":!0,className:"size-2.5 rounded-full",style:{backgroundColor:U.swatch}}),U.label]},U.value):e.jsx("button",{type:"button",onClick:()=>d(U.value),title:U.label,"aria-label":U.label,"aria-pressed":i===U.value,style:{backgroundColor:U.swatch},className:W("size-5 rounded-full transition-shadow",i===U.value&&"ring-2 ring-offset-2 ring-offset-card ring-foreground/60")},U.value))}),e.jsx(Ru,{})]})]}),e.jsx(Pu,{}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:N("Terminal")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:N("Terminal appearance")})]}),e.jsx(Cu,{theme:B,fontSize:M,fontFamily:T,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:N("Color scheme")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{variant:"outline",size:"icon",onClick:K,children:e.jsx(Hr,{className:"h-4 w-4"})}),e.jsx("div",{className:"flex-1",children:e.jsx(Iu,{value:u,onValueChange:ae,themes:G,favoriteThemes:C,onToggleFavorite:S,onThemeHover:m,showFavoritesOnly:q,onShowFavoritesOnlyChange:w,showEmptyFavoritesHint:le})}),e.jsx(y,{variant:"outline",size:"icon",onClick:ie,children:e.jsx(Gs,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:N("Font")}),e.jsx(X,{value:T,onChange:U=>_(U.target.value),onBlur:H,onKeyDown:U=>{U.nativeEvent.isComposing||U.key==="Enter"&&(H(),U.currentTarget.blur())},placeholder:"JetBrains Mono, monospace"})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:N("Font size")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(X,{type:"number",value:M,onChange:U=>k(Number(U.target.value)),onBlur:z,onKeyDown:U=>{U.key==="Enter"&&(z(),U.currentTarget.blur())},min:8,max:32,className:"w-20"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"px"})]})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:N("Font weight")}),e.jsxs(Z,{items:rt,value:h,onValueChange:U=>j(U),children:[e.jsx(ee,{className:"w-48",children:e.jsx(se,{})}),e.jsx(te,{children:rt.map(U=>e.jsx(J,{value:U.value,children:U.label},U.value))})]})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:N("Bold font weight")}),e.jsxs(Z,{items:rt,value:b,onValueChange:U=>I(U),children:[e.jsx(ee,{className:"w-48",children:e.jsx(se,{})}),e.jsx(te,{children:rt.map(U=>e.jsx(J,{value:U.value,children:U.label},U.value))})]})]})]}),e.jsx(rs,{label:N("Border opacity"),value:Math.round(t*100),onCommit:U=>n(U/100)}),e.jsx(ku,{})]})}const Va=15e3,Du=3e3;function Lu(s){return!s||!s.timeoutSet&&s.timeoutMs===Du?Va:s.timeoutMs}const Ka=()=>{},Jt="off",Xt=s=>({timeoutMs:s?.timeoutMs??ol,...s?.timeoutSet&&{timeoutSet:!0}});function zu({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 d=()=>{const u=Number(o);if(!o.trim()||!Number.isFinite(u))return i(String(t/1e3));const m=cl(u*1e3);i(String(m/1e3)),m!==t&&a({...s,timeoutMs:m,timeoutSet:!0})};return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs",children:r("Timeout")}),e.jsx(X,{type:"number",value:o,min:ll/1e3,max:il/1e3,step:.5,className:"h-7 w-20 text-xs",onChange:u=>i(u.target.value),onBlur:d,onKeyDown:u=>{u.key==="Enter"&&u.currentTarget.blur()}}),e.jsx("span",{className:"text-xs text-muted-foreground",children:r("seconds")}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:n})]})}function pt({providers:s,value:t,emptyLabel:n,onSelect:a}){return e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx(ze,{providers:s,providerId:t?.providerId??"",modelId:t?.modelId??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:n,side:"bottom",triggerClassName:es,onSelect:(r,o)=>a({providerId:r,modelId:o}),onReasoningChange:Ka,onThinkingChange:Ka})})}function ct({label:s,hint:t,children:n}){return e.jsxs("div",{className:"grid grid-cols-[6rem_1fr] items-start gap-2",children:[e.jsxs("div",{className:"pt-1.5 text-xs",children:[e.jsx("div",{children:s}),t&&e.jsx("div",{className:"text-[10px] text-muted-foreground",children:t})]}),e.jsx("div",{className:"min-w-0 space-y-1",children:n})]})}function zo({value:s,onChange:t,providers:n,classifierProviders:a,offLabel:r,judgeLabel:o,judgeSeed:i,description:d,effectiveTimeoutMs:u,timeoutHint:m}){const{t:p}=R(),c=s,[f,x]=l.useState(!1),h=c?.source??(f?"judge":Jt),j=c?.source==="pi-classifier"?c.model.providerId:"",[b,I]=l.useState([]),[C,S]=l.useState(!1);l.useEffect(()=>{if(!j){I([]);return}let E=!1;return window.electronAPI.providers.classifierModels(j).then(L=>{E||I(L)}),()=>{E=!0}},[j]);const N=async E=>{const M=(await window.electronAPI.providers.classifierModels(E))[0];S(!M),M&&t({source:"pi-classifier",model:{providerId:E,modelId:M.id},...Xt(c)})},A=E=>{if(S(!1),x(E==="judge"&&!i),E===Jt)return t(void 0);if(E==="judge")return t(i?{source:"judge",model:i,...Xt(c)}:void 0);const L=a[0];L&&N(L.id)},$=[{value:Jt,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(Z,{items:$,value:h,onValueChange:E=>A(String(E)),children:[e.jsx(ee,{size:"sm",className:"w-48",children:e.jsx(se,{})}),e.jsx(te,{children:$.map(E=>e.jsx(J,{value:E.value,children:E.label},E.value))})]}),h==="judge"&&e.jsx(pt,{providers:n,value:c?.source==="judge"?c.model:void 0,emptyLabel:p("Select model"),onSelect:E=>{x(!1),t({source:"judge",model:E,...Xt(c)})}}),c?.source==="pi-classifier"&&e.jsxs("div",{className:"flex gap-1",children:[e.jsxs(Z,{items:a.map(E=>({value:E.id,label:E.name})),value:c.model.providerId,onValueChange:E=>{N(String(E))},children:[e.jsx(ee,{size:"sm",className:"w-40",children:e.jsx(se,{})}),e.jsx(te,{children:a.map(E=>e.jsx(J,{value:E.id,children:E.name},E.id))})]}),e.jsxs(Z,{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(ee,{size:"sm",className:"min-w-0 flex-1",children:e.jsx(se,{placeholder:p("Select model")})}),e.jsx(te,{children:b.map(E=>e.jsx(J,{value:E.id,children:E.name},E.id))})]})]}),C&&e.jsx("p",{className:"text-[10px] text-destructive",children:p("No classifier models available")}),c&&e.jsx(zu,{classifier:c,effectiveMs:u??c.timeoutMs,hint:m,onChange:t}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:d})]})}function _u({entry:s,providers:t,classifierProviders:n,update:a}){const{t:r}=R();return s.fast?e.jsx(zo,{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 Fu({entry:s,providers:t,classifierProviders:n}){const{t:a}=R(),r=g(m=>m.updateVirtualModel),o=g(m=>m.removeVirtualModel),i=[s.primary,...s.fast?[s.fast]:[],...s.fallbacks];let d;for(const m of t){const p=m.models.find(c=>c.enabled!==!1&&!i.some(f=>f.providerId===m.id&&f.modelId===c.id));if(p){d={providerId:m.id,modelId:p.id};break}}const u=m=>r(s.id,m);return e.jsxs("div",{"data-slot":"virtual-model-card",className:W("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(oe,{"aria-label":a("Enable virtual model"),checked:s.enabled,onCheckedChange:m=>u({enabled:m})}),e.jsx(X,{value:s.name,maxLength:60,placeholder:"Auto",className:"h-7 flex-1 text-xs",onChange:m=>u({name:m.target.value})}),!s.enabled&&e.jsx(ne,{variant:"outline",className:"shrink-0 text-[10px] text-muted-foreground",children:a("Disabled")}),e.jsx(y,{type:"button",variant:"ghost",size:"icon","aria-label":a("Delete"),className:"h-6 w-6 shrink-0 text-muted-foreground hover:text-destructive",onClick:()=>o(s.id),children:e.jsx(Ee,{className:"h-3.5 w-3.5"})})]}),e.jsx(ct,{label:a("Primary model"),hint:a("Default for each new turn"),children:e.jsx(pt,{providers:t,value:s.primary,onSelect:m=>u({primary:m,fallbacks:s.fallbacks.filter(p=>p.providerId!==m.providerId||p.modelId!==m.modelId)})})}),e.jsx(ct,{label:a("Fast model"),hint:a("Summaries and simple turns"),children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(pt,{providers:t,value:s.fast,emptyLabel:a("Not used"),onSelect:m=>u({fast:m})}),s.fast&&e.jsx(y,{type:"button",variant:"ghost",size:"icon","aria-label":a("Clear"),className:"h-6 w-6 shrink-0 text-muted-foreground",onClick:()=>u({fast:void 0}),children:e.jsx(gs,{className:"h-3.5 w-3.5"})})]})}),e.jsxs(ct,{label:a("Fallback models"),hint:a("Used in order when a model is rate limited or down"),children:[s.fallbacks.map((m,p)=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(pt,{providers:t,value:m,onSelect:c=>u({fallbacks:s.fallbacks.map((f,x)=>x===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:()=>u({fallbacks:s.fallbacks.filter((c,f)=>f!==p)}),children:e.jsx(gs,{className:"h-3.5 w-3.5"})})]},`${m.providerId}/${m.modelId}`)),e.jsxs(y,{type:"button",variant:"outline",size:"sm",className:"h-7 text-xs",disabled:!d||s.fallbacks.length>=8,onClick:()=>{d&&u({fallbacks:[...s.fallbacks,d]})},children:[e.jsx(Ae,{className:"mr-1 h-3.5 w-3.5"}),a("Add fallback")]})]}),e.jsx(ct,{label:a("Difficulty routing"),children:e.jsx(_u,{entry:s,providers:t,classifierProviders:n,update:u})})]})}function Bu(){const{t:s}=R(),t=g(u=>u.virtualModels),n=g(u=>u.addVirtualModel),a=g(u=>u.defaultModel),r=ts(),o=l.useMemo(()=>r.filter(Yr),[r]),i=Ln(),d=l.useMemo(()=>{if(a&&o.find(m=>m.id===a.providerId)?.models.some(m=>m.id===a.modelId&&m.enabled!==!1))return a;for(const u of o){const m=u.models.find(p=>p.enabled!==!1);if(m)return{providerId:u.id,modelId:m.id}}return null},[o,a]);return e.jsxs("section",{"data-slot":"virtual-models",className:"space-y-2 rounded-lg border bg-card p-3",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium text-sm",children:s("Virtual models")}),e.jsx("p",{className:"mt-0.5 text-muted-foreground text-xs",children:s("A virtual model appears as one model in the picker and routes each request to a real model: fallbacks on rate limits or outages, image-capable or larger-context members when needed, and the fast model for summaries.")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:s("Applies to newly started conversations.")})]}),e.jsxs("div",{className:"space-y-2",children:[t.map(u=>e.jsx(Fu,{entry:u,providers:o,classifierProviders:i},u.id)),e.jsxs(y,{type:"button",variant:"outline",size:"sm",className:"h-7 text-xs",disabled:!d,onClick:()=>{d&&n({name:"Auto",enabled:!0,primary:d,fallbacks:[]})},children:[e.jsx(Ae,{className:"mr-1 h-3.5 w-3.5"}),s("New virtual model")]}),!d&&e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Enable a model and configure valid provider credentials first.")})]})]})}function Uu(){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(Ku,{}),e.jsx(Gu,{}),e.jsx($u,{}),e.jsx(Vu,{})]})}function $u(){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(ne,{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(oe,{checked:n,onCheckedChange:r=>a(r===!0)})]}):null}const Ga=Array.from({length:dl-pa+1},(s,t)=>pa+t);function Vu(){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(Z,{items:Object.fromEntries(Ga.map(a=>[String(a),String(a)])),value:String(t),onValueChange:a=>n(Number(a)),children:[e.jsx(ee,{className:"w-20",children:e.jsx(se,{})}),e.jsx(te,{children:Ga.map(a=>e.jsx(J,{value:String(a),children:a},a))})]})]})}function Ku(){const{t:s}=R(),t=g(i=>i.botAssistantModel),n=g(i=>i.setBotAssistantModel),a=ts(),r=t?a.find(i=>i.id===t.providerId):void 0,o=r?.models.find(i=>i.id===t?.modelId);return e.jsxs("div",{className:"rounded-md border px-3 py-2.5","data-settings-row":"bots.assistantModel",children:[e.jsx("p",{className:"text-sm",children:s("Bot assistant model")}),e.jsx("p",{className:"mb-2 text-xs text-muted-foreground",children:s("Used for helper tasks such as auto-configuring member abilities.")}),e.jsx(ze,{providers:a,providerId:o?r?.id??"":"",modelId:o?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:s("Follows the default model"),side:"bottom",triggerClassName:es,onSelect:(i,d)=>n({providerId:i,modelId:d}),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 Gu(){const{t:s}=R(),t=g(d=>d.botRouteClassifier),n=g(d=>d.setBotRouteClassifier),a=g(d=>d.botDiscussModeEnabled),r=ts(),o=l.useMemo(()=>r.filter(Yr),[r]),i=Ln();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(zo,{value:t??void 0,onChange:d=>n(d??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?Lu(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 Wu=()=>({name:"",title:"",scope:"",summary:"",persona:"",color:fn[0],tools:"all",approvalMode:"auto-edits"}),Nn=(s,t)=>({key:s,name:"",title:"",scope:"",persona:"",color:fn[t%fn.length],tools:"all",approvalMode:"auto-edits",canDelegateTo:[],acceptFrom:[]}),Hu=()=>({title:"",summary:"",bossKey:"m1",workspace:"chat-home",members:[Nn("m1",0),Nn("m2",1)]});function qu(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 Yu(){const{t:s}=R(),t=ml(!0),n=ul(!0),[a,r]=l.useState(null),[o,i]=l.useState(null),d=l.useRef(null),u=async(h,j)=>{const b=await Cl(I=>({...I,[h]:j(I[h])}));return b||Ie({type:"error",title:s("Could not save templates")}),b},m=(h,j)=>u("members",b=>h?ja(b,h,j,El):va(b,j,crypto.randomUUID())),p=(h,j)=>u("teams",b=>h?ja(b,h,j,Ml):va(b,j,crypto.randomUUID())),c=async h=>{const j=gl(await h.text());if(!j.ok){Ie({type:"error",title:fa(j.error,s)});return}const b=Xr(jl(j.team));if(!b){Ie({type:"error",title:fa("invalid",s)});return}await p(void 0,b)&&Ie({type:"success",title:s("Imported as a custom team template")})},f=(h,j)=>u(h==="members"?"members":"teams",j),x=(h,j,b)=>e.jsxs(e.Fragment,{children:[e.jsx(fs,{label:s("Edit"),onClick:()=>b({id:j.id,data:j.data}),children:e.jsx(ms,{})}),e.jsx(fs,{label:s("Duplicate as custom"),onClick:()=>b({data:j.data}),children:e.jsx(Jr,{})}),j.source==="builtin"&&e.jsx(fs,{label:j.hidden?s("Show"):s("Hide"),onClick:()=>{f(h,I=>Sl(I,j.id,!j.hidden))},children:j.hidden?e.jsx(pl,{}):e.jsx(fl,{})}),j.modified&&e.jsx(fs,{label:s("Restore default"),onClick:()=>{f(h,I=>ba(I,j.id))},children:e.jsx(zn,{})}),j.source==="custom"&&e.jsx(fs,{label:s("Delete"),onClick:()=>{f(h,I=>ba(I,j.id))},children:e.jsx(Ee,{})})]});return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("Bot templates")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("Templates used when creating members and teams. Built-in templates can be edited, hidden or restored.")})]}),e.jsxs(Ws,{defaultValue:"members",children:[e.jsxs(Hs,{variant:"underline",children:[e.jsx(He,{value:"members",children:s("Member templates")}),e.jsx(He,{value:"teams",children:s("Team templates")})]}),e.jsxs(Bs,{value:"members",className:"space-y-2 pt-3",children:[e.jsxs(y,{size:"sm",variant:"outline",onClick:()=>r({data:Wu()}),children:[e.jsx(Ae,{}),s("New member template")]}),t.map(h=>e.jsx(Wa,{item:h,avatar:e.jsx(pn,{bot:{name:h.data.name,avatar:{color:h.data.color}}}),title:h.data.name,subtitle:h.data.title,summary:h.data.summary,actions:x("members",h,r)},h.id))]}),e.jsxs(Bs,{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:Hu()}),children:[e.jsx(Ae,{}),s("New team template")]}),e.jsxs(y,{size:"sm",variant:"outline",onClick:()=>d.current?.click(),children:[e.jsx(xl,{}),s("Import team (JSON)")]}),e.jsx("input",{ref:d,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(Wa,{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(pn,{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(fs,{label:s("Export JSON"),onClick:()=>qu(`${h.data.title||"team"}.team.json`,{format:Al,version:Il,exportedAt:new Date().toISOString(),team:hl(h.data)}),children:e.jsx(Mn,{})}),x("teams",h,i)]})},h.id))]})]}),a&&e.jsx(Ju,{initial:a.data,onClose:()=>r(null),onSave:async h=>{await m(a.id,h)&&r(null)}}),o&&e.jsx(Qu,{initial:o.data,onClose:()=>i(null),onSave:async h=>{await p(o.id,h)&&i(null)}})]})}function fs({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 Wa({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:W("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(ne,{variant:"secondary",children:s.source==="custom"?i("Custom"):i("Built-in")}),s.modified&&e.jsx(ne,{variant:"outline",children:i("Modified")}),s.hidden&&e.jsx(ne,{variant:"outline",children:i("Hidden")})]}),e.jsx("p",{className:"truncate text-muted-foreground text-xs",children:r})]})]}),e.jsx("div",{className:"flex shrink-0 items-center",children:o})]})}function _o({title:s,error:t,onClose:n,onSave:a,children:r}){const{t:o}=R(),[i,d]=l.useState(!1);return e.jsx(pe,{open:!0,onOpenChange:u=>!u&&n(),children:e.jsxs(fe,{className:"max-h-[85vh] max-w-2xl",children:[e.jsx(ge,{children:e.jsx(je,{children:s})}),e.jsxs(ve,{className:"space-y-3",children:[r,t&&e.jsx("p",{className:"text-destructive text-xs",children:t})]}),e.jsxs(ke,{children:[e.jsx(y,{variant:"outline",size:"sm",onClick:n,children:o("Cancel")}),e.jsx(y,{size:"sm",disabled:i||!!t,onClick:()=>{d(!0),a().finally(()=>d(!1))},children:o("Save")})]})]})})}function Fo({value:s,onChange:t}){const{t:n}=R(),a=s.name?Qr(s.name,[],n):null;return e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx($e,{children:n("Name")}),e.jsx(X,{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($e,{children:n("Title")}),e.jsx(X,{value:s.title,onChange:r=>t({title:r.target.value})})]}),e.jsxs("div",{children:[e.jsx($e,{children:n("Avatar color")}),e.jsx(Nl,{value:s.color,onChange:r=>t({color:r})})]}),e.jsxs("div",{children:[e.jsx($e,{children:n("Tools")}),e.jsx(On,{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($e,{children:n("Approval mode")}),e.jsx(kl,{value:s.approvalMode,onChange:r=>t({approvalMode:r}),zIndex:os.DROPDOWN_IN_MODAL})]}),s.summary!==void 0&&e.jsxs("div",{className:"col-span-2",children:[e.jsx($e,{hint:n("Shown on the template card"),children:n("Summary")}),e.jsx(X,{value:s.summary,onChange:r=>t({summary:r.target.value})})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx($e,{children:n("Responsibilities")}),e.jsx(X,{value:s.scope,onChange:r=>t({scope:r.target.value})})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx($e,{children:n("Persona")}),e.jsx(Qe,{rows:6,value:s.persona,onChange:r=>t({persona:r.target.value})})]})]})}function Ju({initial:s,onClose:t,onSave:n}){const{t:a}=R(),[r,o]=l.useState(s),i=vl(r);return e.jsx(_o,{title:a("Member template"),error:Qr(r.name,[],a)??(i?null:a("Check the template fields")),onClose:t,onSave:()=>i?n(i):Promise.resolve(),children:e.jsx(Fo,{value:r,onChange:d=>o(u=>({...u,...d}))})})}function Xu(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 Qu({initial:s,onClose:t,onSave:n}){const{t:a}=R(),[r,o]=l.useState(s),[i,d]=l.useState(null),u=h=>r.members.find(j=>j.key===h)?.name||h,m=h=>o(j=>({...j,...h})),p=(h,j)=>o(b=>({...b,members:b.members.map(I=>I.key===h?{...I,...j}:I)})),c=()=>{const h=new Set(r.members.map(I=>I.key));let j=r.members.length+1;for(;h.has(`m${j}`);)j++;const b=`m${j}`;m({members:[...r.members,Nn(b,r.members.length)]}),d(b)},f=h=>{const j=b=>b==="any"?"any":b.filter(I=>I!==h);m({members:r.members.filter(b=>b.key!==h).map(b=>({...b,canDelegateTo:j(b.canDelegateTo),acceptFrom:j(b.acceptFrom)}))})},x=Xr(r);return e.jsxs(_o,{title:a("Team template"),error:Xu(wl(r),a),onClose:t,onSave:()=>x?n(x):Promise.resolve(),children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx($e,{children:a("Group name")}),e.jsx(X,{value:r.title,onChange:h=>m({title:h.target.value})})]}),e.jsxs("div",{children:[e.jsx($e,{children:a("Owner")}),e.jsxs(Z,{items:r.members.map(h=>({value:h.key,label:u(h.key)})),value:r.bossKey,onValueChange:h=>m({bossKey:h}),children:[e.jsx(ee,{className:"w-full",children:e.jsx(se,{})}),e.jsx(te,{zIndex:os.DROPDOWN_IN_MODAL,children:r.members.map(h=>e.jsx(J,{value:h.key,children:u(h.key)},h.key))})]})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx($e,{hint:a("Shown on the template card"),children:a("Summary")}),e.jsx(X,{value:r.summary,onChange:h=>m({summary:h.target.value})})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx($e,{children:a("Shared workspace")}),e.jsx(On,{value:r.workspace,options:[{value:"chat-home",label:a("Standalone workspace")},{value:"project",label:a("Based on a Code project")}],onChange:h=>m({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>=bl,onClick:c,children:[e.jsx(Ae,{}),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,I=r.members.filter(C=>C.key!==h.key).map(C=>C.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:()=>d(j?null:h.key),children:[j?e.jsx(vt,{className:"h-3.5 w-3.5 shrink-0"}):e.jsx(Gs,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx(pn,{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(yl,{className:"h-3 w-3"}),a("Owner")]})]}),e.jsx(fs,{label:a("Remove"),disabled:b||r.members.length<=2,onClick:()=>f(h.key),children:e.jsx(Ee,{})})]}),j&&e.jsxs("div",{className:"space-y-3 border-t p-2.5",children:[e.jsx(Fo,{value:h,onChange:C=>p(h.key,C)}),e.jsx(ga,{label:a("Can delegate to"),value:h.canDelegateTo,options:I,nameOf:u,onChange:C=>p(h.key,{canDelegateTo:C})}),e.jsx(ga,{label:a("Accepts delegation from"),value:h.acceptFrom,options:I,nameOf:u,onChange:C=>p(h.key,{acceptFrom:C})})]})]},h.key)})})]})]})}function Bo(s){return s.capturePermission==="unsupported"&&s.axPermission==="unsupported"?"unsupported":s.capturePermission==="granted"&&(s.axPermission==="granted"||s.axPermission==="unsupported")?"ready":"needs-permission"}const Zu=[{id:"collaboration",label:"Collaboration & planning"},{id:"web",label:"Web"},{id:"execution",label:"Execution"},{id:"context",label:"Context & memory"},{id:"safety",label:"Safety"}],Ha={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 ex(s,t){return s.filter(n=>Object.hasOwn(Ha,n.id)?Ha[n.id]===t:!1)}function qa(s){return s.bundleId||s.path}function sx(){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(d=>{i||n(d)}),()=>{i=!0}},[]);const o=async i=>{await window.electronAPI.computer.revokeApp(qa(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(oe,{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")})]},qa(i)))}):null]})}function tx(s){return Object.fromEntries(s.map(t=>[t.id,t]))}function Ot(s,t){return s.reduce((n,a)=>{const r=t[a]?.tokens;return r==null?n:n+r},0)}function Dt({row:s,pending:t}){const{t:n}=R(),a=t?"…":s?.tokens==null?"—":Ke(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 Lt({tokens:s}){return s<=0?null:e.jsx("span",{className:"ml-2 font-normal text-muted-foreground text-xs tabular-nums",children:Ke(s)})}function zt(s,t){const[n,a]=l.useState({}),[r,o]=l.useState(()=>s.length>0),i=s.join("\0"),d=l.useRef(t);return d.current=t,l.useEffect(()=>{let u=!1;const m=i.length===0?[]:i.split("\0");if(m.length===0){a({}),o(!1);return}return o(!0),d.current(m).then(p=>{u||a(tx(p))}).finally(()=>{u||o(!1)}),()=>{u=!0}},[i]),{rows:n,pending:r}}const Ya={replace:"Text replacement",apply_patch:"Apply patch (default)"},nx={subagent:_l,workflow:_n,todo:zl,plan:Ll,ask_user:Dl,browser:Ol,web:eo,background_tasks:Rl,memory:Zr,isolated_sandbox:am,computer:Rn,turn_discard:Tl};function Ss({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(ss,{note:typeof i=="string"?i:void 0})]}),e.jsx("p",{className:"text-muted-foreground text-xs",children:n})]}),a]}),r?e.jsx("div",{className:"mt-2 space-y-2 pl-7",children:r}):null]})}function ax({disabled:s}){const{t}=R(),n=g(c=>c.webSearchChain),a=g(c=>c.setWebSearchChain),r=qs(),o=l.useMemo(()=>Ul(r),[r]),[i,d]=l.useState(null),u=(c,f)=>{a(n.map((x,h)=>h===c?{...x,...f}:x))},m=c=>a(n.filter((f,x)=>x!==c)),p=(c,f)=>{if(c===f)return;const x=[...n],[h]=x.splice(c,1);h&&(x.splice(f,0,h),a(x))};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:x=>{x.dataTransfer.effectAllowed="move",d(f)},onDragEnd:()=>d(null),onDragOver:x=>{i!==null&&i!==f&&x.preventDefault()},onDrop:x=>{x.preventDefault(),i!==null&&p(i,f),d(null)},children:[e.jsx($l,{className:"h-3.5 w-3.5 shrink-0 cursor-grab text-muted-foreground"}),e.jsx("span",{className:"w-4 shrink-0 text-center text-muted-foreground text-xs",children:f+1}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx(ze,{providers:o,providerId:c.providerId,modelId:c.modelId,reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,onSelect:(x,h)=>u(f,{providerId:x,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:()=>m(f),"aria-label":t("Remove"),children:e.jsx(Ee,{className:"h-3.5 w-3.5"})})]},`${c.providerId}/${c.modelId}`)),n.length<Vl&&e.jsx("div",{className:"max-w-xs",children:e.jsx(ze,{providers:o,providerId:"",modelId:"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,triggerLabel:`+ ${t("Add candidate")}`,onSelect:(c,f)=>a([...n,{providerId:c,modelId:f}]),onReasoningChange:()=>{},onThinkingChange:()=>{}})}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Final fallback: Exa (keyless hosted search). Not a chain entry; always last.")})]})}function 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),d=g(w=>w.rtkEnabled),u=g(w=>w.computerPreview),m=g(w=>w.setComputerPreview),p=g(w=>w.openLinksInBuiltinBrowser),c=g(w=>w.setOpenLinksInBuiltinBrowser),f=g(w=>w.setRtkEnabled),x=g(w=>w.protectedActionsInCode),h=g(w=>w.setProtectedActionsInCode),j=g(w=>w.editMode),b=g(w=>w.setEditMode),I=zt(Yt.map(w=>w.id),()=>window.electronAPI.assets.builtinToolOccupancy()),C=Ot(Yt.filter(w=>!t.includes(w.id)).map(w=>w.id),I.rows),[S,N]=l.useState(null),A=!t.includes("subagent"),$=(w,z)=>{r(z?[...new Set([...a,w])]:a.filter(H=>H!==w))},E=async w=>{await window.electronAPI.browser.clearData(w),N(w),setTimeout(()=>N(null),2e3)},L=!t.includes("computer"),[M,k]=l.useState(null),[T,_]=l.useState(!1);l.useEffect(()=>{if(!L||jt()){k(null);return}let w=!1;return window.electronAPI.computer.capabilities().then(z=>{!w&&z.ok&&k(z.capabilities)}),()=>{w=!0}},[L]),l.useEffect(()=>{if(!T||jt())return;let w=!1;const z=()=>{window.electronAPI.computer.capabilities().then(F=>{!w&&F.ok&&k(F.capabilities)})};z();const H=window.setInterval(z,2e3);return()=>{w=!0,window.clearInterval(H)}},[T]);const q={collaboration:null,web:null,execution:e.jsx(Ss,{rowId:"tools.editMode",newSession:!0,icon:dm,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(Z,{items:Object.fromEntries(ya.map(w=>[w,s(Ya[w])])),value:j,onValueChange:w=>{Pl(w)&&b(w)},children:[e.jsx(ee,{className:"w-44 shrink-0","aria-label":s("File edit mode"),children:e.jsx(se,{})}),e.jsx(te,{children:ya.map(w=>e.jsx(J,{value:w,children:s(Ya[w])},w))})]})}),context:e.jsxs(e.Fragment,{children:[e.jsx(Ss,{icon:hm,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(oe,{checked:o,onCheckedChange:i})}),e.jsx(Ss,{rowId:"tools.rtkEnabled",newSession:!0,icon:wm,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(oe,{checked:d,onCheckedChange:f})})]}),safety:e.jsxs(e.Fragment,{children:[e.jsx(Ss,{icon:Pn,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(oe,{checked:x,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(Lt,{tokens:C})]}),e.jsx("p",{className:"text-muted-foreground text-sm",children:s("Toggle the built-in tools available to agents.")})]}),Zu.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)}),ex(Yt,w.id).map(z=>e.jsxs(Ss,{icon:nx[z.id]??so,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(Dt,{row:I.rows[z.id],pending:I.pending&&!I.rows[z.id]}),e.jsx(oe,{checked:!t.includes(z.id),onCheckedChange:H=>{n(z.id,H),z.id==="computer"&&H&&_(!0)}})]}),children:[z.id==="web"?e.jsx(ax,{disabled:t.includes("web")}):null,z.id==="subagent"?e.jsxs("div",{className:"space-y-2","data-settings-row":"tools.subagentModes",children:[[["task","One-shot task agents"],["coworker","Persistent coworkers"]].map(([H,F])=>e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("span",{className:"text-sm",children:s(F)}),e.jsx(oe,{checked:a.includes(H),disabled:!A,onCheckedChange:G=>$(H,G)})]},H)),!A&&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:M&&Bo(M)==="unsupported"?e.jsx("p",{className:"text-muted-foreground text-xs",children:s("This platform cannot operate the desktop yet.")}):e.jsxs(e.Fragment,{children:[M?.platform==="darwin"&&e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Computer needs Screen Recording to capture windows and Accessibility to inspect or click them. Grant both to EnsoCode, then restart the app.")}),M&&e.jsxs("p",{className:"text-muted-foreground text-xs",children:[s(M.capturePermission==="granted"?"Capture: granted":"Capture: denied"),M.axPermission!=="unsupported"&&e.jsxs(e.Fragment,{children:[" · ",s(M.axPermission==="granted"?"Input/AX: granted":"Input/AX: denied")]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(y,{variant:"outline",size:"sm",onClick:()=>_(!0),children:s("Show permission guide")}),M?.platform==="darwin"&&e.jsxs(e.Fragment,{children:[e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.computer.openPermissions("screen")},children:s("Open Screen Recording settings")}),e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.computer.openPermissions("accessibility")},children:s("Open Accessibility settings")})]})]}),M?.platform==="darwin"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium text-sm",children:s("Show the app being operated")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:s("While the AI works in an app in the background, a small floating window shows that app live. Close it any time.")})]}),e.jsx(oe,{checked:u,onCheckedChange:m})]}),e.jsx(sx,{})]})]})}):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:Fl?"Cmd":"Ctrl"})})]}),e.jsx(oe,{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(H=>e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{E(H)},children:s(S===H?"Cleared":H==="cookies"?"Clear cookies":H==="cache"?"Clear cache":"Clear all browsing data")},H))})]}):null]},z.id)),q[w.id]]},w.id)),e.jsx(ix,{open:T,capabilities:M,onOpenChange:_})]})}function ox(){const{t:s}=R(),t=g(x=>x.dcgEnabled),n=g(x=>x.setDcgEnabled),[a,r]=l.useState(null),[o,i]=l.useState(!1),[d,u]=l.useState(null),[m,p]=l.useState(!1);l.useEffect(()=>{let x=!1;return window.electronAPI.dcg.status().then(h=>{x||r(h)}),()=>{x=!0}},[]);const c=async x=>{p(!1),i(!0),u(null);const h=await window.electronAPI.dcg[x]();r(h.status),h.ok?n(x==="install"):u(h.error??s("Operation failed")),i(!1)},f=a?.installed===!0;return e.jsxs(Ss,{rowId:"tools.dcgEnabled",newSession:!0,icon:Bl,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(oe,{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")}))]}),d&&e.jsx("p",{className:"text-destructive text-xs",children:d}),e.jsx(pe,{open:m,onOpenChange:p,children:e.jsxs(fe,{className:"max-w-md",zIndexLevel:"nested",children:[e.jsxs(ge,{children:[e.jsx(je,{children:s("Install dcg")}),e.jsx(We,{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(ve,{children:e.jsxs("div",{className:"flex gap-2 rounded-md border border-destructive/32 bg-destructive/8 p-3 text-sm",children:[e.jsx(Ve,{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(ke,{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 ix({open:s,capabilities:t,onOpenChange:n}){const{t:a}=R(),r=t?Bo(t):null;return e.jsx(pe,{open:s,onOpenChange:n,children:e.jsxs(fe,{className:"max-w-md",zIndexLevel:"nested",children:[e.jsxs(ge,{children:[e.jsx(je,{children:a("Grant Computer permissions")}),e.jsx(We,{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(ve,{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(Ve,{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(ke,{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(cx,{}),!window.electronAPI.remote&&e.jsx(dx,{}),e.jsx(xx,{})]})}function cx(){const{t:s}=R(),[t,n]=l.useState(null),[a,r]=l.useState(null),[o,i]=l.useState(!1),[d,u]=l.useState(null),[m,p]=l.useState(null),[c,f]=l.useState(!1),x=t?.pairingExpiresAt;l.useEffect(()=>{if(!x){p(null);return}const I=()=>p(Math.max(0,Math.ceil((x-Date.now())/1e3)));I();const C=setInterval(I,1e3);return()=>clearInterval(C)},[x]);const h=I=>{navigator.clipboard.writeText(I).then(()=>{f(!0),setTimeout(()=>f(!1),1500)})};l.useEffect(()=>{if(!jt())return window.electronAPI.pair.status().then(n),window.electronAPI.pair.onStatusChanged(I=>{n(I),(I.pairing||I.devices.length>0)&&u(null)})},[]),l.useEffect(()=>{const I=t?.inviteUri;if(!I){r(null);return}Vd.toDataURL(I,{width:320,margin:1}).then(r).catch(()=>{})},[t?.inviteUri]);const j=async()=>{i(!0),u(null);const I=await window.electronAPI.pair.start();i(!1),I.ok||u(I.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(Ce,{className:"mr-1.5 h-4 w-4 animate-spin"}):e.jsx(gn,{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(Ve,{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.")})]}),d&&e.jsx("p",{className:"text-destructive text-xs",children:d}),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(Ce,{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:m===null?s("The code expires in 60 seconds and can only be used once."):m>0?s("Expires in {{seconds}}s · single use",{seconds:m}):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(to,{className:"mr-1.5 h-3.5 w-3.5"}):e.jsx(Jr,{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(gn,{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(I=>e.jsx(mx,{device:I},I.pairId))})]})]})}function dx(){const{t:s}=R(),t=ot(i=>i.nodes),n=ot(i=>i.secureStorage),a=ot(i=>i.refresh),[r,o]=l.useState(!1);return l.useEffect(()=>ot.getState().bind(),[]),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-end justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-medium text-lg",children:s("Connect to a node")}),e.jsx("p",{className:"text-muted-foreground text-sm",children:s("Browse and drive conversations on another EnsoCode desktop. Its agent, keys and history stay there.")})]}),e.jsxs(y,{variant:"outline",size:"sm",className:"shrink-0",onClick:()=>o(!0),children:[e.jsx(Ae,{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(Ve,{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(Rn,{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(ux,{node:i,onChanged:()=>{a()}},i.nodeId))})]}),e.jsx(Kl,{open:r,onOpenChange:o,switchOnSuccess:!1})]})}function Uo({transport:s,rttMs:t}){const{t:n}=R(),a=s==="direct",r=Wl(t);return e.jsxs("span",{className:W("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 mx({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:W("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(Uo,{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:W("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(X,{value:n,autoFocus:!0,onChange:o=>a(o.target.value),onBlur:()=>{r()},onKeyDown:o=>{o.key==="Enter"&&r(),o.key==="Escape"&&a(null)},className:"h-7 text-sm"})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1 opacity-0 transition-opacity group-hover:opacity-100",children:[e.jsx(y,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground",title:t("Rename"),onClick:()=>a(s.deviceName),children:e.jsx(ms,{className:"h-3.5 w-3.5"})}),e.jsx(y,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-destructive",onClick:()=>{window.electronAPI.pair.revoke(s.pairId)},children:e.jsx(Ee,{className:"h-3.5 w-3.5"})})]})]})}function ux({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(Gl,{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(Uo,{transport:s.transport,rttMs:s.rttMs})]}):e.jsx(X,{value:a,autoFocus:!0,onChange:i=>r(i.target.value),onBlur:()=>{o()},onKeyDown:i=>{i.key==="Enter"&&o(),i.key==="Escape"&&r(null)},className:"h-7 text-sm"})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1 opacity-0 transition-opacity group-hover:opacity-100",children:[e.jsx(y,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground",title:n("Rename"),onClick:()=>r(s.label),children:e.jsx(ms,{className:"h-3.5 w-3.5"})}),e.jsx(y,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-destructive",title:n("Disconnect"),onClick:()=>{window.electronAPI.nodes.remove(s.nodeId).then(t)},children:e.jsx(Ee,{className:"h-3.5 w-3.5"})})]})]})}function xx(){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(X,{value:a??t?.relayUrl??"",onChange:i=>r(i.target.value),placeholder:"https://relay.example.com",className:"font-mono text-xs"}),a===null?e.jsx(y,{variant:"ghost",size:"icon",className:"h-8 w-8 shrink-0 text-muted-foreground",onClick:()=>r(t?.relayUrl??""),children:e.jsx(ms,{className:"h-3.5 w-3.5"})}):e.jsxs(y,{size:"sm",className:"shrink-0",onClick:()=>{o()},children:[e.jsx(to,{className:"mr-1.5 h-3.5 w-3.5"}),s("Save")]})]})]})})}function hx({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),d=g(c=>c.setDropShelfEnabled),u=g(c=>c.secretaryEnabled),m=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(we,{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(we,{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(we,{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:d}),e.jsx(we,{rowId:"experimental.secretary",title:t("Secretary"),description:t("A global agent that watches your projects and sessions, creates sessions to do the work, and reports results back to you."),checked:u,onChange:m})]})]})}function px({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,[d,u]=l.useState(""),[m,p]=l.useState(""),[c,f]=l.useState(!1),[x,h]=l.useState(!1),[j,b]=l.useState(null),[I,C]=l.useState(!1),[S,N]=l.useState(!1);l.useEffect(()=>{if(s){if(s==="new"){u(""),p(""),C(!1),b(null),N(!1),f(!1);return}u(s.name),C(!1),b(null),N(!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 A=!!(i&&!i.local&&i.sourcePath),$=async()=>{if(!s||!d.trim())return;if(h(!0),o){const L=crypto.randomUUID(),M=await window.electronAPI.instructions.write(L,m);if(!M.ok){h(!1),b(n("Failed to save"));return}const k=a([{id:L,name:d.trim(),source:"Manual",local:!0,bytes:M.bytes,enabled:!0}]);if(h(!1),k===0){window.electronAPI.instructions.delete(L),b(n("An instruction with this name already exists"));return}t();return}if(!i){h(!1);return}if(A&&S&&i.sourcePath){const L=await window.electronAPI.instructions.writeSource(i.id,i.sourcePath,m);if(h(!1),!L.ok){b(L.error??n("Failed to save"));return}r(i.id,{name:d.trim(),bytes:L.bytes}),t();return}const E=await window.electronAPI.instructions.write(i.id,m);if(h(!1),!E.ok){b(n("Failed to save"));return}r(i.id,{name:d.trim(),local:!0,bytes:E.bytes}),t()};return e.jsx(pe,{open:s!==null,onOpenChange:E=>!E&&t(),children:e.jsxs(fe,{className:"max-w-2xl",children:[e.jsx(ge,{children:e.jsx(je,{children:n(o?"Add Instruction":"Edit Instruction")})}),e.jsxs(ve,{className:"space-y-4",children:[o?null:A?e.jsxs("div",{className:W("w-full rounded-md border px-3 py-2.5 transition-colors",S?"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:[S?e.jsx(Ve,{className:"h-3.5 w-3.5 shrink-0 text-destructive"}):e.jsx(ft,{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(oe,{checked:S,onCheckedChange:N})]}),e.jsx("p",{className:"mt-1.5 pl-5.5 text-muted-foreground text-xs leading-relaxed",children:S?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(ft,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx("p",{className:"text-muted-foreground text-xs leading-relaxed",children:n("Local copy — edits stay in this app.")})]}),e.jsxs(me,{children:[e.jsx(ue,{children:n("Name")}),e.jsx(X,{value:d,onChange:E=>u(E.target.value)})]}),e.jsxs(me,{children:[e.jsx(ue,{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(Ce,{className:"h-4 w-4 animate-spin text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground text-xs",children:n("Loading...")})]}):e.jsx(Qe,{value:m,onChange:E=>{p(E.target.value),C(!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(Es,{className:"h-3.5 w-3.5 shrink-0"}),j]})]}),e.jsxs(ke,{children:[e.jsx(y,{variant:"outline",size:"sm",onClick:t,children:n("Cancel")}),e.jsxs(y,{size:"sm",variant:A&&S?"destructive":"default",disabled:!d.trim()||c||x,onClick:$,children:[x&&e.jsx(Ce,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}),n(A?S?"Overwrite original":I?"Save as local copy":"Save":"Save")]})]})]})})}const Ja=s=>s<1024?`${s} B`:`${(s/1024).toFixed(1)} KB`;function fx(){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,d]=l.useState(null),u=t.map(c=>c.id),m=zt(u,c=>window.electronAPI.assets.instructionOccupancy(c)),p=Ot(t.filter(c=>c.enabled).map(c=>c.id),m.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(Lt,{tokens:p}),e.jsx(ss,{})]}),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(Rt,{className:"mr-1.5 h-4 w-4"}),s("Import from local apps")]}),e.jsxs(y,{variant:"outline",size:"sm",onClick:()=>d("new"),children:[e.jsx(Ae,{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(Fn,{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:W("shrink-0 font-medium text-sm",!c.enabled&&"text-muted-foreground line-through"),children:c.name}),e.jsx(ne,{variant:"secondary",className:"shrink-0 text-[11px]",children:c.source}),!c.local&&e.jsxs(ne,{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")} · ${Ja(c.bytes)}`:`${c.sourcePath} · ${Ja(c.bytes)}`})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(Dt,{row:m.rows[c.id],pending:m.pending&&!m.rows[c.id]}),e.jsx(oe,{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:()=>d(c),children:e.jsx(ms,{className:"h-3.5 w-3.5"})}),e.jsx(y,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity hover:text-destructive group-hover:opacity-100",onClick:()=>a(c.id),children:e.jsx(Ee,{className:"h-3.5 w-3.5"})})]})]},c.id))}),e.jsx(Bn,{kind:"instruction",open:r,onOpenChange:o}),e.jsx(px,{instruction:i,onClose:()=>d(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(bx,{}),e.jsx(vx,{})]})}function jx(){const[s,t]=l.useState([]);return l.useEffect(()=>{const n=window.electronAPI.extensionPlugins;let a=!0;const r=()=>{n.list().then(i=>a&&t(Yl(i)))};r();const o=n.onChanged(r);return()=>{a=!1,o()}},[]),s}function vx(){const{t:s}=R(),t=jx(),n=g(h=>h.keybindings),a=g(h=>h.setKeybinding),r=g(h=>h.resetKeybinding),[o,i]=l.useState(null),[d,u]=l.useState(null);if(t.length===0)return null;const m=no(n),{rows:p}=Hl(t,n,m),c=h=>p.find(j=>j.action===h)?.command.title??s(vn[h]??h),f=()=>{i(null),u(null)},x=(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 I=oo(h);if(!I)return;const C=jn.find(S=>m[S]===I)??p.find(S=>S.action!==j&&!S.conflict&&S.binding===I)?.action;if(C)return u(C);I===b?r(j):a(j,I),f()};return e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium text-sm",children:"插件命令"}),e.jsx("div",{className:"divide-y rounded-md border",children:p.map(({action:h,command:j,binding:b,custom:I,conflict:C})=>{const S=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,C&&!S&&e.jsx("span",{className:"ml-2 text-destructive",children:s('Already used by "{{label}}"',{label:c(C)})})]})]}),S&&d&&e.jsx("span",{className:"text-destructive text-xs",children:s('Already used by "{{label}}"',{label:c(d)})}),b&&!S&&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(gs,{className:"h-3.5 w-3.5"})}),I&&!S&&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(zn,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>{i(h),u(null)},onKeyDown:S?N=>x(N,h,j.key):void 0,onBlur:()=>S&&f(),autoFocus:S,className:W("rounded-md px-1 py-0.5 transition-colors",S?"ring-1 ring-ring":"hover:bg-muted",C&&!S&&"opacity-50 line-through"),children:S?e.jsx("span",{className:"text-muted-foreground text-xs",children:s("Press shortcut…")}):b?e.jsx(ao,{children:ro(b)}):e.jsx("span",{className:"text-muted-foreground text-xs",children:s("No shortcut")})})]},h)})})]})}function bx(){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,d]=l.useState(null),u=no(t),m=p=>{if(p.preventDefault(),p.stopPropagation(),!r)return;if(p.key==="Escape"){o(null),d(null);return}if(p.key==="Backspace"||p.key==="Delete"){n(r,""),o(null),d(null);return}const c=oo(p,{allowBare:r==="send-message"});if(!c)return;const f=jn.find(x=>x!==r&&u[x]===c);if(f){d(f);return}c===ql[r]?a(r):n(r,c),o(null),d(null)};return e.jsx("div",{className:"divide-y rounded-md border",children:jn.map(p=>{const c=r===p,f=t[p]!==void 0,x=u[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(vn[p])}),wa[p]&&e.jsx("p",{className:"text-muted-foreground text-xs",children:s(wa[p])})]}),c&&i&&e.jsx("span",{className:"text-xs text-destructive",children:s('Already used by "{{label}}"',{label:s(vn[i])})}),x&&!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(gs,{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(zn,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>{o(p),d(null)},onKeyDown:c?m:void 0,onBlur:()=>{c&&(o(null),d(null))},autoFocus:c,className:W("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…")}):x?e.jsx(ao,{children:ro(x)}):e.jsx("span",{className:"text-xs text-muted-foreground",children:s("No shortcut")})})]},p)})})}function yx(s){return s.serverId??s.serverName}function $o(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 wx(s){return s.reduce((t,n)=>$o(t,n),{})}function Nx(s,t){return{...s,[t]:{state:"connecting"}}}function kx(s,t,n){return{...s,[t]:{state:"error",...n?{error:n}:{}}}}const Qt=(s,t)=>{const n={...s};return delete n[t],n},hs=Jl()((s,t)=>({statuses:{},authorized:{},pending:{},bind:()=>(window.electronAPI.mcp.authState().then(n=>s({authorized:n})).catch(()=>{}),window.electronAPI.mcp.statusSnapshot().then(n=>s({statuses:{...t().statuses,...wx(n)}})).catch(()=>{}),window.electronAPI.mcp.onStatus(n=>{if(n.type==="mcp-status-cleared"){s({statuses:{}});return}s({statuses:$o(t().statuses,n)}),window.electronAPI.mcp.authState().then(a=>s({authorized:a})).catch(()=>{})})),authorize:async n=>{s({statuses:Nx(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:Qt(t().pending,n),...a.ok?{authorized:{...t().authorized,[n]:!0}}:{statuses:kx(t().statuses,n,a.error)}})},revoke:async n=>{await window.electronAPI.mcp.revoke(n),s({authorized:Qt(t().authorized,n),statuses:Qt(t().statuses,n)})}})),Ze=s=>typeof s=="string"?s.trim():"",Cx=s=>Array.isArray(s)?s.filter(t=>typeof t=="string"):[],Vo=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 Sx(s){const t=Vo(s);return delete t[""],Object.keys(t).length>0?t:void 0}function Xa(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 Qa=s=>Object.entries(s??{}).map(([t,n])=>`${t}: ${n}`).join(`
|
|
12
|
+
`);function Ix(s,t){const n=Ze(s).toLowerCase();return n==="sse"?"sse":n==="http"||n==="streamable-http"?"http":n==="stdio"?"stdio":t?"http":"stdio"}function Za(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=Ze(r.url)||Ze(r.serverUrl),i=Ze(r.command);if(!i&&!o)continue;const d=i?void 0:Sx(r.headers);t.push({name:n,transport:Ix(r.type??r.transport,o),command:i||void 0,args:i?Cx(r.args):void 0,env:i?Vo(r.env):void 0,url:o||void 0,...d?{headers:d}:{}})}return t}const Ax=s=>{const t=s.trim();return(t.match(/^```(?:json)?\s*([\s\S]*?)\s*```$/i)?.[1]??t).trim()},Ex=s=>s.startsWith('"')&&!s.startsWith("{")&&!s.startsWith("[")?`{${s}}`:s,Mx=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},Px=s=>{if(!s||typeof s!="object"||Array.isArray(s))return!1;const t=s;return!!(Ze(t.command)||Ze(t.url)||Ze(t.serverUrl))},Tx=s=>{const t=Ze(s.command);return t&&t.split(/[\\/]/).pop()?.trim()||"mcp"},kn=s=>{if(Array.isArray(s))return s.flatMap(kn);if(Px(s)){const t=Ze(s.name)||Ze(s.id)||Tx(s);return Za({[t]:s})}return Za(s)};function Zt(s){let t;try{t=JSON.parse(Ex(Ax(s)))}catch{return{ok:!1,error:"invalid-json"}}const n=Array.isArray(t)?t.flatMap(kn):kn(Mx(t));return n.length===0?{ok:!1,error:"empty"}:{ok:!0,servers:n}}const Rx=1e4,Ox=12e4,Dx=600,Lx=3600;function er(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 zx={theme:Ql,disableFileHeader:!0,overflow:"scroll",preferredHighlighter:"shiki-js"};function _x(s){return new Kd(s)}function Ko({fileName:s,value:t,epoch:n,onChange:a,className:r="h-60"}){const{t:o}=R(),[i,d]=l.useState(!1),u=Xl(zx),m=l.useRef(a);m.current=a;const p=l.useMemo(()=>({onChange(c){m.current(c.contents)}}),[]);return l.useEffect(()=>{let c=!0;return Zl().then(()=>{c&&d(!0)}),()=>{c=!1}},[]),i?e.jsx("div",{className:W("w-full overflow-hidden rounded-lg border border-input",r),children:e.jsx(Xd,{createEditor:_x,children:e.jsx(Qd,{style:{height:"100%",overflow:"auto"},children:e.jsx(Zd,{file:{name:s,contents:t},disableWorkerPool:!0,edit:!0,editorOptions:p,options:u},n)})})}):e.jsx("div",{className:W("flex w-full items-center justify-center rounded-lg border border-input text-muted-foreground text-xs",r),children:o("Loading...")})}const sr=s=>{const t=s.split(`
|
|
13
|
+
`).map(n=>n.trim()).filter(Boolean);return t.length>0?t:void 0},tr=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},nr=s=>s?Object.entries(s).map(([t,n])=>`${t}=${n}`).join(`
|
|
15
|
+
`):"",ar=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 Fx({server:s,onClose:t}){const{t:n}=R(),a=g(O=>O.addMcpServers),r=g(O=>O.updateMcpServer),o=s==="new",[i,d]=l.useState("form"),[u,m]=l.useState(""),[p,c]=l.useState(""),[f,x]=l.useState(""),[h,j]=l.useState(""),[b,I]=l.useState("stdio"),[C,S]=l.useState(""),[N,A]=l.useState(""),[$,E]=l.useState(""),[L,M]=l.useState(""),[k,T]=l.useState(""),[_,q]=l.useState(""),[w,z]=l.useState(""),[H,F]=l.useState(""),[G,le]=l.useState(0),[B,ae]=l.useState(null),K=()=>({description:p.trim()||void 0,oauthClientName:b!=="stdio"&&f.trim()||void 0,oauthMetadataUrl:b!=="stdio"&&h.trim()||void 0,connectTimeoutSec:er(_,Dx),callTimeoutSec:er(w,Lx)}),ie=O=>{m(O.name),I(O.transport),S(O.command??""),A((O.args??[]).join(`
|
|
16
|
+
`)),E(nr(O.env&&Object.keys(O.env).length>0?O.env:void 0)),M(O.url??""),T(Qa(O.headers))},U=()=>{const O={type:b};if(b==="stdio"){O.command=C.trim();const Y=sr(N);Y&&(O.args=Y);const re=tr($);re&&(O.env=re)}else{O.url=L.trim();const Y=Xa(k);Y&&(O.headers=Y)}return JSON.stringify(O,null,2)},ce=(O,Y)=>{const re=(Y??O.name).trim(),Ge=O.env&&Object.keys(O.env).length>0?O.env:void 0,Pe=O.args&&O.args.length>0?O.args:void 0;return O.transport==="stdio"?{name:re,transport:O.transport,command:(O.command??"").trim(),args:Pe,env:Ge,url:void 0,headers:void 0,...K()}:{name:re,transport:O.transport,url:(O.url??"").trim(),headers:O.headers&&Object.keys(O.headers).length>0?O.headers:void 0,command:void 0,args:void 0,env:void 0,...K()}};l.useEffect(()=>{if(!s)return;const O=s==="new"?null:s;d("form"),m(O?.name??""),c(O?.description??""),x(O?.oauthClientName??""),j(O?.oauthMetadataUrl??""),I(O?.transport??"stdio"),S(O?.command??""),A((O?.args??[]).join(`
|
|
17
|
+
`)),E(nr(O?.env)),M(O?.url??""),T(Qa(O?.headers)),q(O?.connectTimeoutSec?.toString()??""),z(O?.callTimeoutSec?.toString()??""),F(""),le(Y=>Y+1),ae(null)},[s]);const de=O=>n(O==="invalid-json"?"Invalid JSON":"No MCP servers found in JSON"),D=O=>{if(O===i)return;if(O==="json"){F(U()),le(Ge=>Ge+1),ae(null),d("json");return}const Y=Zt(H);if(!Y.ok){if(Y.error==="invalid-json"&&H.trim()){ae(de(Y.error));return}ae(null),d("form");return}if(Y.servers.length!==1){ae(n("JSON must describe a single MCP server to switch to the form"));return}const re=Y.servers[0];ie({...re,name:u.trim()||re.name}),ae(null),d("form")},qe=()=>{const O=Zt(H);if(!O.ok){ae(de(O.error));return}if(O.servers.length===1){const[Y]=O.servers;F(JSON.stringify(ar(Y),null,2)),le(re=>re+1),u.trim()||m(Y.name)}else F(JSON.stringify({mcpServers:Object.fromEntries(O.servers.map(Y=>[Y.name,ar(Y)]))},null,2)),le(Y=>Y+1);ae(null)},Ne=!!u.trim()&&(b==="stdio"?!!C.trim():!!L.trim()),P=i==="json"?!!H.trim():Ne,Q=()=>{if(!s||!P)return;if(i==="json"){const Y=Zt(H);if(!Y.ok){ae(de(Y.error));return}if(!o&&Y.servers.length!==1){ae(n("JSON must describe a single MCP server"));return}if(o){const re=Y.servers.length===1;if(a(Y.servers.map(Pe=>({...ce(Pe,re&&u.trim()?u:Pe.name),...re?{}:{description:void 0},id:crypto.randomUUID(),source:"Manual",enabled:!0})))===0){ae(n("This MCP server already exists"));return}}else r(s.id,ce(Y.servers[0],u.trim()||Y.servers[0].name));t();return}const O=b==="stdio"?{name:u.trim(),transport:b,command:C.trim(),args:sr(N),env:tr($),url:void 0,headers:void 0,...K()}:{name:u.trim(),transport:b,url:L.trim(),headers:Xa(k),command:void 0,args:void 0,env:void 0,...K()};if(o){if(a([{...O,id:crypto.randomUUID(),source:"Manual",enabled:!0}])===0){ae(n("This MCP server already exists"));return}}else r(s.id,O);t()};return e.jsx(pe,{open:s!==null,onOpenChange:O=>!O&&t(),children:e.jsxs(fe,{children:[e.jsx(ge,{children:e.jsx(je,{children:n(o?"Add MCP Server":"Edit MCP Server")})}),e.jsxs(ve,{className:"space-y-4",children:[e.jsx(Ws,{value:i,onValueChange:O=>D(O),children:e.jsxs(Hs,{children:[e.jsx(He,{value:"form",children:n("Form")}),e.jsx(He,{value:"json",children:n("JSON")})]})}),e.jsxs(me,{children:[e.jsx(ue,{children:n("Name")}),e.jsx(X,{value:u,onChange:O=>m(O.target.value)})]}),e.jsxs(me,{children:[e.jsx(ue,{children:n("Description (optional)")}),e.jsx(X,{value:p,onChange:O=>c(O.target.value),placeholder:n("One line telling the model what this server is for")})]}),i==="json"?e.jsxs(me,{children:[e.jsxs("div",{className:"flex w-full items-center justify-between",children:[e.jsx(ue,{children:n("JSON configuration")}),e.jsx(y,{variant:"ghost",size:"sm",className:"h-7 px-2",onClick:qe,children:n("Format")})]}),e.jsx(Ko,{fileName:"mcp.json",value:H,epoch:G,onChange:F}),e.jsx("p",{className:"text-muted-foreground text-xs",children:n("Paste a server object or mcpServers JSON from Cursor / Claude Desktop")})]}):e.jsxs(e.Fragment,{children:[e.jsxs(me,{children:[e.jsx(ue,{children:n("Transport")}),e.jsxs(Z,{items:Na.map(O=>({value:O,label:O})),value:b,onValueChange:O=>I(O),children:[e.jsx(ee,{className:"w-full",children:e.jsx(se,{})}),e.jsx(te,{zIndex:os.DROPDOWN_IN_MODAL,children:Na.map(O=>e.jsx(J,{value:O,children:O},O))})]})]}),b==="stdio"?e.jsxs(e.Fragment,{children:[e.jsxs(me,{children:[e.jsx(ue,{children:n("Command")}),e.jsx(X,{value:C,onChange:O=>S(O.target.value),placeholder:"npx",className:"font-mono text-xs"})]}),e.jsxs(me,{children:[e.jsx(ue,{children:n("Arguments (one per line)")}),e.jsx(Qe,{value:N,onChange:O=>A(O.target.value),rows:3,className:"font-mono text-xs"})]}),e.jsxs(me,{children:[e.jsx(ue,{children:n("Environment variables (KEY=VALUE, one per line)")}),e.jsx(Qe,{value:$,onChange:O=>E(O.target.value),rows:3,className:"font-mono text-xs"})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs(me,{children:[e.jsx(ue,{children:n("URL")}),e.jsx(X,{value:L,onChange:O=>M(O.target.value),placeholder:"https://...",className:"font-mono text-xs"})]}),e.jsxs(me,{children:[e.jsx(ue,{children:n("Headers (Name: value, one per line)")}),e.jsx(Qe,{value:k,onChange:O=>T(O.target.value),rows:2,placeholder:"Authorization: Bearer <token>",className:"font-mono text-xs"})]}),e.jsxs(me,{children:[e.jsx(ue,{children:n("OAuth client name (optional)")}),e.jsx(X,{value:f,onChange:O=>x(O.target.value),placeholder:n("For servers that only accept known OAuth clients")})]}),e.jsxs(me,{children:[e.jsx(ue,{children:n("OAuth authorization server metadata URL (optional)")}),e.jsx(X,{value:h,onChange:O=>j(O.target.value),placeholder:n("Use when the server advertises a wrong authorization server or none"),className:"font-mono text-xs"})]})]}),e.jsxs(me,{children:[e.jsx(ue,{children:n("Connection timeout (seconds)")}),e.jsx(X,{inputMode:"numeric",value:_,onChange:O=>q(O.target.value),placeholder:String(Rx/1e3)})]}),e.jsxs(me,{children:[e.jsx(ue,{children:n("Tool call timeout (seconds)")}),e.jsx(X,{inputMode:"numeric",value:w,onChange:O=>z(O.target.value),placeholder:String(Ox/1e3)})]})]}),B&&e.jsx("p",{className:"t-shake-in text-destructive text-xs",children:B},B)]}),e.jsxs(ke,{children:[e.jsx(y,{variant:"outline",size:"sm",onClick:t,children:n("Cancel")}),e.jsx(y,{size:"sm",disabled:!P,onClick:Q,children:n("Save")})]})]})})}function Bx({status:s}){const{t}=R();return s.state==="connecting"?e.jsx(ne,{variant:"outline",className:"shrink-0 animate-pulse text-[11px] text-muted-foreground",children:t("Connecting")}):s.state==="ready"?e.jsx(ne,{variant:"success",className:"shrink-0 text-[11px]",children:t("{{count}} tools",{count:s.toolCount??0})}):s.state==="unauthorized"?e.jsx(ne,{variant:"warning",className:"shrink-0 text-[11px]",children:t("Not authorized")}):s.state==="idle"?e.jsx(ne,{variant:"outline",className:"shrink-0 text-[11px] text-muted-foreground",children:t("Authorized, pending connection")}):e.jsx(ne,{variant:"error",className:"shrink-0 text-[11px]",title:s.error,children:t("Connection failed")})}function Ux(){const{t:s}=R(),t=g(T=>T.mcpServers),n=g(T=>T.updateMcpServer),a=g(T=>T.setMcpServersEnabled),r=g(T=>T.removeMcpServer),o=hs(T=>T.statuses),i=hs(T=>T.authorized),d=hs(T=>T.pending),u=hs(T=>T.authorize),m=hs(T=>T.revoke);l.useEffect(()=>hs.getState().bind(),[]);const[p,c]=l.useState(!1),[f,x]=l.useState(null),h=async T=>{await u(T),x(hs.getState().authorized[T]===!0?T:null)},[j,b]=l.useState(null),[I,C]=l.useState(""),S=t.filter(T=>io(I,[T.name,T.source,T.transport,T.url,T.command,...T.args??[]])),N=S.map(T=>T.id),A=lo(N),$=t.filter(T=>T.enabled).length,E=t.filter(T=>T.enabled).map(T=>T.id),L=zt(E,T=>window.electronAPI.assets.mcpOccupancy(T)),M=t.filter(T=>T.enabled&&T.loadMode!=="deferred").map(T=>T.id),k=Ot(M,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(ss,{}),t.length>0&&e.jsxs("span",{className:"ml-2 font-normal text-muted-foreground text-xs",children:[s("{{enabled}}/{{total}} enabled",{enabled:$,total:t.length}),e.jsx(Lt,{tokens:k})]})]}),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(Rt,{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(Ae,{className:"mr-1.5 h-4 w-4"}),s("Add MCP server")]})]})]}),t.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx(co,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:s("No MCP servers yet")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:s("Import MCP servers from local apps or add one manually to get started")})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx(mo,{query:I,onQueryChange:C,placeholder:s("Filter MCP servers..."),allSelected:A.allSelected,someSelected:A.someSelected,onToggleSelectAll:A.toggleAll,onEnable:()=>a(A.selectedIds,!0),onDisable:()=>a(A.selectedIds,!1),selectDisabled:S.length===0,actionDisabled:A.selectedIds.length===0}),S.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:S.map(T=>{const _=o[T.id]??o[T.name],q=d[T.id]===!0,w=T.transport!=="stdio"&&i[T.id]!==!0,z=T.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.${T.id}`,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(Re,{checked:A.isSelected(T.id),onCheckedChange:H=>A.toggleOne(T.id,H)}),e.jsx("span",{className:W("shrink-0 font-medium text-sm",!T.enabled&&"text-muted-foreground line-through"),children:T.name}),e.jsx(ne,{variant:"outline",className:"shrink-0 text-[11px]",children:T.transport}),e.jsx(ne,{variant:"secondary",className:"shrink-0 text-[11px]",children:T.source}),_&&e.jsx(Bx,{status:_}),e.jsx("span",{className:"min-w-0 truncate font-mono text-muted-foreground text-xs",children:T.url??[T.command,...T.args??[]].join(" ")})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[(w||_?.state==="unauthorized")&&e.jsxs(y,{variant:"outline",size:"sm",className:"h-7",disabled:q,onClick:()=>{h(T.id)},children:[q?e.jsx(Ce,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):e.jsx(ec,{className:"mr-1.5 h-3.5 w-3.5"}),s(q?"Authorizing":"Authorize")]}),i[T.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:()=>{m(T.id)},children:e.jsx(sc,{className:"h-3.5 w-3.5"})}),e.jsx(Dt,{row:L.rows[T.id],pending:T.enabled&&L.pending&&!L.rows[T.id]}),e.jsx(Ws,{value:z?"deferred":"direct",onValueChange:H=>n(T.id,{loadMode:H==="deferred"?"deferred":"direct"}),title:s("On demand: tool descriptions are not preloaded into context; the model connects through the mcp tool when needed. Suits servers with many or rarely used tools. Takes effect in new conversations."),children:e.jsxs(Hs,{"aria-label":s("Load mode"),children:[e.jsx(He,{value:"direct",className:"h-6 px-2 text-xs sm:h-6 sm:text-xs",children:s("Always loaded")}),e.jsx(He,{value:"deferred",className:"h-6 px-2 text-xs sm:h-6 sm:text-xs",children:s("On demand")})]})}),e.jsx(oe,{checked:T.enabled,onCheckedChange:H=>n(T.id,{enabled:H})}),e.jsx(y,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",onClick:()=>b(T),children:e.jsx(ms,{className:"h-3.5 w-3.5"})}),e.jsx(y,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity hover:text-destructive group-hover:opacity-100",onClick:()=>r(T.id),children:e.jsx(Ee,{className:"h-3.5 w-3.5"})})]})]}),f===T.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.")})]},T.id)})})]}),e.jsx(Bn,{kind:"mcp",open:p,onOpenChange:c}),e.jsx(Fx,{server:j,onClose:()=>b(null)})]})}const rr={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 Go(s){if(rr[s]!==void 0)return rr[s];let t=0;for(let n=0;n<s.length;n++)t=t*17+s.charCodeAt(n)>>>0;return t%360}const en=22,$x=64;function Vx(s,t){if(t<=1)return en;const n=Math.sqrt(Math.max(1,s))/Math.sqrt(t);return Math.round(en+($x-en)*Math.min(1,n))}function Kx(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:Vx(o.memoryCount,a),color:Wo(Go(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 Gx(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:Wo(Go(a),t)})).sort((a,r)=>r.count-a.count||a.entityType.localeCompare(r.entityType))}function Wx(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 Wo(s,t){return Hx(s,t?.62:.68,t?.58:.52)}function Hx(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,d,u]=s<60?[a,r,0]:s<120?[r,a,0]:s<180?[0,a,r]:s<240?[0,r,a]:s<300?[r,0,a]:[a,0,r],m=p=>Math.round((p+o)*255).toString(16).padStart(2,"0");return`#${m(i)}${m(d)}${m(u)}`}let or=!1;function qx(){or||(To.use(em),or=!0)}const ir={name:"fcose",animate:!1,randomize:!1,nodeRepulsion:8e3,idealEdgeLength:90,nodeSeparation:90,padding:24,fit:!0};function Yx({graph:s,selectedId:t,onSelect:n,memories:a,loading:r,onInterpret:o,interpreting:i}){const{t:d}=R(),u=l.useRef(null),m=l.useRef(null),p=l.useRef(n);p.current=n;const[c,f]=l.useState(null),x=l.useMemo(()=>typeof document<"u"&&document.documentElement.classList.contains("dark"),[]);l.useEffect(()=>{const b=u.current;if(!b||s.nodes.length===0)return;qx();const I=To({container:b,elements:Kx(s.nodes,s.edges,x),style:Wx(x),minZoom:.2,maxZoom:2.5,wheelSensitivity:.2});return I.layout(ir).run(),I.on("tap","node",C=>p.current(C.target.id())),I.on("tap",C=>{C.target===I&&p.current(null)}),m.current=I,()=>{I.destroy(),m.current=null}},[s.nodes,s.edges,x]),l.useEffect(()=>{const b=m.current;b&&b.batch(()=>{if(b.elements().removeClass("dimmed").unselect(),!t)return;const I=b.getElementById(t);if(I.empty())return;const C=I.closedNeighborhood();b.elements().difference(C).addClass("dimmed"),I.select()})},[t]);const h=l.useMemo(()=>Gx(s.nodes,x),[s.nodes,x]),j=s.nodes.find(b=>b.id===t)??null;return l.useEffect(()=>{const b=m.current;!b||t||b.batch(()=>{b.elements().removeClass("dimmed"),c&&b.nodes().filter(I=>I.data("entityType")!==c).addClass("dimmed")})},[c,t]),s.nodes.length===0?e.jsx("p",{className:"rounded-lg border px-3 py-6 text-muted-foreground text-sm",children:d(r?"Loading…":"No entities yet. Turn on entity extraction and store a few memories first.")}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"relative overflow-hidden rounded-lg border bg-muted/20",children:[e.jsx("div",{ref:u,className:"h-[440px] w-full"}),e.jsxs("div",{className:"absolute right-2 bottom-2 flex gap-1",children:[e.jsx(y,{size:"sm",variant:"outline",onClick:()=>m.current?.fit(void 0,24),title:d("Fit to view"),children:d("Fit")}),e.jsx(y,{size:"sm",variant:"outline",onClick:()=>m.current?.layout(ir).run(),title:d("Re-run layout"),children:d("Relayout")})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:d("Colour = entity type · size = how many memories mention it",{})}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:h.map(b=>e.jsxs("button",{type:"button",onClick:()=>f(c===b.entityType?null:b.entityType),className:W("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:d("{{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(ne,{variant:"secondary",children:j.entityType})]}),e.jsx("p",{className:"text-muted-foreground text-xs",children:d("{{count}} memories · {{space}}",{count:String(j.memoryCount),space:j.spaceLabel})})]}),e.jsx(y,{size:"sm",variant:"outline",disabled:i,onClick:()=>o(j.id),children:d(i?"Interpreting…":"Interpret")})]}),e.jsxs("ul",{className:"divide-y rounded-lg border",children:[a.length===0&&e.jsx("li",{className:"px-3 py-4 text-muted-foreground text-sm",children:d("Loading…")}),a.map(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:d("Crystal"),children:"★"}),e.jsx("span",{className:"truncate",children:b.title}),e.jsx(ne,{variant:"secondary",children:b.unitType})]}),e.jsx("p",{className:"line-clamp-2 text-muted-foreground text-xs",children:b.contentSummary})]},b.id))]})]})]})}function Jx({tree:s,loading:t,selected:n,onToggle:a,onInterpretGroup:r,interpreting:o}){const{t:i}=R(),[d,u]=l.useState(new Set);return s.length===0?e.jsx("p",{className:"rounded-lg border px-3 py-6 text-muted-foreground text-sm",children:i(t?"Loading…":"No memories yet.")}):e.jsx("ul",{className:"divide-y rounded-lg border",children:s.map(m=>{const p=d.has(m.id),c=(m.children??[]).map(f=>f.memoryId).filter(f=>!!f);return e.jsxs("li",{children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 px-3 py-2",children:[e.jsx("button",{type:"button",className:"min-w-0 flex-1 text-left",onClick:()=>{const f=new Set(d);f.delete(m.id)||f.add(m.id),u(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:m.label}),e.jsx(ne,{variant:"secondary",children:m.count})]})}),e.jsx(y,{size:"sm",variant:"ghost",className:"shrink-0",disabled:o||c.length===0,onClick:()=>r(m),children:i("Interpret")})]}),p&&e.jsxs("ul",{className:"divide-y border-t bg-muted/20",children:[(m.children??[]).map(f=>e.jsxs("li",{className:"flex items-center gap-2 px-3 py-2",children:[f.memoryId&&e.jsx(Re,{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)),m.count>(m.children?.length??0)&&e.jsx("li",{className:"px-3 py-2 text-muted-foreground text-xs",children:i("Showing {{shown}} of {{total}}",{shown:String(m.children?.length??0),total:String(m.count)})})]})]},m.id)})})}const Xx=120,Qx=30,Zx={nodes:[],edges:[],totalEntities:0};function eh({revision:s=0}={}){const{t}=R(),[n,a]=l.useState("graph"),[r,o]=l.useState("unitType"),[i,d]=l.useState(Zx),[u,m]=l.useState([]),[p,c]=l.useState(!0),[f,x]=l.useState(null),[h,j]=l.useState([]),[b,I]=l.useState(new Set),[C,S]=l.useState(null),[N,A]=l.useState(!1),[$,E]=l.useState(null),[L,M]=l.useState(!1),k=l.useCallback(()=>{c(!0);const G=()=>c(!1);n==="graph"?window.electronAPI.memory.graph({limit:Xx,minMemories:1}).then(d).finally(G):window.electronAPI.memory.tree({groupBy:r,limitPerGroup:Qx}).then(m).finally(G)},[n,r]);l.useEffect(k,[k]);const T=l.useRef(k);T.current=k,l.useEffect(()=>window.electronAPI.memory.onChanged(()=>T.current()),[]);const _=l.useRef(s);l.useEffect(()=>{_.current!==s&&(_.current=s,k())},[s,k]),l.useEffect(()=>{if(!f){j([]);return}window.electronAPI.memory.graphEntity(f).then(j)},[f]);const q=async G=>{A(!0),S(null);try{S(await window.electronAPI.memory.insight(G))}finally{A(!1)}},w=async()=>{M(!0);try{const G=await window.electronAPI.memory.crystallize({memoryIds:[...b]});E(G),G.ok&&I(new Set)}finally{M(!1)}},z=[{value:"graph",label:t("Graph")},{value:"tree",label:t("Tree")}],H=[{value:"unitType",label:t("By type")},{value:"entity",label:t("By entity")},{value:"time",label:t("By month")}],F=b.size>=ka;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(Z,{value:n,items:z,onValueChange:G=>a(G==="tree"?"tree":"graph"),children:[e.jsx(ee,{size:"sm",className:"w-32",children:e.jsx(se,{})}),e.jsx(te,{children:z.map(G=>e.jsx(J,{value:G.value,children:G.label},G.value))})]}),n==="tree"&&e.jsxs(Z,{value:r,items:H,onValueChange:G=>o(G),children:[e.jsx(ee,{size:"sm",className:"w-36",children:e.jsx(se,{})}),e.jsx(te,{children:H.map(G=>e.jsx(J,{value:G.value,children:G.label},G.value))})]}),e.jsx("span",{className:"flex-1"}),n==="tree"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:W("text-xs",F?"text-foreground":"text-muted-foreground"),children:t("{{count}} selected",{count:String(b.size)})}),e.jsx(y,{size:"sm",variant:"outline",disabled:!F||L,onClick:()=>{w()},children:L?t("Synthesizing…"):t("Crystallize ({{min}}+)",{min:String(ka)})})]})]}),n==="graph"?e.jsx(Yx,{graph:i,loading:p,selectedId:f,onSelect:x,memories:h,interpreting:N,onInterpret:G=>{q({entityId:G})}}):e.jsx(Jx,{tree:u,loading:p,selected:b,interpreting:N,onToggle:G=>{const le=new Set(b);le.delete(G)||le.add(G),I(le)},onInterpretGroup:G=>{const le=(G.children??[]).map(B=>B.memoryId).filter(B=>!!B);q({memoryIds:le})}}),e.jsx(pe,{open:C!==null,onOpenChange:G=>!G&&S(null),children:e.jsxs(fe,{children:[e.jsxs(ge,{children:[e.jsx(je,{children:t("Interpretation")}),C?.ok&&e.jsx(We,{children:t("Based on {{count}} memories",{count:String(C.sourceCount??0)})})]}),e.jsx(ve,{children:C?.ok?e.jsx("p",{className:"whitespace-pre-wrap text-sm",children:C.text}):e.jsx("p",{className:"text-destructive text-sm",children:C?.error})}),e.jsx(ke,{children:e.jsx(Us,{render:e.jsx(y,{variant:"outline",size:"sm"}),children:t("Close")})})]})}),e.jsx(pe,{open:$!==null,onOpenChange:G=>!G&&E(null),children:e.jsxs(fe,{children:[e.jsxs(ge,{children:[e.jsx(je,{children:$?.ok?t("Crystal created"):t("Nothing was written")}),$?.ok&&e.jsx(We,{children:$.title})]}),e.jsx(ve,{className:"space-y-3",children:$?.ok?e.jsx("p",{className:"whitespace-pre-wrap text-sm",children:$.content}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-destructive text-sm",children:$?.error}),$?.candidates&&$.candidates.length>0&&e.jsx("ul",{className:"divide-y rounded-lg border",children:$.candidates.map(G=>e.jsxs("li",{className:"flex items-center justify-between gap-2 px-3 py-2",children:[e.jsx("span",{className:"truncate text-sm",children:G.title}),e.jsxs(ne,{variant:"secondary",children:[(G.similarity*100).toFixed(0),"%"]})]},G.id))})]})}),e.jsx(ke,{children:e.jsx(Us,{render:e.jsx(y,{variant:"outline",size:"sm"}),children:t("Close")})})]})})]})}function Cn(s){return s==="fast"||s==="deep"}const Cs=25,Le="__all__";function Ms(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 lr=["global","project","secretary","bot","chat"],sh={global:"Global",project:"Projects",secretary:"Secretary",bot:"Members",chat:"Group chats"};function th(s,t,n){return t?{spaceId:t}:s?{spaceIds:n.filter(a=>a.kind===s).map(a=>a.id)}:{}}function nh(s){return s.startsWith("bot:")?"bot":s.startsWith("chat:")?"chat":s.startsWith("proj:")?"project":"global"}function ah(s,t){return s===!1&&!t}function rh(s,t,n,a){return Cn(s)&&!t.trim()?"needs-query":ah(n,a)?"library-empty":"no-match"}function oh({items:s,onOpen:t,onEdit:n,onDelete:a,t:r,selected:o,onToggle:i,emptyLabel:d}){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:d}),s.map(u=>e.jsxs("li",{className:W(Yd,"flex items-center gap-2 px-3 py-2"),"data-memory-id":u.id,children:[i&&e.jsx(Re,{checked:o?.has(u.id)??!1,onCheckedChange:()=>i(u.id),"aria-label":r("Select memory")}),e.jsxs("button",{type:"button",onClick:()=>t(u.id),className:"min-w-0 flex-1 space-y-0.5 text-left",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[u.isCrystal&&e.jsx("span",{title:r("Crystal"),children:"★"}),e.jsx("span",{className:"truncate text-sm",children:u.title}),e.jsx(ne,{variant:"secondary",children:u.unitType}),e.jsx(lh,{importance:u.importance,t:r}),u.lifecycleState==="archived"&&e.jsx(ne,{variant:"outline",children:r("Archived")}),u.archiveCandidateAt&&e.jsx(ne,{variant:"warning",title:r("Marked by the forgetting pass: cold and low importance"),children:r("Archive candidate")})]}),e.jsx("span",{className:"line-clamp-2 text-muted-foreground text-xs",children:u.contentSummary}),e.jsxs("span",{className:"block text-muted-foreground text-xs",children:[r("Recorded {{date}}",{date:Ms(u.createdAt)})," · ",u.spaceLabel," ","· ",r("Retrieved {{count}} times",{count:String(u.appearances)})]})]}),n&&a&&e.jsx(qd,{id:u.id,onEdit:n,onDelete:a})]},u.id))]})}const ih={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=rc(s),a=ih[n];return e.jsx(ne,{variant:a.variant,className:n==="low"?"text-muted-foreground":void 0,title:t("Importance {{value}}",{value:s.toFixed(2)}),children:t(a.label)})}const ch=6,dh=50;function mh(s){const t=[...s].sort((a,r)=>r.edge.createdAt.localeCompare(a.edge.createdAt)||a.edge.id.localeCompare(r.edge.id));if(t.length<=ch)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 cr({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 uh({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 d=s.every(u=>t.has(u.edge.id));return e.jsxs("section",{className:"space-y-2","data-settings-row":"memory.review",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("h3",{className:"text-sm font-medium",children:i("Needs review")}),e.jsxs("label",{className:"flex items-center gap-2 text-muted-foreground text-xs",children:[e.jsx(Re,{checked:d,onCheckedChange:()=>a(!d),"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>dh&&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")})]})]}),mh(s).map(u=>e.jsxs("div",{className:"space-y-2",children:[u.label&&e.jsxs("h4",{className:"text-muted-foreground text-xs",children:[u.label," · ",i("{{count}} pending",{count:String(u.items.length)})]}),u.items.map(({edge:m,older:p,newer:c})=>e.jsxs("div",{className:"space-y-1.5 rounded-lg border px-3 py-2","data-memory-review":m.id,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(Re,{checked:t.has(m.id),onCheckedChange:()=>n(m.id),"aria-label":i("Select memory")}),e.jsx(ne,{variant:"outline",children:m.relation}),e.jsxs("span",{className:"text-muted-foreground text-xs",children:[p.spaceLabel," · ",Ms(m.createdAt)]})]}),e.jsx(cr,{label:i("Earlier memory"),memory:p,onOpen:o}),e.jsx(cr,{label:i("Newer memory"),memory:c,onOpen:o}),e.jsx("p",{className:"text-muted-foreground text-xs",children:m.reason?`${i("Why they conflict")}: ${m.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([m.id],"accepted"),children:i("Accept")}),e.jsx(y,{size:"sm",variant:"ghost",onClick:()=>r([m.id],"rejected"),children:i("Dismiss")})]})]},m.id))]},u.key))]})}function xh({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 hh({t:s}){const t=nc(),n=ac(a=>a.review);return e.jsx(xh,{writes:t,t:s,onReview:(a,r)=>{n(a,r)}})}function ph({revision:s=0}={}){const{t}=R(),[n,a]=l.useState(""),[r,o]=l.useState(Le),[i,d]=l.useState(Le),[u,m]=l.useState(Le),[p,c]=l.useState(!1),[f,x]=l.useState(!1),[h,j]=l.useState(0),[b,I]=l.useState("exact"),[C,S]=l.useState(!1),[N,A]=l.useState(!0),[$,E]=l.useState([]),[L,M]=l.useState(0),[k,T]=l.useState([]),_=l.useRef(k);_.current=k;const[q,w]=l.useState(null),[z,H]=l.useState(null),[F,G]=l.useState(null),[le,B]=l.useState(null),[ae,K]=l.useState(new Set),[ie,U]=l.useState(!1),[ce,de]=l.useState([]),[D,qe]=l.useState(new Set),Ne=l.useRef(!1),P=l.useRef(0),Q=l.useRef(0);l.useEffect(()=>(Ne.current=!0,()=>{Ne.current=!1,P.current++,Q.current++}),[]);const O=l.useCallback(()=>{if(!Ne.current)return;const V=++P.current,xe=()=>Ne.current&&V===P.current;if(Cn(b)&&!n.trim()){E([]),M(0),S(!0),A(!0);return}const Te=lr.find(Se=>Se===r)??null;window.electronAPI.memory.list({query:n.trim()||void 0,...th(Te,i===Le?null:i,_.current),unitType:u===Le?void 0:u,includeArchived:p,archiveCandidate:f||void 0,limit:Cs,offset:h,mode:b}).then(Se=>{xe()&&(E(Se.items),M(Se.total),S(Se.approximate===!0),A(Se.vectorsUsed!==!1))}),window.electronAPI.memory.stats().then(Se=>{Ne.current&&(T(Object.keys(Se.bySpace).map(Je=>({id:Je,label:Se.spaceLabels[Je]??Je,kind:Se.spaceKinds?.[Je]??nh(Je)}))),w(Se.total>0))}),window.electronAPI.memory.evolvesPending().then(Se=>{Ne.current&&de(Se)})},[n,r,i,u,p,f,h,b]);l.useEffect(()=>(O(),()=>{P.current++}),[O]);const Y=l.useRef(O);Y.current=O,l.useEffect(()=>window.electronAPI.memory.onChanged(()=>Y.current()),[]);const re=l.useRef(s);l.useEffect(()=>{re.current!==s&&(re.current=s,O())},[s,O]);const Ge=V=>{const xe=++Q.current;window.electronAPI.memory.detail(V).then(Te=>{Ne.current&&xe===Q.current&&H(Te)})},Pe=()=>{Q.current++,H(null)},Ys=async(V,xe)=>{U(!0);try{for(const Te of V)await xe(Te)}finally{Ne.current&&(U(!1),K(new Set),Y.current())}},Js=()=>{Ys(ae,V=>window.electronAPI.memory.archive(V))},Ft=(V,xe)=>{V.length!==0&&(U(!0),(async()=>{try{for(const Te of V)await window.electronAPI.memory.evolvesReview(Te,xe)}finally{Ne.current&&(U(!1),qe(new Set),Y.current())}})())},Ye=V=>{Ne.current&&(K(new Set),z&&V.includes(z.id)&&Pe(),Y.current())},Bt=V=>{Ne.current&&(F?.reopen&&Ge(V),Y.current())},js=V=>{V.then(()=>{Ne.current&&(Pe(),Y.current())})},Ut=n.trim()!==""||r!==Le||i!==Le||u!==Le||p===!0,ns=[{value:Le,label:t("All space types")},...lr.filter(V=>k.some(xe=>xe.kind===V)).map(V=>({value:V,label:t(sh[V])}))],Xs=[{value:Le,label:t("All spaces")},...k.filter(V=>r===Le||V.kind===r).map(V=>({value:V.id,label:V.label}))],vs=[{value:Le,label:t("All types")},...tc.map(V=>({value:V,label:V}))],Qs=[{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(uo,{className:"w-full sm:w-96","data-size":"sm",children:[e.jsx(xo,{value:n,placeholder:t("Search memories"),onChange:V=>{j(0),a(V.target.value)}}),e.jsx(ho,{align:"inline-end",className:"pe-1",children:e.jsxs(Z,{value:b,items:Qs,onValueChange:V=>{j(0),I(V==="deep"?"deep":V==="fast"?"fast":"exact")},children:[e.jsx(ee,{size:"sm",className:"w-auto min-w-0 gap-1 border-0 bg-transparent px-2 shadow-none before:hidden",children:e.jsx(se,{})}),e.jsx(te,{children:Qs.map(V=>e.jsx(J,{value:V.value,children:V.label},V.value))})]})})]}),e.jsxs(Z,{value:r,items:ns,onValueChange:V=>{j(0),o(String(V)),d(Le)},children:[e.jsx(ee,{size:"sm",className:"w-36","data-memory-filter":"space-kind",children:e.jsx(se,{})}),e.jsx(te,{children:ns.map(V=>e.jsx(J,{value:V.value,children:V.label},V.value))})]}),e.jsxs(Z,{value:i,items:Xs,onValueChange:V=>{j(0),d(String(V))},children:[e.jsx(ee,{size:"sm",className:"w-36","data-memory-filter":"space",children:e.jsx(se,{})}),e.jsx(te,{children:Xs.map(V=>e.jsx(J,{value:V.value,children:V.label},V.value))})]}),e.jsxs(Z,{value:u,items:vs,onValueChange:V=>{j(0),m(String(V))},children:[e.jsx(ee,{size:"sm",className:"w-36",children:e.jsx(se,{})}),e.jsx(te,{children:vs.map(V=>e.jsx(J,{value:V.value,children:V.label},V.value))})]}),b==="exact"&&e.jsxs("label",{className:"flex items-center gap-2 text-muted-foreground text-sm",children:[e.jsx(oe,{checked:p,onCheckedChange:V=>{j(0),c(V===!0)}}),t("Show archived")]}),b==="exact"&&e.jsxs("label",{className:"flex items-center gap-2 text-muted-foreground text-sm",children:[e.jsx(oe,{checked:f,onCheckedChange:V=>{j(0),x(V===!0)}}),t("Archive candidates only")]})]}),Cn(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."),!N&&` ${t("Embedding model is not ready, so vectors are skipped.")}`]}),ae.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(ae.size)})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(y,{variant:"ghost",size:"sm",disabled:ie,onClick:()=>K(new Set),children:t("Clear selection")}),e.jsx(y,{variant:"outline",size:"sm",disabled:ie,onClick:()=>Js(),children:t("Archive selected")}),e.jsx(y,{variant:"destructive-outline",size:"sm",disabled:ie,onClick:()=>B([...ae]),children:t("Delete permanently")})]})]}),e.jsx(oh,{items:$,onOpen:Ge,onEdit:V=>G({id:V,reopen:!1}),onDelete:V=>B([V]),t,selected:ae,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,q,Ut)],onToggle:V=>{const xe=new Set(ae);xe.delete(V)||xe.add(V),K(xe)}}),!C&&L>Cs&&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-Cs)),children:t("Previous")}),e.jsxs("span",{children:[h+1,"–",Math.min(h+Cs,L)," / ",L]}),e.jsx(y,{variant:"outline",size:"sm",disabled:h+Cs>=L,onClick:()=>j(h+Cs),children:t("Next")})]}),e.jsx(hh,{t}),e.jsx(uh,{items:ce,selected:D,onToggle:V=>{const xe=new Set(D);xe.delete(V)||xe.add(V),qe(xe)},onToggleAll:V=>qe(V?new Set(ce.map(xe=>xe.edge.id)):new Set),onOpen:Ge,onReview:Ft,t}),e.jsx(pe,{open:z!==null,onOpenChange:V=>!V&&Pe(),children:e.jsx(fe,{finalFocus:Gd,children:z&&e.jsxs(e.Fragment,{children:[e.jsxs(ge,{children:[e.jsx(je,{children:z.title}),e.jsx(We,{children:[z.unitType,z.spaceLabel].join(" · ")})]}),e.jsxs(ve,{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(Ds,{label:t("Importance"),value:z.importance.toFixed(2)}),e.jsx(Ds,{label:t("Recorded at"),value:Ms(z.createdAt)}),z.updatedAt!==z.createdAt&&e.jsx(Ds,{label:t("Updated at"),value:Ms(z.updatedAt)}),e.jsx(Ds,{label:t("Embedding"),value:z.embeddingModel??t("Not vectorized")}),z.eventStart&&e.jsx(Ds,{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(V=>e.jsx(ne,{variant:"secondary",children:V},V))})]}),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(V=>e.jsxs("li",{className:"flex items-center justify-between gap-2 px-3 py-2",children:[e.jsx("span",{className:"truncate text-sm",children:V.title}),e.jsxs("span",{className:"shrink-0 text-muted-foreground text-xs",children:[(V.contributionWeight*100).toFixed(0),"%"]})]},V.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(V=>e.jsxs("li",{className:"flex items-center gap-2 px-3 py-2",children:[e.jsx(ne,{variant:"outline",children:V.relation}),e.jsx("span",{className:"text-muted-foreground text-xs",children:V.reviewState})]},V.id))})]})]}),e.jsxs(ke,{children:[e.jsx(y,{variant:"destructive-outline",size:"sm",className:"sm:me-auto","data-memory-action":"delete",onClick:()=>B([z.id]),children:t("Delete permanently")}),e.jsx(y,{variant:"outline",size:"sm","data-memory-action":"edit",onClick:()=>{Pe(),G({id:z.id,reopen:!0})},children:t("Edit")}),z.lifecycleState==="archived"?e.jsx(y,{variant:"outline",size:"sm",onClick:()=>js(window.electronAPI.memory.restore(z.id)),children:t("Restore")}):e.jsx(y,{variant:"outline",size:"sm",onClick:()=>js(window.electronAPI.memory.archive(z.id)),children:t("Archive")})]})]})})}),e.jsx(Wd,{memoryId:F?.id??null,onClose:()=>G(null),onSaved:Bt}),e.jsx(Hd,{ids:le,onClose:()=>B(null),onDeleted:Ye})]})}function Ds({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 Ho="openai-compatible",fh=/embed|bge|m3e|voyage|jina|nomic|mxbai|stella|conan|acge|retriev|text-(?:similarity|search)|(?:^|[^a-z0-9])(?:e5|gte|bce)(?:[^a-z0-9]|$)/i;function qo(s){return fh.test(s)}function Kn(s){return Array.isArray(s.models)?s.models.filter(t=>typeof t?.id=="string"&&qo(t.id)):[]}function gh(s){return s.flatMap(t=>{if(!t.apiKey||typeof t.baseUrl!="string"||!t.baseUrl.trim())return[];const n=Kn(t);return n.length>0?[{...t,models:n}]:[]})}function jh(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?Kn(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 vh={"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 bh(s,t,n){return n(vh[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===Ho?"no-model":qo(a)?null:Kn(n).length>0?"not-embedding-model":"no-embedding-models":"no-api-key":"provider-missing":"no-provider"}const wh={"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.'},Nh="No model can be used for embeddings: it needs a provider with an API key and an embedding model (e.g. text-embedding-3-small). Subscription sign-in cannot be used for embeddings.";function kh(s,t,n){return n(wh[s],{provider:t.provider??"",model:t.model??""})}const dr=s=>s.slice(0,8);function sn(s,t){return s==="pending"||s==="running"?"running":s==="cancelled"?"cancelled":t?"failed":"done"}const Ch={low_importance:"importance too low",candidates_found:"similar memory already exists",deduplicated:"identical to an existing memory",rejected:"rejected"};function Sh(s){const t=[];for(const r of s.distill){const o=sn(r.status,r.error);t.push({key:`distill:${r.id}`,kind:"distill",target:r.sessionTitle||dr(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,Ch[i.kind]??i.kind].filter(Boolean).join(" — ")),updatedAt:r.updatedAt})}for(const r of s.kg){const o=sn(r.status,r.error);t.push({key:`kg:${r.id}`,kind:"kg",target:r.memoryTitle||dr(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=sn(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 $s=`remote:${Ho}`,wt="remote:";function mr(s){return s.id==="none"?"None (full-text only)":s.id.replace(/^(local|remote):/,"")}function _t(s){return s.startsWith(wt)&&s.length>wt.length}function Ih(s){return _t(s)?$s:s}function Ah(s){return!_t(s)||s===$s?null:s.slice(wt.length)}function Eh(s){return`${wt}${s}`}function Mh(s,t){return t===$s?_t(s)?s:$s:t}const Ph=4e3,Th=800,ur=6,Rh={distill:"job:distill",kg:"job:entities",reembed:"job:vectors"},xr={distill:[],kg:[],reembed:null,kgFailed:0};function Oh(s){return s.some(t=>t.distilled)}function hr(s){return!s||s.total===0||s.embedded>=s.total?null:s.embeddingError??null}function pr(s){return s?.downloadable&&(s.state==="missing"||s.state==="downloading")?s.state:null}function Dh(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 Lh(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 zh(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 he(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 tn(s,t,n){return(s.includes(t)?[...s]:[...s,t].sort((r,o)=>r-o)).map(r=>({value:String(r),label:n(r)}))}function ps({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(oe,{checked:n,disabled:o,onCheckedChange:i=>a(i===!0)})]})}function nn({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(Z,{value:n,items:a,onValueChange:d=>r(String(d)),disabled:i,children:[e.jsx(ee,{className:"w-40 shrink-0",children:e.jsx(se,{})}),e.jsx(te,{children:a.map(d=>e.jsx(J,{value:d.value,children:d.label},d.value))})]})]})}function _h({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),d=g(v=>v.memoryModelIdleMinutes),u=g(v=>v.setMemoryModelIdleMinutes),m=g(v=>v.memoryEmbeddingRemoteProviderId),p=g(v=>v.setMemoryEmbeddingRemoteProviderId),c=g(v=>v.providers),f=g(v=>v.memoryDistillEnabled),x=g(v=>v.setMemoryDistillEnabled),h=g(v=>v.memoryDistillWindowMinutes),j=g(v=>v.setMemoryDistillWindowMinutes),b=g(v=>v.memoryKgEnabled),I=g(v=>v.setMemoryKgEnabled),C=g(v=>v.memoryReconcileEnabled),S=g(v=>v.setMemoryReconcileEnabled),N=g(v=>v.memoryDecayEnabled),A=g(v=>v.setMemoryDecayEnabled),$=g(v=>v.memoryDecayArchiveCandidates),E=g(v=>v.setMemoryDecayArchiveCandidates),L=g(v=>v.memoryDecayAutoArchive),M=g(v=>v.setMemoryDecayAutoArchive),k=g(v=>v.memoryDecayStaleDays),T=g(v=>v.setMemoryDecayStaleDays),_=g(v=>v.memoryDecayMaxImportance),q=g(v=>v.setMemoryDecayMaxImportance),w=g(v=>v.memoryDecayIntervalDays),z=g(v=>v.setMemoryDecayIntervalDays),H=g(v=>v.memoryDistillModel),F=g(v=>v.setMemoryDistillModel),G=g(v=>v.memoryChatModel)||"remote",le=g(v=>v.setMemoryChatModel),B=g(v=>v.memoryLanguage),ae=g(v=>v.setMemoryLanguage),K=ts(),ie=H?K.find(v=>v.id===H.providerId):void 0,U=ie?.models.find(v=>v.id===H?.modelId),ce=Ah(a),de=l.useMemo(()=>gh(K),[K]),D=l.useMemo(()=>jh(K),[K]),qe=m?de.find(v=>v.id===m):void 0,Ne=qe?.models.find(v=>v.id===ce),P=m?c.find(v=>v.id===m):void 0,Q=yh({providerId:m,provider:P,modelId:ce}),O=Q&&Q!=="no-provider"&&Q!=="no-model"?kh(Q,{provider:P?.name||m||"",model:ce??""},t):null,Y=!n.includes("memory"),[re,Ge]=l.useState(null),[Pe,Ys]=l.useState(xr),[Js,Ft]=l.useState([]),[Ye,Bt]=l.useState(null),[js,Ut]=l.useState([]),[ns,Xs]=l.useState(null),[vs,Qs]=l.useState([]),[V,xe]=l.useState(null),[Te,Se]=l.useState(null),[Je,$t]=l.useState(null),[Oe,Zs]=l.useState(null),[Ts,Wn]=l.useState(!1),[Vt,di]=l.useState(!1),[_e,Hn]=l.useState(null),[bs,Kt]=l.useState(new Set),[et,st]=l.useState(null),[qn,Yn]=l.useState(!1),[tt,mi]=l.useState(void 0),Gt=re?.forgetting??null,Rs=Gt?.lastRun??null,ui=Rs?t("Last run {{date}}: {{scored}} scored, {{candidates}} candidates, {{archived}} archived",{date:Ms(Rs.ranAt),scored:String(Rs.scored),candidates:String(Rs.candidates),archived:String(Rs.archived)}):t("Never run yet"),Jn=l.useRef(!1);Jn.current=Ts;const us=l.useRef(null),Wt=l.useCallback(()=>{window.electronAPI.memory.distillableSessions().then(Qs)},[]);l.useEffect(()=>{Y&&Wt()},[Y,Wt]);const ys=l.useCallback(()=>{window.electronAPI.memory.models().then(Ft)},[]);l.useEffect(()=>(ys(),window.electronAPI.memory.onModelProgress(v=>{Bt(v.done?null:v),v.done&&ys()})),[ys]);const ws=l.useCallback(()=>{window.electronAPI.memory.chatModels().then(Ut)},[]);l.useEffect(()=>(ws(),window.electronAPI.memory.onChatModelProgress(v=>{Xs(v.done?null:v),v.done&&ws()})),[ws]),l.useEffect(()=>{if(!Y){Ge(null),Ys(xr);return}let v=!1;const ye=()=>{window.electronAPI.memory.stats().then(as=>{v||Ge(as)}),window.electronAPI.memory.jobs().then(as=>{v||(Ys(as),Jn.current&&as.reembed?.status!=="running"&&Wn(!1))})};us.current=ye,ye();const Fe=window.electronAPI.memory.onChanged(ye),Os=window.setInterval(ye,Ts?Th:Ph);return()=>{v=!0,us.current=null,Fe(),window.clearInterval(Os)}},[Y,Ts]);const Xn=zh(vs),Qn=vs.filter(v=>!v.distilled),xi=()=>{st("run"),window.electronAPI.memory.runForgetting().then(()=>{st(null),us.current?.()})},hi=()=>{Yn(!0),window.electronAPI.memory.runReconcile().then(v=>{Yn(!1),mi(v),us.current?.()})},Zn=()=>{window.electronAPI.memory.archiveCandidates({limit:200,offset:0}).then(v=>{Hn(v),Kt(new Set)})},pi=()=>{const v=[...bs];v.length!==0&&(st("archive"),window.electronAPI.memory.confirmArchiveCandidates(v).then(()=>{st(null),Zn(),us.current?.(),s?.()}))},ea=(v,ye,Fe)=>{const Os=v.filter(as=>!as.distilled);if(!Oh(v)){nt(v,ye);return}Zs({token:ye,label:Fe,scope:v,pending:Os})},nt=async(v,ye,Fe=!1)=>{const Os=js.find(ks=>ks.id===G)??null;if(pr(Os))return;xe(ye);const as=Date.now();$t({done:0,total:v.length,startedAt:as});try{for(let ks=0;ks<v.length;ks++)await window.electronAPI.memory.distillSession(v[ks].sessionId,Fe),$t({done:ks+1,total:v.length,startedAt:as})}finally{xe(null),$t(null),Wt(),s?.()}},be=Js.find(v=>v.id===a)??null,De=js.find(v=>v.id===G)??null,xs=pr(De),sa=js.map(v=>({value:v.id,label:v.id==="remote"?t("Remote (API model)"):v.label})),ta=[...Js.map(v=>({value:v.id,label:mr(v)})),{value:$s,label:t("Remote (OpenAI-compatible)")}],na=oc.map(v=>({value:String(v),label:v===0?t("Never"):t("{{count}} min",{count:v})})),aa=ic.map(v=>({value:String(v),label:v===0?t("Immediately"):t("{{count}} min",{count:v})})),ra=[{value:"en",label:t("English")},{value:"zh",label:t("Simplified Chinese")},{value:"auto",label:t("Follow conversation")}],at=_t(a)||be?.runtime==="openai-compatible",Ns=l.useMemo(()=>Sh(Pe),[Pe]);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(Z,{value:String(d),items:na,onValueChange:v=>{v!==null&&u(Number(v))},disabled:!Y,children:[e.jsx(ee,{className:"w-56 shrink-0","aria-label":t("Unload automatically when idle"),children:e.jsx(se,{})}),e.jsx(te,{children:na.map(v=>e.jsx(J,{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:be?mr(be):ce??(at?t("Remote (OpenAI-compatible)"):a)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:be?[be.dim?`${be.dim}d`:null,be.downloadable?he(be.approxBytes):null,be.runtime].filter(Boolean).join(" · "):at?"openai-compatible":t("Unknown model; the default is used instead.")})]}),e.jsxs(Z,{value:Ih(a),items:ta,onValueChange:v=>{v!==null&&r(Mh(a,String(v)))},disabled:!Y,children:[e.jsx(ee,{className:"w-56",children:e.jsx(se,{})}),e.jsx(te,{children:ta.map(v=>e.jsx(J,{value:v.value,children:v.label},v.value))})]})]}),be?.downloadable&&e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5","data-settings-row":"memory.download",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:be.state==="ready"?t("Model downloaded"):be.state==="downloading"?t("Downloading…"):t("Model not downloaded")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:Ye&&Ye.modelId===be.id?`${Ye.file} · ${he(Ye.received)}${Ye.total?` / ${he(Ye.total)}`:""} (${Ye.fileIndex+1}/${Ye.fileCount})`:be.state==="ready"?he(be.downloadedBytes):t("Semantic search stays off until the model is on disk.")})]}),e.jsx("div",{className:"flex shrink-0 gap-2",children:be.state==="downloading"?e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.memory.cancelModelDownload(be.id).then(ys)},children:t("Cancel")}):be.state==="ready"?e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.memory.deleteModel(be.id).then(ys)},children:t("Remove")}):e.jsx(y,{size:"sm",disabled:!Y,onClick:()=>{window.electronAPI.memory.downloadModel(be.id).then(ys)},children:t("Download")})})]}),at&&e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5","data-settings-row":"memory.remoteModel",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Remote model")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Credentials stay in the main process and are never sent to the renderer.")})]}),de.length>0?e.jsx("div",{className:"w-56 shrink-0",children:e.jsx(ze,{providers:de,providerId:qe?.id??m??"",modelId:Ne?.id??ce??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:t("Select model"),side:"bottom",triggerClassName:es,onSelect:(v,ye)=>{p(v),r(Eh(ye))},onReasoningChange:()=>{},onThinkingChange:()=>{}})}):e.jsxs("div",{className:"w-56 shrink-0 space-y-1",children:[e.jsx("p",{className:"text-xs text-destructive",children:t(Nh)}),D.map(v=>e.jsx("p",{className:"text-xs text-muted-foreground",children:bh(v.reason,v.name,t)},v.providerId))]})]}),at&&O&&e.jsx("p",{className:"text-xs text-destructive","data-settings-row":"memory.remoteModelIssue",children:O}),e.jsx(ps,{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:!Y})]}),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(Z,{value:G,items:sa,onValueChange:v=>le(String(v)),disabled:!Y,children:[e.jsx(ee,{className:"w-56",children:e.jsx(se,{})}),e.jsx(te,{children:sa.map(v=>e.jsx(J,{value:v.value,children:v.label},v.value))})]})]}),De?.downloadable&&e.jsxs("div",{className:W("flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5",xs==="missing"&&"border-destructive/50"),children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:De.state==="ready"?t("Model downloaded"):De.state==="downloading"?t("Downloading…"):t("Model not downloaded")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:ns&&ns.modelId===De.id?`${ns.file} · ${he(ns.received)}${ns.total?` / ${he(ns.total)}`:""}`:De.state==="ready"?he(De.downloadedBytes):he(De.approxBytes)})]}),e.jsx("div",{className:"flex shrink-0 gap-2",children:De.state==="downloading"?e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.memory.cancelChatModelDownload(De.id).then(ws)},children:t("Cancel")}):De.state==="ready"?e.jsx(y,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.memory.deleteChatModel(De.id).then(ws)},children:t("Remove")}):e.jsx(y,{size:"sm",disabled:!Y,onClick:()=>{window.electronAPI.memory.downloadChatModel(De.id).then(ws)},children:t("Download")})})]}),xs==="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.")}),xs==="downloading"&&e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Download in progress. Distillation waits until the model is ready.")}),G==="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.")})]}),K.length>0&&e.jsx("div",{className:"w-56 shrink-0",children:e.jsx(ze,{providers:K,providerId:ie?.id??"",modelId:U?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:t("Follows the title-summary model"),side:"bottom",triggerClassName:es,onSelect:(v,ye)=>F({providerId:v,modelId:ye}),onReasoningChange:()=>{},onThinkingChange:()=>{}})})]}),H&&e.jsx(y,{variant:"ghost",size:"sm",onClick:()=>F(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(Z,{value:B,items:ra,onValueChange:v=>ae(String(v)),disabled:!Y,children:[e.jsx(ee,{className:"w-56",children:e.jsx(se,{})}),e.jsx(te,{children:ra.map(v=>e.jsx(J,{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(ps,{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:x,disabled:!Y}),f&&xs&&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(Z,{value:String(h),items:aa,onValueChange:v=>{v!==null&&j(Number(v))},disabled:!Y,children:[e.jsx(ee,{className:"w-56 shrink-0","aria-label":t("Merge sessions in the same project"),children:e.jsx(se,{})}),e.jsx(te,{children:aa.map(v=>e.jsx(J,{value:v.value,children:v.label},v.value))})]})]}),e.jsx(ps,{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:I,disabled:!Y}),e.jsx(ps,{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:C,onChange:S,disabled:!Y}),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:tt===void 0?t("Review now runs even when the switch above is off."):tt===null?t("No model is available for memory tasks."):t("Checked {{pairs}} pairs, flagged {{count}} conflicts.",{pairs:String(tt.judged),count:String(tt.challenges)})}),e.jsx(y,{size:"sm",variant:"outline",disabled:qn||!Y,onClick:hi,children:t(qn?"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(ps,{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:N,onChange:A,disabled:!Y}),e.jsx(ps,{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:$,onChange:E,disabled:!Y||!N}),e.jsx(ps,{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:M,disabled:!Y||!N||!$}),N&&e.jsxs(e.Fragment,{children:[e.jsx(nn,{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(k),items:tn(lc,k,v=>t("{{count}} days",{count:String(v)})),onChange:v=>T(Number(v)),disabled:!Y}),e.jsx(nn,{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(_),items:tn(cc,_,v=>v.toFixed(2)),onChange:v=>q(Number(v)),disabled:!Y}),e.jsx(nn,{rowId:"memory.decayInterval",title:t("Run every"),description:t("Checked when the library opens; there is no separate background timer."),value:String(w),items:tn(dc,w,v=>t("{{count}} days",{count:String(v)})),onChange:v=>z(Number(v)),disabled:!Y})]}),N&&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:$||L?t("Archive candidates: {{count}}",{count:String(Gt?.candidates??0)}):t("Archive candidates: marking is off")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:ui})]}),e.jsxs("div",{className:"flex shrink-0 gap-2",children:[e.jsx(y,{size:"sm",variant:"outline",disabled:et!==null||!Y,onClick:xi,children:t(et==="run"?"Running…":"Run now")}),e.jsx(y,{size:"sm",variant:"outline",disabled:!$||(Gt?.candidates??0)===0,onClick:Zn,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")}),re===null||re.total===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:t("No memories stored yet.")}):e.jsxs(e.Fragment,{children:[hr(re)&&e.jsx("p",{className:"text-xs text-destructive",children:t("Vectors unavailable: {{reason}}",{reason:hr(re)??""})}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-3",children:[e.jsx(cs,{label:t("Memories"),value:String(re.total)}),e.jsx(cs,{label:t("Crystals"),value:String(re.crystals)}),e.jsx(cs,{label:t("Entities"),value:String(re.entities)}),e.jsx(cs,{label:t("With vectors"),value:`${re.embedded}/${re.total}`,action:re.embedded<re.total?e.jsx("button",{type:"button",disabled:Ts,className:"text-xs text-muted-foreground underline-offset-2 hover:underline disabled:opacity-60",onClick:()=>{Wn(!0),window.electronAPI.memory.reembed().then(()=>us.current?.())},children:t(Ts?"Backfilling…":"Backfill")}):null}),e.jsx(cs,{label:t("Database size"),value:he(re.databaseBytes)}),e.jsx(cs,{label:t("Spaces"),value:String(Object.keys(re.bySpace).length)}),e.jsx(cs,{label:t("Never retrieved"),value:`${re.neverHit}/${re.total}`,action:e.jsx("span",{className:"text-muted-foreground text-xs",children:t("{{percent}}% of library",{percent:String(re.total>0?Math.round(re.neverHit/re.total*100):0)})})}),e.jsx(cs,{label:t("Added in 7 days"),value:String(re.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")}),Qn.length>0&&e.jsx(y,{size:"sm",variant:"outline",disabled:!Y||V!==null||xs!==null,onClick:()=>ea(vs,"all",t("All sessions")),children:V==="all"?t("Distilling…"):t("Distill all ({{count}})",{count:String(Qn.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.")}),Je&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:[t("{{done}}/{{total}} done",{done:String(Je.done),total:String(Je.total)}),(()=>{const v=Dh(Je,Date.now());return v===null?"":` · ${t("about {{time}} left",{time:Lh(v)})}`})()]}),Xn.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:Xn.map(v=>{const ye=v.sessions.filter(Fe=>!Fe.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(ye.length)})})]}),e.jsxs("div",{className:"flex shrink-0 gap-2",children:[e.jsx(y,{size:"sm",variant:"ghost",onClick:()=>Se(v),children:t("View sessions")}),e.jsx(y,{size:"sm",variant:"outline",disabled:!Y||V!==null||v.sessions.length===0||xs!==null,onClick:()=>ea(v.sessions,v.key,v.name),children:V===v.key?t("Distilling…"):t("Distill project")})]})]},v.key)})})]}),e.jsx(pe,{open:Te!==null,onOpenChange:v=>!v&&Se(null),children:e.jsx(fe,{children:Te&&e.jsxs(e.Fragment,{children:[e.jsxs(ge,{children:[e.jsx(je,{children:Te.name}),e.jsx(We,{children:t("{{total}} sessions · {{pending}} not distilled",{total:String(Te.sessions.length),pending:String(Te.sessions.filter(v=>!v.distilled).length)})})]}),e.jsx(ve,{children:e.jsx("ul",{className:"divide-y rounded-lg border",children:Te.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:!Y||V!==null||xs!==null,onClick:()=>{nt([v],v.sessionId,v.distilled)},children:V===v.sessionId?t("Distilling…"):v.distilled?t("Distill again"):t("Distill")})]},v.sessionId))})}),e.jsx(ke,{children:e.jsx(Us,{render:e.jsx(y,{variant:"outline",size:"sm"}),children:t("Close")})})]})})}),e.jsx(pe,{open:Oe!==null,onOpenChange:v=>!v&&Zs(null),children:e.jsx(fe,{children:Oe&&e.jsxs(e.Fragment,{children:[e.jsxs(ge,{children:[e.jsx(je,{children:t("Some sessions were already distilled")}),e.jsx(We,{children:t("{{label}}: {{total}} sessions, {{done}} already distilled. Re-distilling runs the model again and may add new memories alongside the existing ones.",{label:Oe.label,total:String(Oe.scope.length),done:String(Oe.scope.length-Oe.pending.length)})})]}),e.jsxs(ke,{children:[e.jsx(Us,{render:e.jsx(y,{variant:"ghost",size:"sm"}),children:t("Cancel")}),e.jsx(y,{variant:Oe.pending.length>0?"default":"outline",size:"sm",disabled:Oe.pending.length===0,onClick:()=>{const v=Oe;Zs(null),nt(v.pending,v.token)},children:t("Only the {{count}} remaining",{count:String(Oe.pending.length)})}),e.jsx(y,{variant:Oe.pending.length>0?"outline":"default",size:"sm",onClick:()=>{const v=Oe;Zs(null),nt(v.scope,v.token,!0)},children:t("Re-distill all {{count}}",{count:String(Oe.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:[Pe.kgFailed>0&&e.jsx(y,{size:"sm",variant:"ghost",onClick:()=>{window.electronAPI.memory.retryFailedKgJobs().then(()=>us.current?.())},children:t("Retry failed extractions ({{count}})",{count:String(Pe.kgFailed)})}),Ns.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")}),Ns.length>ur&&e.jsx(y,{size:"sm",variant:"ghost",onClick:()=>di(!Vt),children:Vt?t("Show less"):t("Show all {{count}}",{count:String(Ns.length)})})]})]}),Ns.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:(Vt?Ns:Ns.slice(0,ur)).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(ne,{variant:v.state==="failed"?"destructive":"secondary",children:t(Rh[v.kind])}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-sm",children:v.target}),e.jsx("span",{className:W("shrink-0 text-xs",v.state==="failed"?"text-destructive":"text-muted-foreground"),children:v.state==="running"?`⋯ ${v.detail}`:v.detail})]}),v.notes.map(ye=>e.jsxs("p",{className:"pl-1 text-muted-foreground text-xs",children:["· ",ye]},ye))]},v.key))})]}),e.jsx(pe,{open:_e!==null,onOpenChange:v=>!v&&Hn(null),children:e.jsxs(fe,{children:[e.jsxs(ge,{children:[e.jsx(je,{children:t("Archive candidates")}),e.jsx(We,{children:t("Cold and low-importance memories. Archiving keeps them, hides them from search, and can be undone from the library.")})]}),e.jsx(ve,{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(bs.size),total:String(_e.items.length)})}),e.jsx(y,{size:"sm",variant:"ghost",onClick:()=>Kt(bs.size===_e.items.length?new Set:new Set(_e.items.map(v=>v.id))),children:bs.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(Re,{checked:bs.has(v.id),onCheckedChange:()=>Kt(ye=>{const Fe=new Set(ye);return Fe.has(v.id)?Fe.delete(v.id):Fe.add(v.id),Fe}),"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:Ms(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(ke,{children:[e.jsx(Us,{render:e.jsx(y,{variant:"outline",size:"sm"}),children:t("Close")}),e.jsx(y,{size:"sm",disabled:bs.size===0||et!==null,onClick:pi,children:t(et==="archive"?"Archiving…":"Archive selected")})]})]})})]})}function cs({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 Fh(s,t){if(t===null)return{ok:!0,value:null};if(s.type==="boolean")return typeof t=="boolean"?{ok:!0,value:t}:t==="true"||t==="false"?{ok:!0,value:t==="true"}:{ok:!1,error:"需要打开或关闭"};if(typeof t!="string")return{ok:!1,error:"值不合法"};if(s.type==="number"){const n=t.trim();if(!/^-?\d+(\.\d+)?$/.test(n))return{ok:!1,error:"需要数字"};const a=Number(n);return Number.isFinite(a)?s.min!==void 0&&a<s.min?{ok:!1,error:"小于最小值"}:s.max!==void 0&&a>s.max?{ok:!1,error:"大于最大值"}:{ok:!0,value:a}:{ok:!1,error:"需要数字"}}return s.type==="enum"?s.options?.includes(t)?{ok:!0,value:t}:{ok:!1,error:"不在可选项里"}:s.type==="model"?Po(t)?{ok:!0,value:t}:{ok:!1,error:"不是合法的模型选择"}:t.length>4096||t.includes("\0")?{ok:!1,error:"值不合法"}:{ok:!0,value:t}}const Bh={"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 Yo(s){return Bh[s]??s}const Uh=["themes","agent","productivity","integrations","insights","writing","fun"],Gn={themes:"主题外观",agent:"Agent 能力",productivity:"效率工作流",integrations:"外部集成",insights:"观测统计",writing:"写作翻译",fun:"休闲娱乐"};function $h(s){return{installedKey:s,refresh:!0}}function Vh(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 Kh({pluginId:s,name:t,from:n,homepage:a,onClose:r}){const{t:o}=R();return e.jsx(pe,{open:s!==null,onOpenChange:i=>!i&&r(),children:e.jsxs(fe,{children:[e.jsx(ge,{children:e.jsxs(je,{children:[o("Usage guide"),t?` · ${t}`:""]})}),e.jsx(ve,{className:"max-h-[60vh] space-y-3 overflow-y-auto",children:s&&e.jsx(Jo,{pluginId:s,from:n,homepage:a})})]})})}function Jo({pluginId:s,from:t,homepage:n,showLink:a=!0}){const{t:r}=R(),[o,i]=l.useState(null),[d,u]=l.useState(null),[m,p]=l.useState(_s(n)),[c,f]=l.useState(null);return l.useEffect(()=>{let x=!0;return ht(()=>import("./globals-BFf1P-Y5.js").then(h=>h.nK),__vite__mapDeps([0,1]),import.meta.url).then(h=>{x&&f(()=>h.Markdown)}),()=>{x=!1}},[]),l.useEffect(()=>{let x=!1;return i(null),u(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,I=j.ok?null:j.error;if(!j.ok&&t==="installed"){const C=await h.readme({id:s,from:"market"});C.ok&&(b=C.markdown,I=null)}if(!_s(n)){const C=await h.marketList(!1),S=C.ok?C.plugins.find(N=>N.id===s):void 0;x||p(_s(S?.homepage))}x||(i(b),u(b?null:I))})(),()=>{x=!0}},[s,t,n]),e.jsxs("div",{className:"space-y-3",children:[a&&m&&e.jsx("a",{href:m,target:"_blank",rel:"noreferrer",className:"text-sm underline",children:r("Homepage")}),d&&e.jsx("p",{className:"text-muted-foreground text-sm",children:d}),o===null&&!d&&e.jsx("p",{className:"text-muted-foreground text-sm",children:"…"}),o!==null&&c&&e.jsx(c,{text:o})]})}function Xo(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 Gh(s){const t=r=>s.filter(o=>Xo(o,r)).length,n=["all","installed","updates"],a=[...Uh,"other"];return[...n.map(r=>({id:r,count:t(r)})),...a.map(r=>({id:r,count:t(r)})).filter(r=>r.count>0)]}function Wh(s,t){const n=t.query.trim().toLowerCase();return s.filter(a=>Xo(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 fr={all:"全部",installed:"已安装",updates:"可更新",other:"其他"},Hh=s=>s in fr?fr[s]:Gn[s];function qh({disabled:s,installedKey:t,onInstall:n,initialQuery:a=""}){const{t:r}=R(),o=window.electronAPI.extensionPlugins,[i,d]=l.useState(null),[u,m]=l.useState(!1),[p,c]=l.useState(a),[f,x]=l.useState("all"),[h,j]=l.useState(null),[b,I]=l.useState(()=>$h(t)),C=Vh(b,t);C!==b&&I(C);const S=l.useCallback(async k=>{m(!0);try{d(await o.marketList(k))}catch(T){d({ok:!1,error:T instanceof Error?T.message:String(T),chinaMirror:!1})}finally{m(!1)}},[o]);l.useEffect(()=>{S(b.refresh)},[S,b]);const N=async k=>{await o.setMarketChinaMirror(k),await S(!0)},A=i?.ok===!0?i.plugins:[],$=Gh(A),E=$.some(k=>k.id===f)?f:"all",L=Wh(A,{query:p,section:E}),M=h?A.find(k=>k.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:$.map(k=>e.jsxs("button",{type:"button","aria-pressed":E===k.id,onClick:()=>{x(k.id),j(null)},className:W("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===k.id&&"bg-accent font-medium"),children:[e.jsx("span",{className:"truncate whitespace-nowrap",children:Hh(k.id)}),e.jsx("span",{className:"text-muted-foreground text-xs tabular-nums",children:k.count})]},k.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(X,{className:"min-w-40 flex-1",value:p,placeholder:r("Search plugins"),onChange:k=>{c(k.target.value),j(null)}}),e.jsxs("label",{className:"flex shrink-0 items-center gap-1.5 text-muted-foreground text-xs",children:[e.jsx(oe,{checked:i?.chinaMirror??!1,disabled:u,onCheckedChange:k=>{N(k)}}),r("China mirror")]}),e.jsx(y,{size:"sm",variant:"ghost",disabled:u,onClick:()=>{S(!0)},children:u?e.jsx(zs,{}):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:M?e.jsx(Jh,{plugin:M,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(k=>e.jsx(Yh,{plugin:k,disabled:s,onOpen:()=>j(k.id),onInstall:n},k.id))})})]})]})}function Qo({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 Zo({tier:s}){const{t}=R();return e.jsx(ne,{variant:s==="official"?"secondary":"outline",className:"text-[11px]",children:t(s==="official"?"Official":"Community")})}function Yh({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(ei,{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(Zo,{tier:s.tier})]}),e.jsxs("p",{className:"text-muted-foreground text-xs",children:[s.latest,s.category?` · ${Gn[s.category]}`:""]})]}),e.jsx(Qo,{plugin:s,disabled:t,onInstall:a})]}),s.description&&e.jsx("p",{className:"line-clamp-2 text-muted-foreground text-xs",children:s.description})]})}function Jh({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(po,{className:"size-3.5"}),"返回"]}),e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(ei,{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(Zo,{tier:s.tier}),s.category&&e.jsx(ne,{variant:"outline",className:"text-[11px]",children:Gn[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(mc,{className:"size-3"}),r("Homepage")]})]}),e.jsx(Qo,{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:Yo(i)})]},i))})]}),e.jsxs("section",{className:"space-y-1",children:[e.jsx("h3",{className:"font-medium text-sm",children:r("Usage guide")}),e.jsx(Jo,{pluginId:s.id,from:"market",homepage:s.homepage,showLink:!1})]})]})}function ei({src:s,large:t}){const[n,a]=l.useState(!1);return e.jsx("div",{className:W("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(Tt,{className:"size-4 text-muted-foreground"})})}const gr={session:"跟随当前会话",title:"跟随标题模型",fixed:"指定模型"};function Xh({value:s,onChange:t}){const n=ts(),a=Po(s)??"session",r=typeof a=="string"?a:"fixed",o=typeof a=="string"?null:a,i=o?n.find(u=>u.id===o.providerId):void 0,d=i?.models.find(u=>u.id===o?.modelId);return e.jsxs("div",{className:"space-y-2",children:[e.jsxs(Z,{items:gr,value:r,onValueChange:u=>{if(u==="session"||u==="title")t(u);else if(u==="fixed"&&!o){const m=n[0],p=m?.models[0];m&&p&&t(Pa({providerId:m.id,modelId:p.id}))}},children:[e.jsx(ee,{children:e.jsx(se,{})}),e.jsx(te,{children:Object.entries(gr).map(([u,m])=>e.jsx(J,{value:u,disabled:u==="fixed"&&n.length===0,children:m},u))})]}),o&&e.jsx(ze,{providers:n,providerId:i?.id??"",modelId:d?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:"选择模型",side:"bottom",triggerClassName:es,onSelect:(u,m)=>t(Pa({providerId:u,modelId:m})),onReasoningChange:()=>{},onThinkingChange:()=>{}}),o&&!d&&e.jsx("p",{className:"text-destructive text-xs",children:"选中的模型已不可用,运行时会失败,请重新选择。"})]})}function Qh(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 Zh({pluginId:s,plain:t}){const{t:n}=R(),[a,r]=l.useState([]),[o,i]=l.useState({}),[d,u]=l.useState(null),m=l.useCallback(async()=>{const x=await window.electronAPI.extensionPlugins.configGet(s);x.ok?r(x.fields):u({error:!0,text:x.error}),i({})},[s]);l.useEffect(()=>{m()},[m]);const p=async()=>{const x={};for(const[j,b]of Object.entries(o)){const I=a.find(S=>S.key===j);if(!I||I.secret&&b==="")continue;const C=Fh(I,b);if(!C.ok){u({error:!0,text:`${I.title}:${C.error}`});return}x[j]=C.value}const h=await window.electronAPI.extensionPlugins.configSet(s,x);u(h.ok?{error:!1,text:n("Saved. New calls use it right away.")}:{error:!0,text:h.error??""}),h.ok&&await m()},c=x=>{const h=o[x.key];return typeof h=="string"?h:h===null||x.secret?"":x.value??(x.default!==void 0?String(x.default):"")},f=x=>{const h=o[x.key];return typeof h=="boolean"?h:(x.value??(typeof x.default=="boolean"?String(x.default):"false"))==="true"};return e.jsxs("div",{className:W("space-y-2",t?"":"rounded-md border border-border p-3"),children:[a.map(x=>e.jsxs("div",{className:"space-y-1",children:[e.jsxs("p",{className:"text-sm",children:[x.title,e.jsx("span",{className:"ml-2 font-mono text-muted-foreground text-xs",children:x.key})]}),x.description&&e.jsx("p",{className:"text-muted-foreground text-xs",children:x.description}),x.multiline&&x.type==="string"?e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Qe,{autoComplete:"off",rows:4,value:c(x),placeholder:x.secret&&x.set?n("Set (leave blank to keep)"):n("Not set"),className:"min-w-0 flex-1",onChange:h=>i(j=>({...j,[x.key]:h.target.value}))}),x.set&&e.jsx(y,{size:"sm",variant:"ghost",onClick:()=>i(h=>({...h,[x.key]:null})),children:n("Clear value")})]}):x.secret||x.type==="string"||x.type==="number"||x.type==="path"?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(X,{type:x.secret?"password":x.type==="number"?"number":"text",autoComplete:"off",inputMode:x.type==="number"?"decimal":void 0,min:x.type==="number"?x.min:void 0,max:x.type==="number"?x.max:void 0,value:c(x),placeholder:x.secret&&x.set?n("Set (leave blank to keep)"):n("Not set"),onChange:h=>i(j=>({...j,[x.key]:h.target.value}))}),x.type==="path"&&!x.secret&&!window.electronAPI.remote&&e.jsx(y,{size:"sm",variant:"outline",onClick:()=>{window.electronAPI.extensionPlugins.pickPath(x.pathKind==="directory"?"directory":"file").then(h=>{h.ok&&"path"in h&&i(j=>({...j,[x.key]:h.path}))})},children:x.pathKind==="directory"?"选择文件夹":"选择文件"}),x.set&&e.jsx(y,{size:"sm",variant:"ghost",onClick:()=>i(h=>({...h,[x.key]:null})),children:n("Clear value")})]}):x.type==="boolean"?e.jsx(oe,{checked:f(x),onCheckedChange:h=>i(j=>({...j,[x.key]:h}))}):x.type==="model"?e.jsx(Xh,{value:c(x),onChange:h=>i(j=>({...j,[x.key]:h}))}):e.jsxs(Z,{items:Object.fromEntries((x.options??[]).map(h=>[h,h])),value:c(x),onValueChange:h=>{typeof h=="string"&&i(j=>({...j,[x.key]:h}))},children:[e.jsx(ee,{children:e.jsx(se,{placeholder:"请选择"})}),e.jsx(te,{children:(x.options??[]).map(h=>e.jsx(J,{value:h,children:h},h))})]})]},x.key)),d&&e.jsx("p",{className:W("text-xs",d.error?"text-destructive":"text-muted-foreground"),children:d.text}),e.jsx(y,{size:"sm",disabled:Object.keys(o).length===0,onClick:()=>{p()},children:n("Save")})]})}function ep({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:W("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(is,{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 jr({message:s}){const[t,n]=l.useState(!1);return e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("p",{className:W("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 si({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:Yo(n)})]},n))})}function sp(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 vr(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 br({permissions:s,env:t,interop:n,resident:a,running:r,styles:o,trustedUi:i,events:d,schedules:u}){return e.jsxs("div",{className:"space-y-1",children:[e.jsx(si,{permissions:s,styles:o||i}),i&&e.jsx(tp,{}),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(", ")})]}),d?.map(m=>e.jsxs("p",{className:"text-xs",children:["事件 ",m.event," · ",m.mode==="intercept"?"拦截":"观察",m.failClosed?" · 失败即拒绝":""]},`${m.event}:${m.mode}`)),u?.map(m=>e.jsxs("p",{className:"text-xs",children:["定时任务 ",sp(m)]},m.id))]})}function tp(){return e.jsx("p",{className:"text-amber-700 text-xs dark:text-amber-400",children:"界面代码:运行在主界面里,可读写页面内容、调用界面能力,不受上面权限清单约束;只安装信任的插件"})}function np({pluginId:s,plain:t}){const[n,a]=l.useState(null),[r,o]=l.useState(null),i=l.useCallback(async()=>{const d=await window.electronAPI.extensionPlugins.artifactsList(s);d.ok?(a(d.artifacts),o(null)):o(d.error)},[s]);return l.useEffect(()=>{i()},[i]),e.jsxs("div",{className:W("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(is,{className:"size-4"})})]}),r&&e.jsx("p",{className:"text-destructive text-xs",children:r}),e.jsx(fc,{artifacts:n??[],onDelete:d=>{window.electronAPI.extensionPlugins.artifactDelete(d).then(u=>{u.ok?i():o(u.error??"删除失败")})}})]})}const an=new Set;function ap({requestedInstallUrl:s=null,onRequestedInstallUrlConsumed:t,focusPluginId:n=null,onFocusPluginConsumed:a,requestedMarketQuery:r=null,onRequestedMarketQueryConsumed:o}={}){const{t:i}=R(),d=g(P=>P.pluginAutoUpdate!==!1),u=g(P=>P.setPluginAutoUpdate),[m,p]=l.useState([]),c=Tn(P=>P.errors),[f,x]=l.useState(null),[h,j]=l.useState(null),[b,I]=l.useState([]),[C,S]=l.useState(!1),[N,A]=l.useState(null),[$,E]=l.useState(""),[L,M]=l.useState(!1),[k,T]=l.useState(!1),[_,q]=l.useState(null),[w,z]=l.useState(null),[H,F]=l.useState(!1),[G,le]=l.useState("");l.useEffect(()=>{r&&(le(r),F(!0),o?.())},[r,o]);const[B,ae]=l.useState(null),K=l.useCallback(async()=>{try{p(await window.electronAPI.extensionPlugins.list())}catch{p([])}},[]);l.useEffect(()=>(K(),window.electronAPI.extensionPlugins.registryNotice().then(z).catch(()=>z(null)),window.electronAPI.extensionPlugins.onChanged(()=>{K()})),[K]),l.useEffect(()=>{if(!n||(I(Q=>Q.includes(n)?Q:[...Q,n]),!m.some(Q=>Q.id===n)))return;const P=n;window.requestAnimationFrame(()=>{document.querySelector(`[data-plugin-id="${CSS.escape(P)}"]`)?.scrollIntoView({block:"center"})}),a?.()},[n,m,a]);const ie=async P=>{A(null),f&&window.electronAPI.extensionPlugins.discard(f.token),x(null);const Q=await window.electronAPI.extensionPlugins.pickAndStage(P);Q.ok?"cancelled"in Q||x(Q.preview):A(Q.error)},U=async P=>{const Q=(P??$).trim();if(!Q)return;A(null),M(!0),f&&window.electronAPI.extensionPlugins.discard(f.token),x(null);const O=await window.electronAPI.extensionPlugins.stageFromUrl(Q).finally(()=>{M(!1)});O.ok?x(O.preview):A(O.error)},ce=l.useRef(U);ce.current=U,l.useEffect(()=>{if(!s)return;const P=s;let Q=!1;const O=window.setTimeout(()=>{Q||an.has(P)||(an.add(P),E(P),t?.(),ce.current(P).finally(()=>{an.delete(P)}))},0);return()=>{Q=!0,window.clearTimeout(O)}},[s,t]);const de=async(P,Q=!1)=>{A(null),f&&window.electronAPI.extensionPlugins.discard(f.token),x(null),M(!0);const O=window.electronAPI.extensionPlugins,Y=await(Q?O.marketStage(P):O.restage(P)).finally(()=>{M(!1)});Y.ok?x(Y.preview):A(Y.error)},D=async()=>{T(!0),q(null);try{const P=await window.electronAPI.extensionPlugins.checkUpdates();q(P.checked===0?i("No plugins installed from GitHub to check"):P.available>0?i("{{count}} update(s) available",{count:P.available}):i("All plugins are up to date"))}finally{T(!1)}},qe=async()=>{if(!f)return;S(!0);const P=await window.electronAPI.extensionPlugins.commit(f.token);if(S(!1),!P.ok)A(P.error??i("Install failed"));else{E("");const Q=f.existingVersion?{ok:!0}:await window.electronAPI.extensionPlugins.setEnabled(f.id,!0);Ie({type:Q.ok?"success":"warning",title:i("{{name}} installed",{name:f.name}),description:Q.ok?void 0:Q.error})}x(null)},Ne=()=>{f&&window.electronAPI.extensionPlugins.discard(f.token),x(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(ss,{})]}),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:[m.length>0&&e.jsxs(y,{size:"sm",variant:"outline",disabled:k,onClick:()=>{D()},children:[k?e.jsx(zs,{}):e.jsx(is,{className:"size-4"}),i("Check for updates")]}),e.jsxs(y,{size:"sm",onClick:()=>{le(""),F(!0)},children:[e.jsx(km,{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(oe,{className:"shrink-0",checked:d,onCheckedChange:P=>u(P)})]}),e.jsxs("div",{className:"space-y-2.5 rounded-lg border bg-muted/30 p-3",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(uo,{className:"flex-1",children:[e.jsx(ho,{children:e.jsx(Mo,{className:"size-4 text-muted-foreground"})}),e.jsx(xo,{value:$,placeholder:i("https://github.com/owner/repo"),onChange:P=>E(P.target.value),onKeyDown:P=>{P.key==="Enter"&&U()}})]}),e.jsx(y,{size:"sm",variant:"outline",disabled:C||L||$.trim()==="",onClick:()=>{U()},children:L?e.jsx(zs,{}):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:C||L,onClick:()=>{ie("dir")},children:[e.jsx(Dn,{className:"size-3.5"}),i("Install from folder")]}),e.jsxs(y,{size:"xs",variant:"ghost",disabled:C||L,onClick:()=>{ie("zip")},children:[e.jsx(uc,{className:"size-3.5"}),i("Install from zip")]})]})]}),N&&e.jsx("p",{className:"text-destructive text-sm",children:N}),e.jsx(pe,{open:H,onOpenChange:F,children:e.jsxs(fe,{className:"max-w-5xl",children:[e.jsx(ge,{children:e.jsx(je,{children:i("Marketplace")})}),e.jsx(ve,{children:e.jsx(qh,{initialQuery:G,disabled:C||L,installedKey:m.map(P=>`${P.id}@${P.version}`).join(","),onInstall:P=>{F(!1),de(P,!0)}},G)})]})}),_&&e.jsx("p",{className:"text-muted-foreground text-sm",children:_}),w&&e.jsx(Qh,{notice:w,remote:!!window.electronAPI.remote,onDismiss:()=>{window.electronAPI.extensionPlugins.dismissRegistryNotice().then(()=>z(null)).catch(P=>A(P instanceof Error?P.message:String(P)))}}),e.jsx(pe,{open:f!==null,onOpenChange:P=>!P&&!C&&Ne(),children:e.jsx(fe,{children:f&&e.jsxs(e.Fragment,{children:[e.jsx(ge,{children:e.jsxs(je,{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(ve,{className:"space-y-3",children:[e.jsx(br,{permissions:f.permissions,env:f.env,interop:f.interop,resident:f.resident,styles:f.styles,trustedUi:f.hasRenderer,events:f.events,schedules:f.schedules}),f.mcpServers.map(P=>e.jsxs("p",{className:"font-mono text-xs",children:[P.command," ",P.args.join(" ")]},P.name)),f.mcpTools.length>0&&e.jsxs("p",{className:"text-muted-foreground text-xs",children:[i("Host MCP tools it may call"),":",e.jsx("span",{className:"font-mono",children:f.mcpTools.join(", ")})]}),f.warnings.map(P=>e.jsx("p",{className:"text-muted-foreground text-xs",children:P},P))]}),e.jsxs(ke,{children:[e.jsx(y,{size:"sm",variant:"ghost",disabled:C,onClick:Ne,children:i("Cancel")}),e.jsx(y,{size:"sm",disabled:C,onClick:()=>{qe()},children:C?e.jsx(zs,{}):i("Install")})]})]})})}),m.length===0&&!f&&e.jsxs("div",{className:"rounded-lg border border-dashed px-3 py-10 text-center",children:[e.jsx(Tt,{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:m.map(P=>e.jsxs("div",{"data-plugin-id":P.id,className:W("overflow-hidden rounded-lg border bg-card transition-colors",P.state==="crashed"&&"border-destructive/50"),children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-x-3 gap-y-2 p-3",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 basis-56 items-start gap-3",children:[e.jsx("div",{className:W("flex size-9 shrink-0 items-center justify-center rounded-md bg-muted",P.state==="enabled"?"text-foreground":"text-muted-foreground"),children:e.jsx(xc,{pluginId:P.id,icon:P.icon,className:"size-4"})}),e.jsxs("div",{className:"min-w-0 flex-1 space-y-0.5",children:[e.jsxs("p",{className:"flex flex-wrap items-center gap-1.5 text-sm",children:[e.jsx("span",{className:"truncate font-medium",children:P.name}),e.jsx(ne,{variant:"outline",className:"text-[11px]",children:P.version}),P.state==="crashed"&&e.jsx(ne,{variant:"destructive",className:"text-[11px]",children:i("Stopped after crashes")}),P.availableVersion&&e.jsx(ne,{className:"text-[11px]",children:i("Update")}),P.pendingVersion&&e.jsx(ne,{variant:"warning",className:"text-[11px]",children:"待授权"}),P.hasRenderer&&e.jsx(ne,{variant:"outline",className:"text-[11px]",children:"受信任界面"}),P.devWatch&&e.jsx(ne,{variant:"secondary",className:"text-[11px]",children:"开发模式"}),P.resident&&e.jsx(ne,{variant:P.running?"secondary":"outline",className:"text-[11px]",children:P.running?"常驻运行中":"常驻未运行"})]}),e.jsx("p",{className:"truncate font-mono text-muted-foreground text-xs",children:P.id}),P.availableVersion&&e.jsxs("p",{className:"mt-1 flex items-center gap-2 text-primary text-xs",children:[i("Version {{version}} is available",{version:P.availableVersion}),e.jsx(y,{size:"xs",disabled:C||L,onClick:()=>{de(P.id,P.source?.kind!=="url")},children:L?e.jsx(zs,{}):i("Update")})]}),P.updateCheckError&&e.jsx("p",{className:"text-muted-foreground text-xs",children:i("Update check failed: {{reason}}",{reason:P.updateCheckError})}),P.lastError&&e.jsx(jr,{message:P.lastError.message}),c[P.id]?.map(Q=>e.jsx(jr,{message:`主题加载失败:${Q}`},Q)),P.pendingVersion&&e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2 rounded-md border border-amber-500/50 bg-amber-500/10 px-2 py-1.5 text-amber-700 text-xs dark:text-amber-400",children:[i("{{version}} asks for more and is waiting for approval",{version:P.pendingVersion}),e.jsx(y,{size:"xs",onClick:()=>{window.electronAPI.extensionPlugins.approvePending(P.id)},children:i("Allow")}),e.jsx(y,{size:"xs",variant:"ghost",onClick:()=>{window.electronAPI.extensionPlugins.rejectPending(P.id)},children:i("Keep current")})]})]})]}),e.jsxs("div",{className:"ml-auto flex shrink-0 items-center gap-0.5",children:[P.source&&e.jsx(y,{size:"icon",variant:"ghost",disabled:C||L,"aria-label":i("Reinstall from source"),title:P.source.kind==="url"?`${i("Reinstall from source")}: ${P.source.url}`:i("Reinstall from source"),onClick:()=>{de(P.id)},children:e.jsx(hc,{className:"size-4"})}),e.jsx(y,{size:"icon",variant:"ghost","aria-label":"产出文件",title:"产出文件",onClick:()=>j({kind:"artifacts",pluginId:P.id,pluginName:P.name}),children:e.jsx(Jd,{className:"size-4"})}),e.jsx(y,{size:"icon",variant:"ghost","aria-label":i("Usage guide"),title:i("Usage guide"),onClick:()=>ae({id:P.id,name:P.name,from:"installed"}),children:e.jsx(tm,{className:"size-4"})}),e.jsx(y,{size:"icon",variant:"ghost","aria-label":i("Plugin logs"),title:i("Plugin logs"),onClick:()=>j({kind:"logs",pluginId:P.id,pluginName:P.name}),children:e.jsx(Fn,{className:"size-4"})}),P.configurable&&e.jsx(y,{size:"icon",variant:"ghost","aria-label":i("Configure"),title:i("Configure"),onClick:()=>j({kind:"config",pluginId:P.id,pluginName:P.name}),children:e.jsx(pc,{className:"size-4"})}),e.jsx(y,{size:"icon",variant:"ghost","aria-label":i("Uninstall"),title:i("Uninstall"),className:"text-muted-foreground hover:text-destructive",onClick:()=>{window.electronAPI.extensionPlugins.uninstall(P.id)},children:e.jsx(Ee,{className:"size-4"})}),e.jsx("div",{className:"mx-1.5 h-5 w-px bg-border"}),e.jsx(oe,{checked:P.state==="enabled",onCheckedChange:Q=>{window.electronAPI.extensionPlugins.setEnabled(P.id,Q)}})]})]}),e.jsxs("button",{type:"button","aria-expanded":b.includes(P.id),className:W("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:()=>I(Q=>Q.includes(P.id)?Q.filter(O=>O!==P.id):[...Q,P.id]),children:[b.includes(P.id)?e.jsx(vt,{className:"size-3"}):e.jsx(Gs,{className:"size-3"}),b.includes(P.id)?"收起详情":"详情",!b.includes(P.id)&&vr(P)&&e.jsx("span",{className:"ml-1 opacity-70",children:vr(P)})]}),b.includes(P.id)&&e.jsxs("div",{className:"space-y-3 border-t px-3 py-3",children:[P.interceptBreakers?.map(Q=>e.jsxs("p",{className:"text-amber-600 text-xs dark:text-amber-400",children:[Q.event," 检查连续失败,临时放行到"," ",new Date(Q.until).toLocaleTimeString()]},Q.event)),e.jsx(br,{permissions:P.permissions,resident:P.resident,running:P.running,styles:P.themes.some(Q=>Q.css!==void 0),trustedUi:P.hasRenderer,events:P.events,schedules:P.schedules}),P.crossSessionInject!==void 0&&e.jsxs("div",{className:"flex items-center justify-between gap-3 text-xs",children:[e.jsxs("span",{children:[e.jsx("span",{className:"block",children:"允许向任意运行中的会话发送消息"}),e.jsx("span",{className:"block text-muted-foreground",children:"关闭时只能发到发起调用的会话;开启后定时任务、常驻进程也能向其他项目和窗口的会话发消息并触发执行"})]}),e.jsx(oe,{"aria-label":"允许向任意运行中的会话发送消息",checked:P.crossSessionInject,onCheckedChange:Q=>{window.electronAPI.extensionPlugins.setCrossSessionInject(P.id,Q)}})]}),P.devWatch!==void 0&&e.jsxs("div",{className:"flex items-center justify-between gap-3 text-xs",children:[e.jsxs("span",{children:[e.jsx("span",{className:"block",children:"开发模式:目录改动后自动重装"}),e.jsx("span",{className:"block text-muted-foreground",children:"授权没扩大时直接替换;扩大时停下,需要从来源重新安装并同意。重启应用后关闭"})]}),e.jsx(oe,{"aria-label":"开发模式:目录改动后自动重装",checked:P.devWatch,onCheckedChange:Q=>{window.electronAPI.extensionPlugins.setDevWatch(P.id,Q).then(O=>{!O.ok&&O.error&&Ie({title:O.error})})}})]}),((P.pendingPermissions?.length??0)>0||P.pendingRenderer)&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:"待同意"}),e.jsx(si,{permissions:P.pendingPermissions??[],styles:P.pendingRenderer}),P.pendingRenderer&&e.jsx("p",{className:"text-amber-700 text-xs dark:text-amber-400",children:"新增界面代码:运行在主界面里,不受权限清单约束"})]})]})]},P.id))}),e.jsx(pe,{open:h!==null,onOpenChange:P=>!P&&j(null),children:e.jsxs(fe,{children:[e.jsx(ge,{children:e.jsxs(je,{children:[h?.kind==="config"?i("Configure"):h?.kind==="logs"?i("Plugin logs"):"产出文件",h?` · ${h.pluginName}`:""]})}),e.jsxs(ve,{className:"space-y-4",children:[h?.kind==="config"&&e.jsx(Zh,{pluginId:h.pluginId,plain:!0}),h?.kind==="logs"&&e.jsx(ep,{pluginId:h.pluginId,plain:!0}),h?.kind==="artifacts"&&e.jsx(np,{pluginId:h.pluginId,plain:!0})]})]})}),e.jsx(Kh,{pluginId:B?.id??null,name:B?.name??"",from:B?.from??"installed",homepage:B?.homepage,onClose:()=>ae(null)})]})}const Vs={mask:"Mask",warn:"Warn only",block:"Block"},rp={email:"Email",phone:"Phone number",idCard:"ID card number",bankCard:"Bank card number",ip:"IP address"},Sn={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],ip={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 rn({value:s,onChange:t}){const{t:n}=R(),a=Object.fromEntries(Object.keys(Vs).map(r=>[r,n(Vs[r])]));return e.jsxs(Z,{items:a,value:s,onValueChange:r=>t(r),children:[e.jsx(ee,{className:"w-32",children:e.jsx(se,{})}),e.jsx(te,{children:Object.entries(a).map(([r,o])=>e.jsx(J,{value:r,children:o},r))})]})}function on({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(Qe,{rows:3,value:o,onChange:d=>i(d.target.value),onBlur:()=>a(o.split(`
|
|
20
|
+
`))})]})}function As({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 cp({settings:s}){const{t}=R(),[n,a]=l.useState(""),r=l.useMemo(()=>jc(n,s),[n,s]);return e.jsxs(As,{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(Qe,{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:W("font-medium",Sn[o.action]),children:t(Vs[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 dp(){const{t:s}=R(),[t,n]=l.useState(7),[a,r]=l.useState(null),[o,i]=l.useState(!1),d=l.useRef(0),u=vc(f=>f.conversations),m=l.useCallback(async f=>{const x=++d.current;i(!0);const h=await window.electronAPI.privacyMask.records(f).catch(()=>[]);x===d.current&&(i(!1),r(h))},[]);l.useEffect(()=>{m(t)},[t,m]);const p=l.useMemo(()=>{const f={mask:0,warn:0,block:0},x=new Map;for(const h of a??[]){const j=new Set;for(const b of h.report.hits){const I=`${b.action}:${b.token}`;j.has(I)||(j.add(I),f[b.action]+=1,x.set(b.kind,(x.get(b.kind)??0)+1))}}return{byAction:f,byKind:[...x].sort((h,j)=>j[1]-h[1])}},[a]),c=f=>{if(f.source==="aux")return s("Auxiliary request");const x=f.sessionId?u[f.sessionId]?.title:void 0,h=f.source==="compaction"?s("Compaction"):s("Session");return x?`${h} · ${x}`:h};return e.jsxs(As,{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(ip[f])},f))}),e.jsx(y,{variant:"ghost",size:"icon-sm",onClick:()=>{m(t)},disabled:o,"aria-label":s("Refresh"),children:e.jsx(is,{className:W("size-4",o&&"animate-spin")})})]}),e.jsx("div",{className:"flex flex-wrap gap-4 text-sm",children:Object.keys(Vs).map(f=>e.jsxs("span",{children:[e.jsx("span",{className:Sn[f],children:s(Vs[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,x])=>e.jsxs("span",{className:"rounded bg-muted px-1.5 py-0.5",children:[f," ",x]},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 x=bc(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:W("py-1",x&&Sn[x]),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 mp(){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(we,{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(As,{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(rn,{value:t.secrets.action,onChange:r=>a({secrets:{...t.secrets,action:r}})})]}),e.jsx(we,{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(we,{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(As,{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(rn,{value:t.personal.action,onChange:r=>a({personal:{...t.personal,action:r}})})]}),e.jsx(we,{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:gc.map(r=>e.jsxs("label",{className:"flex items-center gap-1.5 text-sm",children:[e.jsx(Re,{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(As,{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(rn,{value:t.custom.action,onChange:r=>a({custom:{...t.custom,action:r}})})]}),e.jsx(on,{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(on,{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(As,{title:s("Allow list"),children:e.jsx(on,{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(cp,{settings:t})]}),e.jsx(dp,{})]})}function up(){const{t:s}=R(),t=g(x=>x.approvalReviewer),n=g(x=>x.setApprovalReviewer),a=g(x=>x.approvalAutoManage),r=g(x=>x.setApprovalAutoManage),o=yc(g(x=>x.approvalAllowThreshold)),i=g(x=>x.setApprovalAllowThreshold),d={"0.85":s("0.85 (looser)"),"0.9":s("0.9 (default)"),"0.95":s("0.95 (stricter)")},u=ts(),m=Ln(),p=l.useMemo(()=>[...u,...m.filter(bn)],[u,m]),c=t?p.find(x=>x.id===t.providerId):void 0,f=c?.models.find(x=>x.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(ze,{providers:p,providerId:c?.id??"",modelId:f?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:s("No assistant approval model selected"),side:"bottom",triggerClassName:es,onSelect:(x,h)=>n({providerId:x,modelId:h}),onReasoningChange:()=>{},onThinkingChange:()=>{}})}),c&&bn(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(oe,{"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(Z,{items:d,value:String(o),onValueChange:x=>i(Number(x)),children:[e.jsx(ee,{className:"w-36","aria-label":s("Auto-allow threshold"),children:e.jsx(se,{})}),e.jsx(te,{children:wc.map(x=>e.jsx(J,{value:String(x),children:d[String(x)]},x))})]})]}),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 yr(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 xp(){const{t:s}=R(),t=qs(),n=g(A=>A.virtualModels),a=g(A=>A.defaultModel),r=g(A=>A.setDefaultModel),o=g(A=>A.defaultModelFollowLast),i=g(A=>A.setDefaultModelFollowLast),d=g(A=>A.defaultReasoningEnabled),u=g(A=>A.defaultThinkingLevel),m=g(A=>A.setDefaultReasoningEnabled),p=g(A=>A.setDefaultThinkingLevel),c=bt(A=>A.snapshot),f=Nc(A=>A.latest),x=ts(),h=a?x.find(A=>A.id===a.providerId):void 0,j=h?.models.find(A=>A.id===a?.modelId),b=t.some(A=>!!A.oauthAccountKey),I=b&&(c.availability.status==="unloaded"||c.availability.status==="loading"),C=b&&c.availability.status==="error"?c.availability.error:null,S=f?.notice,N=S?s("Default model changed: {{previous}} → {{next}}",{previous:yr(S.previous,t),next:S.next?yr(S.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.")})]}),x.length>0&&e.jsx("div",{className:"w-full min-w-0",children:e.jsx(ze,{providers:x,virtualModels:n,providerId:h?.id??a?.providerId??"",modelId:j?.id??a?.modelId??"",reasoningEnabled:d,thinkingLevel:u,emptyLabel:s("Select model"),triggerLabel:o?s("Follow last selection"):void 0,side:"bottom",triggerClassName:es,onSelect:(A,$)=>r({providerId:A,modelId:$}),onReasoningChange:m,onThinkingChange:p,showReasoningControls:!o})}),!o&&x.length>0&&e.jsx(y,{type:"button",variant:"ghost",size:"sm",className:"self-start",onClick:()=>i(!0),children:s("Follow last selection")}),x.length===0&&e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-5 text-center",children:[e.jsx(Un,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-2 font-medium text-sm",children:s("No usable models")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:s("Enable a model and configure valid provider credentials first.")})]}),(I||C)&&e.jsxs("div",{className:"flex items-start gap-2 rounded-md bg-muted px-2.5 py-2 text-xs",children:[e.jsx(Es,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:C?s("Subscription credentials could not be loaded: {{error}}",{error:C}):s("Subscription credentials are loading. API-key models remain available.")})]}),N&&e.jsx("p",{className:"rounded-md bg-muted px-2.5 py-2 text-muted-foreground text-xs",children:N})]})}function hp(){const{t:s}=R(),t=Rm(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(ze,{providers:t,providerId:n?.providerId??"",modelId:n?.modelId??"",reasoningEnabled:!1,thinkingLevel:"medium",emptyLabel:s("Select model"),side:"bottom",triggerClassName:es,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 pp({provider:s,onClose:t}){const{t:n}=R(),a=g(j=>j.providers),r=g(j=>j.updateProvider),o=fo(j=>j.snapshot),i=l.useMemo(()=>go([s],o)[0]?.models??s.models,[s,o]),d=bt(j=>j.snapshot.availability),u=bt(j=>j.snapshot.revision),[m,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}},[u]);const x=wo(a),h=[...x.flatMap(j=>j.oauthAccountKey??[]),...c.filter(j=>!x.some(b=>b.oauthAccountKey===j))];return e.jsx(jo,{initialValue:{...s,name:$n(s,n),models:i},oauth:!0,hideName:!0,saveDisabled:c.length===0,oauthAccountKey:s.oauthAccountKey,onCancel:t,extraFields:e.jsxs(me,{children:[e.jsx(ue,{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 I=x.find(S=>S.oauthAccountKey===j),C=m.flatMap(S=>S.accounts).find(S=>S.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(Re,{checked:c.includes(j),onCheckedChange:S=>f(N=>S?[...N,j]:N.filter(A=>A!==j))}),e.jsxs("span",{className:"shrink-0 text-xs text-muted-foreground",children:[b+1,"."]}),e.jsx("span",{className:"min-w-0 truncate",children:C?.email??j}),!I?.enabled&&e.jsx("span",{className:"shrink-0 text-xs text-muted-foreground",children:n("Account disabled")}),d.status==="ready"&&!d.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:vo(j.models,yo(o,s.oauthAccountKey??"")?.models,bo(g.getState(),s.id)),oauthAccountPool:{accountKeys:h.filter(b=>c.includes(b))}}),t())}})}function wr(s,t){const n=Object.entries(s.headers??{}),a=t.headers??{};return s.api===t.api&&s.apiKey.trim()===t.apiKey.trim()&&s.baseUrl.trim().replace(/\/+$/,"")===t.baseUrl.trim().replace(/\/+$/,"")&&n.length===Object.keys(a).length&&n.every(([r,o])=>Object.hasOwn(a,r)&&a[r]===o)}function fp({provider:s,onClose:t}){const{t:n}=R(),a=g(d=>d.updateProvider),r=g(d=>d.providers.find(u=>u.id===s?.id)?.modelRefreshStatus),o=fo(d=>d.snapshot),i=l.useMemo(()=>s?.oauthAccountKey?go([s],o)[0]?.models??s.models:s?.models,[s,o]);return e.jsx(pe,{open:s!==null,onOpenChange:d=>!d&&t(),children:e.jsxs(fe,{children:[e.jsx(ge,{children:e.jsx(je,{children:s?.oauthAccountPool?$n(s,n):n("Edit Provider")})}),s?.oauthAccountPool?e.jsx(pp,{provider:s,onClose:t},s.id):s&&e.jsx(jo,{catalogId:s.catalogId,initialValue:{name:s.name,api:s.api,apiKey:s.apiKey,baseUrl:s.baseUrl,models:i??s.models,headers:s.headers,autoFetchModels:s.autoFetchModels,modelRefreshIntervalHours:s.modelRefreshIntervalHours},providerEnabled:s.enabled,modelRefreshStatus:r,oauth:!!s.oauthAccountKey,oauthAccountKey:s.oauthAccountKey,onCancel:t,onSave:(d,u)=>{const m=g.getState();if(s.oauthAccountKey)a(s.id,{name:d.name,models:vo(d.models,yo(o,s.oauthAccountKey)?.models,bo(m,s.id))});else{const p=m.providers.find(C=>C.id===s.id),c=p&&wr(s,d)&&wr(p,d)?kc(d.models,p.models.filter(C=>!u.has(C.id))):d.models,{autoFetchModels:f,modelRefreshIntervalHours:x,...h}=d,j=f!==void 0&&f!==(s.autoFetchModels===!0),b=x!==void 0&&x!==Cc(s.modelRefreshIntervalHours),I=[...new Set([...p?.knownModelIds??[],...u])];a(s.id,{...h,models:c,knownModelIds:I,...j?{autoFetchModels:f}:{},...b?{modelRefreshIntervalHours:x}:{}})}t()}},s.id)]})})}const gp=(s,t)=>s.models.some(n=>n.id===t&&n.enabled!==!1),Nr=()=>{};function kr(s){return s==="on"||s==="off"}function ln(s){return typeof s=="string"&&Mc.includes(s)}function jp(){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),d=g(c=>c.defaultModel),u=g(c=>c.virtualModels),m=ts(),p=l.useMemo(()=>{if(d&&Sc(d)){const c=Ic(u,m).find(f=>f.id===d.modelId);if(c)return{providerId:Ac,modelId:c.id}}if(d){const c=m.find(f=>f.id===d.providerId);if(c&&gp(c,d.modelId))return d}for(const c of m){const f=c.models.find(x=>x.enabled!==!1);if(f)return{providerId:c.id,modelId:f.id}}return null},[m,d,u]);return e.jsxs("section",{"data-slot":"subagent-models",className:"space-y-2 rounded-lg border bg-card p-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h4",{className:"font-medium text-sm",children: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(oe,{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:W("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(oe,{"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(ne,{variant:"outline",className:"shrink-0 text-[10px] text-muted-foreground",children:s("Disabled")}),e.jsx("div",{className:"shrink-0 rounded-md border bg-background",children:e.jsx(ze,{providers:m,virtualModels:u,providerId:c.providerId,modelId:c.modelId,modelCapabilityOverrides:Ec(c),reasoningMode:kr(c.reasoning)?c.reasoning:"follow",reasoningEnabled:c.reasoning==="on",thinkingLevel:ln(c.thinkingLevel)?c.thinkingLevel:"medium",onReasoningModeChange:(f,x)=>{f==="follow"?o(c.id,{reasoning:void 0,thinkingLevel:void 0}):f==="on"&&!ln(c.thinkingLevel)?o(c.id,{reasoning:"on",thinkingLevel:x}):o(c.id,{reasoning:f})},onSelect:(f,x)=>o(c.id,{providerId:f,modelId:x}),onReasoningChange:f=>o(c.id,{reasoning:f?"on":"off"}),onThinkingChange:f=>o(c.id,{thinkingLevel:f}),onReasoningNormalize:kr(c.reasoning)?f=>o(c.id,{reasoning:f?"on":"off"}):Nr,onThinkingNormalize:ln(c.thinkingLevel)?f=>o(c.id,{thinkingLevel:f}):Nr})}),e.jsx(X,{value:c.description,placeholder:s("When to use it, e.g. cheap and fast for simple subtasks"),className:"h-7 flex-1 text-xs",onChange:f=>o(c.id,{description:f.target.value})}),e.jsx(y,{type:"button",variant:"ghost",size:"icon",className:"h-6 w-6 shrink-0 text-muted-foreground hover:text-destructive",onClick:()=>i(c.id),children:e.jsx(Ee,{className:"h-3.5 w-3.5"})})]},c.id)),e.jsxs(y,{type:"button",variant:"outline",size:"sm",className:"h-7 text-xs",disabled:!p,onClick:()=>{p&&r({...p,description:""})},children:[e.jsx(Ae,{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 vp(){const{t:s}=R(),t=g(u=>u.titleSummaryEnabled),n=g(u=>u.setTitleSummaryEnabled),a=g(u=>u.titleSummaryModel),r=g(u=>u.setTitleSummaryModel),o=ts(),i=a?o.find(u=>u.id===a.providerId):void 0,d=i?.models.find(u=>u.id===a?.modelId);return e.jsxs("section",{className:"space-y-2 rounded-lg border bg-card p-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h4",{className:"font-medium text-sm",children: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(oe,{checked:t,onCheckedChange:n})]}),t&&e.jsxs("div",{className:"space-y-2",children:[o.length>0&&e.jsx("div",{className:"w-full min-w-0",children:e.jsx(ze,{providers:o,providerId:i?.id??"",modelId:d?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:s("Follows the default model"),side:"bottom",triggerClassName:es,onSelect:(u,m)=>r({providerId:u,modelId:m}),onReasoningChange:()=>{},onThinkingChange:()=>{}})}),a&&(!i||!d)&&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 bp({accountKey:s}){const t=$c(s);return!t||t.error?null:e.jsx(Vc,{info:t})}function yp(){const{t:s}=R(),t=g(F=>F.providers),n=qs(),a=g(F=>F.updateProvider),r=g(F=>F.addProviders),o=g(F=>F.removeProvider),[i,d]=l.useState(!1),[u,m]=l.useState(!1),[p,c]=l.useState(null),[f,x]=l.useState(null),[h,j]=l.useState(null),[b,I]=l.useState(null),[C,S]=l.useState(!1),[N,A]=l.useState(!1),[$,E]=l.useState(null),L=bt(F=>F.snapshot.revision),[M,k]=l.useState([]);l.useEffect(()=>{let F=!1;return window.electronAPI.providers.listOauth().then(G=>{F||k(G)}),()=>{F=!0}},[L]);const T=l.useMemo(()=>Pc(t,M),[t,M]),_=l.useMemo(()=>{const F=new Map;for(const G of n)F.set(G.id,G.models.length);return F},[n]),q=async(F,G)=>{if(j(F.id),I(null),F.oauthAccountKey&&!F.oauthAccountPool&&!G?.skipLogout)try{await window.electronAPI.providers.oauthLogout(F.oauthAccountKey),await Kc()}catch(le){j(null),I({providerId:F.id,message:le instanceof Error?le.message:String(le)});return}o(F.id),j(null),I(null)},w=()=>{const F=f;F&&q(F)},z=async()=>{S(!0),E(null);try{const F=await Bc(t);Uc(F,a),E(F);const G=Object.values(F).filter(B=>B.status==="failed"),le=Object.keys(F).length-G.length;Ie({type:G.length>0?"warning":"success",title:s("Fetched {{count}} providers",{count:le}),...G.length>0?{description:s("{{count}} failed",{count:G.length})}:{}})}finally{S(!1)}},H=async()=>{A(!0);try{const F=await window.electronAPI.providers.refreshModelCatalog();Fc(),Ie({type:F.ok?"success":"warning",title:F.ok?s("Model info updated"):F.fromCache?s("Model info refresh failed, using cache"):s("Model info refresh failed")})}catch{Ie({type:"error",title:s("Model info refresh failed")})}finally{A(!1)}};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-wrap items-end justify-between gap-x-4 gap-y-3","data-settings-row":"providers.root",children:[e.jsxs("div",{className:"min-w-0 flex-1 basis-56",children:[e.jsxs("h3",{className:"text-lg font-medium",children:[s("Model Providers"),e.jsx(ss,{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:N,onClick:()=>{H()},children:[N?e.jsx(Ce,{className:"mr-1.5 h-4 w-4 animate-spin"}):e.jsx(is,{className:"mr-1.5 h-4 w-4"}),s("Refresh model info")]}),e.jsxs(y,{variant:"outline",size:"sm",disabled:C||t.length===0,onClick:()=>{z()},children:[C?e.jsx(Ce,{className:"mr-1.5 h-4 w-4 animate-spin"}):e.jsx(is,{className:"mr-1.5 h-4 w-4"}),s("Fetch all models")]}),e.jsxs(y,{variant:"outline",size:"sm",onClick:()=>d(!0),children:[e.jsx(Rt,{className:"h-4 w-4 mr-1.5"}),s("Import from local apps")]}),e.jsxs(y,{size:"sm",onClick:()=>m(!0),children:[e.jsx(Ae,{className:"h-4 w-4 mr-1.5"}),s("Add model or provider")]})]})]}),e.jsx(xp,{}),e.jsx(hp,{}),e.jsx(Bu,{}),e.jsx(vp,{}),e.jsx(up,{}),e.jsx(jp,{}),wo(t).length>0&&!t.some(F=>F.oauthAccountPool)&&e.jsxs("div",{className:"space-y-1.5 rounded-md border p-3",children:[e.jsxs(y,{variant:"outline",size:"sm",onClick:()=>{const F=Tc(t,crypto.randomUUID());F&&r([F])>0&&c(F)},children:[e.jsx(Ae,{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(Un,{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:T.map(F=>{const G=M.find(B=>B.id===F.vendorId),le=F.vendorId===Rc?s("Custom"):F.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:le}),e.jsx("span",{className:"text-[11px] text-muted-foreground/60",children:F.providers.length})]}),e.jsx("div",{className:"mt-1.5 space-y-1 border-l pl-3",children:F.providers.map(B=>{const ae=!!B.oauthAccountKey,K=_.get(B.id)??B.models.length,ie=B.oauthAccountKey&&!B.oauthAccountPool?G?.accounts.find(de=>de.key===B.oauthAccountKey):void 0,U=B.oauthAccountPool?$n(B,s):ae?ie?.email??B.oauthAccountKey??B.name:B.name,ce=$?.[B.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.${B.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:[ae?e.jsx(Oc,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}):e.jsx(Dc,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx("span",{className:W("truncate text-sm font-medium",!B.enabled&&"text-muted-foreground line-through"),children:U}),ae?ie?.plan&&e.jsx(ne,{variant:"outline",className:"shrink-0 text-[10px] uppercase",children:ie.plan}):e.jsx(ne,{variant:"outline",className:"shrink-0 text-[11px]",children:Lc[B.api]??B.api}),B.importedFrom&&e.jsx(ne,{variant:"secondary",className:"shrink-0 text-[11px]",children:B.importedFrom}),e.jsx("span",{className:"min-w-0 truncate text-xs text-muted-foreground",children:[ae?void 0:B.baseUrl,B.oauthAccountPool?s("{{count}} accounts",{count:B.oauthAccountPool.accountKeys.length}):void 0,K>0?s("{{count}} models",{count:K}):void 0].filter(Boolean).join(" · ")})]}),bn(B)&&e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:s("Classification only, not for chat")}),B.oauthAccountKey&&!B.oauthAccountPool&&e.jsx(bp,{accountKey:B.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","aria-label":s("Edit Provider"),onClick:()=>c(B),children:e.jsx(ms,{className:"h-3.5 w-3.5"})}),e.jsx(y,{variant:"ghost",size:"icon",disabled:h===B.id,className:W("h-7 w-7 text-muted-foreground opacity-0 transition-opacity hover:text-destructive group-hover:opacity-100",h===B.id&&"opacity-100"),onClick:()=>x(B),children:h===B.id?e.jsx(Ce,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Ee,{className:"h-3.5 w-3.5"})}),e.jsx(oe,{checked:B.enabled,onCheckedChange:de=>a(B.id,{enabled:de})})]})]}),b?.providerId===B.id&&e.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-md border border-destructive/30 bg-destructive/5 px-3 py-1.5 text-xs text-destructive",children:[e.jsx("span",{className:"min-w-0 truncate",children:s("Sign-out failed: {{message}}",{message:b.message})}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(y,{variant:"outline",size:"sm",className:"h-6 px-2 text-[11px]",onClick:()=>{q(B)},children:s("Retry")}),e.jsx(y,{variant:"ghost",size:"sm",className:"h-6 px-2 text-[11px] text-destructive hover:text-destructive",onClick:()=>{q(B,{skipLogout:!0})},children:s("Delete anyway")})]})]}),ce?.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"),": ",ce.message]})})]},B.id)})})]},F.vendorId)})}),e.jsx(zc,{open:i,onOpenChange:d}),e.jsx(_c,{open:u,onOpenChange:m}),e.jsx(fp,{provider:p,onClose:()=>c(null)}),e.jsx(Vr,{open:f!==null,onOpenChange:F=>{F||x(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 wp=2e3,Cr=50,Ls="",Np=[{id:"app",label:"App processes"},{id:"agent",label:"Agent and tools"},{id:"child",label:"Other child processes"}],In={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."],secretaryImages:["Secretary images","Images sent to the secretary. Cleaning removes only images no message references any more and older than 7 days; referenced images are kept."],secretaryReports:["Report screenshots","Copies of screenshots in finished reports, kept for 7 days after completion. Cleaning removes all of them; report text is kept."],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 kp(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 Cp(s,t){return s.id==="data"?t("App data"):t("Worktree directory")}function Sp(s,t){return s.role!=="window"?s.name:s.name==="Main window"?t("Main window"):s.name==="Settings"?t("Settings"):s.name}function Ip(s){return`${s.toFixed(1)}%`}function Ap(){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(Ws,{value:t,onValueChange:a=>n(a),children:[e.jsxs(Hs,{children:[e.jsx(He,{value:"cpu",children:"CPU"}),e.jsx(He,{value:"memory",children:s("RAM")}),e.jsx(He,{value:"storage",children:s("Storage")})]}),e.jsx(Bs,{value:"cpu",className:"pt-4",children:t==="cpu"&&e.jsx(Sr,{metric:"cpu"})}),e.jsx(Bs,{value:"memory",className:"pt-4",children:t==="memory"&&e.jsx(Sr,{metric:"memory"})}),e.jsx(Bs,{value:"storage",className:"pt-4",children:t==="storage"&&e.jsx(Mp,{})})]})]})}function Sr({metric:s}){const{t}=R(),[n,a]=l.useState(null),[r,o]=l.useState(null);if(l.useEffect(()=>{let m=!1,p;const c=async()=>{try{const f=await window.electronAPI.resources.sample();if(m)return;a(f),o(null)}catch(f){m||o(f instanceof Error?f.message:String(f))}m||(p=setTimeout(c,wp))};return c(),()=>{m=!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"?Ip:he,d=s==="cpu"?{app:n.cpu.app,system:n.cpu.system,total:100}:n.memory,u=m=>s==="cpu"?m.cpu:m.memory;return e.jsxs("div",{className:"space-y-4",children:[e.jsx(ti,{app:d.app,system:Math.max(d.system,d.app),total:d.total,format:i}),Np.map(m=>{const p=n.processes.filter(c=>c.group===m.id).sort((c,f)=>u(f)-u(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(m.label)}),e.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:i(p.reduce((c,f)=>c+u(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:kp(c.role,t)}),e.jsx("span",{className:"min-w-0 flex-1 truncate",title:c.command??c.name,children:Sp(c,t)}),e.jsx("span",{className:"w-16 text-right font-mono text-xs text-muted-foreground",children:c.pid}),e.jsx("span",{className:"w-20 text-right font-mono text-xs",children:i(u(c))})]},c.pid))})]},m.id)})]})}function ti({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 Ep(s,t){const n=[t("Freed {{size}}",{size:he(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 Mp(){const{t:s}=R(),[t,n]=l.useState(null),[a,r]=l.useState("scan"),[o,i]=l.useState(null),[d,u]=l.useState(null),[m,p]=l.useState(null),[c,f]=l.useState(null),x=l.useCallback(async(C,S)=>{r(C),u(null),i(null);try{n(await S())}catch(N){const A=N instanceof Error?N.message:String(N);A.includes("Scan cancelled")||u(A)}finally{r(null),i(null)}},[]),h=l.useCallback(()=>x("scan",()=>window.electronAPI.resources.scanStorage()),[x]),j=C=>x(C,async()=>{const S=await window.electronAPI.resources.cleanStorage(C);return Ie({type:S.failed>0?"warning":"success",title:s("{{name}} cleaned",{name:s(In[C][0])}),description:Ep(S,s)}),S.snapshot});l.useEffect(()=>{const C=window.electronAPI.resources.onScanProgress(i);return window.electronAPI.resources.lastStorage().then(S=>{S&&n(N=>N??S)}),h(),()=>{C(),window.electronAPI.resources.cancelScan()}},[h]);const b=t?[...t.categories].filter(C=>C.bytes>0).sort((C,S)=>S.bytes-C.bytes):[],I=l.useMemo(()=>{const C=new Map;for(const S of t?.roots??[])C.set(S.volumeId,[...C.get(S.volumeId)??[],S]);return[...C.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:he(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(is,{})})]}),d&&e.jsx("p",{className:"text-sm text-destructive",children:d}),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(Ve,{className:"h-3.5 w-3.5"}),s("{{count}} paths could not be read and are not counted.",{count:t.errorCount})]}),t&&e.jsxs(e.Fragment,{children:[I.map(C=>{const S=C[0]?.volume,N=C.reduce((A,$)=>A+$.bytes,0);return e.jsxs("div",{className:"space-y-2",children:[S?e.jsx(ti,{app:N,system:S.total-S.free,total:S.total,format:he}):e.jsx("div",{className:"rounded-lg border p-4 font-mono text-2xl font-semibold",children:he(N)}),C.map(A=>e.jsxs("div",{className:"flex items-center gap-2 px-1 text-xs",children:[e.jsx("span",{className:"shrink-0 text-muted-foreground",children:Cp(A,s)}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono",title:A.path,children:A.path}),e.jsx("span",{className:"font-mono",children:he(A.bytes)})]},A.id))]},C[0]?.volumeId)}),e.jsx("div",{className:"divide-y rounded-lg border",children:b.map(C=>e.jsx(Pp,{category:C,share:t.totalBytes>0?C.bytes/t.totalBytes:0,expanded:m===C.id,onToggle:()=>p(m===C.id?null:C.id),cleaning:a===C.id,disabled:a!==null,onClean:()=>No[C.id]==="confirm"?f(C.id):void j(C.id)},C.id))}),e.jsx(Tp,{sessions:t.sessions,busy:a==="sessions",disabled:a!==null,onClean:C=>x("sessions",async()=>{const S=await window.electronAPI.resources.cleanSessions(C);return Ie({type:"success",title:s("{{count}} conversations deleted",{count:S.removed})}),S.snapshot})})]}),e.jsx(Ct,{open:c!==null,onOpenChange:C=>!C&&f(null),children:e.jsxs(St,{className:"sm:max-w-md",zIndexLevel:"nested",children:[e.jsxs(It,{children:[e.jsx(At,{className:"text-base",children:s("Clean {{name}}?",{name:c?s(In[c][0]):""})}),e.jsx(Et,{children:s(c==="browser"?"You will be signed out of sites opened in the built-in browser.":"Deleted files cannot be restored.")})]}),e.jsxs(Mt,{variant:"bare",children:[e.jsx(Pt,{render:e.jsx(y,{variant:"outline",size:"sm"}),children:s("Cancel")}),e.jsx(y,{variant:"destructive",size:"sm",onClick:()=>{const C=c;f(null),C&&j(C)},children:s("Clean")})]})]})})]})}function Pp({category:s,share:t,expanded:n,onToggle:a,cleaning:r,disabled:o,onClean:i}){const{t:d}=R(),[u,m]=In[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(Gs,{className:W("h-4 w-4 shrink-0 transition-transform",n&&"rotate-90")}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-2 text-sm",children:[e.jsx("span",{className:"font-medium",children:d(u)}),e.jsxs("span",{className:"font-mono text-xs",children:[s.id==="secretaryImages"&&e.jsx("span",{className:"mr-2 text-muted-foreground",children:d("{{count}} files",{count:s.files})}),he(s.bytes)]})]}),e.jsx("p",{className:W("text-xs text-muted-foreground",s.id!=="secretaryImages"&&s.id!=="secretaryReports"&&"truncate"),children:d(m)}),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}%`}})})]})]}),No[s.id]!=="none"&&e.jsx(y,{variant:"outline",size:"sm",disabled:o,onClick:i,children:d(r?"Cleaning...":"Clean")})]}),n&&e.jsx("div",{className:"mt-2 space-y-0.5 pl-6",children: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:`${d("Worktree directory")}/${p.path}`}),e.jsx("span",{className:"font-mono",children:he(p.bytes)}),e.jsx(y,{variant:"ghost",size:"icon-sm",className:"opacity-0 group-hover:opacity-100","aria-label":d("Show in folder"),onClick:()=>{window.electronAPI.resources.revealStorage(p.root,p.path)},children:e.jsx(Dn,{})})]},`${p.root}:${p.path}`))})]})}function Tp({sessions:s,busy:t,disabled:n,onClean:a}){const{t:r}=R(),[o,i]=l.useState(!1),[d,u]=l.useState(!1),[m,p]=l.useState(null),[c,f]=l.useState(Ls),x=l.useMemo(()=>new Map(s.map(M=>[M.id,M])),[s]),h=l.useMemo(()=>{const M=new Map;for(const k of s){const T=M.get(k.projectId)??{name:k.projectName,bytes:0,count:0};T.bytes+=k.bytes,T.count+=1,M.set(k.projectId,T)}return[...M].sort((k,T)=>T[1].bytes-k[1].bytes)},[s]),j=h.some(([M])=>M===c)?c:Ls,b=j?s.filter(M=>M.projectId===j):s,I=M=>{const k=Yc(s,M,Date.now());return{request:M,count:k.length,bytes:k.reduce((T,_)=>T+(x.get(_)?.bytes??0),0)}},C=M=>I({kind:"stale",days:M,includeUnarchived:o,...j?{projectId:j}:{}}),S=b.reduce((M,k)=>M+k.bytes,0),N=d?b:b.slice(0,Cr),A=(M,k)=>k||(M?M.slice(0,8):r("No project")),$=m?.request.kind==="one"?x.get(m.request.id):void 0,E=m?.request.kind==="stale"?m.request.projectId:void 0,L=E===void 0?void 0:A(E,h.find(([M])=>M===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," · ",he(S)]})]}),e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsxs(Z,{items:{[Ls]:r("All projects"),...Object.fromEntries(h.map(([M,k])=>[M,A(M,k.name)]))},value:j,onValueChange:M=>f(M??Ls),children:[e.jsx(ee,{size:"sm",className:"w-48 min-w-0",children:e.jsx(se,{})}),e.jsxs(te,{children:[e.jsx(J,{value:Ls,children:r("All projects")}),h.map(([M,k])=>e.jsx(J,{value:M,children:e.jsxs("span",{className:"flex w-full items-center gap-3",children:[e.jsx("span",{className:"flex-1 truncate",children:A(M,k.name)}),e.jsxs("span",{className:"font-mono text-xs text-muted-foreground",children:[k.count," · ",he(k.bytes)]})]})},M))]})]}),e.jsxs(ko,{children:[e.jsxs(Co,{render:e.jsx(y,{variant:"outline",size:"sm",disabled:n||b.length===0}),children:[e.jsx(Gc,{}),r(t?"Cleaning...":"Clean")]}),e.jsxs(So,{align:"end",className:"min-w-48",children:[e.jsx(Wc,{checked:o,onCheckedChange:i,closeOnClick:!1,children:r("Include unarchived")}),e.jsx(Hc,{}),[...qc,0].map(M=>{const k=C(M);return e.jsxs(Io,{variant:"destructive",disabled:k.count===0,onClick:()=>p(k),children:[e.jsx("span",{className:"flex-1",children:M>0?r("Older than {{days}} days",{days:M}):r("All")}),e.jsx("span",{className:"font-mono text-xs opacity-70",children:k.count})]},M)})]})]})]})]}),e.jsx("div",{className:"max-h-96 divide-y overflow-y-auto",children:N.map(M=>e.jsxs("div",{className:"group flex items-center gap-3 px-3 py-1.5 text-sm",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate",title:M.title,children:M.title||r("Untitled")}),e.jsx("div",{className:"truncate text-xs text-muted-foreground",children:[M.projectName,M.archived?r("Archived"):null,new Date(M.lastActiveAt).toLocaleDateString()].filter(Boolean).join(" · ")})]}),e.jsx("span",{className:"font-mono text-xs",children:he(M.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:M.id},count:1,bytes:M.bytes}),children:e.jsx(Ee,{})})]},M.id))}),b.length>Cr&&e.jsx("button",{type:"button",onClick:()=>u(!d),className:"w-full border-t px-3 py-1.5 text-xs text-muted-foreground hover:text-foreground",children:r(d?"Show less":"Show all")}),e.jsx(Ct,{open:m!==null,onOpenChange:M=>!M&&p(null),children:e.jsxs(St,{className:"sm:max-w-md",zIndexLevel:"nested",children:[e.jsxs(It,{children:[e.jsx(At,{className:"text-base",children:$?r('Delete "{{title}}"?',{title:$.title||r("Untitled")}):L!==void 0?r("Delete {{count}} conversations in {{project}}?",{count:m?.count??0,project:L}):r("Delete {{count}} conversations?",{count:m?.count??0})}),e.jsxs(Et,{children:[r("About {{size}} of history, tool output and isolated worktrees will be removed and cannot be restored.",{size:he(m?.bytes??0)}),!$&&` ${r("Open, running and waiting conversations are skipped.")}`]})]}),e.jsxs(Mt,{variant:"bare",children:[e.jsx(Pt,{render:e.jsx(y,{variant:"outline",size:"sm"}),children:r("Cancel")}),e.jsx(y,{variant:"destructive",size:"sm",onClick:()=>{const M=m?.request;p(null),M&&a(M)},children:r("Delete")})]})]})})]})}const ni={cropSource:null,busy:!1,problem:null};function Rp(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 ni;case"save-failed":return{cropSource:null,busy:!1,problem:"save"}}}const Op={ui:"Follow the interface language",zh:"Chinese",en:"English"},Dp={concise:"Concise",detailed:"Detailed"},Lp={"needs-user":"Only what needs you","with-done":"Include finished work",off:"Off"};function dt({title:s,items:t}){return t.length===0?null:e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("p",{className:"text-xs font-medium",children:s}),e.jsx("ul",{className:"max-h-24 overflow-y-auto text-xs text-muted-foreground",children:t.map(n=>e.jsxs("li",{className:"truncate",children:["· ",n]},n))})]})}function zp({open:s,secretaryId:t,onOpenChange:n,onDeleted:a}){const{t:r}=R(),[o,i]=l.useState(null),[d,u]=l.useState("preview"),[m,p]=l.useState(!1),[c,f]=l.useState(null);l.useEffect(()=>{s&&(u("preview"),f(null),i(null),window.electronAPI.secretary.deletePreview(t).then(j=>{j.ok?i(j.preview):f(j.error)}))},[s,t]);const x=async()=>{p(!0),f(null);try{const j=await window.electronAPI.secretary.deleteSecretary(t,!0);if(!j.ok){f(j.error);return}n(!1),a?.()}finally{p(!1)}},h=o!==null&&o.sessions.length+o.todos.length+o.schedules.length+o.contacts.length+o.memories===0;return e.jsx(Ct,{open:s,onOpenChange:n,children:e.jsxs(St,{className:"sm:max-w-md","data-enso":"secretary-delete-dialog",children:[e.jsxs(It,{children:[e.jsx(At,{className:"text-base",children:d==="preview"?`${r("Delete secretary")} · ${o?.name??r("Secretary")}`:r("Delete this secretary?")}),e.jsx(Et,{children:r("This cannot be undone. The sessions it manages stay, but nobody manages them afterwards; its contact bindings are released and its private memory is deleted.")})]}),d==="preview"&&o&&e.jsxs("div",{className:"space-y-2 px-1","data-enso":"secretary-delete-preview",children:[h?e.jsx("p",{className:"text-xs text-muted-foreground",children:r("Nothing is managed by this secretary.")}):null,e.jsx(dt,{title:r("Sessions it manages ({{n}})",{n:o.sessions.length}),items:o.sessions.map(j=>[j.projectName,j.title].filter(Boolean).join(" · "))}),e.jsx(dt,{title:r("Open todos ({{n}})",{n:o.todos.length}),items:o.todos.map(j=>j.text)}),e.jsx(dt,{title:r("Schedules ({{n}})",{n:o.schedules.length}),items:o.schedules.map(j=>j.name)}),e.jsx(dt,{title:r("Contact bindings ({{n}})",{n:o.contacts.length}),items:o.contacts}),o.memories>0&&e.jsx("p",{className:"text-xs font-medium",children:r("Private memories: {{n}}",{n:o.memories})})]}),c?e.jsx("p",{className:"px-1 text-xs text-destructive",children:c}):null,e.jsxs(Mt,{variant:"bare",children:[e.jsx(Pt,{render:e.jsx(y,{variant:"outline",size:"sm"}),children:r("Cancel")}),d==="preview"?e.jsx(y,{variant:"destructive",size:"sm","data-enso":"secretary-delete-next",disabled:!o,onClick:()=>u("confirm"),children:r("Next: confirm again")}):e.jsx(y,{variant:"destructive",size:"sm","data-enso":"secretary-delete-confirm",disabled:m,onClick:()=>{x()},children:r("Delete permanently")})]})]})})}const _p=Array.from({length:Jc-Ca+1},(s,t)=>{const n=String(Ca+t);return{value:n,label:n}}),Fp={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 Fs({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:W("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 Xe({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 ai(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 Bp({pluginIds:s,busy:t,onChange:n}){const{t:a}=R(),[r,o]=l.useState([]);l.useEffect(()=>{window.electronAPI.extensionPlugins.list().then(d=>o(d)).catch(()=>{})},[]);const i=r.filter(d=>d.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(d=>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":d.id,children:[e.jsx(Re,{checked:s.includes(d.id),disabled:t,onCheckedChange:u=>n(u===!0?[...s,d.id]:s.filter(m=>m!==d.id))}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:d.name}),e.jsx("span",{className:"shrink-0 text-xs text-muted-foreground",children:a("{{n}} tools",{n:d.tools.length})}),d.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]},d.id))})}const Ps=l.createContext(void 0);function Up({busy:s}){const{t}=R(),n=l.useContext(Ps),[a,r]=l.useState([]),[o,i]=l.useState(null),d=l.useCallback(async()=>{const m=await window.electronAPI.secretary.listSkills(n);m.ok?r(m.skills.filter(p=>p.source==="own")):i(m.error)},[n]);l.useEffect(()=>{d()},[d]);const u=async m=>{i(null);const p=await window.electronAPI.secretary.removeSkill(m,n);if(!p.ok){i(p.error);return}await d()};return o?e.jsx("p",{className:"text-xs text-destructive",children:o}):a.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:a.map(m=>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:m.name}),!m.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(m.name)},children:t("Remove")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:m.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:m.body??""})]})]},m.name))})}function $p({busy:s}){const{t}=R(),n=l.useContext(Ps),[a,r]=l.useState([]),[o,i]=l.useState(null),d=l.useCallback(async()=>{const m=await window.electronAPI.secretary.listTools(n);m.ok?r(m.tools):i(m.error)},[n]);l.useEffect(()=>{d()},[d]);const u=async m=>{i(null);const p=await window.electronAPI.secretary.removeTool(m,n);if(!p.ok){i(p.error);return}await d()};return o?e.jsx("p",{className:"text-xs text-destructive",children:o}):a.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:a.map(m=>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:m.name}),e.jsx("span",{className:"shrink-0 rounded bg-muted px-1.5 text-[10px] text-muted-foreground",children:m.runtime==="python"?"Python":"Node"}),e.jsx("span",{className:"shrink-0 rounded bg-muted px-1.5 text-[10px] text-muted-foreground",children:m.readOnly?t("Read-only"):t("Asks every call")}),e.jsx(y,{variant:"ghost",size:"sm",disabled:s,onClick:()=>{u(m.name)},children:t("Remove")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:m.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:m.code})]})]},m.name))})}function Vp({profile:s,busy:t,onChange:n}){const{t:a}=R(),r=g(m=>m.projects),o=s.takeoverScope,i=s.visibleProjectIds,d=r.filter(m=>m.kind!=="secretary"&&m.kind!=="scratch"&&(i==="all"||i.includes(m.id))),u=o.mode==="projects"?o.projectIds:[];return e.jsxs("div",{className:"space-y-2",children:[e.jsx(Fs,{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:m=>n(m==="all"?{mode:"all"}:m==="explicit"?{mode:"explicit"}:{mode:"projects",projectIds:u})}),o.mode==="projects"?d.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:d.map(m=>{const p=u.includes(m.id);return e.jsx("button",{type:"button","aria-pressed":p,disabled:t,onClick:()=>n({mode:"projects",projectIds:p?u.filter(c=>c!==m.id):[...u,m.id]}),className:W("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:m.alias||m.name},m.id)})}):null]})}function Kp({locale:s}){const{t}=R(),n=l.useContext(Ps),[a,r]=l.useState([]),[o,i]=l.useState(null),d=l.useCallback(async()=>{const m=await window.electronAPI.secretary.listTakeovers(n);m.ok?r(m.takeovers):i(m.error)},[n]);l.useEffect(()=>(d(),window.electronAPI.secretary.onStateChanged(()=>{d()})),[d]);const u=async m=>{i(null);const p=await window.electronAPI.secretary.revokeTakeover(m);p.ok||i(p.error),await d()};return e.jsxs(e.Fragment,{children:[o?e.jsx("p",{className:"text-xs text-destructive",children:o}):null,a.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:a.map(m=>e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2","data-enso":"secretary-takeover-row","data-conversation-id":m.conversationId,children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-sm",children:m.title||t("Unnamed")}),e.jsx("p",{className:"truncate text-xs text-muted-foreground",children:[m.projectName,ai(m.grantedAt,s)].filter(Boolean).join(" · ")})]}),e.jsx(y,{variant:"ghost",size:"sm",onClick:()=>{u(m.conversationId)},children:t("Take back")})]},m.conversationId))})]})}function Gp(){const{t:s}=R(),t=l.useContext(Ps),[n,a]=l.useState([]),[r,o]=l.useState(null),i=l.useCallback(async()=>{const u=await window.electronAPI.secretary.listUntracked(t);u.ok?a(u.untracked):o(u.error)},[t]);l.useEffect(()=>(i(),window.electronAPI.secretary.onStateChanged(()=>{i()})),[i]);const d=async u=>{o(null);const m=await window.electronAPI.secretary.removeUntracked(u,t);m.ok||o(m.error),await i()};return n.length===0&&!r?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.")}),r?e.jsx("p",{className:"text-xs text-destructive",children:r}):null,e.jsx("div",{className:"divide-y rounded-md border",children:n.map(u=>e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2","data-enso":"secretary-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:()=>{d(u.conversationId)},children:s("Track again")})]},u.conversationId))})]})}function Wp({skillIds:s,onChange:t}){const{t:n}=R(),a=g(r=>r.skills);return e.jsx(ld,{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 Hp(){const{t:s}=R(),[t,n]=l.useState([]),[a,r]=l.useState(()=>{try{return localStorage.getItem(Sa)??void 0}catch{return}}),[o,i]=l.useState(!1),d=l.useCallback(async()=>{const c=await window.electronAPI.secretary.list();n(c)},[]);l.useEffect(()=>(d(),window.electronAPI.secretary.onListChanged(n)),[d]),l.useEffect(()=>{const c=f=>{f.key===Sa&&f.newValue&&r(f.newValue)};return window.addEventListener("storage",c),()=>window.removeEventListener("storage",c)},[]);const u=t.find(c=>c.id===a)?.id??t[0]?.id??void 0,m=t.length>1,p=async()=>{const c=await window.electronAPI.secretary.create();c.ok&&(await d(),r(c.secretaryId))};return e.jsx(Ps.Provider,{value:m?u:void 0,children:e.jsxs("div",{className:"space-y-4",children:[t.length>0&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5","data-enso":"secretary-settings-picker",children:[m&&t.map(c=>e.jsx("button",{type:"button","data-enso":"secretary-settings-pick","data-secretary-id":c.id,"data-selected":c.id===u||void 0,onClick:()=>r(c.id),className:W("rounded-full border px-2.5 py-1 text-xs transition-colors",c.id===u?"border-foreground/40 bg-foreground/5 text-foreground":"border-border text-muted-foreground hover:text-foreground"),children:c.name??s("Secretary")},c.id)),e.jsx(y,{variant:"outline",size:"sm","data-enso":"secretary-settings-create",onClick:()=>{p()},children:s("New secretary")}),u&&e.jsx(y,{variant:"ghost",size:"sm","data-enso":"secretary-settings-delete",onClick:()=>i(!0),children:s("Delete secretary")})]}),e.jsx(qp,{},u??"single"),u&&e.jsx(zp,{open:o,secretaryId:u,onOpenChange:i,onDeleted:()=>{r(void 0),d()}})]})})}function qp(){const{t:s,locale:t}=R(),n=l.useContext(Ps),[a,r]=l.useState(null),[o,i]=l.useState(""),[d,u]=l.useState(null),[m,p]=l.useState([]),[c,f]=l.useState(!1),[x,h]=l.useState(null),[j,b]=l.useState(null),[I,C]=l.useState(!1),[S,N]=l.useReducer(Rp,ni),A=l.useRef(null),$=s("Secretary"),E=l.useCallback(async()=>{const _=await window.electronAPI.secretary.listSchedules(n);_.ok&&p(_.schedules)},[n]),L=l.useCallback(async()=>{const _=await window.electronAPI.secretary.getProfile(n);if(!_.ok){h(_.error);return}r(_.profile),i(_.persona),u(_.profile?it(_.profile,$):null),await E()},[$,E,n]);l.useEffect(()=>{L()},[L]);const M=async _=>{f(!0),h(null),b(null);try{const q=await window.electronAPI.secretary.saveProfile(_,n);if(!q.ok){h(q.error);return}r(q.profile),u(it(q.profile,$)),b(s("Saved")),await E()}catch{h(s("Could not save the secretary profile. Try again."))}finally{f(!1)}},k=async _=>{N({type:"saving"}),h(null);try{const q=await window.electronAPI.secretary.setAvatar(_,n);if(!q.ok){N({type:"save-failed"}),h(q.error);return}r(q.profile),u(it(q.profile,$)),N({type:"saved"})}catch{N({type:"save-failed"}),h(s("Could not save the secretary profile. Try again."))}},T=async _=>{h(null);const q=await window.electronAPI.secretary.removeSchedule(_,n);if(!q.ok){h(q.error);return}await E()};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.")})]}),x?e.jsx("p",{className:"text-xs text-destructive",children:x}):null,S.problem?e.jsx("p",{className:"text-xs text-destructive","data-enso":"secretary-avatar-problem",children:s(Fp[S.problem])}):null,j?e.jsx("p",{className:"text-xs text-muted-foreground",children:j}):null,e.jsxs(Xe,{title:"Secretary profile",description:"Name, avatar, visible projects and patrol.",rowId:"secretary.profile",children:[a?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{ref:A,type:"file",accept:"image/png,image/jpeg,image/webp,image/gif","data-enso":"secretary-avatar-file",className:"hidden",onChange:_=>{const q=_.target.files?.[0];if(_.target.value="",!q)return;const w=Xc(q,Ia);if(N({type:"pick",problem:w}),w)return;const z=()=>id(q).then(F=>N({type:"picked",source:F}));(Qc(q)?q.arrayBuffer().then(F=>{const G=new Uint8Array(F);if(Zc(G)!=="gif")return z();k(G)}):z()).catch(()=>N({type:"read-failed"}))}}),e.jsx(ed,{name:a.name,color:a.avatar.color,image:a.avatar.imageVersion?sd(a.avatar.imageVersion,a.avatar.imageHash,n):void 0,needsYou:0,running:0,enso:"secretary-settings-avatar"}),e.jsx(y,{variant:"outline",size:"sm",disabled:S.busy,onClick:()=>A.current?.click(),"data-enso":"secretary-avatar-upload",children:s("Upload image")}),a.avatar.imageVersion?e.jsx(y,{variant:"ghost",size:"sm",disabled:S.busy,onClick:()=>{k(null)},"data-enso":"secretary-avatar-remove",children:s("Remove image")}):null,e.jsx(td,{source:S.cropSource,onCancel:()=>N({type:"crop-cancelled"}),onDone:_=>{const q=nd(_),w=q.byteLength>Ia;N({type:"cropped",tooLarge:w}),!w&&k(q)}})]}):e.jsx("p",{className:"text-xs text-muted-foreground",children:s("The secretary has not been set up yet.")}),e.jsx(ad,{initialDraft:a?it(a,$):rd($),submitLabel:s("Save"),busy:c,hideMaxRunning:!0,onSubmit:({maxRunningDispatches:_,...q})=>{M(q)}},a?.updatedAt??"new")]}),e.jsx(Xe,{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:a?e.jsx(Fs,{enso:"secretary-dispatch-limit",value:String(a.maxRunningDispatches),options:_p,onChange:_=>{const q=Number(_);c||q===a.maxRunningDispatches||M({maxRunningDispatches:q})}}):e.jsx("p",{className:"text-xs text-muted-foreground",children:s("The secretary has not been set up yet.")})}),e.jsx(Xe,{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:a?e.jsx(Bp,{pluginIds:a.pluginIds??[],busy:c,onChange:_=>{M({pluginIds:_})}}):e.jsx("p",{className:"text-xs text-muted-foreground",children:s("The secretary has not been set up yet.")})}),e.jsx(Xe,{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:a?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(Up,{busy:c})]}),e.jsx(Wp,{skillIds:a.skillIds??[],onChange:_=>{M({skillIds:_})}})]}):e.jsx("p",{className:"text-xs text-muted-foreground",children:s("The secretary has not been set up yet.")})}),e.jsx(Xe,{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:a?e.jsx($p,{busy:c}):e.jsx("p",{className:"text-xs text-muted-foreground",children:s("The secretary has not been set up yet.")})}),d?e.jsx(Xe,{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(X,{value:d.addressAs??"",placeholder:s("Optional"),onChange:_=>u({...d,addressAs:_.target.value.trim()?_.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(Fs,{value:d.replyLanguage??"ui",options:["ui","zh","en"].map(_=>({value:_,label:Op[_]})),onChange:_=>u({...d,replyLanguage:_})})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-sm",children:s("Communication style")}),e.jsx(Fs,{value:d.style??"concise",options:["concise","detailed"].map(_=>({value:_,label:Dp[_]})),onChange:_=>u({...d,style:_})})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-sm",children:s("System notifications")}),e.jsx(Fs,{value:d.notify??"needs-user",options:["needs-user","with-done","off"].map(_=>({value:_,label:Lp[_]})),onChange:_=>u({...d,notify:_})})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-sm",children:s("Daily brief time")}),e.jsx(X,{type:"time",value:d.dailyBriefAt??"",onChange:_=>u({...d,dailyBriefAt:_.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(Qe,{value:o,onChange:_=>i(_.target.value),rows:4})]}),e.jsx(y,{size:"sm",disabled:c,onClick:()=>{M({addressAs:d.addressAs??null,replyLanguage:d.replyLanguage,style:d.style,notify:d.notify,dailyBriefAt:d.dailyBriefAt??null,persona:o})},children:s("Save")})]})}):null,e.jsx(Xe,{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:a?e.jsx(Vp,{profile:a,busy:c,onChange:_=>{M({takeoverScope:_})}}):e.jsx("p",{className:"text-xs text-muted-foreground",children:s("The secretary has not been set up yet.")})}),e.jsxs(Xe,{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(Kp,{locale:t}),e.jsx(Gp,{})]}),e.jsx(Xe,{title:"Scheduled tasks",rowId:"secretary.schedules",children:m.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:m.map(_=>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:_.name}),e.jsxs("p",{className:"truncate text-xs text-muted-foreground",children:[_.cron??_.at??"",_.nextRunAt?` · ${ai(_.nextRunAt,t)}`:""]})]}),_.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:()=>{T(_.id)},children:s("Remove")})]},_.id))})}),e.jsxs(Xe,{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:()=>C(!0),children:s("Re-run setup")}),e.jsx(od,{open:I,secretaryId:n,onOpenChange:C,onReset:()=>{r(null),u(null),i(""),b(null),E()}})]})]})}function Yp(){const{t:s}=R(),t=g(N=>N.skills),n=g(N=>N.updateSkill),a=g(N=>N.setSkillsEnabled),r=g(N=>N.removeSkill),o=g(N=>N.loadLocalSkills),i=g(N=>N.setLoadLocalSkills),d=g(N=>N.loadHarnessAssets),u=g(N=>N.setLoadHarnessAssets),[m,p]=l.useState(!1),[c,f]=l.useState(""),x=t.filter(N=>io(c,[N.name,N.source,N.description,N.path])),h=x.map(N=>N.id),j=lo(h),b=t.filter(N=>N.enabled).length,I=t.map(N=>N.id),C=zt(I,N=>window.electronAPI.assets.skillOccupancy(N)),S=Ot(t.filter(N=>N.enabled).map(N=>N.id),C.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(oe,{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(oe,{checked:d,onCheckedChange:u})]}),e.jsxs("div",{className:"flex items-end justify-between gap-4","data-settings-row":"skills.root",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"font-medium text-lg",children:[s("Skills"),e.jsx(ss,{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(Lt,{tokens:S})]})]}),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(Rt,{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(Ao,{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(mo,{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:x.length===0,actionDisabled:j.selectedIds.length===0}),x.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:x.map(N=>e.jsxs("div",{className:"group flex items-center justify-between gap-3 rounded-md px-3 py-2 transition-colors hover:bg-accent/50","data-settings-row":`skills.${N.id}`,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(Re,{checked:j.isSelected(N.id),onCheckedChange:A=>j.toggleOne(N.id,A)}),e.jsx("span",{className:W("shrink-0 font-medium text-sm",!N.enabled&&"text-muted-foreground line-through"),children:N.name}),e.jsx(ne,{variant:"secondary",className:"shrink-0 text-[11px]",children:N.source}),e.jsx("span",{className:"min-w-0 truncate text-muted-foreground text-xs",children:N.description||N.path})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(Dt,{row:C.rows[N.id],pending:C.pending&&!C.rows[N.id]}),e.jsx(oe,{checked:N.enabled,onCheckedChange:A=>n(N.id,{enabled:A})}),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(N.id),children:e.jsx(Ee,{className:"h-3.5 w-3.5"})})]})]},N.id))})]}),e.jsx(Bn,{kind:"skill",open:m,onOpenChange:p})]})}const Ir=[10,15,30,60,120,300];function Jp(){const{t:s}=R(),[t,n]=l.useState([]),[a,r]=l.useState(!1),[o,i]=l.useState(null),[d,u]=l.useState(""),[m,p]=l.useState(""),[c,f]=l.useState(""),[x,h]=l.useState(""),[j,b]=l.useState("key"),[I,C]=l.useState(""),[S,N]=l.useState(!1),[A,$]=l.useState(null),[E,L]=l.useState(null),[M,k]=l.useState(null),[T,_]=l.useState(null),[q,w]=l.useState(!1),z=l.useCallback(()=>{window.electronAPI.sshConnections.list().then(n)},[]);l.useEffect(()=>{z()},[z]);const H=()=>{i(null),u(""),p(""),f(""),h(""),b("key"),C(""),L(null),r(!0)},F=K=>{i(K),u(K.name),p(K.host),f(K.user??""),h(K.port?String(K.port):""),b(K.auth),C(""),L(null),r(!0)},G=async K=>{K.preventDefault(),N(!0),L(null);const ie=x.trim()?Number(x):void 0,U=await window.electronAPI.sshConnections.upsert({...o?{id:o.id}:{},name:d.trim(),host:m.trim(),...c.trim()?{user:c.trim()}:{},...ie&&Number.isInteger(ie)?{port:ie}:{},auth:j,...j==="password"&&I?{password:I}:{}});if(N(!1),!U.ok){L(U.error);return}r(!1),z()},le=async K=>{const ie=await window.electronAPI.sshConnections.delete(K);if(!ie.ok){k(ie.error);return}k(null),z()},B=async(K,ie=!0)=>{$(K),k(null);const U=await window.electronAPI.sshConnections.test(K);if($(null),!U.ok){const ce=t.find(D=>D.id===K),de=dd(U,ce);if(de&&ie){_({id:K,challenge:de});return}}k(U.ok?s("SSH connection succeeded"):U.error)},ae=async()=>{if(!T)return;w(!0);const K=T.id,ie=await window.electronAPI.sshConnections.trustHost(K);if(w(!1),_(null),!ie.ok){k(ie.error||s("Could not save host key."));return}await B(K,!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(ss,{note:s("The file panel and terminal use the change right away. Agents in open sessions keep the previous connection settings.")})]}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:s("Saved hosts for remote projects. Passwords stay in the system keychain.")})]}),e.jsxs(y,{size:"sm",onClick:H,children:[e.jsx(Ae,{className:"h-4 w-4"}),s("Add connection")]})]}),M&&e.jsx("p",{className:"text-sm text-muted-foreground",children:M}),e.jsxs("ul",{className:"divide-y rounded-lg border",children:[t.length===0&&e.jsx("li",{className:"px-3 py-6 text-sm text-muted-foreground",children:s("No SSH connections yet")}),t.map(K=>e.jsxs("li",{className:"flex items-center gap-2 px-3 py-2","data-settings-row":`ssh.${K.id}`,children:[e.jsxs("button",{type:"button",className:"min-w-0 flex-1 text-left",onClick:()=>F(K),children:[e.jsx("div",{className:"truncate text-sm font-medium",children:K.name}),e.jsxs("div",{className:"truncate text-xs text-muted-foreground",children:[K.user?`${K.user}@`:"",K.host,K.port?`:${K.port}`:""," ·"," ",K.auth==="password"?s("Password"):s("Key / agent")]})]}),e.jsx(y,{size:"sm",variant:"outline",disabled:A===K.id,onClick:()=>{B(K.id)},children:A===K.id?e.jsx(Ce,{className:"h-4 w-4 animate-spin"}):s("Test")}),e.jsx(y,{size:"icon-sm",variant:"ghost",onClick:()=>{le(K.id)},children:e.jsx(Ee,{className:"h-4 w-4"})})]},K.id))]}),e.jsx(Xp,{}),e.jsx(pe,{open:a,onOpenChange:r,children:e.jsx(fe,{className:"max-w-md",children:e.jsxs("form",{onSubmit:K=>{G(K)},className:"flex flex-col",children:[e.jsx(ge,{children:e.jsx(je,{children:s(o?"Edit SSH connection":"Add SSH connection")})}),e.jsxs(ve,{className:"space-y-3",children:[e.jsxs(me,{children:[e.jsx(ue,{children:s("Name")}),e.jsx(X,{value:d,onChange:K=>u(K.target.value),required:!0})]}),e.jsxs(me,{children:[e.jsx(ue,{children:s("Host")}),e.jsx(X,{value:m,onChange:K=>p(K.target.value),placeholder:"example.com",required:!0})]}),e.jsxs(me,{children:[e.jsx(ue,{children:s("User (optional)")}),e.jsx(X,{value:c,onChange:K=>f(K.target.value)})]}),e.jsxs(me,{children:[e.jsx(ue,{children:s("Port (optional)")}),e.jsx(X,{value:x,onChange:K=>h(K.target.value),placeholder:"22"})]}),e.jsxs(me,{children:[e.jsx(ue,{children:s("Authentication")}),e.jsxs(Z,{items:[{value:"key",label:s("Key / agent")},{value:"password",label:s("Password")}],value:j,onValueChange:K=>b(K),children:[e.jsx(ee,{className:"w-full",children:e.jsx(se,{})}),e.jsxs(te,{zIndex:os.DROPDOWN_IN_MODAL,children:[e.jsx(J,{value:"key",children:s("Key / agent")}),e.jsx(J,{value:"password",children:s("Password")})]})]})]}),j==="password"&&e.jsxs(me,{children:[e.jsx(ue,{children:o?.hasPassword?s("Password (leave blank to keep)"):s("Password")}),e.jsx(X,{type:"password",value:I,onChange:K=>C(K.target.value),required:!o?.hasPassword})]}),E&&e.jsx("p",{className:"text-sm text-destructive",children:E})]}),e.jsxs(ke,{children:[e.jsx(y,{type:"button",variant:"outline",size:"sm",onClick:()=>r(!1),children:s("Cancel")}),e.jsx(y,{type:"submit",size:"sm",disabled:S,children:s("Save")})]})]})})}),e.jsx(cd,{challenge:T?.challenge??null,busy:q,onTrust:()=>{ae()},onDismiss:()=>!q&&_(null)})]})}function Xp(){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(Z,{items:Object.fromEntries(Ir.map(a=>[String(a),`${a}s`])),value:String(t),onValueChange:a=>n(Number(a)),children:[e.jsx(ee,{className:"w-24",children:e.jsx(se,{})}),e.jsx(te,{children:Ir.map(a=>e.jsx(J,{value:String(a),children:`${a}s`},a))})]})]})}const Qp={memory:"memory",workflows:"workflow"},ri=["bots","botTemplates"],oi=["secretary"],Zp=[{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 ef(s){const t=new Map(s.map(n=>[n.id,n]));return Zp.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 ii(s,t,n=!1,a=!1){if(oi.includes(s))return a;if(ri.includes(s))return n;if(s==="memory"&&a)return!0;const r=Qp[s];return!r||!t.includes(r)}function sf(s,t,n=!1,a=!1){return s.filter(r=>ii(r.id,t,n,a))}function tf(s,t,n=!1,a=!1){return ii(s,t,n,a)?s:ri.includes(s)||oi.includes(s)?"experimental":"tools"}function nf(s,t,n,a){const r=n.trim();if(!r)return s.map(u=>({...u,hits:[]}));const o=md([...t,...s.map(u=>({id:`${u.id}.root`,category:u.id,title:u.label}))],r,{translate:a,limit:Number.POSITIVE_INFINITY}),i=new Set,d=new Map;for(const u of o){if(i.add(u.category),u.id.endsWith(".root"))continue;const m=d.get(u.category);m?m.push(u):d.set(u.category,[u])}return s.flatMap(u=>i.has(u.id)?[{...u,hits:d.get(u.id)??[]}]:[])}const af=[1,7,30,90],Ar=640,mt=180,Er=8,Mr=18,rf=.3,of=2;function lf(s){const[,t,n]=s.split("-");return`${Number(t)}/${Number(n)}`}const cf=[{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 df({daily:s}){const{t}=R(),[n,a]=l.useState("tokens"),[r,o]=l.useState(null),[i,d]=l.useState({output:!0,input:!0,cache:!0}),u=C=>{d(S=>{const N={...S,[C]:!S[C]};return!N.output&&!N.input&&!N.cache?S:N})},m=s.map(C=>n==="cost"?C.cost??0:(i.output?C.output:0)+(i.input?C.input:0)+(i.cache?C.cache:0)),p=Math.max(0,...m),c=Math.max(1,s.length),f=Ar/c,x=Math.min(f*(1-rf),64),h=mt-Er-Mr,j=C=>p>0?C/p*h:0,b=Math.max(1,Math.ceil(c/12)),I=r!==null?s[r]:null;return e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-sm font-medium",children:t("Daily trend")}),e.jsxs("div",{className:"flex items-center gap-3",children:[n==="tokens"&&e.jsxs("div",{className:"flex items-center gap-3 text-[11px] text-muted-foreground",children:[e.jsx(cn,{className:"bg-foreground",label:t("Output"),pressed:i.output,onClick:()=>u("output")}),e.jsx(cn,{className:"bg-foreground/45",label:t("Input"),pressed:i.input,onClick:()=>u("input")}),e.jsx(cn,{className:"bg-foreground/15",label:t("Cache"),pressed:i.cache,onClick:()=>u("cache")})]}),e.jsx(mf,{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"?Ke(p):yt(p>0?p:null)}),I&&e.jsxs("div",{className:"pointer-events-none absolute right-0 top-0 rounded bg-popover px-2 py-1 font-mono text-[11px] text-popover-foreground shadow-sm ring-1 ring-border",children:[I.day,n==="tokens"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[t("Output")," ",Ke(I.output)]}),e.jsxs("div",{children:[t("Input")," ",Ke(I.input)]}),e.jsxs("div",{children:[t("Cache")," ",Ke(I.cache)]})]}):e.jsxs(e.Fragment,{children:[" · ",yt(I.cost)]})]}),e.jsx("svg",{viewBox:`0 0 ${Ar} ${mt}`,className:"mt-4 block h-[180px] w-full",role:"img","aria-label":t("Daily trend"),onMouseLeave:()=>o(null),children:s.map((C,S)=>{const N=S*f+(f-x)/2,A=mt-Mr,$=n==="tokens"?cf.filter(L=>i[L.id]).map(L=>({v:C[L.id],cls:L.cls})):[{v:C.cost??0,cls:"fill-emerald-600 dark:fill-emerald-500"}];let E=A;return e.jsxs("g",{onMouseEnter:()=>o(S),children:[e.jsx("rect",{x:N,y:Er,width:x,height:h,className:"fill-transparent"}),$.map(L=>{const M=L.v>0?Math.max(of,j(L.v)):0;return E-=M,e.jsx("rect",{x:N,y:E,width:x,height:M,rx:1,className:W(L.cls,r===S&&"opacity-80")},L.cls)}),S%b===0&&e.jsx("text",{x:N+x/2,y:mt-4,textAnchor:"middle",className:"fill-muted-foreground font-mono text-[10px]",children:lf(C.day)})]},C.day)})})]})]})}function cn({className:s,label:t,pressed:n,onClick:a}){return e.jsxs("button",{type:"button","aria-pressed":n,onClick:a,className:W("flex items-center gap-1 rounded px-0.5 transition-opacity",n?"opacity-100":"opacity-40"),children:[e.jsx("span",{className:W("inline-block h-2.5 w-2.5 rounded-sm",s)}),t]})}function mf({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:W("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 dn=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],Pr=Array.from({length:24},(s,t)=>String(t).padStart(2,"0")),Nt=["bg-foreground/[0.06]","bg-foreground/20","bg-foreground/40","bg-foreground/60","bg-foreground/80","bg-foreground"];function uf(s,t){return s<=0||t<=0?0:1+Math.min(Nt.length-2,Math.floor(s/t*(Nt.length-1)))}function xf({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")}),Nt.map(a=>e.jsx("span",{className:W("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(dn[r])}),e.jsx("div",{className:"grid grid-cols-24 gap-[3px]",children:Pr.map((o,i)=>e.jsx("span",{title:`${t(dn[r])} ${o}:00 · ${Ke(a[i]??0)}`,className:W("aspect-square rounded-[2px]",Nt[uf(a[i]??0,n)])},o))})]},dn[r])),e.jsx("span",{}),e.jsx("div",{className:"grid grid-cols-24 font-mono text-[10px] text-muted-foreground",children:Pr.map((a,r)=>e.jsx("span",{className:W(r%3!==0&&"invisible"),children:a},a))})]})]})}function mn({title:s,countLabel:t,rows:n,emptyLabel:a,limit:r=8}){const{t:o}=R(),[i,d]=l.useState(!1),u=n.reduce((c,f)=>c+f.tokens,0),m=n.length>r,p=m&&!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}),m&&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=u>0?c.tokens/u:0;return e.jsxs("tr",{className:"border-t border-border/60",children:[e.jsxs("td",{className:"py-2 pr-3",children:[e.jsx("div",{className:"truncate",title:c.name,children:c.name||o("(no project)")}),e.jsx("div",{className:"mt-1 h-1 w-full rounded-full bg-foreground/[0.06]",children:e.jsx("div",{className:"h-1 rounded-full bg-foreground/70",style:{width:`${Math.max(1,f*100)}%`}})})]}),e.jsx("td",{className:W("py-2 text-right font-mono tabular-nums",c.cost===null&&"text-muted-foreground"),children:yt(c.cost)}),e.jsxs("td",{className:"py-2 text-right font-mono tabular-nums",children:[Ke(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)})})]}),m&&e.jsx(y,{variant:"ghost",size:"xs",className:"mt-2 w-full text-muted-foreground",onClick:()=>d(c=>!c),children:o(i?"Collapse":"Show all")})]})}function hf({value:s,className:t}){const n=s.split("");return e.jsx("span",{className:W("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 pf={default:"text-foreground",success:"text-emerald-600 dark:text-emerald-400",info:"text-sky-600 dark:text-sky-400",muted:"text-muted-foreground"};function ds({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:W("mt-1 truncate font-mono text-xl font-semibold leading-tight tabular-nums sm:text-2xl",pf[a]),title:t,children:e.jsx(hf,{value:t})})]})}const un={input:0,output:0,cacheRead:0,cacheWrite:0},kt=["input","output","cacheRead","cacheWrite"];function xn(s){return{input:String(s.input),output:String(s.output),cacheRead:String(s.cacheRead),cacheWrite:String(s.cacheWrite)}}function ff(s){return pd({id:Object.fromEntries(kt.map(n=>[n,Number(s[n])]))}).id??null}function gf(s){return s===void 0?"—":String(s)}function Tr({rows:s,editing:t,draft:n,overrides:a,onDraft:r,onEdit:o,onSave:i}){const{t:d}=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:d("Name")}),kt.map(u=>e.jsx("th",{className:"pb-2 text-right font-normal",children:u},u)),e.jsx("th",{className:"w-14 pb-2"})]})}),e.jsx("tbody",{children:s.map(u=>{const m=t===u.model,p=u.model in a;return e.jsxs("tr",{className:"border-t border-border/60",children:[e.jsxs("td",{className:"py-1.5 pr-3 align-middle",children:[e.jsx("span",{className:"font-mono text-xs",title:u.model,children:u.model}),p&&e.jsx("span",{className:"ml-1.5 text-[10px] text-muted-foreground",children:d("Custom")})]}),kt.map(c=>e.jsx("td",{className:"py-1.5 text-right align-middle",children:m?e.jsx(X,{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:W("font-mono tabular-nums",u.pricing==null&&"text-muted-foreground"),children:gf(u.pricing?.[c])})},c)),e.jsx("td",{className:"py-1.5 text-right align-middle",children:m?e.jsx(y,{size:"sm",className:"h-6 px-1.5 text-[11px]",onClick:()=>i(u.model),children:d("Save")}):e.jsx(y,{variant:"ghost",size:"sm",className:"h-6 px-1.5 text-[11px]",onClick:()=>o(u.model,u.pricing),children:d("Edit")})})]},u.model)})})]})}function jf({models:s,catalog:t,onChanged:n}){const{t:a}=R(),r=g(w=>w.usageModelPricing),o=qs(),i=g(w=>w.setUsageModelPricing),[d,u]=l.useState(!1),[m,p]=l.useState(!1),[c,f]=l.useState(null),[x,h]=l.useState(xn(un)),[j,b]=l.useState(null),[I,C]=l.useState(!1),[S,N]=l.useState(""),[A,$]=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 M=A.trim().toLowerCase(),k=s.filter(w=>!M||w.model.toLowerCase().includes(M)).map(w=>({model:w.model,pricing:w.pricing})),T=[...L].filter(w=>!E.has(w)&&(!M||w.toLowerCase().includes(M))).sort().map(w=>({model:w,pricing:r[w]??t[w]??null})),_=(w,z)=>{C(!1),f(w),h(xn(z??un)),b(null)},q=w=>{const z=ff(x);return!z||!i(w,z)?(b(a("Enter a model id and non-negative rates.")),!1):(b(null),f(null),C(!1),N(""),n(),!0)};return e.jsxs(ud,{open:d,onOpenChange:u,className:"rounded-lg border bg-card",children:[e.jsxs(xd,{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(vt,{className:W("h-4 w-4 shrink-0 text-muted-foreground transition-transform",d&&"rotate-180")})]}),e.jsx(hd,{children:e.jsxs("div",{className:"space-y-3 border-t px-4 py-3",children:[e.jsx(X,{size:"sm",value:A,onChange:w=>$(w.target.value),placeholder:a("Search models")}),k.length===0&&!I?e.jsx("p",{className:"text-xs text-muted-foreground",children:a(M?"No matching models":"No usage in this period")}):e.jsx(Tr,{rows:k,editing:c,draft:x,overrides:r,onDraft:h,onEdit:_,onSave:q}),T.length>0&&(m||!!M)&&e.jsx(Tr,{rows:T,editing:c,draft:x,overrides:r,onDraft:h,onEdit:_,onSave:q}),I?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-end gap-2",children:[e.jsxs("label",{className:"grid min-w-36 gap-1 text-[11px] text-muted-foreground",children:[a("Model id"),e.jsx(X,{size:"sm",value:S,onChange:w=>N(w.target.value),placeholder:"qwen-3.8-27b"})]}),kt.map(w=>e.jsxs("label",{className:"grid min-w-16 gap-1 text-[11px] text-muted-foreground",children:[w,e.jsx(X,{size:"sm",inputMode:"decimal",value:x[w],onChange:z=>h(H=>({...H,[w]:z.target.value}))})]},w))]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(y,{size:"sm",className:"h-7",onClick:()=>q(S),children:a("Save")}),e.jsx(y,{variant:"ghost",size:"sm",className:"h-7",onClick:()=>{C(!1),N(""),b(null)},children:a("Cancel")})]})]}):e.jsxs("div",{className:"flex justify-end gap-2",children:[T.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(vt,{className:W("ml-1 h-3.5 w-3.5 transition-transform",m&&"rotate-180")})]}),e.jsx(y,{variant:"ghost",size:"sm",className:"h-7",onClick:()=>{C(!0),h(xn(un)),b(null)},children:a("Add")})]}),j&&e.jsx("p",{className:"text-xs text-destructive",children:j})]})})]})}const vf={1:"Today",7:"7D",30:"30D",90:"90D"};function bf(){const{t:s}=R(),[t,n]=l.useState(7),[a,r]=l.useState(null),o=g(h=>h.botModeEnabled),[i,d]=l.useState(null),[u,m]=l.useState(null),[p,c]=l.useState(!1),f=l.useRef(0),x=l.useCallback(async h=>{const j=++f.current;c(!0);const[b,I]=await Promise.all([window.electronAPI.usage.summary(h),o?window.electronAPI.bots.usageSummary(h).catch(()=>null):null]);j===f.current&&(c(!1),d(I?.ok?I.rows:null),b.ok?(r(b.summary),m(null)):(r(null),m(b.error)))},[o]);return l.useEffect(()=>{x(t)},[t,x]),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:()=>{x(t)},disabled:p,"aria-label":s("Refresh"),children:e.jsx(is,{className:W(p&&"animate-spin")})})]}),e.jsx(yf,{value:t,onChange:n}),u&&e.jsx("p",{className:"text-sm text-destructive",children:u}),a&&e.jsxs(e.Fragment,{children:[e.jsx(wf,{totals:a.totals,previous:a.previous}),e.jsx(df,{daily:a.daily}),e.jsx(xf,{heatmap:a.heatmap}),e.jsxs("div",{className:"grid gap-4 xl:grid-cols-2",children:[e.jsx(mn,{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(mn,{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(mn,{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(jf,{models:a?.byModel??[],catalog:a?.pricing??{},onChanged:()=>{x(t)}})]})}function yf({value:s,onChange:t}){const{t:n}=R();return e.jsx("div",{className:"flex items-center gap-1.5",children:af.map(a=>e.jsx("button",{type:"button",onClick:()=>t(a),className:W("rounded-full px-3 py-1 font-mono text-xs transition-colors",s===a?"bg-foreground text-background":"bg-muted text-muted-foreground hover:text-foreground"),children:n(vf[a])},a))})}function wf({totals:s,previous:t}){const{t:n}=R(),a=s.cacheRead+s.cacheWrite,r=t.cacheRead+t.cacheWrite;return e.jsxs("div",{className:"grid grid-cols-2 gap-3 md:grid-cols-4",children:[e.jsx(ds,{label:n("Estimated cost"),value:yt(s.cost),delta:ls(t.cost,s.cost),tone:"success"}),e.jsx(ds,{label:n("Total tokens"),value:Ke(s.tokens),delta:ls(t.tokens,s.tokens)}),e.jsx(ds,{label:n("Input tokens"),value:Ke(s.input),delta:ls(t.input,s.input)}),e.jsx(ds,{label:n("Output tokens"),value:Ke(s.output),delta:ls(t.output,s.output)}),e.jsx(ds,{label:n("Cache tokens"),value:Ke(a),delta:ls(r,a),tone:"muted"}),e.jsx(ds,{label:n("Active time"),value:fd(s.activeMs),delta:ls(t.activeMs,s.activeMs),tone:"info"}),e.jsx(ds,{label:n("Sessions"),value:String(s.sessions),delta:ls(t.sessions,s.sessions)}),e.jsx(ds,{label:n("Messages"),value:s.messages.toLocaleString(),delta:ls(t.messages,s.messages)})]})}const Nf=32,kf=/^[A-Za-z0-9][A-Za-z0-9_:-]{0,127}$/,Cf=/^[A-Za-z_][A-Za-z0-9_]{0,31}$/,Sf=/\{\{\s*(?:args\.([A-Za-z_][A-Za-z0-9_]{0,31})|(prev))\s*\}\}/g;function An(s,t){if(typeof s!="string")return null;const n=s.trim();return n&&n.length<=t?n:null}function If(s,t){const n=[...new Set(s)].filter(a=>Cf.test(a)).map(a=>({kind:"arg",key:a,token:`{{args.${a}}}`}));return t>0&&n.push({kind:"prev",token:"{{prev}}"}),n}function Af(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 Ef(s){if(!s||typeof s!="object"||Array.isArray(s))return null;const t=s,n=An(t.label,80),a=An(t.prompt,8e3),r=typeof t.agentType=="string"?t.agentType.trim():"";return!n||!a||r&&!kf.test(r)?null:{label:n,agentType:r,prompt:a}}function Mf(s){if(!s||typeof s!="object"||Array.isArray(s))return null;const t=s,n=An(t.title,80);if(!n||!Array.isArray(t.steps)||t.steps.length===0)return null;const a=t.steps.map(Ef);return a.every(r=>r!==null)?{title:n,steps:a}:null}function Pf(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(Mf);return n.every(r=>r!==null)&&n.reduce((r,o)=>r+o.steps.length,0)<=Nf?{phases:n}:null}function li(s){const t=[];let n=0;for(const a of s.matchAll(Sf))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 Tf(s){const t=li(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 Rf({label:s,agentType:t,prompt:n}){const a=[`label: ${JSON.stringify(s)}`];return t&&a.push(`agentType: ${JSON.stringify(t)}`),` () => agent(${Tf(n)}, { ${a.join(", ")} }),`}function ci(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(Rf),"]));")}return t.push("","return prev;",""),t.join(`
|
|
22
|
+
`)}async function Of(s){const[t,n,a]=await Promise.all([ht(()=>import("./standalone-oyxre9MX.js"),[],import.meta.url),ht(()=>import("./babel-BktJt1uC.js"),[],import.meta.url),ht(()=>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 Df=32,Ks=(s,t)=>Math.max(0,Math.min(s,t));function Lf(s){return s.phases.reduce((t,n)=>t+n.steps.length,0)<Df}function zf(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 _f(s,t,n){const a=Ks(t,s.phases.length),r=[...s.phases];return r.splice(a,0,n),{design:{phases:r},selection:{kind:"phase",phase:a}}}function Rr(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:Ks(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:Ks(t.phase,a.length-1)}}}function Or(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 Ff(s,t){const n=Ks(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:Ks(t.step,a-1)}}const hn="__default__",Dr=(s="scout")=>({label:"",agentType:s,prompt:""});function Bf({value:s,tokens:t,args:n,onChange:a}){const{t:r}=R(),o=l.useRef(null),i=()=>o.current?.querySelector("textarea")??null,d=m=>{const p=i(),c=s.length,f=Af(s,p?.selectionStart??c,p?.selectionEnd??c,m);a(f.text),requestAnimationFrame(()=>{p?.focus(),p?.setSelectionRange(f.cursor,f.cursor)})},u=m=>m.kind==="prev"?r("Previous phase output"):n.find(p=>p.key.trim()===m.key)?.label.trim()||m.key;return e.jsxs("div",{ref:o,className:"space-y-1",children:[e.jsx(Qe,{rows:5,className:"text-xs",placeholder:r("Prompt"),value:s,onChange:m=>a(m.target.value)}),e.jsxs(ko,{children:[e.jsxs(Co,{disabled:t.length===0,className:"inline-flex h-6 items-center gap-1 rounded-md px-1.5 text-muted-foreground text-xs hover:bg-accent hover:text-foreground disabled:pointer-events-none disabled:opacity-50",children:[e.jsx(vd,{className:"h-3.5 w-3.5"}),r("Insert argument")]}),e.jsx(So,{align:"start",zIndex:os.DROPDOWN_IN_MODAL,finalFocus:i,children:t.map(m=>e.jsxs(Io,{onClick:()=>d(m.token),children:[u(m),e.jsx("span",{className:"ml-auto pl-4 font-mono text-muted-foreground text-xs",children:m.token})]},m.token))})]})]})}const Lr=(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 Uf(s,t){const[n,a]=l.useState([]);return l.useLayoutEffect(()=>{const r=s.current;if(!r)return;const o=()=>{const d=r.getBoundingClientRect(),u=r.offsetWidth?d.width/r.offsetWidth:1,m=f=>{const x=r.querySelector(f)?.getBoundingClientRect();return x?{left:(x.left-d.left)/u,right:(x.right-d.left)/u,y:(x.top-d.top+x.height/2)/u}:null},p=(f,x)=>f<0||f>=t.phases.length?[`[data-node="${x}"]`]:(t.phases[f]?.steps??[]).map((h,j)=>`[data-node="s-${f}-${j}"]`),c=[];for(let f=0;f<=t.phases.length;f++){const x=m(`[data-gap="${f}"]`);if(x){for(const h of p(f-1,"start")){const j=m(h);j&&c.push({d:Lr(j.right,j.y,x.left,x.y),arrow:!1})}for(const h of p(f,"end")){const j=m(h);j&&c.push({d:Lr(x.right,x.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 zr({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 $f({prompt:s,args:t}){const{t:n}=R(),a=li(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 Vf({design:s,agentTypes:t,args:n,onChange:a}){const{t:r}=R(),[o,i]=l.useState({kind:"step",phase:0,step:0}),d=l.useRef(null),u=l.useId(),m=Uf(d,s),p=s.phases,c=Ff(s,o),f=p[c.phase],x=c.kind==="step"?f?.steps[c.step]:void 0,h=t.includes("scout")?"scout":"",j=n.map(E=>E.key.trim()).filter(Boolean),b=Lf(s),I=Rr(s,c)!==null,C=E=>{E&&(a(E.design),i(E.selection))},S=E=>a({phases:p.map((L,M)=>M===c.phase?{...L,...E}:L)}),N=E=>c.kind==="step"&&S({steps:(f?.steps??[]).map((L,M)=>M===c.step?{...L,...E}:L)}),A=E=>{const L=E&&!t.includes(E)?[...t,E]:t;return[{value:hn,label:r("Default (worker)")},...L.map(M=>({value:M,label:M}))]},$=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:()=>C(_f(s,E,{title:"",steps:[Dr(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(Ae,{className:"h-3 w-3"})})});return e.jsxs("div",{className:"w-full space-y-2",children:[e.jsx("div",{className:"overflow-x-auto rounded-lg border bg-muted/30",children:e.jsxs("div",{ref:d,className:"relative flex w-max min-w-full items-center justify-center px-3 py-5",children:[e.jsxs("svg",{"aria-hidden":!0,className:"pointer-events-none absolute inset-0 z-20 h-full w-full overflow-visible text-muted-foreground/50",children:[e.jsx("defs",{children:e.jsx("marker",{id:u,viewBox:"0 0 6 6",refX:"5",refY:"3",markerWidth:"6",markerHeight:"6",orient:"auto",children:e.jsx("path",{d:"M0,0 L6,3 L0,6 z",fill:"currentColor"})})}),m.map(E=>e.jsx("path",{d:E.d,fill:"none",stroke:"currentColor",strokeWidth:1.25,markerEnd:E.arrow?`url(#${u})`:void 0},E.d))]}),e.jsx(zr,{node:"start",icon:e.jsx(gd,{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:[$(L),e.jsxs("div",{className:W("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:W("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((M,k)=>{const T=c.kind==="step"&&c.phase===L&&c.step===k,_=!M.label.trim()||!M.prompt.trim();return e.jsxs("button",{type:"button","data-node":`s-${L}-${k}`,onClick:()=>i({kind:"step",phase:L,step:k}),className:W("block w-full rounded-lg border bg-background px-2.5 py-1.5 text-left shadow-xs transition-colors hover:border-primary/60",T&&"border-primary ring-2 ring-primary/20",_&&!T&&"border-destructive/50"),children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"truncate font-medium text-xs",children:M.label.trim()||r("Untitled step")}),e.jsx("span",{className:"ml-auto shrink-0 rounded bg-muted px-1 text-[10px] text-muted-foreground",children:M.agentType||"worker"})]}),e.jsx("span",{className:"mt-0.5 line-clamp-2 break-words text-[11px] text-muted-foreground",children:e.jsx($f,{prompt:M.prompt,args:n})})]},k)}),e.jsxs("button",{type:"button",disabled:!b,onClick:()=>C(zf(s,L,Dr(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(Ae,{className:"h-3 w-3"}),r("Parallel step")]})]})]},L)),$(p.length),e.jsx(zr,{node:"end",icon:e.jsx(um,{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:()=>C(Or(s,c.phase,-1)),children:e.jsx(po,{})}),e.jsx(y,{variant:"ghost",size:"icon-xs","aria-label":r("Move right"),disabled:c.phase===p.length-1,onClick:()=>C(Or(s,c.phase,1)),children:e.jsx(jd,{})})]}),e.jsx(y,{variant:"ghost",size:"icon-xs","aria-label":r("Delete"),disabled:!I,onClick:()=>C(Rr(s,c)),children:e.jsx(Ee,{})})]})]}),c.kind==="phase"||!x?e.jsx(X,{size:"sm",placeholder:r("Phase title"),value:f?.title??"",onChange:E=>S({title:E.target.value})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(X,{size:"sm",className:"min-w-0 flex-1",placeholder:r("Label"),value:x.label,onChange:E=>N({label:E.target.value})}),e.jsxs(Z,{items:A(x.agentType),value:x.agentType||hn,onValueChange:E=>N({agentType:E===hn?"":String(E??"")}),children:[e.jsx(ee,{size:"sm",className:"w-36 min-w-0 shrink-0",children:e.jsx(se,{})}),e.jsx(te,{zIndex:os.DROPDOWN_IN_MODAL,children:A(x.agentType).map(E=>e.jsx(J,{value:E.value,children:E.label},E.value))})]})]}),e.jsx(Bf,{value:x.prompt,tokens:If(j,c.phase),args:n,onChange:E=>N({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 En={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}}`}]}]},_r={name:"",description:"",args:[{key:"topic",label:"Topic",required:!0}],design:En,script:ci(En)};function Kf(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 Gf({target:s,onClose:t,onSaved:n}){const{t:a}=R(),[r,o]=l.useState(_r),[i,d]=l.useState("design"),[u,m]=l.useState(0),p=l.useRef(null),[c,f]=l.useState(!1),[x,h]=l.useState(!1),[j,b]=l.useState(!1),[I,C]=l.useState(null),S=g(w=>w.disabledBuiltinAgentTypes),N=g(w=>w.agentTypes),A=l.useMemo(()=>[...bd.map(w=>w.name).filter(w=>!S.includes(w)),...N.map(w=>w.name)],[S,N]);l.useEffect(()=>{if(C(null),s===null)return;if(p.current=null,m(z=>z+1),s==="new"){o(_r),d("design");return}let w=!1;return f(!0),window.electronAPI.workflowPresets.read(s).then(z=>{if(!w)if(z){const{id:H,...F}=z;o(F),d(F.design?"design":"code"),m(G=>G+1)}else C(a("Failed to read content"))}).finally(()=>{w||f(!1)}),()=>{w=!0}},[s,a]);const $=w=>o(z=>({...z,...w})),E=(w,z)=>$({args:r.args.map((H,F)=>F===w?{...H,...z}:H)}),L=w=>$({design:w,script:ci(w)}),M=w=>{w!==r.script&&(r.design&&(p.current=r.design),o(z=>({...z,script:w,design:void 0})))},k=async()=>{b(!0);const w=await Of(r.script);if(b(!1),!w.ok){C(a("Format failed: {{error}}",{error:w.error}));return}C(null),w.code!==r.script&&(M(w.code),m(z=>z+1))},T=!r.design||Pf(r.design)!==null,_=!c&&!x&&r.name.trim()!==""&&r.description.trim()!==""&&T&&r.script.trim()!=="",q=async()=>{if(!_||s===null)return;h(!0);const w=await window.electronAPI.workflowPresets.save({...r,args:Kf(r.args)},s==="new"?void 0:s);if(h(!1),!w.ok){C(a(w.error));return}n(),t()};return e.jsx(pe,{open:s!==null,onOpenChange:w=>!w&&t(),children:e.jsxs(fe,{className:"max-w-4xl",children:[e.jsx(ge,{children:e.jsx(je,{children:a(s==="new"?"Add workflow preset":"Edit workflow preset")})}),e.jsxs(ve,{className:"space-y-4",children:[e.jsxs(me,{children:[e.jsx(ue,{children:a("Name")}),e.jsx(X,{value:r.name,onChange:w=>$({name:w.target.value})})]}),e.jsxs(me,{children:[e.jsx(ue,{children:a("Description")}),e.jsx(X,{value:r.description,onChange:w=>$({description:w.target.value})})]}),e.jsxs(me,{children:[e.jsx(ue,{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(X,{size:"sm",className:"w-28 font-mono",placeholder:"key",value:w.key,onChange:H=>E(z,{key:H.target.value})}),e.jsx(X,{size:"sm",className:"flex-1",placeholder:a("Label"),value:w.label,onChange:H=>E(z,{label:H.target.value})}),e.jsx(X,{size:"sm",className:"flex-1",placeholder:a("Default value"),value:w.default??"",onChange:H=>E(z,{default:H.target.value})}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1 text-muted-foreground text-xs",children:[e.jsx(Re,{checked:w.required===!0,onCheckedChange:H=>E(z,{required:H===!0})}),a("Required")]}),e.jsx(y,{variant:"ghost",size:"icon-xs","aria-label":a("Remove"),onClick:()=>$({args:r.args.filter((H,F)=>F!==z)}),children:e.jsx(gs,{})})]},z)),e.jsxs(y,{variant:"outline",size:"xs",disabled:r.args.length>=8,onClick:()=>$({args:[...r.args,{key:"",label:""}]}),children:[e.jsx(Ae,{}),a("Add argument")]})]})]}),e.jsxs(me,{children:[e.jsxs("div",{className:"flex w-full items-center justify-between gap-2",children:[e.jsx(ue,{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:k,children:[j?e.jsx(Ce,{className:"animate-spin"}):e.jsx(yd,{}),a("Format")]}),e.jsx(Ws,{value:i,onValueChange:w=>d(w),children:e.jsxs(Hs,{children:[e.jsx(He,{value:"design",children:a("Design")}),e.jsx(He,{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(Ce,{className:"h-4 w-4 animate-spin text-muted-foreground"})}):i==="design"?r.design?e.jsx(Vf,{design:r.design,agentTypes:A,args:r.args,onChange:L}):e.jsxs("div",{className:"flex w-full flex-col items-center gap-2 rounded-md border border-dashed py-8 text-center",children:[e.jsx("p",{className:"max-w-md text-muted-foreground text-xs",children:a("This preset is plain code and cannot be shown in the designer. Using the designer replaces the current script.")}),e.jsx(y,{variant:"outline",size:"xs",onClick:()=>L(p.current??En),children:a("Use the designer")})]}):e.jsx(Ko,{fileName:"workflow.js",className:"h-80",value:r.script,epoch:u,onChange:M}),e.jsx("p",{className:"text-muted-foreground text-xs",children:i==="design"?!T&&a("Every phase needs a title and every step needs a label and a prompt."):r.design?a("Generated from the design. Editing the code detaches it from the designer."):a("Plain JavaScript with top-level await; end with return. Available: agent(prompt, opts), parallel, pipeline, phase, log, args.")})]}),I&&e.jsxs("p",{className:"flex items-center gap-1.5 text-destructive text-xs",children:[e.jsx(Es,{className:"h-3.5 w-3.5 shrink-0"}),I]})]}),e.jsxs(ke,{children:[e.jsx(y,{variant:"outline",size:"sm",onClick:t,children:a("Cancel")}),e.jsxs(y,{size:"sm",disabled:!_,onClick:q,children:[x&&e.jsx(Ce,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}),a("Save")]})]})]})})}function Wf(){const{t:s}=R(),[t,n]=l.useState([]),[a,r]=l.useState(null),o=g(p=>p.disabledWorkflowPresets),i=g(p=>p.toggleWorkflowPreset),d=l.useCallback(()=>{window.electronAPI.workflowPresets.list().then(n)},[]);l.useEffect(d,[d]);const u=t.filter(p=>p.source!=="builtin"),m=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(Ae,{className:"mr-1.5 h-4 w-4"}),s("Add workflow preset")]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium text-muted-foreground text-xs",children:s("Custom presets")}),u.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx(_n,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:s("No custom workflow presets yet")})]}):e.jsx("div",{className:"space-y-1",children:u.map(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(ne,{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(ms,{className:"h-3.5 w-3.5"})}),e.jsx(y,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity hover:text-destructive group-hover:opacity-100","aria-label":s("Delete"),onClick:()=>{window.electronAPI.workflowPresets.delete(p.id).then(d)},children:e.jsx(Ee,{className:"h-3.5 w-3.5"})})]})]},p.id))})]}),m.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:m.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(ne,{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(oe,{"aria-label":s(p.name),checked:!o.includes(p.id),onCheckedChange:c=>i(p.id,c)})]},p.id))})]}),e.jsx(Gf,{target:a,onClose:()=>r(null),onSaved:d})]})}function Hf(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 Fr(){const{t:s}=R(),[t,n]=l.useState("general"),[a,r]=l.useState(null),[o,i]=l.useState(null),[d,u]=l.useState(null),[m,p]=l.useState(null),[c,f]=l.useState(0),x=wd(),[h,j]=l.useState(!0),[b,I]=l.useState(""),[C,S]=l.useState([]),N=B=>{n(B),j(!1)},A=g(B=>B.disabledBuiltinTools),$=g(B=>B.botModeEnabled),E=g(B=>B.secretaryEnabled),L=l.useSyncExternalStore(B=>g.persist?.onFinishHydration?.(B)??(()=>{}),()=>g.persist?.hasHydrated?.()??!0),M=l.useCallback(B=>{n(B.category),j(!1),r(B.rowId),B.pluginInstallUrl&&i(B.pluginInstallUrl),u(B.pluginId??null),p(B.marketQuery??null)},[]);l.useEffect(()=>(window.electronAPI.window.consumeSettingsDeepLink().then(B=>{B&&M(B)}),window.electronAPI.window.onSettingsDeepLink(M)),[M]),l.useEffect(()=>{let B=!0;return window.electronAPI.sshConnections.list().then(ae=>{B&&S(ae.map(K=>({id:K.id,name:K.name})))}).catch(()=>{B&&S([])}),()=>{B=!1}},[]);const k=Nd(C);l.useLayoutEffect(()=>{if(!a)return;Hf(a);const B=window.setTimeout(()=>r(null),1600);return()=>window.clearTimeout(B)},[a]);const _=sf([{id:"general",icon:Ad,label:"General"},{id:"shortcuts",icon:gm,label:"Shortcuts"},{id:"appearance",icon:bm,label:"Appearance"},{id:"providers",icon:Un,label:"Model Providers"},{id:"presets",icon:Ed,label:"Presets"},{id:"agents",icon:Md,label:"Agent types"},{id:"tools",icon:so,label:"Built-in tools"},{id:"workflows",icon:_n,label:"Workflows"},{id:"memory",icon:Zr,label:"Memory"},{id:"privacy",icon:Pd,label:"Privacy"},{id:"skills",icon:Ao,label:"Skills"},{id:"plugins",icon:Tt,label:"Enso plugins"},{id:"mcp",icon:co,label:"MCP Servers"},{id:"instructions",icon:Fn,label:"Instruction Files"},{id:"phone",icon:gn,label:"Devices"},{id:"ssh",icon:Gr,label:"SSH"},{id:"usage",icon:om,label:"Usage"},{id:"resources",icon:Td,label:"Resources"},{id:"experimental",icon:Rd,label:"Experimental"},{id:"bots",icon:Od,label:"Bot mode",sub:!0},{id:"botTemplates",icon:Dd,label:"Bot templates",sub:!0},{id:"secretary",icon:Ld,label:"Secretary",sub:!0}],A,$,E||!L),q=ef(nf(_,k,b,s)),w=tf(t,A,$||!L,E||!L);l.useEffect(()=>{w!==t&&n(w)},[w,t]);const z=!x||h,H=!x||!h,F=_.find(B=>B.id===t)?.label,G=kd(),le=Eo();return e.jsxs("div",{className:"flex h-full w-full",children:[z&&e.jsxs("nav",{"data-enso":"settings-nav",className:W("flex min-h-0 shrink-0 flex-col",x?"w-full":G?"w-56":"w-56 border-r"),children:[G&&le==="mac"&&e.jsx("div",{"aria-hidden":!0,className:"drag-region -mb-2 h-[44px] shrink-0"}),e.jsx("div",{className:W("sticky top-0 z-10 px-2 pt-2",!G&&"bg-background"),children:e.jsxs("div",{className:"relative",children:[e.jsx(eo,{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:B=>I(B.target.value),onKeyDown:B=>{B.key!=="Escape"||b.length===0||(B.preventDefault(),B.stopPropagation(),I(""))},placeholder:s("Search settings"),className:"h-8 w-full rounded-md border bg-transparent pr-2 pl-7 text-sm outline-none placeholder:text-muted-foreground focus-visible:ring-2 focus-visible:ring-ring"})]})}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto p-2",children:b.trim()&&q.length===0?e.jsx("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:s("No results")}):q.map((B,ae)=>e.jsxs("div",{className:W(ae>0&&"mt-4"),children:[e.jsx("div",{className:"px-2 pb-1.5 text-xs font-semibold text-foreground/55",children:s(B.label)}),e.jsx("div",{className:"space-y-0.5 rounded-lg bg-muted/60 p-1",children:B.items.map(K=>e.jsxs("div",{children:[e.jsxs("button",{type:"button",onClick:()=>N(K.id),className:W("flex w-full items-center gap-2 rounded-md px-3 text-sm transition-colors",x?"py-3":"py-1.5",K.sub&&"pl-8",t===K.id&&!x?"bg-background text-foreground shadow-xs":"text-muted-foreground hover:bg-background/60 hover:text-foreground"),children:[e.jsx(K.icon,{className:"h-4 w-4"}),s(K.label),x&&e.jsx(Gs,{className:"ml-auto h-4 w-4 opacity-60"})]}),K.hits.map(ie=>e.jsx("button",{type:"button",onClick:()=>{N(K.id),r(ie.id)},className:W("block w-full truncate rounded-md pr-3 text-left text-xs text-muted-foreground hover:bg-background/60 hover:text-foreground",K.sub?"pl-14":"pl-9",x?"py-2":"py-1"),children:s(ie.title)},ie.id))]},K.id))})]},B.id))})]}),H&&e.jsxs("div",{"data-enso":"settings-content",className:W("flex min-w-0 flex-1 flex-col",G&&"my-[8px] mr-[8px] overflow-hidden rounded-[10px] bg-background shadow-surface"),children:[G&&e.jsx(Cd,{"data-enso":"title-bar"}),e.jsxs("div",{className:W("min-h-0 flex-1 overflow-y-auto",x?"px-4 pb-6":G?"px-6 pb-6":"p-6"),children:[x&&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(Hr,{className:"h-5 w-5 text-muted-foreground"}),F?s(F):null]}),t==="general"&&e.jsx(ru,{}),t==="shortcuts"&&e.jsx(gx,{}),t==="appearance"&&e.jsx(Ou,{onOpenPlugins:()=>N("plugins")}),t==="providers"&&e.jsx(yp,{}),t==="skills"&&e.jsx(Yp,{}),t==="plugins"&&e.jsx(ap,{requestedInstallUrl:o,onRequestedInstallUrlConsumed:()=>i(null),focusPluginId:d,onFocusPluginConsumed:()=>u(null),requestedMarketQuery:m,onRequestedMarketQueryConsumed:()=>p(null)}),t==="mcp"&&e.jsx(Ux,{}),t==="instructions"&&e.jsx(fx,{}),t==="presets"&&e.jsx(Sd,{}),t==="agents"&&e.jsx(Id,{}),t==="workflows"&&e.jsx(Wf,{}),t==="tools"&&e.jsx(rx,{}),t==="memory"&&e.jsxs("div",{className:"space-y-8",children:[e.jsx(_h,{onLibraryChanged:()=>f(B=>B+1)}),e.jsx(eh,{revision:c}),e.jsx(ph,{revision:c})]}),t==="phone"&&e.jsx(lx,{}),t==="ssh"&&e.jsx(Jp,{}),t==="usage"&&e.jsx(bf,{}),t==="privacy"&&e.jsx(mp,{}),t==="resources"&&e.jsx(Ap,{}),t==="experimental"&&e.jsx(hx,{onOpenBots:()=>n("bots")}),t==="bots"&&e.jsx(Uu,{}),t==="botTemplates"&&e.jsx(Yu,{}),t==="secretary"&&e.jsx(Hp,{})]})]})]})}zd();_d();function qf(){const{t:s}=R(),t=Eo();return t!=="mobile"&&t!=="web"?e.jsxs("div",{"data-enso":"canvas",className:"flex h-screen overflow-hidden bg-canvas",children:[e.jsx(Aa,{}),e.jsx(Bd.Provider,{value:{trailing:e.jsx(Ud,{kind:t,edgeGap:8})},children:e.jsx(Fr,{})}),e.jsx(Ea,{}),e.jsx(Ma,{})]}):e.jsxs("div",{className:"flex h-screen flex-col overflow-hidden",children:[e.jsx(Aa,{}),e.jsx($d,{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(gs,{className:"h-4 w-4"})})}),e.jsx("main",{className:"min-h-0 flex-1 overflow-hidden",children:e.jsx(Fr,{})}),e.jsx(Ea,{}),e.jsx(Ma,{})]})}Fd.createRoot(document.getElementById("root")).render(e.jsx(l.StrictMode,{children:e.jsx(qf,{})}));
|