@ensocode/server 0.3.2 → 0.3.3
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/{abnfDiagram-VCTEODGH-7wNFPVNX.js → abnfDiagram-VCTEODGH-CLgfII9z.js} +1 -1
- package/out/phone/assets/architecture-7GRP2DOG-CQOPTv6S.js +1 -0
- package/out/phone/assets/{architectureDiagram-5GKGNRK7-CnuIop2x.js → architectureDiagram-5GKGNRK7-I2RDn32D.js} +1 -1
- package/out/phone/assets/{blockDiagram-I7D4REHJ-JVET2iOX.js → blockDiagram-I7D4REHJ-D5xNQZkS.js} +1 -1
- package/out/phone/assets/{c4Diagram-7LVT6UL2-BLFmpm8Y.js → c4Diagram-7LVT6UL2-CRKpzdlA.js} +1 -1
- package/out/phone/assets/channel-DdXebl9x.js +1 -0
- package/out/phone/assets/{chunk-4HAMMTFA-t_CWzvX0.js → chunk-4HAMMTFA-CcezrqKz.js} +1 -1
- package/out/phone/assets/{chunk-75Z2AOVW-Ck9s4XbN.js → chunk-75Z2AOVW-DDCXp4y1.js} +1 -1
- package/out/phone/assets/{chunk-DU6HZSFF-Clg-W8ZP.js → chunk-DU6HZSFF-CjWveEkB.js} +1 -1
- package/out/phone/assets/{chunk-F27PBJKO-Dg6DF7tm.js → chunk-F27PBJKO-Bgl_xI02.js} +1 -1
- package/out/phone/assets/{chunk-GMAD6QVW-tyN1lr56.js → chunk-GMAD6QVW-EmL8nOme.js} +1 -1
- package/out/phone/assets/{chunk-GVQU2GXP-Cp6zlp3q.js → chunk-GVQU2GXP-Dox_nphF.js} +1 -1
- package/out/phone/assets/{chunk-IMKFNOWR-DivN0qgp.js → chunk-IMKFNOWR-BapGpI4S.js} +1 -1
- package/out/phone/assets/{chunk-L3NEJ4N5-H6AVmtE_.js → chunk-L3NEJ4N5-Cq_UZI8A.js} +1 -1
- package/out/phone/assets/{chunk-OSK3NFVY-D8Gtw0_S.js → chunk-OSK3NFVY-2VVlErAd.js} +1 -1
- package/out/phone/assets/{chunk-P2QGCYS3-RZSHAUZq.js → chunk-P2QGCYS3-Cci-G-p1.js} +1 -1
- package/out/phone/assets/{chunk-POPQ4Y6H-BVS8pZqz.js → chunk-POPQ4Y6H-CJ47EOfE.js} +1 -1
- package/out/phone/assets/{chunk-PWAF6VOD-D7FryQWf.js → chunk-PWAF6VOD-D9dLdFqC.js} +1 -1
- package/out/phone/assets/{chunk-SHT3W25Y-DGdqMpPQ.js → chunk-SHT3W25Y-BlGSiWZn.js} +1 -1
- package/out/phone/assets/{chunk-SVP7TREG-BwyiT08_.js → chunk-SVP7TREG-C0zdsa_A.js} +1 -1
- package/out/phone/assets/{chunk-TICWLB2K-CY7mq27-.js → chunk-TICWLB2K-DAQW8nQU.js} +1 -1
- package/out/phone/assets/classDiagram-ZZMXUADV-BCctWEp1.js +1 -0
- package/out/phone/assets/classDiagram-v2-VYDZK3BY-BCctWEp1.js +1 -0
- package/out/phone/assets/{cynefin-OW5HDTMX-ep90c-ad.js → cynefin-OW5HDTMX-_zsx5mdV.js} +1 -1
- package/out/phone/assets/{cynefinDiagram-5FMLGOSQ-M8djyXi6.js → cynefinDiagram-5FMLGOSQ-Cww-w0ex.js} +1 -1
- package/out/phone/assets/{dagre-GXQ25YYZ-Qp6_rUFB.js → dagre-GXQ25YYZ-C0i7DPqX.js} +1 -1
- package/out/phone/assets/desk-mfuEW2n4.js +2 -0
- package/out/phone/assets/{diagram-S7CK7UJ4-78nJmih8.js → diagram-S7CK7UJ4-Bx-G5hYz.js} +1 -1
- package/out/phone/assets/{diagram-UQ7AKVKN-DK3Lux6Z.js → diagram-UQ7AKVKN-DaTblkjV.js} +1 -1
- package/out/phone/assets/{diagram-VSXAHHWV-8uHrV5vL.js → diagram-VSXAHHWV-gmN2e1b4.js} +1 -1
- package/out/phone/assets/{diagram-VX7I27RA-DM2jP_ep.js → diagram-VX7I27RA-WYtRtOo8.js} +1 -1
- package/out/phone/assets/{diagram-Z3DM3KII-Dk6weE7F.js → diagram-Z3DM3KII-Cr6uUB5B.js} +1 -1
- package/out/phone/assets/{ebnfDiagram-PWID7BFC-CcOU0Q-s.js → ebnfDiagram-PWID7BFC-BCicfvpA.js} +1 -1
- package/out/phone/assets/{erDiagram-RLTQ6QDP-Cv4zHR88.js → erDiagram-RLTQ6QDP-B3QlJvfQ.js} +1 -1
- package/out/phone/assets/eventmodeling-NTZA5JFV-BtfapP6M.js +1 -0
- package/out/phone/assets/flowDiagram-HODETNUW-BsyiyBtD.js +1 -0
- package/out/phone/assets/{ganttDiagram-EL5Y4UJY-DpMAd_jd.js → ganttDiagram-EL5Y4UJY-LYy2mfCh.js} +1 -1
- package/out/phone/assets/{gitGraph-4MIJSDKK-CeZWGC9r.js → gitGraph-4MIJSDKK-dT22Z2jG.js} +1 -1
- package/out/phone/assets/{gitGraphDiagram-WWUBYQGX-6QsSrkNy.js → gitGraphDiagram-WWUBYQGX-DHNdY57l.js} +1 -1
- package/out/phone/assets/{info-A6RAGUB7-C-8QwtyE.js → info-A6RAGUB7-nIu8NSOs.js} +1 -1
- package/out/phone/assets/{infoDiagram-27XIBGKW-BEywxx6y.js → infoDiagram-27XIBGKW-DGkWZIMT.js} +1 -1
- package/out/phone/assets/{ishikawaDiagram-5VMMS53U-Dv5MWe8O.js → ishikawaDiagram-5VMMS53U-C8EPXru-.js} +1 -1
- package/out/phone/assets/{journeyDiagram-3NMN7TZE-rZqFk8KG.js → journeyDiagram-3NMN7TZE-Dyd9L3l3.js} +1 -1
- package/out/phone/assets/{kanban-definition-UXKFOSKX-Vbp8P778.js → kanban-definition-UXKFOSKX-DehTYcsL.js} +1 -1
- package/out/phone/assets/{line-DtO-RzWq.js → line-Db4SulF4.js} +1 -1
- package/out/phone/assets/main-Dv9ve8mT.css +1 -0
- package/out/phone/assets/main-uMMbioCA.js +1638 -0
- package/out/phone/assets/{mermaid-parser.core-CZ9_GWM0.js → mermaid-parser.core-D7h_8WV8.js} +3 -3
- package/out/phone/assets/{mermaid.core-B15T44DF.js → mermaid.core-Dw_E5kj4.js} +4 -4
- package/out/phone/assets/{mindmap-definition-YA3MSWOX-BgFUJmH3.js → mindmap-definition-YA3MSWOX-_5Mxqxsy.js} +1 -1
- package/out/phone/assets/{packet-AYTQ26CC--RETlRVk.js → packet-AYTQ26CC-_cgeMDdN.js} +1 -1
- package/out/phone/assets/{pegDiagram-XKGWAZYB-D7jmN93W.js → pegDiagram-XKGWAZYB-BhBwaNEr.js} +1 -1
- package/out/phone/assets/{pie-WAS4IAKB-CxG1AbYJ.js → pie-WAS4IAKB-BepY80_0.js} +1 -1
- package/out/phone/assets/{pieDiagram-E7YTZNPT-CHxSdknk.js → pieDiagram-E7YTZNPT-CQQgqmI8.js} +1 -1
- package/out/phone/assets/{quadrantDiagram-AXDQQJYC-707LGShZ.js → quadrantDiagram-AXDQQJYC-DEEatC1J.js} +1 -1
- package/out/phone/assets/{radar-RG4KPBEZ-BBg9aR2Q.js → radar-RG4KPBEZ-BqsiI_qQ.js} +1 -1
- package/out/phone/assets/{railroad-74A4TZTK-BvqQaIGQ.js → railroad-74A4TZTK-C_2pEUjD.js} +1 -1
- package/out/phone/assets/railroad-abnf-HS5TGJTU-TmODpceI.js +1 -0
- package/out/phone/assets/railroad-ebnf-LZEXJU2U-BTCjNR9u.js +1 -0
- package/out/phone/assets/railroad-peg-WCYAUIDC-DjhKNo8j.js +1 -0
- package/out/phone/assets/{railroadDiagram-O6MQD6OU-BQUOk6Jm.js → railroadDiagram-O6MQD6OU-B7786u7W.js} +1 -1
- package/out/phone/assets/{requirementDiagram-BXWQKSXE-ByuJLR7x.js → requirementDiagram-BXWQKSXE-Ci3b5uwm.js} +1 -1
- package/out/phone/assets/{sankeyDiagram-P5KCCOFB-CaWA3qV1.js → sankeyDiagram-P5KCCOFB-PwT2gJjH.js} +1 -1
- package/out/phone/assets/{sequenceDiagram-WJ2MYXX4--wDiyJo9.js → sequenceDiagram-WJ2MYXX4-H6sgB5RI.js} +1 -1
- package/out/phone/assets/{stateDiagram-D77RDMKH-ScVywISP.js → stateDiagram-D77RDMKH-BxyRe7OB.js} +1 -1
- package/out/phone/assets/stateDiagram-v2-MP3YSRHH-Cncmf_cL.js +1 -0
- package/out/phone/assets/{storage-DBoRTPSQ.js → storage-D9RW_4__.js} +1 -1
- package/out/phone/assets/{swimlanes-42K2YHIH-Da4TbCnQ.js → swimlanes-42K2YHIH-DWT3f1Hk.js} +1 -1
- package/out/phone/assets/swimlanesDiagram-VR7AAH4N-DAahG4fH.js +8 -0
- package/out/phone/assets/{timeline-definition-24CTP7MA-Csp8wyPz.js → timeline-definition-24CTP7MA-D67esSVY.js} +1 -1
- package/out/phone/assets/{treeView-Q6P3EWNA-DP_TpAnB.js → treeView-Q6P3EWNA-BTIfu3Qr.js} +1 -1
- package/out/phone/assets/{treemap-WGGIJYW6-CDX7X9Iz.js → treemap-WGGIJYW6-DkPf6LQc.js} +1 -1
- package/out/phone/assets/{vennDiagram-4TSXK5OY-DU4FDr9s.js → vennDiagram-4TSXK5OY-DRMRxJ4f.js} +1 -1
- package/out/phone/assets/{wardley-WFR3VGLG-DJY3i8km.js → wardley-WFR3VGLG-hOvC_8-W.js} +1 -1
- package/out/phone/assets/{wardleyDiagram-VM6X3IG4-CDWkRMg4.js → wardleyDiagram-VM6X3IG4-a5aYRgrw.js} +1 -1
- package/out/phone/assets/{xychartDiagram-S5SC5T6Z-DAWohWCi.js → xychartDiagram-S5SC5T6Z-DXjoRFDL.js} +1 -1
- package/out/phone/desk.html +2 -2
- package/out/phone/index.html +3 -3
- package/out/renderer/assets/{abnfDiagram-VCTEODGH-CyBOQPqT.js → abnfDiagram-VCTEODGH-DhskujJf.js} +1 -1
- package/out/renderer/assets/{arc-JLdYPu0k.js → arc-BcW67t47.js} +1 -1
- package/out/renderer/assets/{architectureDiagram-5GKGNRK7-Bq5gy8K8.js → architectureDiagram-5GKGNRK7-D-x057Ia.js} +1 -1
- package/out/renderer/assets/{blockDiagram-I7D4REHJ-Bno0lw2B.js → blockDiagram-I7D4REHJ-DR3sZkhW.js} +1 -1
- package/out/renderer/assets/{c4Diagram-7LVT6UL2-BC6INPz6.js → c4Diagram-7LVT6UL2-CQ4lScWs.js} +1 -1
- package/out/renderer/assets/channel-CudRig7z.js +1 -0
- package/out/renderer/assets/{chunk-2Q5K7J3B-CcyqDHha.js → chunk-2Q5K7J3B-CtT0yqF3.js} +1 -1
- package/out/renderer/assets/{chunk-5VM5RSS4-QSbyABj3.js → chunk-5VM5RSS4-DlCfddrY.js} +1 -1
- package/out/renderer/assets/{chunk-F27PBJKO-4574JVSg.js → chunk-F27PBJKO-BAJ5dGzo.js} +1 -1
- package/out/renderer/assets/{chunk-IMKFNOWR-DCaKjC49.js → chunk-IMKFNOWR-Dlah_YbP.js} +1 -1
- package/out/renderer/assets/{chunk-JWPE2WC7-CbFsKOIM.js → chunk-JWPE2WC7-BiXd3nUZ.js} +1 -1
- package/out/renderer/assets/{chunk-POPQ4Y6H-B6j8RfR6.js → chunk-POPQ4Y6H-Ch86i4EJ.js} +1 -1
- package/out/renderer/assets/{chunk-SVP7TREG-kRAl0a5G.js → chunk-SVP7TREG-z3inDV-H.js} +1 -1
- package/out/renderer/assets/{chunk-TICWLB2K-BgG8vTk6.js → chunk-TICWLB2K-B34A2AKD.js} +1 -1
- package/out/renderer/assets/{chunk-XXDRQBXY-DdqB8mBq.js → chunk-XXDRQBXY-Do_L0wRR.js} +1 -1
- package/out/renderer/assets/classDiagram-ZZMXUADV-DL20WkD0.js +1 -0
- package/out/renderer/assets/classDiagram-v2-VYDZK3BY-DL20WkD0.js +1 -0
- package/out/renderer/assets/{cose-bilkent-JH36ORCC-HfctEoii.js → cose-bilkent-JH36ORCC-BQraKmgl.js} +1 -1
- package/out/renderer/assets/{cynefin-OW5HDTMX-BNigpbGU.js → cynefin-OW5HDTMX-BwixoR4r.js} +1 -1
- package/out/renderer/assets/{cynefinDiagram-5FMLGOSQ-CL-lRXZ7.js → cynefinDiagram-5FMLGOSQ-BLTBma3J.js} +1 -1
- package/out/renderer/assets/{cytoscape-fcose-B40eUKiT.js → cytoscape-fcose-BRpJ5tyq.js} +1 -1
- package/out/renderer/assets/{dagre-GXQ25YYZ-D7VwJTHe.js → dagre-GXQ25YYZ-aWsjA_wn.js} +1 -1
- package/out/renderer/assets/{diagram-S7CK7UJ4-CAp3JWMB.js → diagram-S7CK7UJ4-Cur2zK4q.js} +1 -1
- package/out/renderer/assets/{diagram-UQ7AKVKN-H_c4KXAy.js → diagram-UQ7AKVKN-DlrY8YcD.js} +1 -1
- package/out/renderer/assets/{diagram-VSXAHHWV-CsEX84Cq.js → diagram-VSXAHHWV-BBdjreqR.js} +1 -1
- package/out/renderer/assets/{diagram-VX7I27RA-ebIy3O1D.js → diagram-VX7I27RA-XiWMdc8S.js} +1 -1
- package/out/renderer/assets/{diagram-Z3DM3KII-BtVfEzv9.js → diagram-Z3DM3KII-CBB5leat.js} +1 -1
- package/out/renderer/assets/{ebnfDiagram-PWID7BFC-C25YK-UV.js → ebnfDiagram-PWID7BFC-nl8RPo8j.js} +1 -1
- package/out/renderer/assets/{erDiagram-RLTQ6QDP-1imAb8Go.js → erDiagram-RLTQ6QDP-C_oaG80x.js} +1 -1
- package/out/renderer/assets/{flowDiagram-HODETNUW-OwceYbhd.js → flowDiagram-HODETNUW-nDoVZFS7.js} +1 -1
- package/out/renderer/assets/{ganttDiagram-EL5Y4UJY-DDoN4Uki.js → ganttDiagram-EL5Y4UJY-DOrcuM3Q.js} +1 -1
- package/out/renderer/assets/{gitGraphDiagram-WWUBYQGX-yrrX43-g.js → gitGraphDiagram-WWUBYQGX-D_DB3jro.js} +1 -1
- package/out/renderer/assets/globals-Bkw7iiQG.css +1 -0
- package/out/renderer/assets/globals-D1ocHHQV.js +2533 -0
- package/out/renderer/assets/index-Cm5iq85v.js +117 -0
- package/out/renderer/assets/{infoDiagram-27XIBGKW-BoYY6yGv.js → infoDiagram-27XIBGKW-BbBrANxo.js} +1 -1
- package/out/renderer/assets/{ishikawaDiagram-5VMMS53U-BbtGOrLg.js → ishikawaDiagram-5VMMS53U-7UlfWlWV.js} +1 -1
- package/out/renderer/assets/{journeyDiagram-3NMN7TZE-BWTb58Kr.js → journeyDiagram-3NMN7TZE-CJP9bosH.js} +1 -1
- package/out/renderer/assets/{kanban-definition-UXKFOSKX-BSN2oIEH.js → kanban-definition-UXKFOSKX-D772kW7T.js} +1 -1
- package/out/renderer/assets/{layout-k2BpK8-6.js → layout-BzVfJEvx.js} +1 -1
- package/out/renderer/assets/{linear-DFArNkXT.js → linear-DBjhr05m.js} +1 -1
- package/out/renderer/assets/{mermaid.core-DthanE8x.js → mermaid.core-CJpNSowm.js} +5 -5
- package/out/renderer/assets/{mindmap-definition-YA3MSWOX-BhETDMxE.js → mindmap-definition-YA3MSWOX-C2oqlH5E.js} +1 -1
- package/out/renderer/assets/{pegDiagram-XKGWAZYB-B9w_o-Iv.js → pegDiagram-XKGWAZYB-CcZ8Hae-.js} +1 -1
- package/out/renderer/assets/{pieDiagram-E7YTZNPT-klH2bEkC.js → pieDiagram-E7YTZNPT-DTw-_k2D.js} +1 -1
- package/out/renderer/assets/{quadrantDiagram-AXDQQJYC-DerYxAqw.js → quadrantDiagram-AXDQQJYC-D5eX0DO7.js} +1 -1
- package/out/renderer/assets/{railroadDiagram-O6MQD6OU-D4EFSRd0.js → railroadDiagram-O6MQD6OU-DzpBB_Re.js} +1 -1
- package/out/renderer/assets/{requirementDiagram-BXWQKSXE-C4O9MABZ.js → requirementDiagram-BXWQKSXE-UbOUXLgl.js} +1 -1
- package/out/renderer/assets/{sankeyDiagram-P5KCCOFB-ILgR3far.js → sankeyDiagram-P5KCCOFB-jRbXLLsa.js} +1 -1
- package/out/renderer/assets/{sequenceDiagram-WJ2MYXX4-SHHY6jka.js → sequenceDiagram-WJ2MYXX4-s0WBQQPf.js} +1 -1
- package/out/renderer/assets/settings-DxYo7s4h.js +34 -0
- package/out/renderer/assets/{sizeCapture-INFHLROL-CX9hC7Eu.js → sizeCapture-INFHLROL-DvUs5rDx.js} +1 -1
- package/out/renderer/assets/{stateDiagram-D77RDMKH-CZ1zq3yT.js → stateDiagram-D77RDMKH-C1_V497y.js} +1 -1
- package/out/renderer/assets/stateDiagram-v2-MP3YSRHH-C9dfLXR8.js +1 -0
- package/out/renderer/assets/{swimlanes-42K2YHIH-BxCpUxk0.js → swimlanes-42K2YHIH-BulPeZ6y.js} +1 -1
- package/out/renderer/assets/swimlanesDiagram-VR7AAH4N-LXwy6qGO.js +8 -0
- package/out/renderer/assets/{timeline-definition-24CTP7MA-BZrSf5qo.js → timeline-definition-24CTP7MA-gQ5OygZn.js} +1 -1
- package/out/renderer/assets/{vennDiagram-4TSXK5OY-g01Cyb5O.js → vennDiagram-4TSXK5OY-A8QyA5Ix.js} +1 -1
- package/out/renderer/assets/{wardleyDiagram-VM6X3IG4-Bt_RS10y.js → wardleyDiagram-VM6X3IG4-CfP6E41T.js} +1 -1
- package/out/renderer/assets/{xychartDiagram-S5SC5T6Z-DuwmVyP6.js → xychartDiagram-S5SC5T6Z-DTG5UHh7.js} +1 -1
- package/out/renderer/index.html +3 -3
- package/out/renderer/plugin-view.html +27 -0
- package/out/renderer/settings.html +4 -4
- package/out/renderer/web-preload.js +1 -1
- package/out/server/agent.js +831 -77
- package/out/server/chunks/{agent-D37_gFfr.js → agent-BhQn6jGA.js} +330 -137
- package/out/server/chunks/{gpuBackendInstall-FekvL7Rv.js → gpuBackendInstall-CdExgjGi.js} +4 -4
- package/out/server/chunks/{loadProvider-CSeEHHnd.js → loadProvider-BnkyjMSW.js} +2 -2
- package/out/server/chunks/{manifest-Bj0K5UgY.js → manifest-2odvnxjZ.js} +97 -19
- package/out/server/chunks/{workflowPresets-DBDQwf8e.js → workflowPresets-DqSsjOj6.js} +725 -460
- package/out/server/index.js +2958 -554
- package/out/server/plugin-host.js +38 -6
- package/package.json +1 -1
- package/out/phone/assets/architecture-7GRP2DOG-_byK4-L4.js +0 -1
- package/out/phone/assets/channel-Dgd_LVvp.js +0 -1
- package/out/phone/assets/classDiagram-ZZMXUADV-C83rE770.js +0 -1
- package/out/phone/assets/classDiagram-v2-VYDZK3BY-C83rE770.js +0 -1
- package/out/phone/assets/desk-DOJjOIls.js +0 -2
- package/out/phone/assets/eventmodeling-NTZA5JFV-7mnBgbcg.js +0 -1
- package/out/phone/assets/flowDiagram-HODETNUW-sLsydHyr.js +0 -1
- package/out/phone/assets/main-CX13EK2l.js +0 -1636
- package/out/phone/assets/main-DZEEX8Mv.css +0 -1
- package/out/phone/assets/railroad-abnf-HS5TGJTU-Cm1qeEMZ.js +0 -1
- package/out/phone/assets/railroad-ebnf-LZEXJU2U-MFhpnZ_W.js +0 -1
- package/out/phone/assets/railroad-peg-WCYAUIDC-DCsilESk.js +0 -1
- package/out/phone/assets/stateDiagram-v2-MP3YSRHH-D1LtnHXy.js +0 -1
- package/out/phone/assets/swimlanesDiagram-VR7AAH4N-C2SWpfVX.js +0 -8
- package/out/renderer/assets/channel-C0GtgNRj.js +0 -1
- package/out/renderer/assets/classDiagram-ZZMXUADV-DUyds1A3.js +0 -1
- package/out/renderer/assets/classDiagram-v2-VYDZK3BY-DUyds1A3.js +0 -1
- package/out/renderer/assets/globals-C6gFTVZy.css +0 -1
- package/out/renderer/assets/globals-CYDlkaHa.js +0 -2509
- package/out/renderer/assets/index-D1rFnBbz.js +0 -116
- package/out/renderer/assets/settings-DB_fAikP.js +0 -33
- package/out/renderer/assets/stateDiagram-v2-MP3YSRHH-NCbr7wNQ.js +0 -1
- package/out/renderer/assets/swimlanesDiagram-VR7AAH4N--ymqRTT2.js +0 -8
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./globals-D1ocHHQV.js","./globals-Bkw7iiQG.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{c as Ae,w as yi,D as Wn,j as e,A as wi,r as m,u as Qr,a as Xr,b as vn,d as Zr,t as eo,C as Yn,e as H,I as Y,f as Ni,X as Ct,h as ki,i as Ci,Z as et,k as Si,S as Ii,l as Ai,m as Ei,n as Mi,o as Pi,p as z,q as j,B as I,s as fe,v as ge,x as je,y as ve,z as $e,E as we,F as Je,G as Ie,H as to,J as _e,K as Jn,L as Ti,M as Wt,N as Yt,O as se,P as ne,Q as ae,R as re,T as Q,U as Ri,V as qe,W as Oi,Y as Di,_ as so,$ as Li,a0 as ms,a1 as no,a2 as zi,a3 as ao,a4 as Bi,a5 as Qn,a6 as ro,a7 as _i,a8 as Fi,a9 as Ui,aa as Xn,ab as $i,ac as Vi,ad as Ki,ae as qi,af as Gi,ag as Hi,ah as Wi,ai as Yi,aj as Ji,ak as Qi,al as Xi,am as hs,an as Zi,ao as el,ap as tl,aq as sl,ar as nl,as as al,at as Pe,au as bn,av as Xt,aw as Le,ax as oo,ay as wt,az as ze,aA as Fe,aB as yn,aC as St,aD as wn,aE as Nn,aF as kn,aG as Cn,aH as Sn,aI as In,aJ as An,aK as Qe,aL as Zn,aM as ea,aN as Oe,aO as Ye,aP as rl,aQ as ol,aR as io,aS as le,aT as ta,aU as xs,aV as sa,aW as na,aX as aa,aY as il,aZ as ll,a_ as ps,a$ as Lt,b0 as lo,b1 as En,b2 as cl,b3 as Mn,b4 as co,b5 as dl,b6 as ul,b7 as ml,b8 as uo,b9 as hl,ba as xl,bb as pl,bc as mo,bd as At,be as Ut,bf as fl,bg as Pn,bh as gl,bi as jl,bj as Tn,bk as tt,bl as vl,bm as bl,bn as ho,bo as yl,bp as wl,bq as Nl,br as xo,bs as Rn,bt as Te,bu as te,bv as Ee,bw as kl,bx as Cl,by as Sl,bz as Il,bA as Al,bB as ra,bC as El,bD as Ml,bE as zt,bF as Bt,bG as Ke,bH as Tt,bI as an,bJ as Pl,bK as Tl,bL as rn,bM as it,bN as po,bO as Rl,bP as Ol,bQ as fo,bR as Dl,bS as oa,bT as go,bU as Ll,bV as zl,bW as jo,bX as Be,bY as Bl,bZ as Zt,b_ as _l,b$ as ia,c0 as Fl,c1 as Ul,c2 as $l,c3 as He,c4 as Vl,c5 as la,c6 as ca,c7 as Kl,c8 as da,c9 as ql,ca as Gl,cb as Hl,cc as Wl,cd as Ue,ce as fs,cf as ua,cg as Yl,ch as vo,ci as Jl,cj as bo,ck as Ql,cl as Xl,cm as Zl,cn as ec,co as On,cp as tc,cq as yo,cr as sc,cs as nc,ct as _t,cu as ac,cv as rc,cw as oc,g as ic,cx as on,cy as wo,cz as $t,cA as lc,cB as cc,cC as ue,cD as me,cE as rs,cF as Dn,cG as Ln,cH as dc,cI as ma,cJ as ha,cK as xa,cL as uc,cM as mc,cN as hc,cO as xc,cP as pc,cQ as fc,cR as gc,cS as jc,cT as vc,cU as bc,cV as yc,cW as wc,cX as pa,cY as No,cZ as ko,c_ as Co,c$ as So,d0 as Nc,d1 as kc,d2 as It,d3 as Io,d4 as Ao,d5 as Eo,d6 as Cc,d7 as Sc,d8 as Ic,d9 as Nt,da as Jt,db as Ac,dc as Ec,dd as Mc,de as Pc,df as Tc,dg as Rc,dh as Oc,di as Dc,dj as Lc,dk as zc,dl as Bc,dm as ln,dn as _c,dp as es,dq as Fc,dr as zn,ds as Mo,dt as Po,du as Bn,dv as To,dw as Ro,dx as Oo,dy as Do,dz as Lo,dA as Uc,dB as _n,dC as $c,dD as Vc,dE as Kc,dF as qc,dG as Gc,dH as Hc,dI as Wc,dJ as Yc,dK as Jc,dL as Qc,dM as Xc,dN as Zc,dO as ed,dP as td,dQ as sd,dR as zo,dS as Bo,dT as _o,dU as nd,dV as Fo,dW as ad,dX as rd,dY as od,dZ as Uo,d_ as id,d$ as ld,e0 as cd,e1 as dd,e2 as ts,e3 as ud,e4 as md,e5 as hd,e6 as xd,e7 as nt,e8 as pd,e9 as $o,ea as fd,eb as gd,ec as jd,ed as vd,ee as bd,ef as yd,eg as wd,eh as Nd,ei as kd,ej as Cd,ek as Vo,el as Sd,em as Id,en as Ad,eo as Ed,ep as Md,eq as Pd,er as Td,es as Rd,et as Od,eu as Dd,ev as Ld,ew as zd,ex as Bd,ey as _d,ez as Fd,eA as Ud,eB as fa,eC as $d,eD as ga,eE as Vd,eF as ja,eG as Kd}from"./globals-D1ocHHQV.js";import{c as Ko}from"./cytoscape.esm-DzSz-X2X.js";import{f as qd}from"./cytoscape-fcose-BRpJ5tyq.js";const Gd=[["path",{d:"M10 22V7a1 1 0 0 0-1-1H4a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-5a1 1 0 0 0-1-1H2",key:"1ah6g2"}],["rect",{x:"14",y:"2",width:"8",height:"8",rx:"1",key:"88lufb"}]],Hd=Ae("blocks",Gd);const Wd=[["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"}]],Yd=Ae("book-open",Wd);const Jd=[["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"}]],Qd=Ae("box",Jd);const Xd=[["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"}]],Zd=Ae("chart-column",Xd);const eu=[["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"}]],tu=Ae("file-archive",eu);const su=[["path",{d:"M14.364 13.634a2 2 0 0 0-.506.854l-.837 2.87a.5.5 0 0 0 .62.62l2.87-.837a2 2 0 0 0 .854-.506l4.013-4.009a1 1 0 0 0-3.004-3.004z",key:"ukzhwg"}],["path",{d:"M14.487 7.858A1 1 0 0 1 14 7V2",key:"1klhew"}],["path",{d:"M20 19.645V20a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l2.516 2.516",key:"rxaxab"}],["path",{d:"M8 18h1",key:"13wk12"}]],nu=Ae("file-pen-line",su);const au=[["path",{d:"M4 22V4a1 1 0 0 1 .4-.8A6 6 0 0 1 8 2c3 0 5 2 7.333 2q2 0 3.067-.8A1 1 0 0 1 20 4v10a1 1 0 0 1-.4.8A6 6 0 0 1 16 16c-3 0-5-2-8-2a6 6 0 0 0-4 1.528",key:"1jaruq"}]],ru=Ae("flag",au);const ou=[["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"}]],iu=Ae("fold-vertical",ou);const lu=[["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"}]],va=Ae("heart",lu);const cu=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}]],du=Ae("image",cu);const uu=[["path",{d:"M9 17H7A5 5 0 0 1 7 7h2",key:"8i5ue5"}],["path",{d:"M15 7h2a5 5 0 1 1 0 10h-2",key:"1b9ql8"}],["line",{x1:"8",x2:"16",y1:"12",y2:"12",key:"1jonct"}]],qo=Ae("link-2",uu);const mu=[["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"}]],Go=Ae("lock-keyhole",mu);const hu=[["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"}]],xu=Ae("palette",hu);const pu=[["path",{d:"m15 15 6 6m-6-6v4.8m0-4.8h4.8",key:"17vawe"}],["path",{d:"M9 19.8V15m0 0H4.2M9 15l-6 6",key:"chjx8e"}],["path",{d:"M15 4.2V9m0 0h4.8M15 9l6-6",key:"lav6yq"}],["path",{d:"M9 4.2V9m0 0H4.2M9 9 3 3",key:"1pxi2q"}]],fu=Ae("shrink",pu);const gu=[["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"}]],ju=Ae("store",gu);const vu=[["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"}]],bu=Ae("sun",vu);const yu=[["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"}]],Ho=Ae("upload",yu);function wu(t){return t&&typeof t=="object"&&!Array.isArray(t)?t:null}function Nu(t){try{const s=new URL(t);return(s.protocol==="http:"||s.protocol==="https:")&&!s.username&&!s.password&&!s.search&&!s.hash&&!t.includes("?")&&!t.includes("#")}catch{return!1}}function ku(t){const s=wu(t);if(!s||Object.keys(s).some(u=>!["providerId","modelId","protocol","baseUrl","apiKey"].includes(u)))return null;const{providerId:n,modelId:a,protocol:r,baseUrl:o,apiKey:i}=s;return typeof n!="string"||!n.trim()||typeof a!="string"||!a.trim()||typeof i!="string"||!i.trim()||typeof o!="string"||!Nu(o)||r!=="openai"&&r!=="openai-compatible"&&r!=="gemini"?null:{providerId:n,modelId:a,protocol:r,baseUrl:o,apiKey:i}}function Cu(t,s){if(t?.enabled!==!0||t.oauthAccountKey||t.oauthAccountPool||typeof t.apiKey!="string"||!t.apiKey.trim()||typeof t.baseUrl!="string")return null;let n;if(t.api==="google-generative-ai")n="gemini";else if(t.api==="openai-completions"||t.api==="openai-responses"){let o="";try{o=new URL(t.baseUrl).hostname.toLowerCase()}catch{}n=t.catalogId!=="__custom"&&(t.catalogId==="openai"||!t.catalogId&&o==="api.openai.com")?"openai":"openai-compatible"}else return null;const a=n==="gemini"?Wn["google-generative-ai"]:n==="openai"?Wn["openai-responses"]:"";let r=t.baseUrl.trim().replace(/\/+$/,"")||a;if(n==="gemini"&&r&&(r=yi(r,"v1beta")),n==="openai"&&r)try{new URL(r).pathname==="/"&&(r=`${r}/v1`)}catch{}return ku({providerId:t.id,modelId:s,protocol:n,baseUrl:r,apiKey:t.apiKey})}function Su(t){return Array.isArray(t?.models)?t.models.filter(s=>!!s&&typeof s=="object"&&typeof s.id=="string"&&!!s.id.trim()&&s.enabled!==!1&&s.imageGeneration===!0):[]}function Iu(t){return t.flatMap(s=>{const n=Su(s).filter(a=>Cu(s,a.id));return n.length?[{...s,models:n}]:[]})}function Au(t){const{multiple:s=!1,defaultValue:n,value:a,onValueChange:r,autoComplete:o,...i}=t;return e.jsx(wi,{...i,selectionMode:s?"multiple":"single",selectedValue:a,defaultSelectedValue:n,onSelectedValueChange:r,formAutoComplete:o})}const Eu=m.forwardRef(function(s,n){const{selected:a}=Qr();return s.keepMounted||a?e.jsx(Mu,{...s,ref:n}):null}),Mu=m.memo(m.forwardRef((t,s)=>{const{render:n,className:a,style:r,keepMounted:o,...i}=t,{selected:u}=Qr(),d=m.useRef(null),{transitionStatus:x,setMounted:h}=Xr(u),f=vn("span",t,{ref:[s,d],state:{selected:u,transitionStatus:x},props:[{"aria-hidden":!0,children:"✔️"},i],stateAttributesMapping:eo});return Zr({open:u,ref:d,onComplete(){u||h(!1)}}),f})),Fn=m.createContext({chipsRef:null,multiple:!1,rootRef:null});function Pu(t){const s=m.useRef(null),n=m.useRef(null);return e.jsx(Fn.Provider,{value:{chipsRef:s,multiple:!!t.multiple,rootRef:n},children:e.jsx("div",{ref:n,className:"contents",children:e.jsx(Au,{...t})})})}function Tu({className:t,showTrigger:s=!0,showClear:n=!1,startAddon:a,size:r,...o}){const{multiple:i}=m.useContext(Fn),u=r??"default";return i?e.jsx(Yn,{className:H("min-w-12 flex-1 text-base outline-none sm:text-sm [[data-slot=combobox-chip]+&]:ps-0.5",u==="sm"?"ps-1.5":"ps-2",t),"data-size":typeof u=="string"?u:void 0,"data-slot":"combobox-input",size:typeof u=="number"?u:void 0,...o}):e.jsxs("div",{className:"relative w-full has-disabled:opacity-64",children:[a&&e.jsx("div",{"aria-hidden":"true",className:"[&_svg]:-mx-0.5 pointer-events-none absolute inset-y-0 start-px z-10 flex items-center ps-[calc(--spacing(3)-1px)] opacity-80 has-[+[data-size=sm]]:ps-[calc(--spacing(2.5)-1px)] [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4","data-slot":"combobox-start-addon",children:a}),e.jsx(Yn,{className:H(a&&"data-[size=sm]:*:data-[slot=combobox-input]:ps-[calc(--spacing(7.5)-1px)] *:data-[slot=combobox-input]:ps-[calc(--spacing(8.5)-1px)] sm:data-[size=sm]:*:data-[slot=combobox-input]:ps-[calc(--spacing(7)-1px)] sm:*:data-[slot=combobox-input]:ps-[calc(--spacing(8)-1px)]",u==="sm"?"has-[+[data-slot=combobox-trigger],+[data-slot=combobox-clear]]:*:data-[slot=combobox-input]:pe-6.5":"has-[+[data-slot=combobox-trigger],+[data-slot=combobox-clear]]:*:data-[slot=combobox-input]:pe-7",t),"data-slot":"combobox-input",render:e.jsx(Y,{className:"has-disabled:opacity-100",size:u}),...o}),s&&e.jsx(Ru,{className:H("-translate-y-1/2 absolute top-1/2 inline-flex size-8 shrink-0 cursor-pointer items-center justify-center rounded-md border border-transparent opacity-80 outline-none transition-opacity pointer-coarse:after:absolute pointer-coarse:after:min-h-11 pointer-coarse:after:min-w-11 hover:opacity-100 has-[+[data-slot=combobox-clear]]:hidden sm:size-7 [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",u==="sm"?"end-0":"end-0.5"),children:e.jsx(Ni,{})}),n&&e.jsx(zu,{className:H("-translate-y-1/2 absolute top-1/2 inline-flex size-8 shrink-0 cursor-pointer items-center justify-center rounded-md border border-transparent opacity-80 outline-none transition-opacity pointer-coarse:after:absolute pointer-coarse:after:min-h-11 pointer-coarse:after:min-w-11 hover:opacity-100 has-[+[data-slot=combobox-clear]]:hidden sm:size-7 [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",u==="sm"?"end-0":"end-0.5"),children:e.jsx(Ct,{})})]})}function Ru({className:t,...s}){return e.jsx(Mi,{className:t,"data-slot":"combobox-trigger",...s})}function Ou({className:t,children:s,sideOffset:n=4,zIndex:a,...r}){const{chipsRef:o,rootRef:i}=m.useContext(Fn);let u=et.DROPDOWN;if(a!==void 0)u=a;else{const d=i?.current;d&&(d.closest('[data-slot="dialog-popup"] [data-slot="dialog-popup"]')?u=et.DROPDOWN_IN_NESTED_MODAL:d.closest('[data-slot="dialog-popup"]')&&(u=et.DROPDOWN_IN_MODAL))}return e.jsx(ki,{children:e.jsx(Ci,{anchor:o,className:"select-none",style:{zIndex:u},"data-slot":"combobox-positioner",sideOffset:n,children:e.jsx("span",{className:H("relative flex max-h-full origin-(--transform-origin) rounded-lg border bg-popover bg-clip-padding transition-[scale,opacity] before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-lg)-1px)] before:shadow-lg has-data-starting-style:scale-98 has-data-starting-style:opacity-0 dark:not-in-data-[slot=group]:bg-clip-border",t),children:e.jsx(Si,{className:"flex max-h-[min(var(--available-height),23rem)] w-(--anchor-width) max-w-(--available-width) flex-col","data-slot":"combobox-popup",...r,children:s})})})})}function Du({className:t,children:s,endAddon:n,...a}){return e.jsxs(Ei,{className:H("grid min-h-8 in-data-[side=none]:min-w-[calc(var(--anchor-width)+1.25rem)] cursor-default grid-cols-[1rem_1fr_auto] items-center gap-2 rounded-sm py-1 ps-2 pe-4 text-base outline-none data-disabled:pointer-events-none data-highlighted:bg-accent data-highlighted:text-accent-foreground data-disabled:opacity-64 sm:min-h-7 sm:text-sm [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",t),"data-slot":"combobox-item",...a,children:[e.jsx(Eu,{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:s}),n&&e.jsx("div",{className:"col-start-3 flex items-center",children:n})]})}function Lu({className:t,...s}){return e.jsx(Ii,{scrollbarGutter:!0,scrollFade:!0,children:e.jsx(Ai,{className:H("not-empty:scroll-py-1 not-empty:px-1 not-empty:py-1 in-data-has-overflow-y:pe-3",t),"data-slot":"combobox-list",...s})})}function zu({className:t,...s}){return e.jsx(Pi,{className:t,"data-slot":"combobox-clear",...s})}function Bu(){const{t}=z(),s=j(l=>l.contextMenuOpen),n=j(l=>l.setContextMenuOpen),[a,r]=m.useState(!1),[o,i]=m.useState(!1),u=l=>l.target==="reveal"?t("File manager"):l.target==="vscode"?t("VS Code"):l.applicationPath.split(/[/\\]/).at(-1)?.replace(/\.(exe|app)$/i,"")||l.applicationPath,d=s.filter(l=>l.enabled).map(u),x=d.length?`${d.slice(0,2).join(", ")}${d.length>2?` +${d.length-2}`:""}`:t("No opening methods enabled"),h=l=>{if(l.length>32){_e({type:"error",title:t("Context menu opening"),description:t("You can configure up to 32 opening methods.")});return}n(l)},c=(l,p)=>{const g=j.getState().contextMenuOpen;n(g.map(w=>w.id===l.id?{...w,enabled:p}:w))},f=async()=>{i(!0);try{const l=await window.electronAPI.dialog.selectFile();if(!l)return;if(!to(l)){_e({type:"error",title:t("Context menu opening"),description:t("The selected application path is invalid.")});return}const p=j.getState().contextMenuOpen,g=Jn(l),w=p.find(C=>C.target==="application"&&Jn(C.applicationPath)===g);if(w){h(p.map(C=>C.id===w.id?{...C,enabled:!0}:C));return}h([...p,{id:crypto.randomUUID(),target:"application",applicationPath:l,enabled:!0}])}catch(l){_e({type:"error",title:t("Context menu opening"),description:l instanceof Error?l.message:String(l)})}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:t("Context menu opening")}),e.jsx(I,{variant:"outline",size:"sm",onClick:()=>r(!0),children:t("Configure list")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Select the opening methods shown in file link context menus. You can add multiple applications.")}),e.jsx("p",{className:"truncate text-xs text-muted-foreground",title:d.join(", "),children:x}),e.jsx(fe,{open:a,onOpenChange:r,children:e.jsxs(ge,{zIndexLevel:"nested",children:[e.jsxs(je,{children:[e.jsx(ve,{children:t("Context menu opening")}),e.jsx($e,{children:t("Select the opening methods shown in file link context menus. You can add multiple applications.")})]}),e.jsxs(we,{className:"space-y-2",children:[s.length===0&&e.jsx("p",{className:"py-6 text-center text-sm text-muted-foreground",children:t("No opening methods enabled")}),s.map(l=>{const p=u(l);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(Je,{checked:l.enabled,disabled:o,"aria-label":p,onCheckedChange:g=>c(l,g)}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-sm",title:p,children:p}),l.target==="application"&&e.jsx("span",{className:"block truncate text-xs text-muted-foreground",title:l.applicationPath,children:l.applicationPath})]})]}),e.jsx(I,{variant:"ghost",size:"sm",disabled:o,onClick:()=>n(j.getState().contextMenuOpen.filter(g=>g.id!==l.id)),children:t("Delete")})]},l.id)})]}),e.jsxs(Ie,{children:[e.jsx(I,{variant:"outline",disabled:o,onClick:()=>{f()},children:t("Add application")}),e.jsx(I,{onClick:()=>r(!1),children:t("Close")})]})]})})]})}const ba=["internal","reveal","system","application"];function ya({extension:t,value:s,disabled:n,onChange:a}){const{t:r}=z(),o={internal:r("Open inside EnsoCode"),reveal:r("Reveal in file manager"),system:r("System default application"),application:r("Selected application")},i=Wt(`file${t}`),u=Yt(`file${t}`)!==null,d=i?u?["internal","reveal"]:["reveal"]:ba,x=i&&(!u||s==="system"||s==="application")?"reveal":s;return e.jsxs(se,{items:Object.fromEntries(d.map(h=>[h,o[h]])),value:x,disabled:n,onValueChange:h=>{ba.includes(h)&&a(h)},children:[e.jsx(ne,{className:"w-52","aria-label":r("File opening"),children:e.jsx(ae,{})}),e.jsx(re,{children:d.map(h=>e.jsx(Q,{value:h,disabled:h==="internal"&&!u,children:o[h]},h))})]})}function _u(){const{t}=z(),s=j(N=>N.fileOpenRules),n=j(N=>N.setFileOpenRules),[a,r]=m.useState(""),[o,i]=m.useState("internal"),[u,d]=m.useState(),[x,h]=m.useState(null),[c,f]=m.useState(!1),l=Ti([{extension:a,target:"reveal"}])[0]?.extension,p=N=>{_e({type:"error",title:t("File opening"),description:N})},g=async N=>{f(!0);try{const y=await window.electronAPI.dialog.selectFile();if(y){if(!to(y)){p(t("The selected application path is invalid."));return}N(y)}}catch(y){p(y instanceof Error?y.message:String(y))}finally{f(!1)}},w=N=>{const y=Ri(N);return y?(n(y),!0):(p(t("Could not complete the file action.")),!1)},C=(N,y,S)=>{if(y==="internal"&&!Yt(`file${N.extension}`)){p(t("This extension does not support internal preview."));return}w(s.map(D=>D.extension===N.extension?{extension:N.extension,target:y,...y==="application"?{applicationPath:S}:{}}:D))},b=()=>{if(!l){h(t("Enter a valid file extension, for example .md."));return}if(s.some(D=>D.extension===l)){h(t("This extension already has an opening rule."));return}const N=Wt(`file${l}`),y=Yt(`file${l}`)!==null,S=N&&(!y||o==="system"||o==="application")?"reveal":o;if(S==="internal"&&!Yt(`file${l}`)){p(t("This extension does not support internal preview."));return}if(S==="application"&&!u){h(t("Choose an application before saving this rule."));return}w([...s,{extension:l,target:S,...S==="application"?{applicationPath:u}:{}}])&&(r(""),d(void 0),h(null))};return e.jsxs("section",{className:"space-y-3","data-settings-row":"appearance.fileOpening",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium",children:t("File opening")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Configure how local workspace file links open by extension.")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("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:t("Executable and installer files are always revealed in the file manager.")})]}),e.jsx(Bu,{}),s.map(N=>e.jsxs("div",{className:"flex flex-wrap items-center gap-2 rounded-md border px-3 py-2",children:[e.jsx("span",{className:"w-20 shrink-0 font-mono text-sm",children:N.extension}),e.jsx(ya,{extension:N.extension,value:N.target,disabled:c,onChange:y=>{y==="application"?g(S=>C(N,y,S)):C(N,y)}}),N.target==="application"&&!Wt(`file${N.extension}`)&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-xs text-muted-foreground",title:N.applicationPath,children:N.applicationPath}),e.jsx(I,{variant:"outline",size:"sm",disabled:c,onClick:()=>{g(y=>C(N,"application",y))},children:t("Choose application")})]}),e.jsx(I,{variant:"ghost",size:"sm",disabled:c,onClick:()=>w(s.filter(y=>y.extension!==N.extension)),children:t("Delete")})]},N.extension)),e.jsxs("div",{className:"space-y-2 rounded-md border p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(Y,{className:"w-24",value:a,placeholder:".md","aria-label":t("File extension"),disabled:c,onChange:N=>{r(N.target.value),h(null)},onKeyDown:N=>{N.key==="Enter"&&b()}}),e.jsx(ya,{extension:l??".md",value:o,disabled:c,onChange:N=>{i(N),h(null)}}),e.jsx(I,{variant:"outline",size:"sm",disabled:c,onClick:b,children:t("Add")})]}),o==="application"&&!Wt(`file${l??".md"}`)&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(I,{variant:"outline",size:"sm",disabled:c,onClick:()=>{g(N=>{d(N),h(null)})},children:t("Choose application")}),e.jsx("span",{className:"min-w-0 truncate text-xs text-muted-foreground",title:u,children:u})]}),x&&e.jsx("p",{role:"alert",className:"text-xs text-destructive",children:x})]})]})}function Fu(t){return/^\//.test(t)||/^[A-Za-z]:[\\/]/.test(t)||/^\\\\[^\\]/.test(t)}const Uu=16384,Wo=4096,Yo=65536;function $u(t){return t===null?null:typeof t=="number"&&Number.isInteger(t)&&t>=Wo&&t<=Yo?t:void 0}function Vu(t){const s=t.trim();return s?/^\d+$/.test(s)?$u(Number(s)):void 0:null}function Ku(){const{t}=z(),[s,n]=m.useState(null),[a,r]=m.useState(""),[o,i]=m.useState(null);m.useEffect(()=>{let d=!1;return window.electronAPI.compaction.getReserveTokens().then(x=>{d||(n(x),r(x===null?"":String(x)))}),()=>{d=!0}},[]);const u=async()=>{const d=Vu(a);if(d===void 0){i(t("Enter a whole number between {{min}} and {{max}}, or leave it empty.",{min:Wo,max:Yo}));return}if(i(null),d===s)return;if(!(await window.electronAPI.compaction.setReserveTokens(d)).ok){i(t("Could not save. Check that pi-agent/settings.json is valid JSON."));return}n(d),r(d===null?"":String(d))};return e.jsxs("div",{className:"flex items-start justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.compactReserveTokens",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"text-sm",children:[t("Compaction reserve tokens"),e.jsx(qe,{})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Compaction runs when context exceeds the model window minus this value. Larger values compact earlier. Do not set it close to the window of small-context models, or every request compacts first. Leave empty for the default.")})]}),e.jsxs("div",{className:"w-32 shrink-0 space-y-1",children:[e.jsx(Y,{inputMode:"numeric",value:a,placeholder:String(Uu),"aria-label":t("Compaction reserve tokens"),onChange:d=>r(d.target.value),onBlur:()=>{u()},onKeyDown:d=>{d.key==="Enter"&&u()}}),o&&e.jsx("p",{className:"text-xs text-destructive",children:o})]})]})}function cn({className:t,render:s,...n}){const a={className:H("inline-flex items-center gap-2 text-base/4.5 sm:text-sm/4 font-medium",t),"data-slot":"label"};return Oi({defaultTagName:"label",props:Di(a,n),render:s})}const dn={checked(t){return t?{"data-checked":""}:{"data-unchecked":""}},...eo,...so},Jo=m.createContext(void 0);function qu(){return m.useContext(Jo)}const Qo=m.createContext(void 0);function Gu(){const t=m.useContext(Qo);if(t===void 0)throw new Error(Li(52));return t}const Hu=m.forwardRef(function(s,n){const{render:a,className:r,disabled:o=!1,readOnly:i=!1,required:u=!1,"aria-labelledby":d,value:x,inputRef:h,nativeButton:c=!1,id:f,style:l,...p}=s,g=qu(),{disabled:w,readOnly:C,required:b,form:N,checkedValue:y,touched:S=!1,validation:D,name:k,setCheckedValue:O=ms,setTouched:E=ms,registerInputRef:M=ms}=g??{},{setTouched:A,setFilled:F,state:V,disabled:v}=no(),U=zi(),{labelId:L,getDescriptionProps:K}=ao(),$=v||U.disabled||w||o,G=C||i,X=b||u,oe=N,q=g?y===x:x==="",ie=m.useRef(null),B=m.useRef(null),ee=D?.registerInput,R=m.useCallback(xe=>ee?.(xe,{controlRef:ie,value:void 0}),[ee]),P=Bi(h,B,M,R);Qn(()=>{B.current?.checked&&F(!0)},[F]),Qn(()=>{if(B.current){if($&&q){M(null);return}M(B.current)}},[q,$,M]);const ce=ro(),pe=_i({id:f,implicit:!1,controlRef:ie}),Ne=c?void 0:pe,Ve=Fi(d,L,B,!c,Ne),_={role:"radio","aria-checked":q,"aria-labelledby":Ve,[Hi]:q?"":void 0,id:c?pe:ce,onKeyDown(xe){xe.key==="Enter"&&xe.preventDefault()},onClick(xe){if(xe.defaultPrevented||$||G)return;xe.preventDefault();const st=B.current;st&&Gi(st,xe)},onFocus(xe){xe.defaultPrevented||$||G||!S||(B.current?.click(),E(!1))}},{getButtonProps:Z,buttonRef:J}=Ui({disabled:$,native:c,composite:!1}),he={type:"radio",ref:P,form:oe,id:Ne,name:k,tabIndex:-1,style:k?Ki:qi,"aria-hidden":!0,...x!==void 0?{value:$i(x)}:Xn,disabled:$,checked:q,required:X,readOnly:G,onChange(xe){if(xe.nativeEvent.defaultPrevented||$||G||x===void 0)return;const st=Wi(Yi,xe.nativeEvent);O(x,st),!st.isCanceled&&A(!0)},onClick(xe){xe.stopPropagation()},onFocus(){ie.current?.focus()}},ke=m.useMemo(()=>({...V,required:X,disabled:$,readOnly:G,checked:q}),[V,$,G,q,X]),xt=ke,W=g!==void 0,Ce=[n,ie,J],Se=[_,p,Z,K,D?xe=>D.getValidationProps($,xe):Xn],De=vn("span",s,{enabled:!W,state:ke,ref:Ce,props:Se,stateAttributesMapping:dn});return e.jsxs(Qo.Provider,{value:xt,children:[W?e.jsx(Vi,{tag:"span",render:a,className:r,style:l,state:ke,refs:Ce,props:Se,stateAttributesMapping:dn}):De,e.jsx("input",{...he,suppressHydrationWarning:!0})]})}),Wu=m.forwardRef(function(s,n){const{render:a,className:r,style:o,keepMounted:i=!1,...u}=s,d=Gu(),x=d.checked,{mounted:h,transitionStatus:c,setMounted:f}=Xr(x),l={...d,transitionStatus:c},p=m.useRef(null),g=i||h,w=vn("span",s,{ref:[n,p],state:l,props:u,stateAttributesMapping:dn});return Zr({open:x,ref:p,onComplete(){x||f(!1)}}),g?w:null}),Yu=[nl],Ju=m.forwardRef(function(s,n){const{render:a,className:r,disabled:o,readOnly:i,required:u,onValueChange:d,value:x,defaultValue:h,form:c,name:f,inputRef:l,id:p,style:g,...w}=s,{setTouched:C,setFocused:b,validationMode:N,name:y,disabled:S,state:D,validation:k,setDirty:O,setFilled:E,validityData:M}=no(),{labelId:A}=ao(),{clearErrors:F,elementRef:V}=Ji(),v=Qi(!0),U=S||o,L=y??f,K=ro(p),[$,G]=Xi({controlled:x,default:h,name:"RadioGroup",state:"value"}),[X,oe]=m.useState(!1),q=hs((J,he)=>{d?.(J,he),!he.isCanceled&&G(J)}),ie=k.getInputControl,B=m.useMemo(()=>({get current(){return ie()}}),[ie]),ee=m.useRef(null),R=m.useRef(null);function P(J){let he;return l&&(typeof l=="function"?he=l(J):l.current=J),ee.current=J,he}const ce=hs(J=>{if(!J||J.disabled)return;R.current||(R.current=J);const he=ee.current,ke=J.checked||he==null||he.disabled?P(J):void 0;return()=>{R.current===J&&(R.current=null),ee.current===J?ke?(ke(),ee.current=null):P(null):ke?.()}}),pe=hs(()=>{const J=V.current;if(!J)return $??null;for(const he of k.registeredInputs.keys())if(he.checked&&Zi(he,J))return $??null;return null});el(B,K,$??null,pe,!U,f),tl($,()=>{F(L),O($!==M.initialValue),E($!=null),k.change($);const J=R.current;$==null&&J&&!J.disabled&&P(J)});const Ne=A??v?.legendId,Ve={...D,disabled:U??!1,required:u??!1,readOnly:i??!1},_=m.useMemo(()=>({checkedValue:$,disabled:U,form:c,validation:k,name:L,readOnly:i,registerInputRef:ce,required:u,setCheckedValue:q,setTouched:oe,touched:X}),[$,U,c,k,L,i,ce,u,q,oe,X]),Z={id:p,role:"radiogroup","aria-required":u||void 0,"aria-disabled":U||void 0,"aria-readonly":i||void 0,"aria-labelledby":Ne,onFocus(){b(!0)},onBlur(J){al(J.currentTarget,J.relatedTarget)||(C(!0),b(!1),N==="onBlur"&&k.commit($))},onKeyDownCapture(J){J.key.startsWith("Arrow")&&(oe(!0),b(!0))}};return e.jsx(Jo.Provider,{value:_,children:e.jsx(sl,{render:a,className:r,style:g,state:Ve,props:[Z,w,J=>k.getValidationProps(U??!1,J)],refs:[n],stateAttributesMapping:so,enableHomeAndEndKeys:!1,modifierKeys:Yu})})});function Qu({className:t,...s}){return e.jsx(Ju,{className:H("flex flex-col gap-3",t),"data-slot":"radio-group",...s})}function wa({className:t,...s}){return e.jsx(Hu,{className:H("relative inline-flex size-4.5 shrink-0 items-center justify-center rounded-full border border-input bg-background bg-clip-padding shadow-xs outline-none transition-shadow before:pointer-events-none before:absolute before:inset-0 before:rounded-full not-data-disabled:not-data-checked:not-aria-invalid:before:shadow-[0_1px_--theme(--color-black/4%)] focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background aria-invalid:border-destructive/36 focus-visible:aria-invalid:border-destructive/64 focus-visible:aria-invalid:ring-destructive/48 data-disabled:opacity-64 sm:size-4 dark:not-data-checked:bg-input/32 dark:bg-clip-border dark:aria-invalid:ring-destructive/24 dark:not-data-disabled:not-data-checked:not-aria-invalid:before:shadow-[0_-1px_--theme(--color-white/8%)] [[data-disabled],[data-checked],[aria-invalid]]:shadow-none",t),"data-slot":"radio",...s,children:e.jsx(Wu,{className:"-inset-px absolute flex size-4.5 items-center justify-center rounded-full before:size-2 before:rounded-full before:bg-primary-foreground data-unchecked:hidden data-checked:bg-primary sm:size-4 sm:before:size-1.5","data-slot":"radio-indicator"})})}const Xu=[{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 Zu(){const{t}=z(),[s,n]=m.useState(!1),[a,r]=m.useState(!1),[o,i]=m.useState(null),[u,d]=m.useState(null),x=()=>{i(null),n(!0)},h=async()=>{r(!0),i(null);try{const c=await window.electronAPI.configSync.openImport();if(!c.ok){i({kind:c.cancelled?"cancelled":"error",text:c.cancelled?t("Import cancelled."):t(c.error)});return}d(c)}catch{i({kind:"error",text:t("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:t("Configuration transfer")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("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(tu,{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:t("Portable Enso configuration")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Export a package or preview one before importing it.")})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsxs(I,{variant:"outline",size:"sm",disabled:a,onClick:h,children:[a?e.jsx(Pe,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(bn,{className:"h-3.5 w-3.5"}),t("Import configuration")]}),e.jsxs(I,{size:"sm",disabled:a,onClick:x,children:[e.jsx(Ho,{className:"h-3.5 w-3.5"}),t("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(Xt,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),e.jsx("p",{children:t("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(em,{open:s,onOpenChange:n}),u&&e.jsx(tm,{file:u,onClose:()=>d(null)})]})}function em({open:t,onOpenChange:s}){const{t:n}=z(),[a,r]=m.useState(!1),[o,i]=m.useState(""),[u,d]=m.useState(""),[x,h]=m.useState(!1),[c,f]=m.useState(null),[l,p]=m.useState(!1),[g,w]=m.useState(null),[C,b]=m.useState([]);m.useEffect(()=>{t&&(r(!1),i(""),d(""),h(!1),f(null),p(!1),w(null),b([]))},[t]);const N=()=>{x||(i(""),d(""),s(!1))},y=async()=>{if(a&&o.length<8){f(n("Password must be at least 8 characters."));return}if(a&&o!==u){f(n("Passwords do not match."));return}h(!0),f(null),p(!1);try{const S=await window.electronAPI.configSync.exportConfig({includeSecrets:a,...a?{password:o}:{}});if(i(""),d(""),!S.ok){S.cancelled?p(!0):f(n(S.error));return}w(S.filePath),b(S.skippedInstructions??[])}catch{i(""),d(""),f(n("Could not export configuration."))}finally{h(!1)}};return e.jsx(fe,{open:t,onOpenChange:S=>!S&&N(),children:e.jsxs(ge,{className:"max-w-xl",showCloseButton:!x,children:[e.jsxs(je,{children:[e.jsx(ve,{children:n("Export configuration")}),e.jsx($e,{children:n("Create a portable .enso-config package for another device.")})]}),e.jsx(we,{className:"max-h-[55vh] space-y-4",children:g?e.jsxs(e.Fragment,{children:[e.jsxs(Le,{variant:"success",children:[e.jsx(oo,{}),e.jsx(wt,{children:n("Configuration exported")}),e.jsxs(ze,{children:[e.jsx("p",{children:n("Saved package:")}),e.jsx("p",{className:"break-all font-mono text-xs text-foreground",children:g})]})]}),C.length>0&&e.jsxs(Le,{variant:"warning",children:[e.jsx(Fe,{}),e.jsxs(ze,{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:C.join(", ")})]})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs(Le,{variant:"warning",children:[e.jsx(yn,{}),e.jsx(wt,{children:n("File contents can be private")}),e.jsx(ze,{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(Je,{checked:a,onCheckedChange:S=>{const D=S===!0;r(D),f(null),D||(i(""),d(""))}}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-sm font-medium",children:n("Include sensitive configuration")}),e.jsx("span",{className:"mt-0.5 block text-xs text-muted-foreground",children:n("Encrypt the entire package with a password. OAuth login sessions are still excluded.")})]})]}),!a&&e.jsxs(Le,{variant:"info",children:[e.jsx(Xt,{}),e.jsx(ze,{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(Go,{className:"h-4 w-4 text-muted-foreground"}),n("Encryption password")]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(cn,{htmlFor:"config-export-password",children:n("Password")}),e.jsx(Y,{id:"config-export-password",type:"password",autoComplete:"new-password",value:o,"aria-invalid":!!(c&&o.length<8),onChange:S=>{i(S.target.value),f(null)}})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(cn,{htmlFor:"config-export-confirmation",children:n("Confirm password")}),e.jsx(Y,{id:"config-export-confirmation",type:"password",autoComplete:"new-password",value:u,"aria-invalid":!!(c&&u!==o),onChange:S=>{d(S.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.")})]}),l&&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(St,{className:"h-3.5 w-3.5 shrink-0"}),c]})]})}),e.jsx(Ie,{children:g?e.jsx(I,{size:"sm",onClick:N,children:n("Done")}):e.jsxs(e.Fragment,{children:[e.jsx(I,{variant:"outline",size:"sm",disabled:x,onClick:N,children:n("Cancel")}),e.jsxs(I,{size:"sm",disabled:x,onClick:()=>{y()},children:[x?e.jsx(Pe,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Ho,{className:"h-3.5 w-3.5"}),n(x?"Exporting…":"Export")]})]})})]})})}function tm({file:t,onClose:s}){const{t:n}=z(),[a,r]=m.useState(t.encrypted?"password":"preview"),[o,i]=m.useState(""),[u,d]=m.useState("merge"),[x,h]=m.useState(null),[c,f]=m.useState([]),[l,p]=m.useState(null),[g,w]=m.useState(!1),[C,b]=m.useState(null),[N,y]=m.useState(null),[S,D]=m.useState(!1),k=m.useRef(0),O=m.useCallback(async(v,U)=>{const L=++k.current;b("preview"),y(null),h(null),f([]);try{const K=await window.electronAPI.configSync.previewImport({token:t.token,mode:v,...U?{password:U}:{}});if(L!==k.current)return;if(i(""),!K.ok){y(n(K.error));return}d(K.mode),h(K.summary),f(K.warnings),r("preview")}catch{L===k.current&&(i(""),y(n("Could not preview configuration package.")))}finally{L===k.current&&b(null)}},[t.token,n]);m.useEffect(()=>{t.encrypted||O("merge")},[t.encrypted,O]);const E=()=>{C||(k.current+=1,D(!1),i(""),window.electronAPI.configSync.cancelImport(t.token).catch(()=>{}),s())},M=v=>{v===u||C||(d(v),O(v))},A=!!x?.some(v=>(v.category==="skills"||v.category==="mcpServers")&&v.added+v.updated+v.skipped>0),F=x!==null,V=async()=>{if(x){b("commit"),y(null);try{const v=await window.electronAPI.configSync.commitImport({token:t.token,mode:u});if(!v.ok){h(null),f([]),y(n(v.error));return}i("");try{await j.persist.rehydrate()}catch{w(!0)}f(v.warnings),p(v.backupPath),r("success")}catch{h(null),f([]),y(n("Could not import configuration."))}finally{b(null)}}};return e.jsxs(fe,{open:!0,onOpenChange:v=>!v&&E(),children:[e.jsxs(ge,{className:"max-w-2xl",showCloseButton:C===null,children:[e.jsxs(je,{children:[e.jsx(ve,{children:n(a==="success"?"Configuration imported":"Import configuration")}),e.jsx($e,{children:a==="success"?n(g?"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:t.fileName})})]}),a==="password"&&e.jsxs(we,{className:"space-y-4",children:[e.jsxs(Le,{variant:"info",children:[e.jsx(Go,{}),e.jsx(wt,{children:n("Encrypted configuration package")}),e.jsx(ze,{children:n("Enter the export password to decrypt and preview this package.")})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(cn,{htmlFor:"config-import-password",children:n("Password")}),e.jsx(Y,{id:"config-import-password",type:"password",autoFocus:!0,autoComplete:"current-password",value:o,"aria-invalid":!!N,onChange:v=>{i(v.target.value),y(null)},onKeyDown:v=>{v.key==="Enter"&&o.length>0&&!C&&O("merge",o)}})]}),N&&e.jsxs("p",{className:"flex items-center gap-1.5 text-xs text-destructive",role:"alert",children:[e.jsx(St,{className:"h-3.5 w-3.5 shrink-0"}),N]})]}),a==="preview"&&e.jsxs(we,{className:"max-h-[58vh] space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium",children:n("Import mode")}),e.jsxs(Qu,{value:u,onValueChange:v=>M(v),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(wa,{value:"merge",disabled:C!==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(wa,{value:"replace",disabled:C!==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.")})]})]})]})]}),C==="preview"&&e.jsxs("div",{className:"flex items-center justify-center gap-2 rounded-md border border-dashed py-10",children:[e.jsx(Pe,{className:"h-4 w-4 animate-spin text-muted-foreground"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:n("Preparing preview…")})]}),!C&&x&&e.jsx("div",{className:"overflow-hidden rounded-md border",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted/50 text-xs text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",className:"px-3 py-2 text-left font-medium",children:n("Category")}),e.jsx("th",{scope:"col",className:"px-3 py-2 text-right font-medium",children:n("Added")}),e.jsx("th",{scope:"col",className:"px-3 py-2 text-right font-medium",children:n("Updated")}),e.jsx("th",{scope:"col",className:"px-3 py-2 text-right font-medium",children:n("Skipped")}),e.jsx("th",{scope:"col",className:"px-3 py-2 text-right font-medium",children:n("Removed")})]})}),e.jsx("tbody",{children:Xu.map(({category:v,label:U})=>{const L=x.find(K=>K.category===v);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(U)}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:L?.added??0}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:L?.updated??0}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:L?.skipped??0}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:L?.removed??0})]},v)})})]})}),!C&&x?.find(v=>v.category==="settings")?.fields?.length?e.jsxs("p",{className:"text-xs text-muted-foreground",children:[n("Portable settings changed:")," ",x.find(v=>v.category==="settings")?.fields?.join(", ")]}):null,u==="replace"&&x&&!C&&e.jsxs(Le,{variant:"error",children:[e.jsx(Fe,{}),e.jsx(wt,{children:n("Local-only configuration will be deleted")}),e.jsx(ze,{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(v=>e.jsxs(Le,{variant:"warning",children:[e.jsx(Fe,{}),e.jsx(ze,{children:n(v)})]},v)),x&&!C&&e.jsxs(Le,{variant:"warning",children:[e.jsx(yn,{}),e.jsx(wt,{children:n("Only import packages you trust")}),e.jsx(ze,{children:n("An imported package can change portable preferences and configuration. Skills and MCP servers may also run commands later when you use them. Previewing does not execute them; continue only if you trust the package.")})]}),N&&e.jsxs(Le,{variant:"error",children:[e.jsx(St,{}),e.jsx(ze,{children:N})]})]}),a==="success"&&l&&e.jsxs(we,{className:"space-y-4",children:[e.jsxs(Le,{variant:"success",children:[e.jsx(oo,{}),e.jsx(wt,{children:n("Import complete")}),e.jsxs(ze,{children:[e.jsx("p",{children:n("Backup of previous settings:")}),e.jsx("p",{className:"break-all font-mono text-xs text-foreground",children:l})]})]}),g&&e.jsxs(Le,{variant:"warning",children:[e.jsx(Fe,{}),e.jsx(ze,{children:n("Reopen Settings to load the imported configuration in this window.")})]}),c.map(v=>e.jsxs(Le,{variant:"warning",children:[e.jsx(Fe,{}),e.jsx(ze,{children:n(v)})]},v))]}),e.jsxs(Ie,{children:[a==="password"&&e.jsxs(e.Fragment,{children:[e.jsx(I,{variant:"outline",size:"sm",disabled:C!==null,onClick:E,children:n("Cancel")}),e.jsxs(I,{size:"sm",disabled:C!==null||o.length===0,onClick:()=>{O("merge",o)},children:[C==="preview"&&e.jsx(Pe,{className:"h-3.5 w-3.5 animate-spin"}),n("Preview")]})]}),a==="preview"&&e.jsxs(e.Fragment,{children:[e.jsx(I,{variant:"outline",size:"sm",disabled:C!==null,onClick:E,children:n("Cancel")}),N&&!x?e.jsx(I,{size:"sm",disabled:C!==null,onClick:()=>{O(u)},children:n("Refresh preview")}):e.jsxs(I,{variant:u==="replace"?"destructive":"default",size:"sm",disabled:C!==null||!x,onClick:()=>{x&&(F?D(!0):V())},children:[C==="commit"?e.jsx(Pe,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(bn,{className:"h-3.5 w-3.5"}),n(C==="commit"?"Importing…":"Import")]})]}),a==="success"&&e.jsx(I,{size:"sm",onClick:E,children:n("Done")})]})]}),e.jsx(sm,{open:S,mode:u,hasImportedExecutableResources:A,onOpenChange:D,onConfirm:()=>{V()}})]})}function sm({open:t,mode:s,hasImportedExecutableResources:n,onOpenChange:a,onConfirm:r}){const{t:o}=z();return e.jsx(wn,{open:t,onOpenChange:a,children:e.jsxs(Nn,{className:"sm:max-w-md",zIndexLevel:"nested",children:[e.jsxs(kn,{children:[e.jsxs(Cn,{className:"flex items-start gap-2 text-base",children:[e.jsx(Fe,{className:"mt-0.5 h-4 w-4 shrink-0 text-destructive"}),o("Confirm configuration import")]}),e.jsxs(Sn,{className:"space-y-2",children:[e.jsx("span",{className:"block",children:o("This package can change portable preferences and configuration. Continue only if you trust this package.")}),n&&e.jsx("span",{className:"block",children:o("It includes skills or MCP servers that may execute commands when you use them.")}),s==="replace"&&e.jsx("span",{className:"block",children:o("Replace mode removes local-only items from transferred collections and overwrites included portable preferences. A complete backup will be created first.")}),e.jsx("span",{className:"block",children:o("Do you want to continue with this import?")})]})]}),e.jsxs(In,{variant:"bare",children:[e.jsx(An,{render:e.jsx(I,{variant:"outline",size:"sm"}),children:o("Cancel")}),e.jsx(I,{variant:s==="replace"?"destructive":"default",size:"sm",onClick:()=>{a(!1),r()},children:o("Confirm import")})]})]})})}const Na={auto:"Auto (by usage)",fast:"Fast",balanced:"Balanced",thorough:"Thorough"},ka={standard:"Standard",smart:"Smart compaction","codex-native":"Codex native compaction","continuous-memory":"Continuous memory (experimental)"};function nm(){const{t}=z(),s=j(l=>l.compactStrategy),n=j(l=>l.smartCompactEnabled),a=rl(s,n),r=j(l=>l.setCompactStrategy),o=a!=="standard",i=j(l=>l.smartCompactModel),u=j(l=>l.setSmartCompactModel),d=j(l=>l.smartCompactMode),x=j(l=>l.setSmartCompactMode),h=Qe(),c=i?h.find(l=>l.id===i.providerId):void 0,f=c?.models.find(l=>l.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:[t("Context compaction strategy"),e.jsx(qe,{})]}),e.jsx("p",{className:"mt-0.5 text-muted-foreground text-xs",children:t("Standard uses default compact. Smart compaction uses Enso verified summary at compact time. Codex native compaction additionally stores an official Codex checkpoint on Codex models and uses smart compaction otherwise. Continuous memory records observations in the background so compact keeps more context; all fall back to default compact on failure. Switching strategy takes effect on the next session. The summary model and compaction mode apply to open conversations on the next compaction.")})]}),e.jsxs(se,{items:Object.fromEntries(Zn.map(l=>[l,t(ka[l])])),value:a,onValueChange:l=>r(l),children:[e.jsx(ne,{className:"w-52",children:e.jsx(ae,{})}),e.jsx(re,{children:Zn.map(l=>e.jsx(Q,{value:l,children:t(ka[l])},l))})]})]}),(a==="smart"||a==="codex-native")&&e.jsxs("div",{className:"flex items-center justify-between gap-4","data-smart-compact-mode":d,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Compaction mode")}),e.jsx("p",{className:"mt-0.5 text-muted-foreground/80 text-[11px]",children:t("Mode changes summary budget and how much recent tail to keep. It does not decide whether compact runs.")})]}),e.jsxs(se,{items:Object.fromEntries(ea.map(l=>[l,t(Na[l])])),value:d,onValueChange:l=>x(l),children:[e.jsx(ne,{className:"w-36",children:e.jsx(ae,{})}),e.jsx(re,{children:ea.map(l=>e.jsx(Q,{value:l,children:t(Na[l])},l))})]})]}),o&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"font-medium text-sm",children:t(a==="continuous-memory"?"Background memory model":"Summary model")}),h.length>0&&e.jsx("div",{className:"w-full min-w-0",children:e.jsx(Oe,{providers:h,providerId:c?.id??"",modelId:f?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:t("Follows the session model"),side:"bottom",triggerClassName:Ye,onSelect:(l,p)=>u({providerId:l,modelId:p}),onReasoningChange:()=>{},onThinkingChange:()=>{}})}),i&&(!c||!f)&&e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Selected model is unavailable — falls back to the session model.")}),i&&e.jsx(I,{variant:"ghost",size:"sm",className:"self-start",onClick:()=>u(null),children:t("Follow session model")})]})]})}const am={cmd:"Command Prompt",powershell:"Windows PowerShell",pwsh:"PowerShell 7 (pwsh)","git-bash":"Git Bash",zsh:"zsh",bash:"bash",fish:"fish"};function rm(){const{language:t,setLanguage:s}=j(),{t:n}=z();return e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:n("General")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:n("General application settings")})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h4",{className:"border-b pb-2 text-base font-semibold",children:n("Application")}),e.jsxs("div",{className:"flex items-center gap-3","data-settings-row":"general.language",children:[e.jsx("span",{className:"text-sm font-medium",children:n("Language")}),e.jsxs(se,{items:{en:"English",zh:"简体中文"},value:t,onValueChange:a=>s(a),children:[e.jsx(ne,{className:"w-48",children:e.jsx(ae,{})}),e.jsxs(re,{children:[e.jsx(Q,{value:"en",children:"English"}),e.jsx(Q,{value:"zh",children:"简体中文"})]})]})]}),e.jsx(om,{}),e.jsx(xm,{}),e.jsx(Zu,{}),e.jsx(pm,{})]}),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(im,{}),e.jsx(lm,{}),e.jsx(nm,{}),e.jsx(Ku,{})]}),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(dm,{}),e.jsx(cm,{}),e.jsx(mm,{})]}),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(hm,{}),e.jsx(um,{})]})]})}function om(){const{t}=z(),s=j(a=>a.notifyMainAgentOnly),n=j(a=>a.setNotifyMainAgentOnly);return e.jsx(Me,{rowId:"general.notifyMainAgentOnly",title:t("Notify only for the main agent"),description:t("Skip coworker completion and failure notifications on this computer and the paired phone. Questions and approvals still notify."),checked:s,onChange:n})}function im(){const{t}=z(),s=j(a=>a.generationStallTimeoutMin),n=j(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:t("Stop if no output")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Abort and retry the run when no tokens or tool results arrive for this long. Thinking counts as output.")})]}),e.jsxs(se,{items:Object.fromEntries(ta.map(a=>[String(a),a===0?t("Never"):t("{{count}} min",{count:a})])),value:String(s),onValueChange:a=>n(Number(a)),children:[e.jsx(ne,{className:"w-28",children:e.jsx(ae,{})}),e.jsx(re,{children:ta.map(a=>e.jsx(Q,{value:String(a),children:a===0?t("Never"):t("{{count}} min",{count:a})},a))})]})]})}function lm(){const{t}=z(),s=j(o=>o.autoRetryLimit),n=j(o=>o.setAutoRetryLimit),a=xs.some(o=>o===s)?[...xs]:[...xs,s].sort((o,i)=>o===ps?1:i===ps?-1:o-i),r=o=>o===0?t("Off"):o===ps?t("Unlimited"):t("{{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:t("Auto-retry on transient errors")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Retry with backoff (up to 60s apart) after 429, 5xx or network errors. Quota and billing errors are never retried. Unlimited keeps retrying until you cancel.")})]}),e.jsxs(se,{items:Object.fromEntries(a.map(o=>[String(o),r(o)])),value:String(s),onValueChange:o=>n(Number(o)),children:[e.jsx(ne,{className:"w-28",children:e.jsx(ae,{})}),e.jsx(re,{children:a.map(o=>e.jsx(Q,{value:String(o),children:r(o)},o))})]})]})}function cm(){const{t}=z(),s=j(r=>r.activeRetentionMinutes),n=j(r=>r.setActiveRetentionMinutes),a=r=>r===0?t("Off"):t("{{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:t("Keep in Active after last message")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Viewed conversations stay in Active for this long after their last message or your last open while still in Active, then leave. Unviewed ones stay until you open them.")})]}),e.jsxs(se,{items:Object.fromEntries(aa.map(r=>[String(r),a(r)])),value:String(s),onValueChange:r=>n(Number(r)),children:[e.jsx(ne,{className:"w-28",children:e.jsx(ae,{})}),e.jsx(re,{children:aa.map(r=>e.jsx(Q,{value:String(r),children:a(r)},r))})]})]})}function Vt(t,s){return s===0?t("Never"):s===1?t("{{count}} day",{count:s}):t("{{count}} days",{count:s})}function dm(){const{t}=z(),s=j(u=>u.autoArchiveIdleDays),n=j(u=>u.setAutoArchiveIdleDays),a=j(u=>u.autoArchiveMergedWorktrees),r=j(u=>u.setAutoArchiveMergedWorktrees),o=j(u=>u.autoDeleteArchivedDays),i=j(u=>u.setAutoDeleteArchivedDays);return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.autoArchiveIdleDays",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Archive idle conversations")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Move conversations that have been idle this long into Archived. Does not delete them.")})]}),e.jsxs(se,{items:Object.fromEntries(sa.map(u=>[String(u),Vt(t,u)])),value:String(s),onValueChange:u=>n(Number(u)),children:[e.jsx(ne,{className:"w-28",children:e.jsx(ae,{})}),e.jsx(re,{children:sa.map(u=>e.jsx(Q,{value:String(u),children:Vt(t,u)},u))})]})]}),e.jsx(Me,{rowId:"general.autoArchiveMergedWorktrees",title:t("Clean up merged worktrees"),description:t("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:t("Delete archived conversations after")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Permanently delete conversations that have been archived longer than this. This cannot be undone. Choosing a positive value deletes already-overdue archived conversations immediately.")})]}),e.jsxs(se,{items:Object.fromEntries(na.map(u=>[String(u),Vt(t,u)])),value:String(o),onValueChange:u=>i(Number(u)),children:[e.jsx(ne,{className:"w-28",children:e.jsx(ae,{})}),e.jsx(re,{children:na.map(u=>e.jsx(Q,{value:String(u),children:Vt(t,u)},u))})]})]})]})}function um(){const{t}=z(),s=j(o=>o.terminalShell),n=j(o=>o.setTerminalShell),a=il(window.electronAPI.env.platform),r=Object.fromEntries(a.map(o=>[o,o==="auto"?t("System default"):am[o]]));return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.terminalShell",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Terminal shell")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Applies to new side panel terminals. SSH projects keep the remote login shell.")})]}),e.jsxs(se,{items:r,value:s,onValueChange:o=>n(o),children:[e.jsx(ne,{className:"w-56",children:e.jsx(ae,{})}),e.jsx(re,{children:a.map(o=>e.jsx(Q,{value:o,children:r[o]},o))})]})]})}function mm(){const{t}=z(),s=j(x=>x.worktreeRoot),n=j(x=>x.setWorktreeRoot),[a,r]=m.useState(s),[o,i]=m.useState(null);m.useEffect(()=>{r(s)},[s]);const u=x=>{const h=x.trim();if(h&&!Fu(h)){i(t("Enter an absolute path"));return}i(null),n(h)},d=async()=>{const x=await window.electronAPI.dialog.selectDirectory();x&&(r(x),u(x))};return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.worktreeRoot",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Worktree root directory")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Where isolated session worktrees are created. Leave empty to use the app data directory. Existing worktrees stay where they are.")})]}),e.jsxs("div",{className:"w-72 shrink-0 space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Y,{value:a,placeholder:t("Default location"),onChange:x=>r(x.target.value),onBlur:()=>u(a),onKeyDown:x=>{x.key==="Enter"&&u(a)}}),e.jsx(I,{variant:"outline",size:"sm",className:"shrink-0",onClick:()=>{d()},children:t("Browse")})]}),o&&e.jsx("p",{className:"text-xs text-destructive",children:o})]})]})}function hm(){const{t}=z(),s=j(r=>r.windowsLocalShell),n=j(r=>r.setWindowsLocalShell),a={auto:t("Windows default (PowerShell)"),powershell:t("PowerShell"),bash:t("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:[t("Windows local command shell"),e.jsx(qe,{})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Only the Windows local agent command tool. SSH and other platforms stay on bash. Takes effect on the next session.")})]}),e.jsxs(se,{items:a,value:s,onValueChange:r=>n(r),children:[e.jsx(ne,{className:"w-56",children:e.jsx(ae,{})}),e.jsx(re,{children:Object.keys(a).map(r=>e.jsx(Q,{value:r,children:a[r]},r))})]})]})}function Me({title:t,description:s,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:t}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s})]}),e.jsx(le,{checked:n,onCheckedChange:i=>a(i===!0)})]}),o?e.jsx("div",{className:"mt-2",children:o}):null]})}function Ca(t,s){window.electronAPI.proxy.apply({mode:t,customUrl:s})}function xm(){const{t}=z(),s=j(c=>c.proxyMode),n=j(c=>c.customProxyUrl),a=j(c=>c.setProxyMode),r=j(c=>c.setCustomProxyUrl),[o,i]=m.useState(n),[u,d]=m.useState(null);m.useEffect(()=>{i(n)},[n]);const x=c=>{a(c),Ca(c,n)},h=()=>{const c=o.trim();if(c&&!ll(c)){d(t("Enter an http(s) proxy URL"));return}d(null),r(c),Ca(s,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:t("Network proxy")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("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:t("Proxy mode")}),e.jsxs(se,{items:{system:t("Follow system proxy"),none:t("No proxy"),custom:t("Custom proxy")},value:s,onValueChange:c=>x(c),children:[e.jsx(ne,{className:"w-56",children:e.jsx(ae,{})}),e.jsxs(re,{children:[e.jsx(Q,{value:"system",children:t("Follow system proxy")}),e.jsx(Q,{value:"none",children:t("No proxy")}),e.jsx(Q,{value:"custom",children:t("Custom proxy")})]})]})]}),s==="custom"&&e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"pt-1.5 text-sm font-medium",children:t("Proxy URL")}),e.jsxs("div",{className:"min-w-0 space-y-1",children:[e.jsx(Y,{value:o,placeholder:"http://127.0.0.1:7890",onChange:c=>i(c.target.value),onBlur:h,onKeyDown:c=>{c.key==="Enter"&&h()}}),u&&e.jsx("p",{className:"text-xs text-destructive",children:u})]})]})]})}function pm(){const{t}=z(),s=j(N=>N.autoUpdate),n=j(N=>N.setAutoUpdate),a=j(N=>N.autoRestartWhenIdle),r=j(N=>N.setAutoRestartWhenIdle),[o,i]=m.useState(null),[u,d]=m.useState(null),[x,h]=m.useState(!1),[c,f]=m.useState(!1);m.useEffect(()=>{let N=!0;window.electronAPI.updater.getState().then(S=>{N&&(d(S),S.status&&i(D=>D??S.status))}).catch(()=>{});const y=window.electronAPI.updater.onStatus(i);return()=>{N=!1,y()}},[]);const l=u?.host==="server"?u:null,p=u?.host==="desktop"||l!==null&&l.mode!=="manual",g=(o?.status==="available"||o?.status==="downloaded")&&!!o.info,C=(()=>{if(!o)return null;switch(o.status){case"checking":return t("Checking for updates…");case"available":return t("New version {{version}} found",{version:o.info?.version??""});case"not-available":return t("You are on the latest version");case"downloading":return t("Downloading update… {{percent}}%",{percent:Math.round(o.progress?.percent??0)});case"downloaded":return t("New version {{version}} is ready — restart to update.",{version:o.info?.version??""});case"error":return l&&o.error?t("Update failed: {{error}}",{error:o.error}):t("Update check failed");default:return null}})(),b=o?.status==="checking"||o?.status==="downloading";return e.jsxs("div",{className:"space-y-3","data-settings-row":"general.updates",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium",children:t("Updates")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l?fm(l.mode,t):t("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:[t("Current version")," · ",gm]}),C&&e.jsx("p",{className:"mt-0.5 truncate text-xs text-muted-foreground",children:C})]}),g&&e.jsx(I,{variant:"ghost",size:"sm",onClick:()=>f(!0),className:"ml-auto shrink-0",children:t("Release notes")}),o?.status==="downloaded"?e.jsx(I,{size:"sm",onClick:()=>{window.electronAPI.updater.quitAndInstall()},className:"shrink-0",children:t("Restart to update")}):p&&o?.status==="available"?e.jsx(I,{size:"sm",onClick:()=>{window.electronAPI.updater.downloadUpdate()},className:"shrink-0",children:t("Download update")}):e.jsx(I,{variant:"outline",size:"sm",disabled:b,onClick:()=>{window.electronAPI.updater.checkForUpdates()},className:"shrink-0",children:t("Check for updates")}),e.jsx(ol,{open:c,onOpenChange:f,status:o,canDownload:p})]}),l?.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:t("Restart server")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Running tasks are interrupted; this page reconnects after the server is back.")})]}),e.jsx(I,{variant:"outline",size:"sm",onClick:()=>h(!0),className:"shrink-0",children:t("Restart")}),e.jsx(io,{open:x,onOpenChange:h,title:t("Restart server?"),description:t("Running tasks are interrupted; this page reconnects after the server is back."),confirmLabel:t("Restart"),onConfirm:()=>{h(!1),window.electronAPI.updater.restart()}})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Automatic updates")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Download and install updates automatically")})]}),e.jsx(le,{checked:s,onCheckedChange:N=>{n(N),window.electronAPI.updater.setAutoUpdateEnabled(N)}})]}),e.jsxs("div",{className:`flex items-center justify-between gap-3 rounded-md border px-3 py-2.5 ${s?"":"opacity-60"}`,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Restart and apply when idle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("After the update is downloaded, restart automatically if no agent is running, nothing is queued, and there are no pending questions or approvals. The idle state must last 5 minutes, and a focused window also blocks it.")})]}),e.jsx(le,{checked:s&&a,disabled:!s,onCheckedChange:N=>{r(N),window.electronAPI.updater.setAutoRestartWhenIdle(N)}})]})]})}function fm(t,s){return s(t==="npm"?"Server updates install the new version with npm and restart.":"This server must be updated on the machine itself.")}const gm="0.3.3",jm=["100%","100%","70%","100%","55%"],vm=["100%","85%","60%"];function bm({palette:t}){return e.jsxs("div",{className:"flex h-[88px] gap-1.5 p-[7px]",style:{background:t.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:t.text}}),jm.slice(1).map((s,n)=>e.jsx("i",{className:"block h-[5px] rounded-[3px] opacity-55",style:{background:t.textSubtle,width:s}},n))]}),e.jsxs("div",{className:"flex flex-1 flex-col gap-[5px] rounded-md px-2.5 py-2",style:{background:t.surface,boxShadow:`0 0 0 1px ${t.border}`},children:[e.jsx("i",{className:"block h-1 w-[70%] rounded-sm opacity-75",style:{background:t.text}}),vm.map(s=>e.jsx("i",{className:"block h-1 rounded-sm opacity-50",style:{background:t.textSubtle,width:s}},s)),e.jsx("b",{className:"mt-auto flex h-3.5 justify-end rounded-full p-[3px]",style:{background:t.sunken,boxShadow:`0 0 0 1px ${t.border}`},children:e.jsx("span",{"data-theme-accent":!0,className:"size-2 rounded-full",style:{background:t.accent}})})]})]})}const Sa="overflow-hidden rounded-lg border text-left transition-shadow";function ym({themes:t,selected:s,mode:n,onSelect:a,onGetMore:r}){const{t:o}=z();return e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[t.map(i=>{const u=i.id===s;return e.jsxs("button",{type:"button","data-theme-card":i.id,"aria-pressed":u,onClick:()=>a(i.id),className:H(Sa,"bg-card",u?"border-transparent shadow-[0_0_0_2px_var(--brand)]":"hover:border-input"),children:[e.jsx(bm,{palette:i[n]}),e.jsxs("div",{className:"flex items-center gap-1.5 border-t px-2.5 py-[7px] text-sm",children:[e.jsx("span",{className:"truncate font-medium",children:i.name}),e.jsx("span",{className:H("ml-auto shrink-0 truncate rounded-full px-1.5 py-px text-[10.5px]",i.source.kind==="plugin"?"max-w-[60%] bg-brand/12 text-brand":"bg-muted text-subtle-foreground"),children:i.source.kind==="plugin"?o("Plugin · {{name}}",{name:i.source.pluginName}):o("Built-in")})]})]},i.id)}),r&&e.jsxs("button",{type:"button",onClick:r,className:H(Sa,"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(Lt,{className:"size-[18px]"}),o("Get more themes")]})]})}function un({rowId:t,title:s,description:n,children:a}){return e.jsxs("div",{"data-settings-row":t,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:s}),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 wm({children:t}){return e.jsx("div",{className:"divide-y rounded-lg border bg-card",children:t})}function Ze({label:t,value:s,onCommit:n,min:a=0,max:r=100,step:o,unit:i="%",formatSuffix:u,onPreview:d,trailing:x,valueClassName:h="w-12"}){const[c,f]=m.useState(s);m.useEffect(()=>{f(s)},[s]);const l=u?.(c);return e.jsxs("div",{className:H("grid items-center gap-4",x?"grid-cols-[9.5rem_minmax(0,1fr)_auto]":"grid-cols-[100px_1fr]"),children:[e.jsx("span",{className:"text-sm font-medium",children:t}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(gl,{min:a,max:r,step:o,value:c,onValueChange:p=>{const g=Array.isArray(p)?p[0]:p;f(g),d?.(g)},onValueCommitted:p=>n(Array.isArray(p)?p[0]:p)}),e.jsxs("span",{className:H("shrink-0 text-right text-sm text-muted-foreground tabular-nums",l?"w-28":h),children:[c,i,l?` · ${l}`:""]})]}),x]})}function Nm(){const{t}=z(),s=j(P=>P.backgroundImageEnabled),n=j(P=>P.setBackgroundImageEnabled),a=j(P=>P.backgroundSourceType),r=j(P=>P.setBackgroundSourceType),o=j(P=>P.backgroundImagePath),i=j(P=>P.setBackgroundImagePath),u=j(P=>P.backgroundFolderPath),d=j(P=>P.setBackgroundFolderPath),x=j(P=>P.backgroundUrlPath),h=j(P=>P.setBackgroundUrlPath),c=j(P=>P.backgroundRandomEnabled),f=j(P=>P.setBackgroundRandomEnabled),l=j(P=>P.backgroundRandomInterval),p=j(P=>P.setBackgroundRandomInterval),g=j(P=>P.backgroundOpacity),w=j(P=>P.setBackgroundOpacity),C=j(P=>P.backgroundBlur),b=j(P=>P.setBackgroundBlur),N=j(P=>P.backgroundBrightness),y=j(P=>P.setBackgroundBrightness),S=j(P=>P.backgroundSaturation),D=j(P=>P.setBackgroundSaturation),k=j(P=>P.backgroundMask),O=j(P=>P.setBackgroundMask),E=j(P=>P.backgroundComposerOpacity),M=j(P=>P.setBackgroundComposerOpacity),A=j(P=>P.backgroundCodeOpacity),F=j(P=>P.setBackgroundCodeOpacity),V=j(P=>P.backgroundSizeMode),v=j(P=>P.setBackgroundSizeMode),U=j(P=>P.bumpBackgroundRefresh),L=jl()?.source==="theme",K=a==="file"?o:a==="folder"?u:x,[$,G]=m.useState(K);m.useEffect(()=>{G(K)},[K]);const X=m.useCallback(()=>{const P=$.trim();a==="file"?i(P):a==="folder"?d(P):h(P)},[$,a,i,d,h]),[oe,q]=m.useState(l);m.useEffect(()=>{q(l)},[l]);const ie=async()=>{if(a==="folder"){const P=await window.electronAPI.dialog.selectDirectory();P&&d(P)}else{const P=await window.electronAPI.dialog.selectFile([...yl,...wl]);P&&i(P)}},B=[{value:"file",label:t("Single image")},{value:"folder",label:t("Folder (random)")},{value:"url",label:t("Remote URL")}],ee=[{value:"cover",label:t("Cover")},{value:"contain",label:t("Contain")},{value:"repeat",label:t("Repeat")},{value:"center",label:t("Center")}],R=t(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:t("Background image")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("Show a custom image behind the interface")})]}),e.jsx(le,{checked:s,onCheckedChange:P=>n(P===!0)})]}),L&&e.jsx("p",{className:"text-sm text-muted-foreground",children:t("The current theme has its own background. Turn this on to replace it with your image.")}),s&&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:t("Source type")}),e.jsxs(se,{items:B,value:a,onValueChange:P=>r(P),children:[e.jsx(ne,{className:"w-48",children:e.jsx(ae,{})}),e.jsx(re,{children:B.map(P=>e.jsx(Q,{value:P.value,children:P.label},P.value))})]})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:R}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Y,{value:$,onChange:P=>G(P.target.value),onBlur:X,onKeyDown:P=>{P.nativeEvent.isComposing||P.key==="Enter"&&(X(),P.currentTarget.blur())},placeholder:a==="url"?"https://example.com/image.jpg":"",className:"flex-1"}),a!=="url"&&e.jsx(I,{variant:"outline",size:"icon",onClick:ie,"aria-label":t("Browse"),children:a==="folder"?e.jsx(Tn,{className:"h-4 w-4"}):e.jsx(du,{className:"h-4 w-4"})}),a!=="file"&&e.jsx(I,{variant:"outline",size:"icon",onClick:U,"aria-label":t("Refresh now"),children:e.jsx(tt,{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:t("Auto switch")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(le,{checked:c,onCheckedChange:P=>f(P===!0)}),c&&e.jsxs(e.Fragment,{children:[e.jsx(Y,{type:"number",min:5,max:86400,value:oe,onChange:P=>q(Number(P.target.value)),onBlur:()=>p(oe),onKeyDown:P=>{P.key==="Enter"&&(p(oe),P.currentTarget.blur())},className:"w-24"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:t("seconds")})]})]})]}),e.jsx(Ze,{label:t("Background visibility"),value:Math.round(g*100),onCommit:P=>w(P/100)}),e.jsx(Ze,{label:t("Blur"),value:C,onCommit:b,max:20,unit:"px"}),e.jsx(Ze,{label:t("Brightness"),value:Math.round(N*100),onCommit:P=>y(P/100),max:200}),e.jsx(Ze,{label:t("Saturation"),value:Math.round(S*100),onCommit:P=>D(P/100),max:200}),e.jsx(Ze,{label:t("Overlay"),value:Math.round(k*100),onCommit:P=>O(P/100)}),e.jsx(Ze,{label:t("Composer opacity"),value:Math.round(E*100),onCommit:P=>M(P/100)}),e.jsx(Ze,{label:t("Code block opacity"),value:Math.round(A*100),onCommit:P=>F(P/100)}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:t("Size mode")}),e.jsxs(se,{items:ee,value:V,onValueChange:P=>v(P),children:[e.jsx(ne,{className:"w-48",children:e.jsx(ae,{})}),e.jsx(re,{children:ee.map(P=>e.jsx(Q,{value:P.value,children:P.label},P.value))})]})]})]})]})}function km({theme:t,fontSize:s,fontFamily:n,fontWeight:a}){const r=[{id:"prompt1",text:"$ ",color:t.green},{id:"cmd1",text:"ls -la",color:t.foreground},{id:"nl1",text:`
|
|
3
|
+
`},{id:"perm1",text:"drwxr-xr-x ",color:t.blue},{id:"meta1",text:"5 user staff 160 Dec 23 ",color:t.foreground},{id:"dir1",text:"Documents",color:t.cyan},{id:"nl2",text:`
|
|
4
|
+
`},{id:"perm2",text:"-rw-r--r-- ",color:t.foreground},{id:"meta2",text:"1 user staff 2048 Dec 22 ",color:t.foreground},{id:"file1",text:"config.json",color:t.yellow},{id:"nl3",text:`
|
|
5
|
+
|
|
6
|
+
`},{id:"prompt2",text:"$ ",color:t.green},{id:"cmd2",text:'echo "Hello, World!"',color:t.foreground},{id:"nl4",text:`
|
|
7
|
+
`},{id:"output1",text:"Hello, World!",color:t.magenta}];return e.jsxs("div",{className:"rounded-lg border p-4 h-40 overflow-auto",style:{backgroundColor:t.background,fontSize:`${s}px`,fontFamily:n,fontWeight:a},children:[r.map(o=>o.text===`
|
|
8
|
+
`?e.jsx("br",{},o.id):o.text===`
|
|
9
|
+
|
|
10
|
+
`?e.jsxs(m.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:t.cursor}})]})}function Cm({isFavorite:t,onClick:s,ariaLabel:n}){return e.jsx("button",{type:"button","aria-label":n,"aria-pressed":t,onClick:a=>{a.stopPropagation(),a.preventDefault(),s(a)},className:"p-1 hover:text-red-500 transition-colors",children:t?e.jsx(va,{className:"h-4 w-4 fill-red-500 text-red-500"}):e.jsx(va,{className:"h-4 w-4"})})}function Sm({value:t,onValueChange:s,themes:n,favoriteThemes:a,onToggleFavorite:r,onThemeHover:o,showFavoritesOnly:i,onShowFavoritesOnlyChange:u,showEmptyFavoritesHint:d}){const{t:x}=z(),[h,c]=m.useState(t),[f,l]=m.useState(t),[p,g]=m.useState(!1),w=m.useRef(void 0),C=m.useRef(null),b=m.useRef(t),N=m.useRef(!1),y=m.useMemo(()=>new Set(a),[a]);m.useEffect(()=>{p||(c(t),l(t))},[t,p]);const S=m.useMemo(()=>{if(!f||f===h)return n;const M=f.toLowerCase();return n.filter(A=>A.toLowerCase().includes(M))},[n,f,h]),D=M=>{M&&(N.current=!0,c(M),l(M)),s(M)},k=M=>{g(M),M?(b.current=t,N.current=!1,c(t),l(t)):N.current||o?.(b.current)},O=M=>{clearTimeout(w.current),w.current=setTimeout(()=>{o?.(M)},50)},E=()=>{clearTimeout(w.current)};return m.useEffect(()=>{if(!p)return;const M=A=>{(A.key==="ArrowDown"||A.key==="ArrowUp")&&requestAnimationFrame(()=>{const F=C.current?.querySelector("[data-highlighted]");if(F){const V=F.getAttribute("data-value");V&&o?.(V)}})};return document.addEventListener("keydown",M,!0),()=>{document.removeEventListener("keydown",M,!0)}},[p,o]),m.useEffect(()=>()=>{clearTimeout(w.current)},[]),e.jsxs(Pu,{value:h,onValueChange:D,inputValue:f,onInputValueChange:l,open:p,onOpenChange:k,children:[e.jsxs("div",{className:"relative",children:[e.jsx(Tu,{placeholder:x("Search themes...")}),e.jsxs("div",{className:"absolute right-8 top-1/2 -translate-y-1/2 flex items-center gap-1.5",children:[e.jsx(Je,{id:"show-favorites-only-inner",checked:i,onCheckedChange:M=>u(M===!0),onClick:M=>M.stopPropagation()}),e.jsx("label",{htmlFor:"show-favorites-only-inner",className:"text-xs text-muted-foreground cursor-pointer whitespace-nowrap",onClick:M=>M.stopPropagation(),onKeyDown:M=>M.stopPropagation(),children:x("Show favorites only")})]})]}),e.jsx(Ou,{children:e.jsxs(Lu,{ref:C,children:[S.length===0&&e.jsx("div",{className:"py-6 text-center text-sm text-muted-foreground",children:x(d?"No favorite themes yet. Click the heart icon to add favorites.":"No themes found")}),S.map(M=>e.jsx(Du,{value:M,"data-value":M,onMouseEnter:()=>O(M),onMouseLeave:E,endAddon:e.jsx(Cm,{isFavorite:y.has(M),onClick:()=>r(M),ariaLabel:y.has(M)?x("Remove from favorites"):x("Add to favorites")}),children:M},M))]})})]})}const Im={theme:"Follow theme",violet:"Violet",indigo:"Indigo",teal:"Teal",amber:"Amber",graphite:"Graphite"},Ia={body:"Body",h1:"Heading 1",h2:"Heading 2",h3:"Heading 3",h4:"Heading 4–6",table:"Table",inlineCode:"Inline code",codeBlock:"Code block"},Aa=ho.map(t=>({value:String(t),label:String(t)}));function Am(){const{t}=z(),s=j(d=>d.chatTypography),n=j(d=>d.setChatTypography),a=j(d=>d.resetChatTypography),[r,o]=m.useState(s.body.size);m.useEffect(()=>{o(s.body.size)},[s.body.size]);const i=(d,x)=>{const h=j.getState().chatTypography;n({...h,[d]:{...h[d],size:x}})},u=(d,x)=>{const h=j.getState().chatTypography;n({...h,[d]:{...h[d],weight:x}})};return e.jsxs("section",{"data-settings-row":"appearance.chatTypography",className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:t("Conversation typography")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("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:[vl.map(d=>{const x=bl[d];return e.jsx(Ze,{label:t(Ia[d]),value:s[d].size,min:x.min,max:x.max,step:x.step,unit:x.unit==="%"?"%":"px",valueClassName:"w-28",formatSuffix:x.unit==="%"?h=>`${(r*h/100).toFixed(1)}px`:void 0,onPreview:d==="body"?o:void 0,onCommit:h=>i(d,h),trailing:e.jsxs(se,{items:Aa,value:String(s[d].weight),onValueChange:h=>{const c=Number(h);ho.includes(c)&&u(d,c)},children:[e.jsx(ne,{className:"w-24 min-w-24","aria-label":t(Ia[d]),children:e.jsx(ae,{})}),e.jsx(re,{children:Aa.map(h=>e.jsx(Q,{value:h.value,children:h.label},h.value))})]})},d)}),e.jsx("div",{className:"flex justify-end",children:e.jsx(I,{variant:"outline",size:"sm",onClick:()=>a(),children:t("Reset to defaults")})})]})]})}function Em({seconds:t,onCommit:s}){const{t:n}=z(),[a,r]=m.useState(String(t));m.useEffect(()=>r(String(t)),[t]);const o=()=>{const i=Number(a);if(!Number.isInteger(i)){r(String(t));return}const u=Nl(i);s(u),r(String(u))};return e.jsxs("div",{className:"flex items-center justify-between gap-3","data-settings-row":"appearance.liveActivityFoldDelaySec",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:n("Wait before folding")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n("Seconds to wait after tools and thinking finish")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Y,{type:"number",min:1,max:60,value:a,onChange:i=>r(i.target.value),onBlur:o,onKeyDown:i=>{i.key==="Enter"&&(o(),i.currentTarget.blur())},className:"w-20"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:n("sec")})]})]})}function Mm(){const{t}=z(),s=j(S=>S.openChangesOnFileEdit),n=j(S=>S.setOpenChangesOnFileEdit),a=j(S=>S.compactReadOnlyTools),r=j(S=>S.setCompactReadOnlyTools),o=j(S=>S.expandLiveEdits),i=j(S=>S.setExpandLiveEdits),u=j(S=>S.expandLiveReasoning),d=j(S=>S.setExpandLiveReasoning),x=j(S=>S.autoCollapseTurns),h=j(S=>S.setAutoCollapseTurns),c=j(S=>S.collapseCompletedActivity),f=j(S=>S.setCollapseCompletedActivity),l=j(S=>S.collapseLiveActivity),p=j(S=>S.setCollapseLiveActivity),g=j(S=>S.liveActivityFoldDelaySec),w=j(S=>S.setLiveActivityFoldDelaySec),C=j(S=>S.pinUnfinishedTodos),b=j(S=>S.setPinUnfinishedTodos),N=j(S=>S.navRailSide),y=j(S=>S.setNavRailSide);return e.jsxs("div",{className:"space-y-6",children:[e.jsx("h3",{className:"text-lg font-medium",children:t("Conversation display")}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Me,{rowId:"appearance.openChangesOnFileEdit",title:t("Open Changes when files are edited"),description:t("Automatically show the side panel Changes tab after the agent edits a file"),checked:s,onChange:n}),e.jsx(Me,{rowId:"appearance.compactReadOnlyTools",title:t("Compact read-only tool calls"),description:t("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(Me,{rowId:"appearance.expandLiveEdits",title:t("Expand file edits while running"),description:t("Automatically unfold diffs or written content from file modification tools while the agent is still running"),checked:o,onChange:i}),e.jsx(Me,{rowId:"appearance.expandLiveReasoning",title:t("Expand reasoning while streaming"),description:t("Automatically unfold the thinking block while the model is still reasoning. It collapses again when reasoning ends."),checked:u,onChange:d}),e.jsx(Me,{rowId:"appearance.autoCollapseTurns",title:t("Auto-collapse previous turns"),description:t("After you send a new message, fold earlier turns down to the question, timestamp and duration; the latest turn stays expanded"),checked:x,onChange:h}),e.jsx(Me,{rowId:"appearance.collapseCompletedActivity",title:t("Collapse activity after reply"),description:t("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(Me,{rowId:"appearance.collapseLiveActivity",title:t("Collapse finished activity while replying"),description:t("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:l,onChange:p,children:l?e.jsx(Em,{seconds:g,onCommit:w}):null}),e.jsx(Me,{rowId:"appearance.pinUnfinishedTodos",title:t("Pin unfinished todos"),description:t("Keep the latest todo list above the input while it has unfinished items, so it does not scroll away with the timeline"),checked:C,onChange:b}),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:t("Turn marks")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Marks along the conversation for each turn. Hover to preview, click to jump. Hidden when the chat uses the full width.")})]}),e.jsx("div",{className:"w-36 shrink-0",children:e.jsx(Pn,{value:N,options:[{value:"left",label:t("Left")},{value:"right",label:t("Right")},{value:"off",label:t("Off")}],onChange:y})})]})]}),e.jsx(Am,{}),e.jsx(_u,{})]})}function Pm({onOpenPlugins:t}){const{t:s}=z(),n=j(i=>i.themeId),a=j(i=>i.setThemeId),r=En(i=>i.themes),o=lo();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:s("Theme")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("Built-in and plugin themes; each one is a set of color tokens")})]}),e.jsx(ym,{themes:uo(r),selected:n,mode:o,onSelect:a,onGetMore:t})]})}function Tm(){const{t}=z(),s=j(r=>r.userCssEnabled),n=j(r=>r.setUserCssEnabled),a=async()=>{const r=await window.electronAPI.appearance.openUserCss();r.ok||_e({type:"error",title:t("Cannot open user.css"),description:r.error})};return e.jsxs(un,{rowId:"appearance.userCss",title:t("Custom CSS"),description:t("Inject user.css into every window; saved changes apply immediately"),children:[e.jsxs(I,{variant:"outline",size:"sm",onClick:()=>{a()},children:[e.jsx(fl,{}),t("Open user.css")]}),e.jsx(le,{checked:s,onCheckedChange:r=>n(r===!0),"aria-label":t("Custom CSS")})]})}function Rm({onOpenPlugins:t}={}){const s=j(B=>B.borderOpacity),n=j(B=>B.setBorderOpacity),{theme:a,setTheme:r,themeId:o,accentColor:i,setAccentColor:u,terminalTheme:d,setTerminalTheme:x,terminalFontSize:h,setTerminalFontSize:c,terminalFontFamily:f,setTerminalFontFamily:l,terminalFontWeight:p,setTerminalFontWeight:g,terminalFontWeightBold:w,setTerminalFontWeightBold:C,favoriteTerminalThemes:b,toggleFavoriteTerminalTheme:N}=j(),{t:y}=z(),S=lo(),D=En(B=>B.themes),k=[{value:"light",icon:bu,label:y("Light")},{value:"dark",icon:cl,label:y("Dark")},{value:"system",icon:Mn,label:y("System")},{value:"sync-terminal",icon:co,label:y("Sync terminal theme")}],O=dl.map(B=>({value:B,label:y(Im[B]),swatch:B==="theme"?ml(o,uo(D))[S].accent:ul[B][S]})),[E,M]=m.useState(h),[A,F]=m.useState(f),[V,v]=m.useState(!1);m.useEffect(()=>{M(h)},[h]),m.useEffect(()=>{F(f)},[f]);const U=m.useCallback(()=>{const B=Math.max(8,Math.min(32,E||8));B!==E&&M(B),B!==h&&c(B)},[E,h,c]),L=m.useCallback(()=>{const B=A.trim()||f;B!==A&&F(B),B!==f&&l(B)},[A,f,l]),K=m.useMemo(()=>hl(),[]),$=m.useMemo(()=>{if(!V)return K;const B=K.filter(ee=>b.includes(ee));return b.includes(d)?B:[d,...B]},[K,V,b,d]),G=V&&b.length===0,X=m.useMemo(()=>pl(d)??xl,[d]),oe=B=>{B&&x(B)},q=()=>{const B=V?$:K,ee=B.indexOf(d),R=ee<=0?B.length-1:ee-1;x(B[R])},ie=()=>{const B=V?$:K,ee=B.indexOf(d),R=ee>=B.length-1?0:ee+1;x(B[R])};return e.jsxs("div",{className:"space-y-6",children:[e.jsx(Pm,{onOpenPlugins:t}),e.jsxs("section",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:y("Personalization")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:y("Applied on top of any theme")})]}),e.jsxs(wm,{children:[e.jsx(un,{rowId:"appearance.theme",title:y("Theme mode"),children:e.jsx("div",{className:"flex rounded-lg bg-muted p-0.5",children:k.map(B=>e.jsxs("button",{type:"button",onClick:()=>r(B.value),"aria-pressed":a===B.value,className:H("flex h-7 items-center gap-1.5 rounded-md px-2.5 text-xs transition-colors",a===B.value?"bg-background text-foreground shadow-xs":"text-muted-foreground hover:text-foreground"),children:[e.jsx(B.icon,{className:"size-3.5"}),B.label]},B.value))})}),e.jsx(un,{rowId:"appearance.accent",title:y("Accent color"),description:y("Used for running state, checkmarks and plan mode"),children:O.map(B=>B.value==="theme"?e.jsxs("button",{type:"button",onClick:()=>u(B.value),"aria-pressed":i===B.value,className:H("flex h-6 items-center gap-1.5 rounded-full border px-2 text-xs transition-shadow",i===B.value&&"border-transparent ring-2 ring-foreground/60"),children:[e.jsx("span",{"data-theme-accent":!0,className:"size-2.5 rounded-full",style:{backgroundColor:B.swatch}}),B.label]},B.value):e.jsx("button",{type:"button",onClick:()=>u(B.value),title:B.label,"aria-label":B.label,"aria-pressed":i===B.value,style:{backgroundColor:B.swatch},className:H("size-5 rounded-full transition-shadow",i===B.value&&"ring-2 ring-offset-2 ring-offset-card ring-foreground/60")},B.value))}),e.jsx(Tm,{})]})]}),e.jsx(Mm,{}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:y("Terminal")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:y("Terminal appearance")})]}),e.jsx(km,{theme:X,fontSize:E,fontFamily:A,fontWeight:p}),e.jsxs("div",{className:"space-y-3 rounded-lg border bg-card p-3.5",children:[e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:y("Color scheme")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(I,{variant:"outline",size:"icon",onClick:q,children:e.jsx(mo,{className:"h-4 w-4"})}),e.jsx("div",{className:"flex-1",children:e.jsx(Sm,{value:d,onValueChange:oe,themes:$,favoriteThemes:b,onToggleFavorite:N,onThemeHover:x,showFavoritesOnly:V,onShowFavoritesOnlyChange:v,showEmptyFavoritesHint:G})}),e.jsx(I,{variant:"outline",size:"icon",onClick:ie,children:e.jsx(At,{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:y("Font")}),e.jsx(Y,{value:A,onChange:B=>F(B.target.value),onBlur:L,onKeyDown:B=>{B.nativeEvent.isComposing||B.key==="Enter"&&(L(),B.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:y("Font size")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Y,{type:"number",value:E,onChange:B=>M(Number(B.target.value)),onBlur:U,onKeyDown:B=>{B.key==="Enter"&&(U(),B.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:y("Font weight")}),e.jsxs(se,{items:Ut,value:p,onValueChange:B=>g(B),children:[e.jsx(ne,{className:"w-48",children:e.jsx(ae,{})}),e.jsx(re,{children:Ut.map(B=>e.jsx(Q,{value:B.value,children:B.label},B.value))})]})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:y("Bold font weight")}),e.jsxs(se,{items:Ut,value:w,onValueChange:B=>C(B),children:[e.jsx(ne,{className:"w-48",children:e.jsx(ae,{})}),e.jsx(re,{children:Ut.map(B=>e.jsx(Q,{value:B.value,children:B.label},B.value))})]})]})]}),e.jsx(Ze,{label:y("Border opacity"),value:Math.round(s*100),onCommit:B=>n(B/100)}),e.jsx(Nm,{})]})}const Ea=15e3,Om=3e3;function Dm(t){return!t||!t.timeoutSet&&t.timeoutMs===Om?Ea:t.timeoutMs}const Ma=()=>{},gs="off",js=t=>({timeoutMs:t?.timeoutMs??kl,...t?.timeoutSet&&{timeoutSet:!0}});function Lm({classifier:t,effectiveMs:s,hint:n,onChange:a}){const{t:r}=z(),[o,i]=m.useState(String(s/1e3));m.useEffect(()=>i(String(s/1e3)),[s]);const u=()=>{const d=Number(o);if(!o.trim()||!Number.isFinite(d))return i(String(s/1e3));const x=Il(d*1e3);i(String(x/1e3)),x!==s&&a({...t,timeoutMs:x,timeoutSet:!0})};return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs",children:r("Timeout")}),e.jsx(Y,{type:"number",value:o,min:Sl/1e3,max:Cl/1e3,step:.5,className:"h-7 w-20 text-xs",onChange:d=>i(d.target.value),onBlur:u,onKeyDown:d=>{d.key==="Enter"&&d.currentTarget.blur()}}),e.jsx("span",{className:"text-xs text-muted-foreground",children:r("seconds")}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:n})]})}function Qt({providers:t,value:s,emptyLabel:n,onSelect:a}){return e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx(Oe,{providers:t,providerId:s?.providerId??"",modelId:s?.modelId??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:n,side:"bottom",triggerClassName:Ye,onSelect:(r,o)=>a({providerId:r,modelId:o}),onReasoningChange:Ma,onThinkingChange:Ma})})}function Kt({label:t,hint:s,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:t}),s&&e.jsx("div",{className:"text-[10px] text-muted-foreground",children:s})]}),e.jsx("div",{className:"min-w-0 space-y-1",children:n})]})}function Xo({value:t,onChange:s,providers:n,classifierProviders:a,offLabel:r,judgeLabel:o,judgeSeed:i,description:u,effectiveTimeoutMs:d,timeoutHint:x}){const{t:h}=z(),c=t,[f,l]=m.useState(!1),p=c?.source??(f?"judge":gs),g=c?.source==="pi-classifier"?c.model.providerId:"",[w,C]=m.useState([]),[b,N]=m.useState(!1);m.useEffect(()=>{if(!g){C([]);return}let k=!1;return window.electronAPI.providers.classifierModels(g).then(O=>{k||C(O)}),()=>{k=!0}},[g]);const y=async k=>{const E=(await window.electronAPI.providers.classifierModels(k))[0];N(!E),E&&s({source:"pi-classifier",model:{providerId:k,modelId:E.id},...js(c)})},S=k=>{if(N(!1),l(k==="judge"&&!i),k===gs)return s(void 0);if(k==="judge")return s(i?{source:"judge",model:i,...js(c)}:void 0);const O=a[0];O&&y(O.id)},D=[{value:gs,label:r},{value:"judge",label:o},...a.length>0?[{value:"pi-classifier",label:h("Classifier model")}]:[]];return e.jsxs("div",{className:"space-y-1",children:[e.jsxs(se,{items:D,value:p,onValueChange:k=>S(String(k)),children:[e.jsx(ne,{size:"sm",className:"w-48",children:e.jsx(ae,{})}),e.jsx(re,{children:D.map(k=>e.jsx(Q,{value:k.value,children:k.label},k.value))})]}),p==="judge"&&e.jsx(Qt,{providers:n,value:c?.source==="judge"?c.model:void 0,emptyLabel:h("Select model"),onSelect:k=>{l(!1),s({source:"judge",model:k,...js(c)})}}),c?.source==="pi-classifier"&&e.jsxs("div",{className:"flex gap-1",children:[e.jsxs(se,{items:a.map(k=>({value:k.id,label:k.name})),value:c.model.providerId,onValueChange:k=>{y(String(k))},children:[e.jsx(ne,{size:"sm",className:"w-40",children:e.jsx(ae,{})}),e.jsx(re,{children:a.map(k=>e.jsx(Q,{value:k.id,children:k.name},k.id))})]}),e.jsxs(se,{items:w.map(k=>({value:k.id,label:k.name})),value:c.model.modelId||null,onValueChange:k=>s({...c,model:{providerId:c.model.providerId,modelId:String(k)}}),children:[e.jsx(ne,{size:"sm",className:"min-w-0 flex-1",children:e.jsx(ae,{placeholder:h("Select model")})}),e.jsx(re,{children:w.map(k=>e.jsx(Q,{value:k.id,children:k.name},k.id))})]})]}),b&&e.jsx("p",{className:"text-[10px] text-destructive",children:h("No classifier models available")}),c&&e.jsx(Lm,{classifier:c,effectiveMs:d??c.timeoutMs,hint:x,onChange:s}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:u})]})}function zm({entry:t,providers:s,classifierProviders:n,update:a}){const{t:r}=z();return t.fast?e.jsx(Xo,{value:t.classifier,onChange:o=>a({classifier:o}),providers:s,classifierProviders:n,offLabel:r("Off"),judgeLabel:r("Fast model judges"),judgeSeed:t.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 Bm({entry:t,providers:s,classifierProviders:n}){const{t:a}=z(),r=j(x=>x.updateVirtualModel),o=j(x=>x.removeVirtualModel),i=[t.primary,...t.fast?[t.fast]:[],...t.fallbacks];let u;for(const x of s){const h=x.models.find(c=>c.enabled!==!1&&!i.some(f=>f.providerId===x.id&&f.modelId===c.id));if(h){u={providerId:x.id,modelId:h.id};break}}const d=x=>r(t.id,x);return e.jsxs("div",{"data-slot":"virtual-model-card",className:H("space-y-2 rounded-md border p-2",!t.enabled&&"bg-muted/50 text-muted-foreground"),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(le,{"aria-label":a("Enable virtual model"),checked:t.enabled,onCheckedChange:x=>d({enabled:x})}),e.jsx(Y,{value:t.name,maxLength:60,placeholder:"Auto",className:"h-7 flex-1 text-xs",onChange:x=>d({name:x.target.value})}),!t.enabled&&e.jsx(te,{variant:"outline",className:"shrink-0 text-[10px] text-muted-foreground",children:a("Disabled")}),e.jsx(I,{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(t.id),children:e.jsx(Ee,{className:"h-3.5 w-3.5"})})]}),e.jsx(Kt,{label:a("Primary model"),hint:a("Default for each new turn"),children:e.jsx(Qt,{providers:s,value:t.primary,onSelect:x=>d({primary:x,fallbacks:t.fallbacks.filter(h=>h.providerId!==x.providerId||h.modelId!==x.modelId)})})}),e.jsx(Kt,{label:a("Fast model"),hint:a("Summaries and simple turns"),children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Qt,{providers:s,value:t.fast,emptyLabel:a("Not used"),onSelect:x=>d({fast:x})}),t.fast&&e.jsx(I,{type:"button",variant:"ghost",size:"icon","aria-label":a("Clear"),className:"h-6 w-6 shrink-0 text-muted-foreground",onClick:()=>d({fast:void 0}),children:e.jsx(Ct,{className:"h-3.5 w-3.5"})})]})}),e.jsxs(Kt,{label:a("Fallback models"),hint:a("Used in order when a model is rate limited or down"),children:[t.fallbacks.map((x,h)=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Qt,{providers:s,value:x,onSelect:c=>d({fallbacks:t.fallbacks.map((f,l)=>l===h?c:f)})}),e.jsx(I,{type:"button",variant:"ghost",size:"icon","aria-label":a("Delete"),className:"h-6 w-6 shrink-0 text-muted-foreground hover:text-destructive",onClick:()=>d({fallbacks:t.fallbacks.filter((c,f)=>f!==h)}),children:e.jsx(Ct,{className:"h-3.5 w-3.5"})})]},`${x.providerId}/${x.modelId}`)),e.jsxs(I,{type:"button",variant:"outline",size:"sm",className:"h-7 text-xs",disabled:!u||t.fallbacks.length>=8,onClick:()=>{u&&d({fallbacks:[...t.fallbacks,u]})},children:[e.jsx(Te,{className:"mr-1 h-3.5 w-3.5"}),a("Add fallback")]})]}),e.jsx(Kt,{label:a("Difficulty routing"),children:e.jsx(zm,{entry:t,providers:s,classifierProviders:n,update:d})})]})}function _m(){const{t}=z(),s=j(d=>d.virtualModels),n=j(d=>d.addVirtualModel),a=j(d=>d.defaultModel),r=Qe(),o=m.useMemo(()=>r.filter(xo),[r]),i=Rn(),u=m.useMemo(()=>{if(a&&o.find(x=>x.id===a.providerId)?.models.some(x=>x.id===a.modelId&&x.enabled!==!1))return a;for(const d of o){const x=d.models.find(h=>h.enabled!==!1);if(x)return{providerId:d.id,modelId:x.id}}return null},[o,a]);return e.jsxs("section",{"data-slot":"virtual-models",className:"space-y-2 rounded-lg border bg-card p-3",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium text-sm",children:t("Virtual models")}),e.jsx("p",{className:"mt-0.5 text-muted-foreground text-xs",children:t("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:t("Applies to newly started conversations.")})]}),e.jsxs("div",{className:"space-y-2",children:[s.map(d=>e.jsx(Bm,{entry:d,providers:o,classifierProviders:i},d.id)),e.jsxs(I,{type:"button",variant:"outline",size:"sm",className:"h-7 text-xs",disabled:!u,onClick:()=>{u&&n({name:"Auto",enabled:!0,primary:u,fallbacks:[]})},children:[e.jsx(Te,{className:"mr-1 h-3.5 w-3.5"}),t("New virtual model")]}),!u&&e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Enable a model and configure valid provider credentials first.")})]})]})}function Fm(){const{t}=z();return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:t("Bot mode")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("Settings shared by all members and group chats.")})]}),e.jsx(Vm,{}),e.jsx(Km,{}),e.jsx(Um,{}),e.jsx($m,{})]})}function Um(){const{t}=z(),s=j(r=>r.botModeEnabled),n=j(r=>r.botDiscussModeEnabled),a=j(r=>r.setBotDiscussModeEnabled);return s?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:t("Discussion mode")}),e.jsx(te,{variant:"warning",size:"sm","data-experimental-badge":"",children:t("Experimental feature")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Off: group chats work the same as the stable release. On: in smart-routing groups, discussion-style messages let the judge model pick who speaks next.")})]}),e.jsx(le,{checked:n,onCheckedChange:r=>a(r===!0)})]}):null}const Pa=Array.from({length:Al-ra+1},(t,s)=>ra+s);function $m(){const{t}=z(),s=j(a=>a.botMaxRunningTurns),n=j(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:t("Bot concurrency limit")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Shared by private chats, group chats, delegations and routines. Lowering it never interrupts running work; raising it may hit model rate limits.")})]}),e.jsxs(se,{items:Object.fromEntries(Pa.map(a=>[String(a),String(a)])),value:String(s),onValueChange:a=>n(Number(a)),children:[e.jsx(ne,{className:"w-20",children:e.jsx(ae,{})}),e.jsx(re,{children:Pa.map(a=>e.jsx(Q,{value:String(a),children:a},a))})]})]})}function Vm(){const{t}=z(),s=j(i=>i.botAssistantModel),n=j(i=>i.setBotAssistantModel),a=Qe(),r=s?a.find(i=>i.id===s.providerId):void 0,o=r?.models.find(i=>i.id===s?.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:t("Bot assistant model")}),e.jsx("p",{className:"mb-2 text-xs text-muted-foreground",children:t("Used for helper tasks such as auto-configuring member abilities.")}),e.jsx(Oe,{providers:a,providerId:o?r?.id??"":"",modelId:o?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:t("Follows the default model"),side:"bottom",triggerClassName:Ye,onSelect:(i,u)=>n({providerId:i,modelId:u}),onReasoningChange:()=>{},onThinkingChange:()=>{}}),s&&!o&&e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:t("Selected model is unavailable — falls back to the default model.")}),s&&e.jsx(I,{variant:"ghost",size:"sm",className:"mt-1",onClick:()=>n(null),children:t("Follow default model")})]})}function Km(){const{t}=z(),s=j(u=>u.botRouteClassifier),n=j(u=>u.setBotRouteClassifier),a=j(u=>u.botDiscussModeEnabled),r=Qe(),o=m.useMemo(()=>r.filter(xo),[r]),i=Rn();return e.jsxs("div",{className:"rounded-md border px-3 py-2.5","data-settings-row":"bots.routeClassifier",children:[e.jsx("p",{className:"text-sm",children:t("Group reply picker model")}),e.jsx("p",{className:"mb-2 text-xs text-muted-foreground",children:t("When nobody is @-mentioned in a smart-routing group, this model picks which member replies.")}),e.jsx(Xo,{value:s??void 0,onChange:u=>n(u??null),providers:o,classifierProviders:i,offLabel:t("Default (title model)"),judgeLabel:t("Fast chat model"),description:t(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:s?Dm(s):void 0,timeoutHint:t(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 qm=()=>({name:"",title:"",scope:"",summary:"",persona:"",color:rn[0],tools:"all",approvalMode:"auto-edits"}),mn=(t,s)=>({key:t,name:"",title:"",scope:"",persona:"",color:rn[s%rn.length],tools:"all",approvalMode:"auto-edits",canDelegateTo:[],acceptFrom:[]}),Gm=()=>({title:"",summary:"",bossKey:"m1",workspace:"chat-home",members:[mn("m1",0),mn("m2",1)]});function Hm(t,s){const n=URL.createObjectURL(new Blob([JSON.stringify(s,null,2)],{type:"application/json"})),a=document.createElement("a");a.href=n,a.download=t,a.click(),URL.revokeObjectURL(n)}function Wm(){const{t}=z(),s=El(!0),n=Ml(!0),[a,r]=m.useState(null),[o,i]=m.useState(null),u=m.useRef(null),d=async(p,g)=>{const w=await Vl(C=>({...C,[p]:g(C[p])}));return w||_e({type:"error",title:t("Could not save templates")}),w},x=(p,g)=>d("members",w=>p?la(w,p,g,Hl):ca(w,g,crypto.randomUUID())),h=(p,g)=>d("teams",w=>p?la(w,p,g,Wl):ca(w,g,crypto.randomUUID())),c=async p=>{const g=Dl(await p.text());if(!g.ok){_e({type:"error",title:oa(g.error,t)});return}const w=go(Ll(g.team));if(!w){_e({type:"error",title:oa("invalid",t)});return}await h(void 0,w)&&_e({type:"success",title:t("Imported as a custom team template")})},f=(p,g)=>d(p==="members"?"members":"teams",g),l=(p,g,w)=>e.jsxs(e.Fragment,{children:[e.jsx(ut,{label:t("Edit"),onClick:()=>w({id:g.id,data:g.data}),children:e.jsx(it,{})}),e.jsx(ut,{label:t("Duplicate as custom"),onClick:()=>w({data:g.data}),children:e.jsx(po,{})}),g.source==="builtin"&&e.jsx(ut,{label:g.hidden?t("Show"):t("Hide"),onClick:()=>{f(p,C=>Kl(C,g.id,!g.hidden))},children:g.hidden?e.jsx(Rl,{}):e.jsx(Ol,{})}),g.modified&&e.jsx(ut,{label:t("Restore default"),onClick:()=>{f(p,C=>da(C,g.id))},children:e.jsx(fo,{})}),g.source==="custom"&&e.jsx(ut,{label:t("Delete"),onClick:()=>{f(p,C=>da(C,g.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:t("Bot templates")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("Templates used when creating members and teams. Built-in templates can be edited, hidden or restored.")})]}),e.jsxs(zt,{defaultValue:"members",children:[e.jsxs(Bt,{variant:"underline",children:[e.jsx(Ke,{value:"members",children:t("Member templates")}),e.jsx(Ke,{value:"teams",children:t("Team templates")})]}),e.jsxs(Tt,{value:"members",className:"space-y-2 pt-3",children:[e.jsxs(I,{size:"sm",variant:"outline",onClick:()=>r({data:qm()}),children:[e.jsx(Te,{}),t("New member template")]}),s.map(p=>e.jsx(Ta,{item:p,avatar:e.jsx(an,{bot:{name:p.data.name,avatar:{color:p.data.color}}}),title:p.data.name,subtitle:p.data.title,summary:p.data.summary,actions:l("members",p,r)},p.id))]}),e.jsxs(Tt,{value:"teams",className:"space-y-2 pt-3",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(I,{size:"sm",variant:"outline",onClick:()=>i({data:Gm()}),children:[e.jsx(Te,{}),t("New team template")]}),e.jsxs(I,{size:"sm",variant:"outline",onClick:()=>u.current?.click(),children:[e.jsx(Pl,{}),t("Import team (JSON)")]}),e.jsx("input",{ref:u,type:"file",accept:".json,application/json",hidden:!0,onChange:p=>{const g=p.target.files?.[0];p.target.value="",g&&c(g)}})]}),n.map(p=>e.jsx(Ta,{item:p,avatar:e.jsx("div",{className:"-space-x-1.5 flex shrink-0",children:p.data.members.slice(0,4).map(g=>e.jsx(an,{size:"sm",bot:{name:g.name,avatar:{color:g.color}}},g.key))}),title:p.data.title,subtitle:t("{{n}} members",{n:p.data.members.length}),summary:p.data.summary,actions:e.jsxs(e.Fragment,{children:[e.jsx(ut,{label:t("Export JSON"),onClick:()=>Hm(`${p.data.title||"team"}.team.json`,{format:Gl,version:ql,exportedAt:new Date().toISOString(),team:Tl(p.data)}),children:e.jsx(bn,{})}),l("teams",p,i)]})},p.id))]})]}),a&&e.jsx(Ym,{initial:a.data,onClose:()=>r(null),onSave:async p=>{await x(a.id,p)&&r(null)}}),o&&e.jsx(Qm,{initial:o.data,onClose:()=>i(null),onSave:async p=>{await h(o.id,p)&&i(null)}})]})}function ut({label:t,onClick:s,disabled:n,children:a}){return e.jsx(I,{variant:"ghost",size:"icon-sm",title:t,"aria-label":t,disabled:n,onClick:s,children:a})}function Ta({item:t,avatar:s,title:n,subtitle:a,summary:r,actions:o}){const{t:i}=z();return e.jsxs("div",{className:"flex items-center gap-3 rounded-md border px-3 py-2.5","data-template-id":t.id,children:[e.jsxs("div",{className:H("flex min-w-0 flex-1 items-center gap-3",t.hidden&&"opacity-50"),children:[s,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(te,{variant:"secondary",children:t.source==="custom"?i("Custom"):i("Built-in")}),t.modified&&e.jsx(te,{variant:"outline",children:i("Modified")}),t.hidden&&e.jsx(te,{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 Zo({title:t,error:s,onClose:n,onSave:a,children:r}){const{t:o}=z(),[i,u]=m.useState(!1);return e.jsx(fe,{open:!0,onOpenChange:d=>!d&&n(),children:e.jsxs(ge,{className:"max-h-[85vh] max-w-2xl",children:[e.jsx(je,{children:e.jsx(ve,{children:t})}),e.jsxs(we,{className:"space-y-3",children:[r,s&&e.jsx("p",{className:"text-destructive text-xs",children:s})]}),e.jsxs(Ie,{children:[e.jsx(I,{variant:"outline",size:"sm",onClick:n,children:o("Cancel")}),e.jsx(I,{size:"sm",disabled:i||!!s,onClick:()=>{u(!0),a().finally(()=>u(!1))},children:o("Save")})]})]})})}function ei({value:t,onChange:s}){const{t:n}=z(),a=t.name?jo(t.name,[],n):null;return e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(Be,{children:n("Name")}),e.jsx(Y,{value:t.name,onChange:r=>s({name:r.target.value})}),a&&e.jsx("p",{className:"mt-1 text-destructive text-xs",children:a})]}),e.jsxs("div",{children:[e.jsx(Be,{children:n("Title")}),e.jsx(Y,{value:t.title,onChange:r=>s({title:r.target.value})})]}),e.jsxs("div",{children:[e.jsx(Be,{children:n("Avatar color")}),e.jsx(Ul,{value:t.color,onChange:r=>s({color:r})})]}),e.jsxs("div",{children:[e.jsx(Be,{children:n("Tools")}),e.jsx(Pn,{value:t.tools,options:[{value:"all",label:n("All tools")},{value:"readonly",label:n("Read-only")}],onChange:r=>s({tools:r})})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(Be,{children:n("Approval mode")}),e.jsx($l,{value:t.approvalMode,onChange:r=>s({approvalMode:r}),zIndex:et.DROPDOWN_IN_MODAL})]}),t.summary!==void 0&&e.jsxs("div",{className:"col-span-2",children:[e.jsx(Be,{hint:n("Shown on the template card"),children:n("Summary")}),e.jsx(Y,{value:t.summary,onChange:r=>s({summary:r.target.value})})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(Be,{children:n("Responsibilities")}),e.jsx(Y,{value:t.scope,onChange:r=>s({scope:r.target.value})})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(Be,{children:n("Persona")}),e.jsx(He,{rows:6,value:t.persona,onChange:r=>s({persona:r.target.value})})]})]})}function Ym({initial:t,onClose:s,onSave:n}){const{t:a}=z(),[r,o]=m.useState(t),i=zl(r);return e.jsx(Zo,{title:a("Member template"),error:jo(r.name,[],a)??(i?null:a("Check the template fields")),onClose:s,onSave:()=>i?n(i):Promise.resolve(),children:e.jsx(ei,{value:r,onChange:u=>o(d=>({...d,...u}))})})}function Jm(t,s){switch(t){case"title":return s("Enter a team title");case"members":return s("A team needs 2–12 members");case"name":return s("Every member needs a valid name");case"invalid":return s("Check the template fields");default:return null}}function Qm({initial:t,onClose:s,onSave:n}){const{t:a}=z(),[r,o]=m.useState(t),[i,u]=m.useState(null),d=p=>r.members.find(g=>g.key===p)?.name||p,x=p=>o(g=>({...g,...p})),h=(p,g)=>o(w=>({...w,members:w.members.map(C=>C.key===p?{...C,...g}:C)})),c=()=>{const p=new Set(r.members.map(C=>C.key));let g=r.members.length+1;for(;p.has(`m${g}`);)g++;const w=`m${g}`;x({members:[...r.members,mn(w,r.members.length)]}),u(w)},f=p=>{const g=w=>w==="any"?"any":w.filter(C=>C!==p);x({members:r.members.filter(w=>w.key!==p).map(w=>({...w,canDelegateTo:g(w.canDelegateTo),acceptFrom:g(w.acceptFrom)}))})},l=go(r);return e.jsxs(Zo,{title:a("Team template"),error:Jm(Fl(r),a),onClose:s,onSave:()=>l?n(l):Promise.resolve(),children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(Be,{children:a("Group name")}),e.jsx(Y,{value:r.title,onChange:p=>x({title:p.target.value})})]}),e.jsxs("div",{children:[e.jsx(Be,{children:a("Owner")}),e.jsxs(se,{items:r.members.map(p=>({value:p.key,label:d(p.key)})),value:r.bossKey,onValueChange:p=>x({bossKey:p}),children:[e.jsx(ne,{className:"w-full",children:e.jsx(ae,{})}),e.jsx(re,{zIndex:et.DROPDOWN_IN_MODAL,children:r.members.map(p=>e.jsx(Q,{value:p.key,children:d(p.key)},p.key))})]})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(Be,{hint:a("Shown on the template card"),children:a("Summary")}),e.jsx(Y,{value:r.summary,onChange:p=>x({summary:p.target.value})})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(Be,{children:a("Shared workspace")}),e.jsx(Pn,{value:r.workspace,options:[{value:"chat-home",label:a("Standalone workspace")},{value:"project",label:a("Based on a Code project")}],onChange:p=>x({workspace:p})})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1.5 flex items-center justify-between",children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:a("Members")}),e.jsxs(I,{size:"xs",variant:"outline",disabled:r.members.length>=Bl,onClick:c,children:[e.jsx(Te,{}),a("Add member")]})]}),e.jsx("div",{className:"space-y-1.5",children:r.members.map(p=>{const g=i===p.key,w=p.key===r.bossKey,C=r.members.filter(b=>b.key!==p.key).map(b=>b.key);return e.jsxs("div",{className:"rounded-lg border","data-member-key":p.key,children:[e.jsxs("div",{className:"flex items-center gap-2 px-2.5 py-2",children:[e.jsxs("button",{type:"button",className:"flex min-w-0 flex-1 items-center gap-2 text-left",onClick:()=>u(g?null:p.key),children:[g?e.jsx(Zt,{className:"h-3.5 w-3.5 shrink-0"}):e.jsx(At,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx(an,{bot:{name:p.name,avatar:{color:p.color}},size:"sm"}),e.jsx("span",{className:"truncate text-sm",children:p.name||a("Unnamed")}),e.jsx("span",{className:"truncate text-muted-foreground text-xs",children:p.title}),w&&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(_l,{className:"h-3 w-3"}),a("Owner")]})]}),e.jsx(ut,{label:a("Remove"),disabled:w||r.members.length<=2,onClick:()=>f(p.key),children:e.jsx(Ee,{})})]}),g&&e.jsxs("div",{className:"space-y-3 border-t p-2.5",children:[e.jsx(ei,{value:p,onChange:b=>h(p.key,b)}),e.jsx(ia,{label:a("Can delegate to"),value:p.canDelegateTo,options:C,nameOf:d,onChange:b=>h(p.key,{canDelegateTo:b})}),e.jsx(ia,{label:a("Accepts delegation from"),value:p.acceptFrom,options:C,nameOf:d,onChange:b=>h(p.key,{acceptFrom:b})})]})]},p.key)})})]})]})}function ti(t){return t.capturePermission==="unsupported"&&t.axPermission==="unsupported"?"unsupported":t.capturePermission==="granted"&&(t.axPermission==="granted"||t.axPermission==="unsupported")?"ready":"needs-permission"}const Xm=[{id:"collaboration",label:"Collaboration & planning"},{id:"web",label:"Web"},{id:"execution",label:"Execution"},{id:"context",label:"Context & memory"},{id:"safety",label:"Safety"}],Ra={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"};function Zm(t,s){return t.filter(n=>Object.hasOwn(Ra,n.id)?Ra[n.id]===s:!1)}function Oa(t){return t.bundleId||t.path}function eh(){const{t}=z(),[s,n]=m.useState(null),a=j(i=>i.computerAllowAllApps),r=j(i=>i.setComputerAllowAllApps);m.useEffect(()=>{let i=!1;return window.electronAPI.computer.allowedApps().then(u=>{i||n(u)}),()=>{i=!0}},[]);const o=async i=>{await window.electronAPI.computer.revokeApp(Oa(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:t("Apps the AI may control")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("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:t("Allow all apps")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("The AI can click, type and read in any app without asking. It can see everything in their windows, including chats and passwords.")})]}),e.jsx(le,{checked:a,onCheckedChange:r})]}),s&&s.length===0?e.jsx("p",{className:"text-muted-foreground text-xs",children:t("No apps are always allowed yet.")}):null,s&&s.length>0?e.jsx("ul",{className:"divide-y rounded-md border",children:s.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(I,{variant:"outline",size:"sm",onClick:()=>{o(i)},children:t("Revoke")})]},Oa(i)))}):null]})}function th(t){return Object.fromEntries(t.map(s=>[s.id,s]))}function os(t,s){return t.reduce((n,a)=>{const r=s[a]?.tokens;return r==null?n:n+r},0)}function is({row:t,pending:s}){const{t:n}=z(),a=s?"…":t?.tokens==null?"—":Ue(t.tokens);return e.jsx("span",{className:"w-12 shrink-0 text-right text-muted-foreground text-xs tabular-nums",title:t?.error||n("Estimate"),children:a})}function ls({tokens:t}){return t<=0?null:e.jsx("span",{className:"ml-2 font-normal text-muted-foreground text-xs tabular-nums",children:Ue(t)})}function cs(t,s){const[n,a]=m.useState({}),[r,o]=m.useState(()=>t.length>0),i=t.join("\0"),u=m.useRef(s);return u.current=s,m.useEffect(()=>{let d=!1;const x=i.length===0?[]:i.split("\0");if(x.length===0){a({}),o(!1);return}return o(!0),u.current(x).then(h=>{d||a(th(h))}).finally(()=>{d||o(!1)}),()=>{d=!0}},[i]),{rows:n,pending:r}}const Da={replace:"Text replacement",apply_patch:"Apply patch (default)"},sh={subagent:tc,workflow:On,todo:ec,plan:Zl,ask_user:Xl,browser:Ql,web:bo,background_tasks:Jl,memory:vo,isolated_sandbox:Qd,computer:Mn};function yt({icon:t,title:s,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(t,{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:[s,i&&e.jsx(qe,{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 nh({disabled:t}){const{t:s}=z(),n=j(c=>c.webSearchChain),a=j(c=>c.setWebSearchChain),r=_t(),o=m.useMemo(()=>ac(r),[r]),[i,u]=m.useState(null),d=(c,f)=>{a(n.map((l,p)=>p===c?{...l,...f}:l))},x=c=>a(n.filter((f,l)=>l!==c)),h=(c,f)=>{if(c===f)return;const l=[...n],[p]=l.splice(c,1);p&&(l.splice(f,0,p),a(l))};return e.jsxs("div",{className:"space-y-2","data-settings-row":"tools.webSearchChain",children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:s("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:s("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:!t,onDragStart:l=>{l.dataTransfer.effectAllowed="move",u(f)},onDragEnd:()=>u(null),onDragOver:l=>{i!==null&&i!==f&&l.preventDefault()},onDrop:l=>{l.preventDefault(),i!==null&&h(i,f),u(null)},children:[e.jsx(rc,{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(Oe,{providers:o,providerId:c.providerId,modelId:c.modelId,reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,onSelect:(l,p)=>d(f,{providerId:l,modelId:p}),onReasoningChange:()=>{},onThinkingChange:()=>{}})}),e.jsx(I,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 shrink-0 p-0",disabled:t,onClick:()=>x(f),"aria-label":s("Remove"),children:e.jsx(Ee,{className:"h-3.5 w-3.5"})})]},`${c.providerId}/${c.modelId}`)),n.length<oc&&e.jsx("div",{className:"max-w-xs",children:e.jsx(Oe,{providers:o,providerId:"",modelId:"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,triggerLabel:`+ ${s("Add candidate")}`,onSelect:(c,f)=>a([...n,{providerId:c,modelId:f}]),onReasoningChange:()=>{},onThinkingChange:()=>{}})}),e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Final fallback: Exa (keyless hosted search). Not a chain entry; always last.")})]})}function ah(){const{t}=z(),s=j(v=>v.disabledBuiltinTools),n=j(v=>v.toggleBuiltinTool),a=j(v=>v.subagentAllowedModes),r=j(v=>v.setSubagentAllowedModes),o=j(v=>v.exploreFoldEnabled),i=j(v=>v.setExploreFoldEnabled),u=j(v=>v.rtkEnabled),d=j(v=>v.computerPreview),x=j(v=>v.setComputerPreview),h=j(v=>v.openLinksInBuiltinBrowser),c=j(v=>v.setOpenLinksInBuiltinBrowser),f=j(v=>v.setRtkEnabled),l=j(v=>v.protectedActionsInCode),p=j(v=>v.setProtectedActionsInCode),g=j(v=>v.editMode),w=j(v=>v.setEditMode),C=cs(fs.map(v=>v.id),()=>window.electronAPI.assets.builtinToolOccupancy()),b=os(fs.filter(v=>!s.includes(v.id)).map(v=>v.id),C.rows),[N,y]=m.useState(null),S=!s.includes("subagent"),D=(v,U)=>{r(U?[...new Set([...a,v])]:a.filter(L=>L!==v))},k=async v=>{await window.electronAPI.browser.clearData(v),y(v),setTimeout(()=>y(null),2e3)},O=!s.includes("computer"),[E,M]=m.useState(null),[A,F]=m.useState(!1);m.useEffect(()=>{if(!O){M(null);return}let v=!1;return window.electronAPI.computer.capabilities().then(U=>{!v&&U.ok&&M(U.capabilities)}),()=>{v=!0}},[O]),m.useEffect(()=>{if(!A)return;let v=!1;const U=()=>{window.electronAPI.computer.capabilities().then(K=>{!v&&K.ok&&M(K.capabilities)})};U();const L=window.setInterval(U,2e3);return()=>{v=!0,window.clearInterval(L)}},[A]);const V={collaboration:null,web:null,execution:e.jsx(yt,{rowId:"tools.editMode",newSession:!0,icon:nu,title:t("File edit mode"),description:t("Choose how files are modified. Apply patch is the default. New and cold-restored sessions use this mode; already warm sessions keep their current mode."),control:e.jsxs(se,{items:Object.fromEntries(ua.map(v=>[v,t(Da[v])])),value:g,onValueChange:v=>{Yl(v)&&w(v)},children:[e.jsx(ne,{className:"w-44 shrink-0","aria-label":t("File edit mode"),children:e.jsx(ae,{})}),e.jsx(re,{children:ua.map(v=>e.jsx(Q,{value:v,children:t(Da[v])},v))})]})}),context:e.jsxs(e.Fragment,{children:[e.jsx(yt,{icon:iu,newSession:!0,title:t("Explore fold"),description:t("Let the agent mark exploratory reads and keep only a short report in later model context. Timeline stays intact."),control:e.jsx(le,{checked:o,onCheckedChange:i})}),e.jsx(yt,{rowId:"tools.rtkEnabled",newSession:!0,icon:fu,title:t("RTK command compression"),description:t("Compress supported command output before it enters the model context. Takes effect on new conversations."),control:e.jsx(le,{checked:u,onCheckedChange:f})})]}),safety:e.jsxs(e.Fragment,{children:[e.jsx(yt,{icon:yn,newSession:!0,title:t("Protected action confirmation"),description:t("Even in full-access mode, ask before external sends, deletions, payments, deployments and secret-file access. Always on for Bot members not set to Full access. Takes effect on new conversations."),control:e.jsx(le,{checked:l,onCheckedChange:p})}),e.jsx(rh,{})]})};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:[t("Built-in tools"),e.jsx(ls,{tokens:b})]}),e.jsx("p",{className:"text-muted-foreground text-sm",children:t("Toggle the built-in tools available to agents.")})]}),Xm.map(v=>e.jsxs("section",{className:"space-y-3",children:[e.jsx("h4",{className:"border-b pb-2 text-base font-semibold",children:t(v.label)}),Zm(fs,v.id).map(U=>e.jsxs(yt,{icon:sh[U.id]??yo,title:t(U.name),description:t(U.description),newSession:U.id==="isolated_sandbox"?t("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(is,{row:C.rows[U.id],pending:C.pending&&!C.rows[U.id]}),e.jsx(le,{checked:!s.includes(U.id),onCheckedChange:L=>{n(U.id,L),U.id==="computer"&&L&&F(!0)}})]}),children:[U.id==="web"?e.jsx(nh,{disabled:s.includes("web")}):null,U.id==="subagent"?e.jsxs("div",{className:"space-y-2","data-settings-row":"tools.subagentModes",children:[[["task","One-shot task agents"],["coworker","Persistent coworkers"]].map(([L,K])=>e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("span",{className:"text-sm",children:t(K)}),e.jsx(le,{checked:a.includes(L),disabled:!S,onCheckedChange:$=>D(L,$)})]},L)),!S&&e.jsx("p",{className:"text-muted-foreground text-xs",children:t("The unified subagent tool is off. Re-enabling it keeps this mode selection.")})]}):null,U.id==="computer"&&O?e.jsx("div",{className:"space-y-2","data-settings-row":"tools.computer",children:E&&ti(E)==="unsupported"?e.jsx("p",{className:"text-muted-foreground text-xs",children:t("This platform cannot operate the desktop yet.")}):e.jsxs(e.Fragment,{children:[E?.platform==="darwin"&&e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Computer needs Screen Recording to capture windows and Accessibility to inspect or click them. Grant both to EnsoCode, then restart the app.")}),E&&e.jsxs("p",{className:"text-muted-foreground text-xs",children:[t(E.capturePermission==="granted"?"Capture: granted":"Capture: denied"),E.axPermission!=="unsupported"&&e.jsxs(e.Fragment,{children:[" · ",t(E.axPermission==="granted"?"Input/AX: granted":"Input/AX: denied")]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(I,{variant:"outline",size:"sm",onClick:()=>F(!0),children:t("Show permission guide")}),E?.platform==="darwin"&&e.jsxs(e.Fragment,{children:[e.jsx(I,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.computer.openPermissions("screen")},children:t("Open Screen Recording settings")}),e.jsx(I,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.computer.openPermissions("accessibility")},children:t("Open Accessibility settings")})]})]}),E?.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:t("Show the app being operated")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("While the AI works in an app in the background, a small floating window shows that app live. Close it any time.")})]}),e.jsx(le,{checked:d,onCheckedChange:x})]}),e.jsx(eh,{})]})]})}):null,U.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:t("Open chat links in the built-in browser")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Clicking a web link in chat opens it in the side panel browser. {{key}}+Click opens it in the external browser.",{key:sc?"Cmd":"Ctrl"})})]}),e.jsx(le,{checked:h,onCheckedChange:c})]}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("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(L=>e.jsx(I,{variant:"outline",size:"sm",onClick:()=>{k(L)},children:t(N===L?"Cleared":L==="cookies"?"Clear cookies":L==="cache"?"Clear cache":"Clear all browsing data")},L))})]}):null]},U.id)),V[v.id]]},v.id)),e.jsx(oh,{open:A,capabilities:E,onOpenChange:F})]})}function rh(){const{t}=z(),s=j(l=>l.dcgEnabled),n=j(l=>l.setDcgEnabled),[a,r]=m.useState(null),[o,i]=m.useState(!1),[u,d]=m.useState(null),[x,h]=m.useState(!1);m.useEffect(()=>{let l=!1;return window.electronAPI.dcg.status().then(p=>{l||r(p)}),()=>{l=!0}},[]);const c=async l=>{h(!1),i(!0),d(null);const p=await window.electronAPI.dcg[l]();r(p.status),p.ok?n(l==="install"):d(p.error??t("Operation failed")),i(!1)},f=a?.installed===!0;return e.jsxs(yt,{rowId:"tools.dcgEnabled",newSession:!0,icon:nc,title:t("Destructive command guard (dcg)"),description:t("Check bash and PowerShell commands with dcg before running. Matches such as git reset --hard or recursive deletes always require your confirmation, even in full-access mode. Takes effect on new conversations."),control:e.jsx(le,{checked:s&&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?t("Installed v{{version}}",{version:a.version}):t("Not installed"):t("Not available on this platform"):t("Loading…")}),a?.supported&&(f?e.jsx(I,{variant:"outline",size:"xs",disabled:o,onClick:()=>{c("uninstall")},children:t("Uninstall")}):e.jsx(I,{variant:"outline",size:"xs",disabled:o,onClick:()=>h(!0),children:t(o?"Installing…":"Install")}))]}),u&&e.jsx("p",{className:"text-destructive text-xs",children:u}),e.jsx(fe,{open:x,onOpenChange:h,children:e.jsxs(ge,{className:"max-w-md",zIndexLevel:"nested",children:[e.jsxs(je,{children:[e.jsx(ve,{children:t("Install dcg")}),e.jsx($e,{children:t("Downloads dcg v{{version}} from its GitHub release and verifies the checksum. dcg is a third-party tool, not part of EnsoCode.",{version:a?.version??""})})]}),e.jsx(we,{children:e.jsxs("div",{className:"flex gap-2 rounded-md border border-destructive/32 bg-destructive/8 p-3 text-sm",children:[e.jsx(Fe,{className:"mt-0.5 h-4 w-4 shrink-0 text-destructive"}),e.jsx("p",{children:t("dcg is licensed under MIT with an additional rider: no rights are granted to OpenAI, Anthropic, their affiliates, or anyone acting on their behalf. Install only if this restriction does not apply to you.")})]})}),e.jsxs(Ie,{children:[e.jsx(I,{variant:"outline",size:"sm",onClick:()=>h(!1),children:t("Cancel")}),e.jsx(I,{size:"sm",onClick:()=>{c("install")},children:t("Agree and install")})]})]})})]})}function oh({open:t,capabilities:s,onOpenChange:n}){const{t:a}=z(),r=s?ti(s):null;return e.jsx(fe,{open:t,onOpenChange:n,children:e.jsxs(ge,{className:"max-w-md",zIndexLevel:"nested",children:[e.jsxs(je,{children:[e.jsx(ve,{children:a("Grant Computer permissions")}),e.jsx($e,{children:a(r==="unsupported"?"This platform cannot operate the desktop yet.":r==="ready"?"Computer is ready. Open sessions can use it from their next step.":"The agent can screenshot windows and control the mouse and keyboard. Grant Screen Recording and Accessibility to EnsoCode, then restart.")})]}),e.jsxs(we,{className:"space-y-3",children:[!s&&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(Fe,{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.")})]}),s?.platform==="darwin"&&r!=="unsupported"&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("p",{className:"text-muted-foreground text-xs",children:[a(s.capturePermission==="granted"?"Capture: granted":"Capture: denied")," · ",a(s.axPermission==="granted"?"Input/AX: granted":"Input/AX: denied"),s.detail?` · ${s.detail}`:""]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(I,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.computer.openPermissions("screen")},children:a("Open Screen Recording settings")}),e.jsx(I,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.computer.openPermissions("accessibility")},children:a("Open Accessibility settings")})]})]})]}),e.jsx(Ie,{className:"sm:justify-end",children:e.jsx(I,{size:"sm",onClick:()=>n(!1),children:a("Done")})})]})})}function ih(t){if(t==null||!Number.isFinite(t)||t<0)return null;const s=Math.round(t);return s<1?"<1ms":`${s}ms`}var gt={},vs,La;function lh(){return La||(La=1,vs=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then}),vs}var bs={},at={},za;function mt(){if(za)return at;za=1;let t;const s=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706];return at.getSymbolSize=function(a){if(!a)throw new Error('"version" cannot be null or undefined');if(a<1||a>40)throw new Error('"version" should be in range from 1 to 40');return a*4+17},at.getSymbolTotalCodewords=function(a){return s[a]},at.getBCHDigit=function(n){let a=0;for(;n!==0;)a++,n>>>=1;return a},at.setToSJISFunction=function(a){if(typeof a!="function")throw new Error('"toSJISFunc" is not a valid function.');t=a},at.isKanjiModeEnabled=function(){return typeof t<"u"},at.toSJIS=function(a){return t(a)},at}var ys={},Ba;function Un(){return Ba||(Ba=1,(function(t){t.L={bit:1},t.M={bit:0},t.Q={bit:3},t.H={bit:2};function s(n){if(typeof n!="string")throw new Error("Param is not a string");switch(n.toLowerCase()){case"l":case"low":return t.L;case"m":case"medium":return t.M;case"q":case"quartile":return t.Q;case"h":case"high":return t.H;default:throw new Error("Unknown EC Level: "+n)}}t.isValid=function(a){return a&&typeof a.bit<"u"&&a.bit>=0&&a.bit<4},t.from=function(a,r){if(t.isValid(a))return a;try{return s(a)}catch{return r}}})(ys)),ys}var ws,_a;function ch(){if(_a)return ws;_a=1;function t(){this.buffer=[],this.length=0}return t.prototype={get:function(s){const n=Math.floor(s/8);return(this.buffer[n]>>>7-s%8&1)===1},put:function(s,n){for(let a=0;a<n;a++)this.putBit((s>>>n-a-1&1)===1)},getLengthInBits:function(){return this.length},putBit:function(s){const n=Math.floor(this.length/8);this.buffer.length<=n&&this.buffer.push(0),s&&(this.buffer[n]|=128>>>this.length%8),this.length++}},ws=t,ws}var Ns,Fa;function dh(){if(Fa)return Ns;Fa=1;function t(s){if(!s||s<1)throw new Error("BitMatrix size must be defined and greater than 0");this.size=s,this.data=new Uint8Array(s*s),this.reservedBit=new Uint8Array(s*s)}return t.prototype.set=function(s,n,a,r){const o=s*this.size+n;this.data[o]=a,r&&(this.reservedBit[o]=!0)},t.prototype.get=function(s,n){return this.data[s*this.size+n]},t.prototype.xor=function(s,n,a){this.data[s*this.size+n]^=a},t.prototype.isReserved=function(s,n){return this.reservedBit[s*this.size+n]},Ns=t,Ns}var ks={},Ua;function uh(){return Ua||(Ua=1,(function(t){const s=mt().getSymbolSize;t.getRowColCoords=function(a){if(a===1)return[];const r=Math.floor(a/7)+2,o=s(a),i=o===145?26:Math.ceil((o-13)/(2*r-2))*2,u=[o-7];for(let d=1;d<r-1;d++)u[d]=u[d-1]-i;return u.push(6),u.reverse()},t.getPositions=function(a){const r=[],o=t.getRowColCoords(a),i=o.length;for(let u=0;u<i;u++)for(let d=0;d<i;d++)u===0&&d===0||u===0&&d===i-1||u===i-1&&d===0||r.push([o[u],o[d]]);return r}})(ks)),ks}var Cs={},$a;function mh(){if($a)return Cs;$a=1;const t=mt().getSymbolSize,s=7;return Cs.getPositions=function(a){const r=t(a);return[[0,0],[r-s,0],[0,r-s]]},Cs}var Ss={},Va;function hh(){return Va||(Va=1,(function(t){t.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};const s={N1:3,N2:3,N3:40,N4:10};t.isValid=function(r){return r!=null&&r!==""&&!isNaN(r)&&r>=0&&r<=7},t.from=function(r){return t.isValid(r)?parseInt(r,10):void 0},t.getPenaltyN1=function(r){const o=r.size;let i=0,u=0,d=0,x=null,h=null;for(let c=0;c<o;c++){u=d=0,x=h=null;for(let f=0;f<o;f++){let l=r.get(c,f);l===x?u++:(u>=5&&(i+=s.N1+(u-5)),x=l,u=1),l=r.get(f,c),l===h?d++:(d>=5&&(i+=s.N1+(d-5)),h=l,d=1)}u>=5&&(i+=s.N1+(u-5)),d>=5&&(i+=s.N1+(d-5))}return i},t.getPenaltyN2=function(r){const o=r.size;let i=0;for(let u=0;u<o-1;u++)for(let d=0;d<o-1;d++){const x=r.get(u,d)+r.get(u,d+1)+r.get(u+1,d)+r.get(u+1,d+1);(x===4||x===0)&&i++}return i*s.N2},t.getPenaltyN3=function(r){const o=r.size;let i=0,u=0,d=0;for(let x=0;x<o;x++){u=d=0;for(let h=0;h<o;h++)u=u<<1&2047|r.get(x,h),h>=10&&(u===1488||u===93)&&i++,d=d<<1&2047|r.get(h,x),h>=10&&(d===1488||d===93)&&i++}return i*s.N3},t.getPenaltyN4=function(r){let o=0;const i=r.data.length;for(let d=0;d<i;d++)o+=r.data[d];return Math.abs(Math.ceil(o*100/i/5)-10)*s.N4};function n(a,r,o){switch(a){case t.Patterns.PATTERN000:return(r+o)%2===0;case t.Patterns.PATTERN001:return r%2===0;case t.Patterns.PATTERN010:return o%3===0;case t.Patterns.PATTERN011:return(r+o)%3===0;case t.Patterns.PATTERN100:return(Math.floor(r/2)+Math.floor(o/3))%2===0;case t.Patterns.PATTERN101:return r*o%2+r*o%3===0;case t.Patterns.PATTERN110:return(r*o%2+r*o%3)%2===0;case t.Patterns.PATTERN111:return(r*o%3+(r+o)%2)%2===0;default:throw new Error("bad maskPattern:"+a)}}t.applyMask=function(r,o){const i=o.size;for(let u=0;u<i;u++)for(let d=0;d<i;d++)o.isReserved(d,u)||o.xor(d,u,n(r,d,u))},t.getBestMask=function(r,o){const i=Object.keys(t.Patterns).length;let u=0,d=1/0;for(let x=0;x<i;x++){o(x),t.applyMask(x,r);const h=t.getPenaltyN1(r)+t.getPenaltyN2(r)+t.getPenaltyN3(r)+t.getPenaltyN4(r);t.applyMask(x,r),h<d&&(d=h,u=x)}return u}})(Ss)),Ss}var qt={},Ka;function si(){if(Ka)return qt;Ka=1;const t=Un(),s=[1,1,1,1,1,1,1,1,1,1,2,2,1,2,2,4,1,2,4,4,2,4,4,4,2,4,6,5,2,4,6,6,2,5,8,8,4,5,8,8,4,5,8,11,4,8,10,11,4,9,12,16,4,9,16,16,6,10,12,18,6,10,17,16,6,11,16,19,6,13,18,21,7,14,21,25,8,16,20,25,8,17,23,25,9,17,23,34,9,18,25,30,10,20,27,32,12,21,29,35,12,23,34,37,12,25,34,40,13,26,35,42,14,28,38,45,15,29,40,48,16,31,43,51,17,33,45,54,18,35,48,57,19,37,51,60,19,38,53,63,20,40,56,66,21,43,59,70,22,45,62,74,24,47,65,77,25,49,68,81],n=[7,10,13,17,10,16,22,28,15,26,36,44,20,36,52,64,26,48,72,88,36,64,96,112,40,72,108,130,48,88,132,156,60,110,160,192,72,130,192,224,80,150,224,264,96,176,260,308,104,198,288,352,120,216,320,384,132,240,360,432,144,280,408,480,168,308,448,532,180,338,504,588,196,364,546,650,224,416,600,700,224,442,644,750,252,476,690,816,270,504,750,900,300,560,810,960,312,588,870,1050,336,644,952,1110,360,700,1020,1200,390,728,1050,1260,420,784,1140,1350,450,812,1200,1440,480,868,1290,1530,510,924,1350,1620,540,980,1440,1710,570,1036,1530,1800,570,1064,1590,1890,600,1120,1680,1980,630,1204,1770,2100,660,1260,1860,2220,720,1316,1950,2310,750,1372,2040,2430];return qt.getBlocksCount=function(r,o){switch(o){case t.L:return s[(r-1)*4+0];case t.M:return s[(r-1)*4+1];case t.Q:return s[(r-1)*4+2];case t.H:return s[(r-1)*4+3];default:return}},qt.getTotalCodewordsCount=function(r,o){switch(o){case t.L:return n[(r-1)*4+0];case t.M:return n[(r-1)*4+1];case t.Q:return n[(r-1)*4+2];case t.H:return n[(r-1)*4+3];default:return}},qt}var Is={},Mt={},qa;function xh(){if(qa)return Mt;qa=1;const t=new Uint8Array(512),s=new Uint8Array(256);return(function(){let a=1;for(let r=0;r<255;r++)t[r]=a,s[a]=r,a<<=1,a&256&&(a^=285);for(let r=255;r<512;r++)t[r]=t[r-255]})(),Mt.log=function(a){if(a<1)throw new Error("log("+a+")");return s[a]},Mt.exp=function(a){return t[a]},Mt.mul=function(a,r){return a===0||r===0?0:t[s[a]+s[r]]},Mt}var Ga;function ph(){return Ga||(Ga=1,(function(t){const s=xh();t.mul=function(a,r){const o=new Uint8Array(a.length+r.length-1);for(let i=0;i<a.length;i++)for(let u=0;u<r.length;u++)o[i+u]^=s.mul(a[i],r[u]);return o},t.mod=function(a,r){let o=new Uint8Array(a);for(;o.length-r.length>=0;){const i=o[0];for(let d=0;d<r.length;d++)o[d]^=s.mul(r[d],i);let u=0;for(;u<o.length&&o[u]===0;)u++;o=o.slice(u)}return o},t.generateECPolynomial=function(a){let r=new Uint8Array([1]);for(let o=0;o<a;o++)r=t.mul(r,new Uint8Array([1,s.exp(o)]));return r}})(Is)),Is}var As,Ha;function fh(){if(Ha)return As;Ha=1;const t=ph();function s(n){this.genPoly=void 0,this.degree=n,this.degree&&this.initialize(this.degree)}return s.prototype.initialize=function(a){this.degree=a,this.genPoly=t.generateECPolynomial(this.degree)},s.prototype.encode=function(a){if(!this.genPoly)throw new Error("Encoder not initialized");const r=new Uint8Array(a.length+this.degree);r.set(a);const o=t.mod(r,this.genPoly),i=this.degree-o.length;if(i>0){const u=new Uint8Array(this.degree);return u.set(o,i),u}return o},As=s,As}var Es={},Ms={},Ps={},Wa;function ni(){return Wa||(Wa=1,Ps.isValid=function(s){return!isNaN(s)&&s>=1&&s<=40}),Ps}var Ge={},Ya;function ai(){if(Ya)return Ge;Ya=1;const t="[0-9]+",s="[A-Z $%*+\\-./:]+";let n="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";n=n.replace(/u/g,"\\u");const a="(?:(?![A-Z0-9 $%*+\\-./:]|"+n+`)(?:.|[\r
|
|
11
|
+
]))+`;Ge.KANJI=new RegExp(n,"g"),Ge.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g"),Ge.BYTE=new RegExp(a,"g"),Ge.NUMERIC=new RegExp(t,"g"),Ge.ALPHANUMERIC=new RegExp(s,"g");const r=new RegExp("^"+n+"$"),o=new RegExp("^"+t+"$"),i=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");return Ge.testKanji=function(d){return r.test(d)},Ge.testNumeric=function(d){return o.test(d)},Ge.testAlphanumeric=function(d){return i.test(d)},Ge}var Ja;function ht(){return Ja||(Ja=1,(function(t){const s=ni(),n=ai();t.NUMERIC={id:"Numeric",bit:1,ccBits:[10,12,14]},t.ALPHANUMERIC={id:"Alphanumeric",bit:2,ccBits:[9,11,13]},t.BYTE={id:"Byte",bit:4,ccBits:[8,16,16]},t.KANJI={id:"Kanji",bit:8,ccBits:[8,10,12]},t.MIXED={bit:-1},t.getCharCountIndicator=function(o,i){if(!o.ccBits)throw new Error("Invalid mode: "+o);if(!s.isValid(i))throw new Error("Invalid version: "+i);return i>=1&&i<10?o.ccBits[0]:i<27?o.ccBits[1]:o.ccBits[2]},t.getBestModeForData=function(o){return n.testNumeric(o)?t.NUMERIC:n.testAlphanumeric(o)?t.ALPHANUMERIC:n.testKanji(o)?t.KANJI:t.BYTE},t.toString=function(o){if(o&&o.id)return o.id;throw new Error("Invalid mode")},t.isValid=function(o){return o&&o.bit&&o.ccBits};function a(r){if(typeof r!="string")throw new Error("Param is not a string");switch(r.toLowerCase()){case"numeric":return t.NUMERIC;case"alphanumeric":return t.ALPHANUMERIC;case"kanji":return t.KANJI;case"byte":return t.BYTE;default:throw new Error("Unknown mode: "+r)}}t.from=function(o,i){if(t.isValid(o))return o;try{return a(o)}catch{return i}}})(Ms)),Ms}var Qa;function gh(){return Qa||(Qa=1,(function(t){const s=mt(),n=si(),a=Un(),r=ht(),o=ni(),i=7973,u=s.getBCHDigit(i);function d(f,l,p){for(let g=1;g<=40;g++)if(l<=t.getCapacity(g,p,f))return g}function x(f,l){return r.getCharCountIndicator(f,l)+4}function h(f,l){let p=0;return f.forEach(function(g){const w=x(g.mode,l);p+=w+g.getBitsLength()}),p}function c(f,l){for(let p=1;p<=40;p++)if(h(f,p)<=t.getCapacity(p,l,r.MIXED))return p}t.from=function(l,p){return o.isValid(l)?parseInt(l,10):p},t.getCapacity=function(l,p,g){if(!o.isValid(l))throw new Error("Invalid QR Code version");typeof g>"u"&&(g=r.BYTE);const w=s.getSymbolTotalCodewords(l),C=n.getTotalCodewordsCount(l,p),b=(w-C)*8;if(g===r.MIXED)return b;const N=b-x(g,l);switch(g){case r.NUMERIC:return Math.floor(N/10*3);case r.ALPHANUMERIC:return Math.floor(N/11*2);case r.KANJI:return Math.floor(N/13);case r.BYTE:default:return Math.floor(N/8)}},t.getBestVersionForData=function(l,p){let g;const w=a.from(p,a.M);if(Array.isArray(l)){if(l.length>1)return c(l,w);if(l.length===0)return 1;g=l[0]}else g=l;return d(g.mode,g.getLength(),w)},t.getEncodedBits=function(l){if(!o.isValid(l)||l<7)throw new Error("Invalid QR Code version");let p=l<<12;for(;s.getBCHDigit(p)-u>=0;)p^=i<<s.getBCHDigit(p)-u;return l<<12|p}})(Es)),Es}var Ts={},Xa;function jh(){if(Xa)return Ts;Xa=1;const t=mt(),s=1335,n=21522,a=t.getBCHDigit(s);return Ts.getEncodedBits=function(o,i){const u=o.bit<<3|i;let d=u<<10;for(;t.getBCHDigit(d)-a>=0;)d^=s<<t.getBCHDigit(d)-a;return(u<<10|d)^n},Ts}var Rs={},Os,Za;function vh(){if(Za)return Os;Za=1;const t=ht();function s(n){this.mode=t.NUMERIC,this.data=n.toString()}return s.getBitsLength=function(a){return 10*Math.floor(a/3)+(a%3?a%3*3+1:0)},s.prototype.getLength=function(){return this.data.length},s.prototype.getBitsLength=function(){return s.getBitsLength(this.data.length)},s.prototype.write=function(a){let r,o,i;for(r=0;r+3<=this.data.length;r+=3)o=this.data.substr(r,3),i=parseInt(o,10),a.put(i,10);const u=this.data.length-r;u>0&&(o=this.data.substr(r),i=parseInt(o,10),a.put(i,u*3+1))},Os=s,Os}var Ds,er;function bh(){if(er)return Ds;er=1;const t=ht(),s=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"," ","$","%","*","+","-",".","/",":"];function n(a){this.mode=t.ALPHANUMERIC,this.data=a}return n.getBitsLength=function(r){return 11*Math.floor(r/2)+6*(r%2)},n.prototype.getLength=function(){return this.data.length},n.prototype.getBitsLength=function(){return n.getBitsLength(this.data.length)},n.prototype.write=function(r){let o;for(o=0;o+2<=this.data.length;o+=2){let i=s.indexOf(this.data[o])*45;i+=s.indexOf(this.data[o+1]),r.put(i,11)}this.data.length%2&&r.put(s.indexOf(this.data[o]),6)},Ds=n,Ds}var Ls,tr;function yh(){if(tr)return Ls;tr=1;const t=ht();function s(n){this.mode=t.BYTE,typeof n=="string"?this.data=new TextEncoder().encode(n):this.data=new Uint8Array(n)}return s.getBitsLength=function(a){return a*8},s.prototype.getLength=function(){return this.data.length},s.prototype.getBitsLength=function(){return s.getBitsLength(this.data.length)},s.prototype.write=function(n){for(let a=0,r=this.data.length;a<r;a++)n.put(this.data[a],8)},Ls=s,Ls}var zs,sr;function wh(){if(sr)return zs;sr=1;const t=ht(),s=mt();function n(a){this.mode=t.KANJI,this.data=a}return n.getBitsLength=function(r){return r*13},n.prototype.getLength=function(){return this.data.length},n.prototype.getBitsLength=function(){return n.getBitsLength(this.data.length)},n.prototype.write=function(a){let r;for(r=0;r<this.data.length;r++){let o=s.toSJIS(this.data[r]);if(o>=33088&&o<=40956)o-=33088;else if(o>=57408&&o<=60351)o-=49472;else throw new Error("Invalid SJIS character: "+this.data[r]+`
|
|
12
|
+
Make sure your charset is UTF-8`);o=(o>>>8&255)*192+(o&255),a.put(o,13)}},zs=n,zs}var Bs={exports:{}},nr;function Nh(){return nr||(nr=1,(function(t){var s={single_source_shortest_paths:function(n,a,r){var o={},i={};i[a]=0;var u=s.PriorityQueue.make();u.push(a,0);for(var d,x,h,c,f,l,p,g,w;!u.empty();){d=u.pop(),x=d.value,c=d.cost,f=n[x]||{};for(h in f)f.hasOwnProperty(h)&&(l=f[h],p=c+l,g=i[h],w=typeof i[h]>"u",(w||g>p)&&(i[h]=p,u.push(h,p),o[h]=x))}if(typeof r<"u"&&typeof i[r]>"u"){var C=["Could not find a path from ",a," to ",r,"."].join("");throw new Error(C)}return o},extract_shortest_path_from_predecessor_list:function(n,a){for(var r=[],o=a;o;)r.push(o),n[o],o=n[o];return r.reverse(),r},find_path:function(n,a,r){var o=s.single_source_shortest_paths(n,a,r);return s.extract_shortest_path_from_predecessor_list(o,r)},PriorityQueue:{make:function(n){var a=s.PriorityQueue,r={},o;n=n||{};for(o in a)a.hasOwnProperty(o)&&(r[o]=a[o]);return r.queue=[],r.sorter=n.sorter||a.default_sorter,r},default_sorter:function(n,a){return n.cost-a.cost},push:function(n,a){var r={value:n,cost:a};this.queue.push(r),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return this.queue.length===0}}};t.exports=s})(Bs)),Bs.exports}var ar;function kh(){return ar||(ar=1,(function(t){const s=ht(),n=vh(),a=bh(),r=yh(),o=wh(),i=ai(),u=mt(),d=Nh();function x(C){return unescape(encodeURIComponent(C)).length}function h(C,b,N){const y=[];let S;for(;(S=C.exec(N))!==null;)y.push({data:S[0],index:S.index,mode:b,length:S[0].length});return y}function c(C){const b=h(i.NUMERIC,s.NUMERIC,C),N=h(i.ALPHANUMERIC,s.ALPHANUMERIC,C);let y,S;return u.isKanjiModeEnabled()?(y=h(i.BYTE,s.BYTE,C),S=h(i.KANJI,s.KANJI,C)):(y=h(i.BYTE_KANJI,s.BYTE,C),S=[]),b.concat(N,y,S).sort(function(k,O){return k.index-O.index}).map(function(k){return{data:k.data,mode:k.mode,length:k.length}})}function f(C,b){switch(b){case s.NUMERIC:return n.getBitsLength(C);case s.ALPHANUMERIC:return a.getBitsLength(C);case s.KANJI:return o.getBitsLength(C);case s.BYTE:return r.getBitsLength(C)}}function l(C){return C.reduce(function(b,N){const y=b.length-1>=0?b[b.length-1]:null;return y&&y.mode===N.mode?(b[b.length-1].data+=N.data,b):(b.push(N),b)},[])}function p(C){const b=[];for(let N=0;N<C.length;N++){const y=C[N];switch(y.mode){case s.NUMERIC:b.push([y,{data:y.data,mode:s.ALPHANUMERIC,length:y.length},{data:y.data,mode:s.BYTE,length:y.length}]);break;case s.ALPHANUMERIC:b.push([y,{data:y.data,mode:s.BYTE,length:y.length}]);break;case s.KANJI:b.push([y,{data:y.data,mode:s.BYTE,length:x(y.data)}]);break;case s.BYTE:b.push([{data:y.data,mode:s.BYTE,length:x(y.data)}])}}return b}function g(C,b){const N={},y={start:{}};let S=["start"];for(let D=0;D<C.length;D++){const k=C[D],O=[];for(let E=0;E<k.length;E++){const M=k[E],A=""+D+E;O.push(A),N[A]={node:M,lastCount:0},y[A]={};for(let F=0;F<S.length;F++){const V=S[F];N[V]&&N[V].node.mode===M.mode?(y[V][A]=f(N[V].lastCount+M.length,M.mode)-f(N[V].lastCount,M.mode),N[V].lastCount+=M.length):(N[V]&&(N[V].lastCount=M.length),y[V][A]=f(M.length,M.mode)+4+s.getCharCountIndicator(M.mode,b))}}S=O}for(let D=0;D<S.length;D++)y[S[D]].end=0;return{map:y,table:N}}function w(C,b){let N;const y=s.getBestModeForData(C);if(N=s.from(b,y),N!==s.BYTE&&N.bit<y.bit)throw new Error('"'+C+'" cannot be encoded with mode '+s.toString(N)+`.
|
|
13
|
+
Suggested mode is: `+s.toString(y));switch(N===s.KANJI&&!u.isKanjiModeEnabled()&&(N=s.BYTE),N){case s.NUMERIC:return new n(C);case s.ALPHANUMERIC:return new a(C);case s.KANJI:return new o(C);case s.BYTE:return new r(C)}}t.fromArray=function(b){return b.reduce(function(N,y){return typeof y=="string"?N.push(w(y,null)):y.data&&N.push(w(y.data,y.mode)),N},[])},t.fromString=function(b,N){const y=c(b,u.isKanjiModeEnabled()),S=p(y),D=g(S,N),k=d.find_path(D.map,"start","end"),O=[];for(let E=1;E<k.length-1;E++)O.push(D.table[k[E]].node);return t.fromArray(l(O))},t.rawSplit=function(b){return t.fromArray(c(b,u.isKanjiModeEnabled()))}})(Rs)),Rs}var rr;function Ch(){if(rr)return bs;rr=1;const t=mt(),s=Un(),n=ch(),a=dh(),r=uh(),o=mh(),i=hh(),u=si(),d=fh(),x=gh(),h=jh(),c=ht(),f=kh();function l(D,k){const O=D.size,E=o.getPositions(k);for(let M=0;M<E.length;M++){const A=E[M][0],F=E[M][1];for(let V=-1;V<=7;V++)if(!(A+V<=-1||O<=A+V))for(let v=-1;v<=7;v++)F+v<=-1||O<=F+v||(V>=0&&V<=6&&(v===0||v===6)||v>=0&&v<=6&&(V===0||V===6)||V>=2&&V<=4&&v>=2&&v<=4?D.set(A+V,F+v,!0,!0):D.set(A+V,F+v,!1,!0))}}function p(D){const k=D.size;for(let O=8;O<k-8;O++){const E=O%2===0;D.set(O,6,E,!0),D.set(6,O,E,!0)}}function g(D,k){const O=r.getPositions(k);for(let E=0;E<O.length;E++){const M=O[E][0],A=O[E][1];for(let F=-2;F<=2;F++)for(let V=-2;V<=2;V++)F===-2||F===2||V===-2||V===2||F===0&&V===0?D.set(M+F,A+V,!0,!0):D.set(M+F,A+V,!1,!0)}}function w(D,k){const O=D.size,E=x.getEncodedBits(k);let M,A,F;for(let V=0;V<18;V++)M=Math.floor(V/3),A=V%3+O-8-3,F=(E>>V&1)===1,D.set(M,A,F,!0),D.set(A,M,F,!0)}function C(D,k,O){const E=D.size,M=h.getEncodedBits(k,O);let A,F;for(A=0;A<15;A++)F=(M>>A&1)===1,A<6?D.set(A,8,F,!0):A<8?D.set(A+1,8,F,!0):D.set(E-15+A,8,F,!0),A<8?D.set(8,E-A-1,F,!0):A<9?D.set(8,15-A-1+1,F,!0):D.set(8,15-A-1,F,!0);D.set(E-8,8,1,!0)}function b(D,k){const O=D.size;let E=-1,M=O-1,A=7,F=0;for(let V=O-1;V>0;V-=2)for(V===6&&V--;;){for(let v=0;v<2;v++)if(!D.isReserved(M,V-v)){let U=!1;F<k.length&&(U=(k[F]>>>A&1)===1),D.set(M,V-v,U),A--,A===-1&&(F++,A=7)}if(M+=E,M<0||O<=M){M-=E,E=-E;break}}}function N(D,k,O){const E=new n;O.forEach(function(v){E.put(v.mode.bit,4),E.put(v.getLength(),c.getCharCountIndicator(v.mode,D)),v.write(E)});const M=t.getSymbolTotalCodewords(D),A=u.getTotalCodewordsCount(D,k),F=(M-A)*8;for(E.getLengthInBits()+4<=F&&E.put(0,4);E.getLengthInBits()%8!==0;)E.putBit(0);const V=(F-E.getLengthInBits())/8;for(let v=0;v<V;v++)E.put(v%2?17:236,8);return y(E,D,k)}function y(D,k,O){const E=t.getSymbolTotalCodewords(k),M=u.getTotalCodewordsCount(k,O),A=E-M,F=u.getBlocksCount(k,O),V=E%F,v=F-V,U=Math.floor(E/F),L=Math.floor(A/F),K=L+1,$=U-L,G=new d($);let X=0;const oe=new Array(F),q=new Array(F);let ie=0;const B=new Uint8Array(D.buffer);for(let pe=0;pe<F;pe++){const Ne=pe<v?L:K;oe[pe]=B.slice(X,X+Ne),q[pe]=G.encode(oe[pe]),X+=Ne,ie=Math.max(ie,Ne)}const ee=new Uint8Array(E);let R=0,P,ce;for(P=0;P<ie;P++)for(ce=0;ce<F;ce++)P<oe[ce].length&&(ee[R++]=oe[ce][P]);for(P=0;P<$;P++)for(ce=0;ce<F;ce++)ee[R++]=q[ce][P];return ee}function S(D,k,O,E){let M;if(Array.isArray(D))M=f.fromArray(D);else if(typeof D=="string"){let U=k;if(!U){const L=f.rawSplit(D);U=x.getBestVersionForData(L,O)}M=f.fromString(D,U||40)}else throw new Error("Invalid data");const A=x.getBestVersionForData(M,O);if(!A)throw new Error("The amount of data is too big to be stored in a QR Code");if(!k)k=A;else if(k<A)throw new Error(`
|
|
14
|
+
The chosen QR Code version cannot contain this amount of data.
|
|
15
|
+
Minimum version required to store current data is: `+A+`.
|
|
16
|
+
`);const F=N(k,O,M),V=t.getSymbolSize(k),v=new a(V);return l(v,k),p(v),g(v,k),C(v,O,0),k>=7&&w(v,k),b(v,F),isNaN(E)&&(E=i.getBestMask(v,C.bind(null,v,O))),i.applyMask(E,v),C(v,O,E),{modules:v,version:k,errorCorrectionLevel:O,maskPattern:E,segments:M}}return bs.create=function(k,O){if(typeof k>"u"||k==="")throw new Error("No input text");let E=s.M,M,A;return typeof O<"u"&&(E=s.from(O.errorCorrectionLevel,s.M),M=x.from(O.version),A=i.from(O.maskPattern),O.toSJISFunc&&t.setToSJISFunction(O.toSJISFunc)),S(k,M,E,A)},bs}var _s={},Fs={},or;function ri(){return or||(or=1,(function(t){function s(n){if(typeof n=="number"&&(n=n.toString()),typeof n!="string")throw new Error("Color should be defined as hex string");let a=n.slice().replace("#","").split("");if(a.length<3||a.length===5||a.length>8)throw new Error("Invalid hex color: "+n);(a.length===3||a.length===4)&&(a=Array.prototype.concat.apply([],a.map(function(o){return[o,o]}))),a.length===6&&a.push("F","F");const r=parseInt(a.join(""),16);return{r:r>>24&255,g:r>>16&255,b:r>>8&255,a:r&255,hex:"#"+a.slice(0,6).join("")}}t.getOptions=function(a){a||(a={}),a.color||(a.color={});const r=typeof a.margin>"u"||a.margin===null||a.margin<0?4:a.margin,o=a.width&&a.width>=21?a.width:void 0,i=a.scale||4;return{width:o,scale:o?4:i,margin:r,color:{dark:s(a.color.dark||"#000000ff"),light:s(a.color.light||"#ffffffff")},type:a.type,rendererOpts:a.rendererOpts||{}}},t.getScale=function(a,r){return r.width&&r.width>=a+r.margin*2?r.width/(a+r.margin*2):r.scale},t.getImageWidth=function(a,r){const o=t.getScale(a,r);return Math.floor((a+r.margin*2)*o)},t.qrToImageData=function(a,r,o){const i=r.modules.size,u=r.modules.data,d=t.getScale(i,o),x=Math.floor((i+o.margin*2)*d),h=o.margin*d,c=[o.color.light,o.color.dark];for(let f=0;f<x;f++)for(let l=0;l<x;l++){let p=(f*x+l)*4,g=o.color.light;if(f>=h&&l>=h&&f<x-h&&l<x-h){const w=Math.floor((f-h)/d),C=Math.floor((l-h)/d);g=c[u[w*i+C]?1:0]}a[p++]=g.r,a[p++]=g.g,a[p++]=g.b,a[p]=g.a}}})(Fs)),Fs}var ir;function Sh(){return ir||(ir=1,(function(t){const s=ri();function n(r,o,i){r.clearRect(0,0,o.width,o.height),o.style||(o.style={}),o.height=i,o.width=i,o.style.height=i+"px",o.style.width=i+"px"}function a(){try{return document.createElement("canvas")}catch{throw new Error("You need to specify a canvas element")}}t.render=function(o,i,u){let d=u,x=i;typeof d>"u"&&(!i||!i.getContext)&&(d=i,i=void 0),i||(x=a()),d=s.getOptions(d);const h=s.getImageWidth(o.modules.size,d),c=x.getContext("2d"),f=c.createImageData(h,h);return s.qrToImageData(f.data,o,d),n(c,x,h),c.putImageData(f,0,0),x},t.renderToDataURL=function(o,i,u){let d=u;typeof d>"u"&&(!i||!i.getContext)&&(d=i,i=void 0),d||(d={});const x=t.render(o,i,d),h=d.type||"image/png",c=d.rendererOpts||{};return x.toDataURL(h,c.quality)}})(_s)),_s}var Us={},lr;function Ih(){if(lr)return Us;lr=1;const t=ri();function s(r,o){const i=r.a/255,u=o+'="'+r.hex+'"';return i<1?u+" "+o+'-opacity="'+i.toFixed(2).slice(1)+'"':u}function n(r,o,i){let u=r+o;return typeof i<"u"&&(u+=" "+i),u}function a(r,o,i){let u="",d=0,x=!1,h=0;for(let c=0;c<r.length;c++){const f=Math.floor(c%o),l=Math.floor(c/o);!f&&!x&&(x=!0),r[c]?(h++,c>0&&f>0&&r[c-1]||(u+=x?n("M",f+i,.5+l+i):n("m",d,0),d=0,x=!1),f+1<o&&r[c+1]||(u+=n("h",h),h=0)):d++}return u}return Us.render=function(o,i,u){const d=t.getOptions(i),x=o.modules.size,h=o.modules.data,c=x+d.margin*2,f=d.color.light.a?"<path "+s(d.color.light,"fill")+' d="M0 0h'+c+"v"+c+'H0z"/>':"",l="<path "+s(d.color.dark,"stroke")+' d="'+a(h,x,d.margin)+'"/>',p='viewBox="0 0 '+c+" "+c+'"',w='<svg xmlns="http://www.w3.org/2000/svg" '+(d.width?'width="'+d.width+'" height="'+d.width+'" ':"")+p+' shape-rendering="crispEdges">'+f+l+`</svg>
|
|
17
|
+
`;return typeof u=="function"&&u(null,w),w},Us}var cr;function Ah(){if(cr)return gt;cr=1;const t=lh(),s=Ch(),n=Sh(),a=Ih();function r(o,i,u,d,x){const h=[].slice.call(arguments,1),c=h.length,f=typeof h[c-1]=="function";if(!f&&!t())throw new Error("Callback required as last argument");if(f){if(c<2)throw new Error("Too few arguments provided");c===2?(x=u,u=i,i=d=void 0):c===3&&(i.getContext&&typeof x>"u"?(x=d,d=void 0):(x=d,d=u,u=i,i=void 0))}else{if(c<1)throw new Error("Too few arguments provided");return c===1?(u=i,i=d=void 0):c===2&&!i.getContext&&(d=u,u=i,i=void 0),new Promise(function(l,p){try{const g=s.create(u,d);l(o(g,i,d))}catch(g){p(g)}})}try{const l=s.create(u,d);x(null,o(l,i,d))}catch(l){x(l)}}return gt.create=s.create,gt.toCanvas=r.bind(null,n.render),gt.toDataURL=r.bind(null,n.renderToDataURL),gt.toString=r.bind(null,function(o,i,u){return a.render(o,u)}),gt}var Eh=Ah();const Mh=ic(Eh);function Ph(){return e.jsxs("div",{className:"space-y-10",children:[e.jsx(Th,{}),e.jsx(Rh,{}),e.jsx(Lh,{})]})}function Th(){const{t}=z(),[s,n]=m.useState(null),[a,r]=m.useState(null),[o,i]=m.useState(!1),[u,d]=m.useState(null),[x,h]=m.useState(null),[c,f]=m.useState(!1),l=s?.pairingExpiresAt;m.useEffect(()=>{if(!l){h(null);return}const C=()=>h(Math.max(0,Math.ceil((l-Date.now())/1e3)));C();const b=setInterval(C,1e3);return()=>clearInterval(b)},[l]);const p=C=>{navigator.clipboard.writeText(C).then(()=>{f(!0),setTimeout(()=>f(!1),1500)})};m.useEffect(()=>(window.electronAPI.pair.status().then(n),window.electronAPI.pair.onStatusChanged(C=>{n(C),(C.pairing||C.devices.length>0)&&d(null)})),[]),m.useEffect(()=>{const C=s?.inviteUri;if(!C){r(null);return}Mh.toDataURL(C,{width:320,margin:1}).then(r).catch(()=>{})},[s?.inviteUri]);const g=async()=>{i(!0),d(null);const C=await window.electronAPI.pair.start();i(!1),C.ok||d(C.error??t("Failed to start pairing"))},w=s?.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:t("Allow connections")}),e.jsx("p",{className:"text-muted-foreground text-sm",children:t("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:s?.pairing?e.jsx(I,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.pair.cancel()},children:t("Cancel pairing")}):e.jsxs(I,{variant:"outline",size:"sm",disabled:o,onClick:()=>{g()},children:[o?e.jsx(Pe,{className:"mr-1.5 h-4 w-4 animate-spin"}):e.jsx(on,{className:"mr-1.5 h-4 w-4"}),t("Generate pairing code")]})})]}),s&&!s.secureStorage&&e.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-dashed px-3 py-2 text-xs",children:[e.jsx(Fe,{className:"mt-0.5 h-4 w-4 shrink-0 text-destructive"}),e.jsx("span",{className:"text-muted-foreground",children:t("Secure storage is unavailable on this system, so pairing keys are stored unencrypted.")})]}),u&&e.jsx("p",{className:"text-destructive text-xs",children:u}),s?.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:t("Pairing QR code"),className:"mx-auto h-52 w-52"}):e.jsx(Pe,{className:"mx-auto h-5 w-5 animate-spin text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:t("Scan with your phone camera")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:t("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:t("On another EnsoCode desktop, paste the link below into Settings → Devices → Connect to a node.")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:x===null?t("The code expires in 60 seconds and can only be used once."):x>0?t("Expires in {{seconds}}s · single use",{seconds:x}):t("Code expired")})]}),s.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:s.inviteUri}),e.jsxs(I,{variant:"outline",size:"sm",className:"shrink-0",onClick:()=>p(s.inviteUri),children:[c?e.jsx(wo,{className:"mr-1.5 h-3.5 w-3.5"}):e.jsx(po,{className:"mr-1.5 h-3.5 w-3.5"}),t(c?"Copied":"Copy")]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"font-medium text-sm",children:t("Paired devices")}),w.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx(on,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:t("No paired devices")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:t("Generate a pairing code to let a phone or another desktop connect.")})]}):e.jsx("div",{className:"space-y-1",children:w.map(C=>e.jsx(Oh,{device:C},C.pairId))})]})]})}function Rh(){const{t}=z(),s=$t(i=>i.nodes),n=$t(i=>i.secureStorage),a=$t(i=>i.refresh),[r,o]=m.useState(!1);return m.useEffect(()=>$t.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:t("Connect to a node")}),e.jsx("p",{className:"text-muted-foreground text-sm",children:t("Browse and drive conversations on another EnsoCode desktop. Its agent, keys and history stay there.")})]}),e.jsxs(I,{variant:"outline",size:"sm",className:"shrink-0",onClick:()=>o(!0),children:[e.jsx(Te,{className:"mr-1.5 h-4 w-4"}),t("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(Fe,{className:"mt-0.5 h-4 w-4 shrink-0 text-destructive"}),e.jsx("span",{className:"text-muted-foreground",children:t("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:t("Connected nodes")}),s.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx(Mn,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:t("No connected nodes")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:t("Each connecting computer needs its own pairing code from the other desktop.")})]}):e.jsx("div",{className:"space-y-1",children:s.map(i=>e.jsx(Dh,{node:i,onChanged:()=>{a()}},i.nodeId))})]}),e.jsx(lc,{open:r,onOpenChange:o,switchOnSuccess:!1})]})}function oi({transport:t,rttMs:s}){const{t:n}=z(),a=t==="direct",r=ih(s);return e.jsxs("span",{className:H("shrink-0 rounded px-1.5 py-0.5 text-[10px] leading-none",a?"bg-emerald-500/15 text-emerald-600":"bg-muted text-muted-foreground"),children:[n(a?"Direct link":"Via relay"),r?` · ${r}`:""]})}function Oh({device:t}){const{t:s}=z(),[n,a]=m.useState(null),r=async()=>{n!==null&&(n.trim()&&n.trim()!==t.deviceName&&await window.electronAPI.pair.rename(t.pairId,n),a(null))};return e.jsxs("div",{className:"group flex items-center justify-between gap-3 rounded-md px-3 py-2 transition-colors hover:bg-accent/50",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[e.jsx("span",{className:H("h-2 w-2 shrink-0 rounded-full",t.phoneOnline?"bg-emerald-500":t.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:t.deviceName}),e.jsx("span",{className:"shrink-0 text-muted-foreground text-xs",children:t.phoneOnline?s("Online"):t.connected?s("Waiting for device"):s("Offline")}),t.phoneOnline&&e.jsx(oi,{transport:t.transport,rttMs:t.rttMs}),e.jsx("button",{type:"button",title:s("Click to switch: view-only devices cannot send, approve or stop."),onClick:()=>{window.electronAPI.pair.setScope(t.pairId,t.scope==="read"?"operate":"read")},className:H("shrink-0 rounded px-1.5 py-0.5 text-[10px] leading-none transition-colors",t.scope==="read"?"bg-amber-500/15 text-amber-600 hover:bg-amber-500/25":"bg-muted text-muted-foreground hover:bg-accent"),children:t.scope==="read"?s("View only"):s("Can operate")})]}):e.jsx(Y,{value:n,autoFocus:!0,onChange:o=>a(o.target.value),onBlur:()=>{r()},onKeyDown:o=>{o.key==="Enter"&&r(),o.key==="Escape"&&a(null)},className:"h-7 text-sm"})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1 opacity-0 transition-opacity group-hover:opacity-100",children:[e.jsx(I,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground",title:s("Rename"),onClick:()=>a(t.deviceName),children:e.jsx(it,{className:"h-3.5 w-3.5"})}),e.jsx(I,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-destructive",onClick:()=>{window.electronAPI.pair.revoke(t.pairId)},children:e.jsx(Ee,{className:"h-3.5 w-3.5"})})]})]})}function Dh({node:t,onChanged:s}){const{t:n}=z(),[a,r]=m.useState(null),o=async()=>{a!==null&&(a.trim()&&a.trim()!==t.label&&(await window.electronAPI.nodes.rename(t.nodeId,a),s()),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(cc,{node:t}),a===null?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"truncate font-medium text-sm",children:t.label}),t.hostname&&t.hostname!==t.label&&e.jsx("span",{className:"shrink-0 truncate font-mono text-[10px] text-muted-foreground",children:t.hostname}),e.jsx("span",{className:"shrink-0 text-muted-foreground text-xs",children:t.hostOnline?n("Online"):t.connected?n("Remote desktop is offline"):n("Offline")}),t.hostOnline&&e.jsx(oi,{transport:t.transport,rttMs:t.rttMs})]}):e.jsx(Y,{value:a,autoFocus:!0,onChange:i=>r(i.target.value),onBlur:()=>{o()},onKeyDown:i=>{i.key==="Enter"&&o(),i.key==="Escape"&&r(null)},className:"h-7 text-sm"})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1 opacity-0 transition-opacity group-hover:opacity-100",children:[e.jsx(I,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground",title:n("Rename"),onClick:()=>r(t.label),children:e.jsx(it,{className:"h-3.5 w-3.5"})}),e.jsx(I,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-destructive",title:n("Disconnect"),onClick:()=>{window.electronAPI.nodes.remove(t.nodeId).then(s)},children:e.jsx(Ee,{className:"h-3.5 w-3.5"})})]})]})}function Lh(){const{t}=z(),[s,n]=m.useState(null),[a,r]=m.useState(null);m.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:t("Relay server")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("The relay only forwards encrypted frames and cannot read your messages.")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Y,{value:a??s?.relayUrl??"",onChange:i=>r(i.target.value),placeholder:"https://relay.example.com",className:"font-mono text-xs"}),a===null?e.jsx(I,{variant:"ghost",size:"icon",className:"h-8 w-8 shrink-0 text-muted-foreground",onClick:()=>r(s?.relayUrl??""),children:e.jsx(it,{className:"h-3.5 w-3.5"})}):e.jsxs(I,{size:"sm",className:"shrink-0",onClick:()=>{o()},children:[e.jsx(wo,{className:"mr-1.5 h-3.5 w-3.5"}),t("Save")]})]})]})})}function zh({onOpenBots:t}){const{t:s}=z(),n=j(i=>i.botModeEnabled),a=j(i=>i.setBotModeEnabled),r=j(i=>i.scratchSessionsEnabled),o=j(i=>i.setScratchSessionsEnabled);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("Experimental")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("Features still being tested. They may change or be removed.")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Me,{rowId:"experimental.botMode",title:s("Bot mode"),description:s("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(I,{variant:"outline",size:"sm",onClick:t,children:s("Bot mode settings")}),e.jsx(Me,{rowId:"experimental.scratchSessions",title:s("Temporary chats"),description:s("Chats that are not tied to a project. Tools follow your global settings."),checked:r,onChange:o})]})]})}function Bh({instruction:t,onClose:s}){const{t:n}=z(),a=j(k=>k.addInstructions),r=j(k=>k.updateInstruction),o=t==="new",i=o||!t?null:t,[u,d]=m.useState(""),[x,h]=m.useState(""),[c,f]=m.useState(!1),[l,p]=m.useState(!1),[g,w]=m.useState(null),[C,b]=m.useState(!1),[N,y]=m.useState(!1);m.useEffect(()=>{if(t){if(t==="new"){d(""),h(""),b(!1),w(null),y(!1),f(!1);return}d(t.name),b(!1),w(null),y(!1),f(!0),window.electronAPI.instructions.read(t.id,t.local,t.sourcePath).then(k=>{k.ok?h(k.content):(h(""),w(k.error??n("Failed to read content")))}).finally(()=>f(!1))}},[t,n]);const S=!!(i&&!i.local&&i.sourcePath),D=async()=>{if(!t||!u.trim())return;if(p(!0),o){const O=crypto.randomUUID(),E=await window.electronAPI.instructions.write(O,x);if(!E.ok){p(!1),w(n("Failed to save"));return}const M=a([{id:O,name:u.trim(),source:"Manual",local:!0,bytes:E.bytes,enabled:!0}]);if(p(!1),M===0){window.electronAPI.instructions.delete(O),w(n("An instruction with this name already exists"));return}s();return}if(!i){p(!1);return}if(S&&N&&i.sourcePath){const O=await window.electronAPI.instructions.writeSource(i.id,i.sourcePath,x);if(p(!1),!O.ok){w(O.error??n("Failed to save"));return}r(i.id,{name:u.trim(),bytes:O.bytes}),s();return}const k=await window.electronAPI.instructions.write(i.id,x);if(p(!1),!k.ok){w(n("Failed to save"));return}r(i.id,{name:u.trim(),local:!0,bytes:k.bytes}),s()};return e.jsx(fe,{open:t!==null,onOpenChange:k=>!k&&s(),children:e.jsxs(ge,{className:"max-w-2xl",children:[e.jsx(je,{children:e.jsx(ve,{children:n(o?"Add Instruction":"Edit Instruction")})}),e.jsxs(we,{className:"space-y-4",children:[o?null:S?e.jsxs("div",{className:H("w-full rounded-md border px-3 py-2.5 transition-colors",N?"border-destructive/32 bg-destructive/8":"border-amber-500/32 bg-amber-500/8"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[N?e.jsx(Fe,{className:"h-3.5 w-3.5 shrink-0 text-destructive"}):e.jsx(Xt,{className:"h-3.5 w-3.5 shrink-0 text-amber-600 dark:text-amber-500"}),e.jsx("span",{className:"font-medium text-xs",children:n("Write back to original file")})]}),e.jsx(le,{checked:N,onCheckedChange:y})]}),e.jsx("p",{className:"mt-1.5 pl-5.5 text-muted-foreground text-xs leading-relaxed",children:N?n("Saving overwrites {{path}} directly — {{source}} will pick up the change.",{path:i?.sourcePath??"",source:i?.source??""}):n("Saving creates a local copy — {{path}} is left untouched, and this entry stops following its updates.",{path:i?.sourcePath??""})})]}):e.jsxs("div",{className:"flex w-full items-start gap-2 rounded-md border bg-muted/50 px-3 py-2",children:[e.jsx(Xt,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx("p",{className:"text-muted-foreground text-xs leading-relaxed",children:n("Local copy — edits stay in this app.")})]}),e.jsxs(ue,{children:[e.jsx(me,{children:n("Name")}),e.jsx(Y,{value:u,onChange:k=>d(k.target.value)})]}),e.jsxs(ue,{children:[e.jsx(me,{children:n("Content")}),c?e.jsxs("div",{className:"flex w-full items-center justify-center gap-2 rounded-md border py-12",children:[e.jsx(Pe,{className:"h-4 w-4 animate-spin text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground text-xs",children:n("Loading...")})]}):e.jsx(He,{value:x,onChange:k=>{h(k.target.value),b(!0)},rows:16,className:"font-mono text-xs"})]}),g&&e.jsxs("p",{className:"flex items-center gap-1.5 text-destructive text-xs",children:[e.jsx(St,{className:"h-3.5 w-3.5 shrink-0"}),g]})]}),e.jsxs(Ie,{children:[e.jsx(I,{variant:"outline",size:"sm",onClick:s,children:n("Cancel")}),e.jsxs(I,{size:"sm",variant:S&&N?"destructive":"default",disabled:!u.trim()||c||l,onClick:D,children:[l&&e.jsx(Pe,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}),n(S?N?"Overwrite original":C?"Save as local copy":"Save":"Save")]})]})]})})}const dr=t=>t<1024?`${t} B`:`${(t/1024).toFixed(1)} KB`;function _h(){const{t}=z(),s=j(c=>c.instructions),n=j(c=>c.updateInstruction),a=j(c=>c.removeInstruction),[r,o]=m.useState(!1),[i,u]=m.useState(null),d=s.map(c=>c.id),x=cs(d,c=>window.electronAPI.assets.instructionOccupancy(c)),h=os(s.filter(c=>c.enabled).map(c=>c.id),x.rows);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-end justify-between gap-4","data-settings-row":"instructions.root",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"font-medium text-lg",children:[t("Instruction Files"),e.jsx(ls,{tokens:h}),e.jsx(qe,{})]}),e.jsx("p",{className:"text-muted-foreground text-sm",children:t("Global CLAUDE.md / AGENTS.md style files from local AI tools")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("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(I,{variant:"outline",size:"sm",onClick:()=>o(!0),children:[e.jsx(rs,{className:"mr-1.5 h-4 w-4"}),t("Import from local apps")]}),e.jsxs(I,{variant:"outline",size:"sm",onClick:()=>u("new"),children:[e.jsx(Te,{className:"mr-1.5 h-4 w-4"}),t("Add instruction")]})]})]}),s.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx(Dn,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:t("No instruction files yet")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:t("Import instruction files from local apps or add one manually to get started")})]}):e.jsx("div",{className:"space-y-1",children:s.map(c=>e.jsxs("div",{className:"group flex items-center justify-between gap-3 rounded-md px-3 py-2 transition-colors hover:bg-accent/50","data-settings-row":`instructions.${c.id}`,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:H("shrink-0 font-medium text-sm",!c.enabled&&"text-muted-foreground line-through"),children:c.name}),e.jsx(te,{variant:"secondary",className:"shrink-0 text-[11px]",children:c.source}),!c.local&&e.jsxs(te,{variant:"outline",className:"shrink-0 gap-1 text-[11px]",children:[e.jsx(qo,{className:"h-3 w-3"}),t("Linked")]}),e.jsx("span",{className:"min-w-0 truncate text-muted-foreground text-xs",children:c.local?`${t("Local copy")} · ${dr(c.bytes)}`:`${c.sourcePath} · ${dr(c.bytes)}`})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(is,{row:x.rows[c.id],pending:x.pending&&!x.rows[c.id]}),e.jsx(le,{checked:c.enabled,onCheckedChange:f=>n(c.id,{enabled:f})}),e.jsx(I,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",onClick:()=>u(c),children:e.jsx(it,{className:"h-3.5 w-3.5"})}),e.jsx(I,{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(Ln,{kind:"instruction",open:r,onOpenChange:o}),e.jsx(Bh,{instruction:i,onClose:()=>u(null)})]})}function Fh(){const{t}=z();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:t("Shortcuts")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("Click a shortcut to rebind it. Backspace removes it; Esc cancels.")})]}),e.jsx(Uh,{})]})}function Uh(){const{t}=z(),s=j(h=>h.keybindings),n=j(h=>h.setKeybinding),a=j(h=>h.resetKeybinding),[r,o]=m.useState(null),[i,u]=m.useState(null),d=dc(s),x=h=>{if(h.preventDefault(),h.stopPropagation(),!r)return;if(h.key==="Escape"){o(null),u(null);return}if(h.key==="Backspace"||h.key==="Delete"){n(r,""),o(null),u(null);return}const c=hc(h,{allowBare:r==="send-message"||r==="voice-hold"});if(!c)return;const f=ma.find(l=>l!==r&&d[l]===c);if(f){u(f);return}c===xc[r]?a(r):n(r,c),o(null),u(null)};return e.jsx("div",{className:"divide-y rounded-md border",children:ma.map(h=>{const c=r===h,f=s[h]!==void 0,l=d[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:t(xa[h])}),ha[h]&&e.jsx("p",{className:"text-muted-foreground text-xs",children:t(ha[h])})]}),c&&i&&e.jsx("span",{className:"text-xs text-destructive",children:t('Already used by "{{label}}"',{label:t(xa[i])})}),l&&!c&&e.jsx("button",{type:"button",title:t("Remove shortcut"),onClick:()=>n(h,""),className:"rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:e.jsx(Ct,{className:"h-3.5 w-3.5"})}),f&&!c&&e.jsx("button",{type:"button",title:t("Reset to default"),onClick:()=>a(h),className:"rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:e.jsx(fo,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>{o(h),u(null)},onKeyDown:c?x:void 0,onBlur:()=>{c&&(o(null),u(null))},autoFocus:c,className:H("rounded-md px-1 py-0.5 transition-colors",c?"ring-1 ring-ring":"hover:bg-muted"),children:c?e.jsx("span",{className:"text-xs text-muted-foreground",children:t("Press shortcut…")}):l?e.jsx(uc,{children:mc(l)}):e.jsx("span",{className:"text-xs text-muted-foreground",children:t("No shortcut")})})]},h)})})}function $h(t){return t.serverId??t.serverName}function ii(t,s){const n={...t};return s.serverId&&delete n[s.serverName],n[$h(s)]={state:s.state,...s.toolCount!==void 0?{toolCount:s.toolCount}:{},...s.error?{error:s.error}:{}},n}function Vh(t){return t.reduce((s,n)=>ii(s,n),{})}function Kh(t,s){return{...t,[s]:{state:"connecting"}}}function qh(t,s,n){return{...t,[s]:{state:"error",...n?{error:n}:{}}}}const $s=(t,s)=>{const n={...t};return delete n[s],n},dt=pc()((t,s)=>({statuses:{},authorized:{},pending:{},bind:()=>(window.electronAPI.mcp.authState().then(n=>t({authorized:n})).catch(()=>{}),window.electronAPI.mcp.statusSnapshot().then(n=>t({statuses:{...s().statuses,...Vh(n)}})).catch(()=>{}),window.electronAPI.mcp.onStatus(n=>{if(n.type==="mcp-status-cleared"){t({statuses:{}});return}t({statuses:ii(s().statuses,n)}),window.electronAPI.mcp.authState().then(a=>t({authorized:a})).catch(()=>{})})),authorize:async n=>{t({statuses:Kh(s().statuses,n),pending:{...s().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)}}t({pending:$s(s().pending,n),...a.ok?{authorized:{...s().authorized,[n]:!0}}:{statuses:qh(s().statuses,n,a.error)}})},revoke:async n=>{await window.electronAPI.mcp.revoke(n),t({authorized:$s(s().authorized,n),statuses:$s(s().statuses,n)})}})),We=t=>typeof t=="string"?t.trim():"",Gh=t=>Array.isArray(t)?t.filter(s=>typeof s=="string"):[],li=t=>{if(!t||typeof t!="object")return{};const s={};for(const[n,a]of Object.entries(t))typeof a=="string"&&(s[n]=a);return s};function Hh(t){const s=li(t);return delete s[""],Object.keys(s).length>0?s:void 0}function ur(t){const s={};for(const n of t.split(`
|
|
18
|
+
`)){const a=n.indexOf(":"),r=a>0?n.slice(0,a).trim():"";r&&(s[r]=n.slice(a+1).trim())}return Object.keys(s).length>0?s:void 0}const mr=t=>Object.entries(t??{}).map(([s,n])=>`${s}: ${n}`).join(`
|
|
19
|
+
`);function Wh(t,s){const n=We(t).toLowerCase();return n==="sse"?"sse":n==="http"||n==="streamable-http"?"http":n==="stdio"?"stdio":s?"http":"stdio"}function hr(t){if(!t||typeof t!="object")return[];const s=[];for(const[n,a]of Object.entries(t)){if(!a||typeof a!="object")continue;const r=a,o=We(r.url)||We(r.serverUrl),i=We(r.command);if(!i&&!o)continue;const u=i?void 0:Hh(r.headers);s.push({name:n,transport:Wh(r.type??r.transport,o),command:i||void 0,args:i?Gh(r.args):void 0,env:i?li(r.env):void 0,url:o||void 0,...u?{headers:u}:{}})}return s}const Yh=t=>{const s=t.trim();return(s.match(/^```(?:json)?\s*([\s\S]*?)\s*```$/i)?.[1]??s).trim()},Jh=t=>t.startsWith('"')&&!t.startsWith("{")&&!t.startsWith("[")?`{${t}}`:t,Qh=t=>{if(!t||typeof t!="object"||Array.isArray(t))return t;const s=t;if(s.mcpServers!=null)return s.mcpServers;if(s.mcp_servers!=null)return s.mcp_servers;if(s.servers!=null)return s.servers;const n=s.mcp;if(n&&typeof n=="object"&&!Array.isArray(n)){const a=n.servers;if(a!=null)return a}return t},Xh=t=>{if(!t||typeof t!="object"||Array.isArray(t))return!1;const s=t;return!!(We(s.command)||We(s.url)||We(s.serverUrl))},Zh=t=>{const s=We(t.command);return s&&s.split(/[\\/]/).pop()?.trim()||"mcp"},hn=t=>{if(Array.isArray(t))return t.flatMap(hn);if(Xh(t)){const s=We(t.name)||We(t.id)||Zh(t);return hr({[s]:t})}return hr(t)};function Vs(t){let s;try{s=JSON.parse(Jh(Yh(t)))}catch{return{ok:!1,error:"invalid-json"}}const n=Array.isArray(s)?s.flatMap(hn):hn(Qh(s));return n.length===0?{ok:!1,error:"empty"}:{ok:!0,servers:n}}const ex=1e4,tx=12e4,sx=600,nx=3600;function xr(t,s){let n;if(typeof t=="string"){const a=t.trim();if(!a||!/^\d+$/.test(a))return;n=Number(a)}else if(typeof t=="number")n=t;else return;if(!(!Number.isInteger(n)||n<=0))return s===void 0?n:Math.min(n,s)}const ax={theme:gc,disableFileHeader:!0,overflow:"scroll",preferredHighlighter:"shiki-js"};function rx(t){return new wc(t)}function ci({fileName:t,value:s,epoch:n,onChange:a,className:r="h-60"}){const{t:o}=z(),[i,u]=m.useState(!1),d=fc(ax),x=m.useRef(a);x.current=a;const h=m.useMemo(()=>({onChange(c){x.current(c.contents)}}),[]);return m.useEffect(()=>{let c=!0;return jc().then(()=>{c&&u(!0)}),()=>{c=!1}},[]),i?e.jsx("div",{className:H("w-full overflow-hidden rounded-lg border border-input",r),children:e.jsx(vc,{createEditor:rx,children:e.jsx(bc,{style:{height:"100%",overflow:"auto"},children:e.jsx(yc,{file:{name:t,contents:s},disableWorkerPool:!0,edit:!0,editorOptions:h,options:d},n)})})}):e.jsx("div",{className:H("flex w-full items-center justify-center rounded-lg border border-input text-muted-foreground text-xs",r),children:o("Loading...")})}const pr=t=>{const s=t.split(`
|
|
20
|
+
`).map(n=>n.trim()).filter(Boolean);return s.length>0?s:void 0},fr=t=>{const s={};for(const n of t.split(`
|
|
21
|
+
`)){const a=n.trim();if(!a)continue;const r=a.indexOf("=");r<=0||(s[a.slice(0,r).trim()]=a.slice(r+1))}return Object.keys(s).length>0?s:void 0},gr=t=>t?Object.entries(t).map(([s,n])=>`${s}=${n}`).join(`
|
|
22
|
+
`):"",jr=t=>{const s={type:t.transport};return t.command&&(s.command=t.command),t.args&&t.args.length>0&&(s.args=t.args),t.env&&Object.keys(t.env).length>0&&(s.env=t.env),t.url&&(s.url=t.url),t.headers&&Object.keys(t.headers).length>0&&(s.headers=t.headers),s};function ox({server:t,onClose:s}){const{t:n}=z(),a=j(_=>_.addMcpServers),r=j(_=>_.updateMcpServer),o=t==="new",[i,u]=m.useState("form"),[d,x]=m.useState(""),[h,c]=m.useState(""),[f,l]=m.useState(""),[p,g]=m.useState(""),[w,C]=m.useState("stdio"),[b,N]=m.useState(""),[y,S]=m.useState(""),[D,k]=m.useState(""),[O,E]=m.useState(""),[M,A]=m.useState(""),[F,V]=m.useState(""),[v,U]=m.useState(""),[L,K]=m.useState(""),[$,G]=m.useState(0),[X,oe]=m.useState(null),q=()=>({description:h.trim()||void 0,oauthClientName:w!=="stdio"&&f.trim()||void 0,oauthMetadataUrl:w!=="stdio"&&p.trim()||void 0,connectTimeoutSec:xr(F,sx),callTimeoutSec:xr(v,nx)}),ie=_=>{x(_.name),C(_.transport),N(_.command??""),S((_.args??[]).join(`
|
|
23
|
+
`)),k(gr(_.env&&Object.keys(_.env).length>0?_.env:void 0)),E(_.url??""),A(mr(_.headers))},B=()=>{const _={type:w};if(w==="stdio"){_.command=b.trim();const Z=pr(y);Z&&(_.args=Z);const J=fr(D);J&&(_.env=J)}else{_.url=O.trim();const Z=ur(M);Z&&(_.headers=Z)}return JSON.stringify(_,null,2)},ee=(_,Z)=>{const J=(Z??_.name).trim(),he=_.env&&Object.keys(_.env).length>0?_.env:void 0,ke=_.args&&_.args.length>0?_.args:void 0;return _.transport==="stdio"?{name:J,transport:_.transport,command:(_.command??"").trim(),args:ke,env:he,url:void 0,headers:void 0,...q()}:{name:J,transport:_.transport,url:(_.url??"").trim(),headers:_.headers&&Object.keys(_.headers).length>0?_.headers:void 0,command:void 0,args:void 0,env:void 0,...q()}};m.useEffect(()=>{if(!t)return;const _=t==="new"?null:t;u("form"),x(_?.name??""),c(_?.description??""),l(_?.oauthClientName??""),g(_?.oauthMetadataUrl??""),C(_?.transport??"stdio"),N(_?.command??""),S((_?.args??[]).join(`
|
|
24
|
+
`)),k(gr(_?.env)),E(_?.url??""),A(mr(_?.headers)),V(_?.connectTimeoutSec?.toString()??""),U(_?.callTimeoutSec?.toString()??""),K(""),G(Z=>Z+1),oe(null)},[t]);const R=_=>n(_==="invalid-json"?"Invalid JSON":"No MCP servers found in JSON"),P=_=>{if(_===i)return;if(_==="json"){K(B()),G(he=>he+1),oe(null),u("json");return}const Z=Vs(L);if(!Z.ok){if(Z.error==="invalid-json"&&L.trim()){oe(R(Z.error));return}oe(null),u("form");return}if(Z.servers.length!==1){oe(n("JSON must describe a single MCP server to switch to the form"));return}const J=Z.servers[0];ie({...J,name:d.trim()||J.name}),oe(null),u("form")},ce=()=>{const _=Vs(L);if(!_.ok){oe(R(_.error));return}if(_.servers.length===1){const[Z]=_.servers;K(JSON.stringify(jr(Z),null,2)),G(J=>J+1),d.trim()||x(Z.name)}else K(JSON.stringify({mcpServers:Object.fromEntries(_.servers.map(Z=>[Z.name,jr(Z)]))},null,2)),G(Z=>Z+1);oe(null)},pe=!!d.trim()&&(w==="stdio"?!!b.trim():!!O.trim()),Ne=i==="json"?!!L.trim():pe,Ve=()=>{if(!t||!Ne)return;if(i==="json"){const Z=Vs(L);if(!Z.ok){oe(R(Z.error));return}if(!o&&Z.servers.length!==1){oe(n("JSON must describe a single MCP server"));return}if(o){const J=Z.servers.length===1;if(a(Z.servers.map(ke=>({...ee(ke,J&&d.trim()?d:ke.name),...J?{}:{description:void 0},id:crypto.randomUUID(),source:"Manual",enabled:!0})))===0){oe(n("This MCP server already exists"));return}}else r(t.id,ee(Z.servers[0],d.trim()||Z.servers[0].name));s();return}const _=w==="stdio"?{name:d.trim(),transport:w,command:b.trim(),args:pr(y),env:fr(D),url:void 0,headers:void 0,...q()}:{name:d.trim(),transport:w,url:O.trim(),headers:ur(M),command:void 0,args:void 0,env:void 0,...q()};if(o){if(a([{..._,id:crypto.randomUUID(),source:"Manual",enabled:!0}])===0){oe(n("This MCP server already exists"));return}}else r(t.id,_);s()};return e.jsx(fe,{open:t!==null,onOpenChange:_=>!_&&s(),children:e.jsxs(ge,{children:[e.jsx(je,{children:e.jsx(ve,{children:n(o?"Add MCP Server":"Edit MCP Server")})}),e.jsxs(we,{className:"space-y-4",children:[e.jsx(zt,{value:i,onValueChange:_=>P(_),children:e.jsxs(Bt,{children:[e.jsx(Ke,{value:"form",children:n("Form")}),e.jsx(Ke,{value:"json",children:n("JSON")})]})}),e.jsxs(ue,{children:[e.jsx(me,{children:n("Name")}),e.jsx(Y,{value:d,onChange:_=>x(_.target.value)})]}),e.jsxs(ue,{children:[e.jsx(me,{children:n("Description (optional)")}),e.jsx(Y,{value:h,onChange:_=>c(_.target.value),placeholder:n("One line telling the model what this server is for")})]}),i==="json"?e.jsxs(ue,{children:[e.jsxs("div",{className:"flex w-full items-center justify-between",children:[e.jsx(me,{children:n("JSON configuration")}),e.jsx(I,{variant:"ghost",size:"sm",className:"h-7 px-2",onClick:ce,children:n("Format")})]}),e.jsx(ci,{fileName:"mcp.json",value:L,epoch:$,onChange:K}),e.jsx("p",{className:"text-muted-foreground text-xs",children:n("Paste a server object or mcpServers JSON from Cursor / Claude Desktop")})]}):e.jsxs(e.Fragment,{children:[e.jsxs(ue,{children:[e.jsx(me,{children:n("Transport")}),e.jsxs(se,{items:pa.map(_=>({value:_,label:_})),value:w,onValueChange:_=>C(_),children:[e.jsx(ne,{className:"w-full",children:e.jsx(ae,{})}),e.jsx(re,{zIndex:et.DROPDOWN_IN_MODAL,children:pa.map(_=>e.jsx(Q,{value:_,children:_},_))})]})]}),w==="stdio"?e.jsxs(e.Fragment,{children:[e.jsxs(ue,{children:[e.jsx(me,{children:n("Command")}),e.jsx(Y,{value:b,onChange:_=>N(_.target.value),placeholder:"npx",className:"font-mono text-xs"})]}),e.jsxs(ue,{children:[e.jsx(me,{children:n("Arguments (one per line)")}),e.jsx(He,{value:y,onChange:_=>S(_.target.value),rows:3,className:"font-mono text-xs"})]}),e.jsxs(ue,{children:[e.jsx(me,{children:n("Environment variables (KEY=VALUE, one per line)")}),e.jsx(He,{value:D,onChange:_=>k(_.target.value),rows:3,className:"font-mono text-xs"})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs(ue,{children:[e.jsx(me,{children:n("URL")}),e.jsx(Y,{value:O,onChange:_=>E(_.target.value),placeholder:"https://...",className:"font-mono text-xs"})]}),e.jsxs(ue,{children:[e.jsx(me,{children:n("Headers (Name: value, one per line)")}),e.jsx(He,{value:M,onChange:_=>A(_.target.value),rows:2,placeholder:"Authorization: Bearer <token>",className:"font-mono text-xs"})]}),e.jsxs(ue,{children:[e.jsx(me,{children:n("OAuth client name (optional)")}),e.jsx(Y,{value:f,onChange:_=>l(_.target.value),placeholder:n("For servers that only accept known OAuth clients")})]}),e.jsxs(ue,{children:[e.jsx(me,{children:n("OAuth authorization server metadata URL (optional)")}),e.jsx(Y,{value:p,onChange:_=>g(_.target.value),placeholder:n("Use when the server advertises a wrong authorization server or none"),className:"font-mono text-xs"})]})]}),e.jsxs(ue,{children:[e.jsx(me,{children:n("Connection timeout (seconds)")}),e.jsx(Y,{inputMode:"numeric",value:F,onChange:_=>V(_.target.value),placeholder:String(ex/1e3)})]}),e.jsxs(ue,{children:[e.jsx(me,{children:n("Tool call timeout (seconds)")}),e.jsx(Y,{inputMode:"numeric",value:v,onChange:_=>U(_.target.value),placeholder:String(tx/1e3)})]})]}),X&&e.jsx("p",{className:"t-shake-in text-destructive text-xs",children:X},X)]}),e.jsxs(Ie,{children:[e.jsx(I,{variant:"outline",size:"sm",onClick:s,children:n("Cancel")}),e.jsx(I,{size:"sm",disabled:!Ne,onClick:Ve,children:n("Save")})]})]})})}function ix({status:t}){const{t:s}=z();return t.state==="connecting"?e.jsx(te,{variant:"outline",className:"shrink-0 animate-pulse text-[11px] text-muted-foreground",children:s("Connecting")}):t.state==="ready"?e.jsx(te,{variant:"success",className:"shrink-0 text-[11px]",children:s("{{count}} tools",{count:t.toolCount??0})}):t.state==="unauthorized"?e.jsx(te,{variant:"warning",className:"shrink-0 text-[11px]",children:s("Not authorized")}):t.state==="idle"?e.jsx(te,{variant:"outline",className:"shrink-0 text-[11px] text-muted-foreground",children:s("Authorized, pending connection")}):e.jsx(te,{variant:"error",className:"shrink-0 text-[11px]",title:t.error,children:s("Connection failed")})}function lx(){const{t}=z(),s=j(A=>A.mcpServers),n=j(A=>A.updateMcpServer),a=j(A=>A.setMcpServersEnabled),r=j(A=>A.removeMcpServer),o=dt(A=>A.statuses),i=dt(A=>A.authorized),u=dt(A=>A.pending),d=dt(A=>A.authorize),x=dt(A=>A.revoke);m.useEffect(()=>dt.getState().bind(),[]);const[h,c]=m.useState(!1),[f,l]=m.useState(null),p=async A=>{await d(A),l(dt.getState().authorized[A]===!0?A:null)},[g,w]=m.useState(null),[C,b]=m.useState(""),N=s.filter(A=>No(C,[A.name,A.source,A.transport,A.url,A.command,...A.args??[]])),y=N.map(A=>A.id),S=ko(y),D=s.filter(A=>A.enabled).length,k=s.filter(A=>A.enabled).map(A=>A.id),O=cs(k,A=>window.electronAPI.assets.mcpOccupancy(A)),E=s.filter(A=>A.enabled&&A.loadMode!=="deferred").map(A=>A.id),M=os(E,O.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:[t("MCP Servers"),e.jsx(qe,{}),s.length>0&&e.jsxs("span",{className:"ml-2 font-normal text-muted-foreground text-xs",children:[t("{{enabled}}/{{total}} enabled",{enabled:D,total:s.length}),e.jsx(ls,{tokens:M})]})]}),e.jsx("p",{className:"text-muted-foreground text-sm",children:t("Model Context Protocol servers available to this app")})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsxs(I,{variant:"outline",size:"sm",onClick:()=>c(!0),children:[e.jsx(rs,{className:"mr-1.5 h-4 w-4"}),t("Import from local apps")]}),e.jsxs(I,{variant:"outline",size:"sm",onClick:()=>w("new"),children:[e.jsx(Te,{className:"mr-1.5 h-4 w-4"}),t("Add MCP server")]})]})]}),s.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:t("No MCP servers yet")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:t("Import MCP servers from local apps or add one manually to get started")})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx(So,{query:C,onQueryChange:b,placeholder:t("Filter MCP servers..."),allSelected:S.allSelected,someSelected:S.someSelected,onToggleSelectAll:S.toggleAll,onEnable:()=>a(S.selectedIds,!0),onDisable:()=>a(S.selectedIds,!1),selectDisabled:N.length===0,actionDisabled:S.selectedIds.length===0}),N.length===0?e.jsx("p",{className:"px-3 py-6 text-center text-muted-foreground text-xs",children:t("No results")}):e.jsx("div",{className:"space-y-1",children:N.map(A=>{const F=o[A.id]??o[A.name],V=u[A.id]===!0,v=A.transport!=="stdio"&&i[A.id]!==!0,U=A.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.${A.id}`,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(Je,{checked:S.isSelected(A.id),onCheckedChange:L=>S.toggleOne(A.id,L)}),e.jsx("span",{className:H("shrink-0 font-medium text-sm",!A.enabled&&"text-muted-foreground line-through"),children:A.name}),e.jsx(te,{variant:"outline",className:"shrink-0 text-[11px]",children:A.transport}),e.jsx(te,{variant:"secondary",className:"shrink-0 text-[11px]",children:A.source}),F&&e.jsx(ix,{status:F}),e.jsx("span",{className:"min-w-0 truncate font-mono text-muted-foreground text-xs",children:A.url??[A.command,...A.args??[]].join(" ")})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[(v||F?.state==="unauthorized")&&e.jsxs(I,{variant:"outline",size:"sm",className:"h-7",disabled:V,onClick:()=>{p(A.id)},children:[V?e.jsx(Pe,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):e.jsx(Nc,{className:"mr-1.5 h-3.5 w-3.5"}),t(V?"Authorizing":"Authorize")]}),i[A.id]===!0&&e.jsx(I,{variant:"ghost",size:"icon",title:t("Revoke authorization"),className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",onClick:()=>{x(A.id)},children:e.jsx(kc,{className:"h-3.5 w-3.5"})}),e.jsx(is,{row:O.rows[A.id],pending:A.enabled&&O.pending&&!O.rows[A.id]}),e.jsx(zt,{value:U?"deferred":"direct",onValueChange:L=>n(A.id,{loadMode:L==="deferred"?"deferred":"direct"}),title:t("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(Bt,{"aria-label":t("Load mode"),children:[e.jsx(Ke,{value:"direct",className:"h-6 px-2 text-xs sm:h-6 sm:text-xs",children:t("Always loaded")}),e.jsx(Ke,{value:"deferred",className:"h-6 px-2 text-xs sm:h-6 sm:text-xs",children:t("On demand")})]})}),e.jsx(le,{checked:A.enabled,onCheckedChange:L=>n(A.id,{enabled:L})}),e.jsx(I,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",onClick:()=>w(A),children:e.jsx(it,{className:"h-3.5 w-3.5"})}),e.jsx(I,{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(A.id),children:e.jsx(Ee,{className:"h-3.5 w-3.5"})})]})]}),f===A.id&&e.jsx("p",{className:"px-3 text-muted-foreground text-xs",children:t("Authorized. Conversations that already include this server can use it on the next message.")})]},A.id)})})]}),e.jsx(Ln,{kind:"mcp",open:h,onOpenChange:c}),e.jsx(ox,{server:g,onClose:()=>w(null)})]})}const cx=["fact","preference","decision","plan","procedure","learning","context","event"],dx=.9,ux=.7,mx=.5;function hx(t){return Number.isFinite(t)?t>=dx?"critical":t>=ux?"important":t>=mx?"useful":"low":"low"}const vr=3,br={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 di(t){if(br[t]!==void 0)return br[t];let s=0;for(let n=0;n<t.length;n++)s=s*17+t.charCodeAt(n)>>>0;return s%360}const Ks=22,xx=64;function px(t,s){if(s<=1)return Ks;const n=Math.sqrt(Math.max(1,t))/Math.sqrt(s);return Math.round(Ks+(xx-Ks)*Math.min(1,n))}function fx(t,s,n){const a=Math.max(1,...t.map(o=>o.memoryCount)),r=new Set(t.map(o=>o.id));return[...t.map(o=>({data:{id:o.id,label:o.name,size:px(o.memoryCount,a),color:ui(di(o.entityType),n),entityType:o.entityType,memoryCount:o.memoryCount,spaceLabel:o.spaceLabel}})),...s.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(t,s){const n=new Map;for(const a of t)n.set(a.entityType,(n.get(a.entityType)??0)+1);return[...n.entries()].map(([a,r])=>({entityType:a,count:r,color:ui(di(a),s)})).sort((a,r)=>r.count-a.count||a.entityType.localeCompare(r.entityType))}function jx(t){const s=t?"#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:s,"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":t?"#4b4b52":"#c9c9d1","curve-style":"bezier",opacity:.65,"font-size":9,color:s,"text-opacity":0}},{selector:"edge:selected, edge.highlighted",style:{"text-opacity":.85,opacity:1}},{selector:"node:selected",style:{"border-width":3,"border-color":s,"background-opacity":1}},{selector:".dimmed",style:{opacity:.18,"text-opacity":.25}}]}function ui(t,s){return vx(t,s?.62:.68,s?.58:.52)}function vx(t,s,n){const a=(1-Math.abs(2*n-1))*s,r=a*(1-Math.abs(t/60%2-1)),o=n-a/2,[i,u,d]=t<60?[a,r,0]:t<120?[r,a,0]:t<180?[0,a,r]:t<240?[0,r,a]:t<300?[r,0,a]:[a,0,r],x=h=>Math.round((h+o)*255).toString(16).padStart(2,"0");return`#${x(i)}${x(u)}${x(d)}`}let yr=!1;function bx(){yr||(Ko.use(qd),yr=!0)}const wr={name:"fcose",animate:!1,randomize:!1,nodeRepulsion:8e3,idealEdgeLength:90,nodeSeparation:90,padding:24,fit:!0};function yx({graph:t,selectedId:s,onSelect:n,memories:a,loading:r,onInterpret:o,interpreting:i}){const{t:u}=z(),d=m.useRef(null),x=m.useRef(null),h=m.useRef(n);h.current=n;const[c,f]=m.useState(null),l=m.useMemo(()=>typeof document<"u"&&document.documentElement.classList.contains("dark"),[]);m.useEffect(()=>{const w=d.current;if(!w||t.nodes.length===0)return;bx();const C=Ko({container:w,elements:fx(t.nodes,t.edges,l),style:jx(l),minZoom:.2,maxZoom:2.5,wheelSensitivity:.2});return C.layout(wr).run(),C.on("tap","node",b=>h.current(b.target.id())),C.on("tap",b=>{b.target===C&&h.current(null)}),x.current=C,()=>{C.destroy(),x.current=null}},[t.nodes,t.edges,l]),m.useEffect(()=>{const w=x.current;w&&w.batch(()=>{if(w.elements().removeClass("dimmed").unselect(),!s)return;const C=w.getElementById(s);if(C.empty())return;const b=C.closedNeighborhood();w.elements().difference(b).addClass("dimmed"),C.select()})},[s]);const p=m.useMemo(()=>gx(t.nodes,l),[t.nodes,l]),g=t.nodes.find(w=>w.id===s)??null;return m.useEffect(()=>{const w=x.current;!w||s||w.batch(()=>{w.elements().removeClass("dimmed"),c&&w.nodes().filter(C=>C.data("entityType")!==c).addClass("dimmed")})},[c,s]),t.nodes.length===0?e.jsx("p",{className:"rounded-lg border px-3 py-6 text-muted-foreground text-sm",children:u(r?"Loading…":"No entities yet. Turn on entity extraction and store a few memories first.")}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"relative overflow-hidden rounded-lg border bg-muted/20",children:[e.jsx("div",{ref:d,className:"h-[440px] w-full"}),e.jsxs("div",{className:"absolute right-2 bottom-2 flex gap-1",children:[e.jsx(I,{size:"sm",variant:"outline",onClick:()=>x.current?.fit(void 0,24),title:u("Fit to view"),children:u("Fit")}),e.jsx(I,{size:"sm",variant:"outline",onClick:()=>x.current?.layout(wr).run(),title:u("Re-run layout"),children:u("Relayout")})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:u("Colour = entity type · size = how many memories mention it",{})}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:p.map(w=>e.jsxs("button",{type:"button",onClick:()=>f(c===w.entityType?null:w.entityType),className:H("inline-flex items-center gap-1.5 rounded-full border px-2 py-0.5 text-xs transition-colors",c===w.entityType?"border-foreground/40 bg-accent":"hover:bg-accent/50"),children:[e.jsx("span",{className:"size-2.5 shrink-0 rounded-full",style:{backgroundColor:w.color}}),e.jsx("span",{className:"text-muted-foreground",children:w.entityType.toLowerCase()}),e.jsx("span",{className:"tabular-nums",children:w.count})]},w.entityType))}),e.jsx("p",{className:"text-muted-foreground text-xs",children:u("{{shown}} of {{total}} entities",{shown:String(t.nodes.length),total:String(t.totalEntities)})})]}),g&&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:g.name}),e.jsx(te,{variant:"secondary",children:g.entityType})]}),e.jsx("p",{className:"text-muted-foreground text-xs",children:u("{{count}} memories · {{space}}",{count:String(g.memoryCount),space:g.spaceLabel})})]}),e.jsx(I,{size:"sm",variant:"outline",disabled:i,onClick:()=>o(g.id),children:u(i?"Interpreting…":"Interpret")})]}),e.jsxs("ul",{className:"divide-y rounded-lg border",children:[a.length===0&&e.jsx("li",{className:"px-3 py-4 text-muted-foreground text-sm",children:u("Loading…")}),a.map(w=>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:[w.isCrystal&&e.jsx("span",{title:u("Crystal"),children:"★"}),e.jsx("span",{className:"truncate",children:w.title}),e.jsx(te,{variant:"secondary",children:w.unitType})]}),e.jsx("p",{className:"line-clamp-2 text-muted-foreground text-xs",children:w.contentSummary})]},w.id))]})]})]})}function wx({tree:t,loading:s,selected:n,onToggle:a,onInterpretGroup:r,interpreting:o}){const{t:i}=z(),[u,d]=m.useState(new Set);return t.length===0?e.jsx("p",{className:"rounded-lg border px-3 py-6 text-muted-foreground text-sm",children:i(s?"Loading…":"No memories yet.")}):e.jsx("ul",{className:"divide-y rounded-lg border",children:t.map(x=>{const h=u.has(x.id),c=(x.children??[]).map(f=>f.memoryId).filter(f=>!!f);return e.jsxs("li",{children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 px-3 py-2",children:[e.jsx("button",{type:"button",className:"min-w-0 flex-1 text-left",onClick:()=>{const f=new Set(u);f.delete(x.id)||f.add(x.id),d(f)},children:e.jsxs("p",{className:"flex items-center gap-2 text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:h?"▾":"▸"}),e.jsx("span",{className:"truncate",children:x.label}),e.jsx(te,{variant:"secondary",children:x.count})]})}),e.jsx(I,{size:"sm",variant:"ghost",className:"shrink-0",disabled:o||c.length===0,onClick:()=>r(x),children:i("Interpret")})]}),h&&e.jsxs("ul",{className:"divide-y border-t bg-muted/20",children:[(x.children??[]).map(f=>e.jsxs("li",{className:"flex items-center gap-2 px-3 py-2",children:[f.memoryId&&e.jsx(Je,{checked:n.has(f.memoryId),onCheckedChange:()=>f.memoryId&&a(f.memoryId),"aria-label":i("Select memory")}),e.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-2",children:[f.isCrystal&&e.jsx("span",{title:i("Crystal"),children:"★"}),e.jsx("span",{className:"truncate text-sm",children:f.label})]})]},f.id)),x.count>(x.children?.length??0)&&e.jsx("li",{className:"px-3 py-2 text-muted-foreground text-xs",children:i("Showing {{shown}} of {{total}}",{shown:String(x.children?.length??0),total:String(x.count)})})]})]},x.id)})})}const Nx=120,kx=30,Cx={nodes:[],edges:[],totalEntities:0};function Sx({revision:t=0}={}){const{t:s}=z(),[n,a]=m.useState("graph"),[r,o]=m.useState("unitType"),[i,u]=m.useState(Cx),[d,x]=m.useState([]),[h,c]=m.useState(!0),[f,l]=m.useState(null),[p,g]=m.useState([]),[w,C]=m.useState(new Set),[b,N]=m.useState(null),[y,S]=m.useState(!1),[D,k]=m.useState(null),[O,E]=m.useState(!1),M=m.useCallback(()=>{c(!0);const $=()=>c(!1);n==="graph"?window.electronAPI.memory.graph({limit:Nx,minMemories:1}).then(u).finally($):window.electronAPI.memory.tree({groupBy:r,limitPerGroup:kx}).then(x).finally($)},[n,r]);m.useEffect(M,[M]);const A=m.useRef(M);A.current=M,m.useEffect(()=>window.electronAPI.memory.onChanged(()=>A.current()),[]);const F=m.useRef(t);m.useEffect(()=>{F.current!==t&&(F.current=t,M())},[t,M]),m.useEffect(()=>{if(!f){g([]);return}window.electronAPI.memory.graphEntity(f).then(g)},[f]);const V=async $=>{S(!0),N(null);try{N(await window.electronAPI.memory.insight($))}finally{S(!1)}},v=async()=>{E(!0);try{const $=await window.electronAPI.memory.crystallize({memoryIds:[...w]});k($),$.ok&&C(new Set)}finally{E(!1)}},U=[{value:"graph",label:s("Graph")},{value:"tree",label:s("Tree")}],L=[{value:"unitType",label:s("By type")},{value:"entity",label:s("By entity")},{value:"time",label:s("By month")}],K=w.size>=vr;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:s("Knowledge")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Browse what the agent knows as a graph or a tree, ask for an interpretation, and consolidate related memories into a crystal.")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(se,{value:n,items:U,onValueChange:$=>a($==="tree"?"tree":"graph"),children:[e.jsx(ne,{size:"sm",className:"w-32",children:e.jsx(ae,{})}),e.jsx(re,{children:U.map($=>e.jsx(Q,{value:$.value,children:$.label},$.value))})]}),n==="tree"&&e.jsxs(se,{value:r,items:L,onValueChange:$=>o($),children:[e.jsx(ne,{size:"sm",className:"w-36",children:e.jsx(ae,{})}),e.jsx(re,{children:L.map($=>e.jsx(Q,{value:$.value,children:$.label},$.value))})]}),e.jsx("span",{className:"flex-1"}),n==="tree"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:H("text-xs",K?"text-foreground":"text-muted-foreground"),children:s("{{count}} selected",{count:String(w.size)})}),e.jsx(I,{size:"sm",variant:"outline",disabled:!K||O,onClick:()=>{v()},children:O?s("Synthesizing…"):s("Crystallize ({{min}}+)",{min:String(vr)})})]})]}),n==="graph"?e.jsx(yx,{graph:i,loading:h,selectedId:f,onSelect:l,memories:p,interpreting:y,onInterpret:$=>{V({entityId:$})}}):e.jsx(wx,{tree:d,loading:h,selected:w,interpreting:y,onToggle:$=>{const G=new Set(w);G.delete($)||G.add($),C(G)},onInterpretGroup:$=>{const G=($.children??[]).map(X=>X.memoryId).filter(X=>!!X);V({memoryIds:G})}}),e.jsx(fe,{open:b!==null,onOpenChange:$=>!$&&N(null),children:e.jsxs(ge,{children:[e.jsxs(je,{children:[e.jsx(ve,{children:s("Interpretation")}),b?.ok&&e.jsx($e,{children:s("Based on {{count}} memories",{count:String(b.sourceCount??0)})})]}),e.jsx(we,{children:b?.ok?e.jsx("p",{className:"whitespace-pre-wrap text-sm",children:b.text}):e.jsx("p",{className:"text-destructive text-sm",children:b?.error})}),e.jsx(Ie,{children:e.jsx(It,{render:e.jsx(I,{variant:"outline",size:"sm"}),children:s("Close")})})]})}),e.jsx(fe,{open:D!==null,onOpenChange:$=>!$&&k(null),children:e.jsxs(ge,{children:[e.jsxs(je,{children:[e.jsx(ve,{children:D?.ok?s("Crystal created"):s("Nothing was written")}),D?.ok&&e.jsx($e,{children:D.title})]}),e.jsx(we,{className:"space-y-3",children:D?.ok?e.jsx("p",{className:"whitespace-pre-wrap text-sm",children:D.content}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-destructive text-sm",children:D?.error}),D?.candidates&&D.candidates.length>0&&e.jsx("ul",{className:"divide-y rounded-lg border",children:D.candidates.map($=>e.jsxs("li",{className:"flex items-center justify-between gap-2 px-3 py-2",children:[e.jsx("span",{className:"truncate text-sm",children:$.title}),e.jsxs(te,{variant:"secondary",children:[($.similarity*100).toFixed(0),"%"]})]},$.id))})]})}),e.jsx(Ie,{children:e.jsx(It,{render:e.jsx(I,{variant:"outline",size:"sm"}),children:s("Close")})})]})})]})}function xn(t){return t==="fast"||t==="deep"}const jt=25,rt="__all__";function mi(t){return t.slice(0,10)}function Ix(t,s){return t===!1&&!s}function Ax(t,s,n,a){return xn(t)&&!s.trim()?"needs-query":Ix(n,a)?"library-empty":"no-match"}function Ex({items:t,onOpen:s,t:n,selected:a,onToggle:r,emptyLabel:o}){return 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:o}),t.map(i=>e.jsxs("li",{className:"flex items-center gap-2 px-3 py-2",children:[r&&e.jsx(Je,{checked:a?.has(i.id)??!1,onCheckedChange:()=>r(i.id),"aria-label":n("Select memory")}),e.jsxs("button",{type:"button",onClick:()=>s(i.id),className:"min-w-0 flex-1 space-y-0.5 text-left",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[i.isCrystal&&e.jsx("span",{title:n("Crystal"),children:"★"}),e.jsx("span",{className:"truncate text-sm",children:i.title}),e.jsx(te,{variant:"secondary",children:i.unitType}),e.jsx(Px,{importance:i.importance,t:n}),i.lifecycleState==="archived"&&e.jsx(te,{variant:"outline",children:n("Archived")})]}),e.jsx("span",{className:"line-clamp-2 text-muted-foreground text-xs",children:i.contentSummary}),e.jsxs("span",{className:"block text-muted-foreground text-xs",children:[mi(i.updatedAt)," · ",i.spaceLabel," ·"," ",n("Retrieved {{count}} times",{count:String(i.appearances)})]})]})]},i.id))]})}const Mx={critical:{variant:"warning",label:"critical"},important:{variant:"info",label:"important"},useful:{variant:"outline",label:"useful"},low:{variant:"outline",label:"low"}};function Px({importance:t,t:s}){const n=hx(t),a=Mx[n];return e.jsx(te,{variant:a.variant,className:n==="low"?"text-muted-foreground":void 0,title:s("Importance {{value}}",{value:t.toFixed(2)}),children:s(a.label)})}function Tx({edges:t,onReview:s,t:n}){return t.length===0?null:e.jsxs("section",{className:"space-y-2","data-settings-row":"memory.review",children:[e.jsx("h3",{className:"text-sm font-medium",children:n("Needs review")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n("Reviewing only records your judgement. Nothing is deleted and no memory is superseded.")}),t.map(a=>e.jsxs("div",{className:"space-y-1 rounded-lg border px-3 py-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(te,{variant:"outline",children:a.relation}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[a.olderId.slice(0,8)," → ",a.newerId.slice(0,8)]})]}),a.reason&&e.jsx("p",{className:"text-xs text-muted-foreground",children:a.reason}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(I,{size:"sm",variant:"outline",onClick:()=>s(a.id,"accepted"),children:n("Accept")}),e.jsx(I,{size:"sm",variant:"ghost",onClick:()=>s(a.id,"rejected"),children:n("Dismiss")})]})]},a.id))]})}function Rx({writes:t,onReview:s,t:n}){return t.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.")}),t.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(I,{size:"sm",variant:"outline",onClick:()=>s(a.id,"approve"),children:n("Approve")}),e.jsx(I,{size:"sm",variant:"ghost",onClick:()=>s(a.id,"reject"),children:n("Reject")})]})]},a.id))]})}function Ox({t}){const s=Cc(),n=Sc(a=>a.review);return e.jsx(Rx,{writes:s,t,onReview:(a,r)=>{n(a,r)}})}function Dx({revision:t=0}={}){const{t:s}=z(),[n,a]=m.useState(""),[r,o]=m.useState(rt),[i,u]=m.useState(rt),[d,x]=m.useState(!1),[h,c]=m.useState(0),[f,l]=m.useState("exact"),[p,g]=m.useState(!1),[w,C]=m.useState(!0),[b,N]=m.useState([]),[y,S]=m.useState(0),[D,k]=m.useState([]),[O,E]=m.useState(null),[M,A]=m.useState(null),[F,V]=m.useState(null),[v,U]=m.useState(new Set),[L,K]=m.useState(!1),[$,G]=m.useState(!1),[X,oe]=m.useState([]),q=m.useRef(!1),ie=m.useRef(0),B=m.useRef(0);m.useEffect(()=>(q.current=!0,()=>{q.current=!1,ie.current++,B.current++}),[]);const ee=m.useCallback(()=>{if(!q.current)return;const W=++ie.current,Ce=()=>q.current&&W===ie.current;if(xn(f)&&!n.trim()){N([]),S(0),g(!0),C(!0);return}window.electronAPI.memory.list({query:n.trim()||void 0,spaceId:r===rt?void 0:r,unitType:i===rt?void 0:i,includeArchived:d,limit:jt,offset:h,mode:f}).then(Se=>{Ce()&&(N(Se.items),S(Se.total),g(Se.approximate===!0),C(Se.vectorsUsed!==!1))}),window.electronAPI.memory.stats().then(Se=>{q.current&&(k(Object.keys(Se.bySpace).map(De=>({id:De,label:Se.spaceLabels[De]??De}))),E(Se.total>0))}),window.electronAPI.memory.evolvesPending().then(Se=>{q.current&&oe(Se)})},[n,r,i,d,h,f]);m.useEffect(()=>(ee(),()=>{ie.current++}),[ee]);const R=m.useRef(ee);R.current=ee,m.useEffect(()=>window.electronAPI.memory.onChanged(()=>R.current()),[]);const P=m.useRef(t);m.useEffect(()=>{P.current!==t&&(P.current=t,ee())},[t,ee]);const ce=W=>{const Ce=++B.current;window.electronAPI.memory.detail(W).then(Se=>{q.current&&Ce===B.current&&A(Se)})},pe=()=>{B.current++,A(null)},Ne=async W=>{G(!0);try{for(const Ce of v)await W(Ce)}finally{q.current&&(G(!1),U(new Set),K(!1),R.current())}},Ve=()=>{Ne(W=>window.electronAPI.memory.archive(W))},_=()=>{Ne(W=>window.electronAPI.memory.delete(W))},Z=W=>{W.then(()=>{q.current&&(pe(),V(null),R.current())})},J=n.trim()!==""||r!==rt||i!==rt||d===!0,he=[{value:rt,label:s("All spaces")},...D.map(W=>({value:W.id,label:W.label}))],ke=[{value:rt,label:s("All types")},...cx.map(W=>({value:W,label:W}))],xt=[{value:"exact",label:s("Exact match")},{value:"fast",label:s("Fast retrieval")},{value:"deep",label:s("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:s("Stored memories")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("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(Io,{className:"w-full sm:w-96","data-size":"sm",children:[e.jsx(Ao,{value:n,placeholder:s("Search memories"),onChange:W=>{c(0),a(W.target.value)}}),e.jsx(Eo,{align:"inline-end",className:"pe-1",children:e.jsxs(se,{value:f,items:xt,onValueChange:W=>{c(0),l(W==="deep"?"deep":W==="fast"?"fast":"exact")},children:[e.jsx(ne,{size:"sm",className:"w-auto min-w-0 gap-1 border-0 bg-transparent px-2 shadow-none before:hidden",children:e.jsx(ae,{})}),e.jsx(re,{children:xt.map(W=>e.jsx(Q,{value:W.value,children:W.label},W.value))})]})})]}),e.jsxs(se,{value:r,items:he,onValueChange:W=>{c(0),o(String(W))},children:[e.jsx(ne,{size:"sm",className:"w-36",children:e.jsx(ae,{})}),e.jsx(re,{children:he.map(W=>e.jsx(Q,{value:W.value,children:W.label},W.value))})]}),e.jsxs(se,{value:i,items:ke,onValueChange:W=>{c(0),u(String(W))},children:[e.jsx(ne,{size:"sm",className:"w-36",children:e.jsx(ae,{})}),e.jsx(re,{children:ke.map(W=>e.jsx(Q,{value:W.value,children:W.label},W.value))})]}),f==="exact"&&e.jsxs("label",{className:"flex items-center gap-2 text-muted-foreground text-sm",children:[e.jsx(le,{checked:d,onCheckedChange:W=>{c(0),x(W===!0)}}),s("Show archived")]})]}),xn(f)&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:[s(f==="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."),!w&&` ${s("Embedding model is not ready, so vectors are skipped.")}`]}),v.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:s("{{count}} selected",{count:String(v.size)})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(I,{variant:"ghost",size:"sm",disabled:$,onClick:()=>U(new Set),children:s("Clear selection")}),e.jsx(I,{variant:"outline",size:"sm",disabled:$,onClick:()=>Ve(),children:s("Archive selected")}),e.jsx("button",{type:"button",disabled:$,className:"text-xs text-muted-foreground underline-offset-2 hover:underline disabled:opacity-50",onClick:()=>K(!0),children:s("Delete permanently")})]})]}),e.jsx(Ex,{items:b,onOpen:ce,t:s,selected:v,emptyLabel:{"needs-query":s("Type a query to search by meaning."),"library-empty":s("No memories yet. They appear here once the agent stores something."),"no-match":s("No memories match these filters.")}[Ax(f,n,O,J)],onToggle:W=>{const Ce=new Set(v);Ce.delete(W)||Ce.add(W),U(Ce)}}),!p&&y>jt&&e.jsxs("div",{className:"flex items-center justify-between text-xs text-muted-foreground",children:[e.jsx(I,{variant:"outline",size:"sm",disabled:h===0,onClick:()=>c(Math.max(0,h-jt)),children:s("Previous")}),e.jsxs("span",{children:[h+1,"–",Math.min(h+jt,y)," / ",y]}),e.jsx(I,{variant:"outline",size:"sm",disabled:h+jt>=y,onClick:()=>c(h+jt),children:s("Next")})]}),e.jsx(Ox,{t:s}),e.jsx(Tx,{edges:X,t:s,onReview:(W,Ce)=>Z(window.electronAPI.memory.evolvesReview(W,Ce))}),e.jsx(fe,{open:M!==null,onOpenChange:W=>!W&&pe(),children:e.jsx(ge,{children:M&&e.jsxs(e.Fragment,{children:[e.jsxs(je,{children:[e.jsx(ve,{children:M.title}),e.jsx($e,{children:[M.unitType,M.spaceLabel,mi(M.createdAt)].join(" · ")})]}),e.jsxs(we,{className:"space-y-4",children:[e.jsx("p",{className:"whitespace-pre-wrap text-sm",children:M.content}),e.jsxs("dl",{className:"grid grid-cols-2 gap-x-4 gap-y-3",children:[e.jsx(qs,{label:s("Importance"),value:M.importance.toFixed(2)}),e.jsx(qs,{label:s("Embedding"),value:M.embeddingModel??s("Not vectorized")}),M.eventStart&&e.jsx(qs,{label:s("Event date"),value:`${M.eventStart}${M.eventEnd?` → ${M.eventEnd}`:""}`})]}),M.entityNames.length>0&&e.jsxs("section",{className:"space-y-1.5",children:[e.jsx("p",{className:"font-medium text-xs",children:s("Entities")}),e.jsx("div",{className:"flex flex-wrap gap-1",children:M.entityNames.map(W=>e.jsx(te,{variant:"secondary",children:W},W))})]}),M.crystalSources.length>0&&e.jsxs("section",{className:"space-y-1.5",children:[e.jsx("p",{className:"font-medium text-xs",children:s("Synthesized from")}),e.jsx("ul",{className:"divide-y rounded-lg border",children:M.crystalSources.map(W=>e.jsxs("li",{className:"flex items-center justify-between gap-2 px-3 py-2",children:[e.jsx("span",{className:"truncate text-sm",children:W.title}),e.jsxs("span",{className:"shrink-0 text-muted-foreground text-xs",children:[(W.contributionWeight*100).toFixed(0),"%"]})]},W.id))})]}),M.evolves.length>0&&e.jsxs("section",{className:"space-y-1.5",children:[e.jsx("p",{className:"font-medium text-xs",children:s("Related versions")}),e.jsx("ul",{className:"divide-y rounded-lg border",children:M.evolves.map(W=>e.jsxs("li",{className:"flex items-center gap-2 px-3 py-2",children:[e.jsx(te,{variant:"outline",children:W.relation}),e.jsx("span",{className:"text-muted-foreground text-xs",children:W.reviewState})]},W.id))})]})]}),e.jsxs(Ie,{children:[e.jsx(I,{variant:"ghost",size:"sm",className:"sm:me-auto",onClick:()=>V(M.id),children:s("Delete permanently")}),M.lifecycleState==="archived"?e.jsx(I,{variant:"outline",size:"sm",onClick:()=>Z(window.electronAPI.memory.restore(M.id)),children:s("Restore")}):e.jsx(I,{variant:"outline",size:"sm",onClick:()=>Z(window.electronAPI.memory.archive(M.id)),children:s("Archive")})]})]})})}),e.jsx(fe,{open:L,onOpenChange:W=>!W&&K(!1),children:e.jsxs(ge,{children:[e.jsxs(je,{children:[e.jsx(ve,{children:s("Delete {{count}} memories permanently?",{count:String(v.size)})}),e.jsx($e,{children:s("This cannot be undone. Archiving keeps the memory out of search while preserving it.")})]}),e.jsxs(Ie,{children:[e.jsx(It,{render:e.jsx(I,{variant:"outline",size:"sm"}),children:s("Cancel")}),e.jsx(I,{variant:"destructive",size:"sm",disabled:$,onClick:_,children:s("Delete permanently")})]})]})}),e.jsx(fe,{open:F!==null,onOpenChange:W=>!W&&V(null),children:e.jsxs(ge,{children:[e.jsxs(je,{children:[e.jsx(ve,{children:s("Delete this memory permanently?")}),e.jsx($e,{children:s("This cannot be undone. Archiving keeps the memory out of search while preserving it.")})]}),e.jsxs(Ie,{children:[e.jsx(It,{render:e.jsx(I,{variant:"outline",size:"sm"}),children:s("Cancel")}),e.jsx(I,{variant:"destructive",size:"sm",onClick:()=>F&&Z(window.electronAPI.memory.delete(F)),children:s("Delete permanently")})]})]})})]})}function qs({label:t,value:s}){return e.jsxs("div",{className:"min-w-0",children:[e.jsx("dt",{className:"text-muted-foreground text-xs",children:t}),e.jsx("dd",{className:"truncate text-sm",children:s})]})}const Nr=t=>t.slice(0,8);function Gs(t,s){return t==="pending"||t==="running"?"running":t==="cancelled"?"cancelled":s?"failed":"done"}const Lx={low_importance:"importance too low",candidates_found:"similar memory already exists",deduplicated:"identical to an existing memory",rejected:"rejected"};function zx(t){const s=[];for(const r of t.distill){const o=Gs(r.status,r.error);s.push({key:`distill:${r.id}`,kind:"distill",target:r.sessionTitle||Nr(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,Lx[i.kind]??i.kind].filter(Boolean).join(" — ")),updatedAt:r.updatedAt})}for(const r of t.kg){const o=Gs(r.status,r.error);s.push({key:`kg:${r.id}`,kind:"kg",target:r.memoryTitle||Nr(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=t.reembed;if(n){const r=Gs(n.status,n.error);s.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 s.sort((r,o)=>a(r)-a(o)||o.updatedAt.localeCompare(r.updatedAt))}const Rt="remote:openai-compatible",ss="remote:";function kr(t){return t.id==="none"?"None (full-text only)":t.id.replace(/^(local|remote):/,"")}function ds(t){return t.startsWith(ss)&&t.length>ss.length}function Bx(t){return ds(t)?Rt:t}function _x(t){return!ds(t)||t===Rt?null:t.slice(ss.length)}function Fx(t){return`${ss}${t}`}function Ux(t,s){return s===Rt?ds(t)?t:Rt:s}const $x=4e3,Vx=800,Cr=6,Kx={distill:"job:distill",kg:"job:entities",reembed:"job:vectors"},Sr={distill:[],kg:[],reembed:null,kgFailed:0};function qx(t){return t.some(s=>s.distilled)}function Ir(t){return!t||t.total===0||t.embedded>=t.total?null:t.embeddingError??null}function Ar(t){return t?.downloadable&&(t.state==="missing"||t.state==="downloading")?t.state:null}function Gx(t,s){if(t.done===0||t.done>=t.total)return null;const n=(s-t.startedAt)/t.done;return Math.round(n*(t.total-t.done))}function Hx(t){const s=Math.max(1,Math.round(t/1e3));if(s<60)return`${s}s`;const n=Math.floor(s/60);return s%60===0?`${n}m`:`${n}m ${s%60}s`}function Wx(t){const s=new Map;for(const a of t){const r=a.projectId??"",o=s.get(r);if(o){o.sessions.push(a);continue}s.set(r,{key:r,name:a.projectName??"No project",sessions:[a]})}const n=[...s.values()];return[...n.filter(a=>a.key),...n.filter(a=>!a.key)]}function de(t){if(t<=0)return"0 B";const s=["B","KB","MB","GB"],n=Math.min(Math.floor(Math.log(t)/Math.log(1024)),s.length-1);return`${(t/1024**n).toFixed(n===0?0:1)} ${s[n]}`}function Hs({title:t,description:s,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:t}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s})]}),e.jsx(le,{checked:n,disabled:o,onCheckedChange:i=>a(i===!0)})]})}function Yx({onLibraryChanged:t}={}){const{t:s}=z(),n=j(T=>T.disabledBuiltinTools),a=j(T=>T.memoryEmbeddingModel),r=j(T=>T.setMemoryEmbeddingModel),o=j(T=>T.memoryEmbeddingAutoDownload),i=j(T=>T.setMemoryEmbeddingAutoDownload),u=j(T=>T.memoryModelIdleMinutes),d=j(T=>T.setMemoryModelIdleMinutes),x=j(T=>T.memoryEmbeddingRemoteProviderId),h=j(T=>T.setMemoryEmbeddingRemoteProviderId),c=j(T=>T.memoryDistillEnabled),f=j(T=>T.setMemoryDistillEnabled),l=j(T=>T.memoryKgEnabled),p=j(T=>T.setMemoryKgEnabled),g=j(T=>T.memoryDistillModel),w=j(T=>T.setMemoryDistillModel),C=j(T=>T.memoryChatModel)||"remote",b=j(T=>T.setMemoryChatModel),N=j(T=>T.memoryLanguage),y=j(T=>T.setMemoryLanguage),S=Qe(),D=g?S.find(T=>T.id===g.providerId):void 0,k=D?.models.find(T=>T.id===g?.modelId),O=_x(a),E=x?S.find(T=>T.id===x):void 0,M=E?.models.find(T=>T.id===O),A=!n.includes("memory"),[F,V]=m.useState(null),[v,U]=m.useState(Sr),[L,K]=m.useState([]),[$,G]=m.useState(null),[X,oe]=m.useState([]),[q,ie]=m.useState(null),[B,ee]=m.useState([]),[R,P]=m.useState(null),[ce,pe]=m.useState(null),[Ne,Ve]=m.useState(null),[_,Z]=m.useState(null),[J,he]=m.useState(!1),[ke,xt]=m.useState(!1),W=m.useRef(!1);W.current=J;const Ce=m.useRef(null),Se=m.useCallback(()=>{window.electronAPI.memory.distillableSessions().then(ee)},[]);m.useEffect(()=>{A&&Se()},[A,Se]);const De=m.useCallback(()=>{window.electronAPI.memory.models().then(K)},[]);m.useEffect(()=>(De(),window.electronAPI.memory.onModelProgress(T=>{G(T.done?null:T),T.done&&De()})),[De]);const xe=m.useCallback(()=>{window.electronAPI.memory.chatModels().then(T=>oe(T.filter(ye=>!ye.purpose)))},[]);m.useEffect(()=>(xe(),window.electronAPI.memory.onChatModelProgress(T=>{ie(T.done?null:T),T.done&&xe()})),[xe]),m.useEffect(()=>{if(!A){V(null),U(Sr);return}let T=!1;const ye=()=>{window.electronAPI.memory.stats().then(Xe=>{T||V(Xe)}),window.electronAPI.memory.jobs().then(Xe=>{T||(U(Xe),W.current&&Xe.reembed?.status!=="running"&&he(!1))})};Ce.current=ye,ye();const ct=window.electronAPI.memory.onChanged(ye),Et=window.setInterval(ye,J?Vx:$x);return()=>{T=!0,Ce.current=null,ct(),window.clearInterval(Et)}},[A,J]);const st=Wx(B),$n=B.filter(T=>!T.distilled),Vn=(T,ye,ct)=>{const Et=T.filter(Xe=>!Xe.distilled);if(!qx(T)){Ft(T,ye);return}Z({token:ye,label:ct,scope:T,pending:Et})},Ft=async(T,ye,ct=!1)=>{const Et=X.find(ft=>ft.id===C)??null;if(Ar(Et))return;P(ye);const Xe=Date.now();Ve({done:0,total:T.length,startedAt:Xe});try{for(let ft=0;ft<T.length;ft++)await window.electronAPI.memory.distillSession(T[ft].sessionId,ct),Ve({done:ft+1,total:T.length,startedAt:Xe})}finally{P(null),Ve(null),Se(),t?.()}},be=L.find(T=>T.id===a)??null,Re=X.find(T=>T.id===C)??null,lt=Ar(Re),Kn=X.map(T=>({value:T.id,label:T.id==="remote"?s("Remote (API model)"):T.label})),qn=[...L.map(T=>({value:T.id,label:kr(T)})),{value:Rt,label:s("Remote (OpenAI-compatible)")}],Gn=Ic.map(T=>({value:String(T),label:T===0?s("Never"):s("{{count}} min",{count:T})})),Hn=[{value:"en",label:s("English")},{value:"zh",label:s("Simplified Chinese")},{value:"auto",label:s("Follow conversation")}],us=ds(a)||be?.runtime==="openai-compatible",pt=m.useMemo(()=>zx(v),[v]);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:s("Memory")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("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:s("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:s("Unload automatically when idle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Release local model memory after this idle period. Models load automatically the next time they are needed.")})]}),e.jsxs(se,{value:String(u),items:Gn,onValueChange:T=>{T!==null&&d(Number(T))},disabled:!A,children:[e.jsx(ne,{className:"w-56 shrink-0","aria-label":s("Unload automatically when idle"),children:e.jsx(ae,{})}),e.jsx(re,{children:Gn.map(T=>e.jsx(Q,{value:T.value,children:T.label},T.value))})]})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium",children:s("Embedding model")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("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?kr(be):O??(us?s("Remote (OpenAI-compatible)"):a)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:be?[be.dim?`${be.dim}d`:null,be.downloadable?de(be.approxBytes):null,be.runtime].filter(Boolean).join(" · "):us?"openai-compatible":s("Unknown model; the default is used instead.")})]}),e.jsxs(se,{value:Bx(a),items:qn,onValueChange:T=>{T!==null&&r(Ux(a,String(T)))},disabled:!A,children:[e.jsx(ne,{className:"w-56",children:e.jsx(ae,{})}),e.jsx(re,{children:qn.map(T=>e.jsx(Q,{value:T.value,children:T.label},T.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"?s("Model downloaded"):be.state==="downloading"?s("Downloading…"):s("Model not downloaded")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:$&&$.modelId===be.id?`${$.file} · ${de($.received)}${$.total?` / ${de($.total)}`:""} (${$.fileIndex+1}/${$.fileCount})`:be.state==="ready"?de(be.downloadedBytes):s("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(I,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.memory.cancelModelDownload(be.id).then(De)},children:s("Cancel")}):be.state==="ready"?e.jsx(I,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.memory.deleteModel(be.id).then(De)},children:s("Remove")}):e.jsx(I,{size:"sm",disabled:!A,onClick:()=>{window.electronAPI.memory.downloadModel(be.id).then(De)},children:s("Download")})})]}),us&&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:s("Remote model")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Credentials stay in the main process and are never sent to the renderer.")})]}),S.length>0&&e.jsx("div",{className:"w-56 shrink-0",children:e.jsx(Oe,{providers:S,providerId:E?.id??x??"",modelId:M?.id??O??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:s("Select model"),side:"bottom",triggerClassName:Ye,onSelect:(T,ye)=>{h(T),r(Fx(ye))},onReasoningChange:()=>{},onThinkingChange:()=>{}})})]}),e.jsx(Hs,{rowId:"memory.autoDownload",title:s("Download models automatically"),description:s("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:!A})]}),e.jsxs("section",{className:"space-y-2","data-settings-row":"memory.distillModel",children:[e.jsx("h3",{className:"text-sm font-medium",children:s("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:s("Completion backend")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Local GGUF runs on this machine. Remote uses the model below.")})]}),e.jsxs(se,{value:C,items:Kn,onValueChange:T=>b(String(T)),disabled:!A,children:[e.jsx(ne,{className:"w-56",children:e.jsx(ae,{})}),e.jsx(re,{children:Kn.map(T=>e.jsx(Q,{value:T.value,children:T.label},T.value))})]})]}),Re?.downloadable&&e.jsxs("div",{className:H("flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5",lt==="missing"&&"border-destructive/50"),children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:Re.state==="ready"?s("Model downloaded"):Re.state==="downloading"?s("Downloading…"):s("Model not downloaded")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:q&&q.modelId===Re.id?`${q.file} · ${de(q.received)}${q.total?` / ${de(q.total)}`:""}`:Re.state==="ready"?de(Re.downloadedBytes):de(Re.approxBytes)})]}),e.jsx("div",{className:"flex shrink-0 gap-2",children:Re.state==="downloading"?e.jsx(I,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.memory.cancelChatModelDownload(Re.id).then(xe)},children:s("Cancel")}):Re.state==="ready"?e.jsx(I,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.memory.deleteChatModel(Re.id).then(xe)},children:s("Remove")}):e.jsx(I,{size:"sm",disabled:!A,onClick:()=>{window.electronAPI.memory.downloadChatModel(Re.id).then(xe)},children:s("Download")})})]}),lt==="missing"&&e.jsx("p",{className:"text-xs text-destructive",children:s("Local model selected but the weights are not on disk. Distillation and interpretation will wait until you click Download.")}),lt==="downloading"&&e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Download in progress. Distillation waits until the model is ready.")}),C==="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:s("Distillation model")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Reads finished sessions and writes the memories.")})]}),S.length>0&&e.jsx("div",{className:"w-56 shrink-0",children:e.jsx(Oe,{providers:S,providerId:D?.id??"",modelId:k?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:s("Follows the title-summary model"),side:"bottom",triggerClassName:Ye,onSelect:(T,ye)=>w({providerId:T,modelId:ye}),onReasoningChange:()=>{},onThinkingChange:()=>{}})})]}),g&&e.jsx(I,{variant:"ghost",size:"sm",onClick:()=>w(null),children:s("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:s("Memory language")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("English keeps retrieval and near-duplicate detection stable across languages. Choose Follow conversation if your team only works in one language.")})]}),e.jsxs(se,{value:N,items:Hn,onValueChange:T=>y(String(T)),disabled:!A,children:[e.jsx(ne,{className:"w-56",children:e.jsx(ae,{})}),e.jsx(re,{children:Hn.map(T=>e.jsx(Q,{value:T.value,children:T.label},T.value))})]})]})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium",children:s("Background processing")}),e.jsx(Hs,{rowId:"memory.distill",title:s("Distill sessions automatically"),description:s("When a session ends, or goes idle for 30 minutes and is reclaimed, extract 1-3 durable memories from it in the background."),checked:c,onChange:f,disabled:!A}),c&<&&e.jsx("p",{className:"text-xs text-destructive",children:s("Automatic distillation is on, but the local model is not ready. Sessions will queue until you download it.")}),e.jsx(Hs,{rowId:"memory.kg",title:s("Extract entities"),description:s("Build an entity graph so a memory can be recalled by a name it does not literally contain."),checked:l,onChange:p,disabled:!A})]}),e.jsxs("section",{className:"space-y-2","data-settings-row":"memory.stats",children:[e.jsx("h3",{className:"text-sm font-medium",children:s("Library")}),F===null||F.total===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:s("No memories stored yet.")}):e.jsxs(e.Fragment,{children:[Ir(F)&&e.jsx("p",{className:"text-xs text-destructive",children:s("Vectors unavailable: {{reason}}",{reason:Ir(F)??""})}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-3",children:[e.jsx(vt,{label:s("Memories"),value:String(F.total)}),e.jsx(vt,{label:s("Crystals"),value:String(F.crystals)}),e.jsx(vt,{label:s("Entities"),value:String(F.entities)}),e.jsx(vt,{label:s("With vectors"),value:`${F.embedded}/${F.total}`,action:F.embedded<F.total?e.jsx("button",{type:"button",disabled:J,className:"text-xs text-muted-foreground underline-offset-2 hover:underline disabled:opacity-60",onClick:()=>{he(!0),window.electronAPI.memory.reembed().then(()=>Ce.current?.())},children:s(J?"Backfilling…":"Backfill")}):null}),e.jsx(vt,{label:s("Database size"),value:de(F.databaseBytes)}),e.jsx(vt,{label:s("Spaces"),value:String(Object.keys(F.bySpace).length)})]})]})]}),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:s("Distill past sessions")}),$n.length>0&&e.jsx(I,{size:"sm",variant:"outline",disabled:!A||R!==null||lt!==null,onClick:()=>Vn(B,"all",s("All sessions")),children:R==="all"?s("Distilling…"):s("Distill all ({{count}})",{count:String($n.length)})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("The automatic switch only covers sessions that end from now on. Distill earlier sessions here to fill the library.")}),Ne&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:[s("{{done}}/{{total}} done",{done:String(Ne.done),total:String(Ne.total)}),(()=>{const T=Gx(Ne,Date.now());return T===null?"":` · ${s("about {{time}} left",{time:Hx(T)})}`})()]}),st.length===0?e.jsx("p",{className:"text-muted-foreground text-sm",children:s("No recorded sessions found.")}):e.jsx("ul",{className:"divide-y rounded-lg border",children:st.map(T=>{const ye=T.sessions.filter(ct=>!ct.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:T.name}),e.jsx("p",{className:"text-muted-foreground text-xs",children:s("{{total}} sessions · {{pending}} not distilled",{total:String(T.sessions.length),pending:String(ye.length)})})]}),e.jsxs("div",{className:"flex shrink-0 gap-2",children:[e.jsx(I,{size:"sm",variant:"ghost",onClick:()=>pe(T),children:s("View sessions")}),e.jsx(I,{size:"sm",variant:"outline",disabled:!A||R!==null||T.sessions.length===0||lt!==null,onClick:()=>Vn(T.sessions,T.key,T.name),children:R===T.key?s("Distilling…"):s("Distill project")})]})]},T.key)})})]}),e.jsx(fe,{open:ce!==null,onOpenChange:T=>!T&&pe(null),children:e.jsx(ge,{children:ce&&e.jsxs(e.Fragment,{children:[e.jsxs(je,{children:[e.jsx(ve,{children:ce.name}),e.jsx($e,{children:s("{{total}} sessions · {{pending}} not distilled",{total:String(ce.sessions.length),pending:String(ce.sessions.filter(T=>!T.distilled).length)})})]}),e.jsx(we,{children:e.jsx("ul",{className:"divide-y rounded-lg border",children:ce.sessions.map(T=>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:T.title}),e.jsxs("p",{className:"text-muted-foreground text-xs",children:[T.updatedAt?T.updatedAt.slice(0,10):"",T.distilled?` · ${s("Already distilled")}`:""]})]}),e.jsx(I,{size:"sm",variant:"ghost",className:"shrink-0",disabled:!A||R!==null||lt!==null,onClick:()=>{Ft([T],T.sessionId,T.distilled)},children:R===T.sessionId?s("Distilling…"):T.distilled?s("Distill again"):s("Distill")})]},T.sessionId))})}),e.jsx(Ie,{children:e.jsx(It,{render:e.jsx(I,{variant:"outline",size:"sm"}),children:s("Close")})})]})})}),e.jsx(fe,{open:_!==null,onOpenChange:T=>!T&&Z(null),children:e.jsx(ge,{children:_&&e.jsxs(e.Fragment,{children:[e.jsxs(je,{children:[e.jsx(ve,{children:s("Some sessions were already distilled")}),e.jsx($e,{children:s("{{label}}: {{total}} sessions, {{done}} already distilled. Re-distilling runs the model again and may add new memories alongside the existing ones.",{label:_.label,total:String(_.scope.length),done:String(_.scope.length-_.pending.length)})})]}),e.jsxs(Ie,{children:[e.jsx(It,{render:e.jsx(I,{variant:"ghost",size:"sm"}),children:s("Cancel")}),e.jsx(I,{variant:_.pending.length>0?"default":"outline",size:"sm",disabled:_.pending.length===0,onClick:()=>{const T=_;Z(null),Ft(T.pending,T.token)},children:s("Only the {{count}} remaining",{count:String(_.pending.length)})}),e.jsx(I,{variant:_.pending.length>0?"outline":"default",size:"sm",onClick:()=>{const T=_;Z(null),Ft(T.scope,T.token,!0)},children:s("Re-distill all {{count}}",{count:String(_.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:s("Background tasks")}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[v.kgFailed>0&&e.jsx(I,{size:"sm",variant:"ghost",onClick:()=>{window.electronAPI.memory.retryFailedKgJobs().then(()=>Ce.current?.())},children:s("Retry failed extractions ({{count}})",{count:String(v.kgFailed)})}),pt.some(T=>T.state!=="running")&&e.jsx(I,{size:"sm",variant:"ghost",title:s("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:s("Clear finished tasks")}),pt.length>Cr&&e.jsx(I,{size:"sm",variant:"ghost",onClick:()=>xt(!ke),children:ke?s("Show less"):s("Show all {{count}}",{count:String(pt.length)})})]})]}),pt.length===0?e.jsx("p",{className:"text-muted-foreground text-sm",children:s("Nothing running.")}):e.jsx("ul",{className:"divide-y rounded-lg border",children:(ke?pt:pt.slice(0,Cr)).map(T=>e.jsxs("li",{className:"space-y-1 px-3 py-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(te,{variant:T.state==="failed"?"destructive":"secondary",children:s(Kx[T.kind])}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-sm",children:T.target}),e.jsx("span",{className:H("shrink-0 text-xs",T.state==="failed"?"text-destructive":"text-muted-foreground"),children:T.state==="running"?`⋯ ${T.detail}`:T.detail})]}),T.notes.map(ye=>e.jsxs("p",{className:"pl-1 text-muted-foreground text-xs",children:["· ",ye]},ye))]},T.key))})]})]})}function vt({label:t,value:s,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:t}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-sm",children:s}),n]})]})}function Jx(t,s){if(s===null)return{ok:!0,value:null};if(t.type==="boolean")return typeof s=="boolean"?{ok:!0,value:s}:s==="true"||s==="false"?{ok:!0,value:s==="true"}:{ok:!1,error:"需要打开或关闭"};if(typeof s!="string")return{ok:!1,error:"值不合法"};if(t.type==="number"){const n=s.trim();if(!/^-?\d+(\.\d+)?$/.test(n))return{ok:!1,error:"需要数字"};const a=Number(n);return Number.isFinite(a)?t.min!==void 0&&a<t.min?{ok:!1,error:"小于最小值"}:t.max!==void 0&&a>t.max?{ok:!1,error:"大于最大值"}:{ok:!0,value:a}:{ok:!1,error:"需要数字"}}return t.type==="enum"?t.options?.includes(s)?{ok:!0,value:s}:{ok:!1,error:"不在可选项里"}:s.length>4096||s.includes("\0")?{ok:!1,error:"值不合法"}:{ok:!0,value:s}}const Qx={"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":"在你点击时于本项目新建会话"};function hi(t){return Qx[t]??t}function Xx(t){return{installedKey:t,refresh:!0}}function Zx(t,s){return t.installedKey===s?t:{installedKey:s,refresh:!1}}function ep(t){const s=new Set;for(const n of t)for(const a of n.tags){const r=a.trim();r&&s.add(r)}return[...s].sort((n,a)=>n.localeCompare(a))}function tp(t,s){const n=s.query.trim().toLowerCase(),a=s.category?.trim()||null;return t.filter(r=>a&&!r.tags.some(o=>o.trim()===a)?!1:n?[r.id,r.name,r.description,...r.tags].some(o=>o.toLowerCase().includes(n)):!0)}function sp({disabled:t,installedKey:s,onInstall:n,onGuide:a}){const{t:r}=z(),o=window.electronAPI.extensionPlugins,[i,u]=m.useState(null),[d,x]=m.useState(!1),[h,c]=m.useState(""),[f,l]=m.useState(null),[p,g]=m.useState(()=>Xx(s)),w=Zx(p,s);w!==p&&g(w);const C=m.useCallback(async k=>{x(!0);try{u(await o.marketList(k))}catch(O){u({ok:!1,error:O instanceof Error?O.message:String(O),chinaMirror:!1})}finally{x(!1)}},[o]);m.useEffect(()=>{C(p.refresh)},[C,p]);const b=async k=>{await o.setMarketChinaMirror(k),await C(!0)},N=i?.ok===!0?i.plugins:[],y=ep(N),S=f!==null&&y.includes(f)?f:null,D=tp(N,{query:h,category:S});return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Y,{value:h,placeholder:r("Search plugins"),onChange:k=>c(k.target.value)}),e.jsxs("label",{className:"flex shrink-0 items-center gap-1.5 text-muted-foreground text-xs",children:[e.jsx(le,{checked:i?.chinaMirror??!1,disabled:d,onCheckedChange:k=>{b(k)}}),r("China mirror")]}),e.jsx(I,{size:"sm",variant:"ghost",disabled:d,onClick:()=>{C(!0)},children:d?e.jsx(Nt,{}):r("Refresh")})]}),y.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1",children:[e.jsx(I,{size:"xs",variant:S===null?"secondary":"outline","aria-pressed":S===null,onClick:()=>l(null),children:r("All")}),y.map(k=>e.jsx(I,{size:"xs",variant:S===k?"secondary":"outline","aria-pressed":S===k,onClick:()=>l(k),children:k},k))]}),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.")}),i?.ok===!0&&D.length===0&&e.jsx("p",{className:"text-muted-foreground text-sm",children:r("No matching plugins")}),D.map(k=>e.jsxs("div",{className:"flex items-start gap-3 py-1",children:[e.jsx(np,{src:k.icon}),e.jsxs("div",{className:"min-w-0 flex-1 space-y-0.5",children:[e.jsxs("p",{className:"truncate text-sm",children:[k.name,e.jsx("span",{className:"ml-2 text-muted-foreground text-xs",children:k.latest}),e.jsx(te,{variant:k.tier==="official"?"secondary":"outline",className:"ml-2",children:k.tier==="official"?r("Official"):r("Community")})]}),k.description&&e.jsx("p",{className:"text-muted-foreground text-xs",children:k.description}),k.permissions.length>0&&e.jsx("p",{className:"text-muted-foreground text-xs",children:k.permissions.map(O=>hi(O)).join("、")})]}),e.jsx(I,{size:"sm",variant:"ghost",onClick:()=>a(k.id,k.name,k.homepage),children:r("Usage guide")}),e.jsxs("div",{className:"relative shrink-0",children:[e.jsx(I,{"aria-hidden":!0,tabIndex:-1,size:"sm",variant:"outline",className:"pointer-events-none invisible",children:r("Installed")}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:k.installedVersion&&!k.updateAvailable?e.jsx("span",{className:"whitespace-nowrap font-medium text-base text-muted-foreground sm:text-sm",children:r("Installed")}):e.jsx(I,{size:"sm",variant:"outline",className:"size-full",disabled:t,onClick:()=>n(k.id),children:k.updateAvailable?r("Update"):r("Install")})})]})]},k.id))]})}function np({src:t}){const[s,n]=m.useState(!1);return e.jsx("div",{className:"flex size-9 shrink-0 items-center justify-center rounded-md bg-muted",children:t&&!s?e.jsx("img",{src:t,alt:"",className:"size-5 object-contain",onError:()=>n(!0)}):e.jsx(Lt,{className:"size-4 text-muted-foreground"})})}function Gt(t){if(!t)return null;try{const s=new URL(t);return s.protocol==="https:"||s.protocol==="http:"?s.href:null}catch{return null}}function ap({pluginId:t,name:s,from:n,homepage:a,onClose:r}){const{t:o}=z(),[i,u]=m.useState(null),[d,x]=m.useState(null),[h,c]=m.useState(Gt(a)),[f,l]=m.useState(null);return m.useEffect(()=>{if(!t)return;let p=!0;return Jt(()=>import("./globals-D1ocHHQV.js").then(g=>g.n7),__vite__mapDeps([0,1]),import.meta.url).then(g=>{p&&l(()=>g.Markdown)}),()=>{p=!1}},[t]),m.useEffect(()=>{if(!t)return;let p=!1;return u(null),x(null),c(Gt(a)),(async()=>{const g=window.electronAPI.extensionPlugins,w=await g.readme({id:t,from:n});let C=w.ok?w.markdown:null,b=w.ok?null:w.error;if(!w.ok&&n==="installed"){const N=await g.readme({id:t,from:"market"});N.ok&&(C=N.markdown,b=null)}if(!Gt(a)){const N=await g.marketList(!1),y=N.ok?N.plugins.find(S=>S.id===t):void 0;p||c(Gt(y?.homepage))}p||(u(C),x(C?null:b))})(),()=>{p=!0}},[t,n,a]),e.jsx(fe,{open:t!==null,onOpenChange:p=>!p&&r(),children:e.jsxs(ge,{children:[e.jsx(je,{children:e.jsxs(ve,{children:[o("Usage guide"),s?` · ${s}`:""]})}),e.jsxs(we,{className:"max-h-[60vh] space-y-3 overflow-y-auto",children:[h&&e.jsx("a",{href:h,target:"_blank",rel:"noreferrer",className:"text-sm underline",children:o("Homepage")}),d&&e.jsx("p",{className:"text-muted-foreground text-sm",children:d}),i!==null&&f&&e.jsx(f,{text:i})]})]})})}function rp(t){const{notice:s,remote:n,onDismiss:a}=t;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:[s.unreadable&&e.jsx("p",{children:"插件登记表曾读取失败,下面的列表可能不全。插件文件没有删除,原文保存在数据目录的 extension-plugins/registry.json.unreadable。"}),s.discarded.length>0&&e.jsxs("p",{children:["检测到旧格式的登记记录,已丢弃并清理,请重新安装:",e.jsx("span",{className:"font-mono",children:s.discarded.join(", ")})]}),n?e.jsx("p",{className:"text-muted-foreground",children:"请在桌面端点「知道了」,或运行 enso-server plugin notice-dismiss 清除此提示。"}):e.jsx(I,{size:"sm",variant:"outline",onClick:a,children:"知道了"})]})}function op({pluginId:t,plain:s}){const{t:n}=z(),[a,r]=m.useState([]),[o,i]=m.useState({}),[u,d]=m.useState(null),x=m.useCallback(async()=>{const l=await window.electronAPI.extensionPlugins.configGet(t);l.ok?r(l.fields):d({error:!0,text:l.error}),i({})},[t]);m.useEffect(()=>{x()},[x]);const h=async()=>{const l={};for(const[g,w]of Object.entries(o)){const C=a.find(N=>N.key===g);if(!C||C.secret&&w==="")continue;const b=Jx(C,w);if(!b.ok){d({error:!0,text:`${C.title}:${b.error}`});return}l[g]=b.value}const p=await window.electronAPI.extensionPlugins.configSet(t,l);d(p.ok?{error:!1,text:n("Saved. New calls use it right away.")}:{error:!0,text:p.error??""}),p.ok&&await x()},c=l=>{const p=o[l.key];return typeof p=="string"?p:p===null||l.secret?"":l.value??(l.default!==void 0?String(l.default):"")},f=l=>{const p=o[l.key];return typeof p=="boolean"?p:(l.value??(typeof l.default=="boolean"?String(l.default):"false"))==="true"};return e.jsxs("div",{className:H("space-y-2",s?"":"rounded-md border border-border p-3"),children:[a.map(l=>e.jsxs("div",{className:"space-y-1",children:[e.jsxs("p",{className:"text-sm",children:[l.title,e.jsx("span",{className:"ml-2 font-mono text-muted-foreground text-xs",children:l.key})]}),l.description&&e.jsx("p",{className:"text-muted-foreground text-xs",children:l.description}),l.multiline&&l.type==="string"?e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(He,{autoComplete:"off",rows:4,value:c(l),placeholder:l.secret&&l.set?n("Set (leave blank to keep)"):n("Not set"),className:"min-w-0 flex-1",onChange:p=>i(g=>({...g,[l.key]:p.target.value}))}),l.set&&e.jsx(I,{size:"sm",variant:"ghost",onClick:()=>i(p=>({...p,[l.key]:null})),children:n("Clear value")})]}):l.secret||l.type==="string"||l.type==="number"||l.type==="path"?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Y,{type:l.secret?"password":l.type==="number"?"number":"text",autoComplete:"off",inputMode:l.type==="number"?"decimal":void 0,min:l.type==="number"?l.min:void 0,max:l.type==="number"?l.max:void 0,value:c(l),placeholder:l.secret&&l.set?n("Set (leave blank to keep)"):n("Not set"),onChange:p=>i(g=>({...g,[l.key]:p.target.value}))}),l.type==="path"&&!l.secret&&!window.electronAPI.remote&&e.jsx(I,{size:"sm",variant:"outline",onClick:()=>{window.electronAPI.extensionPlugins.pickPath(l.pathKind==="directory"?"directory":"file").then(p=>{p.ok&&"path"in p&&i(g=>({...g,[l.key]:p.path}))})},children:l.pathKind==="directory"?"选择文件夹":"选择文件"}),l.set&&e.jsx(I,{size:"sm",variant:"ghost",onClick:()=>i(p=>({...p,[l.key]:null})),children:n("Clear value")})]}):l.type==="boolean"?e.jsx(le,{checked:f(l),onCheckedChange:p=>i(g=>({...g,[l.key]:p}))}):e.jsxs(se,{items:Object.fromEntries((l.options??[]).map(p=>[p,p])),value:c(l),onValueChange:p=>{typeof p=="string"&&i(g=>({...g,[l.key]:p}))},children:[e.jsx(ne,{children:e.jsx(ae,{placeholder:"请选择"})}),e.jsx(re,{children:(l.options??[]).map(p=>e.jsx(Q,{value:p,children:p},p))})]})]},l.key)),u&&e.jsx("p",{className:H("text-xs",u.error?"text-destructive":"text-muted-foreground"),children:u.text}),e.jsx(I,{size:"sm",disabled:Object.keys(o).length===0,onClick:()=>{h()},children:n("Save")})]})}function ip({pluginId:t,plain:s}){const{t:n}=z(),[a,r]=m.useState(null),o=m.useCallback(async()=>{const i=await window.electronAPI.extensionPlugins.logs(t);r(i.ok?i.text:i.error)},[t]);return m.useEffect(()=>{o()},[o]),e.jsxs("div",{className:H("space-y-2",s?"":"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(I,{size:"icon",variant:"ghost","aria-label":n("Refresh"),onClick:()=>{o()},children:e.jsx(tt,{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 Er({message:t}){const[s,n]=m.useState(!1);return e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("p",{className:H("select-text break-all font-mono text-destructive text-xs",s?"max-h-48 overflow-auto whitespace-pre-wrap":"line-clamp-2"),children:t}),t.length>120&&e.jsx("button",{type:"button",className:"text-muted-foreground text-xs hover:text-foreground",onClick:()=>n(a=>!a),children:s?"收起":"展开全部"})]})}function xi({permissions:t,styles:s=!1}){return t.length===0?s?null:e.jsx("p",{className:"text-muted-foreground text-xs",children:"无特殊权限"}):e.jsx("ul",{className:"space-y-0.5",children:t.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:hi(n)})]},n))})}function lp(t){const s=t.intervalSeconds>=60&&t.intervalSeconds%60===0?`每 ${t.intervalSeconds/60} 分钟`:`每 ${t.intervalSeconds} 秒`,n=t.lastRunAt?` · 最近 ${new Date(t.lastRunAt).toLocaleString()}`:"";return`${t.id} · ${s}${n}${t.lastError?` · ${t.lastError}`:""}`}function Mr(t){return[t.permissions.length>0?`${t.permissions.length} 项权限`:"",(t.events?.length??0)>0?`${t.events?.length} 个事件`:"",(t.schedules?.length??0)>0?`${t.schedules?.length} 个定时任务`:"",t.crossSessionInject!==void 0?"跨会话投递开关":""].filter(Boolean).join(" · ")}function Pr({permissions:t,env:s,interop:n,resident:a,running:r,styles:o,events:i,schedules:u}){return e.jsxs("div",{className:"space-y-1",children:[e.jsx(xi,{permissions:t,styles:o}),a&&e.jsxs("p",{className:"text-xs",children:["常驻进程",r===void 0?"":r?":运行中":":未运行"]}),o&&e.jsx("p",{className:"text-xs",children:"修改界面样式:主题 CSS 可以改变应用的任意界面"}),(s?.length??0)>0&&e.jsxs("p",{className:"text-xs",children:["环境变量:",e.jsx("span",{className:"font-mono",children:s?.join(", ")})]}),(n?.length??0)>0&&e.jsxs("p",{className:"text-xs",children:["可调用插件:",e.jsx("span",{className:"font-mono",children:n?.join(", ")})]}),i?.map(d=>e.jsxs("p",{className:"text-xs",children:["事件 ",d.event," · ",d.mode==="intercept"?"拦截":"观察",d.failClosed?" · 失败即拒绝":""]},`${d.event}:${d.mode}`)),u?.map(d=>e.jsxs("p",{className:"text-xs",children:["定时任务 ",lp(d)]},d.id))]})}function cp({pluginId:t,plain:s}){const[n,a]=m.useState(null),[r,o]=m.useState(null),i=m.useCallback(async()=>{const u=await window.electronAPI.extensionPlugins.artifactsList(t);u.ok?(a(u.artifacts),o(null)):o(u.error)},[t]);return m.useEffect(()=>{i()},[i]),e.jsxs("div",{className:H("space-y-2",s?"":"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(I,{size:"icon",variant:"ghost","aria-label":"刷新",onClick:()=>{i()},children:e.jsx(tt,{className:"size-4"})})]}),r&&e.jsx("p",{className:"text-destructive text-xs",children:r}),e.jsx(Rc,{artifacts:n??[],onDelete:u=>{window.electronAPI.extensionPlugins.artifactDelete(u).then(d=>{d.ok?i():o(d.error??"删除失败")})}})]})}const Ws=new Set;function dp({requestedInstallUrl:t=null,onRequestedInstallUrlConsumed:s,focusPluginId:n=null,onFocusPluginConsumed:a}={}){const{t:r}=z(),o=j(R=>R.pluginAutoUpdate!==!1),i=j(R=>R.setPluginAutoUpdate),[u,d]=m.useState([]),x=En(R=>R.errors),[h,c]=m.useState(null),[f,l]=m.useState(null),[p,g]=m.useState([]),[w,C]=m.useState(!1),[b,N]=m.useState(null),[y,S]=m.useState(""),[D,k]=m.useState(!1),[O,E]=m.useState(!1),[M,A]=m.useState(null),[F,V]=m.useState(null),[v,U]=m.useState(!1),[L,K]=m.useState(null),$=m.useCallback(async()=>{try{d(await window.electronAPI.extensionPlugins.list())}catch{d([])}},[]);m.useEffect(()=>($(),window.electronAPI.extensionPlugins.registryNotice().then(V).catch(()=>V(null)),window.electronAPI.extensionPlugins.onChanged(()=>{$()})),[$]),m.useEffect(()=>{if(!n||(g(P=>P.includes(n)?P:[...P,n]),!u.some(P=>P.id===n)))return;const R=n;window.requestAnimationFrame(()=>{document.querySelector(`[data-plugin-id="${CSS.escape(R)}"]`)?.scrollIntoView({block:"center"})}),a?.()},[n,u,a]);const G=async R=>{N(null),h&&window.electronAPI.extensionPlugins.discard(h.token),c(null);const P=await window.electronAPI.extensionPlugins.pickAndStage(R);P.ok?"cancelled"in P||c(P.preview):N(P.error)},X=async R=>{const P=(R??y).trim();if(!P)return;N(null),k(!0),h&&window.electronAPI.extensionPlugins.discard(h.token),c(null);const ce=await window.electronAPI.extensionPlugins.stageFromUrl(P).finally(()=>{k(!1)});ce.ok?c(ce.preview):N(ce.error)},oe=m.useRef(X);oe.current=X,m.useEffect(()=>{if(!t)return;const R=t;let P=!1;const ce=window.setTimeout(()=>{P||Ws.has(R)||(Ws.add(R),S(R),s?.(),oe.current(R).finally(()=>{Ws.delete(R)}))},0);return()=>{P=!0,window.clearTimeout(ce)}},[t,s]);const q=async(R,P=!1)=>{N(null),h&&window.electronAPI.extensionPlugins.discard(h.token),c(null),k(!0);const ce=window.electronAPI.extensionPlugins,pe=await(P?ce.marketStage(R):ce.restage(R)).finally(()=>{k(!1)});pe.ok?c(pe.preview):N(pe.error)},ie=async()=>{E(!0),A(null);try{const R=await window.electronAPI.extensionPlugins.checkUpdates();A(R.checked===0?r("No plugins installed from GitHub to check"):R.available>0?r("{{count}} update(s) available",{count:R.available}):r("All plugins are up to date"))}finally{E(!1)}},B=async()=>{if(!h)return;C(!0);const R=await window.electronAPI.extensionPlugins.commit(h.token);if(C(!1),!R.ok)N(R.error??r("Install failed"));else{S("");const P=h.existingVersion?{ok:!0}:await window.electronAPI.extensionPlugins.setEnabled(h.id,!0);_e({type:P.ok?"success":"warning",title:r("{{name}} installed",{name:h.name}),description:P.ok?void 0:P.error})}c(null)},ee=()=>{h&&window.electronAPI.extensionPlugins.discard(h.token),c(null)};return e.jsxs("div",{className:"space-y-5","data-settings-row":"plugins.enso",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"font-medium text-lg",children:[r("Enso plugins"),e.jsx(qe,{})]}),e.jsx("p",{className:"mt-1 text-muted-foreground text-sm",children:r("Installing a plugin lets it run code on this machine. Review what it asks for before confirming.")})]}),e.jsxs("div",{className:"flex shrink-0 gap-2",children:[u.length>0&&e.jsxs(I,{size:"sm",variant:"outline",disabled:O,onClick:()=>{ie()},children:[O?e.jsx(Nt,{}):e.jsx(tt,{className:"size-4"}),r("Check for updates")]}),e.jsxs(I,{size:"sm",onClick:()=>U(!0),children:[e.jsx(ju,{className:"size-4"}),r("Marketplace")]})]})]}),e.jsxs("label",{className:"flex items-center justify-between gap-3 text-sm",children:[e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block",children:r("Update plugins automatically")}),e.jsx("span",{className:"block text-muted-foreground text-xs",children:r("Marketplace updates that do not ask for new permissions install on their own.")})]}),e.jsx(le,{className:"shrink-0",checked:o,onCheckedChange:R=>i(R)})]}),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(Io,{className:"flex-1",children:[e.jsx(Eo,{children:e.jsx(qo,{className:"size-4 text-muted-foreground"})}),e.jsx(Ao,{value:y,placeholder:r("https://github.com/owner/repo"),onChange:R=>S(R.target.value),onKeyDown:R=>{R.key==="Enter"&&X()}})]}),e.jsx(I,{size:"sm",variant:"outline",disabled:w||D||y.trim()==="",onClick:()=>{X()},children:D?e.jsx(Nt,{}):r("Install from URL")})]}),e.jsxs("div",{className:"flex items-center gap-1 text-muted-foreground text-xs",children:[e.jsx("span",{className:"mr-1",children:r("Or install from")}),e.jsxs(I,{size:"xs",variant:"ghost",disabled:w||D,onClick:()=>{G("dir")},children:[e.jsx(Tn,{className:"size-3.5"}),r("Install from folder")]}),e.jsxs(I,{size:"xs",variant:"ghost",disabled:w||D,onClick:()=>{G("zip")},children:[e.jsx(Ac,{className:"size-3.5"}),r("Install from zip")]})]})]}),b&&e.jsx("p",{className:"text-destructive text-sm",children:b}),e.jsx(fe,{open:v,onOpenChange:U,children:e.jsxs(ge,{className:"max-w-2xl",children:[e.jsx(je,{children:e.jsx(ve,{children:r("Marketplace")})}),e.jsx(we,{children:e.jsx(sp,{disabled:w||D,installedKey:u.map(R=>`${R.id}@${R.version}`).join(","),onInstall:R=>{U(!1),q(R,!0)},onGuide:(R,P,ce)=>{U(!1),K({id:R,name:P,from:"market",homepage:ce})}})})]})}),M&&e.jsx("p",{className:"text-muted-foreground text-sm",children:M}),F&&e.jsx(rp,{notice:F,remote:!!window.electronAPI.remote,onDismiss:()=>{window.electronAPI.extensionPlugins.dismissRegistryNotice().then(()=>V(null)).catch(R=>N(R instanceof Error?R.message:String(R)))}}),e.jsx(fe,{open:h!==null,onOpenChange:R=>!R&&!w&&ee(),children:e.jsx(ge,{children:h&&e.jsxs(e.Fragment,{children:[e.jsx(je,{children:e.jsxs(ve,{children:[h.name," ",h.version,h.existingVersion&&e.jsx("span",{className:"ml-2 text-base text-muted-foreground",children:r("updating from {{version}}",{version:h.existingVersion})})]})}),e.jsxs(we,{className:"space-y-3",children:[e.jsx(Pr,{permissions:h.permissions,env:h.env,interop:h.interop,resident:h.resident,styles:h.styles,events:h.events,schedules:h.schedules}),h.mcpServers.map(R=>e.jsxs("p",{className:"font-mono text-xs",children:[R.command," ",R.args.join(" ")]},R.name)),h.mcpTools.length>0&&e.jsxs("p",{className:"text-muted-foreground text-xs",children:[r("Host MCP tools it may call"),":",e.jsx("span",{className:"font-mono",children:h.mcpTools.join(", ")})]}),h.warnings.map(R=>e.jsx("p",{className:"text-muted-foreground text-xs",children:R},R))]}),e.jsxs(Ie,{children:[e.jsx(I,{size:"sm",variant:"ghost",disabled:w,onClick:ee,children:r("Cancel")}),e.jsx(I,{size:"sm",disabled:w,onClick:()=>{B()},children:w?e.jsx(Nt,{}):r("Install")})]})]})})}),u.length===0&&!h&&e.jsxs("div",{className:"rounded-lg border border-dashed px-3 py-10 text-center",children:[e.jsx(Lt,{className:"mx-auto size-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:r("No Enso plugins installed")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:r("Browse the marketplace or install from a GitHub URL, folder or zip.")})]}),e.jsx("div",{className:"space-y-2",children:u.map(R=>e.jsxs("div",{"data-plugin-id":R.id,className:H("overflow-hidden rounded-lg border bg-card transition-colors",R.state==="crashed"&&"border-destructive/50"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 p-3",children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-3",children:[e.jsx("div",{className:H("flex size-9 shrink-0 items-center justify-center rounded-md bg-muted",R.state==="enabled"?"text-foreground":"text-muted-foreground"),children:e.jsx(Ec,{pluginId:R.id,icon:R.icon,className:"size-4"})}),e.jsxs("div",{className:"min-w-0 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:R.name}),e.jsx(te,{variant:"outline",className:"text-[11px]",children:R.version}),R.state==="crashed"&&e.jsx(te,{variant:"destructive",className:"text-[11px]",children:r("Stopped after crashes")}),R.availableVersion&&e.jsx(te,{className:"text-[11px]",children:r("Update")}),R.pendingVersion&&e.jsx(te,{variant:"warning",className:"text-[11px]",children:"待授权"}),R.resident&&e.jsx(te,{variant:R.running?"secondary":"outline",className:"text-[11px]",children:R.running?"常驻运行中":"常驻未运行"})]}),e.jsx("p",{className:"truncate font-mono text-muted-foreground text-xs",children:R.id}),R.availableVersion&&e.jsxs("p",{className:"mt-1 flex items-center gap-2 text-primary text-xs",children:[r("Version {{version}} is available",{version:R.availableVersion}),e.jsx(I,{size:"xs",disabled:w||D,onClick:()=>{q(R.id,R.source?.kind!=="url")},children:D?e.jsx(Nt,{}):r("Update")})]}),R.updateCheckError&&e.jsx("p",{className:"text-muted-foreground text-xs",children:r("Update check failed: {{reason}}",{reason:R.updateCheckError})}),R.lastError&&e.jsx(Er,{message:R.lastError.message}),x[R.id]?.map(P=>e.jsx(Er,{message:`主题加载失败:${P}`},P)),R.pendingVersion&&e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2 rounded-md border border-amber-500/50 bg-amber-500/10 px-2 py-1.5 text-amber-700 text-xs dark:text-amber-400",children:[r("{{version}} asks for more and is waiting for approval",{version:R.pendingVersion}),e.jsx(I,{size:"xs",onClick:()=>{window.electronAPI.extensionPlugins.approvePending(R.id)},children:r("Allow")}),e.jsx(I,{size:"xs",variant:"ghost",onClick:()=>{window.electronAPI.extensionPlugins.rejectPending(R.id)},children:r("Keep current")})]})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-0.5",children:[R.source&&e.jsx(I,{size:"icon",variant:"ghost",disabled:w||D,"aria-label":r("Reinstall from source"),title:R.source.kind==="url"?`${r("Reinstall from source")}: ${R.source.url}`:r("Reinstall from source"),onClick:()=>{q(R.id)},children:e.jsx(Mc,{className:"size-4"})}),e.jsx(I,{size:"icon",variant:"ghost","aria-label":"产出文件",title:"产出文件",onClick:()=>l({kind:"artifacts",pluginId:R.id,pluginName:R.name}),children:e.jsx(Pc,{className:"size-4"})}),e.jsx(I,{size:"icon",variant:"ghost","aria-label":r("Usage guide"),title:r("Usage guide"),onClick:()=>K({id:R.id,name:R.name,from:"installed"}),children:e.jsx(Yd,{className:"size-4"})}),e.jsx(I,{size:"icon",variant:"ghost","aria-label":r("Plugin logs"),title:r("Plugin logs"),onClick:()=>l({kind:"logs",pluginId:R.id,pluginName:R.name}),children:e.jsx(Dn,{className:"size-4"})}),R.configurable&&e.jsx(I,{size:"icon",variant:"ghost","aria-label":r("Configure"),title:r("Configure"),onClick:()=>l({kind:"config",pluginId:R.id,pluginName:R.name}),children:e.jsx(Tc,{className:"size-4"})}),e.jsx(I,{size:"icon",variant:"ghost","aria-label":r("Uninstall"),title:r("Uninstall"),className:"text-muted-foreground hover:text-destructive",onClick:()=>{window.electronAPI.extensionPlugins.uninstall(R.id)},children:e.jsx(Ee,{className:"size-4"})}),e.jsx("div",{className:"mx-1.5 h-5 w-px bg-border"}),e.jsx(le,{checked:R.state==="enabled",onCheckedChange:P=>{window.electronAPI.extensionPlugins.setEnabled(R.id,P)}})]})]}),e.jsxs("button",{type:"button","aria-expanded":p.includes(R.id),className:H("flex w-full items-center gap-1 border-t bg-muted/20 px-3 py-1.5 text-left text-xs","text-muted-foreground transition-colors hover:bg-muted/50 hover:text-foreground"),onClick:()=>g(P=>P.includes(R.id)?P.filter(ce=>ce!==R.id):[...P,R.id]),children:[p.includes(R.id)?e.jsx(Zt,{className:"size-3"}):e.jsx(At,{className:"size-3"}),p.includes(R.id)?"收起详情":"详情",!p.includes(R.id)&&Mr(R)&&e.jsx("span",{className:"ml-1 opacity-70",children:Mr(R)})]}),p.includes(R.id)&&e.jsxs("div",{className:"space-y-3 border-t px-3 py-3",children:[R.interceptBreakers?.map(P=>e.jsxs("p",{className:"text-amber-600 text-xs dark:text-amber-400",children:[P.event," 检查连续失败,临时放行到"," ",new Date(P.until).toLocaleTimeString()]},P.event)),e.jsx(Pr,{permissions:R.permissions,resident:R.resident,running:R.running,styles:R.themes.some(P=>P.css!==void 0),events:R.events,schedules:R.schedules}),R.crossSessionInject!==void 0&&e.jsxs("div",{className:"flex items-center justify-between gap-3 text-xs",children:[e.jsxs("span",{children:[e.jsx("span",{className:"block",children:"允许向任意运行中的会话发送消息"}),e.jsx("span",{className:"block text-muted-foreground",children:"关闭时只能发到发起调用的会话;开启后定时任务、常驻进程也能向其他项目和窗口的会话发消息并触发执行"})]}),e.jsx(le,{"aria-label":"允许向任意运行中的会话发送消息",checked:R.crossSessionInject,onCheckedChange:P=>{window.electronAPI.extensionPlugins.setCrossSessionInject(R.id,P)}})]}),R.pendingPermissions&&R.pendingPermissions.length>0&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:"待同意的权限"}),e.jsx(xi,{permissions:R.pendingPermissions})]})]})]},R.id))}),e.jsx(fe,{open:f!==null,onOpenChange:R=>!R&&l(null),children:e.jsxs(ge,{children:[e.jsx(je,{children:e.jsxs(ve,{children:[f?.kind==="config"?r("Configure"):f?.kind==="logs"?r("Plugin logs"):"产出文件",f?` · ${f.pluginName}`:""]})}),e.jsxs(we,{className:"space-y-4",children:[f?.kind==="config"&&e.jsx(op,{pluginId:f.pluginId,plain:!0}),f?.kind==="logs"&&e.jsx(ip,{pluginId:f.pluginId,plain:!0}),f?.kind==="artifacts"&&e.jsx(cp,{pluginId:f.pluginId,plain:!0})]})]})}),e.jsx(ap,{pluginId:L?.id??null,name:L?.name??"",from:L?.from??"installed",homepage:L?.homepage,onClose:()=>K(null)})]})}function up(t,s){return[[t.skills.length,s("Skills")],[t.commands.length,s("Commands")],[t.agents.length,s("Agent types")],[t.mcpServers.length,"MCP"],[t.hooks.length,"Hooks"]].filter(([n])=>n>0).map(([n,a])=>`${a} ${n}`).join(" · ")}function bt({label:t,items:s}){return s.length===0?null:e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("p",{className:"font-medium text-muted-foreground text-xs",children:t}),s.map(n=>e.jsx("p",{className:"break-all font-mono text-[11px]",children:n},n))]})}function mp({plugin:t,entry:s,onToggle:n}){const{t:a}=z(),[r,o]=m.useState(!1),{components:i}=t,u=up(i,a);return e.jsxs("div",{className:"rounded-md border","data-settings-row":`plugins.${t.key}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 px-3 py-2",children:[e.jsxs("button",{type:"button",className:"flex min-w-0 flex-1 items-center gap-2 text-left",onClick:()=>o(d=>!d),children:[e.jsx(At,{className:H("h-4 w-4 shrink-0 text-muted-foreground transition-transform",r&&"rotate-90")}),e.jsx("span",{className:"shrink-0 font-medium text-sm",children:t.name}),t.version&&e.jsx(te,{variant:"outline",className:"shrink-0 text-[11px]",children:t.version}),t.marketplace&&e.jsx(te,{variant:"secondary",className:"shrink-0 text-[11px]",children:t.marketplace}),e.jsx("span",{className:"min-w-0 truncate text-muted-foreground text-xs",children:u||(i.unsupported.length>0?`${a("Not supported")}: ${i.unsupported.join(", ")}`:a("No supported components"))})]}),e.jsx(le,{checked:s?.enabled===!0,onCheckedChange:n})]}),r&&e.jsxs("div",{className:"space-y-2 border-t px-3 py-2",children:[t.description&&e.jsx("p",{className:"text-muted-foreground text-xs",children:t.description}),e.jsx(bt,{label:a("Skills"),items:i.skills}),e.jsx(bt,{label:a("Commands"),items:i.commands.map(d=>`/${d}`)}),e.jsx(bt,{label:a("Agent types"),items:i.agents}),e.jsx(bt,{label:a("MCP servers (run when a session starts)"),items:i.mcpServers.map(d=>`${d.name}: ${d.target}`)}),e.jsx(bt,{label:a("Hooks (run automatically on local sessions)"),items:i.hooks.map(d=>`${d.event}: ${d.command}`)}),e.jsx(bt,{label:a("Not supported"),items:i.unsupported})]})]})}function hp(){const{t}=z(),s=j(l=>l.plugins),n=j(l=>l.addPlugins),a=j(l=>l.setPluginEnabled),r=j(l=>l.removePlugin),[o,i]=m.useState(null),u=m.useCallback(async()=>{i(null);try{i(await window.electronAPI.assets.listInstalledPlugins())}catch{i([])}},[]);m.useEffect(()=>{u()},[u]);const d=new Map(s.map(l=>[l.key,l])),x=new Set((o??[]).map(l=>l.key)),h=o?s.filter(l=>!x.has(l.key)):[],c=s.filter(l=>l.enabled).length,f=(l,p)=>{const g=d.get(l.key);if(g){a(g.id,p);return}n([{id:crypto.randomUUID(),key:l.key,name:l.name,description:l.description,...l.version?{version:l.version}:{},source:l.marketplace||"Claude Code",enabled:p}])};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-end justify-between gap-4","data-settings-row":"plugins.root",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"font-medium text-lg",children:[t("Claude Code plugins"),e.jsx(qe,{}),c>0&&e.jsx("span",{className:"ml-2 font-normal text-muted-foreground text-xs",children:t("{{count}} enabled",{count:c})})]}),e.jsx("p",{className:"text-muted-foreground text-sm",children:t("Plugins installed in Claude Code. Each one is switched on or off as a whole here; changes apply to new sessions.")})]}),e.jsxs(I,{variant:"outline",size:"sm",onClick:u,disabled:o===null,children:[e.jsx(tt,{className:"mr-1.5 h-4 w-4"}),t("Rescan")]})]}),o===null?e.jsx("div",{className:"flex justify-center py-10",children:e.jsx(Nt,{className:"size-5"})}):o.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx(Lt,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:t("No Claude Code plugins found")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:t("Install plugins with /plugin in Claude Code, then rescan.")})]}):e.jsx("div",{className:"space-y-2",children:o.map(l=>e.jsx(mp,{plugin:l,entry:d.get(l.key),onToggle:p=>f(l,p)},l.key))}),h.length>0&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"font-medium text-muted-foreground text-xs",children:t("No longer installed in Claude Code")}),h.map(l=>e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md px-3 py-2 hover:bg-accent/50",children:[e.jsx("span",{className:"text-muted-foreground text-sm line-through",children:l.name}),e.jsx(I,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-destructive",onClick:()=>r(l.id),children:e.jsx(Ee,{className:"h-3.5 w-3.5"})})]},l.id))]})]})}const Ot={mask:"Mask",warn:"Warn only",block:"Block"},xp={email:"Email",phone:"Phone number",idCard:"ID card number",bankCard:"Bank card number",ip:"IP address"},pn={mask:"text-sky-600 dark:text-sky-400",warn:"text-amber-600 dark:text-amber-400",block:"text-red-600 dark:text-red-400"},pp=[1,7,30],fp={1:"Today",7:"7D",30:"30D"};function gp(t){const s=new Map;for(const n of t.report.hits){const a=s.get(n.token);a?a.count+=n.count:s.set(n.token,{label:`${n.kind} ${n.preview}`,count:n.count})}return[...s.values()].map(n=>n.count>1?`${n.label} ×${n.count}`:n.label).join(", ")}function Ys({value:t,onChange:s}){const{t:n}=z(),a=Object.fromEntries(Object.keys(Ot).map(r=>[r,n(Ot[r])]));return e.jsxs(se,{items:a,value:t,onValueChange:r=>s(r),children:[e.jsx(ne,{className:"w-32",children:e.jsx(ae,{})}),e.jsx(re,{children:Object.entries(a).map(([r,o])=>e.jsx(Q,{value:r,children:o},r))})]})}function Js({label:t,hint:s,value:n,onCommit:a,rowId:r}){const[o,i]=m.useState(n.join(`
|
|
25
|
+
`));return m.useEffect(()=>i(n.join(`
|
|
26
|
+
`)),[n]),e.jsxs("div",{className:"space-y-1.5","data-settings-row":r,children:[e.jsx("p",{className:"text-sm",children:t}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s}),e.jsx(He,{rows:3,value:o,onChange:u=>i(u.target.value),onBlur:()=>a(o.split(`
|
|
27
|
+
`))})]})}function kt({title:t,children:s}){return e.jsxs("div",{className:"space-y-3 rounded-md border p-3",children:[e.jsx("p",{className:"text-sm font-medium",children:t}),s]})}function jp({settings:t}){const{t:s}=z(),[n,a]=m.useState(""),r=m.useMemo(()=>Dc(n,t),[n,t]);return e.jsxs(kt,{title:s("Try it"),children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Runs locally. Nothing is remembered or sent anywhere.")}),e.jsx(He,{rows:3,value:n,placeholder:s("Paste some text, e.g. an .env file"),onChange:o=>a(o.target.value)}),n&&e.jsxs(e.Fragment,{children:[e.jsx("pre",{className:"max-h-48 overflow-auto whitespace-pre-wrap rounded bg-muted p-2 text-xs",children:r.text}),e.jsxs("ul",{className:"space-y-0.5 text-xs",children:[r.report.hits.map(o=>e.jsxs("li",{className:"flex gap-2",children:[e.jsx("span",{className:H("font-medium",pn[o.action]),children:s(Ot[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:s("Nothing matched")})]})]})]})}function vp(){const{t}=z(),[s,n]=m.useState(7),[a,r]=m.useState(null),[o,i]=m.useState(!1),u=m.useRef(0),d=Lc(f=>f.conversations),x=m.useCallback(async f=>{const l=++u.current;i(!0);const p=await window.electronAPI.privacyMask.records(f).catch(()=>[]);l===u.current&&(i(!1),r(p))},[]);m.useEffect(()=>{x(s)},[s,x]);const h=m.useMemo(()=>{const f={mask:0,warn:0,block:0},l=new Map;for(const p of a??[]){const g=new Set;for(const w of p.report.hits){const C=`${w.action}:${w.token}`;g.has(C)||(g.add(C),f[w.action]+=1,l.set(w.kind,(l.get(w.kind)??0)+1))}}return{byAction:f,byKind:[...l].sort((p,g)=>g[1]-p[1])}},[a]),c=f=>{if(f.source==="aux")return t("Auxiliary request");const l=f.sessionId?d[f.sessionId]?.title:void 0,p=f.source==="compaction"?t("Compaction"):t("Session");return l?`${p} · ${l}`:p};return e.jsxs(kt,{title:t("Records"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"flex gap-1",children:pp.map(f=>e.jsx(I,{size:"sm",variant:f===s?"secondary":"ghost",onClick:()=>n(f),children:t(fp[f])},f))}),e.jsx(I,{variant:"ghost",size:"icon-sm",onClick:()=>{x(s)},disabled:o,"aria-label":t("Refresh"),children:e.jsx(tt,{className:H("size-4",o&&"animate-spin")})})]}),e.jsx("div",{className:"flex flex-wrap gap-4 text-sm",children:Object.keys(Ot).map(f=>e.jsxs("span",{children:[e.jsx("span",{className:pn[f],children:t(Ot[f])})," ",e.jsx("span",{className:"font-medium tabular-nums",children:h.byAction[f]})]},f))}),h.byKind.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 text-xs text-muted-foreground",children:h.byKind.map(([f,l])=>e.jsxs("span",{className:"rounded bg-muted px-1.5 py-0.5",children:[f," ",l]},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:t("Requested at")}),e.jsx("th",{className:"py-1 pr-2 font-normal",children:t("Source")}),e.jsx("th",{className:"py-1 pr-2 font-normal",children:t("Model")}),e.jsx("th",{className:"py-1 font-normal",children:t("Hits")})]})}),e.jsx("tbody",{children:(a??[]).slice(0,200).map(f=>{const l=zc(f.report),p=`${f.at}:${f.sessionId??f.source}:${f.model}:${f.report.hits.map(g=>g.token).join(",")}`;return e.jsxs("tr",{className:"border-t align-top",children:[e.jsx("td",{className:"py-1 pr-2 whitespace-nowrap tabular-nums",children:new Date(f.at).toLocaleString()}),e.jsx("td",{className:"py-1 pr-2",children:c(f)}),e.jsx("td",{className:"py-1 pr-2 break-all",children:f.model}),e.jsxs("td",{className:H("py-1",l&&pn[l]),children:[gp(f),f.report.blocked&&` · ${t("Request blocked")}`]})]},p)})})]}),a?.length===0&&e.jsx("p",{className:"py-4 text-center text-xs text-muted-foreground",children:t("No records yet")})]})]})}function bp(){const{t}=z(),s=j(r=>r.privacyMasking),n=j(r=>r.setPrivacyMasking),a=r=>n({...s,...r});return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:t("Privacy")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("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(Me,{rowId:"privacy.enabled",title:t("Privacy masking"),description:t("Applies to chats, compaction, bot members and helper requests."),checked:s.enabled,onChange:r=>a({enabled:r})}),s.enabled&&e.jsxs(e.Fragment,{children:[e.jsxs(kt,{title:t("Secrets"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:t("API keys, tokens, private keys, passwords in URLs and config files.")}),e.jsx(Ys,{value:s.secrets.action,onChange:r=>a({secrets:{...s.secrets,action:r}})})]}),e.jsx(Me,{rowId:"privacy.secrets",title:t("Detect secrets"),description:t("Recommended. Covers common vendor key formats."),checked:s.secrets.enabled,onChange:r=>a({secrets:{...s.secrets,enabled:r}})}),e.jsx(Me,{rowId:"privacy.shape",title:t("Send look-alike keys"),description:t("Replace keys with fake keys of the same format instead of placeholders, so the model treats them as real keys."),checked:s.secrets.shape,onChange:r=>a({secrets:{...s.secrets,shape:r}})})]}),e.jsxs(kt,{title:t("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:t("Emails, phone numbers, ID and bank card numbers, IP addresses.")}),e.jsx(Ys,{value:s.personal.action,onChange:r=>a({personal:{...s.personal,action:r}})})]}),e.jsx(Me,{rowId:"privacy.personal",title:t("Detect personal data"),description:t("Matches are validated (checksums, real domains) to limit false hits."),checked:s.personal.enabled,onChange:r=>a({personal:{...s.personal,enabled:r}})}),s.personal.enabled&&e.jsx("div",{className:"flex flex-wrap gap-4",children:Oc.map(r=>e.jsxs("label",{className:"flex items-center gap-1.5 text-sm",children:[e.jsx(Je,{checked:s.personal.kinds.includes(r),onCheckedChange:o=>a({personal:{...s.personal,kinds:o?[...s.personal.kinds,r]:s.personal.kinds.filter(i=>i!==r)}})}),t(xp[r])]},r))})]}),e.jsxs(kt,{title:t("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:t("Words and patterns specific to your work.")}),e.jsx(Ys,{value:s.custom.action,onChange:r=>a({custom:{...s.custom,action:r}})})]}),e.jsx(Js,{rowId:"privacy.words",label:t("Words"),hint:t("One per line, case-insensitive. Project codenames, customer names…"),value:s.custom.words,onCommit:r=>a({custom:{...s.custom,words:r}})}),e.jsx(Js,{rowId:"privacy.rules",label:t("Prefixes or patterns"),hint:t("One per line. A prefix like corp_ or a regex like /INC-\\d{4}/i."),value:s.custom.rules,onCommit:r=>a({custom:{...s.custom,rules:r}})})]}),e.jsx(kt,{title:t("Allow list"),children:e.jsx(Js,{rowId:"privacy.allow",label:t("Never mask"),hint:t("Exact values, one per line. Team emails, test keys…"),value:s.allow,onCommit:r=>a({allow:r})})}),e.jsx(jp,{settings:s})]}),e.jsx(vp,{})]})}function yp(){const{t}=z(),s=j(l=>l.approvalReviewer),n=j(l=>l.setApprovalReviewer),a=j(l=>l.approvalAutoManage),r=j(l=>l.setApprovalAutoManage),o=Bc(j(l=>l.approvalAllowThreshold)),i=j(l=>l.setApprovalAllowThreshold),u={"0.85":t("0.85 (looser)"),"0.9":t("0.9 (default)"),"0.95":t("0.95 (stricter)")},d=Qe(),x=Rn(),h=m.useMemo(()=>[...d,...x.filter(ln)],[d,x]),c=s?h.find(l=>l.id===s.providerId):void 0,f=c?.models.find(l=>l.id===s?.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:t("Assistant approval model")}),e.jsx("p",{className:"mt-0.5 text-muted-foreground text-xs",children:t("Required before Assistant approval can be selected. Does not fall back to the chat model.")})]}),h.length>0&&e.jsx("div",{className:"w-full min-w-0",children:e.jsx(Oe,{providers:h,providerId:c?.id??"",modelId:f?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:t("No assistant approval model selected"),side:"bottom",triggerClassName:Ye,onSelect:(l,p)=>n({providerId:l,modelId:p}),onReasoningChange:()=>{},onThinkingChange:()=>{}})}),c&&ln(c)&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:t(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:t("Auto-manage approvals")}),e.jsx(le,{"aria-label":t("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:t("Auto-allow threshold")}),e.jsxs(se,{items:u,value:String(o),onValueChange:l=>i(Number(l)),children:[e.jsx(ne,{className:"w-36","aria-label":t("Auto-allow threshold"),children:e.jsx(ae,{})}),e.jsx(re,{children:_c.map(l=>e.jsx(Q,{value:String(l),children:u[String(l)]},l))})]})]}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Only runs automatically when the allow probability reaches this value. Operations near the threshold may be allowed one time and not the next.")})]}),s&&(!c||!f)&&e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Selected model is unavailable")}),s&&e.jsx(I,{variant:"ghost",size:"sm",className:"self-start",onClick:()=>n(null),children:t("Clear")})]})}function Tr(t,s){const n=s.find(r=>r.id===t.providerId),a=n?.models.find(r=>r.id===t.modelId);return`${n?.name??t.providerId} / ${a?.label??t.modelId}`}function wp(){const{t}=z(),s=_t(),n=j(S=>S.virtualModels),a=j(S=>S.defaultModel),r=j(S=>S.setDefaultModel),o=j(S=>S.defaultModelFollowLast),i=j(S=>S.setDefaultModelFollowLast),u=j(S=>S.defaultReasoningEnabled),d=j(S=>S.defaultThinkingLevel),x=j(S=>S.setDefaultReasoningEnabled),h=j(S=>S.setDefaultThinkingLevel),c=es(S=>S.snapshot),f=Fc(S=>S.latest),l=Qe(),p=a?l.find(S=>S.id===a.providerId):void 0,g=p?.models.find(S=>S.id===a?.modelId),w=s.some(S=>!!S.oauthAccountKey),C=w&&(c.availability.status==="unloaded"||c.availability.status==="loading"),b=w&&c.availability.status==="error"?c.availability.error:null,N=f?.notice,y=N?t("Default model changed: {{previous}} → {{next}}",{previous:Tr(N.previous,s),next:N.next?Tr(N.next,s):t("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:t("Default model")}),e.jsx("p",{className:"mt-0.5 text-muted-foreground text-xs",children:t(o?"New conversations use the last model you picked.":"Used for new conversations.")})]}),l.length>0&&e.jsx("div",{className:"w-full min-w-0",children:e.jsx(Oe,{providers:l,virtualModels:n,providerId:p?.id??a?.providerId??"",modelId:g?.id??a?.modelId??"",reasoningEnabled:u,thinkingLevel:d,emptyLabel:t("Select model"),triggerLabel:o?t("Follow last selection"):void 0,side:"bottom",triggerClassName:Ye,onSelect:(S,D)=>r({providerId:S,modelId:D}),onReasoningChange:x,onThinkingChange:h,showReasoningControls:!o})}),!o&&l.length>0&&e.jsx(I,{type:"button",variant:"ghost",size:"sm",className:"self-start",onClick:()=>i(!0),children:t("Follow last selection")}),l.length===0&&e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-5 text-center",children:[e.jsx(zn,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-2 font-medium text-sm",children:t("No usable models")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:t("Enable a model and configure valid provider credentials first.")})]}),(C||b)&&e.jsxs("div",{className:"flex items-start gap-2 rounded-md bg-muted px-2.5 py-2 text-xs",children:[e.jsx(St,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:b?t("Subscription credentials could not be loaded: {{error}}",{error:b}):t("Subscription credentials are loading. API-key models remain available.")})]}),y&&e.jsx("p",{className:"rounded-md bg-muted px-2.5 py-2 text-muted-foreground text-xs",children:y})]})}function Np(){const{t}=z(),s=Iu(_t()),n=j(o=>o.imageGenerationModel),a=n===null||s.some(o=>o.id===n.providerId&&o.models.some(i=>i.id===n.modelId)),r=j(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:t("Default image generation model")}),s.length>0?e.jsx(Oe,{providers:s,providerId:n?.providerId??"",modelId:n?.modelId??"",reasoningEnabled:!1,thinkingLevel:"medium",emptyLabel:t("Select model"),side:"bottom",triggerClassName:Ye,onSelect:(o,i)=>r({providerId:o,modelId:i}),onReasoningChange:()=>{},onThinkingChange:()=>{},showReasoningControls:!1}):e.jsx("p",{className:"text-muted-foreground text-xs",children:t("No image generation models available")}),!a&&e.jsx("p",{className:"text-destructive text-xs",children:t("Selected image generation model is unavailable")}),n&&e.jsx(I,{type:"button",variant:"ghost",size:"sm",onClick:()=>r(null),children:t("Clear selection")})]})}function kp({provider:t,onClose:s}){const{t:n}=z(),a=j(g=>g.providers),r=j(g=>g.updateProvider),o=Mo(g=>g.snapshot),i=m.useMemo(()=>Po([t],o)[0]?.models??t.models,[t,o]),u=es(g=>g.snapshot.availability),d=es(g=>g.snapshot.revision),[x,h]=m.useState([]),[c,f]=m.useState(t.oauthAccountPool?.accountKeys??[]);m.useEffect(()=>{let g=!1;return window.electronAPI.providers.listOauth().then(w=>{g||h(w)}).catch(w=>{g||(h([]),console.error("Failed to load OAuth account metadata",w))}),()=>{g=!0}},[d]);const l=Lo(a),p=[...l.flatMap(g=>g.oauthAccountKey??[]),...c.filter(g=>!l.some(w=>w.oauthAccountKey===g))];return e.jsx(To,{initialValue:{...t,name:Bn(t,n),models:i},oauth:!0,hideName:!0,saveDisabled:c.length===0,oauthAccountKey:t.oauthAccountKey,onCancel:s,extraFields:e.jsxs(ue,{children:[e.jsx(me,{children:n("Pool members")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n("Use enabled, signed-in accounts in the listed order. Model and reasoning stay unchanged. Main agents and subagents share this pool.")}),e.jsx("div",{className:"mt-2 w-full space-y-1 rounded-md border p-1",children:p.map((g,w)=>{const C=l.find(N=>N.oauthAccountKey===g),b=x.flatMap(N=>N.accounts).find(N=>N.key===g);return e.jsxs("label",{className:"flex min-w-0 items-center gap-2 px-2 py-1.5 text-sm",children:[e.jsx(Je,{checked:c.includes(g),onCheckedChange:N=>f(y=>N?[...y,g]:y.filter(S=>S!==g))}),e.jsxs("span",{className:"shrink-0 text-xs text-muted-foreground",children:[w+1,"."]}),e.jsx("span",{className:"min-w-0 truncate",children:b?.email??g}),!C?.enabled&&e.jsx("span",{className:"shrink-0 text-xs text-muted-foreground",children:n("Account disabled")}),u.status==="ready"&&!u.authenticatedAccountKeys.has(g)&&e.jsx("span",{className:"shrink-0 text-xs text-muted-foreground",children:n("Account signed out")})]},g)})})]}),onSave:g=>{c.length!==0&&(r(t.id,{models:Ro(g.models,Do(o,t.oauthAccountKey??"")?.models,Oo(j.getState(),t.id)),oauthAccountPool:{accountKeys:p.filter(w=>c.includes(w))}}),s())}})}function Cp({provider:t,onClose:s}){const{t:n}=z(),a=j(i=>i.updateProvider),r=Mo(i=>i.snapshot),o=m.useMemo(()=>t?.oauthAccountKey?Po([t],r)[0]?.models??t.models:t?.models,[t,r]);return e.jsx(fe,{open:t!==null,onOpenChange:i=>!i&&s(),children:e.jsxs(ge,{children:[e.jsx(je,{children:e.jsx(ve,{children:t?.oauthAccountPool?Bn(t,n):n("Edit Provider")})}),t?.oauthAccountPool?e.jsx(kp,{provider:t,onClose:s},t.id):t&&e.jsx(To,{initialValue:{name:t.name,api:t.api,apiKey:t.apiKey,baseUrl:t.baseUrl,models:o??t.models},oauth:!!t.oauthAccountKey,oauthAccountKey:t.oauthAccountKey,onCancel:s,onSave:i=>{a(t.id,t.oauthAccountKey?{name:i.name,models:Ro(i.models,Do(r,t.oauthAccountKey)?.models,Oo(j.getState(),t.id))}:i),s()}},t.id)]})})}async function Sp(t){try{if(t.oauthAccountKey){const n=await window.electronAPI.providers.modelMeta({oauthAccountKey:t.oauthAccountKey,modelIds:[]});return n.ok?{status:"ok",count:n.models.filter(a=>a.source!=="unknown").length}:{status:"failed",message:n.error??"Failed"}}const s=await window.electronAPI.providers.listModels({api:t.api,apiKey:t.apiKey,baseUrl:t.baseUrl});return s.ok?{status:"ok",count:s.models.length,models:Uc(t.models,s.models)}:{status:"failed",message:s.error??"Failed"}}catch(s){return{status:"failed",message:s instanceof Error?s.message:String(s)}}}const Ip=(t,s)=>t.models.some(n=>n.id===s&&n.enabled!==!1),Rr=()=>{};function Or(t){return t==="on"||t==="off"}function Qs(t){return typeof t=="string"&&qc.includes(t)}function Ap(){const{t}=z(),s=j(c=>c.subagentModelsEnabled),n=j(c=>c.subagentModels),a=j(c=>c.setSubagentModelsEnabled),r=j(c=>c.addSubagentModel),o=j(c=>c.updateSubagentModel),i=j(c=>c.removeSubagentModel),u=j(c=>c.defaultModel),d=Qe(),x=m.useMemo(()=>{if(u){const c=d.find(f=>f.id===u.providerId);if(c&&Ip(c,u.modelId))return u}for(const c of d){const f=c.models.find(l=>l.enabled!==!1);if(f)return{providerId:c.id,modelId:f.id}}return null},[d,u]),h=()=>{window.electronAPI.window.summonAgent({typeKey:Vc,prompt:t(Kc)})};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:t("Let the agent pick subagent models")}),e.jsx("p",{className:"mt-0.5 text-muted-foreground text-xs",children:t("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:t("Applies to newly started conversations.")})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2.5",children:[e.jsxs(I,{type:"button",variant:"outline",size:"sm",className:"h-7 gap-1 px-2.5 text-xs",onClick:h,children:[e.jsx(_n,{className:"h-3.5 w-3.5 text-primary"}),t("Auto configure with AI")]}),e.jsx(le,{checked:s,onCheckedChange:a})]})]}),s&&e.jsxs("div",{className:"space-y-1.5",children:[n.map(c=>e.jsxs("div",{"data-slot":"subagent-model-row",className:H("flex items-center gap-2 rounded-md border px-2 py-1.5",c.enabled===!1&&"bg-muted/50 text-muted-foreground"),children:[e.jsx(le,{"data-slot":"subagent-model-enabled","aria-label":t("Enable subagent model"),title:t("Make this model available to subagents"),checked:c.enabled!==!1,onCheckedChange:f=>o(c.id,{enabled:f})}),c.enabled===!1&&e.jsx(te,{variant:"outline",className:"shrink-0 text-[10px] text-muted-foreground",children:t("Disabled")}),e.jsx("div",{className:"shrink-0 rounded-md border bg-background",children:e.jsx(Oe,{providers:d,providerId:c.providerId,modelId:c.modelId,modelCapabilityOverrides:$c(c),reasoningMode:Or(c.reasoning)?c.reasoning:"follow",reasoningEnabled:c.reasoning==="on",thinkingLevel:Qs(c.thinkingLevel)?c.thinkingLevel:"medium",onReasoningModeChange:(f,l)=>{f==="follow"?o(c.id,{reasoning:void 0,thinkingLevel:void 0}):f==="on"&&!Qs(c.thinkingLevel)?o(c.id,{reasoning:"on",thinkingLevel:l}):o(c.id,{reasoning:f})},onSelect:(f,l)=>o(c.id,{providerId:f,modelId:l}),onReasoningChange:f=>o(c.id,{reasoning:f?"on":"off"}),onThinkingChange:f=>o(c.id,{thinkingLevel:f}),onReasoningNormalize:Or(c.reasoning)?f=>o(c.id,{reasoning:f?"on":"off"}):Rr,onThinkingNormalize:Qs(c.thinkingLevel)?f=>o(c.id,{thinkingLevel:f}):Rr})}),e.jsx(Y,{value:c.description,placeholder:t("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(I,{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(I,{type:"button",variant:"outline",size:"sm",className:"h-7 text-xs",disabled:!x,onClick:()=>{x&&r({...x,description:""})},children:[e.jsx(Te,{className:"mr-1 h-3.5 w-3.5"}),t("Add model")]}),!x&&e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Enable a model and configure valid provider credentials first.")})]})]})}function Ep(){const{t}=z(),s=j(d=>d.titleSummaryEnabled),n=j(d=>d.setTitleSummaryEnabled),a=j(d=>d.titleSummaryModel),r=j(d=>d.setTitleSummaryModel),o=Qe(),i=a?o.find(d=>d.id===a.providerId):void 0,u=i?.models.find(d=>d.id===a?.modelId);return e.jsxs("section",{className:"space-y-2 rounded-lg border bg-card p-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h4",{className:"font-medium text-sm",children:t("Conversation title summary")}),e.jsx("p",{className:"mt-0.5 text-muted-foreground text-xs",children:t("Generate a short AI title from the first message of a new conversation.")})]}),e.jsx(le,{checked:s,onCheckedChange:n})]}),s&&e.jsxs("div",{className:"space-y-2",children:[o.length>0&&e.jsx("div",{className:"w-full min-w-0",children:e.jsx(Oe,{providers:o,providerId:i?.id??"",modelId:u?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:t("Follows the default model"),side:"bottom",triggerClassName:Ye,onSelect:(d,x)=>r({providerId:d,modelId:x}),onReasoningChange:()=>{},onThinkingChange:()=>{}})}),a&&(!i||!u)&&e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Selected model is unavailable — falls back to the default model.")}),a&&e.jsx(I,{variant:"ghost",size:"sm",className:"self-start",onClick:()=>r(null),children:t("Follow default model")})]})]})}function Mp({accountKey:t}){const s=ed(t);return!s||s.error?null:e.jsx(td,{info:s})}function Pp(){const{t}=z(),s=j(L=>L.providers),n=_t(),a=j(L=>L.updateProvider),r=j(L=>L.addProviders),o=j(L=>L.removeProvider),[i,u]=m.useState(!1),[d,x]=m.useState(!1),[h,c]=m.useState(null),[f,l]=m.useState(null),[p,g]=m.useState(null),[w,C]=m.useState(null),[b,N]=m.useState(!1),[y,S]=m.useState(null),D=es(L=>L.snapshot.revision),[k,O]=m.useState([]);m.useEffect(()=>{let L=!1;return window.electronAPI.providers.listOauth().then(K=>{L||O(K)}),()=>{L=!0}},[D]);const E=m.useMemo(()=>Gc(s,k),[s,k]),M=m.useMemo(()=>{const L=new Map;for(const K of n)L.set(K.id,K.models.length);return L},[n]),A=async(L,K)=>{if(g(L.id),C(null),L.oauthAccountKey&&!L.oauthAccountPool&&!K?.skipLogout)try{await window.electronAPI.providers.oauthLogout(L.oauthAccountKey),await sd()}catch($){g(null),C({providerId:L.id,message:$ instanceof Error?$.message:String($)});return}o(L.id),g(null),C(null)},F=()=>{const L=f;L&&A(L)},V=async()=>{N(!0),S(null);try{const L=await Promise.all(s.map(async $=>{const G=await Sp($);return[$.id,G]})),K={};for(const[$,G]of L)K[$]=G,G.status==="ok"&&G.models&&a($,{models:G.models});S(K)}finally{N(!1)}},v=y?Object.values(y).filter(L=>L.status==="ok").length:0,U=y?Object.values(y).filter(L=>L.status==="failed").length:0;return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-end justify-between gap-4","data-settings-row":"providers.root",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-lg font-medium",children:[t("Model Providers"),e.jsx(qe,{note:t("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:t("Manage model API providers for this app")})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[y&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:[t("Fetched {{count}} providers",{count:v}),U>0&&e.jsxs("span",{className:"text-destructive",children:[" ",t("{{count}} failed",{count:U})]})]}),e.jsxs(I,{variant:"outline",size:"sm",disabled:b||s.length===0,onClick:()=>{V()},children:[b?e.jsx(Pe,{className:"mr-1.5 h-4 w-4 animate-spin"}):e.jsx(tt,{className:"mr-1.5 h-4 w-4"}),t("Fetch all models")]}),e.jsxs(I,{variant:"outline",size:"sm",onClick:()=>u(!0),children:[e.jsx(rs,{className:"h-4 w-4 mr-1.5"}),t("Import from local apps")]}),e.jsxs(I,{size:"sm",onClick:()=>x(!0),children:[e.jsx(Te,{className:"h-4 w-4 mr-1.5"}),t("Add model or provider")]})]})]}),e.jsx(wp,{}),e.jsx(Np,{}),e.jsx(_m,{}),e.jsx(Ep,{}),e.jsx(yp,{}),e.jsx(Ap,{}),Lo(s).length>0&&!s.some(L=>L.oauthAccountPool)&&e.jsxs("div",{className:"space-y-1.5 rounded-md border p-3",children:[e.jsxs(I,{variant:"outline",size:"sm",onClick:()=>{const L=Hc(s,crypto.randomUUID());L&&r([L])>0&&c(L)},children:[e.jsx(Te,{className:"mr-1.5 h-3.5 w-3.5"}),t("Create ChatGPT account pool")]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Pool entries do not show a single account quota. Fixed-account entries remain unchanged.")})]}),s.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx(zn,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 text-sm font-medium",children:t("No providers yet")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:t("Import providers from local apps or use the unified setup to get started")})]}):e.jsx("div",{className:"space-y-1",children:E.map(L=>{const K=k.find(G=>G.id===L.vendorId),$=L.vendorId===Wc?t("Custom"):L.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:$}),e.jsx("span",{className:"text-[11px] text-muted-foreground/60",children:L.providers.length})]}),e.jsx("div",{className:"mt-1.5 space-y-1 border-l pl-3",children:L.providers.map(G=>{const X=!!G.oauthAccountKey,oe=M.get(G.id)??G.models.length,q=G.oauthAccountKey&&!G.oauthAccountPool?K?.accounts.find(ee=>ee.key===G.oauthAccountKey):void 0,ie=G.oauthAccountPool?Bn(G,t):X?q?.email??G.oauthAccountKey??G.name:G.name,B=y?.[G.id];return e.jsxs(m.Fragment,{children:[e.jsxs("div",{className:"group flex items-start justify-between gap-3 rounded-md px-3 py-2 transition-colors hover:bg-accent/50","data-settings-row":`providers.${G.id}`,children:[e.jsxs("div",{className:"min-w-0 flex-1 overflow-hidden",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[X?e.jsx(Yc,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}):e.jsx(Jc,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx("span",{className:H("truncate text-sm font-medium",!G.enabled&&"text-muted-foreground line-through"),children:ie}),X?q?.plan&&e.jsx(te,{variant:"outline",className:"shrink-0 text-[10px] uppercase",children:q.plan}):e.jsx(te,{variant:"outline",className:"shrink-0 text-[11px]",children:Qc[G.api]??G.api}),G.importedFrom&&e.jsx(te,{variant:"secondary",className:"shrink-0 text-[11px]",children:G.importedFrom}),e.jsx("span",{className:"min-w-0 truncate text-xs text-muted-foreground",children:[X?void 0:G.baseUrl,G.oauthAccountPool?t("{{count}} accounts",{count:G.oauthAccountPool.accountKeys.length}):void 0,oe>0?t("{{count}} models",{count:oe}):void 0].filter(Boolean).join(" · ")})]}),ln(G)&&e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:t("Classification only, not for chat")}),G.oauthAccountKey&&!G.oauthAccountPool&&e.jsx(Mp,{accountKey:G.oauthAccountKey})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1 pt-0.5",children:[e.jsx(le,{checked:G.enabled,onCheckedChange:ee=>a(G.id,{enabled:ee})}),e.jsx(I,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",onClick:()=>c(G),children:e.jsx(it,{className:"h-3.5 w-3.5"})}),e.jsx(I,{variant:"ghost",size:"icon",disabled:p===G.id,className:H("h-7 w-7 text-muted-foreground opacity-0 transition-opacity hover:text-destructive group-hover:opacity-100",p===G.id&&"opacity-100"),onClick:()=>l(G),children:p===G.id?e.jsx(Pe,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Ee,{className:"h-3.5 w-3.5"})})]})]}),w?.providerId===G.id&&e.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-md border border-destructive/30 bg-destructive/5 px-3 py-1.5 text-xs text-destructive",children:[e.jsx("span",{className:"min-w-0 truncate",children:t("Sign-out failed: {{message}}",{message:w.message})}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(I,{variant:"outline",size:"sm",className:"h-6 px-2 text-[11px]",onClick:()=>{A(G)},children:t("Retry")}),e.jsx(I,{variant:"ghost",size:"sm",className:"h-6 px-2 text-[11px] text-destructive hover:text-destructive",onClick:()=>{A(G,{skipLogout:!0})},children:t("Delete anyway")})]})]}),B?.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:[t("Fetch failed"),": ",B.message]})})]},G.id)})})]},L.vendorId)})}),e.jsx(Xc,{open:i,onOpenChange:u}),e.jsx(Zc,{open:d,onOpenChange:x}),e.jsx(Cp,{provider:h,onClose:()=>c(null)}),e.jsx(io,{open:f!==null,onOpenChange:L=>{L||l(null)},title:t("Remove provider?"),description:f?f.oauthAccountKey&&!f.oauthAccountPool?t("Removing this also signs out {{name}}. Other accounts for the same vendor stay signed in.",{name:f.name}):t('This permanently deletes the "{{name}}" provider configuration.',{name:f.name}):void 0,confirmLabel:t("Remove"),onConfirm:F})]})}const Tp=2e3,Dr=50,Pt="",Rp=[{id:"app",label:"App processes"},{id:"agent",label:"Agent and tools"},{id:"child",label:"Other child processes"}],fn={sessions:["Conversation history","Conversation transcripts and usage ledger."],coworkers:["Coworker transcripts","Coworker journals; only those of deleted conversations are cleaned."],toolOutputs:["Tool outputs","Saved long tool outputs; only those of deleted conversations are cleaned."],memory:["Memory","Memory database and working memory."],models:["Local models","Downloaded embedding, chat and speech models."],runtimes:["Runtimes","Bundled tools, speech runtime and GPU backends."],worktrees:["Worktrees","Isolated worktrees created for conversations."],snapshots:["Change snapshots","Baselines for the Changes panel."],browser:["Browser data","Cookies, storage and cache of the built-in browser."],cache:["Cache","Rebuildable caches; cleaning is safe."],logs:["Logs","Task and memory logs; files written in the last 24 hours are kept."],backups:["Backups","Configuration backup files; files from the last 24 hours are kept."],config:["Configuration","Settings, instructions, prompts and credentials."],other:["Other","Chromium profile data and other files."]};function Op(t,s){switch(t){case"main":return s("Main process");case"window":return s("Window");case"browser":return s("Built-in browser");case"gpu":return"GPU";case"service":return s("Service");case"agent":return"Agent";case"tool":return s("Tool");default:return s("Child process")}}function Dp(t,s){return t.id==="data"?s("App data"):s("Worktree directory")}function Lp(t,s){return t.role!=="window"?t.name:t.name==="Main window"?s("Main window"):t.name==="Settings"?s("Settings"):t.name}function zp(t){return`${t.toFixed(1)}%`}function Bp(){const{t}=z(),[s,n]=m.useState("cpu");return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:t("Resources")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("CPU, memory and disk usage of EnsoCode and the processes it started.")})]}),e.jsxs(zt,{value:s,onValueChange:a=>n(a),children:[e.jsxs(Bt,{children:[e.jsx(Ke,{value:"cpu",children:"CPU"}),e.jsx(Ke,{value:"memory",children:t("RAM")}),e.jsx(Ke,{value:"storage",children:t("Storage")})]}),e.jsx(Tt,{value:"cpu",className:"pt-4",children:s==="cpu"&&e.jsx(Lr,{metric:"cpu"})}),e.jsx(Tt,{value:"memory",className:"pt-4",children:s==="memory"&&e.jsx(Lr,{metric:"memory"})}),e.jsx(Tt,{value:"storage",className:"pt-4",children:s==="storage"&&e.jsx(Fp,{})})]})]})}function Lr({metric:t}){const{t:s}=z(),[n,a]=m.useState(null),[r,o]=m.useState(null);if(m.useEffect(()=>{let x=!1,h;const c=async()=>{try{const f=await window.electronAPI.resources.sample();if(x)return;a(f),o(null)}catch(f){x||o(f instanceof Error?f.message:String(f))}x||(h=setTimeout(c,Tp))};return c(),()=>{x=!0,clearTimeout(h)}},[]),r&&!n)return e.jsx("p",{className:"text-sm text-destructive",children:r});if(!n)return e.jsx("p",{className:"text-sm text-muted-foreground",children:s("Loading...")});const i=t==="cpu"?zp:de,u=t==="cpu"?{app:n.cpu.app,system:n.cpu.system,total:100}:n.memory,d=x=>t==="cpu"?x.cpu:x.memory;return e.jsxs("div",{className:"space-y-4",children:[e.jsx(pi,{app:u.app,system:Math.max(u.system,u.app),total:u.total,format:i}),Rp.map(x=>{const h=n.processes.filter(c=>c.group===x.id).sort((c,f)=>d(f)-d(c));return h.length===0?null:e.jsxs("div",{className:"rounded-lg border",children:[e.jsxs("div",{className:"flex items-center justify-between border-b px-3 py-2 text-sm font-medium",children:[e.jsx("span",{children:s(x.label)}),e.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:i(h.reduce((c,f)=>c+d(f),0))})]}),e.jsx("div",{className:"divide-y",children:h.map(c=>e.jsxs("div",{className:"flex items-center gap-3 px-3 py-1.5 text-sm",children:[e.jsx("span",{className:"w-20 shrink-0 truncate text-xs text-muted-foreground",children:Op(c.role,s)}),e.jsx("span",{className:"min-w-0 flex-1 truncate",title:c.command??c.name,children:Lp(c,s)}),e.jsx("span",{className:"w-16 text-right font-mono text-xs text-muted-foreground",children:c.pid}),e.jsx("span",{className:"w-20 text-right font-mono text-xs",children:i(d(c))})]},c.pid))})]},x.id)})]})}function pi({app:t,system:s,total:n,format:a}){const{t:r}=z(),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(t)})]}),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(s)," / ",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(s)}}),e.jsx("div",{className:"absolute inset-y-0 left-0 bg-foreground",style:{width:o(t)}})]})]})}function _p(t,s){const n=[s("Freed {{size}}",{size:de(t.freedBytes)})];return t.removed>0&&n.push(s("{{count}} files removed",{count:t.removed})),t.skipped>0&&n.push(s("{{count}} kept",{count:t.skipped})),t.failed>0&&n.push(s("{{count}} failed",{count:t.failed})),n.join(" · ")}function Fp(){const{t}=z(),[s,n]=m.useState(null),[a,r]=m.useState("scan"),[o,i]=m.useState(null),[u,d]=m.useState(null),[x,h]=m.useState(null),[c,f]=m.useState(null),l=m.useCallback(async(b,N)=>{r(b),d(null),i(null);try{n(await N())}catch(y){const S=y instanceof Error?y.message:String(y);S.includes("Scan cancelled")||d(S)}finally{r(null),i(null)}},[]),p=m.useCallback(()=>l("scan",()=>window.electronAPI.resources.scanStorage()),[l]),g=b=>l(b,async()=>{const N=await window.electronAPI.resources.cleanStorage(b);return _e({type:N.failed>0?"warning":"success",title:t("{{name}} cleaned",{name:t(fn[b][0])}),description:_p(N,t)}),N.snapshot});m.useEffect(()=>{const b=window.electronAPI.resources.onScanProgress(i);return window.electronAPI.resources.lastStorage().then(N=>{N&&n(y=>y??N)}),p(),()=>{b(),window.electronAPI.resources.cancelScan()}},[p]);const w=s?[...s.categories].filter(b=>b.bytes>0).sort((b,N)=>N.bytes-b.bytes):[],C=m.useMemo(()=>{const b=new Map;for(const N of s?.roots??[])b.set(N.volumeId,[...b.get(N.volumeId)??[],N]);return[...b.values()]},[s]);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?t("Scanning {{count}} files · {{size}}",{count:o.files.toLocaleString(),size:de(o.bytes)}):t("Scanning..."):s?t("Scanned at {{time}} · took {{seconds}}s",{time:new Date(s.scannedAt).toLocaleTimeString(),seconds:(s.durationMs/1e3).toFixed(1)}):null}),a==="scan"?e.jsx(I,{variant:"ghost",size:"sm",onClick:()=>{window.electronAPI.resources.cancelScan()},children:t("Cancel")}):e.jsx(I,{variant:"ghost",size:"icon-sm",onClick:()=>{p()},disabled:a!==null,"aria-label":t("Refresh"),children:e.jsx(tt,{})})]}),u&&e.jsx("p",{className:"text-sm text-destructive",children:u}),s&&s.errorCount>0&&e.jsxs("p",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",title:s.errors.join(`
|
|
28
|
+
`),children:[e.jsx(Fe,{className:"h-3.5 w-3.5"}),t("{{count}} paths could not be read and are not counted.",{count:s.errorCount})]}),s&&e.jsxs(e.Fragment,{children:[C.map(b=>{const N=b[0]?.volume,y=b.reduce((S,D)=>S+D.bytes,0);return e.jsxs("div",{className:"space-y-2",children:[N?e.jsx(pi,{app:y,system:N.total-N.free,total:N.total,format:de}):e.jsx("div",{className:"rounded-lg border p-4 font-mono text-2xl font-semibold",children:de(y)}),b.map(S=>e.jsxs("div",{className:"flex items-center gap-2 px-1 text-xs",children:[e.jsx("span",{className:"shrink-0 text-muted-foreground",children:Dp(S,t)}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono",title:S.path,children:S.path}),e.jsx("span",{className:"font-mono",children:de(S.bytes)})]},S.id))]},b[0]?.volumeId)}),e.jsx("div",{className:"divide-y rounded-lg border",children:w.map(b=>e.jsx(Up,{category:b,share:s.totalBytes>0?b.bytes/s.totalBytes:0,expanded:x===b.id,onToggle:()=>h(x===b.id?null:b.id),cleaning:a===b.id,disabled:a!==null,onClean:()=>zo[b.id]==="confirm"?f(b.id):void g(b.id)},b.id))}),e.jsx($p,{sessions:s.sessions,busy:a==="sessions",disabled:a!==null,onClean:b=>l("sessions",async()=>{const N=await window.electronAPI.resources.cleanSessions(b);return _e({type:"success",title:t("{{count}} conversations deleted",{count:N.removed})}),N.snapshot})})]}),e.jsx(wn,{open:c!==null,onOpenChange:b=>!b&&f(null),children:e.jsxs(Nn,{className:"sm:max-w-md",zIndexLevel:"nested",children:[e.jsxs(kn,{children:[e.jsx(Cn,{className:"text-base",children:t("Clean {{name}}?",{name:c?t(fn[c][0]):""})}),e.jsx(Sn,{children:t(c==="browser"?"You will be signed out of sites opened in the built-in browser.":"Deleted files cannot be restored.")})]}),e.jsxs(In,{variant:"bare",children:[e.jsx(An,{render:e.jsx(I,{variant:"outline",size:"sm"}),children:t("Cancel")}),e.jsx(I,{variant:"destructive",size:"sm",onClick:()=>{const b=c;f(null),b&&g(b)},children:t("Clean")})]})]})})]})}function Up({category:t,share:s,expanded:n,onToggle:a,cleaning:r,disabled:o,onClean:i}){const{t:u}=z(),[d,x]=fn[t.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(At,{className:H("h-4 w-4 shrink-0 transition-transform",n&&"rotate-90")}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-2 text-sm",children:[e.jsx("span",{className:"font-medium",children:u(d)}),e.jsx("span",{className:"font-mono text-xs",children:de(t.bytes)})]}),e.jsx("p",{className:"truncate text-xs text-muted-foreground",children:u(x)}),e.jsx("div",{className:"mt-1 h-1 overflow-hidden rounded-full bg-muted",children:e.jsx("div",{className:"h-full bg-foreground/60",style:{width:`${s*100}%`}})})]})]}),zo[t.id]!=="none"&&e.jsx(I,{variant:"outline",size:"sm",disabled:o,onClick:i,children:u(r?"Cleaning...":"Clean")})]}),n&&e.jsx("div",{className:"mt-2 space-y-0.5 pl-6",children:t.entries.map(h=>e.jsxs("div",{className:"group flex items-center gap-2 text-xs",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-muted-foreground",children:h.root==="data"?h.path:`${u("Worktree directory")}/${h.path}`}),e.jsx("span",{className:"font-mono",children:de(h.bytes)}),e.jsx(I,{variant:"ghost",size:"icon-sm",className:"opacity-0 group-hover:opacity-100","aria-label":u("Show in folder"),onClick:()=>{window.electronAPI.resources.revealStorage(h.root,h.path)},children:e.jsx(Tn,{})})]},`${h.root}:${h.path}`))})]})}function $p({sessions:t,busy:s,disabled:n,onClean:a}){const{t:r}=z(),[o,i]=m.useState(!1),[u,d]=m.useState(!1),[x,h]=m.useState(null),[c,f]=m.useState(Pt),l=m.useMemo(()=>new Map(t.map(E=>[E.id,E])),[t]),p=m.useMemo(()=>{const E=new Map;for(const M of t){const A=E.get(M.projectId)??{name:M.projectName,bytes:0,count:0};A.bytes+=M.bytes,A.count+=1,E.set(M.projectId,A)}return[...E].sort((M,A)=>A[1].bytes-M[1].bytes)},[t]),g=p.some(([E])=>E===c)?c:Pt,w=g?t.filter(E=>E.projectId===g):t,C=E=>{const M=id(t,E,Date.now());return{request:E,count:M.length,bytes:M.reduce((A,F)=>A+(l.get(F)?.bytes??0),0)}},b=E=>C({kind:"stale",days:E,includeUnarchived:o,...g?{projectId:g}:{}}),N=w.reduce((E,M)=>E+M.bytes,0),y=u?w:w.slice(0,Dr),S=(E,M)=>M||(E?E.slice(0,8):r("No project")),D=x?.request.kind==="one"?l.get(x.request.id):void 0,k=x?.request.kind==="stale"?x.request.projectId:void 0,O=k===void 0?void 0:S(k,p.find(([E])=>E===k)?.[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:[w.length," · ",de(N)]})]}),e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsxs(se,{items:{[Pt]:r("All projects"),...Object.fromEntries(p.map(([E,M])=>[E,S(E,M.name)]))},value:g,onValueChange:E=>f(E??Pt),children:[e.jsx(ne,{size:"sm",className:"w-48 min-w-0",children:e.jsx(ae,{})}),e.jsxs(re,{children:[e.jsx(Q,{value:Pt,children:r("All projects")}),p.map(([E,M])=>e.jsx(Q,{value:E,children:e.jsxs("span",{className:"flex w-full items-center gap-3",children:[e.jsx("span",{className:"flex-1 truncate",children:S(E,M.name)}),e.jsxs("span",{className:"font-mono text-xs text-muted-foreground",children:[M.count," · ",de(M.bytes)]})]})},E))]})]}),e.jsxs(Bo,{children:[e.jsxs(_o,{render:e.jsx(I,{variant:"outline",size:"sm",disabled:n||w.length===0}),children:[e.jsx(nd,{}),r(s?"Cleaning...":"Clean")]}),e.jsxs(Fo,{align:"end",className:"min-w-48",children:[e.jsx(ad,{checked:o,onCheckedChange:i,closeOnClick:!1,children:r("Include unarchived")}),e.jsx(rd,{}),[...od,0].map(E=>{const M=b(E);return e.jsxs(Uo,{variant:"destructive",disabled:M.count===0,onClick:()=>h(M),children:[e.jsx("span",{className:"flex-1",children:E>0?r("Older than {{days}} days",{days:E}):r("All")}),e.jsx("span",{className:"font-mono text-xs opacity-70",children:M.count})]},E)})]})]})]})]}),e.jsx("div",{className:"max-h-96 divide-y overflow-y-auto",children:y.map(E=>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:E.title,children:E.title||r("Untitled")}),e.jsx("div",{className:"truncate text-xs text-muted-foreground",children:[E.projectName,E.archived?r("Archived"):null,new Date(E.lastActiveAt).toLocaleDateString()].filter(Boolean).join(" · ")})]}),e.jsx("span",{className:"font-mono text-xs",children:de(E.bytes)}),e.jsx(I,{variant:"ghost",size:"icon-sm",className:"opacity-0 group-hover:opacity-100",disabled:n,"aria-label":r("Delete"),onClick:()=>h({request:{kind:"one",id:E.id},count:1,bytes:E.bytes}),children:e.jsx(Ee,{})})]},E.id))}),w.length>Dr&&e.jsx("button",{type:"button",onClick:()=>d(!u),className:"w-full border-t px-3 py-1.5 text-xs text-muted-foreground hover:text-foreground",children:r(u?"Show less":"Show all")}),e.jsx(wn,{open:x!==null,onOpenChange:E=>!E&&h(null),children:e.jsxs(Nn,{className:"sm:max-w-md",zIndexLevel:"nested",children:[e.jsxs(kn,{children:[e.jsx(Cn,{className:"text-base",children:D?r('Delete "{{title}}"?',{title:D.title||r("Untitled")}):O!==void 0?r("Delete {{count}} conversations in {{project}}?",{count:x?.count??0,project:O}):r("Delete {{count}} conversations?",{count:x?.count??0})}),e.jsxs(Sn,{children:[r("About {{size}} of history, tool output and isolated worktrees will be removed and cannot be restored.",{size:de(x?.bytes??0)}),!D&&` ${r("Open, running and waiting conversations are skipped.")}`]})]}),e.jsxs(In,{variant:"bare",children:[e.jsx(An,{render:e.jsx(I,{variant:"outline",size:"sm"}),children:r("Cancel")}),e.jsx(I,{variant:"destructive",size:"sm",onClick:()=>{const E=x?.request;h(null),E&&a(E)},children:r("Delete")})]})]})})]})}function Vp(){const{t}=z(),s=j(y=>y.skills),n=j(y=>y.updateSkill),a=j(y=>y.setSkillsEnabled),r=j(y=>y.removeSkill),o=j(y=>y.loadLocalSkills),i=j(y=>y.setLoadLocalSkills),u=j(y=>y.loadHarnessAssets),d=j(y=>y.setLoadHarnessAssets),[x,h]=m.useState(!1),[c,f]=m.useState(""),l=s.filter(y=>No(c,[y.name,y.source,y.description,y.path])),p=l.map(y=>y.id),g=ko(p),w=s.filter(y=>y.enabled).length,C=s.map(y=>y.id),b=cs(C,y=>window.electronAPI.assets.skillOccupancy(y)),N=os(s.filter(y=>y.enabled).map(y=>y.id),b.rows);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 rounded-lg border px-3 py-2.5",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:t("Load local skills")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Let the agent auto-discover skills under .agents/skills and .pi/skills")})]}),e.jsx(le,{checked:o,onCheckedChange:i})]}),e.jsxs("div",{className:"flex items-center justify-between gap-4 rounded-lg border px-3 py-2.5",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:t("Load project harness assets")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Also load skills from .claude/.codex/.cursor and rule files (.cursorrules, .cursor/rules, .claude/rules) in the project")})]}),e.jsx(le,{checked:u,onCheckedChange:d})]}),e.jsxs("div",{className:"flex items-end justify-between gap-4","data-settings-row":"skills.root",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"font-medium text-lg",children:[t("Skills"),e.jsx(qe,{note:t("The / menu updates right away, but open sessions keep the skills they loaded. Start a new session to load the change.")}),s.length>0&&e.jsxs("span",{className:"ml-2 font-normal text-muted-foreground text-xs",children:[t("{{enabled}}/{{total}} enabled",{enabled:w,total:s.length}),e.jsx(ls,{tokens:N})]})]}),e.jsx("p",{className:"text-muted-foreground text-sm",children:t("Skills registered by reference; files stay in their original location")})]}),e.jsxs(I,{variant:"outline",size:"sm",onClick:()=>h(!0),children:[e.jsx(rs,{className:"mr-1.5 h-4 w-4"}),t("Import from local apps")]})]}),s.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:t("No skills yet")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:t("Import skills from Claude Code, Codex or Cursor to get started")})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx(So,{query:c,onQueryChange:f,placeholder:t("Filter skills..."),allSelected:g.allSelected,someSelected:g.someSelected,onToggleSelectAll:g.toggleAll,onEnable:()=>a(g.selectedIds,!0),onDisable:()=>a(g.selectedIds,!1),selectDisabled:l.length===0,actionDisabled:g.selectedIds.length===0}),l.length===0?e.jsx("p",{className:"px-3 py-6 text-center text-muted-foreground text-xs",children:t("No results")}):e.jsx("div",{className:"space-y-1",children:l.map(y=>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.${y.id}`,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(Je,{checked:g.isSelected(y.id),onCheckedChange:S=>g.toggleOne(y.id,S)}),e.jsx("span",{className:H("shrink-0 font-medium text-sm",!y.enabled&&"text-muted-foreground line-through"),children:y.name}),e.jsx(te,{variant:"secondary",className:"shrink-0 text-[11px]",children:y.source}),e.jsx("span",{className:"min-w-0 truncate text-muted-foreground text-xs",children:y.description||y.path})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(is,{row:b.rows[y.id],pending:b.pending&&!b.rows[y.id]}),e.jsx(le,{checked:y.enabled,onCheckedChange:S=>n(y.id,{enabled:S})}),e.jsx(I,{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(y.id),children:e.jsx(Ee,{className:"h-3.5 w-3.5"})})]})]},y.id))})]}),e.jsx(Ln,{kind:"skill",open:x,onOpenChange:h})]})}const zr=[10,15,30,60,120,300];function Kp(){const{t}=z(),[s,n]=m.useState([]),[a,r]=m.useState(!1),[o,i]=m.useState(null),[u,d]=m.useState(""),[x,h]=m.useState(""),[c,f]=m.useState(""),[l,p]=m.useState(""),[g,w]=m.useState("key"),[C,b]=m.useState(""),[N,y]=m.useState(!1),[S,D]=m.useState(null),[k,O]=m.useState(null),[E,M]=m.useState(null),[A,F]=m.useState(null),[V,v]=m.useState(!1),U=m.useCallback(()=>{window.electronAPI.sshConnections.list().then(n)},[]);m.useEffect(()=>{U()},[U]);const L=()=>{i(null),d(""),h(""),f(""),p(""),w("key"),b(""),O(null),r(!0)},K=q=>{i(q),d(q.name),h(q.host),f(q.user??""),p(q.port?String(q.port):""),w(q.auth),b(""),O(null),r(!0)},$=async q=>{q.preventDefault(),y(!0),O(null);const ie=l.trim()?Number(l):void 0,B=await window.electronAPI.sshConnections.upsert({...o?{id:o.id}:{},name:u.trim(),host:x.trim(),...c.trim()?{user:c.trim()}:{},...ie&&Number.isInteger(ie)?{port:ie}:{},auth:g,...g==="password"&&C?{password:C}:{}});if(y(!1),!B.ok){O(B.error);return}r(!1),U()},G=async q=>{const ie=await window.electronAPI.sshConnections.delete(q);if(!ie.ok){M(ie.error);return}M(null),U()},X=async(q,ie=!0)=>{D(q),M(null);const B=await window.electronAPI.sshConnections.test(q);if(D(null),!B.ok){const ee=s.find(P=>P.id===q),R=cd(B,ee);if(R&&ie){F({id:q,challenge:R});return}}M(B.ok?t("SSH connection succeeded"):B.error)},oe=async()=>{if(!A)return;v(!0);const q=A.id,ie=await window.electronAPI.sshConnections.trustHost(q);if(v(!1),F(null),!ie.ok){M(ie.error||t("Could not save host key."));return}await X(q,!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:[t("SSH"),e.jsx(qe,{note:t("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:t("Saved hosts for remote projects. Passwords stay in the system keychain.")})]}),e.jsxs(I,{size:"sm",onClick:L,children:[e.jsx(Te,{className:"h-4 w-4"}),t("Add connection")]})]}),E&&e.jsx("p",{className:"text-sm text-muted-foreground",children:E}),e.jsxs("ul",{className:"divide-y rounded-lg border",children:[s.length===0&&e.jsx("li",{className:"px-3 py-6 text-sm text-muted-foreground",children:t("No SSH connections yet")}),s.map(q=>e.jsxs("li",{className:"flex items-center gap-2 px-3 py-2","data-settings-row":`ssh.${q.id}`,children:[e.jsxs("button",{type:"button",className:"min-w-0 flex-1 text-left",onClick:()=>K(q),children:[e.jsx("div",{className:"truncate text-sm font-medium",children:q.name}),e.jsxs("div",{className:"truncate text-xs text-muted-foreground",children:[q.user?`${q.user}@`:"",q.host,q.port?`:${q.port}`:""," ·"," ",q.auth==="password"?t("Password"):t("Key / agent")]})]}),e.jsx(I,{size:"sm",variant:"outline",disabled:S===q.id,onClick:()=>{X(q.id)},children:S===q.id?e.jsx(Pe,{className:"h-4 w-4 animate-spin"}):t("Test")}),e.jsx(I,{size:"icon-sm",variant:"ghost",onClick:()=>{G(q.id)},children:e.jsx(Ee,{className:"h-4 w-4"})})]},q.id))]}),e.jsx(qp,{}),e.jsx(fe,{open:a,onOpenChange:r,children:e.jsx(ge,{className:"max-w-md",children:e.jsxs("form",{onSubmit:q=>{$(q)},className:"flex flex-col",children:[e.jsx(je,{children:e.jsx(ve,{children:t(o?"Edit SSH connection":"Add SSH connection")})}),e.jsxs(we,{className:"space-y-3",children:[e.jsxs(ue,{children:[e.jsx(me,{children:t("Name")}),e.jsx(Y,{value:u,onChange:q=>d(q.target.value),required:!0})]}),e.jsxs(ue,{children:[e.jsx(me,{children:t("Host")}),e.jsx(Y,{value:x,onChange:q=>h(q.target.value),placeholder:"example.com",required:!0})]}),e.jsxs(ue,{children:[e.jsx(me,{children:t("User (optional)")}),e.jsx(Y,{value:c,onChange:q=>f(q.target.value)})]}),e.jsxs(ue,{children:[e.jsx(me,{children:t("Port (optional)")}),e.jsx(Y,{value:l,onChange:q=>p(q.target.value),placeholder:"22"})]}),e.jsxs(ue,{children:[e.jsx(me,{children:t("Authentication")}),e.jsxs(se,{items:[{value:"key",label:t("Key / agent")},{value:"password",label:t("Password")}],value:g,onValueChange:q=>w(q),children:[e.jsx(ne,{className:"w-full",children:e.jsx(ae,{})}),e.jsxs(re,{zIndex:et.DROPDOWN_IN_MODAL,children:[e.jsx(Q,{value:"key",children:t("Key / agent")}),e.jsx(Q,{value:"password",children:t("Password")})]})]})]}),g==="password"&&e.jsxs(ue,{children:[e.jsx(me,{children:o?.hasPassword?t("Password (leave blank to keep)"):t("Password")}),e.jsx(Y,{type:"password",value:C,onChange:q=>b(q.target.value),required:!o?.hasPassword})]}),k&&e.jsx("p",{className:"text-sm text-destructive",children:k})]}),e.jsxs(Ie,{children:[e.jsx(I,{type:"button",variant:"outline",size:"sm",onClick:()=>r(!1),children:t("Cancel")}),e.jsx(I,{type:"submit",size:"sm",disabled:N,children:t("Save")})]})]})})}),e.jsx(ld,{challenge:A?.challenge??null,busy:V,onTrust:()=>{oe()},onDismiss:()=>!V&&F(null)})]})}function qp(){const{t}=z(),s=j(a=>a.sshTimeoutSeconds),n=j(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:t("SSH timeout")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Time limit for connection tests, loading remote AGENTS.md, remote folder browsing and file panel actions. Agent tool commands are not affected.")})]}),e.jsxs(se,{items:Object.fromEntries(zr.map(a=>[String(a),`${a}s`])),value:String(s),onValueChange:a=>n(Number(a)),children:[e.jsx(ne,{className:"w-24",children:e.jsx(ae,{})}),e.jsx(re,{children:zr.map(a=>e.jsx(Q,{value:String(a),children:`${a}s`},a))})]})]})}const Gp={memory:"memory",workflows:"workflow"},fi=["bots","botTemplates"],Hp=[{id:"app",label:"Application",categories:["general","appearance","shortcuts","voice","privacy"]},{id:"agent",label:"Models & agents",categories:["providers","presets","agents","instructions","memory"]},{id:"extensions",label:"Tools & extensions",categories:["tools","workflows","skills","mcp","plugins","claudePlugins"]},{id:"connections",label:"Connections",categories:["phone","ssh"]},{id:"system",label:"System",categories:["usage","resources","experimental","bots","botTemplates"]}];function Wp(t){const s=new Map(t.map(n=>[n.id,n]));return Hp.flatMap(n=>{const a=n.categories.flatMap(r=>{const o=s.get(r);return o?[o]:[]});return a.length>0?[{id:n.id,label:n.label,items:a}]:[]})}function gi(t,s,n=!1){if(fi.includes(t))return n;const a=Gp[t];return!a||!s.includes(a)}function Yp(t,s,n=!1){return t.filter(a=>gi(a.id,s,n))}function Jp(t,s,n=!1){return gi(t,s,n)?t:fi.includes(t)?"experimental":"tools"}function Qp(t,s,n,a){const r=n.trim();if(!r)return t.map(d=>({...d,hits:[]}));const o=dd([...s,...t.map(d=>({id:`${d.id}.root`,category:d.id,title:d.label}))],r,{translate:a,limit:Number.POSITIVE_INFINITY}),i=new Set,u=new Map;for(const d of o){if(i.add(d.category),d.id.endsWith(".root"))continue;const x=u.get(d.category);x?x.push(d):u.set(d.category,[d])}return t.flatMap(d=>i.has(d.id)?[{...d,hits:u.get(d.id)??[]}]:[])}const Xp=[1,7,30,90],Br=640,Ht=180,_r=8,Fr=18,Zp=.3,ef=2;function tf(t){const[,s,n]=t.split("-");return`${Number(s)}/${Number(n)}`}const sf=[{id:"cache",cls:"fill-foreground/15",swatch:"bg-foreground/15"},{id:"input",cls:"fill-foreground/45",swatch:"bg-foreground/45"},{id:"output",cls:"fill-foreground",swatch:"bg-foreground"}];function nf({daily:t}){const{t:s}=z(),[n,a]=m.useState("tokens"),[r,o]=m.useState(null),[i,u]=m.useState({output:!0,input:!0,cache:!0}),d=b=>{u(N=>{const y={...N,[b]:!N[b]};return!y.output&&!y.input&&!y.cache?N:y})},x=t.map(b=>n==="cost"?b.cost??0:(i.output?b.output:0)+(i.input?b.input:0)+(i.cache?b.cache:0)),h=Math.max(0,...x),c=Math.max(1,t.length),f=Br/c,l=Math.min(f*(1-Zp),64),p=Ht-_r-Fr,g=b=>h>0?b/h*p:0,w=Math.max(1,Math.ceil(c/12)),C=r!==null?t[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:s("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(Xs,{className:"bg-foreground",label:s("Output"),pressed:i.output,onClick:()=>d("output")}),e.jsx(Xs,{className:"bg-foreground/45",label:s("Input"),pressed:i.input,onClick:()=>d("input")}),e.jsx(Xs,{className:"bg-foreground/15",label:s("Cache"),pressed:i.cache,onClick:()=>d("cache")})]}),e.jsx(af,{value:n,onChange:a})]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"pointer-events-none absolute left-0 top-0 font-mono text-[10px] text-muted-foreground",children:n==="tokens"?Ue(h):ts(h>0?h:null)}),C&&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:[C.day,n==="tokens"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[s("Output")," ",Ue(C.output)]}),e.jsxs("div",{children:[s("Input")," ",Ue(C.input)]}),e.jsxs("div",{children:[s("Cache")," ",Ue(C.cache)]})]}):e.jsxs(e.Fragment,{children:[" · ",ts(C.cost)]})]}),e.jsx("svg",{viewBox:`0 0 ${Br} ${Ht}`,className:"mt-4 block h-[180px] w-full",role:"img","aria-label":s("Daily trend"),onMouseLeave:()=>o(null),children:t.map((b,N)=>{const y=N*f+(f-l)/2,S=Ht-Fr,D=n==="tokens"?sf.filter(O=>i[O.id]).map(O=>({v:b[O.id],cls:O.cls})):[{v:b.cost??0,cls:"fill-emerald-600 dark:fill-emerald-500"}];let k=S;return e.jsxs("g",{onMouseEnter:()=>o(N),children:[e.jsx("rect",{x:y,y:_r,width:l,height:p,className:"fill-transparent"}),D.map(O=>{const E=O.v>0?Math.max(ef,g(O.v)):0;return k-=E,e.jsx("rect",{x:y,y:k,width:l,height:E,rx:1,className:H(O.cls,r===N&&"opacity-80")},O.cls)}),N%w===0&&e.jsx("text",{x:y+l/2,y:Ht-4,textAnchor:"middle",className:"fill-muted-foreground font-mono text-[10px]",children:tf(b.day)})]},b.day)})})]})]})}function Xs({className:t,label:s,pressed:n,onClick:a}){return e.jsxs("button",{type:"button","aria-pressed":n,onClick:a,className:H("flex items-center gap-1 rounded px-0.5 transition-opacity",n?"opacity-100":"opacity-40"),children:[e.jsx("span",{className:H("inline-block h-2.5 w-2.5 rounded-sm",t)}),s]})}function af({value:t,onChange:s}){const{t:n}=z(),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:()=>s(r.id),className:H("rounded px-2 py-0.5 text-[11px] transition-colors",t===r.id?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:r.label},r.id))})}const Zs=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],Ur=Array.from({length:24},(t,s)=>String(s).padStart(2,"0")),ns=["bg-foreground/[0.06]","bg-foreground/20","bg-foreground/40","bg-foreground/60","bg-foreground/80","bg-foreground"];function rf(t,s){return t<=0||s<=0?0:1+Math.min(ns.length-2,Math.floor(t/s*(ns.length-1)))}function of({heatmap:t}){const{t:s}=z(),n=Math.max(0,...t.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:s("Activity by hour")}),e.jsxs("div",{className:"flex items-center gap-1 text-[10px] text-muted-foreground",children:[e.jsx("span",{children:s("Less")}),ns.map(a=>e.jsx("span",{className:H("inline-block h-2.5 w-2.5 rounded-[2px]",a)},a)),e.jsx("span",{children:s("More")})]})]}),e.jsxs("div",{className:"grid grid-cols-[28px_1fr] gap-x-2 gap-y-1",children:[t.map((a,r)=>e.jsxs("div",{className:"contents",children:[e.jsx("span",{className:"self-center text-[10px] text-muted-foreground",children:s(Zs[r])}),e.jsx("div",{className:"grid grid-cols-24 gap-[3px]",children:Ur.map((o,i)=>e.jsx("span",{title:`${s(Zs[r])} ${o}:00 · ${Ue(a[i]??0)}`,className:H("aspect-square rounded-[2px]",ns[rf(a[i]??0,n)])},o))})]},Zs[r])),e.jsx("span",{}),e.jsx("div",{className:"grid grid-cols-24 font-mono text-[10px] text-muted-foreground",children:Ur.map((a,r)=>e.jsx("span",{className:H(r%3!==0&&"invisible"),children:a},a))})]})]})}function en({title:t,countLabel:s,rows:n,emptyLabel:a,limit:r=8}){const{t:o}=z(),[i,u]=m.useState(!1),d=n.reduce((c,f)=>c+f.tokens,0),x=n.length>r,h=x&&!i?n.slice(0,r):n;return e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[e.jsx("span",{className:"text-sm font-medium",children:t}),x&&e.jsx("span",{className:"text-[11px] text-muted-foreground",children:i?o("{{total}} items",{total:n.length}):o("Top {{count}} of {{total}}",{count:r,total:n.length})})]}),h.length===0?e.jsx("p",{className:"py-6 text-center text-xs text-muted-foreground",children:a}):e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-[11px] text-muted-foreground",children:[e.jsx("th",{className:"pb-2 text-left font-normal",children:o("Name")}),e.jsx("th",{className:"pb-2 text-right font-normal",children:o("Cost")}),e.jsx("th",{className:"pb-2 text-right font-normal",children:o("Token")}),e.jsx("th",{className:"pb-2 text-right font-normal",children:s})]})}),e.jsx("tbody",{children:h.map(c=>{const f=d>0?c.tokens/d:0;return e.jsxs("tr",{className:"border-t border-border/60",children:[e.jsxs("td",{className:"py-2 pr-3",children:[e.jsx("div",{className:"truncate",title:c.name,children:c.name||o("(no project)")}),e.jsx("div",{className:"mt-1 h-1 w-full rounded-full bg-foreground/[0.06]",children:e.jsx("div",{className:"h-1 rounded-full bg-foreground/70",style:{width:`${Math.max(1,f*100)}%`}})})]}),e.jsx("td",{className:H("py-2 text-right font-mono tabular-nums",c.cost===null&&"text-muted-foreground"),children:ts(c.cost)}),e.jsxs("td",{className:"py-2 text-right font-mono tabular-nums",children:[Ue(c.tokens),e.jsxs("span",{className:"ml-1 text-muted-foreground",children:[(f*100).toFixed(0),"%"]})]}),e.jsx("td",{className:"py-2 text-right font-mono tabular-nums",children:c.count})]},c.key)})})]}),x&&e.jsx(I,{variant:"ghost",size:"xs",className:"mt-2 w-full text-muted-foreground",onClick:()=>u(c=>!c),children:o(i?"Collapse":"Show all")})]})}function lf({value:t,className:s}){const n=t.split("");return e.jsx("span",{className:H("t-digit-group is-animating",s),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}`))},t)}const cf={default:"text-foreground",success:"text-emerald-600 dark:text-emerald-400",info:"text-sky-600 dark:text-sky-400",muted:"text-muted-foreground"};function ot({label:t,value:s,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:t}),n&&e.jsx("span",{className:"shrink-0 font-mono text-[11px] tabular-nums text-muted-foreground",children:n})]}),e.jsx("div",{className:H("mt-1 truncate font-mono text-xl font-semibold leading-tight tabular-nums sm:text-2xl",cf[a]),title:s,children:e.jsx(lf,{value:s})})]})}const tn={input:0,output:0,cacheRead:0,cacheWrite:0},as=["input","output","cacheRead","cacheWrite"];function sn(t){return{input:String(t.input),output:String(t.output),cacheRead:String(t.cacheRead),cacheWrite:String(t.cacheWrite)}}function df(t){return xd({id:Object.fromEntries(as.map(n=>[n,Number(t[n])]))}).id??null}function uf(t){return t===void 0?"—":String(t)}function $r({rows:t,editing:s,draft:n,overrides:a,onDraft:r,onEdit:o,onSave:i}){const{t:u}=z();return e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-[11px] text-muted-foreground",children:[e.jsx("th",{className:"pb-2 text-left font-normal",children:u("Name")}),as.map(d=>e.jsx("th",{className:"pb-2 text-right font-normal",children:d},d)),e.jsx("th",{className:"w-14 pb-2"})]})}),e.jsx("tbody",{children:t.map(d=>{const x=s===d.model,h=d.model in a;return e.jsxs("tr",{className:"border-t border-border/60",children:[e.jsxs("td",{className:"py-1.5 pr-3 align-middle",children:[e.jsx("span",{className:"font-mono text-xs",title:d.model,children:d.model}),h&&e.jsx("span",{className:"ml-1.5 text-[10px] text-muted-foreground",children:u("Custom")})]}),as.map(c=>e.jsx("td",{className:"py-1.5 text-right align-middle",children:x?e.jsx(Y,{size:"sm",inputMode:"decimal",className:"ml-auto w-16 [&_input]:text-right",value:n[c],onChange:f=>r({...n,[c]:f.target.value})}):e.jsx("span",{className:H("font-mono tabular-nums",d.pricing==null&&"text-muted-foreground"),children:uf(d.pricing?.[c])})},c)),e.jsx("td",{className:"py-1.5 text-right align-middle",children:x?e.jsx(I,{size:"sm",className:"h-6 px-1.5 text-[11px]",onClick:()=>i(d.model),children:u("Save")}):e.jsx(I,{variant:"ghost",size:"sm",className:"h-6 px-1.5 text-[11px]",onClick:()=>o(d.model,d.pricing),children:u("Edit")})})]},d.model)})})]})}function mf({models:t,catalog:s,onChanged:n}){const{t:a}=z(),r=j(v=>v.usageModelPricing),o=_t(),i=j(v=>v.setUsageModelPricing),[u,d]=m.useState(!1),[x,h]=m.useState(!1),[c,f]=m.useState(null),[l,p]=m.useState(sn(tn)),[g,w]=m.useState(null),[C,b]=m.useState(!1),[N,y]=m.useState(""),[S,D]=m.useState(""),k=new Set(t.map(v=>v.model)),O=new Set;for(const v of o)for(const U of v.models)O.add(U.id);for(const v of Object.keys(r))O.add(v);const E=S.trim().toLowerCase(),M=t.filter(v=>!E||v.model.toLowerCase().includes(E)).map(v=>({model:v.model,pricing:v.pricing})),A=[...O].filter(v=>!k.has(v)&&(!E||v.toLowerCase().includes(E))).sort().map(v=>({model:v,pricing:r[v]??s[v]??null})),F=(v,U)=>{b(!1),f(v),p(sn(U??tn)),w(null)},V=v=>{const U=df(l);return!U||!i(v,U)?(w(a("Enter a model id and non-negative rates.")),!1):(w(null),f(null),b(!1),y(""),n(),!0)};return e.jsxs(ud,{open:u,onOpenChange:d,className:"rounded-lg border bg-card",children:[e.jsxs(md,{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(Zt,{className:H("h-4 w-4 shrink-0 text-muted-foreground transition-transform",u&&"rotate-180")})]}),e.jsx(hd,{children:e.jsxs("div",{className:"space-y-3 border-t px-4 py-3",children:[e.jsx(Y,{size:"sm",value:S,onChange:v=>D(v.target.value),placeholder:a("Search models")}),M.length===0&&!C?e.jsx("p",{className:"text-xs text-muted-foreground",children:a(E?"No matching models":"No usage in this period")}):e.jsx($r,{rows:M,editing:c,draft:l,overrides:r,onDraft:p,onEdit:F,onSave:V}),A.length>0&&(x||!!E)&&e.jsx($r,{rows:A,editing:c,draft:l,overrides:r,onDraft:p,onEdit:F,onSave:V}),C?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-end gap-2",children:[e.jsxs("label",{className:"grid min-w-36 gap-1 text-[11px] text-muted-foreground",children:[a("Model id"),e.jsx(Y,{size:"sm",value:N,onChange:v=>y(v.target.value),placeholder:"qwen-3.8-27b"})]}),as.map(v=>e.jsxs("label",{className:"grid min-w-16 gap-1 text-[11px] text-muted-foreground",children:[v,e.jsx(Y,{size:"sm",inputMode:"decimal",value:l[v],onChange:U=>p(L=>({...L,[v]:U.target.value}))})]},v))]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(I,{size:"sm",className:"h-7",onClick:()=>V(N),children:a("Save")}),e.jsx(I,{variant:"ghost",size:"sm",className:"h-7",onClick:()=>{b(!1),y(""),w(null)},children:a("Cancel")})]})]}):e.jsxs("div",{className:"flex justify-end gap-2",children:[A.length>0&&e.jsxs(I,{variant:"ghost",size:"sm",className:"h-7 text-muted-foreground",onClick:()=>h(v=>!v),children:[a("Show all"),e.jsx(Zt,{className:H("ml-1 h-3.5 w-3.5 transition-transform",x&&"rotate-180")})]}),e.jsx(I,{variant:"ghost",size:"sm",className:"h-7",onClick:()=>{b(!0),p(sn(tn)),w(null)},children:a("Add")})]}),g&&e.jsx("p",{className:"text-xs text-destructive",children:g})]})})]})}const hf={1:"Today",7:"7D",30:"30D",90:"90D"};function xf(){const{t}=z(),[s,n]=m.useState(7),[a,r]=m.useState(null),o=j(p=>p.botModeEnabled),[i,u]=m.useState(null),[d,x]=m.useState(null),[h,c]=m.useState(!1),f=m.useRef(0),l=m.useCallback(async p=>{const g=++f.current;c(!0);const[w,C]=await Promise.all([window.electronAPI.usage.summary(p),o?window.electronAPI.bots.usageSummary(p).catch(()=>null):null]);g===f.current&&(c(!1),u(C?.ok?C.rows:null),w.ok?(r(w.summary),x(null)):(r(null),x(w.error)))},[o]);return m.useEffect(()=>{l(s)},[s,l]),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:t("Usage")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("Token usage across all local sessions; cost is estimated from catalog prices.")})]}),e.jsx(I,{variant:"ghost",size:"icon-sm",onClick:()=>{l(s)},disabled:h,"aria-label":t("Refresh"),children:e.jsx(tt,{className:H(h&&"animate-spin")})})]}),e.jsx(pf,{value:s,onChange:n}),d&&e.jsx("p",{className:"text-sm text-destructive",children:d}),a&&e.jsxs(e.Fragment,{children:[e.jsx(ff,{totals:a.totals,previous:a.previous}),e.jsx(nf,{daily:a.daily}),e.jsx(of,{heatmap:a.heatmap}),e.jsxs("div",{className:"grid gap-4 xl:grid-cols-2",children:[e.jsx(en,{title:t("By model"),countLabel:t("Messages"),emptyLabel:t("No usage in this period"),rows:a.byModel.map(p=>({key:p.model,name:p.model,cost:p.cost,tokens:p.tokens,count:p.messages}))}),e.jsx(en,{title:t("By project"),countLabel:t("Sessions"),emptyLabel:t("No usage in this period"),rows:a.byProject.map(p=>({key:p.project||"#",name:p.project,cost:p.cost,tokens:p.tokens,count:p.sessions}))})]}),o&&i&&e.jsx(en,{title:t("By member"),countLabel:t("Sessions"),emptyLabel:t("No usage in this period"),rows:i.map(p=>({key:p.botId,name:p.name||t("Deleted member"),cost:p.cost,tokens:p.tokens,count:p.sessions}))}),a.unpricedModels.length>0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:t("No catalog price for: {{models}}. Their cost is not included.",{models:a.unpricedModels.join(", ")})})]}),e.jsx(mf,{models:a?.byModel??[],catalog:a?.pricing??{},onChanged:()=>{l(s)}})]})}function pf({value:t,onChange:s}){const{t:n}=z();return e.jsx("div",{className:"flex items-center gap-1.5",children:Xp.map(a=>e.jsx("button",{type:"button",onClick:()=>s(a),className:H("rounded-full px-3 py-1 font-mono text-xs transition-colors",t===a?"bg-foreground text-background":"bg-muted text-muted-foreground hover:text-foreground"),children:n(hf[a])},a))})}function ff({totals:t,previous:s}){const{t:n}=z(),a=t.cacheRead+t.cacheWrite,r=s.cacheRead+s.cacheWrite;return e.jsxs("div",{className:"grid grid-cols-2 gap-3 md:grid-cols-4",children:[e.jsx(ot,{label:n("Estimated cost"),value:ts(t.cost),delta:nt(s.cost,t.cost),tone:"success"}),e.jsx(ot,{label:n("Total tokens"),value:Ue(t.tokens),delta:nt(s.tokens,t.tokens)}),e.jsx(ot,{label:n("Input tokens"),value:Ue(t.input),delta:nt(s.input,t.input)}),e.jsx(ot,{label:n("Output tokens"),value:Ue(t.output),delta:nt(s.output,t.output)}),e.jsx(ot,{label:n("Cache tokens"),value:Ue(a),delta:nt(r,a),tone:"muted"}),e.jsx(ot,{label:n("Active time"),value:pd(t.activeMs),delta:nt(s.activeMs,t.activeMs),tone:"info"}),e.jsx(ot,{label:n("Sessions"),value:String(t.sessions),delta:nt(s.sessions,t.sessions)}),e.jsx(ot,{label:n("Messages"),value:t.messages.toLocaleString(),delta:nt(s.messages,t.messages)})]})}const Vr={"x-asr-streaming":{name:"X-ASR Streaming",description:"Text appears while you speak. Chinese and English."},"x-asr":{name:"X-ASR",description:"Most accurate on everyday speech. Chinese and English."},"qwen3-asr":{name:"Qwen3-ASR 0.6B",description:"Best with mixed Chinese-English and code terms. Slower and uses more memory."},"sense-voice":{name:"SenseVoice",description:"Chinese, English, Japanese, Korean and Cantonese."},hanbao:{name:"Hanbao",description:"Runs fully offline. Chinese and English."},"gemini-live":{name:"Gemini Transcribe Live",description:"Google cloud recognition, most accurate with mixed Chinese-English and code terms. Needs a Gemini API key."},wetype:{name:"WeType",description:"WeChat Keyboard cloud recognition. Chinese and English, no setup needed."}};function ji({state:t,onDownload:s,onCancel:n,onRemove:a}){const{t:r}=z();return t==="unavailable"?null:t==="downloading"?e.jsx(I,{variant:"outline",size:"sm",onClick:n,children:r("Cancel")}):t==="ready"?e.jsx(I,{variant:"ghost",size:"sm",onClick:a,children:r("Remove")}):e.jsx(I,{variant:"outline",size:"sm",onClick:s,children:r("Download")})}function gf(){const{t}=z(),s=j(h=>h.voiceModel),n=j(h=>h.setVoiceModel),{status:a,progress:r,error:o,refresh:i}=fd();if(!a)return null;if(a.state==="unsupported")return e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Voice input is not available on this platform.")});const u=window.electronAPI.speech,d=h=>{const c=r[h.id];return c?`${c.file} · ${de(c.received)}${c.total?` / ${de(c.total)}`:""} (${c.fileIndex+1}/${c.fileCount})`:o?.modelId===h.id?`${t("Download failed")}: ${o.message}`:h.id==="wetype"?t("Audio is uploaded to Tencent WeChat Keyboard servers."):h.remote?h.state==="ready"?t("Audio is uploaded to Google. On the free tier Google may use it to improve its products."):t("Enter a Gemini API key below first."):t("Download {{size}} · Memory about {{memory}}",{size:de(h.approxBytes),memory:de(h.memoryBytes)})},x=a.models.find(h=>h.id===s);return e.jsxs("div",{className:"space-y-1.5","data-settings-row":"tools.voiceModel",children:[e.jsx("p",{className:"text-sm",children:t("Speech model")}),e.jsx("div",{role:"radiogroup",className:"divide-y rounded-md border",children:a.models.map(h=>{const c=h.id===s;return e.jsxs("div",{className:H("flex items-center gap-3 px-3 py-2",c&&"bg-accent/40"),children:[e.jsxs("button",{type:"button",role:"radio","aria-checked":c,onClick:()=>n(h.id),className:"flex min-w-0 flex-1 items-start gap-2.5 text-left",children:[e.jsx("span",{className:H("mt-1 flex size-3.5 shrink-0 items-center justify-center rounded-full border",c&&"border-primary"),children:c?e.jsx("span",{className:"size-2 rounded-full bg-primary"}):null}),e.jsxs("span",{className:"min-w-0",children:[e.jsxs("span",{className:"flex flex-wrap items-center gap-1.5 text-sm",children:[t(Vr[h.id].name),h.remote?e.jsx(te,{variant:"warning",size:"sm",children:t("Cloud")}):null,e.jsx(te,{variant:h.streaming?"info":"secondary",size:"sm",children:h.streaming?t("Streaming"):t("Sentence by sentence")}),h.state==="ready"&&!h.remote?e.jsx(te,{variant:"success",size:"sm",children:t("Downloaded")}):null]}),e.jsx("span",{className:"block text-muted-foreground text-xs",children:t(Vr[h.id].description)}),e.jsx("span",{className:H("block text-xs",o?.modelId===h.id?"text-destructive":h.remote?"text-warning":"text-muted-foreground"),children:d(h)})]})]}),e.jsx(ji,{state:h.remote?"unavailable":h.state,onDownload:()=>{n(h.id),u.download(h.id).then(i)},onCancel:()=>{u.cancelDownload(h.id).then(i)},onRemove:()=>{u.remove(h.id).then(i)}})]},h.id)})}),a.state!=="ready"&&a.state!=="downloading"&&!x?.remote?e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Download the selected model to start using voice input.")}):null,x?.id==="gemini-live"?e.jsxs(e.Fragment,{children:[e.jsx(jf,{}),e.jsx(vf,{})]}):null]})}function jf(){const{t}=z(),s=j(a=>a.voiceGeminiApiKey),n=j(a=>a.setVoiceGeminiApiKey);return e.jsxs("div",{className:"space-y-1.5 pt-2","data-settings-row":"voice.geminiApiKey",children:[e.jsx("p",{className:"text-sm",children:t("Gemini API key")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Create one for free in Google AI Studio.")}),e.jsx(Y,{type:"password",autoComplete:"off",spellCheck:!1,value:s,onChange:a=>n(a.target.value),placeholder:"AIza…",className:"font-mono"})]})}function vf(){const{t}=z(),s=j(a=>a.voiceVocabulary),n=j(a=>a.setVoiceVocabulary);return e.jsxs("div",{className:"space-y-1.5 pt-2","data-settings-row":"voice.vocabulary",children:[e.jsx("p",{className:"text-sm",children:t("Custom vocabulary")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("One term per line, up to 100. Helps with names and code terms such as useEffect or pnpm.")}),e.jsx(He,{size:"sm",value:s,onChange:a=>n(a.target.value),placeholder:`useEffect
|
|
29
|
+
pnpm
|
|
30
|
+
TypeScript`,className:"font-mono"})]})}function bf(){const{t}=z(),s=j(b=>b.voiceCorrectionEnabled),n=j(b=>b.setVoiceCorrectionEnabled),a=j(b=>b.voiceCorrectionModel)||"remote",r=j(b=>b.setVoiceCorrectionModel),o=j(b=>b.voiceCorrectionRemoteModel),i=j(b=>b.setVoiceCorrectionRemoteModel),u=Qe(),[d,x]=m.useState([]),[h,c]=m.useState(null),f=m.useCallback(()=>{window.electronAPI.memory.chatModels().then(x)},[]);m.useEffect(()=>(f(),window.electronAPI.memory.onChatModelProgress(b=>{c(b.done?null:b),b.done&&f()})),[f]);const l=d.find(b=>b.id===a)??null,p=d.map(b=>({value:b.id,label:b.id==="remote"?t("Remote (API model)"):`${b.label}${b.purpose?` · ${t("tuned for voice")}`:""} · ${de(b.approxBytes)}`})),g=o?u.find(b=>b.id===o.providerId):void 0,w=g?.models.find(b=>b.id===o?.modelId),C=window.electronAPI.memory;return e.jsxs("div",{className:"space-y-2","data-settings-row":"tools.voiceCorrection",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Correct with a language model")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Fixes homophones, code terms and number formats after recognition. Adds about 1-3 seconds; the raw text is kept if it fails.")})]}),e.jsx(le,{checked:s,onCheckedChange:n})]}),s?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:"text-sm",children:t("Correction model")}),e.jsxs(se,{value:a,items:p,onValueChange:b=>r(String(b)),children:[e.jsx(ne,{className:"w-64",children:e.jsx(ae,{})}),e.jsx(re,{children:p.map(b=>e.jsx(Q,{value:b.value,children:b.label},b.value))})]})]}),l?.downloadable?e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:H("text-xs",l.state==="missing"?"text-destructive":"text-muted-foreground"),children:h?.modelId===l.id?`${de(h.received)}${h.total?` / ${de(h.total)}`:""}`:l.state==="ready"?t("Model downloaded"):l.state==="downloading"?t("Downloading…"):t("Not downloaded yet. Correction is skipped until it is.")}),e.jsx(ji,{state:l.state,onDownload:()=>{C.downloadChatModel(l.id).then(f)},onCancel:()=>{C.cancelChatModelDownload(l.id).then(f)},onRemove:()=>{C.deleteChatModel(l.id).then(f)}})]}):null,a==="remote"&&u.length>0?e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:t("A fast, inexpensive model is enough.")}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[o?e.jsx(I,{variant:"ghost",size:"sm",onClick:()=>i(null),children:t("Reset")}):null,e.jsx("div",{className:"w-56",children:e.jsx(Oe,{providers:u,providerId:g?.id??"",modelId:w?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:t("Follows the title-summary model"),side:"bottom",triggerClassName:Ye,onSelect:(b,N)=>i({providerId:b,modelId:N}),onReasoningChange:()=>{},onThinkingChange:()=>{}})})]})]}):null]}):null]})}function yf(){const{t}=z(),s=j(a=>a.voiceInputEnabled),n=j(a=>a.setVoiceInputEnabled);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4","data-settings-row":"voice.root",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-medium text-lg",children:t("Voice input")}),e.jsx("p",{className:"text-muted-foreground text-sm",children:t("Adds a microphone to the composer on this computer and on paired phones. Local models transcribe speech on this computer.")})]}),e.jsx(le,{checked:s,onCheckedChange:n,"aria-label":t("Voice input"),className:"mt-1 shrink-0"})]}),s?e.jsxs(e.Fragment,{children:[e.jsx(Nf,{}),e.jsx(gf,{}),e.jsx(bf,{})]}):null]})}function wf(){const[t,s]=m.useState([]);return m.useEffect(()=>{const n=navigator.mediaDevices;if(!n?.enumerateDevices)return;let a=!0;const r=()=>{n.enumerateDevices().then(o=>{a&&s(o.filter(i=>i.kind==="audioinput"&&i.deviceId!==$o&&i.deviceId!=="communications"))})};return r(),n.addEventListener("devicechange",r),()=>{a=!1,n.removeEventListener("devicechange",r)}},[]),t}function Nf(){const{t}=z(),s=j(o=>o.voiceInputDevice),n=j(o=>o.setVoiceInputDevice),a=wf(),r=[{value:$o,label:t("System default")},...a.map((o,i)=>({value:o.deviceId,label:o.label||t("Microphone {{n}}",{n:i+1})}))];return r.some(o=>o.value===s)||r.push({value:s,label:t("Disconnected, using the system default")}),e.jsxs("div",{className:"flex items-center justify-between gap-3","data-settings-row":"voice.microphone",children:[e.jsx("p",{className:"text-sm",children:t("Microphone")}),e.jsxs(se,{value:s,items:r,onValueChange:o=>n(String(o)),children:[e.jsx(ne,{className:"w-64",children:e.jsx(ae,{})}),e.jsx(re,{children:r.map(o=>e.jsx(Q,{value:o.value,children:o.label},o.value))})]})]})}const kf=32,Cf=/^[A-Za-z0-9][A-Za-z0-9_:-]{0,127}$/,Sf=/^[A-Za-z_][A-Za-z0-9_]{0,31}$/,If=/\{\{\s*(?:args\.([A-Za-z_][A-Za-z0-9_]{0,31})|(prev))\s*\}\}/g;function gn(t,s){if(typeof t!="string")return null;const n=t.trim();return n&&n.length<=s?n:null}function Af(t,s){const n=[...new Set(t)].filter(a=>Sf.test(a)).map(a=>({kind:"arg",key:a,token:`{{args.${a}}}`}));return s>0&&n.push({kind:"prev",token:"{{prev}}"}),n}function Ef(t,s,n,a){const r=Math.min(Math.max(s,0),t.length),o=Math.min(Math.max(n,r),t.length);return{text:t.slice(0,r)+a+t.slice(o),cursor:r+a.length}}function Mf(t){if(!t||typeof t!="object"||Array.isArray(t))return null;const s=t,n=gn(s.label,80),a=gn(s.prompt,8e3),r=typeof s.agentType=="string"?s.agentType.trim():"";return!n||!a||r&&!Cf.test(r)?null:{label:n,agentType:r,prompt:a}}function Pf(t){if(!t||typeof t!="object"||Array.isArray(t))return null;const s=t,n=gn(s.title,80);if(!n||!Array.isArray(s.steps)||s.steps.length===0)return null;const a=s.steps.map(Mf);return a.every(r=>r!==null)?{title:n,steps:a}:null}function Tf(t){if(!t||typeof t!="object"||Array.isArray(t))return null;const s=t.phases;if(!Array.isArray(s)||s.length===0)return null;const n=s.map(Pf);return n.every(r=>r!==null)&&n.reduce((r,o)=>r+o.steps.length,0)<=kf?{phases:n}:null}function vi(t){const s=[];let n=0;for(const a of t.matchAll(If))a.index>n&&s.push({kind:"text",text:t.slice(n,a.index)}),s.push(a[1]?{kind:"arg",key:a[1]}:{kind:"prev"}),n=a.index+a[0].length;return n<t.length&&s.push({kind:"text",text:t.slice(n)}),s}function Rf(t){const s=vi(t).map(n=>n.kind==="text"?JSON.stringify(n.text):n.kind==="arg"?`String(args.${n.key} ?? '')`:"prev");return s.length>0?s.join(" + "):'""'}function Of({label:t,agentType:s,prompt:n}){const a=[`label: ${JSON.stringify(t)}`];return s&&a.push(`agentType: ${JSON.stringify(s)}`),` () => agent(${Rf(n)}, { ${a.join(", ")} }),`}function bi(t){const s=["// 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 t.phases){const a=JSON.stringify(n.steps.map(r=>r.label));s.push("",`await phase(${JSON.stringify(n.title)});`,`prev = collect(${a}, await parallel([`,...n.steps.map(Of),"]));")}return s.push("","return prev;",""),s.join(`
|
|
31
|
+
`)}async function Df(t){const[s,n,a]=await Promise.all([Jt(()=>import("./standalone-oyxre9MX.js"),[],import.meta.url),Jt(()=>import("./babel-BktJt1uC.js"),[],import.meta.url),Jt(()=>import("./estree-C_HWBWad.js"),[],import.meta.url)]);try{return{ok:!0,code:await s.format(t,{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(`
|
|
32
|
+
`)[0]??o}}}const Lf=32,Dt=(t,s)=>Math.max(0,Math.min(t,s));function zf(t){return t.phases.reduce((s,n)=>s+n.steps.length,0)<Lf}function Bf(t,s,n){const a=t.phases.map((r,o)=>o===s?{...r,steps:[...r.steps,n]}:r);return{design:{phases:a},selection:{kind:"step",phase:s,step:(a[s]?.steps.length??1)-1}}}function _f(t,s,n){const a=Dt(s,t.phases.length),r=[...t.phases];return r.splice(a,0,n),{design:{phases:r},selection:{kind:"phase",phase:a}}}function Kr(t,s){const n=t.phases[s.phase];if(!n)return null;if(s.kind==="step"&&n.steps.length>1){const r=n.steps.filter((o,i)=>i!==s.step);return{design:{phases:t.phases.map((o,i)=>i===s.phase?{...o,steps:r}:o)},selection:{kind:"step",phase:s.phase,step:Dt(s.step,r.length-1)}}}if(t.phases.length===1)return null;const a=t.phases.filter((r,o)=>o!==s.phase);return{design:{phases:a},selection:{kind:"phase",phase:Dt(s.phase,a.length-1)}}}function qr(t,s,n){const a=s+n;if(a<0||a>=t.phases.length||!t.phases[s])return{design:t,selection:{kind:"phase",phase:s}};const r=[...t.phases],[o]=r.splice(s,1);return o&&r.splice(a,0,o),{design:{phases:r},selection:{kind:"phase",phase:a}}}function Ff(t,s){const n=Dt(s.phase,t.phases.length-1);if(s.kind==="phase")return{kind:"phase",phase:n};const a=t.phases[n]?.steps.length??1;return{kind:"step",phase:n,step:Dt(s.step,a-1)}}const nn="__default__",Gr=(t="scout")=>({label:"",agentType:t,prompt:""});function Uf({value:t,tokens:s,args:n,onChange:a}){const{t:r}=z(),o=m.useRef(null),i=()=>o.current?.querySelector("textarea")??null,u=x=>{const h=i(),c=t.length,f=Ef(t,h?.selectionStart??c,h?.selectionEnd??c,x);a(f.text),requestAnimationFrame(()=>{h?.focus(),h?.setSelectionRange(f.cursor,f.cursor)})},d=x=>x.kind==="prev"?r("Previous phase output"):n.find(h=>h.key.trim()===x.key)?.label.trim()||x.key;return e.jsxs("div",{ref:o,className:"space-y-1",children:[e.jsx(He,{rows:5,className:"text-xs",placeholder:r("Prompt"),value:t,onChange:x=>a(x.target.value)}),e.jsxs(Bo,{children:[e.jsxs(_o,{disabled:s.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(bd,{className:"h-3.5 w-3.5"}),r("Insert argument")]}),e.jsx(Fo,{align:"start",zIndex:et.DROPDOWN_IN_MODAL,finalFocus:i,children:s.map(x=>e.jsxs(Uo,{onClick:()=>u(x.token),children:[d(x),e.jsx("span",{className:"ml-auto pl-4 font-mono text-muted-foreground text-xs",children:x.token})]},x.token))})]})]})}const Hr=(t,s,n,a)=>{const r=Math.max((n-t)/2,8);return`M${t},${s} C${t+r},${s} ${n-r},${a} ${n},${a}`};function $f(t,s){const[n,a]=m.useState([]);return m.useLayoutEffect(()=>{const r=t.current;if(!r)return;const o=()=>{const u=r.getBoundingClientRect(),d=r.offsetWidth?u.width/r.offsetWidth:1,x=f=>{const l=r.querySelector(f)?.getBoundingClientRect();return l?{left:(l.left-u.left)/d,right:(l.right-u.left)/d,y:(l.top-u.top+l.height/2)/d}:null},h=(f,l)=>f<0||f>=s.phases.length?[`[data-node="${l}"]`]:(s.phases[f]?.steps??[]).map((p,g)=>`[data-node="s-${f}-${g}"]`),c=[];for(let f=0;f<=s.phases.length;f++){const l=x(`[data-gap="${f}"]`);if(l){for(const p of h(f-1,"start")){const g=x(p);g&&c.push({d:Hr(g.right,g.y,l.left,l.y),arrow:!1})}for(const p of h(f,"end")){const g=x(p);g&&c.push({d:Hr(l.right,l.y,g.left-2,g.y),arrow:!0})}}}a(c)};o();const i=new ResizeObserver(o);return i.observe(r),()=>i.disconnect()},[t,s]),n}function Wr({node:t,icon:s,title:n,detail:a}){return e.jsxs("div",{"data-node":t,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:[s,n]}),e.jsx("span",{className:"w-full truncate text-[10px] text-muted-foreground",children:a})]})}function Vf({prompt:t,args:s}){const{t:n}=z(),a=vi(t.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(m.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"):s.find(i=>i.key.trim()===r.key)?.label.trim()||r.key},o))})}function Kf({design:t,agentTypes:s,args:n,onChange:a}){const{t:r}=z(),[o,i]=m.useState({kind:"step",phase:0,step:0}),u=m.useRef(null),d=m.useId(),x=$f(u,t),h=t.phases,c=Ff(t,o),f=h[c.phase],l=c.kind==="step"?f?.steps[c.step]:void 0,p=s.includes("scout")?"scout":"",g=n.map(k=>k.key.trim()).filter(Boolean),w=zf(t),C=Kr(t,c)!==null,b=k=>{k&&(a(k.design),i(k.selection))},N=k=>a({phases:h.map((O,E)=>E===c.phase?{...O,...k}:O)}),y=k=>c.kind==="step"&&N({steps:(f?.steps??[]).map((O,E)=>E===c.step?{...O,...k}:O)}),S=k=>{const O=k&&!s.includes(k)?[...s,k]:s;return[{value:nn,label:r("Default (worker)")},...O.map(E=>({value:E,label:E}))]},D=k=>e.jsx("div",{className:"flex w-10 shrink-0 items-center justify-center self-stretch",children:e.jsx("button",{type:"button","data-gap":k,disabled:!w,"aria-label":r("Insert phase here"),title:r("Insert phase here"),onClick:()=>b(_f(t,k,{title:"",steps:[Gr(p)]})),className:"relative z-30 flex h-5 w-5 items-center justify-center rounded-full border bg-background text-muted-foreground transition-colors hover:border-primary hover:text-primary disabled:pointer-events-none disabled:opacity-50",children:e.jsx(Te,{className:"h-3 w-3"})})});return e.jsxs("div",{className:"w-full space-y-2",children:[e.jsx("div",{className:"overflow-x-auto rounded-lg border bg-muted/30",children:e.jsxs("div",{ref:u,className:"relative flex w-max min-w-full items-center justify-center px-3 py-5",children:[e.jsxs("svg",{"aria-hidden":!0,className:"pointer-events-none absolute inset-0 z-20 h-full w-full overflow-visible text-muted-foreground/50",children:[e.jsx("defs",{children:e.jsx("marker",{id:d,viewBox:"0 0 6 6",refX:"5",refY:"3",markerWidth:"6",markerHeight:"6",orient:"auto",children:e.jsx("path",{d:"M0,0 L6,3 L0,6 z",fill:"currentColor"})})}),x.map(k=>e.jsx("path",{d:k.d,fill:"none",stroke:"currentColor",strokeWidth:1.25,markerEnd:k.arrow?`url(#${d})`:void 0},k.d))]}),e.jsx(Wr,{node:"start",icon:e.jsx(gd,{className:"h-3 w-3"}),title:r("Start"),detail:g.length>0?g.join(", "):r("No arguments")}),h.map((k,O)=>e.jsxs(m.Fragment,{children:[D(O),e.jsxs("div",{className:H("flex w-44 shrink-0 flex-col gap-1.5 rounded-xl border border-dashed bg-background/60 p-2",c.kind==="phase"&&c.phase===O&&"border-primary border-solid"),children:[e.jsxs("button",{type:"button",onClick:()=>i({kind:"phase",phase:O}),className:H("flex min-w-0 items-center gap-1 rounded px-1 text-left text-[11px] hover:text-foreground",k.title.trim()?"text-muted-foreground":"text-destructive"),children:[e.jsx("span",{className:"shrink-0",children:r("Phase {{n}}",{n:O+1})}),e.jsx("span",{className:"truncate font-medium text-foreground",children:k.title.trim()||r("Untitled phase")})]}),k.steps.map((E,M)=>{const A=c.kind==="step"&&c.phase===O&&c.step===M,F=!E.label.trim()||!E.prompt.trim();return e.jsxs("button",{type:"button","data-node":`s-${O}-${M}`,onClick:()=>i({kind:"step",phase:O,step:M}),className:H("block w-full rounded-lg border bg-background px-2.5 py-1.5 text-left shadow-xs transition-colors hover:border-primary/60",A&&"border-primary ring-2 ring-primary/20",F&&!A&&"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:E.label.trim()||r("Untitled step")}),e.jsx("span",{className:"ml-auto shrink-0 rounded bg-muted px-1 text-[10px] text-muted-foreground",children:E.agentType||"worker"})]}),e.jsx("span",{className:"mt-0.5 line-clamp-2 break-words text-[11px] text-muted-foreground",children:e.jsx(Vf,{prompt:E.prompt,args:n})})]},M)}),e.jsxs("button",{type:"button",disabled:!w,onClick:()=>b(Bf(t,O,Gr(p))),className:"flex items-center justify-center gap-1 rounded-lg border border-dashed py-1 text-[11px] text-muted-foreground transition-colors hover:border-primary hover:text-primary disabled:pointer-events-none disabled:opacity-50",children:[e.jsx(Te,{className:"h-3 w-3"}),r("Parallel step")]})]})]},O)),D(h.length),e.jsx(Wr,{node:"end",icon:e.jsx(ru,{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(I,{variant:"ghost",size:"icon-xs","aria-label":r("Move left"),disabled:c.phase===0,onClick:()=>b(qr(t,c.phase,-1)),children:e.jsx(jd,{})}),e.jsx(I,{variant:"ghost",size:"icon-xs","aria-label":r("Move right"),disabled:c.phase===h.length-1,onClick:()=>b(qr(t,c.phase,1)),children:e.jsx(vd,{})})]}),e.jsx(I,{variant:"ghost",size:"icon-xs","aria-label":r("Delete"),disabled:!C,onClick:()=>b(Kr(t,c)),children:e.jsx(Ee,{})})]})]}),c.kind==="phase"||!l?e.jsx(Y,{size:"sm",placeholder:r("Phase title"),value:f?.title??"",onChange:k=>N({title:k.target.value})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Y,{size:"sm",className:"min-w-0 flex-1",placeholder:r("Label"),value:l.label,onChange:k=>y({label:k.target.value})}),e.jsxs(se,{items:S(l.agentType),value:l.agentType||nn,onValueChange:k=>y({agentType:k===nn?"":String(k??"")}),children:[e.jsx(ne,{size:"sm",className:"w-36 min-w-0 shrink-0",children:e.jsx(ae,{})}),e.jsx(re,{zIndex:et.DROPDOWN_IN_MODAL,children:S(l.agentType).map(k=>e.jsx(Q,{value:k.value,children:k.label},k.value))})]})]}),e.jsx(Uf,{value:l.prompt,tokens:Af(g,c.phase),args:n,onChange:k=>y({prompt:k})})]})]}),e.jsx("p",{className:"text-muted-foreground text-xs",children:r("Click a node to edit it. Steps in a column run in parallel; columns run from left to right.")})]})}const jn={phases:[{title:"Investigate",steps:[{label:"code",agentType:"scout",prompt:"Investigate {{args.topic}} in the source code."},{label:"tests",agentType:"scout",prompt:"Investigate {{args.topic}} in the tests."}]},{title:"Summarize",steps:[{label:"summary",agentType:"scout",prompt:`Merge these findings about {{args.topic}} into one short report:
|
|
33
|
+
|
|
34
|
+
{{prev}}`}]}]},Yr={name:"",description:"",args:[{key:"topic",label:"Topic",required:!0}],design:jn,script:bi(jn)};function qf(t){return t.map(({key:s,label:n,default:a,required:r})=>({key:s.trim(),label:n.trim()||s.trim(),...a?.trim()?{default:a}:{},...r?{required:!0}:{}}))}function Gf({target:t,onClose:s,onSaved:n}){const{t:a}=z(),[r,o]=m.useState(Yr),[i,u]=m.useState("design"),[d,x]=m.useState(0),h=m.useRef(null),[c,f]=m.useState(!1),[l,p]=m.useState(!1),[g,w]=m.useState(!1),[C,b]=m.useState(null),N=j(v=>v.disabledBuiltinAgentTypes),y=j(v=>v.agentTypes),S=m.useMemo(()=>[...yd.map(v=>v.name).filter(v=>!N.includes(v)),...y.map(v=>v.name)],[N,y]);m.useEffect(()=>{if(b(null),t===null)return;if(h.current=null,x(U=>U+1),t==="new"){o(Yr),u("design");return}let v=!1;return f(!0),window.electronAPI.workflowPresets.read(t).then(U=>{if(!v)if(U){const{id:L,...K}=U;o(K),u(K.design?"design":"code"),x($=>$+1)}else b(a("Failed to read content"))}).finally(()=>{v||f(!1)}),()=>{v=!0}},[t,a]);const D=v=>o(U=>({...U,...v})),k=(v,U)=>D({args:r.args.map((L,K)=>K===v?{...L,...U}:L)}),O=v=>D({design:v,script:bi(v)}),E=v=>{v!==r.script&&(r.design&&(h.current=r.design),o(U=>({...U,script:v,design:void 0})))},M=async()=>{w(!0);const v=await Df(r.script);if(w(!1),!v.ok){b(a("Format failed: {{error}}",{error:v.error}));return}b(null),v.code!==r.script&&(E(v.code),x(U=>U+1))},A=!r.design||Tf(r.design)!==null,F=!c&&!l&&r.name.trim()!==""&&r.description.trim()!==""&&A&&r.script.trim()!=="",V=async()=>{if(!F||t===null)return;p(!0);const v=await window.electronAPI.workflowPresets.save({...r,args:qf(r.args)},t==="new"?void 0:t);if(p(!1),!v.ok){b(a(v.error));return}n(),s()};return e.jsx(fe,{open:t!==null,onOpenChange:v=>!v&&s(),children:e.jsxs(ge,{className:"max-w-4xl",children:[e.jsx(je,{children:e.jsx(ve,{children:a(t==="new"?"Add workflow preset":"Edit workflow preset")})}),e.jsxs(we,{className:"space-y-4",children:[e.jsxs(ue,{children:[e.jsx(me,{children:a("Name")}),e.jsx(Y,{value:r.name,onChange:v=>D({name:v.target.value})})]}),e.jsxs(ue,{children:[e.jsx(me,{children:a("Description")}),e.jsx(Y,{value:r.description,onChange:v=>D({description:v.target.value})})]}),e.jsxs(ue,{children:[e.jsx(me,{children:a("Arguments")}),e.jsxs("div",{className:"w-full space-y-1.5",children:[r.args.map((v,U)=>e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Y,{size:"sm",className:"w-28 font-mono",placeholder:"key",value:v.key,onChange:L=>k(U,{key:L.target.value})}),e.jsx(Y,{size:"sm",className:"flex-1",placeholder:a("Label"),value:v.label,onChange:L=>k(U,{label:L.target.value})}),e.jsx(Y,{size:"sm",className:"flex-1",placeholder:a("Default value"),value:v.default??"",onChange:L=>k(U,{default:L.target.value})}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1 text-muted-foreground text-xs",children:[e.jsx(Je,{checked:v.required===!0,onCheckedChange:L=>k(U,{required:L===!0})}),a("Required")]}),e.jsx(I,{variant:"ghost",size:"icon-xs","aria-label":a("Remove"),onClick:()=>D({args:r.args.filter((L,K)=>K!==U)}),children:e.jsx(Ct,{})})]},U)),e.jsxs(I,{variant:"outline",size:"xs",disabled:r.args.length>=8,onClick:()=>D({args:[...r.args,{key:"",label:""}]}),children:[e.jsx(Te,{}),a("Add argument")]})]})]}),e.jsxs(ue,{children:[e.jsxs("div",{className:"flex w-full items-center justify-between gap-2",children:[e.jsx(me,{children:a("Steps")}),i==="code"&&e.jsxs(I,{variant:"ghost",size:"xs",className:"ml-auto",disabled:c||g||!!r.design||!r.script.trim(),title:r.design?a("Generated code is already formatted"):void 0,onClick:M,children:[g?e.jsx(Pe,{className:"animate-spin"}):e.jsx(wd,{}),a("Format")]}),e.jsx(zt,{value:i,onValueChange:v=>u(v),children:e.jsxs(Bt,{children:[e.jsx(Ke,{value:"design",children:a("Design")}),e.jsx(Ke,{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(Pe,{className:"h-4 w-4 animate-spin text-muted-foreground"})}):i==="design"?r.design?e.jsx(Kf,{design:r.design,agentTypes:S,args:r.args,onChange:O}):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(I,{variant:"outline",size:"xs",onClick:()=>O(h.current??jn),children:a("Use the designer")})]}):e.jsx(ci,{fileName:"workflow.js",className:"h-80",value:r.script,epoch:d,onChange:E}),e.jsx("p",{className:"text-muted-foreground text-xs",children:i==="design"?!A&&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.")})]}),C&&e.jsxs("p",{className:"flex items-center gap-1.5 text-destructive text-xs",children:[e.jsx(St,{className:"h-3.5 w-3.5 shrink-0"}),C]})]}),e.jsxs(Ie,{children:[e.jsx(I,{variant:"outline",size:"sm",onClick:s,children:a("Cancel")}),e.jsxs(I,{size:"sm",disabled:!F,onClick:V,children:[l&&e.jsx(Pe,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}),a("Save")]})]})]})})}function Hf(){const{t}=z(),[s,n]=m.useState([]),[a,r]=m.useState(null),o=j(h=>h.disabledWorkflowPresets),i=j(h=>h.toggleWorkflowPreset),u=m.useCallback(()=>{window.electronAPI.workflowPresets.list().then(n)},[]);m.useEffect(u,[u]);const d=s.filter(h=>h.source!=="builtin"),x=s.filter(h=>h.source==="builtin");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-end justify-between gap-4","data-settings-row":"workflows.root",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-medium text-lg",children:t("Workflows")}),e.jsx("p",{className:"text-muted-foreground text-sm",children:t("Preset workflows you can run from the Workflow side panel")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Project .agents/workflows files take precedence over these; ~/.agents/workflows and built-in presets come after.")})]}),e.jsxs(I,{variant:"outline",size:"sm",onClick:()=>r("new"),children:[e.jsx(Te,{className:"mr-1.5 h-4 w-4"}),t("Add workflow preset")]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium text-muted-foreground text-xs",children:t("Custom presets")}),d.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx(On,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:t("No custom workflow presets yet")})]}):e.jsx("div",{className:"space-y-1",children:d.map(h=>e.jsxs("div",{className:"group flex items-center justify-between gap-3 rounded-md px-3 py-2 transition-colors hover:bg-accent/50","data-settings-row":`workflows.${h.id}`,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium text-sm",children:h.name}),e.jsx(te,{variant:"secondary",className:"shrink-0 font-mono text-[11px]",children:h.id})]}),e.jsx("p",{className:"truncate text-muted-foreground text-xs",children:h.description})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(I,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100","aria-label":t("Edit"),onClick:()=>r(h.id),children:e.jsx(it,{className:"h-3.5 w-3.5"})}),e.jsx(I,{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":t("Delete"),onClick:()=>{window.electronAPI.workflowPresets.delete(h.id).then(u)},children:e.jsx(Ee,{className:"h-3.5 w-3.5"})})]})]},h.id))})]}),x.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium text-muted-foreground text-xs",children:t("Built-in presets")}),e.jsx("div",{className:"space-y-1",children:x.map(h=>e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md px-3 py-2 transition-colors hover:bg-accent/50","data-settings-row":`workflows.builtin.${h.id}`,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium text-sm",children:t(h.name)}),e.jsx(te,{variant:"secondary",className:"shrink-0 font-mono text-[11px]",children:h.id})]}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t(h.description)}),h.args.length>0&&e.jsxs("p",{className:"mt-0.5 text-muted-foreground text-xs",children:[t("Arguments"),":"," ",h.args.map(c=>`${t(c.label)}${c.required?" *":""}`).join(" · ")]})]}),e.jsx(le,{"aria-label":t(h.name),checked:!o.includes(h.id),onCheckedChange:c=>i(h.id,c)})]},h.id))})]}),e.jsx(Gf,{target:a,onClose:()=>r(null),onSaved:u})]})}function Wf(t){window.requestAnimationFrame(()=>{const s=document.querySelector(`[data-settings-row="${CSS.escape(t)}"]`);s instanceof HTMLElement&&(s.scrollIntoView({block:"center"}),s.dataset.settingsFlash="true",window.setTimeout(()=>{delete s.dataset.settingsFlash},1600))})}function Jr(){const{t}=z(),[s,n]=m.useState("general"),[a,r]=m.useState(null),[o,i]=m.useState(null),[u,d]=m.useState(null),[x,h]=m.useState(0),c=Nd(),[f,l]=m.useState(!0),[p,g]=m.useState(""),[w,C]=m.useState([]),b=K=>{n(K),l(!1)},N=j(K=>K.disabledBuiltinTools),y=j(K=>K.botModeEnabled),S=m.useSyncExternalStore(K=>j.persist?.onFinishHydration?.(K)??(()=>{}),()=>j.persist?.hasHydrated?.()??!0),D=m.useCallback(K=>{n(K.category),l(!1),r(K.rowId),K.pluginInstallUrl&&i(K.pluginInstallUrl),d(K.pluginId??null)},[]);m.useEffect(()=>(window.electronAPI.window.consumeSettingsDeepLink().then(K=>{K&&D(K)}),window.electronAPI.window.onSettingsDeepLink(D)),[D]),m.useEffect(()=>{let K=!0;return window.electronAPI.sshConnections.list().then($=>{K&&C($.map(G=>({id:G.id,name:G.name})))}).catch(()=>{K&&C([])}),()=>{K=!1}},[]);const k=kd(w);m.useLayoutEffect(()=>{if(!a)return;Wf(a);const K=window.setTimeout(()=>r(null),1600);return()=>window.clearTimeout(K)},[a]);const E=Yp([{id:"general",icon:Ed,label:"General"},{id:"shortcuts",icon:Md,label:"Shortcuts"},{id:"voice",icon:Pd,label:"Voice input"},{id:"appearance",icon:xu,label:"Appearance"},{id:"providers",icon:zn,label:"Model Providers"},{id:"presets",icon:Td,label:"Presets"},{id:"agents",icon:Rd,label:"Agent types"},{id:"tools",icon:yo,label:"Built-in tools"},{id:"workflows",icon:On,label:"Workflows"},{id:"memory",icon:vo,label:"Memory"},{id:"privacy",icon:Od,label:"Privacy"},{id:"skills",icon:_n,label:"Skills"},{id:"plugins",icon:Lt,label:"Enso plugins"},{id:"claudePlugins",icon:Hd,label:"Claude Code plugins"},{id:"mcp",icon:Co,label:"MCP Servers"},{id:"instructions",icon:Dn,label:"Instruction Files"},{id:"phone",icon:on,label:"Devices"},{id:"ssh",icon:co,label:"SSH"},{id:"usage",icon:Zd,label:"Usage"},{id:"resources",icon:Dd,label:"Resources"},{id:"experimental",icon:Ld,label:"Experimental"},{id:"bots",icon:zd,label:"Bot mode",sub:!0},{id:"botTemplates",icon:Bd,label:"Bot templates",sub:!0}],N,y),M=Wp(Qp(E,k,p,t)),A=Jp(s,N,y||!S);m.useEffect(()=>{A!==s&&n(A)},[A,s]);const F=!c||f,V=!c||!f,v=E.find(K=>K.id===s)?.label,U=Cd(),L=Vo();return e.jsxs("div",{className:"flex h-full w-full",children:[F&&e.jsxs("nav",{"data-enso":"settings-nav",className:H("flex min-h-0 shrink-0 flex-col",c?"w-full":U?"w-56":"w-56 border-r"),children:[U&&L==="mac"&&e.jsx("div",{"aria-hidden":!0,className:"drag-region -mb-2 h-[44px] shrink-0"}),e.jsx("div",{className:H("sticky top-0 z-10 px-2 pt-2",!U&&"bg-background"),children:e.jsxs("div",{className:"relative",children:[e.jsx(bo,{className:"pointer-events-none absolute top-1/2 left-2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),e.jsx("input",{value:p,onChange:K=>g(K.target.value),onKeyDown:K=>{K.key!=="Escape"||p.length===0||(K.preventDefault(),K.stopPropagation(),g(""))},placeholder:t("Search settings"),className:"h-8 w-full rounded-md border bg-transparent pr-2 pl-7 text-sm outline-none placeholder:text-muted-foreground focus-visible:ring-2 focus-visible:ring-ring"})]})}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto p-2",children:p.trim()&&M.length===0?e.jsx("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:t("No results")}):M.map((K,$)=>e.jsxs("div",{className:H($>0&&"mt-4"),children:[e.jsx("div",{className:"px-2 pb-1.5 text-xs font-semibold text-foreground/55",children:t(K.label)}),e.jsx("div",{className:"space-y-0.5 rounded-lg bg-muted/60 p-1",children:K.items.map(G=>e.jsxs("div",{children:[e.jsxs("button",{type:"button",onClick:()=>b(G.id),className:H("flex w-full items-center gap-2 rounded-md px-3 text-sm transition-colors",c?"py-3":"py-1.5",G.sub&&"pl-8",s===G.id&&!c?"bg-background text-foreground shadow-xs":"text-muted-foreground hover:bg-background/60 hover:text-foreground"),children:[e.jsx(G.icon,{className:"h-4 w-4"}),t(G.label),c&&e.jsx(At,{className:"ml-auto h-4 w-4 opacity-60"})]}),G.hits.map(X=>e.jsx("button",{type:"button",onClick:()=>{b(G.id),r(X.id)},className:H("block w-full truncate rounded-md pr-3 text-left text-xs text-muted-foreground hover:bg-background/60 hover:text-foreground",G.sub?"pl-14":"pl-9",c?"py-2":"py-1"),children:t(X.title)},X.id))]},G.id))})]},K.id))})]}),V&&e.jsxs("div",{"data-enso":"settings-content",className:H("flex min-w-0 flex-1 flex-col",U&&"my-[8px] mr-[8px] overflow-hidden rounded-[10px] bg-background shadow-surface"),children:[U&&e.jsx(Sd,{"data-enso":"title-bar"}),e.jsxs("div",{className:H("min-h-0 flex-1 overflow-y-auto",c?"px-4 pb-6":U?"px-6 pb-6":"p-6"),children:[c&&e.jsxs("button",{type:"button",onClick:()=>l(!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(mo,{className:"h-5 w-5 text-muted-foreground"}),v?t(v):null]}),s==="general"&&e.jsx(rm,{}),s==="shortcuts"&&e.jsx(Fh,{}),s==="appearance"&&e.jsx(Rm,{onOpenPlugins:()=>b("plugins")}),s==="providers"&&e.jsx(Pp,{}),s==="skills"&&e.jsx(Vp,{}),s==="plugins"&&e.jsx(dp,{requestedInstallUrl:o,onRequestedInstallUrlConsumed:()=>i(null),focusPluginId:u,onFocusPluginConsumed:()=>d(null)}),s==="claudePlugins"&&e.jsx(hp,{}),s==="mcp"&&e.jsx(lx,{}),s==="instructions"&&e.jsx(_h,{}),s==="presets"&&e.jsx(Id,{}),s==="agents"&&e.jsx(Ad,{}),s==="workflows"&&e.jsx(Hf,{}),s==="tools"&&e.jsx(ah,{}),s==="memory"&&e.jsxs("div",{className:"space-y-8",children:[e.jsx(Yx,{onLibraryChanged:()=>h(K=>K+1)}),e.jsx(Sx,{revision:x}),e.jsx(Dx,{revision:x})]}),s==="phone"&&e.jsx(Ph,{}),s==="ssh"&&e.jsx(Kp,{}),s==="usage"&&e.jsx(xf,{}),s==="privacy"&&e.jsx(bp,{}),s==="resources"&&e.jsx(Bp,{}),s==="voice"&&e.jsx(yf,{}),s==="experimental"&&e.jsx(zh,{onOpenBots:()=>n("bots")}),s==="bots"&&e.jsx(Fm,{}),s==="botTemplates"&&e.jsx(Wm,{})]})]})]})}_d();Fd();function Yf(){const{t}=z(),s=Vo();return s!=="mobile"&&s!=="web"?e.jsxs("div",{"data-enso":"canvas",className:"flex h-screen overflow-hidden bg-canvas",children:[e.jsx(fa,{}),e.jsx($d.Provider,{value:{trailing:e.jsxs(e.Fragment,{children:[e.jsx(ga,{label:!1}),e.jsx(Vd,{kind:s,edgeGap:8})]})},children:e.jsx(Jr,{})}),e.jsx(ja,{})]}):e.jsxs("div",{className:"flex h-screen flex-col overflow-hidden",children:[e.jsx(fa,{}),e.jsx(Kd,{title:t("Settings"),actions:e.jsxs(e.Fragment,{children:[e.jsx(ga,{label:!1}),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":t("Close"),title:t("Close"),children:e.jsx(Ct,{className:"h-4 w-4"})})]})}),e.jsx("main",{className:"min-h-0 flex-1 overflow-hidden",children:e.jsx(Jr,{})}),e.jsx(ja,{})]})}Ud.createRoot(document.getElementById("root")).render(e.jsx(m.StrictMode,{children:e.jsx(Yf,{})}));
|