decocms 3.34.0 → 3.34.1
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/dist/client/assets/{AlertCircle-CZCJdLyi.js → AlertCircle-rpaL6q8T.js} +1 -1
- package/dist/client/assets/{ArrowUpRight-CHxGqtjn.js → ArrowUpRight-D7_4FAQ5.js} +1 -1
- package/dist/client/assets/{Check-DZFgb4Aq.js → Check-6LmIKXJj.js} +1 -1
- package/dist/client/assets/{CheckCircle-CG-wMven.js → CheckCircle-D0kUlRsN.js} +1 -1
- package/dist/client/assets/{ChevronDown-B7QgMo_j.js → ChevronDown-CaCYdoie.js} +1 -1
- package/dist/client/assets/{ChevronLeft-TMVSDJlu.js → ChevronLeft-BuXkBFIm.js} +1 -1
- package/dist/client/assets/{ChevronRight-BZDLAZs0.js → ChevronRight-kLRVkGUs.js} +1 -1
- package/dist/client/assets/{ChevronUp-D4NcsGJa.js → ChevronUp-DkGtzqyl.js} +1 -1
- package/dist/client/assets/{Container-CIoK_JLI.js → Container-Bl0qWNtu.js} +1 -1
- package/dist/client/assets/{DotsVertical-BTWgDSCZ.js → DotsVertical-CvhOKI-w.js} +1 -1
- package/dist/client/assets/{Eye-BaBZSaML.js → Eye-BNS1RmzG.js} +1 -1
- package/dist/client/assets/{FilterLines-CuEfbFlC.js → FilterLines-BSmtfAHG.js} +1 -1
- package/dist/client/assets/{Globe01-Bu-3l6NI.js → Globe01-DjWlKHom.js} +1 -1
- package/dist/client/assets/{HardDrive-FmjuSfEd.js → HardDrive-Dx3Blqhn.js} +1 -1
- package/dist/client/assets/{Key01-Bnc16AFY.js → Key01-D6jyUgYu.js} +1 -1
- package/dist/client/assets/{LayoutLeft-D2epCZ9e.js → LayoutLeft-C7Cmt2J8.js} +1 -1
- package/dist/client/assets/{LinkExternal01-il-vFJO5.js → LinkExternal01-B6flmd1s.js} +1 -1
- package/dist/client/assets/{Monitor01-s9F0MGZm.js → Monitor01-DBfOkkx9.js} +1 -1
- package/dist/client/assets/{Palette-BXG1B7a_.js → Palette-BX6fdd-v.js} +1 -1
- package/dist/client/assets/{Play-CArhP18b.js → Play-DApzrsBx.js} +1 -1
- package/dist/client/assets/{Plus-BMFN7EYn.js → Plus-Do6ZWheh.js} +1 -1
- package/dist/client/assets/{RefreshCcw01-CKC-7KpZ.js → RefreshCcw01-CW918RSV.js} +1 -1
- package/dist/client/assets/{SearchMd-Cp07lkq4.js → SearchMd-B4Lavo8e.js} +1 -1
- package/dist/client/assets/{Settings02-D4_HBk9b.js → Settings02-B57k_aEv.js} +1 -1
- package/dist/client/assets/{Shield01-C5CB9ixt.js → Shield01-CFDfVqiL.js} +1 -1
- package/dist/client/assets/{Star01-B5uhWV3B.js → Star01-QoJ-qcfh.js} +1 -1
- package/dist/client/assets/{Stars01-Bbj7Y0Z1.js → Stars01-ANwy09AP.js} +1 -1
- package/dist/client/assets/{Stars02-KpOwsvid.js → Stars02-C17u9BVa.js} +1 -1
- package/dist/client/assets/{Sun-BAloSVhR.js → Sun-D4yzlyEv.js} +1 -1
- package/dist/client/assets/{SwitchHorizontal01-Cu45oyoo.js → SwitchHorizontal01-CkwE98n9.js} +1 -1
- package/dist/client/assets/{Tool01-41oNA8tk.js → Tool01-B0zT3ots.js} +1 -1
- package/dist/client/assets/{Trash01-BxDpcA3C.js → Trash01-Bifm5Wb3.js} +1 -1
- package/dist/client/assets/{Upload01-D32r7qgX.js → Upload01-mjA8r4Fi.js} +1 -1
- package/dist/client/assets/{User01-jR83WsDH.js → User01-BZL6tFVt.js} +1 -1
- package/dist/client/assets/{Users01-BBxMW_TC.js → Users01-CqVfleMx.js} +1 -1
- package/dist/client/assets/{Users03-BLIawTyD.js → Users03-C5i2CKOP.js} +1 -1
- package/dist/client/assets/{X-D5a6VwmP.js → X-BWR0-4rz.js} +1 -1
- package/dist/client/assets/{XCircle-uxFEtClP.js → XCircle-CiiIVhRh.js} +1 -1
- package/dist/client/assets/{XClose-DutYcJf9.js → XClose-D0wmxYTF.js} +1 -1
- package/dist/client/assets/{Zap-Dn5qc0WK.js → Zap-BGp3QjmM.js} +1 -1
- package/dist/client/assets/{ZapSquare-rlEq1cG8.js → ZapSquare-CxE5iHdd.js} +1 -1
- package/dist/client/assets/{ZoomOut-BVY1Bb5M.js → ZoomOut-B1VNHI1K.js} +1 -1
- package/dist/client/assets/{access-gate-BG1y9Hug.js → access-gate-BELP4oqa.js} +1 -1
- package/dist/client/assets/{accordion-Dzk41U9r.js → accordion-Dsx4jZXX.js} +1 -1
- package/dist/client/assets/{add-section-modal-DsL7vxG4.js → add-section-modal-BPiyATcO.js} +1 -1
- package/dist/client/assets/agent-capabilities-CmHO-Kgo.js +3 -0
- package/dist/client/assets/{agent-icon-eJeBIKuQ.js → agent-icon-CpBAbwoh.js} +1 -1
- package/dist/client/assets/{agent-icons-BQS7GC08.js → agent-icons-C_pHQRgk.js} +1 -1
- package/dist/client/assets/{agents-list-BuzrDWIw.js → agents-list-ud8B7XUs.js} +1 -1
- package/dist/client/assets/{ai-providers-CVvDeHAY.js → ai-providers-DuT9vieJ.js} +1 -1
- package/dist/client/assets/{alert-B7wpmBJc.js → alert-C_aVuLV8.js} +1 -1
- package/dist/client/assets/{alert-dialog-D0THW25_.js → alert-dialog-Dsb6KPFM.js} +1 -1
- package/dist/client/assets/app-editor-CJE_W_Dn.js +1 -0
- package/dist/client/assets/{auth-catchall-B9qDAn3E.js → auth-catchall-DsJQjIZu.js} +1 -1
- package/dist/client/assets/{auth-split-layout-B_xfyQiq.js → auth-split-layout-BBz1-8cc.js} +1 -1
- package/dist/client/assets/{automation-list-row-D582neu3.js → automation-list-row-DTcrDIUh.js} +1 -1
- package/dist/client/assets/{automation-runs-Bbg-0UVN.js → automation-runs-D8yf4pum.js} +1 -1
- package/dist/client/assets/{automations-CocDDisF.js → automations-BqoqwiaS.js} +1 -1
- package/dist/client/assets/{avatar-BWTRU-cH.js → avatar-nCSKoB6F.js} +1 -1
- package/dist/client/assets/{badge-DAzOgiKc.js → badge-CY1rqnYU.js} +1 -1
- package/dist/client/assets/{brand-context-BxzBhuxy.js → brand-context-DCIkJfS8.js} +1 -1
- package/dist/client/assets/{buckets-OgmEkXt4.js → buckets-CvxCU-Mg.js} +1 -1
- package/dist/client/assets/{calendar-CTsGuWmk.js → calendar-vde5tCHf.js} +1 -1
- package/dist/client/assets/{capability-load-error-B6TBCUEJ.js → capability-load-error-DYWpzVHl.js} +1 -1
- package/dist/client/assets/{card-D4pgDcd2.js → card-CYGsSb57.js} +1 -1
- package/dist/client/assets/{chat-context-DLsfZ4X8.js → chat-context-CDygsN4Q.js} +1 -1
- package/dist/client/assets/{checkbox-NCgkpQdG.js → checkbox-vKl7eadT.js} +1 -1
- package/dist/client/assets/{cli-auth-success-Cg7MVUxb.js → cli-auth-success-BgBSOhsv.js} +1 -1
- package/dist/client/assets/{collection-detail-BTIBM7UV.js → collection-detail-Cl0_mdap.js} +1 -1
- package/dist/client/assets/{collection-display-button-BD_cZwBu.js → collection-display-button-VpCmWGot.js} +1 -1
- package/dist/client/assets/{collection-search-FDG1Rlpn.js → collection-search-CjkYy_AH.js} +1 -1
- package/dist/client/assets/{collection-table-wrapper-CLs6D3Gl.js → collection-table-wrapper-CuUrD2rg.js} +1 -1
- package/dist/client/assets/{collection-tabs-pv_RnATY.js → collection-tabs-BGsvaOVA.js} +1 -1
- package/dist/client/assets/{collections-2LTOAuNh.js → collections-NCEoL2EX.js} +1 -1
- package/dist/client/assets/{command-Eg_TSNDN.js → command-KCI9wvsu.js} +1 -1
- package/dist/client/assets/{connect-desktop-dialog-BfZ9n3Q0.js → connect-desktop-dialog-CgeQRUKM.js} +1 -1
- package/dist/client/assets/{connection-card-CBcUqWOS.js → connection-card-BioQsepZ.js} +1 -1
- package/dist/client/assets/{connection-detail-CLOt0X5i.js → connection-detail-szcerrZK.js} +1 -1
- package/dist/client/assets/{connection-form-helpers-DQ1R8Rbb.js → connection-form-helpers-DC_9yJsF.js} +1 -1
- package/dist/client/assets/{connections-anSV4FAS.js → connections-ZTcaOmQJ.js} +1 -1
- package/dist/client/assets/decopilot-sse-pool-C2fCSDxg.js +1 -0
- package/dist/client/assets/{dialog-GbkSCCDE.js → dialog-CxpeEAA2.js} +1 -1
- package/dist/client/assets/{domain-settings-CfTQTVXk.js → domain-settings-FkOLC-vc.js} +1 -1
- package/dist/client/assets/{drawer-CDEJbPQ_.js → drawer-R-Q-vfsa.js} +1 -1
- package/dist/client/assets/{dropdown-menu-Bp4U1b45.js → dropdown-menu-Xj0lVIXK.js} +1 -1
- package/dist/client/assets/{dynamic-plugin-layout-BwhGs18I.js → dynamic-plugin-layout-ggJeSS9L.js} +1 -1
- package/dist/client/assets/{empty-state-B8atRyt1.js → empty-state-BEE0EBKQ.js} +1 -1
- package/dist/client/assets/{empty-state-v8piTmBi.js → empty-state-BhV-zl-f.js} +1 -1
- package/dist/client/assets/{extract-connection-data-CWzL0whb.js → extract-connection-data-BJ4lD3eO.js} +1 -1
- package/dist/client/assets/{features-DqRtKUxF.js → features-2oa5PE-D.js} +1 -1
- package/dist/client/assets/{file-explorer-COzE78zi.js → file-explorer-mkpu5feK.js} +1 -1
- package/dist/client/assets/{file-type-icon-CrGaQHZH.js → file-type-icon-35VBMVCk.js} +1 -1
- package/dist/client/assets/{files-DcXaeN54.js → files-C37GYe47.js} +1 -1
- package/dist/client/assets/{form-Ct1q5ZTT.js → form-Ci8PGt-R.js} +1 -1
- package/dist/client/assets/{general-6k9CLiVk.js → general-NmglolSe.js} +1 -1
- package/dist/client/assets/{generate-id-Ck2Vi4il.js → generate-id-nWw_PZwJ.js} +1 -1
- package/dist/client/assets/{github-repo-picker-Dh-z3MS6.js → github-repo-picker-DY4w_1I0.js} +1 -1
- package/dist/client/assets/{header-tab-button-TaP3yUvX.js → header-tab-button-C7XZ27Uv.js} +1 -1
- package/dist/client/assets/{hover-card-DUG7qFNS.js → hover-card-DY9PmUZF.js} +1 -1
- package/dist/client/assets/{image-field-BvfbFQCq.js → image-field-DXfNSgLy.js} +1 -1
- package/dist/client/assets/{index-2GwD8zs9.js → index-61WbL3ye.js} +1 -1
- package/dist/client/assets/{index-C4S4NH7_.js → index-BEe1oLVg.js} +1 -1
- package/dist/client/assets/{index-CH5_jbBh.js → index-BToBsTv0.js} +1 -1
- package/dist/client/assets/{index-DUFETPUS.js → index-BvKb9qza.js} +1 -1
- package/dist/client/assets/{index-BG09-Pj6.js → index-Czr8nkWj.js} +1 -1
- package/dist/client/assets/{index-Bg77DGkv.js → index-D9SSFpE5.js} +1 -1
- package/dist/client/assets/{index-C99xN5mu.js → index-DO3UwA_I.js} +1 -1
- package/dist/client/assets/{index-Ca_51Bdz.js → index-DUiGV32e.js} +1 -1
- package/dist/client/assets/{index-D7JjC_Ha.js → index-Dczuf3at.js} +1 -1
- package/dist/client/assets/{index-EWthEHT2.js → index-DppjWA7O.js} +1 -1
- package/dist/client/assets/{index-BQjtT112.js → index-Rf_PdJ5z.js} +1 -1
- package/dist/client/assets/{index-Bo0y-IeN.js → index-So-S11eP.js} +1 -1
- package/dist/client/assets/{index-DrZPYOCw.js → index-czuYZ_ID.js} +1 -1
- package/dist/client/assets/{index-DvjfZyh_.js → index-rZ1TPVyD.js} +3 -3
- package/dist/client/assets/{index-redirect-BQdYxzJo.js → index-redirect-Mq-_t69h.js} +1 -1
- package/dist/client/assets/{index-BwfKFYWi.js → index-u2XUNnQk.js} +12 -12
- package/dist/client/assets/{input-irp5a6Ig.js → input-BPXWlz46.js} +1 -1
- package/dist/client/assets/{integration-icon-FcIrg4H7.js → integration-icon-CWT0gSfx.js} +1 -1
- package/dist/client/assets/{label-BjwEjfOc.js → label-CzVCjiiL.js} +1 -1
- package/dist/client/assets/{layout-s4c1VBr3.js → layout-DRDhyVmm.js} +1 -1
- package/dist/client/assets/{login-DvesO_NT.js → login-BDymjDs5.js} +1 -1
- package/dist/client/assets/{members-C60Aey5n.js → members-CtJP3l4D.js} +1 -1
- package/dist/client/assets/{monaco-editor-CIyIIOLP.js → monaco-editor-C-H4UmIT.js} +1 -1
- package/dist/client/assets/{monitoring-stats-row-B8f5t9as.js → monitoring-stats-row-Bjwv0PCc.js} +1 -1
- package/dist/client/assets/{oauth-callback-BHpZxMn4.js → oauth-callback-BS0_f_H5.js} +1 -1
- package/dist/client/assets/{oauth-callback-ai-provider-BsfNZx3Q.js → oauth-callback-ai-provider-Bp-Z15lU.js} +1 -1
- package/dist/client/assets/{onboarding-B2qJIBXT.js → onboarding-tR6ID9Ba.js} +1 -1
- package/dist/client/assets/{org-install-D8vuUVF_.js → org-install-Dao8BW5b.js} +1 -1
- package/dist/client/assets/{org-layout-BlXjXW59.js → org-layout-3WhlK4a0.js} +1 -1
- package/dist/client/assets/{org-plugin-layout-CX3CIxiU.js → org-plugin-layout-C-NqJRXX.js} +1 -1
- package/dist/client/assets/{page-seo-form-Bj1ei9Gv.js → page-seo-form-Dk6e77BM.js} +1 -1
- package/dist/client/assets/page-seo-sheet-Ceb0gnAp.js +1 -0
- package/dist/client/assets/{pair-QNI_4vE-.js → pair-DYb6YfcG.js} +1 -1
- package/dist/client/assets/{plugin-empty-state-BxAyfpRL.js → plugin-empty-state-YbbYO5hU.js} +1 -1
- package/dist/client/assets/{plugin-header-BmTvDEmx.js → plugin-header-8P4QiIoH.js} +1 -1
- package/dist/client/assets/{plugin-layout-AAC2IROJ.js → plugin-layout-CKmZivzq.js} +1 -1
- package/dist/client/assets/{popover-DKADBzsx.js → popover-Bk3EwUPD.js} +1 -1
- package/dist/client/assets/{post-editor-Dkob_Nf9.js → post-editor-Bw21I9pc.js} +1 -1
- package/dist/client/assets/{primitives-BD_skIF2.js → primitives-Dql_hUCU.js} +1 -1
- package/dist/client/assets/{profile-B7jiHx0p.js → profile-DVNKZaX-.js} +1 -1
- package/dist/client/assets/project-app-view-CMCeiidr.js +1 -0
- package/dist/client/assets/record-editor-803FPqaV.js +1 -0
- package/dist/client/assets/registry-BZxoTJql.js +2 -0
- package/dist/client/assets/{registry-layout-CyYeZQFC.js → registry-layout-DwX4dFWX.js} +1 -1
- package/dist/client/assets/{require-capability-D2k7Kzha.js → require-capability-6kSOKhdT.js} +1 -1
- package/dist/client/assets/{required-auth-layout-Dlm8pGwG.js → required-auth-layout-YEZh9H2w.js} +1 -1
- package/dist/client/assets/{reset-password-Bj1irBT9.js → reset-password-DaCJM4Eh.js} +1 -1
- package/dist/client/assets/{resizable-CflvFHn-.js → resizable-23UTrxEL.js} +1 -1
- package/dist/client/assets/{roles-C-0y_YIa.js → roles-xmvI7O0C.js} +1 -1
- package/dist/client/assets/save-referenced-block-CMYI5Fv0.js +1 -0
- package/dist/client/assets/{save-status-BT2K7vMi.js → save-status-BkzFYIeb.js} +1 -1
- package/dist/client/assets/{schema-form-BmsIuFe9.js → schema-form-DNaVud8y.js} +1 -1
- package/dist/client/assets/{scroll-area-Bcd6M0ah.js → scroll-area-QXSqgT3C.js} +1 -1
- package/dist/client/assets/{search-input-DMce5FEj.js → search-input-DbmU5zU8.js} +1 -1
- package/dist/client/assets/{secrets-DFqTlIhT.js → secrets-CrK7EU6I.js} +1 -1
- package/dist/client/assets/{sections-editor-DPjqmRcC.js → sections-editor-DJ6-AL_q.js} +1 -1
- package/dist/client/assets/{select-DBJdJQxs.js → select-DRqZIuLQ.js} +1 -1
- package/dist/client/assets/{select-model-C6zKg0NG.js → select-model-CZe_eVYF.js} +1 -1
- package/dist/client/assets/{seo-editor-70uW1Cgu.js → seo-editor-pRBB6PMK.js} +1 -1
- package/dist/client/assets/{settings-layout-BL3d6TJ_.js → settings-layout-osjNi_Qw.js} +1 -1
- package/dist/client/assets/{settings-section-C7OUTn7i.js → settings-section-5LNAbhU4.js} +1 -1
- package/dist/client/assets/{sheet-BwH8pS-i.js → sheet-Dsfk9URc.js} +1 -1
- package/dist/client/assets/{shell-controls-CMgf8y54.js → shell-controls-BvG0M9XK.js} +1 -1
- package/dist/client/assets/{shell-layout-C6cd7iM5.js → shell-layout-DkW3B_MZ.js} +1 -1
- package/dist/client/assets/shell-route-loading-CKElD_Av.js +1 -0
- package/dist/client/assets/{sidebar-TMNnGTum.js → sidebar-B3SsvTHC.js} +1 -1
- package/dist/client/assets/{skeleton-l4y2bxXO.js → skeleton-DvVUqja_.js} +1 -1
- package/dist/client/assets/sortable.esm-CnPAeADV.js +5 -0
- package/dist/client/assets/{spinner-BtGInCsG.js → spinner-DZmgr2qu.js} +1 -1
- package/dist/client/assets/{sso-BGAtG4Za.js → sso-Ce8-uwYP.js} +1 -1
- package/dist/client/assets/{store-C3y6O23u.js → store-Cy7UQOIx.js} +1 -1
- package/dist/client/assets/store-registry-Cn522mzq.js +2 -0
- package/dist/client/assets/{studio-tools-B1Ixjcw5.js → studio-tools-jbRVdtpc.js} +1 -1
- package/dist/client/assets/{switch-BFEJpvlr.js → switch-rL3a0x4B.js} +1 -1
- package/dist/client/assets/{tab-id-t-YFcZzw.js → tab-id-hZWLCmfc.js} +1 -1
- package/dist/client/assets/{table-M2WJKO5P.js → table-cHRXPecF.js} +1 -1
- package/dist/client/assets/{tabs-w6d9uq3S.js → tabs-B68TQ0Dt.js} +1 -1
- package/dist/client/assets/{task-status-CfFWQAcK.js → task-status-Cqn0_tco.js} +1 -1
- package/dist/client/assets/{textarea-BGXAM3FF.js → textarea-Bymi75yx.js} +1 -1
- package/dist/client/assets/{toggle-group-C4U40EOv.js → toggle-group-DnRl91Ne.js} +1 -1
- package/dist/client/assets/{toolbar-C2En0zPi.js → toolbar-Cb06hfKk.js} +1 -1
- package/dist/client/assets/{tools-list-CCVW8omn.js → tools-list-D12nTCg-.js} +1 -1
- package/dist/client/assets/{tooltip-6LKHApWj.js → tooltip-ua4lJTzI.js} +1 -1
- package/dist/client/assets/{types-CoBpfu3U.js → types-DJl0mitR.js} +1 -1
- package/dist/client/assets/{use-ai-providers-Dph4wlM9.js → use-ai-providers-P6PF7YRx.js} +1 -1
- package/dist/client/assets/{use-automations-DV8VwbjR.js → use-automations-DGe3A7k6.js} +1 -1
- package/dist/client/assets/{use-capability-CRrm1ogD.js → use-capability-B2IrzHkM.js} +1 -1
- package/dist/client/assets/{use-clock-tick-CyQ108_a.js → use-clock-tick-x-ip1-Lp.js} +1 -1
- package/dist/client/assets/{use-collections-MWh87Qf9.js → use-collections-Dvp_IbhN.js} +1 -1
- package/dist/client/assets/{use-connection-BwjVlVqI.js → use-connection-CyWLUiRu.js} +1 -1
- package/dist/client/assets/{use-copy-BDBsQ8lw.js → use-copy-nAd5EMaO.js} +1 -1
- package/dist/client/assets/{use-create-virtual-mcp--Yql-2p8.js → use-create-virtual-mcp-DmdlMapL.js} +1 -1
- package/dist/client/assets/{use-debounced-autosave-B6SxjuaG.js → use-debounced-autosave-DSZqKaTf.js} +1 -1
- package/dist/client/assets/{use-delete-connection-CE3T6gZf.js → use-delete-connection-VJfJqSrZ.js} +1 -1
- package/dist/client/assets/{use-file-configs-WBUPEX1z.js → use-file-configs-DXD_Hwrv.js} +1 -1
- package/dist/client/assets/{use-infinite-scroll-C_ORywxv.js → use-infinite-scroll-B2zyjKex.js} +1 -1
- package/dist/client/assets/{use-list-state-ZUm8O0U3.js → use-list-state-ByLS4CFA.js} +1 -1
- package/dist/client/assets/{use-mcp-client-kBcr-yIi.js → use-mcp-client-CGBZ7ekq.js} +1 -1
- package/dist/client/assets/{use-mcp-prompts-Cu_s_Tgp.js → use-mcp-prompts-BQNNtRte.js} +1 -1
- package/dist/client/assets/{use-mcp-tools-BVCosz4Y.js → use-mcp-tools-Dn2JgISP.js} +1 -1
- package/dist/client/assets/{use-members-CQwZpJh1.js → use-members-BaX0tyb1.js} +1 -1
- package/dist/client/assets/{use-navigate-to-agent-Dqwftn0z.js → use-navigate-to-agent-5w6ZqBss.js} +1 -1
- package/dist/client/assets/{use-org-auth-client-CKzivxvb.js → use-org-auth-client-CLnnUl3h.js} +1 -1
- package/dist/client/assets/{use-org-sso-CizTzcrl.js → use-org-sso-B8CLPiZl.js} +1 -1
- package/dist/client/assets/{use-organization-roles-DFIysUWU.js → use-organization-roles-UOgWPl1e.js} +1 -1
- package/dist/client/assets/{use-organization-settings-C83zobOQ.js → use-organization-settings-D68AqLOQ.js} +1 -1
- package/dist/client/assets/{use-registry-connections-D2z51tYu.js → use-registry-connections-CRtbznIm.js} +1 -1
- package/dist/client/assets/{use-secrets-DuBDIHg_.js → use-secrets--KIFsJ5I.js} +1 -1
- package/dist/client/assets/{use-status-sounds-C1N5nKtC.js → use-status-sounds-B8VUkU2E.js} +1 -1
- package/dist/client/assets/{use-view-mode-CdGJFg5T.js → use-view-mode-CvlKEBCR.js} +1 -1
- package/dist/client/assets/{use-virtual-mcp-BH7eFRNT.js → use-virtual-mcp-mhycHzLS.js} +1 -1
- package/dist/client/assets/useInfiniteQuery-k6dph5MZ.js +1 -0
- package/dist/client/assets/{useRouterState-mLoytFp1.js → useRouterState-qr3F3XJE.js} +1 -1
- package/dist/client/assets/useSuspenseInfiniteQuery-DGO3SU3a.js +1 -0
- package/dist/client/assets/{user-Bu_LWzDf.js → user-D73GXODW.js} +1 -1
- package/dist/client/assets/{view-mode-toggle-BFVBLid1.js → view-mode-toggle-3i0Tx7_t.js} +1 -1
- package/dist/client/assets/{watch-sse-pool-PpWWHENZ.js → watch-sse-pool-Bo209v56.js} +1 -1
- package/dist/client/assets/{workflow-mBb6h1mU.js → workflow-DoAXdkx8.js} +1 -1
- package/dist/client/assets/workflow-detail-BVmen01p.js +1 -0
- package/dist/client/index.html +1 -1
- package/dist/server/cli.js +1 -1
- package/package.json +1 -1
- package/dist/client/assets/agent-capabilities-BTQpzJzY.js +0 -3
- package/dist/client/assets/app-editor-mnWJa4OB.js +0 -1
- package/dist/client/assets/decopilot-sse-pool-J9IBtPGQ.js +0 -1
- package/dist/client/assets/page-seo-sheet-CAj4OnGN.js +0 -1
- package/dist/client/assets/project-app-view-Bxi1-sx3.js +0 -1
- package/dist/client/assets/record-editor-DhS1gQiJ.js +0 -1
- package/dist/client/assets/registry-CLfDV8ZJ.js +0 -2
- package/dist/client/assets/save-referenced-block-Dm8Vu_wn.js +0 -1
- package/dist/client/assets/shell-route-loading-C_Trke1w.js +0 -1
- package/dist/client/assets/sortable.esm-DzvMqAvs.js +0 -5
- package/dist/client/assets/store-registry-CTUY1_0P.js +0 -2
- package/dist/client/assets/useInfiniteQuery-DCizzYPk.js +0 -1
- package/dist/client/assets/useSuspenseInfiniteQuery-BlGj7aqQ.js +0 -1
- package/dist/client/assets/workflow-detail-GZhsuAzj.js +0 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/sections-editor-
|
|
2
|
-
import{e as K,r as E,c as he,j as n,l as Ce,q as Pe,b as Js,E as Ut,f as ts,d as $o,g as Ac,p as Bu,L as Mu,n as Zs,K as Bt,s as Lu,o as le,B as re,v as Ic,w as Ou,V as $u,t as De,x as Bc,y as zu,z as Xr,C as Bi,D as vt,F as Fu,G as Qs,H as Mc,I as Hu,J as Wu,M as Fa,P as Uu,Q as Jr,R as Ku,a as ei,T as _r,U as yi,W as Tt,_ as qt}from"./index-DvjfZyh_.js";import{C as Oe,a as Vu,u as qu,b as ti,h as Gu,w as Yu,c as Lc,d as zo,s as $n,T as Xu,e as Ju,g as Zu,f as Qu}from"./agent-capabilities-BTQpzJzY.js";import{g as Fo,u as ft,S as Oc,a as Ho}from"./use-mcp-client-kBcr-yIi.js";import{u as Mt,a as ef,b as tf,c as sf}from"./use-virtual-mcp-BH7eFRNT.js";import{a as Ns,b as ss,c as Wo,d as $c,u as rf,t as nf,e as of}from"./chat-context-DLsfZ4X8.js";import{i as Ui}from"./AlertCircle-CZCJdLyi.js";import{i as zc}from"./CheckCircle-CG-wMven.js";import{n as Ha}from"./ChevronLeft-TMVSDJlu.js";import{i as af,a as lf}from"./XCircle-uxFEtClP.js";import{s as ps}from"./XClose-DutYcJf9.js";import{c as cf,u as hf,a as Fc,O as df,t as Wa,G as uf,g as ff,s as mf,C as pf,b as _f,d as gf}from"./pair-QNI_4vE-.js";import{I as Gt}from"./integration-icon-FcIrg4H7.js";import{a as vf}from"./Users03-BLIawTyD.js";import{t as Es}from"./ChevronDown-B7QgMo_j.js";import{u as Hc}from"./use-ai-providers-Dph4wlM9.js";import{r as xf,u as Uo,i as bf}from"./shell-layout-C6cd7iM5.js";import{b as yf,a as Sf}from"./shell-route-loading-C_Trke1w.js";import{u as wf}from"./sidebar-TMNnGTum.js";import{S as Cf,a as kf,b as jf}from"./sheet-BwH8pS-i.js";import{u as Wc,T as Ee,a as Te,b as Re,c as Uc}from"./tooltip-6LKHApWj.js";import{i as Mi,a as Zr,b as Kc,c as Nf,p as Qr,g as en,d as Ko,e as Vc,h as zn,f as fn,j as Ua,A as Ka,k as Ef,l as Tf,m as Rf,n as Pf,o as Df,q as Af,t as If,r as Bf,s as Mf,u as Lf,v as tn,w as Of,x as Va,y as qa,z as $f,B as zf,C as Ff,D as Hf,E as Vo,F as Nr,G as qo,H as qc,I as Gc,J as Wf,K as Uf,L as Kf,M as Vf,N as qf,O as Ga,P as Gf,Q as Yf,R as Ei,S as Xf,T as Yc,U as Xc,V as Jf}from"./agent-icon-eJeBIKuQ.js";import{u as Zf}from"./use-status-sounds-C1N5nKtC.js";import{E as Er}from"./empty-state-v8piTmBi.js";import{u as Qf,r as Fn,a as em,p as Jc,f as Ya,b as Zc,c as Qc,d as eh,e as tm,F as sm,i as im,g as rm,h as nm,j as om}from"./tab-id-t-YFcZzw.js";import{g as si,A as am}from"./sortable.esm-DzvMqAvs.js";import{T as Xa,a as Hn}from"./toolbar-C2En0zPi.js";import{R as th,a as lm,b as cm}from"./resizable-CflvFHn-.js";import{i as Ki,n as hm}from"./Globe01-Bu-3l6NI.js";import{i as sh}from"./Monitor01-s9F0MGZm.js";import{u as Vi,a as Go,b as ih}from"./use-connection-BwjVlVqI.js";import{u as qi}from"./studio-tools-B1Ixjcw5.js";import{u as sn,a as dm,b as um}from"./use-mcp-tools-BVCosz4Y.js";import{u as fm}from"./use-capability-CRrm1ogD.js";import{F as Li,M as Yo}from"./file-type-icon-CrGaQHZH.js";import{u as mm,a as pm,b as _m,c as gm,g as vm,d as rh,e as Ja,F as xm,f as bm,h as ym,i as Sm,j as wm,k as Cm,H as km,l as jm}from"./header-tab-button-TaP3yUvX.js";import{i as Wn,a as nh,b as Nm}from"./ZoomOut-BVY1Bb5M.js";import{P as Ts,a as Rs,b as Ps}from"./popover-DKADBzsx.js";import{S as Xo}from"./spinner-BtGInCsG.js";import{D as Ds,a as As,b as Is,c as He,d as Un,e as Kn,f as Vn,g as gr}from"./dropdown-menu-Bp4U1b45.js";import{D as Lt,a as Ot,b as is,c as rs,d as ii,e as Jo}from"./dialog-GbkSCCDE.js";import{I as qe}from"./input-irp5a6Ig.js";import{T as ys,a as Zo,b as Ti,c as Qo}from"./tabs-w6d9uq3S.js";import{T as Tr}from"./textarea-BGXAM3FF.js";import{a as Qt,s as Em}from"./Eye-BaBZSaML.js";import{t as Ss}from"./Stars01-Bbj7Y0Z1.js";import{l as Tm,w as Rm}from"./index-EWthEHT2.js";import{i as Pm}from"./ChevronRight-BZDLAZs0.js";import{g as Dm}from"./generate-id-Ck2Vi4il.js";import{g as Am}from"./types-CoBpfu3U.js";import{U as oh}from"./user-Bu_LWzDf.js";import{T as Im,u as ah}from"./tools-list-CCVW8omn.js";import{s as lh,g as Bm}from"./connection-slug-eyAPH6o3.js";import{A as Rr,a as Pr,b as Dr,c as Ar,d as Ir,e as Br,f as Mr,g as Lr}from"./alert-dialog-D0THW25_.js";import{C as ch,a as qn}from"./card-D4pgDcd2.js";import{L as jt}from"./label-BjwEjfOc.js";import{S as Pt,a as Dt,b as At,c as ot,d as It}from"./select-DBJdJQxs.js";import{S as Or}from"./switch-BFEJpvlr.js";import{i as Vs}from"./Play-CArhP18b.js";import{s as xt}from"./Plus-BMFN7EYn.js";import{a as Mm}from"./Settings02-D4_HBk9b.js";import{s as qs}from"./Trash01-BxDpcA3C.js";import{u as $r}from"./use-debounced-autosave-B6SxjuaG.js";import{S as rn}from"./scroll-area-Bcd6M0ah.js";import{i as Oi}from"./SearchMd-Cp07lkq4.js";import{i as Lm}from"./Upload01-D32r7qgX.js";import{i as Om}from"./LayoutLeft-D2epCZ9e.js";import{P as Rt}from"./index-C99xN5mu.js";import{C as nn}from"./checkbox-NCgkpQdG.js";import{S as hh}from"./search-input-DMce5FEj.js";import{C as dh}from"./collection-tabs-pv_RnATY.js";import{u as $m}from"./use-mcp-prompts-Cu_s_Tgp.js";import{D as zm,a as Fm,b as Hm}from"./drawer-CDEJbPQ_.js";import{i as ri}from"./Check-DZFgb4Aq.js";import{i as ea}from"./Key01-Bnc16AFY.js";import{S as uh}from"./skeleton-l4y2bxXO.js";import{s as Wm}from"./User01-jR83WsDH.js";import{t as ta}from"./Users01-BBxMW_TC.js";import{u as Um,a as Km}from"./use-secrets-DuBDIHg_.js";import{G as Vm}from"./github-repo-picker-Dh-z3MS6.js";import{f as qm}from"./formatDistanceToNow-Cb2QZZJn.js";import{n as ni}from"./LinkExternal01-il-vFJO5.js";import{A as Gm,a as Ym,b as Xm,c as Jm}from"./accordion-Dzk41U9r.js";import{s as Gs}from"./Star01-B5uhWV3B.js";import{i as fh}from"./Stars02-KpOwsvid.js";import{V as Zm}from"./view-mode-toggle-BFVBLid1.js";import{n as mh}from"./ZapSquare-rlEq1cG8.js";import{i as sa,a as Qm,b as ia}from"./Tool01-41oNA8tk.js";import{c as ph,i as ep}from"./SwitchHorizontal01-Cu45oyoo.js";import{B as tp}from"./badge-DAzOgiKc.js";import{C as sp,a as Za,b as ip,c as rp,d as np,e as op}from"./command-Eg_TSNDN.js";import{M as ap}from"./select-model-C6zKg0NG.js";import{u as Gi,a as lp,b as cp,c as hp,d as dp}from"./use-automations-DV8VwbjR.js";import{i as _h}from"./RefreshCcw01-CKC-7KpZ.js";import{i as $i}from"./Zap-Dn5qc0WK.js";import{M as up}from"./monaco-editor-CIyIIOLP.js";import{A as fp}from"./automation-runs-Bbg-0UVN.js";import{A as mp}from"./automation-list-row-D582neu3.js";import{i as pp}from"./X-D5a6VwmP.js";function ui(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}k`:String(t)}function Qa(t){if(!t)return"—";const e=typeof t=="string"?new Date(t):t;return isNaN(e.getTime())?"—":e.toLocaleString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit"})}function _p(t){return t?t.replace(/-\d{8}(?:-[a-z0-9]+)*$/i,"").replace(/-/g," "):"—"}function gp(t){const e=K.c(4),{items:s}=t;let i;e[0]!==s?(i=s.map(vp),e[0]=s,e[1]=i):i=e[1];let r;return e[2]!==i?(r=n.jsx("div",{className:"grid grid-cols-2 gap-x-8 gap-y-6",children:i}),e[2]=i,e[3]=r):r=e[3],r}function vp(t){return n.jsxs("div",{className:"flex flex-col gap-1 min-w-0",children:[n.jsx("span",{className:"text-xs text-muted-foreground truncate",children:t.label}),n.jsx("span",{className:"text-sm text-foreground tabular-nums truncate",children:t.value})]},t.label)}function xp(t){const e=K.c(30),{userTokens:s,assistantTokens:i,otherTokens:r}=t,o=s+i+r,a=o>0?s/o*100:0,l=o>0?i/o*100:0,h=o>0?r/o*100:0;let c;e[0]!==a?(c=a>0&&n.jsx("div",{className:"h-full bg-chart-1",style:{width:`${a}%`}}),e[0]=a,e[1]=c):c=e[1];let d;e[2]!==l?(d=l>0&&n.jsx("div",{className:"h-full bg-chart-2",style:{width:`${l}%`}}),e[2]=l,e[3]=d):d=e[3];let u;e[4]!==h?(u=h>0&&n.jsx("div",{className:"h-full bg-muted-foreground/30",style:{width:`${h}%`}}),e[4]=h,e[5]=u):u=e[5];let f;e[6]!==c||e[7]!==d||e[8]!==u?(f=n.jsxs("div",{className:"flex h-2 w-full overflow-hidden rounded-full bg-muted",children:[c,d,u]}),e[6]=c,e[7]=d,e[8]=u,e[9]=f):f=e[9];let m;e[10]===Symbol.for("react.memo_cache_sentinel")?(m=n.jsx("span",{className:"inline-block h-2 w-2 rounded-sm bg-chart-1 shrink-0"}),e[10]=m):m=e[10];let p;e[11]!==a?(p=a.toFixed(1),e[11]=a,e[12]=p):p=e[12];let _;e[13]!==p?(_=n.jsxs("div",{className:"flex items-center gap-1.5",children:[m,n.jsxs("span",{className:"text-xs text-muted-foreground",children:["User ",p,"%"]})]}),e[13]=p,e[14]=_):_=e[14];let g;e[15]===Symbol.for("react.memo_cache_sentinel")?(g=n.jsx("span",{className:"inline-block h-2 w-2 rounded-sm bg-chart-2 shrink-0"}),e[15]=g):g=e[15];let v;e[16]!==l?(v=l.toFixed(1),e[16]=l,e[17]=v):v=e[17];let b;e[18]!==v?(b=n.jsxs("div",{className:"flex items-center gap-1.5",children:[g,n.jsxs("span",{className:"text-xs text-muted-foreground",children:["Assistant ",v,"%"]})]}),e[18]=v,e[19]=b):b=e[19];let x;e[20]!==h||e[21]!==r?(x=r>0&&n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("span",{className:"inline-block h-2 w-2 rounded-sm bg-muted-foreground/30 shrink-0"}),n.jsxs("span",{className:"text-xs text-muted-foreground",children:["Other ",h.toFixed(1),"%"]})]}),e[20]=h,e[21]=r,e[22]=x):x=e[22];let y;e[23]!==b||e[24]!==x||e[25]!==_?(y=n.jsxs("div",{className:"flex flex-wrap gap-x-3 gap-y-1",children:[_,b,x]}),e[23]=b,e[24]=x,e[25]=_,e[26]=y):y=e[26];let w;return e[27]!==y||e[28]!==f?(w=n.jsxs("div",{className:"flex flex-col gap-2",children:[f,y]}),e[27]=y,e[28]=f,e[29]=w):w=e[29],w}function bp(t){const e=K.c(11),{agentId:s,isError:i}=t,r=Mt(s),o=r?.title??"Subtask",a=r?.icon??null;let l;e[0]!==a||e[1]!==o?(l=n.jsx(Gt,{icon:a,name:o,size:"xs",className:"size-6 rounded-md shrink-0"}),e[0]=a,e[1]=o,e[2]=l):l=e[2];const h=i?"text-destructive":"text-foreground";let c;e[3]!==h?(c=he("shrink-0 font-medium",h),e[3]=h,e[4]=c):c=e[4];let d;e[5]!==o||e[6]!==c?(d=n.jsx("span",{className:c,children:o}),e[5]=o,e[6]=c,e[7]=d):d=e[7];let u;return e[8]!==l||e[9]!==d?(u=n.jsxs(n.Fragment,{children:[l,d]}),e[8]=l,e[9]=d,e[10]=u):u=e[10],u}function yp(t){const e=K.c(5),{isError:s}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=n.jsx(Gt,{icon:null,name:"Subtask",size:"xs",className:"size-6 rounded-md shrink-0"}),e[0]=i):i=e[0];const r=s?"text-destructive":"text-foreground";let o;e[1]!==r?(o=he("shrink-0 font-medium",r),e[1]=r,e[2]=o):o=e[2];let a;return e[3]!==o?(a=n.jsxs(n.Fragment,{children:[i,n.jsx("span",{className:o,children:"Subtask"})]}),e[3]=o,e[4]=a):a=e[4],a}function Sp(t){const e=K.c(18),{part:s}=t,i=s.input?.agent_id,r=s.state==="input-streaming"||s.state==="input-available"||s.state==="output-available"&&s.preliminary===!0,o=s.state==="output-error",a=s.state==="approval-requested";let l;e[0]!==o?(l=n.jsx(yp,{isError:o}),e[0]=o,e[1]=l):l=e[1];let h;e[2]!==i||e[3]!==o?(h=n.jsx(bp,{agentId:i,isError:o}),e[2]=i,e[3]=o,e[4]=h):h=e[4];let c;e[5]!==l||e[6]!==h?(c=n.jsx(E.Suspense,{fallback:l,children:h}),e[5]=l,e[6]=h,e[7]=c):c=e[7];let d;e[8]!==s.input?(d=s.input?.prompt&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"text-muted-foreground/50",children:"·"}),n.jsx("span",{className:"truncate text-muted-foreground",children:s.input.prompt})]}),e[8]=s.input,e[9]=d):d=e[9];let u;e[10]!==a||e[11]!==o||e[12]!==r?(u=n.jsx("span",{className:"ml-auto shrink-0",children:r?n.jsx(Ce,{size:12,className:"animate-spin text-muted-foreground"}):o?n.jsx(af,{size:12,className:"text-destructive"}):a?n.jsx(Ui,{size:12,className:"text-warning"}):n.jsx(zc,{size:12,className:"text-emerald-500"})}),e[10]=a,e[11]=o,e[12]=r,e[13]=u):u=e[13];let f;return e[14]!==c||e[15]!==d||e[16]!==u?(f=n.jsxs("div",{className:"flex items-center gap-2 text-xs min-w-0",children:[c,d,u]}),e[14]=c,e[15]=d,e[16]=u,e[17]=f):f=e[17],f}function wp(t){const e=K.c(55),{onClose:s,back:i,className:r}=t,[o,a]=E.useState(null),{messages:l}=Ns(),{activeTask:h}=ss(),{selectedModel:c,selectedVirtualMcp:d}=Wo();let u,f,m,p,_,g,v,b;if(e[0]!==h||e[1]!==i||e[2]!==r||e[3]!==l||e[4]!==s||e[5]!==o?.id||e[6]!==c||e[7]!==d?.title){b=Symbol.for("react.early_return_sentinel");e:{const w=cf(l),C=[...l].reverse().find(Ip),j=C?.metadata?.usage,R=C?.metadata?.modelLimits?.contextWindow??c?.limits?.contextWindow??null,B=j?.contextTokens??0,P=R&&R>0?(B/R*100).toFixed(1):null,T=l;let S;e[16]!==T?(S=T.filter(Ap).reduce(Dp,0),e[16]=T,e[17]=S):S=e[17];const k=S,I=l;let N;e[18]!==I?(N=I.filter(Pp).reduce(Rp,0),e[18]=I,e[19]=N):N=e[19];const A=N,M=Math.max(0,w.totalTokens-k-A),D=l[0],$=l.at(-1),z=D?.metadata?.created_at??h?.created_at,W=$?.metadata?.created_at??h?.updated_at,F=l.filter(Tp),V=l.flatMap(Np),J=c?.modelId?_p(c.modelId):"—",Y=d?.title??"Decopilot",U=[{label:"Session",value:h?.title??"New chat"},{label:"Messages",value:F.length},{label:"Agent",value:Y},{label:"Model",value:J},{label:"Context Limit",value:R?ui(R):"—"},{label:"Session Tokens (billed)",value:w.totalTokens>0?ui(w.totalTokens):"0"},{label:"Usage",value:P!==null?`${P}%`:"—"},{label:"Input Tokens",value:w.inputTokens>0?ui(w.inputTokens):"0"},{label:"Output Tokens",value:w.outputTokens>0?ui(w.outputTokens):"0"},{label:"Reasoning Tokens",value:w.reasoningTokens>0?ui(w.reasoningTokens):"0"},{label:"Cost",value:w.cost>0?`$${w.cost<.001?w.cost.toFixed(6):w.cost.toFixed(4)}`:"$0.00"},{label:"Session Created",value:Qa(z)},{label:"Last Activity",value:Qa(W)}];if(!h&&F.length===0){let L;e[20]!==r?(L=he("flex flex-col h-full w-full border-l border-border bg-background",r),e[20]=r,e[21]=L):L=e[21];let se;e[22]===Symbol.for("react.memo_cache_sentinel")?(se=n.jsx("span",{className:"text-sm font-medium text-foreground",children:"Context"}),e[22]=se):se=e[22];let ee;e[23]!==i?(ee=i?n.jsx(Ha,{size:14,className:"text-muted-foreground"}):n.jsx(ps,{size:14,className:"text-muted-foreground"}),e[23]=i,e[24]=ee):ee=e[24];let Q;e[25]!==s||e[26]!==ee?(Q=n.jsxs("div",{className:"h-11 px-4 flex items-center justify-between shrink-0 border-b border-border/50",children:[se,n.jsx("button",{type:"button",onClick:s,className:"flex size-6 items-center justify-center rounded hover:bg-accent transition-colors",children:ee})]}),e[25]=s,e[26]=ee,e[27]=Q):Q=e[27];let O;e[28]===Symbol.for("react.memo_cache_sentinel")?(O=n.jsx("div",{className:"flex-1 flex items-center justify-center px-4 text-center",children:n.jsx("p",{className:"text-xs text-muted-foreground",children:"Start a conversation to see context"})}),e[28]=O):O=e[28];let ce;e[29]!==L||e[30]!==Q?(ce=n.jsxs("div",{className:L,children:[Q,O]}),e[29]=L,e[30]=Q,e[31]=ce):ce=e[31],b=ce;break e}e[32]!==r?(g=he("flex flex-col h-full w-full border-l border-border bg-background overflow-y-auto",r),e[32]=r,e[33]=g):g=e[33];let H;e[34]===Symbol.for("react.memo_cache_sentinel")?(H=n.jsx("span",{className:"text-sm font-medium text-foreground",children:"Context"}),e[34]=H):H=e[34];let X;e[35]!==i?(X=i?n.jsx(Ha,{size:14}):n.jsx(ps,{size:14}),e[35]=i,e[36]=X):X=e[36],e[37]!==s||e[38]!==X?(v=n.jsxs("div",{className:"flex h-11 shrink-0 items-center justify-between border-b border-border/50 px-4",children:[H,n.jsx("button",{type:"button",onClick:s,className:"flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",children:X})]}),e[37]=s,e[38]=X,e[39]=v):v=e[39],u="flex flex-col gap-8 p-6",f=V.length>0&&n.jsxs("div",{className:"flex flex-col gap-3",children:[n.jsx("span",{className:"text-xs text-muted-foreground",children:"Subtasks"}),n.jsx("div",{className:"flex flex-col gap-1",children:V.map(jp)})]}),m=n.jsx(gp,{items:U});let oe;e[40]===Symbol.for("react.memo_cache_sentinel")?(oe=n.jsx("span",{className:"text-xs text-muted-foreground",children:"Context Breakdown"}),e[40]=oe):oe=e[40],e[41]!==A||e[42]!==M||e[43]!==k?(p=n.jsxs("div",{className:"flex flex-col gap-3",children:[oe,n.jsx(xp,{userTokens:k,assistantTokens:A,otherTokens:M})]}),e[41]=A,e[42]=M,e[43]=k,e[44]=p):p=e[44],_=F.length>0&&n.jsxs("div",{className:"flex flex-col gap-3",children:[n.jsx("span",{className:"text-xs text-muted-foreground",children:"Raw messages"}),n.jsx("div",{className:"flex flex-col gap-1",children:F.map(L=>{const se=L.metadata?.created_at,ee=o?.id===L.id;return n.jsxs("div",{className:"rounded-md border border-border/50 overflow-hidden",children:[n.jsxs("button",{type:"button",onClick:()=>a(ee?null:L),className:"flex items-center justify-between gap-2 px-3 py-2 text-xs hover:bg-accent/50 w-full text-left cursor-pointer",children:[n.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[n.jsx("span",{className:he("shrink-0 font-medium",L.role==="user"?"text-chart-1":"text-chart-2"),children:L.role}),n.jsx("span",{className:"text-muted-foreground",children:"•"}),n.jsx("span",{className:"truncate text-muted-foreground font-mono",children:L.id})]}),se&&n.jsx("span",{className:"shrink-0 text-muted-foreground tabular-nums",children:new Date(se).toLocaleString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit"})})]}),ee&&n.jsxs(n.Fragment,{children:[L.role==="assistant"&&(()=>{const Q=L.metadata?._request;if(!Q)return null;const O=Q.systemSections??[],ce=Math.max(1,...O.map(kp)),ue=O.reduce(Cp,0);return n.jsxs("div",{className:"border-t border-border/50 px-3 py-2.5 text-xs space-y-2.5",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("span",{className:"font-medium text-foreground",children:"Request"}),n.jsxs("span",{className:"text-muted-foreground tabular-nums",children:[Q.activeTools??0," / ",Q.tools??0," ","tools active"]})]}),O.length>0&&n.jsxs("div",{className:"space-y-1.5",children:[n.jsxs("div",{className:"text-muted-foreground",children:["System prompt"," ",n.jsxs("span",{className:"tabular-nums",children:["~",Math.round(ue/4).toLocaleString()," ","tok"]})]}),O.map((fe,q)=>{const te=fe.preview.match(/^<([a-z-]+)/i)?.[1]??`section ${q}`,me=fe.chars/ce*100,ne=Math.round(fe.chars/4);return n.jsxs("div",{className:"space-y-0.5",children:[n.jsxs("div",{className:"flex items-center justify-between gap-2",children:[n.jsx("span",{className:"font-mono text-foreground truncate",children:te}),n.jsxs("span",{className:"text-muted-foreground tabular-nums shrink-0",children:["~",ne.toLocaleString()," tok"]})]}),n.jsx("div",{className:"h-1 w-full rounded-full bg-muted overflow-hidden",children:n.jsx("div",{className:"h-full rounded-full bg-chart-3",style:{width:`${me}%`}})})]},q)})]})]})})(),n.jsx("pre",{className:"text-xs font-mono bg-muted px-3 py-2 overflow-auto whitespace-pre-wrap break-all border-t border-border/50 max-h-64",children:JSON.stringify(L,null,2)})]})]},L.id)})})]})}e[0]=h,e[1]=i,e[2]=r,e[3]=l,e[4]=s,e[5]=o?.id,e[6]=c,e[7]=d?.title,e[8]=u,e[9]=f,e[10]=m,e[11]=p,e[12]=_,e[13]=g,e[14]=v,e[15]=b}else u=e[8],f=e[9],m=e[10],p=e[11],_=e[12],g=e[13],v=e[14],b=e[15];if(b!==Symbol.for("react.early_return_sentinel"))return b;let x;e[45]!==u||e[46]!==f||e[47]!==m||e[48]!==p||e[49]!==_?(x=n.jsxs("div",{className:u,children:[f,m,p,_]}),e[45]=u,e[46]=f,e[47]=m,e[48]=p,e[49]=_,e[50]=x):x=e[50];let y;return e[51]!==g||e[52]!==v||e[53]!==x?(y=n.jsxs("div",{className:g,children:[v,x]}),e[51]=g,e[52]=v,e[53]=x,e[54]=y):y=e[54],y}function Cp(t,e){return t+e.chars}function kp(t){return t.chars}function jp(t,e){return n.jsx(Sp,{part:t},e)}function Np(t){return(t.parts??[]).filter(Ep)}function Ep(t){return t.type==="tool-subtask"}function Tp(t){return t.role!=="system"}function Rp(t,e){const s=e.metadata?.usage;return t+(s?.outputTokens??0)}function Pp(t){return t.role==="assistant"}function Dp(t,e){const s=e.metadata?.usage;return t+(s?.inputTokens??0)}function Ap(t){return t.role==="user"}function Ip(t){return t.role==="assistant"&&t.metadata?.usage}function Bp(t){const e=K.c(13),{readOnly:s,identity:i,aboveRow:r,input:o,iceBreakers:a}=t,l=!s&&i?i:null;let h;e[0]!==r||e[1]!==s?(h=!s&&r?n.jsx("div",{"data-chat-above-row":"true",className:"@container/chat-bottom flex justify-start gap-1",children:r}):null,e[0]=r,e[1]=s,e[2]=h):h=e[2];let c;e[3]!==o||e[4]!==h?(c=n.jsxs("div",{className:"flex flex-col gap-2",children:[h,o]}),e[3]=o,e[4]=h,e[5]=c):c=e[5];let d;e[6]!==a||e[7]!==s?(d=!s&&a?n.jsx("div",{className:"w-full",children:a}):null,e[6]=a,e[7]=s,e[8]=d):d=e[8];let u;return e[9]!==l||e[10]!==c||e[11]!==d?(u=n.jsx("div",{"data-chat-centered":"true",className:"h-full w-full flex flex-col items-center justify-center px-4 gap-6",children:n.jsxs("div",{className:"w-full max-w-3xl flex flex-col gap-6",children:[l,c,d]})}),e[9]=l,e[10]=c,e[11]=d,e[12]=u):u=e[12],u}function Mp(t){const e=K.c(25),{onOpenContextPanel:s}=t,{org:i}=Pe(),{selectedVirtualMcp:r}=Wo();let o;e[0]!==i.id?(o=Fo(i.id),e[0]=i.id,e[1]=o):o=e[1];const l=r??o,h=Mt(l.id),c=$c(),{data:d}=Js.useSession(),u=d?.user?.id,f=c?.activeTask??null,m=!!(u&&f?.created_by&&f.created_by!==u);let p;e[2]===Symbol.for("react.memo_cache_sentinel")?(p=n.jsx(vf,{size:32}),e[2]=p):p=e[2];let _;e[3]!==l.icon||e[4]!==l.title?(_=n.jsx(Gt,{icon:l.icon,name:l.title,size:"lg",fallbackIcon:p,className:"size-10 min-w-10 md:size-[60px]! md:min-w-[60px] rounded-xl md:rounded-[18px]!"}),e[3]=l.icon,e[4]=l.title,e[5]=_):_=e[5];let g;e[6]!==l.title?(g=n.jsx("h3",{className:"text-base md:text-xl font-medium text-foreground",children:l.title}),e[6]=l.title,e[7]=g):g=e[7];const v=l.description??"Ask anything about configuring model providers or using MCP Mesh.";let b;e[8]!==v?(b=n.jsx("div",{className:"text-muted-foreground text-center text-base max-w-md line-clamp-2",children:v}),e[8]=v,e[9]=b):b=e[9];let x;e[10]!==_||e[11]!==g||e[12]!==b?(x=n.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 md:gap-4 text-center",children:[_,g,b]}),e[10]=_,e[11]=g,e[12]=b,e[13]=x):x=e[13];const y=c?.currentBranch??null;let w;e[14]!==h||e[15]!==y?(w=n.jsx(Vu,{virtualMcp:h,currentBranch:y}),e[14]=h,e[15]=y,e[16]=w):w=e[16];let C;e[17]!==s?(C=n.jsx(Oe.Input,{onOpenContextPanel:s}),e[17]=s,e[18]=C):C=e[18];let j;e[19]===Symbol.for("react.memo_cache_sentinel")?(j=n.jsx(Oe.IceBreakers,{}),e[19]=j):j=e[19];let R;return e[20]!==m||e[21]!==C||e[22]!==x||e[23]!==w?(R=n.jsx(Bp,{readOnly:m,identity:x,aboveRow:w,input:C,iceBreakers:j}),e[20]=m,e[21]=C,e[22]=x,e[23]=w,e[24]=R):R=e[24],R}function el(t){const e=K.c(17),{outputs:s,collapsed:i,onToggle:r,variant:o}=t,a=o==="card"?"rounded-xl border border-border bg-muted/95 shadow-sm backdrop-blur-sm":"border-b border-border bg-background";let l;e[0]!==a?(l=he(a),e[0]=a,e[1]=l):l=e[1];let h;e[2]===Symbol.for("react.memo_cache_sentinel")?(h=n.jsx("span",{className:"text-sm font-medium text-foreground",children:"Files in this task"}),e[2]=h):h=e[2];const c=i&&"-rotate-90";let d;e[3]!==c?(d=he("size-4 text-muted-foreground transition-transform",c),e[3]=c,e[4]=d):d=e[4];let u;e[5]!==d?(u=n.jsx(Es,{className:d}),e[5]=d,e[6]=u):u=e[6];let f;e[7]!==r||e[8]!==u?(f=n.jsxs("button",{type:"button",onClick:r,className:"flex w-full items-center justify-between px-3 py-2.5 text-left",children:[h,u]}),e[7]=r,e[8]=u,e[9]=f):f=e[9];let m;e[10]!==i||e[11]!==s?(m=!i&&n.jsx("div",{className:"flex max-h-72 flex-col gap-1.5 overflow-y-auto px-2 pb-2",children:s.map(Lp)}),e[10]=i,e[11]=s,e[12]=m):m=e[12];let p;return e[13]!==l||e[14]!==f||e[15]!==m?(p=n.jsxs("div",{className:l,children:[f,m]}),e[13]=l,e[14]=f,e[15]=m,e[16]=p):p=e[16],p}function Lp(t){return n.jsx(df,{file:t},t.key)}function Op(){const t=K.c(13),e=$c()?.taskId??null,s=hf();let i;t[0]!==s?(i={enabled:s},t[0]=s,t[1]=i):i=t[1];const{data:r}=Fc(e,i),[o,a]=E.useState(!1),[l,h]=E.useState(!0);if(!e||!r||r.length===0)return null;let c;t[2]===Symbol.for("react.memo_cache_sentinel")?(c=()=>a(zp),t[2]=c):c=t[2];let d;t[3]!==o||t[4]!==r?(d=n.jsx("div",{className:"absolute top-2 right-2 z-10 hidden w-72 @[1280px]:block",children:n.jsx(el,{variant:"card",outputs:r,collapsed:o,onToggle:c})}),t[3]=o,t[4]=r,t[5]=d):d=t[5];let u;t[6]===Symbol.for("react.memo_cache_sentinel")?(u=()=>h($p),t[6]=u):u=t[6];let f;t[7]!==l||t[8]!==r?(f=n.jsx("div",{className:"shrink-0 @[1280px]:hidden",children:n.jsx(el,{variant:"bar",outputs:r,collapsed:l,onToggle:u})}),t[7]=l,t[8]=r,t[9]=f):f=t[9];let m;return t[10]!==d||t[11]!==f?(m=n.jsxs(n.Fragment,{children:[d,f]}),t[10]=d,t[11]=f,t[12]=m):m=t[12],m}function $p(t){return!t}function zp(t){return!t}function Fp(){const t=K.c(28),{org:e}=Pe(),s=Hc(),{isChatEmpty:i}=Ns(),[r,o]=E.useState("chat"),a=qu(),{selectedVirtualMcp:l}=Wo();let h;t[0]!==e.id?(h=Fo(e.id),t[0]=e.id,t[1]=h):h=t[1];const u=Mt((l??h).id),f=rf(),m=ti(u?.metadata);if(s.length===0&&!(m&&Gu(f))){let T;return t[2]===Symbol.for("react.memo_cache_sentinel")?(T=n.jsx(Oe,{className:"animate-in fade-in-0 duration-200",children:n.jsx(Oe.Main,{className:"flex flex-col items-center",children:n.jsx(Oe.EmptyState,{children:n.jsx(Oe.NoAiProviderEmptyState,{})})})}),t[2]=T):T=t[2],T}let _;t[3]!==a.hasDecoKey||t[4]!==a.hasOnlyDecoProvider||t[5]!==a.isLoading||t[6]!==a.isZeroBalance||t[7]!==i||t[8]!==e.id?(_=a.hasDecoKey&&a.isZeroBalance&&a.hasOnlyDecoProvider&&!a.isLoading&&i&&!Yu(e.id),t[3]=a.hasDecoKey,t[4]=a.hasOnlyDecoProvider,t[5]=a.isLoading,t[6]=a.isZeroBalance,t[7]=i,t[8]=e.id,t[9]=_):_=t[9];const g=_;let v;t[10]!==g?(v=g&&n.jsx(Oe.CreditsEmptyState,{}),t[10]=g,t[11]=v):v=t[11];const b=r!=="chat"?"opacity-0 pointer-events-none":"opacity-100";let x;t[12]!==b?(x=he("absolute inset-0 flex flex-col transition-opacity duration-100 ease-out",b),t[12]=b,t[13]=x):x=t[13];let y;t[14]!==i?(y=i?n.jsx(Oe.Main,{children:n.jsx(Mp,{onOpenContextPanel:()=>o("context")})}):n.jsxs(n.Fragment,{children:[n.jsxs(Oe.Main,{className:"relative flex flex-col overflow-hidden @container",children:[n.jsx(Op,{}),n.jsx("div",{className:"min-h-0 flex-1",children:n.jsx(Oe.Messages,{})})]}),n.jsx(Oe.Footer,{children:n.jsx(Oe.Input,{onOpenContextPanel:()=>o("context")})})]}),t[14]=i,t[15]=y):y=t[15];let w;t[16]!==x||t[17]!==y?(w=n.jsx("div",{className:x,children:y}),t[16]=x,t[17]=y,t[18]=w):w=t[18];const C=r==="context"?"opacity-100":"opacity-0 pointer-events-none";let j;t[19]!==C?(j=he("absolute inset-0 flex flex-col transition-opacity duration-100 ease-out",C),t[19]=C,t[20]=j):j=t[20];let R;t[21]===Symbol.for("react.memo_cache_sentinel")?(R=n.jsx(wp,{back:!0,onClose:()=>o("chat")}),t[21]=R):R=t[21];let B;t[22]!==j?(B=n.jsx("div",{className:j,children:R}),t[22]=j,t[23]=B):B=t[23];let P;return t[24]!==B||t[25]!==v||t[26]!==w?(P=n.jsxs(Oe,{className:"relative overflow-hidden animate-in fade-in-0 duration-200",children:[v,w,B]}),t[24]=B,t[25]=v,t[26]=w,t[27]=P):P=t[27],P}function gh(){const t=K.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=n.jsx(Oe.Skeleton,{}),t[0]=e):e=t[0];let s;return t[1]===Symbol.for("react.memo_cache_sentinel")?(s=n.jsx(Ut,{fallback:e,children:n.jsx(E.Suspense,{fallback:n.jsx(Oe.Skeleton,{}),children:n.jsx(Fp,{})})}),t[1]=s):s=t[1],s}function Hp(t){const e=t.entityMetadata?.defaultMainView??null,s=e==null||e.type==="chat",i=t.mainParamPresent?t.mainParamValue!=="0":!s,r=s?!0:t.entityMetadata?.chatDefaultOpen??!1;return{mainOpen:i,chatOpen:r}}function tl(t,e){return t&&e?{chat:45,main:55}:t&&!e?{chat:100,main:0}:!t&&e?{chat:0,main:100}:{chat:0,main:0}}function Wp(t,e){return t===1?!0:t===0?!1:e}function Up(t,e){const s=ts(),i=$o({strict:!1}),r=Ac({strict:!1}),{create:o}=Qf(),{locator:a}=Pe(),{virtualMcpId:l,orgSlug:h,isAgentRoute:c}=e,d=Hp({entityMetadata:t,mainParamPresent:i.main!==void 0,mainParamValue:i.main}),u=Wp(i.chat,d.chatOpen),f=d.mainOpen,m=E.useRef(crypto.randomUUID()),p=r.taskId??m.current,_="/$org/$taskId",g=B=>({org:h,taskId:B}),v=c?{virtualmcpid:l}:{},b=(B,P)=>{s({to:_,params:g(p),search:T=>({...T,...B}),replace:P?.replace??!1})},x=(B,P)=>{s({to:_,params:g(B),search:T=>{const S={};return P?S.virtualmcpid=P:c&&(S.virtualmcpid=l),S}})},y=()=>{f?b({main:"0"},{replace:!0}):b({main:Fn(t)},{replace:!0})},w=()=>{b({chat:u?0:1},{replace:!0})},C=()=>{u||b({chat:1},{replace:!0})},j=async()=>{const B=crypto.randomUUID(),P=xf(h,a,p);try{await o({id:B,virtual_mcp_id:l,...P?{branch:P}:{}})}catch{}s({to:_,params:g(B),search:T=>({...v,chat:1})})},R=B=>{b({main:B},{replace:!0})};return{taskId:p,mainOpen:f,chatOpen:u,mainParam:i.main,setTaskId:x,toggleMain:y,toggleChat:w,openChat:C,createNewTask:j,openTab:R}}const ra=45;function vh(t,e=ra){const s=typeof t=="number"?t:Number(t);return!Number.isFinite(s)||s<=0||s>=100?e:s}function Kp(t){return vh(t,ra)}function Vp(){const t=K.c(6);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=Mu.decoChatPanelWidth(),t[0]=e):e=t[0];const[s,i]=Bu(e,Kp);let r;t[1]!==s?(r=vh(s,ra),t[1]=s,t[2]=r):r=t[2];const o=r;let a;return t[3]!==i||t[4]!==o?(a=[o,i],t[3]=i,t[4]=o,t[5]=a):a=t[5],a}function qp(t){try{return JSON.parse(t)}catch{return null}}function Gp(t){if(!t||typeof t!="object")return null;const e=t,s=e.content?.find(o=>o.type==="text")?.text,i=s?qp(s):null,r=e.structuredContent;return r==null?i:typeof r=="object"&&!Array.isArray(r)&&Object.keys(r).length===0?i??r:r}function Bs(t){const e=Gp(t);return e===null?null:e}function na(t){if(!t)return null;const e=t.match(/\/pull\/(\d+)\b/);if(!e)return null;const s=Number(e[1]);return Number.isFinite(s)&&s>0?s:null}function Yp(t){if(!t||typeof t!="object")return null;const e=t.content?.find(r=>r.type==="text")?.text;if(!e)return null;const s=e.match(/https:\/\/github\.com\/[^\s"]+\/pull\/\d+/)?.[0],i=na(s);return!i||!s?null:{number:i,htmlUrl:s}}const sl=/[\r\n<>]/,Xp=/^[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+$/;function Yi(t){const e=t?.userName?.trim();if(!e||sl.test(e))return null;const s=t?.userEmail?.trim();return!s||sl.test(s)?{userName:e}:Xp.test(s)?{userName:e,userEmail:s}:{userName:e}}function Jp(t){return t.split(`
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/sections-editor-DJ6-AL_q.js","assets/index-rZ1TPVyD.js","assets/index-DfYyH4IW.css","assets/ChevronDown-CaCYdoie.js","assets/ChevronRight-kLRVkGUs.js","assets/ChevronUp-DkGtzqyl.js","assets/agent-icon-CpBAbwoh.js","assets/AlertCircle-rpaL6q8T.js","assets/Tool01-B0zT3ots.js","assets/SwitchHorizontal01-CkwE98n9.js","assets/RefreshCcw01-CW918RSV.js","assets/XCircle-CiiIVhRh.js","assets/ArrowUpRight-D7_4FAQ5.js","assets/ZapSquare-CxE5iHdd.js","assets/Users03-C5i2CKOP.js","assets/CheckCircle-D0kUlRsN.js","assets/Check-6LmIKXJj.js","assets/ChevronLeft-BuXkBFIm.js","assets/DotsVertical-CvhOKI-w.js","assets/Container-Bl0qWNtu.js","assets/Eye-BNS1RmzG.js","assets/ZoomOut-B1VNHI1K.js","assets/Globe01-DjWlKHom.js","assets/FilterLines-BSmtfAHG.js","assets/Star01-QoJ-qcfh.js","assets/Palette-BX6fdd-v.js","assets/HardDrive-Dx3Blqhn.js","assets/Stars02-C17u9BVa.js","assets/Key01-D6jyUgYu.js","assets/LayoutLeft-C7Cmt2J8.js","assets/LinkExternal01-B6flmd1s.js","assets/Monitor01-DBfOkkx9.js","assets/Sun-D4yzlyEv.js","assets/Play-DApzrsBx.js","assets/Plus-Do6ZWheh.js","assets/SearchMd-B4Lavo8e.js","assets/Settings02-B57k_aEv.js","assets/Shield01-CFDfVqiL.js","assets/Stars01-ANwy09AP.js","assets/Trash01-Bifm5Wb3.js","assets/Upload01-mjA8r4Fi.js","assets/User01-BZL6tFVt.js","assets/Users01-CqVfleMx.js","assets/XClose-D0wmxYTF.js","assets/X-BWR0-4rz.js","assets/Zap-BGp3QjmM.js","assets/scroll-area-QXSqgT3C.js","assets/select-DRqZIuLQ.js","assets/tooltip-ua4lJTzI.js","assets/dialog-CxpeEAA2.js","assets/input-BPXWlz46.js","assets/dropdown-menu-Xj0lVIXK.js","assets/sortable.esm-CnPAeADV.js","assets/connection-slug-eyAPH6o3.js","assets/connection-card-BioQsepZ.js","assets/use-registry-connections-CRtbznIm.js","assets/use-connection-CyWLUiRu.js","assets/use-collections-Dvp_IbhN.js","assets/use-mcp-client-CGBZ7ekq.js","assets/use-organization-settings-D68AqLOQ.js","assets/useInfiniteQuery-k6dph5MZ.js","assets/use-infinite-scroll-B2zyjKex.js","assets/extract-connection-data-BJ4lD3eO.js","assets/generate-id-nWw_PZwJ.js","assets/collections-NCEoL2EX.js","assets/card-CYGsSb57.js","assets/integration-icon-CWT0gSfx.js","assets/collection-search-CjkYy_AH.js","assets/collection-tabs-BGsvaOVA.js","assets/badge-CY1rqnYU.js","assets/drawer-R-Q-vfsa.js","assets/form-Ci8PGt-R.js","assets/label-CzVCjiiL.js","assets/textarea-Bymi75yx.js","assets/connection-form-helpers-DC_9yJsF.js","assets/useSuspenseInfiniteQuery-DGO3SU3a.js","assets/studio-tools-jbRVdtpc.js","assets/use-ai-providers-P6PF7YRx.js","assets/schema-form-DNaVud8y.js","assets/calendar-vde5tCHf.js","assets/popover-Bk3EwUPD.js","assets/switch-rL3a0x4B.js","assets/image-field-DXfNSgLy.js","assets/skeleton-DvVUqja_.js","assets/tabs-B68TQ0Dt.js","assets/use-file-configs-DXD_Hwrv.js","assets/page-seo-form-Dk6e77BM.js","assets/command-KCI9wvsu.js","assets/index-BEe1oLVg.js","assets/add-section-modal-BPiyATcO.js","assets/agent-capabilities-CmHO-Kgo.js","assets/chat-context-CDygsN4Q.js","assets/tab-id-hZWLCmfc.js","assets/watch-sse-pool-Bo209v56.js","assets/decopilot-sse-pool-C2fCSDxg.js","assets/use-virtual-mcp-mhycHzLS.js","assets/pair-DYb6YfcG.js","assets/use-clock-tick-x-ip1-Lp.js","assets/differenceInSeconds-NQ4PDo0z.js","assets/use-copy-nAd5EMaO.js","assets/file-type-icon-35VBMVCk.js","assets/content-blocks-o63cs2vh.js","assets/types-DJl0mitR.js","assets/shell-layout-DkW3B_MZ.js","assets/avatar-nCSKoB6F.js","assets/required-auth-layout-YEZh9H2w.js","assets/useRouterState-qr3F3XJE.js","assets/use-org-sso-B8CLPiZl.js","assets/use-navigate-to-agent-5w6ZqBss.js","assets/use-mcp-prompts-BQNNtRte.js","assets/spinner-DZmgr2qu.js","assets/toggle-group-DnRl91Ne.js","assets/connect-desktop-dialog-CgeQRUKM.js","assets/agent-icons-C_pHQRgk.js","assets/checkbox-vKl7eadT.js","assets/ai-providers-logos-DD3qZ33J.js","assets/settings-section-5LNAbhU4.js","assets/index-Dczuf3at.js","assets/question-004-sINsf4GQ.js","assets/shell-route-loading-CKElD_Av.js","assets/sidebar-B3SsvTHC.js","assets/sheet-Dsfk9URc.js","assets/toolbar-Cb06hfKk.js","assets/use-create-virtual-mcp-DmdlMapL.js","assets/github-repo-picker-DY4w_1I0.js","assets/use-mcp-tools-Dn2JgISP.js","assets/alert-dialog-Dsb6KPFM.js","assets/index-czuYZ_ID.js","assets/use-org-auth-client-CLnnUl3h.js","assets/hover-card-DY9PmUZF.js","assets/task-status-Cqn0_tco.js","assets/use-status-sounds-B8VUkU2E.js","assets/empty-state-BhV-zl-f.js","assets/resizable-23UTrxEL.js","assets/use-capability-B2IrzHkM.js","assets/header-tab-button-C7XZ27Uv.js","assets/index-DppjWA7O.js","assets/user-D73GXODW.js","assets/tools-list-D12nTCg-.js","assets/use-debounced-autosave-DSZqKaTf.js","assets/index-DO3UwA_I.js","assets/search-input-DbmU5zU8.js","assets/use-secrets--KIFsJ5I.js","assets/formatDistanceToNow-Cb2QZZJn.js","assets/accordion-Dsx4jZXX.js","assets/view-mode-toggle-3i0Tx7_t.js","assets/select-model-CZe_eVYF.js","assets/use-automations-DGe3A7k6.js","assets/monaco-editor-C-H4UmIT.js","assets/automation-runs-D8yf4pum.js","assets/table-cHRXPecF.js","assets/use-members-BaX0tyb1.js","assets/automation-list-row-DTcrDIUh.js","assets/save-referenced-block-CMYI5Fv0.js","assets/page-seo-sheet-Ceb0gnAp.js","assets/file-explorer-mkpu5feK.js","assets/app-editor-CJE_W_Dn.js","assets/save-status-BkzFYIeb.js","assets/post-editor-Bw21I9pc.js","assets/primitives-Dql_hUCU.js","assets/record-editor-803FPqaV.js","assets/seo-editor-pRBB6PMK.js","assets/project-app-view-CMCeiidr.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{e as K,r as E,c as he,j as n,l as Ce,q as Pe,b as Js,E as Ut,f as ts,d as $o,g as Ac,p as Bu,L as Mu,n as Zs,K as Bt,s as Lu,o as le,B as re,v as Ic,w as Ou,V as $u,t as De,x as Bc,y as zu,z as Xr,C as Bi,D as vt,F as Fu,G as Qs,H as Mc,I as Hu,J as Wu,M as Fa,P as Uu,Q as Jr,R as Ku,a as ei,T as _r,U as yi,W as Tt,_ as qt}from"./index-rZ1TPVyD.js";import{C as Oe,a as Vu,b as ti,h as qu,w as Gu,c as Lc,u as zo,s as $n,T as Yu,d as Xu,g as Ju,e as Zu}from"./agent-capabilities-CmHO-Kgo.js";import{g as Fo,u as ft,S as Oc,a as Ho}from"./use-mcp-client-CGBZ7ekq.js";import{u as Mt,a as Qu,b as ef,c as tf}from"./use-virtual-mcp-mhycHzLS.js";import{a as Ns,b as ss,c as Wo,d as $c,u as sf,t as rf,e as nf}from"./chat-context-CDygsN4Q.js";import{i as Ui}from"./AlertCircle-rpaL6q8T.js";import{i as zc}from"./CheckCircle-D0kUlRsN.js";import{n as Ha}from"./ChevronLeft-BuXkBFIm.js";import{i as of,a as af}from"./XCircle-CiiIVhRh.js";import{s as ps}from"./XClose-D0wmxYTF.js";import{c as lf,u as cf,a as Fc,O as hf,t as Wa,G as df,g as uf,s as ff,C as mf,b as pf,d as _f}from"./pair-DYb6YfcG.js";import{I as Gt}from"./integration-icon-CWT0gSfx.js";import{a as gf}from"./Users03-C5i2CKOP.js";import{t as Es}from"./ChevronDown-CaCYdoie.js";import{u as Hc}from"./use-ai-providers-P6PF7YRx.js";import{u as vf,g as si,A as xf}from"./sortable.esm-CnPAeADV.js";import{r as bf,u as Uo,i as yf}from"./shell-layout-DkW3B_MZ.js";import{b as Sf,a as wf}from"./shell-route-loading-CKElD_Av.js";import{u as Cf}from"./sidebar-B3SsvTHC.js";import{S as kf,a as jf,b as Nf}from"./sheet-Dsfk9URc.js";import{u as Wc,T as Ee,a as Te,b as Re,c as Uc}from"./tooltip-ua4lJTzI.js";import{i as Mi,a as Zr,b as Kc,c as Ef,p as Qr,g as en,d as Ko,e as Vc,h as zn,f as fn,j as Ua,A as Ka,k as Tf,l as Rf,m as Pf,n as Df,o as Af,q as If,t as Bf,r as Mf,s as Lf,u as Of,v as tn,w as $f,x as Va,y as qa,z as zf,B as Ff,C as Hf,D as Wf,E as Vo,F as Nr,G as qo,H as qc,I as Gc,J as Uf,K as Kf,L as Vf,M as qf,N as Gf,O as Ga,P as Yf,Q as Xf,R as Ei,S as Jf,T as Yc,U as Xc,V as Zf}from"./agent-icon-CpBAbwoh.js";import{u as Qf}from"./use-status-sounds-B8VUkU2E.js";import{E as Er}from"./empty-state-BhV-zl-f.js";import{u as em,r as Fn,a as tm,p as Jc,f as Ya,b as Zc,c as Qc,d as eh,e as sm,F as im,i as rm,g as nm,h as om,j as am}from"./tab-id-hZWLCmfc.js";import{T as Xa,a as Hn}from"./toolbar-Cb06hfKk.js";import{R as th,a as lm,b as cm}from"./resizable-23UTrxEL.js";import{i as Ki,n as hm}from"./Globe01-DjWlKHom.js";import{i as sh}from"./Monitor01-DBfOkkx9.js";import{u as Vi,a as Go,b as ih}from"./use-connection-CyWLUiRu.js";import{u as qi}from"./studio-tools-jbRVdtpc.js";import{u as sn,a as dm,b as um}from"./use-mcp-tools-Dn2JgISP.js";import{u as fm}from"./use-capability-B2IrzHkM.js";import{F as Li,M as Yo}from"./file-type-icon-35VBMVCk.js";import{u as mm,a as pm,b as _m,c as gm,g as vm,d as rh,e as Ja,F as xm,f as bm,h as ym,i as Sm,j as wm,k as Cm,H as km,l as jm}from"./header-tab-button-C7XZ27Uv.js";import{i as Wn,a as nh,b as Nm}from"./ZoomOut-B1VNHI1K.js";import{P as Ts,a as Rs,b as Ps}from"./popover-Bk3EwUPD.js";import{S as Xo}from"./spinner-DZmgr2qu.js";import{D as Ds,a as As,b as Is,c as He,d as Un,e as Kn,f as Vn,g as gr}from"./dropdown-menu-Xj0lVIXK.js";import{D as Lt,a as Ot,b as is,c as rs,d as ii,e as Jo}from"./dialog-CxpeEAA2.js";import{I as qe}from"./input-BPXWlz46.js";import{T as ys,a as Zo,b as Ti,c as Qo}from"./tabs-B68TQ0Dt.js";import{T as Tr}from"./textarea-Bymi75yx.js";import{a as Qt,s as Em}from"./Eye-BNS1RmzG.js";import{t as Ss}from"./Stars01-ANwy09AP.js";import{l as Tm,w as Rm}from"./index-DppjWA7O.js";import{i as Pm}from"./ChevronRight-kLRVkGUs.js";import{g as Dm}from"./generate-id-nWw_PZwJ.js";import{g as Am}from"./types-DJl0mitR.js";import{U as oh}from"./user-D73GXODW.js";import{T as Im,u as ah}from"./tools-list-D12nTCg-.js";import{s as lh,g as Bm}from"./connection-slug-eyAPH6o3.js";import{A as Rr,a as Pr,b as Dr,c as Ar,d as Ir,e as Br,f as Mr,g as Lr}from"./alert-dialog-Dsb6KPFM.js";import{C as ch,a as qn}from"./card-CYGsSb57.js";import{L as jt}from"./label-CzVCjiiL.js";import{S as Pt,a as Dt,b as At,c as ot,d as It}from"./select-DRqZIuLQ.js";import{S as Or}from"./switch-rL3a0x4B.js";import{i as Vs}from"./Play-DApzrsBx.js";import{s as xt}from"./Plus-Do6ZWheh.js";import{a as Mm}from"./Settings02-B57k_aEv.js";import{s as qs}from"./Trash01-Bifm5Wb3.js";import{u as $r}from"./use-debounced-autosave-DSZqKaTf.js";import{S as rn}from"./scroll-area-QXSqgT3C.js";import{i as Oi}from"./SearchMd-B4Lavo8e.js";import{i as Lm}from"./Upload01-mjA8r4Fi.js";import{i as Om}from"./LayoutLeft-C7Cmt2J8.js";import{P as Rt}from"./index-DO3UwA_I.js";import{C as nn}from"./checkbox-vKl7eadT.js";import{S as hh}from"./search-input-DbmU5zU8.js";import{C as dh}from"./collection-tabs-BGsvaOVA.js";import{u as $m}from"./use-mcp-prompts-BQNNtRte.js";import{D as zm,a as Fm,b as Hm}from"./drawer-R-Q-vfsa.js";import{i as ri}from"./Check-6LmIKXJj.js";import{i as ea}from"./Key01-D6jyUgYu.js";import{S as uh}from"./skeleton-DvVUqja_.js";import{s as Wm}from"./User01-BZL6tFVt.js";import{t as ta}from"./Users01-CqVfleMx.js";import{u as Um,a as Km}from"./use-secrets--KIFsJ5I.js";import{G as Vm}from"./github-repo-picker-DY4w_1I0.js";import{f as qm}from"./formatDistanceToNow-Cb2QZZJn.js";import{n as ni}from"./LinkExternal01-B6flmd1s.js";import{A as Gm,a as Ym,b as Xm,c as Jm}from"./accordion-Dsx4jZXX.js";import{s as Gs}from"./Star01-QoJ-qcfh.js";import{i as fh}from"./Stars02-C17u9BVa.js";import{V as Zm}from"./view-mode-toggle-3i0Tx7_t.js";import{n as mh}from"./ZapSquare-CxE5iHdd.js";import{i as sa,a as Qm,b as ia}from"./Tool01-B0zT3ots.js";import{c as ph,i as ep}from"./SwitchHorizontal01-CkwE98n9.js";import{B as tp}from"./badge-CY1rqnYU.js";import{C as sp,a as Za,b as ip,c as rp,d as np,e as op}from"./command-KCI9wvsu.js";import{M as ap}from"./select-model-CZe_eVYF.js";import{u as Gi,a as lp,b as cp,c as hp,d as dp}from"./use-automations-DGe3A7k6.js";import{i as _h}from"./RefreshCcw01-CW918RSV.js";import{i as $i}from"./Zap-BGp3QjmM.js";import{M as up}from"./monaco-editor-C-H4UmIT.js";import{A as fp}from"./automation-runs-D8yf4pum.js";import{A as mp}from"./automation-list-row-DTcrDIUh.js";import{i as pp}from"./X-BWR0-4rz.js";function ui(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}k`:String(t)}function Qa(t){if(!t)return"—";const e=typeof t=="string"?new Date(t):t;return isNaN(e.getTime())?"—":e.toLocaleString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit"})}function _p(t){return t?t.replace(/-\d{8}(?:-[a-z0-9]+)*$/i,"").replace(/-/g," "):"—"}function gp(t){const e=K.c(4),{items:s}=t;let i;e[0]!==s?(i=s.map(vp),e[0]=s,e[1]=i):i=e[1];let r;return e[2]!==i?(r=n.jsx("div",{className:"grid grid-cols-2 gap-x-8 gap-y-6",children:i}),e[2]=i,e[3]=r):r=e[3],r}function vp(t){return n.jsxs("div",{className:"flex flex-col gap-1 min-w-0",children:[n.jsx("span",{className:"text-xs text-muted-foreground truncate",children:t.label}),n.jsx("span",{className:"text-sm text-foreground tabular-nums truncate",children:t.value})]},t.label)}function xp(t){const e=K.c(30),{userTokens:s,assistantTokens:i,otherTokens:r}=t,o=s+i+r,a=o>0?s/o*100:0,l=o>0?i/o*100:0,h=o>0?r/o*100:0;let c;e[0]!==a?(c=a>0&&n.jsx("div",{className:"h-full bg-chart-1",style:{width:`${a}%`}}),e[0]=a,e[1]=c):c=e[1];let d;e[2]!==l?(d=l>0&&n.jsx("div",{className:"h-full bg-chart-2",style:{width:`${l}%`}}),e[2]=l,e[3]=d):d=e[3];let u;e[4]!==h?(u=h>0&&n.jsx("div",{className:"h-full bg-muted-foreground/30",style:{width:`${h}%`}}),e[4]=h,e[5]=u):u=e[5];let f;e[6]!==c||e[7]!==d||e[8]!==u?(f=n.jsxs("div",{className:"flex h-2 w-full overflow-hidden rounded-full bg-muted",children:[c,d,u]}),e[6]=c,e[7]=d,e[8]=u,e[9]=f):f=e[9];let m;e[10]===Symbol.for("react.memo_cache_sentinel")?(m=n.jsx("span",{className:"inline-block h-2 w-2 rounded-sm bg-chart-1 shrink-0"}),e[10]=m):m=e[10];let p;e[11]!==a?(p=a.toFixed(1),e[11]=a,e[12]=p):p=e[12];let _;e[13]!==p?(_=n.jsxs("div",{className:"flex items-center gap-1.5",children:[m,n.jsxs("span",{className:"text-xs text-muted-foreground",children:["User ",p,"%"]})]}),e[13]=p,e[14]=_):_=e[14];let g;e[15]===Symbol.for("react.memo_cache_sentinel")?(g=n.jsx("span",{className:"inline-block h-2 w-2 rounded-sm bg-chart-2 shrink-0"}),e[15]=g):g=e[15];let v;e[16]!==l?(v=l.toFixed(1),e[16]=l,e[17]=v):v=e[17];let b;e[18]!==v?(b=n.jsxs("div",{className:"flex items-center gap-1.5",children:[g,n.jsxs("span",{className:"text-xs text-muted-foreground",children:["Assistant ",v,"%"]})]}),e[18]=v,e[19]=b):b=e[19];let x;e[20]!==h||e[21]!==r?(x=r>0&&n.jsxs("div",{className:"flex items-center gap-1.5",children:[n.jsx("span",{className:"inline-block h-2 w-2 rounded-sm bg-muted-foreground/30 shrink-0"}),n.jsxs("span",{className:"text-xs text-muted-foreground",children:["Other ",h.toFixed(1),"%"]})]}),e[20]=h,e[21]=r,e[22]=x):x=e[22];let y;e[23]!==b||e[24]!==x||e[25]!==_?(y=n.jsxs("div",{className:"flex flex-wrap gap-x-3 gap-y-1",children:[_,b,x]}),e[23]=b,e[24]=x,e[25]=_,e[26]=y):y=e[26];let w;return e[27]!==y||e[28]!==f?(w=n.jsxs("div",{className:"flex flex-col gap-2",children:[f,y]}),e[27]=y,e[28]=f,e[29]=w):w=e[29],w}function bp(t){const e=K.c(11),{agentId:s,isError:i}=t,r=Mt(s),o=r?.title??"Subtask",a=r?.icon??null;let l;e[0]!==a||e[1]!==o?(l=n.jsx(Gt,{icon:a,name:o,size:"xs",className:"size-6 rounded-md shrink-0"}),e[0]=a,e[1]=o,e[2]=l):l=e[2];const h=i?"text-destructive":"text-foreground";let c;e[3]!==h?(c=he("shrink-0 font-medium",h),e[3]=h,e[4]=c):c=e[4];let d;e[5]!==o||e[6]!==c?(d=n.jsx("span",{className:c,children:o}),e[5]=o,e[6]=c,e[7]=d):d=e[7];let u;return e[8]!==l||e[9]!==d?(u=n.jsxs(n.Fragment,{children:[l,d]}),e[8]=l,e[9]=d,e[10]=u):u=e[10],u}function yp(t){const e=K.c(5),{isError:s}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=n.jsx(Gt,{icon:null,name:"Subtask",size:"xs",className:"size-6 rounded-md shrink-0"}),e[0]=i):i=e[0];const r=s?"text-destructive":"text-foreground";let o;e[1]!==r?(o=he("shrink-0 font-medium",r),e[1]=r,e[2]=o):o=e[2];let a;return e[3]!==o?(a=n.jsxs(n.Fragment,{children:[i,n.jsx("span",{className:o,children:"Subtask"})]}),e[3]=o,e[4]=a):a=e[4],a}function Sp(t){const e=K.c(18),{part:s}=t,i=s.input?.agent_id,r=s.state==="input-streaming"||s.state==="input-available"||s.state==="output-available"&&s.preliminary===!0,o=s.state==="output-error",a=s.state==="approval-requested";let l;e[0]!==o?(l=n.jsx(yp,{isError:o}),e[0]=o,e[1]=l):l=e[1];let h;e[2]!==i||e[3]!==o?(h=n.jsx(bp,{agentId:i,isError:o}),e[2]=i,e[3]=o,e[4]=h):h=e[4];let c;e[5]!==l||e[6]!==h?(c=n.jsx(E.Suspense,{fallback:l,children:h}),e[5]=l,e[6]=h,e[7]=c):c=e[7];let d;e[8]!==s.input?(d=s.input?.prompt&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"text-muted-foreground/50",children:"·"}),n.jsx("span",{className:"truncate text-muted-foreground",children:s.input.prompt})]}),e[8]=s.input,e[9]=d):d=e[9];let u;e[10]!==a||e[11]!==o||e[12]!==r?(u=n.jsx("span",{className:"ml-auto shrink-0",children:r?n.jsx(Ce,{size:12,className:"animate-spin text-muted-foreground"}):o?n.jsx(of,{size:12,className:"text-destructive"}):a?n.jsx(Ui,{size:12,className:"text-warning"}):n.jsx(zc,{size:12,className:"text-emerald-500"})}),e[10]=a,e[11]=o,e[12]=r,e[13]=u):u=e[13];let f;return e[14]!==c||e[15]!==d||e[16]!==u?(f=n.jsxs("div",{className:"flex items-center gap-2 text-xs min-w-0",children:[c,d,u]}),e[14]=c,e[15]=d,e[16]=u,e[17]=f):f=e[17],f}function wp(t){const e=K.c(55),{onClose:s,back:i,className:r}=t,[o,a]=E.useState(null),{messages:l}=Ns(),{activeTask:h}=ss(),{selectedModel:c,selectedVirtualMcp:d}=Wo();let u,f,m,p,_,g,v,b;if(e[0]!==h||e[1]!==i||e[2]!==r||e[3]!==l||e[4]!==s||e[5]!==o?.id||e[6]!==c||e[7]!==d?.title){b=Symbol.for("react.early_return_sentinel");e:{const w=lf(l),C=[...l].reverse().find(Ip),j=C?.metadata?.usage,R=C?.metadata?.modelLimits?.contextWindow??c?.limits?.contextWindow??null,B=j?.contextTokens??0,P=R&&R>0?(B/R*100).toFixed(1):null,T=l;let S;e[16]!==T?(S=T.filter(Ap).reduce(Dp,0),e[16]=T,e[17]=S):S=e[17];const k=S,I=l;let N;e[18]!==I?(N=I.filter(Pp).reduce(Rp,0),e[18]=I,e[19]=N):N=e[19];const A=N,M=Math.max(0,w.totalTokens-k-A),D=l[0],$=l.at(-1),z=D?.metadata?.created_at??h?.created_at,W=$?.metadata?.created_at??h?.updated_at,F=l.filter(Tp),V=l.flatMap(Np),J=c?.modelId?_p(c.modelId):"—",Y=d?.title??"Decopilot",U=[{label:"Session",value:h?.title??"New chat"},{label:"Messages",value:F.length},{label:"Agent",value:Y},{label:"Model",value:J},{label:"Context Limit",value:R?ui(R):"—"},{label:"Session Tokens (billed)",value:w.totalTokens>0?ui(w.totalTokens):"0"},{label:"Usage",value:P!==null?`${P}%`:"—"},{label:"Input Tokens",value:w.inputTokens>0?ui(w.inputTokens):"0"},{label:"Output Tokens",value:w.outputTokens>0?ui(w.outputTokens):"0"},{label:"Reasoning Tokens",value:w.reasoningTokens>0?ui(w.reasoningTokens):"0"},{label:"Cost",value:w.cost>0?`$${w.cost<.001?w.cost.toFixed(6):w.cost.toFixed(4)}`:"$0.00"},{label:"Session Created",value:Qa(z)},{label:"Last Activity",value:Qa(W)}];if(!h&&F.length===0){let L;e[20]!==r?(L=he("flex flex-col h-full w-full border-l border-border bg-background",r),e[20]=r,e[21]=L):L=e[21];let se;e[22]===Symbol.for("react.memo_cache_sentinel")?(se=n.jsx("span",{className:"text-sm font-medium text-foreground",children:"Context"}),e[22]=se):se=e[22];let ee;e[23]!==i?(ee=i?n.jsx(Ha,{size:14,className:"text-muted-foreground"}):n.jsx(ps,{size:14,className:"text-muted-foreground"}),e[23]=i,e[24]=ee):ee=e[24];let Q;e[25]!==s||e[26]!==ee?(Q=n.jsxs("div",{className:"h-11 px-4 flex items-center justify-between shrink-0 border-b border-border/50",children:[se,n.jsx("button",{type:"button",onClick:s,className:"flex size-6 items-center justify-center rounded hover:bg-accent transition-colors",children:ee})]}),e[25]=s,e[26]=ee,e[27]=Q):Q=e[27];let O;e[28]===Symbol.for("react.memo_cache_sentinel")?(O=n.jsx("div",{className:"flex-1 flex items-center justify-center px-4 text-center",children:n.jsx("p",{className:"text-xs text-muted-foreground",children:"Start a conversation to see context"})}),e[28]=O):O=e[28];let ce;e[29]!==L||e[30]!==Q?(ce=n.jsxs("div",{className:L,children:[Q,O]}),e[29]=L,e[30]=Q,e[31]=ce):ce=e[31],b=ce;break e}e[32]!==r?(g=he("flex flex-col h-full w-full border-l border-border bg-background overflow-y-auto",r),e[32]=r,e[33]=g):g=e[33];let H;e[34]===Symbol.for("react.memo_cache_sentinel")?(H=n.jsx("span",{className:"text-sm font-medium text-foreground",children:"Context"}),e[34]=H):H=e[34];let X;e[35]!==i?(X=i?n.jsx(Ha,{size:14}):n.jsx(ps,{size:14}),e[35]=i,e[36]=X):X=e[36],e[37]!==s||e[38]!==X?(v=n.jsxs("div",{className:"flex h-11 shrink-0 items-center justify-between border-b border-border/50 px-4",children:[H,n.jsx("button",{type:"button",onClick:s,className:"flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",children:X})]}),e[37]=s,e[38]=X,e[39]=v):v=e[39],u="flex flex-col gap-8 p-6",f=V.length>0&&n.jsxs("div",{className:"flex flex-col gap-3",children:[n.jsx("span",{className:"text-xs text-muted-foreground",children:"Subtasks"}),n.jsx("div",{className:"flex flex-col gap-1",children:V.map(jp)})]}),m=n.jsx(gp,{items:U});let oe;e[40]===Symbol.for("react.memo_cache_sentinel")?(oe=n.jsx("span",{className:"text-xs text-muted-foreground",children:"Context Breakdown"}),e[40]=oe):oe=e[40],e[41]!==A||e[42]!==M||e[43]!==k?(p=n.jsxs("div",{className:"flex flex-col gap-3",children:[oe,n.jsx(xp,{userTokens:k,assistantTokens:A,otherTokens:M})]}),e[41]=A,e[42]=M,e[43]=k,e[44]=p):p=e[44],_=F.length>0&&n.jsxs("div",{className:"flex flex-col gap-3",children:[n.jsx("span",{className:"text-xs text-muted-foreground",children:"Raw messages"}),n.jsx("div",{className:"flex flex-col gap-1",children:F.map(L=>{const se=L.metadata?.created_at,ee=o?.id===L.id;return n.jsxs("div",{className:"rounded-md border border-border/50 overflow-hidden",children:[n.jsxs("button",{type:"button",onClick:()=>a(ee?null:L),className:"flex items-center justify-between gap-2 px-3 py-2 text-xs hover:bg-accent/50 w-full text-left cursor-pointer",children:[n.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[n.jsx("span",{className:he("shrink-0 font-medium",L.role==="user"?"text-chart-1":"text-chart-2"),children:L.role}),n.jsx("span",{className:"text-muted-foreground",children:"•"}),n.jsx("span",{className:"truncate text-muted-foreground font-mono",children:L.id})]}),se&&n.jsx("span",{className:"shrink-0 text-muted-foreground tabular-nums",children:new Date(se).toLocaleString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit"})})]}),ee&&n.jsxs(n.Fragment,{children:[L.role==="assistant"&&(()=>{const Q=L.metadata?._request;if(!Q)return null;const O=Q.systemSections??[],ce=Math.max(1,...O.map(kp)),ue=O.reduce(Cp,0);return n.jsxs("div",{className:"border-t border-border/50 px-3 py-2.5 text-xs space-y-2.5",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("span",{className:"font-medium text-foreground",children:"Request"}),n.jsxs("span",{className:"text-muted-foreground tabular-nums",children:[Q.activeTools??0," / ",Q.tools??0," ","tools active"]})]}),O.length>0&&n.jsxs("div",{className:"space-y-1.5",children:[n.jsxs("div",{className:"text-muted-foreground",children:["System prompt"," ",n.jsxs("span",{className:"tabular-nums",children:["~",Math.round(ue/4).toLocaleString()," ","tok"]})]}),O.map((fe,q)=>{const te=fe.preview.match(/^<([a-z-]+)/i)?.[1]??`section ${q}`,me=fe.chars/ce*100,ne=Math.round(fe.chars/4);return n.jsxs("div",{className:"space-y-0.5",children:[n.jsxs("div",{className:"flex items-center justify-between gap-2",children:[n.jsx("span",{className:"font-mono text-foreground truncate",children:te}),n.jsxs("span",{className:"text-muted-foreground tabular-nums shrink-0",children:["~",ne.toLocaleString()," tok"]})]}),n.jsx("div",{className:"h-1 w-full rounded-full bg-muted overflow-hidden",children:n.jsx("div",{className:"h-full rounded-full bg-chart-3",style:{width:`${me}%`}})})]},q)})]})]})})(),n.jsx("pre",{className:"text-xs font-mono bg-muted px-3 py-2 overflow-auto whitespace-pre-wrap break-all border-t border-border/50 max-h-64",children:JSON.stringify(L,null,2)})]})]},L.id)})})]})}e[0]=h,e[1]=i,e[2]=r,e[3]=l,e[4]=s,e[5]=o?.id,e[6]=c,e[7]=d?.title,e[8]=u,e[9]=f,e[10]=m,e[11]=p,e[12]=_,e[13]=g,e[14]=v,e[15]=b}else u=e[8],f=e[9],m=e[10],p=e[11],_=e[12],g=e[13],v=e[14],b=e[15];if(b!==Symbol.for("react.early_return_sentinel"))return b;let x;e[45]!==u||e[46]!==f||e[47]!==m||e[48]!==p||e[49]!==_?(x=n.jsxs("div",{className:u,children:[f,m,p,_]}),e[45]=u,e[46]=f,e[47]=m,e[48]=p,e[49]=_,e[50]=x):x=e[50];let y;return e[51]!==g||e[52]!==v||e[53]!==x?(y=n.jsxs("div",{className:g,children:[v,x]}),e[51]=g,e[52]=v,e[53]=x,e[54]=y):y=e[54],y}function Cp(t,e){return t+e.chars}function kp(t){return t.chars}function jp(t,e){return n.jsx(Sp,{part:t},e)}function Np(t){return(t.parts??[]).filter(Ep)}function Ep(t){return t.type==="tool-subtask"}function Tp(t){return t.role!=="system"}function Rp(t,e){const s=e.metadata?.usage;return t+(s?.outputTokens??0)}function Pp(t){return t.role==="assistant"}function Dp(t,e){const s=e.metadata?.usage;return t+(s?.inputTokens??0)}function Ap(t){return t.role==="user"}function Ip(t){return t.role==="assistant"&&t.metadata?.usage}function Bp(t){const e=K.c(13),{readOnly:s,identity:i,aboveRow:r,input:o,iceBreakers:a}=t,l=!s&&i?i:null;let h;e[0]!==r||e[1]!==s?(h=!s&&r?n.jsx("div",{"data-chat-above-row":"true",className:"@container/chat-bottom flex justify-start gap-1",children:r}):null,e[0]=r,e[1]=s,e[2]=h):h=e[2];let c;e[3]!==o||e[4]!==h?(c=n.jsxs("div",{className:"flex flex-col gap-2",children:[h,o]}),e[3]=o,e[4]=h,e[5]=c):c=e[5];let d;e[6]!==a||e[7]!==s?(d=!s&&a?n.jsx("div",{className:"w-full",children:a}):null,e[6]=a,e[7]=s,e[8]=d):d=e[8];let u;return e[9]!==l||e[10]!==c||e[11]!==d?(u=n.jsx("div",{"data-chat-centered":"true",className:"h-full w-full flex flex-col items-center justify-center px-4 gap-6",children:n.jsxs("div",{className:"w-full max-w-3xl flex flex-col gap-6",children:[l,c,d]})}),e[9]=l,e[10]=c,e[11]=d,e[12]=u):u=e[12],u}function Mp(t){const e=K.c(25),{onOpenContextPanel:s}=t,{org:i}=Pe(),{selectedVirtualMcp:r}=Wo();let o;e[0]!==i.id?(o=Fo(i.id),e[0]=i.id,e[1]=o):o=e[1];const l=r??o,h=Mt(l.id),c=$c(),{data:d}=Js.useSession(),u=d?.user?.id,f=c?.activeTask??null,m=!!(u&&f?.created_by&&f.created_by!==u);let p;e[2]===Symbol.for("react.memo_cache_sentinel")?(p=n.jsx(gf,{size:32}),e[2]=p):p=e[2];let _;e[3]!==l.icon||e[4]!==l.title?(_=n.jsx(Gt,{icon:l.icon,name:l.title,size:"lg",fallbackIcon:p,className:"size-10 min-w-10 md:size-[60px]! md:min-w-[60px] rounded-xl md:rounded-[18px]!"}),e[3]=l.icon,e[4]=l.title,e[5]=_):_=e[5];let g;e[6]!==l.title?(g=n.jsx("h3",{className:"text-base md:text-xl font-medium text-foreground",children:l.title}),e[6]=l.title,e[7]=g):g=e[7];const v=l.description??"Ask anything about configuring model providers or using MCP Mesh.";let b;e[8]!==v?(b=n.jsx("div",{className:"text-muted-foreground text-center text-base max-w-md line-clamp-2",children:v}),e[8]=v,e[9]=b):b=e[9];let x;e[10]!==_||e[11]!==g||e[12]!==b?(x=n.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 md:gap-4 text-center",children:[_,g,b]}),e[10]=_,e[11]=g,e[12]=b,e[13]=x):x=e[13];const y=c?.currentBranch??null;let w;e[14]!==h||e[15]!==y?(w=n.jsx(Vu,{virtualMcp:h,currentBranch:y}),e[14]=h,e[15]=y,e[16]=w):w=e[16];let C;e[17]!==s?(C=n.jsx(Oe.Input,{onOpenContextPanel:s}),e[17]=s,e[18]=C):C=e[18];let j;e[19]===Symbol.for("react.memo_cache_sentinel")?(j=n.jsx(Oe.IceBreakers,{}),e[19]=j):j=e[19];let R;return e[20]!==m||e[21]!==C||e[22]!==x||e[23]!==w?(R=n.jsx(Bp,{readOnly:m,identity:x,aboveRow:w,input:C,iceBreakers:j}),e[20]=m,e[21]=C,e[22]=x,e[23]=w,e[24]=R):R=e[24],R}function el(t){const e=K.c(17),{outputs:s,collapsed:i,onToggle:r,variant:o}=t,a=o==="card"?"rounded-xl border border-border bg-muted/95 shadow-sm backdrop-blur-sm":"border-b border-border bg-background";let l;e[0]!==a?(l=he(a),e[0]=a,e[1]=l):l=e[1];let h;e[2]===Symbol.for("react.memo_cache_sentinel")?(h=n.jsx("span",{className:"text-sm font-medium text-foreground",children:"Files in this task"}),e[2]=h):h=e[2];const c=i&&"-rotate-90";let d;e[3]!==c?(d=he("size-4 text-muted-foreground transition-transform",c),e[3]=c,e[4]=d):d=e[4];let u;e[5]!==d?(u=n.jsx(Es,{className:d}),e[5]=d,e[6]=u):u=e[6];let f;e[7]!==r||e[8]!==u?(f=n.jsxs("button",{type:"button",onClick:r,className:"flex w-full items-center justify-between px-3 py-2.5 text-left",children:[h,u]}),e[7]=r,e[8]=u,e[9]=f):f=e[9];let m;e[10]!==i||e[11]!==s?(m=!i&&n.jsx("div",{className:"flex max-h-72 flex-col gap-1.5 overflow-y-auto px-2 pb-2",children:s.map(Lp)}),e[10]=i,e[11]=s,e[12]=m):m=e[12];let p;return e[13]!==l||e[14]!==f||e[15]!==m?(p=n.jsxs("div",{className:l,children:[f,m]}),e[13]=l,e[14]=f,e[15]=m,e[16]=p):p=e[16],p}function Lp(t){return n.jsx(hf,{file:t},t.key)}function Op(){const t=K.c(13),e=$c()?.taskId??null,s=cf();let i;t[0]!==s?(i={enabled:s},t[0]=s,t[1]=i):i=t[1];const{data:r}=Fc(e,i),[o,a]=E.useState(!1),[l,h]=E.useState(!0);if(!e||!r||r.length===0)return null;let c;t[2]===Symbol.for("react.memo_cache_sentinel")?(c=()=>a(zp),t[2]=c):c=t[2];let d;t[3]!==o||t[4]!==r?(d=n.jsx("div",{className:"absolute top-2 right-2 z-10 hidden w-72 @[1280px]:block",children:n.jsx(el,{variant:"card",outputs:r,collapsed:o,onToggle:c})}),t[3]=o,t[4]=r,t[5]=d):d=t[5];let u;t[6]===Symbol.for("react.memo_cache_sentinel")?(u=()=>h($p),t[6]=u):u=t[6];let f;t[7]!==l||t[8]!==r?(f=n.jsx("div",{className:"shrink-0 @[1280px]:hidden",children:n.jsx(el,{variant:"bar",outputs:r,collapsed:l,onToggle:u})}),t[7]=l,t[8]=r,t[9]=f):f=t[9];let m;return t[10]!==d||t[11]!==f?(m=n.jsxs(n.Fragment,{children:[d,f]}),t[10]=d,t[11]=f,t[12]=m):m=t[12],m}function $p(t){return!t}function zp(t){return!t}function Fp(){const t=K.c(28),{org:e}=Pe(),s=Hc(),{isChatEmpty:i}=Ns(),[r,o]=E.useState("chat"),a=vf(),{selectedVirtualMcp:l}=Wo();let h;t[0]!==e.id?(h=Fo(e.id),t[0]=e.id,t[1]=h):h=t[1];const u=Mt((l??h).id),f=sf(),m=ti(u?.metadata);if(s.length===0&&!(m&&qu(f))){let T;return t[2]===Symbol.for("react.memo_cache_sentinel")?(T=n.jsx(Oe,{className:"animate-in fade-in-0 duration-200",children:n.jsx(Oe.Main,{className:"flex flex-col items-center",children:n.jsx(Oe.EmptyState,{children:n.jsx(Oe.NoAiProviderEmptyState,{})})})}),t[2]=T):T=t[2],T}let _;t[3]!==a.hasDecoKey||t[4]!==a.hasOnlyDecoProvider||t[5]!==a.isLoading||t[6]!==a.isZeroBalance||t[7]!==i||t[8]!==e.id?(_=a.hasDecoKey&&a.isZeroBalance&&a.hasOnlyDecoProvider&&!a.isLoading&&i&&!Gu(e.id),t[3]=a.hasDecoKey,t[4]=a.hasOnlyDecoProvider,t[5]=a.isLoading,t[6]=a.isZeroBalance,t[7]=i,t[8]=e.id,t[9]=_):_=t[9];const g=_;let v;t[10]!==g?(v=g&&n.jsx(Oe.CreditsEmptyState,{}),t[10]=g,t[11]=v):v=t[11];const b=r!=="chat"?"opacity-0 pointer-events-none":"opacity-100";let x;t[12]!==b?(x=he("absolute inset-0 flex flex-col transition-opacity duration-100 ease-out",b),t[12]=b,t[13]=x):x=t[13];let y;t[14]!==i?(y=i?n.jsx(Oe.Main,{children:n.jsx(Mp,{onOpenContextPanel:()=>o("context")})}):n.jsxs(n.Fragment,{children:[n.jsxs(Oe.Main,{className:"relative flex flex-col overflow-hidden @container",children:[n.jsx(Op,{}),n.jsx("div",{className:"min-h-0 flex-1",children:n.jsx(Oe.Messages,{})})]}),n.jsx(Oe.Footer,{children:n.jsx(Oe.Input,{onOpenContextPanel:()=>o("context")})})]}),t[14]=i,t[15]=y):y=t[15];let w;t[16]!==x||t[17]!==y?(w=n.jsx("div",{className:x,children:y}),t[16]=x,t[17]=y,t[18]=w):w=t[18];const C=r==="context"?"opacity-100":"opacity-0 pointer-events-none";let j;t[19]!==C?(j=he("absolute inset-0 flex flex-col transition-opacity duration-100 ease-out",C),t[19]=C,t[20]=j):j=t[20];let R;t[21]===Symbol.for("react.memo_cache_sentinel")?(R=n.jsx(wp,{back:!0,onClose:()=>o("chat")}),t[21]=R):R=t[21];let B;t[22]!==j?(B=n.jsx("div",{className:j,children:R}),t[22]=j,t[23]=B):B=t[23];let P;return t[24]!==B||t[25]!==v||t[26]!==w?(P=n.jsxs(Oe,{className:"relative overflow-hidden animate-in fade-in-0 duration-200",children:[v,w,B]}),t[24]=B,t[25]=v,t[26]=w,t[27]=P):P=t[27],P}function gh(){const t=K.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=n.jsx(Oe.Skeleton,{}),t[0]=e):e=t[0];let s;return t[1]===Symbol.for("react.memo_cache_sentinel")?(s=n.jsx(Ut,{fallback:e,children:n.jsx(E.Suspense,{fallback:n.jsx(Oe.Skeleton,{}),children:n.jsx(Fp,{})})}),t[1]=s):s=t[1],s}function Hp(t){const e=t.entityMetadata?.defaultMainView??null,s=e==null||e.type==="chat",i=t.mainParamPresent?t.mainParamValue!=="0":!s,r=s?!0:t.entityMetadata?.chatDefaultOpen??!1;return{mainOpen:i,chatOpen:r}}function tl(t,e){return t&&e?{chat:45,main:55}:t&&!e?{chat:100,main:0}:!t&&e?{chat:0,main:100}:{chat:0,main:0}}function Wp(t,e){return t===1?!0:t===0?!1:e}function Up(t,e){const s=ts(),i=$o({strict:!1}),r=Ac({strict:!1}),{create:o}=em(),{locator:a}=Pe(),{virtualMcpId:l,orgSlug:h,isAgentRoute:c}=e,d=Hp({entityMetadata:t,mainParamPresent:i.main!==void 0,mainParamValue:i.main}),u=Wp(i.chat,d.chatOpen),f=d.mainOpen,m=E.useRef(crypto.randomUUID()),p=r.taskId??m.current,_="/$org/$taskId",g=B=>({org:h,taskId:B}),v=c?{virtualmcpid:l}:{},b=(B,P)=>{s({to:_,params:g(p),search:T=>({...T,...B}),replace:P?.replace??!1})},x=(B,P)=>{s({to:_,params:g(B),search:T=>{const S={};return P?S.virtualmcpid=P:c&&(S.virtualmcpid=l),S}})},y=()=>{f?b({main:"0"},{replace:!0}):b({main:Fn(t)},{replace:!0})},w=()=>{b({chat:u?0:1},{replace:!0})},C=()=>{u||b({chat:1},{replace:!0})},j=async()=>{const B=crypto.randomUUID(),P=bf(h,a,p);try{await o({id:B,virtual_mcp_id:l,...P?{branch:P}:{}})}catch{}s({to:_,params:g(B),search:T=>({...v,chat:1})})},R=B=>{b({main:B},{replace:!0})};return{taskId:p,mainOpen:f,chatOpen:u,mainParam:i.main,setTaskId:x,toggleMain:y,toggleChat:w,openChat:C,createNewTask:j,openTab:R}}const ra=45;function vh(t,e=ra){const s=typeof t=="number"?t:Number(t);return!Number.isFinite(s)||s<=0||s>=100?e:s}function Kp(t){return vh(t,ra)}function Vp(){const t=K.c(6);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=Mu.decoChatPanelWidth(),t[0]=e):e=t[0];const[s,i]=Bu(e,Kp);let r;t[1]!==s?(r=vh(s,ra),t[1]=s,t[2]=r):r=t[2];const o=r;let a;return t[3]!==i||t[4]!==o?(a=[o,i],t[3]=i,t[4]=o,t[5]=a):a=t[5],a}function qp(t){try{return JSON.parse(t)}catch{return null}}function Gp(t){if(!t||typeof t!="object")return null;const e=t,s=e.content?.find(o=>o.type==="text")?.text,i=s?qp(s):null,r=e.structuredContent;return r==null?i:typeof r=="object"&&!Array.isArray(r)&&Object.keys(r).length===0?i??r:r}function Bs(t){const e=Gp(t);return e===null?null:e}function na(t){if(!t)return null;const e=t.match(/\/pull\/(\d+)\b/);if(!e)return null;const s=Number(e[1]);return Number.isFinite(s)&&s>0?s:null}function Yp(t){if(!t||typeof t!="object")return null;const e=t.content?.find(r=>r.type==="text")?.text;if(!e)return null;const s=e.match(/https:\/\/github\.com\/[^\s"]+\/pull\/\d+/)?.[0],i=na(s);return!i||!s?null:{number:i,htmlUrl:s}}const sl=/[\r\n<>]/,Xp=/^[^\s@<>]+@[^\s@<>]+\.[^\s@<>]+$/;function Yi(t){const e=t?.userName?.trim();if(!e||sl.test(e))return null;const s=t?.userEmail?.trim();return!s||sl.test(s)?{userName:e}:Xp.test(s)?{userName:e,userEmail:s}:{userName:e}}function Jp(t){return t.split(`
|
|
3
3
|
`).filter(e=>!/^Co-authored-by:\s/i.test(e)).join(`
|
|
4
4
|
`).trimEnd()}function Zp(t){const e=t.userName.trim(),s=t.userEmail?.trim();return s?`Co-authored-by: ${e} <${s}>`:`Co-authored-by: ${e}`}function xh(t,e){const s=Yi(e);if(!s)return t;const i=Jp(t),r=Zp(s);if(i.includes(r))return i;const o=i.trimEnd();return o.length>0?`${o}
|
|
5
5
|
|
|
6
6
|
${r}`:r}function bh(t,e){const s=t?.trim();return s?xh(s,e):s||void 0}const Qp=["dev","start"];function e_(t){if(!t||typeof t!="object")return null;const e=t;return e.isError?e.content?.find(i=>i.type==="text")?.text?.trim()||"GitHub MCP tool returned an error":null}function oa(t){const e=e_(t);if(e)throw new Error(e)}function yh(t,e){for(const s of e){const i=t[s];if(typeof i=="string"&&i.length>0)return i}}function Sh(t,e){for(const s of e){const i=t[s];if(typeof i=="number"&&Number.isFinite(i)&&i>0)return i;if(typeof i=="string"&&/^\d+$/.test(i)){const r=Number(i);if(r>0)return r}}}function t_(t){const s=t.head?.ref;return typeof s=="string"&&s.length>0?s:null}function s_(t,e){return t_(t)===e}function wh(t){const e=Bs(t);if(Array.isArray(e))return e.filter(s=>s!=null&&typeof s=="object");if(e&&typeof e=="object"){const s=e;for(const i of["pull_requests","items","data"]){const r=s[i];if(Array.isArray(r))return r.filter(o=>o!=null&&typeof o=="object")}}return[]}function i_(t){const e=yh(t,["html_url","htmlUrl","url","URL"]),s=Sh(t,["number","pullNumber"])??na(e);return!s||!e?null:{number:s,htmlUrl:e}}function r_(t){oa(t);const e=Yp(t);if(e)return e;const s=Bs(t);if(s&&typeof s=="object"){const i=yh(s,["url","URL","html_url","htmlUrl"]),r=Sh(s,["number","pullNumber"])??na(i);if(r&&i)return{number:r,htmlUrl:i}}throw new Error("Failed to open pull request")}function n_(t){return/already exists|pull request already/i.test(t)}async function o_(t,e){const s=await t.callTool({name:"list_pull_requests",arguments:{owner:e.owner,repo:e.repo,state:"open",...e.head?{head:e.head}:{},perPage:10}});return oa(s),wh(s)}async function il(t,e){const s=[`${e.owner}:${e.branch}`,e.branch];for(const i of s){const o=(await o_(t,{owner:e.owner,repo:e.repo,head:i})).find(l=>s_(l,e.branch)),a=o?i_(o):null;if(a)return a}return null}async function a_(t,e){const s=bh(e.body,Yi(e.coAuthor));if(s)try{await t.callTool({name:"update_pull_request",arguments:{owner:e.owner,repo:e.repo,pullNumber:e.pullNumber,body:s}})}catch{}}async function l_(t,e){const s=bh(e.body,Yi(e.coAuthor)),i=await t.callTool({name:"create_pull_request",arguments:{owner:e.owner,repo:e.repo,title:e.title,body:s||void 0,head:e.head,base:e.base}});return r_(i)}async function rl(t,e){const s=await il(t,{owner:e.owner,repo:e.repo,branch:e.branch});if(s)return await a_(t,{owner:e.owner,repo:e.repo,pullNumber:s.number,body:e.body,coAuthor:e.coAuthor}),s;try{return await l_(t,{owner:e.owner,repo:e.repo,title:e.title,body:e.body,head:e.branch,base:e.base,coAuthor:e.coAuthor})}catch(i){const r=i instanceof Error?i.message:String(i);if(!n_(r))throw i;const o=await il(t,{owner:e.owner,repo:e.repo,branch:e.branch});if(o)return o;throw i}}async function Ch(t,e){const s=Yi(e.coAuthor),i=s?xh(e.commitMessage?.trim()??"",s):e.commitMessage?.trim()||void 0,r=await t.callTool({name:"merge_pull_request",arguments:{owner:e.owner,repo:e.repo,pullNumber:e.pullNumber,merge_method:"squash",...e.commitTitle?{commit_title:e.commitTitle}:{},...i?{commit_message:i}:{}}});oa(r);const o=Bs(r);if(!o||o.merged!==!0)throw new Error(o?.message??"Failed to merge pull request");return{merged:!0,message:o.message??"Pull request merged"}}const aa=6e4,la=3e4;function ca(t){const e=K.c(15);let s;e[0]!==t.connectionId||e[1]!==t.orgId||e[2]!==t.orgSlug?(s={connectionId:t.connectionId,orgId:t.orgId,orgSlug:t.orgSlug},e[0]=t.connectionId,e[1]=t.orgId,e[2]=t.orgSlug,e[3]=s):s=e[3];const i=ft(s);let r;e[4]!==t.branch||e[5]!==t.owner?(r=t.branch?{head:`${t.owner}:${t.branch}`}:{},e[4]=t.branch,e[5]=t.owner,e[6]=r):r=e[6];let o;e[7]!==t.owner||e[8]!==t.repo||e[9]!==r?(o={owner:t.owner,repo:t.repo,state:"all",...r,perPage:1},e[7]=t.owner,e[8]=t.repo,e[9]=r,e[10]=o):o=e[10];const a=!!t.branch&&!!t.connectionId&&!!t.owner&&!!t.repo;let l;return e[11]!==i||e[12]!==o||e[13]!==a?(l={client:i,toolName:"list_pull_requests",toolArguments:o,enabled:a,refetchInterval:aa,refetchIntervalInBackground:!1,staleTime:la,select:c_},e[11]=i,e[12]=o,e[13]=a,e[14]=l):l=e[14],sn(l)}function c_(t){const e=wh(t);if(e.length===0)return null;const s=e[0],i=s.base,r=s.head,o=s.user;return{number:s.number??0,title:s.title??"",body:s.body??"",state:s.state==="closed"?"closed":"open",merged:s.merged_at!=null,mergedAt:s.merged_at??null,base:i?.ref??"main",head:r?.ref??"",headSha:r?.sha??"",htmlUrl:s.html_url??"",author:o?.login??""}}function kh(t){const e=K.c(12);let s;e[0]!==t.connectionId||e[1]!==t.orgId||e[2]!==t.orgSlug?(s={connectionId:t.connectionId,orgId:t.orgId,orgSlug:t.orgSlug},e[0]=t.connectionId,e[1]=t.orgId,e[2]=t.orgSlug,e[3]=s):s=e[3];const i=ft(s),r=t.prNumber??0;let o;e[4]!==t.owner||e[5]!==t.repo||e[6]!==r?(o={method:"get_check_runs",owner:t.owner,repo:t.repo,pullNumber:r},e[4]=t.owner,e[5]=t.repo,e[6]=r,e[7]=o):o=e[7];const a=!!t.prNumber;let l;return e[8]!==i||e[9]!==o||e[10]!==a?(l={client:i,toolName:"pull_request_read",toolArguments:o,enabled:a,refetchInterval:aa,refetchIntervalInBackground:!1,staleTime:la,select:h_},e[8]=i,e[9]=o,e[10]=a,e[11]=l):l=e[11],sn(l)}function h_(t){const e=Bs(t);return(Array.isArray(e)?e:e?.check_runs??[]).map(d_)}function d_(t){const e=t.started_at,s=t.completed_at,i=e&&s?new Date(s).getTime()-new Date(e).getTime():null;return{id:String(t.id??""),name:String(t.name??""),status:t.status??"completed",conclusion:t.conclusion??null,htmlUrl:String(t.html_url??""),durationMs:i}}function u_(t){const e=K.c(12);let s;e[0]!==t.connectionId||e[1]!==t.orgId||e[2]!==t.orgSlug?(s={connectionId:t.connectionId,orgId:t.orgId,orgSlug:t.orgSlug},e[0]=t.connectionId,e[1]=t.orgId,e[2]=t.orgSlug,e[3]=s):s=e[3];const i=ft(s),r=t.prNumber??0;let o;e[4]!==t.owner||e[5]!==t.repo||e[6]!==r?(o={method:"get_comments",owner:t.owner,repo:t.repo,pullNumber:r},e[4]=t.owner,e[5]=t.repo,e[6]=r,e[7]=o):o=e[7];const a=!!t.prNumber;let l;return e[8]!==i||e[9]!==o||e[10]!==a?(l={client:i,toolName:"pull_request_read",toolArguments:o,enabled:a,refetchInterval:aa,refetchIntervalInBackground:!1,staleTime:la,select:f_},e[8]=i,e[9]=o,e[10]=a,e[11]=l):l=e[11],sn(l)}function f_(t){const e=Bs(t);return Array.isArray(e)?e.map(m_):[]}function m_(t){const e=t.user;return{id:Number(t.id??0),author:e?.login??"",body:String(t.body??""),createdAt:String(t.created_at??""),htmlUrl:String(t.html_url??"")}}function ha(t,e){const s=K.c(8),i=t?`${t.orgSlug}/${t.virtualMcpId}/${t.branch}`:"",r=e?.fetchEnabled??!0;let o;s[0]!==i?(o=Bt.decofile(i),s[0]=i,s[1]=o):o=s[1];let a;s[2]!==t?(a=async()=>{const c=new URLSearchParams({path:"/.decofile"}),d=await fetch(`/api/${t.orgSlug}/sandbox/${encodeURIComponent(t.virtualMcpId)}/${encodeURIComponent(t.branch)}/preview-fetch?${c.toString()}`);if(!d.ok){const u=new Error(`Failed to fetch decofile: ${d.status}`);throw u.status=d.status,u}return await d.json()},s[2]=t,s[3]=a):a=s[3];const l=!!t&&r;let h;return s[4]!==o||s[5]!==a||s[6]!==l?(h={queryKey:o,queryFn:a,enabled:l,staleTime:3e4,retry:__,retryDelay:p_},s[4]=o,s[5]=a,s[6]=l,s[7]=h):h=s[7],Zs(h)}function p_(t){return Math.min(1e3*2**t,5e3)}function __(t,e){return e.status!==502&&t<2}function da(t,e){const s=K.c(9),i=t?`${t.orgSlug}/${t.virtualMcpId}/${t.branch}`:"",r=e?.fetchEnabled??!0;let o;s[0]!==i?(o=Bt.liveMeta(i),s[0]=i,s[1]=o):o=s[1];let a;s[2]!==t?(a=async()=>{const d=new URLSearchParams({path:"/live/_meta"}),u=await fetch(`/api/${t.orgSlug}/sandbox/${encodeURIComponent(t.virtualMcpId)}/${encodeURIComponent(t.branch)}/preview-fetch?${d.toString()}`);if(!u.ok){const f=new Error(`Failed to fetch live meta: ${u.status}`);throw f.status=u.status,f}return await u.json()},s[2]=t,s[3]=a):a=s[3];const l=!!t&&r,h=e?.refetchInterval;let c;return s[4]!==o||s[5]!==a||s[6]!==l||s[7]!==h?(c={queryKey:o,queryFn:a,enabled:l,refetchInterval:h,refetchIntervalInBackground:!1,staleTime:3e5,retry:v_,retryDelay:g_},s[4]=o,s[5]=a,s[6]=l,s[7]=h,s[8]=c):c=s[8],Zs(c)}function g_(t){return Math.min(1e3*2**t,5e3)}function v_(t,e){return e.status!==502&&t<3}function x_(t){if(!t.startsWith("#")||!t.includes("@"))return null;const e=t.indexOf("@");return{moduleResolveType:t.slice(1,e),blockId:t.slice(e+1)}}function MC(t){return t.includes("@")}function nl(t){const e=t.lastIndexOf("@");return e<0||e===t.length-1?null:t.slice(e+1)}function LC(t,e){if(t===e)return!0;const s=nl(t);return s?e===s||nl(e)===s:!1}function ua(t,e){const s=t.manifest?.blocks??{};for(const[i,r]of Object.entries(s))if(e in r)return i;return null}function jh(t,e){const s=ua(t,e);return s!==null&&s.includes("sections")}function b_(t,e){const s=ua(t,e);return s!==null&&s.includes("apps")}function y_(t,e){const s=ua(t,e);return s!==null&&s.includes("matchers")}function fa(t){return!(/\.\w+$/.test(t)||t==="__proto__"||t==="constructor")}function Nh(t){try{return decodeURIComponent(t).startsWith("Preview ")}catch{return t.startsWith("Preview ")}}const OC="oklch(0.7278 0.151 289)",S_="website/matchers/always.ts",Eh="website/matchers/never.ts",on="website/flags/multivariate.ts",Th="website/flags/multivariate/section.ts";function ma(){return{__resolveType:S_}}function zr(t){const e=t.split("/");return(e[e.length-1]??t).replace(/\.(tsx?|jsx?)$/,"").replace(/[-_]/g," ").replace(/\b\w/g,i=>i.toUpperCase())||t}function w_(t){const e=t.type;return e==="array"||Array.isArray(e)&&e.includes("array")}const C_="VideoWidget";function Rh(t){const e=t.match(/^site\/apps\/([^/]+)\/([^/.]+)\.tsx?$/);return e?{vendor:e[1],app:e[2]}:null}function Ph(t){const e=t.match(/^([^/]+)\/apps\/([^/.]+)\.tsx?$/);return e?{vendor:e[1],app:e[2]}:null}function Dh(t,e){return[`site/apps/${t}/${e}.ts`,`site/apps/${t}/${e}.tsx`,`${t}/apps/${e}.ts`,`${t}/apps/${e}.tsx`]}function Ah(t,e){const s=e.manifest?.blocks??{};for(const r of Object.values(s))if(r[t])return r[t];const i=Rh(t)??Ph(t);if(!i)return{};for(const r of Dh(i.vendor,i.app))for(const o of Object.values(s))if(o[r])return o[r];return{}}function Gn(t,e){if(b_(t,e))return!0;const s=Rh(e)??Ph(e);if(!s)return!1;const i=t.manifest?.blocks?.apps??{};return Dh(s.vendor,s.app).some(r=>r in i)}function Ih(t,e){const s=e.schema??{},i=Ah(t,e),r=s.$defs??s.definitions??{},o=g=>{const v=g.split("/").pop()??"";return r[v]??{}};let a;typeof i.$ref=="string"?a=o(i.$ref):Object.keys(i).length>0?a=i:a=s;const l=g=>typeof g.$ref=="string"?o(g.$ref):g,h=g=>{const b=l(g).properties?.type;if(b){if(typeof b.const=="string")return b.const;if(typeof b.default=="string")return b.default;if(Array.isArray(b.enum)&&typeof b.enum[0]=="string")return b.enum[0]}},c=(g,v)=>{const b=l(g);return typeof b.title=="string"&&!b.title.startsWith("#")?b.title:v},d=(g,v=new Set)=>{if(typeof g.$ref!="string"||g.properties||g.anyOf||g.allOf||g.oneOf||g.type)return g;const b=g.$ref.split("/").pop()??"";return!b||v.has(b)?g:d(o(g.$ref),new Set([...v,b]))},u=g=>{const v=g.hide;return v===!0||v==="true"},f=(g,v=new Set,b=0)=>{if(b>5)return{};if(typeof g.$ref=="string"){const y=g.$ref.split("/").pop()??"";return v.has(y)?{}:f(o(g.$ref),new Set([...v,y]),b+1)}let x={};if(g.properties&&typeof g.properties=="object"&&(x={...x,...g.properties}),Array.isArray(g.required)){const y=Array.isArray(x.__required)?x.__required:[];x.__required=[...y,...g.required]}for(const y of["allOf","anyOf","oneOf"]){const w=g[y];if(Array.isArray(w))for(const C of w)x={...x,...f(C,v,b+1)}}return x},m=(g,v=0)=>{let b=g;typeof g.$ref=="string"&&(b=o(g.$ref),(g.$ref.split("/").pop()??"")===C_&&!b.format&&(b={...b,format:"video-uri"})),b=d(b);let x;{const P=b.anyOf??b.oneOf;if(Array.isArray(P)){const T=P.filter(k=>!(k.type==="null"||k.type===null)),S=k=>{if(typeof k.const=="string"||typeof k.const=="number")return k.const;if(Array.isArray(k.enum)&&k.enum.length===1&&(typeof k.enum[0]=="string"||typeof k.enum[0]=="number"))return k.enum[0]};T.length>0&&T.every(k=>S(k)!==void 0)&&(x=T.map(k=>S(k)))}}let y,w;if(b.type)y=Array.isArray(b.type)?String(b.type.find(P=>P!=="null")??b.type[0]):String(b.type);else if(b.anyOf||b.allOf||b.oneOf){const T=(b.anyOf??b.allOf??b.oneOf).filter(S=>!(S.type==="null"||S.type===null));if(T.length===0)y="null";else if(T.length===1){const S=T[0];w=S,y=S.type?Array.isArray(S.type)?String(S.type[0]):String(S.type):typeof S.$ref=="string"?"object":"string"}else{if(x)return{type:"string",title:typeof b.title=="string"?b.title:void 0,description:typeof b.description=="string"?b.description:void 0,enum:x};const S=T.filter(D=>{const $=D.properties?.__resolveType?.enum;return Array.isArray($)&&typeof $[0]=="string"}),k=T.find(w_),I=S.some(D=>{const $=D.properties?.__resolveType?.enum;return Array.isArray($)&&$[0]===on});if(k&&I){const D=m(k,v+1);return{...D,type:"array",title:typeof b.title=="string"?b.title:D.title,description:typeof b.description=="string"?b.description:D.description}}if(S.length>0){const D=S.map($=>{const W=$.properties?.__resolveType?.enum??[],F=String(W[0]);return{resolveType:F,title:typeof $.title=="string"?$.title:zr(F),description:typeof $.description=="string"?$.description:void 0,schema:v+1<6?m($,v+1):void 0}});return{type:"block-ref",title:typeof b.title=="string"?b.title:void 0,description:typeof b.description=="string"?b.description:void 0,anyOfRefs:D}}const N=T.map(D=>h(D));if(T.length>1&&N.every(D=>typeof D=="string")){const D=T.map(($,z)=>{const W=l($),F=N[z];return{resolveType:F,title:c($,F),description:typeof W.description=="string"?W.description:void 0,discriminatorValue:F,schema:v+1<6?m(W,v+1):void 0}});return{type:"block-ref",title:typeof g.title=="string"?g.title:typeof b.title=="string"?b.title:void 0,description:typeof g.description=="string"?g.description:typeof b.description=="string"?b.description:void 0,discriminatorKey:"type",anyOfRefs:D}}if(T.every(D=>typeof D.$ref=="string")){const D=[];for(const $ of T){const z=o($.$ref);let W,F;if(typeof z.title=="string"){const J=x_(z.title);J&&(W=J.blockId,F=J.blockId)}if(!W&&Array.isArray(z.allOf))for(const J of z.allOf){const H=((J.properties??{}).__resolveType??{}).enum;if(Array.isArray(H)&&typeof H[0]=="string"){W=H[0];break}}W||(W=$.$ref.split("/").pop()??"");const V=h($);D.push({resolveType:V??W,title:F??(typeof z.title=="string"&&!z.title.startsWith("#")?z.title:zr(W)),description:typeof z.description=="string"?z.description:void 0,discriminatorValue:V,schema:v+1<6?m(z,v+1):void 0})}return{type:"block-ref",title:typeof b.title=="string"?b.title:void 0,description:typeof b.description=="string"?b.description:void 0,anyOfRefs:D}}y="object"}}else typeof g.$ref=="string"&&(y="object");let C;if(v<6){const P=f(b),T=Object.entries(P).filter(([S])=>!S.startsWith("__")&&S!=="@type");if(T.length>0){C={};for(const[S,k]of T)C[S]=m(k,v+1)}}let j;if((y==="array"||b.type==="array")&&v<6){let P=b.items;P&&(typeof P.$ref=="string"&&(P=o(P.$ref)),j=m(P,v+1))}const R=P=>{const T=w?.[P];return typeof T=="string"?T:void 0},B=()=>{if("default"in g)return g.default;if("default"in b)return b.default;if(w&&"default"in w)return w.default};return{type:y??"string",title:typeof g.title=="string"?g.title:typeof b.title=="string"?b.title:R("title"),description:typeof g.description=="string"?g.description:typeof b.description=="string"?b.description:R("description"),default:B(),enum:Array.isArray(b.enum)?b.enum:x??void 0,format:typeof b.format=="string"?b.format:R("format"),properties:C,items:j,hidden:u(b)||u(g)?!0:void 0,titleBy:typeof b.titleBy=="string"?b.titleBy:R("titleBy"),image:typeof b.image=="string"?b.image:R("image")}},p=f(a),_={};for(const[g,v]of Object.entries(p))g.startsWith("__")||g==="@type"||(_[g]=m(v,0));return Object.keys(_).length===0?null:{type:"object",title:typeof a.title=="string"?a.title:void 0,properties:_}}function Xi(t,e){const s=e.schema??{},i=Ah(t,e),r=s.$defs??s.definitions??{},o=typeof i.$ref=="string"?r[i.$ref.split("/").pop()??""]??{}:Object.keys(i).length>0?i:{...s,...i},a=o.icon,l=o.logo;return{title:typeof o.title=="string"?o.title:void 0,description:typeof o.description=="string"?o.description:void 0,icon:typeof a=="string"?a:void 0,logo:typeof l=="string"?l:void 0}}function Us(t){return t.replace(/\/+$/,"")||"/"}function k_(t){const e=t.trim();return!(!e.startsWith("/")||e.startsWith("//")||e.includes("..")||e.includes("\\"))}function pa(t){const e=t.trim();return e?k_(e)?null:"Path must start with / and must not contain .. or //.":"Path is required."}const j_=["website/sections/Rendering/Lazy.tsx","website/sections/Rendering/SingleDeferred.tsx"],ol="website/sections/Rendering/Lazy.tsx";function es(t){return j_.some(e=>t.endsWith(e))}const Bh=["website/pages/Page.tsx","$live/pages/LivePage.tsx"],Mh=new Set(Bh),N_=new Set(["site/sections/Theme/Theme.tsx"]);function _a(t){return!!(N_.has(t)||es(t)||t.toLowerCase().includes("preview"))}function Lh(t){const e=t.manifest?.blocks??{};for(const s of Object.values(e))for(const i of Object.keys(s))if(Mh.has(i))return i;return Bh[0]}function Yn(t){if(!t)return[];if(t.anyOfRefs?.length)return t.anyOfRefs;if(t.items)return Yn(t.items);if(t.properties){const e=[];for(const s of Object.values(t.properties))e.push(...Yn(s));return e}return[]}function E_(t){const e=t.manifest?.blocks??{},s=[];for(const[i,r]of Object.entries(e))if(i.includes("sections"))for(const o of Object.keys(r)){if(_a(o))continue;const a=Xi(o,t);s.push({resolveType:o,title:a.title??zr(o),description:a.description,previewBlock:o,isSavedBlock:!1})}return s}function Oh(t,e){const s=[];for(const[i,r]of Object.entries(e)){if(i.includes("/")||Nh(i)||!r||typeof r!="object"||Array.isArray(r))continue;const o=r,a=o.__resolveType;typeof a=="string"&&(Mh.has(a)||typeof o.path!="string"&&(_a(a)||jh(t,a)&&s.push({resolveType:i,title:i,description:typeof o.name=="string"?o.name:void 0,previewBlock:i,isSavedBlock:!0})))}return s}function T_(t,e){const s=fa(e.resolveType),i=s?{}:Xi(e.resolveType,t);return{resolveType:e.resolveType,title:e.title||i.title||zr(e.resolveType),description:e.description??i.description,previewBlock:e.resolveType,isSavedBlock:s}}function $C(t,e){const s=Lh(t),i=Ih(s,t),r=Yn(i?.properties?.sections),o=new Map,a=l=>{if(!_a(l.resolveType)){if(fa(l.resolveType)){Nh(l.resolveType)||o.set(l.resolveType,l);return}jh(t,l.resolveType)&&(o.has(l.resolveType)||o.set(l.resolveType,l))}};for(const l of E_(t))a(l);for(const l of r)a(T_(t,l));for(const l of Oh(t,e))a(l);return[...o.values()].sort((l,h)=>l.title.localeCompare(h.title))}function zC(t){const e=t.site;if(!e||typeof e!="object"||Array.isArray(e))return;const s=e.theme;if(!(!s||typeof s!="object"||Array.isArray(s)))return s}function R_(t){let e=t;e.startsWith("pages-")&&(e=e.slice(6)),e=e.replace(/-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,""),e=e.replace(/-[0-9a-f]{8,}$/i,"");try{return decodeURIComponent(e)}catch{return e}}function P_(t,e,s){const i=Us;if(s){const o=t.find(a=>a.key===s);if(o)return o}const r=t.filter(o=>i(o.path)===i(e));return r.length===0?null:r.length===1?r[0]??null:[...r].sort((o,a)=>o.key.localeCompare(a.key))[0]??null}const $h=new Set(["website/pages/Page.tsx","$live/pages/LivePage.tsx"]),vr="site",Ri="site/apps/site.ts";function zh(t,e){return t===vr?!0:e.__resolveType===Ri}function ga(t,e){return t?va(t).length>0?!0:e?xa(t,e).length>0||Jn(t,e)?!0:D_(t,e).length>0:!1:!1}function va(t){const e=[];for(const[s,i]of Object.entries(t))if(i&&typeof i=="object"&&!Array.isArray(i)){const r=i;typeof r.__resolveType=="string"&&$h.has(r.__resolveType)&&typeof r.path=="string"&&e.push({key:s,name:typeof r.name=="string"?r.name:R_(s),path:r.path})}return e}function Fh(t,e){if(typeof e.name=="string"){const s=e.name.trim();if(s)return s}return t.replace(/[-_]/g," ").replace(/\b\w/g,s=>s.toUpperCase())}function Xn(t,e,s){const i=typeof e.__resolveType=="string"?e.__resolveType:"",r=i?Xi(i,s):{};if(r.title)return r.title;if(typeof e.name=="string"){const o=e.name.trim();if(o)return o}return t.replace(/[-_]/g," ").replace(/\b\w/g,o=>o.toUpperCase())}function Jn(t,e){const s=t[vr];if(s&&typeof s=="object"&&!Array.isArray(s)){const i=s,r=i.__resolveType;if(typeof r=="string"&&Gn(e,r))return{key:vr,name:Xn(vr,i,e),resolveType:r}}for(const[i,r]of Object.entries(t)){if(i.includes("/")||!r||typeof r!="object"||Array.isArray(r))continue;const o=r;if(o.__resolveType===Ri&&Gn(e,Ri))return{key:i,name:Xn(i,o,e),resolveType:Ri}}return null}function D_(t,e){const s=[];for(const[i,r]of Object.entries(t)){if(i.includes("/")||!r||typeof r!="object"||Array.isArray(r))continue;const o=r,a=o.__resolveType;typeof a=="string"&&($h.has(a)||typeof o.path!="string"&&(zh(i,o)||Gn(e,a)&&s.push({key:i,name:Xn(i,o,e),resolveType:a})))}return s.sort((i,r)=>i.name.localeCompare(r.name))}function xa(t,e){return Oh(e,t).map(s=>{const i=t[s.resolveType],r=typeof i.__resolveType=="string"?i.__resolveType:"";return{key:s.resolveType,name:s.description??Fh(s.resolveType,i),resolveType:r}}).sort((s,i)=>s.name.localeCompare(i.name))}const A_={phase:null,lifecycle:{phase:"idle"},status:{state:"running"},branch:{kind:"unknown"},notFound:!1,scripts:[],activeProcesses:[],getBuffer:()=>"",hasData:()=>!1,subscribeChunks:()=>()=>{},subscribeReload:()=>()=>{}},Hh=E.createContext(A_),al=16384;class I_{data="";append(e){this.data+=e,this.data.length>al&&(this.data=this.data.slice(this.data.length-al))}get(){return this.data}clear(){this.data=""}}const B_=1e3,M_=3e4,L_=3e3,ll=["lifecycle","status","tasks","scripts","branch","reload"],cl="log";function O_(t){if(!t)return null;try{return new URL("/_sandbox/events",t).href}catch{return null}}function $_(t){return t===404}async function z_(t){try{const e=await fetch(t,{headers:{Accept:"text/event-stream"},cache:"no-store",signal:AbortSignal.timeout(L_)});return await e.body?.cancel().catch(()=>{}),$_(e.status)}catch{return!1}}function F_({virtualMcpId:t,branch:e,previewUrl:s=null,enabled:i=!0,children:r}){const{org:o}=Pe(),[a,l]=E.useState(null),[h,c]=E.useState({phase:"idle"}),[d,u]=E.useState({state:"running"}),[f,m]=E.useState({kind:"unknown"}),[p,_]=E.useState(!1),[g,v]=E.useState([]),[b,x]=E.useState([]),[,y]=E.useState(0),w=E.useRef(new Map),C=E.useRef(new Set),j=E.useRef(new Set),R=E.useRef(null),B=O_(s),P=S=>{let k=w.current.get(S);return k||(k=new I_,w.current.set(S,k)),k};E.useEffect(()=>{if(l(null),c({phase:"idle"}),u({state:"running"}),m({kind:"unknown"}),R.current=null,_(!1),v([]),x([]),w.current.clear(),!t||!e||!i)return;const S=`/api/${encodeURIComponent(o.slug)}/sandbox/${encodeURIComponent(t)}/${encodeURIComponent(e)}/events`;let k=!1,I=0,N=null,A=null,M=null;const D=U=>{try{const H=JSON.parse(U.data);l(H),H.kind!=="failed"&&(_(!1),I=0),H.kind==="ready"&&V()}catch(H){console.warn("[vm-events] bad phase payload",H)}},$=()=>{_(!0),l(null),c({phase:"idle"}),u({state:"running"}),m({kind:"unknown"}),v([]),x([]),w.current.clear()},z=U=>{try{const H=JSON.parse(U.data);if(typeof H.data!="string")return;I=0;const X=H.data.replace(/\r?\n/g,`\r
|
|
7
|
-
`);P(H.source).append(X);for(const oe of C.current)try{oe(H.source,X)}catch{}y(oe=>oe+1)}catch{}},W=U=>{const H=U.type;try{const X=JSON.parse(U.data);switch(I=0,H){case"lifecycle":{const oe=X;c(oe.state);const L=oe.state.phase==="running"?oe.state.port:null,se=R.current;if(R.current=L,se!==null&&L!==null&&se!==L)for(const ee of j.current)try{ee()}catch{}return}case"status":u(X);return;case"tasks":{const L=X.active.map(se=>se.logName??"").filter(Boolean);x(L);return}case"scripts":v(X.scripts);return;case"branch":{const oe=X.meta;m(oe);return}case"reload":for(const oe of j.current)try{oe()}catch{}return}}catch{}};function F(){if(k)return;const U=new EventSource(S);A=U,U.onopen=()=>{},U.onerror=()=>{A===U&&U.readyState===EventSource.CLOSED&&Y("studio")},U.addEventListener("phase",D),U.addEventListener("gone",$),U.addEventListener(cl,z);for(const H of ll)U.addEventListener(H,W)}function V(){if(k||!B||M)return;const U=new EventSource(B);M=U;let H=!1;U.onopen=()=>{if(k||M!==U)return;H=!0,I=0;const X=A;A=null,X?.close()},U.onerror=()=>{M===U&&U.readyState===EventSource.CLOSED&&J(U,H)},U.addEventListener(cl,z);for(const X of ll)U.addEventListener(X,W)}async function J(U,H){const X=B?await z_(B):!1;if(!(k||M!==U)){if(U.close(),M=null,X){$(),A||F();return}H&&Y("direct")}}function Y(U){if(k||N)return;const H=Math.min(B_*2**I,M_);I++,N=setTimeout(()=>{if(N=null,!k){if(U==="direct"){M?.close(),M=null,V();return}A?.close(),A=null,F()}},H)}return F(),()=>{k=!0,A?.close(),M?.close(),N&&clearTimeout(N)}},[t,e,o.slug,i,B]);const T={phase:a,lifecycle:h,status:d,branch:f,notFound:p,scripts:g,activeProcesses:b,getBuffer:S=>w.current.get(S)?.get()??"",hasData:S=>(w.current.get(S)?.get().length??0)>0,subscribeChunks:S=>(C.current.add(S),()=>{C.current.delete(S)}),subscribeReload:S=>(j.current.add(S),()=>{j.current.delete(S)})};return n.jsx(Hh,{value:T,children:r})}function Yt(){return E.use(Hh)}function H_(t){const{subscribeChunks:e}=Yt(),s=E.useRef(t);s.current=t,E.useEffect(()=>e((o,a)=>{s.current?.(o,a)}),[e])}function W_(t){const{subscribeReload:e}=Yt(),s=E.useRef(t);s.current=t,E.useEffect(()=>e(()=>{s.current?.()}),[e])}const U_={settings:
|
|
8
|
-
<current_instructions>${o}</current_instructions>`;return{type:"doc",content:[{type:"paragraph",content:[{type:"text",text:"Use "},{type:"mention",attrs:{id:e,name:s,char:"@",metadata:{agentId:e,title:s}}},{type:"text",text:a}]}]}}function G_(t){const e=K.c(86),{value:s,onChange:i,onColorChange:r,name:o,size:a,className:l,avatarClassName:h,showHoverOverlay:c,disabled:d}=t,u=a===void 0?"lg":a,f=c===void 0?!0:c,m=d===void 0?!1:d,[p,_]=E.useState(!1),[g,v]=E.useState("icons"),[b,x]=E.useState(""),[y,w]=E.useState("blue");let C;e[0]!==s?(C=Qr(s),e[0]=s,e[1]=C):C=e[1];const j=C,R=j.type==="icon"||j.type==="url"&&j.color?j.color:y;let B;e[2]!==i||e[3]!==R?(B=Be=>{i(fn(Be,R))},e[2]=i,e[3]=R,e[4]=B):B=e[4];const P=B;let T;e[5]!==i||e[6]!==r||e[7]!==j.name||e[8]!==j.type||e[9]!==j.url?(T=Be=>{w(Be),r?.(Be),j.type==="icon"?i(fn(j.name,Be)):j.type==="url"&&i(Ua(j.url,Be))},e[5]=i,e[6]=r,e[7]=j.name,e[8]=j.type,e[9]=j.url,e[10]=T):T=e[10];const S=T;let k;e[11]!==i||e[12]!==R?(k=Be=>{i(Ua(Be,R)),_(!1)},e[11]=i,e[12]=R,e[13]=k):k=e[13];const I=k;let N;e[14]!==i||e[15]!==R?(N=()=>{const Be=Ko(),mt=Be[Math.floor(Math.random()*Be.length)];i(fn(mt,R))},e[14]=i,e[15]=R,e[16]=N):N=e[16];const A=N;let M,D,$,z,W,F,V,J,Y;if(e[17]!==l||e[18]!==m||e[19]!==p||e[20]!==u){const Be={xs:"rounded-md",sm:"rounded-lg","sm+":"rounded-xl",md:"rounded-xl",lg:"rounded-2xl",xl:"rounded-2xl"};D=Ts,V=m?!1:p,J=_,M=Rs,F=!0,Y="button",$="icon-picker-trigger",z=m,W=he("relative group overflow-hidden",m?"cursor-default opacity-50":"cursor-pointer",Be[u],l),e[17]=l,e[18]=m,e[19]=p,e[20]=u,e[21]=M,e[22]=D,e[23]=$,e[24]=z,e[25]=W,e[26]=F,e[27]=V,e[28]=J,e[29]=Y}else M=e[21],D=e[22],$=e[23],z=e[24],W=e[25],F=e[26],V=e[27],J=e[28],Y=e[29];let U;e[30]!==h||e[31]!==o||e[32]!==u||e[33]!==s?(U=n.jsx(Ka,{icon:s,name:o,size:u,className:h}),e[30]=h,e[31]=o,e[32]=u,e[33]=s,e[34]=U):U=e[34];let H;e[35]!==m||e[36]!==f?(H=f&&!m&&n.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/50 opacity-0 group-hover:opacity-100 transition-opacity",children:n.jsx(Zr,{size:16,className:"text-white"})}),e[35]=m,e[36]=f,e[37]=H):H=e[37];let X;e[38]!==$||e[39]!==z||e[40]!==W||e[41]!==U||e[42]!==H||e[43]!==Y?(X=n.jsxs("button",{type:Y,"data-testid":$,disabled:z,className:W,children:[U,H]}),e[38]=$,e[39]=z,e[40]=W,e[41]=U,e[42]=H,e[43]=Y,e[44]=X):X=e[44];let oe;e[45]!==M||e[46]!==F||e[47]!==X?(oe=n.jsx(M,{asChild:F,children:X}),e[45]=M,e[46]=F,e[47]=X,e[48]=oe):oe=e[48];let L;e[49]!==o||e[50]!==s?(L=n.jsx("div",{className:"flex items-center justify-center py-4",children:n.jsx(Ka,{icon:s,name:o,size:"xl"})}),e[49]=o,e[50]=s,e[51]=L):L=e[51];let se;e[52]===Symbol.for("react.memo_cache_sentinel")?(se=()=>v("icons"),e[52]=se):se=e[52];const ee=g==="icons"?"border-foreground text-foreground":"border-transparent text-muted-foreground hover:text-foreground";let Q;e[53]!==ee?(Q=he("px-3 py-2 text-sm font-medium border-b-2 -mb-px transition-colors",ee),e[53]=ee,e[54]=Q):Q=e[54];let O;e[55]!==Q?(O=n.jsx("button",{type:"button",onClick:se,className:Q,children:"Icons"}),e[55]=Q,e[56]=O):O=e[56];let ce;e[57]===Symbol.for("react.memo_cache_sentinel")?(ce=()=>v("upload"),e[57]=ce):ce=e[57];const ue=g==="upload"?"border-foreground text-foreground":"border-transparent text-muted-foreground hover:text-foreground";let fe;e[58]!==ue?(fe=he("px-3 py-2 text-sm font-medium border-b-2 -mb-px transition-colors",ue),e[58]=ue,e[59]=fe):fe=e[59];let q;e[60]!==fe?(q=n.jsx("button",{type:"button",onClick:ce,className:fe,children:"Upload"}),e[60]=fe,e[61]=q):q=e[61];let te;e[62]===Symbol.for("react.memo_cache_sentinel")?(te=n.jsx("div",{className:"flex-1"}),e[62]=te):te=e[62];let me;e[63]!==O||e[64]!==q?(me=n.jsxs("div",{className:"flex items-center border-b border-border px-3",children:[O,q,te]}),e[63]=O,e[64]=q,e[65]=me):me=e[65];let ne;e[66]!==S||e[67]!==A||e[68]!==P||e[69]!==I||e[70]!==j.name||e[71]!==j.type||e[72]!==b||e[73]!==R||e[74]!==g?(ne=g==="icons"?n.jsx(Z_,{search:b,onSearchChange:x,selectedColor:R,onColorChange:S,onSelectIcon:P,onRandom:A,currentIconName:j.type==="icon"?j.name:null}):n.jsx(Q_,{onUpload:I}),e[66]=S,e[67]=A,e[68]=P,e[69]=I,e[70]=j.name,e[71]=j.type,e[72]=b,e[73]=R,e[74]=g,e[75]=ne):ne=e[75];let ke;e[76]!==L||e[77]!==me||e[78]!==ne?(ke=n.jsx(Ps,{align:"start",className:"w-80 p-0",onOpenAutoFocus:Y_,children:n.jsxs("div",{className:"flex flex-col",children:[L,me,ne]})}),e[76]=L,e[77]=me,e[78]=ne,e[79]=ke):ke=e[79];let at;return e[80]!==D||e[81]!==V||e[82]!==J||e[83]!==oe||e[84]!==ke?(at=n.jsxs(D,{open:V,onOpenChange:J,children:[oe,ke]}),e[80]=D,e[81]=V,e[82]=J,e[83]=oe,e[84]=ke,e[85]=at):at=e[85],at}function Y_(t){return t.preventDefault()}function X_(t){const e=K.c(27),{selectedColor:s,onColorChange:i}=t,[r,o]=E.useState(!1);let a,l,h,c,d,u,f;if(e[0]!==r||e[1]!==s){const b=Vc(s);l=Ts,u=r,f=o,a=Rs,d=!0,h="button",c=he("h-6 w-6 rounded-full shrink-0 ring-2 ring-offset-2 ring-offset-background transition-all cursor-pointer hover:scale-110",b.dot,"ring-foreground/20"),e[0]=r,e[1]=s,e[2]=a,e[3]=l,e[4]=h,e[5]=c,e[6]=d,e[7]=u,e[8]=f}else a=e[2],l=e[3],h=e[4],c=e[5],d=e[6],u=e[7],f=e[8];let m;e[9]!==h||e[10]!==c?(m=n.jsx("button",{type:h,className:c,title:"Change color"}),e[9]=h,e[10]=c,e[11]=m):m=e[11];let p;e[12]!==a||e[13]!==d||e[14]!==m?(p=n.jsx(a,{asChild:d,children:m}),e[12]=a,e[13]=d,e[14]=m,e[15]=p):p=e[15];let _;e[16]!==i||e[17]!==s?(_=Tf.map(b=>n.jsx("button",{type:"button",onClick:()=>{i(b.name),o(!1)},className:he("h-5 w-5 rounded-full transition-all shrink-0 cursor-pointer",b.dot,s===b.name?"ring-2 ring-offset-1 ring-offset-background ring-foreground/30 scale-110":"hover:scale-110"),title:b.name},b.name)),e[16]=i,e[17]=s,e[18]=_):_=e[18];let g;e[19]!==_?(g=n.jsx(Ps,{align:"start",side:"right",sideOffset:8,className:"w-auto p-2",onOpenAutoFocus:J_,children:n.jsx("div",{className:"grid grid-cols-4 gap-1",children:_})}),e[19]=_,e[20]=g):g=e[20];let v;return e[21]!==l||e[22]!==u||e[23]!==f||e[24]!==p||e[25]!==g?(v=n.jsxs(l,{open:u,onOpenChange:f,children:[p,g]}),e[21]=l,e[22]=u,e[23]=f,e[24]=p,e[25]=g,e[26]=v):v=e[26],v}function J_(t){return t.preventDefault()}function Z_(t){const e=K.c(44),{search:s,onSearchChange:i,selectedColor:r,onColorChange:o,onSelectIcon:a,onRandom:l,currentIconName:h}=t;let c,d,u,f,m,p,_;if(e[0]!==h||e[1]!==o||e[2]!==l||e[3]!==i||e[4]!==a||e[5]!==s||e[6]!==r){const y=Ko(),w=Vc(r);d=s.trim()?y.filter(S=>{const k=zn(S),I=s.toLowerCase();return k.includes(I)||S.toLowerCase().includes(I)}):y,p="flex flex-col";let C;e[14]===Symbol.for("react.memo_cache_sentinel")?(C=n.jsx(Oi,{size:14,className:"absolute left-2 top-1/2 -translate-y-1/2 text-muted-foreground pointer-events-none"}),e[14]=C):C=e[14];let j;e[15]!==i?(j=S=>i(S.target.value),e[15]=i,e[16]=j):j=e[16];let R;e[17]!==s||e[18]!==j?(R=n.jsxs("div",{className:"relative flex-1",children:[C,n.jsx(qe,{value:s,onChange:j,placeholder:"Filter...",className:"h-8 text-xs pl-7"})]}),e[17]=s,e[18]=j,e[19]=R):R=e[19];let B;e[20]===Symbol.for("react.memo_cache_sentinel")?(B=n.jsx(Ef,{size:14,className:"text-muted-foreground"}),e[20]=B):B=e[20];let P;e[21]!==l?(P=n.jsx("button",{type:"button",onClick:l,className:"h-8 w-8 flex items-center justify-center rounded-md border border-border hover:bg-accent transition-colors shrink-0",title:"Random icon",children:B}),e[21]=l,e[22]=P):P=e[22];let T;e[23]!==o||e[24]!==r?(T=n.jsx(X_,{selectedColor:r,onColorChange:o}),e[23]=o,e[24]=r,e[25]=T):T=e[25],e[26]!==P||e[27]!==T||e[28]!==R?(_=n.jsxs("div",{className:"flex items-center gap-2 px-3 py-2",children:[R,P,T]}),e[26]=P,e[27]=T,e[28]=R,e[29]=_):_=e[29],c=rn,m="h-56",u="grid grid-cols-9 gap-0.5 px-2 pb-2",f=d.map(S=>{const k=en(S);return k?n.jsx("button",{type:"button",onClick:()=>a(S),className:he("h-8 w-8 flex items-center justify-center rounded-md transition-colors cursor-pointer",h===S?he(w.bg,w.text):he(w.text,"hover:bg-accent")),title:S,children:n.jsx(k,{size:18})},S):null}),e[0]=h,e[1]=o,e[2]=l,e[3]=i,e[4]=a,e[5]=s,e[6]=r,e[7]=c,e[8]=d,e[9]=u,e[10]=f,e[11]=m,e[12]=p,e[13]=_}else c=e[7],d=e[8],u=e[9],f=e[10],m=e[11],p=e[12],_=e[13];let g;e[30]!==u||e[31]!==f?(g=n.jsx("div",{className:u,children:f}),e[30]=u,e[31]=f,e[32]=g):g=e[32];let v;e[33]!==d.length?(v=d.length===0&&n.jsx("div",{className:"flex items-center justify-center py-8 text-sm text-muted-foreground",children:"No icons found"}),e[33]=d.length,e[34]=v):v=e[34];let b;e[35]!==c||e[36]!==m||e[37]!==g||e[38]!==v?(b=n.jsxs(c,{className:m,children:[g,v]}),e[35]=c,e[36]=m,e[37]=g,e[38]=v,e[39]=b):b=e[39];let x;return e[40]!==p||e[41]!==_||e[42]!==b?(x=n.jsxs("div",{className:p,children:[_,b]}),e[40]=p,e[41]=_,e[42]=b,e[43]=x):x=e[43],x}function Q_(t){const e=K.c(27),{onUpload:s}=t,i=E.useRef(null);let r;e[0]!==s?(r=C=>{const j=C.target.files?.[0];if(!j)return;if(j.size>2097152){le.error("Image must be smaller than 2MB"),C.target.value="";return}const R=new FileReader;R.onerror=()=>{le.error("Failed to read image file"),i.current&&(i.current.value="")},R.onloadend=()=>{R.readyState===FileReader.DONE&&R.result&&s(R.result),i.current&&(i.current.value="")},R.readAsDataURL(j)},e[0]=s,e[1]=r):r=e[1];const o=r,[a,l]=E.useState("");let h;e[2]!==s||e[3]!==a?(h=()=>{const C=a.trim();C&&(s(C),l(""))},e[2]=s,e[3]=a,e[4]=h):h=e[4];const c=h;let d;e[5]!==o?(d=n.jsx("input",{type:"file",ref:i,className:"hidden",accept:"image/*",onChange:o}),e[5]=o,e[6]=d):d=e[6];let u;e[7]===Symbol.for("react.memo_cache_sentinel")?(u=()=>i.current?.click(),e[7]=u):u=e[7];let f;e[8]===Symbol.for("react.memo_cache_sentinel")?(f=n.jsxs("button",{type:"button",onClick:u,className:"h-24 rounded-lg border-2 border-dashed border-border hover:border-foreground/50 hover:bg-accent/50 transition-colors flex flex-col items-center justify-center gap-2 text-muted-foreground hover:text-foreground",children:[n.jsx(Lm,{size:20}),n.jsx("span",{className:"text-xs",children:"Click to upload an image (max 2MB)"})]}),e[8]=f):f=e[8];let m;e[9]===Symbol.for("react.memo_cache_sentinel")?(m=n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-xs text-muted-foreground",children:"or"}),n.jsx("div",{className:"flex-1 h-px bg-border"})]}),e[9]=m):m=e[9];let p;e[10]===Symbol.for("react.memo_cache_sentinel")?(p=C=>l(C.target.value),e[10]=p):p=e[10];let _;e[11]!==c?(_=C=>{C.key==="Enter"&&(C.preventDefault(),c())},e[11]=c,e[12]=_):_=e[12];let g;e[13]!==a||e[14]!==_?(g=n.jsx(qe,{value:a,onChange:p,placeholder:"Paste image URL...",className:"h-8 text-xs flex-1",onKeyDown:_}),e[13]=a,e[14]=_,e[15]=g):g=e[15];let v;e[16]!==a?(v=a.trim(),e[16]=a,e[17]=v):v=e[17];const b=!v;let x;e[18]!==c||e[19]!==b?(x=n.jsx(re,{variant:"outline",size:"sm",className:"h-8 px-3 text-xs shrink-0",onClick:c,disabled:b,children:"Apply"}),e[18]=c,e[19]=b,e[20]=x):x=e[20];let y;e[21]!==x||e[22]!==g?(y=n.jsxs("div",{className:"flex items-center gap-1.5",children:[g,x]}),e[21]=x,e[22]=g,e[23]=y):y=e[23];let w;return e[24]!==y||e[25]!==d?(w=n.jsxs("div",{className:"flex flex-col gap-3 p-4",children:[d,f,m,y]}),e[24]=y,e[25]=d,e[26]=w):w=e[26],w}function eg(t){const e=K.c(5),{value:s}=t;let i;if(e[0]!==s){i=Symbol.for("react.early_return_sentinel");e:{const o=Qr(s);if(o.type==="icon"){const a=en(o.name);if(a){let l;e[2]!==a?(l=n.jsx(a,{size:16,className:"text-muted-foreground"}),e[2]=a,e[3]=l):l=e[3],i=l;break e}}}e[0]=s,e[1]=i}else i=e[1];if(i!==Symbol.for("react.early_return_sentinel"))return i;let r;return e[4]===Symbol.for("react.memo_cache_sentinel")?(r=n.jsx(Om,{size:16,className:"text-muted-foreground"}),e[4]=r):r=e[4],r}function tg(t){const e=K.c(66),{value:s,onChange:i,className:r,disabled:o}=t,[a,l]=E.useState(!1),[h,c]=E.useState("");let d;e[0]!==s?(d=Qr(s),e[0]=s,e[1]=d):d=e[1];const u=d,f=u.type==="icon"?u.name:null;let m,p,_,g,v,b,x,y,w,C,j,R,B,P,T;if(e[2]!==r||e[3]!==f||e[4]!==o||e[5]!==i||e[6]!==a||e[7]!==h||e[8]!==s){const D=Ko();g=h.trim()?D.filter(Y=>{const U=h.toLowerCase();return zn(Y).includes(U)||Y.toLowerCase().includes(U)}):D,_=Ts,v=o?!1:a,b=l;const $=o?"cursor-default opacity-50":"cursor-pointer hover:bg-accent";let z;e[24]!==r||e[25]!==$?(z=he("size-7 shrink-0 rounded-md transition-colors flex items-center justify-center",$,r),e[24]=r,e[25]=$,e[26]=z):z=e[26];let W;e[27]!==s?(W=n.jsx(eg,{value:s}),e[27]=s,e[28]=W):W=e[28],e[29]!==o||e[30]!==z||e[31]!==W?(x=n.jsx(Rs,{asChild:!0,children:n.jsx("button",{type:"button",disabled:o,className:z,children:W})}),e[29]=o,e[30]=z,e[31]=W,e[32]=x):x=e[32],p=Ps,B="start",P="w-64 p-0",T=sg,j="flex flex-col";let F;e[33]===Symbol.for("react.memo_cache_sentinel")?(F=n.jsx(Oi,{size:14,className:"absolute left-2 top-1/2 -translate-y-1/2 text-muted-foreground pointer-events-none"}),e[33]=F):F=e[33];let V;e[34]===Symbol.for("react.memo_cache_sentinel")?(V=Y=>c(Y.target.value),e[34]=V):V=e[34],e[35]!==h?(R=n.jsx("div",{className:"px-2 py-2",children:n.jsxs("div",{className:"relative",children:[F,n.jsx(qe,{value:h,onChange:V,placeholder:"Filter...",className:"h-7 text-xs pl-7"})]})}),e[35]=h,e[36]=R):R=e[36],m=rn,C="h-48",y="grid grid-cols-8 gap-0.5 px-2 pb-2";let J;e[37]!==f||e[38]!==i?(J=Y=>{const U=en(Y);return U?n.jsx("button",{type:"button",onClick:()=>{i(`icon://${Y}`),l(!1)},className:he("h-7 w-7 flex items-center justify-center rounded-md transition-colors cursor-pointer",f===Y?"bg-accent text-foreground":"text-muted-foreground hover:bg-accent hover:text-foreground"),title:zn(Y),children:n.jsx(U,{size:16})},Y):null},e[37]=f,e[38]=i,e[39]=J):J=e[39],w=g.map(J),e[2]=r,e[3]=f,e[4]=o,e[5]=i,e[6]=a,e[7]=h,e[8]=s,e[9]=m,e[10]=p,e[11]=_,e[12]=g,e[13]=v,e[14]=b,e[15]=x,e[16]=y,e[17]=w,e[18]=C,e[19]=j,e[20]=R,e[21]=B,e[22]=P,e[23]=T}else m=e[9],p=e[10],_=e[11],g=e[12],v=e[13],b=e[14],x=e[15],y=e[16],w=e[17],C=e[18],j=e[19],R=e[20],B=e[21],P=e[22],T=e[23];let S;e[40]!==y||e[41]!==w?(S=n.jsx("div",{className:y,children:w}),e[40]=y,e[41]=w,e[42]=S):S=e[42];let k;e[43]!==g.length?(k=g.length===0&&n.jsx("div",{className:"flex items-center justify-center py-6 text-xs text-muted-foreground",children:"No icons found"}),e[43]=g.length,e[44]=k):k=e[44];let I;e[45]!==m||e[46]!==S||e[47]!==k||e[48]!==C?(I=n.jsxs(m,{className:C,children:[S,k]}),e[45]=m,e[46]=S,e[47]=k,e[48]=C,e[49]=I):I=e[49];let N;e[50]!==I||e[51]!==j||e[52]!==R?(N=n.jsxs("div",{className:j,children:[R,I]}),e[50]=I,e[51]=j,e[52]=R,e[53]=N):N=e[53];let A;e[54]!==p||e[55]!==N||e[56]!==B||e[57]!==P||e[58]!==T?(A=n.jsx(p,{align:B,className:P,onOpenAutoFocus:T,children:N}),e[54]=p,e[55]=N,e[56]=B,e[57]=P,e[58]=T,e[59]=A):A=e[59];let M;return e[60]!==_||e[61]!==v||e[62]!==b||e[63]!==x||e[64]!==A?(M=n.jsxs(_,{open:v,onOpenChange:b,children:[x,A]}),e[60]=_,e[61]=v,e[62]=b,e[63]=x,e[64]=A,e[65]=M):M=e[65],M}function sg(t){return t.preventDefault()}const ig=25*1024*1024,pn="home",_n="knowledge";function dl(t){return t==null?"":t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(0)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function _s(t){return t.split("/").pop()??t}function rg(t){const e=K.c(52),{form:s}=t,{upload:i}=mm(pn),r=pm(),o=E.useRef(null),[a,l]=E.useState(!1),[h,c]=E.useState(""),[d,u]=E.useState(!1);let f;e[0]!==a?(f={enabled:a},e[0]=a,e[1]=f):f=e[1];const{data:m}=_m(60,f),p=m===void 0?[]:m;let _;e[2]!==a?(_={enabled:a},e[2]=a,e[3]=_):_=e[3];const{data:g}=gm(_),v=g===void 0?[]:g;let b;e[4]!==s?(b=()=>s.getValues("metadata.knowledge")??[],e[4]=s,e[5]=b):b=e[5];const[x,y]=E.useState(b);let w;e[6]!==s?(w=q=>{y(q),s.setValue("metadata.knowledge",q,{shouldDirty:!0})},e[6]=s,e[7]=w):w=e[7];const C=w;let j;e[8]!==r||e[9]!==x||e[10]!==C||e[11]!==i?(j=async q=>{if(!q||q.length===0)return;const te=Array.from(q).filter(cg);if(te.length!==0){try{await i.mutateAsync({dir:_n,files:te})}catch(me){const ne=me;le.error(ne instanceof Error?ne.message:"Failed to upload file.");return}C([...x,...te.map(me=>({id:crypto.randomUUID(),name:me.name,volume:pn,path:`${_n}/${me.name}`,url:r(pn,`${_n}/${me.name}`),contentType:me.type||null,size:me.size,addedAt:new Date().toISOString()}))])}},e[8]=r,e[9]=x,e[10]=C,e[11]=i,e[12]=j):j=e[12];const R=j;let B;e[13]!==r||e[14]!==x||e[15]!==C?(B=q=>{x.some(te=>te.volume===q.volume&&te.path===q.path)||(C([...x,{id:crypto.randomUUID(),name:_s(q.path),volume:q.volume,path:q.path,url:r(q.volume,q.path),contentType:null,size:q.size??null,addedAt:new Date().toISOString()}]),l(!1))},e[13]=r,e[14]=x,e[15]=C,e[16]=B):B=e[16];const P=B;let T;e[17]!==r||e[18]!==x||e[19]!==C?(T=q=>{x.some(te=>te.volume===q.volume&&te.path===q.path)||(C([...x,{id:crypto.randomUUID(),name:_s(q.path),kind:"skill",volume:q.volume,path:q.path,url:r(q.volume,q.path),contentType:null,size:null,addedAt:new Date().toISOString()}]),l(!1))},e[17]=r,e[18]=x,e[19]=C,e[20]=T):T=e[20];const S=T;let k;e[21]!==x||e[22]!==C?(k=q=>{C(x.filter(te=>te.id!==q))},e[21]=x,e[22]=C,e[23]=k):k=e[23];const I=k;let N;e[24]===Symbol.for("react.memo_cache_sentinel")?(N=q=>{l(q),q&&c("")},e[24]=N):N=e[24];const A=N;let M;e[25]!==x?(M=new Set(x.map(lg)),e[25]=x,e[26]=M):M=e[26];const D=M,$=h.toLowerCase();let z;e[27]!==D?(z=q=>!D.has(`${q.volume}/${q.path}`),e[27]=D,e[28]=z):z=e[28];const W=p.filter(ag).filter(z).filter(q=>_s(q.path).toLowerCase().includes($)).slice(0,5);let F;e[29]!==D?(F=q=>!D.has(`${q.volume}/${q.path}`),e[29]=D,e[30]=F):F=e[30];const V=v.filter(F).filter(q=>_s(q.path).toLowerCase().includes($)).slice(0,5),J=q=>n.jsxs(Ds,{open:a,onOpenChange:A,children:[n.jsx(As,{asChild:!0,children:q}),n.jsxs(Is,{align:"end",className:"w-56",children:[n.jsxs(He,{onSelect:()=>{o.current?.click()},children:[n.jsx(Rf,{size:16}),"Upload file"]}),n.jsxs(Un,{children:[n.jsxs(Kn,{className:"gap-2 [&_svg:not([class*='text-'])]:text-muted-foreground",children:[n.jsx(Wn,{size:16}),"Select file or folder"]}),n.jsxs(Vn,{className:"w-72 p-0",children:[n.jsxs("div",{className:"flex items-center gap-2 border-b px-3",children:[n.jsx(Oi,{size:16,className:"shrink-0 text-muted-foreground"}),n.jsx("input",{value:h,onChange:te=>c(te.target.value),onKeyDown:og,placeholder:"Search files...",className:"h-10 w-full bg-transparent text-sm outline-none placeholder:text-muted-foreground"})]}),n.jsx("div",{className:"max-h-64 overflow-y-auto p-1",children:W.length===0?n.jsx("p",{className:"px-2 py-3 text-center text-sm text-muted-foreground",children:"No files found."}):W.map(te=>n.jsxs(He,{onSelect:()=>P(te),children:[n.jsx(Li,{filename:_s(te.path),className:"h-5 w-4 shrink-0"}),n.jsx("span",{className:"flex-1 truncate",children:_s(te.path)}),te.size!=null&&n.jsx("span",{className:"text-xs text-muted-foreground",children:dl(te.size)})]},`${te.volume}/${te.path}`))})]})]}),n.jsxs(Un,{children:[n.jsxs(Kn,{className:"gap-2 [&_svg:not([class*='text-'])]:text-muted-foreground",children:[n.jsx(Ss,{size:16}),"Select skill"]}),n.jsxs(Vn,{className:"w-72 p-0",children:[n.jsxs("div",{className:"flex items-center gap-2 border-b px-3",children:[n.jsx(Oi,{size:16,className:"shrink-0 text-muted-foreground"}),n.jsx("input",{value:h,onChange:te=>c(te.target.value),onKeyDown:ng,placeholder:"Search skills...",className:"h-10 w-full bg-transparent text-sm outline-none placeholder:text-muted-foreground"})]}),n.jsx("div",{className:"max-h-64 overflow-y-auto p-1",children:V.length===0?n.jsx("p",{className:"px-2 py-3 text-center text-sm text-muted-foreground",children:"No skills found."}):V.map(te=>n.jsxs(He,{onSelect:()=>S(te),children:[n.jsx(Ss,{size:16,className:"shrink-0"}),n.jsx("span",{className:"flex-1 truncate",children:_s(te.path)})]},`${te.volume}/${te.path}`))})]})]})]})]}),Y="flex flex-col gap-3";let U;e[31]===Symbol.for("react.memo_cache_sentinel")?(U=n.jsxs("div",{className:"flex flex-col gap-1",children:[n.jsx("h2",{className:"text-sm font-medium text-foreground",children:"Files and skills"}),n.jsx("p",{className:"text-sm text-muted-foreground",children:"Attach files and skills the agent can always reference."})]}),e[31]=U):U=e[31];const H=x.length>0&&J(n.jsxs(re,{variant:"outline",size:"sm",disabled:i.isPending,children:[i.isPending?n.jsx(Xo,{size:"xs"}):n.jsx(xt,{size:14}),"Add"]}));let X;e[32]!==H?(X=n.jsxs("div",{className:"flex items-center justify-between gap-3",children:[U,H]}),e[32]=H,e[33]=X):X=e[33];let oe;e[34]!==R?(oe=n.jsx("input",{ref:o,type:"file",multiple:!0,className:"hidden",onChange:q=>{R(q.target.files),q.target.value=""}}),e[34]=R,e[35]=oe):oe=e[35];let L,se;e[36]===Symbol.for("react.memo_cache_sentinel")?(L=q=>{q.preventDefault(),u(!0)},se=()=>u(!1),e[36]=L,e[37]=se):(L=e[36],se=e[37]);let ee;e[38]!==R?(ee=q=>{q.preventDefault(),u(!1),R(q.dataTransfer.files)},e[38]=R,e[39]=ee):ee=e[39];const Q=d&&"outline outline-2 outline-dashed outline-primary";let O;e[40]!==Q?(O=he("flex flex-col gap-2 rounded-lg",Q),e[40]=Q,e[41]=O):O=e[41];const ce=x.length===0?J(n.jsxs("button",{type:"button",className:"flex items-center gap-3 px-3 py-2.5 rounded-lg border border-dashed border-border hover:bg-accent/50 transition-colors w-full text-left cursor-pointer",children:[n.jsx("div",{className:"flex items-center justify-center size-8 rounded-md text-muted-foreground/75 border border-dashed border-border shrink-0",children:n.jsx(xt,{size:16})}),n.jsx("span",{className:"text-sm text-muted-foreground flex-1",children:"No files or skills yet. Add one or drag and drop here."})]})):x.map(q=>n.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 rounded-xl border bg-card",children:[q.kind==="skill"?n.jsx("div",{className:"flex items-center justify-center h-8 w-6.5 shrink-0 rounded-md bg-muted text-muted-foreground",children:n.jsx(Ss,{size:16})}):n.jsx(Li,{filename:q.name,className:"h-8 w-6.5 shrink-0"}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("p",{className:"text-sm font-medium truncate",children:q.name}),n.jsx("p",{className:"text-xs text-muted-foreground",children:q.kind==="skill"?"Skill":q.size!=null?dl(q.size):"File"})]}),n.jsx(re,{variant:"ghost",size:"icon",onClick:()=>I(q.id),"aria-label":`Remove ${q.name}`,children:n.jsx(qs,{size:16})})]},q.id));let ue;e[42]!==L||e[43]!==se||e[44]!==ee||e[45]!==O||e[46]!==ce?(ue=n.jsx("div",{onDragOver:L,onDragLeave:se,onDrop:ee,className:O,children:ce}),e[42]=L,e[43]=se,e[44]=ee,e[45]=O,e[46]=ce,e[47]=ue):ue=e[47];let fe;return e[48]!==X||e[49]!==oe||e[50]!==ue?(fe=n.jsxs("section",{className:Y,children:[X,oe,ue]}),e[48]=X,e[49]=oe,e[50]=ue,e[51]=fe):fe=e[51],fe}function ng(t){return t.stopPropagation()}function og(t){return t.stopPropagation()}function ag(t){return t.kind!=="dir"}function lg(t){return`${t.volume}/${t.path}`}function cg(t){return t.size<=ig}function hg(t){return t==null?"all":t.length===0?"self":"selected"}function dg(t){const e=K.c(65),{form:s,currentAgentId:i}=t,{org:r}=Pe(),o=ef(),[a,l]=E.useState(!1);let h;e[0]!==s?(h=s.getValues("metadata.subAgents")??null,e[0]=s,e[1]=h):h=e[1];const c=h;let d;e[2]!==c?(d=()=>hg(c),e[2]=c,e[3]=d):d=e[3];const[u,f]=E.useState(d);let m;e[4]!==c?(m=c??[],e[4]=c,e[5]=m):m=e[5];const[p,_]=E.useState(m);let g,v,b,x,y,w;if(e[6]!==o||e[7]!==i||e[8]!==s||e[9]!==u||e[10]!==r||e[11]!==p){let B;e[18]!==i||e[19]!==r?(B=H=>H.id!==i&&H.id!==r.id&&H.status==="active",e[18]=i,e[19]=r,e[20]=B):B=e[20],g=o.filter(B);let P;e[21]!==p?(P=H=>p.includes(H.id),e[21]=p,e[22]=P):P=e[22];const T=g.filter(P);let S;e[23]!==s?(S=(H,X)=>s.setValue("metadata.subAgents",H==="all"?null:H==="self"?[]:X,{shouldDirty:!0}),e[23]=s,e[24]=S):S=e[24];const k=S;let I;e[25]!==k||e[26]!==p?(I=H=>{f(H),k(H,p)},e[25]=k,e[26]=p,e[27]=I):I=e[27];const N=I;let A;e[28]!==k||e[29]!==p?(A=H=>{const X=p.includes(H)?p.filter(oe=>oe!==H):[...p,H];_(X),k("selected",X)},e[28]=k,e[29]=p,e[30]=A):A=e[30],v=A,y="flex flex-col gap-3";let M;e[31]===Symbol.for("react.memo_cache_sentinel")?(M=n.jsx("h2",{className:"text-sm font-medium text-foreground",children:"Sub-agents"}),e[31]=M):M=e[31];let D;e[32]!==u?(D=u==="all"&&n.jsx("p",{className:"text-sm text-muted-foreground",children:"Can delegate to any agent in the organization."}),e[32]=u,e[33]=D):D=e[33];let $;e[34]!==u?($=u==="self"&&n.jsx("p",{className:"text-sm text-muted-foreground",children:"Can only delegate to a fresh copy of itself, no other agents."}),e[34]=u,e[35]=$):$=e[35];let z;e[36]!==D||e[37]!==$?(z=n.jsxs("div",{className:"flex flex-col gap-1",children:[M,D,$]}),e[36]=D,e[37]=$,e[38]=z):z=e[38];const W=u==="selected"&&T.length>0&&n.jsxs(re,{variant:"outline",size:"sm",onClick:()=>l(!0),children:[n.jsx(xt,{size:14}),"Add sub-agent"]});let F;e[39]!==N?(F=H=>N(H),e[39]=N,e[40]=F):F=e[40];let V;e[41]===Symbol.for("react.memo_cache_sentinel")?(V=n.jsx(Pt,{size:"sm",className:"w-auto",children:n.jsx(Dt,{})}),e[41]=V):V=e[41];let J;e[42]===Symbol.for("react.memo_cache_sentinel")?(J=n.jsxs(At,{align:"end",children:[n.jsx(ot,{value:"all",children:"Any agent"}),n.jsx(ot,{value:"selected",children:"Specific agents"}),n.jsx(ot,{value:"self",children:"Only itself"})]}),e[42]=J):J=e[42];let Y;e[43]!==u||e[44]!==F?(Y=n.jsxs(It,{value:u,onValueChange:F,children:[V,J]}),e[43]=u,e[44]=F,e[45]=Y):Y=e[45];let U;e[46]!==W||e[47]!==Y?(U=n.jsxs("div",{className:"flex items-center gap-2",children:[W,Y]}),e[46]=W,e[47]=Y,e[48]=U):U=e[48],e[49]!==z||e[50]!==U?(w=n.jsxs("div",{className:"flex items-center justify-between gap-3",children:[z,U]}),e[49]=z,e[50]=U,e[51]=w):w=e[51],b="flex flex-col gap-2",x=u==="selected"&&(T.length>0?T.map(H=>n.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 rounded-xl border bg-background",children:[n.jsx(Gt,{icon:H.icon,name:H.title,size:"sm",className:"shrink-0"}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("p",{className:"text-sm font-medium truncate",children:H.title}),H.description&&n.jsx("p",{className:"text-xs text-muted-foreground truncate",children:H.description})]}),n.jsx(re,{variant:"ghost",size:"icon",onClick:()=>v(H.id),children:n.jsx(ps,{size:16})})]},H.id)):n.jsxs("button",{type:"button",onClick:()=>l(!0),className:"flex items-center gap-3 px-3 py-2.5 rounded-lg border border-dashed border-border hover:bg-accent/50 transition-colors w-full text-left cursor-pointer",children:[n.jsx("div",{className:"flex items-center justify-center size-8 rounded-md text-muted-foreground/75 border border-dashed border-border shrink-0",children:n.jsx(xt,{size:16})}),n.jsx("span",{className:"text-sm text-muted-foreground",children:"No sub-agents selected yet. Add one — until then this agent can only delegate to itself."})]})),e[6]=o,e[7]=i,e[8]=s,e[9]=u,e[10]=r,e[11]=p,e[12]=g,e[13]=v,e[14]=b,e[15]=x,e[16]=y,e[17]=w}else g=e[12],v=e[13],b=e[14],x=e[15],y=e[16],w=e[17];let C;e[52]!==b||e[53]!==x?(C=n.jsx("div",{className:b,children:x}),e[52]=b,e[53]=x,e[54]=C):C=e[54];let j;e[55]!==g||e[56]!==v||e[57]!==a||e[58]!==p?(j=n.jsx(ug,{open:a,onOpenChange:l,candidates:g,selectedIds:p,onToggle:v}),e[55]=g,e[56]=v,e[57]=a,e[58]=p,e[59]=j):j=e[59];let R;return e[60]!==y||e[61]!==w||e[62]!==C||e[63]!==j?(R=n.jsxs("section",{className:y,children:[w,C,j]}),e[60]=y,e[61]=w,e[62]=C,e[63]=j,e[64]=R):R=e[64],R}function ug(t){const e=K.c(32),{open:s,onOpenChange:i,candidates:r,selectedIds:o,onToggle:a}=t,[l,h]=E.useState("");let c,d,u,f,m,p,_,g,v;if(e[0]!==r||e[1]!==i||e[2]!==a||e[3]!==s||e[4]!==l||e[5]!==o){const w=l.toLowerCase(),C=r.filter(j=>j.title.toLowerCase().includes(w)||j.description?.toLowerCase().includes(w));d=Lt,g=s,v=i,c=Ot,m="max-w-md",e[15]===Symbol.for("react.memo_cache_sentinel")?(p=n.jsx(is,{children:n.jsx(rs,{children:"Sub-agents"})}),e[15]=p):p=e[15],e[16]!==l?(_=n.jsx(hh,{value:l,onChange:h,placeholder:"Search agents...",className:"w-full"}),e[16]=l,e[17]=_):_=e[17],u="flex flex-col gap-1 max-h-80 overflow-y-auto",f=C.length===0?n.jsx("p",{className:"text-sm text-muted-foreground px-1 py-4 text-center",children:"No agents found."}):C.map(j=>n.jsxs("button",{type:"button",onClick:()=>a(j.id),className:"flex items-center gap-3 px-2 py-2 rounded-lg hover:bg-accent/50 transition-colors cursor-pointer w-full text-left",children:[n.jsx(nn,{checked:o.includes(j.id),className:"pointer-events-none",tabIndex:-1}),n.jsx(Gt,{icon:j.icon,name:j.title,size:"sm",className:"shrink-0"}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("p",{className:"text-sm font-medium truncate",children:j.title}),j.description&&n.jsx("p",{className:"text-xs text-muted-foreground truncate",children:j.description})]})]},j.id)),e[0]=r,e[1]=i,e[2]=a,e[3]=s,e[4]=l,e[5]=o,e[6]=c,e[7]=d,e[8]=u,e[9]=f,e[10]=m,e[11]=p,e[12]=_,e[13]=g,e[14]=v}else c=e[6],d=e[7],u=e[8],f=e[9],m=e[10],p=e[11],_=e[12],g=e[13],v=e[14];let b;e[18]!==u||e[19]!==f?(b=n.jsx("div",{className:u,children:f}),e[18]=u,e[19]=f,e[20]=b):b=e[20];let x;e[21]!==c||e[22]!==m||e[23]!==p||e[24]!==_||e[25]!==b?(x=n.jsxs(c,{className:m,children:[p,_,b]}),e[21]=c,e[22]=m,e[23]=p,e[24]=_,e[25]=b,e[26]=x):x=e[26];let y;return e[27]!==d||e[28]!==g||e[29]!==v||e[30]!==x?(y=n.jsx(d,{open:g,onOpenChange:v,children:x}),e[27]=d,e[28]=g,e[29]=v,e[30]=x,e[31]=y):y=e[31],y}function xr(){const t=K.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=n.jsx("div",{className:"flex items-center justify-center h-32",children:n.jsx(Ce,{className:"animate-spin text-muted-foreground",size:24})}),t[0]=e):e=t[0],e}function gn(t){return({error:e})=>e?.message?.includes("Method not found")||e?.code===-32601?n.jsx("div",{className:"flex-1 overflow-auto px-4 py-3 space-y-1",children:n.jsx("div",{className:"flex items-center justify-center h-32 text-sm text-muted-foreground",children:t})}):n.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center h-full p-6 text-center space-y-4",children:[n.jsx("div",{className:"bg-destructive/10 p-3 rounded-full",children:n.jsx(Ic,{className:"h-6 w-6 text-destructive"})}),n.jsxs("div",{className:"space-y-2",children:[n.jsx("h3",{className:"text-lg font-medium",children:"Something went wrong"}),n.jsx("p",{className:"text-sm text-muted-foreground max-w-xs mx-auto",children:e?.message?e.message.length>200?`${e.message.slice(0,200)}...`:e.message:"An unexpected error occurred"})]})]})}function fg(t){const e=K.c(23),{item:s,isSelected:i,onToggle:r,disabled:o}=t,a=o?"cursor-not-allowed opacity-50":"cursor-pointer",l=i?"bg-accent/25":"hover:bg-muted/50";let h;e[0]!==a||e[1]!==l?(h=he("flex items-start gap-3 p-4 rounded-lg transition-colors",a,l),e[0]=a,e[1]=l,e[2]=h):h=e[2];let c;e[3]!==s.name?(c=n.jsx("p",{className:"text-sm font-medium leading-none truncate",children:s.name}),e[3]=s.name,e[4]=c):c=e[4];let d;e[5]!==s.tags?(d=s.tags&&n.jsx("span",{className:"shrink-0",children:s.tags}),e[5]=s.tags,e[6]=d):d=e[6];let u;e[7]!==c||e[8]!==d?(u=n.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[c,d]}),e[7]=c,e[8]=d,e[9]=u):u=e[9];let f;e[10]!==s.description?(f=s.description&&n.jsx("p",{className:"text-xs text-muted-foreground line-clamp-2",children:s.description}),e[10]=s.description,e[11]=f):f=e[11];let m;e[12]!==u||e[13]!==f?(m=n.jsxs("div",{className:"flex-1 min-w-0 space-y-2",children:[u,f]}),e[12]=u,e[13]=f,e[14]=m):m=e[14];let p;e[15]!==o||e[16]!==i||e[17]!==r?(p=n.jsx(nn,{checked:i,onCheckedChange:r,disabled:o,className:"mt-0.5"}),e[15]=o,e[16]=i,e[17]=r,e[18]=p):p=e[18];let _;return e[19]!==h||e[20]!==m||e[21]!==p?(_=n.jsxs("label",{className:h,children:[m,p]}),e[19]=h,e[20]=m,e[21]=p,e[22]=_):_=e[22],_}function ba(t){const e=K.c(13),{items:s,selections:i,onToggle:r,emptyMessage:o,disabled:a}=t;let l,h,c;if(e[0]!==a||e[1]!==o||e[2]!==s||e[3]!==r||e[4]!==i){c=Symbol.for("react.early_return_sentinel");e:{const u=s.map(mg);if(s.length===0){let f;e[8]!==o?(f=n.jsx("div",{className:"flex-1 overflow-auto px-4 py-3 space-y-1",children:n.jsx("div",{className:"flex items-center justify-center h-32 text-sm text-muted-foreground",children:o})}),e[8]=o,e[9]=f):f=e[9],c=f;break e}l="flex-1 overflow-auto px-4 py-3 space-y-1",h=s.map(f=>n.jsx(fg,{item:f,isSelected:i===null||i?.includes(f.id),onToggle:()=>r(f.id,u),disabled:a},f.id))}e[0]=a,e[1]=o,e[2]=s,e[3]=r,e[4]=i,e[5]=l,e[6]=h,e[7]=c}else l=e[5],h=e[6],c=e[7];if(c!==Symbol.for("react.early_return_sentinel"))return c;let d;return e[10]!==l||e[11]!==h?(d=n.jsx("div",{className:l,children:h}),e[10]=l,e[11]=h,e[12]=d):d=e[12],d}function mg(t){return t.id}function pg(t){const e=K.c(13),{connectionId:s,selections:i,onToggle:r,disabled:o}=t,{org:a}=Pe();let l;e[0]!==s||e[1]!==a.id||e[2]!==a.slug?(l={connectionId:s,orgId:a.id,orgSlug:a.slug},e[0]=s,e[1]=a.id,e[2]=a.slug,e[3]=l):l=e[3];const h=ft(l);let c;e[4]!==h?(c={client:h},e[4]=h,e[5]=c):c=e[5];const{data:d}=dm(c);let u;e[6]!==d.tools?(u=d.tools.map(_g),e[6]=d.tools,e[7]=u):u=e[7];const f=u;let m;return e[8]!==o||e[9]!==f||e[10]!==r||e[11]!==i?(m=n.jsx(ba,{items:f,selections:i,onToggle:r,emptyMessage:"No tools available",disabled:o}),e[8]=o,e[9]=f,e[10]=r,e[11]=i,e[12]=m):m=e[12],m}function _g(t){return{id:t.name,name:t.name,description:t.description,tags:n.jsx(Im,{annotations:t.annotations,_meta:t._meta})}}function gg(t){const e=K.c(13),{connectionId:s,selections:i,onToggle:r,disabled:o}=t,{org:a}=Pe();let l;e[0]!==s||e[1]!==a.id||e[2]!==a.slug?(l={connectionId:s,orgId:a.id,orgSlug:a.slug},e[0]=s,e[1]=a.id,e[2]=a.slug,e[3]=l):l=e[3];const h=ft(l);let c;e[4]!==h?(c={client:h},e[4]=h,e[5]=c):c=e[5];const{data:d}=Ou(c);let u;e[6]!==d.resources?(u=d.resources.map(vg),e[6]=d.resources,e[7]=u):u=e[7];const f=u;let m;return e[8]!==o||e[9]!==f||e[10]!==r||e[11]!==i?(m=n.jsx(ba,{items:f,selections:i,onToggle:r,emptyMessage:"No resources available",disabled:o}),e[8]=o,e[9]=f,e[10]=r,e[11]=i,e[12]=m):m=e[12],m}function vg(t){return{id:t.name||t.uri,name:t.name||t.uri,description:t.description}}function xg(t){const e=K.c(13),{connectionId:s,selections:i,onToggle:r,disabled:o}=t,{org:a}=Pe();let l;e[0]!==s||e[1]!==a.id||e[2]!==a.slug?(l={connectionId:s,orgId:a.id,orgSlug:a.slug},e[0]=s,e[1]=a.id,e[2]=a.slug,e[3]=l):l=e[3];const h=ft(l);let c;e[4]!==h?(c={client:h},e[4]=h,e[5]=c):c=e[5];const{data:d}=$m(c);let u;e[6]!==d.prompts?(u=d.prompts.map(bg),e[6]=d.prompts,e[7]=u):u=e[7];const f=u;let m;return e[8]!==o||e[9]!==f||e[10]!==r||e[11]!==i?(m=n.jsx(ba,{items:f,selections:i,onToggle:r,emptyMessage:"No prompts available",disabled:o}),e[8]=o,e[9]=f,e[10]=r,e[11]=i,e[12]=m):m=e[12],m}function bg(t){return{id:t.name,name:t.name,description:t.description}}function yg(t){const e=K.c(54),{currentConnection:s,activeTab:i,selectedId:r,formData:o,toggleTool:a,toggleResource:l,togglePrompt:h,toggleAllTools:c,toggleAllResources:d,toggleAllPrompts:u,onTabChange:f}=t,m=o[r],p=i==="tools"?m?.tools===null:i==="resources"?m?.resources===null:m?.prompts===null;let _;e[0]!==i||e[1]!==r||e[2]!==u||e[3]!==d||e[4]!==c?(_=()=>{i==="tools"?c(r):i==="resources"?d(r):u(r)},e[0]=i,e[1]=r,e[2]=u,e[3]=d,e[4]=c,e[5]=_):_=e[5];const g=_;let v;e[6]!==s.icon||e[7]!==s.title?(v=n.jsx(Gt,{icon:s.icon,name:s.title,size:"sm",className:"shrink-0"}),e[6]=s.icon,e[7]=s.title,e[8]=v):v=e[8];let b;e[9]!==s.title?(b=n.jsx("h2",{className:"text-base font-semibold truncate",children:s.title}),e[9]=s.title,e[10]=b):b=e[10];let x;e[11]!==s.description?(x=s.description&&n.jsx("p",{className:"text-xs text-muted-foreground truncate",children:s.description}),e[11]=s.description,e[12]=x):x=e[12];let y;e[13]!==b||e[14]!==x?(y=n.jsxs("div",{className:"flex-1 min-w-0",children:[b,x]}),e[13]=b,e[14]=x,e[15]=y):y=e[15];let w;e[16]!==v||e[17]!==y?(w=n.jsx("div",{className:"px-6 pt-5 pb-4 shrink-0",children:n.jsxs("div",{className:"flex items-center gap-3",children:[v,y]})}),e[16]=v,e[17]=y,e[18]=w):w=e[18];let C;e[19]===Symbol.for("react.memo_cache_sentinel")?(C=[{id:"tools",label:"Tools"},{id:"resources",label:"Resources"},{id:"prompts",label:"Prompts"}],e[19]=C):C=e[19];let j;e[20]!==f?(j=M=>f(M),e[20]=f,e[21]=j):j=e[21];let R;e[22]!==i||e[23]!==j?(R=n.jsx(dh,{tabs:C,activeTab:i,onTabChange:j}),e[22]=i,e[23]=j,e[24]=R):R=e[24];const B=p?"Deselect all":"Select all";let P;e[25]!==g||e[26]!==B?(P=n.jsx("button",{type:"button",onClick:g,className:"text-xs text-muted-foreground hover:text-foreground transition-colors",children:B}),e[25]=g,e[26]=B,e[27]=P):P=e[27];let T;e[28]!==P||e[29]!==R?(T=n.jsxs("div",{className:"flex items-center justify-between px-6 py-3 border-t border-border shrink-0",children:[R,P]}),e[28]=P,e[29]=R,e[30]=T):T=e[30];let S;e[31]!==i||e[32]!==o||e[33]!==r||e[34]!==a?(S=i==="tools"&&n.jsx(Ut,{fallback:gn("Tools not supported by this server"),children:n.jsx(E.Suspense,{fallback:n.jsx(xr,{}),children:n.jsx(pg,{connectionId:r,selections:o[r]?o[r].tools:[],onToggle:(M,D)=>a(r,M,D)})})}),e[31]=i,e[32]=o,e[33]=r,e[34]=a,e[35]=S):S=e[35];let k;e[36]!==i||e[37]!==o||e[38]!==r||e[39]!==l?(k=i==="resources"&&n.jsx(Ut,{fallback:gn("Resources not supported by this server"),children:n.jsx(E.Suspense,{fallback:n.jsx(xr,{}),children:n.jsx(gg,{connectionId:r,selections:o[r]?o[r].resources:[],onToggle:(M,D)=>l(r,M,D)})})}),e[36]=i,e[37]=o,e[38]=r,e[39]=l,e[40]=k):k=e[40];let I;e[41]!==i||e[42]!==o||e[43]!==r||e[44]!==h?(I=i==="prompts"&&n.jsx(Ut,{fallback:gn("Prompts not supported by this server"),children:n.jsx(E.Suspense,{fallback:n.jsx(xr,{}),children:n.jsx(xg,{connectionId:r,selections:o[r]?o[r].prompts:[],onToggle:(M,D)=>h(r,M,D)})})}),e[41]=i,e[42]=o,e[43]=r,e[44]=h,e[45]=I):I=e[45];let N;e[46]!==S||e[47]!==k||e[48]!==I?(N=n.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[S,k,I]}),e[46]=S,e[47]=k,e[48]=I,e[49]=N):N=e[49];let A;return e[50]!==T||e[51]!==N||e[52]!==w?(A=n.jsxs(n.Fragment,{children:[w,T,N]}),e[50]=T,e[51]=N,e[52]=w,e[53]=A):A=e[53],A}function Sg(t){const e=K.c(11),{connectionId:s,onAuthenticate:i,children:r}=t;let o;e[0]!==s?(o={connectionId:s},e[0]=s,e[1]=o):o=e[1];const a=ah(o);if(a.supportsOAuth&&!a.isAuthenticated){let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c=n.jsx("div",{className:"flex items-center justify-center size-12 rounded-full bg-muted",children:n.jsx(Pf,{size:22,className:"text-muted-foreground"})}),e[2]=c):c=e[2];let d;e[3]===Symbol.for("react.memo_cache_sentinel")?(d=n.jsxs("div",{className:"space-y-1",children:[n.jsx("p",{className:"text-sm font-medium",children:"Authorization required"}),n.jsx("p",{className:"text-xs text-muted-foreground max-w-xs",children:"This connection needs to be authorized before you can configure its tools and resources."})]}),e[3]=d):d=e[3];let u;e[4]!==s||e[5]!==i?(u=i&&n.jsx(re,{variant:"outline",size:"sm",onClick:()=>i(s),children:"Authorize"}),e[4]=s,e[5]=i,e[6]=u):u=e[6];let f;return e[7]!==u?(f=n.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-4 p-8 text-center",children:[c,d,u]}),e[7]=u,e[8]=f):f=e[8],f}let h;return e[9]!==r?(h=n.jsx(n.Fragment,{children:r}),e[9]=r,e[10]=h):h=e[10],h}function wg(t){const e={};for(const s of t)e[s.connection_id]={tools:s.selected_tools,resources:s.selected_resources??null,prompts:s.selected_prompts??null};return e}function ul(t){return Object.entries(t).map(([e,s])=>({connection_id:e,selected_tools:s.tools,selected_resources:s.resources,selected_prompts:s.prompts}))}function Cg(t,e){return e.type==="SET_ACTIVE_TAB"?{...t,activeTab:e.payload}:t}function kg(t){const e=K.c(49),{open:s,onOpenChange:i,selectedId:r,form:o,connections:a,onAuthenticate:l}=t;let h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h={activeTab:"tools"},e[0]=h):h=e[0];const[c,d]=E.useReducer(Cg,h),u=Go(r??"");let f;e[1]!==a?(f=a??[],e[1]=a,e[2]=f):f=e[2];let m;e[3]!==f?(m=wg(f),e[3]=f,e[4]=m):m=e[4];const p=m;let _;e[5]!==o||e[6]!==p?(_=(F,V,J,Y)=>{const U=p[F]?.[V];let H;U===null?H=Y.filter(oe=>oe!==J):U?.includes(J)?H=U.filter(oe=>oe!==J):(H=[...U??[],J],H.length===Y.length&&(H=null));const X={...p};X[F]?X[F]={...X[F]}:X[F]={tools:null,resources:null,prompts:null},X[F][V]=H,o.setValue("connections",ul(X),{shouldDirty:!0,shouldTouch:!0})},e[5]=o,e[6]=p,e[7]=_):_=e[7];const g=_;let v;e[8]!==o||e[9]!==p?(v=(F,V)=>{const Y=p[F]?.[V]===null?[]:null,U={...p};U[F]?U[F]={...U[F]}:U[F]={tools:null,resources:null,prompts:null},U[F][V]=Y,o.setValue("connections",ul(U),{shouldDirty:!0,shouldTouch:!0})},e[8]=o,e[9]=p,e[10]=v):v=e[10];const b=v;let x;e[11]!==g?(x=(F,V,J)=>g(F,"tools",V,J),e[11]=g,e[12]=x):x=e[12];const y=x;let w;e[13]!==g?(w=(F,V,J)=>g(F,"resources",V,J),e[13]=g,e[14]=w):w=e[14];const C=w;let j;e[15]!==g?(j=(F,V,J)=>g(F,"prompts",V,J),e[15]=g,e[16]=j):j=e[16];const R=j;let B;e[17]!==b?(B=F=>b(F,"tools"),e[17]=b,e[18]=B):B=e[18];const P=B;let T;e[19]!==b?(T=F=>b(F,"resources"),e[19]=b,e[20]=T):T=e[20];const S=T;let k;e[21]!==b?(k=F=>b(F,"prompts"),e[21]=b,e[22]=k):k=e[22];const I=k;if(!r||!u)return null;let N;e[23]===Symbol.for("react.memo_cache_sentinel")?(N=n.jsx(xr,{}),e[23]=N):N=e[23];let A;e[24]===Symbol.for("react.memo_cache_sentinel")?(A=F=>d({type:"SET_ACTIVE_TAB",payload:F}),e[24]=A):A=e[24];let M;e[25]!==u||e[26]!==c.activeTab||e[27]!==p||e[28]!==r||e[29]!==I||e[30]!==S||e[31]!==P||e[32]!==R||e[33]!==C||e[34]!==y?(M=n.jsx(yg,{currentConnection:u,activeTab:c.activeTab,selectedId:r,formData:p,toggleTool:y,toggleResource:C,togglePrompt:R,toggleAllTools:P,toggleAllResources:S,toggleAllPrompts:I,onTabChange:A},r),e[25]=u,e[26]=c.activeTab,e[27]=p,e[28]=r,e[29]=I,e[30]=S,e[31]=P,e[32]=R,e[33]=C,e[34]=y,e[35]=M):M=e[35];let D;e[36]!==l||e[37]!==r||e[38]!==M?(D=n.jsx(E.Suspense,{fallback:N,children:n.jsx(Sg,{connectionId:r,onAuthenticate:l,children:M})}),e[36]=l,e[37]=r,e[38]=M,e[39]=D):D=e[39];let $;e[40]!==i?($=n.jsx(ii,{className:"px-6 py-4 border-t border-border shrink-0",children:n.jsx(re,{variant:"outline",onClick:()=>i(!1),children:"Done"})}),e[40]=i,e[41]=$):$=e[41];let z;e[42]!==D||e[43]!==$?(z=n.jsxs(Ot,{className:"sm:max-w-2xl h-[75vh] max-h-[75vh] flex flex-col p-0 gap-0 overflow-hidden w-[95vw]",children:[D,$]}),e[42]=D,e[43]=$,e[44]=z):z=e[44];let W;return e[45]!==i||e[46]!==s||e[47]!==z?(W=n.jsx(Lt,{open:s,onOpenChange:i,children:z}),e[45]=i,e[46]=s,e[47]=z,e[48]=W):W=e[48],W}const vn={tools:null,resources:null,prompts:null},jg=$u.pick({status:!0,title:!0,description:!0,icon:!0,metadata:!0,connections:!0});function Ng(t){const s=new TextEncoder().encode(t),i=Array.from(s,r=>String.fromCharCode(r)).join("");return btoa(i)}function Eg(t){const e=K.c(11),{url:s,agentId:i}=t,[r,o]=E.useState(!1);let a;e[0]!==i||e[1]!==s?(a=async()=>{De("agent_connect_action",{agent_id:i,action:"copy_url"}),await navigator.clipboard.writeText(s),o(!0),le.success("Agent URL copied to clipboard"),setTimeout(()=>o(!1),2e3)},e[0]=i,e[1]=s,e[2]=a):a=e[2];const l=a;let h;e[3]!==r?(h=r?n.jsx(ri,{size:20,className:"text-green-600"}):n.jsx(Qt,{size:20}),e[3]=r,e[4]=h):h=e[4];const c=r?"Copied!":"Copy URL";let d;e[5]!==c?(d=n.jsx("span",{className:"text-xs font-medium",children:c}),e[5]=c,e[6]=d):d=e[6];let u;return e[7]!==l||e[8]!==h||e[9]!==d?(u=n.jsxs(re,{type:"button",variant:"outline",onClick:l,className:"h-auto py-3 px-4 flex flex-col items-center gap-2",children:[h,d]}),e[7]=l,e[8]=h,e[9]=d,e[10]=u):u=e[10],u}function Tg(t){const e=K.c(8),{url:s,serverName:i,agentId:r}=t;let o;e[0]!==r||e[1]!==i||e[2]!==s?(o=()=>{De("agent_connect_action",{agent_id:r,action:"install_cursor"});const d=lh(i),f=Ng(JSON.stringify({type:"http",url:s,headers:{"x-mesh-client":"Cursor"}},null,2)),m=`cursor://anysphere.cursor-deeplink/mcp/install?name=${encodeURIComponent(d)}&config=${encodeURIComponent(f)}`;window.open(m,"_blank"),le.success("Opening Cursor...")},e[0]=r,e[1]=i,e[2]=s,e[3]=o):o=e[3];const a=o;let l,h;e[4]===Symbol.for("react.memo_cache_sentinel")?(l=n.jsx("img",{src:"/logos/cursor.svg",alt:"Cursor",className:"h-5 w-5",style:{filter:"brightness(0) saturate(100%) invert(11%) sepia(8%) saturate(785%) hue-rotate(1deg) brightness(95%) contrast(89%)"}}),h=n.jsx("span",{className:"text-xs font-medium",children:"Install on Cursor"}),e[4]=l,e[5]=h):(l=e[4],h=e[5]);let c;return e[6]!==a?(c=n.jsxs(re,{type:"button",variant:"outline",onClick:a,className:"h-auto py-3 px-4 flex flex-col items-center gap-2",children:[l,h]}),e[6]=a,e[7]=c):c=e[7],c}function Rg(t){const e=K.c(12),{url:s,serverName:i,agentId:r}=t,[o,a]=E.useState(!1);let l;e[0]!==r||e[1]!==i||e[2]!==s?(l=async()=>{De("agent_connect_action",{agent_id:r,action:"install_claude_code"});const m=lh(i),_=JSON.stringify({type:"http",url:s,headers:{"x-mesh-client":"Claude Code"}},null,2),g=`claude mcp add-json "${m}" '${_.replace(/'/g,"'\\''")}' --scope user`;await navigator.clipboard.writeText(g),a(!0),le.success("Claude Code command copied to clipboard"),setTimeout(()=>a(!1),2e3)},e[0]=r,e[1]=i,e[2]=s,e[3]=l):l=e[3];const h=l;let c;e[4]!==o?(c=o?n.jsx(ri,{size:20,className:"text-green-600"}):n.jsx("img",{src:"/logos/Claude Code.svg",alt:"Claude Code",className:"h-5 w-5",style:{filter:"brightness(0) saturate(100%) invert(55%) sepia(31%) saturate(1264%) hue-rotate(331deg) brightness(92%) contrast(86%)"}}),e[4]=o,e[5]=c):c=e[5];const d=o?"Copied!":"Install on Claude Code";let u;e[6]!==d?(u=n.jsx("span",{className:"text-xs font-medium",children:d}),e[6]=d,e[7]=u):u=e[7];let f;return e[8]!==h||e[9]!==c||e[10]!==u?(f=n.jsxs(re,{type:"button",variant:"outline",onClick:h,className:"h-auto py-3 px-4 flex flex-col items-center gap-2",children:[c,u]}),e[8]=h,e[9]=c,e[10]=u,e[11]=f):f=e[11],f}function Pg({virtualMcp:t}){const e=qi(),[s,i]=E.useState(null),[r,o]=E.useState(!1),[a,l]=E.useState(!1),h=t.id,c=t.title||`agent-${h.slice(0,8)}`,d=s?`bunx @decocms/typegen@latest --mcp ${h} --key ${s} --output client.ts`:`bunx @decocms/typegen@latest --mcp ${h} --key <api-key> --output client.ts`,u=async()=>{o(!0);try{const{key:m}=await e.call("API_KEY_CREATE",{name:`typegen-${c}`,permissions:{[h]:["*"]}});if(!m)throw new Error("No key in response");i(m),De("agent_typegen_key_generated",{agent_id:h})}catch{De("agent_typegen_key_failed",{agent_id:h}),le.error("Failed to generate API key")}finally{o(!1)}},f=async()=>{De("agent_connect_action",{agent_id:h,action:"typegen_copy_command",has_api_key:!!s}),await navigator.clipboard.writeText(d),l(!0),le.success("Command copied to clipboard"),setTimeout(()=>l(!1),2e3)};return n.jsxs("div",{className:"flex min-w-0 flex-col gap-3",children:[n.jsxs("div",{className:"flex items-start justify-between gap-3",children:[n.jsxs("div",{className:"flex flex-col gap-0.5",children:[n.jsx("h4",{className:"text-sm font-medium text-foreground",children:"Generate typed client"}),n.jsxs("p",{className:"text-xs text-muted-foreground",children:["Introspects this agent and writes a typed"," ",n.jsx("code",{className:"font-mono",children:"client.ts"})," you can import directly."]})]}),!s&&n.jsxs(re,{type:"button",variant:"outline",size:"sm",className:"shrink-0 gap-1.5",onClick:u,disabled:r,children:[r?n.jsx(Ce,{size:14,className:"animate-spin"}):n.jsx(ea,{size:14}),n.jsx("span",{children:r?"Generating…":"Generate API key"})]})]}),s&&n.jsx("p",{className:"rounded-md border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-700",children:"Store this key securely — it won't be shown again."}),n.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"Generate client"}),n.jsx("div",{className:"rounded-md border border-input bg-muted/50 px-3 py-2.5",children:n.jsxs("div",{className:"flex items-start gap-2",children:[n.jsx("code",{className:"min-w-0 flex-1 break-all font-mono text-xs text-muted-foreground",children:d}),n.jsx(re,{type:"button",variant:"ghost",size:"icon",className:"size-6 shrink-0",onClick:f,children:a?n.jsx(ri,{size:12,className:"text-green-600"}):n.jsx(Qt,{size:12})})]})}),n.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"Runtime variables"}),n.jsx(Dg,{apiKey:s,agentId:h})]})}function Dg(t){const e=K.c(21),{apiKey:s,agentId:i}=t,[r,o]=E.useState(!1),a=window.location.origin,l=s?`MESH_API_KEY=${s}`:"MESH_API_KEY=<api-key>",h=`MESH_BASE_URL=${a}`,c=`${l}
|
|
7
|
+
`);P(H.source).append(X);for(const oe of C.current)try{oe(H.source,X)}catch{}y(oe=>oe+1)}catch{}},W=U=>{const H=U.type;try{const X=JSON.parse(U.data);switch(I=0,H){case"lifecycle":{const oe=X;c(oe.state);const L=oe.state.phase==="running"?oe.state.port:null,se=R.current;if(R.current=L,se!==null&&L!==null&&se!==L)for(const ee of j.current)try{ee()}catch{}return}case"status":u(X);return;case"tasks":{const L=X.active.map(se=>se.logName??"").filter(Boolean);x(L);return}case"scripts":v(X.scripts);return;case"branch":{const oe=X.meta;m(oe);return}case"reload":for(const oe of j.current)try{oe()}catch{}return}}catch{}};function F(){if(k)return;const U=new EventSource(S);A=U,U.onopen=()=>{},U.onerror=()=>{A===U&&U.readyState===EventSource.CLOSED&&Y("studio")},U.addEventListener("phase",D),U.addEventListener("gone",$),U.addEventListener(cl,z);for(const H of ll)U.addEventListener(H,W)}function V(){if(k||!B||M)return;const U=new EventSource(B);M=U;let H=!1;U.onopen=()=>{if(k||M!==U)return;H=!0,I=0;const X=A;A=null,X?.close()},U.onerror=()=>{M===U&&U.readyState===EventSource.CLOSED&&J(U,H)},U.addEventListener(cl,z);for(const X of ll)U.addEventListener(X,W)}async function J(U,H){const X=B?await z_(B):!1;if(!(k||M!==U)){if(U.close(),M=null,X){$(),A||F();return}H&&Y("direct")}}function Y(U){if(k||N)return;const H=Math.min(B_*2**I,M_);I++,N=setTimeout(()=>{if(N=null,!k){if(U==="direct"){M?.close(),M=null,V();return}A?.close(),A=null,F()}},H)}return F(),()=>{k=!0,A?.close(),M?.close(),N&&clearTimeout(N)}},[t,e,o.slug,i,B]);const T={phase:a,lifecycle:h,status:d,branch:f,notFound:p,scripts:g,activeProcesses:b,getBuffer:S=>w.current.get(S)?.get()??"",hasData:S=>(w.current.get(S)?.get().length??0)>0,subscribeChunks:S=>(C.current.add(S),()=>{C.current.delete(S)}),subscribeReload:S=>(j.current.add(S),()=>{j.current.delete(S)})};return n.jsx(Hh,{value:T,children:r})}function Yt(){return E.use(Hh)}function H_(t){const{subscribeChunks:e}=Yt(),s=E.useRef(t);s.current=t,E.useEffect(()=>e((o,a)=>{s.current?.(o,a)}),[e])}function W_(t){const{subscribeReload:e}=Yt(),s=E.useRef(t);s.current=t,E.useEffect(()=>e(()=>{s.current?.()}),[e])}const U_={settings:Ef,automations:Kc,preview:Ki,content:Zr,git:Mi};function hl(t){const e=Qr(t);if(e.type==="icon"){const s=en(e.name);return s?{kind:"component",Component:s}:null}return e.type==="url"?{kind:"url",src:e.url}:null}function mn(t){if(t.kind==="system")return{kind:"component",Component:U_[t.tabId]};const e=hl(t.iconUrl);if(e)return e;if(!t.appId)return{kind:"fallback"};const s=t.connections.find(r=>r.id===t.appId);if(!s)return{kind:"fallback"};const i=hl(s.icon);return i||{kind:"fallback"}}function K_(t){const{org:e}=Pe(),s=qi(),i=eh(),r=E.useSyncExternalStore(i.threads.subscribe,i.threads.get),o=t?r.find(l=>l.id===t)??null:null,{data:a}=Lu({queryKey:Bt.ensureTask(e.id,t),queryFn:async()=>{if(!t)return null;try{const{item:l}=await s.call("COLLECTION_THREADS_GET",{id:t});return l??null}catch{return null}},select:l=>l?.metadata??null,staleTime:3e4});return o?.metadata??a??null}function Wh(t){const e=K.c(28),s=ts();let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i={strict:!1},e[0]=i):i=e[0];const r=$o(i),o=Mt(t.virtualMcpId),a=K_(t.taskId),{org:l}=Pe(),{currentBranch:h}=ss();let c;e[1]!==o?(c=si(o),e[1]=o,e[2]=c):c=e[2];const d=c,u=d?.connectionId??"",f=d?.owner??"",m=d?.name??"",p=d?h:null;let _;e[3]!==l.id||e[4]!==l.slug||e[5]!==u||e[6]!==f||e[7]!==m||e[8]!==p?(_={orgId:l.id,orgSlug:l.slug,connectionId:u,owner:f,repo:m,branch:p},e[3]=l.id,e[4]=l.slug,e[5]=u,e[6]=f,e[7]=m,e[8]=p,e[9]=_):_=e[9];const g=ca(_),v=g.data?.state==="open",b=o?.metadata?.ui??null,x=b?.layout??null,y=x?.tabs??[],w=b?.pinnedViews??[],C=a?.expanded_tools??[],j=Lc(o),R=o?.metadata;let B;e[10]!==R?(B=ti(R),e[10]=R,e[11]=B):B=e[11];const P=B,{granted:T}=fm("agents:manage");let S;e[12]===Symbol.for("react.memo_cache_sentinel")?(S={includeVirtual:!0},e[12]=S):S=e[12];const k=Vi(S),N=Yt().lifecycle.phase==="running";let A;e[13]!==h||e[14]!==o||e[15]!==P||e[16]!==l.slug?(A=P&&o?.id&&h?{orgSlug:l.slug,virtualMcpId:o.id,branch:h}:null,e[13]=h,e[14]=o,e[15]=P,e[16]=l.slug,e[17]=A):A=e[17];const M=A;let D;e[18]!==N?(D={fetchEnabled:N},e[18]=N,e[19]=D):D=e[19];const{data:$}=ha(M,D);let z;e[20]!==N?(z={fetchEnabled:N},e[20]=N,e[21]=z):z=e[21];const{data:W}=da(M,z),F=ga($,W),{activeTab:V,mainOpen:J}=tm({mainParam:r.main,metadata:x?{defaultMainView:x.defaultMainView??null,tabs:y.map(q_)}:null}),Y=j&&(v||g.isPending&&V==="git"),U=x?{defaultMainView:x.defaultMainView??null,tabs:y.map(V_)}:null,H=V==="git"&&!Y&&!g.isPending?Fn(U):V==="content"&&!F?Fn(U):V,X=V==="git"&&!Y&&!g.isPending?!1:J,oe=Jc(H),L=[];P&&(L.push({id:"preview",title:"Preview"}),F&&L.push({id:"content",title:"Content"})),Y&&L.push({id:"git",title:"Review changes"}),T&&L.push({id:"settings",title:"Settings"}),L.push({id:"automations",title:"Automations"});const se=new Map;for(const ne of C){const ke=Ya(ne.appId,ne.toolName);se.set(ke,{id:ke,title:ne.toolName,appId:ne.appId,iconKey:ne.toolName})}for(const ne of w){const ke=Ya(ne.connectionId,ne.toolName);se.set(ke,{id:ke,title:ne.label||ne.toolName,appId:ne.connectionId,iconKey:ne.toolName,iconUrl:ne.icon??null})}const ee=Zc(H),Q=ee?ee.key.split("/").pop()??ee.key:null,O=Q?[{id:H,title:Q,kind:"file",icon:{kind:"component",Component:ne=>E.createElement(Li,{filename:Q,...ne})}}]:[],ce=Qc(H),ue=ce?[{id:H,title:(ce.path.split("/").pop()??ce.path).replace(/\.html$/i,""),kind:"file",icon:{kind:"component",Component:ne=>E.createElement(ce.path.startsWith("pages/")?Ki:sh,ne)}}]:[];let fe;e[22]!==k?(fe=ne=>({id:ne.id,title:ne.title,kind:"agent",icon:mn({tabId:ne.id,kind:"agent",appId:ne.view.appId,connections:k})}),e[22]=k,e[23]=fe):fe=e[23];const q=[...O,...ue,...y.map(fe),...Array.from(se.values()).map(ne=>({id:ne.id,title:ne.title,kind:"expanded",icon:mn({tabId:ne.iconKey,kind:"expanded",appId:ne.appId,iconUrl:ne.iconUrl,connections:k})})),...L.map(ne=>({id:ne.id,title:ne.title,kind:"system",icon:mn({tabId:ne.id,kind:"system",connections:k})}))];let te;return e[24]!==H||e[25]!==X||e[26]!==s?(te=ne=>{const ke=sm({clickedId:ne,activeTab:H,mainOpen:X});s({to:".",search:at=>({...at,main:ke}),replace:!0})},e[24]=H,e[25]=X,e[26]=s,e[27]=te):te=e[27],{activeTab:H,mainOpen:X,setActiveTab:te,systemTabs:L,layoutTabs:y,expandedTools:C,automationTabParsed:oe,tabs:q}}function V_(t){return{id:t.id}}function q_(t){return{id:t.id}}function Uh(t){const{managerAgentId:e,managerName:s,kind:i,id:r,instructions:o}=t,a=` to improve the instructions of ${i} "${r}". Here are its current instructions.
|
|
8
|
+
<current_instructions>${o}</current_instructions>`;return{type:"doc",content:[{type:"paragraph",content:[{type:"text",text:"Use "},{type:"mention",attrs:{id:e,name:s,char:"@",metadata:{agentId:e,title:s}}},{type:"text",text:a}]}]}}function G_(t){const e=K.c(86),{value:s,onChange:i,onColorChange:r,name:o,size:a,className:l,avatarClassName:h,showHoverOverlay:c,disabled:d}=t,u=a===void 0?"lg":a,f=c===void 0?!0:c,m=d===void 0?!1:d,[p,_]=E.useState(!1),[g,v]=E.useState("icons"),[b,x]=E.useState(""),[y,w]=E.useState("blue");let C;e[0]!==s?(C=Qr(s),e[0]=s,e[1]=C):C=e[1];const j=C,R=j.type==="icon"||j.type==="url"&&j.color?j.color:y;let B;e[2]!==i||e[3]!==R?(B=Be=>{i(fn(Be,R))},e[2]=i,e[3]=R,e[4]=B):B=e[4];const P=B;let T;e[5]!==i||e[6]!==r||e[7]!==j.name||e[8]!==j.type||e[9]!==j.url?(T=Be=>{w(Be),r?.(Be),j.type==="icon"?i(fn(j.name,Be)):j.type==="url"&&i(Ua(j.url,Be))},e[5]=i,e[6]=r,e[7]=j.name,e[8]=j.type,e[9]=j.url,e[10]=T):T=e[10];const S=T;let k;e[11]!==i||e[12]!==R?(k=Be=>{i(Ua(Be,R)),_(!1)},e[11]=i,e[12]=R,e[13]=k):k=e[13];const I=k;let N;e[14]!==i||e[15]!==R?(N=()=>{const Be=Ko(),mt=Be[Math.floor(Math.random()*Be.length)];i(fn(mt,R))},e[14]=i,e[15]=R,e[16]=N):N=e[16];const A=N;let M,D,$,z,W,F,V,J,Y;if(e[17]!==l||e[18]!==m||e[19]!==p||e[20]!==u){const Be={xs:"rounded-md",sm:"rounded-lg","sm+":"rounded-xl",md:"rounded-xl",lg:"rounded-2xl",xl:"rounded-2xl"};D=Ts,V=m?!1:p,J=_,M=Rs,F=!0,Y="button",$="icon-picker-trigger",z=m,W=he("relative group overflow-hidden",m?"cursor-default opacity-50":"cursor-pointer",Be[u],l),e[17]=l,e[18]=m,e[19]=p,e[20]=u,e[21]=M,e[22]=D,e[23]=$,e[24]=z,e[25]=W,e[26]=F,e[27]=V,e[28]=J,e[29]=Y}else M=e[21],D=e[22],$=e[23],z=e[24],W=e[25],F=e[26],V=e[27],J=e[28],Y=e[29];let U;e[30]!==h||e[31]!==o||e[32]!==u||e[33]!==s?(U=n.jsx(Ka,{icon:s,name:o,size:u,className:h}),e[30]=h,e[31]=o,e[32]=u,e[33]=s,e[34]=U):U=e[34];let H;e[35]!==m||e[36]!==f?(H=f&&!m&&n.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/50 opacity-0 group-hover:opacity-100 transition-opacity",children:n.jsx(Zr,{size:16,className:"text-white"})}),e[35]=m,e[36]=f,e[37]=H):H=e[37];let X;e[38]!==$||e[39]!==z||e[40]!==W||e[41]!==U||e[42]!==H||e[43]!==Y?(X=n.jsxs("button",{type:Y,"data-testid":$,disabled:z,className:W,children:[U,H]}),e[38]=$,e[39]=z,e[40]=W,e[41]=U,e[42]=H,e[43]=Y,e[44]=X):X=e[44];let oe;e[45]!==M||e[46]!==F||e[47]!==X?(oe=n.jsx(M,{asChild:F,children:X}),e[45]=M,e[46]=F,e[47]=X,e[48]=oe):oe=e[48];let L;e[49]!==o||e[50]!==s?(L=n.jsx("div",{className:"flex items-center justify-center py-4",children:n.jsx(Ka,{icon:s,name:o,size:"xl"})}),e[49]=o,e[50]=s,e[51]=L):L=e[51];let se;e[52]===Symbol.for("react.memo_cache_sentinel")?(se=()=>v("icons"),e[52]=se):se=e[52];const ee=g==="icons"?"border-foreground text-foreground":"border-transparent text-muted-foreground hover:text-foreground";let Q;e[53]!==ee?(Q=he("px-3 py-2 text-sm font-medium border-b-2 -mb-px transition-colors",ee),e[53]=ee,e[54]=Q):Q=e[54];let O;e[55]!==Q?(O=n.jsx("button",{type:"button",onClick:se,className:Q,children:"Icons"}),e[55]=Q,e[56]=O):O=e[56];let ce;e[57]===Symbol.for("react.memo_cache_sentinel")?(ce=()=>v("upload"),e[57]=ce):ce=e[57];const ue=g==="upload"?"border-foreground text-foreground":"border-transparent text-muted-foreground hover:text-foreground";let fe;e[58]!==ue?(fe=he("px-3 py-2 text-sm font-medium border-b-2 -mb-px transition-colors",ue),e[58]=ue,e[59]=fe):fe=e[59];let q;e[60]!==fe?(q=n.jsx("button",{type:"button",onClick:ce,className:fe,children:"Upload"}),e[60]=fe,e[61]=q):q=e[61];let te;e[62]===Symbol.for("react.memo_cache_sentinel")?(te=n.jsx("div",{className:"flex-1"}),e[62]=te):te=e[62];let me;e[63]!==O||e[64]!==q?(me=n.jsxs("div",{className:"flex items-center border-b border-border px-3",children:[O,q,te]}),e[63]=O,e[64]=q,e[65]=me):me=e[65];let ne;e[66]!==S||e[67]!==A||e[68]!==P||e[69]!==I||e[70]!==j.name||e[71]!==j.type||e[72]!==b||e[73]!==R||e[74]!==g?(ne=g==="icons"?n.jsx(Z_,{search:b,onSearchChange:x,selectedColor:R,onColorChange:S,onSelectIcon:P,onRandom:A,currentIconName:j.type==="icon"?j.name:null}):n.jsx(Q_,{onUpload:I}),e[66]=S,e[67]=A,e[68]=P,e[69]=I,e[70]=j.name,e[71]=j.type,e[72]=b,e[73]=R,e[74]=g,e[75]=ne):ne=e[75];let ke;e[76]!==L||e[77]!==me||e[78]!==ne?(ke=n.jsx(Ps,{align:"start",className:"w-80 p-0",onOpenAutoFocus:Y_,children:n.jsxs("div",{className:"flex flex-col",children:[L,me,ne]})}),e[76]=L,e[77]=me,e[78]=ne,e[79]=ke):ke=e[79];let at;return e[80]!==D||e[81]!==V||e[82]!==J||e[83]!==oe||e[84]!==ke?(at=n.jsxs(D,{open:V,onOpenChange:J,children:[oe,ke]}),e[80]=D,e[81]=V,e[82]=J,e[83]=oe,e[84]=ke,e[85]=at):at=e[85],at}function Y_(t){return t.preventDefault()}function X_(t){const e=K.c(27),{selectedColor:s,onColorChange:i}=t,[r,o]=E.useState(!1);let a,l,h,c,d,u,f;if(e[0]!==r||e[1]!==s){const b=Vc(s);l=Ts,u=r,f=o,a=Rs,d=!0,h="button",c=he("h-6 w-6 rounded-full shrink-0 ring-2 ring-offset-2 ring-offset-background transition-all cursor-pointer hover:scale-110",b.dot,"ring-foreground/20"),e[0]=r,e[1]=s,e[2]=a,e[3]=l,e[4]=h,e[5]=c,e[6]=d,e[7]=u,e[8]=f}else a=e[2],l=e[3],h=e[4],c=e[5],d=e[6],u=e[7],f=e[8];let m;e[9]!==h||e[10]!==c?(m=n.jsx("button",{type:h,className:c,title:"Change color"}),e[9]=h,e[10]=c,e[11]=m):m=e[11];let p;e[12]!==a||e[13]!==d||e[14]!==m?(p=n.jsx(a,{asChild:d,children:m}),e[12]=a,e[13]=d,e[14]=m,e[15]=p):p=e[15];let _;e[16]!==i||e[17]!==s?(_=Rf.map(b=>n.jsx("button",{type:"button",onClick:()=>{i(b.name),o(!1)},className:he("h-5 w-5 rounded-full transition-all shrink-0 cursor-pointer",b.dot,s===b.name?"ring-2 ring-offset-1 ring-offset-background ring-foreground/30 scale-110":"hover:scale-110"),title:b.name},b.name)),e[16]=i,e[17]=s,e[18]=_):_=e[18];let g;e[19]!==_?(g=n.jsx(Ps,{align:"start",side:"right",sideOffset:8,className:"w-auto p-2",onOpenAutoFocus:J_,children:n.jsx("div",{className:"grid grid-cols-4 gap-1",children:_})}),e[19]=_,e[20]=g):g=e[20];let v;return e[21]!==l||e[22]!==u||e[23]!==f||e[24]!==p||e[25]!==g?(v=n.jsxs(l,{open:u,onOpenChange:f,children:[p,g]}),e[21]=l,e[22]=u,e[23]=f,e[24]=p,e[25]=g,e[26]=v):v=e[26],v}function J_(t){return t.preventDefault()}function Z_(t){const e=K.c(44),{search:s,onSearchChange:i,selectedColor:r,onColorChange:o,onSelectIcon:a,onRandom:l,currentIconName:h}=t;let c,d,u,f,m,p,_;if(e[0]!==h||e[1]!==o||e[2]!==l||e[3]!==i||e[4]!==a||e[5]!==s||e[6]!==r){const y=Ko(),w=Vc(r);d=s.trim()?y.filter(S=>{const k=zn(S),I=s.toLowerCase();return k.includes(I)||S.toLowerCase().includes(I)}):y,p="flex flex-col";let C;e[14]===Symbol.for("react.memo_cache_sentinel")?(C=n.jsx(Oi,{size:14,className:"absolute left-2 top-1/2 -translate-y-1/2 text-muted-foreground pointer-events-none"}),e[14]=C):C=e[14];let j;e[15]!==i?(j=S=>i(S.target.value),e[15]=i,e[16]=j):j=e[16];let R;e[17]!==s||e[18]!==j?(R=n.jsxs("div",{className:"relative flex-1",children:[C,n.jsx(qe,{value:s,onChange:j,placeholder:"Filter...",className:"h-8 text-xs pl-7"})]}),e[17]=s,e[18]=j,e[19]=R):R=e[19];let B;e[20]===Symbol.for("react.memo_cache_sentinel")?(B=n.jsx(Tf,{size:14,className:"text-muted-foreground"}),e[20]=B):B=e[20];let P;e[21]!==l?(P=n.jsx("button",{type:"button",onClick:l,className:"h-8 w-8 flex items-center justify-center rounded-md border border-border hover:bg-accent transition-colors shrink-0",title:"Random icon",children:B}),e[21]=l,e[22]=P):P=e[22];let T;e[23]!==o||e[24]!==r?(T=n.jsx(X_,{selectedColor:r,onColorChange:o}),e[23]=o,e[24]=r,e[25]=T):T=e[25],e[26]!==P||e[27]!==T||e[28]!==R?(_=n.jsxs("div",{className:"flex items-center gap-2 px-3 py-2",children:[R,P,T]}),e[26]=P,e[27]=T,e[28]=R,e[29]=_):_=e[29],c=rn,m="h-56",u="grid grid-cols-9 gap-0.5 px-2 pb-2",f=d.map(S=>{const k=en(S);return k?n.jsx("button",{type:"button",onClick:()=>a(S),className:he("h-8 w-8 flex items-center justify-center rounded-md transition-colors cursor-pointer",h===S?he(w.bg,w.text):he(w.text,"hover:bg-accent")),title:S,children:n.jsx(k,{size:18})},S):null}),e[0]=h,e[1]=o,e[2]=l,e[3]=i,e[4]=a,e[5]=s,e[6]=r,e[7]=c,e[8]=d,e[9]=u,e[10]=f,e[11]=m,e[12]=p,e[13]=_}else c=e[7],d=e[8],u=e[9],f=e[10],m=e[11],p=e[12],_=e[13];let g;e[30]!==u||e[31]!==f?(g=n.jsx("div",{className:u,children:f}),e[30]=u,e[31]=f,e[32]=g):g=e[32];let v;e[33]!==d.length?(v=d.length===0&&n.jsx("div",{className:"flex items-center justify-center py-8 text-sm text-muted-foreground",children:"No icons found"}),e[33]=d.length,e[34]=v):v=e[34];let b;e[35]!==c||e[36]!==m||e[37]!==g||e[38]!==v?(b=n.jsxs(c,{className:m,children:[g,v]}),e[35]=c,e[36]=m,e[37]=g,e[38]=v,e[39]=b):b=e[39];let x;return e[40]!==p||e[41]!==_||e[42]!==b?(x=n.jsxs("div",{className:p,children:[_,b]}),e[40]=p,e[41]=_,e[42]=b,e[43]=x):x=e[43],x}function Q_(t){const e=K.c(27),{onUpload:s}=t,i=E.useRef(null);let r;e[0]!==s?(r=C=>{const j=C.target.files?.[0];if(!j)return;if(j.size>2097152){le.error("Image must be smaller than 2MB"),C.target.value="";return}const R=new FileReader;R.onerror=()=>{le.error("Failed to read image file"),i.current&&(i.current.value="")},R.onloadend=()=>{R.readyState===FileReader.DONE&&R.result&&s(R.result),i.current&&(i.current.value="")},R.readAsDataURL(j)},e[0]=s,e[1]=r):r=e[1];const o=r,[a,l]=E.useState("");let h;e[2]!==s||e[3]!==a?(h=()=>{const C=a.trim();C&&(s(C),l(""))},e[2]=s,e[3]=a,e[4]=h):h=e[4];const c=h;let d;e[5]!==o?(d=n.jsx("input",{type:"file",ref:i,className:"hidden",accept:"image/*",onChange:o}),e[5]=o,e[6]=d):d=e[6];let u;e[7]===Symbol.for("react.memo_cache_sentinel")?(u=()=>i.current?.click(),e[7]=u):u=e[7];let f;e[8]===Symbol.for("react.memo_cache_sentinel")?(f=n.jsxs("button",{type:"button",onClick:u,className:"h-24 rounded-lg border-2 border-dashed border-border hover:border-foreground/50 hover:bg-accent/50 transition-colors flex flex-col items-center justify-center gap-2 text-muted-foreground hover:text-foreground",children:[n.jsx(Lm,{size:20}),n.jsx("span",{className:"text-xs",children:"Click to upload an image (max 2MB)"})]}),e[8]=f):f=e[8];let m;e[9]===Symbol.for("react.memo_cache_sentinel")?(m=n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-xs text-muted-foreground",children:"or"}),n.jsx("div",{className:"flex-1 h-px bg-border"})]}),e[9]=m):m=e[9];let p;e[10]===Symbol.for("react.memo_cache_sentinel")?(p=C=>l(C.target.value),e[10]=p):p=e[10];let _;e[11]!==c?(_=C=>{C.key==="Enter"&&(C.preventDefault(),c())},e[11]=c,e[12]=_):_=e[12];let g;e[13]!==a||e[14]!==_?(g=n.jsx(qe,{value:a,onChange:p,placeholder:"Paste image URL...",className:"h-8 text-xs flex-1",onKeyDown:_}),e[13]=a,e[14]=_,e[15]=g):g=e[15];let v;e[16]!==a?(v=a.trim(),e[16]=a,e[17]=v):v=e[17];const b=!v;let x;e[18]!==c||e[19]!==b?(x=n.jsx(re,{variant:"outline",size:"sm",className:"h-8 px-3 text-xs shrink-0",onClick:c,disabled:b,children:"Apply"}),e[18]=c,e[19]=b,e[20]=x):x=e[20];let y;e[21]!==x||e[22]!==g?(y=n.jsxs("div",{className:"flex items-center gap-1.5",children:[g,x]}),e[21]=x,e[22]=g,e[23]=y):y=e[23];let w;return e[24]!==y||e[25]!==d?(w=n.jsxs("div",{className:"flex flex-col gap-3 p-4",children:[d,f,m,y]}),e[24]=y,e[25]=d,e[26]=w):w=e[26],w}function eg(t){const e=K.c(5),{value:s}=t;let i;if(e[0]!==s){i=Symbol.for("react.early_return_sentinel");e:{const o=Qr(s);if(o.type==="icon"){const a=en(o.name);if(a){let l;e[2]!==a?(l=n.jsx(a,{size:16,className:"text-muted-foreground"}),e[2]=a,e[3]=l):l=e[3],i=l;break e}}}e[0]=s,e[1]=i}else i=e[1];if(i!==Symbol.for("react.early_return_sentinel"))return i;let r;return e[4]===Symbol.for("react.memo_cache_sentinel")?(r=n.jsx(Om,{size:16,className:"text-muted-foreground"}),e[4]=r):r=e[4],r}function tg(t){const e=K.c(66),{value:s,onChange:i,className:r,disabled:o}=t,[a,l]=E.useState(!1),[h,c]=E.useState("");let d;e[0]!==s?(d=Qr(s),e[0]=s,e[1]=d):d=e[1];const u=d,f=u.type==="icon"?u.name:null;let m,p,_,g,v,b,x,y,w,C,j,R,B,P,T;if(e[2]!==r||e[3]!==f||e[4]!==o||e[5]!==i||e[6]!==a||e[7]!==h||e[8]!==s){const D=Ko();g=h.trim()?D.filter(Y=>{const U=h.toLowerCase();return zn(Y).includes(U)||Y.toLowerCase().includes(U)}):D,_=Ts,v=o?!1:a,b=l;const $=o?"cursor-default opacity-50":"cursor-pointer hover:bg-accent";let z;e[24]!==r||e[25]!==$?(z=he("size-7 shrink-0 rounded-md transition-colors flex items-center justify-center",$,r),e[24]=r,e[25]=$,e[26]=z):z=e[26];let W;e[27]!==s?(W=n.jsx(eg,{value:s}),e[27]=s,e[28]=W):W=e[28],e[29]!==o||e[30]!==z||e[31]!==W?(x=n.jsx(Rs,{asChild:!0,children:n.jsx("button",{type:"button",disabled:o,className:z,children:W})}),e[29]=o,e[30]=z,e[31]=W,e[32]=x):x=e[32],p=Ps,B="start",P="w-64 p-0",T=sg,j="flex flex-col";let F;e[33]===Symbol.for("react.memo_cache_sentinel")?(F=n.jsx(Oi,{size:14,className:"absolute left-2 top-1/2 -translate-y-1/2 text-muted-foreground pointer-events-none"}),e[33]=F):F=e[33];let V;e[34]===Symbol.for("react.memo_cache_sentinel")?(V=Y=>c(Y.target.value),e[34]=V):V=e[34],e[35]!==h?(R=n.jsx("div",{className:"px-2 py-2",children:n.jsxs("div",{className:"relative",children:[F,n.jsx(qe,{value:h,onChange:V,placeholder:"Filter...",className:"h-7 text-xs pl-7"})]})}),e[35]=h,e[36]=R):R=e[36],m=rn,C="h-48",y="grid grid-cols-8 gap-0.5 px-2 pb-2";let J;e[37]!==f||e[38]!==i?(J=Y=>{const U=en(Y);return U?n.jsx("button",{type:"button",onClick:()=>{i(`icon://${Y}`),l(!1)},className:he("h-7 w-7 flex items-center justify-center rounded-md transition-colors cursor-pointer",f===Y?"bg-accent text-foreground":"text-muted-foreground hover:bg-accent hover:text-foreground"),title:zn(Y),children:n.jsx(U,{size:16})},Y):null},e[37]=f,e[38]=i,e[39]=J):J=e[39],w=g.map(J),e[2]=r,e[3]=f,e[4]=o,e[5]=i,e[6]=a,e[7]=h,e[8]=s,e[9]=m,e[10]=p,e[11]=_,e[12]=g,e[13]=v,e[14]=b,e[15]=x,e[16]=y,e[17]=w,e[18]=C,e[19]=j,e[20]=R,e[21]=B,e[22]=P,e[23]=T}else m=e[9],p=e[10],_=e[11],g=e[12],v=e[13],b=e[14],x=e[15],y=e[16],w=e[17],C=e[18],j=e[19],R=e[20],B=e[21],P=e[22],T=e[23];let S;e[40]!==y||e[41]!==w?(S=n.jsx("div",{className:y,children:w}),e[40]=y,e[41]=w,e[42]=S):S=e[42];let k;e[43]!==g.length?(k=g.length===0&&n.jsx("div",{className:"flex items-center justify-center py-6 text-xs text-muted-foreground",children:"No icons found"}),e[43]=g.length,e[44]=k):k=e[44];let I;e[45]!==m||e[46]!==S||e[47]!==k||e[48]!==C?(I=n.jsxs(m,{className:C,children:[S,k]}),e[45]=m,e[46]=S,e[47]=k,e[48]=C,e[49]=I):I=e[49];let N;e[50]!==I||e[51]!==j||e[52]!==R?(N=n.jsxs("div",{className:j,children:[R,I]}),e[50]=I,e[51]=j,e[52]=R,e[53]=N):N=e[53];let A;e[54]!==p||e[55]!==N||e[56]!==B||e[57]!==P||e[58]!==T?(A=n.jsx(p,{align:B,className:P,onOpenAutoFocus:T,children:N}),e[54]=p,e[55]=N,e[56]=B,e[57]=P,e[58]=T,e[59]=A):A=e[59];let M;return e[60]!==_||e[61]!==v||e[62]!==b||e[63]!==x||e[64]!==A?(M=n.jsxs(_,{open:v,onOpenChange:b,children:[x,A]}),e[60]=_,e[61]=v,e[62]=b,e[63]=x,e[64]=A,e[65]=M):M=e[65],M}function sg(t){return t.preventDefault()}const ig=25*1024*1024,pn="home",_n="knowledge";function dl(t){return t==null?"":t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(0)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function _s(t){return t.split("/").pop()??t}function rg(t){const e=K.c(52),{form:s}=t,{upload:i}=mm(pn),r=pm(),o=E.useRef(null),[a,l]=E.useState(!1),[h,c]=E.useState(""),[d,u]=E.useState(!1);let f;e[0]!==a?(f={enabled:a},e[0]=a,e[1]=f):f=e[1];const{data:m}=_m(60,f),p=m===void 0?[]:m;let _;e[2]!==a?(_={enabled:a},e[2]=a,e[3]=_):_=e[3];const{data:g}=gm(_),v=g===void 0?[]:g;let b;e[4]!==s?(b=()=>s.getValues("metadata.knowledge")??[],e[4]=s,e[5]=b):b=e[5];const[x,y]=E.useState(b);let w;e[6]!==s?(w=q=>{y(q),s.setValue("metadata.knowledge",q,{shouldDirty:!0})},e[6]=s,e[7]=w):w=e[7];const C=w;let j;e[8]!==r||e[9]!==x||e[10]!==C||e[11]!==i?(j=async q=>{if(!q||q.length===0)return;const te=Array.from(q).filter(cg);if(te.length!==0){try{await i.mutateAsync({dir:_n,files:te})}catch(me){const ne=me;le.error(ne instanceof Error?ne.message:"Failed to upload file.");return}C([...x,...te.map(me=>({id:crypto.randomUUID(),name:me.name,volume:pn,path:`${_n}/${me.name}`,url:r(pn,`${_n}/${me.name}`),contentType:me.type||null,size:me.size,addedAt:new Date().toISOString()}))])}},e[8]=r,e[9]=x,e[10]=C,e[11]=i,e[12]=j):j=e[12];const R=j;let B;e[13]!==r||e[14]!==x||e[15]!==C?(B=q=>{x.some(te=>te.volume===q.volume&&te.path===q.path)||(C([...x,{id:crypto.randomUUID(),name:_s(q.path),volume:q.volume,path:q.path,url:r(q.volume,q.path),contentType:null,size:q.size??null,addedAt:new Date().toISOString()}]),l(!1))},e[13]=r,e[14]=x,e[15]=C,e[16]=B):B=e[16];const P=B;let T;e[17]!==r||e[18]!==x||e[19]!==C?(T=q=>{x.some(te=>te.volume===q.volume&&te.path===q.path)||(C([...x,{id:crypto.randomUUID(),name:_s(q.path),kind:"skill",volume:q.volume,path:q.path,url:r(q.volume,q.path),contentType:null,size:null,addedAt:new Date().toISOString()}]),l(!1))},e[17]=r,e[18]=x,e[19]=C,e[20]=T):T=e[20];const S=T;let k;e[21]!==x||e[22]!==C?(k=q=>{C(x.filter(te=>te.id!==q))},e[21]=x,e[22]=C,e[23]=k):k=e[23];const I=k;let N;e[24]===Symbol.for("react.memo_cache_sentinel")?(N=q=>{l(q),q&&c("")},e[24]=N):N=e[24];const A=N;let M;e[25]!==x?(M=new Set(x.map(lg)),e[25]=x,e[26]=M):M=e[26];const D=M,$=h.toLowerCase();let z;e[27]!==D?(z=q=>!D.has(`${q.volume}/${q.path}`),e[27]=D,e[28]=z):z=e[28];const W=p.filter(ag).filter(z).filter(q=>_s(q.path).toLowerCase().includes($)).slice(0,5);let F;e[29]!==D?(F=q=>!D.has(`${q.volume}/${q.path}`),e[29]=D,e[30]=F):F=e[30];const V=v.filter(F).filter(q=>_s(q.path).toLowerCase().includes($)).slice(0,5),J=q=>n.jsxs(Ds,{open:a,onOpenChange:A,children:[n.jsx(As,{asChild:!0,children:q}),n.jsxs(Is,{align:"end",className:"w-56",children:[n.jsxs(He,{onSelect:()=>{o.current?.click()},children:[n.jsx(Pf,{size:16}),"Upload file"]}),n.jsxs(Un,{children:[n.jsxs(Kn,{className:"gap-2 [&_svg:not([class*='text-'])]:text-muted-foreground",children:[n.jsx(Wn,{size:16}),"Select file or folder"]}),n.jsxs(Vn,{className:"w-72 p-0",children:[n.jsxs("div",{className:"flex items-center gap-2 border-b px-3",children:[n.jsx(Oi,{size:16,className:"shrink-0 text-muted-foreground"}),n.jsx("input",{value:h,onChange:te=>c(te.target.value),onKeyDown:og,placeholder:"Search files...",className:"h-10 w-full bg-transparent text-sm outline-none placeholder:text-muted-foreground"})]}),n.jsx("div",{className:"max-h-64 overflow-y-auto p-1",children:W.length===0?n.jsx("p",{className:"px-2 py-3 text-center text-sm text-muted-foreground",children:"No files found."}):W.map(te=>n.jsxs(He,{onSelect:()=>P(te),children:[n.jsx(Li,{filename:_s(te.path),className:"h-5 w-4 shrink-0"}),n.jsx("span",{className:"flex-1 truncate",children:_s(te.path)}),te.size!=null&&n.jsx("span",{className:"text-xs text-muted-foreground",children:dl(te.size)})]},`${te.volume}/${te.path}`))})]})]}),n.jsxs(Un,{children:[n.jsxs(Kn,{className:"gap-2 [&_svg:not([class*='text-'])]:text-muted-foreground",children:[n.jsx(Ss,{size:16}),"Select skill"]}),n.jsxs(Vn,{className:"w-72 p-0",children:[n.jsxs("div",{className:"flex items-center gap-2 border-b px-3",children:[n.jsx(Oi,{size:16,className:"shrink-0 text-muted-foreground"}),n.jsx("input",{value:h,onChange:te=>c(te.target.value),onKeyDown:ng,placeholder:"Search skills...",className:"h-10 w-full bg-transparent text-sm outline-none placeholder:text-muted-foreground"})]}),n.jsx("div",{className:"max-h-64 overflow-y-auto p-1",children:V.length===0?n.jsx("p",{className:"px-2 py-3 text-center text-sm text-muted-foreground",children:"No skills found."}):V.map(te=>n.jsxs(He,{onSelect:()=>S(te),children:[n.jsx(Ss,{size:16,className:"shrink-0"}),n.jsx("span",{className:"flex-1 truncate",children:_s(te.path)})]},`${te.volume}/${te.path}`))})]})]})]})]}),Y="flex flex-col gap-3";let U;e[31]===Symbol.for("react.memo_cache_sentinel")?(U=n.jsxs("div",{className:"flex flex-col gap-1",children:[n.jsx("h2",{className:"text-sm font-medium text-foreground",children:"Files and skills"}),n.jsx("p",{className:"text-sm text-muted-foreground",children:"Attach files and skills the agent can always reference."})]}),e[31]=U):U=e[31];const H=x.length>0&&J(n.jsxs(re,{variant:"outline",size:"sm",disabled:i.isPending,children:[i.isPending?n.jsx(Xo,{size:"xs"}):n.jsx(xt,{size:14}),"Add"]}));let X;e[32]!==H?(X=n.jsxs("div",{className:"flex items-center justify-between gap-3",children:[U,H]}),e[32]=H,e[33]=X):X=e[33];let oe;e[34]!==R?(oe=n.jsx("input",{ref:o,type:"file",multiple:!0,className:"hidden",onChange:q=>{R(q.target.files),q.target.value=""}}),e[34]=R,e[35]=oe):oe=e[35];let L,se;e[36]===Symbol.for("react.memo_cache_sentinel")?(L=q=>{q.preventDefault(),u(!0)},se=()=>u(!1),e[36]=L,e[37]=se):(L=e[36],se=e[37]);let ee;e[38]!==R?(ee=q=>{q.preventDefault(),u(!1),R(q.dataTransfer.files)},e[38]=R,e[39]=ee):ee=e[39];const Q=d&&"outline outline-2 outline-dashed outline-primary";let O;e[40]!==Q?(O=he("flex flex-col gap-2 rounded-lg",Q),e[40]=Q,e[41]=O):O=e[41];const ce=x.length===0?J(n.jsxs("button",{type:"button",className:"flex items-center gap-3 px-3 py-2.5 rounded-lg border border-dashed border-border hover:bg-accent/50 transition-colors w-full text-left cursor-pointer",children:[n.jsx("div",{className:"flex items-center justify-center size-8 rounded-md text-muted-foreground/75 border border-dashed border-border shrink-0",children:n.jsx(xt,{size:16})}),n.jsx("span",{className:"text-sm text-muted-foreground flex-1",children:"No files or skills yet. Add one or drag and drop here."})]})):x.map(q=>n.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 rounded-xl border bg-card",children:[q.kind==="skill"?n.jsx("div",{className:"flex items-center justify-center h-8 w-6.5 shrink-0 rounded-md bg-muted text-muted-foreground",children:n.jsx(Ss,{size:16})}):n.jsx(Li,{filename:q.name,className:"h-8 w-6.5 shrink-0"}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("p",{className:"text-sm font-medium truncate",children:q.name}),n.jsx("p",{className:"text-xs text-muted-foreground",children:q.kind==="skill"?"Skill":q.size!=null?dl(q.size):"File"})]}),n.jsx(re,{variant:"ghost",size:"icon",onClick:()=>I(q.id),"aria-label":`Remove ${q.name}`,children:n.jsx(qs,{size:16})})]},q.id));let ue;e[42]!==L||e[43]!==se||e[44]!==ee||e[45]!==O||e[46]!==ce?(ue=n.jsx("div",{onDragOver:L,onDragLeave:se,onDrop:ee,className:O,children:ce}),e[42]=L,e[43]=se,e[44]=ee,e[45]=O,e[46]=ce,e[47]=ue):ue=e[47];let fe;return e[48]!==X||e[49]!==oe||e[50]!==ue?(fe=n.jsxs("section",{className:Y,children:[X,oe,ue]}),e[48]=X,e[49]=oe,e[50]=ue,e[51]=fe):fe=e[51],fe}function ng(t){return t.stopPropagation()}function og(t){return t.stopPropagation()}function ag(t){return t.kind!=="dir"}function lg(t){return`${t.volume}/${t.path}`}function cg(t){return t.size<=ig}function hg(t){return t==null?"all":t.length===0?"self":"selected"}function dg(t){const e=K.c(65),{form:s,currentAgentId:i}=t,{org:r}=Pe(),o=Qu(),[a,l]=E.useState(!1);let h;e[0]!==s?(h=s.getValues("metadata.subAgents")??null,e[0]=s,e[1]=h):h=e[1];const c=h;let d;e[2]!==c?(d=()=>hg(c),e[2]=c,e[3]=d):d=e[3];const[u,f]=E.useState(d);let m;e[4]!==c?(m=c??[],e[4]=c,e[5]=m):m=e[5];const[p,_]=E.useState(m);let g,v,b,x,y,w;if(e[6]!==o||e[7]!==i||e[8]!==s||e[9]!==u||e[10]!==r||e[11]!==p){let B;e[18]!==i||e[19]!==r?(B=H=>H.id!==i&&H.id!==r.id&&H.status==="active",e[18]=i,e[19]=r,e[20]=B):B=e[20],g=o.filter(B);let P;e[21]!==p?(P=H=>p.includes(H.id),e[21]=p,e[22]=P):P=e[22];const T=g.filter(P);let S;e[23]!==s?(S=(H,X)=>s.setValue("metadata.subAgents",H==="all"?null:H==="self"?[]:X,{shouldDirty:!0}),e[23]=s,e[24]=S):S=e[24];const k=S;let I;e[25]!==k||e[26]!==p?(I=H=>{f(H),k(H,p)},e[25]=k,e[26]=p,e[27]=I):I=e[27];const N=I;let A;e[28]!==k||e[29]!==p?(A=H=>{const X=p.includes(H)?p.filter(oe=>oe!==H):[...p,H];_(X),k("selected",X)},e[28]=k,e[29]=p,e[30]=A):A=e[30],v=A,y="flex flex-col gap-3";let M;e[31]===Symbol.for("react.memo_cache_sentinel")?(M=n.jsx("h2",{className:"text-sm font-medium text-foreground",children:"Sub-agents"}),e[31]=M):M=e[31];let D;e[32]!==u?(D=u==="all"&&n.jsx("p",{className:"text-sm text-muted-foreground",children:"Can delegate to any agent in the organization."}),e[32]=u,e[33]=D):D=e[33];let $;e[34]!==u?($=u==="self"&&n.jsx("p",{className:"text-sm text-muted-foreground",children:"Can only delegate to a fresh copy of itself, no other agents."}),e[34]=u,e[35]=$):$=e[35];let z;e[36]!==D||e[37]!==$?(z=n.jsxs("div",{className:"flex flex-col gap-1",children:[M,D,$]}),e[36]=D,e[37]=$,e[38]=z):z=e[38];const W=u==="selected"&&T.length>0&&n.jsxs(re,{variant:"outline",size:"sm",onClick:()=>l(!0),children:[n.jsx(xt,{size:14}),"Add sub-agent"]});let F;e[39]!==N?(F=H=>N(H),e[39]=N,e[40]=F):F=e[40];let V;e[41]===Symbol.for("react.memo_cache_sentinel")?(V=n.jsx(Pt,{size:"sm",className:"w-auto",children:n.jsx(Dt,{})}),e[41]=V):V=e[41];let J;e[42]===Symbol.for("react.memo_cache_sentinel")?(J=n.jsxs(At,{align:"end",children:[n.jsx(ot,{value:"all",children:"Any agent"}),n.jsx(ot,{value:"selected",children:"Specific agents"}),n.jsx(ot,{value:"self",children:"Only itself"})]}),e[42]=J):J=e[42];let Y;e[43]!==u||e[44]!==F?(Y=n.jsxs(It,{value:u,onValueChange:F,children:[V,J]}),e[43]=u,e[44]=F,e[45]=Y):Y=e[45];let U;e[46]!==W||e[47]!==Y?(U=n.jsxs("div",{className:"flex items-center gap-2",children:[W,Y]}),e[46]=W,e[47]=Y,e[48]=U):U=e[48],e[49]!==z||e[50]!==U?(w=n.jsxs("div",{className:"flex items-center justify-between gap-3",children:[z,U]}),e[49]=z,e[50]=U,e[51]=w):w=e[51],b="flex flex-col gap-2",x=u==="selected"&&(T.length>0?T.map(H=>n.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 rounded-xl border bg-background",children:[n.jsx(Gt,{icon:H.icon,name:H.title,size:"sm",className:"shrink-0"}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("p",{className:"text-sm font-medium truncate",children:H.title}),H.description&&n.jsx("p",{className:"text-xs text-muted-foreground truncate",children:H.description})]}),n.jsx(re,{variant:"ghost",size:"icon",onClick:()=>v(H.id),children:n.jsx(ps,{size:16})})]},H.id)):n.jsxs("button",{type:"button",onClick:()=>l(!0),className:"flex items-center gap-3 px-3 py-2.5 rounded-lg border border-dashed border-border hover:bg-accent/50 transition-colors w-full text-left cursor-pointer",children:[n.jsx("div",{className:"flex items-center justify-center size-8 rounded-md text-muted-foreground/75 border border-dashed border-border shrink-0",children:n.jsx(xt,{size:16})}),n.jsx("span",{className:"text-sm text-muted-foreground",children:"No sub-agents selected yet. Add one — until then this agent can only delegate to itself."})]})),e[6]=o,e[7]=i,e[8]=s,e[9]=u,e[10]=r,e[11]=p,e[12]=g,e[13]=v,e[14]=b,e[15]=x,e[16]=y,e[17]=w}else g=e[12],v=e[13],b=e[14],x=e[15],y=e[16],w=e[17];let C;e[52]!==b||e[53]!==x?(C=n.jsx("div",{className:b,children:x}),e[52]=b,e[53]=x,e[54]=C):C=e[54];let j;e[55]!==g||e[56]!==v||e[57]!==a||e[58]!==p?(j=n.jsx(ug,{open:a,onOpenChange:l,candidates:g,selectedIds:p,onToggle:v}),e[55]=g,e[56]=v,e[57]=a,e[58]=p,e[59]=j):j=e[59];let R;return e[60]!==y||e[61]!==w||e[62]!==C||e[63]!==j?(R=n.jsxs("section",{className:y,children:[w,C,j]}),e[60]=y,e[61]=w,e[62]=C,e[63]=j,e[64]=R):R=e[64],R}function ug(t){const e=K.c(32),{open:s,onOpenChange:i,candidates:r,selectedIds:o,onToggle:a}=t,[l,h]=E.useState("");let c,d,u,f,m,p,_,g,v;if(e[0]!==r||e[1]!==i||e[2]!==a||e[3]!==s||e[4]!==l||e[5]!==o){const w=l.toLowerCase(),C=r.filter(j=>j.title.toLowerCase().includes(w)||j.description?.toLowerCase().includes(w));d=Lt,g=s,v=i,c=Ot,m="max-w-md",e[15]===Symbol.for("react.memo_cache_sentinel")?(p=n.jsx(is,{children:n.jsx(rs,{children:"Sub-agents"})}),e[15]=p):p=e[15],e[16]!==l?(_=n.jsx(hh,{value:l,onChange:h,placeholder:"Search agents...",className:"w-full"}),e[16]=l,e[17]=_):_=e[17],u="flex flex-col gap-1 max-h-80 overflow-y-auto",f=C.length===0?n.jsx("p",{className:"text-sm text-muted-foreground px-1 py-4 text-center",children:"No agents found."}):C.map(j=>n.jsxs("button",{type:"button",onClick:()=>a(j.id),className:"flex items-center gap-3 px-2 py-2 rounded-lg hover:bg-accent/50 transition-colors cursor-pointer w-full text-left",children:[n.jsx(nn,{checked:o.includes(j.id),className:"pointer-events-none",tabIndex:-1}),n.jsx(Gt,{icon:j.icon,name:j.title,size:"sm",className:"shrink-0"}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("p",{className:"text-sm font-medium truncate",children:j.title}),j.description&&n.jsx("p",{className:"text-xs text-muted-foreground truncate",children:j.description})]})]},j.id)),e[0]=r,e[1]=i,e[2]=a,e[3]=s,e[4]=l,e[5]=o,e[6]=c,e[7]=d,e[8]=u,e[9]=f,e[10]=m,e[11]=p,e[12]=_,e[13]=g,e[14]=v}else c=e[6],d=e[7],u=e[8],f=e[9],m=e[10],p=e[11],_=e[12],g=e[13],v=e[14];let b;e[18]!==u||e[19]!==f?(b=n.jsx("div",{className:u,children:f}),e[18]=u,e[19]=f,e[20]=b):b=e[20];let x;e[21]!==c||e[22]!==m||e[23]!==p||e[24]!==_||e[25]!==b?(x=n.jsxs(c,{className:m,children:[p,_,b]}),e[21]=c,e[22]=m,e[23]=p,e[24]=_,e[25]=b,e[26]=x):x=e[26];let y;return e[27]!==d||e[28]!==g||e[29]!==v||e[30]!==x?(y=n.jsx(d,{open:g,onOpenChange:v,children:x}),e[27]=d,e[28]=g,e[29]=v,e[30]=x,e[31]=y):y=e[31],y}function xr(){const t=K.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=n.jsx("div",{className:"flex items-center justify-center h-32",children:n.jsx(Ce,{className:"animate-spin text-muted-foreground",size:24})}),t[0]=e):e=t[0],e}function gn(t){return({error:e})=>e?.message?.includes("Method not found")||e?.code===-32601?n.jsx("div",{className:"flex-1 overflow-auto px-4 py-3 space-y-1",children:n.jsx("div",{className:"flex items-center justify-center h-32 text-sm text-muted-foreground",children:t})}):n.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center h-full p-6 text-center space-y-4",children:[n.jsx("div",{className:"bg-destructive/10 p-3 rounded-full",children:n.jsx(Ic,{className:"h-6 w-6 text-destructive"})}),n.jsxs("div",{className:"space-y-2",children:[n.jsx("h3",{className:"text-lg font-medium",children:"Something went wrong"}),n.jsx("p",{className:"text-sm text-muted-foreground max-w-xs mx-auto",children:e?.message?e.message.length>200?`${e.message.slice(0,200)}...`:e.message:"An unexpected error occurred"})]})]})}function fg(t){const e=K.c(23),{item:s,isSelected:i,onToggle:r,disabled:o}=t,a=o?"cursor-not-allowed opacity-50":"cursor-pointer",l=i?"bg-accent/25":"hover:bg-muted/50";let h;e[0]!==a||e[1]!==l?(h=he("flex items-start gap-3 p-4 rounded-lg transition-colors",a,l),e[0]=a,e[1]=l,e[2]=h):h=e[2];let c;e[3]!==s.name?(c=n.jsx("p",{className:"text-sm font-medium leading-none truncate",children:s.name}),e[3]=s.name,e[4]=c):c=e[4];let d;e[5]!==s.tags?(d=s.tags&&n.jsx("span",{className:"shrink-0",children:s.tags}),e[5]=s.tags,e[6]=d):d=e[6];let u;e[7]!==c||e[8]!==d?(u=n.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[c,d]}),e[7]=c,e[8]=d,e[9]=u):u=e[9];let f;e[10]!==s.description?(f=s.description&&n.jsx("p",{className:"text-xs text-muted-foreground line-clamp-2",children:s.description}),e[10]=s.description,e[11]=f):f=e[11];let m;e[12]!==u||e[13]!==f?(m=n.jsxs("div",{className:"flex-1 min-w-0 space-y-2",children:[u,f]}),e[12]=u,e[13]=f,e[14]=m):m=e[14];let p;e[15]!==o||e[16]!==i||e[17]!==r?(p=n.jsx(nn,{checked:i,onCheckedChange:r,disabled:o,className:"mt-0.5"}),e[15]=o,e[16]=i,e[17]=r,e[18]=p):p=e[18];let _;return e[19]!==h||e[20]!==m||e[21]!==p?(_=n.jsxs("label",{className:h,children:[m,p]}),e[19]=h,e[20]=m,e[21]=p,e[22]=_):_=e[22],_}function ba(t){const e=K.c(13),{items:s,selections:i,onToggle:r,emptyMessage:o,disabled:a}=t;let l,h,c;if(e[0]!==a||e[1]!==o||e[2]!==s||e[3]!==r||e[4]!==i){c=Symbol.for("react.early_return_sentinel");e:{const u=s.map(mg);if(s.length===0){let f;e[8]!==o?(f=n.jsx("div",{className:"flex-1 overflow-auto px-4 py-3 space-y-1",children:n.jsx("div",{className:"flex items-center justify-center h-32 text-sm text-muted-foreground",children:o})}),e[8]=o,e[9]=f):f=e[9],c=f;break e}l="flex-1 overflow-auto px-4 py-3 space-y-1",h=s.map(f=>n.jsx(fg,{item:f,isSelected:i===null||i?.includes(f.id),onToggle:()=>r(f.id,u),disabled:a},f.id))}e[0]=a,e[1]=o,e[2]=s,e[3]=r,e[4]=i,e[5]=l,e[6]=h,e[7]=c}else l=e[5],h=e[6],c=e[7];if(c!==Symbol.for("react.early_return_sentinel"))return c;let d;return e[10]!==l||e[11]!==h?(d=n.jsx("div",{className:l,children:h}),e[10]=l,e[11]=h,e[12]=d):d=e[12],d}function mg(t){return t.id}function pg(t){const e=K.c(13),{connectionId:s,selections:i,onToggle:r,disabled:o}=t,{org:a}=Pe();let l;e[0]!==s||e[1]!==a.id||e[2]!==a.slug?(l={connectionId:s,orgId:a.id,orgSlug:a.slug},e[0]=s,e[1]=a.id,e[2]=a.slug,e[3]=l):l=e[3];const h=ft(l);let c;e[4]!==h?(c={client:h},e[4]=h,e[5]=c):c=e[5];const{data:d}=dm(c);let u;e[6]!==d.tools?(u=d.tools.map(_g),e[6]=d.tools,e[7]=u):u=e[7];const f=u;let m;return e[8]!==o||e[9]!==f||e[10]!==r||e[11]!==i?(m=n.jsx(ba,{items:f,selections:i,onToggle:r,emptyMessage:"No tools available",disabled:o}),e[8]=o,e[9]=f,e[10]=r,e[11]=i,e[12]=m):m=e[12],m}function _g(t){return{id:t.name,name:t.name,description:t.description,tags:n.jsx(Im,{annotations:t.annotations,_meta:t._meta})}}function gg(t){const e=K.c(13),{connectionId:s,selections:i,onToggle:r,disabled:o}=t,{org:a}=Pe();let l;e[0]!==s||e[1]!==a.id||e[2]!==a.slug?(l={connectionId:s,orgId:a.id,orgSlug:a.slug},e[0]=s,e[1]=a.id,e[2]=a.slug,e[3]=l):l=e[3];const h=ft(l);let c;e[4]!==h?(c={client:h},e[4]=h,e[5]=c):c=e[5];const{data:d}=Ou(c);let u;e[6]!==d.resources?(u=d.resources.map(vg),e[6]=d.resources,e[7]=u):u=e[7];const f=u;let m;return e[8]!==o||e[9]!==f||e[10]!==r||e[11]!==i?(m=n.jsx(ba,{items:f,selections:i,onToggle:r,emptyMessage:"No resources available",disabled:o}),e[8]=o,e[9]=f,e[10]=r,e[11]=i,e[12]=m):m=e[12],m}function vg(t){return{id:t.name||t.uri,name:t.name||t.uri,description:t.description}}function xg(t){const e=K.c(13),{connectionId:s,selections:i,onToggle:r,disabled:o}=t,{org:a}=Pe();let l;e[0]!==s||e[1]!==a.id||e[2]!==a.slug?(l={connectionId:s,orgId:a.id,orgSlug:a.slug},e[0]=s,e[1]=a.id,e[2]=a.slug,e[3]=l):l=e[3];const h=ft(l);let c;e[4]!==h?(c={client:h},e[4]=h,e[5]=c):c=e[5];const{data:d}=$m(c);let u;e[6]!==d.prompts?(u=d.prompts.map(bg),e[6]=d.prompts,e[7]=u):u=e[7];const f=u;let m;return e[8]!==o||e[9]!==f||e[10]!==r||e[11]!==i?(m=n.jsx(ba,{items:f,selections:i,onToggle:r,emptyMessage:"No prompts available",disabled:o}),e[8]=o,e[9]=f,e[10]=r,e[11]=i,e[12]=m):m=e[12],m}function bg(t){return{id:t.name,name:t.name,description:t.description}}function yg(t){const e=K.c(54),{currentConnection:s,activeTab:i,selectedId:r,formData:o,toggleTool:a,toggleResource:l,togglePrompt:h,toggleAllTools:c,toggleAllResources:d,toggleAllPrompts:u,onTabChange:f}=t,m=o[r],p=i==="tools"?m?.tools===null:i==="resources"?m?.resources===null:m?.prompts===null;let _;e[0]!==i||e[1]!==r||e[2]!==u||e[3]!==d||e[4]!==c?(_=()=>{i==="tools"?c(r):i==="resources"?d(r):u(r)},e[0]=i,e[1]=r,e[2]=u,e[3]=d,e[4]=c,e[5]=_):_=e[5];const g=_;let v;e[6]!==s.icon||e[7]!==s.title?(v=n.jsx(Gt,{icon:s.icon,name:s.title,size:"sm",className:"shrink-0"}),e[6]=s.icon,e[7]=s.title,e[8]=v):v=e[8];let b;e[9]!==s.title?(b=n.jsx("h2",{className:"text-base font-semibold truncate",children:s.title}),e[9]=s.title,e[10]=b):b=e[10];let x;e[11]!==s.description?(x=s.description&&n.jsx("p",{className:"text-xs text-muted-foreground truncate",children:s.description}),e[11]=s.description,e[12]=x):x=e[12];let y;e[13]!==b||e[14]!==x?(y=n.jsxs("div",{className:"flex-1 min-w-0",children:[b,x]}),e[13]=b,e[14]=x,e[15]=y):y=e[15];let w;e[16]!==v||e[17]!==y?(w=n.jsx("div",{className:"px-6 pt-5 pb-4 shrink-0",children:n.jsxs("div",{className:"flex items-center gap-3",children:[v,y]})}),e[16]=v,e[17]=y,e[18]=w):w=e[18];let C;e[19]===Symbol.for("react.memo_cache_sentinel")?(C=[{id:"tools",label:"Tools"},{id:"resources",label:"Resources"},{id:"prompts",label:"Prompts"}],e[19]=C):C=e[19];let j;e[20]!==f?(j=M=>f(M),e[20]=f,e[21]=j):j=e[21];let R;e[22]!==i||e[23]!==j?(R=n.jsx(dh,{tabs:C,activeTab:i,onTabChange:j}),e[22]=i,e[23]=j,e[24]=R):R=e[24];const B=p?"Deselect all":"Select all";let P;e[25]!==g||e[26]!==B?(P=n.jsx("button",{type:"button",onClick:g,className:"text-xs text-muted-foreground hover:text-foreground transition-colors",children:B}),e[25]=g,e[26]=B,e[27]=P):P=e[27];let T;e[28]!==P||e[29]!==R?(T=n.jsxs("div",{className:"flex items-center justify-between px-6 py-3 border-t border-border shrink-0",children:[R,P]}),e[28]=P,e[29]=R,e[30]=T):T=e[30];let S;e[31]!==i||e[32]!==o||e[33]!==r||e[34]!==a?(S=i==="tools"&&n.jsx(Ut,{fallback:gn("Tools not supported by this server"),children:n.jsx(E.Suspense,{fallback:n.jsx(xr,{}),children:n.jsx(pg,{connectionId:r,selections:o[r]?o[r].tools:[],onToggle:(M,D)=>a(r,M,D)})})}),e[31]=i,e[32]=o,e[33]=r,e[34]=a,e[35]=S):S=e[35];let k;e[36]!==i||e[37]!==o||e[38]!==r||e[39]!==l?(k=i==="resources"&&n.jsx(Ut,{fallback:gn("Resources not supported by this server"),children:n.jsx(E.Suspense,{fallback:n.jsx(xr,{}),children:n.jsx(gg,{connectionId:r,selections:o[r]?o[r].resources:[],onToggle:(M,D)=>l(r,M,D)})})}),e[36]=i,e[37]=o,e[38]=r,e[39]=l,e[40]=k):k=e[40];let I;e[41]!==i||e[42]!==o||e[43]!==r||e[44]!==h?(I=i==="prompts"&&n.jsx(Ut,{fallback:gn("Prompts not supported by this server"),children:n.jsx(E.Suspense,{fallback:n.jsx(xr,{}),children:n.jsx(xg,{connectionId:r,selections:o[r]?o[r].prompts:[],onToggle:(M,D)=>h(r,M,D)})})}),e[41]=i,e[42]=o,e[43]=r,e[44]=h,e[45]=I):I=e[45];let N;e[46]!==S||e[47]!==k||e[48]!==I?(N=n.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[S,k,I]}),e[46]=S,e[47]=k,e[48]=I,e[49]=N):N=e[49];let A;return e[50]!==T||e[51]!==N||e[52]!==w?(A=n.jsxs(n.Fragment,{children:[w,T,N]}),e[50]=T,e[51]=N,e[52]=w,e[53]=A):A=e[53],A}function Sg(t){const e=K.c(11),{connectionId:s,onAuthenticate:i,children:r}=t;let o;e[0]!==s?(o={connectionId:s},e[0]=s,e[1]=o):o=e[1];const a=ah(o);if(a.supportsOAuth&&!a.isAuthenticated){let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c=n.jsx("div",{className:"flex items-center justify-center size-12 rounded-full bg-muted",children:n.jsx(Df,{size:22,className:"text-muted-foreground"})}),e[2]=c):c=e[2];let d;e[3]===Symbol.for("react.memo_cache_sentinel")?(d=n.jsxs("div",{className:"space-y-1",children:[n.jsx("p",{className:"text-sm font-medium",children:"Authorization required"}),n.jsx("p",{className:"text-xs text-muted-foreground max-w-xs",children:"This connection needs to be authorized before you can configure its tools and resources."})]}),e[3]=d):d=e[3];let u;e[4]!==s||e[5]!==i?(u=i&&n.jsx(re,{variant:"outline",size:"sm",onClick:()=>i(s),children:"Authorize"}),e[4]=s,e[5]=i,e[6]=u):u=e[6];let f;return e[7]!==u?(f=n.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-4 p-8 text-center",children:[c,d,u]}),e[7]=u,e[8]=f):f=e[8],f}let h;return e[9]!==r?(h=n.jsx(n.Fragment,{children:r}),e[9]=r,e[10]=h):h=e[10],h}function wg(t){const e={};for(const s of t)e[s.connection_id]={tools:s.selected_tools,resources:s.selected_resources??null,prompts:s.selected_prompts??null};return e}function ul(t){return Object.entries(t).map(([e,s])=>({connection_id:e,selected_tools:s.tools,selected_resources:s.resources,selected_prompts:s.prompts}))}function Cg(t,e){return e.type==="SET_ACTIVE_TAB"?{...t,activeTab:e.payload}:t}function kg(t){const e=K.c(49),{open:s,onOpenChange:i,selectedId:r,form:o,connections:a,onAuthenticate:l}=t;let h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h={activeTab:"tools"},e[0]=h):h=e[0];const[c,d]=E.useReducer(Cg,h),u=Go(r??"");let f;e[1]!==a?(f=a??[],e[1]=a,e[2]=f):f=e[2];let m;e[3]!==f?(m=wg(f),e[3]=f,e[4]=m):m=e[4];const p=m;let _;e[5]!==o||e[6]!==p?(_=(F,V,J,Y)=>{const U=p[F]?.[V];let H;U===null?H=Y.filter(oe=>oe!==J):U?.includes(J)?H=U.filter(oe=>oe!==J):(H=[...U??[],J],H.length===Y.length&&(H=null));const X={...p};X[F]?X[F]={...X[F]}:X[F]={tools:null,resources:null,prompts:null},X[F][V]=H,o.setValue("connections",ul(X),{shouldDirty:!0,shouldTouch:!0})},e[5]=o,e[6]=p,e[7]=_):_=e[7];const g=_;let v;e[8]!==o||e[9]!==p?(v=(F,V)=>{const Y=p[F]?.[V]===null?[]:null,U={...p};U[F]?U[F]={...U[F]}:U[F]={tools:null,resources:null,prompts:null},U[F][V]=Y,o.setValue("connections",ul(U),{shouldDirty:!0,shouldTouch:!0})},e[8]=o,e[9]=p,e[10]=v):v=e[10];const b=v;let x;e[11]!==g?(x=(F,V,J)=>g(F,"tools",V,J),e[11]=g,e[12]=x):x=e[12];const y=x;let w;e[13]!==g?(w=(F,V,J)=>g(F,"resources",V,J),e[13]=g,e[14]=w):w=e[14];const C=w;let j;e[15]!==g?(j=(F,V,J)=>g(F,"prompts",V,J),e[15]=g,e[16]=j):j=e[16];const R=j;let B;e[17]!==b?(B=F=>b(F,"tools"),e[17]=b,e[18]=B):B=e[18];const P=B;let T;e[19]!==b?(T=F=>b(F,"resources"),e[19]=b,e[20]=T):T=e[20];const S=T;let k;e[21]!==b?(k=F=>b(F,"prompts"),e[21]=b,e[22]=k):k=e[22];const I=k;if(!r||!u)return null;let N;e[23]===Symbol.for("react.memo_cache_sentinel")?(N=n.jsx(xr,{}),e[23]=N):N=e[23];let A;e[24]===Symbol.for("react.memo_cache_sentinel")?(A=F=>d({type:"SET_ACTIVE_TAB",payload:F}),e[24]=A):A=e[24];let M;e[25]!==u||e[26]!==c.activeTab||e[27]!==p||e[28]!==r||e[29]!==I||e[30]!==S||e[31]!==P||e[32]!==R||e[33]!==C||e[34]!==y?(M=n.jsx(yg,{currentConnection:u,activeTab:c.activeTab,selectedId:r,formData:p,toggleTool:y,toggleResource:C,togglePrompt:R,toggleAllTools:P,toggleAllResources:S,toggleAllPrompts:I,onTabChange:A},r),e[25]=u,e[26]=c.activeTab,e[27]=p,e[28]=r,e[29]=I,e[30]=S,e[31]=P,e[32]=R,e[33]=C,e[34]=y,e[35]=M):M=e[35];let D;e[36]!==l||e[37]!==r||e[38]!==M?(D=n.jsx(E.Suspense,{fallback:N,children:n.jsx(Sg,{connectionId:r,onAuthenticate:l,children:M})}),e[36]=l,e[37]=r,e[38]=M,e[39]=D):D=e[39];let $;e[40]!==i?($=n.jsx(ii,{className:"px-6 py-4 border-t border-border shrink-0",children:n.jsx(re,{variant:"outline",onClick:()=>i(!1),children:"Done"})}),e[40]=i,e[41]=$):$=e[41];let z;e[42]!==D||e[43]!==$?(z=n.jsxs(Ot,{className:"sm:max-w-2xl h-[75vh] max-h-[75vh] flex flex-col p-0 gap-0 overflow-hidden w-[95vw]",children:[D,$]}),e[42]=D,e[43]=$,e[44]=z):z=e[44];let W;return e[45]!==i||e[46]!==s||e[47]!==z?(W=n.jsx(Lt,{open:s,onOpenChange:i,children:z}),e[45]=i,e[46]=s,e[47]=z,e[48]=W):W=e[48],W}const vn={tools:null,resources:null,prompts:null},jg=$u.pick({status:!0,title:!0,description:!0,icon:!0,metadata:!0,connections:!0});function Ng(t){const s=new TextEncoder().encode(t),i=Array.from(s,r=>String.fromCharCode(r)).join("");return btoa(i)}function Eg(t){const e=K.c(11),{url:s,agentId:i}=t,[r,o]=E.useState(!1);let a;e[0]!==i||e[1]!==s?(a=async()=>{De("agent_connect_action",{agent_id:i,action:"copy_url"}),await navigator.clipboard.writeText(s),o(!0),le.success("Agent URL copied to clipboard"),setTimeout(()=>o(!1),2e3)},e[0]=i,e[1]=s,e[2]=a):a=e[2];const l=a;let h;e[3]!==r?(h=r?n.jsx(ri,{size:20,className:"text-green-600"}):n.jsx(Qt,{size:20}),e[3]=r,e[4]=h):h=e[4];const c=r?"Copied!":"Copy URL";let d;e[5]!==c?(d=n.jsx("span",{className:"text-xs font-medium",children:c}),e[5]=c,e[6]=d):d=e[6];let u;return e[7]!==l||e[8]!==h||e[9]!==d?(u=n.jsxs(re,{type:"button",variant:"outline",onClick:l,className:"h-auto py-3 px-4 flex flex-col items-center gap-2",children:[h,d]}),e[7]=l,e[8]=h,e[9]=d,e[10]=u):u=e[10],u}function Tg(t){const e=K.c(8),{url:s,serverName:i,agentId:r}=t;let o;e[0]!==r||e[1]!==i||e[2]!==s?(o=()=>{De("agent_connect_action",{agent_id:r,action:"install_cursor"});const d=lh(i),f=Ng(JSON.stringify({type:"http",url:s,headers:{"x-mesh-client":"Cursor"}},null,2)),m=`cursor://anysphere.cursor-deeplink/mcp/install?name=${encodeURIComponent(d)}&config=${encodeURIComponent(f)}`;window.open(m,"_blank"),le.success("Opening Cursor...")},e[0]=r,e[1]=i,e[2]=s,e[3]=o):o=e[3];const a=o;let l,h;e[4]===Symbol.for("react.memo_cache_sentinel")?(l=n.jsx("img",{src:"/logos/cursor.svg",alt:"Cursor",className:"h-5 w-5",style:{filter:"brightness(0) saturate(100%) invert(11%) sepia(8%) saturate(785%) hue-rotate(1deg) brightness(95%) contrast(89%)"}}),h=n.jsx("span",{className:"text-xs font-medium",children:"Install on Cursor"}),e[4]=l,e[5]=h):(l=e[4],h=e[5]);let c;return e[6]!==a?(c=n.jsxs(re,{type:"button",variant:"outline",onClick:a,className:"h-auto py-3 px-4 flex flex-col items-center gap-2",children:[l,h]}),e[6]=a,e[7]=c):c=e[7],c}function Rg(t){const e=K.c(12),{url:s,serverName:i,agentId:r}=t,[o,a]=E.useState(!1);let l;e[0]!==r||e[1]!==i||e[2]!==s?(l=async()=>{De("agent_connect_action",{agent_id:r,action:"install_claude_code"});const m=lh(i),_=JSON.stringify({type:"http",url:s,headers:{"x-mesh-client":"Claude Code"}},null,2),g=`claude mcp add-json "${m}" '${_.replace(/'/g,"'\\''")}' --scope user`;await navigator.clipboard.writeText(g),a(!0),le.success("Claude Code command copied to clipboard"),setTimeout(()=>a(!1),2e3)},e[0]=r,e[1]=i,e[2]=s,e[3]=l):l=e[3];const h=l;let c;e[4]!==o?(c=o?n.jsx(ri,{size:20,className:"text-green-600"}):n.jsx("img",{src:"/logos/Claude Code.svg",alt:"Claude Code",className:"h-5 w-5",style:{filter:"brightness(0) saturate(100%) invert(55%) sepia(31%) saturate(1264%) hue-rotate(331deg) brightness(92%) contrast(86%)"}}),e[4]=o,e[5]=c):c=e[5];const d=o?"Copied!":"Install on Claude Code";let u;e[6]!==d?(u=n.jsx("span",{className:"text-xs font-medium",children:d}),e[6]=d,e[7]=u):u=e[7];let f;return e[8]!==h||e[9]!==c||e[10]!==u?(f=n.jsxs(re,{type:"button",variant:"outline",onClick:h,className:"h-auto py-3 px-4 flex flex-col items-center gap-2",children:[c,u]}),e[8]=h,e[9]=c,e[10]=u,e[11]=f):f=e[11],f}function Pg({virtualMcp:t}){const e=qi(),[s,i]=E.useState(null),[r,o]=E.useState(!1),[a,l]=E.useState(!1),h=t.id,c=t.title||`agent-${h.slice(0,8)}`,d=s?`bunx @decocms/typegen@latest --mcp ${h} --key ${s} --output client.ts`:`bunx @decocms/typegen@latest --mcp ${h} --key <api-key> --output client.ts`,u=async()=>{o(!0);try{const{key:m}=await e.call("API_KEY_CREATE",{name:`typegen-${c}`,permissions:{[h]:["*"]}});if(!m)throw new Error("No key in response");i(m),De("agent_typegen_key_generated",{agent_id:h})}catch{De("agent_typegen_key_failed",{agent_id:h}),le.error("Failed to generate API key")}finally{o(!1)}},f=async()=>{De("agent_connect_action",{agent_id:h,action:"typegen_copy_command",has_api_key:!!s}),await navigator.clipboard.writeText(d),l(!0),le.success("Command copied to clipboard"),setTimeout(()=>l(!1),2e3)};return n.jsxs("div",{className:"flex min-w-0 flex-col gap-3",children:[n.jsxs("div",{className:"flex items-start justify-between gap-3",children:[n.jsxs("div",{className:"flex flex-col gap-0.5",children:[n.jsx("h4",{className:"text-sm font-medium text-foreground",children:"Generate typed client"}),n.jsxs("p",{className:"text-xs text-muted-foreground",children:["Introspects this agent and writes a typed"," ",n.jsx("code",{className:"font-mono",children:"client.ts"})," you can import directly."]})]}),!s&&n.jsxs(re,{type:"button",variant:"outline",size:"sm",className:"shrink-0 gap-1.5",onClick:u,disabled:r,children:[r?n.jsx(Ce,{size:14,className:"animate-spin"}):n.jsx(ea,{size:14}),n.jsx("span",{children:r?"Generating…":"Generate API key"})]})]}),s&&n.jsx("p",{className:"rounded-md border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-700",children:"Store this key securely — it won't be shown again."}),n.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"Generate client"}),n.jsx("div",{className:"rounded-md border border-input bg-muted/50 px-3 py-2.5",children:n.jsxs("div",{className:"flex items-start gap-2",children:[n.jsx("code",{className:"min-w-0 flex-1 break-all font-mono text-xs text-muted-foreground",children:d}),n.jsx(re,{type:"button",variant:"ghost",size:"icon",className:"size-6 shrink-0",onClick:f,children:a?n.jsx(ri,{size:12,className:"text-green-600"}):n.jsx(Qt,{size:12})})]})}),n.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"Runtime variables"}),n.jsx(Dg,{apiKey:s,agentId:h})]})}function Dg(t){const e=K.c(21),{apiKey:s,agentId:i}=t,[r,o]=E.useState(!1),a=window.location.origin,l=s?`MESH_API_KEY=${s}`:"MESH_API_KEY=<api-key>",h=`MESH_BASE_URL=${a}`,c=`${l}
|
|
9
9
|
${h}`;let d;e[0]!==i||e[1]!==s||e[2]!==c?(d=async()=>{De("agent_connect_action",{agent_id:i,action:"typegen_copy_env",has_api_key:!!s}),await navigator.clipboard.writeText(c),o(!0),setTimeout(()=>o(!1),2e3)},e[0]=i,e[1]=s,e[2]=c,e[3]=d):d=e[3];const u=d,f=!s;let m;e[4]!==f?(m=he({"opacity-50":f}),e[4]=f,e[5]=m):m=e[5];let p;e[6]!==l||e[7]!==m?(p=n.jsx("span",{className:m,children:l}),e[6]=l,e[7]=m,e[8]=p):p=e[8];let _,g;e[9]===Symbol.for("react.memo_cache_sentinel")?(_=n.jsx("br",{}),g=n.jsx("span",{children:h}),e[9]=_,e[10]=g):(_=e[9],g=e[10]);let v;e[11]!==p?(v=n.jsxs("code",{className:"min-w-0 flex-1 font-mono text-xs text-muted-foreground",children:[p,_,g]}),e[11]=p,e[12]=v):v=e[12];let b;e[13]!==r?(b=r?n.jsx(ri,{size:12,className:"text-green-600"}):n.jsx(Qt,{size:12}),e[13]=r,e[14]=b):b=e[14];let x;e[15]!==u||e[16]!==b?(x=n.jsx(re,{type:"button",variant:"ghost",size:"icon",className:"size-6 shrink-0",onClick:u,children:b}),e[15]=u,e[16]=b,e[17]=x):x=e[17];let y;return e[18]!==v||e[19]!==x?(y=n.jsx("div",{className:"rounded-md border border-input bg-muted/50 px-3 py-2.5",children:n.jsxs("div",{className:"flex items-start gap-2",children:[v,x]})}),e[18]=v,e[19]=x,e[20]=y):y=e[20],y}function Ag(t){const e=K.c(3),{virtualMcp:s}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=n.jsx("div",{className:"h-20 animate-pulse rounded-md bg-muted"}),e[0]=i):i=e[0];let r;return e[1]!==s?(r=n.jsx(E.Suspense,{fallback:i,children:n.jsx(Pg,{virtualMcp:s})}),e[1]=s,e[2]=r):r=e[2],r}const Ig={self:["COLLECTION_THREADS_CREATE","COLLECTION_THREADS_GET","COLLECTION_THREAD_MESSAGES_LIST","COLLECTION_THREADS_LIST"]},Bg=3600*24*90;function Mg({virtualMcp:t}){const e=qi(),{org:s}=Pe(),[i,r]=E.useState(null),[o,a]=E.useState(!1),[l,h]=E.useState(!1),c=t.id,d=t.title||`agent-${c.slice(0,8)}`,f=[`MESH_BASE_URL=${window.location.origin}`,`MESH_ORG=${s.slug}`,`MESH_AGENT_ID=${c}`,`MESH_API_KEY=${i??"<api-key>"}`].join(`
|
|
10
|
-
`),m=async()=>{a(!0);try{const{key:_}=await e.call("API_KEY_CREATE",{name:`chat-bridge-${d}`,permissions:Ig,expiresIn:Bg});if(!_)throw new Error("No key in response");r(_),De("agent_chat_bridge_key_generated",{agent_id:c})}catch{De("agent_chat_bridge_key_failed",{agent_id:c}),le.error("Failed to create API key")}finally{a(!1)}},p=async()=>{De("agent_connect_action",{agent_id:c,action:"chat_bridge_copy_env",has_api_key:!!i}),await navigator.clipboard.writeText(f),h(!0),le.success("Connection details copied to clipboard"),setTimeout(()=>h(!1),2e3)};return n.jsxs("div",{className:"flex min-w-0 flex-col gap-3",children:[n.jsxs("div",{className:"flex items-start justify-between gap-3",children:[n.jsxs("div",{className:"flex flex-col gap-0.5",children:[n.jsx("h4",{className:"text-sm font-medium text-foreground",children:"Call from your app"}),n.jsx("p",{className:"text-xs text-muted-foreground",children:"Create a scoped API key to start a thread, run this agent, and stream results from an external system (e.g. a chatbot webhook)."})]}),!i&&n.jsxs(re,{type:"button",variant:"outline",size:"sm",className:"shrink-0 gap-1.5",onClick:m,disabled:o,children:[o?n.jsx(Ce,{size:14,className:"animate-spin"}):n.jsx(ea,{size:14}),n.jsx("span",{children:o?"Creating…":"Create API key"})]})]}),i&&n.jsx("p",{className:"rounded-md border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-700",children:"Store this key securely — it won't be shown again."}),n.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"Connection details"}),n.jsx("div",{className:"rounded-md border border-input bg-muted/50 px-3 py-2.5",children:n.jsxs("div",{className:"flex items-start gap-2",children:[n.jsx("code",{className:"min-w-0 flex-1 whitespace-pre-wrap break-all font-mono text-xs text-muted-foreground",children:f}),n.jsx(re,{type:"button",variant:"ghost",size:"icon",className:"size-6 shrink-0",onClick:p,children:l?n.jsx(ri,{size:12,className:"text-green-600"}):n.jsx(Qt,{size:12})})]})})]})}function Lg(t){const e=K.c(3),{virtualMcp:s}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=n.jsx("div",{className:"h-20 animate-pulse rounded-md bg-muted"}),e[0]=i):i=e[0];let r;return e[1]!==s?(r=n.jsx(E.Suspense,{fallback:i,children:n.jsx(Mg,{virtualMcp:s})}),e[1]=s,e[2]=r):r=e[2],r}function Og(t){const e=K.c(41),{open:s,onOpenChange:i,virtualMcp:r}=t,{org:o}=Pe(),a=`/api/${o.slug}/mcp/virtual-mcp/${r.id}`;let l;e[0]!==a?(l=new URL(a,window.location.origin),e[0]=a,e[1]=l):l=e[1];const h=l;let c;e[2]!==r.id||e[3]!==r.title?(c=r.title||`agent-${r.id?.slice(0,8)??"default"}`,e[2]=r.id,e[3]=r.title,e[4]=c):c=e[4];const d=c,u=Wc();let f;e[5]!==r.id||e[6]!==h.href?(f=n.jsx(Eg,{url:h.href,agentId:r.id}),e[5]=r.id,e[6]=h.href,e[7]=f):f=e[7];let m,p;e[8]!==d||e[9]!==r.id||e[10]!==h.href?(m=n.jsx(Tg,{url:h.href,serverName:d,agentId:r.id}),p=n.jsx(Rg,{url:h.href,serverName:d,agentId:r.id}),e[8]=d,e[9]=r.id,e[10]=h.href,e[11]=m,e[12]=p):(m=e[11],p=e[12]);let _;e[13]!==f||e[14]!==m||e[15]!==p?(_=n.jsx("div",{className:"flex flex-col gap-3 pt-2",children:n.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[f,m,p]})}),e[13]=f,e[14]=m,e[15]=p,e[16]=_):_=e[16];let g;e[17]===Symbol.for("react.memo_cache_sentinel")?(g=n.jsx("div",{className:"border-t border-border"}),e[17]=g):g=e[17];let v;e[18]!==r?(v=n.jsx(Ag,{virtualMcp:r}),e[18]=r,e[19]=v):v=e[19];let b;e[20]===Symbol.for("react.memo_cache_sentinel")?(b=n.jsx("div",{className:"border-t border-border"}),e[20]=b):b=e[20];let x;e[21]!==r?(x=n.jsx(Lg,{virtualMcp:r}),e[21]=r,e[22]=x):x=e[22];let y;e[23]!==x||e[24]!==_||e[25]!==v?(y=n.jsxs("div",{className:"flex flex-col gap-6",children:[_,g,v,b,x]}),e[23]=x,e[24]=_,e[25]=v,e[26]=y):y=e[26];const w=y;if(u){let B;e[27]===Symbol.for("react.memo_cache_sentinel")?(B=n.jsx(zm,{className:"mt-4 mb-4 text-base font-semibold",children:"Connect"}),e[27]=B):B=e[27];let P;e[28]!==w?(P=n.jsx(Fm,{children:n.jsxs("div",{className:"flex-1 overflow-y-auto px-4 pb-6 [touch-action:pan-y]",children:[B,w]})}),e[28]=w,e[29]=P):P=e[29];let T;return e[30]!==i||e[31]!==s||e[32]!==P?(T=n.jsx(Hm,{open:s,onOpenChange:i,children:P}),e[30]=i,e[31]=s,e[32]=P,e[33]=T):T=e[33],T}let C;e[34]===Symbol.for("react.memo_cache_sentinel")?(C=n.jsx(is,{children:n.jsx(rs,{children:"Connect"})}),e[34]=C):C=e[34];let j;e[35]!==w?(j=n.jsxs(Ot,{className:"max-h-[80vh] overflow-y-auto sm:max-w-2xl",children:[C,w]}),e[35]=w,e[36]=j):j=e[36];let R;return e[37]!==i||e[38]!==s||e[39]!==j?(R=n.jsx(Lt,{open:s,onOpenChange:i,children:j}),e[37]=i,e[38]=s,e[39]=j,e[40]=R):R=e[40],R}const $g=/^[A-Za-z_][A-Za-z0-9_]*$/;function zg(t){const e={},s=t.split(/\r?\n/);for(let i=0;i<s.length;i++){let r=(s[i]??"").trim();if(!r||r.startsWith("#"))continue;r.startsWith("export ")&&(r=r.slice(7).trim());const o=r.indexOf("=");if(o<0)throw new Error(`Line ${i+1}: missing '='`);const a=r.slice(0,o).trim();if(!$g.test(a))throw new Error(`Line ${i+1}: invalid key "${a}"`);let l=r.slice(o+1).trim();l.length>=2&&(l.startsWith('"')&&l.endsWith('"')||l.startsWith("'")&&l.endsWith("'"))&&(l=l.slice(1,-1)),e[a]=l}return e}const Fg=/^[A-Za-z0-9_.-]+$/;function Hg(t){const e=K.c(14),{control:s,form:i,virtualMcpId:r,orgSlug:o}=t;let a,l;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=n.jsx("div",{className:"flex items-baseline justify-between gap-2",children:n.jsx(jt,{className:"font-normal text-foreground",children:"Environment variables"})}),l=n.jsx("p",{className:"text-xs text-muted-foreground",children:"Injected into the sandbox on every start. Reference an org/user secret to keep values out of metadata; literals are stored inline."}),e[0]=a,e[1]=l):(a=e[0],l=e[1]);let h;e[2]!==s||e[3]!==i||e[4]!==o||e[5]!==r?(h=n.jsx(Ug,{control:s,form:i,virtualMcpId:r,orgSlug:o}),e[2]=s,e[3]=i,e[4]=o,e[5]=r,e[6]=h):h=e[6];let c;e[7]===Symbol.for("react.memo_cache_sentinel")?(c=n.jsx(uh,{className:"h-9 w-full"}),e[7]=c):c=e[7];let d;e[8]!==s||e[9]!==i?(d=n.jsx(Ut,{fallback:Wg,children:n.jsx(E.Suspense,{fallback:c,children:n.jsx(Vg,{control:s,form:i})})}),e[8]=s,e[9]=i,e[10]=d):d=e[10];let u;return e[11]!==h||e[12]!==d?(u=n.jsxs("div",{className:"space-y-2",children:[a,l,h,d]}),e[11]=h,e[12]=d,e[13]=u):u=e[13],u}function Wg(t){const{error:e}=t;return n.jsx("div",{className:"rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2 text-xs text-destructive",children:e?.message??"Failed to load secrets"})}function Ug(t){const e=K.c(24),{control:s,form:i,virtualMcpId:r,orgSlug:o}=t,l=Js.useSession().data?.user?.id,h="metadata.runtime.env",c="metadata.sandboxMap";let d;e[0]!==i?(d=()=>JSON.stringify(fl(i.getValues(h))),e[0]=i,e[1]=d):d=e[1];const[u,f]=E.useState(d);let m;e[2]!==s?(m={control:s,name:h},e[2]=s,e[3]=m):m=e[3];const p=Bc(m);let _;e[4]!==p?(_=JSON.stringify(fl(p)),e[4]=p,e[5]=_):_=e[5];const g=_,v=g!==u;let b;e[6]!==i?(b=i.getValues(c),e[6]=i,e[7]=b):b=e[7];const x=b;let y;e[8]!==x||e[9]!==l?(y=l?Object.keys(x?.[l]??{}):[],e[8]=x,e[9]=l,e[10]=y):y=e[10];const w=y,C=w.length>0,[j,R]=E.useState(!1);if(!v||!C)return null;let B;e[11]!==g||e[12]!==o||e[13]!==w||e[14]!==r?(B=async()=>{R(!0);const N=await Promise.allSettled(w.map(async M=>{const D=`/api/${encodeURIComponent(o)}/sandbox/${encodeURIComponent(r)}/${encodeURIComponent(M)}/setup/start`,$=await fetch(D,{method:"POST"});if(!$.ok){const z=await $.text().catch(()=>$.statusText);throw new Error(z||$.statusText)}}));R(!1);const A=N.filter(Kg).length;A===0?(f(g),le.success(w.length===1?"Restarted dev with new env":`Restarted ${w.length} branches with new env`)):le.error(`Failed to restart ${A} of ${w.length} branch(es)`)},e[11]=g,e[12]=o,e[13]=w,e[14]=r,e[15]=B):B=e[15];const P=B;let T;e[16]===Symbol.for("react.memo_cache_sentinel")?(T=n.jsxs("div",{className:"flex min-w-0 items-center gap-2 text-amber-900 dark:text-amber-200",children:[n.jsx(Ic,{className:"size-3.5 shrink-0"}),n.jsx("span",{className:"truncate",children:"Your sandbox is running. Restart the dev script to apply the new env."})]}),e[16]=T):T=e[16];let S;e[17]!==j?(S=j?n.jsx(Ce,{className:"size-3.5 animate-spin"}):n.jsx(Bi,{className:"size-3.5"}),e[17]=j,e[18]=S):S=e[18];const k=j?"Restarting…":"Restart dev";let I;return e[19]!==P||e[20]!==j||e[21]!==S||e[22]!==k?(I=n.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border border-amber-200 bg-amber-50 px-3 py-2 text-xs dark:border-amber-900/40 dark:bg-amber-950/30",children:[T,n.jsxs(re,{type:"button",variant:"outline",size:"sm",onClick:P,disabled:j,className:"shrink-0",children:[S,k]})]}),e[19]=P,e[20]=j,e[21]=S,e[22]=k,e[23]=I):I=e[23],I}function Kg(t){return t.status==="rejected"}function Vg(t){const e=K.c(48),{control:s,form:i}=t,r="metadata.runtime.env";let o;e[0]!==s?(o={control:s,name:r},e[0]=s,e[1]=o):o=e[1];const a=zu(o),{fields:l,append:h,remove:c}=a;let d;e[2]!==i?(d=(N,A)=>{i.setValue(`${r}.${N}`,A,{shouldDirty:!0,shouldTouch:!0})},e[2]=i,e[3]=d):d=e[3];const u=d,f=Um();let m;if(e[4]!==f){m=new Map;for(const N of f)m.set(N.id,N);e[4]=f,e[5]=m}else m=e[5];const[p,_]=E.useState(null);let g;e[6]!==h?(g=()=>{h({key:"",kind:"literal",value:""})},e[6]=h,e[7]=g):g=e[7];const v=g;let b;e[8]!==h||e[9]!==i?(b=async()=>{let N;try{N=await navigator.clipboard.readText()}catch{le.error("Couldn't read clipboard");return}if(!N.trim()){le.error("Clipboard is empty");return}let A;try{A=zg(N)}catch(F){const V=F;le.error(V.message);return}const M=Object.entries(A);if(M.length===0){le.error("Nothing to add");return}const D=i.getValues(r)??[],$=new Set;for(const F of D){const V=(F.key??"").trim();V&&$.add(V)}let z=0,W=0;for(const[F,V]of M){if($.has(F)){W++;continue}h({key:F,kind:"literal",value:V}),$.add(F),z++}z===0&&W>0?le.message(`All ${W} key${W===1?"":"s"} already exist`):le.success(W>0?`Added ${z} var${z===1?"":"s"} (${W} already existed)`:`Added ${z} var${z===1?"":"s"}`)},e[8]=h,e[9]=i,e[10]=b):b=e[10];const x=b;let y;if(e[11]!==s||e[12]!==l||e[13]!==i||e[14]!==c||e[15]!==m||e[16]!==f||e[17]!==u){let N;e[19]!==s||e[20]!==i||e[21]!==c||e[22]!==m||e[23]!==f||e[24]!==u?(N=(A,M)=>n.jsx("li",{className:"rounded-md border border-border bg-background",children:n.jsx(qg,{index:M,control:s,form:i,onUpdateEntry:u,fieldPath:r,secrets:f,secretById:m,onSaveAsSecret:(D,$)=>_({kind:"save-literal",index:M,presetKey:D,presetValue:$}),onCreateNewSecret:D=>_({kind:"create-new",index:M,presetKey:D}),onRemove:()=>c(M)})},A.id),e[19]=s,e[20]=i,e[21]=c,e[22]=m,e[23]=f,e[24]=u,e[25]=N):N=e[25],y=l.map(N),e[11]=s,e[12]=l,e[13]=i,e[14]=c,e[15]=m,e[16]=f,e[17]=u,e[18]=y}else y=e[18];let w;e[26]!==y?(w=n.jsx("ul",{className:"space-y-2",children:y}),e[26]=y,e[27]=w):w=e[27];let C;e[28]===Symbol.for("react.memo_cache_sentinel")?(C=n.jsx(xt,{className:"size-3.5"}),e[28]=C):C=e[28];let j;e[29]!==v?(j=n.jsxs(re,{type:"button",variant:"outline",size:"sm",onClick:v,className:"flex-1",children:[C,"Add env var"]}),e[29]=v,e[30]=j):j=e[30];let R;e[31]===Symbol.for("react.memo_cache_sentinel")?(R=n.jsx(Df,{className:"size-3.5"}),e[31]=R):R=e[31];let B;e[32]!==x?(B=n.jsx(Ee,{asChild:!0,children:n.jsxs(re,{type:"button",variant:"outline",size:"sm",onClick:x,"aria-label":"Paste .env",children:[R,"Paste .env"]})}),e[32]=x,e[33]=B):B=e[33];let P;e[34]===Symbol.for("react.memo_cache_sentinel")?(P=n.jsx(Te,{children:"Read a .env blob from the clipboard. Each pair is staged as a literal — save individual rows as secrets after."}),e[34]=P):P=e[34];let T;e[35]!==B?(T=n.jsxs(Re,{children:[B,P]}),e[35]=B,e[36]=T):T=e[36];let S;e[37]!==T||e[38]!==j?(S=n.jsxs("div",{className:"flex items-center gap-2",children:[j,T]}),e[37]=T,e[38]=j,e[39]=S):S=e[39];let k;e[40]!==p||e[41]!==i||e[42]!==u?(k=p!==null?n.jsx(Xg,{mode:p,onClose:()=>_(null),onSaved:N=>{const A=i.getValues(`${r}.${p.index}.key`)?.trim()??"";u(p.index,{key:A,kind:"secret",secretId:N}),_(null)}}):null,e[40]=p,e[41]=i,e[42]=u,e[43]=k):k=e[43];let I;return e[44]!==S||e[45]!==k||e[46]!==w?(I=n.jsxs("div",{className:"space-y-2",children:[w,S,k]}),e[44]=S,e[45]=k,e[46]=w,e[47]=I):I=e[47],I}function qg(t){const e=K.c(55),{index:s,control:i,form:r,onUpdateEntry:o,fieldPath:a,secrets:l,secretById:h,onSaveAsSecret:c,onCreateNewSecret:d,onRemove:u}=t,f=`${a}.${s}.key`,m=`${a}.${s}.value`,p=`${a}.${s}.secretId`,_=`${a}.${s}.kind`;let g;e[0]!==i||e[1]!==_?(g={control:i,name:_},e[0]=i,e[1]=_,e[2]=g):g=e[2];const b=Bc(g)==="secret"?"secret":"literal";let x;e[3]!==r||e[4]!==s||e[5]!==f||e[6]!==c||e[7]!==o||e[8]!==m?(x=z=>{const W=r.getValues(f)?.trim()??"";if(z==="literal"){o(s,{key:W,kind:"literal",value:""});return}const F=r.getValues(m)??"";if(F.length>0){c(W,F);return}o(s,{key:W,kind:"secret",secretId:""})},e[3]=r,e[4]=s,e[5]=f,e[6]=c,e[7]=o,e[8]=m,e[9]=x):x=e[9];const y=x;let w;e[10]!==s?(w=z=>{const{field:W}=z,F=(W.value??"").trim(),V=F.length>0&&!Xr.test(F);return n.jsxs("div",{className:"space-y-1",children:[n.jsx(qe,{...W,value:W.value??"",placeholder:"KEY",spellCheck:!1,autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",className:he("font-mono",V&&"border-destructive focus-visible:ring-destructive"),"aria-invalid":V,"aria-label":`Env var ${s+1} key`,onBlur:J=>{const Y=J.target.value.trim();W.onChange(Y),W.onBlur()}}),V?n.jsx("p",{className:"text-[11px] text-destructive",children:"Letters, digits, underscores. Must start with a letter or underscore."}):null]})},e[10]=s,e[11]=w):w=e[11];let C;e[12]!==i||e[13]!==f||e[14]!==w?(C=n.jsx("div",{className:"flex-1 min-w-0",children:n.jsx(vt,{control:i,name:f,render:w})}),e[12]=i,e[13]=f,e[14]=w,e[15]=C):C=e[15];let j;e[16]!==y?(j=z=>y(z),e[16]=y,e[17]=j):j=e[17];let R;e[18]===Symbol.for("react.memo_cache_sentinel")?(R=n.jsx(Pt,{className:"h-9 w-[110px]",children:n.jsx(Dt,{})}),e[18]=R):R=e[18];let B;e[19]===Symbol.for("react.memo_cache_sentinel")?(B=n.jsx(ot,{value:"literal",children:n.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[n.jsx(ea,{className:"size-3.5"}),"Literal"]})}),e[19]=B):B=e[19];let P;e[20]===Symbol.for("react.memo_cache_sentinel")?(P=n.jsxs(At,{children:[B,n.jsx(ot,{value:"secret",children:n.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[n.jsx(Fu,{className:"size-3.5"}),"Secret"]})})]}),e[20]=P):P=e[20];let T;e[21]!==b||e[22]!==j?(T=n.jsx("div",{className:"shrink-0",children:n.jsxs(It,{value:b,onValueChange:j,children:[R,P]})}),e[21]=b,e[22]=j,e[23]=T):T=e[23];let S;e[24]!==i||e[25]!==r||e[26]!==s||e[27]!==f||e[28]!==b||e[29]!==d||e[30]!==h||e[31]!==p||e[32]!==l||e[33]!==m?(S=n.jsx("div",{className:"flex flex-[2] min-w-0 items-center gap-1",children:b==="literal"?n.jsx(vt,{control:i,name:m,render:z=>{const{field:W}=z;return n.jsx(qe,{...W,value:W.value??"",type:"password",placeholder:"value",spellCheck:!1,autoComplete:"off",className:"font-mono","aria-label":`Env var ${s+1} value`,onBlur:F=>{W.onChange(F.target.value),W.onBlur()}})}}):n.jsxs(n.Fragment,{children:[n.jsx(vt,{control:i,name:p,render:z=>{const{field:W}=z;return n.jsxs(It,{value:W.value||"",onValueChange:F=>W.onChange(F),children:[n.jsx(Pt,{className:he("h-9 w-full",!W.value&&"text-muted-foreground"),children:n.jsx(Dt,{placeholder:"Pick a secret…",children:n.jsx(Yg,{field:W,secretById:h})})}),n.jsx(At,{children:l.length===0?n.jsx("div",{className:"px-2 py-2 text-xs text-muted-foreground",children:"No secrets yet. Use the “+” to create one."}):l.map(Gg)})]})}}),n.jsxs(Re,{children:[n.jsx(Ee,{asChild:!0,children:n.jsx(re,{type:"button",variant:"ghost",size:"icon","aria-label":"Create new secret",onClick:()=>{const z=r.getValues(f)?.trim()??"";d(z)},children:n.jsx(xt,{className:"size-3.5"})})}),n.jsx(Te,{children:"Create new secret"})]})]})}),e[24]=i,e[25]=r,e[26]=s,e[27]=f,e[28]=b,e[29]=d,e[30]=h,e[31]=p,e[32]=l,e[33]=m,e[34]=S):S=e[34];let k;e[35]!==r||e[36]!==f||e[37]!==b||e[38]!==c||e[39]!==m?(k=b==="literal"?n.jsxs(Re,{children:[n.jsx(Ee,{asChild:!0,children:n.jsx(re,{type:"button",variant:"ghost",size:"icon","aria-label":"Save value as secret",onClick:()=>{const z=r.getValues(f)?.trim()??"",W=r.getValues(m)??"";c(z,W)},children:n.jsx(Af,{className:"size-3.5"})})}),n.jsx(Te,{children:"Save value as secret"})]}):null,e[35]=r,e[36]=f,e[37]=b,e[38]=c,e[39]=m,e[40]=k):k=e[40];let I;e[41]===Symbol.for("react.memo_cache_sentinel")?(I=n.jsx(qs,{className:"size-3.5"}),e[41]=I):I=e[41];let N;e[42]!==u?(N=n.jsx(Ee,{asChild:!0,children:n.jsx(re,{type:"button",variant:"ghost",size:"icon","aria-label":"Remove env var",onClick:u,children:I})}),e[42]=u,e[43]=N):N=e[43];let A;e[44]===Symbol.for("react.memo_cache_sentinel")?(A=n.jsx(Te,{children:"Remove"}),e[44]=A):A=e[44];let M;e[45]!==N?(M=n.jsxs(Re,{children:[N,A]}),e[45]=N,e[46]=M):M=e[46];let D;e[47]!==k||e[48]!==M?(D=n.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[k,M]}),e[47]=k,e[48]=M,e[49]=D):D=e[49];let $;return e[50]!==S||e[51]!==D||e[52]!==C||e[53]!==T?($=n.jsxs("div",{className:"flex flex-col gap-2 p-2 sm:flex-row sm:items-center",children:[C,T,S,D]}),e[50]=S,e[51]=D,e[52]=C,e[53]=T,e[54]=$):$=e[54],$}function Gg(t){return n.jsx(ot,{value:t.id,children:n.jsxs("span",{className:"inline-flex items-center gap-2",children:[n.jsx(Kh,{scope:t.scope}),n.jsx("span",{className:"font-mono",children:t.name})]})},t.id)}function Yg(t){const e=K.c(12),{field:s,secretById:i}=t,r=s.value||"";if(!r)return null;let o;e[0]!==r||e[1]!==i?(o=i.get(r),e[0]=r,e[1]=i,e[2]=o):o=e[2];const a=o;if(!a){let d;return e[3]!==r?(d=n.jsxs("span",{className:"text-destructive",children:["Missing secret (",r,")"]}),e[3]=r,e[4]=d):d=e[4],d}let l;e[5]!==a.scope?(l=n.jsx(Kh,{scope:a.scope}),e[5]=a.scope,e[6]=l):l=e[6];let h;e[7]!==a.name?(h=n.jsx("span",{className:"truncate font-mono",children:a.name}),e[7]=a.name,e[8]=h):h=e[8];let c;return e[9]!==l||e[10]!==h?(c=n.jsxs("span",{className:"inline-flex items-center gap-1.5 truncate",children:[l,h]}),e[9]=l,e[10]=h,e[11]=c):c=e[11],c}function Kh(t){const e=K.c(2),{scope:s}=t,i=s==="user"?Wm:ta;let r;return e[0]!==i?(r=n.jsx(i,{className:"size-3 text-muted-foreground"}),e[0]=i,e[1]=r):r=e[1],r}function Xg({mode:t,onClose:e,onSaved:s}){const i=t.kind==="save-literal"?t.presetValue:"",r=t.presetKey,[o,a]=E.useState(()=>Jg(r)),[l,h]=E.useState("organization"),[c,d]=E.useState(i),[u,f]=E.useState(""),m=Km(),p=o.trim(),_=c.length>0&&p.length>0&&Fg.test(p),g=async x=>{if(x.preventDefault(),!!_)try{const y=await m.mutateAsync({scope:l,name:p,value:c,description:u.trim()||void 0});le.success(`Saved secret "${y.name}"`),s(y.id)}catch(y){le.error(y instanceof Error?y.message:"Failed to save")}},v=t.kind==="save-literal"?"Save value as secret":"Create new secret",b=t.kind==="save-literal"?"Move this value into the encrypted vault. The env var will then reference the secret by id — its value never leaves the server.":"Stored encrypted in the credential vault. The env var will reference the new secret by id.";return n.jsx(Lt,{open:!0,onOpenChange:x=>{x||e()},children:n.jsxs(Ot,{className:"sm:max-w-md",children:[n.jsxs(is,{children:[n.jsx(rs,{children:v}),n.jsx(Jo,{children:b})]}),n.jsxs("form",{onSubmit:g,className:"space-y-4",children:[n.jsxs("div",{className:"space-y-1.5",children:[n.jsx(jt,{htmlFor:"save-secret-scope",children:"Scope"}),n.jsxs(It,{value:l,onValueChange:x=>h(x),children:[n.jsx(Pt,{id:"save-secret-scope",children:n.jsx(Dt,{})}),n.jsxs(At,{children:[n.jsx(ot,{value:"organization",children:"Organization — visible to all members"}),n.jsx(ot,{value:"user",children:"Private — only visible to me"})]})]})]}),n.jsxs("div",{className:"space-y-1.5",children:[n.jsx(jt,{htmlFor:"save-secret-name",children:"Name"}),n.jsx(qe,{id:"save-secret-name",value:o,onChange:x=>a(x.target.value),placeholder:"STRIPE_API_KEY",autoComplete:"off",required:!0}),n.jsx("p",{className:"text-xs text-muted-foreground",children:"Letters, digits, underscore, dot, hyphen. Independent of the env var key."})]}),n.jsxs("div",{className:"space-y-1.5",children:[n.jsx(jt,{htmlFor:"save-secret-value",children:"Value"}),n.jsx(qe,{id:"save-secret-value",type:"password",value:c,onChange:x=>d(x.target.value),placeholder:"secret value",autoComplete:"new-password",required:!0})]}),n.jsxs("div",{className:"space-y-1.5",children:[n.jsx(jt,{htmlFor:"save-secret-description",children:"Description (optional)"}),n.jsx(Tr,{id:"save-secret-description",value:u,onChange:x=>f(x.target.value),rows:2,placeholder:"What is this secret used for?"})]}),n.jsxs(ii,{children:[n.jsx(re,{type:"button",variant:"outline",onClick:e,disabled:m.isPending,children:"Cancel"}),n.jsx(re,{type:"submit",disabled:!_||m.isPending,children:m.isPending?"Saving…":"Save secret"})]})]})]})})}function fl(t){if(!Array.isArray(t))return[];const e=[];for(const s of t){if(!s||typeof s!="object")continue;const i=s,r=(i.key??"").trim();if(!(!r||!Xr.test(r))){if(i.kind==="literal"){e.push({key:r,kind:"literal",value:i.value??""});continue}i.kind==="secret"&&i.secretId&&e.push({key:r,kind:"secret",secretId:i.secretId})}}return e}function Jg(t){const e=t.trim();return e&&Xr.test(e)?e:""}function Zg(t){const e=K.c(12),{repo:s,className:i}=t;let r;e[0]!==i?(r=he("space-y-2",i),e[0]=i,e[1]=r):r=e[1];let o;e[2]===Symbol.for("react.memo_cache_sentinel")?(o=n.jsx(jt,{children:"Repository"}),e[2]=o):o=e[2];let a;e[3]===Symbol.for("react.memo_cache_sentinel")?(a=n.jsx(Vm,{size:20,className:"shrink-0 text-foreground/60"}),e[3]=a):a=e[3];let l;e[4]!==s?(l=n.jsx(Ee,{asChild:!0,children:n.jsxs("div",{className:"flex items-center gap-3 rounded-lg border border-border bg-background px-4 py-3",tabIndex:0,children:[a,n.jsx("div",{className:"min-w-0 flex-1",children:s?n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"truncate text-sm font-medium",children:[s.owner,"/",s.name]}),n.jsx("div",{className:"truncate text-xs text-muted-foreground",children:s.url})]}):n.jsx("div",{className:"text-sm text-muted-foreground",children:"No repository connected"})})]})}),e[4]=s,e[5]=l):l=e[5];let h;e[6]===Symbol.for("react.memo_cache_sentinel")?(h=n.jsx(Te,{children:"The connected GitHub repository for this agent. Manage in Connections."}),e[6]=h):h=e[6];let c;e[7]!==l?(c=n.jsxs(Re,{children:[l,h]}),e[7]=l,e[8]=c):c=e[8];let d;return e[9]!==r||e[10]!==c?(d=n.jsxs("div",{className:r,children:[o,c]}),e[9]=r,e[10]=c,e[11]=d):d=e[11],d}const Qg={npm:{install:"npm install",run:t=>`npm run ${t}`,runtime:"node"},pnpm:{install:"pnpm install",run:t=>`pnpm run ${t}`,runtime:"node"},yarn:{install:"yarn install",run:t=>`yarn run ${t}`,runtime:"node"},bun:{install:"bun install",run:t=>`bun run ${t}`,runtime:"bun"},deno:{install:"deno install",run:t=>`deno task ${t}`,runtime:"deno"}};function ev(t){const e=t.trim();if(e==="")return{ok:!0,value:null};if(!/^\d+$/.test(e))return{ok:!1};const s=Number(e);return s<1||s>65535?{ok:!1}:{ok:!0,value:String(s)}}const tv=Object.keys(Qg),xn="__none__";function sv(t){const e=K.c(20),{control:s}=t,i=E.useRef(null);let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=n.jsx(jt,{htmlFor:"runtime-pm",children:"Package manager"}),e[0]=r):r=e[0];let o;e[1]!==s?(o=n.jsxs("div",{className:"space-y-2",children:[r,n.jsx(vt,{control:s,name:"metadata.runtime.selected",render:rv})]}),e[1]=s,e[2]=o):o=e[2];let a;e[3]===Symbol.for("react.memo_cache_sentinel")?(a=n.jsx(jt,{htmlFor:"runtime-path",children:"Package path"}),e[3]=a):a=e[3];let l;e[4]!==s?(l=n.jsx(vt,{control:s,name:"metadata.runtime.path",render:iv}),e[4]=s,e[5]=l):l=e[5];let h;e[6]===Symbol.for("react.memo_cache_sentinel")?(h=n.jsx("p",{className:"text-xs text-muted-foreground",children:"Path (relative to repo root) to the directory containing package.json. Leave blank for the repo root."}),e[6]=h):h=e[6];let c;e[7]!==l?(c=n.jsxs("div",{className:"space-y-2",children:[a,l,h]}),e[7]=l,e[8]=c):c=e[8];let d;e[9]===Symbol.for("react.memo_cache_sentinel")?(d=n.jsx(jt,{htmlFor:"runtime-port",children:"Dev server port"}),e[9]=d):d=e[9];let u;e[10]===Symbol.for("react.memo_cache_sentinel")?(u=g=>{const{field:v}=g;return n.jsx(qe,{ref:i,id:"runtime-port",inputMode:"numeric",placeholder:"Auto",defaultValue:v.value??"",onBlur:b=>{const x=ev(b.target.value);x.ok?v.onChange(x.value):i.current&&(i.current.value=v.value??"")}})},e[10]=u):u=e[10];let f;e[11]!==s?(f=n.jsx(vt,{control:s,name:"metadata.runtime.port",render:u}),e[11]=s,e[12]=f):f=e[12];let m;e[13]===Symbol.for("react.memo_cache_sentinel")?(m=n.jsx("p",{className:"text-xs text-muted-foreground",children:"Leave blank to let the runner pick."}),e[13]=m):m=e[13];let p;e[14]!==f?(p=n.jsxs("div",{className:"space-y-2",children:[d,f,m]}),e[14]=f,e[15]=p):p=e[15];let _;return e[16]!==p||e[17]!==o||e[18]!==c?(_=n.jsxs("div",{className:"space-y-5",children:[o,c,p]}),e[16]=p,e[17]=o,e[18]=c,e[19]=_):_=e[19],_}function iv(t){const{field:e}=t;return n.jsx(qe,{id:"runtime-path",placeholder:".",defaultValue:e.value??"",onBlur:s=>{const i=s.target.value.trim();e.onChange(i===""?null:i)}})}function rv(t){const{field:e}=t;return n.jsxs(It,{value:e.value??xn,onValueChange:s=>e.onChange(s===xn?null:s),children:[n.jsx(Pt,{id:"runtime-pm",children:n.jsx(Dt,{placeholder:"Auto-detect"})}),n.jsxs(At,{children:[n.jsx(ot,{value:xn,children:"Auto-detect"}),tv.map(nv)]})]})}function nv(t){return n.jsx(ot,{value:t,children:t},t)}function ov(t,e){switch(e.type){case"SET_SHARE_DIALOG_OPEN":return{...t,shareDialogOpen:e.payload};case"SET_ADD_DIALOG_OPEN":return{...t,addDialogOpen:e.payload};case"OPEN_SETTINGS":return{...t,settingsDialogOpen:!0,settingsConnectionId:e.payload};case"CLOSE_SETTINGS":return{...t,settingsDialogOpen:!1,settingsConnectionId:null};default:return t}}function av(t,e){switch(e.type){case"accumulate":{const s=t??{start:e.now,fields:new Set,saveCount:0,instructionsLength:null},i=new Set(s.fields);for(const r of e.fields)i.add(r);return{...s,fields:i,saveCount:s.saveCount+1,instructionsLength:e.instructionsLength??s.instructionsLength}}case"reset":return null}}function lv(t){const e=t.metadata?.runtime?.env;if(!e||e.length===0)return t;const s=e.filter(i=>{if(!i||typeof i!="object")return!1;const r=(i.key??"").trim();return!r||!Xr.test(r)?!1:i.kind==="literal"?!0:i.kind==="secret"?!!i.secretId:!1});return s.length===e.length?t:{...t,metadata:{...t.metadata,runtime:{...t.metadata?.runtime??{},env:s}}}}function cv(t){const e=K.c(23),{connection_id:s,usedConnectionIds:i,onOpenSettings:r,onRemove:o,onAuthenticate:a,onSwitchInstance:l,onNewInstance:h}=t,c=Go(s),{org:d}=Pe();if(!c)return null;let u;e[0]!==c?(u=Bm(c),e[0]=c,e[1]=u):u=e[1];const f=u;let m;e[2]!==s?(m=n.jsx(fv,{connection_id:s}),e[2]=s,e[3]=m):m=e[3];let p;e[4]!==c.app_name||e[5]!==c.connection_type||e[6]!==c.description||e[7]!==c.icon||e[8]!==c.status||e[9]!==c.title||e[10]!==s||e[11]!==a||e[12]!==h||e[13]!==r||e[14]!==o||e[15]!==l||e[16]!==d.slug||e[17]!==f||e[18]!==i?(p=n.jsx(uv,{connection_id:s,connectionTitle:c.title,connectionDescription:c.description,connectionIcon:c.icon,connectionType:c.connection_type,connectionStatus:c.status,slug:f,orgSlug:d.slug,appName:c.app_name,usedConnectionIds:i,onOpenSettings:r,onRemove:o,onAuthenticate:a,onSwitchInstance:l,onNewInstance:h}),e[4]=c.app_name,e[5]=c.connection_type,e[6]=c.description,e[7]=c.icon,e[8]=c.status,e[9]=c.title,e[10]=s,e[11]=a,e[12]=h,e[13]=r,e[14]=o,e[15]=l,e[16]=d.slug,e[17]=f,e[18]=i,e[19]=p):p=e[19];let _;return e[20]!==m||e[21]!==p?(_=n.jsx(E.Suspense,{fallback:m,children:p}),e[20]=m,e[21]=p,e[22]=_):_=e[22],_}const ml="__new_instance__";async function hv(t,e){const s=t?.idToken??null;if(s){const r=pl(s);if(r)return r}const i=t?.userinfoEndpoint??null;if(i)try{const r=await fetch(i,{headers:{Authorization:`Bearer ${e}`}});if(r.ok){const o=await r.json(),a=typeof o.email=="string"?o.email:typeof o.upn=="string"?o.upn:typeof o.preferred_username=="string"?o.preferred_username:null;if(a)return a}}catch{}return pl(e)}function pl(t){try{const e=t.split(".");if(e.length===3&&e[1]){const s=JSON.parse(atob(e[1].replace(/-/g,"+").replace(/_/g,"/")));if(typeof s.email=="string")return s.email;if(typeof s.upn=="string")return s.upn;if(typeof s.preferred_username=="string")return s.preferred_username}}catch{}return null}function dv(t){const e=K.c(23),{appName:s,connectionId:i,usedConnectionIds:r,onSwitchInstance:o,onNewInstance:a}=t;let l;e[0]!==s?(l={filters:[{column:"app_name",value:s}]},e[0]=s,e[1]=l):l=e[1];const h=Vi(l);if(h.length<=1)return null;let c;e[2]!==i||e[3]!==a||e[4]!==o?(c=_=>{_===ml?a?.():o(i,_)},e[2]=i,e[3]=a,e[4]=o,e[5]=c):c=e[5];let d;e[6]===Symbol.for("react.memo_cache_sentinel")?(d=n.jsx(Pt,{size:"sm",className:"w-auto text-xs gap-1 px-2 shadow-none",children:n.jsx(Dt,{})}),e[6]=d):d=e[6];let u;if(e[7]!==i||e[8]!==h||e[9]!==r){let _;e[11]!==i||e[12]!==r?(_=g=>n.jsx(ot,{value:g.id,className:"text-xs",disabled:g.id!==i&&r.has(g.id),children:g.title},g.id),e[11]=i,e[12]=r,e[13]=_):_=e[13],u=h.map(_),e[7]=i,e[8]=h,e[9]=r,e[10]=u}else u=e[10];let f;e[14]!==a?(f=a&&n.jsx(ot,{value:ml,className:"text-xs text-muted-foreground",children:"+ New instance"}),e[14]=a,e[15]=f):f=e[15];let m;e[16]!==u||e[17]!==f?(m=n.jsxs(At,{children:[u,f]}),e[16]=u,e[17]=f,e[18]=m):m=e[18];let p;return e[19]!==i||e[20]!==c||e[21]!==m?(p=n.jsxs(It,{value:i,onValueChange:c,children:[d,m]}),e[19]=i,e[20]=c,e[21]=m,e[22]=p):p=e[22],p}function uv({connection_id:t,connectionTitle:e,connectionDescription:s,connectionIcon:i,connectionType:r,connectionStatus:o,slug:a,orgSlug:l,appName:h,usedConnectionIds:c,onOpenSettings:d,onRemove:u,onAuthenticate:f,onSwitchInstance:m,onNewInstance:p}){const _=ah({connectionId:t}),g=ih(),b=!(r==="VIRTUAL")&&_.supportsOAuth&&!_.isAuthenticated,x=o!=="active",y=async w=>{try{await g.update.mutateAsync({id:t,data:{status:w}}),le.success(w==="active"?"Connection enabled":"Connection disabled")}catch{le.error("Failed to update connection")}};return n.jsxs("div",{className:he("rounded-xl border overflow-hidden transition-colors",b||x?"border-destructive/50 bg-destructive/5":"border-border bg-card"),children:[n.jsxs(Uu,{to:"/$org/settings/connections/$appSlug",params:{org:l,appSlug:a},className:"flex items-center gap-3 px-4 py-3 cursor-pointer hover:bg-muted/50 transition-colors",children:[n.jsx(Gt,{icon:i,name:e,size:"sm",className:"shrink-0"}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("p",{className:"text-sm font-medium truncate",children:e}),b?n.jsx("span",{className:"text-xs text-destructive font-medium",children:"Needs authorization"}):x?n.jsx("span",{className:"text-xs text-destructive font-medium",children:o==="error"?"Disabled (error)":"Disabled"}):s&&n.jsx("p",{className:"text-xs text-muted-foreground truncate",children:s})]}),b?n.jsx(re,{variant:"outline",size:"sm",className:"h-7 text-xs shrink-0",onClick:w=>{w.preventDefault(),w.stopPropagation(),f(t)},children:"Authorize"}):x?n.jsxs(re,{variant:"outline",size:"sm",className:"h-7 text-xs gap-1.5 shrink-0",onClick:w=>{w.preventDefault(),w.stopPropagation(),y("active")},children:[n.jsx(Bf,{size:13}),"Enable"]}):n.jsxs(Re,{delayDuration:0,children:[n.jsx(Ee,{asChild:!0,children:n.jsx("span",{className:"inline-flex items-center justify-center rounded-md h-7 w-7 hover:bg-accent text-muted-foreground shrink-0 transition-colors",children:n.jsx(Mm,{size:16})})}),n.jsx(Te,{side:"bottom",children:"Connection settings"})]})]}),n.jsxs("div",{className:"flex items-center gap-3 px-4 py-2 border-t border-border bg-muted/25",children:[h&&n.jsx(dv,{appName:h,connectionId:t,usedConnectionIds:c,onSwitchInstance:m,onNewInstance:p}),n.jsxs("div",{className:"flex items-center gap-0.5 ml-auto",children:[n.jsxs(Re,{delayDuration:0,children:[n.jsx(Ee,{asChild:!0,children:n.jsx(re,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:d,"aria-label":"Configure resources",children:n.jsx(Mf,{size:13})})}),n.jsx(Te,{side:"bottom",children:"Configure resources"})]}),!x&&n.jsxs(Re,{delayDuration:0,children:[n.jsx(Ee,{asChild:!0,children:n.jsx(re,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground",onClick:()=>y("inactive"),"aria-label":"Disable connection",children:n.jsx(Lf,{size:13})})}),n.jsx(Te,{side:"bottom",children:"Disable"})]}),n.jsxs(Re,{delayDuration:0,children:[n.jsx(Ee,{asChild:!0,children:n.jsx(re,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-destructive",onClick:u,"aria-label":"Remove connection",children:n.jsx(ps,{size:13})})}),n.jsx(Te,{side:"bottom",children:"Remove"})]})]})]})]})}function fv(t){const e=K.c(17),{connection_id:s}=t,i=Go(s);if(!i){let u;return e[0]===Symbol.for("react.memo_cache_sentinel")?(u=n.jsx(Vh,{}),e[0]=u):u=e[0],u}let r;e[1]!==i.icon||e[2]!==i.title?(r=n.jsx(Gt,{icon:i.icon,name:i.title,size:"sm",className:"shrink-0"}),e[1]=i.icon,e[2]=i.title,e[3]=r):r=e[3];let o;e[4]!==i.title?(o=n.jsx("p",{className:"text-sm font-medium truncate",children:i.title}),e[4]=i.title,e[5]=o):o=e[5];let a;e[6]!==i.description?(a=i.description&&n.jsx("p",{className:"text-xs text-muted-foreground truncate",children:i.description}),e[6]=i.description,e[7]=a):a=e[7];let l;e[8]!==o||e[9]!==a?(l=n.jsxs("div",{className:"flex-1 min-w-0",children:[o,a]}),e[8]=o,e[9]=a,e[10]=l):l=e[10];let h;e[11]!==r||e[12]!==l?(h=n.jsxs("div",{className:"flex items-center gap-3 px-4 py-3",children:[r,l]}),e[11]=r,e[12]=l,e[13]=h):h=e[13];let c;e[14]===Symbol.for("react.memo_cache_sentinel")?(c=n.jsx("div",{className:"flex items-center px-4 py-2 border-t border-border bg-muted/25",children:n.jsx("div",{className:"h-5 w-20 rounded bg-muted animate-pulse"})}),e[14]=c):c=e[14];let d;return e[15]!==h?(d=n.jsxs("div",{className:"rounded-xl border border-border overflow-hidden",children:[h,c]}),e[15]=h,e[16]=d):d=e[16],d}function Vh(){const t=K.c(3);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=n.jsx("div",{className:"size-8 rounded-md bg-muted animate-pulse shrink-0"}),t[0]=e):e=t[0];let s;t[1]===Symbol.for("react.memo_cache_sentinel")?(s=n.jsxs("div",{className:"flex items-center gap-3 px-4 py-3",children:[e,n.jsxs("div",{className:"flex-1 space-y-1.5",children:[n.jsx("div",{className:"h-4 w-32 rounded bg-muted animate-pulse"}),n.jsx("div",{className:"h-3 w-48 rounded bg-muted animate-pulse"})]})]}),t[1]=s):s=t[1];let i;return t[2]===Symbol.for("react.memo_cache_sentinel")?(i=n.jsxs("div",{className:"rounded-xl border border-border overflow-hidden",children:[s,n.jsx("div",{className:"flex items-center px-4 py-2 border-t border-border bg-muted/25",children:n.jsx("div",{className:"h-5 w-20 rounded bg-muted animate-pulse"})})]}),t[2]=i):i=t[2],i}function mv({virtualMcpId:t,form:e,flushAndSave:s}){const i=qi(),r=Mt(t),o=(r?.connections??[]).map(S=>S.connection_id).sort(),{data:a}=Zs({queryKey:Bt.projectConnectionDetails(t,o),enabled:o.length>0,queryFn:async()=>await Promise.all(o.map(async k=>{try{const{item:I}=await i.call("COLLECTION_CONNECTIONS_GET",{id:k}),N=(I?.tools??[]).flatMap(A=>{const M=Am(A._meta);return M?[{name:A.name,title:A.title,description:A.description,resourceUri:M}]:[]});return{fetchOk:!0,id:k,title:I?.title??k,icon:I?.icon??null,uiTools:N}}catch{return{fetchOk:!1,id:k,title:k,icon:null,uiTools:[]}}}))}),l=(a??[]).filter(S=>S.uiTools.length>0),h=new Set(sm),c=e.watch("metadata.ui.pinnedViews")??[],d=e.watch("metadata.ui.layout")??null,u=d?.defaultMainView??null,f=d?.chatDefaultOpen??!1,m=!u||u.type==="chat"?"chat":u.type==="instructions"||u.type==="connections"||u.type==="layout"?"settings":h.has(u.type)?u.type:`${u.type}:${u.id??""}:${u.toolName??""}`,p=S=>{const[k,I,N]=S.split(":");return k?k==="chat"?{type:k}:h.has(k)?{type:k}:k==="ext-apps"&&I?{type:"ext-apps",id:I,toolName:N||void 0}:null:null},_=S=>{e.setValue("metadata.ui.pinnedViews",S,{shouldDirty:!0})},g=S=>{e.setValue("metadata.ui.layout",{...d,...S},{shouldDirty:!0})},v=E.useRef(!1);if(a&&a.length>0&&!v.current){v.current=!0;const S=new Set((a??[]).filter(N=>N.fetchOk).map(N=>N.id)),k=new Set(l.flatMap(N=>N.uiTools.map(A=>`${N.id}:${A.name}`))),I=c.filter(N=>!S.has(N.connectionId)||k.has(`${N.connectionId}:${N.toolName}`));I.length!==c.length&&(_(I),u?.type==="ext-apps"&&!I.some(N=>N.connectionId===u.id&&N.toolName===u.toolName)&&g({defaultMainView:{type:"chat"}}))}const b=(S,k)=>{if(c.some(N=>N.connectionId===S&&N.toolName===k)){const N=c.filter(M=>!(M.connectionId===S&&M.toolName===k));_(N);const A=`ext-apps:${S}:${k}`;m===A&&g({defaultMainView:{type:"chat"}})}else{const N=l.find(A=>A.id===S)?.uiTools.find(A=>A.name===k)?.title;_([...c,{connectionId:S,toolName:k,label:N??Wa(k),icon:null}])}s()},x=(S,k,I)=>{_(c.map(N=>N.connectionId===S&&N.toolName===k?{...N,label:I}:N))},y=()=>{s()},w=(S,k,I)=>{_(c.map(N=>N.connectionId===S&&N.toolName===k?{...N,icon:I}:N)),s()},C=S=>{g({defaultMainView:p(S)}),s()},j=o.length===0,R=a&&l.length===0,B=ti(r?.metadata),P=[{value:"chat",label:"Chat"},{value:"settings",label:"Settings"},{value:"automations",label:"Automations"}];B&&P.push({value:"preview",label:"Preview"});for(const S of c)P.push({value:`ext-apps:${S.connectionId}:${S.toolName}`,label:S.label||S.toolName});const T=l.length>0||j||R;return n.jsxs("div",{className:"flex flex-col gap-3",children:[n.jsx("div",{className:"flex items-center justify-between gap-3",children:n.jsx("h2",{className:"text-sm font-medium text-foreground",children:"Layout"})}),n.jsxs(ch,{className:"p-6 gap-5",children:[n.jsxs(qn,{className:"p-0 space-y-5",children:[n.jsxs("div",{className:"flex items-center justify-between gap-4",children:[n.jsxs("div",{className:"space-y-0.5 min-w-0",children:[n.jsx(jt,{className:"font-normal text-foreground",children:"Main view"}),n.jsx("p",{className:"text-xs text-muted-foreground",children:"What users see when they first open this agent."})]}),n.jsxs(It,{value:m,onValueChange:C,children:[n.jsx(Pt,{className:"w-44 h-8 text-sm capitalize shrink-0",children:n.jsx(Dt,{})}),n.jsx(At,{children:P.map(S=>n.jsx(ot,{value:S.value,className:"capitalize",children:S.label},S.value))})]})]}),n.jsxs("div",{className:"flex items-center justify-between gap-4",children:[n.jsxs("div",{className:"space-y-0.5 min-w-0",children:[n.jsx(jt,{className:"font-normal text-foreground",children:"Show chat"}),n.jsx("p",{className:"text-xs text-muted-foreground",children:"Display the chat panel alongside the main view."})]}),n.jsxs(Re,{delayDuration:0,children:[n.jsx(Ee,{asChild:!0,children:n.jsx("span",{className:"shrink-0",children:n.jsx(Or,{checked:m==="chat"?!0:f,disabled:m==="chat",onCheckedChange:S=>{g({chatDefaultOpen:S}),s()}})})}),m==="chat"&&n.jsx(Te,{side:"top",children:"Chat is always shown when it is the default view"})]})]})]}),T&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"border-t border-border -mx-6"}),n.jsxs(qn,{className:"p-0 space-y-3",children:[n.jsx("div",{className:"flex items-center justify-between gap-4",children:n.jsxs("div",{className:"space-y-0.5 min-w-0",children:[n.jsx(jt,{className:"font-normal text-foreground",children:"Pinned views"}),n.jsx("p",{className:"text-xs text-muted-foreground",children:"Surface interactive tools as top-level tabs in the agent."})]})}),j&&n.jsx("p",{className:"text-xs text-muted-foreground",children:"Add a connection above to configure pinned views."}),R&&!j&&n.jsx("p",{className:"text-xs text-muted-foreground",children:"None of the connected servers expose interactive tools."}),l.length>0&&n.jsx("div",{className:"space-y-4 pt-1",children:l.map((S,k)=>n.jsxs("div",{children:[k>0&&n.jsx("div",{className:"border-t border-border -mx-6 mb-4"}),n.jsxs("div",{className:"flex items-center gap-2 mb-2.5",children:[n.jsx(Gt,{icon:S.icon,name:S.title,size:"xs",className:"shrink-0"}),n.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:S.title})]}),n.jsx("div",{className:"space-y-1.5",children:S.uiTools.map(I=>{const N=c.some(M=>M.connectionId===S.id&&M.toolName===I.name),A=c.find(M=>M.connectionId===S.id&&M.toolName===I.name);return n.jsxs("div",{className:he("flex items-center justify-between gap-3 px-3 py-2 rounded-lg border transition-colors",N?"bg-accent/40 border-border":"bg-transparent border-border"),children:[n.jsxs("div",{className:"min-w-0 flex-1 flex items-center gap-2",children:[n.jsx(tg,{value:A?.icon??null,onChange:M=>w(S.id,I.name,M),disabled:!N}),n.jsx(qe,{value:N&&A?A.label:I.title??Wa(I.name),onChange:M=>x(S.id,I.name,M.target.value),onBlur:y,className:"h-7 text-sm w-40",disabled:!N,readOnly:!N})]}),n.jsx(Or,{checked:N,onCheckedChange:()=>b(S.id,I.name)})]},I.name)})})]},S.id))})]})]})]})]})}function pv({virtualMcp:t,hideOwnTitle:e}){const{org:s}=Pe(),i=tf(),{data:r}=sf([t.id]),o=r?.get(t.id)?.last_used_at,a=ih(),l=Qs(),h=qi(),c=Mc({resolver:Hu(jg),defaultValues:t}),d=c.watch("connections"),u=Lc(t),f=si(t),m=f?{owner:f.owner,name:f.name,url:f.url}:null,[p,_]=E.useReducer(ov,{shareDialogOpen:!1,addDialogOpen:!1,settingsDialogOpen:!1,settingsConnectionId:null}),[g,v]=E.useState(!1),[b,x]=E.useState(!1),{createNewTask:y,setChatOpen:w}=Uo(),{sendMessage:C}=Ns(),j=async()=>{if(b)return;const L=c.getValues("metadata.instructions");if(L?.trim()){x(!0);try{k(),De("agent_instructions_improve_clicked",{agent_id:t.id,instructions_length:L.length}),w(!0),await C({tiptapDoc:Uh({managerAgentId:Oc.AGENT_MANAGER(s.id),managerName:"Agent Manager",kind:"agent",id:t.id,instructions:L})})}finally{x(!1)}}},R=()=>{k(),De("agent_test_clicked",{agent_id:t.id}),y()},[B,P]=E.useReducer(av,null),T=()=>{B!==null&&(De("agent_updated",{agent_id:t.id,fields:Array.from(B.fields),instructions_length:B.instructionsLength,save_count:B.saveCount,edit_duration_ms:Date.now()-B.start}),P({type:"reset"}))},{schedule:S,flush:k}=$r({delayMs:3e4,save:async()=>T()}),I=async()=>{const L=Object.keys(c.control._formState.dirtyFields);if(L.length===0)return;const se=L.includes("metadata"),ee=c.getValues();c.reset(ee,{keepValues:!0});const Q=lv(ee);await i.update.mutateAsync({id:t.id,data:Q}),P({type:"accumulate",now:Date.now(),fields:L,instructionsLength:se?ee.metadata?.instructions?.length??0:null}),S()},{schedule:N,flush:A}=$r({save:I});E.useEffect(()=>{const L=c.watch(()=>N());return()=>L.unsubscribe()},[]);const M=()=>{De("connections_dialog_opened",{source:"agent_settings",mode:"add"}),_({type:"SET_ADD_DIALOG_OPEN",payload:!0})},D=async L=>{const se=c.getValues("connections");if(se.some(O=>O.connection_id===L))return;c.setValue("connections",[...se,{connection_id:L,selected_tools:vn.tools,selected_resources:vn.resources,selected_prompts:vn.prompts}],{shouldDirty:!0}),_({type:"SET_ADD_DIALOG_OPEN",payload:!1});const ee=new URL(`/api/${s.slug}/mcp/${L}`,window.location.origin),Q=await Fa({url:ee.href,token:null,orgId:s.id});Q.supportsOAuth&&!Q.isAuthenticated&&await V(L)},$=L=>{const ee=c.getValues("connections").filter(Q=>Q.connection_id!==L);c.setValue("connections",ee,{shouldDirty:!0})},z=(L,se)=>{const ee=c.getValues("connections");if(ee.some(Q=>Q.connection_id===se)){le.error("This instance is already added to the agent");return}c.setValue("connections",ee.map(Q=>Q.connection_id===L?{...Q,connection_id:se}:Q),{shouldDirty:!0})},W=async L=>{if(c.getValues("connections").find(ee=>ee.connection_id===L))try{const{item:ee}=await h.call("COLLECTION_CONNECTIONS_GET",{id:L});if(!ee)return;const Q=ee.title.replace(/\s*\(.*?\)\s*$/,""),O=Dm("conn"),ce=`${Q} (${Date.now().toString(36).slice(-4)})`;await a.create.mutateAsync({id:O,title:ce,description:ee.description??null,connection_type:ee.connection_type,connection_url:ee.connection_url??null,connection_token:null,icon:ee.icon??null,app_name:ee.app_name??null,app_id:ee.app_id??null,connection_headers:ee.connection_headers??null});const ue=new URL(`/api/${s.slug}/mcp/${O}`,window.location.origin),fe=await Fa({url:ue.href,token:null,orgId:s.id});if(fe.supportsOAuth&&!fe.isAuthenticated){const q=await V(O);if(!q){await a.delete.mutateAsync(O);return}await a.update.mutateAsync({id:O,data:{title:`${Q} (${q})`}})}z(L,O),le.success("New instance created")}catch(ee){console.error("Failed to create instance:",ee),le.error("Failed to create instance")}},F=L=>{_({type:"OPEN_SETTINGS",payload:L})},V=async L=>{const{token:se,tokenInfo:ee,error:Q}=await Wu({connectionId:L,orgSlug:s.slug,scope:"offline_access"});if(Q||!se)return le.error(`Authentication failed: ${Q}`),null;if(ee)try{const ce=await fetch(`/api/${s.slug}/connections/${L}/oauth-token`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({accessToken:ee.accessToken,refreshToken:ee.refreshToken,expiresIn:ee.expiresIn,scope:ee.scope,clientId:ee.clientId,clientSecret:ee.clientSecret,tokenEndpoint:ee.tokenEndpoint})});if(!ce.ok)console.error("Failed to save OAuth token:",await ce.text()),await a.update.mutateAsync({id:L,data:{connection_token:se}});else try{await a.update.mutateAsync({id:L,data:{}})}catch(ue){console.warn("Failed to refresh connection tools after OAuth:",ue)}}catch(ce){console.error("Error saving OAuth token:",ce),await a.update.mutateAsync({id:L,data:{connection_token:se}})}else await a.update.mutateAsync({id:L,data:{connection_token:se}});const O=new URL(`/api/${s.slug}/mcp/${L}`,window.location.origin);return await l.invalidateQueries({queryKey:Bt.isMCPAuthenticated(O.href,null)}),le.success("Authentication successful"),hv(ee,se)},J=()=>{const L=c.getValues("metadata.instructions")??"",se=`<role>
|
|
10
|
+
`),m=async()=>{a(!0);try{const{key:_}=await e.call("API_KEY_CREATE",{name:`chat-bridge-${d}`,permissions:Ig,expiresIn:Bg});if(!_)throw new Error("No key in response");r(_),De("agent_chat_bridge_key_generated",{agent_id:c})}catch{De("agent_chat_bridge_key_failed",{agent_id:c}),le.error("Failed to create API key")}finally{a(!1)}},p=async()=>{De("agent_connect_action",{agent_id:c,action:"chat_bridge_copy_env",has_api_key:!!i}),await navigator.clipboard.writeText(f),h(!0),le.success("Connection details copied to clipboard"),setTimeout(()=>h(!1),2e3)};return n.jsxs("div",{className:"flex min-w-0 flex-col gap-3",children:[n.jsxs("div",{className:"flex items-start justify-between gap-3",children:[n.jsxs("div",{className:"flex flex-col gap-0.5",children:[n.jsx("h4",{className:"text-sm font-medium text-foreground",children:"Call from your app"}),n.jsx("p",{className:"text-xs text-muted-foreground",children:"Create a scoped API key to start a thread, run this agent, and stream results from an external system (e.g. a chatbot webhook)."})]}),!i&&n.jsxs(re,{type:"button",variant:"outline",size:"sm",className:"shrink-0 gap-1.5",onClick:m,disabled:o,children:[o?n.jsx(Ce,{size:14,className:"animate-spin"}):n.jsx(ea,{size:14}),n.jsx("span",{children:o?"Creating…":"Create API key"})]})]}),i&&n.jsx("p",{className:"rounded-md border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-700",children:"Store this key securely — it won't be shown again."}),n.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"Connection details"}),n.jsx("div",{className:"rounded-md border border-input bg-muted/50 px-3 py-2.5",children:n.jsxs("div",{className:"flex items-start gap-2",children:[n.jsx("code",{className:"min-w-0 flex-1 whitespace-pre-wrap break-all font-mono text-xs text-muted-foreground",children:f}),n.jsx(re,{type:"button",variant:"ghost",size:"icon",className:"size-6 shrink-0",onClick:p,children:l?n.jsx(ri,{size:12,className:"text-green-600"}):n.jsx(Qt,{size:12})})]})})]})}function Lg(t){const e=K.c(3),{virtualMcp:s}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=n.jsx("div",{className:"h-20 animate-pulse rounded-md bg-muted"}),e[0]=i):i=e[0];let r;return e[1]!==s?(r=n.jsx(E.Suspense,{fallback:i,children:n.jsx(Mg,{virtualMcp:s})}),e[1]=s,e[2]=r):r=e[2],r}function Og(t){const e=K.c(41),{open:s,onOpenChange:i,virtualMcp:r}=t,{org:o}=Pe(),a=`/api/${o.slug}/mcp/virtual-mcp/${r.id}`;let l;e[0]!==a?(l=new URL(a,window.location.origin),e[0]=a,e[1]=l):l=e[1];const h=l;let c;e[2]!==r.id||e[3]!==r.title?(c=r.title||`agent-${r.id?.slice(0,8)??"default"}`,e[2]=r.id,e[3]=r.title,e[4]=c):c=e[4];const d=c,u=Wc();let f;e[5]!==r.id||e[6]!==h.href?(f=n.jsx(Eg,{url:h.href,agentId:r.id}),e[5]=r.id,e[6]=h.href,e[7]=f):f=e[7];let m,p;e[8]!==d||e[9]!==r.id||e[10]!==h.href?(m=n.jsx(Tg,{url:h.href,serverName:d,agentId:r.id}),p=n.jsx(Rg,{url:h.href,serverName:d,agentId:r.id}),e[8]=d,e[9]=r.id,e[10]=h.href,e[11]=m,e[12]=p):(m=e[11],p=e[12]);let _;e[13]!==f||e[14]!==m||e[15]!==p?(_=n.jsx("div",{className:"flex flex-col gap-3 pt-2",children:n.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[f,m,p]})}),e[13]=f,e[14]=m,e[15]=p,e[16]=_):_=e[16];let g;e[17]===Symbol.for("react.memo_cache_sentinel")?(g=n.jsx("div",{className:"border-t border-border"}),e[17]=g):g=e[17];let v;e[18]!==r?(v=n.jsx(Ag,{virtualMcp:r}),e[18]=r,e[19]=v):v=e[19];let b;e[20]===Symbol.for("react.memo_cache_sentinel")?(b=n.jsx("div",{className:"border-t border-border"}),e[20]=b):b=e[20];let x;e[21]!==r?(x=n.jsx(Lg,{virtualMcp:r}),e[21]=r,e[22]=x):x=e[22];let y;e[23]!==x||e[24]!==_||e[25]!==v?(y=n.jsxs("div",{className:"flex flex-col gap-6",children:[_,g,v,b,x]}),e[23]=x,e[24]=_,e[25]=v,e[26]=y):y=e[26];const w=y;if(u){let B;e[27]===Symbol.for("react.memo_cache_sentinel")?(B=n.jsx(zm,{className:"mt-4 mb-4 text-base font-semibold",children:"Connect"}),e[27]=B):B=e[27];let P;e[28]!==w?(P=n.jsx(Fm,{children:n.jsxs("div",{className:"flex-1 overflow-y-auto px-4 pb-6 [touch-action:pan-y]",children:[B,w]})}),e[28]=w,e[29]=P):P=e[29];let T;return e[30]!==i||e[31]!==s||e[32]!==P?(T=n.jsx(Hm,{open:s,onOpenChange:i,children:P}),e[30]=i,e[31]=s,e[32]=P,e[33]=T):T=e[33],T}let C;e[34]===Symbol.for("react.memo_cache_sentinel")?(C=n.jsx(is,{children:n.jsx(rs,{children:"Connect"})}),e[34]=C):C=e[34];let j;e[35]!==w?(j=n.jsxs(Ot,{className:"max-h-[80vh] overflow-y-auto sm:max-w-2xl",children:[C,w]}),e[35]=w,e[36]=j):j=e[36];let R;return e[37]!==i||e[38]!==s||e[39]!==j?(R=n.jsx(Lt,{open:s,onOpenChange:i,children:j}),e[37]=i,e[38]=s,e[39]=j,e[40]=R):R=e[40],R}const $g=/^[A-Za-z_][A-Za-z0-9_]*$/;function zg(t){const e={},s=t.split(/\r?\n/);for(let i=0;i<s.length;i++){let r=(s[i]??"").trim();if(!r||r.startsWith("#"))continue;r.startsWith("export ")&&(r=r.slice(7).trim());const o=r.indexOf("=");if(o<0)throw new Error(`Line ${i+1}: missing '='`);const a=r.slice(0,o).trim();if(!$g.test(a))throw new Error(`Line ${i+1}: invalid key "${a}"`);let l=r.slice(o+1).trim();l.length>=2&&(l.startsWith('"')&&l.endsWith('"')||l.startsWith("'")&&l.endsWith("'"))&&(l=l.slice(1,-1)),e[a]=l}return e}const Fg=/^[A-Za-z0-9_.-]+$/;function Hg(t){const e=K.c(14),{control:s,form:i,virtualMcpId:r,orgSlug:o}=t;let a,l;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=n.jsx("div",{className:"flex items-baseline justify-between gap-2",children:n.jsx(jt,{className:"font-normal text-foreground",children:"Environment variables"})}),l=n.jsx("p",{className:"text-xs text-muted-foreground",children:"Injected into the sandbox on every start. Reference an org/user secret to keep values out of metadata; literals are stored inline."}),e[0]=a,e[1]=l):(a=e[0],l=e[1]);let h;e[2]!==s||e[3]!==i||e[4]!==o||e[5]!==r?(h=n.jsx(Ug,{control:s,form:i,virtualMcpId:r,orgSlug:o}),e[2]=s,e[3]=i,e[4]=o,e[5]=r,e[6]=h):h=e[6];let c;e[7]===Symbol.for("react.memo_cache_sentinel")?(c=n.jsx(uh,{className:"h-9 w-full"}),e[7]=c):c=e[7];let d;e[8]!==s||e[9]!==i?(d=n.jsx(Ut,{fallback:Wg,children:n.jsx(E.Suspense,{fallback:c,children:n.jsx(Vg,{control:s,form:i})})}),e[8]=s,e[9]=i,e[10]=d):d=e[10];let u;return e[11]!==h||e[12]!==d?(u=n.jsxs("div",{className:"space-y-2",children:[a,l,h,d]}),e[11]=h,e[12]=d,e[13]=u):u=e[13],u}function Wg(t){const{error:e}=t;return n.jsx("div",{className:"rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2 text-xs text-destructive",children:e?.message??"Failed to load secrets"})}function Ug(t){const e=K.c(24),{control:s,form:i,virtualMcpId:r,orgSlug:o}=t,l=Js.useSession().data?.user?.id,h="metadata.runtime.env",c="metadata.sandboxMap";let d;e[0]!==i?(d=()=>JSON.stringify(fl(i.getValues(h))),e[0]=i,e[1]=d):d=e[1];const[u,f]=E.useState(d);let m;e[2]!==s?(m={control:s,name:h},e[2]=s,e[3]=m):m=e[3];const p=Bc(m);let _;e[4]!==p?(_=JSON.stringify(fl(p)),e[4]=p,e[5]=_):_=e[5];const g=_,v=g!==u;let b;e[6]!==i?(b=i.getValues(c),e[6]=i,e[7]=b):b=e[7];const x=b;let y;e[8]!==x||e[9]!==l?(y=l?Object.keys(x?.[l]??{}):[],e[8]=x,e[9]=l,e[10]=y):y=e[10];const w=y,C=w.length>0,[j,R]=E.useState(!1);if(!v||!C)return null;let B;e[11]!==g||e[12]!==o||e[13]!==w||e[14]!==r?(B=async()=>{R(!0);const N=await Promise.allSettled(w.map(async M=>{const D=`/api/${encodeURIComponent(o)}/sandbox/${encodeURIComponent(r)}/${encodeURIComponent(M)}/setup/start`,$=await fetch(D,{method:"POST"});if(!$.ok){const z=await $.text().catch(()=>$.statusText);throw new Error(z||$.statusText)}}));R(!1);const A=N.filter(Kg).length;A===0?(f(g),le.success(w.length===1?"Restarted dev with new env":`Restarted ${w.length} branches with new env`)):le.error(`Failed to restart ${A} of ${w.length} branch(es)`)},e[11]=g,e[12]=o,e[13]=w,e[14]=r,e[15]=B):B=e[15];const P=B;let T;e[16]===Symbol.for("react.memo_cache_sentinel")?(T=n.jsxs("div",{className:"flex min-w-0 items-center gap-2 text-amber-900 dark:text-amber-200",children:[n.jsx(Ic,{className:"size-3.5 shrink-0"}),n.jsx("span",{className:"truncate",children:"Your sandbox is running. Restart the dev script to apply the new env."})]}),e[16]=T):T=e[16];let S;e[17]!==j?(S=j?n.jsx(Ce,{className:"size-3.5 animate-spin"}):n.jsx(Bi,{className:"size-3.5"}),e[17]=j,e[18]=S):S=e[18];const k=j?"Restarting…":"Restart dev";let I;return e[19]!==P||e[20]!==j||e[21]!==S||e[22]!==k?(I=n.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border border-amber-200 bg-amber-50 px-3 py-2 text-xs dark:border-amber-900/40 dark:bg-amber-950/30",children:[T,n.jsxs(re,{type:"button",variant:"outline",size:"sm",onClick:P,disabled:j,className:"shrink-0",children:[S,k]})]}),e[19]=P,e[20]=j,e[21]=S,e[22]=k,e[23]=I):I=e[23],I}function Kg(t){return t.status==="rejected"}function Vg(t){const e=K.c(48),{control:s,form:i}=t,r="metadata.runtime.env";let o;e[0]!==s?(o={control:s,name:r},e[0]=s,e[1]=o):o=e[1];const a=zu(o),{fields:l,append:h,remove:c}=a;let d;e[2]!==i?(d=(N,A)=>{i.setValue(`${r}.${N}`,A,{shouldDirty:!0,shouldTouch:!0})},e[2]=i,e[3]=d):d=e[3];const u=d,f=Um();let m;if(e[4]!==f){m=new Map;for(const N of f)m.set(N.id,N);e[4]=f,e[5]=m}else m=e[5];const[p,_]=E.useState(null);let g;e[6]!==h?(g=()=>{h({key:"",kind:"literal",value:""})},e[6]=h,e[7]=g):g=e[7];const v=g;let b;e[8]!==h||e[9]!==i?(b=async()=>{let N;try{N=await navigator.clipboard.readText()}catch{le.error("Couldn't read clipboard");return}if(!N.trim()){le.error("Clipboard is empty");return}let A;try{A=zg(N)}catch(F){const V=F;le.error(V.message);return}const M=Object.entries(A);if(M.length===0){le.error("Nothing to add");return}const D=i.getValues(r)??[],$=new Set;for(const F of D){const V=(F.key??"").trim();V&&$.add(V)}let z=0,W=0;for(const[F,V]of M){if($.has(F)){W++;continue}h({key:F,kind:"literal",value:V}),$.add(F),z++}z===0&&W>0?le.message(`All ${W} key${W===1?"":"s"} already exist`):le.success(W>0?`Added ${z} var${z===1?"":"s"} (${W} already existed)`:`Added ${z} var${z===1?"":"s"}`)},e[8]=h,e[9]=i,e[10]=b):b=e[10];const x=b;let y;if(e[11]!==s||e[12]!==l||e[13]!==i||e[14]!==c||e[15]!==m||e[16]!==f||e[17]!==u){let N;e[19]!==s||e[20]!==i||e[21]!==c||e[22]!==m||e[23]!==f||e[24]!==u?(N=(A,M)=>n.jsx("li",{className:"rounded-md border border-border bg-background",children:n.jsx(qg,{index:M,control:s,form:i,onUpdateEntry:u,fieldPath:r,secrets:f,secretById:m,onSaveAsSecret:(D,$)=>_({kind:"save-literal",index:M,presetKey:D,presetValue:$}),onCreateNewSecret:D=>_({kind:"create-new",index:M,presetKey:D}),onRemove:()=>c(M)})},A.id),e[19]=s,e[20]=i,e[21]=c,e[22]=m,e[23]=f,e[24]=u,e[25]=N):N=e[25],y=l.map(N),e[11]=s,e[12]=l,e[13]=i,e[14]=c,e[15]=m,e[16]=f,e[17]=u,e[18]=y}else y=e[18];let w;e[26]!==y?(w=n.jsx("ul",{className:"space-y-2",children:y}),e[26]=y,e[27]=w):w=e[27];let C;e[28]===Symbol.for("react.memo_cache_sentinel")?(C=n.jsx(xt,{className:"size-3.5"}),e[28]=C):C=e[28];let j;e[29]!==v?(j=n.jsxs(re,{type:"button",variant:"outline",size:"sm",onClick:v,className:"flex-1",children:[C,"Add env var"]}),e[29]=v,e[30]=j):j=e[30];let R;e[31]===Symbol.for("react.memo_cache_sentinel")?(R=n.jsx(Af,{className:"size-3.5"}),e[31]=R):R=e[31];let B;e[32]!==x?(B=n.jsx(Ee,{asChild:!0,children:n.jsxs(re,{type:"button",variant:"outline",size:"sm",onClick:x,"aria-label":"Paste .env",children:[R,"Paste .env"]})}),e[32]=x,e[33]=B):B=e[33];let P;e[34]===Symbol.for("react.memo_cache_sentinel")?(P=n.jsx(Te,{children:"Read a .env blob from the clipboard. Each pair is staged as a literal — save individual rows as secrets after."}),e[34]=P):P=e[34];let T;e[35]!==B?(T=n.jsxs(Re,{children:[B,P]}),e[35]=B,e[36]=T):T=e[36];let S;e[37]!==T||e[38]!==j?(S=n.jsxs("div",{className:"flex items-center gap-2",children:[j,T]}),e[37]=T,e[38]=j,e[39]=S):S=e[39];let k;e[40]!==p||e[41]!==i||e[42]!==u?(k=p!==null?n.jsx(Xg,{mode:p,onClose:()=>_(null),onSaved:N=>{const A=i.getValues(`${r}.${p.index}.key`)?.trim()??"";u(p.index,{key:A,kind:"secret",secretId:N}),_(null)}}):null,e[40]=p,e[41]=i,e[42]=u,e[43]=k):k=e[43];let I;return e[44]!==S||e[45]!==k||e[46]!==w?(I=n.jsxs("div",{className:"space-y-2",children:[w,S,k]}),e[44]=S,e[45]=k,e[46]=w,e[47]=I):I=e[47],I}function qg(t){const e=K.c(55),{index:s,control:i,form:r,onUpdateEntry:o,fieldPath:a,secrets:l,secretById:h,onSaveAsSecret:c,onCreateNewSecret:d,onRemove:u}=t,f=`${a}.${s}.key`,m=`${a}.${s}.value`,p=`${a}.${s}.secretId`,_=`${a}.${s}.kind`;let g;e[0]!==i||e[1]!==_?(g={control:i,name:_},e[0]=i,e[1]=_,e[2]=g):g=e[2];const b=Bc(g)==="secret"?"secret":"literal";let x;e[3]!==r||e[4]!==s||e[5]!==f||e[6]!==c||e[7]!==o||e[8]!==m?(x=z=>{const W=r.getValues(f)?.trim()??"";if(z==="literal"){o(s,{key:W,kind:"literal",value:""});return}const F=r.getValues(m)??"";if(F.length>0){c(W,F);return}o(s,{key:W,kind:"secret",secretId:""})},e[3]=r,e[4]=s,e[5]=f,e[6]=c,e[7]=o,e[8]=m,e[9]=x):x=e[9];const y=x;let w;e[10]!==s?(w=z=>{const{field:W}=z,F=(W.value??"").trim(),V=F.length>0&&!Xr.test(F);return n.jsxs("div",{className:"space-y-1",children:[n.jsx(qe,{...W,value:W.value??"",placeholder:"KEY",spellCheck:!1,autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",className:he("font-mono",V&&"border-destructive focus-visible:ring-destructive"),"aria-invalid":V,"aria-label":`Env var ${s+1} key`,onBlur:J=>{const Y=J.target.value.trim();W.onChange(Y),W.onBlur()}}),V?n.jsx("p",{className:"text-[11px] text-destructive",children:"Letters, digits, underscores. Must start with a letter or underscore."}):null]})},e[10]=s,e[11]=w):w=e[11];let C;e[12]!==i||e[13]!==f||e[14]!==w?(C=n.jsx("div",{className:"flex-1 min-w-0",children:n.jsx(vt,{control:i,name:f,render:w})}),e[12]=i,e[13]=f,e[14]=w,e[15]=C):C=e[15];let j;e[16]!==y?(j=z=>y(z),e[16]=y,e[17]=j):j=e[17];let R;e[18]===Symbol.for("react.memo_cache_sentinel")?(R=n.jsx(Pt,{className:"h-9 w-[110px]",children:n.jsx(Dt,{})}),e[18]=R):R=e[18];let B;e[19]===Symbol.for("react.memo_cache_sentinel")?(B=n.jsx(ot,{value:"literal",children:n.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[n.jsx(ea,{className:"size-3.5"}),"Literal"]})}),e[19]=B):B=e[19];let P;e[20]===Symbol.for("react.memo_cache_sentinel")?(P=n.jsxs(At,{children:[B,n.jsx(ot,{value:"secret",children:n.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[n.jsx(Fu,{className:"size-3.5"}),"Secret"]})})]}),e[20]=P):P=e[20];let T;e[21]!==b||e[22]!==j?(T=n.jsx("div",{className:"shrink-0",children:n.jsxs(It,{value:b,onValueChange:j,children:[R,P]})}),e[21]=b,e[22]=j,e[23]=T):T=e[23];let S;e[24]!==i||e[25]!==r||e[26]!==s||e[27]!==f||e[28]!==b||e[29]!==d||e[30]!==h||e[31]!==p||e[32]!==l||e[33]!==m?(S=n.jsx("div",{className:"flex flex-[2] min-w-0 items-center gap-1",children:b==="literal"?n.jsx(vt,{control:i,name:m,render:z=>{const{field:W}=z;return n.jsx(qe,{...W,value:W.value??"",type:"password",placeholder:"value",spellCheck:!1,autoComplete:"off",className:"font-mono","aria-label":`Env var ${s+1} value`,onBlur:F=>{W.onChange(F.target.value),W.onBlur()}})}}):n.jsxs(n.Fragment,{children:[n.jsx(vt,{control:i,name:p,render:z=>{const{field:W}=z;return n.jsxs(It,{value:W.value||"",onValueChange:F=>W.onChange(F),children:[n.jsx(Pt,{className:he("h-9 w-full",!W.value&&"text-muted-foreground"),children:n.jsx(Dt,{placeholder:"Pick a secret…",children:n.jsx(Yg,{field:W,secretById:h})})}),n.jsx(At,{children:l.length===0?n.jsx("div",{className:"px-2 py-2 text-xs text-muted-foreground",children:"No secrets yet. Use the “+” to create one."}):l.map(Gg)})]})}}),n.jsxs(Re,{children:[n.jsx(Ee,{asChild:!0,children:n.jsx(re,{type:"button",variant:"ghost",size:"icon","aria-label":"Create new secret",onClick:()=>{const z=r.getValues(f)?.trim()??"";d(z)},children:n.jsx(xt,{className:"size-3.5"})})}),n.jsx(Te,{children:"Create new secret"})]})]})}),e[24]=i,e[25]=r,e[26]=s,e[27]=f,e[28]=b,e[29]=d,e[30]=h,e[31]=p,e[32]=l,e[33]=m,e[34]=S):S=e[34];let k;e[35]!==r||e[36]!==f||e[37]!==b||e[38]!==c||e[39]!==m?(k=b==="literal"?n.jsxs(Re,{children:[n.jsx(Ee,{asChild:!0,children:n.jsx(re,{type:"button",variant:"ghost",size:"icon","aria-label":"Save value as secret",onClick:()=>{const z=r.getValues(f)?.trim()??"",W=r.getValues(m)??"";c(z,W)},children:n.jsx(If,{className:"size-3.5"})})}),n.jsx(Te,{children:"Save value as secret"})]}):null,e[35]=r,e[36]=f,e[37]=b,e[38]=c,e[39]=m,e[40]=k):k=e[40];let I;e[41]===Symbol.for("react.memo_cache_sentinel")?(I=n.jsx(qs,{className:"size-3.5"}),e[41]=I):I=e[41];let N;e[42]!==u?(N=n.jsx(Ee,{asChild:!0,children:n.jsx(re,{type:"button",variant:"ghost",size:"icon","aria-label":"Remove env var",onClick:u,children:I})}),e[42]=u,e[43]=N):N=e[43];let A;e[44]===Symbol.for("react.memo_cache_sentinel")?(A=n.jsx(Te,{children:"Remove"}),e[44]=A):A=e[44];let M;e[45]!==N?(M=n.jsxs(Re,{children:[N,A]}),e[45]=N,e[46]=M):M=e[46];let D;e[47]!==k||e[48]!==M?(D=n.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[k,M]}),e[47]=k,e[48]=M,e[49]=D):D=e[49];let $;return e[50]!==S||e[51]!==D||e[52]!==C||e[53]!==T?($=n.jsxs("div",{className:"flex flex-col gap-2 p-2 sm:flex-row sm:items-center",children:[C,T,S,D]}),e[50]=S,e[51]=D,e[52]=C,e[53]=T,e[54]=$):$=e[54],$}function Gg(t){return n.jsx(ot,{value:t.id,children:n.jsxs("span",{className:"inline-flex items-center gap-2",children:[n.jsx(Kh,{scope:t.scope}),n.jsx("span",{className:"font-mono",children:t.name})]})},t.id)}function Yg(t){const e=K.c(12),{field:s,secretById:i}=t,r=s.value||"";if(!r)return null;let o;e[0]!==r||e[1]!==i?(o=i.get(r),e[0]=r,e[1]=i,e[2]=o):o=e[2];const a=o;if(!a){let d;return e[3]!==r?(d=n.jsxs("span",{className:"text-destructive",children:["Missing secret (",r,")"]}),e[3]=r,e[4]=d):d=e[4],d}let l;e[5]!==a.scope?(l=n.jsx(Kh,{scope:a.scope}),e[5]=a.scope,e[6]=l):l=e[6];let h;e[7]!==a.name?(h=n.jsx("span",{className:"truncate font-mono",children:a.name}),e[7]=a.name,e[8]=h):h=e[8];let c;return e[9]!==l||e[10]!==h?(c=n.jsxs("span",{className:"inline-flex items-center gap-1.5 truncate",children:[l,h]}),e[9]=l,e[10]=h,e[11]=c):c=e[11],c}function Kh(t){const e=K.c(2),{scope:s}=t,i=s==="user"?Wm:ta;let r;return e[0]!==i?(r=n.jsx(i,{className:"size-3 text-muted-foreground"}),e[0]=i,e[1]=r):r=e[1],r}function Xg({mode:t,onClose:e,onSaved:s}){const i=t.kind==="save-literal"?t.presetValue:"",r=t.presetKey,[o,a]=E.useState(()=>Jg(r)),[l,h]=E.useState("organization"),[c,d]=E.useState(i),[u,f]=E.useState(""),m=Km(),p=o.trim(),_=c.length>0&&p.length>0&&Fg.test(p),g=async x=>{if(x.preventDefault(),!!_)try{const y=await m.mutateAsync({scope:l,name:p,value:c,description:u.trim()||void 0});le.success(`Saved secret "${y.name}"`),s(y.id)}catch(y){le.error(y instanceof Error?y.message:"Failed to save")}},v=t.kind==="save-literal"?"Save value as secret":"Create new secret",b=t.kind==="save-literal"?"Move this value into the encrypted vault. The env var will then reference the secret by id — its value never leaves the server.":"Stored encrypted in the credential vault. The env var will reference the new secret by id.";return n.jsx(Lt,{open:!0,onOpenChange:x=>{x||e()},children:n.jsxs(Ot,{className:"sm:max-w-md",children:[n.jsxs(is,{children:[n.jsx(rs,{children:v}),n.jsx(Jo,{children:b})]}),n.jsxs("form",{onSubmit:g,className:"space-y-4",children:[n.jsxs("div",{className:"space-y-1.5",children:[n.jsx(jt,{htmlFor:"save-secret-scope",children:"Scope"}),n.jsxs(It,{value:l,onValueChange:x=>h(x),children:[n.jsx(Pt,{id:"save-secret-scope",children:n.jsx(Dt,{})}),n.jsxs(At,{children:[n.jsx(ot,{value:"organization",children:"Organization — visible to all members"}),n.jsx(ot,{value:"user",children:"Private — only visible to me"})]})]})]}),n.jsxs("div",{className:"space-y-1.5",children:[n.jsx(jt,{htmlFor:"save-secret-name",children:"Name"}),n.jsx(qe,{id:"save-secret-name",value:o,onChange:x=>a(x.target.value),placeholder:"STRIPE_API_KEY",autoComplete:"off",required:!0}),n.jsx("p",{className:"text-xs text-muted-foreground",children:"Letters, digits, underscore, dot, hyphen. Independent of the env var key."})]}),n.jsxs("div",{className:"space-y-1.5",children:[n.jsx(jt,{htmlFor:"save-secret-value",children:"Value"}),n.jsx(qe,{id:"save-secret-value",type:"password",value:c,onChange:x=>d(x.target.value),placeholder:"secret value",autoComplete:"new-password",required:!0})]}),n.jsxs("div",{className:"space-y-1.5",children:[n.jsx(jt,{htmlFor:"save-secret-description",children:"Description (optional)"}),n.jsx(Tr,{id:"save-secret-description",value:u,onChange:x=>f(x.target.value),rows:2,placeholder:"What is this secret used for?"})]}),n.jsxs(ii,{children:[n.jsx(re,{type:"button",variant:"outline",onClick:e,disabled:m.isPending,children:"Cancel"}),n.jsx(re,{type:"submit",disabled:!_||m.isPending,children:m.isPending?"Saving…":"Save secret"})]})]})]})})}function fl(t){if(!Array.isArray(t))return[];const e=[];for(const s of t){if(!s||typeof s!="object")continue;const i=s,r=(i.key??"").trim();if(!(!r||!Xr.test(r))){if(i.kind==="literal"){e.push({key:r,kind:"literal",value:i.value??""});continue}i.kind==="secret"&&i.secretId&&e.push({key:r,kind:"secret",secretId:i.secretId})}}return e}function Jg(t){const e=t.trim();return e&&Xr.test(e)?e:""}function Zg(t){const e=K.c(12),{repo:s,className:i}=t;let r;e[0]!==i?(r=he("space-y-2",i),e[0]=i,e[1]=r):r=e[1];let o;e[2]===Symbol.for("react.memo_cache_sentinel")?(o=n.jsx(jt,{children:"Repository"}),e[2]=o):o=e[2];let a;e[3]===Symbol.for("react.memo_cache_sentinel")?(a=n.jsx(Vm,{size:20,className:"shrink-0 text-foreground/60"}),e[3]=a):a=e[3];let l;e[4]!==s?(l=n.jsx(Ee,{asChild:!0,children:n.jsxs("div",{className:"flex items-center gap-3 rounded-lg border border-border bg-background px-4 py-3",tabIndex:0,children:[a,n.jsx("div",{className:"min-w-0 flex-1",children:s?n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"truncate text-sm font-medium",children:[s.owner,"/",s.name]}),n.jsx("div",{className:"truncate text-xs text-muted-foreground",children:s.url})]}):n.jsx("div",{className:"text-sm text-muted-foreground",children:"No repository connected"})})]})}),e[4]=s,e[5]=l):l=e[5];let h;e[6]===Symbol.for("react.memo_cache_sentinel")?(h=n.jsx(Te,{children:"The connected GitHub repository for this agent. Manage in Connections."}),e[6]=h):h=e[6];let c;e[7]!==l?(c=n.jsxs(Re,{children:[l,h]}),e[7]=l,e[8]=c):c=e[8];let d;return e[9]!==r||e[10]!==c?(d=n.jsxs("div",{className:r,children:[o,c]}),e[9]=r,e[10]=c,e[11]=d):d=e[11],d}const Qg={npm:{install:"npm install",run:t=>`npm run ${t}`,runtime:"node"},pnpm:{install:"pnpm install",run:t=>`pnpm run ${t}`,runtime:"node"},yarn:{install:"yarn install",run:t=>`yarn run ${t}`,runtime:"node"},bun:{install:"bun install",run:t=>`bun run ${t}`,runtime:"bun"},deno:{install:"deno install",run:t=>`deno task ${t}`,runtime:"deno"}};function ev(t){const e=t.trim();if(e==="")return{ok:!0,value:null};if(!/^\d+$/.test(e))return{ok:!1};const s=Number(e);return s<1||s>65535?{ok:!1}:{ok:!0,value:String(s)}}const tv=Object.keys(Qg),xn="__none__";function sv(t){const e=K.c(20),{control:s}=t,i=E.useRef(null);let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=n.jsx(jt,{htmlFor:"runtime-pm",children:"Package manager"}),e[0]=r):r=e[0];let o;e[1]!==s?(o=n.jsxs("div",{className:"space-y-2",children:[r,n.jsx(vt,{control:s,name:"metadata.runtime.selected",render:rv})]}),e[1]=s,e[2]=o):o=e[2];let a;e[3]===Symbol.for("react.memo_cache_sentinel")?(a=n.jsx(jt,{htmlFor:"runtime-path",children:"Package path"}),e[3]=a):a=e[3];let l;e[4]!==s?(l=n.jsx(vt,{control:s,name:"metadata.runtime.path",render:iv}),e[4]=s,e[5]=l):l=e[5];let h;e[6]===Symbol.for("react.memo_cache_sentinel")?(h=n.jsx("p",{className:"text-xs text-muted-foreground",children:"Path (relative to repo root) to the directory containing package.json. Leave blank for the repo root."}),e[6]=h):h=e[6];let c;e[7]!==l?(c=n.jsxs("div",{className:"space-y-2",children:[a,l,h]}),e[7]=l,e[8]=c):c=e[8];let d;e[9]===Symbol.for("react.memo_cache_sentinel")?(d=n.jsx(jt,{htmlFor:"runtime-port",children:"Dev server port"}),e[9]=d):d=e[9];let u;e[10]===Symbol.for("react.memo_cache_sentinel")?(u=g=>{const{field:v}=g;return n.jsx(qe,{ref:i,id:"runtime-port",inputMode:"numeric",placeholder:"Auto",defaultValue:v.value??"",onBlur:b=>{const x=ev(b.target.value);x.ok?v.onChange(x.value):i.current&&(i.current.value=v.value??"")}})},e[10]=u):u=e[10];let f;e[11]!==s?(f=n.jsx(vt,{control:s,name:"metadata.runtime.port",render:u}),e[11]=s,e[12]=f):f=e[12];let m;e[13]===Symbol.for("react.memo_cache_sentinel")?(m=n.jsx("p",{className:"text-xs text-muted-foreground",children:"Leave blank to let the runner pick."}),e[13]=m):m=e[13];let p;e[14]!==f?(p=n.jsxs("div",{className:"space-y-2",children:[d,f,m]}),e[14]=f,e[15]=p):p=e[15];let _;return e[16]!==p||e[17]!==o||e[18]!==c?(_=n.jsxs("div",{className:"space-y-5",children:[o,c,p]}),e[16]=p,e[17]=o,e[18]=c,e[19]=_):_=e[19],_}function iv(t){const{field:e}=t;return n.jsx(qe,{id:"runtime-path",placeholder:".",defaultValue:e.value??"",onBlur:s=>{const i=s.target.value.trim();e.onChange(i===""?null:i)}})}function rv(t){const{field:e}=t;return n.jsxs(It,{value:e.value??xn,onValueChange:s=>e.onChange(s===xn?null:s),children:[n.jsx(Pt,{id:"runtime-pm",children:n.jsx(Dt,{placeholder:"Auto-detect"})}),n.jsxs(At,{children:[n.jsx(ot,{value:xn,children:"Auto-detect"}),tv.map(nv)]})]})}function nv(t){return n.jsx(ot,{value:t,children:t},t)}function ov(t,e){switch(e.type){case"SET_SHARE_DIALOG_OPEN":return{...t,shareDialogOpen:e.payload};case"SET_ADD_DIALOG_OPEN":return{...t,addDialogOpen:e.payload};case"OPEN_SETTINGS":return{...t,settingsDialogOpen:!0,settingsConnectionId:e.payload};case"CLOSE_SETTINGS":return{...t,settingsDialogOpen:!1,settingsConnectionId:null};default:return t}}function av(t,e){switch(e.type){case"accumulate":{const s=t??{start:e.now,fields:new Set,saveCount:0,instructionsLength:null},i=new Set(s.fields);for(const r of e.fields)i.add(r);return{...s,fields:i,saveCount:s.saveCount+1,instructionsLength:e.instructionsLength??s.instructionsLength}}case"reset":return null}}function lv(t){const e=t.metadata?.runtime?.env;if(!e||e.length===0)return t;const s=e.filter(i=>{if(!i||typeof i!="object")return!1;const r=(i.key??"").trim();return!r||!Xr.test(r)?!1:i.kind==="literal"?!0:i.kind==="secret"?!!i.secretId:!1});return s.length===e.length?t:{...t,metadata:{...t.metadata,runtime:{...t.metadata?.runtime??{},env:s}}}}function cv(t){const e=K.c(23),{connection_id:s,usedConnectionIds:i,onOpenSettings:r,onRemove:o,onAuthenticate:a,onSwitchInstance:l,onNewInstance:h}=t,c=Go(s),{org:d}=Pe();if(!c)return null;let u;e[0]!==c?(u=Bm(c),e[0]=c,e[1]=u):u=e[1];const f=u;let m;e[2]!==s?(m=n.jsx(fv,{connection_id:s}),e[2]=s,e[3]=m):m=e[3];let p;e[4]!==c.app_name||e[5]!==c.connection_type||e[6]!==c.description||e[7]!==c.icon||e[8]!==c.status||e[9]!==c.title||e[10]!==s||e[11]!==a||e[12]!==h||e[13]!==r||e[14]!==o||e[15]!==l||e[16]!==d.slug||e[17]!==f||e[18]!==i?(p=n.jsx(uv,{connection_id:s,connectionTitle:c.title,connectionDescription:c.description,connectionIcon:c.icon,connectionType:c.connection_type,connectionStatus:c.status,slug:f,orgSlug:d.slug,appName:c.app_name,usedConnectionIds:i,onOpenSettings:r,onRemove:o,onAuthenticate:a,onSwitchInstance:l,onNewInstance:h}),e[4]=c.app_name,e[5]=c.connection_type,e[6]=c.description,e[7]=c.icon,e[8]=c.status,e[9]=c.title,e[10]=s,e[11]=a,e[12]=h,e[13]=r,e[14]=o,e[15]=l,e[16]=d.slug,e[17]=f,e[18]=i,e[19]=p):p=e[19];let _;return e[20]!==m||e[21]!==p?(_=n.jsx(E.Suspense,{fallback:m,children:p}),e[20]=m,e[21]=p,e[22]=_):_=e[22],_}const ml="__new_instance__";async function hv(t,e){const s=t?.idToken??null;if(s){const r=pl(s);if(r)return r}const i=t?.userinfoEndpoint??null;if(i)try{const r=await fetch(i,{headers:{Authorization:`Bearer ${e}`}});if(r.ok){const o=await r.json(),a=typeof o.email=="string"?o.email:typeof o.upn=="string"?o.upn:typeof o.preferred_username=="string"?o.preferred_username:null;if(a)return a}}catch{}return pl(e)}function pl(t){try{const e=t.split(".");if(e.length===3&&e[1]){const s=JSON.parse(atob(e[1].replace(/-/g,"+").replace(/_/g,"/")));if(typeof s.email=="string")return s.email;if(typeof s.upn=="string")return s.upn;if(typeof s.preferred_username=="string")return s.preferred_username}}catch{}return null}function dv(t){const e=K.c(23),{appName:s,connectionId:i,usedConnectionIds:r,onSwitchInstance:o,onNewInstance:a}=t;let l;e[0]!==s?(l={filters:[{column:"app_name",value:s}]},e[0]=s,e[1]=l):l=e[1];const h=Vi(l);if(h.length<=1)return null;let c;e[2]!==i||e[3]!==a||e[4]!==o?(c=_=>{_===ml?a?.():o(i,_)},e[2]=i,e[3]=a,e[4]=o,e[5]=c):c=e[5];let d;e[6]===Symbol.for("react.memo_cache_sentinel")?(d=n.jsx(Pt,{size:"sm",className:"w-auto text-xs gap-1 px-2 shadow-none",children:n.jsx(Dt,{})}),e[6]=d):d=e[6];let u;if(e[7]!==i||e[8]!==h||e[9]!==r){let _;e[11]!==i||e[12]!==r?(_=g=>n.jsx(ot,{value:g.id,className:"text-xs",disabled:g.id!==i&&r.has(g.id),children:g.title},g.id),e[11]=i,e[12]=r,e[13]=_):_=e[13],u=h.map(_),e[7]=i,e[8]=h,e[9]=r,e[10]=u}else u=e[10];let f;e[14]!==a?(f=a&&n.jsx(ot,{value:ml,className:"text-xs text-muted-foreground",children:"+ New instance"}),e[14]=a,e[15]=f):f=e[15];let m;e[16]!==u||e[17]!==f?(m=n.jsxs(At,{children:[u,f]}),e[16]=u,e[17]=f,e[18]=m):m=e[18];let p;return e[19]!==i||e[20]!==c||e[21]!==m?(p=n.jsxs(It,{value:i,onValueChange:c,children:[d,m]}),e[19]=i,e[20]=c,e[21]=m,e[22]=p):p=e[22],p}function uv({connection_id:t,connectionTitle:e,connectionDescription:s,connectionIcon:i,connectionType:r,connectionStatus:o,slug:a,orgSlug:l,appName:h,usedConnectionIds:c,onOpenSettings:d,onRemove:u,onAuthenticate:f,onSwitchInstance:m,onNewInstance:p}){const _=ah({connectionId:t}),g=ih(),b=!(r==="VIRTUAL")&&_.supportsOAuth&&!_.isAuthenticated,x=o!=="active",y=async w=>{try{await g.update.mutateAsync({id:t,data:{status:w}}),le.success(w==="active"?"Connection enabled":"Connection disabled")}catch{le.error("Failed to update connection")}};return n.jsxs("div",{className:he("rounded-xl border overflow-hidden transition-colors",b||x?"border-destructive/50 bg-destructive/5":"border-border bg-card"),children:[n.jsxs(Uu,{to:"/$org/settings/connections/$appSlug",params:{org:l,appSlug:a},className:"flex items-center gap-3 px-4 py-3 cursor-pointer hover:bg-muted/50 transition-colors",children:[n.jsx(Gt,{icon:i,name:e,size:"sm",className:"shrink-0"}),n.jsxs("div",{className:"flex-1 min-w-0",children:[n.jsx("p",{className:"text-sm font-medium truncate",children:e}),b?n.jsx("span",{className:"text-xs text-destructive font-medium",children:"Needs authorization"}):x?n.jsx("span",{className:"text-xs text-destructive font-medium",children:o==="error"?"Disabled (error)":"Disabled"}):s&&n.jsx("p",{className:"text-xs text-muted-foreground truncate",children:s})]}),b?n.jsx(re,{variant:"outline",size:"sm",className:"h-7 text-xs shrink-0",onClick:w=>{w.preventDefault(),w.stopPropagation(),f(t)},children:"Authorize"}):x?n.jsxs(re,{variant:"outline",size:"sm",className:"h-7 text-xs gap-1.5 shrink-0",onClick:w=>{w.preventDefault(),w.stopPropagation(),y("active")},children:[n.jsx(Mf,{size:13}),"Enable"]}):n.jsxs(Re,{delayDuration:0,children:[n.jsx(Ee,{asChild:!0,children:n.jsx("span",{className:"inline-flex items-center justify-center rounded-md h-7 w-7 hover:bg-accent text-muted-foreground shrink-0 transition-colors",children:n.jsx(Mm,{size:16})})}),n.jsx(Te,{side:"bottom",children:"Connection settings"})]})]}),n.jsxs("div",{className:"flex items-center gap-3 px-4 py-2 border-t border-border bg-muted/25",children:[h&&n.jsx(dv,{appName:h,connectionId:t,usedConnectionIds:c,onSwitchInstance:m,onNewInstance:p}),n.jsxs("div",{className:"flex items-center gap-0.5 ml-auto",children:[n.jsxs(Re,{delayDuration:0,children:[n.jsx(Ee,{asChild:!0,children:n.jsx(re,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:d,"aria-label":"Configure resources",children:n.jsx(Lf,{size:13})})}),n.jsx(Te,{side:"bottom",children:"Configure resources"})]}),!x&&n.jsxs(Re,{delayDuration:0,children:[n.jsx(Ee,{asChild:!0,children:n.jsx(re,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground",onClick:()=>y("inactive"),"aria-label":"Disable connection",children:n.jsx(Of,{size:13})})}),n.jsx(Te,{side:"bottom",children:"Disable"})]}),n.jsxs(Re,{delayDuration:0,children:[n.jsx(Ee,{asChild:!0,children:n.jsx(re,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-destructive",onClick:u,"aria-label":"Remove connection",children:n.jsx(ps,{size:13})})}),n.jsx(Te,{side:"bottom",children:"Remove"})]})]})]})]})}function fv(t){const e=K.c(17),{connection_id:s}=t,i=Go(s);if(!i){let u;return e[0]===Symbol.for("react.memo_cache_sentinel")?(u=n.jsx(Vh,{}),e[0]=u):u=e[0],u}let r;e[1]!==i.icon||e[2]!==i.title?(r=n.jsx(Gt,{icon:i.icon,name:i.title,size:"sm",className:"shrink-0"}),e[1]=i.icon,e[2]=i.title,e[3]=r):r=e[3];let o;e[4]!==i.title?(o=n.jsx("p",{className:"text-sm font-medium truncate",children:i.title}),e[4]=i.title,e[5]=o):o=e[5];let a;e[6]!==i.description?(a=i.description&&n.jsx("p",{className:"text-xs text-muted-foreground truncate",children:i.description}),e[6]=i.description,e[7]=a):a=e[7];let l;e[8]!==o||e[9]!==a?(l=n.jsxs("div",{className:"flex-1 min-w-0",children:[o,a]}),e[8]=o,e[9]=a,e[10]=l):l=e[10];let h;e[11]!==r||e[12]!==l?(h=n.jsxs("div",{className:"flex items-center gap-3 px-4 py-3",children:[r,l]}),e[11]=r,e[12]=l,e[13]=h):h=e[13];let c;e[14]===Symbol.for("react.memo_cache_sentinel")?(c=n.jsx("div",{className:"flex items-center px-4 py-2 border-t border-border bg-muted/25",children:n.jsx("div",{className:"h-5 w-20 rounded bg-muted animate-pulse"})}),e[14]=c):c=e[14];let d;return e[15]!==h?(d=n.jsxs("div",{className:"rounded-xl border border-border overflow-hidden",children:[h,c]}),e[15]=h,e[16]=d):d=e[16],d}function Vh(){const t=K.c(3);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=n.jsx("div",{className:"size-8 rounded-md bg-muted animate-pulse shrink-0"}),t[0]=e):e=t[0];let s;t[1]===Symbol.for("react.memo_cache_sentinel")?(s=n.jsxs("div",{className:"flex items-center gap-3 px-4 py-3",children:[e,n.jsxs("div",{className:"flex-1 space-y-1.5",children:[n.jsx("div",{className:"h-4 w-32 rounded bg-muted animate-pulse"}),n.jsx("div",{className:"h-3 w-48 rounded bg-muted animate-pulse"})]})]}),t[1]=s):s=t[1];let i;return t[2]===Symbol.for("react.memo_cache_sentinel")?(i=n.jsxs("div",{className:"rounded-xl border border-border overflow-hidden",children:[s,n.jsx("div",{className:"flex items-center px-4 py-2 border-t border-border bg-muted/25",children:n.jsx("div",{className:"h-5 w-20 rounded bg-muted animate-pulse"})})]}),t[2]=i):i=t[2],i}function mv({virtualMcpId:t,form:e,flushAndSave:s}){const i=qi(),r=Mt(t),o=(r?.connections??[]).map(S=>S.connection_id).sort(),{data:a}=Zs({queryKey:Bt.projectConnectionDetails(t,o),enabled:o.length>0,queryFn:async()=>await Promise.all(o.map(async k=>{try{const{item:I}=await i.call("COLLECTION_CONNECTIONS_GET",{id:k}),N=(I?.tools??[]).flatMap(A=>{const M=Am(A._meta);return M?[{name:A.name,title:A.title,description:A.description,resourceUri:M}]:[]});return{fetchOk:!0,id:k,title:I?.title??k,icon:I?.icon??null,uiTools:N}}catch{return{fetchOk:!1,id:k,title:k,icon:null,uiTools:[]}}}))}),l=(a??[]).filter(S=>S.uiTools.length>0),h=new Set(im),c=e.watch("metadata.ui.pinnedViews")??[],d=e.watch("metadata.ui.layout")??null,u=d?.defaultMainView??null,f=d?.chatDefaultOpen??!1,m=!u||u.type==="chat"?"chat":u.type==="instructions"||u.type==="connections"||u.type==="layout"?"settings":h.has(u.type)?u.type:`${u.type}:${u.id??""}:${u.toolName??""}`,p=S=>{const[k,I,N]=S.split(":");return k?k==="chat"?{type:k}:h.has(k)?{type:k}:k==="ext-apps"&&I?{type:"ext-apps",id:I,toolName:N||void 0}:null:null},_=S=>{e.setValue("metadata.ui.pinnedViews",S,{shouldDirty:!0})},g=S=>{e.setValue("metadata.ui.layout",{...d,...S},{shouldDirty:!0})},v=E.useRef(!1);if(a&&a.length>0&&!v.current){v.current=!0;const S=new Set((a??[]).filter(N=>N.fetchOk).map(N=>N.id)),k=new Set(l.flatMap(N=>N.uiTools.map(A=>`${N.id}:${A.name}`))),I=c.filter(N=>!S.has(N.connectionId)||k.has(`${N.connectionId}:${N.toolName}`));I.length!==c.length&&(_(I),u?.type==="ext-apps"&&!I.some(N=>N.connectionId===u.id&&N.toolName===u.toolName)&&g({defaultMainView:{type:"chat"}}))}const b=(S,k)=>{if(c.some(N=>N.connectionId===S&&N.toolName===k)){const N=c.filter(M=>!(M.connectionId===S&&M.toolName===k));_(N);const A=`ext-apps:${S}:${k}`;m===A&&g({defaultMainView:{type:"chat"}})}else{const N=l.find(A=>A.id===S)?.uiTools.find(A=>A.name===k)?.title;_([...c,{connectionId:S,toolName:k,label:N??Wa(k),icon:null}])}s()},x=(S,k,I)=>{_(c.map(N=>N.connectionId===S&&N.toolName===k?{...N,label:I}:N))},y=()=>{s()},w=(S,k,I)=>{_(c.map(N=>N.connectionId===S&&N.toolName===k?{...N,icon:I}:N)),s()},C=S=>{g({defaultMainView:p(S)}),s()},j=o.length===0,R=a&&l.length===0,B=ti(r?.metadata),P=[{value:"chat",label:"Chat"},{value:"settings",label:"Settings"},{value:"automations",label:"Automations"}];B&&P.push({value:"preview",label:"Preview"});for(const S of c)P.push({value:`ext-apps:${S.connectionId}:${S.toolName}`,label:S.label||S.toolName});const T=l.length>0||j||R;return n.jsxs("div",{className:"flex flex-col gap-3",children:[n.jsx("div",{className:"flex items-center justify-between gap-3",children:n.jsx("h2",{className:"text-sm font-medium text-foreground",children:"Layout"})}),n.jsxs(ch,{className:"p-6 gap-5",children:[n.jsxs(qn,{className:"p-0 space-y-5",children:[n.jsxs("div",{className:"flex items-center justify-between gap-4",children:[n.jsxs("div",{className:"space-y-0.5 min-w-0",children:[n.jsx(jt,{className:"font-normal text-foreground",children:"Main view"}),n.jsx("p",{className:"text-xs text-muted-foreground",children:"What users see when they first open this agent."})]}),n.jsxs(It,{value:m,onValueChange:C,children:[n.jsx(Pt,{className:"w-44 h-8 text-sm capitalize shrink-0",children:n.jsx(Dt,{})}),n.jsx(At,{children:P.map(S=>n.jsx(ot,{value:S.value,className:"capitalize",children:S.label},S.value))})]})]}),n.jsxs("div",{className:"flex items-center justify-between gap-4",children:[n.jsxs("div",{className:"space-y-0.5 min-w-0",children:[n.jsx(jt,{className:"font-normal text-foreground",children:"Show chat"}),n.jsx("p",{className:"text-xs text-muted-foreground",children:"Display the chat panel alongside the main view."})]}),n.jsxs(Re,{delayDuration:0,children:[n.jsx(Ee,{asChild:!0,children:n.jsx("span",{className:"shrink-0",children:n.jsx(Or,{checked:m==="chat"?!0:f,disabled:m==="chat",onCheckedChange:S=>{g({chatDefaultOpen:S}),s()}})})}),m==="chat"&&n.jsx(Te,{side:"top",children:"Chat is always shown when it is the default view"})]})]})]}),T&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"border-t border-border -mx-6"}),n.jsxs(qn,{className:"p-0 space-y-3",children:[n.jsx("div",{className:"flex items-center justify-between gap-4",children:n.jsxs("div",{className:"space-y-0.5 min-w-0",children:[n.jsx(jt,{className:"font-normal text-foreground",children:"Pinned views"}),n.jsx("p",{className:"text-xs text-muted-foreground",children:"Surface interactive tools as top-level tabs in the agent."})]})}),j&&n.jsx("p",{className:"text-xs text-muted-foreground",children:"Add a connection above to configure pinned views."}),R&&!j&&n.jsx("p",{className:"text-xs text-muted-foreground",children:"None of the connected servers expose interactive tools."}),l.length>0&&n.jsx("div",{className:"space-y-4 pt-1",children:l.map((S,k)=>n.jsxs("div",{children:[k>0&&n.jsx("div",{className:"border-t border-border -mx-6 mb-4"}),n.jsxs("div",{className:"flex items-center gap-2 mb-2.5",children:[n.jsx(Gt,{icon:S.icon,name:S.title,size:"xs",className:"shrink-0"}),n.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:S.title})]}),n.jsx("div",{className:"space-y-1.5",children:S.uiTools.map(I=>{const N=c.some(M=>M.connectionId===S.id&&M.toolName===I.name),A=c.find(M=>M.connectionId===S.id&&M.toolName===I.name);return n.jsxs("div",{className:he("flex items-center justify-between gap-3 px-3 py-2 rounded-lg border transition-colors",N?"bg-accent/40 border-border":"bg-transparent border-border"),children:[n.jsxs("div",{className:"min-w-0 flex-1 flex items-center gap-2",children:[n.jsx(tg,{value:A?.icon??null,onChange:M=>w(S.id,I.name,M),disabled:!N}),n.jsx(qe,{value:N&&A?A.label:I.title??Wa(I.name),onChange:M=>x(S.id,I.name,M.target.value),onBlur:y,className:"h-7 text-sm w-40",disabled:!N,readOnly:!N})]}),n.jsx(Or,{checked:N,onCheckedChange:()=>b(S.id,I.name)})]},I.name)})})]},S.id))})]})]})]})]})}function pv({virtualMcp:t,hideOwnTitle:e}){const{org:s}=Pe(),i=ef(),{data:r}=tf([t.id]),o=r?.get(t.id)?.last_used_at,a=ih(),l=Qs(),h=qi(),c=Mc({resolver:Hu(jg),defaultValues:t}),d=c.watch("connections"),u=Lc(t),f=si(t),m=f?{owner:f.owner,name:f.name,url:f.url}:null,[p,_]=E.useReducer(ov,{shareDialogOpen:!1,addDialogOpen:!1,settingsDialogOpen:!1,settingsConnectionId:null}),[g,v]=E.useState(!1),[b,x]=E.useState(!1),{createNewTask:y,setChatOpen:w}=Uo(),{sendMessage:C}=Ns(),j=async()=>{if(b)return;const L=c.getValues("metadata.instructions");if(L?.trim()){x(!0);try{k(),De("agent_instructions_improve_clicked",{agent_id:t.id,instructions_length:L.length}),w(!0),await C({tiptapDoc:Uh({managerAgentId:Oc.AGENT_MANAGER(s.id),managerName:"Agent Manager",kind:"agent",id:t.id,instructions:L})})}finally{x(!1)}}},R=()=>{k(),De("agent_test_clicked",{agent_id:t.id}),y()},[B,P]=E.useReducer(av,null),T=()=>{B!==null&&(De("agent_updated",{agent_id:t.id,fields:Array.from(B.fields),instructions_length:B.instructionsLength,save_count:B.saveCount,edit_duration_ms:Date.now()-B.start}),P({type:"reset"}))},{schedule:S,flush:k}=$r({delayMs:3e4,save:async()=>T()}),I=async()=>{const L=Object.keys(c.control._formState.dirtyFields);if(L.length===0)return;const se=L.includes("metadata"),ee=c.getValues();c.reset(ee,{keepValues:!0});const Q=lv(ee);await i.update.mutateAsync({id:t.id,data:Q}),P({type:"accumulate",now:Date.now(),fields:L,instructionsLength:se?ee.metadata?.instructions?.length??0:null}),S()},{schedule:N,flush:A}=$r({save:I});E.useEffect(()=>{const L=c.watch(()=>N());return()=>L.unsubscribe()},[]);const M=()=>{De("connections_dialog_opened",{source:"agent_settings",mode:"add"}),_({type:"SET_ADD_DIALOG_OPEN",payload:!0})},D=async L=>{const se=c.getValues("connections");if(se.some(O=>O.connection_id===L))return;c.setValue("connections",[...se,{connection_id:L,selected_tools:vn.tools,selected_resources:vn.resources,selected_prompts:vn.prompts}],{shouldDirty:!0}),_({type:"SET_ADD_DIALOG_OPEN",payload:!1});const ee=new URL(`/api/${s.slug}/mcp/${L}`,window.location.origin),Q=await Fa({url:ee.href,token:null,orgId:s.id});Q.supportsOAuth&&!Q.isAuthenticated&&await V(L)},$=L=>{const ee=c.getValues("connections").filter(Q=>Q.connection_id!==L);c.setValue("connections",ee,{shouldDirty:!0})},z=(L,se)=>{const ee=c.getValues("connections");if(ee.some(Q=>Q.connection_id===se)){le.error("This instance is already added to the agent");return}c.setValue("connections",ee.map(Q=>Q.connection_id===L?{...Q,connection_id:se}:Q),{shouldDirty:!0})},W=async L=>{if(c.getValues("connections").find(ee=>ee.connection_id===L))try{const{item:ee}=await h.call("COLLECTION_CONNECTIONS_GET",{id:L});if(!ee)return;const Q=ee.title.replace(/\s*\(.*?\)\s*$/,""),O=Dm("conn"),ce=`${Q} (${Date.now().toString(36).slice(-4)})`;await a.create.mutateAsync({id:O,title:ce,description:ee.description??null,connection_type:ee.connection_type,connection_url:ee.connection_url??null,connection_token:null,icon:ee.icon??null,app_name:ee.app_name??null,app_id:ee.app_id??null,connection_headers:ee.connection_headers??null});const ue=new URL(`/api/${s.slug}/mcp/${O}`,window.location.origin),fe=await Fa({url:ue.href,token:null,orgId:s.id});if(fe.supportsOAuth&&!fe.isAuthenticated){const q=await V(O);if(!q){await a.delete.mutateAsync(O);return}await a.update.mutateAsync({id:O,data:{title:`${Q} (${q})`}})}z(L,O),le.success("New instance created")}catch(ee){console.error("Failed to create instance:",ee),le.error("Failed to create instance")}},F=L=>{_({type:"OPEN_SETTINGS",payload:L})},V=async L=>{const{token:se,tokenInfo:ee,error:Q}=await Wu({connectionId:L,orgSlug:s.slug,scope:"offline_access"});if(Q||!se)return le.error(`Authentication failed: ${Q}`),null;if(ee)try{const ce=await fetch(`/api/${s.slug}/connections/${L}/oauth-token`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({accessToken:ee.accessToken,refreshToken:ee.refreshToken,expiresIn:ee.expiresIn,scope:ee.scope,clientId:ee.clientId,clientSecret:ee.clientSecret,tokenEndpoint:ee.tokenEndpoint})});if(!ce.ok)console.error("Failed to save OAuth token:",await ce.text()),await a.update.mutateAsync({id:L,data:{connection_token:se}});else try{await a.update.mutateAsync({id:L,data:{}})}catch(ue){console.warn("Failed to refresh connection tools after OAuth:",ue)}}catch(ce){console.error("Error saving OAuth token:",ce),await a.update.mutateAsync({id:L,data:{connection_token:se}})}else await a.update.mutateAsync({id:L,data:{connection_token:se}});const O=new URL(`/api/${s.slug}/mcp/${L}`,window.location.origin);return await l.invalidateQueries({queryKey:Bt.isMCPAuthenticated(O.href,null)}),le.success("Authentication successful"),hv(ee,se)},J=()=>{const L=c.getValues("metadata.instructions")??"",se=`<role>
|
|
11
11
|
Define who this agent is and what it specializes in.
|
|
12
12
|
Example: You are a support triage agent for B2B merchants.
|
|
13
13
|
</role>
|
|
@@ -34,7 +34,7 @@ Define step-by-step how the agent should handle requests.
|
|
|
34
34
|
4. Ask for confirmation before making any changes.
|
|
35
35
|
</workflows>`,ee=L.trim()?`${L}
|
|
36
36
|
|
|
37
|
-
${se}`:se;c.setValue("metadata.instructions",ee,{shouldDirty:!0})},Y=new Set(d.map(L=>L.connection_id)),U=ts(),[H,X]=E.useState(!1),oe=async()=>{k();try{await i.delete.mutateAsync(t.id),De("agent_deleted",{agent_id:t.id,source:"agent_detail"}),le.success(`Deleted "${t.title}"`),U({to:"/$org",params:{org:s.slug}})}catch{}};return n.jsxs(Rt,{children:[n.jsx(Rt.Content,{children:n.jsx(Rt.Body,{children:n.jsxs("div",{className:"flex flex-col gap-10",children:[!e&&n.jsx(Rt.Title,{actions:n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs(re,{variant:"outline",size:"sm",onClick:R,children:[n.jsx(Vs,{size:14,className:"size-[14px]!"}),"Test Agent"]}),n.jsx(re,{variant:"ghost",size:"icon",className:"text-muted-foreground hover:text-destructive",onClick:()=>X(!0),children:n.jsx(qs,{size:14})})]}),children:"Settings"}),n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx(vt,{name:"icon",control:c.control,render:({field:L})=>n.jsx(G_,{value:L.value??null,onChange:se=>{L.onChange(se),A()},onColorChange:se=>{c.setValue("metadata.ui.themeColor",se,{shouldDirty:!0}),A()},name:c.watch("title")||"Agent",size:"md",className:"shrink-0",avatarClassName:"[&_svg]:w-1/2 [&_svg]:h-1/2"})}),n.jsxs("div",{className:"flex flex-col flex-1 min-w-0",children:[n.jsx(vt,{name:"title",control:c.control,render:({field:L})=>n.jsx("input",{...L,type:"text",value:L.value??"",onChange:se=>{L.onChange(se)},onBlur:()=>{L.onBlur(),A()},disabled:u,placeholder:"Agent name",className:"text-lg font-medium leading-tight text-foreground bg-transparent border-none outline-none px-1 -mx-1 rounded hover:bg-input/25 focus:bg-input/25 transition-colors w-full truncate disabled:hover:bg-transparent disabled:focus:bg-transparent disabled:opacity-50"})}),n.jsx(vt,{name:"description",control:c.control,render:({field:L})=>n.jsx("input",{...L,type:"text",value:L.value??"",onChange:se=>{L.onChange(se)},onBlur:()=>{L.onBlur(),A()},disabled:u,placeholder:"Add a description...",className:"text-sm text-muted-foreground bg-transparent border-none outline-none px-1 -mx-1 rounded hover:bg-input/25 focus:bg-input/25 transition-colors w-full truncate disabled:hover:bg-transparent disabled:focus:bg-transparent disabled:opacity-50"})})]}),n.jsxs(re,{variant:"outline",size:"sm",className:"shrink-0",onClick:()=>{De("agent_connect_modal_opened",{agent_id:t.id}),_({type:"SET_SHARE_DIALOG_OPEN",payload:!0})},children:[n.jsxs("span",{className:"flex items-center -space-x-1.5 mr-0.5",children:[n.jsx("span",{className:"inline-flex items-center justify-center size-4 rounded-full bg-black ring-1 ring-white/20 shrink-0",children:n.jsx("img",{src:"/logos/cursor.svg",alt:"Cursor",className:"size-2.5 brightness-0 invert"})}),n.jsx("span",{className:"relative z-10 inline-flex items-center justify-center size-4 rounded-full ring-1 ring-background shrink-0",style:{backgroundColor:"#D97757"},children:n.jsx("img",{src:"/logos/Claude Code.svg",alt:"Claude",className:"size-2.5 brightness-0 invert"})})]}),"Connect"]})]}),n.jsxs("div",{className:"flex items-center gap-2 -mt-6 text-sm text-muted-foreground",children:[n.jsx(oh,{id:t.created_by,size:"2xs",className:"text-sm text-muted-foreground"}),n.jsx("span",{className:"text-muted-foreground/50",children:"·"}),n.jsxs("span",{children:["Created"," ",new Date(t.created_at).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})]}),n.jsx("span",{className:"text-muted-foreground/50",children:"·"}),n.jsx("span",{children:o?`Last used ${qm(new Date(o),{addSuffix:!0})}`:"Never used"})]}),n.jsxs("section",{className:"flex flex-col gap-3",children:[n.jsxs("div",{className:"flex items-center justify-between gap-3",children:[n.jsx("h2",{className:"text-sm font-medium text-foreground",children:"Connections"}),d.length>0&&n.jsxs(re,{variant:"outline",size:"sm",onClick:M,children:[n.jsx(xt,{size:14}),"Add connection"]})]}),n.jsx("div",{className:"flex flex-col gap-2",children:d.length===0?n.jsxs("button",{type:"button",onClick:M,className:"flex items-center gap-3 px-3 py-2.5 rounded-lg border border-dashed border-border hover:bg-accent/50 transition-colors w-full text-left cursor-pointer",children:[n.jsx("div",{className:"flex items-center justify-center size-8 rounded-md text-muted-foreground/75 border border-dashed border-border shrink-0",children:n.jsx(xt,{size:16})}),n.jsx("span",{className:"text-sm text-muted-foreground",children:"No connections yet. Add one to get started."})]}):d.map(L=>n.jsx(Ut,{fallback:()=>null,children:n.jsx(E.Suspense,{fallback:n.jsx(Vh,{}),children:n.jsx(cv,{connection_id:L.connection_id,usedConnectionIds:Y,onOpenSettings:()=>F(L.connection_id),onRemove:()=>$(L.connection_id),onAuthenticate:V,onSwitchInstance:z,onNewInstance:()=>W(L.connection_id)})})},L.connection_id))})]}),n.jsxs("section",{className:"flex flex-col gap-3",children:[n.jsxs("div",{className:"flex items-center justify-between gap-3",children:[n.jsx("h2",{className:"text-sm font-medium text-foreground",children:"Instructions"}),!u&&n.jsxs("div",{className:"flex items-center gap-2",children:[!c.watch("metadata.instructions")?.trim()&&n.jsx(re,{variant:"outline",size:"sm",onClick:J,children:"+ Prompt template"}),n.jsxs(re,{variant:"outline",size:"sm",disabled:b||!c.watch("metadata.instructions")?.trim(),onClick:j,children:[n.jsx(Ss,{size:13}),"Improve"]})]})]}),n.jsx(vt,{name:"metadata.instructions",control:c.control,render:({field:L})=>n.jsxs("div",{className:"relative rounded-xl card-shadow bg-card focus-within:ring-1 focus-within:ring-ring",children:[n.jsx(Tr,{...L,value:L.value??"",onChange:se=>{L.onChange(se)},onBlur:()=>{L.onBlur(),A()},disabled:u,placeholder:"Define how this agent should behave, what tone to use, any constraints or guidelines...",className:"min-h-[200px] max-h-[360px] overflow-auto resize-none text-base text-muted-foreground placeholder:text-muted-foreground/40 leading-relaxed border-0 shadow-none px-4 py-3 pr-11 focus-visible:ring-0 focus-visible:ring-offset-0 bg-transparent",style:{boxShadow:"none"}}),n.jsxs(Re,{delayDuration:0,children:[n.jsx(Ee,{asChild:!0,children:n.jsx(re,{type:"button",variant:"ghost",size:"icon",className:"absolute top-2 right-2 h-7 w-7 text-muted-foreground",onClick:()=>v(!0),"aria-label":"Open fullscreen editor",children:n.jsx(If,{size:14})})}),n.jsx(Te,{side:"left",children:"Fullscreen"})]})]})})]}),n.jsx(rg,{form:c}),n.jsx(Ut,{fallback:()=>null,children:n.jsx(E.Suspense,{fallback:n.jsxs("section",{className:"flex flex-col gap-3",children:[n.jsx("h2",{className:"text-sm font-medium text-foreground",children:"Sub-agents"}),n.jsx("div",{className:"h-16 rounded-lg border border-dashed border-border animate-pulse"})]}),children:n.jsx(dg,{form:c,currentAgentId:t.id})})}),n.jsx(mv,{virtualMcpId:t.id,form:c,flushAndSave:A}),n.jsxs("div",{className:"flex flex-col gap-3",children:[n.jsx("div",{className:"flex items-center justify-between gap-3",children:n.jsx("h2",{className:"text-sm font-medium text-foreground",children:"Sandbox"})}),n.jsx(ch,{className:"p-6 gap-5",children:n.jsxs(qn,{className:"p-0 space-y-5",children:[n.jsx(Zg,{repo:m}),n.jsx(sv,{control:c.control}),n.jsx(Hg,{control:c.control,form:c,virtualMcpId:t.id,orgSlug:s.slug})]})})]}),n.jsxs("section",{className:"flex items-center justify-between border-t border-border pt-6",children:[n.jsxs("div",{children:[n.jsx("p",{className:"text-sm font-medium",children:"Delete agent"}),n.jsx("p",{className:"text-sm text-muted-foreground",children:"Permanently delete this agent and all its data."})]}),n.jsxs(re,{variant:"outline",size:"sm",className:"text-destructive border-destructive/40 hover:bg-destructive/10 hover:text-destructive shrink-0",onClick:()=>X(!0),children:[n.jsx(qs,{size:14}),"Delete agent"]})]})]})})}),n.jsx(Rr,{open:H,onOpenChange:X,children:n.jsxs(Pr,{children:[n.jsxs(Dr,{children:[n.jsx(Ar,{children:"Delete Agent?"}),n.jsxs(Ir,{children:["This action cannot be undone. This will permanently delete"," ",n.jsx("span",{className:"font-medium text-foreground",children:t.title}),"."]})]}),n.jsxs(Br,{children:[n.jsx(Mr,{children:"Cancel"}),n.jsx(Lr,{onClick:oe,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete"})]})]})}),n.jsx(am,{open:p.addDialogOpen,onOpenChange:L=>_({type:"SET_ADD_DIALOG_OPEN",payload:L}),agentId:t.id,addedConnectionIds:Y,onAdd:D}),n.jsx(kg,{open:p.settingsDialogOpen,onOpenChange:L=>{L||_({type:"CLOSE_SETTINGS"})},selectedId:p.settingsConnectionId,form:c,connections:d,onAuthenticate:V}),n.jsx(Og,{open:p.shareDialogOpen,onOpenChange:L=>_({type:"SET_SHARE_DIALOG_OPEN",payload:L}),virtualMcp:t}),n.jsx(Lt,{open:g,onOpenChange:v,children:n.jsxs(Ot,{className:"w-[90vw] sm:max-w-6xl h-[85vh] flex flex-col p-0 gap-0",children:[n.jsx(is,{className:"px-6 pt-6 pb-3 border-b border-border shrink-0",children:n.jsx(rs,{children:"Instructions"})}),n.jsx("div",{className:"flex-1 min-h-0 p-6",children:n.jsx(vt,{name:"metadata.instructions",control:c.control,render:({field:L})=>n.jsx(Tr,{...L,value:L.value??"",onChange:se=>{L.onChange(se)},onBlur:()=>{L.onBlur(),A()},disabled:u,placeholder:"Define how this agent should behave, what tone to use, any constraints or guidelines...",className:"w-full h-full resize-none text-base text-muted-foreground placeholder:text-muted-foreground/40 leading-relaxed rounded-xl card-shadow px-4 py-3 focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-0 bg-card border-0",style:{boxShadow:"none"}})})})]})})]})}function _v(t){const e=K.c(9),{virtualMcpId:s,hideOwnTitle:i}=t,r=ts(),{org:o}=Pe(),a=Mt(s);if(!a){let c;return e[0]!==r||e[1]!==o.slug?(c=n.jsx("div",{className:"flex h-full w-full bg-background",children:n.jsx(Er,{title:"Space not found",description:"This space may have been deleted or you may not have access.",actions:n.jsx(re,{variant:"outline",onClick:()=>r({to:"/$org",params:{org:o.slug}}),children:"Back to spaces"})})}),e[0]=r,e[1]=o.slug,e[2]=c):c=e[2],c}let l;e[3]!==a?(l=si(a)?.connectionId??"",e[3]=a,e[4]=l):l=e[4];let h;return e[5]!==i||e[6]!==l||e[7]!==a?(h=n.jsx(pv,{virtualMcp:a,hideOwnTitle:i},l),e[5]=i,e[6]=l,e[7]=a,e[8]=h):h=e[8],h}function _l(t){const e=K.c(2),{virtualMcpId:s}=t;let i;return e[0]!==s?(i=n.jsx(_v,{virtualMcpId:s,hideOwnTitle:!0}),e[0]=s,e[1]=i):i=e[1],i}const gv={amp:"&",lt:"<",gt:">",quot:'"',apos:"'",nbsp:" "};function zi(t){return t?t.replace(/&(#x?[0-9a-fA-F]+|[a-zA-Z]+);/g,(e,s)=>{if(s.startsWith("#x")||s.startsWith("#X")){const i=Number.parseInt(s.slice(2),16);return Number.isFinite(i)?String.fromCodePoint(i):e}if(s.startsWith("#")){const i=Number.parseInt(s.slice(1),10);return Number.isFinite(i)?String.fromCodePoint(i):e}return gv[s]??e}):""}const vv=10;function xv(t){const e=t;if(e.isError)return null;const s=e.content?.find(r=>r.type==="resource"),i=s?.resource?.text??s?.text;if(!i)return null;try{const r=JSON.parse(i);return typeof r=="string"?r:r&&typeof r=="object"&&"content"in r&&typeof r.content=="string"?r.content:JSON.stringify(r,null,2)}catch{return i}}async function nr(t,e,s){try{const i=await t.callTool({name:"get_file_contents",arguments:{owner:e.owner,repo:e.repo,path:e.path,...s}});return xv(i)}catch{return null}}function bv(t){const e=Bs(t);return Array.isArray(e)?e.map(s=>{const i=Number(s.additions??0),r=Number(s.changes??i),o=Number(s.deletions??Math.max(0,r-i));return{filename:String(s.filename??""),status:s.status??"modified",additions:i,deletions:o,blobUrl:typeof s.blob_url=="string"?s.blob_url:null}}):[]}async function yv(t,e,s){if(t.length===0)return;let i=0;async function r(){for(;i<t.length;){const o=i++;await s(t[o])}}await Promise.all(Array.from({length:Math.min(e,t.length)},()=>r()))}async function gl(t,e){const s=await t.callTool({name:"pull_request_read",arguments:{method:"get_files",owner:e.owner,repo:e.repo,pullNumber:e.pullNumber,perPage:100}}),i=bv(s).filter(a=>a.filename.length>0),r={},o=e.mergeBaseSha?{sha:e.mergeBaseSha}:{ref:e.base};return await yv(i,vv,async a=>{const l=a.filename;if(a.status==="added"){r[l]={from:null,to:await nr(t,{owner:e.owner,repo:e.repo,path:l},{sha:e.headSha})};return}if(a.status==="removed"){r[l]={from:await nr(t,{owner:e.owner,repo:e.repo,path:l},o),to:null};return}const[h,c]=await Promise.all([nr(t,{owner:e.owner,repo:e.repo,path:l},o),nr(t,{owner:e.owner,repo:e.repo,path:l},{sha:e.headSha})]);r[l]={from:h,to:c}}),{diffs:r}}function qh(t){return t?Object.keys(t.diffs).length:0}function oi(t,e,s,i){return`/api/${t}/sandbox/${encodeURIComponent(e)}/${encodeURIComponent(s)}/git/${i}`}class Gh extends Error{constructor(e,s){super(e),this.status=s,this.name="SandboxGitError"}status}function ya(t){return t instanceof Gh&&(t.status===503||t.status===410||t.status===404)}async function ai(t){const e=await t.json();if(!t.ok)throw new Gh(typeof e.error=="string"?e.error:`Request failed (${t.status})`,t.status);return e}function li(t,e){return fetch(t,{cache:"no-store",...e})}async function br(t,e,s){const i=await li(oi(t,e,s,"status"));return ai(i)}async function Yh(t,e,s,i){const r=i?.base||i?.headSha?{...i.base?{base:i.base}:{},...i.headSha?{headSha:i.headSha}:{}}:void 0,o=await li(oi(t,e,s,"diff"),{method:"POST",headers:r?{"content-type":"application/json"}:void 0,body:r?JSON.stringify(r):void 0});return ai(o)}async function vl(t,e,s,i){const r=await li(oi(t,e,s,"suggest-commit"),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(i??{})});return ai(r)}async function bn(t,e,s,i){const r=await li(oi(t,e,s,"publish"),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({message:i})});await ai(r)}async function Sv(t,e,s,i){const r=await li(oi(t,e,s,"rebase"),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({base:i})});await ai(r)}function wv(t){return t==="blocks.gen.json"||t.endsWith("/blocks.gen.json")}function xl(t){if(!t)return!1;const e=Object.keys(t.diffs);return e.length===0?!1:e.every(s=>s===".deco"||s.startsWith(".deco/")||wv(s))}const Cv="Code changes can't be published directly — use Submit for review";async function bl(t,e,s,i){const r=await li(oi(t,e,s,"discard"),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({filepaths:i})});await ai(r)}const kv="current";function Sa(t){return t?.[kv]??null}function jv(t,e,s){return["sandbox-git-status",t,e,s]}function Xh(t){return t?t.modified.length+t.created.length+t.deleted.length+t.not_added.length+t.renamed.length:0}function Jh(t){return t?Xh(t)>0||t.staged.length>0||t.conflicted.length>0:!1}function Zh(t){return t?Jh(t)||t.ahead>0||(t.unpushed??0)>0?!0:t.unpushed===void 0&&(t.aheadOfBase??0)>0&&t.tracking==null:!1}function Nv(t,e){return t?Zh(t)||e!=null&&Object.keys(e.diffs).length>0:!1}function Ev(t){return Math.max(t.unpushed??0,t.ahead)}function Tv(t){return t.aheadOfBase??0}function Rv(t){return t.behindBase??0}function Pv(t,e){if(!e)return t;const s=Jh(e),i=Sa(e),r=Ev(e),o=Tv(e),a=Rv(e),l=e.base??"main",h=e.headSha??"";return t.kind==="ready"?{...t,branch:i??t.branch,base:e.base??t.base,workingTreeDirty:s,unpushed:Math.max(t.unpushed,r),aheadOfBase:Math.max(t.aheadOfBase,o),behindBase:e.behindBase!==void 0?Math.max(t.behindBase,a):t.behindBase,headSha:h||t.headSha}:!s&&o===0&&r===0?t:{kind:"ready",branch:i??"",base:l,workingTreeDirty:s,unpushed:r,aheadOfBase:o,behindBase:a,headSha:h}}function Dv(t,e,s,i,r,o,a){return["pr-diff",t,e,s,i,r,o,a]}function Av(t){const e=K.c(26),{orgSlug:s,orgId:i,virtualMcpId:r,branch:o,base:a,headSha:l,pullNumber:h,connectionId:c,owner:d,repo:u,enabled:f}=t,m=f===void 0?!0:f;let p;e[0]!==c||e[1]!==i||e[2]!==s?(p={connectionId:c,orgId:i,orgSlug:s},e[0]=c,e[1]=i,e[2]=s,e[3]=p):p=e[3];const _=ft(p);let g;e[4]!==a||e[5]!==o||e[6]!==c||e[7]!==l||e[8]!==s||e[9]!==h||e[10]!==r?(g=Dv(s,r,o,a,l,h,c),e[4]=a,e[5]=o,e[6]=c,e[7]=l,e[8]=s,e[9]=h,e[10]=r,e[11]=g):g=e[11];let v;e[12]!==a||e[13]!==o||e[14]!==_||e[15]!==l||e[16]!==s||e[17]!==d||e[18]!==h||e[19]!==u||e[20]!==r?(v=async()=>{try{const y=await Yh(s,r,o,{base:a,headSha:l});return qh(y)>0?y:gl(_,{owner:d,repo:u,pullNumber:h,base:a,headSha:l,mergeBaseSha:y.mergeBaseSha})}catch{return gl(_,{owner:d,repo:u,pullNumber:h,base:a,headSha:l})}},e[12]=a,e[13]=o,e[14]=_,e[15]=l,e[16]=s,e[17]=d,e[18]=h,e[19]=u,e[20]=r,e[21]=v):v=e[21];const b=m&&!!o&&!!l&&!!c;let x;return e[22]!==g||e[23]!==v||e[24]!==b?(x={queryKey:g,queryFn:v,enabled:b,refetchInterval:3e4,staleTime:1e4},e[22]=g,e[23]=v,e[24]=b,e[25]=x):x=e[25],Zs(x)}Tm.config({paths:{vs:"https://cdn.jsdelivr.net/npm/monaco-editor@0.52.0/min/vs"}});function Iv(){return document.documentElement.classList.contains("dark")?"vs-dark":"vs"}function Qh(t){const e=K.c(9),{diff:s,emptyMessage:i,rowClassName:r,onDiscardFile:o}=t,a=i===void 0?"No file changes in the working tree":i,l=r===void 0?"px-6":r,[h,c]=E.useState(null),[d,u]=E.useState(null);let f;e[0]===Symbol.for("react.memo_cache_sentinel")?(f=Iv(),e[0]=f):f=e[0];const m=f;if(!s||Object.keys(s.diffs).length===0){let _;return e[1]!==a?(_=n.jsx("div",{className:"flex items-center justify-center py-10 text-sm text-muted-foreground",children:a}),e[1]=a,e[2]=_):_=e[2],_}let p;return e[3]!==s.diffs||e[4]!==d||e[5]!==h||e[6]!==o||e[7]!==l?(p=n.jsx("div",{className:"divide-y",children:Object.entries(s.diffs).map(_=>{const[g,v]=_,{from:b,to:x}=v,y=h===g,w=b===null,C=x===null,j=g.startsWith("/")?g.slice(1):g,R=j.lastIndexOf("/"),B=R>=0?j.slice(R+1):j,P=R>=0?j.slice(0,R):null,T=vm(g),S=w?"bg-green-500":C?"bg-red-500":"bg-amber-500";return n.jsxs("div",{children:[n.jsxs("div",{className:he("flex items-center gap-3 py-3 hover:bg-muted/30",l),children:[n.jsx("button",{type:"button",className:"flex h-4 w-4 shrink-0 items-center justify-center text-muted-foreground transition-transform hover:text-foreground",onClick:()=>c(y?null:g),children:n.jsx(Pm,{className:he("h-3.5 w-3.5 transition-transform",y&&"rotate-90")})}),n.jsx("div",{className:he("h-2.5 w-2.5 shrink-0 rounded-full",S)}),n.jsx(nh,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),n.jsx("span",{className:"min-w-0 flex-1 truncate text-sm font-medium",children:B}),P&&n.jsx("span",{className:"shrink-0 text-xs text-muted-foreground",children:P}),o?n.jsxs(Ds,{children:[n.jsx(As,{asChild:!0,children:n.jsx("button",{type:"button",className:"flex h-6 w-6 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-foreground",children:n.jsx(tn,{className:"h-3.5 w-3.5"})})}),n.jsx(Is,{align:"end",children:n.jsx(He,{className:"text-destructive focus:text-destructive",onSelect:()=>u(g),children:"Discard changes"})})]}):null]}),d===g&&o?n.jsxs("div",{className:he("flex items-center justify-between gap-3 border-t bg-destructive/5 py-2.5",l),children:[n.jsxs("span",{className:"text-xs text-destructive",children:["Discard all changes to"," ",n.jsx("span",{className:"font-medium",children:B}),"? This cannot be undone."]}),n.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[n.jsx(re,{type:"button",variant:"ghost",size:"sm",className:"h-7 px-2 text-xs",onClick:()=>u(null),children:"Cancel"}),n.jsx(re,{type:"button",size:"sm",className:"h-7 bg-destructive px-2 text-xs text-destructive-foreground hover:bg-destructive/90",onClick:()=>{u(null),o(g)},children:"Discard"})]})]}):null,y&&n.jsx("div",{className:"border-t",children:n.jsx(Rm,{original:b??"",modified:x??"",language:T,theme:m,height:"380px",options:{readOnly:!0,renderSideBySide:!1,minimap:{enabled:!1},scrollBeyondLastLine:!1,fontSize:12}})})]},g)})}),e[3]=s.diffs,e[4]=d,e[5]=h,e[6]=o,e[7]=l,e[8]=p):p=e[8],p}function Bv(t){const e=K.c(4),{diffQuery:s}=t;if(s.isLoading){let r;return e[0]===Symbol.for("react.memo_cache_sentinel")?(r=n.jsxs("div",{className:"flex items-center justify-center gap-2 py-16 text-muted-foreground",children:[n.jsx(Ce,{className:"h-4 w-4 animate-spin"}),n.jsx("span",{className:"text-sm",children:"Loading changes…"})]}),e[0]=r):r=e[0],r}if(s.isError){let r;return e[1]===Symbol.for("react.memo_cache_sentinel")?(r=n.jsx("div",{className:"py-10 text-sm text-destructive",children:"Couldn't load PR changes."}),e[1]=r):r=e[1],r}let i;return e[2]!==s.data?(i=n.jsx(Qh,{diff:s.data,rowClassName:"px-0",emptyMessage:"No committed changes in this pull request"}),e[2]=s.data,e[3]=i):i=e[3],i}const Ms="The user clicked this action deliberately — execute directly. Do not call user_ask unless you hit an actual problem outside the scope of this intent (missing auth, unresolvable conflict, a check with multiple plausible fixes).";function Mv(t){return`Reopen PR #${t.prNumber}. ${Ms}`}function Lv(t){return`Rebase \`${t.branch}\` on the latest base and force-push with --force-with-lease. ${Ms}`}function Ov(t){return`Re-run the \`${t.checkName}\` check on PR #${t.prNumber}. If an empty commit is needed to retrigger CI, create and push one. ${Ms}`}function $v(t){const e=(t.failingChecks??[]).map(s=>`\`${s}\``).join(", ");return`PR #${t.prNumber} has failing checks: ${e}. For each: read the logs, diagnose the root cause, apply the smallest fix that makes it pass, commit, and push. ${Ms}`}function zv(t){return`Mark PR #${t.prNumber} ready for review. ${Ms}`}function Fv(t){return`Read the unresolved review threads on PR #${t.prNumber}. For each thread: understand the reviewer's ask, apply the needed changes, commit, push, reply explaining what changed, and resolve the thread. If a comment is a question that doesn't need a code change, reply with the answer and resolve. ${Ms}`}function Hv(t){return`Review PR #${t.prNumber}. Read the full diff, analyze every changed file for correctness, security, code quality, and alignment with the repo's patterns. Post specific line-level review comments on concerns, then submit an overall review (approve / request changes / comment) with a concise summary. Do not modify the code — this is a read-and-comment pass. ${Ms}`}function Wv(t){const e=K.c(24),{pr:s,connectionId:i,owner:r,repo:o}=t,{org:a}=Pe(),l=Ns();let h;e[0]!==i||e[1]!==a.id||e[2]!==a.slug||e[3]!==r||e[4]!==s.number||e[5]!==o?(h={orgId:a.id,orgSlug:a.slug,connectionId:i,owner:r,repo:o,prNumber:s.number},e[0]=i,e[1]=a.id,e[2]=a.slug,e[3]=r,e[4]=s.number,e[5]=o,e[6]=h):h=e[6];const c=kh(h);let d;e[7]!==l||e[8]!==s.number?(d=g=>l.sendMessage({parts:[{type:"text",text:Ov({prNumber:s.number,checkName:g})}]}),e[7]=l,e[8]=s.number,e[9]=d):d=e[9];const u=d;if(c.isLoading){let g;return e[10]===Symbol.for("react.memo_cache_sentinel")?(g=n.jsx("div",{className:"text-sm text-muted-foreground",children:"Loading checks…"}),e[10]=g):g=e[10],g}if(c.isError){let g;return e[11]===Symbol.for("react.memo_cache_sentinel")?(g=n.jsx("div",{className:"text-sm text-destructive",children:"Couldn't load check runs."}),e[11]=g):g=e[11],g}let f;e[12]!==c.data?(f=c.data??[],e[12]=c.data,e[13]=f):f=e[13];const m=f;if(m.length===0){let g;return e[14]===Symbol.for("react.memo_cache_sentinel")?(g=n.jsx("div",{className:"text-sm text-muted-foreground",children:"No check runs on the PR head commit."}),e[14]=g):g=e[14],g}let p;if(e[15]!==l||e[16]!==m||e[17]!==u){let g;e[19]!==l||e[20]!==u?(g=v=>n.jsxs("li",{className:"flex items-center justify-between gap-2 rounded px-2 py-1.5 text-sm hover:bg-muted",children:[n.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[n.jsx(Uv,{check:v}),n.jsx("span",{className:"truncate",children:v.name}),v.durationMs!=null&&n.jsx("span",{className:"text-xs text-muted-foreground",children:Kv(v.durationMs)})]}),n.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[v.htmlUrl&&n.jsx("a",{href:v.htmlUrl,target:"_blank",rel:"noreferrer",className:"inline-flex h-7 items-center justify-center rounded px-2 text-xs text-muted-foreground hover:bg-background",title:"View run",children:n.jsx(ni,{className:"h-3.5 w-3.5"})}),v.conclusion==="failure"&&n.jsx(re,{size:"sm",variant:"ghost",disabled:l.isStreaming,onClick:()=>u(v.name),children:"Re-run"})]})]},v.id),e[19]=l,e[20]=u,e[21]=g):g=e[21],p=m.map(g),e[15]=l,e[16]=m,e[17]=u,e[18]=p}else p=e[18];let _;return e[22]!==p?(_=n.jsx("ul",{className:"flex flex-col gap-0.5",children:p}),e[22]=p,e[23]=_):_=e[23],_}function Uv(t){const e=K.c(5),{check:s}=t;if(s.status!=="completed"){let o;return e[0]===Symbol.for("react.memo_cache_sentinel")?(o=n.jsx("span",{className:"text-muted-foreground","aria-label":"In progress",children:"○"}),e[0]=o):o=e[0],o}if(s.conclusion==="success"){let o;return e[1]===Symbol.for("react.memo_cache_sentinel")?(o=n.jsx("span",{className:"text-success","aria-label":"Success",children:"✓"}),e[1]=o):o=e[1],o}if(s.conclusion==="failure"){let o;return e[2]===Symbol.for("react.memo_cache_sentinel")?(o=n.jsx("span",{className:"text-destructive","aria-label":"Failure",children:"✗"}),e[2]=o):o=e[2],o}const i=s.conclusion??"—";let r;return e[3]!==i?(r=n.jsx("span",{className:"text-muted-foreground","aria-label":i,children:"—"}),e[3]=i,e[4]=r):r=e[4],r}function Kv(t){const e=Math.round(t/1e3);return e<60?`${e}s`:`${Math.round(e/60)}m`}function Vv(t){const e=K.c(10),{comments:s,isLoading:i,isError:r}=t;if(i||r||!s||s.length===0)return null;const o=s.length===1?"":"s";let a;e[0]!==s.length||e[1]!==o?(a=n.jsxs(Gm,{className:"py-3 text-sm font-medium",children:[s.length," comment",o]}),e[0]=s.length,e[1]=o,e[2]=a):a=e[2];let l;e[3]!==s?(l=s.map(qv),e[3]=s,e[4]=l):l=e[4];let h;e[5]!==l?(h=n.jsx(Ym,{className:"space-y-3 pb-3",children:l}),e[5]=l,e[6]=h):h=e[6];let c;return e[7]!==a||e[8]!==h?(c=n.jsx(Xm,{type:"single",collapsible:!0,className:"border-t border-border",children:n.jsxs(Jm,{value:"comments",className:"border-b-0",children:[a,h]})}),e[7]=a,e[8]=h,e[9]=c):c=e[9],c}function qv(t){return n.jsxs("div",{className:"rounded-md border border-border p-3",children:[n.jsxs("div",{className:"mb-1 text-xs text-muted-foreground",children:["@",t.author," · ",Gv(t.createdAt)]}),n.jsx(Yo,{id:`pr-comment-${t.id}`,text:zi(t.body)})]},t.id)}function Gv(t){if(!t)return"";const e=new Date(t).getTime();if(!Number.isFinite(e))return"";const s=Date.now()-e;if(s<0)return"just now";const i=Math.floor(s/864e5);if(i>0)return`${i}d ago`;const r=Math.floor(s/36e5);if(r>0)return`${r}h ago`;const o=Math.floor(s/6e4);return`${Math.max(1,o)}m ago`}function Yv(t){const e=K.c(19),{pr:s,connectionId:i,owner:r,repo:o}=t,{org:a}=Pe();let l;e[0]!==i||e[1]!==a.id||e[2]!==a.slug||e[3]!==r||e[4]!==s.number||e[5]!==o?(l={orgId:a.id,orgSlug:a.slug,connectionId:i,owner:r,repo:o,prNumber:s.number},e[0]=i,e[1]=a.id,e[2]=a.slug,e[3]=r,e[4]=s.number,e[5]=o,e[6]=l):l=e[6];const h=u_(l);let c;e[7]!==s.body||e[8]!==s.number?(c=s.body&&n.jsx("div",{className:"text-sm",children:n.jsx(Yo,{id:`pr-body-${s.number}`,text:zi(s.body)})}),e[7]=s.body,e[8]=s.number,e[9]=c):c=e[9];let d;e[10]!==h.data?(d=h.data??[],e[10]=h.data,e[11]=d):d=e[11];let u;e[12]!==h.isError||e[13]!==h.isLoading||e[14]!==d?(u=n.jsx(Vv,{comments:d,isLoading:h.isLoading,isError:h.isError}),e[12]=h.isError,e[13]=h.isLoading,e[14]=d,e[15]=u):u=e[15];let f;return e[16]!==c||e[17]!==u?(f=n.jsxs("div",{className:"space-y-8",children:[c,u]}),e[16]=c,e[17]=u,e[18]=f):f=e[18],f}function Xv(t){const e=K.c(68),{pr:s,virtualMcpId:i,branch:r,connectionId:o,owner:a,repo:l}=t,{org:h}=Pe();let c;e[0]!==r||e[1]!==o||e[2]!==h.id||e[3]!==h.slug||e[4]!==a||e[5]!==s.base||e[6]!==s.headSha||e[7]!==s.number||e[8]!==l||e[9]!==i?(c={orgSlug:h.slug,orgId:h.id,virtualMcpId:i,branch:r,base:s.base,headSha:s.headSha,pullNumber:s.number,connectionId:o,owner:a,repo:l},e[0]=r,e[1]=o,e[2]=h.id,e[3]=h.slug,e[4]=a,e[5]=s.base,e[6]=s.headSha,e[7]=s.number,e[8]=l,e[9]=i,e[10]=c):c=e[10];const d=Av(c);let u;e[11]!==d.data?(u=d.data?qh(d.data):void 0,e[11]=d.data,e[12]=u):u=e[12];const f=u,[m,p]=E.useState("changes");let _;e[13]!==s.title?(_=zi(s.title),e[13]=s.title,e[14]=_):_=e[14];let g;e[15]!==_?(g=n.jsx("h1",{className:"text-lg font-semibold leading-tight",children:_}),e[15]=_,e[16]=g):g=e[16];const v=`Open PR #${s.number} on GitHub`;let b;e[17]===Symbol.for("react.memo_cache_sentinel")?(b=n.jsx(ni,{className:"h-3.5 w-3.5"}),e[17]=b):b=e[17];let x;e[18]!==s.htmlUrl||e[19]!==s.number||e[20]!==v?(x=n.jsxs("a",{href:s.htmlUrl,target:"_blank",rel:"noreferrer","aria-label":v,className:"inline-flex items-center gap-1 hover:text-foreground",children:["PR #",s.number,b]}),e[18]=s.htmlUrl,e[19]=s.number,e[20]=v,e[21]=x):x=e[21];let y;e[22]!==s.author?(y=s.author?n.jsxs(n.Fragment,{children:[n.jsx("span",{children:"·"}),n.jsxs("span",{children:["@",s.author]})]}):null,e[22]=s.author,e[23]=y):y=e[23];let w;e[24]===Symbol.for("react.memo_cache_sentinel")?(w=n.jsx("span",{children:"·"}),e[24]=w):w=e[24];let C;e[25]!==s.base?(C=n.jsx("span",{className:"font-mono text-xs",children:s.base}),e[25]=s.base,e[26]=C):C=e[26];let j;e[27]===Symbol.for("react.memo_cache_sentinel")?(j=n.jsx("span",{children:"←"}),e[27]=j):j=e[27];let R;e[28]!==s.head?(R=n.jsx("span",{className:"font-mono text-xs",children:s.head}),e[28]=s.head,e[29]=R):R=e[29];let B;e[30]!==C||e[31]!==R||e[32]!==x||e[33]!==y?(B=n.jsxs("div",{className:"flex flex-wrap items-center gap-x-1.5 text-sm text-muted-foreground",children:[x,y,w,C,j,R]}),e[30]=C,e[31]=R,e[32]=x,e[33]=y,e[34]=B):B=e[34];let P;e[35]!==B||e[36]!==g?(P=n.jsx("div",{className:"shrink-0 space-y-3 pb-4",children:n.jsxs("div",{className:"space-y-1",children:[g,B]})}),e[35]=B,e[36]=g,e[37]=P):P=e[37];let T;e[38]===Symbol.for("react.memo_cache_sentinel")?(T=V=>p(V),e[38]=T):T=e[38];let S;e[39]===Symbol.for("react.memo_cache_sentinel")?(S=n.jsx(ys,{value:"description",className:"px-3 text-xs",children:"Description"}),e[39]=S):S=e[39];const k=f!==void 0?` ${f}`:"";let I;e[40]!==k?(I=n.jsxs(ys,{value:"changes",className:"px-3 text-xs",children:["Changes",k]}),e[40]=k,e[41]=I):I=e[41];let N;e[42]===Symbol.for("react.memo_cache_sentinel")?(N=n.jsx(ys,{value:"checks",className:"px-3 text-xs",children:"Checks"}),e[42]=N):N=e[42];let A;e[43]!==I?(A=n.jsxs(Zo,{className:"h-8 w-fit max-w-[600px] shrink-0",variant:"pill",children:[S,I,N]}),e[43]=I,e[44]=A):A=e[44];let M;e[45]!==o||e[46]!==a||e[47]!==s||e[48]!==l?(M=n.jsx(Ti,{value:"description",className:"mt-0",children:n.jsx(Yv,{pr:s,connectionId:o,owner:a,repo:l})}),e[45]=o,e[46]=a,e[47]=s,e[48]=l,e[49]=M):M=e[49];let D;e[50]!==d?(D=n.jsx(Ti,{value:"changes",className:"mt-0",children:n.jsx(Bv,{diffQuery:d})}),e[50]=d,e[51]=D):D=e[51];let $;e[52]!==o||e[53]!==a||e[54]!==s||e[55]!==l?($=n.jsx(Ti,{value:"checks",className:"mt-0",children:n.jsx(Wv,{pr:s,connectionId:o,owner:a,repo:l})}),e[52]=o,e[53]=a,e[54]=s,e[55]=l,e[56]=$):$=e[56];let z;e[57]!==M||e[58]!==D||e[59]!==$?(z=n.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto pt-5",children:[M,D,$]}),e[57]=M,e[58]=D,e[59]=$,e[60]=z):z=e[60];let W;e[61]!==m||e[62]!==A||e[63]!==z?(W=n.jsxs(Qo,{value:m,onValueChange:T,className:"flex min-h-0 flex-1 flex-col",children:[A,z]}),e[61]=m,e[62]=A,e[63]=z,e[64]=W):W=e[64];let F;return e[65]!==P||e[66]!==W?(F=n.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[P,W]}),e[65]=P,e[66]=W,e[67]=F):F=e[67],F}function Jv(t){const e=K.c(5),{pr:s}=t,i=`Open PR #${s.number} on GitHub`;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=n.jsx(ni,{className:"h-4 w-4 text-muted-foreground"}),e[0]=r):r=e[0];let o;return e[1]!==s.htmlUrl||e[2]!==s.number||e[3]!==i?(o=n.jsx("div",{className:"flex h-12 items-center border-b border-border px-4 shrink-0",children:n.jsxs("a",{href:s.htmlUrl,target:"_blank",rel:"noreferrer","aria-label":i,className:"inline-flex items-center gap-1.5 text-base font-medium text-foreground hover:underline",children:["PR #",s.number,r]})}),e[1]=s.htmlUrl,e[2]=s.number,e[3]=i,e[4]=o):o=e[4],o}function Zv(t){const e=K.c(10),{virtualMcpId:s}=t,{org:i}=Pe(),r=Mt(s),{currentBranch:o}=ss(),a=r?.metadata?.githubRepo??null;if(!a?.connectionId){let h;return e[0]===Symbol.for("react.memo_cache_sentinel")?(h=n.jsx("div",{className:"flex h-full items-center justify-center p-8 text-sm text-muted-foreground",children:"This virtualmcp is not linked to a GitHub repository."}),e[0]=h):h=e[0],h}if(!o){let h;return e[1]===Symbol.for("react.memo_cache_sentinel")?(h=n.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-8 text-sm",children:[n.jsx(Mi,{className:"h-6 w-6 text-muted-foreground"}),n.jsx("div",{className:"text-muted-foreground",children:"No branch selected."}),n.jsx("div",{className:"text-xs text-muted-foreground",children:"Pick a branch from the header to see PR status."})]}),e[1]=h):h=e[1],h}let l;return e[2]!==o||e[3]!==a.connectionId||e[4]!==a.name||e[5]!==a.owner||e[6]!==i.id||e[7]!==i.slug||e[8]!==s?(l=n.jsx(Qv,{orgId:i.id,orgSlug:i.slug,virtualMcpId:s,connectionId:a.connectionId,owner:a.owner,repo:a.name,branch:o}),e[2]=o,e[3]=a.connectionId,e[4]=a.name,e[5]=a.owner,e[6]=i.id,e[7]=i.slug,e[8]=s,e[9]=l):l=e[9],l}function Qv(t){const e=K.c(47),{orgId:s,orgSlug:i,virtualMcpId:r,connectionId:o,owner:a,repo:l,branch:h}=t;let c;e[0]!==h||e[1]!==o||e[2]!==s||e[3]!==i||e[4]!==a||e[5]!==l?(c={orgId:s,orgSlug:i,connectionId:o,owner:a,repo:l,branch:h},e[0]=h,e[1]=o,e[2]=s,e[3]=i,e[4]=a,e[5]=l,e[6]=c):c=e[6];const{data:d,isLoading:u,isError:f}=ca(c),m=e1;if(u){let x;return e[7]===Symbol.for("react.memo_cache_sentinel")?(x=n.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"Loading PR state…"}),e[7]=x):x=e[7],x}if(f){let x;return e[8]===Symbol.for("react.memo_cache_sentinel")?(x=n.jsx("div",{className:"p-4 text-sm text-destructive",children:"Couldn't load PR state. The GitHub connection may be broken."}),e[8]=x):x=e[8],x}const p=`https://github.com/${a}/${l}/tree/${h}`;if(d&&d.state==="closed"){let x;e[9]!==d?(x=n.jsx(Jv,{pr:d}),e[9]=d,e[10]=x):x=e[10];const y=d.merged?"✓ Merged":"✗ Closed";let w;e[11]!==d.mergedAt?(w=d.mergedAt&&n.jsxs(n.Fragment,{children:[" · ",new Date(d.mergedAt).toLocaleDateString()]}),e[11]=d.mergedAt,e[12]=w):w=e[12];let C;e[13]!==d.author?(C=d.author&&n.jsxs(n.Fragment,{children:[" · by @",d.author]}),e[13]=d.author,e[14]=C):C=e[14];let j;e[15]!==d.base||e[16]!==y||e[17]!==w||e[18]!==C?(j=n.jsxs("div",{className:"text-sm text-success",children:[y," into ",d.base,w,C]}),e[15]=d.base,e[16]=y,e[17]=w,e[18]=C,e[19]=j):j=e[19];let R;e[20]!==d.title?(R=zi(d.title),e[20]=d.title,e[21]=R):R=e[21];let B;e[22]!==R?(B=n.jsx("h1",{className:"text-lg font-semibold",children:R}),e[22]=R,e[23]=B):B=e[23];let P;e[24]!==d.body||e[25]!==d.number?(P=d.body&&n.jsx("div",{className:"rounded-md border border-border bg-muted/30 p-3 text-sm",children:n.jsx(Yo,{id:`pr-body-${d.number}`,text:zi(d.body)})}),e[24]=d.body,e[25]=d.number,e[26]=P):P=e[26];let T;e[27]!==j||e[28]!==B||e[29]!==P?(T=n.jsxs("div",{className:"flex flex-col gap-4 p-4 overflow-auto",children:[j,B,P]}),e[27]=j,e[28]=B,e[29]=P,e[30]=T):T=e[30];let S;return e[31]!==x||e[32]!==T?(S=n.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[x,T]}),e[31]=x,e[32]=T,e[33]=S):S=e[33],S}if(d&&d.state==="open"){let x;return e[34]!==h||e[35]!==o||e[36]!==a||e[37]!==d||e[38]!==l||e[39]!==r?(x=n.jsx("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden",children:n.jsx("div",{className:"flex min-h-0 w-full flex-1 flex-col px-6 py-5",children:n.jsx(Xv,{pr:d,virtualMcpId:r,branch:h,connectionId:o,owner:a,repo:l})})}),e[34]=h,e[35]=o,e[36]=a,e[37]=d,e[38]=l,e[39]=r,e[40]=x):x=e[40],x}let _;e[41]===Symbol.for("react.memo_cache_sentinel")?(_=n.jsx("div",{className:"rounded-md border border-border bg-muted/30 p-4 text-sm",children:`This branch doesn't have an open pull request. Click "Submit for review" in the header to open one; the agent will draft the title and summary from the current state of the branch.`}),e[41]=_):_=e[41];let g;e[42]!==p?(g=()=>m(p),e[42]=p,e[43]=g):g=e[43];let v;e[44]===Symbol.for("react.memo_cache_sentinel")?(v=n.jsx(ni,{className:"mr-1.5 h-4 w-4"}),e[44]=v):v=e[44];let b;return e[45]!==g?(b=n.jsxs("div",{className:"flex flex-col gap-4 p-4",children:[_,n.jsx("div",{className:"flex items-center gap-2",children:n.jsxs(re,{size:"sm",variant:"outline",onClick:g,children:[v,"Open branch on GitHub"]})})]}),e[45]=g,e[46]=b):b=e[46],b}function e1(t){window.open(t,"_blank","noopener,noreferrer")}function ed(t){return t.appPaused||t.userStopped?{kind:"suspended"}:t.previewUrl?{kind:"iframe",previewUrl:t.previewUrl}:{kind:"starting"}}function td(t){const e=Object.values(t),[s]=e;return s?e.find(i=>i.sandboxProviderKind!=="user-desktop")??s:null}function t1(t){return t.hasActiveGithubRepo&&!!t.userId&&!!t.branch&&!t.vmEntry&&!t.userStopped&&!t.isPending&&!t.attempted}function s1(t){return t.notFound&&!!t.deadVmId&&!t.isPending&&!t.userStopped&&t.deadVmId!==t.lastDeadVmId}function i1(t){switch(t.kind){case"suspended":return"suspended";case"iframe":return"running";case"starting":return"starting"}}const r1={branch:null,previewState:{kind:"starting"},status:"idle",vmEntry:null,previewUrl:null,userStopped:!1,start:()=>{},stop:async()=>{},restart:async()=>{},retry:()=>{},resume:()=>{}},sd=E.createContext(r1);function id(){return E.use(sd)}function n1({virtualMcpId:t,branch:e,userId:s,hasActiveGithubRepo:i,sandboxMap:r,children:o}){const{org:a}=Pe(),{setCurrentTaskBranch:l}=ss(),h=Yt(),c=Qs(),d=ft({connectionId:Ho,orgId:a.id,orgSlug:a.slug}),u=zo(d),{mutate:f,reset:m}=u,p=E.useRef(new Set),_=E.useRef(null),g=s&&e?Jr(r?.[s]?.[e]):{},v=td(g),b=v?.previewUrl??null,x=!!t&&!!e&&$n.isStopped(t,e),y=h.status.state==="paused",w=ed({previewUrl:b,appPaused:y,userStopped:x}),C=i1(w),j=e!==null&&p.current.has(e),R=t1({hasActiveGithubRepo:i,userId:s,branch:e,vmEntry:v,userStopped:x,isPending:u.isPending,attempted:j});E.useEffect(()=>{if(!R||!e||!t)return;p.current.add(e),f({virtualMcpId:t,branch:e},{onError:D=>{console.error("[sandbox-lifecycle] auto-start failed:",D)}})},[R,e,t,f]);const B=h.notFound?v?.sandboxHandle??null:null,P=s1({notFound:h.notFound,deadVmId:B,lastDeadVmId:_.current,isPending:u.isPending,userStopped:x});E.useEffect(()=>{if(!P||!B||!t)return;_.current=B;const M={virtualMcpId:t};e&&(M.branch=e),f(M,{onSuccess:D=>{D?.branch&&!e&&l(D.branch)},onError:D=>{console.error("[sandbox-lifecycle] self-heal failed:",D)}})},[P,B,t,e,f,l]);const T=()=>{if(!t)return;const M={virtualMcpId:t};e&&(M.branch=e),f(M,{onSuccess:D=>{D?.branch&&!e&&l(D.branch)},onError:D=>{console.error("[sandbox-lifecycle] user start failed:",D)}})},S=async()=>{if(!t||!e)return;const M=v?.sandboxProviderKind;if(M){$n.mark(t,e);try{await d.callTool({name:"SANDBOX_DELETE",arguments:{virtualMcpId:t,branch:e,sandboxProviderKind:M}})}catch{}Ku(c)}},k=async()=>{await S(),T()},I=()=>{p.current=new Set,_.current=null,m(),T()},A={branch:e,previewState:w,status:C,vmEntry:v,previewUrl:b,userStopped:x,start:T,stop:S,restart:k,retry:I,resume:I};return n.jsx(sd,{value:A,children:o})}function rd(t){return btoa(encodeURIComponent(t))}function o1(t,e,s){const i=new URL(t).origin,r=new URL(`/live/previews/${encodeURIComponent(e)}`,i);return r.searchParams.set("path","/"),r.searchParams.set("pathTemplate","/"),r.searchParams.set("props",rd(JSON.stringify({path:"/",sections:[{__resolveType:s}]}))),r.searchParams.set("__cb",crypto.randomUUID()),r.toString()}function FC(t,e,s,i){const r=new URL(t).origin,o=new URL(`/live/previews/${encodeURIComponent(e)}`,r);o.searchParams.set("__d","");const a=[{__resolveType:"preview",block:s}];return i&&a.push(i),o.searchParams.set("props",rd(JSON.stringify({sections:a}))),o.toString()}const yl={resolveType:"website/pages/Page.tsx",seoResolveType:"website/sections/Seo/SeoV2.tsx"};function wa(t){return`pages-${encodeURIComponent(t)}-${crypto.randomUUID()}`}function nd(t,e){return{name:t,path:e,sections:[],seo:{__resolveType:yl.seoResolveType},__resolveType:yl.resolveType}}const a1=700;function Ca(t){const e=K.c(21),{orgSlug:s,virtualMcpId:i,branch:r}=t,o=Qs();let a;e[0]!==r||e[1]!==s||e[2]!==i?(a=async u=>{const{blockKey:f,data:m}=u,p=rh(f),_=JSON.stringify(m,null,2),g=await fetch(`/api/${s}/sandbox/${encodeURIComponent(i)}/${encodeURIComponent(r)}/write`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({path:p,content:_})});if(!g.ok){const v=await g.json().catch(l1);throw new Error(v.error??`Write failed (${g.status})`)}return g.json()},e[0]=r,e[1]=s,e[2]=i,e[3]=a):a=e[3];let l;e[4]!==r||e[5]!==s||e[6]!==o||e[7]!==i?(l=async u=>{const{blockKey:f,data:m}=u,p=`${s}/${i}/${r}`,_=Bt.decofile(p);await o.cancelQueries({queryKey:_});const g=o.getQueryData(_);return o.setQueryData(_,v=>({...v??{},[f]:m})),{previous:g,queryKey:_}},e[4]=r,e[5]=s,e[6]=o,e[7]=i,e[8]=l):l=e[8];let h;e[9]!==o?(h=(u,f,m)=>{m?.queryKey&&o.setQueryData(m.queryKey,m.previous)},e[9]=o,e[10]=h):h=e[10];let c;e[11]!==r||e[12]!==s||e[13]!==o||e[14]!==i?(c=(u,f)=>{const{blockKey:m,data:p}=f,_=`${s}/${i}/${r}`;o.setQueryData(Bt.decofile(_),g=>({...g??{},[m]:p}))},e[11]=r,e[12]=s,e[13]=o,e[14]=i,e[15]=c):c=e[15];let d;return e[16]!==a||e[17]!==l||e[18]!==h||e[19]!==c?(d={mutationFn:a,onMutate:l,onError:h,onSuccess:c},e[16]=a,e[17]=l,e[18]=h,e[19]=c,e[20]=d):d=e[20],ei(d)}function l1(){return{}}function HC(t,e){const s=K.c(15),i=Ca(t);let r;s[0]===Symbol.for("react.memo_cache_sentinel")?(r=new Map,s[0]=r):r=s[0];const o=E.useRef(r);let a;s[1]===Symbol.for("react.memo_cache_sentinel")?(a=new Map,s[1]=a):a=s[1];const l=E.useRef(a);let h;s[2]!==e||s[3]!==i?(h=v=>{const b=o.current.get(v);if(!b)return;const x=typeof b=="function"?b():b;o.current.delete(v),x&&i.mutate({blockKey:v,data:x},{onSuccess:()=>e?.onSaved?.(),onError:c1})},s[2]=e,s[3]=i,s[4]=h):h=s[4];const c=h;let d;s[5]!==c?(d=()=>{for(const v of l.current.values())clearTimeout(v);l.current.clear();for(const v of[...o.current.keys()])c(v)},s[5]=c,s[6]=d):d=s[6];const u=d;let f,m;s[7]===Symbol.for("react.memo_cache_sentinel")?(f=()=>{const v=l.current;return()=>{for(const b of v.values())clearTimeout(b)}},m=[],s[7]=f,s[8]=m):(f=s[7],m=s[8]),E.useEffect(f,m);let p;s[9]!==c?(p=(v,b)=>{o.current.set(v,b);const x=l.current.get(v);x&&clearTimeout(x),l.current.set(v,setTimeout(()=>{l.current.delete(v),c(v)},a1))},s[9]=c,s[10]=p):p=s[10];const _=p;let g;return s[11]!==u||s[12]!==_||s[13]!==i.isPending?(g={save:_,flush:u,isPending:i.isPending},s[11]=u,s[12]=_,s[13]=i.isPending,s[14]=g):g=s[14],g}function c1(t){return le.error(`Save failed: ${t.message}`)}function h1(t){const e=K.c(5);let s;e[0]!==t?(s=t??{orgSlug:"",virtualMcpId:"",branch:""},e[0]=t,e[1]=s):s=e[1];const i=Ca(s);let r;return e[2]!==t||e[3]!==i?(r={mutationFn:async o=>{const{name:a,path:l}=o;if(!t?.virtualMcpId||!t.branch)throw new Error("Sandbox not ready");const h=wa(a),c=nd(a,l);return await i.mutateAsync({blockKey:h,data:c}),{key:h,name:a,path:l}}},e[2]=t,e[3]=i,e[4]=r):r=e[4],ei(r)}function d1(t){const e=K.c(50),{open:s,onOpenChange:i,isPending:r,error:o,onSubmit:a}=t,l=r===void 0?!1:r,[h,c]=E.useState("My New Page"),[d,u]=E.useState("/example-path"),[f,m]=E.useState(null),[p,_]=E.useState(s);s!==p&&(_(s),s&&(c("My New Page"),u("/example-path"),m(null)));let g;e[0]!==l||e[1]!==i?(g=F=>{!F&&!l&&(m(null),i(!1))},e[0]=l,e[1]=i,e[2]=g):g=e[2];const v=g;let b;e[3]!==l||e[4]!==h||e[5]!==a||e[6]!==d?(b=async F=>{F.preventDefault();const V=h.trim(),J=d.trim();if(!V||!J||l)return;const Y=pa(J);if(Y){m(Y);return}m(null),await a({name:V,path:J})},e[3]=l,e[4]=h,e[5]=a,e[6]=d,e[7]=b):b=e[7];const x=b,y=f??o;let w;e[8]===Symbol.for("react.memo_cache_sentinel")?(w=n.jsx(is,{children:n.jsx(rs,{children:"Create new page"})}),e[8]=w):w=e[8];let C;e[9]===Symbol.for("react.memo_cache_sentinel")?(C=n.jsx("label",{htmlFor:"new-page-name",className:"text-xs font-medium text-muted-foreground",children:"Name"}),e[9]=C):C=e[9];let j;e[10]===Symbol.for("react.memo_cache_sentinel")?(j=F=>c(F.target.value),e[10]=j):j=e[10];let R;e[11]!==l||e[12]!==h?(R=n.jsxs("div",{className:"space-y-1.5",children:[C,n.jsx(qe,{id:"new-page-name",value:h,onChange:j,placeholder:"My New Page",autoFocus:!0,disabled:l})]}),e[11]=l,e[12]=h,e[13]=R):R=e[13];let B;e[14]===Symbol.for("react.memo_cache_sentinel")?(B=n.jsx("label",{htmlFor:"new-page-path",className:"text-xs font-medium text-muted-foreground",children:"Path"}),e[14]=B):B=e[14];let P;e[15]===Symbol.for("react.memo_cache_sentinel")?(P=F=>u(F.target.value),e[15]=P):P=e[15];let T;e[16]!==l||e[17]!==d?(T=n.jsxs("div",{className:"space-y-1.5",children:[B,n.jsx(qe,{id:"new-page-path",value:d,onChange:P,placeholder:"/example-path",disabled:l})]}),e[16]=l,e[17]=d,e[18]=T):T=e[18];let S;e[19]!==y?(S=y&&n.jsx("p",{className:"text-xs text-destructive",children:y}),e[19]=y,e[20]=S):S=e[20];let k;e[21]!==T||e[22]!==S||e[23]!==R?(k=n.jsxs("div",{className:"space-y-4 py-4",children:[R,T,S]}),e[21]=T,e[22]=S,e[23]=R,e[24]=k):k=e[24];let I;e[25]!==i?(I=()=>i(!1),e[25]=i,e[26]=I):I=e[26];let N;e[27]!==l||e[28]!==I?(N=n.jsx(re,{type:"button",variant:"outline",onClick:I,disabled:l,children:"Cancel"}),e[27]=l,e[28]=I,e[29]=N):N=e[29];let A;e[30]!==l||e[31]!==h||e[32]!==d?(A=!h.trim()||!d.trim()||l,e[30]=l,e[31]=h,e[32]=d,e[33]=A):A=e[33];let M;e[34]!==l?(M=l?n.jsxs(n.Fragment,{children:[n.jsx(Ce,{size:14,className:"animate-spin"}),"Creating…"]}):"Create",e[34]=l,e[35]=M):M=e[35];let D;e[36]!==A||e[37]!==M?(D=n.jsx(re,{type:"submit",disabled:A,children:M}),e[36]=A,e[37]=M,e[38]=D):D=e[38];let $;e[39]!==N||e[40]!==D?($=n.jsxs(ii,{children:[N,D]}),e[39]=N,e[40]=D,e[41]=$):$=e[41];let z;e[42]!==x||e[43]!==k||e[44]!==$?(z=n.jsx(Ot,{className:"sm:max-w-md",children:n.jsxs("form",{onSubmit:x,children:[w,k,$]})}),e[42]=x,e[43]=k,e[44]=$,e[45]=z):z=e[45];let W;return e[46]!==v||e[47]!==s||e[48]!==z?(W=n.jsx(Lt,{open:s,onOpenChange:v,children:z}),e[46]=v,e[47]=s,e[48]=z,e[49]=W):W=e[49],W}const u1=_r({tag:Tt(),id:Tt(),classes:Tt(),text:Tt(),html:Tt(),manifestKey:Tt().nullable(),componentName:Tt().nullable(),parents:Tt(),url:Tt(),path:Tt(),viewport:_r({width:yi(),height:yi()}),position:_r({x:yi(),y:yi()})}),f1=`(function() {
|
|
37
|
+
${se}`:se;c.setValue("metadata.instructions",ee,{shouldDirty:!0})},Y=new Set(d.map(L=>L.connection_id)),U=ts(),[H,X]=E.useState(!1),oe=async()=>{k();try{await i.delete.mutateAsync(t.id),De("agent_deleted",{agent_id:t.id,source:"agent_detail"}),le.success(`Deleted "${t.title}"`),U({to:"/$org",params:{org:s.slug}})}catch{}};return n.jsxs(Rt,{children:[n.jsx(Rt.Content,{children:n.jsx(Rt.Body,{children:n.jsxs("div",{className:"flex flex-col gap-10",children:[!e&&n.jsx(Rt.Title,{actions:n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsxs(re,{variant:"outline",size:"sm",onClick:R,children:[n.jsx(Vs,{size:14,className:"size-[14px]!"}),"Test Agent"]}),n.jsx(re,{variant:"ghost",size:"icon",className:"text-muted-foreground hover:text-destructive",onClick:()=>X(!0),children:n.jsx(qs,{size:14})})]}),children:"Settings"}),n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx(vt,{name:"icon",control:c.control,render:({field:L})=>n.jsx(G_,{value:L.value??null,onChange:se=>{L.onChange(se),A()},onColorChange:se=>{c.setValue("metadata.ui.themeColor",se,{shouldDirty:!0}),A()},name:c.watch("title")||"Agent",size:"md",className:"shrink-0",avatarClassName:"[&_svg]:w-1/2 [&_svg]:h-1/2"})}),n.jsxs("div",{className:"flex flex-col flex-1 min-w-0",children:[n.jsx(vt,{name:"title",control:c.control,render:({field:L})=>n.jsx("input",{...L,type:"text",value:L.value??"",onChange:se=>{L.onChange(se)},onBlur:()=>{L.onBlur(),A()},disabled:u,placeholder:"Agent name",className:"text-lg font-medium leading-tight text-foreground bg-transparent border-none outline-none px-1 -mx-1 rounded hover:bg-input/25 focus:bg-input/25 transition-colors w-full truncate disabled:hover:bg-transparent disabled:focus:bg-transparent disabled:opacity-50"})}),n.jsx(vt,{name:"description",control:c.control,render:({field:L})=>n.jsx("input",{...L,type:"text",value:L.value??"",onChange:se=>{L.onChange(se)},onBlur:()=>{L.onBlur(),A()},disabled:u,placeholder:"Add a description...",className:"text-sm text-muted-foreground bg-transparent border-none outline-none px-1 -mx-1 rounded hover:bg-input/25 focus:bg-input/25 transition-colors w-full truncate disabled:hover:bg-transparent disabled:focus:bg-transparent disabled:opacity-50"})})]}),n.jsxs(re,{variant:"outline",size:"sm",className:"shrink-0",onClick:()=>{De("agent_connect_modal_opened",{agent_id:t.id}),_({type:"SET_SHARE_DIALOG_OPEN",payload:!0})},children:[n.jsxs("span",{className:"flex items-center -space-x-1.5 mr-0.5",children:[n.jsx("span",{className:"inline-flex items-center justify-center size-4 rounded-full bg-black ring-1 ring-white/20 shrink-0",children:n.jsx("img",{src:"/logos/cursor.svg",alt:"Cursor",className:"size-2.5 brightness-0 invert"})}),n.jsx("span",{className:"relative z-10 inline-flex items-center justify-center size-4 rounded-full ring-1 ring-background shrink-0",style:{backgroundColor:"#D97757"},children:n.jsx("img",{src:"/logos/Claude Code.svg",alt:"Claude",className:"size-2.5 brightness-0 invert"})})]}),"Connect"]})]}),n.jsxs("div",{className:"flex items-center gap-2 -mt-6 text-sm text-muted-foreground",children:[n.jsx(oh,{id:t.created_by,size:"2xs",className:"text-sm text-muted-foreground"}),n.jsx("span",{className:"text-muted-foreground/50",children:"·"}),n.jsxs("span",{children:["Created"," ",new Date(t.created_at).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})]}),n.jsx("span",{className:"text-muted-foreground/50",children:"·"}),n.jsx("span",{children:o?`Last used ${qm(new Date(o),{addSuffix:!0})}`:"Never used"})]}),n.jsxs("section",{className:"flex flex-col gap-3",children:[n.jsxs("div",{className:"flex items-center justify-between gap-3",children:[n.jsx("h2",{className:"text-sm font-medium text-foreground",children:"Connections"}),d.length>0&&n.jsxs(re,{variant:"outline",size:"sm",onClick:M,children:[n.jsx(xt,{size:14}),"Add connection"]})]}),n.jsx("div",{className:"flex flex-col gap-2",children:d.length===0?n.jsxs("button",{type:"button",onClick:M,className:"flex items-center gap-3 px-3 py-2.5 rounded-lg border border-dashed border-border hover:bg-accent/50 transition-colors w-full text-left cursor-pointer",children:[n.jsx("div",{className:"flex items-center justify-center size-8 rounded-md text-muted-foreground/75 border border-dashed border-border shrink-0",children:n.jsx(xt,{size:16})}),n.jsx("span",{className:"text-sm text-muted-foreground",children:"No connections yet. Add one to get started."})]}):d.map(L=>n.jsx(Ut,{fallback:()=>null,children:n.jsx(E.Suspense,{fallback:n.jsx(Vh,{}),children:n.jsx(cv,{connection_id:L.connection_id,usedConnectionIds:Y,onOpenSettings:()=>F(L.connection_id),onRemove:()=>$(L.connection_id),onAuthenticate:V,onSwitchInstance:z,onNewInstance:()=>W(L.connection_id)})})},L.connection_id))})]}),n.jsxs("section",{className:"flex flex-col gap-3",children:[n.jsxs("div",{className:"flex items-center justify-between gap-3",children:[n.jsx("h2",{className:"text-sm font-medium text-foreground",children:"Instructions"}),!u&&n.jsxs("div",{className:"flex items-center gap-2",children:[!c.watch("metadata.instructions")?.trim()&&n.jsx(re,{variant:"outline",size:"sm",onClick:J,children:"+ Prompt template"}),n.jsxs(re,{variant:"outline",size:"sm",disabled:b||!c.watch("metadata.instructions")?.trim(),onClick:j,children:[n.jsx(Ss,{size:13}),"Improve"]})]})]}),n.jsx(vt,{name:"metadata.instructions",control:c.control,render:({field:L})=>n.jsxs("div",{className:"relative rounded-xl card-shadow bg-card focus-within:ring-1 focus-within:ring-ring",children:[n.jsx(Tr,{...L,value:L.value??"",onChange:se=>{L.onChange(se)},onBlur:()=>{L.onBlur(),A()},disabled:u,placeholder:"Define how this agent should behave, what tone to use, any constraints or guidelines...",className:"min-h-[200px] max-h-[360px] overflow-auto resize-none text-base text-muted-foreground placeholder:text-muted-foreground/40 leading-relaxed border-0 shadow-none px-4 py-3 pr-11 focus-visible:ring-0 focus-visible:ring-offset-0 bg-transparent",style:{boxShadow:"none"}}),n.jsxs(Re,{delayDuration:0,children:[n.jsx(Ee,{asChild:!0,children:n.jsx(re,{type:"button",variant:"ghost",size:"icon",className:"absolute top-2 right-2 h-7 w-7 text-muted-foreground",onClick:()=>v(!0),"aria-label":"Open fullscreen editor",children:n.jsx(Bf,{size:14})})}),n.jsx(Te,{side:"left",children:"Fullscreen"})]})]})})]}),n.jsx(rg,{form:c}),n.jsx(Ut,{fallback:()=>null,children:n.jsx(E.Suspense,{fallback:n.jsxs("section",{className:"flex flex-col gap-3",children:[n.jsx("h2",{className:"text-sm font-medium text-foreground",children:"Sub-agents"}),n.jsx("div",{className:"h-16 rounded-lg border border-dashed border-border animate-pulse"})]}),children:n.jsx(dg,{form:c,currentAgentId:t.id})})}),n.jsx(mv,{virtualMcpId:t.id,form:c,flushAndSave:A}),n.jsxs("div",{className:"flex flex-col gap-3",children:[n.jsx("div",{className:"flex items-center justify-between gap-3",children:n.jsx("h2",{className:"text-sm font-medium text-foreground",children:"Sandbox"})}),n.jsx(ch,{className:"p-6 gap-5",children:n.jsxs(qn,{className:"p-0 space-y-5",children:[n.jsx(Zg,{repo:m}),n.jsx(sv,{control:c.control}),n.jsx(Hg,{control:c.control,form:c,virtualMcpId:t.id,orgSlug:s.slug})]})})]}),n.jsxs("section",{className:"flex items-center justify-between border-t border-border pt-6",children:[n.jsxs("div",{children:[n.jsx("p",{className:"text-sm font-medium",children:"Delete agent"}),n.jsx("p",{className:"text-sm text-muted-foreground",children:"Permanently delete this agent and all its data."})]}),n.jsxs(re,{variant:"outline",size:"sm",className:"text-destructive border-destructive/40 hover:bg-destructive/10 hover:text-destructive shrink-0",onClick:()=>X(!0),children:[n.jsx(qs,{size:14}),"Delete agent"]})]})]})})}),n.jsx(Rr,{open:H,onOpenChange:X,children:n.jsxs(Pr,{children:[n.jsxs(Dr,{children:[n.jsx(Ar,{children:"Delete Agent?"}),n.jsxs(Ir,{children:["This action cannot be undone. This will permanently delete"," ",n.jsx("span",{className:"font-medium text-foreground",children:t.title}),"."]})]}),n.jsxs(Br,{children:[n.jsx(Mr,{children:"Cancel"}),n.jsx(Lr,{onClick:oe,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete"})]})]})}),n.jsx(xf,{open:p.addDialogOpen,onOpenChange:L=>_({type:"SET_ADD_DIALOG_OPEN",payload:L}),agentId:t.id,addedConnectionIds:Y,onAdd:D}),n.jsx(kg,{open:p.settingsDialogOpen,onOpenChange:L=>{L||_({type:"CLOSE_SETTINGS"})},selectedId:p.settingsConnectionId,form:c,connections:d,onAuthenticate:V}),n.jsx(Og,{open:p.shareDialogOpen,onOpenChange:L=>_({type:"SET_SHARE_DIALOG_OPEN",payload:L}),virtualMcp:t}),n.jsx(Lt,{open:g,onOpenChange:v,children:n.jsxs(Ot,{className:"w-[90vw] sm:max-w-6xl h-[85vh] flex flex-col p-0 gap-0",children:[n.jsx(is,{className:"px-6 pt-6 pb-3 border-b border-border shrink-0",children:n.jsx(rs,{children:"Instructions"})}),n.jsx("div",{className:"flex-1 min-h-0 p-6",children:n.jsx(vt,{name:"metadata.instructions",control:c.control,render:({field:L})=>n.jsx(Tr,{...L,value:L.value??"",onChange:se=>{L.onChange(se)},onBlur:()=>{L.onBlur(),A()},disabled:u,placeholder:"Define how this agent should behave, what tone to use, any constraints or guidelines...",className:"w-full h-full resize-none text-base text-muted-foreground placeholder:text-muted-foreground/40 leading-relaxed rounded-xl card-shadow px-4 py-3 focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-0 bg-card border-0",style:{boxShadow:"none"}})})})]})})]})}function _v(t){const e=K.c(9),{virtualMcpId:s,hideOwnTitle:i}=t,r=ts(),{org:o}=Pe(),a=Mt(s);if(!a){let c;return e[0]!==r||e[1]!==o.slug?(c=n.jsx("div",{className:"flex h-full w-full bg-background",children:n.jsx(Er,{title:"Space not found",description:"This space may have been deleted or you may not have access.",actions:n.jsx(re,{variant:"outline",onClick:()=>r({to:"/$org",params:{org:o.slug}}),children:"Back to spaces"})})}),e[0]=r,e[1]=o.slug,e[2]=c):c=e[2],c}let l;e[3]!==a?(l=si(a)?.connectionId??"",e[3]=a,e[4]=l):l=e[4];let h;return e[5]!==i||e[6]!==l||e[7]!==a?(h=n.jsx(pv,{virtualMcp:a,hideOwnTitle:i},l),e[5]=i,e[6]=l,e[7]=a,e[8]=h):h=e[8],h}function _l(t){const e=K.c(2),{virtualMcpId:s}=t;let i;return e[0]!==s?(i=n.jsx(_v,{virtualMcpId:s,hideOwnTitle:!0}),e[0]=s,e[1]=i):i=e[1],i}const gv={amp:"&",lt:"<",gt:">",quot:'"',apos:"'",nbsp:" "};function zi(t){return t?t.replace(/&(#x?[0-9a-fA-F]+|[a-zA-Z]+);/g,(e,s)=>{if(s.startsWith("#x")||s.startsWith("#X")){const i=Number.parseInt(s.slice(2),16);return Number.isFinite(i)?String.fromCodePoint(i):e}if(s.startsWith("#")){const i=Number.parseInt(s.slice(1),10);return Number.isFinite(i)?String.fromCodePoint(i):e}return gv[s]??e}):""}const vv=10;function xv(t){const e=t;if(e.isError)return null;const s=e.content?.find(r=>r.type==="resource"),i=s?.resource?.text??s?.text;if(!i)return null;try{const r=JSON.parse(i);return typeof r=="string"?r:r&&typeof r=="object"&&"content"in r&&typeof r.content=="string"?r.content:JSON.stringify(r,null,2)}catch{return i}}async function nr(t,e,s){try{const i=await t.callTool({name:"get_file_contents",arguments:{owner:e.owner,repo:e.repo,path:e.path,...s}});return xv(i)}catch{return null}}function bv(t){const e=Bs(t);return Array.isArray(e)?e.map(s=>{const i=Number(s.additions??0),r=Number(s.changes??i),o=Number(s.deletions??Math.max(0,r-i));return{filename:String(s.filename??""),status:s.status??"modified",additions:i,deletions:o,blobUrl:typeof s.blob_url=="string"?s.blob_url:null}}):[]}async function yv(t,e,s){if(t.length===0)return;let i=0;async function r(){for(;i<t.length;){const o=i++;await s(t[o])}}await Promise.all(Array.from({length:Math.min(e,t.length)},()=>r()))}async function gl(t,e){const s=await t.callTool({name:"pull_request_read",arguments:{method:"get_files",owner:e.owner,repo:e.repo,pullNumber:e.pullNumber,perPage:100}}),i=bv(s).filter(a=>a.filename.length>0),r={},o=e.mergeBaseSha?{sha:e.mergeBaseSha}:{ref:e.base};return await yv(i,vv,async a=>{const l=a.filename;if(a.status==="added"){r[l]={from:null,to:await nr(t,{owner:e.owner,repo:e.repo,path:l},{sha:e.headSha})};return}if(a.status==="removed"){r[l]={from:await nr(t,{owner:e.owner,repo:e.repo,path:l},o),to:null};return}const[h,c]=await Promise.all([nr(t,{owner:e.owner,repo:e.repo,path:l},o),nr(t,{owner:e.owner,repo:e.repo,path:l},{sha:e.headSha})]);r[l]={from:h,to:c}}),{diffs:r}}function qh(t){return t?Object.keys(t.diffs).length:0}function oi(t,e,s,i){return`/api/${t}/sandbox/${encodeURIComponent(e)}/${encodeURIComponent(s)}/git/${i}`}class Gh extends Error{constructor(e,s){super(e),this.status=s,this.name="SandboxGitError"}status}function ya(t){return t instanceof Gh&&(t.status===503||t.status===410||t.status===404)}async function ai(t){const e=await t.json();if(!t.ok)throw new Gh(typeof e.error=="string"?e.error:`Request failed (${t.status})`,t.status);return e}function li(t,e){return fetch(t,{cache:"no-store",...e})}async function br(t,e,s){const i=await li(oi(t,e,s,"status"));return ai(i)}async function Yh(t,e,s,i){const r=i?.base||i?.headSha?{...i.base?{base:i.base}:{},...i.headSha?{headSha:i.headSha}:{}}:void 0,o=await li(oi(t,e,s,"diff"),{method:"POST",headers:r?{"content-type":"application/json"}:void 0,body:r?JSON.stringify(r):void 0});return ai(o)}async function vl(t,e,s,i){const r=await li(oi(t,e,s,"suggest-commit"),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(i??{})});return ai(r)}async function bn(t,e,s,i){const r=await li(oi(t,e,s,"publish"),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({message:i})});await ai(r)}async function Sv(t,e,s,i){const r=await li(oi(t,e,s,"rebase"),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({base:i})});await ai(r)}function wv(t){return t==="blocks.gen.json"||t.endsWith("/blocks.gen.json")}function xl(t){if(!t)return!1;const e=Object.keys(t.diffs);return e.length===0?!1:e.every(s=>s===".deco"||s.startsWith(".deco/")||wv(s))}const Cv="Code changes can't be published directly — use Submit for review";async function bl(t,e,s,i){const r=await li(oi(t,e,s,"discard"),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({filepaths:i})});await ai(r)}const kv="current";function Sa(t){return t?.[kv]??null}function jv(t,e,s){return["sandbox-git-status",t,e,s]}function Xh(t){return t?t.modified.length+t.created.length+t.deleted.length+t.not_added.length+t.renamed.length:0}function Jh(t){return t?Xh(t)>0||t.staged.length>0||t.conflicted.length>0:!1}function Zh(t){return t?Jh(t)||t.ahead>0||(t.unpushed??0)>0?!0:t.unpushed===void 0&&(t.aheadOfBase??0)>0&&t.tracking==null:!1}function Nv(t,e){return t?Zh(t)||e!=null&&Object.keys(e.diffs).length>0:!1}function Ev(t){return Math.max(t.unpushed??0,t.ahead)}function Tv(t){return t.aheadOfBase??0}function Rv(t){return t.behindBase??0}function Pv(t,e){if(!e)return t;const s=Jh(e),i=Sa(e),r=Ev(e),o=Tv(e),a=Rv(e),l=e.base??"main",h=e.headSha??"";return t.kind==="ready"?{...t,branch:i??t.branch,base:e.base??t.base,workingTreeDirty:s,unpushed:Math.max(t.unpushed,r),aheadOfBase:Math.max(t.aheadOfBase,o),behindBase:e.behindBase!==void 0?Math.max(t.behindBase,a):t.behindBase,headSha:h||t.headSha}:!s&&o===0&&r===0?t:{kind:"ready",branch:i??"",base:l,workingTreeDirty:s,unpushed:r,aheadOfBase:o,behindBase:a,headSha:h}}function Dv(t,e,s,i,r,o,a){return["pr-diff",t,e,s,i,r,o,a]}function Av(t){const e=K.c(26),{orgSlug:s,orgId:i,virtualMcpId:r,branch:o,base:a,headSha:l,pullNumber:h,connectionId:c,owner:d,repo:u,enabled:f}=t,m=f===void 0?!0:f;let p;e[0]!==c||e[1]!==i||e[2]!==s?(p={connectionId:c,orgId:i,orgSlug:s},e[0]=c,e[1]=i,e[2]=s,e[3]=p):p=e[3];const _=ft(p);let g;e[4]!==a||e[5]!==o||e[6]!==c||e[7]!==l||e[8]!==s||e[9]!==h||e[10]!==r?(g=Dv(s,r,o,a,l,h,c),e[4]=a,e[5]=o,e[6]=c,e[7]=l,e[8]=s,e[9]=h,e[10]=r,e[11]=g):g=e[11];let v;e[12]!==a||e[13]!==o||e[14]!==_||e[15]!==l||e[16]!==s||e[17]!==d||e[18]!==h||e[19]!==u||e[20]!==r?(v=async()=>{try{const y=await Yh(s,r,o,{base:a,headSha:l});return qh(y)>0?y:gl(_,{owner:d,repo:u,pullNumber:h,base:a,headSha:l,mergeBaseSha:y.mergeBaseSha})}catch{return gl(_,{owner:d,repo:u,pullNumber:h,base:a,headSha:l})}},e[12]=a,e[13]=o,e[14]=_,e[15]=l,e[16]=s,e[17]=d,e[18]=h,e[19]=u,e[20]=r,e[21]=v):v=e[21];const b=m&&!!o&&!!l&&!!c;let x;return e[22]!==g||e[23]!==v||e[24]!==b?(x={queryKey:g,queryFn:v,enabled:b,refetchInterval:3e4,staleTime:1e4},e[22]=g,e[23]=v,e[24]=b,e[25]=x):x=e[25],Zs(x)}Tm.config({paths:{vs:"https://cdn.jsdelivr.net/npm/monaco-editor@0.52.0/min/vs"}});function Iv(){return document.documentElement.classList.contains("dark")?"vs-dark":"vs"}function Qh(t){const e=K.c(9),{diff:s,emptyMessage:i,rowClassName:r,onDiscardFile:o}=t,a=i===void 0?"No file changes in the working tree":i,l=r===void 0?"px-6":r,[h,c]=E.useState(null),[d,u]=E.useState(null);let f;e[0]===Symbol.for("react.memo_cache_sentinel")?(f=Iv(),e[0]=f):f=e[0];const m=f;if(!s||Object.keys(s.diffs).length===0){let _;return e[1]!==a?(_=n.jsx("div",{className:"flex items-center justify-center py-10 text-sm text-muted-foreground",children:a}),e[1]=a,e[2]=_):_=e[2],_}let p;return e[3]!==s.diffs||e[4]!==d||e[5]!==h||e[6]!==o||e[7]!==l?(p=n.jsx("div",{className:"divide-y",children:Object.entries(s.diffs).map(_=>{const[g,v]=_,{from:b,to:x}=v,y=h===g,w=b===null,C=x===null,j=g.startsWith("/")?g.slice(1):g,R=j.lastIndexOf("/"),B=R>=0?j.slice(R+1):j,P=R>=0?j.slice(0,R):null,T=vm(g),S=w?"bg-green-500":C?"bg-red-500":"bg-amber-500";return n.jsxs("div",{children:[n.jsxs("div",{className:he("flex items-center gap-3 py-3 hover:bg-muted/30",l),children:[n.jsx("button",{type:"button",className:"flex h-4 w-4 shrink-0 items-center justify-center text-muted-foreground transition-transform hover:text-foreground",onClick:()=>c(y?null:g),children:n.jsx(Pm,{className:he("h-3.5 w-3.5 transition-transform",y&&"rotate-90")})}),n.jsx("div",{className:he("h-2.5 w-2.5 shrink-0 rounded-full",S)}),n.jsx(nh,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),n.jsx("span",{className:"min-w-0 flex-1 truncate text-sm font-medium",children:B}),P&&n.jsx("span",{className:"shrink-0 text-xs text-muted-foreground",children:P}),o?n.jsxs(Ds,{children:[n.jsx(As,{asChild:!0,children:n.jsx("button",{type:"button",className:"flex h-6 w-6 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-foreground",children:n.jsx(tn,{className:"h-3.5 w-3.5"})})}),n.jsx(Is,{align:"end",children:n.jsx(He,{className:"text-destructive focus:text-destructive",onSelect:()=>u(g),children:"Discard changes"})})]}):null]}),d===g&&o?n.jsxs("div",{className:he("flex items-center justify-between gap-3 border-t bg-destructive/5 py-2.5",l),children:[n.jsxs("span",{className:"text-xs text-destructive",children:["Discard all changes to"," ",n.jsx("span",{className:"font-medium",children:B}),"? This cannot be undone."]}),n.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[n.jsx(re,{type:"button",variant:"ghost",size:"sm",className:"h-7 px-2 text-xs",onClick:()=>u(null),children:"Cancel"}),n.jsx(re,{type:"button",size:"sm",className:"h-7 bg-destructive px-2 text-xs text-destructive-foreground hover:bg-destructive/90",onClick:()=>{u(null),o(g)},children:"Discard"})]})]}):null,y&&n.jsx("div",{className:"border-t",children:n.jsx(Rm,{original:b??"",modified:x??"",language:T,theme:m,height:"380px",options:{readOnly:!0,renderSideBySide:!1,minimap:{enabled:!1},scrollBeyondLastLine:!1,fontSize:12}})})]},g)})}),e[3]=s.diffs,e[4]=d,e[5]=h,e[6]=o,e[7]=l,e[8]=p):p=e[8],p}function Bv(t){const e=K.c(4),{diffQuery:s}=t;if(s.isLoading){let r;return e[0]===Symbol.for("react.memo_cache_sentinel")?(r=n.jsxs("div",{className:"flex items-center justify-center gap-2 py-16 text-muted-foreground",children:[n.jsx(Ce,{className:"h-4 w-4 animate-spin"}),n.jsx("span",{className:"text-sm",children:"Loading changes…"})]}),e[0]=r):r=e[0],r}if(s.isError){let r;return e[1]===Symbol.for("react.memo_cache_sentinel")?(r=n.jsx("div",{className:"py-10 text-sm text-destructive",children:"Couldn't load PR changes."}),e[1]=r):r=e[1],r}let i;return e[2]!==s.data?(i=n.jsx(Qh,{diff:s.data,rowClassName:"px-0",emptyMessage:"No committed changes in this pull request"}),e[2]=s.data,e[3]=i):i=e[3],i}const Ms="The user clicked this action deliberately — execute directly. Do not call user_ask unless you hit an actual problem outside the scope of this intent (missing auth, unresolvable conflict, a check with multiple plausible fixes).";function Mv(t){return`Reopen PR #${t.prNumber}. ${Ms}`}function Lv(t){return`Rebase \`${t.branch}\` on the latest base and force-push with --force-with-lease. ${Ms}`}function Ov(t){return`Re-run the \`${t.checkName}\` check on PR #${t.prNumber}. If an empty commit is needed to retrigger CI, create and push one. ${Ms}`}function $v(t){const e=(t.failingChecks??[]).map(s=>`\`${s}\``).join(", ");return`PR #${t.prNumber} has failing checks: ${e}. For each: read the logs, diagnose the root cause, apply the smallest fix that makes it pass, commit, and push. ${Ms}`}function zv(t){return`Mark PR #${t.prNumber} ready for review. ${Ms}`}function Fv(t){return`Read the unresolved review threads on PR #${t.prNumber}. For each thread: understand the reviewer's ask, apply the needed changes, commit, push, reply explaining what changed, and resolve the thread. If a comment is a question that doesn't need a code change, reply with the answer and resolve. ${Ms}`}function Hv(t){return`Review PR #${t.prNumber}. Read the full diff, analyze every changed file for correctness, security, code quality, and alignment with the repo's patterns. Post specific line-level review comments on concerns, then submit an overall review (approve / request changes / comment) with a concise summary. Do not modify the code — this is a read-and-comment pass. ${Ms}`}function Wv(t){const e=K.c(24),{pr:s,connectionId:i,owner:r,repo:o}=t,{org:a}=Pe(),l=Ns();let h;e[0]!==i||e[1]!==a.id||e[2]!==a.slug||e[3]!==r||e[4]!==s.number||e[5]!==o?(h={orgId:a.id,orgSlug:a.slug,connectionId:i,owner:r,repo:o,prNumber:s.number},e[0]=i,e[1]=a.id,e[2]=a.slug,e[3]=r,e[4]=s.number,e[5]=o,e[6]=h):h=e[6];const c=kh(h);let d;e[7]!==l||e[8]!==s.number?(d=g=>l.sendMessage({parts:[{type:"text",text:Ov({prNumber:s.number,checkName:g})}]}),e[7]=l,e[8]=s.number,e[9]=d):d=e[9];const u=d;if(c.isLoading){let g;return e[10]===Symbol.for("react.memo_cache_sentinel")?(g=n.jsx("div",{className:"text-sm text-muted-foreground",children:"Loading checks…"}),e[10]=g):g=e[10],g}if(c.isError){let g;return e[11]===Symbol.for("react.memo_cache_sentinel")?(g=n.jsx("div",{className:"text-sm text-destructive",children:"Couldn't load check runs."}),e[11]=g):g=e[11],g}let f;e[12]!==c.data?(f=c.data??[],e[12]=c.data,e[13]=f):f=e[13];const m=f;if(m.length===0){let g;return e[14]===Symbol.for("react.memo_cache_sentinel")?(g=n.jsx("div",{className:"text-sm text-muted-foreground",children:"No check runs on the PR head commit."}),e[14]=g):g=e[14],g}let p;if(e[15]!==l||e[16]!==m||e[17]!==u){let g;e[19]!==l||e[20]!==u?(g=v=>n.jsxs("li",{className:"flex items-center justify-between gap-2 rounded px-2 py-1.5 text-sm hover:bg-muted",children:[n.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[n.jsx(Uv,{check:v}),n.jsx("span",{className:"truncate",children:v.name}),v.durationMs!=null&&n.jsx("span",{className:"text-xs text-muted-foreground",children:Kv(v.durationMs)})]}),n.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[v.htmlUrl&&n.jsx("a",{href:v.htmlUrl,target:"_blank",rel:"noreferrer",className:"inline-flex h-7 items-center justify-center rounded px-2 text-xs text-muted-foreground hover:bg-background",title:"View run",children:n.jsx(ni,{className:"h-3.5 w-3.5"})}),v.conclusion==="failure"&&n.jsx(re,{size:"sm",variant:"ghost",disabled:l.isStreaming,onClick:()=>u(v.name),children:"Re-run"})]})]},v.id),e[19]=l,e[20]=u,e[21]=g):g=e[21],p=m.map(g),e[15]=l,e[16]=m,e[17]=u,e[18]=p}else p=e[18];let _;return e[22]!==p?(_=n.jsx("ul",{className:"flex flex-col gap-0.5",children:p}),e[22]=p,e[23]=_):_=e[23],_}function Uv(t){const e=K.c(5),{check:s}=t;if(s.status!=="completed"){let o;return e[0]===Symbol.for("react.memo_cache_sentinel")?(o=n.jsx("span",{className:"text-muted-foreground","aria-label":"In progress",children:"○"}),e[0]=o):o=e[0],o}if(s.conclusion==="success"){let o;return e[1]===Symbol.for("react.memo_cache_sentinel")?(o=n.jsx("span",{className:"text-success","aria-label":"Success",children:"✓"}),e[1]=o):o=e[1],o}if(s.conclusion==="failure"){let o;return e[2]===Symbol.for("react.memo_cache_sentinel")?(o=n.jsx("span",{className:"text-destructive","aria-label":"Failure",children:"✗"}),e[2]=o):o=e[2],o}const i=s.conclusion??"—";let r;return e[3]!==i?(r=n.jsx("span",{className:"text-muted-foreground","aria-label":i,children:"—"}),e[3]=i,e[4]=r):r=e[4],r}function Kv(t){const e=Math.round(t/1e3);return e<60?`${e}s`:`${Math.round(e/60)}m`}function Vv(t){const e=K.c(10),{comments:s,isLoading:i,isError:r}=t;if(i||r||!s||s.length===0)return null;const o=s.length===1?"":"s";let a;e[0]!==s.length||e[1]!==o?(a=n.jsxs(Gm,{className:"py-3 text-sm font-medium",children:[s.length," comment",o]}),e[0]=s.length,e[1]=o,e[2]=a):a=e[2];let l;e[3]!==s?(l=s.map(qv),e[3]=s,e[4]=l):l=e[4];let h;e[5]!==l?(h=n.jsx(Ym,{className:"space-y-3 pb-3",children:l}),e[5]=l,e[6]=h):h=e[6];let c;return e[7]!==a||e[8]!==h?(c=n.jsx(Xm,{type:"single",collapsible:!0,className:"border-t border-border",children:n.jsxs(Jm,{value:"comments",className:"border-b-0",children:[a,h]})}),e[7]=a,e[8]=h,e[9]=c):c=e[9],c}function qv(t){return n.jsxs("div",{className:"rounded-md border border-border p-3",children:[n.jsxs("div",{className:"mb-1 text-xs text-muted-foreground",children:["@",t.author," · ",Gv(t.createdAt)]}),n.jsx(Yo,{id:`pr-comment-${t.id}`,text:zi(t.body)})]},t.id)}function Gv(t){if(!t)return"";const e=new Date(t).getTime();if(!Number.isFinite(e))return"";const s=Date.now()-e;if(s<0)return"just now";const i=Math.floor(s/864e5);if(i>0)return`${i}d ago`;const r=Math.floor(s/36e5);if(r>0)return`${r}h ago`;const o=Math.floor(s/6e4);return`${Math.max(1,o)}m ago`}function Yv(t){const e=K.c(19),{pr:s,connectionId:i,owner:r,repo:o}=t,{org:a}=Pe();let l;e[0]!==i||e[1]!==a.id||e[2]!==a.slug||e[3]!==r||e[4]!==s.number||e[5]!==o?(l={orgId:a.id,orgSlug:a.slug,connectionId:i,owner:r,repo:o,prNumber:s.number},e[0]=i,e[1]=a.id,e[2]=a.slug,e[3]=r,e[4]=s.number,e[5]=o,e[6]=l):l=e[6];const h=u_(l);let c;e[7]!==s.body||e[8]!==s.number?(c=s.body&&n.jsx("div",{className:"text-sm",children:n.jsx(Yo,{id:`pr-body-${s.number}`,text:zi(s.body)})}),e[7]=s.body,e[8]=s.number,e[9]=c):c=e[9];let d;e[10]!==h.data?(d=h.data??[],e[10]=h.data,e[11]=d):d=e[11];let u;e[12]!==h.isError||e[13]!==h.isLoading||e[14]!==d?(u=n.jsx(Vv,{comments:d,isLoading:h.isLoading,isError:h.isError}),e[12]=h.isError,e[13]=h.isLoading,e[14]=d,e[15]=u):u=e[15];let f;return e[16]!==c||e[17]!==u?(f=n.jsxs("div",{className:"space-y-8",children:[c,u]}),e[16]=c,e[17]=u,e[18]=f):f=e[18],f}function Xv(t){const e=K.c(68),{pr:s,virtualMcpId:i,branch:r,connectionId:o,owner:a,repo:l}=t,{org:h}=Pe();let c;e[0]!==r||e[1]!==o||e[2]!==h.id||e[3]!==h.slug||e[4]!==a||e[5]!==s.base||e[6]!==s.headSha||e[7]!==s.number||e[8]!==l||e[9]!==i?(c={orgSlug:h.slug,orgId:h.id,virtualMcpId:i,branch:r,base:s.base,headSha:s.headSha,pullNumber:s.number,connectionId:o,owner:a,repo:l},e[0]=r,e[1]=o,e[2]=h.id,e[3]=h.slug,e[4]=a,e[5]=s.base,e[6]=s.headSha,e[7]=s.number,e[8]=l,e[9]=i,e[10]=c):c=e[10];const d=Av(c);let u;e[11]!==d.data?(u=d.data?qh(d.data):void 0,e[11]=d.data,e[12]=u):u=e[12];const f=u,[m,p]=E.useState("changes");let _;e[13]!==s.title?(_=zi(s.title),e[13]=s.title,e[14]=_):_=e[14];let g;e[15]!==_?(g=n.jsx("h1",{className:"text-lg font-semibold leading-tight",children:_}),e[15]=_,e[16]=g):g=e[16];const v=`Open PR #${s.number} on GitHub`;let b;e[17]===Symbol.for("react.memo_cache_sentinel")?(b=n.jsx(ni,{className:"h-3.5 w-3.5"}),e[17]=b):b=e[17];let x;e[18]!==s.htmlUrl||e[19]!==s.number||e[20]!==v?(x=n.jsxs("a",{href:s.htmlUrl,target:"_blank",rel:"noreferrer","aria-label":v,className:"inline-flex items-center gap-1 hover:text-foreground",children:["PR #",s.number,b]}),e[18]=s.htmlUrl,e[19]=s.number,e[20]=v,e[21]=x):x=e[21];let y;e[22]!==s.author?(y=s.author?n.jsxs(n.Fragment,{children:[n.jsx("span",{children:"·"}),n.jsxs("span",{children:["@",s.author]})]}):null,e[22]=s.author,e[23]=y):y=e[23];let w;e[24]===Symbol.for("react.memo_cache_sentinel")?(w=n.jsx("span",{children:"·"}),e[24]=w):w=e[24];let C;e[25]!==s.base?(C=n.jsx("span",{className:"font-mono text-xs",children:s.base}),e[25]=s.base,e[26]=C):C=e[26];let j;e[27]===Symbol.for("react.memo_cache_sentinel")?(j=n.jsx("span",{children:"←"}),e[27]=j):j=e[27];let R;e[28]!==s.head?(R=n.jsx("span",{className:"font-mono text-xs",children:s.head}),e[28]=s.head,e[29]=R):R=e[29];let B;e[30]!==C||e[31]!==R||e[32]!==x||e[33]!==y?(B=n.jsxs("div",{className:"flex flex-wrap items-center gap-x-1.5 text-sm text-muted-foreground",children:[x,y,w,C,j,R]}),e[30]=C,e[31]=R,e[32]=x,e[33]=y,e[34]=B):B=e[34];let P;e[35]!==B||e[36]!==g?(P=n.jsx("div",{className:"shrink-0 space-y-3 pb-4",children:n.jsxs("div",{className:"space-y-1",children:[g,B]})}),e[35]=B,e[36]=g,e[37]=P):P=e[37];let T;e[38]===Symbol.for("react.memo_cache_sentinel")?(T=V=>p(V),e[38]=T):T=e[38];let S;e[39]===Symbol.for("react.memo_cache_sentinel")?(S=n.jsx(ys,{value:"description",className:"px-3 text-xs",children:"Description"}),e[39]=S):S=e[39];const k=f!==void 0?` ${f}`:"";let I;e[40]!==k?(I=n.jsxs(ys,{value:"changes",className:"px-3 text-xs",children:["Changes",k]}),e[40]=k,e[41]=I):I=e[41];let N;e[42]===Symbol.for("react.memo_cache_sentinel")?(N=n.jsx(ys,{value:"checks",className:"px-3 text-xs",children:"Checks"}),e[42]=N):N=e[42];let A;e[43]!==I?(A=n.jsxs(Zo,{className:"h-8 w-fit max-w-[600px] shrink-0",variant:"pill",children:[S,I,N]}),e[43]=I,e[44]=A):A=e[44];let M;e[45]!==o||e[46]!==a||e[47]!==s||e[48]!==l?(M=n.jsx(Ti,{value:"description",className:"mt-0",children:n.jsx(Yv,{pr:s,connectionId:o,owner:a,repo:l})}),e[45]=o,e[46]=a,e[47]=s,e[48]=l,e[49]=M):M=e[49];let D;e[50]!==d?(D=n.jsx(Ti,{value:"changes",className:"mt-0",children:n.jsx(Bv,{diffQuery:d})}),e[50]=d,e[51]=D):D=e[51];let $;e[52]!==o||e[53]!==a||e[54]!==s||e[55]!==l?($=n.jsx(Ti,{value:"checks",className:"mt-0",children:n.jsx(Wv,{pr:s,connectionId:o,owner:a,repo:l})}),e[52]=o,e[53]=a,e[54]=s,e[55]=l,e[56]=$):$=e[56];let z;e[57]!==M||e[58]!==D||e[59]!==$?(z=n.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto pt-5",children:[M,D,$]}),e[57]=M,e[58]=D,e[59]=$,e[60]=z):z=e[60];let W;e[61]!==m||e[62]!==A||e[63]!==z?(W=n.jsxs(Qo,{value:m,onValueChange:T,className:"flex min-h-0 flex-1 flex-col",children:[A,z]}),e[61]=m,e[62]=A,e[63]=z,e[64]=W):W=e[64];let F;return e[65]!==P||e[66]!==W?(F=n.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[P,W]}),e[65]=P,e[66]=W,e[67]=F):F=e[67],F}function Jv(t){const e=K.c(5),{pr:s}=t,i=`Open PR #${s.number} on GitHub`;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=n.jsx(ni,{className:"h-4 w-4 text-muted-foreground"}),e[0]=r):r=e[0];let o;return e[1]!==s.htmlUrl||e[2]!==s.number||e[3]!==i?(o=n.jsx("div",{className:"flex h-12 items-center border-b border-border px-4 shrink-0",children:n.jsxs("a",{href:s.htmlUrl,target:"_blank",rel:"noreferrer","aria-label":i,className:"inline-flex items-center gap-1.5 text-base font-medium text-foreground hover:underline",children:["PR #",s.number,r]})}),e[1]=s.htmlUrl,e[2]=s.number,e[3]=i,e[4]=o):o=e[4],o}function Zv(t){const e=K.c(10),{virtualMcpId:s}=t,{org:i}=Pe(),r=Mt(s),{currentBranch:o}=ss(),a=r?.metadata?.githubRepo??null;if(!a?.connectionId){let h;return e[0]===Symbol.for("react.memo_cache_sentinel")?(h=n.jsx("div",{className:"flex h-full items-center justify-center p-8 text-sm text-muted-foreground",children:"This virtualmcp is not linked to a GitHub repository."}),e[0]=h):h=e[0],h}if(!o){let h;return e[1]===Symbol.for("react.memo_cache_sentinel")?(h=n.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-8 text-sm",children:[n.jsx(Mi,{className:"h-6 w-6 text-muted-foreground"}),n.jsx("div",{className:"text-muted-foreground",children:"No branch selected."}),n.jsx("div",{className:"text-xs text-muted-foreground",children:"Pick a branch from the header to see PR status."})]}),e[1]=h):h=e[1],h}let l;return e[2]!==o||e[3]!==a.connectionId||e[4]!==a.name||e[5]!==a.owner||e[6]!==i.id||e[7]!==i.slug||e[8]!==s?(l=n.jsx(Qv,{orgId:i.id,orgSlug:i.slug,virtualMcpId:s,connectionId:a.connectionId,owner:a.owner,repo:a.name,branch:o}),e[2]=o,e[3]=a.connectionId,e[4]=a.name,e[5]=a.owner,e[6]=i.id,e[7]=i.slug,e[8]=s,e[9]=l):l=e[9],l}function Qv(t){const e=K.c(47),{orgId:s,orgSlug:i,virtualMcpId:r,connectionId:o,owner:a,repo:l,branch:h}=t;let c;e[0]!==h||e[1]!==o||e[2]!==s||e[3]!==i||e[4]!==a||e[5]!==l?(c={orgId:s,orgSlug:i,connectionId:o,owner:a,repo:l,branch:h},e[0]=h,e[1]=o,e[2]=s,e[3]=i,e[4]=a,e[5]=l,e[6]=c):c=e[6];const{data:d,isLoading:u,isError:f}=ca(c),m=e1;if(u){let x;return e[7]===Symbol.for("react.memo_cache_sentinel")?(x=n.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"Loading PR state…"}),e[7]=x):x=e[7],x}if(f){let x;return e[8]===Symbol.for("react.memo_cache_sentinel")?(x=n.jsx("div",{className:"p-4 text-sm text-destructive",children:"Couldn't load PR state. The GitHub connection may be broken."}),e[8]=x):x=e[8],x}const p=`https://github.com/${a}/${l}/tree/${h}`;if(d&&d.state==="closed"){let x;e[9]!==d?(x=n.jsx(Jv,{pr:d}),e[9]=d,e[10]=x):x=e[10];const y=d.merged?"✓ Merged":"✗ Closed";let w;e[11]!==d.mergedAt?(w=d.mergedAt&&n.jsxs(n.Fragment,{children:[" · ",new Date(d.mergedAt).toLocaleDateString()]}),e[11]=d.mergedAt,e[12]=w):w=e[12];let C;e[13]!==d.author?(C=d.author&&n.jsxs(n.Fragment,{children:[" · by @",d.author]}),e[13]=d.author,e[14]=C):C=e[14];let j;e[15]!==d.base||e[16]!==y||e[17]!==w||e[18]!==C?(j=n.jsxs("div",{className:"text-sm text-success",children:[y," into ",d.base,w,C]}),e[15]=d.base,e[16]=y,e[17]=w,e[18]=C,e[19]=j):j=e[19];let R;e[20]!==d.title?(R=zi(d.title),e[20]=d.title,e[21]=R):R=e[21];let B;e[22]!==R?(B=n.jsx("h1",{className:"text-lg font-semibold",children:R}),e[22]=R,e[23]=B):B=e[23];let P;e[24]!==d.body||e[25]!==d.number?(P=d.body&&n.jsx("div",{className:"rounded-md border border-border bg-muted/30 p-3 text-sm",children:n.jsx(Yo,{id:`pr-body-${d.number}`,text:zi(d.body)})}),e[24]=d.body,e[25]=d.number,e[26]=P):P=e[26];let T;e[27]!==j||e[28]!==B||e[29]!==P?(T=n.jsxs("div",{className:"flex flex-col gap-4 p-4 overflow-auto",children:[j,B,P]}),e[27]=j,e[28]=B,e[29]=P,e[30]=T):T=e[30];let S;return e[31]!==x||e[32]!==T?(S=n.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[x,T]}),e[31]=x,e[32]=T,e[33]=S):S=e[33],S}if(d&&d.state==="open"){let x;return e[34]!==h||e[35]!==o||e[36]!==a||e[37]!==d||e[38]!==l||e[39]!==r?(x=n.jsx("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden",children:n.jsx("div",{className:"flex min-h-0 w-full flex-1 flex-col px-6 py-5",children:n.jsx(Xv,{pr:d,virtualMcpId:r,branch:h,connectionId:o,owner:a,repo:l})})}),e[34]=h,e[35]=o,e[36]=a,e[37]=d,e[38]=l,e[39]=r,e[40]=x):x=e[40],x}let _;e[41]===Symbol.for("react.memo_cache_sentinel")?(_=n.jsx("div",{className:"rounded-md border border-border bg-muted/30 p-4 text-sm",children:`This branch doesn't have an open pull request. Click "Submit for review" in the header to open one; the agent will draft the title and summary from the current state of the branch.`}),e[41]=_):_=e[41];let g;e[42]!==p?(g=()=>m(p),e[42]=p,e[43]=g):g=e[43];let v;e[44]===Symbol.for("react.memo_cache_sentinel")?(v=n.jsx(ni,{className:"mr-1.5 h-4 w-4"}),e[44]=v):v=e[44];let b;return e[45]!==g?(b=n.jsxs("div",{className:"flex flex-col gap-4 p-4",children:[_,n.jsx("div",{className:"flex items-center gap-2",children:n.jsxs(re,{size:"sm",variant:"outline",onClick:g,children:[v,"Open branch on GitHub"]})})]}),e[45]=g,e[46]=b):b=e[46],b}function e1(t){window.open(t,"_blank","noopener,noreferrer")}function ed(t){return t.appPaused||t.userStopped?{kind:"suspended"}:t.previewUrl?{kind:"iframe",previewUrl:t.previewUrl}:{kind:"starting"}}function td(t){const e=Object.values(t),[s]=e;return s?e.find(i=>i.sandboxProviderKind!=="user-desktop")??s:null}function t1(t){return t.hasActiveGithubRepo&&!!t.userId&&!!t.branch&&!t.vmEntry&&!t.userStopped&&!t.isPending&&!t.attempted}function s1(t){return t.notFound&&!!t.deadVmId&&!t.isPending&&!t.userStopped&&t.deadVmId!==t.lastDeadVmId}function i1(t){switch(t.kind){case"suspended":return"suspended";case"iframe":return"running";case"starting":return"starting"}}const r1={branch:null,previewState:{kind:"starting"},status:"idle",vmEntry:null,previewUrl:null,userStopped:!1,start:()=>{},stop:async()=>{},restart:async()=>{},retry:()=>{},resume:()=>{}},sd=E.createContext(r1);function id(){return E.use(sd)}function n1({virtualMcpId:t,branch:e,userId:s,hasActiveGithubRepo:i,sandboxMap:r,children:o}){const{org:a}=Pe(),{setCurrentTaskBranch:l}=ss(),h=Yt(),c=Qs(),d=ft({connectionId:Ho,orgId:a.id,orgSlug:a.slug}),u=zo(d),{mutate:f,reset:m}=u,p=E.useRef(new Set),_=E.useRef(null),g=s&&e?Jr(r?.[s]?.[e]):{},v=td(g),b=v?.previewUrl??null,x=!!t&&!!e&&$n.isStopped(t,e),y=h.status.state==="paused",w=ed({previewUrl:b,appPaused:y,userStopped:x}),C=i1(w),j=e!==null&&p.current.has(e),R=t1({hasActiveGithubRepo:i,userId:s,branch:e,vmEntry:v,userStopped:x,isPending:u.isPending,attempted:j});E.useEffect(()=>{if(!R||!e||!t)return;p.current.add(e),f({virtualMcpId:t,branch:e},{onError:D=>{console.error("[sandbox-lifecycle] auto-start failed:",D)}})},[R,e,t,f]);const B=h.notFound?v?.sandboxHandle??null:null,P=s1({notFound:h.notFound,deadVmId:B,lastDeadVmId:_.current,isPending:u.isPending,userStopped:x});E.useEffect(()=>{if(!P||!B||!t)return;_.current=B;const M={virtualMcpId:t};e&&(M.branch=e),f(M,{onSuccess:D=>{D?.branch&&!e&&l(D.branch)},onError:D=>{console.error("[sandbox-lifecycle] self-heal failed:",D)}})},[P,B,t,e,f,l]);const T=()=>{if(!t)return;const M={virtualMcpId:t};e&&(M.branch=e),f(M,{onSuccess:D=>{D?.branch&&!e&&l(D.branch)},onError:D=>{console.error("[sandbox-lifecycle] user start failed:",D)}})},S=async()=>{if(!t||!e)return;const M=v?.sandboxProviderKind;if(M){$n.mark(t,e);try{await d.callTool({name:"SANDBOX_DELETE",arguments:{virtualMcpId:t,branch:e,sandboxProviderKind:M}})}catch{}Ku(c)}},k=async()=>{await S(),T()},I=()=>{p.current=new Set,_.current=null,m(),T()},A={branch:e,previewState:w,status:C,vmEntry:v,previewUrl:b,userStopped:x,start:T,stop:S,restart:k,retry:I,resume:I};return n.jsx(sd,{value:A,children:o})}function rd(t){return btoa(encodeURIComponent(t))}function o1(t,e,s){const i=new URL(t).origin,r=new URL(`/live/previews/${encodeURIComponent(e)}`,i);return r.searchParams.set("path","/"),r.searchParams.set("pathTemplate","/"),r.searchParams.set("props",rd(JSON.stringify({path:"/",sections:[{__resolveType:s}]}))),r.searchParams.set("__cb",crypto.randomUUID()),r.toString()}function FC(t,e,s,i){const r=new URL(t).origin,o=new URL(`/live/previews/${encodeURIComponent(e)}`,r);o.searchParams.set("__d","");const a=[{__resolveType:"preview",block:s}];return i&&a.push(i),o.searchParams.set("props",rd(JSON.stringify({sections:a}))),o.toString()}const yl={resolveType:"website/pages/Page.tsx",seoResolveType:"website/sections/Seo/SeoV2.tsx"};function wa(t){return`pages-${encodeURIComponent(t)}-${crypto.randomUUID()}`}function nd(t,e){return{name:t,path:e,sections:[],seo:{__resolveType:yl.seoResolveType},__resolveType:yl.resolveType}}const a1=700;function Ca(t){const e=K.c(21),{orgSlug:s,virtualMcpId:i,branch:r}=t,o=Qs();let a;e[0]!==r||e[1]!==s||e[2]!==i?(a=async u=>{const{blockKey:f,data:m}=u,p=rh(f),_=JSON.stringify(m,null,2),g=await fetch(`/api/${s}/sandbox/${encodeURIComponent(i)}/${encodeURIComponent(r)}/write`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({path:p,content:_})});if(!g.ok){const v=await g.json().catch(l1);throw new Error(v.error??`Write failed (${g.status})`)}return g.json()},e[0]=r,e[1]=s,e[2]=i,e[3]=a):a=e[3];let l;e[4]!==r||e[5]!==s||e[6]!==o||e[7]!==i?(l=async u=>{const{blockKey:f,data:m}=u,p=`${s}/${i}/${r}`,_=Bt.decofile(p);await o.cancelQueries({queryKey:_});const g=o.getQueryData(_);return o.setQueryData(_,v=>({...v??{},[f]:m})),{previous:g,queryKey:_}},e[4]=r,e[5]=s,e[6]=o,e[7]=i,e[8]=l):l=e[8];let h;e[9]!==o?(h=(u,f,m)=>{m?.queryKey&&o.setQueryData(m.queryKey,m.previous)},e[9]=o,e[10]=h):h=e[10];let c;e[11]!==r||e[12]!==s||e[13]!==o||e[14]!==i?(c=(u,f)=>{const{blockKey:m,data:p}=f,_=`${s}/${i}/${r}`;o.setQueryData(Bt.decofile(_),g=>({...g??{},[m]:p}))},e[11]=r,e[12]=s,e[13]=o,e[14]=i,e[15]=c):c=e[15];let d;return e[16]!==a||e[17]!==l||e[18]!==h||e[19]!==c?(d={mutationFn:a,onMutate:l,onError:h,onSuccess:c},e[16]=a,e[17]=l,e[18]=h,e[19]=c,e[20]=d):d=e[20],ei(d)}function l1(){return{}}function HC(t,e){const s=K.c(15),i=Ca(t);let r;s[0]===Symbol.for("react.memo_cache_sentinel")?(r=new Map,s[0]=r):r=s[0];const o=E.useRef(r);let a;s[1]===Symbol.for("react.memo_cache_sentinel")?(a=new Map,s[1]=a):a=s[1];const l=E.useRef(a);let h;s[2]!==e||s[3]!==i?(h=v=>{const b=o.current.get(v);if(!b)return;const x=typeof b=="function"?b():b;o.current.delete(v),x&&i.mutate({blockKey:v,data:x},{onSuccess:()=>e?.onSaved?.(),onError:c1})},s[2]=e,s[3]=i,s[4]=h):h=s[4];const c=h;let d;s[5]!==c?(d=()=>{for(const v of l.current.values())clearTimeout(v);l.current.clear();for(const v of[...o.current.keys()])c(v)},s[5]=c,s[6]=d):d=s[6];const u=d;let f,m;s[7]===Symbol.for("react.memo_cache_sentinel")?(f=()=>{const v=l.current;return()=>{for(const b of v.values())clearTimeout(b)}},m=[],s[7]=f,s[8]=m):(f=s[7],m=s[8]),E.useEffect(f,m);let p;s[9]!==c?(p=(v,b)=>{o.current.set(v,b);const x=l.current.get(v);x&&clearTimeout(x),l.current.set(v,setTimeout(()=>{l.current.delete(v),c(v)},a1))},s[9]=c,s[10]=p):p=s[10];const _=p;let g;return s[11]!==u||s[12]!==_||s[13]!==i.isPending?(g={save:_,flush:u,isPending:i.isPending},s[11]=u,s[12]=_,s[13]=i.isPending,s[14]=g):g=s[14],g}function c1(t){return le.error(`Save failed: ${t.message}`)}function h1(t){const e=K.c(5);let s;e[0]!==t?(s=t??{orgSlug:"",virtualMcpId:"",branch:""},e[0]=t,e[1]=s):s=e[1];const i=Ca(s);let r;return e[2]!==t||e[3]!==i?(r={mutationFn:async o=>{const{name:a,path:l}=o;if(!t?.virtualMcpId||!t.branch)throw new Error("Sandbox not ready");const h=wa(a),c=nd(a,l);return await i.mutateAsync({blockKey:h,data:c}),{key:h,name:a,path:l}}},e[2]=t,e[3]=i,e[4]=r):r=e[4],ei(r)}function d1(t){const e=K.c(50),{open:s,onOpenChange:i,isPending:r,error:o,onSubmit:a}=t,l=r===void 0?!1:r,[h,c]=E.useState("My New Page"),[d,u]=E.useState("/example-path"),[f,m]=E.useState(null),[p,_]=E.useState(s);s!==p&&(_(s),s&&(c("My New Page"),u("/example-path"),m(null)));let g;e[0]!==l||e[1]!==i?(g=F=>{!F&&!l&&(m(null),i(!1))},e[0]=l,e[1]=i,e[2]=g):g=e[2];const v=g;let b;e[3]!==l||e[4]!==h||e[5]!==a||e[6]!==d?(b=async F=>{F.preventDefault();const V=h.trim(),J=d.trim();if(!V||!J||l)return;const Y=pa(J);if(Y){m(Y);return}m(null),await a({name:V,path:J})},e[3]=l,e[4]=h,e[5]=a,e[6]=d,e[7]=b):b=e[7];const x=b,y=f??o;let w;e[8]===Symbol.for("react.memo_cache_sentinel")?(w=n.jsx(is,{children:n.jsx(rs,{children:"Create new page"})}),e[8]=w):w=e[8];let C;e[9]===Symbol.for("react.memo_cache_sentinel")?(C=n.jsx("label",{htmlFor:"new-page-name",className:"text-xs font-medium text-muted-foreground",children:"Name"}),e[9]=C):C=e[9];let j;e[10]===Symbol.for("react.memo_cache_sentinel")?(j=F=>c(F.target.value),e[10]=j):j=e[10];let R;e[11]!==l||e[12]!==h?(R=n.jsxs("div",{className:"space-y-1.5",children:[C,n.jsx(qe,{id:"new-page-name",value:h,onChange:j,placeholder:"My New Page",autoFocus:!0,disabled:l})]}),e[11]=l,e[12]=h,e[13]=R):R=e[13];let B;e[14]===Symbol.for("react.memo_cache_sentinel")?(B=n.jsx("label",{htmlFor:"new-page-path",className:"text-xs font-medium text-muted-foreground",children:"Path"}),e[14]=B):B=e[14];let P;e[15]===Symbol.for("react.memo_cache_sentinel")?(P=F=>u(F.target.value),e[15]=P):P=e[15];let T;e[16]!==l||e[17]!==d?(T=n.jsxs("div",{className:"space-y-1.5",children:[B,n.jsx(qe,{id:"new-page-path",value:d,onChange:P,placeholder:"/example-path",disabled:l})]}),e[16]=l,e[17]=d,e[18]=T):T=e[18];let S;e[19]!==y?(S=y&&n.jsx("p",{className:"text-xs text-destructive",children:y}),e[19]=y,e[20]=S):S=e[20];let k;e[21]!==T||e[22]!==S||e[23]!==R?(k=n.jsxs("div",{className:"space-y-4 py-4",children:[R,T,S]}),e[21]=T,e[22]=S,e[23]=R,e[24]=k):k=e[24];let I;e[25]!==i?(I=()=>i(!1),e[25]=i,e[26]=I):I=e[26];let N;e[27]!==l||e[28]!==I?(N=n.jsx(re,{type:"button",variant:"outline",onClick:I,disabled:l,children:"Cancel"}),e[27]=l,e[28]=I,e[29]=N):N=e[29];let A;e[30]!==l||e[31]!==h||e[32]!==d?(A=!h.trim()||!d.trim()||l,e[30]=l,e[31]=h,e[32]=d,e[33]=A):A=e[33];let M;e[34]!==l?(M=l?n.jsxs(n.Fragment,{children:[n.jsx(Ce,{size:14,className:"animate-spin"}),"Creating…"]}):"Create",e[34]=l,e[35]=M):M=e[35];let D;e[36]!==A||e[37]!==M?(D=n.jsx(re,{type:"submit",disabled:A,children:M}),e[36]=A,e[37]=M,e[38]=D):D=e[38];let $;e[39]!==N||e[40]!==D?($=n.jsxs(ii,{children:[N,D]}),e[39]=N,e[40]=D,e[41]=$):$=e[41];let z;e[42]!==x||e[43]!==k||e[44]!==$?(z=n.jsx(Ot,{className:"sm:max-w-md",children:n.jsxs("form",{onSubmit:x,children:[w,k,$]})}),e[42]=x,e[43]=k,e[44]=$,e[45]=z):z=e[45];let W;return e[46]!==v||e[47]!==s||e[48]!==z?(W=n.jsx(Lt,{open:s,onOpenChange:v,children:z}),e[46]=v,e[47]=s,e[48]=z,e[49]=W):W=e[49],W}const u1=_r({tag:Tt(),id:Tt(),classes:Tt(),text:Tt(),html:Tt(),manifestKey:Tt().nullable(),componentName:Tt().nullable(),parents:Tt(),url:Tt(),path:Tt(),viewport:_r({width:yi(),height:yi()}),position:_r({x:yi(),y:yi()})}),f1=`(function() {
|
|
38
38
|
if (window.__visualEditorActive) return;
|
|
39
39
|
window.__visualEditorActive = true;
|
|
40
40
|
|
|
@@ -258,7 +258,7 @@ ${se}`:se;c.setValue("metadata.instructions",ee,{shouldDirty:!0})},Y=new Set(d.m
|
|
|
258
258
|
}
|
|
259
259
|
});
|
|
260
260
|
})();`;function Os(t){return t.replace(/[`*_]/g,"\\$&")}function _1(t,e){const s=[`The user selected an element on the live preview and asked: **"${Os(e.trim())}"**`,"","For text content changes, locate the correct source file and apply the change.","For code and CSS changes, understand which component the user is referring to and apply changes to the correct component.",""];t.manifestKey&&s.push(`**Section source file:** \`${Os(t.manifestKey)}\``,"");const i=`<${t.tag}${t.classes?` class="${Os(t.classes)}"`:""}>`;s.push(`**Clicked element:** \`${i}\``),t.parents&&s.push(`**DOM breadcrumb:** ${Os(t.parents)} > ${t.tag}`),t.text&&s.push(`**Text content:** "${Os(t.text)}"`),t.componentName&&s.push(`**Component name:** ${Os(t.componentName)}`);const r=t.html.replace(/```/g,"`` `");return s.push("","**HTML snippet:**","```html",r,"```"),s.push("","Please read the source file, locate the element, and apply the requested change."),s.join(`
|
|
261
|
-
`)}function g1(t,e,s=320,i=44,r=12){const{x:o,y:a}=t,{width:l,height:h}=e,c=Math.max(r,Math.min(o-s/2,l-s-r)),u=a/h>.68?Math.max(r,a-i-18):Math.min(a+18,h-i-r);return{leftPct:c/l*100,topPct:u/h*100}}function v1(t){const e=K.c(32),{element:s,onDismiss:i}=t,[r,o]=E.useState(""),a=E.useRef(null),{sendMessage:l}=Ns(),{setChatOpen:h}=Uo();let c;e[0]!==s||e[1]!==r||e[2]!==i||e[3]!==l||e[4]!==h?(c=()=>{if(!r.trim())return;const P=_1(s,r);h(!0),l({parts:[{type:"text",text:P}]}),i()},e[0]=s,e[1]=r,e[2]=i,e[3]=l,e[4]=h,e[5]=c):c=e[5];const d=c;let u;e[6]!==s.position||e[7]!==s.viewport?(u=g1(s.position,s.viewport),e[6]=s.position,e[7]=s.viewport,e[8]=u):u=e[8];const f=u,m=`${f.leftPct}%`,p=`${f.topPct}%`;let _;e[9]!==m||e[10]!==p?(_={left:m,top:p,width:"320px"},e[9]=m,e[10]=p,e[11]=_):_=e[11];let g;e[12]!==d?(g=P=>{P.preventDefault(),d()},e[12]=d,e[13]=g):g=e[13];let v;e[14]===Symbol.for("react.memo_cache_sentinel")?(v=P=>o(P.target.value),e[14]=v):v=e[14];let b;e[15]!==i?(b=P=>{P.key==="Escape"&&i()},e[15]=i,e[16]=b):b=e[16];let x;e[17]!==r||e[18]!==b?(x=n.jsx("input",{ref:a,autoFocus:!0,type:"text",value:r,onChange:v,onKeyDown:b,placeholder:"Ask the AI...",className:"min-w-0 flex-1 bg-transparent text-sm outline-none placeholder:text-muted-foreground"}),e[17]=r,e[18]=b,e[19]=x):x=e[19];let y;e[20]!==r?(y=r.trim(),e[20]=r,e[21]=y):y=e[21];const w=!y;let C;e[22]===Symbol.for("react.memo_cache_sentinel")?(C=n.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none","aria-hidden":"true",children:[n.jsx("title",{children:"Send"}),n.jsx("path",{d:"M5 9V1M1 5l4-4 4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}),e[22]=C):C=e[22];let j;e[23]!==w?(j=n.jsx("button",{type:"submit",disabled:w,className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-full bg-foreground text-background transition-opacity disabled:opacity-30",title:"Send",children:C}),e[23]=w,e[24]=j):j=e[24];let R;e[25]!==j||e[26]!==g||e[27]!==x?(R=n.jsxs("form",{className:"pointer-events-auto flex w-full items-center gap-1.5 rounded-xl border border-border bg-background/95 px-3 py-1.5 shadow-lg backdrop-blur",onSubmit:g,children:[x,j]}),e[25]=j,e[26]=g,e[27]=x,e[28]=R):R=e[28];let B;return e[29]!==R||e[30]!==_?(B=n.jsx("div",{className:"absolute z-30 pointer-events-none",style:_,children:R}),e[29]=R,e[30]=_,e[31]=B):B=e[31],B}const od={claiming:{long:"Reserving sandbox",short:"Reserving sandbox"},"waiting-for-capacity":{long:"Waiting for cluster capacity",short:"Waiting for capacity"},"pulling-image":{long:"Downloading sandbox image",short:"Downloading image"},"starting-container":{long:"Starting your sandbox",short:"Starting container"},"warming-daemon":{long:"Connecting to your sandbox",short:"Connecting to sandbox"}},x1=["provision","cloning","install","dev"];function ad(t){switch(t.lifecycle.phase){case"cloning":case"checking-out":return{step:"cloning",status:"doing"};case"clone-failed":return{step:"cloning",status:"failed"};case"installing":return{step:"install",status:"doing"};case"install-failed":return{step:"install",status:"failed"};case"starting":return{step:"dev",status:"doing"};case"running":return{step:"dev",status:"done"};case"start-failed":return{step:"dev",status:"failed"};case"crashed":return{step:"dev",status:"failed"};case"idle":return t.claimPhase&&t.claimPhase.kind!=="ready"&&t.claimPhase.kind!=="failed"?{step:"provision",status:"doing"}:{step:"cloning",status:"doing"}}}function b1(t){switch(t){case"starting":return"Starting your sandbox";case"suspended":return"Sandbox is paused"}}function y1(t){return x1.indexOf(t.step)}const Sl=48,ld=28,cd=3,S1=(()=>{const t=[];let e=0;for(let s=0;s<Sl;s++)s===ld?t.push(null):(t.push(e/(Sl-1)*cd),e++);return t})(),w1={provision:"Reserving sandbox",cloning:"Cloning your repo",install:"Installing packages",dev:"Starting your preview"};function C1(t,e){return t.step==="provision"&&e!=null&&e.kind!=="ready"&&e.kind!=="failed"?od[e.kind].long:w1[t.step]}const Ht="bg-foreground/[0.05]",Ct="bg-foreground/[0.09]",k1=Array.from({length:35},()=>Math.random()*1.8),j1=Array.from({length:35},()=>Math.random()<.4);function N1(t){const e=K.c(30),{progress:s,claimPhase:i}=t;let r;e[0]!==s?(r=y1(s),e[0]=s,e[1]=r):r=e[1];const o=r;let a;e[2]!==i||e[3]!==s?(a=C1(s,i),e[2]=i,e[3]=s,e[4]=a):a=e[4];const l=a;let h;e[5]===Symbol.for("react.memo_cache_sentinel")?(h=n.jsx(
|
|
261
|
+
`)}function g1(t,e,s=320,i=44,r=12){const{x:o,y:a}=t,{width:l,height:h}=e,c=Math.max(r,Math.min(o-s/2,l-s-r)),u=a/h>.68?Math.max(r,a-i-18):Math.min(a+18,h-i-r);return{leftPct:c/l*100,topPct:u/h*100}}function v1(t){const e=K.c(32),{element:s,onDismiss:i}=t,[r,o]=E.useState(""),a=E.useRef(null),{sendMessage:l}=Ns(),{setChatOpen:h}=Uo();let c;e[0]!==s||e[1]!==r||e[2]!==i||e[3]!==l||e[4]!==h?(c=()=>{if(!r.trim())return;const P=_1(s,r);h(!0),l({parts:[{type:"text",text:P}]}),i()},e[0]=s,e[1]=r,e[2]=i,e[3]=l,e[4]=h,e[5]=c):c=e[5];const d=c;let u;e[6]!==s.position||e[7]!==s.viewport?(u=g1(s.position,s.viewport),e[6]=s.position,e[7]=s.viewport,e[8]=u):u=e[8];const f=u,m=`${f.leftPct}%`,p=`${f.topPct}%`;let _;e[9]!==m||e[10]!==p?(_={left:m,top:p,width:"320px"},e[9]=m,e[10]=p,e[11]=_):_=e[11];let g;e[12]!==d?(g=P=>{P.preventDefault(),d()},e[12]=d,e[13]=g):g=e[13];let v;e[14]===Symbol.for("react.memo_cache_sentinel")?(v=P=>o(P.target.value),e[14]=v):v=e[14];let b;e[15]!==i?(b=P=>{P.key==="Escape"&&i()},e[15]=i,e[16]=b):b=e[16];let x;e[17]!==r||e[18]!==b?(x=n.jsx("input",{ref:a,autoFocus:!0,type:"text",value:r,onChange:v,onKeyDown:b,placeholder:"Ask the AI...",className:"min-w-0 flex-1 bg-transparent text-sm outline-none placeholder:text-muted-foreground"}),e[17]=r,e[18]=b,e[19]=x):x=e[19];let y;e[20]!==r?(y=r.trim(),e[20]=r,e[21]=y):y=e[21];const w=!y;let C;e[22]===Symbol.for("react.memo_cache_sentinel")?(C=n.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none","aria-hidden":"true",children:[n.jsx("title",{children:"Send"}),n.jsx("path",{d:"M5 9V1M1 5l4-4 4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}),e[22]=C):C=e[22];let j;e[23]!==w?(j=n.jsx("button",{type:"submit",disabled:w,className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-full bg-foreground text-background transition-opacity disabled:opacity-30",title:"Send",children:C}),e[23]=w,e[24]=j):j=e[24];let R;e[25]!==j||e[26]!==g||e[27]!==x?(R=n.jsxs("form",{className:"pointer-events-auto flex w-full items-center gap-1.5 rounded-xl border border-border bg-background/95 px-3 py-1.5 shadow-lg backdrop-blur",onSubmit:g,children:[x,j]}),e[25]=j,e[26]=g,e[27]=x,e[28]=R):R=e[28];let B;return e[29]!==R||e[30]!==_?(B=n.jsx("div",{className:"absolute z-30 pointer-events-none",style:_,children:R}),e[29]=R,e[30]=_,e[31]=B):B=e[31],B}const od={claiming:{long:"Reserving sandbox",short:"Reserving sandbox"},"waiting-for-capacity":{long:"Waiting for cluster capacity",short:"Waiting for capacity"},"pulling-image":{long:"Downloading sandbox image",short:"Downloading image"},"starting-container":{long:"Starting your sandbox",short:"Starting container"},"warming-daemon":{long:"Connecting to your sandbox",short:"Connecting to sandbox"}},x1=["provision","cloning","install","dev"];function ad(t){switch(t.lifecycle.phase){case"cloning":case"checking-out":return{step:"cloning",status:"doing"};case"clone-failed":return{step:"cloning",status:"failed"};case"installing":return{step:"install",status:"doing"};case"install-failed":return{step:"install",status:"failed"};case"starting":return{step:"dev",status:"doing"};case"running":return{step:"dev",status:"done"};case"start-failed":return{step:"dev",status:"failed"};case"crashed":return{step:"dev",status:"failed"};case"idle":return t.claimPhase&&t.claimPhase.kind!=="ready"&&t.claimPhase.kind!=="failed"?{step:"provision",status:"doing"}:{step:"cloning",status:"doing"}}}function b1(t){switch(t){case"starting":return"Starting your sandbox";case"suspended":return"Sandbox is paused"}}function y1(t){return x1.indexOf(t.step)}const Sl=48,ld=28,cd=3,S1=(()=>{const t=[];let e=0;for(let s=0;s<Sl;s++)s===ld?t.push(null):(t.push(e/(Sl-1)*cd),e++);return t})(),w1={provision:"Reserving sandbox",cloning:"Cloning your repo",install:"Installing packages",dev:"Starting your preview"};function C1(t,e){return t.step==="provision"&&e!=null&&e.kind!=="ready"&&e.kind!=="failed"?od[e.kind].long:w1[t.step]}const Ht="bg-foreground/[0.05]",Ct="bg-foreground/[0.09]",k1=Array.from({length:35},()=>Math.random()*1.8),j1=Array.from({length:35},()=>Math.random()<.4);function N1(t){const e=K.c(30),{progress:s,claimPhase:i}=t;let r;e[0]!==s?(r=y1(s),e[0]=s,e[1]=r):r=e[1];const o=r;let a;e[2]!==i||e[3]!==s?(a=C1(s,i),e[2]=i,e[3]=s,e[4]=a):a=e[4];const l=a;let h;e[5]===Symbol.for("react.memo_cache_sentinel")?(h=n.jsx(df,{}),e[5]=h):h=e[5];const c=`${s.step}-${l}`;let d;e[6]!==l||e[7]!==c?(d=n.jsxs("div",{className:"flex items-center gap-2 rounded-full border border-foreground/10 bg-background px-3.5 py-1.5 shadow-[0_4px_20px_-4px_rgb(0_0_0_/_0.12)]",children:[h,n.jsxs("span",{className:"animate-in fade-in text-[13px] font-medium text-foreground/85 duration-500",children:[l,"…"]},c)]}),e[6]=l,e[7]=c,e[8]=d):d=e[8];let u;e[9]===Symbol.for("react.memo_cache_sentinel")?(u=n.jsx(E1,{}),e[9]=u):u=e[9];let f;e[10]!==o?(f=n.jsx(or,{phase:0,current:o,children:u}),e[10]=o,e[11]=f):f=e[11];let m;e[12]===Symbol.for("react.memo_cache_sentinel")?(m=n.jsx(R1,{}),e[12]=m):m=e[12];let p;e[13]!==o?(p=n.jsx(or,{phase:1,current:o,children:m}),e[13]=o,e[14]=p):p=e[14];let _;e[15]===Symbol.for("react.memo_cache_sentinel")?(_=n.jsx(P1,{}),e[15]=_):_=e[15];let g;e[16]!==o?(g=n.jsx(or,{phase:2,current:o,children:_}),e[16]=o,e[17]=g):g=e[17];let v;e[18]===Symbol.for("react.memo_cache_sentinel")?(v=n.jsx(A1,{}),e[18]=v):v=e[18];let b;e[19]!==o?(b=n.jsx(or,{phase:3,current:o,children:v}),e[19]=o,e[20]=b):b=e[20];let x;e[21]!==g||e[22]!==b||e[23]!==f||e[24]!==p?(x=n.jsxs("div",{className:"relative aspect-[4/3] w-[min(78%,560px)]",children:[f,p,g,b]}),e[21]=g,e[22]=b,e[23]=f,e[24]=p,e[25]=x):x=e[25];let y;e[26]===Symbol.for("react.memo_cache_sentinel")?(y=n.jsx("style",{children:`
|
|
262
262
|
@keyframes vm-pulse-soft {
|
|
263
263
|
0%, 100% { opacity: 0.25; }
|
|
264
264
|
50% { opacity: 1; }
|
|
@@ -272,7 +272,7 @@ ${se}`:se;c.setValue("metadata.instructions",ee,{shouldDirty:!0})},Y=new Set(d.m
|
|
|
272
272
|
8% { opacity: 1; }
|
|
273
273
|
22% { opacity: 0; }
|
|
274
274
|
}
|
|
275
|
-
`}),e[26]=y):y=e[26];let w;return e[27]!==x||e[28]!==d?(w=n.jsxs("div",{className:"relative flex w-full flex-col items-center justify-center gap-12 select-none [clip-path:inset(-24px_0_-200px_0)]",children:[d,x,y]}),e[27]=x,e[28]=d,e[29]=w):w=e[29],w}function or(t){const e=K.c(10),{phase:s,current:i,children:r}=t,o=s-i,a=o<0,l=o===0,h=a?90:o*-22,c=a?.94:1-Math.max(o,0)*.04,d=a?0:l?1:o===1?.8:.55,u=a?10:30-o,f=!l;let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m=he("absolute inset-0 overflow-hidden rounded-xl border border-foreground/10 bg-background shadow-[0_20px_60px_-20px_rgb(0_0_0_/_0.35)] transition-all ease-[cubic-bezier(0.22,1,0.36,1)]"),e[0]=m):m=e[0];const p=`translateY(${h}px) scale(${c})`,_=l?"auto":"none";let g;e[1]!==d||e[2]!==p||e[3]!==_||e[4]!==u?(g={transform:p,opacity:d,zIndex:u,transitionDuration:"1000ms",pointerEvents:_},e[1]=d,e[2]=p,e[3]=_,e[4]=u,e[5]=g):g=e[5];let v;return e[6]!==r||e[7]!==f||e[8]!==g?(v=n.jsx("div",{"aria-hidden":f,className:m,style:g,children:r}),e[6]=r,e[7]=f,e[8]=g,e[9]=v):v=e[9],v}function an(t){const e=K.c(7),{showUrl:s}=t,i=s===void 0?!1:s;let r,o,a;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=n.jsx("div",{className:he("size-2.5 rounded-full",Ct)}),o=n.jsx("div",{className:he("size-2.5 rounded-full",Ct)}),a=n.jsx("div",{className:he("size-2.5 rounded-full",Ct)}),e[0]=r,e[1]=o,e[2]=a):(r=e[0],o=e[1],a=e[2]);let l;e[3]!==i?(l=i&&n.jsx("div",{className:he("ml-3 h-3.5 max-w-[220px] flex-1 rounded-sm",Ht)}),e[3]=i,e[4]=l):l=e[4];let h;return e[5]!==l?(h=n.jsxs("div",{className:"flex h-7 shrink-0 items-center gap-1.5 px-3",children:[r,o,a,l]}),e[5]=l,e[6]=h):h=e[6],h}function E1(){const t=K.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=n.jsx(an,{}),t[0]=e):e=t[0];let s;return t[1]===Symbol.for("react.memo_cache_sentinel")?(s=n.jsxs("div",{className:"flex h-full flex-col",children:[e,n.jsx("div",{className:"flex flex-1 px-8 py-5",children:n.jsx("div",{className:"grid h-full w-full grid-cols-8 grid-rows-6 gap-2",children:S1.map(T1)})})]}),t[1]=s):s=t[1],s}function T1(t,e){if(e===ld)return n.jsx("div",{className:"rounded-md bg-chart-1/[0.55]",style:{animation:"vm-breathe 2.4s ease-in-out infinite"}},e);const s=t;return n.jsx("div",{className:he("relative rounded-md",Ct),children:n.jsx("div",{className:"absolute inset-0 rounded-md bg-chart-1/40 opacity-0",style:{animation:`vm-rack-scan ${cd}s ease-in-out infinite`,animationDelay:`${s}s`}})},e)}function R1(){const t=K.c(5);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=n.jsx(an,{}),t[0]=e):e=t[0];let s;t[1]===Symbol.for("react.memo_cache_sentinel")?(s=n.jsx("div",{className:he("w-[18%] rounded-md",Ht),style:{animation:"vm-breathe 3s ease-in-out infinite"}}),t[1]=s):s=t[1];let i;t[2]===Symbol.for("react.memo_cache_sentinel")?(i=n.jsx("div",{className:"h-[42%] shrink-0 rounded-md bg-chart-3/[0.12]",style:{animation:"vm-breathe 3s ease-in-out 0.4s infinite"}}),t[2]=i):i=t[2];let r;t[3]===Symbol.for("react.memo_cache_sentinel")?(r=n.jsx("div",{className:"col-span-3 rounded-md bg-chart-3/[0.12]",style:{animation:"vm-breathe 3s ease-in-out 0.8s infinite"}}),t[3]=r):r=t[3];let o;return t[4]===Symbol.for("react.memo_cache_sentinel")?(o=n.jsxs("div",{className:"flex h-full flex-col",children:[e,n.jsxs("div",{className:"flex min-h-0 flex-1 gap-1.5 p-3",children:[s,n.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-1.5",children:[i,n.jsxs("div",{className:"grid min-h-0 flex-1 grid-cols-5 gap-1.5",children:[r,n.jsxs("div",{className:"col-span-2 grid grid-rows-2 gap-1.5",children:[n.jsx("div",{className:he("rounded-md",Ht),style:{animation:"vm-breathe 3s ease-in-out 1.2s infinite"}}),n.jsx("div",{className:he("rounded-md",Ht),style:{animation:"vm-breathe 3s ease-in-out 1.6s infinite"}})]})]})]})]})]}),t[4]=o):o=t[4],o}function P1(){const t=K.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=n.jsx(an,{}),t[0]=e):e=t[0];let s;return t[1]===Symbol.for("react.memo_cache_sentinel")?(s=n.jsxs("div",{className:"flex h-full flex-col",children:[e,n.jsx("div",{className:"relative flex flex-1 items-center justify-center px-8 py-5",children:n.jsx("div",{className:"grid w-full gap-2",style:{gridTemplateColumns:"repeat(7, minmax(0, 1fr))"},children:k1.map(D1)})})]}),t[1]=s):s=t[1],s}function D1(t,e){return n.jsx("div",{className:he("aspect-square rounded-md",j1[e]?"bg-chart-2/70":Ct),style:{animation:`vm-pulse-soft 2.2s ease-in-out ${t}s infinite`}},e)}function A1(){const t=K.c(11);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=n.jsx(an,{showUrl:!0}),t[0]=e):e=t[0];let s,i,r,o,a;t[1]===Symbol.for("react.memo_cache_sentinel")?(s=n.jsx("div",{className:"mb-2 h-5 rounded-md bg-chart-1/[0.10]"}),i=n.jsx("div",{className:he("h-1.5 w-[70%] rounded-sm",Ct)}),r=n.jsx("div",{className:he("h-1.5 w-[55%] rounded-sm",Ct)}),o=n.jsx("div",{className:he("h-1.5 w-[80%] rounded-sm",Ct)}),a=n.jsx("div",{className:he("h-1.5 w-[50%] rounded-sm",Ct)}),t[1]=s,t[2]=i,t[3]=r,t[4]=o,t[5]=a):(s=t[1],i=t[2],r=t[3],o=t[4],a=t[5]);let l;t[6]===Symbol.for("react.memo_cache_sentinel")?(l=n.jsxs("div",{className:"flex w-[18%] shrink-0 flex-col gap-1.5 bg-chart-1/[0.05] p-2.5",children:[s,i,r,o,a,n.jsx("div",{className:"mt-auto",children:n.jsx("div",{className:he("h-4 rounded-md",Ct)})})]}),t[6]=l):l=t[6];let h;t[7]===Symbol.for("react.memo_cache_sentinel")?(h=n.jsx("div",{className:"relative h-[42%] shrink-0 overflow-hidden bg-chart-1/[0.10]",children:n.jsxs("div",{className:"absolute right-3 bottom-3 left-3 space-y-1.5",children:[n.jsx("div",{className:"h-3 w-[35%] rounded-sm bg-chart-1/[0.15]"}),n.jsx("div",{className:he("h-1.5 w-[55%] rounded-sm",Ht)})]})}),t[7]=h):h=t[7];let c;t[8]===Symbol.for("react.memo_cache_sentinel")?(c=n.jsxs("div",{className:"flex shrink-0 gap-1.5",children:[n.jsx("div",{className:"h-4 w-12 rounded-full bg-chart-1/[0.12]"}),n.jsx("div",{className:he("h-4 w-10 rounded-full",Ht)}),n.jsx("div",{className:he("h-4 w-14 rounded-full",Ht)})]}),t[8]=c):c=t[8];let d;t[9]===Symbol.for("react.memo_cache_sentinel")?(d=n.jsxs("div",{className:he("col-span-3 flex flex-col justify-end gap-1 rounded-md p-2",Ht),children:[n.jsx("div",{className:he("h-1.5 w-[50%] rounded-sm",Ct)}),n.jsx("div",{className:he("h-1 w-[75%] rounded-sm",Ct)})]}),t[9]=d):d=t[9];let u;return t[10]===Symbol.for("react.memo_cache_sentinel")?(u=n.jsxs("div",{className:"flex h-full flex-col",children:[e,n.jsxs("div",{className:"flex min-h-0 flex-1",children:[l,n.jsxs("div",{className:"flex min-w-0 flex-1 flex-col",children:[h,n.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-2.5 p-3",children:[c,n.jsxs("div",{className:"grid min-h-0 flex-1 grid-cols-5 gap-2",children:[d,n.jsxs("div",{className:"col-span-2 grid grid-rows-2 gap-2",children:[n.jsx("div",{className:he("rounded-md",Ht)}),n.jsx("div",{className:he("rounded-md",Ht)})]})]})]})]})]})]}),t[10]=u):u=t[10],u}function Fr(t){const e=K.c(9);if(t.kind==="starting"){let l;return e[0]!==t.claimPhase||e[1]!==t.progress?(l=n.jsx("div",{className:"flex h-full w-full items-center justify-center bg-background p-6",children:n.jsx(N1,{progress:t.progress,claimPhase:t.claimPhase})}),e[0]=t.claimPhase,e[1]=t.progress,e[2]=l):l=e[2],l}let s;e[3]===Symbol.for("react.memo_cache_sentinel")?(s=n.jsx(Of,{className:"size-12 text-blue-500"}),e[3]=s):s=e[3];let i,r;e[4]===Symbol.for("react.memo_cache_sentinel")?(i=n.jsx("h3",{className:"text-lg font-medium",children:b1("suspended")}),r=n.jsx("p",{className:"max-w-sm text-sm text-muted-foreground",children:"Resume to continue."}),e[4]=i,e[5]=r):(i=e[4],r=e[5]);let o;e[6]===Symbol.for("react.memo_cache_sentinel")?(o=n.jsx(Vs,{className:"size-4"}),e[6]=o):o=e[6];let a;return e[7]!==t.onResume?(a=n.jsx("div",{className:"flex h-full w-full items-center justify-center bg-background p-6",children:n.jsxs("div",{className:"flex w-full max-w-md flex-col items-center gap-4 text-center",children:[s,i,r,n.jsxs(re,{onClick:t.onResume,className:"mt-2",children:[o," Resume"]})]})}),e[7]=t.onResume,e[8]=a):a=e[8],a}const I1=E.lazy(()=>qt(()=>import("./sections-editor-DPjqmRcC.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153])).then(t=>({default:t.SectionsEditor}))),B1=E.lazy(()=>qt(()=>import("./page-seo-sheet-CAj4OnGN.js"),__vite__mapDeps([154,1,2,121,44,46,47,48,16,3,5,85,72,79,76,6,7,8,9,10,11,12,13,14,15,17,4,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,45,77,50,78,73,51,80,49,81,82,83,84,60,61,89,90,91,58,92,93,94,57,95,59,96,97,98,99,100,101,102,103,104,105,106,107,66,108,56,109,71,110,70,67,111,112,113,114,115,116,65,86,87,52,53,54,55,62,63,64,68,69,74,75,117,118,119,120,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152])).then(t=>({default:t.SeoSheet}))),M1=E.lazy(()=>qt(()=>import("./file-explorer-COzE78zi.js"),__vite__mapDeps([155,1,2,136,6,7,8,9,10,11,12,13,14,15,16,3,17,4,5,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,126,90,91,58,92,93,84,94,57,95,59,103,104,49,105,106,107,50,119,120,121,122,81,78,70,123,108,124,56,67,114,125,62,63,64,71,72,110,127,52,53,54,55,60,61,65,66,68,69,73,74,75,86,87,128,129,130,97,98,135,100,51,89,96,99,101,102,109,82,111,112,113,115,116,117,118,131,132,133,134,137,138,79,139,140,141,142,143,144,145,146,147,148,149,150,151,152])).then(t=>({default:t.FileExplorer}))),yn=500,L1={mobile:375,tablet:768,desktop:null},Sn=["desktop","mobile","tablet"],O1={mobile:"Mobile (375px)",tablet:"Tablet (768px)",desktop:"Desktop"};function $1(t,e){const s=new URL(t,window.location.href);return s.searchParams.set("deviceHint",e),s.href}function z1(){const t=sr(),{currentBranch:e}=ss(),[s,i]=E.useState("preview"),[r,o]=E.useState("desktop"),[a,l]=E.useState(null),h=E.useRef(null),c=s==="cms",[d,u]=E.useState(null),[f,m]=E.useState(384),p=E.useRef(!1),_=E.useRef(0),g=E.useRef(0),v=E.useRef(null),[b,x]=E.useState(!1),[y,w]=E.useState(""),C=E.useRef(null),[j,R]=E.useState(!1),[B,P]=E.useState(),[T,S]=E.useState(null),[k,I]=E.useState(null),[N,A]=E.useState("/"),[M,D]=E.useState(null),[$,z]=E.useState(!1),[W,F]=E.useState(!1),[V,J]=E.useState(null),Y=t?.entity?.id??null,{org:U}=Pe(),H=Yt(),X=id(),oe=X.vmEntry,L=X.previewUrl,se=H.lifecycle.phase,ee=se==="running",Q=Y&&e&&ee?{orgSlug:U.slug,virtualMcpId:Y,branch:e}:null,{data:O}=ha(Q,{fetchEnabled:ee}),{data:ce}=da(Q,{fetchEnabled:ee}),ue=Y&&e?{orgSlug:U.slug,virtualMcpId:Y,branch:e}:null,fe=h1(ue),q=O?va(O).sort((ie,ve)=>ie.name.localeCompare(ve.name)):[],te=O&&ce?xa(O,ce):[],me=Us,ne=q.filter(ie=>{if(!y)return!0;const ve=y.toLowerCase();return ie.name.toLowerCase().includes(ve)||ie.path.toLowerCase().includes(ve)}),ke=te.filter(ie=>{if(!y)return!0;const ve=y.toLowerCase();return ie.name.toLowerCase().includes(ve)||ie.key.toLowerCase().includes(ve)||ie.resolveType.toLowerCase().includes(ve)}),at=T?null:P_(q,N,M),Be=T?T.name:at?.name,mt=at?.key??null,as=E.useRef(null),G=E.useRef(null);W_(()=>{const ie=h.current,ve=as.current;!ie||!ve||(ie.src=ve)});const _e=H.status.state==="paused",xe=H.phase,Se=ad({claimPhase:xe,lifecycle:H.lifecycle}),we=X.previewState,et=X.userStopped,bt=we.kind==="iframe"?$1(k??new URL(N,we.previewUrl).href,r):null,[ir,rr]=E.useState(null);if(we.kind==="iframe"&&ir!==we.previewUrl){const ie=ir!==null;rr(we.previewUrl),ie&&(G.current=null,A("/"),I(null),D(null),S(null))}as.current=bt;const ge=!!Y&&!!e&&!H.notFound&&!et&&!_e&&(xe?.kind==="ready"||se!=="idle"),je=we.kind!=="iframe"&&(s==="visual"||s==="cms")?"preview":s;E.useEffect(()=>{if(!L)return;let ie;try{ie=new URL(L,window.location.href).origin}catch{return}const ve=it=>{if(it.origin===ie){if(it.data?.type==="visual-editor::element-clicked"){const rt=u1.safeParse(it.data.payload);rt.success&&l(rt.data)}else if(it.data?.type==="cms-editor::section-clicked"){const rt=m1.safeParse(it.data.payload);rt.success&&u(rt.data.sectionIndex)}}};return window.addEventListener("message",ve),()=>window.removeEventListener("message",ve)},[L]),E.useEffect(()=>{if(!b)return;const ie=ve=>{C.current?.contains(ve.target)||(x(!1),w(""))};return document.addEventListener("pointerdown",ie),()=>document.removeEventListener("pointerdown",ie)},[b]),E.useEffect(()=>{if(!c)return;const ie=it=>{const rt=it.target;rt&&rt!==h.current&&(v.current=rt)},ve=()=>{requestAnimationFrame(()=>{const it=document.activeElement;(it===document.body||it===h.current)&&v.current&&v.current.focus()})};return document.addEventListener("focusin",ie),document.addEventListener("blur",ve,!0),()=>{document.removeEventListener("focusin",ie),document.removeEventListener("blur",ve,!0)}},[c]);const tt=()=>{const ie=h.current?.contentWindow;ie&&ie.postMessage({type:"visual-editor::activate",script:f1},"*")},yt=()=>{const ie=h.current?.contentWindow;ie&&ie.postMessage({type:"visual-editor::deactivate"},"*")},st=()=>{const ie=h.current?.contentWindow;ie&&ie.postMessage({type:"visual-editor::activate",script:p1},"*")},ku=()=>{const ie=h.current?.contentWindow;ie&&ie.postMessage({type:"cms-editor::deactivate"},"*")},di=ie=>{const ve=s;i(ie),l(null),ie!=="code"&&J(null),ie!=="cms"&&u(null),ve==="visual"&&yt(),ve==="cms"&&ku(),ie==="visual"&&tt(),ie==="cms"&&st()},ju=()=>{if(!h.current||!bt)return;const ie=h.current;ie.src=bt},Nu=()=>{if(!h.current||!bt)return;const ie=bt.includes("?")?"&":"?";h.current.src=`${bt}${ie}_r=${Date.now()}`},Eu=()=>{const ie=Sn.indexOf(r);o(Sn[(ie+1)%Sn.length])},Tu=()=>{const ie=h.current?.contentWindow?.location?.href??bt??L;ie&&navigator.clipboard.writeText(ie)},Ru=(()=>{if(!L)return"No server running";if(T)return T.name;try{const ie=new URL(L),ve=N==="/"?"":N;return`${ie.host}${ve}`}catch{return L}})(),za=ie=>{G.current=ie.path,S(null),I(null),D(ie.key),A(ie.path),u(null),z(!1)},Pu=ie=>{if(!L||!ce){le.error("Preview metadata not ready yet");return}G.current=null;const ve=Lh(ce),it=o1(L,ve,ie.key);S(ie),I(it),u(null)},Du=async({name:ie,path:ve})=>{if(!Y||!e)return;const it=pa(ve);if(it){P(it);return}const rt=ve.trim().startsWith("/")?ve.trim():`/${ve.trim()}`;if(q.some(Et=>me(Et.path)===me(rt))){P(`A page with path "${rt}" already exists.`);return}P(void 0);try{const Et=await fe.mutateAsync({name:ie,path:rt});R(!1),le.success(`Page "${ie}" created`),await new Promise(Iu=>setTimeout(Iu,yn)),za({key:Et.key,name:Et.name,path:Et.path}),di("cms")}catch(Et){P(Et instanceof Error?Et.message:"Failed to create page")}},Au=[{value:"preview",icon:n.jsx(Va,{size:14}),tooltip:"Interactive"},...we.kind==="iframe"?[{value:"visual",icon:n.jsx(qa,{size:14}),tooltip:"Visual editor"}]:[],...we.kind==="iframe"&&ga(O,ce)?[{value:"cms",icon:n.jsx($f,{size:14}),tooltip:"Sections editor"}]:[],{value:"code",icon:n.jsx(zf,{size:14}),tooltip:"Code editor"}];return n.jsxs("div",{className:"flex flex-col w-full h-full",children:[ge&&n.jsxs("div",{className:"flex h-12 shrink-0 items-center gap-4 border-b border-border/60 px-3 md:px-4",children:[n.jsx("div",{className:"flex shrink-0 items-center gap-1",children:n.jsx(Zm,{value:je,onValueChange:di,options:Au,size:"sm",className:"shrink-0 bg-foreground/4.5"})}),we.kind==="iframe"&&n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:he("flex min-w-0 flex-1 items-center gap-0.5 ml-2",s==="code"&&"hidden"),children:[n.jsxs(Re,{children:[n.jsx(Ee,{asChild:!0,children:n.jsx(re,{variant:"ghost",size:"icon",onClick:ju,children:n.jsx(Bi,{size:14})})}),n.jsx(Te,{side:"bottom",children:"Refresh"})]}),n.jsxs(Re,{children:[n.jsx(Ee,{asChild:!0,children:n.jsx(re,{variant:"ghost",size:"icon",onClick:Eu,children:n.jsxs("span",{className:"flex items-center justify-center animate-device-icon-pop",children:[r==="mobile"&&n.jsx(Ff,{size:14}),r==="tablet"&&n.jsx(Hf,{size:14}),r==="desktop"&&n.jsx(Va,{size:14})]},r)})}),n.jsx(Te,{side:"bottom",children:O1[r]})]}),n.jsxs("div",{ref:C,className:"relative min-w-0 flex-1",children:[n.jsxs("button",{type:"button",className:"flex h-8 w-full min-w-0 items-center gap-1 rounded-md bg-background px-2 transition-colors duration-200 hover:bg-accent",onClick:()=>x(ie=>!ie),children:[T&&n.jsxs("span",{className:"shrink-0 inline-flex items-center gap-1 rounded bg-global-section/14 px-1.5 py-0.5 text-[11px] font-medium text-global-section-fg dark:text-global-section-fg-dark",children:[n.jsx(Gs,{size:11}),"Global"]}),n.jsx("span",{className:"min-w-0 flex-1 truncate text-left text-[12px] text-foreground/88",children:Ru}),Be&&!T&&n.jsx("span",{className:"shrink-0 text-[12px] text-muted-foreground",children:Be}),n.jsx(Es,{size:12,className:he("shrink-0 text-muted-foreground transition-transform",b&&"rotate-180")})]}),b&&n.jsxs("div",{className:"absolute left-0 right-0 top-full z-50 mt-1.5 overflow-hidden rounded-lg border bg-popover shadow-lg",children:[n.jsxs("div",{className:"px-2 h-10 flex items-center gap-2 border-b",children:[n.jsx(fh,{size:14,className:"shrink-0 text-muted-foreground","aria-hidden":!0}),n.jsx("input",{type:"text",value:y,onChange:ie=>w(ie.target.value),placeholder:"Search pages and components...",className:"w-full bg-transparent text-sm outline-none placeholder:text-muted-foreground",autoFocus:!0})]}),n.jsx("div",{className:"p-1.5 border-b",children:n.jsxs("button",{type:"button",className:"flex w-full items-center gap-2.5 rounded-md px-3 py-2.5 text-left text-sm hover:bg-accent hover:text-accent-foreground",onMouseDown:ie=>{ie.preventDefault(),x(!1),w(""),P(void 0),R(!0)},children:[n.jsx(xt,{size:16,className:"shrink-0 text-muted-foreground"}),n.jsx("span",{className:"flex-1 font-medium",children:"Create new page"})]})}),ne.length===0&&ke.length===0?n.jsx("div",{className:"px-4 py-5 text-center text-xs text-muted-foreground",children:q.length===0&&te.length===0?"No pages found in this site.":"No results match your search."}):n.jsxs("div",{className:"max-h-80 overflow-y-auto overscroll-contain",children:[ne.length>0&&n.jsx("div",{className:"p-1.5",children:ne.map(ie=>n.jsxs("button",{type:"button",className:"flex w-full items-center gap-3 rounded-md px-3 py-2.5 text-left text-sm hover:bg-accent hover:text-accent-foreground",onMouseDown:ve=>{ve.preventDefault(),x(!1),w(""),za(ie)},children:[n.jsx(Vo,{size:16,className:"shrink-0 text-muted-foreground"}),n.jsx("span",{className:"min-w-0 flex-1 truncate font-medium",children:ie.name}),n.jsx("span",{className:"shrink-0 text-xs text-muted-foreground",children:ie.path})]},ie.key))}),ke.length>0&&n.jsxs("div",{className:he("p-1.5",ne.length>0&&"border-t"),children:[n.jsx("div",{className:"px-3 py-2 text-xs font-medium text-muted-foreground",children:"Global components"}),ke.map(ie=>n.jsxs("button",{type:"button",className:"flex w-full items-center gap-3 rounded-md px-3 py-2.5 text-left text-sm hover:bg-accent hover:text-accent-foreground",onMouseDown:ve=>{ve.preventDefault(),x(!1),w(""),Pu(ie)},children:[n.jsx(Gs,{size:16,className:"shrink-0 text-muted-foreground"}),n.jsx("span",{className:"min-w-0 flex-1 truncate font-medium",children:ie.name}),n.jsx("span",{className:"shrink-0 text-xs text-muted-foreground",children:ie.resolveType.split("/").pop()?.replace(/\.tsx?$/,"")})]},ie.key))]})]})]})]})]}),n.jsxs("div",{className:he("flex shrink-0 items-center gap-0.5",s==="code"&&"hidden"),children:[n.jsxs(Re,{children:[n.jsx(Ee,{asChild:!0,children:n.jsx(re,{variant:"ghost",size:"icon",onClick:()=>{const ie=bt??we.previewUrl;ie&&window.open(ie,"_blank","noopener")},children:n.jsx(ni,{size:14})})}),n.jsx(Te,{side:"bottom",children:"Open in new tab"})]}),n.jsxs(Ds,{children:[n.jsx(As,{asChild:!0,children:n.jsx(re,{variant:"ghost",size:"icon",children:n.jsx(tn,{size:14})})}),n.jsxs(Is,{align:"end",className:"w-44",children:[n.jsx(He,{onClick:Nu,children:"Hard Reload"}),n.jsx(He,{onClick:Tu,children:"Copy Current URL"}),O&&ce&&n.jsxs(n.Fragment,{children:[n.jsx(gr,{}),mt&&n.jsxs(He,{onClick:()=>{z(!0),di("cms")},children:[n.jsx(Nr,{size:14}),"Edit SEO"]}),mt&&n.jsxs(He,{onClick:()=>{try{J(Ja(mt)),di("code")}catch{le.error("Invalid page block key")}},children:[n.jsx(qo,{size:14}),"View JSON"]}),n.jsxs(He,{onClick:()=>F(!0),children:[n.jsx(Nr,{size:14}),"Site SEO"]})]})]})]})]})]})]}),n.jsxs("div",{className:"flex-1 flex overflow-hidden",children:[c&&L&&e&&Y&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"shrink-0 border-r overflow-hidden",style:{width:f},children:n.jsx(E.Suspense,{fallback:n.jsx("div",{className:"h-full flex items-center justify-center",children:n.jsx(Ce,{size:20,className:"animate-spin text-muted-foreground"})}),children:n.jsx(I1,{orgSlug:U.slug,virtualMcpId:Y,branch:e,previewReady:ee,previewUrl:L,currentPath:N,activePageBlockKey:mt,activeGlobalBlockKey:T?.key??null,externalSelectedIndex:T?null:d,onSaved:()=>{setTimeout(()=>{const ie=h.current;if(!ie)return;const ve=document.activeElement,it=ie.tabIndex;ie.tabIndex=-1,ie.style.pointerEvents="none",ie.blur();try{ie.contentWindow?.location.reload()}catch{const Et=as.current;Et&&(ie.src=Et)}const rt=()=>{ie.tabIndex=it,ie.style.pointerEvents="",ve?.focus(),ie.removeEventListener("load",rt)};ie.addEventListener("load",rt),setTimeout(rt,3e3)},yn)},initialEditSeo:$,onExitSeo:()=>z(!1),onViewJsonFile:ie=>{try{J(Ja(ie)),di("code")}catch{le.error("Invalid page block key")}}})})}),n.jsx("div",{className:"w-1 shrink-0 cursor-col-resize bg-transparent hover:bg-border transition-colors",onPointerDown:ie=>{p.current=!0,_.current=ie.clientX,g.current=f,ie.currentTarget.setPointerCapture(ie.pointerId)},onPointerMove:ie=>{if(!p.current)return;const ve=ie.clientX-_.current;m(Math.max(240,Math.min(640,g.current+ve)))},onPointerUp:()=>{p.current=!1}})]}),n.jsxs("div",{className:he("flex-1 relative overflow-hidden",r!=="desktop"&&we.kind==="iframe"&&s!=="code"&&"flex justify-center bg-muted/30"),children:[we.kind==="starting"&&n.jsx("div",{className:"absolute inset-0 z-30",children:n.jsx(Fr,{kind:"starting",progress:Se,claimPhase:xe})}),we.kind==="suspended"&&n.jsx("div",{className:"absolute inset-0 z-30",children:n.jsx(Fr,{kind:"suspended",onResume:X.resume})}),je==="visual"&&!a&&n.jsxs("div",{className:"absolute top-2 left-1/2 -translate-x-1/2 z-20 flex items-center gap-1.5 rounded-full border border-violet-400/40 bg-violet-500/90 px-3 py-1 text-xs font-medium text-white shadow-md backdrop-blur-sm pointer-events-none select-none",children:[n.jsx(qa,{size:12}),"Click any element to ask the AI"]}),je==="visual"&&a&&n.jsx(v1,{element:a,onDismiss:()=>l(null)}),s==="code"&&ge&&Y&&e&&n.jsx("div",{className:"absolute inset-0 z-10 bg-background",children:n.jsx(E.Suspense,{fallback:n.jsx("div",{className:"h-full flex items-center justify-center",children:n.jsx(Ce,{size:20,className:"animate-spin text-muted-foreground"})}),children:n.jsx(M1,{orgSlug:U.slug,virtualMcpId:Y,branch:e,openPath:V})})}),we.kind==="iframe"&&bt&&n.jsx("div",{className:he("h-full transition-[width] duration-250 [transition-timing-function:var(--ease-in-out-cubic)]",r!=="desktop"&&s!=="code"&&"w-full max-w-full border-x border-border bg-background shadow-sm"),style:{width:r==="desktop"||s==="code"?"100%":`${L1[r]}px`},children:n.jsx("iframe",{ref:h,src:bt,className:he("w-full h-full border-0",s==="code"&&"invisible"),title:"Dev Server Preview",tabIndex:c?-1:void 0,onLoad:()=>{if(De("vm_preview_loaded",{view_mode:s,vm_id:oe?.sandboxHandle??null}),!T)try{const ie=h.current?.contentWindow?.location?.pathname;if(!ie)return;const ve=G.current;if(ve!==null){G.current=null,me(ie)===me(ve)&&A(ie);return}A(ie)}catch{}s==="visual"&&tt(),s==="cms"&&st()}},we.previewUrl)})]})]}),n.jsx(d1,{open:j,onOpenChange:R,isPending:fe.isPending,error:B,onSubmit:Du}),W&&O&&ce&&n.jsx(E.Suspense,{fallback:null,children:n.jsx(B1,{open:W,onOpenChange:F,orgSlug:U.slug,virtualMcpId:Y??"",branch:e??"",decofile:O,meta:ce,onSaved:()=>{setTimeout(()=>{const ie=h.current;if(ie)try{ie.contentWindow?.location.reload()}catch{const ve=as.current;ve&&(ie.src=ve)}},yn)},target:{kind:"site"}})})]})}function F1(t){const e=K.c(2),{virtualMcpId:s}=t,i=Mt(s);if(!ti(i?.metadata)){let a;return e[0]===Symbol.for("react.memo_cache_sentinel")?(a=n.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-2 text-center text-sm text-muted-foreground p-6",children:[n.jsx(Ui,{size:24,className:"text-muted-foreground/60"}),n.jsx("div",{children:"No source to preview."}),n.jsx("div",{className:"text-xs text-muted-foreground/80",children:"Connect a GitHub repository from the Connections tab to enable Preview."})]}),e[0]=a):a=e[0],a}let o;return e[1]===Symbol.for("react.memo_cache_sentinel")?(o=n.jsx(z1,{}),e[1]=o):o=e[1],o}function H1(t,e){if(!t||!e?.length)return t;const s=Object.fromEntries(Object.entries(t.properties??{}).filter(([i])=>!e.includes(i)));return Object.keys(s).length>0?{...t,properties:s}:t}function W1(t,e,s){return typeof t!="string"?null:H1(Ih(t,e),s)}function hd(t,e,s){if(!e||typeof t!="string")return!1;const i=W1(t,e,s);return!!i&&Object.keys(i.properties??{}).length>0}function U1({orgSlug:t,virtualMcpId:e,branch:s}){const i=Qs();return ei({mutationFn:async({blockKey:r})=>{const o=rh(r),a=await fetch(`/api/${t}/sandbox/${encodeURIComponent(e)}/${encodeURIComponent(s)}/unlink`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({path:o})});if(!a.ok){const l=await a.json().catch(()=>({}));throw new Error(l.error??`Delete failed (${a.status})`)}return a.json()},onMutate:async({blockKey:r})=>{const o=`${t}/${e}/${s}`,a=Bt.decofile(o);await i.cancelQueries({queryKey:a});const l=i.getQueryData(a);return i.setQueryData(a,h=>{if(!h)return h;const{[r]:c,...d}=h;return d}),{previous:l,queryKey:a}},onError:(r,o,a)=>{a?.queryKey&&i.setQueryData(a.queryKey,a.previous)},onSuccess:()=>{const r=`${t}/${e}/${s}`;i.invalidateQueries({queryKey:Bt.liveMeta(r)})}})}function ln(t,e){return`${t}-${e}`}function ka(t,e){return`site/apps/${t}/${e}.ts`}function ja(t){const e=t.match(/^site\/apps\/([^/]+)\/([^/.]+)\.tsx?$/);if(e)return{vendor:e[1],app:e[2]};const s=t.match(/^([^/]+)\/apps\/([^/.]+)\.tsx?$/);return s?{vendor:s[1],app:s[2]}:null}function dd(t,e,s){const i=new Set([ln(t,e),e].map(o=>o.toLowerCase())),r=ka(t,e);for(const[o,a]of Object.entries(s)){if(o.includes("/")||!a||typeof a!="object"||Array.isArray(a))continue;const l=a;if(i.has(o.toLowerCase())||l.__resolveType===r)return o}return null}function K1(t,e){const s=t.vendor.alias,i=t.name,r=dd(s,i,e);return{id:ln(s,i),app:i,vendor:s,title:t.title||t.name,description:t.description,category:t.category??"Other",logo:t.logo||void 0,resolveType:ka(s,i),blockKey:r,installed:r!==null}}function V1(t,e,s){if(t===Ri)return null;const i=ja(t);if(!i)return null;const{vendor:r,app:o}=i,a=dd(r,o,s),l=Xi(t,e);return{id:ln(r,o),app:o,vendor:r,title:l.title??o,description:l.description??"",category:"Others",logo:l.logo??l.icon,resolveType:t,blockKey:a,installed:a!==null}}function q1(t,e,s){const i=new Map;for(const o of t){const a=K1(o,s);i.set(a.id,a)}const r=e.manifest?.blocks?.apps??{};for(const o of Object.keys(r)){const a=V1(o,e,s);!a||i.has(a.id)||i.set(a.id,a)}for(const o of X1(s,e)){const a=ja(o.resolveType);if(!a)continue;const l=ln(a.vendor,a.app);i.has(l)||i.set(l,{id:l,app:a.app,vendor:a.vendor,title:o.name,description:"",category:"Installed",resolveType:o.resolveType,blockKey:o.key,installed:!0})}return[...i.values()].sort(G1)}function G1(t,e){return t.installed!==e.installed?t.installed?-1:1:t.title.localeCompare(e.title)}function Y1(t,e,s){const i=t.manifest?.blocks?.apps??{};for(const r of[ka(e,s),`site/apps/${e}/${s}.tsx`,`${e}/apps/${s}.ts`,`${e}/apps/${s}.tsx`])if(r in i)return!0;return!1}function X1(t,e){const s=[];for(const[i,r]of Object.entries(t)){if(i.includes("/")||!r||typeof r!="object"||Array.isArray(r))continue;const o=r,a=o.__resolveType;if(typeof a!="string"||zh(i,o))continue;const l=ja(a)??(()=>{const h=i.match(/^([^-]+)-(.+)$/);return h?{vendor:h[1],app:h[2]}:null})();!l||!Y1(e,l.vendor,l.app)||s.push({key:i,name:i.replace(/[-_]/g," ").replace(/\b\w/g,h=>h.toUpperCase()),resolveType:a})}return s}async function J1(){const t=await fetch("/api/deco-apps");if(!t.ok)throw new Error(`Failed to fetch deco apps: ${t.status}`);return(await t.json()).apps??[]}function Z1(t,e,s){const i=K.c(12),r=s?.enabled??!0;let o;i[0]===Symbol.for("react.memo_cache_sentinel")?(o=Bt.decoApps(),i[0]=o):o=i[0];let a;i[1]!==r?(a={queryKey:o,queryFn:J1,staleTime:3e5,retry:1,enabled:r},i[1]=r,i[2]=a):a=i[2];const l=Zs(a);let h;i[3]!==e||i[4]!==t||i[5]!==l.data?(h=t&&e?q1(l.data??[],t,e):[],i[3]=e,i[4]=t,i[5]=l.data,i[6]=h):h=i[6];const c=h,d=l.isLoading&&!l.isError;let u;return i[7]!==c||i[8]!==l.isError||i[9]!==l.refetch||i[10]!==d?(u={catalog:c,isLoading:d,isError:l.isError,refetch:l.refetch},i[7]=c,i[8]=l.isError,i[9]=l.refetch,i[10]=d,i[11]=u):u=i[11],u}const Q1=new Set(["website/pages/Page.tsx","$live/pages/LivePage.tsx"]);function ex(t){return t.includes("matchers")||t.includes("Match")}function tx(t,e){const s=t.__resolveType;return typeof s!="string"||!s||Q1.has(s)?!1:e?y_(e,s):ex(s)}function Ji(t,e,s){if(!t)return!1;const i=t.__resolveType;if(typeof i!="string"||!fa(i)||!Object.hasOwn(e,i))return!1;const r=e[i];return!r||typeof r!="object"||Array.isArray(r)?!1:tx(r,s)}function WC(t,e,s){return Ji(t,e,s)?t?.__resolveType??null:null}function ud(t,e,s){if(!t)return null;const i=t.__resolveType??"";if(!i)return null;if(Ji(t,e,s)){const a=e[i]??{},l=a.__resolveType??i,{__resolveType:h,name:c,...d}=a;return{resolveType:l,data:d,blockKey:i}}const{__resolveType:r,...o}=t;return{resolveType:i,data:o}}function sx(t,e,s){const i=ud(t,e,s);return i?{__resolveType:i.resolveType,...i.data}:{__resolveType:""}}function UC(t,e,s){if(t)return Ji(t,e,s)?sx(t,e,s):t}function ix(t,e,s,i){if(!t)return"Default";if(Ji(t,e,i)){const r=t.__resolveType??"",o=e[r];return Fh(r,o)}return s(t)}function KC(t,e,s){return{__resolveType:t,...e,name:s}}function VC(t){return{__resolveType:t}}function qC(t,e,s){const i=ud(t,e,s);return i?{resolveType:i.resolveType,formValue:i.data}:{resolveType:"",formValue:{}}}function fd(t){const e=t.__resolveType??"";return es(e)?t.section??t:t}function Hr(t){const r=(es(t.__resolveType??"")?t.section:t)?.variants?.[0];return r?.rule?.__resolveType!==Eh?null:r?.value??null}function GC(t){const e=fd(t);return{__resolveType:Th,variants:[{value:e,rule:{__resolveType:Eh}}]}}function YC(t){const e=t.__resolveType??"";if(!e)return null;if(es(e))return t.section??null;const s=Hr(t);return s?es(s.__resolveType??"")?s:{__resolveType:ol,section:fd(s)}:{__resolveType:ol,section:t}}function ar(t){const e=t.__resolveType??"";if(!e)return null;if(es(e)){const s=t.section,i=s?.__resolveType??"";return!i||!s?null:{resolveType:i,data:s}}return{resolveType:e,data:t}}function XC(t){const e=Hr(t);if(e)return ar(e);if(es(t.__resolveType??"")){const i=t.section;if(!i)return null;const r=Hr(i);return ar(r||i)}return ar(t)}function JC(t){return Hr(t)}const rx=["website/matchers/always.ts","$live/matchers/MatchAlways.ts"];function md(t){if(!t)return!1;const e=t.__resolveType??"";return e===""?Object.keys(t).length===0:rx.includes(e)||e.includes("always")}function nx(t){const e=t.variants??[];if(e.length===0)return-1;const s=e.findIndex(i=>md(i.rule));return s!==-1?s:e.length-1}function ZC(t,e,s){const i=s.variants??[];if(i.length===0)return null;const r=nx(s),o=i[r]?.value;if(!o)return null;const a=structuredClone(o);return e.isLazy?{...t,section:a}:a}function pd(t,e){return e.isMultivariate?e.isLazy?t.section??null:t:null}function QC(t,e){return Array.isArray(t.variants)?t.variants.map((s,i)=>({label:e(s.rule)||`Variant ${i+1}`,value:s.value??{},rule:s.rule})):[]}function ek(t,e){const s=t.__resolveType??"";if(!s)return null;if(es(s)){const i=t.section??t,r=i.__resolveType??s;if(!r.includes("/")&&r in e){const o=e[r]??{};return{data:{...o},resolveType:o.__resolveType??r}}return{data:{...i},resolveType:r}}if(!s.includes("/")&&s in e){const i=e[s]??{};return{data:{...i},resolveType:i.__resolveType??s}}return{data:{...t},resolveType:s}}function ox(t,e){const s=t.__resolveType??"";return es(s)?{...t,section:e}:e}function ax(t,e,s){return e.isLazy?{...t,section:s}:s}function tk(t,e,s){const i=[...t.variants??[]],r=i[e];if(!r)return t;const o=r.value??{};return i[e]={...r,value:ox(o,s)},{...t,variants:i}}function sk(t,e,s){const i=[...t.variants??[]];return i[e]?(i[e]={...i[e],rule:s},{...t,variants:i}):t}function ik(t,e){const s=[...t.variants??[]],i=s[e];return i?(s.splice(e+1,0,structuredClone(i)),{...t,variants:s}):t}function rk(t,e){const s=[...t.variants??[]];return s.length<=1?null:(s.splice(e,1),{...t,variants:s})}function Zn(t){return{rule:ma(),value:structuredClone(t)}}function _d(t,e){return{...e,__resolveType:Th,variants:t}}function nk(t){return t.isHidden!==!0&&t.isSavedBlock!==!0}function lx(t,e){if(e.isHidden)return null;if(e.isMultivariate){const i=pd(t,e)?.variants??[],r=i[i.length-1]?.value;return r?structuredClone(r):null}if(e.isLazy){const s=t.section;return s?structuredClone(s):null}return structuredClone(t)}function cx(t,e,s){if(e.isMultivariate||e.isHidden)return null;const i=lx(t,e);if(!i)return null;const r=_d([Zn(i),Zn(i)]);return e.isLazy?{...t,section:r}:r}function ok(t,e,s){if(e.isHidden||e.isSavedBlock)return null;if(e.isMultivariate){const r=pd(t,e);if(!r)return null;const o=r.variants??[],a=o[o.length-1]?.value;if(!a)return null;const l=_d([...o,Zn(a)],r);return{section:ax(t,e,l),newVariantIndex:o.length}}const i=cx(t,e);return i?{section:i,newVariantIndex:1}:null}const hx=new Set(["website/pages/Page.tsx","$live/pages/LivePage.tsx"]);function ak(t){return t.anyOfRefs?.some(e=>e.resolveType!==on?!1:e.schema?.properties?.variants?.items?.properties?.value?.type==="array")??!1}function gd(t){return!t||typeof t!="object"||Array.isArray(t)?!1:t.__resolveType===on}function lk(t){if(!gd(t))return null;const e=t.variants;if(!Array.isArray(e))return null;const s=e[0]?.value;return Array.isArray(s)?s:null}function ck(t,e){if(!gd(t))return e;const s=structuredClone(t),i=[...s.variants??[]];return i.length===0?i.push({rule:ma(),value:e}):i[0]={...i[0],value:e},{...s,variants:i}}function dx(t){if(!t||typeof t!="object"||Array.isArray(t))return!1;const e=t;return typeof e.__resolveType=="string"&&hx.has(e.__resolveType)&&typeof e.path=="string"}function vd(t,e){const i=t[e]?.sections;if(!i||Array.isArray(i))return 1;const r=i;return Array.isArray(r.variants)?r.variants.length:1}function ux(t,e,s){const r=t[e]?.sections;if(Array.isArray(r))return s===0?r:[];if(r&&typeof r=="object"){const o=r.variants;if(Array.isArray(o)){const a=o[s];return Array.isArray(a?.value)?a.value:[]}}return[]}function hk(t,e,s){if(Array.isArray(t))return[{label:"Default",sections:t}];if(t&&typeof t=="object"){const i=t;if(Array.isArray(i.variants)){const r=i.variants,o=r.map(h=>ix(h.rule,e,s)),a=o.reduce((h,c)=>(h[c]=(h[c]??0)+1,h),{}),l={};return r.map((h,c)=>{const d=o[c]??`Variant ${c+1}`,u=a[d]??1;let f=d;return u>1&&(l[d]=(l[d]??0)+1,f=`${d} ${l[d]}`),{label:f||`Variant ${c+1}`,sections:Array.isArray(h.value)?h.value:[],rule:h.rule}})}}return[]}function fi(t){return{rule:ma(),value:t}}function Ks(t,e){return{...e,__resolveType:on,variants:t}}function fx(t,e){const s=structuredClone(e);if(Array.isArray(t))return Ks([fi(t),fi(s)]);if(t&&typeof t=="object"){const i=t;return Array.isArray(i.variants)?Ks([...i.variants,fi(s)],i):null}return Ks([fi([]),fi(s)])}function dk(t){const e=t.variants;return Array.isArray(e)?e.length-1:1}function uk(t,e){if(e.length===0)return Ks([],t);if(e.length===1){const s=e[0],i=s?.rule;if(!md(i))return Ks(e,t);if(Array.isArray(s?.value))return s.value}return Ks(e,t)}function mx(t,e){for(const[s,i]of Object.entries(t)){if(!dx(i))continue;const r=i.sections;if(Array.isArray(r)){e(void 0,s,0);continue}if(!r||typeof r!="object")continue;const o=r.variants;if(Array.isArray(o))for(let a=0;a<o.length;a++){const l=o[a];e(l?.rule,s,a)}}}function fk(t,e,s){let i=0;return mx(t,r=>{if(!r)return;(r.__resolveType??"")===e&&Ji(r,t,s)&&i++}),i}function wl(t,e){const s=e.replace(/\s*\(copy(?:\s+\d+)?\)\s*$/,"").trim(),i=`${s} (copy)`;if(!t.has(i))return i;for(let r=2;r<1e3;r++){const o=`${s} (copy ${r})`;if(!t.has(o))return o}return`${s} (copy ${Date.now()})`}function px(t,e){const s=Us,i=e.replace(/-copy(?:-\d+)?$/,""),r=`${i}-copy`;if(!t.has(s(r)))return r;for(let o=2;o<1e3;o++){const a=`${i}-copy-${o}`;if(!t.has(s(a)))return a}return`${i}-copy-${Date.now()}`}function Cl(t,e){const s=e.replace(/_copy(?:_\d+)?$/,""),i=`${s}_copy`;if(!Object.hasOwn(t,i))return i;for(let r=2;r<1e3;r++){const o=`${s}_copy_${r}`;if(!Object.hasOwn(t,o))return o}return`${s}_copy_${Date.now()}`}function _x(t){const e=wa(t.newName),s={...t.source,name:t.newName,path:t.newPath};return{key:e,data:s}}function gx(t,e){return nd(t,e)}const vx=1e3;function xx(t,e){for(let s=0;s<vx;s++){const i=wa(e);if(!Object.hasOwn(t,i))return i}throw new Error("Could not generate a unique page block key")}const bx={create:"Create new page",duplicate:"Duplicate page",rename:"Rename page"},yx={create:"Create",duplicate:"Duplicate",rename:"Save"},Sx={create:"Creating…",duplicate:"Duplicating…",rename:"Saving…"};function wx(t){const e=K.c(54),{open:s,mode:i,initialName:r,initialPath:o,isPending:a,error:l,validate:h,onSubmit:c,onOpenChange:d}=t,u=a===void 0?!1:a,[f,m]=E.useState(r),[p,_]=E.useState(o),[g,v]=E.useState(null),[b,x]=E.useState(s);s!==b&&(x(s),s&&(m(r),_(o),v(null)));let y;e[0]!==u||e[1]!==d?(y=H=>{!H&&!u&&(v(null),d(!1))},e[0]=u,e[1]=d,e[2]=y):y=e[2];const w=y;let C;e[3]!==u||e[4]!==f||e[5]!==c||e[6]!==p||e[7]!==h?(C=async H=>{H.preventDefault();const X=f.trim(),oe=p.trim();if(!X||!oe||u)return;const L=pa(oe);if(L){v(L);return}const se=h?.({name:X,path:oe});if(se){v(se);return}v(null),await c({name:X,path:oe})},e[3]=u,e[4]=f,e[5]=c,e[6]=p,e[7]=h,e[8]=C):C=e[8];const j=C,R=g??l,B=bx[i];let P;e[9]!==B?(P=n.jsx(is,{children:n.jsx(rs,{children:B})}),e[9]=B,e[10]=P):P=e[10];let T;e[11]===Symbol.for("react.memo_cache_sentinel")?(T=n.jsx("label",{htmlFor:"page-form-name",className:"text-xs font-medium text-muted-foreground",children:"Name"}),e[11]=T):T=e[11];let S;e[12]===Symbol.for("react.memo_cache_sentinel")?(S=H=>m(H.target.value),e[12]=S):S=e[12];let k;e[13]!==u||e[14]!==f?(k=n.jsxs("div",{className:"space-y-1.5",children:[T,n.jsx(qe,{id:"page-form-name",value:f,onChange:S,placeholder:"My page",autoFocus:!0,disabled:u})]}),e[13]=u,e[14]=f,e[15]=k):k=e[15];let I;e[16]===Symbol.for("react.memo_cache_sentinel")?(I=n.jsx("label",{htmlFor:"page-form-path",className:"text-xs font-medium text-muted-foreground",children:"Path"}),e[16]=I):I=e[16];let N;e[17]===Symbol.for("react.memo_cache_sentinel")?(N=H=>_(H.target.value),e[17]=N):N=e[17];let A;e[18]!==u||e[19]!==p?(A=n.jsxs("div",{className:"space-y-1.5",children:[I,n.jsx(qe,{id:"page-form-path",value:p,onChange:N,placeholder:"/example",disabled:u})]}),e[18]=u,e[19]=p,e[20]=A):A=e[20];let M;e[21]!==R?(M=R&&n.jsx("p",{className:"text-xs text-destructive",children:R}),e[21]=R,e[22]=M):M=e[22];let D;e[23]!==A||e[24]!==M||e[25]!==k?(D=n.jsxs("div",{className:"space-y-4 py-4",children:[k,A,M]}),e[23]=A,e[24]=M,e[25]=k,e[26]=D):D=e[26];let $;e[27]!==d?($=()=>d(!1),e[27]=d,e[28]=$):$=e[28];let z;e[29]!==u||e[30]!==$?(z=n.jsx(re,{type:"button",variant:"outline",onClick:$,disabled:u,children:"Cancel"}),e[29]=u,e[30]=$,e[31]=z):z=e[31];let W;e[32]!==u||e[33]!==f||e[34]!==p?(W=!f.trim()||!p.trim()||u,e[32]=u,e[33]=f,e[34]=p,e[35]=W):W=e[35];let F;e[36]!==u||e[37]!==i?(F=u?n.jsxs(n.Fragment,{children:[n.jsx(Ce,{size:14,className:"animate-spin"}),Sx[i]]}):yx[i],e[36]=u,e[37]=i,e[38]=F):F=e[38];let V;e[39]!==W||e[40]!==F?(V=n.jsx(re,{type:"submit",disabled:W,children:F}),e[39]=W,e[40]=F,e[41]=V):V=e[41];let J;e[42]!==z||e[43]!==V?(J=n.jsxs(ii,{children:[z,V]}),e[42]=z,e[43]=V,e[44]=J):J=e[44];let Y;e[45]!==j||e[46]!==D||e[47]!==J||e[48]!==P?(Y=n.jsx(Ot,{className:"sm:max-w-md",children:n.jsxs("form",{onSubmit:j,children:[P,D,J]})}),e[45]=j,e[46]=D,e[47]=J,e[48]=P,e[49]=Y):Y=e[49];let U;return e[50]!==w||e[51]!==s||e[52]!==Y?(U=n.jsx(Lt,{open:s,onOpenChange:w,children:Y}),e[50]=w,e[51]=s,e[52]=Y,e[53]=U):U=e[53],U}function Cx(t){const e=K.c(43),{open:s,blockKey:i,initialName:r,isPending:o,onSubmit:a,onOpenChange:l}=t,h=o===void 0?!1:o,[c,d]=E.useState(r),[u,f]=E.useState(s);s!==u&&(f(s),s&&d(r));let m;e[0]!==h||e[1]!==l?(m=A=>{!A&&!h&&l(!1)},e[0]=h,e[1]=l,e[2]=m):m=e[2];const p=m;let _;e[3]!==h||e[4]!==c||e[5]!==a?(_=async A=>{A.preventDefault();const M=c.trim();!M||h||await a(M)},e[3]=h,e[4]=c,e[5]=a,e[6]=_):_=e[6];const g=_;let v;e[7]===Symbol.for("react.memo_cache_sentinel")?(v=n.jsxs(is,{children:[n.jsx(rs,{children:"Rename section"}),n.jsx(Jo,{children:"Updates the display name. The internal key stays the same so pages referencing this section keep working."})]}),e[7]=v):v=e[7];let b;e[8]===Symbol.for("react.memo_cache_sentinel")?(b=n.jsx("label",{htmlFor:"section-rename-name",className:"text-xs font-medium text-muted-foreground",children:"Name"}),e[8]=b):b=e[8];let x;e[9]===Symbol.for("react.memo_cache_sentinel")?(x=A=>d(A.target.value),e[9]=x):x=e[9];let y;e[10]!==h||e[11]!==c?(y=n.jsxs("div",{className:"space-y-1.5",children:[b,n.jsx(qe,{id:"section-rename-name",value:c,onChange:x,autoFocus:!0,disabled:h})]}),e[10]=h,e[11]=c,e[12]=y):y=e[12];let w;e[13]===Symbol.for("react.memo_cache_sentinel")?(w=n.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"Key"}),e[13]=w):w=e[13];let C;e[14]!==i?(C=n.jsxs("div",{className:"space-y-1.5",children:[w,n.jsx(qe,{value:i,readOnly:!0,disabled:!0,className:"font-mono"})]}),e[14]=i,e[15]=C):C=e[15];let j;e[16]!==y||e[17]!==C?(j=n.jsxs("div",{className:"space-y-4 py-4",children:[y,C]}),e[16]=y,e[17]=C,e[18]=j):j=e[18];let R;e[19]!==l?(R=()=>l(!1),e[19]=l,e[20]=R):R=e[20];let B;e[21]!==h||e[22]!==R?(B=n.jsx(re,{type:"button",variant:"outline",onClick:R,disabled:h,children:"Cancel"}),e[21]=h,e[22]=R,e[23]=B):B=e[23];let P;e[24]!==h||e[25]!==c?(P=!c.trim()||h,e[24]=h,e[25]=c,e[26]=P):P=e[26];let T;e[27]!==h?(T=h?n.jsxs(n.Fragment,{children:[n.jsx(Ce,{size:14,className:"animate-spin"}),"Saving…"]}):"Save",e[27]=h,e[28]=T):T=e[28];let S;e[29]!==P||e[30]!==T?(S=n.jsx(re,{type:"submit",disabled:P,children:T}),e[29]=P,e[30]=T,e[31]=S):S=e[31];let k;e[32]!==B||e[33]!==S?(k=n.jsxs(ii,{children:[B,S]}),e[32]=B,e[33]=S,e[34]=k):k=e[34];let I;e[35]!==g||e[36]!==j||e[37]!==k?(I=n.jsx(Ot,{className:"sm:max-w-md",children:n.jsxs("form",{onSubmit:g,children:[v,j,k]})}),e[35]=g,e[36]=j,e[37]=k,e[38]=I):I=e[38];let N;return e[39]!==p||e[40]!==s||e[41]!==I?(N=n.jsx(Lt,{open:s,onOpenChange:p,children:I}),e[39]=p,e[40]=s,e[41]=I,e[42]=N):N=e[42],N}const wn={post:"blog/loaders/Blogpost.ts",author:"blog/loaders/Author.ts",category:"blog/loaders/Category.ts"},kx="blog/sections/blocks/",Na=["posts","authors","categories"],Pi={posts:"post",authors:"author",categories:"category"};function Di(t){return Na.includes(t)}const Ea={posts:"post",authors:"author",categories:"category"},xd={posts:wn.post,authors:wn.author,categories:wn.category},jx=Object.fromEntries(Object.entries(xd).map(([t,e])=>[e,t]));function Nx(t){return typeof t=="string"?jx[t]??null:null}function Wr(t){return t&&typeof t=="object"&&!Array.isArray(t)?t:null}function $s(t){return typeof t=="string"?t:""}function Ex(t,e){switch(t){case"posts":return{label:$s(e.title)||"Untitled post",subtitle:$s(e.slug)};case"authors":return{label:$s(e.name)||"Unnamed author",subtitle:$s(e.email)};case"categories":return{label:$s(e.name)||"Unnamed category",subtitle:$s(e.slug)};default:{const s=t;throw new Error(`Unhandled blog kind: ${String(s)}`)}}}function bd(t){const e={posts:[],authors:[],categories:[]};for(const[s,i]of Object.entries(t)){const r=Wr(i);if(!r)continue;const o=Nx(r.__resolveType);if(!o)continue;const a=Wr(r[Ea[o]])??{},{label:l,subtitle:h}=Ex(o,a);e[o].push({key:s,kind:o,label:l,subtitle:h})}for(const s of Na)e[s].sort((i,r)=>i.label.localeCompare(r.label));return e}function Tx(t,e){return bd(t)[e]}function mk(t,e){return Tx(t,e).map(s=>({key:s.key,payload:yd(Wr(t[s.key])??void 0,e)}))}function yd(t,e){return t?Wr(t[Ea[e]])??{}:{}}function kl(t,e,s){return{name:t,__resolveType:xd[e],[Ea[e]]:s}}function Sd(t){return`.deco/blocks/${encodeURIComponent(t)}.json`}function Qn(t){const e=new Uint8Array(Math.ceil(t/2));return crypto.getRandomValues(e),Array.from(e,s=>s.toString(16).padStart(2,"0")).join("").slice(0,t)}function jl(t,e){const s=`collections/blog/${e}/${Qn(12)}`;if(!Object.hasOwn(t,s))return s;throw new Error("Could not generate a unique blog block key")}function Rx(t){switch(t){case"posts":return{title:"Untitled post",excerpt:"",slug:`untitled-${Qn(8)}`,date:new Date().toISOString().slice(0,10),image:"",authors:[],categories:[],sections:[]};case"authors":return{name:"New author",email:"",jobTitle:"",company:"",avatar:""};case"categories":return{name:"New category",slug:`category-${Qn(8)}`};default:{const e=t;throw new Error(`Unhandled blog kind: ${String(e)}`)}}}function pk(t){const e=new Set,s=[],i=t.manifest?.blocks??{};for(const r of Object.values(i))for(const o of Object.keys(r)){if(!o.startsWith(kx)||e.has(o))continue;e.add(o);const a=Xi(o,t);s.push({resolveType:o,title:a.title??Px(o),description:a.description,icon:a.icon})}return s.sort((r,o)=>r.title.localeCompare(o.title))}function Px(t){return(t.split("/").pop()??t).replace(/\.(tsx?|jsx?)$/,"")}const Dx=["blog/sections/blocks/","site/sections/Blog/Post/"];function _k(t){return Dx.some(e=>t.startsWith(e))}function wd({orgSlug:t,virtualMcpId:e,branch:s}){return Bt.decofile(`${t}/${e}/${s}`)}function Cd({orgSlug:t,virtualMcpId:e,branch:s},i){return`/api/${t}/sandbox/${encodeURIComponent(e)}/${encodeURIComponent(s)}/${i}`}function Ax(t){const e=K.c(11),s=Qs();let i;e[0]!==t?(i=async l=>{const{blockKey:h,data:c}=l,d=await fetch(Cd(t,"write"),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({path:Sd(h),content:JSON.stringify(c,null,2)})});if(!d.ok){const u=await d.json().catch(Ix);throw new Error(u.error??`Write failed (${d.status})`)}return d.json()},e[0]=t,e[1]=i):i=e[1];let r;e[2]!==t||e[3]!==s?(r=async l=>{const{blockKey:h,data:c}=l,d=wd(t);await s.cancelQueries({queryKey:d});const u=s.getQueryData(d);return s.setQueryData(d,f=>({...f??{},[h]:c})),{previous:u,queryKey:d}},e[2]=t,e[3]=s,e[4]=r):r=e[4];let o;e[5]!==s?(o=(l,h,c)=>{c?.queryKey&&s.setQueryData(c.queryKey,c.previous)},e[5]=s,e[6]=o):o=e[6];let a;return e[7]!==i||e[8]!==r||e[9]!==o?(a={mutationFn:i,onMutate:r,onError:o},e[7]=i,e[8]=r,e[9]=o,e[10]=a):a=e[10],ei(a)}function Ix(){return{}}function Bx(t){const e=Qs();return ei({mutationFn:async({blockKey:s})=>{const i=await fetch(Cd(t,"unlink"),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({path:Sd(s)})});if(!i.ok){const r=await i.json().catch(()=>({}));throw new Error(r.error??`Delete failed (${i.status})`)}return i.json()},onMutate:async({blockKey:s})=>{const i=wd(t);await e.cancelQueries({queryKey:i});const r=e.getQueryData(i);return e.setQueryData(i,o=>{if(!o)return o;const{[s]:a,...l}=o;return l}),{previous:r,queryKey:i}},onError:(s,i,r)=>{r?.queryKey&&e.setQueryData(r.queryKey,r.previous)}})}function Mx(t){const e=K.c(20),{open:s,onOpenChange:i,pageKey:r,decofile:o}=t,[a,l]=E.useState(!1),h=o[r];let c;e[0]!==h?(c=h===void 0?"// Page not found.":JSON.stringify(h,null,2),e[0]=h,e[1]=c):c=e[1];const d=c;let u;e[2]!==d?(u=()=>{navigator.clipboard.writeText(d).then(()=>{l(!0),setTimeout(()=>l(!1),2e3)})},e[2]=d,e[3]=u):u=e[3];const f=u;let m;e[4]===Symbol.for("react.memo_cache_sentinel")?(m=n.jsx(rs,{className:"text-sm font-semibold",children:"Page JSON"}),e[4]=m):m=e[4];let p;e[5]!==a?(p=a?n.jsx(zc,{size:12}):n.jsx(Qt,{size:12}),e[5]=a,e[6]=p):p=e[6];const _=a?"Copied":"Copy";let g;e[7]!==f||e[8]!==p||e[9]!==_?(g=n.jsxs(is,{className:"px-4 py-3 border-b flex-row items-center justify-between space-y-0",children:[m,n.jsxs(re,{variant:"ghost",size:"sm",onClick:f,className:"h-7 gap-1.5 text-xs",children:[p,_]})]}),e[7]=f,e[8]=p,e[9]=_,e[10]=g):g=e[10];let v;e[11]!==d?(v=n.jsx(rn,{className:"max-h-[70vh]",children:n.jsx("pre",{className:"p-4 text-xs font-mono text-foreground/90 whitespace-pre overflow-auto",children:d})}),e[11]=d,e[12]=v):v=e[12];let b;e[13]!==g||e[14]!==v?(b=n.jsxs(Ot,{className:"max-w-2xl p-0 gap-0",children:[g,v]}),e[13]=g,e[14]=v,e[15]=b):b=e[15];let x;return e[16]!==i||e[17]!==s||e[18]!==b?(x=n.jsx(Lt,{open:s,onOpenChange:i,children:b}),e[16]=i,e[17]=s,e[18]=b,e[19]=x):x=e[19],x}const Nl=E.lazy(()=>qt(()=>import("./app-editor-mnWJa4OB.js"),__vite__mapDeps([156,1,2,4,46,47,48,16,3,5,153,135,81,22,136,100,20,49,44,21,51,18,29,30,76,6,7,8,9,10,11,12,13,14,15,17,19,23,24,25,26,27,28,31,32,33,34,35,36,37,38,39,40,41,42,43,45,77,50,72,78,73,79,80,82,83,84,60,61,157,89,90,91,58,92,93,94,57,95,59,96,97,98,99,101,102,103,104,105,106,107,66,108,56,109,71,110,70,67,111,112,113,114,115,116,65,86,87,52,53,54,55,62,63,64,68,69,74,75,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152])).then(t=>({default:t.AppEditor}))),Lx=E.lazy(()=>qt(()=>import("./post-editor-Dkob_Nf9.js"),__vite__mapDeps([158,1,2,3,6,7,8,9,10,11,12,13,14,15,16,17,4,5,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,49,70,48,71,72,50,47,73,74,75,96,97,98,46,99,100,101,102,90,91,92,93,84,94,95,103,104,105,106,107,108,109,110,149,121,150,132,151,128,130,147,114,86,87,78,80,51,81,82,83,76,77,79,159,157,89,111,112,113,115,116,117,118,119,120,122,123,124,125,126,127,129,131,133,134,135,136,137,138,139,140,141,142,143,144,145,146,148,152])).then(t=>({default:t.PostEditor}))),Ox=E.lazy(()=>qt(()=>import("./record-editor-DhS1gQiJ.js"),__vite__mapDeps([160,1,2,50,72,73,80,8,39,40,7,16,20,18,6,9,10,11,12,13,14,15,3,17,4,5,19,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,41,42,43,44,45,49,51,81,82,83,84,60,61,159,157,89,90,91,58,92,93,94,57,95,59,96,97,98,46,47,48,99,100,101,102,103,104,105,106,107,66,108,56,109,71,110,70,67,111,112,113,114,115,116,65,78,86,87,52,53,54,55,62,63,64,68,69,74,75,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,79,139,140,141,142,143,144,145,146,147,148,149,150,151,152])).then(t=>({default:t.RecordEditor}))),$x=E.lazy(()=>qt(()=>import("./sections-editor-DPjqmRcC.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153])).then(t=>({default:t.SectionsEditor}))),zx=E.lazy(()=>qt(()=>import("./seo-editor-70uW1Cgu.js"),__vite__mapDeps([161,1,2,4,6,7,8,9,10,11,12,13,14,15,16,3,17,5,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,85,72,79,76,77,50,78,73,51,80,49,81,82,83,84,60,61,89,90,91,58,92,93,94,57,95,59,96,97,98,99,100,101,102,103,104,105,106,107,66,108,56,109,71,110,70,67,111,112,113,114,115,116,65,86,87,52,53,54,55,62,63,64,68,69,74,75,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152])).then(t=>({default:t.SeoEditor}))),Fx=E.lazy(()=>qt(()=>import("./add-section-modal-DsL7vxG4.js"),__vite__mapDeps([88,1,2,6,7,8,9,10,11,12,13,14,15,16,3,17,4,5,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,49,50,89,90,91,58,92,93,84,94,57,95,59,96,97,98,46,47,48,99,100,101,102,103,104,105,106,107,66,108,56,109,71,72,110,70,67,82,111,112,113,114,81,115,116,65,78,86,87,60,61,52,53,54,55,62,63,64,68,69,73,74,75,117,51,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,79,139,140,141,142,143,144,145,146,147,148,149,150,151,152])).then(t=>({default:t.AddSectionModal}))),eo="oklch(0.65 0.15 160)";function Hx(){const t=K.c(18),e=sr(),{data:s}=Js.useSession(),{currentBranch:i}=ss(),{org:r}=Pe(),o=e?.entity?.id??null,a=s?.user?.id,l=e?.entity?.metadata,h=a&&i?Jr(l?.sandboxMap?.[a]?.[i]):{},c=Object.values(h),u=(c.find(Wx)??c[0])?.previewUrl??null,f=Yt(),m=e?.entity?.organization_id??"";let p;t[0]!==r.slug||t[1]!==m?(p={connectionId:Ho,orgId:m,orgSlug:r.slug},t[0]=r.slug,t[1]=m,t[2]=p):p=t[2];const _=ft(p),g=zo(_);let v;t[3]!==i||t[4]!==g||t[5]!==o?(v=()=>{if(!o)return;const C={virtualMcpId:o};i&&(C.branch=i),g.mutate(C)},t[3]=i,t[4]=g,t[5]=o,t[6]=v):v=t[6];const b=v,x=!!o&&!!i&&$n.isStopped(o,i),y=ed({previewUrl:u,appPaused:f.status.state==="paused",userStopped:x});if(y.kind!=="iframe"){let C;return t[7]!==y||t[8]!==b||t[9]!==f.lifecycle||t[10]!==f.phase?(C=n.jsx(Yx,{state:y,claimPhase:f.phase,lifecycle:f.lifecycle,onStart:b}),t[7]=y,t[8]=b,t[9]=f.lifecycle,t[10]=f.phase,t[11]=C):C=t[11],C}if(!o||!i){let C;return t[12]===Symbol.for("react.memo_cache_sentinel")?(C=n.jsx(Si,{title:"Waiting for sandbox context…"}),t[12]=C):C=t[12],C}let w;return t[13]!==i||t[14]!==r.slug||t[15]!==u||t[16]!==o?(w=n.jsx(Kx,{orgSlug:r.slug,virtualMcpId:o,branch:i,previewUrl:u}),t[13]=i,t[14]=r.slug,t[15]=u,t[16]=o,t[17]=w):w=t[17],w}function Wx(t){return t.sandboxProviderKind!=="user-desktop"}const El=2e3,Ux=15;function Tl(t,e,s,i){return typeof e!="string"||s&&(hd(e,s,i)||t.state.dataUpdateCount>=Ux)?!1:El}function Kx({orgSlug:t,virtualMcpId:e,branch:s,previewUrl:i}){const r={orgSlug:t,virtualMcpId:e,branch:s},{data:o,isLoading:a}=ha(r),[l,h]=E.useState("pages"),[c,d]=E.useState(null),[u,f]=E.useState(null),[m,p]=E.useState(""),[_,g]=E.useState(l);_!==l&&(g(l),p(""));const{data:v,isLoading:b,isFetching:x}=da(r,{refetchInterval:G=>{const _e=G.state.data;if(l==="apps"&&c&&c.collection==="apps"){const xe=o?.[c.key];return Tl(G,typeof xe?.__resolveType=="string"?xe.__resolveType:void 0,_e)}if(l==="site"&&o){const xe=_e?Jn(o,_e):null,Se=o.site,we=xe?.resolveType??(typeof Se?.__resolveType=="string"?Se.__resolveType:void 0);return Tl(G,we,_e,["seo"])}return!1}}),y=(G,_e)=>!hd(G,v,_e)&&(b||x),{catalog:w,isLoading:C}=Z1(v??void 0,o??void 0,{enabled:l==="apps"}),j=Ca(r),R=U1(r),B=Ax(r),P=Bx(r),[T,S]=E.useState(null),[k,I]=E.useState(),[N,A]=E.useState(!1),[M,D]=E.useState(null),[$,z]=E.useState(null),[W,F]=E.useState(null);if(a||b)return n.jsx("div",{className:"h-full w-full flex items-center justify-center",children:n.jsx(Ce,{size:20,className:"animate-spin text-muted-foreground"})});if(!o||!v)return n.jsx(Si,{title:"Could not load site data."});const V=va(o).sort((G,_e)=>G.name.localeCompare(_e.name)),J=xa(o,v),Y=Jn(o,v),U=bd(o),H=Na.some(G=>U[G].length>0),X=Di(l)?U[l]:[];if(!ga(o,v)&&!H)return n.jsx(Si,{icon:Ui,title:"No editable content",description:"This project doesn't expose any Deco pages, sections, or apps."});const oe={pages:V.length,sections:J.length,apps:w.length,posts:U.posts.length,authors:U.authors.length,categories:U.categories.length},L=new Set(V.map(G=>Us(G.path))),se=new Set(V.map(G=>G.name)),ee=new Set(J.map(G=>G.name)),Q=async G=>{const _e=o[G.key];if(!_e)return;const xe=vd(o,G.key),Se=ux(o,G.key,Math.max(0,xe-1)),we=fx(_e.sections,Se);if(we)try{await j.mutateAsync({blockKey:G.key,data:{..._e,sections:we}}),le.success(`Variant added to "${G.name}"`),d({collection:"pages",key:G.key,path:G.path})}catch(et){le.error(et instanceof Error?et.message:"Could not add variant")}},O=()=>{I(void 0),S({mode:"create",sourceKey:null,initialName:"My new page",initialPath:"/example"})},ce=G=>{I(void 0),S({mode:"duplicate",sourceKey:G.key,initialName:wl(se,G.name),initialPath:px(L,G.path)})},ue=G=>{I(void 0),S({mode:"rename",sourceKey:G.key,initialName:G.name,initialPath:G.path})},fe=async G=>{if(!T)return;const{mode:_e,sourceKey:xe}=T;try{if(_e==="create"){const Se=gx(G.name,G.path),we=xx(o,G.name);await j.mutateAsync({blockKey:we,data:Se}),le.success(`Created "${G.name}"`),d({collection:"pages",key:we,path:G.path})}else if(_e==="duplicate"&&xe){const Se=o[xe];if(!Se)throw new Error("Source page not found");const{key:we,data:et}=_x({source:Se,pages:V,newName:G.name,newPath:G.path});await j.mutateAsync({blockKey:we,data:et}),le.success(`Duplicated as "${G.name}"`),d({collection:"pages",key:we,path:G.path})}else if(_e==="rename"&&xe){const Se=o[xe];if(!Se)throw new Error("Page not found");const we={...Se,name:G.name,path:G.path};await j.mutateAsync({blockKey:xe,data:we}),le.success("Page updated"),c?.collection==="pages"&&c.key===xe&&d({collection:"pages",key:xe,path:G.path})}S(null)}catch(Se){I(Se instanceof Error?Se.message:"Save failed")}},q=({path:G})=>{if(!T)return null;const _e=Us(G);return(T.mode==="rename"?Us(T.initialPath):null)!==_e&&L.has(_e)?`A page with path "${G}" already exists.`:null},te=async G=>{const _e=(G.title||G.resolveType.split("/").pop()||"").replace(/\.(tsx?|jsx?)$/,"").replace(/[^A-Za-z0-9_-]/g,""),xe=/^[A-Za-z]/.test(_e)&&_e.length>0?_e:"Section",Se=Cl(o,xe),we={__resolveType:G.resolveType,name:Se};try{await j.mutateAsync({blockKey:Se,data:we}),le.success(`Created section "${Se}"`),A(!1),d({collection:"sections",key:Se})}catch(et){le.error(et instanceof Error?et.message:"Could not create section")}},me=async G=>{const _e=o[G.key];if(!_e){le.error("Section not found.");return}const xe=Cl(o,G.key),Se=wl(ee,G.name),we={..._e,name:Se};try{await j.mutateAsync({blockKey:xe,data:we}),le.success(`Duplicated "${G.name}"`),d({collection:"sections",key:xe})}catch(et){le.error(et instanceof Error?et.message:"Duplicate failed")}},ne=async G=>{if(!M)return;const _e=o[M];if(!_e){le.error("Section not found.");return}try{await j.mutateAsync({blockKey:M,data:{..._e,name:G}}),le.success("Section renamed"),D(null)}catch(xe){le.error(xe instanceof Error?xe.message:"Rename failed")}},ke=async G=>{const _e=jl(o,G),xe=kl(_e,G,Rx(G));try{await B.mutateAsync({blockKey:_e,data:xe}),le.success(`Created ${Pi[G]}`),d({collection:G,key:_e})}catch(Se){le.error(Se instanceof Error?Se.message:"Could not create")}},at=async G=>{const _e=o[G.key];if(!_e){le.error("Record not found.");return}const xe=jl(o,G.kind),Se=G.kind==="posts"?"title":"name",we={...structuredClone(yd(_e,G.kind)),[Se]:`${G.label} (copy)`};try{await B.mutateAsync({blockKey:xe,data:kl(xe,G.kind,we)}),le.success(`Duplicated "${G.label}"`),d({collection:G.kind,key:xe})}catch(et){le.error(et instanceof Error?et.message:"Duplicate failed")}},Be=async()=>{if(!$)return;const{kind:G,key:_e,label:xe}=$;try{G==="blog"?await P.mutateAsync({blockKey:_e}):await R.mutateAsync({blockKey:_e}),le.success(`Deleted "${xe}"`),c&&c.key===_e&&d(null),z(null)}catch(Se){le.error(Se instanceof Error?Se.message:"Delete failed")}},mt=R.isPending||P.isPending,as=$?.kind==="blog"?Pi[$.blogKind]:$?.kind??"item";return n.jsxs("div",{className:"flex h-full w-full",children:[n.jsx(Vx,{active:l,counts:oe,showBlog:H,onSelect:G=>{h(G),d(null),f(null)}}),l!=="seo"&&l!=="site"&&n.jsx(qx,{activeCollection:l,pages:V,sections:J,appCatalog:w,appCatalogLoading:C,blogEntries:X,decofile:o,searchQuery:m,onSearchChange:p,selection:c,onSelect:G=>{d(G),f(null)},previewUrl:i,onCreate:()=>{l==="pages"?O():Di(l)?ke(l):i?A(!0):le.error("Start the preview dev server to add sections.")},onDuplicatePage:ce,onRenamePage:ue,onAddPageVariant:Q,onDeletePage:G=>z({kind:"page",key:G.key,label:G.name}),onEditPageSeo:G=>{d({collection:"pages",key:G.key,path:G.path}),f(G.key)},onViewPageJson:G=>F(G.key),onDuplicateSection:me,onRenameSection:G=>D(G.key),onDeleteSection:G=>z({kind:"section",key:G.key,label:G.name}),onDuplicateBlog:at,onDeleteBlog:G=>z({kind:"blog",blogKind:G.kind,key:G.key,label:G.label})}),n.jsx("div",{className:"flex-1 min-w-0",children:n.jsx(E.Suspense,{fallback:n.jsx("div",{className:"h-full flex items-center justify-center",children:n.jsx(Ce,{size:20,className:"animate-spin text-muted-foreground"})}),children:l==="site"?Y?n.jsx(Nl,{orgSlug:t,virtualMcpId:e,branch:s,blockKey:Y.key,block:o[Y.key],decofile:o,meta:v,title:"Site",excludeFields:["seo"],schemaPending:y(Y.resolveType,["seo"])},`site:${Y.key}`):n.jsx(Si,{title:"Site settings not found",description:"This project doesn't have a site app block (site/apps/site.ts)."}):l==="seo"?n.jsx(zx,{orgSlug:t,virtualMcpId:e,branch:s,decofile:o,meta:v,target:{kind:"site"},previewBaseUrl:i}):c?c.collection==="apps"?n.jsx(Nl,{orgSlug:t,virtualMcpId:e,branch:s,blockKey:c.key,block:o[c.key],decofile:o,meta:v,schemaPending:y(typeof o[c.key]?.__resolveType=="string"?String(o[c.key].__resolveType):void 0)},`app:${c.key}`):c.collection==="posts"?n.jsx(Lx,{orgSlug:t,virtualMcpId:e,branch:s,blockKey:c.key,block:o[c.key],decofile:o,meta:v},`post:${c.key}`):c.collection==="authors"||c.collection==="categories"?n.jsx(Ox,{orgSlug:t,virtualMcpId:e,branch:s,kind:c.collection,blockKey:c.key,block:o[c.key]},`${c.collection}:${c.key}`):n.jsx($x,{orgSlug:t,virtualMcpId:e,branch:s,previewReady:!0,previewUrl:i??void 0,currentPath:c.collection==="pages"?c.path:"/",activePageBlockKey:c.collection==="pages"?c.key:null,activeGlobalBlockKey:c.collection==="sections"?c.key:null,initialEditSeo:c.collection==="pages"&&u===c.key,onExitSeo:()=>f(null)},c.collection==="pages"?`page:${c.key}`:`section:${c.key}`):n.jsx(Si,{title:`Select ${Di(l)?`a ${Pi[l]}`:l==="pages"?"a page":l==="apps"?"an app":"a section"} to edit`,description:l==="apps"?"Browse all apps and select an installed one to edit its settings.":'Pick an item from the list, or click "+" to create one.'})})}),T&&n.jsx(wx,{open:!!T,mode:T.mode,initialName:T.initialName,initialPath:T.initialPath,isPending:j.isPending,error:k,validate:q,onSubmit:fe,onOpenChange:G=>{G||(S(null),I(void 0))}}),M&&n.jsx(Cx,{open:!!M,blockKey:M,initialName:J.find(G=>G.key===M)?.name??M,isPending:j.isPending,onSubmit:ne,onOpenChange:G=>{G||D(null)}}),N&&i&&n.jsx(E.Suspense,{fallback:null,children:n.jsx(Fx,{open:N,onOpenChange:A,meta:v,decofile:o,previewBaseUrl:i,onSelect:te})}),W&&n.jsx(Mx,{open:!!W,onOpenChange:G=>{G||F(null)},pageKey:W,decofile:o}),n.jsx(Rr,{open:!!$,onOpenChange:G=>{!G&&!mt&&z(null)},children:n.jsxs(Pr,{children:[n.jsxs(Dr,{children:[n.jsx(Ar,{children:`Delete ${as}?`}),n.jsx(Ir,{children:$?.kind==="section"?`"${$.label}" will be removed. Pages that still reference it will lose this section.`:$?`"${$.label}" will be removed permanently. This can't be undone.`:null})]}),n.jsxs(Br,{children:[n.jsx(Mr,{disabled:mt,children:"Cancel"}),n.jsx(Lr,{onClick:G=>{G.preventDefault(),Be()},disabled:mt,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:mt?n.jsxs(n.Fragment,{children:[n.jsx(Ce,{size:14,className:"animate-spin"}),"Deleting…"]}):"Delete"})]})]})})]})}function Vx(t){const e=K.c(33),{active:s,counts:i,showBlog:r,onSelect:o}=t;let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=n.jsx("div",{className:"px-3 h-12 flex items-center border-b shrink-0",children:n.jsx("span",{className:"text-sm font-medium",children:"Content"})}),e[0]=a):a=e[0];const l=s==="pages";let h;e[1]!==i.pages||e[2]!==o||e[3]!==l?(h=n.jsx(ls,{id:"pages",icon:Vo,label:"Pages",count:i.pages,active:l,onSelect:o}),e[1]=i.pages,e[2]=o,e[3]=l,e[4]=h):h=e[4];const c=s==="sections";let d;e[5]!==i.sections||e[6]!==o||e[7]!==c?(d=n.jsx(ls,{id:"sections",icon:Gs,label:"Sections",count:i.sections,active:c,onSelect:o}),e[5]=i.sections,e[6]=o,e[7]=c,e[8]=d):d=e[8];const u=s==="apps";let f;e[9]!==i.apps||e[10]!==o||e[11]!==u?(f=n.jsx(ls,{id:"apps",icon:ph,label:"Apps",count:i.apps,active:u,onSelect:o}),e[9]=i.apps,e[10]=o,e[11]=u,e[12]=f):f=e[12];let m;e[13]!==s||e[14]!==i.authors||e[15]!==i.categories||e[16]!==i.posts||e[17]!==o||e[18]!==r?(m=r&&n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"mt-3 flex items-center gap-1.5 px-2.5 pb-1 pt-1 text-xs font-medium text-muted-foreground/70",children:[n.jsx(mh,{size:13,className:"shrink-0"}),"Blog"]}),n.jsx(ls,{id:"posts",icon:qc,label:"Posts",count:i.posts,active:s==="posts",onSelect:o}),n.jsx(ls,{id:"authors",icon:ta,label:"Authors",count:i.authors,active:s==="authors",onSelect:o}),n.jsx(ls,{id:"categories",icon:Gc,label:"Categories",count:i.categories,active:s==="categories",onSelect:o})]}),e[13]=s,e[14]=i.authors,e[15]=i.categories,e[16]=i.posts,e[17]=o,e[18]=r,e[19]=m):m=e[19];const p=s==="site";let _;e[20]!==o||e[21]!==p?(_=n.jsx(ls,{id:"site",icon:Wf,label:"Site",active:p,onSelect:o}),e[20]=o,e[21]=p,e[22]=_):_=e[22];const g=s==="seo";let v;e[23]!==o||e[24]!==g?(v=n.jsx(ls,{id:"seo",icon:Nr,label:"SEO",active:g,onSelect:o}),e[23]=o,e[24]=g,e[25]=v):v=e[25];let b;return e[26]!==_||e[27]!==v||e[28]!==h||e[29]!==d||e[30]!==f||e[31]!==m?(b=n.jsxs("div",{className:"w-[208px] shrink-0 border-r flex flex-col",children:[a,n.jsxs("nav",{className:"flex flex-col p-1.5 gap-0.5",children:[h,d,f,m,_,v]})]}),e[26]=_,e[27]=v,e[28]=h,e[29]=d,e[30]=f,e[31]=m,e[32]=b):b=e[32],b}function ls(t){const e=K.c(18),{id:s,icon:i,label:r,count:o,active:a,onSelect:l}=t;let h;e[0]!==s||e[1]!==l?(h=()=>l(s),e[0]=s,e[1]=l,e[2]=h):h=e[2];const c=a?"bg-accent text-accent-foreground":"text-muted-foreground hover:bg-muted hover:text-foreground";let d;e[3]!==c?(d=he("flex w-full items-center gap-2 rounded-md px-2.5 py-1.5 text-left text-sm transition-colors cursor-pointer",c),e[3]=c,e[4]=d):d=e[4];let u;e[5]!==i?(u=n.jsx(i,{size:16,className:"shrink-0"}),e[5]=i,e[6]=u):u=e[6];let f;e[7]!==r?(f=n.jsx("span",{className:"flex-1 truncate",children:r}),e[7]=r,e[8]=f):f=e[8];let m;e[9]!==a||e[10]!==o?(m=o!==void 0&&n.jsx("span",{className:he("shrink-0 text-xs tabular-nums",a?"text-accent-foreground/70":"text-muted-foreground/70"),children:o}),e[9]=a,e[10]=o,e[11]=m):m=e[11];let p;return e[12]!==h||e[13]!==d||e[14]!==u||e[15]!==f||e[16]!==m?(p=n.jsxs("button",{type:"button",onClick:h,className:d,children:[u,f,m]}),e[12]=h,e[13]=d,e[14]=u,e[15]=f,e[16]=m,e[17]=p):p=e[17],p}function qx(t){const e=K.c(57),{activeCollection:s,pages:i,sections:r,appCatalog:o,appCatalogLoading:a,blogEntries:l,decofile:h,previewUrl:c,searchQuery:d,onSearchChange:u,selection:f,onSelect:m,onCreate:p,onDuplicatePage:_,onRenamePage:g,onAddPageVariant:v,onDeletePage:b,onEditPageSeo:x,onViewPageJson:y,onDuplicateSection:w,onRenameSection:C,onDeleteSection:j,onDuplicateBlog:R,onDeleteBlog:B}=t;let P,T,S,k,I,N;if(e[0]!==s||e[1]!==o||e[2]!==a||e[3]!==l||e[4]!==h||e[5]!==v||e[6]!==p||e[7]!==B||e[8]!==b||e[9]!==j||e[10]!==R||e[11]!==_||e[12]!==w||e[13]!==x||e[14]!==g||e[15]!==C||e[16]!==u||e[17]!==m||e[18]!==y||e[19]!==i||e[20]!==c||e[21]!==d||e[22]!==r||e[23]!==f){const $=d.toLowerCase(),z=i.filter(O=>!$||O.name.toLowerCase().includes($)||O.path.toLowerCase().includes($)),W=r.filter(O=>!$||O.name.toLowerCase().includes($)||O.key.toLowerCase().includes($)||O.resolveType.toLowerCase().includes($)),F=o.filter(O=>!$||O.title.toLowerCase().includes($)||O.app.toLowerCase().includes($)||O.vendor.toLowerCase().includes($)||O.category.toLowerCase().includes($)),V=l.filter(O=>!$||O.label.toLowerCase().includes($)||O.subtitle.toLowerCase().includes($)),J=`Search ${s}…`,Y=Di(s)?`Create new ${Pi[s]}`:s==="pages"?"Create new page":"Create new section",U=s==="sections"&&!c,H=s!=="apps",X=U,oe=U?"Start the preview dev server to add sections":void 0;I="w-[300px] shrink-0 border-r flex flex-col min-h-0";let L;e[30]===Symbol.for("react.memo_cache_sentinel")?(L=n.jsx(fh,{size:14,className:"shrink-0 text-muted-foreground","aria-hidden":!0}),e[30]=L):L=e[30];let se;e[31]!==u?(se=O=>u(O.target.value),e[31]=u,e[32]=se):se=e[32];let ee;e[33]!==J||e[34]!==d||e[35]!==se?(ee=n.jsxs("div",{className:"flex flex-1 items-center gap-2 pl-1",children:[L,n.jsx("input",{type:"text",value:d,onChange:se,placeholder:J,"aria-label":J,className:"w-full bg-transparent text-sm outline-none placeholder:text-muted-foreground"})]}),e[33]=J,e[34]=d,e[35]=se,e[36]=ee):ee=e[36];let Q;e[37]!==X||e[38]!==oe||e[39]!==Y||e[40]!==p||e[41]!==H?(Q=H&&n.jsxs(Re,{children:[n.jsx(Ee,{asChild:!0,children:n.jsx(re,{variant:"ghost",size:"icon",onClick:p,disabled:X,"aria-label":Y,"aria-disabled":X,children:n.jsx(xt,{size:14})})}),n.jsx(Te,{side:"bottom",children:oe??Y})]}),e[37]=X,e[38]=oe,e[39]=Y,e[40]=p,e[41]=H,e[42]=Q):Q=e[42],e[43]!==ee||e[44]!==Q?(N=n.jsxs("div",{className:"px-2 h-12 flex items-center gap-1 border-b shrink-0",children:[ee,Q]}),e[43]=ee,e[44]=Q,e[45]=N):N=e[45],P=rn,k="flex-1 min-h-0 [&_[data-slot=scroll-area-viewport]>div]:!block",T="flex flex-col gap-1 p-1.5",S=s==="pages"?z.length===0?n.jsx(cr,{hasItems:i.length>0,emptyLabel:"No pages yet.",emptyHint:'Click "+" to create your first page.'}):z.map(O=>{const ce=f?.collection==="pages"&&f.key===O.key,ue=vd(h,O.key);return n.jsx(lr,{icon:Vo,title:O.name,subtitle:O.path,active:ce,variantCount:ue,onClick:()=>m({collection:"pages",key:O.key,path:O.path}),menu:n.jsx(Cn,{onDuplicate:()=>_(O),onRename:()=>g(O),onAddVariant:()=>v(O),onEditSeo:()=>x(O),onViewJson:()=>y(O),onDelete:()=>b(O)})},O.key)}):s==="sections"?W.length===0?n.jsx(cr,{hasItems:r.length>0,emptyLabel:"No saved sections yet.",emptyHint:'Click "+" to create one, or save a section from a page.'}):W.map(O=>{const ce=f?.collection==="sections"&&f.key===O.key,ue=O.resolveType.split("/").pop()?.replace(/\.tsx?$/,"");return n.jsx(lr,{icon:Gs,title:O.name,subtitle:ue??O.resolveType,active:ce,onClick:()=>m({collection:"sections",key:O.key}),menu:n.jsx(Cn,{onDuplicate:()=>w(O),onRename:()=>C(O),onDelete:()=>j(O)})},O.key)}):s==="apps"?a?n.jsx("div",{className:"flex items-center justify-center py-8",children:n.jsx(Ce,{size:18,className:"animate-spin text-muted-foreground"})}):F.length===0?n.jsx(cr,{hasItems:o.length>0,emptyLabel:"No apps found.",emptyHint:"Try a different search term."}):F.map(O=>{const ce=f?.collection==="apps"&&O.blockKey!==null&&f.key===O.blockKey;return n.jsx(lr,{icon:ph,logoUrl:O.logo,title:O.title,subtitle:O.category,active:ce,trailing:O.installed?n.jsx("span",{className:"shrink-0 rounded-full bg-emerald-500/15 px-1.5 py-0.5 text-[10px] font-medium text-emerald-700 dark:text-emerald-400",children:"Installed"}):void 0,onClick:()=>{if(!O.installed||!O.blockKey){le.message(`${O.title} is not installed on this site.`);return}m({collection:"apps",key:O.blockKey})}},O.id)}):V.length===0?n.jsx(cr,{hasItems:l.length>0,emptyLabel:`No ${s} yet.`,emptyHint:`Click "+" to create your first ${Di(s)?Pi[s]:"item"}.`}):V.map(O=>{const ce=f?.collection===O.kind&&f.key===O.key;return n.jsx(lr,{icon:O.kind==="posts"?qc:O.kind==="authors"?ta:Gc,title:O.label,subtitle:O.subtitle,active:ce,onClick:()=>m({collection:O.kind,key:O.key}),menu:n.jsx(Cn,{onDuplicate:()=>R(O),onDelete:()=>B(O)})},O.key)}),e[0]=s,e[1]=o,e[2]=a,e[3]=l,e[4]=h,e[5]=v,e[6]=p,e[7]=B,e[8]=b,e[9]=j,e[10]=R,e[11]=_,e[12]=w,e[13]=x,e[14]=g,e[15]=C,e[16]=u,e[17]=m,e[18]=y,e[19]=i,e[20]=c,e[21]=d,e[22]=r,e[23]=f,e[24]=P,e[25]=T,e[26]=S,e[27]=k,e[28]=I,e[29]=N}else P=e[24],T=e[25],S=e[26],k=e[27],I=e[28],N=e[29];let A;e[46]!==T||e[47]!==S?(A=n.jsx("div",{className:T,children:S}),e[46]=T,e[47]=S,e[48]=A):A=e[48];let M;e[49]!==P||e[50]!==k||e[51]!==A?(M=n.jsx(P,{className:k,children:A}),e[49]=P,e[50]=k,e[51]=A,e[52]=M):M=e[52];let D;return e[53]!==I||e[54]!==N||e[55]!==M?(D=n.jsxs("div",{className:I,children:[N,M]}),e[53]=I,e[54]=N,e[55]=M,e[56]=D):D=e[56],D}function lr(t){const e=K.c(29),{icon:s,logoUrl:i,title:r,subtitle:o,active:a,variantCount:l,trailing:h,onClick:c,menu:d}=t;let u;e[0]!==s||e[1]!==a||e[2]!==i||e[3]!==l?(u=l&&l>1?n.jsxs(Re,{children:[n.jsx(Ee,{asChild:!0,children:n.jsx(s,{size:16,className:"shrink-0",style:{color:eo}})}),n.jsxs(Te,{side:"right",children:[l," variants"]})]}):i?n.jsx("img",{src:i,alt:"",className:"size-8 shrink-0 rounded-lg object-cover bg-muted"}):n.jsx(s,{size:16,className:he("shrink-0",a?"text-accent-foreground":"text-muted-foreground")}),e[0]=s,e[1]=a,e[2]=i,e[3]=l,e[4]=u):u=e[4];const f=u,m=a?"bg-accent text-accent-foreground":"hover:bg-muted";let p;e[5]!==m?(p=he("group relative flex min-w-0 items-center rounded-md transition-colors",m),e[5]=m,e[6]=p):p=e[6];let _;e[7]!==r?(_=n.jsx("span",{className:"block truncate text-sm font-medium",children:r}),e[7]=r,e[8]=_):_=e[8];const g=a?"text-accent-foreground/70":"text-muted-foreground";let v;e[9]!==g?(v=he("block truncate text-xs",g),e[9]=g,e[10]=v):v=e[10];let b;e[11]!==o||e[12]!==v?(b=n.jsx("span",{className:v,children:o}),e[11]=o,e[12]=v,e[13]=b):b=e[13];let x;e[14]!==_||e[15]!==b?(x=n.jsxs("span",{className:"min-w-0 flex-1",children:[_,b]}),e[14]=_,e[15]=b,e[16]=x):x=e[16];let y;e[17]!==c||e[18]!==f||e[19]!==x||e[20]!==h?(y=n.jsxs("button",{type:"button",onClick:c,className:"flex min-w-0 flex-1 items-center gap-2.5 rounded-md px-2.5 py-2 text-left cursor-pointer",children:[f,x,h]}),e[17]=c,e[18]=f,e[19]=x,e[20]=h,e[21]=y):y=e[21];let w;e[22]!==a||e[23]!==d?(w=d&&n.jsx("div",{className:he("pr-1 opacity-0 transition-opacity group-hover:opacity-100",a&&"opacity-100"),children:d}),e[22]=a,e[23]=d,e[24]=w):w=e[24];let C;return e[25]!==w||e[26]!==p||e[27]!==y?(C=n.jsxs("div",{className:p,children:[y,w]}),e[25]=w,e[26]=p,e[27]=y,e[28]=C):C=e[28],C}function Cn(t){const e=K.c(21),{onDuplicate:s,onRename:i,onAddVariant:r,onEditSeo:o,onViewJson:a,onDelete:l}=t;let h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h=n.jsx(As,{asChild:!0,children:n.jsx("button",{type:"button","aria-label":"More actions",className:"flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:bg-background hover:text-foreground cursor-pointer",onClick:Gx,children:n.jsx(tn,{size:14})})}),e[0]=h):h=e[0];let c;e[1]!==i?(c=i&&n.jsxs(He,{onClick:i,children:[n.jsx(sa,{size:14}),"Rename"]}),e[1]=i,e[2]=c):c=e[2];let d;e[3]===Symbol.for("react.memo_cache_sentinel")?(d=n.jsx(Qt,{size:14}),e[3]=d):d=e[3];let u;e[4]!==s?(u=n.jsxs(He,{onClick:s,children:[d,"Duplicate"]}),e[4]=s,e[5]=u):u=e[5];let f;e[6]!==r?(f=r&&n.jsxs(n.Fragment,{children:[n.jsx(gr,{}),n.jsxs(He,{onClick:r,className:"cursor-pointer",style:{color:eo},children:[n.jsx(Uf,{size:14,style:{color:eo}}),"Add variant"]})]}),e[6]=r,e[7]=f):f=e[7];let m;e[8]!==o||e[9]!==a?(m=(o||a)&&n.jsxs(n.Fragment,{children:[n.jsx(gr,{}),o&&n.jsxs(He,{onClick:o,children:[n.jsx(Nr,{size:14}),"Edit SEO"]}),a&&n.jsxs(He,{onClick:a,children:[n.jsx(qo,{size:14}),"View JSON"]})]}),e[8]=o,e[9]=a,e[10]=m):m=e[10];let p;e[11]===Symbol.for("react.memo_cache_sentinel")?(p=n.jsx(gr,{}),e[11]=p):p=e[11];let _;e[12]===Symbol.for("react.memo_cache_sentinel")?(_=n.jsx(qs,{size:14}),e[12]=_):_=e[12];let g;e[13]!==l?(g=n.jsxs(He,{onClick:l,className:"text-destructive focus:text-destructive",children:[_,"Delete"]}),e[13]=l,e[14]=g):g=e[14];let v;return e[15]!==c||e[16]!==u||e[17]!==f||e[18]!==m||e[19]!==g?(v=n.jsxs(Ds,{children:[h,n.jsxs(Is,{align:"end",className:"w-44",children:[c,u,f,m,p,g]})]}),e[15]=c,e[16]=u,e[17]=f,e[18]=m,e[19]=g,e[20]=v):v=e[20],v}function Gx(t){return t.stopPropagation()}function cr(t){const e=K.c(6),{hasItems:s,emptyLabel:i,emptyHint:r}=t;let o;e[0]!==r||e[1]!==i||e[2]!==s?(o=s?"No results match your search.":n.jsxs(n.Fragment,{children:[n.jsx("div",{children:i}),n.jsx("div",{className:"mt-1 text-muted-foreground/80",children:r})]}),e[0]=r,e[1]=i,e[2]=s,e[3]=o):o=e[3];let a;return e[4]!==o?(a=n.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:o}),e[4]=o,e[5]=a):a=e[5],a}function Yx(t){const e=K.c(8),{state:s,claimPhase:i,lifecycle:r,onStart:o}=t;switch(s.kind){case"starting":{let a;e[0]!==i||e[1]!==r?(a=ad({claimPhase:i,lifecycle:r}),e[0]=i,e[1]=r,e[2]=a):a=e[2];let l;return e[3]!==i||e[4]!==a?(l=n.jsx(Fr,{kind:"starting",progress:a,claimPhase:i}),e[3]=i,e[4]=a,e[5]=l):l=e[5],l}case"suspended":{let a;return e[6]!==o?(a=n.jsx(Fr,{kind:"suspended",onResume:o}),e[6]=o,e[7]=a):a=e[7],a}}}function Si(t){const e=K.c(10),{icon:s,title:i,description:r}=t;let o;e[0]!==s?(o=s&&n.jsx(s,{size:24,className:"text-muted-foreground/60"}),e[0]=s,e[1]=o):o=e[1];let a;e[2]!==i?(a=n.jsx("div",{children:i}),e[2]=i,e[3]=a):a=e[3];let l;e[4]!==r?(l=r&&n.jsx("div",{className:"text-xs text-muted-foreground/80 max-w-sm",children:r}),e[4]=r,e[5]=l):l=e[5];let h;return e[6]!==o||e[7]!==a||e[8]!==l?(h=n.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-2 p-6 text-center text-sm text-muted-foreground",children:[o,a,l]}),e[6]=o,e[7]=a,e[8]=l,e[9]=h):h=e[9],h}function Xx(t){const e=K.c(2),{virtualMcpId:s}=t,i=Mt(s);if(!ti(i?.metadata)){let a;return e[0]===Symbol.for("react.memo_cache_sentinel")?(a=n.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-2 text-center text-sm text-muted-foreground p-6",children:[n.jsx(Ui,{size:24,className:"text-muted-foreground/60"}),n.jsx("div",{children:"No content to edit."}),n.jsx("div",{className:"text-xs text-muted-foreground/80",children:"Connect a GitHub repository from the Settings tab to enable Content."})]}),e[0]=a):a=e[0],a}let o;return e[1]===Symbol.for("react.memo_cache_sentinel")?(o=n.jsx(Hx,{}),e[1]=o):o=e[1],o}const kn={fast:{label:"Fast",subtitle:"Quick responses for simple tasks",icon:Kc},smart:{label:"Smart",subtitle:"Balanced quality and speed",icon:Ss},thinking:{label:"Thinking",subtitle:"Deeper reasoning for hard tasks",icon:Gf}},Jx=["fast","smart","thinking"];function Zx(t){const e=K.c(15),{tier:s,onSelect:i}=t,[r,o]=E.useState(!1),a=kn[s].icon;let l;e[0]!==a?(l=n.jsx(a,{size:14,className:"text-muted-foreground"}),e[0]=a,e[1]=l):l=e[1];const h=kn[s];let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c=n.jsx(Es,{size:14,className:"text-muted-foreground"}),e[2]=c):c=e[2];let d;e[3]!==l||e[4]!==h.label?(d=n.jsx(Rs,{asChild:!0,children:n.jsxs(re,{variant:"outline",size:"sm",className:"w-fit gap-1.5",children:[l,h.label,c]})}),e[3]=l,e[4]=h.label,e[5]=d):d=e[5];let u;e[6]!==i||e[7]!==s?(u=Jx.map(p=>{const _=kn[p],g=_.icon;return n.jsxs("button",{type:"button",onClick:()=>{i(p),o(!1)},className:he("flex items-start gap-2 px-2 py-1.5 rounded-md text-left hover:bg-muted"),children:[n.jsx(g,{size:16,className:"shrink-0 text-muted-foreground mt-0.5"}),n.jsxs("div",{className:"flex-1",children:[n.jsx("div",{className:"text-sm",children:_.label}),n.jsx("div",{className:"text-xs text-muted-foreground",children:_.subtitle})]}),p===s&&n.jsx(ri,{size:14,className:"text-foreground mt-0.5"})]},p)}),e[6]=i,e[7]=s,e[8]=u):u=e[8];let f;e[9]!==u?(f=n.jsx(Ps,{align:"start",className:"p-1 w-64",children:n.jsx("div",{className:"flex flex-col",children:u})}),e[9]=u,e[10]=f):f=e[10];let m;return e[11]!==r||e[12]!==d||e[13]!==f?(m=n.jsxs(Ts,{open:r,onOpenChange:o,children:[d,f]}),e[11]=r,e[12]=d,e[13]=f,e[14]=m):m=e[14],m}function Qx(t){const e=K.c(15),{tier:s,onTierChange:i,override:r,onOverrideChange:o}=t,[a,l]=E.useState(r!==null);let h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h=n.jsx("span",{className:"text-xs font-semibold text-muted-foreground/60",children:"Model"}),e[0]=h):h=e[0];let c;e[1]!==o||e[2]!==i||e[3]!==r||e[4]!==s||e[5]!==a?(c=a?n.jsx(E.Suspense,{fallback:n.jsx(re,{variant:"outline",size:"sm",disabled:!0,className:"w-fit",children:"Loading models…"}),children:n.jsx(eb,{override:r,onOverrideChange:o})}):n.jsx(Zx,{tier:s,onSelect:i}),e[1]=o,e[2]=i,e[3]=r,e[4]=s,e[5]=a,e[6]=c):c=e[6];let d;e[7]!==o?(d=m=>{l(m),m||o(null)},e[7]=o,e[8]=d):d=e[8];let u;e[9]!==d||e[10]!==a?(u=n.jsxs("label",{className:"flex items-center gap-2 text-xs text-muted-foreground cursor-pointer select-none",children:[n.jsx(Or,{checked:a,onCheckedChange:d,className:"cursor-pointer"}),"Specific model"]}),e[9]=d,e[10]=a,e[11]=u):u=e[11];let f;return e[12]!==c||e[13]!==u?(f=n.jsxs("div",{className:"flex flex-col gap-2",children:[h,n.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[c,u]})]}),e[12]=c,e[13]=u,e[14]=f):f=e[14],f}function eb(t){const e=K.c(10),{override:s,onOverrideChange:i}=t,r=Hc(),o=r[0]?.id??null,[a,l]=E.useState(s?.credentialId??o);let h;e[0]!==s?(h=s?{modelId:s.modelId,title:s.title||s.modelId,keyId:s.credentialId,providerId:"deco",description:null,logo:null,capabilities:[],limits:null,costs:null}:null,e[0]=s,e[1]=h):h=e[1];const c=h;if(r.length===0){let f;return e[2]===Symbol.for("react.memo_cache_sentinel")?(f=n.jsx("span",{className:"text-xs text-muted-foreground italic",children:"Connect an AI provider in settings to pick a specific model."}),e[2]=f):f=e[2],f}let d;e[3]!==a||e[4]!==i?(d=f=>{const m=f.keyId??a??"";l(m),i({modelId:f.modelId,credentialId:m,title:f.title??f.modelId})},e[3]=a,e[4]=i,e[5]=d):d=e[5];let u;return e[6]!==a||e[7]!==c||e[8]!==d?(u=n.jsx("div",{className:"w-fit max-w-full [&_button]:rounded-md",children:n.jsx(ap,{variant:"bordered",placeholder:"Pick a model",model:c,credentialId:a,onCredentialChange:l,onModelChange:d})}),e[6]=a,e[7]=c,e[8]=d,e[9]=u):u=e[9],u}const kd=[{key:"capabilities",heading:"Built-in capabilities",icon:ia,tools:[{name:"web_search",title:"Web search",description:"Look up current information on the web",icon:Ki},{name:"generate_image",title:"Generate image",description:"Create images from a text prompt",icon:Qm},{name:"subtask",title:"Subtask",description:"Spawn a focused sub-agent to handle part of the work",icon:Mi},{name:"user_ask",title:"Ask the user",description:"Pause to ask the user a clarifying question",icon:Kf}]},{key:"files",heading:"Files & code",icon:Wn,tools:[{name:"read",title:"Read File",description:"Read a file from the workspace",icon:nh},{name:"write",title:"Write File",description:"Create or overwrite a file",icon:sa},{name:"edit",title:"Edit File",description:"Make targeted edits to an existing file",icon:Vf},{name:"grep",title:"Search Content",description:"Search file contents by pattern",icon:Oi},{name:"glob",title:"Find Files",description:"Find files by name pattern",icon:Wn},{name:"bash",title:"Run Command",description:"Run shell commands in the sandbox",icon:qf}]},{key:"context",heading:"Context",icon:Ga,tools:[{name:"read_resource",title:"Read Resource",description:"Read an MCP resource by URI",icon:Ga},{name:"read_prompt",title:"Read Prompt",description:"Read an MCP prompt definition",icon:mh}]},{key:"browser",heading:"Browser",icon:Gs,tools:[{name:"take_screenshot",title:"Take Screenshot",description:"Capture a screenshot of a web page",icon:sh},{name:"scrape_url",title:"Scrape URL",description:"Fetch and extract content from a URL",icon:Gs},{name:"inspect_page",title:"Inspect Page",description:"Inspect a web page's structure",icon:qo}]}],tb=kd.flatMap(t=>t.tools.map(e=>e.name));function sb(t){const e=t.replace(/[_-]+/g," ").trim();return e?e.toLowerCase().replace(/\b\w/g,s=>s.toUpperCase()):t}function ib(t){const e=K.c(5),{agentId:s,value:i,onChange:r}=t;let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=n.jsx("span",{className:"text-xs font-semibold text-muted-foreground/60",children:"Tools"}),e[0]=o):o=e[0];let a;return e[1]!==s||e[2]!==r||e[3]!==i?(a=n.jsxs("div",{className:"flex flex-col gap-2",children:[o,s?n.jsx(E.Suspense,{fallback:n.jsxs(re,{variant:"outline",size:"sm",disabled:!0,className:"w-fit",children:[n.jsx(ia,{size:14}),"Loading tools…"]}),children:n.jsx(rb,{agentId:s,value:i,onChange:r})}):n.jsx("span",{className:"text-xs text-muted-foreground italic",children:"Pick an agent first"})]}),e[1]=s,e[2]=r,e[3]=i,e[4]=a):a=e[4],a}function Rl(t){const e=K.c(17),{value:s,checked:i,onToggle:r,title:o,description:a,leading:l}=t;let h;e[0]!==i?(h=n.jsx(nn,{checked:i,className:"pointer-events-none mt-0.5"}),e[0]=i,e[1]=h):h=e[1];let c;e[2]!==l?(c=l&&n.jsx("span",{className:"mt-px shrink-0",children:l}),e[2]=l,e[3]=c):c=e[3];let d;e[4]!==o?(d=n.jsx("span",{className:"truncate text-sm leading-tight",children:o}),e[4]=o,e[5]=d):d=e[5];let u;e[6]!==a?(u=a&&n.jsx("span",{className:"line-clamp-2 text-xs leading-snug text-muted-foreground",children:a}),e[6]=a,e[7]=u):u=e[7];let f;e[8]!==d||e[9]!==u?(f=n.jsxs("div",{className:"flex min-w-0 flex-col gap-0.5",children:[d,u]}),e[8]=d,e[9]=u,e[10]=f):f=e[10];let m;return e[11]!==r||e[12]!==h||e[13]!==c||e[14]!==f||e[15]!==s?(m=n.jsxs(op,{value:s,onSelect:r,className:"items-start gap-2.5 py-2",children:[h,c,f]}),e[11]=r,e[12]=h,e[13]=c,e[14]=f,e[15]=s,e[16]=m):m=e[16],m}function Pl(t){const e=K.c(20),{conn:s,label:i,icon:r,on:o,total:a,onToggle:l}=t,h=o===a;let c;e[0]!==r||e[1]!==s?(c=s?n.jsx(Gt,{icon:s.icon,name:s.title,size:"2xs"}):r?n.jsx(r,{size:14,className:"text-muted-foreground"}):n.jsx(Yf,{size:14,className:"text-muted-foreground"}),e[0]=r,e[1]=s,e[2]=c):c=e[2];const d=s?.title??i??"Other tools";let u;e[3]!==d?(u=n.jsx("span",{className:"truncate",children:d}),e[3]=d,e[4]=u):u=e[4];let f;e[5]!==o||e[6]!==a?(f=n.jsxs("span",{className:"text-[11px] font-normal tabular-nums text-muted-foreground/70",children:[o,"/",a]}),e[5]=o,e[6]=a,e[7]=f):f=e[7];let m;e[8]!==l?(m=b=>{b.stopPropagation(),l()},e[8]=l,e[9]=m):m=e[9];const p=h?"None":"All";let _;e[10]!==m||e[11]!==p?(_=n.jsx("button",{type:"button",onClick:m,className:"text-[11px] font-medium text-primary hover:underline",children:p}),e[10]=m,e[11]=p,e[12]=_):_=e[12];let g;e[13]!==f||e[14]!==_?(g=n.jsxs("span",{className:"ml-auto flex items-center gap-2",children:[f,_]}),e[13]=f,e[14]=_,e[15]=g):g=e[15];let v;return e[16]!==c||e[17]!==u||e[18]!==g?(v=n.jsxs("div",{className:"flex items-center gap-2",children:[c,u,g]}),e[16]=c,e[17]=u,e[18]=g,e[19]=v):v=e[19],v}function rb(t){const e=K.c(70),{agentId:s,value:i,onChange:r}=t,{org:o}=Pe(),[a,l]=E.useState(!1);let h;e[0]!==s||e[1]!==o.id||e[2]!==o.slug?(h={connectionId:s,orgId:o.id,orgSlug:o.slug},e[0]=s,e[1]=o.id,e[2]=o.slug,e[3]=h):h=e[3];const c=ft(h);let d;e[4]!==c?(d={client:c},e[4]=c,e[5]=d):d=e[5];const{data:u,isLoading:f}=um(d),m=Vi();let p,_,g,v,b,x,y,w,C,j,R,B,P;if(e[6]!==m||e[7]!==u?.tools||e[8]!==f||e[9]!==r||e[10]!==a||e[11]!==i){const N=new Map(m.map(cb)),A=new Map;for(const q of u?.tools??[]){const te=ff(q._meta)??"__other__",me=mf(q.name,te==="__other__"?void 0:te),ne=q.title,ke=ne&&ne!==q.name?ne:sb(me);A.has(te)||A.set(te,{clientId:te,conn:N.get(te),tools:[]}),A.get(te).tools.push({name:q.name,display:ke,description:q.description})}const M=[...A.values()].sort(lb),D=(u?.tools??[]).map(ab),$=[...tb,...D],z=i===null?new Set($):new Set(i),W=$.every(q=>z.has(q)),F=q=>r($.every(te=>q.has(te))?null:[...q]),V=q=>{const te=new Set(z);te.has(q)?te.delete(q):te.add(q),F(te)},J=(q,te)=>{const me=new Set(z);for(const ne of q)te?me.add(ne):me.delete(ne);F(me)};v=Ts,P=a,b=l;let Y;e[25]===Symbol.for("react.memo_cache_sentinel")?(Y=n.jsx(ia,{size:14,className:"text-muted-foreground"}),e[25]=Y):Y=e[25];const U=W?"All tools":"Tools",H=!W&&n.jsxs(tp,{variant:"secondary",className:"ml-0.5 h-5 px-1.5 text-[11px] tabular-nums",children:[z.size,"/",$.length]});let X;e[26]===Symbol.for("react.memo_cache_sentinel")?(X=n.jsx(Es,{size:14,className:"text-muted-foreground"}),e[26]=X):X=e[26],e[27]!==U||e[28]!==H?(x=n.jsx(Rs,{asChild:!0,children:n.jsxs(re,{variant:"outline",size:"sm",className:"w-fit gap-1.5",children:[Y,U,H,X]})}),e[27]=U,e[28]=H,e[29]=x):x=e[29],g=Ps,R="p-0 w-80",B="start",_=ip,e[30]===Symbol.for("react.memo_cache_sentinel")?(C=n.jsx(rp,{placeholder:"Search tools..."}),e[30]=C):C=e[30];const oe=W?`All ${$.length} tools enabled`:`${z.size} of ${$.length} enabled`;let L;e[31]!==oe?(L=n.jsx("span",{className:"text-xs text-muted-foreground",children:oe}),e[31]=oe,e[32]=L):L=e[32];let se;e[33]!==r?(se=()=>r(null),e[33]=r,e[34]=se):se=e[34];let ee;e[35]!==W||e[36]!==se?(ee=n.jsx("button",{type:"button",onClick:se,disabled:W,className:"text-xs font-medium text-primary hover:underline disabled:cursor-default disabled:opacity-40 disabled:no-underline",children:"Select all"}),e[35]=W,e[36]=se,e[37]=ee):ee=e[37];let Q;e[38]===Symbol.for("react.memo_cache_sentinel")?(Q=n.jsx("span",{className:"text-muted-foreground/30",children:"·"}),e[38]=Q):Q=e[38];let O;e[39]!==r?(O=()=>r([]),e[39]=r,e[40]=O):O=e[40];const ce=z.size===0;let ue;e[41]!==O||e[42]!==ce?(ue=n.jsx("button",{type:"button",onClick:O,disabled:ce,className:"text-xs font-medium text-muted-foreground hover:underline disabled:cursor-default disabled:opacity-40 disabled:no-underline",children:"Clear"}),e[41]=O,e[42]=ce,e[43]=ue):ue=e[43];let fe;e[44]!==ee||e[45]!==ue?(fe=n.jsxs("div",{className:"flex items-center gap-2",children:[ee,Q,ue]}),e[44]=ee,e[45]=ue,e[46]=fe):fe=e[46],e[47]!==L||e[48]!==fe?(j=n.jsxs("div",{className:"flex items-center justify-between border-b px-3 py-2",children:[L,fe]}),e[47]=L,e[48]=fe,e[49]=j):j=e[49],p=np,y="max-h-80",w=f?n.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:"Loading tools…"}):n.jsxs(n.Fragment,{children:[n.jsx(sp,{children:"No tools found"}),kd.map(q=>{const te=q.tools.map(ob),me=te.filter(ne=>z.has(ne)).length;return n.jsx(Za,{heading:n.jsx(Pl,{label:q.heading,icon:q.icon,on:me,total:te.length,onToggle:()=>J(te,me!==te.length)}),children:q.tools.map(ne=>n.jsx(Rl,{value:`${ne.title} ${ne.name}`,checked:z.has(ne.name),onToggle:()=>V(ne.name),title:ne.title,description:ne.description,leading:n.jsx(ne.icon,{size:16,className:"text-muted-foreground"})},ne.name))},q.key)}),M.map(q=>{const te=q.tools.map(nb),me=te.filter(ne=>z.has(ne)).length;return n.jsx(Za,{heading:n.jsx(Pl,{conn:q.conn,on:me,total:te.length,onToggle:()=>J(te,me!==te.length)}),children:q.tools.map(ne=>n.jsx(Rl,{value:`${ne.display} ${ne.name} ${q.conn?.title??""}`,checked:z.has(ne.name),onToggle:()=>V(ne.name),title:ne.display,description:ne.description},ne.name))},q.clientId)})]}),e[6]=m,e[7]=u?.tools,e[8]=f,e[9]=r,e[10]=a,e[11]=i,e[12]=p,e[13]=_,e[14]=g,e[15]=v,e[16]=b,e[17]=x,e[18]=y,e[19]=w,e[20]=C,e[21]=j,e[22]=R,e[23]=B,e[24]=P}else p=e[12],_=e[13],g=e[14],v=e[15],b=e[16],x=e[17],y=e[18],w=e[19],C=e[20],j=e[21],R=e[22],B=e[23],P=e[24];let T;e[50]!==p||e[51]!==y||e[52]!==w?(T=n.jsx(p,{className:y,children:w}),e[50]=p,e[51]=y,e[52]=w,e[53]=T):T=e[53];let S;e[54]!==_||e[55]!==T||e[56]!==C||e[57]!==j?(S=n.jsxs(_,{children:[C,j,T]}),e[54]=_,e[55]=T,e[56]=C,e[57]=j,e[58]=S):S=e[58];let k;e[59]!==g||e[60]!==S||e[61]!==R||e[62]!==B?(k=n.jsx(g,{className:R,align:B,children:S}),e[59]=g,e[60]=S,e[61]=R,e[62]=B,e[63]=k):k=e[63];let I;return e[64]!==v||e[65]!==b||e[66]!==x||e[67]!==k||e[68]!==P?(I=n.jsxs(v,{open:P,onOpenChange:b,children:[x,k]}),e[64]=v,e[65]=b,e[66]=x,e[67]=k,e[68]=P,e[69]=I):I=e[69],I}function nb(t){return t.name}function ob(t){return t.name}function ab(t){return t.name}function lb(t,e){return(t.conn?.title??t.clientId).localeCompare(e.conn?.title??e.clientId)}function cb(t){return[t.id,t]}function Ai(t){const e=t.trim().split(/\s+/);return e.length!==5?!1:e.every(s=>/^[\d*/,-]+$/.test(s))}function hb(t){if(!t)return"Unknown schedule";const e=t.trim();if(e==="* * * * *")return"Every minute";if(e==="0 * * * *")return"Every hour";if(e==="0 0 * * *")return"Every day";if(e==="0 0 * * 1")return"Every week";const s=e.match(/^\*\/(\d+)\s+\*\s+\*\s+\*\s+\*$/);if(s)return`Every ${s[1]} minutes`;const i=e.match(/^0\s+\*\/(\d+)\s+\*\s+\*\s+\*$/);if(i)return`Every ${i[1]} hours`;const r=e.match(/^0\s+0\s+\*\/(\d+)\s+\*\s+\*$/);if(r){const l=parseInt(r[1]??"1");return l%7===0?`Every ${l/7} weeks`:`Every ${l} days`}const o=e.match(/^(\d+)\s+(\d+)\s+\*\s+\*\s+\*$/);if(o){const l=(o[2]??"0").padStart(2,"0"),h=(o[1]??"0").padStart(2,"0");return`Every day at ${l}:${h} UTC`}const a=e.match(/^(\d+)\s+(\d+)\s+\*\s+\*\s+(\d)$/);if(a){const h=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][parseInt(a[3]??"0")]??"day",c=(a[2]??"0").padStart(2,"0"),d=(a[1]??"0").padStart(2,"0");return`Every ${h} at ${c}:${d} UTC`}return t}function db(t,e){const s=Math.max(1,t);switch(e){case"minutes":return s===1?"* * * * *":`*/${s} * * * *`;case"hours":return s===1?"0 * * * *":`0 */${s} * * *`;case"days":return s===1?"0 0 * * *":`0 0 */${s} * *`;case"weeks":return s===1?"0 0 * * 1":`0 0 */${s*7} * *`}}function ub(t){const e=t.trim();if(e==="* * * * *")return{count:1,unit:"minutes"};if(e==="0 * * * *")return{count:1,unit:"hours"};if(e==="0 0 * * *")return{count:1,unit:"days"};if(e==="0 0 * * 1")return{count:1,unit:"weeks"};const s=e.match(/^\*\/(\d+)\s+\*\s+\*\s+\*\s+\*$/);if(s)return{count:parseInt(s[1]),unit:"minutes"};const i=e.match(/^0\s+\*\/(\d+)\s+\*\s+\*\s+\*$/);if(i)return{count:parseInt(i[1]),unit:"hours"};const r=e.match(/^0\s+0\s+\*\/(\d+)\s+\*\s+\*$/);if(r){const o=parseInt(r[1]);return o%7===0?{count:o/7,unit:"weeks"}:{count:o,unit:"days"}}return null}function fb(t,e){return e===1?{minutes:"minute",hours:"hour",days:"day",weeks:"week"}[t]??t:t}const mb=[{label:"5 minutes",cron:"*/5 * * * *"},{label:"Hour",cron:"0 * * * *"},{label:"Day",cron:"0 0 * * *"},{label:"Week",cron:"0 0 * * 1"}];function pb({automationId:t,open:e,onOpenChange:s,onCustomSelect:i,onEventSelect:r,onWebhookCreated:o}){const{triggerAdd:a}=Gi(),[l,h]=E.useState(!1),c=e??l,d=m=>{s?s(m):h(m)},u=async m=>{try{await a.mutateAsync({automation_id:t,type:"cron",cron_expression:m}),le.success("Starter added"),d(!1)}catch(p){const _=p instanceof Error?p.message:"Failed to add starter";le.error(_)}},f=async()=>{try{const m=await a.mutateAsync({automation_id:t,type:"webhook"});d(!1),m.webhook?o?.(m.webhook):le.success("Webhook starter added")}catch(m){const p=m instanceof Error?m.message:"Failed to add webhook starter";le.error(p)}};return n.jsxs(Ds,{open:c,onOpenChange:d,children:[n.jsx(As,{asChild:!0,children:n.jsxs(re,{variant:"outline",size:"sm",children:[n.jsx(xt,{size:14}),"Add Starter"]})}),n.jsxs(Is,{align:"end",className:"w-[200px]",children:[n.jsxs(Un,{children:[n.jsxs(Kn,{className:"gap-2.5",children:[n.jsx(Ei,{size:14,className:"text-muted-foreground shrink-0"}),"Every..."]}),n.jsx(Vn,{className:"w-[160px]",children:mb.map(m=>n.jsxs(He,{className:"gap-2.5",onSelect:()=>u(m.cron),disabled:a.isPending,children:[n.jsx(Ei,{size:14,className:"text-muted-foreground shrink-0"}),"Every ",m.label]},m.cron))})]}),n.jsxs(He,{className:"gap-2.5",onSelect:()=>{d(!1),i?.()},children:[n.jsx(Ei,{size:14,className:"text-muted-foreground shrink-0"}),"Custom (cron)"]}),n.jsxs(He,{className:"gap-2.5",onSelect:()=>{d(!1),r?.()},children:[n.jsx($i,{size:14,className:"text-muted-foreground shrink-0"}),"Event"]}),n.jsxs(He,{className:"gap-2.5",onSelect:()=>{f()},disabled:a.isPending,children:[n.jsx(Ki,{size:14,className:"text-muted-foreground shrink-0"}),"Webhook"]})]})]})}function jd(t){const e=K.c(31),{open:s,onOpenChange:i,url:r,token:o,title:a,description:l}=t,h=a===void 0?"Webhook ready":a,c=l===void 0?"Send a POST to this URL with the bearer token to fire the automation. The token is shown once — copy it now.":l,[d,u]=E.useState(null),[f,m]=E.useState("curl"),[p,_]=E.useState("header"),g=E.useId();let v;e[0]===Symbol.for("react.memo_cache_sentinel")?(v=async(N,A)=>{try{await navigator.clipboard.writeText(N),u(A),le.success("Copied"),setTimeout(()=>u(null),1500)}catch{le.error("Failed to copy")}},e[0]=v):v=e[0];const b=v;let x;e[1]!==p||e[2]!==o||e[3]!==r?(x=r&&o&&p==="url"?`${r.replace(/\/$/,"")}/${o}`:r??"",e[1]=p,e[2]=o,e[3]=r,e[4]=x):x=e[4];const y=x,w=r&&o?p==="header"?`curl -X POST "${y}" \\
|
|
275
|
+
`}),e[26]=y):y=e[26];let w;return e[27]!==x||e[28]!==d?(w=n.jsxs("div",{className:"relative flex w-full flex-col items-center justify-center gap-12 select-none [clip-path:inset(-24px_0_-200px_0)]",children:[d,x,y]}),e[27]=x,e[28]=d,e[29]=w):w=e[29],w}function or(t){const e=K.c(10),{phase:s,current:i,children:r}=t,o=s-i,a=o<0,l=o===0,h=a?90:o*-22,c=a?.94:1-Math.max(o,0)*.04,d=a?0:l?1:o===1?.8:.55,u=a?10:30-o,f=!l;let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m=he("absolute inset-0 overflow-hidden rounded-xl border border-foreground/10 bg-background shadow-[0_20px_60px_-20px_rgb(0_0_0_/_0.35)] transition-all ease-[cubic-bezier(0.22,1,0.36,1)]"),e[0]=m):m=e[0];const p=`translateY(${h}px) scale(${c})`,_=l?"auto":"none";let g;e[1]!==d||e[2]!==p||e[3]!==_||e[4]!==u?(g={transform:p,opacity:d,zIndex:u,transitionDuration:"1000ms",pointerEvents:_},e[1]=d,e[2]=p,e[3]=_,e[4]=u,e[5]=g):g=e[5];let v;return e[6]!==r||e[7]!==f||e[8]!==g?(v=n.jsx("div",{"aria-hidden":f,className:m,style:g,children:r}),e[6]=r,e[7]=f,e[8]=g,e[9]=v):v=e[9],v}function an(t){const e=K.c(7),{showUrl:s}=t,i=s===void 0?!1:s;let r,o,a;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=n.jsx("div",{className:he("size-2.5 rounded-full",Ct)}),o=n.jsx("div",{className:he("size-2.5 rounded-full",Ct)}),a=n.jsx("div",{className:he("size-2.5 rounded-full",Ct)}),e[0]=r,e[1]=o,e[2]=a):(r=e[0],o=e[1],a=e[2]);let l;e[3]!==i?(l=i&&n.jsx("div",{className:he("ml-3 h-3.5 max-w-[220px] flex-1 rounded-sm",Ht)}),e[3]=i,e[4]=l):l=e[4];let h;return e[5]!==l?(h=n.jsxs("div",{className:"flex h-7 shrink-0 items-center gap-1.5 px-3",children:[r,o,a,l]}),e[5]=l,e[6]=h):h=e[6],h}function E1(){const t=K.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=n.jsx(an,{}),t[0]=e):e=t[0];let s;return t[1]===Symbol.for("react.memo_cache_sentinel")?(s=n.jsxs("div",{className:"flex h-full flex-col",children:[e,n.jsx("div",{className:"flex flex-1 px-8 py-5",children:n.jsx("div",{className:"grid h-full w-full grid-cols-8 grid-rows-6 gap-2",children:S1.map(T1)})})]}),t[1]=s):s=t[1],s}function T1(t,e){if(e===ld)return n.jsx("div",{className:"rounded-md bg-chart-1/[0.55]",style:{animation:"vm-breathe 2.4s ease-in-out infinite"}},e);const s=t;return n.jsx("div",{className:he("relative rounded-md",Ct),children:n.jsx("div",{className:"absolute inset-0 rounded-md bg-chart-1/40 opacity-0",style:{animation:`vm-rack-scan ${cd}s ease-in-out infinite`,animationDelay:`${s}s`}})},e)}function R1(){const t=K.c(5);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=n.jsx(an,{}),t[0]=e):e=t[0];let s;t[1]===Symbol.for("react.memo_cache_sentinel")?(s=n.jsx("div",{className:he("w-[18%] rounded-md",Ht),style:{animation:"vm-breathe 3s ease-in-out infinite"}}),t[1]=s):s=t[1];let i;t[2]===Symbol.for("react.memo_cache_sentinel")?(i=n.jsx("div",{className:"h-[42%] shrink-0 rounded-md bg-chart-3/[0.12]",style:{animation:"vm-breathe 3s ease-in-out 0.4s infinite"}}),t[2]=i):i=t[2];let r;t[3]===Symbol.for("react.memo_cache_sentinel")?(r=n.jsx("div",{className:"col-span-3 rounded-md bg-chart-3/[0.12]",style:{animation:"vm-breathe 3s ease-in-out 0.8s infinite"}}),t[3]=r):r=t[3];let o;return t[4]===Symbol.for("react.memo_cache_sentinel")?(o=n.jsxs("div",{className:"flex h-full flex-col",children:[e,n.jsxs("div",{className:"flex min-h-0 flex-1 gap-1.5 p-3",children:[s,n.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-1.5",children:[i,n.jsxs("div",{className:"grid min-h-0 flex-1 grid-cols-5 gap-1.5",children:[r,n.jsxs("div",{className:"col-span-2 grid grid-rows-2 gap-1.5",children:[n.jsx("div",{className:he("rounded-md",Ht),style:{animation:"vm-breathe 3s ease-in-out 1.2s infinite"}}),n.jsx("div",{className:he("rounded-md",Ht),style:{animation:"vm-breathe 3s ease-in-out 1.6s infinite"}})]})]})]})]})]}),t[4]=o):o=t[4],o}function P1(){const t=K.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=n.jsx(an,{}),t[0]=e):e=t[0];let s;return t[1]===Symbol.for("react.memo_cache_sentinel")?(s=n.jsxs("div",{className:"flex h-full flex-col",children:[e,n.jsx("div",{className:"relative flex flex-1 items-center justify-center px-8 py-5",children:n.jsx("div",{className:"grid w-full gap-2",style:{gridTemplateColumns:"repeat(7, minmax(0, 1fr))"},children:k1.map(D1)})})]}),t[1]=s):s=t[1],s}function D1(t,e){return n.jsx("div",{className:he("aspect-square rounded-md",j1[e]?"bg-chart-2/70":Ct),style:{animation:`vm-pulse-soft 2.2s ease-in-out ${t}s infinite`}},e)}function A1(){const t=K.c(11);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=n.jsx(an,{showUrl:!0}),t[0]=e):e=t[0];let s,i,r,o,a;t[1]===Symbol.for("react.memo_cache_sentinel")?(s=n.jsx("div",{className:"mb-2 h-5 rounded-md bg-chart-1/[0.10]"}),i=n.jsx("div",{className:he("h-1.5 w-[70%] rounded-sm",Ct)}),r=n.jsx("div",{className:he("h-1.5 w-[55%] rounded-sm",Ct)}),o=n.jsx("div",{className:he("h-1.5 w-[80%] rounded-sm",Ct)}),a=n.jsx("div",{className:he("h-1.5 w-[50%] rounded-sm",Ct)}),t[1]=s,t[2]=i,t[3]=r,t[4]=o,t[5]=a):(s=t[1],i=t[2],r=t[3],o=t[4],a=t[5]);let l;t[6]===Symbol.for("react.memo_cache_sentinel")?(l=n.jsxs("div",{className:"flex w-[18%] shrink-0 flex-col gap-1.5 bg-chart-1/[0.05] p-2.5",children:[s,i,r,o,a,n.jsx("div",{className:"mt-auto",children:n.jsx("div",{className:he("h-4 rounded-md",Ct)})})]}),t[6]=l):l=t[6];let h;t[7]===Symbol.for("react.memo_cache_sentinel")?(h=n.jsx("div",{className:"relative h-[42%] shrink-0 overflow-hidden bg-chart-1/[0.10]",children:n.jsxs("div",{className:"absolute right-3 bottom-3 left-3 space-y-1.5",children:[n.jsx("div",{className:"h-3 w-[35%] rounded-sm bg-chart-1/[0.15]"}),n.jsx("div",{className:he("h-1.5 w-[55%] rounded-sm",Ht)})]})}),t[7]=h):h=t[7];let c;t[8]===Symbol.for("react.memo_cache_sentinel")?(c=n.jsxs("div",{className:"flex shrink-0 gap-1.5",children:[n.jsx("div",{className:"h-4 w-12 rounded-full bg-chart-1/[0.12]"}),n.jsx("div",{className:he("h-4 w-10 rounded-full",Ht)}),n.jsx("div",{className:he("h-4 w-14 rounded-full",Ht)})]}),t[8]=c):c=t[8];let d;t[9]===Symbol.for("react.memo_cache_sentinel")?(d=n.jsxs("div",{className:he("col-span-3 flex flex-col justify-end gap-1 rounded-md p-2",Ht),children:[n.jsx("div",{className:he("h-1.5 w-[50%] rounded-sm",Ct)}),n.jsx("div",{className:he("h-1 w-[75%] rounded-sm",Ct)})]}),t[9]=d):d=t[9];let u;return t[10]===Symbol.for("react.memo_cache_sentinel")?(u=n.jsxs("div",{className:"flex h-full flex-col",children:[e,n.jsxs("div",{className:"flex min-h-0 flex-1",children:[l,n.jsxs("div",{className:"flex min-w-0 flex-1 flex-col",children:[h,n.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-2.5 p-3",children:[c,n.jsxs("div",{className:"grid min-h-0 flex-1 grid-cols-5 gap-2",children:[d,n.jsxs("div",{className:"col-span-2 grid grid-rows-2 gap-2",children:[n.jsx("div",{className:he("rounded-md",Ht)}),n.jsx("div",{className:he("rounded-md",Ht)})]})]})]})]})]})]}),t[10]=u):u=t[10],u}function Fr(t){const e=K.c(9);if(t.kind==="starting"){let l;return e[0]!==t.claimPhase||e[1]!==t.progress?(l=n.jsx("div",{className:"flex h-full w-full items-center justify-center bg-background p-6",children:n.jsx(N1,{progress:t.progress,claimPhase:t.claimPhase})}),e[0]=t.claimPhase,e[1]=t.progress,e[2]=l):l=e[2],l}let s;e[3]===Symbol.for("react.memo_cache_sentinel")?(s=n.jsx($f,{className:"size-12 text-blue-500"}),e[3]=s):s=e[3];let i,r;e[4]===Symbol.for("react.memo_cache_sentinel")?(i=n.jsx("h3",{className:"text-lg font-medium",children:b1("suspended")}),r=n.jsx("p",{className:"max-w-sm text-sm text-muted-foreground",children:"Resume to continue."}),e[4]=i,e[5]=r):(i=e[4],r=e[5]);let o;e[6]===Symbol.for("react.memo_cache_sentinel")?(o=n.jsx(Vs,{className:"size-4"}),e[6]=o):o=e[6];let a;return e[7]!==t.onResume?(a=n.jsx("div",{className:"flex h-full w-full items-center justify-center bg-background p-6",children:n.jsxs("div",{className:"flex w-full max-w-md flex-col items-center gap-4 text-center",children:[s,i,r,n.jsxs(re,{onClick:t.onResume,className:"mt-2",children:[o," Resume"]})]})}),e[7]=t.onResume,e[8]=a):a=e[8],a}const I1=E.lazy(()=>qt(()=>import("./sections-editor-DJ6-AL_q.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153])).then(t=>({default:t.SectionsEditor}))),B1=E.lazy(()=>qt(()=>import("./page-seo-sheet-Ceb0gnAp.js"),__vite__mapDeps([154,1,2,121,44,46,47,48,16,3,5,86,72,81,78,6,7,8,9,10,11,12,13,14,15,17,4,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,45,79,50,80,73,51,82,49,83,84,85,76,60,61,90,91,92,58,93,94,95,57,77,59,96,97,98,99,100,101,102,103,104,105,106,107,66,108,56,109,71,110,70,67,111,52,53,54,55,62,63,64,65,68,69,74,75,112,113,114,115,116,87,88,117,118,119,120,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152])).then(t=>({default:t.SeoSheet}))),M1=E.lazy(()=>qt(()=>import("./file-explorer-mkpu5feK.js"),__vite__mapDeps([155,1,2,136,6,7,8,9,10,11,12,13,14,15,16,3,17,4,5,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,126,91,92,58,93,94,76,95,57,77,59,103,104,49,105,106,107,50,119,120,121,122,83,80,70,123,108,124,56,67,114,125,62,63,64,71,72,110,127,52,53,54,55,60,61,65,66,68,69,73,74,75,87,88,128,129,130,97,98,135,100,51,90,96,99,101,102,109,84,111,112,113,115,116,117,118,131,132,133,134,137,138,81,139,140,141,142,143,144,145,146,147,148,149,150,151,152])).then(t=>({default:t.FileExplorer}))),yn=500,L1={mobile:375,tablet:768,desktop:null},Sn=["desktop","mobile","tablet"],O1={mobile:"Mobile (375px)",tablet:"Tablet (768px)",desktop:"Desktop"};function $1(t,e){const s=new URL(t,window.location.href);return s.searchParams.set("deviceHint",e),s.href}function z1(){const t=sr(),{currentBranch:e}=ss(),[s,i]=E.useState("preview"),[r,o]=E.useState("desktop"),[a,l]=E.useState(null),h=E.useRef(null),c=s==="cms",[d,u]=E.useState(null),[f,m]=E.useState(384),p=E.useRef(!1),_=E.useRef(0),g=E.useRef(0),v=E.useRef(null),[b,x]=E.useState(!1),[y,w]=E.useState(""),C=E.useRef(null),[j,R]=E.useState(!1),[B,P]=E.useState(),[T,S]=E.useState(null),[k,I]=E.useState(null),[N,A]=E.useState("/"),[M,D]=E.useState(null),[$,z]=E.useState(!1),[W,F]=E.useState(!1),[V,J]=E.useState(null),Y=t?.entity?.id??null,{org:U}=Pe(),H=Yt(),X=id(),oe=X.vmEntry,L=X.previewUrl,se=H.lifecycle.phase,ee=se==="running",Q=Y&&e&&ee?{orgSlug:U.slug,virtualMcpId:Y,branch:e}:null,{data:O}=ha(Q,{fetchEnabled:ee}),{data:ce}=da(Q,{fetchEnabled:ee}),ue=Y&&e?{orgSlug:U.slug,virtualMcpId:Y,branch:e}:null,fe=h1(ue),q=O?va(O).sort((ie,ve)=>ie.name.localeCompare(ve.name)):[],te=O&&ce?xa(O,ce):[],me=Us,ne=q.filter(ie=>{if(!y)return!0;const ve=y.toLowerCase();return ie.name.toLowerCase().includes(ve)||ie.path.toLowerCase().includes(ve)}),ke=te.filter(ie=>{if(!y)return!0;const ve=y.toLowerCase();return ie.name.toLowerCase().includes(ve)||ie.key.toLowerCase().includes(ve)||ie.resolveType.toLowerCase().includes(ve)}),at=T?null:P_(q,N,M),Be=T?T.name:at?.name,mt=at?.key??null,as=E.useRef(null),G=E.useRef(null);W_(()=>{const ie=h.current,ve=as.current;!ie||!ve||(ie.src=ve)});const _e=H.status.state==="paused",xe=H.phase,Se=ad({claimPhase:xe,lifecycle:H.lifecycle}),we=X.previewState,et=X.userStopped,bt=we.kind==="iframe"?$1(k??new URL(N,we.previewUrl).href,r):null,[ir,rr]=E.useState(null);if(we.kind==="iframe"&&ir!==we.previewUrl){const ie=ir!==null;rr(we.previewUrl),ie&&(G.current=null,A("/"),I(null),D(null),S(null))}as.current=bt;const ge=!!Y&&!!e&&!H.notFound&&!et&&!_e&&(xe?.kind==="ready"||se!=="idle"),je=we.kind!=="iframe"&&(s==="visual"||s==="cms")?"preview":s;E.useEffect(()=>{if(!L)return;let ie;try{ie=new URL(L,window.location.href).origin}catch{return}const ve=it=>{if(it.origin===ie){if(it.data?.type==="visual-editor::element-clicked"){const rt=u1.safeParse(it.data.payload);rt.success&&l(rt.data)}else if(it.data?.type==="cms-editor::section-clicked"){const rt=m1.safeParse(it.data.payload);rt.success&&u(rt.data.sectionIndex)}}};return window.addEventListener("message",ve),()=>window.removeEventListener("message",ve)},[L]),E.useEffect(()=>{if(!b)return;const ie=ve=>{C.current?.contains(ve.target)||(x(!1),w(""))};return document.addEventListener("pointerdown",ie),()=>document.removeEventListener("pointerdown",ie)},[b]),E.useEffect(()=>{if(!c)return;const ie=it=>{const rt=it.target;rt&&rt!==h.current&&(v.current=rt)},ve=()=>{requestAnimationFrame(()=>{const it=document.activeElement;(it===document.body||it===h.current)&&v.current&&v.current.focus()})};return document.addEventListener("focusin",ie),document.addEventListener("blur",ve,!0),()=>{document.removeEventListener("focusin",ie),document.removeEventListener("blur",ve,!0)}},[c]);const tt=()=>{const ie=h.current?.contentWindow;ie&&ie.postMessage({type:"visual-editor::activate",script:f1},"*")},yt=()=>{const ie=h.current?.contentWindow;ie&&ie.postMessage({type:"visual-editor::deactivate"},"*")},st=()=>{const ie=h.current?.contentWindow;ie&&ie.postMessage({type:"visual-editor::activate",script:p1},"*")},ku=()=>{const ie=h.current?.contentWindow;ie&&ie.postMessage({type:"cms-editor::deactivate"},"*")},di=ie=>{const ve=s;i(ie),l(null),ie!=="code"&&J(null),ie!=="cms"&&u(null),ve==="visual"&&yt(),ve==="cms"&&ku(),ie==="visual"&&tt(),ie==="cms"&&st()},ju=()=>{if(!h.current||!bt)return;const ie=h.current;ie.src=bt},Nu=()=>{if(!h.current||!bt)return;const ie=bt.includes("?")?"&":"?";h.current.src=`${bt}${ie}_r=${Date.now()}`},Eu=()=>{const ie=Sn.indexOf(r);o(Sn[(ie+1)%Sn.length])},Tu=()=>{const ie=h.current?.contentWindow?.location?.href??bt??L;ie&&navigator.clipboard.writeText(ie)},Ru=(()=>{if(!L)return"No server running";if(T)return T.name;try{const ie=new URL(L),ve=N==="/"?"":N;return`${ie.host}${ve}`}catch{return L}})(),za=ie=>{G.current=ie.path,S(null),I(null),D(ie.key),A(ie.path),u(null),z(!1)},Pu=ie=>{if(!L||!ce){le.error("Preview metadata not ready yet");return}G.current=null;const ve=Lh(ce),it=o1(L,ve,ie.key);S(ie),I(it),u(null)},Du=async({name:ie,path:ve})=>{if(!Y||!e)return;const it=pa(ve);if(it){P(it);return}const rt=ve.trim().startsWith("/")?ve.trim():`/${ve.trim()}`;if(q.some(Et=>me(Et.path)===me(rt))){P(`A page with path "${rt}" already exists.`);return}P(void 0);try{const Et=await fe.mutateAsync({name:ie,path:rt});R(!1),le.success(`Page "${ie}" created`),await new Promise(Iu=>setTimeout(Iu,yn)),za({key:Et.key,name:Et.name,path:Et.path}),di("cms")}catch(Et){P(Et instanceof Error?Et.message:"Failed to create page")}},Au=[{value:"preview",icon:n.jsx(Va,{size:14}),tooltip:"Interactive"},...we.kind==="iframe"?[{value:"visual",icon:n.jsx(qa,{size:14}),tooltip:"Visual editor"}]:[],...we.kind==="iframe"&&ga(O,ce)?[{value:"cms",icon:n.jsx(zf,{size:14}),tooltip:"Sections editor"}]:[],{value:"code",icon:n.jsx(Ff,{size:14}),tooltip:"Code editor"}];return n.jsxs("div",{className:"flex flex-col w-full h-full",children:[ge&&n.jsxs("div",{className:"flex h-12 shrink-0 items-center gap-4 border-b border-border/60 px-3 md:px-4",children:[n.jsx("div",{className:"flex shrink-0 items-center gap-1",children:n.jsx(Zm,{value:je,onValueChange:di,options:Au,size:"sm",className:"shrink-0 bg-foreground/4.5"})}),we.kind==="iframe"&&n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:he("flex min-w-0 flex-1 items-center gap-0.5 ml-2",s==="code"&&"hidden"),children:[n.jsxs(Re,{children:[n.jsx(Ee,{asChild:!0,children:n.jsx(re,{variant:"ghost",size:"icon",onClick:ju,children:n.jsx(Bi,{size:14})})}),n.jsx(Te,{side:"bottom",children:"Refresh"})]}),n.jsxs(Re,{children:[n.jsx(Ee,{asChild:!0,children:n.jsx(re,{variant:"ghost",size:"icon",onClick:Eu,children:n.jsxs("span",{className:"flex items-center justify-center animate-device-icon-pop",children:[r==="mobile"&&n.jsx(Hf,{size:14}),r==="tablet"&&n.jsx(Wf,{size:14}),r==="desktop"&&n.jsx(Va,{size:14})]},r)})}),n.jsx(Te,{side:"bottom",children:O1[r]})]}),n.jsxs("div",{ref:C,className:"relative min-w-0 flex-1",children:[n.jsxs("button",{type:"button",className:"flex h-8 w-full min-w-0 items-center gap-1 rounded-md bg-background px-2 transition-colors duration-200 hover:bg-accent",onClick:()=>x(ie=>!ie),children:[T&&n.jsxs("span",{className:"shrink-0 inline-flex items-center gap-1 rounded bg-global-section/14 px-1.5 py-0.5 text-[11px] font-medium text-global-section-fg dark:text-global-section-fg-dark",children:[n.jsx(Gs,{size:11}),"Global"]}),n.jsx("span",{className:"min-w-0 flex-1 truncate text-left text-[12px] text-foreground/88",children:Ru}),Be&&!T&&n.jsx("span",{className:"shrink-0 text-[12px] text-muted-foreground",children:Be}),n.jsx(Es,{size:12,className:he("shrink-0 text-muted-foreground transition-transform",b&&"rotate-180")})]}),b&&n.jsxs("div",{className:"absolute left-0 right-0 top-full z-50 mt-1.5 overflow-hidden rounded-lg border bg-popover shadow-lg",children:[n.jsxs("div",{className:"px-2 h-10 flex items-center gap-2 border-b",children:[n.jsx(fh,{size:14,className:"shrink-0 text-muted-foreground","aria-hidden":!0}),n.jsx("input",{type:"text",value:y,onChange:ie=>w(ie.target.value),placeholder:"Search pages and components...",className:"w-full bg-transparent text-sm outline-none placeholder:text-muted-foreground",autoFocus:!0})]}),n.jsx("div",{className:"p-1.5 border-b",children:n.jsxs("button",{type:"button",className:"flex w-full items-center gap-2.5 rounded-md px-3 py-2.5 text-left text-sm hover:bg-accent hover:text-accent-foreground",onMouseDown:ie=>{ie.preventDefault(),x(!1),w(""),P(void 0),R(!0)},children:[n.jsx(xt,{size:16,className:"shrink-0 text-muted-foreground"}),n.jsx("span",{className:"flex-1 font-medium",children:"Create new page"})]})}),ne.length===0&&ke.length===0?n.jsx("div",{className:"px-4 py-5 text-center text-xs text-muted-foreground",children:q.length===0&&te.length===0?"No pages found in this site.":"No results match your search."}):n.jsxs("div",{className:"max-h-80 overflow-y-auto overscroll-contain",children:[ne.length>0&&n.jsx("div",{className:"p-1.5",children:ne.map(ie=>n.jsxs("button",{type:"button",className:"flex w-full items-center gap-3 rounded-md px-3 py-2.5 text-left text-sm hover:bg-accent hover:text-accent-foreground",onMouseDown:ve=>{ve.preventDefault(),x(!1),w(""),za(ie)},children:[n.jsx(Vo,{size:16,className:"shrink-0 text-muted-foreground"}),n.jsx("span",{className:"min-w-0 flex-1 truncate font-medium",children:ie.name}),n.jsx("span",{className:"shrink-0 text-xs text-muted-foreground",children:ie.path})]},ie.key))}),ke.length>0&&n.jsxs("div",{className:he("p-1.5",ne.length>0&&"border-t"),children:[n.jsx("div",{className:"px-3 py-2 text-xs font-medium text-muted-foreground",children:"Global components"}),ke.map(ie=>n.jsxs("button",{type:"button",className:"flex w-full items-center gap-3 rounded-md px-3 py-2.5 text-left text-sm hover:bg-accent hover:text-accent-foreground",onMouseDown:ve=>{ve.preventDefault(),x(!1),w(""),Pu(ie)},children:[n.jsx(Gs,{size:16,className:"shrink-0 text-muted-foreground"}),n.jsx("span",{className:"min-w-0 flex-1 truncate font-medium",children:ie.name}),n.jsx("span",{className:"shrink-0 text-xs text-muted-foreground",children:ie.resolveType.split("/").pop()?.replace(/\.tsx?$/,"")})]},ie.key))]})]})]})]})]}),n.jsxs("div",{className:he("flex shrink-0 items-center gap-0.5",s==="code"&&"hidden"),children:[n.jsxs(Re,{children:[n.jsx(Ee,{asChild:!0,children:n.jsx(re,{variant:"ghost",size:"icon",onClick:()=>{const ie=bt??we.previewUrl;ie&&window.open(ie,"_blank","noopener")},children:n.jsx(ni,{size:14})})}),n.jsx(Te,{side:"bottom",children:"Open in new tab"})]}),n.jsxs(Ds,{children:[n.jsx(As,{asChild:!0,children:n.jsx(re,{variant:"ghost",size:"icon",children:n.jsx(tn,{size:14})})}),n.jsxs(Is,{align:"end",className:"w-44",children:[n.jsx(He,{onClick:Nu,children:"Hard Reload"}),n.jsx(He,{onClick:Tu,children:"Copy Current URL"}),O&&ce&&n.jsxs(n.Fragment,{children:[n.jsx(gr,{}),mt&&n.jsxs(He,{onClick:()=>{z(!0),di("cms")},children:[n.jsx(Nr,{size:14}),"Edit SEO"]}),mt&&n.jsxs(He,{onClick:()=>{try{J(Ja(mt)),di("code")}catch{le.error("Invalid page block key")}},children:[n.jsx(qo,{size:14}),"View JSON"]}),n.jsxs(He,{onClick:()=>F(!0),children:[n.jsx(Nr,{size:14}),"Site SEO"]})]})]})]})]})]})]}),n.jsxs("div",{className:"flex-1 flex overflow-hidden",children:[c&&L&&e&&Y&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"shrink-0 border-r overflow-hidden",style:{width:f},children:n.jsx(E.Suspense,{fallback:n.jsx("div",{className:"h-full flex items-center justify-center",children:n.jsx(Ce,{size:20,className:"animate-spin text-muted-foreground"})}),children:n.jsx(I1,{orgSlug:U.slug,virtualMcpId:Y,branch:e,previewReady:ee,previewUrl:L,currentPath:N,activePageBlockKey:mt,activeGlobalBlockKey:T?.key??null,externalSelectedIndex:T?null:d,onSaved:()=>{setTimeout(()=>{const ie=h.current;if(!ie)return;const ve=document.activeElement,it=ie.tabIndex;ie.tabIndex=-1,ie.style.pointerEvents="none",ie.blur();try{ie.contentWindow?.location.reload()}catch{const Et=as.current;Et&&(ie.src=Et)}const rt=()=>{ie.tabIndex=it,ie.style.pointerEvents="",ve?.focus(),ie.removeEventListener("load",rt)};ie.addEventListener("load",rt),setTimeout(rt,3e3)},yn)},initialEditSeo:$,onExitSeo:()=>z(!1),onViewJsonFile:ie=>{try{J(Ja(ie)),di("code")}catch{le.error("Invalid page block key")}}})})}),n.jsx("div",{className:"w-1 shrink-0 cursor-col-resize bg-transparent hover:bg-border transition-colors",onPointerDown:ie=>{p.current=!0,_.current=ie.clientX,g.current=f,ie.currentTarget.setPointerCapture(ie.pointerId)},onPointerMove:ie=>{if(!p.current)return;const ve=ie.clientX-_.current;m(Math.max(240,Math.min(640,g.current+ve)))},onPointerUp:()=>{p.current=!1}})]}),n.jsxs("div",{className:he("flex-1 relative overflow-hidden",r!=="desktop"&&we.kind==="iframe"&&s!=="code"&&"flex justify-center bg-muted/30"),children:[we.kind==="starting"&&n.jsx("div",{className:"absolute inset-0 z-30",children:n.jsx(Fr,{kind:"starting",progress:Se,claimPhase:xe})}),we.kind==="suspended"&&n.jsx("div",{className:"absolute inset-0 z-30",children:n.jsx(Fr,{kind:"suspended",onResume:X.resume})}),je==="visual"&&!a&&n.jsxs("div",{className:"absolute top-2 left-1/2 -translate-x-1/2 z-20 flex items-center gap-1.5 rounded-full border border-violet-400/40 bg-violet-500/90 px-3 py-1 text-xs font-medium text-white shadow-md backdrop-blur-sm pointer-events-none select-none",children:[n.jsx(qa,{size:12}),"Click any element to ask the AI"]}),je==="visual"&&a&&n.jsx(v1,{element:a,onDismiss:()=>l(null)}),s==="code"&&ge&&Y&&e&&n.jsx("div",{className:"absolute inset-0 z-10 bg-background",children:n.jsx(E.Suspense,{fallback:n.jsx("div",{className:"h-full flex items-center justify-center",children:n.jsx(Ce,{size:20,className:"animate-spin text-muted-foreground"})}),children:n.jsx(M1,{orgSlug:U.slug,virtualMcpId:Y,branch:e,openPath:V})})}),we.kind==="iframe"&&bt&&n.jsx("div",{className:he("h-full transition-[width] duration-250 [transition-timing-function:var(--ease-in-out-cubic)]",r!=="desktop"&&s!=="code"&&"w-full max-w-full border-x border-border bg-background shadow-sm"),style:{width:r==="desktop"||s==="code"?"100%":`${L1[r]}px`},children:n.jsx("iframe",{ref:h,src:bt,className:he("w-full h-full border-0",s==="code"&&"invisible"),title:"Dev Server Preview",tabIndex:c?-1:void 0,onLoad:()=>{if(De("vm_preview_loaded",{view_mode:s,vm_id:oe?.sandboxHandle??null}),!T)try{const ie=h.current?.contentWindow?.location?.pathname;if(!ie)return;const ve=G.current;if(ve!==null){G.current=null,me(ie)===me(ve)&&A(ie);return}A(ie)}catch{}s==="visual"&&tt(),s==="cms"&&st()}},we.previewUrl)})]})]}),n.jsx(d1,{open:j,onOpenChange:R,isPending:fe.isPending,error:B,onSubmit:Du}),W&&O&&ce&&n.jsx(E.Suspense,{fallback:null,children:n.jsx(B1,{open:W,onOpenChange:F,orgSlug:U.slug,virtualMcpId:Y??"",branch:e??"",decofile:O,meta:ce,onSaved:()=>{setTimeout(()=>{const ie=h.current;if(ie)try{ie.contentWindow?.location.reload()}catch{const ve=as.current;ve&&(ie.src=ve)}},yn)},target:{kind:"site"}})})]})}function F1(t){const e=K.c(2),{virtualMcpId:s}=t,i=Mt(s);if(!ti(i?.metadata)){let a;return e[0]===Symbol.for("react.memo_cache_sentinel")?(a=n.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-2 text-center text-sm text-muted-foreground p-6",children:[n.jsx(Ui,{size:24,className:"text-muted-foreground/60"}),n.jsx("div",{children:"No source to preview."}),n.jsx("div",{className:"text-xs text-muted-foreground/80",children:"Connect a GitHub repository from the Connections tab to enable Preview."})]}),e[0]=a):a=e[0],a}let o;return e[1]===Symbol.for("react.memo_cache_sentinel")?(o=n.jsx(z1,{}),e[1]=o):o=e[1],o}function H1(t,e){if(!t||!e?.length)return t;const s=Object.fromEntries(Object.entries(t.properties??{}).filter(([i])=>!e.includes(i)));return Object.keys(s).length>0?{...t,properties:s}:t}function W1(t,e,s){return typeof t!="string"?null:H1(Ih(t,e),s)}function hd(t,e,s){if(!e||typeof t!="string")return!1;const i=W1(t,e,s);return!!i&&Object.keys(i.properties??{}).length>0}function U1({orgSlug:t,virtualMcpId:e,branch:s}){const i=Qs();return ei({mutationFn:async({blockKey:r})=>{const o=rh(r),a=await fetch(`/api/${t}/sandbox/${encodeURIComponent(e)}/${encodeURIComponent(s)}/unlink`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({path:o})});if(!a.ok){const l=await a.json().catch(()=>({}));throw new Error(l.error??`Delete failed (${a.status})`)}return a.json()},onMutate:async({blockKey:r})=>{const o=`${t}/${e}/${s}`,a=Bt.decofile(o);await i.cancelQueries({queryKey:a});const l=i.getQueryData(a);return i.setQueryData(a,h=>{if(!h)return h;const{[r]:c,...d}=h;return d}),{previous:l,queryKey:a}},onError:(r,o,a)=>{a?.queryKey&&i.setQueryData(a.queryKey,a.previous)},onSuccess:()=>{const r=`${t}/${e}/${s}`;i.invalidateQueries({queryKey:Bt.liveMeta(r)})}})}function ln(t,e){return`${t}-${e}`}function ka(t,e){return`site/apps/${t}/${e}.ts`}function ja(t){const e=t.match(/^site\/apps\/([^/]+)\/([^/.]+)\.tsx?$/);if(e)return{vendor:e[1],app:e[2]};const s=t.match(/^([^/]+)\/apps\/([^/.]+)\.tsx?$/);return s?{vendor:s[1],app:s[2]}:null}function dd(t,e,s){const i=new Set([ln(t,e),e].map(o=>o.toLowerCase())),r=ka(t,e);for(const[o,a]of Object.entries(s)){if(o.includes("/")||!a||typeof a!="object"||Array.isArray(a))continue;const l=a;if(i.has(o.toLowerCase())||l.__resolveType===r)return o}return null}function K1(t,e){const s=t.vendor.alias,i=t.name,r=dd(s,i,e);return{id:ln(s,i),app:i,vendor:s,title:t.title||t.name,description:t.description,category:t.category??"Other",logo:t.logo||void 0,resolveType:ka(s,i),blockKey:r,installed:r!==null}}function V1(t,e,s){if(t===Ri)return null;const i=ja(t);if(!i)return null;const{vendor:r,app:o}=i,a=dd(r,o,s),l=Xi(t,e);return{id:ln(r,o),app:o,vendor:r,title:l.title??o,description:l.description??"",category:"Others",logo:l.logo??l.icon,resolveType:t,blockKey:a,installed:a!==null}}function q1(t,e,s){const i=new Map;for(const o of t){const a=K1(o,s);i.set(a.id,a)}const r=e.manifest?.blocks?.apps??{};for(const o of Object.keys(r)){const a=V1(o,e,s);!a||i.has(a.id)||i.set(a.id,a)}for(const o of X1(s,e)){const a=ja(o.resolveType);if(!a)continue;const l=ln(a.vendor,a.app);i.has(l)||i.set(l,{id:l,app:a.app,vendor:a.vendor,title:o.name,description:"",category:"Installed",resolveType:o.resolveType,blockKey:o.key,installed:!0})}return[...i.values()].sort(G1)}function G1(t,e){return t.installed!==e.installed?t.installed?-1:1:t.title.localeCompare(e.title)}function Y1(t,e,s){const i=t.manifest?.blocks?.apps??{};for(const r of[ka(e,s),`site/apps/${e}/${s}.tsx`,`${e}/apps/${s}.ts`,`${e}/apps/${s}.tsx`])if(r in i)return!0;return!1}function X1(t,e){const s=[];for(const[i,r]of Object.entries(t)){if(i.includes("/")||!r||typeof r!="object"||Array.isArray(r))continue;const o=r,a=o.__resolveType;if(typeof a!="string"||zh(i,o))continue;const l=ja(a)??(()=>{const h=i.match(/^([^-]+)-(.+)$/);return h?{vendor:h[1],app:h[2]}:null})();!l||!Y1(e,l.vendor,l.app)||s.push({key:i,name:i.replace(/[-_]/g," ").replace(/\b\w/g,h=>h.toUpperCase()),resolveType:a})}return s}async function J1(){const t=await fetch("/api/deco-apps");if(!t.ok)throw new Error(`Failed to fetch deco apps: ${t.status}`);return(await t.json()).apps??[]}function Z1(t,e,s){const i=K.c(12),r=s?.enabled??!0;let o;i[0]===Symbol.for("react.memo_cache_sentinel")?(o=Bt.decoApps(),i[0]=o):o=i[0];let a;i[1]!==r?(a={queryKey:o,queryFn:J1,staleTime:3e5,retry:1,enabled:r},i[1]=r,i[2]=a):a=i[2];const l=Zs(a);let h;i[3]!==e||i[4]!==t||i[5]!==l.data?(h=t&&e?q1(l.data??[],t,e):[],i[3]=e,i[4]=t,i[5]=l.data,i[6]=h):h=i[6];const c=h,d=l.isLoading&&!l.isError;let u;return i[7]!==c||i[8]!==l.isError||i[9]!==l.refetch||i[10]!==d?(u={catalog:c,isLoading:d,isError:l.isError,refetch:l.refetch},i[7]=c,i[8]=l.isError,i[9]=l.refetch,i[10]=d,i[11]=u):u=i[11],u}const Q1=new Set(["website/pages/Page.tsx","$live/pages/LivePage.tsx"]);function ex(t){return t.includes("matchers")||t.includes("Match")}function tx(t,e){const s=t.__resolveType;return typeof s!="string"||!s||Q1.has(s)?!1:e?y_(e,s):ex(s)}function Ji(t,e,s){if(!t)return!1;const i=t.__resolveType;if(typeof i!="string"||!fa(i)||!Object.hasOwn(e,i))return!1;const r=e[i];return!r||typeof r!="object"||Array.isArray(r)?!1:tx(r,s)}function WC(t,e,s){return Ji(t,e,s)?t?.__resolveType??null:null}function ud(t,e,s){if(!t)return null;const i=t.__resolveType??"";if(!i)return null;if(Ji(t,e,s)){const a=e[i]??{},l=a.__resolveType??i,{__resolveType:h,name:c,...d}=a;return{resolveType:l,data:d,blockKey:i}}const{__resolveType:r,...o}=t;return{resolveType:i,data:o}}function sx(t,e,s){const i=ud(t,e,s);return i?{__resolveType:i.resolveType,...i.data}:{__resolveType:""}}function UC(t,e,s){if(t)return Ji(t,e,s)?sx(t,e,s):t}function ix(t,e,s,i){if(!t)return"Default";if(Ji(t,e,i)){const r=t.__resolveType??"",o=e[r];return Fh(r,o)}return s(t)}function KC(t,e,s){return{__resolveType:t,...e,name:s}}function VC(t){return{__resolveType:t}}function qC(t,e,s){const i=ud(t,e,s);return i?{resolveType:i.resolveType,formValue:i.data}:{resolveType:"",formValue:{}}}function fd(t){const e=t.__resolveType??"";return es(e)?t.section??t:t}function Hr(t){const r=(es(t.__resolveType??"")?t.section:t)?.variants?.[0];return r?.rule?.__resolveType!==Eh?null:r?.value??null}function GC(t){const e=fd(t);return{__resolveType:Th,variants:[{value:e,rule:{__resolveType:Eh}}]}}function YC(t){const e=t.__resolveType??"";if(!e)return null;if(es(e))return t.section??null;const s=Hr(t);return s?es(s.__resolveType??"")?s:{__resolveType:ol,section:fd(s)}:{__resolveType:ol,section:t}}function ar(t){const e=t.__resolveType??"";if(!e)return null;if(es(e)){const s=t.section,i=s?.__resolveType??"";return!i||!s?null:{resolveType:i,data:s}}return{resolveType:e,data:t}}function XC(t){const e=Hr(t);if(e)return ar(e);if(es(t.__resolveType??"")){const i=t.section;if(!i)return null;const r=Hr(i);return ar(r||i)}return ar(t)}function JC(t){return Hr(t)}const rx=["website/matchers/always.ts","$live/matchers/MatchAlways.ts"];function md(t){if(!t)return!1;const e=t.__resolveType??"";return e===""?Object.keys(t).length===0:rx.includes(e)||e.includes("always")}function nx(t){const e=t.variants??[];if(e.length===0)return-1;const s=e.findIndex(i=>md(i.rule));return s!==-1?s:e.length-1}function ZC(t,e,s){const i=s.variants??[];if(i.length===0)return null;const r=nx(s),o=i[r]?.value;if(!o)return null;const a=structuredClone(o);return e.isLazy?{...t,section:a}:a}function pd(t,e){return e.isMultivariate?e.isLazy?t.section??null:t:null}function QC(t,e){return Array.isArray(t.variants)?t.variants.map((s,i)=>({label:e(s.rule)||`Variant ${i+1}`,value:s.value??{},rule:s.rule})):[]}function ek(t,e){const s=t.__resolveType??"";if(!s)return null;if(es(s)){const i=t.section??t,r=i.__resolveType??s;if(!r.includes("/")&&r in e){const o=e[r]??{};return{data:{...o},resolveType:o.__resolveType??r}}return{data:{...i},resolveType:r}}if(!s.includes("/")&&s in e){const i=e[s]??{};return{data:{...i},resolveType:i.__resolveType??s}}return{data:{...t},resolveType:s}}function ox(t,e){const s=t.__resolveType??"";return es(s)?{...t,section:e}:e}function ax(t,e,s){return e.isLazy?{...t,section:s}:s}function tk(t,e,s){const i=[...t.variants??[]],r=i[e];if(!r)return t;const o=r.value??{};return i[e]={...r,value:ox(o,s)},{...t,variants:i}}function sk(t,e,s){const i=[...t.variants??[]];return i[e]?(i[e]={...i[e],rule:s},{...t,variants:i}):t}function ik(t,e){const s=[...t.variants??[]],i=s[e];return i?(s.splice(e+1,0,structuredClone(i)),{...t,variants:s}):t}function rk(t,e){const s=[...t.variants??[]];return s.length<=1?null:(s.splice(e,1),{...t,variants:s})}function Zn(t){return{rule:ma(),value:structuredClone(t)}}function _d(t,e){return{...e,__resolveType:Th,variants:t}}function nk(t){return t.isHidden!==!0&&t.isSavedBlock!==!0}function lx(t,e){if(e.isHidden)return null;if(e.isMultivariate){const i=pd(t,e)?.variants??[],r=i[i.length-1]?.value;return r?structuredClone(r):null}if(e.isLazy){const s=t.section;return s?structuredClone(s):null}return structuredClone(t)}function cx(t,e,s){if(e.isMultivariate||e.isHidden)return null;const i=lx(t,e);if(!i)return null;const r=_d([Zn(i),Zn(i)]);return e.isLazy?{...t,section:r}:r}function ok(t,e,s){if(e.isHidden||e.isSavedBlock)return null;if(e.isMultivariate){const r=pd(t,e);if(!r)return null;const o=r.variants??[],a=o[o.length-1]?.value;if(!a)return null;const l=_d([...o,Zn(a)],r);return{section:ax(t,e,l),newVariantIndex:o.length}}const i=cx(t,e);return i?{section:i,newVariantIndex:1}:null}const hx=new Set(["website/pages/Page.tsx","$live/pages/LivePage.tsx"]);function ak(t){return t.anyOfRefs?.some(e=>e.resolveType!==on?!1:e.schema?.properties?.variants?.items?.properties?.value?.type==="array")??!1}function gd(t){return!t||typeof t!="object"||Array.isArray(t)?!1:t.__resolveType===on}function lk(t){if(!gd(t))return null;const e=t.variants;if(!Array.isArray(e))return null;const s=e[0]?.value;return Array.isArray(s)?s:null}function ck(t,e){if(!gd(t))return e;const s=structuredClone(t),i=[...s.variants??[]];return i.length===0?i.push({rule:ma(),value:e}):i[0]={...i[0],value:e},{...s,variants:i}}function dx(t){if(!t||typeof t!="object"||Array.isArray(t))return!1;const e=t;return typeof e.__resolveType=="string"&&hx.has(e.__resolveType)&&typeof e.path=="string"}function vd(t,e){const i=t[e]?.sections;if(!i||Array.isArray(i))return 1;const r=i;return Array.isArray(r.variants)?r.variants.length:1}function ux(t,e,s){const r=t[e]?.sections;if(Array.isArray(r))return s===0?r:[];if(r&&typeof r=="object"){const o=r.variants;if(Array.isArray(o)){const a=o[s];return Array.isArray(a?.value)?a.value:[]}}return[]}function hk(t,e,s){if(Array.isArray(t))return[{label:"Default",sections:t}];if(t&&typeof t=="object"){const i=t;if(Array.isArray(i.variants)){const r=i.variants,o=r.map(h=>ix(h.rule,e,s)),a=o.reduce((h,c)=>(h[c]=(h[c]??0)+1,h),{}),l={};return r.map((h,c)=>{const d=o[c]??`Variant ${c+1}`,u=a[d]??1;let f=d;return u>1&&(l[d]=(l[d]??0)+1,f=`${d} ${l[d]}`),{label:f||`Variant ${c+1}`,sections:Array.isArray(h.value)?h.value:[],rule:h.rule}})}}return[]}function fi(t){return{rule:ma(),value:t}}function Ks(t,e){return{...e,__resolveType:on,variants:t}}function fx(t,e){const s=structuredClone(e);if(Array.isArray(t))return Ks([fi(t),fi(s)]);if(t&&typeof t=="object"){const i=t;return Array.isArray(i.variants)?Ks([...i.variants,fi(s)],i):null}return Ks([fi([]),fi(s)])}function dk(t){const e=t.variants;return Array.isArray(e)?e.length-1:1}function uk(t,e){if(e.length===0)return Ks([],t);if(e.length===1){const s=e[0],i=s?.rule;if(!md(i))return Ks(e,t);if(Array.isArray(s?.value))return s.value}return Ks(e,t)}function mx(t,e){for(const[s,i]of Object.entries(t)){if(!dx(i))continue;const r=i.sections;if(Array.isArray(r)){e(void 0,s,0);continue}if(!r||typeof r!="object")continue;const o=r.variants;if(Array.isArray(o))for(let a=0;a<o.length;a++){const l=o[a];e(l?.rule,s,a)}}}function fk(t,e,s){let i=0;return mx(t,r=>{if(!r)return;(r.__resolveType??"")===e&&Ji(r,t,s)&&i++}),i}function wl(t,e){const s=e.replace(/\s*\(copy(?:\s+\d+)?\)\s*$/,"").trim(),i=`${s} (copy)`;if(!t.has(i))return i;for(let r=2;r<1e3;r++){const o=`${s} (copy ${r})`;if(!t.has(o))return o}return`${s} (copy ${Date.now()})`}function px(t,e){const s=Us,i=e.replace(/-copy(?:-\d+)?$/,""),r=`${i}-copy`;if(!t.has(s(r)))return r;for(let o=2;o<1e3;o++){const a=`${i}-copy-${o}`;if(!t.has(s(a)))return a}return`${i}-copy-${Date.now()}`}function Cl(t,e){const s=e.replace(/_copy(?:_\d+)?$/,""),i=`${s}_copy`;if(!Object.hasOwn(t,i))return i;for(let r=2;r<1e3;r++){const o=`${s}_copy_${r}`;if(!Object.hasOwn(t,o))return o}return`${s}_copy_${Date.now()}`}function _x(t){const e=wa(t.newName),s={...t.source,name:t.newName,path:t.newPath};return{key:e,data:s}}function gx(t,e){return nd(t,e)}const vx=1e3;function xx(t,e){for(let s=0;s<vx;s++){const i=wa(e);if(!Object.hasOwn(t,i))return i}throw new Error("Could not generate a unique page block key")}const bx={create:"Create new page",duplicate:"Duplicate page",rename:"Rename page"},yx={create:"Create",duplicate:"Duplicate",rename:"Save"},Sx={create:"Creating…",duplicate:"Duplicating…",rename:"Saving…"};function wx(t){const e=K.c(54),{open:s,mode:i,initialName:r,initialPath:o,isPending:a,error:l,validate:h,onSubmit:c,onOpenChange:d}=t,u=a===void 0?!1:a,[f,m]=E.useState(r),[p,_]=E.useState(o),[g,v]=E.useState(null),[b,x]=E.useState(s);s!==b&&(x(s),s&&(m(r),_(o),v(null)));let y;e[0]!==u||e[1]!==d?(y=H=>{!H&&!u&&(v(null),d(!1))},e[0]=u,e[1]=d,e[2]=y):y=e[2];const w=y;let C;e[3]!==u||e[4]!==f||e[5]!==c||e[6]!==p||e[7]!==h?(C=async H=>{H.preventDefault();const X=f.trim(),oe=p.trim();if(!X||!oe||u)return;const L=pa(oe);if(L){v(L);return}const se=h?.({name:X,path:oe});if(se){v(se);return}v(null),await c({name:X,path:oe})},e[3]=u,e[4]=f,e[5]=c,e[6]=p,e[7]=h,e[8]=C):C=e[8];const j=C,R=g??l,B=bx[i];let P;e[9]!==B?(P=n.jsx(is,{children:n.jsx(rs,{children:B})}),e[9]=B,e[10]=P):P=e[10];let T;e[11]===Symbol.for("react.memo_cache_sentinel")?(T=n.jsx("label",{htmlFor:"page-form-name",className:"text-xs font-medium text-muted-foreground",children:"Name"}),e[11]=T):T=e[11];let S;e[12]===Symbol.for("react.memo_cache_sentinel")?(S=H=>m(H.target.value),e[12]=S):S=e[12];let k;e[13]!==u||e[14]!==f?(k=n.jsxs("div",{className:"space-y-1.5",children:[T,n.jsx(qe,{id:"page-form-name",value:f,onChange:S,placeholder:"My page",autoFocus:!0,disabled:u})]}),e[13]=u,e[14]=f,e[15]=k):k=e[15];let I;e[16]===Symbol.for("react.memo_cache_sentinel")?(I=n.jsx("label",{htmlFor:"page-form-path",className:"text-xs font-medium text-muted-foreground",children:"Path"}),e[16]=I):I=e[16];let N;e[17]===Symbol.for("react.memo_cache_sentinel")?(N=H=>_(H.target.value),e[17]=N):N=e[17];let A;e[18]!==u||e[19]!==p?(A=n.jsxs("div",{className:"space-y-1.5",children:[I,n.jsx(qe,{id:"page-form-path",value:p,onChange:N,placeholder:"/example",disabled:u})]}),e[18]=u,e[19]=p,e[20]=A):A=e[20];let M;e[21]!==R?(M=R&&n.jsx("p",{className:"text-xs text-destructive",children:R}),e[21]=R,e[22]=M):M=e[22];let D;e[23]!==A||e[24]!==M||e[25]!==k?(D=n.jsxs("div",{className:"space-y-4 py-4",children:[k,A,M]}),e[23]=A,e[24]=M,e[25]=k,e[26]=D):D=e[26];let $;e[27]!==d?($=()=>d(!1),e[27]=d,e[28]=$):$=e[28];let z;e[29]!==u||e[30]!==$?(z=n.jsx(re,{type:"button",variant:"outline",onClick:$,disabled:u,children:"Cancel"}),e[29]=u,e[30]=$,e[31]=z):z=e[31];let W;e[32]!==u||e[33]!==f||e[34]!==p?(W=!f.trim()||!p.trim()||u,e[32]=u,e[33]=f,e[34]=p,e[35]=W):W=e[35];let F;e[36]!==u||e[37]!==i?(F=u?n.jsxs(n.Fragment,{children:[n.jsx(Ce,{size:14,className:"animate-spin"}),Sx[i]]}):yx[i],e[36]=u,e[37]=i,e[38]=F):F=e[38];let V;e[39]!==W||e[40]!==F?(V=n.jsx(re,{type:"submit",disabled:W,children:F}),e[39]=W,e[40]=F,e[41]=V):V=e[41];let J;e[42]!==z||e[43]!==V?(J=n.jsxs(ii,{children:[z,V]}),e[42]=z,e[43]=V,e[44]=J):J=e[44];let Y;e[45]!==j||e[46]!==D||e[47]!==J||e[48]!==P?(Y=n.jsx(Ot,{className:"sm:max-w-md",children:n.jsxs("form",{onSubmit:j,children:[P,D,J]})}),e[45]=j,e[46]=D,e[47]=J,e[48]=P,e[49]=Y):Y=e[49];let U;return e[50]!==w||e[51]!==s||e[52]!==Y?(U=n.jsx(Lt,{open:s,onOpenChange:w,children:Y}),e[50]=w,e[51]=s,e[52]=Y,e[53]=U):U=e[53],U}function Cx(t){const e=K.c(43),{open:s,blockKey:i,initialName:r,isPending:o,onSubmit:a,onOpenChange:l}=t,h=o===void 0?!1:o,[c,d]=E.useState(r),[u,f]=E.useState(s);s!==u&&(f(s),s&&d(r));let m;e[0]!==h||e[1]!==l?(m=A=>{!A&&!h&&l(!1)},e[0]=h,e[1]=l,e[2]=m):m=e[2];const p=m;let _;e[3]!==h||e[4]!==c||e[5]!==a?(_=async A=>{A.preventDefault();const M=c.trim();!M||h||await a(M)},e[3]=h,e[4]=c,e[5]=a,e[6]=_):_=e[6];const g=_;let v;e[7]===Symbol.for("react.memo_cache_sentinel")?(v=n.jsxs(is,{children:[n.jsx(rs,{children:"Rename section"}),n.jsx(Jo,{children:"Updates the display name. The internal key stays the same so pages referencing this section keep working."})]}),e[7]=v):v=e[7];let b;e[8]===Symbol.for("react.memo_cache_sentinel")?(b=n.jsx("label",{htmlFor:"section-rename-name",className:"text-xs font-medium text-muted-foreground",children:"Name"}),e[8]=b):b=e[8];let x;e[9]===Symbol.for("react.memo_cache_sentinel")?(x=A=>d(A.target.value),e[9]=x):x=e[9];let y;e[10]!==h||e[11]!==c?(y=n.jsxs("div",{className:"space-y-1.5",children:[b,n.jsx(qe,{id:"section-rename-name",value:c,onChange:x,autoFocus:!0,disabled:h})]}),e[10]=h,e[11]=c,e[12]=y):y=e[12];let w;e[13]===Symbol.for("react.memo_cache_sentinel")?(w=n.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"Key"}),e[13]=w):w=e[13];let C;e[14]!==i?(C=n.jsxs("div",{className:"space-y-1.5",children:[w,n.jsx(qe,{value:i,readOnly:!0,disabled:!0,className:"font-mono"})]}),e[14]=i,e[15]=C):C=e[15];let j;e[16]!==y||e[17]!==C?(j=n.jsxs("div",{className:"space-y-4 py-4",children:[y,C]}),e[16]=y,e[17]=C,e[18]=j):j=e[18];let R;e[19]!==l?(R=()=>l(!1),e[19]=l,e[20]=R):R=e[20];let B;e[21]!==h||e[22]!==R?(B=n.jsx(re,{type:"button",variant:"outline",onClick:R,disabled:h,children:"Cancel"}),e[21]=h,e[22]=R,e[23]=B):B=e[23];let P;e[24]!==h||e[25]!==c?(P=!c.trim()||h,e[24]=h,e[25]=c,e[26]=P):P=e[26];let T;e[27]!==h?(T=h?n.jsxs(n.Fragment,{children:[n.jsx(Ce,{size:14,className:"animate-spin"}),"Saving…"]}):"Save",e[27]=h,e[28]=T):T=e[28];let S;e[29]!==P||e[30]!==T?(S=n.jsx(re,{type:"submit",disabled:P,children:T}),e[29]=P,e[30]=T,e[31]=S):S=e[31];let k;e[32]!==B||e[33]!==S?(k=n.jsxs(ii,{children:[B,S]}),e[32]=B,e[33]=S,e[34]=k):k=e[34];let I;e[35]!==g||e[36]!==j||e[37]!==k?(I=n.jsx(Ot,{className:"sm:max-w-md",children:n.jsxs("form",{onSubmit:g,children:[v,j,k]})}),e[35]=g,e[36]=j,e[37]=k,e[38]=I):I=e[38];let N;return e[39]!==p||e[40]!==s||e[41]!==I?(N=n.jsx(Lt,{open:s,onOpenChange:p,children:I}),e[39]=p,e[40]=s,e[41]=I,e[42]=N):N=e[42],N}const wn={post:"blog/loaders/Blogpost.ts",author:"blog/loaders/Author.ts",category:"blog/loaders/Category.ts"},kx="blog/sections/blocks/",Na=["posts","authors","categories"],Pi={posts:"post",authors:"author",categories:"category"};function Di(t){return Na.includes(t)}const Ea={posts:"post",authors:"author",categories:"category"},xd={posts:wn.post,authors:wn.author,categories:wn.category},jx=Object.fromEntries(Object.entries(xd).map(([t,e])=>[e,t]));function Nx(t){return typeof t=="string"?jx[t]??null:null}function Wr(t){return t&&typeof t=="object"&&!Array.isArray(t)?t:null}function $s(t){return typeof t=="string"?t:""}function Ex(t,e){switch(t){case"posts":return{label:$s(e.title)||"Untitled post",subtitle:$s(e.slug)};case"authors":return{label:$s(e.name)||"Unnamed author",subtitle:$s(e.email)};case"categories":return{label:$s(e.name)||"Unnamed category",subtitle:$s(e.slug)};default:{const s=t;throw new Error(`Unhandled blog kind: ${String(s)}`)}}}function bd(t){const e={posts:[],authors:[],categories:[]};for(const[s,i]of Object.entries(t)){const r=Wr(i);if(!r)continue;const o=Nx(r.__resolveType);if(!o)continue;const a=Wr(r[Ea[o]])??{},{label:l,subtitle:h}=Ex(o,a);e[o].push({key:s,kind:o,label:l,subtitle:h})}for(const s of Na)e[s].sort((i,r)=>i.label.localeCompare(r.label));return e}function Tx(t,e){return bd(t)[e]}function mk(t,e){return Tx(t,e).map(s=>({key:s.key,payload:yd(Wr(t[s.key])??void 0,e)}))}function yd(t,e){return t?Wr(t[Ea[e]])??{}:{}}function kl(t,e,s){return{name:t,__resolveType:xd[e],[Ea[e]]:s}}function Sd(t){return`.deco/blocks/${encodeURIComponent(t)}.json`}function Qn(t){const e=new Uint8Array(Math.ceil(t/2));return crypto.getRandomValues(e),Array.from(e,s=>s.toString(16).padStart(2,"0")).join("").slice(0,t)}function jl(t,e){const s=`collections/blog/${e}/${Qn(12)}`;if(!Object.hasOwn(t,s))return s;throw new Error("Could not generate a unique blog block key")}function Rx(t){switch(t){case"posts":return{title:"Untitled post",excerpt:"",slug:`untitled-${Qn(8)}`,date:new Date().toISOString().slice(0,10),image:"",authors:[],categories:[],sections:[]};case"authors":return{name:"New author",email:"",jobTitle:"",company:"",avatar:""};case"categories":return{name:"New category",slug:`category-${Qn(8)}`};default:{const e=t;throw new Error(`Unhandled blog kind: ${String(e)}`)}}}function pk(t){const e=new Set,s=[],i=t.manifest?.blocks??{};for(const r of Object.values(i))for(const o of Object.keys(r)){if(!o.startsWith(kx)||e.has(o))continue;e.add(o);const a=Xi(o,t);s.push({resolveType:o,title:a.title??Px(o),description:a.description,icon:a.icon})}return s.sort((r,o)=>r.title.localeCompare(o.title))}function Px(t){return(t.split("/").pop()??t).replace(/\.(tsx?|jsx?)$/,"")}const Dx=["blog/sections/blocks/","site/sections/Blog/Post/"];function _k(t){return Dx.some(e=>t.startsWith(e))}function wd({orgSlug:t,virtualMcpId:e,branch:s}){return Bt.decofile(`${t}/${e}/${s}`)}function Cd({orgSlug:t,virtualMcpId:e,branch:s},i){return`/api/${t}/sandbox/${encodeURIComponent(e)}/${encodeURIComponent(s)}/${i}`}function Ax(t){const e=K.c(11),s=Qs();let i;e[0]!==t?(i=async l=>{const{blockKey:h,data:c}=l,d=await fetch(Cd(t,"write"),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({path:Sd(h),content:JSON.stringify(c,null,2)})});if(!d.ok){const u=await d.json().catch(Ix);throw new Error(u.error??`Write failed (${d.status})`)}return d.json()},e[0]=t,e[1]=i):i=e[1];let r;e[2]!==t||e[3]!==s?(r=async l=>{const{blockKey:h,data:c}=l,d=wd(t);await s.cancelQueries({queryKey:d});const u=s.getQueryData(d);return s.setQueryData(d,f=>({...f??{},[h]:c})),{previous:u,queryKey:d}},e[2]=t,e[3]=s,e[4]=r):r=e[4];let o;e[5]!==s?(o=(l,h,c)=>{c?.queryKey&&s.setQueryData(c.queryKey,c.previous)},e[5]=s,e[6]=o):o=e[6];let a;return e[7]!==i||e[8]!==r||e[9]!==o?(a={mutationFn:i,onMutate:r,onError:o},e[7]=i,e[8]=r,e[9]=o,e[10]=a):a=e[10],ei(a)}function Ix(){return{}}function Bx(t){const e=Qs();return ei({mutationFn:async({blockKey:s})=>{const i=await fetch(Cd(t,"unlink"),{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({path:Sd(s)})});if(!i.ok){const r=await i.json().catch(()=>({}));throw new Error(r.error??`Delete failed (${i.status})`)}return i.json()},onMutate:async({blockKey:s})=>{const i=wd(t);await e.cancelQueries({queryKey:i});const r=e.getQueryData(i);return e.setQueryData(i,o=>{if(!o)return o;const{[s]:a,...l}=o;return l}),{previous:r,queryKey:i}},onError:(s,i,r)=>{r?.queryKey&&e.setQueryData(r.queryKey,r.previous)}})}function Mx(t){const e=K.c(20),{open:s,onOpenChange:i,pageKey:r,decofile:o}=t,[a,l]=E.useState(!1),h=o[r];let c;e[0]!==h?(c=h===void 0?"// Page not found.":JSON.stringify(h,null,2),e[0]=h,e[1]=c):c=e[1];const d=c;let u;e[2]!==d?(u=()=>{navigator.clipboard.writeText(d).then(()=>{l(!0),setTimeout(()=>l(!1),2e3)})},e[2]=d,e[3]=u):u=e[3];const f=u;let m;e[4]===Symbol.for("react.memo_cache_sentinel")?(m=n.jsx(rs,{className:"text-sm font-semibold",children:"Page JSON"}),e[4]=m):m=e[4];let p;e[5]!==a?(p=a?n.jsx(zc,{size:12}):n.jsx(Qt,{size:12}),e[5]=a,e[6]=p):p=e[6];const _=a?"Copied":"Copy";let g;e[7]!==f||e[8]!==p||e[9]!==_?(g=n.jsxs(is,{className:"px-4 py-3 border-b flex-row items-center justify-between space-y-0",children:[m,n.jsxs(re,{variant:"ghost",size:"sm",onClick:f,className:"h-7 gap-1.5 text-xs",children:[p,_]})]}),e[7]=f,e[8]=p,e[9]=_,e[10]=g):g=e[10];let v;e[11]!==d?(v=n.jsx(rn,{className:"max-h-[70vh]",children:n.jsx("pre",{className:"p-4 text-xs font-mono text-foreground/90 whitespace-pre overflow-auto",children:d})}),e[11]=d,e[12]=v):v=e[12];let b;e[13]!==g||e[14]!==v?(b=n.jsxs(Ot,{className:"max-w-2xl p-0 gap-0",children:[g,v]}),e[13]=g,e[14]=v,e[15]=b):b=e[15];let x;return e[16]!==i||e[17]!==s||e[18]!==b?(x=n.jsx(Lt,{open:s,onOpenChange:i,children:b}),e[16]=i,e[17]=s,e[18]=b,e[19]=x):x=e[19],x}const Nl=E.lazy(()=>qt(()=>import("./app-editor-CJE_W_Dn.js"),__vite__mapDeps([156,1,2,4,46,47,48,16,3,5,153,135,83,22,136,100,20,49,44,21,51,18,29,30,78,6,7,8,9,10,11,12,13,14,15,17,19,23,24,25,26,27,28,31,32,33,34,35,36,37,38,39,40,41,42,43,45,79,50,72,80,73,81,82,84,85,76,60,61,157,90,91,92,58,93,94,95,57,77,59,96,97,98,99,101,102,103,104,105,106,107,66,108,56,109,71,110,70,67,111,52,53,54,55,62,63,64,65,68,69,74,75,112,113,114,115,116,87,88,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152])).then(t=>({default:t.AppEditor}))),Lx=E.lazy(()=>qt(()=>import("./post-editor-Bw21I9pc.js"),__vite__mapDeps([158,1,2,3,6,7,8,9,10,11,12,13,14,15,16,17,4,5,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,49,70,48,71,72,50,47,73,74,75,76,77,96,97,98,46,99,100,101,102,91,92,93,94,95,103,104,105,106,107,108,109,110,149,121,150,132,151,128,130,147,114,87,88,80,82,51,83,84,85,78,79,81,159,157,90,111,112,113,115,116,117,118,119,120,122,123,124,125,126,127,129,131,133,134,135,136,137,138,139,140,141,142,143,144,145,146,148,152])).then(t=>({default:t.PostEditor}))),Ox=E.lazy(()=>qt(()=>import("./record-editor-803FPqaV.js"),__vite__mapDeps([160,1,2,50,72,73,82,8,39,40,7,16,20,18,6,9,10,11,12,13,14,15,3,17,4,5,19,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,41,42,43,44,45,49,51,83,84,85,76,60,61,159,157,90,91,92,58,93,94,95,57,77,59,96,97,98,46,47,48,99,100,101,102,103,104,105,106,107,66,108,56,109,71,110,70,67,111,52,53,54,55,62,63,64,65,68,69,74,75,112,113,114,115,116,80,87,88,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,81,139,140,141,142,143,144,145,146,147,148,149,150,151,152])).then(t=>({default:t.RecordEditor}))),$x=E.lazy(()=>qt(()=>import("./sections-editor-DJ6-AL_q.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153])).then(t=>({default:t.SectionsEditor}))),zx=E.lazy(()=>qt(()=>import("./seo-editor-pRBB6PMK.js"),__vite__mapDeps([161,1,2,4,6,7,8,9,10,11,12,13,14,15,16,3,17,5,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,86,72,81,78,79,50,80,73,51,82,49,83,84,85,76,60,61,90,91,92,58,93,94,95,57,77,59,96,97,98,99,100,101,102,103,104,105,106,107,66,108,56,109,71,110,70,67,111,52,53,54,55,62,63,64,65,68,69,74,75,112,113,114,115,116,87,88,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152])).then(t=>({default:t.SeoEditor}))),Fx=E.lazy(()=>qt(()=>import("./add-section-modal-BPiyATcO.js"),__vite__mapDeps([89,1,2,6,7,8,9,10,11,12,13,14,15,16,3,17,4,5,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,49,50,90,91,92,58,93,94,76,95,57,77,59,96,97,98,46,47,48,99,100,101,102,103,104,105,106,107,66,108,56,109,71,72,110,70,67,84,111,52,53,54,55,60,61,62,63,64,65,68,69,73,74,75,112,113,114,83,115,116,80,87,88,117,51,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,81,139,140,141,142,143,144,145,146,147,148,149,150,151,152])).then(t=>({default:t.AddSectionModal}))),eo="oklch(0.65 0.15 160)";function Hx(){const t=K.c(18),e=sr(),{data:s}=Js.useSession(),{currentBranch:i}=ss(),{org:r}=Pe(),o=e?.entity?.id??null,a=s?.user?.id,l=e?.entity?.metadata,h=a&&i?Jr(l?.sandboxMap?.[a]?.[i]):{},c=Object.values(h),u=(c.find(Wx)??c[0])?.previewUrl??null,f=Yt(),m=e?.entity?.organization_id??"";let p;t[0]!==r.slug||t[1]!==m?(p={connectionId:Ho,orgId:m,orgSlug:r.slug},t[0]=r.slug,t[1]=m,t[2]=p):p=t[2];const _=ft(p),g=zo(_);let v;t[3]!==i||t[4]!==g||t[5]!==o?(v=()=>{if(!o)return;const C={virtualMcpId:o};i&&(C.branch=i),g.mutate(C)},t[3]=i,t[4]=g,t[5]=o,t[6]=v):v=t[6];const b=v,x=!!o&&!!i&&$n.isStopped(o,i),y=ed({previewUrl:u,appPaused:f.status.state==="paused",userStopped:x});if(y.kind!=="iframe"){let C;return t[7]!==y||t[8]!==b||t[9]!==f.lifecycle||t[10]!==f.phase?(C=n.jsx(Yx,{state:y,claimPhase:f.phase,lifecycle:f.lifecycle,onStart:b}),t[7]=y,t[8]=b,t[9]=f.lifecycle,t[10]=f.phase,t[11]=C):C=t[11],C}if(!o||!i){let C;return t[12]===Symbol.for("react.memo_cache_sentinel")?(C=n.jsx(Si,{title:"Waiting for sandbox context…"}),t[12]=C):C=t[12],C}let w;return t[13]!==i||t[14]!==r.slug||t[15]!==u||t[16]!==o?(w=n.jsx(Kx,{orgSlug:r.slug,virtualMcpId:o,branch:i,previewUrl:u}),t[13]=i,t[14]=r.slug,t[15]=u,t[16]=o,t[17]=w):w=t[17],w}function Wx(t){return t.sandboxProviderKind!=="user-desktop"}const El=2e3,Ux=15;function Tl(t,e,s,i){return typeof e!="string"||s&&(hd(e,s,i)||t.state.dataUpdateCount>=Ux)?!1:El}function Kx({orgSlug:t,virtualMcpId:e,branch:s,previewUrl:i}){const r={orgSlug:t,virtualMcpId:e,branch:s},{data:o,isLoading:a}=ha(r),[l,h]=E.useState("pages"),[c,d]=E.useState(null),[u,f]=E.useState(null),[m,p]=E.useState(""),[_,g]=E.useState(l);_!==l&&(g(l),p(""));const{data:v,isLoading:b,isFetching:x}=da(r,{refetchInterval:G=>{const _e=G.state.data;if(l==="apps"&&c&&c.collection==="apps"){const xe=o?.[c.key];return Tl(G,typeof xe?.__resolveType=="string"?xe.__resolveType:void 0,_e)}if(l==="site"&&o){const xe=_e?Jn(o,_e):null,Se=o.site,we=xe?.resolveType??(typeof Se?.__resolveType=="string"?Se.__resolveType:void 0);return Tl(G,we,_e,["seo"])}return!1}}),y=(G,_e)=>!hd(G,v,_e)&&(b||x),{catalog:w,isLoading:C}=Z1(v??void 0,o??void 0,{enabled:l==="apps"}),j=Ca(r),R=U1(r),B=Ax(r),P=Bx(r),[T,S]=E.useState(null),[k,I]=E.useState(),[N,A]=E.useState(!1),[M,D]=E.useState(null),[$,z]=E.useState(null),[W,F]=E.useState(null);if(a||b)return n.jsx("div",{className:"h-full w-full flex items-center justify-center",children:n.jsx(Ce,{size:20,className:"animate-spin text-muted-foreground"})});if(!o||!v)return n.jsx(Si,{title:"Could not load site data."});const V=va(o).sort((G,_e)=>G.name.localeCompare(_e.name)),J=xa(o,v),Y=Jn(o,v),U=bd(o),H=Na.some(G=>U[G].length>0),X=Di(l)?U[l]:[];if(!ga(o,v)&&!H)return n.jsx(Si,{icon:Ui,title:"No editable content",description:"This project doesn't expose any Deco pages, sections, or apps."});const oe={pages:V.length,sections:J.length,apps:w.length,posts:U.posts.length,authors:U.authors.length,categories:U.categories.length},L=new Set(V.map(G=>Us(G.path))),se=new Set(V.map(G=>G.name)),ee=new Set(J.map(G=>G.name)),Q=async G=>{const _e=o[G.key];if(!_e)return;const xe=vd(o,G.key),Se=ux(o,G.key,Math.max(0,xe-1)),we=fx(_e.sections,Se);if(we)try{await j.mutateAsync({blockKey:G.key,data:{..._e,sections:we}}),le.success(`Variant added to "${G.name}"`),d({collection:"pages",key:G.key,path:G.path})}catch(et){le.error(et instanceof Error?et.message:"Could not add variant")}},O=()=>{I(void 0),S({mode:"create",sourceKey:null,initialName:"My new page",initialPath:"/example"})},ce=G=>{I(void 0),S({mode:"duplicate",sourceKey:G.key,initialName:wl(se,G.name),initialPath:px(L,G.path)})},ue=G=>{I(void 0),S({mode:"rename",sourceKey:G.key,initialName:G.name,initialPath:G.path})},fe=async G=>{if(!T)return;const{mode:_e,sourceKey:xe}=T;try{if(_e==="create"){const Se=gx(G.name,G.path),we=xx(o,G.name);await j.mutateAsync({blockKey:we,data:Se}),le.success(`Created "${G.name}"`),d({collection:"pages",key:we,path:G.path})}else if(_e==="duplicate"&&xe){const Se=o[xe];if(!Se)throw new Error("Source page not found");const{key:we,data:et}=_x({source:Se,pages:V,newName:G.name,newPath:G.path});await j.mutateAsync({blockKey:we,data:et}),le.success(`Duplicated as "${G.name}"`),d({collection:"pages",key:we,path:G.path})}else if(_e==="rename"&&xe){const Se=o[xe];if(!Se)throw new Error("Page not found");const we={...Se,name:G.name,path:G.path};await j.mutateAsync({blockKey:xe,data:we}),le.success("Page updated"),c?.collection==="pages"&&c.key===xe&&d({collection:"pages",key:xe,path:G.path})}S(null)}catch(Se){I(Se instanceof Error?Se.message:"Save failed")}},q=({path:G})=>{if(!T)return null;const _e=Us(G);return(T.mode==="rename"?Us(T.initialPath):null)!==_e&&L.has(_e)?`A page with path "${G}" already exists.`:null},te=async G=>{const _e=(G.title||G.resolveType.split("/").pop()||"").replace(/\.(tsx?|jsx?)$/,"").replace(/[^A-Za-z0-9_-]/g,""),xe=/^[A-Za-z]/.test(_e)&&_e.length>0?_e:"Section",Se=Cl(o,xe),we={__resolveType:G.resolveType,name:Se};try{await j.mutateAsync({blockKey:Se,data:we}),le.success(`Created section "${Se}"`),A(!1),d({collection:"sections",key:Se})}catch(et){le.error(et instanceof Error?et.message:"Could not create section")}},me=async G=>{const _e=o[G.key];if(!_e){le.error("Section not found.");return}const xe=Cl(o,G.key),Se=wl(ee,G.name),we={..._e,name:Se};try{await j.mutateAsync({blockKey:xe,data:we}),le.success(`Duplicated "${G.name}"`),d({collection:"sections",key:xe})}catch(et){le.error(et instanceof Error?et.message:"Duplicate failed")}},ne=async G=>{if(!M)return;const _e=o[M];if(!_e){le.error("Section not found.");return}try{await j.mutateAsync({blockKey:M,data:{..._e,name:G}}),le.success("Section renamed"),D(null)}catch(xe){le.error(xe instanceof Error?xe.message:"Rename failed")}},ke=async G=>{const _e=jl(o,G),xe=kl(_e,G,Rx(G));try{await B.mutateAsync({blockKey:_e,data:xe}),le.success(`Created ${Pi[G]}`),d({collection:G,key:_e})}catch(Se){le.error(Se instanceof Error?Se.message:"Could not create")}},at=async G=>{const _e=o[G.key];if(!_e){le.error("Record not found.");return}const xe=jl(o,G.kind),Se=G.kind==="posts"?"title":"name",we={...structuredClone(yd(_e,G.kind)),[Se]:`${G.label} (copy)`};try{await B.mutateAsync({blockKey:xe,data:kl(xe,G.kind,we)}),le.success(`Duplicated "${G.label}"`),d({collection:G.kind,key:xe})}catch(et){le.error(et instanceof Error?et.message:"Duplicate failed")}},Be=async()=>{if(!$)return;const{kind:G,key:_e,label:xe}=$;try{G==="blog"?await P.mutateAsync({blockKey:_e}):await R.mutateAsync({blockKey:_e}),le.success(`Deleted "${xe}"`),c&&c.key===_e&&d(null),z(null)}catch(Se){le.error(Se instanceof Error?Se.message:"Delete failed")}},mt=R.isPending||P.isPending,as=$?.kind==="blog"?Pi[$.blogKind]:$?.kind??"item";return n.jsxs("div",{className:"flex h-full w-full",children:[n.jsx(Vx,{active:l,counts:oe,showBlog:H,onSelect:G=>{h(G),d(null),f(null)}}),l!=="seo"&&l!=="site"&&n.jsx(qx,{activeCollection:l,pages:V,sections:J,appCatalog:w,appCatalogLoading:C,blogEntries:X,decofile:o,searchQuery:m,onSearchChange:p,selection:c,onSelect:G=>{d(G),f(null)},previewUrl:i,onCreate:()=>{l==="pages"?O():Di(l)?ke(l):i?A(!0):le.error("Start the preview dev server to add sections.")},onDuplicatePage:ce,onRenamePage:ue,onAddPageVariant:Q,onDeletePage:G=>z({kind:"page",key:G.key,label:G.name}),onEditPageSeo:G=>{d({collection:"pages",key:G.key,path:G.path}),f(G.key)},onViewPageJson:G=>F(G.key),onDuplicateSection:me,onRenameSection:G=>D(G.key),onDeleteSection:G=>z({kind:"section",key:G.key,label:G.name}),onDuplicateBlog:at,onDeleteBlog:G=>z({kind:"blog",blogKind:G.kind,key:G.key,label:G.label})}),n.jsx("div",{className:"flex-1 min-w-0",children:n.jsx(E.Suspense,{fallback:n.jsx("div",{className:"h-full flex items-center justify-center",children:n.jsx(Ce,{size:20,className:"animate-spin text-muted-foreground"})}),children:l==="site"?Y?n.jsx(Nl,{orgSlug:t,virtualMcpId:e,branch:s,blockKey:Y.key,block:o[Y.key],decofile:o,meta:v,title:"Site",excludeFields:["seo"],schemaPending:y(Y.resolveType,["seo"])},`site:${Y.key}`):n.jsx(Si,{title:"Site settings not found",description:"This project doesn't have a site app block (site/apps/site.ts)."}):l==="seo"?n.jsx(zx,{orgSlug:t,virtualMcpId:e,branch:s,decofile:o,meta:v,target:{kind:"site"},previewBaseUrl:i}):c?c.collection==="apps"?n.jsx(Nl,{orgSlug:t,virtualMcpId:e,branch:s,blockKey:c.key,block:o[c.key],decofile:o,meta:v,schemaPending:y(typeof o[c.key]?.__resolveType=="string"?String(o[c.key].__resolveType):void 0)},`app:${c.key}`):c.collection==="posts"?n.jsx(Lx,{orgSlug:t,virtualMcpId:e,branch:s,blockKey:c.key,block:o[c.key],decofile:o,meta:v},`post:${c.key}`):c.collection==="authors"||c.collection==="categories"?n.jsx(Ox,{orgSlug:t,virtualMcpId:e,branch:s,kind:c.collection,blockKey:c.key,block:o[c.key]},`${c.collection}:${c.key}`):n.jsx($x,{orgSlug:t,virtualMcpId:e,branch:s,previewReady:!0,previewUrl:i??void 0,currentPath:c.collection==="pages"?c.path:"/",activePageBlockKey:c.collection==="pages"?c.key:null,activeGlobalBlockKey:c.collection==="sections"?c.key:null,initialEditSeo:c.collection==="pages"&&u===c.key,onExitSeo:()=>f(null)},c.collection==="pages"?`page:${c.key}`:`section:${c.key}`):n.jsx(Si,{title:`Select ${Di(l)?`a ${Pi[l]}`:l==="pages"?"a page":l==="apps"?"an app":"a section"} to edit`,description:l==="apps"?"Browse all apps and select an installed one to edit its settings.":'Pick an item from the list, or click "+" to create one.'})})}),T&&n.jsx(wx,{open:!!T,mode:T.mode,initialName:T.initialName,initialPath:T.initialPath,isPending:j.isPending,error:k,validate:q,onSubmit:fe,onOpenChange:G=>{G||(S(null),I(void 0))}}),M&&n.jsx(Cx,{open:!!M,blockKey:M,initialName:J.find(G=>G.key===M)?.name??M,isPending:j.isPending,onSubmit:ne,onOpenChange:G=>{G||D(null)}}),N&&i&&n.jsx(E.Suspense,{fallback:null,children:n.jsx(Fx,{open:N,onOpenChange:A,meta:v,decofile:o,previewBaseUrl:i,onSelect:te})}),W&&n.jsx(Mx,{open:!!W,onOpenChange:G=>{G||F(null)},pageKey:W,decofile:o}),n.jsx(Rr,{open:!!$,onOpenChange:G=>{!G&&!mt&&z(null)},children:n.jsxs(Pr,{children:[n.jsxs(Dr,{children:[n.jsx(Ar,{children:`Delete ${as}?`}),n.jsx(Ir,{children:$?.kind==="section"?`"${$.label}" will be removed. Pages that still reference it will lose this section.`:$?`"${$.label}" will be removed permanently. This can't be undone.`:null})]}),n.jsxs(Br,{children:[n.jsx(Mr,{disabled:mt,children:"Cancel"}),n.jsx(Lr,{onClick:G=>{G.preventDefault(),Be()},disabled:mt,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:mt?n.jsxs(n.Fragment,{children:[n.jsx(Ce,{size:14,className:"animate-spin"}),"Deleting…"]}):"Delete"})]})]})})]})}function Vx(t){const e=K.c(33),{active:s,counts:i,showBlog:r,onSelect:o}=t;let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=n.jsx("div",{className:"px-3 h-12 flex items-center border-b shrink-0",children:n.jsx("span",{className:"text-sm font-medium",children:"Content"})}),e[0]=a):a=e[0];const l=s==="pages";let h;e[1]!==i.pages||e[2]!==o||e[3]!==l?(h=n.jsx(ls,{id:"pages",icon:Vo,label:"Pages",count:i.pages,active:l,onSelect:o}),e[1]=i.pages,e[2]=o,e[3]=l,e[4]=h):h=e[4];const c=s==="sections";let d;e[5]!==i.sections||e[6]!==o||e[7]!==c?(d=n.jsx(ls,{id:"sections",icon:Gs,label:"Sections",count:i.sections,active:c,onSelect:o}),e[5]=i.sections,e[6]=o,e[7]=c,e[8]=d):d=e[8];const u=s==="apps";let f;e[9]!==i.apps||e[10]!==o||e[11]!==u?(f=n.jsx(ls,{id:"apps",icon:ph,label:"Apps",count:i.apps,active:u,onSelect:o}),e[9]=i.apps,e[10]=o,e[11]=u,e[12]=f):f=e[12];let m;e[13]!==s||e[14]!==i.authors||e[15]!==i.categories||e[16]!==i.posts||e[17]!==o||e[18]!==r?(m=r&&n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"mt-3 flex items-center gap-1.5 px-2.5 pb-1 pt-1 text-xs font-medium text-muted-foreground/70",children:[n.jsx(mh,{size:13,className:"shrink-0"}),"Blog"]}),n.jsx(ls,{id:"posts",icon:qc,label:"Posts",count:i.posts,active:s==="posts",onSelect:o}),n.jsx(ls,{id:"authors",icon:ta,label:"Authors",count:i.authors,active:s==="authors",onSelect:o}),n.jsx(ls,{id:"categories",icon:Gc,label:"Categories",count:i.categories,active:s==="categories",onSelect:o})]}),e[13]=s,e[14]=i.authors,e[15]=i.categories,e[16]=i.posts,e[17]=o,e[18]=r,e[19]=m):m=e[19];const p=s==="site";let _;e[20]!==o||e[21]!==p?(_=n.jsx(ls,{id:"site",icon:Uf,label:"Site",active:p,onSelect:o}),e[20]=o,e[21]=p,e[22]=_):_=e[22];const g=s==="seo";let v;e[23]!==o||e[24]!==g?(v=n.jsx(ls,{id:"seo",icon:Nr,label:"SEO",active:g,onSelect:o}),e[23]=o,e[24]=g,e[25]=v):v=e[25];let b;return e[26]!==_||e[27]!==v||e[28]!==h||e[29]!==d||e[30]!==f||e[31]!==m?(b=n.jsxs("div",{className:"w-[208px] shrink-0 border-r flex flex-col",children:[a,n.jsxs("nav",{className:"flex flex-col p-1.5 gap-0.5",children:[h,d,f,m,_,v]})]}),e[26]=_,e[27]=v,e[28]=h,e[29]=d,e[30]=f,e[31]=m,e[32]=b):b=e[32],b}function ls(t){const e=K.c(18),{id:s,icon:i,label:r,count:o,active:a,onSelect:l}=t;let h;e[0]!==s||e[1]!==l?(h=()=>l(s),e[0]=s,e[1]=l,e[2]=h):h=e[2];const c=a?"bg-accent text-accent-foreground":"text-muted-foreground hover:bg-muted hover:text-foreground";let d;e[3]!==c?(d=he("flex w-full items-center gap-2 rounded-md px-2.5 py-1.5 text-left text-sm transition-colors cursor-pointer",c),e[3]=c,e[4]=d):d=e[4];let u;e[5]!==i?(u=n.jsx(i,{size:16,className:"shrink-0"}),e[5]=i,e[6]=u):u=e[6];let f;e[7]!==r?(f=n.jsx("span",{className:"flex-1 truncate",children:r}),e[7]=r,e[8]=f):f=e[8];let m;e[9]!==a||e[10]!==o?(m=o!==void 0&&n.jsx("span",{className:he("shrink-0 text-xs tabular-nums",a?"text-accent-foreground/70":"text-muted-foreground/70"),children:o}),e[9]=a,e[10]=o,e[11]=m):m=e[11];let p;return e[12]!==h||e[13]!==d||e[14]!==u||e[15]!==f||e[16]!==m?(p=n.jsxs("button",{type:"button",onClick:h,className:d,children:[u,f,m]}),e[12]=h,e[13]=d,e[14]=u,e[15]=f,e[16]=m,e[17]=p):p=e[17],p}function qx(t){const e=K.c(57),{activeCollection:s,pages:i,sections:r,appCatalog:o,appCatalogLoading:a,blogEntries:l,decofile:h,previewUrl:c,searchQuery:d,onSearchChange:u,selection:f,onSelect:m,onCreate:p,onDuplicatePage:_,onRenamePage:g,onAddPageVariant:v,onDeletePage:b,onEditPageSeo:x,onViewPageJson:y,onDuplicateSection:w,onRenameSection:C,onDeleteSection:j,onDuplicateBlog:R,onDeleteBlog:B}=t;let P,T,S,k,I,N;if(e[0]!==s||e[1]!==o||e[2]!==a||e[3]!==l||e[4]!==h||e[5]!==v||e[6]!==p||e[7]!==B||e[8]!==b||e[9]!==j||e[10]!==R||e[11]!==_||e[12]!==w||e[13]!==x||e[14]!==g||e[15]!==C||e[16]!==u||e[17]!==m||e[18]!==y||e[19]!==i||e[20]!==c||e[21]!==d||e[22]!==r||e[23]!==f){const $=d.toLowerCase(),z=i.filter(O=>!$||O.name.toLowerCase().includes($)||O.path.toLowerCase().includes($)),W=r.filter(O=>!$||O.name.toLowerCase().includes($)||O.key.toLowerCase().includes($)||O.resolveType.toLowerCase().includes($)),F=o.filter(O=>!$||O.title.toLowerCase().includes($)||O.app.toLowerCase().includes($)||O.vendor.toLowerCase().includes($)||O.category.toLowerCase().includes($)),V=l.filter(O=>!$||O.label.toLowerCase().includes($)||O.subtitle.toLowerCase().includes($)),J=`Search ${s}…`,Y=Di(s)?`Create new ${Pi[s]}`:s==="pages"?"Create new page":"Create new section",U=s==="sections"&&!c,H=s!=="apps",X=U,oe=U?"Start the preview dev server to add sections":void 0;I="w-[300px] shrink-0 border-r flex flex-col min-h-0";let L;e[30]===Symbol.for("react.memo_cache_sentinel")?(L=n.jsx(fh,{size:14,className:"shrink-0 text-muted-foreground","aria-hidden":!0}),e[30]=L):L=e[30];let se;e[31]!==u?(se=O=>u(O.target.value),e[31]=u,e[32]=se):se=e[32];let ee;e[33]!==J||e[34]!==d||e[35]!==se?(ee=n.jsxs("div",{className:"flex flex-1 items-center gap-2 pl-1",children:[L,n.jsx("input",{type:"text",value:d,onChange:se,placeholder:J,"aria-label":J,className:"w-full bg-transparent text-sm outline-none placeholder:text-muted-foreground"})]}),e[33]=J,e[34]=d,e[35]=se,e[36]=ee):ee=e[36];let Q;e[37]!==X||e[38]!==oe||e[39]!==Y||e[40]!==p||e[41]!==H?(Q=H&&n.jsxs(Re,{children:[n.jsx(Ee,{asChild:!0,children:n.jsx(re,{variant:"ghost",size:"icon",onClick:p,disabled:X,"aria-label":Y,"aria-disabled":X,children:n.jsx(xt,{size:14})})}),n.jsx(Te,{side:"bottom",children:oe??Y})]}),e[37]=X,e[38]=oe,e[39]=Y,e[40]=p,e[41]=H,e[42]=Q):Q=e[42],e[43]!==ee||e[44]!==Q?(N=n.jsxs("div",{className:"px-2 h-12 flex items-center gap-1 border-b shrink-0",children:[ee,Q]}),e[43]=ee,e[44]=Q,e[45]=N):N=e[45],P=rn,k="flex-1 min-h-0 [&_[data-slot=scroll-area-viewport]>div]:!block",T="flex flex-col gap-1 p-1.5",S=s==="pages"?z.length===0?n.jsx(cr,{hasItems:i.length>0,emptyLabel:"No pages yet.",emptyHint:'Click "+" to create your first page.'}):z.map(O=>{const ce=f?.collection==="pages"&&f.key===O.key,ue=vd(h,O.key);return n.jsx(lr,{icon:Vo,title:O.name,subtitle:O.path,active:ce,variantCount:ue,onClick:()=>m({collection:"pages",key:O.key,path:O.path}),menu:n.jsx(Cn,{onDuplicate:()=>_(O),onRename:()=>g(O),onAddVariant:()=>v(O),onEditSeo:()=>x(O),onViewJson:()=>y(O),onDelete:()=>b(O)})},O.key)}):s==="sections"?W.length===0?n.jsx(cr,{hasItems:r.length>0,emptyLabel:"No saved sections yet.",emptyHint:'Click "+" to create one, or save a section from a page.'}):W.map(O=>{const ce=f?.collection==="sections"&&f.key===O.key,ue=O.resolveType.split("/").pop()?.replace(/\.tsx?$/,"");return n.jsx(lr,{icon:Gs,title:O.name,subtitle:ue??O.resolveType,active:ce,onClick:()=>m({collection:"sections",key:O.key}),menu:n.jsx(Cn,{onDuplicate:()=>w(O),onRename:()=>C(O),onDelete:()=>j(O)})},O.key)}):s==="apps"?a?n.jsx("div",{className:"flex items-center justify-center py-8",children:n.jsx(Ce,{size:18,className:"animate-spin text-muted-foreground"})}):F.length===0?n.jsx(cr,{hasItems:o.length>0,emptyLabel:"No apps found.",emptyHint:"Try a different search term."}):F.map(O=>{const ce=f?.collection==="apps"&&O.blockKey!==null&&f.key===O.blockKey;return n.jsx(lr,{icon:ph,logoUrl:O.logo,title:O.title,subtitle:O.category,active:ce,trailing:O.installed?n.jsx("span",{className:"shrink-0 rounded-full bg-emerald-500/15 px-1.5 py-0.5 text-[10px] font-medium text-emerald-700 dark:text-emerald-400",children:"Installed"}):void 0,onClick:()=>{if(!O.installed||!O.blockKey){le.message(`${O.title} is not installed on this site.`);return}m({collection:"apps",key:O.blockKey})}},O.id)}):V.length===0?n.jsx(cr,{hasItems:l.length>0,emptyLabel:`No ${s} yet.`,emptyHint:`Click "+" to create your first ${Di(s)?Pi[s]:"item"}.`}):V.map(O=>{const ce=f?.collection===O.kind&&f.key===O.key;return n.jsx(lr,{icon:O.kind==="posts"?qc:O.kind==="authors"?ta:Gc,title:O.label,subtitle:O.subtitle,active:ce,onClick:()=>m({collection:O.kind,key:O.key}),menu:n.jsx(Cn,{onDuplicate:()=>R(O),onDelete:()=>B(O)})},O.key)}),e[0]=s,e[1]=o,e[2]=a,e[3]=l,e[4]=h,e[5]=v,e[6]=p,e[7]=B,e[8]=b,e[9]=j,e[10]=R,e[11]=_,e[12]=w,e[13]=x,e[14]=g,e[15]=C,e[16]=u,e[17]=m,e[18]=y,e[19]=i,e[20]=c,e[21]=d,e[22]=r,e[23]=f,e[24]=P,e[25]=T,e[26]=S,e[27]=k,e[28]=I,e[29]=N}else P=e[24],T=e[25],S=e[26],k=e[27],I=e[28],N=e[29];let A;e[46]!==T||e[47]!==S?(A=n.jsx("div",{className:T,children:S}),e[46]=T,e[47]=S,e[48]=A):A=e[48];let M;e[49]!==P||e[50]!==k||e[51]!==A?(M=n.jsx(P,{className:k,children:A}),e[49]=P,e[50]=k,e[51]=A,e[52]=M):M=e[52];let D;return e[53]!==I||e[54]!==N||e[55]!==M?(D=n.jsxs("div",{className:I,children:[N,M]}),e[53]=I,e[54]=N,e[55]=M,e[56]=D):D=e[56],D}function lr(t){const e=K.c(29),{icon:s,logoUrl:i,title:r,subtitle:o,active:a,variantCount:l,trailing:h,onClick:c,menu:d}=t;let u;e[0]!==s||e[1]!==a||e[2]!==i||e[3]!==l?(u=l&&l>1?n.jsxs(Re,{children:[n.jsx(Ee,{asChild:!0,children:n.jsx(s,{size:16,className:"shrink-0",style:{color:eo}})}),n.jsxs(Te,{side:"right",children:[l," variants"]})]}):i?n.jsx("img",{src:i,alt:"",className:"size-8 shrink-0 rounded-lg object-cover bg-muted"}):n.jsx(s,{size:16,className:he("shrink-0",a?"text-accent-foreground":"text-muted-foreground")}),e[0]=s,e[1]=a,e[2]=i,e[3]=l,e[4]=u):u=e[4];const f=u,m=a?"bg-accent text-accent-foreground":"hover:bg-muted";let p;e[5]!==m?(p=he("group relative flex min-w-0 items-center rounded-md transition-colors",m),e[5]=m,e[6]=p):p=e[6];let _;e[7]!==r?(_=n.jsx("span",{className:"block truncate text-sm font-medium",children:r}),e[7]=r,e[8]=_):_=e[8];const g=a?"text-accent-foreground/70":"text-muted-foreground";let v;e[9]!==g?(v=he("block truncate text-xs",g),e[9]=g,e[10]=v):v=e[10];let b;e[11]!==o||e[12]!==v?(b=n.jsx("span",{className:v,children:o}),e[11]=o,e[12]=v,e[13]=b):b=e[13];let x;e[14]!==_||e[15]!==b?(x=n.jsxs("span",{className:"min-w-0 flex-1",children:[_,b]}),e[14]=_,e[15]=b,e[16]=x):x=e[16];let y;e[17]!==c||e[18]!==f||e[19]!==x||e[20]!==h?(y=n.jsxs("button",{type:"button",onClick:c,className:"flex min-w-0 flex-1 items-center gap-2.5 rounded-md px-2.5 py-2 text-left cursor-pointer",children:[f,x,h]}),e[17]=c,e[18]=f,e[19]=x,e[20]=h,e[21]=y):y=e[21];let w;e[22]!==a||e[23]!==d?(w=d&&n.jsx("div",{className:he("pr-1 opacity-0 transition-opacity group-hover:opacity-100",a&&"opacity-100"),children:d}),e[22]=a,e[23]=d,e[24]=w):w=e[24];let C;return e[25]!==w||e[26]!==p||e[27]!==y?(C=n.jsxs("div",{className:p,children:[y,w]}),e[25]=w,e[26]=p,e[27]=y,e[28]=C):C=e[28],C}function Cn(t){const e=K.c(21),{onDuplicate:s,onRename:i,onAddVariant:r,onEditSeo:o,onViewJson:a,onDelete:l}=t;let h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h=n.jsx(As,{asChild:!0,children:n.jsx("button",{type:"button","aria-label":"More actions",className:"flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:bg-background hover:text-foreground cursor-pointer",onClick:Gx,children:n.jsx(tn,{size:14})})}),e[0]=h):h=e[0];let c;e[1]!==i?(c=i&&n.jsxs(He,{onClick:i,children:[n.jsx(sa,{size:14}),"Rename"]}),e[1]=i,e[2]=c):c=e[2];let d;e[3]===Symbol.for("react.memo_cache_sentinel")?(d=n.jsx(Qt,{size:14}),e[3]=d):d=e[3];let u;e[4]!==s?(u=n.jsxs(He,{onClick:s,children:[d,"Duplicate"]}),e[4]=s,e[5]=u):u=e[5];let f;e[6]!==r?(f=r&&n.jsxs(n.Fragment,{children:[n.jsx(gr,{}),n.jsxs(He,{onClick:r,className:"cursor-pointer",style:{color:eo},children:[n.jsx(Kf,{size:14,style:{color:eo}}),"Add variant"]})]}),e[6]=r,e[7]=f):f=e[7];let m;e[8]!==o||e[9]!==a?(m=(o||a)&&n.jsxs(n.Fragment,{children:[n.jsx(gr,{}),o&&n.jsxs(He,{onClick:o,children:[n.jsx(Nr,{size:14}),"Edit SEO"]}),a&&n.jsxs(He,{onClick:a,children:[n.jsx(qo,{size:14}),"View JSON"]})]}),e[8]=o,e[9]=a,e[10]=m):m=e[10];let p;e[11]===Symbol.for("react.memo_cache_sentinel")?(p=n.jsx(gr,{}),e[11]=p):p=e[11];let _;e[12]===Symbol.for("react.memo_cache_sentinel")?(_=n.jsx(qs,{size:14}),e[12]=_):_=e[12];let g;e[13]!==l?(g=n.jsxs(He,{onClick:l,className:"text-destructive focus:text-destructive",children:[_,"Delete"]}),e[13]=l,e[14]=g):g=e[14];let v;return e[15]!==c||e[16]!==u||e[17]!==f||e[18]!==m||e[19]!==g?(v=n.jsxs(Ds,{children:[h,n.jsxs(Is,{align:"end",className:"w-44",children:[c,u,f,m,p,g]})]}),e[15]=c,e[16]=u,e[17]=f,e[18]=m,e[19]=g,e[20]=v):v=e[20],v}function Gx(t){return t.stopPropagation()}function cr(t){const e=K.c(6),{hasItems:s,emptyLabel:i,emptyHint:r}=t;let o;e[0]!==r||e[1]!==i||e[2]!==s?(o=s?"No results match your search.":n.jsxs(n.Fragment,{children:[n.jsx("div",{children:i}),n.jsx("div",{className:"mt-1 text-muted-foreground/80",children:r})]}),e[0]=r,e[1]=i,e[2]=s,e[3]=o):o=e[3];let a;return e[4]!==o?(a=n.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:o}),e[4]=o,e[5]=a):a=e[5],a}function Yx(t){const e=K.c(8),{state:s,claimPhase:i,lifecycle:r,onStart:o}=t;switch(s.kind){case"starting":{let a;e[0]!==i||e[1]!==r?(a=ad({claimPhase:i,lifecycle:r}),e[0]=i,e[1]=r,e[2]=a):a=e[2];let l;return e[3]!==i||e[4]!==a?(l=n.jsx(Fr,{kind:"starting",progress:a,claimPhase:i}),e[3]=i,e[4]=a,e[5]=l):l=e[5],l}case"suspended":{let a;return e[6]!==o?(a=n.jsx(Fr,{kind:"suspended",onResume:o}),e[6]=o,e[7]=a):a=e[7],a}}}function Si(t){const e=K.c(10),{icon:s,title:i,description:r}=t;let o;e[0]!==s?(o=s&&n.jsx(s,{size:24,className:"text-muted-foreground/60"}),e[0]=s,e[1]=o):o=e[1];let a;e[2]!==i?(a=n.jsx("div",{children:i}),e[2]=i,e[3]=a):a=e[3];let l;e[4]!==r?(l=r&&n.jsx("div",{className:"text-xs text-muted-foreground/80 max-w-sm",children:r}),e[4]=r,e[5]=l):l=e[5];let h;return e[6]!==o||e[7]!==a||e[8]!==l?(h=n.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-2 p-6 text-center text-sm text-muted-foreground",children:[o,a,l]}),e[6]=o,e[7]=a,e[8]=l,e[9]=h):h=e[9],h}function Xx(t){const e=K.c(2),{virtualMcpId:s}=t,i=Mt(s);if(!ti(i?.metadata)){let a;return e[0]===Symbol.for("react.memo_cache_sentinel")?(a=n.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-2 text-center text-sm text-muted-foreground p-6",children:[n.jsx(Ui,{size:24,className:"text-muted-foreground/60"}),n.jsx("div",{children:"No content to edit."}),n.jsx("div",{className:"text-xs text-muted-foreground/80",children:"Connect a GitHub repository from the Settings tab to enable Content."})]}),e[0]=a):a=e[0],a}let o;return e[1]===Symbol.for("react.memo_cache_sentinel")?(o=n.jsx(Hx,{}),e[1]=o):o=e[1],o}const kn={fast:{label:"Fast",subtitle:"Quick responses for simple tasks",icon:Kc},smart:{label:"Smart",subtitle:"Balanced quality and speed",icon:Ss},thinking:{label:"Thinking",subtitle:"Deeper reasoning for hard tasks",icon:Yf}},Jx=["fast","smart","thinking"];function Zx(t){const e=K.c(15),{tier:s,onSelect:i}=t,[r,o]=E.useState(!1),a=kn[s].icon;let l;e[0]!==a?(l=n.jsx(a,{size:14,className:"text-muted-foreground"}),e[0]=a,e[1]=l):l=e[1];const h=kn[s];let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c=n.jsx(Es,{size:14,className:"text-muted-foreground"}),e[2]=c):c=e[2];let d;e[3]!==l||e[4]!==h.label?(d=n.jsx(Rs,{asChild:!0,children:n.jsxs(re,{variant:"outline",size:"sm",className:"w-fit gap-1.5",children:[l,h.label,c]})}),e[3]=l,e[4]=h.label,e[5]=d):d=e[5];let u;e[6]!==i||e[7]!==s?(u=Jx.map(p=>{const _=kn[p],g=_.icon;return n.jsxs("button",{type:"button",onClick:()=>{i(p),o(!1)},className:he("flex items-start gap-2 px-2 py-1.5 rounded-md text-left hover:bg-muted"),children:[n.jsx(g,{size:16,className:"shrink-0 text-muted-foreground mt-0.5"}),n.jsxs("div",{className:"flex-1",children:[n.jsx("div",{className:"text-sm",children:_.label}),n.jsx("div",{className:"text-xs text-muted-foreground",children:_.subtitle})]}),p===s&&n.jsx(ri,{size:14,className:"text-foreground mt-0.5"})]},p)}),e[6]=i,e[7]=s,e[8]=u):u=e[8];let f;e[9]!==u?(f=n.jsx(Ps,{align:"start",className:"p-1 w-64",children:n.jsx("div",{className:"flex flex-col",children:u})}),e[9]=u,e[10]=f):f=e[10];let m;return e[11]!==r||e[12]!==d||e[13]!==f?(m=n.jsxs(Ts,{open:r,onOpenChange:o,children:[d,f]}),e[11]=r,e[12]=d,e[13]=f,e[14]=m):m=e[14],m}function Qx(t){const e=K.c(15),{tier:s,onTierChange:i,override:r,onOverrideChange:o}=t,[a,l]=E.useState(r!==null);let h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h=n.jsx("span",{className:"text-xs font-semibold text-muted-foreground/60",children:"Model"}),e[0]=h):h=e[0];let c;e[1]!==o||e[2]!==i||e[3]!==r||e[4]!==s||e[5]!==a?(c=a?n.jsx(E.Suspense,{fallback:n.jsx(re,{variant:"outline",size:"sm",disabled:!0,className:"w-fit",children:"Loading models…"}),children:n.jsx(eb,{override:r,onOverrideChange:o})}):n.jsx(Zx,{tier:s,onSelect:i}),e[1]=o,e[2]=i,e[3]=r,e[4]=s,e[5]=a,e[6]=c):c=e[6];let d;e[7]!==o?(d=m=>{l(m),m||o(null)},e[7]=o,e[8]=d):d=e[8];let u;e[9]!==d||e[10]!==a?(u=n.jsxs("label",{className:"flex items-center gap-2 text-xs text-muted-foreground cursor-pointer select-none",children:[n.jsx(Or,{checked:a,onCheckedChange:d,className:"cursor-pointer"}),"Specific model"]}),e[9]=d,e[10]=a,e[11]=u):u=e[11];let f;return e[12]!==c||e[13]!==u?(f=n.jsxs("div",{className:"flex flex-col gap-2",children:[h,n.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[c,u]})]}),e[12]=c,e[13]=u,e[14]=f):f=e[14],f}function eb(t){const e=K.c(10),{override:s,onOverrideChange:i}=t,r=Hc(),o=r[0]?.id??null,[a,l]=E.useState(s?.credentialId??o);let h;e[0]!==s?(h=s?{modelId:s.modelId,title:s.title||s.modelId,keyId:s.credentialId,providerId:"deco",description:null,logo:null,capabilities:[],limits:null,costs:null}:null,e[0]=s,e[1]=h):h=e[1];const c=h;if(r.length===0){let f;return e[2]===Symbol.for("react.memo_cache_sentinel")?(f=n.jsx("span",{className:"text-xs text-muted-foreground italic",children:"Connect an AI provider in settings to pick a specific model."}),e[2]=f):f=e[2],f}let d;e[3]!==a||e[4]!==i?(d=f=>{const m=f.keyId??a??"";l(m),i({modelId:f.modelId,credentialId:m,title:f.title??f.modelId})},e[3]=a,e[4]=i,e[5]=d):d=e[5];let u;return e[6]!==a||e[7]!==c||e[8]!==d?(u=n.jsx("div",{className:"w-fit max-w-full [&_button]:rounded-md",children:n.jsx(ap,{variant:"bordered",placeholder:"Pick a model",model:c,credentialId:a,onCredentialChange:l,onModelChange:d})}),e[6]=a,e[7]=c,e[8]=d,e[9]=u):u=e[9],u}const kd=[{key:"capabilities",heading:"Built-in capabilities",icon:ia,tools:[{name:"web_search",title:"Web search",description:"Look up current information on the web",icon:Ki},{name:"generate_image",title:"Generate image",description:"Create images from a text prompt",icon:Qm},{name:"subtask",title:"Subtask",description:"Spawn a focused sub-agent to handle part of the work",icon:Mi},{name:"user_ask",title:"Ask the user",description:"Pause to ask the user a clarifying question",icon:Vf}]},{key:"files",heading:"Files & code",icon:Wn,tools:[{name:"read",title:"Read File",description:"Read a file from the workspace",icon:nh},{name:"write",title:"Write File",description:"Create or overwrite a file",icon:sa},{name:"edit",title:"Edit File",description:"Make targeted edits to an existing file",icon:qf},{name:"grep",title:"Search Content",description:"Search file contents by pattern",icon:Oi},{name:"glob",title:"Find Files",description:"Find files by name pattern",icon:Wn},{name:"bash",title:"Run Command",description:"Run shell commands in the sandbox",icon:Gf}]},{key:"context",heading:"Context",icon:Ga,tools:[{name:"read_resource",title:"Read Resource",description:"Read an MCP resource by URI",icon:Ga},{name:"read_prompt",title:"Read Prompt",description:"Read an MCP prompt definition",icon:mh}]},{key:"browser",heading:"Browser",icon:Gs,tools:[{name:"take_screenshot",title:"Take Screenshot",description:"Capture a screenshot of a web page",icon:sh},{name:"scrape_url",title:"Scrape URL",description:"Fetch and extract content from a URL",icon:Gs},{name:"inspect_page",title:"Inspect Page",description:"Inspect a web page's structure",icon:qo}]}],tb=kd.flatMap(t=>t.tools.map(e=>e.name));function sb(t){const e=t.replace(/[_-]+/g," ").trim();return e?e.toLowerCase().replace(/\b\w/g,s=>s.toUpperCase()):t}function ib(t){const e=K.c(5),{agentId:s,value:i,onChange:r}=t;let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=n.jsx("span",{className:"text-xs font-semibold text-muted-foreground/60",children:"Tools"}),e[0]=o):o=e[0];let a;return e[1]!==s||e[2]!==r||e[3]!==i?(a=n.jsxs("div",{className:"flex flex-col gap-2",children:[o,s?n.jsx(E.Suspense,{fallback:n.jsxs(re,{variant:"outline",size:"sm",disabled:!0,className:"w-fit",children:[n.jsx(ia,{size:14}),"Loading tools…"]}),children:n.jsx(rb,{agentId:s,value:i,onChange:r})}):n.jsx("span",{className:"text-xs text-muted-foreground italic",children:"Pick an agent first"})]}),e[1]=s,e[2]=r,e[3]=i,e[4]=a):a=e[4],a}function Rl(t){const e=K.c(17),{value:s,checked:i,onToggle:r,title:o,description:a,leading:l}=t;let h;e[0]!==i?(h=n.jsx(nn,{checked:i,className:"pointer-events-none mt-0.5"}),e[0]=i,e[1]=h):h=e[1];let c;e[2]!==l?(c=l&&n.jsx("span",{className:"mt-px shrink-0",children:l}),e[2]=l,e[3]=c):c=e[3];let d;e[4]!==o?(d=n.jsx("span",{className:"truncate text-sm leading-tight",children:o}),e[4]=o,e[5]=d):d=e[5];let u;e[6]!==a?(u=a&&n.jsx("span",{className:"line-clamp-2 text-xs leading-snug text-muted-foreground",children:a}),e[6]=a,e[7]=u):u=e[7];let f;e[8]!==d||e[9]!==u?(f=n.jsxs("div",{className:"flex min-w-0 flex-col gap-0.5",children:[d,u]}),e[8]=d,e[9]=u,e[10]=f):f=e[10];let m;return e[11]!==r||e[12]!==h||e[13]!==c||e[14]!==f||e[15]!==s?(m=n.jsxs(op,{value:s,onSelect:r,className:"items-start gap-2.5 py-2",children:[h,c,f]}),e[11]=r,e[12]=h,e[13]=c,e[14]=f,e[15]=s,e[16]=m):m=e[16],m}function Pl(t){const e=K.c(20),{conn:s,label:i,icon:r,on:o,total:a,onToggle:l}=t,h=o===a;let c;e[0]!==r||e[1]!==s?(c=s?n.jsx(Gt,{icon:s.icon,name:s.title,size:"2xs"}):r?n.jsx(r,{size:14,className:"text-muted-foreground"}):n.jsx(Xf,{size:14,className:"text-muted-foreground"}),e[0]=r,e[1]=s,e[2]=c):c=e[2];const d=s?.title??i??"Other tools";let u;e[3]!==d?(u=n.jsx("span",{className:"truncate",children:d}),e[3]=d,e[4]=u):u=e[4];let f;e[5]!==o||e[6]!==a?(f=n.jsxs("span",{className:"text-[11px] font-normal tabular-nums text-muted-foreground/70",children:[o,"/",a]}),e[5]=o,e[6]=a,e[7]=f):f=e[7];let m;e[8]!==l?(m=b=>{b.stopPropagation(),l()},e[8]=l,e[9]=m):m=e[9];const p=h?"None":"All";let _;e[10]!==m||e[11]!==p?(_=n.jsx("button",{type:"button",onClick:m,className:"text-[11px] font-medium text-primary hover:underline",children:p}),e[10]=m,e[11]=p,e[12]=_):_=e[12];let g;e[13]!==f||e[14]!==_?(g=n.jsxs("span",{className:"ml-auto flex items-center gap-2",children:[f,_]}),e[13]=f,e[14]=_,e[15]=g):g=e[15];let v;return e[16]!==c||e[17]!==u||e[18]!==g?(v=n.jsxs("div",{className:"flex items-center gap-2",children:[c,u,g]}),e[16]=c,e[17]=u,e[18]=g,e[19]=v):v=e[19],v}function rb(t){const e=K.c(70),{agentId:s,value:i,onChange:r}=t,{org:o}=Pe(),[a,l]=E.useState(!1);let h;e[0]!==s||e[1]!==o.id||e[2]!==o.slug?(h={connectionId:s,orgId:o.id,orgSlug:o.slug},e[0]=s,e[1]=o.id,e[2]=o.slug,e[3]=h):h=e[3];const c=ft(h);let d;e[4]!==c?(d={client:c},e[4]=c,e[5]=d):d=e[5];const{data:u,isLoading:f}=um(d),m=Vi();let p,_,g,v,b,x,y,w,C,j,R,B,P;if(e[6]!==m||e[7]!==u?.tools||e[8]!==f||e[9]!==r||e[10]!==a||e[11]!==i){const N=new Map(m.map(cb)),A=new Map;for(const q of u?.tools??[]){const te=uf(q._meta)??"__other__",me=ff(q.name,te==="__other__"?void 0:te),ne=q.title,ke=ne&&ne!==q.name?ne:sb(me);A.has(te)||A.set(te,{clientId:te,conn:N.get(te),tools:[]}),A.get(te).tools.push({name:q.name,display:ke,description:q.description})}const M=[...A.values()].sort(lb),D=(u?.tools??[]).map(ab),$=[...tb,...D],z=i===null?new Set($):new Set(i),W=$.every(q=>z.has(q)),F=q=>r($.every(te=>q.has(te))?null:[...q]),V=q=>{const te=new Set(z);te.has(q)?te.delete(q):te.add(q),F(te)},J=(q,te)=>{const me=new Set(z);for(const ne of q)te?me.add(ne):me.delete(ne);F(me)};v=Ts,P=a,b=l;let Y;e[25]===Symbol.for("react.memo_cache_sentinel")?(Y=n.jsx(ia,{size:14,className:"text-muted-foreground"}),e[25]=Y):Y=e[25];const U=W?"All tools":"Tools",H=!W&&n.jsxs(tp,{variant:"secondary",className:"ml-0.5 h-5 px-1.5 text-[11px] tabular-nums",children:[z.size,"/",$.length]});let X;e[26]===Symbol.for("react.memo_cache_sentinel")?(X=n.jsx(Es,{size:14,className:"text-muted-foreground"}),e[26]=X):X=e[26],e[27]!==U||e[28]!==H?(x=n.jsx(Rs,{asChild:!0,children:n.jsxs(re,{variant:"outline",size:"sm",className:"w-fit gap-1.5",children:[Y,U,H,X]})}),e[27]=U,e[28]=H,e[29]=x):x=e[29],g=Ps,R="p-0 w-80",B="start",_=ip,e[30]===Symbol.for("react.memo_cache_sentinel")?(C=n.jsx(rp,{placeholder:"Search tools..."}),e[30]=C):C=e[30];const oe=W?`All ${$.length} tools enabled`:`${z.size} of ${$.length} enabled`;let L;e[31]!==oe?(L=n.jsx("span",{className:"text-xs text-muted-foreground",children:oe}),e[31]=oe,e[32]=L):L=e[32];let se;e[33]!==r?(se=()=>r(null),e[33]=r,e[34]=se):se=e[34];let ee;e[35]!==W||e[36]!==se?(ee=n.jsx("button",{type:"button",onClick:se,disabled:W,className:"text-xs font-medium text-primary hover:underline disabled:cursor-default disabled:opacity-40 disabled:no-underline",children:"Select all"}),e[35]=W,e[36]=se,e[37]=ee):ee=e[37];let Q;e[38]===Symbol.for("react.memo_cache_sentinel")?(Q=n.jsx("span",{className:"text-muted-foreground/30",children:"·"}),e[38]=Q):Q=e[38];let O;e[39]!==r?(O=()=>r([]),e[39]=r,e[40]=O):O=e[40];const ce=z.size===0;let ue;e[41]!==O||e[42]!==ce?(ue=n.jsx("button",{type:"button",onClick:O,disabled:ce,className:"text-xs font-medium text-muted-foreground hover:underline disabled:cursor-default disabled:opacity-40 disabled:no-underline",children:"Clear"}),e[41]=O,e[42]=ce,e[43]=ue):ue=e[43];let fe;e[44]!==ee||e[45]!==ue?(fe=n.jsxs("div",{className:"flex items-center gap-2",children:[ee,Q,ue]}),e[44]=ee,e[45]=ue,e[46]=fe):fe=e[46],e[47]!==L||e[48]!==fe?(j=n.jsxs("div",{className:"flex items-center justify-between border-b px-3 py-2",children:[L,fe]}),e[47]=L,e[48]=fe,e[49]=j):j=e[49],p=np,y="max-h-80",w=f?n.jsx("div",{className:"px-3 py-6 text-center text-xs text-muted-foreground",children:"Loading tools…"}):n.jsxs(n.Fragment,{children:[n.jsx(sp,{children:"No tools found"}),kd.map(q=>{const te=q.tools.map(ob),me=te.filter(ne=>z.has(ne)).length;return n.jsx(Za,{heading:n.jsx(Pl,{label:q.heading,icon:q.icon,on:me,total:te.length,onToggle:()=>J(te,me!==te.length)}),children:q.tools.map(ne=>n.jsx(Rl,{value:`${ne.title} ${ne.name}`,checked:z.has(ne.name),onToggle:()=>V(ne.name),title:ne.title,description:ne.description,leading:n.jsx(ne.icon,{size:16,className:"text-muted-foreground"})},ne.name))},q.key)}),M.map(q=>{const te=q.tools.map(nb),me=te.filter(ne=>z.has(ne)).length;return n.jsx(Za,{heading:n.jsx(Pl,{conn:q.conn,on:me,total:te.length,onToggle:()=>J(te,me!==te.length)}),children:q.tools.map(ne=>n.jsx(Rl,{value:`${ne.display} ${ne.name} ${q.conn?.title??""}`,checked:z.has(ne.name),onToggle:()=>V(ne.name),title:ne.display,description:ne.description},ne.name))},q.clientId)})]}),e[6]=m,e[7]=u?.tools,e[8]=f,e[9]=r,e[10]=a,e[11]=i,e[12]=p,e[13]=_,e[14]=g,e[15]=v,e[16]=b,e[17]=x,e[18]=y,e[19]=w,e[20]=C,e[21]=j,e[22]=R,e[23]=B,e[24]=P}else p=e[12],_=e[13],g=e[14],v=e[15],b=e[16],x=e[17],y=e[18],w=e[19],C=e[20],j=e[21],R=e[22],B=e[23],P=e[24];let T;e[50]!==p||e[51]!==y||e[52]!==w?(T=n.jsx(p,{className:y,children:w}),e[50]=p,e[51]=y,e[52]=w,e[53]=T):T=e[53];let S;e[54]!==_||e[55]!==T||e[56]!==C||e[57]!==j?(S=n.jsxs(_,{children:[C,j,T]}),e[54]=_,e[55]=T,e[56]=C,e[57]=j,e[58]=S):S=e[58];let k;e[59]!==g||e[60]!==S||e[61]!==R||e[62]!==B?(k=n.jsx(g,{className:R,align:B,children:S}),e[59]=g,e[60]=S,e[61]=R,e[62]=B,e[63]=k):k=e[63];let I;return e[64]!==v||e[65]!==b||e[66]!==x||e[67]!==k||e[68]!==P?(I=n.jsxs(v,{open:P,onOpenChange:b,children:[x,k]}),e[64]=v,e[65]=b,e[66]=x,e[67]=k,e[68]=P,e[69]=I):I=e[69],I}function nb(t){return t.name}function ob(t){return t.name}function ab(t){return t.name}function lb(t,e){return(t.conn?.title??t.clientId).localeCompare(e.conn?.title??e.clientId)}function cb(t){return[t.id,t]}function Ai(t){const e=t.trim().split(/\s+/);return e.length!==5?!1:e.every(s=>/^[\d*/,-]+$/.test(s))}function hb(t){if(!t)return"Unknown schedule";const e=t.trim();if(e==="* * * * *")return"Every minute";if(e==="0 * * * *")return"Every hour";if(e==="0 0 * * *")return"Every day";if(e==="0 0 * * 1")return"Every week";const s=e.match(/^\*\/(\d+)\s+\*\s+\*\s+\*\s+\*$/);if(s)return`Every ${s[1]} minutes`;const i=e.match(/^0\s+\*\/(\d+)\s+\*\s+\*\s+\*$/);if(i)return`Every ${i[1]} hours`;const r=e.match(/^0\s+0\s+\*\/(\d+)\s+\*\s+\*$/);if(r){const l=parseInt(r[1]??"1");return l%7===0?`Every ${l/7} weeks`:`Every ${l} days`}const o=e.match(/^(\d+)\s+(\d+)\s+\*\s+\*\s+\*$/);if(o){const l=(o[2]??"0").padStart(2,"0"),h=(o[1]??"0").padStart(2,"0");return`Every day at ${l}:${h} UTC`}const a=e.match(/^(\d+)\s+(\d+)\s+\*\s+\*\s+(\d)$/);if(a){const h=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][parseInt(a[3]??"0")]??"day",c=(a[2]??"0").padStart(2,"0"),d=(a[1]??"0").padStart(2,"0");return`Every ${h} at ${c}:${d} UTC`}return t}function db(t,e){const s=Math.max(1,t);switch(e){case"minutes":return s===1?"* * * * *":`*/${s} * * * *`;case"hours":return s===1?"0 * * * *":`0 */${s} * * *`;case"days":return s===1?"0 0 * * *":`0 0 */${s} * *`;case"weeks":return s===1?"0 0 * * 1":`0 0 */${s*7} * *`}}function ub(t){const e=t.trim();if(e==="* * * * *")return{count:1,unit:"minutes"};if(e==="0 * * * *")return{count:1,unit:"hours"};if(e==="0 0 * * *")return{count:1,unit:"days"};if(e==="0 0 * * 1")return{count:1,unit:"weeks"};const s=e.match(/^\*\/(\d+)\s+\*\s+\*\s+\*\s+\*$/);if(s)return{count:parseInt(s[1]),unit:"minutes"};const i=e.match(/^0\s+\*\/(\d+)\s+\*\s+\*\s+\*$/);if(i)return{count:parseInt(i[1]),unit:"hours"};const r=e.match(/^0\s+0\s+\*\/(\d+)\s+\*\s+\*$/);if(r){const o=parseInt(r[1]);return o%7===0?{count:o/7,unit:"weeks"}:{count:o,unit:"days"}}return null}function fb(t,e){return e===1?{minutes:"minute",hours:"hour",days:"day",weeks:"week"}[t]??t:t}const mb=[{label:"5 minutes",cron:"*/5 * * * *"},{label:"Hour",cron:"0 * * * *"},{label:"Day",cron:"0 0 * * *"},{label:"Week",cron:"0 0 * * 1"}];function pb({automationId:t,open:e,onOpenChange:s,onCustomSelect:i,onEventSelect:r,onWebhookCreated:o}){const{triggerAdd:a}=Gi(),[l,h]=E.useState(!1),c=e??l,d=m=>{s?s(m):h(m)},u=async m=>{try{await a.mutateAsync({automation_id:t,type:"cron",cron_expression:m}),le.success("Starter added"),d(!1)}catch(p){const _=p instanceof Error?p.message:"Failed to add starter";le.error(_)}},f=async()=>{try{const m=await a.mutateAsync({automation_id:t,type:"webhook"});d(!1),m.webhook?o?.(m.webhook):le.success("Webhook starter added")}catch(m){const p=m instanceof Error?m.message:"Failed to add webhook starter";le.error(p)}};return n.jsxs(Ds,{open:c,onOpenChange:d,children:[n.jsx(As,{asChild:!0,children:n.jsxs(re,{variant:"outline",size:"sm",children:[n.jsx(xt,{size:14}),"Add Starter"]})}),n.jsxs(Is,{align:"end",className:"w-[200px]",children:[n.jsxs(Un,{children:[n.jsxs(Kn,{className:"gap-2.5",children:[n.jsx(Ei,{size:14,className:"text-muted-foreground shrink-0"}),"Every..."]}),n.jsx(Vn,{className:"w-[160px]",children:mb.map(m=>n.jsxs(He,{className:"gap-2.5",onSelect:()=>u(m.cron),disabled:a.isPending,children:[n.jsx(Ei,{size:14,className:"text-muted-foreground shrink-0"}),"Every ",m.label]},m.cron))})]}),n.jsxs(He,{className:"gap-2.5",onSelect:()=>{d(!1),i?.()},children:[n.jsx(Ei,{size:14,className:"text-muted-foreground shrink-0"}),"Custom (cron)"]}),n.jsxs(He,{className:"gap-2.5",onSelect:()=>{d(!1),r?.()},children:[n.jsx($i,{size:14,className:"text-muted-foreground shrink-0"}),"Event"]}),n.jsxs(He,{className:"gap-2.5",onSelect:()=>{f()},disabled:a.isPending,children:[n.jsx(Ki,{size:14,className:"text-muted-foreground shrink-0"}),"Webhook"]})]})]})}function jd(t){const e=K.c(31),{open:s,onOpenChange:i,url:r,token:o,title:a,description:l}=t,h=a===void 0?"Webhook ready":a,c=l===void 0?"Send a POST to this URL with the bearer token to fire the automation. The token is shown once — copy it now.":l,[d,u]=E.useState(null),[f,m]=E.useState("curl"),[p,_]=E.useState("header"),g=E.useId();let v;e[0]===Symbol.for("react.memo_cache_sentinel")?(v=async(N,A)=>{try{await navigator.clipboard.writeText(N),u(A),le.success("Copied"),setTimeout(()=>u(null),1500)}catch{le.error("Failed to copy")}},e[0]=v):v=e[0];const b=v;let x;e[1]!==p||e[2]!==o||e[3]!==r?(x=r&&o&&p==="url"?`${r.replace(/\/$/,"")}/${o}`:r??"",e[1]=p,e[2]=o,e[3]=r,e[4]=x):x=e[4];const y=x,w=r&&o?p==="header"?`curl -X POST "${y}" \\
|
|
276
276
|
-H "Authorization: Bearer ${o}" \\
|
|
277
277
|
-H "Content-Type: application/json" \\
|
|
278
278
|
-d '{"hello":"world"}'`:`curl -X POST "${y}" \\
|
|
@@ -290,8 +290,8 @@ ${se}`:se;c.setValue("metadata.instructions",ee,{shouldDirty:!0})},Y=new Set(d.m
|
|
|
290
290
|
"Content-Type": "application/json",
|
|
291
291
|
},
|
|
292
292
|
body: JSON.stringify({ hello: "world" }),
|
|
293
|
-
});`:"",j=f==="curl"?w:C;let R;e[5]!==h?(R=n.jsx(rs,{children:h}),e[5]=h,e[6]=R):R=e[6];let B;e[7]!==c?(B=n.jsx(Jo,{children:c}),e[7]=c,e[8]=B):B=e[8];let P;e[9]!==R||e[10]!==B?(P=n.jsxs(is,{children:[R,B]}),e[9]=R,e[10]=B,e[11]=P):P=e[11];let T;e[12]!==p||e[13]!==d||e[14]!==y||e[15]!==f||e[16]!==j||e[17]!==o||e[18]!==g||e[19]!==r?(T=r&&o?n.jsxs("div",{className:"flex flex-col gap-3 min-w-0",children:[n.jsxs("div",{className:"flex flex-col gap-1",children:[n.jsx("span",{className:"text-xs font-semibold text-muted-foreground",children:"URL"}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("code",{className:"flex-1 min-w-0 text-xs font-mono bg-muted rounded-md px-2 py-1.5 truncate",children:y}),n.jsxs(re,{size:"sm",variant:"outline",onClick:()=>b(y,"url"),children:[n.jsx(Qt,{size:13}),d==="url"?"Copied":"Copy"]})]})]}),n.jsxs("div",{className:"flex flex-col gap-1",children:[n.jsx("span",{className:"text-xs font-semibold text-muted-foreground",children:"Token (shown once)"}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("code",{className:"flex-1 min-w-0 text-xs font-mono bg-muted rounded-md px-2 py-1.5 truncate",children:o}),n.jsxs(re,{size:"sm",variant:"outline",onClick:()=>b(o,"token"),children:[n.jsx(Qt,{size:13}),d==="token"?"Copied":"Copy"]})]})]}),n.jsxs("div",{className:"flex flex-col gap-2",children:[n.jsx("span",{className:"text-xs font-semibold text-muted-foreground",children:"Snippet"}),n.jsxs("div",{className:"flex items-center justify-between gap-3",children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx(Qo,{value:f,onValueChange:N=>m(N),children:n.jsxs(Zo,{className:"h-8 p-[2px]",children:[n.jsx(ys,{value:"curl",className:"h-7 px-2.5 text-xs",children:"curl"}),n.jsx(ys,{value:"fetch",className:"h-7 px-2.5 text-xs",children:"fetch"})]})}),n.jsxs("label",{htmlFor:g,className:"flex items-center gap-1.5 text-xs text-muted-foreground cursor-pointer select-none",children:[n.jsx(nn,{id:g,checked:p==="url",onCheckedChange:N=>_(N?"url":"header")}),"Token in URL"]})]}),n.jsxs(re,{size:"sm",variant:"outline",onClick:()=>b(j,"example"),children:[n.jsx(Qt,{size:13}),d==="example"?"Copied":"Copy"]})]}),n.jsx("div",{className:"rounded-md border overflow-hidden min-w-0",children:n.jsx(up,{code:j,language:f==="curl"?"shell":"typescript",readOnly:!0,disableDiagnostics:!0,height:180})})]})]}):null,e[12]=p,e[13]=d,e[14]=y,e[15]=f,e[16]=j,e[17]=o,e[18]=g,e[19]=r,e[20]=T):T=e[20];let S;e[21]!==i?(S=n.jsx(ii,{children:n.jsx(re,{onClick:()=>i(!1),children:"Done"})}),e[21]=i,e[22]=S):S=e[22];let k;e[23]!==P||e[24]!==T||e[25]!==S?(k=n.jsxs(Ot,{className:"max-w-lg",children:[P,T,S]}),e[23]=P,e[24]=T,e[25]=S,e[26]=k):k=e[26];let I;return e[27]!==i||e[28]!==s||e[29]!==k?(I=n.jsx(Lt,{open:s,onOpenChange:i,children:k}),e[27]=i,e[28]=s,e[29]=k,e[30]=I):I=e[30],I}function _b(t){const e=K.c(83),{trigger:s,automationId:i,connectionName:r}=t,{triggerAdd:o,triggerRemove:a,triggerRotateToken:l}=Gi(),[h,c]=E.useState(!1),[d,u]=E.useState(!1),[f,m]=E.useState(null);let p;e[0]!==s.cron_expression?(p=s.cron_expression?ub(s.cron_expression):null,e[0]=s.cron_expression,e[1]=p):p=e[1];const _=p,[g,v]=E.useState(_?.count??1),[b,x]=E.useState(!1),[y,w]=E.useState(s.cron_expression??""),C=a.isPending||o.isPending||l.isPending,j=s.type==="cron",R=s.type==="webhook";let B;e[2]!==i||e[3]!==a||e[4]!==s.id?(B=async()=>{try{await a.mutateAsync({trigger_id:s.id,automation_id:i}),le.success("Starter removed")}catch{le.error("Failed to remove starter")}c(!1)},e[2]=i,e[3]=a,e[4]=s.id,e[5]=B):B=e[5];const P=B;let T;e[6]!==o||e[7]!==i||e[8]!==y||e[9]!==a||e[10]!==s.cron_expression||e[11]!==s.id?(T=async()=>{const te=y.trim();if(!te||!Ai(te)||te===s.cron_expression){x(!1),w(s.cron_expression??"");return}try{await o.mutateAsync({automation_id:i,type:"cron",cron_expression:te}),await a.mutateAsync({trigger_id:s.id,automation_id:i}),x(!1)}catch{le.error("Failed to update starter"),w(s.cron_expression??""),x(!1)}},e[6]=o,e[7]=i,e[8]=y,e[9]=a,e[10]=s.cron_expression,e[11]=s.id,e[12]=T):T=e[12];const S=T;let k;e[13]!==i||e[14]!==l||e[15]!==s.id?(k=async()=>{u(!1);try{const te=await l.mutateAsync({trigger_id:s.id,automation_id:i});m({url:te.url,token:te.token})}catch(te){const me=te,ne=me instanceof Error?me.message:"Failed to rotate token";le.error(ne)}},e[13]=i,e[14]=l,e[15]=s.id,e[16]=k):k=e[16];const I=k;let N;e[17]!==o||e[18]!==i||e[19]!==_||e[20]!==a||e[21]!==s.cron_expression||e[22]!==s.id?(N=async te=>{if(!_)return;const me=_.unit==="minutes"?5:1,ne=Math.max(me,te);ne!==te&&v(ne);const ke=db(ne,_.unit);if(ke!==s.cron_expression)try{await o.mutateAsync({automation_id:i,type:"cron",cron_expression:ke}),await a.mutateAsync({trigger_id:s.id,automation_id:i})}catch{le.error("Failed to update starter"),v(_.count)}},e[17]=o,e[18]=i,e[19]=_,e[20]=a,e[21]=s.cron_expression,e[22]=s.id,e[23]=N):N=e[23];const A=N;let M;e[24]!==j||e[25]!==R?(M=j?n.jsx(Ei,{size:14,className:"text-muted-foreground shrink-0"}):R?n.jsx(Ki,{size:14,className:"text-muted-foreground shrink-0"}):n.jsx($i,{size:14,className:"text-muted-foreground shrink-0"}),e[24]=j,e[25]=R,e[26]=M):M=e[26];let D;e[27]!==r||e[28]!==g||e[29]!==y||e[30]!==A||e[31]!==S||e[32]!==_||e[33]!==j||e[34]!==b||e[35]!==C||e[36]!==R||e[37]!==s.cron_expression||e[38]!==s.event_type||e[39]!==s.params?(D=_&&j?n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"text-sm text-muted-foreground",children:"Every"}),n.jsx("input",{type:"number",min:_.unit==="minutes"?5:1,value:g,onChange:te=>v(parseInt(te.target.value)||1),onBlur:()=>A(g),onKeyDown:te=>{te.key==="Enter"&&te.target.blur(),te.key==="Escape"&&v(_.count)},disabled:C,className:"w-12 text-center text-sm h-7 border border-border rounded-md bg-background px-1 focus:outline-none focus:ring-1 focus:ring-ring"}),n.jsx("span",{className:"text-sm",children:fb(_.unit,g)})]}):j&&b?n.jsxs(n.Fragment,{children:[n.jsx("input",{type:"text",value:y,onChange:te=>w(te.target.value),onBlur:S,onKeyDown:te=>{te.key==="Enter"&&te.target.blur(),te.key==="Escape"&&(x(!1),w(s.cron_expression??""))},className:"flex-1 text-sm font-mono bg-transparent outline-none",autoFocus:!0}),y&&!Ai(y)&&n.jsx("span",{className:"text-xs text-muted-foreground/60 shrink-0",children:"invalid"})]}):n.jsxs("div",{className:"flex flex-col gap-0.5 flex-1 min-w-0",children:[n.jsx("span",{className:"text-sm font-mono text-xs text-muted-foreground truncate",children:j?hb(s.cron_expression??""):R?"Webhook · POST to fire":`${s.event_type}${r?` · ${r}`:""}`}),!j&&!R&&s.params&&Object.keys(s.params).length>0&&n.jsx("span",{className:"text-xs text-muted-foreground/60 truncate",children:Object.entries(s.params).map(gb).join(", ")})]}),e[27]=r,e[28]=g,e[29]=y,e[30]=A,e[31]=S,e[32]=_,e[33]=j,e[34]=b,e[35]=C,e[36]=R,e[37]=s.cron_expression,e[38]=s.event_type,e[39]=s.params,e[40]=D):D=e[40];let $;e[41]!==C?($=C&&n.jsx(Ce,{size:13,className:"animate-spin text-muted-foreground"}),e[41]=C,e[42]=$):$=e[42];let z;e[43]!==_||e[44]!==j||e[45]!==b||e[46]!==s.cron_expression?(z=j&&!_&&!b&&n.jsx(re,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 opacity-0 group-hover:opacity-100 transition-opacity",onClick:()=>{w(s.cron_expression??""),x(!0)},children:n.jsx(sa,{size:13,className:"text-muted-foreground"})}),e[43]=_,e[44]=j,e[45]=b,e[46]=s.cron_expression,e[47]=z):z=e[47];let W;e[48]!==R?(W=R&&n.jsx(re,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 opacity-0 group-hover:opacity-100 transition-opacity",title:"Rotate token",onClick:()=>u(!0),children:n.jsx(Bi,{size:13,className:"text-muted-foreground"})}),e[48]=R,e[49]=W):W=e[49];let F;e[50]===Symbol.for("react.memo_cache_sentinel")?(F=n.jsx(re,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 opacity-0 group-hover:opacity-100 transition-opacity",onClick:()=>c(!0),children:n.jsx(ps,{size:13,className:"text-muted-foreground"})}),e[50]=F):F=e[50];let V;e[51]!==W||e[52]!==$||e[53]!==z?(V=n.jsxs("div",{className:"ml-auto flex items-center gap-1",children:[$,z,W,F]}),e[51]=W,e[52]=$,e[53]=z,e[54]=V):V=e[54];let J;e[55]!==V||e[56]!==M||e[57]!==D?(J=n.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-2.5 rounded-lg border border-border bg-background group",children:[M,D,V]}),e[55]=V,e[56]=M,e[57]=D,e[58]=J):J=e[58];let Y;e[59]===Symbol.for("react.memo_cache_sentinel")?(Y=n.jsxs(Dr,{children:[n.jsx(Ar,{children:"Remove Starter"}),n.jsx(Ir,{children:"Are you sure you want to remove this starter?"})]}),e[59]=Y):Y=e[59];let U;e[60]===Symbol.for("react.memo_cache_sentinel")?(U=n.jsx(Mr,{children:"Cancel"}),e[60]=U):U=e[60];let H;e[61]!==P?(H=n.jsxs(Pr,{children:[Y,n.jsxs(Br,{children:[U,n.jsx(Lr,{onClick:P,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Remove"})]})]}),e[61]=P,e[62]=H):H=e[62];let X;e[63]!==h||e[64]!==H?(X=n.jsx(Rr,{open:h,onOpenChange:c,children:H}),e[63]=h,e[64]=H,e[65]=X):X=e[65];let oe;e[66]===Symbol.for("react.memo_cache_sentinel")?(oe=n.jsxs(Dr,{children:[n.jsx(Ar,{children:"Rotate webhook token"}),n.jsx(Ir,{children:"A new token will be generated and the current token will stop working. Any senders using the old token must be updated."})]}),e[66]=oe):oe=e[66];let L;e[67]===Symbol.for("react.memo_cache_sentinel")?(L=n.jsx(Mr,{children:"Cancel"}),e[67]=L):L=e[67];let se;e[68]!==I?(se=n.jsxs(Pr,{children:[oe,n.jsxs(Br,{children:[L,n.jsx(Lr,{onClick:I,children:"Rotate"})]})]}),e[68]=I,e[69]=se):se=e[69];let ee;e[70]!==d||e[71]!==se?(ee=n.jsx(Rr,{open:d,onOpenChange:u,children:se}),e[70]=d,e[71]=se,e[72]=ee):ee=e[72];const Q=f!==null;let O;e[73]===Symbol.for("react.memo_cache_sentinel")?(O=te=>{te||m(null)},e[73]=O):O=e[73];const ce=f?.url??null,ue=f?.token??null;let fe;e[74]!==Q||e[75]!==ce||e[76]!==ue?(fe=n.jsx(jd,{open:Q,onOpenChange:O,url:ce,token:ue,title:"New webhook token",description:"The previous token has been revoked. Copy the new token now — it will not be shown again."}),e[74]=Q,e[75]=ce,e[76]=ue,e[77]=fe):fe=e[77];let q;return e[78]!==J||e[79]!==X||e[80]!==ee||e[81]!==fe?(q=n.jsxs(n.Fragment,{children:[J,X,ee,fe]}),e[78]=J,e[79]=X,e[80]=ee,e[81]=fe,e[82]=q):q=e[82],q}function gb(t){const[e,s]=t;return`${e}: ${s}`}const vb=30;function xb(t,e){switch(e.type){case"accumulate":{const s=t??{start:e.now,fields:new Set,saveCount:0},i=new Set(s.fields);for(const r of e.fields)i.add(r);return{...s,fields:i,saveCount:s.saveCount+1}}case"reset":return null}}function bb(t){const e=K.c(55),{automationId:s,onDone:i}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={binding:"TRIGGER"},e[0]=r):r=e[0];const o=Vi(r),[a,l]=E.useState(),[h,c]=E.useState();let d;e[1]===Symbol.for("react.memo_cache_sentinel")?(d={},e[1]=d):d=e[1];const[u,f]=E.useState(d),{triggerAdd:m}=Gi(),{data:p,isLoading:_}=lp(a);let g,v,b,x,y,w;if(e[2]!==m||e[3]!==s||e[4]!==a||e[5]!==h||e[6]!==_||e[7]!==i||e[8]!==u||e[9]!==o||e[10]!==p){const R=p?.find(D=>D.type===h);let B;e[17]!==m||e[18]!==s||e[19]!==a||e[20]!==h||e[21]!==i||e[22]!==u?(B=async()=>{if(!(!a||!h))try{await m.mutateAsync({automation_id:s,type:"event",event_type:h,connection_id:a,params:u}),De("automation_trigger_added",{automation_id:s,trigger_type:"event",connection_id:a,event_type:h}),le.success("Event trigger added"),i()}catch{le.error("Failed to add event trigger")}},e[17]=m,e[18]=s,e[19]=a,e[20]=h,e[21]=i,e[22]=u,e[23]=B):B=e[23],g=B,v="flex flex-col gap-3 px-3 py-3 rounded-lg border border-border bg-background";let P,T;e[24]===Symbol.for("react.memo_cache_sentinel")?(T=n.jsx($i,{size:14,className:"text-muted-foreground shrink-0"}),P=n.jsx("span",{className:"text-sm font-medium",children:"Event trigger"}),e[24]=P,e[25]=T):(P=e[24],T=e[25]);let S;e[26]===Symbol.for("react.memo_cache_sentinel")?(S=n.jsx(ps,{size:13}),e[26]=S):S=e[26],e[27]!==i?(b=n.jsxs("div",{className:"flex items-center gap-2",children:[T,P,n.jsx("button",{type:"button",className:"ml-auto shrink-0 p-0.5 rounded text-muted-foreground hover:text-foreground",onClick:i,children:S})]}),e[27]=i,e[28]=b):b=e[28];const k=a??"";let I;e[29]===Symbol.for("react.memo_cache_sentinel")?(I=D=>{l(D),c(void 0),f({})},e[29]=I):I=e[29];let N;e[30]===Symbol.for("react.memo_cache_sentinel")?(N=n.jsx(Pt,{className:"w-full",children:n.jsx(Dt,{placeholder:"Select connection..."})}),e[30]=N):N=e[30];let A;e[31]!==o?(A=o.length===0?n.jsx("div",{className:"px-2 py-3 text-center text-xs text-muted-foreground",children:"No connections with trigger support"}):o.map(wb),e[31]=o,e[32]=A):A=e[32];let M;e[33]!==A?(M=n.jsx(At,{children:A}),e[33]=A,e[34]=M):M=e[34],e[35]!==k||e[36]!==M?(x=n.jsxs(It,{value:k,onValueChange:I,children:[N,M]}),e[35]=k,e[36]=M,e[37]=x):x=e[37],e[38]!==a||e[39]!==h||e[40]!==_||e[41]!==p?(y=a&&n.jsxs(It,{value:h??"",onValueChange:D=>{c(D),f({})},children:[n.jsx(Pt,{className:"w-full",children:_?n.jsxs("span",{className:"flex items-center gap-2 text-muted-foreground",children:[n.jsx(Ce,{size:13,className:"animate-spin"}),"Loading events..."]}):n.jsx(Dt,{placeholder:"Select event type...",children:h??"Select event type..."})}),n.jsx(At,{children:p?.map(Sb)})]}),e[38]=a,e[39]=h,e[40]=_,e[41]=p,e[42]=y):y=e[42],w=R?.paramsSchema&&Object.keys(R.paramsSchema).length>0&&n.jsx("div",{className:"flex flex-col gap-2",children:Object.entries(R.paramsSchema).map(D=>{const[$,z]=D;return n.jsxs("div",{className:"flex flex-col gap-1",children:[n.jsxs("label",{className:"text-xs text-muted-foreground",children:[$,z.description&&n.jsxs("span",{className:"text-muted-foreground/60",children:[" ","— ",z.description]})]}),z.enum?n.jsxs(It,{value:u[$]??"",onValueChange:W=>f(F=>({...F,[$]:W})),children:[n.jsx(Pt,{className:"w-full",children:n.jsx(Dt,{placeholder:`Select ${$}...`})}),n.jsx(At,{children:z.enum.map(yb)})]}):n.jsx("input",{type:"text",value:u[$]??"",onChange:W=>f(F=>({...F,[$]:W.target.value})),placeholder:z.description??$,className:"text-sm border border-border rounded-md bg-background px-2 py-1.5 focus:outline-none focus:ring-1 focus:ring-ring"})]},$)})}),e[2]=m,e[3]=s,e[4]=a,e[5]=h,e[6]=_,e[7]=i,e[8]=u,e[9]=o,e[10]=p,e[11]=g,e[12]=v,e[13]=b,e[14]=x,e[15]=y,e[16]=w}else g=e[11],v=e[12],b=e[13],x=e[14],y=e[15],w=e[16];let C;e[43]!==m||e[44]!==a||e[45]!==h||e[46]!==g?(C=a&&h&&n.jsx(re,{size:"sm",onClick:g,disabled:m.isPending,children:m.isPending?n.jsx(Ce,{size:13,className:"animate-spin"}):"Add trigger"}),e[43]=m,e[44]=a,e[45]=h,e[46]=g,e[47]=C):C=e[47];let j;return e[48]!==v||e[49]!==b||e[50]!==x||e[51]!==y||e[52]!==w||e[53]!==C?(j=n.jsxs("div",{className:v,children:[b,x,y,w,C]}),e[48]=v,e[49]=b,e[50]=x,e[51]=y,e[52]=w,e[53]=C,e[54]=j):j=e[54],j}function yb(t){return n.jsx(ot,{value:t,children:t},t)}function Sb(t){return n.jsx(ot,{value:t.type,children:n.jsxs("div",{className:"flex flex-col",children:[n.jsx("span",{children:t.type}),n.jsx("span",{className:"text-xs text-muted-foreground",children:t.description})]})},t.type)}function wb(t){return n.jsx(ot,{value:t.id,children:t.title},t.id)}function Cb({automationId:t,automation:e,onBack:s,onDelete:i}){const r=e.virtual_mcp_id,{org:o}=Pe(),{update:a,triggerAdd:l,run:h}=Gi(),c=Vi(),d=new Map(c.map(O=>[O.id,O.title])),{openTask:u}=ss(),{setChatOpen:f}=Uo(),{sendMessage:m}=Ns(),p=e.messages?.[0]?.metadata?.tiptapDoc??void 0,[_,g]=E.useState(p),[v,b]=E.useState(!1),[x,y]=E.useState(!1),[w,C]=E.useState(!1),[j,R]=E.useState(""),[B,P]=E.useState(!1),[T,S]=E.useState(null),[k,I]=E.useState(!1),[N,A]=E.useState(!1),[M,D]=E.useState(!1),$=async()=>{if(k)return;const ce=of(_).filter(ue=>ue.type==="text").map(ue=>ue.text).join(`
|
|
294
|
-
`);if(ce.trim()){I(!0);try{se(),De("automation_improve_clicked",{automation_id:t,agent_id:r,instructions_length:ce.length}),f(!0),await m({tiptapDoc:Uh({managerAgentId:Oc.AUTOMATION_MANAGER(o.id),managerName:"Automation Manager",kind:"automation",id:t,instructions:ce})})}finally{I(!1)}}},z=e.models?.tier??"smart",W=e.models?.modelId&&e.models?.credentialId?{modelId:e.models.modelId,credentialId:e.models.credentialId,title:e.models.modelTitle??e.models.modelId}:null,F=Mc({defaultValues:{name:e.name,active:e.active,tier:z,modelOverride:W,tools:e.tools??null,maxAgentSteps:e.maxAgentSteps??null}}),V=F.watch("active"),[J,Y]=E.useReducer(xb,null),U=()=>{J!==null&&(De("automation_updated",{automation_id:t,agent_id:r,fields:Array.from(J.fields),save_count:J.saveCount,edit_duration_ms:Date.now()-J.start}),Y({type:"reset"}))},H=async()=>{const O=F.control._formState.dirtyFields,ce=Object.keys(O);if(ce.length===0&&!M)return!0;const ue=F.getValues(),fe=F.control._defaultValues;F.reset(ue,{keepValues:!0});const q=M;D(!1);const te={tier:ue.tier,...ue.modelOverride?{modelId:ue.modelOverride.modelId,credentialId:ue.modelOverride.credentialId,modelTitle:ue.modelOverride.title}:{}},me={id:t,name:ue.name,active:ue.active,models:te,tools:ue.tools,maxAgentSteps:ue.maxAgentSteps,messages:nf(_),temperature:0};try{await a.mutateAsync(me)}catch{return F.reset(fe,{keepValues:!0}),q&&D(!0),!1}const ne=[...ce];return q&&ne.push("messages"),Y({type:"accumulate",now:Date.now(),fields:ne}),L(),!0},{schedule:X,flush:oe}=$r({save:H}),{schedule:L,flush:se}=$r({delayMs:3e4,save:async()=>U()});E.useEffect(()=>{const O=F.watch(()=>X());return()=>O.unsubscribe()},[]);const ee=O=>{if(g(O),!N){A(!0);return}D(!0),X()},Q=async()=>{De("automation_test_clicked",{automation_id:t,agent_id:r});const O=await oe();if(se(),!!O){if(!_){le.error("No instructions configured for this automation");return}try{const ce=await h.mutateAsync(t);ce.threadId&&(f(!0),u(ce.threadId))}catch{}}};return n.jsxs(n.Fragment,{children:[s&&n.jsx("div",{className:"flex items-center pb-4 shrink-0",children:n.jsxs(re,{variant:"ghost",size:"sm",onClick:s,children:[n.jsx(_h,{size:14}),"Back to list"]})}),n.jsxs("div",{className:"flex flex-col gap-8",children:[n.jsxs("div",{className:"flex flex-col gap-1.5",children:[n.jsxs("div",{className:"flex items-center justify-between gap-4",children:[n.jsx(vt,{control:F.control,name:"name",render:({field:O})=>n.jsx(qe,{...O,placeholder:"Automation name",className:"border border-transparent shadow-none px-0 text-lg font-medium h-auto focus-visible:ring-0 focus-visible:border-border bg-transparent flex-1",style:{boxShadow:"none"}})}),i&&n.jsx(re,{variant:"ghost",size:"icon",className:"text-muted-foreground hover:text-destructive shrink-0",onClick:i,children:n.jsx(qs,{size:14})})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(vt,{control:F.control,name:"active",render:({field:O})=>n.jsx(Or,{checked:O.value,onCheckedChange:ce=>{O.onChange(ce),oe()},className:"cursor-pointer"})}),n.jsx("span",{className:"text-sm text-muted-foreground",children:V?"Active":"Inactive"}),n.jsx("span",{className:"text-muted-foreground/50 text-sm",children:"·"}),n.jsx(oh,{id:e.created_by,size:"2xs",className:"text-sm text-muted-foreground"})]})]}),n.jsxs("div",{className:"flex flex-col gap-2.5",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("span",{className:"text-xs font-semibold text-muted-foreground/60",children:"Starter"}),n.jsx(pb,{automationId:t,open:v,onOpenChange:b,onCustomSelect:()=>{C(!0),P(!1),R("")},onEventSelect:()=>{P(!0),C(!1)},onWebhookCreated:O=>{De("automation_trigger_added",{automation_id:t,trigger_type:"webhook"}),S(O)}})]}),e.triggers.length===0&&!w?n.jsx("div",{className:"rounded-lg border border-dashed border-border px-4 py-6 text-center",children:n.jsxs("p",{className:"text-sm text-muted-foreground",children:["When should this automation run?"," ",n.jsx("button",{type:"button",className:"text-foreground underline underline-offset-2 cursor-pointer hover:text-foreground/80 transition-colors",onClick:()=>b(!0),children:"Add a starter"})," ","to get going."]})}):n.jsx("div",{className:"flex flex-col gap-2",children:e.triggers.map(O=>n.jsx(_b,{trigger:O,automationId:t,connectionName:O.connection_id?d.get(O.connection_id):void 0},O.id))}),w&&n.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-2.5 rounded-lg border border-border bg-background group",children:[n.jsx(Ei,{size:14,className:"text-muted-foreground shrink-0"}),n.jsx("input",{type:"text",value:j,onChange:O=>R(O.target.value),onBlur:async()=>{const O=j.trim();if(!(!O||!Ai(O)))try{await l.mutateAsync({automation_id:t,type:"cron",cron_expression:O}),De("automation_trigger_added",{automation_id:t,trigger_type:"cron"}),le.success("Starter added"),C(!1),R("")}catch{le.error("Failed to add starter")}},onKeyDown:async O=>{const ce=j.trim();O.key==="Enter"&&ce&&Ai(ce)&&O.target.blur(),O.key==="Escape"&&(C(!1),R(""))},placeholder:"0 9 * * 1-5",className:"flex-1 text-sm font-mono bg-transparent outline-none placeholder:text-muted-foreground/40",autoFocus:!0}),j&&!Ai(j)&&n.jsx("span",{className:"text-xs text-muted-foreground/60 shrink-0",children:"invalid"}),l.isPending&&n.jsx(Ce,{size:13,className:"animate-spin text-muted-foreground shrink-0"}),n.jsx("button",{type:"button",className:"shrink-0 p-0.5 rounded text-muted-foreground opacity-0 group-hover:opacity-100 hover:text-foreground transition-opacity",onClick:()=>{C(!1),R("")},children:n.jsx(ps,{size:13})})]}),B&&n.jsx(E.Suspense,{fallback:n.jsxs("div",{className:"flex items-center gap-2 px-3 py-3 rounded-lg border border-border bg-background",children:[n.jsx(Ce,{size:13,className:"animate-spin text-muted-foreground"}),n.jsx("span",{className:"text-sm text-muted-foreground",children:"Loading connections..."})]}),children:n.jsx(bb,{automationId:t,onDone:()=>P(!1)})}),n.jsx(jd,{open:T!==null,onOpenChange:O=>{O||S(null)},url:T?.url??null,token:T?.token??null})]}),n.jsxs("div",{className:"flex flex-col gap-2.5",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("span",{className:"text-xs font-semibold text-muted-foreground/60",children:"Instructions"}),n.jsxs(re,{variant:"outline",size:"sm",className:"h-7 gap-1.5 px-2 text-xs",disabled:k||!_,onClick:$,children:[n.jsx(Ss,{size:13}),"Improve"]})]}),n.jsx(Xu,{tiptapDoc:_,setTiptapDoc:ee,placeholder:"What should this automation do?",children:n.jsxs("div",{className:"rounded-xl border border-border min-h-[120px] flex flex-col",children:[n.jsx(Ju,{virtualMcpId:r||null,className:"max-h-[45vh]"}),n.jsx("div",{className:"@container/chat-bottom flex items-center justify-end gap-1.5 p-2.5",children:n.jsxs(Re,{children:[n.jsx(Ee,{asChild:!0,children:n.jsxs(re,{type:"button",variant:"default",className:"h-8 gap-1.5 rounded-md px-3 text-sm font-medium",onClick:Q,disabled:!r,children:[n.jsx(ep,{size:16}),"Test"]})}),n.jsx(Te,{children:"Test Automation"})]})})]})})]}),n.jsxs(pf,{open:x,onOpenChange:y,className:"flex flex-col gap-2.5",children:[n.jsxs(_f,{className:"group flex w-fit cursor-pointer items-center gap-1.5",children:[n.jsx("span",{className:"text-xs font-semibold text-muted-foreground/60",children:"Advanced"}),n.jsx(Es,{size:14,className:"text-muted-foreground/60 transition-transform group-data-[state=open]:rotate-180"})]}),n.jsxs(gf,{className:"flex flex-col gap-5 pt-0.5",children:[n.jsx(Qx,{tier:F.watch("tier"),onTierChange:O=>F.setValue("tier",O,{shouldDirty:!0}),override:F.watch("modelOverride"),onOverrideChange:O=>F.setValue("modelOverride",O,{shouldDirty:!0})}),n.jsx(ib,{agentId:r||null,value:F.watch("tools"),onChange:O=>F.setValue("tools",O,{shouldDirty:!0})}),n.jsxs("div",{className:"flex flex-col gap-2",children:[n.jsx("span",{className:"text-xs font-semibold text-muted-foreground/60",children:"Max steps"}),n.jsx(qe,{type:"number",min:1,max:100,className:"w-40",placeholder:`${vb} (default)`,value:F.watch("maxAgentSteps")??"",onChange:O=>{const ce=O.target.value.trim(),ue=ce===""?null:Number(ce);F.setValue("maxAgentSteps",ue===null||Number.isNaN(ue)?null:ue,{shouldDirty:!0})}})]})]})]})]})]})}function Ys(){const t=K.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=n.jsx("div",{"data-testid":"main-panel-loading",className:"flex h-full w-full items-center justify-center",children:n.jsx(Ce,{size:20,className:"animate-spin text-muted-foreground"})}),t[0]=e):e=t[0],e}const Nd=[{key:"24h",label:"Last 24 hours",ms:1440*60*1e3},{key:"7d",label:"Last 7 days",ms:10080*60*1e3},{key:"30d",label:"Last 30 days",ms:720*60*60*1e3}];function Ed(t){const e=Nd.find(i=>i.key===t).ms,s=Date.now();return{startDate:new Date(s-e).toISOString(),endDate:new Date(s).toISOString()}}function kb(t){const e=K.c(12),{automationId:s,triggerIds:i}=t,[r,o]=E.useState("30d"),[a,l]=E.useState(Nb);let h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h=p=>{const _=p;o(_),l(Ed(_))},e[0]=h):h=e[0];let c;e[1]===Symbol.for("react.memo_cache_sentinel")?(c=n.jsx(Pt,{className:"w-44",children:n.jsx(Dt,{})}),e[1]=c):c=e[1];let d;e[2]===Symbol.for("react.memo_cache_sentinel")?(d=n.jsx(At,{children:Nd.map(jb)}),e[2]=d):d=e[2];let u;e[3]!==r?(u=n.jsx("div",{className:"flex items-center justify-end",children:n.jsxs(It,{value:r,onValueChange:h,children:[c,d]})}),e[3]=r,e[4]=u):u=e[4];let f;e[5]!==s||e[6]!==a||e[7]!==i?(f=n.jsx(fp,{automationId:s,triggerIds:i,range:a}),e[5]=s,e[6]=a,e[7]=i,e[8]=f):f=e[8];let m;return e[9]!==u||e[10]!==f?(m=n.jsxs("div",{className:"flex flex-col gap-5",children:[u,f]}),e[9]=u,e[10]=f,e[11]=m):m=e[11],m}function jb(t){return n.jsx(ot,{value:t.key,children:t.label},t.key)}function Nb(){return Ed("30d")}function Eb(t){const e=K.c(5),{tabId:s}=t;let i;e[0]!==s?(i=Jc(s),e[0]=s,e[1]=i):i=e[1];const r=i;if(!r)return null;let o;e[2]===Symbol.for("react.memo_cache_sentinel")?(o=n.jsx(Ys,{}),e[2]=o):o=e[2];let a;return e[3]!==r.id?(a=n.jsx(E.Suspense,{fallback:o,children:n.jsx(Tb,{id:r.id})}),e[3]=r.id,e[4]=a):a=e[4],a}function Tb(t){const e=K.c(24),{id:s}=t,i=ts(),{data:r,isLoading:o}=cp(s),[a,l]=E.useState("settings");let h;e[0]!==i?(h=()=>{i({to:".",search:Pb,replace:!0})},e[0]=i,e[1]=h):h=e[1];const c=h;if(o){let y;return e[2]===Symbol.for("react.memo_cache_sentinel")?(y=n.jsx(Ys,{}),e[2]=y):y=e[2],y}if(!r){let y;return e[3]===Symbol.for("react.memo_cache_sentinel")?(y=n.jsx("div",{className:"flex h-full w-full items-center justify-center text-sm text-muted-foreground",children:"Automation not found"}),e[3]=y):y=e[3],y}let d;e[4]!==r.triggers?(d=r.triggers.map(Rb),e[4]=r.triggers,e[5]=d):d=e[5];const u=d;let f;e[6]===Symbol.for("react.memo_cache_sentinel")?(f=n.jsx(_h,{size:14}),e[6]=f):f=e[6];let m;e[7]!==c?(m=n.jsxs(re,{variant:"ghost",size:"sm",onClick:c,children:[f,"Back to list"]}),e[7]=c,e[8]=m):m=e[8];let p;e[9]===Symbol.for("react.memo_cache_sentinel")?(p=[{id:"settings",label:"Settings"},{id:"runs",label:"Runs"}],e[9]=p):p=e[9];let _;e[10]===Symbol.for("react.memo_cache_sentinel")?(_=y=>l(y),e[10]=_):_=e[10];let g;e[11]!==a?(g=n.jsx(dh,{tabs:p,activeTab:a,onTabChange:_}),e[11]=a,e[12]=g):g=e[12];let v;e[13]!==m||e[14]!==g?(v=n.jsxs("div",{className:"flex items-center justify-between pb-4 shrink-0",children:[m,g]}),e[13]=m,e[14]=g,e[15]=v):v=e[15];let b;e[16]!==r||e[17]!==s||e[18]!==a||e[19]!==u?(b=a==="settings"?n.jsx(Cb,{automationId:s,automation:r}):n.jsx(kb,{automationId:s,triggerIds:u}),e[16]=r,e[17]=s,e[18]=a,e[19]=u,e[20]=b):b=e[20];let x;return e[21]!==v||e[22]!==b?(x=n.jsx(Rt,{children:n.jsx(Rt.Content,{children:n.jsxs(Rt.Body,{children:[v,b]})})}),e[21]=v,e[22]=b,e[23]=x):x=e[23],x}function Rb(t){return t.id}function Pb(t){return{...t,main:"automations"}}function Db(t){const e=K.c(20),{virtualMcpId:s}=t,i=ts(),{data:r}=hp(s),o=r===void 0?[]:r,{create:a}=Gi(),[l,h]=E.useState(""),c=l.toLowerCase(),d=o.filter(T=>T.name.toLowerCase().includes(c));let u;e[0]!==i?(u=T=>i({to:".",search:S=>({...S,main:"automation:"+T}),replace:!0}),e[0]=i,e[1]=u):u=e[1];const f=u,m=async()=>{if(a.isPending)return;De("automation_new_clicked",{virtual_mcp_id:s,existing_count:o.length});const T=await a.mutateAsync(dp(s));f(T.id)};let p;e[2]===Symbol.for("react.memo_cache_sentinel")?(p=n.jsx(xt,{size:14}),e[2]=p):p=e[2];let _;e[3]!==a.isPending||e[4]!==m?(_=n.jsxs(re,{size:"sm",onClick:m,disabled:a.isPending,children:[p,"New automation"]}),e[3]=a.isPending,e[4]=m,e[5]=_):_=e[5];const g=_,v=Rt,b=Rt,x=Rt;let y;e[6]===Symbol.for("react.memo_cache_sentinel")?(y=n.jsx(Rt.Title,{children:"Automations"}),e[6]=y):y=e[6];const w=o.length>0&&n.jsx(hh,{value:l,onChange:h,placeholder:"Search automations...",className:"w-full md:w-[375px]"});let C;e[7]!==g||e[8]!==w?(C=n.jsxs("div",{className:"flex flex-col gap-6",children:[y,n.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[w,g]})]}),e[7]=g,e[8]=w,e[9]=C):C=e[9];const j=o.length===0?n.jsx("div",{className:"flex items-center justify-center py-20",children:n.jsx(Er,{image:n.jsx($i,{size:48,className:"text-muted-foreground"}),title:"No automations yet",description:"Create your first automation to run this agent on a schedule or in response to events.",actions:g})}):d.length===0?n.jsx("div",{className:"flex items-center justify-center py-20",children:n.jsx(Er,{image:n.jsx($i,{size:48,className:"text-muted-foreground"}),title:"No automations found",description:`No automations match "${l}"`})}):n.jsx("div",{className:"mt-6 rounded-xl border border-border overflow-hidden",children:d.map(T=>n.jsx(mp,{automation:T,onClick:()=>f(T.id)},T.id))});let R;e[10]!==j||e[11]!==x.Body||e[12]!==C?(R=n.jsxs(x.Body,{children:[C,j]}),e[10]=j,e[11]=x.Body,e[12]=C,e[13]=R):R=e[13];let B;e[14]!==R||e[15]!==b.Content?(B=n.jsx(b.Content,{children:R}),e[14]=R,e[15]=b.Content,e[16]=B):B=e[16];let P;return e[17]!==v||e[18]!==B?(P=n.jsx(v,{children:B}),e[17]=v,e[18]=B,e[19]=P):P=e[19],P}function Ab(t){const e=K.c(3),{virtualMcpId:s}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=n.jsx(Ys,{}),e[0]=i):i=e[0];let r;return e[1]!==s?(r=n.jsx(E.Suspense,{fallback:i,children:n.jsx(Db,{virtualMcpId:s})}),e[1]=s,e[2]=r):r=e[2],r}function Ib(t){const e=K.c(37),{file:s,onClose:i}=t;let r,o;e[0]!==s.filename?(r=n.jsx(Li,{filename:s.filename,className:"h-4.5 w-3.5 shrink-0"}),o=n.jsx("span",{className:"truncate text-xs font-medium text-foreground",children:s.filename}),e[0]=s.filename,e[1]=r,e[2]=o):(r=e[1],o=e[2]);let a;e[3]!==s.size?(a=ym(s.size),e[3]=s.size,e[4]=a):a=e[4];let l;e[5]!==a?(l=n.jsx("span",{className:"shrink-0 text-xs text-muted-foreground",children:a}),e[5]=a,e[6]=l):l=e[6];let h;e[7]!==r||e[8]!==o||e[9]!==l?(h=n.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 px-2",children:[r,o,l]}),e[7]=r,e[8]=o,e[9]=l,e[10]=h):h=e[10];let c;e[11]===Symbol.for("react.memo_cache_sentinel")?(c=n.jsx(hm,{size:14}),e[11]=c):c=e[11];let d;e[12]!==s.downloadUrl||e[13]!==s.filename?(d=n.jsx(Ee,{asChild:!0,children:n.jsx(re,{variant:"ghost",size:"icon",asChild:!0,children:n.jsx("a",{href:s.downloadUrl,download:s.filename,children:c})})}),e[12]=s.downloadUrl,e[13]=s.filename,e[14]=d):d=e[14];let u;e[15]===Symbol.for("react.memo_cache_sentinel")?(u=n.jsx(Te,{side:"bottom",children:"Download"}),e[15]=u):u=e[15];let f;e[16]!==d?(f=n.jsxs(Re,{children:[d,u]}),e[16]=d,e[17]=f):f=e[17];let m;e[18]!==s.downloadUrl?(m=()=>window.open(s.downloadUrl,"_blank","noopener"),e[18]=s.downloadUrl,e[19]=m):m=e[19];let p;e[20]===Symbol.for("react.memo_cache_sentinel")?(p=n.jsx(ni,{size:14}),e[20]=p):p=e[20];let _;e[21]!==m?(_=n.jsx(Ee,{asChild:!0,children:n.jsx(re,{variant:"ghost",size:"icon",onClick:m,children:p})}),e[21]=m,e[22]=_):_=e[22];let g;e[23]===Symbol.for("react.memo_cache_sentinel")?(g=n.jsx(Te,{side:"bottom",children:"Open in new tab"}),e[23]=g):g=e[23];let v;e[24]!==_?(v=n.jsxs(Re,{children:[_,g]}),e[24]=_,e[25]=v):v=e[25];let b;e[26]===Symbol.for("react.memo_cache_sentinel")?(b=n.jsx(ps,{size:14}),e[26]=b):b=e[26];let x;e[27]!==i?(x=n.jsx(Ee,{asChild:!0,children:n.jsx(re,{variant:"ghost",size:"icon",onClick:i,children:b})}),e[27]=i,e[28]=x):x=e[28];let y;e[29]===Symbol.for("react.memo_cache_sentinel")?(y=n.jsx(Te,{side:"bottom",children:"Close"}),e[29]=y):y=e[29];let w;e[30]!==x?(w=n.jsxs(Re,{children:[x,y]}),e[30]=x,e[31]=w):w=e[31];let C;return e[32]!==v||e[33]!==w||e[34]!==h||e[35]!==f?(C=n.jsxs("div",{className:"flex h-9 shrink-0 items-center gap-1 border-b border-border/60 px-2",children:[h,f,v,w]}),e[32]=v,e[33]=w,e[34]=h,e[35]=f,e[36]=C):C=e[36],C}function Bb(t){const e=K.c(24),{fileKey:s,taskId:i}=t,r=ts(),{data:o,isPending:a}=Fc(i);let l;e[0]!==s||e[1]!==o?(l=o?.find(p=>p.key===s)??null,e[0]=s,e[1]=o,e[2]=l):l=e[2];const h=l;let c;e[3]!==r?(c=()=>r({to:".",search:Mb,replace:!0}),e[3]=r,e[4]=c):c=e[4];const d=c;if(!h){if(a){let x;return e[5]===Symbol.for("react.memo_cache_sentinel")?(x=n.jsx("div",{className:"h-full w-full bg-background",children:n.jsx(xm,{})}),e[5]=x):x=e[5],x}let p;e[6]!==s?(p=s.split("/").pop()??s,e[6]=s,e[7]=p):p=e[7];let _;e[8]!==p?(_=n.jsx(Li,{filename:p,className:"h-7.5 w-6"}),e[8]=p,e[9]=_):_=e[9];let g;e[10]===Symbol.for("react.memo_cache_sentinel")?(g=n.jsx("span",{className:"text-sm text-muted-foreground",children:"This file is no longer available."}),e[10]=g):g=e[10];let v;e[11]!==d?(v=n.jsx(re,{variant:"ghost",size:"sm",onClick:d,children:"Close"}),e[11]=d,e[12]=v):v=e[12];let b;return e[13]!==_||e[14]!==v?(b=n.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-2 bg-background",children:[_,g,v]}),e[13]=_,e[14]=v,e[15]=b):b=e[15],b}let u;e[16]!==h||e[17]!==d?(u=n.jsx(Ib,{file:h,onClose:d}),e[16]=h,e[17]=d,e[18]=u):u=e[18];let f;e[19]!==h?(f=n.jsx("div",{className:"relative min-h-0 flex-1",children:n.jsx(bm,{file:h})}),e[19]=h,e[20]=f):f=e[20];let m;return e[21]!==u||e[22]!==f?(m=n.jsxs("div",{className:"flex h-full w-full flex-col bg-background",children:[u,f]}),e[21]=u,e[22]=f,e[23]=m):m=e[23],m}function Mb(t){return{...t,main:"0"}}const Dl="home";function Lb(t){const e=K.c(5),{label:s}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=n.jsx(uh,{className:"aspect-video w-2/3 max-w-xl"}),e[0]=i):i=e[0];let r;e[1]!==s?(r=s&&n.jsx("p",{className:"text-xs text-muted-foreground",children:s}),e[1]=s,e[2]=r):r=e[2];let o;return e[3]!==r?(o=n.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-3 bg-background",children:[i,r]}),e[3]=r,e[4]=o):o=e[4],o}function Ob(t){const e=K.c(12),{path:s}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i={refetchIntervalWhenAbsent:2e3},e[0]=i):i=e[0];const r=Sm(Dl,s,i),o=wm(Dl);let a;e[1]!==s||e[2]!==o?(a=o(s),e[1]=s,e[2]=o,e[3]=a):a=e[3];const l=a;if(r.isPending||!r.data){const d=!r.isPending&&!r.data?"Waiting for the deck to sync…":void 0;let u;return e[4]!==d?(u=n.jsx(Lb,{label:d}),e[4]=d,e[5]=u):u=e[5],u}let h;e[6]!==r.data?(h=Cm(r.data),e[6]=r.data,e[7]=h):h=e[7];let c;return e[8]!==s||e[9]!==l||e[10]!==h?(c=n.jsx(km,{readUrl:l,marker:h,title:s,savePath:s}),e[8]=s,e[9]=l,e[10]=h,e[11]=c):c=e[11],c}const Al=E.lazy(()=>qt(()=>import("./project-app-view-Bxi1-sx3.js"),__vite__mapDeps([162,1,2,96,6,7,8,9,10,11,12,13,14,15,16,3,17,4,5,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,97,98,46,47,48,99,100,49,101,102,58,90,91,92,93,84,94,57,95,59,103,104,105,106,107,66,108,56,109,71,72,50,110,125])).then(t=>({default:t.AppViewContent})));function $b(t){const e=K.c(49),{activeTab:s,virtualMcpId:i,taskId:r,layoutTabs:o,expandedTools:a,automationTabParsed:l}=t;if(im(s)){let v;return e[0]!==i?(v=n.jsx(_l,{virtualMcpId:i}),e[0]=i,e[1]=v):v=e[1],v}if(s==="git"){let v;return e[2]!==i?(v=n.jsx(Zv,{virtualMcpId:i}),e[2]=i,e[3]=v):v=e[3],v}if(s==="automations"){let v;return e[4]!==i?(v=n.jsx(Ab,{virtualMcpId:i}),e[4]=i,e[5]=v):v=e[5],v}if(s==="preview"){let v;return e[6]!==i?(v=n.jsx(F1,{virtualMcpId:i}),e[6]=i,e[7]=v):v=e[7],v}if(s==="content"){let v;return e[8]!==i?(v=n.jsx(Xx,{virtualMcpId:i}),e[8]=i,e[9]=v):v=e[9],v}if(l){let v;return e[10]!==s?(v=n.jsx(Eb,{tabId:s}),e[10]=s,e[11]=v):v=e[11],v}let h;e[12]!==s?(h=Qc(s),e[12]=s,e[13]=h):h=e[13];const c=h;if(c){let v;return e[14]!==c.path?(v=n.jsx(Ob,{path:c.path},c.path),e[14]=c.path,e[15]=v):v=e[15],v}let d;e[16]!==s?(d=Zc(s),e[16]=s,e[17]=d):d=e[17];const u=d;if(u){let v;return e[18]!==u.key||e[19]!==r?(v=n.jsx(Bb,{fileKey:u.key,taskId:r}),e[18]=u.key,e[19]=r,e[20]=v):v=e[20],v}let f;e[21]!==s?(f=rm(s),e[21]=s,e[22]=f):f=e[22];const m=f;if(m){let v;if(e[23]!==a||e[24]!==m.connectionId||e[25]!==m.toolName){let C;e[27]!==m.connectionId||e[28]!==m.toolName?(C=j=>j.appId===m.connectionId&&j.toolName===m.toolName,e[27]=m.connectionId,e[28]=m.toolName,e[29]=C):C=e[29],v=a.find(C),e[23]=a,e[24]=m.connectionId,e[25]=m.toolName,e[26]=v}else v=e[26];const b=v;let x;e[30]===Symbol.for("react.memo_cache_sentinel")?(x=n.jsx(Ys,{}),e[30]=x):x=e[30];const y=b?.args;let w;return e[31]!==s||e[32]!==m.connectionId||e[33]!==m.toolName||e[34]!==y?(w=n.jsx(E.Suspense,{fallback:x,children:n.jsx(Al,{connectionId:m.connectionId,toolName:m.toolName,args:y},s)}),e[31]=s,e[32]=m.connectionId,e[33]=m.toolName,e[34]=y,e[35]=w):w=e[35],w}let p;if(e[36]!==s||e[37]!==o){let v;e[39]!==s?(v=b=>b.id===s,e[39]=s,e[40]=v):v=e[40],p=o.find(v),e[36]=s,e[37]=o,e[38]=p}else p=e[38];const _=p;if(_){let v;e[41]===Symbol.for("react.memo_cache_sentinel")?(v=n.jsx(Ys,{}),e[41]=v):v=e[41];let b;return e[42]!==s||e[43]!==_.id||e[44]!==_.view.appId||e[45]!==_.view.args?(b=n.jsx(E.Suspense,{fallback:v,children:n.jsx(Al,{connectionId:_.view.appId,toolName:_.id,args:_.view.args},s)}),e[42]=s,e[43]=_.id,e[44]=_.view.appId,e[45]=_.view.args,e[46]=b):b=e[46],b}let g;return e[47]!==i?(g=n.jsx(_l,{virtualMcpId:i}),e[47]=i,e[48]=g):g=e[48],g}function zb(t){const e=K.c(14),{taskId:s,virtualMcpId:i}=t;let r;e[0]!==s||e[1]!==i?(r={virtualMcpId:i,taskId:s},e[0]=s,e[1]=i,e[2]=r):r=e[2];const{activeTab:o,layoutTabs:a,expandedTools:l,automationTabParsed:h}=Wh(r);let c;e[3]===Symbol.for("react.memo_cache_sentinel")?(c=n.jsx(Ys,{}),e[3]=c):c=e[3];let d;e[4]!==o||e[5]!==h||e[6]!==l||e[7]!==a||e[8]!==s||e[9]!==i?(d=n.jsx(E.Suspense,{fallback:c,children:n.jsx($b,{activeTab:o,virtualMcpId:i,taskId:s,layoutTabs:a,expandedTools:l,automationTabParsed:h})}),e[4]=o,e[5]=h,e[6]=l,e[7]=a,e[8]=s,e[9]=i,e[10]=d):d=e[10];let u;return e[11]!==o||e[12]!==d?(u=n.jsx(Ut,{children:d},o),e[11]=o,e[12]=d,e[13]=u):u=e[13],u}const ws="setup";function Fb(t){const e=K.c(35);let s;if(e[0]!==t.scriptTabs||e[1]!==t.scripts){let m;e[3]!==t.scriptTabs?(m=p=>!t.scriptTabs.includes(p),e[3]=t.scriptTabs,e[4]=m):m=e[4],s=t.scripts.filter(m),e[0]=t.scriptTabs,e[1]=t.scripts,e[2]=s}else s=e[2];const i=s;let r;e[5]!==t?(r=()=>{t.active===ws?t.onToggle():t.onSelectTab(ws)},e[5]=t,e[6]=r):r=e[6];const o=r,a=t.active===ws;let l;e[7]!==o||e[8]!==t.open||e[9]!==a?(l=n.jsx(Hb,{active:a,open:t.open,onClick:o}),e[7]=o,e[8]=t.open,e[9]=a,e[10]=l):l=e[10];let h;e[11]!==t?(h=t.scriptTabs.map(m=>n.jsx(Ub,{active:t.active===m,onClick:()=>t.onSelectTab(m),onClose:()=>t.onCloseScript(m),children:m},m)),e[11]=t,e[12]=h):h=e[12];let c;e[13]!==i||e[14]!==t.onAddScript?(c=n.jsx(Kb,{scripts:i,onRun:t.onAddScript}),e[13]=i,e[14]=t.onAddScript,e[15]=c):c=e[15];let d;e[16]!==l||e[17]!==h||e[18]!==c?(d=n.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1 overflow-x-auto",children:[l,h,c]}),e[16]=l,e[17]=h,e[18]=c,e[19]=d):d=e[19];let u;e[20]!==t.onRestart||e[21]!==t.onResume||e[22]!==t.onRetry||e[23]!==t.onRunActiveScript||e[24]!==t.onStart||e[25]!==t.onStop||e[26]!==t.onStopActiveScript||e[27]!==t.scriptIsKilling||e[28]!==t.scriptIsRunning||e[29]!==t.showScriptControls||e[30]!==t.status?(u=t.showScriptControls?n.jsx(Vb,{isRunning:t.scriptIsRunning,isKilling:t.scriptIsKilling,onRun:t.onRunActiveScript,onStop:t.onStopActiveScript}):n.jsx(Wb,{status:t.status,onStart:t.onStart,onStop:t.onStop,onRestart:t.onRestart,onResume:t.onResume,onRetry:t.onRetry}),e[20]=t.onRestart,e[21]=t.onResume,e[22]=t.onRetry,e[23]=t.onRunActiveScript,e[24]=t.onStart,e[25]=t.onStop,e[26]=t.onStopActiveScript,e[27]=t.scriptIsKilling,e[28]=t.scriptIsRunning,e[29]=t.showScriptControls,e[30]=t.status,e[31]=u):u=e[31];let f;return e[32]!==d||e[33]!==u?(f=n.jsxs("div",{className:"flex h-10 shrink-0 items-center gap-1 border-t border-b border-border bg-muted/60 px-3",children:[d,u]}),e[32]=d,e[33]=u,e[34]=f):f=e[34],f}function Hb(t){const e=K.c(8),{active:s,open:i,onClick:r}=t,o=s&&i,a=s&&i,l=s?"border-border bg-background font-medium text-foreground shadow-sm":"border-transparent text-muted-foreground hover:bg-background/50 hover:text-foreground";let h;e[0]!==l?(h=he("flex h-7 items-center gap-1.5 rounded-md border px-2.5 text-xs",l),e[0]=l,e[1]=h):h=e[1];let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c=n.jsx(Xf,{className:"size-3.5"}),e[2]=c):c=e[2];let d;return e[3]!==r||e[4]!==o||e[5]!==a||e[6]!==h?(d=n.jsxs("button",{type:"button","aria-pressed":o,"aria-expanded":a,onClick:r,className:h,children:[c,"sandbox"]}),e[3]=r,e[4]=o,e[5]=a,e[6]=h,e[7]=d):d=e[7],d}function Wb(t){const e=K.c(24),{status:s,onStart:i,onStop:r,onRestart:o,onResume:a,onRetry:l}=t;if(s==="idle"&&i){let h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h=n.jsx(Vs,{className:"size-3.5"}),e[0]=h):h=e[0];let c;return e[1]!==i?(c=n.jsxs(re,{variant:"outline",size:"sm",onClick:i,children:[h," Start"]}),e[1]=i,e[2]=c):c=e[2],c}if(s==="suspended"&&a){let h;e[3]===Symbol.for("react.memo_cache_sentinel")?(h=n.jsx(Vs,{className:"size-3.5"}),e[3]=h):h=e[3];let c;return e[4]!==a?(c=n.jsxs(re,{variant:"outline",size:"sm",onClick:a,children:[h," Resume"]}),e[4]=a,e[5]=c):c=e[5],c}if(s==="errored"&&l){let h;e[6]===Symbol.for("react.memo_cache_sentinel")?(h=n.jsx(Bi,{className:"size-3.5"}),e[6]=h):h=e[6];let c;return e[7]!==l?(c=n.jsxs(re,{variant:"outline",size:"sm",onClick:l,children:[h," Retry"]}),e[7]=l,e[8]=c):c=e[8],c}if(s==="starting"||s==="running"){const h=s==="running"&&!!o,c=h?"rounded-r-none border-r-0":void 0;let d;e[9]!==c?(d=he(c),e[9]=c,e[10]=d):d=e[10];let u;e[11]===Symbol.for("react.memo_cache_sentinel")?(u=n.jsx(Yc,{className:"size-3.5"}),e[11]=u):u=e[11];let f;e[12]!==r||e[13]!==d?(f=n.jsx(Ee,{asChild:!0,children:n.jsxs(re,{variant:"outline",size:"sm",onClick:r,className:d,children:[u," Stop"]})}),e[12]=r,e[13]=d,e[14]=f):f=e[14];let m;e[15]===Symbol.for("react.memo_cache_sentinel")?(m=n.jsx(Te,{children:"Stop sandbox"}),e[15]=m):m=e[15];let p;e[16]!==f?(p=n.jsxs(Re,{children:[f,m]}),e[16]=f,e[17]=p):p=e[17];let _;e[18]!==o||e[19]!==h?(_=h&&n.jsxs(Ds,{children:[n.jsx(As,{asChild:!0,children:n.jsx(re,{variant:"outline",size:"sm",className:"rounded-l-none px-1",children:n.jsx(Es,{className:"size-3"})})}),n.jsx(Is,{align:"end",children:n.jsxs(He,{onClick:o,children:[n.jsx(Bi,{className:"size-3.5"})," Restart"]})})]}),e[18]=o,e[19]=h,e[20]=_):_=e[20];let g;return e[21]!==p||e[22]!==_?(g=n.jsxs("div",{className:"flex items-center",children:[p,_]}),e[21]=p,e[22]=_,e[23]=g):g=e[23],g}return null}function Ub(t){const e=K.c(16),{active:s,onClick:i,onClose:r,children:o}=t,a=s?"border-border bg-background shadow-sm":"border-transparent hover:bg-background/50";let l;e[0]!==a?(l=he("flex h-7 items-center rounded-md border text-xs",a),e[0]=a,e[1]=l):l=e[1];const h=r?"pl-2.5 pr-1":"px-2.5",c=s?"font-medium text-foreground":"text-muted-foreground hover:text-foreground";let d;e[2]!==h||e[3]!==c?(d=he("flex h-full items-center",h,c),e[2]=h,e[3]=c,e[4]=d):d=e[4];let u;e[5]!==o||e[6]!==i||e[7]!==d?(u=n.jsx("button",{type:"button",onClick:i,className:d,children:o}),e[5]=o,e[6]=i,e[7]=d,e[8]=u):u=e[8];let f;e[9]!==o||e[10]!==r?(f=r&&n.jsx("button",{type:"button","aria-label":`Close ${o}`,onClick:r,className:"pr-1.5 text-muted-foreground hover:text-foreground",children:n.jsx(pp,{className:"size-3"})}),e[9]=o,e[10]=r,e[11]=f):f=e[11];let m;return e[12]!==l||e[13]!==u||e[14]!==f?(m=n.jsxs("div",{className:l,children:[u,f]}),e[12]=l,e[13]=u,e[14]=f,e[15]=m):m=e[15],m}function Kb(t){const e=K.c(10),{scripts:s,onRun:i}=t,[r,o]=E.useState(!1);let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=n.jsxs(Re,{children:[n.jsx(Ee,{asChild:!0,children:n.jsx(Rs,{asChild:!0,children:n.jsx(re,{variant:"ghost",size:"sm","aria-label":"Run script",children:n.jsx(xt,{className:"size-3.5"})})})}),n.jsx(Te,{children:"Run script"})]}),e[0]=a):a=e[0];let l;e[1]===Symbol.for("react.memo_cache_sentinel")?(l=n.jsx("div",{className:"px-2 py-1 text-[10px] uppercase tracking-wide text-muted-foreground",children:"run a script"}),e[1]=l):l=e[1];let h;e[2]!==i||e[3]!==s?(h=s.length===0?n.jsx("div",{className:"px-2 py-2 text-xs text-muted-foreground",children:"No scripts found"}):s.map(u=>n.jsxs("button",{type:"button",onClick:()=>{o(!1),i(u)},className:"w-full rounded-md px-2 py-1.5 text-left text-xs hover:bg-accent",children:["▸ ",u]},u)),e[2]=i,e[3]=s,e[4]=h):h=e[4];let c;e[5]!==h?(c=n.jsxs(Ps,{align:"start",className:"p-1 w-56",children:[l,h]}),e[5]=h,e[6]=c):c=e[6];let d;return e[7]!==r||e[8]!==c?(d=n.jsxs(Ts,{open:r,onOpenChange:o,children:[a,c]}),e[7]=r,e[8]=c,e[9]=d):d=e[9],d}function Vb(t){const e=K.c(13),{isRunning:s,isKilling:i,onRun:r,onStop:o}=t;if(i){let d;return e[0]===Symbol.for("react.memo_cache_sentinel")?(d=n.jsxs(re,{variant:"outline",size:"sm",disabled:!0,children:[n.jsx(Ce,{className:"size-3.5 animate-spin"})," Stopping…"]}),e[0]=d):d=e[0],d}if(!s){let d;e[1]===Symbol.for("react.memo_cache_sentinel")?(d=n.jsx(Vs,{className:"size-3.5"}),e[1]=d):d=e[1];let u;e[2]!==r?(u=n.jsx(Ee,{asChild:!0,children:n.jsxs(re,{variant:"outline",size:"sm",onClick:r,children:[d," Run"]})}),e[2]=r,e[3]=u):u=e[3];let f;e[4]===Symbol.for("react.memo_cache_sentinel")?(f=n.jsx(Te,{children:"Start process"}),e[4]=f):f=e[4];let m;return e[5]!==u?(m=n.jsxs(Re,{children:[u,f]}),e[5]=u,e[6]=m):m=e[6],m}let a;e[7]===Symbol.for("react.memo_cache_sentinel")?(a=n.jsx(Yc,{className:"size-3.5"}),e[7]=a):a=e[7];let l;e[8]!==o?(l=n.jsx(Ee,{asChild:!0,children:n.jsxs(re,{variant:"outline",size:"sm",onClick:o,children:[a," Stop"]})}),e[8]=o,e[9]=l):l=e[9];let h;e[10]===Symbol.for("react.memo_cache_sentinel")?(h=n.jsx(Te,{children:"Stop process"}),e[10]=h):h=e[10];let c;return e[11]!==l?(c=n.jsxs(Re,{children:[l,h]}),e[11]=l,e[12]=c):c=e[12],c}var Td=Object.defineProperty,qb=Object.getOwnPropertyDescriptor,Gb=(t,e)=>{for(var s in e)Td(t,s,{get:e[s],enumerable:!0})},ze=(t,e,s,i)=>{for(var r=i>1?void 0:i?qb(e,s):e,o=t.length-1,a;o>=0;o--)(a=t[o])&&(r=(i?a(e,s,r):a(r))||r);return i&&r&&Td(e,s,r),r},de=(t,e)=>(s,i)=>e(s,i,t),Il="Terminal input",to={get:()=>Il,set:t=>Il=t},Bl="Too much output to announce, navigate to rows manually to read",so={get:()=>Bl,set:t=>Bl=t};function Yb(t){return t.replace(/\r?\n/g,"\r")}function Xb(t,e){return e?"\x1B[200~"+t+"\x1B[201~":t}function Jb(t,e){t.clipboardData&&t.clipboardData.setData("text/plain",e.selectionText),t.preventDefault()}function Zb(t,e,s,i){if(t.stopPropagation(),t.clipboardData){let r=t.clipboardData.getData("text/plain");Rd(r,e,s,i)}}function Rd(t,e,s,i){t=Yb(t),t=Xb(t,s.decPrivateModes.bracketedPasteMode&&i.rawOptions.ignoreBracketedPasteMode!==!0),s.triggerDataEvent(t,!0),e.value=""}function Pd(t,e,s){let i=s.getBoundingClientRect(),r=t.clientX-i.left-10,o=t.clientY-i.top-10;e.style.width="20px",e.style.height="20px",e.style.left=`${r}px`,e.style.top=`${o}px`,e.style.zIndex="1000",e.focus()}function Ml(t,e,s,i,r){Pd(t,e,s),r&&i.rightClickSelect(t),e.value=i.selectionText,e.select()}function us(t){return t>65535?(t-=65536,String.fromCharCode((t>>10)+55296)+String.fromCharCode(t%1024+56320)):String.fromCharCode(t)}function cn(t,e=0,s=t.length){let i="";for(let r=e;r<s;++r){let o=t[r];o>65535?(o-=65536,i+=String.fromCharCode((o>>10)+55296)+String.fromCharCode(o%1024+56320)):i+=String.fromCharCode(o)}return i}var Qb=class{constructor(){this._interim=0}clear(){this._interim=0}decode(t,e){let s=t.length;if(!s)return 0;let i=0,r=0;if(this._interim){let o=t.charCodeAt(r++);56320<=o&&o<=57343?e[i++]=(this._interim-55296)*1024+o-56320+65536:(e[i++]=this._interim,e[i++]=o),this._interim=0}for(let o=r;o<s;++o){let a=t.charCodeAt(o);if(55296<=a&&a<=56319){if(++o>=s)return this._interim=a,i;let l=t.charCodeAt(o);56320<=l&&l<=57343?e[i++]=(a-55296)*1024+l-56320+65536:(e[i++]=a,e[i++]=l);continue}a!==65279&&(e[i++]=a)}return i}},ey=class{constructor(){this.interim=new Uint8Array(3)}clear(){this.interim.fill(0)}decode(t,e){let s=t.length;if(!s)return 0;let i=0,r,o,a,l,h=0,c=0;if(this.interim[0]){let f=!1,m=this.interim[0];m&=(m&224)===192?31:(m&240)===224?15:7;let p=0,_;for(;(_=this.interim[++p]&63)&&p<4;)m<<=6,m|=_;let g=(this.interim[0]&224)===192?2:(this.interim[0]&240)===224?3:4,v=g-p;for(;c<v;){if(c>=s)return 0;if(_=t[c++],(_&192)!==128){c--,f=!0;break}else this.interim[p++]=_,m<<=6,m|=_&63}f||(g===2?m<128?c--:e[i++]=m:g===3?m<2048||m>=55296&&m<=57343||m===65279||(e[i++]=m):m<65536||m>1114111||(e[i++]=m)),this.interim.fill(0)}let d=s-4,u=c;for(;u<s;){for(;u<d&&!((r=t[u])&128)&&!((o=t[u+1])&128)&&!((a=t[u+2])&128)&&!((l=t[u+3])&128);)e[i++]=r,e[i++]=o,e[i++]=a,e[i++]=l,u+=4;if(r=t[u++],r<128)e[i++]=r;else if((r&224)===192){if(u>=s)return this.interim[0]=r,i;if(o=t[u++],(o&192)!==128){u--;continue}if(h=(r&31)<<6|o&63,h<128){u--;continue}e[i++]=h}else if((r&240)===224){if(u>=s)return this.interim[0]=r,i;if(o=t[u++],(o&192)!==128){u--;continue}if(u>=s)return this.interim[0]=r,this.interim[1]=o,i;if(a=t[u++],(a&192)!==128){u--;continue}if(h=(r&15)<<12|(o&63)<<6|a&63,h<2048||h>=55296&&h<=57343||h===65279)continue;e[i++]=h}else if((r&248)===240){if(u>=s)return this.interim[0]=r,i;if(o=t[u++],(o&192)!==128){u--;continue}if(u>=s)return this.interim[0]=r,this.interim[1]=o,i;if(a=t[u++],(a&192)!==128){u--;continue}if(u>=s)return this.interim[0]=r,this.interim[1]=o,this.interim[2]=a,i;if(l=t[u++],(l&192)!==128){u--;continue}if(h=(r&7)<<18|(o&63)<<12|(a&63)<<6|l&63,h<65536||h>1114111)continue;e[i++]=h}}return i}},Dd="",fs=" ",Zi=class Ad{constructor(){this.fg=0,this.bg=0,this.extended=new Ur}static toColorRGB(e){return[e>>>16&255,e>>>8&255,e&255]}static fromColorRGB(e){return(e[0]&255)<<16|(e[1]&255)<<8|e[2]&255}clone(){let e=new Ad;return e.fg=this.fg,e.bg=this.bg,e.extended=this.extended.clone(),e}isInverse(){return this.fg&67108864}isBold(){return this.fg&134217728}isUnderline(){return this.hasExtendedAttrs()&&this.extended.underlineStyle!==0?1:this.fg&268435456}isBlink(){return this.fg&536870912}isInvisible(){return this.fg&1073741824}isItalic(){return this.bg&67108864}isDim(){return this.bg&134217728}isStrikethrough(){return this.fg&2147483648}isProtected(){return this.bg&536870912}isOverline(){return this.bg&1073741824}getFgColorMode(){return this.fg&50331648}getBgColorMode(){return this.bg&50331648}isFgRGB(){return(this.fg&50331648)===50331648}isBgRGB(){return(this.bg&50331648)===50331648}isFgPalette(){return(this.fg&50331648)===16777216||(this.fg&50331648)===33554432}isBgPalette(){return(this.bg&50331648)===16777216||(this.bg&50331648)===33554432}isFgDefault(){return(this.fg&50331648)===0}isBgDefault(){return(this.bg&50331648)===0}isAttributeDefault(){return this.fg===0&&this.bg===0}getFgColor(){switch(this.fg&50331648){case 16777216:case 33554432:return this.fg&255;case 50331648:return this.fg&16777215;default:return-1}}getBgColor(){switch(this.bg&50331648){case 16777216:case 33554432:return this.bg&255;case 50331648:return this.bg&16777215;default:return-1}}hasExtendedAttrs(){return this.bg&268435456}updateExtended(){this.extended.isEmpty()?this.bg&=-268435457:this.bg|=268435456}getUnderlineColor(){if(this.bg&268435456&&~this.extended.underlineColor)switch(this.extended.underlineColor&50331648){case 16777216:case 33554432:return this.extended.underlineColor&255;case 50331648:return this.extended.underlineColor&16777215;default:return this.getFgColor()}return this.getFgColor()}getUnderlineColorMode(){return this.bg&268435456&&~this.extended.underlineColor?this.extended.underlineColor&50331648:this.getFgColorMode()}isUnderlineColorRGB(){return this.bg&268435456&&~this.extended.underlineColor?(this.extended.underlineColor&50331648)===50331648:this.isFgRGB()}isUnderlineColorPalette(){return this.bg&268435456&&~this.extended.underlineColor?(this.extended.underlineColor&50331648)===16777216||(this.extended.underlineColor&50331648)===33554432:this.isFgPalette()}isUnderlineColorDefault(){return this.bg&268435456&&~this.extended.underlineColor?(this.extended.underlineColor&50331648)===0:this.isFgDefault()}getUnderlineStyle(){return this.fg&268435456?this.bg&268435456?this.extended.underlineStyle:1:0}getUnderlineVariantOffset(){return this.extended.underlineVariantOffset}},Ur=class Id{constructor(e=0,s=0){this._ext=0,this._urlId=0,this._ext=e,this._urlId=s}get ext(){return this._urlId?this._ext&-469762049|this.underlineStyle<<26:this._ext}set ext(e){this._ext=e}get underlineStyle(){return this._urlId?5:(this._ext&469762048)>>26}set underlineStyle(e){this._ext&=-469762049,this._ext|=e<<26&469762048}get underlineColor(){return this._ext&67108863}set underlineColor(e){this._ext&=-67108864,this._ext|=e&67108863}get urlId(){return this._urlId}set urlId(e){this._urlId=e}get underlineVariantOffset(){let e=(this._ext&3758096384)>>29;return e<0?e^4294967288:e}set underlineVariantOffset(e){this._ext&=536870911,this._ext|=e<<29&3758096384}clone(){return new Id(this._ext,this._urlId)}isEmpty(){return this.underlineStyle===0&&this._urlId===0}},Nt=class Bd extends Zi{constructor(){super(...arguments),this.content=0,this.fg=0,this.bg=0,this.extended=new Ur,this.combinedData=""}static fromCharData(e){let s=new Bd;return s.setFromCharData(e),s}isCombined(){return this.content&2097152}getWidth(){return this.content>>22}getChars(){return this.content&2097152?this.combinedData:this.content&2097151?us(this.content&2097151):""}getCode(){return this.isCombined()?this.combinedData.charCodeAt(this.combinedData.length-1):this.content&2097151}setFromCharData(e){this.fg=e[0],this.bg=0;let s=!1;if(e[1].length>2)s=!0;else if(e[1].length===2){let i=e[1].charCodeAt(0);if(55296<=i&&i<=56319){let r=e[1].charCodeAt(1);56320<=r&&r<=57343?this.content=(i-55296)*1024+r-56320+65536|e[2]<<22:s=!0}else s=!0}else this.content=e[1].charCodeAt(0)|e[2]<<22;s&&(this.combinedData=e[1],this.content=2097152|e[2]<<22)}getAsCharData(){return[this.fg,this.getChars(),this.getWidth(),this.getCode()]}},Ll="di$target",io="di$dependencies",jn=new Map;function ty(t){return t[io]||[]}function Qe(t){if(jn.has(t))return jn.get(t);let e=function(s,i,r){if(arguments.length!==3)throw new Error("@IServiceName-decorator can only be used to decorate a parameter");sy(e,s,r)};return e._id=t,jn.set(t,e),e}function sy(t,e,s){e[Ll]===e?e[io].push({id:t,index:s}):(e[io]=[{id:t,index:s}],e[Ll]=e)}var ht=Qe("BufferService"),Md=Qe("CoreMouseService"),Ls=Qe("CoreService"),iy=Qe("CharsetService"),Ta=Qe("InstantiationService"),Ld=Qe("LogService"),dt=Qe("OptionsService"),Od=Qe("OscLinkService"),ry=Qe("UnicodeService"),Qi=Qe("DecorationService"),ro=class{constructor(t,e,s){this._bufferService=t,this._optionsService=e,this._oscLinkService=s}provideLinks(t,e){let s=this._bufferService.buffer.lines.get(t-1);if(!s){e(void 0);return}let i=[],r=this._optionsService.rawOptions.linkHandler,o=new Nt,a=s.getTrimmedLength(),l=-1,h=-1,c=!1;for(let d=0;d<a;d++)if(!(h===-1&&!s.hasContent(d))){if(s.loadCell(d,o),o.hasExtendedAttrs()&&o.extended.urlId)if(h===-1){h=d,l=o.extended.urlId;continue}else c=o.extended.urlId!==l;else h!==-1&&(c=!0);if(c||h!==-1&&d===a-1){let u=this._oscLinkService.getLinkData(l)?.uri;if(u){let f={start:{x:h+1,y:t},end:{x:d+(!c&&d===a-1?1:0),y:t}},m=!1;if(!r?.allowNonHttpProtocols)try{let p=new URL(u);["http:","https:"].includes(p.protocol)||(m=!0)}catch{m=!0}m||i.push({text:u,range:f,activate:(p,_)=>r?r.activate(p,_,f):ny(p,_),hover:(p,_)=>r?.hover?.(p,_,f),leave:(p,_)=>r?.leave?.(p,_,f)})}c=!1,o.hasExtendedAttrs()&&o.extended.urlId?(h=d,l=o.extended.urlId):(h=-1,l=-1)}}e(i)}};ro=ze([de(0,ht),de(1,dt),de(2,Od)],ro);function ny(t,e){if(confirm(`Do you want to navigate to ${e}?
|
|
293
|
+
});`:"",j=f==="curl"?w:C;let R;e[5]!==h?(R=n.jsx(rs,{children:h}),e[5]=h,e[6]=R):R=e[6];let B;e[7]!==c?(B=n.jsx(Jo,{children:c}),e[7]=c,e[8]=B):B=e[8];let P;e[9]!==R||e[10]!==B?(P=n.jsxs(is,{children:[R,B]}),e[9]=R,e[10]=B,e[11]=P):P=e[11];let T;e[12]!==p||e[13]!==d||e[14]!==y||e[15]!==f||e[16]!==j||e[17]!==o||e[18]!==g||e[19]!==r?(T=r&&o?n.jsxs("div",{className:"flex flex-col gap-3 min-w-0",children:[n.jsxs("div",{className:"flex flex-col gap-1",children:[n.jsx("span",{className:"text-xs font-semibold text-muted-foreground",children:"URL"}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("code",{className:"flex-1 min-w-0 text-xs font-mono bg-muted rounded-md px-2 py-1.5 truncate",children:y}),n.jsxs(re,{size:"sm",variant:"outline",onClick:()=>b(y,"url"),children:[n.jsx(Qt,{size:13}),d==="url"?"Copied":"Copy"]})]})]}),n.jsxs("div",{className:"flex flex-col gap-1",children:[n.jsx("span",{className:"text-xs font-semibold text-muted-foreground",children:"Token (shown once)"}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("code",{className:"flex-1 min-w-0 text-xs font-mono bg-muted rounded-md px-2 py-1.5 truncate",children:o}),n.jsxs(re,{size:"sm",variant:"outline",onClick:()=>b(o,"token"),children:[n.jsx(Qt,{size:13}),d==="token"?"Copied":"Copy"]})]})]}),n.jsxs("div",{className:"flex flex-col gap-2",children:[n.jsx("span",{className:"text-xs font-semibold text-muted-foreground",children:"Snippet"}),n.jsxs("div",{className:"flex items-center justify-between gap-3",children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx(Qo,{value:f,onValueChange:N=>m(N),children:n.jsxs(Zo,{className:"h-8 p-[2px]",children:[n.jsx(ys,{value:"curl",className:"h-7 px-2.5 text-xs",children:"curl"}),n.jsx(ys,{value:"fetch",className:"h-7 px-2.5 text-xs",children:"fetch"})]})}),n.jsxs("label",{htmlFor:g,className:"flex items-center gap-1.5 text-xs text-muted-foreground cursor-pointer select-none",children:[n.jsx(nn,{id:g,checked:p==="url",onCheckedChange:N=>_(N?"url":"header")}),"Token in URL"]})]}),n.jsxs(re,{size:"sm",variant:"outline",onClick:()=>b(j,"example"),children:[n.jsx(Qt,{size:13}),d==="example"?"Copied":"Copy"]})]}),n.jsx("div",{className:"rounded-md border overflow-hidden min-w-0",children:n.jsx(up,{code:j,language:f==="curl"?"shell":"typescript",readOnly:!0,disableDiagnostics:!0,height:180})})]})]}):null,e[12]=p,e[13]=d,e[14]=y,e[15]=f,e[16]=j,e[17]=o,e[18]=g,e[19]=r,e[20]=T):T=e[20];let S;e[21]!==i?(S=n.jsx(ii,{children:n.jsx(re,{onClick:()=>i(!1),children:"Done"})}),e[21]=i,e[22]=S):S=e[22];let k;e[23]!==P||e[24]!==T||e[25]!==S?(k=n.jsxs(Ot,{className:"max-w-lg",children:[P,T,S]}),e[23]=P,e[24]=T,e[25]=S,e[26]=k):k=e[26];let I;return e[27]!==i||e[28]!==s||e[29]!==k?(I=n.jsx(Lt,{open:s,onOpenChange:i,children:k}),e[27]=i,e[28]=s,e[29]=k,e[30]=I):I=e[30],I}function _b(t){const e=K.c(83),{trigger:s,automationId:i,connectionName:r}=t,{triggerAdd:o,triggerRemove:a,triggerRotateToken:l}=Gi(),[h,c]=E.useState(!1),[d,u]=E.useState(!1),[f,m]=E.useState(null);let p;e[0]!==s.cron_expression?(p=s.cron_expression?ub(s.cron_expression):null,e[0]=s.cron_expression,e[1]=p):p=e[1];const _=p,[g,v]=E.useState(_?.count??1),[b,x]=E.useState(!1),[y,w]=E.useState(s.cron_expression??""),C=a.isPending||o.isPending||l.isPending,j=s.type==="cron",R=s.type==="webhook";let B;e[2]!==i||e[3]!==a||e[4]!==s.id?(B=async()=>{try{await a.mutateAsync({trigger_id:s.id,automation_id:i}),le.success("Starter removed")}catch{le.error("Failed to remove starter")}c(!1)},e[2]=i,e[3]=a,e[4]=s.id,e[5]=B):B=e[5];const P=B;let T;e[6]!==o||e[7]!==i||e[8]!==y||e[9]!==a||e[10]!==s.cron_expression||e[11]!==s.id?(T=async()=>{const te=y.trim();if(!te||!Ai(te)||te===s.cron_expression){x(!1),w(s.cron_expression??"");return}try{await o.mutateAsync({automation_id:i,type:"cron",cron_expression:te}),await a.mutateAsync({trigger_id:s.id,automation_id:i}),x(!1)}catch{le.error("Failed to update starter"),w(s.cron_expression??""),x(!1)}},e[6]=o,e[7]=i,e[8]=y,e[9]=a,e[10]=s.cron_expression,e[11]=s.id,e[12]=T):T=e[12];const S=T;let k;e[13]!==i||e[14]!==l||e[15]!==s.id?(k=async()=>{u(!1);try{const te=await l.mutateAsync({trigger_id:s.id,automation_id:i});m({url:te.url,token:te.token})}catch(te){const me=te,ne=me instanceof Error?me.message:"Failed to rotate token";le.error(ne)}},e[13]=i,e[14]=l,e[15]=s.id,e[16]=k):k=e[16];const I=k;let N;e[17]!==o||e[18]!==i||e[19]!==_||e[20]!==a||e[21]!==s.cron_expression||e[22]!==s.id?(N=async te=>{if(!_)return;const me=_.unit==="minutes"?5:1,ne=Math.max(me,te);ne!==te&&v(ne);const ke=db(ne,_.unit);if(ke!==s.cron_expression)try{await o.mutateAsync({automation_id:i,type:"cron",cron_expression:ke}),await a.mutateAsync({trigger_id:s.id,automation_id:i})}catch{le.error("Failed to update starter"),v(_.count)}},e[17]=o,e[18]=i,e[19]=_,e[20]=a,e[21]=s.cron_expression,e[22]=s.id,e[23]=N):N=e[23];const A=N;let M;e[24]!==j||e[25]!==R?(M=j?n.jsx(Ei,{size:14,className:"text-muted-foreground shrink-0"}):R?n.jsx(Ki,{size:14,className:"text-muted-foreground shrink-0"}):n.jsx($i,{size:14,className:"text-muted-foreground shrink-0"}),e[24]=j,e[25]=R,e[26]=M):M=e[26];let D;e[27]!==r||e[28]!==g||e[29]!==y||e[30]!==A||e[31]!==S||e[32]!==_||e[33]!==j||e[34]!==b||e[35]!==C||e[36]!==R||e[37]!==s.cron_expression||e[38]!==s.event_type||e[39]!==s.params?(D=_&&j?n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"text-sm text-muted-foreground",children:"Every"}),n.jsx("input",{type:"number",min:_.unit==="minutes"?5:1,value:g,onChange:te=>v(parseInt(te.target.value)||1),onBlur:()=>A(g),onKeyDown:te=>{te.key==="Enter"&&te.target.blur(),te.key==="Escape"&&v(_.count)},disabled:C,className:"w-12 text-center text-sm h-7 border border-border rounded-md bg-background px-1 focus:outline-none focus:ring-1 focus:ring-ring"}),n.jsx("span",{className:"text-sm",children:fb(_.unit,g)})]}):j&&b?n.jsxs(n.Fragment,{children:[n.jsx("input",{type:"text",value:y,onChange:te=>w(te.target.value),onBlur:S,onKeyDown:te=>{te.key==="Enter"&&te.target.blur(),te.key==="Escape"&&(x(!1),w(s.cron_expression??""))},className:"flex-1 text-sm font-mono bg-transparent outline-none",autoFocus:!0}),y&&!Ai(y)&&n.jsx("span",{className:"text-xs text-muted-foreground/60 shrink-0",children:"invalid"})]}):n.jsxs("div",{className:"flex flex-col gap-0.5 flex-1 min-w-0",children:[n.jsx("span",{className:"text-sm font-mono text-xs text-muted-foreground truncate",children:j?hb(s.cron_expression??""):R?"Webhook · POST to fire":`${s.event_type}${r?` · ${r}`:""}`}),!j&&!R&&s.params&&Object.keys(s.params).length>0&&n.jsx("span",{className:"text-xs text-muted-foreground/60 truncate",children:Object.entries(s.params).map(gb).join(", ")})]}),e[27]=r,e[28]=g,e[29]=y,e[30]=A,e[31]=S,e[32]=_,e[33]=j,e[34]=b,e[35]=C,e[36]=R,e[37]=s.cron_expression,e[38]=s.event_type,e[39]=s.params,e[40]=D):D=e[40];let $;e[41]!==C?($=C&&n.jsx(Ce,{size:13,className:"animate-spin text-muted-foreground"}),e[41]=C,e[42]=$):$=e[42];let z;e[43]!==_||e[44]!==j||e[45]!==b||e[46]!==s.cron_expression?(z=j&&!_&&!b&&n.jsx(re,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 opacity-0 group-hover:opacity-100 transition-opacity",onClick:()=>{w(s.cron_expression??""),x(!0)},children:n.jsx(sa,{size:13,className:"text-muted-foreground"})}),e[43]=_,e[44]=j,e[45]=b,e[46]=s.cron_expression,e[47]=z):z=e[47];let W;e[48]!==R?(W=R&&n.jsx(re,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 opacity-0 group-hover:opacity-100 transition-opacity",title:"Rotate token",onClick:()=>u(!0),children:n.jsx(Bi,{size:13,className:"text-muted-foreground"})}),e[48]=R,e[49]=W):W=e[49];let F;e[50]===Symbol.for("react.memo_cache_sentinel")?(F=n.jsx(re,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 opacity-0 group-hover:opacity-100 transition-opacity",onClick:()=>c(!0),children:n.jsx(ps,{size:13,className:"text-muted-foreground"})}),e[50]=F):F=e[50];let V;e[51]!==W||e[52]!==$||e[53]!==z?(V=n.jsxs("div",{className:"ml-auto flex items-center gap-1",children:[$,z,W,F]}),e[51]=W,e[52]=$,e[53]=z,e[54]=V):V=e[54];let J;e[55]!==V||e[56]!==M||e[57]!==D?(J=n.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-2.5 rounded-lg border border-border bg-background group",children:[M,D,V]}),e[55]=V,e[56]=M,e[57]=D,e[58]=J):J=e[58];let Y;e[59]===Symbol.for("react.memo_cache_sentinel")?(Y=n.jsxs(Dr,{children:[n.jsx(Ar,{children:"Remove Starter"}),n.jsx(Ir,{children:"Are you sure you want to remove this starter?"})]}),e[59]=Y):Y=e[59];let U;e[60]===Symbol.for("react.memo_cache_sentinel")?(U=n.jsx(Mr,{children:"Cancel"}),e[60]=U):U=e[60];let H;e[61]!==P?(H=n.jsxs(Pr,{children:[Y,n.jsxs(Br,{children:[U,n.jsx(Lr,{onClick:P,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Remove"})]})]}),e[61]=P,e[62]=H):H=e[62];let X;e[63]!==h||e[64]!==H?(X=n.jsx(Rr,{open:h,onOpenChange:c,children:H}),e[63]=h,e[64]=H,e[65]=X):X=e[65];let oe;e[66]===Symbol.for("react.memo_cache_sentinel")?(oe=n.jsxs(Dr,{children:[n.jsx(Ar,{children:"Rotate webhook token"}),n.jsx(Ir,{children:"A new token will be generated and the current token will stop working. Any senders using the old token must be updated."})]}),e[66]=oe):oe=e[66];let L;e[67]===Symbol.for("react.memo_cache_sentinel")?(L=n.jsx(Mr,{children:"Cancel"}),e[67]=L):L=e[67];let se;e[68]!==I?(se=n.jsxs(Pr,{children:[oe,n.jsxs(Br,{children:[L,n.jsx(Lr,{onClick:I,children:"Rotate"})]})]}),e[68]=I,e[69]=se):se=e[69];let ee;e[70]!==d||e[71]!==se?(ee=n.jsx(Rr,{open:d,onOpenChange:u,children:se}),e[70]=d,e[71]=se,e[72]=ee):ee=e[72];const Q=f!==null;let O;e[73]===Symbol.for("react.memo_cache_sentinel")?(O=te=>{te||m(null)},e[73]=O):O=e[73];const ce=f?.url??null,ue=f?.token??null;let fe;e[74]!==Q||e[75]!==ce||e[76]!==ue?(fe=n.jsx(jd,{open:Q,onOpenChange:O,url:ce,token:ue,title:"New webhook token",description:"The previous token has been revoked. Copy the new token now — it will not be shown again."}),e[74]=Q,e[75]=ce,e[76]=ue,e[77]=fe):fe=e[77];let q;return e[78]!==J||e[79]!==X||e[80]!==ee||e[81]!==fe?(q=n.jsxs(n.Fragment,{children:[J,X,ee,fe]}),e[78]=J,e[79]=X,e[80]=ee,e[81]=fe,e[82]=q):q=e[82],q}function gb(t){const[e,s]=t;return`${e}: ${s}`}const vb=30;function xb(t,e){switch(e.type){case"accumulate":{const s=t??{start:e.now,fields:new Set,saveCount:0},i=new Set(s.fields);for(const r of e.fields)i.add(r);return{...s,fields:i,saveCount:s.saveCount+1}}case"reset":return null}}function bb(t){const e=K.c(55),{automationId:s,onDone:i}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={binding:"TRIGGER"},e[0]=r):r=e[0];const o=Vi(r),[a,l]=E.useState(),[h,c]=E.useState();let d;e[1]===Symbol.for("react.memo_cache_sentinel")?(d={},e[1]=d):d=e[1];const[u,f]=E.useState(d),{triggerAdd:m}=Gi(),{data:p,isLoading:_}=lp(a);let g,v,b,x,y,w;if(e[2]!==m||e[3]!==s||e[4]!==a||e[5]!==h||e[6]!==_||e[7]!==i||e[8]!==u||e[9]!==o||e[10]!==p){const R=p?.find(D=>D.type===h);let B;e[17]!==m||e[18]!==s||e[19]!==a||e[20]!==h||e[21]!==i||e[22]!==u?(B=async()=>{if(!(!a||!h))try{await m.mutateAsync({automation_id:s,type:"event",event_type:h,connection_id:a,params:u}),De("automation_trigger_added",{automation_id:s,trigger_type:"event",connection_id:a,event_type:h}),le.success("Event trigger added"),i()}catch{le.error("Failed to add event trigger")}},e[17]=m,e[18]=s,e[19]=a,e[20]=h,e[21]=i,e[22]=u,e[23]=B):B=e[23],g=B,v="flex flex-col gap-3 px-3 py-3 rounded-lg border border-border bg-background";let P,T;e[24]===Symbol.for("react.memo_cache_sentinel")?(T=n.jsx($i,{size:14,className:"text-muted-foreground shrink-0"}),P=n.jsx("span",{className:"text-sm font-medium",children:"Event trigger"}),e[24]=P,e[25]=T):(P=e[24],T=e[25]);let S;e[26]===Symbol.for("react.memo_cache_sentinel")?(S=n.jsx(ps,{size:13}),e[26]=S):S=e[26],e[27]!==i?(b=n.jsxs("div",{className:"flex items-center gap-2",children:[T,P,n.jsx("button",{type:"button",className:"ml-auto shrink-0 p-0.5 rounded text-muted-foreground hover:text-foreground",onClick:i,children:S})]}),e[27]=i,e[28]=b):b=e[28];const k=a??"";let I;e[29]===Symbol.for("react.memo_cache_sentinel")?(I=D=>{l(D),c(void 0),f({})},e[29]=I):I=e[29];let N;e[30]===Symbol.for("react.memo_cache_sentinel")?(N=n.jsx(Pt,{className:"w-full",children:n.jsx(Dt,{placeholder:"Select connection..."})}),e[30]=N):N=e[30];let A;e[31]!==o?(A=o.length===0?n.jsx("div",{className:"px-2 py-3 text-center text-xs text-muted-foreground",children:"No connections with trigger support"}):o.map(wb),e[31]=o,e[32]=A):A=e[32];let M;e[33]!==A?(M=n.jsx(At,{children:A}),e[33]=A,e[34]=M):M=e[34],e[35]!==k||e[36]!==M?(x=n.jsxs(It,{value:k,onValueChange:I,children:[N,M]}),e[35]=k,e[36]=M,e[37]=x):x=e[37],e[38]!==a||e[39]!==h||e[40]!==_||e[41]!==p?(y=a&&n.jsxs(It,{value:h??"",onValueChange:D=>{c(D),f({})},children:[n.jsx(Pt,{className:"w-full",children:_?n.jsxs("span",{className:"flex items-center gap-2 text-muted-foreground",children:[n.jsx(Ce,{size:13,className:"animate-spin"}),"Loading events..."]}):n.jsx(Dt,{placeholder:"Select event type...",children:h??"Select event type..."})}),n.jsx(At,{children:p?.map(Sb)})]}),e[38]=a,e[39]=h,e[40]=_,e[41]=p,e[42]=y):y=e[42],w=R?.paramsSchema&&Object.keys(R.paramsSchema).length>0&&n.jsx("div",{className:"flex flex-col gap-2",children:Object.entries(R.paramsSchema).map(D=>{const[$,z]=D;return n.jsxs("div",{className:"flex flex-col gap-1",children:[n.jsxs("label",{className:"text-xs text-muted-foreground",children:[$,z.description&&n.jsxs("span",{className:"text-muted-foreground/60",children:[" ","— ",z.description]})]}),z.enum?n.jsxs(It,{value:u[$]??"",onValueChange:W=>f(F=>({...F,[$]:W})),children:[n.jsx(Pt,{className:"w-full",children:n.jsx(Dt,{placeholder:`Select ${$}...`})}),n.jsx(At,{children:z.enum.map(yb)})]}):n.jsx("input",{type:"text",value:u[$]??"",onChange:W=>f(F=>({...F,[$]:W.target.value})),placeholder:z.description??$,className:"text-sm border border-border rounded-md bg-background px-2 py-1.5 focus:outline-none focus:ring-1 focus:ring-ring"})]},$)})}),e[2]=m,e[3]=s,e[4]=a,e[5]=h,e[6]=_,e[7]=i,e[8]=u,e[9]=o,e[10]=p,e[11]=g,e[12]=v,e[13]=b,e[14]=x,e[15]=y,e[16]=w}else g=e[11],v=e[12],b=e[13],x=e[14],y=e[15],w=e[16];let C;e[43]!==m||e[44]!==a||e[45]!==h||e[46]!==g?(C=a&&h&&n.jsx(re,{size:"sm",onClick:g,disabled:m.isPending,children:m.isPending?n.jsx(Ce,{size:13,className:"animate-spin"}):"Add trigger"}),e[43]=m,e[44]=a,e[45]=h,e[46]=g,e[47]=C):C=e[47];let j;return e[48]!==v||e[49]!==b||e[50]!==x||e[51]!==y||e[52]!==w||e[53]!==C?(j=n.jsxs("div",{className:v,children:[b,x,y,w,C]}),e[48]=v,e[49]=b,e[50]=x,e[51]=y,e[52]=w,e[53]=C,e[54]=j):j=e[54],j}function yb(t){return n.jsx(ot,{value:t,children:t},t)}function Sb(t){return n.jsx(ot,{value:t.type,children:n.jsxs("div",{className:"flex flex-col",children:[n.jsx("span",{children:t.type}),n.jsx("span",{className:"text-xs text-muted-foreground",children:t.description})]})},t.type)}function wb(t){return n.jsx(ot,{value:t.id,children:t.title},t.id)}function Cb({automationId:t,automation:e,onBack:s,onDelete:i}){const r=e.virtual_mcp_id,{org:o}=Pe(),{update:a,triggerAdd:l,run:h}=Gi(),c=Vi(),d=new Map(c.map(O=>[O.id,O.title])),{openTask:u}=ss(),{setChatOpen:f}=Uo(),{sendMessage:m}=Ns(),p=e.messages?.[0]?.metadata?.tiptapDoc??void 0,[_,g]=E.useState(p),[v,b]=E.useState(!1),[x,y]=E.useState(!1),[w,C]=E.useState(!1),[j,R]=E.useState(""),[B,P]=E.useState(!1),[T,S]=E.useState(null),[k,I]=E.useState(!1),[N,A]=E.useState(!1),[M,D]=E.useState(!1),$=async()=>{if(k)return;const ce=nf(_).filter(ue=>ue.type==="text").map(ue=>ue.text).join(`
|
|
294
|
+
`);if(ce.trim()){I(!0);try{se(),De("automation_improve_clicked",{automation_id:t,agent_id:r,instructions_length:ce.length}),f(!0),await m({tiptapDoc:Uh({managerAgentId:Oc.AUTOMATION_MANAGER(o.id),managerName:"Automation Manager",kind:"automation",id:t,instructions:ce})})}finally{I(!1)}}},z=e.models?.tier??"smart",W=e.models?.modelId&&e.models?.credentialId?{modelId:e.models.modelId,credentialId:e.models.credentialId,title:e.models.modelTitle??e.models.modelId}:null,F=Mc({defaultValues:{name:e.name,active:e.active,tier:z,modelOverride:W,tools:e.tools??null,maxAgentSteps:e.maxAgentSteps??null}}),V=F.watch("active"),[J,Y]=E.useReducer(xb,null),U=()=>{J!==null&&(De("automation_updated",{automation_id:t,agent_id:r,fields:Array.from(J.fields),save_count:J.saveCount,edit_duration_ms:Date.now()-J.start}),Y({type:"reset"}))},H=async()=>{const O=F.control._formState.dirtyFields,ce=Object.keys(O);if(ce.length===0&&!M)return!0;const ue=F.getValues(),fe=F.control._defaultValues;F.reset(ue,{keepValues:!0});const q=M;D(!1);const te={tier:ue.tier,...ue.modelOverride?{modelId:ue.modelOverride.modelId,credentialId:ue.modelOverride.credentialId,modelTitle:ue.modelOverride.title}:{}},me={id:t,name:ue.name,active:ue.active,models:te,tools:ue.tools,maxAgentSteps:ue.maxAgentSteps,messages:rf(_),temperature:0};try{await a.mutateAsync(me)}catch{return F.reset(fe,{keepValues:!0}),q&&D(!0),!1}const ne=[...ce];return q&&ne.push("messages"),Y({type:"accumulate",now:Date.now(),fields:ne}),L(),!0},{schedule:X,flush:oe}=$r({save:H}),{schedule:L,flush:se}=$r({delayMs:3e4,save:async()=>U()});E.useEffect(()=>{const O=F.watch(()=>X());return()=>O.unsubscribe()},[]);const ee=O=>{if(g(O),!N){A(!0);return}D(!0),X()},Q=async()=>{De("automation_test_clicked",{automation_id:t,agent_id:r});const O=await oe();if(se(),!!O){if(!_){le.error("No instructions configured for this automation");return}try{const ce=await h.mutateAsync(t);ce.threadId&&(f(!0),u(ce.threadId))}catch{}}};return n.jsxs(n.Fragment,{children:[s&&n.jsx("div",{className:"flex items-center pb-4 shrink-0",children:n.jsxs(re,{variant:"ghost",size:"sm",onClick:s,children:[n.jsx(_h,{size:14}),"Back to list"]})}),n.jsxs("div",{className:"flex flex-col gap-8",children:[n.jsxs("div",{className:"flex flex-col gap-1.5",children:[n.jsxs("div",{className:"flex items-center justify-between gap-4",children:[n.jsx(vt,{control:F.control,name:"name",render:({field:O})=>n.jsx(qe,{...O,placeholder:"Automation name",className:"border border-transparent shadow-none px-0 text-lg font-medium h-auto focus-visible:ring-0 focus-visible:border-border bg-transparent flex-1",style:{boxShadow:"none"}})}),i&&n.jsx(re,{variant:"ghost",size:"icon",className:"text-muted-foreground hover:text-destructive shrink-0",onClick:i,children:n.jsx(qs,{size:14})})]}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(vt,{control:F.control,name:"active",render:({field:O})=>n.jsx(Or,{checked:O.value,onCheckedChange:ce=>{O.onChange(ce),oe()},className:"cursor-pointer"})}),n.jsx("span",{className:"text-sm text-muted-foreground",children:V?"Active":"Inactive"}),n.jsx("span",{className:"text-muted-foreground/50 text-sm",children:"·"}),n.jsx(oh,{id:e.created_by,size:"2xs",className:"text-sm text-muted-foreground"})]})]}),n.jsxs("div",{className:"flex flex-col gap-2.5",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("span",{className:"text-xs font-semibold text-muted-foreground/60",children:"Starter"}),n.jsx(pb,{automationId:t,open:v,onOpenChange:b,onCustomSelect:()=>{C(!0),P(!1),R("")},onEventSelect:()=>{P(!0),C(!1)},onWebhookCreated:O=>{De("automation_trigger_added",{automation_id:t,trigger_type:"webhook"}),S(O)}})]}),e.triggers.length===0&&!w?n.jsx("div",{className:"rounded-lg border border-dashed border-border px-4 py-6 text-center",children:n.jsxs("p",{className:"text-sm text-muted-foreground",children:["When should this automation run?"," ",n.jsx("button",{type:"button",className:"text-foreground underline underline-offset-2 cursor-pointer hover:text-foreground/80 transition-colors",onClick:()=>b(!0),children:"Add a starter"})," ","to get going."]})}):n.jsx("div",{className:"flex flex-col gap-2",children:e.triggers.map(O=>n.jsx(_b,{trigger:O,automationId:t,connectionName:O.connection_id?d.get(O.connection_id):void 0},O.id))}),w&&n.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-2.5 rounded-lg border border-border bg-background group",children:[n.jsx(Ei,{size:14,className:"text-muted-foreground shrink-0"}),n.jsx("input",{type:"text",value:j,onChange:O=>R(O.target.value),onBlur:async()=>{const O=j.trim();if(!(!O||!Ai(O)))try{await l.mutateAsync({automation_id:t,type:"cron",cron_expression:O}),De("automation_trigger_added",{automation_id:t,trigger_type:"cron"}),le.success("Starter added"),C(!1),R("")}catch{le.error("Failed to add starter")}},onKeyDown:async O=>{const ce=j.trim();O.key==="Enter"&&ce&&Ai(ce)&&O.target.blur(),O.key==="Escape"&&(C(!1),R(""))},placeholder:"0 9 * * 1-5",className:"flex-1 text-sm font-mono bg-transparent outline-none placeholder:text-muted-foreground/40",autoFocus:!0}),j&&!Ai(j)&&n.jsx("span",{className:"text-xs text-muted-foreground/60 shrink-0",children:"invalid"}),l.isPending&&n.jsx(Ce,{size:13,className:"animate-spin text-muted-foreground shrink-0"}),n.jsx("button",{type:"button",className:"shrink-0 p-0.5 rounded text-muted-foreground opacity-0 group-hover:opacity-100 hover:text-foreground transition-opacity",onClick:()=>{C(!1),R("")},children:n.jsx(ps,{size:13})})]}),B&&n.jsx(E.Suspense,{fallback:n.jsxs("div",{className:"flex items-center gap-2 px-3 py-3 rounded-lg border border-border bg-background",children:[n.jsx(Ce,{size:13,className:"animate-spin text-muted-foreground"}),n.jsx("span",{className:"text-sm text-muted-foreground",children:"Loading connections..."})]}),children:n.jsx(bb,{automationId:t,onDone:()=>P(!1)})}),n.jsx(jd,{open:T!==null,onOpenChange:O=>{O||S(null)},url:T?.url??null,token:T?.token??null})]}),n.jsxs("div",{className:"flex flex-col gap-2.5",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("span",{className:"text-xs font-semibold text-muted-foreground/60",children:"Instructions"}),n.jsxs(re,{variant:"outline",size:"sm",className:"h-7 gap-1.5 px-2 text-xs",disabled:k||!_,onClick:$,children:[n.jsx(Ss,{size:13}),"Improve"]})]}),n.jsx(Yu,{tiptapDoc:_,setTiptapDoc:ee,placeholder:"What should this automation do?",children:n.jsxs("div",{className:"rounded-xl border border-border min-h-[120px] flex flex-col",children:[n.jsx(Xu,{virtualMcpId:r||null,className:"max-h-[45vh]"}),n.jsx("div",{className:"@container/chat-bottom flex items-center justify-end gap-1.5 p-2.5",children:n.jsxs(Re,{children:[n.jsx(Ee,{asChild:!0,children:n.jsxs(re,{type:"button",variant:"default",className:"h-8 gap-1.5 rounded-md px-3 text-sm font-medium",onClick:Q,disabled:!r,children:[n.jsx(ep,{size:16}),"Test"]})}),n.jsx(Te,{children:"Test Automation"})]})})]})})]}),n.jsxs(mf,{open:x,onOpenChange:y,className:"flex flex-col gap-2.5",children:[n.jsxs(pf,{className:"group flex w-fit cursor-pointer items-center gap-1.5",children:[n.jsx("span",{className:"text-xs font-semibold text-muted-foreground/60",children:"Advanced"}),n.jsx(Es,{size:14,className:"text-muted-foreground/60 transition-transform group-data-[state=open]:rotate-180"})]}),n.jsxs(_f,{className:"flex flex-col gap-5 pt-0.5",children:[n.jsx(Qx,{tier:F.watch("tier"),onTierChange:O=>F.setValue("tier",O,{shouldDirty:!0}),override:F.watch("modelOverride"),onOverrideChange:O=>F.setValue("modelOverride",O,{shouldDirty:!0})}),n.jsx(ib,{agentId:r||null,value:F.watch("tools"),onChange:O=>F.setValue("tools",O,{shouldDirty:!0})}),n.jsxs("div",{className:"flex flex-col gap-2",children:[n.jsx("span",{className:"text-xs font-semibold text-muted-foreground/60",children:"Max steps"}),n.jsx(qe,{type:"number",min:1,max:100,className:"w-40",placeholder:`${vb} (default)`,value:F.watch("maxAgentSteps")??"",onChange:O=>{const ce=O.target.value.trim(),ue=ce===""?null:Number(ce);F.setValue("maxAgentSteps",ue===null||Number.isNaN(ue)?null:ue,{shouldDirty:!0})}})]})]})]})]})]})}function Ys(){const t=K.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=n.jsx("div",{"data-testid":"main-panel-loading",className:"flex h-full w-full items-center justify-center",children:n.jsx(Ce,{size:20,className:"animate-spin text-muted-foreground"})}),t[0]=e):e=t[0],e}const Nd=[{key:"24h",label:"Last 24 hours",ms:1440*60*1e3},{key:"7d",label:"Last 7 days",ms:10080*60*1e3},{key:"30d",label:"Last 30 days",ms:720*60*60*1e3}];function Ed(t){const e=Nd.find(i=>i.key===t).ms,s=Date.now();return{startDate:new Date(s-e).toISOString(),endDate:new Date(s).toISOString()}}function kb(t){const e=K.c(12),{automationId:s,triggerIds:i}=t,[r,o]=E.useState("30d"),[a,l]=E.useState(Nb);let h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h=p=>{const _=p;o(_),l(Ed(_))},e[0]=h):h=e[0];let c;e[1]===Symbol.for("react.memo_cache_sentinel")?(c=n.jsx(Pt,{className:"w-44",children:n.jsx(Dt,{})}),e[1]=c):c=e[1];let d;e[2]===Symbol.for("react.memo_cache_sentinel")?(d=n.jsx(At,{children:Nd.map(jb)}),e[2]=d):d=e[2];let u;e[3]!==r?(u=n.jsx("div",{className:"flex items-center justify-end",children:n.jsxs(It,{value:r,onValueChange:h,children:[c,d]})}),e[3]=r,e[4]=u):u=e[4];let f;e[5]!==s||e[6]!==a||e[7]!==i?(f=n.jsx(fp,{automationId:s,triggerIds:i,range:a}),e[5]=s,e[6]=a,e[7]=i,e[8]=f):f=e[8];let m;return e[9]!==u||e[10]!==f?(m=n.jsxs("div",{className:"flex flex-col gap-5",children:[u,f]}),e[9]=u,e[10]=f,e[11]=m):m=e[11],m}function jb(t){return n.jsx(ot,{value:t.key,children:t.label},t.key)}function Nb(){return Ed("30d")}function Eb(t){const e=K.c(5),{tabId:s}=t;let i;e[0]!==s?(i=Jc(s),e[0]=s,e[1]=i):i=e[1];const r=i;if(!r)return null;let o;e[2]===Symbol.for("react.memo_cache_sentinel")?(o=n.jsx(Ys,{}),e[2]=o):o=e[2];let a;return e[3]!==r.id?(a=n.jsx(E.Suspense,{fallback:o,children:n.jsx(Tb,{id:r.id})}),e[3]=r.id,e[4]=a):a=e[4],a}function Tb(t){const e=K.c(24),{id:s}=t,i=ts(),{data:r,isLoading:o}=cp(s),[a,l]=E.useState("settings");let h;e[0]!==i?(h=()=>{i({to:".",search:Pb,replace:!0})},e[0]=i,e[1]=h):h=e[1];const c=h;if(o){let y;return e[2]===Symbol.for("react.memo_cache_sentinel")?(y=n.jsx(Ys,{}),e[2]=y):y=e[2],y}if(!r){let y;return e[3]===Symbol.for("react.memo_cache_sentinel")?(y=n.jsx("div",{className:"flex h-full w-full items-center justify-center text-sm text-muted-foreground",children:"Automation not found"}),e[3]=y):y=e[3],y}let d;e[4]!==r.triggers?(d=r.triggers.map(Rb),e[4]=r.triggers,e[5]=d):d=e[5];const u=d;let f;e[6]===Symbol.for("react.memo_cache_sentinel")?(f=n.jsx(_h,{size:14}),e[6]=f):f=e[6];let m;e[7]!==c?(m=n.jsxs(re,{variant:"ghost",size:"sm",onClick:c,children:[f,"Back to list"]}),e[7]=c,e[8]=m):m=e[8];let p;e[9]===Symbol.for("react.memo_cache_sentinel")?(p=[{id:"settings",label:"Settings"},{id:"runs",label:"Runs"}],e[9]=p):p=e[9];let _;e[10]===Symbol.for("react.memo_cache_sentinel")?(_=y=>l(y),e[10]=_):_=e[10];let g;e[11]!==a?(g=n.jsx(dh,{tabs:p,activeTab:a,onTabChange:_}),e[11]=a,e[12]=g):g=e[12];let v;e[13]!==m||e[14]!==g?(v=n.jsxs("div",{className:"flex items-center justify-between pb-4 shrink-0",children:[m,g]}),e[13]=m,e[14]=g,e[15]=v):v=e[15];let b;e[16]!==r||e[17]!==s||e[18]!==a||e[19]!==u?(b=a==="settings"?n.jsx(Cb,{automationId:s,automation:r}):n.jsx(kb,{automationId:s,triggerIds:u}),e[16]=r,e[17]=s,e[18]=a,e[19]=u,e[20]=b):b=e[20];let x;return e[21]!==v||e[22]!==b?(x=n.jsx(Rt,{children:n.jsx(Rt.Content,{children:n.jsxs(Rt.Body,{children:[v,b]})})}),e[21]=v,e[22]=b,e[23]=x):x=e[23],x}function Rb(t){return t.id}function Pb(t){return{...t,main:"automations"}}function Db(t){const e=K.c(20),{virtualMcpId:s}=t,i=ts(),{data:r}=hp(s),o=r===void 0?[]:r,{create:a}=Gi(),[l,h]=E.useState(""),c=l.toLowerCase(),d=o.filter(T=>T.name.toLowerCase().includes(c));let u;e[0]!==i?(u=T=>i({to:".",search:S=>({...S,main:"automation:"+T}),replace:!0}),e[0]=i,e[1]=u):u=e[1];const f=u,m=async()=>{if(a.isPending)return;De("automation_new_clicked",{virtual_mcp_id:s,existing_count:o.length});const T=await a.mutateAsync(dp(s));f(T.id)};let p;e[2]===Symbol.for("react.memo_cache_sentinel")?(p=n.jsx(xt,{size:14}),e[2]=p):p=e[2];let _;e[3]!==a.isPending||e[4]!==m?(_=n.jsxs(re,{size:"sm",onClick:m,disabled:a.isPending,children:[p,"New automation"]}),e[3]=a.isPending,e[4]=m,e[5]=_):_=e[5];const g=_,v=Rt,b=Rt,x=Rt;let y;e[6]===Symbol.for("react.memo_cache_sentinel")?(y=n.jsx(Rt.Title,{children:"Automations"}),e[6]=y):y=e[6];const w=o.length>0&&n.jsx(hh,{value:l,onChange:h,placeholder:"Search automations...",className:"w-full md:w-[375px]"});let C;e[7]!==g||e[8]!==w?(C=n.jsxs("div",{className:"flex flex-col gap-6",children:[y,n.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[w,g]})]}),e[7]=g,e[8]=w,e[9]=C):C=e[9];const j=o.length===0?n.jsx("div",{className:"flex items-center justify-center py-20",children:n.jsx(Er,{image:n.jsx($i,{size:48,className:"text-muted-foreground"}),title:"No automations yet",description:"Create your first automation to run this agent on a schedule or in response to events.",actions:g})}):d.length===0?n.jsx("div",{className:"flex items-center justify-center py-20",children:n.jsx(Er,{image:n.jsx($i,{size:48,className:"text-muted-foreground"}),title:"No automations found",description:`No automations match "${l}"`})}):n.jsx("div",{className:"mt-6 rounded-xl border border-border overflow-hidden",children:d.map(T=>n.jsx(mp,{automation:T,onClick:()=>f(T.id)},T.id))});let R;e[10]!==j||e[11]!==x.Body||e[12]!==C?(R=n.jsxs(x.Body,{children:[C,j]}),e[10]=j,e[11]=x.Body,e[12]=C,e[13]=R):R=e[13];let B;e[14]!==R||e[15]!==b.Content?(B=n.jsx(b.Content,{children:R}),e[14]=R,e[15]=b.Content,e[16]=B):B=e[16];let P;return e[17]!==v||e[18]!==B?(P=n.jsx(v,{children:B}),e[17]=v,e[18]=B,e[19]=P):P=e[19],P}function Ab(t){const e=K.c(3),{virtualMcpId:s}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=n.jsx(Ys,{}),e[0]=i):i=e[0];let r;return e[1]!==s?(r=n.jsx(E.Suspense,{fallback:i,children:n.jsx(Db,{virtualMcpId:s})}),e[1]=s,e[2]=r):r=e[2],r}function Ib(t){const e=K.c(37),{file:s,onClose:i}=t;let r,o;e[0]!==s.filename?(r=n.jsx(Li,{filename:s.filename,className:"h-4.5 w-3.5 shrink-0"}),o=n.jsx("span",{className:"truncate text-xs font-medium text-foreground",children:s.filename}),e[0]=s.filename,e[1]=r,e[2]=o):(r=e[1],o=e[2]);let a;e[3]!==s.size?(a=ym(s.size),e[3]=s.size,e[4]=a):a=e[4];let l;e[5]!==a?(l=n.jsx("span",{className:"shrink-0 text-xs text-muted-foreground",children:a}),e[5]=a,e[6]=l):l=e[6];let h;e[7]!==r||e[8]!==o||e[9]!==l?(h=n.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 px-2",children:[r,o,l]}),e[7]=r,e[8]=o,e[9]=l,e[10]=h):h=e[10];let c;e[11]===Symbol.for("react.memo_cache_sentinel")?(c=n.jsx(hm,{size:14}),e[11]=c):c=e[11];let d;e[12]!==s.downloadUrl||e[13]!==s.filename?(d=n.jsx(Ee,{asChild:!0,children:n.jsx(re,{variant:"ghost",size:"icon",asChild:!0,children:n.jsx("a",{href:s.downloadUrl,download:s.filename,children:c})})}),e[12]=s.downloadUrl,e[13]=s.filename,e[14]=d):d=e[14];let u;e[15]===Symbol.for("react.memo_cache_sentinel")?(u=n.jsx(Te,{side:"bottom",children:"Download"}),e[15]=u):u=e[15];let f;e[16]!==d?(f=n.jsxs(Re,{children:[d,u]}),e[16]=d,e[17]=f):f=e[17];let m;e[18]!==s.downloadUrl?(m=()=>window.open(s.downloadUrl,"_blank","noopener"),e[18]=s.downloadUrl,e[19]=m):m=e[19];let p;e[20]===Symbol.for("react.memo_cache_sentinel")?(p=n.jsx(ni,{size:14}),e[20]=p):p=e[20];let _;e[21]!==m?(_=n.jsx(Ee,{asChild:!0,children:n.jsx(re,{variant:"ghost",size:"icon",onClick:m,children:p})}),e[21]=m,e[22]=_):_=e[22];let g;e[23]===Symbol.for("react.memo_cache_sentinel")?(g=n.jsx(Te,{side:"bottom",children:"Open in new tab"}),e[23]=g):g=e[23];let v;e[24]!==_?(v=n.jsxs(Re,{children:[_,g]}),e[24]=_,e[25]=v):v=e[25];let b;e[26]===Symbol.for("react.memo_cache_sentinel")?(b=n.jsx(ps,{size:14}),e[26]=b):b=e[26];let x;e[27]!==i?(x=n.jsx(Ee,{asChild:!0,children:n.jsx(re,{variant:"ghost",size:"icon",onClick:i,children:b})}),e[27]=i,e[28]=x):x=e[28];let y;e[29]===Symbol.for("react.memo_cache_sentinel")?(y=n.jsx(Te,{side:"bottom",children:"Close"}),e[29]=y):y=e[29];let w;e[30]!==x?(w=n.jsxs(Re,{children:[x,y]}),e[30]=x,e[31]=w):w=e[31];let C;return e[32]!==v||e[33]!==w||e[34]!==h||e[35]!==f?(C=n.jsxs("div",{className:"flex h-9 shrink-0 items-center gap-1 border-b border-border/60 px-2",children:[h,f,v,w]}),e[32]=v,e[33]=w,e[34]=h,e[35]=f,e[36]=C):C=e[36],C}function Bb(t){const e=K.c(24),{fileKey:s,taskId:i}=t,r=ts(),{data:o,isPending:a}=Fc(i);let l;e[0]!==s||e[1]!==o?(l=o?.find(p=>p.key===s)??null,e[0]=s,e[1]=o,e[2]=l):l=e[2];const h=l;let c;e[3]!==r?(c=()=>r({to:".",search:Mb,replace:!0}),e[3]=r,e[4]=c):c=e[4];const d=c;if(!h){if(a){let x;return e[5]===Symbol.for("react.memo_cache_sentinel")?(x=n.jsx("div",{className:"h-full w-full bg-background",children:n.jsx(xm,{})}),e[5]=x):x=e[5],x}let p;e[6]!==s?(p=s.split("/").pop()??s,e[6]=s,e[7]=p):p=e[7];let _;e[8]!==p?(_=n.jsx(Li,{filename:p,className:"h-7.5 w-6"}),e[8]=p,e[9]=_):_=e[9];let g;e[10]===Symbol.for("react.memo_cache_sentinel")?(g=n.jsx("span",{className:"text-sm text-muted-foreground",children:"This file is no longer available."}),e[10]=g):g=e[10];let v;e[11]!==d?(v=n.jsx(re,{variant:"ghost",size:"sm",onClick:d,children:"Close"}),e[11]=d,e[12]=v):v=e[12];let b;return e[13]!==_||e[14]!==v?(b=n.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-2 bg-background",children:[_,g,v]}),e[13]=_,e[14]=v,e[15]=b):b=e[15],b}let u;e[16]!==h||e[17]!==d?(u=n.jsx(Ib,{file:h,onClose:d}),e[16]=h,e[17]=d,e[18]=u):u=e[18];let f;e[19]!==h?(f=n.jsx("div",{className:"relative min-h-0 flex-1",children:n.jsx(bm,{file:h})}),e[19]=h,e[20]=f):f=e[20];let m;return e[21]!==u||e[22]!==f?(m=n.jsxs("div",{className:"flex h-full w-full flex-col bg-background",children:[u,f]}),e[21]=u,e[22]=f,e[23]=m):m=e[23],m}function Mb(t){return{...t,main:"0"}}const Dl="home";function Lb(t){const e=K.c(5),{label:s}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=n.jsx(uh,{className:"aspect-video w-2/3 max-w-xl"}),e[0]=i):i=e[0];let r;e[1]!==s?(r=s&&n.jsx("p",{className:"text-xs text-muted-foreground",children:s}),e[1]=s,e[2]=r):r=e[2];let o;return e[3]!==r?(o=n.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-3 bg-background",children:[i,r]}),e[3]=r,e[4]=o):o=e[4],o}function Ob(t){const e=K.c(12),{path:s}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i={refetchIntervalWhenAbsent:2e3},e[0]=i):i=e[0];const r=Sm(Dl,s,i),o=wm(Dl);let a;e[1]!==s||e[2]!==o?(a=o(s),e[1]=s,e[2]=o,e[3]=a):a=e[3];const l=a;if(r.isPending||!r.data){const d=!r.isPending&&!r.data?"Waiting for the deck to sync…":void 0;let u;return e[4]!==d?(u=n.jsx(Lb,{label:d}),e[4]=d,e[5]=u):u=e[5],u}let h;e[6]!==r.data?(h=Cm(r.data),e[6]=r.data,e[7]=h):h=e[7];let c;return e[8]!==s||e[9]!==l||e[10]!==h?(c=n.jsx(km,{readUrl:l,marker:h,title:s,savePath:s}),e[8]=s,e[9]=l,e[10]=h,e[11]=c):c=e[11],c}const Al=E.lazy(()=>qt(()=>import("./project-app-view-CMCeiidr.js"),__vite__mapDeps([162,1,2,96,6,7,8,9,10,11,12,13,14,15,16,3,17,4,5,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,97,98,46,47,48,99,100,49,101,102,58,91,92,93,94,76,95,57,77,59,103,104,105,106,107,66,108,56,109,71,72,50,110,125])).then(t=>({default:t.AppViewContent})));function $b(t){const e=K.c(49),{activeTab:s,virtualMcpId:i,taskId:r,layoutTabs:o,expandedTools:a,automationTabParsed:l}=t;if(rm(s)){let v;return e[0]!==i?(v=n.jsx(_l,{virtualMcpId:i}),e[0]=i,e[1]=v):v=e[1],v}if(s==="git"){let v;return e[2]!==i?(v=n.jsx(Zv,{virtualMcpId:i}),e[2]=i,e[3]=v):v=e[3],v}if(s==="automations"){let v;return e[4]!==i?(v=n.jsx(Ab,{virtualMcpId:i}),e[4]=i,e[5]=v):v=e[5],v}if(s==="preview"){let v;return e[6]!==i?(v=n.jsx(F1,{virtualMcpId:i}),e[6]=i,e[7]=v):v=e[7],v}if(s==="content"){let v;return e[8]!==i?(v=n.jsx(Xx,{virtualMcpId:i}),e[8]=i,e[9]=v):v=e[9],v}if(l){let v;return e[10]!==s?(v=n.jsx(Eb,{tabId:s}),e[10]=s,e[11]=v):v=e[11],v}let h;e[12]!==s?(h=Qc(s),e[12]=s,e[13]=h):h=e[13];const c=h;if(c){let v;return e[14]!==c.path?(v=n.jsx(Ob,{path:c.path},c.path),e[14]=c.path,e[15]=v):v=e[15],v}let d;e[16]!==s?(d=Zc(s),e[16]=s,e[17]=d):d=e[17];const u=d;if(u){let v;return e[18]!==u.key||e[19]!==r?(v=n.jsx(Bb,{fileKey:u.key,taskId:r}),e[18]=u.key,e[19]=r,e[20]=v):v=e[20],v}let f;e[21]!==s?(f=nm(s),e[21]=s,e[22]=f):f=e[22];const m=f;if(m){let v;if(e[23]!==a||e[24]!==m.connectionId||e[25]!==m.toolName){let C;e[27]!==m.connectionId||e[28]!==m.toolName?(C=j=>j.appId===m.connectionId&&j.toolName===m.toolName,e[27]=m.connectionId,e[28]=m.toolName,e[29]=C):C=e[29],v=a.find(C),e[23]=a,e[24]=m.connectionId,e[25]=m.toolName,e[26]=v}else v=e[26];const b=v;let x;e[30]===Symbol.for("react.memo_cache_sentinel")?(x=n.jsx(Ys,{}),e[30]=x):x=e[30];const y=b?.args;let w;return e[31]!==s||e[32]!==m.connectionId||e[33]!==m.toolName||e[34]!==y?(w=n.jsx(E.Suspense,{fallback:x,children:n.jsx(Al,{connectionId:m.connectionId,toolName:m.toolName,args:y},s)}),e[31]=s,e[32]=m.connectionId,e[33]=m.toolName,e[34]=y,e[35]=w):w=e[35],w}let p;if(e[36]!==s||e[37]!==o){let v;e[39]!==s?(v=b=>b.id===s,e[39]=s,e[40]=v):v=e[40],p=o.find(v),e[36]=s,e[37]=o,e[38]=p}else p=e[38];const _=p;if(_){let v;e[41]===Symbol.for("react.memo_cache_sentinel")?(v=n.jsx(Ys,{}),e[41]=v):v=e[41];let b;return e[42]!==s||e[43]!==_.id||e[44]!==_.view.appId||e[45]!==_.view.args?(b=n.jsx(E.Suspense,{fallback:v,children:n.jsx(Al,{connectionId:_.view.appId,toolName:_.id,args:_.view.args},s)}),e[42]=s,e[43]=_.id,e[44]=_.view.appId,e[45]=_.view.args,e[46]=b):b=e[46],b}let g;return e[47]!==i?(g=n.jsx(_l,{virtualMcpId:i}),e[47]=i,e[48]=g):g=e[48],g}function zb(t){const e=K.c(14),{taskId:s,virtualMcpId:i}=t;let r;e[0]!==s||e[1]!==i?(r={virtualMcpId:i,taskId:s},e[0]=s,e[1]=i,e[2]=r):r=e[2];const{activeTab:o,layoutTabs:a,expandedTools:l,automationTabParsed:h}=Wh(r);let c;e[3]===Symbol.for("react.memo_cache_sentinel")?(c=n.jsx(Ys,{}),e[3]=c):c=e[3];let d;e[4]!==o||e[5]!==h||e[6]!==l||e[7]!==a||e[8]!==s||e[9]!==i?(d=n.jsx(E.Suspense,{fallback:c,children:n.jsx($b,{activeTab:o,virtualMcpId:i,taskId:s,layoutTabs:a,expandedTools:l,automationTabParsed:h})}),e[4]=o,e[5]=h,e[6]=l,e[7]=a,e[8]=s,e[9]=i,e[10]=d):d=e[10];let u;return e[11]!==o||e[12]!==d?(u=n.jsx(Ut,{children:d},o),e[11]=o,e[12]=d,e[13]=u):u=e[13],u}const ws="setup";function Fb(t){const e=K.c(35);let s;if(e[0]!==t.scriptTabs||e[1]!==t.scripts){let m;e[3]!==t.scriptTabs?(m=p=>!t.scriptTabs.includes(p),e[3]=t.scriptTabs,e[4]=m):m=e[4],s=t.scripts.filter(m),e[0]=t.scriptTabs,e[1]=t.scripts,e[2]=s}else s=e[2];const i=s;let r;e[5]!==t?(r=()=>{t.active===ws?t.onToggle():t.onSelectTab(ws)},e[5]=t,e[6]=r):r=e[6];const o=r,a=t.active===ws;let l;e[7]!==o||e[8]!==t.open||e[9]!==a?(l=n.jsx(Hb,{active:a,open:t.open,onClick:o}),e[7]=o,e[8]=t.open,e[9]=a,e[10]=l):l=e[10];let h;e[11]!==t?(h=t.scriptTabs.map(m=>n.jsx(Ub,{active:t.active===m,onClick:()=>t.onSelectTab(m),onClose:()=>t.onCloseScript(m),children:m},m)),e[11]=t,e[12]=h):h=e[12];let c;e[13]!==i||e[14]!==t.onAddScript?(c=n.jsx(Kb,{scripts:i,onRun:t.onAddScript}),e[13]=i,e[14]=t.onAddScript,e[15]=c):c=e[15];let d;e[16]!==l||e[17]!==h||e[18]!==c?(d=n.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1 overflow-x-auto",children:[l,h,c]}),e[16]=l,e[17]=h,e[18]=c,e[19]=d):d=e[19];let u;e[20]!==t.onRestart||e[21]!==t.onResume||e[22]!==t.onRetry||e[23]!==t.onRunActiveScript||e[24]!==t.onStart||e[25]!==t.onStop||e[26]!==t.onStopActiveScript||e[27]!==t.scriptIsKilling||e[28]!==t.scriptIsRunning||e[29]!==t.showScriptControls||e[30]!==t.status?(u=t.showScriptControls?n.jsx(Vb,{isRunning:t.scriptIsRunning,isKilling:t.scriptIsKilling,onRun:t.onRunActiveScript,onStop:t.onStopActiveScript}):n.jsx(Wb,{status:t.status,onStart:t.onStart,onStop:t.onStop,onRestart:t.onRestart,onResume:t.onResume,onRetry:t.onRetry}),e[20]=t.onRestart,e[21]=t.onResume,e[22]=t.onRetry,e[23]=t.onRunActiveScript,e[24]=t.onStart,e[25]=t.onStop,e[26]=t.onStopActiveScript,e[27]=t.scriptIsKilling,e[28]=t.scriptIsRunning,e[29]=t.showScriptControls,e[30]=t.status,e[31]=u):u=e[31];let f;return e[32]!==d||e[33]!==u?(f=n.jsxs("div",{className:"flex h-10 shrink-0 items-center gap-1 border-t border-b border-border bg-muted/60 px-3",children:[d,u]}),e[32]=d,e[33]=u,e[34]=f):f=e[34],f}function Hb(t){const e=K.c(8),{active:s,open:i,onClick:r}=t,o=s&&i,a=s&&i,l=s?"border-border bg-background font-medium text-foreground shadow-sm":"border-transparent text-muted-foreground hover:bg-background/50 hover:text-foreground";let h;e[0]!==l?(h=he("flex h-7 items-center gap-1.5 rounded-md border px-2.5 text-xs",l),e[0]=l,e[1]=h):h=e[1];let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c=n.jsx(Jf,{className:"size-3.5"}),e[2]=c):c=e[2];let d;return e[3]!==r||e[4]!==o||e[5]!==a||e[6]!==h?(d=n.jsxs("button",{type:"button","aria-pressed":o,"aria-expanded":a,onClick:r,className:h,children:[c,"sandbox"]}),e[3]=r,e[4]=o,e[5]=a,e[6]=h,e[7]=d):d=e[7],d}function Wb(t){const e=K.c(24),{status:s,onStart:i,onStop:r,onRestart:o,onResume:a,onRetry:l}=t;if(s==="idle"&&i){let h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h=n.jsx(Vs,{className:"size-3.5"}),e[0]=h):h=e[0];let c;return e[1]!==i?(c=n.jsxs(re,{variant:"outline",size:"sm",onClick:i,children:[h," Start"]}),e[1]=i,e[2]=c):c=e[2],c}if(s==="suspended"&&a){let h;e[3]===Symbol.for("react.memo_cache_sentinel")?(h=n.jsx(Vs,{className:"size-3.5"}),e[3]=h):h=e[3];let c;return e[4]!==a?(c=n.jsxs(re,{variant:"outline",size:"sm",onClick:a,children:[h," Resume"]}),e[4]=a,e[5]=c):c=e[5],c}if(s==="errored"&&l){let h;e[6]===Symbol.for("react.memo_cache_sentinel")?(h=n.jsx(Bi,{className:"size-3.5"}),e[6]=h):h=e[6];let c;return e[7]!==l?(c=n.jsxs(re,{variant:"outline",size:"sm",onClick:l,children:[h," Retry"]}),e[7]=l,e[8]=c):c=e[8],c}if(s==="starting"||s==="running"){const h=s==="running"&&!!o,c=h?"rounded-r-none border-r-0":void 0;let d;e[9]!==c?(d=he(c),e[9]=c,e[10]=d):d=e[10];let u;e[11]===Symbol.for("react.memo_cache_sentinel")?(u=n.jsx(Yc,{className:"size-3.5"}),e[11]=u):u=e[11];let f;e[12]!==r||e[13]!==d?(f=n.jsx(Ee,{asChild:!0,children:n.jsxs(re,{variant:"outline",size:"sm",onClick:r,className:d,children:[u," Stop"]})}),e[12]=r,e[13]=d,e[14]=f):f=e[14];let m;e[15]===Symbol.for("react.memo_cache_sentinel")?(m=n.jsx(Te,{children:"Stop sandbox"}),e[15]=m):m=e[15];let p;e[16]!==f?(p=n.jsxs(Re,{children:[f,m]}),e[16]=f,e[17]=p):p=e[17];let _;e[18]!==o||e[19]!==h?(_=h&&n.jsxs(Ds,{children:[n.jsx(As,{asChild:!0,children:n.jsx(re,{variant:"outline",size:"sm",className:"rounded-l-none px-1",children:n.jsx(Es,{className:"size-3"})})}),n.jsx(Is,{align:"end",children:n.jsxs(He,{onClick:o,children:[n.jsx(Bi,{className:"size-3.5"})," Restart"]})})]}),e[18]=o,e[19]=h,e[20]=_):_=e[20];let g;return e[21]!==p||e[22]!==_?(g=n.jsxs("div",{className:"flex items-center",children:[p,_]}),e[21]=p,e[22]=_,e[23]=g):g=e[23],g}return null}function Ub(t){const e=K.c(16),{active:s,onClick:i,onClose:r,children:o}=t,a=s?"border-border bg-background shadow-sm":"border-transparent hover:bg-background/50";let l;e[0]!==a?(l=he("flex h-7 items-center rounded-md border text-xs",a),e[0]=a,e[1]=l):l=e[1];const h=r?"pl-2.5 pr-1":"px-2.5",c=s?"font-medium text-foreground":"text-muted-foreground hover:text-foreground";let d;e[2]!==h||e[3]!==c?(d=he("flex h-full items-center",h,c),e[2]=h,e[3]=c,e[4]=d):d=e[4];let u;e[5]!==o||e[6]!==i||e[7]!==d?(u=n.jsx("button",{type:"button",onClick:i,className:d,children:o}),e[5]=o,e[6]=i,e[7]=d,e[8]=u):u=e[8];let f;e[9]!==o||e[10]!==r?(f=r&&n.jsx("button",{type:"button","aria-label":`Close ${o}`,onClick:r,className:"pr-1.5 text-muted-foreground hover:text-foreground",children:n.jsx(pp,{className:"size-3"})}),e[9]=o,e[10]=r,e[11]=f):f=e[11];let m;return e[12]!==l||e[13]!==u||e[14]!==f?(m=n.jsxs("div",{className:l,children:[u,f]}),e[12]=l,e[13]=u,e[14]=f,e[15]=m):m=e[15],m}function Kb(t){const e=K.c(10),{scripts:s,onRun:i}=t,[r,o]=E.useState(!1);let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=n.jsxs(Re,{children:[n.jsx(Ee,{asChild:!0,children:n.jsx(Rs,{asChild:!0,children:n.jsx(re,{variant:"ghost",size:"sm","aria-label":"Run script",children:n.jsx(xt,{className:"size-3.5"})})})}),n.jsx(Te,{children:"Run script"})]}),e[0]=a):a=e[0];let l;e[1]===Symbol.for("react.memo_cache_sentinel")?(l=n.jsx("div",{className:"px-2 py-1 text-[10px] uppercase tracking-wide text-muted-foreground",children:"run a script"}),e[1]=l):l=e[1];let h;e[2]!==i||e[3]!==s?(h=s.length===0?n.jsx("div",{className:"px-2 py-2 text-xs text-muted-foreground",children:"No scripts found"}):s.map(u=>n.jsxs("button",{type:"button",onClick:()=>{o(!1),i(u)},className:"w-full rounded-md px-2 py-1.5 text-left text-xs hover:bg-accent",children:["▸ ",u]},u)),e[2]=i,e[3]=s,e[4]=h):h=e[4];let c;e[5]!==h?(c=n.jsxs(Ps,{align:"start",className:"p-1 w-56",children:[l,h]}),e[5]=h,e[6]=c):c=e[6];let d;return e[7]!==r||e[8]!==c?(d=n.jsxs(Ts,{open:r,onOpenChange:o,children:[a,c]}),e[7]=r,e[8]=c,e[9]=d):d=e[9],d}function Vb(t){const e=K.c(13),{isRunning:s,isKilling:i,onRun:r,onStop:o}=t;if(i){let d;return e[0]===Symbol.for("react.memo_cache_sentinel")?(d=n.jsxs(re,{variant:"outline",size:"sm",disabled:!0,children:[n.jsx(Ce,{className:"size-3.5 animate-spin"})," Stopping…"]}),e[0]=d):d=e[0],d}if(!s){let d;e[1]===Symbol.for("react.memo_cache_sentinel")?(d=n.jsx(Vs,{className:"size-3.5"}),e[1]=d):d=e[1];let u;e[2]!==r?(u=n.jsx(Ee,{asChild:!0,children:n.jsxs(re,{variant:"outline",size:"sm",onClick:r,children:[d," Run"]})}),e[2]=r,e[3]=u):u=e[3];let f;e[4]===Symbol.for("react.memo_cache_sentinel")?(f=n.jsx(Te,{children:"Start process"}),e[4]=f):f=e[4];let m;return e[5]!==u?(m=n.jsxs(Re,{children:[u,f]}),e[5]=u,e[6]=m):m=e[6],m}let a;e[7]===Symbol.for("react.memo_cache_sentinel")?(a=n.jsx(Yc,{className:"size-3.5"}),e[7]=a):a=e[7];let l;e[8]!==o?(l=n.jsx(Ee,{asChild:!0,children:n.jsxs(re,{variant:"outline",size:"sm",onClick:o,children:[a," Stop"]})}),e[8]=o,e[9]=l):l=e[9];let h;e[10]===Symbol.for("react.memo_cache_sentinel")?(h=n.jsx(Te,{children:"Stop process"}),e[10]=h):h=e[10];let c;return e[11]!==l?(c=n.jsxs(Re,{children:[l,h]}),e[11]=l,e[12]=c):c=e[12],c}var Td=Object.defineProperty,qb=Object.getOwnPropertyDescriptor,Gb=(t,e)=>{for(var s in e)Td(t,s,{get:e[s],enumerable:!0})},ze=(t,e,s,i)=>{for(var r=i>1?void 0:i?qb(e,s):e,o=t.length-1,a;o>=0;o--)(a=t[o])&&(r=(i?a(e,s,r):a(r))||r);return i&&r&&Td(e,s,r),r},de=(t,e)=>(s,i)=>e(s,i,t),Il="Terminal input",to={get:()=>Il,set:t=>Il=t},Bl="Too much output to announce, navigate to rows manually to read",so={get:()=>Bl,set:t=>Bl=t};function Yb(t){return t.replace(/\r?\n/g,"\r")}function Xb(t,e){return e?"\x1B[200~"+t+"\x1B[201~":t}function Jb(t,e){t.clipboardData&&t.clipboardData.setData("text/plain",e.selectionText),t.preventDefault()}function Zb(t,e,s,i){if(t.stopPropagation(),t.clipboardData){let r=t.clipboardData.getData("text/plain");Rd(r,e,s,i)}}function Rd(t,e,s,i){t=Yb(t),t=Xb(t,s.decPrivateModes.bracketedPasteMode&&i.rawOptions.ignoreBracketedPasteMode!==!0),s.triggerDataEvent(t,!0),e.value=""}function Pd(t,e,s){let i=s.getBoundingClientRect(),r=t.clientX-i.left-10,o=t.clientY-i.top-10;e.style.width="20px",e.style.height="20px",e.style.left=`${r}px`,e.style.top=`${o}px`,e.style.zIndex="1000",e.focus()}function Ml(t,e,s,i,r){Pd(t,e,s),r&&i.rightClickSelect(t),e.value=i.selectionText,e.select()}function us(t){return t>65535?(t-=65536,String.fromCharCode((t>>10)+55296)+String.fromCharCode(t%1024+56320)):String.fromCharCode(t)}function cn(t,e=0,s=t.length){let i="";for(let r=e;r<s;++r){let o=t[r];o>65535?(o-=65536,i+=String.fromCharCode((o>>10)+55296)+String.fromCharCode(o%1024+56320)):i+=String.fromCharCode(o)}return i}var Qb=class{constructor(){this._interim=0}clear(){this._interim=0}decode(t,e){let s=t.length;if(!s)return 0;let i=0,r=0;if(this._interim){let o=t.charCodeAt(r++);56320<=o&&o<=57343?e[i++]=(this._interim-55296)*1024+o-56320+65536:(e[i++]=this._interim,e[i++]=o),this._interim=0}for(let o=r;o<s;++o){let a=t.charCodeAt(o);if(55296<=a&&a<=56319){if(++o>=s)return this._interim=a,i;let l=t.charCodeAt(o);56320<=l&&l<=57343?e[i++]=(a-55296)*1024+l-56320+65536:(e[i++]=a,e[i++]=l);continue}a!==65279&&(e[i++]=a)}return i}},ey=class{constructor(){this.interim=new Uint8Array(3)}clear(){this.interim.fill(0)}decode(t,e){let s=t.length;if(!s)return 0;let i=0,r,o,a,l,h=0,c=0;if(this.interim[0]){let f=!1,m=this.interim[0];m&=(m&224)===192?31:(m&240)===224?15:7;let p=0,_;for(;(_=this.interim[++p]&63)&&p<4;)m<<=6,m|=_;let g=(this.interim[0]&224)===192?2:(this.interim[0]&240)===224?3:4,v=g-p;for(;c<v;){if(c>=s)return 0;if(_=t[c++],(_&192)!==128){c--,f=!0;break}else this.interim[p++]=_,m<<=6,m|=_&63}f||(g===2?m<128?c--:e[i++]=m:g===3?m<2048||m>=55296&&m<=57343||m===65279||(e[i++]=m):m<65536||m>1114111||(e[i++]=m)),this.interim.fill(0)}let d=s-4,u=c;for(;u<s;){for(;u<d&&!((r=t[u])&128)&&!((o=t[u+1])&128)&&!((a=t[u+2])&128)&&!((l=t[u+3])&128);)e[i++]=r,e[i++]=o,e[i++]=a,e[i++]=l,u+=4;if(r=t[u++],r<128)e[i++]=r;else if((r&224)===192){if(u>=s)return this.interim[0]=r,i;if(o=t[u++],(o&192)!==128){u--;continue}if(h=(r&31)<<6|o&63,h<128){u--;continue}e[i++]=h}else if((r&240)===224){if(u>=s)return this.interim[0]=r,i;if(o=t[u++],(o&192)!==128){u--;continue}if(u>=s)return this.interim[0]=r,this.interim[1]=o,i;if(a=t[u++],(a&192)!==128){u--;continue}if(h=(r&15)<<12|(o&63)<<6|a&63,h<2048||h>=55296&&h<=57343||h===65279)continue;e[i++]=h}else if((r&248)===240){if(u>=s)return this.interim[0]=r,i;if(o=t[u++],(o&192)!==128){u--;continue}if(u>=s)return this.interim[0]=r,this.interim[1]=o,i;if(a=t[u++],(a&192)!==128){u--;continue}if(u>=s)return this.interim[0]=r,this.interim[1]=o,this.interim[2]=a,i;if(l=t[u++],(l&192)!==128){u--;continue}if(h=(r&7)<<18|(o&63)<<12|(a&63)<<6|l&63,h<65536||h>1114111)continue;e[i++]=h}}return i}},Dd="",fs=" ",Zi=class Ad{constructor(){this.fg=0,this.bg=0,this.extended=new Ur}static toColorRGB(e){return[e>>>16&255,e>>>8&255,e&255]}static fromColorRGB(e){return(e[0]&255)<<16|(e[1]&255)<<8|e[2]&255}clone(){let e=new Ad;return e.fg=this.fg,e.bg=this.bg,e.extended=this.extended.clone(),e}isInverse(){return this.fg&67108864}isBold(){return this.fg&134217728}isUnderline(){return this.hasExtendedAttrs()&&this.extended.underlineStyle!==0?1:this.fg&268435456}isBlink(){return this.fg&536870912}isInvisible(){return this.fg&1073741824}isItalic(){return this.bg&67108864}isDim(){return this.bg&134217728}isStrikethrough(){return this.fg&2147483648}isProtected(){return this.bg&536870912}isOverline(){return this.bg&1073741824}getFgColorMode(){return this.fg&50331648}getBgColorMode(){return this.bg&50331648}isFgRGB(){return(this.fg&50331648)===50331648}isBgRGB(){return(this.bg&50331648)===50331648}isFgPalette(){return(this.fg&50331648)===16777216||(this.fg&50331648)===33554432}isBgPalette(){return(this.bg&50331648)===16777216||(this.bg&50331648)===33554432}isFgDefault(){return(this.fg&50331648)===0}isBgDefault(){return(this.bg&50331648)===0}isAttributeDefault(){return this.fg===0&&this.bg===0}getFgColor(){switch(this.fg&50331648){case 16777216:case 33554432:return this.fg&255;case 50331648:return this.fg&16777215;default:return-1}}getBgColor(){switch(this.bg&50331648){case 16777216:case 33554432:return this.bg&255;case 50331648:return this.bg&16777215;default:return-1}}hasExtendedAttrs(){return this.bg&268435456}updateExtended(){this.extended.isEmpty()?this.bg&=-268435457:this.bg|=268435456}getUnderlineColor(){if(this.bg&268435456&&~this.extended.underlineColor)switch(this.extended.underlineColor&50331648){case 16777216:case 33554432:return this.extended.underlineColor&255;case 50331648:return this.extended.underlineColor&16777215;default:return this.getFgColor()}return this.getFgColor()}getUnderlineColorMode(){return this.bg&268435456&&~this.extended.underlineColor?this.extended.underlineColor&50331648:this.getFgColorMode()}isUnderlineColorRGB(){return this.bg&268435456&&~this.extended.underlineColor?(this.extended.underlineColor&50331648)===50331648:this.isFgRGB()}isUnderlineColorPalette(){return this.bg&268435456&&~this.extended.underlineColor?(this.extended.underlineColor&50331648)===16777216||(this.extended.underlineColor&50331648)===33554432:this.isFgPalette()}isUnderlineColorDefault(){return this.bg&268435456&&~this.extended.underlineColor?(this.extended.underlineColor&50331648)===0:this.isFgDefault()}getUnderlineStyle(){return this.fg&268435456?this.bg&268435456?this.extended.underlineStyle:1:0}getUnderlineVariantOffset(){return this.extended.underlineVariantOffset}},Ur=class Id{constructor(e=0,s=0){this._ext=0,this._urlId=0,this._ext=e,this._urlId=s}get ext(){return this._urlId?this._ext&-469762049|this.underlineStyle<<26:this._ext}set ext(e){this._ext=e}get underlineStyle(){return this._urlId?5:(this._ext&469762048)>>26}set underlineStyle(e){this._ext&=-469762049,this._ext|=e<<26&469762048}get underlineColor(){return this._ext&67108863}set underlineColor(e){this._ext&=-67108864,this._ext|=e&67108863}get urlId(){return this._urlId}set urlId(e){this._urlId=e}get underlineVariantOffset(){let e=(this._ext&3758096384)>>29;return e<0?e^4294967288:e}set underlineVariantOffset(e){this._ext&=536870911,this._ext|=e<<29&3758096384}clone(){return new Id(this._ext,this._urlId)}isEmpty(){return this.underlineStyle===0&&this._urlId===0}},Nt=class Bd extends Zi{constructor(){super(...arguments),this.content=0,this.fg=0,this.bg=0,this.extended=new Ur,this.combinedData=""}static fromCharData(e){let s=new Bd;return s.setFromCharData(e),s}isCombined(){return this.content&2097152}getWidth(){return this.content>>22}getChars(){return this.content&2097152?this.combinedData:this.content&2097151?us(this.content&2097151):""}getCode(){return this.isCombined()?this.combinedData.charCodeAt(this.combinedData.length-1):this.content&2097151}setFromCharData(e){this.fg=e[0],this.bg=0;let s=!1;if(e[1].length>2)s=!0;else if(e[1].length===2){let i=e[1].charCodeAt(0);if(55296<=i&&i<=56319){let r=e[1].charCodeAt(1);56320<=r&&r<=57343?this.content=(i-55296)*1024+r-56320+65536|e[2]<<22:s=!0}else s=!0}else this.content=e[1].charCodeAt(0)|e[2]<<22;s&&(this.combinedData=e[1],this.content=2097152|e[2]<<22)}getAsCharData(){return[this.fg,this.getChars(),this.getWidth(),this.getCode()]}},Ll="di$target",io="di$dependencies",jn=new Map;function ty(t){return t[io]||[]}function Qe(t){if(jn.has(t))return jn.get(t);let e=function(s,i,r){if(arguments.length!==3)throw new Error("@IServiceName-decorator can only be used to decorate a parameter");sy(e,s,r)};return e._id=t,jn.set(t,e),e}function sy(t,e,s){e[Ll]===e?e[io].push({id:t,index:s}):(e[io]=[{id:t,index:s}],e[Ll]=e)}var ht=Qe("BufferService"),Md=Qe("CoreMouseService"),Ls=Qe("CoreService"),iy=Qe("CharsetService"),Ta=Qe("InstantiationService"),Ld=Qe("LogService"),dt=Qe("OptionsService"),Od=Qe("OscLinkService"),ry=Qe("UnicodeService"),Qi=Qe("DecorationService"),ro=class{constructor(t,e,s){this._bufferService=t,this._optionsService=e,this._oscLinkService=s}provideLinks(t,e){let s=this._bufferService.buffer.lines.get(t-1);if(!s){e(void 0);return}let i=[],r=this._optionsService.rawOptions.linkHandler,o=new Nt,a=s.getTrimmedLength(),l=-1,h=-1,c=!1;for(let d=0;d<a;d++)if(!(h===-1&&!s.hasContent(d))){if(s.loadCell(d,o),o.hasExtendedAttrs()&&o.extended.urlId)if(h===-1){h=d,l=o.extended.urlId;continue}else c=o.extended.urlId!==l;else h!==-1&&(c=!0);if(c||h!==-1&&d===a-1){let u=this._oscLinkService.getLinkData(l)?.uri;if(u){let f={start:{x:h+1,y:t},end:{x:d+(!c&&d===a-1?1:0),y:t}},m=!1;if(!r?.allowNonHttpProtocols)try{let p=new URL(u);["http:","https:"].includes(p.protocol)||(m=!0)}catch{m=!0}m||i.push({text:u,range:f,activate:(p,_)=>r?r.activate(p,_,f):ny(p,_),hover:(p,_)=>r?.hover?.(p,_,f),leave:(p,_)=>r?.leave?.(p,_,f)})}c=!1,o.hasExtendedAttrs()&&o.extended.urlId?(h=d,l=o.extended.urlId):(h=-1,l=-1)}}e(i)}};ro=ze([de(0,ht),de(1,dt),de(2,Od)],ro);function ny(t,e){if(confirm(`Do you want to navigate to ${e}?
|
|
295
295
|
|
|
296
296
|
WARNING: This link could potentially be dangerous`)){let s=window.open();if(s){try{s.opener=null}catch{}s.location.href=e}else console.warn("Opening link blocked as opener could not be cleared")}}var hn=Qe("CharSizeService"),ns=Qe("CoreBrowserService"),Ra=Qe("MouseService"),os=Qe("RenderService"),oy=Qe("SelectionService"),$d=Qe("CharacterJoinerService"),ci=Qe("ThemeService"),zd=Qe("LinkProviderService"),ay=class{constructor(){this.listeners=[],this.unexpectedErrorHandler=function(t){setTimeout(()=>{throw t.stack?Ol.isErrorNoTelemetry(t)?new Ol(t.message+`
|
|
297
297
|
|
|
@@ -306,6 +306,6 @@ WARNING: This link could potentially be dangerous`)){let s=window.open();if(s){t
|
|
|
306
306
|
`)}clearSelection(){this._model.clearSelection(),this._removeMouseDownListeners(),this.refresh(),this._onSelectionChange.fire()}refresh(t){this._refreshAnimationFrame||(this._refreshAnimationFrame=this._coreBrowserService.window.requestAnimationFrame(()=>this._refresh())),Oa&&t&&this.selectionText.length&&this._onLinuxMouseSelection.fire(this.selectionText)}_refresh(){this._refreshAnimationFrame=void 0,this._onRedrawRequest.fire({start:this._model.finalSelectionStart,end:this._model.finalSelectionEnd,columnSelectMode:this._activeSelectionMode===3})}_isClickInSelection(t){let e=this._getMouseBufferCoords(t),s=this._model.finalSelectionStart,i=this._model.finalSelectionEnd;return!s||!i||!e?!1:this._areCoordsInSelection(e,s,i)}isCellInSelection(t,e){let s=this._model.finalSelectionStart,i=this._model.finalSelectionEnd;return!s||!i?!1:this._areCoordsInSelection([t,e],s,i)}_areCoordsInSelection(t,e,s){return t[1]>e[1]&&t[1]<s[1]||e[1]===s[1]&&t[1]===e[1]&&t[0]>=e[0]&&t[0]<s[0]||e[1]<s[1]&&t[1]===s[1]&&t[0]<s[0]||e[1]<s[1]&&t[1]===e[1]&&t[0]>=e[0]}_selectWordAtCursor(t,e){let s=this._linkifier.currentLink?.link?.range;if(s)return this._model.selectionStart=[s.start.x-1,s.start.y-1],this._model.selectionStartLength=ic(s,this._bufferService.cols),this._model.selectionEnd=void 0,!0;let i=this._getMouseBufferCoords(t);return i?(this._selectWordAt(i,e),this._model.selectionEnd=void 0,!0):!1}selectAll(){this._model.isSelectAllActive=!0,this.refresh(),this._onSelectionChange.fire()}selectLines(t,e){this._model.clearSelection(),t=Math.max(t,0),e=Math.min(e,this._bufferService.buffer.lines.length-1),this._model.selectionStart=[0,t],this._model.selectionEnd=[this._bufferService.cols,e],this.refresh(),this._onSelectionChange.fire()}_handleTrim(t){this._model.handleTrim(t)&&this.refresh()}_getMouseBufferCoords(t){let e=this._mouseService.getCoords(t,this._screenElement,this._bufferService.cols,this._bufferService.rows,!0);if(e)return e[0]--,e[1]--,e[1]+=this._bufferService.buffer.ydisp,e}_getMouseEventScrollAmount(t){let e=La(this._coreBrowserService.window,t,this._screenElement)[1],s=this._renderService.dimensions.css.canvas.height;return e>=0&&e<=s?0:(e>s&&(e-=s),e=Math.min(Math.max(e,-Dn),Dn),e/=Dn,e/Math.abs(e)+Math.round(e*(tS-1)))}shouldForceSelection(t){return qr?t.altKey&&this._optionsService.rawOptions.macOptionClickForcesSelection:t.shiftKey}handleMouseDown(t){if(this._mouseDownTimeStamp=t.timeStamp,!(t.button===2&&this.hasSelection)&&t.button===0){if(!this._enabled){if(!this.shouldForceSelection(t))return;t.stopPropagation()}t.preventDefault(),this._dragScrollAmount=0,this._enabled&&t.shiftKey?this._handleIncrementalClick(t):t.detail===1?this._handleSingleClick(t):t.detail===2?this._handleDoubleClick(t):t.detail===3&&this._handleTripleClick(t),this._addMouseDownListeners(),this.refresh(!0)}}_addMouseDownListeners(){this._screenElement.ownerDocument&&(this._screenElement.ownerDocument.addEventListener("mousemove",this._mouseMoveListener),this._screenElement.ownerDocument.addEventListener("mouseup",this._mouseUpListener)),this._dragScrollIntervalTimer=this._coreBrowserService.window.setInterval(()=>this._dragScroll(),sS)}_removeMouseDownListeners(){this._screenElement.ownerDocument&&(this._screenElement.ownerDocument.removeEventListener("mousemove",this._mouseMoveListener),this._screenElement.ownerDocument.removeEventListener("mouseup",this._mouseUpListener)),this._coreBrowserService.window.clearInterval(this._dragScrollIntervalTimer),this._dragScrollIntervalTimer=void 0}_handleIncrementalClick(t){this._model.selectionStart&&(this._model.selectionEnd=this._getMouseBufferCoords(t))}_handleSingleClick(t){if(this._model.selectionStartLength=0,this._model.isSelectAllActive=!1,this._activeSelectionMode=this.shouldColumnSelect(t)?3:0,this._model.selectionStart=this._getMouseBufferCoords(t),!this._model.selectionStart)return;this._model.selectionEnd=void 0;let e=this._bufferService.buffer.lines.get(this._model.selectionStart[1]);e&&e.length!==this._model.selectionStart[0]&&e.hasWidth(this._model.selectionStart[0])===0&&this._model.selectionStart[0]++}_handleDoubleClick(t){this._selectWordAtCursor(t,!0)&&(this._activeSelectionMode=1)}_handleTripleClick(t){let e=this._getMouseBufferCoords(t);e&&(this._activeSelectionMode=2,this._selectLineAt(e[1]))}shouldColumnSelect(t){return t.altKey&&!(qr&&this._optionsService.rawOptions.macOptionClickForcesSelection)}_handleMouseMove(t){if(t.stopImmediatePropagation(),!this._model.selectionStart)return;let e=this._model.selectionEnd?[this._model.selectionEnd[0],this._model.selectionEnd[1]]:null;if(this._model.selectionEnd=this._getMouseBufferCoords(t),!this._model.selectionEnd){this.refresh(!0);return}this._activeSelectionMode===2?this._model.selectionEnd[1]<this._model.selectionStart[1]?this._model.selectionEnd[0]=0:this._model.selectionEnd[0]=this._bufferService.cols:this._activeSelectionMode===1&&this._selectToWordAt(this._model.selectionEnd),this._dragScrollAmount=this._getMouseEventScrollAmount(t),this._activeSelectionMode!==3&&(this._dragScrollAmount>0?this._model.selectionEnd[0]=this._bufferService.cols:this._dragScrollAmount<0&&(this._model.selectionEnd[0]=0));let s=this._bufferService.buffer;if(this._model.selectionEnd[1]<s.lines.length){let i=s.lines.get(this._model.selectionEnd[1]);i&&i.hasWidth(this._model.selectionEnd[0])===0&&this._model.selectionEnd[0]<this._bufferService.cols&&this._model.selectionEnd[0]++}(!e||e[0]!==this._model.selectionEnd[0]||e[1]!==this._model.selectionEnd[1])&&this.refresh(!0)}_dragScroll(){if(!(!this._model.selectionEnd||!this._model.selectionStart)&&this._dragScrollAmount){this._onRequestScrollLines.fire({amount:this._dragScrollAmount,suppressScrollEvent:!1});let t=this._bufferService.buffer;this._dragScrollAmount>0?(this._activeSelectionMode!==3&&(this._model.selectionEnd[0]=this._bufferService.cols),this._model.selectionEnd[1]=Math.min(t.ydisp+this._bufferService.rows,t.lines.length-1)):(this._activeSelectionMode!==3&&(this._model.selectionEnd[0]=0),this._model.selectionEnd[1]=t.ydisp),this.refresh()}}_handleMouseUp(t){let e=t.timeStamp-this._mouseDownTimeStamp;if(this._removeMouseDownListeners(),this.selectionText.length<=1&&e<iS&&t.altKey&&this._optionsService.rawOptions.altClickMovesCursor){if(this._bufferService.buffer.ybase===this._bufferService.buffer.ydisp){let s=this._mouseService.getCoords(t,this._element,this._bufferService.cols,this._bufferService.rows,!1);if(s&&s[0]!==void 0&&s[1]!==void 0){let i=q0(s[0]-1,s[1]-1,this._bufferService,this._coreService.decPrivateModes.applicationCursorKeys);this._coreService.triggerDataEvent(i,!0)}}}else this._fireEventIfSelectionChanged()}_fireEventIfSelectionChanged(){let t=this._model.finalSelectionStart,e=this._model.finalSelectionEnd,s=!!t&&!!e&&(t[0]!==e[0]||t[1]!==e[1]);if(!s){this._oldHasSelection&&this._fireOnSelectionChange(t,e,s);return}!t||!e||(!this._oldSelectionStart||!this._oldSelectionEnd||t[0]!==this._oldSelectionStart[0]||t[1]!==this._oldSelectionStart[1]||e[0]!==this._oldSelectionEnd[0]||e[1]!==this._oldSelectionEnd[1])&&this._fireOnSelectionChange(t,e,s)}_fireOnSelectionChange(t,e,s){this._oldSelectionStart=t,this._oldSelectionEnd=e,this._oldHasSelection=s,this._onSelectionChange.fire()}_handleBufferActivate(t){this.clearSelection(),this._trimListener.dispose(),this._trimListener=t.activeBuffer.lines.onTrim(e=>this._handleTrim(e))}_convertViewportColToCharacterIndex(t,e){let s=e;for(let i=0;e>=i;i++){let r=t.loadCell(i,this._workCell).getChars().length;this._workCell.getWidth()===0?s--:r>1&&e!==i&&(s+=r-1)}return s}setSelection(t,e,s){this._model.clearSelection(),this._removeMouseDownListeners(),this._model.selectionStart=[t,e],this._model.selectionStartLength=s,this.refresh(),this._fireEventIfSelectionChanged()}rightClickSelect(t){this._isClickInSelection(t)||(this._selectWordAtCursor(t,!1)&&this.refresh(!0),this._fireEventIfSelectionChanged())}_getWordAt(t,e,s=!0,i=!0){if(t[0]>=this._bufferService.cols)return;let r=this._bufferService.buffer,o=r.lines.get(t[1]);if(!o)return;let a=r.translateBufferLineToString(t[1],!1),l=this._convertViewportColToCharacterIndex(o,t[0]),h=l,c=t[0]-l,d=0,u=0,f=0,m=0;if(a.charAt(l)===" "){for(;l>0&&a.charAt(l-1)===" ";)l--;for(;h<a.length&&a.charAt(h+1)===" ";)h++}else{let g=t[0],v=t[0];o.getWidth(g)===0&&(d++,g--),o.getWidth(v)===2&&(u++,v++);let b=o.getString(v).length;for(b>1&&(m+=b-1,h+=b-1);g>0&&l>0&&!this._isCharWordSeparator(o.loadCell(g-1,this._workCell));){o.loadCell(g-1,this._workCell);let x=this._workCell.getChars().length;this._workCell.getWidth()===0?(d++,g--):x>1&&(f+=x-1,l-=x-1),l--,g--}for(;v<o.length&&h+1<a.length&&!this._isCharWordSeparator(o.loadCell(v+1,this._workCell));){o.loadCell(v+1,this._workCell);let x=this._workCell.getChars().length;this._workCell.getWidth()===2?(u++,v++):x>1&&(m+=x-1,h+=x-1),h++,v++}}h++;let p=l+c-d+f,_=Math.min(this._bufferService.cols,h-l+d+u-f-m);if(!(!e&&a.slice(l,h).trim()==="")){if(s&&p===0&&o.getCodePoint(0)!==32){let g=r.lines.get(t[1]-1);if(g&&o.isWrapped&&g.getCodePoint(this._bufferService.cols-1)!==32){let v=this._getWordAt([this._bufferService.cols-1,t[1]-1],!1,!0,!1);if(v){let b=this._bufferService.cols-v.start;p-=b,_+=b}}}if(i&&p+_===this._bufferService.cols&&o.getCodePoint(this._bufferService.cols-1)!==32){let g=r.lines.get(t[1]+1);if(g?.isWrapped&&g.getCodePoint(0)!==32){let v=this._getWordAt([0,t[1]+1],!1,!1,!0);v&&(_+=v.length)}}return{start:p,length:_}}}_selectWordAt(t,e){let s=this._getWordAt(t,e);if(s){for(;s.start<0;)s.start+=this._bufferService.cols,t[1]--;this._model.selectionStart=[s.start,t[1]],this._model.selectionStartLength=s.length}}_selectToWordAt(t){let e=this._getWordAt(t,!0);if(e){let s=t[1];for(;e.start<0;)e.start+=this._bufferService.cols,s--;if(!this._model.areSelectionValuesReversed())for(;e.start+e.length>this._bufferService.cols;)e.length-=this._bufferService.cols,s++;this._model.selectionEnd=[this._model.areSelectionValuesReversed()?e.start:e.start+e.length,s]}}_isCharWordSeparator(t){return t.getWidth()===0?!1:this._optionsService.rawOptions.wordSeparator.indexOf(t.getChars())>=0}_selectLineAt(t){let e=this._bufferService.buffer.getWrappedRangeForLine(t),s={start:{x:0,y:e.first},end:{x:this._bufferService.cols-1,y:e.last}};this._model.selectionStart=[0,e.first],this._model.selectionEnd=void 0,this._model.selectionStartLength=ic(s,this._bufferService.cols)}};To=ze([de(3,ht),de(4,Ls),de(5,Ra),de(6,dt),de(7,os),de(8,ns)],To);var rc=class{constructor(){this._data={}}set(t,e,s){this._data[t]||(this._data[t]={}),this._data[t][e]=s}get(t,e){return this._data[t]?this._data[t][e]:void 0}clear(){this._data={}}},nc=class{constructor(){this._color=new rc,this._css=new rc}setCss(t,e,s){this._css.set(t,e,s)}getCss(t,e){return this._css.get(t,e)}setColor(t,e,s){this._color.set(t,e,s)}getColor(t,e){return this._color.get(t,e)}clear(){this._color.clear(),this._css.clear()}},Ke=Object.freeze((()=>{let t=[Le.toColor("#2e3436"),Le.toColor("#cc0000"),Le.toColor("#4e9a06"),Le.toColor("#c4a000"),Le.toColor("#3465a4"),Le.toColor("#75507b"),Le.toColor("#06989a"),Le.toColor("#d3d7cf"),Le.toColor("#555753"),Le.toColor("#ef2929"),Le.toColor("#8ae234"),Le.toColor("#fce94f"),Le.toColor("#729fcf"),Le.toColor("#ad7fa8"),Le.toColor("#34e2e2"),Le.toColor("#eeeeec")],e=[0,95,135,175,215,255];for(let s=0;s<216;s++){let i=e[s/36%6|0],r=e[s/6%6|0],o=e[s%6];t.push({css:Ue.toCss(i,r,o),rgba:Ue.toRgba(i,r,o)})}for(let s=0;s<24;s++){let i=8+s*10;t.push({css:Ue.toCss(i,i,i),rgba:Ue.toRgba(i,i,i)})}return t})()),vs=Le.toColor("#ffffff"),Ci=Le.toColor("#000000"),oc=Le.toColor("#ffffff"),ac=Ci,_i={css:"rgba(255, 255, 255, 0.3)",rgba:4294967117},oS=vs,Ro=class extends ye{constructor(t){super(),this._optionsService=t,this._contrastCache=new nc,this._halfContrastCache=new nc,this._onChangeColors=this._register(new ae),this.onChangeColors=this._onChangeColors.event,this._colors={foreground:vs,background:Ci,cursor:oc,cursorAccent:ac,selectionForeground:void 0,selectionBackgroundTransparent:_i,selectionBackgroundOpaque:Ae.blend(Ci,_i),selectionInactiveBackgroundTransparent:_i,selectionInactiveBackgroundOpaque:Ae.blend(Ci,_i),scrollbarSliderBackground:Ae.opacity(vs,.2),scrollbarSliderHoverBackground:Ae.opacity(vs,.4),scrollbarSliderActiveBackground:Ae.opacity(vs,.5),overviewRulerBorder:vs,ansi:Ke.slice(),contrastCache:this._contrastCache,halfContrastCache:this._halfContrastCache},this._updateRestoreColors(),this._setTheme(this._optionsService.rawOptions.theme),this._register(this._optionsService.onSpecificOptionChange("minimumContrastRatio",()=>this._contrastCache.clear())),this._register(this._optionsService.onSpecificOptionChange("theme",()=>this._setTheme(this._optionsService.rawOptions.theme)))}get colors(){return this._colors}_setTheme(t={}){let e=this._colors;if(e.foreground=Ne(t.foreground,vs),e.background=Ne(t.background,Ci),e.cursor=Ae.blend(e.background,Ne(t.cursor,oc)),e.cursorAccent=Ae.blend(e.background,Ne(t.cursorAccent,ac)),e.selectionBackgroundTransparent=Ne(t.selectionBackground,_i),e.selectionBackgroundOpaque=Ae.blend(e.background,e.selectionBackgroundTransparent),e.selectionInactiveBackgroundTransparent=Ne(t.selectionInactiveBackground,e.selectionBackgroundTransparent),e.selectionInactiveBackgroundOpaque=Ae.blend(e.background,e.selectionInactiveBackgroundTransparent),e.selectionForeground=t.selectionForeground?Ne(t.selectionForeground,ec):void 0,e.selectionForeground===ec&&(e.selectionForeground=void 0),Ae.isOpaque(e.selectionBackgroundTransparent)&&(e.selectionBackgroundTransparent=Ae.opacity(e.selectionBackgroundTransparent,.3)),Ae.isOpaque(e.selectionInactiveBackgroundTransparent)&&(e.selectionInactiveBackgroundTransparent=Ae.opacity(e.selectionInactiveBackgroundTransparent,.3)),e.scrollbarSliderBackground=Ne(t.scrollbarSliderBackground,Ae.opacity(e.foreground,.2)),e.scrollbarSliderHoverBackground=Ne(t.scrollbarSliderHoverBackground,Ae.opacity(e.foreground,.4)),e.scrollbarSliderActiveBackground=Ne(t.scrollbarSliderActiveBackground,Ae.opacity(e.foreground,.5)),e.overviewRulerBorder=Ne(t.overviewRulerBorder,oS),e.ansi=Ke.slice(),e.ansi[0]=Ne(t.black,Ke[0]),e.ansi[1]=Ne(t.red,Ke[1]),e.ansi[2]=Ne(t.green,Ke[2]),e.ansi[3]=Ne(t.yellow,Ke[3]),e.ansi[4]=Ne(t.blue,Ke[4]),e.ansi[5]=Ne(t.magenta,Ke[5]),e.ansi[6]=Ne(t.cyan,Ke[6]),e.ansi[7]=Ne(t.white,Ke[7]),e.ansi[8]=Ne(t.brightBlack,Ke[8]),e.ansi[9]=Ne(t.brightRed,Ke[9]),e.ansi[10]=Ne(t.brightGreen,Ke[10]),e.ansi[11]=Ne(t.brightYellow,Ke[11]),e.ansi[12]=Ne(t.brightBlue,Ke[12]),e.ansi[13]=Ne(t.brightMagenta,Ke[13]),e.ansi[14]=Ne(t.brightCyan,Ke[14]),e.ansi[15]=Ne(t.brightWhite,Ke[15]),t.extendedAnsi){let s=Math.min(e.ansi.length-16,t.extendedAnsi.length);for(let i=0;i<s;i++)e.ansi[i+16]=Ne(t.extendedAnsi[i],Ke[i+16])}this._contrastCache.clear(),this._halfContrastCache.clear(),this._updateRestoreColors(),this._onChangeColors.fire(this.colors)}restoreColor(t){this._restoreColor(t),this._onChangeColors.fire(this.colors)}_restoreColor(t){if(t===void 0){for(let e=0;e<this._restoreColors.ansi.length;++e)this._colors.ansi[e]=this._restoreColors.ansi[e];return}switch(t){case 256:this._colors.foreground=this._restoreColors.foreground;break;case 257:this._colors.background=this._restoreColors.background;break;case 258:this._colors.cursor=this._restoreColors.cursor;break;default:this._colors.ansi[t]=this._restoreColors.ansi[t]}}modifyColors(t){t(this._colors),this._onChangeColors.fire(this.colors)}_updateRestoreColors(){this._restoreColors={foreground:this._colors.foreground,background:this._colors.background,cursor:this._colors.cursor,ansi:this._colors.ansi.slice()}}};Ro=ze([de(0,dt)],Ro);function Ne(t,e){if(t!==void 0)try{return Le.toColor(t)}catch{}return e}var aS=class{constructor(...t){this._entries=new Map;for(let[e,s]of t)this.set(e,s)}set(t,e){let s=this._entries.get(t);return this._entries.set(t,e),s}forEach(t){for(let[e,s]of this._entries.entries())t(e,s)}has(t){return this._entries.has(t)}get(t){return this._entries.get(t)}},lS=class{constructor(){this._services=new aS,this._services.set(Ta,this)}setService(t,e){this._services.set(t,e)}getService(t){return this._services.get(t)}createInstance(t,...e){let s=ty(t).sort((o,a)=>o.index-a.index),i=[];for(let o of s){let a=this._services.get(o.id);if(!a)throw new Error(`[createInstance] ${t.name} depends on UNKNOWN service ${o.id._id}.`);i.push(a)}let r=s.length>0?s[0].index:e.length;if(e.length!==r)throw new Error(`[createInstance] First service dependency of ${t.name} at position ${r+1} conflicts with ${e.length} static arguments`);return new t(...e,...i)}},cS={trace:0,debug:1,info:2,warn:3,error:4,off:5},hS="xterm.js: ",Po=class extends ye{constructor(t){super(),this._optionsService=t,this._logLevel=5,this._updateLogLevel(),this._register(this._optionsService.onSpecificOptionChange("logLevel",()=>this._updateLogLevel()))}get logLevel(){return this._logLevel}_updateLogLevel(){this._logLevel=cS[this._optionsService.rawOptions.logLevel]}_evalLazyOptionalParams(t){for(let e=0;e<t.length;e++)typeof t[e]=="function"&&(t[e]=t[e]())}_log(t,e,s){this._evalLazyOptionalParams(s),t.call(console,(this._optionsService.options.logger?"":hS)+e,...s)}trace(t,...e){this._logLevel<=0&&this._log(this._optionsService.options.logger?.trace.bind(this._optionsService.options.logger)??console.log,t,e)}debug(t,...e){this._logLevel<=1&&this._log(this._optionsService.options.logger?.debug.bind(this._optionsService.options.logger)??console.log,t,e)}info(t,...e){this._logLevel<=2&&this._log(this._optionsService.options.logger?.info.bind(this._optionsService.options.logger)??console.info,t,e)}warn(t,...e){this._logLevel<=3&&this._log(this._optionsService.options.logger?.warn.bind(this._optionsService.options.logger)??console.warn,t,e)}error(t,...e){this._logLevel<=4&&this._log(this._optionsService.options.logger?.error.bind(this._optionsService.options.logger)??console.error,t,e)}};Po=ze([de(0,dt)],Po);var lc=class extends ye{constructor(t){super(),this._maxLength=t,this.onDeleteEmitter=this._register(new ae),this.onDelete=this.onDeleteEmitter.event,this.onInsertEmitter=this._register(new ae),this.onInsert=this.onInsertEmitter.event,this.onTrimEmitter=this._register(new ae),this.onTrim=this.onTrimEmitter.event,this._array=new Array(this._maxLength),this._startIndex=0,this._length=0}get maxLength(){return this._maxLength}set maxLength(t){if(this._maxLength===t)return;let e=new Array(t);for(let s=0;s<Math.min(t,this.length);s++)e[s]=this._array[this._getCyclicIndex(s)];this._array=e,this._maxLength=t,this._startIndex=0}get length(){return this._length}set length(t){if(t>this._length)for(let e=this._length;e<t;e++)this._array[e]=void 0;this._length=t}get(t){return this._array[this._getCyclicIndex(t)]}set(t,e){this._array[this._getCyclicIndex(t)]=e}push(t){this._array[this._getCyclicIndex(this._length)]=t,this._length===this._maxLength?(this._startIndex=++this._startIndex%this._maxLength,this.onTrimEmitter.fire(1)):this._length++}recycle(){if(this._length!==this._maxLength)throw new Error("Can only recycle when the buffer is full");return this._startIndex=++this._startIndex%this._maxLength,this.onTrimEmitter.fire(1),this._array[this._getCyclicIndex(this._length-1)]}get isFull(){return this._length===this._maxLength}pop(){return this._array[this._getCyclicIndex(this._length---1)]}splice(t,e,...s){if(e){for(let i=t;i<this._length-e;i++)this._array[this._getCyclicIndex(i)]=this._array[this._getCyclicIndex(i+e)];this._length-=e,this.onDeleteEmitter.fire({index:t,amount:e})}for(let i=this._length-1;i>=t;i--)this._array[this._getCyclicIndex(i+s.length)]=this._array[this._getCyclicIndex(i)];for(let i=0;i<s.length;i++)this._array[this._getCyclicIndex(t+i)]=s[i];if(s.length&&this.onInsertEmitter.fire({index:t,amount:s.length}),this._length+s.length>this._maxLength){let i=this._length+s.length-this._maxLength;this._startIndex+=i,this._length=this._maxLength,this.onTrimEmitter.fire(i)}else this._length+=s.length}trimStart(t){t>this._length&&(t=this._length),this._startIndex+=t,this._length-=t,this.onTrimEmitter.fire(t)}shiftElements(t,e,s){if(!(e<=0)){if(t<0||t>=this._length)throw new Error("start argument out of range");if(t+s<0)throw new Error("Cannot shift elements in list beyond index 0");if(s>0){for(let r=e-1;r>=0;r--)this.set(t+r+s,this.get(t+r));let i=t+e+s-this._length;if(i>0)for(this._length+=i;this._length>this._maxLength;)this._length--,this._startIndex++,this.onTrimEmitter.fire(1)}else for(let i=0;i<e;i++)this.set(t+i+s,this.get(t+i))}}_getCyclicIndex(t){return(this._startIndex+t)%this._maxLength}},be=3,We=Object.freeze(new Zi),pr=0,An=2,ki=class fu{constructor(e,s,i=!1){this.isWrapped=i,this._combined={},this._extendedAttrs={},this._data=new Uint32Array(e*be);let r=s||Nt.fromCharData([0,Dd,1,0]);for(let o=0;o<e;++o)this.setCell(o,r);this.length=e}get(e){let s=this._data[e*be+0],i=s&2097151;return[this._data[e*be+1],s&2097152?this._combined[e]:i?us(i):"",s>>22,s&2097152?this._combined[e].charCodeAt(this._combined[e].length-1):i]}set(e,s){this._data[e*be+1]=s[0],s[1].length>1?(this._combined[e]=s[1],this._data[e*be+0]=e|2097152|s[2]<<22):this._data[e*be+0]=s[1].charCodeAt(0)|s[2]<<22}getWidth(e){return this._data[e*be+0]>>22}hasWidth(e){return this._data[e*be+0]&12582912}getFg(e){return this._data[e*be+1]}getBg(e){return this._data[e*be+2]}hasContent(e){return this._data[e*be+0]&4194303}getCodePoint(e){let s=this._data[e*be+0];return s&2097152?this._combined[e].charCodeAt(this._combined[e].length-1):s&2097151}isCombined(e){return this._data[e*be+0]&2097152}getString(e){let s=this._data[e*be+0];return s&2097152?this._combined[e]:s&2097151?us(s&2097151):""}isProtected(e){return this._data[e*be+2]&536870912}loadCell(e,s){return pr=e*be,s.content=this._data[pr+0],s.fg=this._data[pr+1],s.bg=this._data[pr+2],s.content&2097152&&(s.combinedData=this._combined[e]),s.bg&268435456&&(s.extended=this._extendedAttrs[e]),s}setCell(e,s){s.content&2097152&&(this._combined[e]=s.combinedData),s.bg&268435456&&(this._extendedAttrs[e]=s.extended),this._data[e*be+0]=s.content,this._data[e*be+1]=s.fg,this._data[e*be+2]=s.bg}setCellFromCodepoint(e,s,i,r){r.bg&268435456&&(this._extendedAttrs[e]=r.extended),this._data[e*be+0]=s|i<<22,this._data[e*be+1]=r.fg,this._data[e*be+2]=r.bg}addCodepointToCell(e,s,i){let r=this._data[e*be+0];r&2097152?this._combined[e]+=us(s):r&2097151?(this._combined[e]=us(r&2097151)+us(s),r&=-2097152,r|=2097152):r=s|1<<22,i&&(r&=-12582913,r|=i<<22),this._data[e*be+0]=r}insertCells(e,s,i){if(e%=this.length,e&&this.getWidth(e-1)===2&&this.setCellFromCodepoint(e-1,0,1,i),s<this.length-e){let r=new Nt;for(let o=this.length-e-s-1;o>=0;--o)this.setCell(e+s+o,this.loadCell(e+o,r));for(let o=0;o<s;++o)this.setCell(e+o,i)}else for(let r=e;r<this.length;++r)this.setCell(r,i);this.getWidth(this.length-1)===2&&this.setCellFromCodepoint(this.length-1,0,1,i)}deleteCells(e,s,i){if(e%=this.length,s<this.length-e){let r=new Nt;for(let o=0;o<this.length-e-s;++o)this.setCell(e+o,this.loadCell(e+s+o,r));for(let o=this.length-s;o<this.length;++o)this.setCell(o,i)}else for(let r=e;r<this.length;++r)this.setCell(r,i);e&&this.getWidth(e-1)===2&&this.setCellFromCodepoint(e-1,0,1,i),this.getWidth(e)===0&&!this.hasContent(e)&&this.setCellFromCodepoint(e,0,1,i)}replaceCells(e,s,i,r=!1){if(r){for(e&&this.getWidth(e-1)===2&&!this.isProtected(e-1)&&this.setCellFromCodepoint(e-1,0,1,i),s<this.length&&this.getWidth(s-1)===2&&!this.isProtected(s)&&this.setCellFromCodepoint(s,0,1,i);e<s&&e<this.length;)this.isProtected(e)||this.setCell(e,i),e++;return}for(e&&this.getWidth(e-1)===2&&this.setCellFromCodepoint(e-1,0,1,i),s<this.length&&this.getWidth(s-1)===2&&this.setCellFromCodepoint(s,0,1,i);e<s&&e<this.length;)this.setCell(e++,i)}resize(e,s){if(e===this.length)return this._data.length*4*An<this._data.buffer.byteLength;let i=e*be;if(e>this.length){if(this._data.buffer.byteLength>=i*4)this._data=new Uint32Array(this._data.buffer,0,i);else{let r=new Uint32Array(i);r.set(this._data),this._data=r}for(let r=this.length;r<e;++r)this.setCell(r,s)}else{this._data=this._data.subarray(0,i);let r=Object.keys(this._combined);for(let a=0;a<r.length;a++){let l=parseInt(r[a],10);l>=e&&delete this._combined[l]}let o=Object.keys(this._extendedAttrs);for(let a=0;a<o.length;a++){let l=parseInt(o[a],10);l>=e&&delete this._extendedAttrs[l]}}return this.length=e,i*4*An<this._data.buffer.byteLength}cleanupMemory(){if(this._data.length*4*An<this._data.buffer.byteLength){let e=new Uint32Array(this._data.length);return e.set(this._data),this._data=e,1}return 0}fill(e,s=!1){if(s){for(let i=0;i<this.length;++i)this.isProtected(i)||this.setCell(i,e);return}this._combined={},this._extendedAttrs={};for(let i=0;i<this.length;++i)this.setCell(i,e)}copyFrom(e){this.length!==e.length?this._data=new Uint32Array(e._data):this._data.set(e._data),this.length=e.length,this._combined={};for(let s in e._combined)this._combined[s]=e._combined[s];this._extendedAttrs={};for(let s in e._extendedAttrs)this._extendedAttrs[s]=e._extendedAttrs[s];this.isWrapped=e.isWrapped}clone(){let e=new fu(0);e._data=new Uint32Array(this._data),e.length=this.length;for(let s in this._combined)e._combined[s]=this._combined[s];for(let s in this._extendedAttrs)e._extendedAttrs[s]=this._extendedAttrs[s];return e.isWrapped=this.isWrapped,e}getTrimmedLength(){for(let e=this.length-1;e>=0;--e)if(this._data[e*be+0]&4194303)return e+(this._data[e*be+0]>>22);return 0}getNoBgTrimmedLength(){for(let e=this.length-1;e>=0;--e)if(this._data[e*be+0]&4194303||this._data[e*be+2]&50331648)return e+(this._data[e*be+0]>>22);return 0}copyCellsFrom(e,s,i,r,o){let a=e._data;if(o)for(let h=r-1;h>=0;h--){for(let c=0;c<be;c++)this._data[(i+h)*be+c]=a[(s+h)*be+c];a[(s+h)*be+2]&268435456&&(this._extendedAttrs[i+h]=e._extendedAttrs[s+h])}else for(let h=0;h<r;h++){for(let c=0;c<be;c++)this._data[(i+h)*be+c]=a[(s+h)*be+c];a[(s+h)*be+2]&268435456&&(this._extendedAttrs[i+h]=e._extendedAttrs[s+h])}let l=Object.keys(e._combined);for(let h=0;h<l.length;h++){let c=parseInt(l[h],10);c>=s&&(this._combined[c-s+i]=e._combined[c])}}translateToString(e,s,i,r){s=s??0,i=i??this.length,e&&(i=Math.min(i,this.getTrimmedLength())),r&&(r.length=0);let o="";for(;s<i;){let a=this._data[s*be+0],l=a&2097151,h=a&2097152?this._combined[s]:l?us(l):fs;if(o+=h,r)for(let c=0;c<h.length;++c)r.push(s);s+=a>>22||1}return r&&r.push(s),o}};function dS(t,e,s,i,r,o){let a=[];for(let l=0;l<t.length-1;l++){let h=l,c=t.get(++h);if(!c.isWrapped)continue;let d=[t.get(l)];for(;h<t.length&&c.isWrapped;)d.push(c),c=t.get(++h);if(!o&&i>=l&&i<h){l+=d.length-1;continue}let u=0,f=Wi(d,u,e),m=1,p=0;for(;m<d.length;){let g=Wi(d,m,e),v=g-p,b=s-f,x=Math.min(v,b);d[u].copyCellsFrom(d[m],p,f,x,!1),f+=x,f===s&&(u++,f=0),p+=x,p===g&&(m++,p=0),f===0&&u!==0&&d[u-1].getWidth(s-1)===2&&(d[u].copyCellsFrom(d[u-1],s-1,f++,1,!1),d[u-1].setCell(s-1,r))}d[u].replaceCells(f,s,r);let _=0;for(let g=d.length-1;g>0&&(g>u||d[g].getTrimmedLength()===0);g--)_++;_>0&&(a.push(l+d.length-_),a.push(_)),l+=d.length-1}return a}function uS(t,e){let s=[],i=0,r=e[i],o=0;for(let a=0;a<t.length;a++)if(r===a){let l=e[++i];t.onDeleteEmitter.fire({index:a-o,amount:l}),a+=l-1,o+=l,r=e[++i]}else s.push(a);return{layout:s,countRemoved:o}}function fS(t,e){let s=[];for(let i=0;i<e.length;i++)s.push(t.get(e[i]));for(let i=0;i<s.length;i++)t.set(i,s[i]);t.length=e.length}function mS(t,e,s){let i=[],r=t.map((h,c)=>Wi(t,c,e)).reduce((h,c)=>h+c),o=0,a=0,l=0;for(;l<r;){if(r-l<s){i.push(r-l);break}o+=s;let h=Wi(t,a,e);o>h&&(o-=h,a++);let c=t[a].getWidth(o-1)===2;c&&o--;let d=c?s-1:s;i.push(d),l+=d}return i}function Wi(t,e,s){if(e===t.length-1)return t[e].getTrimmedLength();let i=!t[e].hasContent(s-1)&&t[e].getWidth(s-1)===1,r=t[e+1].getWidth(0)===2;return i&&r?s-1:s}var mu=class pu{constructor(e){this.line=e,this.isDisposed=!1,this._disposables=[],this._id=pu._nextId++,this._onDispose=this.register(new ae),this.onDispose=this._onDispose.event}get id(){return this._id}dispose(){this.isDisposed||(this.isDisposed=!0,this.line=-1,this._onDispose.fire(),ks(this._disposables),this._disposables.length=0)}register(e){return this._disposables.push(e),e}};mu._nextId=1;var pS=mu,Ge={},xs=Ge.B;Ge[0]={"`":"◆",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:"≥","{":"π","|":"≠","}":"£","~":"·"};Ge.A={"#":"£"};Ge.B=void 0;Ge[4]={"#":"£","@":"¾","[":"ij","\\":"½","]":"|","{":"¨","|":"f","}":"¼","~":"´"};Ge.C=Ge[5]={"[":"Ä","\\":"Ö","]":"Å","^":"Ü","`":"é","{":"ä","|":"ö","}":"å","~":"ü"};Ge.R={"#":"£","@":"à","[":"°","\\":"ç","]":"§","{":"é","|":"ù","}":"è","~":"¨"};Ge.Q={"@":"à","[":"â","\\":"ç","]":"ê","^":"î","`":"ô","{":"é","|":"ù","}":"è","~":"û"};Ge.K={"@":"§","[":"Ä","\\":"Ö","]":"Ü","{":"ä","|":"ö","}":"ü","~":"ß"};Ge.Y={"#":"£","@":"§","[":"°","\\":"ç","]":"é","`":"ù","{":"à","|":"ò","}":"è","~":"ì"};Ge.E=Ge[6]={"@":"Ä","[":"Æ","\\":"Ø","]":"Å","^":"Ü","`":"ä","{":"æ","|":"ø","}":"å","~":"ü"};Ge.Z={"#":"£","@":"§","[":"¡","\\":"Ñ","]":"¿","{":"°","|":"ñ","}":"ç"};Ge.H=Ge[7]={"@":"É","[":"Ä","\\":"Ö","]":"Å","^":"Ü","`":"é","{":"ä","|":"ö","}":"å","~":"ü"};Ge["="]={"#":"ù","@":"à","[":"é","\\":"ç","]":"ê","^":"î",_:"è","`":"ô","{":"ä","|":"ö","}":"ü","~":"û"};var cc=4294967295,hc=class{constructor(t,e,s){this._hasScrollback=t,this._optionsService=e,this._bufferService=s,this.ydisp=0,this.ybase=0,this.y=0,this.x=0,this.tabs={},this.savedY=0,this.savedX=0,this.savedCurAttrData=We.clone(),this.savedCharset=xs,this.markers=[],this._nullCell=Nt.fromCharData([0,Dd,1,0]),this._whitespaceCell=Nt.fromCharData([0,fs,1,32]),this._isClearing=!1,this._memoryCleanupQueue=new Gr,this._memoryCleanupPosition=0,this._cols=this._bufferService.cols,this._rows=this._bufferService.rows,this.lines=new lc(this._getCorrectBufferLength(this._rows)),this.scrollTop=0,this.scrollBottom=this._rows-1,this.setupTabStops()}getNullCell(t){return t?(this._nullCell.fg=t.fg,this._nullCell.bg=t.bg,this._nullCell.extended=t.extended):(this._nullCell.fg=0,this._nullCell.bg=0,this._nullCell.extended=new Ur),this._nullCell}getWhitespaceCell(t){return t?(this._whitespaceCell.fg=t.fg,this._whitespaceCell.bg=t.bg,this._whitespaceCell.extended=t.extended):(this._whitespaceCell.fg=0,this._whitespaceCell.bg=0,this._whitespaceCell.extended=new Ur),this._whitespaceCell}getBlankLine(t,e){return new ki(this._bufferService.cols,this.getNullCell(t),e)}get hasScrollback(){return this._hasScrollback&&this.lines.maxLength>this._rows}get isCursorInViewport(){let t=this.ybase+this.y-this.ydisp;return t>=0&&t<this._rows}_getCorrectBufferLength(t){if(!this._hasScrollback)return t;let e=t+this._optionsService.rawOptions.scrollback;return e>cc?cc:e}fillViewportRows(t){if(this.lines.length===0){t===void 0&&(t=We);let e=this._rows;for(;e--;)this.lines.push(this.getBlankLine(t))}}clear(){this.ydisp=0,this.ybase=0,this.y=0,this.x=0,this.lines=new lc(this._getCorrectBufferLength(this._rows)),this.scrollTop=0,this.scrollBottom=this._rows-1,this.setupTabStops()}resize(t,e){let s=this.getNullCell(We),i=0,r=this._getCorrectBufferLength(e);if(r>this.lines.maxLength&&(this.lines.maxLength=r),this.lines.length>0){if(this._cols<t)for(let a=0;a<this.lines.length;a++)i+=+this.lines.get(a).resize(t,s);let o=0;if(this._rows<e)for(let a=this._rows;a<e;a++)this.lines.length<e+this.ybase&&(this._optionsService.rawOptions.windowsMode||this._optionsService.rawOptions.windowsPty.backend!==void 0||this._optionsService.rawOptions.windowsPty.buildNumber!==void 0?this.lines.push(new ki(t,s)):this.ybase>0&&this.lines.length<=this.ybase+this.y+o+1?(this.ybase--,o++,this.ydisp>0&&this.ydisp--):this.lines.push(new ki(t,s)));else for(let a=this._rows;a>e;a--)this.lines.length>e+this.ybase&&(this.lines.length>this.ybase+this.y+1?this.lines.pop():(this.ybase++,this.ydisp++));if(r<this.lines.maxLength){let a=this.lines.length-r;a>0&&(this.lines.trimStart(a),this.ybase=Math.max(this.ybase-a,0),this.ydisp=Math.max(this.ydisp-a,0),this.savedY=Math.max(this.savedY-a,0)),this.lines.maxLength=r}this.x=Math.min(this.x,t-1),this.y=Math.min(this.y,e-1),o&&(this.y+=o),this.savedX=Math.min(this.savedX,t-1),this.scrollTop=0}if(this.scrollBottom=e-1,this._isReflowEnabled&&(this._reflow(t,e),this._cols>t))for(let o=0;o<this.lines.length;o++)i+=+this.lines.get(o).resize(t,s);this._cols=t,this._rows=e,this._memoryCleanupQueue.clear(),i>.1*this.lines.length&&(this._memoryCleanupPosition=0,this._memoryCleanupQueue.enqueue(()=>this._batchedMemoryCleanup()))}_batchedMemoryCleanup(){let t=!0;this._memoryCleanupPosition>=this.lines.length&&(this._memoryCleanupPosition=0,t=!1);let e=0;for(;this._memoryCleanupPosition<this.lines.length;)if(e+=this.lines.get(this._memoryCleanupPosition++).cleanupMemory(),e>100)return!0;return t}get _isReflowEnabled(){let t=this._optionsService.rawOptions.windowsPty;return t&&t.buildNumber?this._hasScrollback&&t.backend==="conpty"&&t.buildNumber>=21376:this._hasScrollback&&!this._optionsService.rawOptions.windowsMode}_reflow(t,e){this._cols!==t&&(t>this._cols?this._reflowLarger(t,e):this._reflowSmaller(t,e))}_reflowLarger(t,e){let s=this._optionsService.rawOptions.reflowCursorLine,i=dS(this.lines,this._cols,t,this.ybase+this.y,this.getNullCell(We),s);if(i.length>0){let r=uS(this.lines,i);fS(this.lines,r.layout),this._reflowLargerAdjustViewport(t,e,r.countRemoved)}}_reflowLargerAdjustViewport(t,e,s){let i=this.getNullCell(We),r=s;for(;r-- >0;)this.ybase===0?(this.y>0&&this.y--,this.lines.length<e&&this.lines.push(new ki(t,i))):(this.ydisp===this.ybase&&this.ydisp--,this.ybase--);this.savedY=Math.max(this.savedY-s,0)}_reflowSmaller(t,e){let s=this._optionsService.rawOptions.reflowCursorLine,i=this.getNullCell(We),r=[],o=0;for(let a=this.lines.length-1;a>=0;a--){let l=this.lines.get(a);if(!l||!l.isWrapped&&l.getTrimmedLength()<=t)continue;let h=[l];for(;l.isWrapped&&a>0;)l=this.lines.get(--a),h.unshift(l);if(!s){let x=this.ybase+this.y;if(x>=a&&x<a+h.length)continue}let c=h[h.length-1].getTrimmedLength(),d=mS(h,this._cols,t),u=d.length-h.length,f;this.ybase===0&&this.y!==this.lines.length-1?f=Math.max(0,this.y-this.lines.maxLength+u):f=Math.max(0,this.lines.length-this.lines.maxLength+u);let m=[];for(let x=0;x<u;x++){let y=this.getBlankLine(We,!0);m.push(y)}m.length>0&&(r.push({start:a+h.length+o,newLines:m}),o+=m.length),h.push(...m);let p=d.length-1,_=d[p];_===0&&(p--,_=d[p]);let g=h.length-u-1,v=c;for(;g>=0;){let x=Math.min(v,_);if(h[p]===void 0)break;if(h[p].copyCellsFrom(h[g],v-x,_-x,x,!0),_-=x,_===0&&(p--,_=d[p]),v-=x,v===0){g--;let y=Math.max(g,0);v=Wi(h,y,this._cols)}}for(let x=0;x<h.length;x++)d[x]<t&&h[x].setCell(d[x],i);let b=u-f;for(;b-- >0;)this.ybase===0?this.y<e-1?(this.y++,this.lines.pop()):(this.ybase++,this.ydisp++):this.ybase<Math.min(this.lines.maxLength,this.lines.length+o)-e&&(this.ybase===this.ydisp&&this.ydisp++,this.ybase++);this.savedY=Math.min(this.savedY+u,this.ybase+e-1)}if(r.length>0){let a=[],l=[];for(let _=0;_<this.lines.length;_++)l.push(this.lines.get(_));let h=this.lines.length,c=h-1,d=0,u=r[d];this.lines.length=Math.min(this.lines.maxLength,this.lines.length+o);let f=0;for(let _=Math.min(this.lines.maxLength-1,h+o-1);_>=0;_--)if(u&&u.start>c+f){for(let g=u.newLines.length-1;g>=0;g--)this.lines.set(_--,u.newLines[g]);_++,a.push({index:c+1,amount:u.newLines.length}),f+=u.newLines.length,u=r[++d]}else this.lines.set(_,l[c--]);let m=0;for(let _=a.length-1;_>=0;_--)a[_].index+=m,this.lines.onInsertEmitter.fire(a[_]),m+=a[_].amount;let p=Math.max(0,h+o-this.lines.maxLength);p>0&&this.lines.onTrimEmitter.fire(p)}}translateBufferLineToString(t,e,s=0,i){let r=this.lines.get(t);return r?r.translateToString(e,s,i):""}getWrappedRangeForLine(t){let e=t,s=t;for(;e>0&&this.lines.get(e).isWrapped;)e--;for(;s+1<this.lines.length&&this.lines.get(s+1).isWrapped;)s++;return{first:e,last:s}}setupTabStops(t){for(t!=null?this.tabs[t]||(t=this.prevStop(t)):(this.tabs={},t=0);t<this._cols;t+=this._optionsService.rawOptions.tabStopWidth)this.tabs[t]=!0}prevStop(t){for(t==null&&(t=this.x);!this.tabs[--t]&&t>0;);return t>=this._cols?this._cols-1:t<0?0:t}nextStop(t){for(t==null&&(t=this.x);!this.tabs[++t]&&t<this._cols;);return t>=this._cols?this._cols-1:t<0?0:t}clearMarkers(t){this._isClearing=!0;for(let e=0;e<this.markers.length;e++)this.markers[e].line===t&&(this.markers[e].dispose(),this.markers.splice(e--,1));this._isClearing=!1}clearAllMarkers(){this._isClearing=!0;for(let t=0;t<this.markers.length;t++)this.markers[t].dispose();this.markers.length=0,this._isClearing=!1}addMarker(t){let e=new pS(t);return this.markers.push(e),e.register(this.lines.onTrim(s=>{e.line-=s,e.line<0&&e.dispose()})),e.register(this.lines.onInsert(s=>{e.line>=s.index&&(e.line+=s.amount)})),e.register(this.lines.onDelete(s=>{e.line>=s.index&&e.line<s.index+s.amount&&e.dispose(),e.line>s.index&&(e.line-=s.amount)})),e.register(e.onDispose(()=>this._removeMarker(e))),e}_removeMarker(t){this._isClearing||this.markers.splice(this.markers.indexOf(t),1)}},_S=class extends ye{constructor(t,e){super(),this._optionsService=t,this._bufferService=e,this._onBufferActivate=this._register(new ae),this.onBufferActivate=this._onBufferActivate.event,this.reset(),this._register(this._optionsService.onSpecificOptionChange("scrollback",()=>this.resize(this._bufferService.cols,this._bufferService.rows))),this._register(this._optionsService.onSpecificOptionChange("tabStopWidth",()=>this.setupTabStops()))}reset(){this._normal=new hc(!0,this._optionsService,this._bufferService),this._normal.fillViewportRows(),this._alt=new hc(!1,this._optionsService,this._bufferService),this._activeBuffer=this._normal,this._onBufferActivate.fire({activeBuffer:this._normal,inactiveBuffer:this._alt}),this.setupTabStops()}get alt(){return this._alt}get active(){return this._activeBuffer}get normal(){return this._normal}activateNormalBuffer(){this._activeBuffer!==this._normal&&(this._normal.x=this._alt.x,this._normal.y=this._alt.y,this._alt.clearAllMarkers(),this._alt.clear(),this._activeBuffer=this._normal,this._onBufferActivate.fire({activeBuffer:this._normal,inactiveBuffer:this._alt}))}activateAltBuffer(t){this._activeBuffer!==this._alt&&(this._alt.fillViewportRows(t),this._alt.x=this._normal.x,this._alt.y=this._normal.y,this._activeBuffer=this._alt,this._onBufferActivate.fire({activeBuffer:this._alt,inactiveBuffer:this._normal}))}resize(t,e){this._normal.resize(t,e),this._alt.resize(t,e),this.setupTabStops(t)}setupTabStops(t){this._normal.setupTabStops(t),this._alt.setupTabStops(t)}},_u=2,gu=1,Do=class extends ye{constructor(t){super(),this.isUserScrolling=!1,this._onResize=this._register(new ae),this.onResize=this._onResize.event,this._onScroll=this._register(new ae),this.onScroll=this._onScroll.event,this.cols=Math.max(t.rawOptions.cols||0,_u),this.rows=Math.max(t.rawOptions.rows||0,gu),this.buffers=this._register(new _S(t,this)),this._register(this.buffers.onBufferActivate(e=>{this._onScroll.fire(e.activeBuffer.ydisp)}))}get buffer(){return this.buffers.active}resize(t,e){let s=this.cols!==t,i=this.rows!==e;this.cols=t,this.rows=e,this.buffers.resize(t,e),this._onResize.fire({cols:t,rows:e,colsChanged:s,rowsChanged:i})}reset(){this.buffers.reset(),this.isUserScrolling=!1}scroll(t,e=!1){let s=this.buffer,i;i=this._cachedBlankLine,(!i||i.length!==this.cols||i.getFg(0)!==t.fg||i.getBg(0)!==t.bg)&&(i=s.getBlankLine(t,e),this._cachedBlankLine=i),i.isWrapped=e;let r=s.ybase+s.scrollTop,o=s.ybase+s.scrollBottom;if(s.scrollTop===0){let a=s.lines.isFull;o===s.lines.length-1?a?s.lines.recycle().copyFrom(i):s.lines.push(i.clone()):s.lines.splice(o+1,0,i.clone()),a?this.isUserScrolling&&(s.ydisp=Math.max(s.ydisp-1,0)):(s.ybase++,this.isUserScrolling||s.ydisp++)}else{let a=o-r+1;s.lines.shiftElements(r+1,a-1,-1),s.lines.set(o,i.clone())}this.isUserScrolling||(s.ydisp=s.ybase),this._onScroll.fire(s.ydisp)}scrollLines(t,e){let s=this.buffer;if(t<0){if(s.ydisp===0)return;this.isUserScrolling=!0}else t+s.ydisp>=s.ybase&&(this.isUserScrolling=!1);let i=s.ydisp;s.ydisp=Math.max(Math.min(s.ydisp+t,s.ybase),0),i!==s.ydisp&&(e||this._onScroll.fire(s.ydisp))}};Do=ze([de(0,dt)],Do);var Fs={cols:80,rows:24,cursorBlink:!1,cursorStyle:"block",cursorWidth:1,cursorInactiveStyle:"outline",customGlyphs:!0,drawBoldTextInBrightColors:!0,documentOverride:null,fastScrollModifier:"alt",fastScrollSensitivity:5,fontFamily:"monospace",fontSize:15,fontWeight:"normal",fontWeightBold:"bold",ignoreBracketedPasteMode:!1,lineHeight:1,letterSpacing:0,linkHandler:null,logLevel:"info",logger:null,scrollback:1e3,scrollOnEraseInDisplay:!1,scrollOnUserInput:!0,scrollSensitivity:1,screenReaderMode:!1,smoothScrollDuration:0,macOptionIsMeta:!1,macOptionClickForcesSelection:!1,minimumContrastRatio:1,disableStdin:!1,allowProposedApi:!1,allowTransparency:!1,tabStopWidth:8,theme:{},reflowCursorLine:!1,rescaleOverlappingGlyphs:!1,rightClickSelectsWord:qr,windowOptions:{},windowsMode:!1,windowsPty:{},wordSeparator:" ()[]{}',\"`",altClickMovesCursor:!0,convertEol:!1,termName:"xterm",cancelEvents:!1,overviewRuler:{}},gS=["normal","bold","100","200","300","400","500","600","700","800","900"],vS=class extends ye{constructor(t){super(),this._onOptionChange=this._register(new ae),this.onOptionChange=this._onOptionChange.event;let e={...Fs};for(let s in t)if(s in e)try{let i=t[s];e[s]=this._sanitizeAndValidateOption(s,i)}catch(i){console.error(i)}this.rawOptions=e,this.options={...e},this._setupOptions(),this._register(Ie(()=>{this.rawOptions.linkHandler=null,this.rawOptions.documentOverride=null}))}onSpecificOptionChange(t,e){return this.onOptionChange(s=>{s===t&&e(this.rawOptions[t])})}onMultipleOptionChange(t,e){return this.onOptionChange(s=>{t.indexOf(s)!==-1&&e()})}_setupOptions(){let t=s=>{if(!(s in Fs))throw new Error(`No option with key "${s}"`);return this.rawOptions[s]},e=(s,i)=>{if(!(s in Fs))throw new Error(`No option with key "${s}"`);i=this._sanitizeAndValidateOption(s,i),this.rawOptions[s]!==i&&(this.rawOptions[s]=i,this._onOptionChange.fire(s))};for(let s in this.rawOptions){let i={get:t.bind(this,s),set:e.bind(this,s)};Object.defineProperty(this.options,s,i)}}_sanitizeAndValidateOption(t,e){switch(t){case"cursorStyle":if(e||(e=Fs[t]),!xS(e))throw new Error(`"${e}" is not a valid value for ${t}`);break;case"wordSeparator":e||(e=Fs[t]);break;case"fontWeight":case"fontWeightBold":if(typeof e=="number"&&1<=e&&e<=1e3)break;e=gS.includes(e)?e:Fs[t];break;case"cursorWidth":e=Math.floor(e);case"lineHeight":case"tabStopWidth":if(e<1)throw new Error(`${t} cannot be less than 1, value: ${e}`);break;case"minimumContrastRatio":e=Math.max(1,Math.min(21,Math.round(e*10)/10));break;case"scrollback":if(e=Math.min(e,4294967295),e<0)throw new Error(`${t} cannot be less than 0, value: ${e}`);break;case"fastScrollSensitivity":case"scrollSensitivity":if(e<=0)throw new Error(`${t} cannot be less than or equal to 0, value: ${e}`);break;case"rows":case"cols":if(!e&&e!==0)throw new Error(`${t} must be numeric, value: ${e}`);break;case"windowsPty":e=e??{};break}return e}};function xS(t){return t==="block"||t==="underline"||t==="bar"}function ji(t,e=5){if(typeof t!="object")return t;let s=Array.isArray(t)?[]:{};for(let i in t)s[i]=e<=1?t[i]:t[i]&&ji(t[i],e-1);return s}var dc=Object.freeze({insertMode:!1}),uc=Object.freeze({applicationCursorKeys:!1,applicationKeypad:!1,bracketedPasteMode:!1,cursorBlink:void 0,cursorStyle:void 0,origin:!1,reverseWraparound:!1,sendFocus:!1,synchronizedOutput:!1,wraparound:!0}),Ao=class extends ye{constructor(t,e,s){super(),this._bufferService=t,this._logService=e,this._optionsService=s,this.isCursorInitialized=!1,this.isCursorHidden=!1,this._onData=this._register(new ae),this.onData=this._onData.event,this._onUserInput=this._register(new ae),this.onUserInput=this._onUserInput.event,this._onBinary=this._register(new ae),this.onBinary=this._onBinary.event,this._onRequestScrollToBottom=this._register(new ae),this.onRequestScrollToBottom=this._onRequestScrollToBottom.event,this.modes=ji(dc),this.decPrivateModes=ji(uc)}reset(){this.modes=ji(dc),this.decPrivateModes=ji(uc)}triggerDataEvent(t,e=!1){if(this._optionsService.rawOptions.disableStdin)return;let s=this._bufferService.buffer;e&&this._optionsService.rawOptions.scrollOnUserInput&&s.ybase!==s.ydisp&&this._onRequestScrollToBottom.fire(),e&&this._onUserInput.fire(),this._logService.debug(`sending data "${t}"`),this._logService.trace("sending data (codes)",()=>t.split("").map(i=>i.charCodeAt(0))),this._onData.fire(t)}triggerBinaryEvent(t){this._optionsService.rawOptions.disableStdin||(this._logService.debug(`sending binary "${t}"`),this._logService.trace("sending binary (codes)",()=>t.split("").map(e=>e.charCodeAt(0))),this._onBinary.fire(t))}};Ao=ze([de(0,ht),de(1,Ld),de(2,dt)],Ao);var fc={NONE:{events:0,restrict:()=>!1},X10:{events:1,restrict:t=>t.button===4||t.action!==1?!1:(t.ctrl=!1,t.alt=!1,t.shift=!1,!0)},VT200:{events:19,restrict:t=>t.action!==32},DRAG:{events:23,restrict:t=>!(t.action===32&&t.button===3)},ANY:{events:31,restrict:t=>!0}};function In(t,e){let s=(t.ctrl?16:0)|(t.shift?4:0)|(t.alt?8:0);return t.button===4?(s|=64,s|=t.action):(s|=t.button&3,t.button&4&&(s|=64),t.button&8&&(s|=128),t.action===32?s|=32:t.action===0&&!e&&(s|=3)),s}var Bn=String.fromCharCode,mc={DEFAULT:t=>{let e=[In(t,!1)+32,t.col+32,t.row+32];return e[0]>255||e[1]>255||e[2]>255?"":`\x1B[M${Bn(e[0])}${Bn(e[1])}${Bn(e[2])}`},SGR:t=>{let e=t.action===0&&t.button!==4?"m":"M";return`\x1B[<${In(t,!0)};${t.col};${t.row}${e}`},SGR_PIXELS:t=>{let e=t.action===0&&t.button!==4?"m":"M";return`\x1B[<${In(t,!0)};${t.x};${t.y}${e}`}},Io=class extends ye{constructor(t,e,s){super(),this._bufferService=t,this._coreService=e,this._optionsService=s,this._protocols={},this._encodings={},this._activeProtocol="",this._activeEncoding="",this._lastEvent=null,this._wheelPartialScroll=0,this._onProtocolChange=this._register(new ae),this.onProtocolChange=this._onProtocolChange.event;for(let i of Object.keys(fc))this.addProtocol(i,fc[i]);for(let i of Object.keys(mc))this.addEncoding(i,mc[i]);this.reset()}addProtocol(t,e){this._protocols[t]=e}addEncoding(t,e){this._encodings[t]=e}get activeProtocol(){return this._activeProtocol}get areMouseEventsActive(){return this._protocols[this._activeProtocol].events!==0}set activeProtocol(t){if(!this._protocols[t])throw new Error(`unknown protocol "${t}"`);this._activeProtocol=t,this._onProtocolChange.fire(this._protocols[t].events)}get activeEncoding(){return this._activeEncoding}set activeEncoding(t){if(!this._encodings[t])throw new Error(`unknown encoding "${t}"`);this._activeEncoding=t}reset(){this.activeProtocol="NONE",this.activeEncoding="DEFAULT",this._lastEvent=null,this._wheelPartialScroll=0}consumeWheelEvent(t,e,s){if(t.deltaY===0||t.shiftKey||e===void 0||s===void 0)return 0;let i=e/s,r=this._applyScrollModifier(t.deltaY,t);return t.deltaMode===WheelEvent.DOM_DELTA_PIXEL?(r/=i+0,Math.abs(t.deltaY)<50&&(r*=.3),this._wheelPartialScroll+=r,r=Math.floor(Math.abs(this._wheelPartialScroll))*(this._wheelPartialScroll>0?1:-1),this._wheelPartialScroll%=1):t.deltaMode===WheelEvent.DOM_DELTA_PAGE&&(r*=this._bufferService.rows),r}_applyScrollModifier(t,e){return e.altKey||e.ctrlKey||e.shiftKey?t*this._optionsService.rawOptions.fastScrollSensitivity*this._optionsService.rawOptions.scrollSensitivity:t*this._optionsService.rawOptions.scrollSensitivity}triggerMouseEvent(t){if(t.col<0||t.col>=this._bufferService.cols||t.row<0||t.row>=this._bufferService.rows||t.button===4&&t.action===32||t.button===3&&t.action!==32||t.button!==4&&(t.action===2||t.action===3)||(t.col++,t.row++,t.action===32&&this._lastEvent&&this._equalEvents(this._lastEvent,t,this._activeEncoding==="SGR_PIXELS"))||!this._protocols[this._activeProtocol].restrict(t))return!1;let e=this._encodings[this._activeEncoding](t);return e&&(this._activeEncoding==="DEFAULT"?this._coreService.triggerBinaryEvent(e):this._coreService.triggerDataEvent(e,!0)),this._lastEvent=t,!0}explainEvents(t){return{down:!!(t&1),up:!!(t&2),drag:!!(t&4),move:!!(t&8),wheel:!!(t&16)}}_equalEvents(t,e,s){if(s){if(t.x!==e.x||t.y!==e.y)return!1}else if(t.col!==e.col||t.row!==e.row)return!1;return!(t.button!==e.button||t.action!==e.action||t.ctrl!==e.ctrl||t.alt!==e.alt||t.shift!==e.shift)}};Io=ze([de(0,ht),de(1,Ls),de(2,dt)],Io);var Mn=[[768,879],[1155,1158],[1160,1161],[1425,1469],[1471,1471],[1473,1474],[1476,1477],[1479,1479],[1536,1539],[1552,1557],[1611,1630],[1648,1648],[1750,1764],[1767,1768],[1770,1773],[1807,1807],[1809,1809],[1840,1866],[1958,1968],[2027,2035],[2305,2306],[2364,2364],[2369,2376],[2381,2381],[2385,2388],[2402,2403],[2433,2433],[2492,2492],[2497,2500],[2509,2509],[2530,2531],[2561,2562],[2620,2620],[2625,2626],[2631,2632],[2635,2637],[2672,2673],[2689,2690],[2748,2748],[2753,2757],[2759,2760],[2765,2765],[2786,2787],[2817,2817],[2876,2876],[2879,2879],[2881,2883],[2893,2893],[2902,2902],[2946,2946],[3008,3008],[3021,3021],[3134,3136],[3142,3144],[3146,3149],[3157,3158],[3260,3260],[3263,3263],[3270,3270],[3276,3277],[3298,3299],[3393,3395],[3405,3405],[3530,3530],[3538,3540],[3542,3542],[3633,3633],[3636,3642],[3655,3662],[3761,3761],[3764,3769],[3771,3772],[3784,3789],[3864,3865],[3893,3893],[3895,3895],[3897,3897],[3953,3966],[3968,3972],[3974,3975],[3984,3991],[3993,4028],[4038,4038],[4141,4144],[4146,4146],[4150,4151],[4153,4153],[4184,4185],[4448,4607],[4959,4959],[5906,5908],[5938,5940],[5970,5971],[6002,6003],[6068,6069],[6071,6077],[6086,6086],[6089,6099],[6109,6109],[6155,6157],[6313,6313],[6432,6434],[6439,6440],[6450,6450],[6457,6459],[6679,6680],[6912,6915],[6964,6964],[6966,6970],[6972,6972],[6978,6978],[7019,7027],[7616,7626],[7678,7679],[8203,8207],[8234,8238],[8288,8291],[8298,8303],[8400,8431],[12330,12335],[12441,12442],[43014,43014],[43019,43019],[43045,43046],[64286,64286],[65024,65039],[65056,65059],[65279,65279],[65529,65531]],bS=[[68097,68099],[68101,68102],[68108,68111],[68152,68154],[68159,68159],[119143,119145],[119155,119170],[119173,119179],[119210,119213],[119362,119364],[917505,917505],[917536,917631],[917760,917999]],Ve;function yS(t,e){let s=0,i=e.length-1,r;if(t<e[0][0]||t>e[i][1])return!1;for(;i>=s;)if(r=s+i>>1,t>e[r][1])s=r+1;else if(t<e[r][0])i=r-1;else return!0;return!1}var SS=class{constructor(){if(this.version="6",!Ve){Ve=new Uint8Array(65536),Ve.fill(1),Ve[0]=0,Ve.fill(0,1,32),Ve.fill(0,127,160),Ve.fill(2,4352,4448),Ve[9001]=2,Ve[9002]=2,Ve.fill(2,11904,42192),Ve[12351]=1,Ve.fill(2,44032,55204),Ve.fill(2,63744,64256),Ve.fill(2,65040,65050),Ve.fill(2,65072,65136),Ve.fill(2,65280,65377),Ve.fill(2,65504,65511);for(let t=0;t<Mn.length;++t)Ve.fill(0,Mn[t][0],Mn[t][1]+1)}}wcwidth(t){return t<32?0:t<127?1:t<65536?Ve[t]:yS(t,bS)?0:t>=131072&&t<=196605||t>=196608&&t<=262141?2:1}charProperties(t,e){let s=this.wcwidth(t),i=s===0&&e!==0;if(i){let r=bs.extractWidth(e);r===0?i=!1:r>s&&(s=r)}return bs.createPropertyValue(0,s,i)}},bs=class jr{constructor(){this._providers=Object.create(null),this._active="",this._onChange=new ae,this.onChange=this._onChange.event;let e=new SS;this.register(e),this._active=e.version,this._activeProvider=e}static extractShouldJoin(e){return(e&1)!==0}static extractWidth(e){return e>>1&3}static extractCharKind(e){return e>>3}static createPropertyValue(e,s,i=!1){return(e&16777215)<<3|(s&3)<<1|(i?1:0)}dispose(){this._onChange.dispose()}get versions(){return Object.keys(this._providers)}get activeVersion(){return this._active}set activeVersion(e){if(!this._providers[e])throw new Error(`unknown Unicode version "${e}"`);this._active=e,this._activeProvider=this._providers[e],this._onChange.fire(e)}register(e){this._providers[e.version]=e}wcwidth(e){return this._activeProvider.wcwidth(e)}getStringCellWidth(e){let s=0,i=0,r=e.length;for(let o=0;o<r;++o){let a=e.charCodeAt(o);if(55296<=a&&a<=56319){if(++o>=r)return s+this.wcwidth(a);let c=e.charCodeAt(o);56320<=c&&c<=57343?a=(a-55296)*1024+c-56320+65536:s+=this.wcwidth(c)}let l=this.charProperties(a,i),h=jr.extractWidth(l);jr.extractShouldJoin(l)&&(h-=jr.extractWidth(i)),s+=h,i=l}return s}charProperties(e,s){return this._activeProvider.charProperties(e,s)}},wS=class{constructor(){this.glevel=0,this._charsets=[]}reset(){this.charset=void 0,this._charsets=[],this.glevel=0}setgLevel(t){this.glevel=t,this.charset=this._charsets[t]}setgCharset(t,e){this._charsets[t]=e,this.glevel===t&&(this.charset=e)}};function pc(t){let e=t.buffer.lines.get(t.buffer.ybase+t.buffer.y-1)?.get(t.cols-1),s=t.buffer.lines.get(t.buffer.ybase+t.buffer.y);s&&e&&(s.isWrapped=e[3]!==0&&e[3]!==32)}var gi=2147483647,CS=256,vu=class Bo{constructor(e=32,s=32){if(this.maxLength=e,this.maxSubParamsLength=s,s>CS)throw new Error("maxSubParamsLength must not be greater than 256");this.params=new Int32Array(e),this.length=0,this._subParams=new Int32Array(s),this._subParamsLength=0,this._subParamsIdx=new Uint16Array(e),this._rejectDigits=!1,this._rejectSubDigits=!1,this._digitIsSub=!1}static fromArray(e){let s=new Bo;if(!e.length)return s;for(let i=Array.isArray(e[0])?1:0;i<e.length;++i){let r=e[i];if(Array.isArray(r))for(let o=0;o<r.length;++o)s.addSubParam(r[o]);else s.addParam(r)}return s}clone(){let e=new Bo(this.maxLength,this.maxSubParamsLength);return e.params.set(this.params),e.length=this.length,e._subParams.set(this._subParams),e._subParamsLength=this._subParamsLength,e._subParamsIdx.set(this._subParamsIdx),e._rejectDigits=this._rejectDigits,e._rejectSubDigits=this._rejectSubDigits,e._digitIsSub=this._digitIsSub,e}toArray(){let e=[];for(let s=0;s<this.length;++s){e.push(this.params[s]);let i=this._subParamsIdx[s]>>8,r=this._subParamsIdx[s]&255;r-i>0&&e.push(Array.prototype.slice.call(this._subParams,i,r))}return e}reset(){this.length=0,this._subParamsLength=0,this._rejectDigits=!1,this._rejectSubDigits=!1,this._digitIsSub=!1}addParam(e){if(this._digitIsSub=!1,this.length>=this.maxLength){this._rejectDigits=!0;return}if(e<-1)throw new Error("values lesser than -1 are not allowed");this._subParamsIdx[this.length]=this._subParamsLength<<8|this._subParamsLength,this.params[this.length++]=e>gi?gi:e}addSubParam(e){if(this._digitIsSub=!0,!!this.length){if(this._rejectDigits||this._subParamsLength>=this.maxSubParamsLength){this._rejectSubDigits=!0;return}if(e<-1)throw new Error("values lesser than -1 are not allowed");this._subParams[this._subParamsLength++]=e>gi?gi:e,this._subParamsIdx[this.length-1]++}}hasSubParams(e){return(this._subParamsIdx[e]&255)-(this._subParamsIdx[e]>>8)>0}getSubParams(e){let s=this._subParamsIdx[e]>>8,i=this._subParamsIdx[e]&255;return i-s>0?this._subParams.subarray(s,i):null}getSubParamsAll(){let e={};for(let s=0;s<this.length;++s){let i=this._subParamsIdx[s]>>8,r=this._subParamsIdx[s]&255;r-i>0&&(e[s]=this._subParams.slice(i,r))}return e}addDigit(e){let s;if(this._rejectDigits||!(s=this._digitIsSub?this._subParamsLength:this.length)||this._digitIsSub&&this._rejectSubDigits)return;let i=this._digitIsSub?this._subParams:this.params,r=i[s-1];i[s-1]=~r?Math.min(r*10+e,gi):e}},vi=[],kS=class{constructor(){this._state=0,this._active=vi,this._id=-1,this._handlers=Object.create(null),this._handlerFb=()=>{},this._stack={paused:!1,loopPosition:0,fallThrough:!1}}registerHandler(t,e){this._handlers[t]===void 0&&(this._handlers[t]=[]);let s=this._handlers[t];return s.push(e),{dispose:()=>{let i=s.indexOf(e);i!==-1&&s.splice(i,1)}}}clearHandler(t){this._handlers[t]&&delete this._handlers[t]}setHandlerFallback(t){this._handlerFb=t}dispose(){this._handlers=Object.create(null),this._handlerFb=()=>{},this._active=vi}reset(){if(this._state===2)for(let t=this._stack.paused?this._stack.loopPosition-1:this._active.length-1;t>=0;--t)this._active[t].end(!1);this._stack.paused=!1,this._active=vi,this._id=-1,this._state=0}_start(){if(this._active=this._handlers[this._id]||vi,!this._active.length)this._handlerFb(this._id,"START");else for(let t=this._active.length-1;t>=0;t--)this._active[t].start()}_put(t,e,s){if(!this._active.length)this._handlerFb(this._id,"PUT",cn(t,e,s));else for(let i=this._active.length-1;i>=0;i--)this._active[i].put(t,e,s)}start(){this.reset(),this._state=1}put(t,e,s){if(this._state!==3){if(this._state===1)for(;e<s;){let i=t[e++];if(i===59){this._state=2,this._start();break}if(i<48||57<i){this._state=3;return}this._id===-1&&(this._id=0),this._id=this._id*10+i-48}this._state===2&&s-e>0&&this._put(t,e,s)}}end(t,e=!0){if(this._state!==0){if(this._state!==3)if(this._state===1&&this._start(),!this._active.length)this._handlerFb(this._id,"END",t);else{let s=!1,i=this._active.length-1,r=!1;if(this._stack.paused&&(i=this._stack.loopPosition-1,s=e,r=this._stack.fallThrough,this._stack.paused=!1),!r&&s===!1){for(;i>=0&&(s=this._active[i].end(t),s!==!0);i--)if(s instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=i,this._stack.fallThrough=!1,s;i--}for(;i>=0;i--)if(s=this._active[i].end(!1),s instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=i,this._stack.fallThrough=!0,s}this._active=vi,this._id=-1,this._state=0}}},_t=class{constructor(t){this._handler=t,this._data="",this._hitLimit=!1}start(){this._data="",this._hitLimit=!1}put(t,e,s){this._hitLimit||(this._data+=cn(t,e,s),this._data.length>1e7&&(this._data="",this._hitLimit=!0))}end(t){let e=!1;if(this._hitLimit)e=!1;else if(t&&(e=this._handler(this._data),e instanceof Promise))return e.then(s=>(this._data="",this._hitLimit=!1,s));return this._data="",this._hitLimit=!1,e}},xi=[],jS=class{constructor(){this._handlers=Object.create(null),this._active=xi,this._ident=0,this._handlerFb=()=>{},this._stack={paused:!1,loopPosition:0,fallThrough:!1}}dispose(){this._handlers=Object.create(null),this._handlerFb=()=>{},this._active=xi}registerHandler(t,e){this._handlers[t]===void 0&&(this._handlers[t]=[]);let s=this._handlers[t];return s.push(e),{dispose:()=>{let i=s.indexOf(e);i!==-1&&s.splice(i,1)}}}clearHandler(t){this._handlers[t]&&delete this._handlers[t]}setHandlerFallback(t){this._handlerFb=t}reset(){if(this._active.length)for(let t=this._stack.paused?this._stack.loopPosition-1:this._active.length-1;t>=0;--t)this._active[t].unhook(!1);this._stack.paused=!1,this._active=xi,this._ident=0}hook(t,e){if(this.reset(),this._ident=t,this._active=this._handlers[t]||xi,!this._active.length)this._handlerFb(this._ident,"HOOK",e);else for(let s=this._active.length-1;s>=0;s--)this._active[s].hook(e)}put(t,e,s){if(!this._active.length)this._handlerFb(this._ident,"PUT",cn(t,e,s));else for(let i=this._active.length-1;i>=0;i--)this._active[i].put(t,e,s)}unhook(t,e=!0){if(!this._active.length)this._handlerFb(this._ident,"UNHOOK",t);else{let s=!1,i=this._active.length-1,r=!1;if(this._stack.paused&&(i=this._stack.loopPosition-1,s=e,r=this._stack.fallThrough,this._stack.paused=!1),!r&&s===!1){for(;i>=0&&(s=this._active[i].unhook(t),s!==!0);i--)if(s instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=i,this._stack.fallThrough=!1,s;i--}for(;i>=0;i--)if(s=this._active[i].unhook(!1),s instanceof Promise)return this._stack.paused=!0,this._stack.loopPosition=i,this._stack.fallThrough=!0,s}this._active=xi,this._ident=0}},Ni=new vu;Ni.addParam(0);var _c=class{constructor(t){this._handler=t,this._data="",this._params=Ni,this._hitLimit=!1}hook(t){this._params=t.length>1||t.params[0]?t.clone():Ni,this._data="",this._hitLimit=!1}put(t,e,s){this._hitLimit||(this._data+=cn(t,e,s),this._data.length>1e7&&(this._data="",this._hitLimit=!0))}unhook(t){let e=!1;if(this._hitLimit)e=!1;else if(t&&(e=this._handler(this._data,this._params),e instanceof Promise))return e.then(s=>(this._params=Ni,this._data="",this._hitLimit=!1,s));return this._params=Ni,this._data="",this._hitLimit=!1,e}},NS=class{constructor(t){this.table=new Uint8Array(t)}setDefault(t,e){this.table.fill(t<<4|e)}add(t,e,s,i){this.table[e<<8|t]=s<<4|i}addMany(t,e,s,i){for(let r=0;r<t.length;r++)this.table[e<<8|t[r]]=s<<4|i}},kt=160,ES=(function(){let t=new NS(4095),e=Array.apply(null,Array(256)).map((l,h)=>h),s=(l,h)=>e.slice(l,h),i=s(32,127),r=s(0,24);r.push(25),r.push.apply(r,s(28,32));let o=s(0,14),a;t.setDefault(1,0),t.addMany(i,0,2,0);for(a in o)t.addMany([24,26,153,154],a,3,0),t.addMany(s(128,144),a,3,0),t.addMany(s(144,152),a,3,0),t.add(156,a,0,0),t.add(27,a,11,1),t.add(157,a,4,8),t.addMany([152,158,159],a,0,7),t.add(155,a,11,3),t.add(144,a,11,9);return t.addMany(r,0,3,0),t.addMany(r,1,3,1),t.add(127,1,0,1),t.addMany(r,8,0,8),t.addMany(r,3,3,3),t.add(127,3,0,3),t.addMany(r,4,3,4),t.add(127,4,0,4),t.addMany(r,6,3,6),t.addMany(r,5,3,5),t.add(127,5,0,5),t.addMany(r,2,3,2),t.add(127,2,0,2),t.add(93,1,4,8),t.addMany(i,8,5,8),t.add(127,8,5,8),t.addMany([156,27,24,26,7],8,6,0),t.addMany(s(28,32),8,0,8),t.addMany([88,94,95],1,0,7),t.addMany(i,7,0,7),t.addMany(r,7,0,7),t.add(156,7,0,0),t.add(127,7,0,7),t.add(91,1,11,3),t.addMany(s(64,127),3,7,0),t.addMany(s(48,60),3,8,4),t.addMany([60,61,62,63],3,9,4),t.addMany(s(48,60),4,8,4),t.addMany(s(64,127),4,7,0),t.addMany([60,61,62,63],4,0,6),t.addMany(s(32,64),6,0,6),t.add(127,6,0,6),t.addMany(s(64,127),6,0,0),t.addMany(s(32,48),3,9,5),t.addMany(s(32,48),5,9,5),t.addMany(s(48,64),5,0,6),t.addMany(s(64,127),5,7,0),t.addMany(s(32,48),4,9,5),t.addMany(s(32,48),1,9,2),t.addMany(s(32,48),2,9,2),t.addMany(s(48,127),2,10,0),t.addMany(s(48,80),1,10,0),t.addMany(s(81,88),1,10,0),t.addMany([89,90,92],1,10,0),t.addMany(s(96,127),1,10,0),t.add(80,1,11,9),t.addMany(r,9,0,9),t.add(127,9,0,9),t.addMany(s(28,32),9,0,9),t.addMany(s(32,48),9,9,12),t.addMany(s(48,60),9,8,10),t.addMany([60,61,62,63],9,9,10),t.addMany(r,11,0,11),t.addMany(s(32,128),11,0,11),t.addMany(s(28,32),11,0,11),t.addMany(r,10,0,10),t.add(127,10,0,10),t.addMany(s(28,32),10,0,10),t.addMany(s(48,60),10,8,10),t.addMany([60,61,62,63],10,0,11),t.addMany(s(32,48),10,9,12),t.addMany(r,12,0,12),t.add(127,12,0,12),t.addMany(s(28,32),12,0,12),t.addMany(s(32,48),12,9,12),t.addMany(s(48,64),12,0,11),t.addMany(s(64,127),12,12,13),t.addMany(s(64,127),10,12,13),t.addMany(s(64,127),9,12,13),t.addMany(r,13,13,13),t.addMany(i,13,13,13),t.add(127,13,0,13),t.addMany([27,156,24,26],13,14,0),t.add(kt,0,2,0),t.add(kt,8,5,8),t.add(kt,6,0,6),t.add(kt,11,0,11),t.add(kt,13,13,13),t})(),TS=class extends ye{constructor(t=ES){super(),this._transitions=t,this._parseStack={state:0,handlers:[],handlerPos:0,transition:0,chunkPos:0},this.initialState=0,this.currentState=this.initialState,this._params=new vu,this._params.addParam(0),this._collect=0,this.precedingJoinState=0,this._printHandlerFb=(e,s,i)=>{},this._executeHandlerFb=e=>{},this._csiHandlerFb=(e,s)=>{},this._escHandlerFb=e=>{},this._errorHandlerFb=e=>e,this._printHandler=this._printHandlerFb,this._executeHandlers=Object.create(null),this._csiHandlers=Object.create(null),this._escHandlers=Object.create(null),this._register(Ie(()=>{this._csiHandlers=Object.create(null),this._executeHandlers=Object.create(null),this._escHandlers=Object.create(null)})),this._oscParser=this._register(new kS),this._dcsParser=this._register(new jS),this._errorHandler=this._errorHandlerFb,this.registerEscHandler({final:"\\"},()=>!0)}_identifier(t,e=[64,126]){let s=0;if(t.prefix){if(t.prefix.length>1)throw new Error("only one byte as prefix supported");if(s=t.prefix.charCodeAt(0),s&&60>s||s>63)throw new Error("prefix must be in range 0x3c .. 0x3f")}if(t.intermediates){if(t.intermediates.length>2)throw new Error("only two bytes as intermediates are supported");for(let r=0;r<t.intermediates.length;++r){let o=t.intermediates.charCodeAt(r);if(32>o||o>47)throw new Error("intermediate must be in range 0x20 .. 0x2f");s<<=8,s|=o}}if(t.final.length!==1)throw new Error("final must be a single byte");let i=t.final.charCodeAt(0);if(e[0]>i||i>e[1])throw new Error(`final must be in range ${e[0]} .. ${e[1]}`);return s<<=8,s|=i,s}identToString(t){let e=[];for(;t;)e.push(String.fromCharCode(t&255)),t>>=8;return e.reverse().join("")}setPrintHandler(t){this._printHandler=t}clearPrintHandler(){this._printHandler=this._printHandlerFb}registerEscHandler(t,e){let s=this._identifier(t,[48,126]);this._escHandlers[s]===void 0&&(this._escHandlers[s]=[]);let i=this._escHandlers[s];return i.push(e),{dispose:()=>{let r=i.indexOf(e);r!==-1&&i.splice(r,1)}}}clearEscHandler(t){this._escHandlers[this._identifier(t,[48,126])]&&delete this._escHandlers[this._identifier(t,[48,126])]}setEscHandlerFallback(t){this._escHandlerFb=t}setExecuteHandler(t,e){this._executeHandlers[t.charCodeAt(0)]=e}clearExecuteHandler(t){this._executeHandlers[t.charCodeAt(0)]&&delete this._executeHandlers[t.charCodeAt(0)]}setExecuteHandlerFallback(t){this._executeHandlerFb=t}registerCsiHandler(t,e){let s=this._identifier(t);this._csiHandlers[s]===void 0&&(this._csiHandlers[s]=[]);let i=this._csiHandlers[s];return i.push(e),{dispose:()=>{let r=i.indexOf(e);r!==-1&&i.splice(r,1)}}}clearCsiHandler(t){this._csiHandlers[this._identifier(t)]&&delete this._csiHandlers[this._identifier(t)]}setCsiHandlerFallback(t){this._csiHandlerFb=t}registerDcsHandler(t,e){return this._dcsParser.registerHandler(this._identifier(t),e)}clearDcsHandler(t){this._dcsParser.clearHandler(this._identifier(t))}setDcsHandlerFallback(t){this._dcsParser.setHandlerFallback(t)}registerOscHandler(t,e){return this._oscParser.registerHandler(t,e)}clearOscHandler(t){this._oscParser.clearHandler(t)}setOscHandlerFallback(t){this._oscParser.setHandlerFallback(t)}setErrorHandler(t){this._errorHandler=t}clearErrorHandler(){this._errorHandler=this._errorHandlerFb}reset(){this.currentState=this.initialState,this._oscParser.reset(),this._dcsParser.reset(),this._params.reset(),this._params.addParam(0),this._collect=0,this.precedingJoinState=0,this._parseStack.state!==0&&(this._parseStack.state=2,this._parseStack.handlers=[])}_preserveStack(t,e,s,i,r){this._parseStack.state=t,this._parseStack.handlers=e,this._parseStack.handlerPos=s,this._parseStack.transition=i,this._parseStack.chunkPos=r}parse(t,e,s){let i=0,r=0,o=0,a;if(this._parseStack.state)if(this._parseStack.state===2)this._parseStack.state=0,o=this._parseStack.chunkPos+1;else{if(s===void 0||this._parseStack.state===1)throw this._parseStack.state=1,new Error("improper continuation due to previous async handler, giving up parsing");let l=this._parseStack.handlers,h=this._parseStack.handlerPos-1;switch(this._parseStack.state){case 3:if(s===!1&&h>-1){for(;h>=0&&(a=l[h](this._params),a!==!0);h--)if(a instanceof Promise)return this._parseStack.handlerPos=h,a}this._parseStack.handlers=[];break;case 4:if(s===!1&&h>-1){for(;h>=0&&(a=l[h](),a!==!0);h--)if(a instanceof Promise)return this._parseStack.handlerPos=h,a}this._parseStack.handlers=[];break;case 6:if(i=t[this._parseStack.chunkPos],a=this._dcsParser.unhook(i!==24&&i!==26,s),a)return a;i===27&&(this._parseStack.transition|=1),this._params.reset(),this._params.addParam(0),this._collect=0;break;case 5:if(i=t[this._parseStack.chunkPos],a=this._oscParser.end(i!==24&&i!==26,s),a)return a;i===27&&(this._parseStack.transition|=1),this._params.reset(),this._params.addParam(0),this._collect=0;break}this._parseStack.state=0,o=this._parseStack.chunkPos+1,this.precedingJoinState=0,this.currentState=this._parseStack.transition&15}for(let l=o;l<e;++l){switch(i=t[l],r=this._transitions.table[this.currentState<<8|(i<160?i:kt)],r>>4){case 2:for(let f=l+1;;++f){if(f>=e||(i=t[f])<32||i>126&&i<kt){this._printHandler(t,l,f),l=f-1;break}if(++f>=e||(i=t[f])<32||i>126&&i<kt){this._printHandler(t,l,f),l=f-1;break}if(++f>=e||(i=t[f])<32||i>126&&i<kt){this._printHandler(t,l,f),l=f-1;break}if(++f>=e||(i=t[f])<32||i>126&&i<kt){this._printHandler(t,l,f),l=f-1;break}}break;case 3:this._executeHandlers[i]?this._executeHandlers[i]():this._executeHandlerFb(i),this.precedingJoinState=0;break;case 0:break;case 1:if(this._errorHandler({position:l,code:i,currentState:this.currentState,collect:this._collect,params:this._params,abort:!1}).abort)return;break;case 7:let h=this._csiHandlers[this._collect<<8|i],c=h?h.length-1:-1;for(;c>=0&&(a=h[c](this._params),a!==!0);c--)if(a instanceof Promise)return this._preserveStack(3,h,c,r,l),a;c<0&&this._csiHandlerFb(this._collect<<8|i,this._params),this.precedingJoinState=0;break;case 8:do switch(i){case 59:this._params.addParam(0);break;case 58:this._params.addSubParam(-1);break;default:this._params.addDigit(i-48)}while(++l<e&&(i=t[l])>47&&i<60);l--;break;case 9:this._collect<<=8,this._collect|=i;break;case 10:let d=this._escHandlers[this._collect<<8|i],u=d?d.length-1:-1;for(;u>=0&&(a=d[u](),a!==!0);u--)if(a instanceof Promise)return this._preserveStack(4,d,u,r,l),a;u<0&&this._escHandlerFb(this._collect<<8|i),this.precedingJoinState=0;break;case 11:this._params.reset(),this._params.addParam(0),this._collect=0;break;case 12:this._dcsParser.hook(this._collect<<8|i,this._params);break;case 13:for(let f=l+1;;++f)if(f>=e||(i=t[f])===24||i===26||i===27||i>127&&i<kt){this._dcsParser.put(t,l,f),l=f-1;break}break;case 14:if(a=this._dcsParser.unhook(i!==24&&i!==26),a)return this._preserveStack(6,[],0,r,l),a;i===27&&(r|=1),this._params.reset(),this._params.addParam(0),this._collect=0,this.precedingJoinState=0;break;case 4:this._oscParser.start();break;case 5:for(let f=l+1;;f++)if(f>=e||(i=t[f])<32||i>127&&i<kt){this._oscParser.put(t,l,f),l=f-1;break}break;case 6:if(a=this._oscParser.end(i!==24&&i!==26),a)return this._preserveStack(5,[],0,r,l),a;i===27&&(r|=1),this._params.reset(),this._params.addParam(0),this._collect=0,this.precedingJoinState=0;break}this.currentState=r&15}}},RS=/^([\da-f])\/([\da-f])\/([\da-f])$|^([\da-f]{2})\/([\da-f]{2})\/([\da-f]{2})$|^([\da-f]{3})\/([\da-f]{3})\/([\da-f]{3})$|^([\da-f]{4})\/([\da-f]{4})\/([\da-f]{4})$/,PS=/^[\da-f]+$/;function gc(t){if(!t)return;let e=t.toLowerCase();if(e.indexOf("rgb:")===0){e=e.slice(4);let s=RS.exec(e);if(s){let i=s[1]?15:s[4]?255:s[7]?4095:65535;return[Math.round(parseInt(s[1]||s[4]||s[7]||s[10],16)/i*255),Math.round(parseInt(s[2]||s[5]||s[8]||s[11],16)/i*255),Math.round(parseInt(s[3]||s[6]||s[9]||s[12],16)/i*255)]}}else if(e.indexOf("#")===0&&(e=e.slice(1),PS.exec(e)&&[3,6,9,12].includes(e.length))){let s=e.length/3,i=[0,0,0];for(let r=0;r<3;++r){let o=parseInt(e.slice(s*r,s*r+s),16);i[r]=s===1?o<<4:s===2?o:s===3?o>>4:o>>8}return i}}function Ln(t,e){let s=t.toString(16),i=s.length<2?"0"+s:s;switch(e){case 4:return s[0];case 8:return i;case 12:return(i+i).slice(0,3);default:return i+i}}function DS(t,e=16){let[s,i,r]=t;return`rgb:${Ln(s,e)}/${Ln(i,e)}/${Ln(r,e)}`}var AS={"(":0,")":1,"*":2,"+":3,"-":1,".":2},ds=131072,vc=10;function xc(t,e){if(t>24)return e.setWinLines||!1;switch(t){case 1:return!!e.restoreWin;case 2:return!!e.minimizeWin;case 3:return!!e.setWinPosition;case 4:return!!e.setWinSizePixels;case 5:return!!e.raiseWin;case 6:return!!e.lowerWin;case 7:return!!e.refreshWin;case 8:return!!e.setWinSizeChars;case 9:return!!e.maximizeWin;case 10:return!!e.fullscreenWin;case 11:return!!e.getWinState;case 13:return!!e.getWinPosition;case 14:return!!e.getWinSizePixels;case 15:return!!e.getScreenSizePixels;case 16:return!!e.getCellSizePixels;case 18:return!!e.getWinSizeChars;case 19:return!!e.getScreenSizeChars;case 20:return!!e.getIconTitle;case 21:return!!e.getWinTitle;case 22:return!!e.pushTitle;case 23:return!!e.popTitle;case 24:return!!e.setWinLines}return!1}var bc=5e3,yc=0,IS=class extends ye{constructor(t,e,s,i,r,o,a,l,h=new TS){super(),this._bufferService=t,this._charsetService=e,this._coreService=s,this._logService=i,this._optionsService=r,this._oscLinkService=o,this._coreMouseService=a,this._unicodeService=l,this._parser=h,this._parseBuffer=new Uint32Array(4096),this._stringDecoder=new Qb,this._utf8Decoder=new ey,this._windowTitle="",this._iconName="",this._windowTitleStack=[],this._iconNameStack=[],this._curAttrData=We.clone(),this._eraseAttrDataInternal=We.clone(),this._onRequestBell=this._register(new ae),this.onRequestBell=this._onRequestBell.event,this._onRequestRefreshRows=this._register(new ae),this.onRequestRefreshRows=this._onRequestRefreshRows.event,this._onRequestReset=this._register(new ae),this.onRequestReset=this._onRequestReset.event,this._onRequestSendFocus=this._register(new ae),this.onRequestSendFocus=this._onRequestSendFocus.event,this._onRequestSyncScrollBar=this._register(new ae),this.onRequestSyncScrollBar=this._onRequestSyncScrollBar.event,this._onRequestWindowsOptionsReport=this._register(new ae),this.onRequestWindowsOptionsReport=this._onRequestWindowsOptionsReport.event,this._onA11yChar=this._register(new ae),this.onA11yChar=this._onA11yChar.event,this._onA11yTab=this._register(new ae),this.onA11yTab=this._onA11yTab.event,this._onCursorMove=this._register(new ae),this.onCursorMove=this._onCursorMove.event,this._onLineFeed=this._register(new ae),this.onLineFeed=this._onLineFeed.event,this._onScroll=this._register(new ae),this.onScroll=this._onScroll.event,this._onTitleChange=this._register(new ae),this.onTitleChange=this._onTitleChange.event,this._onColor=this._register(new ae),this.onColor=this._onColor.event,this._parseStack={paused:!1,cursorStartX:0,cursorStartY:0,decodedLength:0,position:0},this._specialColors=[256,257,258],this._register(this._parser),this._dirtyRowTracker=new Mo(this._bufferService),this._activeBuffer=this._bufferService.buffer,this._register(this._bufferService.buffers.onBufferActivate(c=>this._activeBuffer=c.activeBuffer)),this._parser.setCsiHandlerFallback((c,d)=>{this._logService.debug("Unknown CSI code: ",{identifier:this._parser.identToString(c),params:d.toArray()})}),this._parser.setEscHandlerFallback(c=>{this._logService.debug("Unknown ESC code: ",{identifier:this._parser.identToString(c)})}),this._parser.setExecuteHandlerFallback(c=>{this._logService.debug("Unknown EXECUTE code: ",{code:c})}),this._parser.setOscHandlerFallback((c,d,u)=>{this._logService.debug("Unknown OSC code: ",{identifier:c,action:d,data:u})}),this._parser.setDcsHandlerFallback((c,d,u)=>{d==="HOOK"&&(u=u.toArray()),this._logService.debug("Unknown DCS code: ",{identifier:this._parser.identToString(c),action:d,payload:u})}),this._parser.setPrintHandler((c,d,u)=>this.print(c,d,u)),this._parser.registerCsiHandler({final:"@"},c=>this.insertChars(c)),this._parser.registerCsiHandler({intermediates:" ",final:"@"},c=>this.scrollLeft(c)),this._parser.registerCsiHandler({final:"A"},c=>this.cursorUp(c)),this._parser.registerCsiHandler({intermediates:" ",final:"A"},c=>this.scrollRight(c)),this._parser.registerCsiHandler({final:"B"},c=>this.cursorDown(c)),this._parser.registerCsiHandler({final:"C"},c=>this.cursorForward(c)),this._parser.registerCsiHandler({final:"D"},c=>this.cursorBackward(c)),this._parser.registerCsiHandler({final:"E"},c=>this.cursorNextLine(c)),this._parser.registerCsiHandler({final:"F"},c=>this.cursorPrecedingLine(c)),this._parser.registerCsiHandler({final:"G"},c=>this.cursorCharAbsolute(c)),this._parser.registerCsiHandler({final:"H"},c=>this.cursorPosition(c)),this._parser.registerCsiHandler({final:"I"},c=>this.cursorForwardTab(c)),this._parser.registerCsiHandler({final:"J"},c=>this.eraseInDisplay(c,!1)),this._parser.registerCsiHandler({prefix:"?",final:"J"},c=>this.eraseInDisplay(c,!0)),this._parser.registerCsiHandler({final:"K"},c=>this.eraseInLine(c,!1)),this._parser.registerCsiHandler({prefix:"?",final:"K"},c=>this.eraseInLine(c,!0)),this._parser.registerCsiHandler({final:"L"},c=>this.insertLines(c)),this._parser.registerCsiHandler({final:"M"},c=>this.deleteLines(c)),this._parser.registerCsiHandler({final:"P"},c=>this.deleteChars(c)),this._parser.registerCsiHandler({final:"S"},c=>this.scrollUp(c)),this._parser.registerCsiHandler({final:"T"},c=>this.scrollDown(c)),this._parser.registerCsiHandler({final:"X"},c=>this.eraseChars(c)),this._parser.registerCsiHandler({final:"Z"},c=>this.cursorBackwardTab(c)),this._parser.registerCsiHandler({final:"`"},c=>this.charPosAbsolute(c)),this._parser.registerCsiHandler({final:"a"},c=>this.hPositionRelative(c)),this._parser.registerCsiHandler({final:"b"},c=>this.repeatPrecedingCharacter(c)),this._parser.registerCsiHandler({final:"c"},c=>this.sendDeviceAttributesPrimary(c)),this._parser.registerCsiHandler({prefix:">",final:"c"},c=>this.sendDeviceAttributesSecondary(c)),this._parser.registerCsiHandler({final:"d"},c=>this.linePosAbsolute(c)),this._parser.registerCsiHandler({final:"e"},c=>this.vPositionRelative(c)),this._parser.registerCsiHandler({final:"f"},c=>this.hVPosition(c)),this._parser.registerCsiHandler({final:"g"},c=>this.tabClear(c)),this._parser.registerCsiHandler({final:"h"},c=>this.setMode(c)),this._parser.registerCsiHandler({prefix:"?",final:"h"},c=>this.setModePrivate(c)),this._parser.registerCsiHandler({final:"l"},c=>this.resetMode(c)),this._parser.registerCsiHandler({prefix:"?",final:"l"},c=>this.resetModePrivate(c)),this._parser.registerCsiHandler({final:"m"},c=>this.charAttributes(c)),this._parser.registerCsiHandler({final:"n"},c=>this.deviceStatus(c)),this._parser.registerCsiHandler({prefix:"?",final:"n"},c=>this.deviceStatusPrivate(c)),this._parser.registerCsiHandler({intermediates:"!",final:"p"},c=>this.softReset(c)),this._parser.registerCsiHandler({intermediates:" ",final:"q"},c=>this.setCursorStyle(c)),this._parser.registerCsiHandler({final:"r"},c=>this.setScrollRegion(c)),this._parser.registerCsiHandler({final:"s"},c=>this.saveCursor(c)),this._parser.registerCsiHandler({final:"t"},c=>this.windowOptions(c)),this._parser.registerCsiHandler({final:"u"},c=>this.restoreCursor(c)),this._parser.registerCsiHandler({intermediates:"'",final:"}"},c=>this.insertColumns(c)),this._parser.registerCsiHandler({intermediates:"'",final:"~"},c=>this.deleteColumns(c)),this._parser.registerCsiHandler({intermediates:'"',final:"q"},c=>this.selectProtected(c)),this._parser.registerCsiHandler({intermediates:"$",final:"p"},c=>this.requestMode(c,!0)),this._parser.registerCsiHandler({prefix:"?",intermediates:"$",final:"p"},c=>this.requestMode(c,!1)),this._parser.setExecuteHandler(Z.BEL,()=>this.bell()),this._parser.setExecuteHandler(Z.LF,()=>this.lineFeed()),this._parser.setExecuteHandler(Z.VT,()=>this.lineFeed()),this._parser.setExecuteHandler(Z.FF,()=>this.lineFeed()),this._parser.setExecuteHandler(Z.CR,()=>this.carriageReturn()),this._parser.setExecuteHandler(Z.BS,()=>this.backspace()),this._parser.setExecuteHandler(Z.HT,()=>this.tab()),this._parser.setExecuteHandler(Z.SO,()=>this.shiftOut()),this._parser.setExecuteHandler(Z.SI,()=>this.shiftIn()),this._parser.setExecuteHandler(Cr.IND,()=>this.index()),this._parser.setExecuteHandler(Cr.NEL,()=>this.nextLine()),this._parser.setExecuteHandler(Cr.HTS,()=>this.tabSet()),this._parser.registerOscHandler(0,new _t(c=>(this.setTitle(c),this.setIconName(c),!0))),this._parser.registerOscHandler(1,new _t(c=>this.setIconName(c))),this._parser.registerOscHandler(2,new _t(c=>this.setTitle(c))),this._parser.registerOscHandler(4,new _t(c=>this.setOrReportIndexedColor(c))),this._parser.registerOscHandler(8,new _t(c=>this.setHyperlink(c))),this._parser.registerOscHandler(10,new _t(c=>this.setOrReportFgColor(c))),this._parser.registerOscHandler(11,new _t(c=>this.setOrReportBgColor(c))),this._parser.registerOscHandler(12,new _t(c=>this.setOrReportCursorColor(c))),this._parser.registerOscHandler(104,new _t(c=>this.restoreIndexedColor(c))),this._parser.registerOscHandler(110,new _t(c=>this.restoreFgColor(c))),this._parser.registerOscHandler(111,new _t(c=>this.restoreBgColor(c))),this._parser.registerOscHandler(112,new _t(c=>this.restoreCursorColor(c))),this._parser.registerEscHandler({final:"7"},()=>this.saveCursor()),this._parser.registerEscHandler({final:"8"},()=>this.restoreCursor()),this._parser.registerEscHandler({final:"D"},()=>this.index()),this._parser.registerEscHandler({final:"E"},()=>this.nextLine()),this._parser.registerEscHandler({final:"H"},()=>this.tabSet()),this._parser.registerEscHandler({final:"M"},()=>this.reverseIndex()),this._parser.registerEscHandler({final:"="},()=>this.keypadApplicationMode()),this._parser.registerEscHandler({final:">"},()=>this.keypadNumericMode()),this._parser.registerEscHandler({final:"c"},()=>this.fullReset()),this._parser.registerEscHandler({final:"n"},()=>this.setgLevel(2)),this._parser.registerEscHandler({final:"o"},()=>this.setgLevel(3)),this._parser.registerEscHandler({final:"|"},()=>this.setgLevel(3)),this._parser.registerEscHandler({final:"}"},()=>this.setgLevel(2)),this._parser.registerEscHandler({final:"~"},()=>this.setgLevel(1)),this._parser.registerEscHandler({intermediates:"%",final:"@"},()=>this.selectDefaultCharset()),this._parser.registerEscHandler({intermediates:"%",final:"G"},()=>this.selectDefaultCharset());for(let c in Ge)this._parser.registerEscHandler({intermediates:"(",final:c},()=>this.selectCharset("("+c)),this._parser.registerEscHandler({intermediates:")",final:c},()=>this.selectCharset(")"+c)),this._parser.registerEscHandler({intermediates:"*",final:c},()=>this.selectCharset("*"+c)),this._parser.registerEscHandler({intermediates:"+",final:c},()=>this.selectCharset("+"+c)),this._parser.registerEscHandler({intermediates:"-",final:c},()=>this.selectCharset("-"+c)),this._parser.registerEscHandler({intermediates:".",final:c},()=>this.selectCharset("."+c)),this._parser.registerEscHandler({intermediates:"/",final:c},()=>this.selectCharset("/"+c));this._parser.registerEscHandler({intermediates:"#",final:"8"},()=>this.screenAlignmentPattern()),this._parser.setErrorHandler(c=>(this._logService.error("Parsing error: ",c),c)),this._parser.registerDcsHandler({intermediates:"$",final:"q"},new _c((c,d)=>this.requestStatusString(c,d)))}getAttrData(){return this._curAttrData}_preserveStack(t,e,s,i){this._parseStack.paused=!0,this._parseStack.cursorStartX=t,this._parseStack.cursorStartY=e,this._parseStack.decodedLength=s,this._parseStack.position=i}_logSlowResolvingAsync(t){this._logService.logLevel<=3&&Promise.race([t,new Promise((e,s)=>setTimeout(()=>s("#SLOW_TIMEOUT"),bc))]).catch(e=>{if(e!=="#SLOW_TIMEOUT")throw e;console.warn(`async parser handler taking longer than ${bc} ms`)})}_getCurrentLinkId(){return this._curAttrData.extended.urlId}parse(t,e){let s,i=this._activeBuffer.x,r=this._activeBuffer.y,o=0,a=this._parseStack.paused;if(a){if(s=this._parser.parse(this._parseBuffer,this._parseStack.decodedLength,e))return this._logSlowResolvingAsync(s),s;i=this._parseStack.cursorStartX,r=this._parseStack.cursorStartY,this._parseStack.paused=!1,t.length>ds&&(o=this._parseStack.position+ds)}if(this._logService.logLevel<=1&&this._logService.debug(`parsing data ${typeof t=="string"?` "${t}"`:` "${Array.prototype.map.call(t,c=>String.fromCharCode(c)).join("")}"`}`),this._logService.logLevel===0&&this._logService.trace("parsing data (codes)",typeof t=="string"?t.split("").map(c=>c.charCodeAt(0)):t),this._parseBuffer.length<t.length&&this._parseBuffer.length<ds&&(this._parseBuffer=new Uint32Array(Math.min(t.length,ds))),a||this._dirtyRowTracker.clearRange(),t.length>ds)for(let c=o;c<t.length;c+=ds){let d=c+ds<t.length?c+ds:t.length,u=typeof t=="string"?this._stringDecoder.decode(t.substring(c,d),this._parseBuffer):this._utf8Decoder.decode(t.subarray(c,d),this._parseBuffer);if(s=this._parser.parse(this._parseBuffer,u))return this._preserveStack(i,r,u,c),this._logSlowResolvingAsync(s),s}else if(!a){let c=typeof t=="string"?this._stringDecoder.decode(t,this._parseBuffer):this._utf8Decoder.decode(t,this._parseBuffer);if(s=this._parser.parse(this._parseBuffer,c))return this._preserveStack(i,r,c,0),this._logSlowResolvingAsync(s),s}(this._activeBuffer.x!==i||this._activeBuffer.y!==r)&&this._onCursorMove.fire();let l=this._dirtyRowTracker.end+(this._bufferService.buffer.ybase-this._bufferService.buffer.ydisp),h=this._dirtyRowTracker.start+(this._bufferService.buffer.ybase-this._bufferService.buffer.ydisp);h<this._bufferService.rows&&this._onRequestRefreshRows.fire({start:Math.min(h,this._bufferService.rows-1),end:Math.min(l,this._bufferService.rows-1)})}print(t,e,s){let i,r,o=this._charsetService.charset,a=this._optionsService.rawOptions.screenReaderMode,l=this._bufferService.cols,h=this._coreService.decPrivateModes.wraparound,c=this._coreService.modes.insertMode,d=this._curAttrData,u=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);this._dirtyRowTracker.markDirty(this._activeBuffer.y),this._activeBuffer.x&&s-e>0&&u.getWidth(this._activeBuffer.x-1)===2&&u.setCellFromCodepoint(this._activeBuffer.x-1,0,1,d);let f=this._parser.precedingJoinState;for(let m=e;m<s;++m){if(i=t[m],i<127&&o){let v=o[String.fromCharCode(i)];v&&(i=v.charCodeAt(0))}let p=this._unicodeService.charProperties(i,f);r=bs.extractWidth(p);let _=bs.extractShouldJoin(p),g=_?bs.extractWidth(f):0;if(f=p,a&&this._onA11yChar.fire(us(i)),this._getCurrentLinkId()&&this._oscLinkService.addLineToLink(this._getCurrentLinkId(),this._activeBuffer.ybase+this._activeBuffer.y),this._activeBuffer.x+r-g>l){if(h){let v=u,b=this._activeBuffer.x-g;for(this._activeBuffer.x=g,this._activeBuffer.y++,this._activeBuffer.y===this._activeBuffer.scrollBottom+1?(this._activeBuffer.y--,this._bufferService.scroll(this._eraseAttrData(),!0)):(this._activeBuffer.y>=this._bufferService.rows&&(this._activeBuffer.y=this._bufferService.rows-1),this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y).isWrapped=!0),u=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y),g>0&&u instanceof ki&&u.copyCellsFrom(v,b,0,g,!1);b<l;)v.setCellFromCodepoint(b++,0,1,d)}else if(this._activeBuffer.x=l-1,r===2)continue}if(_&&this._activeBuffer.x){let v=u.getWidth(this._activeBuffer.x-1)?1:2;u.addCodepointToCell(this._activeBuffer.x-v,i,r);for(let b=r-g;--b>=0;)u.setCellFromCodepoint(this._activeBuffer.x++,0,0,d);continue}if(c&&(u.insertCells(this._activeBuffer.x,r-g,this._activeBuffer.getNullCell(d)),u.getWidth(l-1)===2&&u.setCellFromCodepoint(l-1,0,1,d)),u.setCellFromCodepoint(this._activeBuffer.x++,i,r,d),r>0)for(;--r;)u.setCellFromCodepoint(this._activeBuffer.x++,0,0,d)}this._parser.precedingJoinState=f,this._activeBuffer.x<l&&s-e>0&&u.getWidth(this._activeBuffer.x)===0&&!u.hasContent(this._activeBuffer.x)&&u.setCellFromCodepoint(this._activeBuffer.x,0,1,d),this._dirtyRowTracker.markDirty(this._activeBuffer.y)}registerCsiHandler(t,e){return t.final==="t"&&!t.prefix&&!t.intermediates?this._parser.registerCsiHandler(t,s=>xc(s.params[0],this._optionsService.rawOptions.windowOptions)?e(s):!0):this._parser.registerCsiHandler(t,e)}registerDcsHandler(t,e){return this._parser.registerDcsHandler(t,new _c(e))}registerEscHandler(t,e){return this._parser.registerEscHandler(t,e)}registerOscHandler(t,e){return this._parser.registerOscHandler(t,new _t(e))}bell(){return this._onRequestBell.fire(),!0}lineFeed(){return this._dirtyRowTracker.markDirty(this._activeBuffer.y),this._optionsService.rawOptions.convertEol&&(this._activeBuffer.x=0),this._activeBuffer.y++,this._activeBuffer.y===this._activeBuffer.scrollBottom+1?(this._activeBuffer.y--,this._bufferService.scroll(this._eraseAttrData())):this._activeBuffer.y>=this._bufferService.rows?this._activeBuffer.y=this._bufferService.rows-1:this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y).isWrapped=!1,this._activeBuffer.x>=this._bufferService.cols&&this._activeBuffer.x--,this._dirtyRowTracker.markDirty(this._activeBuffer.y),this._onLineFeed.fire(),!0}carriageReturn(){return this._activeBuffer.x=0,!0}backspace(){if(!this._coreService.decPrivateModes.reverseWraparound)return this._restrictCursor(),this._activeBuffer.x>0&&this._activeBuffer.x--,!0;if(this._restrictCursor(this._bufferService.cols),this._activeBuffer.x>0)this._activeBuffer.x--;else if(this._activeBuffer.x===0&&this._activeBuffer.y>this._activeBuffer.scrollTop&&this._activeBuffer.y<=this._activeBuffer.scrollBottom&&this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y)?.isWrapped){this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y).isWrapped=!1,this._activeBuffer.y--,this._activeBuffer.x=this._bufferService.cols-1;let t=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);t.hasWidth(this._activeBuffer.x)&&!t.hasContent(this._activeBuffer.x)&&this._activeBuffer.x--}return this._restrictCursor(),!0}tab(){if(this._activeBuffer.x>=this._bufferService.cols)return!0;let t=this._activeBuffer.x;return this._activeBuffer.x=this._activeBuffer.nextStop(),this._optionsService.rawOptions.screenReaderMode&&this._onA11yTab.fire(this._activeBuffer.x-t),!0}shiftOut(){return this._charsetService.setgLevel(1),!0}shiftIn(){return this._charsetService.setgLevel(0),!0}_restrictCursor(t=this._bufferService.cols-1){this._activeBuffer.x=Math.min(t,Math.max(0,this._activeBuffer.x)),this._activeBuffer.y=this._coreService.decPrivateModes.origin?Math.min(this._activeBuffer.scrollBottom,Math.max(this._activeBuffer.scrollTop,this._activeBuffer.y)):Math.min(this._bufferService.rows-1,Math.max(0,this._activeBuffer.y)),this._dirtyRowTracker.markDirty(this._activeBuffer.y)}_setCursor(t,e){this._dirtyRowTracker.markDirty(this._activeBuffer.y),this._coreService.decPrivateModes.origin?(this._activeBuffer.x=t,this._activeBuffer.y=this._activeBuffer.scrollTop+e):(this._activeBuffer.x=t,this._activeBuffer.y=e),this._restrictCursor(),this._dirtyRowTracker.markDirty(this._activeBuffer.y)}_moveCursor(t,e){this._restrictCursor(),this._setCursor(this._activeBuffer.x+t,this._activeBuffer.y+e)}cursorUp(t){let e=this._activeBuffer.y-this._activeBuffer.scrollTop;return e>=0?this._moveCursor(0,-Math.min(e,t.params[0]||1)):this._moveCursor(0,-(t.params[0]||1)),!0}cursorDown(t){let e=this._activeBuffer.scrollBottom-this._activeBuffer.y;return e>=0?this._moveCursor(0,Math.min(e,t.params[0]||1)):this._moveCursor(0,t.params[0]||1),!0}cursorForward(t){return this._moveCursor(t.params[0]||1,0),!0}cursorBackward(t){return this._moveCursor(-(t.params[0]||1),0),!0}cursorNextLine(t){return this.cursorDown(t),this._activeBuffer.x=0,!0}cursorPrecedingLine(t){return this.cursorUp(t),this._activeBuffer.x=0,!0}cursorCharAbsolute(t){return this._setCursor((t.params[0]||1)-1,this._activeBuffer.y),!0}cursorPosition(t){return this._setCursor(t.length>=2?(t.params[1]||1)-1:0,(t.params[0]||1)-1),!0}charPosAbsolute(t){return this._setCursor((t.params[0]||1)-1,this._activeBuffer.y),!0}hPositionRelative(t){return this._moveCursor(t.params[0]||1,0),!0}linePosAbsolute(t){return this._setCursor(this._activeBuffer.x,(t.params[0]||1)-1),!0}vPositionRelative(t){return this._moveCursor(0,t.params[0]||1),!0}hVPosition(t){return this.cursorPosition(t),!0}tabClear(t){let e=t.params[0];return e===0?delete this._activeBuffer.tabs[this._activeBuffer.x]:e===3&&(this._activeBuffer.tabs={}),!0}cursorForwardTab(t){if(this._activeBuffer.x>=this._bufferService.cols)return!0;let e=t.params[0]||1;for(;e--;)this._activeBuffer.x=this._activeBuffer.nextStop();return!0}cursorBackwardTab(t){if(this._activeBuffer.x>=this._bufferService.cols)return!0;let e=t.params[0]||1;for(;e--;)this._activeBuffer.x=this._activeBuffer.prevStop();return!0}selectProtected(t){let e=t.params[0];return e===1&&(this._curAttrData.bg|=536870912),(e===2||e===0)&&(this._curAttrData.bg&=-536870913),!0}_eraseInBufferLine(t,e,s,i=!1,r=!1){let o=this._activeBuffer.lines.get(this._activeBuffer.ybase+t);o.replaceCells(e,s,this._activeBuffer.getNullCell(this._eraseAttrData()),r),i&&(o.isWrapped=!1)}_resetBufferLine(t,e=!1){let s=this._activeBuffer.lines.get(this._activeBuffer.ybase+t);s&&(s.fill(this._activeBuffer.getNullCell(this._eraseAttrData()),e),this._bufferService.buffer.clearMarkers(this._activeBuffer.ybase+t),s.isWrapped=!1)}eraseInDisplay(t,e=!1){this._restrictCursor(this._bufferService.cols);let s;switch(t.params[0]){case 0:for(s=this._activeBuffer.y,this._dirtyRowTracker.markDirty(s),this._eraseInBufferLine(s++,this._activeBuffer.x,this._bufferService.cols,this._activeBuffer.x===0,e);s<this._bufferService.rows;s++)this._resetBufferLine(s,e);this._dirtyRowTracker.markDirty(s);break;case 1:for(s=this._activeBuffer.y,this._dirtyRowTracker.markDirty(s),this._eraseInBufferLine(s,0,this._activeBuffer.x+1,!0,e),this._activeBuffer.x+1>=this._bufferService.cols&&(this._activeBuffer.lines.get(s+1).isWrapped=!1);s--;)this._resetBufferLine(s,e);this._dirtyRowTracker.markDirty(0);break;case 2:if(this._optionsService.rawOptions.scrollOnEraseInDisplay){for(s=this._bufferService.rows,this._dirtyRowTracker.markRangeDirty(0,s-1);s--&&!this._activeBuffer.lines.get(this._activeBuffer.ybase+s)?.getTrimmedLength(););for(;s>=0;s--)this._bufferService.scroll(this._eraseAttrData())}else{for(s=this._bufferService.rows,this._dirtyRowTracker.markDirty(s-1);s--;)this._resetBufferLine(s,e);this._dirtyRowTracker.markDirty(0)}break;case 3:let i=this._activeBuffer.lines.length-this._bufferService.rows;i>0&&(this._activeBuffer.lines.trimStart(i),this._activeBuffer.ybase=Math.max(this._activeBuffer.ybase-i,0),this._activeBuffer.ydisp=Math.max(this._activeBuffer.ydisp-i,0),this._onScroll.fire(0));break}return!0}eraseInLine(t,e=!1){switch(this._restrictCursor(this._bufferService.cols),t.params[0]){case 0:this._eraseInBufferLine(this._activeBuffer.y,this._activeBuffer.x,this._bufferService.cols,this._activeBuffer.x===0,e);break;case 1:this._eraseInBufferLine(this._activeBuffer.y,0,this._activeBuffer.x+1,!1,e);break;case 2:this._eraseInBufferLine(this._activeBuffer.y,0,this._bufferService.cols,!0,e);break}return this._dirtyRowTracker.markDirty(this._activeBuffer.y),!0}insertLines(t){this._restrictCursor();let e=t.params[0]||1;if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let s=this._activeBuffer.ybase+this._activeBuffer.y,i=this._bufferService.rows-1-this._activeBuffer.scrollBottom,r=this._bufferService.rows-1+this._activeBuffer.ybase-i+1;for(;e--;)this._activeBuffer.lines.splice(r-1,1),this._activeBuffer.lines.splice(s,0,this._activeBuffer.getBlankLine(this._eraseAttrData()));return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.y,this._activeBuffer.scrollBottom),this._activeBuffer.x=0,!0}deleteLines(t){this._restrictCursor();let e=t.params[0]||1;if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let s=this._activeBuffer.ybase+this._activeBuffer.y,i;for(i=this._bufferService.rows-1-this._activeBuffer.scrollBottom,i=this._bufferService.rows-1+this._activeBuffer.ybase-i;e--;)this._activeBuffer.lines.splice(s,1),this._activeBuffer.lines.splice(i,0,this._activeBuffer.getBlankLine(this._eraseAttrData()));return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.y,this._activeBuffer.scrollBottom),this._activeBuffer.x=0,!0}insertChars(t){this._restrictCursor();let e=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);return e&&(e.insertCells(this._activeBuffer.x,t.params[0]||1,this._activeBuffer.getNullCell(this._eraseAttrData())),this._dirtyRowTracker.markDirty(this._activeBuffer.y)),!0}deleteChars(t){this._restrictCursor();let e=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);return e&&(e.deleteCells(this._activeBuffer.x,t.params[0]||1,this._activeBuffer.getNullCell(this._eraseAttrData())),this._dirtyRowTracker.markDirty(this._activeBuffer.y)),!0}scrollUp(t){let e=t.params[0]||1;for(;e--;)this._activeBuffer.lines.splice(this._activeBuffer.ybase+this._activeBuffer.scrollTop,1),this._activeBuffer.lines.splice(this._activeBuffer.ybase+this._activeBuffer.scrollBottom,0,this._activeBuffer.getBlankLine(this._eraseAttrData()));return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}scrollDown(t){let e=t.params[0]||1;for(;e--;)this._activeBuffer.lines.splice(this._activeBuffer.ybase+this._activeBuffer.scrollBottom,1),this._activeBuffer.lines.splice(this._activeBuffer.ybase+this._activeBuffer.scrollTop,0,this._activeBuffer.getBlankLine(We));return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}scrollLeft(t){if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let e=t.params[0]||1;for(let s=this._activeBuffer.scrollTop;s<=this._activeBuffer.scrollBottom;++s){let i=this._activeBuffer.lines.get(this._activeBuffer.ybase+s);i.deleteCells(0,e,this._activeBuffer.getNullCell(this._eraseAttrData())),i.isWrapped=!1}return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}scrollRight(t){if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let e=t.params[0]||1;for(let s=this._activeBuffer.scrollTop;s<=this._activeBuffer.scrollBottom;++s){let i=this._activeBuffer.lines.get(this._activeBuffer.ybase+s);i.insertCells(0,e,this._activeBuffer.getNullCell(this._eraseAttrData())),i.isWrapped=!1}return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}insertColumns(t){if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let e=t.params[0]||1;for(let s=this._activeBuffer.scrollTop;s<=this._activeBuffer.scrollBottom;++s){let i=this._activeBuffer.lines.get(this._activeBuffer.ybase+s);i.insertCells(this._activeBuffer.x,e,this._activeBuffer.getNullCell(this._eraseAttrData())),i.isWrapped=!1}return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}deleteColumns(t){if(this._activeBuffer.y>this._activeBuffer.scrollBottom||this._activeBuffer.y<this._activeBuffer.scrollTop)return!0;let e=t.params[0]||1;for(let s=this._activeBuffer.scrollTop;s<=this._activeBuffer.scrollBottom;++s){let i=this._activeBuffer.lines.get(this._activeBuffer.ybase+s);i.deleteCells(this._activeBuffer.x,e,this._activeBuffer.getNullCell(this._eraseAttrData())),i.isWrapped=!1}return this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom),!0}eraseChars(t){this._restrictCursor();let e=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);return e&&(e.replaceCells(this._activeBuffer.x,this._activeBuffer.x+(t.params[0]||1),this._activeBuffer.getNullCell(this._eraseAttrData())),this._dirtyRowTracker.markDirty(this._activeBuffer.y)),!0}repeatPrecedingCharacter(t){let e=this._parser.precedingJoinState;if(!e)return!0;let s=t.params[0]||1,i=bs.extractWidth(e),r=this._activeBuffer.x-i,o=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y).getString(r),a=new Uint32Array(o.length*s),l=0;for(let c=0;c<o.length;){let d=o.codePointAt(c)||0;a[l++]=d,c+=d>65535?2:1}let h=l;for(let c=1;c<s;++c)a.copyWithin(h,0,l),h+=l;return this.print(a,0,h),!0}sendDeviceAttributesPrimary(t){return t.params[0]>0||(this._is("xterm")||this._is("rxvt-unicode")||this._is("screen")?this._coreService.triggerDataEvent(Z.ESC+"[?1;2c"):this._is("linux")&&this._coreService.triggerDataEvent(Z.ESC+"[?6c")),!0}sendDeviceAttributesSecondary(t){return t.params[0]>0||(this._is("xterm")?this._coreService.triggerDataEvent(Z.ESC+"[>0;276;0c"):this._is("rxvt-unicode")?this._coreService.triggerDataEvent(Z.ESC+"[>85;95;0c"):this._is("linux")?this._coreService.triggerDataEvent(t.params[0]+"c"):this._is("screen")&&this._coreService.triggerDataEvent(Z.ESC+"[>83;40003;0c")),!0}_is(t){return(this._optionsService.rawOptions.termName+"").indexOf(t)===0}setMode(t){for(let e=0;e<t.length;e++)switch(t.params[e]){case 4:this._coreService.modes.insertMode=!0;break;case 20:this._optionsService.options.convertEol=!0;break}return!0}setModePrivate(t){for(let e=0;e<t.length;e++)switch(t.params[e]){case 1:this._coreService.decPrivateModes.applicationCursorKeys=!0;break;case 2:this._charsetService.setgCharset(0,xs),this._charsetService.setgCharset(1,xs),this._charsetService.setgCharset(2,xs),this._charsetService.setgCharset(3,xs);break;case 3:this._optionsService.rawOptions.windowOptions.setWinLines&&(this._bufferService.resize(132,this._bufferService.rows),this._onRequestReset.fire());break;case 6:this._coreService.decPrivateModes.origin=!0,this._setCursor(0,0);break;case 7:this._coreService.decPrivateModes.wraparound=!0;break;case 12:this._optionsService.options.cursorBlink=!0;break;case 45:this._coreService.decPrivateModes.reverseWraparound=!0;break;case 66:this._logService.debug("Serial port requested application keypad."),this._coreService.decPrivateModes.applicationKeypad=!0,this._onRequestSyncScrollBar.fire();break;case 9:this._coreMouseService.activeProtocol="X10";break;case 1e3:this._coreMouseService.activeProtocol="VT200";break;case 1002:this._coreMouseService.activeProtocol="DRAG";break;case 1003:this._coreMouseService.activeProtocol="ANY";break;case 1004:this._coreService.decPrivateModes.sendFocus=!0,this._onRequestSendFocus.fire();break;case 1005:this._logService.debug("DECSET 1005 not supported (see #2507)");break;case 1006:this._coreMouseService.activeEncoding="SGR";break;case 1015:this._logService.debug("DECSET 1015 not supported (see #2507)");break;case 1016:this._coreMouseService.activeEncoding="SGR_PIXELS";break;case 25:this._coreService.isCursorHidden=!1;break;case 1048:this.saveCursor();break;case 1049:this.saveCursor();case 47:case 1047:this._bufferService.buffers.activateAltBuffer(this._eraseAttrData()),this._coreService.isCursorInitialized=!0,this._onRequestRefreshRows.fire(void 0),this._onRequestSyncScrollBar.fire();break;case 2004:this._coreService.decPrivateModes.bracketedPasteMode=!0;break;case 2026:this._coreService.decPrivateModes.synchronizedOutput=!0;break}return!0}resetMode(t){for(let e=0;e<t.length;e++)switch(t.params[e]){case 4:this._coreService.modes.insertMode=!1;break;case 20:this._optionsService.options.convertEol=!1;break}return!0}resetModePrivate(t){for(let e=0;e<t.length;e++)switch(t.params[e]){case 1:this._coreService.decPrivateModes.applicationCursorKeys=!1;break;case 3:this._optionsService.rawOptions.windowOptions.setWinLines&&(this._bufferService.resize(80,this._bufferService.rows),this._onRequestReset.fire());break;case 6:this._coreService.decPrivateModes.origin=!1,this._setCursor(0,0);break;case 7:this._coreService.decPrivateModes.wraparound=!1;break;case 12:this._optionsService.options.cursorBlink=!1;break;case 45:this._coreService.decPrivateModes.reverseWraparound=!1;break;case 66:this._logService.debug("Switching back to normal keypad."),this._coreService.decPrivateModes.applicationKeypad=!1,this._onRequestSyncScrollBar.fire();break;case 9:case 1e3:case 1002:case 1003:this._coreMouseService.activeProtocol="NONE";break;case 1004:this._coreService.decPrivateModes.sendFocus=!1;break;case 1005:this._logService.debug("DECRST 1005 not supported (see #2507)");break;case 1006:this._coreMouseService.activeEncoding="DEFAULT";break;case 1015:this._logService.debug("DECRST 1015 not supported (see #2507)");break;case 1016:this._coreMouseService.activeEncoding="DEFAULT";break;case 25:this._coreService.isCursorHidden=!0;break;case 1048:this.restoreCursor();break;case 1049:case 47:case 1047:this._bufferService.buffers.activateNormalBuffer(),t.params[e]===1049&&this.restoreCursor(),this._coreService.isCursorInitialized=!0,this._onRequestRefreshRows.fire(void 0),this._onRequestSyncScrollBar.fire();break;case 2004:this._coreService.decPrivateModes.bracketedPasteMode=!1;break;case 2026:this._coreService.decPrivateModes.synchronizedOutput=!1,this._onRequestRefreshRows.fire(void 0);break}return!0}requestMode(t,e){let s;(_=>(_[_.NOT_RECOGNIZED=0]="NOT_RECOGNIZED",_[_.SET=1]="SET",_[_.RESET=2]="RESET",_[_.PERMANENTLY_SET=3]="PERMANENTLY_SET",_[_.PERMANENTLY_RESET=4]="PERMANENTLY_RESET"))(s||={});let i=this._coreService.decPrivateModes,{activeProtocol:r,activeEncoding:o}=this._coreMouseService,a=this._coreService,{buffers:l,cols:h}=this._bufferService,{active:c,alt:d}=l,u=this._optionsService.rawOptions,f=(_,g)=>(a.triggerDataEvent(`${Z.ESC}[${e?"":"?"}${_};${g}$y`),!0),m=_=>_?1:2,p=t.params[0];return e?p===2?f(p,4):p===4?f(p,m(a.modes.insertMode)):p===12?f(p,3):p===20?f(p,m(u.convertEol)):f(p,0):p===1?f(p,m(i.applicationCursorKeys)):p===3?f(p,u.windowOptions.setWinLines?h===80?2:h===132?1:0:0):p===6?f(p,m(i.origin)):p===7?f(p,m(i.wraparound)):p===8?f(p,3):p===9?f(p,m(r==="X10")):p===12?f(p,m(u.cursorBlink)):p===25?f(p,m(!a.isCursorHidden)):p===45?f(p,m(i.reverseWraparound)):p===66?f(p,m(i.applicationKeypad)):p===67?f(p,4):p===1e3?f(p,m(r==="VT200")):p===1002?f(p,m(r==="DRAG")):p===1003?f(p,m(r==="ANY")):p===1004?f(p,m(i.sendFocus)):p===1005?f(p,4):p===1006?f(p,m(o==="SGR")):p===1015?f(p,4):p===1016?f(p,m(o==="SGR_PIXELS")):p===1048?f(p,1):p===47||p===1047||p===1049?f(p,m(c===d)):p===2004?f(p,m(i.bracketedPasteMode)):p===2026?f(p,m(i.synchronizedOutput)):f(p,0)}_updateAttrColor(t,e,s,i,r){return e===2?(t|=50331648,t&=-16777216,t|=Zi.fromColorRGB([s,i,r])):e===5&&(t&=-50331904,t|=33554432|s&255),t}_extractColor(t,e,s){let i=[0,0,-1,0,0,0],r=0,o=0;do{if(i[o+r]=t.params[e+o],t.hasSubParams(e+o)){let a=t.getSubParams(e+o),l=0;do i[1]===5&&(r=1),i[o+l+1+r]=a[l];while(++l<a.length&&l+o+1+r<i.length);break}if(i[1]===5&&o+r>=2||i[1]===2&&o+r>=5)break;i[1]&&(r=1)}while(++o+e<t.length&&o+r<i.length);for(let a=2;a<i.length;++a)i[a]===-1&&(i[a]=0);switch(i[0]){case 38:s.fg=this._updateAttrColor(s.fg,i[1],i[3],i[4],i[5]);break;case 48:s.bg=this._updateAttrColor(s.bg,i[1],i[3],i[4],i[5]);break;case 58:s.extended=s.extended.clone(),s.extended.underlineColor=this._updateAttrColor(s.extended.underlineColor,i[1],i[3],i[4],i[5])}return o}_processUnderline(t,e){e.extended=e.extended.clone(),(!~t||t>5)&&(t=1),e.extended.underlineStyle=t,e.fg|=268435456,t===0&&(e.fg&=-268435457),e.updateExtended()}_processSGR0(t){t.fg=We.fg,t.bg=We.bg,t.extended=t.extended.clone(),t.extended.underlineStyle=0,t.extended.underlineColor&=-67108864,t.updateExtended()}charAttributes(t){if(t.length===1&&t.params[0]===0)return this._processSGR0(this._curAttrData),!0;let e=t.length,s,i=this._curAttrData;for(let r=0;r<e;r++)s=t.params[r],s>=30&&s<=37?(i.fg&=-50331904,i.fg|=16777216|s-30):s>=40&&s<=47?(i.bg&=-50331904,i.bg|=16777216|s-40):s>=90&&s<=97?(i.fg&=-50331904,i.fg|=16777216|s-90|8):s>=100&&s<=107?(i.bg&=-50331904,i.bg|=16777216|s-100|8):s===0?this._processSGR0(i):s===1?i.fg|=134217728:s===3?i.bg|=67108864:s===4?(i.fg|=268435456,this._processUnderline(t.hasSubParams(r)?t.getSubParams(r)[0]:1,i)):s===5?i.fg|=536870912:s===7?i.fg|=67108864:s===8?i.fg|=1073741824:s===9?i.fg|=2147483648:s===2?i.bg|=134217728:s===21?this._processUnderline(2,i):s===22?(i.fg&=-134217729,i.bg&=-134217729):s===23?i.bg&=-67108865:s===24?(i.fg&=-268435457,this._processUnderline(0,i)):s===25?i.fg&=-536870913:s===27?i.fg&=-67108865:s===28?i.fg&=-1073741825:s===29?i.fg&=2147483647:s===39?(i.fg&=-67108864,i.fg|=We.fg&16777215):s===49?(i.bg&=-67108864,i.bg|=We.bg&16777215):s===38||s===48||s===58?r+=this._extractColor(t,r,i):s===53?i.bg|=1073741824:s===55?i.bg&=-1073741825:s===59?(i.extended=i.extended.clone(),i.extended.underlineColor=-1,i.updateExtended()):s===100?(i.fg&=-67108864,i.fg|=We.fg&16777215,i.bg&=-67108864,i.bg|=We.bg&16777215):this._logService.debug("Unknown SGR attribute: %d.",s);return!0}deviceStatus(t){switch(t.params[0]){case 5:this._coreService.triggerDataEvent(`${Z.ESC}[0n`);break;case 6:let e=this._activeBuffer.y+1,s=this._activeBuffer.x+1;this._coreService.triggerDataEvent(`${Z.ESC}[${e};${s}R`);break}return!0}deviceStatusPrivate(t){if(t.params[0]===6){let e=this._activeBuffer.y+1,s=this._activeBuffer.x+1;this._coreService.triggerDataEvent(`${Z.ESC}[?${e};${s}R`)}return!0}softReset(t){return this._coreService.isCursorHidden=!1,this._onRequestSyncScrollBar.fire(),this._activeBuffer.scrollTop=0,this._activeBuffer.scrollBottom=this._bufferService.rows-1,this._curAttrData=We.clone(),this._coreService.reset(),this._charsetService.reset(),this._activeBuffer.savedX=0,this._activeBuffer.savedY=this._activeBuffer.ybase,this._activeBuffer.savedCurAttrData.fg=this._curAttrData.fg,this._activeBuffer.savedCurAttrData.bg=this._curAttrData.bg,this._activeBuffer.savedCharset=this._charsetService.charset,this._coreService.decPrivateModes.origin=!1,!0}setCursorStyle(t){let e=t.length===0?1:t.params[0];if(e===0)this._coreService.decPrivateModes.cursorStyle=void 0,this._coreService.decPrivateModes.cursorBlink=void 0;else{switch(e){case 1:case 2:this._coreService.decPrivateModes.cursorStyle="block";break;case 3:case 4:this._coreService.decPrivateModes.cursorStyle="underline";break;case 5:case 6:this._coreService.decPrivateModes.cursorStyle="bar";break}let s=e%2===1;this._coreService.decPrivateModes.cursorBlink=s}return!0}setScrollRegion(t){let e=t.params[0]||1,s;return(t.length<2||(s=t.params[1])>this._bufferService.rows||s===0)&&(s=this._bufferService.rows),s>e&&(this._activeBuffer.scrollTop=e-1,this._activeBuffer.scrollBottom=s-1,this._setCursor(0,0)),!0}windowOptions(t){if(!xc(t.params[0],this._optionsService.rawOptions.windowOptions))return!0;let e=t.length>1?t.params[1]:0;switch(t.params[0]){case 14:e!==2&&this._onRequestWindowsOptionsReport.fire(0);break;case 16:this._onRequestWindowsOptionsReport.fire(1);break;case 18:this._bufferService&&this._coreService.triggerDataEvent(`${Z.ESC}[8;${this._bufferService.rows};${this._bufferService.cols}t`);break;case 22:(e===0||e===2)&&(this._windowTitleStack.push(this._windowTitle),this._windowTitleStack.length>vc&&this._windowTitleStack.shift()),(e===0||e===1)&&(this._iconNameStack.push(this._iconName),this._iconNameStack.length>vc&&this._iconNameStack.shift());break;case 23:(e===0||e===2)&&this._windowTitleStack.length&&this.setTitle(this._windowTitleStack.pop()),(e===0||e===1)&&this._iconNameStack.length&&this.setIconName(this._iconNameStack.pop());break}return!0}saveCursor(t){return this._activeBuffer.savedX=this._activeBuffer.x,this._activeBuffer.savedY=this._activeBuffer.ybase+this._activeBuffer.y,this._activeBuffer.savedCurAttrData.fg=this._curAttrData.fg,this._activeBuffer.savedCurAttrData.bg=this._curAttrData.bg,this._activeBuffer.savedCharset=this._charsetService.charset,!0}restoreCursor(t){return this._activeBuffer.x=this._activeBuffer.savedX||0,this._activeBuffer.y=Math.max(this._activeBuffer.savedY-this._activeBuffer.ybase,0),this._curAttrData.fg=this._activeBuffer.savedCurAttrData.fg,this._curAttrData.bg=this._activeBuffer.savedCurAttrData.bg,this._charsetService.charset=this._savedCharset,this._activeBuffer.savedCharset&&(this._charsetService.charset=this._activeBuffer.savedCharset),this._restrictCursor(),!0}setTitle(t){return this._windowTitle=t,this._onTitleChange.fire(t),!0}setIconName(t){return this._iconName=t,!0}setOrReportIndexedColor(t){let e=[],s=t.split(";");for(;s.length>1;){let i=s.shift(),r=s.shift();if(/^\d+$/.exec(i)){let o=parseInt(i);if(Sc(o))if(r==="?")e.push({type:0,index:o});else{let a=gc(r);a&&e.push({type:1,index:o,color:a})}}}return e.length&&this._onColor.fire(e),!0}setHyperlink(t){let e=t.indexOf(";");if(e===-1)return!0;let s=t.slice(0,e).trim(),i=t.slice(e+1);return i?this._createHyperlink(s,i):s.trim()?!1:this._finishHyperlink()}_createHyperlink(t,e){this._getCurrentLinkId()&&this._finishHyperlink();let s=t.split(":"),i,r=s.findIndex(o=>o.startsWith("id="));return r!==-1&&(i=s[r].slice(3)||void 0),this._curAttrData.extended=this._curAttrData.extended.clone(),this._curAttrData.extended.urlId=this._oscLinkService.registerLink({id:i,uri:e}),this._curAttrData.updateExtended(),!0}_finishHyperlink(){return this._curAttrData.extended=this._curAttrData.extended.clone(),this._curAttrData.extended.urlId=0,this._curAttrData.updateExtended(),!0}_setOrReportSpecialColor(t,e){let s=t.split(";");for(let i=0;i<s.length&&!(e>=this._specialColors.length);++i,++e)if(s[i]==="?")this._onColor.fire([{type:0,index:this._specialColors[e]}]);else{let r=gc(s[i]);r&&this._onColor.fire([{type:1,index:this._specialColors[e],color:r}])}return!0}setOrReportFgColor(t){return this._setOrReportSpecialColor(t,0)}setOrReportBgColor(t){return this._setOrReportSpecialColor(t,1)}setOrReportCursorColor(t){return this._setOrReportSpecialColor(t,2)}restoreIndexedColor(t){if(!t)return this._onColor.fire([{type:2}]),!0;let e=[],s=t.split(";");for(let i=0;i<s.length;++i)if(/^\d+$/.exec(s[i])){let r=parseInt(s[i]);Sc(r)&&e.push({type:2,index:r})}return e.length&&this._onColor.fire(e),!0}restoreFgColor(t){return this._onColor.fire([{type:2,index:256}]),!0}restoreBgColor(t){return this._onColor.fire([{type:2,index:257}]),!0}restoreCursorColor(t){return this._onColor.fire([{type:2,index:258}]),!0}nextLine(){return this._activeBuffer.x=0,this.index(),!0}keypadApplicationMode(){return this._logService.debug("Serial port requested application keypad."),this._coreService.decPrivateModes.applicationKeypad=!0,this._onRequestSyncScrollBar.fire(),!0}keypadNumericMode(){return this._logService.debug("Switching back to normal keypad."),this._coreService.decPrivateModes.applicationKeypad=!1,this._onRequestSyncScrollBar.fire(),!0}selectDefaultCharset(){return this._charsetService.setgLevel(0),this._charsetService.setgCharset(0,xs),!0}selectCharset(t){return t.length!==2?(this.selectDefaultCharset(),!0):(t[0]==="/"||this._charsetService.setgCharset(AS[t[0]],Ge[t[1]]||xs),!0)}index(){return this._restrictCursor(),this._activeBuffer.y++,this._activeBuffer.y===this._activeBuffer.scrollBottom+1?(this._activeBuffer.y--,this._bufferService.scroll(this._eraseAttrData())):this._activeBuffer.y>=this._bufferService.rows&&(this._activeBuffer.y=this._bufferService.rows-1),this._restrictCursor(),!0}tabSet(){return this._activeBuffer.tabs[this._activeBuffer.x]=!0,!0}reverseIndex(){if(this._restrictCursor(),this._activeBuffer.y===this._activeBuffer.scrollTop){let t=this._activeBuffer.scrollBottom-this._activeBuffer.scrollTop;this._activeBuffer.lines.shiftElements(this._activeBuffer.ybase+this._activeBuffer.y,t,1),this._activeBuffer.lines.set(this._activeBuffer.ybase+this._activeBuffer.y,this._activeBuffer.getBlankLine(this._eraseAttrData())),this._dirtyRowTracker.markRangeDirty(this._activeBuffer.scrollTop,this._activeBuffer.scrollBottom)}else this._activeBuffer.y--,this._restrictCursor();return!0}fullReset(){return this._parser.reset(),this._onRequestReset.fire(),!0}reset(){this._curAttrData=We.clone(),this._eraseAttrDataInternal=We.clone()}_eraseAttrData(){return this._eraseAttrDataInternal.bg&=-67108864,this._eraseAttrDataInternal.bg|=this._curAttrData.bg&67108863,this._eraseAttrDataInternal}setgLevel(t){return this._charsetService.setgLevel(t),!0}screenAlignmentPattern(){let t=new Nt;t.content=1<<22|69,t.fg=this._curAttrData.fg,t.bg=this._curAttrData.bg,this._setCursor(0,0);for(let e=0;e<this._bufferService.rows;++e){let s=this._activeBuffer.ybase+this._activeBuffer.y+e,i=this._activeBuffer.lines.get(s);i&&(i.fill(t),i.isWrapped=!1)}return this._dirtyRowTracker.markAllDirty(),this._setCursor(0,0),!0}requestStatusString(t,e){let s=a=>(this._coreService.triggerDataEvent(`${Z.ESC}${a}${Z.ESC}\\`),!0),i=this._bufferService.buffer,r=this._optionsService.rawOptions;return s(t==='"q'?`P1$r${this._curAttrData.isProtected()?1:0}"q`:t==='"p'?'P1$r61;1"p':t==="r"?`P1$r${i.scrollTop+1};${i.scrollBottom+1}r`:t==="m"?"P1$r0m":t===" q"?`P1$r${{block:2,underline:4,bar:6}[r.cursorStyle]-(r.cursorBlink?1:0)} q`:"P0$r")}markRangeDirty(t,e){this._dirtyRowTracker.markRangeDirty(t,e)}},Mo=class{constructor(t){this._bufferService=t,this.clearRange()}clearRange(){this.start=this._bufferService.buffer.y,this.end=this._bufferService.buffer.y}markDirty(t){t<this.start?this.start=t:t>this.end&&(this.end=t)}markRangeDirty(t,e){t>e&&(yc=t,t=e,e=yc),t<this.start&&(this.start=t),e>this.end&&(this.end=e)}markAllDirty(){this.markRangeDirty(0,this._bufferService.rows-1)}};Mo=ze([de(0,ht)],Mo);function Sc(t){return 0<=t&&t<256}var BS=5e7,wc=12,MS=50,LS=class extends ye{constructor(t){super(),this._action=t,this._writeBuffer=[],this._callbacks=[],this._pendingData=0,this._bufferOffset=0,this._isSyncWriting=!1,this._syncCalls=0,this._didUserInput=!1,this._onWriteParsed=this._register(new ae),this.onWriteParsed=this._onWriteParsed.event}handleUserInput(){this._didUserInput=!0}writeSync(t,e){if(e!==void 0&&this._syncCalls>e){this._syncCalls=0;return}if(this._pendingData+=t.length,this._writeBuffer.push(t),this._callbacks.push(void 0),this._syncCalls++,this._isSyncWriting)return;this._isSyncWriting=!0;let s;for(;s=this._writeBuffer.shift();){this._action(s);let i=this._callbacks.shift();i&&i()}this._pendingData=0,this._bufferOffset=2147483647,this._isSyncWriting=!1,this._syncCalls=0}write(t,e){if(this._pendingData>BS)throw new Error("write data discarded, use flow control to avoid losing data");if(!this._writeBuffer.length){if(this._bufferOffset=0,this._didUserInput){this._didUserInput=!1,this._pendingData+=t.length,this._writeBuffer.push(t),this._callbacks.push(e),this._innerWrite();return}setTimeout(()=>this._innerWrite())}this._pendingData+=t.length,this._writeBuffer.push(t),this._callbacks.push(e)}_innerWrite(t=0,e=!0){let s=t||performance.now();for(;this._writeBuffer.length>this._bufferOffset;){let i=this._writeBuffer[this._bufferOffset],r=this._action(i,e);if(r){let a=l=>performance.now()-s>=wc?setTimeout(()=>this._innerWrite(0,l)):this._innerWrite(s,l);r.catch(l=>(queueMicrotask(()=>{throw l}),Promise.resolve(!1))).then(a);return}let o=this._callbacks[this._bufferOffset];if(o&&o(),this._bufferOffset++,this._pendingData-=i.length,performance.now()-s>=wc)break}this._writeBuffer.length>this._bufferOffset?(this._bufferOffset>MS&&(this._writeBuffer=this._writeBuffer.slice(this._bufferOffset),this._callbacks=this._callbacks.slice(this._bufferOffset),this._bufferOffset=0),setTimeout(()=>this._innerWrite())):(this._writeBuffer.length=0,this._callbacks.length=0,this._pendingData=0,this._bufferOffset=0),this._onWriteParsed.fire()}},Lo=class{constructor(t){this._bufferService=t,this._nextId=1,this._entriesWithId=new Map,this._dataByLinkId=new Map}registerLink(t){let e=this._bufferService.buffer;if(t.id===void 0){let l=e.addMarker(e.ybase+e.y),h={data:t,id:this._nextId++,lines:[l]};return l.onDispose(()=>this._removeMarkerFromLink(h,l)),this._dataByLinkId.set(h.id,h),h.id}let s=t,i=this._getEntryIdKey(s),r=this._entriesWithId.get(i);if(r)return this.addLineToLink(r.id,e.ybase+e.y),r.id;let o=e.addMarker(e.ybase+e.y),a={id:this._nextId++,key:this._getEntryIdKey(s),data:s,lines:[o]};return o.onDispose(()=>this._removeMarkerFromLink(a,o)),this._entriesWithId.set(a.key,a),this._dataByLinkId.set(a.id,a),a.id}addLineToLink(t,e){let s=this._dataByLinkId.get(t);if(s&&s.lines.every(i=>i.line!==e)){let i=this._bufferService.buffer.addMarker(e);s.lines.push(i),i.onDispose(()=>this._removeMarkerFromLink(s,i))}}getLinkData(t){return this._dataByLinkId.get(t)?.data}_getEntryIdKey(t){return`${t.id};;${t.uri}`}_removeMarkerFromLink(t,e){let s=t.lines.indexOf(e);s!==-1&&(t.lines.splice(s,1),t.lines.length===0&&(t.data.id!==void 0&&this._entriesWithId.delete(t.key),this._dataByLinkId.delete(t.id)))}};Lo=ze([de(0,ht)],Lo);var Cc=!1,OS=class extends ye{constructor(t){super(),this._windowsWrappingHeuristics=this._register(new Xs),this._onBinary=this._register(new ae),this.onBinary=this._onBinary.event,this._onData=this._register(new ae),this.onData=this._onData.event,this._onLineFeed=this._register(new ae),this.onLineFeed=this._onLineFeed.event,this._onResize=this._register(new ae),this.onResize=this._onResize.event,this._onWriteParsed=this._register(new ae),this.onWriteParsed=this._onWriteParsed.event,this._onScroll=this._register(new ae),this._instantiationService=new lS,this.optionsService=this._register(new vS(t)),this._instantiationService.setService(dt,this.optionsService),this._bufferService=this._register(this._instantiationService.createInstance(Do)),this._instantiationService.setService(ht,this._bufferService),this._logService=this._register(this._instantiationService.createInstance(Po)),this._instantiationService.setService(Ld,this._logService),this.coreService=this._register(this._instantiationService.createInstance(Ao)),this._instantiationService.setService(Ls,this.coreService),this.coreMouseService=this._register(this._instantiationService.createInstance(Io)),this._instantiationService.setService(Md,this.coreMouseService),this.unicodeService=this._register(this._instantiationService.createInstance(bs)),this._instantiationService.setService(ry,this.unicodeService),this._charsetService=this._instantiationService.createInstance(wS),this._instantiationService.setService(iy,this._charsetService),this._oscLinkService=this._instantiationService.createInstance(Lo),this._instantiationService.setService(Od,this._oscLinkService),this._inputHandler=this._register(new IS(this._bufferService,this._charsetService,this.coreService,this._logService,this.optionsService,this._oscLinkService,this.coreMouseService,this.unicodeService)),this._register(nt.forward(this._inputHandler.onLineFeed,this._onLineFeed)),this._register(this._inputHandler),this._register(nt.forward(this._bufferService.onResize,this._onResize)),this._register(nt.forward(this.coreService.onData,this._onData)),this._register(nt.forward(this.coreService.onBinary,this._onBinary)),this._register(this.coreService.onRequestScrollToBottom(()=>this.scrollToBottom(!0))),this._register(this.coreService.onUserInput(()=>this._writeBuffer.handleUserInput())),this._register(this.optionsService.onMultipleOptionChange(["windowsMode","windowsPty"],()=>this._handleWindowsPtyOptionChange())),this._register(this._bufferService.onScroll(()=>{this._onScroll.fire({position:this._bufferService.buffer.ydisp}),this._inputHandler.markRangeDirty(this._bufferService.buffer.scrollTop,this._bufferService.buffer.scrollBottom)})),this._writeBuffer=this._register(new LS((e,s)=>this._inputHandler.parse(e,s))),this._register(nt.forward(this._writeBuffer.onWriteParsed,this._onWriteParsed))}get onScroll(){return this._onScrollApi||(this._onScrollApi=this._register(new ae),this._onScroll.event(t=>{this._onScrollApi?.fire(t.position)})),this._onScrollApi.event}get cols(){return this._bufferService.cols}get rows(){return this._bufferService.rows}get buffers(){return this._bufferService.buffers}get options(){return this.optionsService.options}set options(t){for(let e in t)this.optionsService.options[e]=t[e]}write(t,e){this._writeBuffer.write(t,e)}writeSync(t,e){this._logService.logLevel<=3&&!Cc&&(this._logService.warn("writeSync is unreliable and will be removed soon."),Cc=!0),this._writeBuffer.writeSync(t,e)}input(t,e=!0){this.coreService.triggerDataEvent(t,e)}resize(t,e){isNaN(t)||isNaN(e)||(t=Math.max(t,_u),e=Math.max(e,gu),this._bufferService.resize(t,e))}scroll(t,e=!1){this._bufferService.scroll(t,e)}scrollLines(t,e){this._bufferService.scrollLines(t,e)}scrollPages(t){this.scrollLines(t*(this.rows-1))}scrollToTop(){this.scrollLines(-this._bufferService.buffer.ydisp)}scrollToBottom(t){this.scrollLines(this._bufferService.buffer.ybase-this._bufferService.buffer.ydisp)}scrollToLine(t){let e=t-this._bufferService.buffer.ydisp;e!==0&&this.scrollLines(e)}registerEscHandler(t,e){return this._inputHandler.registerEscHandler(t,e)}registerDcsHandler(t,e){return this._inputHandler.registerDcsHandler(t,e)}registerCsiHandler(t,e){return this._inputHandler.registerCsiHandler(t,e)}registerOscHandler(t,e){return this._inputHandler.registerOscHandler(t,e)}_setup(){this._handleWindowsPtyOptionChange()}reset(){this._inputHandler.reset(),this._bufferService.reset(),this._charsetService.reset(),this.coreService.reset(),this.coreMouseService.reset()}_handleWindowsPtyOptionChange(){let t=!1,e=this.optionsService.rawOptions.windowsPty;e&&e.buildNumber!==void 0&&e.buildNumber!==void 0?t=e.backend==="conpty"&&e.buildNumber<21376:this.optionsService.rawOptions.windowsMode&&(t=!0),t?this._enableWindowsWrappingHeuristics():this._windowsWrappingHeuristics.clear()}_enableWindowsWrappingHeuristics(){if(!this._windowsWrappingHeuristics.value){let t=[];t.push(this.onLineFeed(pc.bind(null,this._bufferService))),t.push(this.registerCsiHandler({final:"H"},()=>(pc(this._bufferService),!1))),this._windowsWrappingHeuristics.value=Ie(()=>{for(let e of t)e.dispose()})}}},$S={48:["0",")"],49:["1","!"],50:["2","@"],51:["3","#"],52:["4","$"],53:["5","%"],54:["6","^"],55:["7","&"],56:["8","*"],57:["9","("],186:[";",":"],187:["=","+"],188:[",","<"],189:["-","_"],190:[".",">"],191:["/","?"],192:["`","~"],219:["[","{"],220:["\\","|"],221:["]","}"],222:["'",'"']};function zS(t,e,s,i){let r={type:0,cancel:!1,key:void 0},o=(t.shiftKey?1:0)|(t.altKey?2:0)|(t.ctrlKey?4:0)|(t.metaKey?8:0);switch(t.keyCode){case 0:t.key==="UIKeyInputUpArrow"?e?r.key=Z.ESC+"OA":r.key=Z.ESC+"[A":t.key==="UIKeyInputLeftArrow"?e?r.key=Z.ESC+"OD":r.key=Z.ESC+"[D":t.key==="UIKeyInputRightArrow"?e?r.key=Z.ESC+"OC":r.key=Z.ESC+"[C":t.key==="UIKeyInputDownArrow"&&(e?r.key=Z.ESC+"OB":r.key=Z.ESC+"[B");break;case 8:r.key=t.ctrlKey?"\b":Z.DEL,t.altKey&&(r.key=Z.ESC+r.key);break;case 9:if(t.shiftKey){r.key=Z.ESC+"[Z";break}r.key=Z.HT,r.cancel=!0;break;case 13:r.key=t.altKey?Z.ESC+Z.CR:Z.CR,r.cancel=!0;break;case 27:r.key=Z.ESC,t.altKey&&(r.key=Z.ESC+Z.ESC),r.cancel=!0;break;case 37:if(t.metaKey)break;o?r.key=Z.ESC+"[1;"+(o+1)+"D":e?r.key=Z.ESC+"OD":r.key=Z.ESC+"[D";break;case 39:if(t.metaKey)break;o?r.key=Z.ESC+"[1;"+(o+1)+"C":e?r.key=Z.ESC+"OC":r.key=Z.ESC+"[C";break;case 38:if(t.metaKey)break;o?r.key=Z.ESC+"[1;"+(o+1)+"A":e?r.key=Z.ESC+"OA":r.key=Z.ESC+"[A";break;case 40:if(t.metaKey)break;o?r.key=Z.ESC+"[1;"+(o+1)+"B":e?r.key=Z.ESC+"OB":r.key=Z.ESC+"[B";break;case 45:!t.shiftKey&&!t.ctrlKey&&(r.key=Z.ESC+"[2~");break;case 46:o?r.key=Z.ESC+"[3;"+(o+1)+"~":r.key=Z.ESC+"[3~";break;case 36:o?r.key=Z.ESC+"[1;"+(o+1)+"H":e?r.key=Z.ESC+"OH":r.key=Z.ESC+"[H";break;case 35:o?r.key=Z.ESC+"[1;"+(o+1)+"F":e?r.key=Z.ESC+"OF":r.key=Z.ESC+"[F";break;case 33:t.shiftKey?r.type=2:t.ctrlKey?r.key=Z.ESC+"[5;"+(o+1)+"~":r.key=Z.ESC+"[5~";break;case 34:t.shiftKey?r.type=3:t.ctrlKey?r.key=Z.ESC+"[6;"+(o+1)+"~":r.key=Z.ESC+"[6~";break;case 112:o?r.key=Z.ESC+"[1;"+(o+1)+"P":r.key=Z.ESC+"OP";break;case 113:o?r.key=Z.ESC+"[1;"+(o+1)+"Q":r.key=Z.ESC+"OQ";break;case 114:o?r.key=Z.ESC+"[1;"+(o+1)+"R":r.key=Z.ESC+"OR";break;case 115:o?r.key=Z.ESC+"[1;"+(o+1)+"S":r.key=Z.ESC+"OS";break;case 116:o?r.key=Z.ESC+"[15;"+(o+1)+"~":r.key=Z.ESC+"[15~";break;case 117:o?r.key=Z.ESC+"[17;"+(o+1)+"~":r.key=Z.ESC+"[17~";break;case 118:o?r.key=Z.ESC+"[18;"+(o+1)+"~":r.key=Z.ESC+"[18~";break;case 119:o?r.key=Z.ESC+"[19;"+(o+1)+"~":r.key=Z.ESC+"[19~";break;case 120:o?r.key=Z.ESC+"[20;"+(o+1)+"~":r.key=Z.ESC+"[20~";break;case 121:o?r.key=Z.ESC+"[21;"+(o+1)+"~":r.key=Z.ESC+"[21~";break;case 122:o?r.key=Z.ESC+"[23;"+(o+1)+"~":r.key=Z.ESC+"[23~";break;case 123:o?r.key=Z.ESC+"[24;"+(o+1)+"~":r.key=Z.ESC+"[24~";break;default:if(t.ctrlKey&&!t.shiftKey&&!t.altKey&&!t.metaKey)t.keyCode>=65&&t.keyCode<=90?r.key=String.fromCharCode(t.keyCode-64):t.keyCode===32?r.key=Z.NUL:t.keyCode>=51&&t.keyCode<=55?r.key=String.fromCharCode(t.keyCode-51+27):t.keyCode===56?r.key=Z.DEL:t.keyCode===219?r.key=Z.ESC:t.keyCode===220?r.key=Z.FS:t.keyCode===221&&(r.key=Z.GS);else if((!s||i)&&t.altKey&&!t.metaKey){let a=$S[t.keyCode]?.[t.shiftKey?1:0];if(a)r.key=Z.ESC+a;else if(t.keyCode>=65&&t.keyCode<=90){let l=t.ctrlKey?t.keyCode-64:t.keyCode+32,h=String.fromCharCode(l);t.shiftKey&&(h=h.toUpperCase()),r.key=Z.ESC+h}else if(t.keyCode===32)r.key=Z.ESC+(t.ctrlKey?Z.NUL:" ");else if(t.key==="Dead"&&t.code.startsWith("Key")){let l=t.code.slice(3,4);t.shiftKey||(l=l.toLowerCase()),r.key=Z.ESC+l,r.cancel=!0}}else s&&!t.altKey&&!t.ctrlKey&&!t.shiftKey&&t.metaKey?t.keyCode===65&&(r.type=1):t.key&&!t.ctrlKey&&!t.altKey&&!t.metaKey&&t.keyCode>=48&&t.key.length===1?r.key=t.key:t.key&&t.ctrlKey&&(t.key==="_"&&(r.key=Z.US),t.key==="@"&&(r.key=Z.NUL));break}return r}var Fe=0,FS=class{constructor(t){this._getKey=t,this._array=[],this._insertedValues=[],this._flushInsertedTask=new Gr,this._isFlushingInserted=!1,this._deletedIndices=[],this._flushDeletedTask=new Gr,this._isFlushingDeleted=!1}clear(){this._array.length=0,this._insertedValues.length=0,this._flushInsertedTask.clear(),this._isFlushingInserted=!1,this._deletedIndices.length=0,this._flushDeletedTask.clear(),this._isFlushingDeleted=!1}insert(t){this._flushCleanupDeleted(),this._insertedValues.length===0&&this._flushInsertedTask.enqueue(()=>this._flushInserted()),this._insertedValues.push(t)}_flushInserted(){let t=this._insertedValues.sort((r,o)=>this._getKey(r)-this._getKey(o)),e=0,s=0,i=new Array(this._array.length+this._insertedValues.length);for(let r=0;r<i.length;r++)s>=this._array.length||this._getKey(t[e])<=this._getKey(this._array[s])?(i[r]=t[e],e++):i[r]=this._array[s++];this._array=i,this._insertedValues.length=0}_flushCleanupInserted(){!this._isFlushingInserted&&this._insertedValues.length>0&&this._flushInsertedTask.flush()}delete(t){if(this._flushCleanupInserted(),this._array.length===0)return!1;let e=this._getKey(t);if(e===void 0||(Fe=this._search(e),Fe===-1)||this._getKey(this._array[Fe])!==e)return!1;do if(this._array[Fe]===t)return this._deletedIndices.length===0&&this._flushDeletedTask.enqueue(()=>this._flushDeleted()),this._deletedIndices.push(Fe),!0;while(++Fe<this._array.length&&this._getKey(this._array[Fe])===e);return!1}_flushDeleted(){this._isFlushingDeleted=!0;let t=this._deletedIndices.sort((r,o)=>r-o),e=0,s=new Array(this._array.length-t.length),i=0;for(let r=0;r<this._array.length;r++)t[e]===r?e++:s[i++]=this._array[r];this._array=s,this._deletedIndices.length=0,this._isFlushingDeleted=!1}_flushCleanupDeleted(){!this._isFlushingDeleted&&this._deletedIndices.length>0&&this._flushDeletedTask.flush()}*getKeyIterator(t){if(this._flushCleanupInserted(),this._flushCleanupDeleted(),this._array.length!==0&&(Fe=this._search(t),!(Fe<0||Fe>=this._array.length)&&this._getKey(this._array[Fe])===t))do yield this._array[Fe];while(++Fe<this._array.length&&this._getKey(this._array[Fe])===t)}forEachByKey(t,e){if(this._flushCleanupInserted(),this._flushCleanupDeleted(),this._array.length!==0&&(Fe=this._search(t),!(Fe<0||Fe>=this._array.length)&&this._getKey(this._array[Fe])===t))do e(this._array[Fe]);while(++Fe<this._array.length&&this._getKey(this._array[Fe])===t)}values(){return this._flushCleanupInserted(),this._flushCleanupDeleted(),[...this._array].values()}_search(t){let e=0,s=this._array.length-1;for(;s>=e;){let i=e+s>>1,r=this._getKey(this._array[i]);if(r>t)s=i-1;else if(r<t)e=i+1;else{for(;i>0&&this._getKey(this._array[i-1])===t;)i--;return i}}return e}},On=0,kc=0,HS=class extends ye{constructor(){super(),this._decorations=new FS(t=>t?.marker.line),this._onDecorationRegistered=this._register(new ae),this.onDecorationRegistered=this._onDecorationRegistered.event,this._onDecorationRemoved=this._register(new ae),this.onDecorationRemoved=this._onDecorationRemoved.event,this._register(Ie(()=>this.reset()))}get decorations(){return this._decorations.values()}registerDecoration(t){if(t.marker.isDisposed)return;let e=new WS(t);if(e){let s=e.marker.onDispose(()=>e.dispose()),i=e.onDispose(()=>{i.dispose(),e&&(this._decorations.delete(e)&&this._onDecorationRemoved.fire(e),s.dispose())});this._decorations.insert(e),this._onDecorationRegistered.fire(e)}return e}reset(){for(let t of this._decorations.values())t.dispose();this._decorations.clear()}*getDecorationsAtCell(t,e,s){let i=0,r=0;for(let o of this._decorations.getKeyIterator(e))i=o.options.x??0,r=i+(o.options.width??1),t>=i&&t<r&&(!s||(o.options.layer??"bottom")===s)&&(yield o)}forEachDecorationAtCell(t,e,s,i){this._decorations.forEachByKey(e,r=>{On=r.options.x??0,kc=On+(r.options.width??1),t>=On&&t<kc&&(!s||(r.options.layer??"bottom")===s)&&i(r)})}},WS=class extends ms{constructor(t){super(),this.options=t,this.onRenderEmitter=this.add(new ae),this.onRender=this.onRenderEmitter.event,this._onDispose=this.add(new ae),this.onDispose=this._onDispose.event,this._cachedBg=null,this._cachedFg=null,this.marker=t.marker,this.options.overviewRulerOptions&&!this.options.overviewRulerOptions.position&&(this.options.overviewRulerOptions.position="full")}get backgroundColorRGB(){return this._cachedBg===null&&(this.options.backgroundColor?this._cachedBg=Le.toColor(this.options.backgroundColor):this._cachedBg=void 0),this._cachedBg}get foregroundColorRGB(){return this._cachedFg===null&&(this.options.foregroundColor?this._cachedFg=Le.toColor(this.options.foregroundColor):this._cachedFg=void 0),this._cachedFg}dispose(){this._onDispose.fire(),super.dispose()}},US=1e3,KS=class{constructor(t,e=US){this._renderCallback=t,this._debounceThresholdMS=e,this._lastRefreshMs=0,this._additionalRefreshRequested=!1}dispose(){this._refreshTimeoutID&&clearTimeout(this._refreshTimeoutID)}refresh(t,e,s){this._rowCount=s,t=t!==void 0?t:0,e=e!==void 0?e:this._rowCount-1,this._rowStart=this._rowStart!==void 0?Math.min(this._rowStart,t):t,this._rowEnd=this._rowEnd!==void 0?Math.max(this._rowEnd,e):e;let i=performance.now();if(i-this._lastRefreshMs>=this._debounceThresholdMS)this._lastRefreshMs=i,this._innerRefresh();else if(!this._additionalRefreshRequested){let r=i-this._lastRefreshMs,o=this._debounceThresholdMS-r;this._additionalRefreshRequested=!0,this._refreshTimeoutID=window.setTimeout(()=>{this._lastRefreshMs=performance.now(),this._innerRefresh(),this._additionalRefreshRequested=!1,this._refreshTimeoutID=void 0},o)}}_innerRefresh(){if(this._rowStart===void 0||this._rowEnd===void 0||this._rowCount===void 0)return;let t=Math.max(this._rowStart,0),e=Math.min(this._rowEnd,this._rowCount-1);this._rowStart=void 0,this._rowEnd=void 0,this._renderCallback(t,e)}},jc=20,Yr=class extends ye{constructor(t,e,s,i){super(),this._terminal=t,this._coreBrowserService=s,this._renderService=i,this._rowColumns=new WeakMap,this._liveRegionLineCount=0,this._charsToConsume=[],this._charsToAnnounce="";let r=this._coreBrowserService.mainDocument;this._accessibilityContainer=r.createElement("div"),this._accessibilityContainer.classList.add("xterm-accessibility"),this._rowContainer=r.createElement("div"),this._rowContainer.setAttribute("role","list"),this._rowContainer.classList.add("xterm-accessibility-tree"),this._rowElements=[];for(let o=0;o<this._terminal.rows;o++)this._rowElements[o]=this._createAccessibilityTreeNode(),this._rowContainer.appendChild(this._rowElements[o]);if(this._topBoundaryFocusListener=o=>this._handleBoundaryFocus(o,0),this._bottomBoundaryFocusListener=o=>this._handleBoundaryFocus(o,1),this._rowElements[0].addEventListener("focus",this._topBoundaryFocusListener),this._rowElements[this._rowElements.length-1].addEventListener("focus",this._bottomBoundaryFocusListener),this._accessibilityContainer.appendChild(this._rowContainer),this._liveRegion=r.createElement("div"),this._liveRegion.classList.add("live-region"),this._liveRegion.setAttribute("aria-live","assertive"),this._accessibilityContainer.appendChild(this._liveRegion),this._liveRegionDebouncer=this._register(new KS(this._renderRows.bind(this))),!this._terminal.element)throw new Error("Cannot enable accessibility before Terminal.open");this._terminal.element.insertAdjacentElement("afterbegin",this._accessibilityContainer),this._register(this._terminal.onResize(o=>this._handleResize(o.rows))),this._register(this._terminal.onRender(o=>this._refreshRows(o.start,o.end))),this._register(this._terminal.onScroll(()=>this._refreshRows())),this._register(this._terminal.onA11yChar(o=>this._handleChar(o))),this._register(this._terminal.onLineFeed(()=>this._handleChar(`
|
|
307
307
|
`))),this._register(this._terminal.onA11yTab(o=>this._handleTab(o))),this._register(this._terminal.onKey(o=>this._handleKey(o.key))),this._register(this._terminal.onBlur(()=>this._clearLiveRegion())),this._register(this._renderService.onDimensionsChange(()=>this._refreshRowsDimensions())),this._register(pe(r,"selectionchange",()=>this._handleSelectionChange())),this._register(this._coreBrowserService.onDprChange(()=>this._refreshRowsDimensions())),this._refreshRowsDimensions(),this._refreshRows(),this._register(Ie(()=>{this._accessibilityContainer.remove(),this._rowElements.length=0}))}_handleTab(t){for(let e=0;e<t;e++)this._handleChar(" ")}_handleChar(t){this._liveRegionLineCount<jc+1&&(this._charsToConsume.length>0?this._charsToConsume.shift()!==t&&(this._charsToAnnounce+=t):this._charsToAnnounce+=t,t===`
|
|
308
308
|
`&&(this._liveRegionLineCount++,this._liveRegionLineCount===jc+1&&(this._liveRegion.textContent+=so.get())))}_clearLiveRegion(){this._liveRegion.textContent="",this._liveRegionLineCount=0}_handleKey(t){this._clearLiveRegion(),new RegExp("\\p{Control}","u").test(t)||this._charsToConsume.push(t)}_refreshRows(t,e){this._liveRegionDebouncer.refresh(t,e,this._terminal.rows)}_renderRows(t,e){let s=this._terminal.buffer,i=s.lines.length.toString();for(let r=t;r<=e;r++){let o=s.lines.get(s.ydisp+r),a=[],l=o?.translateToString(!0,void 0,void 0,a)||"",h=(s.ydisp+r+1).toString(),c=this._rowElements[r];c&&(l.length===0?(c.textContent=" ",this._rowColumns.set(c,[0,1])):(c.textContent=l,this._rowColumns.set(c,a)),c.setAttribute("aria-posinset",h),c.setAttribute("aria-setsize",i),this._alignRowWidth(c))}this._announceCharacters()}_announceCharacters(){this._charsToAnnounce.length!==0&&(this._liveRegion.textContent+=this._charsToAnnounce,this._charsToAnnounce="")}_handleBoundaryFocus(t,e){let s=t.target,i=this._rowElements[e===0?1:this._rowElements.length-2],r=s.getAttribute("aria-posinset"),o=e===0?"1":`${this._terminal.buffer.lines.length}`;if(r===o||t.relatedTarget!==i)return;let a,l;if(e===0?(a=s,l=this._rowElements.pop(),this._rowContainer.removeChild(l)):(a=this._rowElements.shift(),l=s,this._rowContainer.removeChild(a)),a.removeEventListener("focus",this._topBoundaryFocusListener),l.removeEventListener("focus",this._bottomBoundaryFocusListener),e===0){let h=this._createAccessibilityTreeNode();this._rowElements.unshift(h),this._rowContainer.insertAdjacentElement("afterbegin",h)}else{let h=this._createAccessibilityTreeNode();this._rowElements.push(h),this._rowContainer.appendChild(h)}this._rowElements[0].addEventListener("focus",this._topBoundaryFocusListener),this._rowElements[this._rowElements.length-1].addEventListener("focus",this._bottomBoundaryFocusListener),this._terminal.scrollLines(e===0?-1:1),this._rowElements[e===0?1:this._rowElements.length-2].focus(),t.preventDefault(),t.stopImmediatePropagation()}_handleSelectionChange(){if(this._rowElements.length===0)return;let t=this._coreBrowserService.mainDocument.getSelection();if(!t)return;if(t.isCollapsed){this._rowContainer.contains(t.anchorNode)&&this._terminal.clearSelection();return}if(!t.anchorNode||!t.focusNode){console.error("anchorNode and/or focusNode are null");return}let e={node:t.anchorNode,offset:t.anchorOffset},s={node:t.focusNode,offset:t.focusOffset};if((e.node.compareDocumentPosition(s.node)&Node.DOCUMENT_POSITION_PRECEDING||e.node===s.node&&e.offset>s.offset)&&([e,s]=[s,e]),e.node.compareDocumentPosition(this._rowElements[0])&(Node.DOCUMENT_POSITION_CONTAINED_BY|Node.DOCUMENT_POSITION_FOLLOWING)&&(e={node:this._rowElements[0].childNodes[0],offset:0}),!this._rowContainer.contains(e.node))return;let i=this._rowElements.slice(-1)[0];if(s.node.compareDocumentPosition(i)&(Node.DOCUMENT_POSITION_CONTAINED_BY|Node.DOCUMENT_POSITION_PRECEDING)&&(s={node:i,offset:i.textContent?.length??0}),!this._rowContainer.contains(s.node))return;let r=({node:l,offset:h})=>{let c=l instanceof Text?l.parentNode:l,d=parseInt(c?.getAttribute("aria-posinset"),10)-1;if(isNaN(d))return console.warn("row is invalid. Race condition?"),null;let u=this._rowColumns.get(c);if(!u)return console.warn("columns is null. Race condition?"),null;let f=h<u.length?u[h]:u.slice(-1)[0]+1;return f>=this._terminal.cols&&(++d,f=0),{row:d,column:f}},o=r(e),a=r(s);if(!(!o||!a)){if(o.row>a.row||o.row===a.row&&o.column>=a.column)throw new Error("invalid range");this._terminal.select(o.column,o.row,(a.row-o.row)*this._terminal.cols-o.column+a.column)}}_handleResize(t){this._rowElements[this._rowElements.length-1].removeEventListener("focus",this._bottomBoundaryFocusListener);for(let e=this._rowContainer.children.length;e<this._terminal.rows;e++)this._rowElements[e]=this._createAccessibilityTreeNode(),this._rowContainer.appendChild(this._rowElements[e]);for(;this._rowElements.length>t;)this._rowContainer.removeChild(this._rowElements.pop());this._rowElements[this._rowElements.length-1].addEventListener("focus",this._bottomBoundaryFocusListener),this._refreshRowsDimensions()}_createAccessibilityTreeNode(){let t=this._coreBrowserService.mainDocument.createElement("div");return t.setAttribute("role","listitem"),t.tabIndex=-1,this._refreshRowDimensions(t),t}_refreshRowsDimensions(){if(this._renderService.dimensions.css.cell.height){Object.assign(this._accessibilityContainer.style,{width:`${this._renderService.dimensions.css.canvas.width}px`,fontSize:`${this._terminal.options.fontSize}px`}),this._rowElements.length!==this._terminal.rows&&this._handleResize(this._terminal.rows);for(let t=0;t<this._terminal.rows;t++)this._refreshRowDimensions(this._rowElements[t]),this._alignRowWidth(this._rowElements[t])}}_refreshRowDimensions(t){t.style.height=`${this._renderService.dimensions.css.cell.height}px`}_alignRowWidth(t){t.style.transform="";let e=t.getBoundingClientRect().width,s=this._rowColumns.get(t)?.slice(-1)?.[0];if(!s)return;let i=s*this._renderService.dimensions.css.cell.width;t.style.transform=`scaleX(${i/e})`}};Yr=ze([de(1,Ta),de(2,ns),de(3,os)],Yr);var Oo=class extends ye{constructor(t,e,s,i,r){super(),this._element=t,this._mouseService=e,this._renderService=s,this._bufferService=i,this._linkProviderService=r,this._linkCacheDisposables=[],this._isMouseOut=!0,this._wasResized=!1,this._activeLine=-1,this._onShowLinkUnderline=this._register(new ae),this.onShowLinkUnderline=this._onShowLinkUnderline.event,this._onHideLinkUnderline=this._register(new ae),this.onHideLinkUnderline=this._onHideLinkUnderline.event,this._register(Ie(()=>{ks(this._linkCacheDisposables),this._linkCacheDisposables.length=0,this._lastMouseEvent=void 0,this._activeProviderReplies?.clear()})),this._register(this._bufferService.onResize(()=>{this._clearCurrentLink(),this._wasResized=!0})),this._register(pe(this._element,"mouseleave",()=>{this._isMouseOut=!0,this._clearCurrentLink()})),this._register(pe(this._element,"mousemove",this._handleMouseMove.bind(this))),this._register(pe(this._element,"mousedown",this._handleMouseDown.bind(this))),this._register(pe(this._element,"mouseup",this._handleMouseUp.bind(this)))}get currentLink(){return this._currentLink}_handleMouseMove(t){this._lastMouseEvent=t;let e=this._positionFromMouseEvent(t,this._element,this._mouseService);if(!e)return;this._isMouseOut=!1;let s=t.composedPath();for(let i=0;i<s.length;i++){let r=s[i];if(r.classList.contains("xterm"))break;if(r.classList.contains("xterm-hover"))return}(!this._lastBufferCell||e.x!==this._lastBufferCell.x||e.y!==this._lastBufferCell.y)&&(this._handleHover(e),this._lastBufferCell=e)}_handleHover(t){if(this._activeLine!==t.y||this._wasResized){this._clearCurrentLink(),this._askForLink(t,!1),this._wasResized=!1;return}this._currentLink&&this._linkAtPosition(this._currentLink.link,t)||(this._clearCurrentLink(),this._askForLink(t,!0))}_askForLink(t,e){(!this._activeProviderReplies||!e)&&(this._activeProviderReplies?.forEach(i=>{i?.forEach(r=>{r.link.dispose&&r.link.dispose()})}),this._activeProviderReplies=new Map,this._activeLine=t.y);let s=!1;for(let[i,r]of this._linkProviderService.linkProviders.entries())e?this._activeProviderReplies?.get(i)&&(s=this._checkLinkProviderResult(i,t,s)):r.provideLinks(t.y,o=>{if(this._isMouseOut)return;let a=o?.map(l=>({link:l}));this._activeProviderReplies?.set(i,a),s=this._checkLinkProviderResult(i,t,s),this._activeProviderReplies?.size===this._linkProviderService.linkProviders.length&&this._removeIntersectingLinks(t.y,this._activeProviderReplies)})}_removeIntersectingLinks(t,e){let s=new Set;for(let i=0;i<e.size;i++){let r=e.get(i);if(r)for(let o=0;o<r.length;o++){let a=r[o],l=a.link.range.start.y<t?0:a.link.range.start.x,h=a.link.range.end.y>t?this._bufferService.cols:a.link.range.end.x;for(let c=l;c<=h;c++){if(s.has(c)){r.splice(o--,1);break}s.add(c)}}}}_checkLinkProviderResult(t,e,s){if(!this._activeProviderReplies)return s;let i=this._activeProviderReplies.get(t),r=!1;for(let o=0;o<t;o++)(!this._activeProviderReplies.has(o)||this._activeProviderReplies.get(o))&&(r=!0);if(!r&&i){let o=i.find(a=>this._linkAtPosition(a.link,e));o&&(s=!0,this._handleNewLink(o))}if(this._activeProviderReplies.size===this._linkProviderService.linkProviders.length&&!s)for(let o=0;o<this._activeProviderReplies.size;o++){let a=this._activeProviderReplies.get(o)?.find(l=>this._linkAtPosition(l.link,e));if(a){s=!0,this._handleNewLink(a);break}}return s}_handleMouseDown(){this._mouseDownLink=this._currentLink}_handleMouseUp(t){if(!this._currentLink)return;let e=this._positionFromMouseEvent(t,this._element,this._mouseService);e&&this._mouseDownLink&&VS(this._mouseDownLink.link,this._currentLink.link)&&this._linkAtPosition(this._currentLink.link,e)&&this._currentLink.link.activate(t,this._currentLink.link.text)}_clearCurrentLink(t,e){!this._currentLink||!this._lastMouseEvent||(!t||!e||this._currentLink.link.range.start.y>=t&&this._currentLink.link.range.end.y<=e)&&(this._linkLeave(this._element,this._currentLink.link,this._lastMouseEvent),this._currentLink=void 0,ks(this._linkCacheDisposables),this._linkCacheDisposables.length=0)}_handleNewLink(t){if(!this._lastMouseEvent)return;let e=this._positionFromMouseEvent(this._lastMouseEvent,this._element,this._mouseService);e&&this._linkAtPosition(t.link,e)&&(this._currentLink=t,this._currentLink.state={decorations:{underline:t.link.decorations===void 0?!0:t.link.decorations.underline,pointerCursor:t.link.decorations===void 0?!0:t.link.decorations.pointerCursor},isHovered:!0},this._linkHover(this._element,t.link,this._lastMouseEvent),t.link.decorations={},Object.defineProperties(t.link.decorations,{pointerCursor:{get:()=>this._currentLink?.state?.decorations.pointerCursor,set:s=>{this._currentLink?.state&&this._currentLink.state.decorations.pointerCursor!==s&&(this._currentLink.state.decorations.pointerCursor=s,this._currentLink.state.isHovered&&this._element.classList.toggle("xterm-cursor-pointer",s))}},underline:{get:()=>this._currentLink?.state?.decorations.underline,set:s=>{this._currentLink?.state&&this._currentLink?.state?.decorations.underline!==s&&(this._currentLink.state.decorations.underline=s,this._currentLink.state.isHovered&&this._fireUnderlineEvent(t.link,s))}}}),this._linkCacheDisposables.push(this._renderService.onRenderedViewportChange(s=>{if(!this._currentLink)return;let i=s.start===0?0:s.start+1+this._bufferService.buffer.ydisp,r=this._bufferService.buffer.ydisp+1+s.end;if(this._currentLink.link.range.start.y>=i&&this._currentLink.link.range.end.y<=r&&(this._clearCurrentLink(i,r),this._lastMouseEvent)){let o=this._positionFromMouseEvent(this._lastMouseEvent,this._element,this._mouseService);o&&this._askForLink(o,!1)}})))}_linkHover(t,e,s){this._currentLink?.state&&(this._currentLink.state.isHovered=!0,this._currentLink.state.decorations.underline&&this._fireUnderlineEvent(e,!0),this._currentLink.state.decorations.pointerCursor&&t.classList.add("xterm-cursor-pointer")),e.hover&&e.hover(s,e.text)}_fireUnderlineEvent(t,e){let s=t.range,i=this._bufferService.buffer.ydisp,r=this._createLinkUnderlineEvent(s.start.x-1,s.start.y-i-1,s.end.x,s.end.y-i-1,void 0);(e?this._onShowLinkUnderline:this._onHideLinkUnderline).fire(r)}_linkLeave(t,e,s){this._currentLink?.state&&(this._currentLink.state.isHovered=!1,this._currentLink.state.decorations.underline&&this._fireUnderlineEvent(e,!1),this._currentLink.state.decorations.pointerCursor&&t.classList.remove("xterm-cursor-pointer")),e.leave&&e.leave(s,e.text)}_linkAtPosition(t,e){let s=t.range.start.y*this._bufferService.cols+t.range.start.x,i=t.range.end.y*this._bufferService.cols+t.range.end.x,r=e.y*this._bufferService.cols+e.x;return s<=r&&r<=i}_positionFromMouseEvent(t,e,s){let i=s.getCoords(t,e,this._bufferService.cols,this._bufferService.rows);if(i)return{x:i[0],y:i[1]+this._bufferService.buffer.ydisp}}_createLinkUnderlineEvent(t,e,s,i,r){return{x1:t,y1:e,x2:s,y2:i,cols:this._bufferService.cols,fg:r}}};Oo=ze([de(1,Ra),de(2,os),de(3,ht),de(4,zd)],Oo);function VS(t,e){return t.text===e.text&&t.range.start.x===e.range.start.x&&t.range.start.y===e.range.start.y&&t.range.end.x===e.range.end.x&&t.range.end.y===e.range.end.y}var qS=class extends OS{constructor(t={}){super(t),this._linkifier=this._register(new Xs),this.browser=nu,this._keyDownHandled=!1,this._keyDownSeen=!1,this._keyPressHandled=!1,this._unprocessedDeadKey=!1,this._accessibilityManager=this._register(new Xs),this._onCursorMove=this._register(new ae),this.onCursorMove=this._onCursorMove.event,this._onKey=this._register(new ae),this.onKey=this._onKey.event,this._onRender=this._register(new ae),this.onRender=this._onRender.event,this._onSelectionChange=this._register(new ae),this.onSelectionChange=this._onSelectionChange.event,this._onTitleChange=this._register(new ae),this.onTitleChange=this._onTitleChange.event,this._onBell=this._register(new ae),this.onBell=this._onBell.event,this._onFocus=this._register(new ae),this._onBlur=this._register(new ae),this._onA11yCharEmitter=this._register(new ae),this._onA11yTabEmitter=this._register(new ae),this._onWillOpen=this._register(new ae),this._setup(),this._decorationService=this._instantiationService.createInstance(HS),this._instantiationService.setService(Qi,this._decorationService),this._linkProviderService=this._instantiationService.createInstance(M0),this._instantiationService.setService(zd,this._linkProviderService),this._linkProviderService.registerLinkProvider(this._instantiationService.createInstance(ro)),this._register(this._inputHandler.onRequestBell(()=>this._onBell.fire())),this._register(this._inputHandler.onRequestRefreshRows(e=>this.refresh(e?.start??0,e?.end??this.rows-1))),this._register(this._inputHandler.onRequestSendFocus(()=>this._reportFocus())),this._register(this._inputHandler.onRequestReset(()=>this.reset())),this._register(this._inputHandler.onRequestWindowsOptionsReport(e=>this._reportWindowsOptions(e))),this._register(this._inputHandler.onColor(e=>this._handleColorEvent(e))),this._register(nt.forward(this._inputHandler.onCursorMove,this._onCursorMove)),this._register(nt.forward(this._inputHandler.onTitleChange,this._onTitleChange)),this._register(nt.forward(this._inputHandler.onA11yChar,this._onA11yCharEmitter)),this._register(nt.forward(this._inputHandler.onA11yTab,this._onA11yTabEmitter)),this._register(this._bufferService.onResize(e=>this._afterResize(e.cols,e.rows))),this._register(Ie(()=>{this._customKeyEventHandler=void 0,this.element?.parentNode?.removeChild(this.element)}))}get linkifier(){return this._linkifier.value}get onFocus(){return this._onFocus.event}get onBlur(){return this._onBlur.event}get onA11yChar(){return this._onA11yCharEmitter.event}get onA11yTab(){return this._onA11yTabEmitter.event}get onWillOpen(){return this._onWillOpen.event}_handleColorEvent(t){if(this._themeService)for(let e of t){let s,i="";switch(e.index){case 256:s="foreground",i="10";break;case 257:s="background",i="11";break;case 258:s="cursor",i="12";break;default:s="ansi",i="4;"+e.index}switch(e.type){case 0:let r=Ae.toColorRGB(s==="ansi"?this._themeService.colors.ansi[e.index]:this._themeService.colors[s]);this.coreService.triggerDataEvent(`${Z.ESC}]${i};${DS(r)}${iu.ST}`);break;case 1:if(s==="ansi")this._themeService.modifyColors(o=>o.ansi[e.index]=Ue.toColor(...e.color));else{let o=s;this._themeService.modifyColors(a=>a[o]=Ue.toColor(...e.color))}break;case 2:this._themeService.restoreColor(e.index);break}}}_setup(){super._setup(),this._customKeyEventHandler=void 0}get buffer(){return this.buffers.active}focus(){this.textarea&&this.textarea.focus({preventScroll:!0})}_handleScreenReaderModeOptionChange(t){t?!this._accessibilityManager.value&&this._renderService&&(this._accessibilityManager.value=this._instantiationService.createInstance(Yr,this)):this._accessibilityManager.clear()}_handleTextAreaFocus(t){this.coreService.decPrivateModes.sendFocus&&this.coreService.triggerDataEvent(Z.ESC+"[I"),this.element.classList.add("focus"),this._showCursor(),this._onFocus.fire()}blur(){return this.textarea?.blur()}_handleTextAreaBlur(){this.textarea.value="",this.refresh(this.buffer.y,this.buffer.y),this.coreService.decPrivateModes.sendFocus&&this.coreService.triggerDataEvent(Z.ESC+"[O"),this.element.classList.remove("focus"),this._onBlur.fire()}_syncTextArea(){if(!this.textarea||!this.buffer.isCursorInViewport||this._compositionHelper.isComposing||!this._renderService)return;let t=this.buffer.ybase+this.buffer.y,e=this.buffer.lines.get(t);if(!e)return;let s=Math.min(this.buffer.x,this.cols-1),i=this._renderService.dimensions.css.cell.height,r=e.getWidth(s),o=this._renderService.dimensions.css.cell.width*r,a=this.buffer.y*this._renderService.dimensions.css.cell.height,l=s*this._renderService.dimensions.css.cell.width;this.textarea.style.left=l+"px",this.textarea.style.top=a+"px",this.textarea.style.width=o+"px",this.textarea.style.height=i+"px",this.textarea.style.lineHeight=i+"px",this.textarea.style.zIndex="-5"}_initGlobal(){this._bindKeys(),this._register(pe(this.element,"copy",e=>{this.hasSelection()&&Jb(e,this._selectionService)}));let t=e=>Zb(e,this.textarea,this.coreService,this.optionsService);this._register(pe(this.textarea,"paste",t)),this._register(pe(this.element,"paste",t)),ou?this._register(pe(this.element,"mousedown",e=>{e.button===2&&Ml(e,this.textarea,this.screenElement,this._selectionService,this.options.rightClickSelectsWord)})):this._register(pe(this.element,"contextmenu",e=>{Ml(e,this.textarea,this.screenElement,this._selectionService,this.options.rightClickSelectsWord)})),Oa&&this._register(pe(this.element,"auxclick",e=>{e.button===1&&Pd(e,this.textarea,this.screenElement)}))}_bindKeys(){this._register(pe(this.textarea,"keyup",t=>this._keyUp(t),!0)),this._register(pe(this.textarea,"keydown",t=>this._keyDown(t),!0)),this._register(pe(this.textarea,"keypress",t=>this._keyPress(t),!0)),this._register(pe(this.textarea,"compositionstart",()=>this._compositionHelper.compositionstart())),this._register(pe(this.textarea,"compositionupdate",t=>this._compositionHelper.compositionupdate(t))),this._register(pe(this.textarea,"compositionend",()=>this._compositionHelper.compositionend())),this._register(pe(this.textarea,"input",t=>this._inputEvent(t),!0)),this._register(this.onRender(()=>this._compositionHelper.updateCompositionElements()))}open(t){if(!t)throw new Error("Terminal requires a parent element.");if(t.isConnected||this._logService.debug("Terminal.open was called on an element that was not attached to the DOM"),this.element?.ownerDocument.defaultView&&this._coreBrowserService){this.element.ownerDocument.defaultView!==this._coreBrowserService.window&&(this._coreBrowserService.window=this.element.ownerDocument.defaultView);return}this._document=t.ownerDocument,this.options.documentOverride&&this.options.documentOverride instanceof Document&&(this._document=this.optionsService.rawOptions.documentOverride),this.element=this._document.createElement("div"),this.element.dir="ltr",this.element.classList.add("terminal"),this.element.classList.add("xterm"),t.appendChild(this.element);let e=this._document.createDocumentFragment();this._viewportElement=this._document.createElement("div"),this._viewportElement.classList.add("xterm-viewport"),e.appendChild(this._viewportElement),this.screenElement=this._document.createElement("div"),this.screenElement.classList.add("xterm-screen"),this._register(pe(this.screenElement,"mousemove",r=>this.updateCursorStyle(r))),this._helperContainer=this._document.createElement("div"),this._helperContainer.classList.add("xterm-helpers"),this.screenElement.appendChild(this._helperContainer),e.appendChild(this.screenElement);let s=this.textarea=this._document.createElement("textarea");this.textarea.classList.add("xterm-helper-textarea"),this.textarea.setAttribute("aria-label",to.get()),cu||this.textarea.setAttribute("aria-multiline","false"),this.textarea.setAttribute("autocorrect","off"),this.textarea.setAttribute("autocapitalize","off"),this.textarea.setAttribute("spellcheck","false"),this.textarea.tabIndex=0,this._register(this.optionsService.onSpecificOptionChange("disableStdin",()=>s.readOnly=this.optionsService.rawOptions.disableStdin)),this.textarea.readOnly=this.optionsService.rawOptions.disableStdin,this._coreBrowserService=this._register(this._instantiationService.createInstance(I0,this.textarea,t.ownerDocument.defaultView??window,this._document??typeof window<"u"?window.document:null)),this._instantiationService.setService(ns,this._coreBrowserService),this._register(pe(this.textarea,"focus",r=>this._handleTextAreaFocus(r))),this._register(pe(this.textarea,"blur",()=>this._handleTextAreaBlur())),this._helperContainer.appendChild(this.textarea),this._charSizeService=this._instantiationService.createInstance(jo,this._document,this._helperContainer),this._instantiationService.setService(hn,this._charSizeService),this._themeService=this._instantiationService.createInstance(Ro),this._instantiationService.setService(ci,this._themeService),this._characterJoinerService=this._instantiationService.createInstance(Vr),this._instantiationService.setService($d,this._characterJoinerService),this._renderService=this._register(this._instantiationService.createInstance(Eo,this.rows,this.screenElement)),this._instantiationService.setService(os,this._renderService),this._register(this._renderService.onRenderedViewportChange(r=>this._onRender.fire(r))),this.onResize(r=>this._renderService.resize(r.cols,r.rows)),this._compositionView=this._document.createElement("div"),this._compositionView.classList.add("composition-view"),this._compositionHelper=this._instantiationService.createInstance(wo,this.textarea,this._compositionView),this._helperContainer.appendChild(this._compositionView),this._mouseService=this._instantiationService.createInstance(No),this._instantiationService.setService(Ra,this._mouseService);let i=this._linkifier.value=this._register(this._instantiationService.createInstance(Oo,this.screenElement));this.element.appendChild(e);try{this._onWillOpen.fire(this.element)}catch{}this._renderService.hasRenderer()||this._renderService.setRenderer(this._createRenderer()),this._register(this.onCursorMove(()=>{this._renderService.handleCursorMove(),this._syncTextArea()})),this._register(this.onResize(()=>this._renderService.handleResize(this.cols,this.rows))),this._register(this.onBlur(()=>this._renderService.handleBlur())),this._register(this.onFocus(()=>this._renderService.handleFocus())),this._viewport=this._register(this._instantiationService.createInstance(yo,this.element,this.screenElement)),this._register(this._viewport.onRequestScrollLines(r=>{super.scrollLines(r,!1),this.refresh(0,this.rows-1)})),this._selectionService=this._register(this._instantiationService.createInstance(To,this.element,this.screenElement,i)),this._instantiationService.setService(oy,this._selectionService),this._register(this._selectionService.onRequestScrollLines(r=>this.scrollLines(r.amount,r.suppressScrollEvent))),this._register(this._selectionService.onSelectionChange(()=>this._onSelectionChange.fire())),this._register(this._selectionService.onRequestRedraw(r=>this._renderService.handleSelectionChanged(r.start,r.end,r.columnSelectMode))),this._register(this._selectionService.onLinuxMouseSelection(r=>{this.textarea.value=r,this.textarea.focus(),this.textarea.select()})),this._register(nt.any(this._onScroll.event,this._inputHandler.onScroll)(()=>{this._selectionService.refresh(),this._viewport?.queueSync()})),this._register(this._instantiationService.createInstance(So,this.screenElement)),this._register(pe(this.element,"mousedown",r=>this._selectionService.handleMouseDown(r))),this.coreMouseService.areMouseEventsActive?(this._selectionService.disable(),this.element.classList.add("enable-mouse-events")):this._selectionService.enable(),this.options.screenReaderMode&&(this._accessibilityManager.value=this._instantiationService.createInstance(Yr,this)),this._register(this.optionsService.onSpecificOptionChange("screenReaderMode",r=>this._handleScreenReaderModeOptionChange(r))),this.options.overviewRuler.width&&(this._overviewRulerRenderer=this._register(this._instantiationService.createInstance(Kr,this._viewportElement,this.screenElement))),this.optionsService.onSpecificOptionChange("overviewRuler",r=>{!this._overviewRulerRenderer&&r&&this._viewportElement&&this.screenElement&&(this._overviewRulerRenderer=this._register(this._instantiationService.createInstance(Kr,this._viewportElement,this.screenElement)))}),this._charSizeService.measure(),this.refresh(0,this.rows-1),this._initGlobal(),this.bindMouse()}_createRenderer(){return this._instantiationService.createInstance(ko,this,this._document,this.element,this.screenElement,this._viewportElement,this._helperContainer,this.linkifier)}bindMouse(){let t=this,e=this.element;function s(o){let a=t._mouseService.getMouseReportCoords(o,t.screenElement);if(!a)return!1;let l,h;switch(o.overrideType||o.type){case"mousemove":h=32,o.buttons===void 0?(l=3,o.button!==void 0&&(l=o.button<3?o.button:3)):l=o.buttons&1?0:o.buttons&4?1:o.buttons&2?2:3;break;case"mouseup":h=0,l=o.button<3?o.button:3;break;case"mousedown":h=1,l=o.button<3?o.button:3;break;case"wheel":if(t._customWheelEventHandler&&t._customWheelEventHandler(o)===!1)return!1;let c=o.deltaY;if(c===0||t.coreMouseService.consumeWheelEvent(o,t._renderService?.dimensions?.device?.cell?.height,t._coreBrowserService?.dpr)===0)return!1;h=c<0?0:1,l=4;break;default:return!1}return h===void 0||l===void 0||l>4?!1:t.coreMouseService.triggerMouseEvent({col:a.col,row:a.row,x:a.x,y:a.y,button:l,action:h,ctrl:o.ctrlKey,alt:o.altKey,shift:o.shiftKey})}let i={mouseup:null,wheel:null,mousedrag:null,mousemove:null},r={mouseup:o=>(s(o),o.buttons||(this._document.removeEventListener("mouseup",i.mouseup),i.mousedrag&&this._document.removeEventListener("mousemove",i.mousedrag)),this.cancel(o)),wheel:o=>(s(o),this.cancel(o,!0)),mousedrag:o=>{o.buttons&&s(o)},mousemove:o=>{o.buttons||s(o)}};this._register(this.coreMouseService.onProtocolChange(o=>{o?(this.optionsService.rawOptions.logLevel==="debug"&&this._logService.debug("Binding to mouse events:",this.coreMouseService.explainEvents(o)),this.element.classList.add("enable-mouse-events"),this._selectionService.disable()):(this._logService.debug("Unbinding from mouse events."),this.element.classList.remove("enable-mouse-events"),this._selectionService.enable()),o&8?i.mousemove||(e.addEventListener("mousemove",r.mousemove),i.mousemove=r.mousemove):(e.removeEventListener("mousemove",i.mousemove),i.mousemove=null),o&16?i.wheel||(e.addEventListener("wheel",r.wheel,{passive:!1}),i.wheel=r.wheel):(e.removeEventListener("wheel",i.wheel),i.wheel=null),o&2?i.mouseup||(i.mouseup=r.mouseup):(this._document.removeEventListener("mouseup",i.mouseup),i.mouseup=null),o&4?i.mousedrag||(i.mousedrag=r.mousedrag):(this._document.removeEventListener("mousemove",i.mousedrag),i.mousedrag=null)})),this.coreMouseService.activeProtocol=this.coreMouseService.activeProtocol,this._register(pe(e,"mousedown",o=>{if(o.preventDefault(),this.focus(),!(!this.coreMouseService.areMouseEventsActive||this._selectionService.shouldForceSelection(o)))return s(o),i.mouseup&&this._document.addEventListener("mouseup",i.mouseup),i.mousedrag&&this._document.addEventListener("mousemove",i.mousedrag),this.cancel(o)})),this._register(pe(e,"wheel",o=>{if(!i.wheel){if(this._customWheelEventHandler&&this._customWheelEventHandler(o)===!1)return!1;if(!this.buffer.hasScrollback){if(o.deltaY===0)return!1;if(t.coreMouseService.consumeWheelEvent(o,t._renderService?.dimensions?.device?.cell?.height,t._coreBrowserService?.dpr)===0)return this.cancel(o,!0);let a=Z.ESC+(this.coreService.decPrivateModes.applicationCursorKeys?"O":"[")+(o.deltaY<0?"A":"B");return this.coreService.triggerDataEvent(a,!0),this.cancel(o,!0)}}},{passive:!1}))}refresh(t,e){this._renderService?.refreshRows(t,e)}updateCursorStyle(t){this._selectionService?.shouldColumnSelect(t)?this.element.classList.add("column-select"):this.element.classList.remove("column-select")}_showCursor(){this.coreService.isCursorInitialized||(this.coreService.isCursorInitialized=!0,this.refresh(this.buffer.y,this.buffer.y))}scrollLines(t,e){this._viewport?this._viewport.scrollLines(t):super.scrollLines(t,e),this.refresh(0,this.rows-1)}scrollPages(t){this.scrollLines(t*(this.rows-1))}scrollToTop(){this.scrollLines(-this._bufferService.buffer.ydisp)}scrollToBottom(t){t&&this._viewport?this._viewport.scrollToLine(this.buffer.ybase,!0):this.scrollLines(this._bufferService.buffer.ybase-this._bufferService.buffer.ydisp)}scrollToLine(t){let e=t-this._bufferService.buffer.ydisp;e!==0&&this.scrollLines(e)}paste(t){Rd(t,this.textarea,this.coreService,this.optionsService)}attachCustomKeyEventHandler(t){this._customKeyEventHandler=t}attachCustomWheelEventHandler(t){this._customWheelEventHandler=t}registerLinkProvider(t){return this._linkProviderService.registerLinkProvider(t)}registerCharacterJoiner(t){if(!this._characterJoinerService)throw new Error("Terminal must be opened first");let e=this._characterJoinerService.register(t);return this.refresh(0,this.rows-1),e}deregisterCharacterJoiner(t){if(!this._characterJoinerService)throw new Error("Terminal must be opened first");this._characterJoinerService.deregister(t)&&this.refresh(0,this.rows-1)}get markers(){return this.buffer.markers}registerMarker(t){return this.buffer.addMarker(this.buffer.ybase+this.buffer.y+t)}registerDecoration(t){return this._decorationService.registerDecoration(t)}hasSelection(){return this._selectionService?this._selectionService.hasSelection:!1}select(t,e,s){this._selectionService.setSelection(t,e,s)}getSelection(){return this._selectionService?this._selectionService.selectionText:""}getSelectionPosition(){if(!(!this._selectionService||!this._selectionService.hasSelection))return{start:{x:this._selectionService.selectionStart[0],y:this._selectionService.selectionStart[1]},end:{x:this._selectionService.selectionEnd[0],y:this._selectionService.selectionEnd[1]}}}clearSelection(){this._selectionService?.clearSelection()}selectAll(){this._selectionService?.selectAll()}selectLines(t,e){this._selectionService?.selectLines(t,e)}_keyDown(t){if(this._keyDownHandled=!1,this._keyDownSeen=!0,this._customKeyEventHandler&&this._customKeyEventHandler(t)===!1)return!1;let e=this.browser.isMac&&this.options.macOptionIsMeta&&t.altKey;if(!e&&!this._compositionHelper.keydown(t))return this.options.scrollOnUserInput&&this.buffer.ybase!==this.buffer.ydisp&&this.scrollToBottom(!0),!1;!e&&(t.key==="Dead"||t.key==="AltGraph")&&(this._unprocessedDeadKey=!0);let s=zS(t,this.coreService.decPrivateModes.applicationCursorKeys,this.browser.isMac,this.options.macOptionIsMeta);if(this.updateCursorStyle(t),s.type===3||s.type===2){let i=this.rows-1;return this.scrollLines(s.type===2?-i:i),this.cancel(t,!0)}if(s.type===1&&this.selectAll(),this._isThirdLevelShift(this.browser,t)||(s.cancel&&this.cancel(t,!0),!s.key)||t.key&&!t.ctrlKey&&!t.altKey&&!t.metaKey&&t.key.length===1&&t.key.charCodeAt(0)>=65&&t.key.charCodeAt(0)<=90)return!0;if(this._unprocessedDeadKey)return this._unprocessedDeadKey=!1,!0;if((s.key===Z.ETX||s.key===Z.CR)&&(this.textarea.value=""),this._onKey.fire({key:s.key,domEvent:t}),this._showCursor(),this.coreService.triggerDataEvent(s.key,!0),!this.optionsService.rawOptions.screenReaderMode||t.altKey||t.ctrlKey)return this.cancel(t,!0);this._keyDownHandled=!0}_isThirdLevelShift(t,e){let s=t.isMac&&!this.options.macOptionIsMeta&&e.altKey&&!e.ctrlKey&&!e.metaKey||t.isWindows&&e.altKey&&e.ctrlKey&&!e.metaKey||t.isWindows&&e.getModifierState("AltGraph");return e.type==="keypress"?s:s&&(!e.keyCode||e.keyCode>47)}_keyUp(t){this._keyDownSeen=!1,!(this._customKeyEventHandler&&this._customKeyEventHandler(t)===!1)&&(GS(t)||this.focus(),this.updateCursorStyle(t),this._keyPressHandled=!1)}_keyPress(t){let e;if(this._keyPressHandled=!1,this._keyDownHandled||this._customKeyEventHandler&&this._customKeyEventHandler(t)===!1)return!1;if(this.cancel(t),t.charCode)e=t.charCode;else if(t.which===null||t.which===void 0)e=t.keyCode;else if(t.which!==0&&t.charCode!==0)e=t.which;else return!1;return!e||(t.altKey||t.ctrlKey||t.metaKey)&&!this._isThirdLevelShift(this.browser,t)?!1:(e=String.fromCharCode(e),this._onKey.fire({key:e,domEvent:t}),this._showCursor(),this.coreService.triggerDataEvent(e,!0),this._keyPressHandled=!0,this._unprocessedDeadKey=!1,!0)}_inputEvent(t){if(t.data&&t.inputType==="insertText"&&(!t.composed||!this._keyDownSeen)&&!this.optionsService.rawOptions.screenReaderMode){if(this._keyPressHandled)return!1;this._unprocessedDeadKey=!1;let e=t.data;return this.coreService.triggerDataEvent(e,!0),this.cancel(t),!0}return!1}resize(t,e){if(t===this.cols&&e===this.rows){this._charSizeService&&!this._charSizeService.hasValidSize&&this._charSizeService.measure();return}super.resize(t,e)}_afterResize(t,e){this._charSizeService?.measure()}clear(){if(!(this.buffer.ybase===0&&this.buffer.y===0)){this.buffer.clearAllMarkers(),this.buffer.lines.set(0,this.buffer.lines.get(this.buffer.ybase+this.buffer.y)),this.buffer.lines.length=1,this.buffer.ydisp=0,this.buffer.ybase=0,this.buffer.y=0;for(let t=1;t<this.rows;t++)this.buffer.lines.push(this.buffer.getBlankLine(We));this._onScroll.fire({position:this.buffer.ydisp}),this.refresh(0,this.rows-1)}}reset(){this.options.rows=this.rows,this.options.cols=this.cols;let t=this._customKeyEventHandler;this._setup(),super.reset(),this._selectionService?.reset(),this._decorationService.reset(),this._customKeyEventHandler=t,this.refresh(0,this.rows-1)}clearTextureAtlas(){this._renderService?.clearTextureAtlas()}_reportFocus(){this.element?.classList.contains("focus")?this.coreService.triggerDataEvent(Z.ESC+"[I"):this.coreService.triggerDataEvent(Z.ESC+"[O")}_reportWindowsOptions(t){if(this._renderService)switch(t){case 0:let e=this._renderService.dimensions.css.canvas.width.toFixed(0),s=this._renderService.dimensions.css.canvas.height.toFixed(0);this.coreService.triggerDataEvent(`${Z.ESC}[4;${s};${e}t`);break;case 1:let i=this._renderService.dimensions.css.cell.width.toFixed(0),r=this._renderService.dimensions.css.cell.height.toFixed(0);this.coreService.triggerDataEvent(`${Z.ESC}[6;${r};${i}t`);break}}cancel(t,e){if(!(!this.options.cancelEvents&&!e))return t.preventDefault(),t.stopPropagation(),!1}};function GS(t){return t.keyCode===16||t.keyCode===17||t.keyCode===18}var YS=class{constructor(){this._addons=[]}dispose(){for(let t=this._addons.length-1;t>=0;t--)this._addons[t].instance.dispose()}loadAddon(t,e){let s={instance:e,dispose:e.dispose,isDisposed:!1};this._addons.push(s),e.dispose=()=>this._wrappedAddonDispose(s),e.activate(t)}_wrappedAddonDispose(t){if(t.isDisposed)return;let e=-1;for(let s=0;s<this._addons.length;s++)if(this._addons[s]===t){e=s;break}if(e===-1)throw new Error("Could not dispose an addon that has not been loaded");t.isDisposed=!0,t.dispose.apply(t.instance),this._addons.splice(e,1)}},XS=class{constructor(t){this._line=t}get isWrapped(){return this._line.isWrapped}get length(){return this._line.length}getCell(t,e){if(!(t<0||t>=this._line.length))return e?(this._line.loadCell(t,e),e):this._line.loadCell(t,new Nt)}translateToString(t,e,s){return this._line.translateToString(t,e,s)}},Nc=class{constructor(t,e){this._buffer=t,this.type=e}init(t){return this._buffer=t,this}get cursorY(){return this._buffer.y}get cursorX(){return this._buffer.x}get viewportY(){return this._buffer.ydisp}get baseY(){return this._buffer.ybase}get length(){return this._buffer.lines.length}getLine(t){let e=this._buffer.lines.get(t);if(e)return new XS(e)}getNullCell(){return new Nt}},JS=class extends ye{constructor(t){super(),this._core=t,this._onBufferChange=this._register(new ae),this.onBufferChange=this._onBufferChange.event,this._normal=new Nc(this._core.buffers.normal,"normal"),this._alternate=new Nc(this._core.buffers.alt,"alternate"),this._core.buffers.onBufferActivate(()=>this._onBufferChange.fire(this.active))}get active(){if(this._core.buffers.active===this._core.buffers.normal)return this.normal;if(this._core.buffers.active===this._core.buffers.alt)return this.alternate;throw new Error("Active buffer is neither normal nor alternate")}get normal(){return this._normal.init(this._core.buffers.normal)}get alternate(){return this._alternate.init(this._core.buffers.alt)}},ZS=class{constructor(t){this._core=t}registerCsiHandler(t,e){return this._core.registerCsiHandler(t,s=>e(s.toArray()))}addCsiHandler(t,e){return this.registerCsiHandler(t,e)}registerDcsHandler(t,e){return this._core.registerDcsHandler(t,(s,i)=>e(s,i.toArray()))}addDcsHandler(t,e){return this.registerDcsHandler(t,e)}registerEscHandler(t,e){return this._core.registerEscHandler(t,e)}addEscHandler(t,e){return this.registerEscHandler(t,e)}registerOscHandler(t,e){return this._core.registerOscHandler(t,e)}addOscHandler(t,e){return this.registerOscHandler(t,e)}},QS=class{constructor(t){this._core=t}register(t){this._core.unicodeService.register(t)}get versions(){return this._core.unicodeService.versions}get activeVersion(){return this._core.unicodeService.activeVersion}set activeVersion(t){this._core.unicodeService.activeVersion=t}},e2=["cols","rows"],zt=0,t2=class extends ye{constructor(t){super(),this._core=this._register(new qS(t)),this._addonManager=this._register(new YS),this._publicOptions={...this._core.options};let e=i=>this._core.options[i],s=(i,r)=>{this._checkReadonlyOptions(i),this._core.options[i]=r};for(let i in this._core.options){let r={get:e.bind(this,i),set:s.bind(this,i)};Object.defineProperty(this._publicOptions,i,r)}}_checkReadonlyOptions(t){if(e2.includes(t))throw new Error(`Option "${t}" can only be set in the constructor`)}_checkProposedApi(){if(!this._core.optionsService.rawOptions.allowProposedApi)throw new Error("You must set the allowProposedApi option to true to use proposed API")}get onBell(){return this._core.onBell}get onBinary(){return this._core.onBinary}get onCursorMove(){return this._core.onCursorMove}get onData(){return this._core.onData}get onKey(){return this._core.onKey}get onLineFeed(){return this._core.onLineFeed}get onRender(){return this._core.onRender}get onResize(){return this._core.onResize}get onScroll(){return this._core.onScroll}get onSelectionChange(){return this._core.onSelectionChange}get onTitleChange(){return this._core.onTitleChange}get onWriteParsed(){return this._core.onWriteParsed}get element(){return this._core.element}get parser(){return this._parser||(this._parser=new ZS(this._core)),this._parser}get unicode(){return this._checkProposedApi(),new QS(this._core)}get textarea(){return this._core.textarea}get rows(){return this._core.rows}get cols(){return this._core.cols}get buffer(){return this._buffer||(this._buffer=this._register(new JS(this._core))),this._buffer}get markers(){return this._checkProposedApi(),this._core.markers}get modes(){let t=this._core.coreService.decPrivateModes,e="none";switch(this._core.coreMouseService.activeProtocol){case"X10":e="x10";break;case"VT200":e="vt200";break;case"DRAG":e="drag";break;case"ANY":e="any";break}return{applicationCursorKeysMode:t.applicationCursorKeys,applicationKeypadMode:t.applicationKeypad,bracketedPasteMode:t.bracketedPasteMode,insertMode:this._core.coreService.modes.insertMode,mouseTrackingMode:e,originMode:t.origin,reverseWraparoundMode:t.reverseWraparound,sendFocusMode:t.sendFocus,synchronizedOutputMode:t.synchronizedOutput,wraparoundMode:t.wraparound}}get options(){return this._publicOptions}set options(t){for(let e in t)this._publicOptions[e]=t[e]}blur(){this._core.blur()}focus(){this._core.focus()}input(t,e=!0){this._core.input(t,e)}resize(t,e){this._verifyIntegers(t,e),this._core.resize(t,e)}open(t){this._core.open(t)}attachCustomKeyEventHandler(t){this._core.attachCustomKeyEventHandler(t)}attachCustomWheelEventHandler(t){this._core.attachCustomWheelEventHandler(t)}registerLinkProvider(t){return this._core.registerLinkProvider(t)}registerCharacterJoiner(t){return this._checkProposedApi(),this._core.registerCharacterJoiner(t)}deregisterCharacterJoiner(t){this._checkProposedApi(),this._core.deregisterCharacterJoiner(t)}registerMarker(t=0){return this._verifyIntegers(t),this._core.registerMarker(t)}registerDecoration(t){return this._checkProposedApi(),this._verifyPositiveIntegers(t.x??0,t.width??0,t.height??0),this._core.registerDecoration(t)}hasSelection(){return this._core.hasSelection()}select(t,e,s){this._verifyIntegers(t,e,s),this._core.select(t,e,s)}getSelection(){return this._core.getSelection()}getSelectionPosition(){return this._core.getSelectionPosition()}clearSelection(){this._core.clearSelection()}selectAll(){this._core.selectAll()}selectLines(t,e){this._verifyIntegers(t,e),this._core.selectLines(t,e)}dispose(){super.dispose()}scrollLines(t){this._verifyIntegers(t),this._core.scrollLines(t)}scrollPages(t){this._verifyIntegers(t),this._core.scrollPages(t)}scrollToTop(){this._core.scrollToTop()}scrollToBottom(){this._core.scrollToBottom()}scrollToLine(t){this._verifyIntegers(t),this._core.scrollToLine(t)}clear(){this._core.clear()}write(t,e){this._core.write(t,e)}writeln(t,e){this._core.write(t),this._core.write(`\r
|
|
309
|
-
`,e)}paste(t){this._core.paste(t)}refresh(t,e){this._verifyIntegers(t,e),this._core.refresh(t,e)}reset(){this._core.reset()}clearTextureAtlas(){this._core.clearTextureAtlas()}loadAddon(t){this._addonManager.loadAddon(this,t)}static get strings(){return{get promptLabel(){return to.get()},set promptLabel(t){to.set(t)},get tooMuchOutput(){return so.get()},set tooMuchOutput(t){so.set(t)}}}_verifyIntegers(...t){for(zt of t)if(zt===1/0||isNaN(zt)||zt%1!==0)throw new Error("This API only accepts integers")}_verifyPositiveIntegers(...t){for(zt of t)if(zt&&(zt===1/0||isNaN(zt)||zt%1!==0||zt<0))throw new Error("This API only accepts positive integers")}};var s2=2,i2=1,r2=class{activate(t){this._terminal=t}dispose(){}fit(){let t=this.proposeDimensions();if(!t||!this._terminal||isNaN(t.cols)||isNaN(t.rows))return;let e=this._terminal._core;(this._terminal.rows!==t.rows||this._terminal.cols!==t.cols)&&(e._renderService.clear(),this._terminal.resize(t.cols,t.rows))}proposeDimensions(){if(!this._terminal||!this._terminal.element||!this._terminal.element.parentElement)return;let t=this._terminal._core._renderService.dimensions;if(t.css.cell.width===0||t.css.cell.height===0)return;let e=this._terminal.options.scrollback===0?0:this._terminal.options.overviewRuler?.width||14,s=window.getComputedStyle(this._terminal.element.parentElement),i=parseInt(s.getPropertyValue("height")),r=Math.max(0,parseInt(s.getPropertyValue("width"))),o=window.getComputedStyle(this._terminal.element),a={top:parseInt(o.getPropertyValue("padding-top")),bottom:parseInt(o.getPropertyValue("padding-bottom")),right:parseInt(o.getPropertyValue("padding-right")),left:parseInt(o.getPropertyValue("padding-left"))},l=a.top+a.bottom,h=a.right+a.left,c=i-l,d=r-h-e;return{cols:Math.max(s2,Math.floor(d/t.css.cell.width)),rows:Math.max(i2,Math.floor(c/t.css.cell.height))}}};function n2({source:t,onReady:e,onSelectionChange:s,className:i}){const r=E.useRef(null),o=E.useRef(null),a=E.useRef(s);a.current=s;const l=Yt(),h=E.useRef(t);return h.current=t,H_((c,d)=>{c===h.current&&o.current?.write(d)}),E.useEffect(()=>{const c=r.current;if(!c)return;const d=getComputedStyle(document.documentElement),u=v=>d.getPropertyValue(v).trim()||void 0,f=new t2({allowTransparency:!1,fontFamily:u("--font-mono")||"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",fontSize:12.5,lineHeight:1.5,scrollback:5e3,cursorBlink:!1,disableStdin:!0,theme:{background:u("--sidebar")||u("--card")||u("--background")||"#1e1e1e",cursor:"transparent",foreground:u("--foreground")||"#d4d4d4",selectionBackground:u("--accent"),selectionForeground:u("--accent-foreground"),black:u("--muted"),red:u("--destructive"),green:u("--success"),yellow:u("--warning"),blue:u("--chart-1"),magenta:u("--chart-3"),cyan:u("--chart-5"),white:u("--foreground"),brightBlack:u("--muted-foreground"),brightRed:u("--destructive"),brightGreen:u("--success"),brightYellow:u("--warning"),brightBlue:u("--chart-1"),brightMagenta:u("--chart-3"),brightCyan:u("--chart-5"),brightWhite:u("--foreground")}}),m=new r2;f.loadAddon(m),f.open(c),m.fit();const p=l.getBuffer(t);p&&f.write(p),o.current=f,e?.(f);const _=f.onSelectionChange(()=>{const v=!!f.getSelection();a.current?.(v,()=>f.getSelection())}),g=new ResizeObserver(()=>{m.fit()});return g.observe(c),()=>{_.dispose(),g.disconnect(),o.current=null,f.dispose()}},[]),n.jsx("div",{className:he("h-full bg-sidebar p-3",i),children:n.jsx("div",{ref:r,className:"h-full"})})}function o2(t){const e=Yt(),[s,i]=E.useState(ws),[r,o]=E.useState([]),[a,l]=E.useState(new Set),h=E.useRef(!1);if(!h.current&&e.scripts.length>0){const y=Qp.find(w=>e.scripts.includes(w));y&&(h.current=!0,o(w=>w.includes(y)?w:[...w,y]),i(y))}if(a.size>0){let y=!1;const w=new Set(a);for(const C of a)e.activeProcesses.includes(C)||(w.delete(C),y=!0);y&&l(w)}const c=()=>t.onOpenChange(!t.open),d=y=>{i(y),t.open||t.onOpenChange(!0)},u=y=>!t.virtualMcpId||!t.branch?Promise.resolve(null):fetch(`/api/${encodeURIComponent(t.orgSlug)}/sandbox/${encodeURIComponent(t.virtualMcpId)}/${encodeURIComponent(t.branch)}/exec/${encodeURIComponent(y)}`,{method:"POST"}),f=y=>!t.virtualMcpId||!t.branch?Promise.resolve(null):fetch(`/api/${encodeURIComponent(t.orgSlug)}/sandbox/${encodeURIComponent(t.virtualMcpId)}/${encodeURIComponent(t.branch)}/exec/${encodeURIComponent(y)}/kill`,{method:"POST"}),m=async y=>{o(w=>w.includes(y)?w:[...w,y]),i(y),t.onOpenChange(!0);try{const w=await u(y);if(w===null)return;if(!w.ok)throw new Error(`Exec failed: ${w.statusText}`)}catch{le.error("Failed to run "+y)}},p=async y=>{await f(y),o(w=>w.filter(C=>C!==y)),s===y&&i(ws)},_=async()=>{const y=e.activeProcesses.includes(s);try{const w=await u(s);if(w===null)return;if(!w.ok)throw new Error(`Exec failed: ${w.statusText}`)}catch{le.error((y?"Failed to restart ":"Failed to run ")+s)}},g=async()=>{if(!a.has(s)){l(y=>new Set(y).add(s));try{const y=await f(s);if(y===null){l(w=>{const C=new Set(w);return C.delete(s),C});return}if(!y.ok)throw new Error(`Kill failed: ${y.statusText}`)}catch{l(y=>{const w=new Set(y);return w.delete(s),w}),le.error("Failed to stop "+s)}}},v=s!==ws&&r.includes(s),b=v&&e.activeProcesses.includes(s),x=v&&a.has(s);return n.jsxs("div",{className:"flex shrink-0 flex-col",style:{height:t.open?"50%":"auto"},children:[n.jsx(Fb,{status:t.status,open:t.open,onToggle:c,onStart:t.status==="idle"?t.onStart:void 0,onStop:t.status==="running"||t.status==="starting"?t.onStop:void 0,onRestart:t.status==="running"?t.onRestart:void 0,onResume:t.status==="suspended"?t.onResume:void 0,onRetry:t.status==="errored"?t.onRetry:void 0,scripts:t.scripts,active:s,scriptTabs:r,onSelectTab:d,onAddScript:m,onCloseScript:p,showScriptControls:v,scriptIsRunning:b,scriptIsKilling:x,onRunActiveScript:_,onStopActiveScript:g}),t.open&&n.jsx("div",{className:"flex-1 overflow-hidden",children:n.jsx(a2,{vmId:t.vmId,active:s,hasData:e.hasData(s),onRunActive:_})})]})}function a2(t){const e=K.c(10),{vmId:s,active:i,hasData:r,onRunActive:o}=t;if(!s)return null;if(i===ws||r){let d;return e[0]!==i?(d=n.jsx(n2,{source:i,className:"h-full"},i),e[0]=i,e[1]=d):d=e[1],d}let a;e[2]!==i?(a=n.jsxs("p",{children:['Script "',n.jsx("span",{className:"font-mono text-foreground",children:i}),'" not running']}),e[2]=i,e[3]=a):a=e[3];let l;e[4]===Symbol.for("react.memo_cache_sentinel")?(l=n.jsx(Vs,{className:"size-3.5"}),e[4]=l):l=e[4];let h;e[5]!==o?(h=n.jsxs("button",{type:"button",onClick:o,className:"flex items-center gap-1.5 rounded-md border border-border px-3 py-1.5 text-xs text-foreground hover:bg-accent",children:[l," Run"]}),e[5]=o,e[6]=h):h=e[6];let c;return e[7]!==a||e[8]!==h?(c=n.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 text-sm text-muted-foreground",children:[a,h]}),e[7]=a,e[8]=h,e[9]=c):c=e[9],c}const xu=t=>`preview-drawer:${t}`;function l2(t){try{const e=localStorage.getItem(xu(t));return e?!!JSON.parse(e).open:!1}catch{return!1}}function c2(t,e){try{localStorage.setItem(xu(t),JSON.stringify({open:e}))}catch{}}function h2(){const t=K.c(17),e=sr(),{org:s}=Pe(),i=e?.virtualMcpId??null,r=id(),o=Yt(),a=i??"__no-vmcp__",[l,h]=E.useState(null),c=E.useRef(null);c.current!==a&&(c.current=a,h(l2(a)));const d=l??!1;let u;t[0]!==a?(u=g=>{h(g),c2(a,g)},t[0]=a,t[1]=u):u=t[1];const f=u,m=r.vmEntry?.sandboxHandle??"no-vm",p=r.vmEntry?.sandboxHandle??null;let _;return t[2]!==o.scripts||t[3]!==f||t[4]!==r.branch||t[5]!==r.restart||t[6]!==r.resume||t[7]!==r.retry||t[8]!==r.start||t[9]!==r.status||t[10]!==r.stop||t[11]!==d||t[12]!==s.slug||t[13]!==m||t[14]!==p||t[15]!==i?(_=n.jsx(o2,{vmId:p,orgSlug:s.slug,virtualMcpId:i,branch:r.branch,status:r.status,scripts:o.scripts,open:d,onOpenChange:f,onStart:r.start,onStop:r.stop,onRestart:r.restart,onResume:r.resume,onRetry:r.retry},m),t[2]=o.scripts,t[3]=f,t[4]=r.branch,t[5]=r.restart,t[6]=r.resume,t[7]=r.retry,t[8]=r.start,t[9]=r.status,t[10]=r.stop,t[11]=d,t[12]=s.slug,t[13]=m,t[14]=p,t[15]=i,t[16]=_):_=t[16],_}function bu(t){const e=K.c(10),{virtualMcpId:s,taskId:i}=t,o=sr()?.entity?.metadata;let a;e[0]!==o?(a=ti(o),e[0]=o,e[1]=a):a=e[1];const l=a;let h;e[2]!==i||e[3]!==s?(h=n.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:n.jsx(zb,{taskId:i,virtualMcpId:s})}),e[2]=i,e[3]=s,e[4]=h):h=e[4];let c;e[5]!==l?(c=l&&n.jsx(h2,{}),e[5]=l,e[6]=c):c=e[6];let d;return e[7]!==h||e[8]!==c?(d=n.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[h,c]}),e[7]=h,e[8]=c,e[9]=d):d=e[9],d}function d2(t){const e=K.c(9),{children:s,defaultSize:i,chatOpen:r,chatPanelWidth:o,onChatPanelResize:a}=t,[,l]=E.useTransition(),h=i>0&&i<100?o:i;let c;e[0]!==a?(c=p=>l(()=>{p>0&&p<100&&a(p)}),e[0]=a,e[1]=c):c=e[1];const d=c,u=r?"min-w-[348px]":"min-w-0";let f;e[2]!==u?(f=he("overflow-hidden bg-sidebar",u),e[2]=u,e[3]=f):f=e[3];let m;return e[4]!==s||e[5]!==h||e[6]!==d||e[7]!==f?(m=n.jsx(th,{defaultSize:h,minSize:20,collapsible:!0,collapsedSize:0,className:f,onResize:d,order:1,children:s}),e[4]=s,e[5]=h,e[6]=d,e[7]=f,e[8]=m):m=e[8],m}function u2(t){const e=K.c(32),{virtualMcpId:s,taskId:i,chatOpen:r,mainOpen:o,chatContent:a}=t;let l;e[0]!==r||e[1]!==o?(l=tl(r,o),e[0]=r,e[1]=o,e[2]=l):l=e[2];const h=l,[c,d]=Vp(),u=E.useRef(null);let f,m;e[3]!==r||e[4]!==c||e[5]!==o?(f=()=>{const P=u.current;if(!P)return;const T=tl(r,o),S=T.chat>0&&T.chat<100?c:T.chat,k=T.chat>0&&T.chat<100?100-c:T.main;P.setLayout([S,k])},m=[r,o,c],e[3]=r,e[4]=c,e[5]=o,e[6]=f,e[7]=m):(f=e[6],m=e[7]),E.useEffect(f,m);const p=`${s}-${i}`;let _;e[8]===Symbol.for("react.memo_cache_sentinel")?(_={overflow:"visible"},e[8]=_):_=e[8];let g;e[9]!==a?(g=a??n.jsx(gh,{}),e[9]=a,e[10]=g):g=e[10];let v;e[11]!==g?(v=n.jsx("div",{className:"h-full p-0.5 pt-0.25",children:n.jsx("div",{className:"h-full bg-background rounded-[0.75rem] overflow-hidden card-shadow",children:g})}),e[11]=g,e[12]=v):v=e[12];let b;e[13]!==r||e[14]!==c||e[15]!==d||e[16]!==h.chat||e[17]!==v?(b=n.jsx(d2,{defaultSize:h.chat,chatOpen:r,chatPanelWidth:c,onChatPanelResize:d,children:v}),e[13]=r,e[14]=c,e[15]=d,e[16]=h.chat,e[17]=v,e[18]=b):b=e[18];let x;e[19]===Symbol.for("react.memo_cache_sentinel")?(x=n.jsx(lm,{className:"bg-sidebar"}),e[19]=x):x=e[19];const y=h.main;let w;e[20]===Symbol.for("react.memo_cache_sentinel")?(w={overflow:"visible"},e[20]=w):w=e[20];let C;e[21]===Symbol.for("react.memo_cache_sentinel")?(C=he("flex flex-col h-full min-h-0 bg-background overflow-hidden","card-shadow","transition-[border-radius] duration-200 ease-[var(--ease-out-quart)]","rounded-[0.75rem]"),e[21]=C):C=e[21];let j;e[22]!==i||e[23]!==s?(j=n.jsx("div",{className:"h-full p-0.5 pt-0.25",children:n.jsx("div",{className:C,children:n.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:n.jsx(bu,{taskId:i,virtualMcpId:s})})})}),e[22]=i,e[23]=s,e[24]=j):j=e[24];let R;e[25]!==h.main||e[26]!==j?(R=n.jsx(th,{className:"min-w-0 flex flex-col",order:2,defaultSize:y,style:w,collapsible:!0,collapsedSize:0,minSize:20,children:j}),e[25]=h.main,e[26]=j,e[27]=R):R=e[27];let B;return e[28]!==R||e[29]!==p||e[30]!==b?(B=n.jsxs(cm,{ref:u,direction:"horizontal",className:"flex-1 min-h-0 pb-1 pr-1 pl-0 pt-0",style:_,children:[b,x,R]},p),e[28]=R,e[29]=p,e[30]=b,e[31]=B):B=e[31],B}function f2(t){const e=K.c(15),{chatOpen:s,toggleChat:i,onNewTask:r}=t;let o;e[0]!==s||e[1]!==i?(o=()=>{De("agent_toolbar_toggled",{button:"chat",next_state:s?"closed":"open"}),i()},e[0]=s,e[1]=i,e[2]=o):o=e[2];let a;e[3]===Symbol.for("react.memo_cache_sentinel")?(a=n.jsx(Xc,{size:16}),e[3]=a):a=e[3];let l;e[4]!==s||e[5]!==o?(l=n.jsx(Ee,{asChild:!0,children:n.jsx(Xa,{onClick:o,"aria-pressed":s,"aria-label":"Chat",active:s,children:a})}),e[4]=s,e[5]=o,e[6]=l):l=e[6];let h;e[7]===Symbol.for("react.memo_cache_sentinel")?(h=n.jsx(Te,{side:"bottom",children:"Chat"}),e[7]=h):h=e[7];let c;e[8]!==l?(c=n.jsxs(Re,{delayDuration:300,children:[l,h]}),e[8]=l,e[9]=c):c=e[9];let d;e[10]!==r?(d=r&&n.jsxs(Re,{delayDuration:300,children:[n.jsx(Ee,{asChild:!0,children:n.jsx(Xa,{onClick:r,"aria-label":"New task",children:n.jsx(Zr,{size:16})})}),n.jsx(Te,{side:"bottom",children:"New task"})]}),e[10]=r,e[11]=d):d=e[11];let u;return e[12]!==c||e[13]!==d?(u=n.jsxs(n.Fragment,{children:[c,d]}),e[12]=c,e[13]=d,e[14]=u):u=e[14],u}function m2(t,e,s){if(t.length<=s)return{visible:t,overflow:[]};const i=t.slice(0,s),r=t.slice(s);if(e==null)return{visible:i,overflow:r};if(i.some(u=>u.id===e))return{visible:i,overflow:r};const a=r.findIndex(u=>u.id===e);if(a===-1)return{visible:i,overflow:r};const l=i[i.length-1],h=r[a],c=[...i.slice(0,-1),h],d=[l,...r.slice(0,a),...r.slice(a+1)];return{visible:c,overflow:d}}function p2(t){const e=K.c(13),{overflow:s,onSelect:i}=t,[r,o]=E.useState(!1);let a;e[0]!==i?(a=f=>{o(!1),i(f)},e[0]=i,e[1]=a):a=e[1];const l=a;let h;e[2]===Symbol.for("react.memo_cache_sentinel")?(h=n.jsx(Rs,{asChild:!0,children:n.jsx("button",{type:"button",title:"More tabs","aria-label":"More tabs",className:"shrink-0 flex size-8 items-center justify-center rounded-md text-muted-foreground hover:bg-accent hover:text-foreground transition-colors",children:n.jsx(tn,{className:"size-4"})})}),e[2]=h):h=e[2];let c;if(e[3]!==l||e[4]!==s){let f;e[6]!==l?(f=m=>n.jsx("li",{children:n.jsxs("button",{type:"button",onClick:()=>l(m.id),className:"w-full flex items-center gap-2 px-3 py-2 rounded-md hover:bg-accent text-sm text-foreground",children:[n.jsx("span",{className:"flex size-5 items-center justify-center shrink-0",children:n.jsx(_2,{icon:m.icon})}),n.jsx("span",{className:"truncate",children:m.title})]})},m.id),e[6]=l,e[7]=f):f=e[7],c=s.map(f),e[3]=l,e[4]=s,e[5]=c}else c=e[5];let d;e[8]!==c?(d=n.jsx(Ps,{align:"end",className:"w-56 p-1",children:n.jsx("ul",{className:"flex flex-col",children:c})}),e[8]=c,e[9]=d):d=e[9];let u;return e[10]!==r||e[11]!==d?(u=n.jsxs(Ts,{open:r,onOpenChange:o,children:[h,d]}),e[10]=r,e[11]=d,e[12]=u):u=e[12],u}function _2(t){const e=K.c(5),{icon:s}=t;if(s.kind==="component"){const{Component:r}=s;let o;return e[0]!==r?(o=n.jsx(r,{className:"size-4"}),e[0]=r,e[1]=o):o=e[1],o}if(s.kind==="url"){let r;return e[2]!==s.src?(r=n.jsx("img",{src:s.src,alt:"",className:"size-4 rounded-sm object-cover"}),e[2]=s.src,e[3]=r):r=e[3],r}let i;return e[4]===Symbol.for("react.memo_cache_sentinel")?(i=n.jsx(Nm,{className:"size-4"}),e[4]=i):i=e[4],i}const g2=6;function yu(t){const e=K.c(20),{virtualMcpId:s,taskId:i}=t,r=ts();let o;e[0]!==i||e[1]!==s?(o={virtualMcpId:s,taskId:i},e[0]=i,e[1]=s,e[2]=o):o=e[2];const{tabs:a,activeTab:l,mainOpen:h,setActiveTab:c}=Wh(o);let d,u,f,m;if(e[3]!==l||e[4]!==h||e[5]!==r||e[6]!==c||e[7]!==a||e[8]!==s){const g=nm({activeTab:l,mainOpen:h}),v=C=>C.id==="automations"?g:h&&C.id===l,x=a.find(C=>v(C))?.id??null,{visible:y,overflow:w}=m2(a,x,g2);u=w,d=C=>{const j=a.find(B=>B.id===C),R=x===C&&h;if(De("main_panel_tab_clicked",{virtual_mcp_id:s,tab_id:C,tab_kind:j?.kind??null,was_active:R}),C==="automations"){const B=om({activeTab:l,mainOpen:h});r({to:".",search:P=>({...P,main:B}),replace:!0});return}c(C)},f="flex items-center min-w-0 gap-0.5",m=y.map(C=>n.jsx(jm,{title:C.title,icon:C.icon,active:v(C),onClick:()=>d(C.id)},C.id)),e[3]=l,e[4]=h,e[5]=r,e[6]=c,e[7]=a,e[8]=s,e[9]=d,e[10]=u,e[11]=f,e[12]=m}else d=e[9],u=e[10],f=e[11],m=e[12];let p;e[13]!==d||e[14]!==u?(p=u.length>0&&n.jsx(p2,{overflow:u,onSelect:d}),e[13]=d,e[14]=u,e[15]=p):p=e[15];let _;return e[16]!==f||e[17]!==m||e[18]!==p?(_=n.jsxs("div",{className:f,children:[m,p]}),e[16]=f,e[17]=m,e[18]=p,e[19]=_):_=e[19],_}function Su(t){return Yi({userName:t?.name,userEmail:t?.email})??void 0}const Ec=3e3,v2=6e4;function x2(t){const e=K.c(12),{orgSlug:s,virtualMcpId:i,branch:r,enabled:o}=t,a=o===void 0?!0:o,l=r??"";let h;e[0]!==s||e[1]!==l||e[2]!==i?(h=jv(s,i,l),e[0]=s,e[1]=l,e[2]=i,e[3]=h):h=e[3];let c;e[4]!==r||e[5]!==s||e[6]!==i?(c=()=>br(s,i,r),e[4]=r,e[5]=s,e[6]=i,e[7]=c):c=e[7];const d=a&&!!r;let u;return e[8]!==h||e[9]!==c||e[10]!==d?(u={queryKey:h,queryFn:c,enabled:d,refetchInterval:y2,retry:b2,staleTime:1e3},e[8]=h,e[9]=c,e[10]=d,e[11]=u):u=e[11],Zs(u)}function b2(t,e){return!ya(e)}function y2(t){if(!ya(t.state.error))return Ec;const e=t.state.fetchFailureCount;return Math.min(Ec*2**e,v2)}const S2=new Set(["main","master"]);function $a(t){return S2.has(t.trim().toLowerCase())?"Publish to production":"Publish"}function w2(t){const e=K.c(24),{baseBranch:s,disabled:i,loading:r,onPublish:o,onReview:a}=t,l=r===void 0?!1:r;let h;e[0]!==s?(h=$a(s),e[0]=s,e[1]=h):h=e[1];const c=h;let d;e[2]!==o?(d=()=>{o()},e[2]=o,e[3]=d):d=e[3];let u;e[4]!==l?(u=l?n.jsx(Xo,{size:"xs",variant:"default"}):null,e[4]=l,e[5]=u):u=e[5];let f;e[6]!==i||e[7]!==c||e[8]!==d||e[9]!==u?(f=n.jsxs(re,{size:"sm",variant:"success",className:"rounded-r-none border-r border-success-foreground/20",disabled:i,onClick:d,children:[u,c]}),e[6]=i,e[7]=c,e[8]=d,e[9]=u,e[10]=f):f=e[10];let m;e[11]===Symbol.for("react.memo_cache_sentinel")?(m=n.jsx(Es,{className:"h-3.5 w-3.5"}),e[11]=m):m=e[11];let p;e[12]!==i?(p=n.jsx(As,{asChild:!0,children:n.jsx(re,{size:"sm",variant:"success",className:"rounded-l-none px-2",disabled:i,"aria-label":"More actions",children:m})}),e[12]=i,e[13]=p):p=e[13];let _;e[14]!==a?(_=a?n.jsx(He,{onClick:a,children:"Review"}):null,e[14]=a,e[15]=_):_=e[15];let g;e[16]!==_?(g=n.jsx(Is,{align:"end",children:_}),e[16]=_,e[17]=g):g=e[17];let v;e[18]!==p||e[19]!==g?(v=n.jsxs(Ds,{children:[p,g]}),e[18]=p,e[19]=g,e[20]=v):v=e[20];let b;return e[21]!==v||e[22]!==f?(b=n.jsxs("div",{className:"inline-flex items-stretch rounded-md",children:[f,v]}),e[21]=v,e[22]=f,e[23]=b):b=e[23],b}class bi extends Error{constructor(e,s,i){super(e),this.step=s,this.pr=i,this.name="PublishFlowError"}step;pr}function C2(t){const e=K.c(10),[s,i]=E.useState(0);let r;e[0]!==t?(r=h=>{h&&i(k2),t.onOpenChange(h)},e[0]=t,e[1]=r):r=e[1];const o=r;let a;e[2]!==o||e[3]!==t||e[4]!==s?(a=t.open?n.jsx(j2,{...t,onOpenChange:o},s):null,e[2]=o,e[3]=t,e[4]=s,e[5]=a):a=e[5];let l;return e[6]!==o||e[7]!==t.open||e[8]!==a?(l=n.jsx(Lt,{open:t.open,onOpenChange:o,children:a}),e[6]=o,e[7]=t.open,e[8]=a,e[9]=l):l=e[9],l}function k2(t){return t+1}function j2({onOpenChange:t,orgSlug:e,orgId:s,virtualMcpId:i,branch:r,baseBranch:o,githubConnectionId:a,owner:l,repo:h,previewUrl:c,dialogIntent:d="publish",headSha:u=null,openPullRequest:f=null,onPullRequestChanged:m,onPublished:p}){const _=ft({connectionId:a,orgId:s,orgSlug:e}),g=ft({connectionId:Ho,orgId:s,orgSlug:e}),{data:v}=Js.useSession(),b=zo(g),x=Su(v?.user),y=f?.state==="open",w=d==="publish",C=d==="open-pr"&&!y,[j,R]=E.useState(null),[B,P]=E.useState(null),[T,S]=E.useState(!0),[k,I]=E.useState(!1),[N,A]=E.useState(""),[M,D]=E.useState(""),[$,z]=E.useState(),[W,F]=E.useState(!1),[V,J]=E.useState(!1),[Y,U]=E.useState(),[H,X]=E.useState(),[oe,L]=E.useState(!1),[se,ee]=E.useState(!1),[Q,O]=E.useState(!1),ce=E.useRef(!1),ue=E.useRef(!1),fe=async()=>{const ge=await br(e,i,r),tt=C||!y&&(ge.aheadOfBase??0)>0?{base:o,...u?{headSha:u}:{}}:void 0,yt=await Yh(e,i,r,tt);R(ge),P(yt),A(`Changes from ${ge.current??r}`),O(!0),vl(e,i,r,{status:ge,diff:yt}).then(st=>{A(st.title),D(st.body)}).catch(()=>{}).finally(()=>O(!1))};ce.current||(ce.current=!0,(async()=>{S(!0),z(void 0),P(null),A(""),D(""),U(void 0),X(void 0);try{await fe()}catch(ge){if(ya(ge)&&!ue.current){ue.current=!0;try{await b.mutateAsync({virtualMcpId:i,branch:r}),await fe();return}catch(je){z(je instanceof Error?je.message:"Failed to load changes after re-provisioning the sandbox.");return}}z(ge instanceof Error?ge.message:"Failed to load changes.")}finally{S(!1)}})());const q=Sa(j)??r,te=$a(o),me=()=>{!j||!B||(O(!0),vl(e,i,r,{status:j,diff:B}).then(ge=>{A(ge.title),D(ge.body)}).catch(()=>{}).finally(()=>O(!1)))},ne=Xh(j),ke=B?Object.keys(B.diffs).length:ne,at=C?Zh(j):Nv(j,B),Be=!T&&(w?at:at||C),mt=Be&&xl(B),as=Be&&!xl(B)?Cv:null,G=C||!y&&(j?.aheadOfBase??0)>0,_e=!T&&(G||at)&&(ke>0||at),xe=()=>[N.trim(),M.trim()].filter(Boolean).join(`
|
|
309
|
+
`,e)}paste(t){this._core.paste(t)}refresh(t,e){this._verifyIntegers(t,e),this._core.refresh(t,e)}reset(){this._core.reset()}clearTextureAtlas(){this._core.clearTextureAtlas()}loadAddon(t){this._addonManager.loadAddon(this,t)}static get strings(){return{get promptLabel(){return to.get()},set promptLabel(t){to.set(t)},get tooMuchOutput(){return so.get()},set tooMuchOutput(t){so.set(t)}}}_verifyIntegers(...t){for(zt of t)if(zt===1/0||isNaN(zt)||zt%1!==0)throw new Error("This API only accepts integers")}_verifyPositiveIntegers(...t){for(zt of t)if(zt&&(zt===1/0||isNaN(zt)||zt%1!==0||zt<0))throw new Error("This API only accepts positive integers")}};var s2=2,i2=1,r2=class{activate(t){this._terminal=t}dispose(){}fit(){let t=this.proposeDimensions();if(!t||!this._terminal||isNaN(t.cols)||isNaN(t.rows))return;let e=this._terminal._core;(this._terminal.rows!==t.rows||this._terminal.cols!==t.cols)&&(e._renderService.clear(),this._terminal.resize(t.cols,t.rows))}proposeDimensions(){if(!this._terminal||!this._terminal.element||!this._terminal.element.parentElement)return;let t=this._terminal._core._renderService.dimensions;if(t.css.cell.width===0||t.css.cell.height===0)return;let e=this._terminal.options.scrollback===0?0:this._terminal.options.overviewRuler?.width||14,s=window.getComputedStyle(this._terminal.element.parentElement),i=parseInt(s.getPropertyValue("height")),r=Math.max(0,parseInt(s.getPropertyValue("width"))),o=window.getComputedStyle(this._terminal.element),a={top:parseInt(o.getPropertyValue("padding-top")),bottom:parseInt(o.getPropertyValue("padding-bottom")),right:parseInt(o.getPropertyValue("padding-right")),left:parseInt(o.getPropertyValue("padding-left"))},l=a.top+a.bottom,h=a.right+a.left,c=i-l,d=r-h-e;return{cols:Math.max(s2,Math.floor(d/t.css.cell.width)),rows:Math.max(i2,Math.floor(c/t.css.cell.height))}}};function n2({source:t,onReady:e,onSelectionChange:s,className:i}){const r=E.useRef(null),o=E.useRef(null),a=E.useRef(s);a.current=s;const l=Yt(),h=E.useRef(t);return h.current=t,H_((c,d)=>{c===h.current&&o.current?.write(d)}),E.useEffect(()=>{const c=r.current;if(!c)return;const d=getComputedStyle(document.documentElement),u=v=>d.getPropertyValue(v).trim()||void 0,f=new t2({allowTransparency:!1,fontFamily:u("--font-mono")||"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",fontSize:12.5,lineHeight:1.5,scrollback:5e3,cursorBlink:!1,disableStdin:!0,theme:{background:u("--sidebar")||u("--card")||u("--background")||"#1e1e1e",cursor:"transparent",foreground:u("--foreground")||"#d4d4d4",selectionBackground:u("--accent"),selectionForeground:u("--accent-foreground"),black:u("--muted"),red:u("--destructive"),green:u("--success"),yellow:u("--warning"),blue:u("--chart-1"),magenta:u("--chart-3"),cyan:u("--chart-5"),white:u("--foreground"),brightBlack:u("--muted-foreground"),brightRed:u("--destructive"),brightGreen:u("--success"),brightYellow:u("--warning"),brightBlue:u("--chart-1"),brightMagenta:u("--chart-3"),brightCyan:u("--chart-5"),brightWhite:u("--foreground")}}),m=new r2;f.loadAddon(m),f.open(c),m.fit();const p=l.getBuffer(t);p&&f.write(p),o.current=f,e?.(f);const _=f.onSelectionChange(()=>{const v=!!f.getSelection();a.current?.(v,()=>f.getSelection())}),g=new ResizeObserver(()=>{m.fit()});return g.observe(c),()=>{_.dispose(),g.disconnect(),o.current=null,f.dispose()}},[]),n.jsx("div",{className:he("h-full bg-sidebar p-3",i),children:n.jsx("div",{ref:r,className:"h-full"})})}function o2(t){const e=Yt(),[s,i]=E.useState(ws),[r,o]=E.useState([]),[a,l]=E.useState(new Set),h=E.useRef(!1);if(!h.current&&e.scripts.length>0){const y=Qp.find(w=>e.scripts.includes(w));y&&(h.current=!0,o(w=>w.includes(y)?w:[...w,y]),i(y))}if(a.size>0){let y=!1;const w=new Set(a);for(const C of a)e.activeProcesses.includes(C)||(w.delete(C),y=!0);y&&l(w)}const c=()=>t.onOpenChange(!t.open),d=y=>{i(y),t.open||t.onOpenChange(!0)},u=y=>!t.virtualMcpId||!t.branch?Promise.resolve(null):fetch(`/api/${encodeURIComponent(t.orgSlug)}/sandbox/${encodeURIComponent(t.virtualMcpId)}/${encodeURIComponent(t.branch)}/exec/${encodeURIComponent(y)}`,{method:"POST"}),f=y=>!t.virtualMcpId||!t.branch?Promise.resolve(null):fetch(`/api/${encodeURIComponent(t.orgSlug)}/sandbox/${encodeURIComponent(t.virtualMcpId)}/${encodeURIComponent(t.branch)}/exec/${encodeURIComponent(y)}/kill`,{method:"POST"}),m=async y=>{o(w=>w.includes(y)?w:[...w,y]),i(y),t.onOpenChange(!0);try{const w=await u(y);if(w===null)return;if(!w.ok)throw new Error(`Exec failed: ${w.statusText}`)}catch{le.error("Failed to run "+y)}},p=async y=>{await f(y),o(w=>w.filter(C=>C!==y)),s===y&&i(ws)},_=async()=>{const y=e.activeProcesses.includes(s);try{const w=await u(s);if(w===null)return;if(!w.ok)throw new Error(`Exec failed: ${w.statusText}`)}catch{le.error((y?"Failed to restart ":"Failed to run ")+s)}},g=async()=>{if(!a.has(s)){l(y=>new Set(y).add(s));try{const y=await f(s);if(y===null){l(w=>{const C=new Set(w);return C.delete(s),C});return}if(!y.ok)throw new Error(`Kill failed: ${y.statusText}`)}catch{l(y=>{const w=new Set(y);return w.delete(s),w}),le.error("Failed to stop "+s)}}},v=s!==ws&&r.includes(s),b=v&&e.activeProcesses.includes(s),x=v&&a.has(s);return n.jsxs("div",{className:"flex shrink-0 flex-col",style:{height:t.open?"50%":"auto"},children:[n.jsx(Fb,{status:t.status,open:t.open,onToggle:c,onStart:t.status==="idle"?t.onStart:void 0,onStop:t.status==="running"||t.status==="starting"?t.onStop:void 0,onRestart:t.status==="running"?t.onRestart:void 0,onResume:t.status==="suspended"?t.onResume:void 0,onRetry:t.status==="errored"?t.onRetry:void 0,scripts:t.scripts,active:s,scriptTabs:r,onSelectTab:d,onAddScript:m,onCloseScript:p,showScriptControls:v,scriptIsRunning:b,scriptIsKilling:x,onRunActiveScript:_,onStopActiveScript:g}),t.open&&n.jsx("div",{className:"flex-1 overflow-hidden",children:n.jsx(a2,{vmId:t.vmId,active:s,hasData:e.hasData(s),onRunActive:_})})]})}function a2(t){const e=K.c(10),{vmId:s,active:i,hasData:r,onRunActive:o}=t;if(!s)return null;if(i===ws||r){let d;return e[0]!==i?(d=n.jsx(n2,{source:i,className:"h-full"},i),e[0]=i,e[1]=d):d=e[1],d}let a;e[2]!==i?(a=n.jsxs("p",{children:['Script "',n.jsx("span",{className:"font-mono text-foreground",children:i}),'" not running']}),e[2]=i,e[3]=a):a=e[3];let l;e[4]===Symbol.for("react.memo_cache_sentinel")?(l=n.jsx(Vs,{className:"size-3.5"}),e[4]=l):l=e[4];let h;e[5]!==o?(h=n.jsxs("button",{type:"button",onClick:o,className:"flex items-center gap-1.5 rounded-md border border-border px-3 py-1.5 text-xs text-foreground hover:bg-accent",children:[l," Run"]}),e[5]=o,e[6]=h):h=e[6];let c;return e[7]!==a||e[8]!==h?(c=n.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 text-sm text-muted-foreground",children:[a,h]}),e[7]=a,e[8]=h,e[9]=c):c=e[9],c}const xu=t=>`preview-drawer:${t}`;function l2(t){try{const e=localStorage.getItem(xu(t));return e?!!JSON.parse(e).open:!1}catch{return!1}}function c2(t,e){try{localStorage.setItem(xu(t),JSON.stringify({open:e}))}catch{}}function h2(){const t=K.c(17),e=sr(),{org:s}=Pe(),i=e?.virtualMcpId??null,r=id(),o=Yt(),a=i??"__no-vmcp__",[l,h]=E.useState(null),c=E.useRef(null);c.current!==a&&(c.current=a,h(l2(a)));const d=l??!1;let u;t[0]!==a?(u=g=>{h(g),c2(a,g)},t[0]=a,t[1]=u):u=t[1];const f=u,m=r.vmEntry?.sandboxHandle??"no-vm",p=r.vmEntry?.sandboxHandle??null;let _;return t[2]!==o.scripts||t[3]!==f||t[4]!==r.branch||t[5]!==r.restart||t[6]!==r.resume||t[7]!==r.retry||t[8]!==r.start||t[9]!==r.status||t[10]!==r.stop||t[11]!==d||t[12]!==s.slug||t[13]!==m||t[14]!==p||t[15]!==i?(_=n.jsx(o2,{vmId:p,orgSlug:s.slug,virtualMcpId:i,branch:r.branch,status:r.status,scripts:o.scripts,open:d,onOpenChange:f,onStart:r.start,onStop:r.stop,onRestart:r.restart,onResume:r.resume,onRetry:r.retry},m),t[2]=o.scripts,t[3]=f,t[4]=r.branch,t[5]=r.restart,t[6]=r.resume,t[7]=r.retry,t[8]=r.start,t[9]=r.status,t[10]=r.stop,t[11]=d,t[12]=s.slug,t[13]=m,t[14]=p,t[15]=i,t[16]=_):_=t[16],_}function bu(t){const e=K.c(10),{virtualMcpId:s,taskId:i}=t,o=sr()?.entity?.metadata;let a;e[0]!==o?(a=ti(o),e[0]=o,e[1]=a):a=e[1];const l=a;let h;e[2]!==i||e[3]!==s?(h=n.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:n.jsx(zb,{taskId:i,virtualMcpId:s})}),e[2]=i,e[3]=s,e[4]=h):h=e[4];let c;e[5]!==l?(c=l&&n.jsx(h2,{}),e[5]=l,e[6]=c):c=e[6];let d;return e[7]!==h||e[8]!==c?(d=n.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[h,c]}),e[7]=h,e[8]=c,e[9]=d):d=e[9],d}function d2(t){const e=K.c(9),{children:s,defaultSize:i,chatOpen:r,chatPanelWidth:o,onChatPanelResize:a}=t,[,l]=E.useTransition(),h=i>0&&i<100?o:i;let c;e[0]!==a?(c=p=>l(()=>{p>0&&p<100&&a(p)}),e[0]=a,e[1]=c):c=e[1];const d=c,u=r?"min-w-[348px]":"min-w-0";let f;e[2]!==u?(f=he("overflow-hidden bg-sidebar",u),e[2]=u,e[3]=f):f=e[3];let m;return e[4]!==s||e[5]!==h||e[6]!==d||e[7]!==f?(m=n.jsx(th,{defaultSize:h,minSize:20,collapsible:!0,collapsedSize:0,className:f,onResize:d,order:1,children:s}),e[4]=s,e[5]=h,e[6]=d,e[7]=f,e[8]=m):m=e[8],m}function u2(t){const e=K.c(32),{virtualMcpId:s,taskId:i,chatOpen:r,mainOpen:o,chatContent:a}=t;let l;e[0]!==r||e[1]!==o?(l=tl(r,o),e[0]=r,e[1]=o,e[2]=l):l=e[2];const h=l,[c,d]=Vp(),u=E.useRef(null);let f,m;e[3]!==r||e[4]!==c||e[5]!==o?(f=()=>{const P=u.current;if(!P)return;const T=tl(r,o),S=T.chat>0&&T.chat<100?c:T.chat,k=T.chat>0&&T.chat<100?100-c:T.main;P.setLayout([S,k])},m=[r,o,c],e[3]=r,e[4]=c,e[5]=o,e[6]=f,e[7]=m):(f=e[6],m=e[7]),E.useEffect(f,m);const p=`${s}-${i}`;let _;e[8]===Symbol.for("react.memo_cache_sentinel")?(_={overflow:"visible"},e[8]=_):_=e[8];let g;e[9]!==a?(g=a??n.jsx(gh,{}),e[9]=a,e[10]=g):g=e[10];let v;e[11]!==g?(v=n.jsx("div",{className:"h-full p-0.5 pt-0.25",children:n.jsx("div",{className:"h-full bg-background rounded-[0.75rem] overflow-hidden card-shadow",children:g})}),e[11]=g,e[12]=v):v=e[12];let b;e[13]!==r||e[14]!==c||e[15]!==d||e[16]!==h.chat||e[17]!==v?(b=n.jsx(d2,{defaultSize:h.chat,chatOpen:r,chatPanelWidth:c,onChatPanelResize:d,children:v}),e[13]=r,e[14]=c,e[15]=d,e[16]=h.chat,e[17]=v,e[18]=b):b=e[18];let x;e[19]===Symbol.for("react.memo_cache_sentinel")?(x=n.jsx(lm,{className:"bg-sidebar"}),e[19]=x):x=e[19];const y=h.main;let w;e[20]===Symbol.for("react.memo_cache_sentinel")?(w={overflow:"visible"},e[20]=w):w=e[20];let C;e[21]===Symbol.for("react.memo_cache_sentinel")?(C=he("flex flex-col h-full min-h-0 bg-background overflow-hidden","card-shadow","transition-[border-radius] duration-200 ease-[var(--ease-out-quart)]","rounded-[0.75rem]"),e[21]=C):C=e[21];let j;e[22]!==i||e[23]!==s?(j=n.jsx("div",{className:"h-full p-0.5 pt-0.25",children:n.jsx("div",{className:C,children:n.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:n.jsx(bu,{taskId:i,virtualMcpId:s})})})}),e[22]=i,e[23]=s,e[24]=j):j=e[24];let R;e[25]!==h.main||e[26]!==j?(R=n.jsx(th,{className:"min-w-0 flex flex-col",order:2,defaultSize:y,style:w,collapsible:!0,collapsedSize:0,minSize:20,children:j}),e[25]=h.main,e[26]=j,e[27]=R):R=e[27];let B;return e[28]!==R||e[29]!==p||e[30]!==b?(B=n.jsxs(cm,{ref:u,direction:"horizontal",className:"flex-1 min-h-0 pb-1 pr-1 pl-0 pt-0",style:_,children:[b,x,R]},p),e[28]=R,e[29]=p,e[30]=b,e[31]=B):B=e[31],B}function f2(t){const e=K.c(15),{chatOpen:s,toggleChat:i,onNewTask:r}=t;let o;e[0]!==s||e[1]!==i?(o=()=>{De("agent_toolbar_toggled",{button:"chat",next_state:s?"closed":"open"}),i()},e[0]=s,e[1]=i,e[2]=o):o=e[2];let a;e[3]===Symbol.for("react.memo_cache_sentinel")?(a=n.jsx(Xc,{size:16}),e[3]=a):a=e[3];let l;e[4]!==s||e[5]!==o?(l=n.jsx(Ee,{asChild:!0,children:n.jsx(Xa,{onClick:o,"aria-pressed":s,"aria-label":"Chat",active:s,children:a})}),e[4]=s,e[5]=o,e[6]=l):l=e[6];let h;e[7]===Symbol.for("react.memo_cache_sentinel")?(h=n.jsx(Te,{side:"bottom",children:"Chat"}),e[7]=h):h=e[7];let c;e[8]!==l?(c=n.jsxs(Re,{delayDuration:300,children:[l,h]}),e[8]=l,e[9]=c):c=e[9];let d;e[10]!==r?(d=r&&n.jsxs(Re,{delayDuration:300,children:[n.jsx(Ee,{asChild:!0,children:n.jsx(Xa,{onClick:r,"aria-label":"New task",children:n.jsx(Zr,{size:16})})}),n.jsx(Te,{side:"bottom",children:"New task"})]}),e[10]=r,e[11]=d):d=e[11];let u;return e[12]!==c||e[13]!==d?(u=n.jsxs(n.Fragment,{children:[c,d]}),e[12]=c,e[13]=d,e[14]=u):u=e[14],u}function m2(t,e,s){if(t.length<=s)return{visible:t,overflow:[]};const i=t.slice(0,s),r=t.slice(s);if(e==null)return{visible:i,overflow:r};if(i.some(u=>u.id===e))return{visible:i,overflow:r};const a=r.findIndex(u=>u.id===e);if(a===-1)return{visible:i,overflow:r};const l=i[i.length-1],h=r[a],c=[...i.slice(0,-1),h],d=[l,...r.slice(0,a),...r.slice(a+1)];return{visible:c,overflow:d}}function p2(t){const e=K.c(13),{overflow:s,onSelect:i}=t,[r,o]=E.useState(!1);let a;e[0]!==i?(a=f=>{o(!1),i(f)},e[0]=i,e[1]=a):a=e[1];const l=a;let h;e[2]===Symbol.for("react.memo_cache_sentinel")?(h=n.jsx(Rs,{asChild:!0,children:n.jsx("button",{type:"button",title:"More tabs","aria-label":"More tabs",className:"shrink-0 flex size-8 items-center justify-center rounded-md text-muted-foreground hover:bg-accent hover:text-foreground transition-colors",children:n.jsx(tn,{className:"size-4"})})}),e[2]=h):h=e[2];let c;if(e[3]!==l||e[4]!==s){let f;e[6]!==l?(f=m=>n.jsx("li",{children:n.jsxs("button",{type:"button",onClick:()=>l(m.id),className:"w-full flex items-center gap-2 px-3 py-2 rounded-md hover:bg-accent text-sm text-foreground",children:[n.jsx("span",{className:"flex size-5 items-center justify-center shrink-0",children:n.jsx(_2,{icon:m.icon})}),n.jsx("span",{className:"truncate",children:m.title})]})},m.id),e[6]=l,e[7]=f):f=e[7],c=s.map(f),e[3]=l,e[4]=s,e[5]=c}else c=e[5];let d;e[8]!==c?(d=n.jsx(Ps,{align:"end",className:"w-56 p-1",children:n.jsx("ul",{className:"flex flex-col",children:c})}),e[8]=c,e[9]=d):d=e[9];let u;return e[10]!==r||e[11]!==d?(u=n.jsxs(Ts,{open:r,onOpenChange:o,children:[h,d]}),e[10]=r,e[11]=d,e[12]=u):u=e[12],u}function _2(t){const e=K.c(5),{icon:s}=t;if(s.kind==="component"){const{Component:r}=s;let o;return e[0]!==r?(o=n.jsx(r,{className:"size-4"}),e[0]=r,e[1]=o):o=e[1],o}if(s.kind==="url"){let r;return e[2]!==s.src?(r=n.jsx("img",{src:s.src,alt:"",className:"size-4 rounded-sm object-cover"}),e[2]=s.src,e[3]=r):r=e[3],r}let i;return e[4]===Symbol.for("react.memo_cache_sentinel")?(i=n.jsx(Nm,{className:"size-4"}),e[4]=i):i=e[4],i}const g2=6;function yu(t){const e=K.c(20),{virtualMcpId:s,taskId:i}=t,r=ts();let o;e[0]!==i||e[1]!==s?(o={virtualMcpId:s,taskId:i},e[0]=i,e[1]=s,e[2]=o):o=e[2];const{tabs:a,activeTab:l,mainOpen:h,setActiveTab:c}=Wh(o);let d,u,f,m;if(e[3]!==l||e[4]!==h||e[5]!==r||e[6]!==c||e[7]!==a||e[8]!==s){const g=om({activeTab:l,mainOpen:h}),v=C=>C.id==="automations"?g:h&&C.id===l,x=a.find(C=>v(C))?.id??null,{visible:y,overflow:w}=m2(a,x,g2);u=w,d=C=>{const j=a.find(B=>B.id===C),R=x===C&&h;if(De("main_panel_tab_clicked",{virtual_mcp_id:s,tab_id:C,tab_kind:j?.kind??null,was_active:R}),C==="automations"){const B=am({activeTab:l,mainOpen:h});r({to:".",search:P=>({...P,main:B}),replace:!0});return}c(C)},f="flex items-center min-w-0 gap-0.5",m=y.map(C=>n.jsx(jm,{title:C.title,icon:C.icon,active:v(C),onClick:()=>d(C.id)},C.id)),e[3]=l,e[4]=h,e[5]=r,e[6]=c,e[7]=a,e[8]=s,e[9]=d,e[10]=u,e[11]=f,e[12]=m}else d=e[9],u=e[10],f=e[11],m=e[12];let p;e[13]!==d||e[14]!==u?(p=u.length>0&&n.jsx(p2,{overflow:u,onSelect:d}),e[13]=d,e[14]=u,e[15]=p):p=e[15];let _;return e[16]!==f||e[17]!==m||e[18]!==p?(_=n.jsxs("div",{className:f,children:[m,p]}),e[16]=f,e[17]=m,e[18]=p,e[19]=_):_=e[19],_}function Su(t){return Yi({userName:t?.name,userEmail:t?.email})??void 0}const Ec=3e3,v2=6e4;function x2(t){const e=K.c(12),{orgSlug:s,virtualMcpId:i,branch:r,enabled:o}=t,a=o===void 0?!0:o,l=r??"";let h;e[0]!==s||e[1]!==l||e[2]!==i?(h=jv(s,i,l),e[0]=s,e[1]=l,e[2]=i,e[3]=h):h=e[3];let c;e[4]!==r||e[5]!==s||e[6]!==i?(c=()=>br(s,i,r),e[4]=r,e[5]=s,e[6]=i,e[7]=c):c=e[7];const d=a&&!!r;let u;return e[8]!==h||e[9]!==c||e[10]!==d?(u={queryKey:h,queryFn:c,enabled:d,refetchInterval:y2,retry:b2,staleTime:1e3},e[8]=h,e[9]=c,e[10]=d,e[11]=u):u=e[11],Zs(u)}function b2(t,e){return!ya(e)}function y2(t){if(!ya(t.state.error))return Ec;const e=t.state.fetchFailureCount;return Math.min(Ec*2**e,v2)}const S2=new Set(["main","master"]);function $a(t){return S2.has(t.trim().toLowerCase())?"Publish to production":"Publish"}function w2(t){const e=K.c(24),{baseBranch:s,disabled:i,loading:r,onPublish:o,onReview:a}=t,l=r===void 0?!1:r;let h;e[0]!==s?(h=$a(s),e[0]=s,e[1]=h):h=e[1];const c=h;let d;e[2]!==o?(d=()=>{o()},e[2]=o,e[3]=d):d=e[3];let u;e[4]!==l?(u=l?n.jsx(Xo,{size:"xs",variant:"default"}):null,e[4]=l,e[5]=u):u=e[5];let f;e[6]!==i||e[7]!==c||e[8]!==d||e[9]!==u?(f=n.jsxs(re,{size:"sm",variant:"success",className:"rounded-r-none border-r border-success-foreground/20",disabled:i,onClick:d,children:[u,c]}),e[6]=i,e[7]=c,e[8]=d,e[9]=u,e[10]=f):f=e[10];let m;e[11]===Symbol.for("react.memo_cache_sentinel")?(m=n.jsx(Es,{className:"h-3.5 w-3.5"}),e[11]=m):m=e[11];let p;e[12]!==i?(p=n.jsx(As,{asChild:!0,children:n.jsx(re,{size:"sm",variant:"success",className:"rounded-l-none px-2",disabled:i,"aria-label":"More actions",children:m})}),e[12]=i,e[13]=p):p=e[13];let _;e[14]!==a?(_=a?n.jsx(He,{onClick:a,children:"Review"}):null,e[14]=a,e[15]=_):_=e[15];let g;e[16]!==_?(g=n.jsx(Is,{align:"end",children:_}),e[16]=_,e[17]=g):g=e[17];let v;e[18]!==p||e[19]!==g?(v=n.jsxs(Ds,{children:[p,g]}),e[18]=p,e[19]=g,e[20]=v):v=e[20];let b;return e[21]!==v||e[22]!==f?(b=n.jsxs("div",{className:"inline-flex items-stretch rounded-md",children:[f,v]}),e[21]=v,e[22]=f,e[23]=b):b=e[23],b}class bi extends Error{constructor(e,s,i){super(e),this.step=s,this.pr=i,this.name="PublishFlowError"}step;pr}function C2(t){const e=K.c(10),[s,i]=E.useState(0);let r;e[0]!==t?(r=h=>{h&&i(k2),t.onOpenChange(h)},e[0]=t,e[1]=r):r=e[1];const o=r;let a;e[2]!==o||e[3]!==t||e[4]!==s?(a=t.open?n.jsx(j2,{...t,onOpenChange:o},s):null,e[2]=o,e[3]=t,e[4]=s,e[5]=a):a=e[5];let l;return e[6]!==o||e[7]!==t.open||e[8]!==a?(l=n.jsx(Lt,{open:t.open,onOpenChange:o,children:a}),e[6]=o,e[7]=t.open,e[8]=a,e[9]=l):l=e[9],l}function k2(t){return t+1}function j2({onOpenChange:t,orgSlug:e,orgId:s,virtualMcpId:i,branch:r,baseBranch:o,githubConnectionId:a,owner:l,repo:h,previewUrl:c,dialogIntent:d="publish",headSha:u=null,openPullRequest:f=null,onPullRequestChanged:m,onPublished:p}){const _=ft({connectionId:a,orgId:s,orgSlug:e}),g=ft({connectionId:Ho,orgId:s,orgSlug:e}),{data:v}=Js.useSession(),b=zo(g),x=Su(v?.user),y=f?.state==="open",w=d==="publish",C=d==="open-pr"&&!y,[j,R]=E.useState(null),[B,P]=E.useState(null),[T,S]=E.useState(!0),[k,I]=E.useState(!1),[N,A]=E.useState(""),[M,D]=E.useState(""),[$,z]=E.useState(),[W,F]=E.useState(!1),[V,J]=E.useState(!1),[Y,U]=E.useState(),[H,X]=E.useState(),[oe,L]=E.useState(!1),[se,ee]=E.useState(!1),[Q,O]=E.useState(!1),ce=E.useRef(!1),ue=E.useRef(!1),fe=async()=>{const ge=await br(e,i,r),tt=C||!y&&(ge.aheadOfBase??0)>0?{base:o,...u?{headSha:u}:{}}:void 0,yt=await Yh(e,i,r,tt);R(ge),P(yt),A(`Changes from ${ge.current??r}`),O(!0),vl(e,i,r,{status:ge,diff:yt}).then(st=>{A(st.title),D(st.body)}).catch(()=>{}).finally(()=>O(!1))};ce.current||(ce.current=!0,(async()=>{S(!0),z(void 0),P(null),A(""),D(""),U(void 0),X(void 0);try{await fe()}catch(ge){if(ya(ge)&&!ue.current){ue.current=!0;try{await b.mutateAsync({virtualMcpId:i,branch:r}),await fe();return}catch(je){z(je instanceof Error?je.message:"Failed to load changes after re-provisioning the sandbox.");return}}z(ge instanceof Error?ge.message:"Failed to load changes.")}finally{S(!1)}})());const q=Sa(j)??r,te=$a(o),me=()=>{!j||!B||(O(!0),vl(e,i,r,{status:j,diff:B}).then(ge=>{A(ge.title),D(ge.body)}).catch(()=>{}).finally(()=>O(!1)))},ne=Xh(j),ke=B?Object.keys(B.diffs).length:ne,at=C?Zh(j):Nv(j,B),Be=!T&&(w?at:at||C),mt=Be&&xl(B),as=Be&&!xl(B)?Cv:null,G=C||!y&&(j?.aheadOfBase??0)>0,_e=!T&&(G||at)&&(ke>0||at),xe=()=>[N.trim(),M.trim()].filter(Boolean).join(`
|
|
310
310
|
|
|
311
|
-
`),Se=ge=>{k||W||V||t(ge)},we=async()=>{J(!0),X(void 0);try{const ge=xe()||N.trim()||`Changes from ${q}`;await bn(e,i,r,ge),le.success(f?`Saved changes to PR #${f.number}`:"Changes saved"),Se(!1),await m?.()}catch(ge){X(ge instanceof Error?ge.message:"Failed to save changes")}finally{J(!1)}},et=async()=>{I(!0),z(void 0);let ge;try{const je=N.trim()||`Changes from ${q}`,tt=M.trim()||void 0,yt=xe()||je;try{await bn(e,i,r,yt)}catch(st){throw new bi(st instanceof Error?st.message:"Failed to push changes","push")}try{await Sv(e,i,r,o)}catch(st){throw new bi(st instanceof Error?st.message:"Failed to rebase onto base","rebase")}try{ge=await rl(_,{owner:l,repo:h,branch:q,title:je,body:tt,base:o,coAuthor:x})}catch(st){throw new bi(st instanceof Error?st.message:"Failed to open pull request","open-pr")}try{await Ch(_,{owner:l,repo:h,pullNumber:ge.number,commitTitle:je,commitMessage:tt,coAuthor:x})}catch(st){throw new bi(st instanceof Error?st.message:"Failed to merge pull request","merge",ge)}le.success(`Published to ${o}`),Se(!1),P(null),A(""),D(""),await m?.(),await p?.()}catch(je){if(je instanceof bi&&je.step==="merge"&&je.pr){const tt=`Changes were pushed and PR #${je.pr.number} is open, but merge failed: ${je.message}`;z(tt),le.error(tt,{action:{label:"View PR",onClick:()=>window.open(je.pr.htmlUrl,"_blank","noopener,noreferrer")}}),await m?.();return}z(je instanceof Error?je.message:"Failed to publish")}finally{I(!1)}},bt=async ge=>{try{await bl(e,i,r,[ge]),le.success(`Discarded changes to ${ge}`),P(tt=>{if(!tt)return tt;const yt={...tt,diffs:{...tt.diffs}};return delete yt.diffs[ge],yt});const je=await br(e,i,r);R(je)}catch(je){le.error(je instanceof Error?je.message:"Failed to discard changes")}},ir=async()=>{if(B){L(!1),ee(!0);try{const ge=Object.keys(B.diffs);if(ge.length===0)return;await bl(e,i,r,ge),le.success("All changes discarded"),P(null);const je=await br(e,i,r);R(je),Se(!1)}catch(ge){le.error(ge instanceof Error?ge.message:"Failed to discard changes")}finally{ee(!1)}}},rr=async()=>{F(!0),U(void 0);try{const ge=N.trim()||`Changes from ${q}`,je=M.trim()||void 0,tt=xe()||ge;await bn(e,i,r,tt);const yt=await rl(_,{owner:l,repo:h,branch:q,title:ge,body:je,base:o,coAuthor:x});le.success(`Submitted pull request #${yt.number} for review`,{action:{label:"View on GitHub",onClick:()=>window.open(yt.htmlUrl,"_blank","noopener,noreferrer")}}),Se(!1),await m?.()}catch(ge){U(ge instanceof Error?ge.message:"Failed to submit for review")}finally{F(!1)}};return n.jsx(Ot,{className:"top-14 left-auto right-4 flex h-[90%] max-h-[85vh] w-[90vw] max-w-[600px] translate-x-0 translate-y-0 flex-col gap-0 overflow-hidden p-0",children:n.jsxs(Qo,{defaultValue:"description",className:"flex h-full flex-col gap-0",children:[n.jsxs("div",{className:"shrink-0 space-y-3 px-6 pt-5 pb-4",children:[n.jsxs("div",{className:"space-y-1",children:[n.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:w?"Save changes":C?"Submit for review":te}),n.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[n.jsx("span",{className:"inline-block h-2.5 w-2.5 shrink-0 rounded-full bg-green-500"}),ke," ",ke===1?"change":"changes"," ",w?"to save":C?"in this PR":"to publish"]})]}),oe?n.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md bg-destructive/5 px-3 py-2",children:[n.jsx("span",{className:"text-xs text-destructive",children:"Discard all changes? This cannot be undone."}),n.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[n.jsx(re,{type:"button",variant:"ghost",size:"sm",className:"h-7 px-2 text-xs",onClick:()=>L(!1),children:"Cancel"}),n.jsxs(re,{type:"button",size:"sm",className:"h-7 bg-destructive px-2 text-xs text-destructive-foreground hover:bg-destructive/90",onClick:ir,disabled:se,children:[se?n.jsx(Ce,{className:"h-3 w-3 animate-spin"}):null,"Discard all"]})]})]}):n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs(Zo,{className:"h-8 w-auto",variant:"pill",children:[n.jsx(ys,{value:"description",className:"px-3 text-xs",children:"Description"}),n.jsx(ys,{value:"changes",className:"px-3 text-xs",children:"Changes"})]}),ke>0&&!C&&n.jsx("button",{type:"button",className:"text-xs text-muted-foreground transition-colors hover:text-destructive disabled:opacity-50",onClick:()=>L(!0),disabled:k||se||V,children:"Discard all"})]})]}),n.jsx("div",{className:"border-t"}),n.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:T?n.jsxs("div",{className:"flex items-center justify-center gap-2 py-16 text-muted-foreground",children:[n.jsx(Ce,{className:"h-4 w-4 animate-spin"}),n.jsx("span",{className:"text-sm",children:"Loading changes…"})]}):n.jsxs(n.Fragment,{children:[n.jsx(Ti,{value:"description",className:"mt-0 px-6 py-5",children:n.jsxs("div",{className:"space-y-4",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("p",{className:"text-sm font-medium",children:C?"Pull request":"Commit message"}),n.jsxs("button",{type:"button",className:"flex items-center gap-1.5 text-xs text-muted-foreground transition-colors hover:text-foreground disabled:opacity-50",disabled:Q||k||W||V,onClick:me,children:[Q?n.jsx(Ce,{className:"h-3 w-3 animate-spin"}):n.jsx(Ss,{className:"h-3 w-3"}),Q?"Generating…":"Regenerate"]})]}),n.jsxs("div",{className:"space-y-1.5",children:[n.jsx("label",{htmlFor:"publish-title",className:"text-xs font-medium text-muted-foreground",children:"Title"}),n.jsx(qe,{id:"publish-title",value:N,onChange:ge=>A(ge.target.value),placeholder:Q?"Generating…":"Commit title…",disabled:k||W||V||Q,className:"text-sm"})]}),n.jsxs("div",{className:"space-y-1.5",children:[n.jsx("label",{htmlFor:"publish-body",className:"text-xs font-medium text-muted-foreground",children:"Description"}),n.jsx(Tr,{id:"publish-body",value:M,onChange:ge=>D(ge.target.value),placeholder:Q?"Generating…":"Description (optional)…",disabled:k||W||V||Q,rows:5,className:"resize-none text-sm"})]}),n.jsxs("p",{className:"text-xs text-muted-foreground",children:["Branch: ",n.jsx("span",{className:"font-mono",children:r}),w?n.jsxs(n.Fragment,{children:[" · ",n.jsx("span",{className:"text-foreground/80",children:y?`Commits and pushes to update open PR #${f.number}.`:"Commits and pushes to the branch without opening a pull request."})]}):n.jsxs(n.Fragment,{children:[" → ",n.jsx("span",{className:"font-mono",children:o})," · ",n.jsxs("span",{className:"text-foreground/80",children:["Submit for review keeps changes on the branch;"," ",te," squash-merges into ",o,"."]})]})]})]})}),n.jsx(Ti,{value:"changes",className:"mt-0",children:n.jsx(Qh,{diff:B,onDiscardFile:bt})})]})}),n.jsx("div",{className:"shrink-0 border-t",children:n.jsxs("button",{type:"button",className:"flex w-full items-center justify-between px-6 py-3.5 text-sm transition-colors hover:bg-muted/50 disabled:opacity-50",onClick:()=>{c&&window.open(c,"_blank","noopener,noreferrer")},disabled:!c,children:[n.jsxs("span",{className:"flex items-center gap-3",children:[n.jsx(Em,{className:"h-4 w-4 text-muted-foreground"}),"Visit preview"]}),n.jsx(lf,{className:"h-4 w-4 text-muted-foreground"})]})}),n.jsx("div",{className:"shrink-0 border-t px-6 py-3",children:w&&!G?n.jsxs(n.Fragment,{children:[n.jsxs(re,{type:"button",className:"w-full",onClick:we,disabled:!Be||V,children:[V?n.jsx(Ce,{className:"h-4 w-4 animate-spin"}):null,"Save changes"]}),H&&n.jsx("p",{className:"mt-2 text-xs text-destructive",children:H})]}):w?n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsxs(re,{type:"button",variant:"outline",className:"flex-1",onClick:we,disabled:!Be||V||W,children:[V?n.jsx(Ce,{className:"h-4 w-4 animate-spin"}):null,"Save changes"]}),n.jsxs(re,{type:"button",className:"flex-1",onClick:rr,disabled:!_e||W||V,children:[W?n.jsx(Ce,{className:"h-4 w-4 animate-spin"}):n.jsx(Mi,{className:"h-4 w-4"}),"Submit for review"]})]}),H&&n.jsx("p",{className:"mt-2 text-xs text-destructive",children:H}),Y&&n.jsx("p",{className:"mt-2 text-xs text-destructive",children:Y})]}):n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsxs(re,{type:"button",variant:"outline",className:"flex-1",onClick:rr,disabled:!_e||W||k,children:[W?n.jsx(Ce,{className:"h-4 w-4 animate-spin"}):n.jsx(Mi,{className:"h-4 w-4"}),"Submit for review"]}),n.jsx(N2,{label:te,canPublish:mt,disabledReason:as,isPublishing:k,isSubmittingForReview:W,onPublish:et})]}),Y&&n.jsx("p",{className:"mt-2 text-xs text-destructive",children:Y}),$&&n.jsx("p",{className:"mt-2 text-xs text-destructive",children:$})]})})]})})}function N2(t){const e=K.c(14),{label:s,canPublish:i,disabledReason:r,isPublishing:o,isSubmittingForReview:a,onPublish:l}=t,h=!i||o||a;let c;e[0]!==o?(c=o?n.jsx(Ce,{className:"h-4 w-4 animate-spin"}):null,e[0]=o,e[1]=c):c=e[1];let d;e[2]!==s||e[3]!==l||e[4]!==h||e[5]!==c?(d=n.jsxs(re,{type:"button",variant:"success",className:"flex-1",onClick:l,disabled:h,children:[c,s]}),e[2]=s,e[3]=l,e[4]=h,e[5]=c,e[6]=d):d=e[6];const u=d;if(!r)return u;let f;e[7]!==u?(f=n.jsx(Ee,{asChild:!0,children:n.jsx("span",{className:"flex flex-1",children:u})}),e[7]=u,e[8]=f):f=e[8];let m;e[9]!==r?(m=n.jsx(Te,{children:r}),e[9]=r,e[10]=m):m=e[10];let p;return e[11]!==f||e[12]!==m?(p=n.jsx(Uc,{children:n.jsxs(Re,{children:[f,m]})}),e[11]=f,e[12]=m,e[13]=p):p=e[13],p}function E2(){return!1}function wu(t,e){E2()&&console.log(`[github-header] ${t}`,e??"")}function T2(t){if(!(t==="claiming"||t==="ready"||t==="failed"))return od[t].short}const R2=new Set(["failure","timed_out","cancelled","action_required"]);function P2(t){return t.status==="completed"&&R2.has(t.conclusion)}function D2(t){return t.status==="queued"||t.status==="in_progress"}function A2(t){const{lifecycle:e,branch:s,pr:i,checks:r,reviews:o,loading:a}=t;if(a)return{label:"Loading…",disabled:!0,loading:!0,variant:"outline",tooltip:"Loading branch and pull request status"};switch(e.phase){case"idle":return{label:t.claimPhase&&T2(t.claimPhase.kind)||"Starting sandbox…",disabled:!0,loading:!0,variant:"outline",tooltip:"Waiting for the sandbox daemon to come online"};case"cloning":return{label:"Cloning repo…",disabled:!0,loading:!0,variant:"outline",tooltip:"Cloning the project repository"};case"clone-failed":return{label:"Clone failed",disabled:!0,variant:"outline",tooltip:e.error||"git clone failed — see setup logs"};case"checking-out":return{label:`Switching to ${e.to}…`,disabled:!0,loading:!0,variant:"outline",tooltip:`Checking out ${e.to}`}}if(s.kind!=="ready")return{label:"Loading branch…",disabled:!0,loading:!0,variant:"outline",tooltip:"Waiting for branch metadata from the sandbox daemon"};const l=s;if(l.workingTreeDirty)return{label:"Save changes",action:"commit-and-push",variant:"default",tooltip:"Commit and push local changes"};if(l.unpushed>0)return i?{label:"Save changes",action:"commit-and-push",variant:"default",tooltip:"Push local commits"}:{label:"Submit for review",action:"create-pr",variant:"default",tooltip:`Push and open a PR for ${l.branch} → ${l.base}`};if(wu("no local work — checking PR/sync state",{workingTreeDirty:l.workingTreeDirty,unpushed:l.unpushed,aheadOfBase:l.aheadOfBase,behindBase:l.behindBase,branch:l.branch,base:l.base,prMerged:i?.merged??null,prState:i?.state??null}),i?.merged)return!!l.headSha&&!!i.headSha&&l.headSha!==i.headSha?{label:"Continue",action:"create-pr",variant:"special",tooltip:"Open a new PR with the latest commits"}:{label:"Published",disabled:!0,variant:"outline",tooltip:`PR #${i.number} merged into ${i.base}`};if(l.aheadOfBase>0){if(i&&i.state==="closed"&&!i.merged)return{label:"Reopen",action:"reopen",variant:"default",tooltip:`Reopen PR #${i.number}`};if(!i)return{label:"Submit for review",action:"create-pr",variant:"default",tooltip:`Open a PR for ${l.branch} → ${l.base}`};if((o?.mergeableState??"unknown")==="dirty")return{label:`Sync with ${i.base}`,action:"rebase",variant:"default",tooltip:`Resolve conflicts with ${i.base} before merging`};const c=r.filter(P2).map(f=>f.name);if(c.length>0)return{label:"Fix tests",action:"fix-checks",variant:"default",tooltip:`Failing: ${c.join(", ")}`,meta:{failingChecks:c}};const d=r.filter(D2);if(d.length>0)return{label:"Running tests…",disabled:!0,loading:!0,variant:"outline",tooltip:`Waiting on ${d.length} check${d.length===1?"":"s"} to finish`};if(o?.draft)return{label:"Mark ready",action:"mark-ready",variant:"default",tooltip:"Mark draft PR ready for review"};const u=o?.unresolvedConversations??0;return u>0?{label:"Address feedback",action:"resolve-comments",variant:"default",tooltip:`${u} unresolved conversation${u===1?"":"s"}`}:o?.missingRequiredApprovals?{label:"Awaiting review",disabled:!0,variant:"outline",tooltip:"Waiting for required approvals"}:{label:$a(i.base),action:"merge-split",variant:"success",tooltip:`Squash-merge PR #${i.number} into ${i.base}`}}return{label:"Up to date",disabled:!0,variant:"outline",tooltip:`Branch is in sync with ${l.base}`}}function I2(t,e,s){if(!e)return s??null;const i=t?.[e];if(!i)return s??null;if(s&&i[s])return s;for(const[r,o]of Object.entries(i))if(o&&Object.keys(o).length>0)return r;return s??null}const B2=6e4,M2=3e4;function L2(t){const e=K.c(12);let s;e[0]!==t.connectionId||e[1]!==t.orgId||e[2]!==t.orgSlug?(s={connectionId:t.connectionId,orgId:t.orgId,orgSlug:t.orgSlug},e[0]=t.connectionId,e[1]=t.orgId,e[2]=t.orgSlug,e[3]=s):s=e[3];const i=ft(s),r=t.prNumber??0;let o;e[4]!==t.owner||e[5]!==t.repo||e[6]!==r?(o={method:"get",owner:t.owner,repo:t.repo,pullNumber:r},e[4]=t.owner,e[5]=t.repo,e[6]=r,e[7]=o):o=e[7];const a=!!t.prNumber;let l;return e[8]!==i||e[9]!==o||e[10]!==a?(l={client:i,toolName:"pull_request_read",toolArguments:o,enabled:a,refetchInterval:B2,refetchIntervalInBackground:!1,staleTime:M2,select:O2},e[8]=i,e[9]=o,e[10]=a,e[11]=l):l=e[11],sn(l)}function O2(t){const e=Bs(t);if(!e)return null;const s=e.mergeable_state??"unknown",i=!!(e.draft??!1),r=Number(e.review_comments??0),o=s==="blocked"&&r>0?r:0;return{draft:i,mergeableState:s,unresolvedConversations:o,missingRequiredApprovals:s==="blocked"&&o===0}}const $2={label:"Loading branch…",disabled:!0,loading:!0,variant:"outline",tooltip:"Waiting for sandbox branch"};function z2({virtualMcpId:t}){const{org:e}=Pe(),{data:s}=Js.useSession(),i=Mt(t),{currentBranch:r,setCurrentTaskBranch:o}=ss(),a=Ns(),[l,h]=E.useState(!1),[c,d]=E.useState("publish"),[u,f]=E.useState(!1),m=E.useRef(""),p=si(i),_=s?.user?.id,g=ft({connectionId:p?.connectionId??"",orgId:e.id,orgSlug:e.slug}),{lifecycle:v,branch:b,phase:x,notFound:y}=Yt(),w=b.kind==="ready"?b.branch:null,C=I2(i?.metadata?.sandboxMap,_,r??w),j=r??w??C??void 0,R=v.phase==="cloning"||v.phase==="checking-out"||v.phase==="clone-failed",B=x2({orgSlug:e.slug,virtualMcpId:t,branch:j??null,enabled:!!p&&!!j&&!y&&!R}),P=Sa(B.data)??j??null,T=ca({orgId:e.id,orgSlug:e.slug,connectionId:p?.connectionId??"",owner:p?.owner??"",repo:p?.name??"",branch:P}),S=T.data??null,k=kh({orgId:e.id,orgSlug:e.slug,connectionId:p?.connectionId??"",owner:p?.owner??"",repo:p?.name??"",prNumber:S&&S.state==="open"?S.number:null}),I=L2({orgId:e.id,orgSlug:e.slug,connectionId:p?.connectionId??"",owner:p?.owner??"",repo:p?.name??"",prNumber:S&&S.state==="open"?S.number:null}),N=Pv(b,B.data);if(!p)return null;const A=_&&P?Jr(i?.metadata?.sandboxMap?.[_]?.[P]):{},M=Object.values(A),$=(M.find(L=>L.sandboxProviderKind!=="user-desktop")??M[0])?.previewUrl??null,z=P?A2({lifecycle:v,branch:N,claimPhase:x,pr:S,checks:k.data??[],reviews:I.data??null,loading:T.isPending}):$2,W=JSON.stringify({label:z.label,branchKind:N.kind,workingTreeDirty:N.kind==="ready"?N.workingTreeDirty:null,gitModifiedCount:B.data?.modified.length??null,unpushed:N.kind==="ready"?N.unpushed:null,aheadOfBase:N.kind==="ready"?N.aheadOfBase:null,lifecycle:v.phase,githubHeadBranch:P});m.current!==W&&(m.current=W,wu("header button",{label:z.label,tooltip:z.tooltip,action:z.action,chatBranch:r,sandboxBranch:w,sandboxMapBranch:C,sandboxRouteBranch:j,githubHeadBranch:P,branchMeta:b,effectiveBranchMeta:N,gitStatus:B.data??null,lifecyclePhase:v.phase,prNumber:S?.number??null,prState:S?.state??null}));const F=L=>a.sendMessage({parts:[{type:"text",text:L}]}),V=a.isStreaming,J=N.kind==="ready"?N.base:"main",Y=async()=>{await Promise.all([T.refetch(),B.refetch(),k.refetch(),I.refetch()])},U=async()=>{const L=Zu();await o(L)},H=async L=>{if(!(!p?.connectionId||u)){f(!0);try{const se=Su(s?.user);await Ch(g,{owner:p.owner,repo:p.name,pullNumber:L,coAuthor:se}),le.success(`Published PR #${L}`),await Y(),await U()}catch(se){le.error(se instanceof Error?se.message:"Failed to merge pull request")}finally{f(!1)}}},X=L=>{if(!(!L||!P))switch(L){case"commit-and-push":d("publish"),h(!0);return;case"create-pr":d("open-pr"),h(!0);return;case"reopen":if(V)return;S&&F(Mv({prNumber:S.number}));return;case"rebase":if(V)return;F(Lv({branch:P}));return;case"fix-checks":if(V)return;S&&F($v({prNumber:S.number,failingChecks:z.meta?.failingChecks??[]}));return;case"mark-ready":if(V)return;S&&F(zv({prNumber:S.number}));return;case"resolve-comments":if(V)return;S&&F(Fv({prNumber:S.number}));return;case"merge-split":return}},oe=u||V;return n.jsxs(n.Fragment,{children:[n.jsx(F2,{button:z,actionBusy:oe,githubActionPending:u,onActivate:X,prNumber:S?.number,prBase:S?.base,onSquashMerge:H,onReview:S?()=>{V||F(Hv({prNumber:S.number}))}:void 0}),j&&n.jsx(C2,{open:l,onOpenChange:h,orgSlug:e.slug,orgId:e.id,virtualMcpId:t,branch:j,baseBranch:J,githubConnectionId:p.connectionId??"",owner:p.owner,repo:p.name,previewUrl:$,dialogIntent:c,headSha:N.kind==="ready"?N.headSha:null,openPullRequest:S?.state==="open"?S:null,onPullRequestChanged:Y,onPublished:U})]})}function F2(t){const e=K.c(25),{button:s,actionBusy:i,githubActionPending:r}=t,o=i&&s.action!=="create-pr"&&s.action!=="commit-and-push"&&s.action!=="merge-split",a=!!s.disabled||o||r&&s.action==="merge-split",l=!!s.loading||r&&s.action==="merge-split",h=o?"Chat is running":s.tooltip??null;if(s.action==="merge-split"&&t.prNumber!=null&&t.prBase!=null){let m;e[0]!==t?(m=()=>t.onSquashMerge(t.prNumber),e[0]=t,e[1]=m):m=e[1];let p;e[2]!==a||e[3]!==l||e[4]!==t.onReview||e[5]!==t.prBase||e[6]!==m?(p=n.jsx(w2,{baseBranch:t.prBase,disabled:a,loading:l,onPublish:m,onReview:t.onReview}),e[2]=a,e[3]=l,e[4]=t.onReview,e[5]=t.prBase,e[6]=m,e[7]=p):p=e[7];let _;return e[8]!==p||e[9]!==h?(_=n.jsx(Tc,{label:h,children:p}),e[8]=p,e[9]=h,e[10]=_):_=e[10],_}let c;e[11]!==s.action||e[12]!==t?(c=()=>{s.action&&t.onActivate(s.action)},e[11]=s.action,e[12]=t,e[13]=c):c=e[13];let d;e[14]!==l?(d=l?n.jsx(Xo,{size:"xs",variant:"default"}):null,e[14]=l,e[15]=d):d=e[15];let u;e[16]!==s.label||e[17]!==s.variant||e[18]!==a||e[19]!==c||e[20]!==d?(u=n.jsxs(re,{size:"sm",variant:s.variant,disabled:a,onClick:c,children:[d,s.label]}),e[16]=s.label,e[17]=s.variant,e[18]=a,e[19]=c,e[20]=d,e[21]=u):u=e[21];let f;return e[22]!==u||e[23]!==h?(f=n.jsx(Tc,{label:h,children:u}),e[22]=u,e[23]=h,e[24]=f):f=e[24],f}function Tc(t){const e=K.c(9),{label:s,children:i}=t;if(!s){let l;return e[0]!==i?(l=n.jsx(n.Fragment,{children:i}),e[0]=i,e[1]=l):l=e[1],l}let r;e[2]!==i?(r=n.jsx(Ee,{asChild:!0,children:n.jsx("span",{children:i})}),e[2]=i,e[3]=r):r=e[3];let o;e[4]!==s?(o=n.jsx(Te,{children:s}),e[4]=s,e[5]=o):o=e[5];let a;return e[6]!==r||e[7]!==o?(a=n.jsx(Uc,{children:n.jsxs(Re,{children:[r,o]})}),e[6]=r,e[7]=o,e[8]=a):a=e[8],a}function Cu(t){const e=K.c(4),{virtualMcp:s,inline:i}=t,r=i===void 0?!1:i;if(!si(s))return null;let a;e[0]!==s.id?(a=n.jsx(z2,{virtualMcpId:s.id}),e[0]=s.id,e[1]=a):a=e[1];const l=a;if(r)return l;let h;return e[2]!==l?(h=n.jsx(Hn.Right,{children:l}),e[2]=l,e[3]=h):h=e[3],h}function H2(t,e){const s=K.c(34),i=eh(),r=E.useSyncExternalStore(i.threads.subscribe,i.threads.get),o=E.useSyncExternalStore(i.threadsStatus.subscribe,i.threadsStatus.get);let a;s[0]!==t||s[1]!==r?(a=t?r.find(x=>x.id===t)??null:null,s[0]=t,s[1]=r,s[2]=a):a=s[2];const l=a,[h,c]=E.useState(void 0);let d;s[3]===Symbol.for("react.memo_cache_sentinel")?(d=()=>{c(void 0)},s[3]=d):d=s[3];let u;s[4]!==t?(u=[t],s[4]=t,s[5]=u):u=s[5],E.useEffect(d,u);let f,m;s[6]!==h||s[7]!==t||s[8]!==l||s[9]!==i||s[10]!==o.kind?(f=()=>{t&&(l||o.kind!=="loading"&&h===void 0&&(c("pending"),i.fetchThread(t).then(x=>{c(x)})))},m=[t,l,o.kind,h,i],s[6]=h,s[7]=t,s[8]=l,s[9]=i,s[10]=o.kind,s[11]=f,s[12]=m):(f=s[11],m=s[12]),E.useEffect(f,m);let p;s[13]!==i||s[14]!==e?(p={mutationFn:async x=>i.create({id:x,virtual_mcp_id:e})},s[13]=i,s[14]=e,s[15]=p):p=s[15];const _=ei(p);let g,v;if(s[16]!==_||s[17]!==h||s[18]!==t||s[19]!==l||s[20]!==o.kind?(g=()=>{t&&(l||h===null&&o.kind!=="loading"&&(_.isPending||_.variables!==t&&_.mutate(t)))},v=[t,l,h,o.kind,_],s[16]=_,s[17]=h,s[18]=t,s[19]=l,s[20]=o.kind,s[21]=g,s[22]=v):(g=s[21],v=s[22]),E.useEffect(g,v),!t){let x;return s[23]===Symbol.for("react.memo_cache_sentinel")?(x={status:"ready",task:null},s[23]=x):x=s[23],x}if(l){let x;return s[24]!==l?(x={status:"ready",task:l},s[24]=l,s[25]=x):x=s[25],x}if(h&&typeof h=="object"){let x;return s[26]!==h?(x={status:"ready",task:h},s[26]=h,s[27]=x):x=s[27],x}if(_.data){let x;return s[28]!==_.data?(x={status:"ready",task:_.data},s[28]=_.data,s[29]=x):x=s[29],x}if(_.isError){let x;return s[30]!==_.error?(x={status:"error",error:_.error},s[30]=_.error,s[31]=x):x=s[31],x}if(_.isPending||o.kind!=="loading"){let x;return s[32]===Symbol.for("react.memo_cache_sentinel")?(x={status:"creating"},s[32]=x):x=s[32],x}let b;return s[33]===Symbol.for("react.memo_cache_sentinel")?(b={status:"loading"},s[33]=b):b=s[33],b}const Hs=E.createContext(null);function sr(){return E.use(Hs)}function Rc(t){const e=K.c(6),{children:s}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=n.jsx("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:"Something went wrong loading the chat. Try refreshing."}),e[0]=i):i=e[0];let r;e[1]===Symbol.for("react.memo_cache_sentinel")?(r=n.jsx(Oe.Skeleton,{}),e[1]=r):r=e[1];let o;e[2]!==s?(o=s??n.jsx(gh,{}),e[2]=s,e[3]=o):o=e[3];let a;return e[4]!==o?(a=n.jsx(Ut,{fallback:i,children:n.jsx(E.Suspense,{fallback:r,children:o})}),e[4]=o,e[5]=a):a=e[5],a}function Pc(t){const e=K.c(3),{onNewTaskRef:s,createNewTask:i}=t;let r;return e[0]!==i||e[1]!==s?(r=()=>(s.current=i,()=>{s.current=null}),e[0]=i,e[1]=s,e[2]=r):r=e[2],E.useLayoutEffect(r),null}function W2(t){const e=K.c(27),{onOpenSidebar:s,virtualMcpId:i,taskId:r,mainOpen:o,onToggleMain:a,onNewTask:l,entity:h,hasActiveGithubRepo:c}=t;let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d=n.jsx(Jf,{size:20}),e[0]=d):d=e[0];let u;e[1]!==s?(u=n.jsx("button",{type:"button",onClick:s,className:"flex size-8 shrink-0 items-center justify-center rounded-md text-foreground/60 hover:bg-accent hover:text-foreground transition-colors","aria-label":"Open menu",children:d}),e[1]=s,e[2]=u):u=e[2];let f;e[3]!==r||e[4]!==i?(f=n.jsx("div",{className:"flex-1 min-w-0 overflow-x-auto [scrollbar-width:none]",children:n.jsx(yu,{virtualMcpId:i,taskId:r})}),e[3]=r,e[4]=i,e[5]=f):f=e[5];let m;e[6]!==h||e[7]!==c?(m=h&&c?n.jsx(Cu,{virtualMcp:h,inline:!0}):null,e[6]=h,e[7]=c,e[8]=m):m=e[8];const p=!o,_=o?"text-foreground/60 hover:bg-accent hover:text-foreground":"bg-accent text-foreground";let g;e[9]!==_?(g=he("flex size-7 shrink-0 items-center justify-center rounded-md transition-colors",_),e[9]=_,e[10]=g):g=e[10];let v;e[11]===Symbol.for("react.memo_cache_sentinel")?(v=n.jsx(Xc,{size:16}),e[11]=v):v=e[11];let b;e[12]!==a||e[13]!==p||e[14]!==g?(b=n.jsx("button",{type:"button",onClick:a,"aria-pressed":p,className:g,title:"Chat",children:v}),e[12]=a,e[13]=p,e[14]=g,e[15]=b):b=e[15];let x;e[16]===Symbol.for("react.memo_cache_sentinel")?(x=n.jsx(Zr,{size:16}),e[16]=x):x=e[16];let y;e[17]!==l?(y=n.jsx("button",{type:"button",onClick:l,className:"flex size-7 shrink-0 items-center justify-center rounded-md text-foreground/60 hover:bg-accent hover:text-foreground transition-colors",title:"New task",children:x}),e[17]=l,e[18]=y):y=e[18];let w;e[19]!==y||e[20]!==m||e[21]!==b?(w=n.jsxs("div",{className:"flex items-center gap-0.5 shrink-0",children:[m,b,y]}),e[19]=y,e[20]=m,e[21]=b,e[22]=w):w=e[22];let C;return e[23]!==w||e[24]!==u||e[25]!==f?(C=n.jsxs("div",{className:"shrink-0 flex items-center gap-1 px-2 h-12 bg-background border-b border-border",children:[u,f,w]}),e[23]=w,e[24]=u,e[25]=f,e[26]=C):C=e[26],C}function Dc(t){const e=K.c(21),{virtualMcpId:s,hasActiveGithubRepo:i,sandboxMap:r,children:o}=t,{currentBranch:a}=ss(),{data:l}=Js.useSession(),h=l?.user?.id,c=Qu(s,a??void 0);let d,u;e[0]!==a||e[1]!==r||e[2]!==h?(d=h&&a?Jr(r?.[h]?.[a]):{},u=td(d),e[0]=a,e[1]=r,e[2]=h,e[3]=d,e[4]=u):(d=e[3],u=e[4]);const m=u?.previewUrl??null;let p;e[5]!==d||e[6]!==c?(p=Object.keys(d).length>0||c,e[5]=d,e[6]=c,e[7]=p):p=e[7];const _=p,g=a??null,v=a??null,b=h??null;let x;e[8]!==o||e[9]!==i||e[10]!==r||e[11]!==v||e[12]!==b||e[13]!==s?(x=n.jsx(n1,{virtualMcpId:s,branch:v,userId:b,hasActiveGithubRepo:i,sandboxMap:r,children:o}),e[8]=o,e[9]=i,e[10]=r,e[11]=v,e[12]=b,e[13]=s,e[14]=x):x=e[14];let y;return e[15]!==m||e[16]!==_||e[17]!==g||e[18]!==x||e[19]!==s?(y=n.jsx(F_,{virtualMcpId:s,branch:g,previewUrl:m,enabled:_,children:x}),e[15]=m,e[16]=_,e[17]=g,e[18]=x,e[19]=s,e[20]=y):y=e[20],y}function U2(){const t=K.c(116),e=Wc(),s=ts(),{org:i}=Pe();Zf(i.slug);let r;t[0]===Symbol.for("react.memo_cache_sentinel")?(r={strict:!1},t[0]=r):r=t[0];const o=Ac(r),a=o.org??"";let l;t[1]===Symbol.for("react.memo_cache_sentinel")?(l={strict:!1},t[1]=l):l=t[1];const h=$o(l);let c;t[2]!==i.id||t[3]!==h.virtualmcpid?(c=h.virtualmcpid??Fo(i.id).id,t[2]=i.id,t[3]=h.virtualmcpid,t[4]=c):c=t[4];const d=c,u=H2(o.taskId??"",d),f=Mt(d),m=f?.metadata?.ui?.layout??null;let p;t[5]!==m?(p=m?{defaultMainView:m.defaultMainView??null,chatDefaultOpen:m.chatDefaultOpen??null}:null,t[5]=m,t[6]=p):p=t[6];const _=p;let g;t[7]!==f?(g=f&&si(f),t[7]=f,t[8]=g):g=t[8];const v=!!g;let b;t[9]!==a||t[10]!==d?(b={virtualMcpId:d,orgSlug:a,isAgentRoute:!0},t[9]=a,t[10]=d,t[11]=b):b=t[11];const x=Up(_,b),{setOpenMobile:y,openMobile:w}=wf(),C=y,j=E.useRef(null);let R,B;t[12]===Symbol.for("react.memo_cache_sentinel")?(R=()=>{const U=H=>{bf(H)&&H.shiftKey&&H.code==="KeyS"&&!H.repeat&&(H.preventDefault(),j.current?.())};return document.addEventListener("keydown",U),()=>document.removeEventListener("keydown",U)},B=[],t[12]=R,t[13]=B):(R=t[12],B=t[13]),E.useEffect(R,B);const P=d;let T;t[14]!==f||t[15]!==d?(T={virtualMcpId:d,entity:f},t[14]=f,t[15]=d,t[16]=T):T=t[16];const S=T;if(u.status==="creating"||u.status==="loading"){let U;t[17]===Symbol.for("react.memo_cache_sentinel")?(U=n.jsx("div",{className:"flex-1 min-h-0 pr-1.5 pb-1.5 overflow-hidden",children:n.jsxs("div",{className:"flex h-full items-center justify-center bg-background card-shadow rounded-[0.75rem] text-sm text-muted-foreground",children:[n.jsx(Ce,{className:"size-4 animate-spin mr-2"}),"Creating task…"]})}),t[17]=U):U=t[17];let H;return t[18]!==S?(H=n.jsx(Hs,{value:S,children:U}),t[18]=S,t[19]=H):H=t[19],H}if(u.status==="error"){let U;t[20]===Symbol.for("react.memo_cache_sentinel")?(U=n.jsx("div",{className:"font-medium",children:"Task unavailable"}),t[20]=U):U=t[20];let H;t[21]!==u.error.message?(H=n.jsx("div",{className:"flex-1 min-h-0 pr-1.5 pb-1.5 overflow-hidden",children:n.jsxs("div",{className:"flex flex-col h-full items-center justify-center gap-2 bg-background card-shadow rounded-[0.75rem] p-8 text-sm",children:[U,n.jsx("div",{className:"text-muted-foreground",children:u.error.message})]})}),t[21]=u.error.message,t[22]=H):H=t[22];let X;return t[23]!==S||t[24]!==H?(X=n.jsx(Hs,{value:S,children:H}),t[23]=S,t[24]=H,t[25]=X):X=t[25],X}if(!f){let U;t[26]===Symbol.for("react.memo_cache_sentinel")?(U=n.jsx(Ui,{size:48,className:"text-muted-foreground"}),t[26]=U):U=t[26];const H=`The agent "${d}" does not exist in this organization.`;let X;t[27]!==s||t[28]!==a?(X=n.jsx(re,{variant:"outline",onClick:()=>s({to:"/$org",params:{org:a}}),children:"Go to organization home"}),t[27]=s,t[28]=a,t[29]=X):X=t[29];let oe;t[30]!==H||t[31]!==X?(oe=n.jsx("div",{className:"flex-1 min-h-0 pr-1.5 pb-1.5 overflow-hidden",children:n.jsx("div",{className:"flex flex-col h-full bg-background overflow-hidden card-shadow rounded-[0.75rem]",children:n.jsx(Er,{image:U,title:"Agent not found",description:H,actions:X})})}),t[30]=H,t[31]=X,t[32]=oe):oe=t[32];let L;return t[33]!==S||t[34]!==oe?(L=n.jsx(Hs,{value:S,children:oe}),t[33]=S,t[34]=oe,t[35]=L):L=t[35],L}if(e){let U;t[36]===Symbol.for("react.memo_cache_sentinel")?(U=n.jsx(Cf,{className:"sr-only",children:"Navigation"}),t[36]=U):U=t[36];let H;t[37]!==C?(H=n.jsxs(kf,{side:"left",hideCloseButton:!0,className:"w-[calc(100vw-3rem)] sm:max-w-md! p-0",children:[U,n.jsx("div",{className:"flex h-full",children:n.jsx("div",{className:"w-full bg-sidebar flex flex-col overflow-y-auto group/sidebar","data-state":"expanded",children:n.jsx(Sf,{onClose:()=>C(!1)})})})]}),t[37]=C,t[38]=H):H=t[38];let X;t[39]!==w||t[40]!==C||t[41]!==H?(X=n.jsx(jf,{open:w,onOpenChange:C,children:H}),t[39]=w,t[40]=C,t[41]=H,t[42]=X):X=t[42];const oe=X,L=u.status==="ready"?u.task:null,se=f?.metadata?.sandboxMap;let ee;t[43]!==x.createNewTask?(ee=n.jsx(Pc,{onNewTaskRef:j,createNewTask:x.createNewTask}),t[43]=x.createNewTask,t[44]=ee):ee=t[44];let Q;t[45]!==C?(Q=()=>C(!0),t[45]=C,t[46]=Q):Q=t[46];let O;t[47]!==P||t[48]!==f||t[49]!==v||t[50]!==x.createNewTask||t[51]!==x.mainOpen||t[52]!==x.taskId||t[53]!==x.toggleMain||t[54]!==Q?(O=n.jsx(W2,{onOpenSidebar:Q,virtualMcpId:P,taskId:x.taskId,mainOpen:x.mainOpen,onToggleMain:x.toggleMain,onNewTask:x.createNewTask,entity:f,hasActiveGithubRepo:v}),t[47]=P,t[48]=f,t[49]=v,t[50]=x.createNewTask,t[51]=x.mainOpen,t[52]=x.taskId,t[53]=x.toggleMain,t[54]=Q,t[55]=O):O=t[55];let ce;t[56]===Symbol.for("react.memo_cache_sentinel")?(ce=n.jsx(Oe.Skeleton,{}),t[56]=ce):ce=t[56];let ue;t[57]!==P||t[58]!==x.mainOpen||t[59]!==x.taskId?(ue=n.jsx(E.Suspense,{fallback:ce,children:n.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:x.mainOpen?n.jsx(Ut,{fallback:n.jsx("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:"Something went wrong. Try refreshing."}),children:n.jsx(E.Suspense,{fallback:n.jsx("div",{className:"h-full flex items-center justify-center",children:n.jsx(Ce,{size:20,className:"animate-spin text-muted-foreground"})}),children:n.jsx(bu,{taskId:x.taskId,virtualMcpId:P})})}):n.jsx(Rc,{})})}),t[57]=P,t[58]=x.mainOpen,t[59]=x.taskId,t[60]=ue):ue=t[60];let fe;t[61]!==x.taskId||t[62]!==O||t[63]!==ue?(fe=n.jsxs(Oe.ActiveTaskProvider,{taskId:x.taskId,children:[O,ue]},x.taskId),t[61]=x.taskId,t[62]=O,t[63]=ue,t[64]=fe):fe=t[64];let q;t[65]!==v||t[66]!==oe||t[67]!==se||t[68]!==ee||t[69]!==fe||t[70]!==d?(q=n.jsxs(Dc,{virtualMcpId:d,hasActiveGithubRepo:v,sandboxMap:se,children:[ee,fe,oe]}),t[65]=v,t[66]=oe,t[67]=se,t[68]=ee,t[69]=fe,t[70]=d,t[71]=q):q=t[71];let te;t[72]!==P||t[73]!==L||t[74]!==q?(te=n.jsx("div",{className:"flex flex-col flex-1 min-w-0 bg-background min-h-0",children:n.jsx(Oe.Provider,{virtualMcpId:P,task:L,children:q},P)}),t[72]=P,t[73]=L,t[74]=q,t[75]=te):te=t[75];let me;return t[76]!==S||t[77]!==te?(me=n.jsx(Hs,{value:S,children:te}),t[76]=S,t[77]=te,t[78]=me):me=t[78],me}let k;t[79]!==x.chatOpen||t[80]!==x.createNewTask||t[81]!==x.toggleChat?(k=n.jsx(Hn.Toggles,{children:n.jsx(f2,{chatOpen:x.chatOpen,toggleChat:x.toggleChat,onNewTask:x.createNewTask})}),t[79]=x.chatOpen,t[80]=x.createNewTask,t[81]=x.toggleChat,t[82]=k):k=t[82];const I=u.status==="ready"?u.task:null,N=f?.metadata?.sandboxMap;let A;t[83]!==x.taskId||t[84]!==d?(A=n.jsx(Hn.Tabs,{children:n.jsx(yu,{virtualMcpId:d,taskId:x.taskId})}),t[83]=x.taskId,t[84]=d,t[85]=A):A=t[85];let M;t[86]!==x.createNewTask?(M=n.jsx(Pc,{onNewTaskRef:j,createNewTask:x.createNewTask}),t[86]=x.createNewTask,t[87]=M):M=t[87];let D;t[88]!==f?(D=n.jsx(Cu,{virtualMcp:f}),t[88]=f,t[89]=D):D=t[89];let $;t[90]===Symbol.for("react.memo_cache_sentinel")?($=n.jsx(Oe.Skeleton,{}),t[90]=$):$=t[90];let z;t[91]===Symbol.for("react.memo_cache_sentinel")?(z=n.jsx(Rc,{}),t[91]=z):z=t[91];let W;t[92]!==x.chatOpen||t[93]!==x.mainOpen||t[94]!==x.taskId||t[95]!==d?(W=n.jsx(E.Suspense,{fallback:$,children:n.jsx(u2,{virtualMcpId:d,taskId:x.taskId,chatOpen:x.chatOpen,mainOpen:x.mainOpen,chatContent:z})}),t[92]=x.chatOpen,t[93]=x.mainOpen,t[94]=x.taskId,t[95]=d,t[96]=W):W=t[96];let F;t[97]!==x.taskId||t[98]!==D||t[99]!==W?(F=n.jsxs(Oe.ActiveTaskProvider,{taskId:x.taskId,children:[D,W]},x.taskId),t[97]=x.taskId,t[98]=D,t[99]=W,t[100]=F):F=t[100];let V;t[101]!==v||t[102]!==N||t[103]!==A||t[104]!==M||t[105]!==F||t[106]!==d?(V=n.jsxs(Dc,{virtualMcpId:d,hasActiveGithubRepo:v,sandboxMap:N,children:[A,M,F]}),t[101]=v,t[102]=N,t[103]=A,t[104]=M,t[105]=F,t[106]=d,t[107]=V):V=t[107];let J;t[108]!==P||t[109]!==I||t[110]!==V?(J=n.jsx(Oe.Provider,{virtualMcpId:P,task:I,children:V},P),t[108]=P,t[109]=I,t[110]=V,t[111]=J):J=t[111];let Y;return t[112]!==S||t[113]!==J||t[114]!==k?(Y=n.jsx("div",{className:"flex-1 min-w-0 flex flex-col",children:n.jsxs(Hs,{value:S,children:[k,J]})}),t[112]=S,t[113]=J,t[114]=k,t[115]=Y):Y=t[115],Y}function K2(){const t=K.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=n.jsx(E.Suspense,{fallback:n.jsx(yf,{}),children:n.jsx(U2,{})}),t[0]=e):e=t[0],e}const xk=Object.freeze(Object.defineProperty({__proto__:null,default:K2,useInsetContext:sr},Symbol.toStringTag,{value:"Module"}));export{gd as $,dk as A,WC as B,ZC as C,rk as D,ax as E,ik as F,OC as G,YC as H,JC as I,GC as J,sx as K,ud as L,KC as M,Eh as N,VC as O,on as P,uk as Q,sk as R,Th as S,a1 as T,tk as U,fk as V,S_ as W,ak as X,MC as Y,LC as Z,nl as _,fa as a,lk as a0,ck as a1,Lh as a2,Yn as a3,$C as a4,zC as a5,FC as a6,wu as a7,jv as a8,br as a9,W1 as aa,Xn as ab,Px as ac,_k as ad,Ax as ae,yd as af,pk as ag,kl as ah,mk as ai,xk as aj,Xi as b,nk as c,UC as d,da as e,HC as f,Ca as g,U1 as h,es as i,va as j,P_ as k,zr as l,Fh as m,Ih as n,qC as o,pd as p,QC as q,XC as r,ix as s,Mx as t,ha as u,Ji as v,hk as w,ek as x,ok as y,fx as z};
|
|
311
|
+
`),Se=ge=>{k||W||V||t(ge)},we=async()=>{J(!0),X(void 0);try{const ge=xe()||N.trim()||`Changes from ${q}`;await bn(e,i,r,ge),le.success(f?`Saved changes to PR #${f.number}`:"Changes saved"),Se(!1),await m?.()}catch(ge){X(ge instanceof Error?ge.message:"Failed to save changes")}finally{J(!1)}},et=async()=>{I(!0),z(void 0);let ge;try{const je=N.trim()||`Changes from ${q}`,tt=M.trim()||void 0,yt=xe()||je;try{await bn(e,i,r,yt)}catch(st){throw new bi(st instanceof Error?st.message:"Failed to push changes","push")}try{await Sv(e,i,r,o)}catch(st){throw new bi(st instanceof Error?st.message:"Failed to rebase onto base","rebase")}try{ge=await rl(_,{owner:l,repo:h,branch:q,title:je,body:tt,base:o,coAuthor:x})}catch(st){throw new bi(st instanceof Error?st.message:"Failed to open pull request","open-pr")}try{await Ch(_,{owner:l,repo:h,pullNumber:ge.number,commitTitle:je,commitMessage:tt,coAuthor:x})}catch(st){throw new bi(st instanceof Error?st.message:"Failed to merge pull request","merge",ge)}le.success(`Published to ${o}`),Se(!1),P(null),A(""),D(""),await m?.(),await p?.()}catch(je){if(je instanceof bi&&je.step==="merge"&&je.pr){const tt=`Changes were pushed and PR #${je.pr.number} is open, but merge failed: ${je.message}`;z(tt),le.error(tt,{action:{label:"View PR",onClick:()=>window.open(je.pr.htmlUrl,"_blank","noopener,noreferrer")}}),await m?.();return}z(je instanceof Error?je.message:"Failed to publish")}finally{I(!1)}},bt=async ge=>{try{await bl(e,i,r,[ge]),le.success(`Discarded changes to ${ge}`),P(tt=>{if(!tt)return tt;const yt={...tt,diffs:{...tt.diffs}};return delete yt.diffs[ge],yt});const je=await br(e,i,r);R(je)}catch(je){le.error(je instanceof Error?je.message:"Failed to discard changes")}},ir=async()=>{if(B){L(!1),ee(!0);try{const ge=Object.keys(B.diffs);if(ge.length===0)return;await bl(e,i,r,ge),le.success("All changes discarded"),P(null);const je=await br(e,i,r);R(je),Se(!1)}catch(ge){le.error(ge instanceof Error?ge.message:"Failed to discard changes")}finally{ee(!1)}}},rr=async()=>{F(!0),U(void 0);try{const ge=N.trim()||`Changes from ${q}`,je=M.trim()||void 0,tt=xe()||ge;await bn(e,i,r,tt);const yt=await rl(_,{owner:l,repo:h,branch:q,title:ge,body:je,base:o,coAuthor:x});le.success(`Submitted pull request #${yt.number} for review`,{action:{label:"View on GitHub",onClick:()=>window.open(yt.htmlUrl,"_blank","noopener,noreferrer")}}),Se(!1),await m?.()}catch(ge){U(ge instanceof Error?ge.message:"Failed to submit for review")}finally{F(!1)}};return n.jsx(Ot,{className:"top-14 left-auto right-4 flex h-[90%] max-h-[85vh] w-[90vw] max-w-[600px] translate-x-0 translate-y-0 flex-col gap-0 overflow-hidden p-0",children:n.jsxs(Qo,{defaultValue:"description",className:"flex h-full flex-col gap-0",children:[n.jsxs("div",{className:"shrink-0 space-y-3 px-6 pt-5 pb-4",children:[n.jsxs("div",{className:"space-y-1",children:[n.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:w?"Save changes":C?"Submit for review":te}),n.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[n.jsx("span",{className:"inline-block h-2.5 w-2.5 shrink-0 rounded-full bg-green-500"}),ke," ",ke===1?"change":"changes"," ",w?"to save":C?"in this PR":"to publish"]})]}),oe?n.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md bg-destructive/5 px-3 py-2",children:[n.jsx("span",{className:"text-xs text-destructive",children:"Discard all changes? This cannot be undone."}),n.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[n.jsx(re,{type:"button",variant:"ghost",size:"sm",className:"h-7 px-2 text-xs",onClick:()=>L(!1),children:"Cancel"}),n.jsxs(re,{type:"button",size:"sm",className:"h-7 bg-destructive px-2 text-xs text-destructive-foreground hover:bg-destructive/90",onClick:ir,disabled:se,children:[se?n.jsx(Ce,{className:"h-3 w-3 animate-spin"}):null,"Discard all"]})]})]}):n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs(Zo,{className:"h-8 w-auto",variant:"pill",children:[n.jsx(ys,{value:"description",className:"px-3 text-xs",children:"Description"}),n.jsx(ys,{value:"changes",className:"px-3 text-xs",children:"Changes"})]}),ke>0&&!C&&n.jsx("button",{type:"button",className:"text-xs text-muted-foreground transition-colors hover:text-destructive disabled:opacity-50",onClick:()=>L(!0),disabled:k||se||V,children:"Discard all"})]})]}),n.jsx("div",{className:"border-t"}),n.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:T?n.jsxs("div",{className:"flex items-center justify-center gap-2 py-16 text-muted-foreground",children:[n.jsx(Ce,{className:"h-4 w-4 animate-spin"}),n.jsx("span",{className:"text-sm",children:"Loading changes…"})]}):n.jsxs(n.Fragment,{children:[n.jsx(Ti,{value:"description",className:"mt-0 px-6 py-5",children:n.jsxs("div",{className:"space-y-4",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("p",{className:"text-sm font-medium",children:C?"Pull request":"Commit message"}),n.jsxs("button",{type:"button",className:"flex items-center gap-1.5 text-xs text-muted-foreground transition-colors hover:text-foreground disabled:opacity-50",disabled:Q||k||W||V,onClick:me,children:[Q?n.jsx(Ce,{className:"h-3 w-3 animate-spin"}):n.jsx(Ss,{className:"h-3 w-3"}),Q?"Generating…":"Regenerate"]})]}),n.jsxs("div",{className:"space-y-1.5",children:[n.jsx("label",{htmlFor:"publish-title",className:"text-xs font-medium text-muted-foreground",children:"Title"}),n.jsx(qe,{id:"publish-title",value:N,onChange:ge=>A(ge.target.value),placeholder:Q?"Generating…":"Commit title…",disabled:k||W||V||Q,className:"text-sm"})]}),n.jsxs("div",{className:"space-y-1.5",children:[n.jsx("label",{htmlFor:"publish-body",className:"text-xs font-medium text-muted-foreground",children:"Description"}),n.jsx(Tr,{id:"publish-body",value:M,onChange:ge=>D(ge.target.value),placeholder:Q?"Generating…":"Description (optional)…",disabled:k||W||V||Q,rows:5,className:"resize-none text-sm"})]}),n.jsxs("p",{className:"text-xs text-muted-foreground",children:["Branch: ",n.jsx("span",{className:"font-mono",children:r}),w?n.jsxs(n.Fragment,{children:[" · ",n.jsx("span",{className:"text-foreground/80",children:y?`Commits and pushes to update open PR #${f.number}.`:"Commits and pushes to the branch without opening a pull request."})]}):n.jsxs(n.Fragment,{children:[" → ",n.jsx("span",{className:"font-mono",children:o})," · ",n.jsxs("span",{className:"text-foreground/80",children:["Submit for review keeps changes on the branch;"," ",te," squash-merges into ",o,"."]})]})]})]})}),n.jsx(Ti,{value:"changes",className:"mt-0",children:n.jsx(Qh,{diff:B,onDiscardFile:bt})})]})}),n.jsx("div",{className:"shrink-0 border-t",children:n.jsxs("button",{type:"button",className:"flex w-full items-center justify-between px-6 py-3.5 text-sm transition-colors hover:bg-muted/50 disabled:opacity-50",onClick:()=>{c&&window.open(c,"_blank","noopener,noreferrer")},disabled:!c,children:[n.jsxs("span",{className:"flex items-center gap-3",children:[n.jsx(Em,{className:"h-4 w-4 text-muted-foreground"}),"Visit preview"]}),n.jsx(af,{className:"h-4 w-4 text-muted-foreground"})]})}),n.jsx("div",{className:"shrink-0 border-t px-6 py-3",children:w&&!G?n.jsxs(n.Fragment,{children:[n.jsxs(re,{type:"button",className:"w-full",onClick:we,disabled:!Be||V,children:[V?n.jsx(Ce,{className:"h-4 w-4 animate-spin"}):null,"Save changes"]}),H&&n.jsx("p",{className:"mt-2 text-xs text-destructive",children:H})]}):w?n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsxs(re,{type:"button",variant:"outline",className:"flex-1",onClick:we,disabled:!Be||V||W,children:[V?n.jsx(Ce,{className:"h-4 w-4 animate-spin"}):null,"Save changes"]}),n.jsxs(re,{type:"button",className:"flex-1",onClick:rr,disabled:!_e||W||V,children:[W?n.jsx(Ce,{className:"h-4 w-4 animate-spin"}):n.jsx(Mi,{className:"h-4 w-4"}),"Submit for review"]})]}),H&&n.jsx("p",{className:"mt-2 text-xs text-destructive",children:H}),Y&&n.jsx("p",{className:"mt-2 text-xs text-destructive",children:Y})]}):n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsxs(re,{type:"button",variant:"outline",className:"flex-1",onClick:rr,disabled:!_e||W||k,children:[W?n.jsx(Ce,{className:"h-4 w-4 animate-spin"}):n.jsx(Mi,{className:"h-4 w-4"}),"Submit for review"]}),n.jsx(N2,{label:te,canPublish:mt,disabledReason:as,isPublishing:k,isSubmittingForReview:W,onPublish:et})]}),Y&&n.jsx("p",{className:"mt-2 text-xs text-destructive",children:Y}),$&&n.jsx("p",{className:"mt-2 text-xs text-destructive",children:$})]})})]})})}function N2(t){const e=K.c(14),{label:s,canPublish:i,disabledReason:r,isPublishing:o,isSubmittingForReview:a,onPublish:l}=t,h=!i||o||a;let c;e[0]!==o?(c=o?n.jsx(Ce,{className:"h-4 w-4 animate-spin"}):null,e[0]=o,e[1]=c):c=e[1];let d;e[2]!==s||e[3]!==l||e[4]!==h||e[5]!==c?(d=n.jsxs(re,{type:"button",variant:"success",className:"flex-1",onClick:l,disabled:h,children:[c,s]}),e[2]=s,e[3]=l,e[4]=h,e[5]=c,e[6]=d):d=e[6];const u=d;if(!r)return u;let f;e[7]!==u?(f=n.jsx(Ee,{asChild:!0,children:n.jsx("span",{className:"flex flex-1",children:u})}),e[7]=u,e[8]=f):f=e[8];let m;e[9]!==r?(m=n.jsx(Te,{children:r}),e[9]=r,e[10]=m):m=e[10];let p;return e[11]!==f||e[12]!==m?(p=n.jsx(Uc,{children:n.jsxs(Re,{children:[f,m]})}),e[11]=f,e[12]=m,e[13]=p):p=e[13],p}function E2(){return!1}function wu(t,e){E2()&&console.log(`[github-header] ${t}`,e??"")}function T2(t){if(!(t==="claiming"||t==="ready"||t==="failed"))return od[t].short}const R2=new Set(["failure","timed_out","cancelled","action_required"]);function P2(t){return t.status==="completed"&&R2.has(t.conclusion)}function D2(t){return t.status==="queued"||t.status==="in_progress"}function A2(t){const{lifecycle:e,branch:s,pr:i,checks:r,reviews:o,loading:a}=t;if(a)return{label:"Loading…",disabled:!0,loading:!0,variant:"outline",tooltip:"Loading branch and pull request status"};switch(e.phase){case"idle":return{label:t.claimPhase&&T2(t.claimPhase.kind)||"Starting sandbox…",disabled:!0,loading:!0,variant:"outline",tooltip:"Waiting for the sandbox daemon to come online"};case"cloning":return{label:"Cloning repo…",disabled:!0,loading:!0,variant:"outline",tooltip:"Cloning the project repository"};case"clone-failed":return{label:"Clone failed",disabled:!0,variant:"outline",tooltip:e.error||"git clone failed — see setup logs"};case"checking-out":return{label:`Switching to ${e.to}…`,disabled:!0,loading:!0,variant:"outline",tooltip:`Checking out ${e.to}`}}if(s.kind!=="ready")return{label:"Loading branch…",disabled:!0,loading:!0,variant:"outline",tooltip:"Waiting for branch metadata from the sandbox daemon"};const l=s;if(l.workingTreeDirty)return{label:"Save changes",action:"commit-and-push",variant:"default",tooltip:"Commit and push local changes"};if(l.unpushed>0)return i?{label:"Save changes",action:"commit-and-push",variant:"default",tooltip:"Push local commits"}:{label:"Submit for review",action:"create-pr",variant:"default",tooltip:`Push and open a PR for ${l.branch} → ${l.base}`};if(wu("no local work — checking PR/sync state",{workingTreeDirty:l.workingTreeDirty,unpushed:l.unpushed,aheadOfBase:l.aheadOfBase,behindBase:l.behindBase,branch:l.branch,base:l.base,prMerged:i?.merged??null,prState:i?.state??null}),i?.merged)return!!l.headSha&&!!i.headSha&&l.headSha!==i.headSha?{label:"Continue",action:"create-pr",variant:"special",tooltip:"Open a new PR with the latest commits"}:{label:"Published",disabled:!0,variant:"outline",tooltip:`PR #${i.number} merged into ${i.base}`};if(l.aheadOfBase>0){if(i&&i.state==="closed"&&!i.merged)return{label:"Reopen",action:"reopen",variant:"default",tooltip:`Reopen PR #${i.number}`};if(!i)return{label:"Submit for review",action:"create-pr",variant:"default",tooltip:`Open a PR for ${l.branch} → ${l.base}`};if((o?.mergeableState??"unknown")==="dirty")return{label:`Sync with ${i.base}`,action:"rebase",variant:"default",tooltip:`Resolve conflicts with ${i.base} before merging`};const c=r.filter(P2).map(f=>f.name);if(c.length>0)return{label:"Fix tests",action:"fix-checks",variant:"default",tooltip:`Failing: ${c.join(", ")}`,meta:{failingChecks:c}};const d=r.filter(D2);if(d.length>0)return{label:"Running tests…",disabled:!0,loading:!0,variant:"outline",tooltip:`Waiting on ${d.length} check${d.length===1?"":"s"} to finish`};if(o?.draft)return{label:"Mark ready",action:"mark-ready",variant:"default",tooltip:"Mark draft PR ready for review"};const u=o?.unresolvedConversations??0;return u>0?{label:"Address feedback",action:"resolve-comments",variant:"default",tooltip:`${u} unresolved conversation${u===1?"":"s"}`}:o?.missingRequiredApprovals?{label:"Awaiting review",disabled:!0,variant:"outline",tooltip:"Waiting for required approvals"}:{label:$a(i.base),action:"merge-split",variant:"success",tooltip:`Squash-merge PR #${i.number} into ${i.base}`}}return{label:"Up to date",disabled:!0,variant:"outline",tooltip:`Branch is in sync with ${l.base}`}}function I2(t,e,s){if(!e)return s??null;const i=t?.[e];if(!i)return s??null;if(s&&i[s])return s;for(const[r,o]of Object.entries(i))if(o&&Object.keys(o).length>0)return r;return s??null}const B2=6e4,M2=3e4;function L2(t){const e=K.c(12);let s;e[0]!==t.connectionId||e[1]!==t.orgId||e[2]!==t.orgSlug?(s={connectionId:t.connectionId,orgId:t.orgId,orgSlug:t.orgSlug},e[0]=t.connectionId,e[1]=t.orgId,e[2]=t.orgSlug,e[3]=s):s=e[3];const i=ft(s),r=t.prNumber??0;let o;e[4]!==t.owner||e[5]!==t.repo||e[6]!==r?(o={method:"get",owner:t.owner,repo:t.repo,pullNumber:r},e[4]=t.owner,e[5]=t.repo,e[6]=r,e[7]=o):o=e[7];const a=!!t.prNumber;let l;return e[8]!==i||e[9]!==o||e[10]!==a?(l={client:i,toolName:"pull_request_read",toolArguments:o,enabled:a,refetchInterval:B2,refetchIntervalInBackground:!1,staleTime:M2,select:O2},e[8]=i,e[9]=o,e[10]=a,e[11]=l):l=e[11],sn(l)}function O2(t){const e=Bs(t);if(!e)return null;const s=e.mergeable_state??"unknown",i=!!(e.draft??!1),r=Number(e.review_comments??0),o=s==="blocked"&&r>0?r:0;return{draft:i,mergeableState:s,unresolvedConversations:o,missingRequiredApprovals:s==="blocked"&&o===0}}const $2={label:"Loading branch…",disabled:!0,loading:!0,variant:"outline",tooltip:"Waiting for sandbox branch"};function z2({virtualMcpId:t}){const{org:e}=Pe(),{data:s}=Js.useSession(),i=Mt(t),{currentBranch:r,setCurrentTaskBranch:o}=ss(),a=Ns(),[l,h]=E.useState(!1),[c,d]=E.useState("publish"),[u,f]=E.useState(!1),m=E.useRef(""),p=si(i),_=s?.user?.id,g=ft({connectionId:p?.connectionId??"",orgId:e.id,orgSlug:e.slug}),{lifecycle:v,branch:b,phase:x,notFound:y}=Yt(),w=b.kind==="ready"?b.branch:null,C=I2(i?.metadata?.sandboxMap,_,r??w),j=r??w??C??void 0,R=v.phase==="cloning"||v.phase==="checking-out"||v.phase==="clone-failed",B=x2({orgSlug:e.slug,virtualMcpId:t,branch:j??null,enabled:!!p&&!!j&&!y&&!R}),P=Sa(B.data)??j??null,T=ca({orgId:e.id,orgSlug:e.slug,connectionId:p?.connectionId??"",owner:p?.owner??"",repo:p?.name??"",branch:P}),S=T.data??null,k=kh({orgId:e.id,orgSlug:e.slug,connectionId:p?.connectionId??"",owner:p?.owner??"",repo:p?.name??"",prNumber:S&&S.state==="open"?S.number:null}),I=L2({orgId:e.id,orgSlug:e.slug,connectionId:p?.connectionId??"",owner:p?.owner??"",repo:p?.name??"",prNumber:S&&S.state==="open"?S.number:null}),N=Pv(b,B.data);if(!p)return null;const A=_&&P?Jr(i?.metadata?.sandboxMap?.[_]?.[P]):{},M=Object.values(A),$=(M.find(L=>L.sandboxProviderKind!=="user-desktop")??M[0])?.previewUrl??null,z=P?A2({lifecycle:v,branch:N,claimPhase:x,pr:S,checks:k.data??[],reviews:I.data??null,loading:T.isPending}):$2,W=JSON.stringify({label:z.label,branchKind:N.kind,workingTreeDirty:N.kind==="ready"?N.workingTreeDirty:null,gitModifiedCount:B.data?.modified.length??null,unpushed:N.kind==="ready"?N.unpushed:null,aheadOfBase:N.kind==="ready"?N.aheadOfBase:null,lifecycle:v.phase,githubHeadBranch:P});m.current!==W&&(m.current=W,wu("header button",{label:z.label,tooltip:z.tooltip,action:z.action,chatBranch:r,sandboxBranch:w,sandboxMapBranch:C,sandboxRouteBranch:j,githubHeadBranch:P,branchMeta:b,effectiveBranchMeta:N,gitStatus:B.data??null,lifecyclePhase:v.phase,prNumber:S?.number??null,prState:S?.state??null}));const F=L=>a.sendMessage({parts:[{type:"text",text:L}]}),V=a.isStreaming,J=N.kind==="ready"?N.base:"main",Y=async()=>{await Promise.all([T.refetch(),B.refetch(),k.refetch(),I.refetch()])},U=async()=>{const L=Ju();await o(L)},H=async L=>{if(!(!p?.connectionId||u)){f(!0);try{const se=Su(s?.user);await Ch(g,{owner:p.owner,repo:p.name,pullNumber:L,coAuthor:se}),le.success(`Published PR #${L}`),await Y(),await U()}catch(se){le.error(se instanceof Error?se.message:"Failed to merge pull request")}finally{f(!1)}}},X=L=>{if(!(!L||!P))switch(L){case"commit-and-push":d("publish"),h(!0);return;case"create-pr":d("open-pr"),h(!0);return;case"reopen":if(V)return;S&&F(Mv({prNumber:S.number}));return;case"rebase":if(V)return;F(Lv({branch:P}));return;case"fix-checks":if(V)return;S&&F($v({prNumber:S.number,failingChecks:z.meta?.failingChecks??[]}));return;case"mark-ready":if(V)return;S&&F(zv({prNumber:S.number}));return;case"resolve-comments":if(V)return;S&&F(Fv({prNumber:S.number}));return;case"merge-split":return}},oe=u||V;return n.jsxs(n.Fragment,{children:[n.jsx(F2,{button:z,actionBusy:oe,githubActionPending:u,onActivate:X,prNumber:S?.number,prBase:S?.base,onSquashMerge:H,onReview:S?()=>{V||F(Hv({prNumber:S.number}))}:void 0}),j&&n.jsx(C2,{open:l,onOpenChange:h,orgSlug:e.slug,orgId:e.id,virtualMcpId:t,branch:j,baseBranch:J,githubConnectionId:p.connectionId??"",owner:p.owner,repo:p.name,previewUrl:$,dialogIntent:c,headSha:N.kind==="ready"?N.headSha:null,openPullRequest:S?.state==="open"?S:null,onPullRequestChanged:Y,onPublished:U})]})}function F2(t){const e=K.c(25),{button:s,actionBusy:i,githubActionPending:r}=t,o=i&&s.action!=="create-pr"&&s.action!=="commit-and-push"&&s.action!=="merge-split",a=!!s.disabled||o||r&&s.action==="merge-split",l=!!s.loading||r&&s.action==="merge-split",h=o?"Chat is running":s.tooltip??null;if(s.action==="merge-split"&&t.prNumber!=null&&t.prBase!=null){let m;e[0]!==t?(m=()=>t.onSquashMerge(t.prNumber),e[0]=t,e[1]=m):m=e[1];let p;e[2]!==a||e[3]!==l||e[4]!==t.onReview||e[5]!==t.prBase||e[6]!==m?(p=n.jsx(w2,{baseBranch:t.prBase,disabled:a,loading:l,onPublish:m,onReview:t.onReview}),e[2]=a,e[3]=l,e[4]=t.onReview,e[5]=t.prBase,e[6]=m,e[7]=p):p=e[7];let _;return e[8]!==p||e[9]!==h?(_=n.jsx(Tc,{label:h,children:p}),e[8]=p,e[9]=h,e[10]=_):_=e[10],_}let c;e[11]!==s.action||e[12]!==t?(c=()=>{s.action&&t.onActivate(s.action)},e[11]=s.action,e[12]=t,e[13]=c):c=e[13];let d;e[14]!==l?(d=l?n.jsx(Xo,{size:"xs",variant:"default"}):null,e[14]=l,e[15]=d):d=e[15];let u;e[16]!==s.label||e[17]!==s.variant||e[18]!==a||e[19]!==c||e[20]!==d?(u=n.jsxs(re,{size:"sm",variant:s.variant,disabled:a,onClick:c,children:[d,s.label]}),e[16]=s.label,e[17]=s.variant,e[18]=a,e[19]=c,e[20]=d,e[21]=u):u=e[21];let f;return e[22]!==u||e[23]!==h?(f=n.jsx(Tc,{label:h,children:u}),e[22]=u,e[23]=h,e[24]=f):f=e[24],f}function Tc(t){const e=K.c(9),{label:s,children:i}=t;if(!s){let l;return e[0]!==i?(l=n.jsx(n.Fragment,{children:i}),e[0]=i,e[1]=l):l=e[1],l}let r;e[2]!==i?(r=n.jsx(Ee,{asChild:!0,children:n.jsx("span",{children:i})}),e[2]=i,e[3]=r):r=e[3];let o;e[4]!==s?(o=n.jsx(Te,{children:s}),e[4]=s,e[5]=o):o=e[5];let a;return e[6]!==r||e[7]!==o?(a=n.jsx(Uc,{children:n.jsxs(Re,{children:[r,o]})}),e[6]=r,e[7]=o,e[8]=a):a=e[8],a}function Cu(t){const e=K.c(4),{virtualMcp:s,inline:i}=t,r=i===void 0?!1:i;if(!si(s))return null;let a;e[0]!==s.id?(a=n.jsx(z2,{virtualMcpId:s.id}),e[0]=s.id,e[1]=a):a=e[1];const l=a;if(r)return l;let h;return e[2]!==l?(h=n.jsx(Hn.Right,{children:l}),e[2]=l,e[3]=h):h=e[3],h}function H2(t,e){const s=K.c(34),i=eh(),r=E.useSyncExternalStore(i.threads.subscribe,i.threads.get),o=E.useSyncExternalStore(i.threadsStatus.subscribe,i.threadsStatus.get);let a;s[0]!==t||s[1]!==r?(a=t?r.find(x=>x.id===t)??null:null,s[0]=t,s[1]=r,s[2]=a):a=s[2];const l=a,[h,c]=E.useState(void 0);let d;s[3]===Symbol.for("react.memo_cache_sentinel")?(d=()=>{c(void 0)},s[3]=d):d=s[3];let u;s[4]!==t?(u=[t],s[4]=t,s[5]=u):u=s[5],E.useEffect(d,u);let f,m;s[6]!==h||s[7]!==t||s[8]!==l||s[9]!==i||s[10]!==o.kind?(f=()=>{t&&(l||o.kind!=="loading"&&h===void 0&&(c("pending"),i.fetchThread(t).then(x=>{c(x)})))},m=[t,l,o.kind,h,i],s[6]=h,s[7]=t,s[8]=l,s[9]=i,s[10]=o.kind,s[11]=f,s[12]=m):(f=s[11],m=s[12]),E.useEffect(f,m);let p;s[13]!==i||s[14]!==e?(p={mutationFn:async x=>i.create({id:x,virtual_mcp_id:e})},s[13]=i,s[14]=e,s[15]=p):p=s[15];const _=ei(p);let g,v;if(s[16]!==_||s[17]!==h||s[18]!==t||s[19]!==l||s[20]!==o.kind?(g=()=>{t&&(l||h===null&&o.kind!=="loading"&&(_.isPending||_.variables!==t&&_.mutate(t)))},v=[t,l,h,o.kind,_],s[16]=_,s[17]=h,s[18]=t,s[19]=l,s[20]=o.kind,s[21]=g,s[22]=v):(g=s[21],v=s[22]),E.useEffect(g,v),!t){let x;return s[23]===Symbol.for("react.memo_cache_sentinel")?(x={status:"ready",task:null},s[23]=x):x=s[23],x}if(l){let x;return s[24]!==l?(x={status:"ready",task:l},s[24]=l,s[25]=x):x=s[25],x}if(h&&typeof h=="object"){let x;return s[26]!==h?(x={status:"ready",task:h},s[26]=h,s[27]=x):x=s[27],x}if(_.data){let x;return s[28]!==_.data?(x={status:"ready",task:_.data},s[28]=_.data,s[29]=x):x=s[29],x}if(_.isError){let x;return s[30]!==_.error?(x={status:"error",error:_.error},s[30]=_.error,s[31]=x):x=s[31],x}if(_.isPending||o.kind!=="loading"){let x;return s[32]===Symbol.for("react.memo_cache_sentinel")?(x={status:"creating"},s[32]=x):x=s[32],x}let b;return s[33]===Symbol.for("react.memo_cache_sentinel")?(b={status:"loading"},s[33]=b):b=s[33],b}const Hs=E.createContext(null);function sr(){return E.use(Hs)}function Rc(t){const e=K.c(6),{children:s}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=n.jsx("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:"Something went wrong loading the chat. Try refreshing."}),e[0]=i):i=e[0];let r;e[1]===Symbol.for("react.memo_cache_sentinel")?(r=n.jsx(Oe.Skeleton,{}),e[1]=r):r=e[1];let o;e[2]!==s?(o=s??n.jsx(gh,{}),e[2]=s,e[3]=o):o=e[3];let a;return e[4]!==o?(a=n.jsx(Ut,{fallback:i,children:n.jsx(E.Suspense,{fallback:r,children:o})}),e[4]=o,e[5]=a):a=e[5],a}function Pc(t){const e=K.c(3),{onNewTaskRef:s,createNewTask:i}=t;let r;return e[0]!==i||e[1]!==s?(r=()=>(s.current=i,()=>{s.current=null}),e[0]=i,e[1]=s,e[2]=r):r=e[2],E.useLayoutEffect(r),null}function W2(t){const e=K.c(27),{onOpenSidebar:s,virtualMcpId:i,taskId:r,mainOpen:o,onToggleMain:a,onNewTask:l,entity:h,hasActiveGithubRepo:c}=t;let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d=n.jsx(Zf,{size:20}),e[0]=d):d=e[0];let u;e[1]!==s?(u=n.jsx("button",{type:"button",onClick:s,className:"flex size-8 shrink-0 items-center justify-center rounded-md text-foreground/60 hover:bg-accent hover:text-foreground transition-colors","aria-label":"Open menu",children:d}),e[1]=s,e[2]=u):u=e[2];let f;e[3]!==r||e[4]!==i?(f=n.jsx("div",{className:"flex-1 min-w-0 overflow-x-auto [scrollbar-width:none]",children:n.jsx(yu,{virtualMcpId:i,taskId:r})}),e[3]=r,e[4]=i,e[5]=f):f=e[5];let m;e[6]!==h||e[7]!==c?(m=h&&c?n.jsx(Cu,{virtualMcp:h,inline:!0}):null,e[6]=h,e[7]=c,e[8]=m):m=e[8];const p=!o,_=o?"text-foreground/60 hover:bg-accent hover:text-foreground":"bg-accent text-foreground";let g;e[9]!==_?(g=he("flex size-7 shrink-0 items-center justify-center rounded-md transition-colors",_),e[9]=_,e[10]=g):g=e[10];let v;e[11]===Symbol.for("react.memo_cache_sentinel")?(v=n.jsx(Xc,{size:16}),e[11]=v):v=e[11];let b;e[12]!==a||e[13]!==p||e[14]!==g?(b=n.jsx("button",{type:"button",onClick:a,"aria-pressed":p,className:g,title:"Chat",children:v}),e[12]=a,e[13]=p,e[14]=g,e[15]=b):b=e[15];let x;e[16]===Symbol.for("react.memo_cache_sentinel")?(x=n.jsx(Zr,{size:16}),e[16]=x):x=e[16];let y;e[17]!==l?(y=n.jsx("button",{type:"button",onClick:l,className:"flex size-7 shrink-0 items-center justify-center rounded-md text-foreground/60 hover:bg-accent hover:text-foreground transition-colors",title:"New task",children:x}),e[17]=l,e[18]=y):y=e[18];let w;e[19]!==y||e[20]!==m||e[21]!==b?(w=n.jsxs("div",{className:"flex items-center gap-0.5 shrink-0",children:[m,b,y]}),e[19]=y,e[20]=m,e[21]=b,e[22]=w):w=e[22];let C;return e[23]!==w||e[24]!==u||e[25]!==f?(C=n.jsxs("div",{className:"shrink-0 flex items-center gap-1 px-2 h-12 bg-background border-b border-border",children:[u,f,w]}),e[23]=w,e[24]=u,e[25]=f,e[26]=C):C=e[26],C}function Dc(t){const e=K.c(21),{virtualMcpId:s,hasActiveGithubRepo:i,sandboxMap:r,children:o}=t,{currentBranch:a}=ss(),{data:l}=Js.useSession(),h=l?.user?.id,c=Zu(s,a??void 0);let d,u;e[0]!==a||e[1]!==r||e[2]!==h?(d=h&&a?Jr(r?.[h]?.[a]):{},u=td(d),e[0]=a,e[1]=r,e[2]=h,e[3]=d,e[4]=u):(d=e[3],u=e[4]);const m=u?.previewUrl??null;let p;e[5]!==d||e[6]!==c?(p=Object.keys(d).length>0||c,e[5]=d,e[6]=c,e[7]=p):p=e[7];const _=p,g=a??null,v=a??null,b=h??null;let x;e[8]!==o||e[9]!==i||e[10]!==r||e[11]!==v||e[12]!==b||e[13]!==s?(x=n.jsx(n1,{virtualMcpId:s,branch:v,userId:b,hasActiveGithubRepo:i,sandboxMap:r,children:o}),e[8]=o,e[9]=i,e[10]=r,e[11]=v,e[12]=b,e[13]=s,e[14]=x):x=e[14];let y;return e[15]!==m||e[16]!==_||e[17]!==g||e[18]!==x||e[19]!==s?(y=n.jsx(F_,{virtualMcpId:s,branch:g,previewUrl:m,enabled:_,children:x}),e[15]=m,e[16]=_,e[17]=g,e[18]=x,e[19]=s,e[20]=y):y=e[20],y}function U2(){const t=K.c(116),e=Wc(),s=ts(),{org:i}=Pe();Qf(i.slug);let r;t[0]===Symbol.for("react.memo_cache_sentinel")?(r={strict:!1},t[0]=r):r=t[0];const o=Ac(r),a=o.org??"";let l;t[1]===Symbol.for("react.memo_cache_sentinel")?(l={strict:!1},t[1]=l):l=t[1];const h=$o(l);let c;t[2]!==i.id||t[3]!==h.virtualmcpid?(c=h.virtualmcpid??Fo(i.id).id,t[2]=i.id,t[3]=h.virtualmcpid,t[4]=c):c=t[4];const d=c,u=H2(o.taskId??"",d),f=Mt(d),m=f?.metadata?.ui?.layout??null;let p;t[5]!==m?(p=m?{defaultMainView:m.defaultMainView??null,chatDefaultOpen:m.chatDefaultOpen??null}:null,t[5]=m,t[6]=p):p=t[6];const _=p;let g;t[7]!==f?(g=f&&si(f),t[7]=f,t[8]=g):g=t[8];const v=!!g;let b;t[9]!==a||t[10]!==d?(b={virtualMcpId:d,orgSlug:a,isAgentRoute:!0},t[9]=a,t[10]=d,t[11]=b):b=t[11];const x=Up(_,b),{setOpenMobile:y,openMobile:w}=Cf(),C=y,j=E.useRef(null);let R,B;t[12]===Symbol.for("react.memo_cache_sentinel")?(R=()=>{const U=H=>{yf(H)&&H.shiftKey&&H.code==="KeyS"&&!H.repeat&&(H.preventDefault(),j.current?.())};return document.addEventListener("keydown",U),()=>document.removeEventListener("keydown",U)},B=[],t[12]=R,t[13]=B):(R=t[12],B=t[13]),E.useEffect(R,B);const P=d;let T;t[14]!==f||t[15]!==d?(T={virtualMcpId:d,entity:f},t[14]=f,t[15]=d,t[16]=T):T=t[16];const S=T;if(u.status==="creating"||u.status==="loading"){let U;t[17]===Symbol.for("react.memo_cache_sentinel")?(U=n.jsx("div",{className:"flex-1 min-h-0 pr-1.5 pb-1.5 overflow-hidden",children:n.jsxs("div",{className:"flex h-full items-center justify-center bg-background card-shadow rounded-[0.75rem] text-sm text-muted-foreground",children:[n.jsx(Ce,{className:"size-4 animate-spin mr-2"}),"Creating task…"]})}),t[17]=U):U=t[17];let H;return t[18]!==S?(H=n.jsx(Hs,{value:S,children:U}),t[18]=S,t[19]=H):H=t[19],H}if(u.status==="error"){let U;t[20]===Symbol.for("react.memo_cache_sentinel")?(U=n.jsx("div",{className:"font-medium",children:"Task unavailable"}),t[20]=U):U=t[20];let H;t[21]!==u.error.message?(H=n.jsx("div",{className:"flex-1 min-h-0 pr-1.5 pb-1.5 overflow-hidden",children:n.jsxs("div",{className:"flex flex-col h-full items-center justify-center gap-2 bg-background card-shadow rounded-[0.75rem] p-8 text-sm",children:[U,n.jsx("div",{className:"text-muted-foreground",children:u.error.message})]})}),t[21]=u.error.message,t[22]=H):H=t[22];let X;return t[23]!==S||t[24]!==H?(X=n.jsx(Hs,{value:S,children:H}),t[23]=S,t[24]=H,t[25]=X):X=t[25],X}if(!f){let U;t[26]===Symbol.for("react.memo_cache_sentinel")?(U=n.jsx(Ui,{size:48,className:"text-muted-foreground"}),t[26]=U):U=t[26];const H=`The agent "${d}" does not exist in this organization.`;let X;t[27]!==s||t[28]!==a?(X=n.jsx(re,{variant:"outline",onClick:()=>s({to:"/$org",params:{org:a}}),children:"Go to organization home"}),t[27]=s,t[28]=a,t[29]=X):X=t[29];let oe;t[30]!==H||t[31]!==X?(oe=n.jsx("div",{className:"flex-1 min-h-0 pr-1.5 pb-1.5 overflow-hidden",children:n.jsx("div",{className:"flex flex-col h-full bg-background overflow-hidden card-shadow rounded-[0.75rem]",children:n.jsx(Er,{image:U,title:"Agent not found",description:H,actions:X})})}),t[30]=H,t[31]=X,t[32]=oe):oe=t[32];let L;return t[33]!==S||t[34]!==oe?(L=n.jsx(Hs,{value:S,children:oe}),t[33]=S,t[34]=oe,t[35]=L):L=t[35],L}if(e){let U;t[36]===Symbol.for("react.memo_cache_sentinel")?(U=n.jsx(kf,{className:"sr-only",children:"Navigation"}),t[36]=U):U=t[36];let H;t[37]!==C?(H=n.jsxs(jf,{side:"left",hideCloseButton:!0,className:"w-[calc(100vw-3rem)] sm:max-w-md! p-0",children:[U,n.jsx("div",{className:"flex h-full",children:n.jsx("div",{className:"w-full bg-sidebar flex flex-col overflow-y-auto group/sidebar","data-state":"expanded",children:n.jsx(wf,{onClose:()=>C(!1)})})})]}),t[37]=C,t[38]=H):H=t[38];let X;t[39]!==w||t[40]!==C||t[41]!==H?(X=n.jsx(Nf,{open:w,onOpenChange:C,children:H}),t[39]=w,t[40]=C,t[41]=H,t[42]=X):X=t[42];const oe=X,L=u.status==="ready"?u.task:null,se=f?.metadata?.sandboxMap;let ee;t[43]!==x.createNewTask?(ee=n.jsx(Pc,{onNewTaskRef:j,createNewTask:x.createNewTask}),t[43]=x.createNewTask,t[44]=ee):ee=t[44];let Q;t[45]!==C?(Q=()=>C(!0),t[45]=C,t[46]=Q):Q=t[46];let O;t[47]!==P||t[48]!==f||t[49]!==v||t[50]!==x.createNewTask||t[51]!==x.mainOpen||t[52]!==x.taskId||t[53]!==x.toggleMain||t[54]!==Q?(O=n.jsx(W2,{onOpenSidebar:Q,virtualMcpId:P,taskId:x.taskId,mainOpen:x.mainOpen,onToggleMain:x.toggleMain,onNewTask:x.createNewTask,entity:f,hasActiveGithubRepo:v}),t[47]=P,t[48]=f,t[49]=v,t[50]=x.createNewTask,t[51]=x.mainOpen,t[52]=x.taskId,t[53]=x.toggleMain,t[54]=Q,t[55]=O):O=t[55];let ce;t[56]===Symbol.for("react.memo_cache_sentinel")?(ce=n.jsx(Oe.Skeleton,{}),t[56]=ce):ce=t[56];let ue;t[57]!==P||t[58]!==x.mainOpen||t[59]!==x.taskId?(ue=n.jsx(E.Suspense,{fallback:ce,children:n.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:x.mainOpen?n.jsx(Ut,{fallback:n.jsx("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:"Something went wrong. Try refreshing."}),children:n.jsx(E.Suspense,{fallback:n.jsx("div",{className:"h-full flex items-center justify-center",children:n.jsx(Ce,{size:20,className:"animate-spin text-muted-foreground"})}),children:n.jsx(bu,{taskId:x.taskId,virtualMcpId:P})})}):n.jsx(Rc,{})})}),t[57]=P,t[58]=x.mainOpen,t[59]=x.taskId,t[60]=ue):ue=t[60];let fe;t[61]!==x.taskId||t[62]!==O||t[63]!==ue?(fe=n.jsxs(Oe.ActiveTaskProvider,{taskId:x.taskId,children:[O,ue]},x.taskId),t[61]=x.taskId,t[62]=O,t[63]=ue,t[64]=fe):fe=t[64];let q;t[65]!==v||t[66]!==oe||t[67]!==se||t[68]!==ee||t[69]!==fe||t[70]!==d?(q=n.jsxs(Dc,{virtualMcpId:d,hasActiveGithubRepo:v,sandboxMap:se,children:[ee,fe,oe]}),t[65]=v,t[66]=oe,t[67]=se,t[68]=ee,t[69]=fe,t[70]=d,t[71]=q):q=t[71];let te;t[72]!==P||t[73]!==L||t[74]!==q?(te=n.jsx("div",{className:"flex flex-col flex-1 min-w-0 bg-background min-h-0",children:n.jsx(Oe.Provider,{virtualMcpId:P,task:L,children:q},P)}),t[72]=P,t[73]=L,t[74]=q,t[75]=te):te=t[75];let me;return t[76]!==S||t[77]!==te?(me=n.jsx(Hs,{value:S,children:te}),t[76]=S,t[77]=te,t[78]=me):me=t[78],me}let k;t[79]!==x.chatOpen||t[80]!==x.createNewTask||t[81]!==x.toggleChat?(k=n.jsx(Hn.Toggles,{children:n.jsx(f2,{chatOpen:x.chatOpen,toggleChat:x.toggleChat,onNewTask:x.createNewTask})}),t[79]=x.chatOpen,t[80]=x.createNewTask,t[81]=x.toggleChat,t[82]=k):k=t[82];const I=u.status==="ready"?u.task:null,N=f?.metadata?.sandboxMap;let A;t[83]!==x.taskId||t[84]!==d?(A=n.jsx(Hn.Tabs,{children:n.jsx(yu,{virtualMcpId:d,taskId:x.taskId})}),t[83]=x.taskId,t[84]=d,t[85]=A):A=t[85];let M;t[86]!==x.createNewTask?(M=n.jsx(Pc,{onNewTaskRef:j,createNewTask:x.createNewTask}),t[86]=x.createNewTask,t[87]=M):M=t[87];let D;t[88]!==f?(D=n.jsx(Cu,{virtualMcp:f}),t[88]=f,t[89]=D):D=t[89];let $;t[90]===Symbol.for("react.memo_cache_sentinel")?($=n.jsx(Oe.Skeleton,{}),t[90]=$):$=t[90];let z;t[91]===Symbol.for("react.memo_cache_sentinel")?(z=n.jsx(Rc,{}),t[91]=z):z=t[91];let W;t[92]!==x.chatOpen||t[93]!==x.mainOpen||t[94]!==x.taskId||t[95]!==d?(W=n.jsx(E.Suspense,{fallback:$,children:n.jsx(u2,{virtualMcpId:d,taskId:x.taskId,chatOpen:x.chatOpen,mainOpen:x.mainOpen,chatContent:z})}),t[92]=x.chatOpen,t[93]=x.mainOpen,t[94]=x.taskId,t[95]=d,t[96]=W):W=t[96];let F;t[97]!==x.taskId||t[98]!==D||t[99]!==W?(F=n.jsxs(Oe.ActiveTaskProvider,{taskId:x.taskId,children:[D,W]},x.taskId),t[97]=x.taskId,t[98]=D,t[99]=W,t[100]=F):F=t[100];let V;t[101]!==v||t[102]!==N||t[103]!==A||t[104]!==M||t[105]!==F||t[106]!==d?(V=n.jsxs(Dc,{virtualMcpId:d,hasActiveGithubRepo:v,sandboxMap:N,children:[A,M,F]}),t[101]=v,t[102]=N,t[103]=A,t[104]=M,t[105]=F,t[106]=d,t[107]=V):V=t[107];let J;t[108]!==P||t[109]!==I||t[110]!==V?(J=n.jsx(Oe.Provider,{virtualMcpId:P,task:I,children:V},P),t[108]=P,t[109]=I,t[110]=V,t[111]=J):J=t[111];let Y;return t[112]!==S||t[113]!==J||t[114]!==k?(Y=n.jsx("div",{className:"flex-1 min-w-0 flex flex-col",children:n.jsxs(Hs,{value:S,children:[k,J]})}),t[112]=S,t[113]=J,t[114]=k,t[115]=Y):Y=t[115],Y}function K2(){const t=K.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=n.jsx(E.Suspense,{fallback:n.jsx(Sf,{}),children:n.jsx(U2,{})}),t[0]=e):e=t[0],e}const xk=Object.freeze(Object.defineProperty({__proto__:null,default:K2,useInsetContext:sr},Symbol.toStringTag,{value:"Module"}));export{gd as $,dk as A,WC as B,ZC as C,rk as D,ax as E,ik as F,OC as G,YC as H,JC as I,GC as J,sx as K,ud as L,KC as M,Eh as N,VC as O,on as P,uk as Q,sk as R,Th as S,a1 as T,tk as U,fk as V,S_ as W,ak as X,MC as Y,LC as Z,nl as _,fa as a,lk as a0,ck as a1,Lh as a2,Yn as a3,$C as a4,zC as a5,FC as a6,wu as a7,jv as a8,br as a9,W1 as aa,Xn as ab,Px as ac,_k as ad,Ax as ae,yd as af,pk as ag,kl as ah,mk as ai,xk as aj,Xi as b,nk as c,UC as d,da as e,HC as f,Ca as g,U1 as h,es as i,va as j,P_ as k,zr as l,Fh as m,Ih as n,qC as o,pd as p,QC as q,XC as r,ix as s,Mx as t,ha as u,Ji as v,hk as w,ek as x,ok as y,fx as z};
|