decocms 2.276.3 → 2.277.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (193) hide show
  1. package/dist/client/assets/{AlertCircle-B4Z_bYRy.js → AlertCircle-CDrkM01U.js} +1 -1
  2. package/dist/client/assets/{ArrowNarrowLeft-Cfmub-b9.js → ArrowNarrowLeft-D40KhznE.js} +1 -1
  3. package/dist/client/assets/{CheckCircle-BCmdWySf.js → CheckCircle-BTIsSwsN.js} +1 -1
  4. package/dist/client/assets/{ChevronDown-LbB92Eif.js → ChevronDown-CYdW9NBw.js} +1 -1
  5. package/dist/client/assets/{ChevronRight-Bp2wM59-.js → ChevronRight-YkSQYi3B.js} +1 -1
  6. package/dist/client/assets/{ChevronUp-DugRD1Os.js → ChevronUp-BcPC1hCC.js} +1 -1
  7. package/dist/client/assets/{Container-4EEqLr04.js → Container-ChD3KoS4.js} +1 -1
  8. package/dist/client/assets/{LinkExternal01-n0OTj3Hs.js → LinkExternal01-l0w4_WlJ.js} +1 -1
  9. package/dist/client/assets/{Lock01-Bcc8tT2X.js → Lock01-CmojMPTn.js} +1 -1
  10. package/dist/client/assets/{Palette-DJlRra7b.js → Palette-D4s8zWmN.js} +1 -1
  11. package/dist/client/assets/{Play-DE1MmEh7.js → Play-CiTVDuYt.js} +1 -1
  12. package/dist/client/assets/{Plus-lTLN-5sW.js → Plus-CVdax6FK.js} +1 -1
  13. package/dist/client/assets/{SearchMd-Ch9A9-sY.js → SearchMd-DJ0JdIz3.js} +1 -1
  14. package/dist/client/assets/{Settings02-CRSd_kje.js → Settings02-D-hypCbK.js} +1 -1
  15. package/dist/client/assets/{Star01-jT36fQMs.js → Star01-Vcjv0Tzc.js} +1 -1
  16. package/dist/client/assets/{Sun-BjJ31DgB.js → Sun-51uZR1E5.js} +1 -1
  17. package/dist/client/assets/{Tool01-BABHhadV.js → Tool01-DCaYwllU.js} +1 -1
  18. package/dist/client/assets/{Trash01-qTBTo_1R.js → Trash01-D5ZS0TOT.js} +1 -1
  19. package/dist/client/assets/{Upload01-D584ZGhL.js → Upload01-CBYhGwn0.js} +1 -1
  20. package/dist/client/assets/{User01-Dn7ERaE8.js → User01-Dq3q9cE-.js} +1 -1
  21. package/dist/client/assets/{Users03-CLsqBvj5.js → Users03-BIYd5t8v.js} +1 -1
  22. package/dist/client/assets/{X-DbufVvYT.js → X-D_4PiiTE.js} +1 -1
  23. package/dist/client/assets/{XCircle-CMz1Sln8.js → XCircle-rGav0QLs.js} +1 -1
  24. package/dist/client/assets/{Zap-DCaRrmPx.js → Zap-qFCEz_qt.js} +1 -1
  25. package/dist/client/assets/{ZapSquare-DOWrBmYM.js → ZapSquare-BYfCzFpy.js} +1 -1
  26. package/dist/client/assets/{accordion-BM2v3K-F.js → accordion-C_FjDGY7.js} +1 -1
  27. package/dist/client/assets/{agent-icon-WnDt_mly.js → agent-icon-31CiXnkF.js} +1 -1
  28. package/dist/client/assets/{agents-list-B15lvUTv.js → agents-list-kGMjebHK.js} +1 -1
  29. package/dist/client/assets/ai-providers-Bykzb-xW.js +1 -0
  30. package/dist/client/assets/{alert-dialog-BGXEvrTS.js → alert-dialog-BpydK2MI.js} +1 -1
  31. package/dist/client/assets/{auth-catchall-BhYcp03z.js → auth-catchall-I0vdEcHs.js} +1 -1
  32. package/dist/client/assets/{automation-list-row-CzwsnIcA.js → automation-list-row-mTTWiKQ6.js} +1 -1
  33. package/dist/client/assets/{automations-BleBenZq.js → automations-Z179s9qX.js} +1 -1
  34. package/dist/client/assets/{avatar-B6IagwQu.js → avatar-BVvDTfBW.js} +1 -1
  35. package/dist/client/assets/{badge-CYgBI6R4.js → badge-BhfSxzi-.js} +1 -1
  36. package/dist/client/assets/{brand-context-kUM9sJBK.js → brand-context-Bn_7uvJT.js} +1 -1
  37. package/dist/client/assets/{card-CDkIOtIp.js → card-BAp6Jwgi.js} +1 -1
  38. package/dist/client/assets/{chat-context-DeS_zKzS.js → chat-context-Dp5HM8R-.js} +1 -1
  39. package/dist/client/assets/{checkbox-B1ZvEQ9K.js → checkbox-BhkHXCse.js} +1 -1
  40. package/dist/client/assets/{collection-detail-C4RjlFe9.js → collection-detail-Bm3mvhEG.js} +1 -1
  41. package/dist/client/assets/{collection-display-button-BYlepxvt.js → collection-display-button-jqECsu1f.js} +1 -1
  42. package/dist/client/assets/{collection-search-BaDjhV61.js → collection-search-C0B93tJw.js} +1 -1
  43. package/dist/client/assets/{collection-table-wrapper-BtJe8KWC.js → collection-table-wrapper-Bf17fkBP.js} +1 -1
  44. package/dist/client/assets/{collection-tabs-B5daS-aK.js → collection-tabs-CMC3SILy.js} +1 -1
  45. package/dist/client/assets/{collections-CnDJSz0t.js → collections-DIuw_dNV.js} +1 -1
  46. package/dist/client/assets/{command-CVgGbZrE.js → command-CRMnQTof.js} +1 -1
  47. package/dist/client/assets/{connection-card-DAXfCJL1.js → connection-card-CJ6uOT9E.js} +1 -1
  48. package/dist/client/assets/{connection-detail-0iVaAltH.js → connection-detail-Dj-OLW3C.js} +1 -1
  49. package/dist/client/assets/{connection-form-helpers-BK0aECJK.js → connection-form-helpers-CDPt3S_P.js} +1 -1
  50. package/dist/client/assets/{connections-CPgxORLh.js → connections-aYS5E8PJ.js} +1 -1
  51. package/dist/client/assets/{constants-BxY9N-ws.js → constants-BG70AVFL.js} +1 -1
  52. package/dist/client/assets/{constants-MEMD8ENM.js → constants-CdNdiXMf.js} +1 -1
  53. package/dist/client/assets/{dialog-D8xpcPd2.js → dialog-C0FUDu40.js} +1 -1
  54. package/dist/client/assets/{drawer-BpOYQqLe.js → drawer-D4_wXu6X.js} +1 -1
  55. package/dist/client/assets/{dropdown-menu-ClMXG_z6.js → dropdown-menu-aG44dJsz.js} +1 -1
  56. package/dist/client/assets/{dynamic-plugin-layout-BDs8LP0t.js → dynamic-plugin-layout-pzG9mWCw.js} +1 -1
  57. package/dist/client/assets/{empty-state-DlH6Q1vv.js → empty-state-BGqwS_3w.js} +1 -1
  58. package/dist/client/assets/{empty-state-DqQ_mj5B.js → empty-state-BjAjwUcB.js} +1 -1
  59. package/dist/client/assets/{extract-connection-data-BattRyEN.js → extract-connection-data-CAAXAkZY.js} +1 -1
  60. package/dist/client/assets/{features-BgwyDCES.js → features-DCfAHIGS.js} +1 -1
  61. package/dist/client/assets/{form-pojp-kTY.js → form-BQFhlKGv.js} +1 -1
  62. package/dist/client/assets/{general-AROtMABc.js → general-0YlUSUig.js} +1 -1
  63. package/dist/client/assets/{index-DiAp1HHT.js → index-BRiQU6du.js} +1 -1
  64. package/dist/client/assets/{index-CtnGGdXo.js → index-C6SXa4V4.js} +1 -1
  65. package/dist/client/assets/{index-DY2kqbCP.js → index-CEQG3Gi2.js} +1 -1
  66. package/dist/client/assets/{index-C3NVKlFX.js → index-CIlSPTSj.js} +1 -1
  67. package/dist/client/assets/{index-BSxLmbjR.js → index-CN1oVHjb.js} +23 -23
  68. package/dist/client/assets/{index-DIVxtkpR.js → index-CoTOPljc.js} +1 -1
  69. package/dist/client/assets/{index-BFVdz8if.js → index-DRjT3wqk.js} +1 -1
  70. package/dist/client/assets/{index-WGfZydLo.js → index-EE9r4ne7.js} +2 -2
  71. package/dist/client/assets/{index-B2JtGbgE.js → index-NYDZhYFt.js} +1 -1
  72. package/dist/client/assets/{index-Coav-ncz.js → index-mdSoEPSF.js} +1 -1
  73. package/dist/client/assets/{infiniteQueryObserver-CdZ0ASHN.js → infiniteQueryObserver-BQYXKuj2.js} +1 -1
  74. package/dist/client/assets/{input-Bzj33Fxq.js → input-r_oEqK-V.js} +1 -1
  75. package/dist/client/assets/{integration-icon-ZjWVueCq.js → integration-icon-BKKqOsd5.js} +1 -1
  76. package/dist/client/assets/{label-DiBCBN0N.js → label-CenAgqhm.js} +1 -1
  77. package/dist/client/assets/{layout-BXIOD6PJ.js → layout-DB6YepVn.js} +1 -1
  78. package/dist/client/assets/{lean-canvas-recruit-modal-BL32AVEC.js → lean-canvas-recruit-modal-TnasvQfT.js} +1 -1
  79. package/dist/client/assets/{login-CXDNRsDi.js → login-DDMVtz0x.js} +1 -1
  80. package/dist/client/assets/{members-DVaoQxs-.js → members-BH6aFn0i.js} +1 -1
  81. package/dist/client/assets/{monaco-editor-lqRUssyU.js → monaco-editor-C3TYqqnp.js} +1 -1
  82. package/dist/client/assets/{monitoring-stats-row-BcGs8N45.js → monitoring-stats-row-DosCpU_L.js} +1 -1
  83. package/dist/client/assets/{oauth-callback-C20Tc5eT.js → oauth-callback-BV7Kg1aN.js} +1 -1
  84. package/dist/client/assets/{oauth-callback-ai-provider-CHWLGFFS.js → oauth-callback-ai-provider-DjkxS6zo.js} +1 -1
  85. package/dist/client/assets/{onboarding-AqO1F9Ot.js → onboarding-DmzJa5qN.js} +1 -1
  86. package/dist/client/assets/{org-layout-GwZNK-gH.js → org-layout-D05CVA_8.js} +1 -1
  87. package/dist/client/assets/{org-plugin-layout-DiKymIqI.js → org-plugin-layout-Cv_313Tb.js} +1 -1
  88. package/dist/client/assets/{plugin-empty-state-BmbedKr8.js → plugin-empty-state-CQeGBgOP.js} +1 -1
  89. package/dist/client/assets/{plugin-header-5ddC-K4s.js → plugin-header-BXYsY1_p.js} +1 -1
  90. package/dist/client/assets/{plugin-layout-ZLFaNfn_.js → plugin-layout-Do_Ws-WY.js} +1 -1
  91. package/dist/client/assets/{popover-DB3l_dUB.js → popover-BktSfQG9.js} +1 -1
  92. package/dist/client/assets/{profile-BXxzRaC3.js → profile-BSS2RbEG.js} +1 -1
  93. package/dist/client/assets/{project-app-view-CLbmaYfp.js → project-app-view-B_z1QorU.js} +1 -1
  94. package/dist/client/assets/registry-B_QfL3wE.js +2 -0
  95. package/dist/client/assets/{registry-layout-Bcu6gWnT.js → registry-layout-B0UM9hrK.js} +1 -1
  96. package/dist/client/assets/{required-auth-layout-DXAKQPxa.js → required-auth-layout-C6TLzB3T.js} +1 -1
  97. package/dist/client/assets/{reset-password-BgkjBAas.js → reset-password-BV1UW9SB.js} +1 -1
  98. package/dist/client/assets/{scroll-area-Df4WEHfA.js → scroll-area-C6ws31M0.js} +1 -1
  99. package/dist/client/assets/{search-input-BgrLZ0dV.js → search-input-Dxw50-Fc.js} +1 -1
  100. package/dist/client/assets/{select-DMGlO4yi.js → select-DMKL-iI9.js} +1 -1
  101. package/dist/client/assets/select-model-D2d213qn.js +4 -0
  102. package/dist/client/assets/{settings-layout-DGJoyTnE.js → settings-layout-BBdiRp4e.js} +1 -1
  103. package/dist/client/assets/{shell-layout-DjJ6Z_Cf.js → shell-layout-CDe1Q4z8.js} +1 -1
  104. package/dist/client/assets/{skeleton-CAEDpRxb.js → skeleton-C8k5qVSG.js} +1 -1
  105. package/dist/client/assets/{sso-D1MeHfxN.js → sso-CChrq6HN.js} +1 -1
  106. package/dist/client/assets/{store-C324vYbF.js → store-Dk4svl-0.js} +1 -1
  107. package/dist/client/assets/store-registry-DNqLsJlQ.js +2 -0
  108. package/dist/client/assets/{switch-DjEl0Zkr.js → switch-BlmZa3uf.js} +1 -1
  109. package/dist/client/assets/{table-DAEmh2te.js → table-omg9OiL8.js} +1 -1
  110. package/dist/client/assets/{tabs-3MozWL7O.js → tabs-ZI6fRQkw.js} +1 -1
  111. package/dist/client/assets/{task-status-DlDVvsLX.js → task-status-erNd2Sbl.js} +1 -1
  112. package/dist/client/assets/{textarea-CfqOOIJa.js → textarea-CpW5pfml.js} +1 -1
  113. package/dist/client/assets/{toggle-group-CNs9-MRq.js → toggle-group-By5F9baT.js} +1 -1
  114. package/dist/client/assets/{tools-list-Bc5Oy8LD.js → tools-list-2T2hc8nL.js} +1 -1
  115. package/dist/client/assets/{types-D_q3jEZ8.js → types-BOQuLrVp.js} +1 -1
  116. package/dist/client/assets/{use-ai-providers-StUHlUMB.js → use-ai-providers-CITI1iNq.js} +1 -1
  117. package/dist/client/assets/{use-collections-DEST7K_q.js → use-collections-CRzXRke9.js} +1 -1
  118. package/dist/client/assets/{use-connection-CbAQnOed.js → use-connection-CeSGdaGP.js} +1 -1
  119. package/dist/client/assets/{use-copy-Cl4ZPEvD.js → use-copy-DGEKKbaG.js} +1 -1
  120. package/dist/client/assets/{use-create-virtual-mcp-CwozrztD.js → use-create-virtual-mcp-UIh1S6RD.js} +1 -1
  121. package/dist/client/assets/{use-decopilot-events-K_yfq6tB.js → use-decopilot-events-CN7YV5I-.js} +1 -1
  122. package/dist/client/assets/{use-delete-connection-BjsFe5Xj.js → use-delete-connection-DeXytvwf.js} +1 -1
  123. package/dist/client/assets/{use-infinite-scroll-BCfAtSyW.js → use-infinite-scroll-DjXaeUEQ.js} +1 -1
  124. package/dist/client/assets/{use-list-state-Dk_FNgfa.js → use-list-state-UZMoJUvO.js} +1 -1
  125. package/dist/client/assets/{use-mcp-tools-BtTkT0ox.js → use-mcp-tools-BKQPDk4x.js} +1 -1
  126. package/dist/client/assets/{use-members-DVLjy3CZ.js → use-members-afZV5Me8.js} +1 -1
  127. package/dist/client/assets/{use-mobile-vpGkifWc.js → use-mobile-DP4MR1ix.js} +1 -1
  128. package/dist/client/assets/{use-navigate-to-agent-Dg-q0ecS.js → use-navigate-to-agent-C0iuNKaP.js} +1 -1
  129. package/dist/client/assets/{use-org-sso-DK-UaGWB.js → use-org-sso-B4mWsSMh.js} +1 -1
  130. package/dist/client/assets/{use-organization-settings-D9EGsoNi.js → use-organization-settings-CcvcpCtE.js} +1 -1
  131. package/dist/client/assets/{use-registry-connections-CjUJFqM_.js → use-registry-connections-Bj_DPVwf.js} +1 -1
  132. package/dist/client/assets/{use-status-sounds-CuOzTU0E.js → use-status-sounds-ChUYFOhF.js} +1 -1
  133. package/dist/client/assets/{use-tasks-Cf8x3tn2.js → use-tasks-DGmrkFpo.js} +1 -1
  134. package/dist/client/assets/{use-view-mode-Cz3j5joy.js → use-view-mode-zFqL6G4U.js} +1 -1
  135. package/dist/client/assets/{use-virtual-mcp-DJidRNsl.js → use-virtual-mcp-Dn9ixQmR.js} +1 -1
  136. package/dist/client/assets/useInfiniteQuery-7hq96Va6.js +1 -0
  137. package/dist/client/assets/{user-DJ61KCKE.js → user-D7q59BB0.js} +1 -1
  138. package/dist/client/assets/{view-mode-toggle-D3cr4bdy.js → view-mode-toggle-BTfIGFL4.js} +1 -1
  139. package/dist/client/assets/{workflow-BJJzWzRg.js → workflow-DXb2lFI1.js} +1 -1
  140. package/dist/client/assets/workflow-detail-CC_ctEsy.js +1 -0
  141. package/dist/client/index.html +1 -1
  142. package/dist/server/cli.js +166 -166
  143. package/dist/server/node_modules/pg/LICENSE +21 -0
  144. package/dist/server/node_modules/pg/README.md +95 -0
  145. package/dist/server/node_modules/pg/esm/index.mjs +20 -0
  146. package/dist/server/node_modules/pg/lib/client.js +743 -0
  147. package/dist/server/node_modules/pg/lib/connection-parameters.js +171 -0
  148. package/dist/server/node_modules/pg/lib/connection.js +221 -0
  149. package/dist/server/node_modules/pg/lib/crypto/cert-signatures.js +122 -0
  150. package/dist/server/node_modules/pg/lib/crypto/sasl.js +212 -0
  151. package/dist/server/node_modules/pg/lib/crypto/utils-legacy.js +43 -0
  152. package/dist/server/node_modules/pg/lib/crypto/utils-webcrypto.js +89 -0
  153. package/dist/server/node_modules/pg/lib/crypto/utils.js +9 -0
  154. package/dist/server/node_modules/pg/lib/defaults.js +91 -0
  155. package/dist/server/node_modules/pg/lib/index.js +73 -0
  156. package/dist/server/node_modules/pg/lib/native/client.js +323 -0
  157. package/dist/server/node_modules/pg/lib/native/index.js +2 -0
  158. package/dist/server/node_modules/pg/lib/native/query.js +165 -0
  159. package/dist/server/node_modules/pg/lib/query.js +252 -0
  160. package/dist/server/node_modules/pg/lib/result.js +109 -0
  161. package/dist/server/node_modules/pg/lib/stream.js +83 -0
  162. package/dist/server/node_modules/pg/lib/type-overrides.js +35 -0
  163. package/dist/server/node_modules/pg/lib/utils.js +217 -0
  164. package/dist/server/node_modules/pg/package.json +76 -0
  165. package/dist/server/node_modules/xtend/.jshintrc +30 -0
  166. package/dist/server/node_modules/{deepmerge/license.txt → xtend/LICENSE} +1 -2
  167. package/dist/server/node_modules/xtend/README.md +32 -0
  168. package/dist/server/node_modules/xtend/immutable.js +19 -0
  169. package/dist/server/node_modules/xtend/mutable.js +17 -0
  170. package/dist/server/node_modules/xtend/package.json +55 -0
  171. package/dist/server/node_modules/xtend/test.js +103 -0
  172. package/package.json +1 -1
  173. package/dist/client/assets/ai-providers-B3rFYyQJ.js +0 -1
  174. package/dist/client/assets/registry-h9nbKgtr.js +0 -2
  175. package/dist/client/assets/select-model-D4EGus9X.js +0 -4
  176. package/dist/client/assets/store-registry-DkhNudAU.js +0 -2
  177. package/dist/client/assets/useInfiniteQuery-ChHJkjep.js +0 -1
  178. package/dist/client/assets/workflow-detail-CPLNyuzk.js +0 -1
  179. package/dist/server/node_modules/deepmerge/.editorconfig +0 -7
  180. package/dist/server/node_modules/deepmerge/.eslintcache +0 -1
  181. package/dist/server/node_modules/deepmerge/changelog.md +0 -167
  182. package/dist/server/node_modules/deepmerge/dist/cjs.js +0 -133
  183. package/dist/server/node_modules/deepmerge/dist/umd.js +0 -139
  184. package/dist/server/node_modules/deepmerge/index.d.ts +0 -20
  185. package/dist/server/node_modules/deepmerge/index.js +0 -106
  186. package/dist/server/node_modules/deepmerge/package.json +0 -42
  187. package/dist/server/node_modules/deepmerge/readme.md +0 -264
  188. package/dist/server/node_modules/deepmerge/rollup.config.js +0 -22
  189. package/dist/server/node_modules/onetime/index.d.ts +0 -64
  190. package/dist/server/node_modules/onetime/index.js +0 -44
  191. package/dist/server/node_modules/onetime/license +0 -9
  192. package/dist/server/node_modules/onetime/package.json +0 -43
  193. package/dist/server/node_modules/onetime/readme.md +0 -94
@@ -1,7 +1,7 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/project-app-view-CLbmaYfp.js","assets/index-WGfZydLo.js","assets/index-B2LlXg0m.css","assets/task-status-DlDVvsLX.js","assets/agent-icon-WnDt_mly.js","assets/AlertCircle-B4Z_bYRy.js","assets/Tool01-BABHhadV.js","assets/SearchMd-Ch9A9-sY.js","assets/ArrowNarrowLeft-Cfmub-b9.js","assets/XCircle-CMz1Sln8.js","assets/ZapSquare-DOWrBmYM.js","assets/Users03-CLsqBvj5.js","assets/CheckCircle-BCmdWySf.js","assets/ChevronDown-LbB92Eif.js","assets/ChevronRight-Bp2wM59-.js","assets/ChevronUp-DugRD1Os.js","assets/Container-4EEqLr04.js","assets/Star01-jT36fQMs.js","assets/Palette-DJlRra7b.js","assets/index-DiAp1HHT.js","assets/use-mobile-vpGkifWc.js","assets/X-DbufVvYT.js","assets/LinkExternal01-n0OTj3Hs.js","assets/Lock01-Bcc8tT2X.js","assets/Sun-BjJ31DgB.js","assets/Play-DE1MmEh7.js","assets/Plus-lTLN-5sW.js","assets/Settings02-CRSd_kje.js","assets/Trash01-qTBTo_1R.js","assets/Upload01-D584ZGhL.js","assets/User01-Dn7ERaE8.js","assets/Zap-DCaRrmPx.js","assets/scroll-area-Df4WEHfA.js","assets/select-DMGlO4yi.js","assets/use-copy-Cl4ZPEvD.js","assets/differenceInSeconds-NQ4PDo0z.js","assets/dialog-D8xpcPd2.js","assets/content-blocks-o63cs2vh.js","assets/types-D_q3jEZ8.js","assets/constants-MEMD8ENM.js","assets/chat-context-DeS_zKzS.js","assets/use-virtual-mcp-DJidRNsl.js","assets/use-collections-DEST7K_q.js","assets/use-ai-providers-StUHlUMB.js","assets/use-decopilot-events-K_yfq6tB.js","assets/create-sse-subscription-CxkOgzKf.js","assets/use-tasks-Cf8x3tn2.js","assets/use-organization-settings-D9EGsoNi.js","assets/shell-layout-DjJ6Z_Cf.js","assets/required-auth-layout-DXAKQPxa.js","assets/use-org-sso-DK-UaGWB.js","assets/integration-icon-ZjWVueCq.js","assets/use-mcp-tools-BtTkT0ox.js"])))=>i.map(i=>d[i]);
2
- import{o as Mt,r as S,p as Bm,q as Om,e as B,s as be,K as lt,n as Fi,a as Br,v as Vs,w as Or,x as Hi,j as r,B as ne,y as Et,c as X,E as Cs,z as ge,C as Wi,_ as $m,t as se,f as Ke,D as yh,F as zm,R as Sh,G as Fm,H as ys,I as So,J as ds,L as Hm,M as wo,P as Wm,Q as Um,T as Km,U as qm,V as wh,W as Gm,X as Ym,Y as Xm,Z as Jm,$ as lc,l as Ee,b as St,u as Qm,a0 as pr,a1 as vn,a2 as nl,a3 as ol,g as $r,a4 as Vh,d as vi,a5 as Zm,a6 as ep,a7 as tp,a8 as sp,a9 as Ch,aa as jh,ab as ip,ac as rp,ad as np,ae as Ft,af as op,ag as ap,ah as lp,ai as cp,aj as Zi,ak as dp,al as hp,am as up,an as fp,ao as kh,ap as mp,aq as pp,ar as gp,as as _p,at as xp,au as vp,av as bp,aw as yp,ax as Sp,ay as wp,az as Nh,aA as bn,aB as Vp,aC as Ai,aD as nn,aE as Ah,aF as Cp,aG as jp}from"./index-WGfZydLo.js";import{u as ni,a as Ui,b as es,A as kp,C as Np,c as ia,d as Ap,e as Zn,f as cc,t as Ep}from"./chat-context-DeS_zKzS.js";import{d as eo,g as si,c as Ip,s as al,t as Rp,a as Tp,M as Dp,i as Mp,b as Cr,e as Pp,F as Lp,f as Eh,S as Bp,u as Op,h as dc,j as $p,k as zp,l as ra,r as Fp,m as Hp,p as Ih,n as Wp,o as Up,q as ll,G as Kp,L as qp,v as Gp,w as Yp,x as Xp,y as Jp}from"./task-status-DlDVvsLX.js";import{S as jr,u as to,P as na,a as Qp,b as Zp,c as eg,E as tg,i as sg,d as ig,e as Rh}from"./scroll-area-Df4WEHfA.js";import{T as Mi,u as Rs,a as tt,b as st,c as it}from"./use-mobile-vpGkifWc.js";import{D as Ts,a as Ds,b as cl,c as ms,d as ps,e as dl}from"./dialog-D8xpcPd2.js";import{D as so,a as bi,b as yi,c as Si,d as rg,e as ng,f as og}from"./drawer-BpOYQqLe.js";import{C as Th}from"./collection-search-BaDjhV61.js";import{S as Wt,u as Me,g as io,i as Mn,c as ag,W as Os,a as lg,b as hl}from"./constants-MEMD8ENM.js";import{u as Dh,g as ul,T as Mh,a as yn,l as Pn,b as Vo,c as cg}from"./tabs-3MozWL7O.js";import{F as Pi,a as It,b as Rt,c as rs,d as Tt,e as Dt,f as dg}from"./form-pojp-kTY.js";import{I as bt}from"./input-Bzj33Fxq.js";import{i as Ph,u as zr,r as Lh}from"./shell-layout-DjJ6Z_Cf.js";import{D as ot,a as Sn,b as wn,c as js,d as ks,e as Ns,f as Bh,g as Oh,h as hc}from"./dropdown-menu-ClMXG_z6.js";import{t as hg,i as $h,n as ug,A as zs,a as zh,b as fl,s as ii,c as fg,d as mg,e as Fh,f as Hh,g as pg,h as ml,j as gr,k as gg,l as pl,m as _g,o as xg,p as Fr,q as Hr,r as vg,u as uc,v as fc,w as bg,x as yg,y as mc,z as Sg,B as gl,C as Wh,D as oa,E as Co,F as pc,G as wg,H as Vg,I as Cg,J as jg,K as Uh,L as Kh,M as qh,N as Gh,O as gc,P as kg,Q as _r,R as Ng,S as Ag,T as Eg,U as Yh}from"./agent-icon-WnDt_mly.js";import{n as Xh,a as aa,i as Ig,b as Rg,c as Tg}from"./ZapSquare-DOWrBmYM.js";import{i as Jt,t as kr}from"./ChevronDown-LbB92Eif.js";import{s as Ti}from"./Star01-jT36fQMs.js";import{a as la,t as _l}from"./Tool01-BABHhadV.js";import{i as Jh}from"./Lock01-Bcc8tT2X.js";import{s as Qt}from"./Plus-lTLN-5sW.js";import{i as Qh}from"./Upload01-D584ZGhL.js";import{i as fi}from"./X-DbufVvYT.js";import{i as ri}from"./AlertCircle-B4Z_bYRy.js";import{S as Js,a as Qs,b as Ht,c as Zs,d as ei}from"./select-DMGlO4yi.js";import{i as xl,a as vl,b as Dg}from"./SearchMd-Ch9A9-sY.js";import{i as ro,t as Mg,a as Pg,b as Lg,c as Bg,d as Og,e as Li,f as Zh}from"./XCircle-CMz1Sln8.js";import{T as eu,a as Ln}from"./toggle-group-CNs9-MRq.js";import{u as bl,a as tu}from"./use-ai-providers-StUHlUMB.js";import{m as no,M as su,N as $g}from"./select-model-D4EGus9X.js";import{S as zg,A as Fg,a as Hg,b as Wg,c as Ug,R as iu,d as Kg,e as qg}from"./accordion-BM2v3K-F.js";import{r as ru,l as xr,u as Gg,g as Yg}from"./types-D_q3jEZ8.js";import{u as oo,a as ts,b as yl}from"./use-virtual-mcp-DJidRNsl.js";import{u as Wr,a as Sl,b as wl}from"./use-connection-CbAQnOed.js";import{p as Xg,q as _c}from"./question-004-sINsf4GQ.js";import{g as xc}from"./ai-providers-logos-CS4PCiqI.js";import{g as nu,s as ou}from"./connection-slug-eyAPH6o3.js";import{u as au,a as lu,g as Jg,C as jo}from"./connection-card-DAXfCJL1.js";import{C as cu}from"./collection-tabs-B5daS-aK.js";import{g as du}from"./constants-BxY9N-ws.js";import{T as ca}from"./textarea-CfqOOIJa.js";import{n as Vn}from"./Container-4EEqLr04.js";import{c as Qg,i as on,a as vc,E as Zg,p as e_,b as t_,d as s_}from"./connection-form-helpers-BK0aECJK.js";import{u as bc}from"./use-infinite-scroll-BCfAtSyW.js";import{u as i_,C as r_,a as yc,b as Sc,c as n_,d as o_,e as a_,f as l_}from"./command-CVgGbZrE.js";import{g as c_,e as d_,a as h_}from"./extract-connection-data-BattRyEN.js";import{B as wc}from"./badge-CYgBI6R4.js";import{i as Vl}from"./ChevronRight-Bp2wM59-.js";import{I as Ms}from"./integration-icon-ZjWVueCq.js";import{S as Bi}from"./skeleton-CAEDpRxb.js";import{a as ao}from"./Users03-CLsqBvj5.js";import{I as Bn,S as hu,G as u_,L as f_,a as m_,b as uu}from"./lean-canvas-recruit-modal-BL32AVEC.js";import{u as lo,a as fu}from"./use-navigate-to-agent-Dg-q0ecS.js";import{u as mu}from"./use-create-virtual-mcp-CwozrztD.js";import{i as p_}from"./CheckCircle-BCmdWySf.js";import{P as oi,a as ai,b as li}from"./popover-DB3l_dUB.js";import{u as wi,a as g_}from"./use-mcp-tools-BtTkT0ox.js";import{E as Oi}from"./empty-state-DqQ_mj5B.js";import{u as __}from"./use-decopilot-events-K_yfq6tB.js";import{i as $i}from"./Zap-DCaRrmPx.js";import{i as pu,S as Ur,a as Kr,b as gs,u as qr,c as us,d as Zt,e as gu,f as _u,g as x_,h as xu,j as vu,P as hs,k as v_,l as b_,m as y_,n as S_,o as w_,p as V_}from"./index-DiAp1HHT.js";import{A as Vc}from"./avatar-B6IagwQu.js";import{n as C_,a as j_,i as k_}from"./Sun-BjJ31DgB.js";import{a as Gr}from"./Settings02-CRSd_kje.js";import{A as Cl,a as jl,b as kl,c as Nl,d as Al,e as El,f as Il,g as bu}from"./alert-dialog-BGXEvrTS.js";import"./index-C3NVKlFX.js";import{u as yu}from"./use-tasks-Cf8x3tn2.js";import{u as N_}from"./use-status-sounds-CuOzTU0E.js";import{T as A_,u as Su}from"./tools-list-Bc5Oy8LD.js";import{u as ko}from"./unwrap-tool-result-BYXdCQMg.js";import{C as E_,a as Cc}from"./card-CDkIOtIp.js";import{L as vr}from"./label-DiBCBN0N.js";import{S as da}from"./switch-DjEl0Zkr.js";import{i as Cn}from"./Play-DE1MmEh7.js";import{s as ha}from"./Trash01-qTBTo_1R.js";import{C as I_}from"./checkbox-B1ZvEQ9K.js";import{n as Vi}from"./LinkExternal01-n0OTj3Hs.js";import{V as R_}from"./view-mode-toggle-D3cr4bdy.js";import{U as T_}from"./user-DJ61KCKE.js";import{u as Yr,a as D_,b as M_,c as P_,A as L_,d as B_}from"./automation-list-row-CzwsnIcA.js";import{S as O_}from"./search-input-BgrLZ0dV.js";import"./use-collections-DEST7K_q.js";import"./use-organization-settings-D9EGsoNi.js";import"./use-copy-Cl4ZPEvD.js";import"./differenceInSeconds-NQ4PDo0z.js";import"./content-blocks-o63cs2vh.js";import"./required-auth-layout-DXAKQPxa.js";import"./use-org-sso-DK-UaGWB.js";import"./ArrowNarrowLeft-Cfmub-b9.js";import"./ChevronUp-DugRD1Os.js";import"./Palette-DJlRra7b.js";import"./User01-Dn7ERaE8.js";import"./formatDistanceToNow-Cb2QZZJn.js";import"./use-registry-connections-CjUJFqM_.js";import"./useInfiniteQuery-ChHJkjep.js";import"./infiniteQueryObserver-CdZ0ASHN.js";import"./collections-CnDJSz0t.js";import"./index-CtnGGdXo.js";import"./create-sse-subscription-CxkOgzKf.js";function $_(t,e){const s=Mt(e);return z_({filters:{...t,status:"pending"}},s).length}function jc(t,e){return t.findAll(e.filters).map(s=>e.select?e.select(s):s.state)}function z_(t={},e){const s=Mt(e).getMutationCache(),i=S.useRef(t),n=S.useRef(null);return n.current===null&&(n.current=jc(s,t)),S.useEffect(()=>{i.current=t}),S.useSyncExternalStore(S.useCallback(o=>s.subscribe(()=>{const a=Bm(n.current,jc(s,i.current));n.current!==a&&(n.current=a,Om.schedule(o))}),[s]),()=>n.current,()=>n.current)}function F_(t,e){const s=B.c(37),{org:i,locator:n}=be();let o;s[0]!==i.id?(o={connectionId:Wt,orgId:i.id},s[0]=i.id,s[1]=o):o=s[1];const a=Me(o),l=Mt();let c;s[2]!==t||s[3]!==i.id?(c=lt.ensureTask(i.id,t),s[2]=t,s[3]=i.id,s[4]=c):c=s[4];let d;s[5]!==a||s[6]!==t?(d=async()=>(await a.callTool({name:"COLLECTION_THREADS_GET",arguments:{id:t}})).structuredContent?.item??null,s[5]=a,s[6]=t,s[7]=d):d=s[7];let u;s[8]!==c||s[9]!==d?(u={queryKey:c,queryFn:d,retry:!1,refetchOnWindowFocus:!1},s[8]=c,s[9]=d,s[10]=u):u=s[10];const h=Fi(u);let f;s[11]!==a||s[12]!==e?(f=async b=>{const y=await a.callTool({name:"COLLECTION_THREADS_CREATE",arguments:{data:{id:b,virtual_mcp_id:e}}});if(y.isError){const j=y.content,V=Array.isArray(j)&&j[0]&&typeof j[0]=="object"?j[0].text??"Create failed":"Create failed";throw new Error(V)}return y.structuredContent.item},s[11]=a,s[12]=e,s[13]=f):f=s[13];let m;s[14]!==n||s[15]!==i.id||s[16]!==h||s[17]!==l?(m=()=>{l.invalidateQueries({predicate:b=>b.queryKey[1]===i.id&&b.queryKey[3]==="collection"&&b.queryKey[4]==="THREADS"}),l.invalidateQueries({queryKey:lt.tasksPrefix(n)}),h.refetch()},s[14]=n,s[15]=i.id,s[16]=h,s[17]=l,s[18]=m):m=s[18];let p;s[19]!==f||s[20]!==m?(p={mutationFn:f,onSuccess:m},s[19]=f,s[20]=m,s[21]=p):p=s[21];const g=Br(p);let _,v;if(s[22]!==g||s[23]!==t||s[24]!==h.data||s[25]!==h.isSuccess?(_=()=>{!h.isSuccess||h.data||g.isPending||g.variables!==t&&g.mutate(t)},v=[t,h.isSuccess,h.data,g],s[22]=g,s[23]=t,s[24]=h.data,s[25]=h.isSuccess,s[26]=_,s[27]=v):(_=s[26],v=s[27]),S.useEffect(_,v),h.isLoading){let b;return s[28]===Symbol.for("react.memo_cache_sentinel")?(b={status:"loading"},s[28]=b):b=s[28],b}if(h.isError){const b=h.error;let y;return s[29]!==b?(y={status:"error",error:b},s[29]=b,s[30]=y):y=s[30],y}if(h.isSuccess&&h.data){let b;return s[31]!==h.data?(b={status:"ready",task:h.data},s[31]=h.data,s[32]=b):b=s[32],b}if(g.isPending||h.isSuccess&&!h.data){let b;return s[33]===Symbol.for("react.memo_cache_sentinel")?(b={status:"creating"},s[33]=b):b=s[33],b}if(g.isError){let b;return s[34]!==g.error?(b={status:"error",error:g.error},s[34]=g.error,s[35]=b):b=s[35],b}let x;return s[36]===Symbol.for("react.memo_cache_sentinel")?(x={status:"loading"},s[36]=x):x=s[36],x}function H_(t){const e={};for(const s of t.arguments??[])e[s.name]=s.required?Et().min(1,"Required"):Et();return Vs(e)}function W_(t){const e={};for(const s of t.arguments??[])e[s.name]="";return e}function Rl(t){const e=B.c(65),{prompt:s,setPrompt:i,onSubmit:n}=t,o=S.useId();let a;if(e[0]!==s){const D=s?H_(s):Vs({});a=Or(D),e[0]=s,e[1]=a}else a=e[1];const c=a;let d;e[2]!==s?(d=s?W_(s):{},e[2]=s,e[3]=d):d=e[3];let u;e[4]!==c||e[5]!==d?(u={resolver:c,defaultValues:d,mode:"onChange"},e[4]=c,e[5]=d,e[6]=u):u=e[6];const h=Hi(u);let f;e[7]!==s?.arguments?(f=s?.arguments??[],e[7]=s?.arguments,e[8]=f):f=e[8];const m=f;let p;e[9]!==h||e[10]!==n||e[11]!==i?(p=async D=>{await n(D),i(null),h.reset()},e[9]=h,e[10]=n,e[11]=i,e[12]=p):p=e[12];const g=p;let _;e[13]!==h||e[14]!==i?(_=D=>{D||(h.reset(),i(null))},e[13]=h,e[14]=i,e[15]=_):_=e[15];const v=_;if(!s)return null;let x;e[16]!==s._meta||e[17]!==s.name||e[18]!==s.title?(x=s.title||eo(s.name,si(s._meta)),e[16]=s._meta,e[17]=s.name,e[18]=s.title,e[19]=x):x=e[19];let b;e[20]!==x?(b=r.jsx(Ts,{children:r.jsx("span",{className:"capitalize",children:x})}),e[20]=x,e[21]=b):b=e[21];let y;e[22]!==s.description?(y=s.description&&r.jsx("p",{className:"text-sm text-muted-foreground",children:s.description}),e[22]=s.description,e[23]=y):y=e[23];let C;e[24]!==y||e[25]!==b?(C=r.jsxs(Ds,{children:[b,y]}),e[24]=y,e[25]=b,e[26]=C):C=e[26];let j;e[27]!==h||e[28]!==g?(j=D=>{D.stopPropagation(),h.handleSubmit(g)(D)},e[27]=h,e[28]=g,e[29]=j):j=e[29];let V;if(e[30]!==m||e[31]!==h.control||e[32]!==h.formState.isSubmitting){let D;e[34]!==h.control||e[35]!==h.formState.isSubmitting?(D=P=>r.jsx(It,{control:h.control,name:P.name,render:O=>{const{field:z}=O;return r.jsxs(Rt,{children:[r.jsxs(rs,{className:"text-xs",children:[P.name,P.required?null:r.jsxs("span",{className:"text-muted-foreground font-normal",children:[" ","(optional)"]})]}),r.jsx(Tt,{children:r.jsx(bt,{...z,value:z.value??"",required:P.required,placeholder:P.description??"",className:"h-9",disabled:h.formState.isSubmitting})}),r.jsx(Dt,{})]})}},P.name),e[34]=h.control,e[35]=h.formState.isSubmitting,e[36]=D):D=e[36],V=m.map(D),e[30]=m,e[31]=h.control,e[32]=h.formState.isSubmitting,e[33]=V}else V=e[33];let w;e[37]!==v?(w=()=>v(!1),e[37]=v,e[38]=w):w=e[38];let k;e[39]!==h.formState.isSubmitting||e[40]!==w?(k=r.jsx(ne,{type:"button",variant:"ghost",onClick:w,disabled:h.formState.isSubmitting,children:"Cancel"}),e[39]=h.formState.isSubmitting,e[40]=w,e[41]=k):k=e[41];const T=!h.formState.isValid||h.formState.isSubmitting;let I;e[42]!==h.formState.isSubmitting?(I=h.formState.isSubmitting?r.jsxs("span",{className:"flex items-center gap-2",children:[r.jsx(jr,{size:"xs"}),"Loading..."]}):"Use prompt",e[42]=h.formState.isSubmitting,e[43]=I):I=e[43];let A;e[44]!==o||e[45]!==T||e[46]!==I?(A=r.jsx(ne,{type:"submit",form:o,disabled:T,children:I}),e[44]=o,e[45]=T,e[46]=I,e[47]=A):A=e[47];let N;e[48]!==k||e[49]!==A?(N=r.jsxs(cl,{children:[k,A]}),e[48]=k,e[49]=A,e[50]=N):N=e[50];let E;e[51]!==o||e[52]!==j||e[53]!==V||e[54]!==N?(E=r.jsxs("form",{id:o,className:"space-y-4 py-4",autoComplete:"off",onSubmit:j,children:[V,N]}),e[51]=o,e[52]=j,e[53]=V,e[54]=N,e[55]=E):E=e[55];let R;e[56]!==h||e[57]!==E?(R=r.jsx(Pi,{...h,children:E}),e[56]=h,e[57]=E,e[58]=R):R=e[58];let M;e[59]!==C||e[60]!==R?(M=r.jsxs(ms,{className:"sm:max-w-lg max-h-[80vh] overflow-y-auto",children:[C,R]}),e[59]=C,e[60]=R,e[61]=M):M=e[61];let L;return e[62]!==v||e[63]!==M?(L=r.jsx(ps,{open:!0,onOpenChange:v,children:M}),e[62]=v,e[63]=M,e[64]=L):L=e[64],L}function U_(t){return!t||!t.content||t.content.length===0?!0:t.content.every(e=>e.type==="paragraph"?!e.content||e.content.length===0?!0:e.content.every(s=>s.type==="hardBreak"||s.type==="text"&&(!s.text||s.text.trim()==="")):!1)}function K_(t,e){return{type:"doc",content:[...t?.content??[],e].filter(Boolean)}}const kc=3,wu="inline-flex items-center gap-2 px-5 py-2.5 rounded-full bg-muted text-muted-foreground text-sm font-medium transition-colors cursor-pointer",q_="flex flex-col gap-1.5 p-4 rounded-xl bg-accent/40 text-sm leading-snug transition-colors cursor-pointer text-left";function Vu(t){const e=B.c(46),{item:s,onSelect:i,isLoading:n,isDisabled:o,variant:a}=t,l=a===void 0?"pill":a,{prompt:c}=s;let d;if(e[0]!==c._meta||e[1]!==c.name||e[2]!==c.title){const V=si(c._meta);d=c.title??eo(c.name,V),e[0]=c._meta,e[1]=c.name,e[2]=c.title,e[3]=d}else d=e[3];const u=d,h=c.description||null;if(l==="card"){let V;e[4]!==i||e[5]!==c?(V=()=>i(c),e[4]=i,e[5]=c,e[6]=V):V=e[6];const w=o||n,k=n&&"bg-accent/40",T=(o||n)&&"cursor-not-allowed opacity-50";let I;e[7]!==k||e[8]!==T?(I=X(q_,"hover:bg-accent/60 text-foreground",k,T),e[7]=k,e[8]=T,e[9]=I):I=e[9];let A;e[10]!==u?(A=r.jsx("span",{className:"font-medium truncate capitalize",children:u}),e[10]=u,e[11]=A):A=e[11];let N;e[12]!==n?(N=n&&r.jsx(jr,{size:"xs"}),e[12]=n,e[13]=N):N=e[13];let E;e[14]!==A||e[15]!==N?(E=r.jsxs("div",{className:"flex items-center justify-between gap-2",children:[A,N]}),e[14]=A,e[15]=N,e[16]=E):E=e[16];let R;e[17]!==h?(R=h&&r.jsx("span",{className:"text-xs text-muted-foreground line-clamp-2",children:h}),e[17]=h,e[18]=R):R=e[18];let M;return e[19]!==E||e[20]!==R||e[21]!==V||e[22]!==w||e[23]!==I?(M=r.jsxs("button",{type:"button",onClick:V,disabled:w,className:I,children:[E,R]}),e[19]=E,e[20]=R,e[21]=V,e[22]=w,e[23]=I,e[24]=M):M=e[24],M}let f;e[25]!==i||e[26]!==c?(f=()=>i(c),e[25]=i,e[26]=c,e[27]=f):f=e[27];const m=o||n,p=n&&"bg-muted/50",g=(o||n)&&"cursor-not-allowed opacity-50";let _;e[28]!==p||e[29]!==g?(_=X(wu,"hover:bg-muted/70 hover:text-foreground",p,g),e[28]=p,e[29]=g,e[30]=_):_=e[30];let v;e[31]!==u?(v=r.jsx("span",{className:"capitalize",children:u}),e[31]=u,e[32]=v):v=e[32];let x;e[33]!==n?(x=n&&r.jsx(jr,{size:"xs"}),e[33]=n,e[34]=x):x=e[34];let b;e[35]!==f||e[36]!==m||e[37]!==_||e[38]!==v||e[39]!==x?(b=r.jsx(tt,{asChild:!0,children:r.jsxs("button",{type:"button",onClick:f,disabled:m,className:_,children:[v,x]})}),e[35]=f,e[36]=m,e[37]=_,e[38]=v,e[39]=x,e[40]=b):b=e[40];const y=h??u;let C;e[41]!==y?(C=r.jsx(st,{side:"top",className:"max-w-xs",children:r.jsx("p",{className:"text-xs",children:y})}),e[41]=y,e[42]=C):C=e[42];let j;return e[43]!==b||e[44]!==C?(j=r.jsxs(it,{delayDuration:400,children:[b,C]}),e[43]=b,e[44]=C,e[45]=j):j=e[45],j}function G_(t){const e=B.c(41),{items:s,open:i,onOpenChange:n,onSelect:o,loadingPrompt:a}=t,[l,c]=S.useState(""),d=!!a;let u;e[0]!==s||e[1]!==l?(u=l.trim()?s.filter(w=>{const k=l.toLowerCase();return w.prompt.name.toLowerCase().includes(k)||(w.prompt.title??"").toLowerCase().includes(k)||(w.prompt.description??"").toLowerCase().includes(k)}):s,e[0]=s,e[1]=l,e[2]=u):u=e[2];const h=u,f=Rs();let m;e[3]!==h.length||e[4]!==l?(m=h.length===0&&r.jsxs("p",{className:"col-span-4 text-sm text-muted-foreground text-center py-8",children:["No prompts match “",l,"”"]}),e[3]=h.length,e[4]=l,e[5]=m):m=e[5];let p;if(e[6]!==h||e[7]!==d||e[8]!==a?.name||e[9]!==n||e[10]!==o){let w;e[12]!==d||e[13]!==a?.name||e[14]!==n||e[15]!==o?(w=k=>r.jsx(Vu,{item:k,variant:"card",onSelect:T=>{n(!1),o(T)},isLoading:a?.name===k.prompt.name,isDisabled:d&&a?.name!==k.prompt.name},k.prompt.name),e[12]=d,e[13]=a?.name,e[14]=n,e[15]=o,e[16]=w):w=e[16],p=h.map(w),e[6]=h,e[7]=d,e[8]=a?.name,e[9]=n,e[10]=o,e[11]=p}else p=e[11];let g;e[17]!==m||e[18]!==p?(g=r.jsx("div",{className:"flex-1 overflow-y-auto [scrollbar-gutter:stable]",children:r.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 gap-3 p-5",children:[m,p]})}),e[17]=m,e[18]=p,e[19]=g):g=e[19];const _=g;let v;e[20]===Symbol.for("react.memo_cache_sentinel")?(v=w=>{w.key==="Escape"&&c("")},e[20]=v):v=e[20];let x;e[21]!==l?(x=r.jsx(Th,{value:l,onChange:c,placeholder:"Search prompts...",onKeyDown:v}),e[21]=l,e[22]=x):x=e[22];const b=x;if(f){let w;e[23]===Symbol.for("react.memo_cache_sentinel")?(w=r.jsx(so,{className:"sr-only",children:r.jsx(bi,{children:"All prompts"})}),e[23]=w):w=e[23];let k;e[24]===Symbol.for("react.memo_cache_sentinel")?(k=r.jsx("div",{className:"flex items-center h-12 border-b border-border px-4 shrink-0",children:r.jsx("span",{className:"text-sm font-medium text-foreground",children:"Prompts"})}),e[24]=k):k=e[24];let T;e[25]!==_||e[26]!==b?(T=r.jsxs(yi,{className:"h-[85vh] flex flex-col p-0 gap-0",children:[w,k,b,_]}),e[25]=_,e[26]=b,e[27]=T):T=e[27];let I;return e[28]!==n||e[29]!==i||e[30]!==T?(I=r.jsx(Mi,{delayDuration:400,children:r.jsx(Si,{open:i,onOpenChange:n,children:T})}),e[28]=n,e[29]=i,e[30]=T,e[31]=I):I=e[31],I}let y;e[32]===Symbol.for("react.memo_cache_sentinel")?(y=r.jsx(Ds,{className:"sr-only",children:r.jsx(Ts,{children:"All prompts"})}),e[32]=y):y=e[32];let C;e[33]===Symbol.for("react.memo_cache_sentinel")?(C=r.jsx("div",{className:"flex items-center h-12 border-b border-border px-4 shrink-0",children:r.jsx("span",{className:"text-sm font-medium text-foreground",children:"Prompts"})}),e[33]=C):C=e[33];let j;e[34]!==_||e[35]!==b?(j=r.jsxs(ms,{className:"sm:max-w-[1100px] h-[680px] p-0 gap-0 overflow-hidden flex flex-col",children:[y,C,b,_]}),e[34]=_,e[35]=b,e[36]=j):j=e[36];let V;return e[37]!==n||e[38]!==i||e[39]!==j?(V=r.jsx(Mi,{delayDuration:400,children:r.jsx(ps,{open:i,onOpenChange:n,children:j})}),e[37]=n,e[38]=i,e[39]=j,e[40]=V):V=e[40],V}function Y_(t){const e=B.c(29),{items:s,onSelect:i,loadingPrompt:n,className:o}=t,[a,l]=S.useState(!1);if(s.length===0)return null;let c,d,u;if(e[0]!==s||e[1]!==n||e[2]!==i){const v=s.slice(0,kc);let x;e[6]!==s?(x=s.slice(kc),e[6]=s,e[7]=x):x=e[7],c=x,d=!!n;let b;e[8]!==d||e[9]!==n?.name||e[10]!==i?(b=y=>r.jsx(Vu,{item:y,onSelect:i,isLoading:n?.name===y.prompt.name,isDisabled:d&&n?.name!==y.prompt.name},y.prompt.name),e[8]=d,e[9]=n?.name,e[10]=i,e[11]=b):b=e[11],u=v.map(b),e[0]=s,e[1]=n,e[2]=i,e[3]=c,e[4]=d,e[5]=u}else c=e[3],d=e[4],u=e[5];const h=u;let f;e[12]!==o?(f=X("w-full flex flex-wrap gap-2 justify-center",o),e[12]=o,e[13]=f):f=e[13];let m;e[14]!==c.length||e[15]!==d?(m=c.length>0&&r.jsxs("button",{type:"button",disabled:d,onClick:()=>l(!0),className:X(wu,"hover:bg-muted/70 hover:text-foreground",d&&"opacity-50 cursor-not-allowed"),children:["+",c.length," more"]}),e[14]=c.length,e[15]=d,e[16]=m):m=e[16];let p;e[17]!==h||e[18]!==f||e[19]!==m?(p=r.jsxs("div",{className:f,children:[h,m]}),e[17]=h,e[18]=f,e[19]=m,e[20]=p):p=e[20];let g;e[21]!==s||e[22]!==n||e[23]!==a||e[24]!==i?(g=r.jsx(G_,{items:s,open:a,onOpenChange:l,onSelect:i,loadingPrompt:n}),e[21]=s,e[22]=n,e[23]=a,e[24]=i,e[25]=g):g=e[25];let _;return e[26]!==p||e[27]!==g?(_=r.jsxs(Mi,{delayDuration:400,children:[p,g]}),e[26]=p,e[27]=g,e[28]=_):_=e[28],_}function X_(){return null}function J_(t,e){switch(e.type){case"SELECT_PROMPT":return!e.prompt.arguments||e.prompt.arguments.length===0?{stage:"loading",prompt:e.prompt}:{stage:"idle"};case"START_LOADING":return{stage:"loading",prompt:e.prompt,arguments:e.arguments};case"RESET":return{stage:"idle"};default:return t}}function Q_(t){const e=B.c(30),{connectionId:s}=t,{sendMessage:i}=Ui(),{tiptapDocRef:n}=ni(),{org:o}=be();let a;e[0]!==s||e[1]!==o.id?(a={connectionId:s,orgId:o.id},e[0]=s,e[1]=o.id,e[2]=a):a=e[2];const l=Me(a);let c;e[3]!==l?(c={client:l,staleTime:6e4},e[3]=l,e[4]=c):c=e[4];const{data:d}=Dh(c);let u;e[5]!==d?.prompts?(u=d?.prompts??[],e[5]=d?.prompts,e[6]=u):u=e[6];const h=u;let f;e[7]!==h?(f=h.map(Z_),e[7]=h,e[8]=f):f=e[8];const m=f;let p;e[9]===Symbol.for("react.memo_cache_sentinel")?(p={stage:"idle"},e[9]=p):p=e[9];const[g,_]=S.useReducer(J_,p),[v,x]=S.useState(null);let b;e[10]!==l||e[11]!==i||e[12]!==n?(b=async(E,R)=>{if(!l){ge.error("MCP client not available"),_({type:"RESET"});return}try{const M=await ul(l,E.name,R);_({type:"RESET"});const L=K_(n.current,{type:"paragraph",content:[Ip({id:E.name,name:al(E.name,si(E._meta)),metadata:M.messages,char:"/"})]});await i(L)}catch(M){console.error("[ice-breakers] Failed to fetch prompt:",M),ge.error("Failed to load prompt. Please try again."),_({type:"RESET"})}},e[10]=l,e[11]=i,e[12]=n,e[13]=b):b=e[13];const y=b;let C;e[14]!==y?(C=async E=>{if(E.arguments&&E.arguments.length>0){_({type:"SELECT_PROMPT",prompt:E}),x(E);return}_({type:"START_LOADING",prompt:E}),await y(E)},e[14]=y,e[15]=C):C=e[15];const j=C;let V;e[16]!==v||e[17]!==y?(V=async E=>{v&&(_({type:"START_LOADING",prompt:v,arguments:E}),x(null),await y(v,E))},e[16]=v,e[17]=y,e[18]=V):V=e[18];const w=V;if(m.length===0)return null;const k=g.stage==="loading"?g.prompt:null;let T;e[19]!==j||e[20]!==m||e[21]!==k?(T=r.jsx(Y_,{items:m,onSelect:j,loadingPrompt:k}),e[19]=j,e[20]=m,e[21]=k,e[22]=T):T=e[22];let I;e[23]===Symbol.for("react.memo_cache_sentinel")?(I=()=>{x(null),_({type:"RESET"})},e[23]=I):I=e[23];let A;e[24]!==v||e[25]!==w?(A=r.jsx(Rl,{prompt:v,setPrompt:I,onSubmit:w}),e[24]=v,e[25]=w,e[26]=A):A=e[26];let N;return e[27]!==T||e[28]!==A?(N=r.jsxs(r.Fragment,{children:[T,A]}),e[27]=T,e[28]=A,e[29]=N):N=e[29],N}function Z_(t){return{prompt:t}}function ex(t){const e=B.c(13),{className:s}=t,{selectedVirtualMcp:i}=ni(),{org:n}=be();let o;e[0]!==n.id?(o=io(n.id),e[0]=n.id,e[1]=o):o=e[1];const a=o.id,l=i?.id??a;let c;e[2]!==s?(c=X("w-full @container",s),e[2]=s,e[3]=c):c=e[3];const d=l??"default";let u;e[4]===Symbol.for("react.memo_cache_sentinel")?(u=r.jsx(X_,{}),e[4]=u):u=e[4];let h;e[5]!==l?(h=r.jsx(Q_,{connectionId:l}),e[5]=l,e[6]=h):h=e[6];let f;e[7]!==d||e[8]!==h?(f=r.jsx(Cs,{fallback:null,children:r.jsx(S.Suspense,{fallback:u,children:h},d)}),e[7]=d,e[8]=h,e[9]=f):f=e[9];let m;return e[10]!==c||e[11]!==f?(m=r.jsx("div",{className:c,children:f}),e[10]=c,e[11]=f,e[12]=m):m=e[12],m}function Cu(t){const e=B.c(21),{current:s,total:i,onPrev:n,onNext:o}=t;if(i<=1)return null;const a=s===0,l=s===0?"opacity-30 cursor-not-allowed":"hover:text-foreground cursor-pointer";let c;e[0]!==l?(c=X("p-0.5 rounded transition-colors",l),e[0]=l,e[1]=c):c=e[1];let d;e[2]===Symbol.for("react.memo_cache_sentinel")?(d=r.jsx(xl,{size:14}),e[2]=d):d=e[2];let u;e[3]!==n||e[4]!==a||e[5]!==c?(u=r.jsx("button",{type:"button",onClick:n,disabled:a,className:c,"aria-label":"Previous question",children:d}),e[3]=n,e[4]=a,e[5]=c,e[6]=u):u=e[6];const h=s+1;let f;e[7]!==h||e[8]!==i?(f=r.jsxs("span",{className:"tabular-nums text-xs",children:[h," of ",i]}),e[7]=h,e[8]=i,e[9]=f):f=e[9];const m=s===i-1,p=s===i-1?"opacity-30 cursor-not-allowed":"hover:text-foreground cursor-pointer";let g;e[10]!==p?(g=X("p-0.5 rounded transition-colors",p),e[10]=p,e[11]=g):g=e[11];let _;e[12]===Symbol.for("react.memo_cache_sentinel")?(_=r.jsx(ro,{size:14}),e[12]=_):_=e[12];let v;e[13]!==o||e[14]!==g||e[15]!==m?(v=r.jsx("button",{type:"button",onClick:o,disabled:m,className:g,"aria-label":"Next question",children:_}),e[13]=o,e[14]=g,e[15]=m,e[16]=v):v=e[16];let x;return e[17]!==v||e[18]!==u||e[19]!==f?(x=r.jsxs("div",{className:"flex items-center gap-1 text-sm text-muted-foreground",children:[u,f,v]}),e[17]=v,e[18]=u,e[19]=f,e[20]=x):x=e[20],x}function On(t){const e=B.c(18),{title:s,children:i,footerLeft:n,footerRight:o,className:a}=t,l=a??"border-border";let c;e[0]!==l?(c=X("flex flex-col rounded-xl bg-background border shadow-md w-[calc(100%-16px)] max-w-[584px] mx-auto mb-[-16px]",l),e[0]=l,e[1]=c):c=e[1];let d;e[2]!==s?(d=r.jsx("div",{className:"flex items-center gap-2 p-4",children:r.jsx("p",{className:"flex-1 text-base font-medium text-foreground min-w-0",children:s})}),e[2]=s,e[3]=d):d=e[3];let u;e[4]!==i?(u=r.jsx("div",{className:"overflow-clip pb-4",children:i}),e[4]=i,e[5]=u):u=e[5];let h;e[6]!==n?(h=r.jsx("div",{children:n}),e[6]=n,e[7]=h):h=e[7];let f;e[8]!==o?(f=r.jsx("div",{className:"flex items-center gap-2",children:o}),e[8]=o,e[9]=f):f=e[9];let m;e[10]!==h||e[11]!==f?(m=r.jsx("div",{className:"border-t border-border px-3 py-3 pb-6",children:r.jsxs("div",{className:"flex items-center justify-between",children:[h,f]})}),e[10]=h,e[11]=f,e[12]=m):m=e[12];let p;return e[13]!==c||e[14]!==d||e[15]!==u||e[16]!==m?(p=r.jsxs("div",{className:c,children:[d,u,m]}),e[13]=c,e[14]=d,e[15]=u,e[16]=m,e[17]=p):p=e[17],p}const tx="User denied this tool call, give other alternatives.",sx=[{value:"readonly",label:"Ask before edit"},{value:"auto",label:"Auto approve"}];function ix(t){const e=B.c(9),{onYolo:s}=t,[i,n]=Wi();let o;e[0]!==s||e[1]!==i||e[2]!==n?(o=u=>{const h=u;n({...i,toolApprovalLevel:h}),h==="auto"&&s()},e[0]=s,e[1]=i,e[2]=n,e[3]=o):o=e[3];const a=o;let l;e[4]===Symbol.for("react.memo_cache_sentinel")?(l=r.jsx(Zs,{size:"xs",className:"text-xs text-muted-foreground border-border/60 bg-transparent hover:bg-accent/60 h-7 gap-1",onClick:nx,children:r.jsx(ei,{})}),e[4]=l):l=e[4];let c;e[5]===Symbol.for("react.memo_cache_sentinel")?(c=r.jsx(Js,{children:sx.map(rx)}),e[5]=c):c=e[5];let d;return e[6]!==a||e[7]!==i.toolApprovalLevel?(d=r.jsxs(Qs,{value:i.toolApprovalLevel,onValueChange:a,children:[l,c]}),e[6]=a,e[7]=i.toolApprovalLevel,e[8]=d):d=e[8],d}function rx(t){return r.jsx(Ht,{value:t.value,children:t.label},t.value)}function nx(t){return t.stopPropagation()}function ox(t){const e=B.c(5),{input:s}=t;if(s==null){let o;return e[0]===Symbol.for("react.memo_cache_sentinel")?(o=r.jsx("div",{className:"px-4 text-xs text-muted-foreground",children:"No input"}),e[0]=o):o=e[0],o}let i;try{let o;e[1]!==s?(o=JSON.stringify(s,null,2),e[1]=s,e[2]=o):o=e[2],i=o}catch{i=String(s)}let n;return e[3]!==i?(n=r.jsx("div",{className:"px-4",children:r.jsx("pre",{className:"text-xs font-mono text-muted-foreground/70 whitespace-pre-wrap wrap-break-word max-h-32 overflow-y-auto rounded-md bg-muted/30 px-3 py-2",children:i})}),e[3]=i,e[4]=n):n=e[4],n}function ax(t){const e=B.c(42),{approvals:s,onRespond:i}=t,[n,o]=S.useState(0),a=Math.min(n,s.length-1),l=s[a];if(!l)return null;let c;e[0]!==l.approvalId||e[1]!==i?(c=()=>{i(l.approvalId,!1,tx)},e[0]=l.approvalId,e[1]=i,e[2]=c):c=e[2];const d=c;let u;e[3]!==l.approvalId||e[4]!==i?(u=()=>{i(l.approvalId,!0)},e[3]=l.approvalId,e[4]=i,e[5]=u):u=e[5];const h=u;let f;e[6]!==s||e[7]!==i?(f=()=>{for(const N of s)i(N.approvalId,!0)},e[6]=s,e[7]=i,e[8]=f):f=e[8];const m=f;let p;e[9]!==a?(p=()=>{a>0&&o(a-1)},e[9]=a,e[10]=p):p=e[10];const g=p;let _;e[11]!==s.length||e[12]!==a?(_=()=>{a<s.length-1&&o(a+1)},e[11]=s.length,e[12]=a,e[13]=_):_=e[13];const v=_;let x;e[14]!==m?(x=r.jsx(ix,{onYolo:m}),e[14]=m,e[15]=x):x=e[15];let b;e[16]!==s.length||e[17]!==v||e[18]!==g||e[19]!==a?(b=r.jsx(Cu,{current:a,total:s.length,onPrev:g,onNext:v}),e[16]=s.length,e[17]=v,e[18]=g,e[19]=a,e[20]=b):b=e[20];let y;e[21]!==x||e[22]!==b?(y=r.jsxs("div",{className:"flex items-center gap-2",children:[x,b]}),e[21]=x,e[22]=b,e[23]=y):y=e[23];const C=y;let j;e[24]!==d?(j=r.jsx(ne,{type:"button",variant:"ghost",size:"sm",className:"h-7 px-2.5 text-xs text-muted-foreground [@media(hover:hover)]:hover:text-foreground active:scale-[0.97] transition-transform",onClick:d,children:"Deny"}),e[24]=d,e[25]=j):j=e[25];let V;e[26]!==s.length||e[27]!==m?(V=s.length>1&&r.jsx(ne,{type:"button",variant:"outline",size:"sm",className:"h-7 px-2.5 text-xs active:scale-[0.97] transition-transform",onClick:m,children:"Accept All"}),e[26]=s.length,e[27]=m,e[28]=V):V=e[28];let w;e[29]!==h?(w=r.jsx(ne,{type:"button",size:"sm",className:"h-7 px-2.5 text-xs active:scale-[0.97] transition-transform",onClick:h,children:"Accept"}),e[29]=h,e[30]=w):w=e[30];let k;e[31]!==V||e[32]!==w||e[33]!==j?(k=r.jsxs(r.Fragment,{children:[j,V,w]}),e[31]=V,e[32]=w,e[33]=j,e[34]=k):k=e[34];const T=k;let I;e[35]!==l.input?(I=r.jsx(ox,{input:l.input}),e[35]=l.input,e[36]=I):I=e[36];let A;return e[37]!==l.friendlyName||e[38]!==C||e[39]!==T||e[40]!==I?(A=r.jsx(On,{title:l.friendlyName,footerLeft:C,footerRight:T,children:I}),e[37]=l.friendlyName,e[38]=C,e[39]=T,e[40]=I,e[41]=A):A=e[41],A}function lx(){const t=B.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=r.jsxs("div",{className:"flex items-center gap-2 p-4 border border-dashed rounded-lg bg-accent/50 w-[calc(100%-16px)] max-w-[584px] mx-auto mb-2",children:[r.jsx(hg,{className:"size-5 text-muted-foreground shimmer"}),r.jsx("span",{className:"text-sm text-muted-foreground shimmer",children:"Preparing approval request..."})]}),t[0]=e):e=t[0],e}function cx(t){const e=B.c(4),{approvals:s,isStreaming:i,onRespond:n}=t;if(i&&s.length===0){let a;return e[0]===Symbol.for("react.memo_cache_sentinel")?(a=r.jsx(lx,{}),e[0]=a):a=e[0],a}if(s.length===0)return null;let o;return e[1]!==s||e[2]!==n?(o=r.jsx(ax,{approvals:s,onRespond:n}),e[1]=s,e[2]=n,e[3]=o):o=e[3],o}function dx(t){const e=[];for(const s of t)if("state"in s&&s.state==="approval-requested"&&"approval"in s&&s.approval?.id&&"toolCallId"in s&&s.toolCallId){const i="toolName"in s&&typeof s.toolName=="string"?s.toolName:s.type.startsWith("tool-")?s.type.replace("tool-",""):"Tool";e.push({approvalId:s.approval.id,toolCallId:s.toolCallId,toolName:i,friendlyName:Rp(Tp(i)),input:s.input})}return e}function hx(t){const e=B.c(15),{plan:s,onApprove:i,onDismiss:n}=t;let o;e[0]!==i||e[1]!==s.plan?(o=()=>{i(s.plan)},e[0]=i,e[1]=s.plan,e[2]=o):o=e[2];const a=o;let l;e[3]!==n?(l=r.jsx(ne,{type:"button",variant:"ghost",size:"sm",className:"h-7 px-2.5 text-xs text-muted-foreground [@media(hover:hover)]:hover:text-foreground active:scale-[0.97] transition-transform",onClick:n,children:"Keep iterating"}),e[3]=n,e[4]=l):l=e[4];let c;e[5]!==a?(c=r.jsx(ne,{type:"button",size:"sm",className:"h-7 px-2.5 text-xs bg-purple-600 hover:bg-purple-700 text-white active:scale-[0.97] transition-transform",onClick:a,children:"Let's go"}),e[5]=a,e[6]=c):c=e[6];let d;e[7]!==l||e[8]!==c?(d=r.jsxs(r.Fragment,{children:[l,c]}),e[7]=l,e[8]=c,e[9]=d):d=e[9];const u=d;let h;e[10]!==s.plan?(h=r.jsx("div",{className:"px-4 max-h-64 overflow-y-auto",children:r.jsx("div",{className:"prose prose-sm max-w-none text-sm",children:r.jsx(Dp,{id:"plan-preview",part:{type:"text",text:s.plan}})})}),e[10]=s.plan,e[11]=h):h=e[11];let f;return e[12]!==u||e[13]!==h?(f=r.jsx(On,{title:"Implementation Plan",footerRight:u,className:"border-dashed border-purple-500",children:h}),e[12]=u,e[13]=h,e[14]=f):f=e[14],f}function ux(){const t=B.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=r.jsxs("div",{className:"flex items-center gap-2 p-4 border border-dashed border-purple-500/30 rounded-lg bg-purple-500/5 w-[calc(100%-16px)] max-w-[584px] mx-auto mb-2",children:[r.jsx(Jt,{className:"size-5 text-purple-500 shimmer"}),r.jsx("span",{className:"text-sm text-muted-foreground shimmer",children:"Preparing plan..."})]}),t[0]=e):e=t[0],e}function fx(t){const e=B.c(7),{plans:s,isStreaming:i,onApprove:n,onDismiss:o}=t;if(i&&s.length===0){let d;return e[0]===Symbol.for("react.memo_cache_sentinel")?(d=r.jsx(ux,{}),e[0]=d):d=e[0],d}let a;e[1]!==s?(a=s.at(-1),e[1]=s,e[2]=a):a=e[2];const l=a;if(!l)return null;let c;return e[3]!==l||e[4]!==n||e[5]!==o?(c=r.jsx(hx,{plan:l,onApprove:n,onDismiss:o}),e[3]=l,e[4]=n,e[5]=o,e[6]=c):c=e[6],c}function mx(t){const e=[];for(const s of t)if("type"in s&&s.type==="tool-propose_plan"&&"state"in s&&s.state==="input-available"&&"toolCallId"in s&&"input"in s){const i=s.input;e.push({toolCallId:s.toolCallId,plan:i.plan,state:s.state})}return e}const Nc=Vs({response:Et().min(1,"Response is required")}),px=Vs({response:Et().min(1,"Please select or enter an option")}),gx=Vs({response:$m(["yes","no"])});function _x(t){switch(t.type){case"text":return Nc;case"choice":return px;case"confirm":return gx;default:return Nc}}function xx(t){const e={};for(const s of t)e[s.toolCallId]=_x(s.input);return Vs(e)}function vx(t){const e=B.c(6),{control:s,name:i,placeholder:n}=t;let o;e[0]!==n?(o=l=>{const{field:c}=l;return r.jsxs(Rt,{children:[r.jsx(Tt,{children:r.jsx("div",{className:"px-2",children:r.jsxs("div",{className:"flex items-center gap-3 px-2 py-3 rounded-lg bg-accent/50",children:[r.jsx("span",{className:"flex items-center justify-center size-6 rounded-md bg-muted shrink-0",children:r.jsx($h,{size:16,className:"text-muted-foreground"})}),r.jsx("input",{...c,type:"text",placeholder:n||"Type your response...",autoFocus:!0,"aria-label":"Text response input",className:"flex-1 text-sm bg-transparent outline-none placeholder:text-foreground/25 text-foreground min-w-0"})]})})}),r.jsx(Dt,{})]})},e[0]=n,e[1]=o):o=e[1];let a;return e[2]!==s||e[3]!==i||e[4]!==o?(a=r.jsx(It,{control:s,name:i,render:o}),e[2]=s,e[3]=i,e[4]=o,e[5]=a):a=e[5],a}function ju(t,e){const s=B.c(4);let i,n;s[0]!==t||s[1]!==e?(i=()=>{const o=a=>{const l=a.target.tagName;if(l==="INPUT"||l==="TEXTAREA"||a.metaKey||a.ctrlKey||a.altKey)return;const c=Number.parseInt(a.key,10);c>=1&&c<=t&&(a.preventDefault(),e(c-1))};return document.addEventListener("keydown",o),()=>document.removeEventListener("keydown",o)},n=[t,e],s[0]=t,s[1]=e,s[2]=i,s[3]=n):(i=s[2],n=s[3]),S.useEffect(i,n)}function bx(t){const e=B.c(9),{control:s,name:i,options:n}=t,[o,a]=S.useState(!1),l=S.useRef(null),c=S.useRef(null);let d;if(e[0]!==n?(d=f=>{c.current?.onChange(n[f]??""),a(!1)},e[0]=n,e[1]=d):d=e[1],ju(n.length,d),n.length===0)return null;let u;e[2]!==o||e[3]!==n?(u=f=>{const{field:m}=f;c.current=m;const p=o||!!m.value&&!n.includes(m.value);return r.jsxs(Rt,{children:[r.jsx(Tt,{children:r.jsxs("div",{className:"flex flex-col px-2",role:"group","aria-label":"Choice options",children:[n.map((g,_)=>{const v=m.value===g;return r.jsxs("button",{type:"button",onClick:()=>{m.onChange(g??""),a(!1)},className:X("flex items-center gap-3 px-2 py-3 rounded-lg text-left transition-colors w-full",v&&"bg-accent/50",!v&&"hover:bg-accent/30"),"aria-label":`Select ${g}`,children:[r.jsx("span",{className:X("flex items-center justify-center size-6 rounded-md text-sm shrink-0",v?"bg-chart-1 text-white":"bg-muted text-foreground"),children:_+1}),r.jsx("span",{className:"text-sm text-foreground truncate",children:g})]},`${_}-${g}`)}),r.jsxs("div",{className:X("flex items-center gap-3 px-2 py-3 rounded-lg transition-colors w-full cursor-text",p&&"bg-accent/50",!p&&"hover:bg-accent/30"),onClick:()=>{a(!0),n.includes(m.value)&&m.onChange(""),setTimeout(()=>l.current?.focus(),0)},children:[r.jsx("span",{className:"flex items-center justify-center size-6 rounded-md bg-muted shrink-0",children:r.jsx($h,{size:16,className:"text-muted-foreground"})}),p?r.jsx("input",{ref:l,type:"text",value:m.value,onChange:g=>m.onChange(g.target.value),placeholder:"Something else...",autoFocus:!0,"aria-label":"Custom choice input",className:"flex-1 text-sm bg-transparent outline-none placeholder:text-foreground/25 text-foreground min-w-0"}):r.jsx("span",{className:"text-sm text-foreground/25",children:"Something else..."})]})]})}),r.jsx(Dt,{})]})},e[2]=o,e[3]=n,e[4]=u):u=e[4];let h;return e[5]!==s||e[6]!==i||e[7]!==u?(h=r.jsx(It,{control:s,name:i,render:u}),e[5]=s,e[6]=i,e[7]=u,e[8]=h):h=e[8],h}function yx(t){const e=B.c(6),{control:s,name:i}=t;let n;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=["yes","no"],e[0]=n):n=e[0];const o=n,a=S.useRef(null);let l;e[1]===Symbol.for("react.memo_cache_sentinel")?(l=u=>{a.current?.onChange(o[u]??"")},e[1]=l):l=e[1],ju(o.length,l);let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c=u=>{const{field:h}=u;return a.current=h,r.jsxs(Rt,{children:[r.jsx(Tt,{children:r.jsx("div",{className:"flex gap-2 px-2",role:"group","aria-label":"Confirmation options",children:o.map(f=>{const m=h.value===f;return r.jsxs("button",{type:"button",onClick:()=>h.onChange(f),className:X("flex items-center gap-3 px-4 py-3 rounded-lg text-left transition-colors flex-1",m&&"bg-accent/50",!m&&"hover:bg-accent/30"),"aria-label":`Confirm ${f}`,children:[r.jsx("span",{className:X("flex items-center justify-center size-6 rounded-md text-sm shrink-0",m?"bg-chart-1 text-white":"bg-muted text-foreground"),children:f==="yes"?1:2}),r.jsx("span",{className:"text-sm text-foreground capitalize",children:f})]},f)})})}),r.jsx(Dt,{})]})},e[2]=c):c=e[2];let d;return e[3]!==s||e[4]!==i?(d=r.jsx(It,{control:s,name:i,render:c}),e[3]=s,e[4]=i,e[5]=d):d=e[5],d}function Ac(t){const e=B.c(13),{input:s,control:i,name:n}=t;switch(s.type){case"text":{let o;return e[0]!==i||e[1]!==s.default||e[2]!==n?(o=r.jsx(vx,{control:i,name:n,placeholder:s.default}),e[0]=i,e[1]=s.default,e[2]=n,e[3]=o):o=e[3],o}case"choice":{let o;e[4]!==s.options?(o=s.options?.filter(Boolean)??[],e[4]=s.options,e[5]=o):o=e[5];const a=o;let l;return e[6]!==i||e[7]!==n||e[8]!==a?(l=r.jsx(bx,{control:i,name:n,options:a}),e[6]=i,e[7]=n,e[8]=a,e[9]=l):l=e[9],l}case"confirm":{let o;return e[10]!==i||e[11]!==n?(o=r.jsx(yx,{control:i,name:n}),e[10]=i,e[11]=n,e[12]=o):o=e[12],o}default:return null}}function Sx({parts:t,onSubmit:e}){const[s,i]=S.useState(t[0]?.toolCallId??""),n=xx(t.map(x=>({toolCallId:x.toolCallId,input:x.input}))),o=Hi({resolver:Or(n),defaultValues:Object.fromEntries(t.map(x=>[x.toolCallId,{response:""}]))}),a=o.watch(),l=t.findIndex(x=>x.toolCallId===s),c=!!a[s]?.response,d=t.every(x=>!!a[x.toolCallId]?.response),u=x=>{for(const b of t){const y=x[b.toolCallId]?.response;y&&e(b,y)}},h=x=>t.find(b=>!x[b.toolCallId]?.response&&b.toolCallId!==s)??null,f=()=>{const x=o.getValues();if(t.every(y=>!!x[y.toolCallId]?.response))o.handleSubmit(u)();else{const y=h(x);y&&i(y.toolCallId)}},m=()=>{o.setValue(`${s}.response`,"user has skip this question"),f()},p=()=>{if(l>0){const x=t[l-1];x&&i(x.toolCallId)}},g=()=>{if(l<t.length-1){const x=t[l+1];x&&i(x.toolCallId)}},_=r.jsxs(r.Fragment,{children:[r.jsx(ne,{type:"button",variant:"outline",size:"sm",onClick:m,className:"h-7",children:"Skip"}),r.jsx(ne,{type:"button",size:"sm",disabled:!c,onClick:f,className:X("h-7",c?"":"opacity-50"),children:d?"Submit":"Next"})]}),v=r.jsx(Cu,{current:l,total:t.length,onPrev:p,onNext:g});if(t.length===1){const x=t[0];return x?.input?r.jsx(Pi,{...o,children:r.jsx("form",{onSubmit:o.handleSubmit(u),autoComplete:"off",children:r.jsx(On,{title:x.input?.prompt??"Question",footerRight:_,children:r.jsx(Ac,{input:x.input,control:o.control,name:`${x.toolCallId}.response`})})})}):null}return r.jsx(Pi,{...o,children:r.jsx("form",{onSubmit:o.handleSubmit(u),autoComplete:"off",children:r.jsx(Mh,{value:s,onValueChange:i,children:t.map(x=>r.jsx(yn,{value:x.toolCallId,className:"mt-0",children:r.jsx(On,{title:x.input?.prompt??"Question",footerLeft:v,footerRight:_,children:r.jsx(Ac,{input:x.input,control:o.control,name:`${x.toolCallId}.response`})})},x.toolCallId))})})})}function wx(){const t=B.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=r.jsxs("div",{className:"flex items-center gap-2 p-4 border border-dashed rounded-lg bg-accent/50 w-[calc(100%-16px)] max-w-[584px] mx-auto mb-2",children:[r.jsx(Mg,{className:"size-5 text-muted-foreground shimmer"}),r.jsx("span",{className:"text-sm text-muted-foreground shimmer",children:"Preparing question..."})]}),t[0]=e):e=t[0],e}function ku(t){const e=B.c(6),{userAskParts:s,isStreaming:i,onSubmit:n}=t;let o;e[0]!==s?(o=s.filter(Vx),e[0]=s,e[1]=o):o=e[1];const a=o;if(i){let c;return e[2]===Symbol.for("react.memo_cache_sentinel")?(c=r.jsx(wx,{}),e[2]=c):c=e[2],c}if(a.length===0)return null;let l;return e[3]!==n||e[4]!==a?(l=r.jsx(Sx,{parts:a,onSubmit:n}),e[3]=n,e[4]=a,e[5]=l):l=e[5],l}function Vx(t){return t.state==="input-available"}const Ec=new Map;function co(){const{org:t}=be(),e=Me({connectionId:Wt,orgId:t.id}),s=bl(),i=s.find(_=>_.providerId==="deco"),{data:n,isLoading:o,refetch:a,isFetching:l}=Fi({queryKey:lt.aiProviderCredits(t.id,"deco"),enabled:!!i,staleTime:6e4,queryFn:async()=>{const _=await e.callTool({name:"AI_PROVIDER_CREDITS",arguments:{providerId:"deco"}});return _?.isError?null:_.structuredContent??null}}),c=n?.balanceCents??null,d=c!=null?c/100:null,u=S.useRef(new Map);if(c!=null){const _=Ec.get(t.id);u.current.get(t.id)&&_!=null&&c>_&&se("credits_topped_up_detected",{organization_id:t.id,delta_cents:c-_,previous_balance_cents:_,new_balance_cents:c}),Ec.set(t.id,c),u.current.set(t.id,!0)}const h=!!i,f=c!=null&&c>0,m=c!=null&&c===0,p=c!=null&&c===200,g=s.length>0&&s.every(_=>_.providerId==="deco");return{hasDecoKey:h,decoKeyId:i?.id??null,balanceCents:c,balanceDollars:d,hasCredits:f,isZeroBalance:m,isInitialFreeCredit:p,hasOnlyDecoProvider:g,isLoading:o,isFetching:l,refetch:a}}function Cx(t){return t?t.message.startsWith("[CREDITS]"):!1}const jx={usd:[{dollars:10,label:"Starter"},{dollars:20,label:"Popular"},{dollars:100,label:"Best value"}],brl:[{dollars:50,label:"Starter"},{dollars:100,label:"Popular"},{dollars:500,label:"Best value"}]},kx=["Access to 100+ AI models","Unified API, no separate keys needed","Pay only for what you use"];function Nu(t){const e=B.c(43),{onDismiss:s}=t,{org:i}=be(),n=Ke(),{decoKeyId:o}=co();let a;e[0]!==i.id?(a={connectionId:Wt,orgId:i.id},e[0]=i.id,e[1]=a):a=e[1];const l=Me(a),[c,d]=S.useState(""),[u,h]=S.useState(!1),[f,m]=S.useState("usd"),p=f==="brl"?"R$":"$";let g,_;e[2]!==i.id?(g=()=>{se("credits_exhausted_shown",{organization_id:i.id})},_=[i.id],e[2]=i.id,e[3]=g,e[4]=_):(g=e[3],_=e[4]),S.useEffect(g,_);let v;e[5]!==l||e[6]!==f?(v=async D=>{const P=await l.callTool({name:"AI_PROVIDER_TOPUP_URL",arguments:{providerId:"deco",amountCents:D,currency:f}});if(P?.isError)throw new Error(P.content?.[0]?.text??"Failed to get top-up URL");return P.structuredContent?.url},e[5]=l,e[6]=f,e[7]=v):v=e[7];let x;e[8]!==s?(x=D=>{D&&window.open(D,"_blank","noopener,noreferrer"),s?.()},e[8]=s,e[9]=x):x=e[9];let b;e[10]!==v||e[11]!==x?(b={mutationFn:v,onSuccess:x,onError:Ex},e[10]=v,e[11]=x,e[12]=b):b=e[12];const{mutate:y,isPending:C}=Br(b),j=parseFloat(c),V=!isNaN(j)&&j>=1;let w;e[13]!==s?(w=D=>!D&&s?.(),e[13]=s,e[14]=w):w=e[14];let k;e[15]===Symbol.for("react.memo_cache_sentinel")?(k=["radial-gradient(ellipse 40% 200% at -5% 100%, rgba(165,149,255,0.5) 0%, transparent 100%)","radial-gradient(ellipse 40% 200% at 105% -10%, rgba(208,236,26,0.45) 0%, transparent 100%)"],e[15]=k):k=e[15];let T;e[16]===Symbol.for("react.memo_cache_sentinel")?(T=r.jsx("div",{className:"absolute inset-x-0 top-0 h-36 pointer-events-none",style:{backgroundImage:k.join(", "),maskImage:"linear-gradient(to bottom, black 0%, transparent 100%)",WebkitMaskImage:"linear-gradient(to bottom, black 0%, transparent 100%)"}}),e[16]=T):T=e[16];let I;e[17]===Symbol.for("react.memo_cache_sentinel")?(I=r.jsxs("div",{className:"relative px-8 pt-8 pb-2 overflow-hidden",children:[T,r.jsxs(Ds,{className:"relative gap-4",children:[r.jsx("img",{src:"/logos/deco%20logo.svg",alt:"Deco AI Gateway",className:"size-9 rounded-lg object-contain dark:bg-white dark:p-0.5"}),r.jsxs("div",{children:[r.jsx(Ts,{className:"text-xl font-semibold tracking-tight",children:"Top up to keep building"}),r.jsx(dl,{className:"mt-1.5 text-sm leading-relaxed",children:"Your credits are used up. Add more to continue using AI across all your agents."})]})]})]}),e[17]=I):I=e[17];let A;e[18]!==f||e[19]!==p||e[20]!==c||e[21]!==j||e[22]!==o||e[23]!==V||e[24]!==C||e[25]!==u||e[26]!==y?(A=o&&r.jsxs("div",{className:"px-8 pt-5 pb-6",children:[r.jsx("div",{className:"mb-4",children:r.jsxs(eu,{type:"single",variant:"outline",size:"sm",value:f,onValueChange:D=>{D&&m(D)},children:[r.jsx(Ln,{value:"usd",className:"h-8 px-3 text-xs",children:"USD"}),r.jsx(Ln,{value:"brl",className:"h-8 px-3 text-xs",children:"BRL"})]})}),r.jsxs("div",{className:"rounded-xl border border-border p-5",children:[r.jsx("div",{className:"grid grid-cols-3 gap-2.5",children:jx[f].map(D=>{const{dollars:P,label:O}=D;return r.jsxs("button",{type:"button",disabled:C,onClick:()=>{se("credits_topup_clicked",{amount_cents:P*100,currency:f,tier_label:O,source:"exhausted_banner"}),y(P*100)},className:X("relative flex flex-col items-center gap-1 py-5 rounded-xl border transition-all duration-150 cursor-pointer","disabled:opacity-50 disabled:cursor-wait","border-border hover:border-foreground/20 hover:bg-muted/30"),children:[r.jsxs("span",{className:"text-2xl font-semibold tabular-nums text-foreground",children:[p,P]}),r.jsx("span",{className:"text-xs text-muted-foreground",children:O})]},P)})}),u?r.jsxs("div",{className:"flex gap-2 mt-3",children:[r.jsxs("div",{className:"relative flex-1",children:[r.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-sm text-muted-foreground select-none",children:p}),r.jsx(bt,{type:"number",min:"1",step:"1",placeholder:"50",value:c,onChange:D=>d(D.target.value),className:"h-10 text-sm pl-7",autoFocus:!0})]}),r.jsx(ne,{className:"h-10",disabled:!V||C,onClick:()=>{se("credits_topup_clicked",{amount_cents:Math.round(j*100),currency:f,tier_label:"custom",source:"exhausted_banner"}),y(Math.round(j*100))},children:C?"Opening...":"Add"})]}):r.jsx("button",{type:"button",className:"w-full mt-3 text-xs text-muted-foreground hover:text-foreground transition-colors py-1",onClick:()=>h(!0),children:"Enter custom amount"})]}),r.jsx("div",{className:"mt-5 rounded-xl bg-muted/25 border border-border/50 p-4 space-y-3",children:kx.map(Nx)})]}),e[18]=f,e[19]=p,e[20]=c,e[21]=j,e[22]=o,e[23]=V,e[24]=C,e[25]=u,e[26]=y,e[27]=A):A=e[27];let N;e[28]!==s?(N=r.jsx(ne,{variant:"ghost",size:"sm",onClick:s,children:"Dismiss"}),e[28]=s,e[29]=N):N=e[29];let E;e[30]!==n||e[31]!==s||e[32]!==i.slug?(E=r.jsx("button",{type:"button",className:"text-xs text-muted-foreground hover:text-foreground transition-colors",onClick:()=>{n({to:"/$org/settings/ai-providers",params:{org:i.slug}}),s?.()},children:"Manage providers"}),e[30]=n,e[31]=s,e[32]=i.slug,e[33]=E):E=e[33];let R;e[34]!==N||e[35]!==E?(R=r.jsxs("div",{className:"px-8 py-4 border-t border-border bg-muted/30 flex items-center justify-between",children:[N,E]}),e[34]=N,e[35]=E,e[36]=R):R=e[36];let M;e[37]!==A||e[38]!==R?(M=r.jsxs(ms,{className:"sm:max-w-[520px] gap-0 p-0 overflow-hidden",onOpenAutoFocus:Ax,children:[I,A,R]}),e[37]=A,e[38]=R,e[39]=M):M=e[39];let L;return e[40]!==M||e[41]!==w?(L=r.jsx(ps,{open:!0,onOpenChange:w,children:M}),e[40]=M,e[41]=w,e[42]=L):L=e[42],L}function Nx(t){return r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("div",{className:"flex items-center justify-center size-5 rounded-full bg-[hsl(var(--chart-1))]/15 shrink-0",children:r.jsx(Jt,{size:12,className:"text-[hsl(var(--chart-1))]"})}),r.jsx("span",{className:"text-sm text-foreground/80",children:t})]},t)}function Ax(t){return t.preventDefault()}function Ex(t){ge.error(`Top-up failed: ${t.message}`)}const Ix={length:"Response reached the model's output limit. Different models have different limits. Try switching models or asking it to continue.","content-filter":"Response was filtered due to content policy.","tool-calls":"Response paused after tool execution to prevent infinite loops and save costs. Click continue to keep working."};function $n(t){const e=B.c(32),{variant:s,onDismiss:i}=t,n=s==="error",o=n?"Error occurred":"Response incomplete",a=n?t.error.message:Ix[t.finishReason]??`Response stopped unexpectedly: ${t.finishReason}`,l=n?"border-destructive/30 bg-destructive/5":"border-amber-500/30 bg-amber-500/5",c=n?"text-destructive":"text-amber-600 dark:text-amber-500",d=n?ri:yh;let u;e[0]!==l?(u=X("flex items-start gap-2 px-3 py-2.5 rounded-lg border border-dashed text-sm w-full mb-2 shadow",l),e[0]=l,e[1]=u):u=e[1];let h;e[2]!==c?(h=X("mt-0.5 shrink-0",c),e[2]=c,e[3]=h):h=e[3];let f;e[4]!==d?(f=r.jsx(d,{size:16}),e[4]=d,e[5]=f):f=e[5];let m;e[6]!==h||e[7]!==f?(m=r.jsx("div",{className:h,children:f}),e[6]=h,e[7]=f,e[8]=m):m=e[8];let p;e[9]!==c?(p=X("text-xs mb-1 font-medium",c),e[9]=c,e[10]=p):p=e[10];let g;e[11]!==p||e[12]!==o?(g=r.jsx("div",{className:p,children:o}),e[11]=p,e[12]=o,e[13]=g):g=e[13];let _;e[14]!==a?(_=r.jsx("div",{className:"text-xs line-clamp-2 text-muted-foreground mb-2",children:a}),e[14]=a,e[15]=_):_=e[15];let v;e[16]!==n||e[17]!==t.onContinue||e[18]!==t.onFixInChat?(v=r.jsx("div",{className:"flex gap-2",children:n?r.jsxs(r.Fragment,{children:[r.jsx(ne,{size:"sm",variant:"outline",onClick:t.onFixInChat,className:"h-7 text-xs",children:"Fix in chat"}),r.jsx(ne,{size:"sm",variant:"outline",disabled:!0,className:"h-7 text-xs",children:"Report"})]}):r.jsx(ne,{size:"sm",variant:"outline",onClick:t.onContinue,className:"h-7 text-xs",children:"Continue"})}),e[16]=n,e[17]=t.onContinue,e[18]=t.onFixInChat,e[19]=v):v=e[19];let x;e[20]!==g||e[21]!==_||e[22]!==v?(x=r.jsxs("div",{className:"flex-1 min-w-0",children:[g,_,v]}),e[20]=g,e[21]=_,e[22]=v,e[23]=x):x=e[23];let b;e[24]===Symbol.for("react.memo_cache_sentinel")?(b=r.jsx(fi,{size:14}),e[24]=b):b=e[24];let y;e[25]!==i?(y=r.jsx("button",{type:"button",onClick:i,className:"text-muted-foreground hover:text-foreground transition-colors shrink-0",title:"Dismiss",children:b}),e[25]=i,e[26]=y):y=e[26];let C;return e[27]!==u||e[28]!==y||e[29]!==m||e[30]!==x?(C=r.jsx("div",{className:"px-0.5",children:r.jsxs("div",{className:u,children:[m,x,y]})}),e[27]=u,e[28]=y,e[29]=m,e[30]=x,e[31]=C):C=e[31],C}function ho(){const t=B.c(41),{error:e,clearError:s,finishReason:i,clearFinishReason:n,messages:o,isStreaming:a,isWaitingForApprovals:l,addToolOutput:c,addToolApprovalResponse:d,sendMessage:u}=Ui(),[h,f]=Wi(),{virtualMcpId:m,createTaskWithMessage:p}=es();let g,_,v,x;if(t[0]!==o){const R=o.at(-1);x=R?.role==="assistant"?R.parts.filter(Dx):null,g=x?.filter(Tx)?.length,_=R?.role==="assistant"?mx(R.parts):[],v=R?.role==="assistant"?dx(R.parts):[],t[0]=o,t[1]=g,t[2]=_,t[3]=v,t[4]=x}else g=t[1],_=t[2],v=t[3],x=t[4];const b=v;let y;t[5]!==e||t[6]!==u?(y=()=>{if(e){const M={type:"doc",content:[{type:"paragraph",content:[{type:"text",text:`I encountered this error: ${e.message}. Can you help me fix it?`}]}]};u(M)}},t[5]=e,t[6]=u,t[7]=y):y=t[7];const C=y;let j;t[8]!==u?(j=()=>{u({type:"doc",content:[{type:"paragraph",content:[{type:"text",text:"Please continue."}]}]})},t[8]=u,t[9]=j):j=t[9];const V=j;let w;t[10]!==c?(w=(R,M)=>{c({tool:"user_ask",toolCallId:R.toolCallId,output:{response:M}})},t[10]=c,t[11]=w):w=t[11];const k=w;let T;t[12]!==p||t[13]!==h||t[14]!==f||t[15]!==m?(T=R=>{f({...h,toolApprovalLevel:"auto"}),p({virtualMcpId:m,message:{parts:[{type:"text",text:`Implement this plan:
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/project-app-view-B_z1QorU.js","assets/index-EE9r4ne7.js","assets/index-B2LlXg0m.css","assets/task-status-erNd2Sbl.js","assets/agent-icon-31CiXnkF.js","assets/AlertCircle-CDrkM01U.js","assets/Tool01-DCaYwllU.js","assets/SearchMd-DJ0JdIz3.js","assets/ArrowNarrowLeft-D40KhznE.js","assets/XCircle-rGav0QLs.js","assets/ZapSquare-BYfCzFpy.js","assets/Users03-BIYd5t8v.js","assets/CheckCircle-BTIsSwsN.js","assets/ChevronDown-CYdW9NBw.js","assets/ChevronRight-YkSQYi3B.js","assets/ChevronUp-BcPC1hCC.js","assets/Container-ChD3KoS4.js","assets/Star01-Vcjv0Tzc.js","assets/Palette-D4s8zWmN.js","assets/index-BRiQU6du.js","assets/use-mobile-DP4MR1ix.js","assets/X-D_4PiiTE.js","assets/LinkExternal01-l0w4_WlJ.js","assets/Lock01-CmojMPTn.js","assets/Sun-51uZR1E5.js","assets/Play-CiTVDuYt.js","assets/Plus-CVdax6FK.js","assets/Settings02-D-hypCbK.js","assets/Trash01-D5ZS0TOT.js","assets/Upload01-CBYhGwn0.js","assets/User01-Dq3q9cE-.js","assets/Zap-qFCEz_qt.js","assets/scroll-area-C6ws31M0.js","assets/select-DMKL-iI9.js","assets/use-copy-DGEKKbaG.js","assets/differenceInSeconds-NQ4PDo0z.js","assets/dialog-C0FUDu40.js","assets/content-blocks-o63cs2vh.js","assets/types-BOQuLrVp.js","assets/constants-CdNdiXMf.js","assets/chat-context-Dp5HM8R-.js","assets/use-virtual-mcp-Dn9ixQmR.js","assets/use-collections-CRzXRke9.js","assets/use-ai-providers-CITI1iNq.js","assets/use-decopilot-events-CN7YV5I-.js","assets/create-sse-subscription-CxkOgzKf.js","assets/use-tasks-DGmrkFpo.js","assets/use-organization-settings-CcvcpCtE.js","assets/shell-layout-CDe1Q4z8.js","assets/required-auth-layout-C6TLzB3T.js","assets/use-org-sso-B4mWsSMh.js","assets/integration-icon-BKKqOsd5.js","assets/use-mcp-tools-BKQPDk4x.js"])))=>i.map(i=>d[i]);
2
+ import{o as Mt,r as S,p as Om,q as $m,e as B,s as be,K as lt,n as Fi,a as Br,v as Vs,w as Or,x as Hi,j as r,B as ne,y as Et,c as X,E as Cs,z as pe,C as Wi,_ as zm,t as se,f as Ke,D as yh,F as Fm,R as Sh,G as Hm,H as ys,I as So,J as ds,L as Wm,M as wo,P as Um,Q as Km,T as qm,U as Gm,V as wh,W as Ym,X as Xm,Y as Jm,Z as Qm,$ as lc,l as Ee,b as St,u as Zm,a0 as pr,a1 as vn,a2 as nl,a3 as ol,g as $r,a4 as Vh,d as vi,a5 as ep,a6 as tp,a7 as sp,a8 as ip,a9 as Ch,aa as jh,ab as rp,ac as np,ad as op,ae as Ft,af as ap,ag as lp,ah as cp,ai as dp,aj as Zi,ak as hp,al as up,am as fp,an as mp,ao as kh,ap as pp,aq as gp,ar as _p,as as xp,at as vp,au as bp,av as yp,aw as Sp,ax as wp,ay as Vp,az as Nh,aA as bn,aB as Cp,aC as Ai,aD as nn,aE as Ah,aF as jp,aG as kp}from"./index-EE9r4ne7.js";import{u as ni,a as Ui,b as es,A as Np,C as Ap,c as ia,d as Ep,e as Zn,f as cc,t as Ip}from"./chat-context-Dp5HM8R-.js";import{d as eo,g as si,c as Rp,s as al,t as Tp,a as Dp,M as Mp,i as Pp,b as Cr,e as Lp,F as Bp,f as Eh,S as Op,u as $p,h as dc,j as zp,k as Fp,l as ra,r as Hp,m as Wp,p as Ih,n as Up,o as Kp,q as ll,G as qp,L as Gp,v as Yp,w as Xp,x as Jp,y as Qp}from"./task-status-erNd2Sbl.js";import{S as jr,u as to,P as na,a as Zp,b as eg,c as tg,E as sg,i as ig,d as rg,e as Rh}from"./scroll-area-C6ws31M0.js";import{T as Mi,u as Rs,a as tt,b as st,c as it}from"./use-mobile-DP4MR1ix.js";import{D as Ts,a as Ds,b as cl,c as ms,d as ps,e as dl}from"./dialog-C0FUDu40.js";import{D as so,a as bi,b as yi,c as Si,d as ng,e as og,f as ag}from"./drawer-D4_wXu6X.js";import{C as Th}from"./collection-search-C0B93tJw.js";import{S as Wt,u as Me,g as io,i as Mn,c as lg,W as Os,a as cg,b as hl}from"./constants-CdNdiXMf.js";import{u as Dh,g as ul,T as Mh,a as yn,l as Pn,b as Vo,c as dg}from"./tabs-ZI6fRQkw.js";import{F as Pi,a as It,b as Rt,c as rs,d as Tt,e as Dt,f as hg}from"./form-BQFhlKGv.js";import{I as bt}from"./input-r_oEqK-V.js";import{i as Ph,u as zr,r as Lh}from"./shell-layout-CDe1Q4z8.js";import{D as ot,a as Sn,b as wn,c as js,d as ks,e as Ns,f as Bh,g as Oh,h as hc}from"./dropdown-menu-aG44dJsz.js";import{t as ug,i as $h,n as fg,A as zs,a as zh,b as fl,s as ii,c as mg,d as pg,e as Fh,f as Hh,g as gg,h as ml,j as gr,k as _g,l as pl,m as xg,o as vg,p as Fr,q as Hr,r as bg,u as uc,v as fc,w as yg,x as Sg,y as mc,z as wg,B as gl,C as Wh,D as oa,E as Co,F as pc,G as Vg,H as Cg,I as jg,J as kg,K as Uh,L as Kh,M as qh,N as Gh,O as gc,P as Ng,Q as _r,R as Ag,S as Eg,T as Ig,U as Yh}from"./agent-icon-31CiXnkF.js";import{n as Xh,a as aa,i as Rg,b as Tg,c as Dg}from"./ZapSquare-BYfCzFpy.js";import{i as Jt,t as kr}from"./ChevronDown-CYdW9NBw.js";import{s as Ti}from"./Star01-Vcjv0Tzc.js";import{a as la,t as _l}from"./Tool01-DCaYwllU.js";import{i as Jh}from"./Lock01-CmojMPTn.js";import{s as Qt}from"./Plus-CVdax6FK.js";import{i as Qh}from"./Upload01-CBYhGwn0.js";import{i as fi}from"./X-D_4PiiTE.js";import{i as ri}from"./AlertCircle-CDrkM01U.js";import{S as Js,a as Qs,b as Ht,c as Zs,d as ei}from"./select-DMKL-iI9.js";import{i as xl,a as vl,b as Mg}from"./SearchMd-DJ0JdIz3.js";import{i as ro,t as Pg,a as Lg,b as Bg,c as Og,d as $g,e as Li,f as Zh}from"./XCircle-rGav0QLs.js";import{T as eu,a as Ln}from"./toggle-group-By5F9baT.js";import{u as bl,a as tu}from"./use-ai-providers-CITI1iNq.js";import{m as no,g as zg,i as Fg,a as su,M as iu,N as Hg}from"./select-model-D2d213qn.js";import{S as Wg,A as Ug,a as Kg,b as qg,c as Gg,R as ru,d as Yg,e as Xg}from"./accordion-C_FjDGY7.js";import{r as nu,l as xr,u as Jg,g as Qg}from"./types-BOQuLrVp.js";import{u as oo,a as ts,b as yl}from"./use-virtual-mcp-Dn9ixQmR.js";import{u as Wr,a as Sl,b as wl}from"./use-connection-CeSGdaGP.js";import{p as Zg,q as _c}from"./question-004-sINsf4GQ.js";import{g as xc}from"./ai-providers-logos-CS4PCiqI.js";import{g as ou,s as au}from"./connection-slug-eyAPH6o3.js";import{u as lu,a as cu,g as e_,C as jo}from"./connection-card-CJ6uOT9E.js";import{C as du}from"./collection-tabs-CMC3SILy.js";import{g as hu}from"./constants-BG70AVFL.js";import{T as ca}from"./textarea-CpW5pfml.js";import{n as Vn}from"./Container-ChD3KoS4.js";import{c as t_,i as on,a as vc,E as s_,p as i_,b as r_,d as n_}from"./connection-form-helpers-CDPt3S_P.js";import{u as bc}from"./use-infinite-scroll-DjXaeUEQ.js";import{u as o_,C as a_,a as yc,b as Sc,c as l_,d as c_,e as d_,f as h_}from"./command-CRMnQTof.js";import{g as u_,e as f_,a as m_}from"./extract-connection-data-CAAXAkZY.js";import{B as wc}from"./badge-BhfSxzi-.js";import{i as Vl}from"./ChevronRight-YkSQYi3B.js";import{I as Ms}from"./integration-icon-BKKqOsd5.js";import{S as Bi}from"./skeleton-C8k5qVSG.js";import{a as ao}from"./Users03-BIYd5t8v.js";import{I as Bn,S as uu,G as p_,L as g_,a as __,b as fu}from"./lean-canvas-recruit-modal-TnasvQfT.js";import{u as lo,a as mu}from"./use-navigate-to-agent-C0iuNKaP.js";import{u as pu}from"./use-create-virtual-mcp-UIh1S6RD.js";import{i as x_}from"./CheckCircle-BTIsSwsN.js";import{P as oi,a as ai,b as li}from"./popover-BktSfQG9.js";import{u as wi,a as v_}from"./use-mcp-tools-BKQPDk4x.js";import{E as Oi}from"./empty-state-BjAjwUcB.js";import{u as b_}from"./use-decopilot-events-CN7YV5I-.js";import{i as $i}from"./Zap-qFCEz_qt.js";import{i as gu,S as Ur,a as Kr,b as gs,u as qr,c as us,d as Zt,e as _u,f as xu,g as y_,h as vu,j as bu,P as hs,k as S_,l as w_,m as V_,n as C_,o as j_,p as k_}from"./index-BRiQU6du.js";import{A as Vc}from"./avatar-BVvDTfBW.js";import{n as N_,a as A_,i as E_}from"./Sun-51uZR1E5.js";import{a as Gr}from"./Settings02-D-hypCbK.js";import{A as Cl,a as jl,b as kl,c as Nl,d as Al,e as El,f as Il,g as yu}from"./alert-dialog-BpydK2MI.js";import"./index-CIlSPTSj.js";import{u as Su}from"./use-tasks-DGmrkFpo.js";import{u as I_}from"./use-status-sounds-ChUYFOhF.js";import{T as R_,u as wu}from"./tools-list-2T2hc8nL.js";import{u as ko}from"./unwrap-tool-result-BYXdCQMg.js";import{C as T_,a as Cc}from"./card-BAp6Jwgi.js";import{L as vr}from"./label-CenAgqhm.js";import{S as da}from"./switch-BlmZa3uf.js";import{i as Cn}from"./Play-CiTVDuYt.js";import{s as ha}from"./Trash01-D5ZS0TOT.js";import{C as D_}from"./checkbox-BhkHXCse.js";import{n as Vi}from"./LinkExternal01-l0w4_WlJ.js";import{V as M_}from"./view-mode-toggle-BTfIGFL4.js";import{U as P_}from"./user-D7q59BB0.js";import{u as Yr,a as L_,b as B_,c as O_,A as $_,d as z_}from"./automation-list-row-mTTWiKQ6.js";import{S as F_}from"./search-input-Dxw50-Fc.js";import"./use-collections-CRzXRke9.js";import"./use-organization-settings-CcvcpCtE.js";import"./use-copy-DGEKKbaG.js";import"./differenceInSeconds-NQ4PDo0z.js";import"./content-blocks-o63cs2vh.js";import"./required-auth-layout-C6TLzB3T.js";import"./use-org-sso-B4mWsSMh.js";import"./ArrowNarrowLeft-D40KhznE.js";import"./ChevronUp-BcPC1hCC.js";import"./Palette-D4s8zWmN.js";import"./User01-Dq3q9cE-.js";import"./formatDistanceToNow-Cb2QZZJn.js";import"./use-registry-connections-Bj_DPVwf.js";import"./useInfiniteQuery-7hq96Va6.js";import"./infiniteQueryObserver-BQYXKuj2.js";import"./collections-DIuw_dNV.js";import"./index-C6SXa4V4.js";import"./create-sse-subscription-CxkOgzKf.js";function H_(t,e){const s=Mt(e);return W_({filters:{...t,status:"pending"}},s).length}function jc(t,e){return t.findAll(e.filters).map(s=>e.select?e.select(s):s.state)}function W_(t={},e){const s=Mt(e).getMutationCache(),i=S.useRef(t),n=S.useRef(null);return n.current===null&&(n.current=jc(s,t)),S.useEffect(()=>{i.current=t}),S.useSyncExternalStore(S.useCallback(o=>s.subscribe(()=>{const a=Om(n.current,jc(s,i.current));n.current!==a&&(n.current=a,$m.schedule(o))}),[s]),()=>n.current,()=>n.current)}function U_(t,e){const s=B.c(37),{org:i,locator:n}=be();let o;s[0]!==i.id?(o={connectionId:Wt,orgId:i.id},s[0]=i.id,s[1]=o):o=s[1];const a=Me(o),l=Mt();let c;s[2]!==t||s[3]!==i.id?(c=lt.ensureTask(i.id,t),s[2]=t,s[3]=i.id,s[4]=c):c=s[4];let d;s[5]!==a||s[6]!==t?(d=async()=>(await a.callTool({name:"COLLECTION_THREADS_GET",arguments:{id:t}})).structuredContent?.item??null,s[5]=a,s[6]=t,s[7]=d):d=s[7];let u;s[8]!==c||s[9]!==d?(u={queryKey:c,queryFn:d,retry:!1,refetchOnWindowFocus:!1},s[8]=c,s[9]=d,s[10]=u):u=s[10];const h=Fi(u);let f;s[11]!==a||s[12]!==e?(f=async b=>{const y=await a.callTool({name:"COLLECTION_THREADS_CREATE",arguments:{data:{id:b,virtual_mcp_id:e}}});if(y.isError){const j=y.content,V=Array.isArray(j)&&j[0]&&typeof j[0]=="object"?j[0].text??"Create failed":"Create failed";throw new Error(V)}return y.structuredContent.item},s[11]=a,s[12]=e,s[13]=f):f=s[13];let m;s[14]!==n||s[15]!==i.id||s[16]!==h||s[17]!==l?(m=()=>{l.invalidateQueries({predicate:b=>b.queryKey[1]===i.id&&b.queryKey[3]==="collection"&&b.queryKey[4]==="THREADS"}),l.invalidateQueries({queryKey:lt.tasksPrefix(n)}),h.refetch()},s[14]=n,s[15]=i.id,s[16]=h,s[17]=l,s[18]=m):m=s[18];let p;s[19]!==f||s[20]!==m?(p={mutationFn:f,onSuccess:m},s[19]=f,s[20]=m,s[21]=p):p=s[21];const g=Br(p);let _,v;if(s[22]!==g||s[23]!==t||s[24]!==h.data||s[25]!==h.isSuccess?(_=()=>{!h.isSuccess||h.data||g.isPending||g.variables!==t&&g.mutate(t)},v=[t,h.isSuccess,h.data,g],s[22]=g,s[23]=t,s[24]=h.data,s[25]=h.isSuccess,s[26]=_,s[27]=v):(_=s[26],v=s[27]),S.useEffect(_,v),h.isLoading){let b;return s[28]===Symbol.for("react.memo_cache_sentinel")?(b={status:"loading"},s[28]=b):b=s[28],b}if(h.isError){const b=h.error;let y;return s[29]!==b?(y={status:"error",error:b},s[29]=b,s[30]=y):y=s[30],y}if(h.isSuccess&&h.data){let b;return s[31]!==h.data?(b={status:"ready",task:h.data},s[31]=h.data,s[32]=b):b=s[32],b}if(g.isPending||h.isSuccess&&!h.data){let b;return s[33]===Symbol.for("react.memo_cache_sentinel")?(b={status:"creating"},s[33]=b):b=s[33],b}if(g.isError){let b;return s[34]!==g.error?(b={status:"error",error:g.error},s[34]=g.error,s[35]=b):b=s[35],b}let x;return s[36]===Symbol.for("react.memo_cache_sentinel")?(x={status:"loading"},s[36]=x):x=s[36],x}function K_(t){const e={};for(const s of t.arguments??[])e[s.name]=s.required?Et().min(1,"Required"):Et();return Vs(e)}function q_(t){const e={};for(const s of t.arguments??[])e[s.name]="";return e}function Rl(t){const e=B.c(65),{prompt:s,setPrompt:i,onSubmit:n}=t,o=S.useId();let a;if(e[0]!==s){const D=s?K_(s):Vs({});a=Or(D),e[0]=s,e[1]=a}else a=e[1];const c=a;let d;e[2]!==s?(d=s?q_(s):{},e[2]=s,e[3]=d):d=e[3];let u;e[4]!==c||e[5]!==d?(u={resolver:c,defaultValues:d,mode:"onChange"},e[4]=c,e[5]=d,e[6]=u):u=e[6];const h=Hi(u);let f;e[7]!==s?.arguments?(f=s?.arguments??[],e[7]=s?.arguments,e[8]=f):f=e[8];const m=f;let p;e[9]!==h||e[10]!==n||e[11]!==i?(p=async D=>{await n(D),i(null),h.reset()},e[9]=h,e[10]=n,e[11]=i,e[12]=p):p=e[12];const g=p;let _;e[13]!==h||e[14]!==i?(_=D=>{D||(h.reset(),i(null))},e[13]=h,e[14]=i,e[15]=_):_=e[15];const v=_;if(!s)return null;let x;e[16]!==s._meta||e[17]!==s.name||e[18]!==s.title?(x=s.title||eo(s.name,si(s._meta)),e[16]=s._meta,e[17]=s.name,e[18]=s.title,e[19]=x):x=e[19];let b;e[20]!==x?(b=r.jsx(Ts,{children:r.jsx("span",{className:"capitalize",children:x})}),e[20]=x,e[21]=b):b=e[21];let y;e[22]!==s.description?(y=s.description&&r.jsx("p",{className:"text-sm text-muted-foreground",children:s.description}),e[22]=s.description,e[23]=y):y=e[23];let C;e[24]!==y||e[25]!==b?(C=r.jsxs(Ds,{children:[b,y]}),e[24]=y,e[25]=b,e[26]=C):C=e[26];let j;e[27]!==h||e[28]!==g?(j=D=>{D.stopPropagation(),h.handleSubmit(g)(D)},e[27]=h,e[28]=g,e[29]=j):j=e[29];let V;if(e[30]!==m||e[31]!==h.control||e[32]!==h.formState.isSubmitting){let D;e[34]!==h.control||e[35]!==h.formState.isSubmitting?(D=P=>r.jsx(It,{control:h.control,name:P.name,render:O=>{const{field:z}=O;return r.jsxs(Rt,{children:[r.jsxs(rs,{className:"text-xs",children:[P.name,P.required?null:r.jsxs("span",{className:"text-muted-foreground font-normal",children:[" ","(optional)"]})]}),r.jsx(Tt,{children:r.jsx(bt,{...z,value:z.value??"",required:P.required,placeholder:P.description??"",className:"h-9",disabled:h.formState.isSubmitting})}),r.jsx(Dt,{})]})}},P.name),e[34]=h.control,e[35]=h.formState.isSubmitting,e[36]=D):D=e[36],V=m.map(D),e[30]=m,e[31]=h.control,e[32]=h.formState.isSubmitting,e[33]=V}else V=e[33];let w;e[37]!==v?(w=()=>v(!1),e[37]=v,e[38]=w):w=e[38];let k;e[39]!==h.formState.isSubmitting||e[40]!==w?(k=r.jsx(ne,{type:"button",variant:"ghost",onClick:w,disabled:h.formState.isSubmitting,children:"Cancel"}),e[39]=h.formState.isSubmitting,e[40]=w,e[41]=k):k=e[41];const T=!h.formState.isValid||h.formState.isSubmitting;let I;e[42]!==h.formState.isSubmitting?(I=h.formState.isSubmitting?r.jsxs("span",{className:"flex items-center gap-2",children:[r.jsx(jr,{size:"xs"}),"Loading..."]}):"Use prompt",e[42]=h.formState.isSubmitting,e[43]=I):I=e[43];let A;e[44]!==o||e[45]!==T||e[46]!==I?(A=r.jsx(ne,{type:"submit",form:o,disabled:T,children:I}),e[44]=o,e[45]=T,e[46]=I,e[47]=A):A=e[47];let N;e[48]!==k||e[49]!==A?(N=r.jsxs(cl,{children:[k,A]}),e[48]=k,e[49]=A,e[50]=N):N=e[50];let E;e[51]!==o||e[52]!==j||e[53]!==V||e[54]!==N?(E=r.jsxs("form",{id:o,className:"space-y-4 py-4",autoComplete:"off",onSubmit:j,children:[V,N]}),e[51]=o,e[52]=j,e[53]=V,e[54]=N,e[55]=E):E=e[55];let R;e[56]!==h||e[57]!==E?(R=r.jsx(Pi,{...h,children:E}),e[56]=h,e[57]=E,e[58]=R):R=e[58];let M;e[59]!==C||e[60]!==R?(M=r.jsxs(ms,{className:"sm:max-w-lg max-h-[80vh] overflow-y-auto",children:[C,R]}),e[59]=C,e[60]=R,e[61]=M):M=e[61];let L;return e[62]!==v||e[63]!==M?(L=r.jsx(ps,{open:!0,onOpenChange:v,children:M}),e[62]=v,e[63]=M,e[64]=L):L=e[64],L}function G_(t){return!t||!t.content||t.content.length===0?!0:t.content.every(e=>e.type==="paragraph"?!e.content||e.content.length===0?!0:e.content.every(s=>s.type==="hardBreak"||s.type==="text"&&(!s.text||s.text.trim()==="")):!1)}function Y_(t,e){return{type:"doc",content:[...t?.content??[],e].filter(Boolean)}}const kc=3,Vu="inline-flex items-center gap-2 px-5 py-2.5 rounded-full bg-muted text-muted-foreground text-sm font-medium transition-colors cursor-pointer",X_="flex flex-col gap-1.5 p-4 rounded-xl bg-accent/40 text-sm leading-snug transition-colors cursor-pointer text-left";function Cu(t){const e=B.c(46),{item:s,onSelect:i,isLoading:n,isDisabled:o,variant:a}=t,l=a===void 0?"pill":a,{prompt:c}=s;let d;if(e[0]!==c._meta||e[1]!==c.name||e[2]!==c.title){const V=si(c._meta);d=c.title??eo(c.name,V),e[0]=c._meta,e[1]=c.name,e[2]=c.title,e[3]=d}else d=e[3];const u=d,h=c.description||null;if(l==="card"){let V;e[4]!==i||e[5]!==c?(V=()=>i(c),e[4]=i,e[5]=c,e[6]=V):V=e[6];const w=o||n,k=n&&"bg-accent/40",T=(o||n)&&"cursor-not-allowed opacity-50";let I;e[7]!==k||e[8]!==T?(I=X(X_,"hover:bg-accent/60 text-foreground",k,T),e[7]=k,e[8]=T,e[9]=I):I=e[9];let A;e[10]!==u?(A=r.jsx("span",{className:"font-medium truncate capitalize",children:u}),e[10]=u,e[11]=A):A=e[11];let N;e[12]!==n?(N=n&&r.jsx(jr,{size:"xs"}),e[12]=n,e[13]=N):N=e[13];let E;e[14]!==A||e[15]!==N?(E=r.jsxs("div",{className:"flex items-center justify-between gap-2",children:[A,N]}),e[14]=A,e[15]=N,e[16]=E):E=e[16];let R;e[17]!==h?(R=h&&r.jsx("span",{className:"text-xs text-muted-foreground line-clamp-2",children:h}),e[17]=h,e[18]=R):R=e[18];let M;return e[19]!==E||e[20]!==R||e[21]!==V||e[22]!==w||e[23]!==I?(M=r.jsxs("button",{type:"button",onClick:V,disabled:w,className:I,children:[E,R]}),e[19]=E,e[20]=R,e[21]=V,e[22]=w,e[23]=I,e[24]=M):M=e[24],M}let f;e[25]!==i||e[26]!==c?(f=()=>i(c),e[25]=i,e[26]=c,e[27]=f):f=e[27];const m=o||n,p=n&&"bg-muted/50",g=(o||n)&&"cursor-not-allowed opacity-50";let _;e[28]!==p||e[29]!==g?(_=X(Vu,"hover:bg-muted/70 hover:text-foreground",p,g),e[28]=p,e[29]=g,e[30]=_):_=e[30];let v;e[31]!==u?(v=r.jsx("span",{className:"capitalize",children:u}),e[31]=u,e[32]=v):v=e[32];let x;e[33]!==n?(x=n&&r.jsx(jr,{size:"xs"}),e[33]=n,e[34]=x):x=e[34];let b;e[35]!==f||e[36]!==m||e[37]!==_||e[38]!==v||e[39]!==x?(b=r.jsx(tt,{asChild:!0,children:r.jsxs("button",{type:"button",onClick:f,disabled:m,className:_,children:[v,x]})}),e[35]=f,e[36]=m,e[37]=_,e[38]=v,e[39]=x,e[40]=b):b=e[40];const y=h??u;let C;e[41]!==y?(C=r.jsx(st,{side:"top",className:"max-w-xs",children:r.jsx("p",{className:"text-xs",children:y})}),e[41]=y,e[42]=C):C=e[42];let j;return e[43]!==b||e[44]!==C?(j=r.jsxs(it,{delayDuration:400,children:[b,C]}),e[43]=b,e[44]=C,e[45]=j):j=e[45],j}function J_(t){const e=B.c(41),{items:s,open:i,onOpenChange:n,onSelect:o,loadingPrompt:a}=t,[l,c]=S.useState(""),d=!!a;let u;e[0]!==s||e[1]!==l?(u=l.trim()?s.filter(w=>{const k=l.toLowerCase();return w.prompt.name.toLowerCase().includes(k)||(w.prompt.title??"").toLowerCase().includes(k)||(w.prompt.description??"").toLowerCase().includes(k)}):s,e[0]=s,e[1]=l,e[2]=u):u=e[2];const h=u,f=Rs();let m;e[3]!==h.length||e[4]!==l?(m=h.length===0&&r.jsxs("p",{className:"col-span-4 text-sm text-muted-foreground text-center py-8",children:["No prompts match “",l,"”"]}),e[3]=h.length,e[4]=l,e[5]=m):m=e[5];let p;if(e[6]!==h||e[7]!==d||e[8]!==a?.name||e[9]!==n||e[10]!==o){let w;e[12]!==d||e[13]!==a?.name||e[14]!==n||e[15]!==o?(w=k=>r.jsx(Cu,{item:k,variant:"card",onSelect:T=>{n(!1),o(T)},isLoading:a?.name===k.prompt.name,isDisabled:d&&a?.name!==k.prompt.name},k.prompt.name),e[12]=d,e[13]=a?.name,e[14]=n,e[15]=o,e[16]=w):w=e[16],p=h.map(w),e[6]=h,e[7]=d,e[8]=a?.name,e[9]=n,e[10]=o,e[11]=p}else p=e[11];let g;e[17]!==m||e[18]!==p?(g=r.jsx("div",{className:"flex-1 overflow-y-auto [scrollbar-gutter:stable]",children:r.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 gap-3 p-5",children:[m,p]})}),e[17]=m,e[18]=p,e[19]=g):g=e[19];const _=g;let v;e[20]===Symbol.for("react.memo_cache_sentinel")?(v=w=>{w.key==="Escape"&&c("")},e[20]=v):v=e[20];let x;e[21]!==l?(x=r.jsx(Th,{value:l,onChange:c,placeholder:"Search prompts...",onKeyDown:v}),e[21]=l,e[22]=x):x=e[22];const b=x;if(f){let w;e[23]===Symbol.for("react.memo_cache_sentinel")?(w=r.jsx(so,{className:"sr-only",children:r.jsx(bi,{children:"All prompts"})}),e[23]=w):w=e[23];let k;e[24]===Symbol.for("react.memo_cache_sentinel")?(k=r.jsx("div",{className:"flex items-center h-12 border-b border-border px-4 shrink-0",children:r.jsx("span",{className:"text-sm font-medium text-foreground",children:"Prompts"})}),e[24]=k):k=e[24];let T;e[25]!==_||e[26]!==b?(T=r.jsxs(yi,{className:"h-[85vh] flex flex-col p-0 gap-0",children:[w,k,b,_]}),e[25]=_,e[26]=b,e[27]=T):T=e[27];let I;return e[28]!==n||e[29]!==i||e[30]!==T?(I=r.jsx(Mi,{delayDuration:400,children:r.jsx(Si,{open:i,onOpenChange:n,children:T})}),e[28]=n,e[29]=i,e[30]=T,e[31]=I):I=e[31],I}let y;e[32]===Symbol.for("react.memo_cache_sentinel")?(y=r.jsx(Ds,{className:"sr-only",children:r.jsx(Ts,{children:"All prompts"})}),e[32]=y):y=e[32];let C;e[33]===Symbol.for("react.memo_cache_sentinel")?(C=r.jsx("div",{className:"flex items-center h-12 border-b border-border px-4 shrink-0",children:r.jsx("span",{className:"text-sm font-medium text-foreground",children:"Prompts"})}),e[33]=C):C=e[33];let j;e[34]!==_||e[35]!==b?(j=r.jsxs(ms,{className:"sm:max-w-[1100px] h-[680px] p-0 gap-0 overflow-hidden flex flex-col",children:[y,C,b,_]}),e[34]=_,e[35]=b,e[36]=j):j=e[36];let V;return e[37]!==n||e[38]!==i||e[39]!==j?(V=r.jsx(Mi,{delayDuration:400,children:r.jsx(ps,{open:i,onOpenChange:n,children:j})}),e[37]=n,e[38]=i,e[39]=j,e[40]=V):V=e[40],V}function Q_(t){const e=B.c(29),{items:s,onSelect:i,loadingPrompt:n,className:o}=t,[a,l]=S.useState(!1);if(s.length===0)return null;let c,d,u;if(e[0]!==s||e[1]!==n||e[2]!==i){const v=s.slice(0,kc);let x;e[6]!==s?(x=s.slice(kc),e[6]=s,e[7]=x):x=e[7],c=x,d=!!n;let b;e[8]!==d||e[9]!==n?.name||e[10]!==i?(b=y=>r.jsx(Cu,{item:y,onSelect:i,isLoading:n?.name===y.prompt.name,isDisabled:d&&n?.name!==y.prompt.name},y.prompt.name),e[8]=d,e[9]=n?.name,e[10]=i,e[11]=b):b=e[11],u=v.map(b),e[0]=s,e[1]=n,e[2]=i,e[3]=c,e[4]=d,e[5]=u}else c=e[3],d=e[4],u=e[5];const h=u;let f;e[12]!==o?(f=X("w-full flex flex-wrap gap-2 justify-center",o),e[12]=o,e[13]=f):f=e[13];let m;e[14]!==c.length||e[15]!==d?(m=c.length>0&&r.jsxs("button",{type:"button",disabled:d,onClick:()=>l(!0),className:X(Vu,"hover:bg-muted/70 hover:text-foreground",d&&"opacity-50 cursor-not-allowed"),children:["+",c.length," more"]}),e[14]=c.length,e[15]=d,e[16]=m):m=e[16];let p;e[17]!==h||e[18]!==f||e[19]!==m?(p=r.jsxs("div",{className:f,children:[h,m]}),e[17]=h,e[18]=f,e[19]=m,e[20]=p):p=e[20];let g;e[21]!==s||e[22]!==n||e[23]!==a||e[24]!==i?(g=r.jsx(J_,{items:s,open:a,onOpenChange:l,onSelect:i,loadingPrompt:n}),e[21]=s,e[22]=n,e[23]=a,e[24]=i,e[25]=g):g=e[25];let _;return e[26]!==p||e[27]!==g?(_=r.jsxs(Mi,{delayDuration:400,children:[p,g]}),e[26]=p,e[27]=g,e[28]=_):_=e[28],_}function Z_(){return null}function ex(t,e){switch(e.type){case"SELECT_PROMPT":return!e.prompt.arguments||e.prompt.arguments.length===0?{stage:"loading",prompt:e.prompt}:{stage:"idle"};case"START_LOADING":return{stage:"loading",prompt:e.prompt,arguments:e.arguments};case"RESET":return{stage:"idle"};default:return t}}function tx(t){const e=B.c(30),{connectionId:s}=t,{sendMessage:i}=Ui(),{tiptapDocRef:n}=ni(),{org:o}=be();let a;e[0]!==s||e[1]!==o.id?(a={connectionId:s,orgId:o.id},e[0]=s,e[1]=o.id,e[2]=a):a=e[2];const l=Me(a);let c;e[3]!==l?(c={client:l,staleTime:6e4},e[3]=l,e[4]=c):c=e[4];const{data:d}=Dh(c);let u;e[5]!==d?.prompts?(u=d?.prompts??[],e[5]=d?.prompts,e[6]=u):u=e[6];const h=u;let f;e[7]!==h?(f=h.map(sx),e[7]=h,e[8]=f):f=e[8];const m=f;let p;e[9]===Symbol.for("react.memo_cache_sentinel")?(p={stage:"idle"},e[9]=p):p=e[9];const[g,_]=S.useReducer(ex,p),[v,x]=S.useState(null);let b;e[10]!==l||e[11]!==i||e[12]!==n?(b=async(E,R)=>{if(!l){pe.error("MCP client not available"),_({type:"RESET"});return}try{const M=await ul(l,E.name,R);_({type:"RESET"});const L=Y_(n.current,{type:"paragraph",content:[Rp({id:E.name,name:al(E.name,si(E._meta)),metadata:M.messages,char:"/"})]});await i(L)}catch(M){console.error("[ice-breakers] Failed to fetch prompt:",M),pe.error("Failed to load prompt. Please try again."),_({type:"RESET"})}},e[10]=l,e[11]=i,e[12]=n,e[13]=b):b=e[13];const y=b;let C;e[14]!==y?(C=async E=>{if(E.arguments&&E.arguments.length>0){_({type:"SELECT_PROMPT",prompt:E}),x(E);return}_({type:"START_LOADING",prompt:E}),await y(E)},e[14]=y,e[15]=C):C=e[15];const j=C;let V;e[16]!==v||e[17]!==y?(V=async E=>{v&&(_({type:"START_LOADING",prompt:v,arguments:E}),x(null),await y(v,E))},e[16]=v,e[17]=y,e[18]=V):V=e[18];const w=V;if(m.length===0)return null;const k=g.stage==="loading"?g.prompt:null;let T;e[19]!==j||e[20]!==m||e[21]!==k?(T=r.jsx(Q_,{items:m,onSelect:j,loadingPrompt:k}),e[19]=j,e[20]=m,e[21]=k,e[22]=T):T=e[22];let I;e[23]===Symbol.for("react.memo_cache_sentinel")?(I=()=>{x(null),_({type:"RESET"})},e[23]=I):I=e[23];let A;e[24]!==v||e[25]!==w?(A=r.jsx(Rl,{prompt:v,setPrompt:I,onSubmit:w}),e[24]=v,e[25]=w,e[26]=A):A=e[26];let N;return e[27]!==T||e[28]!==A?(N=r.jsxs(r.Fragment,{children:[T,A]}),e[27]=T,e[28]=A,e[29]=N):N=e[29],N}function sx(t){return{prompt:t}}function ix(t){const e=B.c(13),{className:s}=t,{selectedVirtualMcp:i}=ni(),{org:n}=be();let o;e[0]!==n.id?(o=io(n.id),e[0]=n.id,e[1]=o):o=e[1];const a=o.id,l=i?.id??a;let c;e[2]!==s?(c=X("w-full @container",s),e[2]=s,e[3]=c):c=e[3];const d=l??"default";let u;e[4]===Symbol.for("react.memo_cache_sentinel")?(u=r.jsx(Z_,{}),e[4]=u):u=e[4];let h;e[5]!==l?(h=r.jsx(tx,{connectionId:l}),e[5]=l,e[6]=h):h=e[6];let f;e[7]!==d||e[8]!==h?(f=r.jsx(Cs,{fallback:null,children:r.jsx(S.Suspense,{fallback:u,children:h},d)}),e[7]=d,e[8]=h,e[9]=f):f=e[9];let m;return e[10]!==c||e[11]!==f?(m=r.jsx("div",{className:c,children:f}),e[10]=c,e[11]=f,e[12]=m):m=e[12],m}function ju(t){const e=B.c(21),{current:s,total:i,onPrev:n,onNext:o}=t;if(i<=1)return null;const a=s===0,l=s===0?"opacity-30 cursor-not-allowed":"hover:text-foreground cursor-pointer";let c;e[0]!==l?(c=X("p-0.5 rounded transition-colors",l),e[0]=l,e[1]=c):c=e[1];let d;e[2]===Symbol.for("react.memo_cache_sentinel")?(d=r.jsx(xl,{size:14}),e[2]=d):d=e[2];let u;e[3]!==n||e[4]!==a||e[5]!==c?(u=r.jsx("button",{type:"button",onClick:n,disabled:a,className:c,"aria-label":"Previous question",children:d}),e[3]=n,e[4]=a,e[5]=c,e[6]=u):u=e[6];const h=s+1;let f;e[7]!==h||e[8]!==i?(f=r.jsxs("span",{className:"tabular-nums text-xs",children:[h," of ",i]}),e[7]=h,e[8]=i,e[9]=f):f=e[9];const m=s===i-1,p=s===i-1?"opacity-30 cursor-not-allowed":"hover:text-foreground cursor-pointer";let g;e[10]!==p?(g=X("p-0.5 rounded transition-colors",p),e[10]=p,e[11]=g):g=e[11];let _;e[12]===Symbol.for("react.memo_cache_sentinel")?(_=r.jsx(ro,{size:14}),e[12]=_):_=e[12];let v;e[13]!==o||e[14]!==g||e[15]!==m?(v=r.jsx("button",{type:"button",onClick:o,disabled:m,className:g,"aria-label":"Next question",children:_}),e[13]=o,e[14]=g,e[15]=m,e[16]=v):v=e[16];let x;return e[17]!==v||e[18]!==u||e[19]!==f?(x=r.jsxs("div",{className:"flex items-center gap-1 text-sm text-muted-foreground",children:[u,f,v]}),e[17]=v,e[18]=u,e[19]=f,e[20]=x):x=e[20],x}function On(t){const e=B.c(18),{title:s,children:i,footerLeft:n,footerRight:o,className:a}=t,l=a??"border-border";let c;e[0]!==l?(c=X("flex flex-col rounded-xl bg-background border shadow-md w-[calc(100%-16px)] max-w-[584px] mx-auto mb-[-16px]",l),e[0]=l,e[1]=c):c=e[1];let d;e[2]!==s?(d=r.jsx("div",{className:"flex items-center gap-2 p-4",children:r.jsx("p",{className:"flex-1 text-base font-medium text-foreground min-w-0",children:s})}),e[2]=s,e[3]=d):d=e[3];let u;e[4]!==i?(u=r.jsx("div",{className:"overflow-clip pb-4",children:i}),e[4]=i,e[5]=u):u=e[5];let h;e[6]!==n?(h=r.jsx("div",{children:n}),e[6]=n,e[7]=h):h=e[7];let f;e[8]!==o?(f=r.jsx("div",{className:"flex items-center gap-2",children:o}),e[8]=o,e[9]=f):f=e[9];let m;e[10]!==h||e[11]!==f?(m=r.jsx("div",{className:"border-t border-border px-3 py-3 pb-6",children:r.jsxs("div",{className:"flex items-center justify-between",children:[h,f]})}),e[10]=h,e[11]=f,e[12]=m):m=e[12];let p;return e[13]!==c||e[14]!==d||e[15]!==u||e[16]!==m?(p=r.jsxs("div",{className:c,children:[d,u,m]}),e[13]=c,e[14]=d,e[15]=u,e[16]=m,e[17]=p):p=e[17],p}const rx="User denied this tool call, give other alternatives.",nx=[{value:"readonly",label:"Ask before edit"},{value:"auto",label:"Auto approve"}];function ox(t){const e=B.c(9),{onYolo:s}=t,[i,n]=Wi();let o;e[0]!==s||e[1]!==i||e[2]!==n?(o=u=>{const h=u;n({...i,toolApprovalLevel:h}),h==="auto"&&s()},e[0]=s,e[1]=i,e[2]=n,e[3]=o):o=e[3];const a=o;let l;e[4]===Symbol.for("react.memo_cache_sentinel")?(l=r.jsx(Zs,{size:"xs",className:"text-xs text-muted-foreground border-border/60 bg-transparent hover:bg-accent/60 h-7 gap-1",onClick:lx,children:r.jsx(ei,{})}),e[4]=l):l=e[4];let c;e[5]===Symbol.for("react.memo_cache_sentinel")?(c=r.jsx(Js,{children:nx.map(ax)}),e[5]=c):c=e[5];let d;return e[6]!==a||e[7]!==i.toolApprovalLevel?(d=r.jsxs(Qs,{value:i.toolApprovalLevel,onValueChange:a,children:[l,c]}),e[6]=a,e[7]=i.toolApprovalLevel,e[8]=d):d=e[8],d}function ax(t){return r.jsx(Ht,{value:t.value,children:t.label},t.value)}function lx(t){return t.stopPropagation()}function cx(t){const e=B.c(5),{input:s}=t;if(s==null){let o;return e[0]===Symbol.for("react.memo_cache_sentinel")?(o=r.jsx("div",{className:"px-4 text-xs text-muted-foreground",children:"No input"}),e[0]=o):o=e[0],o}let i;try{let o;e[1]!==s?(o=JSON.stringify(s,null,2),e[1]=s,e[2]=o):o=e[2],i=o}catch{i=String(s)}let n;return e[3]!==i?(n=r.jsx("div",{className:"px-4",children:r.jsx("pre",{className:"text-xs font-mono text-muted-foreground/70 whitespace-pre-wrap wrap-break-word max-h-32 overflow-y-auto rounded-md bg-muted/30 px-3 py-2",children:i})}),e[3]=i,e[4]=n):n=e[4],n}function dx(t){const e=B.c(42),{approvals:s,onRespond:i}=t,[n,o]=S.useState(0),a=Math.min(n,s.length-1),l=s[a];if(!l)return null;let c;e[0]!==l.approvalId||e[1]!==i?(c=()=>{i(l.approvalId,!1,rx)},e[0]=l.approvalId,e[1]=i,e[2]=c):c=e[2];const d=c;let u;e[3]!==l.approvalId||e[4]!==i?(u=()=>{i(l.approvalId,!0)},e[3]=l.approvalId,e[4]=i,e[5]=u):u=e[5];const h=u;let f;e[6]!==s||e[7]!==i?(f=()=>{for(const N of s)i(N.approvalId,!0)},e[6]=s,e[7]=i,e[8]=f):f=e[8];const m=f;let p;e[9]!==a?(p=()=>{a>0&&o(a-1)},e[9]=a,e[10]=p):p=e[10];const g=p;let _;e[11]!==s.length||e[12]!==a?(_=()=>{a<s.length-1&&o(a+1)},e[11]=s.length,e[12]=a,e[13]=_):_=e[13];const v=_;let x;e[14]!==m?(x=r.jsx(ox,{onYolo:m}),e[14]=m,e[15]=x):x=e[15];let b;e[16]!==s.length||e[17]!==v||e[18]!==g||e[19]!==a?(b=r.jsx(ju,{current:a,total:s.length,onPrev:g,onNext:v}),e[16]=s.length,e[17]=v,e[18]=g,e[19]=a,e[20]=b):b=e[20];let y;e[21]!==x||e[22]!==b?(y=r.jsxs("div",{className:"flex items-center gap-2",children:[x,b]}),e[21]=x,e[22]=b,e[23]=y):y=e[23];const C=y;let j;e[24]!==d?(j=r.jsx(ne,{type:"button",variant:"ghost",size:"sm",className:"h-7 px-2.5 text-xs text-muted-foreground [@media(hover:hover)]:hover:text-foreground active:scale-[0.97] transition-transform",onClick:d,children:"Deny"}),e[24]=d,e[25]=j):j=e[25];let V;e[26]!==s.length||e[27]!==m?(V=s.length>1&&r.jsx(ne,{type:"button",variant:"outline",size:"sm",className:"h-7 px-2.5 text-xs active:scale-[0.97] transition-transform",onClick:m,children:"Accept All"}),e[26]=s.length,e[27]=m,e[28]=V):V=e[28];let w;e[29]!==h?(w=r.jsx(ne,{type:"button",size:"sm",className:"h-7 px-2.5 text-xs active:scale-[0.97] transition-transform",onClick:h,children:"Accept"}),e[29]=h,e[30]=w):w=e[30];let k;e[31]!==V||e[32]!==w||e[33]!==j?(k=r.jsxs(r.Fragment,{children:[j,V,w]}),e[31]=V,e[32]=w,e[33]=j,e[34]=k):k=e[34];const T=k;let I;e[35]!==l.input?(I=r.jsx(cx,{input:l.input}),e[35]=l.input,e[36]=I):I=e[36];let A;return e[37]!==l.friendlyName||e[38]!==C||e[39]!==T||e[40]!==I?(A=r.jsx(On,{title:l.friendlyName,footerLeft:C,footerRight:T,children:I}),e[37]=l.friendlyName,e[38]=C,e[39]=T,e[40]=I,e[41]=A):A=e[41],A}function hx(){const t=B.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=r.jsxs("div",{className:"flex items-center gap-2 p-4 border border-dashed rounded-lg bg-accent/50 w-[calc(100%-16px)] max-w-[584px] mx-auto mb-2",children:[r.jsx(ug,{className:"size-5 text-muted-foreground shimmer"}),r.jsx("span",{className:"text-sm text-muted-foreground shimmer",children:"Preparing approval request..."})]}),t[0]=e):e=t[0],e}function ux(t){const e=B.c(4),{approvals:s,isStreaming:i,onRespond:n}=t;if(i&&s.length===0){let a;return e[0]===Symbol.for("react.memo_cache_sentinel")?(a=r.jsx(hx,{}),e[0]=a):a=e[0],a}if(s.length===0)return null;let o;return e[1]!==s||e[2]!==n?(o=r.jsx(dx,{approvals:s,onRespond:n}),e[1]=s,e[2]=n,e[3]=o):o=e[3],o}function fx(t){const e=[];for(const s of t)if("state"in s&&s.state==="approval-requested"&&"approval"in s&&s.approval?.id&&"toolCallId"in s&&s.toolCallId){const i="toolName"in s&&typeof s.toolName=="string"?s.toolName:s.type.startsWith("tool-")?s.type.replace("tool-",""):"Tool";e.push({approvalId:s.approval.id,toolCallId:s.toolCallId,toolName:i,friendlyName:Tp(Dp(i)),input:s.input})}return e}function mx(t){const e=B.c(15),{plan:s,onApprove:i,onDismiss:n}=t;let o;e[0]!==i||e[1]!==s.plan?(o=()=>{i(s.plan)},e[0]=i,e[1]=s.plan,e[2]=o):o=e[2];const a=o;let l;e[3]!==n?(l=r.jsx(ne,{type:"button",variant:"ghost",size:"sm",className:"h-7 px-2.5 text-xs text-muted-foreground [@media(hover:hover)]:hover:text-foreground active:scale-[0.97] transition-transform",onClick:n,children:"Keep iterating"}),e[3]=n,e[4]=l):l=e[4];let c;e[5]!==a?(c=r.jsx(ne,{type:"button",size:"sm",className:"h-7 px-2.5 text-xs bg-purple-600 hover:bg-purple-700 text-white active:scale-[0.97] transition-transform",onClick:a,children:"Let's go"}),e[5]=a,e[6]=c):c=e[6];let d;e[7]!==l||e[8]!==c?(d=r.jsxs(r.Fragment,{children:[l,c]}),e[7]=l,e[8]=c,e[9]=d):d=e[9];const u=d;let h;e[10]!==s.plan?(h=r.jsx("div",{className:"px-4 max-h-64 overflow-y-auto",children:r.jsx("div",{className:"prose prose-sm max-w-none text-sm",children:r.jsx(Mp,{id:"plan-preview",part:{type:"text",text:s.plan}})})}),e[10]=s.plan,e[11]=h):h=e[11];let f;return e[12]!==u||e[13]!==h?(f=r.jsx(On,{title:"Implementation Plan",footerRight:u,className:"border-dashed border-purple-500",children:h}),e[12]=u,e[13]=h,e[14]=f):f=e[14],f}function px(){const t=B.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=r.jsxs("div",{className:"flex items-center gap-2 p-4 border border-dashed border-purple-500/30 rounded-lg bg-purple-500/5 w-[calc(100%-16px)] max-w-[584px] mx-auto mb-2",children:[r.jsx(Jt,{className:"size-5 text-purple-500 shimmer"}),r.jsx("span",{className:"text-sm text-muted-foreground shimmer",children:"Preparing plan..."})]}),t[0]=e):e=t[0],e}function gx(t){const e=B.c(7),{plans:s,isStreaming:i,onApprove:n,onDismiss:o}=t;if(i&&s.length===0){let d;return e[0]===Symbol.for("react.memo_cache_sentinel")?(d=r.jsx(px,{}),e[0]=d):d=e[0],d}let a;e[1]!==s?(a=s.at(-1),e[1]=s,e[2]=a):a=e[2];const l=a;if(!l)return null;let c;return e[3]!==l||e[4]!==n||e[5]!==o?(c=r.jsx(mx,{plan:l,onApprove:n,onDismiss:o}),e[3]=l,e[4]=n,e[5]=o,e[6]=c):c=e[6],c}function _x(t){const e=[];for(const s of t)if("type"in s&&s.type==="tool-propose_plan"&&"state"in s&&s.state==="input-available"&&"toolCallId"in s&&"input"in s){const i=s.input;e.push({toolCallId:s.toolCallId,plan:i.plan,state:s.state})}return e}const Nc=Vs({response:Et().min(1,"Response is required")}),xx=Vs({response:Et().min(1,"Please select or enter an option")}),vx=Vs({response:zm(["yes","no"])});function bx(t){switch(t.type){case"text":return Nc;case"choice":return xx;case"confirm":return vx;default:return Nc}}function yx(t){const e={};for(const s of t)e[s.toolCallId]=bx(s.input);return Vs(e)}function Sx(t){const e=B.c(6),{control:s,name:i,placeholder:n}=t;let o;e[0]!==n?(o=l=>{const{field:c}=l;return r.jsxs(Rt,{children:[r.jsx(Tt,{children:r.jsx("div",{className:"px-2",children:r.jsxs("div",{className:"flex items-center gap-3 px-2 py-3 rounded-lg bg-accent/50",children:[r.jsx("span",{className:"flex items-center justify-center size-6 rounded-md bg-muted shrink-0",children:r.jsx($h,{size:16,className:"text-muted-foreground"})}),r.jsx("input",{...c,type:"text",placeholder:n||"Type your response...",autoFocus:!0,"aria-label":"Text response input",className:"flex-1 text-sm bg-transparent outline-none placeholder:text-foreground/25 text-foreground min-w-0"})]})})}),r.jsx(Dt,{})]})},e[0]=n,e[1]=o):o=e[1];let a;return e[2]!==s||e[3]!==i||e[4]!==o?(a=r.jsx(It,{control:s,name:i,render:o}),e[2]=s,e[3]=i,e[4]=o,e[5]=a):a=e[5],a}function ku(t,e){const s=B.c(4);let i,n;s[0]!==t||s[1]!==e?(i=()=>{const o=a=>{const l=a.target.tagName;if(l==="INPUT"||l==="TEXTAREA"||a.metaKey||a.ctrlKey||a.altKey)return;const c=Number.parseInt(a.key,10);c>=1&&c<=t&&(a.preventDefault(),e(c-1))};return document.addEventListener("keydown",o),()=>document.removeEventListener("keydown",o)},n=[t,e],s[0]=t,s[1]=e,s[2]=i,s[3]=n):(i=s[2],n=s[3]),S.useEffect(i,n)}function wx(t){const e=B.c(9),{control:s,name:i,options:n}=t,[o,a]=S.useState(!1),l=S.useRef(null),c=S.useRef(null);let d;if(e[0]!==n?(d=f=>{c.current?.onChange(n[f]??""),a(!1)},e[0]=n,e[1]=d):d=e[1],ku(n.length,d),n.length===0)return null;let u;e[2]!==o||e[3]!==n?(u=f=>{const{field:m}=f;c.current=m;const p=o||!!m.value&&!n.includes(m.value);return r.jsxs(Rt,{children:[r.jsx(Tt,{children:r.jsxs("div",{className:"flex flex-col px-2",role:"group","aria-label":"Choice options",children:[n.map((g,_)=>{const v=m.value===g;return r.jsxs("button",{type:"button",onClick:()=>{m.onChange(g??""),a(!1)},className:X("flex items-center gap-3 px-2 py-3 rounded-lg text-left transition-colors w-full",v&&"bg-accent/50",!v&&"hover:bg-accent/30"),"aria-label":`Select ${g}`,children:[r.jsx("span",{className:X("flex items-center justify-center size-6 rounded-md text-sm shrink-0",v?"bg-chart-1 text-white":"bg-muted text-foreground"),children:_+1}),r.jsx("span",{className:"text-sm text-foreground truncate",children:g})]},`${_}-${g}`)}),r.jsxs("div",{className:X("flex items-center gap-3 px-2 py-3 rounded-lg transition-colors w-full cursor-text",p&&"bg-accent/50",!p&&"hover:bg-accent/30"),onClick:()=>{a(!0),n.includes(m.value)&&m.onChange(""),setTimeout(()=>l.current?.focus(),0)},children:[r.jsx("span",{className:"flex items-center justify-center size-6 rounded-md bg-muted shrink-0",children:r.jsx($h,{size:16,className:"text-muted-foreground"})}),p?r.jsx("input",{ref:l,type:"text",value:m.value,onChange:g=>m.onChange(g.target.value),placeholder:"Something else...",autoFocus:!0,"aria-label":"Custom choice input",className:"flex-1 text-sm bg-transparent outline-none placeholder:text-foreground/25 text-foreground min-w-0"}):r.jsx("span",{className:"text-sm text-foreground/25",children:"Something else..."})]})]})}),r.jsx(Dt,{})]})},e[2]=o,e[3]=n,e[4]=u):u=e[4];let h;return e[5]!==s||e[6]!==i||e[7]!==u?(h=r.jsx(It,{control:s,name:i,render:u}),e[5]=s,e[6]=i,e[7]=u,e[8]=h):h=e[8],h}function Vx(t){const e=B.c(6),{control:s,name:i}=t;let n;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=["yes","no"],e[0]=n):n=e[0];const o=n,a=S.useRef(null);let l;e[1]===Symbol.for("react.memo_cache_sentinel")?(l=u=>{a.current?.onChange(o[u]??"")},e[1]=l):l=e[1],ku(o.length,l);let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c=u=>{const{field:h}=u;return a.current=h,r.jsxs(Rt,{children:[r.jsx(Tt,{children:r.jsx("div",{className:"flex gap-2 px-2",role:"group","aria-label":"Confirmation options",children:o.map(f=>{const m=h.value===f;return r.jsxs("button",{type:"button",onClick:()=>h.onChange(f),className:X("flex items-center gap-3 px-4 py-3 rounded-lg text-left transition-colors flex-1",m&&"bg-accent/50",!m&&"hover:bg-accent/30"),"aria-label":`Confirm ${f}`,children:[r.jsx("span",{className:X("flex items-center justify-center size-6 rounded-md text-sm shrink-0",m?"bg-chart-1 text-white":"bg-muted text-foreground"),children:f==="yes"?1:2}),r.jsx("span",{className:"text-sm text-foreground capitalize",children:f})]},f)})})}),r.jsx(Dt,{})]})},e[2]=c):c=e[2];let d;return e[3]!==s||e[4]!==i?(d=r.jsx(It,{control:s,name:i,render:c}),e[3]=s,e[4]=i,e[5]=d):d=e[5],d}function Ac(t){const e=B.c(13),{input:s,control:i,name:n}=t;switch(s.type){case"text":{let o;return e[0]!==i||e[1]!==s.default||e[2]!==n?(o=r.jsx(Sx,{control:i,name:n,placeholder:s.default}),e[0]=i,e[1]=s.default,e[2]=n,e[3]=o):o=e[3],o}case"choice":{let o;e[4]!==s.options?(o=s.options?.filter(Boolean)??[],e[4]=s.options,e[5]=o):o=e[5];const a=o;let l;return e[6]!==i||e[7]!==n||e[8]!==a?(l=r.jsx(wx,{control:i,name:n,options:a}),e[6]=i,e[7]=n,e[8]=a,e[9]=l):l=e[9],l}case"confirm":{let o;return e[10]!==i||e[11]!==n?(o=r.jsx(Vx,{control:i,name:n}),e[10]=i,e[11]=n,e[12]=o):o=e[12],o}default:return null}}function Cx({parts:t,onSubmit:e}){const[s,i]=S.useState(t[0]?.toolCallId??""),n=yx(t.map(x=>({toolCallId:x.toolCallId,input:x.input}))),o=Hi({resolver:Or(n),defaultValues:Object.fromEntries(t.map(x=>[x.toolCallId,{response:""}]))}),a=o.watch(),l=t.findIndex(x=>x.toolCallId===s),c=!!a[s]?.response,d=t.every(x=>!!a[x.toolCallId]?.response),u=x=>{for(const b of t){const y=x[b.toolCallId]?.response;y&&e(b,y)}},h=x=>t.find(b=>!x[b.toolCallId]?.response&&b.toolCallId!==s)??null,f=()=>{const x=o.getValues();if(t.every(y=>!!x[y.toolCallId]?.response))o.handleSubmit(u)();else{const y=h(x);y&&i(y.toolCallId)}},m=()=>{o.setValue(`${s}.response`,"user has skip this question"),f()},p=()=>{if(l>0){const x=t[l-1];x&&i(x.toolCallId)}},g=()=>{if(l<t.length-1){const x=t[l+1];x&&i(x.toolCallId)}},_=r.jsxs(r.Fragment,{children:[r.jsx(ne,{type:"button",variant:"outline",size:"sm",onClick:m,className:"h-7",children:"Skip"}),r.jsx(ne,{type:"button",size:"sm",disabled:!c,onClick:f,className:X("h-7",c?"":"opacity-50"),children:d?"Submit":"Next"})]}),v=r.jsx(ju,{current:l,total:t.length,onPrev:p,onNext:g});if(t.length===1){const x=t[0];return x?.input?r.jsx(Pi,{...o,children:r.jsx("form",{onSubmit:o.handleSubmit(u),autoComplete:"off",children:r.jsx(On,{title:x.input?.prompt??"Question",footerRight:_,children:r.jsx(Ac,{input:x.input,control:o.control,name:`${x.toolCallId}.response`})})})}):null}return r.jsx(Pi,{...o,children:r.jsx("form",{onSubmit:o.handleSubmit(u),autoComplete:"off",children:r.jsx(Mh,{value:s,onValueChange:i,children:t.map(x=>r.jsx(yn,{value:x.toolCallId,className:"mt-0",children:r.jsx(On,{title:x.input?.prompt??"Question",footerLeft:v,footerRight:_,children:r.jsx(Ac,{input:x.input,control:o.control,name:`${x.toolCallId}.response`})})},x.toolCallId))})})})}function jx(){const t=B.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=r.jsxs("div",{className:"flex items-center gap-2 p-4 border border-dashed rounded-lg bg-accent/50 w-[calc(100%-16px)] max-w-[584px] mx-auto mb-2",children:[r.jsx(Pg,{className:"size-5 text-muted-foreground shimmer"}),r.jsx("span",{className:"text-sm text-muted-foreground shimmer",children:"Preparing question..."})]}),t[0]=e):e=t[0],e}function Nu(t){const e=B.c(6),{userAskParts:s,isStreaming:i,onSubmit:n}=t;let o;e[0]!==s?(o=s.filter(kx),e[0]=s,e[1]=o):o=e[1];const a=o;if(i){let c;return e[2]===Symbol.for("react.memo_cache_sentinel")?(c=r.jsx(jx,{}),e[2]=c):c=e[2],c}if(a.length===0)return null;let l;return e[3]!==n||e[4]!==a?(l=r.jsx(Cx,{parts:a,onSubmit:n}),e[3]=n,e[4]=a,e[5]=l):l=e[5],l}function kx(t){return t.state==="input-available"}const Ec=new Map;function co(){const{org:t}=be(),e=Me({connectionId:Wt,orgId:t.id}),s=bl(),i=s.find(_=>_.providerId==="deco"),{data:n,isLoading:o,refetch:a,isFetching:l}=Fi({queryKey:lt.aiProviderCredits(t.id,"deco"),enabled:!!i,staleTime:6e4,queryFn:async()=>{const _=await e.callTool({name:"AI_PROVIDER_CREDITS",arguments:{providerId:"deco"}});return _?.isError?null:_.structuredContent??null}}),c=n?.balanceCents??null,d=c!=null?c/100:null,u=S.useRef(new Map);if(c!=null){const _=Ec.get(t.id);u.current.get(t.id)&&_!=null&&c>_&&se("credits_topped_up_detected",{organization_id:t.id,delta_cents:c-_,previous_balance_cents:_,new_balance_cents:c}),Ec.set(t.id,c),u.current.set(t.id,!0)}const h=!!i,f=c!=null&&c>0,m=c!=null&&c===0,p=c!=null&&c===200,g=s.length>0&&s.every(_=>_.providerId==="deco");return{hasDecoKey:h,decoKeyId:i?.id??null,balanceCents:c,balanceDollars:d,hasCredits:f,isZeroBalance:m,isInitialFreeCredit:p,hasOnlyDecoProvider:g,isLoading:o,isFetching:l,refetch:a}}function Nx(t){return t?t.message.startsWith("[CREDITS]"):!1}const Ax={usd:[{dollars:10,label:"Starter"},{dollars:20,label:"Popular"},{dollars:100,label:"Best value"}],brl:[{dollars:50,label:"Starter"},{dollars:100,label:"Popular"},{dollars:500,label:"Best value"}]},Ex=["Access to 100+ AI models","Unified API, no separate keys needed","Pay only for what you use"];function Au(t){const e=B.c(43),{onDismiss:s}=t,{org:i}=be(),n=Ke(),{decoKeyId:o}=co();let a;e[0]!==i.id?(a={connectionId:Wt,orgId:i.id},e[0]=i.id,e[1]=a):a=e[1];const l=Me(a),[c,d]=S.useState(""),[u,h]=S.useState(!1),[f,m]=S.useState("usd"),p=f==="brl"?"R$":"$";let g,_;e[2]!==i.id?(g=()=>{se("credits_exhausted_shown",{organization_id:i.id})},_=[i.id],e[2]=i.id,e[3]=g,e[4]=_):(g=e[3],_=e[4]),S.useEffect(g,_);let v;e[5]!==l||e[6]!==f?(v=async D=>{const P=await l.callTool({name:"AI_PROVIDER_TOPUP_URL",arguments:{providerId:"deco",amountCents:D,currency:f}});if(P?.isError)throw new Error(P.content?.[0]?.text??"Failed to get top-up URL");return P.structuredContent?.url},e[5]=l,e[6]=f,e[7]=v):v=e[7];let x;e[8]!==s?(x=D=>{D&&window.open(D,"_blank","noopener,noreferrer"),s?.()},e[8]=s,e[9]=x):x=e[9];let b;e[10]!==v||e[11]!==x?(b={mutationFn:v,onSuccess:x,onError:Tx},e[10]=v,e[11]=x,e[12]=b):b=e[12];const{mutate:y,isPending:C}=Br(b),j=parseFloat(c),V=!isNaN(j)&&j>=1;let w;e[13]!==s?(w=D=>!D&&s?.(),e[13]=s,e[14]=w):w=e[14];let k;e[15]===Symbol.for("react.memo_cache_sentinel")?(k=["radial-gradient(ellipse 40% 200% at -5% 100%, rgba(165,149,255,0.5) 0%, transparent 100%)","radial-gradient(ellipse 40% 200% at 105% -10%, rgba(208,236,26,0.45) 0%, transparent 100%)"],e[15]=k):k=e[15];let T;e[16]===Symbol.for("react.memo_cache_sentinel")?(T=r.jsx("div",{className:"absolute inset-x-0 top-0 h-36 pointer-events-none",style:{backgroundImage:k.join(", "),maskImage:"linear-gradient(to bottom, black 0%, transparent 100%)",WebkitMaskImage:"linear-gradient(to bottom, black 0%, transparent 100%)"}}),e[16]=T):T=e[16];let I;e[17]===Symbol.for("react.memo_cache_sentinel")?(I=r.jsxs("div",{className:"relative px-8 pt-8 pb-2 overflow-hidden",children:[T,r.jsxs(Ds,{className:"relative gap-4",children:[r.jsx("img",{src:"/logos/deco%20logo.svg",alt:"Deco AI Gateway",className:"size-9 rounded-lg object-contain dark:bg-white dark:p-0.5"}),r.jsxs("div",{children:[r.jsx(Ts,{className:"text-xl font-semibold tracking-tight",children:"Top up to keep building"}),r.jsx(dl,{className:"mt-1.5 text-sm leading-relaxed",children:"Your credits are used up. Add more to continue using AI across all your agents."})]})]})]}),e[17]=I):I=e[17];let A;e[18]!==f||e[19]!==p||e[20]!==c||e[21]!==j||e[22]!==o||e[23]!==V||e[24]!==C||e[25]!==u||e[26]!==y?(A=o&&r.jsxs("div",{className:"px-8 pt-5 pb-6",children:[r.jsx("div",{className:"mb-4",children:r.jsxs(eu,{type:"single",variant:"outline",size:"sm",value:f,onValueChange:D=>{D&&m(D)},children:[r.jsx(Ln,{value:"usd",className:"h-8 px-3 text-xs",children:"USD"}),r.jsx(Ln,{value:"brl",className:"h-8 px-3 text-xs",children:"BRL"})]})}),r.jsxs("div",{className:"rounded-xl border border-border p-5",children:[r.jsx("div",{className:"grid grid-cols-3 gap-2.5",children:Ax[f].map(D=>{const{dollars:P,label:O}=D;return r.jsxs("button",{type:"button",disabled:C,onClick:()=>{se("credits_topup_clicked",{amount_cents:P*100,currency:f,tier_label:O,source:"exhausted_banner"}),y(P*100)},className:X("relative flex flex-col items-center gap-1 py-5 rounded-xl border transition-all duration-150 cursor-pointer","disabled:opacity-50 disabled:cursor-wait","border-border hover:border-foreground/20 hover:bg-muted/30"),children:[r.jsxs("span",{className:"text-2xl font-semibold tabular-nums text-foreground",children:[p,P]}),r.jsx("span",{className:"text-xs text-muted-foreground",children:O})]},P)})}),u?r.jsxs("div",{className:"flex gap-2 mt-3",children:[r.jsxs("div",{className:"relative flex-1",children:[r.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-sm text-muted-foreground select-none",children:p}),r.jsx(bt,{type:"number",min:"1",step:"1",placeholder:"50",value:c,onChange:D=>d(D.target.value),className:"h-10 text-sm pl-7",autoFocus:!0})]}),r.jsx(ne,{className:"h-10",disabled:!V||C,onClick:()=>{se("credits_topup_clicked",{amount_cents:Math.round(j*100),currency:f,tier_label:"custom",source:"exhausted_banner"}),y(Math.round(j*100))},children:C?"Opening...":"Add"})]}):r.jsx("button",{type:"button",className:"w-full mt-3 text-xs text-muted-foreground hover:text-foreground transition-colors py-1",onClick:()=>h(!0),children:"Enter custom amount"})]}),r.jsx("div",{className:"mt-5 rounded-xl bg-muted/25 border border-border/50 p-4 space-y-3",children:Ex.map(Ix)})]}),e[18]=f,e[19]=p,e[20]=c,e[21]=j,e[22]=o,e[23]=V,e[24]=C,e[25]=u,e[26]=y,e[27]=A):A=e[27];let N;e[28]!==s?(N=r.jsx(ne,{variant:"ghost",size:"sm",onClick:s,children:"Dismiss"}),e[28]=s,e[29]=N):N=e[29];let E;e[30]!==n||e[31]!==s||e[32]!==i.slug?(E=r.jsx("button",{type:"button",className:"text-xs text-muted-foreground hover:text-foreground transition-colors",onClick:()=>{n({to:"/$org/settings/ai-providers",params:{org:i.slug}}),s?.()},children:"Manage providers"}),e[30]=n,e[31]=s,e[32]=i.slug,e[33]=E):E=e[33];let R;e[34]!==N||e[35]!==E?(R=r.jsxs("div",{className:"px-8 py-4 border-t border-border bg-muted/30 flex items-center justify-between",children:[N,E]}),e[34]=N,e[35]=E,e[36]=R):R=e[36];let M;e[37]!==A||e[38]!==R?(M=r.jsxs(ms,{className:"sm:max-w-[520px] gap-0 p-0 overflow-hidden",onOpenAutoFocus:Rx,children:[I,A,R]}),e[37]=A,e[38]=R,e[39]=M):M=e[39];let L;return e[40]!==M||e[41]!==w?(L=r.jsx(ps,{open:!0,onOpenChange:w,children:M}),e[40]=M,e[41]=w,e[42]=L):L=e[42],L}function Ix(t){return r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx("div",{className:"flex items-center justify-center size-5 rounded-full bg-[hsl(var(--chart-1))]/15 shrink-0",children:r.jsx(Jt,{size:12,className:"text-[hsl(var(--chart-1))]"})}),r.jsx("span",{className:"text-sm text-foreground/80",children:t})]},t)}function Rx(t){return t.preventDefault()}function Tx(t){pe.error(`Top-up failed: ${t.message}`)}const Dx={length:"Response reached the model's output limit. Different models have different limits. Try switching models or asking it to continue.","content-filter":"Response was filtered due to content policy.","tool-calls":"Response paused after tool execution to prevent infinite loops and save costs. Click continue to keep working."};function $n(t){const e=B.c(32),{variant:s,onDismiss:i}=t,n=s==="error",o=n?"Error occurred":"Response incomplete",a=n?t.error.message:Dx[t.finishReason]??`Response stopped unexpectedly: ${t.finishReason}`,l=n?"border-destructive/30 bg-destructive/5":"border-amber-500/30 bg-amber-500/5",c=n?"text-destructive":"text-amber-600 dark:text-amber-500",d=n?ri:yh;let u;e[0]!==l?(u=X("flex items-start gap-2 px-3 py-2.5 rounded-lg border border-dashed text-sm w-full mb-2 shadow",l),e[0]=l,e[1]=u):u=e[1];let h;e[2]!==c?(h=X("mt-0.5 shrink-0",c),e[2]=c,e[3]=h):h=e[3];let f;e[4]!==d?(f=r.jsx(d,{size:16}),e[4]=d,e[5]=f):f=e[5];let m;e[6]!==h||e[7]!==f?(m=r.jsx("div",{className:h,children:f}),e[6]=h,e[7]=f,e[8]=m):m=e[8];let p;e[9]!==c?(p=X("text-xs mb-1 font-medium",c),e[9]=c,e[10]=p):p=e[10];let g;e[11]!==p||e[12]!==o?(g=r.jsx("div",{className:p,children:o}),e[11]=p,e[12]=o,e[13]=g):g=e[13];let _;e[14]!==a?(_=r.jsx("div",{className:"text-xs line-clamp-2 text-muted-foreground mb-2",children:a}),e[14]=a,e[15]=_):_=e[15];let v;e[16]!==n||e[17]!==t.onContinue||e[18]!==t.onFixInChat?(v=r.jsx("div",{className:"flex gap-2",children:n?r.jsxs(r.Fragment,{children:[r.jsx(ne,{size:"sm",variant:"outline",onClick:t.onFixInChat,className:"h-7 text-xs",children:"Fix in chat"}),r.jsx(ne,{size:"sm",variant:"outline",disabled:!0,className:"h-7 text-xs",children:"Report"})]}):r.jsx(ne,{size:"sm",variant:"outline",onClick:t.onContinue,className:"h-7 text-xs",children:"Continue"})}),e[16]=n,e[17]=t.onContinue,e[18]=t.onFixInChat,e[19]=v):v=e[19];let x;e[20]!==g||e[21]!==_||e[22]!==v?(x=r.jsxs("div",{className:"flex-1 min-w-0",children:[g,_,v]}),e[20]=g,e[21]=_,e[22]=v,e[23]=x):x=e[23];let b;e[24]===Symbol.for("react.memo_cache_sentinel")?(b=r.jsx(fi,{size:14}),e[24]=b):b=e[24];let y;e[25]!==i?(y=r.jsx("button",{type:"button",onClick:i,className:"text-muted-foreground hover:text-foreground transition-colors shrink-0",title:"Dismiss",children:b}),e[25]=i,e[26]=y):y=e[26];let C;return e[27]!==u||e[28]!==y||e[29]!==m||e[30]!==x?(C=r.jsx("div",{className:"px-0.5",children:r.jsxs("div",{className:u,children:[m,x,y]})}),e[27]=u,e[28]=y,e[29]=m,e[30]=x,e[31]=C):C=e[31],C}function ho(){const t=B.c(41),{error:e,clearError:s,finishReason:i,clearFinishReason:n,messages:o,isStreaming:a,isWaitingForApprovals:l,addToolOutput:c,addToolApprovalResponse:d,sendMessage:u}=Ui(),[h,f]=Wi(),{virtualMcpId:m,createTaskWithMessage:p}=es();let g,_,v,x;if(t[0]!==o){const R=o.at(-1);x=R?.role==="assistant"?R.parts.filter(Lx):null,g=x?.filter(Px)?.length,_=R?.role==="assistant"?_x(R.parts):[],v=R?.role==="assistant"?fx(R.parts):[],t[0]=o,t[1]=g,t[2]=_,t[3]=v,t[4]=x}else g=t[1],_=t[2],v=t[3],x=t[4];const b=v;let y;t[5]!==e||t[6]!==u?(y=()=>{if(e){const M={type:"doc",content:[{type:"paragraph",content:[{type:"text",text:`I encountered this error: ${e.message}. Can you help me fix it?`}]}]};u(M)}},t[5]=e,t[6]=u,t[7]=y):y=t[7];const C=y;let j;t[8]!==u?(j=()=>{u({type:"doc",content:[{type:"paragraph",content:[{type:"text",text:"Please continue."}]}]})},t[8]=u,t[9]=j):j=t[9];const V=j;let w;t[10]!==c?(w=(R,M)=>{c({tool:"user_ask",toolCallId:R.toolCallId,output:{response:M}})},t[10]=c,t[11]=w):w=t[11];const k=w;let T;t[12]!==p||t[13]!==h||t[14]!==f||t[15]!==m?(T=R=>{f({...h,toolApprovalLevel:"auto"}),p({virtualMcpId:m,message:{parts:[{type:"text",text:`Implement this plan:
3
3
 
4
- ${R}`}]}})},t[12]=p,t[13]=h,t[14]=f,t[15]=m,t[16]=T):T=t[16];const I=T,A=Rx;let N;t[17]!==d?(N=(R,M,L)=>{d({id:R,approved:M,...L?{reason:L}:{}})},t[17]=d,t[18]=N):N=t[18];const E=N;if(g){let R;return t[19]!==k||t[20]!==a||t[21]!==x?(R=r.jsx("div",{className:"absolute bottom-full left-0 right-0",children:r.jsx(ku,{userAskParts:x,isStreaming:a,onSubmit:k})}),t[19]=k,t[20]=a,t[21]=x,t[22]=R):R=t[22],R}if(_.length>0){let R;return t[23]!==I||t[24]!==a||t[25]!==_?(R=r.jsx("div",{className:"absolute bottom-full left-0 right-0",children:r.jsx(fx,{plans:_,isStreaming:a,onApprove:I,onDismiss:A})}),t[23]=I,t[24]=a,t[25]=_,t[26]=R):R=t[26],R}if(b.length>0||a&&l){let R;return t[27]!==E||t[28]!==a||t[29]!==b?(R=r.jsx("div",{className:"absolute bottom-full left-0 right-0",children:r.jsx(cx,{approvals:b,isStreaming:a,onRespond:E})}),t[27]=E,t[28]=a,t[29]=b,t[30]=R):R=t[30],R}if(!a&&e){if(Cx(e)){let M;return t[31]!==s?(M=r.jsx(Nu,{onDismiss:s}),t[31]=s,t[32]=M):M=t[32],M}let R;return t[33]!==s||t[34]!==e||t[35]!==C?(R=r.jsx("div",{className:"absolute bottom-full left-0 right-0 bg-background",children:r.jsx($n,{variant:"error",error:e,onDismiss:s,onFixInChat:C})}),t[33]=s,t[34]=e,t[35]=C,t[36]=R):R=t[36],R}if(!a&&i&&i!=="stop"&&!l){let R;return t[37]!==n||t[38]!==i||t[39]!==V?(R=r.jsx("div",{className:"absolute bottom-full left-0 right-0 bg-background",children:r.jsx($n,{variant:"warning",finishReason:i,onDismiss:n,onContinue:V})}),t[37]=n,t[38]=i,t[39]=V,t[40]=R):R=t[40],R}return null}function Rx(){document.querySelector("[data-chat-input]")?.focus()}function Tx(t){return t.state!=="output-available"}function Dx(t){return t.type==="tool-user_ask"}ho.Error=function(e){return r.jsx($n,{variant:"error",error:e.error,onDismiss:e.onDismiss,onFixInChat:e.onFixInChat})};ho.Warning=function(e){return r.jsx($n,{variant:"warning",finishReason:e.finishReason,onDismiss:e.onDismiss,onContinue:e.onContinue})};ho.UserAskQuestion=ku;async function Tl(t,e,s,i){if(!no(e)){ge.error("Selected model does not support file uploads");return}const n=10*1024*1024;if(s.size>n){ge.error(`File "${s.name}" exceeds 10MB limit`);return}try{const o=new FileReader,a=new Promise((d,u)=>{o.onload=()=>{const h=o.result;if(typeof h!="string"){u(new Error("Failed to read file as data URL"));return}const f=h.includes(",")?h.split(",")[1]??h:h;d(f)},o.onerror=u});o.readAsDataURL(s);const l=await a,c={id:crypto.randomUUID(),name:s.name,mimeType:s.type||"application/octet-stream",size:s.size,data:l};Mp(t,{from:i,to:i},c)}catch(o){console.error("Failed to process file:",o),ge.error(`Failed to load file "${s.name}"`)}}function Mx(t){const e=B.c(7),{editor:s,selectedModel:i}=t,n=S.useRef(Lx);let o,a;e[0]!==s||e[1]!==i?(o=()=>{n.current=async(d,u)=>{await Tl(s,i,d,u)}},a=[s,i],e[0]=s,e[1]=i,e[2]=o,e[3]=a):(o=e[2],a=e[3]),S.useEffect(o,a);let l,c;return e[4]!==s?(l=()=>{if(s?.isDestroyed)return;const d=new na("fileDropHandler");s.state.plugins.find(f=>f.spec.key===d)&&s.unregisterPlugin(d);const h=new Qp({key:d,props:{handleDrop:(f,m,p,g)=>{if(g)return!1;const _=m.dataTransfer?.files;if(!_||_.length===0)return!1;m.preventDefault();const v=f.posAtCoords({left:m.clientX,top:m.clientY});if(!v)return!1;const x=Array.from(_),b=v.pos;for(const y of x)n.current?.(y,b);return!0},handlePaste:(f,m)=>{const p=m.clipboardData?.items;if(!p)return!1;const g=Array.from(p).filter(Px);if(g.length===0)return!1;m.preventDefault();const{from:_}=f.state.selection;for(const v of g){const x=v.getAsFile();x&&n.current?.(x,_)}return!0}}});return s.registerPlugin(h),()=>{s?.isDestroyed||s.unregisterPlugin(d)}},c=[s],e[4]=s,e[5]=l,e[6]=c):(l=e[5],c=e[6]),S.useEffect(l,c),null}function Px(t){return t.kind==="file"}function Lx(){return Promise.resolve()}function Bx(t){const e=B.c(20),{selectedModel:s,isStreaming:i,icon:n}=t,{editor:o}=to(),a=S.useRef(null);let l;e[0]!==s?(l=no(s),e[0]=s,e[1]=l):l=e[1];const c=l;let d;e[2]!==o||e[3]!==s?(d=async b=>{const y=b.target.files;if(!y||y.length===0||!o)return;const C=Array.from(y),{from:j}=o.state.selection,V=j;for(const w of C)await Tl(o,s,w,V);a.current&&(a.current.value="")},e[2]=o,e[3]=s,e[4]=d):d=e[4];const u=d;if(!o||!c)return null;let h;e[5]!==u||e[6]!==i?(h=r.jsx("input",{ref:a,type:"file",multiple:!0,className:"hidden",onChange:u,disabled:i}),e[5]=u,e[6]=i,e[7]=h):h=e[7];const f=i||!c;let m;e[8]===Symbol.for("react.memo_cache_sentinel")?(m=()=>a.current?.click(),e[8]=m):m=e[8];let p;e[9]!==n?(p=n??r.jsx(ug,{size:16}),e[9]=n,e[10]=p):p=e[10];let g;e[11]!==f||e[12]!==p?(g=r.jsx(tt,{asChild:!0,children:r.jsx(ne,{type:"button",variant:"ghost",size:"icon",className:"text-muted-foreground/75",disabled:f,onClick:m,children:p})}),e[11]=f,e[12]=p,e[13]=g):g=e[13];let _;e[14]===Symbol.for("react.memo_cache_sentinel")?(_=r.jsx(st,{side:"top",children:"Add file"}),e[14]=_):_=e[14];let v;e[15]!==g?(v=r.jsxs(it,{children:[g,_]}),e[15]=g,e[16]=v):v=e[16];let x;return e[17]!==h||e[18]!==v?(x=r.jsxs(r.Fragment,{children:[h,v]}),e[17]=h,e[18]=v,e[19]=x):x=e[19],x}var Ox=Zp;var $x=["input:not([inert]):not([inert] *)","select:not([inert]):not([inert] *)","textarea:not([inert]):not([inert] *)","a[href]:not([inert]):not([inert] *)","button:not([inert]):not([inert] *)","[tabindex]:not(slot):not([inert]):not([inert] *)","audio[controls]:not([inert]):not([inert] *)","video[controls]:not([inert]):not([inert] *)",'[contenteditable]:not([contenteditable="false"]):not([inert]):not([inert] *)',"details>summary:first-of-type:not([inert]):not([inert] *)","details:not([inert]):not([inert] *)"],ua=$x.join(","),Au=typeof Element>"u",Nr=Au?function(){}:Element.prototype.matches||Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector,zn=!Au&&Element.prototype.getRootNode?function(t){var e;return t==null||(e=t.getRootNode)===null||e===void 0?void 0:e.call(t)}:function(t){return t?.ownerDocument},Fn=function(e,s){var i;s===void 0&&(s=!0);var n=e==null||(i=e.getAttribute)===null||i===void 0?void 0:i.call(e,"inert"),o=n===""||n==="true",a=o||s&&e&&(typeof e.closest=="function"?e.closest("[inert]"):Fn(e.parentNode));return a},zx=function(e){var s,i=e==null||(s=e.getAttribute)===null||s===void 0?void 0:s.call(e,"contenteditable");return i===""||i==="true"},Fx=function(e,s,i){if(Fn(e))return[];var n=Array.prototype.slice.apply(e.querySelectorAll(ua));return s&&Nr.call(e,ua)&&n.unshift(e),n=n.filter(i),n},fa=function(e,s,i){for(var n=[],o=Array.from(e);o.length;){var a=o.shift();if(!Fn(a,!1))if(a.tagName==="SLOT"){var l=a.assignedElements(),c=l.length?l:a.children,d=fa(c,!0,i);i.flatten?n.push.apply(n,d):n.push({scopeParent:a,candidates:d})}else{var u=Nr.call(a,ua);u&&i.filter(a)&&(s||!e.includes(a))&&n.push(a);var h=a.shadowRoot||typeof i.getShadowRoot=="function"&&i.getShadowRoot(a),f=!Fn(h,!1)&&(!i.shadowRootFilter||i.shadowRootFilter(a));if(h&&f){var m=fa(h===!0?a.children:h.children,!0,i);i.flatten?n.push.apply(n,m):n.push({scopeParent:a,candidates:m})}else o.unshift.apply(o,a.children)}}return n},Eu=function(e){return!isNaN(parseInt(e.getAttribute("tabindex"),10))},Iu=function(e){if(!e)throw new Error("No node provided");return e.tabIndex<0&&(/^(AUDIO|VIDEO|DETAILS)$/.test(e.tagName)||zx(e))&&!Eu(e)?0:e.tabIndex},Hx=function(e,s){var i=Iu(e);return i<0&&s&&!Eu(e)?0:i},Wx=function(e,s){return e.tabIndex===s.tabIndex?e.documentOrder-s.documentOrder:e.tabIndex-s.tabIndex},Ru=function(e){return e.tagName==="INPUT"},Ux=function(e){return Ru(e)&&e.type==="hidden"},Kx=function(e){var s=e.tagName==="DETAILS"&&Array.prototype.slice.apply(e.children).some(function(i){return i.tagName==="SUMMARY"});return s},qx=function(e,s){for(var i=0;i<e.length;i++)if(e[i].checked&&e[i].form===s)return e[i]},Gx=function(e){if(!e.name)return!0;var s=e.form||zn(e),i=function(l){return s.querySelectorAll('input[type="radio"][name="'+l+'"]')},n;if(typeof window<"u"&&typeof window.CSS<"u"&&typeof window.CSS.escape=="function")n=i(window.CSS.escape(e.name));else try{n=i(e.name)}catch(a){return console.error("Looks like you have a radio button with a name attribute containing invalid CSS selector characters and need the CSS.escape polyfill: %s",a.message),!1}var o=qx(n,e.form);return!o||o===e},Yx=function(e){return Ru(e)&&e.type==="radio"},Xx=function(e){return Yx(e)&&!Gx(e)},Jx=function(e){var s,i=e&&zn(e),n=(s=i)===null||s===void 0?void 0:s.host,o=!1;if(i&&i!==e){var a,l,c;for(o=!!((a=n)!==null&&a!==void 0&&(l=a.ownerDocument)!==null&&l!==void 0&&l.contains(n)||e!=null&&(c=e.ownerDocument)!==null&&c!==void 0&&c.contains(e));!o&&n;){var d,u,h;i=zn(n),n=(d=i)===null||d===void 0?void 0:d.host,o=!!((u=n)!==null&&u!==void 0&&(h=u.ownerDocument)!==null&&h!==void 0&&h.contains(n))}}return o},Ic=function(e){var s=e.getBoundingClientRect(),i=s.width,n=s.height;return i===0&&n===0},Qx=function(e,s){var i=s.displayCheck,n=s.getShadowRoot;if(i==="full-native"&&"checkVisibility"in e){var o=e.checkVisibility({checkOpacity:!1,opacityProperty:!1,contentVisibilityAuto:!0,visibilityProperty:!0,checkVisibilityCSS:!0});return!o}if(getComputedStyle(e).visibility==="hidden")return!0;var a=Nr.call(e,"details>summary:first-of-type"),l=a?e.parentElement:e;if(Nr.call(l,"details:not([open]) *"))return!0;if(!i||i==="full"||i==="full-native"||i==="legacy-full"){if(typeof n=="function"){for(var c=e;e;){var d=e.parentElement,u=zn(e);if(d&&!d.shadowRoot&&n(d)===!0)return Ic(e);e.assignedSlot?e=e.assignedSlot:!d&&u!==e.ownerDocument?e=u.host:e=d}e=c}if(Jx(e))return!e.getClientRects().length;if(i!=="legacy-full")return!0}else if(i==="non-zero-area")return Ic(e);return!1},Zx=function(e){if(/^(INPUT|BUTTON|SELECT|TEXTAREA)$/.test(e.tagName))for(var s=e.parentElement;s;){if(s.tagName==="FIELDSET"&&s.disabled){for(var i=0;i<s.children.length;i++){var n=s.children.item(i);if(n.tagName==="LEGEND")return Nr.call(s,"fieldset[disabled] *")?!0:!n.contains(e)}return!0}s=s.parentElement}return!1},e1=function(e,s){return!(s.disabled||Ux(s)||Qx(s,e)||Kx(s)||Zx(s))},Rc=function(e,s){return!(Xx(s)||Iu(s)<0||!e1(e,s))},t1=function(e){var s=parseInt(e.getAttribute("tabindex"),10);return!!(isNaN(s)||s>=0)},Tu=function(e){var s=[],i=[];return e.forEach(function(n,o){var a=!!n.scopeParent,l=a?n.scopeParent:n,c=Hx(l,a),d=a?Tu(n.candidates):l;c===0?a?s.push.apply(s,d):s.push(l):i.push({documentOrder:o,tabIndex:c,item:n,isScope:a,content:d})}),i.sort(Wx).reduce(function(n,o){return o.isScope?n.push.apply(n,o.content):n.push(o.content),n},[]).concat(s)},Du=function(e,s){s=s||{};var i;return s.getShadowRoot?i=fa([e],s.includeContainer,{filter:Rc.bind(null,s),flatten:!1,getShadowRoot:s.getShadowRoot,shadowRootFilter:t1}):i=Fx(e,s.includeContainer,Rc.bind(null,s)),Tu(i)};function s1(){return/apple/i.test(navigator.vendor)}const Tc="data-floating-ui-focusable";function i1(t){let e=t.activeElement;for(;((s=e)==null||(s=s.shadowRoot)==null?void 0:s.activeElement)!=null;){var s;e=e.shadowRoot.activeElement}return e}function ma(t,e){if(!t||!e)return!1;const s=e.getRootNode==null?void 0:e.getRootNode();if(t.contains(e))return!0;if(s&&zm(s)){let i=e;for(;i;){if(t===i)return!0;i=i.parentNode||i.host}}return!1}function er(t){return"composedPath"in t?t.composedPath()[0]:t.target}function No(t,e){if(e==null)return!1;if("composedPath"in t)return t.composedPath().includes(e);const s=t;return s.target!=null&&e.contains(s.target)}function r1(t){return t.matches("html,body")}function Ar(t){return t?.ownerDocument||document}function n1(t){return t?t.hasAttribute(Tc)?t:t.querySelector("["+Tc+"]")||t:null}function jn(t,e,s){return s===void 0&&(s=!0),t.filter(n=>{var o;return n.parentId===e&&(!s||((o=n.context)==null?void 0:o.open))}).flatMap(n=>[n,...jn(t,n.id,s)])}function o1(t){return"nativeEvent"in t}var a1=typeof document<"u",l1=function(){},pi=a1?S.useLayoutEffect:l1;const c1={...Sh},d1=c1.useInsertionEffect,h1=d1||(t=>t());function Ei(t){const e=S.useRef(()=>{});return h1(()=>{e.current=t}),S.useCallback(function(){for(var s=arguments.length,i=new Array(s),n=0;n<s;n++)i[n]=arguments[n];return e.current==null?void 0:e.current(...i)},[])}const Mu=()=>({getShadowRoot:!0,displayCheck:typeof ResizeObserver=="function"&&ResizeObserver.toString().includes("[native code]")?"full":"none"});function Pu(t,e){const s=Du(t,Mu()),i=s.length;if(i===0)return;const n=i1(Ar(t)),o=s.indexOf(n),a=o===-1?e===1?0:i-1:o+e;return s[a]}function u1(t){return Pu(Ar(t).body,1)||t}function f1(t){return Pu(Ar(t).body,-1)||t}function Ao(t,e){const s=e||t.currentTarget,i=t.relatedTarget;return!i||!ma(s,i)}function m1(t){Du(t,Mu()).forEach(s=>{s.dataset.tabindex=s.getAttribute("tabindex")||"",s.setAttribute("tabindex","-1")})}function Dc(t){t.querySelectorAll("[data-tabindex]").forEach(s=>{const i=s.dataset.tabindex;delete s.dataset.tabindex,i?s.setAttribute("tabindex",i):s.removeAttribute("tabindex")})}const p1="data-floating-ui-focusable",Mc="active",Pc="selected",g1={...Sh};let Lc=!1,_1=0;const Bc=()=>"floating-ui-"+Math.random().toString(36).slice(2,6)+_1++;function x1(){const[t,e]=S.useState(()=>Lc?Bc():void 0);return pi(()=>{t==null&&e(Bc())},[]),S.useEffect(()=>{Lc=!0},[]),t}const v1=g1.useId,Dl=v1||x1;function b1(){const t=new Map;return{emit(e,s){var i;(i=t.get(e))==null||i.forEach(n=>n(s))},on(e,s){t.has(e)||t.set(e,new Set),t.get(e).add(s)},off(e,s){var i;(i=t.get(e))==null||i.delete(s)}}}const y1=S.createContext(null),S1=S.createContext(null),Lu=()=>{var t;return((t=S.useContext(y1))==null?void 0:t.id)||null},Bu=()=>S.useContext(S1);function Ml(t){return"data-floating-ui-"+t}const w1={border:0,clip:"rect(0 0 0 0)",height:"1px",margin:"-1px",overflow:"hidden",padding:0,position:"fixed",whiteSpace:"nowrap",width:"1px",top:0,left:0},Oc=S.forwardRef(function(e,s){const[i,n]=S.useState();pi(()=>{s1()&&n("button")},[]);const o={ref:s,tabIndex:0,role:i,"aria-hidden":i?void 0:!0,[Ml("focus-guard")]:"",style:w1};return r.jsx("span",{...e,...o})}),V1={clipPath:"inset(50%)",position:"fixed",top:0,left:0},Ou=S.createContext(null),$c=Ml("portal");function C1(t){t===void 0&&(t={});const{id:e,root:s}=t,i=Dl(),n=k1(),[o,a]=S.useState(null),l=S.useRef(null);return pi(()=>()=>{o?.remove(),queueMicrotask(()=>{l.current=null})},[o]),pi(()=>{if(!i||l.current)return;const c=e?document.getElementById(e):null;if(!c)return;const d=document.createElement("div");d.id=i,d.setAttribute($c,""),c.appendChild(d),l.current=d,a(d)},[e,i]),pi(()=>{if(s===null||!i||l.current)return;let c=s||n?.portalNode;c&&!qm(c)&&(c=c.current),c=c||document.body;let d=null;e&&(d=document.createElement("div"),d.id=e,c.appendChild(d));const u=document.createElement("div");u.id=i,u.setAttribute($c,""),c=d||c,c.appendChild(u),l.current=u,a(u)},[e,s,i,n]),o}function j1(t){const{children:e,id:s,root:i,preserveTabOrder:n=!0}=t,o=C1({id:s,root:i}),[a,l]=S.useState(null),c=S.useRef(null),d=S.useRef(null),u=S.useRef(null),h=S.useRef(null),f=a?.modal,m=a?.open,p=!!a&&!a.modal&&a.open&&n&&!!(i||o);return S.useEffect(()=>{if(!o||!n||f)return;function g(_){o&&Ao(_)&&(_.type==="focusin"?Dc:m1)(o)}return o.addEventListener("focusin",g,!0),o.addEventListener("focusout",g,!0),()=>{o.removeEventListener("focusin",g,!0),o.removeEventListener("focusout",g,!0)}},[o,n,f]),S.useEffect(()=>{o&&(m||Dc(o))},[m,o]),r.jsxs(Ou.Provider,{value:S.useMemo(()=>({preserveTabOrder:n,beforeOutsideRef:c,afterOutsideRef:d,beforeInsideRef:u,afterInsideRef:h,portalNode:o,setFocusManagerState:l}),[n,o]),children:[p&&o&&r.jsx(Oc,{"data-type":"outside",ref:c,onFocus:g=>{if(Ao(g,o)){var _;(_=u.current)==null||_.focus()}else{const v=a?a.domReference:null,x=f1(v);x?.focus()}}}),p&&o&&r.jsx("span",{"aria-owns":o.id,style:V1}),o&&ds.createPortal(e,o),p&&o&&r.jsx(Oc,{"data-type":"outside",ref:d,onFocus:g=>{if(Ao(g,o)){var _;(_=h.current)==null||_.focus()}else{const v=a?a.domReference:null,x=u1(v);x?.focus(),a?.closeOnFocusOut&&a?.onOpenChange(!1,g.nativeEvent,"focus-out")}}})]})}const k1=()=>S.useContext(Ou),N1={pointerdown:"onPointerDown",mousedown:"onMouseDown",click:"onClick"},A1={pointerdown:"onPointerDownCapture",mousedown:"onMouseDownCapture",click:"onClickCapture"},zc=t=>{var e,s;return{escapeKey:typeof t=="boolean"?t:(e=t?.escapeKey)!=null?e:!1,outsidePress:typeof t=="boolean"?t:(s=t?.outsidePress)!=null?s:!0}};function E1(t,e){e===void 0&&(e={});const{open:s,onOpenChange:i,elements:n,dataRef:o}=t,{enabled:a=!0,escapeKey:l=!0,outsidePress:c=!0,outsidePressEvent:d="pointerdown",referencePress:u=!1,referencePressEvent:h="pointerdown",ancestorScroll:f=!1,bubbles:m,capture:p}=e,g=Bu(),_=Ei(typeof c=="function"?c:()=>!1),v=typeof c=="function"?_:c,x=S.useRef(!1),{escapeKey:b,outsidePress:y}=zc(m),{escapeKey:C,outsidePress:j}=zc(p),V=S.useRef(!1),w=Ei(E=>{var R;if(!s||!a||!l||E.key!=="Escape"||V.current)return;const M=(R=o.current.floatingContext)==null?void 0:R.nodeId,L=g?jn(g.nodesRef.current,M):[];if(!b&&(E.stopPropagation(),L.length>0)){let D=!0;if(L.forEach(P=>{var O;if((O=P.context)!=null&&O.open&&!P.context.dataRef.current.__escapeKeyBubbles){D=!1;return}}),!D)return}i(!1,o1(E)?E.nativeEvent:E,"escape-key")}),k=Ei(E=>{var R;const M=()=>{var L;w(E),(L=er(E))==null||L.removeEventListener("keydown",M)};(R=er(E))==null||R.addEventListener("keydown",M)}),T=Ei(E=>{var R;const M=o.current.insideReactTree;o.current.insideReactTree=!1;const L=x.current;if(x.current=!1,d==="click"&&L||M||typeof v=="function"&&!v(E))return;const D=er(E),P="["+Ml("inert")+"]",O=Ar(n.floating).querySelectorAll(P);let z=ys(D)?D:null;for(;z&&!wo(z);){const G=Wm(z);if(wo(G)||!ys(G))break;z=G}if(O.length&&ys(D)&&!r1(D)&&!ma(D,n.floating)&&Array.from(O).every(G=>!ma(z,G)))return;if(Um(D)&&N){const G=wo(D),q=Km(D),H=/auto|scroll/,ee=G||H.test(q.overflowX),K=G||H.test(q.overflowY),U=ee&&D.clientWidth>0&&D.scrollWidth>D.clientWidth,te=K&&D.clientHeight>0&&D.scrollHeight>D.clientHeight,Y=q.direction==="rtl",J=te&&(Y?E.offsetX<=D.offsetWidth-D.clientWidth:E.offsetX>D.clientWidth),ie=U&&E.offsetY>D.clientHeight;if(J||ie)return}const $=(R=o.current.floatingContext)==null?void 0:R.nodeId,W=g&&jn(g.nodesRef.current,$).some(G=>{var q;return No(E,(q=G.context)==null?void 0:q.elements.floating)});if(No(E,n.floating)||No(E,n.domReference)||W)return;const F=g?jn(g.nodesRef.current,$):[];if(F.length>0){let G=!0;if(F.forEach(q=>{var H;if((H=q.context)!=null&&H.open&&!q.context.dataRef.current.__outsidePressBubbles){G=!1;return}}),!G)return}i(!1,E,"outside-press")}),I=Ei(E=>{var R;const M=()=>{var L;T(E),(L=er(E))==null||L.removeEventListener(d,M)};(R=er(E))==null||R.addEventListener(d,M)});S.useEffect(()=>{if(!s||!a)return;o.current.__escapeKeyBubbles=b,o.current.__outsidePressBubbles=y;let E=-1;function R(O){i(!1,O,"ancestor-scroll")}function M(){window.clearTimeout(E),V.current=!0}function L(){E=window.setTimeout(()=>{V.current=!1},Hm()?5:0)}const D=Ar(n.floating);l&&(D.addEventListener("keydown",C?k:w,C),D.addEventListener("compositionstart",M),D.addEventListener("compositionend",L)),v&&D.addEventListener(d,j?I:T,j);let P=[];return f&&(ys(n.domReference)&&(P=So(n.domReference)),ys(n.floating)&&(P=P.concat(So(n.floating))),!ys(n.reference)&&n.reference&&n.reference.contextElement&&(P=P.concat(So(n.reference.contextElement)))),P=P.filter(O=>{var z;return O!==((z=D.defaultView)==null?void 0:z.visualViewport)}),P.forEach(O=>{O.addEventListener("scroll",R,{passive:!0})}),()=>{l&&(D.removeEventListener("keydown",C?k:w,C),D.removeEventListener("compositionstart",M),D.removeEventListener("compositionend",L)),v&&D.removeEventListener(d,j?I:T,j),P.forEach(O=>{O.removeEventListener("scroll",R)}),window.clearTimeout(E)}},[o,n,l,v,d,s,i,f,a,b,y,w,C,k,T,j,I]),S.useEffect(()=>{o.current.insideReactTree=!1},[o,v,d]);const A=S.useMemo(()=>({onKeyDown:w,...u&&{[N1[h]]:E=>{i(!1,E.nativeEvent,"reference-press")},...h!=="click"&&{onClick(E){i(!1,E.nativeEvent,"reference-press")}}}}),[w,i,u,h]),N=S.useMemo(()=>{function E(R){R.button===0&&(x.current=!0)}return{onKeyDown:w,onMouseDown:E,onMouseUp:E,[A1[d]]:()=>{o.current.insideReactTree=!0}}},[w,d,o]);return S.useMemo(()=>a?{reference:A,floating:N}:{},[a,A,N])}function I1(t){const{open:e=!1,onOpenChange:s,elements:i}=t,n=Dl(),o=S.useRef({}),[a]=S.useState(()=>b1()),l=Lu()!=null,[c,d]=S.useState(i.reference),u=Ei((m,p,g)=>{o.current.openEvent=m?p:void 0,a.emit("openchange",{open:m,event:p,reason:g,nested:l}),s?.(m,p,g)}),h=S.useMemo(()=>({setPositionReference:d}),[]),f=S.useMemo(()=>({reference:c||i.reference||null,floating:i.floating||null,domReference:i.reference}),[c,i.reference,i.floating]);return S.useMemo(()=>({dataRef:o,open:e,onOpenChange:u,elements:f,events:a,floatingId:n,refs:h}),[e,u,f,a,n,h])}function R1(t){t===void 0&&(t={});const{nodeId:e}=t,s=I1({...t,elements:{reference:null,floating:null,...t.elements}}),i=t.rootContext||s,n=i.elements,[o,a]=S.useState(null),[l,c]=S.useState(null),u=n?.domReference||o,h=S.useRef(null),f=Bu();pi(()=>{u&&(h.current=u)},[u]);const m=Fm({...t,elements:{...n,...l&&{reference:l}}}),p=S.useCallback(b=>{const y=ys(b)?{getBoundingClientRect:()=>b.getBoundingClientRect(),getClientRects:()=>b.getClientRects(),contextElement:b}:b;c(y),m.refs.setReference(y)},[m.refs]),g=S.useCallback(b=>{(ys(b)||b===null)&&(h.current=b,a(b)),(ys(m.refs.reference.current)||m.refs.reference.current===null||b!==null&&!ys(b))&&m.refs.setReference(b)},[m.refs]),_=S.useMemo(()=>({...m.refs,setReference:g,setPositionReference:p,domReference:h}),[m.refs,g,p]),v=S.useMemo(()=>({...m.elements,domReference:u}),[m.elements,u]),x=S.useMemo(()=>({...m,...i,refs:_,elements:v,nodeId:e}),[m,_,v,e,i]);return pi(()=>{i.dataRef.current.floatingContext=x;const b=f?.nodesRef.current.find(y=>y.id===e);b&&(b.context=x)}),S.useMemo(()=>({...m,context:x,refs:_,elements:v}),[m,_,v,x])}function Eo(t,e,s){const i=new Map,n=s==="item";let o=t;if(n&&t){const{[Mc]:a,[Pc]:l,...c}=t;o=c}return{...s==="floating"&&{tabIndex:-1,[p1]:""},...o,...e.map(a=>{const l=a?a[s]:null;return typeof l=="function"?t?l(t):null:l}).concat(t).reduce((a,l)=>(l&&Object.entries(l).forEach(c=>{let[d,u]=c;if(!(n&&[Mc,Pc].includes(d)))if(d.indexOf("on")===0){if(i.has(d)||i.set(d,[]),typeof u=="function"){var h;(h=i.get(d))==null||h.push(u),a[d]=function(){for(var f,m=arguments.length,p=new Array(m),g=0;g<m;g++)p[g]=arguments[g];return(f=i.get(d))==null?void 0:f.map(_=>_(...p)).find(_=>_!==void 0)}}}else a[d]=u}),a),{})}}function T1(t){t===void 0&&(t=[]);const e=t.map(l=>l?.reference),s=t.map(l=>l?.floating),i=t.map(l=>l?.item),n=S.useCallback(l=>Eo(l,t,"reference"),e),o=S.useCallback(l=>Eo(l,t,"floating"),s),a=S.useCallback(l=>Eo(l,t,"item"),i);return S.useMemo(()=>({getReferenceProps:n,getFloatingProps:o,getItemProps:a}),[n,o,a])}const D1=new Map([["select","listbox"],["combobox","listbox"],["label",!1]]);function M1(t,e){var s,i;e===void 0&&(e={});const{open:n,elements:o,floatingId:a}=t,{enabled:l=!0,role:c="dialog"}=e,d=Dl(),u=((s=o.domReference)==null?void 0:s.id)||d,h=S.useMemo(()=>{var x;return((x=n1(o.floating))==null?void 0:x.id)||a},[o.floating,a]),f=(i=D1.get(c))!=null?i:c,p=Lu()!=null,g=S.useMemo(()=>f==="tooltip"||c==="label"?{["aria-"+(c==="label"?"labelledby":"describedby")]:n?h:void 0}:{"aria-expanded":n?"true":"false","aria-haspopup":f==="alertdialog"?"dialog":f,"aria-controls":n?h:void 0,...f==="listbox"&&{role:"combobox"},...f==="menu"&&{id:u},...f==="menu"&&p&&{role:"menuitem"},...c==="select"&&{"aria-autocomplete":"none"},...c==="combobox"&&{"aria-autocomplete":"list"}},[f,h,p,n,u,c]),_=S.useMemo(()=>{const x={id:h,...f&&{role:f}};return f==="tooltip"||c==="label"?x:{...x,...f==="menu"&&{"aria-labelledby":u}}},[f,h,u,c]),v=S.useCallback(x=>{let{active:b,selected:y}=x;const C={role:"option",...b&&{id:h+"-fui-option"}};switch(c){case"select":case"combobox":return{...C,"aria-selected":y}}return{}},[h,c]);return S.useMemo(()=>l?{reference:g,floating:_,item:v}:{},[l,g,_,v])}function P1(t){const e=B.c(26),{editor:s,query:i,items:n,onSelect:o,onClose:a}=t,[l,c]=S.useState(0),d=S.useRef(n),u=S.useRef(l),h=S.useRef(o),f=S.useRef(a),m=S.useDeferredValue(i);let p;e[0]===Symbol.for("react.memo_cache_sentinel")?(p=()=>{c(0)},e[0]=p):p=e[0];let g;e[1]!==m?(g=[m],e[1]=m,e[2]=g):g=e[2],S.useEffect(p,g);let _,v;e[3]!==n.length||e[4]!==l?(_=()=>{l>=n.length&&n.length>0&&c(0)},v=[n.length,l],e[3]=n.length,e[4]=l,e[5]=_,e[6]=v):(_=e[5],v=e[6]),S.useEffect(_,v);let x,b;e[7]!==n?(x=()=>{d.current=n},b=[n],e[7]=n,e[8]=x,e[9]=b):(x=e[8],b=e[9]),S.useEffect(x,b);let y,C;e[10]!==l?(y=()=>{u.current=l},C=[l],e[10]=l,e[11]=y,e[12]=C):(y=e[11],C=e[12]),S.useEffect(y,C);let j,V;e[13]!==o?(V=()=>{h.current=o},j=[o],e[13]=o,e[14]=j,e[15]=V):(j=e[14],V=e[15]),S.useEffect(V,j);let w,k;e[16]!==a?(w=()=>{f.current=a},k=[a],e[16]=a,e[17]=w,e[18]=k):(w=e[17],k=e[18]),S.useEffect(w,k);let T;e[19]!==s.isDestroyed||e[20]!==s.view.dom?(T=()=>{const E=s.view.dom;if(s?.isDestroyed||!E)return;const R=L=>{const D=d.current;if(!D.length)return!1;const P=()=>c(z=>(z+1)%D.length),O=()=>c(z=>(z-1+D.length)%D.length);switch(L.key){case"ArrowUp":return L.preventDefault(),O(),!0;case"ArrowDown":return L.preventDefault(),P(),!0;case"Tab":return L.preventDefault(),L.shiftKey?O():P(),!0;case"Home":return L.preventDefault(),c(0),!0;case"End":return L.preventDefault(),c(D.length-1),!0;case"Enter":{if(L.isComposing)return!1;L.preventDefault();const z=u.current;return z!==-1&&D[z]&&h.current?.(D[z],z),!0}case"Escape":return L.preventDefault(),f.current?.(),!0;default:return!1}},M=L=>{R(L)};return E.addEventListener("keydown",M,!0),()=>{E?.removeEventListener("keydown",M,!0)}},e[19]=s.isDestroyed,e[20]=s.view.dom,e[21]=T):T=e[21];let I;e[22]!==s?(I=[s],e[22]=s,e[23]=I):I=e[23],S.useEffect(T,I);const A=n.length?l:void 0;let N;return e[24]!==A?(N={selectedIndex:A,setSelectedIndex:c},e[24]=A,e[25]=N):N=e[25],N}function L1(t,e){switch(e.type){case"SET_SELECTED_ITEM":return{...t,selectedItem:e.payload};case"ON_START":return{...t,open:!0,selectedItem:null,element:e.payload.element,query:e.payload.query,range:e.payload.range};case"ON_UPDATE":return{...t,element:e.payload.element,query:e.payload.query,range:e.payload.range};case"ON_EXIT":return{open:!1,element:null,query:"",range:null,selectedItem:null};default:return t}}const $u=S.createContext(void 0);function zu(){const t=S.useContext($u);if(!t)throw new Error("useSuggestionContext must be used within a SuggestionContext.Provider");return t}function B1({editor:t,char:e,pluginKey:s,allow:i,onOpenChange:n}){const[o,a]=S.useReducer(L1,{open:!1,element:null,query:"",range:null,selectedItem:null}),l=S.useRef(n);return l.current=n,S.useEffect(()=>{if(t?.isDestroyed)return;const c=s instanceof na?s:new na(s);t.state.plugins.find(h=>h.spec.key===c)&&t.unregisterPlugin(c);const u=zg({pluginKey:c,editor:t,char:e,allow(h){const f=t.state.doc.resolve(h.range.from);for(let m=f.depth;m>0;m--)if(f.node(m).type.name==="image")return!1;return!(i&&!i(h))},command(){},render:()=>({onStart:h=>{a({type:"ON_START",payload:{element:h.decorationNode??null,query:h.query,range:h.range}}),l.current?.(!0)},onUpdate:h=>{a({type:"ON_UPDATE",payload:{element:h.decorationNode??null,query:h.query,range:h.range}})},onKeyDown:h=>h.event.key==="Escape"?(a({type:"ON_EXIT"}),!0):!1,onExit:()=>{a({type:"ON_EXIT"}),l.current?.(!1)}}),items:()=>[]});return t.registerPlugin(u),()=>{t?.isDestroyed||t.unregisterPlugin(c)}},[t,s,e,a,i]),{state:o,dispatch:a}}function O1({editor:t,queryKey:e,queryFn:s,onSelect:i}){const{state:n,dispatch:o}=zu(),a=S.useDeferredValue(n.query),{data:l}=wh({queryKey:lt.suggestionItems(e,n.open,a),queryFn:()=>n.open?s({query:a}):[]}),c=()=>{o({type:"ON_EXIT"})},d=async(h,f)=>{if(!(n.selectedItem!==null||!n.range)){o({type:"SET_SELECTED_ITEM",payload:h});try{const{view:m}=t,g=m.state.selection.$to.nodeAfter?.text?.startsWith(" "),_=n.range?{...n.range}:{from:0,to:0};g&&n.range&&(_.to+=1),await i({range:_,item:h})===!1?o({type:"SET_SELECTED_ITEM",payload:null}):c()}catch{c()}}},{selectedIndex:u}=P1({editor:t,query:a,items:l,onSelect:d,onClose:c});return{selectedItem:n.selectedItem,items:l,selectedIndex:u,close:c,onSelect:d}}function $1({children:t}){const{state:e,dispatch:s}=zu(),{open:i,element:n}=e,o=()=>{s({type:"ON_EXIT"})},{refs:a,floatingStyles:l,context:c}=R1({placement:"bottom-start",open:i,onOpenChange:f=>{f||o()},elements:{reference:n},middleware:[Gm(10),Ym(),Xm()],whileElementsMounted:Jm}),d=E1(c,{outsidePress:f=>!(f.target instanceof Element&&f.target.closest(".ProseMirror"))}),u=M1(c,{role:"listbox"}),{getFloatingProps:h}=T1([d,u]);return i?r.jsx(j1,{children:r.jsx("div",{ref:a.setFloating,style:l,...h(),className:"z-50 w-auto min-w-[360px] max-w-[520px] rounded-lg border bg-popover p-0 text-popover-foreground shadow-md outline-hidden overflow-hidden",children:t})}):null}const z1=t=>{const e=B.c(29),{item:s,isSelected:i,onSelect:n,isLoading:o,ref:a}=t;let l;if(e[0]!==s){const j=si(s._meta);l=s.title||eo(s.name,j),e[0]=s,e[1]=l}else l=e[1];const c=l,d=s.description||null,u=s.icon,h=i&&"bg-accent text-accent-foreground",f=o&&"pointer-events-none opacity-50";let m;e[2]!==h||e[3]!==f?(m=X("relative flex w-full cursor-pointer select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors","hover:bg-accent hover:text-accent-foreground","focus:bg-accent focus:text-accent-foreground",h,f),e[2]=h,e[3]=f,e[4]=m):m=e[4];let p;e[5]!==u||e[6]!==c?(p=u!==void 0&&r.jsx(zs,{icon:u,name:c,size:"xs",className:"mr-2"}),e[5]=u,e[6]=c,e[7]=p):p=e[7];let g;e[8]!==c?(g=r.jsx("span",{className:"font-medium flex items-center truncate capitalize",children:c}),e[8]=c,e[9]=g):g=e[9];let _;e[10]!==o?(_=o&&r.jsx(jr,{size:"xs"}),e[10]=o,e[11]=_):_=e[11];let v;e[12]!==g||e[13]!==_?(v=r.jsxs("div",{className:"flex items-center justify-between gap-2",children:[g,_]}),e[12]=g,e[13]=_,e[14]=v):v=e[14];let x;e[15]!==d?(x=d&&r.jsx("div",{className:"text-xs text-muted-foreground line-clamp-1",children:d}),e[15]=d,e[16]=x):x=e[16];let b;e[17]!==v||e[18]!==x?(b=r.jsxs("div",{className:"flex flex-col gap-0.5 flex-1 min-w-0",children:[v,x]}),e[17]=v,e[18]=x,e[19]=b):b=e[19];let y;e[20]!==s.drillable?(y=s.drillable&&r.jsx("kbd",{className:"shrink-0 ml-2 px-1.5 py-0.5 text-[10px] font-medium text-muted-foreground bg-muted border border-border rounded",children:"↵"}),e[20]=s.drillable,e[21]=y):y=e[21];let C;return e[22]!==n||e[23]!==a||e[24]!==b||e[25]!==y||e[26]!==m||e[27]!==p?(C=r.jsxs("div",{ref:a,onClick:n,className:m,children:[p,b,y]}),e[22]=n,e[23]=a,e[24]=b,e[25]=y,e[26]=m,e[27]=p,e[28]=C):C=e[28],C},F1=t=>{const e=B.c(18),{editor:s,queryKey:i,queryFn:n,onSelect:o}=t;let a;e[0]!==s||e[1]!==o||e[2]!==n||e[3]!==i?(a={editor:s,queryKey:i,queryFn:n,onSelect:o},e[0]=s,e[1]=o,e[2]=n,e[3]=i,e[4]=a):a=e[4];const{items:l,selectedIndex:c,onSelect:d,selectedItem:u}=O1(a);if(!l.length){let p;return e[5]===Symbol.for("react.memo_cache_sentinel")?(p=r.jsx("div",{className:"min-w-[360px] max-w-[520px] bg-popover text-popover-foreground rounded-md border shadow-md p-3 text-sm",children:"No items found"}),e[5]=p):p=e[5],p}let h;e[6]===Symbol.for("react.memo_cache_sentinel")?(h={maxHeight:"min(320px, var(--radix-popover-content-available-height, 320px))"},e[6]=h):h=e[6];let f;if(e[7]!==d||e[8]!==l||e[9]!==c||e[10]!==u?.name){let p;e[12]!==d||e[13]!==c||e[14]!==u?.name?(p=(g,_)=>r.jsx(z1,{item:g,isSelected:_===c,ref:_===c?U1:void 0,onSelect:()=>d(g,_),isLoading:u?.name===g.name},g.name),e[12]=d,e[13]=c,e[14]=u?.name,e[15]=p):p=e[15],f=l.map(p),e[7]=d,e[8]=l,e[9]=c,e[10]=u?.name,e[11]=f}else f=e[11];let m;return e[16]!==f?(m=r.jsx("div",{className:"min-w-[360px] max-w-[520px] bg-popover text-popover-foreground rounded-md overflow-y-auto",style:h,children:r.jsx("div",{className:"p-1",children:f})}),e[16]=f,e[17]=m):m=e[17],m};function H1(){const t=B.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=r.jsx("div",{className:"p-1",children:[...Array(3)].map(W1)}),t[0]=e):e=t[0],e}function W1(t,e){return r.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1.5 animate-pulse",children:[r.jsx("div",{className:"h-4 w-24 bg-muted rounded"}),r.jsx("div",{className:"h-3 w-32 bg-muted rounded"})]},e)}function Fu(t){const e=B.c(18),{editor:s,char:i,pluginKey:n,queryKey:o,queryFn:a,onSelect:l,allow:c,onOpenChange:d}=t;let u;e[0]!==c||e[1]!==i||e[2]!==s||e[3]!==d||e[4]!==n?(u={editor:s,char:i,pluginKey:n,allow:c,onOpenChange:d},e[0]=c,e[1]=i,e[2]=s,e[3]=d,e[4]=n,e[5]=u):u=e[5];const{state:h,dispatch:f}=B1(u);let m;e[6]!==f||e[7]!==h?(m={state:h,dispatch:f},e[6]=f,e[7]=h,e[8]=m):m=e[8];let p;e[9]===Symbol.for("react.memo_cache_sentinel")?(p=r.jsx(H1,{}),e[9]=p):p=e[9];let g;e[10]!==s||e[11]!==l||e[12]!==a||e[13]!==o?(g=r.jsx($1,{children:r.jsx(S.Suspense,{fallback:p,children:r.jsx(F1,{editor:s,queryKey:o,queryFn:a,onSelect:l})})}),e[10]=s,e[11]=l,e[12]=a,e[13]=o,e[14]=g):g=e[14];let _;return e[15]!==m||e[16]!==g?(_=r.jsx($u.Provider,{value:m,children:g}),e[15]=m,e[16]=g,e[17]=_):_=e[17],_}function U1(t){t&&t.scrollIntoView({block:"center",behavior:"smooth"})}const K1=[{name:"agents",title:"Agents",description:"Mention an agent to hand off work",kind:"category",drillable:!0},{name:"resources",title:"Resources",description:"Attach a resource as context",kind:"category",drillable:!0}],q1=({editor:t,virtualMcpId:e})=>{const s=Mt(),{org:i}=be(),n=oo(),o=Me({connectionId:e,orgId:i.id}),a=lt.virtualMcpResources(e,i.id),[l,c]=S.useState("categories"),d=S.useRef(l);d.current=l;const u=S.useRef(null),h=S.useRef(!1),f=["at-mention",i.id,e??"default",l],m=async({item:_,range:v})=>{if(se("chat_picker_item_selected",{picker:"@",item_kind:_.kind,item_name:_.name}),_.kind!=="category"&&(h.current=!0),_.kind==="category")return c(_.name==="agents"?"agents":"resources"),!1;if(_.kind==="agent"&&_.agentId){Cr(t,v,{id:_.agentId,name:_.name,metadata:{agentId:_.agentId,title:_.name},char:"@"}),c("categories");return}if(_.kind==="resource"&&_.uri&&o){try{const x=await ru(o,_.uri);Cr(t,v,{id:_.uri,name:_.uri,metadata:x.contents,char:"@"})}catch(x){console.error("[at-mention] Failed to fetch resource:",x),ge.error("Failed to load resource. Please try again.")}c("categories");return}},p=async _=>{const{query:v}=_,x=d.current;if(x==="categories"){if(!v.trim())return K1;const C=v.toLowerCase(),j=n.filter(w=>w.status==="active"&&(!w.id||!Mn(w.id))&&w.id!==e&&(w.title.toLowerCase().includes(C)||w.description?.toLowerCase().includes(C))).map(w=>({name:w.title,title:w.title,description:w.description??void 0,icon:w.icon??null,kind:"agent",agentId:w.id})),V=await(async()=>{if(!o)return[];let w=s.getQueryData(a);return w||(w=await s.fetchQuery({queryKey:a,queryFn:()=>xr(o),staleTime:6e4})),(w?.resources??[]).filter(k=>k.uri.toLowerCase().includes(C)||k.name?.toLowerCase().includes(C)||k.description?.toLowerCase().includes(C)).map(k=>({name:k.name??k.uri,title:k.name,description:k.description,kind:"resource",uri:k.uri}))})();return[...j,...V]}if(x==="agents"){let C=n.filter(j=>j.status==="active"&&(!j.id||!Mn(j.id))&&j.id!==e);if(v.trim()){const j=v.toLowerCase();C=C.filter(V=>V.title.toLowerCase().includes(j)||V.description?.toLowerCase().includes(j))}return C.map(j=>({name:j.title,title:j.title,description:j.description??void 0,icon:j.icon??null,kind:"agent",agentId:j.id}))}if(!o)return[];let b=s.getQueryData(a);b?s.fetchQuery({queryKey:a,queryFn:()=>xr(o),staleTime:6e4}).catch(()=>{}):b=await s.fetchQuery({queryKey:a,queryFn:()=>xr(o),staleTime:6e4});let y=b?.resources??[];if(v.trim()){const C=v.toLowerCase();y=y.filter(j=>j.uri.toLowerCase().includes(C)||j.name?.toLowerCase().includes(C)||j.description?.toLowerCase().includes(C))}return y.map(C=>({name:C.name??C.uri,title:C.name,description:C.description,kind:"resource",uri:C.uri}))},g=_=>{if(_)u.current=Date.now(),h.current=!1,se("chat_picker_opened",{picker:"@"});else{const v=u.current;se("chat_picker_closed",{picker:"@",outcome:h.current?"selected":"dismissed",duration_ms:v?Date.now()-v:null}),u.current=null,c("categories")}};return r.jsx(Fu,{editor:t,char:"@",pluginKey:"atDropdownMenu",queryKey:f,queryFn:p,onSelect:m,onOpenChange:g})};function G1(t,e){const s=ts(t),i=Wr(),n=new Map(i.map(c=>[c.id,c])),o=(s?.connections??[]).map(c=>c.connection_id),{data:a}=Fi({queryKey:lt.promptConnectionMap(e,o),queryFn:async()=>{const c={};return await Promise.all(o.map(async d=>{try{const u=await ag({connectionId:d,orgId:e}),h=await Pn(u);for(const f of h.prompts)f.name in c||(c[f.name]=d)}catch{}})),c},staleTime:6e4,enabled:o.length>0}),l=new Map;for(const[c,d]of Object.entries(a??{})){const u=n.get(d);u&&l.set(c,u)}return l}async function Fc(t,e,s,i,n,o){try{const a=await ul(s,i,o);Cr(t,e,{id:i,name:al(i,n),metadata:a.messages,char:"/"})}catch(a){console.error("[slash] Failed to fetch prompt:",a),ge.error("Failed to load prompt. Please try again.")}}async function Y1(t,e,s,i){try{const n=await ru(s,i);Cr(t,e,{id:i,name:i,metadata:n.contents,char:"/"})}catch(n){console.error("[slash] Failed to fetch resource:",n),ge.error("Failed to load resource. Please try again.")}}const X1=({editor:t,virtualMcpId:e})=>{const s=Mt(),{org:i}=be(),n=Me({connectionId:e,orgId:i.id}),o=G1(e,i.id),a=S.useRef(o);a.current=o;const l=lt.virtualMcpPrompts(e,i.id),c=lt.virtualMcpResources(e,i.id),d=["slash-mention",i.id,e??"default"],[u,h]=S.useState(null),f=S.useRef(null),m=S.useRef(!1),p=async({item:x,range:b})=>{if(se("chat_picker_item_selected",{picker:"/",item_kind:x.kind,item_name:x.name}),m.current=!0,!!n)if(x.kind==="prompt"){if(x.arguments&&x.arguments.length>0){h({range:b,item:x});return}const y=si(x._meta);await Fc(t,b,n,x.name,y)}else x.uri&&await Y1(t,b,n,x.uri)},g=async x=>{if(!u||!n)return;const{range:b,item:y}=u,C=si(y._meta);await Fc(t,b,n,y.name,C,x),h(null)},_=async x=>{const{query:b}=x;if(!n)return[];const[y,C]=await Promise.all([J1(s,l,n),Q1(s,c,n)]),j=b.trim().toLowerCase(),V=(y??[]).filter(k=>!j||k.name.toLowerCase().includes(j)||k.title?.toLowerCase().includes(j)||k.description?.toLowerCase().includes(j)).map(k=>({name:k.name,title:k.title,description:k.description,icon:a.current.get(k.name)?.icon??null,kind:"prompt",arguments:k.arguments,_meta:k._meta})),w=(C??[]).filter(k=>!j||k.uri.toLowerCase().includes(j)||k.name?.toLowerCase().includes(j)||k.description?.toLowerCase().includes(j)).map(k=>({name:k.name??k.uri,title:k.name,description:k.description,kind:"resource",uri:k.uri}));return[...V,...w]},v=u?.item.kind==="prompt"?{name:u.item.name,arguments:u.item.arguments,description:u.item.description}:null;return r.jsxs(r.Fragment,{children:[r.jsx(Fu,{editor:t,char:"/",pluginKey:"slashDropdownMenu",queryKey:d,queryFn:_,onSelect:p,onOpenChange:x=>{if(x)f.current=Date.now(),m.current=!1,se("chat_picker_opened",{picker:"/"});else{const b=f.current;se("chat_picker_closed",{picker:"/",outcome:m.current?"selected":"dismissed",duration_ms:b?Date.now()-b:null}),f.current=null}}}),r.jsx(Rl,{prompt:v,setPrompt:()=>h(null),onSubmit:g})]})};async function J1(t,e,s){let i=t.getQueryData(e);return i?t.fetchQuery({queryKey:e,queryFn:()=>Pn(s),staleTime:6e4}).catch(()=>{}):i=await t.fetchQuery({queryKey:e,queryFn:()=>Pn(s),staleTime:6e4}),i?.prompts??[]}async function Q1(t,e,s){let i=t.getQueryData(e);return i?t.fetchQuery({queryKey:e,queryFn:()=>xr(s),staleTime:6e4}).catch(()=>{}):i=await t.fetchQuery({queryKey:e,queryFn:()=>xr(s),staleTime:6e4}),i?.resources??[]}function Z1(t){return[sg.configure({heading:!1,blockquote:!1,codeBlock:!1,horizontalRule:!1,dropcursor:!1}),Ox.configure({placeholder:()=>t.current??"Ask anything, / for prompts, @ for agents & resources...",showOnlyWhenEditable:!1}),Pp,Lp]}function Hu({tiptapDoc:t,setTiptapDoc:e,disabled:s=!1,enterToSubmit:i=!1,placeholder:n,onSubmit:o,children:a}){const l=S.useRef(o),c=S.useRef(e),d=S.useRef(i),u=S.useRef(n),h=eg({extensions:Z1(u),content:t||"",editorProps:{attributes:{"data-chat-input":"true",class:"prose prose-sm max-w-none focus:outline-none w-full h-full text-[15px] p-[18px]"},handleKeyDown:(f,m)=>m.key==="Enter"&&!m.shiftKey&&d.current?(m.preventDefault(),l.current?.(),!0):!1},onUpdate:({editor:f})=>{c.current(f?.getJSON())}});return S.useEffect(()=>{h?.setEditable(!s)},[h,s]),S.useEffect(()=>{l.current=o},[o]),S.useEffect(()=>{c.current=e},[e]),S.useEffect(()=>{d.current=i},[i]),S.useEffect(()=>{u.current=n},[n]),S.useEffect(()=>{if(h?.isDestroyed)return;const f=JSON.stringify(h?.getJSON()),m=JSON.stringify(t||{type:"doc",content:[]});f!==m&&h.commands.setContent(t||{type:"doc",content:[]})},[h,t]),r.jsx(tg.Provider,{value:{editor:h},children:a})}function Wu(t){const e=B.c(25),{disabled:s,virtualMcpId:i,showFileUploader:n,selectedModel:o,ref:a,className:l}=t,c=s===void 0?!1:s,d=n===void 0?!1:n,{editor:u}=to();let h,f;if(e[0]!==u?(h=()=>({focus:()=>{u?.commands.focus()},clear:()=>{u?.commands.clearContent(!0)},appendText:V=>{if(!u)return;const w=u.state.doc.textContent.trim()==="";u.commands.focus("end"),w||u.commands.insertContent(" "),u.commands.insertContent(V)},syncVoiceText:(V,w)=>{if(u&&(u.commands.setContent(V||{type:"doc",content:[]}),w)){u.commands.focus("end");const k=u.state.doc.textContent.trim().length>0;u.commands.insertContent(k?" "+w:w)}},restoreContent:V=>{u&&u.commands.setContent(V||{type:"doc",content:[]})}}),f=[u],e[0]=u,e[1]=h,e[2]=f):(h=e[1],f=e[2]),S.useImperativeHandle(a??null,h,f),!u)return null;const m=c&&"cursor-not-allowed opacity-70",p=c&&"[&_.ProseMirror]:cursor-not-allowed";let g;e[3]!==l||e[4]!==m||e[5]!==p?(g=X("overflow-y-auto relative flex-1 max-h-[164px] min-h-[20px] w-full flex flex-col",l,"[&_.ProseMirror]:outline-none [&_.ProseMirror]:min-h-[20px] [&_.ProseMirror]:flex-1","[&_.ProseMirror_p.is-editor-empty:first-child::before]:content-[attr(data-placeholder)]","[&_.ProseMirror_p.is-editor-empty:first-child::before]:text-muted-foreground","[&_.ProseMirror_p.is-editor-empty:first-child::before]:opacity-50","[&_.ProseMirror_p.is-editor-empty:first-child::before]:float-left","[&_.ProseMirror_p.is-editor-empty:first-child::before]:pointer-events-none","[&_.ProseMirror_p.is-editor-empty:first-child::before]:h-0",m,p),e[3]=l,e[4]=m,e[5]=p,e[6]=g):g=e[6];let _;e[7]!==u||e[8]!==g?(_=r.jsx(ig,{editor:u,className:g}),e[7]=u,e[8]=g,e[9]=_):_=e[9];const v=i??null;let x;e[10]!==u||e[11]!==v?(x=r.jsx(S.Suspense,{fallback:null,children:r.jsx(X1,{editor:u,virtualMcpId:v})}),e[10]=u,e[11]=v,e[12]=x):x=e[12];const b=i??null;let y;e[13]!==u||e[14]!==b?(y=r.jsx(S.Suspense,{fallback:null,children:r.jsx(q1,{editor:u,virtualMcpId:b})}),e[13]=u,e[14]=b,e[15]=y):y=e[15];let C;e[16]!==u||e[17]!==o||e[18]!==d?(C=d&&o?r.jsx(Mx,{editor:u,selectedModel:o}):null,e[16]=u,e[17]=o,e[18]=d,e[19]=C):C=e[19];let j;return e[20]!==x||e[21]!==y||e[22]!==C||e[23]!==_?(j=r.jsxs(r.Fragment,{children:[_,x,y,C]}),e[20]=x,e[21]=y,e[22]=C,e[23]=_,e[24]=j):j=e[24],j}function pa(t){const e=B.c(3),[s]=Wi();let i;return e[0]!==s.enableSounds||e[1]!==t?(i=()=>{s.enableSounds&&Xg(t.dataUri).catch(o=>{console.warn(`[sound] ${t.name} playback failed:`,o)})},e[0]=s.enableSounds,e[1]=t,e[2]=i):i=e[2],i}const ev={name:"switch-005",dataUri:"data:audio/mpeg;base64,SUQzBAAAAAAAIlRTU0VAAAAOAAADTGF2ZjYyLjMuMTAwAAAAAAAAAAAAAAD/+1DAAAAAAAAAAAAAAAAAAAAAAABJbmZvAAAADwAAABkAABU4ABMTEx0dHR0nJycnMTExMTs7OztERERETk5OTlhYWFhiYmJibGxsbHZ2dnZ/f39/iYmJiZOTk5OdnZ2dp6enp7GxsbG7u7u7xMTExM7Ozs7Y2NjY4uLi4uzs7Oz29vb2/////wAAAABMYXZjNjIuMTEAAAAAAAAAAAAAAAAkBVYAAAAAAAAVOPCP8KUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//tQxAAACEwDXvQRAAG8Ii93HtACUCAABAKCJwfaCEHwfeoEAQdEAYygIHBOCAIAgCAJh9QIOg+D5/ygPh/wfB8DuKAgCHyn9QPh/5SCDv+CEHAQdxOD4B27c39tbckkqYbBAYAN9bNJLB+aXAf5wQAKdzxfbmrVIRQ4xNx3HwnoDmLhfMhgJiiw/HREXNCHqjvHEPEG8QjBYlxQNepJAT0kC8ip6JzSWj1TasoG+iyycbf2Uil1ovf1f/oUtR1qP+s1WSBFKoAAU02BDjMhuP/7UsQEgws8bRpd8YABJYPeBf9wCGXTGxBYcw5AJFMFMAmQQAhGAxgLBgHIAMYAAALhgAchipbe/91aU1VV4zcZj1Vf1XgYCIMBNrsBAIGs9/Ue4i/xFPeqCqwViI9/UeLf///rOngdA3OPHFjmOBv+EQnGahgaZxVplmkAH5JadDTQlNCEuGNiWYbCCONWdUJg6HXNazFdu1T+VgaEpOP70exv7f2/4b/yH//2/4cqCX/zWRUrIw+IPNMNlDnjAXQas/I4AzmYifA0tMSCgQDF//tSxBCDSzzi3k/sQwEyCtjJ/rBZAk+Uqj1YhA5YMCAAMwgOUchTkK7OR7LbMl0W1H6SvzG0Q2ZzfKUhnmTobv9DNhS1v7P8h//8Gv8gTRt1jReZ7YEjmMQg9hhwwMycHooasFmZyjcZGBKJD+IwbMCQQLoi+IQXCcIoydKoilI2MWFS5uJdDEu2taRrYI2ZSqKY50pJLv2NfjUAAuQAMfqVQ/T3PDQgMJMeEZ45hJzY6MNoFMxqTj1zNGQKJjAxEsSCBgQJBSIL0mcKYQJfVAn/+1LEGwLKlEKrD3MiYcuMkVa/wABB8Vh6M1q1epbvXwWBURhkyEhWZ/////////////9gjZ/Wt4w+4MNMCpE4TBYQl4w1IHvMDdA2zBngBMwc8COMDhCpDAfgOAAgrBgNYU+YC0FBGAkAMpgWoSCYAGESGBGAKBgXgJOdiOJmMCmNwCYNDJhYRPykRCJhTBnEUzlsjv4UNLj/z97n3Mv/7z1nZqyitYAZIqErIwMwJAqEw0GAAMFptJMaqFwB8CQIWlhuhuDAwNjfuwrQFAYXCf/7UsQVAA+9PTP42gYRdiIu9zBwAPbFUCi0DAhgNcS+7cDwVgM05A9bUDeuQMyE/u3CygVISgZhpIau/9PhdQG2C9DpxZZJmn/dn/Psmt0EFm////l84ThUTopE4VD/9JkubOGasTvN30C20G21qgUCkVCoUCgPMywrPCGly27V5q5t24vl/8jSlSAPCxzNseNCw3oh3NGBu4BZJ5hv7DRSfR/+eWG7nA8IKh2Olv5iz3q5m3//Joxo3JqNyYkSuGt/k6D4DeoBOHmHdl0dkZYA//tSxAUAC4B1Z/2DADEcA17Z/uhI4Yoik/TrZo+ww7UtmpW4LDWu2IacoJKJJeTSM+ZmAYBEiU+ZnnAwCn1VVVV6JUJQVnioKhrgqdKgqGpUFeCp0sDR3ztQNREDRUFioKuxKCpYGQBlRIBk+aLwb8KblGQVDdphPYTUdBOGbVpAaTF6ZdjEV0iRUZRCYkA4oUQDx5zqDugtXvza/7fuNNvfZ+j9v+T/2f//J/4cAAOTpE5K4zksR9MfIB+TDcQTI4gNs1XKAzEFUrGkxABYEBb/+1LEEYNKrEjgT/TCwYYVmUX+mHoKgWhKU5Eiw9SFIRmppw+3fYo4siPhUFeexM8KgIO6wVuPDDy01qeRaVbw357//y3+o8M0pBNlNLCGBzGKwyYw2IIFOE1WNTjRM6x8MlA1AxDhUHTAkEiyKpnbWrLcaOBotBUKbk1pypcWDAIK00AhKLGkUco6q9VWvM53mcaq3tVa8zjTM/tX//EDP//////////XAAmrwAAPoKwcw0ShDCZD/BQlhzinxQdorsOuXTEIC01ZkJyu4k/qPP/7UsQUAEjkrrkvZaPBIRXUoe5QObfMhYKX9RVgTPqCSCaSCaSC0XVdV1f/////6IAlguuAJSiDRNloNBsZg+0+Ts8MMCn81WUTRAlIi+GHECD0y8AWDIqswYsxGOSKVV7MqOni8tkVOip0fZX/////9HrMCbAz2EHGS4GKAAiRAAAYAcDdKd4G6Z/nwYgJ0ZAIgZyC8aPAs/iPBhwMpWDQNARltNS5Y61v//9i8Yl4SkFkIGTkAc0UBrIYLPA4MYBEy+YLMRuY4nhTC3hZA68H//tSxCoAyQC6mY6CkWDJBIsBz/QUrgNmahSzcrYw0/HhfnMAZBojDsgTFkDR5MDkG/DZEbk2FCmowqdqv2TYABiJwqqYjaQRGZ1URZ1DhSsdiHX/GBu0QpzIBNSaLqZ0ARkwFARxMrpt/Eh47mbQAhhU6sisFUxBTUUzLjEwMFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVX/+1LESoHHJCRaj/dmYAIAQAAQAARVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVTEFNRTMuMTAwVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVf/7UsSLg8AAAaQAAAAgAAA0gAAABFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVTEFNRTMuMTAwVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV//tSxKGDwAABpAAAACAAADSAAAAEVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVMQU1FMy4xMDBVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV//tSxKGDwAABpAAAACAAADSAAAAEVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVMQU1FMy4xMDBVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV//tSxKGDwAABpAAAACAAADSAAAAEVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVMQU1FMy4xMDBVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVX/+1LEoYPAAAGkAAAAIAAANIAAAARVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVUxBTUUzLjEwMFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVf/7UsShg8AAAaQAAAAgAAA0gAAABFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVTEFNRTMuMTAwVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV//tSxKGDwAABpAAAACAAADSAAAAEVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVMQU1FMy4xMDBVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVX/+1LEoYPAAAGkAAAAIAAANIAAAARVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVUxBTUUzLjEwMFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV//tSxKGDwAABpAAAACAAADSAAAAEVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVMQU1FMy4xMDBVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV//tSxKGDwAABpAAAACAAADSAAAAEVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVMQU1FMy4xMDBVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV//tSxKGDwAABpAAAACAAADSAAAAEVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVMQU1FMy4xMDBVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV//tSxKGDwAABpAAAACAAADSAAAAEVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVMQU1FMy4xMDBVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV//tSxKGDwAABpAAAACAAADSAAAAEVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVMQU1FMy4xMDBVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV",duration:.609,format:"mp3",license:"CC0",author:"Kenney"},tv=[{src:"/connections/gmail.png",name:"Gmail"},{src:"/connections/perplexity.png",name:"Perplexity"},{src:"/connections/github.png",name:"GitHub"}];function sv(){const t=B.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=r.jsx("div",{className:"flex items-center -space-x-1.5",children:tv.map(iv)}),t[0]=e):e=t[0],e}function iv(t){return r.jsx("img",{src:t.src,alt:t.name,className:"size-5 rounded-sm ring-1 ring-border object-cover bg-white"},t.name)}function rv(t){const e=B.c(129),{disabled:s,onOpenConnections:i,virtualMcpId:n}=t,[o,a]=S.useState(!1),l=pa(ev),{org:c}=be(),{editor:d}=to();let u;e[0]!==c.id||e[1]!==n?(u={connectionId:n,orgId:c.id},e[0]=c.id,e[1]=n,e[2]=u):u=e[2];const h=Me(u);let f;e[3]!==c.id||e[4]!==n?(f=lt.virtualMcpPrompts(n,c.id),e[3]=c.id,e[4]=n,e[5]=f):f=e[5];const m=f;let p;e[6]!==h?(p=()=>Pn(h),e[6]=h,e[7]=p):p=e[7];const g=o&&!!h;let _;e[8]!==m||e[9]!==p||e[10]!==g?(_={queryKey:m,queryFn:p,staleTime:6e4,enabled:g},e[8]=m,e[9]=p,e[10]=g,e[11]=_):_=e[11];const{data:v,isLoading:x}=Fi(_);let b;e[12]!==v?.prompts?(b=v?.prompts??[],e[12]=v?.prompts,e[13]=b):b=e[13];const y=b,[C,j]=S.useState(null),{credentialId:V,imageModel:w,setImageModel:k,deepResearchModel:T,setDeepResearchModel:I,chatMode:A,setChatMode:N,simpleModeEnabled:E}=ni(),R=A==="plan",[M,L]=S.useState(!1),[D,P]=S.useState(!1),{models:O,isLoading:z}=tu(M||D?V??void 0:void 0);let $,W,F,G,q,H,ee,K,U,te,Y,J,ie;if(e[14]!==C||e[15]!==O||e[16]!==A||e[17]!==h||e[18]!==T||e[19]!==s||e[20]!==d||e[21]!==w||e[22]!==M||e[23]!==z||e[24]!==R||e[25]!==i||e[26]!==o||e[27]!==l||e[28]!==D||e[29]!==N||e[30]!==I||e[31]!==k||e[32]!==E){const Q=O.filter(ov),ae=O.filter(nv);let Se;e[46]!==A||e[47]!==R||e[48]!==l||e[49]!==N?(Se=()=>{l();const _e=R?"default":"plan";se("chat_mode_changed",{from_mode:A,to_mode:_e,source:"tools_popover"}),N(_e),a(!1)},e[46]=A,e[47]=R,e[48]=l,e[49]=N,e[50]=Se):Se=e[50];const Ne=Se;let Be;e[51]!==i?(Be=()=>{i(),a(!1)},e[51]=i,e[52]=Be):Be=e[52],F=Be;let Oe;e[53]!==h||e[54]!==d?(Oe=async(_e,Ot)=>{if(!d||!h)return;const $t=si(_e._meta),ls={from:d.state.selection.from,to:d.state.selection.to};try{const Qi=await ul(h,_e.name,Ot);Cr(d,ls,{id:_e.name,name:al(_e.name,$t),metadata:Qi.messages,char:"/"})}catch{ge.error("Failed to load prompt. Please try again.")}},e[53]=h,e[54]=d,e[55]=Oe):Oe=e[55];const He=Oe;let Je;e[56]!==He?(Je=async _e=>{a(!1);const Ot=!!(_e.arguments&&_e.arguments.length>0);if(se("chat_prompt_inserted",{prompt_name:_e.name,with_arguments:Ot}),Ot){j(_e);return}await He(_e)},e[56]=He,e[57]=Je):Je=e[57],q=Je;let dt;e[58]!==C||e[59]!==He?(dt=async _e=>{C&&(await He(C,_e),j(null))},e[58]=C,e[59]=He,e[60]=dt):dt=e[60],G=dt;let pe;e[61]!==l||e[62]!==k?(pe=_e=>{l(),se("chat_image_model_selected",{model_id:_e.modelId,model_title:_e.title,provider:_e.providerId??null}),k(_e),a(!1)},e[61]=l,e[62]=k,e[63]=pe):pe=e[63];const ke=pe;let Qe;e[64]!==l||e[65]!==I?(Qe=_e=>{l(),se("chat_search_model_selected",{model_id:_e.modelId,model_title:_e.title,provider:_e.providerId??null}),I(_e),a(!1)},e[64]=l,e[65]=I,e[66]=Qe):Qe=e[66];const Ct=Qe;let Pe;e[67]!==A||e[68]!==l||e[69]!==N?(Pe=()=>{l();const _e=A==="gen-image"?"default":"gen-image";se("chat_mode_changed",{from_mode:A,to_mode:_e,source:"tools_popover"}),N(_e),a(!1)},e[67]=A,e[68]=l,e[69]=N,e[70]=Pe):Pe=e[70];const Kt=Pe;let jt;e[71]!==A||e[72]!==l||e[73]!==N?(jt=()=>{l();const _e=A==="web-search"?"default":"web-search";se("chat_mode_changed",{from_mode:A,to_mode:_e,source:"tools_popover"}),N(_e),a(!1)},e[71]=A,e[72]=l,e[73]=N,e[74]=jt):jt=e[74];const Ae=jt,Ie=A==="gen-image",qe=A==="web-search";W=js,K=o,e[75]!==A||e[76]!==o?(U=_e=>{_e&&!o&&se("chat_tools_popover_opened",{chat_mode:A}),a(_e)},e[75]=A,e[76]=o,e[77]=U):U=e[77];let qt,_t;e[78]===Symbol.for("react.memo_cache_sentinel")?(qt=r.jsx(zh,{size:14}),_t=r.jsx("span",{className:"hidden sm:inline",children:"Tools"}),e[78]=qt,e[79]=_t):(qt=e[78],_t=e[79]),e[80]!==s?(te=r.jsx(ks,{asChild:!0,children:r.jsxs(ne,{type:"button",variant:"ghost",size:"default",disabled:s,className:"text-muted-foreground hover:text-foreground",children:[qt,_t]})}),e[80]=s,e[81]=te):te=e[81],$=Ns,Y="start",J="w-52 p-1.5";const xt=R&&"text-violet-600 dark:text-violet-400";let vt;e[82]!==xt?(vt=X(xt),e[82]=xt,e[83]=vt):vt=e[83];const _s=R&&"text-violet-500";let $e;e[84]!==_s?($e=X(_s),e[84]=_s,e[85]=$e):$e=e[85];let kt;e[86]!==$e?(kt=r.jsx(Xh,{size:16,className:$e}),e[86]=$e,e[87]=kt):kt=e[87];let Nt;e[88]===Symbol.for("react.memo_cache_sentinel")?(Nt=r.jsx("span",{className:"flex-1",children:"Plan mode"}),e[88]=Nt):Nt=e[88];let wt;e[89]!==R?(wt=R&&r.jsx("span",{className:"text-xs text-violet-500 font-medium",children:"On"}),e[89]=R,e[90]=wt):wt=e[90],e[91]!==Ne||e[92]!==vt||e[93]!==kt||e[94]!==wt?(ie=r.jsxs(ot,{onClick:Ne,className:vt,children:[kt,Nt,wt]}),e[91]=Ne,e[92]=vt,e[93]=kt,e[94]=wt,e[95]=ie):ie=e[95],H=E?r.jsxs(ot,{onClick:Kt,className:X(Ie&&"text-pink-600 dark:text-pink-400"),children:[r.jsx(la,{size:16,className:X(Ie&&"text-pink-500")}),r.jsx("span",{className:"flex-1",children:"Create image"}),Ie&&r.jsx("span",{className:"text-xs text-pink-500 font-medium",children:"On"})]}):r.jsxs(Sn,{open:M,onOpenChange:L,children:[r.jsxs("div",{className:"flex items-center rounded-lg",children:[r.jsxs(ot,{onClick:Kt,disabled:!w,className:X("flex-1 rounded-r-none pr-1",Ie&&"text-pink-600 dark:text-pink-400"),children:[r.jsx(la,{size:16,className:X(Ie&&"text-pink-500")}),r.jsx("span",{className:"flex-1",children:"Create image"}),Ie&&r.jsx("span",{className:"text-xs text-pink-500 font-medium",children:"On"})]}),r.jsx(lc,{className:X("flex items-center justify-center rounded-r-lg rounded-l-none px-1.5 py-1.5 text-muted-foreground outline-hidden select-none","hover:bg-accent hover:text-accent-foreground focus:bg-accent focus:text-accent-foreground","data-[state=open]:bg-accent data-[state=open]:text-accent-foreground"),children:r.jsx(kr,{size:14})})]}),r.jsx(wn,{className:"w-80 max-h-72 overflow-y-auto p-1.5",children:z?r.jsxs("div",{className:"flex items-center gap-2 px-2 py-3 text-sm text-muted-foreground",children:[r.jsx(Ee,{size:14,className:"animate-spin"}),"Loading models…"]}):Q.length===0?r.jsx("div",{className:"px-2 py-3 text-sm text-muted-foreground",children:"No image models available"}):Q.map(_e=>{const Ot=w?.modelId===_e.modelId,$t=xc(_e),ls=_e.title.includes(": ")?_e.title.split(": ").slice(1).join(": "):_e.title;return r.jsxs(ot,{onClick:()=>ke(_e),className:"flex items-center gap-2",children:[r.jsx("img",{src:$t,alt:"",className:"size-4 shrink-0 rounded-sm dark:bg-white dark:p-px"}),r.jsx("span",{className:"flex-1 text-sm truncate",children:ls}),Ot&&r.jsx(Jt,{size:14,className:"text-pink-500 shrink-0"})]},_e.modelId)})})]}),ee=E?r.jsxs(ot,{onClick:Ae,className:X(qe&&"text-blue-600 dark:text-blue-400"),children:[r.jsx(Ti,{size:16,className:X(qe&&"text-blue-500")}),r.jsx("span",{className:"flex-1",children:"Web search"}),qe&&r.jsx("span",{className:"text-xs text-blue-500 font-medium",children:"On"})]}):T&&r.jsxs(Sn,{open:D,onOpenChange:P,children:[r.jsxs("div",{className:"flex items-center rounded-lg",children:[r.jsxs(ot,{onClick:Ae,className:X("flex-1 rounded-r-none pr-1",qe&&"text-blue-600 dark:text-blue-400"),children:[r.jsx(Ti,{size:16,className:X(qe&&"text-blue-500")}),r.jsx("span",{className:"flex-1",children:"Web search"}),qe&&r.jsx("span",{className:"text-xs text-blue-500 font-medium",children:"On"})]}),r.jsx(lc,{className:X("flex items-center justify-center rounded-r-lg rounded-l-none px-1.5 py-1.5 text-muted-foreground outline-hidden select-none","hover:bg-accent hover:text-accent-foreground focus:bg-accent focus:text-accent-foreground","data-[state=open]:bg-accent data-[state=open]:text-accent-foreground"),children:r.jsx(kr,{size:14})})]}),r.jsx(wn,{className:"w-80 max-h-72 overflow-y-auto p-1.5",children:z?r.jsxs("div",{className:"flex items-center gap-2 px-2 py-3 text-sm text-muted-foreground",children:[r.jsx(Ee,{size:14,className:"animate-spin"}),"Loading models…"]}):ae.map(_e=>{const Ot=T?.modelId===_e.modelId,$t=xc(_e),ls=_e.title.includes(": ")?_e.title.split(": ").slice(1).join(": "):_e.title;return r.jsxs(ot,{onClick:()=>Ct(_e),className:"flex items-center gap-2",children:[r.jsx("img",{src:$t,alt:"",className:"size-4 shrink-0 rounded-sm dark:bg-white dark:p-px"}),r.jsx("span",{className:"flex-1 text-sm truncate",children:ls}),Ot&&r.jsx(Jt,{size:14,className:"text-blue-500 shrink-0"})]},_e.modelId)})})]}),e[14]=C,e[15]=O,e[16]=A,e[17]=h,e[18]=T,e[19]=s,e[20]=d,e[21]=w,e[22]=M,e[23]=z,e[24]=R,e[25]=i,e[26]=o,e[27]=l,e[28]=D,e[29]=N,e[30]=I,e[31]=k,e[32]=E,e[33]=$,e[34]=W,e[35]=F,e[36]=G,e[37]=q,e[38]=H,e[39]=ee,e[40]=K,e[41]=U,e[42]=te,e[43]=Y,e[44]=J,e[45]=ie}else $=e[33],W=e[34],F=e[35],G=e[36],q=e[37],H=e[38],ee=e[39],K=e[40],U=e[41],te=e[42],Y=e[43],J=e[44],ie=e[45];let ue;e[96]===Symbol.for("react.memo_cache_sentinel")?(ue=r.jsxs(Bh,{className:"gap-2",children:[r.jsx("span",{className:"flex size-4 items-center justify-center text-base font-medium text-muted-foreground",children:"/"}),r.jsx("span",{className:"flex-1",children:"Prompts"})]}),e[96]=ue):ue=e[96];let de;e[97]!==q||e[98]!==x||e[99]!==y?(de=x?r.jsxs("div",{className:"flex items-center gap-2 px-2 py-3 text-sm text-muted-foreground",children:[r.jsx(Ee,{size:14,className:"animate-spin"}),"Loading prompts…"]}):y.length===0?r.jsx("div",{className:"px-2 py-3 text-sm text-muted-foreground",children:"No prompts available"}):y.map(Q=>r.jsxs(ot,{onClick:()=>q(Q),className:"flex flex-col items-start gap-0.5",children:[r.jsx("span",{className:"font-medium text-sm capitalize",children:Q.title||eo(Q.name,si(Q._meta))}),Q.description&&r.jsx("span",{className:"text-xs text-muted-foreground line-clamp-2",children:Q.description})]},Q.name)),e[97]=q,e[98]=x,e[99]=y,e[100]=de):de=e[100];let xe;e[101]!==de?(xe=r.jsxs(Sn,{children:[ue,r.jsx(wn,{className:"w-80 max-h-72 overflow-y-auto p-1.5",children:de})]}),e[101]=de,e[102]=xe):xe=e[102];let oe,he;e[103]===Symbol.for("react.memo_cache_sentinel")?(oe=r.jsx(Pg,{size:16}),he=r.jsx("span",{className:"flex-1",children:"Connections"}),e[103]=oe,e[104]=he):(oe=e[103],he=e[104]);let me;e[105]===Symbol.for("react.memo_cache_sentinel")?(me=r.jsx(S.Suspense,{children:r.jsx(sv,{})}),e[105]=me):me=e[105];let fe;e[106]!==F?(fe=r.jsxs(ot,{onClick:F,children:[oe,he,me]}),e[106]=F,e[107]=fe):fe=e[107];let le;e[108]!==$||e[109]!==H||e[110]!==ee||e[111]!==xe||e[112]!==fe||e[113]!==Y||e[114]!==J||e[115]!==ie?(le=r.jsxs($,{align:Y,className:J,children:[ie,H,ee,xe,fe]}),e[108]=$,e[109]=H,e[110]=ee,e[111]=xe,e[112]=fe,e[113]=Y,e[114]=J,e[115]=ie,e[116]=le):le=e[116];let ve;e[117]!==W||e[118]!==K||e[119]!==U||e[120]!==te||e[121]!==le?(ve=r.jsxs(W,{open:K,onOpenChange:U,children:[te,le]}),e[117]=W,e[118]=K,e[119]=U,e[120]=te,e[121]=le,e[122]=ve):ve=e[122];let Ce;e[123]!==C||e[124]!==G?(Ce=r.jsx(Rl,{prompt:C,setPrompt:j,onSubmit:G}),e[123]=C,e[124]=G,e[125]=Ce):Ce=e[125];let Te;return e[126]!==ve||e[127]!==Ce?(Te=r.jsxs(r.Fragment,{children:[ve,Ce]}),e[126]=ve,e[127]=Ce,e[128]=Te):Te=e[128],Te}function nv(t){const e=t.modelId.toLowerCase().replace(/[^a-z0-9]/g,"");return e.includes("sonar")||e.includes("deepresearch")}function ov(t){return t.capabilities?.includes("image")}function av({open:t,onOpenChange:e,onCreated:s}){const{org:i}=be(),{data:n}=St.useSession(),{stdioEnabled:o}=Qm(),a=Rs(),l=Sl(),c=au(),u=lu(c,"").items,h=Hi({resolver:Or(Qg),defaultValues:{title:"",description:null,icon:null,ui_type:"HTTP",connection_url:"",connection_token:null,npx_package:"",stdio_command:"",stdio_args:"",stdio_cwd:"",env_vars:[]}}),f=h.watch("ui_type"),m=h.watch("connection_url"),p=h.watch("npx_package"),g=on({uiType:f,connectionUrl:m??"",npxPackage:p??""})??vc({uiType:f,connectionUrl:m??"",registryItems:u}),_=V=>{const w=V.trim();if(!w)return;const k=!!h.formState.dirtyFields.title,T=!!h.formState.dirtyFields.description,I=!!h.formState.dirtyFields.env_vars,A=E=>{if(E&&(!k&&!h.getValues("title").trim()&&E.title&&h.setValue("title",E.title,{shouldDirty:!1}),!T&&!(h.getValues("description")??"").trim()&&E.description&&h.setValue("description",E.description,{shouldDirty:!1}),!I&&E.envVarKeys?.length)){const R=h.getValues("env_vars")??[],M=new Set(R.map(D=>D.key)),L=E.envVarKeys.filter(D=>!M.has(D));L.length>0&&h.setValue("env_vars",[...R,...L.map(D=>({key:D,value:""}))],{shouldDirty:!0})}},N=e_(w);if(N&&o){h.setValue("ui_type","NPX",{shouldDirty:!0}),h.setValue("npx_package",N.packageName,{shouldDirty:!0}),h.setValue("connection_url","",{shouldDirty:!0}),h.setValue("connection_token",null,{shouldDirty:!0}),A(on({uiType:"NPX",npxPackage:N.packageName}));return}if(w.startsWith("http://")||w.startsWith("https://")){const E=f==="HTTP"||f==="SSE"||f==="Websocket"?f:"HTTP";h.setValue("ui_type",E,{shouldDirty:!0}),h.setValue("connection_url",w,{shouldDirty:!0}),A(on({uiType:E,connectionUrl:w})??vc({uiType:E,connectionUrl:w,registryItems:u}));return}f==="NPX"&&A(on({uiType:"NPX",npxPackage:w}))},v=V=>{V||h.reset(),e(V)},x=async V=>{let w,k=null,T=null,I=null;V.ui_type==="NPX"?(w="STDIO",k="",I=t_(V.npx_package||"",V.env_vars||[])):V.ui_type==="STDIO"?(w="STDIO",k="",I=s_(V.stdio_command||"",V.stdio_args||"",V.stdio_cwd,V.env_vars||[])):(w=V.ui_type,k=V.connection_url||"",T=V.connection_token||null);const A=du("conn");try{await l.create.mutateAsync({id:A,title:V.title,description:V.description||null,connection_type:w,connection_url:k,connection_token:T,created_at:new Date().toISOString(),updated_at:new Date().toISOString(),created_by:n?.user?.id||"system",organization_id:i.id,icon:V.icon??null,app_name:null,app_id:null,connection_headers:I,oauth_config:null,configuration_state:null,metadata:null,tools:null,bindings:null,status:"inactive"}),h.reset(),e(!1),s?.(A)}catch{ge.error("Failed to create connection")}},b="Create Connection",y="Create a custom connection in your organization. Fill in the details below.",C=h.formState.isSubmitting?"Saving...":"Create Connection",j=r.jsxs("div",{className:"grid gap-4",children:[r.jsx(It,{control:h.control,name:"ui_type",render:({field:V})=>r.jsxs(Rt,{children:[r.jsx(rs,{children:"Type *"}),r.jsxs(Qs,{value:V.value,onValueChange:V.onChange,children:[r.jsx(Tt,{children:r.jsx(Zs,{children:r.jsx(ei,{})})}),r.jsxs(Js,{children:[r.jsx(Ht,{value:"HTTP",children:r.jsxs("span",{className:"flex items-center gap-2",children:[r.jsx(Ti,{className:"w-4 h-4"}),"HTTP"]})}),r.jsx(Ht,{value:"SSE",children:r.jsxs("span",{className:"flex items-center gap-2",children:[r.jsx(Ti,{className:"w-4 h-4"}),"SSE"]})}),r.jsx(Ht,{value:"Websocket",children:r.jsxs("span",{className:"flex items-center gap-2",children:[r.jsx(Ti,{className:"w-4 h-4"}),"Websocket"]})}),o&&r.jsxs(r.Fragment,{children:[r.jsx(Ht,{value:"NPX",children:r.jsxs("span",{className:"flex items-center gap-2",children:[r.jsx(Vn,{className:"w-4 h-4"}),"NPX Package"]})}),r.jsx(Ht,{value:"STDIO",children:r.jsxs("span",{className:"flex items-center gap-2",children:[r.jsx(fl,{className:"w-4 h-4"}),"Custom Command"]})})]})]})]}),r.jsx(Dt,{})]})}),f==="NPX"&&r.jsx(It,{control:h.control,name:"npx_package",render:({field:V})=>r.jsxs(Rt,{children:[r.jsx(rs,{children:"NPM Package *"}),r.jsx(Tt,{children:r.jsx(bt,{placeholder:"@perplexity-ai/mcp-server",...V,value:V.value??"",onPaste:w=>{const k=w.clipboardData.getData("text");k&&(w.preventDefault(),h.setValue("npx_package",k.trim(),{shouldDirty:!0}),_(k))},onBlur:w=>{_(w.target.value),V.onBlur()}})}),r.jsx(Dt,{})]})}),f==="STDIO"&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"grid grid-cols-2 gap-4 items-start",children:[r.jsx(It,{control:h.control,name:"stdio_command",render:({field:V})=>r.jsxs(Rt,{children:[r.jsx(rs,{children:"Command *"}),r.jsx(Tt,{children:r.jsx(bt,{placeholder:"node, bun, python...",...V,value:V.value??""})}),r.jsx(Dt,{})]})}),r.jsx(It,{control:h.control,name:"stdio_args",render:({field:V})=>r.jsxs(Rt,{children:[r.jsx(rs,{children:"Arguments"}),r.jsx(Tt,{children:r.jsx(bt,{placeholder:"arg1 arg2 --flag value",...V,value:V.value??""})}),r.jsx(Dt,{})]})})]}),r.jsx(It,{control:h.control,name:"stdio_cwd",render:({field:V})=>r.jsxs(Rt,{children:[r.jsx(rs,{children:"Working Directory"}),r.jsx(Tt,{children:r.jsx(bt,{placeholder:"/path/to/project (optional)",...V,value:V.value??""})}),r.jsx("p",{className:"text-xs text-muted-foreground",children:"Directory where the command will be executed"}),r.jsx(Dt,{})]})})]}),(f==="NPX"||f==="STDIO")&&r.jsx(It,{control:h.control,name:"env_vars",render:({field:V})=>r.jsxs(Rt,{children:[r.jsx(rs,{children:"Environment Variables"}),r.jsx(Tt,{children:r.jsx(Zg,{value:V.value??[],onChange:V.onChange})}),r.jsx(Dt,{})]})}),f!=="NPX"&&f!=="STDIO"&&r.jsxs(r.Fragment,{children:[r.jsx(It,{control:h.control,name:"connection_url",render:({field:V})=>r.jsxs(Rt,{children:[r.jsx(rs,{children:"URL *"}),r.jsx(Tt,{children:r.jsx(bt,{placeholder:"https://example.com/mcp",...V,value:V.value??"",onPaste:w=>{const k=w.clipboardData.getData("text");k&&(w.preventDefault(),h.setValue("connection_url",k.trim(),{shouldDirty:!0}),_(k))},onBlur:w=>{_(w.target.value),V.onBlur()}})}),r.jsx(Dt,{})]})}),r.jsx(It,{control:h.control,name:"connection_token",render:({field:V})=>r.jsxs(Rt,{children:[r.jsx(rs,{children:g?.token?.label??"Token (optional)"}),r.jsx(Tt,{children:r.jsx(bt,{type:"password",placeholder:g?.token?.placeholder??"Bearer token or API key",className:"ph-no-capture",...V,value:V.value??""})}),g?.token?.helperText&&r.jsxs("p",{className:"text-xs text-muted-foreground",children:[g.token.helperText,g.id==="github"&&r.jsxs(r.Fragment,{children:[" ","·"," ",r.jsx("a",{className:"text-foreground underline underline-offset-4 hover:text-foreground/80",href:"https://github.com/settings/personal-access-tokens",target:"_blank",rel:"noreferrer",children:"Open GitHub PAT settings"})]})]}),r.jsx(Dt,{})]})})]}),r.jsx(It,{control:h.control,name:"title",render:({field:V})=>r.jsxs(Rt,{children:[r.jsx(rs,{children:"Name *"}),r.jsx(Tt,{children:r.jsx(bt,{placeholder:"My Connection",...V})}),r.jsx(Dt,{})]})}),r.jsx(It,{control:h.control,name:"description",render:({field:V})=>r.jsxs(Rt,{children:[r.jsx(rs,{children:"Description"}),r.jsx(Tt,{children:r.jsx(ca,{placeholder:"A brief description of this connection",rows:3,...V,value:V.value??""})}),r.jsx(Dt,{})]})})]});return a?r.jsx(Si,{open:t,onOpenChange:v,children:r.jsxs(yi,{className:"max-h-[90vh]",children:[r.jsx(so,{className:"pb-2",children:r.jsxs("div",{className:"flex items-start justify-between gap-4",children:[r.jsxs("div",{className:"flex-1 text-left",children:[r.jsx(bi,{children:b}),r.jsx(rg,{className:"mt-1",children:y})]}),r.jsx(ng,{asChild:!0,children:r.jsx(ne,{variant:"ghost",size:"icon",className:"shrink-0 -mt-1",children:r.jsx(ii,{size:16})})})]})}),r.jsx(Pi,{...h,children:r.jsxs("form",{onSubmit:h.handleSubmit(x),children:[r.jsx("div",{className:"overflow-y-auto px-4 pb-4",children:j}),r.jsx(og,{children:r.jsx(ne,{type:"submit",disabled:h.formState.isSubmitting,className:"w-full",children:C})})]})})]})}):r.jsx(ps,{open:t,onOpenChange:v,children:r.jsxs(ms,{className:"sm:max-w-[525px]",children:[r.jsxs(Ds,{children:[r.jsx(Ts,{children:b}),r.jsx(dl,{children:y})]}),r.jsx(Pi,{...h,children:r.jsxs("form",{onSubmit:h.handleSubmit(x),children:[r.jsx("div",{className:"py-4",children:j}),r.jsxs(cl,{children:[r.jsx(ne,{type:"button",variant:"outline",onClick:()=>v(!1),children:"Cancel"}),r.jsx(ne,{type:"submit",disabled:h.formState.isSubmitting,className:"min-w-40",children:C})]})]})})]})})}function lv(t){const e=B.c(79),{mode:s,agentId:i,addedConnectionIds:n,onAdd:o,onCloneAndAdd:a,onConnectAndAdd:l,connectingItemId:c,search:d,onCreateConnection:u,onBrowseNavigate:h,defaultTab:f}=t,m=s===void 0?"add":s,p=f===void 0?"connected":f,{org:g}=be(),_=S.useDeferredValue(d),v=d!==_;let x;e[0]!==_?(x=_.toLowerCase(),e[0]=_,e[1]=x):x=e[1];const b=x;let y;e[2]!==p?(y=pe=>pe??p,e[2]=p,e[3]=y):y=e[3];const[C,j]=nl(ol.connectionsTab(g.slug)+(p==="all"?":home-modal":":agent-modal"),y);let V;e[4]!==C||e[5]!==j?(V=pe=>{pe!==C&&se("connections_dialog_tab_changed",{to_tab:pe}),j(pe)},e[4]=C,e[5]=j,e[6]=V):V=e[6];const w=V;let k;e[7]!==g.id?(k={connectionId:Wt,orgId:g.id},e[7]=g.id,e[8]=k):k=e[8];const T=Me(k);let I,A,N;if(e[9]!==T||e[10]!==_||e[11]!==g.id){N=_?.trim()?{operator:"or",conditions:[{field:["title"],operator:"contains",value:_.trim()},{field:["description"],operator:"contains",value:_.trim()}]}:void 0;const pe={...N&&{where:N},orderBy:[{field:["updated_at"],direction:"asc"}],limit:100,offset:0},ke=JSON.stringify(pe);A=i_,I=lt.collectionListInfinite(T,g.id,"","CONNECTIONS",ke),e[9]=T,e[10]=_,e[11]=g.id,e[12]=I,e[13]=A,e[14]=N}else I=e[12],A=e[13],N=e[14];let E;e[15]!==T||e[16]!==N?(E=async pe=>{const{pageParam:ke}=pe,Qe=ke===void 0?0:ke;return(await T.callTool({name:"COLLECTION_CONNECTIONS_LIST",arguments:{...N&&{where:N},orderBy:[{field:["updated_at"],direction:"asc"}],limit:100,offset:Qe}})).structuredContent},e[15]=T,e[16]=N,e[17]=E):E=e[17];let R;e[18]!==I||e[19]!==E?(R={queryKey:I,queryFn:E,initialPageParam:0,getNextPageParam:mv,staleTime:3e4},e[18]=I,e[19]=E,e[20]=R):R=e[20];const{data:M,fetchNextPage:L,hasNextPage:D,isFetchingNextPage:P}=A(R),O=M?.pages.flatMap(fv)??[],z=Jg(O),$=new Set(O.filter(uv).map(hv)),W=au(),F=lu(W,_),G=bc(F.loadMore,F.hasMore,F.isLoadingMore),q=bc(L,D??!1,P),H=C==="all"||!!b,ee=H?F.items.filter(pe=>{const ke=c_(pe);return!(ke&&$.has(ke))}):[],K=ee.filter(dv),U=ee.filter(cv);let te;e[21]!==n?(te=pe=>pe.some(ke=>n.has(ke.id)),e[21]=n,e[22]=te):te=e[22];const Y=te;let J;e[23]!==n||e[24]!==i||e[25]!==c||e[26]!==Y||e[27]!==m||e[28]!==o||e[29]!==h||e[30]!==a?(J=(pe,ke,Qe,Ct,Pe)=>{const Kt=Y(Pe),jt=Pe.find(Ie=>!n.has(Ie.id)),Ae=Pe[0];if(m==="browse"){const Ie=nu(Ae);return r.jsx(jo,{connection:{title:ke,icon:Qe,description:Pe.length>1?`${Pe.length} instances`:Ct??void 0},fallbackIcon:r.jsx(Vn,{}),headerActionsAlwaysVisible:!0,headerActions:r.jsxs(wc,{variant:"secondary",className:"text-xs gap-1 font-normal",children:[r.jsx(Jt,{size:11})," Connected"]}),onClick:()=>{se("connection_browse_clicked",{app_name:Ae.app_name??null,connection_id:Ae.id,instances_count:Pe.length}),h?.(Ie)}},pe)}return r.jsx(jo,{connection:{title:ke,icon:Qe,description:Ct},fallbackIcon:r.jsx(Vn,{}),headerActionsAlwaysVisible:!0,headerActions:r.jsxs("div",{className:"flex items-center gap-1.5",children:[Kt&&r.jsxs(wc,{variant:"secondary",className:"text-xs gap-1 font-normal",children:[r.jsx(Jt,{size:11})," Added"]}),r.jsx(ne,{variant:"outline",size:"sm",className:"h-7 px-3 text-xs font-medium",disabled:c!==null,onClick:Ie=>{Ie.stopPropagation(),jt?(se("connection_add_clicked",{action:"use_existing",app_name:Ae.app_name??null,connection_id:jt.id}),i&&se("agent_connection_attached",{agent_id:i,connection_id:jt.id,app_name:Ae.app_name??null,mode:"existing"}),o(jt.id)):(se("connection_add_clicked",{action:"clone",app_name:Ae.app_name??null,base_connection_id:Ae.id}),a(Ae))},children:"Add"})]})},pe)},e[23]=n,e[24]=i,e[25]=c,e[26]=Y,e[27]=m,e[28]=o,e[29]=h,e[30]=a,e[31]=J):J=e[31];const ie=J;let ue;e[32]!==c||e[33]!==m||e[34]!==l?(ue=pe=>{const ke=pe._meta?.["mcp.mesh"],Qe=ke?.friendlyName||ke?.friendly_name||pe.server?.title||pe.title||pe.server?.name||pe.name||pe.id||"",Ct=pe.server?.description||pe.description||null,Pe=pe.server?.icons?.[0]?.src||h_(pe.server?.repository)||null;return r.jsx(jo,{connection:{title:Qe,description:Ct,icon:Pe},fallbackIcon:r.jsx(Vn,{}),headerActionsAlwaysVisible:!0,headerActions:r.jsx(ne,{variant:"outline",size:"sm",className:"h-7 px-3 text-xs font-medium",disabled:c!==null,onClick:Kt=>{Kt.stopPropagation(),se("connection_add_clicked",{action:"connect_new",registry_item_id:pe.id,app_name:pe._meta?.["mcp.mesh"]?.friendlyName||pe.server?.name||pe.name||null}),l(pe)},children:c===pe.id?r.jsx(Ee,{size:14,className:"animate-spin"}):m==="browse"?"Connect":"Add"})},`catalog-${pe.id}`)},e[32]=c,e[33]=m,e[34]=l,e[35]=ue):ue=e[35];const de=ue;let xe;e[36]!==C||e[37]!==w||e[38]!==u||e[39]!==b?(xe=!b&&r.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-border shrink-0",children:[r.jsx(cu,{tabs:[{id:"all",label:"All"},{id:"connected",label:"Connected"}],activeTab:C,onTabChange:pe=>w(pe)}),r.jsxs(ne,{variant:"outline",size:"sm",className:"h-7 px-2 text-sm",onClick:()=>{se("connections_dialog_custom_clicked"),u()},children:[r.jsx(Qt,{size:12}),"Custom Connection"]})]}),e[36]=C,e[37]=w,e[38]=u,e[39]=b,e[40]=xe):xe=e[40];const oe=v&&"opacity-50 pointer-events-none";let he;e[41]!==oe?(he=X("flex-1 overflow-auto p-5 transition-opacity duration-150",oe),e[41]=oe,e[42]=he):he=e[42];const me="grid grid-cols-[repeat(auto-fill,minmax(260px,1fr))] gap-4";let fe;e[43]!==ie?(fe=pe=>{if(pe.type==="group")return ie(pe.key,pe.title,pe.icon,null,pe.connections);const ke=pe.connection;return ie(ke.id,ke.title,ke.icon,ke.description??null,[ke])},e[43]=ie,e[44]=fe):fe=e[44];const le=z.map(fe);let ve;e[45]!==q?(ve=r.jsx("div",{ref:q,className:"col-span-full h-1"}),e[45]=q,e[46]=ve):ve=e[46];let Ce;e[47]!==P?(Ce=P&&r.jsx("div",{className:"col-span-full flex justify-center py-6",children:r.jsx(Ee,{size:24,className:"animate-spin text-muted-foreground"})}),e[47]=P,e[48]=Ce):Ce=e[48];const Te=H&&K.length>0&&r.jsxs("div",{className:"col-span-full flex items-center gap-2 mt-2",children:[r.jsx(Lg,{size:13,className:"text-muted-foreground shrink-0"}),r.jsx("span",{className:"text-sm font-medium text-muted-foreground whitespace-nowrap",children:"Verified"}),r.jsx("div",{className:"flex-1 h-px bg-border"})]}),Q=H&&K.map(de),ae=H&&U.length>0&&r.jsxs("div",{className:"col-span-full flex items-center gap-2 mt-2",children:[r.jsx("span",{className:"text-sm font-medium text-muted-foreground whitespace-nowrap",children:"All connections"}),r.jsx("div",{className:"flex-1 h-px bg-border"})]}),Se=H&&U.map(de);let Ne;e[49]!==G||e[50]!==W||e[51]!==H?(Ne=H&&W.length>0&&r.jsx("div",{ref:G,className:"col-span-full h-1"}),e[49]=G,e[50]=W,e[51]=H,e[52]=Ne):Ne=e[52];let Be;e[53]!==F.isLoadingMore||e[54]!==H?(Be=H&&F.isLoadingMore&&r.jsx("div",{className:"col-span-full flex justify-center py-6",children:r.jsx(Ee,{size:24,className:"animate-spin text-muted-foreground"})}),e[53]=F.isLoadingMore,e[54]=H,e[55]=Be):Be=e[55];let Oe;e[56]!==le||e[57]!==ve||e[58]!==Ce||e[59]!==Te||e[60]!==Q||e[61]!==ae||e[62]!==Se||e[63]!==Ne||e[64]!==Be?(Oe=r.jsxs("div",{className:me,children:[le,ve,Ce,Te,Q,ae,Se,Ne,Be]}),e[56]=le,e[57]=ve,e[58]=Ce,e[59]=Te,e[60]=Q,e[61]=ae,e[62]=Se,e[63]=Ne,e[64]=Be,e[65]=Oe):Oe=e[65];let He;e[66]!==C||e[67]!==z.length||e[68]!==U||e[69]!==d||e[70]!==K?(He=z.length===0&&K.length===0&&U.length===0&&r.jsx("div",{className:"flex items-center justify-center h-48 text-sm text-muted-foreground",children:d?`No connections match "${d}"`:C==="connected"?"No connections yet":"No connections available"}),e[66]=C,e[67]=z.length,e[68]=U,e[69]=d,e[70]=K,e[71]=He):He=e[71];let Je;e[72]!==he||e[73]!==Oe||e[74]!==He?(Je=r.jsxs("div",{className:he,children:[Oe,He]}),e[72]=he,e[73]=Oe,e[74]=He,e[75]=Je):Je=e[75];let dt;return e[76]!==xe||e[77]!==Je?(dt=r.jsxs(r.Fragment,{children:[xe,Je]}),e[76]=xe,e[77]=Je,e[78]=dt):dt=e[78],dt}function cv(t){return!t.verified&&!t._meta?.["mcp.mesh"]?.verified&&!t.meta?.verified}function dv(t){return t.verified||t._meta?.["mcp.mesh"]?.verified||t.meta?.verified}function hv(t){return t.app_name}function uv(t){return t.app_name}function fv(t){return t?.items??[]}function mv(t,e){if(t?.hasMore)return e.reduce(pv,0)}function pv(t,e){return t+(e?.items?.length??0)}function Pl({open:t,onOpenChange:e,defaultTab:s,initialSearch:i="",...n}){const o=n.mode??"add",a="agentId"in n?n.agentId:void 0,l="addedConnectionIds"in n?n.addedConnectionIds??new Set:new Set,c="onAdd"in n&&n.onAdd?n.onAdd:w=>{},d=(w,k,T)=>{a&&se("agent_connection_attached",{agent_id:a,connection_id:w,app_name:k,mode:T})},[u,h]=S.useState(null),[f,m]=S.useState(i),[p,g]=S.useState(!1),{org:_}=be(),{data:v}=St.useSession(),x=Sl(),b=Mt(),y=Ke(),C=w=>{e(!1),y({to:"/$org/settings/connections/$appSlug",params:{org:_.slug,appSlug:w}})},j=async w=>{h(w.app_name??w.id);try{const T=`${w.title.replace(/\s*\(\d+\)\s*$/,"")} (${Date.now().toString(36).slice(-4)})`,A=(await x.create.mutateAsync({title:T,description:w.description??null,connection_type:w.connection_type,connection_url:w.connection_url??null,connection_token:null,icon:w.icon??null,app_name:w.app_name??null,app_id:w.app_id??null,connection_headers:w.connection_headers??null})).id,N=new URL(`/mcp/${A}`,window.location.origin),E=await pr({url:N.href,token:null});if(E.supportsOAuth&&!E.isAuthenticated){const{token:R,tokenInfo:M,error:L}=await vn({connectionId:A,scope:"offline_access"});if(L||!R){se("connection_oauth_failed",{connection_id:A,flow:"clone",error:L??"no_token"}),ge.error(`Authentication failed: ${L??"no token received"}`),await x.delete.mutateAsync(A);return}if(se("connection_oauth_succeeded",{connection_id:A,flow:"clone"}),M)try{(await fetch(`/api/connections/${A}/oauth-token`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({accessToken:M.accessToken,refreshToken:M.refreshToken,expiresIn:M.expiresIn,scope:M.scope,clientId:M.clientId,clientSecret:M.clientSecret,tokenEndpoint:M.tokenEndpoint})})).ok?await x.update.mutateAsync({id:A,data:{}}):await x.update.mutateAsync({id:A,data:{connection_token:R}})}catch{await x.update.mutateAsync({id:A,data:{connection_token:R}})}else await x.update.mutateAsync({id:A,data:{connection_token:R}});await b.invalidateQueries({queryKey:lt.isMCPAuthenticated(N.href,null)})}d(A,w.app_name??null,"clone"),c(A)}catch(k){console.error("Failed to add connection:",k),ge.error("Failed to add connection")}finally{h(null)}},V=async w=>{if(!(!_||!v?.user?.id)){h(w.id);try{const k=d_(w,_.id,v.user.id,{remoteIndex:0}),T=k.connection_type==="STDIO",I=!!k.connection_url,A=T&&k.connection_headers&&typeof k.connection_headers=="object"&&"command"in k.connection_headers;if(!I&&!A){ge.error("This MCP Server cannot be connected: no connection method available"),h(null);return}const{id:N}=await x.create.mutateAsync(k),E=new URL(`/mcp/${N}`,window.location.origin),R=await pr({url:E.href,token:null});if(R.supportsOAuth&&!R.isAuthenticated){const{token:M,tokenInfo:L,error:D}=await vn({connectionId:N,scope:"offline_access"});if(D||!M){se("connection_oauth_failed",{connection_id:N,flow:"connect_new",error:D??"no_token"}),ge.error(`Authentication failed: ${D??"no token received"}`),d(N,k.app_name??null,"new"),c(N);return}if(se("connection_oauth_succeeded",{connection_id:N,flow:"connect_new"}),L)try{(await fetch(`/api/connections/${N}/oauth-token`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({accessToken:L.accessToken,refreshToken:L.refreshToken,expiresIn:L.expiresIn,scope:L.scope,clientId:L.clientId,clientSecret:L.clientSecret,tokenEndpoint:L.tokenEndpoint})})).ok?await x.update.mutateAsync({id:N,data:{}}):await x.update.mutateAsync({id:N,data:{connection_token:M}})}catch{await x.update.mutateAsync({id:N,data:{connection_token:M}})}else await x.update.mutateAsync({id:N,data:{connection_token:M}});await b.invalidateQueries({queryKey:lt.isMCPAuthenticated(E.href,null)}),ge.success("Connected and authenticated")}else ge.success("Connected");d(N,k.app_name??null,"new"),c(N)}catch(k){console.error("Failed to connect:",k),ge.error("Failed to connect")}finally{h(null)}}};return r.jsxs(ps,{open:t,onOpenChange:e,children:[r.jsxs(ms,{className:"sm:max-w-5xl h-[85vh] max-h-[85vh] flex flex-col p-0 gap-0 overflow-hidden w-[95vw]",children:[r.jsx(Ds,{className:"px-6 pt-5 pb-0 shrink-0",children:r.jsx(Ts,{className:"text-base font-semibold",children:o==="browse"?"Connections":"Add Connection"})}),r.jsx("div",{className:"pt-3 shrink-0",children:r.jsx(Th,{value:f,onChange:m,placeholder:"Search connections..."})}),r.jsx(S.Suspense,{fallback:r.jsx("div",{className:"flex-1 flex items-center justify-center",children:r.jsx(Ee,{size:24,className:"animate-spin text-muted-foreground"})}),children:r.jsx(lv,{mode:o,agentId:a,addedConnectionIds:l,onAdd:c,onCloneAndAdd:j,onConnectAndAdd:V,connectingItemId:u,search:f,onCreateConnection:()=>g(!0),onBrowseNavigate:C,defaultTab:s})})]}),r.jsx(av,{open:p,onOpenChange:g,onCreated:async w=>{g(!1);const k=new URL(`/mcp/${w}`,window.location.origin),T=await pr({url:k.href,token:null});if(T.supportsOAuth&&!T.isAuthenticated){const{token:I,tokenInfo:A,error:N}=await vn({connectionId:w,scope:"offline_access"});if(N||!I){se("connection_oauth_failed",{connection_id:w,flow:"custom_create",error:N??"no_token"}),ge.error(`Authentication failed: ${N??"no token received"}`),await x.delete.mutateAsync(w);return}if(se("connection_oauth_succeeded",{connection_id:w,flow:"custom_create"}),A)try{(await fetch(`/api/connections/${w}/oauth-token`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({accessToken:A.accessToken,refreshToken:A.refreshToken,expiresIn:A.expiresIn,scope:A.scope,clientId:A.clientId,clientSecret:A.clientSecret,tokenEndpoint:A.tokenEndpoint})})).ok?await x.update.mutateAsync({id:w,data:{}}):await x.update.mutateAsync({id:w,data:{connection_token:I}})}catch{await x.update.mutateAsync({id:w,data:{connection_token:I}})}else await x.update.mutateAsync({id:w,data:{connection_token:I}});await b.invalidateQueries({queryKey:lt.isMCPAuthenticated(k.href,null)})}d(w,null,"custom"),c(w),e(!1)}})]})}const gv=[{src:"/connections/github.png",name:"GitHub"},{src:"/connections/gmail.png",name:"Gmail"},{src:"/connections/linear.png",name:"Linear"},{src:"/connections/shopify.png",name:"Shopify"},{src:"/connections/firecrawl.png",name:"Firecrawl"},{src:"/connections/perplexity.png",name:"Perplexity"}];function _v(){const t=B.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=r.jsx("div",{className:"flex items-center -space-x-1",children:gv.map(xv)}),t[0]=e):e=t[0],e}function xv(t){return r.jsx("img",{src:t.src,alt:t.name,className:"size-5 rounded-sm ring-2 ring-muted object-cover bg-white"},t.name)}function vv(t){const e=B.c(6),{onClick:s}=t;let i,n,o,a;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=X("group relative z-10 flex items-center gap-3 w-full px-4 py-3","rounded-b-2xl","cursor-pointer"),n=r.jsx("p",{className:"flex-1 text-xs text-muted-foreground truncate text-left",children:"Connect tools and get more done"}),o=r.jsx(_v,{}),a=r.jsx(Vl,{size:14,className:"shrink-0 text-muted-foreground/60 group-hover:text-muted-foreground transition-colors"}),e[0]=i,e[1]=n,e[2]=o,e[3]=a):(i=e[0],n=e[1],o=e[2],a=e[3]);let l;return e[4]!==s?(l=r.jsxs("button",{type:"button",onClick:s,className:i,children:[n,o,a]}),e[4]=s,e[5]=l):l=e[5],l}const cr=48;function bv(){const t=B.c(9),[e,s]=S.useState("idle"),[i,n]=S.useState(""),[o,a]=S.useState(""),[l,c]=S.useState(wv),d=S.useRef(null),u=S.useRef(null),h=S.useRef(null),f=S.useRef(null),m=S.useRef(0),p=S.useRef(!1),g=S.useRef(""),_=S.useRef(""),v=typeof window<"u"&&!!(window.SpeechRecognition||window.webkitSpeechRecognition);let x;t[0]===Symbol.for("react.memo_cache_sentinel")?(x=()=>{m.current&&(cancelAnimationFrame(m.current),m.current=0),u.current?.close().catch(Sv),f.current?.getTracks().forEach(yv),h.current=null,u.current=null,f.current=null},t[0]=x):x=t[0];const b=x;let y;if(t[1]===Symbol.for("react.memo_cache_sentinel")){const I=A=>{f.current=A;const N=new AudioContext;u.current=N;const E=N.createMediaStreamSource(A),R=N.createAnalyser();R.fftSize=128,R.smoothingTimeConstant=.8,E.connect(R),h.current=R;const M=new Uint8Array(R.frequencyBinCount),L=()=>{if(!h.current)return;h.current.getByteFrequencyData(M);const D=[];for(let P=0;P<cr;P++){const O=Math.floor(P/cr*M.length);D.push(Math.max(.04,(M[O]??0)/255))}c(D),m.current=requestAnimationFrame(L)};L()};y=async()=>{const A=window.SpeechRecognition||window.webkitSpeechRecognition;if(!A){s("unsupported");return}let N;try{N=await navigator.mediaDevices.getUserMedia({audio:!0})}catch{s("permission-denied");return}n(""),a(""),_.current="",g.current="",p.current=!0,s("recording"),I(N);const E=new A;d.current=E,E.interimResults=!0,E.continuous=!0,E.lang=navigator.language||"en-US",E.onresult=R=>{let M="",L="";for(let D=R.resultIndex;D<R.results.length;D++){const P=R.results[D],O=P?.[0]?.transcript??"";P?.isFinal?L=L+O:M=M+O}L&&(g.current=g.current+L,n(g.current)),_.current=M,a(M)},E.onend=()=>{if(p.current)try{E.start()}catch{}};try{E.start()}catch{s("idle")}},t[1]=y}else y=t[1];const C=y;let j;t[2]===Symbol.for("react.memo_cache_sentinel")?(j=()=>{p.current=!1,d.current?.stop(),b(),s("idle"),c(Array(cr).fill(.05)),a("");const I=(g.current+(_.current?" "+_.current:"")).trim();return n(""),g.current="",_.current="",I},t[2]=j):j=t[2];const V=j;let w;t[3]===Symbol.for("react.memo_cache_sentinel")?(w=()=>{p.current=!1,d.current?.abort(),b(),s("idle"),n(""),a(""),c(Array(cr).fill(.05)),g.current="",_.current=""},t[3]=w):w=t[3];const k=w;let T;return t[4]!==o||t[5]!==e||t[6]!==i||t[7]!==l?(T={status:e,transcript:i,interimTranscript:o,waveformData:l,isSupported:v,startRecording:C,stopRecording:V,cancelRecording:k},t[4]=o,t[5]=e,t[6]=i,t[7]=l,t[8]=T):T=t[8],T}function yv(t){return t.stop()}function Sv(){}function wv(){return Array(cr).fill(.05)}function Vv(t){const e=B.c(4),{data:s}=t;let i;e[0]!==s?(i=s.map(Cv),e[0]=s,e[1]=i):i=e[1];let n;return e[2]!==i?(n=r.jsx("div",{className:"flex items-center justify-center gap-[2px] h-10 overflow-hidden","aria-hidden":"true",children:i}),e[2]=i,e[3]=n):n=e[3],n}function Cv(t,e){return r.jsx("div",{className:"w-[2px] shrink-0 rounded-full bg-chart-2 transition-[height] duration-75 ease-out",style:{height:`${Math.max(4,Math.round(t*40))}px`}},e)}const Io=[{value:"fast",label:"Fast",Icon:Hh,description:"Quicker responses"},{value:"smart",label:"Smart",Icon:_l,description:"Balanced quality"},{value:"thinking",label:"Thinking",Icon:pg,description:"Deeper reasoning"}];function jv(t){const e=B.c(17),{tier:s,onSelect:i}=t;let n;e[0]!==s?(n=Io.find(m=>m.value===s)??Io[1],e[0]=s,e[1]=n):n=e[1];const o=n,a=o.Icon;let l;e[2]!==a?(l=r.jsx(a,{size:14}),e[2]=a,e[3]=l):l=e[3];let c;e[4]!==o.label?(c=r.jsx("span",{className:"hidden sm:inline",children:o.label}),e[4]=o.label,e[5]=c):c=e[5];let d;e[6]!==l||e[7]!==c?(d=r.jsx(ks,{asChild:!0,children:r.jsxs(ne,{type:"button",variant:"ghost",size:"default",className:"text-muted-foreground hover:text-foreground",children:[l,c]})}),e[6]=l,e[7]=c,e[8]=d):d=e[8];let u;e[9]!==i||e[10]!==s?(u=Io.map(m=>{const{value:p,label:g,Icon:_,description:v}=m;return r.jsxs(ot,{onSelect:()=>i(p),children:[r.jsx(_,{size:16,className:"text-muted-foreground"}),r.jsxs("div",{className:"flex flex-col gap-0.5 flex-1",children:[r.jsx("span",{children:g}),r.jsx("span",{className:"text-xs text-muted-foreground font-normal",children:v})]}),s===p&&r.jsx("span",{className:"text-xs text-muted-foreground font-medium",children:"On"})]},p)}),e[9]=i,e[10]=s,e[11]=u):u=e[11];let h;e[12]!==u?(h=r.jsx(Ns,{align:"end",className:"w-52 p-1.5",children:u}),e[12]=u,e[13]=h):h=e[13];let f;return e[14]!==d||e[15]!==h?(f=r.jsxs(js,{children:[d,h]}),e[14]=d,e[15]=h,e[16]=f):f=e[16],f}function kv(t){const e=B.c(4),{editor:s}=to(),[i,n]=S.useState(!1),o=S.useRef(0);let a,l;return e[0]!==s||e[1]!==t?(a=()=>{const c=f=>{f.dataTransfer?.types.includes("Files")&&(f.preventDefault(),o.current=o.current+1,n(!0))},d=f=>{f.preventDefault(),o.current=Math.max(0,o.current-1),o.current===0&&n(!1)},u=Nv,h=f=>{if(f.preventDefault(),o.current=0,n(!1),!s||!t||!no(t))return;const m=f.dataTransfer?.files;if(!m||m.length===0)return;const{from:p}=s.state.selection;for(const g of Array.from(m))Tl(s,t,g,p)};return window.addEventListener("dragenter",c),window.addEventListener("dragleave",d),window.addEventListener("dragover",u),window.addEventListener("drop",h),()=>{window.removeEventListener("dragenter",c),window.removeEventListener("dragleave",d),window.removeEventListener("dragover",u),window.removeEventListener("drop",h)}},l=[s,t],e[0]=s,e[1]=t,e[2]=a,e[3]=l):(a=e[2],l=e[3]),S.useEffect(a,l),i}function Nv(t){t.dataTransfer?.types.includes("Files")&&t.preventDefault()}function Av(t){const e=B.c(10),{selectedModel:s}=t,i=kv(s);let n;e[0]!==s?(n=no(s),e[0]=s,e[1]=n):n=e[1];const o=n,a=i?"opacity-100":"opacity-0 pointer-events-none",l=o?"border-primary/40 text-primary/70":"border-destructive/30 text-destructive/70";let c;e[2]!==a||e[3]!==l?(c=X("absolute inset-0 z-20 rounded-xl flex flex-col items-center justify-center gap-2 bg-muted border-2 border-dashed transition-opacity",a,l),e[2]=a,e[3]=l,e[4]=c):c=e[4];let d;e[5]!==o?(d=o?r.jsxs(r.Fragment,{children:[r.jsx(Qh,{size:24}),r.jsx("span",{className:"text-sm font-medium",children:"Drop files here"})]}):r.jsxs(r.Fragment,{children:[r.jsx(Jh,{size:24}),r.jsx("span",{className:"text-sm font-medium",children:"This model does not support files"})]}),e[5]=o,e[6]=d):d=e[6];let u;return e[7]!==c||e[8]!==d?(u=r.jsx("div",{className:c,children:d}),e[7]=c,e[8]=d,e[9]=u):u=e[9],u}function Ev({onOpenContextPanel:t,showConnectionsBanner:e=!1}){const{messages:s,isStreaming:i,isRunInProgress:n,sendMessage:o,stop:a}=Ui(),{taskId:l,tasks:c}=es(),{selectedModel:d,selectedVirtualMcp:u,isModelsLoading:h,tiptapDocRef:f,imageModel:m,deepResearchModel:p,chatMode:g,setChatMode:_,simpleModeEnabled:v,simpleModeTier:x,setSimpleModeTier:b}=ni(),{data:y}=St.useSession(),C=y?.user?.id,{org:j}=be(),V=io(j.id).id,w=pa(_c),[k,T]=S.useState(!1),I=bv(),A=S.useRef(void 0),N=async()=>{A.current=L,await I.startRecording();const Y=I.status==="recording"?"started":I.status==="unsupported"?"unsupported":I.status==="permission-denied"?"permission_denied":"unknown";se("chat_voice_started",{thread_id:l,outcome:Y})},E=()=>{se("chat_voice_confirmed",{thread_id:l});const Y=I.stopRecording();W.current?.syncVoiceText(A.current,Y),W.current?.focus()},R=()=>{se("chat_voice_cancelled",{thread_id:l}),I.cancelRecording(),W.current?.restoreContent(A.current)};S.useEffect(()=>{if(I.status!=="recording")return;const Y=(I.transcript+(I.interimTranscript?" "+I.interimTranscript:"")).trim();W.current?.syncVoiceText(A.current,Y)},[I.transcript,I.interimTranscript,I.status]);const M=c.find(Y=>Y.id===l),[L,D]=S.useState(void 0),P=Y=>{D(Y),f.current=Y},O=S.useRef(l);O.current!==l&&(O.current=l,D(void 0),f.current=void 0);const $=[...s].reverse().find(Y=>Y.role==="assistant")?.metadata?.modelLimits?.contextWindow??d?.limits?.contextWindow,W=S.useRef(null),F=g==="plan";S.useEffect(()=>{const Y=J=>{Ph(J)&&J.code==="KeyL"&&(J.preventDefault(),J.shiftKey&&_(g==="plan"?"default":"plan"),W.current?.focus())};return document.addEventListener("keydown",Y),()=>document.removeEventListener("keydown",Y)},[g,_]);const G=Eh(s),q=[...s].reverse().find(Y=>Y.role==="assistant"&&Y.metadata?.usage)?.metadata?.usage,H=q?.contextTokens??(q?.totalTokens??0)-(q?.reasoningTokens??0),ee=pa(_c),K=!i&&!!d&&!h&&!U_(L),U=i||n,te=Y=>{Y?.preventDefault(),i?(se("chat_message_stopped",{thread_id:l}),a()):n?(se("chat_message_stopped",{thread_id:l}),a()):K&&L&&(se("chat_message_sent",{thread_id:l,mode:g,model_id:d?.modelId??null,model_provider:d?.providerId??null,virtual_mcp_id:u?.id??null,submission:Y?"button_or_enter":"programmatic"}),ee(),o(L),P(void 0))};return C&&M?.created_by&&M.created_by!==C?r.jsxs("div",{className:"flex w-full items-center gap-2 px-3 py-2.5 rounded-xl border border-border bg-muted/40 text-muted-foreground",children:[r.jsx(Jh,{size:14,className:"shrink-0"}),r.jsx("span",{className:"text-sm",children:"Read only — you're viewing someone else's thread"})]}):r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"flex flex-col w-full justify-end",children:r.jsxs("div",{className:"relative rounded-2xl w-full flex flex-col",children:[e&&r.jsx("div",{className:"absolute inset-0 rounded-2xl pointer-events-none bg-muted/50"}),r.jsx(ho,{}),r.jsx(Hu,{tiptapDoc:L,setTiptapDoc:P,disabled:i||!d,enterToSubmit:!0,onSubmit:te,children:r.jsxs("form",{onSubmit:te,className:X("w-full relative rounded-2xl min-h-[110px] md:min-h-[130px] flex flex-col bg-background dark:bg-muted card-shadow"),children:[r.jsx(Av,{selectedModel:d}),r.jsx("div",{className:"group/input relative flex flex-col gap-2 flex-1",children:r.jsx(Wu,{ref:W,disabled:i||!d||I.status==="recording",virtualMcpId:u?.id??V,showFileUploader:!0,selectedModel:d})}),r.jsx("div",{className:"flex items-center justify-between p-2.5 gap-1",children:I.status==="recording"?r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"flex-1"}),r.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[r.jsx(Vv,{data:I.waveformData.slice(0,28)}),r.jsx("button",{type:"button",onClick:R,className:"flex items-center justify-center size-8 rounded-lg hover:bg-muted text-muted-foreground hover:text-foreground transition-colors","aria-label":"Cancel recording",children:r.jsx(fi,{size:16})}),r.jsx("button",{type:"button",onClick:E,className:"flex items-center justify-center size-8 rounded-lg bg-foreground text-background hover:opacity-80 transition-opacity","aria-label":"Use transcription",children:r.jsx(Jt,{size:16})})]})]}):r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"flex items-center gap-1.5 min-w-0 shrink-0",children:[r.jsx(Bx,{selectedModel:d,isStreaming:i,icon:r.jsx(Qt,{size:16})}),r.jsx(rv,{disabled:i,onOpenConnections:()=>{se("connections_dialog_opened",{source:"tools_popover",mode:"add"}),T(!0)},virtualMcpId:u?.id??V}),F&&r.jsxs("button",{type:"button",onClick:()=>{w(),se("chat_mode_changed",{from_mode:"plan",to_mode:"default",source:"pill_dismiss"}),_("default")},className:"flex items-center gap-1.5 h-8 rounded-lg px-2.5 text-sm font-medium text-violet-600 dark:text-violet-400 hover:bg-violet-500/10 group whitespace-nowrap animate-in fade-in duration-200",children:[r.jsx(Xh,{size:14,className:"shrink-0"}),"Plan mode",r.jsx(fi,{size:14,className:"shrink-0 hidden group-hover:block"})]}),g==="gen-image"&&m&&r.jsxs("button",{type:"button",onClick:()=>{w(),se("chat_mode_changed",{from_mode:"gen-image",to_mode:"default",source:"pill_dismiss"}),_("default")},className:"flex items-center gap-1.5 h-8 rounded-lg px-2.5 text-sm font-medium text-pink-600 dark:text-pink-400 hover:bg-pink-500/10 group whitespace-nowrap animate-in fade-in duration-200",children:[r.jsx(la,{size:14,className:"shrink-0"}),r.jsx("span",{className:"max-w-[120px] truncate",children:v?"Create image":m.title.includes(": ")?m.title.split(": ").slice(1).join(": "):m.title}),r.jsx(fi,{size:14,className:"shrink-0 hidden group-hover:block"})]}),g==="web-search"&&p&&r.jsxs("button",{type:"button",onClick:()=>{w(),se("chat_mode_changed",{from_mode:"web-search",to_mode:"default",source:"pill_dismiss"}),_("default")},className:"flex items-center gap-1.5 h-8 rounded-lg px-2.5 text-sm font-medium text-blue-600 dark:text-blue-400 hover:bg-blue-500/10 group whitespace-nowrap animate-in fade-in duration-200",children:[r.jsx(Ti,{size:14,className:"shrink-0"}),r.jsx("span",{className:"max-w-[120px] truncate",children:v?"Web search":p.title.includes(": ")?p.title.split(": ").slice(1).join(": "):p.title}),r.jsx(fi,{size:14,className:"shrink-0 hidden group-hover:block"})]}),$&&H>0&&r.jsx(Bp,{usage:G,totalTokens:H,contextWindow:$,onOpenContextPanel:t})]}),r.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[v?r.jsx(jv,{tier:x,onSelect:b}):r.jsx(su,{placeholder:"Model",variant:"borderless",className:"h-8 text-sm py-2 min-w-0"}),I.isSupported&&!i&&!n&&r.jsx(ne,{type:"button",onClick:N,variant:"ghost",size:"icon",className:X("size-8 rounded-lg transition-colors",I.status==="permission-denied"?"text-destructive hover:text-destructive hover:bg-destructive/10":"text-muted-foreground hover:text-foreground"),title:I.status==="permission-denied"?"Microphone access denied — click to try again":"Voice input",children:r.jsx(fg,{size:18})}),r.jsx(ne,{type:U?"button":"submit",onClick:Y=>{U&&(Y.preventDefault(),Y.stopPropagation(),a())},variant:K||U?"default":"ghost",size:"icon",disabled:!K&&!U,className:X("size-8 rounded-lg transition-all",!K&&!U&&"bg-muted text-muted-foreground hover:bg-muted hover:text-muted-foreground cursor-not-allowed"),title:i?"Stop generating":n?"Cancel run":"Send message (Enter)",children:U?r.jsx(mg,{size:20}):r.jsx(Fh,{size:20})})]})]})})]})},l),e&&r.jsx(vv,{onClick:()=>{se("connections_banner_clicked",{source:"home_chat_input"}),se("connections_dialog_opened",{source:"home_banner",mode:"add"}),T(!0)}})]})}),r.jsx(Pl,{mode:"browse",open:k,onOpenChange:T,defaultTab:"all"})]})}const Iv={usd:[{dollars:10,label:"Starter"},{dollars:20,label:"Popular"},{dollars:100,label:"Best value"}],brl:[{dollars:50,label:"Starter"},{dollars:100,label:"Popular"},{dollars:500,label:"Best value"}]};function Uu(t){return`deco-credits-empty-dismissed:${t}`}function Rv(t){try{return localStorage.getItem(Uu(t))==="1"}catch{return!1}}function Tv(){const t=B.c(49),{org:e}=be(),s=Ke(),{decoKeyId:i}=co();let n;t[0]!==e.id?(n={connectionId:Wt,orgId:e.id},t[0]=e.id,t[1]=n):n=t[1];const o=Me(n),[a,l]=S.useState(!0),[c,d]=S.useState(""),[u,h]=S.useState(!1),[f,m]=S.useState("usd"),p=f==="brl"?"R$":"$";let g;t[2]!==e.id?(g=()=>{se("credits_empty_state_dismissed",{organization_id:e.id}),l(!1);try{localStorage.setItem(Uu(e.id),"1")}catch{}},t[2]=e.id,t[3]=g):g=t[3];const _=g;let v,x;t[4]!==a||t[5]!==e.id?(v=()=>{a&&se("credits_empty_state_shown",{organization_id:e.id})},x=[a,e.id],t[4]=a,t[5]=e.id,t[6]=v,t[7]=x):(v=t[6],x=t[7]),S.useEffect(v,x);let b;t[8]!==o||t[9]!==f?(b=async $=>{const W=await o.callTool({name:"AI_PROVIDER_TOPUP_URL",arguments:{providerId:"deco",amountCents:$,currency:f}});if(W?.isError)throw new Error(W.content?.[0]?.text??"Failed to get top-up URL");return W.structuredContent?.url},t[8]=o,t[9]=f,t[10]=b):b=t[10];let y;t[11]!==_?(y=$=>{$&&window.open($,"_blank","noopener,noreferrer"),_()},t[11]=_,t[12]=y):y=t[12];let C;t[13]!==b||t[14]!==y?(C={mutationFn:b,onSuccess:y,onError:Mv},t[13]=b,t[14]=y,t[15]=C):C=t[15];const{mutate:j,isPending:V}=Br(C),w=parseFloat(c),k=!isNaN(w)&&w>=1;if(!a)return null;let T;t[16]!==_?(T=$=>!$&&_(),t[16]=_,t[17]=T):T=t[17];let I;t[18]===Symbol.for("react.memo_cache_sentinel")?(I=r.jsx("div",{className:"absolute inset-x-0 top-0 h-24 bg-gradient-to-b from-amber-500/8 to-transparent pointer-events-none rounded-t-lg"}),t[18]=I):I=t[18];let A;t[19]===Symbol.for("react.memo_cache_sentinel")?(A=r.jsx("div",{className:"flex items-center justify-center size-11 rounded-full bg-amber-100 dark:bg-amber-900/40 border border-amber-200/60 dark:border-amber-800/40 mx-auto",children:r.jsx(ml,{size:20,className:"text-amber-600 dark:text-amber-400"})}),t[19]=A):A=t[19];let N;t[20]===Symbol.for("react.memo_cache_sentinel")?(N=r.jsxs("div",{className:"relative px-6 pt-7 pb-5",children:[I,r.jsxs(Ds,{className:"relative gap-3",children:[A,r.jsxs("div",{className:"text-center",children:[r.jsx(Ts,{className:"text-lg font-semibold",children:"This workspace has no credits"}),r.jsx(dl,{className:"mt-2 text-[13px] leading-relaxed max-w-[320px] mx-auto",children:"Your free credits were used in another workspace. Add credits to use AI here."})]})]})]}),t[20]=N):N=t[20];let E;t[21]!==f||t[22]!==p||t[23]!==c||t[24]!==w||t[25]!==i||t[26]!==k||t[27]!==V||t[28]!==u||t[29]!==j?(E=i&&r.jsxs("div",{className:"px-6 pb-5",children:[r.jsx("div",{className:"mb-4",children:r.jsxs(eu,{type:"single",variant:"outline",size:"sm",value:f,onValueChange:$=>{$&&m($)},children:[r.jsx(Ln,{value:"usd",className:"h-8 px-3 text-xs",children:"USD"}),r.jsx(Ln,{value:"brl",className:"h-8 px-3 text-xs",children:"BRL"})]})}),r.jsx("div",{className:"grid grid-cols-3 gap-2.5",children:Iv[f].map($=>{const{dollars:W,label:F}=$;return r.jsxs("button",{type:"button",disabled:V,onClick:()=>{se("credits_topup_clicked",{amount_cents:W*100,currency:f,tier_label:F,source:"empty_state"}),j(W*100)},className:X("relative flex flex-col items-center gap-1 py-6 rounded-xl border transition-all duration-150 cursor-pointer","disabled:opacity-50 disabled:cursor-wait","border-border hover:border-foreground/20 hover:bg-muted/30"),children:[r.jsxs("span",{className:"text-2xl font-semibold tabular-nums text-foreground",children:[p,W]}),r.jsx("span",{className:"text-xs text-muted-foreground",children:F})]},W)})}),u?r.jsxs("div",{className:"flex gap-2 mt-3",children:[r.jsxs("div",{className:"relative flex-1",children:[r.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-sm text-muted-foreground select-none",children:p}),r.jsx(bt,{type:"number",min:"1",step:"1",placeholder:"50",value:c,onChange:$=>d($.target.value),className:"h-10 text-sm pl-7",autoFocus:!0})]}),r.jsx(ne,{className:"h-10",disabled:!k||V,onClick:()=>{se("credits_topup_clicked",{amount_cents:Math.round(w*100),currency:f,tier_label:"custom",source:"empty_state"}),j(Math.round(w*100))},children:V?"Opening...":"Add"})]}):r.jsx("button",{type:"button",className:"w-full mt-2.5 text-xs text-muted-foreground hover:text-foreground transition-colors py-1",onClick:()=>h(!0),children:"Enter custom amount"})]}),t[21]=f,t[22]=p,t[23]=c,t[24]=w,t[25]=i,t[26]=k,t[27]=V,t[28]=u,t[29]=j,t[30]=E):E=t[30];let R;t[31]!==_||t[32]!==s||t[33]!==e.slug?(R=()=>{s({to:"/$org/settings/ai-providers",params:{org:e.slug}}),_()},t[31]=_,t[32]=s,t[33]=e.slug,t[34]=R):R=t[34];let M;t[35]===Symbol.for("react.memo_cache_sentinel")?(M=r.jsx(ro,{size:12,className:"transition-transform duration-150 group-hover:translate-x-0.5"}),t[35]=M):M=t[35];let L;t[36]!==R?(L=r.jsxs("button",{type:"button",className:"group flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors",onClick:R,children:["Use your own provider",M]}),t[36]=R,t[37]=L):L=t[37];let D;t[38]!==_?(D=r.jsx(ne,{variant:"ghost",size:"sm",className:"text-xs text-muted-foreground",onClick:_,children:"Skip for now"}),t[38]=_,t[39]=D):D=t[39];let P;t[40]!==L||t[41]!==D?(P=r.jsxs("div",{className:"px-6 py-3.5 border-t border-border bg-muted/30 flex items-center justify-between",children:[L,D]}),t[40]=L,t[41]=D,t[42]=P):P=t[42];let O;t[43]!==E||t[44]!==P?(O=r.jsxs(ms,{className:"sm:max-w-[500px] gap-0 p-0 overflow-hidden",onOpenAutoFocus:Dv,children:[N,E,P]}),t[43]=E,t[44]=P,t[45]=O):O=t[45];let z;return t[46]!==O||t[47]!==T?(z=r.jsx(ps,{open:!0,onOpenChange:T,children:O}),t[46]=O,t[47]=T,t[48]=z):z=t[48],z}function Dv(t){return t.preventDefault()}function Mv(t){ge.error(`Top-up failed: ${t.message}`)}function Pv(t){const e=B.c(6),{balanceDollars:s}=t;let i;e[0]!==s?(i=s.toFixed(2),e[0]=s,e[1]=i):i=e[1];const n=i;let o,a;e[2]===Symbol.for("react.memo_cache_sentinel")?(o=X("inline-flex items-center gap-1.5 px-3 py-1 rounded-full","bg-emerald-50 dark:bg-emerald-950/30","border border-emerald-200/60 dark:border-emerald-800/40","animate-in fade-in-0 slide-in-from-bottom-2 duration-300"),a=r.jsx(ml,{size:13,className:"text-emerald-600 dark:text-emerald-400"}),e[2]=o,e[3]=a):(o=e[2],a=e[3]);let l;return e[4]!==n?(l=r.jsxs("div",{className:o,children:[a,r.jsxs("span",{className:"text-xs font-medium text-emerald-700 dark:text-emerald-300 tabular-nums",children:["$",n," in credits to get started"]})]}),e[4]=n,e[5]=l):l=e[5],l}function Lv(){const t=B.c(8),{org:e}=be(),s=Ke();let i;t[0]!==s||t[1]!==e.slug?(i=()=>s({to:"/$org/settings/ai-providers",params:{org:e.slug}}),t[0]=s,t[1]=e.slug,t[2]=i):i=t[2];let n,o,a;t[3]===Symbol.for("react.memo_cache_sentinel")?(n=X("inline-flex items-center gap-1.5 px-3 py-1 rounded-full cursor-pointer","bg-amber-50 dark:bg-amber-950/30","border border-amber-200/60 dark:border-amber-800/40","hover:bg-amber-100/60 dark:hover:bg-amber-900/30","transition-colors duration-150","animate-in fade-in-0 slide-in-from-bottom-2 duration-300"),o=r.jsx(ri,{size:13,className:"text-amber-600 dark:text-amber-400"}),a=r.jsx("span",{className:"text-xs font-medium text-amber-700 dark:text-amber-300",children:"No credits remaining · Add more"}),t[3]=n,t[4]=o,t[5]=a):(n=t[3],o=t[4],a=t[5]);let l;return t[6]!==i?(l=r.jsxs("button",{type:"button",onClick:i,className:n,children:[o,a]}),t[6]=i,t[7]=l):l=t[7],l}function Bv(t){const e=B.c(11),{className:s}=t;let i;e[0]!==s?(i=X("flex h-full w-full flex-col bg-background",s),e[0]=s,e[1]=i):i=e[1];let n;e[2]===Symbol.for("react.memo_cache_sentinel")?(n=r.jsx("div",{className:"size-6 rounded-lg bg-muted animate-pulse"}),e[2]=n):n=e[2];let o;e[3]===Symbol.for("react.memo_cache_sentinel")?(o=r.jsxs("div",{className:"flex items-center gap-3",children:[n,r.jsxs("div",{className:"flex flex-col gap-2",children:[r.jsx("div",{className:"h-3.5 w-28 rounded bg-muted animate-pulse"}),r.jsx("div",{className:"h-3 w-40 rounded bg-muted/60 animate-pulse"})]})]}),e[3]=o):o=e[3];let a;e[4]===Symbol.for("react.memo_cache_sentinel")?(a=r.jsx("div",{className:"flex items-center h-12 flex-none border-b border-border/80 px-4",children:r.jsxs("div",{className:"flex items-center justify-between gap-3 w-full",children:[o,r.jsxs("div",{className:"flex items-end gap-2",children:[r.jsx("div",{className:"h-6 w-6 rounded-full bg-muted animate-pulse"}),r.jsx("div",{className:"h-6 w-6 rounded-lg bg-muted animate-pulse"})]})]})}),e[4]=a):a=e[4];let l;e[5]===Symbol.for("react.memo_cache_sentinel")?(l=r.jsx("div",{className:"flex-1 overflow-hidden px-4 py-4",children:r.jsxs("div",{className:"mx-auto flex w-full max-w-2xl flex-col gap-4",children:[r.jsx(an,{align:"right",width:"w-3/4"}),r.jsx(an,{align:"left",width:"w-full",lines:3}),r.jsx(an,{align:"right",width:"w-2/3"}),r.jsx(an,{align:"left",width:"w-5/6",lines:2})]})}),e[5]=l):l=e[5];let c;e[6]===Symbol.for("react.memo_cache_sentinel")?(c=r.jsx("div",{className:"relative flex flex-1 flex-col gap-2 p-2.5",children:r.jsx("div",{className:"relative flex-1",children:r.jsxs("div",{className:"space-y-2 p-2",children:[r.jsx("div",{className:"h-3 w-full rounded bg-muted/40 animate-pulse"}),r.jsx("div",{className:"h-3 w-4/5 rounded bg-muted/40 animate-pulse"})]})})}),e[6]=c):c=e[6];let d;e[7]===Symbol.for("react.memo_cache_sentinel")?(d=r.jsx("div",{className:"flex items-center gap-1",children:r.jsx("div",{className:"size-8 rounded-full bg-muted/60 animate-pulse"})}),e[7]=d):d=e[7];let u;e[8]===Symbol.for("react.memo_cache_sentinel")?(u=r.jsx("div",{className:"px-4 py-4",children:r.jsx("div",{className:"mx-auto w-full max-w-2xl",children:r.jsxs("div",{className:"relative flex min-h-[130px] flex-col rounded-xl bg-background card-shadow",children:[c,r.jsxs("div",{className:"flex items-center justify-between px-2.5 pb-2.5",children:[d,r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsx("div",{className:"h-8 w-32 rounded-lg bg-muted/60 animate-pulse"}),r.jsx("div",{className:"size-8 rounded-full bg-muted animate-pulse"})]})]})]})})}),e[8]=u):u=e[8];let h;return e[9]!==i?(h=r.jsxs("div",{className:i,children:[a,l,u]}),e[9]=i,e[10]=h):h=e[10],h}function an(t){const e=B.c(22),{align:s,width:i,lines:n}=t,o=i===void 0?"w-full":i,a=n===void 0?1:n,l=s==="right"?"flex-row-reverse":"flex-row";let c;e[0]!==l?(c=X("flex w-full gap-4 px-4 py-2",l),e[0]=l,e[1]=c):c=e[1];const d=s==="right"?"ml-auto max-w-3/4 items-end":"w-full items-start";let u;e[2]!==d?(u=X("flex min-w-0 flex-col gap-2",d),e[2]=d,e[3]=u):u=e[3];let h;e[4]===Symbol.for("react.memo_cache_sentinel")?(h=r.jsx("div",{className:"h-3 w-16 rounded bg-muted/40 animate-pulse"}),e[4]=h):h=e[4];const f=s==="right"?"bg-muted":"bg-transparent border border-border/40";let m;e[5]!==f||e[6]!==o?(m=X("min-w-0 rounded-2xl p-4",f,o),e[5]=f,e[6]=o,e[7]=m):m=e[7];let p;e[8]!==a?(p=Array.from({length:a}),e[8]=a,e[9]=p):p=e[9];let g;e[10]!==a||e[11]!==p?(g=r.jsx("div",{className:"space-y-2",children:p.map((b,y)=>r.jsx("div",{className:X("h-3 rounded bg-muted-foreground/20 animate-pulse",y===a-1?"w-3/4":"w-full"),style:{animationDelay:`${y*.1}s`}},y))}),e[10]=a,e[11]=p,e[12]=g):g=e[12];let _;e[13]!==g||e[14]!==m?(_=r.jsx("div",{className:m,children:g}),e[13]=g,e[14]=m,e[15]=_):_=e[15];let v;e[16]!==_||e[17]!==u?(v=r.jsxs("div",{className:u,children:[h,_]}),e[16]=_,e[17]=u,e[18]=v):v=e[18];let x;return e[19]!==v||e[20]!==c?(x=r.jsx("div",{className:c,children:v}),e[19]=v,e[20]=c,e[21]=x):x=e[21],x}function Ov(t){const e=B.c(5),{className:s,children:i}=t;let n;e[0]!==s?(n=X("flex flex-col h-full w-full bg-background transform-[translateZ(0)]",s),e[0]=s,e[1]=n):n=e[1];let o;return e[2]!==i||e[3]!==n?(o=r.jsx("div",{className:n,children:i}),e[2]=i,e[3]=n,e[4]=o):o=e[4],o}function $v(t){const e=B.c(5),{children:s,className:i}=t;let n;e[0]!==i?(n=X("flex-1 min-h-0 overflow-y-auto isolate",i),e[0]=i,e[1]=n):n=e[1];let o;return e[2]!==s||e[3]!==n?(o=r.jsx("div",{className:n,children:s}),e[2]=s,e[3]=n,e[4]=o):o=e[4],o}function zv(t){const e=B.c(2),{children:s}=t;let i;return e[0]!==s?(i=r.jsx("div",{className:"h-full w-full flex items-center justify-center max-w-2xl mx-auto",children:s}),e[0]=s,e[1]=i):i=e[1],i}function Fv(){const t=B.c(16),{messages:e,status:s}=Ui(),i=Op(e);let n;t[0]!==i?(n=i.at(-1),t[0]=i,t[1]=n):n=t[1];const o=n,a=s==="submitted"||s==="streaming";let l;if(t[2]!==a||t[3]!==o||t[4]!==i||t[5]!==e||t[6]!==s){const c=e.at(-1),d=!a&&c?.role==="assistant"&&c.parts.filter(Uv).some(Wv),u=!a&&c?.role==="assistant"&&c.parts.some(Hv);let h;if(t[8]!==i||t[9]!==s){let m;t[11]!==i.length||t[12]!==s?(m=(p,g)=>r.jsx(dc,{pair:p,isLastPair:!1,status:g===i.length-1?s:void 0},`pair-${p.user.id}`),t[11]=i.length,t[12]=s,t[13]=m):m=t[13],h=i.slice(0,-1).map(m),t[8]=i,t[9]=s,t[10]=h}else h=t[10];let f;t[14]!==h?(f=r.jsx("div",{className:"flex flex-col min-w-0 max-w-2xl mx-auto w-full",children:h}),t[14]=h,t[15]=f):f=t[15],l=r.jsxs("div",{className:"w-full min-w-0 max-w-full overflow-y-auto h-full overflow-x-hidden",children:[f,o&&r.jsx("div",{className:X("min-h-full min-w-0 max-w-2xl mx-auto w-full",(d||u)&&"pb-60"),children:r.jsx(dc,{pair:o,isLastPair:!0,status:s},`pair-${o?.user.id}`)})]}),t[2]=a,t[3]=o,t[4]=i,t[5]=e,t[6]=s,t[7]=l}else l=t[7];return l}function Hv(t){return"state"in t&&t.state==="approval-requested"}function Wv(t){return t.state==="input-available"}function Uv(t){return t.type==="tool-user_ask"}function Kv(t){const e=B.c(5),{children:s,className:i}=t;let n;e[0]!==i?(n=X("flex-none w-full mx-auto p-2 pt-0","max-w-2xl min-w-0",i),e[0]=i,e[1]=n):n=e[1];let o;return e[2]!==s||e[3]!==n?(o=r.jsx("div",{className:n,children:s}),e[2]=s,e[3]=n,e[4]=o):o=e[4],o}const De=Object.assign(Ov,{Main:$v,Messages:Fv,EmptyState:zv,Footer:Kv,Input:Ev,Provider:Np,ActiveTaskProvider:kp,Skeleton:Bv,IceBreakers:ex,NoAiProviderEmptyState:$g,CreditsEmptyState:Tv,CreditsEyebrow:Pv,NoCreditsEyebrow:Lv,CreditsExhaustedBanner:Nu}),qv=`You are an image generator agent. Every request of the user is somewhat related to creating, editing or varying an image. You have access to image generation tools
4
+ ${R}`}]}})},t[12]=p,t[13]=h,t[14]=f,t[15]=m,t[16]=T):T=t[16];const I=T,A=Mx;let N;t[17]!==d?(N=(R,M,L)=>{d({id:R,approved:M,...L?{reason:L}:{}})},t[17]=d,t[18]=N):N=t[18];const E=N;if(g){let R;return t[19]!==k||t[20]!==a||t[21]!==x?(R=r.jsx("div",{className:"absolute bottom-full left-0 right-0",children:r.jsx(Nu,{userAskParts:x,isStreaming:a,onSubmit:k})}),t[19]=k,t[20]=a,t[21]=x,t[22]=R):R=t[22],R}if(_.length>0){let R;return t[23]!==I||t[24]!==a||t[25]!==_?(R=r.jsx("div",{className:"absolute bottom-full left-0 right-0",children:r.jsx(gx,{plans:_,isStreaming:a,onApprove:I,onDismiss:A})}),t[23]=I,t[24]=a,t[25]=_,t[26]=R):R=t[26],R}if(b.length>0||a&&l){let R;return t[27]!==E||t[28]!==a||t[29]!==b?(R=r.jsx("div",{className:"absolute bottom-full left-0 right-0",children:r.jsx(ux,{approvals:b,isStreaming:a,onRespond:E})}),t[27]=E,t[28]=a,t[29]=b,t[30]=R):R=t[30],R}if(!a&&e){if(Nx(e)){let M;return t[31]!==s?(M=r.jsx(Au,{onDismiss:s}),t[31]=s,t[32]=M):M=t[32],M}let R;return t[33]!==s||t[34]!==e||t[35]!==C?(R=r.jsx("div",{className:"absolute bottom-full left-0 right-0 bg-background",children:r.jsx($n,{variant:"error",error:e,onDismiss:s,onFixInChat:C})}),t[33]=s,t[34]=e,t[35]=C,t[36]=R):R=t[36],R}if(!a&&i&&i!=="stop"&&!l){let R;return t[37]!==n||t[38]!==i||t[39]!==V?(R=r.jsx("div",{className:"absolute bottom-full left-0 right-0 bg-background",children:r.jsx($n,{variant:"warning",finishReason:i,onDismiss:n,onContinue:V})}),t[37]=n,t[38]=i,t[39]=V,t[40]=R):R=t[40],R}return null}function Mx(){document.querySelector("[data-chat-input]")?.focus()}function Px(t){return t.state!=="output-available"}function Lx(t){return t.type==="tool-user_ask"}ho.Error=function(e){return r.jsx($n,{variant:"error",error:e.error,onDismiss:e.onDismiss,onFixInChat:e.onFixInChat})};ho.Warning=function(e){return r.jsx($n,{variant:"warning",finishReason:e.finishReason,onDismiss:e.onDismiss,onContinue:e.onContinue})};ho.UserAskQuestion=Nu;async function Tl(t,e,s,i){if(!no(e)){pe.error("Selected model does not support file uploads");return}const n=s.type||"application/octet-stream";if(!Fg(n,e)){const a=su(e),l=e?.title??"This model";pe.error(`"${s.name}" can't be attached`,{description:`${l} accepts ${a}. PowerPoint, Word, and Excel files aren't supported yet.`});return}const o=10*1024*1024;if(s.size>o){pe.error(`File "${s.name}" exceeds 10MB limit`);return}try{const a=new FileReader,l=new Promise((u,h)=>{a.onload=()=>{const f=a.result;if(typeof f!="string"){h(new Error("Failed to read file as data URL"));return}const m=f.includes(",")?f.split(",")[1]??f:f;u(m)},a.onerror=h});a.readAsDataURL(s);const c=await l,d={id:crypto.randomUUID(),name:s.name,mimeType:s.type||"application/octet-stream",size:s.size,data:c};Pp(t,{from:i,to:i},d)}catch(a){console.error("Failed to process file:",a),pe.error(`Failed to load file "${s.name}"`)}}function Bx(t){const e=B.c(7),{editor:s,selectedModel:i}=t,n=S.useRef($x);let o,a;e[0]!==s||e[1]!==i?(o=()=>{n.current=async(d,u)=>{await Tl(s,i,d,u)}},a=[s,i],e[0]=s,e[1]=i,e[2]=o,e[3]=a):(o=e[2],a=e[3]),S.useEffect(o,a);let l,c;return e[4]!==s?(l=()=>{if(s?.isDestroyed)return;const d=new na("fileDropHandler");s.state.plugins.find(f=>f.spec.key===d)&&s.unregisterPlugin(d);const h=new Zp({key:d,props:{handleDrop:(f,m,p,g)=>{if(g)return!1;const _=m.dataTransfer?.files;if(!_||_.length===0)return!1;m.preventDefault();const v=f.posAtCoords({left:m.clientX,top:m.clientY});if(!v)return!1;const x=Array.from(_),b=v.pos;for(const y of x)n.current?.(y,b);return!0},handlePaste:(f,m)=>{const p=m.clipboardData?.items;if(!p)return!1;const g=Array.from(p).filter(Ox);if(g.length===0)return!1;m.preventDefault();const{from:_}=f.state.selection;for(const v of g){const x=v.getAsFile();x&&n.current?.(x,_)}return!0}}});return s.registerPlugin(h),()=>{s?.isDestroyed||s.unregisterPlugin(d)}},c=[s],e[4]=s,e[5]=l,e[6]=c):(l=e[5],c=e[6]),S.useEffect(l,c),null}function Ox(t){return t.kind==="file"}function $x(){return Promise.resolve()}function zx(t){const e=B.c(23),{selectedModel:s,isStreaming:i,icon:n}=t,{editor:o}=to(),a=S.useRef(null);let l;e[0]!==s?(l=no(s),e[0]=s,e[1]=l):l=e[1];const c=l;let d;e[2]!==o||e[3]!==s?(d=async y=>{const C=y.target.files;if(!C||C.length===0||!o)return;const j=Array.from(C),{from:V}=o.state.selection,w=V;for(const k of j)await Tl(o,s,k,w);a.current&&(a.current.value="")},e[2]=o,e[3]=s,e[4]=d):d=e[4];const u=d;if(!o||!c)return null;let h;e[5]!==s?(h=zg(s),e[5]=s,e[6]=h):h=e[6];let f;e[7]!==u||e[8]!==i||e[9]!==h?(f=r.jsx("input",{ref:a,type:"file",multiple:!0,accept:h,className:"hidden",onChange:u,disabled:i}),e[7]=u,e[8]=i,e[9]=h,e[10]=f):f=e[10];const m=i||!c;let p;e[11]===Symbol.for("react.memo_cache_sentinel")?(p=()=>a.current?.click(),e[11]=p):p=e[11];let g;e[12]!==n?(g=n??r.jsx(fg,{size:16}),e[12]=n,e[13]=g):g=e[13];let _;e[14]!==m||e[15]!==g?(_=r.jsx(tt,{asChild:!0,children:r.jsx(ne,{type:"button",variant:"ghost",size:"icon",className:"text-muted-foreground/75",disabled:m,onClick:p,children:g})}),e[14]=m,e[15]=g,e[16]=_):_=e[16];let v;e[17]===Symbol.for("react.memo_cache_sentinel")?(v=r.jsx(st,{side:"top",children:"Add file"}),e[17]=v):v=e[17];let x;e[18]!==_?(x=r.jsxs(it,{children:[_,v]}),e[18]=_,e[19]=x):x=e[19];let b;return e[20]!==x||e[21]!==f?(b=r.jsxs(r.Fragment,{children:[f,x]}),e[20]=x,e[21]=f,e[22]=b):b=e[22],b}var Fx=eg;var Hx=["input:not([inert]):not([inert] *)","select:not([inert]):not([inert] *)","textarea:not([inert]):not([inert] *)","a[href]:not([inert]):not([inert] *)","button:not([inert]):not([inert] *)","[tabindex]:not(slot):not([inert]):not([inert] *)","audio[controls]:not([inert]):not([inert] *)","video[controls]:not([inert]):not([inert] *)",'[contenteditable]:not([contenteditable="false"]):not([inert]):not([inert] *)',"details>summary:first-of-type:not([inert]):not([inert] *)","details:not([inert]):not([inert] *)"],ua=Hx.join(","),Eu=typeof Element>"u",Nr=Eu?function(){}:Element.prototype.matches||Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector,zn=!Eu&&Element.prototype.getRootNode?function(t){var e;return t==null||(e=t.getRootNode)===null||e===void 0?void 0:e.call(t)}:function(t){return t?.ownerDocument},Fn=function(e,s){var i;s===void 0&&(s=!0);var n=e==null||(i=e.getAttribute)===null||i===void 0?void 0:i.call(e,"inert"),o=n===""||n==="true",a=o||s&&e&&(typeof e.closest=="function"?e.closest("[inert]"):Fn(e.parentNode));return a},Wx=function(e){var s,i=e==null||(s=e.getAttribute)===null||s===void 0?void 0:s.call(e,"contenteditable");return i===""||i==="true"},Ux=function(e,s,i){if(Fn(e))return[];var n=Array.prototype.slice.apply(e.querySelectorAll(ua));return s&&Nr.call(e,ua)&&n.unshift(e),n=n.filter(i),n},fa=function(e,s,i){for(var n=[],o=Array.from(e);o.length;){var a=o.shift();if(!Fn(a,!1))if(a.tagName==="SLOT"){var l=a.assignedElements(),c=l.length?l:a.children,d=fa(c,!0,i);i.flatten?n.push.apply(n,d):n.push({scopeParent:a,candidates:d})}else{var u=Nr.call(a,ua);u&&i.filter(a)&&(s||!e.includes(a))&&n.push(a);var h=a.shadowRoot||typeof i.getShadowRoot=="function"&&i.getShadowRoot(a),f=!Fn(h,!1)&&(!i.shadowRootFilter||i.shadowRootFilter(a));if(h&&f){var m=fa(h===!0?a.children:h.children,!0,i);i.flatten?n.push.apply(n,m):n.push({scopeParent:a,candidates:m})}else o.unshift.apply(o,a.children)}}return n},Iu=function(e){return!isNaN(parseInt(e.getAttribute("tabindex"),10))},Ru=function(e){if(!e)throw new Error("No node provided");return e.tabIndex<0&&(/^(AUDIO|VIDEO|DETAILS)$/.test(e.tagName)||Wx(e))&&!Iu(e)?0:e.tabIndex},Kx=function(e,s){var i=Ru(e);return i<0&&s&&!Iu(e)?0:i},qx=function(e,s){return e.tabIndex===s.tabIndex?e.documentOrder-s.documentOrder:e.tabIndex-s.tabIndex},Tu=function(e){return e.tagName==="INPUT"},Gx=function(e){return Tu(e)&&e.type==="hidden"},Yx=function(e){var s=e.tagName==="DETAILS"&&Array.prototype.slice.apply(e.children).some(function(i){return i.tagName==="SUMMARY"});return s},Xx=function(e,s){for(var i=0;i<e.length;i++)if(e[i].checked&&e[i].form===s)return e[i]},Jx=function(e){if(!e.name)return!0;var s=e.form||zn(e),i=function(l){return s.querySelectorAll('input[type="radio"][name="'+l+'"]')},n;if(typeof window<"u"&&typeof window.CSS<"u"&&typeof window.CSS.escape=="function")n=i(window.CSS.escape(e.name));else try{n=i(e.name)}catch(a){return console.error("Looks like you have a radio button with a name attribute containing invalid CSS selector characters and need the CSS.escape polyfill: %s",a.message),!1}var o=Xx(n,e.form);return!o||o===e},Qx=function(e){return Tu(e)&&e.type==="radio"},Zx=function(e){return Qx(e)&&!Jx(e)},e1=function(e){var s,i=e&&zn(e),n=(s=i)===null||s===void 0?void 0:s.host,o=!1;if(i&&i!==e){var a,l,c;for(o=!!((a=n)!==null&&a!==void 0&&(l=a.ownerDocument)!==null&&l!==void 0&&l.contains(n)||e!=null&&(c=e.ownerDocument)!==null&&c!==void 0&&c.contains(e));!o&&n;){var d,u,h;i=zn(n),n=(d=i)===null||d===void 0?void 0:d.host,o=!!((u=n)!==null&&u!==void 0&&(h=u.ownerDocument)!==null&&h!==void 0&&h.contains(n))}}return o},Ic=function(e){var s=e.getBoundingClientRect(),i=s.width,n=s.height;return i===0&&n===0},t1=function(e,s){var i=s.displayCheck,n=s.getShadowRoot;if(i==="full-native"&&"checkVisibility"in e){var o=e.checkVisibility({checkOpacity:!1,opacityProperty:!1,contentVisibilityAuto:!0,visibilityProperty:!0,checkVisibilityCSS:!0});return!o}if(getComputedStyle(e).visibility==="hidden")return!0;var a=Nr.call(e,"details>summary:first-of-type"),l=a?e.parentElement:e;if(Nr.call(l,"details:not([open]) *"))return!0;if(!i||i==="full"||i==="full-native"||i==="legacy-full"){if(typeof n=="function"){for(var c=e;e;){var d=e.parentElement,u=zn(e);if(d&&!d.shadowRoot&&n(d)===!0)return Ic(e);e.assignedSlot?e=e.assignedSlot:!d&&u!==e.ownerDocument?e=u.host:e=d}e=c}if(e1(e))return!e.getClientRects().length;if(i!=="legacy-full")return!0}else if(i==="non-zero-area")return Ic(e);return!1},s1=function(e){if(/^(INPUT|BUTTON|SELECT|TEXTAREA)$/.test(e.tagName))for(var s=e.parentElement;s;){if(s.tagName==="FIELDSET"&&s.disabled){for(var i=0;i<s.children.length;i++){var n=s.children.item(i);if(n.tagName==="LEGEND")return Nr.call(s,"fieldset[disabled] *")?!0:!n.contains(e)}return!0}s=s.parentElement}return!1},i1=function(e,s){return!(s.disabled||Gx(s)||t1(s,e)||Yx(s)||s1(s))},Rc=function(e,s){return!(Zx(s)||Ru(s)<0||!i1(e,s))},r1=function(e){var s=parseInt(e.getAttribute("tabindex"),10);return!!(isNaN(s)||s>=0)},Du=function(e){var s=[],i=[];return e.forEach(function(n,o){var a=!!n.scopeParent,l=a?n.scopeParent:n,c=Kx(l,a),d=a?Du(n.candidates):l;c===0?a?s.push.apply(s,d):s.push(l):i.push({documentOrder:o,tabIndex:c,item:n,isScope:a,content:d})}),i.sort(qx).reduce(function(n,o){return o.isScope?n.push.apply(n,o.content):n.push(o.content),n},[]).concat(s)},Mu=function(e,s){s=s||{};var i;return s.getShadowRoot?i=fa([e],s.includeContainer,{filter:Rc.bind(null,s),flatten:!1,getShadowRoot:s.getShadowRoot,shadowRootFilter:r1}):i=Ux(e,s.includeContainer,Rc.bind(null,s)),Du(i)};function n1(){return/apple/i.test(navigator.vendor)}const Tc="data-floating-ui-focusable";function o1(t){let e=t.activeElement;for(;((s=e)==null||(s=s.shadowRoot)==null?void 0:s.activeElement)!=null;){var s;e=e.shadowRoot.activeElement}return e}function ma(t,e){if(!t||!e)return!1;const s=e.getRootNode==null?void 0:e.getRootNode();if(t.contains(e))return!0;if(s&&Fm(s)){let i=e;for(;i;){if(t===i)return!0;i=i.parentNode||i.host}}return!1}function er(t){return"composedPath"in t?t.composedPath()[0]:t.target}function No(t,e){if(e==null)return!1;if("composedPath"in t)return t.composedPath().includes(e);const s=t;return s.target!=null&&e.contains(s.target)}function a1(t){return t.matches("html,body")}function Ar(t){return t?.ownerDocument||document}function l1(t){return t?t.hasAttribute(Tc)?t:t.querySelector("["+Tc+"]")||t:null}function jn(t,e,s){return s===void 0&&(s=!0),t.filter(n=>{var o;return n.parentId===e&&(!s||((o=n.context)==null?void 0:o.open))}).flatMap(n=>[n,...jn(t,n.id,s)])}function c1(t){return"nativeEvent"in t}var d1=typeof document<"u",h1=function(){},pi=d1?S.useLayoutEffect:h1;const u1={...Sh},f1=u1.useInsertionEffect,m1=f1||(t=>t());function Ei(t){const e=S.useRef(()=>{});return m1(()=>{e.current=t}),S.useCallback(function(){for(var s=arguments.length,i=new Array(s),n=0;n<s;n++)i[n]=arguments[n];return e.current==null?void 0:e.current(...i)},[])}const Pu=()=>({getShadowRoot:!0,displayCheck:typeof ResizeObserver=="function"&&ResizeObserver.toString().includes("[native code]")?"full":"none"});function Lu(t,e){const s=Mu(t,Pu()),i=s.length;if(i===0)return;const n=o1(Ar(t)),o=s.indexOf(n),a=o===-1?e===1?0:i-1:o+e;return s[a]}function p1(t){return Lu(Ar(t).body,1)||t}function g1(t){return Lu(Ar(t).body,-1)||t}function Ao(t,e){const s=e||t.currentTarget,i=t.relatedTarget;return!i||!ma(s,i)}function _1(t){Mu(t,Pu()).forEach(s=>{s.dataset.tabindex=s.getAttribute("tabindex")||"",s.setAttribute("tabindex","-1")})}function Dc(t){t.querySelectorAll("[data-tabindex]").forEach(s=>{const i=s.dataset.tabindex;delete s.dataset.tabindex,i?s.setAttribute("tabindex",i):s.removeAttribute("tabindex")})}const x1="data-floating-ui-focusable",Mc="active",Pc="selected",v1={...Sh};let Lc=!1,b1=0;const Bc=()=>"floating-ui-"+Math.random().toString(36).slice(2,6)+b1++;function y1(){const[t,e]=S.useState(()=>Lc?Bc():void 0);return pi(()=>{t==null&&e(Bc())},[]),S.useEffect(()=>{Lc=!0},[]),t}const S1=v1.useId,Dl=S1||y1;function w1(){const t=new Map;return{emit(e,s){var i;(i=t.get(e))==null||i.forEach(n=>n(s))},on(e,s){t.has(e)||t.set(e,new Set),t.get(e).add(s)},off(e,s){var i;(i=t.get(e))==null||i.delete(s)}}}const V1=S.createContext(null),C1=S.createContext(null),Bu=()=>{var t;return((t=S.useContext(V1))==null?void 0:t.id)||null},Ou=()=>S.useContext(C1);function Ml(t){return"data-floating-ui-"+t}const j1={border:0,clip:"rect(0 0 0 0)",height:"1px",margin:"-1px",overflow:"hidden",padding:0,position:"fixed",whiteSpace:"nowrap",width:"1px",top:0,left:0},Oc=S.forwardRef(function(e,s){const[i,n]=S.useState();pi(()=>{n1()&&n("button")},[]);const o={ref:s,tabIndex:0,role:i,"aria-hidden":i?void 0:!0,[Ml("focus-guard")]:"",style:j1};return r.jsx("span",{...e,...o})}),k1={clipPath:"inset(50%)",position:"fixed",top:0,left:0},$u=S.createContext(null),$c=Ml("portal");function N1(t){t===void 0&&(t={});const{id:e,root:s}=t,i=Dl(),n=E1(),[o,a]=S.useState(null),l=S.useRef(null);return pi(()=>()=>{o?.remove(),queueMicrotask(()=>{l.current=null})},[o]),pi(()=>{if(!i||l.current)return;const c=e?document.getElementById(e):null;if(!c)return;const d=document.createElement("div");d.id=i,d.setAttribute($c,""),c.appendChild(d),l.current=d,a(d)},[e,i]),pi(()=>{if(s===null||!i||l.current)return;let c=s||n?.portalNode;c&&!Gm(c)&&(c=c.current),c=c||document.body;let d=null;e&&(d=document.createElement("div"),d.id=e,c.appendChild(d));const u=document.createElement("div");u.id=i,u.setAttribute($c,""),c=d||c,c.appendChild(u),l.current=u,a(u)},[e,s,i,n]),o}function A1(t){const{children:e,id:s,root:i,preserveTabOrder:n=!0}=t,o=N1({id:s,root:i}),[a,l]=S.useState(null),c=S.useRef(null),d=S.useRef(null),u=S.useRef(null),h=S.useRef(null),f=a?.modal,m=a?.open,p=!!a&&!a.modal&&a.open&&n&&!!(i||o);return S.useEffect(()=>{if(!o||!n||f)return;function g(_){o&&Ao(_)&&(_.type==="focusin"?Dc:_1)(o)}return o.addEventListener("focusin",g,!0),o.addEventListener("focusout",g,!0),()=>{o.removeEventListener("focusin",g,!0),o.removeEventListener("focusout",g,!0)}},[o,n,f]),S.useEffect(()=>{o&&(m||Dc(o))},[m,o]),r.jsxs($u.Provider,{value:S.useMemo(()=>({preserveTabOrder:n,beforeOutsideRef:c,afterOutsideRef:d,beforeInsideRef:u,afterInsideRef:h,portalNode:o,setFocusManagerState:l}),[n,o]),children:[p&&o&&r.jsx(Oc,{"data-type":"outside",ref:c,onFocus:g=>{if(Ao(g,o)){var _;(_=u.current)==null||_.focus()}else{const v=a?a.domReference:null,x=g1(v);x?.focus()}}}),p&&o&&r.jsx("span",{"aria-owns":o.id,style:k1}),o&&ds.createPortal(e,o),p&&o&&r.jsx(Oc,{"data-type":"outside",ref:d,onFocus:g=>{if(Ao(g,o)){var _;(_=h.current)==null||_.focus()}else{const v=a?a.domReference:null,x=p1(v);x?.focus(),a?.closeOnFocusOut&&a?.onOpenChange(!1,g.nativeEvent,"focus-out")}}})]})}const E1=()=>S.useContext($u),I1={pointerdown:"onPointerDown",mousedown:"onMouseDown",click:"onClick"},R1={pointerdown:"onPointerDownCapture",mousedown:"onMouseDownCapture",click:"onClickCapture"},zc=t=>{var e,s;return{escapeKey:typeof t=="boolean"?t:(e=t?.escapeKey)!=null?e:!1,outsidePress:typeof t=="boolean"?t:(s=t?.outsidePress)!=null?s:!0}};function T1(t,e){e===void 0&&(e={});const{open:s,onOpenChange:i,elements:n,dataRef:o}=t,{enabled:a=!0,escapeKey:l=!0,outsidePress:c=!0,outsidePressEvent:d="pointerdown",referencePress:u=!1,referencePressEvent:h="pointerdown",ancestorScroll:f=!1,bubbles:m,capture:p}=e,g=Ou(),_=Ei(typeof c=="function"?c:()=>!1),v=typeof c=="function"?_:c,x=S.useRef(!1),{escapeKey:b,outsidePress:y}=zc(m),{escapeKey:C,outsidePress:j}=zc(p),V=S.useRef(!1),w=Ei(E=>{var R;if(!s||!a||!l||E.key!=="Escape"||V.current)return;const M=(R=o.current.floatingContext)==null?void 0:R.nodeId,L=g?jn(g.nodesRef.current,M):[];if(!b&&(E.stopPropagation(),L.length>0)){let D=!0;if(L.forEach(P=>{var O;if((O=P.context)!=null&&O.open&&!P.context.dataRef.current.__escapeKeyBubbles){D=!1;return}}),!D)return}i(!1,c1(E)?E.nativeEvent:E,"escape-key")}),k=Ei(E=>{var R;const M=()=>{var L;w(E),(L=er(E))==null||L.removeEventListener("keydown",M)};(R=er(E))==null||R.addEventListener("keydown",M)}),T=Ei(E=>{var R;const M=o.current.insideReactTree;o.current.insideReactTree=!1;const L=x.current;if(x.current=!1,d==="click"&&L||M||typeof v=="function"&&!v(E))return;const D=er(E),P="["+Ml("inert")+"]",O=Ar(n.floating).querySelectorAll(P);let z=ys(D)?D:null;for(;z&&!wo(z);){const G=Um(z);if(wo(G)||!ys(G))break;z=G}if(O.length&&ys(D)&&!a1(D)&&!ma(D,n.floating)&&Array.from(O).every(G=>!ma(z,G)))return;if(Km(D)&&N){const G=wo(D),q=qm(D),H=/auto|scroll/,ee=G||H.test(q.overflowX),K=G||H.test(q.overflowY),U=ee&&D.clientWidth>0&&D.scrollWidth>D.clientWidth,te=K&&D.clientHeight>0&&D.scrollHeight>D.clientHeight,Y=q.direction==="rtl",J=te&&(Y?E.offsetX<=D.offsetWidth-D.clientWidth:E.offsetX>D.clientWidth),ie=U&&E.offsetY>D.clientHeight;if(J||ie)return}const $=(R=o.current.floatingContext)==null?void 0:R.nodeId,W=g&&jn(g.nodesRef.current,$).some(G=>{var q;return No(E,(q=G.context)==null?void 0:q.elements.floating)});if(No(E,n.floating)||No(E,n.domReference)||W)return;const F=g?jn(g.nodesRef.current,$):[];if(F.length>0){let G=!0;if(F.forEach(q=>{var H;if((H=q.context)!=null&&H.open&&!q.context.dataRef.current.__outsidePressBubbles){G=!1;return}}),!G)return}i(!1,E,"outside-press")}),I=Ei(E=>{var R;const M=()=>{var L;T(E),(L=er(E))==null||L.removeEventListener(d,M)};(R=er(E))==null||R.addEventListener(d,M)});S.useEffect(()=>{if(!s||!a)return;o.current.__escapeKeyBubbles=b,o.current.__outsidePressBubbles=y;let E=-1;function R(O){i(!1,O,"ancestor-scroll")}function M(){window.clearTimeout(E),V.current=!0}function L(){E=window.setTimeout(()=>{V.current=!1},Wm()?5:0)}const D=Ar(n.floating);l&&(D.addEventListener("keydown",C?k:w,C),D.addEventListener("compositionstart",M),D.addEventListener("compositionend",L)),v&&D.addEventListener(d,j?I:T,j);let P=[];return f&&(ys(n.domReference)&&(P=So(n.domReference)),ys(n.floating)&&(P=P.concat(So(n.floating))),!ys(n.reference)&&n.reference&&n.reference.contextElement&&(P=P.concat(So(n.reference.contextElement)))),P=P.filter(O=>{var z;return O!==((z=D.defaultView)==null?void 0:z.visualViewport)}),P.forEach(O=>{O.addEventListener("scroll",R,{passive:!0})}),()=>{l&&(D.removeEventListener("keydown",C?k:w,C),D.removeEventListener("compositionstart",M),D.removeEventListener("compositionend",L)),v&&D.removeEventListener(d,j?I:T,j),P.forEach(O=>{O.removeEventListener("scroll",R)}),window.clearTimeout(E)}},[o,n,l,v,d,s,i,f,a,b,y,w,C,k,T,j,I]),S.useEffect(()=>{o.current.insideReactTree=!1},[o,v,d]);const A=S.useMemo(()=>({onKeyDown:w,...u&&{[I1[h]]:E=>{i(!1,E.nativeEvent,"reference-press")},...h!=="click"&&{onClick(E){i(!1,E.nativeEvent,"reference-press")}}}}),[w,i,u,h]),N=S.useMemo(()=>{function E(R){R.button===0&&(x.current=!0)}return{onKeyDown:w,onMouseDown:E,onMouseUp:E,[R1[d]]:()=>{o.current.insideReactTree=!0}}},[w,d,o]);return S.useMemo(()=>a?{reference:A,floating:N}:{},[a,A,N])}function D1(t){const{open:e=!1,onOpenChange:s,elements:i}=t,n=Dl(),o=S.useRef({}),[a]=S.useState(()=>w1()),l=Bu()!=null,[c,d]=S.useState(i.reference),u=Ei((m,p,g)=>{o.current.openEvent=m?p:void 0,a.emit("openchange",{open:m,event:p,reason:g,nested:l}),s?.(m,p,g)}),h=S.useMemo(()=>({setPositionReference:d}),[]),f=S.useMemo(()=>({reference:c||i.reference||null,floating:i.floating||null,domReference:i.reference}),[c,i.reference,i.floating]);return S.useMemo(()=>({dataRef:o,open:e,onOpenChange:u,elements:f,events:a,floatingId:n,refs:h}),[e,u,f,a,n,h])}function M1(t){t===void 0&&(t={});const{nodeId:e}=t,s=D1({...t,elements:{reference:null,floating:null,...t.elements}}),i=t.rootContext||s,n=i.elements,[o,a]=S.useState(null),[l,c]=S.useState(null),u=n?.domReference||o,h=S.useRef(null),f=Ou();pi(()=>{u&&(h.current=u)},[u]);const m=Hm({...t,elements:{...n,...l&&{reference:l}}}),p=S.useCallback(b=>{const y=ys(b)?{getBoundingClientRect:()=>b.getBoundingClientRect(),getClientRects:()=>b.getClientRects(),contextElement:b}:b;c(y),m.refs.setReference(y)},[m.refs]),g=S.useCallback(b=>{(ys(b)||b===null)&&(h.current=b,a(b)),(ys(m.refs.reference.current)||m.refs.reference.current===null||b!==null&&!ys(b))&&m.refs.setReference(b)},[m.refs]),_=S.useMemo(()=>({...m.refs,setReference:g,setPositionReference:p,domReference:h}),[m.refs,g,p]),v=S.useMemo(()=>({...m.elements,domReference:u}),[m.elements,u]),x=S.useMemo(()=>({...m,...i,refs:_,elements:v,nodeId:e}),[m,_,v,e,i]);return pi(()=>{i.dataRef.current.floatingContext=x;const b=f?.nodesRef.current.find(y=>y.id===e);b&&(b.context=x)}),S.useMemo(()=>({...m,context:x,refs:_,elements:v}),[m,_,v,x])}function Eo(t,e,s){const i=new Map,n=s==="item";let o=t;if(n&&t){const{[Mc]:a,[Pc]:l,...c}=t;o=c}return{...s==="floating"&&{tabIndex:-1,[x1]:""},...o,...e.map(a=>{const l=a?a[s]:null;return typeof l=="function"?t?l(t):null:l}).concat(t).reduce((a,l)=>(l&&Object.entries(l).forEach(c=>{let[d,u]=c;if(!(n&&[Mc,Pc].includes(d)))if(d.indexOf("on")===0){if(i.has(d)||i.set(d,[]),typeof u=="function"){var h;(h=i.get(d))==null||h.push(u),a[d]=function(){for(var f,m=arguments.length,p=new Array(m),g=0;g<m;g++)p[g]=arguments[g];return(f=i.get(d))==null?void 0:f.map(_=>_(...p)).find(_=>_!==void 0)}}}else a[d]=u}),a),{})}}function P1(t){t===void 0&&(t=[]);const e=t.map(l=>l?.reference),s=t.map(l=>l?.floating),i=t.map(l=>l?.item),n=S.useCallback(l=>Eo(l,t,"reference"),e),o=S.useCallback(l=>Eo(l,t,"floating"),s),a=S.useCallback(l=>Eo(l,t,"item"),i);return S.useMemo(()=>({getReferenceProps:n,getFloatingProps:o,getItemProps:a}),[n,o,a])}const L1=new Map([["select","listbox"],["combobox","listbox"],["label",!1]]);function B1(t,e){var s,i;e===void 0&&(e={});const{open:n,elements:o,floatingId:a}=t,{enabled:l=!0,role:c="dialog"}=e,d=Dl(),u=((s=o.domReference)==null?void 0:s.id)||d,h=S.useMemo(()=>{var x;return((x=l1(o.floating))==null?void 0:x.id)||a},[o.floating,a]),f=(i=L1.get(c))!=null?i:c,p=Bu()!=null,g=S.useMemo(()=>f==="tooltip"||c==="label"?{["aria-"+(c==="label"?"labelledby":"describedby")]:n?h:void 0}:{"aria-expanded":n?"true":"false","aria-haspopup":f==="alertdialog"?"dialog":f,"aria-controls":n?h:void 0,...f==="listbox"&&{role:"combobox"},...f==="menu"&&{id:u},...f==="menu"&&p&&{role:"menuitem"},...c==="select"&&{"aria-autocomplete":"none"},...c==="combobox"&&{"aria-autocomplete":"list"}},[f,h,p,n,u,c]),_=S.useMemo(()=>{const x={id:h,...f&&{role:f}};return f==="tooltip"||c==="label"?x:{...x,...f==="menu"&&{"aria-labelledby":u}}},[f,h,u,c]),v=S.useCallback(x=>{let{active:b,selected:y}=x;const C={role:"option",...b&&{id:h+"-fui-option"}};switch(c){case"select":case"combobox":return{...C,"aria-selected":y}}return{}},[h,c]);return S.useMemo(()=>l?{reference:g,floating:_,item:v}:{},[l,g,_,v])}function O1(t){const e=B.c(26),{editor:s,query:i,items:n,onSelect:o,onClose:a}=t,[l,c]=S.useState(0),d=S.useRef(n),u=S.useRef(l),h=S.useRef(o),f=S.useRef(a),m=S.useDeferredValue(i);let p;e[0]===Symbol.for("react.memo_cache_sentinel")?(p=()=>{c(0)},e[0]=p):p=e[0];let g;e[1]!==m?(g=[m],e[1]=m,e[2]=g):g=e[2],S.useEffect(p,g);let _,v;e[3]!==n.length||e[4]!==l?(_=()=>{l>=n.length&&n.length>0&&c(0)},v=[n.length,l],e[3]=n.length,e[4]=l,e[5]=_,e[6]=v):(_=e[5],v=e[6]),S.useEffect(_,v);let x,b;e[7]!==n?(x=()=>{d.current=n},b=[n],e[7]=n,e[8]=x,e[9]=b):(x=e[8],b=e[9]),S.useEffect(x,b);let y,C;e[10]!==l?(y=()=>{u.current=l},C=[l],e[10]=l,e[11]=y,e[12]=C):(y=e[11],C=e[12]),S.useEffect(y,C);let j,V;e[13]!==o?(V=()=>{h.current=o},j=[o],e[13]=o,e[14]=j,e[15]=V):(j=e[14],V=e[15]),S.useEffect(V,j);let w,k;e[16]!==a?(w=()=>{f.current=a},k=[a],e[16]=a,e[17]=w,e[18]=k):(w=e[17],k=e[18]),S.useEffect(w,k);let T;e[19]!==s.isDestroyed||e[20]!==s.view.dom?(T=()=>{const E=s.view.dom;if(s?.isDestroyed||!E)return;const R=L=>{const D=d.current;if(!D.length)return!1;const P=()=>c(z=>(z+1)%D.length),O=()=>c(z=>(z-1+D.length)%D.length);switch(L.key){case"ArrowUp":return L.preventDefault(),O(),!0;case"ArrowDown":return L.preventDefault(),P(),!0;case"Tab":return L.preventDefault(),L.shiftKey?O():P(),!0;case"Home":return L.preventDefault(),c(0),!0;case"End":return L.preventDefault(),c(D.length-1),!0;case"Enter":{if(L.isComposing)return!1;L.preventDefault();const z=u.current;return z!==-1&&D[z]&&h.current?.(D[z],z),!0}case"Escape":return L.preventDefault(),f.current?.(),!0;default:return!1}},M=L=>{R(L)};return E.addEventListener("keydown",M,!0),()=>{E?.removeEventListener("keydown",M,!0)}},e[19]=s.isDestroyed,e[20]=s.view.dom,e[21]=T):T=e[21];let I;e[22]!==s?(I=[s],e[22]=s,e[23]=I):I=e[23],S.useEffect(T,I);const A=n.length?l:void 0;let N;return e[24]!==A?(N={selectedIndex:A,setSelectedIndex:c},e[24]=A,e[25]=N):N=e[25],N}function $1(t,e){switch(e.type){case"SET_SELECTED_ITEM":return{...t,selectedItem:e.payload};case"ON_START":return{...t,open:!0,selectedItem:null,element:e.payload.element,query:e.payload.query,range:e.payload.range};case"ON_UPDATE":return{...t,element:e.payload.element,query:e.payload.query,range:e.payload.range};case"ON_EXIT":return{open:!1,element:null,query:"",range:null,selectedItem:null};default:return t}}const zu=S.createContext(void 0);function Fu(){const t=S.useContext(zu);if(!t)throw new Error("useSuggestionContext must be used within a SuggestionContext.Provider");return t}function z1({editor:t,char:e,pluginKey:s,allow:i,onOpenChange:n}){const[o,a]=S.useReducer($1,{open:!1,element:null,query:"",range:null,selectedItem:null}),l=S.useRef(n);return l.current=n,S.useEffect(()=>{if(t?.isDestroyed)return;const c=s instanceof na?s:new na(s);t.state.plugins.find(h=>h.spec.key===c)&&t.unregisterPlugin(c);const u=Wg({pluginKey:c,editor:t,char:e,allow(h){const f=t.state.doc.resolve(h.range.from);for(let m=f.depth;m>0;m--)if(f.node(m).type.name==="image")return!1;return!(i&&!i(h))},command(){},render:()=>({onStart:h=>{a({type:"ON_START",payload:{element:h.decorationNode??null,query:h.query,range:h.range}}),l.current?.(!0)},onUpdate:h=>{a({type:"ON_UPDATE",payload:{element:h.decorationNode??null,query:h.query,range:h.range}})},onKeyDown:h=>h.event.key==="Escape"?(a({type:"ON_EXIT"}),!0):!1,onExit:()=>{a({type:"ON_EXIT"}),l.current?.(!1)}}),items:()=>[]});return t.registerPlugin(u),()=>{t?.isDestroyed||t.unregisterPlugin(c)}},[t,s,e,a,i]),{state:o,dispatch:a}}function F1({editor:t,queryKey:e,queryFn:s,onSelect:i}){const{state:n,dispatch:o}=Fu(),a=S.useDeferredValue(n.query),{data:l}=wh({queryKey:lt.suggestionItems(e,n.open,a),queryFn:()=>n.open?s({query:a}):[]}),c=()=>{o({type:"ON_EXIT"})},d=async(h,f)=>{if(!(n.selectedItem!==null||!n.range)){o({type:"SET_SELECTED_ITEM",payload:h});try{const{view:m}=t,g=m.state.selection.$to.nodeAfter?.text?.startsWith(" "),_=n.range?{...n.range}:{from:0,to:0};g&&n.range&&(_.to+=1),await i({range:_,item:h})===!1?o({type:"SET_SELECTED_ITEM",payload:null}):c()}catch{c()}}},{selectedIndex:u}=O1({editor:t,query:a,items:l,onSelect:d,onClose:c});return{selectedItem:n.selectedItem,items:l,selectedIndex:u,close:c,onSelect:d}}function H1({children:t}){const{state:e,dispatch:s}=Fu(),{open:i,element:n}=e,o=()=>{s({type:"ON_EXIT"})},{refs:a,floatingStyles:l,context:c}=M1({placement:"bottom-start",open:i,onOpenChange:f=>{f||o()},elements:{reference:n},middleware:[Ym(10),Xm(),Jm()],whileElementsMounted:Qm}),d=T1(c,{outsidePress:f=>!(f.target instanceof Element&&f.target.closest(".ProseMirror"))}),u=B1(c,{role:"listbox"}),{getFloatingProps:h}=P1([d,u]);return i?r.jsx(A1,{children:r.jsx("div",{ref:a.setFloating,style:l,...h(),className:"z-50 w-auto min-w-[360px] max-w-[520px] rounded-lg border bg-popover p-0 text-popover-foreground shadow-md outline-hidden overflow-hidden",children:t})}):null}const W1=t=>{const e=B.c(29),{item:s,isSelected:i,onSelect:n,isLoading:o,ref:a}=t;let l;if(e[0]!==s){const j=si(s._meta);l=s.title||eo(s.name,j),e[0]=s,e[1]=l}else l=e[1];const c=l,d=s.description||null,u=s.icon,h=i&&"bg-accent text-accent-foreground",f=o&&"pointer-events-none opacity-50";let m;e[2]!==h||e[3]!==f?(m=X("relative flex w-full cursor-pointer select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors","hover:bg-accent hover:text-accent-foreground","focus:bg-accent focus:text-accent-foreground",h,f),e[2]=h,e[3]=f,e[4]=m):m=e[4];let p;e[5]!==u||e[6]!==c?(p=u!==void 0&&r.jsx(zs,{icon:u,name:c,size:"xs",className:"mr-2"}),e[5]=u,e[6]=c,e[7]=p):p=e[7];let g;e[8]!==c?(g=r.jsx("span",{className:"font-medium flex items-center truncate capitalize",children:c}),e[8]=c,e[9]=g):g=e[9];let _;e[10]!==o?(_=o&&r.jsx(jr,{size:"xs"}),e[10]=o,e[11]=_):_=e[11];let v;e[12]!==g||e[13]!==_?(v=r.jsxs("div",{className:"flex items-center justify-between gap-2",children:[g,_]}),e[12]=g,e[13]=_,e[14]=v):v=e[14];let x;e[15]!==d?(x=d&&r.jsx("div",{className:"text-xs text-muted-foreground line-clamp-1",children:d}),e[15]=d,e[16]=x):x=e[16];let b;e[17]!==v||e[18]!==x?(b=r.jsxs("div",{className:"flex flex-col gap-0.5 flex-1 min-w-0",children:[v,x]}),e[17]=v,e[18]=x,e[19]=b):b=e[19];let y;e[20]!==s.drillable?(y=s.drillable&&r.jsx("kbd",{className:"shrink-0 ml-2 px-1.5 py-0.5 text-[10px] font-medium text-muted-foreground bg-muted border border-border rounded",children:"↵"}),e[20]=s.drillable,e[21]=y):y=e[21];let C;return e[22]!==n||e[23]!==a||e[24]!==b||e[25]!==y||e[26]!==m||e[27]!==p?(C=r.jsxs("div",{ref:a,onClick:n,className:m,children:[p,b,y]}),e[22]=n,e[23]=a,e[24]=b,e[25]=y,e[26]=m,e[27]=p,e[28]=C):C=e[28],C},U1=t=>{const e=B.c(18),{editor:s,queryKey:i,queryFn:n,onSelect:o}=t;let a;e[0]!==s||e[1]!==o||e[2]!==n||e[3]!==i?(a={editor:s,queryKey:i,queryFn:n,onSelect:o},e[0]=s,e[1]=o,e[2]=n,e[3]=i,e[4]=a):a=e[4];const{items:l,selectedIndex:c,onSelect:d,selectedItem:u}=F1(a);if(!l.length){let p;return e[5]===Symbol.for("react.memo_cache_sentinel")?(p=r.jsx("div",{className:"min-w-[360px] max-w-[520px] bg-popover text-popover-foreground rounded-md border shadow-md p-3 text-sm",children:"No items found"}),e[5]=p):p=e[5],p}let h;e[6]===Symbol.for("react.memo_cache_sentinel")?(h={maxHeight:"min(320px, var(--radix-popover-content-available-height, 320px))"},e[6]=h):h=e[6];let f;if(e[7]!==d||e[8]!==l||e[9]!==c||e[10]!==u?.name){let p;e[12]!==d||e[13]!==c||e[14]!==u?.name?(p=(g,_)=>r.jsx(W1,{item:g,isSelected:_===c,ref:_===c?G1:void 0,onSelect:()=>d(g,_),isLoading:u?.name===g.name},g.name),e[12]=d,e[13]=c,e[14]=u?.name,e[15]=p):p=e[15],f=l.map(p),e[7]=d,e[8]=l,e[9]=c,e[10]=u?.name,e[11]=f}else f=e[11];let m;return e[16]!==f?(m=r.jsx("div",{className:"min-w-[360px] max-w-[520px] bg-popover text-popover-foreground rounded-md overflow-y-auto",style:h,children:r.jsx("div",{className:"p-1",children:f})}),e[16]=f,e[17]=m):m=e[17],m};function K1(){const t=B.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=r.jsx("div",{className:"p-1",children:[...Array(3)].map(q1)}),t[0]=e):e=t[0],e}function q1(t,e){return r.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1.5 animate-pulse",children:[r.jsx("div",{className:"h-4 w-24 bg-muted rounded"}),r.jsx("div",{className:"h-3 w-32 bg-muted rounded"})]},e)}function Hu(t){const e=B.c(18),{editor:s,char:i,pluginKey:n,queryKey:o,queryFn:a,onSelect:l,allow:c,onOpenChange:d}=t;let u;e[0]!==c||e[1]!==i||e[2]!==s||e[3]!==d||e[4]!==n?(u={editor:s,char:i,pluginKey:n,allow:c,onOpenChange:d},e[0]=c,e[1]=i,e[2]=s,e[3]=d,e[4]=n,e[5]=u):u=e[5];const{state:h,dispatch:f}=z1(u);let m;e[6]!==f||e[7]!==h?(m={state:h,dispatch:f},e[6]=f,e[7]=h,e[8]=m):m=e[8];let p;e[9]===Symbol.for("react.memo_cache_sentinel")?(p=r.jsx(K1,{}),e[9]=p):p=e[9];let g;e[10]!==s||e[11]!==l||e[12]!==a||e[13]!==o?(g=r.jsx(H1,{children:r.jsx(S.Suspense,{fallback:p,children:r.jsx(U1,{editor:s,queryKey:o,queryFn:a,onSelect:l})})}),e[10]=s,e[11]=l,e[12]=a,e[13]=o,e[14]=g):g=e[14];let _;return e[15]!==m||e[16]!==g?(_=r.jsx(zu.Provider,{value:m,children:g}),e[15]=m,e[16]=g,e[17]=_):_=e[17],_}function G1(t){t&&t.scrollIntoView({block:"center",behavior:"smooth"})}const Y1=[{name:"agents",title:"Agents",description:"Mention an agent to hand off work",kind:"category",drillable:!0},{name:"resources",title:"Resources",description:"Attach a resource as context",kind:"category",drillable:!0}],X1=({editor:t,virtualMcpId:e})=>{const s=Mt(),{org:i}=be(),n=oo(),o=Me({connectionId:e,orgId:i.id}),a=lt.virtualMcpResources(e,i.id),[l,c]=S.useState("categories"),d=S.useRef(l);d.current=l;const u=S.useRef(null),h=S.useRef(!1),f=["at-mention",i.id,e??"default",l],m=async({item:_,range:v})=>{if(se("chat_picker_item_selected",{picker:"@",item_kind:_.kind,item_name:_.name}),_.kind!=="category"&&(h.current=!0),_.kind==="category")return c(_.name==="agents"?"agents":"resources"),!1;if(_.kind==="agent"&&_.agentId){Cr(t,v,{id:_.agentId,name:_.name,metadata:{agentId:_.agentId,title:_.name},char:"@"}),c("categories");return}if(_.kind==="resource"&&_.uri&&o){try{const x=await nu(o,_.uri);Cr(t,v,{id:_.uri,name:_.uri,metadata:x.contents,char:"@"})}catch(x){console.error("[at-mention] Failed to fetch resource:",x),pe.error("Failed to load resource. Please try again.")}c("categories");return}},p=async _=>{const{query:v}=_,x=d.current;if(x==="categories"){if(!v.trim())return Y1;const C=v.toLowerCase(),j=n.filter(w=>w.status==="active"&&(!w.id||!Mn(w.id))&&w.id!==e&&(w.title.toLowerCase().includes(C)||w.description?.toLowerCase().includes(C))).map(w=>({name:w.title,title:w.title,description:w.description??void 0,icon:w.icon??null,kind:"agent",agentId:w.id})),V=await(async()=>{if(!o)return[];let w=s.getQueryData(a);return w||(w=await s.fetchQuery({queryKey:a,queryFn:()=>xr(o),staleTime:6e4})),(w?.resources??[]).filter(k=>k.uri.toLowerCase().includes(C)||k.name?.toLowerCase().includes(C)||k.description?.toLowerCase().includes(C)).map(k=>({name:k.name??k.uri,title:k.name,description:k.description,kind:"resource",uri:k.uri}))})();return[...j,...V]}if(x==="agents"){let C=n.filter(j=>j.status==="active"&&(!j.id||!Mn(j.id))&&j.id!==e);if(v.trim()){const j=v.toLowerCase();C=C.filter(V=>V.title.toLowerCase().includes(j)||V.description?.toLowerCase().includes(j))}return C.map(j=>({name:j.title,title:j.title,description:j.description??void 0,icon:j.icon??null,kind:"agent",agentId:j.id}))}if(!o)return[];let b=s.getQueryData(a);b?s.fetchQuery({queryKey:a,queryFn:()=>xr(o),staleTime:6e4}).catch(()=>{}):b=await s.fetchQuery({queryKey:a,queryFn:()=>xr(o),staleTime:6e4});let y=b?.resources??[];if(v.trim()){const C=v.toLowerCase();y=y.filter(j=>j.uri.toLowerCase().includes(C)||j.name?.toLowerCase().includes(C)||j.description?.toLowerCase().includes(C))}return y.map(C=>({name:C.name??C.uri,title:C.name,description:C.description,kind:"resource",uri:C.uri}))},g=_=>{if(_)u.current=Date.now(),h.current=!1,se("chat_picker_opened",{picker:"@"});else{const v=u.current;se("chat_picker_closed",{picker:"@",outcome:h.current?"selected":"dismissed",duration_ms:v?Date.now()-v:null}),u.current=null,c("categories")}};return r.jsx(Hu,{editor:t,char:"@",pluginKey:"atDropdownMenu",queryKey:f,queryFn:p,onSelect:m,onOpenChange:g})};function J1(t,e){const s=ts(t),i=Wr(),n=new Map(i.map(c=>[c.id,c])),o=(s?.connections??[]).map(c=>c.connection_id),{data:a}=Fi({queryKey:lt.promptConnectionMap(e,o),queryFn:async()=>{const c={};return await Promise.all(o.map(async d=>{try{const u=await lg({connectionId:d,orgId:e}),h=await Pn(u);for(const f of h.prompts)f.name in c||(c[f.name]=d)}catch{}})),c},staleTime:6e4,enabled:o.length>0}),l=new Map;for(const[c,d]of Object.entries(a??{})){const u=n.get(d);u&&l.set(c,u)}return l}async function Fc(t,e,s,i,n,o){try{const a=await ul(s,i,o);Cr(t,e,{id:i,name:al(i,n),metadata:a.messages,char:"/"})}catch(a){console.error("[slash] Failed to fetch prompt:",a),pe.error("Failed to load prompt. Please try again.")}}async function Q1(t,e,s,i){try{const n=await nu(s,i);Cr(t,e,{id:i,name:i,metadata:n.contents,char:"/"})}catch(n){console.error("[slash] Failed to fetch resource:",n),pe.error("Failed to load resource. Please try again.")}}const Z1=({editor:t,virtualMcpId:e})=>{const s=Mt(),{org:i}=be(),n=Me({connectionId:e,orgId:i.id}),o=J1(e,i.id),a=S.useRef(o);a.current=o;const l=lt.virtualMcpPrompts(e,i.id),c=lt.virtualMcpResources(e,i.id),d=["slash-mention",i.id,e??"default"],[u,h]=S.useState(null),f=S.useRef(null),m=S.useRef(!1),p=async({item:x,range:b})=>{if(se("chat_picker_item_selected",{picker:"/",item_kind:x.kind,item_name:x.name}),m.current=!0,!!n)if(x.kind==="prompt"){if(x.arguments&&x.arguments.length>0){h({range:b,item:x});return}const y=si(x._meta);await Fc(t,b,n,x.name,y)}else x.uri&&await Q1(t,b,n,x.uri)},g=async x=>{if(!u||!n)return;const{range:b,item:y}=u,C=si(y._meta);await Fc(t,b,n,y.name,C,x),h(null)},_=async x=>{const{query:b}=x;if(!n)return[];const[y,C]=await Promise.all([ev(s,l,n),tv(s,c,n)]),j=b.trim().toLowerCase(),V=(y??[]).filter(k=>!j||k.name.toLowerCase().includes(j)||k.title?.toLowerCase().includes(j)||k.description?.toLowerCase().includes(j)).map(k=>({name:k.name,title:k.title,description:k.description,icon:a.current.get(k.name)?.icon??null,kind:"prompt",arguments:k.arguments,_meta:k._meta})),w=(C??[]).filter(k=>!j||k.uri.toLowerCase().includes(j)||k.name?.toLowerCase().includes(j)||k.description?.toLowerCase().includes(j)).map(k=>({name:k.name??k.uri,title:k.name,description:k.description,kind:"resource",uri:k.uri}));return[...V,...w]},v=u?.item.kind==="prompt"?{name:u.item.name,arguments:u.item.arguments,description:u.item.description}:null;return r.jsxs(r.Fragment,{children:[r.jsx(Hu,{editor:t,char:"/",pluginKey:"slashDropdownMenu",queryKey:d,queryFn:_,onSelect:p,onOpenChange:x=>{if(x)f.current=Date.now(),m.current=!1,se("chat_picker_opened",{picker:"/"});else{const b=f.current;se("chat_picker_closed",{picker:"/",outcome:m.current?"selected":"dismissed",duration_ms:b?Date.now()-b:null}),f.current=null}}}),r.jsx(Rl,{prompt:v,setPrompt:()=>h(null),onSubmit:g})]})};async function ev(t,e,s){let i=t.getQueryData(e);return i?t.fetchQuery({queryKey:e,queryFn:()=>Pn(s),staleTime:6e4}).catch(()=>{}):i=await t.fetchQuery({queryKey:e,queryFn:()=>Pn(s),staleTime:6e4}),i?.prompts??[]}async function tv(t,e,s){let i=t.getQueryData(e);return i?t.fetchQuery({queryKey:e,queryFn:()=>xr(s),staleTime:6e4}).catch(()=>{}):i=await t.fetchQuery({queryKey:e,queryFn:()=>xr(s),staleTime:6e4}),i?.resources??[]}function sv(t){return[ig.configure({heading:!1,blockquote:!1,codeBlock:!1,horizontalRule:!1,dropcursor:!1}),Fx.configure({placeholder:()=>t.current??"Ask anything, / for prompts, @ for agents & resources...",showOnlyWhenEditable:!1}),Lp,Bp]}function Wu({tiptapDoc:t,setTiptapDoc:e,disabled:s=!1,enterToSubmit:i=!1,placeholder:n,onSubmit:o,children:a}){const l=S.useRef(o),c=S.useRef(e),d=S.useRef(i),u=S.useRef(n),h=tg({extensions:sv(u),content:t||"",editorProps:{attributes:{"data-chat-input":"true",class:"prose prose-sm max-w-none focus:outline-none w-full h-full text-[15px] p-[18px]"},handleKeyDown:(f,m)=>m.key==="Enter"&&!m.shiftKey&&d.current?(m.preventDefault(),l.current?.(),!0):!1},onUpdate:({editor:f})=>{c.current(f?.getJSON())}});return S.useEffect(()=>{h?.setEditable(!s)},[h,s]),S.useEffect(()=>{l.current=o},[o]),S.useEffect(()=>{c.current=e},[e]),S.useEffect(()=>{d.current=i},[i]),S.useEffect(()=>{u.current=n},[n]),S.useEffect(()=>{if(h?.isDestroyed)return;const f=JSON.stringify(h?.getJSON()),m=JSON.stringify(t||{type:"doc",content:[]});f!==m&&h.commands.setContent(t||{type:"doc",content:[]})},[h,t]),r.jsx(sg.Provider,{value:{editor:h},children:a})}function Uu(t){const e=B.c(25),{disabled:s,virtualMcpId:i,showFileUploader:n,selectedModel:o,ref:a,className:l}=t,c=s===void 0?!1:s,d=n===void 0?!1:n,{editor:u}=to();let h,f;if(e[0]!==u?(h=()=>({focus:()=>{u?.commands.focus()},clear:()=>{u?.commands.clearContent(!0)},appendText:V=>{if(!u)return;const w=u.state.doc.textContent.trim()==="";u.commands.focus("end"),w||u.commands.insertContent(" "),u.commands.insertContent(V)},syncVoiceText:(V,w)=>{if(u&&(u.commands.setContent(V||{type:"doc",content:[]}),w)){u.commands.focus("end");const k=u.state.doc.textContent.trim().length>0;u.commands.insertContent(k?" "+w:w)}},restoreContent:V=>{u&&u.commands.setContent(V||{type:"doc",content:[]})}}),f=[u],e[0]=u,e[1]=h,e[2]=f):(h=e[1],f=e[2]),S.useImperativeHandle(a??null,h,f),!u)return null;const m=c&&"cursor-not-allowed opacity-70",p=c&&"[&_.ProseMirror]:cursor-not-allowed";let g;e[3]!==l||e[4]!==m||e[5]!==p?(g=X("overflow-y-auto relative flex-1 max-h-[164px] min-h-[20px] w-full flex flex-col",l,"[&_.ProseMirror]:outline-none [&_.ProseMirror]:min-h-[20px] [&_.ProseMirror]:flex-1","[&_.ProseMirror_p.is-editor-empty:first-child::before]:content-[attr(data-placeholder)]","[&_.ProseMirror_p.is-editor-empty:first-child::before]:text-muted-foreground","[&_.ProseMirror_p.is-editor-empty:first-child::before]:opacity-50","[&_.ProseMirror_p.is-editor-empty:first-child::before]:float-left","[&_.ProseMirror_p.is-editor-empty:first-child::before]:pointer-events-none","[&_.ProseMirror_p.is-editor-empty:first-child::before]:h-0",m,p),e[3]=l,e[4]=m,e[5]=p,e[6]=g):g=e[6];let _;e[7]!==u||e[8]!==g?(_=r.jsx(rg,{editor:u,className:g}),e[7]=u,e[8]=g,e[9]=_):_=e[9];const v=i??null;let x;e[10]!==u||e[11]!==v?(x=r.jsx(S.Suspense,{fallback:null,children:r.jsx(Z1,{editor:u,virtualMcpId:v})}),e[10]=u,e[11]=v,e[12]=x):x=e[12];const b=i??null;let y;e[13]!==u||e[14]!==b?(y=r.jsx(S.Suspense,{fallback:null,children:r.jsx(X1,{editor:u,virtualMcpId:b})}),e[13]=u,e[14]=b,e[15]=y):y=e[15];let C;e[16]!==u||e[17]!==o||e[18]!==d?(C=d&&o?r.jsx(Bx,{editor:u,selectedModel:o}):null,e[16]=u,e[17]=o,e[18]=d,e[19]=C):C=e[19];let j;return e[20]!==x||e[21]!==y||e[22]!==C||e[23]!==_?(j=r.jsxs(r.Fragment,{children:[_,x,y,C]}),e[20]=x,e[21]=y,e[22]=C,e[23]=_,e[24]=j):j=e[24],j}function pa(t){const e=B.c(3),[s]=Wi();let i;return e[0]!==s.enableSounds||e[1]!==t?(i=()=>{s.enableSounds&&Zg(t.dataUri).catch(o=>{console.warn(`[sound] ${t.name} playback failed:`,o)})},e[0]=s.enableSounds,e[1]=t,e[2]=i):i=e[2],i}const iv={name:"switch-005",dataUri:"data:audio/mpeg;base64,SUQzBAAAAAAAIlRTU0VAAAAOAAADTGF2ZjYyLjMuMTAwAAAAAAAAAAAAAAD/+1DAAAAAAAAAAAAAAAAAAAAAAABJbmZvAAAADwAAABkAABU4ABMTEx0dHR0nJycnMTExMTs7OztERERETk5OTlhYWFhiYmJibGxsbHZ2dnZ/f39/iYmJiZOTk5OdnZ2dp6enp7GxsbG7u7u7xMTExM7Ozs7Y2NjY4uLi4uzs7Oz29vb2/////wAAAABMYXZjNjIuMTEAAAAAAAAAAAAAAAAkBVYAAAAAAAAVOPCP8KUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//tQxAAACEwDXvQRAAG8Ii93HtACUCAABAKCJwfaCEHwfeoEAQdEAYygIHBOCAIAgCAJh9QIOg+D5/ygPh/wfB8DuKAgCHyn9QPh/5SCDv+CEHAQdxOD4B27c39tbckkqYbBAYAN9bNJLB+aXAf5wQAKdzxfbmrVIRQ4xNx3HwnoDmLhfMhgJiiw/HREXNCHqjvHEPEG8QjBYlxQNepJAT0kC8ip6JzSWj1TasoG+iyycbf2Uil1ovf1f/oUtR1qP+s1WSBFKoAAU02BDjMhuP/7UsQEgws8bRpd8YABJYPeBf9wCGXTGxBYcw5AJFMFMAmQQAhGAxgLBgHIAMYAAALhgAchipbe/91aU1VV4zcZj1Vf1XgYCIMBNrsBAIGs9/Ue4i/xFPeqCqwViI9/UeLf///rOngdA3OPHFjmOBv+EQnGahgaZxVplmkAH5JadDTQlNCEuGNiWYbCCONWdUJg6HXNazFdu1T+VgaEpOP70exv7f2/4b/yH//2/4cqCX/zWRUrIw+IPNMNlDnjAXQas/I4AzmYifA0tMSCgQDF//tSxBCDSzzi3k/sQwEyCtjJ/rBZAk+Uqj1YhA5YMCAAMwgOUchTkK7OR7LbMl0W1H6SvzG0Q2ZzfKUhnmTobv9DNhS1v7P8h//8Gv8gTRt1jReZ7YEjmMQg9hhwwMycHooasFmZyjcZGBKJD+IwbMCQQLoi+IQXCcIoydKoilI2MWFS5uJdDEu2taRrYI2ZSqKY50pJLv2NfjUAAuQAMfqVQ/T3PDQgMJMeEZ45hJzY6MNoFMxqTj1zNGQKJjAxEsSCBgQJBSIL0mcKYQJfVAn/+1LEGwLKlEKrD3MiYcuMkVa/wABB8Vh6M1q1epbvXwWBURhkyEhWZ/////////////9gjZ/Wt4w+4MNMCpE4TBYQl4w1IHvMDdA2zBngBMwc8COMDhCpDAfgOAAgrBgNYU+YC0FBGAkAMpgWoSCYAGESGBGAKBgXgJOdiOJmMCmNwCYNDJhYRPykRCJhTBnEUzlsjv4UNLj/z97n3Mv/7z1nZqyitYAZIqErIwMwJAqEw0GAAMFptJMaqFwB8CQIWlhuhuDAwNjfuwrQFAYXCf/7UsQVAA+9PTP42gYRdiIu9zBwAPbFUCi0DAhgNcS+7cDwVgM05A9bUDeuQMyE/u3CygVISgZhpIau/9PhdQG2C9DpxZZJmn/dn/Psmt0EFm////l84ThUTopE4VD/9JkubOGasTvN30C20G21qgUCkVCoUCgPMywrPCGly27V5q5t24vl/8jSlSAPCxzNseNCw3oh3NGBu4BZJ5hv7DRSfR/+eWG7nA8IKh2Olv5iz3q5m3//Joxo3JqNyYkSuGt/k6D4DeoBOHmHdl0dkZYA//tSxAUAC4B1Z/2DADEcA17Z/uhI4Yoik/TrZo+ww7UtmpW4LDWu2IacoJKJJeTSM+ZmAYBEiU+ZnnAwCn1VVVV6JUJQVnioKhrgqdKgqGpUFeCp0sDR3ztQNREDRUFioKuxKCpYGQBlRIBk+aLwb8KblGQVDdphPYTUdBOGbVpAaTF6ZdjEV0iRUZRCYkA4oUQDx5zqDugtXvza/7fuNNvfZ+j9v+T/2f//J/4cAAOTpE5K4zksR9MfIB+TDcQTI4gNs1XKAzEFUrGkxABYEBb/+1LEEYNKrEjgT/TCwYYVmUX+mHoKgWhKU5Eiw9SFIRmppw+3fYo4siPhUFeexM8KgIO6wVuPDDy01qeRaVbw357//y3+o8M0pBNlNLCGBzGKwyYw2IIFOE1WNTjRM6x8MlA1AxDhUHTAkEiyKpnbWrLcaOBotBUKbk1pypcWDAIK00AhKLGkUco6q9VWvM53mcaq3tVa8zjTM/tX//EDP//////////XAAmrwAAPoKwcw0ShDCZD/BQlhzinxQdorsOuXTEIC01ZkJyu4k/qPP/7UsQUAEjkrrkvZaPBIRXUoe5QObfMhYKX9RVgTPqCSCaSCaSC0XVdV1f/////6IAlguuAJSiDRNloNBsZg+0+Ts8MMCn81WUTRAlIi+GHECD0y8AWDIqswYsxGOSKVV7MqOni8tkVOip0fZX/////9HrMCbAz2EHGS4GKAAiRAAAYAcDdKd4G6Z/nwYgJ0ZAIgZyC8aPAs/iPBhwMpWDQNARltNS5Y61v//9i8Yl4SkFkIGTkAc0UBrIYLPA4MYBEy+YLMRuY4nhTC3hZA68H//tSxCoAyQC6mY6CkWDJBIsBz/QUrgNmahSzcrYw0/HhfnMAZBojDsgTFkDR5MDkG/DZEbk2FCmowqdqv2TYABiJwqqYjaQRGZ1URZ1DhSsdiHX/GBu0QpzIBNSaLqZ0ARkwFARxMrpt/Eh47mbQAhhU6sisFUxBTUUzLjEwMFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVX/+1LESoHHJCRaj/dmYAIAQAAQAARVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVTEFNRTMuMTAwVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVf/7UsSLg8AAAaQAAAAgAAA0gAAABFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVTEFNRTMuMTAwVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV//tSxKGDwAABpAAAACAAADSAAAAEVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVMQU1FMy4xMDBVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV//tSxKGDwAABpAAAACAAADSAAAAEVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVMQU1FMy4xMDBVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV//tSxKGDwAABpAAAACAAADSAAAAEVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVMQU1FMy4xMDBVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVX/+1LEoYPAAAGkAAAAIAAANIAAAARVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVUxBTUUzLjEwMFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVf/7UsShg8AAAaQAAAAgAAA0gAAABFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVTEFNRTMuMTAwVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV//tSxKGDwAABpAAAACAAADSAAAAEVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVMQU1FMy4xMDBVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVX/+1LEoYPAAAGkAAAAIAAANIAAAARVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVUxBTUUzLjEwMFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV//tSxKGDwAABpAAAACAAADSAAAAEVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVMQU1FMy4xMDBVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV//tSxKGDwAABpAAAACAAADSAAAAEVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVMQU1FMy4xMDBVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV//tSxKGDwAABpAAAACAAADSAAAAEVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVMQU1FMy4xMDBVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV//tSxKGDwAABpAAAACAAADSAAAAEVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVMQU1FMy4xMDBVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV//tSxKGDwAABpAAAACAAADSAAAAEVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVMQU1FMy4xMDBVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV",duration:.609,format:"mp3",license:"CC0",author:"Kenney"},rv=[{src:"/connections/gmail.png",name:"Gmail"},{src:"/connections/perplexity.png",name:"Perplexity"},{src:"/connections/github.png",name:"GitHub"}];function nv(){const t=B.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=r.jsx("div",{className:"flex items-center -space-x-1.5",children:rv.map(ov)}),t[0]=e):e=t[0],e}function ov(t){return r.jsx("img",{src:t.src,alt:t.name,className:"size-5 rounded-sm ring-1 ring-border object-cover bg-white"},t.name)}function av(t){const e=B.c(129),{disabled:s,onOpenConnections:i,virtualMcpId:n}=t,[o,a]=S.useState(!1),l=pa(iv),{org:c}=be(),{editor:d}=to();let u;e[0]!==c.id||e[1]!==n?(u={connectionId:n,orgId:c.id},e[0]=c.id,e[1]=n,e[2]=u):u=e[2];const h=Me(u);let f;e[3]!==c.id||e[4]!==n?(f=lt.virtualMcpPrompts(n,c.id),e[3]=c.id,e[4]=n,e[5]=f):f=e[5];const m=f;let p;e[6]!==h?(p=()=>Pn(h),e[6]=h,e[7]=p):p=e[7];const g=o&&!!h;let _;e[8]!==m||e[9]!==p||e[10]!==g?(_={queryKey:m,queryFn:p,staleTime:6e4,enabled:g},e[8]=m,e[9]=p,e[10]=g,e[11]=_):_=e[11];const{data:v,isLoading:x}=Fi(_);let b;e[12]!==v?.prompts?(b=v?.prompts??[],e[12]=v?.prompts,e[13]=b):b=e[13];const y=b,[C,j]=S.useState(null),{credentialId:V,imageModel:w,setImageModel:k,deepResearchModel:T,setDeepResearchModel:I,chatMode:A,setChatMode:N,simpleModeEnabled:E}=ni(),R=A==="plan",[M,L]=S.useState(!1),[D,P]=S.useState(!1),{models:O,isLoading:z}=tu(M||D?V??void 0:void 0);let $,W,F,G,q,H,ee,K,U,te,Y,J,ie;if(e[14]!==C||e[15]!==O||e[16]!==A||e[17]!==h||e[18]!==T||e[19]!==s||e[20]!==d||e[21]!==w||e[22]!==M||e[23]!==z||e[24]!==R||e[25]!==i||e[26]!==o||e[27]!==l||e[28]!==D||e[29]!==N||e[30]!==I||e[31]!==k||e[32]!==E){const Q=O.filter(cv),ae=O.filter(lv);let Se;e[46]!==A||e[47]!==R||e[48]!==l||e[49]!==N?(Se=()=>{l();const _e=R?"default":"plan";se("chat_mode_changed",{from_mode:A,to_mode:_e,source:"tools_popover"}),N(_e),a(!1)},e[46]=A,e[47]=R,e[48]=l,e[49]=N,e[50]=Se):Se=e[50];const Ne=Se;let Be;e[51]!==i?(Be=()=>{i(),a(!1)},e[51]=i,e[52]=Be):Be=e[52],F=Be;let Oe;e[53]!==h||e[54]!==d?(Oe=async(_e,Ot)=>{if(!d||!h)return;const $t=si(_e._meta),ls={from:d.state.selection.from,to:d.state.selection.to};try{const Qi=await ul(h,_e.name,Ot);Cr(d,ls,{id:_e.name,name:al(_e.name,$t),metadata:Qi.messages,char:"/"})}catch{pe.error("Failed to load prompt. Please try again.")}},e[53]=h,e[54]=d,e[55]=Oe):Oe=e[55];const He=Oe;let Je;e[56]!==He?(Je=async _e=>{a(!1);const Ot=!!(_e.arguments&&_e.arguments.length>0);if(se("chat_prompt_inserted",{prompt_name:_e.name,with_arguments:Ot}),Ot){j(_e);return}await He(_e)},e[56]=He,e[57]=Je):Je=e[57],q=Je;let dt;e[58]!==C||e[59]!==He?(dt=async _e=>{C&&(await He(C,_e),j(null))},e[58]=C,e[59]=He,e[60]=dt):dt=e[60],G=dt;let ge;e[61]!==l||e[62]!==k?(ge=_e=>{l(),se("chat_image_model_selected",{model_id:_e.modelId,model_title:_e.title,provider:_e.providerId??null}),k(_e),a(!1)},e[61]=l,e[62]=k,e[63]=ge):ge=e[63];const ke=ge;let Qe;e[64]!==l||e[65]!==I?(Qe=_e=>{l(),se("chat_search_model_selected",{model_id:_e.modelId,model_title:_e.title,provider:_e.providerId??null}),I(_e),a(!1)},e[64]=l,e[65]=I,e[66]=Qe):Qe=e[66];const Ct=Qe;let Pe;e[67]!==A||e[68]!==l||e[69]!==N?(Pe=()=>{l();const _e=A==="gen-image"?"default":"gen-image";se("chat_mode_changed",{from_mode:A,to_mode:_e,source:"tools_popover"}),N(_e),a(!1)},e[67]=A,e[68]=l,e[69]=N,e[70]=Pe):Pe=e[70];const Kt=Pe;let jt;e[71]!==A||e[72]!==l||e[73]!==N?(jt=()=>{l();const _e=A==="web-search"?"default":"web-search";se("chat_mode_changed",{from_mode:A,to_mode:_e,source:"tools_popover"}),N(_e),a(!1)},e[71]=A,e[72]=l,e[73]=N,e[74]=jt):jt=e[74];const Ae=jt,Ie=A==="gen-image",qe=A==="web-search";W=js,K=o,e[75]!==A||e[76]!==o?(U=_e=>{_e&&!o&&se("chat_tools_popover_opened",{chat_mode:A}),a(_e)},e[75]=A,e[76]=o,e[77]=U):U=e[77];let qt,_t;e[78]===Symbol.for("react.memo_cache_sentinel")?(qt=r.jsx(zh,{size:14}),_t=r.jsx("span",{className:"hidden sm:inline",children:"Tools"}),e[78]=qt,e[79]=_t):(qt=e[78],_t=e[79]),e[80]!==s?(te=r.jsx(ks,{asChild:!0,children:r.jsxs(ne,{type:"button",variant:"ghost",size:"default",disabled:s,className:"text-muted-foreground hover:text-foreground",children:[qt,_t]})}),e[80]=s,e[81]=te):te=e[81],$=Ns,Y="start",J="w-52 p-1.5";const xt=R&&"text-violet-600 dark:text-violet-400";let vt;e[82]!==xt?(vt=X(xt),e[82]=xt,e[83]=vt):vt=e[83];const _s=R&&"text-violet-500";let $e;e[84]!==_s?($e=X(_s),e[84]=_s,e[85]=$e):$e=e[85];let kt;e[86]!==$e?(kt=r.jsx(Xh,{size:16,className:$e}),e[86]=$e,e[87]=kt):kt=e[87];let Nt;e[88]===Symbol.for("react.memo_cache_sentinel")?(Nt=r.jsx("span",{className:"flex-1",children:"Plan mode"}),e[88]=Nt):Nt=e[88];let wt;e[89]!==R?(wt=R&&r.jsx("span",{className:"text-xs text-violet-500 font-medium",children:"On"}),e[89]=R,e[90]=wt):wt=e[90],e[91]!==Ne||e[92]!==vt||e[93]!==kt||e[94]!==wt?(ie=r.jsxs(ot,{onClick:Ne,className:vt,children:[kt,Nt,wt]}),e[91]=Ne,e[92]=vt,e[93]=kt,e[94]=wt,e[95]=ie):ie=e[95],H=E?r.jsxs(ot,{onClick:Kt,className:X(Ie&&"text-pink-600 dark:text-pink-400"),children:[r.jsx(la,{size:16,className:X(Ie&&"text-pink-500")}),r.jsx("span",{className:"flex-1",children:"Create image"}),Ie&&r.jsx("span",{className:"text-xs text-pink-500 font-medium",children:"On"})]}):r.jsxs(Sn,{open:M,onOpenChange:L,children:[r.jsxs("div",{className:"flex items-center rounded-lg",children:[r.jsxs(ot,{onClick:Kt,disabled:!w,className:X("flex-1 rounded-r-none pr-1",Ie&&"text-pink-600 dark:text-pink-400"),children:[r.jsx(la,{size:16,className:X(Ie&&"text-pink-500")}),r.jsx("span",{className:"flex-1",children:"Create image"}),Ie&&r.jsx("span",{className:"text-xs text-pink-500 font-medium",children:"On"})]}),r.jsx(lc,{className:X("flex items-center justify-center rounded-r-lg rounded-l-none px-1.5 py-1.5 text-muted-foreground outline-hidden select-none","hover:bg-accent hover:text-accent-foreground focus:bg-accent focus:text-accent-foreground","data-[state=open]:bg-accent data-[state=open]:text-accent-foreground"),children:r.jsx(kr,{size:14})})]}),r.jsx(wn,{className:"w-80 max-h-72 overflow-y-auto p-1.5",children:z?r.jsxs("div",{className:"flex items-center gap-2 px-2 py-3 text-sm text-muted-foreground",children:[r.jsx(Ee,{size:14,className:"animate-spin"}),"Loading models…"]}):Q.length===0?r.jsx("div",{className:"px-2 py-3 text-sm text-muted-foreground",children:"No image models available"}):Q.map(_e=>{const Ot=w?.modelId===_e.modelId,$t=xc(_e),ls=_e.title.includes(": ")?_e.title.split(": ").slice(1).join(": "):_e.title;return r.jsxs(ot,{onClick:()=>ke(_e),className:"flex items-center gap-2",children:[r.jsx("img",{src:$t,alt:"",className:"size-4 shrink-0 rounded-sm dark:bg-white dark:p-px"}),r.jsx("span",{className:"flex-1 text-sm truncate",children:ls}),Ot&&r.jsx(Jt,{size:14,className:"text-pink-500 shrink-0"})]},_e.modelId)})})]}),ee=E?r.jsxs(ot,{onClick:Ae,className:X(qe&&"text-blue-600 dark:text-blue-400"),children:[r.jsx(Ti,{size:16,className:X(qe&&"text-blue-500")}),r.jsx("span",{className:"flex-1",children:"Web search"}),qe&&r.jsx("span",{className:"text-xs text-blue-500 font-medium",children:"On"})]}):T&&r.jsxs(Sn,{open:D,onOpenChange:P,children:[r.jsxs("div",{className:"flex items-center rounded-lg",children:[r.jsxs(ot,{onClick:Ae,className:X("flex-1 rounded-r-none pr-1",qe&&"text-blue-600 dark:text-blue-400"),children:[r.jsx(Ti,{size:16,className:X(qe&&"text-blue-500")}),r.jsx("span",{className:"flex-1",children:"Web search"}),qe&&r.jsx("span",{className:"text-xs text-blue-500 font-medium",children:"On"})]}),r.jsx(lc,{className:X("flex items-center justify-center rounded-r-lg rounded-l-none px-1.5 py-1.5 text-muted-foreground outline-hidden select-none","hover:bg-accent hover:text-accent-foreground focus:bg-accent focus:text-accent-foreground","data-[state=open]:bg-accent data-[state=open]:text-accent-foreground"),children:r.jsx(kr,{size:14})})]}),r.jsx(wn,{className:"w-80 max-h-72 overflow-y-auto p-1.5",children:z?r.jsxs("div",{className:"flex items-center gap-2 px-2 py-3 text-sm text-muted-foreground",children:[r.jsx(Ee,{size:14,className:"animate-spin"}),"Loading models…"]}):ae.map(_e=>{const Ot=T?.modelId===_e.modelId,$t=xc(_e),ls=_e.title.includes(": ")?_e.title.split(": ").slice(1).join(": "):_e.title;return r.jsxs(ot,{onClick:()=>Ct(_e),className:"flex items-center gap-2",children:[r.jsx("img",{src:$t,alt:"",className:"size-4 shrink-0 rounded-sm dark:bg-white dark:p-px"}),r.jsx("span",{className:"flex-1 text-sm truncate",children:ls}),Ot&&r.jsx(Jt,{size:14,className:"text-blue-500 shrink-0"})]},_e.modelId)})})]}),e[14]=C,e[15]=O,e[16]=A,e[17]=h,e[18]=T,e[19]=s,e[20]=d,e[21]=w,e[22]=M,e[23]=z,e[24]=R,e[25]=i,e[26]=o,e[27]=l,e[28]=D,e[29]=N,e[30]=I,e[31]=k,e[32]=E,e[33]=$,e[34]=W,e[35]=F,e[36]=G,e[37]=q,e[38]=H,e[39]=ee,e[40]=K,e[41]=U,e[42]=te,e[43]=Y,e[44]=J,e[45]=ie}else $=e[33],W=e[34],F=e[35],G=e[36],q=e[37],H=e[38],ee=e[39],K=e[40],U=e[41],te=e[42],Y=e[43],J=e[44],ie=e[45];let ue;e[96]===Symbol.for("react.memo_cache_sentinel")?(ue=r.jsxs(Bh,{className:"gap-2",children:[r.jsx("span",{className:"flex size-4 items-center justify-center text-base font-medium text-muted-foreground",children:"/"}),r.jsx("span",{className:"flex-1",children:"Prompts"})]}),e[96]=ue):ue=e[96];let de;e[97]!==q||e[98]!==x||e[99]!==y?(de=x?r.jsxs("div",{className:"flex items-center gap-2 px-2 py-3 text-sm text-muted-foreground",children:[r.jsx(Ee,{size:14,className:"animate-spin"}),"Loading prompts…"]}):y.length===0?r.jsx("div",{className:"px-2 py-3 text-sm text-muted-foreground",children:"No prompts available"}):y.map(Q=>r.jsxs(ot,{onClick:()=>q(Q),className:"flex flex-col items-start gap-0.5",children:[r.jsx("span",{className:"font-medium text-sm capitalize",children:Q.title||eo(Q.name,si(Q._meta))}),Q.description&&r.jsx("span",{className:"text-xs text-muted-foreground line-clamp-2",children:Q.description})]},Q.name)),e[97]=q,e[98]=x,e[99]=y,e[100]=de):de=e[100];let xe;e[101]!==de?(xe=r.jsxs(Sn,{children:[ue,r.jsx(wn,{className:"w-80 max-h-72 overflow-y-auto p-1.5",children:de})]}),e[101]=de,e[102]=xe):xe=e[102];let oe,he;e[103]===Symbol.for("react.memo_cache_sentinel")?(oe=r.jsx(Lg,{size:16}),he=r.jsx("span",{className:"flex-1",children:"Connections"}),e[103]=oe,e[104]=he):(oe=e[103],he=e[104]);let me;e[105]===Symbol.for("react.memo_cache_sentinel")?(me=r.jsx(S.Suspense,{children:r.jsx(nv,{})}),e[105]=me):me=e[105];let fe;e[106]!==F?(fe=r.jsxs(ot,{onClick:F,children:[oe,he,me]}),e[106]=F,e[107]=fe):fe=e[107];let le;e[108]!==$||e[109]!==H||e[110]!==ee||e[111]!==xe||e[112]!==fe||e[113]!==Y||e[114]!==J||e[115]!==ie?(le=r.jsxs($,{align:Y,className:J,children:[ie,H,ee,xe,fe]}),e[108]=$,e[109]=H,e[110]=ee,e[111]=xe,e[112]=fe,e[113]=Y,e[114]=J,e[115]=ie,e[116]=le):le=e[116];let ve;e[117]!==W||e[118]!==K||e[119]!==U||e[120]!==te||e[121]!==le?(ve=r.jsxs(W,{open:K,onOpenChange:U,children:[te,le]}),e[117]=W,e[118]=K,e[119]=U,e[120]=te,e[121]=le,e[122]=ve):ve=e[122];let Ce;e[123]!==C||e[124]!==G?(Ce=r.jsx(Rl,{prompt:C,setPrompt:j,onSubmit:G}),e[123]=C,e[124]=G,e[125]=Ce):Ce=e[125];let Te;return e[126]!==ve||e[127]!==Ce?(Te=r.jsxs(r.Fragment,{children:[ve,Ce]}),e[126]=ve,e[127]=Ce,e[128]=Te):Te=e[128],Te}function lv(t){const e=t.modelId.toLowerCase().replace(/[^a-z0-9]/g,"");return e.includes("sonar")||e.includes("deepresearch")}function cv(t){return t.capabilities?.includes("image")}function dv({open:t,onOpenChange:e,onCreated:s}){const{org:i}=be(),{data:n}=St.useSession(),{stdioEnabled:o}=Zm(),a=Rs(),l=Sl(),c=lu(),u=cu(c,"").items,h=Hi({resolver:Or(t_),defaultValues:{title:"",description:null,icon:null,ui_type:"HTTP",connection_url:"",connection_token:null,npx_package:"",stdio_command:"",stdio_args:"",stdio_cwd:"",env_vars:[]}}),f=h.watch("ui_type"),m=h.watch("connection_url"),p=h.watch("npx_package"),g=on({uiType:f,connectionUrl:m??"",npxPackage:p??""})??vc({uiType:f,connectionUrl:m??"",registryItems:u}),_=V=>{const w=V.trim();if(!w)return;const k=!!h.formState.dirtyFields.title,T=!!h.formState.dirtyFields.description,I=!!h.formState.dirtyFields.env_vars,A=E=>{if(E&&(!k&&!h.getValues("title").trim()&&E.title&&h.setValue("title",E.title,{shouldDirty:!1}),!T&&!(h.getValues("description")??"").trim()&&E.description&&h.setValue("description",E.description,{shouldDirty:!1}),!I&&E.envVarKeys?.length)){const R=h.getValues("env_vars")??[],M=new Set(R.map(D=>D.key)),L=E.envVarKeys.filter(D=>!M.has(D));L.length>0&&h.setValue("env_vars",[...R,...L.map(D=>({key:D,value:""}))],{shouldDirty:!0})}},N=i_(w);if(N&&o){h.setValue("ui_type","NPX",{shouldDirty:!0}),h.setValue("npx_package",N.packageName,{shouldDirty:!0}),h.setValue("connection_url","",{shouldDirty:!0}),h.setValue("connection_token",null,{shouldDirty:!0}),A(on({uiType:"NPX",npxPackage:N.packageName}));return}if(w.startsWith("http://")||w.startsWith("https://")){const E=f==="HTTP"||f==="SSE"||f==="Websocket"?f:"HTTP";h.setValue("ui_type",E,{shouldDirty:!0}),h.setValue("connection_url",w,{shouldDirty:!0}),A(on({uiType:E,connectionUrl:w})??vc({uiType:E,connectionUrl:w,registryItems:u}));return}f==="NPX"&&A(on({uiType:"NPX",npxPackage:w}))},v=V=>{V||h.reset(),e(V)},x=async V=>{let w,k=null,T=null,I=null;V.ui_type==="NPX"?(w="STDIO",k="",I=r_(V.npx_package||"",V.env_vars||[])):V.ui_type==="STDIO"?(w="STDIO",k="",I=n_(V.stdio_command||"",V.stdio_args||"",V.stdio_cwd,V.env_vars||[])):(w=V.ui_type,k=V.connection_url||"",T=V.connection_token||null);const A=hu("conn");try{await l.create.mutateAsync({id:A,title:V.title,description:V.description||null,connection_type:w,connection_url:k,connection_token:T,created_at:new Date().toISOString(),updated_at:new Date().toISOString(),created_by:n?.user?.id||"system",organization_id:i.id,icon:V.icon??null,app_name:null,app_id:null,connection_headers:I,oauth_config:null,configuration_state:null,metadata:null,tools:null,bindings:null,status:"inactive"}),h.reset(),e(!1),s?.(A)}catch{pe.error("Failed to create connection")}},b="Create Connection",y="Create a custom connection in your organization. Fill in the details below.",C=h.formState.isSubmitting?"Saving...":"Create Connection",j=r.jsxs("div",{className:"grid gap-4",children:[r.jsx(It,{control:h.control,name:"ui_type",render:({field:V})=>r.jsxs(Rt,{children:[r.jsx(rs,{children:"Type *"}),r.jsxs(Qs,{value:V.value,onValueChange:V.onChange,children:[r.jsx(Tt,{children:r.jsx(Zs,{children:r.jsx(ei,{})})}),r.jsxs(Js,{children:[r.jsx(Ht,{value:"HTTP",children:r.jsxs("span",{className:"flex items-center gap-2",children:[r.jsx(Ti,{className:"w-4 h-4"}),"HTTP"]})}),r.jsx(Ht,{value:"SSE",children:r.jsxs("span",{className:"flex items-center gap-2",children:[r.jsx(Ti,{className:"w-4 h-4"}),"SSE"]})}),r.jsx(Ht,{value:"Websocket",children:r.jsxs("span",{className:"flex items-center gap-2",children:[r.jsx(Ti,{className:"w-4 h-4"}),"Websocket"]})}),o&&r.jsxs(r.Fragment,{children:[r.jsx(Ht,{value:"NPX",children:r.jsxs("span",{className:"flex items-center gap-2",children:[r.jsx(Vn,{className:"w-4 h-4"}),"NPX Package"]})}),r.jsx(Ht,{value:"STDIO",children:r.jsxs("span",{className:"flex items-center gap-2",children:[r.jsx(fl,{className:"w-4 h-4"}),"Custom Command"]})})]})]})]}),r.jsx(Dt,{})]})}),f==="NPX"&&r.jsx(It,{control:h.control,name:"npx_package",render:({field:V})=>r.jsxs(Rt,{children:[r.jsx(rs,{children:"NPM Package *"}),r.jsx(Tt,{children:r.jsx(bt,{placeholder:"@perplexity-ai/mcp-server",...V,value:V.value??"",onPaste:w=>{const k=w.clipboardData.getData("text");k&&(w.preventDefault(),h.setValue("npx_package",k.trim(),{shouldDirty:!0}),_(k))},onBlur:w=>{_(w.target.value),V.onBlur()}})}),r.jsx(Dt,{})]})}),f==="STDIO"&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"grid grid-cols-2 gap-4 items-start",children:[r.jsx(It,{control:h.control,name:"stdio_command",render:({field:V})=>r.jsxs(Rt,{children:[r.jsx(rs,{children:"Command *"}),r.jsx(Tt,{children:r.jsx(bt,{placeholder:"node, bun, python...",...V,value:V.value??""})}),r.jsx(Dt,{})]})}),r.jsx(It,{control:h.control,name:"stdio_args",render:({field:V})=>r.jsxs(Rt,{children:[r.jsx(rs,{children:"Arguments"}),r.jsx(Tt,{children:r.jsx(bt,{placeholder:"arg1 arg2 --flag value",...V,value:V.value??""})}),r.jsx(Dt,{})]})})]}),r.jsx(It,{control:h.control,name:"stdio_cwd",render:({field:V})=>r.jsxs(Rt,{children:[r.jsx(rs,{children:"Working Directory"}),r.jsx(Tt,{children:r.jsx(bt,{placeholder:"/path/to/project (optional)",...V,value:V.value??""})}),r.jsx("p",{className:"text-xs text-muted-foreground",children:"Directory where the command will be executed"}),r.jsx(Dt,{})]})})]}),(f==="NPX"||f==="STDIO")&&r.jsx(It,{control:h.control,name:"env_vars",render:({field:V})=>r.jsxs(Rt,{children:[r.jsx(rs,{children:"Environment Variables"}),r.jsx(Tt,{children:r.jsx(s_,{value:V.value??[],onChange:V.onChange})}),r.jsx(Dt,{})]})}),f!=="NPX"&&f!=="STDIO"&&r.jsxs(r.Fragment,{children:[r.jsx(It,{control:h.control,name:"connection_url",render:({field:V})=>r.jsxs(Rt,{children:[r.jsx(rs,{children:"URL *"}),r.jsx(Tt,{children:r.jsx(bt,{placeholder:"https://example.com/mcp",...V,value:V.value??"",onPaste:w=>{const k=w.clipboardData.getData("text");k&&(w.preventDefault(),h.setValue("connection_url",k.trim(),{shouldDirty:!0}),_(k))},onBlur:w=>{_(w.target.value),V.onBlur()}})}),r.jsx(Dt,{})]})}),r.jsx(It,{control:h.control,name:"connection_token",render:({field:V})=>r.jsxs(Rt,{children:[r.jsx(rs,{children:g?.token?.label??"Token (optional)"}),r.jsx(Tt,{children:r.jsx(bt,{type:"password",placeholder:g?.token?.placeholder??"Bearer token or API key",className:"ph-no-capture",...V,value:V.value??""})}),g?.token?.helperText&&r.jsxs("p",{className:"text-xs text-muted-foreground",children:[g.token.helperText,g.id==="github"&&r.jsxs(r.Fragment,{children:[" ","·"," ",r.jsx("a",{className:"text-foreground underline underline-offset-4 hover:text-foreground/80",href:"https://github.com/settings/personal-access-tokens",target:"_blank",rel:"noreferrer",children:"Open GitHub PAT settings"})]})]}),r.jsx(Dt,{})]})})]}),r.jsx(It,{control:h.control,name:"title",render:({field:V})=>r.jsxs(Rt,{children:[r.jsx(rs,{children:"Name *"}),r.jsx(Tt,{children:r.jsx(bt,{placeholder:"My Connection",...V})}),r.jsx(Dt,{})]})}),r.jsx(It,{control:h.control,name:"description",render:({field:V})=>r.jsxs(Rt,{children:[r.jsx(rs,{children:"Description"}),r.jsx(Tt,{children:r.jsx(ca,{placeholder:"A brief description of this connection",rows:3,...V,value:V.value??""})}),r.jsx(Dt,{})]})})]});return a?r.jsx(Si,{open:t,onOpenChange:v,children:r.jsxs(yi,{className:"max-h-[90vh]",children:[r.jsx(so,{className:"pb-2",children:r.jsxs("div",{className:"flex items-start justify-between gap-4",children:[r.jsxs("div",{className:"flex-1 text-left",children:[r.jsx(bi,{children:b}),r.jsx(ng,{className:"mt-1",children:y})]}),r.jsx(og,{asChild:!0,children:r.jsx(ne,{variant:"ghost",size:"icon",className:"shrink-0 -mt-1",children:r.jsx(ii,{size:16})})})]})}),r.jsx(Pi,{...h,children:r.jsxs("form",{onSubmit:h.handleSubmit(x),children:[r.jsx("div",{className:"overflow-y-auto px-4 pb-4",children:j}),r.jsx(ag,{children:r.jsx(ne,{type:"submit",disabled:h.formState.isSubmitting,className:"w-full",children:C})})]})})]})}):r.jsx(ps,{open:t,onOpenChange:v,children:r.jsxs(ms,{className:"sm:max-w-[525px]",children:[r.jsxs(Ds,{children:[r.jsx(Ts,{children:b}),r.jsx(dl,{children:y})]}),r.jsx(Pi,{...h,children:r.jsxs("form",{onSubmit:h.handleSubmit(x),children:[r.jsx("div",{className:"py-4",children:j}),r.jsxs(cl,{children:[r.jsx(ne,{type:"button",variant:"outline",onClick:()=>v(!1),children:"Cancel"}),r.jsx(ne,{type:"submit",disabled:h.formState.isSubmitting,className:"min-w-40",children:C})]})]})})]})})}function hv(t){const e=B.c(79),{mode:s,agentId:i,addedConnectionIds:n,onAdd:o,onCloneAndAdd:a,onConnectAndAdd:l,connectingItemId:c,search:d,onCreateConnection:u,onBrowseNavigate:h,defaultTab:f}=t,m=s===void 0?"add":s,p=f===void 0?"connected":f,{org:g}=be(),_=S.useDeferredValue(d),v=d!==_;let x;e[0]!==_?(x=_.toLowerCase(),e[0]=_,e[1]=x):x=e[1];const b=x;let y;e[2]!==p?(y=ge=>ge??p,e[2]=p,e[3]=y):y=e[3];const[C,j]=nl(ol.connectionsTab(g.slug)+(p==="all"?":home-modal":":agent-modal"),y);let V;e[4]!==C||e[5]!==j?(V=ge=>{ge!==C&&se("connections_dialog_tab_changed",{to_tab:ge}),j(ge)},e[4]=C,e[5]=j,e[6]=V):V=e[6];const w=V;let k;e[7]!==g.id?(k={connectionId:Wt,orgId:g.id},e[7]=g.id,e[8]=k):k=e[8];const T=Me(k);let I,A,N;if(e[9]!==T||e[10]!==_||e[11]!==g.id){N=_?.trim()?{operator:"or",conditions:[{field:["title"],operator:"contains",value:_.trim()},{field:["description"],operator:"contains",value:_.trim()}]}:void 0;const ge={...N&&{where:N},orderBy:[{field:["updated_at"],direction:"asc"}],limit:100,offset:0},ke=JSON.stringify(ge);A=o_,I=lt.collectionListInfinite(T,g.id,"","CONNECTIONS",ke),e[9]=T,e[10]=_,e[11]=g.id,e[12]=I,e[13]=A,e[14]=N}else I=e[12],A=e[13],N=e[14];let E;e[15]!==T||e[16]!==N?(E=async ge=>{const{pageParam:ke}=ge,Qe=ke===void 0?0:ke;return(await T.callTool({name:"COLLECTION_CONNECTIONS_LIST",arguments:{...N&&{where:N},orderBy:[{field:["updated_at"],direction:"asc"}],limit:100,offset:Qe}})).structuredContent},e[15]=T,e[16]=N,e[17]=E):E=e[17];let R;e[18]!==I||e[19]!==E?(R={queryKey:I,queryFn:E,initialPageParam:0,getNextPageParam:_v,staleTime:3e4},e[18]=I,e[19]=E,e[20]=R):R=e[20];const{data:M,fetchNextPage:L,hasNextPage:D,isFetchingNextPage:P}=A(R),O=M?.pages.flatMap(gv)??[],z=e_(O),$=new Set(O.filter(pv).map(mv)),W=lu(),F=cu(W,_),G=bc(F.loadMore,F.hasMore,F.isLoadingMore),q=bc(L,D??!1,P),H=C==="all"||!!b,ee=H?F.items.filter(ge=>{const ke=u_(ge);return!(ke&&$.has(ke))}):[],K=ee.filter(fv),U=ee.filter(uv);let te;e[21]!==n?(te=ge=>ge.some(ke=>n.has(ke.id)),e[21]=n,e[22]=te):te=e[22];const Y=te;let J;e[23]!==n||e[24]!==i||e[25]!==c||e[26]!==Y||e[27]!==m||e[28]!==o||e[29]!==h||e[30]!==a?(J=(ge,ke,Qe,Ct,Pe)=>{const Kt=Y(Pe),jt=Pe.find(Ie=>!n.has(Ie.id)),Ae=Pe[0];if(m==="browse"){const Ie=ou(Ae);return r.jsx(jo,{connection:{title:ke,icon:Qe,description:Pe.length>1?`${Pe.length} instances`:Ct??void 0},fallbackIcon:r.jsx(Vn,{}),headerActionsAlwaysVisible:!0,headerActions:r.jsxs(wc,{variant:"secondary",className:"text-xs gap-1 font-normal",children:[r.jsx(Jt,{size:11})," Connected"]}),onClick:()=>{se("connection_browse_clicked",{app_name:Ae.app_name??null,connection_id:Ae.id,instances_count:Pe.length}),h?.(Ie)}},ge)}return r.jsx(jo,{connection:{title:ke,icon:Qe,description:Ct},fallbackIcon:r.jsx(Vn,{}),headerActionsAlwaysVisible:!0,headerActions:r.jsxs("div",{className:"flex items-center gap-1.5",children:[Kt&&r.jsxs(wc,{variant:"secondary",className:"text-xs gap-1 font-normal",children:[r.jsx(Jt,{size:11})," Added"]}),r.jsx(ne,{variant:"outline",size:"sm",className:"h-7 px-3 text-xs font-medium",disabled:c!==null,onClick:Ie=>{Ie.stopPropagation(),jt?(se("connection_add_clicked",{action:"use_existing",app_name:Ae.app_name??null,connection_id:jt.id}),i&&se("agent_connection_attached",{agent_id:i,connection_id:jt.id,app_name:Ae.app_name??null,mode:"existing"}),o(jt.id)):(se("connection_add_clicked",{action:"clone",app_name:Ae.app_name??null,base_connection_id:Ae.id}),a(Ae))},children:"Add"})]})},ge)},e[23]=n,e[24]=i,e[25]=c,e[26]=Y,e[27]=m,e[28]=o,e[29]=h,e[30]=a,e[31]=J):J=e[31];const ie=J;let ue;e[32]!==c||e[33]!==m||e[34]!==l?(ue=ge=>{const ke=ge._meta?.["mcp.mesh"],Qe=ke?.friendlyName||ke?.friendly_name||ge.server?.title||ge.title||ge.server?.name||ge.name||ge.id||"",Ct=ge.server?.description||ge.description||null,Pe=ge.server?.icons?.[0]?.src||m_(ge.server?.repository)||null;return r.jsx(jo,{connection:{title:Qe,description:Ct,icon:Pe},fallbackIcon:r.jsx(Vn,{}),headerActionsAlwaysVisible:!0,headerActions:r.jsx(ne,{variant:"outline",size:"sm",className:"h-7 px-3 text-xs font-medium",disabled:c!==null,onClick:Kt=>{Kt.stopPropagation(),se("connection_add_clicked",{action:"connect_new",registry_item_id:ge.id,app_name:ge._meta?.["mcp.mesh"]?.friendlyName||ge.server?.name||ge.name||null}),l(ge)},children:c===ge.id?r.jsx(Ee,{size:14,className:"animate-spin"}):m==="browse"?"Connect":"Add"})},`catalog-${ge.id}`)},e[32]=c,e[33]=m,e[34]=l,e[35]=ue):ue=e[35];const de=ue;let xe;e[36]!==C||e[37]!==w||e[38]!==u||e[39]!==b?(xe=!b&&r.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-border shrink-0",children:[r.jsx(du,{tabs:[{id:"all",label:"All"},{id:"connected",label:"Connected"}],activeTab:C,onTabChange:ge=>w(ge)}),r.jsxs(ne,{variant:"outline",size:"sm",className:"h-7 px-2 text-sm",onClick:()=>{se("connections_dialog_custom_clicked"),u()},children:[r.jsx(Qt,{size:12}),"Custom Connection"]})]}),e[36]=C,e[37]=w,e[38]=u,e[39]=b,e[40]=xe):xe=e[40];const oe=v&&"opacity-50 pointer-events-none";let he;e[41]!==oe?(he=X("flex-1 overflow-auto p-5 transition-opacity duration-150",oe),e[41]=oe,e[42]=he):he=e[42];const me="grid grid-cols-[repeat(auto-fill,minmax(260px,1fr))] gap-4";let fe;e[43]!==ie?(fe=ge=>{if(ge.type==="group")return ie(ge.key,ge.title,ge.icon,null,ge.connections);const ke=ge.connection;return ie(ke.id,ke.title,ke.icon,ke.description??null,[ke])},e[43]=ie,e[44]=fe):fe=e[44];const le=z.map(fe);let ve;e[45]!==q?(ve=r.jsx("div",{ref:q,className:"col-span-full h-1"}),e[45]=q,e[46]=ve):ve=e[46];let Ce;e[47]!==P?(Ce=P&&r.jsx("div",{className:"col-span-full flex justify-center py-6",children:r.jsx(Ee,{size:24,className:"animate-spin text-muted-foreground"})}),e[47]=P,e[48]=Ce):Ce=e[48];const Te=H&&K.length>0&&r.jsxs("div",{className:"col-span-full flex items-center gap-2 mt-2",children:[r.jsx(Bg,{size:13,className:"text-muted-foreground shrink-0"}),r.jsx("span",{className:"text-sm font-medium text-muted-foreground whitespace-nowrap",children:"Verified"}),r.jsx("div",{className:"flex-1 h-px bg-border"})]}),Q=H&&K.map(de),ae=H&&U.length>0&&r.jsxs("div",{className:"col-span-full flex items-center gap-2 mt-2",children:[r.jsx("span",{className:"text-sm font-medium text-muted-foreground whitespace-nowrap",children:"All connections"}),r.jsx("div",{className:"flex-1 h-px bg-border"})]}),Se=H&&U.map(de);let Ne;e[49]!==G||e[50]!==W||e[51]!==H?(Ne=H&&W.length>0&&r.jsx("div",{ref:G,className:"col-span-full h-1"}),e[49]=G,e[50]=W,e[51]=H,e[52]=Ne):Ne=e[52];let Be;e[53]!==F.isLoadingMore||e[54]!==H?(Be=H&&F.isLoadingMore&&r.jsx("div",{className:"col-span-full flex justify-center py-6",children:r.jsx(Ee,{size:24,className:"animate-spin text-muted-foreground"})}),e[53]=F.isLoadingMore,e[54]=H,e[55]=Be):Be=e[55];let Oe;e[56]!==le||e[57]!==ve||e[58]!==Ce||e[59]!==Te||e[60]!==Q||e[61]!==ae||e[62]!==Se||e[63]!==Ne||e[64]!==Be?(Oe=r.jsxs("div",{className:me,children:[le,ve,Ce,Te,Q,ae,Se,Ne,Be]}),e[56]=le,e[57]=ve,e[58]=Ce,e[59]=Te,e[60]=Q,e[61]=ae,e[62]=Se,e[63]=Ne,e[64]=Be,e[65]=Oe):Oe=e[65];let He;e[66]!==C||e[67]!==z.length||e[68]!==U||e[69]!==d||e[70]!==K?(He=z.length===0&&K.length===0&&U.length===0&&r.jsx("div",{className:"flex items-center justify-center h-48 text-sm text-muted-foreground",children:d?`No connections match "${d}"`:C==="connected"?"No connections yet":"No connections available"}),e[66]=C,e[67]=z.length,e[68]=U,e[69]=d,e[70]=K,e[71]=He):He=e[71];let Je;e[72]!==he||e[73]!==Oe||e[74]!==He?(Je=r.jsxs("div",{className:he,children:[Oe,He]}),e[72]=he,e[73]=Oe,e[74]=He,e[75]=Je):Je=e[75];let dt;return e[76]!==xe||e[77]!==Je?(dt=r.jsxs(r.Fragment,{children:[xe,Je]}),e[76]=xe,e[77]=Je,e[78]=dt):dt=e[78],dt}function uv(t){return!t.verified&&!t._meta?.["mcp.mesh"]?.verified&&!t.meta?.verified}function fv(t){return t.verified||t._meta?.["mcp.mesh"]?.verified||t.meta?.verified}function mv(t){return t.app_name}function pv(t){return t.app_name}function gv(t){return t?.items??[]}function _v(t,e){if(t?.hasMore)return e.reduce(xv,0)}function xv(t,e){return t+(e?.items?.length??0)}function Pl({open:t,onOpenChange:e,defaultTab:s,initialSearch:i="",...n}){const o=n.mode??"add",a="agentId"in n?n.agentId:void 0,l="addedConnectionIds"in n?n.addedConnectionIds??new Set:new Set,c="onAdd"in n&&n.onAdd?n.onAdd:w=>{},d=(w,k,T)=>{a&&se("agent_connection_attached",{agent_id:a,connection_id:w,app_name:k,mode:T})},[u,h]=S.useState(null),[f,m]=S.useState(i),[p,g]=S.useState(!1),{org:_}=be(),{data:v}=St.useSession(),x=Sl(),b=Mt(),y=Ke(),C=w=>{e(!1),y({to:"/$org/settings/connections/$appSlug",params:{org:_.slug,appSlug:w}})},j=async w=>{h(w.app_name??w.id);try{const T=`${w.title.replace(/\s*\(\d+\)\s*$/,"")} (${Date.now().toString(36).slice(-4)})`,A=(await x.create.mutateAsync({title:T,description:w.description??null,connection_type:w.connection_type,connection_url:w.connection_url??null,connection_token:null,icon:w.icon??null,app_name:w.app_name??null,app_id:w.app_id??null,connection_headers:w.connection_headers??null})).id,N=new URL(`/mcp/${A}`,window.location.origin),E=await pr({url:N.href,token:null});if(E.supportsOAuth&&!E.isAuthenticated){const{token:R,tokenInfo:M,error:L}=await vn({connectionId:A,scope:"offline_access"});if(L||!R){se("connection_oauth_failed",{connection_id:A,flow:"clone",error:L??"no_token"}),pe.error(`Authentication failed: ${L??"no token received"}`),await x.delete.mutateAsync(A);return}if(se("connection_oauth_succeeded",{connection_id:A,flow:"clone"}),M)try{(await fetch(`/api/connections/${A}/oauth-token`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({accessToken:M.accessToken,refreshToken:M.refreshToken,expiresIn:M.expiresIn,scope:M.scope,clientId:M.clientId,clientSecret:M.clientSecret,tokenEndpoint:M.tokenEndpoint})})).ok?await x.update.mutateAsync({id:A,data:{}}):await x.update.mutateAsync({id:A,data:{connection_token:R}})}catch{await x.update.mutateAsync({id:A,data:{connection_token:R}})}else await x.update.mutateAsync({id:A,data:{connection_token:R}});await b.invalidateQueries({queryKey:lt.isMCPAuthenticated(N.href,null)})}d(A,w.app_name??null,"clone"),c(A)}catch(k){console.error("Failed to add connection:",k),pe.error("Failed to add connection")}finally{h(null)}},V=async w=>{if(!(!_||!v?.user?.id)){h(w.id);try{const k=f_(w,_.id,v.user.id,{remoteIndex:0}),T=k.connection_type==="STDIO",I=!!k.connection_url,A=T&&k.connection_headers&&typeof k.connection_headers=="object"&&"command"in k.connection_headers;if(!I&&!A){pe.error("This MCP Server cannot be connected: no connection method available"),h(null);return}const{id:N}=await x.create.mutateAsync(k),E=new URL(`/mcp/${N}`,window.location.origin),R=await pr({url:E.href,token:null});if(R.supportsOAuth&&!R.isAuthenticated){const{token:M,tokenInfo:L,error:D}=await vn({connectionId:N,scope:"offline_access"});if(D||!M){se("connection_oauth_failed",{connection_id:N,flow:"connect_new",error:D??"no_token"}),pe.error(`Authentication failed: ${D??"no token received"}`),d(N,k.app_name??null,"new"),c(N);return}if(se("connection_oauth_succeeded",{connection_id:N,flow:"connect_new"}),L)try{(await fetch(`/api/connections/${N}/oauth-token`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({accessToken:L.accessToken,refreshToken:L.refreshToken,expiresIn:L.expiresIn,scope:L.scope,clientId:L.clientId,clientSecret:L.clientSecret,tokenEndpoint:L.tokenEndpoint})})).ok?await x.update.mutateAsync({id:N,data:{}}):await x.update.mutateAsync({id:N,data:{connection_token:M}})}catch{await x.update.mutateAsync({id:N,data:{connection_token:M}})}else await x.update.mutateAsync({id:N,data:{connection_token:M}});await b.invalidateQueries({queryKey:lt.isMCPAuthenticated(E.href,null)}),pe.success("Connected and authenticated")}else pe.success("Connected");d(N,k.app_name??null,"new"),c(N)}catch(k){console.error("Failed to connect:",k),pe.error("Failed to connect")}finally{h(null)}}};return r.jsxs(ps,{open:t,onOpenChange:e,children:[r.jsxs(ms,{className:"sm:max-w-5xl h-[85vh] max-h-[85vh] flex flex-col p-0 gap-0 overflow-hidden w-[95vw]",children:[r.jsx(Ds,{className:"px-6 pt-5 pb-0 shrink-0",children:r.jsx(Ts,{className:"text-base font-semibold",children:o==="browse"?"Connections":"Add Connection"})}),r.jsx("div",{className:"pt-3 shrink-0",children:r.jsx(Th,{value:f,onChange:m,placeholder:"Search connections..."})}),r.jsx(S.Suspense,{fallback:r.jsx("div",{className:"flex-1 flex items-center justify-center",children:r.jsx(Ee,{size:24,className:"animate-spin text-muted-foreground"})}),children:r.jsx(hv,{mode:o,agentId:a,addedConnectionIds:l,onAdd:c,onCloneAndAdd:j,onConnectAndAdd:V,connectingItemId:u,search:f,onCreateConnection:()=>g(!0),onBrowseNavigate:C,defaultTab:s})})]}),r.jsx(dv,{open:p,onOpenChange:g,onCreated:async w=>{g(!1);const k=new URL(`/mcp/${w}`,window.location.origin),T=await pr({url:k.href,token:null});if(T.supportsOAuth&&!T.isAuthenticated){const{token:I,tokenInfo:A,error:N}=await vn({connectionId:w,scope:"offline_access"});if(N||!I){se("connection_oauth_failed",{connection_id:w,flow:"custom_create",error:N??"no_token"}),pe.error(`Authentication failed: ${N??"no token received"}`),await x.delete.mutateAsync(w);return}if(se("connection_oauth_succeeded",{connection_id:w,flow:"custom_create"}),A)try{(await fetch(`/api/connections/${w}/oauth-token`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({accessToken:A.accessToken,refreshToken:A.refreshToken,expiresIn:A.expiresIn,scope:A.scope,clientId:A.clientId,clientSecret:A.clientSecret,tokenEndpoint:A.tokenEndpoint})})).ok?await x.update.mutateAsync({id:w,data:{}}):await x.update.mutateAsync({id:w,data:{connection_token:I}})}catch{await x.update.mutateAsync({id:w,data:{connection_token:I}})}else await x.update.mutateAsync({id:w,data:{connection_token:I}});await b.invalidateQueries({queryKey:lt.isMCPAuthenticated(k.href,null)})}d(w,null,"custom"),c(w),e(!1)}})]})}const vv=[{src:"/connections/github.png",name:"GitHub"},{src:"/connections/gmail.png",name:"Gmail"},{src:"/connections/linear.png",name:"Linear"},{src:"/connections/shopify.png",name:"Shopify"},{src:"/connections/firecrawl.png",name:"Firecrawl"},{src:"/connections/perplexity.png",name:"Perplexity"}];function bv(){const t=B.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=r.jsx("div",{className:"flex items-center -space-x-1",children:vv.map(yv)}),t[0]=e):e=t[0],e}function yv(t){return r.jsx("img",{src:t.src,alt:t.name,className:"size-5 rounded-sm ring-2 ring-muted object-cover bg-white"},t.name)}function Sv(t){const e=B.c(6),{onClick:s}=t;let i,n,o,a;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=X("group relative z-10 flex items-center gap-3 w-full px-4 py-3","rounded-b-2xl","cursor-pointer"),n=r.jsx("p",{className:"flex-1 text-xs text-muted-foreground truncate text-left",children:"Connect tools and get more done"}),o=r.jsx(bv,{}),a=r.jsx(Vl,{size:14,className:"shrink-0 text-muted-foreground/60 group-hover:text-muted-foreground transition-colors"}),e[0]=i,e[1]=n,e[2]=o,e[3]=a):(i=e[0],n=e[1],o=e[2],a=e[3]);let l;return e[4]!==s?(l=r.jsxs("button",{type:"button",onClick:s,className:i,children:[n,o,a]}),e[4]=s,e[5]=l):l=e[5],l}const cr=48;function wv(){const t=B.c(9),[e,s]=S.useState("idle"),[i,n]=S.useState(""),[o,a]=S.useState(""),[l,c]=S.useState(jv),d=S.useRef(null),u=S.useRef(null),h=S.useRef(null),f=S.useRef(null),m=S.useRef(0),p=S.useRef(!1),g=S.useRef(""),_=S.useRef(""),v=typeof window<"u"&&!!(window.SpeechRecognition||window.webkitSpeechRecognition);let x;t[0]===Symbol.for("react.memo_cache_sentinel")?(x=()=>{m.current&&(cancelAnimationFrame(m.current),m.current=0),u.current?.close().catch(Cv),f.current?.getTracks().forEach(Vv),h.current=null,u.current=null,f.current=null},t[0]=x):x=t[0];const b=x;let y;if(t[1]===Symbol.for("react.memo_cache_sentinel")){const I=A=>{f.current=A;const N=new AudioContext;u.current=N;const E=N.createMediaStreamSource(A),R=N.createAnalyser();R.fftSize=128,R.smoothingTimeConstant=.8,E.connect(R),h.current=R;const M=new Uint8Array(R.frequencyBinCount),L=()=>{if(!h.current)return;h.current.getByteFrequencyData(M);const D=[];for(let P=0;P<cr;P++){const O=Math.floor(P/cr*M.length);D.push(Math.max(.04,(M[O]??0)/255))}c(D),m.current=requestAnimationFrame(L)};L()};y=async()=>{const A=window.SpeechRecognition||window.webkitSpeechRecognition;if(!A){s("unsupported");return}let N;try{N=await navigator.mediaDevices.getUserMedia({audio:!0})}catch{s("permission-denied");return}n(""),a(""),_.current="",g.current="",p.current=!0,s("recording"),I(N);const E=new A;d.current=E,E.interimResults=!0,E.continuous=!0,E.lang=navigator.language||"en-US",E.onresult=R=>{let M="",L="";for(let D=R.resultIndex;D<R.results.length;D++){const P=R.results[D],O=P?.[0]?.transcript??"";P?.isFinal?L=L+O:M=M+O}L&&(g.current=g.current+L,n(g.current)),_.current=M,a(M)},E.onend=()=>{if(p.current)try{E.start()}catch{}};try{E.start()}catch{s("idle")}},t[1]=y}else y=t[1];const C=y;let j;t[2]===Symbol.for("react.memo_cache_sentinel")?(j=()=>{p.current=!1,d.current?.stop(),b(),s("idle"),c(Array(cr).fill(.05)),a("");const I=(g.current+(_.current?" "+_.current:"")).trim();return n(""),g.current="",_.current="",I},t[2]=j):j=t[2];const V=j;let w;t[3]===Symbol.for("react.memo_cache_sentinel")?(w=()=>{p.current=!1,d.current?.abort(),b(),s("idle"),n(""),a(""),c(Array(cr).fill(.05)),g.current="",_.current=""},t[3]=w):w=t[3];const k=w;let T;return t[4]!==o||t[5]!==e||t[6]!==i||t[7]!==l?(T={status:e,transcript:i,interimTranscript:o,waveformData:l,isSupported:v,startRecording:C,stopRecording:V,cancelRecording:k},t[4]=o,t[5]=e,t[6]=i,t[7]=l,t[8]=T):T=t[8],T}function Vv(t){return t.stop()}function Cv(){}function jv(){return Array(cr).fill(.05)}function kv(t){const e=B.c(4),{data:s}=t;let i;e[0]!==s?(i=s.map(Nv),e[0]=s,e[1]=i):i=e[1];let n;return e[2]!==i?(n=r.jsx("div",{className:"flex items-center justify-center gap-[2px] h-10 overflow-hidden","aria-hidden":"true",children:i}),e[2]=i,e[3]=n):n=e[3],n}function Nv(t,e){return r.jsx("div",{className:"w-[2px] shrink-0 rounded-full bg-chart-2 transition-[height] duration-75 ease-out",style:{height:`${Math.max(4,Math.round(t*40))}px`}},e)}const Io=[{value:"fast",label:"Fast",Icon:Hh,description:"Quicker responses"},{value:"smart",label:"Smart",Icon:_l,description:"Balanced quality"},{value:"thinking",label:"Thinking",Icon:gg,description:"Deeper reasoning"}];function Av(t){const e=B.c(17),{tier:s,onSelect:i}=t;let n;e[0]!==s?(n=Io.find(m=>m.value===s)??Io[1],e[0]=s,e[1]=n):n=e[1];const o=n,a=o.Icon;let l;e[2]!==a?(l=r.jsx(a,{size:14}),e[2]=a,e[3]=l):l=e[3];let c;e[4]!==o.label?(c=r.jsx("span",{className:"hidden sm:inline",children:o.label}),e[4]=o.label,e[5]=c):c=e[5];let d;e[6]!==l||e[7]!==c?(d=r.jsx(ks,{asChild:!0,children:r.jsxs(ne,{type:"button",variant:"ghost",size:"default",className:"text-muted-foreground hover:text-foreground",children:[l,c]})}),e[6]=l,e[7]=c,e[8]=d):d=e[8];let u;e[9]!==i||e[10]!==s?(u=Io.map(m=>{const{value:p,label:g,Icon:_,description:v}=m;return r.jsxs(ot,{onSelect:()=>i(p),children:[r.jsx(_,{size:16,className:"text-muted-foreground"}),r.jsxs("div",{className:"flex flex-col gap-0.5 flex-1",children:[r.jsx("span",{children:g}),r.jsx("span",{className:"text-xs text-muted-foreground font-normal",children:v})]}),s===p&&r.jsx("span",{className:"text-xs text-muted-foreground font-medium",children:"On"})]},p)}),e[9]=i,e[10]=s,e[11]=u):u=e[11];let h;e[12]!==u?(h=r.jsx(Ns,{align:"end",className:"w-52 p-1.5",children:u}),e[12]=u,e[13]=h):h=e[13];let f;return e[14]!==d||e[15]!==h?(f=r.jsxs(js,{children:[d,h]}),e[14]=d,e[15]=h,e[16]=f):f=e[16],f}function Ev(t){const e=B.c(4),{editor:s}=to(),[i,n]=S.useState(!1),o=S.useRef(0);let a,l;return e[0]!==s||e[1]!==t?(a=()=>{const c=f=>{f.dataTransfer?.types.includes("Files")&&(f.preventDefault(),o.current=o.current+1,n(!0))},d=f=>{f.preventDefault(),o.current=Math.max(0,o.current-1),o.current===0&&n(!1)},u=Iv,h=f=>{if(f.preventDefault(),o.current=0,n(!1),!s||!t||!no(t))return;const m=f.dataTransfer?.files;if(!m||m.length===0)return;const{from:p}=s.state.selection;for(const g of Array.from(m))Tl(s,t,g,p)};return window.addEventListener("dragenter",c),window.addEventListener("dragleave",d),window.addEventListener("dragover",u),window.addEventListener("drop",h),()=>{window.removeEventListener("dragenter",c),window.removeEventListener("dragleave",d),window.removeEventListener("dragover",u),window.removeEventListener("drop",h)}},l=[s,t],e[0]=s,e[1]=t,e[2]=a,e[3]=l):(a=e[2],l=e[3]),S.useEffect(a,l),i}function Iv(t){t.dataTransfer?.types.includes("Files")&&t.preventDefault()}function Rv(t){const e=B.c(11),{selectedModel:s}=t,i=Ev(s);let n;e[0]!==s?(n=no(s),e[0]=s,e[1]=n):n=e[1];const o=n,a=i?"opacity-100":"opacity-0 pointer-events-none",l=o?"border-primary/40 text-primary/70":"border-destructive/30 text-destructive/70";let c;e[2]!==a||e[3]!==l?(c=X("absolute inset-0 z-20 rounded-xl flex flex-col items-center justify-center gap-2 bg-muted border-2 border-dashed transition-opacity",a,l),e[2]=a,e[3]=l,e[4]=c):c=e[4];let d;e[5]!==s||e[6]!==o?(d=o?r.jsxs(r.Fragment,{children:[r.jsx(Qh,{size:24}),r.jsxs("span",{className:"text-sm font-medium",children:["Drop ",su(s)," here"]})]}):r.jsxs(r.Fragment,{children:[r.jsx(Jh,{size:24}),r.jsx("span",{className:"text-sm font-medium",children:"This model can't read attachments — switch to one with vision or file support"})]}),e[5]=s,e[6]=o,e[7]=d):d=e[7];let u;return e[8]!==c||e[9]!==d?(u=r.jsx("div",{className:c,children:d}),e[8]=c,e[9]=d,e[10]=u):u=e[10],u}function Tv({onOpenContextPanel:t,showConnectionsBanner:e=!1}){const{messages:s,isStreaming:i,isRunInProgress:n,sendMessage:o,stop:a}=Ui(),{taskId:l,tasks:c}=es(),{selectedModel:d,selectedVirtualMcp:u,isModelsLoading:h,tiptapDocRef:f,imageModel:m,deepResearchModel:p,chatMode:g,setChatMode:_,simpleModeEnabled:v,simpleModeTier:x,setSimpleModeTier:b}=ni(),{data:y}=St.useSession(),C=y?.user?.id,{org:j}=be(),V=io(j.id).id,w=pa(_c),[k,T]=S.useState(!1),I=wv(),A=S.useRef(void 0),N=async()=>{A.current=L,await I.startRecording();const Y=I.status==="recording"?"started":I.status==="unsupported"?"unsupported":I.status==="permission-denied"?"permission_denied":"unknown";se("chat_voice_started",{thread_id:l,outcome:Y})},E=()=>{se("chat_voice_confirmed",{thread_id:l});const Y=I.stopRecording();W.current?.syncVoiceText(A.current,Y),W.current?.focus()},R=()=>{se("chat_voice_cancelled",{thread_id:l}),I.cancelRecording(),W.current?.restoreContent(A.current)};S.useEffect(()=>{if(I.status!=="recording")return;const Y=(I.transcript+(I.interimTranscript?" "+I.interimTranscript:"")).trim();W.current?.syncVoiceText(A.current,Y)},[I.transcript,I.interimTranscript,I.status]);const M=c.find(Y=>Y.id===l),[L,D]=S.useState(void 0),P=Y=>{D(Y),f.current=Y},O=S.useRef(l);O.current!==l&&(O.current=l,D(void 0),f.current=void 0);const $=[...s].reverse().find(Y=>Y.role==="assistant")?.metadata?.modelLimits?.contextWindow??d?.limits?.contextWindow,W=S.useRef(null),F=g==="plan";S.useEffect(()=>{const Y=J=>{Ph(J)&&J.code==="KeyL"&&(J.preventDefault(),J.shiftKey&&_(g==="plan"?"default":"plan"),W.current?.focus())};return document.addEventListener("keydown",Y),()=>document.removeEventListener("keydown",Y)},[g,_]);const G=Eh(s),q=[...s].reverse().find(Y=>Y.role==="assistant"&&Y.metadata?.usage)?.metadata?.usage,H=q?.contextTokens??(q?.totalTokens??0)-(q?.reasoningTokens??0),ee=pa(_c),K=!i&&!!d&&!h&&!G_(L),U=i||n,te=Y=>{Y?.preventDefault(),i?(se("chat_message_stopped",{thread_id:l}),a()):n?(se("chat_message_stopped",{thread_id:l}),a()):K&&L&&(se("chat_message_sent",{thread_id:l,mode:g,model_id:d?.modelId??null,model_provider:d?.providerId??null,virtual_mcp_id:u?.id??null,submission:Y?"button_or_enter":"programmatic"}),ee(),o(L),P(void 0))};return C&&M?.created_by&&M.created_by!==C?r.jsxs("div",{className:"flex w-full items-center gap-2 px-3 py-2.5 rounded-xl border border-border bg-muted/40 text-muted-foreground",children:[r.jsx(Jh,{size:14,className:"shrink-0"}),r.jsx("span",{className:"text-sm",children:"Read only — you're viewing someone else's thread"})]}):r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"flex flex-col w-full justify-end",children:r.jsxs("div",{className:"relative rounded-2xl w-full flex flex-col",children:[e&&r.jsx("div",{className:"absolute inset-0 rounded-2xl pointer-events-none bg-muted/50"}),r.jsx(ho,{}),r.jsx(Wu,{tiptapDoc:L,setTiptapDoc:P,disabled:i||!d,enterToSubmit:!0,onSubmit:te,children:r.jsxs("form",{onSubmit:te,className:X("w-full relative rounded-2xl min-h-[110px] md:min-h-[130px] flex flex-col bg-background dark:bg-muted card-shadow"),children:[r.jsx(Rv,{selectedModel:d}),r.jsx("div",{className:"group/input relative flex flex-col gap-2 flex-1",children:r.jsx(Uu,{ref:W,disabled:i||!d||I.status==="recording",virtualMcpId:u?.id??V,showFileUploader:!0,selectedModel:d})}),r.jsx("div",{className:"flex items-center justify-between p-2.5 gap-1",children:I.status==="recording"?r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"flex-1"}),r.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[r.jsx(kv,{data:I.waveformData.slice(0,28)}),r.jsx("button",{type:"button",onClick:R,className:"flex items-center justify-center size-8 rounded-lg hover:bg-muted text-muted-foreground hover:text-foreground transition-colors","aria-label":"Cancel recording",children:r.jsx(fi,{size:16})}),r.jsx("button",{type:"button",onClick:E,className:"flex items-center justify-center size-8 rounded-lg bg-foreground text-background hover:opacity-80 transition-opacity","aria-label":"Use transcription",children:r.jsx(Jt,{size:16})})]})]}):r.jsxs(r.Fragment,{children:[r.jsxs("div",{className:"flex items-center gap-1.5 min-w-0 shrink-0",children:[r.jsx(zx,{selectedModel:d,isStreaming:i,icon:r.jsx(Qt,{size:16})}),r.jsx(av,{disabled:i,onOpenConnections:()=>{se("connections_dialog_opened",{source:"tools_popover",mode:"add"}),T(!0)},virtualMcpId:u?.id??V}),F&&r.jsxs("button",{type:"button",onClick:()=>{w(),se("chat_mode_changed",{from_mode:"plan",to_mode:"default",source:"pill_dismiss"}),_("default")},className:"flex items-center gap-1.5 h-8 rounded-lg px-2.5 text-sm font-medium text-violet-600 dark:text-violet-400 hover:bg-violet-500/10 group whitespace-nowrap animate-in fade-in duration-200",children:[r.jsx(Xh,{size:14,className:"shrink-0"}),"Plan mode",r.jsx(fi,{size:14,className:"shrink-0 hidden group-hover:block"})]}),g==="gen-image"&&m&&r.jsxs("button",{type:"button",onClick:()=>{w(),se("chat_mode_changed",{from_mode:"gen-image",to_mode:"default",source:"pill_dismiss"}),_("default")},className:"flex items-center gap-1.5 h-8 rounded-lg px-2.5 text-sm font-medium text-pink-600 dark:text-pink-400 hover:bg-pink-500/10 group whitespace-nowrap animate-in fade-in duration-200",children:[r.jsx(la,{size:14,className:"shrink-0"}),r.jsx("span",{className:"max-w-[120px] truncate",children:v?"Create image":m.title.includes(": ")?m.title.split(": ").slice(1).join(": "):m.title}),r.jsx(fi,{size:14,className:"shrink-0 hidden group-hover:block"})]}),g==="web-search"&&p&&r.jsxs("button",{type:"button",onClick:()=>{w(),se("chat_mode_changed",{from_mode:"web-search",to_mode:"default",source:"pill_dismiss"}),_("default")},className:"flex items-center gap-1.5 h-8 rounded-lg px-2.5 text-sm font-medium text-blue-600 dark:text-blue-400 hover:bg-blue-500/10 group whitespace-nowrap animate-in fade-in duration-200",children:[r.jsx(Ti,{size:14,className:"shrink-0"}),r.jsx("span",{className:"max-w-[120px] truncate",children:v?"Web search":p.title.includes(": ")?p.title.split(": ").slice(1).join(": "):p.title}),r.jsx(fi,{size:14,className:"shrink-0 hidden group-hover:block"})]}),$&&H>0&&r.jsx(Op,{usage:G,totalTokens:H,contextWindow:$,onOpenContextPanel:t})]}),r.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[v?r.jsx(Av,{tier:x,onSelect:b}):r.jsx(iu,{placeholder:"Model",variant:"borderless",className:"h-8 text-sm py-2 min-w-0"}),I.isSupported&&!i&&!n&&r.jsx(ne,{type:"button",onClick:N,variant:"ghost",size:"icon",className:X("size-8 rounded-lg transition-colors",I.status==="permission-denied"?"text-destructive hover:text-destructive hover:bg-destructive/10":"text-muted-foreground hover:text-foreground"),title:I.status==="permission-denied"?"Microphone access denied — click to try again":"Voice input",children:r.jsx(mg,{size:18})}),r.jsx(ne,{type:U?"button":"submit",onClick:Y=>{U&&(Y.preventDefault(),Y.stopPropagation(),a())},variant:K||U?"default":"ghost",size:"icon",disabled:!K&&!U,className:X("size-8 rounded-lg transition-all",!K&&!U&&"bg-muted text-muted-foreground hover:bg-muted hover:text-muted-foreground cursor-not-allowed"),title:i?"Stop generating":n?"Cancel run":"Send message (Enter)",children:U?r.jsx(pg,{size:20}):r.jsx(Fh,{size:20})})]})]})})]})},l),e&&r.jsx(Sv,{onClick:()=>{se("connections_banner_clicked",{source:"home_chat_input"}),se("connections_dialog_opened",{source:"home_banner",mode:"add"}),T(!0)}})]})}),r.jsx(Pl,{mode:"browse",open:k,onOpenChange:T,defaultTab:"all"})]})}const Dv={usd:[{dollars:10,label:"Starter"},{dollars:20,label:"Popular"},{dollars:100,label:"Best value"}],brl:[{dollars:50,label:"Starter"},{dollars:100,label:"Popular"},{dollars:500,label:"Best value"}]};function Ku(t){return`deco-credits-empty-dismissed:${t}`}function Mv(t){try{return localStorage.getItem(Ku(t))==="1"}catch{return!1}}function Pv(){const t=B.c(49),{org:e}=be(),s=Ke(),{decoKeyId:i}=co();let n;t[0]!==e.id?(n={connectionId:Wt,orgId:e.id},t[0]=e.id,t[1]=n):n=t[1];const o=Me(n),[a,l]=S.useState(!0),[c,d]=S.useState(""),[u,h]=S.useState(!1),[f,m]=S.useState("usd"),p=f==="brl"?"R$":"$";let g;t[2]!==e.id?(g=()=>{se("credits_empty_state_dismissed",{organization_id:e.id}),l(!1);try{localStorage.setItem(Ku(e.id),"1")}catch{}},t[2]=e.id,t[3]=g):g=t[3];const _=g;let v,x;t[4]!==a||t[5]!==e.id?(v=()=>{a&&se("credits_empty_state_shown",{organization_id:e.id})},x=[a,e.id],t[4]=a,t[5]=e.id,t[6]=v,t[7]=x):(v=t[6],x=t[7]),S.useEffect(v,x);let b;t[8]!==o||t[9]!==f?(b=async $=>{const W=await o.callTool({name:"AI_PROVIDER_TOPUP_URL",arguments:{providerId:"deco",amountCents:$,currency:f}});if(W?.isError)throw new Error(W.content?.[0]?.text??"Failed to get top-up URL");return W.structuredContent?.url},t[8]=o,t[9]=f,t[10]=b):b=t[10];let y;t[11]!==_?(y=$=>{$&&window.open($,"_blank","noopener,noreferrer"),_()},t[11]=_,t[12]=y):y=t[12];let C;t[13]!==b||t[14]!==y?(C={mutationFn:b,onSuccess:y,onError:Bv},t[13]=b,t[14]=y,t[15]=C):C=t[15];const{mutate:j,isPending:V}=Br(C),w=parseFloat(c),k=!isNaN(w)&&w>=1;if(!a)return null;let T;t[16]!==_?(T=$=>!$&&_(),t[16]=_,t[17]=T):T=t[17];let I;t[18]===Symbol.for("react.memo_cache_sentinel")?(I=r.jsx("div",{className:"absolute inset-x-0 top-0 h-24 bg-gradient-to-b from-amber-500/8 to-transparent pointer-events-none rounded-t-lg"}),t[18]=I):I=t[18];let A;t[19]===Symbol.for("react.memo_cache_sentinel")?(A=r.jsx("div",{className:"flex items-center justify-center size-11 rounded-full bg-amber-100 dark:bg-amber-900/40 border border-amber-200/60 dark:border-amber-800/40 mx-auto",children:r.jsx(ml,{size:20,className:"text-amber-600 dark:text-amber-400"})}),t[19]=A):A=t[19];let N;t[20]===Symbol.for("react.memo_cache_sentinel")?(N=r.jsxs("div",{className:"relative px-6 pt-7 pb-5",children:[I,r.jsxs(Ds,{className:"relative gap-3",children:[A,r.jsxs("div",{className:"text-center",children:[r.jsx(Ts,{className:"text-lg font-semibold",children:"This workspace has no credits"}),r.jsx(dl,{className:"mt-2 text-[13px] leading-relaxed max-w-[320px] mx-auto",children:"Your free credits were used in another workspace. Add credits to use AI here."})]})]})]}),t[20]=N):N=t[20];let E;t[21]!==f||t[22]!==p||t[23]!==c||t[24]!==w||t[25]!==i||t[26]!==k||t[27]!==V||t[28]!==u||t[29]!==j?(E=i&&r.jsxs("div",{className:"px-6 pb-5",children:[r.jsx("div",{className:"mb-4",children:r.jsxs(eu,{type:"single",variant:"outline",size:"sm",value:f,onValueChange:$=>{$&&m($)},children:[r.jsx(Ln,{value:"usd",className:"h-8 px-3 text-xs",children:"USD"}),r.jsx(Ln,{value:"brl",className:"h-8 px-3 text-xs",children:"BRL"})]})}),r.jsx("div",{className:"grid grid-cols-3 gap-2.5",children:Dv[f].map($=>{const{dollars:W,label:F}=$;return r.jsxs("button",{type:"button",disabled:V,onClick:()=>{se("credits_topup_clicked",{amount_cents:W*100,currency:f,tier_label:F,source:"empty_state"}),j(W*100)},className:X("relative flex flex-col items-center gap-1 py-6 rounded-xl border transition-all duration-150 cursor-pointer","disabled:opacity-50 disabled:cursor-wait","border-border hover:border-foreground/20 hover:bg-muted/30"),children:[r.jsxs("span",{className:"text-2xl font-semibold tabular-nums text-foreground",children:[p,W]}),r.jsx("span",{className:"text-xs text-muted-foreground",children:F})]},W)})}),u?r.jsxs("div",{className:"flex gap-2 mt-3",children:[r.jsxs("div",{className:"relative flex-1",children:[r.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-sm text-muted-foreground select-none",children:p}),r.jsx(bt,{type:"number",min:"1",step:"1",placeholder:"50",value:c,onChange:$=>d($.target.value),className:"h-10 text-sm pl-7",autoFocus:!0})]}),r.jsx(ne,{className:"h-10",disabled:!k||V,onClick:()=>{se("credits_topup_clicked",{amount_cents:Math.round(w*100),currency:f,tier_label:"custom",source:"empty_state"}),j(Math.round(w*100))},children:V?"Opening...":"Add"})]}):r.jsx("button",{type:"button",className:"w-full mt-2.5 text-xs text-muted-foreground hover:text-foreground transition-colors py-1",onClick:()=>h(!0),children:"Enter custom amount"})]}),t[21]=f,t[22]=p,t[23]=c,t[24]=w,t[25]=i,t[26]=k,t[27]=V,t[28]=u,t[29]=j,t[30]=E):E=t[30];let R;t[31]!==_||t[32]!==s||t[33]!==e.slug?(R=()=>{s({to:"/$org/settings/ai-providers",params:{org:e.slug}}),_()},t[31]=_,t[32]=s,t[33]=e.slug,t[34]=R):R=t[34];let M;t[35]===Symbol.for("react.memo_cache_sentinel")?(M=r.jsx(ro,{size:12,className:"transition-transform duration-150 group-hover:translate-x-0.5"}),t[35]=M):M=t[35];let L;t[36]!==R?(L=r.jsxs("button",{type:"button",className:"group flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors",onClick:R,children:["Use your own provider",M]}),t[36]=R,t[37]=L):L=t[37];let D;t[38]!==_?(D=r.jsx(ne,{variant:"ghost",size:"sm",className:"text-xs text-muted-foreground",onClick:_,children:"Skip for now"}),t[38]=_,t[39]=D):D=t[39];let P;t[40]!==L||t[41]!==D?(P=r.jsxs("div",{className:"px-6 py-3.5 border-t border-border bg-muted/30 flex items-center justify-between",children:[L,D]}),t[40]=L,t[41]=D,t[42]=P):P=t[42];let O;t[43]!==E||t[44]!==P?(O=r.jsxs(ms,{className:"sm:max-w-[500px] gap-0 p-0 overflow-hidden",onOpenAutoFocus:Lv,children:[N,E,P]}),t[43]=E,t[44]=P,t[45]=O):O=t[45];let z;return t[46]!==O||t[47]!==T?(z=r.jsx(ps,{open:!0,onOpenChange:T,children:O}),t[46]=O,t[47]=T,t[48]=z):z=t[48],z}function Lv(t){return t.preventDefault()}function Bv(t){pe.error(`Top-up failed: ${t.message}`)}function Ov(t){const e=B.c(6),{balanceDollars:s}=t;let i;e[0]!==s?(i=s.toFixed(2),e[0]=s,e[1]=i):i=e[1];const n=i;let o,a;e[2]===Symbol.for("react.memo_cache_sentinel")?(o=X("inline-flex items-center gap-1.5 px-3 py-1 rounded-full","bg-emerald-50 dark:bg-emerald-950/30","border border-emerald-200/60 dark:border-emerald-800/40","animate-in fade-in-0 slide-in-from-bottom-2 duration-300"),a=r.jsx(ml,{size:13,className:"text-emerald-600 dark:text-emerald-400"}),e[2]=o,e[3]=a):(o=e[2],a=e[3]);let l;return e[4]!==n?(l=r.jsxs("div",{className:o,children:[a,r.jsxs("span",{className:"text-xs font-medium text-emerald-700 dark:text-emerald-300 tabular-nums",children:["$",n," in credits to get started"]})]}),e[4]=n,e[5]=l):l=e[5],l}function $v(){const t=B.c(8),{org:e}=be(),s=Ke();let i;t[0]!==s||t[1]!==e.slug?(i=()=>s({to:"/$org/settings/ai-providers",params:{org:e.slug}}),t[0]=s,t[1]=e.slug,t[2]=i):i=t[2];let n,o,a;t[3]===Symbol.for("react.memo_cache_sentinel")?(n=X("inline-flex items-center gap-1.5 px-3 py-1 rounded-full cursor-pointer","bg-amber-50 dark:bg-amber-950/30","border border-amber-200/60 dark:border-amber-800/40","hover:bg-amber-100/60 dark:hover:bg-amber-900/30","transition-colors duration-150","animate-in fade-in-0 slide-in-from-bottom-2 duration-300"),o=r.jsx(ri,{size:13,className:"text-amber-600 dark:text-amber-400"}),a=r.jsx("span",{className:"text-xs font-medium text-amber-700 dark:text-amber-300",children:"No credits remaining · Add more"}),t[3]=n,t[4]=o,t[5]=a):(n=t[3],o=t[4],a=t[5]);let l;return t[6]!==i?(l=r.jsxs("button",{type:"button",onClick:i,className:n,children:[o,a]}),t[6]=i,t[7]=l):l=t[7],l}function zv(t){const e=B.c(11),{className:s}=t;let i;e[0]!==s?(i=X("flex h-full w-full flex-col bg-background",s),e[0]=s,e[1]=i):i=e[1];let n;e[2]===Symbol.for("react.memo_cache_sentinel")?(n=r.jsx("div",{className:"size-6 rounded-lg bg-muted animate-pulse"}),e[2]=n):n=e[2];let o;e[3]===Symbol.for("react.memo_cache_sentinel")?(o=r.jsxs("div",{className:"flex items-center gap-3",children:[n,r.jsxs("div",{className:"flex flex-col gap-2",children:[r.jsx("div",{className:"h-3.5 w-28 rounded bg-muted animate-pulse"}),r.jsx("div",{className:"h-3 w-40 rounded bg-muted/60 animate-pulse"})]})]}),e[3]=o):o=e[3];let a;e[4]===Symbol.for("react.memo_cache_sentinel")?(a=r.jsx("div",{className:"flex items-center h-12 flex-none border-b border-border/80 px-4",children:r.jsxs("div",{className:"flex items-center justify-between gap-3 w-full",children:[o,r.jsxs("div",{className:"flex items-end gap-2",children:[r.jsx("div",{className:"h-6 w-6 rounded-full bg-muted animate-pulse"}),r.jsx("div",{className:"h-6 w-6 rounded-lg bg-muted animate-pulse"})]})]})}),e[4]=a):a=e[4];let l;e[5]===Symbol.for("react.memo_cache_sentinel")?(l=r.jsx("div",{className:"flex-1 overflow-hidden px-4 py-4",children:r.jsxs("div",{className:"mx-auto flex w-full max-w-2xl flex-col gap-4",children:[r.jsx(an,{align:"right",width:"w-3/4"}),r.jsx(an,{align:"left",width:"w-full",lines:3}),r.jsx(an,{align:"right",width:"w-2/3"}),r.jsx(an,{align:"left",width:"w-5/6",lines:2})]})}),e[5]=l):l=e[5];let c;e[6]===Symbol.for("react.memo_cache_sentinel")?(c=r.jsx("div",{className:"relative flex flex-1 flex-col gap-2 p-2.5",children:r.jsx("div",{className:"relative flex-1",children:r.jsxs("div",{className:"space-y-2 p-2",children:[r.jsx("div",{className:"h-3 w-full rounded bg-muted/40 animate-pulse"}),r.jsx("div",{className:"h-3 w-4/5 rounded bg-muted/40 animate-pulse"})]})})}),e[6]=c):c=e[6];let d;e[7]===Symbol.for("react.memo_cache_sentinel")?(d=r.jsx("div",{className:"flex items-center gap-1",children:r.jsx("div",{className:"size-8 rounded-full bg-muted/60 animate-pulse"})}),e[7]=d):d=e[7];let u;e[8]===Symbol.for("react.memo_cache_sentinel")?(u=r.jsx("div",{className:"px-4 py-4",children:r.jsx("div",{className:"mx-auto w-full max-w-2xl",children:r.jsxs("div",{className:"relative flex min-h-[130px] flex-col rounded-xl bg-background card-shadow",children:[c,r.jsxs("div",{className:"flex items-center justify-between px-2.5 pb-2.5",children:[d,r.jsxs("div",{className:"flex items-center gap-1",children:[r.jsx("div",{className:"h-8 w-32 rounded-lg bg-muted/60 animate-pulse"}),r.jsx("div",{className:"size-8 rounded-full bg-muted animate-pulse"})]})]})]})})}),e[8]=u):u=e[8];let h;return e[9]!==i?(h=r.jsxs("div",{className:i,children:[a,l,u]}),e[9]=i,e[10]=h):h=e[10],h}function an(t){const e=B.c(22),{align:s,width:i,lines:n}=t,o=i===void 0?"w-full":i,a=n===void 0?1:n,l=s==="right"?"flex-row-reverse":"flex-row";let c;e[0]!==l?(c=X("flex w-full gap-4 px-4 py-2",l),e[0]=l,e[1]=c):c=e[1];const d=s==="right"?"ml-auto max-w-3/4 items-end":"w-full items-start";let u;e[2]!==d?(u=X("flex min-w-0 flex-col gap-2",d),e[2]=d,e[3]=u):u=e[3];let h;e[4]===Symbol.for("react.memo_cache_sentinel")?(h=r.jsx("div",{className:"h-3 w-16 rounded bg-muted/40 animate-pulse"}),e[4]=h):h=e[4];const f=s==="right"?"bg-muted":"bg-transparent border border-border/40";let m;e[5]!==f||e[6]!==o?(m=X("min-w-0 rounded-2xl p-4",f,o),e[5]=f,e[6]=o,e[7]=m):m=e[7];let p;e[8]!==a?(p=Array.from({length:a}),e[8]=a,e[9]=p):p=e[9];let g;e[10]!==a||e[11]!==p?(g=r.jsx("div",{className:"space-y-2",children:p.map((b,y)=>r.jsx("div",{className:X("h-3 rounded bg-muted-foreground/20 animate-pulse",y===a-1?"w-3/4":"w-full"),style:{animationDelay:`${y*.1}s`}},y))}),e[10]=a,e[11]=p,e[12]=g):g=e[12];let _;e[13]!==g||e[14]!==m?(_=r.jsx("div",{className:m,children:g}),e[13]=g,e[14]=m,e[15]=_):_=e[15];let v;e[16]!==_||e[17]!==u?(v=r.jsxs("div",{className:u,children:[h,_]}),e[16]=_,e[17]=u,e[18]=v):v=e[18];let x;return e[19]!==v||e[20]!==c?(x=r.jsx("div",{className:c,children:v}),e[19]=v,e[20]=c,e[21]=x):x=e[21],x}function Fv(t){const e=B.c(5),{className:s,children:i}=t;let n;e[0]!==s?(n=X("flex flex-col h-full w-full bg-background transform-[translateZ(0)]",s),e[0]=s,e[1]=n):n=e[1];let o;return e[2]!==i||e[3]!==n?(o=r.jsx("div",{className:n,children:i}),e[2]=i,e[3]=n,e[4]=o):o=e[4],o}function Hv(t){const e=B.c(5),{children:s,className:i}=t;let n;e[0]!==i?(n=X("flex-1 min-h-0 overflow-y-auto isolate",i),e[0]=i,e[1]=n):n=e[1];let o;return e[2]!==s||e[3]!==n?(o=r.jsx("div",{className:n,children:s}),e[2]=s,e[3]=n,e[4]=o):o=e[4],o}function Wv(t){const e=B.c(2),{children:s}=t;let i;return e[0]!==s?(i=r.jsx("div",{className:"h-full w-full flex items-center justify-center max-w-2xl mx-auto",children:s}),e[0]=s,e[1]=i):i=e[1],i}function Uv(){const t=B.c(16),{messages:e,status:s}=Ui(),i=$p(e);let n;t[0]!==i?(n=i.at(-1),t[0]=i,t[1]=n):n=t[1];const o=n,a=s==="submitted"||s==="streaming";let l;if(t[2]!==a||t[3]!==o||t[4]!==i||t[5]!==e||t[6]!==s){const c=e.at(-1),d=!a&&c?.role==="assistant"&&c.parts.filter(Gv).some(qv),u=!a&&c?.role==="assistant"&&c.parts.some(Kv);let h;if(t[8]!==i||t[9]!==s){let m;t[11]!==i.length||t[12]!==s?(m=(p,g)=>r.jsx(dc,{pair:p,isLastPair:!1,status:g===i.length-1?s:void 0},`pair-${p.user.id}`),t[11]=i.length,t[12]=s,t[13]=m):m=t[13],h=i.slice(0,-1).map(m),t[8]=i,t[9]=s,t[10]=h}else h=t[10];let f;t[14]!==h?(f=r.jsx("div",{className:"flex flex-col min-w-0 max-w-2xl mx-auto w-full",children:h}),t[14]=h,t[15]=f):f=t[15],l=r.jsxs("div",{className:"w-full min-w-0 max-w-full overflow-y-auto h-full overflow-x-hidden",children:[f,o&&r.jsx("div",{className:X("min-h-full min-w-0 max-w-2xl mx-auto w-full",(d||u)&&"pb-60"),children:r.jsx(dc,{pair:o,isLastPair:!0,status:s},`pair-${o?.user.id}`)})]}),t[2]=a,t[3]=o,t[4]=i,t[5]=e,t[6]=s,t[7]=l}else l=t[7];return l}function Kv(t){return"state"in t&&t.state==="approval-requested"}function qv(t){return t.state==="input-available"}function Gv(t){return t.type==="tool-user_ask"}function Yv(t){const e=B.c(5),{children:s,className:i}=t;let n;e[0]!==i?(n=X("flex-none w-full mx-auto p-2 pt-0","max-w-2xl min-w-0",i),e[0]=i,e[1]=n):n=e[1];let o;return e[2]!==s||e[3]!==n?(o=r.jsx("div",{className:n,children:s}),e[2]=s,e[3]=n,e[4]=o):o=e[4],o}const De=Object.assign(Fv,{Main:Hv,Messages:Uv,EmptyState:Wv,Footer:Yv,Input:Tv,Provider:Ap,ActiveTaskProvider:Np,Skeleton:zv,IceBreakers:ix,NoAiProviderEmptyState:Hg,CreditsEmptyState:Pv,CreditsEyebrow:Ov,NoCreditsEyebrow:$v,CreditsExhaustedBanner:Au}),Xv=`You are an image generator agent. Every request of the user is somewhat related to creating, editing or varying an image. You have access to image generation tools
5
5
 
6
6
  These guidelines define how prompts should be structured, specified, and iterated to produce high-quality, controlled image outputs across different use cases.
7
7
 
@@ -245,7 +245,7 @@ This helps define finish quality and realism level.
245
245
  * Prefer clarity over poetic language.
246
246
  * Keep prompts structured, not verbose.
247
247
  * Add detail only when it improves control.
248
- * Prevent drift by restating critical constraints`,Gv=["Turn ideas into detailed, ready-to-use image generation prompts","Offer multiple artistic directions for every concept","Refine prompts iteratively based on your feedback","Advise on style, lighting, composition, and color palette","Support any use case: product shots, illustrations, concept art, and more"];function Hc(t){const e=B.c(7),{onRecruit:s,isRecruiting:i}=t;let n;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=r.jsx("p",{className:"text-sm text-muted-foreground",children:"Add an Image Creator agent that turns your ideas into precise, evocative prompts for any AI image generation tool."}),e[0]=n):n=e[0];let o;e[1]===Symbol.for("react.memo_cache_sentinel")?(o=r.jsx("p",{className:"text-sm font-medium text-foreground",children:"Capabilities"}),e[1]=o):o=e[1];let a;e[2]===Symbol.for("react.memo_cache_sentinel")?(a=r.jsxs("div",{className:"space-y-2",children:[o,r.jsx("ul",{className:"space-y-1.5",children:Gv.map(Yv)})]}),e[2]=a):a=e[2];const l=i?"Setting up...":"Add Image Creator";let c;return e[3]!==i||e[4]!==s||e[5]!==l?(c=r.jsxs("div",{className:"flex flex-col gap-6",children:[n,a,r.jsx(ne,{onClick:s,disabled:i,className:"w-full cursor-pointer",children:l})]}),e[3]=i,e[4]=s,e[5]=l,e[6]=c):c=e[6],c}function Yv(t){return r.jsxs("li",{className:"text-sm text-muted-foreground flex items-start gap-2",children:[r.jsx("span",{className:"text-rose-500 mt-0.5 shrink-0",children:"+"}),t]},t)}function Xv({open:t,onOpenChange:e,existingAgent:s}){const i=Rs(),n=lo(),o=yl(),[a,l]=S.useState(!1),c=Os.find(f=>f.id==="ai-image"),d=r.jsx(Ms,{icon:c.icon,name:c.title,size:"sm"}),u=async()=>{if(s){e(!1),n(s.id);return}l(!0);try{const f=await o.create.mutateAsync({title:c.title,description:"AI image prompt engineering and visual ideation assistant",icon:c.icon,status:"active",connections:[],metadata:{type:"ai-image",instructions:qv}});se("agent_recruit_confirmed",{template_id:"ai-image",agent_id:f.id}),e(!1),n(f.id)}catch(f){se("agent_recruit_failed",{template_id:"ai-image",error:f instanceof Error?f.message:String(f)}),console.error("Failed to create Image Creator agent:",f)}finally{l(!1)}},h=`Add ${c.title}`;return i?r.jsx(Si,{open:t,onOpenChange:e,children:r.jsxs(yi,{className:"h-[70dvh]",children:[r.jsx(so,{className:"px-4 pt-4 pb-4 shrink-0",children:r.jsxs("div",{className:"flex items-center gap-3",children:[d,r.jsx(bi,{className:"text-xl font-semibold",children:h})]})}),r.jsx("div",{className:"flex flex-col flex-1 min-h-0 px-4 pb-8",children:r.jsx(Hc,{onRecruit:u,isRecruiting:a})})]})}):r.jsx(ps,{open:t,onOpenChange:e,children:r.jsxs(ms,{className:"sm:max-w-[500px] p-8",children:[r.jsx(Ds,{className:"mb-4",children:r.jsxs("div",{className:"flex items-center gap-3",children:[d,r.jsx(Ts,{className:"text-xl font-semibold",children:h})]})}),r.jsx(Hc,{onRecruit:u,isRecruiting:a})]})})}const Jv=`You are a systematic research assistant. You have access to web search tools and user's prompts will have somewhat relation to searching the web. Help users conduct thorough, well-structured research on any topic.
248
+ * Prevent drift by restating critical constraints`,Jv=["Turn ideas into detailed, ready-to-use image generation prompts","Offer multiple artistic directions for every concept","Refine prompts iteratively based on your feedback","Advise on style, lighting, composition, and color palette","Support any use case: product shots, illustrations, concept art, and more"];function Hc(t){const e=B.c(7),{onRecruit:s,isRecruiting:i}=t;let n;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=r.jsx("p",{className:"text-sm text-muted-foreground",children:"Add an Image Creator agent that turns your ideas into precise, evocative prompts for any AI image generation tool."}),e[0]=n):n=e[0];let o;e[1]===Symbol.for("react.memo_cache_sentinel")?(o=r.jsx("p",{className:"text-sm font-medium text-foreground",children:"Capabilities"}),e[1]=o):o=e[1];let a;e[2]===Symbol.for("react.memo_cache_sentinel")?(a=r.jsxs("div",{className:"space-y-2",children:[o,r.jsx("ul",{className:"space-y-1.5",children:Jv.map(Qv)})]}),e[2]=a):a=e[2];const l=i?"Setting up...":"Add Image Creator";let c;return e[3]!==i||e[4]!==s||e[5]!==l?(c=r.jsxs("div",{className:"flex flex-col gap-6",children:[n,a,r.jsx(ne,{onClick:s,disabled:i,className:"w-full cursor-pointer",children:l})]}),e[3]=i,e[4]=s,e[5]=l,e[6]=c):c=e[6],c}function Qv(t){return r.jsxs("li",{className:"text-sm text-muted-foreground flex items-start gap-2",children:[r.jsx("span",{className:"text-rose-500 mt-0.5 shrink-0",children:"+"}),t]},t)}function Zv({open:t,onOpenChange:e,existingAgent:s}){const i=Rs(),n=lo(),o=yl(),[a,l]=S.useState(!1),c=Os.find(f=>f.id==="ai-image"),d=r.jsx(Ms,{icon:c.icon,name:c.title,size:"sm"}),u=async()=>{if(s){e(!1),n(s.id);return}l(!0);try{const f=await o.create.mutateAsync({title:c.title,description:"AI image prompt engineering and visual ideation assistant",icon:c.icon,status:"active",connections:[],metadata:{type:"ai-image",instructions:Xv}});se("agent_recruit_confirmed",{template_id:"ai-image",agent_id:f.id}),e(!1),n(f.id)}catch(f){se("agent_recruit_failed",{template_id:"ai-image",error:f instanceof Error?f.message:String(f)}),console.error("Failed to create Image Creator agent:",f)}finally{l(!1)}},h=`Add ${c.title}`;return i?r.jsx(Si,{open:t,onOpenChange:e,children:r.jsxs(yi,{className:"h-[70dvh]",children:[r.jsx(so,{className:"px-4 pt-4 pb-4 shrink-0",children:r.jsxs("div",{className:"flex items-center gap-3",children:[d,r.jsx(bi,{className:"text-xl font-semibold",children:h})]})}),r.jsx("div",{className:"flex flex-col flex-1 min-h-0 px-4 pb-8",children:r.jsx(Hc,{onRecruit:u,isRecruiting:a})})]})}):r.jsx(ps,{open:t,onOpenChange:e,children:r.jsxs(ms,{className:"sm:max-w-[500px] p-8",children:[r.jsx(Ds,{className:"mb-4",children:r.jsxs("div",{className:"flex items-center gap-3",children:[d,r.jsx(Ts,{className:"text-xl font-semibold",children:h})]})}),r.jsx(Hc,{onRecruit:u,isRecruiting:a})]})})}const eb=`You are a systematic research assistant. You have access to web search tools and user's prompts will have somewhat relation to searching the web. Help users conduct thorough, well-structured research on any topic.
249
249
 
250
250
  VERY IMPORTANT: The user might not have any web research model connected. If so, guide the user to use an AI Provider that has an Web Search generation, or connect a specific model in our connections.
251
251
 
@@ -256,16 +256,16 @@ When given a research question or topic:
256
256
  - Identify sources, patterns, gaps, and contradictions
257
257
  - Deliver findings as clear, structured summaries with actionable insights
258
258
 
259
- Approach every request with rigor and intellectual honesty. Always surface what is uncertain or debated, not just what is known.`,Qv=["Break any topic into key sub-questions and define scope","Synthesize information from multiple angles and sources","Distinguish facts, expert consensus, and contested claims","Identify gaps, contradictions, and emerging patterns","Deliver structured summaries with actionable insights"];function Wc(t){const e=B.c(7),{onRecruit:s,isRecruiting:i}=t;let n;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=r.jsx("p",{className:"text-sm text-muted-foreground",children:"Add a Web Researcher agent that conducts thorough, rigorous research on any topic and delivers structured, actionable insights."}),e[0]=n):n=e[0];let o;e[1]===Symbol.for("react.memo_cache_sentinel")?(o=r.jsx("p",{className:"text-sm font-medium text-foreground",children:"Capabilities"}),e[1]=o):o=e[1];let a;e[2]===Symbol.for("react.memo_cache_sentinel")?(a=r.jsxs("div",{className:"space-y-2",children:[o,r.jsx("ul",{className:"space-y-1.5",children:Qv.map(Zv)})]}),e[2]=a):a=e[2];const l=i?"Setting up...":"Add Web Researcher";let c;return e[3]!==i||e[4]!==s||e[5]!==l?(c=r.jsxs("div",{className:"flex flex-col gap-6",children:[n,a,r.jsx(ne,{onClick:s,disabled:i,className:"w-full cursor-pointer",children:l})]}),e[3]=i,e[4]=s,e[5]=l,e[6]=c):c=e[6],c}function Zv(t){return r.jsxs("li",{className:"text-sm text-muted-foreground flex items-start gap-2",children:[r.jsx("span",{className:"text-amber-500 mt-0.5 shrink-0",children:"+"}),t]},t)}function eb({open:t,onOpenChange:e,existingAgent:s}){const i=Rs(),n=lo(),o=yl(),[a,l]=S.useState(!1),c=Os.find(f=>f.id==="ai-research"),d=r.jsx(Ms,{icon:c.icon,name:c.title,size:"sm"}),u=async()=>{if(s){e(!1),n(s.id);return}l(!0);try{const f=await o.create.mutateAsync({title:c.title,description:"Systematic research and information synthesis assistant",icon:c.icon,status:"active",connections:[],metadata:{type:"ai-research",instructions:Jv}});se("agent_recruit_confirmed",{template_id:"ai-research",agent_id:f.id}),e(!1),n(f.id)}catch(f){se("agent_recruit_failed",{template_id:"ai-research",error:f instanceof Error?f.message:String(f)}),console.error("Failed to create Researcher agent:",f)}finally{l(!1)}},h=`Add ${c.title}`;return i?r.jsx(Si,{open:t,onOpenChange:e,children:r.jsxs(yi,{className:"h-[70dvh]",children:[r.jsx(so,{className:"px-4 pt-4 pb-4 shrink-0",children:r.jsxs("div",{className:"flex items-center gap-3",children:[d,r.jsx(bi,{className:"text-xl font-semibold",children:h})]})}),r.jsx("div",{className:"flex flex-col flex-1 min-h-0 px-4 pb-8",children:r.jsx(Wc,{onRecruit:u,isRecruiting:a})})]})}):r.jsx(ps,{open:t,onOpenChange:e,children:r.jsxs(ms,{className:"sm:max-w-[500px] p-8",children:[r.jsx(Ds,{className:"mb-4",children:r.jsxs("div",{className:"flex items-center gap-3",children:[d,r.jsx(Ts,{className:"text-xl font-semibold",children:h})]})}),r.jsx(Wc,{onRecruit:u,isRecruiting:a})]})})}function tb(t){try{const e=localStorage.getItem(`mesh:chat:recent-agents:${t}`);return e?JSON.parse(e):[]}catch{return[]}}function tr(t){const e=B.c(21),{agent:s,onSpecialClick:i,tracking:n}=t,{org:o}=be(),a=Ke();let l;e[0]!==s.id||e[1]!==s.title||e[2]!==a||e[3]!==i||e[4]!==o||e[5]!==n.action||e[6]!==n.template_id||e[7]!==n.tile_kind?(l=()=>{if(se("home_agent_tile_clicked",{template_id:n.template_id,agent_id:s.id,agent_title:s.title,tile_kind:n.tile_kind,action:n.action}),i)i();else{const g=crypto.randomUUID();a({to:"/$org/$taskId",params:{org:o.slug,taskId:g},search:{virtualmcpid:s.id}})}},e[0]=s.id,e[1]=s.title,e[2]=a,e[3]=i,e[4]=o,e[5]=n.action,e[6]=n.template_id,e[7]=n.tile_kind,e[8]=l):l=e[8];const c=l;let d;e[9]===Symbol.for("react.memo_cache_sentinel")?(d=X("flex flex-col items-center gap-3 p-2 rounded-lg","transition-colors","cursor-pointer","w-[100px] shrink-0","group"),e[9]=d):d=e[9];const u=`Select agent ${s.title}`;let h;e[10]===Symbol.for("react.memo_cache_sentinel")?(h=r.jsx(ao,{size:24}),e[10]=h):h=e[10];let f;e[11]!==s.icon||e[12]!==s.title?(f=r.jsx(Ms,{icon:s.icon,name:s.title,size:"md",fallbackIcon:h,className:"transition-transform group-hover:scale-110"}),e[11]=s.icon,e[12]=s.title,e[13]=f):f=e[13];let m;e[14]!==s.title?(m=r.jsx("p",{className:"text-xs sm:text-sm text-foreground text-center leading-tight line-clamp-2 break-words w-full",children:s.title}),e[14]=s.title,e[15]=m):m=e[15];let p;return e[16]!==c||e[17]!==u||e[18]!==f||e[19]!==m?(p=r.jsxs("button",{type:"button",onClick:c,className:d,"aria-label":u,children:[f,m]}),e[16]=c,e[17]=u,e[18]=f,e[19]=m,e[20]=p):p=e[20],p}function sb(){const t=B.c(8),e=Ke(),{org:s}=be();let i;t[0]===Symbol.for("react.memo_cache_sentinel")?(i=X("flex flex-col items-center gap-3 p-2 rounded-lg","transition-colors","cursor-pointer","w-[100px] shrink-0","group"),t[0]=i):i=t[0];let n;t[1]!==e||t[2]!==s.slug?(n=()=>{se("home_see_all_agents_clicked"),e({to:"/$org/settings/agents",params:{org:s.slug}})},t[1]=e,t[2]=s.slug,t[3]=n):n=t[3];let o,a;t[4]===Symbol.for("react.memo_cache_sentinel")?(o=r.jsx("div",{className:"size-12 rounded-xl bg-accent flex items-center justify-center shrink-0 transition-transform group-hover:scale-110",children:r.jsx(Vl,{size:20,className:"text-foreground"})}),a=r.jsx("p",{className:"text-xs sm:text-sm text-foreground text-center leading-tight",children:"See all"}),t[4]=o,t[5]=a):(o=t[4],a=t[5]);let l;return t[6]!==n?(l=r.jsxs("button",{type:"button",className:i,"aria-label":"See all agents",onClick:n,children:[o,a]}),t[6]=n,t[7]=l):l=t[7],l}function ib(){const t=B.c(9);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e={navigateOnCreate:!0},t[0]=e):e=t[0];const{createVirtualMCP:s,isCreating:i}=mu(e);let n;t[1]!==s?(n=()=>{se("home_create_agent_clicked"),s()},t[1]=s,t[2]=n):n=t[2];let o;t[3]===Symbol.for("react.memo_cache_sentinel")?(o=X("flex flex-col items-center gap-3 p-2 rounded-lg","transition-colors","cursor-pointer","w-[100px] shrink-0","group","disabled:opacity-50 disabled:cursor-not-allowed"),t[3]=o):o=t[3];let a,l;t[4]===Symbol.for("react.memo_cache_sentinel")?(a=r.jsx("div",{className:"size-12 rounded-xl bg-background border-2 border-dashed border-border flex items-center justify-center shrink-0 transition-transform group-hover:scale-110",children:r.jsx(Qt,{size:20,className:"text-muted-foreground"})}),l=r.jsx("p",{className:"text-xs sm:text-sm text-foreground text-center leading-tight",children:"Create agent"}),t[4]=a,t[5]=l):(a=t[4],l=t[5]);let c;return t[6]!==i||t[7]!==n?(c=r.jsxs("button",{type:"button",onClick:n,disabled:i,className:o,"aria-label":"Create agent",children:[a,l]}),t[6]=i,t[7]=n,t[8]=c):c=t[8],c}function rb(){const t=B.c(95),e=oo(),{locator:s}=be(),[i,n]=S.useState(!1),[o,a]=S.useState(!1),[l,c]=S.useState(!1),[d,u]=S.useState(!1),h=lo();let f;t[0]===Symbol.for("react.memo_cache_sentinel")?(f=Os.find(cb),t[0]=f):f=t[0];const m=f;let p;t[1]===Symbol.for("react.memo_cache_sentinel")?(p=Os.find(lb),t[1]=p):p=t[1];const g=p;let _;t[2]===Symbol.for("react.memo_cache_sentinel")?(_=Os.find(ab),t[2]=_):_=t[2];const v=_;let x;t[3]===Symbol.for("react.memo_cache_sentinel")?(x=Os.find(ob),t[3]=x):x=t[3];const b=x;let y,C,j,V,w,k,T,I,A,N,E;if(t[4]!==s||t[5]!==h||t[6]!==e){const F=tb(s),G=e.filter(nb).sort((Q,ae)=>{const Se=F.indexOf(Q.id),Ne=F.indexOf(ae.id);return Se!==-1&&Ne!==-1?Se-Ne:Se!==-1?-1:Ne!==-1?1:new Date(ae.updated_at).getTime()-new Date(Q.updated_at).getTime()}).slice(0,4);let q;if(t[18]!==e){let Q;t[20]===Symbol.for("react.memo_cache_sentinel")?(Q=ae=>ae.id!==null&&(ae.metadata?.type===g.id||ae.title===g.title),t[20]=Q):Q=t[20],q=e.find(Q),t[18]=e,t[19]=q}else q=t[19];j=q;let H;if(t[21]!==e){let Q;t[23]===Symbol.for("react.memo_cache_sentinel")?(Q=ae=>ae.id!==null&&(ae.metadata?.type===v.id||ae.title===v.title),t[23]=Q):Q=t[23],H=e.find(Q),t[21]=e,t[22]=H}else H=t[22];y=H;let ee;if(t[24]!==e){let Q;t[26]===Symbol.for("react.memo_cache_sentinel")?(Q=ae=>ae.id!==null&&(ae.metadata?.type===b.id||ae.title===b.title),t[26]=Q):Q=t[26],ee=e.find(Q),t[24]=e,t[25]=ee}else ee=t[25];C=ee,V=G.length>0,w="w-full max-md:overflow-x-auto max-md:[scrollbar-width:none] max-md:[&::-webkit-scrollbar]:hidden",k="flex flex-wrap justify-center gap-1.5 max-md:flex-nowrap max-md:justify-start md:max-h-52 md:overflow-hidden",t[27]===Symbol.for("react.memo_cache_sentinel")?(T=r.jsx(tr,{agent:m,onSpecialClick:()=>n(!0),tracking:{template_id:m.id,tile_kind:"template",action:"open_modal"}},m.id),t[27]=T):T=t[27];const K=j??g;let U;t[28]!==j||t[29]!==h?(U=j?()=>h(j.id):()=>a(!0),t[28]=j,t[29]=h,t[30]=U):U=t[30];const te=j?"existing":"template",Y=j?"navigate":"open_modal";let J;t[31]!==te||t[32]!==Y?(J={template_id:g.id,tile_kind:te,action:Y},t[31]=te,t[32]=Y,t[33]=J):J=t[33],t[34]!==K||t[35]!==U||t[36]!==J?(I=r.jsx(tr,{agent:K,onSpecialClick:U,tracking:J},g.id),t[34]=K,t[35]=U,t[36]=J,t[37]=I):I=t[37];const ie=y??v;let ue;t[38]!==y||t[39]!==h?(ue=y?()=>h(y.id):()=>c(!0),t[38]=y,t[39]=h,t[40]=ue):ue=t[40];const de=y?"existing":"template",xe=y?"navigate":"open_modal";let oe;t[41]!==de||t[42]!==xe?(oe={template_id:v.id,tile_kind:de,action:xe},t[41]=de,t[42]=xe,t[43]=oe):oe=t[43],t[44]!==ie||t[45]!==ue||t[46]!==oe?(A=r.jsx(tr,{agent:ie,onSpecialClick:ue,tracking:oe},v.id),t[44]=ie,t[45]=ue,t[46]=oe,t[47]=A):A=t[47];const he=C??b;let me;t[48]!==C||t[49]!==h?(me=C?()=>h(C.id):()=>u(!0),t[48]=C,t[49]=h,t[50]=me):me=t[50];const fe=C?"existing":"template",le=C?"navigate":"open_modal";let ve;t[51]!==fe||t[52]!==le?(ve={template_id:b.id,tile_kind:fe,action:le},t[51]=fe,t[52]=le,t[53]=ve):ve=t[53],t[54]!==he||t[55]!==me||t[56]!==ve?(N=r.jsx(tr,{agent:he,onSpecialClick:me,tracking:ve},b.id),t[54]=he,t[55]=me,t[56]=ve,t[57]=N):N=t[57];let Ce;t[58]!==y?.id||t[59]!==C?.id||t[60]!==j?.id?(Ce=Q=>Q.id!==j?.id&&Q.id!==y?.id&&Q.id!==C?.id,t[58]=y?.id,t[59]=C?.id,t[60]=j?.id,t[61]=Ce):Ce=t[61];let Te;t[62]!==h?(Te=Q=>r.jsx(tr,{agent:Q,onSpecialClick:()=>h(Q.id),tracking:{template_id:null,tile_kind:"recent",action:"navigate"}},Q.id??"default"),t[62]=h,t[63]=Te):Te=t[63],E=G.filter(Ce).map(Te),t[4]=s,t[5]=h,t[6]=e,t[7]=y,t[8]=C,t[9]=j,t[10]=V,t[11]=w,t[12]=k,t[13]=T,t[14]=I,t[15]=A,t[16]=N,t[17]=E}else y=t[7],C=t[8],j=t[9],V=t[10],w=t[11],k=t[12],T=t[13],I=t[14],A=t[15],N=t[16],E=t[17];let R;t[64]===Symbol.for("react.memo_cache_sentinel")?(R=r.jsx(ib,{}),t[64]=R):R=t[64];let M;t[65]!==V?(M=V&&r.jsx(sb,{}),t[65]=V,t[66]=M):M=t[66];let L;t[67]!==M||t[68]!==k||t[69]!==T||t[70]!==I||t[71]!==A||t[72]!==N||t[73]!==E?(L=r.jsxs("div",{className:k,children:[T,I,A,N,E,R,M]}),t[67]=M,t[68]=k,t[69]=T,t[70]=I,t[71]=A,t[72]=N,t[73]=E,t[74]=L):L=t[74];let D;t[75]!==w||t[76]!==L?(D=r.jsx("div",{className:w,children:L}),t[75]=w,t[76]=L,t[77]=D):D=t[77];let P;t[78]!==i?(P=r.jsx(Bn,{open:i,onOpenChange:n}),t[78]=i,t[79]=P):P=t[79];let O;t[80]!==o||t[81]!==j?(O=r.jsx(hu,{open:o,onOpenChange:a,existingAgent:j}),t[80]=o,t[81]=j,t[82]=O):O=t[82];let z;t[83]!==l||t[84]!==y?(z=r.jsx(Xv,{open:l,onOpenChange:c,existingAgent:y}),t[83]=l,t[84]=y,t[85]=z):z=t[85];let $;t[86]!==d||t[87]!==C?($=r.jsx(eb,{open:d,onOpenChange:u,existingAgent:C}),t[86]=d,t[87]=C,t[88]=$):$=t[88];let W;return t[89]!==D||t[90]!==P||t[91]!==O||t[92]!==z||t[93]!==$?(W=r.jsxs(r.Fragment,{children:[D,P,O,z,$]}),t[89]=D,t[90]=P,t[91]=O,t[92]=z,t[93]=$,t[94]=W):W=t[94],W}function nb(t){return t.id!==null&&!Mn(t.id)}function ob(t){return t.id==="ai-research"}function ab(t){return t.id==="ai-image"}function lb(t){return t.id==="site-diagnostics"}function cb(t){return t.id==="site-editor"}function db(){const t=B.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=r.jsx("div",{className:"w-full max-md:overflow-x-auto max-md:[scrollbar-width:none] max-md:[&::-webkit-scrollbar]:hidden",children:r.jsx("div",{className:"flex flex-wrap justify-center gap-1.5 max-md:flex-nowrap max-md:justify-start md:max-h-52 md:overflow-hidden",children:Array.from({length:7}).map(hb)})}),t[0]=e):e=t[0],e}function hb(t,e){return r.jsxs("div",{className:"flex flex-col items-center gap-3 p-2 w-[100px] shrink-0",children:[r.jsx(Bi,{className:"size-12 rounded-xl shrink-0"}),r.jsx(Bi,{className:"h-3 sm:h-4 w-full"})]},e)}function Uc(){const t=B.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=r.jsx(S.Suspense,{fallback:r.jsx(db,{}),children:r.jsx(rb,{})}),t[0]=e):e=t[0],e}function sr(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}k`:String(t)}function Kc(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 ub(t){return t?t.replace(/-\d{8}(?:-[a-z0-9]+)*$/i,"").replace(/-/g," "):"—"}function fb(t){const e=B.c(4),{items:s}=t;let i;e[0]!==s?(i=s.map(mb),e[0]=s,e[1]=i):i=e[1];let n;return e[2]!==i?(n=r.jsx("div",{className:"grid grid-cols-2 gap-x-8 gap-y-6",children:i}),e[2]=i,e[3]=n):n=e[3],n}function mb(t){return r.jsxs("div",{className:"flex flex-col gap-1 min-w-0",children:[r.jsx("span",{className:"text-xs text-muted-foreground truncate",children:t.label}),r.jsx("span",{className:"text-sm text-foreground tabular-nums truncate",children:t.value})]},t.label)}function pb(t){const e=B.c(30),{userTokens:s,assistantTokens:i,otherTokens:n}=t,o=s+i+n,a=o>0?s/o*100:0,l=o>0?i/o*100:0,c=o>0?n/o*100:0;let d;e[0]!==a?(d=a>0&&r.jsx("div",{className:"h-full bg-chart-1",style:{width:`${a}%`}}),e[0]=a,e[1]=d):d=e[1];let u;e[2]!==l?(u=l>0&&r.jsx("div",{className:"h-full bg-chart-2",style:{width:`${l}%`}}),e[2]=l,e[3]=u):u=e[3];let h;e[4]!==c?(h=c>0&&r.jsx("div",{className:"h-full bg-muted-foreground/30",style:{width:`${c}%`}}),e[4]=c,e[5]=h):h=e[5];let f;e[6]!==d||e[7]!==u||e[8]!==h?(f=r.jsxs("div",{className:"flex h-2 w-full overflow-hidden rounded-full bg-muted",children:[d,u,h]}),e[6]=d,e[7]=u,e[8]=h,e[9]=f):f=e[9];let m;e[10]===Symbol.for("react.memo_cache_sentinel")?(m=r.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 g;e[13]!==p?(g=r.jsxs("div",{className:"flex items-center gap-1.5",children:[m,r.jsxs("span",{className:"text-xs text-muted-foreground",children:["User ",p,"%"]})]}),e[13]=p,e[14]=g):g=e[14];let _;e[15]===Symbol.for("react.memo_cache_sentinel")?(_=r.jsx("span",{className:"inline-block h-2 w-2 rounded-sm bg-chart-2 shrink-0"}),e[15]=_):_=e[15];let v;e[16]!==l?(v=l.toFixed(1),e[16]=l,e[17]=v):v=e[17];let x;e[18]!==v?(x=r.jsxs("div",{className:"flex items-center gap-1.5",children:[_,r.jsxs("span",{className:"text-xs text-muted-foreground",children:["Assistant ",v,"%"]})]}),e[18]=v,e[19]=x):x=e[19];let b;e[20]!==c||e[21]!==n?(b=n>0&&r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:"inline-block h-2 w-2 rounded-sm bg-muted-foreground/30 shrink-0"}),r.jsxs("span",{className:"text-xs text-muted-foreground",children:["Other ",c.toFixed(1),"%"]})]}),e[20]=c,e[21]=n,e[22]=b):b=e[22];let y;e[23]!==x||e[24]!==b||e[25]!==g?(y=r.jsxs("div",{className:"flex flex-wrap gap-x-3 gap-y-1",children:[g,x,b]}),e[23]=x,e[24]=b,e[25]=g,e[26]=y):y=e[26];let C;return e[27]!==y||e[28]!==f?(C=r.jsxs("div",{className:"flex flex-col gap-2",children:[f,y]}),e[27]=y,e[28]=f,e[29]=C):C=e[29],C}function gb(t){const e=B.c(19),{part:s}=t,i=s.input?.agent_id,n=ts(i),o=n?.title??"Subtask",a=n?.icon??null,l=s.state==="input-streaming"||s.state==="input-available"||s.state==="output-available"&&s.preliminary===!0,c=s.state==="output-error",d=s.state==="approval-requested";let u;e[0]!==a||e[1]!==o?(u=r.jsx(Ms,{icon:a,name:o,size:"xs",className:"size-6 rounded-md shrink-0"}),e[0]=a,e[1]=o,e[2]=u):u=e[2];const h=c?"text-destructive":"text-foreground";let f;e[3]!==h?(f=X("shrink-0 font-medium",h),e[3]=h,e[4]=f):f=e[4];let m;e[5]!==o||e[6]!==f?(m=r.jsx("span",{className:f,children:o}),e[5]=o,e[6]=f,e[7]=m):m=e[7];let p;e[8]!==s.input?(p=s.input?.prompt&&r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"text-muted-foreground/50",children:"·"}),r.jsx("span",{className:"truncate text-muted-foreground",children:s.input.prompt})]}),e[8]=s.input,e[9]=p):p=e[9];let g;e[10]!==d||e[11]!==c||e[12]!==l?(g=r.jsx("span",{className:"ml-auto shrink-0",children:l?r.jsx(Ee,{size:12,className:"animate-spin text-muted-foreground"}):c?r.jsx(Bg,{size:12,className:"text-destructive"}):d?r.jsx(ri,{size:12,className:"text-warning"}):r.jsx(p_,{size:12,className:"text-emerald-500"})}),e[10]=d,e[11]=c,e[12]=l,e[13]=g):g=e[13];let _;return e[14]!==u||e[15]!==m||e[16]!==p||e[17]!==g?(_=r.jsxs("div",{className:"flex items-center gap-2 text-xs min-w-0",children:[u,m,p,g]}),e[14]=u,e[15]=m,e[16]=p,e[17]=g,e[18]=_):_=e[18],_}function _b(t){const e=B.c(58),{onClose:s,back:i,className:n}=t,[o,a]=S.useState(null),{messages:l}=Ui(),{tasks:c,taskId:d}=es(),{selectedModel:u,selectedVirtualMcp:h}=ni();let f,m,p,g,_,v,x,b;if(e[0]!==i||e[1]!==n||e[2]!==l||e[3]!==s||e[4]!==o?.id||e[5]!==u||e[6]!==h?.title||e[7]!==d||e[8]!==c){b=Symbol.for("react.early_return_sentinel");e:{let j;e[17]!==d?(j=J=>J.id===d,e[17]=d,e[18]=j):j=e[18];const V=c.find(j),w=Eh(l),k=[...l].reverse().find(jb),T=k?.metadata?.usage,I=k?.metadata?.modelLimits?.contextWindow??u?.limits?.contextWindow??null,A=T?.contextTokens??T?.totalTokens??0,N=I&&I>0?(A/I*100).toFixed(1):null,E=l;let R;e[19]!==E?(R=E.filter(Cb).reduce(Vb,0),e[19]=E,e[20]=R):R=e[20];const M=R,L=l;let D;e[21]!==L?(D=L.filter(wb).reduce(Sb,0),e[21]=L,e[22]=D):D=e[22];const P=D,O=Math.max(0,w.totalTokens-M-P),z=l[0],$=l.at(-1),W=z?.metadata?.created_at??V?.created_at,F=$?.metadata?.created_at??V?.updated_at,G=l.filter(yb),q=l.flatMap(vb),H=u?.modelId?ub(u.modelId):"—",ee=h?.title??"Decopilot",K=[{label:"Session",value:V?.title??"New chat"},{label:"Messages",value:G.length},{label:"Agent",value:ee},{label:"Model",value:H},{label:"Context Limit",value:I?sr(I):"—"},{label:"Session Tokens (billed)",value:w.totalTokens>0?sr(w.totalTokens):"0"},{label:"Usage",value:N!==null?`${N}%`:"—"},{label:"Input Tokens",value:w.inputTokens>0?sr(w.inputTokens):"0"},{label:"Output Tokens",value:w.outputTokens>0?sr(w.outputTokens):"0"},{label:"Reasoning Tokens",value:w.reasoningTokens>0?sr(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:Kc(W)},{label:"Last Activity",value:Kc(F)}];if(!V&&G.length===0){let J;e[23]!==n?(J=X("flex flex-col h-full w-full border-l border-border bg-background",n),e[23]=n,e[24]=J):J=e[24];let ie;e[25]===Symbol.for("react.memo_cache_sentinel")?(ie=r.jsx("span",{className:"text-sm font-medium text-foreground",children:"Context"}),e[25]=ie):ie=e[25];let ue;e[26]!==i?(ue=i?r.jsx(aa,{size:14,className:"text-muted-foreground"}):r.jsx(ii,{size:14,className:"text-muted-foreground"}),e[26]=i,e[27]=ue):ue=e[27];let de;e[28]!==s||e[29]!==ue?(de=r.jsxs("div",{className:"h-11 px-4 flex items-center justify-between shrink-0 border-b border-border/50",children:[ie,r.jsx("button",{type:"button",onClick:s,className:"flex size-6 items-center justify-center rounded hover:bg-accent transition-colors",children:ue})]}),e[28]=s,e[29]=ue,e[30]=de):de=e[30];let xe;e[31]===Symbol.for("react.memo_cache_sentinel")?(xe=r.jsx("div",{className:"flex-1 flex items-center justify-center px-4 text-center",children:r.jsx("p",{className:"text-xs text-muted-foreground",children:"Start a conversation to see context"})}),e[31]=xe):xe=e[31];let oe;e[32]!==J||e[33]!==de?(oe=r.jsxs("div",{className:J,children:[de,xe]}),e[32]=J,e[33]=de,e[34]=oe):oe=e[34],b=oe;break e}e[35]!==n?(v=X("flex flex-col h-full w-full border-l border-border bg-background overflow-y-auto",n),e[35]=n,e[36]=v):v=e[36];let U;e[37]===Symbol.for("react.memo_cache_sentinel")?(U=r.jsx("span",{className:"text-sm font-medium text-foreground",children:"Context"}),e[37]=U):U=e[37];let te;e[38]!==i?(te=i?r.jsx(aa,{size:14}):r.jsx(ii,{size:14}),e[38]=i,e[39]=te):te=e[39],e[40]!==s||e[41]!==te?(x=r.jsxs("div",{className:"flex h-11 shrink-0 items-center justify-between border-b border-border/50 px-4",children:[U,r.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:te})]}),e[40]=s,e[41]=te,e[42]=x):x=e[42],f="flex flex-col gap-8 p-6",m=q.length>0&&r.jsxs("div",{className:"flex flex-col gap-3",children:[r.jsx("span",{className:"text-xs text-muted-foreground",children:"Subtasks"}),r.jsx("div",{className:"flex flex-col gap-1",children:q.map(xb)})]}),p=r.jsx(fb,{items:K});let Y;e[43]===Symbol.for("react.memo_cache_sentinel")?(Y=r.jsx("span",{className:"text-xs text-muted-foreground",children:"Context Breakdown"}),e[43]=Y):Y=e[43],e[44]!==P||e[45]!==O||e[46]!==M?(g=r.jsxs("div",{className:"flex flex-col gap-3",children:[Y,r.jsx(pb,{userTokens:M,assistantTokens:P,otherTokens:O})]}),e[44]=P,e[45]=O,e[46]=M,e[47]=g):g=e[47],_=G.length>0&&r.jsxs("div",{className:"flex flex-col gap-3",children:[r.jsx("span",{className:"text-xs text-muted-foreground",children:"Raw messages"}),r.jsx("div",{className:"flex flex-col gap-1",children:G.map(J=>{const ie=J.metadata?.created_at,ue=o?.id===J.id;return r.jsxs("div",{className:"rounded-md border border-border/50 overflow-hidden",children:[r.jsxs("button",{type:"button",onClick:()=>a(ue?null:J),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:[r.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[r.jsx("span",{className:X("shrink-0 font-medium",J.role==="user"?"text-chart-1":"text-chart-2"),children:J.role}),r.jsx("span",{className:"text-muted-foreground",children:"•"}),r.jsx("span",{className:"truncate text-muted-foreground font-mono",children:J.id})]}),ie&&r.jsx("span",{className:"shrink-0 text-muted-foreground tabular-nums",children:new Date(ie).toLocaleString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit"})})]}),ue&&r.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(J,null,2)})]},J.id)})})]})}e[0]=i,e[1]=n,e[2]=l,e[3]=s,e[4]=o?.id,e[5]=u,e[6]=h?.title,e[7]=d,e[8]=c,e[9]=f,e[10]=m,e[11]=p,e[12]=g,e[13]=_,e[14]=v,e[15]=x,e[16]=b}else f=e[9],m=e[10],p=e[11],g=e[12],_=e[13],v=e[14],x=e[15],b=e[16];if(b!==Symbol.for("react.early_return_sentinel"))return b;let y;e[48]!==f||e[49]!==m||e[50]!==p||e[51]!==g||e[52]!==_?(y=r.jsxs("div",{className:f,children:[m,p,g,_]}),e[48]=f,e[49]=m,e[50]=p,e[51]=g,e[52]=_,e[53]=y):y=e[53];let C;return e[54]!==v||e[55]!==x||e[56]!==y?(C=r.jsxs("div",{className:v,children:[x,y]}),e[54]=v,e[55]=x,e[56]=y,e[57]=C):C=e[57],C}function xb(t,e){return r.jsx(gb,{part:t},e)}function vb(t){return(t.parts??[]).filter(bb)}function bb(t){return t.type==="tool-subtask"}function yb(t){return t.role!=="system"}function Sb(t,e){const s=e.metadata?.usage;return t+(s?.outputTokens??0)}function wb(t){return t.role==="assistant"}function Vb(t,e){const s=e.metadata?.usage;return t+(s?.inputTokens??0)}function Cb(t){return t.role==="user"}function jb(t){return t.role==="assistant"&&t.metadata?.usage}function kb(t){const e=t;if(e.structuredContent)return e.structuredContent;const s=e.content?.find(i=>i.type==="text")?.text;if(s)try{return JSON.parse(s)}catch{return[]}return[]}function Nb(t){const e=B.c(25),{orgId:s,userId:i,connectionId:n,vmMap:o,owner:a,repo:l,enabled:c}=t,d=c===void 0?!0:c,u=n??null;let h;e[0]!==s||e[1]!==u?(h={connectionId:u,orgId:s},e[0]=s,e[1]=u,e[2]=h):h=e[2];const f=Me(h);let m;e[3]!==a||e[4]!==l?(m={owner:a,repo:l},e[3]=a,e[4]=l,e[5]=m):m=e[5];const p=d&&!!n&&!!a&&!!l;let g;e[6]!==f||e[7]!==m||e[8]!==p?(g={client:f,toolName:"list_branches",toolArguments:m,enabled:p,staleTime:3e4,select:Rb},e[6]=f,e[7]=m,e[8]=p,e[9]=g):g=e[9];const{data:_,isLoading:v,isError:x}=wi(g);let b,y;e[10]!==i||e[11]!==o?(y=new Set(Object.keys(o?.[i]??{})),b=[...y].sort().map(Ib),e[10]=i,e[11]=o,e[12]=b,e[13]=y):(b=e[12],y=e[13]);const C=b;let j;if(e[14]!==_||e[15]!==y){const T=Array.isArray(_)?_:_?.branches??[];let I;e[17]!==y?(I=A=>!y.has(A.name),e[17]=y,e[18]=I):I=e[18],j=T.filter(Eb).filter(I).map(Ab),e[14]=_,e[15]=y,e[16]=j}else j=e[16];const V=j,w=Array.isArray(_)?null:_?.default_branch??null;let k;return e[19]!==w||e[20]!==x||e[21]!==v||e[22]!==V||e[23]!==C?(k={yours:C,others:V,defaultBase:w,isLoading:v,isError:x},e[19]=w,e[20]=x,e[21]=v,e[22]=V,e[23]=C,e[24]=k):k=e[24],k}function Ab(t){return{name:t.name,source:"other",author:typeof t.commit?.author=="string"?t.commit.author:t.commit?.author?.login??null}}function Eb(t){return typeof t.name=="string"}function Ib(t){return{name:t,source:"yours"}}function Rb(t){return kb(t)}function Tb(t){const e=B.c(36),{orgId:s,userId:i,connectionId:n,owner:o,repo:a,vmMap:l,value:c,onChange:d}=t,[u,h]=S.useState(!1);let f;e[0]!==n||e[1]!==u||e[2]!==s||e[3]!==o||e[4]!==a||e[5]!==i||e[6]!==l?(f={orgId:s,userId:i,connectionId:n,vmMap:l,owner:o,repo:a,enabled:u},e[0]=n,e[1]=u,e[2]=s,e[3]=o,e[4]=a,e[5]=i,e[6]=l,e[7]=f):f=e[7];const{yours:m,others:p,isLoading:g,isError:_}=Nb(f);let v;e[8]!==d?(v=N=>{d(N),h(!1)},e[8]=d,e[9]=v):v=e[9];const x=v,b=c??"Select branch…";let y;e[10]===Symbol.for("react.memo_cache_sentinel")?(y=r.jsx(gr,{className:"h-3.5 w-3.5"}),e[10]=y):y=e[10];let C;e[11]!==b?(C=r.jsx(oi,{asChild:!0,children:r.jsxs(ne,{variant:"outline",size:"sm",className:"h-7 gap-1.5 px-2 font-mono text-xs",children:[y,r.jsx("span",{className:"max-w-[200px] truncate",children:b})]})}),e[11]=b,e[12]=C):C=e[12];let j;e[13]===Symbol.for("react.memo_cache_sentinel")?(j=r.jsx(o_,{placeholder:"Search branches…"}),e[13]=j):j=e[13];let V;e[14]!==_?(V=_&&r.jsx("div",{className:"p-3 text-xs text-muted-foreground",children:"Couldn't load branches from GitHub. You can still pick from your branches."}),e[14]=_,e[15]=V):V=e[15];let w;e[16]!==_||e[17]!==g||e[18]!==p.length||e[19]!==m.length?(w=!_&&!g&&m.length===0&&p.length===0&&r.jsx(r_,{children:"No branches found."}),e[16]=_,e[17]=g,e[18]=p.length,e[19]=m.length,e[20]=w):w=e[20];let k;e[21]!==x||e[22]!==m?(k=m.length>0&&r.jsx(yc,{heading:"Your branches",children:m.map(N=>r.jsxs(Sc,{value:N.name,onSelect:()=>x(N.name),children:[r.jsx(gr,{className:"mr-2 h-4 w-4"}),r.jsx("span",{className:"flex-1 truncate",children:N.name})]},N.name))}),e[21]=x,e[22]=m,e[23]=k):k=e[23];let T;e[24]!==p||e[25]!==x?(T=p.length>0&&r.jsxs(r.Fragment,{children:[r.jsx(n_,{}),r.jsx(yc,{heading:"Other branches in repo",children:p.map(N=>r.jsxs(Sc,{value:N.name,onSelect:()=>x(N.name),children:[r.jsx(gr,{className:"mr-2 h-4 w-4"}),r.jsx("span",{className:"flex-1 truncate",children:N.name}),N.author&&r.jsxs("span",{className:"text-xs text-muted-foreground",children:["@",N.author]})]},N.name))})]}),e[24]=p,e[25]=x,e[26]=T):T=e[26];let I;e[27]!==V||e[28]!==w||e[29]!==k||e[30]!==T?(I=r.jsx(ai,{className:"w-[min(420px,calc(100vw-2rem))] p-0",align:"start",children:r.jsxs(a_,{children:[j,r.jsxs(l_,{children:[V,w,k,T]})]})}),e[27]=V,e[28]=w,e[29]=k,e[30]=T,e[31]=I):I=e[31];let A;return e[32]!==u||e[33]!==I||e[34]!==C?(A=r.jsxs(li,{open:u,onOpenChange:h,children:[C,I]}),e[32]=u,e[33]=I,e[34]=C,e[35]=A):A=e[35],A}const Db=["radial-gradient(ellipse 25% 220% at -5% 120%, rgba(165,149,255,0.35) 0%, transparent 100%)","radial-gradient(ellipse 25% 220% at 105% -20%, rgba(208,236,26,0.32) 0%, transparent 100%)"].join(", "),Mb="/decotexture.svg";function qc(t){const e=B.c(7),{onClick:s}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i={backgroundImage:Db},e[0]=i):i=e[0];let n,o;e[1]===Symbol.for("react.memo_cache_sentinel")?(n=r.jsx("div",{className:"relative shrink-0 p-1.5 bg-[var(--brand-green-light)] rounded-lg border border-border",children:r.jsx(Ms,{icon:"/logos/deco%20logo.svg",name:"deco.cx",size:"xs",className:"border-0 rounded-none bg-transparent"})}),o=r.jsx("p",{className:"flex-1 relative text-sm font-medium text-foreground leading-none whitespace-nowrap",children:"Import your deco.cx site"}),e[1]=n,e[2]=o):(n=e[1],o=e[2]);let a;e[3]===Symbol.for("react.memo_cache_sentinel")?(a=r.jsx("img",{src:Mb,alt:"","aria-hidden":!0,className:"absolute pointer-events-none",style:{width:"274.5px",height:"272.25px",left:"calc(50% + 145.5px)",top:"calc(50% + 40px)",transform:"translate(-50%, -50%)"}}),e[3]=a):a=e[3];let l;e[4]===Symbol.for("react.memo_cache_sentinel")?(l=r.jsx("div",{className:"relative bg-background flex items-center justify-center size-8 rounded-md shrink-0",children:r.jsx(ro,{size:16,className:"text-foreground transition-transform group-hover:translate-x-0.5"})}),e[4]=l):l=e[4];let c;return e[5]!==s?(c=r.jsxs("button",{type:"button",onClick:s,className:"w-full relative flex items-center gap-4 px-4 py-4 rounded-lg border border-border bg-background overflow-hidden transition-colors text-left cursor-pointer group",style:i,children:[n,o,a,l]}),e[5]=s,e[6]=c):c=e[6],c}function Pb(){const t=B.c(5),{data:e}=St.useSession();let s;t[0]!==e?.user?.email?(s=lt.decoProfile(e?.user?.email),t[0]=e?.user?.email,t[1]=s):s=t[1];const i=!!e?.user?.email;let n;t[2]!==s||t[3]!==i?(n={queryKey:s,queryFn:Lb,enabled:i,staleTime:3e5},t[2]=s,t[3]=i,t[4]=n):n=t[4];const{data:o}=Fi(n);return o?.isDecoUser??!1}async function Lb(){const t=await fetch("/api/deco-sites/profile");return t.ok?t.json():{isDecoUser:!1}}function Bb(t){const e=B.c(56),{onOpenContextPanel:s}=t,{data:i}=St.useSession(),[n,o]=S.useState(!1),a=Pb(),l=Rs(),{hasDecoKey:c,isZeroBalance:d,isInitialFreeCredit:u,balanceDollars:h,hasOnlyDecoProvider:f}=co();let m;e[0]!==i?.user?.name?(m=i?.user?.name?.split(" ")[0]||"there",e[0]=i?.user?.name,e[1]=m):m=e[1];const p=m,g=c&&u&&h!=null,_=c&&d&&f;if(l){let N;e[2]!==h||e[3]!==g?(N=g&&r.jsx("div",{className:"mb-4",children:r.jsx(De.CreditsEyebrow,{balanceDollars:h})}),e[2]=h,e[3]=g,e[4]=N):N=e[4];let E;e[5]!==_?(E=_&&r.jsx("div",{className:"mb-4",children:r.jsx(De.NoCreditsEyebrow,{})}),e[5]=_,e[6]=E):E=e[6];let R;e[7]!==p?(R=r.jsxs("p",{className:"text-3xl font-medium text-foreground text-center max-w-[280px]",children:["What's on your mind, ",p,"?"]}),e[7]=p,e[8]=R):R=e[8];let M;e[9]!==N||e[10]!==E||e[11]!==R?(M=r.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center w-full",children:[N,E,R]}),e[9]=N,e[10]=E,e[11]=R,e[12]=M):M=e[12];let L;e[13]===Symbol.for("react.memo_cache_sentinel")?(L=r.jsx(Uc,{}),e[13]=L):L=e[13];let D;e[14]!==s?(D=r.jsxs("div",{className:"w-full flex flex-col gap-4 pb-4",children:[L,r.jsx(De.Input,{onOpenContextPanel:s,showConnectionsBanner:!0})]}),e[14]=s,e[15]=D):D=e[15];let P;e[16]!==a?(P=a&&r.jsx("div",{className:"w-full",children:r.jsx(qc,{onClick:()=>o(!0)})}),e[16]=a,e[17]=P):P=e[17];let O;e[18]!==M||e[19]!==D||e[20]!==P?(O=r.jsxs("div",{className:"flex-1 relative flex flex-col items-center px-4",children:[M,D,P]}),e[18]=M,e[19]=D,e[20]=P,e[21]=O):O=e[21];let z;e[22]!==n?(z=r.jsx(Bn,{open:n,onOpenChange:o}),e[22]=n,e[23]=z):z=e[23];let $;return e[24]!==z||e[25]!==O?($=r.jsxs(r.Fragment,{children:[O,z]}),e[24]=z,e[25]=O,e[26]=$):$=e[26],$}let v;e[27]!==h||e[28]!==g?(v=g&&r.jsx("div",{className:"mb-4",children:r.jsx(De.CreditsEyebrow,{balanceDollars:h})}),e[27]=h,e[28]=g,e[29]=v):v=e[29];let x;e[30]!==_?(x=_&&r.jsx("div",{className:"mb-4",children:r.jsx(De.NoCreditsEyebrow,{})}),e[30]=_,e[31]=x):x=e[31];let b;e[32]!==p?(b=r.jsxs("p",{className:"text-3xl font-medium text-foreground",children:["What's on your mind, ",p,"?"]}),e[32]=p,e[33]=b):b=e[33];let y;e[34]!==v||e[35]!==x||e[36]!==b?(y=r.jsxs("div",{className:"text-center mb-10",children:[v,x,b]}),e[34]=v,e[35]=x,e[36]=b,e[37]=y):y=e[37];let C;e[38]!==s?(C=r.jsx("div",{className:"w-full",children:r.jsx(De.Input,{onOpenContextPanel:s,showConnectionsBanner:!0})}),e[38]=s,e[39]=C):C=e[39];let j;e[40]!==y||e[41]!==C?(j=r.jsxs("div",{className:"flex flex-col items-center w-full max-w-[672px]",children:[y,C]}),e[40]=y,e[41]=C,e[42]=j):j=e[42];let V;e[43]===Symbol.for("react.memo_cache_sentinel")?(V=r.jsx("div",{className:"w-full mt-10 mx-auto",children:r.jsx(Uc,{})}),e[43]=V):V=e[43];let w;e[44]!==j?(w=r.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center w-full",children:[j,V]}),e[44]=j,e[45]=w):w=e[45];let k;e[46]!==a?(k=a&&r.jsx("div",{className:"absolute bottom-6 left-0 right-0 px-10",children:r.jsx("div",{className:"w-full max-w-[500px] mx-auto",children:r.jsx(qc,{onClick:()=>o(!0)})})}),e[46]=a,e[47]=k):k=e[47];let T;e[48]!==k||e[49]!==w?(T=r.jsxs("div",{className:"flex-1 relative flex flex-col items-center px-10",children:[w,k]}),e[48]=k,e[49]=w,e[50]=T):T=e[50];let I;e[51]!==n?(I=r.jsx(Bn,{open:n,onOpenChange:o}),e[51]=n,e[52]=I):I=e[52];let A;return e[53]!==T||e[54]!==I?(A=r.jsxs(r.Fragment,{children:[T,I]}),e[53]=T,e[54]=I,e[55]=A):A=e[55],A}function Ob(){const t=B.c(26),{org:e}=be(),{selectedVirtualMcp:s}=ni(),{data:i}=St.useSession(),{currentBranch:n,setCurrentTaskBranch:o}=es();let a;t[0]!==e.id?(a=io(e.id),t[0]=e.id,t[1]=a):a=t[1];const c=s??a,d=ts(c.id),u=i?.user?.id??"",h=d?.metadata?.githubRepo??null,f=!!h?.connectionId&&!!u;let m;t[2]===Symbol.for("react.memo_cache_sentinel")?(m=r.jsx(ao,{size:32}),t[2]=m):m=t[2];let p;t[3]!==c.icon||t[4]!==c.title?(p=r.jsx(Ms,{icon:c.icon,name:c.title,size:"lg",fallbackIcon:m,className:"size-10 min-w-10 md:size-[60px]! md:min-w-[60px] rounded-xl md:rounded-[18px]!"}),t[3]=c.icon,t[4]=c.title,t[5]=p):p=t[5];let g;t[6]!==c.title?(g=r.jsx("h3",{className:"text-base md:text-xl font-medium text-foreground",children:c.title}),t[6]=c.title,t[7]=g):g=t[7];const _=c.description??"Ask anything about configuring model providers or using MCP Mesh.";let v;t[8]!==_?(v=r.jsx("div",{className:"text-muted-foreground text-center text-base max-w-md line-clamp-2",children:_}),t[8]=_,t[9]=v):v=t[9];let x;t[10]!==n||t[11]!==d?.metadata?.vmMap||t[12]!==h||t[13]!==e.id||t[14]!==o||t[15]!==f||t[16]!==u?(x=f&&r.jsx("div",{className:"mt-2",children:r.jsx(Tb,{orgId:e.id,userId:u,connectionId:h.connectionId,owner:h.owner,repo:h.name,vmMap:d?.metadata?.vmMap,value:n??void 0,onChange:o})}),t[10]=n,t[11]=d?.metadata?.vmMap,t[12]=h,t[13]=e.id,t[14]=o,t[15]=f,t[16]=u,t[17]=x):x=t[17];let b;t[18]!==p||t[19]!==g||t[20]!==v||t[21]!==x?(b=r.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 md:gap-4 text-center",children:[p,g,v,x]}),t[18]=p,t[19]=g,t[20]=v,t[21]=x,t[22]=b):b=t[22];let y;t[23]===Symbol.for("react.memo_cache_sentinel")?(y=r.jsx("div",{className:"w-full max-w-3xl mx-auto",children:r.jsx(De.IceBreakers,{})}),t[23]=y):y=t[23];let C;return t[24]!==b?(C=r.jsxs("div",{className:"h-full w-full flex flex-col items-center justify-center gap-6 px-4",children:[b,y]}),t[24]=b,t[25]=C):C=t[25],C}function $b(t){const e=B.c(27),{variant:s}=t,{org:i}=be(),n=bl(),{isChatEmpty:o}=Ui(),[a,l]=S.useState("chat"),c=co();if(n.length===0){let C;return e[0]===Symbol.for("react.memo_cache_sentinel")?(C=r.jsx(De,{className:"animate-in fade-in-0 duration-200",children:r.jsx(De.Main,{className:"flex flex-col items-center",children:r.jsx(De.EmptyState,{children:r.jsx(De.NoAiProviderEmptyState,{})})})}),e[0]=C):C=e[0],C}let d;e[1]!==c.hasDecoKey||e[2]!==c.hasOnlyDecoProvider||e[3]!==c.isLoading||e[4]!==c.isZeroBalance||e[5]!==o||e[6]!==i?(d=c.hasDecoKey&&c.isZeroBalance&&c.hasOnlyDecoProvider&&!c.isLoading&&o&&!Rv(i.id),e[1]=c.hasDecoKey,e[2]=c.hasOnlyDecoProvider,e[3]=c.isLoading,e[4]=c.isZeroBalance,e[5]=o,e[6]=i,e[7]=d):d=e[7];const u=d;let h;e[8]!==u?(h=u&&r.jsx(De.CreditsEmptyState,{}),e[8]=u,e[9]=h):h=e[9];const f=a!=="chat"?"opacity-0 pointer-events-none":"opacity-100";let m;e[10]!==f?(m=X("absolute inset-0 flex flex-col transition-opacity duration-100 ease-out",f),e[10]=f,e[11]=m):m=e[11];let p;e[12]!==o||e[13]!==s?(p=o?s==="home"?r.jsx(Bb,{onOpenContextPanel:()=>l("context")}):r.jsxs(r.Fragment,{children:[r.jsx(De.Main,{children:r.jsx(Ob,{})}),r.jsx(De.Footer,{children:r.jsx(De.Input,{onOpenContextPanel:()=>l("context")})})]}):r.jsxs(r.Fragment,{children:[r.jsx(De.Main,{children:r.jsx(De.Messages,{})}),r.jsx(De.Footer,{children:r.jsx(De.Input,{onOpenContextPanel:()=>l("context")})})]}),e[12]=o,e[13]=s,e[14]=p):p=e[14];let g;e[15]!==m||e[16]!==p?(g=r.jsx("div",{className:m,children:p}),e[15]=m,e[16]=p,e[17]=g):g=e[17];const _=a==="context"?"opacity-100":"opacity-0 pointer-events-none";let v;e[18]!==_?(v=X("absolute inset-0 flex flex-col transition-opacity duration-100 ease-out",_),e[18]=_,e[19]=v):v=e[19];let x;e[20]===Symbol.for("react.memo_cache_sentinel")?(x=r.jsx(_b,{back:!0,onClose:()=>l("chat")}),e[20]=x):x=e[20];let b;e[21]!==v?(b=r.jsx("div",{className:v,children:x}),e[21]=v,e[22]=b):b=e[22];let y;return e[23]!==b||e[24]!==h||e[25]!==g?(y=r.jsxs(De,{className:"relative overflow-hidden animate-in fade-in-0 duration-200",children:[h,g,b]}),e[23]=b,e[24]=h,e[25]=g,e[26]=y):y=e[26],y}function Ku(t){const e=B.c(4),{variant:s}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=r.jsx(De.Skeleton,{}),e[0]=i):i=e[0];let n;e[1]===Symbol.for("react.memo_cache_sentinel")?(n=r.jsx(De.Skeleton,{}),e[1]=n):n=e[1];let o;return e[2]!==s?(o=r.jsx(Cs,{fallback:i,children:r.jsx(S.Suspense,{fallback:n,children:r.jsx($b,{variant:s})})}),e[2]=s,e[3]=o):o=e[3],o}function zb(){const t=B.c(6),{org:e,locator:s}=be(),i=Mt();let n;t[0]!==s||t[1]!==i?(n=()=>{i.invalidateQueries({queryKey:lt.tasksPrefix(s)})},t[0]=s,t[1]=i,t[2]=n):n=t[2];let o;t[3]!==e.id||t[4]!==n?(o={orgId:e.id,onTaskStatus:n},t[3]=e.id,t[4]=n,t[5]=o):o=t[5],__(o)}function Fb(t){const e=B.c(8),{virtualMcpId:s,size:i,showAutomationBadge:n}=t,o=i===void 0?"sm":i;let a;e[0]!==o||e[1]!==s?(a=s?r.jsx(Hb,{virtualMcpId:s,size:o}):r.jsx(zs,{icon:null,name:"?",size:o}),e[0]=o,e[1]=s,e[2]=a):a=e[2];let l;e[3]!==n?(l=n&&r.jsx("span",{"aria-label":"Automation-triggered",className:"absolute -bottom-0.5 -right-0.5 flex size-4 items-center justify-center rounded-full bg-blue-500 border border-blue-600 text-white",children:r.jsx($i,{size:10,className:"text-white"})}),e[3]=n,e[4]=l):l=e[4];let c;return e[5]!==a||e[6]!==l?(c=r.jsxs("div",{className:"relative shrink-0",children:[a,l]}),e[5]=a,e[6]=l,e[7]=c):c=e[7],c}function Hb(t){const e=B.c(6),{virtualMcpId:s,size:i}=t,n=ts(s);if(!n){let l;return e[0]!==i?(l=r.jsx(zs,{icon:null,name:"?",size:i}),e[0]=i,e[1]=l):l=e[1],l}const o=n.icon??null;let a;return e[2]!==n.title||e[3]!==i||e[4]!==o?(a=r.jsx(zs,{icon:o,name:n.title,size:i}),e[2]=n.title,e[3]=i,e[4]=o,e[5]=a):a=e[5],a}function Fs(t){const e=t?.metadata?.githubRepo;return e?.connectionId&&t?.connections?.some(i=>i.connection_id===e.connectionId)?e:null}function Wb(t){const e=B.c(42),{task:s,isActive:i,onClick:n,onArchive:o,showAutomationBadge:a}=t,l=$p(s.status),c=l.icon,d=ts(s.virtual_mcp_id);let u;e[0]!==d?(u=Fs(d),e[0]=d,e[1]=u):u=e[1];const h=u,f="button",m=0;let p;e[2]!==n?(p=O=>{O.target===O.currentTarget&&(O.key==="Enter"||O.key===" ")&&(O.preventDefault(),n())},e[2]=n,e[3]=p):p=e[3];const g=i?"bg-accent":"hover:bg-accent/60";let _;e[4]!==g?(_=X("group/row flex items-center gap-3 px-2 py-1.5 rounded-md cursor-pointer transition-colors",g),e[4]=g,e[5]=_):_=e[5];let v;e[6]!==a||e[7]!==s.virtual_mcp_id?(v=r.jsx(Fb,{virtualMcpId:s.virtual_mcp_id,size:"sm",showAutomationBadge:a}),e[6]=a,e[7]=s.virtual_mcp_id,e[8]=v):v=e[8];const x=s.title||"Untitled task";let b;e[9]!==x?(b=r.jsx("div",{className:"text-sm text-foreground truncate",children:x}),e[9]=x,e[10]=b):b=e[10];let y;e[11]!==h||e[12]!==s.branch||e[13]!==s.updated_at?(y=s.updated_at&&r.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground min-w-0",children:[s.branch?r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"truncate font-mono",children:s.branch}),r.jsx("span",{className:"shrink-0",children:"·"})]}):h?r.jsxs(r.Fragment,{children:[r.jsxs("span",{className:"truncate",children:[h.owner,"/",h.name]}),r.jsx("span",{className:"shrink-0",children:"·"})]}):null,r.jsx("span",{className:"shrink-0",children:zp(new Date(s.updated_at))})]}),e[11]=h,e[12]=s.branch,e[13]=s.updated_at,e[14]=y):y=e[14];let C;e[15]!==y||e[16]!==b?(C=r.jsxs("div",{className:"flex-1 min-w-0",children:[b,y]}),e[15]=y,e[16]=b,e[17]=C):C=e[17];const j="shrink-0 grid [grid-template-areas:'slot'] items-center justify-items-center",V="[grid-area:slot] flex size-7 items-center justify-center group-hover/row:invisible",w=l.label,k=14,T=X(l.iconClassName,s.status==="in_progress"&&"animate-spin");let I;e[18]!==c||e[19]!==T?(I=r.jsx(c,{size:k,className:T}),e[18]=c,e[19]=T,e[20]=I):I=e[20];let A;e[21]!==l||e[22]!==I?(A=r.jsx("span",{className:V,"aria-label":w,children:I}),e[21]=l,e[22]=I,e[23]=A):A=e[23];let N;e[24]!==o?(N=O=>{O.stopPropagation(),o()},e[24]=o,e[25]=N):N=e[25];let E;e[26]===Symbol.for("react.memo_cache_sentinel")?(E=r.jsx(gg,{size:14}),e[26]=E):E=e[26];let R;e[27]!==N?(R=r.jsx(tt,{asChild:!0,children:r.jsx("button",{type:"button","aria-label":"Archive task",onClick:N,className:"[grid-area:slot] invisible group-hover/row:visible flex size-7 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-muted",children:E})}),e[27]=N,e[28]=R):R=e[28];let M;e[29]===Symbol.for("react.memo_cache_sentinel")?(M=r.jsx(st,{side:"right",children:"Archive"}),e[29]=M):M=e[29];let L;e[30]!==R?(L=r.jsxs(it,{children:[R,M]}),e[30]=R,e[31]=L):L=e[31];let D;e[32]!==A||e[33]!==L?(D=r.jsxs("div",{className:j,children:[A,L]}),e[32]=A,e[33]=L,e[34]=D):D=e[34];let P;return e[35]!==n||e[36]!==C||e[37]!==D||e[38]!==p||e[39]!==_||e[40]!==v?(P=r.jsxs("div",{role:f,tabIndex:m,onClick:n,onKeyDown:p,className:_,children:[v,C,D]}),e[35]=n,e[36]=C,e[37]=D,e[38]=p,e[39]=_,e[40]=v,e[41]=P):P=e[41],P}const qu={all:"All tasks",manual:"Chats",automation:"Automation"},Gu={all:"All members",mine:"Mine only"};function Ub(t){const e=B.c(57),{title:s,tasks:i,activeTaskId:n,onSelect:o,onArchive:a,onNew:l,showNewButton:c,showAutomationBadge:d,emptyLabel:u,currentUserId:h}=t,[f,m]=S.useState("all"),[p,g]=S.useState("mine");let _;e[0]!==h||e[1]!==p||e[2]!==i?(_=p==="mine"&&h?i.filter(G=>G.created_by===h):i,e[0]=h,e[1]=p,e[2]=i,e[3]=_):_=e[3];const v=_;let x;e[4]!==f||e[5]!==v?(x=f==="automation"?v.filter(Yb):f==="manual"?v.filter(Gb):v,e[4]=f,e[5]=v,e[6]=x):x=e[6];const b=x;let y;e[7]!==s?(y=r.jsx("span",{children:s}),e[7]=s,e[8]=y):y=e[8];let C;e[9]!==p?(C=r.jsx(ks,{asChild:!0,children:r.jsx("button",{type:"button","aria-label":"Filter by member",className:"flex size-8 items-center justify-center rounded-md hover:bg-muted hover:text-foreground",children:p==="mine"?r.jsx(_g,{size:16}):r.jsx(ao,{size:16})})}),e[9]=p,e[10]=C):C=e[10];let j;e[11]!==p?(j=G=>{const q=G;q!==p&&se("tasks_panel_member_filter_changed",{to_value:q}),g(q)},e[11]=p,e[12]=j):j=e[12];let V;e[13]===Symbol.for("react.memo_cache_sentinel")?(V=Object.keys(Gu),e[13]=V):V=e[13];let w;e[14]===Symbol.for("react.memo_cache_sentinel")?(w=V.map(qb),e[14]=w):w=e[14];let k;e[15]!==p||e[16]!==j?(k=r.jsx(Ns,{align:"end",children:r.jsx(hc,{value:p,onValueChange:j,children:w})}),e[15]=p,e[16]=j,e[17]=k):k=e[17];let T;e[18]!==C||e[19]!==k?(T=r.jsxs(js,{children:[C,k]}),e[18]=C,e[19]=k,e[20]=T):T=e[20];const I=f!=="all"&&"text-purple-500";let A;e[21]!==I?(A=X("flex size-8 items-center justify-center rounded-md hover:bg-muted hover:text-foreground",I),e[21]=I,e[22]=A):A=e[22];let N;e[23]===Symbol.for("react.memo_cache_sentinel")?(N=r.jsx(Og,{size:16}),e[23]=N):N=e[23];let E;e[24]!==A?(E=r.jsx(ks,{asChild:!0,children:r.jsx("button",{type:"button","aria-label":"Filter tasks",className:A,children:N})}),e[24]=A,e[25]=E):E=e[25];let R;e[26]!==f?(R=G=>{const q=G;q!==f&&se("tasks_panel_filter_changed",{to_value:q}),m(q)},e[26]=f,e[27]=R):R=e[27];let M;e[28]===Symbol.for("react.memo_cache_sentinel")?(M=Object.keys(qu),e[28]=M):M=e[28];let L;e[29]===Symbol.for("react.memo_cache_sentinel")?(L=M.map(Kb),e[29]=L):L=e[29];let D;e[30]!==f||e[31]!==R?(D=r.jsx(Ns,{align:"end",children:r.jsx(hc,{value:f,onValueChange:R,children:L})}),e[30]=f,e[31]=R,e[32]=D):D=e[32];let P;e[33]!==E||e[34]!==D?(P=r.jsxs(js,{children:[E,D]}),e[33]=E,e[34]=D,e[35]=P):P=e[35];let O;e[36]!==l||e[37]!==c||e[38]!==s?(O=c&&l&&r.jsx("button",{type:"button",onClick:()=>{se("tasks_panel_new_clicked"),l()},"aria-label":`New ${s.toLowerCase()}`,className:"flex size-8 items-center justify-center rounded-md hover:bg-muted hover:text-foreground",children:r.jsx(pl,{size:16})}),e[36]=l,e[37]=c,e[38]=s,e[39]=O):O=e[39];let z;e[40]!==P||e[41]!==O||e[42]!==T?(z=r.jsxs("div",{className:"flex items-center gap-0.5",children:[T,P,O]}),e[40]=P,e[41]=O,e[42]=T,e[43]=z):z=e[43];let $;e[44]!==z||e[45]!==y?($=r.jsxs("div",{className:"pl-2 pr-1.5 h-7 flex items-center justify-between text-xs font-medium text-muted-foreground mb-1",children:[y,z]}),e[44]=z,e[45]=y,e[46]=$):$=e[46];let W;e[47]!==n||e[48]!==u||e[49]!==a||e[50]!==o||e[51]!==d||e[52]!==b?(W=b.length===0&&u?r.jsx("div",{className:"px-2 py-1.5 text-xs text-muted-foreground/70",children:u}):b.map(G=>r.jsx(Wb,{task:G,isActive:n===G.id,onClick:()=>{n!==G.id&&se("tasks_panel_task_clicked",{thread_id:G.id,virtual_mcp_id:G.virtual_mcp_id??null,from_automation:!!G.fromAutomation}),o(G)},onArchive:()=>{se("tasks_panel_task_archived",{thread_id:G.id,virtual_mcp_id:G.virtual_mcp_id??null}),a(G)},showAutomationBadge:d||G.fromAutomation},G.id)),e[47]=n,e[48]=u,e[49]=a,e[50]=o,e[51]=d,e[52]=b,e[53]=W):W=e[53];let F;return e[54]!==$||e[55]!==W?(F=r.jsxs("div",{className:"flex flex-col gap-0.5 mt-1",children:[$,W]}),e[54]=$,e[55]=W,e[56]=F):F=e[56],F}function Kb(t){return r.jsx(Oh,{value:t,children:qu[t]},t)}function qb(t){return r.jsx(Oh,{value:t,children:Gu[t]},t)}function Gb(t){return!t.fromAutomation}function Yb(t){return t.fromAutomation}function Xb(){const t=B.c(22);zb();const{data:e}=St.useSession(),s=e?.user?.id;let i;t[0]===Symbol.for("react.memo_cache_sentinel")?(i={owner:"me",status:"open",hasTrigger:!1},t[0]=i):i=t[0];const{tasks:n}=ia(i);let o;t[1]===Symbol.for("react.memo_cache_sentinel")?(o={owner:"all",status:"open",hasTrigger:!0},t[1]=o):o=t[1];const{tasks:a}=ia(o),{setTaskId:l,createNewTask:c}=zr();let d;t[2]===Symbol.for("react.memo_cache_sentinel")?(d={strict:!1},t[2]=d):d=t[2];const u=$r(d),{locator:h,org:f}=be(),m=Mt();let p;t[3]!==f.id?(p={connectionId:Wt,orgId:f.id},t[3]=f.id,t[4]=p):p=t[4];const g=Me(p),_=u.taskId??null;let v;t[5]!==a||t[6]!==n?(v=[...n,...a.map(Qb)].sort(Jb),t[5]=a,t[6]=n,t[7]=v):v=t[7];const x=v;let b;t[8]!==g||t[9]!==h||t[10]!==m?(b=async V=>{try{await Ap(g,V.id,{hidden:!0}),m.invalidateQueries({queryKey:lt.tasksPrefix(h)})}catch(w){const T=w;ge.error(`Failed to archive task: ${T.message}`)}},t[8]=g,t[9]=h,t[10]=m,t[11]=b):b=t[11];const y=b;if(x.length===0){let V;return t[12]===Symbol.for("react.memo_cache_sentinel")?(V=r.jsx("div",{className:"h-full flex items-center justify-center p-4",children:r.jsx(Oi,{image:r.jsx(xg,{size:48,className:"text-muted-foreground"}),title:"No tasks yet",description:"Start a conversation to create your first task."})}),t[12]=V):V=t[12],V}let C;t[13]!==l?(C=V=>l(V.id,V.virtual_mcp_id),t[13]=l,t[14]=C):C=t[14];let j;return t[15]!==_||t[16]!==x||t[17]!==c||t[18]!==s||t[19]!==y||t[20]!==C?(j=r.jsx("div",{className:"flex flex-col h-full min-h-0 overflow-y-auto p-2 gap-3",children:r.jsx(Ub,{title:"Tasks",tasks:x,activeTaskId:_,onSelect:C,onArchive:y,onNew:c,showNewButton:!0,currentUserId:s})}),t[15]=_,t[16]=x,t[17]=c,t[18]=s,t[19]=y,t[20]=C,t[21]=j):j=t[21],j}function Jb(t,e){return(e.updated_at??"").localeCompare(t.updated_at??"")}function Qb(t){return{...t,fromAutomation:!0}}function Zb(){const t=B.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=r.jsx("div",{className:"flex flex-col h-full p-2 gap-1.5",children:Array.from({length:6}).map(e0)}),t[0]=e):e=t[0],e}function e0(t,e){return r.jsx("div",{className:"h-10 rounded-md bg-muted/60 animate-pulse"},e)}function Yu(){const t=B.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=r.jsx(De.Skeleton,{}),t[0]=e):e=t[0];let s;return t[1]===Symbol.for("react.memo_cache_sentinel")?(s=r.jsx(Cs,{fallback:e,children:r.jsx(S.Suspense,{fallback:r.jsx(Zb,{}),children:r.jsx(Xb,{})})}),t[1]=s):s=t[1],s}function Xu(){const t=B.c(77),{org:e}=be(),s=Ke(),i=Vh(),{setTasksOpen:n,openTab:o}=zr(),a=e.slug,l=be().project;let c;t[0]===Symbol.for("react.memo_cache_sentinel")?(c={strict:!1},t[0]=c):c=t[0];const d=$r(c);let u;t[1]===Symbol.for("react.memo_cache_sentinel")?(u={strict:!1},t[1]=u):u=t[1];const h=vi(u),f=i.location.pathname;let m;t[2]!==l.enabledPlugins?(m=l.enabledPlugins??[],t[2]=l.enabledPlugins,t[3]=m):m=t[3];const p=m;let g;t[4]!==l.ui?(g=l.ui?.pinnedViews??[],t[4]=l.ui,t[5]=g):g=t[5];const _=g;let v,x,b,y;if(t[6]!==l.id||t[7]!==p||t[8]!==s||t[9]!==a||t[10]!==d.pluginId||t[11]!==d.taskId||t[12]!==h.virtualmcpid){let q;t[17]!==p?(q=ie=>p.includes(ie.pluginId),t[17]=p,t[18]=q):q=t[18];const H=Zm.filter(q),ee=h.virtualmcpid??l.id;x=!!h.virtualmcpid;const K=d.taskId??"",U=d.pluginId;let te;t[19]!==U?(te=ie=>U===ie,t[19]=U,t[20]=te):te=t[20],v=te;let Y;t[21]!==K||t[22]!==s||t[23]!==a||t[24]!==ee?(Y=ie=>{const ue=K||crypto.randomUUID();s({to:"/$org/$taskId/$pluginId",params:{org:a,taskId:ue,pluginId:ie},search:de=>({...de,virtualmcpid:ee})})},t[21]=K,t[22]=s,t[23]=a,t[24]=ee,t[25]=Y):Y=t[25],b=Y;let J;t[26]!==v||t[27]!==b?(J=ie=>({key:ie.pluginId,label:ie.label,icon:ie.icon,isActive:v(ie.pluginId),onClick:()=>b(ie.pluginId)}),t[26]=v,t[27]=b,t[28]=J):J=t[28],y=H.map(J),t[6]=l.id,t[7]=p,t[8]=s,t[9]=a,t[10]=d.pluginId,t[11]=d.taskId,t[12]=h.virtualmcpid,t[13]=v,t[14]=x,t[15]=b,t[16]=y}else v=t[13],x=t[14],b=t[15],y=t[16];const C=y;let j;if(t[29]!==p||t[30]!==v||t[31]!==b){let q;t[33]!==p?(q=K=>p.includes(K.pluginId),t[33]=p,t[34]=q):q=t[34];const H=ep.filter(q);let ee;t[35]!==v||t[36]!==b?(ee=K=>({type:"group",group:{id:`${K.pluginId}-${K.id}`,label:K.label,items:K.items.map((U,te)=>({key:`${K.pluginId}-${K.id}-${te}`,label:U.label,icon:U.icon,isActive:v(K.pluginId),onClick:()=>b(K.pluginId)})),defaultExpanded:K.defaultExpanded??!0}}),t[35]=v,t[36]=b,t[37]=ee):ee=t[37],j=H.map(ee),t[29]=p,t[30]=v,t[31]=b,t[32]=j}else j=t[32];const V=j;let w;if(t[38]!==o||t[39]!==_){let q;t[41]!==o?(q=H=>{const ee=Fr(H.icon),K=ee.type==="icon"?Hr(ee.name):null;return{key:`app-${H.connectionId}-${H.toolName}`,label:H.label||H.toolName,icon:K?r.jsx(K,{size:16,className:"text-muted-foreground"}):ee.type==="url"?r.jsx("img",{src:ee.url,alt:"",className:"size-4 rounded"}):r.jsx(pu,{size:16,className:"text-muted-foreground"}),isActive:!1,onClick:()=>o(ra(H.connectionId,H.toolName))}},t[41]=o,t[42]=q):q=t[42],w=_.map(q),t[38]=o,t[39]=_,t[40]=w}else w=t[40];const k=w;let T;t[43]!==k?(T=k.length>0?{type:"group",group:{id:"apps",label:"Apps",items:k,defaultExpanded:!0}}:null,t[43]=k,t[44]=T):T=t[44];const I=T;let A;t[45]===Symbol.for("react.memo_cache_sentinel")?(A=r.jsx(vg,{className:"size-4!"}),t[45]=A):A=t[45];const N=f===`/${a}`||f===`/${a}/`;let E;t[46]!==s||t[47]!==a||t[48]!==n?(E=()=>{n(!1),s({to:"/$org",params:{org:a}})},t[46]=s,t[47]=a,t[48]=n,t[49]=E):E=t[49];let R;t[50]!==E||t[51]!==N?(R={key:"home",label:"Home",icon:A,isActive:N,onClick:E},t[50]=E,t[51]=N,t[52]=R):R=t[52];const M=R;let L;t[53]!==p?(L=p.includes(tp),t[53]=p,t[54]=L):L=t[54];const D=L;let P;t[55]===Symbol.for("react.memo_cache_sentinel")?(P=r.jsx(sp,{className:"size-4!"}),t[55]=P):P=t[55];let O;t[56]!==a||t[57]!==f?(O=f.startsWith(`/${a}/settings/workflows`),t[56]=a,t[57]=f,t[58]=O):O=t[58];let z;t[59]!==s||t[60]!==a?(z=()=>s({to:"/$org/settings/workflows",params:{org:a}}),t[59]=s,t[60]=a,t[61]=z):z=t[61];let $;t[62]!==O||t[63]!==z?($={key:"workflows",label:"Workflows",icon:P,isActive:O,onClick:z},t[62]=O,t[63]=z,t[64]=$):$=t[64];const W=$;let F;if(t[65]!==M||t[66]!==x||t[67]!==D||t[68]!==W){const q=[M];x&&D&&q.push(W),F={type:"items",items:q},t[65]=M,t[66]=x,t[67]=D,t[68]=W,t[69]=F}else F=t[69];let G;if(t[70]!==I||t[71]!==V||t[72]!==C||t[73]!==F){if(G=[F],C.length>0){let q;t[75]!==C?(q={type:"items",items:C},t[75]=C,t[76]=q):q=t[76],G.push(q)}V.length>0&&G.push(...V),I&&G.push(I),t[70]=I,t[71]=V,t[72]=C,t[73]=F,t[74]=G}else G=t[74];return G}function Ju(t){const e=B.c(3),{children:s}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=r.jsx("div",{className:"flex h-6 items-center",children:r.jsx("div",{className:"h-0.5 w-16 rounded-full bg-sidebar-foreground/15"})}),e[0]=i):i=e[0];let n;return e[1]!==s?(n=r.jsxs(Ur,{className:"pt-0 pr-0 pb-2 pl-0 mt-2",children:[i,r.jsx(Kr,{children:r.jsx(gs,{className:"gap-0.5",children:s})})]}),e[1]=s,e[2]=n):n=e[2],n}function t0(){const t=B.c(7),s=Ch().logo??jh,i=typeof s=="string"?s:s.light,n=typeof s=="string"?s:s.dark;let o;t[0]!==i?(o=r.jsx("img",{src:i,alt:"Logo",className:"size-6 object-contain dark:hidden"}),t[0]=i,t[1]=o):o=t[1];let a;t[2]!==n?(a=r.jsx("img",{src:n,alt:"Logo",className:"size-6 object-contain hidden dark:block"}),t[2]=n,t[3]=a):a=t[3];let l;return t[4]!==o||t[5]!==a?(l=r.jsx(xu,{className:"flex items-center justify-center shrink-0 px-2 pb-0",children:r.jsxs("div",{className:"flex w-full aspect-square items-center justify-center",children:[o,a]})}),t[4]=o,t[5]=a,t[6]=l):l=t[6],l}function Qu(t){const e=B.c(15),{item:s}=t,{isMobile:i,setOpenMobile:n}=qr();let o;e[0]!==i||e[1]!==s||e[2]!==n?(o=()=>{se("nav_item_clicked",{nav_key:s.key,nav_label:s.label,is_active:!!s.isActive,is_mobile:i}),s.onClick?.(),i&&n(!1)},e[0]=i,e[1]=s,e[2]=n,e[3]=o):o=e[3];const a=o,l=s.key,c=s.isActive&&"z-10";let d;e[4]!==c?(d=X(c),e[4]=c,e[5]=d):d=e[5];let u;e[6]!==a||e[7]!==s.icon||e[8]!==s.isActive||e[9]!==s.label?(u=r.jsx(us,{onClick:a,isActive:s.isActive,tooltip:s.label,className:"bg-muted/75",children:s.icon}),e[6]=a,e[7]=s.icon,e[8]=s.isActive,e[9]=s.label,e[10]=u):u=e[10];let h;return e[11]!==s.key||e[12]!==d||e[13]!==u?(h=r.jsx(Zt,{className:d,children:u},l),e[11]=s.key,e[12]=d,e[13]=u,e[14]=h):h=e[14],h}function s0(t){const e=B.c(12),{section:s}=t;switch(s.type){case"divider":{let i;return e[0]===Symbol.for("react.memo_cache_sentinel")?(i=r.jsx(gu,{className:"my-2"}),e[0]=i):i=e[0],i}case"spacer":{let i;return e[1]===Symbol.for("react.memo_cache_sentinel")?(i=r.jsx("div",{className:"flex-1"}),e[1]=i):i=e[1],i}case"group":{const i=s.group.label,n=s.group.defaultExpanded;let o;e[2]!==s.group.items?(o=s.group.items.map(r0),e[2]=s.group.items,e[3]=o):o=e[3];let a;return e[4]!==s.group.defaultExpanded||e[5]!==s.group.label||e[6]!==o?(a=r.jsx(Ju,{label:i,defaultExpanded:n,children:o}),e[4]=s.group.defaultExpanded,e[5]=s.group.label,e[6]=o,e[7]=a):a=e[7],a}case"items":{let i;e[8]!==s.items?(i=s.items.map(i0),e[8]=s.items,e[9]=i):i=e[9];let n;return e[10]!==i?(n=r.jsx(Ur,{className:"pt-0 pr-0 pb-0 pl-0",children:r.jsx(Kr,{children:r.jsx(gs,{className:"gap-1.5",children:i})})}),e[10]=i,e[11]=n):n=e[11],n}}}function i0(t){return r.jsx(Qu,{item:t},t.key)}function r0(t){return r.jsx(Qu,{item:t},t.key)}function n0(t){const e=B.c(14),{sections:s,header:i,footer:n,additionalContent:o,variant:a,contentClassName:l}=t,c=a===void 0?"sidebar":a;let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d=r.jsx(S.Suspense,{fallback:r.jsx("div",{className:"h-10 shrink-0"}),children:r.jsx(t0,{})}),e[0]=d):d=e[0];let u;e[1]!==l?(u=X("flex flex-col flex-1 px-2 py-2 gap-0",l),e[1]=l,e[2]=u):u=e[2];let h;e[3]!==s?(h=s.map(o0),e[3]=s,e[4]=h):h=e[4];let f;e[5]!==o||e[6]!==u||e[7]!==h?(f=r.jsxs(_u,{className:u,children:[h,o]}),e[5]=o,e[6]=u,e[7]=h,e[8]=f):f=e[8];let m;return e[9]!==n||e[10]!==i||e[11]!==f||e[12]!==c?(m=r.jsxs(x_,{variant:c,children:[d,i,f,n]}),e[9]=n,e[10]=i,e[11]=f,e[12]=c,e[13]=m):m=e[13],m}function o0(t,e){return r.jsx(s0,{section:t},e)}function Zu(t){const e=B.c(2);let s;return e[0]!==t?(s=r.jsx(n0,{...t}),e[0]=t,e[1]=s):s=e[1],s}Zu.Skeleton=function(){return r.jsx("div",{className:"flex flex-col gap-0.5",children:Array.from({length:8}).map((e,s)=>r.jsx("div",{className:"w-full h-8",children:r.jsx(Bi,{className:"h-full bg-sidebar-accent rounded-md"})},s))})};function a0(){const t=B.c(7),s=Ch().logo??jh,i=typeof s=="string"?s:s.light,n=typeof s=="string"?s:s.dark;let o;t[0]!==i?(o=r.jsx("img",{src:i,alt:"Logo",className:"size-6 object-contain dark:hidden"}),t[0]=i,t[1]=o):o=t[1];let a;t[2]!==n?(a=r.jsx("img",{src:n,alt:"Logo",className:"size-6 object-contain hidden dark:block"}),t[2]=n,t[3]=a):a=t[3];let l;return t[4]!==o||t[5]!==a?(l=r.jsx(xu,{className:"flex items-center justify-center shrink-0 px-2 pb-0",children:r.jsxs("div",{className:"flex w-full aspect-square items-center justify-center",children:[o,a]})}),t[4]=o,t[5]=a,t[6]=l):l=t[6],l}function Gc(t){const e=B.c(15),{item:s,onClose:i}=t,n=s.isActive&&"z-10";let o;e[0]!==n?(o=X(n),e[0]=n,e[1]=o):o=e[1];let a;e[2]!==s||e[3]!==i?(a=()=>{s.onClick?.(),i()},e[2]=s,e[3]=i,e[4]=a):a=e[4];let l;e[5]!==s.icon?(l=r.jsx("span",{className:"[&>svg]:size-8",children:s.icon}),e[5]=s.icon,e[6]=l):l=e[6];let c;e[7]!==s.isActive||e[8]!==s.label||e[9]!==a||e[10]!==l?(c=r.jsx(us,{onClick:a,isActive:s.isActive,tooltip:s.label,className:"bg-muted/75",children:l}),e[7]=s.isActive,e[8]=s.label,e[9]=a,e[10]=l,e[11]=c):c=e[11];let d;return e[12]!==o||e[13]!==c?(d=r.jsx(Zt,{className:o,children:c}),e[12]=o,e[13]=c,e[14]=d):d=e[14],d}function l0(t){const e=B.c(18),{section:s,onClose:i}=t;switch(s.type){case"divider":{let n;return e[0]===Symbol.for("react.memo_cache_sentinel")?(n=r.jsx(gu,{className:"my-2"}),e[0]=n):n=e[0],n}case"spacer":{let n;return e[1]===Symbol.for("react.memo_cache_sentinel")?(n=r.jsx("div",{className:"flex-1"}),e[1]=n):n=e[1],n}case"group":{const n=s.group.label,o=s.group.defaultExpanded;let a;if(e[2]!==i||e[3]!==s.group.items){let c;e[5]!==i?(c=d=>r.jsx(Gc,{item:d,onClose:i},d.key),e[5]=i,e[6]=c):c=e[6],a=s.group.items.map(c),e[2]=i,e[3]=s.group.items,e[4]=a}else a=e[4];let l;return e[7]!==s.group.defaultExpanded||e[8]!==s.group.label||e[9]!==a?(l=r.jsx(Ju,{label:n,defaultExpanded:o,children:a}),e[7]=s.group.defaultExpanded,e[8]=s.group.label,e[9]=a,e[10]=l):l=e[10],l}case"items":{let n;if(e[11]!==i||e[12]!==s.items){let a;e[14]!==i?(a=l=>r.jsx(Gc,{item:l,onClose:i},l.key),e[14]=i,e[15]=a):a=e[15],n=s.items.map(a),e[11]=i,e[12]=s.items,e[13]=n}else n=e[13];let o;return e[16]!==n?(o=r.jsx(Ur,{className:"pt-0 pr-0 pb-0 pl-0",children:r.jsx(Kr,{children:r.jsx(gs,{className:"gap-1.5",children:n})})}),e[16]=n,e[17]=o):o=e[17],o}}}function c0(t){const e=B.c(12),{sections:s,onClose:i,footer:n,additionalContent:o}=t;let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=r.jsx(S.Suspense,{fallback:r.jsx("div",{className:"h-10 shrink-0"}),children:r.jsx(a0,{})}),e[0]=a):a=e[0];let l;if(e[1]!==i||e[2]!==s){let u;e[4]!==i?(u=(h,f)=>r.jsx(l0,{section:h,onClose:i},f),e[4]=i,e[5]=u):u=e[5],l=s.map(u),e[1]=i,e[2]=s,e[3]=l}else l=e[3];let c;e[6]!==o||e[7]!==l?(c=r.jsxs(_u,{className:"flex flex-col flex-1 px-2 py-2 gap-0",children:[l,o]}),e[6]=o,e[7]=l,e[8]=c):c=e[8];let d;return e[9]!==n||e[10]!==c?(d=r.jsxs("div",{className:"bg-sidebar flex h-full w-full flex-col","data-sidebar":"sidebar",children:[a,c,n]}),e[9]=n,e[10]=c,e[11]=d):d=e[11],d}function ef(t){return t.toLowerCase().trim().replace(/[^a-z0-9\s_-]+/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}const d0=Vs({name:Et().min(2,"Organization name is required")});function h0(t){const e=B.c(41),{open:s,onOpenChange:i}=t;let n;e[0]===Symbol.for("react.memo_cache_sentinel")?(n={resolver:Or(d0),defaultValues:{name:""}},e[0]=n):n=e[0];const o=Hi(n);let a;e[1]===Symbol.for("react.memo_cache_sentinel")?(a={mutationFn:f0,onSuccess:u0},e[1]=a):a=e[1];const l=Br(a),c=l.error instanceof Error?l.error.message:l.error?"Failed to create organization.":null;let d;e[2]===Symbol.for("react.memo_cache_sentinel")?(d=r.jsxs(kl,{children:[r.jsx(Nl,{children:"Create a new organization"}),r.jsx(Al,{children:"Set up a new organization to collaborate with others."})]}),e[2]=d):d=e[2];let u;if(e[3]!==l||e[4]!==o){let V;e[6]!==l?(V=w=>l.mutateAsync(w),e[6]=l,e[7]=V):V=e[7],u=o.handleSubmit(V),e[3]=l,e[4]=o,e[5]=u}else u=e[5];let h;e[8]!==o.formState.isSubmitting?(h=V=>{const{field:w}=V;return r.jsxs(Rt,{children:[r.jsx(rs,{children:"Organization Name"}),r.jsx(Tt,{children:r.jsx(bt,{...w,placeholder:"Acme Inc.",disabled:o.formState.isSubmitting})}),r.jsx(dg,{children:"The name of your company or organization"}),w.value&&r.jsxs("div",{className:"text-xs text-muted-foreground mt-1",children:["Organization URL:"," ",r.jsxs("span",{className:"font-mono",children:[typeof window<"u"?globalThis.location.origin:"","/",ef(w.value)]})]}),r.jsx(Dt,{})]})},e[8]=o.formState.isSubmitting,e[9]=h):h=e[9];let f;e[10]!==o.control||e[11]!==h?(f=r.jsx(It,{control:o.control,name:"name",render:h}),e[10]=o.control,e[11]=h,e[12]=f):f=e[12];let m;e[13]!==c?(m=c&&r.jsx("div",{className:"text-destructive text-sm mt-2",children:c}),e[13]=c,e[14]=m):m=e[14];let p;e[15]!==l||e[16]!==o?(p=()=>{l.reset(),o.reset()},e[15]=l,e[16]=o,e[17]=p):p=e[17];let g;e[18]!==o.formState.isSubmitting||e[19]!==p?(g=r.jsx(Cl,{disabled:o.formState.isSubmitting,onClick:p,children:"Cancel"}),e[18]=o.formState.isSubmitting,e[19]=p,e[20]=g):g=e[20];const _=!o.formState.isValid||o.formState.isSubmitting;let v;e[21]!==o.formState.isSubmitting?(v=o.formState.isSubmitting?r.jsxs("span",{className:"flex items-center gap-2",children:[r.jsx(jr,{size:"xs"})," Creating..."]}):"Create Organization",e[21]=o.formState.isSubmitting,e[22]=v):v=e[22];let x;e[23]!==_||e[24]!==v?(x=r.jsx(ne,{type:"submit",variant:"default",disabled:_,children:v}),e[23]=_,e[24]=v,e[25]=x):x=e[25];let b;e[26]!==x||e[27]!==g?(b=r.jsxs(El,{children:[g,x]}),e[26]=x,e[27]=g,e[28]=b):b=e[28];let y;e[29]!==b||e[30]!==u||e[31]!==f||e[32]!==m?(y=r.jsxs("form",{className:"space-y-6",onSubmit:u,autoComplete:"off",children:[f,m,b]}),e[29]=b,e[30]=u,e[31]=f,e[32]=m,e[33]=y):y=e[33];let C;e[34]!==o||e[35]!==y?(C=r.jsxs(jl,{children:[d,r.jsx(Pi,{...o,children:y})]}),e[34]=o,e[35]=y,e[36]=C):C=e[36];let j;return e[37]!==i||e[38]!==s||e[39]!==C?(j=r.jsx(Il,{open:s,onOpenChange:i,children:C}),e[37]=i,e[38]=s,e[39]=C,e[40]=j):j=e[40],j}function u0(t){const{orgSlug:e}=t;window.location.href=`/${e}`}async function f0(t){const e=ef(t.name);if(!e)throw new Error("Organization slug is invalid");const s=await St.organization.create({name:t.name,slug:e});if(s?.error)throw new Error(s.error.message||"Failed to create organization");const i=s?.data?.slug??e;if(!i)throw new Error("Failed to create organization");return{orgSlug:i}}function ga(t){let e=0;for(let i=0;i<t.length;i++)e=t.charCodeAt(i)+((e<<5)-e);const s=Math.abs(e)%360;return{backgroundColor:`hsl(${s} 55% 70%)`,color:`hsl(${s} 55% 20%)`}}function m0(t){const e=B.c(13),{org:s,size:i}=t,n=i===void 0?"sm":i,o=n==="xs"?"size-5":"size-6",a=n==="xs"?"text-[9px]":"text-xs";let l;e[0]!==o?(l=X(o,"shrink-0 rounded-md flex items-center justify-center border border-border/50 overflow-hidden"),e[0]=o,e[1]=l):l=e[1];let c;e[2]!==s.logo||e[3]!==s.name?(c=s.logo?void 0:ga(s.name),e[2]=s.logo,e[3]=s.name,e[4]=c):c=e[4];let d;e[5]!==s.logo||e[6]!==s.name||e[7]!==a?(d=s.logo?r.jsx("img",{src:s.logo,alt:"",className:"size-full object-cover"}):r.jsx("span",{className:X("font-semibold leading-none",a),children:s.name.slice(0,2).toUpperCase()}),e[5]=s.logo,e[6]=s.name,e[7]=a,e[8]=d):d=e[8];let u;return e[9]!==l||e[10]!==c||e[11]!==d?(u=r.jsx("div",{className:l,style:c,children:d}),e[9]=l,e[10]=c,e[11]=d,e[12]=u):u=e[12],u}function ln(t){const e=B.c(22),{item:s,onClose:i}=t;if(s.href){const c=s.external?"_blank":void 0,d=s.external?"noopener noreferrer":void 0;let u;e[0]!==s.icon?(u=r.jsx("span",{className:"shrink-0 text-muted-foreground",children:s.icon}),e[0]=s.icon,e[1]=u):u=e[1];let h;e[2]!==s.label?(h=r.jsx("span",{className:"flex-1",children:s.label}),e[2]=s.label,e[3]=h):h=e[3];let f;return e[4]!==s.href||e[5]!==i||e[6]!==c||e[7]!==d||e[8]!==u||e[9]!==h?(f=r.jsxs("a",{href:s.href,target:c,rel:d,className:"flex items-center gap-2.5 px-3 py-2 rounded-md text-sm text-left w-full transition-colors text-foreground/80 hover:bg-sidebar-accent hover:text-foreground",onClick:i,children:[u,h]}),e[4]=s.href,e[5]=i,e[6]=c,e[7]=d,e[8]=u,e[9]=h,e[10]=f):f=e[10],f}let n;e[11]!==s||e[12]!==i?(n=()=>{s.onClick?.(),i()},e[11]=s,e[12]=i,e[13]=n):n=e[13];let o;e[14]!==s.icon?(o=r.jsx("span",{className:"shrink-0 text-muted-foreground",children:s.icon}),e[14]=s.icon,e[15]=o):o=e[15];let a;e[16]!==s.label?(a=r.jsx("span",{className:"flex-1",children:s.label}),e[16]=s.label,e[17]=a):a=e[17];let l;return e[18]!==n||e[19]!==o||e[20]!==a?(l=r.jsxs("button",{type:"button",onClick:n,className:"flex items-center gap-2.5 px-3 py-2 rounded-md text-sm text-left w-full transition-colors text-foreground/80 hover:bg-sidebar-accent hover:text-foreground",children:[o,a]}),e[18]=n,e[19]=o,e[20]=a,e[21]=l):l=e[21],l}function Yc(t){const e=B.c(16),{sortedOrgs:s,orgParam:i,onSelectOrg:n,onCreateOrg:o}=t;let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=r.jsx("span",{className:"text-sm font-medium text-muted-foreground/60",children:"Your Organizations"}),e[0]=a):a=e[0];let l;e[1]===Symbol.for("react.memo_cache_sentinel")?(l=r.jsx(Qt,{size:16}),e[1]=l):l=e[1];let c;e[2]!==o?(c=r.jsxs("div",{className:"flex items-center justify-between px-4 py-3",children:[a,r.jsx("button",{type:"button",onClick:o,className:"flex items-center justify-center size-7 rounded-md text-muted-foreground hover:bg-accent/50 hover:text-foreground transition-colors",children:l})]}),e[2]=o,e[3]=c):c=e[3];let d;if(e[4]!==n||e[5]!==i||e[6]!==s){let f;e[8]!==n||e[9]!==i?(f=m=>r.jsxs("button",{type:"button",onClick:()=>n(m.slug),className:X("flex items-center gap-3 px-3 py-2.5 rounded-md text-sm text-left w-full transition-colors",m.slug===i?"bg-accent text-accent-foreground":"text-foreground hover:bg-accent/50"),children:[r.jsx(m0,{org:m,size:"sm"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-sm font-medium truncate",children:m.name}),r.jsx("p",{className:"text-xs text-muted-foreground truncate",children:m.slug})]}),m.slug===i&&r.jsx(Jt,{size:14,className:"ml-auto text-muted-foreground shrink-0"})]},m.id),e[8]=n,e[9]=i,e[10]=f):f=e[10],d=s.map(f),e[4]=n,e[5]=i,e[6]=s,e[7]=d}else d=e[7];let u;e[11]!==d?(u=r.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto p-1.5 flex flex-col gap-1",children:d}),e[11]=d,e[12]=u):u=e[12];let h;return e[13]!==c||e[14]!==u?(h=r.jsxs(r.Fragment,{children:[c,u]}),e[13]=c,e[14]=u,e[15]=h):h=e[15],h}function Xc(t){const e=B.c(142),{user:s,userImage:i,menuItems:n,signOutItem:o,themeOptions:a,preferences:l,setPreferences:c,sortedOrgs:d,orgParam:u,onSelectOrg:h,onCreateOrg:f,close:m,isMobile:p}=t;if(p){const K=s?.name??"U";let U;e[0]!==K||e[1]!==i?(U=r.jsx(Vc,{url:i,fallback:K,shape:"circle",size:"sm",className:"shrink-0"}),e[0]=K,e[1]=i,e[2]=U):U=e[2];const te=s?.name??"User";let Y;e[3]!==te?(Y=r.jsx("p",{className:"text-sm font-medium truncate",children:te}),e[3]=te,e[4]=Y):Y=e[4];const J=s?.email;let ie;e[5]!==J?(ie=r.jsx("p",{className:"text-xs text-muted-foreground truncate",children:J}),e[5]=J,e[6]=ie):ie=e[6];let ue;e[7]!==Y||e[8]!==ie?(ue=r.jsxs("div",{className:"flex-1 min-w-0",children:[Y,ie]}),e[7]=Y,e[8]=ie,e[9]=ue):ue=e[9];let de;e[10]!==s?(de=()=>{s?.id&&navigator.clipboard.writeText(s.id).then(x0)},e[10]=s,e[11]=de):de=e[11];let xe;e[12]===Symbol.for("react.memo_cache_sentinel")?(xe=r.jsx(Li,{size:14}),e[12]=xe):xe=e[12];let oe;e[13]!==de?(oe=r.jsx(tt,{asChild:!0,children:r.jsx("button",{type:"button",tabIndex:-1,onClick:de,className:"shrink-0 text-muted-foreground hover:text-foreground transition-colors",children:xe})}),e[13]=de,e[14]=oe):oe=e[14];let he;e[15]===Symbol.for("react.memo_cache_sentinel")?(he=r.jsx(st,{side:"right",children:r.jsx("p",{className:"text-xs",children:"Copy user ID"})}),e[15]=he):he=e[15];let me;e[16]!==oe?(me=r.jsx(Mi,{delayDuration:300,children:r.jsxs(it,{children:[oe,he]})}),e[16]=oe,e[17]=me):me=e[17];let fe;e[18]!==me||e[19]!==U||e[20]!==ue?(fe=r.jsxs("div",{className:"flex items-center gap-3 px-4 py-4 border-b border-border",children:[U,ue,me]}),e[18]=me,e[19]=U,e[20]=ue,e[21]=fe):fe=e[21];let le;e[22]!==f||e[23]!==h||e[24]!==u||e[25]!==d?(le=r.jsx("div",{className:"border-b border-border pb-2",children:r.jsx(Yc,{sortedOrgs:d,orgParam:u,onSelectOrg:h,onCreateOrg:f})}),e[22]=f,e[23]=h,e[24]=u,e[25]=d,e[26]=le):le=e[26];let ve;if(e[27]!==m||e[28]!==n){let Pe;e[30]!==m?(Pe=Kt=>r.jsx(ln,{item:Kt,onClose:m},Kt.key),e[30]=m,e[31]=Pe):Pe=e[31],ve=n.map(Pe),e[27]=m,e[28]=n,e[29]=ve}else ve=e[29];let Ce;e[32]!==m||e[33]!==o?(Ce=r.jsx(ln,{item:o,onClose:m}),e[32]=m,e[33]=o,e[34]=Ce):Ce=e[34];let Te;e[35]!==ve||e[36]!==Ce?(Te=r.jsxs("nav",{className:"flex flex-col px-2 pt-2 pb-2 gap-0.5",children:[ve,Ce]}),e[35]=ve,e[36]=Ce,e[37]=Te):Te=e[37];let Q;e[38]!==le||e[39]!==Te?(Q=r.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[le,Te]}),e[38]=le,e[39]=Te,e[40]=Q):Q=e[40];let ae;if(e[41]!==l.theme||e[42]!==c||e[43]!==a){let Pe;e[45]!==l.theme||e[46]!==c?(Pe=Kt=>{const{value:jt,icon:Ae,label:Ie}=Kt;return r.jsx("button",{type:"button","aria-label":Ie,onClick:()=>c(qe=>({...qe,theme:jt})),className:X("size-8 rounded-md flex items-center justify-center transition-colors",l.theme===jt?"bg-sidebar-accent text-foreground":"text-muted-foreground hover:bg-sidebar-accent/50 hover:text-foreground"),children:Ae},jt)},e[45]=l.theme,e[46]=c,e[47]=Pe):Pe=e[47],ae=a.map(Pe),e[41]=l.theme,e[42]=c,e[43]=a,e[44]=ae}else ae=e[44];let Se;e[48]!==ae?(Se=r.jsx("div",{className:"flex items-center gap-0.5",children:ae}),e[48]=ae,e[49]=Se):Se=e[49];const Ne=l.enableSounds?"Disable sounds":"Enable sounds";let Be;e[50]!==c?(Be=()=>c(_0),e[50]=c,e[51]=Be):Be=e[51];const Oe=l.enableSounds?"text-foreground hover:bg-sidebar-accent/50":"text-muted-foreground hover:bg-sidebar-accent/50 hover:text-foreground";let He;e[52]!==Oe?(He=X("size-8 rounded-md flex items-center justify-center transition-colors",Oe),e[52]=Oe,e[53]=He):He=e[53];let Je;e[54]!==l.enableSounds?(Je=l.enableSounds?r.jsx(uc,{size:14}):r.jsx(fc,{size:14}),e[54]=l.enableSounds,e[55]=Je):Je=e[55];let dt;e[56]!==Ne||e[57]!==Be||e[58]!==He||e[59]!==Je?(dt=r.jsx("button",{type:"button","aria-label":Ne,onClick:Be,className:He,children:Je}),e[56]=Ne,e[57]=Be,e[58]=He,e[59]=Je,e[60]=dt):dt=e[60];let pe;e[61]===Symbol.for("react.memo_cache_sentinel")?(pe=r.jsxs("span",{className:"text-xs text-muted-foreground/60",children:["v","2.276.3"]}),e[61]=pe):pe=e[61];let ke;e[62]!==dt?(ke=r.jsxs("div",{className:"flex items-center gap-2",children:[dt,pe]}),e[62]=dt,e[63]=ke):ke=e[63];let Qe;e[64]!==Se||e[65]!==ke?(Qe=r.jsxs("div",{className:"flex items-center justify-between px-3 py-3 border-t border-border/50",children:[Se,ke]}),e[64]=Se,e[65]=ke,e[66]=Qe):Qe=e[66];let Ct;return e[67]!==fe||e[68]!==Q||e[69]!==Qe?(Ct=r.jsxs("div",{className:"flex flex-col h-full overflow-hidden",children:[fe,Q,Qe]}),e[67]=fe,e[68]=Q,e[69]=Qe,e[70]=Ct):Ct=e[70],Ct}const g=s?.name??"U";let _;e[71]!==g||e[72]!==i?(_=r.jsx(Vc,{url:i,fallback:g,shape:"circle",size:"sm",className:"shrink-0"}),e[71]=g,e[72]=i,e[73]=_):_=e[73];const v=s?.name??"User";let x;e[74]!==v?(x=r.jsx("p",{className:"text-sm font-medium truncate",children:v}),e[74]=v,e[75]=x):x=e[75];const b=s?.email;let y;e[76]!==b?(y=r.jsx("p",{className:"text-xs text-muted-foreground truncate",children:b}),e[76]=b,e[77]=y):y=e[77];let C;e[78]!==x||e[79]!==y?(C=r.jsxs("div",{className:"flex-1 min-w-0",children:[x,y]}),e[78]=x,e[79]=y,e[80]=C):C=e[80];let j;e[81]!==s?(j=()=>{s?.id&&navigator.clipboard.writeText(s.id).then(g0)},e[81]=s,e[82]=j):j=e[82];let V;e[83]===Symbol.for("react.memo_cache_sentinel")?(V=r.jsx(Li,{size:14}),e[83]=V):V=e[83];let w;e[84]!==j?(w=r.jsx(tt,{asChild:!0,children:r.jsx("button",{type:"button",tabIndex:-1,onClick:j,className:"shrink-0 text-muted-foreground hover:text-foreground transition-colors",children:V})}),e[84]=j,e[85]=w):w=e[85];let k;e[86]===Symbol.for("react.memo_cache_sentinel")?(k=r.jsx(st,{side:"right",children:r.jsx("p",{className:"text-xs",children:"Copy user ID"})}),e[86]=k):k=e[86];let T;e[87]!==w?(T=r.jsx(Mi,{delayDuration:300,children:r.jsxs(it,{children:[w,k]})}),e[87]=w,e[88]=T):T=e[88];let I;e[89]!==T||e[90]!==_||e[91]!==C?(I=r.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 mx-1 mt-1",children:[_,C,T]}),e[89]=T,e[90]=_,e[91]=C,e[92]=I):I=e[92];let A;if(e[93]!==m||e[94]!==n){let K;e[96]!==m?(K=U=>r.jsx(ln,{item:U,onClose:m},U.key),e[96]=m,e[97]=K):K=e[97],A=n.map(K),e[93]=m,e[94]=n,e[95]=A}else A=e[95];let N;e[98]!==m||e[99]!==o?(N=r.jsx(ln,{item:o,onClose:m}),e[98]=m,e[99]=o,e[100]=N):N=e[100];let E;e[101]!==A||e[102]!==N?(E=r.jsxs("nav",{className:"flex-1 flex flex-col px-2 pt-1 overflow-y-auto",children:[A,N]}),e[101]=A,e[102]=N,e[103]=E):E=e[103];let R;if(e[104]!==l.theme||e[105]!==c||e[106]!==a){let K;e[108]!==l.theme||e[109]!==c?(K=U=>{const{value:te,icon:Y,label:J}=U;return r.jsx("button",{type:"button","aria-label":J,onClick:()=>c(ie=>({...ie,theme:te})),className:X("size-7 rounded-md flex items-center justify-center transition-colors",l.theme===te?"bg-sidebar-accent text-foreground":"text-muted-foreground hover:bg-sidebar-accent/50 hover:text-foreground"),children:Y},te)},e[108]=l.theme,e[109]=c,e[110]=K):K=e[110],R=a.map(K),e[104]=l.theme,e[105]=c,e[106]=a,e[107]=R}else R=e[107];let M;e[111]!==R?(M=r.jsx("div",{className:"flex items-center gap-0.5",children:R}),e[111]=R,e[112]=M):M=e[112];const L=l.enableSounds?"Disable sounds":"Enable sounds";let D;e[113]!==c?(D=()=>c(p0),e[113]=c,e[114]=D):D=e[114];const P=l.enableSounds?"text-foreground hover:bg-sidebar-accent/50":"text-muted-foreground hover:bg-sidebar-accent/50 hover:text-foreground";let O;e[115]!==P?(O=X("size-7 rounded-md flex items-center justify-center transition-colors",P),e[115]=P,e[116]=O):O=e[116];let z;e[117]!==l.enableSounds?(z=l.enableSounds?r.jsx(uc,{size:14}):r.jsx(fc,{size:14}),e[117]=l.enableSounds,e[118]=z):z=e[118];let $;e[119]!==L||e[120]!==D||e[121]!==O||e[122]!==z?($=r.jsx("button",{type:"button","aria-label":L,onClick:D,className:O,children:z}),e[119]=L,e[120]=D,e[121]=O,e[122]=z,e[123]=$):$=e[123];let W;e[124]===Symbol.for("react.memo_cache_sentinel")?(W=r.jsxs("span",{className:"text-xs text-muted-foreground/60",children:["v","2.276.3"]}),e[124]=W):W=e[124];let F;e[125]!==$?(F=r.jsxs("div",{className:"flex items-center gap-2",children:[$,W]}),e[125]=$,e[126]=F):F=e[126];let G;e[127]!==M||e[128]!==F?(G=r.jsxs("div",{className:"flex items-center justify-between px-2 py-1.5 border-t border-border/50",children:[M,F]}),e[127]=M,e[128]=F,e[129]=G):G=e[129];let q;e[130]!==I||e[131]!==E||e[132]!==G?(q=r.jsxs("div",{className:"w-60 shrink-0 flex flex-col border-r border-border bg-sidebar/75",children:[I,E,G]}),e[130]=I,e[131]=E,e[132]=G,e[133]=q):q=e[133];let H;e[134]!==f||e[135]!==h||e[136]!==u||e[137]!==d?(H=r.jsx("div",{className:"flex-1 flex flex-col min-w-0 min-h-0 overflow-hidden",children:r.jsx(Yc,{sortedOrgs:d,orgParam:u,onSelectOrg:h,onCreateOrg:f})}),e[134]=f,e[135]=h,e[136]=u,e[137]=d,e[138]=H):H=e[138];let ee;return e[139]!==q||e[140]!==H?(ee=r.jsxs("div",{className:"flex min-h-[380px] w-full overflow-hidden",children:[q,H]}),e[139]=q,e[140]=H,e[141]=ee):ee=e[141],ee}function p0(t){return{...t,enableSounds:!t.enableSounds}}function g0(){ge.success("User ID copied")}function _0(t){return{...t,enableSounds:!t.enableSounds}}function x0(){ge.success("User ID copied")}function tf(){const t=B.c(50),{data:e}=St.useSession(),{data:s}=St.useListOrganizations(),i=Ke();let n;t[0]===Symbol.for("react.memo_cache_sentinel")?(n={from:"/shell/$org",shouldThrow:!1},t[0]=n):n=t[0];const a=ip(n)?.params.org,[l,c]=Wi(),d=Rs(),[u,h]=S.useState(!1),[f,m]=S.useState(!1),p=e?.user,g=p?.image;let _;if(t[1]!==d||t[2]!==i||t[3]!==u||t[4]!==a||t[5]!==s||t[6]!==l||t[7]!==c||t[8]!==p||t[9]!==g){const b=s?.find(ee=>ee.slug===a);let y;if(t[11]!==a||t[12]!==s){let ee;t[14]!==a?(ee=(K,U)=>K.slug===a?-1:U.slug===a?1:K.name.localeCompare(U.name),t[14]=a,t[15]=ee):ee=t[15],y=[...s??[]].sort(ee),t[11]=a,t[12]=s,t[13]=y}else y=t[13];const C=y;let j;t[16]!==i?(j=ee=>{h(!1),i({to:"/$org",params:{org:ee}})},t[16]=i,t[17]=j):j=t[17];const V=j;let w;t[18]===Symbol.for("react.memo_cache_sentinel")?(w=()=>h(!1),t[18]=w):w=t[18];const k=w;let T;t[19]===Symbol.for("react.memo_cache_sentinel")?(T=r.jsx(Gr,{size:16}),t[19]=T):T=t[19];let I;t[20]!==i||t[21]!==a?(I={key:"preferences",label:"Preferences",icon:T,onClick:()=>{i({to:"/$org/settings/profile",params:{org:a??""}})}},t[20]=i,t[21]=a,t[22]=I):I=t[22];let A;t[23]===Symbol.for("react.memo_cache_sentinel")?(A={key:"terms",label:"Terms of Use",icon:r.jsx(bg,{size:16}),href:"https://www.decocms.com/terms-of-use",external:!0},t[23]=A):A=t[23];let N;t[24]===Symbol.for("react.memo_cache_sentinel")?(N={key:"privacy",label:"Privacy Policy",icon:r.jsx(yg,{size:16}),href:"https://www.decocms.com/privacy-policy",external:!0},t[24]=N):N=t[24];let E;t[25]===Symbol.for("react.memo_cache_sentinel")?(E={key:"github",label:"decocms/studio",icon:r.jsx(rp,{className:"w-4 h-4"}),href:"https://github.com/decocms/studio",external:!0},t[25]=E):E=t[25];let R;t[26]===Symbol.for("react.memo_cache_sentinel")?(R={key:"community",label:"Community",icon:r.jsx(ao,{size:16}),href:"https://decocms.com/discord",external:!0},t[26]=R):R=t[26];let M;t[27]===Symbol.for("react.memo_cache_sentinel")?(M={key:"homepage",label:"Homepage",icon:r.jsx(Zh,{size:16}),href:"https://decocms.com",external:!0},t[27]=M):M=t[27];let L;t[28]!==I?(L=[I,A,N,E,R,M],t[28]=I,t[29]=L):L=t[29];const D=L;let P;t[30]===Symbol.for("react.memo_cache_sentinel")?(P={key:"logout",label:"Sign out",icon:r.jsx(Ig,{size:16}),onClick:b0},t[30]=P):P=t[30];const O=P;let z;t[31]===Symbol.for("react.memo_cache_sentinel")?(z={value:"light",icon:r.jsx(C_,{size:14}),label:"Light theme"},t[31]=z):z=t[31];let $;t[32]===Symbol.for("react.memo_cache_sentinel")?($={value:"dark",icon:r.jsx(j_,{size:14}),label:"Dark theme"},t[32]=$):$=t[32];let W;t[33]===Symbol.for("react.memo_cache_sentinel")?(W=[z,$,{value:"system",icon:r.jsx(k_,{size:14}),label:"System theme"}],t[33]=W):W=t[33];const F=W;let G;t[34]===Symbol.for("react.memo_cache_sentinel")?(G=()=>{h(!1),m(!0)},t[34]=G):G=t[34];let q;t[35]!==V||t[36]!==d||t[37]!==D||t[38]!==a||t[39]!==l||t[40]!==c||t[41]!==C||t[42]!==p||t[43]!==g?(q={user:p,userImage:g,menuItems:D,signOutItem:O,themeOptions:F,preferences:l,setPreferences:c,sortedOrgs:C,orgParam:a,onSelectOrg:V,onCreateOrg:G,close:k,isMobile:d},t[35]=V,t[36]=d,t[37]=D,t[38]=a,t[39]=l,t[40]=c,t[41]=C,t[42]=p,t[43]=g,t[44]=q):q=t[44];const H=q;_=d?r.jsxs(Si,{open:u,onOpenChange:h,direction:"bottom",children:[r.jsxs("button",{type:"button",onClick:()=>h(!0),className:"flex items-center gap-3 w-full px-3 py-2.5 rounded-lg transition-colors text-sm text-sidebar-foreground/70 hover:bg-sidebar-accent hover:text-sidebar-foreground",children:[r.jsx("div",{className:"shrink-0 size-5 rounded-md flex items-center justify-center border border-border/50 overflow-hidden",style:b?.logo?void 0:ga(b?.name??""),children:b?.logo?r.jsx("img",{src:b.logo,alt:"",className:"size-full object-cover"}):r.jsx("span",{className:"font-semibold leading-none text-[8px]",children:(b?.name??"?").slice(0,2).toUpperCase()})}),r.jsx("span",{className:"truncate",children:b?.name??"Account"})]}),r.jsxs(yi,{className:"h-[80dvh] p-0",children:[r.jsx(bi,{className:"sr-only",children:"Account"}),r.jsx(Xc,{...H})]})]}):r.jsxs(li,{open:u,onOpenChange:h,children:[r.jsx(oi,{asChild:!0,children:r.jsx(us,{tooltip:b?.name??"Account",className:"rounded-md",children:r.jsx("div",{className:"shrink-0 size-6 rounded-md flex items-center justify-center border border-border/50 overflow-hidden",style:b?.logo?void 0:ga(b?.name??""),children:b?.logo?r.jsx("img",{src:b.logo,alt:"",className:"size-full object-cover"}):r.jsx("span",{className:"font-semibold leading-none text-[9px]",children:(b?.name??"?").slice(0,2).toUpperCase()})})})}),r.jsx(ai,{side:"right",align:"end",sideOffset:18,collisionPadding:16,className:"w-[520px] p-0 flex max-h-[520px]",onCloseAutoFocus:v0,children:r.jsx(Xc,{...H})})]}),t[1]=d,t[2]=i,t[3]=u,t[4]=a,t[5]=s,t[6]=l,t[7]=c,t[8]=p,t[9]=g,t[10]=_}else _=t[10];let v;t[45]!==f?(v=r.jsx(h0,{open:f,onOpenChange:m}),t[45]=f,t[46]=v):v=t[46];let x;return t[47]!==_||t[48]!==v?(x=r.jsxs(r.Fragment,{children:[_,v]}),t[47]=_,t[48]=v,t[49]=x):x=t[49],x}function v0(t){return t.preventDefault()}function b0(){se("signed_out",{source:"account_popover"}),St.signOut()}function y0({invitation:t}){const[e,s]=S.useState(!1),[i,n]=S.useState(!1),o=Mt(),a=async()=>{s(!0);try{const c=await St.organization.acceptInvitation({invitationId:t.id});if(c.error)ge.error(c.error.message),s(!1);else{const d=await St.organization.setActive({organizationId:t.organizationId});ge.success("Invitation accepted!");const u=d?.data?.slug;window.location.href=u?`/${u}`:"/"}}catch{ge.error("Failed to accept invitation"),s(!1)}},l=async()=>{n(!0);try{const c=await St.organization.rejectInvitation({invitationId:t.id});c.error?(ge.error(c.error.message),n(!1)):(ge.success("Invitation declined"),o.invalidateQueries())}catch{ge.error("Failed to decline invitation"),n(!1)}};return r.jsxs("div",{className:"flex items-center gap-3 px-5 py-4 border-b border-border last:border-0 hover:bg-muted/25 transition-colors",children:[r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-xs text-muted-foreground",children:"You've been invited to join"}),r.jsx("p",{className:"text-sm font-medium truncate",children:t.organizationName??"Unknown organization"})]}),r.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[r.jsx(ne,{size:"icon",variant:"ghost",className:"size-7 text-green-600 hover:text-green-700 hover:bg-green-50 dark:hover:bg-green-950",onClick:a,disabled:e||i,"aria-label":"Accept invitation",children:r.jsx(Jt,{size:14})}),r.jsx(ne,{size:"icon",variant:"ghost",className:"size-7 text-muted-foreground hover:text-destructive hover:bg-destructive/10",onClick:l,disabled:e||i,"aria-label":"Decline invitation",children:r.jsx(ii,{size:14})})]})]})}function S0(){const t=S.useContext(np),{data:e}=t.hooks.useListUserInvitations();return(e??[]).filter(i=>i.status==="pending"&&new Date(i.expiresAt)>new Date)}class w0 extends S.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e,s){}render(){return this.state.hasError?null:this.props.children}}function V0(t){return t<=1?"text-destructive":t<=5?"text-amber-500 dark:text-amber-400":"text-foreground/70"}function C0(){const t=B.c(19),e=Ke(),{org:s}=be();let i;t[0]!==s.id?(i={connectionId:Wt,orgId:s.id},t[0]=s.id,t[1]=i):i=t[1];const n=Me(i);let o;t[2]===Symbol.for("react.memo_cache_sentinel")?(o={providerId:"deco"},t[2]=o):o=t[2];let a;t[3]!==n?(a={client:n,toolName:"AI_PROVIDER_CREDITS",toolArguments:o,staleTime:6e4,select:j0},t[3]=n,t[4]=a):a=t[4];const{data:l,isPending:c,isError:d}=wi(a),u=l?.balanceCents!=null?l.balanceCents/100:null;let h;t[5]!==u||t[6]!==d||t[7]!==c?(h=c||d||u==null?"Credits":`Credits: $${u.toFixed(2)}`,t[5]=u,t[6]=d,t[7]=c,t[8]=h):h=t[8];const f=h;let m;t[9]!==u?(m=X(u!=null&&V0(u)),t[9]=u,t[10]=m):m=t[10];let p;t[11]!==e||t[12]!==s.slug?(p=()=>e({to:"/$org/settings/ai-providers",params:{org:s.slug}}),t[11]=e,t[12]=s.slug,t[13]=p):p=t[13];let g;t[14]===Symbol.for("react.memo_cache_sentinel")?(g=r.jsx(ml,{size:24}),t[14]=g):g=t[14];let _;return t[15]!==m||t[16]!==p||t[17]!==f?(_=r.jsx(gs,{children:r.jsx(Zt,{children:r.jsx(us,{tooltip:f,className:m,onClick:p,children:g})})}),t[15]=m,t[16]=p,t[17]=f,t[18]=_):_=t[18],_}function j0(t){return t.structuredContent}function k0(){const t=B.c(1);if(!bl().some(N0))return null;let i;return t[0]===Symbol.for("react.memo_cache_sentinel")?(i=r.jsx(C0,{}),t[0]=i):i=t[0],i}function N0(t){return t.providerId==="deco"}function A0(){const t=B.c(3),[e,s]=S.useState(!1);let i;t[0]===Symbol.for("react.memo_cache_sentinel")?(i=r.jsx(gs,{children:r.jsx(Zt,{children:r.jsx(us,{tooltip:"Connections",onClick:()=>{se("connections_dialog_opened",{source:"sidebar_footer",mode:"browse"}),s(!0)},children:r.jsx(Rg,{size:24})})})}),t[0]=i):i=t[0];let n;return t[1]!==e?(n=r.jsxs(r.Fragment,{children:[i,r.jsx(Pl,{mode:"browse",open:e,onOpenChange:s,defaultTab:"all"})]}),t[1]=e,t[2]=n):n=t[2],n}function E0(){const t=B.c(11),e=S0();let s;t[0]===Symbol.for("react.memo_cache_sentinel")?(s=r.jsx(mc,{size:24}),t[0]=s):s=t[0];let i;t[1]!==e.length?(i=e.length>0&&r.jsx("span",{className:"absolute top-1 right-1 size-2 rounded-full bg-red-500 pointer-events-none"}),t[1]=e.length,t[2]=i):i=t[2];let n;t[3]!==i?(n=r.jsx(gs,{children:r.jsx(Zt,{children:r.jsx(oi,{asChild:!0,children:r.jsxs(us,{tooltip:"Inbox",className:"relative",children:[s,i]})})})}),t[3]=i,t[4]=n):n=t[4];let o;t[5]===Symbol.for("react.memo_cache_sentinel")?(o=r.jsx("div",{className:"px-4 py-3 border-b border-border shrink-0",children:r.jsx("h3",{className:"text-sm font-medium",children:"Inbox"})}),t[5]=o):o=t[5];let a;t[6]!==e?(a=r.jsxs(ai,{side:"right",align:"start",sideOffset:16,collisionPadding:16,className:"w-[min(400px,calc(100vw-2rem))] p-0 h-[min(650px,calc(100dvh-4rem))] flex flex-col",children:[o,e.length===0?r.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-2 px-6 text-center",children:[r.jsx(mc,{size:24,className:"text-muted-foreground/50"}),r.jsx("p",{className:"text-sm font-medium text-foreground",children:"No invites pending"}),r.jsx("p",{className:"text-xs text-muted-foreground",children:"Organization invitations will appear here"})]}):r.jsx("div",{className:"overflow-y-auto flex-1",children:e.map(I0)})]}),t[6]=e,t[7]=a):a=t[7];let l;return t[8]!==n||t[9]!==a?(l=r.jsxs(li,{children:[n,a]}),t[8]=n,t[9]=a,t[10]=l):l=t[10],l}function I0(t){return r.jsx(y0,{invitation:t},t.id)}function R0(){const t=B.c(6),e=Ke(),{org:s}=be();let i;t[0]!==e||t[1]!==s.slug?(i=()=>e({to:"/$org/settings",params:{org:s.slug}}),t[0]=e,t[1]=s.slug,t[2]=i):i=t[2];let n;t[3]===Symbol.for("react.memo_cache_sentinel")?(n=r.jsx(Gr,{size:24}),t[3]=n):n=t[3];let o;return t[4]!==i?(o=r.jsx(gs,{children:r.jsx(Zt,{children:r.jsx(us,{tooltip:"Settings",onClick:i,children:n})})}),t[4]=i,t[5]=o):o=t[5],o}function T0(){const t=B.c(5);let e,s,i,n;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=r.jsx(w0,{children:r.jsx(S.Suspense,{fallback:null,children:r.jsx(k0,{})})}),s=r.jsx(A0,{}),i=r.jsx(E0,{}),n=r.jsx(R0,{}),t[0]=e,t[1]=s,t[2]=i,t[3]=n):(e=t[0],s=t[1],i=t[2],n=t[3]);let o;return t[4]===Symbol.for("react.memo_cache_sentinel")?(o=r.jsxs(vu,{className:"px-2 pb-3 gap-1",children:[e,s,i,n,r.jsx(gs,{children:r.jsx(Zt,{children:r.jsx(tf,{})})})]}),t[4]=o):o=t[4],o}function D0(){const t=B.c(10),e=Ke(),{org:s}=be(),{setOpenMobile:i}=qr();let n;t[0]!==e||t[1]!==s.slug||t[2]!==i?(n=()=>{e({to:"/$org/settings",params:{org:s.slug}}),i(!1)},t[0]=e,t[1]=s.slug,t[2]=i,t[3]=n):n=t[3];let o;t[4]===Symbol.for("react.memo_cache_sentinel")?(o=r.jsx(Gr,{}),t[4]=o):o=t[4];let a;t[5]!==n?(a=r.jsx(Zt,{children:r.jsx(us,{tooltip:"Settings",onClick:n,children:o})}),t[5]=n,t[6]=a):a=t[6];let l;t[7]===Symbol.for("react.memo_cache_sentinel")?(l=r.jsx(Zt,{children:r.jsx(tf,{})}),t[7]=l):l=t[7];let c;return t[8]!==a?(c=r.jsx(vu,{children:r.jsxs(gs,{children:[a,l]})}),t[8]=a,t[9]=c):c=t[9],c}function M0(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];return S.useMemo(()=>i=>{e.forEach(n=>n(i))},e)}const uo=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function Ki(t){const e=Object.prototype.toString.call(t);return e==="[object Window]"||e==="[object global]"}function Ll(t){return"nodeType"in t}function Ut(t){var e,s;return t?Ki(t)?t:Ll(t)&&(e=(s=t.ownerDocument)==null?void 0:s.defaultView)!=null?e:window:window}function Bl(t){const{Document:e}=Ut(t);return t instanceof e}function Xr(t){return Ki(t)?!1:t instanceof Ut(t).HTMLElement}function sf(t){return t instanceof Ut(t).SVGElement}function qi(t){return t?Ki(t)?t.document:Ll(t)?Bl(t)?t:Xr(t)||sf(t)?t.ownerDocument:document:document:document}const Es=uo?S.useLayoutEffect:S.useEffect;function Ol(t){const e=S.useRef(t);return Es(()=>{e.current=t}),S.useCallback(function(){for(var s=arguments.length,i=new Array(s),n=0;n<s;n++)i[n]=arguments[n];return e.current==null?void 0:e.current(...i)},[])}function P0(){const t=S.useRef(null),e=S.useCallback((i,n)=>{t.current=setInterval(i,n)},[]),s=S.useCallback(()=>{t.current!==null&&(clearInterval(t.current),t.current=null)},[]);return[e,s]}function Er(t,e){e===void 0&&(e=[t]);const s=S.useRef(t);return Es(()=>{s.current!==t&&(s.current=t)},e),s}function Jr(t,e){const s=S.useRef();return S.useMemo(()=>{const i=t(s.current);return s.current=i,i},[...e])}function Hn(t){const e=Ol(t),s=S.useRef(null),i=S.useCallback(n=>{n!==s.current&&e?.(n,s.current),s.current=n},[]);return[s,i]}function _a(t){const e=S.useRef();return S.useEffect(()=>{e.current=t},[t]),e.current}let Ro={};function Qr(t,e){return S.useMemo(()=>{if(e)return e;const s=Ro[t]==null?0:Ro[t]+1;return Ro[t]=s,t+"-"+s},[t,e])}function rf(t){return function(e){for(var s=arguments.length,i=new Array(s>1?s-1:0),n=1;n<s;n++)i[n-1]=arguments[n];return i.reduce((o,a)=>{const l=Object.entries(a);for(const[c,d]of l){const u=o[c];u!=null&&(o[c]=u+t*d)}return o},{...e})}}const Di=rf(1),Ir=rf(-1);function L0(t){return"clientX"in t&&"clientY"in t}function $l(t){if(!t)return!1;const{KeyboardEvent:e}=Ut(t.target);return e&&t instanceof e}function B0(t){if(!t)return!1;const{TouchEvent:e}=Ut(t.target);return e&&t instanceof e}function xa(t){if(B0(t)){if(t.touches&&t.touches.length){const{clientX:e,clientY:s}=t.touches[0];return{x:e,y:s}}else if(t.changedTouches&&t.changedTouches.length){const{clientX:e,clientY:s}=t.changedTouches[0];return{x:e,y:s}}}return L0(t)?{x:t.clientX,y:t.clientY}:null}const Rr=Object.freeze({Translate:{toString(t){if(!t)return;const{x:e,y:s}=t;return"translate3d("+(e?Math.round(e):0)+"px, "+(s?Math.round(s):0)+"px, 0)"}},Scale:{toString(t){if(!t)return;const{scaleX:e,scaleY:s}=t;return"scaleX("+e+") scaleY("+s+")"}},Transform:{toString(t){if(t)return[Rr.Translate.toString(t),Rr.Scale.toString(t)].join(" ")}},Transition:{toString(t){let{property:e,duration:s,easing:i}=t;return e+" "+s+"ms "+i}}}),Jc="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";function O0(t){return t.matches(Jc)?t:t.querySelector(Jc)}const $0={display:"none"};function z0(t){let{id:e,value:s}=t;return Ft.createElement("div",{id:e,style:$0},s)}function F0(t){let{id:e,announcement:s,ariaLiveType:i="assertive"}=t;const n={position:"fixed",top:0,left:0,width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",clipPath:"inset(100%)",whiteSpace:"nowrap"};return Ft.createElement("div",{id:e,style:n,role:"status","aria-live":i,"aria-atomic":!0},s)}function H0(){const[t,e]=S.useState("");return{announce:S.useCallback(i=>{i!=null&&e(i)},[]),announcement:t}}const nf=S.createContext(null);function W0(t){const e=S.useContext(nf);S.useEffect(()=>{if(!e)throw new Error("useDndMonitor must be used within a children of <DndContext>");return e(t)},[t,e])}function U0(){const[t]=S.useState(()=>new Set),e=S.useCallback(i=>(t.add(i),()=>t.delete(i)),[t]);return[S.useCallback(i=>{let{type:n,event:o}=i;t.forEach(a=>{var l;return(l=a[n])==null?void 0:l.call(a,o)})},[t]),e]}const K0={draggable:`
259
+ Approach every request with rigor and intellectual honesty. Always surface what is uncertain or debated, not just what is known.`,tb=["Break any topic into key sub-questions and define scope","Synthesize information from multiple angles and sources","Distinguish facts, expert consensus, and contested claims","Identify gaps, contradictions, and emerging patterns","Deliver structured summaries with actionable insights"];function Wc(t){const e=B.c(7),{onRecruit:s,isRecruiting:i}=t;let n;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=r.jsx("p",{className:"text-sm text-muted-foreground",children:"Add a Web Researcher agent that conducts thorough, rigorous research on any topic and delivers structured, actionable insights."}),e[0]=n):n=e[0];let o;e[1]===Symbol.for("react.memo_cache_sentinel")?(o=r.jsx("p",{className:"text-sm font-medium text-foreground",children:"Capabilities"}),e[1]=o):o=e[1];let a;e[2]===Symbol.for("react.memo_cache_sentinel")?(a=r.jsxs("div",{className:"space-y-2",children:[o,r.jsx("ul",{className:"space-y-1.5",children:tb.map(sb)})]}),e[2]=a):a=e[2];const l=i?"Setting up...":"Add Web Researcher";let c;return e[3]!==i||e[4]!==s||e[5]!==l?(c=r.jsxs("div",{className:"flex flex-col gap-6",children:[n,a,r.jsx(ne,{onClick:s,disabled:i,className:"w-full cursor-pointer",children:l})]}),e[3]=i,e[4]=s,e[5]=l,e[6]=c):c=e[6],c}function sb(t){return r.jsxs("li",{className:"text-sm text-muted-foreground flex items-start gap-2",children:[r.jsx("span",{className:"text-amber-500 mt-0.5 shrink-0",children:"+"}),t]},t)}function ib({open:t,onOpenChange:e,existingAgent:s}){const i=Rs(),n=lo(),o=yl(),[a,l]=S.useState(!1),c=Os.find(f=>f.id==="ai-research"),d=r.jsx(Ms,{icon:c.icon,name:c.title,size:"sm"}),u=async()=>{if(s){e(!1),n(s.id);return}l(!0);try{const f=await o.create.mutateAsync({title:c.title,description:"Systematic research and information synthesis assistant",icon:c.icon,status:"active",connections:[],metadata:{type:"ai-research",instructions:eb}});se("agent_recruit_confirmed",{template_id:"ai-research",agent_id:f.id}),e(!1),n(f.id)}catch(f){se("agent_recruit_failed",{template_id:"ai-research",error:f instanceof Error?f.message:String(f)}),console.error("Failed to create Researcher agent:",f)}finally{l(!1)}},h=`Add ${c.title}`;return i?r.jsx(Si,{open:t,onOpenChange:e,children:r.jsxs(yi,{className:"h-[70dvh]",children:[r.jsx(so,{className:"px-4 pt-4 pb-4 shrink-0",children:r.jsxs("div",{className:"flex items-center gap-3",children:[d,r.jsx(bi,{className:"text-xl font-semibold",children:h})]})}),r.jsx("div",{className:"flex flex-col flex-1 min-h-0 px-4 pb-8",children:r.jsx(Wc,{onRecruit:u,isRecruiting:a})})]})}):r.jsx(ps,{open:t,onOpenChange:e,children:r.jsxs(ms,{className:"sm:max-w-[500px] p-8",children:[r.jsx(Ds,{className:"mb-4",children:r.jsxs("div",{className:"flex items-center gap-3",children:[d,r.jsx(Ts,{className:"text-xl font-semibold",children:h})]})}),r.jsx(Wc,{onRecruit:u,isRecruiting:a})]})})}function rb(t){try{const e=localStorage.getItem(`mesh:chat:recent-agents:${t}`);return e?JSON.parse(e):[]}catch{return[]}}function tr(t){const e=B.c(21),{agent:s,onSpecialClick:i,tracking:n}=t,{org:o}=be(),a=Ke();let l;e[0]!==s.id||e[1]!==s.title||e[2]!==a||e[3]!==i||e[4]!==o||e[5]!==n.action||e[6]!==n.template_id||e[7]!==n.tile_kind?(l=()=>{if(se("home_agent_tile_clicked",{template_id:n.template_id,agent_id:s.id,agent_title:s.title,tile_kind:n.tile_kind,action:n.action}),i)i();else{const g=crypto.randomUUID();a({to:"/$org/$taskId",params:{org:o.slug,taskId:g},search:{virtualmcpid:s.id}})}},e[0]=s.id,e[1]=s.title,e[2]=a,e[3]=i,e[4]=o,e[5]=n.action,e[6]=n.template_id,e[7]=n.tile_kind,e[8]=l):l=e[8];const c=l;let d;e[9]===Symbol.for("react.memo_cache_sentinel")?(d=X("flex flex-col items-center gap-3 p-2 rounded-lg","transition-colors","cursor-pointer","w-[100px] shrink-0","group"),e[9]=d):d=e[9];const u=`Select agent ${s.title}`;let h;e[10]===Symbol.for("react.memo_cache_sentinel")?(h=r.jsx(ao,{size:24}),e[10]=h):h=e[10];let f;e[11]!==s.icon||e[12]!==s.title?(f=r.jsx(Ms,{icon:s.icon,name:s.title,size:"md",fallbackIcon:h,className:"transition-transform group-hover:scale-110"}),e[11]=s.icon,e[12]=s.title,e[13]=f):f=e[13];let m;e[14]!==s.title?(m=r.jsx("p",{className:"text-xs sm:text-sm text-foreground text-center leading-tight line-clamp-2 break-words w-full",children:s.title}),e[14]=s.title,e[15]=m):m=e[15];let p;return e[16]!==c||e[17]!==u||e[18]!==f||e[19]!==m?(p=r.jsxs("button",{type:"button",onClick:c,className:d,"aria-label":u,children:[f,m]}),e[16]=c,e[17]=u,e[18]=f,e[19]=m,e[20]=p):p=e[20],p}function nb(){const t=B.c(8),e=Ke(),{org:s}=be();let i;t[0]===Symbol.for("react.memo_cache_sentinel")?(i=X("flex flex-col items-center gap-3 p-2 rounded-lg","transition-colors","cursor-pointer","w-[100px] shrink-0","group"),t[0]=i):i=t[0];let n;t[1]!==e||t[2]!==s.slug?(n=()=>{se("home_see_all_agents_clicked"),e({to:"/$org/settings/agents",params:{org:s.slug}})},t[1]=e,t[2]=s.slug,t[3]=n):n=t[3];let o,a;t[4]===Symbol.for("react.memo_cache_sentinel")?(o=r.jsx("div",{className:"size-12 rounded-xl bg-accent flex items-center justify-center shrink-0 transition-transform group-hover:scale-110",children:r.jsx(Vl,{size:20,className:"text-foreground"})}),a=r.jsx("p",{className:"text-xs sm:text-sm text-foreground text-center leading-tight",children:"See all"}),t[4]=o,t[5]=a):(o=t[4],a=t[5]);let l;return t[6]!==n?(l=r.jsxs("button",{type:"button",className:i,"aria-label":"See all agents",onClick:n,children:[o,a]}),t[6]=n,t[7]=l):l=t[7],l}function ob(){const t=B.c(9);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e={navigateOnCreate:!0},t[0]=e):e=t[0];const{createVirtualMCP:s,isCreating:i}=pu(e);let n;t[1]!==s?(n=()=>{se("home_create_agent_clicked"),s()},t[1]=s,t[2]=n):n=t[2];let o;t[3]===Symbol.for("react.memo_cache_sentinel")?(o=X("flex flex-col items-center gap-3 p-2 rounded-lg","transition-colors","cursor-pointer","w-[100px] shrink-0","group","disabled:opacity-50 disabled:cursor-not-allowed"),t[3]=o):o=t[3];let a,l;t[4]===Symbol.for("react.memo_cache_sentinel")?(a=r.jsx("div",{className:"size-12 rounded-xl bg-background border-2 border-dashed border-border flex items-center justify-center shrink-0 transition-transform group-hover:scale-110",children:r.jsx(Qt,{size:20,className:"text-muted-foreground"})}),l=r.jsx("p",{className:"text-xs sm:text-sm text-foreground text-center leading-tight",children:"Create agent"}),t[4]=a,t[5]=l):(a=t[4],l=t[5]);let c;return t[6]!==i||t[7]!==n?(c=r.jsxs("button",{type:"button",onClick:n,disabled:i,className:o,"aria-label":"Create agent",children:[a,l]}),t[6]=i,t[7]=n,t[8]=c):c=t[8],c}function ab(){const t=B.c(95),e=oo(),{locator:s}=be(),[i,n]=S.useState(!1),[o,a]=S.useState(!1),[l,c]=S.useState(!1),[d,u]=S.useState(!1),h=lo();let f;t[0]===Symbol.for("react.memo_cache_sentinel")?(f=Os.find(ub),t[0]=f):f=t[0];const m=f;let p;t[1]===Symbol.for("react.memo_cache_sentinel")?(p=Os.find(hb),t[1]=p):p=t[1];const g=p;let _;t[2]===Symbol.for("react.memo_cache_sentinel")?(_=Os.find(db),t[2]=_):_=t[2];const v=_;let x;t[3]===Symbol.for("react.memo_cache_sentinel")?(x=Os.find(cb),t[3]=x):x=t[3];const b=x;let y,C,j,V,w,k,T,I,A,N,E;if(t[4]!==s||t[5]!==h||t[6]!==e){const F=rb(s),G=e.filter(lb).sort((Q,ae)=>{const Se=F.indexOf(Q.id),Ne=F.indexOf(ae.id);return Se!==-1&&Ne!==-1?Se-Ne:Se!==-1?-1:Ne!==-1?1:new Date(ae.updated_at).getTime()-new Date(Q.updated_at).getTime()}).slice(0,4);let q;if(t[18]!==e){let Q;t[20]===Symbol.for("react.memo_cache_sentinel")?(Q=ae=>ae.id!==null&&(ae.metadata?.type===g.id||ae.title===g.title),t[20]=Q):Q=t[20],q=e.find(Q),t[18]=e,t[19]=q}else q=t[19];j=q;let H;if(t[21]!==e){let Q;t[23]===Symbol.for("react.memo_cache_sentinel")?(Q=ae=>ae.id!==null&&(ae.metadata?.type===v.id||ae.title===v.title),t[23]=Q):Q=t[23],H=e.find(Q),t[21]=e,t[22]=H}else H=t[22];y=H;let ee;if(t[24]!==e){let Q;t[26]===Symbol.for("react.memo_cache_sentinel")?(Q=ae=>ae.id!==null&&(ae.metadata?.type===b.id||ae.title===b.title),t[26]=Q):Q=t[26],ee=e.find(Q),t[24]=e,t[25]=ee}else ee=t[25];C=ee,V=G.length>0,w="w-full max-md:overflow-x-auto max-md:[scrollbar-width:none] max-md:[&::-webkit-scrollbar]:hidden",k="flex flex-wrap justify-center gap-1.5 max-md:flex-nowrap max-md:justify-start md:max-h-52 md:overflow-hidden",t[27]===Symbol.for("react.memo_cache_sentinel")?(T=r.jsx(tr,{agent:m,onSpecialClick:()=>n(!0),tracking:{template_id:m.id,tile_kind:"template",action:"open_modal"}},m.id),t[27]=T):T=t[27];const K=j??g;let U;t[28]!==j||t[29]!==h?(U=j?()=>h(j.id):()=>a(!0),t[28]=j,t[29]=h,t[30]=U):U=t[30];const te=j?"existing":"template",Y=j?"navigate":"open_modal";let J;t[31]!==te||t[32]!==Y?(J={template_id:g.id,tile_kind:te,action:Y},t[31]=te,t[32]=Y,t[33]=J):J=t[33],t[34]!==K||t[35]!==U||t[36]!==J?(I=r.jsx(tr,{agent:K,onSpecialClick:U,tracking:J},g.id),t[34]=K,t[35]=U,t[36]=J,t[37]=I):I=t[37];const ie=y??v;let ue;t[38]!==y||t[39]!==h?(ue=y?()=>h(y.id):()=>c(!0),t[38]=y,t[39]=h,t[40]=ue):ue=t[40];const de=y?"existing":"template",xe=y?"navigate":"open_modal";let oe;t[41]!==de||t[42]!==xe?(oe={template_id:v.id,tile_kind:de,action:xe},t[41]=de,t[42]=xe,t[43]=oe):oe=t[43],t[44]!==ie||t[45]!==ue||t[46]!==oe?(A=r.jsx(tr,{agent:ie,onSpecialClick:ue,tracking:oe},v.id),t[44]=ie,t[45]=ue,t[46]=oe,t[47]=A):A=t[47];const he=C??b;let me;t[48]!==C||t[49]!==h?(me=C?()=>h(C.id):()=>u(!0),t[48]=C,t[49]=h,t[50]=me):me=t[50];const fe=C?"existing":"template",le=C?"navigate":"open_modal";let ve;t[51]!==fe||t[52]!==le?(ve={template_id:b.id,tile_kind:fe,action:le},t[51]=fe,t[52]=le,t[53]=ve):ve=t[53],t[54]!==he||t[55]!==me||t[56]!==ve?(N=r.jsx(tr,{agent:he,onSpecialClick:me,tracking:ve},b.id),t[54]=he,t[55]=me,t[56]=ve,t[57]=N):N=t[57];let Ce;t[58]!==y?.id||t[59]!==C?.id||t[60]!==j?.id?(Ce=Q=>Q.id!==j?.id&&Q.id!==y?.id&&Q.id!==C?.id,t[58]=y?.id,t[59]=C?.id,t[60]=j?.id,t[61]=Ce):Ce=t[61];let Te;t[62]!==h?(Te=Q=>r.jsx(tr,{agent:Q,onSpecialClick:()=>h(Q.id),tracking:{template_id:null,tile_kind:"recent",action:"navigate"}},Q.id??"default"),t[62]=h,t[63]=Te):Te=t[63],E=G.filter(Ce).map(Te),t[4]=s,t[5]=h,t[6]=e,t[7]=y,t[8]=C,t[9]=j,t[10]=V,t[11]=w,t[12]=k,t[13]=T,t[14]=I,t[15]=A,t[16]=N,t[17]=E}else y=t[7],C=t[8],j=t[9],V=t[10],w=t[11],k=t[12],T=t[13],I=t[14],A=t[15],N=t[16],E=t[17];let R;t[64]===Symbol.for("react.memo_cache_sentinel")?(R=r.jsx(ob,{}),t[64]=R):R=t[64];let M;t[65]!==V?(M=V&&r.jsx(nb,{}),t[65]=V,t[66]=M):M=t[66];let L;t[67]!==M||t[68]!==k||t[69]!==T||t[70]!==I||t[71]!==A||t[72]!==N||t[73]!==E?(L=r.jsxs("div",{className:k,children:[T,I,A,N,E,R,M]}),t[67]=M,t[68]=k,t[69]=T,t[70]=I,t[71]=A,t[72]=N,t[73]=E,t[74]=L):L=t[74];let D;t[75]!==w||t[76]!==L?(D=r.jsx("div",{className:w,children:L}),t[75]=w,t[76]=L,t[77]=D):D=t[77];let P;t[78]!==i?(P=r.jsx(Bn,{open:i,onOpenChange:n}),t[78]=i,t[79]=P):P=t[79];let O;t[80]!==o||t[81]!==j?(O=r.jsx(uu,{open:o,onOpenChange:a,existingAgent:j}),t[80]=o,t[81]=j,t[82]=O):O=t[82];let z;t[83]!==l||t[84]!==y?(z=r.jsx(Zv,{open:l,onOpenChange:c,existingAgent:y}),t[83]=l,t[84]=y,t[85]=z):z=t[85];let $;t[86]!==d||t[87]!==C?($=r.jsx(ib,{open:d,onOpenChange:u,existingAgent:C}),t[86]=d,t[87]=C,t[88]=$):$=t[88];let W;return t[89]!==D||t[90]!==P||t[91]!==O||t[92]!==z||t[93]!==$?(W=r.jsxs(r.Fragment,{children:[D,P,O,z,$]}),t[89]=D,t[90]=P,t[91]=O,t[92]=z,t[93]=$,t[94]=W):W=t[94],W}function lb(t){return t.id!==null&&!Mn(t.id)}function cb(t){return t.id==="ai-research"}function db(t){return t.id==="ai-image"}function hb(t){return t.id==="site-diagnostics"}function ub(t){return t.id==="site-editor"}function fb(){const t=B.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=r.jsx("div",{className:"w-full max-md:overflow-x-auto max-md:[scrollbar-width:none] max-md:[&::-webkit-scrollbar]:hidden",children:r.jsx("div",{className:"flex flex-wrap justify-center gap-1.5 max-md:flex-nowrap max-md:justify-start md:max-h-52 md:overflow-hidden",children:Array.from({length:7}).map(mb)})}),t[0]=e):e=t[0],e}function mb(t,e){return r.jsxs("div",{className:"flex flex-col items-center gap-3 p-2 w-[100px] shrink-0",children:[r.jsx(Bi,{className:"size-12 rounded-xl shrink-0"}),r.jsx(Bi,{className:"h-3 sm:h-4 w-full"})]},e)}function Uc(){const t=B.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=r.jsx(S.Suspense,{fallback:r.jsx(fb,{}),children:r.jsx(ab,{})}),t[0]=e):e=t[0],e}function sr(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}k`:String(t)}function Kc(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 pb(t){return t?t.replace(/-\d{8}(?:-[a-z0-9]+)*$/i,"").replace(/-/g," "):"—"}function gb(t){const e=B.c(4),{items:s}=t;let i;e[0]!==s?(i=s.map(_b),e[0]=s,e[1]=i):i=e[1];let n;return e[2]!==i?(n=r.jsx("div",{className:"grid grid-cols-2 gap-x-8 gap-y-6",children:i}),e[2]=i,e[3]=n):n=e[3],n}function _b(t){return r.jsxs("div",{className:"flex flex-col gap-1 min-w-0",children:[r.jsx("span",{className:"text-xs text-muted-foreground truncate",children:t.label}),r.jsx("span",{className:"text-sm text-foreground tabular-nums truncate",children:t.value})]},t.label)}function xb(t){const e=B.c(30),{userTokens:s,assistantTokens:i,otherTokens:n}=t,o=s+i+n,a=o>0?s/o*100:0,l=o>0?i/o*100:0,c=o>0?n/o*100:0;let d;e[0]!==a?(d=a>0&&r.jsx("div",{className:"h-full bg-chart-1",style:{width:`${a}%`}}),e[0]=a,e[1]=d):d=e[1];let u;e[2]!==l?(u=l>0&&r.jsx("div",{className:"h-full bg-chart-2",style:{width:`${l}%`}}),e[2]=l,e[3]=u):u=e[3];let h;e[4]!==c?(h=c>0&&r.jsx("div",{className:"h-full bg-muted-foreground/30",style:{width:`${c}%`}}),e[4]=c,e[5]=h):h=e[5];let f;e[6]!==d||e[7]!==u||e[8]!==h?(f=r.jsxs("div",{className:"flex h-2 w-full overflow-hidden rounded-full bg-muted",children:[d,u,h]}),e[6]=d,e[7]=u,e[8]=h,e[9]=f):f=e[9];let m;e[10]===Symbol.for("react.memo_cache_sentinel")?(m=r.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 g;e[13]!==p?(g=r.jsxs("div",{className:"flex items-center gap-1.5",children:[m,r.jsxs("span",{className:"text-xs text-muted-foreground",children:["User ",p,"%"]})]}),e[13]=p,e[14]=g):g=e[14];let _;e[15]===Symbol.for("react.memo_cache_sentinel")?(_=r.jsx("span",{className:"inline-block h-2 w-2 rounded-sm bg-chart-2 shrink-0"}),e[15]=_):_=e[15];let v;e[16]!==l?(v=l.toFixed(1),e[16]=l,e[17]=v):v=e[17];let x;e[18]!==v?(x=r.jsxs("div",{className:"flex items-center gap-1.5",children:[_,r.jsxs("span",{className:"text-xs text-muted-foreground",children:["Assistant ",v,"%"]})]}),e[18]=v,e[19]=x):x=e[19];let b;e[20]!==c||e[21]!==n?(b=n>0&&r.jsxs("div",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:"inline-block h-2 w-2 rounded-sm bg-muted-foreground/30 shrink-0"}),r.jsxs("span",{className:"text-xs text-muted-foreground",children:["Other ",c.toFixed(1),"%"]})]}),e[20]=c,e[21]=n,e[22]=b):b=e[22];let y;e[23]!==x||e[24]!==b||e[25]!==g?(y=r.jsxs("div",{className:"flex flex-wrap gap-x-3 gap-y-1",children:[g,x,b]}),e[23]=x,e[24]=b,e[25]=g,e[26]=y):y=e[26];let C;return e[27]!==y||e[28]!==f?(C=r.jsxs("div",{className:"flex flex-col gap-2",children:[f,y]}),e[27]=y,e[28]=f,e[29]=C):C=e[29],C}function vb(t){const e=B.c(19),{part:s}=t,i=s.input?.agent_id,n=ts(i),o=n?.title??"Subtask",a=n?.icon??null,l=s.state==="input-streaming"||s.state==="input-available"||s.state==="output-available"&&s.preliminary===!0,c=s.state==="output-error",d=s.state==="approval-requested";let u;e[0]!==a||e[1]!==o?(u=r.jsx(Ms,{icon:a,name:o,size:"xs",className:"size-6 rounded-md shrink-0"}),e[0]=a,e[1]=o,e[2]=u):u=e[2];const h=c?"text-destructive":"text-foreground";let f;e[3]!==h?(f=X("shrink-0 font-medium",h),e[3]=h,e[4]=f):f=e[4];let m;e[5]!==o||e[6]!==f?(m=r.jsx("span",{className:f,children:o}),e[5]=o,e[6]=f,e[7]=m):m=e[7];let p;e[8]!==s.input?(p=s.input?.prompt&&r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"text-muted-foreground/50",children:"·"}),r.jsx("span",{className:"truncate text-muted-foreground",children:s.input.prompt})]}),e[8]=s.input,e[9]=p):p=e[9];let g;e[10]!==d||e[11]!==c||e[12]!==l?(g=r.jsx("span",{className:"ml-auto shrink-0",children:l?r.jsx(Ee,{size:12,className:"animate-spin text-muted-foreground"}):c?r.jsx(Og,{size:12,className:"text-destructive"}):d?r.jsx(ri,{size:12,className:"text-warning"}):r.jsx(x_,{size:12,className:"text-emerald-500"})}),e[10]=d,e[11]=c,e[12]=l,e[13]=g):g=e[13];let _;return e[14]!==u||e[15]!==m||e[16]!==p||e[17]!==g?(_=r.jsxs("div",{className:"flex items-center gap-2 text-xs min-w-0",children:[u,m,p,g]}),e[14]=u,e[15]=m,e[16]=p,e[17]=g,e[18]=_):_=e[18],_}function bb(t){const e=B.c(58),{onClose:s,back:i,className:n}=t,[o,a]=S.useState(null),{messages:l}=Ui(),{tasks:c,taskId:d}=es(),{selectedModel:u,selectedVirtualMcp:h}=ni();let f,m,p,g,_,v,x,b;if(e[0]!==i||e[1]!==n||e[2]!==l||e[3]!==s||e[4]!==o?.id||e[5]!==u||e[6]!==h?.title||e[7]!==d||e[8]!==c){b=Symbol.for("react.early_return_sentinel");e:{let j;e[17]!==d?(j=J=>J.id===d,e[17]=d,e[18]=j):j=e[18];const V=c.find(j),w=Eh(l),k=[...l].reverse().find(Ab),T=k?.metadata?.usage,I=k?.metadata?.modelLimits?.contextWindow??u?.limits?.contextWindow??null,A=T?.contextTokens??T?.totalTokens??0,N=I&&I>0?(A/I*100).toFixed(1):null,E=l;let R;e[19]!==E?(R=E.filter(Nb).reduce(kb,0),e[19]=E,e[20]=R):R=e[20];const M=R,L=l;let D;e[21]!==L?(D=L.filter(jb).reduce(Cb,0),e[21]=L,e[22]=D):D=e[22];const P=D,O=Math.max(0,w.totalTokens-M-P),z=l[0],$=l.at(-1),W=z?.metadata?.created_at??V?.created_at,F=$?.metadata?.created_at??V?.updated_at,G=l.filter(Vb),q=l.flatMap(Sb),H=u?.modelId?pb(u.modelId):"—",ee=h?.title??"Decopilot",K=[{label:"Session",value:V?.title??"New chat"},{label:"Messages",value:G.length},{label:"Agent",value:ee},{label:"Model",value:H},{label:"Context Limit",value:I?sr(I):"—"},{label:"Session Tokens (billed)",value:w.totalTokens>0?sr(w.totalTokens):"0"},{label:"Usage",value:N!==null?`${N}%`:"—"},{label:"Input Tokens",value:w.inputTokens>0?sr(w.inputTokens):"0"},{label:"Output Tokens",value:w.outputTokens>0?sr(w.outputTokens):"0"},{label:"Reasoning Tokens",value:w.reasoningTokens>0?sr(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:Kc(W)},{label:"Last Activity",value:Kc(F)}];if(!V&&G.length===0){let J;e[23]!==n?(J=X("flex flex-col h-full w-full border-l border-border bg-background",n),e[23]=n,e[24]=J):J=e[24];let ie;e[25]===Symbol.for("react.memo_cache_sentinel")?(ie=r.jsx("span",{className:"text-sm font-medium text-foreground",children:"Context"}),e[25]=ie):ie=e[25];let ue;e[26]!==i?(ue=i?r.jsx(aa,{size:14,className:"text-muted-foreground"}):r.jsx(ii,{size:14,className:"text-muted-foreground"}),e[26]=i,e[27]=ue):ue=e[27];let de;e[28]!==s||e[29]!==ue?(de=r.jsxs("div",{className:"h-11 px-4 flex items-center justify-between shrink-0 border-b border-border/50",children:[ie,r.jsx("button",{type:"button",onClick:s,className:"flex size-6 items-center justify-center rounded hover:bg-accent transition-colors",children:ue})]}),e[28]=s,e[29]=ue,e[30]=de):de=e[30];let xe;e[31]===Symbol.for("react.memo_cache_sentinel")?(xe=r.jsx("div",{className:"flex-1 flex items-center justify-center px-4 text-center",children:r.jsx("p",{className:"text-xs text-muted-foreground",children:"Start a conversation to see context"})}),e[31]=xe):xe=e[31];let oe;e[32]!==J||e[33]!==de?(oe=r.jsxs("div",{className:J,children:[de,xe]}),e[32]=J,e[33]=de,e[34]=oe):oe=e[34],b=oe;break e}e[35]!==n?(v=X("flex flex-col h-full w-full border-l border-border bg-background overflow-y-auto",n),e[35]=n,e[36]=v):v=e[36];let U;e[37]===Symbol.for("react.memo_cache_sentinel")?(U=r.jsx("span",{className:"text-sm font-medium text-foreground",children:"Context"}),e[37]=U):U=e[37];let te;e[38]!==i?(te=i?r.jsx(aa,{size:14}):r.jsx(ii,{size:14}),e[38]=i,e[39]=te):te=e[39],e[40]!==s||e[41]!==te?(x=r.jsxs("div",{className:"flex h-11 shrink-0 items-center justify-between border-b border-border/50 px-4",children:[U,r.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:te})]}),e[40]=s,e[41]=te,e[42]=x):x=e[42],f="flex flex-col gap-8 p-6",m=q.length>0&&r.jsxs("div",{className:"flex flex-col gap-3",children:[r.jsx("span",{className:"text-xs text-muted-foreground",children:"Subtasks"}),r.jsx("div",{className:"flex flex-col gap-1",children:q.map(yb)})]}),p=r.jsx(gb,{items:K});let Y;e[43]===Symbol.for("react.memo_cache_sentinel")?(Y=r.jsx("span",{className:"text-xs text-muted-foreground",children:"Context Breakdown"}),e[43]=Y):Y=e[43],e[44]!==P||e[45]!==O||e[46]!==M?(g=r.jsxs("div",{className:"flex flex-col gap-3",children:[Y,r.jsx(xb,{userTokens:M,assistantTokens:P,otherTokens:O})]}),e[44]=P,e[45]=O,e[46]=M,e[47]=g):g=e[47],_=G.length>0&&r.jsxs("div",{className:"flex flex-col gap-3",children:[r.jsx("span",{className:"text-xs text-muted-foreground",children:"Raw messages"}),r.jsx("div",{className:"flex flex-col gap-1",children:G.map(J=>{const ie=J.metadata?.created_at,ue=o?.id===J.id;return r.jsxs("div",{className:"rounded-md border border-border/50 overflow-hidden",children:[r.jsxs("button",{type:"button",onClick:()=>a(ue?null:J),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:[r.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[r.jsx("span",{className:X("shrink-0 font-medium",J.role==="user"?"text-chart-1":"text-chart-2"),children:J.role}),r.jsx("span",{className:"text-muted-foreground",children:"•"}),r.jsx("span",{className:"truncate text-muted-foreground font-mono",children:J.id})]}),ie&&r.jsx("span",{className:"shrink-0 text-muted-foreground tabular-nums",children:new Date(ie).toLocaleString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit"})})]}),ue&&r.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(J,null,2)})]},J.id)})})]})}e[0]=i,e[1]=n,e[2]=l,e[3]=s,e[4]=o?.id,e[5]=u,e[6]=h?.title,e[7]=d,e[8]=c,e[9]=f,e[10]=m,e[11]=p,e[12]=g,e[13]=_,e[14]=v,e[15]=x,e[16]=b}else f=e[9],m=e[10],p=e[11],g=e[12],_=e[13],v=e[14],x=e[15],b=e[16];if(b!==Symbol.for("react.early_return_sentinel"))return b;let y;e[48]!==f||e[49]!==m||e[50]!==p||e[51]!==g||e[52]!==_?(y=r.jsxs("div",{className:f,children:[m,p,g,_]}),e[48]=f,e[49]=m,e[50]=p,e[51]=g,e[52]=_,e[53]=y):y=e[53];let C;return e[54]!==v||e[55]!==x||e[56]!==y?(C=r.jsxs("div",{className:v,children:[x,y]}),e[54]=v,e[55]=x,e[56]=y,e[57]=C):C=e[57],C}function yb(t,e){return r.jsx(vb,{part:t},e)}function Sb(t){return(t.parts??[]).filter(wb)}function wb(t){return t.type==="tool-subtask"}function Vb(t){return t.role!=="system"}function Cb(t,e){const s=e.metadata?.usage;return t+(s?.outputTokens??0)}function jb(t){return t.role==="assistant"}function kb(t,e){const s=e.metadata?.usage;return t+(s?.inputTokens??0)}function Nb(t){return t.role==="user"}function Ab(t){return t.role==="assistant"&&t.metadata?.usage}function Eb(t){const e=t;if(e.structuredContent)return e.structuredContent;const s=e.content?.find(i=>i.type==="text")?.text;if(s)try{return JSON.parse(s)}catch{return[]}return[]}function Ib(t){const e=B.c(25),{orgId:s,userId:i,connectionId:n,vmMap:o,owner:a,repo:l,enabled:c}=t,d=c===void 0?!0:c,u=n??null;let h;e[0]!==s||e[1]!==u?(h={connectionId:u,orgId:s},e[0]=s,e[1]=u,e[2]=h):h=e[2];const f=Me(h);let m;e[3]!==a||e[4]!==l?(m={owner:a,repo:l},e[3]=a,e[4]=l,e[5]=m):m=e[5];const p=d&&!!n&&!!a&&!!l;let g;e[6]!==f||e[7]!==m||e[8]!==p?(g={client:f,toolName:"list_branches",toolArguments:m,enabled:p,staleTime:3e4,select:Mb},e[6]=f,e[7]=m,e[8]=p,e[9]=g):g=e[9];const{data:_,isLoading:v,isError:x}=wi(g);let b,y;e[10]!==i||e[11]!==o?(y=new Set(Object.keys(o?.[i]??{})),b=[...y].sort().map(Db),e[10]=i,e[11]=o,e[12]=b,e[13]=y):(b=e[12],y=e[13]);const C=b;let j;if(e[14]!==_||e[15]!==y){const T=Array.isArray(_)?_:_?.branches??[];let I;e[17]!==y?(I=A=>!y.has(A.name),e[17]=y,e[18]=I):I=e[18],j=T.filter(Tb).filter(I).map(Rb),e[14]=_,e[15]=y,e[16]=j}else j=e[16];const V=j,w=Array.isArray(_)?null:_?.default_branch??null;let k;return e[19]!==w||e[20]!==x||e[21]!==v||e[22]!==V||e[23]!==C?(k={yours:C,others:V,defaultBase:w,isLoading:v,isError:x},e[19]=w,e[20]=x,e[21]=v,e[22]=V,e[23]=C,e[24]=k):k=e[24],k}function Rb(t){return{name:t.name,source:"other",author:typeof t.commit?.author=="string"?t.commit.author:t.commit?.author?.login??null}}function Tb(t){return typeof t.name=="string"}function Db(t){return{name:t,source:"yours"}}function Mb(t){return Eb(t)}function Pb(t){const e=B.c(36),{orgId:s,userId:i,connectionId:n,owner:o,repo:a,vmMap:l,value:c,onChange:d}=t,[u,h]=S.useState(!1);let f;e[0]!==n||e[1]!==u||e[2]!==s||e[3]!==o||e[4]!==a||e[5]!==i||e[6]!==l?(f={orgId:s,userId:i,connectionId:n,vmMap:l,owner:o,repo:a,enabled:u},e[0]=n,e[1]=u,e[2]=s,e[3]=o,e[4]=a,e[5]=i,e[6]=l,e[7]=f):f=e[7];const{yours:m,others:p,isLoading:g,isError:_}=Ib(f);let v;e[8]!==d?(v=N=>{d(N),h(!1)},e[8]=d,e[9]=v):v=e[9];const x=v,b=c??"Select branch…";let y;e[10]===Symbol.for("react.memo_cache_sentinel")?(y=r.jsx(gr,{className:"h-3.5 w-3.5"}),e[10]=y):y=e[10];let C;e[11]!==b?(C=r.jsx(oi,{asChild:!0,children:r.jsxs(ne,{variant:"outline",size:"sm",className:"h-7 gap-1.5 px-2 font-mono text-xs",children:[y,r.jsx("span",{className:"max-w-[200px] truncate",children:b})]})}),e[11]=b,e[12]=C):C=e[12];let j;e[13]===Symbol.for("react.memo_cache_sentinel")?(j=r.jsx(c_,{placeholder:"Search branches…"}),e[13]=j):j=e[13];let V;e[14]!==_?(V=_&&r.jsx("div",{className:"p-3 text-xs text-muted-foreground",children:"Couldn't load branches from GitHub. You can still pick from your branches."}),e[14]=_,e[15]=V):V=e[15];let w;e[16]!==_||e[17]!==g||e[18]!==p.length||e[19]!==m.length?(w=!_&&!g&&m.length===0&&p.length===0&&r.jsx(a_,{children:"No branches found."}),e[16]=_,e[17]=g,e[18]=p.length,e[19]=m.length,e[20]=w):w=e[20];let k;e[21]!==x||e[22]!==m?(k=m.length>0&&r.jsx(yc,{heading:"Your branches",children:m.map(N=>r.jsxs(Sc,{value:N.name,onSelect:()=>x(N.name),children:[r.jsx(gr,{className:"mr-2 h-4 w-4"}),r.jsx("span",{className:"flex-1 truncate",children:N.name})]},N.name))}),e[21]=x,e[22]=m,e[23]=k):k=e[23];let T;e[24]!==p||e[25]!==x?(T=p.length>0&&r.jsxs(r.Fragment,{children:[r.jsx(l_,{}),r.jsx(yc,{heading:"Other branches in repo",children:p.map(N=>r.jsxs(Sc,{value:N.name,onSelect:()=>x(N.name),children:[r.jsx(gr,{className:"mr-2 h-4 w-4"}),r.jsx("span",{className:"flex-1 truncate",children:N.name}),N.author&&r.jsxs("span",{className:"text-xs text-muted-foreground",children:["@",N.author]})]},N.name))})]}),e[24]=p,e[25]=x,e[26]=T):T=e[26];let I;e[27]!==V||e[28]!==w||e[29]!==k||e[30]!==T?(I=r.jsx(ai,{className:"w-[min(420px,calc(100vw-2rem))] p-0",align:"start",children:r.jsxs(d_,{children:[j,r.jsxs(h_,{children:[V,w,k,T]})]})}),e[27]=V,e[28]=w,e[29]=k,e[30]=T,e[31]=I):I=e[31];let A;return e[32]!==u||e[33]!==I||e[34]!==C?(A=r.jsxs(li,{open:u,onOpenChange:h,children:[C,I]}),e[32]=u,e[33]=I,e[34]=C,e[35]=A):A=e[35],A}const Lb=["radial-gradient(ellipse 25% 220% at -5% 120%, rgba(165,149,255,0.35) 0%, transparent 100%)","radial-gradient(ellipse 25% 220% at 105% -20%, rgba(208,236,26,0.32) 0%, transparent 100%)"].join(", "),Bb="/decotexture.svg";function qc(t){const e=B.c(7),{onClick:s}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i={backgroundImage:Lb},e[0]=i):i=e[0];let n,o;e[1]===Symbol.for("react.memo_cache_sentinel")?(n=r.jsx("div",{className:"relative shrink-0 p-1.5 bg-[var(--brand-green-light)] rounded-lg border border-border",children:r.jsx(Ms,{icon:"/logos/deco%20logo.svg",name:"deco.cx",size:"xs",className:"border-0 rounded-none bg-transparent"})}),o=r.jsx("p",{className:"flex-1 relative text-sm font-medium text-foreground leading-none whitespace-nowrap",children:"Import your deco.cx site"}),e[1]=n,e[2]=o):(n=e[1],o=e[2]);let a;e[3]===Symbol.for("react.memo_cache_sentinel")?(a=r.jsx("img",{src:Bb,alt:"","aria-hidden":!0,className:"absolute pointer-events-none",style:{width:"274.5px",height:"272.25px",left:"calc(50% + 145.5px)",top:"calc(50% + 40px)",transform:"translate(-50%, -50%)"}}),e[3]=a):a=e[3];let l;e[4]===Symbol.for("react.memo_cache_sentinel")?(l=r.jsx("div",{className:"relative bg-background flex items-center justify-center size-8 rounded-md shrink-0",children:r.jsx(ro,{size:16,className:"text-foreground transition-transform group-hover:translate-x-0.5"})}),e[4]=l):l=e[4];let c;return e[5]!==s?(c=r.jsxs("button",{type:"button",onClick:s,className:"w-full relative flex items-center gap-4 px-4 py-4 rounded-lg border border-border bg-background overflow-hidden transition-colors text-left cursor-pointer group",style:i,children:[n,o,a,l]}),e[5]=s,e[6]=c):c=e[6],c}function Ob(){const t=B.c(5),{data:e}=St.useSession();let s;t[0]!==e?.user?.email?(s=lt.decoProfile(e?.user?.email),t[0]=e?.user?.email,t[1]=s):s=t[1];const i=!!e?.user?.email;let n;t[2]!==s||t[3]!==i?(n={queryKey:s,queryFn:$b,enabled:i,staleTime:3e5},t[2]=s,t[3]=i,t[4]=n):n=t[4];const{data:o}=Fi(n);return o?.isDecoUser??!1}async function $b(){const t=await fetch("/api/deco-sites/profile");return t.ok?t.json():{isDecoUser:!1}}function zb(t){const e=B.c(56),{onOpenContextPanel:s}=t,{data:i}=St.useSession(),[n,o]=S.useState(!1),a=Ob(),l=Rs(),{hasDecoKey:c,isZeroBalance:d,isInitialFreeCredit:u,balanceDollars:h,hasOnlyDecoProvider:f}=co();let m;e[0]!==i?.user?.name?(m=i?.user?.name?.split(" ")[0]||"there",e[0]=i?.user?.name,e[1]=m):m=e[1];const p=m,g=c&&u&&h!=null,_=c&&d&&f;if(l){let N;e[2]!==h||e[3]!==g?(N=g&&r.jsx("div",{className:"mb-4",children:r.jsx(De.CreditsEyebrow,{balanceDollars:h})}),e[2]=h,e[3]=g,e[4]=N):N=e[4];let E;e[5]!==_?(E=_&&r.jsx("div",{className:"mb-4",children:r.jsx(De.NoCreditsEyebrow,{})}),e[5]=_,e[6]=E):E=e[6];let R;e[7]!==p?(R=r.jsxs("p",{className:"text-3xl font-medium text-foreground text-center max-w-[280px]",children:["What's on your mind, ",p,"?"]}),e[7]=p,e[8]=R):R=e[8];let M;e[9]!==N||e[10]!==E||e[11]!==R?(M=r.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center w-full",children:[N,E,R]}),e[9]=N,e[10]=E,e[11]=R,e[12]=M):M=e[12];let L;e[13]===Symbol.for("react.memo_cache_sentinel")?(L=r.jsx(Uc,{}),e[13]=L):L=e[13];let D;e[14]!==s?(D=r.jsxs("div",{className:"w-full flex flex-col gap-4 pb-4",children:[L,r.jsx(De.Input,{onOpenContextPanel:s,showConnectionsBanner:!0})]}),e[14]=s,e[15]=D):D=e[15];let P;e[16]!==a?(P=a&&r.jsx("div",{className:"w-full",children:r.jsx(qc,{onClick:()=>o(!0)})}),e[16]=a,e[17]=P):P=e[17];let O;e[18]!==M||e[19]!==D||e[20]!==P?(O=r.jsxs("div",{className:"flex-1 relative flex flex-col items-center px-4",children:[M,D,P]}),e[18]=M,e[19]=D,e[20]=P,e[21]=O):O=e[21];let z;e[22]!==n?(z=r.jsx(Bn,{open:n,onOpenChange:o}),e[22]=n,e[23]=z):z=e[23];let $;return e[24]!==z||e[25]!==O?($=r.jsxs(r.Fragment,{children:[O,z]}),e[24]=z,e[25]=O,e[26]=$):$=e[26],$}let v;e[27]!==h||e[28]!==g?(v=g&&r.jsx("div",{className:"mb-4",children:r.jsx(De.CreditsEyebrow,{balanceDollars:h})}),e[27]=h,e[28]=g,e[29]=v):v=e[29];let x;e[30]!==_?(x=_&&r.jsx("div",{className:"mb-4",children:r.jsx(De.NoCreditsEyebrow,{})}),e[30]=_,e[31]=x):x=e[31];let b;e[32]!==p?(b=r.jsxs("p",{className:"text-3xl font-medium text-foreground",children:["What's on your mind, ",p,"?"]}),e[32]=p,e[33]=b):b=e[33];let y;e[34]!==v||e[35]!==x||e[36]!==b?(y=r.jsxs("div",{className:"text-center mb-10",children:[v,x,b]}),e[34]=v,e[35]=x,e[36]=b,e[37]=y):y=e[37];let C;e[38]!==s?(C=r.jsx("div",{className:"w-full",children:r.jsx(De.Input,{onOpenContextPanel:s,showConnectionsBanner:!0})}),e[38]=s,e[39]=C):C=e[39];let j;e[40]!==y||e[41]!==C?(j=r.jsxs("div",{className:"flex flex-col items-center w-full max-w-[672px]",children:[y,C]}),e[40]=y,e[41]=C,e[42]=j):j=e[42];let V;e[43]===Symbol.for("react.memo_cache_sentinel")?(V=r.jsx("div",{className:"w-full mt-10 mx-auto",children:r.jsx(Uc,{})}),e[43]=V):V=e[43];let w;e[44]!==j?(w=r.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center w-full",children:[j,V]}),e[44]=j,e[45]=w):w=e[45];let k;e[46]!==a?(k=a&&r.jsx("div",{className:"absolute bottom-6 left-0 right-0 px-10",children:r.jsx("div",{className:"w-full max-w-[500px] mx-auto",children:r.jsx(qc,{onClick:()=>o(!0)})})}),e[46]=a,e[47]=k):k=e[47];let T;e[48]!==k||e[49]!==w?(T=r.jsxs("div",{className:"flex-1 relative flex flex-col items-center px-10",children:[w,k]}),e[48]=k,e[49]=w,e[50]=T):T=e[50];let I;e[51]!==n?(I=r.jsx(Bn,{open:n,onOpenChange:o}),e[51]=n,e[52]=I):I=e[52];let A;return e[53]!==T||e[54]!==I?(A=r.jsxs(r.Fragment,{children:[T,I]}),e[53]=T,e[54]=I,e[55]=A):A=e[55],A}function Fb(){const t=B.c(26),{org:e}=be(),{selectedVirtualMcp:s}=ni(),{data:i}=St.useSession(),{currentBranch:n,setCurrentTaskBranch:o}=es();let a;t[0]!==e.id?(a=io(e.id),t[0]=e.id,t[1]=a):a=t[1];const c=s??a,d=ts(c.id),u=i?.user?.id??"",h=d?.metadata?.githubRepo??null,f=!!h?.connectionId&&!!u;let m;t[2]===Symbol.for("react.memo_cache_sentinel")?(m=r.jsx(ao,{size:32}),t[2]=m):m=t[2];let p;t[3]!==c.icon||t[4]!==c.title?(p=r.jsx(Ms,{icon:c.icon,name:c.title,size:"lg",fallbackIcon:m,className:"size-10 min-w-10 md:size-[60px]! md:min-w-[60px] rounded-xl md:rounded-[18px]!"}),t[3]=c.icon,t[4]=c.title,t[5]=p):p=t[5];let g;t[6]!==c.title?(g=r.jsx("h3",{className:"text-base md:text-xl font-medium text-foreground",children:c.title}),t[6]=c.title,t[7]=g):g=t[7];const _=c.description??"Ask anything about configuring model providers or using MCP Mesh.";let v;t[8]!==_?(v=r.jsx("div",{className:"text-muted-foreground text-center text-base max-w-md line-clamp-2",children:_}),t[8]=_,t[9]=v):v=t[9];let x;t[10]!==n||t[11]!==d?.metadata?.vmMap||t[12]!==h||t[13]!==e.id||t[14]!==o||t[15]!==f||t[16]!==u?(x=f&&r.jsx("div",{className:"mt-2",children:r.jsx(Pb,{orgId:e.id,userId:u,connectionId:h.connectionId,owner:h.owner,repo:h.name,vmMap:d?.metadata?.vmMap,value:n??void 0,onChange:o})}),t[10]=n,t[11]=d?.metadata?.vmMap,t[12]=h,t[13]=e.id,t[14]=o,t[15]=f,t[16]=u,t[17]=x):x=t[17];let b;t[18]!==p||t[19]!==g||t[20]!==v||t[21]!==x?(b=r.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 md:gap-4 text-center",children:[p,g,v,x]}),t[18]=p,t[19]=g,t[20]=v,t[21]=x,t[22]=b):b=t[22];let y;t[23]===Symbol.for("react.memo_cache_sentinel")?(y=r.jsx("div",{className:"w-full max-w-3xl mx-auto",children:r.jsx(De.IceBreakers,{})}),t[23]=y):y=t[23];let C;return t[24]!==b?(C=r.jsxs("div",{className:"h-full w-full flex flex-col items-center justify-center gap-6 px-4",children:[b,y]}),t[24]=b,t[25]=C):C=t[25],C}function Hb(t){const e=B.c(27),{variant:s}=t,{org:i}=be(),n=bl(),{isChatEmpty:o}=Ui(),[a,l]=S.useState("chat"),c=co();if(n.length===0){let C;return e[0]===Symbol.for("react.memo_cache_sentinel")?(C=r.jsx(De,{className:"animate-in fade-in-0 duration-200",children:r.jsx(De.Main,{className:"flex flex-col items-center",children:r.jsx(De.EmptyState,{children:r.jsx(De.NoAiProviderEmptyState,{})})})}),e[0]=C):C=e[0],C}let d;e[1]!==c.hasDecoKey||e[2]!==c.hasOnlyDecoProvider||e[3]!==c.isLoading||e[4]!==c.isZeroBalance||e[5]!==o||e[6]!==i?(d=c.hasDecoKey&&c.isZeroBalance&&c.hasOnlyDecoProvider&&!c.isLoading&&o&&!Mv(i.id),e[1]=c.hasDecoKey,e[2]=c.hasOnlyDecoProvider,e[3]=c.isLoading,e[4]=c.isZeroBalance,e[5]=o,e[6]=i,e[7]=d):d=e[7];const u=d;let h;e[8]!==u?(h=u&&r.jsx(De.CreditsEmptyState,{}),e[8]=u,e[9]=h):h=e[9];const f=a!=="chat"?"opacity-0 pointer-events-none":"opacity-100";let m;e[10]!==f?(m=X("absolute inset-0 flex flex-col transition-opacity duration-100 ease-out",f),e[10]=f,e[11]=m):m=e[11];let p;e[12]!==o||e[13]!==s?(p=o?s==="home"?r.jsx(zb,{onOpenContextPanel:()=>l("context")}):r.jsxs(r.Fragment,{children:[r.jsx(De.Main,{children:r.jsx(Fb,{})}),r.jsx(De.Footer,{children:r.jsx(De.Input,{onOpenContextPanel:()=>l("context")})})]}):r.jsxs(r.Fragment,{children:[r.jsx(De.Main,{children:r.jsx(De.Messages,{})}),r.jsx(De.Footer,{children:r.jsx(De.Input,{onOpenContextPanel:()=>l("context")})})]}),e[12]=o,e[13]=s,e[14]=p):p=e[14];let g;e[15]!==m||e[16]!==p?(g=r.jsx("div",{className:m,children:p}),e[15]=m,e[16]=p,e[17]=g):g=e[17];const _=a==="context"?"opacity-100":"opacity-0 pointer-events-none";let v;e[18]!==_?(v=X("absolute inset-0 flex flex-col transition-opacity duration-100 ease-out",_),e[18]=_,e[19]=v):v=e[19];let x;e[20]===Symbol.for("react.memo_cache_sentinel")?(x=r.jsx(bb,{back:!0,onClose:()=>l("chat")}),e[20]=x):x=e[20];let b;e[21]!==v?(b=r.jsx("div",{className:v,children:x}),e[21]=v,e[22]=b):b=e[22];let y;return e[23]!==b||e[24]!==h||e[25]!==g?(y=r.jsxs(De,{className:"relative overflow-hidden animate-in fade-in-0 duration-200",children:[h,g,b]}),e[23]=b,e[24]=h,e[25]=g,e[26]=y):y=e[26],y}function qu(t){const e=B.c(4),{variant:s}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=r.jsx(De.Skeleton,{}),e[0]=i):i=e[0];let n;e[1]===Symbol.for("react.memo_cache_sentinel")?(n=r.jsx(De.Skeleton,{}),e[1]=n):n=e[1];let o;return e[2]!==s?(o=r.jsx(Cs,{fallback:i,children:r.jsx(S.Suspense,{fallback:n,children:r.jsx(Hb,{variant:s})})}),e[2]=s,e[3]=o):o=e[3],o}function Wb(){const t=B.c(6),{org:e,locator:s}=be(),i=Mt();let n;t[0]!==s||t[1]!==i?(n=()=>{i.invalidateQueries({queryKey:lt.tasksPrefix(s)})},t[0]=s,t[1]=i,t[2]=n):n=t[2];let o;t[3]!==e.id||t[4]!==n?(o={orgId:e.id,onTaskStatus:n},t[3]=e.id,t[4]=n,t[5]=o):o=t[5],b_(o)}function Ub(t){const e=B.c(8),{virtualMcpId:s,size:i,showAutomationBadge:n}=t,o=i===void 0?"sm":i;let a;e[0]!==o||e[1]!==s?(a=s?r.jsx(Kb,{virtualMcpId:s,size:o}):r.jsx(zs,{icon:null,name:"?",size:o}),e[0]=o,e[1]=s,e[2]=a):a=e[2];let l;e[3]!==n?(l=n&&r.jsx("span",{"aria-label":"Automation-triggered",className:"absolute -bottom-0.5 -right-0.5 flex size-4 items-center justify-center rounded-full bg-blue-500 border border-blue-600 text-white",children:r.jsx($i,{size:10,className:"text-white"})}),e[3]=n,e[4]=l):l=e[4];let c;return e[5]!==a||e[6]!==l?(c=r.jsxs("div",{className:"relative shrink-0",children:[a,l]}),e[5]=a,e[6]=l,e[7]=c):c=e[7],c}function Kb(t){const e=B.c(6),{virtualMcpId:s,size:i}=t,n=ts(s);if(!n){let l;return e[0]!==i?(l=r.jsx(zs,{icon:null,name:"?",size:i}),e[0]=i,e[1]=l):l=e[1],l}const o=n.icon??null;let a;return e[2]!==n.title||e[3]!==i||e[4]!==o?(a=r.jsx(zs,{icon:o,name:n.title,size:i}),e[2]=n.title,e[3]=i,e[4]=o,e[5]=a):a=e[5],a}function Fs(t){const e=t?.metadata?.githubRepo;return e?.connectionId&&t?.connections?.some(i=>i.connection_id===e.connectionId)?e:null}function qb(t){const e=B.c(42),{task:s,isActive:i,onClick:n,onArchive:o,showAutomationBadge:a}=t,l=zp(s.status),c=l.icon,d=ts(s.virtual_mcp_id);let u;e[0]!==d?(u=Fs(d),e[0]=d,e[1]=u):u=e[1];const h=u,f="button",m=0;let p;e[2]!==n?(p=O=>{O.target===O.currentTarget&&(O.key==="Enter"||O.key===" ")&&(O.preventDefault(),n())},e[2]=n,e[3]=p):p=e[3];const g=i?"bg-accent":"hover:bg-accent/60";let _;e[4]!==g?(_=X("group/row flex items-center gap-3 px-2 py-1.5 rounded-md cursor-pointer transition-colors",g),e[4]=g,e[5]=_):_=e[5];let v;e[6]!==a||e[7]!==s.virtual_mcp_id?(v=r.jsx(Ub,{virtualMcpId:s.virtual_mcp_id,size:"sm",showAutomationBadge:a}),e[6]=a,e[7]=s.virtual_mcp_id,e[8]=v):v=e[8];const x=s.title||"Untitled task";let b;e[9]!==x?(b=r.jsx("div",{className:"text-sm text-foreground truncate",children:x}),e[9]=x,e[10]=b):b=e[10];let y;e[11]!==h||e[12]!==s.branch||e[13]!==s.updated_at?(y=s.updated_at&&r.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground min-w-0",children:[s.branch?r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"truncate font-mono",children:s.branch}),r.jsx("span",{className:"shrink-0",children:"·"})]}):h?r.jsxs(r.Fragment,{children:[r.jsxs("span",{className:"truncate",children:[h.owner,"/",h.name]}),r.jsx("span",{className:"shrink-0",children:"·"})]}):null,r.jsx("span",{className:"shrink-0",children:Fp(new Date(s.updated_at))})]}),e[11]=h,e[12]=s.branch,e[13]=s.updated_at,e[14]=y):y=e[14];let C;e[15]!==y||e[16]!==b?(C=r.jsxs("div",{className:"flex-1 min-w-0",children:[b,y]}),e[15]=y,e[16]=b,e[17]=C):C=e[17];const j="shrink-0 grid [grid-template-areas:'slot'] items-center justify-items-center",V="[grid-area:slot] flex size-7 items-center justify-center group-hover/row:invisible",w=l.label,k=14,T=X(l.iconClassName,s.status==="in_progress"&&"animate-spin");let I;e[18]!==c||e[19]!==T?(I=r.jsx(c,{size:k,className:T}),e[18]=c,e[19]=T,e[20]=I):I=e[20];let A;e[21]!==l||e[22]!==I?(A=r.jsx("span",{className:V,"aria-label":w,children:I}),e[21]=l,e[22]=I,e[23]=A):A=e[23];let N;e[24]!==o?(N=O=>{O.stopPropagation(),o()},e[24]=o,e[25]=N):N=e[25];let E;e[26]===Symbol.for("react.memo_cache_sentinel")?(E=r.jsx(_g,{size:14}),e[26]=E):E=e[26];let R;e[27]!==N?(R=r.jsx(tt,{asChild:!0,children:r.jsx("button",{type:"button","aria-label":"Archive task",onClick:N,className:"[grid-area:slot] invisible group-hover/row:visible flex size-7 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-muted",children:E})}),e[27]=N,e[28]=R):R=e[28];let M;e[29]===Symbol.for("react.memo_cache_sentinel")?(M=r.jsx(st,{side:"right",children:"Archive"}),e[29]=M):M=e[29];let L;e[30]!==R?(L=r.jsxs(it,{children:[R,M]}),e[30]=R,e[31]=L):L=e[31];let D;e[32]!==A||e[33]!==L?(D=r.jsxs("div",{className:j,children:[A,L]}),e[32]=A,e[33]=L,e[34]=D):D=e[34];let P;return e[35]!==n||e[36]!==C||e[37]!==D||e[38]!==p||e[39]!==_||e[40]!==v?(P=r.jsxs("div",{role:f,tabIndex:m,onClick:n,onKeyDown:p,className:_,children:[v,C,D]}),e[35]=n,e[36]=C,e[37]=D,e[38]=p,e[39]=_,e[40]=v,e[41]=P):P=e[41],P}const Gu={all:"All tasks",manual:"Chats",automation:"Automation"},Yu={all:"All members",mine:"Mine only"};function Gb(t){const e=B.c(57),{title:s,tasks:i,activeTaskId:n,onSelect:o,onArchive:a,onNew:l,showNewButton:c,showAutomationBadge:d,emptyLabel:u,currentUserId:h}=t,[f,m]=S.useState("all"),[p,g]=S.useState("mine");let _;e[0]!==h||e[1]!==p||e[2]!==i?(_=p==="mine"&&h?i.filter(G=>G.created_by===h):i,e[0]=h,e[1]=p,e[2]=i,e[3]=_):_=e[3];const v=_;let x;e[4]!==f||e[5]!==v?(x=f==="automation"?v.filter(Qb):f==="manual"?v.filter(Jb):v,e[4]=f,e[5]=v,e[6]=x):x=e[6];const b=x;let y;e[7]!==s?(y=r.jsx("span",{children:s}),e[7]=s,e[8]=y):y=e[8];let C;e[9]!==p?(C=r.jsx(ks,{asChild:!0,children:r.jsx("button",{type:"button","aria-label":"Filter by member",className:"flex size-8 items-center justify-center rounded-md hover:bg-muted hover:text-foreground",children:p==="mine"?r.jsx(xg,{size:16}):r.jsx(ao,{size:16})})}),e[9]=p,e[10]=C):C=e[10];let j;e[11]!==p?(j=G=>{const q=G;q!==p&&se("tasks_panel_member_filter_changed",{to_value:q}),g(q)},e[11]=p,e[12]=j):j=e[12];let V;e[13]===Symbol.for("react.memo_cache_sentinel")?(V=Object.keys(Yu),e[13]=V):V=e[13];let w;e[14]===Symbol.for("react.memo_cache_sentinel")?(w=V.map(Xb),e[14]=w):w=e[14];let k;e[15]!==p||e[16]!==j?(k=r.jsx(Ns,{align:"end",children:r.jsx(hc,{value:p,onValueChange:j,children:w})}),e[15]=p,e[16]=j,e[17]=k):k=e[17];let T;e[18]!==C||e[19]!==k?(T=r.jsxs(js,{children:[C,k]}),e[18]=C,e[19]=k,e[20]=T):T=e[20];const I=f!=="all"&&"text-purple-500";let A;e[21]!==I?(A=X("flex size-8 items-center justify-center rounded-md hover:bg-muted hover:text-foreground",I),e[21]=I,e[22]=A):A=e[22];let N;e[23]===Symbol.for("react.memo_cache_sentinel")?(N=r.jsx($g,{size:16}),e[23]=N):N=e[23];let E;e[24]!==A?(E=r.jsx(ks,{asChild:!0,children:r.jsx("button",{type:"button","aria-label":"Filter tasks",className:A,children:N})}),e[24]=A,e[25]=E):E=e[25];let R;e[26]!==f?(R=G=>{const q=G;q!==f&&se("tasks_panel_filter_changed",{to_value:q}),m(q)},e[26]=f,e[27]=R):R=e[27];let M;e[28]===Symbol.for("react.memo_cache_sentinel")?(M=Object.keys(Gu),e[28]=M):M=e[28];let L;e[29]===Symbol.for("react.memo_cache_sentinel")?(L=M.map(Yb),e[29]=L):L=e[29];let D;e[30]!==f||e[31]!==R?(D=r.jsx(Ns,{align:"end",children:r.jsx(hc,{value:f,onValueChange:R,children:L})}),e[30]=f,e[31]=R,e[32]=D):D=e[32];let P;e[33]!==E||e[34]!==D?(P=r.jsxs(js,{children:[E,D]}),e[33]=E,e[34]=D,e[35]=P):P=e[35];let O;e[36]!==l||e[37]!==c||e[38]!==s?(O=c&&l&&r.jsx("button",{type:"button",onClick:()=>{se("tasks_panel_new_clicked"),l()},"aria-label":`New ${s.toLowerCase()}`,className:"flex size-8 items-center justify-center rounded-md hover:bg-muted hover:text-foreground",children:r.jsx(pl,{size:16})}),e[36]=l,e[37]=c,e[38]=s,e[39]=O):O=e[39];let z;e[40]!==P||e[41]!==O||e[42]!==T?(z=r.jsxs("div",{className:"flex items-center gap-0.5",children:[T,P,O]}),e[40]=P,e[41]=O,e[42]=T,e[43]=z):z=e[43];let $;e[44]!==z||e[45]!==y?($=r.jsxs("div",{className:"pl-2 pr-1.5 h-7 flex items-center justify-between text-xs font-medium text-muted-foreground mb-1",children:[y,z]}),e[44]=z,e[45]=y,e[46]=$):$=e[46];let W;e[47]!==n||e[48]!==u||e[49]!==a||e[50]!==o||e[51]!==d||e[52]!==b?(W=b.length===0&&u?r.jsx("div",{className:"px-2 py-1.5 text-xs text-muted-foreground/70",children:u}):b.map(G=>r.jsx(qb,{task:G,isActive:n===G.id,onClick:()=>{n!==G.id&&se("tasks_panel_task_clicked",{thread_id:G.id,virtual_mcp_id:G.virtual_mcp_id??null,from_automation:!!G.fromAutomation}),o(G)},onArchive:()=>{se("tasks_panel_task_archived",{thread_id:G.id,virtual_mcp_id:G.virtual_mcp_id??null}),a(G)},showAutomationBadge:d||G.fromAutomation},G.id)),e[47]=n,e[48]=u,e[49]=a,e[50]=o,e[51]=d,e[52]=b,e[53]=W):W=e[53];let F;return e[54]!==$||e[55]!==W?(F=r.jsxs("div",{className:"flex flex-col gap-0.5 mt-1",children:[$,W]}),e[54]=$,e[55]=W,e[56]=F):F=e[56],F}function Yb(t){return r.jsx(Oh,{value:t,children:Gu[t]},t)}function Xb(t){return r.jsx(Oh,{value:t,children:Yu[t]},t)}function Jb(t){return!t.fromAutomation}function Qb(t){return t.fromAutomation}function Zb(){const t=B.c(22);Wb();const{data:e}=St.useSession(),s=e?.user?.id;let i;t[0]===Symbol.for("react.memo_cache_sentinel")?(i={owner:"me",status:"open",hasTrigger:!1},t[0]=i):i=t[0];const{tasks:n}=ia(i);let o;t[1]===Symbol.for("react.memo_cache_sentinel")?(o={owner:"all",status:"open",hasTrigger:!0},t[1]=o):o=t[1];const{tasks:a}=ia(o),{setTaskId:l,createNewTask:c}=zr();let d;t[2]===Symbol.for("react.memo_cache_sentinel")?(d={strict:!1},t[2]=d):d=t[2];const u=$r(d),{locator:h,org:f}=be(),m=Mt();let p;t[3]!==f.id?(p={connectionId:Wt,orgId:f.id},t[3]=f.id,t[4]=p):p=t[4];const g=Me(p),_=u.taskId??null;let v;t[5]!==a||t[6]!==n?(v=[...n,...a.map(t0)].sort(e0),t[5]=a,t[6]=n,t[7]=v):v=t[7];const x=v;let b;t[8]!==g||t[9]!==h||t[10]!==m?(b=async V=>{try{await Ep(g,V.id,{hidden:!0}),m.invalidateQueries({queryKey:lt.tasksPrefix(h)})}catch(w){const T=w;pe.error(`Failed to archive task: ${T.message}`)}},t[8]=g,t[9]=h,t[10]=m,t[11]=b):b=t[11];const y=b;if(x.length===0){let V;return t[12]===Symbol.for("react.memo_cache_sentinel")?(V=r.jsx("div",{className:"h-full flex items-center justify-center p-4",children:r.jsx(Oi,{image:r.jsx(vg,{size:48,className:"text-muted-foreground"}),title:"No tasks yet",description:"Start a conversation to create your first task."})}),t[12]=V):V=t[12],V}let C;t[13]!==l?(C=V=>l(V.id,V.virtual_mcp_id),t[13]=l,t[14]=C):C=t[14];let j;return t[15]!==_||t[16]!==x||t[17]!==c||t[18]!==s||t[19]!==y||t[20]!==C?(j=r.jsx("div",{className:"flex flex-col h-full min-h-0 overflow-y-auto p-2 gap-3",children:r.jsx(Gb,{title:"Tasks",tasks:x,activeTaskId:_,onSelect:C,onArchive:y,onNew:c,showNewButton:!0,currentUserId:s})}),t[15]=_,t[16]=x,t[17]=c,t[18]=s,t[19]=y,t[20]=C,t[21]=j):j=t[21],j}function e0(t,e){return(e.updated_at??"").localeCompare(t.updated_at??"")}function t0(t){return{...t,fromAutomation:!0}}function s0(){const t=B.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=r.jsx("div",{className:"flex flex-col h-full p-2 gap-1.5",children:Array.from({length:6}).map(i0)}),t[0]=e):e=t[0],e}function i0(t,e){return r.jsx("div",{className:"h-10 rounded-md bg-muted/60 animate-pulse"},e)}function Xu(){const t=B.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=r.jsx(De.Skeleton,{}),t[0]=e):e=t[0];let s;return t[1]===Symbol.for("react.memo_cache_sentinel")?(s=r.jsx(Cs,{fallback:e,children:r.jsx(S.Suspense,{fallback:r.jsx(s0,{}),children:r.jsx(Zb,{})})}),t[1]=s):s=t[1],s}function Ju(){const t=B.c(77),{org:e}=be(),s=Ke(),i=Vh(),{setTasksOpen:n,openTab:o}=zr(),a=e.slug,l=be().project;let c;t[0]===Symbol.for("react.memo_cache_sentinel")?(c={strict:!1},t[0]=c):c=t[0];const d=$r(c);let u;t[1]===Symbol.for("react.memo_cache_sentinel")?(u={strict:!1},t[1]=u):u=t[1];const h=vi(u),f=i.location.pathname;let m;t[2]!==l.enabledPlugins?(m=l.enabledPlugins??[],t[2]=l.enabledPlugins,t[3]=m):m=t[3];const p=m;let g;t[4]!==l.ui?(g=l.ui?.pinnedViews??[],t[4]=l.ui,t[5]=g):g=t[5];const _=g;let v,x,b,y;if(t[6]!==l.id||t[7]!==p||t[8]!==s||t[9]!==a||t[10]!==d.pluginId||t[11]!==d.taskId||t[12]!==h.virtualmcpid){let q;t[17]!==p?(q=ie=>p.includes(ie.pluginId),t[17]=p,t[18]=q):q=t[18];const H=ep.filter(q),ee=h.virtualmcpid??l.id;x=!!h.virtualmcpid;const K=d.taskId??"",U=d.pluginId;let te;t[19]!==U?(te=ie=>U===ie,t[19]=U,t[20]=te):te=t[20],v=te;let Y;t[21]!==K||t[22]!==s||t[23]!==a||t[24]!==ee?(Y=ie=>{const ue=K||crypto.randomUUID();s({to:"/$org/$taskId/$pluginId",params:{org:a,taskId:ue,pluginId:ie},search:de=>({...de,virtualmcpid:ee})})},t[21]=K,t[22]=s,t[23]=a,t[24]=ee,t[25]=Y):Y=t[25],b=Y;let J;t[26]!==v||t[27]!==b?(J=ie=>({key:ie.pluginId,label:ie.label,icon:ie.icon,isActive:v(ie.pluginId),onClick:()=>b(ie.pluginId)}),t[26]=v,t[27]=b,t[28]=J):J=t[28],y=H.map(J),t[6]=l.id,t[7]=p,t[8]=s,t[9]=a,t[10]=d.pluginId,t[11]=d.taskId,t[12]=h.virtualmcpid,t[13]=v,t[14]=x,t[15]=b,t[16]=y}else v=t[13],x=t[14],b=t[15],y=t[16];const C=y;let j;if(t[29]!==p||t[30]!==v||t[31]!==b){let q;t[33]!==p?(q=K=>p.includes(K.pluginId),t[33]=p,t[34]=q):q=t[34];const H=tp.filter(q);let ee;t[35]!==v||t[36]!==b?(ee=K=>({type:"group",group:{id:`${K.pluginId}-${K.id}`,label:K.label,items:K.items.map((U,te)=>({key:`${K.pluginId}-${K.id}-${te}`,label:U.label,icon:U.icon,isActive:v(K.pluginId),onClick:()=>b(K.pluginId)})),defaultExpanded:K.defaultExpanded??!0}}),t[35]=v,t[36]=b,t[37]=ee):ee=t[37],j=H.map(ee),t[29]=p,t[30]=v,t[31]=b,t[32]=j}else j=t[32];const V=j;let w;if(t[38]!==o||t[39]!==_){let q;t[41]!==o?(q=H=>{const ee=Fr(H.icon),K=ee.type==="icon"?Hr(ee.name):null;return{key:`app-${H.connectionId}-${H.toolName}`,label:H.label||H.toolName,icon:K?r.jsx(K,{size:16,className:"text-muted-foreground"}):ee.type==="url"?r.jsx("img",{src:ee.url,alt:"",className:"size-4 rounded"}):r.jsx(gu,{size:16,className:"text-muted-foreground"}),isActive:!1,onClick:()=>o(ra(H.connectionId,H.toolName))}},t[41]=o,t[42]=q):q=t[42],w=_.map(q),t[38]=o,t[39]=_,t[40]=w}else w=t[40];const k=w;let T;t[43]!==k?(T=k.length>0?{type:"group",group:{id:"apps",label:"Apps",items:k,defaultExpanded:!0}}:null,t[43]=k,t[44]=T):T=t[44];const I=T;let A;t[45]===Symbol.for("react.memo_cache_sentinel")?(A=r.jsx(bg,{className:"size-4!"}),t[45]=A):A=t[45];const N=f===`/${a}`||f===`/${a}/`;let E;t[46]!==s||t[47]!==a||t[48]!==n?(E=()=>{n(!1),s({to:"/$org",params:{org:a}})},t[46]=s,t[47]=a,t[48]=n,t[49]=E):E=t[49];let R;t[50]!==E||t[51]!==N?(R={key:"home",label:"Home",icon:A,isActive:N,onClick:E},t[50]=E,t[51]=N,t[52]=R):R=t[52];const M=R;let L;t[53]!==p?(L=p.includes(sp),t[53]=p,t[54]=L):L=t[54];const D=L;let P;t[55]===Symbol.for("react.memo_cache_sentinel")?(P=r.jsx(ip,{className:"size-4!"}),t[55]=P):P=t[55];let O;t[56]!==a||t[57]!==f?(O=f.startsWith(`/${a}/settings/workflows`),t[56]=a,t[57]=f,t[58]=O):O=t[58];let z;t[59]!==s||t[60]!==a?(z=()=>s({to:"/$org/settings/workflows",params:{org:a}}),t[59]=s,t[60]=a,t[61]=z):z=t[61];let $;t[62]!==O||t[63]!==z?($={key:"workflows",label:"Workflows",icon:P,isActive:O,onClick:z},t[62]=O,t[63]=z,t[64]=$):$=t[64];const W=$;let F;if(t[65]!==M||t[66]!==x||t[67]!==D||t[68]!==W){const q=[M];x&&D&&q.push(W),F={type:"items",items:q},t[65]=M,t[66]=x,t[67]=D,t[68]=W,t[69]=F}else F=t[69];let G;if(t[70]!==I||t[71]!==V||t[72]!==C||t[73]!==F){if(G=[F],C.length>0){let q;t[75]!==C?(q={type:"items",items:C},t[75]=C,t[76]=q):q=t[76],G.push(q)}V.length>0&&G.push(...V),I&&G.push(I),t[70]=I,t[71]=V,t[72]=C,t[73]=F,t[74]=G}else G=t[74];return G}function Qu(t){const e=B.c(3),{children:s}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=r.jsx("div",{className:"flex h-6 items-center",children:r.jsx("div",{className:"h-0.5 w-16 rounded-full bg-sidebar-foreground/15"})}),e[0]=i):i=e[0];let n;return e[1]!==s?(n=r.jsxs(Ur,{className:"pt-0 pr-0 pb-2 pl-0 mt-2",children:[i,r.jsx(Kr,{children:r.jsx(gs,{className:"gap-0.5",children:s})})]}),e[1]=s,e[2]=n):n=e[2],n}function r0(){const t=B.c(7),s=Ch().logo??jh,i=typeof s=="string"?s:s.light,n=typeof s=="string"?s:s.dark;let o;t[0]!==i?(o=r.jsx("img",{src:i,alt:"Logo",className:"size-6 object-contain dark:hidden"}),t[0]=i,t[1]=o):o=t[1];let a;t[2]!==n?(a=r.jsx("img",{src:n,alt:"Logo",className:"size-6 object-contain hidden dark:block"}),t[2]=n,t[3]=a):a=t[3];let l;return t[4]!==o||t[5]!==a?(l=r.jsx(vu,{className:"flex items-center justify-center shrink-0 px-2 pb-0",children:r.jsxs("div",{className:"flex w-full aspect-square items-center justify-center",children:[o,a]})}),t[4]=o,t[5]=a,t[6]=l):l=t[6],l}function Zu(t){const e=B.c(15),{item:s}=t,{isMobile:i,setOpenMobile:n}=qr();let o;e[0]!==i||e[1]!==s||e[2]!==n?(o=()=>{se("nav_item_clicked",{nav_key:s.key,nav_label:s.label,is_active:!!s.isActive,is_mobile:i}),s.onClick?.(),i&&n(!1)},e[0]=i,e[1]=s,e[2]=n,e[3]=o):o=e[3];const a=o,l=s.key,c=s.isActive&&"z-10";let d;e[4]!==c?(d=X(c),e[4]=c,e[5]=d):d=e[5];let u;e[6]!==a||e[7]!==s.icon||e[8]!==s.isActive||e[9]!==s.label?(u=r.jsx(us,{onClick:a,isActive:s.isActive,tooltip:s.label,className:"bg-muted/75",children:s.icon}),e[6]=a,e[7]=s.icon,e[8]=s.isActive,e[9]=s.label,e[10]=u):u=e[10];let h;return e[11]!==s.key||e[12]!==d||e[13]!==u?(h=r.jsx(Zt,{className:d,children:u},l),e[11]=s.key,e[12]=d,e[13]=u,e[14]=h):h=e[14],h}function n0(t){const e=B.c(12),{section:s}=t;switch(s.type){case"divider":{let i;return e[0]===Symbol.for("react.memo_cache_sentinel")?(i=r.jsx(_u,{className:"my-2"}),e[0]=i):i=e[0],i}case"spacer":{let i;return e[1]===Symbol.for("react.memo_cache_sentinel")?(i=r.jsx("div",{className:"flex-1"}),e[1]=i):i=e[1],i}case"group":{const i=s.group.label,n=s.group.defaultExpanded;let o;e[2]!==s.group.items?(o=s.group.items.map(a0),e[2]=s.group.items,e[3]=o):o=e[3];let a;return e[4]!==s.group.defaultExpanded||e[5]!==s.group.label||e[6]!==o?(a=r.jsx(Qu,{label:i,defaultExpanded:n,children:o}),e[4]=s.group.defaultExpanded,e[5]=s.group.label,e[6]=o,e[7]=a):a=e[7],a}case"items":{let i;e[8]!==s.items?(i=s.items.map(o0),e[8]=s.items,e[9]=i):i=e[9];let n;return e[10]!==i?(n=r.jsx(Ur,{className:"pt-0 pr-0 pb-0 pl-0",children:r.jsx(Kr,{children:r.jsx(gs,{className:"gap-1.5",children:i})})}),e[10]=i,e[11]=n):n=e[11],n}}}function o0(t){return r.jsx(Zu,{item:t},t.key)}function a0(t){return r.jsx(Zu,{item:t},t.key)}function l0(t){const e=B.c(14),{sections:s,header:i,footer:n,additionalContent:o,variant:a,contentClassName:l}=t,c=a===void 0?"sidebar":a;let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d=r.jsx(S.Suspense,{fallback:r.jsx("div",{className:"h-10 shrink-0"}),children:r.jsx(r0,{})}),e[0]=d):d=e[0];let u;e[1]!==l?(u=X("flex flex-col flex-1 px-2 py-2 gap-0",l),e[1]=l,e[2]=u):u=e[2];let h;e[3]!==s?(h=s.map(c0),e[3]=s,e[4]=h):h=e[4];let f;e[5]!==o||e[6]!==u||e[7]!==h?(f=r.jsxs(xu,{className:u,children:[h,o]}),e[5]=o,e[6]=u,e[7]=h,e[8]=f):f=e[8];let m;return e[9]!==n||e[10]!==i||e[11]!==f||e[12]!==c?(m=r.jsxs(y_,{variant:c,children:[d,i,f,n]}),e[9]=n,e[10]=i,e[11]=f,e[12]=c,e[13]=m):m=e[13],m}function c0(t,e){return r.jsx(n0,{section:t},e)}function ef(t){const e=B.c(2);let s;return e[0]!==t?(s=r.jsx(l0,{...t}),e[0]=t,e[1]=s):s=e[1],s}ef.Skeleton=function(){return r.jsx("div",{className:"flex flex-col gap-0.5",children:Array.from({length:8}).map((e,s)=>r.jsx("div",{className:"w-full h-8",children:r.jsx(Bi,{className:"h-full bg-sidebar-accent rounded-md"})},s))})};function d0(){const t=B.c(7),s=Ch().logo??jh,i=typeof s=="string"?s:s.light,n=typeof s=="string"?s:s.dark;let o;t[0]!==i?(o=r.jsx("img",{src:i,alt:"Logo",className:"size-6 object-contain dark:hidden"}),t[0]=i,t[1]=o):o=t[1];let a;t[2]!==n?(a=r.jsx("img",{src:n,alt:"Logo",className:"size-6 object-contain hidden dark:block"}),t[2]=n,t[3]=a):a=t[3];let l;return t[4]!==o||t[5]!==a?(l=r.jsx(vu,{className:"flex items-center justify-center shrink-0 px-2 pb-0",children:r.jsxs("div",{className:"flex w-full aspect-square items-center justify-center",children:[o,a]})}),t[4]=o,t[5]=a,t[6]=l):l=t[6],l}function Gc(t){const e=B.c(15),{item:s,onClose:i}=t,n=s.isActive&&"z-10";let o;e[0]!==n?(o=X(n),e[0]=n,e[1]=o):o=e[1];let a;e[2]!==s||e[3]!==i?(a=()=>{s.onClick?.(),i()},e[2]=s,e[3]=i,e[4]=a):a=e[4];let l;e[5]!==s.icon?(l=r.jsx("span",{className:"[&>svg]:size-8",children:s.icon}),e[5]=s.icon,e[6]=l):l=e[6];let c;e[7]!==s.isActive||e[8]!==s.label||e[9]!==a||e[10]!==l?(c=r.jsx(us,{onClick:a,isActive:s.isActive,tooltip:s.label,className:"bg-muted/75",children:l}),e[7]=s.isActive,e[8]=s.label,e[9]=a,e[10]=l,e[11]=c):c=e[11];let d;return e[12]!==o||e[13]!==c?(d=r.jsx(Zt,{className:o,children:c}),e[12]=o,e[13]=c,e[14]=d):d=e[14],d}function h0(t){const e=B.c(18),{section:s,onClose:i}=t;switch(s.type){case"divider":{let n;return e[0]===Symbol.for("react.memo_cache_sentinel")?(n=r.jsx(_u,{className:"my-2"}),e[0]=n):n=e[0],n}case"spacer":{let n;return e[1]===Symbol.for("react.memo_cache_sentinel")?(n=r.jsx("div",{className:"flex-1"}),e[1]=n):n=e[1],n}case"group":{const n=s.group.label,o=s.group.defaultExpanded;let a;if(e[2]!==i||e[3]!==s.group.items){let c;e[5]!==i?(c=d=>r.jsx(Gc,{item:d,onClose:i},d.key),e[5]=i,e[6]=c):c=e[6],a=s.group.items.map(c),e[2]=i,e[3]=s.group.items,e[4]=a}else a=e[4];let l;return e[7]!==s.group.defaultExpanded||e[8]!==s.group.label||e[9]!==a?(l=r.jsx(Qu,{label:n,defaultExpanded:o,children:a}),e[7]=s.group.defaultExpanded,e[8]=s.group.label,e[9]=a,e[10]=l):l=e[10],l}case"items":{let n;if(e[11]!==i||e[12]!==s.items){let a;e[14]!==i?(a=l=>r.jsx(Gc,{item:l,onClose:i},l.key),e[14]=i,e[15]=a):a=e[15],n=s.items.map(a),e[11]=i,e[12]=s.items,e[13]=n}else n=e[13];let o;return e[16]!==n?(o=r.jsx(Ur,{className:"pt-0 pr-0 pb-0 pl-0",children:r.jsx(Kr,{children:r.jsx(gs,{className:"gap-1.5",children:n})})}),e[16]=n,e[17]=o):o=e[17],o}}}function u0(t){const e=B.c(12),{sections:s,onClose:i,footer:n,additionalContent:o}=t;let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=r.jsx(S.Suspense,{fallback:r.jsx("div",{className:"h-10 shrink-0"}),children:r.jsx(d0,{})}),e[0]=a):a=e[0];let l;if(e[1]!==i||e[2]!==s){let u;e[4]!==i?(u=(h,f)=>r.jsx(h0,{section:h,onClose:i},f),e[4]=i,e[5]=u):u=e[5],l=s.map(u),e[1]=i,e[2]=s,e[3]=l}else l=e[3];let c;e[6]!==o||e[7]!==l?(c=r.jsxs(xu,{className:"flex flex-col flex-1 px-2 py-2 gap-0",children:[l,o]}),e[6]=o,e[7]=l,e[8]=c):c=e[8];let d;return e[9]!==n||e[10]!==c?(d=r.jsxs("div",{className:"bg-sidebar flex h-full w-full flex-col","data-sidebar":"sidebar",children:[a,c,n]}),e[9]=n,e[10]=c,e[11]=d):d=e[11],d}function tf(t){return t.toLowerCase().trim().replace(/[^a-z0-9\s_-]+/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}const f0=Vs({name:Et().min(2,"Organization name is required")});function m0(t){const e=B.c(41),{open:s,onOpenChange:i}=t;let n;e[0]===Symbol.for("react.memo_cache_sentinel")?(n={resolver:Or(f0),defaultValues:{name:""}},e[0]=n):n=e[0];const o=Hi(n);let a;e[1]===Symbol.for("react.memo_cache_sentinel")?(a={mutationFn:g0,onSuccess:p0},e[1]=a):a=e[1];const l=Br(a),c=l.error instanceof Error?l.error.message:l.error?"Failed to create organization.":null;let d;e[2]===Symbol.for("react.memo_cache_sentinel")?(d=r.jsxs(kl,{children:[r.jsx(Nl,{children:"Create a new organization"}),r.jsx(Al,{children:"Set up a new organization to collaborate with others."})]}),e[2]=d):d=e[2];let u;if(e[3]!==l||e[4]!==o){let V;e[6]!==l?(V=w=>l.mutateAsync(w),e[6]=l,e[7]=V):V=e[7],u=o.handleSubmit(V),e[3]=l,e[4]=o,e[5]=u}else u=e[5];let h;e[8]!==o.formState.isSubmitting?(h=V=>{const{field:w}=V;return r.jsxs(Rt,{children:[r.jsx(rs,{children:"Organization Name"}),r.jsx(Tt,{children:r.jsx(bt,{...w,placeholder:"Acme Inc.",disabled:o.formState.isSubmitting})}),r.jsx(hg,{children:"The name of your company or organization"}),w.value&&r.jsxs("div",{className:"text-xs text-muted-foreground mt-1",children:["Organization URL:"," ",r.jsxs("span",{className:"font-mono",children:[typeof window<"u"?globalThis.location.origin:"","/",tf(w.value)]})]}),r.jsx(Dt,{})]})},e[8]=o.formState.isSubmitting,e[9]=h):h=e[9];let f;e[10]!==o.control||e[11]!==h?(f=r.jsx(It,{control:o.control,name:"name",render:h}),e[10]=o.control,e[11]=h,e[12]=f):f=e[12];let m;e[13]!==c?(m=c&&r.jsx("div",{className:"text-destructive text-sm mt-2",children:c}),e[13]=c,e[14]=m):m=e[14];let p;e[15]!==l||e[16]!==o?(p=()=>{l.reset(),o.reset()},e[15]=l,e[16]=o,e[17]=p):p=e[17];let g;e[18]!==o.formState.isSubmitting||e[19]!==p?(g=r.jsx(Cl,{disabled:o.formState.isSubmitting,onClick:p,children:"Cancel"}),e[18]=o.formState.isSubmitting,e[19]=p,e[20]=g):g=e[20];const _=!o.formState.isValid||o.formState.isSubmitting;let v;e[21]!==o.formState.isSubmitting?(v=o.formState.isSubmitting?r.jsxs("span",{className:"flex items-center gap-2",children:[r.jsx(jr,{size:"xs"})," Creating..."]}):"Create Organization",e[21]=o.formState.isSubmitting,e[22]=v):v=e[22];let x;e[23]!==_||e[24]!==v?(x=r.jsx(ne,{type:"submit",variant:"default",disabled:_,children:v}),e[23]=_,e[24]=v,e[25]=x):x=e[25];let b;e[26]!==x||e[27]!==g?(b=r.jsxs(El,{children:[g,x]}),e[26]=x,e[27]=g,e[28]=b):b=e[28];let y;e[29]!==b||e[30]!==u||e[31]!==f||e[32]!==m?(y=r.jsxs("form",{className:"space-y-6",onSubmit:u,autoComplete:"off",children:[f,m,b]}),e[29]=b,e[30]=u,e[31]=f,e[32]=m,e[33]=y):y=e[33];let C;e[34]!==o||e[35]!==y?(C=r.jsxs(jl,{children:[d,r.jsx(Pi,{...o,children:y})]}),e[34]=o,e[35]=y,e[36]=C):C=e[36];let j;return e[37]!==i||e[38]!==s||e[39]!==C?(j=r.jsx(Il,{open:s,onOpenChange:i,children:C}),e[37]=i,e[38]=s,e[39]=C,e[40]=j):j=e[40],j}function p0(t){const{orgSlug:e}=t;window.location.href=`/${e}`}async function g0(t){const e=tf(t.name);if(!e)throw new Error("Organization slug is invalid");const s=await St.organization.create({name:t.name,slug:e});if(s?.error)throw new Error(s.error.message||"Failed to create organization");const i=s?.data?.slug??e;if(!i)throw new Error("Failed to create organization");return{orgSlug:i}}function ga(t){let e=0;for(let i=0;i<t.length;i++)e=t.charCodeAt(i)+((e<<5)-e);const s=Math.abs(e)%360;return{backgroundColor:`hsl(${s} 55% 70%)`,color:`hsl(${s} 55% 20%)`}}function _0(t){const e=B.c(13),{org:s,size:i}=t,n=i===void 0?"sm":i,o=n==="xs"?"size-5":"size-6",a=n==="xs"?"text-[9px]":"text-xs";let l;e[0]!==o?(l=X(o,"shrink-0 rounded-md flex items-center justify-center border border-border/50 overflow-hidden"),e[0]=o,e[1]=l):l=e[1];let c;e[2]!==s.logo||e[3]!==s.name?(c=s.logo?void 0:ga(s.name),e[2]=s.logo,e[3]=s.name,e[4]=c):c=e[4];let d;e[5]!==s.logo||e[6]!==s.name||e[7]!==a?(d=s.logo?r.jsx("img",{src:s.logo,alt:"",className:"size-full object-cover"}):r.jsx("span",{className:X("font-semibold leading-none",a),children:s.name.slice(0,2).toUpperCase()}),e[5]=s.logo,e[6]=s.name,e[7]=a,e[8]=d):d=e[8];let u;return e[9]!==l||e[10]!==c||e[11]!==d?(u=r.jsx("div",{className:l,style:c,children:d}),e[9]=l,e[10]=c,e[11]=d,e[12]=u):u=e[12],u}function ln(t){const e=B.c(22),{item:s,onClose:i}=t;if(s.href){const c=s.external?"_blank":void 0,d=s.external?"noopener noreferrer":void 0;let u;e[0]!==s.icon?(u=r.jsx("span",{className:"shrink-0 text-muted-foreground",children:s.icon}),e[0]=s.icon,e[1]=u):u=e[1];let h;e[2]!==s.label?(h=r.jsx("span",{className:"flex-1",children:s.label}),e[2]=s.label,e[3]=h):h=e[3];let f;return e[4]!==s.href||e[5]!==i||e[6]!==c||e[7]!==d||e[8]!==u||e[9]!==h?(f=r.jsxs("a",{href:s.href,target:c,rel:d,className:"flex items-center gap-2.5 px-3 py-2 rounded-md text-sm text-left w-full transition-colors text-foreground/80 hover:bg-sidebar-accent hover:text-foreground",onClick:i,children:[u,h]}),e[4]=s.href,e[5]=i,e[6]=c,e[7]=d,e[8]=u,e[9]=h,e[10]=f):f=e[10],f}let n;e[11]!==s||e[12]!==i?(n=()=>{s.onClick?.(),i()},e[11]=s,e[12]=i,e[13]=n):n=e[13];let o;e[14]!==s.icon?(o=r.jsx("span",{className:"shrink-0 text-muted-foreground",children:s.icon}),e[14]=s.icon,e[15]=o):o=e[15];let a;e[16]!==s.label?(a=r.jsx("span",{className:"flex-1",children:s.label}),e[16]=s.label,e[17]=a):a=e[17];let l;return e[18]!==n||e[19]!==o||e[20]!==a?(l=r.jsxs("button",{type:"button",onClick:n,className:"flex items-center gap-2.5 px-3 py-2 rounded-md text-sm text-left w-full transition-colors text-foreground/80 hover:bg-sidebar-accent hover:text-foreground",children:[o,a]}),e[18]=n,e[19]=o,e[20]=a,e[21]=l):l=e[21],l}function Yc(t){const e=B.c(16),{sortedOrgs:s,orgParam:i,onSelectOrg:n,onCreateOrg:o}=t;let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=r.jsx("span",{className:"text-sm font-medium text-muted-foreground/60",children:"Your Organizations"}),e[0]=a):a=e[0];let l;e[1]===Symbol.for("react.memo_cache_sentinel")?(l=r.jsx(Qt,{size:16}),e[1]=l):l=e[1];let c;e[2]!==o?(c=r.jsxs("div",{className:"flex items-center justify-between px-4 py-3",children:[a,r.jsx("button",{type:"button",onClick:o,className:"flex items-center justify-center size-7 rounded-md text-muted-foreground hover:bg-accent/50 hover:text-foreground transition-colors",children:l})]}),e[2]=o,e[3]=c):c=e[3];let d;if(e[4]!==n||e[5]!==i||e[6]!==s){let f;e[8]!==n||e[9]!==i?(f=m=>r.jsxs("button",{type:"button",onClick:()=>n(m.slug),className:X("flex items-center gap-3 px-3 py-2.5 rounded-md text-sm text-left w-full transition-colors",m.slug===i?"bg-accent text-accent-foreground":"text-foreground hover:bg-accent/50"),children:[r.jsx(_0,{org:m,size:"sm"}),r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-sm font-medium truncate",children:m.name}),r.jsx("p",{className:"text-xs text-muted-foreground truncate",children:m.slug})]}),m.slug===i&&r.jsx(Jt,{size:14,className:"ml-auto text-muted-foreground shrink-0"})]},m.id),e[8]=n,e[9]=i,e[10]=f):f=e[10],d=s.map(f),e[4]=n,e[5]=i,e[6]=s,e[7]=d}else d=e[7];let u;e[11]!==d?(u=r.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto p-1.5 flex flex-col gap-1",children:d}),e[11]=d,e[12]=u):u=e[12];let h;return e[13]!==c||e[14]!==u?(h=r.jsxs(r.Fragment,{children:[c,u]}),e[13]=c,e[14]=u,e[15]=h):h=e[15],h}function Xc(t){const e=B.c(142),{user:s,userImage:i,menuItems:n,signOutItem:o,themeOptions:a,preferences:l,setPreferences:c,sortedOrgs:d,orgParam:u,onSelectOrg:h,onCreateOrg:f,close:m,isMobile:p}=t;if(p){const K=s?.name??"U";let U;e[0]!==K||e[1]!==i?(U=r.jsx(Vc,{url:i,fallback:K,shape:"circle",size:"sm",className:"shrink-0"}),e[0]=K,e[1]=i,e[2]=U):U=e[2];const te=s?.name??"User";let Y;e[3]!==te?(Y=r.jsx("p",{className:"text-sm font-medium truncate",children:te}),e[3]=te,e[4]=Y):Y=e[4];const J=s?.email;let ie;e[5]!==J?(ie=r.jsx("p",{className:"text-xs text-muted-foreground truncate",children:J}),e[5]=J,e[6]=ie):ie=e[6];let ue;e[7]!==Y||e[8]!==ie?(ue=r.jsxs("div",{className:"flex-1 min-w-0",children:[Y,ie]}),e[7]=Y,e[8]=ie,e[9]=ue):ue=e[9];let de;e[10]!==s?(de=()=>{s?.id&&navigator.clipboard.writeText(s.id).then(y0)},e[10]=s,e[11]=de):de=e[11];let xe;e[12]===Symbol.for("react.memo_cache_sentinel")?(xe=r.jsx(Li,{size:14}),e[12]=xe):xe=e[12];let oe;e[13]!==de?(oe=r.jsx(tt,{asChild:!0,children:r.jsx("button",{type:"button",tabIndex:-1,onClick:de,className:"shrink-0 text-muted-foreground hover:text-foreground transition-colors",children:xe})}),e[13]=de,e[14]=oe):oe=e[14];let he;e[15]===Symbol.for("react.memo_cache_sentinel")?(he=r.jsx(st,{side:"right",children:r.jsx("p",{className:"text-xs",children:"Copy user ID"})}),e[15]=he):he=e[15];let me;e[16]!==oe?(me=r.jsx(Mi,{delayDuration:300,children:r.jsxs(it,{children:[oe,he]})}),e[16]=oe,e[17]=me):me=e[17];let fe;e[18]!==me||e[19]!==U||e[20]!==ue?(fe=r.jsxs("div",{className:"flex items-center gap-3 px-4 py-4 border-b border-border",children:[U,ue,me]}),e[18]=me,e[19]=U,e[20]=ue,e[21]=fe):fe=e[21];let le;e[22]!==f||e[23]!==h||e[24]!==u||e[25]!==d?(le=r.jsx("div",{className:"border-b border-border pb-2",children:r.jsx(Yc,{sortedOrgs:d,orgParam:u,onSelectOrg:h,onCreateOrg:f})}),e[22]=f,e[23]=h,e[24]=u,e[25]=d,e[26]=le):le=e[26];let ve;if(e[27]!==m||e[28]!==n){let Pe;e[30]!==m?(Pe=Kt=>r.jsx(ln,{item:Kt,onClose:m},Kt.key),e[30]=m,e[31]=Pe):Pe=e[31],ve=n.map(Pe),e[27]=m,e[28]=n,e[29]=ve}else ve=e[29];let Ce;e[32]!==m||e[33]!==o?(Ce=r.jsx(ln,{item:o,onClose:m}),e[32]=m,e[33]=o,e[34]=Ce):Ce=e[34];let Te;e[35]!==ve||e[36]!==Ce?(Te=r.jsxs("nav",{className:"flex flex-col px-2 pt-2 pb-2 gap-0.5",children:[ve,Ce]}),e[35]=ve,e[36]=Ce,e[37]=Te):Te=e[37];let Q;e[38]!==le||e[39]!==Te?(Q=r.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[le,Te]}),e[38]=le,e[39]=Te,e[40]=Q):Q=e[40];let ae;if(e[41]!==l.theme||e[42]!==c||e[43]!==a){let Pe;e[45]!==l.theme||e[46]!==c?(Pe=Kt=>{const{value:jt,icon:Ae,label:Ie}=Kt;return r.jsx("button",{type:"button","aria-label":Ie,onClick:()=>c(qe=>({...qe,theme:jt})),className:X("size-8 rounded-md flex items-center justify-center transition-colors",l.theme===jt?"bg-sidebar-accent text-foreground":"text-muted-foreground hover:bg-sidebar-accent/50 hover:text-foreground"),children:Ae},jt)},e[45]=l.theme,e[46]=c,e[47]=Pe):Pe=e[47],ae=a.map(Pe),e[41]=l.theme,e[42]=c,e[43]=a,e[44]=ae}else ae=e[44];let Se;e[48]!==ae?(Se=r.jsx("div",{className:"flex items-center gap-0.5",children:ae}),e[48]=ae,e[49]=Se):Se=e[49];const Ne=l.enableSounds?"Disable sounds":"Enable sounds";let Be;e[50]!==c?(Be=()=>c(b0),e[50]=c,e[51]=Be):Be=e[51];const Oe=l.enableSounds?"text-foreground hover:bg-sidebar-accent/50":"text-muted-foreground hover:bg-sidebar-accent/50 hover:text-foreground";let He;e[52]!==Oe?(He=X("size-8 rounded-md flex items-center justify-center transition-colors",Oe),e[52]=Oe,e[53]=He):He=e[53];let Je;e[54]!==l.enableSounds?(Je=l.enableSounds?r.jsx(uc,{size:14}):r.jsx(fc,{size:14}),e[54]=l.enableSounds,e[55]=Je):Je=e[55];let dt;e[56]!==Ne||e[57]!==Be||e[58]!==He||e[59]!==Je?(dt=r.jsx("button",{type:"button","aria-label":Ne,onClick:Be,className:He,children:Je}),e[56]=Ne,e[57]=Be,e[58]=He,e[59]=Je,e[60]=dt):dt=e[60];let ge;e[61]===Symbol.for("react.memo_cache_sentinel")?(ge=r.jsxs("span",{className:"text-xs text-muted-foreground/60",children:["v","2.277.0"]}),e[61]=ge):ge=e[61];let ke;e[62]!==dt?(ke=r.jsxs("div",{className:"flex items-center gap-2",children:[dt,ge]}),e[62]=dt,e[63]=ke):ke=e[63];let Qe;e[64]!==Se||e[65]!==ke?(Qe=r.jsxs("div",{className:"flex items-center justify-between px-3 py-3 border-t border-border/50",children:[Se,ke]}),e[64]=Se,e[65]=ke,e[66]=Qe):Qe=e[66];let Ct;return e[67]!==fe||e[68]!==Q||e[69]!==Qe?(Ct=r.jsxs("div",{className:"flex flex-col h-full overflow-hidden",children:[fe,Q,Qe]}),e[67]=fe,e[68]=Q,e[69]=Qe,e[70]=Ct):Ct=e[70],Ct}const g=s?.name??"U";let _;e[71]!==g||e[72]!==i?(_=r.jsx(Vc,{url:i,fallback:g,shape:"circle",size:"sm",className:"shrink-0"}),e[71]=g,e[72]=i,e[73]=_):_=e[73];const v=s?.name??"User";let x;e[74]!==v?(x=r.jsx("p",{className:"text-sm font-medium truncate",children:v}),e[74]=v,e[75]=x):x=e[75];const b=s?.email;let y;e[76]!==b?(y=r.jsx("p",{className:"text-xs text-muted-foreground truncate",children:b}),e[76]=b,e[77]=y):y=e[77];let C;e[78]!==x||e[79]!==y?(C=r.jsxs("div",{className:"flex-1 min-w-0",children:[x,y]}),e[78]=x,e[79]=y,e[80]=C):C=e[80];let j;e[81]!==s?(j=()=>{s?.id&&navigator.clipboard.writeText(s.id).then(v0)},e[81]=s,e[82]=j):j=e[82];let V;e[83]===Symbol.for("react.memo_cache_sentinel")?(V=r.jsx(Li,{size:14}),e[83]=V):V=e[83];let w;e[84]!==j?(w=r.jsx(tt,{asChild:!0,children:r.jsx("button",{type:"button",tabIndex:-1,onClick:j,className:"shrink-0 text-muted-foreground hover:text-foreground transition-colors",children:V})}),e[84]=j,e[85]=w):w=e[85];let k;e[86]===Symbol.for("react.memo_cache_sentinel")?(k=r.jsx(st,{side:"right",children:r.jsx("p",{className:"text-xs",children:"Copy user ID"})}),e[86]=k):k=e[86];let T;e[87]!==w?(T=r.jsx(Mi,{delayDuration:300,children:r.jsxs(it,{children:[w,k]})}),e[87]=w,e[88]=T):T=e[88];let I;e[89]!==T||e[90]!==_||e[91]!==C?(I=r.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 mx-1 mt-1",children:[_,C,T]}),e[89]=T,e[90]=_,e[91]=C,e[92]=I):I=e[92];let A;if(e[93]!==m||e[94]!==n){let K;e[96]!==m?(K=U=>r.jsx(ln,{item:U,onClose:m},U.key),e[96]=m,e[97]=K):K=e[97],A=n.map(K),e[93]=m,e[94]=n,e[95]=A}else A=e[95];let N;e[98]!==m||e[99]!==o?(N=r.jsx(ln,{item:o,onClose:m}),e[98]=m,e[99]=o,e[100]=N):N=e[100];let E;e[101]!==A||e[102]!==N?(E=r.jsxs("nav",{className:"flex-1 flex flex-col px-2 pt-1 overflow-y-auto",children:[A,N]}),e[101]=A,e[102]=N,e[103]=E):E=e[103];let R;if(e[104]!==l.theme||e[105]!==c||e[106]!==a){let K;e[108]!==l.theme||e[109]!==c?(K=U=>{const{value:te,icon:Y,label:J}=U;return r.jsx("button",{type:"button","aria-label":J,onClick:()=>c(ie=>({...ie,theme:te})),className:X("size-7 rounded-md flex items-center justify-center transition-colors",l.theme===te?"bg-sidebar-accent text-foreground":"text-muted-foreground hover:bg-sidebar-accent/50 hover:text-foreground"),children:Y},te)},e[108]=l.theme,e[109]=c,e[110]=K):K=e[110],R=a.map(K),e[104]=l.theme,e[105]=c,e[106]=a,e[107]=R}else R=e[107];let M;e[111]!==R?(M=r.jsx("div",{className:"flex items-center gap-0.5",children:R}),e[111]=R,e[112]=M):M=e[112];const L=l.enableSounds?"Disable sounds":"Enable sounds";let D;e[113]!==c?(D=()=>c(x0),e[113]=c,e[114]=D):D=e[114];const P=l.enableSounds?"text-foreground hover:bg-sidebar-accent/50":"text-muted-foreground hover:bg-sidebar-accent/50 hover:text-foreground";let O;e[115]!==P?(O=X("size-7 rounded-md flex items-center justify-center transition-colors",P),e[115]=P,e[116]=O):O=e[116];let z;e[117]!==l.enableSounds?(z=l.enableSounds?r.jsx(uc,{size:14}):r.jsx(fc,{size:14}),e[117]=l.enableSounds,e[118]=z):z=e[118];let $;e[119]!==L||e[120]!==D||e[121]!==O||e[122]!==z?($=r.jsx("button",{type:"button","aria-label":L,onClick:D,className:O,children:z}),e[119]=L,e[120]=D,e[121]=O,e[122]=z,e[123]=$):$=e[123];let W;e[124]===Symbol.for("react.memo_cache_sentinel")?(W=r.jsxs("span",{className:"text-xs text-muted-foreground/60",children:["v","2.277.0"]}),e[124]=W):W=e[124];let F;e[125]!==$?(F=r.jsxs("div",{className:"flex items-center gap-2",children:[$,W]}),e[125]=$,e[126]=F):F=e[126];let G;e[127]!==M||e[128]!==F?(G=r.jsxs("div",{className:"flex items-center justify-between px-2 py-1.5 border-t border-border/50",children:[M,F]}),e[127]=M,e[128]=F,e[129]=G):G=e[129];let q;e[130]!==I||e[131]!==E||e[132]!==G?(q=r.jsxs("div",{className:"w-60 shrink-0 flex flex-col border-r border-border bg-sidebar/75",children:[I,E,G]}),e[130]=I,e[131]=E,e[132]=G,e[133]=q):q=e[133];let H;e[134]!==f||e[135]!==h||e[136]!==u||e[137]!==d?(H=r.jsx("div",{className:"flex-1 flex flex-col min-w-0 min-h-0 overflow-hidden",children:r.jsx(Yc,{sortedOrgs:d,orgParam:u,onSelectOrg:h,onCreateOrg:f})}),e[134]=f,e[135]=h,e[136]=u,e[137]=d,e[138]=H):H=e[138];let ee;return e[139]!==q||e[140]!==H?(ee=r.jsxs("div",{className:"flex min-h-[380px] w-full overflow-hidden",children:[q,H]}),e[139]=q,e[140]=H,e[141]=ee):ee=e[141],ee}function x0(t){return{...t,enableSounds:!t.enableSounds}}function v0(){pe.success("User ID copied")}function b0(t){return{...t,enableSounds:!t.enableSounds}}function y0(){pe.success("User ID copied")}function sf(){const t=B.c(50),{data:e}=St.useSession(),{data:s}=St.useListOrganizations(),i=Ke();let n;t[0]===Symbol.for("react.memo_cache_sentinel")?(n={from:"/shell/$org",shouldThrow:!1},t[0]=n):n=t[0];const a=rp(n)?.params.org,[l,c]=Wi(),d=Rs(),[u,h]=S.useState(!1),[f,m]=S.useState(!1),p=e?.user,g=p?.image;let _;if(t[1]!==d||t[2]!==i||t[3]!==u||t[4]!==a||t[5]!==s||t[6]!==l||t[7]!==c||t[8]!==p||t[9]!==g){const b=s?.find(ee=>ee.slug===a);let y;if(t[11]!==a||t[12]!==s){let ee;t[14]!==a?(ee=(K,U)=>K.slug===a?-1:U.slug===a?1:K.name.localeCompare(U.name),t[14]=a,t[15]=ee):ee=t[15],y=[...s??[]].sort(ee),t[11]=a,t[12]=s,t[13]=y}else y=t[13];const C=y;let j;t[16]!==i?(j=ee=>{h(!1),i({to:"/$org",params:{org:ee}})},t[16]=i,t[17]=j):j=t[17];const V=j;let w;t[18]===Symbol.for("react.memo_cache_sentinel")?(w=()=>h(!1),t[18]=w):w=t[18];const k=w;let T;t[19]===Symbol.for("react.memo_cache_sentinel")?(T=r.jsx(Gr,{size:16}),t[19]=T):T=t[19];let I;t[20]!==i||t[21]!==a?(I={key:"preferences",label:"Preferences",icon:T,onClick:()=>{i({to:"/$org/settings/profile",params:{org:a??""}})}},t[20]=i,t[21]=a,t[22]=I):I=t[22];let A;t[23]===Symbol.for("react.memo_cache_sentinel")?(A={key:"terms",label:"Terms of Use",icon:r.jsx(yg,{size:16}),href:"https://www.decocms.com/terms-of-use",external:!0},t[23]=A):A=t[23];let N;t[24]===Symbol.for("react.memo_cache_sentinel")?(N={key:"privacy",label:"Privacy Policy",icon:r.jsx(Sg,{size:16}),href:"https://www.decocms.com/privacy-policy",external:!0},t[24]=N):N=t[24];let E;t[25]===Symbol.for("react.memo_cache_sentinel")?(E={key:"github",label:"decocms/studio",icon:r.jsx(np,{className:"w-4 h-4"}),href:"https://github.com/decocms/studio",external:!0},t[25]=E):E=t[25];let R;t[26]===Symbol.for("react.memo_cache_sentinel")?(R={key:"community",label:"Community",icon:r.jsx(ao,{size:16}),href:"https://decocms.com/discord",external:!0},t[26]=R):R=t[26];let M;t[27]===Symbol.for("react.memo_cache_sentinel")?(M={key:"homepage",label:"Homepage",icon:r.jsx(Zh,{size:16}),href:"https://decocms.com",external:!0},t[27]=M):M=t[27];let L;t[28]!==I?(L=[I,A,N,E,R,M],t[28]=I,t[29]=L):L=t[29];const D=L;let P;t[30]===Symbol.for("react.memo_cache_sentinel")?(P={key:"logout",label:"Sign out",icon:r.jsx(Rg,{size:16}),onClick:w0},t[30]=P):P=t[30];const O=P;let z;t[31]===Symbol.for("react.memo_cache_sentinel")?(z={value:"light",icon:r.jsx(N_,{size:14}),label:"Light theme"},t[31]=z):z=t[31];let $;t[32]===Symbol.for("react.memo_cache_sentinel")?($={value:"dark",icon:r.jsx(A_,{size:14}),label:"Dark theme"},t[32]=$):$=t[32];let W;t[33]===Symbol.for("react.memo_cache_sentinel")?(W=[z,$,{value:"system",icon:r.jsx(E_,{size:14}),label:"System theme"}],t[33]=W):W=t[33];const F=W;let G;t[34]===Symbol.for("react.memo_cache_sentinel")?(G=()=>{h(!1),m(!0)},t[34]=G):G=t[34];let q;t[35]!==V||t[36]!==d||t[37]!==D||t[38]!==a||t[39]!==l||t[40]!==c||t[41]!==C||t[42]!==p||t[43]!==g?(q={user:p,userImage:g,menuItems:D,signOutItem:O,themeOptions:F,preferences:l,setPreferences:c,sortedOrgs:C,orgParam:a,onSelectOrg:V,onCreateOrg:G,close:k,isMobile:d},t[35]=V,t[36]=d,t[37]=D,t[38]=a,t[39]=l,t[40]=c,t[41]=C,t[42]=p,t[43]=g,t[44]=q):q=t[44];const H=q;_=d?r.jsxs(Si,{open:u,onOpenChange:h,direction:"bottom",children:[r.jsxs("button",{type:"button",onClick:()=>h(!0),className:"flex items-center gap-3 w-full px-3 py-2.5 rounded-lg transition-colors text-sm text-sidebar-foreground/70 hover:bg-sidebar-accent hover:text-sidebar-foreground",children:[r.jsx("div",{className:"shrink-0 size-5 rounded-md flex items-center justify-center border border-border/50 overflow-hidden",style:b?.logo?void 0:ga(b?.name??""),children:b?.logo?r.jsx("img",{src:b.logo,alt:"",className:"size-full object-cover"}):r.jsx("span",{className:"font-semibold leading-none text-[8px]",children:(b?.name??"?").slice(0,2).toUpperCase()})}),r.jsx("span",{className:"truncate",children:b?.name??"Account"})]}),r.jsxs(yi,{className:"h-[80dvh] p-0",children:[r.jsx(bi,{className:"sr-only",children:"Account"}),r.jsx(Xc,{...H})]})]}):r.jsxs(li,{open:u,onOpenChange:h,children:[r.jsx(oi,{asChild:!0,children:r.jsx(us,{tooltip:b?.name??"Account",className:"rounded-md",children:r.jsx("div",{className:"shrink-0 size-6 rounded-md flex items-center justify-center border border-border/50 overflow-hidden",style:b?.logo?void 0:ga(b?.name??""),children:b?.logo?r.jsx("img",{src:b.logo,alt:"",className:"size-full object-cover"}):r.jsx("span",{className:"font-semibold leading-none text-[9px]",children:(b?.name??"?").slice(0,2).toUpperCase()})})})}),r.jsx(ai,{side:"right",align:"end",sideOffset:18,collisionPadding:16,className:"w-[520px] p-0 flex max-h-[520px]",onCloseAutoFocus:S0,children:r.jsx(Xc,{...H})})]}),t[1]=d,t[2]=i,t[3]=u,t[4]=a,t[5]=s,t[6]=l,t[7]=c,t[8]=p,t[9]=g,t[10]=_}else _=t[10];let v;t[45]!==f?(v=r.jsx(m0,{open:f,onOpenChange:m}),t[45]=f,t[46]=v):v=t[46];let x;return t[47]!==_||t[48]!==v?(x=r.jsxs(r.Fragment,{children:[_,v]}),t[47]=_,t[48]=v,t[49]=x):x=t[49],x}function S0(t){return t.preventDefault()}function w0(){se("signed_out",{source:"account_popover"}),St.signOut()}function V0({invitation:t}){const[e,s]=S.useState(!1),[i,n]=S.useState(!1),o=Mt(),a=async()=>{s(!0);try{const c=await St.organization.acceptInvitation({invitationId:t.id});if(c.error)pe.error(c.error.message),s(!1);else{const d=await St.organization.setActive({organizationId:t.organizationId});pe.success("Invitation accepted!");const u=d?.data?.slug;window.location.href=u?`/${u}`:"/"}}catch{pe.error("Failed to accept invitation"),s(!1)}},l=async()=>{n(!0);try{const c=await St.organization.rejectInvitation({invitationId:t.id});c.error?(pe.error(c.error.message),n(!1)):(pe.success("Invitation declined"),o.invalidateQueries())}catch{pe.error("Failed to decline invitation"),n(!1)}};return r.jsxs("div",{className:"flex items-center gap-3 px-5 py-4 border-b border-border last:border-0 hover:bg-muted/25 transition-colors",children:[r.jsxs("div",{className:"flex-1 min-w-0",children:[r.jsx("p",{className:"text-xs text-muted-foreground",children:"You've been invited to join"}),r.jsx("p",{className:"text-sm font-medium truncate",children:t.organizationName??"Unknown organization"})]}),r.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[r.jsx(ne,{size:"icon",variant:"ghost",className:"size-7 text-green-600 hover:text-green-700 hover:bg-green-50 dark:hover:bg-green-950",onClick:a,disabled:e||i,"aria-label":"Accept invitation",children:r.jsx(Jt,{size:14})}),r.jsx(ne,{size:"icon",variant:"ghost",className:"size-7 text-muted-foreground hover:text-destructive hover:bg-destructive/10",onClick:l,disabled:e||i,"aria-label":"Decline invitation",children:r.jsx(ii,{size:14})})]})]})}function C0(){const t=S.useContext(op),{data:e}=t.hooks.useListUserInvitations();return(e??[]).filter(i=>i.status==="pending"&&new Date(i.expiresAt)>new Date)}class j0 extends S.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e,s){}render(){return this.state.hasError?null:this.props.children}}function k0(t){return t<=1?"text-destructive":t<=5?"text-amber-500 dark:text-amber-400":"text-foreground/70"}function N0(){const t=B.c(19),e=Ke(),{org:s}=be();let i;t[0]!==s.id?(i={connectionId:Wt,orgId:s.id},t[0]=s.id,t[1]=i):i=t[1];const n=Me(i);let o;t[2]===Symbol.for("react.memo_cache_sentinel")?(o={providerId:"deco"},t[2]=o):o=t[2];let a;t[3]!==n?(a={client:n,toolName:"AI_PROVIDER_CREDITS",toolArguments:o,staleTime:6e4,select:A0},t[3]=n,t[4]=a):a=t[4];const{data:l,isPending:c,isError:d}=wi(a),u=l?.balanceCents!=null?l.balanceCents/100:null;let h;t[5]!==u||t[6]!==d||t[7]!==c?(h=c||d||u==null?"Credits":`Credits: $${u.toFixed(2)}`,t[5]=u,t[6]=d,t[7]=c,t[8]=h):h=t[8];const f=h;let m;t[9]!==u?(m=X(u!=null&&k0(u)),t[9]=u,t[10]=m):m=t[10];let p;t[11]!==e||t[12]!==s.slug?(p=()=>e({to:"/$org/settings/ai-providers",params:{org:s.slug}}),t[11]=e,t[12]=s.slug,t[13]=p):p=t[13];let g;t[14]===Symbol.for("react.memo_cache_sentinel")?(g=r.jsx(ml,{size:24}),t[14]=g):g=t[14];let _;return t[15]!==m||t[16]!==p||t[17]!==f?(_=r.jsx(gs,{children:r.jsx(Zt,{children:r.jsx(us,{tooltip:f,className:m,onClick:p,children:g})})}),t[15]=m,t[16]=p,t[17]=f,t[18]=_):_=t[18],_}function A0(t){return t.structuredContent}function E0(){const t=B.c(1);if(!bl().some(I0))return null;let i;return t[0]===Symbol.for("react.memo_cache_sentinel")?(i=r.jsx(N0,{}),t[0]=i):i=t[0],i}function I0(t){return t.providerId==="deco"}function R0(){const t=B.c(3),[e,s]=S.useState(!1);let i;t[0]===Symbol.for("react.memo_cache_sentinel")?(i=r.jsx(gs,{children:r.jsx(Zt,{children:r.jsx(us,{tooltip:"Connections",onClick:()=>{se("connections_dialog_opened",{source:"sidebar_footer",mode:"browse"}),s(!0)},children:r.jsx(Tg,{size:24})})})}),t[0]=i):i=t[0];let n;return t[1]!==e?(n=r.jsxs(r.Fragment,{children:[i,r.jsx(Pl,{mode:"browse",open:e,onOpenChange:s,defaultTab:"all"})]}),t[1]=e,t[2]=n):n=t[2],n}function T0(){const t=B.c(11),e=C0();let s;t[0]===Symbol.for("react.memo_cache_sentinel")?(s=r.jsx(mc,{size:24}),t[0]=s):s=t[0];let i;t[1]!==e.length?(i=e.length>0&&r.jsx("span",{className:"absolute top-1 right-1 size-2 rounded-full bg-red-500 pointer-events-none"}),t[1]=e.length,t[2]=i):i=t[2];let n;t[3]!==i?(n=r.jsx(gs,{children:r.jsx(Zt,{children:r.jsx(oi,{asChild:!0,children:r.jsxs(us,{tooltip:"Inbox",className:"relative",children:[s,i]})})})}),t[3]=i,t[4]=n):n=t[4];let o;t[5]===Symbol.for("react.memo_cache_sentinel")?(o=r.jsx("div",{className:"px-4 py-3 border-b border-border shrink-0",children:r.jsx("h3",{className:"text-sm font-medium",children:"Inbox"})}),t[5]=o):o=t[5];let a;t[6]!==e?(a=r.jsxs(ai,{side:"right",align:"start",sideOffset:16,collisionPadding:16,className:"w-[min(400px,calc(100vw-2rem))] p-0 h-[min(650px,calc(100dvh-4rem))] flex flex-col",children:[o,e.length===0?r.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-2 px-6 text-center",children:[r.jsx(mc,{size:24,className:"text-muted-foreground/50"}),r.jsx("p",{className:"text-sm font-medium text-foreground",children:"No invites pending"}),r.jsx("p",{className:"text-xs text-muted-foreground",children:"Organization invitations will appear here"})]}):r.jsx("div",{className:"overflow-y-auto flex-1",children:e.map(D0)})]}),t[6]=e,t[7]=a):a=t[7];let l;return t[8]!==n||t[9]!==a?(l=r.jsxs(li,{children:[n,a]}),t[8]=n,t[9]=a,t[10]=l):l=t[10],l}function D0(t){return r.jsx(V0,{invitation:t},t.id)}function M0(){const t=B.c(6),e=Ke(),{org:s}=be();let i;t[0]!==e||t[1]!==s.slug?(i=()=>e({to:"/$org/settings",params:{org:s.slug}}),t[0]=e,t[1]=s.slug,t[2]=i):i=t[2];let n;t[3]===Symbol.for("react.memo_cache_sentinel")?(n=r.jsx(Gr,{size:24}),t[3]=n):n=t[3];let o;return t[4]!==i?(o=r.jsx(gs,{children:r.jsx(Zt,{children:r.jsx(us,{tooltip:"Settings",onClick:i,children:n})})}),t[4]=i,t[5]=o):o=t[5],o}function P0(){const t=B.c(5);let e,s,i,n;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=r.jsx(j0,{children:r.jsx(S.Suspense,{fallback:null,children:r.jsx(E0,{})})}),s=r.jsx(R0,{}),i=r.jsx(T0,{}),n=r.jsx(M0,{}),t[0]=e,t[1]=s,t[2]=i,t[3]=n):(e=t[0],s=t[1],i=t[2],n=t[3]);let o;return t[4]===Symbol.for("react.memo_cache_sentinel")?(o=r.jsxs(bu,{className:"px-2 pb-3 gap-1",children:[e,s,i,n,r.jsx(gs,{children:r.jsx(Zt,{children:r.jsx(sf,{})})})]}),t[4]=o):o=t[4],o}function L0(){const t=B.c(10),e=Ke(),{org:s}=be(),{setOpenMobile:i}=qr();let n;t[0]!==e||t[1]!==s.slug||t[2]!==i?(n=()=>{e({to:"/$org/settings",params:{org:s.slug}}),i(!1)},t[0]=e,t[1]=s.slug,t[2]=i,t[3]=n):n=t[3];let o;t[4]===Symbol.for("react.memo_cache_sentinel")?(o=r.jsx(Gr,{}),t[4]=o):o=t[4];let a;t[5]!==n?(a=r.jsx(Zt,{children:r.jsx(us,{tooltip:"Settings",onClick:n,children:o})}),t[5]=n,t[6]=a):a=t[6];let l;t[7]===Symbol.for("react.memo_cache_sentinel")?(l=r.jsx(Zt,{children:r.jsx(sf,{})}),t[7]=l):l=t[7];let c;return t[8]!==a?(c=r.jsx(bu,{children:r.jsxs(gs,{children:[a,l]})}),t[8]=a,t[9]=c):c=t[9],c}function B0(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];return S.useMemo(()=>i=>{e.forEach(n=>n(i))},e)}const uo=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function Ki(t){const e=Object.prototype.toString.call(t);return e==="[object Window]"||e==="[object global]"}function Ll(t){return"nodeType"in t}function Ut(t){var e,s;return t?Ki(t)?t:Ll(t)&&(e=(s=t.ownerDocument)==null?void 0:s.defaultView)!=null?e:window:window}function Bl(t){const{Document:e}=Ut(t);return t instanceof e}function Xr(t){return Ki(t)?!1:t instanceof Ut(t).HTMLElement}function rf(t){return t instanceof Ut(t).SVGElement}function qi(t){return t?Ki(t)?t.document:Ll(t)?Bl(t)?t:Xr(t)||rf(t)?t.ownerDocument:document:document:document}const Es=uo?S.useLayoutEffect:S.useEffect;function Ol(t){const e=S.useRef(t);return Es(()=>{e.current=t}),S.useCallback(function(){for(var s=arguments.length,i=new Array(s),n=0;n<s;n++)i[n]=arguments[n];return e.current==null?void 0:e.current(...i)},[])}function O0(){const t=S.useRef(null),e=S.useCallback((i,n)=>{t.current=setInterval(i,n)},[]),s=S.useCallback(()=>{t.current!==null&&(clearInterval(t.current),t.current=null)},[]);return[e,s]}function Er(t,e){e===void 0&&(e=[t]);const s=S.useRef(t);return Es(()=>{s.current!==t&&(s.current=t)},e),s}function Jr(t,e){const s=S.useRef();return S.useMemo(()=>{const i=t(s.current);return s.current=i,i},[...e])}function Hn(t){const e=Ol(t),s=S.useRef(null),i=S.useCallback(n=>{n!==s.current&&e?.(n,s.current),s.current=n},[]);return[s,i]}function _a(t){const e=S.useRef();return S.useEffect(()=>{e.current=t},[t]),e.current}let Ro={};function Qr(t,e){return S.useMemo(()=>{if(e)return e;const s=Ro[t]==null?0:Ro[t]+1;return Ro[t]=s,t+"-"+s},[t,e])}function nf(t){return function(e){for(var s=arguments.length,i=new Array(s>1?s-1:0),n=1;n<s;n++)i[n-1]=arguments[n];return i.reduce((o,a)=>{const l=Object.entries(a);for(const[c,d]of l){const u=o[c];u!=null&&(o[c]=u+t*d)}return o},{...e})}}const Di=nf(1),Ir=nf(-1);function $0(t){return"clientX"in t&&"clientY"in t}function $l(t){if(!t)return!1;const{KeyboardEvent:e}=Ut(t.target);return e&&t instanceof e}function z0(t){if(!t)return!1;const{TouchEvent:e}=Ut(t.target);return e&&t instanceof e}function xa(t){if(z0(t)){if(t.touches&&t.touches.length){const{clientX:e,clientY:s}=t.touches[0];return{x:e,y:s}}else if(t.changedTouches&&t.changedTouches.length){const{clientX:e,clientY:s}=t.changedTouches[0];return{x:e,y:s}}}return $0(t)?{x:t.clientX,y:t.clientY}:null}const Rr=Object.freeze({Translate:{toString(t){if(!t)return;const{x:e,y:s}=t;return"translate3d("+(e?Math.round(e):0)+"px, "+(s?Math.round(s):0)+"px, 0)"}},Scale:{toString(t){if(!t)return;const{scaleX:e,scaleY:s}=t;return"scaleX("+e+") scaleY("+s+")"}},Transform:{toString(t){if(t)return[Rr.Translate.toString(t),Rr.Scale.toString(t)].join(" ")}},Transition:{toString(t){let{property:e,duration:s,easing:i}=t;return e+" "+s+"ms "+i}}}),Jc="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";function F0(t){return t.matches(Jc)?t:t.querySelector(Jc)}const H0={display:"none"};function W0(t){let{id:e,value:s}=t;return Ft.createElement("div",{id:e,style:H0},s)}function U0(t){let{id:e,announcement:s,ariaLiveType:i="assertive"}=t;const n={position:"fixed",top:0,left:0,width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",clipPath:"inset(100%)",whiteSpace:"nowrap"};return Ft.createElement("div",{id:e,style:n,role:"status","aria-live":i,"aria-atomic":!0},s)}function K0(){const[t,e]=S.useState("");return{announce:S.useCallback(i=>{i!=null&&e(i)},[]),announcement:t}}const of=S.createContext(null);function q0(t){const e=S.useContext(of);S.useEffect(()=>{if(!e)throw new Error("useDndMonitor must be used within a children of <DndContext>");return e(t)},[t,e])}function G0(){const[t]=S.useState(()=>new Set),e=S.useCallback(i=>(t.add(i),()=>t.delete(i)),[t]);return[S.useCallback(i=>{let{type:n,event:o}=i;t.forEach(a=>{var l;return(l=a[n])==null?void 0:l.call(a,o)})},[t]),e]}const Y0={draggable:`
260
260
  To pick up a draggable item, press the space bar.
261
261
  While dragging, use the arrow keys to move the item.
262
262
  Press space again to drop the item in its new position, or press escape to cancel.
263
- `},q0={onDragStart(t){let{active:e}=t;return"Picked up draggable item "+e.id+"."},onDragOver(t){let{active:e,over:s}=t;return s?"Draggable item "+e.id+" was moved over droppable area "+s.id+".":"Draggable item "+e.id+" is no longer over a droppable area."},onDragEnd(t){let{active:e,over:s}=t;return s?"Draggable item "+e.id+" was dropped over droppable area "+s.id:"Draggable item "+e.id+" was dropped."},onDragCancel(t){let{active:e}=t;return"Dragging was cancelled. Draggable item "+e.id+" was dropped."}};function G0(t){let{announcements:e=q0,container:s,hiddenTextDescribedById:i,screenReaderInstructions:n=K0}=t;const{announce:o,announcement:a}=H0(),l=Qr("DndLiveRegion"),[c,d]=S.useState(!1);if(S.useEffect(()=>{d(!0)},[]),W0(S.useMemo(()=>({onDragStart(h){let{active:f}=h;o(e.onDragStart({active:f}))},onDragMove(h){let{active:f,over:m}=h;e.onDragMove&&o(e.onDragMove({active:f,over:m}))},onDragOver(h){let{active:f,over:m}=h;o(e.onDragOver({active:f,over:m}))},onDragEnd(h){let{active:f,over:m}=h;o(e.onDragEnd({active:f,over:m}))},onDragCancel(h){let{active:f,over:m}=h;o(e.onDragCancel({active:f,over:m}))}}),[o,e])),!c)return null;const u=Ft.createElement(Ft.Fragment,null,Ft.createElement(z0,{id:i,value:n.draggable}),Ft.createElement(F0,{id:l,announcement:a}));return s?ds.createPortal(u,s):u}var at;(function(t){t.DragStart="dragStart",t.DragMove="dragMove",t.DragEnd="dragEnd",t.DragCancel="dragCancel",t.DragOver="dragOver",t.RegisterDroppable="registerDroppable",t.SetDroppableDisabled="setDroppableDisabled",t.UnregisterDroppable="unregisterDroppable"})(at||(at={}));function Wn(){}function Qc(t,e){return S.useMemo(()=>({sensor:t,options:e??{}}),[t,e])}function Y0(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];return S.useMemo(()=>[...e].filter(i=>i!=null),[...e])}const fs=Object.freeze({x:0,y:0});function of(t,e){return Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2))}function af(t,e){let{data:{value:s}}=t,{data:{value:i}}=e;return s-i}function X0(t,e){let{data:{value:s}}=t,{data:{value:i}}=e;return i-s}function Zc(t){let{left:e,top:s,height:i,width:n}=t;return[{x:e,y:s},{x:e+n,y:s},{x:e,y:s+i},{x:e+n,y:s+i}]}function lf(t,e){if(!t||t.length===0)return null;const[s]=t;return s[e]}function ed(t,e,s){return e===void 0&&(e=t.left),s===void 0&&(s=t.top),{x:e+t.width*.5,y:s+t.height*.5}}const J0=t=>{let{collisionRect:e,droppableRects:s,droppableContainers:i}=t;const n=ed(e,e.left,e.top),o=[];for(const a of i){const{id:l}=a,c=s.get(l);if(c){const d=of(ed(c),n);o.push({id:l,data:{droppableContainer:a,value:d}})}}return o.sort(af)},Q0=t=>{let{collisionRect:e,droppableRects:s,droppableContainers:i}=t;const n=Zc(e),o=[];for(const a of i){const{id:l}=a,c=s.get(l);if(c){const d=Zc(c),u=n.reduce((f,m,p)=>f+of(d[p],m),0),h=Number((u/4).toFixed(4));o.push({id:l,data:{droppableContainer:a,value:h}})}}return o.sort(af)};function Z0(t,e){const s=Math.max(e.top,t.top),i=Math.max(e.left,t.left),n=Math.min(e.left+e.width,t.left+t.width),o=Math.min(e.top+e.height,t.top+t.height),a=n-i,l=o-s;if(i<n&&s<o){const c=e.width*e.height,d=t.width*t.height,u=a*l,h=u/(c+d-u);return Number(h.toFixed(4))}return 0}const ey=t=>{let{collisionRect:e,droppableRects:s,droppableContainers:i}=t;const n=[];for(const o of i){const{id:a}=o,l=s.get(a);if(l){const c=Z0(l,e);c>0&&n.push({id:a,data:{droppableContainer:o,value:c}})}}return n.sort(X0)};function ty(t,e,s){return{...t,scaleX:e&&s?e.width/s.width:1,scaleY:e&&s?e.height/s.height:1}}function cf(t,e){return t&&e?{x:t.left-e.left,y:t.top-e.top}:fs}function sy(t){return function(s){for(var i=arguments.length,n=new Array(i>1?i-1:0),o=1;o<i;o++)n[o-1]=arguments[o];return n.reduce((a,l)=>({...a,top:a.top+t*l.y,bottom:a.bottom+t*l.y,left:a.left+t*l.x,right:a.right+t*l.x}),{...s})}}const iy=sy(1);function ry(t){if(t.startsWith("matrix3d(")){const e=t.slice(9,-1).split(/, /);return{x:+e[12],y:+e[13],scaleX:+e[0],scaleY:+e[5]}}else if(t.startsWith("matrix(")){const e=t.slice(7,-1).split(/, /);return{x:+e[4],y:+e[5],scaleX:+e[0],scaleY:+e[3]}}return null}function ny(t,e,s){const i=ry(e);if(!i)return t;const{scaleX:n,scaleY:o,x:a,y:l}=i,c=t.left-a-(1-n)*parseFloat(s),d=t.top-l-(1-o)*parseFloat(s.slice(s.indexOf(" ")+1)),u=n?t.width/n:t.width,h=o?t.height/o:t.height;return{width:u,height:h,top:d,right:c+u,bottom:d+h,left:c}}const oy={ignoreTransform:!1};function Gi(t,e){e===void 0&&(e=oy);let s=t.getBoundingClientRect();if(e.ignoreTransform){const{transform:d,transformOrigin:u}=Ut(t).getComputedStyle(t);d&&(s=ny(s,d,u))}const{top:i,left:n,width:o,height:a,bottom:l,right:c}=s;return{top:i,left:n,width:o,height:a,bottom:l,right:c}}function td(t){return Gi(t,{ignoreTransform:!0})}function ay(t){const e=t.innerWidth,s=t.innerHeight;return{top:0,left:0,right:e,bottom:s,width:e,height:s}}function ly(t,e){return e===void 0&&(e=Ut(t).getComputedStyle(t)),e.position==="fixed"}function cy(t,e){e===void 0&&(e=Ut(t).getComputedStyle(t));const s=/(auto|scroll|overlay)/;return["overflow","overflowX","overflowY"].some(n=>{const o=e[n];return typeof o=="string"?s.test(o):!1})}function fo(t,e){const s=[];function i(n){if(e!=null&&s.length>=e||!n)return s;if(Bl(n)&&n.scrollingElement!=null&&!s.includes(n.scrollingElement))return s.push(n.scrollingElement),s;if(!Xr(n)||sf(n)||s.includes(n))return s;const o=Ut(t).getComputedStyle(n);return n!==t&&cy(n,o)&&s.push(n),ly(n,o)?s:i(n.parentNode)}return t?i(t):s}function df(t){const[e]=fo(t,1);return e??null}function To(t){return!uo||!t?null:Ki(t)?t:Ll(t)?Bl(t)||t===qi(t).scrollingElement?window:Xr(t)?t:null:null}function hf(t){return Ki(t)?t.scrollX:t.scrollLeft}function uf(t){return Ki(t)?t.scrollY:t.scrollTop}function va(t){return{x:hf(t),y:uf(t)}}var ut;(function(t){t[t.Forward=1]="Forward",t[t.Backward=-1]="Backward"})(ut||(ut={}));function ff(t){return!uo||!t?!1:t===document.scrollingElement}function mf(t){const e={x:0,y:0},s=ff(t)?{height:window.innerHeight,width:window.innerWidth}:{height:t.clientHeight,width:t.clientWidth},i={x:t.scrollWidth-s.width,y:t.scrollHeight-s.height},n=t.scrollTop<=e.y,o=t.scrollLeft<=e.x,a=t.scrollTop>=i.y,l=t.scrollLeft>=i.x;return{isTop:n,isLeft:o,isBottom:a,isRight:l,maxScroll:i,minScroll:e}}const dy={x:.2,y:.2};function hy(t,e,s,i,n){let{top:o,left:a,right:l,bottom:c}=s;i===void 0&&(i=10),n===void 0&&(n=dy);const{isTop:d,isBottom:u,isLeft:h,isRight:f}=mf(t),m={x:0,y:0},p={x:0,y:0},g={height:e.height*n.y,width:e.width*n.x};return!d&&o<=e.top+g.height?(m.y=ut.Backward,p.y=i*Math.abs((e.top+g.height-o)/g.height)):!u&&c>=e.bottom-g.height&&(m.y=ut.Forward,p.y=i*Math.abs((e.bottom-g.height-c)/g.height)),!f&&l>=e.right-g.width?(m.x=ut.Forward,p.x=i*Math.abs((e.right-g.width-l)/g.width)):!h&&a<=e.left+g.width&&(m.x=ut.Backward,p.x=i*Math.abs((e.left+g.width-a)/g.width)),{direction:m,speed:p}}function uy(t){if(t===document.scrollingElement){const{innerWidth:o,innerHeight:a}=window;return{top:0,left:0,right:o,bottom:a,width:o,height:a}}const{top:e,left:s,right:i,bottom:n}=t.getBoundingClientRect();return{top:e,left:s,right:i,bottom:n,width:t.clientWidth,height:t.clientHeight}}function pf(t){return t.reduce((e,s)=>Di(e,va(s)),fs)}function fy(t){return t.reduce((e,s)=>e+hf(s),0)}function my(t){return t.reduce((e,s)=>e+uf(s),0)}function py(t,e){if(e===void 0&&(e=Gi),!t)return;const{top:s,left:i,bottom:n,right:o}=e(t);df(t)&&(n<=0||o<=0||s>=window.innerHeight||i>=window.innerWidth)&&t.scrollIntoView({block:"center",inline:"center"})}const gy=[["x",["left","right"],fy],["y",["top","bottom"],my]];class zl{constructor(e,s){this.rect=void 0,this.width=void 0,this.height=void 0,this.top=void 0,this.bottom=void 0,this.right=void 0,this.left=void 0;const i=fo(s),n=pf(i);this.rect={...e},this.width=e.width,this.height=e.height;for(const[o,a,l]of gy)for(const c of a)Object.defineProperty(this,c,{get:()=>{const d=l(i),u=n[o]-d;return this.rect[c]+u},enumerable:!0});Object.defineProperty(this,"rect",{enumerable:!1})}}class br{constructor(e){this.target=void 0,this.listeners=[],this.removeAll=()=>{this.listeners.forEach(s=>{var i;return(i=this.target)==null?void 0:i.removeEventListener(...s)})},this.target=e}add(e,s,i){var n;(n=this.target)==null||n.addEventListener(e,s,i),this.listeners.push([e,s,i])}}function _y(t){const{EventTarget:e}=Ut(t);return t instanceof e?t:qi(t)}function Do(t,e){const s=Math.abs(t.x),i=Math.abs(t.y);return typeof e=="number"?Math.sqrt(s**2+i**2)>e:"x"in e&&"y"in e?s>e.x&&i>e.y:"x"in e?s>e.x:"y"in e?i>e.y:!1}var ns;(function(t){t.Click="click",t.DragStart="dragstart",t.Keydown="keydown",t.ContextMenu="contextmenu",t.Resize="resize",t.SelectionChange="selectionchange",t.VisibilityChange="visibilitychange"})(ns||(ns={}));function sd(t){t.preventDefault()}function xy(t){t.stopPropagation()}var je;(function(t){t.Space="Space",t.Down="ArrowDown",t.Right="ArrowRight",t.Left="ArrowLeft",t.Up="ArrowUp",t.Esc="Escape",t.Enter="Enter",t.Tab="Tab"})(je||(je={}));const gf={start:[je.Space,je.Enter],cancel:[je.Esc],end:[je.Space,je.Enter,je.Tab]},vy=(t,e)=>{let{currentCoordinates:s}=e;switch(t.code){case je.Right:return{...s,x:s.x+25};case je.Left:return{...s,x:s.x-25};case je.Down:return{...s,y:s.y+25};case je.Up:return{...s,y:s.y-25}}};class Fl{constructor(e){this.props=void 0,this.autoScrollEnabled=!1,this.referenceCoordinates=void 0,this.listeners=void 0,this.windowListeners=void 0,this.props=e;const{event:{target:s}}=e;this.props=e,this.listeners=new br(qi(s)),this.windowListeners=new br(Ut(s)),this.handleKeyDown=this.handleKeyDown.bind(this),this.handleCancel=this.handleCancel.bind(this),this.attach()}attach(){this.handleStart(),this.windowListeners.add(ns.Resize,this.handleCancel),this.windowListeners.add(ns.VisibilityChange,this.handleCancel),setTimeout(()=>this.listeners.add(ns.Keydown,this.handleKeyDown))}handleStart(){const{activeNode:e,onStart:s}=this.props,i=e.node.current;i&&py(i),s(fs)}handleKeyDown(e){if($l(e)){const{active:s,context:i,options:n}=this.props,{keyboardCodes:o=gf,coordinateGetter:a=vy,scrollBehavior:l="smooth"}=n,{code:c}=e;if(o.end.includes(c)){this.handleEnd(e);return}if(o.cancel.includes(c)){this.handleCancel(e);return}const{collisionRect:d}=i.current,u=d?{x:d.left,y:d.top}:fs;this.referenceCoordinates||(this.referenceCoordinates=u);const h=a(e,{active:s,context:i.current,currentCoordinates:u});if(h){const f=Ir(h,u),m={x:0,y:0},{scrollableAncestors:p}=i.current;for(const g of p){const _=e.code,{isTop:v,isRight:x,isLeft:b,isBottom:y,maxScroll:C,minScroll:j}=mf(g),V=uy(g),w={x:Math.min(_===je.Right?V.right-V.width/2:V.right,Math.max(_===je.Right?V.left:V.left+V.width/2,h.x)),y:Math.min(_===je.Down?V.bottom-V.height/2:V.bottom,Math.max(_===je.Down?V.top:V.top+V.height/2,h.y))},k=_===je.Right&&!x||_===je.Left&&!b,T=_===je.Down&&!y||_===je.Up&&!v;if(k&&w.x!==h.x){const I=g.scrollLeft+f.x,A=_===je.Right&&I<=C.x||_===je.Left&&I>=j.x;if(A&&!f.y){g.scrollTo({left:I,behavior:l});return}A?m.x=g.scrollLeft-I:m.x=_===je.Right?g.scrollLeft-C.x:g.scrollLeft-j.x,m.x&&g.scrollBy({left:-m.x,behavior:l});break}else if(T&&w.y!==h.y){const I=g.scrollTop+f.y,A=_===je.Down&&I<=C.y||_===je.Up&&I>=j.y;if(A&&!f.x){g.scrollTo({top:I,behavior:l});return}A?m.y=g.scrollTop-I:m.y=_===je.Down?g.scrollTop-C.y:g.scrollTop-j.y,m.y&&g.scrollBy({top:-m.y,behavior:l});break}}this.handleMove(e,Di(Ir(h,this.referenceCoordinates),m))}}}handleMove(e,s){const{onMove:i}=this.props;e.preventDefault(),i(s)}handleEnd(e){const{onEnd:s}=this.props;e.preventDefault(),this.detach(),s()}handleCancel(e){const{onCancel:s}=this.props;e.preventDefault(),this.detach(),s()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll()}}Fl.activators=[{eventName:"onKeyDown",handler:(t,e,s)=>{let{keyboardCodes:i=gf,onActivation:n}=e,{active:o}=s;const{code:a}=t.nativeEvent;if(i.start.includes(a)){const l=o.activatorNode.current;return l&&t.target!==l?!1:(t.preventDefault(),n?.({event:t.nativeEvent}),!0)}return!1}}];function id(t){return!!(t&&"distance"in t)}function rd(t){return!!(t&&"delay"in t)}class Hl{constructor(e,s,i){var n;i===void 0&&(i=_y(e.event.target)),this.props=void 0,this.events=void 0,this.autoScrollEnabled=!0,this.document=void 0,this.activated=!1,this.initialCoordinates=void 0,this.timeoutId=null,this.listeners=void 0,this.documentListeners=void 0,this.windowListeners=void 0,this.props=e,this.events=s;const{event:o}=e,{target:a}=o;this.props=e,this.events=s,this.document=qi(a),this.documentListeners=new br(this.document),this.listeners=new br(i),this.windowListeners=new br(Ut(a)),this.initialCoordinates=(n=xa(o))!=null?n:fs,this.handleStart=this.handleStart.bind(this),this.handleMove=this.handleMove.bind(this),this.handleEnd=this.handleEnd.bind(this),this.handleCancel=this.handleCancel.bind(this),this.handleKeydown=this.handleKeydown.bind(this),this.removeTextSelection=this.removeTextSelection.bind(this),this.attach()}attach(){const{events:e,props:{options:{activationConstraint:s,bypassActivationConstraint:i}}}=this;if(this.listeners.add(e.move.name,this.handleMove,{passive:!1}),this.listeners.add(e.end.name,this.handleEnd),e.cancel&&this.listeners.add(e.cancel.name,this.handleCancel),this.windowListeners.add(ns.Resize,this.handleCancel),this.windowListeners.add(ns.DragStart,sd),this.windowListeners.add(ns.VisibilityChange,this.handleCancel),this.windowListeners.add(ns.ContextMenu,sd),this.documentListeners.add(ns.Keydown,this.handleKeydown),s){if(i!=null&&i({event:this.props.event,activeNode:this.props.activeNode,options:this.props.options}))return this.handleStart();if(rd(s)){this.timeoutId=setTimeout(this.handleStart,s.delay),this.handlePending(s);return}if(id(s)){this.handlePending(s);return}}this.handleStart()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll(),setTimeout(this.documentListeners.removeAll,50),this.timeoutId!==null&&(clearTimeout(this.timeoutId),this.timeoutId=null)}handlePending(e,s){const{active:i,onPending:n}=this.props;n(i,e,this.initialCoordinates,s)}handleStart(){const{initialCoordinates:e}=this,{onStart:s}=this.props;e&&(this.activated=!0,this.documentListeners.add(ns.Click,xy,{capture:!0}),this.removeTextSelection(),this.documentListeners.add(ns.SelectionChange,this.removeTextSelection),s(e))}handleMove(e){var s;const{activated:i,initialCoordinates:n,props:o}=this,{onMove:a,options:{activationConstraint:l}}=o;if(!n)return;const c=(s=xa(e))!=null?s:fs,d=Ir(n,c);if(!i&&l){if(id(l)){if(l.tolerance!=null&&Do(d,l.tolerance))return this.handleCancel();if(Do(d,l.distance))return this.handleStart()}if(rd(l)&&Do(d,l.tolerance))return this.handleCancel();this.handlePending(l,d);return}e.cancelable&&e.preventDefault(),a(c)}handleEnd(){const{onAbort:e,onEnd:s}=this.props;this.detach(),this.activated||e(this.props.active),s()}handleCancel(){const{onAbort:e,onCancel:s}=this.props;this.detach(),this.activated||e(this.props.active),s()}handleKeydown(e){e.code===je.Esc&&this.handleCancel()}removeTextSelection(){var e;(e=this.document.getSelection())==null||e.removeAllRanges()}}const by={cancel:{name:"pointercancel"},move:{name:"pointermove"},end:{name:"pointerup"}};class Wl extends Hl{constructor(e){const{event:s}=e,i=qi(s.target);super(e,by,i)}}Wl.activators=[{eventName:"onPointerDown",handler:(t,e)=>{let{nativeEvent:s}=t,{onActivation:i}=e;return!s.isPrimary||s.button!==0?!1:(i?.({event:s}),!0)}}];const yy={move:{name:"mousemove"},end:{name:"mouseup"}};var ba;(function(t){t[t.RightClick=2]="RightClick"})(ba||(ba={}));class Sy extends Hl{constructor(e){super(e,yy,qi(e.event.target))}}Sy.activators=[{eventName:"onMouseDown",handler:(t,e)=>{let{nativeEvent:s}=t,{onActivation:i}=e;return s.button===ba.RightClick?!1:(i?.({event:s}),!0)}}];const Mo={cancel:{name:"touchcancel"},move:{name:"touchmove"},end:{name:"touchend"}};class wy extends Hl{constructor(e){super(e,Mo)}static setup(){return window.addEventListener(Mo.move.name,e,{capture:!1,passive:!1}),function(){window.removeEventListener(Mo.move.name,e)};function e(){}}}wy.activators=[{eventName:"onTouchStart",handler:(t,e)=>{let{nativeEvent:s}=t,{onActivation:i}=e;const{touches:n}=s;return n.length>1?!1:(i?.({event:s}),!0)}}];var yr;(function(t){t[t.Pointer=0]="Pointer",t[t.DraggableRect=1]="DraggableRect"})(yr||(yr={}));var Un;(function(t){t[t.TreeOrder=0]="TreeOrder",t[t.ReversedTreeOrder=1]="ReversedTreeOrder"})(Un||(Un={}));function Vy(t){let{acceleration:e,activator:s=yr.Pointer,canScroll:i,draggingRect:n,enabled:o,interval:a=5,order:l=Un.TreeOrder,pointerCoordinates:c,scrollableAncestors:d,scrollableAncestorRects:u,delta:h,threshold:f}=t;const m=jy({delta:h,disabled:!o}),[p,g]=P0(),_=S.useRef({x:0,y:0}),v=S.useRef({x:0,y:0}),x=S.useMemo(()=>{switch(s){case yr.Pointer:return c?{top:c.y,bottom:c.y,left:c.x,right:c.x}:null;case yr.DraggableRect:return n}},[s,n,c]),b=S.useRef(null),y=S.useCallback(()=>{const j=b.current;if(!j)return;const V=_.current.x*v.current.x,w=_.current.y*v.current.y;j.scrollBy(V,w)},[]),C=S.useMemo(()=>l===Un.TreeOrder?[...d].reverse():d,[l,d]);S.useEffect(()=>{if(!o||!d.length||!x){g();return}for(const j of C){if(i?.(j)===!1)continue;const V=d.indexOf(j),w=u[V];if(!w)continue;const{direction:k,speed:T}=hy(j,w,x,e,f);for(const I of["x","y"])m[I][k[I]]||(T[I]=0,k[I]=0);if(T.x>0||T.y>0){g(),b.current=j,p(y,a),_.current=T,v.current=k;return}}_.current={x:0,y:0},v.current={x:0,y:0},g()},[e,y,i,g,o,a,JSON.stringify(x),JSON.stringify(m),p,d,C,u,JSON.stringify(f)])}const Cy={x:{[ut.Backward]:!1,[ut.Forward]:!1},y:{[ut.Backward]:!1,[ut.Forward]:!1}};function jy(t){let{delta:e,disabled:s}=t;const i=_a(e);return Jr(n=>{if(s||!i||!n)return Cy;const o={x:Math.sign(e.x-i.x),y:Math.sign(e.y-i.y)};return{x:{[ut.Backward]:n.x[ut.Backward]||o.x===-1,[ut.Forward]:n.x[ut.Forward]||o.x===1},y:{[ut.Backward]:n.y[ut.Backward]||o.y===-1,[ut.Forward]:n.y[ut.Forward]||o.y===1}}},[s,e,i])}function ky(t,e){const s=e!=null?t.get(e):void 0,i=s?s.node.current:null;return Jr(n=>{var o;return e==null?null:(o=i??n)!=null?o:null},[i,e])}function Ny(t,e){return S.useMemo(()=>t.reduce((s,i)=>{const{sensor:n}=i,o=n.activators.map(a=>({eventName:a.eventName,handler:e(a.handler,i)}));return[...s,...o]},[]),[t,e])}var Tr;(function(t){t[t.Always=0]="Always",t[t.BeforeDragging=1]="BeforeDragging",t[t.WhileDragging=2]="WhileDragging"})(Tr||(Tr={}));var ya;(function(t){t.Optimized="optimized"})(ya||(ya={}));const nd=new Map;function Ay(t,e){let{dragging:s,dependencies:i,config:n}=e;const[o,a]=S.useState(null),{frequency:l,measure:c,strategy:d}=n,u=S.useRef(t),h=_(),f=Er(h),m=S.useCallback(function(v){v===void 0&&(v=[]),!f.current&&a(x=>x===null?v:x.concat(v.filter(b=>!x.includes(b))))},[f]),p=S.useRef(null),g=Jr(v=>{if(h&&!s)return nd;if(!v||v===nd||u.current!==t||o!=null){const x=new Map;for(let b of t){if(!b)continue;if(o&&o.length>0&&!o.includes(b.id)&&b.rect.current){x.set(b.id,b.rect.current);continue}const y=b.node.current,C=y?new zl(c(y),y):null;b.rect.current=C,C&&x.set(b.id,C)}return x}return v},[t,o,s,h,c]);return S.useEffect(()=>{u.current=t},[t]),S.useEffect(()=>{h||m()},[s,h]),S.useEffect(()=>{o&&o.length>0&&a(null)},[JSON.stringify(o)]),S.useEffect(()=>{h||typeof l!="number"||p.current!==null||(p.current=setTimeout(()=>{m(),p.current=null},l))},[l,h,m,...i]),{droppableRects:g,measureDroppableContainers:m,measuringScheduled:o!=null};function _(){switch(d){case Tr.Always:return!1;case Tr.BeforeDragging:return s;default:return!s}}}function _f(t,e){return Jr(s=>t?s||(typeof e=="function"?e(t):t):null,[e,t])}function Ey(t,e){return _f(t,e)}function Iy(t){let{callback:e,disabled:s}=t;const i=Ol(e),n=S.useMemo(()=>{if(s||typeof window>"u"||typeof window.MutationObserver>"u")return;const{MutationObserver:o}=window;return new o(i)},[i,s]);return S.useEffect(()=>()=>n?.disconnect(),[n]),n}function mo(t){let{callback:e,disabled:s}=t;const i=Ol(e),n=S.useMemo(()=>{if(s||typeof window>"u"||typeof window.ResizeObserver>"u")return;const{ResizeObserver:o}=window;return new o(i)},[s]);return S.useEffect(()=>()=>n?.disconnect(),[n]),n}function Ry(t){return new zl(Gi(t),t)}function od(t,e,s){e===void 0&&(e=Ry);const[i,n]=S.useState(null);function o(){n(c=>{if(!t)return null;if(t.isConnected===!1){var d;return(d=c??s)!=null?d:null}const u=e(t);return JSON.stringify(c)===JSON.stringify(u)?c:u})}const a=Iy({callback(c){if(t)for(const d of c){const{type:u,target:h}=d;if(u==="childList"&&h instanceof HTMLElement&&h.contains(t)){o();break}}}}),l=mo({callback:o});return Es(()=>{o(),t?(l?.observe(t),a?.observe(document.body,{childList:!0,subtree:!0})):(l?.disconnect(),a?.disconnect())},[t]),i}function Ty(t){const e=_f(t);return cf(t,e)}const ad=[];function Dy(t){const e=S.useRef(t),s=Jr(i=>t?i&&i!==ad&&t&&e.current&&t.parentNode===e.current.parentNode?i:fo(t):ad,[t]);return S.useEffect(()=>{e.current=t},[t]),s}function My(t){const[e,s]=S.useState(null),i=S.useRef(t),n=S.useCallback(o=>{const a=To(o.target);a&&s(l=>l?(l.set(a,va(a)),new Map(l)):null)},[]);return S.useEffect(()=>{const o=i.current;if(t!==o){a(o);const l=t.map(c=>{const d=To(c);return d?(d.addEventListener("scroll",n,{passive:!0}),[d,va(d)]):null}).filter(c=>c!=null);s(l.length?new Map(l):null),i.current=t}return()=>{a(t),a(o)};function a(l){l.forEach(c=>{const d=To(c);d?.removeEventListener("scroll",n)})}},[n,t]),S.useMemo(()=>t.length?e?Array.from(e.values()).reduce((o,a)=>Di(o,a),fs):pf(t):fs,[t,e])}function ld(t,e){e===void 0&&(e=[]);const s=S.useRef(null);return S.useEffect(()=>{s.current=null},e),S.useEffect(()=>{const i=t!==fs;i&&!s.current&&(s.current=t),!i&&s.current&&(s.current=null)},[t]),s.current?Ir(t,s.current):fs}function Py(t){S.useEffect(()=>{if(!uo)return;const e=t.map(s=>{let{sensor:i}=s;return i.setup==null?void 0:i.setup()});return()=>{for(const s of e)s?.()}},t.map(e=>{let{sensor:s}=e;return s}))}function Ly(t,e){return S.useMemo(()=>t.reduce((s,i)=>{let{eventName:n,handler:o}=i;return s[n]=a=>{o(a,e)},s},{}),[t,e])}function xf(t){return S.useMemo(()=>t?ay(t):null,[t])}const cd=[];function By(t,e){e===void 0&&(e=Gi);const[s]=t,i=xf(s?Ut(s):null),[n,o]=S.useState(cd);function a(){o(()=>t.length?t.map(c=>ff(c)?i:new zl(e(c),c)):cd)}const l=mo({callback:a});return Es(()=>{l?.disconnect(),a(),t.forEach(c=>l?.observe(c))},[t]),n}function Oy(t){if(!t)return null;if(t.children.length>1)return t;const e=t.children[0];return Xr(e)?e:t}function $y(t){let{measure:e}=t;const[s,i]=S.useState(null),n=S.useCallback(d=>{for(const{target:u}of d)if(Xr(u)){i(h=>{const f=e(u);return h?{...h,width:f.width,height:f.height}:f});break}},[e]),o=mo({callback:n}),a=S.useCallback(d=>{const u=Oy(d);o?.disconnect(),u&&o?.observe(u),i(u?e(u):null)},[e,o]),[l,c]=Hn(a);return S.useMemo(()=>({nodeRef:l,rect:s,setRef:c}),[s,l,c])}const zy=[{sensor:Wl,options:{}},{sensor:Fl,options:{}}],Fy={current:{}},kn={draggable:{measure:td},droppable:{measure:td,strategy:Tr.WhileDragging,frequency:ya.Optimized},dragOverlay:{measure:Gi}};class Sr extends Map{get(e){var s;return e!=null&&(s=super.get(e))!=null?s:void 0}toArray(){return Array.from(this.values())}getEnabled(){return this.toArray().filter(e=>{let{disabled:s}=e;return!s})}getNodeFor(e){var s,i;return(s=(i=this.get(e))==null?void 0:i.node.current)!=null?s:void 0}}const Hy={activatorEvent:null,active:null,activeNode:null,activeNodeRect:null,collisions:null,containerNodeRect:null,draggableNodes:new Map,droppableRects:new Map,droppableContainers:new Sr,over:null,dragOverlay:{nodeRef:{current:null},rect:null,setRef:Wn},scrollableAncestors:[],scrollableAncestorRects:[],measuringConfiguration:kn,measureDroppableContainers:Wn,windowRect:null,measuringScheduled:!1},Wy={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:""},dispatch:Wn,draggableNodes:new Map,over:null,measureDroppableContainers:Wn},po=S.createContext(Wy),vf=S.createContext(Hy);function Uy(){return{draggable:{active:null,initialCoordinates:{x:0,y:0},nodes:new Map,translate:{x:0,y:0}},droppable:{containers:new Sr}}}function Ky(t,e){switch(e.type){case at.DragStart:return{...t,draggable:{...t.draggable,initialCoordinates:e.initialCoordinates,active:e.active}};case at.DragMove:return t.draggable.active==null?t:{...t,draggable:{...t.draggable,translate:{x:e.coordinates.x-t.draggable.initialCoordinates.x,y:e.coordinates.y-t.draggable.initialCoordinates.y}}};case at.DragEnd:case at.DragCancel:return{...t,draggable:{...t.draggable,active:null,initialCoordinates:{x:0,y:0},translate:{x:0,y:0}}};case at.RegisterDroppable:{const{element:s}=e,{id:i}=s,n=new Sr(t.droppable.containers);return n.set(i,s),{...t,droppable:{...t.droppable,containers:n}}}case at.SetDroppableDisabled:{const{id:s,key:i,disabled:n}=e,o=t.droppable.containers.get(s);if(!o||i!==o.key)return t;const a=new Sr(t.droppable.containers);return a.set(s,{...o,disabled:n}),{...t,droppable:{...t.droppable,containers:a}}}case at.UnregisterDroppable:{const{id:s,key:i}=e,n=t.droppable.containers.get(s);if(!n||i!==n.key)return t;const o=new Sr(t.droppable.containers);return o.delete(s),{...t,droppable:{...t.droppable,containers:o}}}default:return t}}function qy(t){let{disabled:e}=t;const{active:s,activatorEvent:i,draggableNodes:n}=S.useContext(po),o=_a(i),a=_a(s?.id);return S.useEffect(()=>{if(!e&&!i&&o&&a!=null){if(!$l(o)||document.activeElement===o.target)return;const l=n.get(a);if(!l)return;const{activatorNode:c,node:d}=l;if(!c.current&&!d.current)return;requestAnimationFrame(()=>{for(const u of[c.current,d.current]){if(!u)continue;const h=O0(u);if(h){h.focus();break}}})}},[i,e,n,a,o]),null}function Gy(t,e){let{transform:s,...i}=e;return t!=null&&t.length?t.reduce((n,o)=>o({transform:n,...i}),s):s}function Yy(t){return S.useMemo(()=>({draggable:{...kn.draggable,...t?.draggable},droppable:{...kn.droppable,...t?.droppable},dragOverlay:{...kn.dragOverlay,...t?.dragOverlay}}),[t?.draggable,t?.droppable,t?.dragOverlay])}function Xy(t){let{activeNode:e,measure:s,initialRect:i,config:n=!0}=t;const o=S.useRef(!1),{x:a,y:l}=typeof n=="boolean"?{x:n,y:n}:n;Es(()=>{if(!a&&!l||!e){o.current=!1;return}if(o.current||!i)return;const d=e?.node.current;if(!d||d.isConnected===!1)return;const u=s(d),h=cf(u,i);if(a||(h.x=0),l||(h.y=0),o.current=!0,Math.abs(h.x)>0||Math.abs(h.y)>0){const f=df(d);f&&f.scrollBy({top:h.y,left:h.x})}},[e,a,l,i,s])}const bf=S.createContext({...fs,scaleX:1,scaleY:1});var Gs;(function(t){t[t.Uninitialized=0]="Uninitialized",t[t.Initializing=1]="Initializing",t[t.Initialized=2]="Initialized"})(Gs||(Gs={}));const Jy=S.memo(function(e){var s,i,n,o;let{id:a,accessibility:l,autoScroll:c=!0,children:d,sensors:u=zy,collisionDetection:h=ey,measuring:f,modifiers:m,...p}=e;const g=S.useReducer(Ky,void 0,Uy),[_,v]=g,[x,b]=U0(),[y,C]=S.useState(Gs.Uninitialized),j=y===Gs.Initialized,{draggable:{active:V,nodes:w,translate:k},droppable:{containers:T}}=_,I=V!=null?w.get(V):null,A=S.useRef({initial:null,translated:null}),N=S.useMemo(()=>{var Ae;return V!=null?{id:V,data:(Ae=I?.data)!=null?Ae:Fy,rect:A}:null},[V,I]),E=S.useRef(null),[R,M]=S.useState(null),[L,D]=S.useState(null),P=Er(p,Object.values(p)),O=Qr("DndDescribedBy",a),z=S.useMemo(()=>T.getEnabled(),[T]),$=Yy(f),{droppableRects:W,measureDroppableContainers:F,measuringScheduled:G}=Ay(z,{dragging:j,dependencies:[k.x,k.y],config:$.droppable}),q=ky(w,V),H=S.useMemo(()=>L?xa(L):null,[L]),ee=jt(),K=Ey(q,$.draggable.measure);Xy({activeNode:V!=null?w.get(V):null,config:ee.layoutShiftCompensation,initialRect:K,measure:$.draggable.measure});const U=od(q,$.draggable.measure,K),te=od(q?q.parentElement:null),Y=S.useRef({activatorEvent:null,active:null,activeNode:q,collisionRect:null,collisions:null,droppableRects:W,draggableNodes:w,draggingNode:null,draggingNodeRect:null,droppableContainers:T,over:null,scrollableAncestors:[],scrollAdjustedTranslate:null}),J=T.getNodeFor((s=Y.current.over)==null?void 0:s.id),ie=$y({measure:$.dragOverlay.measure}),ue=(i=ie.nodeRef.current)!=null?i:q,de=j?(n=ie.rect)!=null?n:U:null,xe=!!(ie.nodeRef.current&&ie.rect),oe=Ty(xe?null:U),he=xf(ue?Ut(ue):null),me=Dy(j?J??q:null),fe=By(me),le=Gy(m,{transform:{x:k.x-oe.x,y:k.y-oe.y,scaleX:1,scaleY:1},activatorEvent:L,active:N,activeNodeRect:U,containerNodeRect:te,draggingNodeRect:de,over:Y.current.over,overlayNodeRect:ie.rect,scrollableAncestors:me,scrollableAncestorRects:fe,windowRect:he}),ve=H?Di(H,k):null,Ce=My(me),Te=ld(Ce),Q=ld(Ce,[U]),ae=Di(le,Te),Se=de?iy(de,le):null,Ne=N&&Se?h({active:N,collisionRect:Se,droppableRects:W,droppableContainers:z,pointerCoordinates:ve}):null,Be=lf(Ne,"id"),[Oe,He]=S.useState(null),Je=xe?le:Di(le,Q),dt=ty(Je,(o=Oe?.rect)!=null?o:null,U),pe=S.useRef(null),ke=S.useCallback((Ae,Ie)=>{let{sensor:qe,options:qt}=Ie;if(E.current==null)return;const _t=w.get(E.current);if(!_t)return;const xt=Ae.nativeEvent,vt=new qe({active:E.current,activeNode:_t,event:xt,options:qt,context:Y,onAbort($e){if(!w.get($e))return;const{onDragAbort:Nt}=P.current,wt={id:$e};Nt?.(wt),x({type:"onDragAbort",event:wt})},onPending($e,kt,Nt,wt){if(!w.get($e))return;const{onDragPending:Ot}=P.current,$t={id:$e,constraint:kt,initialCoordinates:Nt,offset:wt};Ot?.($t),x({type:"onDragPending",event:$t})},onStart($e){const kt=E.current;if(kt==null)return;const Nt=w.get(kt);if(!Nt)return;const{onDragStart:wt}=P.current,_e={activatorEvent:xt,active:{id:kt,data:Nt.data,rect:A}};ds.unstable_batchedUpdates(()=>{wt?.(_e),C(Gs.Initializing),v({type:at.DragStart,initialCoordinates:$e,active:kt}),x({type:"onDragStart",event:_e}),M(pe.current),D(xt)})},onMove($e){v({type:at.DragMove,coordinates:$e})},onEnd:_s(at.DragEnd),onCancel:_s(at.DragCancel)});pe.current=vt;function _s($e){return async function(){const{active:Nt,collisions:wt,over:_e,scrollAdjustedTranslate:Ot}=Y.current;let $t=null;if(Nt&&Ot){const{cancelDrop:ls}=P.current;$t={activatorEvent:xt,active:Nt,collisions:wt,delta:Ot,over:_e},$e===at.DragEnd&&typeof ls=="function"&&await Promise.resolve(ls($t))&&($e=at.DragCancel)}E.current=null,ds.unstable_batchedUpdates(()=>{v({type:$e}),C(Gs.Uninitialized),He(null),M(null),D(null),pe.current=null;const ls=$e===at.DragEnd?"onDragEnd":"onDragCancel";if($t){const Qi=P.current[ls];Qi?.($t),x({type:ls,event:$t})}})}}},[w]),Qe=S.useCallback((Ae,Ie)=>(qe,qt)=>{const _t=qe.nativeEvent,xt=w.get(qt);if(E.current!==null||!xt||_t.dndKit||_t.defaultPrevented)return;const vt={active:xt};Ae(qe,Ie.options,vt)===!0&&(_t.dndKit={capturedBy:Ie.sensor},E.current=qt,ke(qe,Ie))},[w,ke]),Ct=Ny(u,Qe);Py(u),Es(()=>{U&&y===Gs.Initializing&&C(Gs.Initialized)},[U,y]),S.useEffect(()=>{const{onDragMove:Ae}=P.current,{active:Ie,activatorEvent:qe,collisions:qt,over:_t}=Y.current;if(!Ie||!qe)return;const xt={active:Ie,activatorEvent:qe,collisions:qt,delta:{x:ae.x,y:ae.y},over:_t};ds.unstable_batchedUpdates(()=>{Ae?.(xt),x({type:"onDragMove",event:xt})})},[ae.x,ae.y]),S.useEffect(()=>{const{active:Ae,activatorEvent:Ie,collisions:qe,droppableContainers:qt,scrollAdjustedTranslate:_t}=Y.current;if(!Ae||E.current==null||!Ie||!_t)return;const{onDragOver:xt}=P.current,vt=qt.get(Be),_s=vt&&vt.rect.current?{id:vt.id,rect:vt.rect.current,data:vt.data,disabled:vt.disabled}:null,$e={active:Ae,activatorEvent:Ie,collisions:qe,delta:{x:_t.x,y:_t.y},over:_s};ds.unstable_batchedUpdates(()=>{He(_s),xt?.($e),x({type:"onDragOver",event:$e})})},[Be]),Es(()=>{Y.current={activatorEvent:L,active:N,activeNode:q,collisionRect:Se,collisions:Ne,droppableRects:W,draggableNodes:w,draggingNode:ue,draggingNodeRect:de,droppableContainers:T,over:Oe,scrollableAncestors:me,scrollAdjustedTranslate:ae},A.current={initial:de,translated:Se}},[N,q,Ne,Se,w,ue,de,W,T,Oe,me,ae]),Vy({...ee,delta:k,draggingRect:Se,pointerCoordinates:ve,scrollableAncestors:me,scrollableAncestorRects:fe});const Pe=S.useMemo(()=>({active:N,activeNode:q,activeNodeRect:U,activatorEvent:L,collisions:Ne,containerNodeRect:te,dragOverlay:ie,draggableNodes:w,droppableContainers:T,droppableRects:W,over:Oe,measureDroppableContainers:F,scrollableAncestors:me,scrollableAncestorRects:fe,measuringConfiguration:$,measuringScheduled:G,windowRect:he}),[N,q,U,L,Ne,te,ie,w,T,W,Oe,F,me,fe,$,G,he]),Kt=S.useMemo(()=>({activatorEvent:L,activators:Ct,active:N,activeNodeRect:U,ariaDescribedById:{draggable:O},dispatch:v,draggableNodes:w,over:Oe,measureDroppableContainers:F}),[L,Ct,N,U,v,O,w,Oe,F]);return Ft.createElement(nf.Provider,{value:b},Ft.createElement(po.Provider,{value:Kt},Ft.createElement(vf.Provider,{value:Pe},Ft.createElement(bf.Provider,{value:dt},d)),Ft.createElement(qy,{disabled:l?.restoreFocus===!1})),Ft.createElement(G0,{...l,hiddenTextDescribedById:O}));function jt(){const Ae=R?.autoScrollEnabled===!1,Ie=typeof c=="object"?c.enabled===!1:c===!1,qe=j&&!Ae&&!Ie;return typeof c=="object"?{...c,enabled:qe}:{enabled:qe}}}),Qy=S.createContext(null),dd="button",Zy="Draggable";function e2(t){let{id:e,data:s,disabled:i=!1,attributes:n}=t;const o=Qr(Zy),{activators:a,activatorEvent:l,active:c,activeNodeRect:d,ariaDescribedById:u,draggableNodes:h,over:f}=S.useContext(po),{role:m=dd,roleDescription:p="draggable",tabIndex:g=0}=n??{},_=c?.id===e,v=S.useContext(_?bf:Qy),[x,b]=Hn(),[y,C]=Hn(),j=Ly(a,e),V=Er(s);Es(()=>(h.set(e,{id:e,key:o,node:x,activatorNode:y,data:V}),()=>{const k=h.get(e);k&&k.key===o&&h.delete(e)}),[h,e]);const w=S.useMemo(()=>({role:m,tabIndex:g,"aria-disabled":i,"aria-pressed":_&&m===dd?!0:void 0,"aria-roledescription":p,"aria-describedby":u.draggable}),[i,m,g,_,p,u.draggable]);return{active:c,activatorEvent:l,activeNodeRect:d,attributes:w,isDragging:_,listeners:i?void 0:j,node:x,over:f,setNodeRef:b,setActivatorNodeRef:C,transform:v}}function t2(){return S.useContext(vf)}const s2="Droppable",i2={timeout:25};function r2(t){let{data:e,disabled:s=!1,id:i,resizeObserverConfig:n}=t;const o=Qr(s2),{active:a,dispatch:l,over:c,measureDroppableContainers:d}=S.useContext(po),u=S.useRef({disabled:s}),h=S.useRef(!1),f=S.useRef(null),m=S.useRef(null),{disabled:p,updateMeasurementsFor:g,timeout:_}={...i2,...n},v=Er(g??i),x=S.useCallback(()=>{if(!h.current){h.current=!0;return}m.current!=null&&clearTimeout(m.current),m.current=setTimeout(()=>{d(Array.isArray(v.current)?v.current:[v.current]),m.current=null},_)},[_]),b=mo({callback:x,disabled:p||!a}),y=S.useCallback((w,k)=>{b&&(k&&(b.unobserve(k),h.current=!1),w&&b.observe(w))},[b]),[C,j]=Hn(y),V=Er(e);return S.useEffect(()=>{!b||!C.current||(b.disconnect(),h.current=!1,b.observe(C.current))},[C,b]),S.useEffect(()=>(l({type:at.RegisterDroppable,element:{id:i,key:o,disabled:s,node:C,rect:f,data:V}}),()=>l({type:at.UnregisterDroppable,key:o,id:i})),[i]),S.useEffect(()=>{s!==u.current.disabled&&(l({type:at.SetDroppableDisabled,id:i,key:o,disabled:s}),u.current.disabled=s)},[i,o,s,l]),{active:a,rect:f,isOver:c?.id===i,node:C,over:c,setNodeRef:j}}function Ul(t,e,s){const i=t.slice();return i.splice(s<0?i.length+s:s,0,i.splice(e,1)[0]),i}function n2(t,e){return t.reduce((s,i,n)=>{const o=e.get(i);return o&&(s[n]=o),s},Array(t.length))}function cn(t){return t!==null&&t>=0}function o2(t,e){if(t===e)return!0;if(t.length!==e.length)return!1;for(let s=0;s<t.length;s++)if(t[s]!==e[s])return!1;return!0}function a2(t){return typeof t=="boolean"?{draggable:t,droppable:t}:t}const yf=t=>{let{rects:e,activeIndex:s,overIndex:i,index:n}=t;const o=Ul(e,i,s),a=e[n],l=o[n];return!l||!a?null:{x:l.left-a.left,y:l.top-a.top,scaleX:l.width/a.width,scaleY:l.height/a.height}},dn={scaleX:1,scaleY:1},l2=t=>{var e;let{activeIndex:s,activeNodeRect:i,index:n,rects:o,overIndex:a}=t;const l=(e=o[s])!=null?e:i;if(!l)return null;if(n===s){const d=o[a];return d?{x:0,y:s<a?d.top+d.height-(l.top+l.height):d.top-l.top,...dn}:null}const c=c2(o,n,s);return n>s&&n<=a?{x:0,y:-l.height-c,...dn}:n<s&&n>=a?{x:0,y:l.height+c,...dn}:{x:0,y:0,...dn}};function c2(t,e,s){const i=t[e],n=t[e-1],o=t[e+1];return i?s<e?n?i.top-(n.top+n.height):o?o.top-(i.top+i.height):0:o?o.top-(i.top+i.height):n?i.top-(n.top+n.height):0:0}const Sf="Sortable",wf=Ft.createContext({activeIndex:-1,containerId:Sf,disableTransforms:!1,items:[],overIndex:-1,useDragOverlay:!1,sortedRects:[],strategy:yf,disabled:{draggable:!1,droppable:!1}});function d2(t){let{children:e,id:s,items:i,strategy:n=yf,disabled:o=!1}=t;const{active:a,dragOverlay:l,droppableRects:c,over:d,measureDroppableContainers:u}=t2(),h=Qr(Sf,s),f=l.rect!==null,m=S.useMemo(()=>i.map(j=>typeof j=="object"&&"id"in j?j.id:j),[i]),p=a!=null,g=a?m.indexOf(a.id):-1,_=d?m.indexOf(d.id):-1,v=S.useRef(m),x=!o2(m,v.current),b=_!==-1&&g===-1||x,y=a2(o);Es(()=>{x&&p&&u(m)},[x,m,p,u]),S.useEffect(()=>{v.current=m},[m]);const C=S.useMemo(()=>({activeIndex:g,containerId:h,disabled:y,disableTransforms:b,items:m,overIndex:_,useDragOverlay:f,sortedRects:n2(m,c),strategy:n}),[g,h,y.draggable,y.droppable,b,m,_,c,f,n]);return Ft.createElement(wf.Provider,{value:C},e)}const h2=t=>{let{id:e,items:s,activeIndex:i,overIndex:n}=t;return Ul(s,i,n).indexOf(e)},u2=t=>{let{containerId:e,isSorting:s,wasDragging:i,index:n,items:o,newIndex:a,previousItems:l,previousContainerId:c,transition:d}=t;return!d||!i||l!==o&&n===a?!1:s?!0:a!==n&&e===c},f2={duration:200,easing:"ease"},Vf="transform",m2=Rr.Transition.toString({property:Vf,duration:0,easing:"linear"}),p2={roleDescription:"sortable"};function g2(t){let{disabled:e,index:s,node:i,rect:n}=t;const[o,a]=S.useState(null),l=S.useRef(s);return Es(()=>{if(!e&&s!==l.current&&i.current){const c=n.current;if(c){const d=Gi(i.current,{ignoreTransform:!0}),u={x:c.left-d.left,y:c.top-d.top,scaleX:c.width/d.width,scaleY:c.height/d.height};(u.x||u.y)&&a(u)}}s!==l.current&&(l.current=s)},[e,s,i,n]),S.useEffect(()=>{o&&a(null)},[o]),o}function _2(t){let{animateLayoutChanges:e=u2,attributes:s,disabled:i,data:n,getNewIndex:o=h2,id:a,strategy:l,resizeObserverConfig:c,transition:d=f2}=t;const{items:u,containerId:h,activeIndex:f,disabled:m,disableTransforms:p,sortedRects:g,overIndex:_,useDragOverlay:v,strategy:x}=S.useContext(wf),b=x2(i,m),y=u.indexOf(a),C=S.useMemo(()=>({sortable:{containerId:h,index:y,items:u},...n}),[h,n,y,u]),j=S.useMemo(()=>u.slice(u.indexOf(a)),[u,a]),{rect:V,node:w,isOver:k,setNodeRef:T}=r2({id:a,data:C,disabled:b.droppable,resizeObserverConfig:{updateMeasurementsFor:j,...c}}),{active:I,activatorEvent:A,activeNodeRect:N,attributes:E,setNodeRef:R,listeners:M,isDragging:L,over:D,setActivatorNodeRef:P,transform:O}=e2({id:a,data:C,attributes:{...p2,...s},disabled:b.draggable}),z=M0(T,R),$=!!I,W=$&&!p&&cn(f)&&cn(_),F=!v&&L,G=F&&W?O:null,H=W?G??(l??x)({rects:g,activeNodeRect:N,activeIndex:f,overIndex:_,index:y}):null,ee=cn(f)&&cn(_)?o({id:a,items:u,activeIndex:f,overIndex:_}):y,K=I?.id,U=S.useRef({activeId:K,items:u,newIndex:ee,containerId:h}),te=u!==U.current.items,Y=e({active:I,containerId:h,isDragging:L,isSorting:$,id:a,index:y,items:u,newIndex:U.current.newIndex,previousItems:U.current.items,previousContainerId:U.current.containerId,transition:d,wasDragging:U.current.activeId!=null}),J=g2({disabled:!Y,index:y,node:w,rect:V});return S.useEffect(()=>{$&&U.current.newIndex!==ee&&(U.current.newIndex=ee),h!==U.current.containerId&&(U.current.containerId=h),u!==U.current.items&&(U.current.items=u)},[$,ee,h,u]),S.useEffect(()=>{if(K===U.current.activeId)return;if(K!=null&&U.current.activeId==null){U.current.activeId=K;return}const ue=setTimeout(()=>{U.current.activeId=K},50);return()=>clearTimeout(ue)},[K]),{active:I,activeIndex:f,attributes:E,data:C,rect:V,index:y,newIndex:ee,items:u,isOver:k,isSorting:$,isDragging:L,listeners:M,node:w,overIndex:_,over:D,setNodeRef:z,setActivatorNodeRef:P,setDroppableNodeRef:T,setDraggableNodeRef:R,transform:J??H,transition:ie()};function ie(){if(J||te&&U.current.newIndex===y)return m2;if(!(F&&!$l(A)||!d)&&($||Y))return Rr.Transition.toString({...d,property:Vf})}}function x2(t,e){var s,i;return typeof t=="boolean"?{draggable:t,droppable:!1}:{draggable:(s=t?.draggable)!=null?s:e.draggable,droppable:(i=t?.droppable)!=null?i:e.droppable}}function Kn(t){if(!t)return!1;const e=t.data.current;return!!(e&&"sortable"in e&&typeof e.sortable=="object"&&"containerId"in e.sortable&&"items"in e.sortable&&"index"in e.sortable)}const v2=[je.Down,je.Right,je.Up,je.Left],b2=(t,e)=>{let{context:{active:s,collisionRect:i,droppableRects:n,droppableContainers:o,over:a,scrollableAncestors:l}}=e;if(v2.includes(t.code)){if(t.preventDefault(),!s||!i)return;const c=[];o.getEnabled().forEach(h=>{if(!h||h!=null&&h.disabled)return;const f=n.get(h.id);if(f)switch(t.code){case je.Down:i.top<f.top&&c.push(h);break;case je.Up:i.top>f.top&&c.push(h);break;case je.Left:i.left>f.left&&c.push(h);break;case je.Right:i.left<f.left&&c.push(h);break}});const d=Q0({collisionRect:i,droppableRects:n,droppableContainers:c});let u=lf(d,"id");if(u===a?.id&&d.length>1&&(u=d[1].id),u!=null){const h=o.get(s.id),f=o.get(u),m=f?n.get(f.id):null,p=f?.node.current;if(p&&m&&h&&f){const _=fo(p).some((j,V)=>l[V]!==j),v=Cf(h,f),x=y2(h,f),b=_||!v?{x:0,y:0}:{x:x?i.width-m.width:0,y:x?i.height-m.height:0},y={x:m.left,y:m.top};return b.x&&b.y?y:Ir(y,b)}}}};function Cf(t,e){return!Kn(t)||!Kn(e)?!1:t.data.current.sortable.containerId===e.data.current.sortable.containerId}function y2(t,e){return!Kn(t)||!Kn(e)||!Cf(t,e)?!1:t.data.current.sortable.index<e.data.current.sortable.index}function S2(t){const e=B.c(21),{value:s,onChange:i,placeholder:n,onKeyDown:o,className:a,isSearching:l,disabled:c}=t,d=n===void 0?"Search...":n;let u;e[0]!==a?(u=X("shrink-0 w-full border-b border-border h-12",a),e[0]=a,e[1]=u):u=e[1];const h=c?"cursor-not-allowed opacity-50":"cursor-text";let f;e[2]!==h?(f=X("flex items-center gap-2.5 h-12 px-4",h),e[2]=h,e[3]=f):f=e[3];let m;e[4]!==l?(m=l?r.jsx(Ee,{size:16,className:"animate-spin text-muted-foreground shrink-0"}):r.jsx(vl,{size:16,className:"text-muted-foreground shrink-0"}),e[4]=l,e[5]=m):m=e[5];let p;e[6]!==i?(p=x=>i(x.target.value),e[6]=i,e[7]=p):p=e[7];let g;e[8]!==c||e[9]!==o||e[10]!==d||e[11]!==p||e[12]!==s?(g=r.jsx("input",{type:"text",value:s,onChange:p,onKeyDown:o,placeholder:d,disabled:c,className:"flex-1 min-w-0 bg-transparent text-sm text-foreground placeholder:text-muted-foreground/50 outline-none"}),e[8]=c,e[9]=o,e[10]=d,e[11]=p,e[12]=s,e[13]=g):g=e[13];let _;e[14]!==f||e[15]!==m||e[16]!==g?(_=r.jsxs("label",{className:f,children:[m,g]}),e[14]=f,e[15]=m,e[16]=g,e[17]=_):_=e[17];let v;return e[18]!==u||e[19]!==_?(v=r.jsx("div",{className:u,children:_}),e[18]=u,e[19]=_,e[20]=v):v=e[20],v}var Kl="ContextMenu",[w2]=mp(Kl,[kh]),Pt=kh(),[V2,jf]=w2(Kl),kf=t=>{const{__scopeContextMenu:e,children:s,onOpenChange:i,dir:n,modal:o=!0}=t,[a,l]=S.useState(!1),c=Pt(e),d=op(i),u=S.useCallback(h=>{l(h),d(h)},[d]);return r.jsx(V2,{scope:e,open:a,onOpenChange:u,modal:o,children:r.jsx(ap,{...c,dir:n,open:a,onOpenChange:u,modal:o,children:s})})};kf.displayName=Kl;var Nf="ContextMenuTrigger",Af=S.forwardRef((t,e)=>{const{__scopeContextMenu:s,disabled:i=!1,...n}=t,o=jf(Nf,s),a=Pt(s),l=S.useRef({x:0,y:0}),c=S.useRef({getBoundingClientRect:()=>DOMRect.fromRect({width:0,height:0,...l.current})}),d=S.useRef(0),u=S.useCallback(()=>window.clearTimeout(d.current),[]),h=f=>{l.current={x:f.clientX,y:f.clientY},o.onOpenChange(!0)};return S.useEffect(()=>u,[u]),S.useEffect(()=>{i&&u()},[i,u]),r.jsxs(r.Fragment,{children:[r.jsx(lp,{...a,virtualRef:c}),r.jsx(cp.span,{"data-state":o.open?"open":"closed","data-disabled":i?"":void 0,...n,ref:e,style:{WebkitTouchCallout:"none",...t.style},onContextMenu:i?t.onContextMenu:Zi(t.onContextMenu,f=>{u(),h(f),f.preventDefault()}),onPointerDown:i?t.onPointerDown:Zi(t.onPointerDown,hn(f=>{u(),d.current=window.setTimeout(()=>h(f),700)})),onPointerMove:i?t.onPointerMove:Zi(t.onPointerMove,hn(u)),onPointerCancel:i?t.onPointerCancel:Zi(t.onPointerCancel,hn(u)),onPointerUp:i?t.onPointerUp:Zi(t.onPointerUp,hn(u))})]})});Af.displayName=Nf;var C2="ContextMenuPortal",Ef=t=>{const{__scopeContextMenu:e,...s}=t,i=Pt(e);return r.jsx(dp,{...i,...s})};Ef.displayName=C2;var If="ContextMenuContent",Rf=S.forwardRef((t,e)=>{const{__scopeContextMenu:s,...i}=t,n=jf(If,s),o=Pt(s),a=S.useRef(!1);return r.jsx(hp,{...o,...i,ref:e,side:"right",sideOffset:2,align:"start",onCloseAutoFocus:l=>{t.onCloseAutoFocus?.(l),!l.defaultPrevented&&a.current&&l.preventDefault(),a.current=!1},onInteractOutside:l=>{t.onInteractOutside?.(l),!l.defaultPrevented&&!n.modal&&(a.current=!0)},style:{...t.style,"--radix-context-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-context-menu-content-available-width":"var(--radix-popper-available-width)","--radix-context-menu-content-available-height":"var(--radix-popper-available-height)","--radix-context-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-context-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});Rf.displayName=If;var j2="ContextMenuGroup",k2=S.forwardRef((t,e)=>{const{__scopeContextMenu:s,...i}=t,n=Pt(s);return r.jsx(pp,{...n,...i,ref:e})});k2.displayName=j2;var N2="ContextMenuLabel",A2=S.forwardRef((t,e)=>{const{__scopeContextMenu:s,...i}=t,n=Pt(s);return r.jsx(gp,{...n,...i,ref:e})});A2.displayName=N2;var E2="ContextMenuItem",Tf=S.forwardRef((t,e)=>{const{__scopeContextMenu:s,...i}=t,n=Pt(s);return r.jsx(up,{...n,...i,ref:e})});Tf.displayName=E2;var I2="ContextMenuCheckboxItem",R2=S.forwardRef((t,e)=>{const{__scopeContextMenu:s,...i}=t,n=Pt(s);return r.jsx(_p,{...n,...i,ref:e})});R2.displayName=I2;var T2="ContextMenuRadioGroup",D2=S.forwardRef((t,e)=>{const{__scopeContextMenu:s,...i}=t,n=Pt(s);return r.jsx(xp,{...n,...i,ref:e})});D2.displayName=T2;var M2="ContextMenuRadioItem",P2=S.forwardRef((t,e)=>{const{__scopeContextMenu:s,...i}=t,n=Pt(s);return r.jsx(vp,{...n,...i,ref:e})});P2.displayName=M2;var L2="ContextMenuItemIndicator",B2=S.forwardRef((t,e)=>{const{__scopeContextMenu:s,...i}=t,n=Pt(s);return r.jsx(bp,{...n,...i,ref:e})});B2.displayName=L2;var O2="ContextMenuSeparator",Df=S.forwardRef((t,e)=>{const{__scopeContextMenu:s,...i}=t,n=Pt(s);return r.jsx(fp,{...n,...i,ref:e})});Df.displayName=O2;var $2="ContextMenuArrow",z2=S.forwardRef((t,e)=>{const{__scopeContextMenu:s,...i}=t,n=Pt(s);return r.jsx(yp,{...n,...i,ref:e})});z2.displayName=$2;var F2="ContextMenuSubTrigger",H2=S.forwardRef((t,e)=>{const{__scopeContextMenu:s,...i}=t,n=Pt(s);return r.jsx(Sp,{...n,...i,ref:e})});H2.displayName=F2;var W2="ContextMenuSubContent",U2=S.forwardRef((t,e)=>{const{__scopeContextMenu:s,...i}=t,n=Pt(s);return r.jsx(wp,{...n,...i,ref:e,style:{...t.style,"--radix-context-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-context-menu-content-available-width":"var(--radix-popper-available-width)","--radix-context-menu-content-available-height":"var(--radix-popper-available-height)","--radix-context-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-context-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});U2.displayName=W2;function hn(t){return e=>e.pointerType!=="mouse"?t(e):void 0}var K2=kf,q2=Af,G2=Ef,Y2=Rf,X2=Tf,J2=Df;function Q2(t){const e=B.c(4);let s;e[0]!==t?({...s}=t,e[0]=t,e[1]=s):s=e[1];let i;return e[2]!==s?(i=r.jsx(K2,{"data-slot":"context-menu",...s}),e[2]=s,e[3]=i):i=e[3],i}function Z2(t){const e=B.c(4);let s;e[0]!==t?({...s}=t,e[0]=t,e[1]=s):s=e[1];let i;return e[2]!==s?(i=r.jsx(q2,{"data-slot":"context-menu-trigger",...s}),e[2]=s,e[3]=i):i=e[3],i}function eS(t){const e=B.c(8);let s,i;e[0]!==t?({className:s,...i}=t,e[0]=t,e[1]=s,e[2]=i):(s=e[1],i=e[2]);let n;e[3]!==s?(n=X("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 max-h-(--radix-context-menu-content-available-height) min-w-[8rem] origin-(--radix-context-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border p-1 shadow-md",s),e[3]=s,e[4]=n):n=e[4];let o;return e[5]!==i||e[6]!==n?(o=r.jsx(G2,{children:r.jsx(Y2,{"data-slot":"context-menu-content",className:n,...i})}),e[5]=i,e[6]=n,e[7]=o):o=e[7],o}function hd(t){const e=B.c(12);let s,i,n,o;e[0]!==t?({className:s,inset:i,variant:o,...n}=t,e[0]=t,e[1]=s,e[2]=i,e[3]=n,e[4]=o):(s=e[1],i=e[2],n=e[3],o=e[4]);const a=o===void 0?"default":o;let l;e[5]!==s?(l=X("focus:bg-accent focus:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",s),e[5]=s,e[6]=l):l=e[6];let c;return e[7]!==i||e[8]!==n||e[9]!==l||e[10]!==a?(c=r.jsx(X2,{"data-slot":"context-menu-item","data-inset":i,"data-variant":a,className:l,...n}),e[7]=i,e[8]=n,e[9]=l,e[10]=a,e[11]=c):c=e[11],c}function tS(t){const e=B.c(8);let s,i;e[0]!==t?({className:s,...i}=t,e[0]=t,e[1]=s,e[2]=i):(s=e[1],i=e[2]);let n;e[3]!==s?(n=X("bg-border -mx-1 my-1 h-px",s),e[3]=s,e[4]=n):n=e[4];let o;return e[5]!==i||e[6]!==n?(o=r.jsx(J2,{"data-slot":"context-menu-separator",className:n,...i}),e[5]=i,e[6]=n,e[7]=o):o=e[7],o}function Mf(t){const e=Ke(),s=Mt(),i=yu(),{locator:n}=be(),o=$r({strict:!1}),a=vi({strict:!1});return async l=>{const c=crypto.randomUUID(),d=l===a.virtualmcpid?Lh(s,n,o.taskId??""):null;try{await i.create.mutateAsync({id:c,virtual_mcp_id:l,...d?{branch:d}:{}})}catch{}e({to:"/$org/$taskId",params:{org:t,taskId:c},search:{virtualmcpid:l}})}}function sS({agent:t,org:e,onUnpin:s,isDragging:i}){const n=Ke(),{isMobile:o,setOpenMobile:a}=qr(),l=Mf(e),d=Vh({select:b=>b.location.pathname}).startsWith(`/${e}/${t.id}`),[u,h]=S.useState(null),f=S.useRef(null),m=S.useRef(null),p=S.useRef(!1);p.current=!!i,i&&(u||m.current)&&(m.current&&(clearTimeout(m.current),m.current=null),u&&h(null));const g=b=>{if(p.current)return;const y=b.currentTarget.getBoundingClientRect();m.current=setTimeout(()=>{p.current||h(y)},550)},_=b=>{m.current&&(clearTimeout(m.current),m.current=null),!(f.current&&b.relatedTarget instanceof Node&&f.current.contains(b.relatedTarget))&&h(null)},v=u?Math.round(u.height*.9):0,x=u?u.width+v:0;return r.jsx(Q2,{children:r.jsxs(Zt,{className:X(u&&"z-[55]"),children:[r.jsx(Z2,{asChild:!0,children:r.jsx(us,{tooltip:u?void 0:t.title,isActive:d,onClick:()=>{se("sidebar_agent_pin_clicked",{agent_id:t.id,agent_title:t.title}),l(t.id),o&&a(!1)},onMouseEnter:g,onMouseLeave:_,children:r.jsx(zs,{icon:t.icon,name:t.title,size:"xs",className:"w-full h-full [&_svg]:w-1/2 [&_svg]:h-1/2"})})}),r.jsxs(eS,{children:[r.jsxs(hd,{onClick:()=>{const b=crypto.randomUUID();n({to:"/$org/$taskId",params:{org:e,taskId:b},search:{virtualmcpid:t.id}})},children:[r.jsx(Gr,{size:14}),"Settings"]}),r.jsx(tS,{}),r.jsxs(hd,{onClick:()=>{s(),d&&n({to:"/$org",params:{org:e}})},className:"",children:[r.jsx(fi,{size:14}),"Unpin"]})]}),u&&ds.createPortal(r.jsx("button",{ref:f,type:"button",onMouseLeave:()=>h(null),onClick:b=>{b.stopPropagation(),h(null),s(),n({to:"/$org",params:{org:e}})},className:X("flex items-center justify-center","bg-sidebar-accent text-muted-foreground","rounded-xl cursor-pointer","animate-in fade-in-0 slide-in-from-right-2","duration-150 [animation-timing-function:cubic-bezier(0.165,0.84,0.44,1)]","hover:text-foreground transition-colors"),style:{position:"fixed",top:u.top,left:u.left,height:u.height,width:x,paddingLeft:u.width,zIndex:50,boxShadow:"inset 0 0 0.5px 1px hsla(0, 0%, 100%, 0.075), 0 0 0 0.5px hsla(0, 0%, 0%, 0.12)"},children:r.jsx(fi,{size:14})}),document.body)]})})}function iS(t){const e=B.c(18);let s;e[0]!==t.agent.id?(s={id:t.agent.id},e[0]=t.agent.id,e[1]=s):s=e[1];const{attributes:i,listeners:n,setNodeRef:o,transform:a,transition:l,isDragging:c}=_2(s);let d;e[2]!==a?(d=Rr.Transform.toString(a?{...a,x:0}:null),e[2]=a,e[3]=d):d=e[3];const u=c?.5:void 0,h=c?100:void 0;let f;e[4]!==d||e[5]!==u||e[6]!==h||e[7]!==l?(f={transform:d,transition:l,opacity:u,zIndex:h},e[4]=d,e[5]=u,e[6]=h,e[7]=l,e[8]=f):f=e[8];const m=f;let p;e[9]!==c||e[10]!==t?(p=r.jsx(sS,{...t,isDragging:c}),e[9]=c,e[10]=t,e[11]=p):p=e[11];let g;return e[12]!==i||e[13]!==n||e[14]!==o||e[15]!==m||e[16]!==p?(g=r.jsx("div",{ref:o,style:m,...i,...n,tabIndex:-1,className:"w-full",children:p}),e[12]=i,e[13]=n,e[14]=o,e[15]=m,e[16]=p,e[17]=g):g=e[17],g}function rS(t){const e=B.c(9),{agent:s,onClick:i}=t;let n;e[0]!==s.icon||e[1]!==s.title?(n=r.jsx(zs,{icon:s.icon,name:s.title,size:"md",className:"transition-transform group-hover:scale-105"}),e[0]=s.icon,e[1]=s.title,e[2]=n):n=e[2];let o;e[3]!==s.title?(o=r.jsx("span",{className:"text-xs leading-tight text-center text-muted-foreground group-hover:text-foreground line-clamp-2 w-full",children:s.title}),e[3]=s.title,e[4]=o):o=e[4];let a;return e[5]!==i||e[6]!==n||e[7]!==o?(a=r.jsxs("button",{type:"button",onClick:i,className:"flex flex-col items-center gap-2 p-3 rounded-xl transition-colors hover:bg-accent cursor-pointer group",children:[n,o]}),e[5]=i,e[6]=n,e[7]=o,e[8]=a):a=e[8],a}function nS(t){const e=B.c(82),{onClose:s,onOpenImportDeco:i,onOpenGithubImport:n,onOpenDiagnosticsModal:o,onOpenLeanCanvasModal:a,onOpenStudioPackModal:l}=t,[c,d]=S.useState(""),u=oo(),{org:h}=be();let f;e[0]!==u?(f=u.filter(hS).map(dS),e[0]=u,e[1]=f):f=e[1];const m=f,{pin:p,isPinned:g}=fu(h.id,m);let _;e[2]===Symbol.for("react.memo_cache_sentinel")?(_={navigateOnCreate:!0},e[2]=_):_=e[2];const{createVirtualMCP:v,isCreating:x}=mu(_),[b]=Wi(),y=Mf(h.slug),C=lo();let j,V,w,k,T,I,A,N;if(e[3]!==u||e[4]!==v||e[5]!==x||e[6]!==g||e[7]!==C||e[8]!==y||e[9]!==s||e[10]!==o||e[11]!==n||e[12]!==i||e[13]!==a||e[14]!==l||e[15]!==p||e[16]!==b.experimental_vibecode||e[17]!==c){const O=c.toLowerCase();N=u.filter(cS).filter(le=>!c||le.title.toLowerCase().includes(O));let z;e[26]!==u?(z=u.some(lS),e[26]=u,e[27]=z):z=e[27];const $=z;j=Os.filter(le=>(!c||le.title.toLowerCase().includes(O))&&!(le.id==="studio-pack"&&$));let W;e[28]===Symbol.for("react.memo_cache_sentinel")?(W=Os.find(aS),e[28]=W):W=e[28];const F=W,G=F?u.find(le=>le.metadata?.type===F.id):void 0;let q;e[29]===Symbol.for("react.memo_cache_sentinel")?(q=Os.find(oS),e[29]=q):q=e[29];const H=q,ee=H?u.find(le=>le.metadata?.type===H.id):void 0;let K;e[30]!==g||e[31]!==y||e[32]!==s||e[33]!==p?(K=le=>{g(le.id)||p(le.id),s(),d(""),y(le.id)},e[30]=g,e[31]=y,e[32]=s,e[33]=p,e[34]=K):K=e[34];const U=K,te=le=>{s(),d(""),le==="site-editor"?i():le==="site-diagnostics"?G?C(G.id):o():le==="lean-canvas"?ee?C(ee.id):a():le==="studio-pack"?l():y(le)};I="flex flex-col max-h-[min(640px,80dvh)]",e[35]!==c?(A=r.jsx(S2,{value:c,onChange:d,placeholder:"Search agents..."}),e[35]=c,e[36]=A):A=e[36],V="overflow-y-auto flex-1 min-h-0 px-3 pb-3",e[37]===Symbol.for("react.memo_cache_sentinel")?(w=r.jsx("div",{className:"px-1 pt-3 pb-2",children:r.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"Agents"})}),e[37]=w):w=e[37];let Y;e[38]!==v||e[39]!==s?(Y=async()=>{se("agent_create_new_clicked",{source:"browse_popover"}),await v(),s()},e[38]=v,e[39]=s,e[40]=Y):Y=e[40];let J,ie;e[41]===Symbol.for("react.memo_cache_sentinel")?(J=r.jsx("div",{className:"w-12 h-12 rounded-xl border-2 border-dashed border-border flex items-center justify-center shrink-0 transition-transform group-hover:scale-105",children:r.jsx(Qt,{size:16,className:"text-muted-foreground"})}),ie=r.jsx("span",{className:"text-xs leading-tight text-center text-muted-foreground group-hover:text-foreground",children:"Create new"}),e[41]=J,e[42]=ie):(J=e[41],ie=e[42]);let ue;e[43]!==x||e[44]!==Y?(ue=r.jsxs("button",{type:"button",disabled:x,onClick:Y,className:"flex flex-col items-center gap-2 p-3 rounded-xl transition-colors hover:bg-accent cursor-pointer group disabled:opacity-50 disabled:cursor-not-allowed",children:[J,ie]}),e[43]=x,e[44]=Y,e[45]=ue):ue=e[45];let de;e[46]!==s||e[47]!==i?(de=()=>{se("agent_import_clicked",{source:"deco_cx"}),i(),s()},e[46]=s,e[47]=i,e[48]=de):de=e[48];let xe,oe;e[49]===Symbol.for("react.memo_cache_sentinel")?(xe=r.jsx("div",{className:"w-12 h-12 rounded-xl border-2 border-border flex items-center justify-center shrink-0 transition-transform group-hover:scale-105",children:r.jsx("img",{src:"/logos/deco%20logo.svg",alt:"deco.cx",className:"size-5"})}),oe=r.jsx("span",{className:"text-xs leading-tight text-center text-muted-foreground group-hover:text-foreground",children:"Import deco.cx"}),e[49]=xe,e[50]=oe):(xe=e[49],oe=e[50]);let he;e[51]!==de?(he=r.jsxs("button",{type:"button",onClick:de,className:"flex flex-col items-center gap-2 p-3 rounded-xl transition-colors hover:bg-accent cursor-pointer group",children:[xe,oe]}),e[51]=de,e[52]=he):he=e[52];let me;e[53]!==s||e[54]!==n||e[55]!==b.experimental_vibecode?(me=b.experimental_vibecode&&r.jsxs("button",{type:"button",onClick:()=>{se("agent_import_clicked",{source:"github"}),n(),s()},className:"flex flex-col items-center gap-2 p-3 rounded-xl transition-colors hover:bg-accent cursor-pointer group",children:[r.jsx("div",{className:"w-12 h-12 rounded-xl border-2 border-border flex items-center justify-center shrink-0 transition-transform group-hover:scale-105",children:r.jsx(uu,{className:"size-5 text-muted-foreground"})}),r.jsx("span",{className:"text-xs leading-tight text-center text-muted-foreground group-hover:text-foreground",children:"Import GitHub"})]}),e[53]=s,e[54]=n,e[55]=b.experimental_vibecode,e[56]=me):me=e[56];let fe;e[57]!==U?(fe=le=>r.jsx(rS,{agent:le,onClick:()=>U(le)},le.id),e[57]=U,e[58]=fe):fe=e[58],k=r.jsxs("div",{className:"grid grid-cols-3 gap-1",children:[ue,he,me,N.map(fe)]}),T=j.length>0&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"px-1 pt-4 pb-2",children:r.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"Agent templates"})}),r.jsx("div",{className:"grid grid-cols-3 gap-1",children:j.map(le=>r.jsxs("button",{type:"button",onClick:()=>{se("agent_template_clicked",{template_id:le.id,template_title:le.title}),te(le.id)},className:"flex flex-col items-center gap-2 p-3 rounded-xl transition-colors hover:bg-accent cursor-pointer group disabled:opacity-50 disabled:cursor-not-allowed",children:[r.jsx(zs,{icon:le.icon,name:le.title,size:"md",className:"transition-transform group-hover:scale-105"}),r.jsx("span",{className:"text-xs leading-tight text-center text-muted-foreground group-hover:text-foreground line-clamp-2 w-full",children:le.title})]},le.id))})]}),e[3]=u,e[4]=v,e[5]=x,e[6]=g,e[7]=C,e[8]=y,e[9]=s,e[10]=o,e[11]=n,e[12]=i,e[13]=a,e[14]=l,e[15]=p,e[16]=b.experimental_vibecode,e[17]=c,e[18]=j,e[19]=V,e[20]=w,e[21]=k,e[22]=T,e[23]=I,e[24]=A,e[25]=N}else j=e[18],V=e[19],w=e[20],k=e[21],T=e[22],I=e[23],A=e[24],N=e[25];let E;e[59]!==j||e[60]!==x||e[61]!==c||e[62]!==N.length?(E=N.length===0&&j.length===0&&!x&&r.jsx("div",{className:"flex items-center justify-center py-6 text-xs text-muted-foreground",children:c?"No agents found":"No agents yet"}),e[59]=j,e[60]=x,e[61]=c,e[62]=N.length,e[63]=E):E=e[63];let R;e[64]!==V||e[65]!==w||e[66]!==k||e[67]!==T||e[68]!==E?(R=r.jsxs("div",{className:V,children:[w,k,T,E]}),e[64]=V,e[65]=w,e[66]=k,e[67]=T,e[68]=E,e[69]=R):R=e[69];let M;e[70]!==h.slug?(M={org:h.slug},e[70]=h.slug,e[71]=M):M=e[71];let L;e[72]!==s?(L=()=>s(),e[72]=s,e[73]=L):L=e[73];let D;e[74]!==M||e[75]!==L?(D=r.jsx("div",{className:"border-t border-border px-3 py-2.5",children:r.jsx(Nh,{to:"/$org/settings/agents",params:M,onClick:L,className:"text-xs text-muted-foreground hover:text-foreground transition-colors flex items-center justify-center",children:"See all agents"})}),e[74]=M,e[75]=L,e[76]=D):D=e[76];let P;return e[77]!==R||e[78]!==D||e[79]!==I||e[80]!==A?(P=r.jsxs("div",{className:I,children:[A,R,D]}),e[77]=R,e[78]=D,e[79]=I,e[80]=A,e[81]=P):P=e[81],P}function oS(t){return t.id==="lean-canvas"}function aS(t){return t.id==="site-diagnostics"}function lS(t){return lg(t.id)}function cS(t){return!Mn(t.id)}function dS(t){return t.id}function hS(t){return t.pinned}function uS(){const t=B.c(27),[e,s]=S.useState(!1),[i,n]=S.useState(!1),[o,a]=S.useState(!1),[l,c]=S.useState(!1),[d,u]=S.useState(!1),[h,f]=S.useState(!1),m=Rs(),{setOpenMobile:p}=qr();let g;t[0]!==m||t[1]!==p?(g=()=>{s(!1),m&&p(!1)},t[0]=m,t[1]=p,t[2]=g):g=t[2];const _=g;let v;t[3]!==_||t[4]!==e?(v=e&&r.jsx(S.Suspense,{fallback:r.jsx("div",{className:"flex items-center justify-center py-8",children:r.jsx(Bi,{className:"h-4 w-24"})}),children:r.jsx(nS,{onClose:_,onOpenImportDeco:()=>n(!0),onOpenGithubImport:()=>{a(!0),_()},onOpenDiagnosticsModal:()=>c(!0),onOpenLeanCanvasModal:()=>u(!0),onOpenStudioPackModal:()=>f(!0)})}),t[3]=_,t[4]=e,t[5]=v):v=t[5];const x=v;let b;t[6]!==m||t[7]!==e||t[8]!==x?(b=m?r.jsxs(r.Fragment,{children:[r.jsx(Zt,{children:r.jsx(us,{tooltip:"Browse agents",className:"bg-muted/75 hover:bg-sidebar-accent",onClick:()=>{se("agent_browser_opened",{surface:"mobile_drawer"}),s(!0)},children:r.jsx(Qt,{className:"!opacity-100"})})}),r.jsx(Si,{open:e,onOpenChange:s,direction:"bottom",children:r.jsxs(yi,{className:"max-h-[85dvh] p-0",children:[r.jsx(bi,{className:"sr-only",children:"Browse agents"}),x]})})]}):r.jsxs(li,{open:e,onOpenChange:T=>{T&&!e&&se("agent_browser_opened",{surface:"desktop_popover"}),s(T)},children:[r.jsx(Zt,{children:r.jsx(oi,{asChild:!0,children:r.jsx(us,{tooltip:"Browse agents",className:"bg-muted/75 hover:bg-sidebar-accent",children:r.jsx(Qt,{className:"!opacity-100"})})})}),r.jsx(ai,{className:"w-[380px] p-0 overflow-hidden",side:"right",align:"start",children:x})]}),t[6]=m,t[7]=e,t[8]=x,t[9]=b):b=t[9];let y;t[10]!==i?(y=r.jsx(Bn,{open:i,onOpenChange:n}),t[10]=i,t[11]=y):y=t[11];let C;t[12]!==o?(C=r.jsx(u_,{open:o,onOpenChange:a}),t[12]=o,t[13]=C):C=t[13];let j;t[14]!==l?(j=r.jsx(hu,{open:l,onOpenChange:c}),t[14]=l,t[15]=j):j=t[15];let V;t[16]!==d?(V=r.jsx(f_,{open:d,onOpenChange:u}),t[16]=d,t[17]=V):V=t[17];let w;t[18]!==h?(w=r.jsx(m_,{open:h,onOpenChange:f}),t[18]=h,t[19]=w):w=t[19];let k;return t[20]!==b||t[21]!==y||t[22]!==C||t[23]!==j||t[24]!==V||t[25]!==w?(k=r.jsxs(r.Fragment,{children:[b,y,C,j,V,w]}),t[20]=b,t[21]=y,t[22]=C,t[23]=j,t[24]=V,t[25]=w,t[26]=k):k=t[26],k}function fS(){const t=B.c(34),e=oo(),{org:s}=be();let i;t[0]!==e?(i=e.filter(_S).map(gS),t[0]=e,t[1]=i):i=t[1];const n=i,{pinnedIds:o,unpin:a,reorder:l}=fu(s.id,n),c=new Map(e.map(pS)),d=o.map(D=>c.get(D)).filter(mS);let u;t[2]===Symbol.for("react.memo_cache_sentinel")?(u={activationConstraint:{distance:5}},t[2]=u):u=t[2];let h;t[3]===Symbol.for("react.memo_cache_sentinel")?(h={coordinateGetter:b2},t[3]=h):h=t[3];const f=Y0(Qc(Wl,u),Qc(Fl,h));let m;t[4]!==o||t[5]!==l?(m=D=>{const{active:P,over:O}=D;if(!O||P.id===O.id)return;const z=o.indexOf(P.id),$=o.indexOf(O.id);z===-1||$===-1||l(Ul([...o],z,$))},t[4]=o,t[5]=l,t[6]=m):m=t[6];const p=m,g=Ur,_="py-0 px-0 mt-2 flex-1 min-h-0";let v;t[7]===Symbol.for("react.memo_cache_sentinel")?(v=r.jsx("div",{className:"h-px bg-border mx-2 mb-2"}),t[7]=v):v=t[7];const x=Kr,b="flex flex-1 min-h-0 flex-col overflow-y-auto [scrollbar-width:none] [-ms-overflow-style:none] [&::-webkit-scrollbar]:hidden",y=gs,C="gap-2";let j;t[8]===Symbol.for("react.memo_cache_sentinel")?(j=r.jsx(uS,{}),t[8]=j):j=t[8];const V=Jy,w=J0,k=d2,T=l2;let I;t[9]!==s.slug||t[10]!==a?(I=D=>r.jsx(iS,{agent:D,org:s.slug,onUnpin:()=>a(D.id)},D.id),t[9]=s.slug,t[10]=a,t[11]=I):I=t[11];const A=d.map(I);let N;t[12]!==k||t[13]!==o||t[14]!==T||t[15]!==A?(N=r.jsx(k,{items:o,strategy:T,children:A}),t[12]=k,t[13]=o,t[14]=T,t[15]=A,t[16]=N):N=t[16];let E;t[17]!==V||t[18]!==p||t[19]!==f||t[20]!==N||t[21]!==w?(E=r.jsx(V,{sensors:f,collisionDetection:w,onDragEnd:p,children:N}),t[17]=V,t[18]=p,t[19]=f,t[20]=N,t[21]=w,t[22]=E):E=t[22];let R;t[23]!==y||t[24]!==E||t[25]!==j?(R=r.jsxs(y,{className:C,children:[j,E]}),t[23]=y,t[24]=E,t[25]=j,t[26]=R):R=t[26];let M;t[27]!==x||t[28]!==R?(M=r.jsx(x,{className:b,children:R}),t[27]=x,t[28]=R,t[29]=M):M=t[29];let L;return t[30]!==g||t[31]!==M||t[32]!==v?(L=r.jsxs(g,{className:_,children:[v,M]}),t[30]=g,t[31]=M,t[32]=v,t[33]=L):L=t[33],L}function mS(t){return!!t}function pS(t){return[t.id,t]}function gS(t){return t.id}function _S(t){return t.pinned}function Pf(){const t=B.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=r.jsx(S.Suspense,{fallback:r.jsx(Ur,{className:"py-0 px-0",children:r.jsx(Kr,{children:r.jsx(gs,{className:"gap-2",children:r.jsx(Zt,{children:r.jsxs("div",{className:"flex items-center gap-2 px-2 py-2",children:[r.jsx(Bi,{className:"h-4 w-4 rounded"}),r.jsx(Bi,{className:"h-4 flex-1"})]})})})})}),children:r.jsx(fS,{})}),t[0]=e):e=t[0],e}function xS(){const t=B.c(4),e=Xu();let s;t[0]===Symbol.for("react.memo_cache_sentinel")?(s=r.jsx(T0,{}),t[0]=s):s=t[0];let i;t[1]===Symbol.for("react.memo_cache_sentinel")?(i=r.jsx(Cs,{children:r.jsx(S.Suspense,{fallback:null,children:r.jsx(Pf,{})})}),t[1]=i):i=t[1];let n;return t[2]!==e?(n=r.jsx(Zu,{sections:e,footer:s,additionalContent:i}),t[2]=e,t[3]=n):n=t[3],n}function vS(t){const e=B.c(5),{onClose:s}=t,i=Xu();let n;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=r.jsx(D0,{}),e[0]=n):n=e[0];let o;e[1]===Symbol.for("react.memo_cache_sentinel")?(o=r.jsx(Cs,{children:r.jsx(S.Suspense,{fallback:null,children:r.jsx(Pf,{})})}),e[1]=o):o=e[1];let a;return e[2]!==s||e[3]!==i?(a=r.jsx(c0,{sections:i,onClose:s,footer:n,additionalContent:o}),e[2]=s,e[3]=i,e[4]=a):a=e[4],a}async function bS(t,e,s){const i=await t.callTool({name:e,arguments:s});if(i.isError){const n=i.content?.[0]?.text??`Tool ${e} failed without a message`;throw new Error(n)}return i}const Lf=["VM_START"],un=new Map,yS=t=>`${t.virtualMcpId}::${t.branch??""}`;function ql(t){const e=Mt();return Br({mutationKey:Lf,mutationFn:async s=>{const i=yS(s),n=un.get(i);if(n)return n;const o=(async()=>(await bS(t,"VM_START",s)).structuredContent)();un.set(i,o);try{return await o}finally{un.get(i)===o&&un.delete(i)}},onSuccess:()=>{bn(e)}})}function SS(t,e){const s=B.c(3);let i;return s[0]!==e||s[1]!==t?(i={mutationKey:Lf,predicate:o=>{if(!t)return!1;const a=o.state.variables;return!a||a.virtualMcpId!==t?!1:(a.branch??"")===(e??"")}},s[0]=e,s[1]=t,s[2]=i):i=s[2],$_(i)>0}function wS(t,e){return t===1?!0:t===0?!1:e}function VS(t){const e=t.entityMetadata?.defaultMainView??null,s=e==null||e.type==="chat",i=t.mainParamPresent?t.mainParamValue!=="0":!s,n=s?!0:t.entityMetadata?.chatDefaultOpen??!1;return{mainOpen:i,chatOpen:n}}function ud(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 CS(t,e){return t===1?!0:t===0?!1:e}function jS(t,e){const s=Ke(),i=vi({strict:!1}),n=$r({strict:!1}),o=Mt(),a=yu(),{locator:l}=be(),{virtualMcpId:c,orgSlug:d,isAgentRoute:u}=e,h=VS({entityMetadata:t,mainParamPresent:i.main!==void 0,mainParamValue:i.main}),f=CS(i.chat,h.chatOpen),m=h.mainOpen,p=S.useRef(crypto.randomUUID()),g=n.taskId??p.current,_="/$org/$taskId",v=T=>({org:d,taskId:T}),x=u?{virtualmcpid:c}:{},b=(T,I)=>{s({to:_,params:v(g),search:A=>({...A,...T}),replace:I?.replace??!1})},y=(T,I)=>{s({to:_,params:v(T),search:A=>{const N={};return I?N.virtualmcpid=I:u&&(N.virtualmcpid=c),A.tasks&&(N.tasks=A.tasks),N}})},C=()=>{m?b({main:"0"},{replace:!0}):b({main:Fp(t)},{replace:!0})},j=()=>{b({chat:f?0:1},{replace:!0})},V=()=>{f||b({chat:1},{replace:!0})},w=async()=>{const T=crypto.randomUUID(),I=Lh(o,l,g);try{await a.create.mutateAsync({id:T,virtual_mcp_id:c,...I?{branch:I}:{}})}catch{}s({to:_,params:v(T),search:A=>{const N={...x,chat:1};return A.tasks&&(N.tasks=A.tasks),N}})},k=T=>{b({main:T},{replace:!0})};return{taskId:g,mainOpen:m,chatOpen:f,mainParam:i.main,setTaskId:y,toggleMain:C,toggleChat:j,openChat:V,createNewTask:w,openTab:k}}const Gl=S.createContext(null);function kS(t){const e=B.c(15),{children:s}=t,i=Ke();let n;e[0]===Symbol.for("react.memo_cache_sentinel")?(n={strict:!1},e[0]=n):n=e[0];const o=vi(n);let a;e[1]===Symbol.for("react.memo_cache_sentinel")?(a={owner:"all",status:"open"},e[1]=a):a=e[1];const{tasks:l}=ia(a);let c;e[2]!==o.tasks||e[3]!==l.length?(c=()=>wS(o.tasks,l.length>0),e[2]=o.tasks,e[3]=l.length,e[4]=c):c=e[4];const[d,u]=S.useState(c);let h,f;e[5]!==i||e[6]!==d?(h=()=>{i({search:(v=>({...v,tasks:d?1:0})),replace:!0})},f=[d,i],e[5]=i,e[6]=d,e[7]=h,e[8]=f):(h=e[7],f=e[8]),S.useEffect(h,f);let m;e[9]===Symbol.for("react.memo_cache_sentinel")?(m=()=>u(NS),e[9]=m):m=e[9];const p=m;let g;e[10]!==d?(g={tasksOpen:d,toggleTasks:p},e[10]=d,e[11]=g):g=e[11];let _;return e[12]!==s||e[13]!==g?(_=r.jsx(Gl.Provider,{value:g,children:s}),e[12]=s,e[13]=g,e[14]=_):_=e[14],_}function NS(t){return!t}function Bf(){const t=S.useContext(Gl);if(!t)throw new Error("useTasksPanelState must be used inside <TasksPanelStateProvider>");return t}function AS(){return S.useContext(Gl)}const Of=S.createContext(null);function ci(){const t=S.use(Of);if(!t)throw new Error("Toolbar.* must be used inside <Toolbar>");return t}function ze(t){const e=B.c(10),{children:s}=t,[i,n]=S.useState(null),[o,a]=S.useState(null),[l,c]=S.useState(null),[d,u]=S.useState(null);let h;e[0]!==l||e[1]!==d||e[2]!==o||e[3]!==i?(h={togglesEl:i,setTogglesEl:n,tabsEl:o,setTabsEl:a,centerEl:l,setCenterEl:c,rightEl:d,setRightEl:u},e[0]=l,e[1]=d,e[2]=o,e[3]=i,e[4]=h):h=e[4];let f;e[5]!==s?(f=r.jsx("div",{className:"flex flex-col h-full min-h-0",children:s}),e[5]=s,e[6]=f):f=e[6];let m;return e[7]!==h||e[8]!==f?(m=r.jsx(Of,{value:h,children:f}),e[7]=h,e[8]=f,e[9]=m):m=e[9],m}function ES(t){const e=B.c(2),{children:s}=t;let i;return e[0]!==s?(i=r.jsx("div",{className:"shrink-0 grid grid-cols-3 items-center pl-1 pr-2 pt-0.25 h-12",children:s}),e[0]=s,e[1]=i):i=e[1],i}function IS(t){const e=B.c(2),{children:s}=t;let i;return e[0]!==s?(i=r.jsx("div",{className:"flex items-center gap-0.5 min-w-0 justify-self-start",children:s}),e[0]=s,e[1]=i):i=e[1],i}function RS(t){const e=B.c(2),{children:s}=t;let i;return e[0]!==s?(i=r.jsx("div",{className:"flex items-center justify-end gap-0.5 min-w-0 justify-self-end",children:s}),e[0]=s,e[1]=i):i=e[1],i}function TS(){const t=B.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=r.jsx("button",{type:"button",onClick:MS,className:"flex size-7 shrink-0 items-center justify-center rounded-md text-sidebar-foreground/60 hover:bg-sidebar-accent hover:text-sidebar-foreground transition-colors",title:"Go back",children:r.jsx(aa,{size:16})}),t[0]=e):e=t[0];let s;return t[1]===Symbol.for("react.memo_cache_sentinel")?(s=r.jsxs(r.Fragment,{children:[e,r.jsx("button",{type:"button",onClick:DS,className:"flex size-7 shrink-0 items-center justify-center rounded-md text-sidebar-foreground/60 hover:bg-sidebar-accent hover:text-sidebar-foreground transition-colors",title:"Go forward",children:r.jsx(Vl,{size:16})})]}),t[1]=s):s=t[1],s}function DS(){return window.history.forward()}function MS(){return window.history.back()}function PS(){const t=B.c(2),{setCenterEl:e}=ci();let s;return t[0]!==e?(s=r.jsx("div",{ref:e,className:"min-w-0 flex items-center justify-center gap-2"}),t[0]=e,t[1]=s):s=t[1],s}function LS(t){const e=B.c(3),{children:s}=t,{centerEl:i}=ci();if(!i)return null;let n;return e[0]!==i||e[1]!==s?(n=ds.createPortal(s,i),e[0]=i,e[1]=s,e[2]=n):n=e[2],n}function BS(){const t=B.c(2),{setTabsEl:e}=ci();let s;return t[0]!==e?(s=r.jsx("div",{ref:e,className:"shrink-0 flex items-center overflow-x-auto"}),t[0]=e,t[1]=s):s=t[1],s}function OS(t){const e=B.c(3),{children:s}=t,{tabsEl:i}=ci();if(!i)return null;let n;return e[0]!==s||e[1]!==i?(n=ds.createPortal(s,i),e[0]=s,e[1]=i,e[2]=n):n=e[2],n}function $S(){const t=B.c(2),{setTogglesEl:e}=ci();let s;return t[0]!==e?(s=r.jsx("div",{ref:e,className:"flex items-center gap-0.5 shrink-0 ml-0.5"}),t[0]=e,t[1]=s):s=t[1],s}function zS(t){const e=B.c(3),{children:s}=t,{togglesEl:i}=ci();if(!i)return null;let n;return e[0]!==s||e[1]!==i?(n=ds.createPortal(s,i),e[0]=s,e[1]=i,e[2]=n):n=e[2],n}function FS(){const t=B.c(2),{setRightEl:e}=ci();let s;return t[0]!==e?(s=r.jsx("div",{ref:e,className:"flex items-center justify-end gap-0.5 shrink-0"}),t[0]=e,t[1]=s):s=t[1],s}function HS(t){const e=B.c(3),{children:s}=t,{rightEl:i}=ci();if(!i)return null;let n;return e[0]!==s||e[1]!==i?(n=ds.createPortal(s,i),e[0]=s,e[1]=i,e[2]=n):n=e[2],n}ze.Header=ES;ze.LeftColumn=IS;ze.RightColumn=RS;ze.Nav=TS;ze.CenterSlot=PS;ze.Center=LS;ze.TabsSlot=BS;ze.Tabs=OS;ze.TogglesSlot=$S;ze.Toggles=zS;ze.RightSlot=FS;ze.Right=HS;const WS=280;function US(){const t=B.c(2),{tasksOpen:e}=Bf();if(!e)return null;let s;t[0]===Symbol.for("react.memo_cache_sentinel")?(s={width:`${WS}px`},t[0]=s):s=t[0];let i;return t[1]===Symbol.for("react.memo_cache_sentinel")?(i=r.jsx("aside",{className:"shrink-0 h-full bg-sidebar pb-1",style:s,children:r.jsx("div",{className:"h-full p-0.5 pt-0.25",children:r.jsx("div",{className:"h-full bg-background rounded-[0.75rem] overflow-hidden card-shadow",children:r.jsx(Yu,{})})})}),t[1]=i):i=t[1],i}function KS(){const t=B.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=r.jsx(S.Suspense,{fallback:null,children:r.jsx(US,{})}),t[0]=e):e=t[0],e}const qS={settings:Sg,automations:Hh,env:fl,preview:Zh,git:gr};function fd(t){const e=Fr(t);if(e.type==="icon"){const s=Hr(e.name);return s?{kind:"component",Component:s}:null}return e.type==="url"?{kind:"url",src:e.url}:null}function Po(t){if(t.kind==="system")return{kind:"component",Component:qS[t.tabId]};const e=fd(t.iconUrl);if(e)return e;if(!t.appId)return{kind:"fallback"};const s=t.connections.find(n=>n.id===t.appId);if(!s)return{kind:"fallback"};const i=fd(s.icon);return i||{kind:"fallback"}}function GS(t){const{org:e}=be(),s=Me({connectionId:Wt,orgId:e.id}),{data:i}=wh({queryKey:lt.threadMetadata(t),queryFn:async()=>{if(!s||!t)return null;try{const n=await s.callTool({name:"COLLECTION_THREADS_GET",arguments:{id:t}});return(n.structuredContent??n).item?.metadata??null}catch{return null}},staleTime:3e4});return i}function $f(t){const e=B.c(8),s=Ke();let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i={strict:!1},e[0]=i):i=e[0];const n=vi(i),o=ts(t.virtualMcpId),a=GS(t.taskId),{currentBranch:l}=es(),c=o?.metadata?.ui??null,d=c?.layout??null,u=d?.tabs??[],h=c?.pinnedViews??[],f=a?.expanded_tools??[],m=!!(o&&Fs(o));let p;e[1]===Symbol.for("react.memo_cache_sentinel")?(p={includeVirtual:!0},e[1]=p):p=e[1];const g=Wr(p),{activeTab:_,mainOpen:v}=Hp({mainParam:n.main,metadata:d?{defaultMainView:d.defaultMainView??null,tabs:u.map(YS)}:null}),x=Ih(_),b=[];m&&(b.push({id:"preview",title:"Preview"}),b.push({id:"env",title:"Terminal"}),b.push({id:"git",title:l??"git"})),b.push({id:"settings",title:"Settings"}),b.push({id:"automations",title:"Automations"});const y=new Map;for(const k of f){const T=ra(k.appId,k.toolName);y.set(T,{id:T,title:k.toolName,appId:k.appId,iconKey:k.toolName})}for(const k of h){const T=ra(k.connectionId,k.toolName);y.set(T,{id:T,title:k.label||k.toolName,appId:k.connectionId,iconKey:k.toolName,iconUrl:k.icon??null})}let C;e[2]!==g?(C=k=>({id:k.id,title:k.title,kind:"agent",icon:Po({tabId:k.id,kind:"agent",appId:k.view.appId,connections:g})}),e[2]=g,e[3]=C):C=e[3];const j=[...u.map(C),...Array.from(y.values()).map(k=>({id:k.id,title:k.title,kind:"expanded",icon:Po({tabId:k.iconKey,kind:"expanded",appId:k.appId,iconUrl:k.iconUrl,connections:g})})),...b.map(k=>({id:k.id,title:k.title,kind:"system",icon:Po({tabId:k.id,kind:"system",connections:g})}))];let V;return e[4]!==_||e[5]!==v||e[6]!==s?(V=k=>{const T=Wp({clickedId:k,activeTab:_,mainOpen:v});s({to:".",search:I=>({...I,main:T}),replace:!0})},e[4]=_,e[5]=v,e[6]=s,e[7]=V):V=e[7],{activeTab:_,mainOpen:v,setActiveTab:V,systemTabs:b,layoutTabs:u,expandedTools:f,automationTabParsed:x,tabs:j}}function YS(t){return{id:t.id}}function XS(t){const e=B.c(84),{value:s,onChange:i,onColorChange:n,name:o,size:a,className:l,avatarClassName:c,showHoverOverlay:d,disabled:u}=t,h=a===void 0?"lg":a,f=d===void 0?!0:d,m=u===void 0?!1:u,[p,g]=S.useState(!1),[_,v]=S.useState("icons"),[x,b]=S.useState(""),[y,C]=S.useState("blue");let j;e[0]!==s?(j=Fr(s),e[0]=s,e[1]=j):j=e[1];const V=j,w=V.type==="icon"||V.type==="url"&&V.color?V.color:y;let k;e[2]!==i||e[3]!==w?(k=ve=>{i(Co(ve,w))},e[2]=i,e[3]=w,e[4]=k):k=e[4];const T=k;let I;e[5]!==i||e[6]!==n||e[7]!==V.name||e[8]!==V.type||e[9]!==V.url?(I=ve=>{C(ve),n?.(ve),V.type==="icon"?i(Co(V.name,ve)):V.type==="url"&&i(pc(V.url,ve))},e[5]=i,e[6]=n,e[7]=V.name,e[8]=V.type,e[9]=V.url,e[10]=I):I=e[10];const A=I;let N;e[11]!==i||e[12]!==w?(N=ve=>{i(pc(ve,w)),g(!1)},e[11]=i,e[12]=w,e[13]=N):N=e[13];const E=N;let R;e[14]!==i||e[15]!==w?(R=()=>{const ve=gl(),Ce=ve[Math.floor(Math.random()*ve.length)];i(Co(Ce,w))},e[14]=i,e[15]=w,e[16]=R):R=e[16];const M=R;let L,D,P,O,z,$,W,F;if(e[17]!==l||e[18]!==m||e[19]!==p||e[20]!==h){const ve={xs:"rounded-md",sm:"rounded-lg","sm+":"rounded-xl",md:"rounded-xl",lg:"rounded-2xl",xl:"rounded-2xl"};D=li,$=m?!1:p,W=g,L=oi,z=!0,F="button",P=m,O=X("relative group overflow-hidden",m?"cursor-default opacity-50":"cursor-pointer",ve[h],l),e[17]=l,e[18]=m,e[19]=p,e[20]=h,e[21]=L,e[22]=D,e[23]=P,e[24]=O,e[25]=z,e[26]=$,e[27]=W,e[28]=F}else L=e[21],D=e[22],P=e[23],O=e[24],z=e[25],$=e[26],W=e[27],F=e[28];let G;e[29]!==c||e[30]!==o||e[31]!==h||e[32]!==s?(G=r.jsx(zs,{icon:s,name:o,size:h,className:c}),e[29]=c,e[30]=o,e[31]=h,e[32]=s,e[33]=G):G=e[33];let q;e[34]!==m||e[35]!==f?(q=f&&!m&&r.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/50 opacity-0 group-hover:opacity-100 transition-opacity",children:r.jsx(pl,{size:16,className:"text-white"})}),e[34]=m,e[35]=f,e[36]=q):q=e[36];let H;e[37]!==P||e[38]!==O||e[39]!==G||e[40]!==q||e[41]!==F?(H=r.jsxs("button",{type:F,disabled:P,className:O,children:[G,q]}),e[37]=P,e[38]=O,e[39]=G,e[40]=q,e[41]=F,e[42]=H):H=e[42];let ee;e[43]!==L||e[44]!==z||e[45]!==H?(ee=r.jsx(L,{asChild:z,children:H}),e[43]=L,e[44]=z,e[45]=H,e[46]=ee):ee=e[46];let K;e[47]!==o||e[48]!==s?(K=r.jsx("div",{className:"flex items-center justify-center py-4",children:r.jsx(zs,{icon:s,name:o,size:"xl"})}),e[47]=o,e[48]=s,e[49]=K):K=e[49];let U;e[50]===Symbol.for("react.memo_cache_sentinel")?(U=()=>v("icons"),e[50]=U):U=e[50];const te=_==="icons"?"border-foreground text-foreground":"border-transparent text-muted-foreground hover:text-foreground";let Y;e[51]!==te?(Y=X("px-3 py-2 text-sm font-medium border-b-2 -mb-px transition-colors",te),e[51]=te,e[52]=Y):Y=e[52];let J;e[53]!==Y?(J=r.jsx("button",{type:"button",onClick:U,className:Y,children:"Icons"}),e[53]=Y,e[54]=J):J=e[54];let ie;e[55]===Symbol.for("react.memo_cache_sentinel")?(ie=()=>v("upload"),e[55]=ie):ie=e[55];const ue=_==="upload"?"border-foreground text-foreground":"border-transparent text-muted-foreground hover:text-foreground";let de;e[56]!==ue?(de=X("px-3 py-2 text-sm font-medium border-b-2 -mb-px transition-colors",ue),e[56]=ue,e[57]=de):de=e[57];let xe;e[58]!==de?(xe=r.jsx("button",{type:"button",onClick:ie,className:de,children:"Upload"}),e[58]=de,e[59]=xe):xe=e[59];let oe;e[60]===Symbol.for("react.memo_cache_sentinel")?(oe=r.jsx("div",{className:"flex-1"}),e[60]=oe):oe=e[60];let he;e[61]!==J||e[62]!==xe?(he=r.jsxs("div",{className:"flex items-center border-b border-border px-3",children:[J,xe,oe]}),e[61]=J,e[62]=xe,e[63]=he):he=e[63];let me;e[64]!==A||e[65]!==M||e[66]!==T||e[67]!==E||e[68]!==V.name||e[69]!==V.type||e[70]!==x||e[71]!==w||e[72]!==_?(me=_==="icons"?r.jsx(ew,{search:x,onSearchChange:b,selectedColor:w,onColorChange:A,onSelectIcon:T,onRandom:M,currentIconName:V.type==="icon"?V.name:null}):r.jsx(tw,{onUpload:E}),e[64]=A,e[65]=M,e[66]=T,e[67]=E,e[68]=V.name,e[69]=V.type,e[70]=x,e[71]=w,e[72]=_,e[73]=me):me=e[73];let fe;e[74]!==K||e[75]!==he||e[76]!==me?(fe=r.jsx(ai,{align:"start",className:"w-80 p-0",onOpenAutoFocus:JS,children:r.jsxs("div",{className:"flex flex-col",children:[K,he,me]})}),e[74]=K,e[75]=he,e[76]=me,e[77]=fe):fe=e[77];let le;return e[78]!==D||e[79]!==$||e[80]!==W||e[81]!==ee||e[82]!==fe?(le=r.jsxs(D,{open:$,onOpenChange:W,children:[ee,fe]}),e[78]=D,e[79]=$,e[80]=W,e[81]=ee,e[82]=fe,e[83]=le):le=e[83],le}function JS(t){return t.preventDefault()}function QS(t){const e=B.c(27),{selectedColor:s,onColorChange:i}=t,[n,o]=S.useState(!1);let a,l,c,d,u,h,f;if(e[0]!==n||e[1]!==s){const x=Wh(s);l=li,h=n,f=o,a=oi,u=!0,c="button",d=X("h-6 w-6 rounded-full shrink-0 ring-2 ring-offset-2 ring-offset-background transition-all cursor-pointer hover:scale-110",x.dot,"ring-foreground/20"),e[0]=n,e[1]=s,e[2]=a,e[3]=l,e[4]=c,e[5]=d,e[6]=u,e[7]=h,e[8]=f}else a=e[2],l=e[3],c=e[4],d=e[5],u=e[6],h=e[7],f=e[8];let m;e[9]!==c||e[10]!==d?(m=r.jsx("button",{type:c,className:d,title:"Change color"}),e[9]=c,e[10]=d,e[11]=m):m=e[11];let p;e[12]!==a||e[13]!==u||e[14]!==m?(p=r.jsx(a,{asChild:u,children:m}),e[12]=a,e[13]=u,e[14]=m,e[15]=p):p=e[15];let g;e[16]!==i||e[17]!==s?(g=Vg.map(x=>r.jsx("button",{type:"button",onClick:()=>{i(x.name),o(!1)},className:X("h-5 w-5 rounded-full transition-all shrink-0 cursor-pointer",x.dot,s===x.name?"ring-2 ring-offset-1 ring-offset-background ring-foreground/30 scale-110":"hover:scale-110"),title:x.name},x.name)),e[16]=i,e[17]=s,e[18]=g):g=e[18];let _;e[19]!==g?(_=r.jsx(ai,{align:"start",side:"right",sideOffset:8,className:"w-auto p-2",onOpenAutoFocus:ZS,children:r.jsx("div",{className:"grid grid-cols-4 gap-1",children:g})}),e[19]=g,e[20]=_):_=e[20];let v;return e[21]!==l||e[22]!==h||e[23]!==f||e[24]!==p||e[25]!==_?(v=r.jsxs(l,{open:h,onOpenChange:f,children:[p,_]}),e[21]=l,e[22]=h,e[23]=f,e[24]=p,e[25]=_,e[26]=v):v=e[26],v}function ZS(t){return t.preventDefault()}function ew(t){const e=B.c(44),{search:s,onSearchChange:i,selectedColor:n,onColorChange:o,onSelectIcon:a,onRandom:l,currentIconName:c}=t;let d,u,h,f,m,p,g;if(e[0]!==c||e[1]!==o||e[2]!==l||e[3]!==i||e[4]!==a||e[5]!==s||e[6]!==n){const y=gl(),C=Wh(n);u=s.trim()?y.filter(A=>{const N=oa(A),E=s.toLowerCase();return N.includes(E)||A.toLowerCase().includes(E)}):y,p="flex flex-col";let j;e[14]===Symbol.for("react.memo_cache_sentinel")?(j=r.jsx(vl,{size:14,className:"absolute left-2 top-1/2 -translate-y-1/2 text-muted-foreground pointer-events-none"}),e[14]=j):j=e[14];let V;e[15]!==i?(V=A=>i(A.target.value),e[15]=i,e[16]=V):V=e[16];let w;e[17]!==s||e[18]!==V?(w=r.jsxs("div",{className:"relative flex-1",children:[j,r.jsx(bt,{value:s,onChange:V,placeholder:"Filter...",className:"h-8 text-xs pl-7"})]}),e[17]=s,e[18]=V,e[19]=w):w=e[19];let k;e[20]===Symbol.for("react.memo_cache_sentinel")?(k=r.jsx(wg,{size:14,className:"text-muted-foreground"}),e[20]=k):k=e[20];let T;e[21]!==l?(T=r.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:k}),e[21]=l,e[22]=T):T=e[22];let I;e[23]!==o||e[24]!==n?(I=r.jsx(QS,{selectedColor:n,onColorChange:o}),e[23]=o,e[24]=n,e[25]=I):I=e[25],e[26]!==T||e[27]!==I||e[28]!==w?(g=r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2",children:[w,T,I]}),e[26]=T,e[27]=I,e[28]=w,e[29]=g):g=e[29],d=Rh,m="h-56",h="grid grid-cols-9 gap-0.5 px-2 pb-2",f=u.map(A=>{const N=Hr(A);return N?r.jsx("button",{type:"button",onClick:()=>a(A),className:X("h-8 w-8 flex items-center justify-center rounded-md transition-colors cursor-pointer",c===A?X(C.bg,C.text):X(C.text,"hover:bg-accent")),title:A,children:r.jsx(N,{size:18})},A):null}),e[0]=c,e[1]=o,e[2]=l,e[3]=i,e[4]=a,e[5]=s,e[6]=n,e[7]=d,e[8]=u,e[9]=h,e[10]=f,e[11]=m,e[12]=p,e[13]=g}else d=e[7],u=e[8],h=e[9],f=e[10],m=e[11],p=e[12],g=e[13];let _;e[30]!==h||e[31]!==f?(_=r.jsx("div",{className:h,children:f}),e[30]=h,e[31]=f,e[32]=_):_=e[32];let v;e[33]!==u.length?(v=u.length===0&&r.jsx("div",{className:"flex items-center justify-center py-8 text-sm text-muted-foreground",children:"No icons found"}),e[33]=u.length,e[34]=v):v=e[34];let x;e[35]!==d||e[36]!==m||e[37]!==_||e[38]!==v?(x=r.jsxs(d,{className:m,children:[_,v]}),e[35]=d,e[36]=m,e[37]=_,e[38]=v,e[39]=x):x=e[39];let b;return e[40]!==p||e[41]!==g||e[42]!==x?(b=r.jsxs("div",{className:p,children:[g,x]}),e[40]=p,e[41]=g,e[42]=x,e[43]=b):b=e[43],b}function tw(t){const e=B.c(27),{onUpload:s}=t,i=S.useRef(null);let n;e[0]!==s?(n=j=>{const V=j.target.files?.[0];if(!V)return;if(V.size>2097152){ge.error("Image must be smaller than 2MB"),j.target.value="";return}const w=new FileReader;w.onerror=()=>{ge.error("Failed to read image file"),i.current&&(i.current.value="")},w.onloadend=()=>{w.readyState===FileReader.DONE&&w.result&&s(w.result),i.current&&(i.current.value="")},w.readAsDataURL(V)},e[0]=s,e[1]=n):n=e[1];const o=n,[a,l]=S.useState("");let c;e[2]!==s||e[3]!==a?(c=()=>{const j=a.trim();j&&(s(j),l(""))},e[2]=s,e[3]=a,e[4]=c):c=e[4];const d=c;let u;e[5]!==o?(u=r.jsx("input",{type:"file",ref:i,className:"hidden",accept:"image/*",onChange:o}),e[5]=o,e[6]=u):u=e[6];let h;e[7]===Symbol.for("react.memo_cache_sentinel")?(h=()=>i.current?.click(),e[7]=h):h=e[7];let f;e[8]===Symbol.for("react.memo_cache_sentinel")?(f=r.jsxs("button",{type:"button",onClick:h,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:[r.jsx(Qh,{size:20}),r.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=r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-xs text-muted-foreground",children:"or"}),r.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=j=>l(j.target.value),e[10]=p):p=e[10];let g;e[11]!==d?(g=j=>{j.key==="Enter"&&(j.preventDefault(),d())},e[11]=d,e[12]=g):g=e[12];let _;e[13]!==a||e[14]!==g?(_=r.jsx(bt,{value:a,onChange:p,placeholder:"Paste image URL...",className:"h-8 text-xs flex-1",onKeyDown:g}),e[13]=a,e[14]=g,e[15]=_):_=e[15];let v;e[16]!==a?(v=a.trim(),e[16]=a,e[17]=v):v=e[17];const x=!v;let b;e[18]!==d||e[19]!==x?(b=r.jsx(ne,{variant:"outline",size:"sm",className:"h-8 px-3 text-xs shrink-0",onClick:d,disabled:x,children:"Apply"}),e[18]=d,e[19]=x,e[20]=b):b=e[20];let y;e[21]!==b||e[22]!==_?(y=r.jsxs("div",{className:"flex items-center gap-1.5",children:[_,b]}),e[21]=b,e[22]=_,e[23]=y):y=e[23];let C;return e[24]!==y||e[25]!==u?(C=r.jsxs("div",{className:"flex flex-col gap-3 p-4",children:[u,f,m,y]}),e[24]=y,e[25]=u,e[26]=C):C=e[26],C}function sw(t){const e=B.c(5),{value:s}=t;let i;if(e[0]!==s){i=Symbol.for("react.early_return_sentinel");e:{const o=Fr(s);if(o.type==="icon"){const a=Hr(o.name);if(a){let l;e[2]!==a?(l=r.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 n;return e[4]===Symbol.for("react.memo_cache_sentinel")?(n=r.jsx(pu,{size:16,className:"text-muted-foreground"}),e[4]=n):n=e[4],n}function iw(t){const e=B.c(66),{value:s,onChange:i,className:n,disabled:o}=t,[a,l]=S.useState(!1),[c,d]=S.useState("");let u;e[0]!==s?(u=Fr(s),e[0]=s,e[1]=u):u=e[1];const h=u,f=h.type==="icon"?h.name:null;let m,p,g,_,v,x,b,y,C,j,V,w,k,T,I;if(e[2]!==n||e[3]!==f||e[4]!==o||e[5]!==i||e[6]!==a||e[7]!==c||e[8]!==s){const D=gl();_=c.trim()?D.filter(G=>{const q=c.toLowerCase();return oa(G).includes(q)||G.toLowerCase().includes(q)}):D,g=li,v=o?!1:a,x=l;const P=o?"cursor-default opacity-50":"cursor-pointer hover:bg-accent";let O;e[24]!==n||e[25]!==P?(O=X("size-7 shrink-0 rounded-md transition-colors flex items-center justify-center",P,n),e[24]=n,e[25]=P,e[26]=O):O=e[26];let z;e[27]!==s?(z=r.jsx(sw,{value:s}),e[27]=s,e[28]=z):z=e[28],e[29]!==o||e[30]!==O||e[31]!==z?(b=r.jsx(oi,{asChild:!0,children:r.jsx("button",{type:"button",disabled:o,className:O,children:z})}),e[29]=o,e[30]=O,e[31]=z,e[32]=b):b=e[32],p=ai,k="start",T="w-64 p-0",I=rw,V="flex flex-col";let $;e[33]===Symbol.for("react.memo_cache_sentinel")?($=r.jsx(vl,{size:14,className:"absolute left-2 top-1/2 -translate-y-1/2 text-muted-foreground pointer-events-none"}),e[33]=$):$=e[33];let W;e[34]===Symbol.for("react.memo_cache_sentinel")?(W=G=>d(G.target.value),e[34]=W):W=e[34],e[35]!==c?(w=r.jsx("div",{className:"px-2 py-2",children:r.jsxs("div",{className:"relative",children:[$,r.jsx(bt,{value:c,onChange:W,placeholder:"Filter...",className:"h-7 text-xs pl-7"})]})}),e[35]=c,e[36]=w):w=e[36],m=Rh,j="h-48",y="grid grid-cols-8 gap-0.5 px-2 pb-2";let F;e[37]!==f||e[38]!==i?(F=G=>{const q=Hr(G);return q?r.jsx("button",{type:"button",onClick:()=>{i(`icon://${G}`),l(!1)},className:X("h-7 w-7 flex items-center justify-center rounded-md transition-colors cursor-pointer",f===G?"bg-accent text-foreground":"text-muted-foreground hover:bg-accent hover:text-foreground"),title:oa(G),children:r.jsx(q,{size:16})},G):null},e[37]=f,e[38]=i,e[39]=F):F=e[39],C=_.map(F),e[2]=n,e[3]=f,e[4]=o,e[5]=i,e[6]=a,e[7]=c,e[8]=s,e[9]=m,e[10]=p,e[11]=g,e[12]=_,e[13]=v,e[14]=x,e[15]=b,e[16]=y,e[17]=C,e[18]=j,e[19]=V,e[20]=w,e[21]=k,e[22]=T,e[23]=I}else m=e[9],p=e[10],g=e[11],_=e[12],v=e[13],x=e[14],b=e[15],y=e[16],C=e[17],j=e[18],V=e[19],w=e[20],k=e[21],T=e[22],I=e[23];let A;e[40]!==y||e[41]!==C?(A=r.jsx("div",{className:y,children:C}),e[40]=y,e[41]=C,e[42]=A):A=e[42];let N;e[43]!==_.length?(N=_.length===0&&r.jsx("div",{className:"flex items-center justify-center py-6 text-xs text-muted-foreground",children:"No icons found"}),e[43]=_.length,e[44]=N):N=e[44];let E;e[45]!==m||e[46]!==A||e[47]!==N||e[48]!==j?(E=r.jsxs(m,{className:j,children:[A,N]}),e[45]=m,e[46]=A,e[47]=N,e[48]=j,e[49]=E):E=e[49];let R;e[50]!==E||e[51]!==V||e[52]!==w?(R=r.jsxs("div",{className:V,children:[w,E]}),e[50]=E,e[51]=V,e[52]=w,e[53]=R):R=e[53];let M;e[54]!==p||e[55]!==R||e[56]!==k||e[57]!==T||e[58]!==I?(M=r.jsx(p,{align:k,className:T,onOpenAutoFocus:I,children:R}),e[54]=p,e[55]=R,e[56]=k,e[57]=T,e[58]=I,e[59]=M):M=e[59];let L;return e[60]!==g||e[61]!==v||e[62]!==x||e[63]!==b||e[64]!==M?(L=r.jsxs(g,{open:v,onOpenChange:x,children:[b,M]}),e[60]=g,e[61]=v,e[62]=x,e[63]=b,e[64]=M,e[65]=L):L=e[65],L}function rw(t){return t.preventDefault()}function Nn(){const t=B.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=r.jsx("div",{className:"flex items-center justify-center h-32",children:r.jsx(Ee,{className:"animate-spin text-muted-foreground",size:24})}),t[0]=e):e=t[0],e}function Lo(t){return({error:e})=>e?.message?.includes("Method not found")||e?.code===-32601?r.jsx("div",{className:"flex-1 overflow-auto px-4 py-3 space-y-1",children:r.jsx("div",{className:"flex items-center justify-center h-32 text-sm text-muted-foreground",children:t})}):r.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center h-full p-6 text-center space-y-4",children:[r.jsx("div",{className:"bg-destructive/10 p-3 rounded-full",children:r.jsx(yh,{className:"h-6 w-6 text-destructive"})}),r.jsxs("div",{className:"space-y-2",children:[r.jsx("h3",{className:"text-lg font-medium",children:"Something went wrong"}),r.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 nw(t){const e=B.c(23),{item:s,isSelected:i,onToggle:n,disabled:o}=t,a=o?"cursor-not-allowed opacity-50":"cursor-pointer",l=i?"bg-accent/25":"hover:bg-muted/50";let c;e[0]!==a||e[1]!==l?(c=X("flex items-start gap-3 p-4 rounded-lg transition-colors",a,l),e[0]=a,e[1]=l,e[2]=c):c=e[2];let d;e[3]!==s.name?(d=r.jsx("p",{className:"text-sm font-medium leading-none truncate",children:s.name}),e[3]=s.name,e[4]=d):d=e[4];let u;e[5]!==s.tags?(u=s.tags&&r.jsx("span",{className:"shrink-0",children:s.tags}),e[5]=s.tags,e[6]=u):u=e[6];let h;e[7]!==d||e[8]!==u?(h=r.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[d,u]}),e[7]=d,e[8]=u,e[9]=h):h=e[9];let f;e[10]!==s.description?(f=s.description&&r.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]!==h||e[13]!==f?(m=r.jsxs("div",{className:"flex-1 min-w-0 space-y-2",children:[h,f]}),e[12]=h,e[13]=f,e[14]=m):m=e[14];let p;e[15]!==o||e[16]!==i||e[17]!==n?(p=r.jsx(I_,{checked:i,onCheckedChange:n,disabled:o,className:"mt-0.5"}),e[15]=o,e[16]=i,e[17]=n,e[18]=p):p=e[18];let g;return e[19]!==c||e[20]!==m||e[21]!==p?(g=r.jsxs("label",{className:c,children:[m,p]}),e[19]=c,e[20]=m,e[21]=p,e[22]=g):g=e[22],g}function Yl(t){const e=B.c(13),{items:s,selections:i,onToggle:n,emptyMessage:o,disabled:a}=t;let l,c,d;if(e[0]!==a||e[1]!==o||e[2]!==s||e[3]!==n||e[4]!==i){d=Symbol.for("react.early_return_sentinel");e:{const h=s.map(ow);if(s.length===0){let f;e[8]!==o?(f=r.jsx("div",{className:"flex-1 overflow-auto px-4 py-3 space-y-1",children:r.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],d=f;break e}l="flex-1 overflow-auto px-4 py-3 space-y-1",c=s.map(f=>r.jsx(nw,{item:f,isSelected:i===null||i?.includes(f.id),onToggle:()=>n(f.id,h),disabled:a},f.id))}e[0]=a,e[1]=o,e[2]=s,e[3]=n,e[4]=i,e[5]=l,e[6]=c,e[7]=d}else l=e[5],c=e[6],d=e[7];if(d!==Symbol.for("react.early_return_sentinel"))return d;let u;return e[10]!==l||e[11]!==c?(u=r.jsx("div",{className:l,children:c}),e[10]=l,e[11]=c,e[12]=u):u=e[12],u}function ow(t){return t.id}function aw(t){const e=B.c(12),{connectionId:s,selections:i,onToggle:n,disabled:o}=t,{org:a}=be();let l;e[0]!==s||e[1]!==a.id?(l={connectionId:s,orgId:a.id},e[0]=s,e[1]=a.id,e[2]=l):l=e[2];const c=Me(l);let d;e[3]!==c?(d={client:c},e[3]=c,e[4]=d):d=e[4];const{data:u}=g_(d);let h;e[5]!==u.tools?(h=u.tools.map(lw),e[5]=u.tools,e[6]=h):h=e[6];const f=h;let m;return e[7]!==o||e[8]!==f||e[9]!==n||e[10]!==i?(m=r.jsx(Yl,{items:f,selections:i,onToggle:n,emptyMessage:"No tools available",disabled:o}),e[7]=o,e[8]=f,e[9]=n,e[10]=i,e[11]=m):m=e[11],m}function lw(t){return{id:t.name,name:t.name,description:t.description,tags:r.jsx(A_,{annotations:t.annotations,_meta:t._meta})}}function cw(t){const e=B.c(12),{connectionId:s,selections:i,onToggle:n,disabled:o}=t,{org:a}=be();let l;e[0]!==s||e[1]!==a.id?(l={connectionId:s,orgId:a.id},e[0]=s,e[1]=a.id,e[2]=l):l=e[2];const c=Me(l);let d;e[3]!==c?(d={client:c},e[3]=c,e[4]=d):d=e[4];const{data:u}=Gg(d);let h;e[5]!==u.resources?(h=u.resources.map(dw),e[5]=u.resources,e[6]=h):h=e[6];const f=h;let m;return e[7]!==o||e[8]!==f||e[9]!==n||e[10]!==i?(m=r.jsx(Yl,{items:f,selections:i,onToggle:n,emptyMessage:"No resources available",disabled:o}),e[7]=o,e[8]=f,e[9]=n,e[10]=i,e[11]=m):m=e[11],m}function dw(t){return{id:t.name||t.uri,name:t.name||t.uri,description:t.description}}function hw(t){const e=B.c(12),{connectionId:s,selections:i,onToggle:n,disabled:o}=t,{org:a}=be();let l;e[0]!==s||e[1]!==a.id?(l={connectionId:s,orgId:a.id},e[0]=s,e[1]=a.id,e[2]=l):l=e[2];const c=Me(l);let d;e[3]!==c?(d={client:c},e[3]=c,e[4]=d):d=e[4];const{data:u}=Dh(d);let h;e[5]!==u.prompts?(h=u.prompts.map(uw),e[5]=u.prompts,e[6]=h):h=e[6];const f=h;let m;return e[7]!==o||e[8]!==f||e[9]!==n||e[10]!==i?(m=r.jsx(Yl,{items:f,selections:i,onToggle:n,emptyMessage:"No prompts available",disabled:o}),e[7]=o,e[8]=f,e[9]=n,e[10]=i,e[11]=m):m=e[11],m}function uw(t){return{id:t.name,name:t.name,description:t.description}}function fw(t){const e=B.c(54),{currentConnection:s,activeTab:i,selectedId:n,formData:o,toggleTool:a,toggleResource:l,togglePrompt:c,toggleAllTools:d,toggleAllResources:u,toggleAllPrompts:h,onTabChange:f}=t,m=o[n],p=i==="tools"?m?.tools===null:i==="resources"?m?.resources===null:m?.prompts===null;let g;e[0]!==i||e[1]!==n||e[2]!==h||e[3]!==u||e[4]!==d?(g=()=>{i==="tools"?d(n):i==="resources"?u(n):h(n)},e[0]=i,e[1]=n,e[2]=h,e[3]=u,e[4]=d,e[5]=g):g=e[5];const _=g;let v;e[6]!==s.icon||e[7]!==s.title?(v=r.jsx(Ms,{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 x;e[9]!==s.title?(x=r.jsx("h2",{className:"text-base font-semibold truncate",children:s.title}),e[9]=s.title,e[10]=x):x=e[10];let b;e[11]!==s.description?(b=s.description&&r.jsx("p",{className:"text-xs text-muted-foreground truncate",children:s.description}),e[11]=s.description,e[12]=b):b=e[12];let y;e[13]!==x||e[14]!==b?(y=r.jsxs("div",{className:"flex-1 min-w-0",children:[x,b]}),e[13]=x,e[14]=b,e[15]=y):y=e[15];let C;e[16]!==v||e[17]!==y?(C=r.jsx("div",{className:"px-6 pt-5 pb-4 shrink-0",children:r.jsxs("div",{className:"flex items-center gap-3",children:[v,y]})}),e[16]=v,e[17]=y,e[18]=C):C=e[18];let j;e[19]===Symbol.for("react.memo_cache_sentinel")?(j=[{id:"tools",label:"Tools"},{id:"resources",label:"Resources"},{id:"prompts",label:"Prompts"}],e[19]=j):j=e[19];let V;e[20]!==f?(V=L=>f(L),e[20]=f,e[21]=V):V=e[21];let w;e[22]!==i||e[23]!==V?(w=r.jsx(cu,{tabs:j,activeTab:i,onTabChange:V}),e[22]=i,e[23]=V,e[24]=w):w=e[24];const k=p?"Deselect all":"Select all";let T;e[25]!==_||e[26]!==k?(T=r.jsx("button",{type:"button",onClick:_,className:"text-xs text-muted-foreground hover:text-foreground transition-colors",children:k}),e[25]=_,e[26]=k,e[27]=T):T=e[27];let I;e[28]!==T||e[29]!==w?(I=r.jsxs("div",{className:"flex items-center justify-between px-6 py-3 border-t border-border shrink-0",children:[w,T]}),e[28]=T,e[29]=w,e[30]=I):I=e[30];let A;e[31]!==i||e[32]!==o||e[33]!==n||e[34]!==a?(A=i==="tools"&&r.jsx(Cs,{fallback:Lo("Tools not supported by this server"),children:r.jsx(S.Suspense,{fallback:r.jsx(Nn,{}),children:r.jsx(aw,{connectionId:n,selections:o[n]?o[n].tools:[],onToggle:(L,D)=>a(n,L,D)})})}),e[31]=i,e[32]=o,e[33]=n,e[34]=a,e[35]=A):A=e[35];let N;e[36]!==i||e[37]!==o||e[38]!==n||e[39]!==l?(N=i==="resources"&&r.jsx(Cs,{fallback:Lo("Resources not supported by this server"),children:r.jsx(S.Suspense,{fallback:r.jsx(Nn,{}),children:r.jsx(cw,{connectionId:n,selections:o[n]?o[n].resources:[],onToggle:(L,D)=>l(n,L,D)})})}),e[36]=i,e[37]=o,e[38]=n,e[39]=l,e[40]=N):N=e[40];let E;e[41]!==i||e[42]!==o||e[43]!==n||e[44]!==c?(E=i==="prompts"&&r.jsx(Cs,{fallback:Lo("Prompts not supported by this server"),children:r.jsx(S.Suspense,{fallback:r.jsx(Nn,{}),children:r.jsx(hw,{connectionId:n,selections:o[n]?o[n].prompts:[],onToggle:(L,D)=>c(n,L,D)})})}),e[41]=i,e[42]=o,e[43]=n,e[44]=c,e[45]=E):E=e[45];let R;e[46]!==A||e[47]!==N||e[48]!==E?(R=r.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[A,N,E]}),e[46]=A,e[47]=N,e[48]=E,e[49]=R):R=e[49];let M;return e[50]!==I||e[51]!==R||e[52]!==C?(M=r.jsxs(r.Fragment,{children:[C,I,R]}),e[50]=I,e[51]=R,e[52]=C,e[53]=M):M=e[53],M}function mw(t){const e=B.c(11),{connectionId:s,onAuthenticate:i,children:n}=t;let o;e[0]!==s?(o={connectionId:s},e[0]=s,e[1]=o):o=e[1];const a=Su(o);if(a.supportsOAuth&&!a.isAuthenticated){let d;e[2]===Symbol.for("react.memo_cache_sentinel")?(d=r.jsx("div",{className:"flex items-center justify-center size-12 rounded-full bg-muted",children:r.jsx(Cg,{size:22,className:"text-muted-foreground"})}),e[2]=d):d=e[2];let u;e[3]===Symbol.for("react.memo_cache_sentinel")?(u=r.jsxs("div",{className:"space-y-1",children:[r.jsx("p",{className:"text-sm font-medium",children:"Authorization required"}),r.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]=u):u=e[3];let h;e[4]!==s||e[5]!==i?(h=i&&r.jsx(ne,{variant:"outline",size:"sm",onClick:()=>i(s),children:"Authorize"}),e[4]=s,e[5]=i,e[6]=h):h=e[6];let f;return e[7]!==h?(f=r.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-4 p-8 text-center",children:[d,u,h]}),e[7]=h,e[8]=f):f=e[8],f}let c;return e[9]!==n?(c=r.jsx(r.Fragment,{children:n}),e[9]=n,e[10]=c):c=e[10],c}function pw(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 md(t){return Object.entries(t).map(([e,s])=>({connection_id:e,selected_tools:s.tools,selected_resources:s.resources,selected_prompts:s.prompts}))}function gw(t,e){return e.type==="SET_ACTIVE_TAB"?{...t,activeTab:e.payload}:t}function _w(t){const e=B.c(49),{open:s,onOpenChange:i,selectedId:n,form:o,connections:a,onAuthenticate:l}=t;let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c={activeTab:"tools"},e[0]=c):c=e[0];const[d,u]=S.useReducer(gw,c),h=wl(n??"");let f;e[1]!==a?(f=a??[],e[1]=a,e[2]=f):f=e[2];let m;e[3]!==f?(m=pw(f),e[3]=f,e[4]=m):m=e[4];const p=m;let g;e[5]!==o||e[6]!==p?(g=($,W,F,G)=>{const q=p[$]?.[W];let H;q===null?H=G.filter(K=>K!==F):q?.includes(F)?H=q.filter(K=>K!==F):(H=[...q??[],F],H.length===G.length&&(H=null));const ee={...p};ee[$]?ee[$]={...ee[$]}:ee[$]={tools:null,resources:null,prompts:null},ee[$][W]=H,o.setValue("connections",md(ee),{shouldDirty:!0,shouldTouch:!0})},e[5]=o,e[6]=p,e[7]=g):g=e[7];const _=g;let v;e[8]!==o||e[9]!==p?(v=($,W)=>{const G=p[$]?.[W]===null?[]:null,q={...p};q[$]?q[$]={...q[$]}:q[$]={tools:null,resources:null,prompts:null},q[$][W]=G,o.setValue("connections",md(q),{shouldDirty:!0,shouldTouch:!0})},e[8]=o,e[9]=p,e[10]=v):v=e[10];const x=v;let b;e[11]!==_?(b=($,W,F)=>_($,"tools",W,F),e[11]=_,e[12]=b):b=e[12];const y=b;let C;e[13]!==_?(C=($,W,F)=>_($,"resources",W,F),e[13]=_,e[14]=C):C=e[14];const j=C;let V;e[15]!==_?(V=($,W,F)=>_($,"prompts",W,F),e[15]=_,e[16]=V):V=e[16];const w=V;let k;e[17]!==x?(k=$=>x($,"tools"),e[17]=x,e[18]=k):k=e[18];const T=k;let I;e[19]!==x?(I=$=>x($,"resources"),e[19]=x,e[20]=I):I=e[20];const A=I;let N;e[21]!==x?(N=$=>x($,"prompts"),e[21]=x,e[22]=N):N=e[22];const E=N;if(!n||!h)return null;let R;e[23]===Symbol.for("react.memo_cache_sentinel")?(R=r.jsx(Nn,{}),e[23]=R):R=e[23];let M;e[24]===Symbol.for("react.memo_cache_sentinel")?(M=$=>u({type:"SET_ACTIVE_TAB",payload:$}),e[24]=M):M=e[24];let L;e[25]!==h||e[26]!==d.activeTab||e[27]!==p||e[28]!==n||e[29]!==E||e[30]!==A||e[31]!==T||e[32]!==w||e[33]!==j||e[34]!==y?(L=r.jsx(fw,{currentConnection:h,activeTab:d.activeTab,selectedId:n,formData:p,toggleTool:y,toggleResource:j,togglePrompt:w,toggleAllTools:T,toggleAllResources:A,toggleAllPrompts:E,onTabChange:M},n),e[25]=h,e[26]=d.activeTab,e[27]=p,e[28]=n,e[29]=E,e[30]=A,e[31]=T,e[32]=w,e[33]=j,e[34]=y,e[35]=L):L=e[35];let D;e[36]!==l||e[37]!==n||e[38]!==L?(D=r.jsx(S.Suspense,{fallback:R,children:r.jsx(mw,{connectionId:n,onAuthenticate:l,children:L})}),e[36]=l,e[37]=n,e[38]=L,e[39]=D):D=e[39];let P;e[40]!==i?(P=r.jsx(cl,{className:"px-6 py-4 border-t border-border shrink-0",children:r.jsx(ne,{variant:"outline",onClick:()=>i(!1),children:"Done"})}),e[40]=i,e[41]=P):P=e[41];let O;e[42]!==D||e[43]!==P?(O=r.jsxs(ms,{className:"sm:max-w-2xl h-[75vh] max-h-[75vh] flex flex-col p-0 gap-0 overflow-hidden w-[95vw]",children:[D,P]}),e[42]=D,e[43]=P,e[44]=O):O=e[44];let z;return e[45]!==i||e[46]!==s||e[47]!==O?(z=r.jsx(ps,{open:s,onOpenChange:i,children:O}),e[45]=i,e[46]=s,e[47]=O,e[48]=z):z=e[48],z}const Bo={tools:null,resources:null,prompts:null},xw=Vp.pick({status:!0,title:!0,description:!0,icon:!0,metadata:!0,connections:!0});function vw(t){const s=new TextEncoder().encode(t),i=Array.from(s,n=>String.fromCharCode(n)).join("");return btoa(i)}function bw(t){const e=B.c(11),{url:s,agentId:i}=t,[n,o]=S.useState(!1);let a;e[0]!==i||e[1]!==s?(a=async()=>{se("agent_connect_action",{agent_id:i,action:"copy_url"}),await navigator.clipboard.writeText(s),o(!0),ge.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 c;e[3]!==n?(c=n?r.jsx(Jt,{size:20,className:"text-green-600"}):r.jsx(Li,{size:20}),e[3]=n,e[4]=c):c=e[4];const d=n?"Copied!":"Copy URL";let u;e[5]!==d?(u=r.jsx("span",{className:"text-xs font-medium",children:d}),e[5]=d,e[6]=u):u=e[6];let h;return e[7]!==l||e[8]!==c||e[9]!==u?(h=r.jsxs(ne,{type:"button",variant:"outline",onClick:l,className:"h-auto py-3 px-4 flex flex-col items-center gap-2",children:[c,u]}),e[7]=l,e[8]=c,e[9]=u,e[10]=h):h=e[10],h}function yw(t){const e=B.c(8),{url:s,serverName:i,agentId:n}=t;let o;e[0]!==n||e[1]!==i||e[2]!==s?(o=()=>{se("agent_connect_action",{agent_id:n,action:"install_cursor"});const u=ou(i),f=vw(JSON.stringify({type:"http",url:s,headers:{"x-mesh-client":"Cursor"}},null,2)),m=`cursor://anysphere.cursor-deeplink/mcp/install?name=${encodeURIComponent(u)}&config=${encodeURIComponent(f)}`;window.open(m,"_blank"),ge.success("Opening Cursor...")},e[0]=n,e[1]=i,e[2]=s,e[3]=o):o=e[3];const a=o;let l,c;e[4]===Symbol.for("react.memo_cache_sentinel")?(l=r.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%)"}}),c=r.jsx("span",{className:"text-xs font-medium",children:"Install on Cursor"}),e[4]=l,e[5]=c):(l=e[4],c=e[5]);let d;return e[6]!==a?(d=r.jsxs(ne,{type:"button",variant:"outline",onClick:a,className:"h-auto py-3 px-4 flex flex-col items-center gap-2",children:[l,c]}),e[6]=a,e[7]=d):d=e[7],d}function Sw(t){const e=B.c(12),{url:s,serverName:i,agentId:n}=t,[o,a]=S.useState(!1);let l;e[0]!==n||e[1]!==i||e[2]!==s?(l=async()=>{se("agent_connect_action",{agent_id:n,action:"install_claude_code"});const m=ou(i),g=JSON.stringify({type:"http",url:s,headers:{"x-mesh-client":"Claude Code"}},null,2),_=`claude mcp add-json "${m}" '${g.replace(/'/g,"'\\''")}' --scope user`;await navigator.clipboard.writeText(_),a(!0),ge.success("Claude Code command copied to clipboard"),setTimeout(()=>a(!1),2e3)},e[0]=n,e[1]=i,e[2]=s,e[3]=l):l=e[3];const c=l;let d;e[4]!==o?(d=o?r.jsx(Jt,{size:20,className:"text-green-600"}):r.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]=d):d=e[5];const u=o?"Copied!":"Install on Claude Code";let h;e[6]!==u?(h=r.jsx("span",{className:"text-xs font-medium",children:u}),e[6]=u,e[7]=h):h=e[7];let f;return e[8]!==c||e[9]!==d||e[10]!==h?(f=r.jsxs(ne,{type:"button",variant:"outline",onClick:c,className:"h-auto py-3 px-4 flex flex-col items-center gap-2",children:[d,h]}),e[8]=c,e[9]=d,e[10]=h,e[11]=f):f=e[11],f}function ww({virtualMcp:t}){const{org:e}=be(),s=Me({connectionId:Wt,orgId:e.id}),[i,n]=S.useState(null),[o,a]=S.useState(!1),[l,c]=S.useState(!1),d=t.id,u=t.title||`agent-${d.slice(0,8)}`,h=i?`bunx @decocms/typegen@latest --mcp ${d} --key ${i} --output client.ts`:`bunx @decocms/typegen@latest --mcp ${d} --key <api-key> --output client.ts`,f=async()=>{a(!0);try{const g=(await s.callTool({name:"API_KEY_CREATE",arguments:{name:`typegen-${u}`,permissions:{[d]:["*"]}}})).structuredContent?.key;if(!g)throw new Error("No key in response");n(g),se("agent_typegen_key_generated",{agent_id:d})}catch{se("agent_typegen_key_failed",{agent_id:d}),ge.error("Failed to generate API key")}finally{a(!1)}},m=async()=>{se("agent_connect_action",{agent_id:d,action:"typegen_copy_command",has_api_key:!!i}),await navigator.clipboard.writeText(h),c(!0),ge.success("Command copied to clipboard"),setTimeout(()=>c(!1),2e3)};return r.jsxs("div",{className:"flex min-w-0 flex-col gap-3",children:[r.jsxs("div",{className:"flex items-start justify-between gap-3",children:[r.jsxs("div",{className:"flex flex-col gap-0.5",children:[r.jsx("h4",{className:"text-sm font-medium text-foreground",children:"Generate typed client"}),r.jsxs("p",{className:"text-xs text-muted-foreground",children:["Introspects this agent and writes a typed"," ",r.jsx("code",{className:"font-mono",children:"client.ts"})," you can import directly."]})]}),!i&&r.jsxs(ne,{type:"button",variant:"outline",size:"sm",className:"shrink-0 gap-1.5",onClick:f,disabled:o,children:[o?r.jsx(Ee,{size:14,className:"animate-spin"}):r.jsx(Dg,{size:14}),r.jsx("span",{children:o?"Generating…":"Generate API key"})]})]}),i&&r.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."}),r.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"Generate client"}),r.jsx("div",{className:"rounded-md border border-input bg-muted/50 px-3 py-2.5",children:r.jsxs("div",{className:"flex items-start gap-2",children:[r.jsx("code",{className:"min-w-0 flex-1 break-all font-mono text-xs text-muted-foreground",children:h}),r.jsx(ne,{type:"button",variant:"ghost",size:"icon",className:"size-6 shrink-0",onClick:m,children:l?r.jsx(Jt,{size:12,className:"text-green-600"}):r.jsx(Li,{size:12})})]})}),r.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"Runtime variables"}),r.jsx(Vw,{apiKey:i,agentId:d})]})}function Vw(t){const e=B.c(21),{apiKey:s,agentId:i}=t,[n,o]=S.useState(!1),a=window.location.origin,l=s?`MESH_API_KEY=${s}`:"MESH_API_KEY=<api-key>",c=`MESH_BASE_URL=${a}`,d=`${l}
264
- ${c}`;let u;e[0]!==i||e[1]!==s||e[2]!==d?(u=async()=>{se("agent_connect_action",{agent_id:i,action:"typegen_copy_env",has_api_key:!!s}),await navigator.clipboard.writeText(d),o(!0),setTimeout(()=>o(!1),2e3)},e[0]=i,e[1]=s,e[2]=d,e[3]=u):u=e[3];const h=u,f=!s;let m;e[4]!==f?(m=X({"opacity-50":f}),e[4]=f,e[5]=m):m=e[5];let p;e[6]!==l||e[7]!==m?(p=r.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")?(g=r.jsx("br",{}),_=r.jsx("span",{children:c}),e[9]=g,e[10]=_):(g=e[9],_=e[10]);let v;e[11]!==p?(v=r.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 x;e[13]!==n?(x=n?r.jsx(Jt,{size:12,className:"text-green-600"}):r.jsx(Li,{size:12}),e[13]=n,e[14]=x):x=e[14];let b;e[15]!==h||e[16]!==x?(b=r.jsx(ne,{type:"button",variant:"ghost",size:"icon",className:"size-6 shrink-0",onClick:h,children:x}),e[15]=h,e[16]=x,e[17]=b):b=e[17];let y;return e[18]!==v||e[19]!==b?(y=r.jsx("div",{className:"rounded-md border border-input bg-muted/50 px-3 py-2.5",children:r.jsxs("div",{className:"flex items-start gap-2",children:[v,b]})}),e[18]=v,e[19]=b,e[20]=y):y=e[20],y}function Cw(t){const e=B.c(3),{virtualMcp:s}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=r.jsx("div",{className:"h-20 animate-pulse rounded-md bg-muted"}),e[0]=i):i=e[0];let n;return e[1]!==s?(n=r.jsx(S.Suspense,{fallback:i,children:r.jsx(ww,{virtualMcp:s})}),e[1]=s,e[2]=n):n=e[2],n}function jw(t){const e=B.c(37),{open:s,onOpenChange:i,virtualMcp:n}=t,o=`/mcp/virtual-mcp/${n.id}`;let a;e[0]!==o?(a=new URL(o,window.location.origin),e[0]=o,e[1]=a):a=e[1];const l=a;let c;e[2]!==n.id||e[3]!==n.title?(c=n.title||`agent-${n.id?.slice(0,8)??"default"}`,e[2]=n.id,e[3]=n.title,e[4]=c):c=e[4];const d=c,u=Rs();let h;e[5]!==n.id||e[6]!==l.href?(h=r.jsx(bw,{url:l.href,agentId:n.id}),e[5]=n.id,e[6]=l.href,e[7]=h):h=e[7];let f,m;e[8]!==d||e[9]!==n.id||e[10]!==l.href?(f=r.jsx(yw,{url:l.href,serverName:d,agentId:n.id}),m=r.jsx(Sw,{url:l.href,serverName:d,agentId:n.id}),e[8]=d,e[9]=n.id,e[10]=l.href,e[11]=f,e[12]=m):(f=e[11],m=e[12]);let p;e[13]!==h||e[14]!==f||e[15]!==m?(p=r.jsx("div",{className:"flex flex-col gap-3 pt-2",children:r.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[h,f,m]})}),e[13]=h,e[14]=f,e[15]=m,e[16]=p):p=e[16];let g;e[17]===Symbol.for("react.memo_cache_sentinel")?(g=r.jsx("div",{className:"border-t border-border"}),e[17]=g):g=e[17];let _;e[18]!==n?(_=r.jsx(Cw,{virtualMcp:n}),e[18]=n,e[19]=_):_=e[19];let v;e[20]!==p||e[21]!==_?(v=r.jsxs("div",{className:"flex flex-col gap-6",children:[p,g,_]}),e[20]=p,e[21]=_,e[22]=v):v=e[22];const x=v;if(u){let j;e[23]===Symbol.for("react.memo_cache_sentinel")?(j=r.jsx(bi,{className:"mt-4 mb-4 text-base font-semibold",children:"Connect"}),e[23]=j):j=e[23];let V;e[24]!==x?(V=r.jsx(yi,{children:r.jsxs("div",{className:"flex-1 overflow-y-auto px-4 pb-6 [touch-action:pan-y]",children:[j,x]})}),e[24]=x,e[25]=V):V=e[25];let w;return e[26]!==i||e[27]!==s||e[28]!==V?(w=r.jsx(Si,{open:s,onOpenChange:i,children:V}),e[26]=i,e[27]=s,e[28]=V,e[29]=w):w=e[29],w}let b;e[30]===Symbol.for("react.memo_cache_sentinel")?(b=r.jsx(Ds,{children:r.jsx(Ts,{children:"Connect"})}),e[30]=b):b=e[30];let y;e[31]!==x?(y=r.jsxs(ms,{className:"max-h-[80vh] overflow-y-auto sm:max-w-2xl",children:[b,x]}),e[31]=x,e[32]=y):y=e[32];let C;return e[33]!==i||e[34]!==s||e[35]!==y?(C=r.jsx(ps,{open:s,onOpenChange:i,children:y}),e[33]=i,e[34]=s,e[35]=y,e[36]=C):C=e[36],C}function kw(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 Nw(t){const e=B.c(22),{connection_id:s,usedConnectionIds:i,onOpenSettings:n,onRemove:o,onAuthenticate:a,onSwitchInstance:l,onNewInstance:c}=t,d=wl(s),{org:u}=be();if(!d)return null;let h;e[0]!==d?(h=nu(d),e[0]=d,e[1]=h):h=e[1];const f=h;let m;e[2]!==s?(m=r.jsx(Rw,{connection_id:s}),e[2]=s,e[3]=m):m=e[3];let p;e[4]!==d.app_name||e[5]!==d.connection_type||e[6]!==d.description||e[7]!==d.icon||e[8]!==d.title||e[9]!==s||e[10]!==a||e[11]!==c||e[12]!==n||e[13]!==o||e[14]!==l||e[15]!==u.slug||e[16]!==f||e[17]!==i?(p=r.jsx(Iw,{connection_id:s,connectionTitle:d.title,connectionDescription:d.description,connectionIcon:d.icon,connectionType:d.connection_type,slug:f,orgSlug:u.slug,appName:d.app_name,usedConnectionIds:i,onOpenSettings:n,onRemove:o,onAuthenticate:a,onSwitchInstance:l,onNewInstance:c}),e[4]=d.app_name,e[5]=d.connection_type,e[6]=d.description,e[7]=d.icon,e[8]=d.title,e[9]=s,e[10]=a,e[11]=c,e[12]=n,e[13]=o,e[14]=l,e[15]=u.slug,e[16]=f,e[17]=i,e[18]=p):p=e[18];let g;return e[19]!==m||e[20]!==p?(g=r.jsx(S.Suspense,{fallback:m,children:p}),e[19]=m,e[20]=p,e[21]=g):g=e[21],g}const pd="__new_instance__";async function Aw(t,e){const s=t?.idToken??null;if(s){const n=gd(s);if(n)return n}const i=t?.userinfoEndpoint??null;if(i)try{const n=await fetch(i,{headers:{Authorization:`Bearer ${e}`}});if(n.ok){const o=await n.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 gd(e)}function gd(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 Ew(t){const e=B.c(23),{appName:s,connectionId:i,usedConnectionIds:n,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 c=Wr(l);if(c.length<=1)return null;let d;e[2]!==i||e[3]!==a||e[4]!==o?(d=g=>{g===pd?a?.():o(i,g)},e[2]=i,e[3]=a,e[4]=o,e[5]=d):d=e[5];let u;e[6]===Symbol.for("react.memo_cache_sentinel")?(u=r.jsx(Zs,{size:"sm",className:"w-auto text-xs gap-1 px-2 shadow-none",children:r.jsx(ei,{})}),e[6]=u):u=e[6];let h;if(e[7]!==i||e[8]!==c||e[9]!==n){let g;e[11]!==i||e[12]!==n?(g=_=>r.jsx(Ht,{value:_.id,className:"text-xs",disabled:_.id!==i&&n.has(_.id),children:_.title},_.id),e[11]=i,e[12]=n,e[13]=g):g=e[13],h=c.map(g),e[7]=i,e[8]=c,e[9]=n,e[10]=h}else h=e[10];let f;e[14]!==a?(f=a&&r.jsx(Ht,{value:pd,className:"text-xs text-muted-foreground",children:"+ New instance"}),e[14]=a,e[15]=f):f=e[15];let m;e[16]!==h||e[17]!==f?(m=r.jsxs(Js,{children:[h,f]}),e[16]=h,e[17]=f,e[18]=m):m=e[18];let p;return e[19]!==i||e[20]!==d||e[21]!==m?(p=r.jsxs(Qs,{value:i,onValueChange:d,children:[u,m]}),e[19]=i,e[20]=d,e[21]=m,e[22]=p):p=e[22],p}function Iw(t){const e=B.c(55),{connection_id:s,connectionTitle:i,connectionDescription:n,connectionIcon:o,connectionType:a,slug:l,orgSlug:c,appName:d,usedConnectionIds:u,onOpenSettings:h,onRemove:f,onAuthenticate:m,onSwitchInstance:p,onNewInstance:g}=t;let _;e[0]!==s?(_={connectionId:s},e[0]=s,e[1]=_):_=e[1];const v=Su(_),b=!(a==="VIRTUAL")&&v.supportsOAuth&&!v.isAuthenticated,y=b?"border-destructive/50 bg-destructive/5":"border-border";let C;e[2]!==y?(C=X("rounded-xl border overflow-hidden transition-colors",y),e[2]=y,e[3]=C):C=e[3];let j;e[4]!==c||e[5]!==l?(j={org:c,appSlug:l},e[4]=c,e[5]=l,e[6]=j):j=e[6];let V;e[7]!==o||e[8]!==i?(V=r.jsx(Ms,{icon:o,name:i,size:"sm",className:"shrink-0"}),e[7]=o,e[8]=i,e[9]=V):V=e[9];let w;e[10]!==i?(w=r.jsx("p",{className:"text-sm font-medium truncate",children:i}),e[10]=i,e[11]=w):w=e[11];let k;e[12]!==n||e[13]!==b?(k=b?r.jsx("span",{className:"text-xs text-destructive font-medium",children:"Needs authorization"}):n&&r.jsx("p",{className:"text-xs text-muted-foreground truncate",children:n}),e[12]=n,e[13]=b,e[14]=k):k=e[14];let T;e[15]!==w||e[16]!==k?(T=r.jsxs("div",{className:"flex-1 min-w-0",children:[w,k]}),e[15]=w,e[16]=k,e[17]=T):T=e[17];let I;e[18]!==s||e[19]!==b||e[20]!==m?(I=b?r.jsx(ne,{variant:"outline",size:"sm",className:"h-7 text-xs shrink-0",onClick:G=>{G.preventDefault(),G.stopPropagation(),m(s)},children:"Authorize"}):r.jsxs(it,{delayDuration:0,children:[r.jsx(tt,{asChild:!0,children:r.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:r.jsx(Gr,{size:16})})}),r.jsx(st,{side:"bottom",children:"Connection settings"})]}),e[18]=s,e[19]=b,e[20]=m,e[21]=I):I=e[21];let A;e[22]!==j||e[23]!==V||e[24]!==T||e[25]!==I?(A=r.jsxs(Nh,{to:"/$org/settings/connections/$appSlug",params:j,className:"flex items-center gap-3 px-4 py-3 cursor-pointer hover:bg-muted/50 transition-colors",children:[V,T,I]}),e[22]=j,e[23]=V,e[24]=T,e[25]=I,e[26]=A):A=e[26];let N;e[27]!==d||e[28]!==s||e[29]!==g||e[30]!==p||e[31]!==u?(N=d&&r.jsx(Ew,{appName:d,connectionId:s,usedConnectionIds:u,onSwitchInstance:p,onNewInstance:g}),e[27]=d,e[28]=s,e[29]=g,e[30]=p,e[31]=u,e[32]=N):N=e[32];let E;e[33]===Symbol.for("react.memo_cache_sentinel")?(E=r.jsx(zh,{size:13}),e[33]=E):E=e[33];let R;e[34]!==h?(R=r.jsx(tt,{asChild:!0,children:r.jsx(ne,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:h,"aria-label":"Configure resources",children:E})}),e[34]=h,e[35]=R):R=e[35];let M;e[36]===Symbol.for("react.memo_cache_sentinel")?(M=r.jsx(st,{side:"bottom",children:"Configure resources"}),e[36]=M):M=e[36];let L;e[37]!==R?(L=r.jsxs(it,{delayDuration:0,children:[R,M]}),e[37]=R,e[38]=L):L=e[38];let D;e[39]===Symbol.for("react.memo_cache_sentinel")?(D=r.jsx(ii,{size:13}),e[39]=D):D=e[39];let P;e[40]!==f?(P=r.jsx(tt,{asChild:!0,children:r.jsx(ne,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-destructive",onClick:f,"aria-label":"Remove connection",children:D})}),e[40]=f,e[41]=P):P=e[41];let O;e[42]===Symbol.for("react.memo_cache_sentinel")?(O=r.jsx(st,{side:"bottom",children:"Remove"}),e[42]=O):O=e[42];let z;e[43]!==P?(z=r.jsxs(it,{delayDuration:0,children:[P,O]}),e[43]=P,e[44]=z):z=e[44];let $;e[45]!==L||e[46]!==z?($=r.jsxs("div",{className:"flex items-center gap-0.5 ml-auto",children:[L,z]}),e[45]=L,e[46]=z,e[47]=$):$=e[47];let W;e[48]!==N||e[49]!==$?(W=r.jsxs("div",{className:"flex items-center gap-3 px-4 py-2 border-t border-border bg-muted/25",children:[N,$]}),e[48]=N,e[49]=$,e[50]=W):W=e[50];let F;return e[51]!==A||e[52]!==W||e[53]!==C?(F=r.jsxs("div",{className:C,children:[A,W]}),e[51]=A,e[52]=W,e[53]=C,e[54]=F):F=e[54],F}function Rw(t){const e=B.c(17),{connection_id:s}=t,i=wl(s);if(!i){let h;return e[0]===Symbol.for("react.memo_cache_sentinel")?(h=r.jsx(zf,{}),e[0]=h):h=e[0],h}let n;e[1]!==i.icon||e[2]!==i.title?(n=r.jsx(Ms,{icon:i.icon,name:i.title,size:"sm",className:"shrink-0"}),e[1]=i.icon,e[2]=i.title,e[3]=n):n=e[3];let o;e[4]!==i.title?(o=r.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&&r.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=r.jsxs("div",{className:"flex-1 min-w-0",children:[o,a]}),e[8]=o,e[9]=a,e[10]=l):l=e[10];let c;e[11]!==n||e[12]!==l?(c=r.jsxs("div",{className:"flex items-center gap-3 px-4 py-3",children:[n,l]}),e[11]=n,e[12]=l,e[13]=c):c=e[13];let d;e[14]===Symbol.for("react.memo_cache_sentinel")?(d=r.jsx("div",{className:"flex items-center px-4 py-2 border-t border-border bg-muted/25",children:r.jsx("div",{className:"h-5 w-20 rounded bg-muted animate-pulse"})}),e[14]=d):d=e[14];let u;return e[15]!==c?(u=r.jsxs("div",{className:"rounded-xl border border-border overflow-hidden",children:[c,d]}),e[15]=c,e[16]=u):u=e[16],u}function zf(){const t=B.c(3);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=r.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=r.jsxs("div",{className:"flex items-center gap-3 px-4 py-3",children:[e,r.jsxs("div",{className:"flex-1 space-y-1.5",children:[r.jsx("div",{className:"h-4 w-32 rounded bg-muted animate-pulse"}),r.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=r.jsxs("div",{className:"rounded-xl border border-border overflow-hidden",children:[s,r.jsx("div",{className:"flex items-center px-4 py-2 border-t border-border bg-muted/25",children:r.jsx("div",{className:"h-5 w-20 rounded bg-muted animate-pulse"})})]}),t[2]=i):i=t[2],i}function Tw({virtualMcpId:t}){const{org:e}=be(),s=Me({connectionId:Wt,orgId:e.id}),i=Mt(),n=ts(t),o=(n?.connections??[]).map(P=>P.connection_id).sort(),{data:a}=Fi({queryKey:lt.projectConnectionDetails(t,o),enabled:o.length>0,queryFn:async()=>await Promise.all(o.map(async O=>{try{const z=await s.callTool({name:"COLLECTION_CONNECTIONS_GET",arguments:{id:O}}),{item:$}=ko(z),W=($?.tools??[]).filter(F=>!!Yg(F._meta)).map(F=>({name:F.name,description:F.description}));return{fetchOk:!0,id:O,title:$?.title??O,icon:$?.icon??null,uiTools:W}}catch{return{fetchOk:!1,id:O,title:O,icon:null,uiTools:[]}}}))}),l=(a??[]).filter(P=>P.uiTools.length>0),c=new Set(Up),d=n?.metadata?.ui,u=d?.pinnedViews??[],h=d?.layout?.defaultMainView??null,f=d?.layout?.chatDefaultOpen??!1,m=!h||h.type==="chat"?"chat":h.type==="settings"?"layout":c.has(h.type)?h.type:`${h.type}:${h.id??""}:${h.toolName??""}`,[p,g]=S.useState(u),[_,v]=S.useState(m),[x,b]=S.useState(f),[y,C]=S.useState(!1),j=P=>{const[O,z,$]=P.split(":");return O?O==="chat"?{type:O}:c.has(O)?{type:O}:O==="ext-apps"&&z?{type:"ext-apps",id:z,toolName:$||void 0}:null:null},V=S.useRef(!1);if(a&&a.length>0&&!V.current){V.current=!0;const P=new Set((a??[]).filter($=>$.fetchOk).map($=>$.id)),O=new Set(l.flatMap($=>$.uiTools.map(W=>`${$.id}:${W.name}`))),z=u.filter($=>!P.has($.connectionId)||O.has(`${$.connectionId}:${$.toolName}`));if(z.length!==u.length){g(z);let $=_;h?.type==="ext-apps"&&!z.some(W=>W.connectionId===h.id&&W.toolName===h.toolName)&&($="chat",v($)),s.callTool({name:"VIRTUAL_MCP_PINNED_VIEWS_UPDATE",arguments:{virtualMcpId:t,pinnedViews:z,layout:{defaultMainView:j($),chatDefaultOpen:x}}}).then(W=>{ko(W),i.invalidateQueries({predicate:F=>Array.isArray(F.queryKey)&&F.queryKey.includes("collection")&&F.queryKey.includes("VIRTUAL_MCP")})}).catch(()=>{g(u),v(m)})}}const w=(P,O,z)=>{C(!0),(async()=>{try{const W=await s.callTool({name:"VIRTUAL_MCP_PINNED_VIEWS_UPDATE",arguments:{virtualMcpId:t,pinnedViews:P,layout:{defaultMainView:j(O),chatDefaultOpen:z??x}}});ko(W),i.invalidateQueries({predicate:F=>Array.isArray(F.queryKey)&&F.queryKey.includes("collection")&&F.queryKey.includes("VIRTUAL_MCP")}),ge.success("Layout updated")}catch(W){ge.error("Failed to update layout: "+(W instanceof Error?W.message:"Unknown error"))}finally{C(!1)}})()},k=(P,O)=>{const z=p.some(F=>F.connectionId===P&&F.toolName===O);let $,W=_;if(z){$=p.filter(G=>!(G.connectionId===P&&G.toolName===O));const F=`ext-apps:${P}:${O}`;_===F&&(W="chat",v(W))}else $=[...p,{connectionId:P,toolName:O,label:O.replace(/_/g," "),icon:null}];g($),w($,W)},T=(P,O,z)=>{g($=>$.map(W=>W.connectionId===P&&W.toolName===O?{...W,label:z}:W))},I=()=>{w(p,_)},A=(P,O,z)=>{g(W=>W.map(F=>F.connectionId===P&&F.toolName===O?{...F,icon:z}:F));const $=p.map(W=>W.connectionId===P&&W.toolName===O?{...W,icon:z}:W);w($,_)},N=P=>{v(P),w(p,P)},E=o.length===0,R=a&&l.length===0,M=!!Fs(n),L=[{value:"chat",label:"Chat"},{value:"instructions",label:"Instructions"},{value:"connections",label:"Connections"},{value:"layout",label:"Layout"}];M&&(L.push({value:"env",label:"Terminal"}),L.push({value:"preview",label:"Preview"}));for(const P of p)L.push({value:`ext-apps:${P.connectionId}:${P.toolName}`,label:P.label||P.toolName});const D=l.length>0||E||R;return r.jsxs("div",{className:"flex flex-col gap-3",children:[r.jsx("div",{className:"flex items-center justify-between gap-3",children:r.jsx("h2",{className:"text-sm font-medium text-foreground",children:"Layout"})}),r.jsxs(E_,{className:"p-6 gap-5",children:[r.jsxs(Cc,{className:"p-0 space-y-5",children:[r.jsxs("div",{className:"flex items-center justify-between gap-4",children:[r.jsxs("div",{className:"space-y-0.5 min-w-0",children:[r.jsx(vr,{className:"font-normal text-foreground",children:"Main view"}),r.jsx("p",{className:"text-xs text-muted-foreground",children:"What users see when they first open this agent."})]}),r.jsxs(Qs,{value:_,onValueChange:N,children:[r.jsx(Zs,{className:"w-44 h-8 text-sm capitalize shrink-0",children:r.jsx(ei,{})}),r.jsx(Js,{children:L.map(P=>r.jsx(Ht,{value:P.value,className:"capitalize",children:P.label},P.value))})]})]}),r.jsxs("div",{className:"flex items-center justify-between gap-4",children:[r.jsxs("div",{className:"space-y-0.5 min-w-0",children:[r.jsx(vr,{className:"font-normal text-foreground",children:"Show chat"}),r.jsx("p",{className:"text-xs text-muted-foreground",children:"Display the chat panel alongside the main view."})]}),r.jsxs(it,{delayDuration:0,children:[r.jsx(tt,{asChild:!0,children:r.jsx("span",{className:"shrink-0",children:r.jsx(da,{checked:_==="chat"?!0:x,disabled:_==="chat"||y,onCheckedChange:P=>{b(P),w(p,_,P)}})})}),_==="chat"&&r.jsx(st,{side:"top",children:"Chat is always shown when it is the default view"})]})]})]}),D&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"border-t border-border -mx-6"}),r.jsxs(Cc,{className:"p-0 space-y-3",children:[r.jsx("div",{className:"flex items-center justify-between gap-4",children:r.jsxs("div",{className:"space-y-0.5 min-w-0",children:[r.jsx(vr,{className:"font-normal text-foreground",children:"Pinned views"}),r.jsx("p",{className:"text-xs text-muted-foreground",children:"Surface interactive tools as top-level tabs in the agent."})]})}),E&&r.jsx("p",{className:"text-xs text-muted-foreground",children:"Add a connection above to configure pinned views."}),R&&!E&&r.jsx("p",{className:"text-xs text-muted-foreground",children:"None of the connected servers expose interactive tools."}),l.length>0&&r.jsx("div",{className:"space-y-4 pt-1",children:l.map((P,O)=>r.jsxs("div",{children:[O>0&&r.jsx("div",{className:"border-t border-border -mx-6 mb-4"}),r.jsxs("div",{className:"flex items-center gap-2 mb-2.5",children:[r.jsx(Ms,{icon:P.icon,name:P.title,size:"xs",className:"shrink-0"}),r.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:P.title})]}),r.jsx("div",{className:"space-y-1.5",children:P.uiTools.map(z=>{const $=p.some(F=>F.connectionId===P.id&&F.toolName===z.name),W=p.find(F=>F.connectionId===P.id&&F.toolName===z.name);return r.jsxs("div",{className:X("flex items-center justify-between gap-3 px-3 py-2 rounded-lg border transition-colors",$?"bg-accent/40 border-border":"bg-transparent border-border"),children:[r.jsxs("div",{className:"min-w-0 flex-1 flex items-center gap-2",children:[r.jsx(iw,{value:W?.icon??null,onChange:F=>A(P.id,z.name,F),disabled:!$||y}),r.jsx(bt,{value:$&&W?W.label:z.name.replace(/_/g," "),onChange:F=>T(P.id,z.name,F.target.value),onBlur:I,className:"h-7 text-sm w-40 capitalize",disabled:!$||y,readOnly:!$})]}),r.jsx(da,{checked:$,onCheckedChange:()=>k(P.id,z.name),disabled:y})]},z.name)})})]},P.id))})]})]})]})]})}function Dw({virtualMcp:t,hideOwnTitle:e}){const{org:s}=be(),i=yl(),n=Sl(),o=Mt(),a=Me({connectionId:Wt,orgId:s.id}),l=Hi({resolver:Or(xw),defaultValues:t}),c=l.watch("connections"),d=!!Fs(t),[u,h]=S.useReducer(kw,{shareDialogOpen:!1,addDialogOpen:!1,settingsDialogOpen:!1,settingsConnectionId:null}),[f,m]=S.useState(!1),{createTaskWithMessage:p}=es(),{setChatMode:g}=ni(),{createNewTask:_}=zr(),v=()=>{const H=l.getValues("metadata.instructions");H?.trim()&&(T(),se("agent_instructions_improve_clicked",{agent_id:t.id,instructions_length:H.length}),g("plan"),p({virtualMcpId:hl(s.id),message:{parts:[{type:"text",text:`/writing-prompts ${t.id}
263
+ `},X0={onDragStart(t){let{active:e}=t;return"Picked up draggable item "+e.id+"."},onDragOver(t){let{active:e,over:s}=t;return s?"Draggable item "+e.id+" was moved over droppable area "+s.id+".":"Draggable item "+e.id+" is no longer over a droppable area."},onDragEnd(t){let{active:e,over:s}=t;return s?"Draggable item "+e.id+" was dropped over droppable area "+s.id:"Draggable item "+e.id+" was dropped."},onDragCancel(t){let{active:e}=t;return"Dragging was cancelled. Draggable item "+e.id+" was dropped."}};function J0(t){let{announcements:e=X0,container:s,hiddenTextDescribedById:i,screenReaderInstructions:n=Y0}=t;const{announce:o,announcement:a}=K0(),l=Qr("DndLiveRegion"),[c,d]=S.useState(!1);if(S.useEffect(()=>{d(!0)},[]),q0(S.useMemo(()=>({onDragStart(h){let{active:f}=h;o(e.onDragStart({active:f}))},onDragMove(h){let{active:f,over:m}=h;e.onDragMove&&o(e.onDragMove({active:f,over:m}))},onDragOver(h){let{active:f,over:m}=h;o(e.onDragOver({active:f,over:m}))},onDragEnd(h){let{active:f,over:m}=h;o(e.onDragEnd({active:f,over:m}))},onDragCancel(h){let{active:f,over:m}=h;o(e.onDragCancel({active:f,over:m}))}}),[o,e])),!c)return null;const u=Ft.createElement(Ft.Fragment,null,Ft.createElement(W0,{id:i,value:n.draggable}),Ft.createElement(U0,{id:l,announcement:a}));return s?ds.createPortal(u,s):u}var at;(function(t){t.DragStart="dragStart",t.DragMove="dragMove",t.DragEnd="dragEnd",t.DragCancel="dragCancel",t.DragOver="dragOver",t.RegisterDroppable="registerDroppable",t.SetDroppableDisabled="setDroppableDisabled",t.UnregisterDroppable="unregisterDroppable"})(at||(at={}));function Wn(){}function Qc(t,e){return S.useMemo(()=>({sensor:t,options:e??{}}),[t,e])}function Q0(){for(var t=arguments.length,e=new Array(t),s=0;s<t;s++)e[s]=arguments[s];return S.useMemo(()=>[...e].filter(i=>i!=null),[...e])}const fs=Object.freeze({x:0,y:0});function af(t,e){return Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2))}function lf(t,e){let{data:{value:s}}=t,{data:{value:i}}=e;return s-i}function Z0(t,e){let{data:{value:s}}=t,{data:{value:i}}=e;return i-s}function Zc(t){let{left:e,top:s,height:i,width:n}=t;return[{x:e,y:s},{x:e+n,y:s},{x:e,y:s+i},{x:e+n,y:s+i}]}function cf(t,e){if(!t||t.length===0)return null;const[s]=t;return s[e]}function ed(t,e,s){return e===void 0&&(e=t.left),s===void 0&&(s=t.top),{x:e+t.width*.5,y:s+t.height*.5}}const ey=t=>{let{collisionRect:e,droppableRects:s,droppableContainers:i}=t;const n=ed(e,e.left,e.top),o=[];for(const a of i){const{id:l}=a,c=s.get(l);if(c){const d=af(ed(c),n);o.push({id:l,data:{droppableContainer:a,value:d}})}}return o.sort(lf)},ty=t=>{let{collisionRect:e,droppableRects:s,droppableContainers:i}=t;const n=Zc(e),o=[];for(const a of i){const{id:l}=a,c=s.get(l);if(c){const d=Zc(c),u=n.reduce((f,m,p)=>f+af(d[p],m),0),h=Number((u/4).toFixed(4));o.push({id:l,data:{droppableContainer:a,value:h}})}}return o.sort(lf)};function sy(t,e){const s=Math.max(e.top,t.top),i=Math.max(e.left,t.left),n=Math.min(e.left+e.width,t.left+t.width),o=Math.min(e.top+e.height,t.top+t.height),a=n-i,l=o-s;if(i<n&&s<o){const c=e.width*e.height,d=t.width*t.height,u=a*l,h=u/(c+d-u);return Number(h.toFixed(4))}return 0}const iy=t=>{let{collisionRect:e,droppableRects:s,droppableContainers:i}=t;const n=[];for(const o of i){const{id:a}=o,l=s.get(a);if(l){const c=sy(l,e);c>0&&n.push({id:a,data:{droppableContainer:o,value:c}})}}return n.sort(Z0)};function ry(t,e,s){return{...t,scaleX:e&&s?e.width/s.width:1,scaleY:e&&s?e.height/s.height:1}}function df(t,e){return t&&e?{x:t.left-e.left,y:t.top-e.top}:fs}function ny(t){return function(s){for(var i=arguments.length,n=new Array(i>1?i-1:0),o=1;o<i;o++)n[o-1]=arguments[o];return n.reduce((a,l)=>({...a,top:a.top+t*l.y,bottom:a.bottom+t*l.y,left:a.left+t*l.x,right:a.right+t*l.x}),{...s})}}const oy=ny(1);function ay(t){if(t.startsWith("matrix3d(")){const e=t.slice(9,-1).split(/, /);return{x:+e[12],y:+e[13],scaleX:+e[0],scaleY:+e[5]}}else if(t.startsWith("matrix(")){const e=t.slice(7,-1).split(/, /);return{x:+e[4],y:+e[5],scaleX:+e[0],scaleY:+e[3]}}return null}function ly(t,e,s){const i=ay(e);if(!i)return t;const{scaleX:n,scaleY:o,x:a,y:l}=i,c=t.left-a-(1-n)*parseFloat(s),d=t.top-l-(1-o)*parseFloat(s.slice(s.indexOf(" ")+1)),u=n?t.width/n:t.width,h=o?t.height/o:t.height;return{width:u,height:h,top:d,right:c+u,bottom:d+h,left:c}}const cy={ignoreTransform:!1};function Gi(t,e){e===void 0&&(e=cy);let s=t.getBoundingClientRect();if(e.ignoreTransform){const{transform:d,transformOrigin:u}=Ut(t).getComputedStyle(t);d&&(s=ly(s,d,u))}const{top:i,left:n,width:o,height:a,bottom:l,right:c}=s;return{top:i,left:n,width:o,height:a,bottom:l,right:c}}function td(t){return Gi(t,{ignoreTransform:!0})}function dy(t){const e=t.innerWidth,s=t.innerHeight;return{top:0,left:0,right:e,bottom:s,width:e,height:s}}function hy(t,e){return e===void 0&&(e=Ut(t).getComputedStyle(t)),e.position==="fixed"}function uy(t,e){e===void 0&&(e=Ut(t).getComputedStyle(t));const s=/(auto|scroll|overlay)/;return["overflow","overflowX","overflowY"].some(n=>{const o=e[n];return typeof o=="string"?s.test(o):!1})}function fo(t,e){const s=[];function i(n){if(e!=null&&s.length>=e||!n)return s;if(Bl(n)&&n.scrollingElement!=null&&!s.includes(n.scrollingElement))return s.push(n.scrollingElement),s;if(!Xr(n)||rf(n)||s.includes(n))return s;const o=Ut(t).getComputedStyle(n);return n!==t&&uy(n,o)&&s.push(n),hy(n,o)?s:i(n.parentNode)}return t?i(t):s}function hf(t){const[e]=fo(t,1);return e??null}function To(t){return!uo||!t?null:Ki(t)?t:Ll(t)?Bl(t)||t===qi(t).scrollingElement?window:Xr(t)?t:null:null}function uf(t){return Ki(t)?t.scrollX:t.scrollLeft}function ff(t){return Ki(t)?t.scrollY:t.scrollTop}function va(t){return{x:uf(t),y:ff(t)}}var ut;(function(t){t[t.Forward=1]="Forward",t[t.Backward=-1]="Backward"})(ut||(ut={}));function mf(t){return!uo||!t?!1:t===document.scrollingElement}function pf(t){const e={x:0,y:0},s=mf(t)?{height:window.innerHeight,width:window.innerWidth}:{height:t.clientHeight,width:t.clientWidth},i={x:t.scrollWidth-s.width,y:t.scrollHeight-s.height},n=t.scrollTop<=e.y,o=t.scrollLeft<=e.x,a=t.scrollTop>=i.y,l=t.scrollLeft>=i.x;return{isTop:n,isLeft:o,isBottom:a,isRight:l,maxScroll:i,minScroll:e}}const fy={x:.2,y:.2};function my(t,e,s,i,n){let{top:o,left:a,right:l,bottom:c}=s;i===void 0&&(i=10),n===void 0&&(n=fy);const{isTop:d,isBottom:u,isLeft:h,isRight:f}=pf(t),m={x:0,y:0},p={x:0,y:0},g={height:e.height*n.y,width:e.width*n.x};return!d&&o<=e.top+g.height?(m.y=ut.Backward,p.y=i*Math.abs((e.top+g.height-o)/g.height)):!u&&c>=e.bottom-g.height&&(m.y=ut.Forward,p.y=i*Math.abs((e.bottom-g.height-c)/g.height)),!f&&l>=e.right-g.width?(m.x=ut.Forward,p.x=i*Math.abs((e.right-g.width-l)/g.width)):!h&&a<=e.left+g.width&&(m.x=ut.Backward,p.x=i*Math.abs((e.left+g.width-a)/g.width)),{direction:m,speed:p}}function py(t){if(t===document.scrollingElement){const{innerWidth:o,innerHeight:a}=window;return{top:0,left:0,right:o,bottom:a,width:o,height:a}}const{top:e,left:s,right:i,bottom:n}=t.getBoundingClientRect();return{top:e,left:s,right:i,bottom:n,width:t.clientWidth,height:t.clientHeight}}function gf(t){return t.reduce((e,s)=>Di(e,va(s)),fs)}function gy(t){return t.reduce((e,s)=>e+uf(s),0)}function _y(t){return t.reduce((e,s)=>e+ff(s),0)}function xy(t,e){if(e===void 0&&(e=Gi),!t)return;const{top:s,left:i,bottom:n,right:o}=e(t);hf(t)&&(n<=0||o<=0||s>=window.innerHeight||i>=window.innerWidth)&&t.scrollIntoView({block:"center",inline:"center"})}const vy=[["x",["left","right"],gy],["y",["top","bottom"],_y]];class zl{constructor(e,s){this.rect=void 0,this.width=void 0,this.height=void 0,this.top=void 0,this.bottom=void 0,this.right=void 0,this.left=void 0;const i=fo(s),n=gf(i);this.rect={...e},this.width=e.width,this.height=e.height;for(const[o,a,l]of vy)for(const c of a)Object.defineProperty(this,c,{get:()=>{const d=l(i),u=n[o]-d;return this.rect[c]+u},enumerable:!0});Object.defineProperty(this,"rect",{enumerable:!1})}}class br{constructor(e){this.target=void 0,this.listeners=[],this.removeAll=()=>{this.listeners.forEach(s=>{var i;return(i=this.target)==null?void 0:i.removeEventListener(...s)})},this.target=e}add(e,s,i){var n;(n=this.target)==null||n.addEventListener(e,s,i),this.listeners.push([e,s,i])}}function by(t){const{EventTarget:e}=Ut(t);return t instanceof e?t:qi(t)}function Do(t,e){const s=Math.abs(t.x),i=Math.abs(t.y);return typeof e=="number"?Math.sqrt(s**2+i**2)>e:"x"in e&&"y"in e?s>e.x&&i>e.y:"x"in e?s>e.x:"y"in e?i>e.y:!1}var ns;(function(t){t.Click="click",t.DragStart="dragstart",t.Keydown="keydown",t.ContextMenu="contextmenu",t.Resize="resize",t.SelectionChange="selectionchange",t.VisibilityChange="visibilitychange"})(ns||(ns={}));function sd(t){t.preventDefault()}function yy(t){t.stopPropagation()}var je;(function(t){t.Space="Space",t.Down="ArrowDown",t.Right="ArrowRight",t.Left="ArrowLeft",t.Up="ArrowUp",t.Esc="Escape",t.Enter="Enter",t.Tab="Tab"})(je||(je={}));const _f={start:[je.Space,je.Enter],cancel:[je.Esc],end:[je.Space,je.Enter,je.Tab]},Sy=(t,e)=>{let{currentCoordinates:s}=e;switch(t.code){case je.Right:return{...s,x:s.x+25};case je.Left:return{...s,x:s.x-25};case je.Down:return{...s,y:s.y+25};case je.Up:return{...s,y:s.y-25}}};class Fl{constructor(e){this.props=void 0,this.autoScrollEnabled=!1,this.referenceCoordinates=void 0,this.listeners=void 0,this.windowListeners=void 0,this.props=e;const{event:{target:s}}=e;this.props=e,this.listeners=new br(qi(s)),this.windowListeners=new br(Ut(s)),this.handleKeyDown=this.handleKeyDown.bind(this),this.handleCancel=this.handleCancel.bind(this),this.attach()}attach(){this.handleStart(),this.windowListeners.add(ns.Resize,this.handleCancel),this.windowListeners.add(ns.VisibilityChange,this.handleCancel),setTimeout(()=>this.listeners.add(ns.Keydown,this.handleKeyDown))}handleStart(){const{activeNode:e,onStart:s}=this.props,i=e.node.current;i&&xy(i),s(fs)}handleKeyDown(e){if($l(e)){const{active:s,context:i,options:n}=this.props,{keyboardCodes:o=_f,coordinateGetter:a=Sy,scrollBehavior:l="smooth"}=n,{code:c}=e;if(o.end.includes(c)){this.handleEnd(e);return}if(o.cancel.includes(c)){this.handleCancel(e);return}const{collisionRect:d}=i.current,u=d?{x:d.left,y:d.top}:fs;this.referenceCoordinates||(this.referenceCoordinates=u);const h=a(e,{active:s,context:i.current,currentCoordinates:u});if(h){const f=Ir(h,u),m={x:0,y:0},{scrollableAncestors:p}=i.current;for(const g of p){const _=e.code,{isTop:v,isRight:x,isLeft:b,isBottom:y,maxScroll:C,minScroll:j}=pf(g),V=py(g),w={x:Math.min(_===je.Right?V.right-V.width/2:V.right,Math.max(_===je.Right?V.left:V.left+V.width/2,h.x)),y:Math.min(_===je.Down?V.bottom-V.height/2:V.bottom,Math.max(_===je.Down?V.top:V.top+V.height/2,h.y))},k=_===je.Right&&!x||_===je.Left&&!b,T=_===je.Down&&!y||_===je.Up&&!v;if(k&&w.x!==h.x){const I=g.scrollLeft+f.x,A=_===je.Right&&I<=C.x||_===je.Left&&I>=j.x;if(A&&!f.y){g.scrollTo({left:I,behavior:l});return}A?m.x=g.scrollLeft-I:m.x=_===je.Right?g.scrollLeft-C.x:g.scrollLeft-j.x,m.x&&g.scrollBy({left:-m.x,behavior:l});break}else if(T&&w.y!==h.y){const I=g.scrollTop+f.y,A=_===je.Down&&I<=C.y||_===je.Up&&I>=j.y;if(A&&!f.x){g.scrollTo({top:I,behavior:l});return}A?m.y=g.scrollTop-I:m.y=_===je.Down?g.scrollTop-C.y:g.scrollTop-j.y,m.y&&g.scrollBy({top:-m.y,behavior:l});break}}this.handleMove(e,Di(Ir(h,this.referenceCoordinates),m))}}}handleMove(e,s){const{onMove:i}=this.props;e.preventDefault(),i(s)}handleEnd(e){const{onEnd:s}=this.props;e.preventDefault(),this.detach(),s()}handleCancel(e){const{onCancel:s}=this.props;e.preventDefault(),this.detach(),s()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll()}}Fl.activators=[{eventName:"onKeyDown",handler:(t,e,s)=>{let{keyboardCodes:i=_f,onActivation:n}=e,{active:o}=s;const{code:a}=t.nativeEvent;if(i.start.includes(a)){const l=o.activatorNode.current;return l&&t.target!==l?!1:(t.preventDefault(),n?.({event:t.nativeEvent}),!0)}return!1}}];function id(t){return!!(t&&"distance"in t)}function rd(t){return!!(t&&"delay"in t)}class Hl{constructor(e,s,i){var n;i===void 0&&(i=by(e.event.target)),this.props=void 0,this.events=void 0,this.autoScrollEnabled=!0,this.document=void 0,this.activated=!1,this.initialCoordinates=void 0,this.timeoutId=null,this.listeners=void 0,this.documentListeners=void 0,this.windowListeners=void 0,this.props=e,this.events=s;const{event:o}=e,{target:a}=o;this.props=e,this.events=s,this.document=qi(a),this.documentListeners=new br(this.document),this.listeners=new br(i),this.windowListeners=new br(Ut(a)),this.initialCoordinates=(n=xa(o))!=null?n:fs,this.handleStart=this.handleStart.bind(this),this.handleMove=this.handleMove.bind(this),this.handleEnd=this.handleEnd.bind(this),this.handleCancel=this.handleCancel.bind(this),this.handleKeydown=this.handleKeydown.bind(this),this.removeTextSelection=this.removeTextSelection.bind(this),this.attach()}attach(){const{events:e,props:{options:{activationConstraint:s,bypassActivationConstraint:i}}}=this;if(this.listeners.add(e.move.name,this.handleMove,{passive:!1}),this.listeners.add(e.end.name,this.handleEnd),e.cancel&&this.listeners.add(e.cancel.name,this.handleCancel),this.windowListeners.add(ns.Resize,this.handleCancel),this.windowListeners.add(ns.DragStart,sd),this.windowListeners.add(ns.VisibilityChange,this.handleCancel),this.windowListeners.add(ns.ContextMenu,sd),this.documentListeners.add(ns.Keydown,this.handleKeydown),s){if(i!=null&&i({event:this.props.event,activeNode:this.props.activeNode,options:this.props.options}))return this.handleStart();if(rd(s)){this.timeoutId=setTimeout(this.handleStart,s.delay),this.handlePending(s);return}if(id(s)){this.handlePending(s);return}}this.handleStart()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll(),setTimeout(this.documentListeners.removeAll,50),this.timeoutId!==null&&(clearTimeout(this.timeoutId),this.timeoutId=null)}handlePending(e,s){const{active:i,onPending:n}=this.props;n(i,e,this.initialCoordinates,s)}handleStart(){const{initialCoordinates:e}=this,{onStart:s}=this.props;e&&(this.activated=!0,this.documentListeners.add(ns.Click,yy,{capture:!0}),this.removeTextSelection(),this.documentListeners.add(ns.SelectionChange,this.removeTextSelection),s(e))}handleMove(e){var s;const{activated:i,initialCoordinates:n,props:o}=this,{onMove:a,options:{activationConstraint:l}}=o;if(!n)return;const c=(s=xa(e))!=null?s:fs,d=Ir(n,c);if(!i&&l){if(id(l)){if(l.tolerance!=null&&Do(d,l.tolerance))return this.handleCancel();if(Do(d,l.distance))return this.handleStart()}if(rd(l)&&Do(d,l.tolerance))return this.handleCancel();this.handlePending(l,d);return}e.cancelable&&e.preventDefault(),a(c)}handleEnd(){const{onAbort:e,onEnd:s}=this.props;this.detach(),this.activated||e(this.props.active),s()}handleCancel(){const{onAbort:e,onCancel:s}=this.props;this.detach(),this.activated||e(this.props.active),s()}handleKeydown(e){e.code===je.Esc&&this.handleCancel()}removeTextSelection(){var e;(e=this.document.getSelection())==null||e.removeAllRanges()}}const wy={cancel:{name:"pointercancel"},move:{name:"pointermove"},end:{name:"pointerup"}};class Wl extends Hl{constructor(e){const{event:s}=e,i=qi(s.target);super(e,wy,i)}}Wl.activators=[{eventName:"onPointerDown",handler:(t,e)=>{let{nativeEvent:s}=t,{onActivation:i}=e;return!s.isPrimary||s.button!==0?!1:(i?.({event:s}),!0)}}];const Vy={move:{name:"mousemove"},end:{name:"mouseup"}};var ba;(function(t){t[t.RightClick=2]="RightClick"})(ba||(ba={}));class Cy extends Hl{constructor(e){super(e,Vy,qi(e.event.target))}}Cy.activators=[{eventName:"onMouseDown",handler:(t,e)=>{let{nativeEvent:s}=t,{onActivation:i}=e;return s.button===ba.RightClick?!1:(i?.({event:s}),!0)}}];const Mo={cancel:{name:"touchcancel"},move:{name:"touchmove"},end:{name:"touchend"}};class jy extends Hl{constructor(e){super(e,Mo)}static setup(){return window.addEventListener(Mo.move.name,e,{capture:!1,passive:!1}),function(){window.removeEventListener(Mo.move.name,e)};function e(){}}}jy.activators=[{eventName:"onTouchStart",handler:(t,e)=>{let{nativeEvent:s}=t,{onActivation:i}=e;const{touches:n}=s;return n.length>1?!1:(i?.({event:s}),!0)}}];var yr;(function(t){t[t.Pointer=0]="Pointer",t[t.DraggableRect=1]="DraggableRect"})(yr||(yr={}));var Un;(function(t){t[t.TreeOrder=0]="TreeOrder",t[t.ReversedTreeOrder=1]="ReversedTreeOrder"})(Un||(Un={}));function ky(t){let{acceleration:e,activator:s=yr.Pointer,canScroll:i,draggingRect:n,enabled:o,interval:a=5,order:l=Un.TreeOrder,pointerCoordinates:c,scrollableAncestors:d,scrollableAncestorRects:u,delta:h,threshold:f}=t;const m=Ay({delta:h,disabled:!o}),[p,g]=O0(),_=S.useRef({x:0,y:0}),v=S.useRef({x:0,y:0}),x=S.useMemo(()=>{switch(s){case yr.Pointer:return c?{top:c.y,bottom:c.y,left:c.x,right:c.x}:null;case yr.DraggableRect:return n}},[s,n,c]),b=S.useRef(null),y=S.useCallback(()=>{const j=b.current;if(!j)return;const V=_.current.x*v.current.x,w=_.current.y*v.current.y;j.scrollBy(V,w)},[]),C=S.useMemo(()=>l===Un.TreeOrder?[...d].reverse():d,[l,d]);S.useEffect(()=>{if(!o||!d.length||!x){g();return}for(const j of C){if(i?.(j)===!1)continue;const V=d.indexOf(j),w=u[V];if(!w)continue;const{direction:k,speed:T}=my(j,w,x,e,f);for(const I of["x","y"])m[I][k[I]]||(T[I]=0,k[I]=0);if(T.x>0||T.y>0){g(),b.current=j,p(y,a),_.current=T,v.current=k;return}}_.current={x:0,y:0},v.current={x:0,y:0},g()},[e,y,i,g,o,a,JSON.stringify(x),JSON.stringify(m),p,d,C,u,JSON.stringify(f)])}const Ny={x:{[ut.Backward]:!1,[ut.Forward]:!1},y:{[ut.Backward]:!1,[ut.Forward]:!1}};function Ay(t){let{delta:e,disabled:s}=t;const i=_a(e);return Jr(n=>{if(s||!i||!n)return Ny;const o={x:Math.sign(e.x-i.x),y:Math.sign(e.y-i.y)};return{x:{[ut.Backward]:n.x[ut.Backward]||o.x===-1,[ut.Forward]:n.x[ut.Forward]||o.x===1},y:{[ut.Backward]:n.y[ut.Backward]||o.y===-1,[ut.Forward]:n.y[ut.Forward]||o.y===1}}},[s,e,i])}function Ey(t,e){const s=e!=null?t.get(e):void 0,i=s?s.node.current:null;return Jr(n=>{var o;return e==null?null:(o=i??n)!=null?o:null},[i,e])}function Iy(t,e){return S.useMemo(()=>t.reduce((s,i)=>{const{sensor:n}=i,o=n.activators.map(a=>({eventName:a.eventName,handler:e(a.handler,i)}));return[...s,...o]},[]),[t,e])}var Tr;(function(t){t[t.Always=0]="Always",t[t.BeforeDragging=1]="BeforeDragging",t[t.WhileDragging=2]="WhileDragging"})(Tr||(Tr={}));var ya;(function(t){t.Optimized="optimized"})(ya||(ya={}));const nd=new Map;function Ry(t,e){let{dragging:s,dependencies:i,config:n}=e;const[o,a]=S.useState(null),{frequency:l,measure:c,strategy:d}=n,u=S.useRef(t),h=_(),f=Er(h),m=S.useCallback(function(v){v===void 0&&(v=[]),!f.current&&a(x=>x===null?v:x.concat(v.filter(b=>!x.includes(b))))},[f]),p=S.useRef(null),g=Jr(v=>{if(h&&!s)return nd;if(!v||v===nd||u.current!==t||o!=null){const x=new Map;for(let b of t){if(!b)continue;if(o&&o.length>0&&!o.includes(b.id)&&b.rect.current){x.set(b.id,b.rect.current);continue}const y=b.node.current,C=y?new zl(c(y),y):null;b.rect.current=C,C&&x.set(b.id,C)}return x}return v},[t,o,s,h,c]);return S.useEffect(()=>{u.current=t},[t]),S.useEffect(()=>{h||m()},[s,h]),S.useEffect(()=>{o&&o.length>0&&a(null)},[JSON.stringify(o)]),S.useEffect(()=>{h||typeof l!="number"||p.current!==null||(p.current=setTimeout(()=>{m(),p.current=null},l))},[l,h,m,...i]),{droppableRects:g,measureDroppableContainers:m,measuringScheduled:o!=null};function _(){switch(d){case Tr.Always:return!1;case Tr.BeforeDragging:return s;default:return!s}}}function xf(t,e){return Jr(s=>t?s||(typeof e=="function"?e(t):t):null,[e,t])}function Ty(t,e){return xf(t,e)}function Dy(t){let{callback:e,disabled:s}=t;const i=Ol(e),n=S.useMemo(()=>{if(s||typeof window>"u"||typeof window.MutationObserver>"u")return;const{MutationObserver:o}=window;return new o(i)},[i,s]);return S.useEffect(()=>()=>n?.disconnect(),[n]),n}function mo(t){let{callback:e,disabled:s}=t;const i=Ol(e),n=S.useMemo(()=>{if(s||typeof window>"u"||typeof window.ResizeObserver>"u")return;const{ResizeObserver:o}=window;return new o(i)},[s]);return S.useEffect(()=>()=>n?.disconnect(),[n]),n}function My(t){return new zl(Gi(t),t)}function od(t,e,s){e===void 0&&(e=My);const[i,n]=S.useState(null);function o(){n(c=>{if(!t)return null;if(t.isConnected===!1){var d;return(d=c??s)!=null?d:null}const u=e(t);return JSON.stringify(c)===JSON.stringify(u)?c:u})}const a=Dy({callback(c){if(t)for(const d of c){const{type:u,target:h}=d;if(u==="childList"&&h instanceof HTMLElement&&h.contains(t)){o();break}}}}),l=mo({callback:o});return Es(()=>{o(),t?(l?.observe(t),a?.observe(document.body,{childList:!0,subtree:!0})):(l?.disconnect(),a?.disconnect())},[t]),i}function Py(t){const e=xf(t);return df(t,e)}const ad=[];function Ly(t){const e=S.useRef(t),s=Jr(i=>t?i&&i!==ad&&t&&e.current&&t.parentNode===e.current.parentNode?i:fo(t):ad,[t]);return S.useEffect(()=>{e.current=t},[t]),s}function By(t){const[e,s]=S.useState(null),i=S.useRef(t),n=S.useCallback(o=>{const a=To(o.target);a&&s(l=>l?(l.set(a,va(a)),new Map(l)):null)},[]);return S.useEffect(()=>{const o=i.current;if(t!==o){a(o);const l=t.map(c=>{const d=To(c);return d?(d.addEventListener("scroll",n,{passive:!0}),[d,va(d)]):null}).filter(c=>c!=null);s(l.length?new Map(l):null),i.current=t}return()=>{a(t),a(o)};function a(l){l.forEach(c=>{const d=To(c);d?.removeEventListener("scroll",n)})}},[n,t]),S.useMemo(()=>t.length?e?Array.from(e.values()).reduce((o,a)=>Di(o,a),fs):gf(t):fs,[t,e])}function ld(t,e){e===void 0&&(e=[]);const s=S.useRef(null);return S.useEffect(()=>{s.current=null},e),S.useEffect(()=>{const i=t!==fs;i&&!s.current&&(s.current=t),!i&&s.current&&(s.current=null)},[t]),s.current?Ir(t,s.current):fs}function Oy(t){S.useEffect(()=>{if(!uo)return;const e=t.map(s=>{let{sensor:i}=s;return i.setup==null?void 0:i.setup()});return()=>{for(const s of e)s?.()}},t.map(e=>{let{sensor:s}=e;return s}))}function $y(t,e){return S.useMemo(()=>t.reduce((s,i)=>{let{eventName:n,handler:o}=i;return s[n]=a=>{o(a,e)},s},{}),[t,e])}function vf(t){return S.useMemo(()=>t?dy(t):null,[t])}const cd=[];function zy(t,e){e===void 0&&(e=Gi);const[s]=t,i=vf(s?Ut(s):null),[n,o]=S.useState(cd);function a(){o(()=>t.length?t.map(c=>mf(c)?i:new zl(e(c),c)):cd)}const l=mo({callback:a});return Es(()=>{l?.disconnect(),a(),t.forEach(c=>l?.observe(c))},[t]),n}function Fy(t){if(!t)return null;if(t.children.length>1)return t;const e=t.children[0];return Xr(e)?e:t}function Hy(t){let{measure:e}=t;const[s,i]=S.useState(null),n=S.useCallback(d=>{for(const{target:u}of d)if(Xr(u)){i(h=>{const f=e(u);return h?{...h,width:f.width,height:f.height}:f});break}},[e]),o=mo({callback:n}),a=S.useCallback(d=>{const u=Fy(d);o?.disconnect(),u&&o?.observe(u),i(u?e(u):null)},[e,o]),[l,c]=Hn(a);return S.useMemo(()=>({nodeRef:l,rect:s,setRef:c}),[s,l,c])}const Wy=[{sensor:Wl,options:{}},{sensor:Fl,options:{}}],Uy={current:{}},kn={draggable:{measure:td},droppable:{measure:td,strategy:Tr.WhileDragging,frequency:ya.Optimized},dragOverlay:{measure:Gi}};class Sr extends Map{get(e){var s;return e!=null&&(s=super.get(e))!=null?s:void 0}toArray(){return Array.from(this.values())}getEnabled(){return this.toArray().filter(e=>{let{disabled:s}=e;return!s})}getNodeFor(e){var s,i;return(s=(i=this.get(e))==null?void 0:i.node.current)!=null?s:void 0}}const Ky={activatorEvent:null,active:null,activeNode:null,activeNodeRect:null,collisions:null,containerNodeRect:null,draggableNodes:new Map,droppableRects:new Map,droppableContainers:new Sr,over:null,dragOverlay:{nodeRef:{current:null},rect:null,setRef:Wn},scrollableAncestors:[],scrollableAncestorRects:[],measuringConfiguration:kn,measureDroppableContainers:Wn,windowRect:null,measuringScheduled:!1},qy={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:""},dispatch:Wn,draggableNodes:new Map,over:null,measureDroppableContainers:Wn},po=S.createContext(qy),bf=S.createContext(Ky);function Gy(){return{draggable:{active:null,initialCoordinates:{x:0,y:0},nodes:new Map,translate:{x:0,y:0}},droppable:{containers:new Sr}}}function Yy(t,e){switch(e.type){case at.DragStart:return{...t,draggable:{...t.draggable,initialCoordinates:e.initialCoordinates,active:e.active}};case at.DragMove:return t.draggable.active==null?t:{...t,draggable:{...t.draggable,translate:{x:e.coordinates.x-t.draggable.initialCoordinates.x,y:e.coordinates.y-t.draggable.initialCoordinates.y}}};case at.DragEnd:case at.DragCancel:return{...t,draggable:{...t.draggable,active:null,initialCoordinates:{x:0,y:0},translate:{x:0,y:0}}};case at.RegisterDroppable:{const{element:s}=e,{id:i}=s,n=new Sr(t.droppable.containers);return n.set(i,s),{...t,droppable:{...t.droppable,containers:n}}}case at.SetDroppableDisabled:{const{id:s,key:i,disabled:n}=e,o=t.droppable.containers.get(s);if(!o||i!==o.key)return t;const a=new Sr(t.droppable.containers);return a.set(s,{...o,disabled:n}),{...t,droppable:{...t.droppable,containers:a}}}case at.UnregisterDroppable:{const{id:s,key:i}=e,n=t.droppable.containers.get(s);if(!n||i!==n.key)return t;const o=new Sr(t.droppable.containers);return o.delete(s),{...t,droppable:{...t.droppable,containers:o}}}default:return t}}function Xy(t){let{disabled:e}=t;const{active:s,activatorEvent:i,draggableNodes:n}=S.useContext(po),o=_a(i),a=_a(s?.id);return S.useEffect(()=>{if(!e&&!i&&o&&a!=null){if(!$l(o)||document.activeElement===o.target)return;const l=n.get(a);if(!l)return;const{activatorNode:c,node:d}=l;if(!c.current&&!d.current)return;requestAnimationFrame(()=>{for(const u of[c.current,d.current]){if(!u)continue;const h=F0(u);if(h){h.focus();break}}})}},[i,e,n,a,o]),null}function Jy(t,e){let{transform:s,...i}=e;return t!=null&&t.length?t.reduce((n,o)=>o({transform:n,...i}),s):s}function Qy(t){return S.useMemo(()=>({draggable:{...kn.draggable,...t?.draggable},droppable:{...kn.droppable,...t?.droppable},dragOverlay:{...kn.dragOverlay,...t?.dragOverlay}}),[t?.draggable,t?.droppable,t?.dragOverlay])}function Zy(t){let{activeNode:e,measure:s,initialRect:i,config:n=!0}=t;const o=S.useRef(!1),{x:a,y:l}=typeof n=="boolean"?{x:n,y:n}:n;Es(()=>{if(!a&&!l||!e){o.current=!1;return}if(o.current||!i)return;const d=e?.node.current;if(!d||d.isConnected===!1)return;const u=s(d),h=df(u,i);if(a||(h.x=0),l||(h.y=0),o.current=!0,Math.abs(h.x)>0||Math.abs(h.y)>0){const f=hf(d);f&&f.scrollBy({top:h.y,left:h.x})}},[e,a,l,i,s])}const yf=S.createContext({...fs,scaleX:1,scaleY:1});var Gs;(function(t){t[t.Uninitialized=0]="Uninitialized",t[t.Initializing=1]="Initializing",t[t.Initialized=2]="Initialized"})(Gs||(Gs={}));const e2=S.memo(function(e){var s,i,n,o;let{id:a,accessibility:l,autoScroll:c=!0,children:d,sensors:u=Wy,collisionDetection:h=iy,measuring:f,modifiers:m,...p}=e;const g=S.useReducer(Yy,void 0,Gy),[_,v]=g,[x,b]=G0(),[y,C]=S.useState(Gs.Uninitialized),j=y===Gs.Initialized,{draggable:{active:V,nodes:w,translate:k},droppable:{containers:T}}=_,I=V!=null?w.get(V):null,A=S.useRef({initial:null,translated:null}),N=S.useMemo(()=>{var Ae;return V!=null?{id:V,data:(Ae=I?.data)!=null?Ae:Uy,rect:A}:null},[V,I]),E=S.useRef(null),[R,M]=S.useState(null),[L,D]=S.useState(null),P=Er(p,Object.values(p)),O=Qr("DndDescribedBy",a),z=S.useMemo(()=>T.getEnabled(),[T]),$=Qy(f),{droppableRects:W,measureDroppableContainers:F,measuringScheduled:G}=Ry(z,{dragging:j,dependencies:[k.x,k.y],config:$.droppable}),q=Ey(w,V),H=S.useMemo(()=>L?xa(L):null,[L]),ee=jt(),K=Ty(q,$.draggable.measure);Zy({activeNode:V!=null?w.get(V):null,config:ee.layoutShiftCompensation,initialRect:K,measure:$.draggable.measure});const U=od(q,$.draggable.measure,K),te=od(q?q.parentElement:null),Y=S.useRef({activatorEvent:null,active:null,activeNode:q,collisionRect:null,collisions:null,droppableRects:W,draggableNodes:w,draggingNode:null,draggingNodeRect:null,droppableContainers:T,over:null,scrollableAncestors:[],scrollAdjustedTranslate:null}),J=T.getNodeFor((s=Y.current.over)==null?void 0:s.id),ie=Hy({measure:$.dragOverlay.measure}),ue=(i=ie.nodeRef.current)!=null?i:q,de=j?(n=ie.rect)!=null?n:U:null,xe=!!(ie.nodeRef.current&&ie.rect),oe=Py(xe?null:U),he=vf(ue?Ut(ue):null),me=Ly(j?J??q:null),fe=zy(me),le=Jy(m,{transform:{x:k.x-oe.x,y:k.y-oe.y,scaleX:1,scaleY:1},activatorEvent:L,active:N,activeNodeRect:U,containerNodeRect:te,draggingNodeRect:de,over:Y.current.over,overlayNodeRect:ie.rect,scrollableAncestors:me,scrollableAncestorRects:fe,windowRect:he}),ve=H?Di(H,k):null,Ce=By(me),Te=ld(Ce),Q=ld(Ce,[U]),ae=Di(le,Te),Se=de?oy(de,le):null,Ne=N&&Se?h({active:N,collisionRect:Se,droppableRects:W,droppableContainers:z,pointerCoordinates:ve}):null,Be=cf(Ne,"id"),[Oe,He]=S.useState(null),Je=xe?le:Di(le,Q),dt=ry(Je,(o=Oe?.rect)!=null?o:null,U),ge=S.useRef(null),ke=S.useCallback((Ae,Ie)=>{let{sensor:qe,options:qt}=Ie;if(E.current==null)return;const _t=w.get(E.current);if(!_t)return;const xt=Ae.nativeEvent,vt=new qe({active:E.current,activeNode:_t,event:xt,options:qt,context:Y,onAbort($e){if(!w.get($e))return;const{onDragAbort:Nt}=P.current,wt={id:$e};Nt?.(wt),x({type:"onDragAbort",event:wt})},onPending($e,kt,Nt,wt){if(!w.get($e))return;const{onDragPending:Ot}=P.current,$t={id:$e,constraint:kt,initialCoordinates:Nt,offset:wt};Ot?.($t),x({type:"onDragPending",event:$t})},onStart($e){const kt=E.current;if(kt==null)return;const Nt=w.get(kt);if(!Nt)return;const{onDragStart:wt}=P.current,_e={activatorEvent:xt,active:{id:kt,data:Nt.data,rect:A}};ds.unstable_batchedUpdates(()=>{wt?.(_e),C(Gs.Initializing),v({type:at.DragStart,initialCoordinates:$e,active:kt}),x({type:"onDragStart",event:_e}),M(ge.current),D(xt)})},onMove($e){v({type:at.DragMove,coordinates:$e})},onEnd:_s(at.DragEnd),onCancel:_s(at.DragCancel)});ge.current=vt;function _s($e){return async function(){const{active:Nt,collisions:wt,over:_e,scrollAdjustedTranslate:Ot}=Y.current;let $t=null;if(Nt&&Ot){const{cancelDrop:ls}=P.current;$t={activatorEvent:xt,active:Nt,collisions:wt,delta:Ot,over:_e},$e===at.DragEnd&&typeof ls=="function"&&await Promise.resolve(ls($t))&&($e=at.DragCancel)}E.current=null,ds.unstable_batchedUpdates(()=>{v({type:$e}),C(Gs.Uninitialized),He(null),M(null),D(null),ge.current=null;const ls=$e===at.DragEnd?"onDragEnd":"onDragCancel";if($t){const Qi=P.current[ls];Qi?.($t),x({type:ls,event:$t})}})}}},[w]),Qe=S.useCallback((Ae,Ie)=>(qe,qt)=>{const _t=qe.nativeEvent,xt=w.get(qt);if(E.current!==null||!xt||_t.dndKit||_t.defaultPrevented)return;const vt={active:xt};Ae(qe,Ie.options,vt)===!0&&(_t.dndKit={capturedBy:Ie.sensor},E.current=qt,ke(qe,Ie))},[w,ke]),Ct=Iy(u,Qe);Oy(u),Es(()=>{U&&y===Gs.Initializing&&C(Gs.Initialized)},[U,y]),S.useEffect(()=>{const{onDragMove:Ae}=P.current,{active:Ie,activatorEvent:qe,collisions:qt,over:_t}=Y.current;if(!Ie||!qe)return;const xt={active:Ie,activatorEvent:qe,collisions:qt,delta:{x:ae.x,y:ae.y},over:_t};ds.unstable_batchedUpdates(()=>{Ae?.(xt),x({type:"onDragMove",event:xt})})},[ae.x,ae.y]),S.useEffect(()=>{const{active:Ae,activatorEvent:Ie,collisions:qe,droppableContainers:qt,scrollAdjustedTranslate:_t}=Y.current;if(!Ae||E.current==null||!Ie||!_t)return;const{onDragOver:xt}=P.current,vt=qt.get(Be),_s=vt&&vt.rect.current?{id:vt.id,rect:vt.rect.current,data:vt.data,disabled:vt.disabled}:null,$e={active:Ae,activatorEvent:Ie,collisions:qe,delta:{x:_t.x,y:_t.y},over:_s};ds.unstable_batchedUpdates(()=>{He(_s),xt?.($e),x({type:"onDragOver",event:$e})})},[Be]),Es(()=>{Y.current={activatorEvent:L,active:N,activeNode:q,collisionRect:Se,collisions:Ne,droppableRects:W,draggableNodes:w,draggingNode:ue,draggingNodeRect:de,droppableContainers:T,over:Oe,scrollableAncestors:me,scrollAdjustedTranslate:ae},A.current={initial:de,translated:Se}},[N,q,Ne,Se,w,ue,de,W,T,Oe,me,ae]),ky({...ee,delta:k,draggingRect:Se,pointerCoordinates:ve,scrollableAncestors:me,scrollableAncestorRects:fe});const Pe=S.useMemo(()=>({active:N,activeNode:q,activeNodeRect:U,activatorEvent:L,collisions:Ne,containerNodeRect:te,dragOverlay:ie,draggableNodes:w,droppableContainers:T,droppableRects:W,over:Oe,measureDroppableContainers:F,scrollableAncestors:me,scrollableAncestorRects:fe,measuringConfiguration:$,measuringScheduled:G,windowRect:he}),[N,q,U,L,Ne,te,ie,w,T,W,Oe,F,me,fe,$,G,he]),Kt=S.useMemo(()=>({activatorEvent:L,activators:Ct,active:N,activeNodeRect:U,ariaDescribedById:{draggable:O},dispatch:v,draggableNodes:w,over:Oe,measureDroppableContainers:F}),[L,Ct,N,U,v,O,w,Oe,F]);return Ft.createElement(of.Provider,{value:b},Ft.createElement(po.Provider,{value:Kt},Ft.createElement(bf.Provider,{value:Pe},Ft.createElement(yf.Provider,{value:dt},d)),Ft.createElement(Xy,{disabled:l?.restoreFocus===!1})),Ft.createElement(J0,{...l,hiddenTextDescribedById:O}));function jt(){const Ae=R?.autoScrollEnabled===!1,Ie=typeof c=="object"?c.enabled===!1:c===!1,qe=j&&!Ae&&!Ie;return typeof c=="object"?{...c,enabled:qe}:{enabled:qe}}}),t2=S.createContext(null),dd="button",s2="Draggable";function i2(t){let{id:e,data:s,disabled:i=!1,attributes:n}=t;const o=Qr(s2),{activators:a,activatorEvent:l,active:c,activeNodeRect:d,ariaDescribedById:u,draggableNodes:h,over:f}=S.useContext(po),{role:m=dd,roleDescription:p="draggable",tabIndex:g=0}=n??{},_=c?.id===e,v=S.useContext(_?yf:t2),[x,b]=Hn(),[y,C]=Hn(),j=$y(a,e),V=Er(s);Es(()=>(h.set(e,{id:e,key:o,node:x,activatorNode:y,data:V}),()=>{const k=h.get(e);k&&k.key===o&&h.delete(e)}),[h,e]);const w=S.useMemo(()=>({role:m,tabIndex:g,"aria-disabled":i,"aria-pressed":_&&m===dd?!0:void 0,"aria-roledescription":p,"aria-describedby":u.draggable}),[i,m,g,_,p,u.draggable]);return{active:c,activatorEvent:l,activeNodeRect:d,attributes:w,isDragging:_,listeners:i?void 0:j,node:x,over:f,setNodeRef:b,setActivatorNodeRef:C,transform:v}}function r2(){return S.useContext(bf)}const n2="Droppable",o2={timeout:25};function a2(t){let{data:e,disabled:s=!1,id:i,resizeObserverConfig:n}=t;const o=Qr(n2),{active:a,dispatch:l,over:c,measureDroppableContainers:d}=S.useContext(po),u=S.useRef({disabled:s}),h=S.useRef(!1),f=S.useRef(null),m=S.useRef(null),{disabled:p,updateMeasurementsFor:g,timeout:_}={...o2,...n},v=Er(g??i),x=S.useCallback(()=>{if(!h.current){h.current=!0;return}m.current!=null&&clearTimeout(m.current),m.current=setTimeout(()=>{d(Array.isArray(v.current)?v.current:[v.current]),m.current=null},_)},[_]),b=mo({callback:x,disabled:p||!a}),y=S.useCallback((w,k)=>{b&&(k&&(b.unobserve(k),h.current=!1),w&&b.observe(w))},[b]),[C,j]=Hn(y),V=Er(e);return S.useEffect(()=>{!b||!C.current||(b.disconnect(),h.current=!1,b.observe(C.current))},[C,b]),S.useEffect(()=>(l({type:at.RegisterDroppable,element:{id:i,key:o,disabled:s,node:C,rect:f,data:V}}),()=>l({type:at.UnregisterDroppable,key:o,id:i})),[i]),S.useEffect(()=>{s!==u.current.disabled&&(l({type:at.SetDroppableDisabled,id:i,key:o,disabled:s}),u.current.disabled=s)},[i,o,s,l]),{active:a,rect:f,isOver:c?.id===i,node:C,over:c,setNodeRef:j}}function Ul(t,e,s){const i=t.slice();return i.splice(s<0?i.length+s:s,0,i.splice(e,1)[0]),i}function l2(t,e){return t.reduce((s,i,n)=>{const o=e.get(i);return o&&(s[n]=o),s},Array(t.length))}function cn(t){return t!==null&&t>=0}function c2(t,e){if(t===e)return!0;if(t.length!==e.length)return!1;for(let s=0;s<t.length;s++)if(t[s]!==e[s])return!1;return!0}function d2(t){return typeof t=="boolean"?{draggable:t,droppable:t}:t}const Sf=t=>{let{rects:e,activeIndex:s,overIndex:i,index:n}=t;const o=Ul(e,i,s),a=e[n],l=o[n];return!l||!a?null:{x:l.left-a.left,y:l.top-a.top,scaleX:l.width/a.width,scaleY:l.height/a.height}},dn={scaleX:1,scaleY:1},h2=t=>{var e;let{activeIndex:s,activeNodeRect:i,index:n,rects:o,overIndex:a}=t;const l=(e=o[s])!=null?e:i;if(!l)return null;if(n===s){const d=o[a];return d?{x:0,y:s<a?d.top+d.height-(l.top+l.height):d.top-l.top,...dn}:null}const c=u2(o,n,s);return n>s&&n<=a?{x:0,y:-l.height-c,...dn}:n<s&&n>=a?{x:0,y:l.height+c,...dn}:{x:0,y:0,...dn}};function u2(t,e,s){const i=t[e],n=t[e-1],o=t[e+1];return i?s<e?n?i.top-(n.top+n.height):o?o.top-(i.top+i.height):0:o?o.top-(i.top+i.height):n?i.top-(n.top+n.height):0:0}const wf="Sortable",Vf=Ft.createContext({activeIndex:-1,containerId:wf,disableTransforms:!1,items:[],overIndex:-1,useDragOverlay:!1,sortedRects:[],strategy:Sf,disabled:{draggable:!1,droppable:!1}});function f2(t){let{children:e,id:s,items:i,strategy:n=Sf,disabled:o=!1}=t;const{active:a,dragOverlay:l,droppableRects:c,over:d,measureDroppableContainers:u}=r2(),h=Qr(wf,s),f=l.rect!==null,m=S.useMemo(()=>i.map(j=>typeof j=="object"&&"id"in j?j.id:j),[i]),p=a!=null,g=a?m.indexOf(a.id):-1,_=d?m.indexOf(d.id):-1,v=S.useRef(m),x=!c2(m,v.current),b=_!==-1&&g===-1||x,y=d2(o);Es(()=>{x&&p&&u(m)},[x,m,p,u]),S.useEffect(()=>{v.current=m},[m]);const C=S.useMemo(()=>({activeIndex:g,containerId:h,disabled:y,disableTransforms:b,items:m,overIndex:_,useDragOverlay:f,sortedRects:l2(m,c),strategy:n}),[g,h,y.draggable,y.droppable,b,m,_,c,f,n]);return Ft.createElement(Vf.Provider,{value:C},e)}const m2=t=>{let{id:e,items:s,activeIndex:i,overIndex:n}=t;return Ul(s,i,n).indexOf(e)},p2=t=>{let{containerId:e,isSorting:s,wasDragging:i,index:n,items:o,newIndex:a,previousItems:l,previousContainerId:c,transition:d}=t;return!d||!i||l!==o&&n===a?!1:s?!0:a!==n&&e===c},g2={duration:200,easing:"ease"},Cf="transform",_2=Rr.Transition.toString({property:Cf,duration:0,easing:"linear"}),x2={roleDescription:"sortable"};function v2(t){let{disabled:e,index:s,node:i,rect:n}=t;const[o,a]=S.useState(null),l=S.useRef(s);return Es(()=>{if(!e&&s!==l.current&&i.current){const c=n.current;if(c){const d=Gi(i.current,{ignoreTransform:!0}),u={x:c.left-d.left,y:c.top-d.top,scaleX:c.width/d.width,scaleY:c.height/d.height};(u.x||u.y)&&a(u)}}s!==l.current&&(l.current=s)},[e,s,i,n]),S.useEffect(()=>{o&&a(null)},[o]),o}function b2(t){let{animateLayoutChanges:e=p2,attributes:s,disabled:i,data:n,getNewIndex:o=m2,id:a,strategy:l,resizeObserverConfig:c,transition:d=g2}=t;const{items:u,containerId:h,activeIndex:f,disabled:m,disableTransforms:p,sortedRects:g,overIndex:_,useDragOverlay:v,strategy:x}=S.useContext(Vf),b=y2(i,m),y=u.indexOf(a),C=S.useMemo(()=>({sortable:{containerId:h,index:y,items:u},...n}),[h,n,y,u]),j=S.useMemo(()=>u.slice(u.indexOf(a)),[u,a]),{rect:V,node:w,isOver:k,setNodeRef:T}=a2({id:a,data:C,disabled:b.droppable,resizeObserverConfig:{updateMeasurementsFor:j,...c}}),{active:I,activatorEvent:A,activeNodeRect:N,attributes:E,setNodeRef:R,listeners:M,isDragging:L,over:D,setActivatorNodeRef:P,transform:O}=i2({id:a,data:C,attributes:{...x2,...s},disabled:b.draggable}),z=B0(T,R),$=!!I,W=$&&!p&&cn(f)&&cn(_),F=!v&&L,G=F&&W?O:null,H=W?G??(l??x)({rects:g,activeNodeRect:N,activeIndex:f,overIndex:_,index:y}):null,ee=cn(f)&&cn(_)?o({id:a,items:u,activeIndex:f,overIndex:_}):y,K=I?.id,U=S.useRef({activeId:K,items:u,newIndex:ee,containerId:h}),te=u!==U.current.items,Y=e({active:I,containerId:h,isDragging:L,isSorting:$,id:a,index:y,items:u,newIndex:U.current.newIndex,previousItems:U.current.items,previousContainerId:U.current.containerId,transition:d,wasDragging:U.current.activeId!=null}),J=v2({disabled:!Y,index:y,node:w,rect:V});return S.useEffect(()=>{$&&U.current.newIndex!==ee&&(U.current.newIndex=ee),h!==U.current.containerId&&(U.current.containerId=h),u!==U.current.items&&(U.current.items=u)},[$,ee,h,u]),S.useEffect(()=>{if(K===U.current.activeId)return;if(K!=null&&U.current.activeId==null){U.current.activeId=K;return}const ue=setTimeout(()=>{U.current.activeId=K},50);return()=>clearTimeout(ue)},[K]),{active:I,activeIndex:f,attributes:E,data:C,rect:V,index:y,newIndex:ee,items:u,isOver:k,isSorting:$,isDragging:L,listeners:M,node:w,overIndex:_,over:D,setNodeRef:z,setActivatorNodeRef:P,setDroppableNodeRef:T,setDraggableNodeRef:R,transform:J??H,transition:ie()};function ie(){if(J||te&&U.current.newIndex===y)return _2;if(!(F&&!$l(A)||!d)&&($||Y))return Rr.Transition.toString({...d,property:Cf})}}function y2(t,e){var s,i;return typeof t=="boolean"?{draggable:t,droppable:!1}:{draggable:(s=t?.draggable)!=null?s:e.draggable,droppable:(i=t?.droppable)!=null?i:e.droppable}}function Kn(t){if(!t)return!1;const e=t.data.current;return!!(e&&"sortable"in e&&typeof e.sortable=="object"&&"containerId"in e.sortable&&"items"in e.sortable&&"index"in e.sortable)}const S2=[je.Down,je.Right,je.Up,je.Left],w2=(t,e)=>{let{context:{active:s,collisionRect:i,droppableRects:n,droppableContainers:o,over:a,scrollableAncestors:l}}=e;if(S2.includes(t.code)){if(t.preventDefault(),!s||!i)return;const c=[];o.getEnabled().forEach(h=>{if(!h||h!=null&&h.disabled)return;const f=n.get(h.id);if(f)switch(t.code){case je.Down:i.top<f.top&&c.push(h);break;case je.Up:i.top>f.top&&c.push(h);break;case je.Left:i.left>f.left&&c.push(h);break;case je.Right:i.left<f.left&&c.push(h);break}});const d=ty({collisionRect:i,droppableRects:n,droppableContainers:c});let u=cf(d,"id");if(u===a?.id&&d.length>1&&(u=d[1].id),u!=null){const h=o.get(s.id),f=o.get(u),m=f?n.get(f.id):null,p=f?.node.current;if(p&&m&&h&&f){const _=fo(p).some((j,V)=>l[V]!==j),v=jf(h,f),x=V2(h,f),b=_||!v?{x:0,y:0}:{x:x?i.width-m.width:0,y:x?i.height-m.height:0},y={x:m.left,y:m.top};return b.x&&b.y?y:Ir(y,b)}}}};function jf(t,e){return!Kn(t)||!Kn(e)?!1:t.data.current.sortable.containerId===e.data.current.sortable.containerId}function V2(t,e){return!Kn(t)||!Kn(e)||!jf(t,e)?!1:t.data.current.sortable.index<e.data.current.sortable.index}function C2(t){const e=B.c(21),{value:s,onChange:i,placeholder:n,onKeyDown:o,className:a,isSearching:l,disabled:c}=t,d=n===void 0?"Search...":n;let u;e[0]!==a?(u=X("shrink-0 w-full border-b border-border h-12",a),e[0]=a,e[1]=u):u=e[1];const h=c?"cursor-not-allowed opacity-50":"cursor-text";let f;e[2]!==h?(f=X("flex items-center gap-2.5 h-12 px-4",h),e[2]=h,e[3]=f):f=e[3];let m;e[4]!==l?(m=l?r.jsx(Ee,{size:16,className:"animate-spin text-muted-foreground shrink-0"}):r.jsx(vl,{size:16,className:"text-muted-foreground shrink-0"}),e[4]=l,e[5]=m):m=e[5];let p;e[6]!==i?(p=x=>i(x.target.value),e[6]=i,e[7]=p):p=e[7];let g;e[8]!==c||e[9]!==o||e[10]!==d||e[11]!==p||e[12]!==s?(g=r.jsx("input",{type:"text",value:s,onChange:p,onKeyDown:o,placeholder:d,disabled:c,className:"flex-1 min-w-0 bg-transparent text-sm text-foreground placeholder:text-muted-foreground/50 outline-none"}),e[8]=c,e[9]=o,e[10]=d,e[11]=p,e[12]=s,e[13]=g):g=e[13];let _;e[14]!==f||e[15]!==m||e[16]!==g?(_=r.jsxs("label",{className:f,children:[m,g]}),e[14]=f,e[15]=m,e[16]=g,e[17]=_):_=e[17];let v;return e[18]!==u||e[19]!==_?(v=r.jsx("div",{className:u,children:_}),e[18]=u,e[19]=_,e[20]=v):v=e[20],v}var Kl="ContextMenu",[j2]=pp(Kl,[kh]),Pt=kh(),[k2,kf]=j2(Kl),Nf=t=>{const{__scopeContextMenu:e,children:s,onOpenChange:i,dir:n,modal:o=!0}=t,[a,l]=S.useState(!1),c=Pt(e),d=ap(i),u=S.useCallback(h=>{l(h),d(h)},[d]);return r.jsx(k2,{scope:e,open:a,onOpenChange:u,modal:o,children:r.jsx(lp,{...c,dir:n,open:a,onOpenChange:u,modal:o,children:s})})};Nf.displayName=Kl;var Af="ContextMenuTrigger",Ef=S.forwardRef((t,e)=>{const{__scopeContextMenu:s,disabled:i=!1,...n}=t,o=kf(Af,s),a=Pt(s),l=S.useRef({x:0,y:0}),c=S.useRef({getBoundingClientRect:()=>DOMRect.fromRect({width:0,height:0,...l.current})}),d=S.useRef(0),u=S.useCallback(()=>window.clearTimeout(d.current),[]),h=f=>{l.current={x:f.clientX,y:f.clientY},o.onOpenChange(!0)};return S.useEffect(()=>u,[u]),S.useEffect(()=>{i&&u()},[i,u]),r.jsxs(r.Fragment,{children:[r.jsx(cp,{...a,virtualRef:c}),r.jsx(dp.span,{"data-state":o.open?"open":"closed","data-disabled":i?"":void 0,...n,ref:e,style:{WebkitTouchCallout:"none",...t.style},onContextMenu:i?t.onContextMenu:Zi(t.onContextMenu,f=>{u(),h(f),f.preventDefault()}),onPointerDown:i?t.onPointerDown:Zi(t.onPointerDown,hn(f=>{u(),d.current=window.setTimeout(()=>h(f),700)})),onPointerMove:i?t.onPointerMove:Zi(t.onPointerMove,hn(u)),onPointerCancel:i?t.onPointerCancel:Zi(t.onPointerCancel,hn(u)),onPointerUp:i?t.onPointerUp:Zi(t.onPointerUp,hn(u))})]})});Ef.displayName=Af;var N2="ContextMenuPortal",If=t=>{const{__scopeContextMenu:e,...s}=t,i=Pt(e);return r.jsx(hp,{...i,...s})};If.displayName=N2;var Rf="ContextMenuContent",Tf=S.forwardRef((t,e)=>{const{__scopeContextMenu:s,...i}=t,n=kf(Rf,s),o=Pt(s),a=S.useRef(!1);return r.jsx(up,{...o,...i,ref:e,side:"right",sideOffset:2,align:"start",onCloseAutoFocus:l=>{t.onCloseAutoFocus?.(l),!l.defaultPrevented&&a.current&&l.preventDefault(),a.current=!1},onInteractOutside:l=>{t.onInteractOutside?.(l),!l.defaultPrevented&&!n.modal&&(a.current=!0)},style:{...t.style,"--radix-context-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-context-menu-content-available-width":"var(--radix-popper-available-width)","--radix-context-menu-content-available-height":"var(--radix-popper-available-height)","--radix-context-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-context-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});Tf.displayName=Rf;var A2="ContextMenuGroup",E2=S.forwardRef((t,e)=>{const{__scopeContextMenu:s,...i}=t,n=Pt(s);return r.jsx(gp,{...n,...i,ref:e})});E2.displayName=A2;var I2="ContextMenuLabel",R2=S.forwardRef((t,e)=>{const{__scopeContextMenu:s,...i}=t,n=Pt(s);return r.jsx(_p,{...n,...i,ref:e})});R2.displayName=I2;var T2="ContextMenuItem",Df=S.forwardRef((t,e)=>{const{__scopeContextMenu:s,...i}=t,n=Pt(s);return r.jsx(fp,{...n,...i,ref:e})});Df.displayName=T2;var D2="ContextMenuCheckboxItem",M2=S.forwardRef((t,e)=>{const{__scopeContextMenu:s,...i}=t,n=Pt(s);return r.jsx(xp,{...n,...i,ref:e})});M2.displayName=D2;var P2="ContextMenuRadioGroup",L2=S.forwardRef((t,e)=>{const{__scopeContextMenu:s,...i}=t,n=Pt(s);return r.jsx(vp,{...n,...i,ref:e})});L2.displayName=P2;var B2="ContextMenuRadioItem",O2=S.forwardRef((t,e)=>{const{__scopeContextMenu:s,...i}=t,n=Pt(s);return r.jsx(bp,{...n,...i,ref:e})});O2.displayName=B2;var $2="ContextMenuItemIndicator",z2=S.forwardRef((t,e)=>{const{__scopeContextMenu:s,...i}=t,n=Pt(s);return r.jsx(yp,{...n,...i,ref:e})});z2.displayName=$2;var F2="ContextMenuSeparator",Mf=S.forwardRef((t,e)=>{const{__scopeContextMenu:s,...i}=t,n=Pt(s);return r.jsx(mp,{...n,...i,ref:e})});Mf.displayName=F2;var H2="ContextMenuArrow",W2=S.forwardRef((t,e)=>{const{__scopeContextMenu:s,...i}=t,n=Pt(s);return r.jsx(Sp,{...n,...i,ref:e})});W2.displayName=H2;var U2="ContextMenuSubTrigger",K2=S.forwardRef((t,e)=>{const{__scopeContextMenu:s,...i}=t,n=Pt(s);return r.jsx(wp,{...n,...i,ref:e})});K2.displayName=U2;var q2="ContextMenuSubContent",G2=S.forwardRef((t,e)=>{const{__scopeContextMenu:s,...i}=t,n=Pt(s);return r.jsx(Vp,{...n,...i,ref:e,style:{...t.style,"--radix-context-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-context-menu-content-available-width":"var(--radix-popper-available-width)","--radix-context-menu-content-available-height":"var(--radix-popper-available-height)","--radix-context-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-context-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});G2.displayName=q2;function hn(t){return e=>e.pointerType!=="mouse"?t(e):void 0}var Y2=Nf,X2=Ef,J2=If,Q2=Tf,Z2=Df,eS=Mf;function tS(t){const e=B.c(4);let s;e[0]!==t?({...s}=t,e[0]=t,e[1]=s):s=e[1];let i;return e[2]!==s?(i=r.jsx(Y2,{"data-slot":"context-menu",...s}),e[2]=s,e[3]=i):i=e[3],i}function sS(t){const e=B.c(4);let s;e[0]!==t?({...s}=t,e[0]=t,e[1]=s):s=e[1];let i;return e[2]!==s?(i=r.jsx(X2,{"data-slot":"context-menu-trigger",...s}),e[2]=s,e[3]=i):i=e[3],i}function iS(t){const e=B.c(8);let s,i;e[0]!==t?({className:s,...i}=t,e[0]=t,e[1]=s,e[2]=i):(s=e[1],i=e[2]);let n;e[3]!==s?(n=X("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 max-h-(--radix-context-menu-content-available-height) min-w-[8rem] origin-(--radix-context-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border p-1 shadow-md",s),e[3]=s,e[4]=n):n=e[4];let o;return e[5]!==i||e[6]!==n?(o=r.jsx(J2,{children:r.jsx(Q2,{"data-slot":"context-menu-content",className:n,...i})}),e[5]=i,e[6]=n,e[7]=o):o=e[7],o}function hd(t){const e=B.c(12);let s,i,n,o;e[0]!==t?({className:s,inset:i,variant:o,...n}=t,e[0]=t,e[1]=s,e[2]=i,e[3]=n,e[4]=o):(s=e[1],i=e[2],n=e[3],o=e[4]);const a=o===void 0?"default":o;let l;e[5]!==s?(l=X("focus:bg-accent focus:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",s),e[5]=s,e[6]=l):l=e[6];let c;return e[7]!==i||e[8]!==n||e[9]!==l||e[10]!==a?(c=r.jsx(Z2,{"data-slot":"context-menu-item","data-inset":i,"data-variant":a,className:l,...n}),e[7]=i,e[8]=n,e[9]=l,e[10]=a,e[11]=c):c=e[11],c}function rS(t){const e=B.c(8);let s,i;e[0]!==t?({className:s,...i}=t,e[0]=t,e[1]=s,e[2]=i):(s=e[1],i=e[2]);let n;e[3]!==s?(n=X("bg-border -mx-1 my-1 h-px",s),e[3]=s,e[4]=n):n=e[4];let o;return e[5]!==i||e[6]!==n?(o=r.jsx(eS,{"data-slot":"context-menu-separator",className:n,...i}),e[5]=i,e[6]=n,e[7]=o):o=e[7],o}function Pf(t){const e=Ke(),s=Mt(),i=Su(),{locator:n}=be(),o=$r({strict:!1}),a=vi({strict:!1});return async l=>{const c=crypto.randomUUID(),d=l===a.virtualmcpid?Lh(s,n,o.taskId??""):null;try{await i.create.mutateAsync({id:c,virtual_mcp_id:l,...d?{branch:d}:{}})}catch{}e({to:"/$org/$taskId",params:{org:t,taskId:c},search:{virtualmcpid:l}})}}function nS({agent:t,org:e,onUnpin:s,isDragging:i}){const n=Ke(),{isMobile:o,setOpenMobile:a}=qr(),l=Pf(e),d=Vh({select:b=>b.location.pathname}).startsWith(`/${e}/${t.id}`),[u,h]=S.useState(null),f=S.useRef(null),m=S.useRef(null),p=S.useRef(!1);p.current=!!i,i&&(u||m.current)&&(m.current&&(clearTimeout(m.current),m.current=null),u&&h(null));const g=b=>{if(p.current)return;const y=b.currentTarget.getBoundingClientRect();m.current=setTimeout(()=>{p.current||h(y)},550)},_=b=>{m.current&&(clearTimeout(m.current),m.current=null),!(f.current&&b.relatedTarget instanceof Node&&f.current.contains(b.relatedTarget))&&h(null)},v=u?Math.round(u.height*.9):0,x=u?u.width+v:0;return r.jsx(tS,{children:r.jsxs(Zt,{className:X(u&&"z-[55]"),children:[r.jsx(sS,{asChild:!0,children:r.jsx(us,{tooltip:u?void 0:t.title,isActive:d,onClick:()=>{se("sidebar_agent_pin_clicked",{agent_id:t.id,agent_title:t.title}),l(t.id),o&&a(!1)},onMouseEnter:g,onMouseLeave:_,children:r.jsx(zs,{icon:t.icon,name:t.title,size:"xs",className:"w-full h-full [&_svg]:w-1/2 [&_svg]:h-1/2"})})}),r.jsxs(iS,{children:[r.jsxs(hd,{onClick:()=>{const b=crypto.randomUUID();n({to:"/$org/$taskId",params:{org:e,taskId:b},search:{virtualmcpid:t.id}})},children:[r.jsx(Gr,{size:14}),"Settings"]}),r.jsx(rS,{}),r.jsxs(hd,{onClick:()=>{s(),d&&n({to:"/$org",params:{org:e}})},className:"",children:[r.jsx(fi,{size:14}),"Unpin"]})]}),u&&ds.createPortal(r.jsx("button",{ref:f,type:"button",onMouseLeave:()=>h(null),onClick:b=>{b.stopPropagation(),h(null),s(),n({to:"/$org",params:{org:e}})},className:X("flex items-center justify-center","bg-sidebar-accent text-muted-foreground","rounded-xl cursor-pointer","animate-in fade-in-0 slide-in-from-right-2","duration-150 [animation-timing-function:cubic-bezier(0.165,0.84,0.44,1)]","hover:text-foreground transition-colors"),style:{position:"fixed",top:u.top,left:u.left,height:u.height,width:x,paddingLeft:u.width,zIndex:50,boxShadow:"inset 0 0 0.5px 1px hsla(0, 0%, 100%, 0.075), 0 0 0 0.5px hsla(0, 0%, 0%, 0.12)"},children:r.jsx(fi,{size:14})}),document.body)]})})}function oS(t){const e=B.c(18);let s;e[0]!==t.agent.id?(s={id:t.agent.id},e[0]=t.agent.id,e[1]=s):s=e[1];const{attributes:i,listeners:n,setNodeRef:o,transform:a,transition:l,isDragging:c}=b2(s);let d;e[2]!==a?(d=Rr.Transform.toString(a?{...a,x:0}:null),e[2]=a,e[3]=d):d=e[3];const u=c?.5:void 0,h=c?100:void 0;let f;e[4]!==d||e[5]!==u||e[6]!==h||e[7]!==l?(f={transform:d,transition:l,opacity:u,zIndex:h},e[4]=d,e[5]=u,e[6]=h,e[7]=l,e[8]=f):f=e[8];const m=f;let p;e[9]!==c||e[10]!==t?(p=r.jsx(nS,{...t,isDragging:c}),e[9]=c,e[10]=t,e[11]=p):p=e[11];let g;return e[12]!==i||e[13]!==n||e[14]!==o||e[15]!==m||e[16]!==p?(g=r.jsx("div",{ref:o,style:m,...i,...n,tabIndex:-1,className:"w-full",children:p}),e[12]=i,e[13]=n,e[14]=o,e[15]=m,e[16]=p,e[17]=g):g=e[17],g}function aS(t){const e=B.c(9),{agent:s,onClick:i}=t;let n;e[0]!==s.icon||e[1]!==s.title?(n=r.jsx(zs,{icon:s.icon,name:s.title,size:"md",className:"transition-transform group-hover:scale-105"}),e[0]=s.icon,e[1]=s.title,e[2]=n):n=e[2];let o;e[3]!==s.title?(o=r.jsx("span",{className:"text-xs leading-tight text-center text-muted-foreground group-hover:text-foreground line-clamp-2 w-full",children:s.title}),e[3]=s.title,e[4]=o):o=e[4];let a;return e[5]!==i||e[6]!==n||e[7]!==o?(a=r.jsxs("button",{type:"button",onClick:i,className:"flex flex-col items-center gap-2 p-3 rounded-xl transition-colors hover:bg-accent cursor-pointer group",children:[n,o]}),e[5]=i,e[6]=n,e[7]=o,e[8]=a):a=e[8],a}function lS(t){const e=B.c(82),{onClose:s,onOpenImportDeco:i,onOpenGithubImport:n,onOpenDiagnosticsModal:o,onOpenLeanCanvasModal:a,onOpenStudioPackModal:l}=t,[c,d]=S.useState(""),u=oo(),{org:h}=be();let f;e[0]!==u?(f=u.filter(mS).map(fS),e[0]=u,e[1]=f):f=e[1];const m=f,{pin:p,isPinned:g}=mu(h.id,m);let _;e[2]===Symbol.for("react.memo_cache_sentinel")?(_={navigateOnCreate:!0},e[2]=_):_=e[2];const{createVirtualMCP:v,isCreating:x}=pu(_),[b]=Wi(),y=Pf(h.slug),C=lo();let j,V,w,k,T,I,A,N;if(e[3]!==u||e[4]!==v||e[5]!==x||e[6]!==g||e[7]!==C||e[8]!==y||e[9]!==s||e[10]!==o||e[11]!==n||e[12]!==i||e[13]!==a||e[14]!==l||e[15]!==p||e[16]!==b.experimental_vibecode||e[17]!==c){const O=c.toLowerCase();N=u.filter(uS).filter(le=>!c||le.title.toLowerCase().includes(O));let z;e[26]!==u?(z=u.some(hS),e[26]=u,e[27]=z):z=e[27];const $=z;j=Os.filter(le=>(!c||le.title.toLowerCase().includes(O))&&!(le.id==="studio-pack"&&$));let W;e[28]===Symbol.for("react.memo_cache_sentinel")?(W=Os.find(dS),e[28]=W):W=e[28];const F=W,G=F?u.find(le=>le.metadata?.type===F.id):void 0;let q;e[29]===Symbol.for("react.memo_cache_sentinel")?(q=Os.find(cS),e[29]=q):q=e[29];const H=q,ee=H?u.find(le=>le.metadata?.type===H.id):void 0;let K;e[30]!==g||e[31]!==y||e[32]!==s||e[33]!==p?(K=le=>{g(le.id)||p(le.id),s(),d(""),y(le.id)},e[30]=g,e[31]=y,e[32]=s,e[33]=p,e[34]=K):K=e[34];const U=K,te=le=>{s(),d(""),le==="site-editor"?i():le==="site-diagnostics"?G?C(G.id):o():le==="lean-canvas"?ee?C(ee.id):a():le==="studio-pack"?l():y(le)};I="flex flex-col max-h-[min(640px,80dvh)]",e[35]!==c?(A=r.jsx(C2,{value:c,onChange:d,placeholder:"Search agents..."}),e[35]=c,e[36]=A):A=e[36],V="overflow-y-auto flex-1 min-h-0 px-3 pb-3",e[37]===Symbol.for("react.memo_cache_sentinel")?(w=r.jsx("div",{className:"px-1 pt-3 pb-2",children:r.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"Agents"})}),e[37]=w):w=e[37];let Y;e[38]!==v||e[39]!==s?(Y=async()=>{se("agent_create_new_clicked",{source:"browse_popover"}),await v(),s()},e[38]=v,e[39]=s,e[40]=Y):Y=e[40];let J,ie;e[41]===Symbol.for("react.memo_cache_sentinel")?(J=r.jsx("div",{className:"w-12 h-12 rounded-xl border-2 border-dashed border-border flex items-center justify-center shrink-0 transition-transform group-hover:scale-105",children:r.jsx(Qt,{size:16,className:"text-muted-foreground"})}),ie=r.jsx("span",{className:"text-xs leading-tight text-center text-muted-foreground group-hover:text-foreground",children:"Create new"}),e[41]=J,e[42]=ie):(J=e[41],ie=e[42]);let ue;e[43]!==x||e[44]!==Y?(ue=r.jsxs("button",{type:"button",disabled:x,onClick:Y,className:"flex flex-col items-center gap-2 p-3 rounded-xl transition-colors hover:bg-accent cursor-pointer group disabled:opacity-50 disabled:cursor-not-allowed",children:[J,ie]}),e[43]=x,e[44]=Y,e[45]=ue):ue=e[45];let de;e[46]!==s||e[47]!==i?(de=()=>{se("agent_import_clicked",{source:"deco_cx"}),i(),s()},e[46]=s,e[47]=i,e[48]=de):de=e[48];let xe,oe;e[49]===Symbol.for("react.memo_cache_sentinel")?(xe=r.jsx("div",{className:"w-12 h-12 rounded-xl border-2 border-border flex items-center justify-center shrink-0 transition-transform group-hover:scale-105",children:r.jsx("img",{src:"/logos/deco%20logo.svg",alt:"deco.cx",className:"size-5"})}),oe=r.jsx("span",{className:"text-xs leading-tight text-center text-muted-foreground group-hover:text-foreground",children:"Import deco.cx"}),e[49]=xe,e[50]=oe):(xe=e[49],oe=e[50]);let he;e[51]!==de?(he=r.jsxs("button",{type:"button",onClick:de,className:"flex flex-col items-center gap-2 p-3 rounded-xl transition-colors hover:bg-accent cursor-pointer group",children:[xe,oe]}),e[51]=de,e[52]=he):he=e[52];let me;e[53]!==s||e[54]!==n||e[55]!==b.experimental_vibecode?(me=b.experimental_vibecode&&r.jsxs("button",{type:"button",onClick:()=>{se("agent_import_clicked",{source:"github"}),n(),s()},className:"flex flex-col items-center gap-2 p-3 rounded-xl transition-colors hover:bg-accent cursor-pointer group",children:[r.jsx("div",{className:"w-12 h-12 rounded-xl border-2 border-border flex items-center justify-center shrink-0 transition-transform group-hover:scale-105",children:r.jsx(fu,{className:"size-5 text-muted-foreground"})}),r.jsx("span",{className:"text-xs leading-tight text-center text-muted-foreground group-hover:text-foreground",children:"Import GitHub"})]}),e[53]=s,e[54]=n,e[55]=b.experimental_vibecode,e[56]=me):me=e[56];let fe;e[57]!==U?(fe=le=>r.jsx(aS,{agent:le,onClick:()=>U(le)},le.id),e[57]=U,e[58]=fe):fe=e[58],k=r.jsxs("div",{className:"grid grid-cols-3 gap-1",children:[ue,he,me,N.map(fe)]}),T=j.length>0&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"px-1 pt-4 pb-2",children:r.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"Agent templates"})}),r.jsx("div",{className:"grid grid-cols-3 gap-1",children:j.map(le=>r.jsxs("button",{type:"button",onClick:()=>{se("agent_template_clicked",{template_id:le.id,template_title:le.title}),te(le.id)},className:"flex flex-col items-center gap-2 p-3 rounded-xl transition-colors hover:bg-accent cursor-pointer group disabled:opacity-50 disabled:cursor-not-allowed",children:[r.jsx(zs,{icon:le.icon,name:le.title,size:"md",className:"transition-transform group-hover:scale-105"}),r.jsx("span",{className:"text-xs leading-tight text-center text-muted-foreground group-hover:text-foreground line-clamp-2 w-full",children:le.title})]},le.id))})]}),e[3]=u,e[4]=v,e[5]=x,e[6]=g,e[7]=C,e[8]=y,e[9]=s,e[10]=o,e[11]=n,e[12]=i,e[13]=a,e[14]=l,e[15]=p,e[16]=b.experimental_vibecode,e[17]=c,e[18]=j,e[19]=V,e[20]=w,e[21]=k,e[22]=T,e[23]=I,e[24]=A,e[25]=N}else j=e[18],V=e[19],w=e[20],k=e[21],T=e[22],I=e[23],A=e[24],N=e[25];let E;e[59]!==j||e[60]!==x||e[61]!==c||e[62]!==N.length?(E=N.length===0&&j.length===0&&!x&&r.jsx("div",{className:"flex items-center justify-center py-6 text-xs text-muted-foreground",children:c?"No agents found":"No agents yet"}),e[59]=j,e[60]=x,e[61]=c,e[62]=N.length,e[63]=E):E=e[63];let R;e[64]!==V||e[65]!==w||e[66]!==k||e[67]!==T||e[68]!==E?(R=r.jsxs("div",{className:V,children:[w,k,T,E]}),e[64]=V,e[65]=w,e[66]=k,e[67]=T,e[68]=E,e[69]=R):R=e[69];let M;e[70]!==h.slug?(M={org:h.slug},e[70]=h.slug,e[71]=M):M=e[71];let L;e[72]!==s?(L=()=>s(),e[72]=s,e[73]=L):L=e[73];let D;e[74]!==M||e[75]!==L?(D=r.jsx("div",{className:"border-t border-border px-3 py-2.5",children:r.jsx(Nh,{to:"/$org/settings/agents",params:M,onClick:L,className:"text-xs text-muted-foreground hover:text-foreground transition-colors flex items-center justify-center",children:"See all agents"})}),e[74]=M,e[75]=L,e[76]=D):D=e[76];let P;return e[77]!==R||e[78]!==D||e[79]!==I||e[80]!==A?(P=r.jsxs("div",{className:I,children:[A,R,D]}),e[77]=R,e[78]=D,e[79]=I,e[80]=A,e[81]=P):P=e[81],P}function cS(t){return t.id==="lean-canvas"}function dS(t){return t.id==="site-diagnostics"}function hS(t){return cg(t.id)}function uS(t){return!Mn(t.id)}function fS(t){return t.id}function mS(t){return t.pinned}function pS(){const t=B.c(27),[e,s]=S.useState(!1),[i,n]=S.useState(!1),[o,a]=S.useState(!1),[l,c]=S.useState(!1),[d,u]=S.useState(!1),[h,f]=S.useState(!1),m=Rs(),{setOpenMobile:p}=qr();let g;t[0]!==m||t[1]!==p?(g=()=>{s(!1),m&&p(!1)},t[0]=m,t[1]=p,t[2]=g):g=t[2];const _=g;let v;t[3]!==_||t[4]!==e?(v=e&&r.jsx(S.Suspense,{fallback:r.jsx("div",{className:"flex items-center justify-center py-8",children:r.jsx(Bi,{className:"h-4 w-24"})}),children:r.jsx(lS,{onClose:_,onOpenImportDeco:()=>n(!0),onOpenGithubImport:()=>{a(!0),_()},onOpenDiagnosticsModal:()=>c(!0),onOpenLeanCanvasModal:()=>u(!0),onOpenStudioPackModal:()=>f(!0)})}),t[3]=_,t[4]=e,t[5]=v):v=t[5];const x=v;let b;t[6]!==m||t[7]!==e||t[8]!==x?(b=m?r.jsxs(r.Fragment,{children:[r.jsx(Zt,{children:r.jsx(us,{tooltip:"Browse agents",className:"bg-muted/75 hover:bg-sidebar-accent",onClick:()=>{se("agent_browser_opened",{surface:"mobile_drawer"}),s(!0)},children:r.jsx(Qt,{className:"!opacity-100"})})}),r.jsx(Si,{open:e,onOpenChange:s,direction:"bottom",children:r.jsxs(yi,{className:"max-h-[85dvh] p-0",children:[r.jsx(bi,{className:"sr-only",children:"Browse agents"}),x]})})]}):r.jsxs(li,{open:e,onOpenChange:T=>{T&&!e&&se("agent_browser_opened",{surface:"desktop_popover"}),s(T)},children:[r.jsx(Zt,{children:r.jsx(oi,{asChild:!0,children:r.jsx(us,{tooltip:"Browse agents",className:"bg-muted/75 hover:bg-sidebar-accent",children:r.jsx(Qt,{className:"!opacity-100"})})})}),r.jsx(ai,{className:"w-[380px] p-0 overflow-hidden",side:"right",align:"start",children:x})]}),t[6]=m,t[7]=e,t[8]=x,t[9]=b):b=t[9];let y;t[10]!==i?(y=r.jsx(Bn,{open:i,onOpenChange:n}),t[10]=i,t[11]=y):y=t[11];let C;t[12]!==o?(C=r.jsx(p_,{open:o,onOpenChange:a}),t[12]=o,t[13]=C):C=t[13];let j;t[14]!==l?(j=r.jsx(uu,{open:l,onOpenChange:c}),t[14]=l,t[15]=j):j=t[15];let V;t[16]!==d?(V=r.jsx(g_,{open:d,onOpenChange:u}),t[16]=d,t[17]=V):V=t[17];let w;t[18]!==h?(w=r.jsx(__,{open:h,onOpenChange:f}),t[18]=h,t[19]=w):w=t[19];let k;return t[20]!==b||t[21]!==y||t[22]!==C||t[23]!==j||t[24]!==V||t[25]!==w?(k=r.jsxs(r.Fragment,{children:[b,y,C,j,V,w]}),t[20]=b,t[21]=y,t[22]=C,t[23]=j,t[24]=V,t[25]=w,t[26]=k):k=t[26],k}function gS(){const t=B.c(34),e=oo(),{org:s}=be();let i;t[0]!==e?(i=e.filter(bS).map(vS),t[0]=e,t[1]=i):i=t[1];const n=i,{pinnedIds:o,unpin:a,reorder:l}=mu(s.id,n),c=new Map(e.map(xS)),d=o.map(D=>c.get(D)).filter(_S);let u;t[2]===Symbol.for("react.memo_cache_sentinel")?(u={activationConstraint:{distance:5}},t[2]=u):u=t[2];let h;t[3]===Symbol.for("react.memo_cache_sentinel")?(h={coordinateGetter:w2},t[3]=h):h=t[3];const f=Q0(Qc(Wl,u),Qc(Fl,h));let m;t[4]!==o||t[5]!==l?(m=D=>{const{active:P,over:O}=D;if(!O||P.id===O.id)return;const z=o.indexOf(P.id),$=o.indexOf(O.id);z===-1||$===-1||l(Ul([...o],z,$))},t[4]=o,t[5]=l,t[6]=m):m=t[6];const p=m,g=Ur,_="py-0 px-0 mt-2 flex-1 min-h-0";let v;t[7]===Symbol.for("react.memo_cache_sentinel")?(v=r.jsx("div",{className:"h-px bg-border mx-2 mb-2"}),t[7]=v):v=t[7];const x=Kr,b="flex flex-1 min-h-0 flex-col overflow-y-auto [scrollbar-width:none] [-ms-overflow-style:none] [&::-webkit-scrollbar]:hidden",y=gs,C="gap-2";let j;t[8]===Symbol.for("react.memo_cache_sentinel")?(j=r.jsx(pS,{}),t[8]=j):j=t[8];const V=e2,w=ey,k=f2,T=h2;let I;t[9]!==s.slug||t[10]!==a?(I=D=>r.jsx(oS,{agent:D,org:s.slug,onUnpin:()=>a(D.id)},D.id),t[9]=s.slug,t[10]=a,t[11]=I):I=t[11];const A=d.map(I);let N;t[12]!==k||t[13]!==o||t[14]!==T||t[15]!==A?(N=r.jsx(k,{items:o,strategy:T,children:A}),t[12]=k,t[13]=o,t[14]=T,t[15]=A,t[16]=N):N=t[16];let E;t[17]!==V||t[18]!==p||t[19]!==f||t[20]!==N||t[21]!==w?(E=r.jsx(V,{sensors:f,collisionDetection:w,onDragEnd:p,children:N}),t[17]=V,t[18]=p,t[19]=f,t[20]=N,t[21]=w,t[22]=E):E=t[22];let R;t[23]!==y||t[24]!==E||t[25]!==j?(R=r.jsxs(y,{className:C,children:[j,E]}),t[23]=y,t[24]=E,t[25]=j,t[26]=R):R=t[26];let M;t[27]!==x||t[28]!==R?(M=r.jsx(x,{className:b,children:R}),t[27]=x,t[28]=R,t[29]=M):M=t[29];let L;return t[30]!==g||t[31]!==M||t[32]!==v?(L=r.jsxs(g,{className:_,children:[v,M]}),t[30]=g,t[31]=M,t[32]=v,t[33]=L):L=t[33],L}function _S(t){return!!t}function xS(t){return[t.id,t]}function vS(t){return t.id}function bS(t){return t.pinned}function Lf(){const t=B.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=r.jsx(S.Suspense,{fallback:r.jsx(Ur,{className:"py-0 px-0",children:r.jsx(Kr,{children:r.jsx(gs,{className:"gap-2",children:r.jsx(Zt,{children:r.jsxs("div",{className:"flex items-center gap-2 px-2 py-2",children:[r.jsx(Bi,{className:"h-4 w-4 rounded"}),r.jsx(Bi,{className:"h-4 flex-1"})]})})})})}),children:r.jsx(gS,{})}),t[0]=e):e=t[0],e}function yS(){const t=B.c(4),e=Ju();let s;t[0]===Symbol.for("react.memo_cache_sentinel")?(s=r.jsx(P0,{}),t[0]=s):s=t[0];let i;t[1]===Symbol.for("react.memo_cache_sentinel")?(i=r.jsx(Cs,{children:r.jsx(S.Suspense,{fallback:null,children:r.jsx(Lf,{})})}),t[1]=i):i=t[1];let n;return t[2]!==e?(n=r.jsx(ef,{sections:e,footer:s,additionalContent:i}),t[2]=e,t[3]=n):n=t[3],n}function SS(t){const e=B.c(5),{onClose:s}=t,i=Ju();let n;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=r.jsx(L0,{}),e[0]=n):n=e[0];let o;e[1]===Symbol.for("react.memo_cache_sentinel")?(o=r.jsx(Cs,{children:r.jsx(S.Suspense,{fallback:null,children:r.jsx(Lf,{})})}),e[1]=o):o=e[1];let a;return e[2]!==s||e[3]!==i?(a=r.jsx(u0,{sections:i,onClose:s,footer:n,additionalContent:o}),e[2]=s,e[3]=i,e[4]=a):a=e[4],a}async function wS(t,e,s){const i=await t.callTool({name:e,arguments:s});if(i.isError){const n=i.content?.[0]?.text??`Tool ${e} failed without a message`;throw new Error(n)}return i}const Bf=["VM_START"],un=new Map,VS=t=>`${t.virtualMcpId}::${t.branch??""}`;function ql(t){const e=Mt();return Br({mutationKey:Bf,mutationFn:async s=>{const i=VS(s),n=un.get(i);if(n)return n;const o=(async()=>(await wS(t,"VM_START",s)).structuredContent)();un.set(i,o);try{return await o}finally{un.get(i)===o&&un.delete(i)}},onSuccess:()=>{bn(e)}})}function CS(t,e){const s=B.c(3);let i;return s[0]!==e||s[1]!==t?(i={mutationKey:Bf,predicate:o=>{if(!t)return!1;const a=o.state.variables;return!a||a.virtualMcpId!==t?!1:(a.branch??"")===(e??"")}},s[0]=e,s[1]=t,s[2]=i):i=s[2],H_(i)>0}function jS(t,e){return t===1?!0:t===0?!1:e}function kS(t){const e=t.entityMetadata?.defaultMainView??null,s=e==null||e.type==="chat",i=t.mainParamPresent?t.mainParamValue!=="0":!s,n=s?!0:t.entityMetadata?.chatDefaultOpen??!1;return{mainOpen:i,chatOpen:n}}function ud(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 NS(t,e){return t===1?!0:t===0?!1:e}function AS(t,e){const s=Ke(),i=vi({strict:!1}),n=$r({strict:!1}),o=Mt(),a=Su(),{locator:l}=be(),{virtualMcpId:c,orgSlug:d,isAgentRoute:u}=e,h=kS({entityMetadata:t,mainParamPresent:i.main!==void 0,mainParamValue:i.main}),f=NS(i.chat,h.chatOpen),m=h.mainOpen,p=S.useRef(crypto.randomUUID()),g=n.taskId??p.current,_="/$org/$taskId",v=T=>({org:d,taskId:T}),x=u?{virtualmcpid:c}:{},b=(T,I)=>{s({to:_,params:v(g),search:A=>({...A,...T}),replace:I?.replace??!1})},y=(T,I)=>{s({to:_,params:v(T),search:A=>{const N={};return I?N.virtualmcpid=I:u&&(N.virtualmcpid=c),A.tasks&&(N.tasks=A.tasks),N}})},C=()=>{m?b({main:"0"},{replace:!0}):b({main:Hp(t)},{replace:!0})},j=()=>{b({chat:f?0:1},{replace:!0})},V=()=>{f||b({chat:1},{replace:!0})},w=async()=>{const T=crypto.randomUUID(),I=Lh(o,l,g);try{await a.create.mutateAsync({id:T,virtual_mcp_id:c,...I?{branch:I}:{}})}catch{}s({to:_,params:v(T),search:A=>{const N={...x,chat:1};return A.tasks&&(N.tasks=A.tasks),N}})},k=T=>{b({main:T},{replace:!0})};return{taskId:g,mainOpen:m,chatOpen:f,mainParam:i.main,setTaskId:y,toggleMain:C,toggleChat:j,openChat:V,createNewTask:w,openTab:k}}const Gl=S.createContext(null);function ES(t){const e=B.c(15),{children:s}=t,i=Ke();let n;e[0]===Symbol.for("react.memo_cache_sentinel")?(n={strict:!1},e[0]=n):n=e[0];const o=vi(n);let a;e[1]===Symbol.for("react.memo_cache_sentinel")?(a={owner:"all",status:"open"},e[1]=a):a=e[1];const{tasks:l}=ia(a);let c;e[2]!==o.tasks||e[3]!==l.length?(c=()=>jS(o.tasks,l.length>0),e[2]=o.tasks,e[3]=l.length,e[4]=c):c=e[4];const[d,u]=S.useState(c);let h,f;e[5]!==i||e[6]!==d?(h=()=>{i({search:(v=>({...v,tasks:d?1:0})),replace:!0})},f=[d,i],e[5]=i,e[6]=d,e[7]=h,e[8]=f):(h=e[7],f=e[8]),S.useEffect(h,f);let m;e[9]===Symbol.for("react.memo_cache_sentinel")?(m=()=>u(IS),e[9]=m):m=e[9];const p=m;let g;e[10]!==d?(g={tasksOpen:d,toggleTasks:p},e[10]=d,e[11]=g):g=e[11];let _;return e[12]!==s||e[13]!==g?(_=r.jsx(Gl.Provider,{value:g,children:s}),e[12]=s,e[13]=g,e[14]=_):_=e[14],_}function IS(t){return!t}function Of(){const t=S.useContext(Gl);if(!t)throw new Error("useTasksPanelState must be used inside <TasksPanelStateProvider>");return t}function RS(){return S.useContext(Gl)}const $f=S.createContext(null);function ci(){const t=S.use($f);if(!t)throw new Error("Toolbar.* must be used inside <Toolbar>");return t}function ze(t){const e=B.c(10),{children:s}=t,[i,n]=S.useState(null),[o,a]=S.useState(null),[l,c]=S.useState(null),[d,u]=S.useState(null);let h;e[0]!==l||e[1]!==d||e[2]!==o||e[3]!==i?(h={togglesEl:i,setTogglesEl:n,tabsEl:o,setTabsEl:a,centerEl:l,setCenterEl:c,rightEl:d,setRightEl:u},e[0]=l,e[1]=d,e[2]=o,e[3]=i,e[4]=h):h=e[4];let f;e[5]!==s?(f=r.jsx("div",{className:"flex flex-col h-full min-h-0",children:s}),e[5]=s,e[6]=f):f=e[6];let m;return e[7]!==h||e[8]!==f?(m=r.jsx($f,{value:h,children:f}),e[7]=h,e[8]=f,e[9]=m):m=e[9],m}function TS(t){const e=B.c(2),{children:s}=t;let i;return e[0]!==s?(i=r.jsx("div",{className:"shrink-0 grid grid-cols-3 items-center pl-1 pr-2 pt-0.25 h-12",children:s}),e[0]=s,e[1]=i):i=e[1],i}function DS(t){const e=B.c(2),{children:s}=t;let i;return e[0]!==s?(i=r.jsx("div",{className:"flex items-center gap-0.5 min-w-0 justify-self-start",children:s}),e[0]=s,e[1]=i):i=e[1],i}function MS(t){const e=B.c(2),{children:s}=t;let i;return e[0]!==s?(i=r.jsx("div",{className:"flex items-center justify-end gap-0.5 min-w-0 justify-self-end",children:s}),e[0]=s,e[1]=i):i=e[1],i}function PS(){const t=B.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=r.jsx("button",{type:"button",onClick:BS,className:"flex size-7 shrink-0 items-center justify-center rounded-md text-sidebar-foreground/60 hover:bg-sidebar-accent hover:text-sidebar-foreground transition-colors",title:"Go back",children:r.jsx(aa,{size:16})}),t[0]=e):e=t[0];let s;return t[1]===Symbol.for("react.memo_cache_sentinel")?(s=r.jsxs(r.Fragment,{children:[e,r.jsx("button",{type:"button",onClick:LS,className:"flex size-7 shrink-0 items-center justify-center rounded-md text-sidebar-foreground/60 hover:bg-sidebar-accent hover:text-sidebar-foreground transition-colors",title:"Go forward",children:r.jsx(Vl,{size:16})})]}),t[1]=s):s=t[1],s}function LS(){return window.history.forward()}function BS(){return window.history.back()}function OS(){const t=B.c(2),{setCenterEl:e}=ci();let s;return t[0]!==e?(s=r.jsx("div",{ref:e,className:"min-w-0 flex items-center justify-center gap-2"}),t[0]=e,t[1]=s):s=t[1],s}function $S(t){const e=B.c(3),{children:s}=t,{centerEl:i}=ci();if(!i)return null;let n;return e[0]!==i||e[1]!==s?(n=ds.createPortal(s,i),e[0]=i,e[1]=s,e[2]=n):n=e[2],n}function zS(){const t=B.c(2),{setTabsEl:e}=ci();let s;return t[0]!==e?(s=r.jsx("div",{ref:e,className:"shrink-0 flex items-center overflow-x-auto"}),t[0]=e,t[1]=s):s=t[1],s}function FS(t){const e=B.c(3),{children:s}=t,{tabsEl:i}=ci();if(!i)return null;let n;return e[0]!==s||e[1]!==i?(n=ds.createPortal(s,i),e[0]=s,e[1]=i,e[2]=n):n=e[2],n}function HS(){const t=B.c(2),{setTogglesEl:e}=ci();let s;return t[0]!==e?(s=r.jsx("div",{ref:e,className:"flex items-center gap-0.5 shrink-0 ml-0.5"}),t[0]=e,t[1]=s):s=t[1],s}function WS(t){const e=B.c(3),{children:s}=t,{togglesEl:i}=ci();if(!i)return null;let n;return e[0]!==s||e[1]!==i?(n=ds.createPortal(s,i),e[0]=s,e[1]=i,e[2]=n):n=e[2],n}function US(){const t=B.c(2),{setRightEl:e}=ci();let s;return t[0]!==e?(s=r.jsx("div",{ref:e,className:"flex items-center justify-end gap-0.5 shrink-0"}),t[0]=e,t[1]=s):s=t[1],s}function KS(t){const e=B.c(3),{children:s}=t,{rightEl:i}=ci();if(!i)return null;let n;return e[0]!==s||e[1]!==i?(n=ds.createPortal(s,i),e[0]=s,e[1]=i,e[2]=n):n=e[2],n}ze.Header=TS;ze.LeftColumn=DS;ze.RightColumn=MS;ze.Nav=PS;ze.CenterSlot=OS;ze.Center=$S;ze.TabsSlot=zS;ze.Tabs=FS;ze.TogglesSlot=HS;ze.Toggles=WS;ze.RightSlot=US;ze.Right=KS;const qS=280;function GS(){const t=B.c(2),{tasksOpen:e}=Of();if(!e)return null;let s;t[0]===Symbol.for("react.memo_cache_sentinel")?(s={width:`${qS}px`},t[0]=s):s=t[0];let i;return t[1]===Symbol.for("react.memo_cache_sentinel")?(i=r.jsx("aside",{className:"shrink-0 h-full bg-sidebar pb-1",style:s,children:r.jsx("div",{className:"h-full p-0.5 pt-0.25",children:r.jsx("div",{className:"h-full bg-background rounded-[0.75rem] overflow-hidden card-shadow",children:r.jsx(Xu,{})})})}),t[1]=i):i=t[1],i}function YS(){const t=B.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=r.jsx(S.Suspense,{fallback:null,children:r.jsx(GS,{})}),t[0]=e):e=t[0],e}const XS={settings:wg,automations:Hh,env:fl,preview:Zh,git:gr};function fd(t){const e=Fr(t);if(e.type==="icon"){const s=Hr(e.name);return s?{kind:"component",Component:s}:null}return e.type==="url"?{kind:"url",src:e.url}:null}function Po(t){if(t.kind==="system")return{kind:"component",Component:XS[t.tabId]};const e=fd(t.iconUrl);if(e)return e;if(!t.appId)return{kind:"fallback"};const s=t.connections.find(n=>n.id===t.appId);if(!s)return{kind:"fallback"};const i=fd(s.icon);return i||{kind:"fallback"}}function JS(t){const{org:e}=be(),s=Me({connectionId:Wt,orgId:e.id}),{data:i}=wh({queryKey:lt.threadMetadata(t),queryFn:async()=>{if(!s||!t)return null;try{const n=await s.callTool({name:"COLLECTION_THREADS_GET",arguments:{id:t}});return(n.structuredContent??n).item?.metadata??null}catch{return null}},staleTime:3e4});return i}function zf(t){const e=B.c(8),s=Ke();let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i={strict:!1},e[0]=i):i=e[0];const n=vi(i),o=ts(t.virtualMcpId),a=JS(t.taskId),{currentBranch:l}=es(),c=o?.metadata?.ui??null,d=c?.layout??null,u=d?.tabs??[],h=c?.pinnedViews??[],f=a?.expanded_tools??[],m=!!(o&&Fs(o));let p;e[1]===Symbol.for("react.memo_cache_sentinel")?(p={includeVirtual:!0},e[1]=p):p=e[1];const g=Wr(p),{activeTab:_,mainOpen:v}=Wp({mainParam:n.main,metadata:d?{defaultMainView:d.defaultMainView??null,tabs:u.map(QS)}:null}),x=Ih(_),b=[];m&&(b.push({id:"preview",title:"Preview"}),b.push({id:"env",title:"Terminal"}),b.push({id:"git",title:l??"git"})),b.push({id:"settings",title:"Settings"}),b.push({id:"automations",title:"Automations"});const y=new Map;for(const k of f){const T=ra(k.appId,k.toolName);y.set(T,{id:T,title:k.toolName,appId:k.appId,iconKey:k.toolName})}for(const k of h){const T=ra(k.connectionId,k.toolName);y.set(T,{id:T,title:k.label||k.toolName,appId:k.connectionId,iconKey:k.toolName,iconUrl:k.icon??null})}let C;e[2]!==g?(C=k=>({id:k.id,title:k.title,kind:"agent",icon:Po({tabId:k.id,kind:"agent",appId:k.view.appId,connections:g})}),e[2]=g,e[3]=C):C=e[3];const j=[...u.map(C),...Array.from(y.values()).map(k=>({id:k.id,title:k.title,kind:"expanded",icon:Po({tabId:k.iconKey,kind:"expanded",appId:k.appId,iconUrl:k.iconUrl,connections:g})})),...b.map(k=>({id:k.id,title:k.title,kind:"system",icon:Po({tabId:k.id,kind:"system",connections:g})}))];let V;return e[4]!==_||e[5]!==v||e[6]!==s?(V=k=>{const T=Up({clickedId:k,activeTab:_,mainOpen:v});s({to:".",search:I=>({...I,main:T}),replace:!0})},e[4]=_,e[5]=v,e[6]=s,e[7]=V):V=e[7],{activeTab:_,mainOpen:v,setActiveTab:V,systemTabs:b,layoutTabs:u,expandedTools:f,automationTabParsed:x,tabs:j}}function QS(t){return{id:t.id}}function ZS(t){const e=B.c(84),{value:s,onChange:i,onColorChange:n,name:o,size:a,className:l,avatarClassName:c,showHoverOverlay:d,disabled:u}=t,h=a===void 0?"lg":a,f=d===void 0?!0:d,m=u===void 0?!1:u,[p,g]=S.useState(!1),[_,v]=S.useState("icons"),[x,b]=S.useState(""),[y,C]=S.useState("blue");let j;e[0]!==s?(j=Fr(s),e[0]=s,e[1]=j):j=e[1];const V=j,w=V.type==="icon"||V.type==="url"&&V.color?V.color:y;let k;e[2]!==i||e[3]!==w?(k=ve=>{i(Co(ve,w))},e[2]=i,e[3]=w,e[4]=k):k=e[4];const T=k;let I;e[5]!==i||e[6]!==n||e[7]!==V.name||e[8]!==V.type||e[9]!==V.url?(I=ve=>{C(ve),n?.(ve),V.type==="icon"?i(Co(V.name,ve)):V.type==="url"&&i(pc(V.url,ve))},e[5]=i,e[6]=n,e[7]=V.name,e[8]=V.type,e[9]=V.url,e[10]=I):I=e[10];const A=I;let N;e[11]!==i||e[12]!==w?(N=ve=>{i(pc(ve,w)),g(!1)},e[11]=i,e[12]=w,e[13]=N):N=e[13];const E=N;let R;e[14]!==i||e[15]!==w?(R=()=>{const ve=gl(),Ce=ve[Math.floor(Math.random()*ve.length)];i(Co(Ce,w))},e[14]=i,e[15]=w,e[16]=R):R=e[16];const M=R;let L,D,P,O,z,$,W,F;if(e[17]!==l||e[18]!==m||e[19]!==p||e[20]!==h){const ve={xs:"rounded-md",sm:"rounded-lg","sm+":"rounded-xl",md:"rounded-xl",lg:"rounded-2xl",xl:"rounded-2xl"};D=li,$=m?!1:p,W=g,L=oi,z=!0,F="button",P=m,O=X("relative group overflow-hidden",m?"cursor-default opacity-50":"cursor-pointer",ve[h],l),e[17]=l,e[18]=m,e[19]=p,e[20]=h,e[21]=L,e[22]=D,e[23]=P,e[24]=O,e[25]=z,e[26]=$,e[27]=W,e[28]=F}else L=e[21],D=e[22],P=e[23],O=e[24],z=e[25],$=e[26],W=e[27],F=e[28];let G;e[29]!==c||e[30]!==o||e[31]!==h||e[32]!==s?(G=r.jsx(zs,{icon:s,name:o,size:h,className:c}),e[29]=c,e[30]=o,e[31]=h,e[32]=s,e[33]=G):G=e[33];let q;e[34]!==m||e[35]!==f?(q=f&&!m&&r.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/50 opacity-0 group-hover:opacity-100 transition-opacity",children:r.jsx(pl,{size:16,className:"text-white"})}),e[34]=m,e[35]=f,e[36]=q):q=e[36];let H;e[37]!==P||e[38]!==O||e[39]!==G||e[40]!==q||e[41]!==F?(H=r.jsxs("button",{type:F,disabled:P,className:O,children:[G,q]}),e[37]=P,e[38]=O,e[39]=G,e[40]=q,e[41]=F,e[42]=H):H=e[42];let ee;e[43]!==L||e[44]!==z||e[45]!==H?(ee=r.jsx(L,{asChild:z,children:H}),e[43]=L,e[44]=z,e[45]=H,e[46]=ee):ee=e[46];let K;e[47]!==o||e[48]!==s?(K=r.jsx("div",{className:"flex items-center justify-center py-4",children:r.jsx(zs,{icon:s,name:o,size:"xl"})}),e[47]=o,e[48]=s,e[49]=K):K=e[49];let U;e[50]===Symbol.for("react.memo_cache_sentinel")?(U=()=>v("icons"),e[50]=U):U=e[50];const te=_==="icons"?"border-foreground text-foreground":"border-transparent text-muted-foreground hover:text-foreground";let Y;e[51]!==te?(Y=X("px-3 py-2 text-sm font-medium border-b-2 -mb-px transition-colors",te),e[51]=te,e[52]=Y):Y=e[52];let J;e[53]!==Y?(J=r.jsx("button",{type:"button",onClick:U,className:Y,children:"Icons"}),e[53]=Y,e[54]=J):J=e[54];let ie;e[55]===Symbol.for("react.memo_cache_sentinel")?(ie=()=>v("upload"),e[55]=ie):ie=e[55];const ue=_==="upload"?"border-foreground text-foreground":"border-transparent text-muted-foreground hover:text-foreground";let de;e[56]!==ue?(de=X("px-3 py-2 text-sm font-medium border-b-2 -mb-px transition-colors",ue),e[56]=ue,e[57]=de):de=e[57];let xe;e[58]!==de?(xe=r.jsx("button",{type:"button",onClick:ie,className:de,children:"Upload"}),e[58]=de,e[59]=xe):xe=e[59];let oe;e[60]===Symbol.for("react.memo_cache_sentinel")?(oe=r.jsx("div",{className:"flex-1"}),e[60]=oe):oe=e[60];let he;e[61]!==J||e[62]!==xe?(he=r.jsxs("div",{className:"flex items-center border-b border-border px-3",children:[J,xe,oe]}),e[61]=J,e[62]=xe,e[63]=he):he=e[63];let me;e[64]!==A||e[65]!==M||e[66]!==T||e[67]!==E||e[68]!==V.name||e[69]!==V.type||e[70]!==x||e[71]!==w||e[72]!==_?(me=_==="icons"?r.jsx(iw,{search:x,onSearchChange:b,selectedColor:w,onColorChange:A,onSelectIcon:T,onRandom:M,currentIconName:V.type==="icon"?V.name:null}):r.jsx(rw,{onUpload:E}),e[64]=A,e[65]=M,e[66]=T,e[67]=E,e[68]=V.name,e[69]=V.type,e[70]=x,e[71]=w,e[72]=_,e[73]=me):me=e[73];let fe;e[74]!==K||e[75]!==he||e[76]!==me?(fe=r.jsx(ai,{align:"start",className:"w-80 p-0",onOpenAutoFocus:ew,children:r.jsxs("div",{className:"flex flex-col",children:[K,he,me]})}),e[74]=K,e[75]=he,e[76]=me,e[77]=fe):fe=e[77];let le;return e[78]!==D||e[79]!==$||e[80]!==W||e[81]!==ee||e[82]!==fe?(le=r.jsxs(D,{open:$,onOpenChange:W,children:[ee,fe]}),e[78]=D,e[79]=$,e[80]=W,e[81]=ee,e[82]=fe,e[83]=le):le=e[83],le}function ew(t){return t.preventDefault()}function tw(t){const e=B.c(27),{selectedColor:s,onColorChange:i}=t,[n,o]=S.useState(!1);let a,l,c,d,u,h,f;if(e[0]!==n||e[1]!==s){const x=Wh(s);l=li,h=n,f=o,a=oi,u=!0,c="button",d=X("h-6 w-6 rounded-full shrink-0 ring-2 ring-offset-2 ring-offset-background transition-all cursor-pointer hover:scale-110",x.dot,"ring-foreground/20"),e[0]=n,e[1]=s,e[2]=a,e[3]=l,e[4]=c,e[5]=d,e[6]=u,e[7]=h,e[8]=f}else a=e[2],l=e[3],c=e[4],d=e[5],u=e[6],h=e[7],f=e[8];let m;e[9]!==c||e[10]!==d?(m=r.jsx("button",{type:c,className:d,title:"Change color"}),e[9]=c,e[10]=d,e[11]=m):m=e[11];let p;e[12]!==a||e[13]!==u||e[14]!==m?(p=r.jsx(a,{asChild:u,children:m}),e[12]=a,e[13]=u,e[14]=m,e[15]=p):p=e[15];let g;e[16]!==i||e[17]!==s?(g=Cg.map(x=>r.jsx("button",{type:"button",onClick:()=>{i(x.name),o(!1)},className:X("h-5 w-5 rounded-full transition-all shrink-0 cursor-pointer",x.dot,s===x.name?"ring-2 ring-offset-1 ring-offset-background ring-foreground/30 scale-110":"hover:scale-110"),title:x.name},x.name)),e[16]=i,e[17]=s,e[18]=g):g=e[18];let _;e[19]!==g?(_=r.jsx(ai,{align:"start",side:"right",sideOffset:8,className:"w-auto p-2",onOpenAutoFocus:sw,children:r.jsx("div",{className:"grid grid-cols-4 gap-1",children:g})}),e[19]=g,e[20]=_):_=e[20];let v;return e[21]!==l||e[22]!==h||e[23]!==f||e[24]!==p||e[25]!==_?(v=r.jsxs(l,{open:h,onOpenChange:f,children:[p,_]}),e[21]=l,e[22]=h,e[23]=f,e[24]=p,e[25]=_,e[26]=v):v=e[26],v}function sw(t){return t.preventDefault()}function iw(t){const e=B.c(44),{search:s,onSearchChange:i,selectedColor:n,onColorChange:o,onSelectIcon:a,onRandom:l,currentIconName:c}=t;let d,u,h,f,m,p,g;if(e[0]!==c||e[1]!==o||e[2]!==l||e[3]!==i||e[4]!==a||e[5]!==s||e[6]!==n){const y=gl(),C=Wh(n);u=s.trim()?y.filter(A=>{const N=oa(A),E=s.toLowerCase();return N.includes(E)||A.toLowerCase().includes(E)}):y,p="flex flex-col";let j;e[14]===Symbol.for("react.memo_cache_sentinel")?(j=r.jsx(vl,{size:14,className:"absolute left-2 top-1/2 -translate-y-1/2 text-muted-foreground pointer-events-none"}),e[14]=j):j=e[14];let V;e[15]!==i?(V=A=>i(A.target.value),e[15]=i,e[16]=V):V=e[16];let w;e[17]!==s||e[18]!==V?(w=r.jsxs("div",{className:"relative flex-1",children:[j,r.jsx(bt,{value:s,onChange:V,placeholder:"Filter...",className:"h-8 text-xs pl-7"})]}),e[17]=s,e[18]=V,e[19]=w):w=e[19];let k;e[20]===Symbol.for("react.memo_cache_sentinel")?(k=r.jsx(Vg,{size:14,className:"text-muted-foreground"}),e[20]=k):k=e[20];let T;e[21]!==l?(T=r.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:k}),e[21]=l,e[22]=T):T=e[22];let I;e[23]!==o||e[24]!==n?(I=r.jsx(tw,{selectedColor:n,onColorChange:o}),e[23]=o,e[24]=n,e[25]=I):I=e[25],e[26]!==T||e[27]!==I||e[28]!==w?(g=r.jsxs("div",{className:"flex items-center gap-2 px-3 py-2",children:[w,T,I]}),e[26]=T,e[27]=I,e[28]=w,e[29]=g):g=e[29],d=Rh,m="h-56",h="grid grid-cols-9 gap-0.5 px-2 pb-2",f=u.map(A=>{const N=Hr(A);return N?r.jsx("button",{type:"button",onClick:()=>a(A),className:X("h-8 w-8 flex items-center justify-center rounded-md transition-colors cursor-pointer",c===A?X(C.bg,C.text):X(C.text,"hover:bg-accent")),title:A,children:r.jsx(N,{size:18})},A):null}),e[0]=c,e[1]=o,e[2]=l,e[3]=i,e[4]=a,e[5]=s,e[6]=n,e[7]=d,e[8]=u,e[9]=h,e[10]=f,e[11]=m,e[12]=p,e[13]=g}else d=e[7],u=e[8],h=e[9],f=e[10],m=e[11],p=e[12],g=e[13];let _;e[30]!==h||e[31]!==f?(_=r.jsx("div",{className:h,children:f}),e[30]=h,e[31]=f,e[32]=_):_=e[32];let v;e[33]!==u.length?(v=u.length===0&&r.jsx("div",{className:"flex items-center justify-center py-8 text-sm text-muted-foreground",children:"No icons found"}),e[33]=u.length,e[34]=v):v=e[34];let x;e[35]!==d||e[36]!==m||e[37]!==_||e[38]!==v?(x=r.jsxs(d,{className:m,children:[_,v]}),e[35]=d,e[36]=m,e[37]=_,e[38]=v,e[39]=x):x=e[39];let b;return e[40]!==p||e[41]!==g||e[42]!==x?(b=r.jsxs("div",{className:p,children:[g,x]}),e[40]=p,e[41]=g,e[42]=x,e[43]=b):b=e[43],b}function rw(t){const e=B.c(27),{onUpload:s}=t,i=S.useRef(null);let n;e[0]!==s?(n=j=>{const V=j.target.files?.[0];if(!V)return;if(V.size>2097152){pe.error("Image must be smaller than 2MB"),j.target.value="";return}const w=new FileReader;w.onerror=()=>{pe.error("Failed to read image file"),i.current&&(i.current.value="")},w.onloadend=()=>{w.readyState===FileReader.DONE&&w.result&&s(w.result),i.current&&(i.current.value="")},w.readAsDataURL(V)},e[0]=s,e[1]=n):n=e[1];const o=n,[a,l]=S.useState("");let c;e[2]!==s||e[3]!==a?(c=()=>{const j=a.trim();j&&(s(j),l(""))},e[2]=s,e[3]=a,e[4]=c):c=e[4];const d=c;let u;e[5]!==o?(u=r.jsx("input",{type:"file",ref:i,className:"hidden",accept:"image/*",onChange:o}),e[5]=o,e[6]=u):u=e[6];let h;e[7]===Symbol.for("react.memo_cache_sentinel")?(h=()=>i.current?.click(),e[7]=h):h=e[7];let f;e[8]===Symbol.for("react.memo_cache_sentinel")?(f=r.jsxs("button",{type:"button",onClick:h,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:[r.jsx(Qh,{size:20}),r.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=r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("span",{className:"text-xs text-muted-foreground",children:"or"}),r.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=j=>l(j.target.value),e[10]=p):p=e[10];let g;e[11]!==d?(g=j=>{j.key==="Enter"&&(j.preventDefault(),d())},e[11]=d,e[12]=g):g=e[12];let _;e[13]!==a||e[14]!==g?(_=r.jsx(bt,{value:a,onChange:p,placeholder:"Paste image URL...",className:"h-8 text-xs flex-1",onKeyDown:g}),e[13]=a,e[14]=g,e[15]=_):_=e[15];let v;e[16]!==a?(v=a.trim(),e[16]=a,e[17]=v):v=e[17];const x=!v;let b;e[18]!==d||e[19]!==x?(b=r.jsx(ne,{variant:"outline",size:"sm",className:"h-8 px-3 text-xs shrink-0",onClick:d,disabled:x,children:"Apply"}),e[18]=d,e[19]=x,e[20]=b):b=e[20];let y;e[21]!==b||e[22]!==_?(y=r.jsxs("div",{className:"flex items-center gap-1.5",children:[_,b]}),e[21]=b,e[22]=_,e[23]=y):y=e[23];let C;return e[24]!==y||e[25]!==u?(C=r.jsxs("div",{className:"flex flex-col gap-3 p-4",children:[u,f,m,y]}),e[24]=y,e[25]=u,e[26]=C):C=e[26],C}function nw(t){const e=B.c(5),{value:s}=t;let i;if(e[0]!==s){i=Symbol.for("react.early_return_sentinel");e:{const o=Fr(s);if(o.type==="icon"){const a=Hr(o.name);if(a){let l;e[2]!==a?(l=r.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 n;return e[4]===Symbol.for("react.memo_cache_sentinel")?(n=r.jsx(gu,{size:16,className:"text-muted-foreground"}),e[4]=n):n=e[4],n}function ow(t){const e=B.c(66),{value:s,onChange:i,className:n,disabled:o}=t,[a,l]=S.useState(!1),[c,d]=S.useState("");let u;e[0]!==s?(u=Fr(s),e[0]=s,e[1]=u):u=e[1];const h=u,f=h.type==="icon"?h.name:null;let m,p,g,_,v,x,b,y,C,j,V,w,k,T,I;if(e[2]!==n||e[3]!==f||e[4]!==o||e[5]!==i||e[6]!==a||e[7]!==c||e[8]!==s){const D=gl();_=c.trim()?D.filter(G=>{const q=c.toLowerCase();return oa(G).includes(q)||G.toLowerCase().includes(q)}):D,g=li,v=o?!1:a,x=l;const P=o?"cursor-default opacity-50":"cursor-pointer hover:bg-accent";let O;e[24]!==n||e[25]!==P?(O=X("size-7 shrink-0 rounded-md transition-colors flex items-center justify-center",P,n),e[24]=n,e[25]=P,e[26]=O):O=e[26];let z;e[27]!==s?(z=r.jsx(nw,{value:s}),e[27]=s,e[28]=z):z=e[28],e[29]!==o||e[30]!==O||e[31]!==z?(b=r.jsx(oi,{asChild:!0,children:r.jsx("button",{type:"button",disabled:o,className:O,children:z})}),e[29]=o,e[30]=O,e[31]=z,e[32]=b):b=e[32],p=ai,k="start",T="w-64 p-0",I=aw,V="flex flex-col";let $;e[33]===Symbol.for("react.memo_cache_sentinel")?($=r.jsx(vl,{size:14,className:"absolute left-2 top-1/2 -translate-y-1/2 text-muted-foreground pointer-events-none"}),e[33]=$):$=e[33];let W;e[34]===Symbol.for("react.memo_cache_sentinel")?(W=G=>d(G.target.value),e[34]=W):W=e[34],e[35]!==c?(w=r.jsx("div",{className:"px-2 py-2",children:r.jsxs("div",{className:"relative",children:[$,r.jsx(bt,{value:c,onChange:W,placeholder:"Filter...",className:"h-7 text-xs pl-7"})]})}),e[35]=c,e[36]=w):w=e[36],m=Rh,j="h-48",y="grid grid-cols-8 gap-0.5 px-2 pb-2";let F;e[37]!==f||e[38]!==i?(F=G=>{const q=Hr(G);return q?r.jsx("button",{type:"button",onClick:()=>{i(`icon://${G}`),l(!1)},className:X("h-7 w-7 flex items-center justify-center rounded-md transition-colors cursor-pointer",f===G?"bg-accent text-foreground":"text-muted-foreground hover:bg-accent hover:text-foreground"),title:oa(G),children:r.jsx(q,{size:16})},G):null},e[37]=f,e[38]=i,e[39]=F):F=e[39],C=_.map(F),e[2]=n,e[3]=f,e[4]=o,e[5]=i,e[6]=a,e[7]=c,e[8]=s,e[9]=m,e[10]=p,e[11]=g,e[12]=_,e[13]=v,e[14]=x,e[15]=b,e[16]=y,e[17]=C,e[18]=j,e[19]=V,e[20]=w,e[21]=k,e[22]=T,e[23]=I}else m=e[9],p=e[10],g=e[11],_=e[12],v=e[13],x=e[14],b=e[15],y=e[16],C=e[17],j=e[18],V=e[19],w=e[20],k=e[21],T=e[22],I=e[23];let A;e[40]!==y||e[41]!==C?(A=r.jsx("div",{className:y,children:C}),e[40]=y,e[41]=C,e[42]=A):A=e[42];let N;e[43]!==_.length?(N=_.length===0&&r.jsx("div",{className:"flex items-center justify-center py-6 text-xs text-muted-foreground",children:"No icons found"}),e[43]=_.length,e[44]=N):N=e[44];let E;e[45]!==m||e[46]!==A||e[47]!==N||e[48]!==j?(E=r.jsxs(m,{className:j,children:[A,N]}),e[45]=m,e[46]=A,e[47]=N,e[48]=j,e[49]=E):E=e[49];let R;e[50]!==E||e[51]!==V||e[52]!==w?(R=r.jsxs("div",{className:V,children:[w,E]}),e[50]=E,e[51]=V,e[52]=w,e[53]=R):R=e[53];let M;e[54]!==p||e[55]!==R||e[56]!==k||e[57]!==T||e[58]!==I?(M=r.jsx(p,{align:k,className:T,onOpenAutoFocus:I,children:R}),e[54]=p,e[55]=R,e[56]=k,e[57]=T,e[58]=I,e[59]=M):M=e[59];let L;return e[60]!==g||e[61]!==v||e[62]!==x||e[63]!==b||e[64]!==M?(L=r.jsxs(g,{open:v,onOpenChange:x,children:[b,M]}),e[60]=g,e[61]=v,e[62]=x,e[63]=b,e[64]=M,e[65]=L):L=e[65],L}function aw(t){return t.preventDefault()}function Nn(){const t=B.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=r.jsx("div",{className:"flex items-center justify-center h-32",children:r.jsx(Ee,{className:"animate-spin text-muted-foreground",size:24})}),t[0]=e):e=t[0],e}function Lo(t){return({error:e})=>e?.message?.includes("Method not found")||e?.code===-32601?r.jsx("div",{className:"flex-1 overflow-auto px-4 py-3 space-y-1",children:r.jsx("div",{className:"flex items-center justify-center h-32 text-sm text-muted-foreground",children:t})}):r.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center h-full p-6 text-center space-y-4",children:[r.jsx("div",{className:"bg-destructive/10 p-3 rounded-full",children:r.jsx(yh,{className:"h-6 w-6 text-destructive"})}),r.jsxs("div",{className:"space-y-2",children:[r.jsx("h3",{className:"text-lg font-medium",children:"Something went wrong"}),r.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 lw(t){const e=B.c(23),{item:s,isSelected:i,onToggle:n,disabled:o}=t,a=o?"cursor-not-allowed opacity-50":"cursor-pointer",l=i?"bg-accent/25":"hover:bg-muted/50";let c;e[0]!==a||e[1]!==l?(c=X("flex items-start gap-3 p-4 rounded-lg transition-colors",a,l),e[0]=a,e[1]=l,e[2]=c):c=e[2];let d;e[3]!==s.name?(d=r.jsx("p",{className:"text-sm font-medium leading-none truncate",children:s.name}),e[3]=s.name,e[4]=d):d=e[4];let u;e[5]!==s.tags?(u=s.tags&&r.jsx("span",{className:"shrink-0",children:s.tags}),e[5]=s.tags,e[6]=u):u=e[6];let h;e[7]!==d||e[8]!==u?(h=r.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[d,u]}),e[7]=d,e[8]=u,e[9]=h):h=e[9];let f;e[10]!==s.description?(f=s.description&&r.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]!==h||e[13]!==f?(m=r.jsxs("div",{className:"flex-1 min-w-0 space-y-2",children:[h,f]}),e[12]=h,e[13]=f,e[14]=m):m=e[14];let p;e[15]!==o||e[16]!==i||e[17]!==n?(p=r.jsx(D_,{checked:i,onCheckedChange:n,disabled:o,className:"mt-0.5"}),e[15]=o,e[16]=i,e[17]=n,e[18]=p):p=e[18];let g;return e[19]!==c||e[20]!==m||e[21]!==p?(g=r.jsxs("label",{className:c,children:[m,p]}),e[19]=c,e[20]=m,e[21]=p,e[22]=g):g=e[22],g}function Yl(t){const e=B.c(13),{items:s,selections:i,onToggle:n,emptyMessage:o,disabled:a}=t;let l,c,d;if(e[0]!==a||e[1]!==o||e[2]!==s||e[3]!==n||e[4]!==i){d=Symbol.for("react.early_return_sentinel");e:{const h=s.map(cw);if(s.length===0){let f;e[8]!==o?(f=r.jsx("div",{className:"flex-1 overflow-auto px-4 py-3 space-y-1",children:r.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],d=f;break e}l="flex-1 overflow-auto px-4 py-3 space-y-1",c=s.map(f=>r.jsx(lw,{item:f,isSelected:i===null||i?.includes(f.id),onToggle:()=>n(f.id,h),disabled:a},f.id))}e[0]=a,e[1]=o,e[2]=s,e[3]=n,e[4]=i,e[5]=l,e[6]=c,e[7]=d}else l=e[5],c=e[6],d=e[7];if(d!==Symbol.for("react.early_return_sentinel"))return d;let u;return e[10]!==l||e[11]!==c?(u=r.jsx("div",{className:l,children:c}),e[10]=l,e[11]=c,e[12]=u):u=e[12],u}function cw(t){return t.id}function dw(t){const e=B.c(12),{connectionId:s,selections:i,onToggle:n,disabled:o}=t,{org:a}=be();let l;e[0]!==s||e[1]!==a.id?(l={connectionId:s,orgId:a.id},e[0]=s,e[1]=a.id,e[2]=l):l=e[2];const c=Me(l);let d;e[3]!==c?(d={client:c},e[3]=c,e[4]=d):d=e[4];const{data:u}=v_(d);let h;e[5]!==u.tools?(h=u.tools.map(hw),e[5]=u.tools,e[6]=h):h=e[6];const f=h;let m;return e[7]!==o||e[8]!==f||e[9]!==n||e[10]!==i?(m=r.jsx(Yl,{items:f,selections:i,onToggle:n,emptyMessage:"No tools available",disabled:o}),e[7]=o,e[8]=f,e[9]=n,e[10]=i,e[11]=m):m=e[11],m}function hw(t){return{id:t.name,name:t.name,description:t.description,tags:r.jsx(R_,{annotations:t.annotations,_meta:t._meta})}}function uw(t){const e=B.c(12),{connectionId:s,selections:i,onToggle:n,disabled:o}=t,{org:a}=be();let l;e[0]!==s||e[1]!==a.id?(l={connectionId:s,orgId:a.id},e[0]=s,e[1]=a.id,e[2]=l):l=e[2];const c=Me(l);let d;e[3]!==c?(d={client:c},e[3]=c,e[4]=d):d=e[4];const{data:u}=Jg(d);let h;e[5]!==u.resources?(h=u.resources.map(fw),e[5]=u.resources,e[6]=h):h=e[6];const f=h;let m;return e[7]!==o||e[8]!==f||e[9]!==n||e[10]!==i?(m=r.jsx(Yl,{items:f,selections:i,onToggle:n,emptyMessage:"No resources available",disabled:o}),e[7]=o,e[8]=f,e[9]=n,e[10]=i,e[11]=m):m=e[11],m}function fw(t){return{id:t.name||t.uri,name:t.name||t.uri,description:t.description}}function mw(t){const e=B.c(12),{connectionId:s,selections:i,onToggle:n,disabled:o}=t,{org:a}=be();let l;e[0]!==s||e[1]!==a.id?(l={connectionId:s,orgId:a.id},e[0]=s,e[1]=a.id,e[2]=l):l=e[2];const c=Me(l);let d;e[3]!==c?(d={client:c},e[3]=c,e[4]=d):d=e[4];const{data:u}=Dh(d);let h;e[5]!==u.prompts?(h=u.prompts.map(pw),e[5]=u.prompts,e[6]=h):h=e[6];const f=h;let m;return e[7]!==o||e[8]!==f||e[9]!==n||e[10]!==i?(m=r.jsx(Yl,{items:f,selections:i,onToggle:n,emptyMessage:"No prompts available",disabled:o}),e[7]=o,e[8]=f,e[9]=n,e[10]=i,e[11]=m):m=e[11],m}function pw(t){return{id:t.name,name:t.name,description:t.description}}function gw(t){const e=B.c(54),{currentConnection:s,activeTab:i,selectedId:n,formData:o,toggleTool:a,toggleResource:l,togglePrompt:c,toggleAllTools:d,toggleAllResources:u,toggleAllPrompts:h,onTabChange:f}=t,m=o[n],p=i==="tools"?m?.tools===null:i==="resources"?m?.resources===null:m?.prompts===null;let g;e[0]!==i||e[1]!==n||e[2]!==h||e[3]!==u||e[4]!==d?(g=()=>{i==="tools"?d(n):i==="resources"?u(n):h(n)},e[0]=i,e[1]=n,e[2]=h,e[3]=u,e[4]=d,e[5]=g):g=e[5];const _=g;let v;e[6]!==s.icon||e[7]!==s.title?(v=r.jsx(Ms,{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 x;e[9]!==s.title?(x=r.jsx("h2",{className:"text-base font-semibold truncate",children:s.title}),e[9]=s.title,e[10]=x):x=e[10];let b;e[11]!==s.description?(b=s.description&&r.jsx("p",{className:"text-xs text-muted-foreground truncate",children:s.description}),e[11]=s.description,e[12]=b):b=e[12];let y;e[13]!==x||e[14]!==b?(y=r.jsxs("div",{className:"flex-1 min-w-0",children:[x,b]}),e[13]=x,e[14]=b,e[15]=y):y=e[15];let C;e[16]!==v||e[17]!==y?(C=r.jsx("div",{className:"px-6 pt-5 pb-4 shrink-0",children:r.jsxs("div",{className:"flex items-center gap-3",children:[v,y]})}),e[16]=v,e[17]=y,e[18]=C):C=e[18];let j;e[19]===Symbol.for("react.memo_cache_sentinel")?(j=[{id:"tools",label:"Tools"},{id:"resources",label:"Resources"},{id:"prompts",label:"Prompts"}],e[19]=j):j=e[19];let V;e[20]!==f?(V=L=>f(L),e[20]=f,e[21]=V):V=e[21];let w;e[22]!==i||e[23]!==V?(w=r.jsx(du,{tabs:j,activeTab:i,onTabChange:V}),e[22]=i,e[23]=V,e[24]=w):w=e[24];const k=p?"Deselect all":"Select all";let T;e[25]!==_||e[26]!==k?(T=r.jsx("button",{type:"button",onClick:_,className:"text-xs text-muted-foreground hover:text-foreground transition-colors",children:k}),e[25]=_,e[26]=k,e[27]=T):T=e[27];let I;e[28]!==T||e[29]!==w?(I=r.jsxs("div",{className:"flex items-center justify-between px-6 py-3 border-t border-border shrink-0",children:[w,T]}),e[28]=T,e[29]=w,e[30]=I):I=e[30];let A;e[31]!==i||e[32]!==o||e[33]!==n||e[34]!==a?(A=i==="tools"&&r.jsx(Cs,{fallback:Lo("Tools not supported by this server"),children:r.jsx(S.Suspense,{fallback:r.jsx(Nn,{}),children:r.jsx(dw,{connectionId:n,selections:o[n]?o[n].tools:[],onToggle:(L,D)=>a(n,L,D)})})}),e[31]=i,e[32]=o,e[33]=n,e[34]=a,e[35]=A):A=e[35];let N;e[36]!==i||e[37]!==o||e[38]!==n||e[39]!==l?(N=i==="resources"&&r.jsx(Cs,{fallback:Lo("Resources not supported by this server"),children:r.jsx(S.Suspense,{fallback:r.jsx(Nn,{}),children:r.jsx(uw,{connectionId:n,selections:o[n]?o[n].resources:[],onToggle:(L,D)=>l(n,L,D)})})}),e[36]=i,e[37]=o,e[38]=n,e[39]=l,e[40]=N):N=e[40];let E;e[41]!==i||e[42]!==o||e[43]!==n||e[44]!==c?(E=i==="prompts"&&r.jsx(Cs,{fallback:Lo("Prompts not supported by this server"),children:r.jsx(S.Suspense,{fallback:r.jsx(Nn,{}),children:r.jsx(mw,{connectionId:n,selections:o[n]?o[n].prompts:[],onToggle:(L,D)=>c(n,L,D)})})}),e[41]=i,e[42]=o,e[43]=n,e[44]=c,e[45]=E):E=e[45];let R;e[46]!==A||e[47]!==N||e[48]!==E?(R=r.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[A,N,E]}),e[46]=A,e[47]=N,e[48]=E,e[49]=R):R=e[49];let M;return e[50]!==I||e[51]!==R||e[52]!==C?(M=r.jsxs(r.Fragment,{children:[C,I,R]}),e[50]=I,e[51]=R,e[52]=C,e[53]=M):M=e[53],M}function _w(t){const e=B.c(11),{connectionId:s,onAuthenticate:i,children:n}=t;let o;e[0]!==s?(o={connectionId:s},e[0]=s,e[1]=o):o=e[1];const a=wu(o);if(a.supportsOAuth&&!a.isAuthenticated){let d;e[2]===Symbol.for("react.memo_cache_sentinel")?(d=r.jsx("div",{className:"flex items-center justify-center size-12 rounded-full bg-muted",children:r.jsx(jg,{size:22,className:"text-muted-foreground"})}),e[2]=d):d=e[2];let u;e[3]===Symbol.for("react.memo_cache_sentinel")?(u=r.jsxs("div",{className:"space-y-1",children:[r.jsx("p",{className:"text-sm font-medium",children:"Authorization required"}),r.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]=u):u=e[3];let h;e[4]!==s||e[5]!==i?(h=i&&r.jsx(ne,{variant:"outline",size:"sm",onClick:()=>i(s),children:"Authorize"}),e[4]=s,e[5]=i,e[6]=h):h=e[6];let f;return e[7]!==h?(f=r.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-4 p-8 text-center",children:[d,u,h]}),e[7]=h,e[8]=f):f=e[8],f}let c;return e[9]!==n?(c=r.jsx(r.Fragment,{children:n}),e[9]=n,e[10]=c):c=e[10],c}function xw(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 md(t){return Object.entries(t).map(([e,s])=>({connection_id:e,selected_tools:s.tools,selected_resources:s.resources,selected_prompts:s.prompts}))}function vw(t,e){return e.type==="SET_ACTIVE_TAB"?{...t,activeTab:e.payload}:t}function bw(t){const e=B.c(49),{open:s,onOpenChange:i,selectedId:n,form:o,connections:a,onAuthenticate:l}=t;let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c={activeTab:"tools"},e[0]=c):c=e[0];const[d,u]=S.useReducer(vw,c),h=wl(n??"");let f;e[1]!==a?(f=a??[],e[1]=a,e[2]=f):f=e[2];let m;e[3]!==f?(m=xw(f),e[3]=f,e[4]=m):m=e[4];const p=m;let g;e[5]!==o||e[6]!==p?(g=($,W,F,G)=>{const q=p[$]?.[W];let H;q===null?H=G.filter(K=>K!==F):q?.includes(F)?H=q.filter(K=>K!==F):(H=[...q??[],F],H.length===G.length&&(H=null));const ee={...p};ee[$]?ee[$]={...ee[$]}:ee[$]={tools:null,resources:null,prompts:null},ee[$][W]=H,o.setValue("connections",md(ee),{shouldDirty:!0,shouldTouch:!0})},e[5]=o,e[6]=p,e[7]=g):g=e[7];const _=g;let v;e[8]!==o||e[9]!==p?(v=($,W)=>{const G=p[$]?.[W]===null?[]:null,q={...p};q[$]?q[$]={...q[$]}:q[$]={tools:null,resources:null,prompts:null},q[$][W]=G,o.setValue("connections",md(q),{shouldDirty:!0,shouldTouch:!0})},e[8]=o,e[9]=p,e[10]=v):v=e[10];const x=v;let b;e[11]!==_?(b=($,W,F)=>_($,"tools",W,F),e[11]=_,e[12]=b):b=e[12];const y=b;let C;e[13]!==_?(C=($,W,F)=>_($,"resources",W,F),e[13]=_,e[14]=C):C=e[14];const j=C;let V;e[15]!==_?(V=($,W,F)=>_($,"prompts",W,F),e[15]=_,e[16]=V):V=e[16];const w=V;let k;e[17]!==x?(k=$=>x($,"tools"),e[17]=x,e[18]=k):k=e[18];const T=k;let I;e[19]!==x?(I=$=>x($,"resources"),e[19]=x,e[20]=I):I=e[20];const A=I;let N;e[21]!==x?(N=$=>x($,"prompts"),e[21]=x,e[22]=N):N=e[22];const E=N;if(!n||!h)return null;let R;e[23]===Symbol.for("react.memo_cache_sentinel")?(R=r.jsx(Nn,{}),e[23]=R):R=e[23];let M;e[24]===Symbol.for("react.memo_cache_sentinel")?(M=$=>u({type:"SET_ACTIVE_TAB",payload:$}),e[24]=M):M=e[24];let L;e[25]!==h||e[26]!==d.activeTab||e[27]!==p||e[28]!==n||e[29]!==E||e[30]!==A||e[31]!==T||e[32]!==w||e[33]!==j||e[34]!==y?(L=r.jsx(gw,{currentConnection:h,activeTab:d.activeTab,selectedId:n,formData:p,toggleTool:y,toggleResource:j,togglePrompt:w,toggleAllTools:T,toggleAllResources:A,toggleAllPrompts:E,onTabChange:M},n),e[25]=h,e[26]=d.activeTab,e[27]=p,e[28]=n,e[29]=E,e[30]=A,e[31]=T,e[32]=w,e[33]=j,e[34]=y,e[35]=L):L=e[35];let D;e[36]!==l||e[37]!==n||e[38]!==L?(D=r.jsx(S.Suspense,{fallback:R,children:r.jsx(_w,{connectionId:n,onAuthenticate:l,children:L})}),e[36]=l,e[37]=n,e[38]=L,e[39]=D):D=e[39];let P;e[40]!==i?(P=r.jsx(cl,{className:"px-6 py-4 border-t border-border shrink-0",children:r.jsx(ne,{variant:"outline",onClick:()=>i(!1),children:"Done"})}),e[40]=i,e[41]=P):P=e[41];let O;e[42]!==D||e[43]!==P?(O=r.jsxs(ms,{className:"sm:max-w-2xl h-[75vh] max-h-[75vh] flex flex-col p-0 gap-0 overflow-hidden w-[95vw]",children:[D,P]}),e[42]=D,e[43]=P,e[44]=O):O=e[44];let z;return e[45]!==i||e[46]!==s||e[47]!==O?(z=r.jsx(ps,{open:s,onOpenChange:i,children:O}),e[45]=i,e[46]=s,e[47]=O,e[48]=z):z=e[48],z}const Bo={tools:null,resources:null,prompts:null},yw=Cp.pick({status:!0,title:!0,description:!0,icon:!0,metadata:!0,connections:!0});function Sw(t){const s=new TextEncoder().encode(t),i=Array.from(s,n=>String.fromCharCode(n)).join("");return btoa(i)}function ww(t){const e=B.c(11),{url:s,agentId:i}=t,[n,o]=S.useState(!1);let a;e[0]!==i||e[1]!==s?(a=async()=>{se("agent_connect_action",{agent_id:i,action:"copy_url"}),await navigator.clipboard.writeText(s),o(!0),pe.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 c;e[3]!==n?(c=n?r.jsx(Jt,{size:20,className:"text-green-600"}):r.jsx(Li,{size:20}),e[3]=n,e[4]=c):c=e[4];const d=n?"Copied!":"Copy URL";let u;e[5]!==d?(u=r.jsx("span",{className:"text-xs font-medium",children:d}),e[5]=d,e[6]=u):u=e[6];let h;return e[7]!==l||e[8]!==c||e[9]!==u?(h=r.jsxs(ne,{type:"button",variant:"outline",onClick:l,className:"h-auto py-3 px-4 flex flex-col items-center gap-2",children:[c,u]}),e[7]=l,e[8]=c,e[9]=u,e[10]=h):h=e[10],h}function Vw(t){const e=B.c(8),{url:s,serverName:i,agentId:n}=t;let o;e[0]!==n||e[1]!==i||e[2]!==s?(o=()=>{se("agent_connect_action",{agent_id:n,action:"install_cursor"});const u=au(i),f=Sw(JSON.stringify({type:"http",url:s,headers:{"x-mesh-client":"Cursor"}},null,2)),m=`cursor://anysphere.cursor-deeplink/mcp/install?name=${encodeURIComponent(u)}&config=${encodeURIComponent(f)}`;window.open(m,"_blank"),pe.success("Opening Cursor...")},e[0]=n,e[1]=i,e[2]=s,e[3]=o):o=e[3];const a=o;let l,c;e[4]===Symbol.for("react.memo_cache_sentinel")?(l=r.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%)"}}),c=r.jsx("span",{className:"text-xs font-medium",children:"Install on Cursor"}),e[4]=l,e[5]=c):(l=e[4],c=e[5]);let d;return e[6]!==a?(d=r.jsxs(ne,{type:"button",variant:"outline",onClick:a,className:"h-auto py-3 px-4 flex flex-col items-center gap-2",children:[l,c]}),e[6]=a,e[7]=d):d=e[7],d}function Cw(t){const e=B.c(12),{url:s,serverName:i,agentId:n}=t,[o,a]=S.useState(!1);let l;e[0]!==n||e[1]!==i||e[2]!==s?(l=async()=>{se("agent_connect_action",{agent_id:n,action:"install_claude_code"});const m=au(i),g=JSON.stringify({type:"http",url:s,headers:{"x-mesh-client":"Claude Code"}},null,2),_=`claude mcp add-json "${m}" '${g.replace(/'/g,"'\\''")}' --scope user`;await navigator.clipboard.writeText(_),a(!0),pe.success("Claude Code command copied to clipboard"),setTimeout(()=>a(!1),2e3)},e[0]=n,e[1]=i,e[2]=s,e[3]=l):l=e[3];const c=l;let d;e[4]!==o?(d=o?r.jsx(Jt,{size:20,className:"text-green-600"}):r.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]=d):d=e[5];const u=o?"Copied!":"Install on Claude Code";let h;e[6]!==u?(h=r.jsx("span",{className:"text-xs font-medium",children:u}),e[6]=u,e[7]=h):h=e[7];let f;return e[8]!==c||e[9]!==d||e[10]!==h?(f=r.jsxs(ne,{type:"button",variant:"outline",onClick:c,className:"h-auto py-3 px-4 flex flex-col items-center gap-2",children:[d,h]}),e[8]=c,e[9]=d,e[10]=h,e[11]=f):f=e[11],f}function jw({virtualMcp:t}){const{org:e}=be(),s=Me({connectionId:Wt,orgId:e.id}),[i,n]=S.useState(null),[o,a]=S.useState(!1),[l,c]=S.useState(!1),d=t.id,u=t.title||`agent-${d.slice(0,8)}`,h=i?`bunx @decocms/typegen@latest --mcp ${d} --key ${i} --output client.ts`:`bunx @decocms/typegen@latest --mcp ${d} --key <api-key> --output client.ts`,f=async()=>{a(!0);try{const g=(await s.callTool({name:"API_KEY_CREATE",arguments:{name:`typegen-${u}`,permissions:{[d]:["*"]}}})).structuredContent?.key;if(!g)throw new Error("No key in response");n(g),se("agent_typegen_key_generated",{agent_id:d})}catch{se("agent_typegen_key_failed",{agent_id:d}),pe.error("Failed to generate API key")}finally{a(!1)}},m=async()=>{se("agent_connect_action",{agent_id:d,action:"typegen_copy_command",has_api_key:!!i}),await navigator.clipboard.writeText(h),c(!0),pe.success("Command copied to clipboard"),setTimeout(()=>c(!1),2e3)};return r.jsxs("div",{className:"flex min-w-0 flex-col gap-3",children:[r.jsxs("div",{className:"flex items-start justify-between gap-3",children:[r.jsxs("div",{className:"flex flex-col gap-0.5",children:[r.jsx("h4",{className:"text-sm font-medium text-foreground",children:"Generate typed client"}),r.jsxs("p",{className:"text-xs text-muted-foreground",children:["Introspects this agent and writes a typed"," ",r.jsx("code",{className:"font-mono",children:"client.ts"})," you can import directly."]})]}),!i&&r.jsxs(ne,{type:"button",variant:"outline",size:"sm",className:"shrink-0 gap-1.5",onClick:f,disabled:o,children:[o?r.jsx(Ee,{size:14,className:"animate-spin"}):r.jsx(Mg,{size:14}),r.jsx("span",{children:o?"Generating…":"Generate API key"})]})]}),i&&r.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."}),r.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"Generate client"}),r.jsx("div",{className:"rounded-md border border-input bg-muted/50 px-3 py-2.5",children:r.jsxs("div",{className:"flex items-start gap-2",children:[r.jsx("code",{className:"min-w-0 flex-1 break-all font-mono text-xs text-muted-foreground",children:h}),r.jsx(ne,{type:"button",variant:"ghost",size:"icon",className:"size-6 shrink-0",onClick:m,children:l?r.jsx(Jt,{size:12,className:"text-green-600"}):r.jsx(Li,{size:12})})]})}),r.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"Runtime variables"}),r.jsx(kw,{apiKey:i,agentId:d})]})}function kw(t){const e=B.c(21),{apiKey:s,agentId:i}=t,[n,o]=S.useState(!1),a=window.location.origin,l=s?`MESH_API_KEY=${s}`:"MESH_API_KEY=<api-key>",c=`MESH_BASE_URL=${a}`,d=`${l}
264
+ ${c}`;let u;e[0]!==i||e[1]!==s||e[2]!==d?(u=async()=>{se("agent_connect_action",{agent_id:i,action:"typegen_copy_env",has_api_key:!!s}),await navigator.clipboard.writeText(d),o(!0),setTimeout(()=>o(!1),2e3)},e[0]=i,e[1]=s,e[2]=d,e[3]=u):u=e[3];const h=u,f=!s;let m;e[4]!==f?(m=X({"opacity-50":f}),e[4]=f,e[5]=m):m=e[5];let p;e[6]!==l||e[7]!==m?(p=r.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")?(g=r.jsx("br",{}),_=r.jsx("span",{children:c}),e[9]=g,e[10]=_):(g=e[9],_=e[10]);let v;e[11]!==p?(v=r.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 x;e[13]!==n?(x=n?r.jsx(Jt,{size:12,className:"text-green-600"}):r.jsx(Li,{size:12}),e[13]=n,e[14]=x):x=e[14];let b;e[15]!==h||e[16]!==x?(b=r.jsx(ne,{type:"button",variant:"ghost",size:"icon",className:"size-6 shrink-0",onClick:h,children:x}),e[15]=h,e[16]=x,e[17]=b):b=e[17];let y;return e[18]!==v||e[19]!==b?(y=r.jsx("div",{className:"rounded-md border border-input bg-muted/50 px-3 py-2.5",children:r.jsxs("div",{className:"flex items-start gap-2",children:[v,b]})}),e[18]=v,e[19]=b,e[20]=y):y=e[20],y}function Nw(t){const e=B.c(3),{virtualMcp:s}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=r.jsx("div",{className:"h-20 animate-pulse rounded-md bg-muted"}),e[0]=i):i=e[0];let n;return e[1]!==s?(n=r.jsx(S.Suspense,{fallback:i,children:r.jsx(jw,{virtualMcp:s})}),e[1]=s,e[2]=n):n=e[2],n}function Aw(t){const e=B.c(37),{open:s,onOpenChange:i,virtualMcp:n}=t,o=`/mcp/virtual-mcp/${n.id}`;let a;e[0]!==o?(a=new URL(o,window.location.origin),e[0]=o,e[1]=a):a=e[1];const l=a;let c;e[2]!==n.id||e[3]!==n.title?(c=n.title||`agent-${n.id?.slice(0,8)??"default"}`,e[2]=n.id,e[3]=n.title,e[4]=c):c=e[4];const d=c,u=Rs();let h;e[5]!==n.id||e[6]!==l.href?(h=r.jsx(ww,{url:l.href,agentId:n.id}),e[5]=n.id,e[6]=l.href,e[7]=h):h=e[7];let f,m;e[8]!==d||e[9]!==n.id||e[10]!==l.href?(f=r.jsx(Vw,{url:l.href,serverName:d,agentId:n.id}),m=r.jsx(Cw,{url:l.href,serverName:d,agentId:n.id}),e[8]=d,e[9]=n.id,e[10]=l.href,e[11]=f,e[12]=m):(f=e[11],m=e[12]);let p;e[13]!==h||e[14]!==f||e[15]!==m?(p=r.jsx("div",{className:"flex flex-col gap-3 pt-2",children:r.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[h,f,m]})}),e[13]=h,e[14]=f,e[15]=m,e[16]=p):p=e[16];let g;e[17]===Symbol.for("react.memo_cache_sentinel")?(g=r.jsx("div",{className:"border-t border-border"}),e[17]=g):g=e[17];let _;e[18]!==n?(_=r.jsx(Nw,{virtualMcp:n}),e[18]=n,e[19]=_):_=e[19];let v;e[20]!==p||e[21]!==_?(v=r.jsxs("div",{className:"flex flex-col gap-6",children:[p,g,_]}),e[20]=p,e[21]=_,e[22]=v):v=e[22];const x=v;if(u){let j;e[23]===Symbol.for("react.memo_cache_sentinel")?(j=r.jsx(bi,{className:"mt-4 mb-4 text-base font-semibold",children:"Connect"}),e[23]=j):j=e[23];let V;e[24]!==x?(V=r.jsx(yi,{children:r.jsxs("div",{className:"flex-1 overflow-y-auto px-4 pb-6 [touch-action:pan-y]",children:[j,x]})}),e[24]=x,e[25]=V):V=e[25];let w;return e[26]!==i||e[27]!==s||e[28]!==V?(w=r.jsx(Si,{open:s,onOpenChange:i,children:V}),e[26]=i,e[27]=s,e[28]=V,e[29]=w):w=e[29],w}let b;e[30]===Symbol.for("react.memo_cache_sentinel")?(b=r.jsx(Ds,{children:r.jsx(Ts,{children:"Connect"})}),e[30]=b):b=e[30];let y;e[31]!==x?(y=r.jsxs(ms,{className:"max-h-[80vh] overflow-y-auto sm:max-w-2xl",children:[b,x]}),e[31]=x,e[32]=y):y=e[32];let C;return e[33]!==i||e[34]!==s||e[35]!==y?(C=r.jsx(ps,{open:s,onOpenChange:i,children:y}),e[33]=i,e[34]=s,e[35]=y,e[36]=C):C=e[36],C}function Ew(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 Iw(t){const e=B.c(22),{connection_id:s,usedConnectionIds:i,onOpenSettings:n,onRemove:o,onAuthenticate:a,onSwitchInstance:l,onNewInstance:c}=t,d=wl(s),{org:u}=be();if(!d)return null;let h;e[0]!==d?(h=ou(d),e[0]=d,e[1]=h):h=e[1];const f=h;let m;e[2]!==s?(m=r.jsx(Mw,{connection_id:s}),e[2]=s,e[3]=m):m=e[3];let p;e[4]!==d.app_name||e[5]!==d.connection_type||e[6]!==d.description||e[7]!==d.icon||e[8]!==d.title||e[9]!==s||e[10]!==a||e[11]!==c||e[12]!==n||e[13]!==o||e[14]!==l||e[15]!==u.slug||e[16]!==f||e[17]!==i?(p=r.jsx(Dw,{connection_id:s,connectionTitle:d.title,connectionDescription:d.description,connectionIcon:d.icon,connectionType:d.connection_type,slug:f,orgSlug:u.slug,appName:d.app_name,usedConnectionIds:i,onOpenSettings:n,onRemove:o,onAuthenticate:a,onSwitchInstance:l,onNewInstance:c}),e[4]=d.app_name,e[5]=d.connection_type,e[6]=d.description,e[7]=d.icon,e[8]=d.title,e[9]=s,e[10]=a,e[11]=c,e[12]=n,e[13]=o,e[14]=l,e[15]=u.slug,e[16]=f,e[17]=i,e[18]=p):p=e[18];let g;return e[19]!==m||e[20]!==p?(g=r.jsx(S.Suspense,{fallback:m,children:p}),e[19]=m,e[20]=p,e[21]=g):g=e[21],g}const pd="__new_instance__";async function Rw(t,e){const s=t?.idToken??null;if(s){const n=gd(s);if(n)return n}const i=t?.userinfoEndpoint??null;if(i)try{const n=await fetch(i,{headers:{Authorization:`Bearer ${e}`}});if(n.ok){const o=await n.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 gd(e)}function gd(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 Tw(t){const e=B.c(23),{appName:s,connectionId:i,usedConnectionIds:n,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 c=Wr(l);if(c.length<=1)return null;let d;e[2]!==i||e[3]!==a||e[4]!==o?(d=g=>{g===pd?a?.():o(i,g)},e[2]=i,e[3]=a,e[4]=o,e[5]=d):d=e[5];let u;e[6]===Symbol.for("react.memo_cache_sentinel")?(u=r.jsx(Zs,{size:"sm",className:"w-auto text-xs gap-1 px-2 shadow-none",children:r.jsx(ei,{})}),e[6]=u):u=e[6];let h;if(e[7]!==i||e[8]!==c||e[9]!==n){let g;e[11]!==i||e[12]!==n?(g=_=>r.jsx(Ht,{value:_.id,className:"text-xs",disabled:_.id!==i&&n.has(_.id),children:_.title},_.id),e[11]=i,e[12]=n,e[13]=g):g=e[13],h=c.map(g),e[7]=i,e[8]=c,e[9]=n,e[10]=h}else h=e[10];let f;e[14]!==a?(f=a&&r.jsx(Ht,{value:pd,className:"text-xs text-muted-foreground",children:"+ New instance"}),e[14]=a,e[15]=f):f=e[15];let m;e[16]!==h||e[17]!==f?(m=r.jsxs(Js,{children:[h,f]}),e[16]=h,e[17]=f,e[18]=m):m=e[18];let p;return e[19]!==i||e[20]!==d||e[21]!==m?(p=r.jsxs(Qs,{value:i,onValueChange:d,children:[u,m]}),e[19]=i,e[20]=d,e[21]=m,e[22]=p):p=e[22],p}function Dw(t){const e=B.c(55),{connection_id:s,connectionTitle:i,connectionDescription:n,connectionIcon:o,connectionType:a,slug:l,orgSlug:c,appName:d,usedConnectionIds:u,onOpenSettings:h,onRemove:f,onAuthenticate:m,onSwitchInstance:p,onNewInstance:g}=t;let _;e[0]!==s?(_={connectionId:s},e[0]=s,e[1]=_):_=e[1];const v=wu(_),b=!(a==="VIRTUAL")&&v.supportsOAuth&&!v.isAuthenticated,y=b?"border-destructive/50 bg-destructive/5":"border-border";let C;e[2]!==y?(C=X("rounded-xl border overflow-hidden transition-colors",y),e[2]=y,e[3]=C):C=e[3];let j;e[4]!==c||e[5]!==l?(j={org:c,appSlug:l},e[4]=c,e[5]=l,e[6]=j):j=e[6];let V;e[7]!==o||e[8]!==i?(V=r.jsx(Ms,{icon:o,name:i,size:"sm",className:"shrink-0"}),e[7]=o,e[8]=i,e[9]=V):V=e[9];let w;e[10]!==i?(w=r.jsx("p",{className:"text-sm font-medium truncate",children:i}),e[10]=i,e[11]=w):w=e[11];let k;e[12]!==n||e[13]!==b?(k=b?r.jsx("span",{className:"text-xs text-destructive font-medium",children:"Needs authorization"}):n&&r.jsx("p",{className:"text-xs text-muted-foreground truncate",children:n}),e[12]=n,e[13]=b,e[14]=k):k=e[14];let T;e[15]!==w||e[16]!==k?(T=r.jsxs("div",{className:"flex-1 min-w-0",children:[w,k]}),e[15]=w,e[16]=k,e[17]=T):T=e[17];let I;e[18]!==s||e[19]!==b||e[20]!==m?(I=b?r.jsx(ne,{variant:"outline",size:"sm",className:"h-7 text-xs shrink-0",onClick:G=>{G.preventDefault(),G.stopPropagation(),m(s)},children:"Authorize"}):r.jsxs(it,{delayDuration:0,children:[r.jsx(tt,{asChild:!0,children:r.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:r.jsx(Gr,{size:16})})}),r.jsx(st,{side:"bottom",children:"Connection settings"})]}),e[18]=s,e[19]=b,e[20]=m,e[21]=I):I=e[21];let A;e[22]!==j||e[23]!==V||e[24]!==T||e[25]!==I?(A=r.jsxs(Nh,{to:"/$org/settings/connections/$appSlug",params:j,className:"flex items-center gap-3 px-4 py-3 cursor-pointer hover:bg-muted/50 transition-colors",children:[V,T,I]}),e[22]=j,e[23]=V,e[24]=T,e[25]=I,e[26]=A):A=e[26];let N;e[27]!==d||e[28]!==s||e[29]!==g||e[30]!==p||e[31]!==u?(N=d&&r.jsx(Tw,{appName:d,connectionId:s,usedConnectionIds:u,onSwitchInstance:p,onNewInstance:g}),e[27]=d,e[28]=s,e[29]=g,e[30]=p,e[31]=u,e[32]=N):N=e[32];let E;e[33]===Symbol.for("react.memo_cache_sentinel")?(E=r.jsx(zh,{size:13}),e[33]=E):E=e[33];let R;e[34]!==h?(R=r.jsx(tt,{asChild:!0,children:r.jsx(ne,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:h,"aria-label":"Configure resources",children:E})}),e[34]=h,e[35]=R):R=e[35];let M;e[36]===Symbol.for("react.memo_cache_sentinel")?(M=r.jsx(st,{side:"bottom",children:"Configure resources"}),e[36]=M):M=e[36];let L;e[37]!==R?(L=r.jsxs(it,{delayDuration:0,children:[R,M]}),e[37]=R,e[38]=L):L=e[38];let D;e[39]===Symbol.for("react.memo_cache_sentinel")?(D=r.jsx(ii,{size:13}),e[39]=D):D=e[39];let P;e[40]!==f?(P=r.jsx(tt,{asChild:!0,children:r.jsx(ne,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-destructive",onClick:f,"aria-label":"Remove connection",children:D})}),e[40]=f,e[41]=P):P=e[41];let O;e[42]===Symbol.for("react.memo_cache_sentinel")?(O=r.jsx(st,{side:"bottom",children:"Remove"}),e[42]=O):O=e[42];let z;e[43]!==P?(z=r.jsxs(it,{delayDuration:0,children:[P,O]}),e[43]=P,e[44]=z):z=e[44];let $;e[45]!==L||e[46]!==z?($=r.jsxs("div",{className:"flex items-center gap-0.5 ml-auto",children:[L,z]}),e[45]=L,e[46]=z,e[47]=$):$=e[47];let W;e[48]!==N||e[49]!==$?(W=r.jsxs("div",{className:"flex items-center gap-3 px-4 py-2 border-t border-border bg-muted/25",children:[N,$]}),e[48]=N,e[49]=$,e[50]=W):W=e[50];let F;return e[51]!==A||e[52]!==W||e[53]!==C?(F=r.jsxs("div",{className:C,children:[A,W]}),e[51]=A,e[52]=W,e[53]=C,e[54]=F):F=e[54],F}function Mw(t){const e=B.c(17),{connection_id:s}=t,i=wl(s);if(!i){let h;return e[0]===Symbol.for("react.memo_cache_sentinel")?(h=r.jsx(Ff,{}),e[0]=h):h=e[0],h}let n;e[1]!==i.icon||e[2]!==i.title?(n=r.jsx(Ms,{icon:i.icon,name:i.title,size:"sm",className:"shrink-0"}),e[1]=i.icon,e[2]=i.title,e[3]=n):n=e[3];let o;e[4]!==i.title?(o=r.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&&r.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=r.jsxs("div",{className:"flex-1 min-w-0",children:[o,a]}),e[8]=o,e[9]=a,e[10]=l):l=e[10];let c;e[11]!==n||e[12]!==l?(c=r.jsxs("div",{className:"flex items-center gap-3 px-4 py-3",children:[n,l]}),e[11]=n,e[12]=l,e[13]=c):c=e[13];let d;e[14]===Symbol.for("react.memo_cache_sentinel")?(d=r.jsx("div",{className:"flex items-center px-4 py-2 border-t border-border bg-muted/25",children:r.jsx("div",{className:"h-5 w-20 rounded bg-muted animate-pulse"})}),e[14]=d):d=e[14];let u;return e[15]!==c?(u=r.jsxs("div",{className:"rounded-xl border border-border overflow-hidden",children:[c,d]}),e[15]=c,e[16]=u):u=e[16],u}function Ff(){const t=B.c(3);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=r.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=r.jsxs("div",{className:"flex items-center gap-3 px-4 py-3",children:[e,r.jsxs("div",{className:"flex-1 space-y-1.5",children:[r.jsx("div",{className:"h-4 w-32 rounded bg-muted animate-pulse"}),r.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=r.jsxs("div",{className:"rounded-xl border border-border overflow-hidden",children:[s,r.jsx("div",{className:"flex items-center px-4 py-2 border-t border-border bg-muted/25",children:r.jsx("div",{className:"h-5 w-20 rounded bg-muted animate-pulse"})})]}),t[2]=i):i=t[2],i}function Pw({virtualMcpId:t}){const{org:e}=be(),s=Me({connectionId:Wt,orgId:e.id}),i=Mt(),n=ts(t),o=(n?.connections??[]).map(P=>P.connection_id).sort(),{data:a}=Fi({queryKey:lt.projectConnectionDetails(t,o),enabled:o.length>0,queryFn:async()=>await Promise.all(o.map(async O=>{try{const z=await s.callTool({name:"COLLECTION_CONNECTIONS_GET",arguments:{id:O}}),{item:$}=ko(z),W=($?.tools??[]).filter(F=>!!Qg(F._meta)).map(F=>({name:F.name,description:F.description}));return{fetchOk:!0,id:O,title:$?.title??O,icon:$?.icon??null,uiTools:W}}catch{return{fetchOk:!1,id:O,title:O,icon:null,uiTools:[]}}}))}),l=(a??[]).filter(P=>P.uiTools.length>0),c=new Set(Kp),d=n?.metadata?.ui,u=d?.pinnedViews??[],h=d?.layout?.defaultMainView??null,f=d?.layout?.chatDefaultOpen??!1,m=!h||h.type==="chat"?"chat":h.type==="settings"?"layout":c.has(h.type)?h.type:`${h.type}:${h.id??""}:${h.toolName??""}`,[p,g]=S.useState(u),[_,v]=S.useState(m),[x,b]=S.useState(f),[y,C]=S.useState(!1),j=P=>{const[O,z,$]=P.split(":");return O?O==="chat"?{type:O}:c.has(O)?{type:O}:O==="ext-apps"&&z?{type:"ext-apps",id:z,toolName:$||void 0}:null:null},V=S.useRef(!1);if(a&&a.length>0&&!V.current){V.current=!0;const P=new Set((a??[]).filter($=>$.fetchOk).map($=>$.id)),O=new Set(l.flatMap($=>$.uiTools.map(W=>`${$.id}:${W.name}`))),z=u.filter($=>!P.has($.connectionId)||O.has(`${$.connectionId}:${$.toolName}`));if(z.length!==u.length){g(z);let $=_;h?.type==="ext-apps"&&!z.some(W=>W.connectionId===h.id&&W.toolName===h.toolName)&&($="chat",v($)),s.callTool({name:"VIRTUAL_MCP_PINNED_VIEWS_UPDATE",arguments:{virtualMcpId:t,pinnedViews:z,layout:{defaultMainView:j($),chatDefaultOpen:x}}}).then(W=>{ko(W),i.invalidateQueries({predicate:F=>Array.isArray(F.queryKey)&&F.queryKey.includes("collection")&&F.queryKey.includes("VIRTUAL_MCP")})}).catch(()=>{g(u),v(m)})}}const w=(P,O,z)=>{C(!0),(async()=>{try{const W=await s.callTool({name:"VIRTUAL_MCP_PINNED_VIEWS_UPDATE",arguments:{virtualMcpId:t,pinnedViews:P,layout:{defaultMainView:j(O),chatDefaultOpen:z??x}}});ko(W),i.invalidateQueries({predicate:F=>Array.isArray(F.queryKey)&&F.queryKey.includes("collection")&&F.queryKey.includes("VIRTUAL_MCP")}),pe.success("Layout updated")}catch(W){pe.error("Failed to update layout: "+(W instanceof Error?W.message:"Unknown error"))}finally{C(!1)}})()},k=(P,O)=>{const z=p.some(F=>F.connectionId===P&&F.toolName===O);let $,W=_;if(z){$=p.filter(G=>!(G.connectionId===P&&G.toolName===O));const F=`ext-apps:${P}:${O}`;_===F&&(W="chat",v(W))}else $=[...p,{connectionId:P,toolName:O,label:O.replace(/_/g," "),icon:null}];g($),w($,W)},T=(P,O,z)=>{g($=>$.map(W=>W.connectionId===P&&W.toolName===O?{...W,label:z}:W))},I=()=>{w(p,_)},A=(P,O,z)=>{g(W=>W.map(F=>F.connectionId===P&&F.toolName===O?{...F,icon:z}:F));const $=p.map(W=>W.connectionId===P&&W.toolName===O?{...W,icon:z}:W);w($,_)},N=P=>{v(P),w(p,P)},E=o.length===0,R=a&&l.length===0,M=!!Fs(n),L=[{value:"chat",label:"Chat"},{value:"instructions",label:"Instructions"},{value:"connections",label:"Connections"},{value:"layout",label:"Layout"}];M&&(L.push({value:"env",label:"Terminal"}),L.push({value:"preview",label:"Preview"}));for(const P of p)L.push({value:`ext-apps:${P.connectionId}:${P.toolName}`,label:P.label||P.toolName});const D=l.length>0||E||R;return r.jsxs("div",{className:"flex flex-col gap-3",children:[r.jsx("div",{className:"flex items-center justify-between gap-3",children:r.jsx("h2",{className:"text-sm font-medium text-foreground",children:"Layout"})}),r.jsxs(T_,{className:"p-6 gap-5",children:[r.jsxs(Cc,{className:"p-0 space-y-5",children:[r.jsxs("div",{className:"flex items-center justify-between gap-4",children:[r.jsxs("div",{className:"space-y-0.5 min-w-0",children:[r.jsx(vr,{className:"font-normal text-foreground",children:"Main view"}),r.jsx("p",{className:"text-xs text-muted-foreground",children:"What users see when they first open this agent."})]}),r.jsxs(Qs,{value:_,onValueChange:N,children:[r.jsx(Zs,{className:"w-44 h-8 text-sm capitalize shrink-0",children:r.jsx(ei,{})}),r.jsx(Js,{children:L.map(P=>r.jsx(Ht,{value:P.value,className:"capitalize",children:P.label},P.value))})]})]}),r.jsxs("div",{className:"flex items-center justify-between gap-4",children:[r.jsxs("div",{className:"space-y-0.5 min-w-0",children:[r.jsx(vr,{className:"font-normal text-foreground",children:"Show chat"}),r.jsx("p",{className:"text-xs text-muted-foreground",children:"Display the chat panel alongside the main view."})]}),r.jsxs(it,{delayDuration:0,children:[r.jsx(tt,{asChild:!0,children:r.jsx("span",{className:"shrink-0",children:r.jsx(da,{checked:_==="chat"?!0:x,disabled:_==="chat"||y,onCheckedChange:P=>{b(P),w(p,_,P)}})})}),_==="chat"&&r.jsx(st,{side:"top",children:"Chat is always shown when it is the default view"})]})]})]}),D&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"border-t border-border -mx-6"}),r.jsxs(Cc,{className:"p-0 space-y-3",children:[r.jsx("div",{className:"flex items-center justify-between gap-4",children:r.jsxs("div",{className:"space-y-0.5 min-w-0",children:[r.jsx(vr,{className:"font-normal text-foreground",children:"Pinned views"}),r.jsx("p",{className:"text-xs text-muted-foreground",children:"Surface interactive tools as top-level tabs in the agent."})]})}),E&&r.jsx("p",{className:"text-xs text-muted-foreground",children:"Add a connection above to configure pinned views."}),R&&!E&&r.jsx("p",{className:"text-xs text-muted-foreground",children:"None of the connected servers expose interactive tools."}),l.length>0&&r.jsx("div",{className:"space-y-4 pt-1",children:l.map((P,O)=>r.jsxs("div",{children:[O>0&&r.jsx("div",{className:"border-t border-border -mx-6 mb-4"}),r.jsxs("div",{className:"flex items-center gap-2 mb-2.5",children:[r.jsx(Ms,{icon:P.icon,name:P.title,size:"xs",className:"shrink-0"}),r.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:P.title})]}),r.jsx("div",{className:"space-y-1.5",children:P.uiTools.map(z=>{const $=p.some(F=>F.connectionId===P.id&&F.toolName===z.name),W=p.find(F=>F.connectionId===P.id&&F.toolName===z.name);return r.jsxs("div",{className:X("flex items-center justify-between gap-3 px-3 py-2 rounded-lg border transition-colors",$?"bg-accent/40 border-border":"bg-transparent border-border"),children:[r.jsxs("div",{className:"min-w-0 flex-1 flex items-center gap-2",children:[r.jsx(ow,{value:W?.icon??null,onChange:F=>A(P.id,z.name,F),disabled:!$||y}),r.jsx(bt,{value:$&&W?W.label:z.name.replace(/_/g," "),onChange:F=>T(P.id,z.name,F.target.value),onBlur:I,className:"h-7 text-sm w-40 capitalize",disabled:!$||y,readOnly:!$})]}),r.jsx(da,{checked:$,onCheckedChange:()=>k(P.id,z.name),disabled:y})]},z.name)})})]},P.id))})]})]})]})]})}function Lw({virtualMcp:t,hideOwnTitle:e}){const{org:s}=be(),i=yl(),n=Sl(),o=Mt(),a=Me({connectionId:Wt,orgId:s.id}),l=Hi({resolver:Or(yw),defaultValues:t}),c=l.watch("connections"),d=!!Fs(t),[u,h]=S.useReducer(Ew,{shareDialogOpen:!1,addDialogOpen:!1,settingsDialogOpen:!1,settingsConnectionId:null}),[f,m]=S.useState(!1),{createTaskWithMessage:p}=es(),{setChatMode:g}=ni(),{createNewTask:_}=zr(),v=()=>{const H=l.getValues("metadata.instructions");H?.trim()&&(T(),se("agent_instructions_improve_clicked",{agent_id:t.id,instructions_length:H.length}),g("plan"),p({virtualMcpId:hl(s.id),message:{parts:[{type:"text",text:`/writing-prompts ${t.id}
265
265
 
266
266
  <instructions>
267
267
  ${H}
268
- </instructions>`}]}}))},x=()=>{T(),se("agent_test_clicked",{agent_id:t.id}),_()},b=S.useRef(null),y=S.useRef(null),C=S.useRef(new Set),j=S.useRef(0),V=S.useRef(null),w=S.useRef(null),k=3e4,T=()=>{w.current&&(clearTimeout(w.current),w.current=null),y.current!==null&&(se("agent_updated",{agent_id:t.id,fields:Array.from(C.current),instructions_length:V.current,save_count:j.current,edit_duration_ms:Date.now()-y.current}),y.current=null,C.current=new Set,j.current=0,V.current=null)},I=async()=>{b.current&&(clearTimeout(b.current),b.current=null);const H=Object.keys(l.formState.dirtyFields);if(H.length===0)return;const ee=H.includes("metadata"),K=l.getValues(),U=await i.update.mutateAsync({id:t.id,data:K});y.current===null&&(y.current=Date.now());for(const te of H)C.current.add(te);j.current+=1,ee&&(V.current=K.metadata?.instructions?.length??0),w.current&&clearTimeout(w.current),w.current=setTimeout(T,k),l.reset(U)},A=()=>{b.current&&clearTimeout(b.current),b.current=setTimeout(()=>{I()},1e3)},N=S.useRef(!1);N.current||(N.current=!0,l.watch(()=>{A()}));const E=()=>{se("connections_dialog_opened",{source:"agent_settings",mode:"add"}),h({type:"SET_ADD_DIALOG_OPEN",payload:!0})},R=async H=>{const ee=l.getValues("connections");if(ee.some(te=>te.connection_id===H))return;l.setValue("connections",[...ee,{connection_id:H,selected_tools:Bo.tools,selected_resources:Bo.resources,selected_prompts:Bo.prompts}],{shouldDirty:!0}),h({type:"SET_ADD_DIALOG_OPEN",payload:!1});const K=new URL(`/mcp/${H}`,window.location.origin),U=await pr({url:K.href,token:null});U.supportsOAuth&&!U.isAuthenticated&&await O(H)},M=H=>{const K=l.getValues("connections").filter(U=>U.connection_id!==H);l.setValue("connections",K,{shouldDirty:!0})},L=(H,ee)=>{const K=l.getValues("connections");if(K.some(U=>U.connection_id===ee)){ge.error("This instance is already added to the agent");return}l.setValue("connections",K.map(U=>U.connection_id===H?{...U,connection_id:ee}:U),{shouldDirty:!0})},D=async H=>{if(l.getValues("connections").find(K=>K.connection_id===H))try{const K=await a.callTool({name:"COLLECTION_CONNECTIONS_GET",arguments:{id:H}}),{item:U}=K.structuredContent??{};if(!U)return;const te=U.title.replace(/\s*\(.*?\)\s*$/,""),Y=du("conn"),J=`${te} (${Date.now().toString(36).slice(-4)})`;await n.create.mutateAsync({id:Y,title:J,description:U.description??null,connection_type:U.connection_type,connection_url:U.connection_url??null,connection_token:null,icon:U.icon??null,app_name:U.app_name??null,app_id:U.app_id??null,connection_headers:U.connection_headers??null});const ie=new URL(`/mcp/${Y}`,window.location.origin),ue=await pr({url:ie.href,token:null});if(ue.supportsOAuth&&!ue.isAuthenticated){const de=await O(Y);if(!de){await n.delete.mutateAsync(Y);return}await n.update.mutateAsync({id:Y,data:{title:`${te} (${de})`}})}L(H,Y),ge.success("New instance created")}catch(K){console.error("Failed to create instance:",K),ge.error("Failed to create instance")}},P=H=>{h({type:"OPEN_SETTINGS",payload:H})},O=async H=>{const{token:ee,tokenInfo:K,error:U}=await vn({connectionId:H,scope:"offline_access"});if(U||!ee)return ge.error(`Authentication failed: ${U}`),null;if(K)try{const Y=await fetch(`/api/connections/${H}/oauth-token`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({accessToken:K.accessToken,refreshToken:K.refreshToken,expiresIn:K.expiresIn,scope:K.scope,clientId:K.clientId,clientSecret:K.clientSecret,tokenEndpoint:K.tokenEndpoint})});if(!Y.ok)console.error("Failed to save OAuth token:",await Y.text()),await n.update.mutateAsync({id:H,data:{connection_token:ee}});else try{await n.update.mutateAsync({id:H,data:{}})}catch(J){console.warn("Failed to refresh connection tools after OAuth:",J)}}catch(Y){console.error("Error saving OAuth token:",Y),await n.update.mutateAsync({id:H,data:{connection_token:ee}})}else await n.update.mutateAsync({id:H,data:{connection_token:ee}});const te=new URL(`/mcp/${H}`,window.location.origin);return await o.invalidateQueries({queryKey:lt.isMCPAuthenticated(te.href,null)}),ge.success("Authentication successful"),Aw(K,ee)},z=()=>{const H=l.getValues("metadata.instructions")??"",ee=`<role>
268
+ </instructions>`}]}}))},x=()=>{T(),se("agent_test_clicked",{agent_id:t.id}),_()},b=S.useRef(null),y=S.useRef(null),C=S.useRef(new Set),j=S.useRef(0),V=S.useRef(null),w=S.useRef(null),k=3e4,T=()=>{w.current&&(clearTimeout(w.current),w.current=null),y.current!==null&&(se("agent_updated",{agent_id:t.id,fields:Array.from(C.current),instructions_length:V.current,save_count:j.current,edit_duration_ms:Date.now()-y.current}),y.current=null,C.current=new Set,j.current=0,V.current=null)},I=async()=>{b.current&&(clearTimeout(b.current),b.current=null);const H=Object.keys(l.formState.dirtyFields);if(H.length===0)return;const ee=H.includes("metadata"),K=l.getValues(),U=await i.update.mutateAsync({id:t.id,data:K});y.current===null&&(y.current=Date.now());for(const te of H)C.current.add(te);j.current+=1,ee&&(V.current=K.metadata?.instructions?.length??0),w.current&&clearTimeout(w.current),w.current=setTimeout(T,k),l.reset(U)},A=()=>{b.current&&clearTimeout(b.current),b.current=setTimeout(()=>{I()},1e3)},N=S.useRef(!1);N.current||(N.current=!0,l.watch(()=>{A()}));const E=()=>{se("connections_dialog_opened",{source:"agent_settings",mode:"add"}),h({type:"SET_ADD_DIALOG_OPEN",payload:!0})},R=async H=>{const ee=l.getValues("connections");if(ee.some(te=>te.connection_id===H))return;l.setValue("connections",[...ee,{connection_id:H,selected_tools:Bo.tools,selected_resources:Bo.resources,selected_prompts:Bo.prompts}],{shouldDirty:!0}),h({type:"SET_ADD_DIALOG_OPEN",payload:!1});const K=new URL(`/mcp/${H}`,window.location.origin),U=await pr({url:K.href,token:null});U.supportsOAuth&&!U.isAuthenticated&&await O(H)},M=H=>{const K=l.getValues("connections").filter(U=>U.connection_id!==H);l.setValue("connections",K,{shouldDirty:!0})},L=(H,ee)=>{const K=l.getValues("connections");if(K.some(U=>U.connection_id===ee)){pe.error("This instance is already added to the agent");return}l.setValue("connections",K.map(U=>U.connection_id===H?{...U,connection_id:ee}:U),{shouldDirty:!0})},D=async H=>{if(l.getValues("connections").find(K=>K.connection_id===H))try{const K=await a.callTool({name:"COLLECTION_CONNECTIONS_GET",arguments:{id:H}}),{item:U}=K.structuredContent??{};if(!U)return;const te=U.title.replace(/\s*\(.*?\)\s*$/,""),Y=hu("conn"),J=`${te} (${Date.now().toString(36).slice(-4)})`;await n.create.mutateAsync({id:Y,title:J,description:U.description??null,connection_type:U.connection_type,connection_url:U.connection_url??null,connection_token:null,icon:U.icon??null,app_name:U.app_name??null,app_id:U.app_id??null,connection_headers:U.connection_headers??null});const ie=new URL(`/mcp/${Y}`,window.location.origin),ue=await pr({url:ie.href,token:null});if(ue.supportsOAuth&&!ue.isAuthenticated){const de=await O(Y);if(!de){await n.delete.mutateAsync(Y);return}await n.update.mutateAsync({id:Y,data:{title:`${te} (${de})`}})}L(H,Y),pe.success("New instance created")}catch(K){console.error("Failed to create instance:",K),pe.error("Failed to create instance")}},P=H=>{h({type:"OPEN_SETTINGS",payload:H})},O=async H=>{const{token:ee,tokenInfo:K,error:U}=await vn({connectionId:H,scope:"offline_access"});if(U||!ee)return pe.error(`Authentication failed: ${U}`),null;if(K)try{const Y=await fetch(`/api/connections/${H}/oauth-token`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({accessToken:K.accessToken,refreshToken:K.refreshToken,expiresIn:K.expiresIn,scope:K.scope,clientId:K.clientId,clientSecret:K.clientSecret,tokenEndpoint:K.tokenEndpoint})});if(!Y.ok)console.error("Failed to save OAuth token:",await Y.text()),await n.update.mutateAsync({id:H,data:{connection_token:ee}});else try{await n.update.mutateAsync({id:H,data:{}})}catch(J){console.warn("Failed to refresh connection tools after OAuth:",J)}}catch(Y){console.error("Error saving OAuth token:",Y),await n.update.mutateAsync({id:H,data:{connection_token:ee}})}else await n.update.mutateAsync({id:H,data:{connection_token:ee}});const te=new URL(`/mcp/${H}`,window.location.origin);return await o.invalidateQueries({queryKey:lt.isMCPAuthenticated(te.href,null)}),pe.success("Authentication successful"),Rw(K,ee)},z=()=>{const H=l.getValues("metadata.instructions")??"",ee=`<role>
269
269
  Define who this agent is and what it specializes in.
270
270
  Example: You are a support triage agent for B2B merchants.
271
271
  </role>
@@ -292,7 +292,7 @@ Define step-by-step how the agent should handle requests.
292
292
  4. Ask for confirmation before making any changes.
293
293
  </workflows>`,K=H.trim()?`${H}
294
294
 
295
- ${ee}`:ee;l.setValue("metadata.instructions",K,{shouldDirty:!0})},$=new Set(c.map(H=>H.connection_id)),W=Ke(),[F,G]=S.useState(!1),q=async()=>{T();try{await i.delete.mutateAsync(t.id),se("agent_deleted",{agent_id:t.id,source:"agent_detail"}),ge.success(`Deleted "${t.title}"`),W({to:"/$org",params:{org:s.slug}})}catch{}};return r.jsxs(hs,{children:[r.jsx(hs.Content,{children:r.jsx(hs.Body,{children:r.jsxs("div",{className:"flex flex-col gap-10",children:[!e&&r.jsx(hs.Title,{actions:r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs(ne,{variant:"outline",size:"sm",onClick:x,children:[r.jsx(Cn,{size:14,className:"!size-[14px]"}),"Test Agent"]}),r.jsx(ne,{variant:"ghost",size:"icon",className:"text-muted-foreground hover:text-destructive",onClick:()=>G(!0),children:r.jsx(ha,{size:14})})]}),children:"Settings"}),r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx(Ai,{name:"icon",control:l.control,render:({field:H})=>r.jsx(XS,{value:H.value??null,onChange:ee=>{H.onChange(ee),I()},onColorChange:ee=>{l.setValue("metadata.ui.themeColor",ee,{shouldDirty:!0}),I()},name:l.watch("title")||"Agent",size:"md",className:"shrink-0",avatarClassName:"[&_svg]:w-1/2 [&_svg]:h-1/2",disabled:d})}),r.jsxs("div",{className:"flex flex-col flex-1 min-w-0",children:[r.jsx(Ai,{name:"title",control:l.control,render:({field:H})=>r.jsx("input",{...H,type:"text",value:H.value??"",onBlur:()=>{H.onBlur(),I()},disabled:d,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"})}),r.jsx(Ai,{name:"description",control:l.control,render:({field:H})=>r.jsx("input",{...H,type:"text",value:H.value??"",onBlur:()=>{H.onBlur(),I()},disabled:d,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"})})]}),r.jsxs(ne,{variant:"outline",size:"sm",className:"shrink-0",onClick:()=>{se("agent_connect_modal_opened",{agent_id:t.id}),h({type:"SET_SHARE_DIALOG_OPEN",payload:!0})},children:[r.jsxs("span",{className:"flex items-center -space-x-1.5 mr-0.5",children:[r.jsx("span",{className:"inline-flex items-center justify-center size-4 rounded-full bg-black ring-1 ring-white/20 shrink-0",children:r.jsx("img",{src:"/logos/cursor.svg",alt:"Cursor",className:"size-2.5 brightness-0 invert"})}),r.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:r.jsx("img",{src:"/logos/Claude Code.svg",alt:"Claude",className:"size-2.5 brightness-0 invert"})})]}),"Connect"]})]}),r.jsxs("section",{className:"flex flex-col gap-3",children:[r.jsxs("div",{className:"flex items-center justify-between gap-3",children:[r.jsx("h2",{className:"text-sm font-medium text-foreground",children:"Connections"}),c.length>0&&r.jsxs(ne,{variant:"outline",size:"sm",onClick:E,children:[r.jsx(Qt,{size:14}),"Add connection"]})]}),r.jsx("div",{className:"flex flex-col gap-2",children:c.length===0?r.jsxs("button",{type:"button",onClick:E,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:[r.jsx("div",{className:"flex items-center justify-center size-8 rounded-md text-muted-foreground/75 border border-dashed border-border shrink-0",children:r.jsx(Qt,{size:16})}),r.jsx("span",{className:"text-sm text-muted-foreground",children:"No connections yet. Add one to get started."})]}):c.map(H=>r.jsx(Cs,{fallback:()=>null,children:r.jsx(S.Suspense,{fallback:r.jsx(zf,{}),children:r.jsx(Nw,{connection_id:H.connection_id,usedConnectionIds:$,onOpenSettings:()=>P(H.connection_id),onRemove:()=>M(H.connection_id),onAuthenticate:O,onSwitchInstance:L,onNewInstance:()=>D(H.connection_id)})})},H.connection_id))})]}),r.jsxs("section",{className:"flex flex-col gap-3",children:[r.jsxs("div",{className:"flex items-center justify-between gap-3",children:[r.jsx("h2",{className:"text-sm font-medium text-foreground",children:"Instructions"}),!d&&r.jsxs("div",{className:"flex items-center gap-2",children:[!l.watch("metadata.instructions")?.trim()&&r.jsx(ne,{variant:"outline",size:"sm",onClick:z,children:"+ Prompt template"}),r.jsxs(ne,{variant:"outline",size:"sm",disabled:!l.watch("metadata.instructions")?.trim(),onClick:v,children:[r.jsx(_l,{size:13}),"Improve"]})]})]}),r.jsx(Ai,{name:"metadata.instructions",control:l.control,render:({field:H})=>r.jsxs("div",{className:"relative rounded-xl card-shadow bg-card focus-within:ring-1 focus-within:ring-ring",children:[r.jsx(ca,{...H,value:H.value??"",onBlur:()=>{H.onBlur(),I()},disabled:d,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"}}),r.jsxs(it,{delayDuration:0,children:[r.jsx(tt,{asChild:!0,children:r.jsx(ne,{type:"button",variant:"ghost",size:"icon",className:"absolute top-2 right-2 h-7 w-7 text-muted-foreground",onClick:()=>m(!0),"aria-label":"Open fullscreen editor",children:r.jsx(jg,{size:14})})}),r.jsx(st,{side:"left",children:"Fullscreen"})]})]})})]}),r.jsx(Tw,{virtualMcpId:t.id}),r.jsxs("section",{className:"flex items-center justify-between border-t border-border pt-6",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-sm font-medium",children:"Delete agent"}),r.jsx("p",{className:"text-sm text-muted-foreground",children:"Permanently delete this agent and all its data."})]}),r.jsxs(ne,{variant:"outline",size:"sm",className:"text-destructive border-destructive/40 hover:bg-destructive/10 hover:text-destructive shrink-0",onClick:()=>G(!0),children:[r.jsx(ha,{size:14}),"Delete agent"]})]})]})})}),r.jsx(Il,{open:F,onOpenChange:G,children:r.jsxs(jl,{children:[r.jsxs(kl,{children:[r.jsx(Nl,{children:"Delete Agent?"}),r.jsxs(Al,{children:["This action cannot be undone. This will permanently delete"," ",r.jsx("span",{className:"font-medium text-foreground",children:t.title}),"."]})]}),r.jsxs(El,{children:[r.jsx(Cl,{children:"Cancel"}),r.jsx(bu,{onClick:q,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete"})]})]})}),r.jsx(Pl,{open:u.addDialogOpen,onOpenChange:H=>h({type:"SET_ADD_DIALOG_OPEN",payload:H}),agentId:t.id,addedConnectionIds:$,onAdd:R}),r.jsx(_w,{open:u.settingsDialogOpen,onOpenChange:H=>{H||h({type:"CLOSE_SETTINGS"})},selectedId:u.settingsConnectionId,form:l,connections:c,onAuthenticate:O}),r.jsx(jw,{open:u.shareDialogOpen,onOpenChange:H=>h({type:"SET_SHARE_DIALOG_OPEN",payload:H}),virtualMcp:t}),r.jsx(ps,{open:f,onOpenChange:m,children:r.jsxs(ms,{className:"w-[90vw] sm:max-w-6xl h-[85vh] flex flex-col p-0 gap-0",children:[r.jsx(Ds,{className:"px-6 pt-6 pb-3 border-b border-border shrink-0",children:r.jsx(Ts,{children:"Instructions"})}),r.jsx("div",{className:"flex-1 min-h-0 p-6",children:r.jsx(Ai,{name:"metadata.instructions",control:l.control,render:({field:H})=>r.jsx(ca,{...H,value:H.value??"",onBlur:()=>{H.onBlur(),I()},disabled:d,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 Mw(t){const e=B.c(9),{virtualMcpId:s,hideOwnTitle:i}=t,n=Ke(),{org:o}=be(),a=ts(s);if(!a){let d;return e[0]!==n||e[1]!==o.slug?(d=r.jsx("div",{className:"flex h-full w-full bg-background",children:r.jsx(Oi,{title:"Space not found",description:"This space may have been deleted or you may not have access.",actions:r.jsx(ne,{variant:"outline",onClick:()=>n({to:"/$org",params:{org:o.slug}}),children:"Back to spaces"})})}),e[0]=n,e[1]=o.slug,e[2]=d):d=e[2],d}let l;e[3]!==a?(l=Fs(a)?.connectionId??"",e[3]=a,e[4]=l):l=e[4];let c;return e[5]!==i||e[6]!==l||e[7]!==a?(c=r.jsx(Dw,{virtualMcp:a,hideOwnTitle:i},l),e[5]=i,e[6]=l,e[7]=a,e[8]=c):c=e[8],c}function _d(t){const e=B.c(2),{virtualMcpId:s}=t;let i;return e[0]!==s?(i=r.jsx(Mw,{virtualMcpId:s,hideOwnTitle:!0}),e[0]=s,e[1]=i):i=e[1],i}const Pw={amp:"&",lt:"<",gt:">",quot:'"',apos:"'",nbsp:" "};function Dr(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 Pw[s]??e}):""}function Zr(t){if(!t||typeof t!="object")return null;const e=t;if(e.structuredContent!==void 0)return e.structuredContent;const s=e.content?.find(i=>i.type==="text")?.text;if(!s)return null;try{return JSON.parse(s)}catch{return null}}const go=6e4,_o=3e4;function Ff(t){const e=B.c(11);let s;e[0]!==t.connectionId||e[1]!==t.orgId?(s={connectionId:t.connectionId,orgId:t.orgId},e[0]=t.connectionId,e[1]=t.orgId,e[2]=s):s=e[2];const i=Me(s),n=t.branch?`${t.owner}:${t.branch}`:void 0;let o;e[3]!==t.owner||e[4]!==t.repo||e[5]!==n?(o={owner:t.owner,repo:t.repo,state:"all",head:n,perPage:1},e[3]=t.owner,e[4]=t.repo,e[5]=n,e[6]=o):o=e[6];const a=!!t.branch;let l;return e[7]!==i||e[8]!==o||e[9]!==a?(l={client:i,toolName:"list_pull_requests",toolArguments:o,enabled:a,refetchInterval:go,refetchIntervalInBackground:!1,staleTime:_o,select:Lw},e[7]=i,e[8]=o,e[9]=a,e[10]=l):l=e[10],wi(l)}function Lw(t){const e=Zr(t);if(!e||!Array.isArray(e)||e.length===0)return null;const s=e[0],i=s.base,n=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:n?.ref??"",headSha:n?.sha??"",htmlUrl:s.html_url??"",author:o?.login??""}}function Hf(t){const e=B.c(11);let s;e[0]!==t.connectionId||e[1]!==t.orgId?(s={connectionId:t.connectionId,orgId:t.orgId},e[0]=t.connectionId,e[1]=t.orgId,e[2]=s):s=e[2];const i=Me(s),n=t.prNumber??0;let o;e[3]!==t.owner||e[4]!==t.repo||e[5]!==n?(o={method:"get_files",owner:t.owner,repo:t.repo,pullNumber:n},e[3]=t.owner,e[4]=t.repo,e[5]=n,e[6]=o):o=e[6];const a=!!t.prNumber;let l;return e[7]!==i||e[8]!==o||e[9]!==a?(l={client:i,toolName:"pull_request_read",toolArguments:o,enabled:a,refetchInterval:go,refetchIntervalInBackground:!1,staleTime:_o,select:Bw},e[7]=i,e[8]=o,e[9]=a,e[10]=l):l=e[10],wi(l)}function Bw(t){const e=Zr(t);return Array.isArray(e)?e.map(Ow):[]}function Ow(t){const e=Number(t.additions??0),s=Number(t.changes??e),i=Number(t.deletions??Math.max(0,s-e));return{filename:String(t.filename??""),status:t.status??"modified",additions:e,deletions:i,blobUrl:typeof t.blob_url=="string"?t.blob_url:null}}function Wf(t){const e=B.c(11);let s;e[0]!==t.connectionId||e[1]!==t.orgId?(s={connectionId:t.connectionId,orgId:t.orgId},e[0]=t.connectionId,e[1]=t.orgId,e[2]=s):s=e[2];const i=Me(s),n=t.prNumber??0;let o;e[3]!==t.owner||e[4]!==t.repo||e[5]!==n?(o={method:"get_check_runs",owner:t.owner,repo:t.repo,pullNumber:n},e[3]=t.owner,e[4]=t.repo,e[5]=n,e[6]=o):o=e[6];const a=!!t.prNumber;let l;return e[7]!==i||e[8]!==o||e[9]!==a?(l={client:i,toolName:"pull_request_read",toolArguments:o,enabled:a,refetchInterval:go,refetchIntervalInBackground:!1,staleTime:_o,select:$w},e[7]=i,e[8]=o,e[9]=a,e[10]=l):l=e[10],wi(l)}function $w(t){const e=Zr(t);return(Array.isArray(e)?e:e?.check_runs??[]).map(zw)}function zw(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 Fw(t){const e=B.c(11);let s;e[0]!==t.connectionId||e[1]!==t.orgId?(s={connectionId:t.connectionId,orgId:t.orgId},e[0]=t.connectionId,e[1]=t.orgId,e[2]=s):s=e[2];const i=Me(s),n=t.prNumber??0;let o;e[3]!==t.owner||e[4]!==t.repo||e[5]!==n?(o={method:"get_comments",owner:t.owner,repo:t.repo,pullNumber:n},e[3]=t.owner,e[4]=t.repo,e[5]=n,e[6]=o):o=e[6];const a=!!t.prNumber;let l;return e[7]!==i||e[8]!==o||e[9]!==a?(l={client:i,toolName:"pull_request_read",toolArguments:o,enabled:a,refetchInterval:go,refetchIntervalInBackground:!1,staleTime:_o,select:Hw},e[7]=i,e[8]=o,e[9]=a,e[10]=l):l=e[10],wi(l)}function Hw(t){const e=Zr(t);return Array.isArray(e)?e.map(Ww):[]}function Ww(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 Uw(t){const e=B.c(27),{pr:s,connectionId:i,owner:n,repo:o}=t,{org:a}=be();let l;e[0]!==i||e[1]!==a.id||e[2]!==n||e[3]!==s.number||e[4]!==o?(l={orgId:a.id,connectionId:i,owner:n,repo:o,prNumber:s.number},e[0]=i,e[1]=a.id,e[2]=n,e[3]=s.number,e[4]=o,e[5]=l):l=e[5];const c=Hf(l);if(c.isLoading){let x;return e[6]===Symbol.for("react.memo_cache_sentinel")?(x=r.jsx("div",{className:"text-sm text-muted-foreground",children:"Loading files…"}),e[6]=x):x=e[6],x}if(c.isError){let x;return e[7]===Symbol.for("react.memo_cache_sentinel")?(x=r.jsx("div",{className:"text-sm text-destructive",children:"Couldn't load file list."}),e[7]=x):x=e[7],x}let d;e[8]!==c.data?(d=c.data??[],e[8]=c.data,e[9]=d):d=e[9];const u=d;if(u.length===0){let x;return e[10]===Symbol.for("react.memo_cache_sentinel")?(x=r.jsx("div",{className:"text-sm text-muted-foreground",children:"No files changed."}),e[10]=x):x=e[10],x}const h=u.length===1?"":"s",f=`${s.htmlUrl}/files`;let m;e[11]!==f?(m=r.jsx("a",{href:f,target:"_blank",rel:"noreferrer",className:"underline hover:text-foreground",children:"View diffs on GitHub"}),e[11]=f,e[12]=m):m=e[12];let p;e[13]!==u.length||e[14]!==h||e[15]!==m?(p=r.jsxs("div",{className:"pb-2 text-xs text-muted-foreground",children:[u.length," file",h," changed ·"," ",m]}),e[13]=u.length,e[14]=h,e[15]=m,e[16]=p):p=e[16];let g;if(e[17]!==u||e[18]!==s.htmlUrl){let x;e[20]!==s.htmlUrl?(x=b=>r.jsx("li",{children:r.jsxs("a",{href:b.blobUrl??`${s.htmlUrl}/files`,target:"_blank",rel:"noreferrer",className:"flex items-center justify-between rounded px-2 py-1 font-mono text-xs hover:bg-muted",children:[r.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[r.jsx(Kw,{status:b.status}),r.jsx("span",{className:"truncate",children:b.filename})]}),r.jsxs("span",{className:"flex shrink-0 items-center gap-2 tabular-nums",children:[r.jsxs("span",{children:[r.jsxs("span",{className:"text-success",children:["+",b.additions]})," ",r.jsxs("span",{className:"text-destructive",children:["−",b.deletions]})]}),r.jsx(Vi,{className:"h-3 w-3 text-muted-foreground"})]})]})},b.filename),e[20]=s.htmlUrl,e[21]=x):x=e[21],g=u.map(x),e[17]=u,e[18]=s.htmlUrl,e[19]=g}else g=e[19];let _;e[22]!==g?(_=r.jsx("ul",{className:"space-y-0.5",children:g}),e[22]=g,e[23]=_):_=e[23];let v;return e[24]!==p||e[25]!==_?(v=r.jsxs("div",{className:"flex flex-col gap-1",children:[p,_]}),e[24]=p,e[25]=_,e[26]=v):v=e[26],v}function Kw(t){const e=B.c(2),{status:s}=t,i=s==="added"?"A":s==="removed"?"D":s==="renamed"?"R":s==="copied"?"C":"M";let n;return e[0]!==i?(n=r.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center rounded bg-muted text-[10px] font-bold text-muted-foreground",children:i}),e[0]=i,e[1]=n):n=e[1],n}const Ps="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 qw(t){return`Commit every pending change in the working tree with a concise conventional-commit message summarizing the diff, then push to \`origin/${t.branch}\`. If local commits are ahead of the remote, push those in the same invocation. ${Ps}`}function Gw(t){return`Open a pull request for \`${t.branch}\` against its base. Write a clear title and a summary of the changes so far. ${Ps}`}function Yw(t){return`Reopen PR #${t.prNumber}. ${Ps}`}function Xw(t){return`Rebase \`${t.branch}\` on the latest base and force-push with --force-with-lease. ${Ps}`}function Jw(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. ${Ps}`}function Qw(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. ${Ps}`}function Zw(t){return`Mark PR #${t.prNumber} ready for review. ${Ps}`}function eV(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. ${Ps}`}function tV(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. ${Ps}`}function sV(t){return`Squash-merge PR #${t.prNumber} into its base. ${Ps}`}function iV(t){const e=B.c(23),{pr:s,connectionId:i,owner:n,repo:o}=t,{org:a}=be(),l=Zn();let c;e[0]!==i||e[1]!==a.id||e[2]!==n||e[3]!==s.number||e[4]!==o?(c={orgId:a.id,connectionId:i,owner:n,repo:o,prNumber:s.number},e[0]=i,e[1]=a.id,e[2]=n,e[3]=s.number,e[4]=o,e[5]=c):c=e[5];const d=Wf(c);let u;e[6]!==l||e[7]!==s.number?(u=_=>l.sendMessage({parts:[{type:"text",text:Jw({prNumber:s.number,checkName:_})}]}),e[6]=l,e[7]=s.number,e[8]=u):u=e[8];const h=u;if(d.isLoading){let _;return e[9]===Symbol.for("react.memo_cache_sentinel")?(_=r.jsx("div",{className:"text-sm text-muted-foreground",children:"Loading checks…"}),e[9]=_):_=e[9],_}if(d.isError){let _;return e[10]===Symbol.for("react.memo_cache_sentinel")?(_=r.jsx("div",{className:"text-sm text-destructive",children:"Couldn't load check runs."}),e[10]=_):_=e[10],_}let f;e[11]!==d.data?(f=d.data??[],e[11]=d.data,e[12]=f):f=e[12];const m=f;if(m.length===0){let _;return e[13]===Symbol.for("react.memo_cache_sentinel")?(_=r.jsx("div",{className:"text-sm text-muted-foreground",children:"No check runs on the PR head commit."}),e[13]=_):_=e[13],_}let p;if(e[14]!==l||e[15]!==m||e[16]!==h){let _;e[18]!==l||e[19]!==h?(_=v=>r.jsxs("li",{className:"flex items-center justify-between gap-2 rounded px-2 py-1.5 text-sm hover:bg-muted",children:[r.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[r.jsx(rV,{check:v}),r.jsx("span",{className:"truncate",children:v.name}),v.durationMs!=null&&r.jsx("span",{className:"text-xs text-muted-foreground",children:nV(v.durationMs)})]}),r.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[v.htmlUrl&&r.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:r.jsx(Vi,{className:"h-3.5 w-3.5"})}),v.conclusion==="failure"&&r.jsx(ne,{size:"sm",variant:"ghost",disabled:l.isStreaming,onClick:()=>h(v.name),children:"Re-run"})]})]},v.id),e[18]=l,e[19]=h,e[20]=_):_=e[20],p=m.map(_),e[14]=l,e[15]=m,e[16]=h,e[17]=p}else p=e[17];let g;return e[21]!==p?(g=r.jsx("ul",{className:"flex flex-col gap-0.5",children:p}),e[21]=p,e[22]=g):g=e[22],g}function rV(t){const e=B.c(5),{check:s}=t;if(s.status!=="completed"){let o;return e[0]===Symbol.for("react.memo_cache_sentinel")?(o=r.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=r.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=r.jsx("span",{className:"text-destructive","aria-label":"Failure",children:"✗"}),e[2]=o):o=e[2],o}const i=s.conclusion??"—";let n;return e[3]!==i?(n=r.jsx("span",{className:"text-muted-foreground","aria-label":i,children:"—"}),e[3]=i,e[4]=n):n=e[4],n}function nV(t){const e=Math.round(t/1e3);return e<60?`${e}s`:`${Math.round(e/60)}m`}function oV(t){const e=B.c(10),{comments:s,isLoading:i,isError:n}=t;if(i||n||!s||s.length===0)return null;const o=s.length===1?"":"s";let a;e[0]!==s.length||e[1]!==o?(a=r.jsxs(Fg,{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(aV),e[3]=s,e[4]=l):l=e[4];let c;e[5]!==l?(c=r.jsx(Hg,{className:"space-y-3 pb-3",children:l}),e[5]=l,e[6]=c):c=e[6];let d;return e[7]!==a||e[8]!==c?(d=r.jsx(Wg,{type:"single",collapsible:!0,className:"border-t border-border",children:r.jsxs(Ug,{value:"comments",className:"border-b-0",children:[a,c]})}),e[7]=a,e[8]=c,e[9]=d):d=e[9],d}function aV(t){return r.jsxs("div",{className:"rounded-md border border-border p-3",children:[r.jsxs("div",{className:"mb-1 text-xs text-muted-foreground",children:["@",t.author," · ",lV(t.createdAt)]}),r.jsx(ll,{id:`pr-comment-${t.id}`,text:Dr(t.body)})]},t.id)}function lV(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 n=Math.floor(s/36e5);if(n>0)return`${n}h ago`;const o=Math.floor(s/6e4);return`${Math.max(1,o)}m ago`}function cV(t){const e=B.c(18),{pr:s,connectionId:i,owner:n,repo:o}=t,{org:a}=be();let l;e[0]!==i||e[1]!==a.id||e[2]!==n||e[3]!==s.number||e[4]!==o?(l={orgId:a.id,connectionId:i,owner:n,repo:o,prNumber:s.number},e[0]=i,e[1]=a.id,e[2]=n,e[3]=s.number,e[4]=o,e[5]=l):l=e[5];const c=Fw(l);let d;e[6]!==s.body||e[7]!==s.number?(d=s.body&&r.jsx("div",{className:"text-sm",children:r.jsx(ll,{id:`pr-body-${s.number}`,text:Dr(s.body)})}),e[6]=s.body,e[7]=s.number,e[8]=d):d=e[8];let u;e[9]!==c.data?(u=c.data??[],e[9]=c.data,e[10]=u):u=e[10];let h;e[11]!==c.isError||e[12]!==c.isLoading||e[13]!==u?(h=r.jsx(oV,{comments:u,isLoading:c.isLoading,isError:c.isError}),e[11]=c.isError,e[12]=c.isLoading,e[13]=u,e[14]=h):h=e[14];let f;return e[15]!==d||e[16]!==h?(f=r.jsxs("div",{className:"space-y-8",children:[d,h]}),e[15]=d,e[16]=h,e[17]=f):f=e[17],f}function dV(t){const e=B.c(26),{pr:s,connectionId:i,owner:n,repo:o}=t,{org:a}=be();let l;e[0]!==i||e[1]!==a.id||e[2]!==n||e[3]!==s.number||e[4]!==o?(l={orgId:a.id,connectionId:i,owner:n,repo:o,prNumber:s.number},e[0]=i,e[1]=a.id,e[2]=n,e[3]=s.number,e[4]=o,e[5]=l):l=e[5];const d=Hf(l).data?.length,[u,h]=S.useState("description"),f=S.useRef({description:null,changes:null,checks:null}),[m,p]=S.useState(null),g=w=>k=>{if(f.current[w]=k,k&&w===u){const T=k.offsetLeft,I=k.offsetWidth;(m===null||T!==m.left||I!==m.width)&&p({left:T,width:I})}},_=w=>{const k=w;h(k);const T=f.current[k];T&&p({left:T.offsetLeft,width:T.offsetWidth})},v=Vo,x=g("checks");let b;e[6]!==v||e[7]!==x?(b=r.jsx(v,{ref:x,variant:"underline",value:"checks",className:"pb-3 data-[state=active]:border-transparent",children:"Checks"}),e[6]=v,e[7]=x,e[8]=b):b=e[8];let y;e[9]!==m?(y=m&&r.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute bottom-[-1px] h-0.5 bg-primary transition-[left,width] duration-200 ease-out",style:{left:m.left,width:m.width}}),e[9]=m,e[10]=y):y=e[10];let C;e[11]!==i||e[12]!==n||e[13]!==s||e[14]!==o?(C=r.jsx(yn,{value:"description",className:"mt-6",children:r.jsx(cV,{pr:s,connectionId:i,owner:n,repo:o})}),e[11]=i,e[12]=n,e[13]=s,e[14]=o,e[15]=C):C=e[15];let j;e[16]!==i||e[17]!==n||e[18]!==s||e[19]!==o?(j=r.jsx(yn,{value:"changes",className:"mt-6",children:r.jsx(Uw,{pr:s,connectionId:i,owner:n,repo:o})}),e[16]=i,e[17]=n,e[18]=s,e[19]=o,e[20]=j):j=e[20];let V;return e[21]!==i||e[22]!==n||e[23]!==s||e[24]!==o?(V=r.jsx(yn,{value:"checks",className:"mt-6",children:r.jsx(iV,{pr:s,connectionId:i,owner:n,repo:o})}),e[21]=i,e[22]=n,e[23]=s,e[24]=o,e[25]=V):V=e[25],r.jsxs(Mh,{value:u,onValueChange:_,variant:"underline",children:[r.jsxs(cg,{variant:"underline",className:"relative h-auto p-0",children:[r.jsx(Vo,{ref:g("description"),variant:"underline",value:"description",className:"pb-3 data-[state=active]:border-transparent",children:"Description"}),r.jsxs(Vo,{ref:g("changes"),variant:"underline",value:"changes",className:"pb-3 data-[state=active]:border-transparent",children:["Changes",d!==void 0?` ${d}`:""]}),b,y]}),C,j,V]})}function hV(t){const e=B.c(5),{pr:s}=t,i=`Open PR #${s.number} on GitHub`;let n;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=r.jsx(Vi,{className:"h-4 w-4 text-muted-foreground"}),e[0]=n):n=e[0];let o;return e[1]!==s.htmlUrl||e[2]!==s.number||e[3]!==i?(o=r.jsx("div",{className:"flex h-12 items-center border-b border-border px-4 shrink-0",children:r.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,n]})}),e[1]=s.htmlUrl,e[2]=s.number,e[3]=i,e[4]=o):o=e[4],o}function uV(t){const e=B.c(23),{pr:s}=t;let i;e[0]!==s.title?(i=Dr(s.title),e[0]=s.title,e[1]=i):i=e[1];let n;e[2]!==i?(n=r.jsx("h1",{className:"text-2xl font-semibold",children:i}),e[2]=i,e[3]=n):n=e[3];const o=`Open PR #${s.number} on GitHub`;let a;e[4]===Symbol.for("react.memo_cache_sentinel")?(a=r.jsx(Vi,{className:"h-3.5 w-3.5"}),e[4]=a):a=e[4];let l;e[5]!==s.htmlUrl||e[6]!==s.number||e[7]!==o?(l=r.jsxs("a",{href:s.htmlUrl,target:"_blank",rel:"noreferrer","aria-label":o,className:"inline-flex items-center gap-1 hover:text-foreground",children:["PR #",s.number,a]}),e[5]=s.htmlUrl,e[6]=s.number,e[7]=o,e[8]=l):l=e[8];let c;e[9]!==s.author?(c=s.author&&r.jsxs(r.Fragment,{children:["@",s.author," · "]}),e[9]=s.author,e[10]=c):c=e[10];let d;e[11]!==s.base?(d=r.jsx("span",{className:"font-mono text-xs",children:s.base}),e[11]=s.base,e[12]=d):d=e[12];let u;e[13]!==s.head?(u=r.jsx("span",{className:"font-mono text-xs",children:s.head}),e[13]=s.head,e[14]=u):u=e[14];let h;e[15]!==l||e[16]!==c||e[17]!==d||e[18]!==u?(h=r.jsxs("div",{className:"text-sm text-muted-foreground",children:[l," · ",c,d," ← ",u]}),e[15]=l,e[16]=c,e[17]=d,e[18]=u,e[19]=h):h=e[19];let f;return e[20]!==n||e[21]!==h?(f=r.jsxs("div",{className:"space-y-2",children:[n,h]}),e[20]=n,e[21]=h,e[22]=f):f=e[22],f}function fV(t){const e=B.c(8),{virtualMcpId:s}=t,{org:i}=be(),n=ts(s),{currentBranch:o}=es(),a=n?.metadata?.githubRepo??null;if(!a?.connectionId){let c;return e[0]===Symbol.for("react.memo_cache_sentinel")?(c=r.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]=c):c=e[0],c}if(!o){let c;return e[1]===Symbol.for("react.memo_cache_sentinel")?(c=r.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-8 text-sm",children:[r.jsx(gr,{className:"h-6 w-6 text-muted-foreground"}),r.jsx("div",{className:"text-muted-foreground",children:"No branch selected."}),r.jsx("div",{className:"text-xs text-muted-foreground",children:"Pick a branch from the dropdown in the header to see PR status."})]}),e[1]=c):c=e[1],c}let l;return e[2]!==o||e[3]!==a.connectionId||e[4]!==a.name||e[5]!==a.owner||e[6]!==i.id?(l=r.jsx(mV,{orgId:i.id,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]=l):l=e[7],l}function mV(t){const e=B.c(49),{orgId:s,connectionId:i,owner:n,repo:o,branch:a}=t;let l;e[0]!==a||e[1]!==i||e[2]!==s||e[3]!==n||e[4]!==o?(l={orgId:s,connectionId:i,owner:n,repo:o,branch:a},e[0]=a,e[1]=i,e[2]=s,e[3]=n,e[4]=o,e[5]=l):l=e[5];const{data:c,isLoading:d,isError:u}=Ff(l),h=pV;if(d){let v;return e[6]===Symbol.for("react.memo_cache_sentinel")?(v=r.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"Loading PR state…"}),e[6]=v):v=e[6],v}if(u){let v;return e[7]===Symbol.for("react.memo_cache_sentinel")?(v=r.jsx("div",{className:"p-4 text-sm text-destructive",children:"Couldn't load PR state. The GitHub connection may be broken."}),e[7]=v):v=e[7],v}const f=`https://github.com/${n}/${o}/tree/${a}`;if(c&&c.state==="closed"){let v;e[8]!==c?(v=r.jsx(hV,{pr:c}),e[8]=c,e[9]=v):v=e[9];const x=c.merged?"✓ Merged":"✗ Closed";let b;e[10]!==c.mergedAt?(b=c.mergedAt&&r.jsxs(r.Fragment,{children:[" · ",new Date(c.mergedAt).toLocaleDateString()]}),e[10]=c.mergedAt,e[11]=b):b=e[11];let y;e[12]!==c.author?(y=c.author&&r.jsxs(r.Fragment,{children:[" · by @",c.author]}),e[12]=c.author,e[13]=y):y=e[13];let C;e[14]!==c.base||e[15]!==x||e[16]!==b||e[17]!==y?(C=r.jsxs("div",{className:"text-sm text-success",children:[x," into ",c.base,b,y]}),e[14]=c.base,e[15]=x,e[16]=b,e[17]=y,e[18]=C):C=e[18];let j;e[19]!==c.title?(j=Dr(c.title),e[19]=c.title,e[20]=j):j=e[20];let V;e[21]!==j?(V=r.jsx("h1",{className:"text-lg font-semibold",children:j}),e[21]=j,e[22]=V):V=e[22];let w;e[23]!==c.body||e[24]!==c.number?(w=c.body&&r.jsx("div",{className:"rounded-md border border-border bg-muted/30 p-3 text-sm",children:r.jsx(ll,{id:`pr-body-${c.number}`,text:Dr(c.body)})}),e[23]=c.body,e[24]=c.number,e[25]=w):w=e[25];let k;e[26]!==C||e[27]!==V||e[28]!==w?(k=r.jsxs("div",{className:"flex flex-col gap-4 p-4 overflow-auto",children:[C,V,w]}),e[26]=C,e[27]=V,e[28]=w,e[29]=k):k=e[29];let T;return e[30]!==v||e[31]!==k?(T=r.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[v,k]}),e[30]=v,e[31]=k,e[32]=T):T=e[32],T}if(c&&c.state==="open"){let v;e[33]!==c?(v=r.jsx(uV,{pr:c}),e[33]=c,e[34]=v):v=e[34];let x;e[35]!==i||e[36]!==n||e[37]!==c||e[38]!==o?(x=r.jsx("div",{className:"mt-8",children:r.jsx(dV,{pr:c,connectionId:i,owner:n,repo:o})}),e[35]=i,e[36]=n,e[37]=c,e[38]=o,e[39]=x):x=e[39];let b;return e[40]!==v||e[41]!==x?(b=r.jsx("div",{className:"flex min-h-0 flex-1 flex-col",children:r.jsx("div",{className:"flex-1 overflow-auto",children:r.jsxs("div",{className:"mx-auto w-full max-w-[1200px] px-4 pt-8 pb-6 md:px-10 md:pt-12 md:pb-10",children:[v,x]})})}),e[40]=v,e[41]=x,e[42]=b):b=e[42],b}let m;e[43]===Symbol.for("react.memo_cache_sentinel")?(m=r.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[43]=m):m=e[43];let p;e[44]!==f?(p=()=>h(f),e[44]=f,e[45]=p):p=e[45];let g;e[46]===Symbol.for("react.memo_cache_sentinel")?(g=r.jsx(Vi,{className:"mr-1.5 h-4 w-4"}),e[46]=g):g=e[46];let _;return e[47]!==p?(_=r.jsxs("div",{className:"flex flex-col gap-4 p-4",children:[m,r.jsx("div",{className:"flex items-center gap-2",children:r.jsxs(ne,{size:"sm",variant:"outline",onClick:p,children:[g,"Open branch on GitHub"]})})]}),e[47]=p,e[48]=_):_=e[48],_}function pV(t){window.open(t,"_blank","noopener,noreferrer")}const Oo="env";function gV(){const t=B.c(13),e=Ke();let s;t[0]===Symbol.for("react.memo_cache_sentinel")?(s={strict:!1},t[0]=s):s=t[0];const n=vi(s).main===Oo;let o;t[1]!==e?(o=f=>{e({search:(m=>({...m,main:f})),replace:!0})},t[1]=e,t[2]=o):o=t[2];const a=o;let l;t[3]!==n||t[4]!==a?(l=()=>{a(n?"0":Oo)},t[3]=n,t[4]=a,t[5]=l):l=t[5];const c=l;let d;t[6]!==n||t[7]!==a?(d=()=>{n||a(Oo)},t[6]=n,t[7]=a,t[8]=d):d=t[8];const u=d;let h;return t[9]!==n||t[10]!==u||t[11]!==c?(h={envOpen:n,toggleEnv:c,openEnv:u},t[9]=n,t[10]=u,t[11]=c,t[12]=h):h=t[12],h}const _V=Vs({tag:Et(),id:Et(),classes:Et(),text:Et(),html:Et(),manifestKey:Et().nullable(),componentName:Et().nullable(),parents:Et(),url:Et(),path:Et(),viewport:Vs({width:nn(),height:nn()}),position:Vs({x:nn(),y:nn()})}),xV=`(function() {
295
+ ${ee}`:ee;l.setValue("metadata.instructions",K,{shouldDirty:!0})},$=new Set(c.map(H=>H.connection_id)),W=Ke(),[F,G]=S.useState(!1),q=async()=>{T();try{await i.delete.mutateAsync(t.id),se("agent_deleted",{agent_id:t.id,source:"agent_detail"}),pe.success(`Deleted "${t.title}"`),W({to:"/$org",params:{org:s.slug}})}catch{}};return r.jsxs(hs,{children:[r.jsx(hs.Content,{children:r.jsx(hs.Body,{children:r.jsxs("div",{className:"flex flex-col gap-10",children:[!e&&r.jsx(hs.Title,{actions:r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs(ne,{variant:"outline",size:"sm",onClick:x,children:[r.jsx(Cn,{size:14,className:"!size-[14px]"}),"Test Agent"]}),r.jsx(ne,{variant:"ghost",size:"icon",className:"text-muted-foreground hover:text-destructive",onClick:()=>G(!0),children:r.jsx(ha,{size:14})})]}),children:"Settings"}),r.jsxs("div",{className:"flex items-center gap-3",children:[r.jsx(Ai,{name:"icon",control:l.control,render:({field:H})=>r.jsx(ZS,{value:H.value??null,onChange:ee=>{H.onChange(ee),I()},onColorChange:ee=>{l.setValue("metadata.ui.themeColor",ee,{shouldDirty:!0}),I()},name:l.watch("title")||"Agent",size:"md",className:"shrink-0",avatarClassName:"[&_svg]:w-1/2 [&_svg]:h-1/2",disabled:d})}),r.jsxs("div",{className:"flex flex-col flex-1 min-w-0",children:[r.jsx(Ai,{name:"title",control:l.control,render:({field:H})=>r.jsx("input",{...H,type:"text",value:H.value??"",onBlur:()=>{H.onBlur(),I()},disabled:d,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"})}),r.jsx(Ai,{name:"description",control:l.control,render:({field:H})=>r.jsx("input",{...H,type:"text",value:H.value??"",onBlur:()=>{H.onBlur(),I()},disabled:d,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"})})]}),r.jsxs(ne,{variant:"outline",size:"sm",className:"shrink-0",onClick:()=>{se("agent_connect_modal_opened",{agent_id:t.id}),h({type:"SET_SHARE_DIALOG_OPEN",payload:!0})},children:[r.jsxs("span",{className:"flex items-center -space-x-1.5 mr-0.5",children:[r.jsx("span",{className:"inline-flex items-center justify-center size-4 rounded-full bg-black ring-1 ring-white/20 shrink-0",children:r.jsx("img",{src:"/logos/cursor.svg",alt:"Cursor",className:"size-2.5 brightness-0 invert"})}),r.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:r.jsx("img",{src:"/logos/Claude Code.svg",alt:"Claude",className:"size-2.5 brightness-0 invert"})})]}),"Connect"]})]}),r.jsxs("section",{className:"flex flex-col gap-3",children:[r.jsxs("div",{className:"flex items-center justify-between gap-3",children:[r.jsx("h2",{className:"text-sm font-medium text-foreground",children:"Connections"}),c.length>0&&r.jsxs(ne,{variant:"outline",size:"sm",onClick:E,children:[r.jsx(Qt,{size:14}),"Add connection"]})]}),r.jsx("div",{className:"flex flex-col gap-2",children:c.length===0?r.jsxs("button",{type:"button",onClick:E,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:[r.jsx("div",{className:"flex items-center justify-center size-8 rounded-md text-muted-foreground/75 border border-dashed border-border shrink-0",children:r.jsx(Qt,{size:16})}),r.jsx("span",{className:"text-sm text-muted-foreground",children:"No connections yet. Add one to get started."})]}):c.map(H=>r.jsx(Cs,{fallback:()=>null,children:r.jsx(S.Suspense,{fallback:r.jsx(Ff,{}),children:r.jsx(Iw,{connection_id:H.connection_id,usedConnectionIds:$,onOpenSettings:()=>P(H.connection_id),onRemove:()=>M(H.connection_id),onAuthenticate:O,onSwitchInstance:L,onNewInstance:()=>D(H.connection_id)})})},H.connection_id))})]}),r.jsxs("section",{className:"flex flex-col gap-3",children:[r.jsxs("div",{className:"flex items-center justify-between gap-3",children:[r.jsx("h2",{className:"text-sm font-medium text-foreground",children:"Instructions"}),!d&&r.jsxs("div",{className:"flex items-center gap-2",children:[!l.watch("metadata.instructions")?.trim()&&r.jsx(ne,{variant:"outline",size:"sm",onClick:z,children:"+ Prompt template"}),r.jsxs(ne,{variant:"outline",size:"sm",disabled:!l.watch("metadata.instructions")?.trim(),onClick:v,children:[r.jsx(_l,{size:13}),"Improve"]})]})]}),r.jsx(Ai,{name:"metadata.instructions",control:l.control,render:({field:H})=>r.jsxs("div",{className:"relative rounded-xl card-shadow bg-card focus-within:ring-1 focus-within:ring-ring",children:[r.jsx(ca,{...H,value:H.value??"",onBlur:()=>{H.onBlur(),I()},disabled:d,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"}}),r.jsxs(it,{delayDuration:0,children:[r.jsx(tt,{asChild:!0,children:r.jsx(ne,{type:"button",variant:"ghost",size:"icon",className:"absolute top-2 right-2 h-7 w-7 text-muted-foreground",onClick:()=>m(!0),"aria-label":"Open fullscreen editor",children:r.jsx(kg,{size:14})})}),r.jsx(st,{side:"left",children:"Fullscreen"})]})]})})]}),r.jsx(Pw,{virtualMcpId:t.id}),r.jsxs("section",{className:"flex items-center justify-between border-t border-border pt-6",children:[r.jsxs("div",{children:[r.jsx("p",{className:"text-sm font-medium",children:"Delete agent"}),r.jsx("p",{className:"text-sm text-muted-foreground",children:"Permanently delete this agent and all its data."})]}),r.jsxs(ne,{variant:"outline",size:"sm",className:"text-destructive border-destructive/40 hover:bg-destructive/10 hover:text-destructive shrink-0",onClick:()=>G(!0),children:[r.jsx(ha,{size:14}),"Delete agent"]})]})]})})}),r.jsx(Il,{open:F,onOpenChange:G,children:r.jsxs(jl,{children:[r.jsxs(kl,{children:[r.jsx(Nl,{children:"Delete Agent?"}),r.jsxs(Al,{children:["This action cannot be undone. This will permanently delete"," ",r.jsx("span",{className:"font-medium text-foreground",children:t.title}),"."]})]}),r.jsxs(El,{children:[r.jsx(Cl,{children:"Cancel"}),r.jsx(yu,{onClick:q,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete"})]})]})}),r.jsx(Pl,{open:u.addDialogOpen,onOpenChange:H=>h({type:"SET_ADD_DIALOG_OPEN",payload:H}),agentId:t.id,addedConnectionIds:$,onAdd:R}),r.jsx(bw,{open:u.settingsDialogOpen,onOpenChange:H=>{H||h({type:"CLOSE_SETTINGS"})},selectedId:u.settingsConnectionId,form:l,connections:c,onAuthenticate:O}),r.jsx(Aw,{open:u.shareDialogOpen,onOpenChange:H=>h({type:"SET_SHARE_DIALOG_OPEN",payload:H}),virtualMcp:t}),r.jsx(ps,{open:f,onOpenChange:m,children:r.jsxs(ms,{className:"w-[90vw] sm:max-w-6xl h-[85vh] flex flex-col p-0 gap-0",children:[r.jsx(Ds,{className:"px-6 pt-6 pb-3 border-b border-border shrink-0",children:r.jsx(Ts,{children:"Instructions"})}),r.jsx("div",{className:"flex-1 min-h-0 p-6",children:r.jsx(Ai,{name:"metadata.instructions",control:l.control,render:({field:H})=>r.jsx(ca,{...H,value:H.value??"",onBlur:()=>{H.onBlur(),I()},disabled:d,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 Bw(t){const e=B.c(9),{virtualMcpId:s,hideOwnTitle:i}=t,n=Ke(),{org:o}=be(),a=ts(s);if(!a){let d;return e[0]!==n||e[1]!==o.slug?(d=r.jsx("div",{className:"flex h-full w-full bg-background",children:r.jsx(Oi,{title:"Space not found",description:"This space may have been deleted or you may not have access.",actions:r.jsx(ne,{variant:"outline",onClick:()=>n({to:"/$org",params:{org:o.slug}}),children:"Back to spaces"})})}),e[0]=n,e[1]=o.slug,e[2]=d):d=e[2],d}let l;e[3]!==a?(l=Fs(a)?.connectionId??"",e[3]=a,e[4]=l):l=e[4];let c;return e[5]!==i||e[6]!==l||e[7]!==a?(c=r.jsx(Lw,{virtualMcp:a,hideOwnTitle:i},l),e[5]=i,e[6]=l,e[7]=a,e[8]=c):c=e[8],c}function _d(t){const e=B.c(2),{virtualMcpId:s}=t;let i;return e[0]!==s?(i=r.jsx(Bw,{virtualMcpId:s,hideOwnTitle:!0}),e[0]=s,e[1]=i):i=e[1],i}const Ow={amp:"&",lt:"<",gt:">",quot:'"',apos:"'",nbsp:" "};function Dr(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 Ow[s]??e}):""}function Zr(t){if(!t||typeof t!="object")return null;const e=t;if(e.structuredContent!==void 0)return e.structuredContent;const s=e.content?.find(i=>i.type==="text")?.text;if(!s)return null;try{return JSON.parse(s)}catch{return null}}const go=6e4,_o=3e4;function Hf(t){const e=B.c(11);let s;e[0]!==t.connectionId||e[1]!==t.orgId?(s={connectionId:t.connectionId,orgId:t.orgId},e[0]=t.connectionId,e[1]=t.orgId,e[2]=s):s=e[2];const i=Me(s),n=t.branch?`${t.owner}:${t.branch}`:void 0;let o;e[3]!==t.owner||e[4]!==t.repo||e[5]!==n?(o={owner:t.owner,repo:t.repo,state:"all",head:n,perPage:1},e[3]=t.owner,e[4]=t.repo,e[5]=n,e[6]=o):o=e[6];const a=!!t.branch;let l;return e[7]!==i||e[8]!==o||e[9]!==a?(l={client:i,toolName:"list_pull_requests",toolArguments:o,enabled:a,refetchInterval:go,refetchIntervalInBackground:!1,staleTime:_o,select:$w},e[7]=i,e[8]=o,e[9]=a,e[10]=l):l=e[10],wi(l)}function $w(t){const e=Zr(t);if(!e||!Array.isArray(e)||e.length===0)return null;const s=e[0],i=s.base,n=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:n?.ref??"",headSha:n?.sha??"",htmlUrl:s.html_url??"",author:o?.login??""}}function Wf(t){const e=B.c(11);let s;e[0]!==t.connectionId||e[1]!==t.orgId?(s={connectionId:t.connectionId,orgId:t.orgId},e[0]=t.connectionId,e[1]=t.orgId,e[2]=s):s=e[2];const i=Me(s),n=t.prNumber??0;let o;e[3]!==t.owner||e[4]!==t.repo||e[5]!==n?(o={method:"get_files",owner:t.owner,repo:t.repo,pullNumber:n},e[3]=t.owner,e[4]=t.repo,e[5]=n,e[6]=o):o=e[6];const a=!!t.prNumber;let l;return e[7]!==i||e[8]!==o||e[9]!==a?(l={client:i,toolName:"pull_request_read",toolArguments:o,enabled:a,refetchInterval:go,refetchIntervalInBackground:!1,staleTime:_o,select:zw},e[7]=i,e[8]=o,e[9]=a,e[10]=l):l=e[10],wi(l)}function zw(t){const e=Zr(t);return Array.isArray(e)?e.map(Fw):[]}function Fw(t){const e=Number(t.additions??0),s=Number(t.changes??e),i=Number(t.deletions??Math.max(0,s-e));return{filename:String(t.filename??""),status:t.status??"modified",additions:e,deletions:i,blobUrl:typeof t.blob_url=="string"?t.blob_url:null}}function Uf(t){const e=B.c(11);let s;e[0]!==t.connectionId||e[1]!==t.orgId?(s={connectionId:t.connectionId,orgId:t.orgId},e[0]=t.connectionId,e[1]=t.orgId,e[2]=s):s=e[2];const i=Me(s),n=t.prNumber??0;let o;e[3]!==t.owner||e[4]!==t.repo||e[5]!==n?(o={method:"get_check_runs",owner:t.owner,repo:t.repo,pullNumber:n},e[3]=t.owner,e[4]=t.repo,e[5]=n,e[6]=o):o=e[6];const a=!!t.prNumber;let l;return e[7]!==i||e[8]!==o||e[9]!==a?(l={client:i,toolName:"pull_request_read",toolArguments:o,enabled:a,refetchInterval:go,refetchIntervalInBackground:!1,staleTime:_o,select:Hw},e[7]=i,e[8]=o,e[9]=a,e[10]=l):l=e[10],wi(l)}function Hw(t){const e=Zr(t);return(Array.isArray(e)?e:e?.check_runs??[]).map(Ww)}function Ww(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 Uw(t){const e=B.c(11);let s;e[0]!==t.connectionId||e[1]!==t.orgId?(s={connectionId:t.connectionId,orgId:t.orgId},e[0]=t.connectionId,e[1]=t.orgId,e[2]=s):s=e[2];const i=Me(s),n=t.prNumber??0;let o;e[3]!==t.owner||e[4]!==t.repo||e[5]!==n?(o={method:"get_comments",owner:t.owner,repo:t.repo,pullNumber:n},e[3]=t.owner,e[4]=t.repo,e[5]=n,e[6]=o):o=e[6];const a=!!t.prNumber;let l;return e[7]!==i||e[8]!==o||e[9]!==a?(l={client:i,toolName:"pull_request_read",toolArguments:o,enabled:a,refetchInterval:go,refetchIntervalInBackground:!1,staleTime:_o,select:Kw},e[7]=i,e[8]=o,e[9]=a,e[10]=l):l=e[10],wi(l)}function Kw(t){const e=Zr(t);return Array.isArray(e)?e.map(qw):[]}function qw(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 Gw(t){const e=B.c(27),{pr:s,connectionId:i,owner:n,repo:o}=t,{org:a}=be();let l;e[0]!==i||e[1]!==a.id||e[2]!==n||e[3]!==s.number||e[4]!==o?(l={orgId:a.id,connectionId:i,owner:n,repo:o,prNumber:s.number},e[0]=i,e[1]=a.id,e[2]=n,e[3]=s.number,e[4]=o,e[5]=l):l=e[5];const c=Wf(l);if(c.isLoading){let x;return e[6]===Symbol.for("react.memo_cache_sentinel")?(x=r.jsx("div",{className:"text-sm text-muted-foreground",children:"Loading files…"}),e[6]=x):x=e[6],x}if(c.isError){let x;return e[7]===Symbol.for("react.memo_cache_sentinel")?(x=r.jsx("div",{className:"text-sm text-destructive",children:"Couldn't load file list."}),e[7]=x):x=e[7],x}let d;e[8]!==c.data?(d=c.data??[],e[8]=c.data,e[9]=d):d=e[9];const u=d;if(u.length===0){let x;return e[10]===Symbol.for("react.memo_cache_sentinel")?(x=r.jsx("div",{className:"text-sm text-muted-foreground",children:"No files changed."}),e[10]=x):x=e[10],x}const h=u.length===1?"":"s",f=`${s.htmlUrl}/files`;let m;e[11]!==f?(m=r.jsx("a",{href:f,target:"_blank",rel:"noreferrer",className:"underline hover:text-foreground",children:"View diffs on GitHub"}),e[11]=f,e[12]=m):m=e[12];let p;e[13]!==u.length||e[14]!==h||e[15]!==m?(p=r.jsxs("div",{className:"pb-2 text-xs text-muted-foreground",children:[u.length," file",h," changed ·"," ",m]}),e[13]=u.length,e[14]=h,e[15]=m,e[16]=p):p=e[16];let g;if(e[17]!==u||e[18]!==s.htmlUrl){let x;e[20]!==s.htmlUrl?(x=b=>r.jsx("li",{children:r.jsxs("a",{href:b.blobUrl??`${s.htmlUrl}/files`,target:"_blank",rel:"noreferrer",className:"flex items-center justify-between rounded px-2 py-1 font-mono text-xs hover:bg-muted",children:[r.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[r.jsx(Yw,{status:b.status}),r.jsx("span",{className:"truncate",children:b.filename})]}),r.jsxs("span",{className:"flex shrink-0 items-center gap-2 tabular-nums",children:[r.jsxs("span",{children:[r.jsxs("span",{className:"text-success",children:["+",b.additions]})," ",r.jsxs("span",{className:"text-destructive",children:["−",b.deletions]})]}),r.jsx(Vi,{className:"h-3 w-3 text-muted-foreground"})]})]})},b.filename),e[20]=s.htmlUrl,e[21]=x):x=e[21],g=u.map(x),e[17]=u,e[18]=s.htmlUrl,e[19]=g}else g=e[19];let _;e[22]!==g?(_=r.jsx("ul",{className:"space-y-0.5",children:g}),e[22]=g,e[23]=_):_=e[23];let v;return e[24]!==p||e[25]!==_?(v=r.jsxs("div",{className:"flex flex-col gap-1",children:[p,_]}),e[24]=p,e[25]=_,e[26]=v):v=e[26],v}function Yw(t){const e=B.c(2),{status:s}=t,i=s==="added"?"A":s==="removed"?"D":s==="renamed"?"R":s==="copied"?"C":"M";let n;return e[0]!==i?(n=r.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center rounded bg-muted text-[10px] font-bold text-muted-foreground",children:i}),e[0]=i,e[1]=n):n=e[1],n}const Ps="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 Xw(t){return`Commit every pending change in the working tree with a concise conventional-commit message summarizing the diff, then push to \`origin/${t.branch}\`. If local commits are ahead of the remote, push those in the same invocation. ${Ps}`}function Jw(t){return`Open a pull request for \`${t.branch}\` against its base. Write a clear title and a summary of the changes so far. ${Ps}`}function Qw(t){return`Reopen PR #${t.prNumber}. ${Ps}`}function Zw(t){return`Rebase \`${t.branch}\` on the latest base and force-push with --force-with-lease. ${Ps}`}function eV(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. ${Ps}`}function tV(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. ${Ps}`}function sV(t){return`Mark PR #${t.prNumber} ready for review. ${Ps}`}function iV(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. ${Ps}`}function rV(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. ${Ps}`}function nV(t){return`Squash-merge PR #${t.prNumber} into its base. ${Ps}`}function oV(t){const e=B.c(23),{pr:s,connectionId:i,owner:n,repo:o}=t,{org:a}=be(),l=Zn();let c;e[0]!==i||e[1]!==a.id||e[2]!==n||e[3]!==s.number||e[4]!==o?(c={orgId:a.id,connectionId:i,owner:n,repo:o,prNumber:s.number},e[0]=i,e[1]=a.id,e[2]=n,e[3]=s.number,e[4]=o,e[5]=c):c=e[5];const d=Uf(c);let u;e[6]!==l||e[7]!==s.number?(u=_=>l.sendMessage({parts:[{type:"text",text:eV({prNumber:s.number,checkName:_})}]}),e[6]=l,e[7]=s.number,e[8]=u):u=e[8];const h=u;if(d.isLoading){let _;return e[9]===Symbol.for("react.memo_cache_sentinel")?(_=r.jsx("div",{className:"text-sm text-muted-foreground",children:"Loading checks…"}),e[9]=_):_=e[9],_}if(d.isError){let _;return e[10]===Symbol.for("react.memo_cache_sentinel")?(_=r.jsx("div",{className:"text-sm text-destructive",children:"Couldn't load check runs."}),e[10]=_):_=e[10],_}let f;e[11]!==d.data?(f=d.data??[],e[11]=d.data,e[12]=f):f=e[12];const m=f;if(m.length===0){let _;return e[13]===Symbol.for("react.memo_cache_sentinel")?(_=r.jsx("div",{className:"text-sm text-muted-foreground",children:"No check runs on the PR head commit."}),e[13]=_):_=e[13],_}let p;if(e[14]!==l||e[15]!==m||e[16]!==h){let _;e[18]!==l||e[19]!==h?(_=v=>r.jsxs("li",{className:"flex items-center justify-between gap-2 rounded px-2 py-1.5 text-sm hover:bg-muted",children:[r.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[r.jsx(aV,{check:v}),r.jsx("span",{className:"truncate",children:v.name}),v.durationMs!=null&&r.jsx("span",{className:"text-xs text-muted-foreground",children:lV(v.durationMs)})]}),r.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[v.htmlUrl&&r.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:r.jsx(Vi,{className:"h-3.5 w-3.5"})}),v.conclusion==="failure"&&r.jsx(ne,{size:"sm",variant:"ghost",disabled:l.isStreaming,onClick:()=>h(v.name),children:"Re-run"})]})]},v.id),e[18]=l,e[19]=h,e[20]=_):_=e[20],p=m.map(_),e[14]=l,e[15]=m,e[16]=h,e[17]=p}else p=e[17];let g;return e[21]!==p?(g=r.jsx("ul",{className:"flex flex-col gap-0.5",children:p}),e[21]=p,e[22]=g):g=e[22],g}function aV(t){const e=B.c(5),{check:s}=t;if(s.status!=="completed"){let o;return e[0]===Symbol.for("react.memo_cache_sentinel")?(o=r.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=r.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=r.jsx("span",{className:"text-destructive","aria-label":"Failure",children:"✗"}),e[2]=o):o=e[2],o}const i=s.conclusion??"—";let n;return e[3]!==i?(n=r.jsx("span",{className:"text-muted-foreground","aria-label":i,children:"—"}),e[3]=i,e[4]=n):n=e[4],n}function lV(t){const e=Math.round(t/1e3);return e<60?`${e}s`:`${Math.round(e/60)}m`}function cV(t){const e=B.c(10),{comments:s,isLoading:i,isError:n}=t;if(i||n||!s||s.length===0)return null;const o=s.length===1?"":"s";let a;e[0]!==s.length||e[1]!==o?(a=r.jsxs(Ug,{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(dV),e[3]=s,e[4]=l):l=e[4];let c;e[5]!==l?(c=r.jsx(Kg,{className:"space-y-3 pb-3",children:l}),e[5]=l,e[6]=c):c=e[6];let d;return e[7]!==a||e[8]!==c?(d=r.jsx(qg,{type:"single",collapsible:!0,className:"border-t border-border",children:r.jsxs(Gg,{value:"comments",className:"border-b-0",children:[a,c]})}),e[7]=a,e[8]=c,e[9]=d):d=e[9],d}function dV(t){return r.jsxs("div",{className:"rounded-md border border-border p-3",children:[r.jsxs("div",{className:"mb-1 text-xs text-muted-foreground",children:["@",t.author," · ",hV(t.createdAt)]}),r.jsx(ll,{id:`pr-comment-${t.id}`,text:Dr(t.body)})]},t.id)}function hV(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 n=Math.floor(s/36e5);if(n>0)return`${n}h ago`;const o=Math.floor(s/6e4);return`${Math.max(1,o)}m ago`}function uV(t){const e=B.c(18),{pr:s,connectionId:i,owner:n,repo:o}=t,{org:a}=be();let l;e[0]!==i||e[1]!==a.id||e[2]!==n||e[3]!==s.number||e[4]!==o?(l={orgId:a.id,connectionId:i,owner:n,repo:o,prNumber:s.number},e[0]=i,e[1]=a.id,e[2]=n,e[3]=s.number,e[4]=o,e[5]=l):l=e[5];const c=Uw(l);let d;e[6]!==s.body||e[7]!==s.number?(d=s.body&&r.jsx("div",{className:"text-sm",children:r.jsx(ll,{id:`pr-body-${s.number}`,text:Dr(s.body)})}),e[6]=s.body,e[7]=s.number,e[8]=d):d=e[8];let u;e[9]!==c.data?(u=c.data??[],e[9]=c.data,e[10]=u):u=e[10];let h;e[11]!==c.isError||e[12]!==c.isLoading||e[13]!==u?(h=r.jsx(cV,{comments:u,isLoading:c.isLoading,isError:c.isError}),e[11]=c.isError,e[12]=c.isLoading,e[13]=u,e[14]=h):h=e[14];let f;return e[15]!==d||e[16]!==h?(f=r.jsxs("div",{className:"space-y-8",children:[d,h]}),e[15]=d,e[16]=h,e[17]=f):f=e[17],f}function fV(t){const e=B.c(26),{pr:s,connectionId:i,owner:n,repo:o}=t,{org:a}=be();let l;e[0]!==i||e[1]!==a.id||e[2]!==n||e[3]!==s.number||e[4]!==o?(l={orgId:a.id,connectionId:i,owner:n,repo:o,prNumber:s.number},e[0]=i,e[1]=a.id,e[2]=n,e[3]=s.number,e[4]=o,e[5]=l):l=e[5];const d=Wf(l).data?.length,[u,h]=S.useState("description"),f=S.useRef({description:null,changes:null,checks:null}),[m,p]=S.useState(null),g=w=>k=>{if(f.current[w]=k,k&&w===u){const T=k.offsetLeft,I=k.offsetWidth;(m===null||T!==m.left||I!==m.width)&&p({left:T,width:I})}},_=w=>{const k=w;h(k);const T=f.current[k];T&&p({left:T.offsetLeft,width:T.offsetWidth})},v=Vo,x=g("checks");let b;e[6]!==v||e[7]!==x?(b=r.jsx(v,{ref:x,variant:"underline",value:"checks",className:"pb-3 data-[state=active]:border-transparent",children:"Checks"}),e[6]=v,e[7]=x,e[8]=b):b=e[8];let y;e[9]!==m?(y=m&&r.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute bottom-[-1px] h-0.5 bg-primary transition-[left,width] duration-200 ease-out",style:{left:m.left,width:m.width}}),e[9]=m,e[10]=y):y=e[10];let C;e[11]!==i||e[12]!==n||e[13]!==s||e[14]!==o?(C=r.jsx(yn,{value:"description",className:"mt-6",children:r.jsx(uV,{pr:s,connectionId:i,owner:n,repo:o})}),e[11]=i,e[12]=n,e[13]=s,e[14]=o,e[15]=C):C=e[15];let j;e[16]!==i||e[17]!==n||e[18]!==s||e[19]!==o?(j=r.jsx(yn,{value:"changes",className:"mt-6",children:r.jsx(Gw,{pr:s,connectionId:i,owner:n,repo:o})}),e[16]=i,e[17]=n,e[18]=s,e[19]=o,e[20]=j):j=e[20];let V;return e[21]!==i||e[22]!==n||e[23]!==s||e[24]!==o?(V=r.jsx(yn,{value:"checks",className:"mt-6",children:r.jsx(oV,{pr:s,connectionId:i,owner:n,repo:o})}),e[21]=i,e[22]=n,e[23]=s,e[24]=o,e[25]=V):V=e[25],r.jsxs(Mh,{value:u,onValueChange:_,variant:"underline",children:[r.jsxs(dg,{variant:"underline",className:"relative h-auto p-0",children:[r.jsx(Vo,{ref:g("description"),variant:"underline",value:"description",className:"pb-3 data-[state=active]:border-transparent",children:"Description"}),r.jsxs(Vo,{ref:g("changes"),variant:"underline",value:"changes",className:"pb-3 data-[state=active]:border-transparent",children:["Changes",d!==void 0?` ${d}`:""]}),b,y]}),C,j,V]})}function mV(t){const e=B.c(5),{pr:s}=t,i=`Open PR #${s.number} on GitHub`;let n;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=r.jsx(Vi,{className:"h-4 w-4 text-muted-foreground"}),e[0]=n):n=e[0];let o;return e[1]!==s.htmlUrl||e[2]!==s.number||e[3]!==i?(o=r.jsx("div",{className:"flex h-12 items-center border-b border-border px-4 shrink-0",children:r.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,n]})}),e[1]=s.htmlUrl,e[2]=s.number,e[3]=i,e[4]=o):o=e[4],o}function pV(t){const e=B.c(23),{pr:s}=t;let i;e[0]!==s.title?(i=Dr(s.title),e[0]=s.title,e[1]=i):i=e[1];let n;e[2]!==i?(n=r.jsx("h1",{className:"text-2xl font-semibold",children:i}),e[2]=i,e[3]=n):n=e[3];const o=`Open PR #${s.number} on GitHub`;let a;e[4]===Symbol.for("react.memo_cache_sentinel")?(a=r.jsx(Vi,{className:"h-3.5 w-3.5"}),e[4]=a):a=e[4];let l;e[5]!==s.htmlUrl||e[6]!==s.number||e[7]!==o?(l=r.jsxs("a",{href:s.htmlUrl,target:"_blank",rel:"noreferrer","aria-label":o,className:"inline-flex items-center gap-1 hover:text-foreground",children:["PR #",s.number,a]}),e[5]=s.htmlUrl,e[6]=s.number,e[7]=o,e[8]=l):l=e[8];let c;e[9]!==s.author?(c=s.author&&r.jsxs(r.Fragment,{children:["@",s.author," · "]}),e[9]=s.author,e[10]=c):c=e[10];let d;e[11]!==s.base?(d=r.jsx("span",{className:"font-mono text-xs",children:s.base}),e[11]=s.base,e[12]=d):d=e[12];let u;e[13]!==s.head?(u=r.jsx("span",{className:"font-mono text-xs",children:s.head}),e[13]=s.head,e[14]=u):u=e[14];let h;e[15]!==l||e[16]!==c||e[17]!==d||e[18]!==u?(h=r.jsxs("div",{className:"text-sm text-muted-foreground",children:[l," · ",c,d," ← ",u]}),e[15]=l,e[16]=c,e[17]=d,e[18]=u,e[19]=h):h=e[19];let f;return e[20]!==n||e[21]!==h?(f=r.jsxs("div",{className:"space-y-2",children:[n,h]}),e[20]=n,e[21]=h,e[22]=f):f=e[22],f}function gV(t){const e=B.c(8),{virtualMcpId:s}=t,{org:i}=be(),n=ts(s),{currentBranch:o}=es(),a=n?.metadata?.githubRepo??null;if(!a?.connectionId){let c;return e[0]===Symbol.for("react.memo_cache_sentinel")?(c=r.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]=c):c=e[0],c}if(!o){let c;return e[1]===Symbol.for("react.memo_cache_sentinel")?(c=r.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-8 text-sm",children:[r.jsx(gr,{className:"h-6 w-6 text-muted-foreground"}),r.jsx("div",{className:"text-muted-foreground",children:"No branch selected."}),r.jsx("div",{className:"text-xs text-muted-foreground",children:"Pick a branch from the dropdown in the header to see PR status."})]}),e[1]=c):c=e[1],c}let l;return e[2]!==o||e[3]!==a.connectionId||e[4]!==a.name||e[5]!==a.owner||e[6]!==i.id?(l=r.jsx(_V,{orgId:i.id,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]=l):l=e[7],l}function _V(t){const e=B.c(49),{orgId:s,connectionId:i,owner:n,repo:o,branch:a}=t;let l;e[0]!==a||e[1]!==i||e[2]!==s||e[3]!==n||e[4]!==o?(l={orgId:s,connectionId:i,owner:n,repo:o,branch:a},e[0]=a,e[1]=i,e[2]=s,e[3]=n,e[4]=o,e[5]=l):l=e[5];const{data:c,isLoading:d,isError:u}=Hf(l),h=xV;if(d){let v;return e[6]===Symbol.for("react.memo_cache_sentinel")?(v=r.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"Loading PR state…"}),e[6]=v):v=e[6],v}if(u){let v;return e[7]===Symbol.for("react.memo_cache_sentinel")?(v=r.jsx("div",{className:"p-4 text-sm text-destructive",children:"Couldn't load PR state. The GitHub connection may be broken."}),e[7]=v):v=e[7],v}const f=`https://github.com/${n}/${o}/tree/${a}`;if(c&&c.state==="closed"){let v;e[8]!==c?(v=r.jsx(mV,{pr:c}),e[8]=c,e[9]=v):v=e[9];const x=c.merged?"✓ Merged":"✗ Closed";let b;e[10]!==c.mergedAt?(b=c.mergedAt&&r.jsxs(r.Fragment,{children:[" · ",new Date(c.mergedAt).toLocaleDateString()]}),e[10]=c.mergedAt,e[11]=b):b=e[11];let y;e[12]!==c.author?(y=c.author&&r.jsxs(r.Fragment,{children:[" · by @",c.author]}),e[12]=c.author,e[13]=y):y=e[13];let C;e[14]!==c.base||e[15]!==x||e[16]!==b||e[17]!==y?(C=r.jsxs("div",{className:"text-sm text-success",children:[x," into ",c.base,b,y]}),e[14]=c.base,e[15]=x,e[16]=b,e[17]=y,e[18]=C):C=e[18];let j;e[19]!==c.title?(j=Dr(c.title),e[19]=c.title,e[20]=j):j=e[20];let V;e[21]!==j?(V=r.jsx("h1",{className:"text-lg font-semibold",children:j}),e[21]=j,e[22]=V):V=e[22];let w;e[23]!==c.body||e[24]!==c.number?(w=c.body&&r.jsx("div",{className:"rounded-md border border-border bg-muted/30 p-3 text-sm",children:r.jsx(ll,{id:`pr-body-${c.number}`,text:Dr(c.body)})}),e[23]=c.body,e[24]=c.number,e[25]=w):w=e[25];let k;e[26]!==C||e[27]!==V||e[28]!==w?(k=r.jsxs("div",{className:"flex flex-col gap-4 p-4 overflow-auto",children:[C,V,w]}),e[26]=C,e[27]=V,e[28]=w,e[29]=k):k=e[29];let T;return e[30]!==v||e[31]!==k?(T=r.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[v,k]}),e[30]=v,e[31]=k,e[32]=T):T=e[32],T}if(c&&c.state==="open"){let v;e[33]!==c?(v=r.jsx(pV,{pr:c}),e[33]=c,e[34]=v):v=e[34];let x;e[35]!==i||e[36]!==n||e[37]!==c||e[38]!==o?(x=r.jsx("div",{className:"mt-8",children:r.jsx(fV,{pr:c,connectionId:i,owner:n,repo:o})}),e[35]=i,e[36]=n,e[37]=c,e[38]=o,e[39]=x):x=e[39];let b;return e[40]!==v||e[41]!==x?(b=r.jsx("div",{className:"flex min-h-0 flex-1 flex-col",children:r.jsx("div",{className:"flex-1 overflow-auto",children:r.jsxs("div",{className:"mx-auto w-full max-w-[1200px] px-4 pt-8 pb-6 md:px-10 md:pt-12 md:pb-10",children:[v,x]})})}),e[40]=v,e[41]=x,e[42]=b):b=e[42],b}let m;e[43]===Symbol.for("react.memo_cache_sentinel")?(m=r.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[43]=m):m=e[43];let p;e[44]!==f?(p=()=>h(f),e[44]=f,e[45]=p):p=e[45];let g;e[46]===Symbol.for("react.memo_cache_sentinel")?(g=r.jsx(Vi,{className:"mr-1.5 h-4 w-4"}),e[46]=g):g=e[46];let _;return e[47]!==p?(_=r.jsxs("div",{className:"flex flex-col gap-4 p-4",children:[m,r.jsx("div",{className:"flex items-center gap-2",children:r.jsxs(ne,{size:"sm",variant:"outline",onClick:p,children:[g,"Open branch on GitHub"]})})]}),e[47]=p,e[48]=_):_=e[48],_}function xV(t){window.open(t,"_blank","noopener,noreferrer")}const Oo="env";function vV(){const t=B.c(13),e=Ke();let s;t[0]===Symbol.for("react.memo_cache_sentinel")?(s={strict:!1},t[0]=s):s=t[0];const n=vi(s).main===Oo;let o;t[1]!==e?(o=f=>{e({search:(m=>({...m,main:f})),replace:!0})},t[1]=e,t[2]=o):o=t[2];const a=o;let l;t[3]!==n||t[4]!==a?(l=()=>{a(n?"0":Oo)},t[3]=n,t[4]=a,t[5]=l):l=t[5];const c=l;let d;t[6]!==n||t[7]!==a?(d=()=>{n||a(Oo)},t[6]=n,t[7]=a,t[8]=d):d=t[8];const u=d;let h;return t[9]!==n||t[10]!==u||t[11]!==c?(h={envOpen:n,toggleEnv:c,openEnv:u},t[9]=n,t[10]=u,t[11]=c,t[12]=h):h=t[12],h}const bV=Vs({tag:Et(),id:Et(),classes:Et(),text:Et(),html:Et(),manifestKey:Et().nullable(),componentName:Et().nullable(),parents:Et(),url:Et(),path:Et(),viewport:Vs({width:nn(),height:nn()}),position:Vs({x:nn(),y:nn()})}),yV=`(function() {
296
296
  if (window.__visualEditorActive) return;
297
297
  window.__visualEditorActive = true;
298
298
 
@@ -414,9 +414,9 @@ ${ee}`:ee;l.setValue("metadata.instructions",K,{shouldDirty:!0})},$=new Set(c.ma
414
414
  window.__visualEditorActive = false;
415
415
  }
416
416
  });
417
- })();`;function ji(t){return t.replace(/[`*_]/g,"\\$&")}function vV(t,e){const s=[`The user selected an element on the live preview and asked: **"${ji(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:** \`${ji(t.manifestKey)}\``,"");const i=`<${t.tag}${t.classes?` class="${ji(t.classes)}"`:""}>`;s.push(`**Clicked element:** \`${i}\``),t.parents&&s.push(`**DOM breadcrumb:** ${ji(t.parents)} > ${t.tag}`),t.text&&s.push(`**Text content:** "${ji(t.text)}"`),t.componentName&&s.push(`**Component name:** ${ji(t.componentName)}`);const n=t.html.replace(/```/g,"`` `");return s.push("","**HTML snippet:**","```html",n,"```"),s.push("","Please read the source file, locate the element, and apply the requested change."),s.join(`
418
- `)}function bV(t,e,s=320,i=44,n=12){const{x:o,y:a}=t,{width:l,height:c}=e,d=Math.max(n,Math.min(o-s/2,l-s-n)),h=a/c>.68?Math.max(n,a-i-18):Math.min(a+18,c-i-n);return{leftPct:d/l*100,topPct:h/c*100}}function yV(t){const e=B.c(32),{element:s,onDismiss:i}=t,[n,o]=S.useState(""),a=S.useRef(null),{sendMessage:l}=Zn(),{setChatOpen:c}=zr();let d;e[0]!==s||e[1]!==n||e[2]!==i||e[3]!==l||e[4]!==c?(d=()=>{if(!n.trim())return;const T=vV(s,n);c(!0),l({parts:[{type:"text",text:T}]}),i()},e[0]=s,e[1]=n,e[2]=i,e[3]=l,e[4]=c,e[5]=d):d=e[5];const u=d;let h;e[6]!==s.position||e[7]!==s.viewport?(h=bV(s.position,s.viewport),e[6]=s.position,e[7]=s.viewport,e[8]=h):h=e[8];const f=h,m=`${f.leftPct}%`,p=`${f.topPct}%`;let g;e[9]!==m||e[10]!==p?(g={left:m,top:p,width:"320px"},e[9]=m,e[10]=p,e[11]=g):g=e[11];let _;e[12]!==u?(_=T=>{T.preventDefault(),u()},e[12]=u,e[13]=_):_=e[13];let v;e[14]===Symbol.for("react.memo_cache_sentinel")?(v=T=>o(T.target.value),e[14]=v):v=e[14];let x;e[15]!==i?(x=T=>{T.key==="Escape"&&i()},e[15]=i,e[16]=x):x=e[16];let b;e[17]!==n||e[18]!==x?(b=r.jsx("input",{ref:a,autoFocus:!0,type:"text",value:n,onChange:v,onKeyDown:x,placeholder:"Ask the AI...",className:"min-w-0 flex-1 bg-transparent text-sm outline-none placeholder:text-muted-foreground"}),e[17]=n,e[18]=x,e[19]=b):b=e[19];let y;e[20]!==n?(y=n.trim(),e[20]=n,e[21]=y):y=e[21];const C=!y;let j;e[22]===Symbol.for("react.memo_cache_sentinel")?(j=r.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none","aria-hidden":"true",children:[r.jsx("title",{children:"Send"}),r.jsx("path",{d:"M5 9V1M1 5l4-4 4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}),e[22]=j):j=e[22];let V;e[23]!==C?(V=r.jsx("button",{type:"submit",disabled:C,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:j}),e[23]=C,e[24]=V):V=e[24];let w;e[25]!==V||e[26]!==_||e[27]!==b?(w=r.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:_,children:[b,V]}),e[25]=V,e[26]=_,e[27]=b,e[28]=w):w=e[28];let k;return e[29]!==w||e[30]!==g?(k=r.jsx("div",{className:"absolute z-30 pointer-events-none",style:g,children:w}),e[29]=w,e[30]=g,e[31]=k):k=e[31],k}const SV={status:{ready:!1,htmlSupport:!1},suspended:!1,notFound:!1,scripts:[],activeProcesses:[],branchStatus:null,getBuffer:()=>"",hasData:()=>!1,subscribeChunks:()=>()=>{},subscribeReload:()=>()=>{}},Uf=S.createContext(SV),xd=16384;class wV{data="";append(e){this.data+=e,this.data.length>xd&&(this.data=this.data.slice(this.data.length-xd))}get(){return this.data}clear(){this.data=""}}const VV=6e4,CV=1e3,jV=3e4,kV=["log","status","scripts","processes","reload","branch-status"];function NV({daemonBaseUrl:t,children:e}){const[s,i]=S.useState({ready:!1,htmlSupport:!1}),[n,o]=S.useState(!1),[a,l]=S.useState(!1),[c,d]=S.useState([]),[u,h]=S.useState([]),[f,m]=S.useState(null),[,p]=S.useState(0),g=S.useRef(new Map),_=S.useRef(new Set),v=S.useRef(new Set),x=y=>{let C=g.current.get(y);return C||(C=new wV,g.current.set(y,C)),C};S.useEffect(()=>{if(i({ready:!1,htmlSupport:!1}),o(!1),l(!1),d([]),h([]),m(null),g.current.clear(),!t)return;const y=`${t}/_decopilot_vm/events`;let C=!1,j=!1,V=0,w=null,k=null,T=null;const I=new AbortController;async function A(){try{const D=await fetch(y,{method:"GET",headers:{Accept:"text/event-stream"},cache:"no-store",signal:I.signal});if(D.body)try{await D.body.cancel()}catch{}return D.status===404}catch{return!1}}const N=()=>{k||(k=setTimeout(()=>{o(!0)},VV))},E=()=>{k&&(clearTimeout(k),k=null)},R=D=>{try{const P=JSON.parse(D.data);if(D.type==="log"&&typeof P.data=="string"){const O=P.source,z=P.data.replace(/\r?\n/g,`\r
419
- `);x(O).append(z);for(const $ of _.current)try{$(O,z)}catch{}p($=>$+1)}else if(D.type==="status")i({ready:!!P.ready,htmlSupport:!!P.htmlSupport});else if(D.type==="scripts")d(P.scripts??[]);else if(D.type==="processes")h(P.active??[]);else if(D.type==="reload")for(const O of v.current)try{O()}catch{}else D.type==="branch-status"&&m({branch:String(P.branch??""),base:String(P.base??"main"),workingTreeDirty:!!P.workingTreeDirty,unpushed:Number(P.unpushed??0),aheadOfBase:Number(P.aheadOfBase??0),behindBase:Number(P.behindBase??0),headSha:String(P.headSha??"")})}catch{}};function M(){if(!C){T=new EventSource(y),T.onopen=()=>{V=0,E(),o(!1)},T.onerror=()=>{if(T?.readyState===EventSource.CLOSED){if(N(),j){L();return}j=!0,A().then(D=>{if(!C){if(D){l(!0);return}L()}})}};for(const D of kV)T.addEventListener(D,R)}}function L(){if(C||w)return;const D=Math.min(CV*2**V,jV);V++,w=setTimeout(()=>{w=null,!C&&(T?.close(),M())},D)}return M(),()=>{C=!0,I.abort(),T?.close(),w&&clearTimeout(w),E()}},[t]);const b={status:s,suspended:n,notFound:a,scripts:c,activeProcesses:u,branchStatus:f,getBuffer:y=>g.current.get(y)?.get()??"",hasData:y=>(g.current.get(y)?.get().length??0)>0,subscribeChunks:y=>(_.current.add(y),()=>{_.current.delete(y)}),subscribeReload:y=>(v.current.add(y),()=>{v.current.delete(y)})};return r.jsx(Uf,{value:b,children:e})}function Yi(){return S.use(Uf)}function AV(t){const{subscribeChunks:e}=Yi(),s=S.useRef(t);s.current=t,S.useEffect(()=>e((o,a)=>{s.current?.(o,a)}),[e])}function EV(t){const{subscribeReload:e}=Yi(),s=S.useRef(t);s.current=t,S.useEffect(()=>e(()=>{s.current?.()}),[e])}function Kf(t){const e=B.c(5),{onResume:s,label:i}=t,n=i===void 0?"Resume Server":i;let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=r.jsx("p",{className:"text-sm text-muted-foreground",children:"VM suspended due to inactivity."}),e[0]=o):o=e[0];let a;e[1]===Symbol.for("react.memo_cache_sentinel")?(a=r.jsx(Uh,{size:14}),e[1]=a):a=e[1];let l;return e[2]!==n||e[3]!==s?(l=r.jsxs("div",{className:"flex flex-col items-center justify-center w-full h-full gap-4",children:[o,r.jsxs(ne,{onClick:s,children:[a,n]})]}),e[2]=n,e[3]=s,e[4]=l):l=e[4],l}const $o=[{key:"sandbox",label:"Setting up your workspace"},{key:"setup",label:"Installing packages"},{key:"server",label:"Starting your preview"}],Ss="bg-foreground/[0.05]",cs="bg-foreground/[0.09]",IV=Array.from({length:35},()=>Math.random()*1.8),RV=Array.from({length:35},()=>Math.random()<.4);function TV(t,e,s){return s.length>0?2:t||e.length>0?1:0}function DV(t){return t.replace(/\u001b\[[0-9;?]*[a-zA-Z]/g,"")}function MV(t,e){const s=[...e,"setup"];for(const i of s){const n=t(i);if(!n)continue;const o=DV(n).split(/\r\n|\r|\n/);for(let a=o.length-1;a>=0;a--){const l=o[a]?.trim();if(l)return l}}return null}function PV(t){const e=B.c(37),{hasSetupData:s,scripts:i,activeProcesses:n,onViewLogs:o}=t;let a;e[0]!==n||e[1]!==s||e[2]!==i?(a=TV(s,i,n),e[0]=n,e[1]=s,e[2]=i,e[3]=a):a=e[3];const l=a,c=$o[l]?.label??$o[0].label,{getBuffer:d}=Yi();let u;e[4]!==n||e[5]!==d?(u=MV(d,n),e[4]=n,e[5]=d,e[6]=u):u=e[6];const h=u;let f;e[7]===Symbol.for("react.memo_cache_sentinel")?(f=r.jsx(Kp,{}),e[7]=f):f=e[7];const m=$o[l]?.key??"sandbox";let p;e[8]!==c||e[9]!==m?(p=r.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:[f,r.jsxs("span",{className:"text-[13px] font-medium text-foreground/85 animate-in fade-in duration-500",children:[c,"…"]},m)]}),e[8]=c,e[9]=m,e[10]=p):p=e[10];let g;e[11]===Symbol.for("react.memo_cache_sentinel")?(g=r.jsx(LV,{}),e[11]=g):g=e[11];let _;e[12]!==l?(_=r.jsx(zo,{phase:0,current:l,children:g}),e[12]=l,e[13]=_):_=e[13];let v;e[14]===Symbol.for("react.memo_cache_sentinel")?(v=r.jsx(BV,{}),e[14]=v):v=e[14];let x;e[15]!==l?(x=r.jsx(zo,{phase:1,current:l,children:v}),e[15]=l,e[16]=x):x=e[16];let b;e[17]===Symbol.for("react.memo_cache_sentinel")?(b=r.jsx($V,{}),e[17]=b):b=e[17];let y;e[18]!==l?(y=r.jsx(zo,{phase:2,current:l,children:b}),e[18]=l,e[19]=y):y=e[19];let C;e[20]!==y||e[21]!==_||e[22]!==x?(C=r.jsxs("div",{className:"relative w-[min(78%,560px)] aspect-[4/3]",children:[_,x,y]}),e[20]=y,e[21]=_,e[22]=x,e[23]=C):C=e[23];let j;e[24]!==h?(j=h&&r.jsx("span",{className:"block w-full max-w-[440px] truncate text-center text-xs font-mono text-muted-foreground/45 animate-in fade-in duration-300",children:h},h),e[24]=h,e[25]=j):j=e[25];let V;e[26]===Symbol.for("react.memo_cache_sentinel")?(V=r.jsx(fl,{size:11}),e[26]=V):V=e[26];let w;e[27]!==o?(w=r.jsxs("button",{type:"button",onClick:o,className:"flex items-center gap-1.5 text-xs text-muted-foreground/50 hover:text-muted-foreground transition-colors duration-200",children:[V,"View logs"]}),e[27]=o,e[28]=w):w=e[28];let k;e[29]!==j||e[30]!==w?(k=r.jsxs("div",{className:"absolute bottom-5 left-1/2 -translate-x-1/2 flex flex-col items-center gap-1 max-w-[80%] min-w-0",children:[j,w]}),e[29]=j,e[30]=w,e[31]=k):k=e[31];let T;e[32]===Symbol.for("react.memo_cache_sentinel")?(T=r.jsx("style",{children:`
417
+ })();`;function ji(t){return t.replace(/[`*_]/g,"\\$&")}function SV(t,e){const s=[`The user selected an element on the live preview and asked: **"${ji(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:** \`${ji(t.manifestKey)}\``,"");const i=`<${t.tag}${t.classes?` class="${ji(t.classes)}"`:""}>`;s.push(`**Clicked element:** \`${i}\``),t.parents&&s.push(`**DOM breadcrumb:** ${ji(t.parents)} > ${t.tag}`),t.text&&s.push(`**Text content:** "${ji(t.text)}"`),t.componentName&&s.push(`**Component name:** ${ji(t.componentName)}`);const n=t.html.replace(/```/g,"`` `");return s.push("","**HTML snippet:**","```html",n,"```"),s.push("","Please read the source file, locate the element, and apply the requested change."),s.join(`
418
+ `)}function wV(t,e,s=320,i=44,n=12){const{x:o,y:a}=t,{width:l,height:c}=e,d=Math.max(n,Math.min(o-s/2,l-s-n)),h=a/c>.68?Math.max(n,a-i-18):Math.min(a+18,c-i-n);return{leftPct:d/l*100,topPct:h/c*100}}function VV(t){const e=B.c(32),{element:s,onDismiss:i}=t,[n,o]=S.useState(""),a=S.useRef(null),{sendMessage:l}=Zn(),{setChatOpen:c}=zr();let d;e[0]!==s||e[1]!==n||e[2]!==i||e[3]!==l||e[4]!==c?(d=()=>{if(!n.trim())return;const T=SV(s,n);c(!0),l({parts:[{type:"text",text:T}]}),i()},e[0]=s,e[1]=n,e[2]=i,e[3]=l,e[4]=c,e[5]=d):d=e[5];const u=d;let h;e[6]!==s.position||e[7]!==s.viewport?(h=wV(s.position,s.viewport),e[6]=s.position,e[7]=s.viewport,e[8]=h):h=e[8];const f=h,m=`${f.leftPct}%`,p=`${f.topPct}%`;let g;e[9]!==m||e[10]!==p?(g={left:m,top:p,width:"320px"},e[9]=m,e[10]=p,e[11]=g):g=e[11];let _;e[12]!==u?(_=T=>{T.preventDefault(),u()},e[12]=u,e[13]=_):_=e[13];let v;e[14]===Symbol.for("react.memo_cache_sentinel")?(v=T=>o(T.target.value),e[14]=v):v=e[14];let x;e[15]!==i?(x=T=>{T.key==="Escape"&&i()},e[15]=i,e[16]=x):x=e[16];let b;e[17]!==n||e[18]!==x?(b=r.jsx("input",{ref:a,autoFocus:!0,type:"text",value:n,onChange:v,onKeyDown:x,placeholder:"Ask the AI...",className:"min-w-0 flex-1 bg-transparent text-sm outline-none placeholder:text-muted-foreground"}),e[17]=n,e[18]=x,e[19]=b):b=e[19];let y;e[20]!==n?(y=n.trim(),e[20]=n,e[21]=y):y=e[21];const C=!y;let j;e[22]===Symbol.for("react.memo_cache_sentinel")?(j=r.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 10 10",fill:"none","aria-hidden":"true",children:[r.jsx("title",{children:"Send"}),r.jsx("path",{d:"M5 9V1M1 5l4-4 4 4",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]}),e[22]=j):j=e[22];let V;e[23]!==C?(V=r.jsx("button",{type:"submit",disabled:C,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:j}),e[23]=C,e[24]=V):V=e[24];let w;e[25]!==V||e[26]!==_||e[27]!==b?(w=r.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:_,children:[b,V]}),e[25]=V,e[26]=_,e[27]=b,e[28]=w):w=e[28];let k;return e[29]!==w||e[30]!==g?(k=r.jsx("div",{className:"absolute z-30 pointer-events-none",style:g,children:w}),e[29]=w,e[30]=g,e[31]=k):k=e[31],k}const CV={status:{ready:!1,htmlSupport:!1},suspended:!1,notFound:!1,scripts:[],activeProcesses:[],branchStatus:null,getBuffer:()=>"",hasData:()=>!1,subscribeChunks:()=>()=>{},subscribeReload:()=>()=>{}},Kf=S.createContext(CV),xd=16384;class jV{data="";append(e){this.data+=e,this.data.length>xd&&(this.data=this.data.slice(this.data.length-xd))}get(){return this.data}clear(){this.data=""}}const kV=6e4,NV=1e3,AV=3e4,EV=["log","status","scripts","processes","reload","branch-status"];function IV({daemonBaseUrl:t,children:e}){const[s,i]=S.useState({ready:!1,htmlSupport:!1}),[n,o]=S.useState(!1),[a,l]=S.useState(!1),[c,d]=S.useState([]),[u,h]=S.useState([]),[f,m]=S.useState(null),[,p]=S.useState(0),g=S.useRef(new Map),_=S.useRef(new Set),v=S.useRef(new Set),x=y=>{let C=g.current.get(y);return C||(C=new jV,g.current.set(y,C)),C};S.useEffect(()=>{if(i({ready:!1,htmlSupport:!1}),o(!1),l(!1),d([]),h([]),m(null),g.current.clear(),!t)return;const y=`${t}/_decopilot_vm/events`;let C=!1,j=!1,V=0,w=null,k=null,T=null;const I=new AbortController;async function A(){try{const D=await fetch(y,{method:"GET",headers:{Accept:"text/event-stream"},cache:"no-store",signal:I.signal});if(D.body)try{await D.body.cancel()}catch{}return D.status===404}catch{return!1}}const N=()=>{k||(k=setTimeout(()=>{o(!0)},kV))},E=()=>{k&&(clearTimeout(k),k=null)},R=D=>{try{const P=JSON.parse(D.data);if(D.type==="log"&&typeof P.data=="string"){const O=P.source,z=P.data.replace(/\r?\n/g,`\r
419
+ `);x(O).append(z);for(const $ of _.current)try{$(O,z)}catch{}p($=>$+1)}else if(D.type==="status")i({ready:!!P.ready,htmlSupport:!!P.htmlSupport});else if(D.type==="scripts")d(P.scripts??[]);else if(D.type==="processes")h(P.active??[]);else if(D.type==="reload")for(const O of v.current)try{O()}catch{}else D.type==="branch-status"&&m({branch:String(P.branch??""),base:String(P.base??"main"),workingTreeDirty:!!P.workingTreeDirty,unpushed:Number(P.unpushed??0),aheadOfBase:Number(P.aheadOfBase??0),behindBase:Number(P.behindBase??0),headSha:String(P.headSha??"")})}catch{}};function M(){if(!C){T=new EventSource(y),T.onopen=()=>{V=0,E(),o(!1)},T.onerror=()=>{if(T?.readyState===EventSource.CLOSED){if(N(),j){L();return}j=!0,A().then(D=>{if(!C){if(D){l(!0);return}L()}})}};for(const D of EV)T.addEventListener(D,R)}}function L(){if(C||w)return;const D=Math.min(NV*2**V,AV);V++,w=setTimeout(()=>{w=null,!C&&(T?.close(),M())},D)}return M(),()=>{C=!0,I.abort(),T?.close(),w&&clearTimeout(w),E()}},[t]);const b={status:s,suspended:n,notFound:a,scripts:c,activeProcesses:u,branchStatus:f,getBuffer:y=>g.current.get(y)?.get()??"",hasData:y=>(g.current.get(y)?.get().length??0)>0,subscribeChunks:y=>(_.current.add(y),()=>{_.current.delete(y)}),subscribeReload:y=>(v.current.add(y),()=>{v.current.delete(y)})};return r.jsx(Kf,{value:b,children:e})}function Yi(){return S.use(Kf)}function RV(t){const{subscribeChunks:e}=Yi(),s=S.useRef(t);s.current=t,S.useEffect(()=>e((o,a)=>{s.current?.(o,a)}),[e])}function TV(t){const{subscribeReload:e}=Yi(),s=S.useRef(t);s.current=t,S.useEffect(()=>e(()=>{s.current?.()}),[e])}function qf(t){const e=B.c(5),{onResume:s,label:i}=t,n=i===void 0?"Resume Server":i;let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=r.jsx("p",{className:"text-sm text-muted-foreground",children:"VM suspended due to inactivity."}),e[0]=o):o=e[0];let a;e[1]===Symbol.for("react.memo_cache_sentinel")?(a=r.jsx(Uh,{size:14}),e[1]=a):a=e[1];let l;return e[2]!==n||e[3]!==s?(l=r.jsxs("div",{className:"flex flex-col items-center justify-center w-full h-full gap-4",children:[o,r.jsxs(ne,{onClick:s,children:[a,n]})]}),e[2]=n,e[3]=s,e[4]=l):l=e[4],l}const $o=[{key:"sandbox",label:"Setting up your workspace"},{key:"setup",label:"Installing packages"},{key:"server",label:"Starting your preview"}],Ss="bg-foreground/[0.05]",cs="bg-foreground/[0.09]",DV=Array.from({length:35},()=>Math.random()*1.8),MV=Array.from({length:35},()=>Math.random()<.4);function PV(t,e,s){return s.length>0?2:t||e.length>0?1:0}function LV(t){return t.replace(/\u001b\[[0-9;?]*[a-zA-Z]/g,"")}function BV(t,e){const s=[...e,"setup"];for(const i of s){const n=t(i);if(!n)continue;const o=LV(n).split(/\r\n|\r|\n/);for(let a=o.length-1;a>=0;a--){const l=o[a]?.trim();if(l)return l}}return null}function OV(t){const e=B.c(37),{hasSetupData:s,scripts:i,activeProcesses:n,onViewLogs:o}=t;let a;e[0]!==n||e[1]!==s||e[2]!==i?(a=PV(s,i,n),e[0]=n,e[1]=s,e[2]=i,e[3]=a):a=e[3];const l=a,c=$o[l]?.label??$o[0].label,{getBuffer:d}=Yi();let u;e[4]!==n||e[5]!==d?(u=BV(d,n),e[4]=n,e[5]=d,e[6]=u):u=e[6];const h=u;let f;e[7]===Symbol.for("react.memo_cache_sentinel")?(f=r.jsx(qp,{}),e[7]=f):f=e[7];const m=$o[l]?.key??"sandbox";let p;e[8]!==c||e[9]!==m?(p=r.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:[f,r.jsxs("span",{className:"text-[13px] font-medium text-foreground/85 animate-in fade-in duration-500",children:[c,"…"]},m)]}),e[8]=c,e[9]=m,e[10]=p):p=e[10];let g;e[11]===Symbol.for("react.memo_cache_sentinel")?(g=r.jsx($V,{}),e[11]=g):g=e[11];let _;e[12]!==l?(_=r.jsx(zo,{phase:0,current:l,children:g}),e[12]=l,e[13]=_):_=e[13];let v;e[14]===Symbol.for("react.memo_cache_sentinel")?(v=r.jsx(zV,{}),e[14]=v):v=e[14];let x;e[15]!==l?(x=r.jsx(zo,{phase:1,current:l,children:v}),e[15]=l,e[16]=x):x=e[16];let b;e[17]===Symbol.for("react.memo_cache_sentinel")?(b=r.jsx(HV,{}),e[17]=b):b=e[17];let y;e[18]!==l?(y=r.jsx(zo,{phase:2,current:l,children:b}),e[18]=l,e[19]=y):y=e[19];let C;e[20]!==y||e[21]!==_||e[22]!==x?(C=r.jsxs("div",{className:"relative w-[min(78%,560px)] aspect-[4/3]",children:[_,x,y]}),e[20]=y,e[21]=_,e[22]=x,e[23]=C):C=e[23];let j;e[24]!==h?(j=h&&r.jsx("span",{className:"block w-full max-w-[440px] truncate text-center text-xs font-mono text-muted-foreground/45 animate-in fade-in duration-300",children:h},h),e[24]=h,e[25]=j):j=e[25];let V;e[26]===Symbol.for("react.memo_cache_sentinel")?(V=r.jsx(fl,{size:11}),e[26]=V):V=e[26];let w;e[27]!==o?(w=r.jsxs("button",{type:"button",onClick:o,className:"flex items-center gap-1.5 text-xs text-muted-foreground/50 hover:text-muted-foreground transition-colors duration-200",children:[V,"View logs"]}),e[27]=o,e[28]=w):w=e[28];let k;e[29]!==j||e[30]!==w?(k=r.jsxs("div",{className:"absolute bottom-5 left-1/2 -translate-x-1/2 flex flex-col items-center gap-1 max-w-[80%] min-w-0",children:[j,w]}),e[29]=j,e[30]=w,e[31]=k):k=e[31];let T;e[32]===Symbol.for("react.memo_cache_sentinel")?(T=r.jsx("style",{children:`
420
420
  @keyframes vm-pulse-soft {
421
421
  0%, 100% { opacity: 0.25; }
422
422
  50% { opacity: 1; }
@@ -425,26 +425,26 @@ ${ee}`:ee;l.setValue("metadata.instructions",K,{shouldDirty:!0})},$=new Set(c.ma
425
425
  0%, 100% { opacity: 0.5; }
426
426
  50% { opacity: 1; }
427
427
  }
428
- `}),e[32]=T):T=e[32];let I;return e[33]!==C||e[34]!==k||e[35]!==p?(I=r.jsxs("div",{className:"relative flex flex-col items-center justify-center w-full h-full overflow-hidden select-none gap-8",children:[p,C,k,T]}),e[33]=C,e[34]=k,e[35]=p,e[36]=I):I=e[36],I}function zo(t){const e=B.c(10),{phase:s,current:i,children:n}=t,o=s-i,a=o<0,l=o===0,c=a?90:o*-22,d=a?.94:1-Math.max(o,0)*.04,u=a?0:l?1:o===1?.8:.55,h=a?10:30-o,f=!l;let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m=X("absolute inset-0 rounded-xl border border-foreground/10 bg-background shadow-[0_20px_60px_-20px_rgb(0_0_0_/_0.35)] overflow-hidden transition-all ease-[cubic-bezier(0.22,1,0.36,1)]"),e[0]=m):m=e[0];const p=`translateY(${c}px) scale(${d})`,g=l?"auto":"none";let _;e[1]!==u||e[2]!==p||e[3]!==g||e[4]!==h?(_={transform:p,opacity:u,zIndex:h,transitionDuration:"1000ms",pointerEvents:g},e[1]=u,e[2]=p,e[3]=g,e[4]=h,e[5]=_):_=e[5];let v;return e[6]!==n||e[7]!==f||e[8]!==_?(v=r.jsx("div",{"aria-hidden":f,className:m,style:_,children:n}),e[6]=n,e[7]=f,e[8]=_,e[9]=v):v=e[9],v}function Xl(t){const e=B.c(7),{showUrl:s}=t,i=s===void 0?!1:s;let n,o,a;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=r.jsx("div",{className:X("w-2.5 h-2.5 rounded-full",cs)}),o=r.jsx("div",{className:X("w-2.5 h-2.5 rounded-full",cs)}),a=r.jsx("div",{className:X("w-2.5 h-2.5 rounded-full",cs)}),e[0]=n,e[1]=o,e[2]=a):(n=e[0],o=e[1],a=e[2]);let l;e[3]!==i?(l=i&&r.jsx("div",{className:X("ml-3 h-3.5 flex-1 max-w-[220px] rounded-sm",Ss)}),e[3]=i,e[4]=l):l=e[4];let c;return e[5]!==l?(c=r.jsxs("div",{className:"h-7 flex items-center gap-1.5 px-3 shrink-0",children:[n,o,a,l]}),e[5]=l,e[6]=c):c=e[6],c}function LV(){const t=B.c(5);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=r.jsx(Xl,{}),t[0]=e):e=t[0];let s;t[1]===Symbol.for("react.memo_cache_sentinel")?(s=r.jsx("div",{className:X("w-[18%] rounded-md",Ss),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=r.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 n;t[3]===Symbol.for("react.memo_cache_sentinel")?(n=r.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]=n):n=t[3];let o;return t[4]===Symbol.for("react.memo_cache_sentinel")?(o=r.jsxs("div",{className:"flex h-full flex-col",children:[e,r.jsxs("div",{className:"flex flex-1 min-h-0 gap-1.5 p-3",children:[s,r.jsxs("div",{className:"flex-1 flex flex-col gap-1.5 min-w-0",children:[i,r.jsxs("div",{className:"flex-1 grid grid-cols-5 gap-1.5 min-h-0",children:[n,r.jsxs("div",{className:"col-span-2 grid grid-rows-2 gap-1.5",children:[r.jsx("div",{className:X("rounded-md",Ss),style:{animation:"vm-breathe 3s ease-in-out 1.2s infinite"}}),r.jsx("div",{className:X("rounded-md",Ss),style:{animation:"vm-breathe 3s ease-in-out 1.6s infinite"}})]})]})]})]})]}),t[4]=o):o=t[4],o}function BV(){const t=B.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=r.jsx(Xl,{}),t[0]=e):e=t[0];let s;return t[1]===Symbol.for("react.memo_cache_sentinel")?(s=r.jsxs("div",{className:"flex h-full flex-col",children:[e,r.jsx("div",{className:"relative flex-1 flex items-center justify-center px-8 py-5",children:r.jsx("div",{className:"grid gap-2 w-full",style:{gridTemplateColumns:"repeat(7, minmax(0, 1fr))"},children:IV.map(OV)})})]}),t[1]=s):s=t[1],s}function OV(t,e){return r.jsx("div",{className:X("aspect-square rounded-md",RV[e]?"bg-chart-2/70":cs),style:{animation:`vm-pulse-soft 2.2s ease-in-out ${t}s infinite`}},e)}function $V(){const t=B.c(11);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=r.jsx(Xl,{showUrl:!0}),t[0]=e):e=t[0];let s,i,n,o,a;t[1]===Symbol.for("react.memo_cache_sentinel")?(s=r.jsx("div",{className:"h-5 rounded-md mb-2 bg-chart-1/[0.10]"}),i=r.jsx("div",{className:X("h-1.5 rounded-sm w-[70%]",cs)}),n=r.jsx("div",{className:X("h-1.5 rounded-sm w-[55%]",cs)}),o=r.jsx("div",{className:X("h-1.5 rounded-sm w-[80%]",cs)}),a=r.jsx("div",{className:X("h-1.5 rounded-sm w-[50%]",cs)}),t[1]=s,t[2]=i,t[3]=n,t[4]=o,t[5]=a):(s=t[1],i=t[2],n=t[3],o=t[4],a=t[5]);let l;t[6]===Symbol.for("react.memo_cache_sentinel")?(l=r.jsxs("div",{className:"w-[18%] p-2.5 flex flex-col gap-1.5 shrink-0 bg-chart-1/[0.05]",children:[s,i,n,o,a,r.jsx("div",{className:"mt-auto",children:r.jsx("div",{className:X("h-4 rounded-md",cs)})})]}),t[6]=l):l=t[6];let c;t[7]===Symbol.for("react.memo_cache_sentinel")?(c=r.jsx("div",{className:"relative h-[42%] shrink-0 overflow-hidden bg-chart-1/[0.10]",children:r.jsxs("div",{className:"absolute bottom-3 left-3 right-3 space-y-1.5",children:[r.jsx("div",{className:"h-3 rounded-sm w-[35%] bg-chart-1/[0.15]"}),r.jsx("div",{className:X("h-1.5 rounded-sm w-[55%]",Ss)})]})}),t[7]=c):c=t[7];let d;t[8]===Symbol.for("react.memo_cache_sentinel")?(d=r.jsxs("div",{className:"flex gap-1.5 shrink-0",children:[r.jsx("div",{className:"h-4 w-12 rounded-full bg-chart-1/[0.12]"}),r.jsx("div",{className:X("h-4 w-10 rounded-full",Ss)}),r.jsx("div",{className:X("h-4 w-14 rounded-full",Ss)})]}),t[8]=d):d=t[8];let u;t[9]===Symbol.for("react.memo_cache_sentinel")?(u=r.jsxs("div",{className:X("col-span-3 rounded-md flex flex-col justify-end p-2 gap-1",Ss),children:[r.jsx("div",{className:X("h-1.5 w-[50%] rounded-sm",cs)}),r.jsx("div",{className:X("h-1 w-[75%] rounded-sm",cs)})]}),t[9]=u):u=t[9];let h;return t[10]===Symbol.for("react.memo_cache_sentinel")?(h=r.jsxs("div",{className:"flex h-full flex-col",children:[e,r.jsxs("div",{className:"flex flex-1 min-h-0",children:[l,r.jsxs("div",{className:"flex-1 min-w-0 flex flex-col",children:[c,r.jsxs("div",{className:"flex-1 p-3 flex flex-col gap-2.5 min-h-0",children:[d,r.jsxs("div",{className:"flex-1 grid grid-cols-5 gap-2 min-h-0",children:[u,r.jsxs("div",{className:"col-span-2 grid grid-rows-2 gap-2",children:[r.jsx("div",{className:X("rounded-md",Ss)}),r.jsx("div",{className:X("rounded-md",Ss)})]})]})]})]})]})]}),t[10]=h):h=t[10],h}function qf(t){const e=B.c(21),{errorMsg:s,onRetry:i}=t;let n;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=r.jsxs("div",{className:"absolute top-8 left-1/2 -translate-x-1/2 z-20 flex items-center gap-2 rounded-full border border-destructive/30 bg-background/80 px-3.5 py-1.5 shadow-[0_4px_20px_-4px_rgb(0_0_0_/_0.12)] backdrop-blur-md",children:[r.jsx(ri,{size:13,className:"text-destructive/80"}),r.jsx("span",{className:"text-[13px] font-medium text-destructive/90",children:"Failed to start"})]}),e[0]=n):n=e[0];let o,a;e[1]===Symbol.for("react.memo_cache_sentinel")?(o=r.jsx("div",{className:"absolute left-[8%] right-[8%] -top-5 h-full rounded-xl border border-foreground/[0.05] bg-foreground/[0.015]"}),a=r.jsx("div",{className:"absolute left-[4%] right-[4%] -top-2.5 h-full rounded-xl border border-foreground/[0.07] bg-foreground/[0.025]"}),e[1]=o,e[2]=a):(o=e[1],a=e[2]);let l;e[3]===Symbol.for("react.memo_cache_sentinel")?(l=r.jsxs("div",{className:"h-7 border-b border-foreground/[0.08] bg-foreground/[0.015] flex items-center gap-1.5 px-3",children:[r.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-foreground/10"}),r.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-foreground/10"}),r.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-foreground/10"}),r.jsx("div",{className:"ml-3 h-3.5 flex-1 max-w-[240px] rounded-sm bg-foreground/[0.04]"})]}),e[3]=l):l=e[3];let c;e[4]===Symbol.for("react.memo_cache_sentinel")?(c=r.jsx(ri,{size:14,className:"text-destructive/80 mt-0.5 shrink-0"}),e[4]=c):c=e[4];let d;e[5]!==s?(d=r.jsxs("div",{className:"flex items-start gap-2",children:[c,r.jsx("p",{className:"text-xs text-destructive/80 line-clamp-5 break-all leading-relaxed font-mono",children:s})]}),e[5]=s,e[6]=d):d=e[6];let u;e[7]===Symbol.for("react.memo_cache_sentinel")?(u=r.jsx(Ah,{size:12}),e[7]=u):u=e[7];let h;e[8]!==i?(h=r.jsxs(ne,{variant:"outline",size:"sm",onClick:i,children:[u,"Retry"]}),e[8]=i,e[9]=h):h=e[9];let f;e[10]!==s?(f=()=>navigator.clipboard.writeText(s).then(zV),e[10]=s,e[11]=f):f=e[11];let m;e[12]===Symbol.for("react.memo_cache_sentinel")?(m=r.jsx(Li,{size:10}),e[12]=m):m=e[12];let p;e[13]!==f?(p=r.jsxs("button",{type:"button",onClick:f,className:"flex items-center gap-1 text-[11px] text-muted-foreground/60 hover:text-muted-foreground transition-colors duration-200",children:[m,"Copy error"]}),e[13]=f,e[14]=p):p=e[14];let g;e[15]!==p||e[16]!==h?(g=r.jsxs("div",{className:"flex items-center gap-2",children:[h,p]}),e[15]=p,e[16]=h,e[17]=g):g=e[17];let _;return e[18]!==g||e[19]!==d?(_=r.jsxs("div",{className:"relative flex flex-col items-center justify-center w-full h-full overflow-hidden select-none",children:[n,r.jsxs("div",{className:"relative w-[min(78%,560px)] aspect-[4/3] mt-6 opacity-60",children:[o,a,r.jsxs("div",{className:"relative w-full h-full rounded-xl border border-foreground/10 bg-background shadow-[0_20px_60px_-20px_rgb(0_0_0_/_0.35)] overflow-hidden",children:[l,r.jsx("div",{className:"flex items-center justify-center p-6 h-[calc(100%-1.75rem)]",children:r.jsxs("div",{className:"w-full max-w-sm rounded-lg border border-destructive/20 bg-destructive/[0.03] p-4 space-y-3",children:[d,g]})})]})]})]}),e[18]=g,e[19]=d,e[20]=_):_=e[20],_}function zV(){ge.success("Error copied to clipboard")}const FV=[{value:"preview",icon:r.jsx(qh,{size:14}),tooltip:"Interactive"},{value:"visual",icon:r.jsx(Gh,{size:14}),tooltip:"Visual Editor"}];function HV(){const t=ac(),{data:e}=St.useSession(),{openEnv:s}=gV(),{taskId:i,currentBranch:n,setCurrentTaskBranch:o}=es(),[a,l]=S.useState("preview"),[c,d]=S.useState(null),u=S.useRef(null),h=e?.user?.id,f=t?.entity?.metadata,m=h&&n?f?.vmMap?.[h]?.[n]:void 0,p=m?.previewUrl??null,g=Yi();EV(()=>{const F=u.current;F&&(F.src=F.src)});const _=g.status.htmlSupport,v=g.suspended,x=S.useRef({url:"",at:0,ready:!1});p&&x.current.url!==p&&(x.current={url:p,at:m?.createdAt??Date.now(),ready:!1}),p&&g.status.ready&&!x.current.ready&&(x.current.ready=!0);const b=!!p&&!x.current.ready&&!v,y=S.useRef(0),C=t?.entity?.id??null,j=Me({connectionId:Wt,orgId:t?.entity?.organization_id??""}),V=ql(j),w=V.error?.message??null;V.isPending?y.current||(y.current=Date.now()):p&&(y.current=0);const k=V.isPending&&!p&&!v,T=S.useRef(null),I=S.useRef(null),A=F=>{if(!C)return;const G={virtualMcpId:C};n&&(G.branch=n),V.mutate(G,{onSuccess:q=>{q?.branch&&!n&&o(q.branch)},onError:q=>{console.error(`[preview] ${F} VM_START failed`,q)}})},N=S.useRef(A);N.current=A,i&&m&&T.current!==i&&(T.current=i);const E=!!i&&!!C&&!!h&&!!n&&!m&&!w&&!V.isPending&&T.current!==i;S.useEffect(()=>{!E||!i||(T.current=i,N.current("auto-start"))},[E,i]);const R=g.notFound?m?.vmId??null:null;S.useEffect(()=>{!R||!C||w||V.isPending||I.current!==R&&(I.current=R,N.current("self-heal"))},[R,C,w,V.isPending]);const M=()=>{T.current=null,I.current=null,V.reset(),N.current("auto-start")};S.useEffect(()=>{if(!p)return;let F;try{F=new URL(p,window.location.href).origin}catch{return}const G=q=>{if(q.origin!==F||q.data?.type!=="visual-editor::element-clicked")return;const H=_V.safeParse(q.data.payload);H.success&&d(H.data)};return window.addEventListener("message",G),()=>window.removeEventListener("message",G)},[p]);const L=()=>{const F=u.current?.contentWindow;F&&F.postMessage({type:"visual-editor::activate",script:xV},"*")},D=()=>{const F=u.current?.contentWindow;F&&F.postMessage({type:"visual-editor::deactivate"},"*")},P=F=>{l(F),d(null),F==="visual"?L():D()},O=()=>{if(!u.current)return;const F=u.current;F.src=F.src},z=()=>{if(!u.current||!p)return;const F=p.includes("?")?"&":"?";u.current.src=`${p}${F}_r=${Date.now()}`},$=()=>{const F=u.current?.contentWindow?.location?.href??p;F&&navigator.clipboard.writeText(F)},W=(()=>{if(!p)return"No server running";try{const F=new URL(p);return`${F.host}${F.pathname==="/"?"":F.pathname}`}catch{return p}})();return r.jsxs("div",{className:"flex flex-col w-full h-full",children:[p&&r.jsxs("div",{className:"flex h-12 shrink-0 items-center gap-4 border-b border-border/60 px-3 md:px-4",children:[_&&r.jsx(R_,{value:a,onValueChange:P,options:FV,size:"sm",className:"shrink-0 bg-foreground/[0.045]"}),r.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-0.5",children:[r.jsxs(it,{children:[r.jsx(tt,{asChild:!0,children:r.jsx(ne,{variant:"ghost",size:"icon",onClick:()=>u.current?.contentWindow?.history.back(),children:r.jsx(xl,{size:14})})}),r.jsx(st,{side:"bottom",children:"Back"})]}),r.jsxs(it,{children:[r.jsx(tt,{asChild:!0,children:r.jsx(ne,{variant:"ghost",size:"icon",onClick:()=>u.current?.contentWindow?.history.forward(),children:r.jsx(ro,{size:14})})}),r.jsx(st,{side:"bottom",children:"Forward"})]}),r.jsxs(it,{children:[r.jsx(tt,{asChild:!0,children:r.jsx(ne,{variant:"ghost",size:"icon",onClick:O,children:r.jsx(Ah,{size:14})})}),r.jsx(st,{side:"bottom",children:"Refresh"})]}),r.jsx("div",{className:"flex h-8 min-w-0 flex-1 items-center rounded-md bg-background px-2 transition-colors duration-200 hover:bg-accent",children:r.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px] text-foreground/88",children:W})})]}),r.jsxs("div",{className:"flex shrink-0 items-center gap-0.5",children:[r.jsxs(it,{children:[r.jsx(tt,{asChild:!0,children:r.jsx(ne,{variant:"ghost",size:"icon",onClick:()=>window.open(p,"_blank","noopener"),children:r.jsx(Vi,{size:14})})}),r.jsx(st,{side:"bottom",children:"Open in new tab"})]}),r.jsxs(js,{children:[r.jsx(ks,{asChild:!0,children:r.jsx(ne,{variant:"ghost",size:"icon",children:r.jsx(Kh,{size:14})})}),r.jsxs(Ns,{align:"end",children:[r.jsx(ot,{onClick:z,children:"Hard Reload"}),r.jsx(ot,{onClick:$,children:"Copy Current URL"})]})]})]})]}),r.jsxs("div",{className:"flex-1 relative overflow-hidden",children:[!p&&!k&&!w&&r.jsxs("div",{className:"absolute inset-0 z-30 flex flex-col items-center justify-center gap-4 bg-background",children:[r.jsx(qh,{size:48,className:"text-muted-foreground/40"}),r.jsx("h3",{className:"text-lg font-medium",children:"Preview"}),r.jsx("p",{className:"text-sm text-muted-foreground text-center max-w-sm",children:"Start the development server to see a live preview"}),r.jsxs(ne,{onClick:s,children:[r.jsx(Uh,{size:14}),"Start Server"]})]}),w&&r.jsx("div",{className:"absolute inset-0 z-40 flex items-center justify-center bg-background",children:r.jsx(qf,{errorMsg:w,onRetry:M})}),!w&&v&&r.jsx("div",{className:"absolute inset-0 z-30 bg-background/80 backdrop-blur-sm",children:r.jsx(Kf,{onResume:s})}),!w&&(b||k)&&r.jsx("div",{className:"absolute inset-0 z-30 flex items-center justify-center bg-background",children:r.jsx(PV,{since:b?x.current.at:y.current,hasSetupData:g.hasData("setup"),scripts:g.scripts,activeProcesses:g.activeProcesses,onViewLogs:s})}),a==="visual"&&!c&&r.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:[r.jsx(Gh,{size:12}),"Click any element to ask the AI"]}),a==="visual"&&c&&r.jsx(yV,{element:c,onDismiss:()=>d(null)}),p&&!b&&r.jsx("iframe",{ref:u,src:p,className:"w-full h-full border-0",title:"Dev Server Preview",onLoad:()=>{se("vm_preview_loaded",{view_mode:a,vm_id:m?.vmId??null}),a==="visual"&&L()}},p)]})]})}function WV(t){const e=B.c(2),{virtualMcpId:s}=t,i=ts(s);if(!(i?Fs(i):null)){let a;return e[0]===Symbol.for("react.memo_cache_sentinel")?(a=r.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-2 text-center text-sm text-muted-foreground p-6",children:[r.jsx(ri,{size:24,className:"text-muted-foreground/60"}),r.jsx("div",{children:"No repository connected."}),r.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=r.jsx(HV,{}),e[1]=o):o=e[1],o}var Gf=Object.defineProperty,UV=Object.getOwnPropertyDescriptor,KV=(t,e)=>{for(var s in e)Gf(t,s,{get:e[s],enumerable:!0})},Ye=(t,e,s,i)=>{for(var n=i>1?void 0:i?UV(e,s):e,o=t.length-1,a;o>=0;o--)(a=t[o])&&(n=(i?a(e,s,n):a(n))||n);return i&&n&&Gf(e,s,n),n},ce=(t,e)=>(s,i)=>e(s,i,t),vd="Terminal input",Sa={get:()=>vd,set:t=>vd=t},bd="Too much output to announce, navigate to rows manually to read",wa={get:()=>bd,set:t=>bd=t};function qV(t){return t.replace(/\r?\n/g,"\r")}function GV(t,e){return e?"\x1B[200~"+t+"\x1B[201~":t}function YV(t,e){t.clipboardData&&t.clipboardData.setData("text/plain",e.selectionText),t.preventDefault()}function XV(t,e,s,i){if(t.stopPropagation(),t.clipboardData){let n=t.clipboardData.getData("text/plain");Yf(n,e,s,i)}}function Yf(t,e,s,i){t=qV(t),t=GV(t,s.decPrivateModes.bracketedPasteMode&&i.rawOptions.ignoreBracketedPasteMode!==!0),s.triggerDataEvent(t,!0),e.value=""}function Xf(t,e,s){let i=s.getBoundingClientRect(),n=t.clientX-i.left-10,o=t.clientY-i.top-10;e.style.width="20px",e.style.height="20px",e.style.left=`${n}px`,e.style.top=`${o}px`,e.style.zIndex="1000",e.focus()}function yd(t,e,s,i,n){Xf(t,e,s),n&&i.rightClickSelect(t),e.value=i.selectionText,e.select()}function Ys(t){return t>65535?(t-=65536,String.fromCharCode((t>>10)+55296)+String.fromCharCode(t%1024+56320)):String.fromCharCode(t)}function xo(t,e=0,s=t.length){let i="";for(let n=e;n<s;++n){let o=t[n];o>65535?(o-=65536,i+=String.fromCharCode((o>>10)+55296)+String.fromCharCode(o%1024+56320)):i+=String.fromCharCode(o)}return i}var JV=class{constructor(){this._interim=0}clear(){this._interim=0}decode(t,e){let s=t.length;if(!s)return 0;let i=0,n=0;if(this._interim){let o=t.charCodeAt(n++);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=n;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}},QV=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,n,o,a,l,c=0,d=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,g;for(;(g=this.interim[++p]&63)&&p<4;)m<<=6,m|=g;let _=(this.interim[0]&224)===192?2:(this.interim[0]&240)===224?3:4,v=_-p;for(;d<v;){if(d>=s)return 0;if(g=t[d++],(g&192)!==128){d--,f=!0;break}else this.interim[p++]=g,m<<=6,m|=g&63}f||(_===2?m<128?d--:e[i++]=m:_===3?m<2048||m>=55296&&m<=57343||m===65279||(e[i++]=m):m<65536||m>1114111||(e[i++]=m)),this.interim.fill(0)}let u=s-4,h=d;for(;h<s;){for(;h<u&&!((n=t[h])&128)&&!((o=t[h+1])&128)&&!((a=t[h+2])&128)&&!((l=t[h+3])&128);)e[i++]=n,e[i++]=o,e[i++]=a,e[i++]=l,h+=4;if(n=t[h++],n<128)e[i++]=n;else if((n&224)===192){if(h>=s)return this.interim[0]=n,i;if(o=t[h++],(o&192)!==128){h--;continue}if(c=(n&31)<<6|o&63,c<128){h--;continue}e[i++]=c}else if((n&240)===224){if(h>=s)return this.interim[0]=n,i;if(o=t[h++],(o&192)!==128){h--;continue}if(h>=s)return this.interim[0]=n,this.interim[1]=o,i;if(a=t[h++],(a&192)!==128){h--;continue}if(c=(n&15)<<12|(o&63)<<6|a&63,c<2048||c>=55296&&c<=57343||c===65279)continue;e[i++]=c}else if((n&248)===240){if(h>=s)return this.interim[0]=n,i;if(o=t[h++],(o&192)!==128){h--;continue}if(h>=s)return this.interim[0]=n,this.interim[1]=o,i;if(a=t[h++],(a&192)!==128){h--;continue}if(h>=s)return this.interim[0]=n,this.interim[1]=o,this.interim[2]=a,i;if(l=t[h++],(l&192)!==128){h--;continue}if(c=(n&7)<<18|(o&63)<<12|(a&63)<<6|l&63,c<65536||c>1114111)continue;e[i++]=c}}return i}},Jf="",Xs=" ",en=class Qf{constructor(){this.fg=0,this.bg=0,this.extended=new qn}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 Qf;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}},qn=class Zf{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 Zf(this._ext,this._urlId)}isEmpty(){return this.underlineStyle===0&&this._urlId===0}},as=class em extends en{constructor(){super(...arguments),this.content=0,this.fg=0,this.bg=0,this.extended=new qn,this.combinedData=""}static fromCharData(e){let s=new em;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?Ys(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 n=e[1].charCodeAt(1);56320<=n&&n<=57343?this.content=(i-55296)*1024+n-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()]}},Sd="di$target",Va="di$dependencies",Fo=new Map;function ZV(t){return t[Va]||[]}function gt(t){if(Fo.has(t))return Fo.get(t);let e=function(s,i,n){if(arguments.length!==3)throw new Error("@IServiceName-decorator can only be used to decorate a parameter");eC(e,s,n)};return e._id=t,Fo.set(t,e),e}function eC(t,e,s){e[Sd]===e?e[Va].push({id:t,index:s}):(e[Va]=[{id:t,index:s}],e[Sd]=e)}var Lt=gt("BufferService"),tm=gt("CoreMouseService"),Ci=gt("CoreService"),tC=gt("CharsetService"),Jl=gt("InstantiationService"),sm=gt("LogService"),Bt=gt("OptionsService"),im=gt("OscLinkService"),sC=gt("UnicodeService"),tn=gt("DecorationService"),Ca=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=[],n=this._optionsService.rawOptions.linkHandler,o=new as,a=s.getTrimmedLength(),l=-1,c=-1,d=!1;for(let u=0;u<a;u++)if(!(c===-1&&!s.hasContent(u))){if(s.loadCell(u,o),o.hasExtendedAttrs()&&o.extended.urlId)if(c===-1){c=u,l=o.extended.urlId;continue}else d=o.extended.urlId!==l;else c!==-1&&(d=!0);if(d||c!==-1&&u===a-1){let h=this._oscLinkService.getLinkData(l)?.uri;if(h){let f={start:{x:c+1,y:t},end:{x:u+(!d&&u===a-1?1:0),y:t}},m=!1;if(!n?.allowNonHttpProtocols)try{let p=new URL(h);["http:","https:"].includes(p.protocol)||(m=!0)}catch{m=!0}m||i.push({text:h,range:f,activate:(p,g)=>n?n.activate(p,g,f):iC(p,g),hover:(p,g)=>n?.hover?.(p,g,f),leave:(p,g)=>n?.leave?.(p,g,f)})}d=!1,o.hasExtendedAttrs()&&o.extended.urlId?(c=u,l=o.extended.urlId):(c=-1,l=-1)}}e(i)}};Ca=Ye([ce(0,Lt),ce(1,Bt),ce(2,im)],Ca);function iC(t,e){if(confirm(`Do you want to navigate to ${e}?
428
+ `}),e[32]=T):T=e[32];let I;return e[33]!==C||e[34]!==k||e[35]!==p?(I=r.jsxs("div",{className:"relative flex flex-col items-center justify-center w-full h-full overflow-hidden select-none gap-8",children:[p,C,k,T]}),e[33]=C,e[34]=k,e[35]=p,e[36]=I):I=e[36],I}function zo(t){const e=B.c(10),{phase:s,current:i,children:n}=t,o=s-i,a=o<0,l=o===0,c=a?90:o*-22,d=a?.94:1-Math.max(o,0)*.04,u=a?0:l?1:o===1?.8:.55,h=a?10:30-o,f=!l;let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m=X("absolute inset-0 rounded-xl border border-foreground/10 bg-background shadow-[0_20px_60px_-20px_rgb(0_0_0_/_0.35)] overflow-hidden transition-all ease-[cubic-bezier(0.22,1,0.36,1)]"),e[0]=m):m=e[0];const p=`translateY(${c}px) scale(${d})`,g=l?"auto":"none";let _;e[1]!==u||e[2]!==p||e[3]!==g||e[4]!==h?(_={transform:p,opacity:u,zIndex:h,transitionDuration:"1000ms",pointerEvents:g},e[1]=u,e[2]=p,e[3]=g,e[4]=h,e[5]=_):_=e[5];let v;return e[6]!==n||e[7]!==f||e[8]!==_?(v=r.jsx("div",{"aria-hidden":f,className:m,style:_,children:n}),e[6]=n,e[7]=f,e[8]=_,e[9]=v):v=e[9],v}function Xl(t){const e=B.c(7),{showUrl:s}=t,i=s===void 0?!1:s;let n,o,a;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=r.jsx("div",{className:X("w-2.5 h-2.5 rounded-full",cs)}),o=r.jsx("div",{className:X("w-2.5 h-2.5 rounded-full",cs)}),a=r.jsx("div",{className:X("w-2.5 h-2.5 rounded-full",cs)}),e[0]=n,e[1]=o,e[2]=a):(n=e[0],o=e[1],a=e[2]);let l;e[3]!==i?(l=i&&r.jsx("div",{className:X("ml-3 h-3.5 flex-1 max-w-[220px] rounded-sm",Ss)}),e[3]=i,e[4]=l):l=e[4];let c;return e[5]!==l?(c=r.jsxs("div",{className:"h-7 flex items-center gap-1.5 px-3 shrink-0",children:[n,o,a,l]}),e[5]=l,e[6]=c):c=e[6],c}function $V(){const t=B.c(5);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=r.jsx(Xl,{}),t[0]=e):e=t[0];let s;t[1]===Symbol.for("react.memo_cache_sentinel")?(s=r.jsx("div",{className:X("w-[18%] rounded-md",Ss),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=r.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 n;t[3]===Symbol.for("react.memo_cache_sentinel")?(n=r.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]=n):n=t[3];let o;return t[4]===Symbol.for("react.memo_cache_sentinel")?(o=r.jsxs("div",{className:"flex h-full flex-col",children:[e,r.jsxs("div",{className:"flex flex-1 min-h-0 gap-1.5 p-3",children:[s,r.jsxs("div",{className:"flex-1 flex flex-col gap-1.5 min-w-0",children:[i,r.jsxs("div",{className:"flex-1 grid grid-cols-5 gap-1.5 min-h-0",children:[n,r.jsxs("div",{className:"col-span-2 grid grid-rows-2 gap-1.5",children:[r.jsx("div",{className:X("rounded-md",Ss),style:{animation:"vm-breathe 3s ease-in-out 1.2s infinite"}}),r.jsx("div",{className:X("rounded-md",Ss),style:{animation:"vm-breathe 3s ease-in-out 1.6s infinite"}})]})]})]})]})]}),t[4]=o):o=t[4],o}function zV(){const t=B.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=r.jsx(Xl,{}),t[0]=e):e=t[0];let s;return t[1]===Symbol.for("react.memo_cache_sentinel")?(s=r.jsxs("div",{className:"flex h-full flex-col",children:[e,r.jsx("div",{className:"relative flex-1 flex items-center justify-center px-8 py-5",children:r.jsx("div",{className:"grid gap-2 w-full",style:{gridTemplateColumns:"repeat(7, minmax(0, 1fr))"},children:DV.map(FV)})})]}),t[1]=s):s=t[1],s}function FV(t,e){return r.jsx("div",{className:X("aspect-square rounded-md",MV[e]?"bg-chart-2/70":cs),style:{animation:`vm-pulse-soft 2.2s ease-in-out ${t}s infinite`}},e)}function HV(){const t=B.c(11);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=r.jsx(Xl,{showUrl:!0}),t[0]=e):e=t[0];let s,i,n,o,a;t[1]===Symbol.for("react.memo_cache_sentinel")?(s=r.jsx("div",{className:"h-5 rounded-md mb-2 bg-chart-1/[0.10]"}),i=r.jsx("div",{className:X("h-1.5 rounded-sm w-[70%]",cs)}),n=r.jsx("div",{className:X("h-1.5 rounded-sm w-[55%]",cs)}),o=r.jsx("div",{className:X("h-1.5 rounded-sm w-[80%]",cs)}),a=r.jsx("div",{className:X("h-1.5 rounded-sm w-[50%]",cs)}),t[1]=s,t[2]=i,t[3]=n,t[4]=o,t[5]=a):(s=t[1],i=t[2],n=t[3],o=t[4],a=t[5]);let l;t[6]===Symbol.for("react.memo_cache_sentinel")?(l=r.jsxs("div",{className:"w-[18%] p-2.5 flex flex-col gap-1.5 shrink-0 bg-chart-1/[0.05]",children:[s,i,n,o,a,r.jsx("div",{className:"mt-auto",children:r.jsx("div",{className:X("h-4 rounded-md",cs)})})]}),t[6]=l):l=t[6];let c;t[7]===Symbol.for("react.memo_cache_sentinel")?(c=r.jsx("div",{className:"relative h-[42%] shrink-0 overflow-hidden bg-chart-1/[0.10]",children:r.jsxs("div",{className:"absolute bottom-3 left-3 right-3 space-y-1.5",children:[r.jsx("div",{className:"h-3 rounded-sm w-[35%] bg-chart-1/[0.15]"}),r.jsx("div",{className:X("h-1.5 rounded-sm w-[55%]",Ss)})]})}),t[7]=c):c=t[7];let d;t[8]===Symbol.for("react.memo_cache_sentinel")?(d=r.jsxs("div",{className:"flex gap-1.5 shrink-0",children:[r.jsx("div",{className:"h-4 w-12 rounded-full bg-chart-1/[0.12]"}),r.jsx("div",{className:X("h-4 w-10 rounded-full",Ss)}),r.jsx("div",{className:X("h-4 w-14 rounded-full",Ss)})]}),t[8]=d):d=t[8];let u;t[9]===Symbol.for("react.memo_cache_sentinel")?(u=r.jsxs("div",{className:X("col-span-3 rounded-md flex flex-col justify-end p-2 gap-1",Ss),children:[r.jsx("div",{className:X("h-1.5 w-[50%] rounded-sm",cs)}),r.jsx("div",{className:X("h-1 w-[75%] rounded-sm",cs)})]}),t[9]=u):u=t[9];let h;return t[10]===Symbol.for("react.memo_cache_sentinel")?(h=r.jsxs("div",{className:"flex h-full flex-col",children:[e,r.jsxs("div",{className:"flex flex-1 min-h-0",children:[l,r.jsxs("div",{className:"flex-1 min-w-0 flex flex-col",children:[c,r.jsxs("div",{className:"flex-1 p-3 flex flex-col gap-2.5 min-h-0",children:[d,r.jsxs("div",{className:"flex-1 grid grid-cols-5 gap-2 min-h-0",children:[u,r.jsxs("div",{className:"col-span-2 grid grid-rows-2 gap-2",children:[r.jsx("div",{className:X("rounded-md",Ss)}),r.jsx("div",{className:X("rounded-md",Ss)})]})]})]})]})]})]}),t[10]=h):h=t[10],h}function Gf(t){const e=B.c(21),{errorMsg:s,onRetry:i}=t;let n;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=r.jsxs("div",{className:"absolute top-8 left-1/2 -translate-x-1/2 z-20 flex items-center gap-2 rounded-full border border-destructive/30 bg-background/80 px-3.5 py-1.5 shadow-[0_4px_20px_-4px_rgb(0_0_0_/_0.12)] backdrop-blur-md",children:[r.jsx(ri,{size:13,className:"text-destructive/80"}),r.jsx("span",{className:"text-[13px] font-medium text-destructive/90",children:"Failed to start"})]}),e[0]=n):n=e[0];let o,a;e[1]===Symbol.for("react.memo_cache_sentinel")?(o=r.jsx("div",{className:"absolute left-[8%] right-[8%] -top-5 h-full rounded-xl border border-foreground/[0.05] bg-foreground/[0.015]"}),a=r.jsx("div",{className:"absolute left-[4%] right-[4%] -top-2.5 h-full rounded-xl border border-foreground/[0.07] bg-foreground/[0.025]"}),e[1]=o,e[2]=a):(o=e[1],a=e[2]);let l;e[3]===Symbol.for("react.memo_cache_sentinel")?(l=r.jsxs("div",{className:"h-7 border-b border-foreground/[0.08] bg-foreground/[0.015] flex items-center gap-1.5 px-3",children:[r.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-foreground/10"}),r.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-foreground/10"}),r.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-foreground/10"}),r.jsx("div",{className:"ml-3 h-3.5 flex-1 max-w-[240px] rounded-sm bg-foreground/[0.04]"})]}),e[3]=l):l=e[3];let c;e[4]===Symbol.for("react.memo_cache_sentinel")?(c=r.jsx(ri,{size:14,className:"text-destructive/80 mt-0.5 shrink-0"}),e[4]=c):c=e[4];let d;e[5]!==s?(d=r.jsxs("div",{className:"flex items-start gap-2",children:[c,r.jsx("p",{className:"text-xs text-destructive/80 line-clamp-5 break-all leading-relaxed font-mono",children:s})]}),e[5]=s,e[6]=d):d=e[6];let u;e[7]===Symbol.for("react.memo_cache_sentinel")?(u=r.jsx(Ah,{size:12}),e[7]=u):u=e[7];let h;e[8]!==i?(h=r.jsxs(ne,{variant:"outline",size:"sm",onClick:i,children:[u,"Retry"]}),e[8]=i,e[9]=h):h=e[9];let f;e[10]!==s?(f=()=>navigator.clipboard.writeText(s).then(WV),e[10]=s,e[11]=f):f=e[11];let m;e[12]===Symbol.for("react.memo_cache_sentinel")?(m=r.jsx(Li,{size:10}),e[12]=m):m=e[12];let p;e[13]!==f?(p=r.jsxs("button",{type:"button",onClick:f,className:"flex items-center gap-1 text-[11px] text-muted-foreground/60 hover:text-muted-foreground transition-colors duration-200",children:[m,"Copy error"]}),e[13]=f,e[14]=p):p=e[14];let g;e[15]!==p||e[16]!==h?(g=r.jsxs("div",{className:"flex items-center gap-2",children:[h,p]}),e[15]=p,e[16]=h,e[17]=g):g=e[17];let _;return e[18]!==g||e[19]!==d?(_=r.jsxs("div",{className:"relative flex flex-col items-center justify-center w-full h-full overflow-hidden select-none",children:[n,r.jsxs("div",{className:"relative w-[min(78%,560px)] aspect-[4/3] mt-6 opacity-60",children:[o,a,r.jsxs("div",{className:"relative w-full h-full rounded-xl border border-foreground/10 bg-background shadow-[0_20px_60px_-20px_rgb(0_0_0_/_0.35)] overflow-hidden",children:[l,r.jsx("div",{className:"flex items-center justify-center p-6 h-[calc(100%-1.75rem)]",children:r.jsxs("div",{className:"w-full max-w-sm rounded-lg border border-destructive/20 bg-destructive/[0.03] p-4 space-y-3",children:[d,g]})})]})]})]}),e[18]=g,e[19]=d,e[20]=_):_=e[20],_}function WV(){pe.success("Error copied to clipboard")}const UV=[{value:"preview",icon:r.jsx(qh,{size:14}),tooltip:"Interactive"},{value:"visual",icon:r.jsx(Gh,{size:14}),tooltip:"Visual Editor"}];function KV(){const t=ac(),{data:e}=St.useSession(),{openEnv:s}=vV(),{taskId:i,currentBranch:n,setCurrentTaskBranch:o}=es(),[a,l]=S.useState("preview"),[c,d]=S.useState(null),u=S.useRef(null),h=e?.user?.id,f=t?.entity?.metadata,m=h&&n?f?.vmMap?.[h]?.[n]:void 0,p=m?.previewUrl??null,g=Yi();TV(()=>{const F=u.current;F&&(F.src=F.src)});const _=g.status.htmlSupport,v=g.suspended,x=S.useRef({url:"",at:0,ready:!1});p&&x.current.url!==p&&(x.current={url:p,at:m?.createdAt??Date.now(),ready:!1}),p&&g.status.ready&&!x.current.ready&&(x.current.ready=!0);const b=!!p&&!x.current.ready&&!v,y=S.useRef(0),C=t?.entity?.id??null,j=Me({connectionId:Wt,orgId:t?.entity?.organization_id??""}),V=ql(j),w=V.error?.message??null;V.isPending?y.current||(y.current=Date.now()):p&&(y.current=0);const k=V.isPending&&!p&&!v,T=S.useRef(null),I=S.useRef(null),A=F=>{if(!C)return;const G={virtualMcpId:C};n&&(G.branch=n),V.mutate(G,{onSuccess:q=>{q?.branch&&!n&&o(q.branch)},onError:q=>{console.error(`[preview] ${F} VM_START failed`,q)}})},N=S.useRef(A);N.current=A,i&&m&&T.current!==i&&(T.current=i);const E=!!i&&!!C&&!!h&&!!n&&!m&&!w&&!V.isPending&&T.current!==i;S.useEffect(()=>{!E||!i||(T.current=i,N.current("auto-start"))},[E,i]);const R=g.notFound?m?.vmId??null:null;S.useEffect(()=>{!R||!C||w||V.isPending||I.current!==R&&(I.current=R,N.current("self-heal"))},[R,C,w,V.isPending]);const M=()=>{T.current=null,I.current=null,V.reset(),N.current("auto-start")};S.useEffect(()=>{if(!p)return;let F;try{F=new URL(p,window.location.href).origin}catch{return}const G=q=>{if(q.origin!==F||q.data?.type!=="visual-editor::element-clicked")return;const H=bV.safeParse(q.data.payload);H.success&&d(H.data)};return window.addEventListener("message",G),()=>window.removeEventListener("message",G)},[p]);const L=()=>{const F=u.current?.contentWindow;F&&F.postMessage({type:"visual-editor::activate",script:yV},"*")},D=()=>{const F=u.current?.contentWindow;F&&F.postMessage({type:"visual-editor::deactivate"},"*")},P=F=>{l(F),d(null),F==="visual"?L():D()},O=()=>{if(!u.current)return;const F=u.current;F.src=F.src},z=()=>{if(!u.current||!p)return;const F=p.includes("?")?"&":"?";u.current.src=`${p}${F}_r=${Date.now()}`},$=()=>{const F=u.current?.contentWindow?.location?.href??p;F&&navigator.clipboard.writeText(F)},W=(()=>{if(!p)return"No server running";try{const F=new URL(p);return`${F.host}${F.pathname==="/"?"":F.pathname}`}catch{return p}})();return r.jsxs("div",{className:"flex flex-col w-full h-full",children:[p&&r.jsxs("div",{className:"flex h-12 shrink-0 items-center gap-4 border-b border-border/60 px-3 md:px-4",children:[_&&r.jsx(M_,{value:a,onValueChange:P,options:UV,size:"sm",className:"shrink-0 bg-foreground/[0.045]"}),r.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-0.5",children:[r.jsxs(it,{children:[r.jsx(tt,{asChild:!0,children:r.jsx(ne,{variant:"ghost",size:"icon",onClick:()=>u.current?.contentWindow?.history.back(),children:r.jsx(xl,{size:14})})}),r.jsx(st,{side:"bottom",children:"Back"})]}),r.jsxs(it,{children:[r.jsx(tt,{asChild:!0,children:r.jsx(ne,{variant:"ghost",size:"icon",onClick:()=>u.current?.contentWindow?.history.forward(),children:r.jsx(ro,{size:14})})}),r.jsx(st,{side:"bottom",children:"Forward"})]}),r.jsxs(it,{children:[r.jsx(tt,{asChild:!0,children:r.jsx(ne,{variant:"ghost",size:"icon",onClick:O,children:r.jsx(Ah,{size:14})})}),r.jsx(st,{side:"bottom",children:"Refresh"})]}),r.jsx("div",{className:"flex h-8 min-w-0 flex-1 items-center rounded-md bg-background px-2 transition-colors duration-200 hover:bg-accent",children:r.jsx("span",{className:"min-w-0 flex-1 truncate text-[12px] text-foreground/88",children:W})})]}),r.jsxs("div",{className:"flex shrink-0 items-center gap-0.5",children:[r.jsxs(it,{children:[r.jsx(tt,{asChild:!0,children:r.jsx(ne,{variant:"ghost",size:"icon",onClick:()=>window.open(p,"_blank","noopener"),children:r.jsx(Vi,{size:14})})}),r.jsx(st,{side:"bottom",children:"Open in new tab"})]}),r.jsxs(js,{children:[r.jsx(ks,{asChild:!0,children:r.jsx(ne,{variant:"ghost",size:"icon",children:r.jsx(Kh,{size:14})})}),r.jsxs(Ns,{align:"end",children:[r.jsx(ot,{onClick:z,children:"Hard Reload"}),r.jsx(ot,{onClick:$,children:"Copy Current URL"})]})]})]})]}),r.jsxs("div",{className:"flex-1 relative overflow-hidden",children:[!p&&!k&&!w&&r.jsxs("div",{className:"absolute inset-0 z-30 flex flex-col items-center justify-center gap-4 bg-background",children:[r.jsx(qh,{size:48,className:"text-muted-foreground/40"}),r.jsx("h3",{className:"text-lg font-medium",children:"Preview"}),r.jsx("p",{className:"text-sm text-muted-foreground text-center max-w-sm",children:"Start the development server to see a live preview"}),r.jsxs(ne,{onClick:s,children:[r.jsx(Uh,{size:14}),"Start Server"]})]}),w&&r.jsx("div",{className:"absolute inset-0 z-40 flex items-center justify-center bg-background",children:r.jsx(Gf,{errorMsg:w,onRetry:M})}),!w&&v&&r.jsx("div",{className:"absolute inset-0 z-30 bg-background/80 backdrop-blur-sm",children:r.jsx(qf,{onResume:s})}),!w&&(b||k)&&r.jsx("div",{className:"absolute inset-0 z-30 flex items-center justify-center bg-background",children:r.jsx(OV,{since:b?x.current.at:y.current,hasSetupData:g.hasData("setup"),scripts:g.scripts,activeProcesses:g.activeProcesses,onViewLogs:s})}),a==="visual"&&!c&&r.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:[r.jsx(Gh,{size:12}),"Click any element to ask the AI"]}),a==="visual"&&c&&r.jsx(VV,{element:c,onDismiss:()=>d(null)}),p&&!b&&r.jsx("iframe",{ref:u,src:p,className:"w-full h-full border-0",title:"Dev Server Preview",onLoad:()=>{se("vm_preview_loaded",{view_mode:a,vm_id:m?.vmId??null}),a==="visual"&&L()}},p)]})]})}function qV(t){const e=B.c(2),{virtualMcpId:s}=t,i=ts(s);if(!(i?Fs(i):null)){let a;return e[0]===Symbol.for("react.memo_cache_sentinel")?(a=r.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-2 text-center text-sm text-muted-foreground p-6",children:[r.jsx(ri,{size:24,className:"text-muted-foreground/60"}),r.jsx("div",{children:"No repository connected."}),r.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=r.jsx(KV,{}),e[1]=o):o=e[1],o}var Yf=Object.defineProperty,GV=Object.getOwnPropertyDescriptor,YV=(t,e)=>{for(var s in e)Yf(t,s,{get:e[s],enumerable:!0})},Ye=(t,e,s,i)=>{for(var n=i>1?void 0:i?GV(e,s):e,o=t.length-1,a;o>=0;o--)(a=t[o])&&(n=(i?a(e,s,n):a(n))||n);return i&&n&&Yf(e,s,n),n},ce=(t,e)=>(s,i)=>e(s,i,t),vd="Terminal input",Sa={get:()=>vd,set:t=>vd=t},bd="Too much output to announce, navigate to rows manually to read",wa={get:()=>bd,set:t=>bd=t};function XV(t){return t.replace(/\r?\n/g,"\r")}function JV(t,e){return e?"\x1B[200~"+t+"\x1B[201~":t}function QV(t,e){t.clipboardData&&t.clipboardData.setData("text/plain",e.selectionText),t.preventDefault()}function ZV(t,e,s,i){if(t.stopPropagation(),t.clipboardData){let n=t.clipboardData.getData("text/plain");Xf(n,e,s,i)}}function Xf(t,e,s,i){t=XV(t),t=JV(t,s.decPrivateModes.bracketedPasteMode&&i.rawOptions.ignoreBracketedPasteMode!==!0),s.triggerDataEvent(t,!0),e.value=""}function Jf(t,e,s){let i=s.getBoundingClientRect(),n=t.clientX-i.left-10,o=t.clientY-i.top-10;e.style.width="20px",e.style.height="20px",e.style.left=`${n}px`,e.style.top=`${o}px`,e.style.zIndex="1000",e.focus()}function yd(t,e,s,i,n){Jf(t,e,s),n&&i.rightClickSelect(t),e.value=i.selectionText,e.select()}function Ys(t){return t>65535?(t-=65536,String.fromCharCode((t>>10)+55296)+String.fromCharCode(t%1024+56320)):String.fromCharCode(t)}function xo(t,e=0,s=t.length){let i="";for(let n=e;n<s;++n){let o=t[n];o>65535?(o-=65536,i+=String.fromCharCode((o>>10)+55296)+String.fromCharCode(o%1024+56320)):i+=String.fromCharCode(o)}return i}var eC=class{constructor(){this._interim=0}clear(){this._interim=0}decode(t,e){let s=t.length;if(!s)return 0;let i=0,n=0;if(this._interim){let o=t.charCodeAt(n++);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=n;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}},tC=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,n,o,a,l,c=0,d=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,g;for(;(g=this.interim[++p]&63)&&p<4;)m<<=6,m|=g;let _=(this.interim[0]&224)===192?2:(this.interim[0]&240)===224?3:4,v=_-p;for(;d<v;){if(d>=s)return 0;if(g=t[d++],(g&192)!==128){d--,f=!0;break}else this.interim[p++]=g,m<<=6,m|=g&63}f||(_===2?m<128?d--:e[i++]=m:_===3?m<2048||m>=55296&&m<=57343||m===65279||(e[i++]=m):m<65536||m>1114111||(e[i++]=m)),this.interim.fill(0)}let u=s-4,h=d;for(;h<s;){for(;h<u&&!((n=t[h])&128)&&!((o=t[h+1])&128)&&!((a=t[h+2])&128)&&!((l=t[h+3])&128);)e[i++]=n,e[i++]=o,e[i++]=a,e[i++]=l,h+=4;if(n=t[h++],n<128)e[i++]=n;else if((n&224)===192){if(h>=s)return this.interim[0]=n,i;if(o=t[h++],(o&192)!==128){h--;continue}if(c=(n&31)<<6|o&63,c<128){h--;continue}e[i++]=c}else if((n&240)===224){if(h>=s)return this.interim[0]=n,i;if(o=t[h++],(o&192)!==128){h--;continue}if(h>=s)return this.interim[0]=n,this.interim[1]=o,i;if(a=t[h++],(a&192)!==128){h--;continue}if(c=(n&15)<<12|(o&63)<<6|a&63,c<2048||c>=55296&&c<=57343||c===65279)continue;e[i++]=c}else if((n&248)===240){if(h>=s)return this.interim[0]=n,i;if(o=t[h++],(o&192)!==128){h--;continue}if(h>=s)return this.interim[0]=n,this.interim[1]=o,i;if(a=t[h++],(a&192)!==128){h--;continue}if(h>=s)return this.interim[0]=n,this.interim[1]=o,this.interim[2]=a,i;if(l=t[h++],(l&192)!==128){h--;continue}if(c=(n&7)<<18|(o&63)<<12|(a&63)<<6|l&63,c<65536||c>1114111)continue;e[i++]=c}}return i}},Qf="",Xs=" ",en=class Zf{constructor(){this.fg=0,this.bg=0,this.extended=new qn}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 Zf;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}},qn=class em{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 em(this._ext,this._urlId)}isEmpty(){return this.underlineStyle===0&&this._urlId===0}},as=class tm extends en{constructor(){super(...arguments),this.content=0,this.fg=0,this.bg=0,this.extended=new qn,this.combinedData=""}static fromCharData(e){let s=new tm;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?Ys(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 n=e[1].charCodeAt(1);56320<=n&&n<=57343?this.content=(i-55296)*1024+n-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()]}},Sd="di$target",Va="di$dependencies",Fo=new Map;function sC(t){return t[Va]||[]}function gt(t){if(Fo.has(t))return Fo.get(t);let e=function(s,i,n){if(arguments.length!==3)throw new Error("@IServiceName-decorator can only be used to decorate a parameter");iC(e,s,n)};return e._id=t,Fo.set(t,e),e}function iC(t,e,s){e[Sd]===e?e[Va].push({id:t,index:s}):(e[Va]=[{id:t,index:s}],e[Sd]=e)}var Lt=gt("BufferService"),sm=gt("CoreMouseService"),Ci=gt("CoreService"),rC=gt("CharsetService"),Jl=gt("InstantiationService"),im=gt("LogService"),Bt=gt("OptionsService"),rm=gt("OscLinkService"),nC=gt("UnicodeService"),tn=gt("DecorationService"),Ca=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=[],n=this._optionsService.rawOptions.linkHandler,o=new as,a=s.getTrimmedLength(),l=-1,c=-1,d=!1;for(let u=0;u<a;u++)if(!(c===-1&&!s.hasContent(u))){if(s.loadCell(u,o),o.hasExtendedAttrs()&&o.extended.urlId)if(c===-1){c=u,l=o.extended.urlId;continue}else d=o.extended.urlId!==l;else c!==-1&&(d=!0);if(d||c!==-1&&u===a-1){let h=this._oscLinkService.getLinkData(l)?.uri;if(h){let f={start:{x:c+1,y:t},end:{x:u+(!d&&u===a-1?1:0),y:t}},m=!1;if(!n?.allowNonHttpProtocols)try{let p=new URL(h);["http:","https:"].includes(p.protocol)||(m=!0)}catch{m=!0}m||i.push({text:h,range:f,activate:(p,g)=>n?n.activate(p,g,f):oC(p,g),hover:(p,g)=>n?.hover?.(p,g,f),leave:(p,g)=>n?.leave?.(p,g,f)})}d=!1,o.hasExtendedAttrs()&&o.extended.urlId?(c=u,l=o.extended.urlId):(c=-1,l=-1)}}e(i)}};Ca=Ye([ce(0,Lt),ce(1,Bt),ce(2,rm)],Ca);function oC(t,e){if(confirm(`Do you want to navigate to ${e}?
429
429
 
430
- 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 vo=gt("CharSizeService"),Hs=gt("CoreBrowserService"),Ql=gt("MouseService"),Ws=gt("RenderService"),rC=gt("SelectionService"),rm=gt("CharacterJoinerService"),Xi=gt("ThemeService"),nm=gt("LinkProviderService"),nC=class{constructor(){this.listeners=[],this.unexpectedErrorHandler=function(t){setTimeout(()=>{throw t.stack?wd.isErrorNoTelemetry(t)?new wd(t.message+`
430
+ 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 vo=gt("CharSizeService"),Hs=gt("CoreBrowserService"),Ql=gt("MouseService"),Ws=gt("RenderService"),aC=gt("SelectionService"),nm=gt("CharacterJoinerService"),Xi=gt("ThemeService"),om=gt("LinkProviderService"),lC=class{constructor(){this.listeners=[],this.unexpectedErrorHandler=function(t){setTimeout(()=>{throw t.stack?wd.isErrorNoTelemetry(t)?new wd(t.message+`
431
431
 
432
432
  `+t.stack):new Error(t.message+`
433
433
 
434
- `+t.stack):t},0)}}addListener(t){return this.listeners.push(t),()=>{this._removeListener(t)}}emit(t){this.listeners.forEach(e=>{e(t)})}_removeListener(t){this.listeners.splice(this.listeners.indexOf(t),1)}setUnexpectedErrorHandler(t){this.unexpectedErrorHandler=t}getUnexpectedErrorHandler(){return this.unexpectedErrorHandler}onUnexpectedError(t){this.unexpectedErrorHandler(t),this.emit(t)}onUnexpectedExternalError(t){this.unexpectedErrorHandler(t)}},oC=new nC;function An(t){aC(t)||oC.onUnexpectedError(t)}var ja="Canceled";function aC(t){return t instanceof lC?!0:t instanceof Error&&t.name===ja&&t.message===ja}var lC=class extends Error{constructor(){super(ja),this.name=this.message}};function cC(t){return new Error(`Illegal argument: ${t}`)}var wd=class ka extends Error{constructor(e){super(e),this.name="CodeExpectedError"}static fromError(e){if(e instanceof ka)return e;let s=new ka;return s.message=e.message,s.stack=e.stack,s}static isErrorNoTelemetry(e){return e.name==="CodeExpectedError"}},Na=class om extends Error{constructor(e){super(e||"An unexpected bug occurred."),Object.setPrototypeOf(this,om.prototype)}};function Gt(t,e=0){return t[t.length-(1+e)]}var dC;(t=>{function e(o){return o<0}t.isLessThan=e;function s(o){return o<=0}t.isLessThanOrEqual=s;function i(o){return o>0}t.isGreaterThan=i;function n(o){return o===0}t.isNeitherLessOrGreaterThan=n,t.greaterThan=1,t.lessThan=-1,t.neitherLessOrGreaterThan=0})(dC||={});function hC(t,e){let s=this,i=!1,n;return function(){return i||(i=!0,e||(n=t.apply(s,arguments))),n}}var am;(t=>{function e(y){return y&&typeof y=="object"&&typeof y[Symbol.iterator]=="function"}t.is=e;let s=Object.freeze([]);function i(){return s}t.empty=i;function*n(y){yield y}t.single=n;function o(y){return e(y)?y:n(y)}t.wrap=o;function a(y){return y||s}t.from=a;function*l(y){for(let C=y.length-1;C>=0;C--)yield y[C]}t.reverse=l;function c(y){return!y||y[Symbol.iterator]().next().done===!0}t.isEmpty=c;function d(y){return y[Symbol.iterator]().next().value}t.first=d;function u(y,C){let j=0;for(let V of y)if(C(V,j++))return!0;return!1}t.some=u;function h(y,C){for(let j of y)if(C(j))return j}t.find=h;function*f(y,C){for(let j of y)C(j)&&(yield j)}t.filter=f;function*m(y,C){let j=0;for(let V of y)yield C(V,j++)}t.map=m;function*p(y,C){let j=0;for(let V of y)yield*C(V,j++)}t.flatMap=p;function*g(...y){for(let C of y)yield*C}t.concat=g;function _(y,C,j){let V=j;for(let w of y)V=C(V,w);return V}t.reduce=_;function*v(y,C,j=y.length){for(C<0&&(C+=y.length),j<0?j+=y.length:j>y.length&&(j=y.length);C<j;C++)yield y[C]}t.slice=v;function x(y,C=Number.POSITIVE_INFINITY){let j=[];if(C===0)return[j,y];let V=y[Symbol.iterator]();for(let w=0;w<C;w++){let k=V.next();if(k.done)return[j,t.empty()];j.push(k.value)}return[j,{[Symbol.iterator](){return V}}]}t.consume=x;async function b(y){let C=[];for await(let j of y)C.push(j);return Promise.resolve(C)}t.asyncToArray=b})(am||={});function _i(t){if(am.is(t)){let e=[];for(let s of t)if(s)try{s.dispose()}catch(i){e.push(i)}if(e.length===1)throw e[0];if(e.length>1)throw new AggregateError(e,"Encountered errors while disposing of store");return Array.isArray(t)?[]:t}else if(t)return t.dispose(),t}function uC(...t){return Fe(()=>_i(t))}function Fe(t){return{dispose:hC(()=>{t()})}}var lm=class cm{constructor(){this._toDispose=new Set,this._isDisposed=!1}dispose(){this._isDisposed||(this._isDisposed=!0,this.clear())}get isDisposed(){return this._isDisposed}clear(){if(this._toDispose.size!==0)try{_i(this._toDispose)}finally{this._toDispose.clear()}}add(e){if(!e)return e;if(e===this)throw new Error("Cannot register a disposable on itself!");return this._isDisposed?cm.DISABLE_DISPOSED_WARNING||console.warn(new Error("Trying to add a disposable to a DisposableStore that has already been disposed of. The added object will be leaked!").stack):this._toDispose.add(e),e}delete(e){if(e){if(e===this)throw new Error("Cannot dispose a disposable on itself!");this._toDispose.delete(e),e.dispose()}}deleteAndLeak(e){e&&this._toDispose.has(e)&&(this._toDispose.delete(e),void 0)}};lm.DISABLE_DISPOSED_WARNING=!1;var ti=lm,Ve=class{constructor(){this._store=new ti,this._store}dispose(){this._store.dispose()}_register(t){if(t===this)throw new Error("Cannot register a disposable on itself!");return this._store.add(t)}};Ve.None=Object.freeze({dispose(){}});var zi=class{constructor(){this._isDisposed=!1}get value(){return this._isDisposed?void 0:this._value}set value(t){this._isDisposed||t===this._value||(this._value?.dispose(),this._value=t)}clear(){this.value=void 0}dispose(){this._isDisposed=!0,this._value?.dispose(),this._value=void 0}clearAndLeak(){let t=this._value;return this._value=void 0,t}},$s=typeof window=="object"?window:globalThis,Aa=class Ea{constructor(e){this.element=e,this.next=Ea.Undefined,this.prev=Ea.Undefined}};Aa.Undefined=new Aa(void 0);var We=Aa,Vd=class{constructor(){this._first=We.Undefined,this._last=We.Undefined,this._size=0}get size(){return this._size}isEmpty(){return this._first===We.Undefined}clear(){let t=this._first;for(;t!==We.Undefined;){let e=t.next;t.prev=We.Undefined,t.next=We.Undefined,t=e}this._first=We.Undefined,this._last=We.Undefined,this._size=0}unshift(t){return this._insert(t,!1)}push(t){return this._insert(t,!0)}_insert(t,e){let s=new We(t);if(this._first===We.Undefined)this._first=s,this._last=s;else if(e){let n=this._last;this._last=s,s.prev=n,n.next=s}else{let n=this._first;this._first=s,s.next=n,n.prev=s}this._size+=1;let i=!1;return()=>{i||(i=!0,this._remove(s))}}shift(){if(this._first!==We.Undefined){let t=this._first.element;return this._remove(this._first),t}}pop(){if(this._last!==We.Undefined){let t=this._last.element;return this._remove(this._last),t}}_remove(t){if(t.prev!==We.Undefined&&t.next!==We.Undefined){let e=t.prev;e.next=t.next,t.next.prev=e}else t.prev===We.Undefined&&t.next===We.Undefined?(this._first=We.Undefined,this._last=We.Undefined):t.next===We.Undefined?(this._last=this._last.prev,this._last.next=We.Undefined):t.prev===We.Undefined&&(this._first=this._first.next,this._first.prev=We.Undefined);this._size-=1}*[Symbol.iterator](){let t=this._first;for(;t!==We.Undefined;)yield t.element,t=t.next}},fC=globalThis.performance&&typeof globalThis.performance.now=="function",mC=class dm{static create(e){return new dm(e)}constructor(e){this._now=fC&&e===!1?Date.now:globalThis.performance.now.bind(globalThis.performance),this._startTime=this._now(),this._stopTime=-1}stop(){this._stopTime=this._now()}reset(){this._startTime=this._now(),this._stopTime=-1}elapsed(){return this._stopTime!==-1?this._stopTime-this._startTime:this._now()-this._startTime}},yt;(t=>{t.None=()=>Ve.None;function e(A,N){return h(A,()=>{},0,void 0,!0,void 0,N)}t.defer=e;function s(A){return(N,E=null,R)=>{let M=!1,L;return L=A(D=>{if(!M)return L?L.dispose():M=!0,N.call(E,D)},null,R),M&&L.dispose(),L}}t.once=s;function i(A,N,E){return d((R,M=null,L)=>A(D=>R.call(M,N(D)),null,L),E)}t.map=i;function n(A,N,E){return d((R,M=null,L)=>A(D=>{N(D),R.call(M,D)},null,L),E)}t.forEach=n;function o(A,N,E){return d((R,M=null,L)=>A(D=>N(D)&&R.call(M,D),null,L),E)}t.filter=o;function a(A){return A}t.signal=a;function l(...A){return(N,E=null,R)=>{let M=uC(...A.map(L=>L(D=>N.call(E,D))));return u(M,R)}}t.any=l;function c(A,N,E,R){let M=E;return i(A,L=>(M=N(M,L),M),R)}t.reduce=c;function d(A,N){let E,R={onWillAddFirstListener(){E=A(M.fire,M)},onDidRemoveLastListener(){E?.dispose()}},M=new re(R);return N?.add(M),M.event}function u(A,N){return N instanceof Array?N.push(A):N&&N.add(A),A}function h(A,N,E=100,R=!1,M=!1,L,D){let P,O,z,$=0,W,F={leakWarningThreshold:L,onWillAddFirstListener(){P=A(q=>{$++,O=N(O,q),R&&!z&&(G.fire(O),O=void 0),W=()=>{let H=O;O=void 0,z=void 0,(!R||$>1)&&G.fire(H),$=0},typeof E=="number"?(clearTimeout(z),z=setTimeout(W,E)):z===void 0&&(z=0,queueMicrotask(W))})},onWillRemoveListener(){M&&$>0&&W?.()},onDidRemoveLastListener(){W=void 0,P.dispose()}},G=new re(F);return D?.add(G),G.event}t.debounce=h;function f(A,N=0,E){return t.debounce(A,(R,M)=>R?(R.push(M),R):[M],N,void 0,!0,void 0,E)}t.accumulate=f;function m(A,N=(R,M)=>R===M,E){let R=!0,M;return o(A,L=>{let D=R||!N(L,M);return R=!1,M=L,D},E)}t.latch=m;function p(A,N,E){return[t.filter(A,N,E),t.filter(A,R=>!N(R),E)]}t.split=p;function g(A,N=!1,E=[],R){let M=E.slice(),L=A(O=>{M?M.push(O):P.fire(O)});R&&R.add(L);let D=()=>{M?.forEach(O=>P.fire(O)),M=null},P=new re({onWillAddFirstListener(){L||(L=A(O=>P.fire(O)),R&&R.add(L))},onDidAddFirstListener(){M&&(N?setTimeout(D):D())},onDidRemoveLastListener(){L&&L.dispose(),L=null}});return R&&R.add(P),P.event}t.buffer=g;function _(A,N){return(E,R,M)=>{let L=N(new x);return A(function(D){let P=L.evaluate(D);P!==v&&E.call(R,P)},void 0,M)}}t.chain=_;let v=Symbol("HaltChainable");class x{constructor(){this.steps=[]}map(N){return this.steps.push(N),this}forEach(N){return this.steps.push(E=>(N(E),E)),this}filter(N){return this.steps.push(E=>N(E)?E:v),this}reduce(N,E){let R=E;return this.steps.push(M=>(R=N(R,M),R)),this}latch(N=(E,R)=>E===R){let E=!0,R;return this.steps.push(M=>{let L=E||!N(M,R);return E=!1,R=M,L?M:v}),this}evaluate(N){for(let E of this.steps)if(N=E(N),N===v)break;return N}}function b(A,N,E=R=>R){let R=(...P)=>D.fire(E(...P)),M=()=>A.on(N,R),L=()=>A.removeListener(N,R),D=new re({onWillAddFirstListener:M,onDidRemoveLastListener:L});return D.event}t.fromNodeEventEmitter=b;function y(A,N,E=R=>R){let R=(...P)=>D.fire(E(...P)),M=()=>A.addEventListener(N,R),L=()=>A.removeEventListener(N,R),D=new re({onWillAddFirstListener:M,onDidRemoveLastListener:L});return D.event}t.fromDOMEventEmitter=y;function C(A){return new Promise(N=>s(A)(N))}t.toPromise=C;function j(A){let N=new re;return A.then(E=>{N.fire(E)},()=>{N.fire(void 0)}).finally(()=>{N.dispose()}),N.event}t.fromPromise=j;function V(A,N){return A(E=>N.fire(E))}t.forward=V;function w(A,N,E){return N(E),A(R=>N(R))}t.runAndSubscribe=w;class k{constructor(N,E){this._observable=N,this._counter=0,this._hasChanged=!1;let R={onWillAddFirstListener:()=>{N.addObserver(this)},onDidRemoveLastListener:()=>{N.removeObserver(this)}};this.emitter=new re(R),E&&E.add(this.emitter)}beginUpdate(N){this._counter++}handlePossibleChange(N){}handleChange(N,E){this._hasChanged=!0}endUpdate(N){this._counter--,this._counter===0&&(this._observable.reportChanges(),this._hasChanged&&(this._hasChanged=!1,this.emitter.fire(this._observable.get())))}}function T(A,N){return new k(A,N).emitter.event}t.fromObservable=T;function I(A){return(N,E,R)=>{let M=0,L=!1,D={beginUpdate(){M++},endUpdate(){M--,M===0&&(A.reportChanges(),L&&(L=!1,N.call(E)))},handlePossibleChange(){},handleChange(){L=!0}};A.addObserver(D),A.reportChanges();let P={dispose(){A.removeObserver(D)}};return R instanceof ti?R.add(P):Array.isArray(R)&&R.push(P),P}}t.fromObservableLight=I})(yt||={});var Ia=class Ra{constructor(e){this.listenerCount=0,this.invocationCount=0,this.elapsedOverall=0,this.durations=[],this.name=`${e}_${Ra._idPool++}`,Ra.all.add(this)}start(e){this._stopWatch=new mC,this.listenerCount=e}stop(){if(this._stopWatch){let e=this._stopWatch.elapsed();this.durations.push(e),this.elapsedOverall+=e,this.invocationCount+=1,this._stopWatch=void 0}}};Ia.all=new Set,Ia._idPool=0;var pC=Ia,gC=-1,hm=class um{constructor(e,s,i=(um._idPool++).toString(16).padStart(3,"0")){this._errorHandler=e,this.threshold=s,this.name=i,this._warnCountdown=0}dispose(){this._stacks?.clear()}check(e,s){let i=this.threshold;if(i<=0||s<i)return;this._stacks||(this._stacks=new Map);let n=this._stacks.get(e.value)||0;if(this._stacks.set(e.value,n+1),this._warnCountdown-=1,this._warnCountdown<=0){this._warnCountdown=i*.5;let[o,a]=this.getMostFrequentStack(),l=`[${this.name}] potential listener LEAK detected, having ${s} listeners already. MOST frequent listener (${a}):`;console.warn(l),console.warn(o);let c=new vC(l,o);this._errorHandler(c)}return()=>{let o=this._stacks.get(e.value)||0;this._stacks.set(e.value,o-1)}}getMostFrequentStack(){if(!this._stacks)return;let e,s=0;for(let[i,n]of this._stacks)(!e||s<n)&&(e=[i,n],s=n);return e}};hm._idPool=1;var _C=hm,xC=class fm{constructor(e){this.value=e}static create(){let e=new Error;return new fm(e.stack??"")}print(){console.warn(this.value.split(`
434
+ `+t.stack):t},0)}}addListener(t){return this.listeners.push(t),()=>{this._removeListener(t)}}emit(t){this.listeners.forEach(e=>{e(t)})}_removeListener(t){this.listeners.splice(this.listeners.indexOf(t),1)}setUnexpectedErrorHandler(t){this.unexpectedErrorHandler=t}getUnexpectedErrorHandler(){return this.unexpectedErrorHandler}onUnexpectedError(t){this.unexpectedErrorHandler(t),this.emit(t)}onUnexpectedExternalError(t){this.unexpectedErrorHandler(t)}},cC=new lC;function An(t){dC(t)||cC.onUnexpectedError(t)}var ja="Canceled";function dC(t){return t instanceof hC?!0:t instanceof Error&&t.name===ja&&t.message===ja}var hC=class extends Error{constructor(){super(ja),this.name=this.message}};function uC(t){return new Error(`Illegal argument: ${t}`)}var wd=class ka extends Error{constructor(e){super(e),this.name="CodeExpectedError"}static fromError(e){if(e instanceof ka)return e;let s=new ka;return s.message=e.message,s.stack=e.stack,s}static isErrorNoTelemetry(e){return e.name==="CodeExpectedError"}},Na=class am extends Error{constructor(e){super(e||"An unexpected bug occurred."),Object.setPrototypeOf(this,am.prototype)}};function Gt(t,e=0){return t[t.length-(1+e)]}var fC;(t=>{function e(o){return o<0}t.isLessThan=e;function s(o){return o<=0}t.isLessThanOrEqual=s;function i(o){return o>0}t.isGreaterThan=i;function n(o){return o===0}t.isNeitherLessOrGreaterThan=n,t.greaterThan=1,t.lessThan=-1,t.neitherLessOrGreaterThan=0})(fC||={});function mC(t,e){let s=this,i=!1,n;return function(){return i||(i=!0,e||(n=t.apply(s,arguments))),n}}var lm;(t=>{function e(y){return y&&typeof y=="object"&&typeof y[Symbol.iterator]=="function"}t.is=e;let s=Object.freeze([]);function i(){return s}t.empty=i;function*n(y){yield y}t.single=n;function o(y){return e(y)?y:n(y)}t.wrap=o;function a(y){return y||s}t.from=a;function*l(y){for(let C=y.length-1;C>=0;C--)yield y[C]}t.reverse=l;function c(y){return!y||y[Symbol.iterator]().next().done===!0}t.isEmpty=c;function d(y){return y[Symbol.iterator]().next().value}t.first=d;function u(y,C){let j=0;for(let V of y)if(C(V,j++))return!0;return!1}t.some=u;function h(y,C){for(let j of y)if(C(j))return j}t.find=h;function*f(y,C){for(let j of y)C(j)&&(yield j)}t.filter=f;function*m(y,C){let j=0;for(let V of y)yield C(V,j++)}t.map=m;function*p(y,C){let j=0;for(let V of y)yield*C(V,j++)}t.flatMap=p;function*g(...y){for(let C of y)yield*C}t.concat=g;function _(y,C,j){let V=j;for(let w of y)V=C(V,w);return V}t.reduce=_;function*v(y,C,j=y.length){for(C<0&&(C+=y.length),j<0?j+=y.length:j>y.length&&(j=y.length);C<j;C++)yield y[C]}t.slice=v;function x(y,C=Number.POSITIVE_INFINITY){let j=[];if(C===0)return[j,y];let V=y[Symbol.iterator]();for(let w=0;w<C;w++){let k=V.next();if(k.done)return[j,t.empty()];j.push(k.value)}return[j,{[Symbol.iterator](){return V}}]}t.consume=x;async function b(y){let C=[];for await(let j of y)C.push(j);return Promise.resolve(C)}t.asyncToArray=b})(lm||={});function _i(t){if(lm.is(t)){let e=[];for(let s of t)if(s)try{s.dispose()}catch(i){e.push(i)}if(e.length===1)throw e[0];if(e.length>1)throw new AggregateError(e,"Encountered errors while disposing of store");return Array.isArray(t)?[]:t}else if(t)return t.dispose(),t}function pC(...t){return Fe(()=>_i(t))}function Fe(t){return{dispose:mC(()=>{t()})}}var cm=class dm{constructor(){this._toDispose=new Set,this._isDisposed=!1}dispose(){this._isDisposed||(this._isDisposed=!0,this.clear())}get isDisposed(){return this._isDisposed}clear(){if(this._toDispose.size!==0)try{_i(this._toDispose)}finally{this._toDispose.clear()}}add(e){if(!e)return e;if(e===this)throw new Error("Cannot register a disposable on itself!");return this._isDisposed?dm.DISABLE_DISPOSED_WARNING||console.warn(new Error("Trying to add a disposable to a DisposableStore that has already been disposed of. The added object will be leaked!").stack):this._toDispose.add(e),e}delete(e){if(e){if(e===this)throw new Error("Cannot dispose a disposable on itself!");this._toDispose.delete(e),e.dispose()}}deleteAndLeak(e){e&&this._toDispose.has(e)&&(this._toDispose.delete(e),void 0)}};cm.DISABLE_DISPOSED_WARNING=!1;var ti=cm,Ve=class{constructor(){this._store=new ti,this._store}dispose(){this._store.dispose()}_register(t){if(t===this)throw new Error("Cannot register a disposable on itself!");return this._store.add(t)}};Ve.None=Object.freeze({dispose(){}});var zi=class{constructor(){this._isDisposed=!1}get value(){return this._isDisposed?void 0:this._value}set value(t){this._isDisposed||t===this._value||(this._value?.dispose(),this._value=t)}clear(){this.value=void 0}dispose(){this._isDisposed=!0,this._value?.dispose(),this._value=void 0}clearAndLeak(){let t=this._value;return this._value=void 0,t}},$s=typeof window=="object"?window:globalThis,Aa=class Ea{constructor(e){this.element=e,this.next=Ea.Undefined,this.prev=Ea.Undefined}};Aa.Undefined=new Aa(void 0);var We=Aa,Vd=class{constructor(){this._first=We.Undefined,this._last=We.Undefined,this._size=0}get size(){return this._size}isEmpty(){return this._first===We.Undefined}clear(){let t=this._first;for(;t!==We.Undefined;){let e=t.next;t.prev=We.Undefined,t.next=We.Undefined,t=e}this._first=We.Undefined,this._last=We.Undefined,this._size=0}unshift(t){return this._insert(t,!1)}push(t){return this._insert(t,!0)}_insert(t,e){let s=new We(t);if(this._first===We.Undefined)this._first=s,this._last=s;else if(e){let n=this._last;this._last=s,s.prev=n,n.next=s}else{let n=this._first;this._first=s,s.next=n,n.prev=s}this._size+=1;let i=!1;return()=>{i||(i=!0,this._remove(s))}}shift(){if(this._first!==We.Undefined){let t=this._first.element;return this._remove(this._first),t}}pop(){if(this._last!==We.Undefined){let t=this._last.element;return this._remove(this._last),t}}_remove(t){if(t.prev!==We.Undefined&&t.next!==We.Undefined){let e=t.prev;e.next=t.next,t.next.prev=e}else t.prev===We.Undefined&&t.next===We.Undefined?(this._first=We.Undefined,this._last=We.Undefined):t.next===We.Undefined?(this._last=this._last.prev,this._last.next=We.Undefined):t.prev===We.Undefined&&(this._first=this._first.next,this._first.prev=We.Undefined);this._size-=1}*[Symbol.iterator](){let t=this._first;for(;t!==We.Undefined;)yield t.element,t=t.next}},gC=globalThis.performance&&typeof globalThis.performance.now=="function",_C=class hm{static create(e){return new hm(e)}constructor(e){this._now=gC&&e===!1?Date.now:globalThis.performance.now.bind(globalThis.performance),this._startTime=this._now(),this._stopTime=-1}stop(){this._stopTime=this._now()}reset(){this._startTime=this._now(),this._stopTime=-1}elapsed(){return this._stopTime!==-1?this._stopTime-this._startTime:this._now()-this._startTime}},yt;(t=>{t.None=()=>Ve.None;function e(A,N){return h(A,()=>{},0,void 0,!0,void 0,N)}t.defer=e;function s(A){return(N,E=null,R)=>{let M=!1,L;return L=A(D=>{if(!M)return L?L.dispose():M=!0,N.call(E,D)},null,R),M&&L.dispose(),L}}t.once=s;function i(A,N,E){return d((R,M=null,L)=>A(D=>R.call(M,N(D)),null,L),E)}t.map=i;function n(A,N,E){return d((R,M=null,L)=>A(D=>{N(D),R.call(M,D)},null,L),E)}t.forEach=n;function o(A,N,E){return d((R,M=null,L)=>A(D=>N(D)&&R.call(M,D),null,L),E)}t.filter=o;function a(A){return A}t.signal=a;function l(...A){return(N,E=null,R)=>{let M=pC(...A.map(L=>L(D=>N.call(E,D))));return u(M,R)}}t.any=l;function c(A,N,E,R){let M=E;return i(A,L=>(M=N(M,L),M),R)}t.reduce=c;function d(A,N){let E,R={onWillAddFirstListener(){E=A(M.fire,M)},onDidRemoveLastListener(){E?.dispose()}},M=new re(R);return N?.add(M),M.event}function u(A,N){return N instanceof Array?N.push(A):N&&N.add(A),A}function h(A,N,E=100,R=!1,M=!1,L,D){let P,O,z,$=0,W,F={leakWarningThreshold:L,onWillAddFirstListener(){P=A(q=>{$++,O=N(O,q),R&&!z&&(G.fire(O),O=void 0),W=()=>{let H=O;O=void 0,z=void 0,(!R||$>1)&&G.fire(H),$=0},typeof E=="number"?(clearTimeout(z),z=setTimeout(W,E)):z===void 0&&(z=0,queueMicrotask(W))})},onWillRemoveListener(){M&&$>0&&W?.()},onDidRemoveLastListener(){W=void 0,P.dispose()}},G=new re(F);return D?.add(G),G.event}t.debounce=h;function f(A,N=0,E){return t.debounce(A,(R,M)=>R?(R.push(M),R):[M],N,void 0,!0,void 0,E)}t.accumulate=f;function m(A,N=(R,M)=>R===M,E){let R=!0,M;return o(A,L=>{let D=R||!N(L,M);return R=!1,M=L,D},E)}t.latch=m;function p(A,N,E){return[t.filter(A,N,E),t.filter(A,R=>!N(R),E)]}t.split=p;function g(A,N=!1,E=[],R){let M=E.slice(),L=A(O=>{M?M.push(O):P.fire(O)});R&&R.add(L);let D=()=>{M?.forEach(O=>P.fire(O)),M=null},P=new re({onWillAddFirstListener(){L||(L=A(O=>P.fire(O)),R&&R.add(L))},onDidAddFirstListener(){M&&(N?setTimeout(D):D())},onDidRemoveLastListener(){L&&L.dispose(),L=null}});return R&&R.add(P),P.event}t.buffer=g;function _(A,N){return(E,R,M)=>{let L=N(new x);return A(function(D){let P=L.evaluate(D);P!==v&&E.call(R,P)},void 0,M)}}t.chain=_;let v=Symbol("HaltChainable");class x{constructor(){this.steps=[]}map(N){return this.steps.push(N),this}forEach(N){return this.steps.push(E=>(N(E),E)),this}filter(N){return this.steps.push(E=>N(E)?E:v),this}reduce(N,E){let R=E;return this.steps.push(M=>(R=N(R,M),R)),this}latch(N=(E,R)=>E===R){let E=!0,R;return this.steps.push(M=>{let L=E||!N(M,R);return E=!1,R=M,L?M:v}),this}evaluate(N){for(let E of this.steps)if(N=E(N),N===v)break;return N}}function b(A,N,E=R=>R){let R=(...P)=>D.fire(E(...P)),M=()=>A.on(N,R),L=()=>A.removeListener(N,R),D=new re({onWillAddFirstListener:M,onDidRemoveLastListener:L});return D.event}t.fromNodeEventEmitter=b;function y(A,N,E=R=>R){let R=(...P)=>D.fire(E(...P)),M=()=>A.addEventListener(N,R),L=()=>A.removeEventListener(N,R),D=new re({onWillAddFirstListener:M,onDidRemoveLastListener:L});return D.event}t.fromDOMEventEmitter=y;function C(A){return new Promise(N=>s(A)(N))}t.toPromise=C;function j(A){let N=new re;return A.then(E=>{N.fire(E)},()=>{N.fire(void 0)}).finally(()=>{N.dispose()}),N.event}t.fromPromise=j;function V(A,N){return A(E=>N.fire(E))}t.forward=V;function w(A,N,E){return N(E),A(R=>N(R))}t.runAndSubscribe=w;class k{constructor(N,E){this._observable=N,this._counter=0,this._hasChanged=!1;let R={onWillAddFirstListener:()=>{N.addObserver(this)},onDidRemoveLastListener:()=>{N.removeObserver(this)}};this.emitter=new re(R),E&&E.add(this.emitter)}beginUpdate(N){this._counter++}handlePossibleChange(N){}handleChange(N,E){this._hasChanged=!0}endUpdate(N){this._counter--,this._counter===0&&(this._observable.reportChanges(),this._hasChanged&&(this._hasChanged=!1,this.emitter.fire(this._observable.get())))}}function T(A,N){return new k(A,N).emitter.event}t.fromObservable=T;function I(A){return(N,E,R)=>{let M=0,L=!1,D={beginUpdate(){M++},endUpdate(){M--,M===0&&(A.reportChanges(),L&&(L=!1,N.call(E)))},handlePossibleChange(){},handleChange(){L=!0}};A.addObserver(D),A.reportChanges();let P={dispose(){A.removeObserver(D)}};return R instanceof ti?R.add(P):Array.isArray(R)&&R.push(P),P}}t.fromObservableLight=I})(yt||={});var Ia=class Ra{constructor(e){this.listenerCount=0,this.invocationCount=0,this.elapsedOverall=0,this.durations=[],this.name=`${e}_${Ra._idPool++}`,Ra.all.add(this)}start(e){this._stopWatch=new _C,this.listenerCount=e}stop(){if(this._stopWatch){let e=this._stopWatch.elapsed();this.durations.push(e),this.elapsedOverall+=e,this.invocationCount+=1,this._stopWatch=void 0}}};Ia.all=new Set,Ia._idPool=0;var xC=Ia,vC=-1,um=class fm{constructor(e,s,i=(fm._idPool++).toString(16).padStart(3,"0")){this._errorHandler=e,this.threshold=s,this.name=i,this._warnCountdown=0}dispose(){this._stacks?.clear()}check(e,s){let i=this.threshold;if(i<=0||s<i)return;this._stacks||(this._stacks=new Map);let n=this._stacks.get(e.value)||0;if(this._stacks.set(e.value,n+1),this._warnCountdown-=1,this._warnCountdown<=0){this._warnCountdown=i*.5;let[o,a]=this.getMostFrequentStack(),l=`[${this.name}] potential listener LEAK detected, having ${s} listeners already. MOST frequent listener (${a}):`;console.warn(l),console.warn(o);let c=new SC(l,o);this._errorHandler(c)}return()=>{let o=this._stacks.get(e.value)||0;this._stacks.set(e.value,o-1)}}getMostFrequentStack(){if(!this._stacks)return;let e,s=0;for(let[i,n]of this._stacks)(!e||s<n)&&(e=[i,n],s=n);return e}};um._idPool=1;var bC=um,yC=class mm{constructor(e){this.value=e}static create(){let e=new Error;return new mm(e.stack??"")}print(){console.warn(this.value.split(`
435
435
  `).slice(2).join(`
436
- `))}},vC=class extends Error{constructor(t,e){super(t),this.name="ListenerLeakError",this.stack=e}},bC=class extends Error{constructor(t,e){super(t),this.name="ListenerRefusalError",this.stack=e}},yC=0,Ho=class{constructor(t){this.value=t,this.id=yC++}},SC=2,wC,re=class{constructor(t){this._size=0,this._options=t,this._leakageMon=this._options?.leakWarningThreshold?new _C(t?.onListenerError??An,this._options?.leakWarningThreshold??gC):void 0,this._perfMon=this._options?._profName?new pC(this._options._profName):void 0,this._deliveryQueue=this._options?.deliveryQueue}dispose(){this._disposed||(this._disposed=!0,this._deliveryQueue?.current===this&&this._deliveryQueue.reset(),this._listeners&&(this._listeners=void 0,this._size=0),this._options?.onDidRemoveLastListener?.(),this._leakageMon?.dispose())}get event(){return this._event??=(t,e,s)=>{if(this._leakageMon&&this._size>this._leakageMon.threshold**2){let a=`[${this._leakageMon.name}] REFUSES to accept new listeners because it exceeded its threshold by far (${this._size} vs ${this._leakageMon.threshold})`;console.warn(a);let l=this._leakageMon.getMostFrequentStack()??["UNKNOWN stack",-1],c=new bC(`${a}. HINT: Stack shows most frequent listener (${l[1]}-times)`,l[0]);return(this._options?.onListenerError||An)(c),Ve.None}if(this._disposed)return Ve.None;e&&(t=t.bind(e));let i=new Ho(t),n;this._leakageMon&&this._size>=Math.ceil(this._leakageMon.threshold*.2)&&(i.stack=xC.create(),n=this._leakageMon.check(i.stack,this._size+1)),this._listeners?this._listeners instanceof Ho?(this._deliveryQueue??=new VC,this._listeners=[this._listeners,i]):this._listeners.push(i):(this._options?.onWillAddFirstListener?.(this),this._listeners=i,this._options?.onDidAddFirstListener?.(this)),this._size++;let o=Fe(()=>{n?.(),this._removeListener(i)});return s instanceof ti?s.add(o):Array.isArray(s)&&s.push(o),o},this._event}_removeListener(t){if(this._options?.onWillRemoveListener?.(this),!this._listeners)return;if(this._size===1){this._listeners=void 0,this._options?.onDidRemoveLastListener?.(this),this._size=0;return}let e=this._listeners,s=e.indexOf(t);if(s===-1)throw console.log("disposed?",this._disposed),console.log("size?",this._size),console.log("arr?",JSON.stringify(this._listeners)),new Error("Attempted to dispose unknown listener");this._size--,e[s]=void 0;let i=this._deliveryQueue.current===this;if(this._size*SC<=e.length){let n=0;for(let o=0;o<e.length;o++)e[o]?e[n++]=e[o]:i&&(this._deliveryQueue.end--,n<this._deliveryQueue.i&&this._deliveryQueue.i--);e.length=n}}_deliver(t,e){if(!t)return;let s=this._options?.onListenerError||An;if(!s){t.value(e);return}try{t.value(e)}catch(i){s(i)}}_deliverQueue(t){let e=t.current._listeners;for(;t.i<t.end;)this._deliver(e[t.i++],t.value);t.reset()}fire(t){if(this._deliveryQueue?.current&&(this._deliverQueue(this._deliveryQueue),this._perfMon?.stop()),this._perfMon?.start(this._size),this._listeners)if(this._listeners instanceof Ho)this._deliver(this._listeners,t);else{let e=this._deliveryQueue;e.enqueue(this,t,this._listeners.length),this._deliverQueue(e)}this._perfMon?.stop()}hasListeners(){return this._size>0}},VC=class{constructor(){this.i=-1,this.end=0}enqueue(t,e,s){this.i=0,this.end=s,this.current=t,this.value=e}reset(){this.i=this.end,this.current=void 0,this.value=void 0}},Ta=class{constructor(){this.mapWindowIdToZoomLevel=new Map,this._onDidChangeZoomLevel=new re,this.onDidChangeZoomLevel=this._onDidChangeZoomLevel.event,this.mapWindowIdToZoomFactor=new Map,this._onDidChangeFullscreen=new re,this.onDidChangeFullscreen=this._onDidChangeFullscreen.event,this.mapWindowIdToFullScreen=new Map}getZoomLevel(e){return this.mapWindowIdToZoomLevel.get(this.getWindowId(e))??0}setZoomLevel(e,s){if(this.getZoomLevel(s)===e)return;let i=this.getWindowId(s);this.mapWindowIdToZoomLevel.set(i,e),this._onDidChangeZoomLevel.fire(i)}getZoomFactor(e){return this.mapWindowIdToZoomFactor.get(this.getWindowId(e))??1}setZoomFactor(e,s){this.mapWindowIdToZoomFactor.set(this.getWindowId(s),e)}setFullscreen(e,s){if(this.isFullscreen(s)===e)return;let i=this.getWindowId(s);this.mapWindowIdToFullScreen.set(i,e),this._onDidChangeFullscreen.fire(i)}isFullscreen(e){return!!this.mapWindowIdToFullScreen.get(this.getWindowId(e))}getWindowId(e){return e.vscodeWindowId}};Ta.INSTANCE=new Ta;var Zl=Ta;function CC(t,e,s){typeof e=="string"&&(e=t.matchMedia(e)),e.addEventListener("change",s)}Zl.INSTANCE.onDidChangeZoomLevel;function jC(t){return Zl.INSTANCE.getZoomFactor(t)}Zl.INSTANCE.onDidChangeFullscreen;var Ji=typeof navigator=="object"?navigator.userAgent:"",Da=Ji.indexOf("Firefox")>=0,kC=Ji.indexOf("AppleWebKit")>=0,ec=Ji.indexOf("Chrome")>=0,NC=!ec&&Ji.indexOf("Safari")>=0;Ji.indexOf("Electron/")>=0;Ji.indexOf("Android")>=0;var Wo=!1;if(typeof $s.matchMedia=="function"){let t=$s.matchMedia("(display-mode: standalone) or (display-mode: window-controls-overlay)"),e=$s.matchMedia("(display-mode: fullscreen)");Wo=t.matches,CC($s,t,({matches:s})=>{Wo&&e.matches||(Wo=s)})}var Ri="en",Ma=!1,Pa=!1,En=!1,mm=!1,fn,In=Ri,Cd=Ri,AC,Bs,gi=globalThis,Xt;typeof gi.vscode<"u"&&typeof gi.vscode.process<"u"?Xt=gi.vscode.process:typeof process<"u"&&typeof process?.versions?.node=="string"&&(Xt=process);var EC=typeof Xt?.versions?.electron=="string",IC=EC&&Xt?.type==="renderer";if(typeof Xt=="object"){Ma=Xt.platform==="win32",Pa=Xt.platform==="darwin",En=Xt.platform==="linux",En&&Xt.env.SNAP&&Xt.env.SNAP_REVISION,Xt.env.CI||Xt.env.BUILD_ARTIFACTSTAGINGDIRECTORY,fn=Ri,In=Ri;let t=Xt.env.VSCODE_NLS_CONFIG;if(t)try{let e=JSON.parse(t);fn=e.userLocale,Cd=e.osLocale,In=e.resolvedLanguage||Ri,AC=e.languagePack?.translationsConfigFile}catch{}mm=!0}else typeof navigator=="object"&&!IC?(Bs=navigator.userAgent,Ma=Bs.indexOf("Windows")>=0,Pa=Bs.indexOf("Macintosh")>=0,(Bs.indexOf("Macintosh")>=0||Bs.indexOf("iPad")>=0||Bs.indexOf("iPhone")>=0)&&navigator.maxTouchPoints&&navigator.maxTouchPoints>0,En=Bs.indexOf("Linux")>=0,Bs?.indexOf("Mobi")>=0,In=globalThis._VSCODE_NLS_LANGUAGE||Ri,fn=navigator.language.toLowerCase(),Cd=fn):console.error("Unable to resolve platform.");var pm=Ma,As=Pa,RC=En,jd=mm,Is=Bs,Us=In,TC;(t=>{function e(){return Us}t.value=e;function s(){return Us.length===2?Us==="en":Us.length>=3?Us[0]==="e"&&Us[1]==="n"&&Us[2]==="-":!1}t.isDefaultVariant=s;function i(){return Us==="en"}t.isDefault=i})(TC||={});var DC=typeof gi.postMessage=="function"&&!gi.importScripts;(()=>{if(DC){let t=[];gi.addEventListener("message",s=>{if(s.data&&s.data.vscodeScheduleAsyncWork)for(let i=0,n=t.length;i<n;i++){let o=t[i];if(o.id===s.data.vscodeScheduleAsyncWork){t.splice(i,1),o.callback();return}}});let e=0;return s=>{let i=++e;t.push({id:i,callback:s}),gi.postMessage({vscodeScheduleAsyncWork:i},"*")}}return t=>setTimeout(t)})();var MC=!!(Is&&Is.indexOf("Chrome")>=0);Is&&Is.indexOf("Firefox")>=0;!MC&&Is&&Is.indexOf("Safari")>=0;Is&&Is.indexOf("Edg/")>=0;Is&&Is.indexOf("Android")>=0;var ki=typeof navigator=="object"?navigator:{};jd||document.queryCommandSupported&&document.queryCommandSupported("copy")||ki&&ki.clipboard&&ki.clipboard.writeText,jd||ki&&ki.clipboard&&ki.clipboard.readText;var tc=class{constructor(){this._keyCodeToStr=[],this._strToKeyCode=Object.create(null)}define(t,e){this._keyCodeToStr[t]=e,this._strToKeyCode[e.toLowerCase()]=t}keyCodeToStr(t){return this._keyCodeToStr[t]}strToKeyCode(t){return this._strToKeyCode[t.toLowerCase()]||0}},Uo=new tc,kd=new tc,Nd=new tc,PC=new Array(230),gm;(t=>{function e(l){return Uo.keyCodeToStr(l)}t.toString=e;function s(l){return Uo.strToKeyCode(l)}t.fromString=s;function i(l){return kd.keyCodeToStr(l)}t.toUserSettingsUS=i;function n(l){return Nd.keyCodeToStr(l)}t.toUserSettingsGeneral=n;function o(l){return kd.strToKeyCode(l)||Nd.strToKeyCode(l)}t.fromUserSettings=o;function a(l){if(l>=98&&l<=113)return null;switch(l){case 16:return"Up";case 18:return"Down";case 15:return"Left";case 17:return"Right"}return Uo.keyCodeToStr(l)}t.toElectronAccelerator=a})(gm||={});var LC=class _m{constructor(e,s,i,n,o){this.ctrlKey=e,this.shiftKey=s,this.altKey=i,this.metaKey=n,this.keyCode=o}equals(e){return e instanceof _m&&this.ctrlKey===e.ctrlKey&&this.shiftKey===e.shiftKey&&this.altKey===e.altKey&&this.metaKey===e.metaKey&&this.keyCode===e.keyCode}getHashCode(){let e=this.ctrlKey?"1":"0",s=this.shiftKey?"1":"0",i=this.altKey?"1":"0",n=this.metaKey?"1":"0";return`K${e}${s}${i}${n}${this.keyCode}`}isModifierKey(){return this.keyCode===0||this.keyCode===5||this.keyCode===57||this.keyCode===6||this.keyCode===4}toKeybinding(){return new BC([this])}isDuplicateModifierCase(){return this.ctrlKey&&this.keyCode===5||this.shiftKey&&this.keyCode===4||this.altKey&&this.keyCode===6||this.metaKey&&this.keyCode===57}},BC=class{constructor(t){if(t.length===0)throw cC("chords");this.chords=t}getHashCode(){let t="";for(let e=0,s=this.chords.length;e<s;e++)e!==0&&(t+=";"),t+=this.chords[e].getHashCode();return t}equals(t){if(t===null||this.chords.length!==t.chords.length)return!1;for(let e=0;e<this.chords.length;e++)if(!this.chords[e].equals(t.chords[e]))return!1;return!0}};function OC(t){if(t.charCode){let s=String.fromCharCode(t.charCode).toUpperCase();return gm.fromString(s)}let e=t.keyCode;if(e===3)return 7;if(Da)switch(e){case 59:return 85;case 60:if(RC)return 97;break;case 61:return 86;case 107:return 109;case 109:return 111;case 173:return 88;case 224:if(As)return 57;break}else if(kC&&(As&&e===93||!As&&e===92))return 57;return PC[e]||0}var $C=As?256:2048,zC=512,FC=1024,HC=As?2048:256,Ad=class{constructor(t){this._standardKeyboardEventBrand=!0;let e=t;this.browserEvent=e,this.target=e.target,this.ctrlKey=e.ctrlKey,this.shiftKey=e.shiftKey,this.altKey=e.altKey,this.metaKey=e.metaKey,this.altGraphKey=e.getModifierState?.("AltGraph"),this.keyCode=OC(e),this.code=e.code,this.ctrlKey=this.ctrlKey||this.keyCode===5,this.altKey=this.altKey||this.keyCode===6,this.shiftKey=this.shiftKey||this.keyCode===4,this.metaKey=this.metaKey||this.keyCode===57,this._asKeybinding=this._computeKeybinding(),this._asKeyCodeChord=this._computeKeyCodeChord()}preventDefault(){this.browserEvent&&this.browserEvent.preventDefault&&this.browserEvent.preventDefault()}stopPropagation(){this.browserEvent&&this.browserEvent.stopPropagation&&this.browserEvent.stopPropagation()}toKeyCodeChord(){return this._asKeyCodeChord}equals(t){return this._asKeybinding===t}_computeKeybinding(){let t=0;this.keyCode!==5&&this.keyCode!==4&&this.keyCode!==6&&this.keyCode!==57&&(t=this.keyCode);let e=0;return this.ctrlKey&&(e|=$C),this.altKey&&(e|=zC),this.shiftKey&&(e|=FC),this.metaKey&&(e|=HC),e|=t,e}_computeKeyCodeChord(){let t=0;return this.keyCode!==5&&this.keyCode!==4&&this.keyCode!==6&&this.keyCode!==57&&(t=this.keyCode),new LC(this.ctrlKey,this.shiftKey,this.altKey,this.metaKey,t)}},Ed=new WeakMap;function WC(t){if(!t.parent||t.parent===t)return null;try{let e=t.location,s=t.parent.location;if(e.origin!=="null"&&s.origin!=="null"&&e.origin!==s.origin)return null}catch{return null}return t.parent}var UC=class{static getSameOriginWindowChain(t){let e=Ed.get(t);if(!e){e=[],Ed.set(t,e);let s=t,i;do i=WC(s),i?e.push({window:new WeakRef(s),iframeElement:s.frameElement||null}):e.push({window:new WeakRef(s),iframeElement:null}),s=i;while(s)}return e.slice(0)}static getPositionOfChildWindowRelativeToAncestorWindow(t,e){if(!e||t===e)return{top:0,left:0};let s=0,i=0,n=this.getSameOriginWindowChain(t);for(let o of n){let a=o.window.deref();if(s+=a?.scrollY??0,i+=a?.scrollX??0,a===e||!o.iframeElement)break;let l=o.iframeElement.getBoundingClientRect();s+=l.top,i+=l.left}return{top:s,left:i}}},mn=class{constructor(t,e){this.timestamp=Date.now(),this.browserEvent=e,this.leftButton=e.button===0,this.middleButton=e.button===1,this.rightButton=e.button===2,this.buttons=e.buttons,this.target=e.target,this.detail=e.detail||1,e.type==="dblclick"&&(this.detail=2),this.ctrlKey=e.ctrlKey,this.shiftKey=e.shiftKey,this.altKey=e.altKey,this.metaKey=e.metaKey,typeof e.pageX=="number"?(this.posx=e.pageX,this.posy=e.pageY):(this.posx=e.clientX+this.target.ownerDocument.body.scrollLeft+this.target.ownerDocument.documentElement.scrollLeft,this.posy=e.clientY+this.target.ownerDocument.body.scrollTop+this.target.ownerDocument.documentElement.scrollTop);let s=UC.getPositionOfChildWindowRelativeToAncestorWindow(t,e.view);this.posx-=s.left,this.posy-=s.top}preventDefault(){this.browserEvent.preventDefault()}stopPropagation(){this.browserEvent.stopPropagation()}},Id=class{constructor(t,e=0,s=0){this.browserEvent=t||null,this.target=t?t.target||t.targetNode||t.srcElement:null,this.deltaY=s,this.deltaX=e;let i=!1;if(ec){let n=navigator.userAgent.match(/Chrome\/(\d+)/);i=(n?parseInt(n[1]):123)<=122}if(t){let n=t,o=t,a=t.view?.devicePixelRatio||1;if(typeof n.wheelDeltaY<"u")i?this.deltaY=n.wheelDeltaY/(120*a):this.deltaY=n.wheelDeltaY/120;else if(typeof o.VERTICAL_AXIS<"u"&&o.axis===o.VERTICAL_AXIS)this.deltaY=-o.detail/3;else if(t.type==="wheel"){let l=t;l.deltaMode===l.DOM_DELTA_LINE?Da&&!As?this.deltaY=-t.deltaY/3:this.deltaY=-t.deltaY:this.deltaY=-t.deltaY/40}if(typeof n.wheelDeltaX<"u")NC&&pm?this.deltaX=-(n.wheelDeltaX/120):i?this.deltaX=n.wheelDeltaX/(120*a):this.deltaX=n.wheelDeltaX/120;else if(typeof o.HORIZONTAL_AXIS<"u"&&o.axis===o.HORIZONTAL_AXIS)this.deltaX=-t.detail/3;else if(t.type==="wheel"){let l=t;l.deltaMode===l.DOM_DELTA_LINE?Da&&!As?this.deltaX=-t.deltaX/3:this.deltaX=-t.deltaX:this.deltaX=-t.deltaX/40}this.deltaY===0&&this.deltaX===0&&t.wheelDelta&&(i?this.deltaY=t.wheelDelta/(120*a):this.deltaY=t.wheelDelta/120)}}preventDefault(){this.browserEvent?.preventDefault()}stopPropagation(){this.browserEvent?.stopPropagation()}},xm=Object.freeze(function(t,e){let s=setTimeout(t.bind(e),0);return{dispose(){clearTimeout(s)}}}),KC;(t=>{function e(s){return s===t.None||s===t.Cancelled||s instanceof qC?!0:!s||typeof s!="object"?!1:typeof s.isCancellationRequested=="boolean"&&typeof s.onCancellationRequested=="function"}t.isCancellationToken=e,t.None=Object.freeze({isCancellationRequested:!1,onCancellationRequested:yt.None}),t.Cancelled=Object.freeze({isCancellationRequested:!0,onCancellationRequested:xm})})(KC||={});var qC=class{constructor(){this._isCancelled=!1,this._emitter=null}cancel(){this._isCancelled||(this._isCancelled=!0,this._emitter&&(this._emitter.fire(void 0),this.dispose()))}get isCancellationRequested(){return this._isCancelled}get onCancellationRequested(){return this._isCancelled?xm:(this._emitter||(this._emitter=new re),this._emitter.event)}dispose(){this._emitter&&(this._emitter.dispose(),this._emitter=null)}},sc=class{constructor(t,e){this._isDisposed=!1,this._token=-1,typeof t=="function"&&typeof e=="number"&&this.setIfNotSet(t,e)}dispose(){this.cancel(),this._isDisposed=!0}cancel(){this._token!==-1&&(clearTimeout(this._token),this._token=-1)}cancelAndSet(t,e){if(this._isDisposed)throw new Na("Calling 'cancelAndSet' on a disposed TimeoutTimer");this.cancel(),this._token=setTimeout(()=>{this._token=-1,t()},e)}setIfNotSet(t,e){if(this._isDisposed)throw new Na("Calling 'setIfNotSet' on a disposed TimeoutTimer");this._token===-1&&(this._token=setTimeout(()=>{this._token=-1,t()},e))}},GC=class{constructor(){this.disposable=void 0,this.isDisposed=!1}cancel(){this.disposable?.dispose(),this.disposable=void 0}cancelAndSet(t,e,s=globalThis){if(this.isDisposed)throw new Na("Calling 'cancelAndSet' on a disposed IntervalTimer");this.cancel();let i=s.setInterval(()=>{t()},e);this.disposable=Fe(()=>{s.clearInterval(i),this.disposable=void 0})}dispose(){this.cancel(),this.isDisposed=!0}},YC;(t=>{async function e(i){let n,o=await Promise.all(i.map(a=>a.then(l=>l,l=>{n||(n=l)})));if(typeof n<"u")throw n;return o}t.settled=e;function s(i){return new Promise(async(n,o)=>{try{await i(n,o)}catch(a){o(a)}})}t.withAsyncBody=s})(YC||={});var Rd=class is{static fromArray(e){return new is(s=>{s.emitMany(e)})}static fromPromise(e){return new is(async s=>{s.emitMany(await e)})}static fromPromises(e){return new is(async s=>{await Promise.all(e.map(async i=>s.emitOne(await i)))})}static merge(e){return new is(async s=>{await Promise.all(e.map(async i=>{for await(let n of i)s.emitOne(n)}))})}constructor(e,s){this._state=0,this._results=[],this._error=null,this._onReturn=s,this._onStateChanged=new re,queueMicrotask(async()=>{let i={emitOne:n=>this.emitOne(n),emitMany:n=>this.emitMany(n),reject:n=>this.reject(n)};try{await Promise.resolve(e(i)),this.resolve()}catch(n){this.reject(n)}finally{i.emitOne=void 0,i.emitMany=void 0,i.reject=void 0}})}[Symbol.asyncIterator](){let e=0;return{next:async()=>{do{if(this._state===2)throw this._error;if(e<this._results.length)return{done:!1,value:this._results[e++]};if(this._state===1)return{done:!0,value:void 0};await yt.toPromise(this._onStateChanged.event)}while(!0)},return:async()=>(this._onReturn?.(),{done:!0,value:void 0})}}static map(e,s){return new is(async i=>{for await(let n of e)i.emitOne(s(n))})}map(e){return is.map(this,e)}static filter(e,s){return new is(async i=>{for await(let n of e)s(n)&&i.emitOne(n)})}filter(e){return is.filter(this,e)}static coalesce(e){return is.filter(e,s=>!!s)}coalesce(){return is.coalesce(this)}static async toPromise(e){let s=[];for await(let i of e)s.push(i);return s}toPromise(){return is.toPromise(this)}emitOne(e){this._state===0&&(this._results.push(e),this._onStateChanged.fire())}emitMany(e){this._state===0&&(this._results=this._results.concat(e),this._onStateChanged.fire())}resolve(){this._state===0&&(this._state=1,this._onStateChanged.fire())}reject(e){this._state===0&&(this._state=2,this._error=e,this._onStateChanged.fire())}};Rd.EMPTY=Rd.fromArray([]);var{getWindow:ws,getWindowId:XC,onDidRegisterWindow:JC}=(function(){let t=new Map,e={window:$s,disposables:new ti};t.set($s.vscodeWindowId,e);let s=new re,i=new re,n=new re;function o(a,l){return(typeof a=="number"?t.get(a):void 0)??(l?e:void 0)}return{onDidRegisterWindow:s.event,onWillUnregisterWindow:n.event,onDidUnregisterWindow:i.event,registerWindow(a){if(t.has(a.vscodeWindowId))return Ve.None;let l=new ti,c={window:a,disposables:l.add(new ti)};return t.set(a.vscodeWindowId,c),l.add(Fe(()=>{t.delete(a.vscodeWindowId),i.fire(a)})),l.add(ye(a,ht.BEFORE_UNLOAD,()=>{n.fire(a)})),s.fire(c),l},getWindows(){return t.values()},getWindowsCount(){return t.size},getWindowId(a){return a.vscodeWindowId},hasWindow(a){return t.has(a)},getWindowById:o,getWindow(a){let l=a;if(l?.ownerDocument?.defaultView)return l.ownerDocument.defaultView.window;let c=a;return c?.view?c.view.window:$s},getDocument(a){return ws(a).document}}})(),QC=class{constructor(t,e,s,i){this._node=t,this._type=e,this._handler=s,this._options=i||!1,this._node.addEventListener(this._type,this._handler,this._options)}dispose(){this._handler&&(this._node.removeEventListener(this._type,this._handler,this._options),this._node=null,this._handler=null)}};function ye(t,e,s,i){return new QC(t,e,s,i)}var Td=function(t,e,s,i){return ye(t,e,s,i)},ic,ZC=class extends GC{constructor(t){super(),this.defaultTarget=t&&ws(t)}cancelAndSet(t,e,s){return super.cancelAndSet(t,e,s??this.defaultTarget)}},Dd=class{constructor(t,e=0){this._runner=t,this.priority=e,this._canceled=!1}dispose(){this._canceled=!0}execute(){if(!this._canceled)try{this._runner()}catch(t){An(t)}}static sort(t,e){return e.priority-t.priority}};(function(){let t=new Map,e=new Map,s=new Map,i=new Map,n=o=>{s.set(o,!1);let a=t.get(o)??[];for(e.set(o,a),t.set(o,[]),i.set(o,!0);a.length>0;)a.sort(Dd.sort),a.shift().execute();i.set(o,!1)};ic=(o,a,l=0)=>{let c=XC(o),d=new Dd(a,l),u=t.get(c);return u||(u=[],t.set(c,u)),u.push(d),s.get(c)||(s.set(c,!0),o.requestAnimationFrame(()=>n(c))),d}})();function e3(t){let e=t.getBoundingClientRect(),s=ws(t);return{left:e.left+s.scrollX,top:e.top+s.scrollY,width:e.width,height:e.height}}var ht={CLICK:"click",MOUSE_DOWN:"mousedown",MOUSE_OVER:"mouseover",MOUSE_LEAVE:"mouseleave",MOUSE_WHEEL:"wheel",POINTER_UP:"pointerup",POINTER_DOWN:"pointerdown",POINTER_MOVE:"pointermove",KEY_DOWN:"keydown",KEY_UP:"keyup",BEFORE_UNLOAD:"beforeunload",CHANGE:"change",FOCUS:"focus",BLUR:"blur",INPUT:"input"},t3=class{constructor(t){this.domNode=t,this._maxWidth="",this._width="",this._height="",this._top="",this._left="",this._bottom="",this._right="",this._paddingTop="",this._paddingLeft="",this._paddingBottom="",this._paddingRight="",this._fontFamily="",this._fontWeight="",this._fontSize="",this._fontStyle="",this._fontFeatureSettings="",this._fontVariationSettings="",this._textDecoration="",this._lineHeight="",this._letterSpacing="",this._className="",this._display="",this._position="",this._visibility="",this._color="",this._backgroundColor="",this._layerHint=!1,this._contain="none",this._boxShadow=""}setMaxWidth(t){let e=zt(t);this._maxWidth!==e&&(this._maxWidth=e,this.domNode.style.maxWidth=this._maxWidth)}setWidth(t){let e=zt(t);this._width!==e&&(this._width=e,this.domNode.style.width=this._width)}setHeight(t){let e=zt(t);this._height!==e&&(this._height=e,this.domNode.style.height=this._height)}setTop(t){let e=zt(t);this._top!==e&&(this._top=e,this.domNode.style.top=this._top)}setLeft(t){let e=zt(t);this._left!==e&&(this._left=e,this.domNode.style.left=this._left)}setBottom(t){let e=zt(t);this._bottom!==e&&(this._bottom=e,this.domNode.style.bottom=this._bottom)}setRight(t){let e=zt(t);this._right!==e&&(this._right=e,this.domNode.style.right=this._right)}setPaddingTop(t){let e=zt(t);this._paddingTop!==e&&(this._paddingTop=e,this.domNode.style.paddingTop=this._paddingTop)}setPaddingLeft(t){let e=zt(t);this._paddingLeft!==e&&(this._paddingLeft=e,this.domNode.style.paddingLeft=this._paddingLeft)}setPaddingBottom(t){let e=zt(t);this._paddingBottom!==e&&(this._paddingBottom=e,this.domNode.style.paddingBottom=this._paddingBottom)}setPaddingRight(t){let e=zt(t);this._paddingRight!==e&&(this._paddingRight=e,this.domNode.style.paddingRight=this._paddingRight)}setFontFamily(t){this._fontFamily!==t&&(this._fontFamily=t,this.domNode.style.fontFamily=this._fontFamily)}setFontWeight(t){this._fontWeight!==t&&(this._fontWeight=t,this.domNode.style.fontWeight=this._fontWeight)}setFontSize(t){let e=zt(t);this._fontSize!==e&&(this._fontSize=e,this.domNode.style.fontSize=this._fontSize)}setFontStyle(t){this._fontStyle!==t&&(this._fontStyle=t,this.domNode.style.fontStyle=this._fontStyle)}setFontFeatureSettings(t){this._fontFeatureSettings!==t&&(this._fontFeatureSettings=t,this.domNode.style.fontFeatureSettings=this._fontFeatureSettings)}setFontVariationSettings(t){this._fontVariationSettings!==t&&(this._fontVariationSettings=t,this.domNode.style.fontVariationSettings=this._fontVariationSettings)}setTextDecoration(t){this._textDecoration!==t&&(this._textDecoration=t,this.domNode.style.textDecoration=this._textDecoration)}setLineHeight(t){let e=zt(t);this._lineHeight!==e&&(this._lineHeight=e,this.domNode.style.lineHeight=this._lineHeight)}setLetterSpacing(t){let e=zt(t);this._letterSpacing!==e&&(this._letterSpacing=e,this.domNode.style.letterSpacing=this._letterSpacing)}setClassName(t){this._className!==t&&(this._className=t,this.domNode.className=this._className)}toggleClassName(t,e){this.domNode.classList.toggle(t,e),this._className=this.domNode.className}setDisplay(t){this._display!==t&&(this._display=t,this.domNode.style.display=this._display)}setPosition(t){this._position!==t&&(this._position=t,this.domNode.style.position=this._position)}setVisibility(t){this._visibility!==t&&(this._visibility=t,this.domNode.style.visibility=this._visibility)}setColor(t){this._color!==t&&(this._color=t,this.domNode.style.color=this._color)}setBackgroundColor(t){this._backgroundColor!==t&&(this._backgroundColor=t,this.domNode.style.backgroundColor=this._backgroundColor)}setLayerHinting(t){this._layerHint!==t&&(this._layerHint=t,this.domNode.style.transform=this._layerHint?"translate3d(0px, 0px, 0px)":"")}setBoxShadow(t){this._boxShadow!==t&&(this._boxShadow=t,this.domNode.style.boxShadow=t)}setContain(t){this._contain!==t&&(this._contain=t,this.domNode.style.contain=this._contain)}setAttribute(t,e){this.domNode.setAttribute(t,e)}removeAttribute(t){this.domNode.removeAttribute(t)}appendChild(t){this.domNode.appendChild(t.domNode)}removeChild(t){this.domNode.removeChild(t.domNode)}};function zt(t){return typeof t=="number"?`${t}px`:t}function wr(t){return new t3(t)}var vm=class{constructor(){this._hooks=new ti,this._pointerMoveCallback=null,this._onStopCallback=null}dispose(){this.stopMonitoring(!1),this._hooks.dispose()}stopMonitoring(t,e){if(!this.isMonitoring())return;this._hooks.clear(),this._pointerMoveCallback=null;let s=this._onStopCallback;this._onStopCallback=null,t&&s&&s(e)}isMonitoring(){return!!this._pointerMoveCallback}startMonitoring(t,e,s,i,n){this.isMonitoring()&&this.stopMonitoring(!1),this._pointerMoveCallback=i,this._onStopCallback=n;let o=t;try{t.setPointerCapture(e),this._hooks.add(Fe(()=>{try{t.releasePointerCapture(e)}catch{}}))}catch{o=ws(t)}this._hooks.add(ye(o,ht.POINTER_MOVE,a=>{if(a.buttons!==s){this.stopMonitoring(!0);return}a.preventDefault(),this._pointerMoveCallback(a)})),this._hooks.add(ye(o,ht.POINTER_UP,a=>this.stopMonitoring(!0)))}};function s3(t,e,s){let i=null,n=null;if(typeof s.value=="function"?(i="value",n=s.value,n.length!==0&&console.warn("Memoize should only be used in functions with zero parameters")):typeof s.get=="function"&&(i="get",n=s.get),!n)throw new Error("not supported");let o=`$memoize$${e}`;s[i]=function(...a){return this.hasOwnProperty(o)||Object.defineProperty(this,o,{configurable:!1,enumerable:!1,writable:!1,value:n.apply(this,a)}),this[o]}}var bs;(t=>(t.Tap="-xterm-gesturetap",t.Change="-xterm-gesturechange",t.Start="-xterm-gesturestart",t.End="-xterm-gesturesend",t.Contextmenu="-xterm-gesturecontextmenu"))(bs||={});var dr=class Vt extends Ve{constructor(){super(),this.dispatched=!1,this.targets=new Vd,this.ignoreTargets=new Vd,this.activeTouches={},this.handle=null,this._lastSetTapCountTime=0,this._register(yt.runAndSubscribe(JC,({window:e,disposables:s})=>{s.add(ye(e.document,"touchstart",i=>this.onTouchStart(i),{passive:!1})),s.add(ye(e.document,"touchend",i=>this.onTouchEnd(e,i))),s.add(ye(e.document,"touchmove",i=>this.onTouchMove(i),{passive:!1}))},{window:$s,disposables:this._store}))}static addTarget(e){if(!Vt.isTouchDevice())return Ve.None;Vt.INSTANCE||(Vt.INSTANCE=new Vt);let s=Vt.INSTANCE.targets.push(e);return Fe(s)}static ignoreTarget(e){if(!Vt.isTouchDevice())return Ve.None;Vt.INSTANCE||(Vt.INSTANCE=new Vt);let s=Vt.INSTANCE.ignoreTargets.push(e);return Fe(s)}static isTouchDevice(){return"ontouchstart"in $s||navigator.maxTouchPoints>0}dispose(){this.handle&&(this.handle.dispose(),this.handle=null),super.dispose()}onTouchStart(e){let s=Date.now();this.handle&&(this.handle.dispose(),this.handle=null);for(let i=0,n=e.targetTouches.length;i<n;i++){let o=e.targetTouches.item(i);this.activeTouches[o.identifier]={id:o.identifier,initialTarget:o.target,initialTimeStamp:s,initialPageX:o.pageX,initialPageY:o.pageY,rollingTimestamps:[s],rollingPageX:[o.pageX],rollingPageY:[o.pageY]};let a=this.newGestureEvent(bs.Start,o.target);a.pageX=o.pageX,a.pageY=o.pageY,this.dispatchEvent(a)}this.dispatched&&(e.preventDefault(),e.stopPropagation(),this.dispatched=!1)}onTouchEnd(e,s){let i=Date.now(),n=Object.keys(this.activeTouches).length;for(let o=0,a=s.changedTouches.length;o<a;o++){let l=s.changedTouches.item(o);if(!this.activeTouches.hasOwnProperty(String(l.identifier))){console.warn("move of an UNKNOWN touch",l);continue}let c=this.activeTouches[l.identifier],d=Date.now()-c.initialTimeStamp;if(d<Vt.HOLD_DELAY&&Math.abs(c.initialPageX-Gt(c.rollingPageX))<30&&Math.abs(c.initialPageY-Gt(c.rollingPageY))<30){let u=this.newGestureEvent(bs.Tap,c.initialTarget);u.pageX=Gt(c.rollingPageX),u.pageY=Gt(c.rollingPageY),this.dispatchEvent(u)}else if(d>=Vt.HOLD_DELAY&&Math.abs(c.initialPageX-Gt(c.rollingPageX))<30&&Math.abs(c.initialPageY-Gt(c.rollingPageY))<30){let u=this.newGestureEvent(bs.Contextmenu,c.initialTarget);u.pageX=Gt(c.rollingPageX),u.pageY=Gt(c.rollingPageY),this.dispatchEvent(u)}else if(n===1){let u=Gt(c.rollingPageX),h=Gt(c.rollingPageY),f=Gt(c.rollingTimestamps)-c.rollingTimestamps[0],m=u-c.rollingPageX[0],p=h-c.rollingPageY[0],g=[...this.targets].filter(_=>c.initialTarget instanceof Node&&_.contains(c.initialTarget));this.inertia(e,g,i,Math.abs(m)/f,m>0?1:-1,u,Math.abs(p)/f,p>0?1:-1,h)}this.dispatchEvent(this.newGestureEvent(bs.End,c.initialTarget)),delete this.activeTouches[l.identifier]}this.dispatched&&(s.preventDefault(),s.stopPropagation(),this.dispatched=!1)}newGestureEvent(e,s){let i=document.createEvent("CustomEvent");return i.initEvent(e,!1,!0),i.initialTarget=s,i.tapCount=0,i}dispatchEvent(e){if(e.type===bs.Tap){let s=new Date().getTime(),i=0;s-this._lastSetTapCountTime>Vt.CLEAR_TAP_COUNT_TIME?i=1:i=2,this._lastSetTapCountTime=s,e.tapCount=i}else(e.type===bs.Change||e.type===bs.Contextmenu)&&(this._lastSetTapCountTime=0);if(e.initialTarget instanceof Node){for(let i of this.ignoreTargets)if(i.contains(e.initialTarget))return;let s=[];for(let i of this.targets)if(i.contains(e.initialTarget)){let n=0,o=e.initialTarget;for(;o&&o!==i;)n++,o=o.parentElement;s.push([n,i])}s.sort((i,n)=>i[0]-n[0]);for(let[i,n]of s)n.dispatchEvent(e),this.dispatched=!0}}inertia(e,s,i,n,o,a,l,c,d){this.handle=ic(e,()=>{let u=Date.now(),h=u-i,f=0,m=0,p=!0;n+=Vt.SCROLL_FRICTION*h,l+=Vt.SCROLL_FRICTION*h,n>0&&(p=!1,f=o*n*h),l>0&&(p=!1,m=c*l*h);let g=this.newGestureEvent(bs.Change);g.translationX=f,g.translationY=m,s.forEach(_=>_.dispatchEvent(g)),p||this.inertia(e,s,u,n,o,a+f,l,c,d+m)})}onTouchMove(e){let s=Date.now();for(let i=0,n=e.changedTouches.length;i<n;i++){let o=e.changedTouches.item(i);if(!this.activeTouches.hasOwnProperty(String(o.identifier))){console.warn("end of an UNKNOWN touch",o);continue}let a=this.activeTouches[o.identifier],l=this.newGestureEvent(bs.Change,a.initialTarget);l.translationX=o.pageX-Gt(a.rollingPageX),l.translationY=o.pageY-Gt(a.rollingPageY),l.pageX=o.pageX,l.pageY=o.pageY,this.dispatchEvent(l),a.rollingPageX.length>3&&(a.rollingPageX.shift(),a.rollingPageY.shift(),a.rollingTimestamps.shift()),a.rollingPageX.push(o.pageX),a.rollingPageY.push(o.pageY),a.rollingTimestamps.push(s)}this.dispatched&&(e.preventDefault(),e.stopPropagation(),this.dispatched=!1)}};dr.SCROLL_FRICTION=-.005,dr.HOLD_DELAY=700,dr.CLEAR_TAP_COUNT_TIME=400,Ye([s3],dr,"isTouchDevice",1);var i3=dr,rc=class extends Ve{onclick(t,e){this._register(ye(t,ht.CLICK,s=>e(new mn(ws(t),s))))}onmousedown(t,e){this._register(ye(t,ht.MOUSE_DOWN,s=>e(new mn(ws(t),s))))}onmouseover(t,e){this._register(ye(t,ht.MOUSE_OVER,s=>e(new mn(ws(t),s))))}onmouseleave(t,e){this._register(ye(t,ht.MOUSE_LEAVE,s=>e(new mn(ws(t),s))))}onkeydown(t,e){this._register(ye(t,ht.KEY_DOWN,s=>e(new Ad(s))))}onkeyup(t,e){this._register(ye(t,ht.KEY_UP,s=>e(new Ad(s))))}oninput(t,e){this._register(ye(t,ht.INPUT,e))}onblur(t,e){this._register(ye(t,ht.BLUR,e))}onfocus(t,e){this._register(ye(t,ht.FOCUS,e))}onchange(t,e){this._register(ye(t,ht.CHANGE,e))}ignoreGesture(t){return i3.ignoreTarget(t)}},Md=11,r3=class extends rc{constructor(t){super(),this._onActivate=t.onActivate,this.bgDomNode=document.createElement("div"),this.bgDomNode.className="arrow-background",this.bgDomNode.style.position="absolute",this.bgDomNode.style.width=t.bgWidth+"px",this.bgDomNode.style.height=t.bgHeight+"px",typeof t.top<"u"&&(this.bgDomNode.style.top="0px"),typeof t.left<"u"&&(this.bgDomNode.style.left="0px"),typeof t.bottom<"u"&&(this.bgDomNode.style.bottom="0px"),typeof t.right<"u"&&(this.bgDomNode.style.right="0px"),this.domNode=document.createElement("div"),this.domNode.className=t.className,this.domNode.style.position="absolute",this.domNode.style.width=Md+"px",this.domNode.style.height=Md+"px",typeof t.top<"u"&&(this.domNode.style.top=t.top+"px"),typeof t.left<"u"&&(this.domNode.style.left=t.left+"px"),typeof t.bottom<"u"&&(this.domNode.style.bottom=t.bottom+"px"),typeof t.right<"u"&&(this.domNode.style.right=t.right+"px"),this._pointerMoveMonitor=this._register(new vm),this._register(Td(this.bgDomNode,ht.POINTER_DOWN,e=>this._arrowPointerDown(e))),this._register(Td(this.domNode,ht.POINTER_DOWN,e=>this._arrowPointerDown(e))),this._pointerdownRepeatTimer=this._register(new ZC),this._pointerdownScheduleRepeatTimer=this._register(new sc)}_arrowPointerDown(t){if(!t.target||!(t.target instanceof Element))return;let e=()=>{this._pointerdownRepeatTimer.cancelAndSet(()=>this._onActivate(),1e3/24,ws(t))};this._onActivate(),this._pointerdownRepeatTimer.cancel(),this._pointerdownScheduleRepeatTimer.cancelAndSet(e,200),this._pointerMoveMonitor.startMonitoring(t.target,t.pointerId,t.buttons,s=>{},()=>{this._pointerdownRepeatTimer.cancel(),this._pointerdownScheduleRepeatTimer.cancel()}),t.preventDefault()}},n3=class La{constructor(e,s,i,n,o,a,l){this._forceIntegerValues=e,this._scrollStateBrand=void 0,this._forceIntegerValues&&(s=s|0,i=i|0,n=n|0,o=o|0,a=a|0,l=l|0),this.rawScrollLeft=n,this.rawScrollTop=l,s<0&&(s=0),n+s>i&&(n=i-s),n<0&&(n=0),o<0&&(o=0),l+o>a&&(l=a-o),l<0&&(l=0),this.width=s,this.scrollWidth=i,this.scrollLeft=n,this.height=o,this.scrollHeight=a,this.scrollTop=l}equals(e){return this.rawScrollLeft===e.rawScrollLeft&&this.rawScrollTop===e.rawScrollTop&&this.width===e.width&&this.scrollWidth===e.scrollWidth&&this.scrollLeft===e.scrollLeft&&this.height===e.height&&this.scrollHeight===e.scrollHeight&&this.scrollTop===e.scrollTop}withScrollDimensions(e,s){return new La(this._forceIntegerValues,typeof e.width<"u"?e.width:this.width,typeof e.scrollWidth<"u"?e.scrollWidth:this.scrollWidth,s?this.rawScrollLeft:this.scrollLeft,typeof e.height<"u"?e.height:this.height,typeof e.scrollHeight<"u"?e.scrollHeight:this.scrollHeight,s?this.rawScrollTop:this.scrollTop)}withScrollPosition(e){return new La(this._forceIntegerValues,this.width,this.scrollWidth,typeof e.scrollLeft<"u"?e.scrollLeft:this.rawScrollLeft,this.height,this.scrollHeight,typeof e.scrollTop<"u"?e.scrollTop:this.rawScrollTop)}createScrollEvent(e,s){let i=this.width!==e.width,n=this.scrollWidth!==e.scrollWidth,o=this.scrollLeft!==e.scrollLeft,a=this.height!==e.height,l=this.scrollHeight!==e.scrollHeight,c=this.scrollTop!==e.scrollTop;return{inSmoothScrolling:s,oldWidth:e.width,oldScrollWidth:e.scrollWidth,oldScrollLeft:e.scrollLeft,width:this.width,scrollWidth:this.scrollWidth,scrollLeft:this.scrollLeft,oldHeight:e.height,oldScrollHeight:e.scrollHeight,oldScrollTop:e.scrollTop,height:this.height,scrollHeight:this.scrollHeight,scrollTop:this.scrollTop,widthChanged:i,scrollWidthChanged:n,scrollLeftChanged:o,heightChanged:a,scrollHeightChanged:l,scrollTopChanged:c}}},o3=class extends Ve{constructor(t){super(),this._scrollableBrand=void 0,this._onScroll=this._register(new re),this.onScroll=this._onScroll.event,this._smoothScrollDuration=t.smoothScrollDuration,this._scheduleAtNextAnimationFrame=t.scheduleAtNextAnimationFrame,this._state=new n3(t.forceIntegerValues,0,0,0,0,0,0),this._smoothScrolling=null}dispose(){this._smoothScrolling&&(this._smoothScrolling.dispose(),this._smoothScrolling=null),super.dispose()}setSmoothScrollDuration(t){this._smoothScrollDuration=t}validateScrollPosition(t){return this._state.withScrollPosition(t)}getScrollDimensions(){return this._state}setScrollDimensions(t,e){let s=this._state.withScrollDimensions(t,e);this._setState(s,!!this._smoothScrolling),this._smoothScrolling?.acceptScrollDimensions(this._state)}getFutureScrollPosition(){return this._smoothScrolling?this._smoothScrolling.to:this._state}getCurrentScrollPosition(){return this._state}setScrollPositionNow(t){let e=this._state.withScrollPosition(t);this._smoothScrolling&&(this._smoothScrolling.dispose(),this._smoothScrolling=null),this._setState(e,!1)}setScrollPositionSmooth(t,e){if(this._smoothScrollDuration===0)return this.setScrollPositionNow(t);if(this._smoothScrolling){t={scrollLeft:typeof t.scrollLeft>"u"?this._smoothScrolling.to.scrollLeft:t.scrollLeft,scrollTop:typeof t.scrollTop>"u"?this._smoothScrolling.to.scrollTop:t.scrollTop};let s=this._state.withScrollPosition(t);if(this._smoothScrolling.to.scrollLeft===s.scrollLeft&&this._smoothScrolling.to.scrollTop===s.scrollTop)return;let i;e?i=new Ld(this._smoothScrolling.from,s,this._smoothScrolling.startTime,this._smoothScrolling.duration):i=this._smoothScrolling.combine(this._state,s,this._smoothScrollDuration),this._smoothScrolling.dispose(),this._smoothScrolling=i}else{let s=this._state.withScrollPosition(t);this._smoothScrolling=Ld.start(this._state,s,this._smoothScrollDuration)}this._smoothScrolling.animationFrameDisposable=this._scheduleAtNextAnimationFrame(()=>{this._smoothScrolling&&(this._smoothScrolling.animationFrameDisposable=null,this._performSmoothScrolling())})}hasPendingScrollAnimation(){return!!this._smoothScrolling}_performSmoothScrolling(){if(!this._smoothScrolling)return;let t=this._smoothScrolling.tick(),e=this._state.withScrollPosition(t);if(this._setState(e,!0),!!this._smoothScrolling){if(t.isDone){this._smoothScrolling.dispose(),this._smoothScrolling=null;return}this._smoothScrolling.animationFrameDisposable=this._scheduleAtNextAnimationFrame(()=>{this._smoothScrolling&&(this._smoothScrolling.animationFrameDisposable=null,this._performSmoothScrolling())})}}_setState(t,e){let s=this._state;s.equals(t)||(this._state=t,this._onScroll.fire(this._state.createScrollEvent(s,e)))}},Pd=class{constructor(t,e,s){this.scrollLeft=t,this.scrollTop=e,this.isDone=s}};function Ko(t,e){let s=e-t;return function(i){return t+s*c3(i)}}function a3(t,e,s){return function(i){return i<s?t(i/s):e((i-s)/(1-s))}}var Ld=class Ba{constructor(e,s,i,n){this.from=e,this.to=s,this.duration=n,this.startTime=i,this.animationFrameDisposable=null,this._initAnimations()}_initAnimations(){this.scrollLeft=this._initAnimation(this.from.scrollLeft,this.to.scrollLeft,this.to.width),this.scrollTop=this._initAnimation(this.from.scrollTop,this.to.scrollTop,this.to.height)}_initAnimation(e,s,i){if(Math.abs(e-s)>2.5*i){let n,o;return e<s?(n=e+.75*i,o=s-.75*i):(n=e-.75*i,o=s+.75*i),a3(Ko(e,n),Ko(o,s),.33)}return Ko(e,s)}dispose(){this.animationFrameDisposable!==null&&(this.animationFrameDisposable.dispose(),this.animationFrameDisposable=null)}acceptScrollDimensions(e){this.to=e.withScrollPosition(this.to),this._initAnimations()}tick(){return this._tick(Date.now())}_tick(e){let s=(e-this.startTime)/this.duration;if(s<1){let i=this.scrollLeft(s),n=this.scrollTop(s);return new Pd(i,n,!1)}return new Pd(this.to.scrollLeft,this.to.scrollTop,!0)}combine(e,s,i){return Ba.start(e,s,i)}static start(e,s,i){i=i+10;let n=Date.now()-10;return new Ba(e,s,n,i)}};function l3(t){return Math.pow(t,3)}function c3(t){return 1-l3(1-t)}var d3=class extends Ve{constructor(t,e,s){super(),this._visibility=t,this._visibleClassName=e,this._invisibleClassName=s,this._domNode=null,this._isVisible=!1,this._isNeeded=!1,this._rawShouldBeVisible=!1,this._shouldBeVisible=!1,this._revealTimer=this._register(new sc)}setVisibility(t){this._visibility!==t&&(this._visibility=t,this._updateShouldBeVisible())}setShouldBeVisible(t){this._rawShouldBeVisible=t,this._updateShouldBeVisible()}_applyVisibilitySetting(){return this._visibility===2?!1:this._visibility===3?!0:this._rawShouldBeVisible}_updateShouldBeVisible(){let t=this._applyVisibilitySetting();this._shouldBeVisible!==t&&(this._shouldBeVisible=t,this.ensureVisibility())}setIsNeeded(t){this._isNeeded!==t&&(this._isNeeded=t,this.ensureVisibility())}setDomNode(t){this._domNode=t,this._domNode.setClassName(this._invisibleClassName),this.setShouldBeVisible(!1)}ensureVisibility(){if(!this._isNeeded){this._hide(!1);return}this._shouldBeVisible?this._reveal():this._hide(!0)}_reveal(){this._isVisible||(this._isVisible=!0,this._revealTimer.setIfNotSet(()=>{this._domNode?.setClassName(this._visibleClassName)},0))}_hide(t){this._revealTimer.cancel(),this._isVisible&&(this._isVisible=!1,this._domNode?.setClassName(this._invisibleClassName+(t?" fade":"")))}},h3=140,bm=class extends rc{constructor(t){super(),this._lazyRender=t.lazyRender,this._host=t.host,this._scrollable=t.scrollable,this._scrollByPage=t.scrollByPage,this._scrollbarState=t.scrollbarState,this._visibilityController=this._register(new d3(t.visibility,"visible scrollbar "+t.extraScrollbarClassName,"invisible scrollbar "+t.extraScrollbarClassName)),this._visibilityController.setIsNeeded(this._scrollbarState.isNeeded()),this._pointerMoveMonitor=this._register(new vm),this._shouldRender=!0,this.domNode=wr(document.createElement("div")),this.domNode.setAttribute("role","presentation"),this.domNode.setAttribute("aria-hidden","true"),this._visibilityController.setDomNode(this.domNode),this.domNode.setPosition("absolute"),this._register(ye(this.domNode.domNode,ht.POINTER_DOWN,e=>this._domNodePointerDown(e)))}_createArrow(t){let e=this._register(new r3(t));this.domNode.domNode.appendChild(e.bgDomNode),this.domNode.domNode.appendChild(e.domNode)}_createSlider(t,e,s,i){this.slider=wr(document.createElement("div")),this.slider.setClassName("slider"),this.slider.setPosition("absolute"),this.slider.setTop(t),this.slider.setLeft(e),typeof s=="number"&&this.slider.setWidth(s),typeof i=="number"&&this.slider.setHeight(i),this.slider.setLayerHinting(!0),this.slider.setContain("strict"),this.domNode.domNode.appendChild(this.slider.domNode),this._register(ye(this.slider.domNode,ht.POINTER_DOWN,n=>{n.button===0&&(n.preventDefault(),this._sliderPointerDown(n))})),this.onclick(this.slider.domNode,n=>{n.leftButton&&n.stopPropagation()})}_onElementSize(t){return this._scrollbarState.setVisibleSize(t)&&(this._visibilityController.setIsNeeded(this._scrollbarState.isNeeded()),this._shouldRender=!0,this._lazyRender||this.render()),this._shouldRender}_onElementScrollSize(t){return this._scrollbarState.setScrollSize(t)&&(this._visibilityController.setIsNeeded(this._scrollbarState.isNeeded()),this._shouldRender=!0,this._lazyRender||this.render()),this._shouldRender}_onElementScrollPosition(t){return this._scrollbarState.setScrollPosition(t)&&(this._visibilityController.setIsNeeded(this._scrollbarState.isNeeded()),this._shouldRender=!0,this._lazyRender||this.render()),this._shouldRender}beginReveal(){this._visibilityController.setShouldBeVisible(!0)}beginHide(){this._visibilityController.setShouldBeVisible(!1)}render(){this._shouldRender&&(this._shouldRender=!1,this._renderDomNode(this._scrollbarState.getRectangleLargeSize(),this._scrollbarState.getRectangleSmallSize()),this._updateSlider(this._scrollbarState.getSliderSize(),this._scrollbarState.getArrowSize()+this._scrollbarState.getSliderPosition()))}_domNodePointerDown(t){t.target===this.domNode.domNode&&this._onPointerDown(t)}delegatePointerDown(t){let e=this.domNode.domNode.getClientRects()[0].top,s=e+this._scrollbarState.getSliderPosition(),i=e+this._scrollbarState.getSliderPosition()+this._scrollbarState.getSliderSize(),n=this._sliderPointerPosition(t);s<=n&&n<=i?t.button===0&&(t.preventDefault(),this._sliderPointerDown(t)):this._onPointerDown(t)}_onPointerDown(t){let e,s;if(t.target===this.domNode.domNode&&typeof t.offsetX=="number"&&typeof t.offsetY=="number")e=t.offsetX,s=t.offsetY;else{let n=e3(this.domNode.domNode);e=t.pageX-n.left,s=t.pageY-n.top}let i=this._pointerDownRelativePosition(e,s);this._setDesiredScrollPositionNow(this._scrollByPage?this._scrollbarState.getDesiredScrollPositionFromOffsetPaged(i):this._scrollbarState.getDesiredScrollPositionFromOffset(i)),t.button===0&&(t.preventDefault(),this._sliderPointerDown(t))}_sliderPointerDown(t){if(!t.target||!(t.target instanceof Element))return;let e=this._sliderPointerPosition(t),s=this._sliderOrthogonalPointerPosition(t),i=this._scrollbarState.clone();this.slider.toggleClassName("active",!0),this._pointerMoveMonitor.startMonitoring(t.target,t.pointerId,t.buttons,n=>{let o=this._sliderOrthogonalPointerPosition(n),a=Math.abs(o-s);if(pm&&a>h3){this._setDesiredScrollPositionNow(i.getScrollPosition());return}let l=this._sliderPointerPosition(n)-e;this._setDesiredScrollPositionNow(i.getDesiredScrollPositionFromDelta(l))},()=>{this.slider.toggleClassName("active",!1),this._host.onDragEnd()}),this._host.onDragStart()}_setDesiredScrollPositionNow(t){let e={};this.writeScrollPosition(e,t),this._scrollable.setScrollPositionNow(e)}updateScrollbarSize(t){this._updateScrollbarSize(t),this._scrollbarState.setScrollbarSize(t),this._shouldRender=!0,this._lazyRender||this.render()}isNeeded(){return this._scrollbarState.isNeeded()}},ym=class Oa{constructor(e,s,i,n,o,a){this._scrollbarSize=Math.round(s),this._oppositeScrollbarSize=Math.round(i),this._arrowSize=Math.round(e),this._visibleSize=n,this._scrollSize=o,this._scrollPosition=a,this._computedAvailableSize=0,this._computedIsNeeded=!1,this._computedSliderSize=0,this._computedSliderRatio=0,this._computedSliderPosition=0,this._refreshComputedValues()}clone(){return new Oa(this._arrowSize,this._scrollbarSize,this._oppositeScrollbarSize,this._visibleSize,this._scrollSize,this._scrollPosition)}setVisibleSize(e){let s=Math.round(e);return this._visibleSize!==s?(this._visibleSize=s,this._refreshComputedValues(),!0):!1}setScrollSize(e){let s=Math.round(e);return this._scrollSize!==s?(this._scrollSize=s,this._refreshComputedValues(),!0):!1}setScrollPosition(e){let s=Math.round(e);return this._scrollPosition!==s?(this._scrollPosition=s,this._refreshComputedValues(),!0):!1}setScrollbarSize(e){this._scrollbarSize=Math.round(e)}setOppositeScrollbarSize(e){this._oppositeScrollbarSize=Math.round(e)}static _computeValues(e,s,i,n,o){let a=Math.max(0,i-e),l=Math.max(0,a-2*s),c=n>0&&n>i;if(!c)return{computedAvailableSize:Math.round(a),computedIsNeeded:c,computedSliderSize:Math.round(l),computedSliderRatio:0,computedSliderPosition:0};let d=Math.round(Math.max(20,Math.floor(i*l/n))),u=(l-d)/(n-i),h=o*u;return{computedAvailableSize:Math.round(a),computedIsNeeded:c,computedSliderSize:Math.round(d),computedSliderRatio:u,computedSliderPosition:Math.round(h)}}_refreshComputedValues(){let e=Oa._computeValues(this._oppositeScrollbarSize,this._arrowSize,this._visibleSize,this._scrollSize,this._scrollPosition);this._computedAvailableSize=e.computedAvailableSize,this._computedIsNeeded=e.computedIsNeeded,this._computedSliderSize=e.computedSliderSize,this._computedSliderRatio=e.computedSliderRatio,this._computedSliderPosition=e.computedSliderPosition}getArrowSize(){return this._arrowSize}getScrollPosition(){return this._scrollPosition}getRectangleLargeSize(){return this._computedAvailableSize}getRectangleSmallSize(){return this._scrollbarSize}isNeeded(){return this._computedIsNeeded}getSliderSize(){return this._computedSliderSize}getSliderPosition(){return this._computedSliderPosition}getDesiredScrollPositionFromOffset(e){if(!this._computedIsNeeded)return 0;let s=e-this._arrowSize-this._computedSliderSize/2;return Math.round(s/this._computedSliderRatio)}getDesiredScrollPositionFromOffsetPaged(e){if(!this._computedIsNeeded)return 0;let s=e-this._arrowSize,i=this._scrollPosition;return s<this._computedSliderPosition?i-=this._visibleSize:i+=this._visibleSize,i}getDesiredScrollPositionFromDelta(e){if(!this._computedIsNeeded)return 0;let s=this._computedSliderPosition+e;return Math.round(s/this._computedSliderRatio)}},u3=class extends bm{constructor(t,e,s){let i=t.getScrollDimensions(),n=t.getCurrentScrollPosition();if(super({lazyRender:e.lazyRender,host:s,scrollbarState:new ym(e.horizontalHasArrows?e.arrowSize:0,e.horizontal===2?0:e.horizontalScrollbarSize,e.vertical===2?0:e.verticalScrollbarSize,i.width,i.scrollWidth,n.scrollLeft),visibility:e.horizontal,extraScrollbarClassName:"horizontal",scrollable:t,scrollByPage:e.scrollByPage}),e.horizontalHasArrows)throw new Error("horizontalHasArrows is not supported in xterm.js");this._createSlider(Math.floor((e.horizontalScrollbarSize-e.horizontalSliderSize)/2),0,void 0,e.horizontalSliderSize)}_updateSlider(t,e){this.slider.setWidth(t),this.slider.setLeft(e)}_renderDomNode(t,e){this.domNode.setWidth(t),this.domNode.setHeight(e),this.domNode.setLeft(0),this.domNode.setBottom(0)}onDidScroll(t){return this._shouldRender=this._onElementScrollSize(t.scrollWidth)||this._shouldRender,this._shouldRender=this._onElementScrollPosition(t.scrollLeft)||this._shouldRender,this._shouldRender=this._onElementSize(t.width)||this._shouldRender,this._shouldRender}_pointerDownRelativePosition(t,e){return t}_sliderPointerPosition(t){return t.pageX}_sliderOrthogonalPointerPosition(t){return t.pageY}_updateScrollbarSize(t){this.slider.setHeight(t)}writeScrollPosition(t,e){t.scrollLeft=e}updateOptions(t){this.updateScrollbarSize(t.horizontal===2?0:t.horizontalScrollbarSize),this._scrollbarState.setOppositeScrollbarSize(t.vertical===2?0:t.verticalScrollbarSize),this._visibilityController.setVisibility(t.horizontal),this._scrollByPage=t.scrollByPage}},f3=class extends bm{constructor(t,e,s){let i=t.getScrollDimensions(),n=t.getCurrentScrollPosition();if(super({lazyRender:e.lazyRender,host:s,scrollbarState:new ym(e.verticalHasArrows?e.arrowSize:0,e.vertical===2?0:e.verticalScrollbarSize,0,i.height,i.scrollHeight,n.scrollTop),visibility:e.vertical,extraScrollbarClassName:"vertical",scrollable:t,scrollByPage:e.scrollByPage}),e.verticalHasArrows)throw new Error("horizontalHasArrows is not supported in xterm.js");this._createSlider(0,Math.floor((e.verticalScrollbarSize-e.verticalSliderSize)/2),e.verticalSliderSize,void 0)}_updateSlider(t,e){this.slider.setHeight(t),this.slider.setTop(e)}_renderDomNode(t,e){this.domNode.setWidth(e),this.domNode.setHeight(t),this.domNode.setRight(0),this.domNode.setTop(0)}onDidScroll(t){return this._shouldRender=this._onElementScrollSize(t.scrollHeight)||this._shouldRender,this._shouldRender=this._onElementScrollPosition(t.scrollTop)||this._shouldRender,this._shouldRender=this._onElementSize(t.height)||this._shouldRender,this._shouldRender}_pointerDownRelativePosition(t,e){return e}_sliderPointerPosition(t){return t.pageY}_sliderOrthogonalPointerPosition(t){return t.pageX}_updateScrollbarSize(t){this.slider.setWidth(t)}writeScrollPosition(t,e){t.scrollTop=e}updateOptions(t){this.updateScrollbarSize(t.vertical===2?0:t.verticalScrollbarSize),this._scrollbarState.setOppositeScrollbarSize(0),this._visibilityController.setVisibility(t.vertical),this._scrollByPage=t.scrollByPage}},m3=500,Bd=50,p3=class{constructor(t,e,s){this.timestamp=t,this.deltaX=e,this.deltaY=s,this.score=0}},$a=class{constructor(){this._capacity=5,this._memory=[],this._front=-1,this._rear=-1}isPhysicalMouseWheel(){if(this._front===-1&&this._rear===-1)return!1;let e=1,s=0,i=1,n=this._rear;do{let o=n===this._front?e:Math.pow(2,-i);if(e-=o,s+=this._memory[n].score*o,n===this._front)break;n=(this._capacity+n-1)%this._capacity,i++}while(!0);return s<=.5}acceptStandardWheelEvent(e){if(ec){let s=ws(e.browserEvent),i=jC(s);this.accept(Date.now(),e.deltaX*i,e.deltaY*i)}else this.accept(Date.now(),e.deltaX,e.deltaY)}accept(e,s,i){let n=null,o=new p3(e,s,i);this._front===-1&&this._rear===-1?(this._memory[0]=o,this._front=0,this._rear=0):(n=this._memory[this._rear],this._rear=(this._rear+1)%this._capacity,this._rear===this._front&&(this._front=(this._front+1)%this._capacity),this._memory[this._rear]=o),o.score=this._computeScore(o,n)}_computeScore(e,s){if(Math.abs(e.deltaX)>0&&Math.abs(e.deltaY)>0)return 1;let i=.5;if((!this._isAlmostInt(e.deltaX)||!this._isAlmostInt(e.deltaY))&&(i+=.25),s){let n=Math.abs(e.deltaX),o=Math.abs(e.deltaY),a=Math.abs(s.deltaX),l=Math.abs(s.deltaY),c=Math.max(Math.min(n,a),1),d=Math.max(Math.min(o,l),1),u=Math.max(n,a),h=Math.max(o,l);u%c===0&&h%d===0&&(i-=.5)}return Math.min(Math.max(i,0),1)}_isAlmostInt(e){return Math.abs(Math.round(e)-e)<.01}};$a.INSTANCE=new $a;var g3=$a,_3=class extends rc{constructor(t,e,s){super(),this._onScroll=this._register(new re),this.onScroll=this._onScroll.event,this._onWillScroll=this._register(new re),this.onWillScroll=this._onWillScroll.event,this._options=v3(e),this._scrollable=s,this._register(this._scrollable.onScroll(n=>{this._onWillScroll.fire(n),this._onDidScroll(n),this._onScroll.fire(n)}));let i={onMouseWheel:n=>this._onMouseWheel(n),onDragStart:()=>this._onDragStart(),onDragEnd:()=>this._onDragEnd()};this._verticalScrollbar=this._register(new f3(this._scrollable,this._options,i)),this._horizontalScrollbar=this._register(new u3(this._scrollable,this._options,i)),this._domNode=document.createElement("div"),this._domNode.className="xterm-scrollable-element "+this._options.className,this._domNode.setAttribute("role","presentation"),this._domNode.style.position="relative",this._domNode.appendChild(t),this._domNode.appendChild(this._horizontalScrollbar.domNode.domNode),this._domNode.appendChild(this._verticalScrollbar.domNode.domNode),this._options.useShadows?(this._leftShadowDomNode=wr(document.createElement("div")),this._leftShadowDomNode.setClassName("shadow"),this._domNode.appendChild(this._leftShadowDomNode.domNode),this._topShadowDomNode=wr(document.createElement("div")),this._topShadowDomNode.setClassName("shadow"),this._domNode.appendChild(this._topShadowDomNode.domNode),this._topLeftShadowDomNode=wr(document.createElement("div")),this._topLeftShadowDomNode.setClassName("shadow"),this._domNode.appendChild(this._topLeftShadowDomNode.domNode)):(this._leftShadowDomNode=null,this._topShadowDomNode=null,this._topLeftShadowDomNode=null),this._listenOnDomNode=this._options.listenOnDomNode||this._domNode,this._mouseWheelToDispose=[],this._setListeningToMouseWheel(this._options.handleMouseWheel),this.onmouseover(this._listenOnDomNode,n=>this._onMouseOver(n)),this.onmouseleave(this._listenOnDomNode,n=>this._onMouseLeave(n)),this._hideTimeout=this._register(new sc),this._isDragging=!1,this._mouseIsOver=!1,this._shouldRender=!0,this._revealOnScroll=!0}get options(){return this._options}dispose(){this._mouseWheelToDispose=_i(this._mouseWheelToDispose),super.dispose()}getDomNode(){return this._domNode}getOverviewRulerLayoutInfo(){return{parent:this._domNode,insertBefore:this._verticalScrollbar.domNode.domNode}}delegateVerticalScrollbarPointerDown(t){this._verticalScrollbar.delegatePointerDown(t)}getScrollDimensions(){return this._scrollable.getScrollDimensions()}setScrollDimensions(t){this._scrollable.setScrollDimensions(t,!1)}updateClassName(t){this._options.className=t,As&&(this._options.className+=" mac"),this._domNode.className="xterm-scrollable-element "+this._options.className}updateOptions(t){typeof t.handleMouseWheel<"u"&&(this._options.handleMouseWheel=t.handleMouseWheel,this._setListeningToMouseWheel(this._options.handleMouseWheel)),typeof t.mouseWheelScrollSensitivity<"u"&&(this._options.mouseWheelScrollSensitivity=t.mouseWheelScrollSensitivity),typeof t.fastScrollSensitivity<"u"&&(this._options.fastScrollSensitivity=t.fastScrollSensitivity),typeof t.scrollPredominantAxis<"u"&&(this._options.scrollPredominantAxis=t.scrollPredominantAxis),typeof t.horizontal<"u"&&(this._options.horizontal=t.horizontal),typeof t.vertical<"u"&&(this._options.vertical=t.vertical),typeof t.horizontalScrollbarSize<"u"&&(this._options.horizontalScrollbarSize=t.horizontalScrollbarSize),typeof t.verticalScrollbarSize<"u"&&(this._options.verticalScrollbarSize=t.verticalScrollbarSize),typeof t.scrollByPage<"u"&&(this._options.scrollByPage=t.scrollByPage),this._horizontalScrollbar.updateOptions(this._options),this._verticalScrollbar.updateOptions(this._options),this._options.lazyRender||this._render()}setRevealOnScroll(t){this._revealOnScroll=t}delegateScrollFromMouseWheelEvent(t){this._onMouseWheel(new Id(t))}_setListeningToMouseWheel(t){if(this._mouseWheelToDispose.length>0!==t&&(this._mouseWheelToDispose=_i(this._mouseWheelToDispose),t)){let e=s=>{this._onMouseWheel(new Id(s))};this._mouseWheelToDispose.push(ye(this._listenOnDomNode,ht.MOUSE_WHEEL,e,{passive:!1}))}}_onMouseWheel(t){if(t.browserEvent?.defaultPrevented)return;let e=g3.INSTANCE;e.acceptStandardWheelEvent(t);let s=!1;if(t.deltaY||t.deltaX){let n=t.deltaY*this._options.mouseWheelScrollSensitivity,o=t.deltaX*this._options.mouseWheelScrollSensitivity;this._options.scrollPredominantAxis&&(this._options.scrollYToX&&o+n===0?o=n=0:Math.abs(n)>=Math.abs(o)?o=0:n=0),this._options.flipAxes&&([n,o]=[o,n]);let a=!As&&t.browserEvent&&t.browserEvent.shiftKey;(this._options.scrollYToX||a)&&!o&&(o=n,n=0),t.browserEvent&&t.browserEvent.altKey&&(o=o*this._options.fastScrollSensitivity,n=n*this._options.fastScrollSensitivity);let l=this._scrollable.getFutureScrollPosition(),c={};if(n){let d=Bd*n,u=l.scrollTop-(d<0?Math.floor(d):Math.ceil(d));this._verticalScrollbar.writeScrollPosition(c,u)}if(o){let d=Bd*o,u=l.scrollLeft-(d<0?Math.floor(d):Math.ceil(d));this._horizontalScrollbar.writeScrollPosition(c,u)}c=this._scrollable.validateScrollPosition(c),(l.scrollLeft!==c.scrollLeft||l.scrollTop!==c.scrollTop)&&(this._options.mouseWheelSmoothScroll&&e.isPhysicalMouseWheel()?this._scrollable.setScrollPositionSmooth(c):this._scrollable.setScrollPositionNow(c),s=!0)}let i=s;!i&&this._options.alwaysConsumeMouseWheel&&(i=!0),!i&&this._options.consumeMouseWheelIfScrollbarIsNeeded&&(this._verticalScrollbar.isNeeded()||this._horizontalScrollbar.isNeeded())&&(i=!0),i&&(t.preventDefault(),t.stopPropagation())}_onDidScroll(t){this._shouldRender=this._horizontalScrollbar.onDidScroll(t)||this._shouldRender,this._shouldRender=this._verticalScrollbar.onDidScroll(t)||this._shouldRender,this._options.useShadows&&(this._shouldRender=!0),this._revealOnScroll&&this._reveal(),this._options.lazyRender||this._render()}renderNow(){if(!this._options.lazyRender)throw new Error("Please use `lazyRender` together with `renderNow`!");this._render()}_render(){if(this._shouldRender&&(this._shouldRender=!1,this._horizontalScrollbar.render(),this._verticalScrollbar.render(),this._options.useShadows)){let t=this._scrollable.getCurrentScrollPosition(),e=t.scrollTop>0,s=t.scrollLeft>0,i=s?" left":"",n=e?" top":"",o=s||e?" top-left-corner":"";this._leftShadowDomNode.setClassName(`shadow${i}`),this._topShadowDomNode.setClassName(`shadow${n}`),this._topLeftShadowDomNode.setClassName(`shadow${o}${n}${i}`)}}_onDragStart(){this._isDragging=!0,this._reveal()}_onDragEnd(){this._isDragging=!1,this._hide()}_onMouseLeave(t){this._mouseIsOver=!1,this._hide()}_onMouseOver(t){this._mouseIsOver=!0,this._reveal()}_reveal(){this._verticalScrollbar.beginReveal(),this._horizontalScrollbar.beginReveal(),this._scheduleHide()}_hide(){!this._mouseIsOver&&!this._isDragging&&(this._verticalScrollbar.beginHide(),this._horizontalScrollbar.beginHide())}_scheduleHide(){!this._mouseIsOver&&!this._isDragging&&this._hideTimeout.cancelAndSet(()=>this._hide(),m3)}},x3=class extends _3{constructor(t,e,s){super(t,e,s)}setScrollPosition(t){t.reuseAnimation?this._scrollable.setScrollPositionSmooth(t,t.reuseAnimation):this._scrollable.setScrollPositionNow(t)}getScrollPosition(){return this._scrollable.getCurrentScrollPosition()}};function v3(t){let e={lazyRender:typeof t.lazyRender<"u"?t.lazyRender:!1,className:typeof t.className<"u"?t.className:"",useShadows:typeof t.useShadows<"u"?t.useShadows:!0,handleMouseWheel:typeof t.handleMouseWheel<"u"?t.handleMouseWheel:!0,flipAxes:typeof t.flipAxes<"u"?t.flipAxes:!1,consumeMouseWheelIfScrollbarIsNeeded:typeof t.consumeMouseWheelIfScrollbarIsNeeded<"u"?t.consumeMouseWheelIfScrollbarIsNeeded:!1,alwaysConsumeMouseWheel:typeof t.alwaysConsumeMouseWheel<"u"?t.alwaysConsumeMouseWheel:!1,scrollYToX:typeof t.scrollYToX<"u"?t.scrollYToX:!1,mouseWheelScrollSensitivity:typeof t.mouseWheelScrollSensitivity<"u"?t.mouseWheelScrollSensitivity:1,fastScrollSensitivity:typeof t.fastScrollSensitivity<"u"?t.fastScrollSensitivity:5,scrollPredominantAxis:typeof t.scrollPredominantAxis<"u"?t.scrollPredominantAxis:!0,mouseWheelSmoothScroll:typeof t.mouseWheelSmoothScroll<"u"?t.mouseWheelSmoothScroll:!0,arrowSize:typeof t.arrowSize<"u"?t.arrowSize:11,listenOnDomNode:typeof t.listenOnDomNode<"u"?t.listenOnDomNode:null,horizontal:typeof t.horizontal<"u"?t.horizontal:1,horizontalScrollbarSize:typeof t.horizontalScrollbarSize<"u"?t.horizontalScrollbarSize:10,horizontalSliderSize:typeof t.horizontalSliderSize<"u"?t.horizontalSliderSize:0,horizontalHasArrows:typeof t.horizontalHasArrows<"u"?t.horizontalHasArrows:!1,vertical:typeof t.vertical<"u"?t.vertical:1,verticalScrollbarSize:typeof t.verticalScrollbarSize<"u"?t.verticalScrollbarSize:10,verticalHasArrows:typeof t.verticalHasArrows<"u"?t.verticalHasArrows:!1,verticalSliderSize:typeof t.verticalSliderSize<"u"?t.verticalSliderSize:0,scrollByPage:typeof t.scrollByPage<"u"?t.scrollByPage:!1};return e.horizontalSliderSize=typeof t.horizontalSliderSize<"u"?t.horizontalSliderSize:e.horizontalScrollbarSize,e.verticalSliderSize=typeof t.verticalSliderSize<"u"?t.verticalSliderSize:e.verticalScrollbarSize,As&&(e.className+=" mac"),e}var za=class extends Ve{constructor(t,e,s,i,n,o,a,l){super(),this._bufferService=s,this._optionsService=a,this._renderService=l,this._onRequestScrollLines=this._register(new re),this.onRequestScrollLines=this._onRequestScrollLines.event,this._isSyncing=!1,this._isHandlingScroll=!1,this._suppressOnScrollHandler=!1;let c=this._register(new o3({forceIntegerValues:!1,smoothScrollDuration:this._optionsService.rawOptions.smoothScrollDuration,scheduleAtNextAnimationFrame:d=>ic(i.window,d)}));this._register(this._optionsService.onSpecificOptionChange("smoothScrollDuration",()=>{c.setSmoothScrollDuration(this._optionsService.rawOptions.smoothScrollDuration)})),this._scrollableElement=this._register(new x3(e,{vertical:1,horizontal:2,useShadows:!1,mouseWheelSmoothScroll:!0,...this._getChangeOptions()},c)),this._register(this._optionsService.onMultipleOptionChange(["scrollSensitivity","fastScrollSensitivity","overviewRuler"],()=>this._scrollableElement.updateOptions(this._getChangeOptions()))),this._register(n.onProtocolChange(d=>{this._scrollableElement.updateOptions({handleMouseWheel:!(d&16)})})),this._scrollableElement.setScrollDimensions({height:0,scrollHeight:0}),this._register(yt.runAndSubscribe(o.onChangeColors,()=>{this._scrollableElement.getDomNode().style.backgroundColor=o.colors.background.css})),t.appendChild(this._scrollableElement.getDomNode()),this._register(Fe(()=>this._scrollableElement.getDomNode().remove())),this._styleElement=i.mainDocument.createElement("style"),e.appendChild(this._styleElement),this._register(Fe(()=>this._styleElement.remove())),this._register(yt.runAndSubscribe(o.onChangeColors,()=>{this._styleElement.textContent=[".xterm .xterm-scrollable-element > .scrollbar > .slider {",` background: ${o.colors.scrollbarSliderBackground.css};`,"}",".xterm .xterm-scrollable-element > .scrollbar > .slider:hover {",` background: ${o.colors.scrollbarSliderHoverBackground.css};`,"}",".xterm .xterm-scrollable-element > .scrollbar > .slider.active {",` background: ${o.colors.scrollbarSliderActiveBackground.css};`,"}"].join(`
437
- `)})),this._register(this._bufferService.onResize(()=>this.queueSync())),this._register(this._bufferService.buffers.onBufferActivate(()=>{this._latestYDisp=void 0,this.queueSync()})),this._register(this._bufferService.onScroll(()=>this._sync())),this._register(this._scrollableElement.onScroll(d=>this._handleScroll(d)))}scrollLines(t){let e=this._scrollableElement.getScrollPosition();this._scrollableElement.setScrollPosition({reuseAnimation:!0,scrollTop:e.scrollTop+t*this._renderService.dimensions.css.cell.height})}scrollToLine(t,e){e&&(this._latestYDisp=t),this._scrollableElement.setScrollPosition({reuseAnimation:!e,scrollTop:t*this._renderService.dimensions.css.cell.height})}_getChangeOptions(){return{mouseWheelScrollSensitivity:this._optionsService.rawOptions.scrollSensitivity,fastScrollSensitivity:this._optionsService.rawOptions.fastScrollSensitivity,verticalScrollbarSize:this._optionsService.rawOptions.overviewRuler?.width||14}}queueSync(t){t!==void 0&&(this._latestYDisp=t),this._queuedAnimationFrame===void 0&&(this._queuedAnimationFrame=this._renderService.addRefreshCallback(()=>{this._queuedAnimationFrame=void 0,this._sync(this._latestYDisp)}))}_sync(t=this._bufferService.buffer.ydisp){!this._renderService||this._isSyncing||(this._isSyncing=!0,this._suppressOnScrollHandler=!0,this._scrollableElement.setScrollDimensions({height:this._renderService.dimensions.css.canvas.height,scrollHeight:this._renderService.dimensions.css.cell.height*this._bufferService.buffer.lines.length}),this._suppressOnScrollHandler=!1,t!==this._latestYDisp&&this._scrollableElement.setScrollPosition({scrollTop:t*this._renderService.dimensions.css.cell.height}),this._isSyncing=!1)}_handleScroll(t){if(!this._renderService||this._isHandlingScroll||this._suppressOnScrollHandler)return;this._isHandlingScroll=!0;let e=Math.round(t.scrollTop/this._renderService.dimensions.css.cell.height),s=e-this._bufferService.buffer.ydisp;s!==0&&(this._latestYDisp=e,this._onRequestScrollLines.fire(s)),this._isHandlingScroll=!1}};za=Ye([ce(2,Lt),ce(3,Hs),ce(4,tm),ce(5,Xi),ce(6,Bt),ce(7,Ws)],za);var Fa=class extends Ve{constructor(t,e,s,i,n){super(),this._screenElement=t,this._bufferService=e,this._coreBrowserService=s,this._decorationService=i,this._renderService=n,this._decorationElements=new Map,this._altBufferIsActive=!1,this._dimensionsChanged=!1,this._container=document.createElement("div"),this._container.classList.add("xterm-decoration-container"),this._screenElement.appendChild(this._container),this._register(this._renderService.onRenderedViewportChange(()=>this._doRefreshDecorations())),this._register(this._renderService.onDimensionsChange(()=>{this._dimensionsChanged=!0,this._queueRefresh()})),this._register(this._coreBrowserService.onDprChange(()=>this._queueRefresh())),this._register(this._bufferService.buffers.onBufferActivate(()=>{this._altBufferIsActive=this._bufferService.buffer===this._bufferService.buffers.alt})),this._register(this._decorationService.onDecorationRegistered(()=>this._queueRefresh())),this._register(this._decorationService.onDecorationRemoved(o=>this._removeDecoration(o))),this._register(Fe(()=>{this._container.remove(),this._decorationElements.clear()}))}_queueRefresh(){this._animationFrame===void 0&&(this._animationFrame=this._renderService.addRefreshCallback(()=>{this._doRefreshDecorations(),this._animationFrame=void 0}))}_doRefreshDecorations(){for(let t of this._decorationService.decorations)this._renderDecoration(t);this._dimensionsChanged=!1}_renderDecoration(t){this._refreshStyle(t),this._dimensionsChanged&&this._refreshXPosition(t)}_createElement(t){let e=this._coreBrowserService.mainDocument.createElement("div");e.classList.add("xterm-decoration"),e.classList.toggle("xterm-decoration-top-layer",t?.options?.layer==="top"),e.style.width=`${Math.round((t.options.width||1)*this._renderService.dimensions.css.cell.width)}px`,e.style.height=`${(t.options.height||1)*this._renderService.dimensions.css.cell.height}px`,e.style.top=`${(t.marker.line-this._bufferService.buffers.active.ydisp)*this._renderService.dimensions.css.cell.height}px`,e.style.lineHeight=`${this._renderService.dimensions.css.cell.height}px`;let s=t.options.x??0;return s&&s>this._bufferService.cols&&(e.style.display="none"),this._refreshXPosition(t,e),e}_refreshStyle(t){let e=t.marker.line-this._bufferService.buffers.active.ydisp;if(e<0||e>=this._bufferService.rows)t.element&&(t.element.style.display="none",t.onRenderEmitter.fire(t.element));else{let s=this._decorationElements.get(t);s||(s=this._createElement(t),t.element=s,this._decorationElements.set(t,s),this._container.appendChild(s),t.onDispose(()=>{this._decorationElements.delete(t),s.remove()})),s.style.display=this._altBufferIsActive?"none":"block",this._altBufferIsActive||(s.style.width=`${Math.round((t.options.width||1)*this._renderService.dimensions.css.cell.width)}px`,s.style.height=`${(t.options.height||1)*this._renderService.dimensions.css.cell.height}px`,s.style.top=`${e*this._renderService.dimensions.css.cell.height}px`,s.style.lineHeight=`${this._renderService.dimensions.css.cell.height}px`),t.onRenderEmitter.fire(s)}}_refreshXPosition(t,e=t.element){if(!e)return;let s=t.options.x??0;(t.options.anchor||"left")==="right"?e.style.right=s?`${s*this._renderService.dimensions.css.cell.width}px`:"":e.style.left=s?`${s*this._renderService.dimensions.css.cell.width}px`:""}_removeDecoration(t){this._decorationElements.get(t)?.remove(),this._decorationElements.delete(t),t.dispose()}};Fa=Ye([ce(1,Lt),ce(2,Hs),ce(3,tn),ce(4,Ws)],Fa);var b3=class{constructor(){this._zones=[],this._zonePool=[],this._zonePoolIndex=0,this._linePadding={full:0,left:0,center:0,right:0}}get zones(){return this._zonePool.length=Math.min(this._zonePool.length,this._zones.length),this._zones}clear(){this._zones.length=0,this._zonePoolIndex=0}addDecoration(t){if(t.options.overviewRulerOptions){for(let e of this._zones)if(e.color===t.options.overviewRulerOptions.color&&e.position===t.options.overviewRulerOptions.position){if(this._lineIntersectsZone(e,t.marker.line))return;if(this._lineAdjacentToZone(e,t.marker.line,t.options.overviewRulerOptions.position)){this._addLineToZone(e,t.marker.line);return}}if(this._zonePoolIndex<this._zonePool.length){this._zonePool[this._zonePoolIndex].color=t.options.overviewRulerOptions.color,this._zonePool[this._zonePoolIndex].position=t.options.overviewRulerOptions.position,this._zonePool[this._zonePoolIndex].startBufferLine=t.marker.line,this._zonePool[this._zonePoolIndex].endBufferLine=t.marker.line,this._zones.push(this._zonePool[this._zonePoolIndex++]);return}this._zones.push({color:t.options.overviewRulerOptions.color,position:t.options.overviewRulerOptions.position,startBufferLine:t.marker.line,endBufferLine:t.marker.line}),this._zonePool.push(this._zones[this._zones.length-1]),this._zonePoolIndex++}}setPadding(t){this._linePadding=t}_lineIntersectsZone(t,e){return e>=t.startBufferLine&&e<=t.endBufferLine}_lineAdjacentToZone(t,e,s){return e>=t.startBufferLine-this._linePadding[s||"full"]&&e<=t.endBufferLine+this._linePadding[s||"full"]}_addLineToZone(t,e){t.startBufferLine=Math.min(t.startBufferLine,e),t.endBufferLine=Math.max(t.endBufferLine,e)}},xs={full:0,left:0,center:0,right:0},Ks={full:0,left:0,center:0,right:0},ir={full:0,left:0,center:0,right:0},Gn=class extends Ve{constructor(t,e,s,i,n,o,a,l){super(),this._viewportElement=t,this._screenElement=e,this._bufferService=s,this._decorationService=i,this._renderService=n,this._optionsService=o,this._themeService=a,this._coreBrowserService=l,this._colorZoneStore=new b3,this._shouldUpdateDimensions=!0,this._shouldUpdateAnchor=!0,this._lastKnownBufferLength=0,this._canvas=this._coreBrowserService.mainDocument.createElement("canvas"),this._canvas.classList.add("xterm-decoration-overview-ruler"),this._refreshCanvasDimensions(),this._viewportElement.parentElement?.insertBefore(this._canvas,this._viewportElement),this._register(Fe(()=>this._canvas?.remove()));let c=this._canvas.getContext("2d");if(c)this._ctx=c;else throw new Error("Ctx cannot be null");this._register(this._decorationService.onDecorationRegistered(()=>this._queueRefresh(void 0,!0))),this._register(this._decorationService.onDecorationRemoved(()=>this._queueRefresh(void 0,!0))),this._register(this._renderService.onRenderedViewportChange(()=>this._queueRefresh())),this._register(this._bufferService.buffers.onBufferActivate(()=>{this._canvas.style.display=this._bufferService.buffer===this._bufferService.buffers.alt?"none":"block"})),this._register(this._bufferService.onScroll(()=>{this._lastKnownBufferLength!==this._bufferService.buffers.normal.lines.length&&(this._refreshDrawHeightConstants(),this._refreshColorZonePadding())})),this._register(this._renderService.onRender(()=>{(!this._containerHeight||this._containerHeight!==this._screenElement.clientHeight)&&(this._queueRefresh(!0),this._containerHeight=this._screenElement.clientHeight)})),this._register(this._coreBrowserService.onDprChange(()=>this._queueRefresh(!0))),this._register(this._optionsService.onSpecificOptionChange("overviewRuler",()=>this._queueRefresh(!0))),this._register(this._themeService.onChangeColors(()=>this._queueRefresh())),this._queueRefresh(!0)}get _width(){return this._optionsService.options.overviewRuler?.width||0}_refreshDrawConstants(){let t=Math.floor((this._canvas.width-1)/3),e=Math.ceil((this._canvas.width-1)/3);Ks.full=this._canvas.width,Ks.left=t,Ks.center=e,Ks.right=t,this._refreshDrawHeightConstants(),ir.full=1,ir.left=1,ir.center=1+Ks.left,ir.right=1+Ks.left+Ks.center}_refreshDrawHeightConstants(){xs.full=Math.round(2*this._coreBrowserService.dpr);let t=this._canvas.height/this._bufferService.buffer.lines.length,e=Math.round(Math.max(Math.min(t,12),6)*this._coreBrowserService.dpr);xs.left=e,xs.center=e,xs.right=e}_refreshColorZonePadding(){this._colorZoneStore.setPadding({full:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*xs.full),left:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*xs.left),center:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*xs.center),right:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*xs.right)}),this._lastKnownBufferLength=this._bufferService.buffers.normal.lines.length}_refreshCanvasDimensions(){this._canvas.style.width=`${this._width}px`,this._canvas.width=Math.round(this._width*this._coreBrowserService.dpr),this._canvas.style.height=`${this._screenElement.clientHeight}px`,this._canvas.height=Math.round(this._screenElement.clientHeight*this._coreBrowserService.dpr),this._refreshDrawConstants(),this._refreshColorZonePadding()}_refreshDecorations(){this._shouldUpdateDimensions&&this._refreshCanvasDimensions(),this._ctx.clearRect(0,0,this._canvas.width,this._canvas.height),this._colorZoneStore.clear();for(let e of this._decorationService.decorations)this._colorZoneStore.addDecoration(e);this._ctx.lineWidth=1,this._renderRulerOutline();let t=this._colorZoneStore.zones;for(let e of t)e.position!=="full"&&this._renderColorZone(e);for(let e of t)e.position==="full"&&this._renderColorZone(e);this._shouldUpdateDimensions=!1,this._shouldUpdateAnchor=!1}_renderRulerOutline(){this._ctx.fillStyle=this._themeService.colors.overviewRulerBorder.css,this._ctx.fillRect(0,0,1,this._canvas.height),this._optionsService.rawOptions.overviewRuler.showTopBorder&&this._ctx.fillRect(1,0,this._canvas.width-1,1),this._optionsService.rawOptions.overviewRuler.showBottomBorder&&this._ctx.fillRect(1,this._canvas.height-1,this._canvas.width-1,this._canvas.height)}_renderColorZone(t){this._ctx.fillStyle=t.color,this._ctx.fillRect(ir[t.position||"full"],Math.round((this._canvas.height-1)*(t.startBufferLine/this._bufferService.buffers.active.lines.length)-xs[t.position||"full"]/2),Ks[t.position||"full"],Math.round((this._canvas.height-1)*((t.endBufferLine-t.startBufferLine)/this._bufferService.buffers.active.lines.length)+xs[t.position||"full"]))}_queueRefresh(t,e){this._shouldUpdateDimensions=t||this._shouldUpdateDimensions,this._shouldUpdateAnchor=e||this._shouldUpdateAnchor,this._animationFrame===void 0&&(this._animationFrame=this._coreBrowserService.window.requestAnimationFrame(()=>{this._refreshDecorations(),this._animationFrame=void 0}))}};Gn=Ye([ce(2,Lt),ce(3,tn),ce(4,Ws),ce(5,Bt),ce(6,Xi),ce(7,Hs)],Gn);var Z;(t=>(t.NUL="\0",t.SOH="",t.STX="",t.ETX="",t.EOT="",t.ENQ="",t.ACK="",t.BEL="\x07",t.BS="\b",t.HT=" ",t.LF=`
438
- `,t.VT="\v",t.FF="\f",t.CR="\r",t.SO="",t.SI="",t.DLE="",t.DC1="",t.DC2="",t.DC3="",t.DC4="",t.NAK="",t.SYN="",t.ETB="",t.CAN="",t.EM="",t.SUB="",t.ESC="\x1B",t.FS="",t.GS="",t.RS="",t.US="",t.SP=" ",t.DEL=""))(Z||={});var Rn;(t=>(t.PAD="€",t.HOP="",t.BPH="‚",t.NBH="ƒ",t.IND="„",t.NEL="…",t.SSA="†",t.ESA="‡",t.HTS="ˆ",t.HTJ="‰",t.VTS="Š",t.PLD="‹",t.PLU="Œ",t.RI="",t.SS2="Ž",t.SS3="",t.DCS="",t.PU1="‘",t.PU2="’",t.STS="“",t.CCH="”",t.MW="•",t.SPA="–",t.EPA="—",t.SOS="˜",t.SGCI="™",t.SCI="š",t.CSI="›",t.ST="œ",t.OSC="",t.PM="ž",t.APC="Ÿ"))(Rn||={});var Sm;(t=>t.ST=`${Z.ESC}\\`)(Sm||={});var Ha=class{constructor(t,e,s,i,n,o){this._textarea=t,this._compositionView=e,this._bufferService=s,this._optionsService=i,this._coreService=n,this._renderService=o,this._isComposing=!1,this._isSendingComposition=!1,this._compositionPosition={start:0,end:0},this._dataAlreadySent=""}get isComposing(){return this._isComposing}compositionstart(){this._isComposing=!0,this._compositionPosition.start=this._textarea.value.length,this._compositionView.textContent="",this._dataAlreadySent="",this._compositionView.classList.add("active")}compositionupdate(t){this._compositionView.textContent=t.data,this.updateCompositionElements(),setTimeout(()=>{this._compositionPosition.end=this._textarea.value.length},0)}compositionend(){this._finalizeComposition(!0)}keydown(t){if(this._isComposing||this._isSendingComposition){if(t.keyCode===20||t.keyCode===229||t.keyCode===16||t.keyCode===17||t.keyCode===18)return!1;this._finalizeComposition(!1)}return t.keyCode===229?(this._handleAnyTextareaChanges(),!1):!0}_finalizeComposition(t){if(this._compositionView.classList.remove("active"),this._isComposing=!1,t){let e={start:this._compositionPosition.start,end:this._compositionPosition.end};this._isSendingComposition=!0,setTimeout(()=>{if(this._isSendingComposition){this._isSendingComposition=!1;let s;e.start+=this._dataAlreadySent.length,this._isComposing?s=this._textarea.value.substring(e.start,this._compositionPosition.start):s=this._textarea.value.substring(e.start),s.length>0&&this._coreService.triggerDataEvent(s,!0)}},0)}else{this._isSendingComposition=!1;let e=this._textarea.value.substring(this._compositionPosition.start,this._compositionPosition.end);this._coreService.triggerDataEvent(e,!0)}}_handleAnyTextareaChanges(){let t=this._textarea.value;setTimeout(()=>{if(!this._isComposing){let e=this._textarea.value,s=e.replace(t,"");this._dataAlreadySent=s,e.length>t.length?this._coreService.triggerDataEvent(s,!0):e.length<t.length?this._coreService.triggerDataEvent(`${Z.DEL}`,!0):e.length===t.length&&e!==t&&this._coreService.triggerDataEvent(e,!0)}},0)}updateCompositionElements(t){if(this._isComposing){if(this._bufferService.buffer.isCursorInViewport){let e=Math.min(this._bufferService.buffer.x,this._bufferService.cols-1),s=this._renderService.dimensions.css.cell.height,i=this._bufferService.buffer.y*this._renderService.dimensions.css.cell.height,n=e*this._renderService.dimensions.css.cell.width;this._compositionView.style.left=n+"px",this._compositionView.style.top=i+"px",this._compositionView.style.height=s+"px",this._compositionView.style.lineHeight=s+"px",this._compositionView.style.fontFamily=this._optionsService.rawOptions.fontFamily,this._compositionView.style.fontSize=this._optionsService.rawOptions.fontSize+"px";let o=this._compositionView.getBoundingClientRect();this._textarea.style.left=n+"px",this._textarea.style.top=i+"px",this._textarea.style.width=Math.max(o.width,1)+"px",this._textarea.style.height=Math.max(o.height,1)+"px",this._textarea.style.lineHeight=o.height+"px"}t||setTimeout(()=>this.updateCompositionElements(!0),0)}}};Ha=Ye([ce(2,Lt),ce(3,Bt),ce(4,Ci),ce(5,Ws)],Ha);var ft=0,mt=0,pt=0,Ge=0,Od={css:"#00000000",rgba:0},et;(t=>{function e(n,o,a,l){return l!==void 0?`#${di(n)}${di(o)}${di(a)}${di(l)}`:`#${di(n)}${di(o)}${di(a)}`}t.toCss=e;function s(n,o,a,l=255){return(n<<24|o<<16|a<<8|l)>>>0}t.toRgba=s;function i(n,o,a,l){return{css:t.toCss(n,o,a,l),rgba:t.toRgba(n,o,a,l)}}t.toColor=i})(et||={});var Le;(t=>{function e(c,d){if(Ge=(d.rgba&255)/255,Ge===1)return{css:d.css,rgba:d.rgba};let u=d.rgba>>24&255,h=d.rgba>>16&255,f=d.rgba>>8&255,m=c.rgba>>24&255,p=c.rgba>>16&255,g=c.rgba>>8&255;ft=m+Math.round((u-m)*Ge),mt=p+Math.round((h-p)*Ge),pt=g+Math.round((f-g)*Ge);let _=et.toCss(ft,mt,pt),v=et.toRgba(ft,mt,pt);return{css:_,rgba:v}}t.blend=e;function s(c){return(c.rgba&255)===255}t.isOpaque=s;function i(c,d,u){let h=Tn.ensureContrastRatio(c.rgba,d.rgba,u);if(h)return et.toColor(h>>24&255,h>>16&255,h>>8&255)}t.ensureContrastRatio=i;function n(c){let d=(c.rgba|255)>>>0;return[ft,mt,pt]=Tn.toChannels(d),{css:et.toCss(ft,mt,pt),rgba:d}}t.opaque=n;function o(c,d){return Ge=Math.round(d*255),[ft,mt,pt]=Tn.toChannels(c.rgba),{css:et.toCss(ft,mt,pt,Ge),rgba:et.toRgba(ft,mt,pt,Ge)}}t.opacity=o;function a(c,d){return Ge=c.rgba&255,o(c,Ge*d/255)}t.multiplyOpacity=a;function l(c){return[c.rgba>>24&255,c.rgba>>16&255,c.rgba>>8&255]}t.toColorRGB=l})(Le||={});var Ue;(t=>{let e,s;try{let n=document.createElement("canvas");n.width=1,n.height=1;let o=n.getContext("2d",{willReadFrequently:!0});o&&(e=o,e.globalCompositeOperation="copy",s=e.createLinearGradient(0,0,1,1))}catch{}function i(n){if(n.match(/#[\da-f]{3,8}/i))switch(n.length){case 4:return ft=parseInt(n.slice(1,2).repeat(2),16),mt=parseInt(n.slice(2,3).repeat(2),16),pt=parseInt(n.slice(3,4).repeat(2),16),et.toColor(ft,mt,pt);case 5:return ft=parseInt(n.slice(1,2).repeat(2),16),mt=parseInt(n.slice(2,3).repeat(2),16),pt=parseInt(n.slice(3,4).repeat(2),16),Ge=parseInt(n.slice(4,5).repeat(2),16),et.toColor(ft,mt,pt,Ge);case 7:return{css:n,rgba:(parseInt(n.slice(1),16)<<8|255)>>>0};case 9:return{css:n,rgba:parseInt(n.slice(1),16)>>>0}}let o=n.match(/rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(,\s*(0|1|\d?\.(\d+))\s*)?\)/);if(o)return ft=parseInt(o[1]),mt=parseInt(o[2]),pt=parseInt(o[3]),Ge=Math.round((o[5]===void 0?1:parseFloat(o[5]))*255),et.toColor(ft,mt,pt,Ge);if(!e||!s)throw new Error("css.toColor: Unsupported css format");if(e.fillStyle=s,e.fillStyle=n,typeof e.fillStyle!="string")throw new Error("css.toColor: Unsupported css format");if(e.fillRect(0,0,1,1),[ft,mt,pt,Ge]=e.getImageData(0,0,1,1).data,Ge!==255)throw new Error("css.toColor: Unsupported css format");return{rgba:et.toRgba(ft,mt,pt,Ge),css:n}}t.toColor=i})(Ue||={});var At;(t=>{function e(i){return s(i>>16&255,i>>8&255,i&255)}t.relativeLuminance=e;function s(i,n,o){let a=i/255,l=n/255,c=o/255,d=a<=.03928?a/12.92:Math.pow((a+.055)/1.055,2.4),u=l<=.03928?l/12.92:Math.pow((l+.055)/1.055,2.4),h=c<=.03928?c/12.92:Math.pow((c+.055)/1.055,2.4);return d*.2126+u*.7152+h*.0722}t.relativeLuminance2=s})(At||={});var Tn;(t=>{function e(a,l){if(Ge=(l&255)/255,Ge===1)return l;let c=l>>24&255,d=l>>16&255,u=l>>8&255,h=a>>24&255,f=a>>16&255,m=a>>8&255;return ft=h+Math.round((c-h)*Ge),mt=f+Math.round((d-f)*Ge),pt=m+Math.round((u-m)*Ge),et.toRgba(ft,mt,pt)}t.blend=e;function s(a,l,c){let d=At.relativeLuminance(a>>8),u=At.relativeLuminance(l>>8);if(Ls(d,u)<c){if(u<d){let m=i(a,l,c),p=Ls(d,At.relativeLuminance(m>>8));if(p<c){let g=n(a,l,c),_=Ls(d,At.relativeLuminance(g>>8));return p>_?m:g}return m}let h=n(a,l,c),f=Ls(d,At.relativeLuminance(h>>8));if(f<c){let m=i(a,l,c),p=Ls(d,At.relativeLuminance(m>>8));return f>p?h:m}return h}}t.ensureContrastRatio=s;function i(a,l,c){let d=a>>24&255,u=a>>16&255,h=a>>8&255,f=l>>24&255,m=l>>16&255,p=l>>8&255,g=Ls(At.relativeLuminance2(f,m,p),At.relativeLuminance2(d,u,h));for(;g<c&&(f>0||m>0||p>0);)f-=Math.max(0,Math.ceil(f*.1)),m-=Math.max(0,Math.ceil(m*.1)),p-=Math.max(0,Math.ceil(p*.1)),g=Ls(At.relativeLuminance2(f,m,p),At.relativeLuminance2(d,u,h));return(f<<24|m<<16|p<<8|255)>>>0}t.reduceLuminance=i;function n(a,l,c){let d=a>>24&255,u=a>>16&255,h=a>>8&255,f=l>>24&255,m=l>>16&255,p=l>>8&255,g=Ls(At.relativeLuminance2(f,m,p),At.relativeLuminance2(d,u,h));for(;g<c&&(f<255||m<255||p<255);)f=Math.min(255,f+Math.ceil((255-f)*.1)),m=Math.min(255,m+Math.ceil((255-m)*.1)),p=Math.min(255,p+Math.ceil((255-p)*.1)),g=Ls(At.relativeLuminance2(f,m,p),At.relativeLuminance2(d,u,h));return(f<<24|m<<16|p<<8|255)>>>0}t.increaseLuminance=n;function o(a){return[a>>24&255,a>>16&255,a>>8&255,a&255]}t.toChannels=o})(Tn||={});function di(t){let e=t.toString(16);return e.length<2?"0"+e:e}function Ls(t,e){return t<e?(e+.05)/(t+.05):(t+.05)/(e+.05)}var y3=class extends en{constructor(t,e,s){super(),this.content=0,this.combinedData="",this.fg=t.fg,this.bg=t.bg,this.combinedData=e,this._width=s}isCombined(){return 2097152}getWidth(){return this._width}getChars(){return this.combinedData}getCode(){return 2097151}setFromCharData(t){throw new Error("not implemented")}getAsCharData(){return[this.fg,this.getChars(),this.getWidth(),this.getCode()]}},Yn=class{constructor(t){this._bufferService=t,this._characterJoiners=[],this._nextCharacterJoinerId=0,this._workCell=new as}register(t){let e={id:this._nextCharacterJoinerId++,handler:t};return this._characterJoiners.push(e),e.id}deregister(t){for(let e=0;e<this._characterJoiners.length;e++)if(this._characterJoiners[e].id===t)return this._characterJoiners.splice(e,1),!0;return!1}getJoinedCharacters(t){if(this._characterJoiners.length===0)return[];let e=this._bufferService.buffer.lines.get(t);if(!e||e.length===0)return[];let s=[],i=e.translateToString(!0),n=0,o=0,a=0,l=e.getFg(0),c=e.getBg(0);for(let d=0;d<e.getTrimmedLength();d++)if(e.loadCell(d,this._workCell),this._workCell.getWidth()!==0){if(this._workCell.fg!==l||this._workCell.bg!==c){if(d-n>1){let u=this._getJoinedRanges(i,a,o,e,n);for(let h=0;h<u.length;h++)s.push(u[h])}n=d,a=o,l=this._workCell.fg,c=this._workCell.bg}o+=this._workCell.getChars().length||Xs.length}if(this._bufferService.cols-n>1){let d=this._getJoinedRanges(i,a,o,e,n);for(let u=0;u<d.length;u++)s.push(d[u])}return s}_getJoinedRanges(t,e,s,i,n){let o=t.substring(e,s),a=[];try{a=this._characterJoiners[0].handler(o)}catch(l){console.error(l)}for(let l=1;l<this._characterJoiners.length;l++)try{let c=this._characterJoiners[l].handler(o);for(let d=0;d<c.length;d++)Yn._mergeRanges(a,c[d])}catch(c){console.error(c)}return this._stringRangesToCellRanges(a,i,n),a}_stringRangesToCellRanges(t,e,s){let i=0,n=!1,o=0,a=t[i];if(a){for(let l=s;l<this._bufferService.cols;l++){let c=e.getWidth(l),d=e.getString(l).length||Xs.length;if(c!==0){if(!n&&a[0]<=o&&(a[0]=l,n=!0),a[1]<=o){if(a[1]=l,a=t[++i],!a)break;a[0]<=o?(a[0]=l,n=!0):n=!1}o+=d}}a&&(a[1]=this._bufferService.cols)}}static _mergeRanges(t,e){let s=!1;for(let i=0;i<t.length;i++){let n=t[i];if(s){if(e[1]<=n[0])return t[i-1][1]=e[1],t;if(e[1]<=n[1])return t[i-1][1]=Math.max(e[1],n[1]),t.splice(i,1),t;t.splice(i,1),i--}else{if(e[1]<=n[0])return t.splice(i,0,e),t;if(e[1]<=n[1])return n[0]=Math.min(e[0],n[0]),t;e[0]<n[1]&&(n[0]=Math.min(e[0],n[0]),s=!0);continue}}return s?t[t.length-1][1]=e[1]:t.push(e),t}};Yn=Ye([ce(0,Lt)],Yn);function S3(t){return 57508<=t&&t<=57558}function w3(t){return 9472<=t&&t<=9631}function V3(t){return S3(t)||w3(t)}function C3(){return{css:{canvas:pn(),cell:pn()},device:{canvas:pn(),cell:pn(),char:{width:0,height:0,left:0,top:0}}}}function pn(){return{width:0,height:0}}var Wa=class{constructor(t,e,s,i,n,o,a){this._document=t,this._characterJoinerService=e,this._optionsService=s,this._coreBrowserService=i,this._coreService=n,this._decorationService=o,this._themeService=a,this._workCell=new as,this._columnSelectMode=!1,this.defaultSpacing=0}handleSelectionChanged(t,e,s){this._selectionStart=t,this._selectionEnd=e,this._columnSelectMode=s}createRow(t,e,s,i,n,o,a,l,c,d,u){let h=[],f=this._characterJoinerService.getJoinedCharacters(e),m=this._themeService.colors,p=t.getNoBgTrimmedLength();s&&p<o+1&&(p=o+1);let g,_=0,v="",x=0,b=0,y=0,C=0,j=!1,V=0,w=!1,k=0,T=0,I=[],A=d!==-1&&u!==-1;for(let N=0;N<p;N++){t.loadCell(N,this._workCell);let E=this._workCell.getWidth();if(E===0)continue;let R=!1,M=N>=T,L=N,D=this._workCell;if(f.length>0&&N===f[0][0]&&M){let J=f.shift(),ie=this._isCellInSelection(J[0],e);for(x=J[0]+1;x<J[1];x++)M&&=ie===this._isCellInSelection(x,e);M&&=!s||o<J[0]||o>=J[1],M?(R=!0,D=new y3(this._workCell,t.translateToString(!0,J[0],J[1]),J[1]-J[0]),L=J[1]-1,E=D.getWidth()):T=J[1]}let P=this._isCellInSelection(N,e),O=s&&N===o,z=A&&N>=d&&N<=u,$=!1;this._decorationService.forEachDecorationAtCell(N,e,void 0,J=>{$=!0});let W=D.getChars()||Xs;if(W===" "&&(D.isUnderline()||D.isOverline())&&(W=" "),k=E*l-c.get(W,D.isBold(),D.isItalic()),!g)g=this._document.createElement("span");else if(_&&(P&&w||!P&&!w&&D.bg===b)&&(P&&w&&m.selectionForeground||D.fg===y)&&D.extended.ext===C&&z===j&&k===V&&!O&&!R&&!$&&M){D.isInvisible()?v+=Xs:v+=W,_++;continue}else _&&(g.textContent=v),g=this._document.createElement("span"),_=0,v="";if(b=D.bg,y=D.fg,C=D.extended.ext,j=z,V=k,w=P,R&&o>=N&&o<=L&&(o=N),!this._coreService.isCursorHidden&&O&&this._coreService.isCursorInitialized){if(I.push("xterm-cursor"),this._coreBrowserService.isFocused)a&&I.push("xterm-cursor-blink"),I.push(i==="bar"?"xterm-cursor-bar":i==="underline"?"xterm-cursor-underline":"xterm-cursor-block");else if(n)switch(n){case"outline":I.push("xterm-cursor-outline");break;case"block":I.push("xterm-cursor-block");break;case"bar":I.push("xterm-cursor-bar");break;case"underline":I.push("xterm-cursor-underline");break}}if(D.isBold()&&I.push("xterm-bold"),D.isItalic()&&I.push("xterm-italic"),D.isDim()&&I.push("xterm-dim"),D.isInvisible()?v=Xs:v=D.getChars()||Xs,D.isUnderline()&&(I.push(`xterm-underline-${D.extended.underlineStyle}`),v===" "&&(v=" "),!D.isUnderlineColorDefault()))if(D.isUnderlineColorRGB())g.style.textDecorationColor=`rgb(${en.toColorRGB(D.getUnderlineColor()).join(",")})`;else{let J=D.getUnderlineColor();this._optionsService.rawOptions.drawBoldTextInBrightColors&&D.isBold()&&J<8&&(J+=8),g.style.textDecorationColor=m.ansi[J].css}D.isOverline()&&(I.push("xterm-overline"),v===" "&&(v=" ")),D.isStrikethrough()&&I.push("xterm-strikethrough"),z&&(g.style.textDecoration="underline");let F=D.getFgColor(),G=D.getFgColorMode(),q=D.getBgColor(),H=D.getBgColorMode(),ee=!!D.isInverse();if(ee){let J=F;F=q,q=J;let ie=G;G=H,H=ie}let K,U,te=!1;this._decorationService.forEachDecorationAtCell(N,e,void 0,J=>{J.options.layer!=="top"&&te||(J.backgroundColorRGB&&(H=50331648,q=J.backgroundColorRGB.rgba>>8&16777215,K=J.backgroundColorRGB),J.foregroundColorRGB&&(G=50331648,F=J.foregroundColorRGB.rgba>>8&16777215,U=J.foregroundColorRGB),te=J.options.layer==="top")}),!te&&P&&(K=this._coreBrowserService.isFocused?m.selectionBackgroundOpaque:m.selectionInactiveBackgroundOpaque,q=K.rgba>>8&16777215,H=50331648,te=!0,m.selectionForeground&&(G=50331648,F=m.selectionForeground.rgba>>8&16777215,U=m.selectionForeground)),te&&I.push("xterm-decoration-top");let Y;switch(H){case 16777216:case 33554432:Y=m.ansi[q],I.push(`xterm-bg-${q}`);break;case 50331648:Y=et.toColor(q>>16,q>>8&255,q&255),this._addStyle(g,`background-color:#${$d((q>>>0).toString(16),"0",6)}`);break;default:ee?(Y=m.foreground,I.push("xterm-bg-257")):Y=m.background}switch(K||D.isDim()&&(K=Le.multiplyOpacity(Y,.5)),G){case 16777216:case 33554432:D.isBold()&&F<8&&this._optionsService.rawOptions.drawBoldTextInBrightColors&&(F+=8),this._applyMinimumContrast(g,Y,m.ansi[F],D,K,void 0)||I.push(`xterm-fg-${F}`);break;case 50331648:let J=et.toColor(F>>16&255,F>>8&255,F&255);this._applyMinimumContrast(g,Y,J,D,K,U)||this._addStyle(g,`color:#${$d(F.toString(16),"0",6)}`);break;default:this._applyMinimumContrast(g,Y,m.foreground,D,K,U)||ee&&I.push("xterm-fg-257")}I.length&&(g.className=I.join(" "),I.length=0),!O&&!R&&!$&&M?_++:g.textContent=v,k!==this.defaultSpacing&&(g.style.letterSpacing=`${k}px`),h.push(g),N=L}return g&&_&&(g.textContent=v),h}_applyMinimumContrast(t,e,s,i,n,o){if(this._optionsService.rawOptions.minimumContrastRatio===1||V3(i.getCode()))return!1;let a=this._getContrastCache(i),l;if(!n&&!o&&(l=a.getColor(e.rgba,s.rgba)),l===void 0){let c=this._optionsService.rawOptions.minimumContrastRatio/(i.isDim()?2:1);l=Le.ensureContrastRatio(n||e,o||s,c),a.setColor((n||e).rgba,(o||s).rgba,l??null)}return l?(this._addStyle(t,`color:${l.css}`),!0):!1}_getContrastCache(t){return t.isDim()?this._themeService.colors.halfContrastCache:this._themeService.colors.contrastCache}_addStyle(t,e){t.setAttribute("style",`${t.getAttribute("style")||""}${e};`)}_isCellInSelection(t,e){let s=this._selectionStart,i=this._selectionEnd;return!s||!i?!1:this._columnSelectMode?s[0]<=i[0]?t>=s[0]&&e>=s[1]&&t<i[0]&&e<=i[1]:t<s[0]&&e>=s[1]&&t>=i[0]&&e<=i[1]:e>s[1]&&e<i[1]||s[1]===i[1]&&e===s[1]&&t>=s[0]&&t<i[0]||s[1]<i[1]&&e===i[1]&&t<i[0]||s[1]<i[1]&&e===s[1]&&t>=s[0]}};Wa=Ye([ce(1,rm),ce(2,Bt),ce(3,Hs),ce(4,Ci),ce(5,tn),ce(6,Xi)],Wa);function $d(t,e,s){for(;t.length<s;)t=e+t;return t}var j3=class{constructor(t,e){this._flat=new Float32Array(256),this._font="",this._fontSize=0,this._weight="normal",this._weightBold="bold",this._measureElements=[],this._container=t.createElement("div"),this._container.classList.add("xterm-width-cache-measure-container"),this._container.setAttribute("aria-hidden","true"),this._container.style.whiteSpace="pre",this._container.style.fontKerning="none";let s=t.createElement("span");s.classList.add("xterm-char-measure-element");let i=t.createElement("span");i.classList.add("xterm-char-measure-element"),i.style.fontWeight="bold";let n=t.createElement("span");n.classList.add("xterm-char-measure-element"),n.style.fontStyle="italic";let o=t.createElement("span");o.classList.add("xterm-char-measure-element"),o.style.fontWeight="bold",o.style.fontStyle="italic",this._measureElements=[s,i,n,o],this._container.appendChild(s),this._container.appendChild(i),this._container.appendChild(n),this._container.appendChild(o),e.appendChild(this._container),this.clear()}dispose(){this._container.remove(),this._measureElements.length=0,this._holey=void 0}clear(){this._flat.fill(-9999),this._holey=new Map}setFont(t,e,s,i){t===this._font&&e===this._fontSize&&s===this._weight&&i===this._weightBold||(this._font=t,this._fontSize=e,this._weight=s,this._weightBold=i,this._container.style.fontFamily=this._font,this._container.style.fontSize=`${this._fontSize}px`,this._measureElements[0].style.fontWeight=`${s}`,this._measureElements[1].style.fontWeight=`${i}`,this._measureElements[2].style.fontWeight=`${s}`,this._measureElements[3].style.fontWeight=`${i}`,this.clear())}get(t,e,s){let i=0;if(!e&&!s&&t.length===1&&(i=t.charCodeAt(0))<256){if(this._flat[i]!==-9999)return this._flat[i];let a=this._measure(t,0);return a>0&&(this._flat[i]=a),a}let n=t;e&&(n+="B"),s&&(n+="I");let o=this._holey.get(n);if(o===void 0){let a=0;e&&(a|=1),s&&(a|=2),o=this._measure(t,a),o>0&&this._holey.set(n,o)}return o}_measure(t,e){let s=this._measureElements[e];return s.textContent=t.repeat(32),s.offsetWidth/32}},k3=class{constructor(){this.clear()}clear(){this.hasSelection=!1,this.columnSelectMode=!1,this.viewportStartRow=0,this.viewportEndRow=0,this.viewportCappedStartRow=0,this.viewportCappedEndRow=0,this.startCol=0,this.endCol=0,this.selectionStart=void 0,this.selectionEnd=void 0}update(t,e,s,i=!1){if(this.selectionStart=e,this.selectionEnd=s,!e||!s||e[0]===s[0]&&e[1]===s[1]){this.clear();return}let n=t.buffers.active.ydisp,o=e[1]-n,a=s[1]-n,l=Math.max(o,0),c=Math.min(a,t.rows-1);if(l>=t.rows||c<0){this.clear();return}this.hasSelection=!0,this.columnSelectMode=i,this.viewportStartRow=o,this.viewportEndRow=a,this.viewportCappedStartRow=l,this.viewportCappedEndRow=c,this.startCol=e[0],this.endCol=s[0]}isCellSelected(t,e,s){return this.hasSelection?(s-=t.buffer.active.viewportY,this.columnSelectMode?this.startCol<=this.endCol?e>=this.startCol&&s>=this.viewportCappedStartRow&&e<this.endCol&&s<=this.viewportCappedEndRow:e<this.startCol&&s>=this.viewportCappedStartRow&&e>=this.endCol&&s<=this.viewportCappedEndRow:s>this.viewportStartRow&&s<this.viewportEndRow||this.viewportStartRow===this.viewportEndRow&&s===this.viewportStartRow&&e>=this.startCol&&e<this.endCol||this.viewportStartRow<this.viewportEndRow&&s===this.viewportEndRow&&e<this.endCol||this.viewportStartRow<this.viewportEndRow&&s===this.viewportStartRow&&e>=this.startCol):!1}};function N3(){return new k3}var qo="xterm-dom-renderer-owner-",ss="xterm-rows",gn="xterm-fg-",zd="xterm-bg-",rr="xterm-focus",_n="xterm-selection",A3=1,Ua=class extends Ve{constructor(t,e,s,i,n,o,a,l,c,d,u,h,f,m){super(),this._terminal=t,this._document=e,this._element=s,this._screenElement=i,this._viewportElement=n,this._helperContainer=o,this._linkifier2=a,this._charSizeService=c,this._optionsService=d,this._bufferService=u,this._coreService=h,this._coreBrowserService=f,this._themeService=m,this._terminalClass=A3++,this._rowElements=[],this._selectionRenderModel=N3(),this.onRequestRedraw=this._register(new re).event,this._rowContainer=this._document.createElement("div"),this._rowContainer.classList.add(ss),this._rowContainer.style.lineHeight="normal",this._rowContainer.setAttribute("aria-hidden","true"),this._refreshRowElements(this._bufferService.cols,this._bufferService.rows),this._selectionContainer=this._document.createElement("div"),this._selectionContainer.classList.add(_n),this._selectionContainer.setAttribute("aria-hidden","true"),this.dimensions=C3(),this._updateDimensions(),this._register(this._optionsService.onOptionChange(()=>this._handleOptionsChanged())),this._register(this._themeService.onChangeColors(p=>this._injectCss(p))),this._injectCss(this._themeService.colors),this._rowFactory=l.createInstance(Wa,document),this._element.classList.add(qo+this._terminalClass),this._screenElement.appendChild(this._rowContainer),this._screenElement.appendChild(this._selectionContainer),this._register(this._linkifier2.onShowLinkUnderline(p=>this._handleLinkHover(p))),this._register(this._linkifier2.onHideLinkUnderline(p=>this._handleLinkLeave(p))),this._register(Fe(()=>{this._element.classList.remove(qo+this._terminalClass),this._rowContainer.remove(),this._selectionContainer.remove(),this._widthCache.dispose(),this._themeStyleElement.remove(),this._dimensionsStyleElement.remove()})),this._widthCache=new j3(this._document,this._helperContainer),this._widthCache.setFont(this._optionsService.rawOptions.fontFamily,this._optionsService.rawOptions.fontSize,this._optionsService.rawOptions.fontWeight,this._optionsService.rawOptions.fontWeightBold),this._setDefaultSpacing()}_updateDimensions(){let t=this._coreBrowserService.dpr;this.dimensions.device.char.width=this._charSizeService.width*t,this.dimensions.device.char.height=Math.ceil(this._charSizeService.height*t),this.dimensions.device.cell.width=this.dimensions.device.char.width+Math.round(this._optionsService.rawOptions.letterSpacing),this.dimensions.device.cell.height=Math.floor(this.dimensions.device.char.height*this._optionsService.rawOptions.lineHeight),this.dimensions.device.char.left=0,this.dimensions.device.char.top=0,this.dimensions.device.canvas.width=this.dimensions.device.cell.width*this._bufferService.cols,this.dimensions.device.canvas.height=this.dimensions.device.cell.height*this._bufferService.rows,this.dimensions.css.canvas.width=Math.round(this.dimensions.device.canvas.width/t),this.dimensions.css.canvas.height=Math.round(this.dimensions.device.canvas.height/t),this.dimensions.css.cell.width=this.dimensions.css.canvas.width/this._bufferService.cols,this.dimensions.css.cell.height=this.dimensions.css.canvas.height/this._bufferService.rows;for(let s of this._rowElements)s.style.width=`${this.dimensions.css.canvas.width}px`,s.style.height=`${this.dimensions.css.cell.height}px`,s.style.lineHeight=`${this.dimensions.css.cell.height}px`,s.style.overflow="hidden";this._dimensionsStyleElement||(this._dimensionsStyleElement=this._document.createElement("style"),this._screenElement.appendChild(this._dimensionsStyleElement));let e=`${this._terminalSelector} .${ss} span { display: inline-block; height: 100%; vertical-align: top;}`;this._dimensionsStyleElement.textContent=e,this._selectionContainer.style.height=this._viewportElement.style.height,this._screenElement.style.width=`${this.dimensions.css.canvas.width}px`,this._screenElement.style.height=`${this.dimensions.css.canvas.height}px`}_injectCss(t){this._themeStyleElement||(this._themeStyleElement=this._document.createElement("style"),this._screenElement.appendChild(this._themeStyleElement));let e=`${this._terminalSelector} .${ss} { pointer-events: none; color: ${t.foreground.css}; font-family: ${this._optionsService.rawOptions.fontFamily}; font-size: ${this._optionsService.rawOptions.fontSize}px; font-kerning: none; white-space: pre}`;e+=`${this._terminalSelector} .${ss} .xterm-dim { color: ${Le.multiplyOpacity(t.foreground,.5).css};}`,e+=`${this._terminalSelector} span:not(.xterm-bold) { font-weight: ${this._optionsService.rawOptions.fontWeight};}${this._terminalSelector} span.xterm-bold { font-weight: ${this._optionsService.rawOptions.fontWeightBold};}${this._terminalSelector} span.xterm-italic { font-style: italic;}`;let s=`blink_underline_${this._terminalClass}`,i=`blink_bar_${this._terminalClass}`,n=`blink_block_${this._terminalClass}`;e+=`@keyframes ${s} { 50% { border-bottom-style: hidden; }}`,e+=`@keyframes ${i} { 50% { box-shadow: none; }}`,e+=`@keyframes ${n} { 0% { background-color: ${t.cursor.css}; color: ${t.cursorAccent.css}; } 50% { background-color: inherit; color: ${t.cursor.css}; }}`,e+=`${this._terminalSelector} .${ss}.${rr} .xterm-cursor.xterm-cursor-blink.xterm-cursor-underline { animation: ${s} 1s step-end infinite;}${this._terminalSelector} .${ss}.${rr} .xterm-cursor.xterm-cursor-blink.xterm-cursor-bar { animation: ${i} 1s step-end infinite;}${this._terminalSelector} .${ss}.${rr} .xterm-cursor.xterm-cursor-blink.xterm-cursor-block { animation: ${n} 1s step-end infinite;}${this._terminalSelector} .${ss} .xterm-cursor.xterm-cursor-block { background-color: ${t.cursor.css}; color: ${t.cursorAccent.css};}${this._terminalSelector} .${ss} .xterm-cursor.xterm-cursor-block:not(.xterm-cursor-blink) { background-color: ${t.cursor.css} !important; color: ${t.cursorAccent.css} !important;}${this._terminalSelector} .${ss} .xterm-cursor.xterm-cursor-outline { outline: 1px solid ${t.cursor.css}; outline-offset: -1px;}${this._terminalSelector} .${ss} .xterm-cursor.xterm-cursor-bar { box-shadow: ${this._optionsService.rawOptions.cursorWidth}px 0 0 ${t.cursor.css} inset;}${this._terminalSelector} .${ss} .xterm-cursor.xterm-cursor-underline { border-bottom: 1px ${t.cursor.css}; border-bottom-style: solid; height: calc(100% - 1px);}`,e+=`${this._terminalSelector} .${_n} { position: absolute; top: 0; left: 0; z-index: 1; pointer-events: none;}${this._terminalSelector}.focus .${_n} div { position: absolute; background-color: ${t.selectionBackgroundOpaque.css};}${this._terminalSelector} .${_n} div { position: absolute; background-color: ${t.selectionInactiveBackgroundOpaque.css};}`;for(let[o,a]of t.ansi.entries())e+=`${this._terminalSelector} .${gn}${o} { color: ${a.css}; }${this._terminalSelector} .${gn}${o}.xterm-dim { color: ${Le.multiplyOpacity(a,.5).css}; }${this._terminalSelector} .${zd}${o} { background-color: ${a.css}; }`;e+=`${this._terminalSelector} .${gn}257 { color: ${Le.opaque(t.background).css}; }${this._terminalSelector} .${gn}257.xterm-dim { color: ${Le.multiplyOpacity(Le.opaque(t.background),.5).css}; }${this._terminalSelector} .${zd}257 { background-color: ${t.foreground.css}; }`,this._themeStyleElement.textContent=e}_setDefaultSpacing(){let t=this.dimensions.css.cell.width-this._widthCache.get("W",!1,!1);this._rowContainer.style.letterSpacing=`${t}px`,this._rowFactory.defaultSpacing=t}handleDevicePixelRatioChange(){this._updateDimensions(),this._widthCache.clear(),this._setDefaultSpacing()}_refreshRowElements(t,e){for(let s=this._rowElements.length;s<=e;s++){let i=this._document.createElement("div");this._rowContainer.appendChild(i),this._rowElements.push(i)}for(;this._rowElements.length>e;)this._rowContainer.removeChild(this._rowElements.pop())}handleResize(t,e){this._refreshRowElements(t,e),this._updateDimensions(),this.handleSelectionChanged(this._selectionRenderModel.selectionStart,this._selectionRenderModel.selectionEnd,this._selectionRenderModel.columnSelectMode)}handleCharSizeChanged(){this._updateDimensions(),this._widthCache.clear(),this._setDefaultSpacing()}handleBlur(){this._rowContainer.classList.remove(rr),this.renderRows(0,this._bufferService.rows-1)}handleFocus(){this._rowContainer.classList.add(rr),this.renderRows(this._bufferService.buffer.y,this._bufferService.buffer.y)}handleSelectionChanged(t,e,s){if(this._selectionContainer.replaceChildren(),this._rowFactory.handleSelectionChanged(t,e,s),this.renderRows(0,this._bufferService.rows-1),!t||!e||(this._selectionRenderModel.update(this._terminal,t,e,s),!this._selectionRenderModel.hasSelection))return;let i=this._selectionRenderModel.viewportStartRow,n=this._selectionRenderModel.viewportEndRow,o=this._selectionRenderModel.viewportCappedStartRow,a=this._selectionRenderModel.viewportCappedEndRow,l=this._document.createDocumentFragment();if(s){let c=t[0]>e[0];l.appendChild(this._createSelectionElement(o,c?e[0]:t[0],c?t[0]:e[0],a-o+1))}else{let c=i===o?t[0]:0,d=o===n?e[0]:this._bufferService.cols;l.appendChild(this._createSelectionElement(o,c,d));let u=a-o-1;if(l.appendChild(this._createSelectionElement(o+1,0,this._bufferService.cols,u)),o!==a){let h=n===a?e[0]:this._bufferService.cols;l.appendChild(this._createSelectionElement(a,0,h))}}this._selectionContainer.appendChild(l)}_createSelectionElement(t,e,s,i=1){let n=this._document.createElement("div"),o=e*this.dimensions.css.cell.width,a=this.dimensions.css.cell.width*(s-e);return o+a>this.dimensions.css.canvas.width&&(a=this.dimensions.css.canvas.width-o),n.style.height=`${i*this.dimensions.css.cell.height}px`,n.style.top=`${t*this.dimensions.css.cell.height}px`,n.style.left=`${o}px`,n.style.width=`${a}px`,n}handleCursorMove(){}_handleOptionsChanged(){this._updateDimensions(),this._injectCss(this._themeService.colors),this._widthCache.setFont(this._optionsService.rawOptions.fontFamily,this._optionsService.rawOptions.fontSize,this._optionsService.rawOptions.fontWeight,this._optionsService.rawOptions.fontWeightBold),this._setDefaultSpacing()}clear(){for(let t of this._rowElements)t.replaceChildren()}renderRows(t,e){let s=this._bufferService.buffer,i=s.ybase+s.y,n=Math.min(s.x,this._bufferService.cols-1),o=this._coreService.decPrivateModes.cursorBlink??this._optionsService.rawOptions.cursorBlink,a=this._coreService.decPrivateModes.cursorStyle??this._optionsService.rawOptions.cursorStyle,l=this._optionsService.rawOptions.cursorInactiveStyle;for(let c=t;c<=e;c++){let d=c+s.ydisp,u=this._rowElements[c],h=s.lines.get(d);if(!u||!h)break;u.replaceChildren(...this._rowFactory.createRow(h,d,d===i,a,l,n,o,this.dimensions.css.cell.width,this._widthCache,-1,-1))}}get _terminalSelector(){return`.${qo}${this._terminalClass}`}_handleLinkHover(t){this._setCellUnderline(t.x1,t.x2,t.y1,t.y2,t.cols,!0)}_handleLinkLeave(t){this._setCellUnderline(t.x1,t.x2,t.y1,t.y2,t.cols,!1)}_setCellUnderline(t,e,s,i,n,o){s<0&&(t=0),i<0&&(e=0);let a=this._bufferService.rows-1;s=Math.max(Math.min(s,a),0),i=Math.max(Math.min(i,a),0),n=Math.min(n,this._bufferService.cols);let l=this._bufferService.buffer,c=l.ybase+l.y,d=Math.min(l.x,n-1),u=this._optionsService.rawOptions.cursorBlink,h=this._optionsService.rawOptions.cursorStyle,f=this._optionsService.rawOptions.cursorInactiveStyle;for(let m=s;m<=i;++m){let p=m+l.ydisp,g=this._rowElements[m],_=l.lines.get(p);if(!g||!_)break;g.replaceChildren(...this._rowFactory.createRow(_,p,p===c,h,f,d,u,this.dimensions.css.cell.width,this._widthCache,o?m===s?t:0:-1,o?(m===i?e:n)-1:-1))}}};Ua=Ye([ce(7,Jl),ce(8,vo),ce(9,Bt),ce(10,Lt),ce(11,Ci),ce(12,Hs),ce(13,Xi)],Ua);var Ka=class extends Ve{constructor(t,e,s){super(),this._optionsService=s,this.width=0,this.height=0,this._onCharSizeChange=this._register(new re),this.onCharSizeChange=this._onCharSizeChange.event;try{this._measureStrategy=this._register(new I3(this._optionsService))}catch{this._measureStrategy=this._register(new E3(t,e,this._optionsService))}this._register(this._optionsService.onMultipleOptionChange(["fontFamily","fontSize"],()=>this.measure()))}get hasValidSize(){return this.width>0&&this.height>0}measure(){let t=this._measureStrategy.measure();(t.width!==this.width||t.height!==this.height)&&(this.width=t.width,this.height=t.height,this._onCharSizeChange.fire())}};Ka=Ye([ce(2,Bt)],Ka);var wm=class extends Ve{constructor(){super(...arguments),this._result={width:0,height:0}}_validateAndSet(t,e){t!==void 0&&t>0&&e!==void 0&&e>0&&(this._result.width=t,this._result.height=e)}},E3=class extends wm{constructor(t,e,s){super(),this._document=t,this._parentElement=e,this._optionsService=s,this._measureElement=this._document.createElement("span"),this._measureElement.classList.add("xterm-char-measure-element"),this._measureElement.textContent="W".repeat(32),this._measureElement.setAttribute("aria-hidden","true"),this._measureElement.style.whiteSpace="pre",this._measureElement.style.fontKerning="none",this._parentElement.appendChild(this._measureElement)}measure(){return this._measureElement.style.fontFamily=this._optionsService.rawOptions.fontFamily,this._measureElement.style.fontSize=`${this._optionsService.rawOptions.fontSize}px`,this._validateAndSet(Number(this._measureElement.offsetWidth)/32,Number(this._measureElement.offsetHeight)),this._result}},I3=class extends wm{constructor(t){super(),this._optionsService=t,this._canvas=new OffscreenCanvas(100,100),this._ctx=this._canvas.getContext("2d");let e=this._ctx.measureText("W");if(!("width"in e&&"fontBoundingBoxAscent"in e&&"fontBoundingBoxDescent"in e))throw new Error("Required font metrics not supported")}measure(){this._ctx.font=`${this._optionsService.rawOptions.fontSize}px ${this._optionsService.rawOptions.fontFamily}`;let t=this._ctx.measureText("W");return this._validateAndSet(t.width,t.fontBoundingBoxAscent+t.fontBoundingBoxDescent),this._result}},R3=class extends Ve{constructor(t,e,s){super(),this._textarea=t,this._window=e,this.mainDocument=s,this._isFocused=!1,this._cachedIsFocused=void 0,this._screenDprMonitor=this._register(new T3(this._window)),this._onDprChange=this._register(new re),this.onDprChange=this._onDprChange.event,this._onWindowChange=this._register(new re),this.onWindowChange=this._onWindowChange.event,this._register(this.onWindowChange(i=>this._screenDprMonitor.setWindow(i))),this._register(yt.forward(this._screenDprMonitor.onDprChange,this._onDprChange)),this._register(ye(this._textarea,"focus",()=>this._isFocused=!0)),this._register(ye(this._textarea,"blur",()=>this._isFocused=!1))}get window(){return this._window}set window(t){this._window!==t&&(this._window=t,this._onWindowChange.fire(this._window))}get dpr(){return this.window.devicePixelRatio}get isFocused(){return this._cachedIsFocused===void 0&&(this._cachedIsFocused=this._isFocused&&this._textarea.ownerDocument.hasFocus(),queueMicrotask(()=>this._cachedIsFocused=void 0)),this._cachedIsFocused}},T3=class extends Ve{constructor(t){super(),this._parentWindow=t,this._windowResizeListener=this._register(new zi),this._onDprChange=this._register(new re),this.onDprChange=this._onDprChange.event,this._outerListener=()=>this._setDprAndFireIfDiffers(),this._currentDevicePixelRatio=this._parentWindow.devicePixelRatio,this._updateDpr(),this._setWindowResizeListener(),this._register(Fe(()=>this.clearListener()))}setWindow(t){this._parentWindow=t,this._setWindowResizeListener(),this._setDprAndFireIfDiffers()}_setWindowResizeListener(){this._windowResizeListener.value=ye(this._parentWindow,"resize",()=>this._setDprAndFireIfDiffers())}_setDprAndFireIfDiffers(){this._parentWindow.devicePixelRatio!==this._currentDevicePixelRatio&&this._onDprChange.fire(this._parentWindow.devicePixelRatio),this._updateDpr()}_updateDpr(){this._outerListener&&(this._resolutionMediaMatchList?.removeListener(this._outerListener),this._currentDevicePixelRatio=this._parentWindow.devicePixelRatio,this._resolutionMediaMatchList=this._parentWindow.matchMedia(`screen and (resolution: ${this._parentWindow.devicePixelRatio}dppx)`),this._resolutionMediaMatchList.addListener(this._outerListener))}clearListener(){!this._resolutionMediaMatchList||!this._outerListener||(this._resolutionMediaMatchList.removeListener(this._outerListener),this._resolutionMediaMatchList=void 0,this._outerListener=void 0)}},D3=class extends Ve{constructor(){super(),this.linkProviders=[],this._register(Fe(()=>this.linkProviders.length=0))}registerLinkProvider(t){return this.linkProviders.push(t),{dispose:()=>{let e=this.linkProviders.indexOf(t);e!==-1&&this.linkProviders.splice(e,1)}}}};function nc(t,e,s){let i=s.getBoundingClientRect(),n=t.getComputedStyle(s),o=parseInt(n.getPropertyValue("padding-left")),a=parseInt(n.getPropertyValue("padding-top"));return[e.clientX-i.left-o,e.clientY-i.top-a]}function M3(t,e,s,i,n,o,a,l,c){if(!o)return;let d=nc(t,e,s);if(d)return d[0]=Math.ceil((d[0]+(c?a/2:0))/a),d[1]=Math.ceil(d[1]/l),d[0]=Math.min(Math.max(d[0],1),i+(c?1:0)),d[1]=Math.min(Math.max(d[1],1),n),d}var qa=class{constructor(t,e){this._renderService=t,this._charSizeService=e}getCoords(t,e,s,i,n){return M3(window,t,e,s,i,this._charSizeService.hasValidSize,this._renderService.dimensions.css.cell.width,this._renderService.dimensions.css.cell.height,n)}getMouseReportCoords(t,e){let s=nc(window,t,e);if(this._charSizeService.hasValidSize)return s[0]=Math.min(Math.max(s[0],0),this._renderService.dimensions.css.canvas.width-1),s[1]=Math.min(Math.max(s[1],0),this._renderService.dimensions.css.canvas.height-1),{col:Math.floor(s[0]/this._renderService.dimensions.css.cell.width),row:Math.floor(s[1]/this._renderService.dimensions.css.cell.height),x:Math.floor(s[0]),y:Math.floor(s[1])}}};qa=Ye([ce(0,Ws),ce(1,vo)],qa);var P3=class{constructor(t,e){this._renderCallback=t,this._coreBrowserService=e,this._refreshCallbacks=[]}dispose(){this._animationFrame&&(this._coreBrowserService.window.cancelAnimationFrame(this._animationFrame),this._animationFrame=void 0)}addRefreshCallback(t){return this._refreshCallbacks.push(t),this._animationFrame||(this._animationFrame=this._coreBrowserService.window.requestAnimationFrame(()=>this._innerRefresh())),this._animationFrame}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,!this._animationFrame&&(this._animationFrame=this._coreBrowserService.window.requestAnimationFrame(()=>this._innerRefresh()))}_innerRefresh(){if(this._animationFrame=void 0,this._rowStart===void 0||this._rowEnd===void 0||this._rowCount===void 0){this._runRefreshCallbacks();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),this._runRefreshCallbacks()}_runRefreshCallbacks(){for(let t of this._refreshCallbacks)t(0);this._refreshCallbacks=[]}},Vm={};KV(Vm,{getSafariVersion:()=>B3,isChromeOS:()=>Nm,isFirefox:()=>Cm,isIpad:()=>O3,isIphone:()=>$3,isLegacyEdge:()=>L3,isLinux:()=>oc,isMac:()=>Xn,isNode:()=>bo,isSafari:()=>jm,isWindows:()=>km});var bo=typeof process<"u"&&"title"in process,sn=bo?"node":navigator.userAgent,rn=bo?"node":navigator.platform,Cm=sn.includes("Firefox"),L3=sn.includes("Edge"),jm=/^((?!chrome|android).)*safari/i.test(sn);function B3(){if(!jm)return 0;let t=sn.match(/Version\/(\d+)/);return t===null||t.length<2?0:parseInt(t[1])}var Xn=["Macintosh","MacIntel","MacPPC","Mac68K"].includes(rn),O3=rn==="iPad",$3=rn==="iPhone",km=["Windows","Win16","Win32","WinCE"].includes(rn),oc=rn.indexOf("Linux")>=0,Nm=/\bCrOS\b/.test(sn),Am=class{constructor(){this._tasks=[],this._i=0}enqueue(t){this._tasks.push(t),this._start()}flush(){for(;this._i<this._tasks.length;)this._tasks[this._i]()||this._i++;this.clear()}clear(){this._idleCallback&&(this._cancelCallback(this._idleCallback),this._idleCallback=void 0),this._i=0,this._tasks.length=0}_start(){this._idleCallback||(this._idleCallback=this._requestCallback(this._process.bind(this)))}_process(t){this._idleCallback=void 0;let e=0,s=0,i=t.timeRemaining(),n=0;for(;this._i<this._tasks.length;){if(e=performance.now(),this._tasks[this._i]()||this._i++,e=Math.max(1,performance.now()-e),s=Math.max(e,s),n=t.timeRemaining(),s*1.5>n){i-e<-20&&console.warn(`task queue exceeded allotted deadline by ${Math.abs(Math.round(i-e))}ms`),this._start();return}i=n}this.clear()}},z3=class extends Am{_requestCallback(t){return setTimeout(()=>t(this._createDeadline(16)))}_cancelCallback(t){clearTimeout(t)}_createDeadline(t){let e=performance.now()+t;return{timeRemaining:()=>Math.max(0,e-performance.now())}}},F3=class extends Am{_requestCallback(t){return requestIdleCallback(t)}_cancelCallback(t){cancelIdleCallback(t)}},Jn=!bo&&"requestIdleCallback"in window?F3:z3,H3=class{constructor(){this._queue=new Jn}set(t){this._queue.clear(),this._queue.enqueue(t)}flush(){this._queue.flush()}},Ga=class extends Ve{constructor(t,e,s,i,n,o,a,l,c){super(),this._rowCount=t,this._optionsService=s,this._charSizeService=i,this._coreService=n,this._coreBrowserService=l,this._renderer=this._register(new zi),this._pausedResizeTask=new H3,this._observerDisposable=this._register(new zi),this._isPaused=!1,this._needsFullRefresh=!1,this._isNextRenderRedrawOnly=!0,this._needsSelectionRefresh=!1,this._canvasWidth=0,this._canvasHeight=0,this._selectionState={start:void 0,end:void 0,columnSelectMode:!1},this._onDimensionsChange=this._register(new re),this.onDimensionsChange=this._onDimensionsChange.event,this._onRenderedViewportChange=this._register(new re),this.onRenderedViewportChange=this._onRenderedViewportChange.event,this._onRender=this._register(new re),this.onRender=this._onRender.event,this._onRefreshRequest=this._register(new re),this.onRefreshRequest=this._onRefreshRequest.event,this._renderDebouncer=new P3((d,u)=>this._renderRows(d,u),this._coreBrowserService),this._register(this._renderDebouncer),this._syncOutputHandler=new W3(this._coreBrowserService,this._coreService,()=>this._fullRefresh()),this._register(Fe(()=>this._syncOutputHandler.dispose())),this._register(this._coreBrowserService.onDprChange(()=>this.handleDevicePixelRatioChange())),this._register(a.onResize(()=>this._fullRefresh())),this._register(a.buffers.onBufferActivate(()=>this._renderer.value?.clear())),this._register(this._optionsService.onOptionChange(()=>this._handleOptionsChanged())),this._register(this._charSizeService.onCharSizeChange(()=>this.handleCharSizeChanged())),this._register(o.onDecorationRegistered(()=>this._fullRefresh())),this._register(o.onDecorationRemoved(()=>this._fullRefresh())),this._register(this._optionsService.onMultipleOptionChange(["customGlyphs","drawBoldTextInBrightColors","letterSpacing","lineHeight","fontFamily","fontSize","fontWeight","fontWeightBold","minimumContrastRatio","rescaleOverlappingGlyphs"],()=>{this.clear(),this.handleResize(a.cols,a.rows),this._fullRefresh()})),this._register(this._optionsService.onMultipleOptionChange(["cursorBlink","cursorStyle"],()=>this.refreshRows(a.buffer.y,a.buffer.y,!0))),this._register(c.onChangeColors(()=>this._fullRefresh())),this._registerIntersectionObserver(this._coreBrowserService.window,e),this._register(this._coreBrowserService.onWindowChange(d=>this._registerIntersectionObserver(d,e)))}get dimensions(){return this._renderer.value.dimensions}_registerIntersectionObserver(t,e){if("IntersectionObserver"in t){let s=new t.IntersectionObserver(i=>this._handleIntersectionChange(i[i.length-1]),{threshold:0});s.observe(e),this._observerDisposable.value=Fe(()=>s.disconnect())}}_handleIntersectionChange(t){this._isPaused=t.isIntersecting===void 0?t.intersectionRatio===0:!t.isIntersecting,!this._isPaused&&!this._charSizeService.hasValidSize&&this._charSizeService.measure(),!this._isPaused&&this._needsFullRefresh&&(this._pausedResizeTask.flush(),this.refreshRows(0,this._rowCount-1),this._needsFullRefresh=!1)}refreshRows(t,e,s=!1){if(this._isPaused){this._needsFullRefresh=!0;return}if(this._coreService.decPrivateModes.synchronizedOutput){this._syncOutputHandler.bufferRows(t,e);return}let i=this._syncOutputHandler.flush();i&&(t=Math.min(t,i.start),e=Math.max(e,i.end)),s||(this._isNextRenderRedrawOnly=!1),this._renderDebouncer.refresh(t,e,this._rowCount)}_renderRows(t,e){if(this._renderer.value){if(this._coreService.decPrivateModes.synchronizedOutput){this._syncOutputHandler.bufferRows(t,e);return}t=Math.min(t,this._rowCount-1),e=Math.min(e,this._rowCount-1),this._renderer.value.renderRows(t,e),this._needsSelectionRefresh&&(this._renderer.value.handleSelectionChanged(this._selectionState.start,this._selectionState.end,this._selectionState.columnSelectMode),this._needsSelectionRefresh=!1),this._isNextRenderRedrawOnly||this._onRenderedViewportChange.fire({start:t,end:e}),this._onRender.fire({start:t,end:e}),this._isNextRenderRedrawOnly=!0}}resize(t,e){this._rowCount=e,this._fireOnCanvasResize()}_handleOptionsChanged(){this._renderer.value&&(this.refreshRows(0,this._rowCount-1),this._fireOnCanvasResize())}_fireOnCanvasResize(){this._renderer.value&&(this._renderer.value.dimensions.css.canvas.width===this._canvasWidth&&this._renderer.value.dimensions.css.canvas.height===this._canvasHeight||this._onDimensionsChange.fire(this._renderer.value.dimensions))}hasRenderer(){return!!this._renderer.value}setRenderer(t){this._renderer.value=t,this._renderer.value&&(this._renderer.value.onRequestRedraw(e=>this.refreshRows(e.start,e.end,!0)),this._needsSelectionRefresh=!0,this._fullRefresh())}addRefreshCallback(t){return this._renderDebouncer.addRefreshCallback(t)}_fullRefresh(){this._isPaused?this._needsFullRefresh=!0:this.refreshRows(0,this._rowCount-1)}clearTextureAtlas(){this._renderer.value&&(this._renderer.value.clearTextureAtlas?.(),this._fullRefresh())}handleDevicePixelRatioChange(){this._charSizeService.measure(),this._renderer.value&&(this._renderer.value.handleDevicePixelRatioChange(),this.refreshRows(0,this._rowCount-1))}handleResize(t,e){this._renderer.value&&(this._isPaused?this._pausedResizeTask.set(()=>this._renderer.value?.handleResize(t,e)):this._renderer.value.handleResize(t,e),this._fullRefresh())}handleCharSizeChanged(){this._renderer.value?.handleCharSizeChanged()}handleBlur(){this._renderer.value?.handleBlur()}handleFocus(){this._renderer.value?.handleFocus()}handleSelectionChanged(t,e,s){this._selectionState.start=t,this._selectionState.end=e,this._selectionState.columnSelectMode=s,this._renderer.value?.handleSelectionChanged(t,e,s)}handleCursorMove(){this._renderer.value?.handleCursorMove()}clear(){this._renderer.value?.clear()}};Ga=Ye([ce(2,Bt),ce(3,vo),ce(4,Ci),ce(5,tn),ce(6,Lt),ce(7,Hs),ce(8,Xi)],Ga);var W3=class{constructor(t,e,s){this._coreBrowserService=t,this._coreService=e,this._onTimeout=s,this._start=0,this._end=0,this._isBuffering=!1}bufferRows(t,e){this._isBuffering?(this._start=Math.min(this._start,t),this._end=Math.max(this._end,e)):(this._start=t,this._end=e,this._isBuffering=!0),this._timeout===void 0&&(this._timeout=this._coreBrowserService.window.setTimeout(()=>{this._timeout=void 0,this._coreService.decPrivateModes.synchronizedOutput=!1,this._onTimeout()},1e3))}flush(){if(this._timeout!==void 0&&(this._coreBrowserService.window.clearTimeout(this._timeout),this._timeout=void 0),!this._isBuffering)return;let t={start:this._start,end:this._end};return this._isBuffering=!1,t}dispose(){this._timeout!==void 0&&(this._coreBrowserService.window.clearTimeout(this._timeout),this._timeout=void 0)}};function U3(t,e,s,i){let n=s.buffer.x,o=s.buffer.y;if(!s.buffer.hasScrollback)return G3(n,o,t,e,s,i)+yo(o,e,s,i)+Y3(n,o,t,e,s,i);let a;if(o===e)return a=n>t?"D":"C",Pr(Math.abs(n-t),Mr(a,i));a=o>e?"D":"C";let l=Math.abs(o-e),c=q3(o>e?t:n,s)+(l-1)*s.cols+1+K3(o>e?n:t);return Pr(c,Mr(a,i))}function K3(t,e){return t-1}function q3(t,e){return e.cols-t}function G3(t,e,s,i,n,o){return yo(e,i,n,o).length===0?"":Pr(Im(t,e,t,e-xi(e,n),!1,n).length,Mr("D",o))}function yo(t,e,s,i){let n=t-xi(t,s),o=e-xi(e,s),a=Math.abs(n-o)-X3(t,e,s);return Pr(a,Mr(Em(t,e),i))}function Y3(t,e,s,i,n,o){let a;yo(e,i,n,o).length>0?a=i-xi(i,n):a=e;let l=i,c=J3(t,e,s,i,n,o);return Pr(Im(t,a,s,l,c==="C",n).length,Mr(c,o))}function X3(t,e,s){let i=0,n=t-xi(t,s),o=e-xi(e,s);for(let a=0;a<Math.abs(n-o);a++){let l=Em(t,e)==="A"?-1:1;s.buffer.lines.get(n+l*a)?.isWrapped&&i++}return i}function xi(t,e){let s=0,i=e.buffer.lines.get(t),n=i?.isWrapped;for(;n&&t>=0&&t<e.rows;)s++,i=e.buffer.lines.get(--t),n=i?.isWrapped;return s}function J3(t,e,s,i,n,o){let a;return yo(s,i,n,o).length>0?a=i-xi(i,n):a=e,t<s&&a<=i||t>=s&&a<i?"C":"D"}function Em(t,e){return t>e?"A":"B"}function Im(t,e,s,i,n,o){let a=t,l=e,c="";for(;(a!==s||l!==i)&&l>=0&&l<o.buffer.lines.length;)a+=n?1:-1,n&&a>o.cols-1?(c+=o.buffer.translateBufferLineToString(l,!1,t,a),a=0,t=0,l++):!n&&a<0&&(c+=o.buffer.translateBufferLineToString(l,!1,0,t+1),a=o.cols-1,t=a,l--);return c+o.buffer.translateBufferLineToString(l,!1,t,a)}function Mr(t,e){let s=e?"O":"[";return Z.ESC+s+t}function Pr(t,e){t=Math.floor(t);let s="";for(let i=0;i<t;i++)s+=e;return s}var Q3=class{constructor(t){this._bufferService=t,this.isSelectAllActive=!1,this.selectionStartLength=0}clearSelection(){this.selectionStart=void 0,this.selectionEnd=void 0,this.isSelectAllActive=!1,this.selectionStartLength=0}get finalSelectionStart(){return this.isSelectAllActive?[0,0]:!this.selectionEnd||!this.selectionStart?this.selectionStart:this.areSelectionValuesReversed()?this.selectionEnd:this.selectionStart}get finalSelectionEnd(){if(this.isSelectAllActive)return[this._bufferService.cols,this._bufferService.buffer.ybase+this._bufferService.rows-1];if(this.selectionStart){if(!this.selectionEnd||this.areSelectionValuesReversed()){let t=this.selectionStart[0]+this.selectionStartLength;return t>this._bufferService.cols?t%this._bufferService.cols===0?[this._bufferService.cols,this.selectionStart[1]+Math.floor(t/this._bufferService.cols)-1]:[t%this._bufferService.cols,this.selectionStart[1]+Math.floor(t/this._bufferService.cols)]:[t,this.selectionStart[1]]}if(this.selectionStartLength&&this.selectionEnd[1]===this.selectionStart[1]){let t=this.selectionStart[0]+this.selectionStartLength;return t>this._bufferService.cols?[t%this._bufferService.cols,this.selectionStart[1]+Math.floor(t/this._bufferService.cols)]:[Math.max(t,this.selectionEnd[0]),this.selectionEnd[1]]}return this.selectionEnd}}areSelectionValuesReversed(){let t=this.selectionStart,e=this.selectionEnd;return!t||!e?!1:t[1]>e[1]||t[1]===e[1]&&t[0]>e[0]}handleTrim(t){return this.selectionStart&&(this.selectionStart[1]-=t),this.selectionEnd&&(this.selectionEnd[1]-=t),this.selectionEnd&&this.selectionEnd[1]<0?(this.clearSelection(),!0):(this.selectionStart&&this.selectionStart[1]<0&&(this.selectionStart[1]=0),!1)}};function Fd(t,e){if(t.start.y>t.end.y)throw new Error(`Buffer range end (${t.end.x}, ${t.end.y}) cannot be before start (${t.start.x}, ${t.start.y})`);return e*(t.end.y-t.start.y)+(t.end.x-t.start.x+1)}var Go=50,Z3=15,ej=50,tj=500,sj=" ",ij=new RegExp(sj,"g"),Ya=class extends Ve{constructor(t,e,s,i,n,o,a,l,c){super(),this._element=t,this._screenElement=e,this._linkifier=s,this._bufferService=i,this._coreService=n,this._mouseService=o,this._optionsService=a,this._renderService=l,this._coreBrowserService=c,this._dragScrollAmount=0,this._enabled=!0,this._workCell=new as,this._mouseDownTimeStamp=0,this._oldHasSelection=!1,this._oldSelectionStart=void 0,this._oldSelectionEnd=void 0,this._onLinuxMouseSelection=this._register(new re),this.onLinuxMouseSelection=this._onLinuxMouseSelection.event,this._onRedrawRequest=this._register(new re),this.onRequestRedraw=this._onRedrawRequest.event,this._onSelectionChange=this._register(new re),this.onSelectionChange=this._onSelectionChange.event,this._onRequestScrollLines=this._register(new re),this.onRequestScrollLines=this._onRequestScrollLines.event,this._mouseMoveListener=d=>this._handleMouseMove(d),this._mouseUpListener=d=>this._handleMouseUp(d),this._coreService.onUserInput(()=>{this.hasSelection&&this.clearSelection()}),this._trimListener=this._bufferService.buffer.lines.onTrim(d=>this._handleTrim(d)),this._register(this._bufferService.buffers.onBufferActivate(d=>this._handleBufferActivate(d))),this.enable(),this._model=new Q3(this._bufferService),this._activeSelectionMode=0,this._register(Fe(()=>{this._removeMouseDownListeners()})),this._register(this._bufferService.onResize(d=>{d.rowsChanged&&this.clearSelection()}))}reset(){this.clearSelection()}disable(){this.clearSelection(),this._enabled=!1}enable(){this._enabled=!0}get selectionStart(){return this._model.finalSelectionStart}get selectionEnd(){return this._model.finalSelectionEnd}get hasSelection(){let t=this._model.finalSelectionStart,e=this._model.finalSelectionEnd;return!t||!e?!1:t[0]!==e[0]||t[1]!==e[1]}get selectionText(){let t=this._model.finalSelectionStart,e=this._model.finalSelectionEnd;if(!t||!e)return"";let s=this._bufferService.buffer,i=[];if(this._activeSelectionMode===3){if(t[0]===e[0])return"";let n=t[0]<e[0]?t[0]:e[0],o=t[0]<e[0]?e[0]:t[0];for(let a=t[1];a<=e[1];a++){let l=s.translateBufferLineToString(a,!0,n,o);i.push(l)}}else{let n=t[1]===e[1]?e[0]:void 0;i.push(s.translateBufferLineToString(t[1],!0,t[0],n));for(let o=t[1]+1;o<=e[1]-1;o++){let a=s.lines.get(o),l=s.translateBufferLineToString(o,!0);a?.isWrapped?i[i.length-1]+=l:i.push(l)}if(t[1]!==e[1]){let o=s.lines.get(e[1]),a=s.translateBufferLineToString(e[1],!0,0,e[0]);o&&o.isWrapped?i[i.length-1]+=a:i.push(a)}}return i.map(n=>n.replace(ij," ")).join(km?`\r
436
+ `))}},SC=class extends Error{constructor(t,e){super(t),this.name="ListenerLeakError",this.stack=e}},wC=class extends Error{constructor(t,e){super(t),this.name="ListenerRefusalError",this.stack=e}},VC=0,Ho=class{constructor(t){this.value=t,this.id=VC++}},CC=2,jC,re=class{constructor(t){this._size=0,this._options=t,this._leakageMon=this._options?.leakWarningThreshold?new bC(t?.onListenerError??An,this._options?.leakWarningThreshold??vC):void 0,this._perfMon=this._options?._profName?new xC(this._options._profName):void 0,this._deliveryQueue=this._options?.deliveryQueue}dispose(){this._disposed||(this._disposed=!0,this._deliveryQueue?.current===this&&this._deliveryQueue.reset(),this._listeners&&(this._listeners=void 0,this._size=0),this._options?.onDidRemoveLastListener?.(),this._leakageMon?.dispose())}get event(){return this._event??=(t,e,s)=>{if(this._leakageMon&&this._size>this._leakageMon.threshold**2){let a=`[${this._leakageMon.name}] REFUSES to accept new listeners because it exceeded its threshold by far (${this._size} vs ${this._leakageMon.threshold})`;console.warn(a);let l=this._leakageMon.getMostFrequentStack()??["UNKNOWN stack",-1],c=new wC(`${a}. HINT: Stack shows most frequent listener (${l[1]}-times)`,l[0]);return(this._options?.onListenerError||An)(c),Ve.None}if(this._disposed)return Ve.None;e&&(t=t.bind(e));let i=new Ho(t),n;this._leakageMon&&this._size>=Math.ceil(this._leakageMon.threshold*.2)&&(i.stack=yC.create(),n=this._leakageMon.check(i.stack,this._size+1)),this._listeners?this._listeners instanceof Ho?(this._deliveryQueue??=new kC,this._listeners=[this._listeners,i]):this._listeners.push(i):(this._options?.onWillAddFirstListener?.(this),this._listeners=i,this._options?.onDidAddFirstListener?.(this)),this._size++;let o=Fe(()=>{n?.(),this._removeListener(i)});return s instanceof ti?s.add(o):Array.isArray(s)&&s.push(o),o},this._event}_removeListener(t){if(this._options?.onWillRemoveListener?.(this),!this._listeners)return;if(this._size===1){this._listeners=void 0,this._options?.onDidRemoveLastListener?.(this),this._size=0;return}let e=this._listeners,s=e.indexOf(t);if(s===-1)throw console.log("disposed?",this._disposed),console.log("size?",this._size),console.log("arr?",JSON.stringify(this._listeners)),new Error("Attempted to dispose unknown listener");this._size--,e[s]=void 0;let i=this._deliveryQueue.current===this;if(this._size*CC<=e.length){let n=0;for(let o=0;o<e.length;o++)e[o]?e[n++]=e[o]:i&&(this._deliveryQueue.end--,n<this._deliveryQueue.i&&this._deliveryQueue.i--);e.length=n}}_deliver(t,e){if(!t)return;let s=this._options?.onListenerError||An;if(!s){t.value(e);return}try{t.value(e)}catch(i){s(i)}}_deliverQueue(t){let e=t.current._listeners;for(;t.i<t.end;)this._deliver(e[t.i++],t.value);t.reset()}fire(t){if(this._deliveryQueue?.current&&(this._deliverQueue(this._deliveryQueue),this._perfMon?.stop()),this._perfMon?.start(this._size),this._listeners)if(this._listeners instanceof Ho)this._deliver(this._listeners,t);else{let e=this._deliveryQueue;e.enqueue(this,t,this._listeners.length),this._deliverQueue(e)}this._perfMon?.stop()}hasListeners(){return this._size>0}},kC=class{constructor(){this.i=-1,this.end=0}enqueue(t,e,s){this.i=0,this.end=s,this.current=t,this.value=e}reset(){this.i=this.end,this.current=void 0,this.value=void 0}},Ta=class{constructor(){this.mapWindowIdToZoomLevel=new Map,this._onDidChangeZoomLevel=new re,this.onDidChangeZoomLevel=this._onDidChangeZoomLevel.event,this.mapWindowIdToZoomFactor=new Map,this._onDidChangeFullscreen=new re,this.onDidChangeFullscreen=this._onDidChangeFullscreen.event,this.mapWindowIdToFullScreen=new Map}getZoomLevel(e){return this.mapWindowIdToZoomLevel.get(this.getWindowId(e))??0}setZoomLevel(e,s){if(this.getZoomLevel(s)===e)return;let i=this.getWindowId(s);this.mapWindowIdToZoomLevel.set(i,e),this._onDidChangeZoomLevel.fire(i)}getZoomFactor(e){return this.mapWindowIdToZoomFactor.get(this.getWindowId(e))??1}setZoomFactor(e,s){this.mapWindowIdToZoomFactor.set(this.getWindowId(s),e)}setFullscreen(e,s){if(this.isFullscreen(s)===e)return;let i=this.getWindowId(s);this.mapWindowIdToFullScreen.set(i,e),this._onDidChangeFullscreen.fire(i)}isFullscreen(e){return!!this.mapWindowIdToFullScreen.get(this.getWindowId(e))}getWindowId(e){return e.vscodeWindowId}};Ta.INSTANCE=new Ta;var Zl=Ta;function NC(t,e,s){typeof e=="string"&&(e=t.matchMedia(e)),e.addEventListener("change",s)}Zl.INSTANCE.onDidChangeZoomLevel;function AC(t){return Zl.INSTANCE.getZoomFactor(t)}Zl.INSTANCE.onDidChangeFullscreen;var Ji=typeof navigator=="object"?navigator.userAgent:"",Da=Ji.indexOf("Firefox")>=0,EC=Ji.indexOf("AppleWebKit")>=0,ec=Ji.indexOf("Chrome")>=0,IC=!ec&&Ji.indexOf("Safari")>=0;Ji.indexOf("Electron/")>=0;Ji.indexOf("Android")>=0;var Wo=!1;if(typeof $s.matchMedia=="function"){let t=$s.matchMedia("(display-mode: standalone) or (display-mode: window-controls-overlay)"),e=$s.matchMedia("(display-mode: fullscreen)");Wo=t.matches,NC($s,t,({matches:s})=>{Wo&&e.matches||(Wo=s)})}var Ri="en",Ma=!1,Pa=!1,En=!1,pm=!1,fn,In=Ri,Cd=Ri,RC,Bs,gi=globalThis,Xt;typeof gi.vscode<"u"&&typeof gi.vscode.process<"u"?Xt=gi.vscode.process:typeof process<"u"&&typeof process?.versions?.node=="string"&&(Xt=process);var TC=typeof Xt?.versions?.electron=="string",DC=TC&&Xt?.type==="renderer";if(typeof Xt=="object"){Ma=Xt.platform==="win32",Pa=Xt.platform==="darwin",En=Xt.platform==="linux",En&&Xt.env.SNAP&&Xt.env.SNAP_REVISION,Xt.env.CI||Xt.env.BUILD_ARTIFACTSTAGINGDIRECTORY,fn=Ri,In=Ri;let t=Xt.env.VSCODE_NLS_CONFIG;if(t)try{let e=JSON.parse(t);fn=e.userLocale,Cd=e.osLocale,In=e.resolvedLanguage||Ri,RC=e.languagePack?.translationsConfigFile}catch{}pm=!0}else typeof navigator=="object"&&!DC?(Bs=navigator.userAgent,Ma=Bs.indexOf("Windows")>=0,Pa=Bs.indexOf("Macintosh")>=0,(Bs.indexOf("Macintosh")>=0||Bs.indexOf("iPad")>=0||Bs.indexOf("iPhone")>=0)&&navigator.maxTouchPoints&&navigator.maxTouchPoints>0,En=Bs.indexOf("Linux")>=0,Bs?.indexOf("Mobi")>=0,In=globalThis._VSCODE_NLS_LANGUAGE||Ri,fn=navigator.language.toLowerCase(),Cd=fn):console.error("Unable to resolve platform.");var gm=Ma,As=Pa,MC=En,jd=pm,Is=Bs,Us=In,PC;(t=>{function e(){return Us}t.value=e;function s(){return Us.length===2?Us==="en":Us.length>=3?Us[0]==="e"&&Us[1]==="n"&&Us[2]==="-":!1}t.isDefaultVariant=s;function i(){return Us==="en"}t.isDefault=i})(PC||={});var LC=typeof gi.postMessage=="function"&&!gi.importScripts;(()=>{if(LC){let t=[];gi.addEventListener("message",s=>{if(s.data&&s.data.vscodeScheduleAsyncWork)for(let i=0,n=t.length;i<n;i++){let o=t[i];if(o.id===s.data.vscodeScheduleAsyncWork){t.splice(i,1),o.callback();return}}});let e=0;return s=>{let i=++e;t.push({id:i,callback:s}),gi.postMessage({vscodeScheduleAsyncWork:i},"*")}}return t=>setTimeout(t)})();var BC=!!(Is&&Is.indexOf("Chrome")>=0);Is&&Is.indexOf("Firefox")>=0;!BC&&Is&&Is.indexOf("Safari")>=0;Is&&Is.indexOf("Edg/")>=0;Is&&Is.indexOf("Android")>=0;var ki=typeof navigator=="object"?navigator:{};jd||document.queryCommandSupported&&document.queryCommandSupported("copy")||ki&&ki.clipboard&&ki.clipboard.writeText,jd||ki&&ki.clipboard&&ki.clipboard.readText;var tc=class{constructor(){this._keyCodeToStr=[],this._strToKeyCode=Object.create(null)}define(t,e){this._keyCodeToStr[t]=e,this._strToKeyCode[e.toLowerCase()]=t}keyCodeToStr(t){return this._keyCodeToStr[t]}strToKeyCode(t){return this._strToKeyCode[t.toLowerCase()]||0}},Uo=new tc,kd=new tc,Nd=new tc,OC=new Array(230),_m;(t=>{function e(l){return Uo.keyCodeToStr(l)}t.toString=e;function s(l){return Uo.strToKeyCode(l)}t.fromString=s;function i(l){return kd.keyCodeToStr(l)}t.toUserSettingsUS=i;function n(l){return Nd.keyCodeToStr(l)}t.toUserSettingsGeneral=n;function o(l){return kd.strToKeyCode(l)||Nd.strToKeyCode(l)}t.fromUserSettings=o;function a(l){if(l>=98&&l<=113)return null;switch(l){case 16:return"Up";case 18:return"Down";case 15:return"Left";case 17:return"Right"}return Uo.keyCodeToStr(l)}t.toElectronAccelerator=a})(_m||={});var $C=class xm{constructor(e,s,i,n,o){this.ctrlKey=e,this.shiftKey=s,this.altKey=i,this.metaKey=n,this.keyCode=o}equals(e){return e instanceof xm&&this.ctrlKey===e.ctrlKey&&this.shiftKey===e.shiftKey&&this.altKey===e.altKey&&this.metaKey===e.metaKey&&this.keyCode===e.keyCode}getHashCode(){let e=this.ctrlKey?"1":"0",s=this.shiftKey?"1":"0",i=this.altKey?"1":"0",n=this.metaKey?"1":"0";return`K${e}${s}${i}${n}${this.keyCode}`}isModifierKey(){return this.keyCode===0||this.keyCode===5||this.keyCode===57||this.keyCode===6||this.keyCode===4}toKeybinding(){return new zC([this])}isDuplicateModifierCase(){return this.ctrlKey&&this.keyCode===5||this.shiftKey&&this.keyCode===4||this.altKey&&this.keyCode===6||this.metaKey&&this.keyCode===57}},zC=class{constructor(t){if(t.length===0)throw uC("chords");this.chords=t}getHashCode(){let t="";for(let e=0,s=this.chords.length;e<s;e++)e!==0&&(t+=";"),t+=this.chords[e].getHashCode();return t}equals(t){if(t===null||this.chords.length!==t.chords.length)return!1;for(let e=0;e<this.chords.length;e++)if(!this.chords[e].equals(t.chords[e]))return!1;return!0}};function FC(t){if(t.charCode){let s=String.fromCharCode(t.charCode).toUpperCase();return _m.fromString(s)}let e=t.keyCode;if(e===3)return 7;if(Da)switch(e){case 59:return 85;case 60:if(MC)return 97;break;case 61:return 86;case 107:return 109;case 109:return 111;case 173:return 88;case 224:if(As)return 57;break}else if(EC&&(As&&e===93||!As&&e===92))return 57;return OC[e]||0}var HC=As?256:2048,WC=512,UC=1024,KC=As?2048:256,Ad=class{constructor(t){this._standardKeyboardEventBrand=!0;let e=t;this.browserEvent=e,this.target=e.target,this.ctrlKey=e.ctrlKey,this.shiftKey=e.shiftKey,this.altKey=e.altKey,this.metaKey=e.metaKey,this.altGraphKey=e.getModifierState?.("AltGraph"),this.keyCode=FC(e),this.code=e.code,this.ctrlKey=this.ctrlKey||this.keyCode===5,this.altKey=this.altKey||this.keyCode===6,this.shiftKey=this.shiftKey||this.keyCode===4,this.metaKey=this.metaKey||this.keyCode===57,this._asKeybinding=this._computeKeybinding(),this._asKeyCodeChord=this._computeKeyCodeChord()}preventDefault(){this.browserEvent&&this.browserEvent.preventDefault&&this.browserEvent.preventDefault()}stopPropagation(){this.browserEvent&&this.browserEvent.stopPropagation&&this.browserEvent.stopPropagation()}toKeyCodeChord(){return this._asKeyCodeChord}equals(t){return this._asKeybinding===t}_computeKeybinding(){let t=0;this.keyCode!==5&&this.keyCode!==4&&this.keyCode!==6&&this.keyCode!==57&&(t=this.keyCode);let e=0;return this.ctrlKey&&(e|=HC),this.altKey&&(e|=WC),this.shiftKey&&(e|=UC),this.metaKey&&(e|=KC),e|=t,e}_computeKeyCodeChord(){let t=0;return this.keyCode!==5&&this.keyCode!==4&&this.keyCode!==6&&this.keyCode!==57&&(t=this.keyCode),new $C(this.ctrlKey,this.shiftKey,this.altKey,this.metaKey,t)}},Ed=new WeakMap;function qC(t){if(!t.parent||t.parent===t)return null;try{let e=t.location,s=t.parent.location;if(e.origin!=="null"&&s.origin!=="null"&&e.origin!==s.origin)return null}catch{return null}return t.parent}var GC=class{static getSameOriginWindowChain(t){let e=Ed.get(t);if(!e){e=[],Ed.set(t,e);let s=t,i;do i=qC(s),i?e.push({window:new WeakRef(s),iframeElement:s.frameElement||null}):e.push({window:new WeakRef(s),iframeElement:null}),s=i;while(s)}return e.slice(0)}static getPositionOfChildWindowRelativeToAncestorWindow(t,e){if(!e||t===e)return{top:0,left:0};let s=0,i=0,n=this.getSameOriginWindowChain(t);for(let o of n){let a=o.window.deref();if(s+=a?.scrollY??0,i+=a?.scrollX??0,a===e||!o.iframeElement)break;let l=o.iframeElement.getBoundingClientRect();s+=l.top,i+=l.left}return{top:s,left:i}}},mn=class{constructor(t,e){this.timestamp=Date.now(),this.browserEvent=e,this.leftButton=e.button===0,this.middleButton=e.button===1,this.rightButton=e.button===2,this.buttons=e.buttons,this.target=e.target,this.detail=e.detail||1,e.type==="dblclick"&&(this.detail=2),this.ctrlKey=e.ctrlKey,this.shiftKey=e.shiftKey,this.altKey=e.altKey,this.metaKey=e.metaKey,typeof e.pageX=="number"?(this.posx=e.pageX,this.posy=e.pageY):(this.posx=e.clientX+this.target.ownerDocument.body.scrollLeft+this.target.ownerDocument.documentElement.scrollLeft,this.posy=e.clientY+this.target.ownerDocument.body.scrollTop+this.target.ownerDocument.documentElement.scrollTop);let s=GC.getPositionOfChildWindowRelativeToAncestorWindow(t,e.view);this.posx-=s.left,this.posy-=s.top}preventDefault(){this.browserEvent.preventDefault()}stopPropagation(){this.browserEvent.stopPropagation()}},Id=class{constructor(t,e=0,s=0){this.browserEvent=t||null,this.target=t?t.target||t.targetNode||t.srcElement:null,this.deltaY=s,this.deltaX=e;let i=!1;if(ec){let n=navigator.userAgent.match(/Chrome\/(\d+)/);i=(n?parseInt(n[1]):123)<=122}if(t){let n=t,o=t,a=t.view?.devicePixelRatio||1;if(typeof n.wheelDeltaY<"u")i?this.deltaY=n.wheelDeltaY/(120*a):this.deltaY=n.wheelDeltaY/120;else if(typeof o.VERTICAL_AXIS<"u"&&o.axis===o.VERTICAL_AXIS)this.deltaY=-o.detail/3;else if(t.type==="wheel"){let l=t;l.deltaMode===l.DOM_DELTA_LINE?Da&&!As?this.deltaY=-t.deltaY/3:this.deltaY=-t.deltaY:this.deltaY=-t.deltaY/40}if(typeof n.wheelDeltaX<"u")IC&&gm?this.deltaX=-(n.wheelDeltaX/120):i?this.deltaX=n.wheelDeltaX/(120*a):this.deltaX=n.wheelDeltaX/120;else if(typeof o.HORIZONTAL_AXIS<"u"&&o.axis===o.HORIZONTAL_AXIS)this.deltaX=-t.detail/3;else if(t.type==="wheel"){let l=t;l.deltaMode===l.DOM_DELTA_LINE?Da&&!As?this.deltaX=-t.deltaX/3:this.deltaX=-t.deltaX:this.deltaX=-t.deltaX/40}this.deltaY===0&&this.deltaX===0&&t.wheelDelta&&(i?this.deltaY=t.wheelDelta/(120*a):this.deltaY=t.wheelDelta/120)}}preventDefault(){this.browserEvent?.preventDefault()}stopPropagation(){this.browserEvent?.stopPropagation()}},vm=Object.freeze(function(t,e){let s=setTimeout(t.bind(e),0);return{dispose(){clearTimeout(s)}}}),YC;(t=>{function e(s){return s===t.None||s===t.Cancelled||s instanceof XC?!0:!s||typeof s!="object"?!1:typeof s.isCancellationRequested=="boolean"&&typeof s.onCancellationRequested=="function"}t.isCancellationToken=e,t.None=Object.freeze({isCancellationRequested:!1,onCancellationRequested:yt.None}),t.Cancelled=Object.freeze({isCancellationRequested:!0,onCancellationRequested:vm})})(YC||={});var XC=class{constructor(){this._isCancelled=!1,this._emitter=null}cancel(){this._isCancelled||(this._isCancelled=!0,this._emitter&&(this._emitter.fire(void 0),this.dispose()))}get isCancellationRequested(){return this._isCancelled}get onCancellationRequested(){return this._isCancelled?vm:(this._emitter||(this._emitter=new re),this._emitter.event)}dispose(){this._emitter&&(this._emitter.dispose(),this._emitter=null)}},sc=class{constructor(t,e){this._isDisposed=!1,this._token=-1,typeof t=="function"&&typeof e=="number"&&this.setIfNotSet(t,e)}dispose(){this.cancel(),this._isDisposed=!0}cancel(){this._token!==-1&&(clearTimeout(this._token),this._token=-1)}cancelAndSet(t,e){if(this._isDisposed)throw new Na("Calling 'cancelAndSet' on a disposed TimeoutTimer");this.cancel(),this._token=setTimeout(()=>{this._token=-1,t()},e)}setIfNotSet(t,e){if(this._isDisposed)throw new Na("Calling 'setIfNotSet' on a disposed TimeoutTimer");this._token===-1&&(this._token=setTimeout(()=>{this._token=-1,t()},e))}},JC=class{constructor(){this.disposable=void 0,this.isDisposed=!1}cancel(){this.disposable?.dispose(),this.disposable=void 0}cancelAndSet(t,e,s=globalThis){if(this.isDisposed)throw new Na("Calling 'cancelAndSet' on a disposed IntervalTimer");this.cancel();let i=s.setInterval(()=>{t()},e);this.disposable=Fe(()=>{s.clearInterval(i),this.disposable=void 0})}dispose(){this.cancel(),this.isDisposed=!0}},QC;(t=>{async function e(i){let n,o=await Promise.all(i.map(a=>a.then(l=>l,l=>{n||(n=l)})));if(typeof n<"u")throw n;return o}t.settled=e;function s(i){return new Promise(async(n,o)=>{try{await i(n,o)}catch(a){o(a)}})}t.withAsyncBody=s})(QC||={});var Rd=class is{static fromArray(e){return new is(s=>{s.emitMany(e)})}static fromPromise(e){return new is(async s=>{s.emitMany(await e)})}static fromPromises(e){return new is(async s=>{await Promise.all(e.map(async i=>s.emitOne(await i)))})}static merge(e){return new is(async s=>{await Promise.all(e.map(async i=>{for await(let n of i)s.emitOne(n)}))})}constructor(e,s){this._state=0,this._results=[],this._error=null,this._onReturn=s,this._onStateChanged=new re,queueMicrotask(async()=>{let i={emitOne:n=>this.emitOne(n),emitMany:n=>this.emitMany(n),reject:n=>this.reject(n)};try{await Promise.resolve(e(i)),this.resolve()}catch(n){this.reject(n)}finally{i.emitOne=void 0,i.emitMany=void 0,i.reject=void 0}})}[Symbol.asyncIterator](){let e=0;return{next:async()=>{do{if(this._state===2)throw this._error;if(e<this._results.length)return{done:!1,value:this._results[e++]};if(this._state===1)return{done:!0,value:void 0};await yt.toPromise(this._onStateChanged.event)}while(!0)},return:async()=>(this._onReturn?.(),{done:!0,value:void 0})}}static map(e,s){return new is(async i=>{for await(let n of e)i.emitOne(s(n))})}map(e){return is.map(this,e)}static filter(e,s){return new is(async i=>{for await(let n of e)s(n)&&i.emitOne(n)})}filter(e){return is.filter(this,e)}static coalesce(e){return is.filter(e,s=>!!s)}coalesce(){return is.coalesce(this)}static async toPromise(e){let s=[];for await(let i of e)s.push(i);return s}toPromise(){return is.toPromise(this)}emitOne(e){this._state===0&&(this._results.push(e),this._onStateChanged.fire())}emitMany(e){this._state===0&&(this._results=this._results.concat(e),this._onStateChanged.fire())}resolve(){this._state===0&&(this._state=1,this._onStateChanged.fire())}reject(e){this._state===0&&(this._state=2,this._error=e,this._onStateChanged.fire())}};Rd.EMPTY=Rd.fromArray([]);var{getWindow:ws,getWindowId:ZC,onDidRegisterWindow:e3}=(function(){let t=new Map,e={window:$s,disposables:new ti};t.set($s.vscodeWindowId,e);let s=new re,i=new re,n=new re;function o(a,l){return(typeof a=="number"?t.get(a):void 0)??(l?e:void 0)}return{onDidRegisterWindow:s.event,onWillUnregisterWindow:n.event,onDidUnregisterWindow:i.event,registerWindow(a){if(t.has(a.vscodeWindowId))return Ve.None;let l=new ti,c={window:a,disposables:l.add(new ti)};return t.set(a.vscodeWindowId,c),l.add(Fe(()=>{t.delete(a.vscodeWindowId),i.fire(a)})),l.add(ye(a,ht.BEFORE_UNLOAD,()=>{n.fire(a)})),s.fire(c),l},getWindows(){return t.values()},getWindowsCount(){return t.size},getWindowId(a){return a.vscodeWindowId},hasWindow(a){return t.has(a)},getWindowById:o,getWindow(a){let l=a;if(l?.ownerDocument?.defaultView)return l.ownerDocument.defaultView.window;let c=a;return c?.view?c.view.window:$s},getDocument(a){return ws(a).document}}})(),t3=class{constructor(t,e,s,i){this._node=t,this._type=e,this._handler=s,this._options=i||!1,this._node.addEventListener(this._type,this._handler,this._options)}dispose(){this._handler&&(this._node.removeEventListener(this._type,this._handler,this._options),this._node=null,this._handler=null)}};function ye(t,e,s,i){return new t3(t,e,s,i)}var Td=function(t,e,s,i){return ye(t,e,s,i)},ic,s3=class extends JC{constructor(t){super(),this.defaultTarget=t&&ws(t)}cancelAndSet(t,e,s){return super.cancelAndSet(t,e,s??this.defaultTarget)}},Dd=class{constructor(t,e=0){this._runner=t,this.priority=e,this._canceled=!1}dispose(){this._canceled=!0}execute(){if(!this._canceled)try{this._runner()}catch(t){An(t)}}static sort(t,e){return e.priority-t.priority}};(function(){let t=new Map,e=new Map,s=new Map,i=new Map,n=o=>{s.set(o,!1);let a=t.get(o)??[];for(e.set(o,a),t.set(o,[]),i.set(o,!0);a.length>0;)a.sort(Dd.sort),a.shift().execute();i.set(o,!1)};ic=(o,a,l=0)=>{let c=ZC(o),d=new Dd(a,l),u=t.get(c);return u||(u=[],t.set(c,u)),u.push(d),s.get(c)||(s.set(c,!0),o.requestAnimationFrame(()=>n(c))),d}})();function i3(t){let e=t.getBoundingClientRect(),s=ws(t);return{left:e.left+s.scrollX,top:e.top+s.scrollY,width:e.width,height:e.height}}var ht={CLICK:"click",MOUSE_DOWN:"mousedown",MOUSE_OVER:"mouseover",MOUSE_LEAVE:"mouseleave",MOUSE_WHEEL:"wheel",POINTER_UP:"pointerup",POINTER_DOWN:"pointerdown",POINTER_MOVE:"pointermove",KEY_DOWN:"keydown",KEY_UP:"keyup",BEFORE_UNLOAD:"beforeunload",CHANGE:"change",FOCUS:"focus",BLUR:"blur",INPUT:"input"},r3=class{constructor(t){this.domNode=t,this._maxWidth="",this._width="",this._height="",this._top="",this._left="",this._bottom="",this._right="",this._paddingTop="",this._paddingLeft="",this._paddingBottom="",this._paddingRight="",this._fontFamily="",this._fontWeight="",this._fontSize="",this._fontStyle="",this._fontFeatureSettings="",this._fontVariationSettings="",this._textDecoration="",this._lineHeight="",this._letterSpacing="",this._className="",this._display="",this._position="",this._visibility="",this._color="",this._backgroundColor="",this._layerHint=!1,this._contain="none",this._boxShadow=""}setMaxWidth(t){let e=zt(t);this._maxWidth!==e&&(this._maxWidth=e,this.domNode.style.maxWidth=this._maxWidth)}setWidth(t){let e=zt(t);this._width!==e&&(this._width=e,this.domNode.style.width=this._width)}setHeight(t){let e=zt(t);this._height!==e&&(this._height=e,this.domNode.style.height=this._height)}setTop(t){let e=zt(t);this._top!==e&&(this._top=e,this.domNode.style.top=this._top)}setLeft(t){let e=zt(t);this._left!==e&&(this._left=e,this.domNode.style.left=this._left)}setBottom(t){let e=zt(t);this._bottom!==e&&(this._bottom=e,this.domNode.style.bottom=this._bottom)}setRight(t){let e=zt(t);this._right!==e&&(this._right=e,this.domNode.style.right=this._right)}setPaddingTop(t){let e=zt(t);this._paddingTop!==e&&(this._paddingTop=e,this.domNode.style.paddingTop=this._paddingTop)}setPaddingLeft(t){let e=zt(t);this._paddingLeft!==e&&(this._paddingLeft=e,this.domNode.style.paddingLeft=this._paddingLeft)}setPaddingBottom(t){let e=zt(t);this._paddingBottom!==e&&(this._paddingBottom=e,this.domNode.style.paddingBottom=this._paddingBottom)}setPaddingRight(t){let e=zt(t);this._paddingRight!==e&&(this._paddingRight=e,this.domNode.style.paddingRight=this._paddingRight)}setFontFamily(t){this._fontFamily!==t&&(this._fontFamily=t,this.domNode.style.fontFamily=this._fontFamily)}setFontWeight(t){this._fontWeight!==t&&(this._fontWeight=t,this.domNode.style.fontWeight=this._fontWeight)}setFontSize(t){let e=zt(t);this._fontSize!==e&&(this._fontSize=e,this.domNode.style.fontSize=this._fontSize)}setFontStyle(t){this._fontStyle!==t&&(this._fontStyle=t,this.domNode.style.fontStyle=this._fontStyle)}setFontFeatureSettings(t){this._fontFeatureSettings!==t&&(this._fontFeatureSettings=t,this.domNode.style.fontFeatureSettings=this._fontFeatureSettings)}setFontVariationSettings(t){this._fontVariationSettings!==t&&(this._fontVariationSettings=t,this.domNode.style.fontVariationSettings=this._fontVariationSettings)}setTextDecoration(t){this._textDecoration!==t&&(this._textDecoration=t,this.domNode.style.textDecoration=this._textDecoration)}setLineHeight(t){let e=zt(t);this._lineHeight!==e&&(this._lineHeight=e,this.domNode.style.lineHeight=this._lineHeight)}setLetterSpacing(t){let e=zt(t);this._letterSpacing!==e&&(this._letterSpacing=e,this.domNode.style.letterSpacing=this._letterSpacing)}setClassName(t){this._className!==t&&(this._className=t,this.domNode.className=this._className)}toggleClassName(t,e){this.domNode.classList.toggle(t,e),this._className=this.domNode.className}setDisplay(t){this._display!==t&&(this._display=t,this.domNode.style.display=this._display)}setPosition(t){this._position!==t&&(this._position=t,this.domNode.style.position=this._position)}setVisibility(t){this._visibility!==t&&(this._visibility=t,this.domNode.style.visibility=this._visibility)}setColor(t){this._color!==t&&(this._color=t,this.domNode.style.color=this._color)}setBackgroundColor(t){this._backgroundColor!==t&&(this._backgroundColor=t,this.domNode.style.backgroundColor=this._backgroundColor)}setLayerHinting(t){this._layerHint!==t&&(this._layerHint=t,this.domNode.style.transform=this._layerHint?"translate3d(0px, 0px, 0px)":"")}setBoxShadow(t){this._boxShadow!==t&&(this._boxShadow=t,this.domNode.style.boxShadow=t)}setContain(t){this._contain!==t&&(this._contain=t,this.domNode.style.contain=this._contain)}setAttribute(t,e){this.domNode.setAttribute(t,e)}removeAttribute(t){this.domNode.removeAttribute(t)}appendChild(t){this.domNode.appendChild(t.domNode)}removeChild(t){this.domNode.removeChild(t.domNode)}};function zt(t){return typeof t=="number"?`${t}px`:t}function wr(t){return new r3(t)}var bm=class{constructor(){this._hooks=new ti,this._pointerMoveCallback=null,this._onStopCallback=null}dispose(){this.stopMonitoring(!1),this._hooks.dispose()}stopMonitoring(t,e){if(!this.isMonitoring())return;this._hooks.clear(),this._pointerMoveCallback=null;let s=this._onStopCallback;this._onStopCallback=null,t&&s&&s(e)}isMonitoring(){return!!this._pointerMoveCallback}startMonitoring(t,e,s,i,n){this.isMonitoring()&&this.stopMonitoring(!1),this._pointerMoveCallback=i,this._onStopCallback=n;let o=t;try{t.setPointerCapture(e),this._hooks.add(Fe(()=>{try{t.releasePointerCapture(e)}catch{}}))}catch{o=ws(t)}this._hooks.add(ye(o,ht.POINTER_MOVE,a=>{if(a.buttons!==s){this.stopMonitoring(!0);return}a.preventDefault(),this._pointerMoveCallback(a)})),this._hooks.add(ye(o,ht.POINTER_UP,a=>this.stopMonitoring(!0)))}};function n3(t,e,s){let i=null,n=null;if(typeof s.value=="function"?(i="value",n=s.value,n.length!==0&&console.warn("Memoize should only be used in functions with zero parameters")):typeof s.get=="function"&&(i="get",n=s.get),!n)throw new Error("not supported");let o=`$memoize$${e}`;s[i]=function(...a){return this.hasOwnProperty(o)||Object.defineProperty(this,o,{configurable:!1,enumerable:!1,writable:!1,value:n.apply(this,a)}),this[o]}}var bs;(t=>(t.Tap="-xterm-gesturetap",t.Change="-xterm-gesturechange",t.Start="-xterm-gesturestart",t.End="-xterm-gesturesend",t.Contextmenu="-xterm-gesturecontextmenu"))(bs||={});var dr=class Vt extends Ve{constructor(){super(),this.dispatched=!1,this.targets=new Vd,this.ignoreTargets=new Vd,this.activeTouches={},this.handle=null,this._lastSetTapCountTime=0,this._register(yt.runAndSubscribe(e3,({window:e,disposables:s})=>{s.add(ye(e.document,"touchstart",i=>this.onTouchStart(i),{passive:!1})),s.add(ye(e.document,"touchend",i=>this.onTouchEnd(e,i))),s.add(ye(e.document,"touchmove",i=>this.onTouchMove(i),{passive:!1}))},{window:$s,disposables:this._store}))}static addTarget(e){if(!Vt.isTouchDevice())return Ve.None;Vt.INSTANCE||(Vt.INSTANCE=new Vt);let s=Vt.INSTANCE.targets.push(e);return Fe(s)}static ignoreTarget(e){if(!Vt.isTouchDevice())return Ve.None;Vt.INSTANCE||(Vt.INSTANCE=new Vt);let s=Vt.INSTANCE.ignoreTargets.push(e);return Fe(s)}static isTouchDevice(){return"ontouchstart"in $s||navigator.maxTouchPoints>0}dispose(){this.handle&&(this.handle.dispose(),this.handle=null),super.dispose()}onTouchStart(e){let s=Date.now();this.handle&&(this.handle.dispose(),this.handle=null);for(let i=0,n=e.targetTouches.length;i<n;i++){let o=e.targetTouches.item(i);this.activeTouches[o.identifier]={id:o.identifier,initialTarget:o.target,initialTimeStamp:s,initialPageX:o.pageX,initialPageY:o.pageY,rollingTimestamps:[s],rollingPageX:[o.pageX],rollingPageY:[o.pageY]};let a=this.newGestureEvent(bs.Start,o.target);a.pageX=o.pageX,a.pageY=o.pageY,this.dispatchEvent(a)}this.dispatched&&(e.preventDefault(),e.stopPropagation(),this.dispatched=!1)}onTouchEnd(e,s){let i=Date.now(),n=Object.keys(this.activeTouches).length;for(let o=0,a=s.changedTouches.length;o<a;o++){let l=s.changedTouches.item(o);if(!this.activeTouches.hasOwnProperty(String(l.identifier))){console.warn("move of an UNKNOWN touch",l);continue}let c=this.activeTouches[l.identifier],d=Date.now()-c.initialTimeStamp;if(d<Vt.HOLD_DELAY&&Math.abs(c.initialPageX-Gt(c.rollingPageX))<30&&Math.abs(c.initialPageY-Gt(c.rollingPageY))<30){let u=this.newGestureEvent(bs.Tap,c.initialTarget);u.pageX=Gt(c.rollingPageX),u.pageY=Gt(c.rollingPageY),this.dispatchEvent(u)}else if(d>=Vt.HOLD_DELAY&&Math.abs(c.initialPageX-Gt(c.rollingPageX))<30&&Math.abs(c.initialPageY-Gt(c.rollingPageY))<30){let u=this.newGestureEvent(bs.Contextmenu,c.initialTarget);u.pageX=Gt(c.rollingPageX),u.pageY=Gt(c.rollingPageY),this.dispatchEvent(u)}else if(n===1){let u=Gt(c.rollingPageX),h=Gt(c.rollingPageY),f=Gt(c.rollingTimestamps)-c.rollingTimestamps[0],m=u-c.rollingPageX[0],p=h-c.rollingPageY[0],g=[...this.targets].filter(_=>c.initialTarget instanceof Node&&_.contains(c.initialTarget));this.inertia(e,g,i,Math.abs(m)/f,m>0?1:-1,u,Math.abs(p)/f,p>0?1:-1,h)}this.dispatchEvent(this.newGestureEvent(bs.End,c.initialTarget)),delete this.activeTouches[l.identifier]}this.dispatched&&(s.preventDefault(),s.stopPropagation(),this.dispatched=!1)}newGestureEvent(e,s){let i=document.createEvent("CustomEvent");return i.initEvent(e,!1,!0),i.initialTarget=s,i.tapCount=0,i}dispatchEvent(e){if(e.type===bs.Tap){let s=new Date().getTime(),i=0;s-this._lastSetTapCountTime>Vt.CLEAR_TAP_COUNT_TIME?i=1:i=2,this._lastSetTapCountTime=s,e.tapCount=i}else(e.type===bs.Change||e.type===bs.Contextmenu)&&(this._lastSetTapCountTime=0);if(e.initialTarget instanceof Node){for(let i of this.ignoreTargets)if(i.contains(e.initialTarget))return;let s=[];for(let i of this.targets)if(i.contains(e.initialTarget)){let n=0,o=e.initialTarget;for(;o&&o!==i;)n++,o=o.parentElement;s.push([n,i])}s.sort((i,n)=>i[0]-n[0]);for(let[i,n]of s)n.dispatchEvent(e),this.dispatched=!0}}inertia(e,s,i,n,o,a,l,c,d){this.handle=ic(e,()=>{let u=Date.now(),h=u-i,f=0,m=0,p=!0;n+=Vt.SCROLL_FRICTION*h,l+=Vt.SCROLL_FRICTION*h,n>0&&(p=!1,f=o*n*h),l>0&&(p=!1,m=c*l*h);let g=this.newGestureEvent(bs.Change);g.translationX=f,g.translationY=m,s.forEach(_=>_.dispatchEvent(g)),p||this.inertia(e,s,u,n,o,a+f,l,c,d+m)})}onTouchMove(e){let s=Date.now();for(let i=0,n=e.changedTouches.length;i<n;i++){let o=e.changedTouches.item(i);if(!this.activeTouches.hasOwnProperty(String(o.identifier))){console.warn("end of an UNKNOWN touch",o);continue}let a=this.activeTouches[o.identifier],l=this.newGestureEvent(bs.Change,a.initialTarget);l.translationX=o.pageX-Gt(a.rollingPageX),l.translationY=o.pageY-Gt(a.rollingPageY),l.pageX=o.pageX,l.pageY=o.pageY,this.dispatchEvent(l),a.rollingPageX.length>3&&(a.rollingPageX.shift(),a.rollingPageY.shift(),a.rollingTimestamps.shift()),a.rollingPageX.push(o.pageX),a.rollingPageY.push(o.pageY),a.rollingTimestamps.push(s)}this.dispatched&&(e.preventDefault(),e.stopPropagation(),this.dispatched=!1)}};dr.SCROLL_FRICTION=-.005,dr.HOLD_DELAY=700,dr.CLEAR_TAP_COUNT_TIME=400,Ye([n3],dr,"isTouchDevice",1);var o3=dr,rc=class extends Ve{onclick(t,e){this._register(ye(t,ht.CLICK,s=>e(new mn(ws(t),s))))}onmousedown(t,e){this._register(ye(t,ht.MOUSE_DOWN,s=>e(new mn(ws(t),s))))}onmouseover(t,e){this._register(ye(t,ht.MOUSE_OVER,s=>e(new mn(ws(t),s))))}onmouseleave(t,e){this._register(ye(t,ht.MOUSE_LEAVE,s=>e(new mn(ws(t),s))))}onkeydown(t,e){this._register(ye(t,ht.KEY_DOWN,s=>e(new Ad(s))))}onkeyup(t,e){this._register(ye(t,ht.KEY_UP,s=>e(new Ad(s))))}oninput(t,e){this._register(ye(t,ht.INPUT,e))}onblur(t,e){this._register(ye(t,ht.BLUR,e))}onfocus(t,e){this._register(ye(t,ht.FOCUS,e))}onchange(t,e){this._register(ye(t,ht.CHANGE,e))}ignoreGesture(t){return o3.ignoreTarget(t)}},Md=11,a3=class extends rc{constructor(t){super(),this._onActivate=t.onActivate,this.bgDomNode=document.createElement("div"),this.bgDomNode.className="arrow-background",this.bgDomNode.style.position="absolute",this.bgDomNode.style.width=t.bgWidth+"px",this.bgDomNode.style.height=t.bgHeight+"px",typeof t.top<"u"&&(this.bgDomNode.style.top="0px"),typeof t.left<"u"&&(this.bgDomNode.style.left="0px"),typeof t.bottom<"u"&&(this.bgDomNode.style.bottom="0px"),typeof t.right<"u"&&(this.bgDomNode.style.right="0px"),this.domNode=document.createElement("div"),this.domNode.className=t.className,this.domNode.style.position="absolute",this.domNode.style.width=Md+"px",this.domNode.style.height=Md+"px",typeof t.top<"u"&&(this.domNode.style.top=t.top+"px"),typeof t.left<"u"&&(this.domNode.style.left=t.left+"px"),typeof t.bottom<"u"&&(this.domNode.style.bottom=t.bottom+"px"),typeof t.right<"u"&&(this.domNode.style.right=t.right+"px"),this._pointerMoveMonitor=this._register(new bm),this._register(Td(this.bgDomNode,ht.POINTER_DOWN,e=>this._arrowPointerDown(e))),this._register(Td(this.domNode,ht.POINTER_DOWN,e=>this._arrowPointerDown(e))),this._pointerdownRepeatTimer=this._register(new s3),this._pointerdownScheduleRepeatTimer=this._register(new sc)}_arrowPointerDown(t){if(!t.target||!(t.target instanceof Element))return;let e=()=>{this._pointerdownRepeatTimer.cancelAndSet(()=>this._onActivate(),1e3/24,ws(t))};this._onActivate(),this._pointerdownRepeatTimer.cancel(),this._pointerdownScheduleRepeatTimer.cancelAndSet(e,200),this._pointerMoveMonitor.startMonitoring(t.target,t.pointerId,t.buttons,s=>{},()=>{this._pointerdownRepeatTimer.cancel(),this._pointerdownScheduleRepeatTimer.cancel()}),t.preventDefault()}},l3=class La{constructor(e,s,i,n,o,a,l){this._forceIntegerValues=e,this._scrollStateBrand=void 0,this._forceIntegerValues&&(s=s|0,i=i|0,n=n|0,o=o|0,a=a|0,l=l|0),this.rawScrollLeft=n,this.rawScrollTop=l,s<0&&(s=0),n+s>i&&(n=i-s),n<0&&(n=0),o<0&&(o=0),l+o>a&&(l=a-o),l<0&&(l=0),this.width=s,this.scrollWidth=i,this.scrollLeft=n,this.height=o,this.scrollHeight=a,this.scrollTop=l}equals(e){return this.rawScrollLeft===e.rawScrollLeft&&this.rawScrollTop===e.rawScrollTop&&this.width===e.width&&this.scrollWidth===e.scrollWidth&&this.scrollLeft===e.scrollLeft&&this.height===e.height&&this.scrollHeight===e.scrollHeight&&this.scrollTop===e.scrollTop}withScrollDimensions(e,s){return new La(this._forceIntegerValues,typeof e.width<"u"?e.width:this.width,typeof e.scrollWidth<"u"?e.scrollWidth:this.scrollWidth,s?this.rawScrollLeft:this.scrollLeft,typeof e.height<"u"?e.height:this.height,typeof e.scrollHeight<"u"?e.scrollHeight:this.scrollHeight,s?this.rawScrollTop:this.scrollTop)}withScrollPosition(e){return new La(this._forceIntegerValues,this.width,this.scrollWidth,typeof e.scrollLeft<"u"?e.scrollLeft:this.rawScrollLeft,this.height,this.scrollHeight,typeof e.scrollTop<"u"?e.scrollTop:this.rawScrollTop)}createScrollEvent(e,s){let i=this.width!==e.width,n=this.scrollWidth!==e.scrollWidth,o=this.scrollLeft!==e.scrollLeft,a=this.height!==e.height,l=this.scrollHeight!==e.scrollHeight,c=this.scrollTop!==e.scrollTop;return{inSmoothScrolling:s,oldWidth:e.width,oldScrollWidth:e.scrollWidth,oldScrollLeft:e.scrollLeft,width:this.width,scrollWidth:this.scrollWidth,scrollLeft:this.scrollLeft,oldHeight:e.height,oldScrollHeight:e.scrollHeight,oldScrollTop:e.scrollTop,height:this.height,scrollHeight:this.scrollHeight,scrollTop:this.scrollTop,widthChanged:i,scrollWidthChanged:n,scrollLeftChanged:o,heightChanged:a,scrollHeightChanged:l,scrollTopChanged:c}}},c3=class extends Ve{constructor(t){super(),this._scrollableBrand=void 0,this._onScroll=this._register(new re),this.onScroll=this._onScroll.event,this._smoothScrollDuration=t.smoothScrollDuration,this._scheduleAtNextAnimationFrame=t.scheduleAtNextAnimationFrame,this._state=new l3(t.forceIntegerValues,0,0,0,0,0,0),this._smoothScrolling=null}dispose(){this._smoothScrolling&&(this._smoothScrolling.dispose(),this._smoothScrolling=null),super.dispose()}setSmoothScrollDuration(t){this._smoothScrollDuration=t}validateScrollPosition(t){return this._state.withScrollPosition(t)}getScrollDimensions(){return this._state}setScrollDimensions(t,e){let s=this._state.withScrollDimensions(t,e);this._setState(s,!!this._smoothScrolling),this._smoothScrolling?.acceptScrollDimensions(this._state)}getFutureScrollPosition(){return this._smoothScrolling?this._smoothScrolling.to:this._state}getCurrentScrollPosition(){return this._state}setScrollPositionNow(t){let e=this._state.withScrollPosition(t);this._smoothScrolling&&(this._smoothScrolling.dispose(),this._smoothScrolling=null),this._setState(e,!1)}setScrollPositionSmooth(t,e){if(this._smoothScrollDuration===0)return this.setScrollPositionNow(t);if(this._smoothScrolling){t={scrollLeft:typeof t.scrollLeft>"u"?this._smoothScrolling.to.scrollLeft:t.scrollLeft,scrollTop:typeof t.scrollTop>"u"?this._smoothScrolling.to.scrollTop:t.scrollTop};let s=this._state.withScrollPosition(t);if(this._smoothScrolling.to.scrollLeft===s.scrollLeft&&this._smoothScrolling.to.scrollTop===s.scrollTop)return;let i;e?i=new Ld(this._smoothScrolling.from,s,this._smoothScrolling.startTime,this._smoothScrolling.duration):i=this._smoothScrolling.combine(this._state,s,this._smoothScrollDuration),this._smoothScrolling.dispose(),this._smoothScrolling=i}else{let s=this._state.withScrollPosition(t);this._smoothScrolling=Ld.start(this._state,s,this._smoothScrollDuration)}this._smoothScrolling.animationFrameDisposable=this._scheduleAtNextAnimationFrame(()=>{this._smoothScrolling&&(this._smoothScrolling.animationFrameDisposable=null,this._performSmoothScrolling())})}hasPendingScrollAnimation(){return!!this._smoothScrolling}_performSmoothScrolling(){if(!this._smoothScrolling)return;let t=this._smoothScrolling.tick(),e=this._state.withScrollPosition(t);if(this._setState(e,!0),!!this._smoothScrolling){if(t.isDone){this._smoothScrolling.dispose(),this._smoothScrolling=null;return}this._smoothScrolling.animationFrameDisposable=this._scheduleAtNextAnimationFrame(()=>{this._smoothScrolling&&(this._smoothScrolling.animationFrameDisposable=null,this._performSmoothScrolling())})}}_setState(t,e){let s=this._state;s.equals(t)||(this._state=t,this._onScroll.fire(this._state.createScrollEvent(s,e)))}},Pd=class{constructor(t,e,s){this.scrollLeft=t,this.scrollTop=e,this.isDone=s}};function Ko(t,e){let s=e-t;return function(i){return t+s*u3(i)}}function d3(t,e,s){return function(i){return i<s?t(i/s):e((i-s)/(1-s))}}var Ld=class Ba{constructor(e,s,i,n){this.from=e,this.to=s,this.duration=n,this.startTime=i,this.animationFrameDisposable=null,this._initAnimations()}_initAnimations(){this.scrollLeft=this._initAnimation(this.from.scrollLeft,this.to.scrollLeft,this.to.width),this.scrollTop=this._initAnimation(this.from.scrollTop,this.to.scrollTop,this.to.height)}_initAnimation(e,s,i){if(Math.abs(e-s)>2.5*i){let n,o;return e<s?(n=e+.75*i,o=s-.75*i):(n=e-.75*i,o=s+.75*i),d3(Ko(e,n),Ko(o,s),.33)}return Ko(e,s)}dispose(){this.animationFrameDisposable!==null&&(this.animationFrameDisposable.dispose(),this.animationFrameDisposable=null)}acceptScrollDimensions(e){this.to=e.withScrollPosition(this.to),this._initAnimations()}tick(){return this._tick(Date.now())}_tick(e){let s=(e-this.startTime)/this.duration;if(s<1){let i=this.scrollLeft(s),n=this.scrollTop(s);return new Pd(i,n,!1)}return new Pd(this.to.scrollLeft,this.to.scrollTop,!0)}combine(e,s,i){return Ba.start(e,s,i)}static start(e,s,i){i=i+10;let n=Date.now()-10;return new Ba(e,s,n,i)}};function h3(t){return Math.pow(t,3)}function u3(t){return 1-h3(1-t)}var f3=class extends Ve{constructor(t,e,s){super(),this._visibility=t,this._visibleClassName=e,this._invisibleClassName=s,this._domNode=null,this._isVisible=!1,this._isNeeded=!1,this._rawShouldBeVisible=!1,this._shouldBeVisible=!1,this._revealTimer=this._register(new sc)}setVisibility(t){this._visibility!==t&&(this._visibility=t,this._updateShouldBeVisible())}setShouldBeVisible(t){this._rawShouldBeVisible=t,this._updateShouldBeVisible()}_applyVisibilitySetting(){return this._visibility===2?!1:this._visibility===3?!0:this._rawShouldBeVisible}_updateShouldBeVisible(){let t=this._applyVisibilitySetting();this._shouldBeVisible!==t&&(this._shouldBeVisible=t,this.ensureVisibility())}setIsNeeded(t){this._isNeeded!==t&&(this._isNeeded=t,this.ensureVisibility())}setDomNode(t){this._domNode=t,this._domNode.setClassName(this._invisibleClassName),this.setShouldBeVisible(!1)}ensureVisibility(){if(!this._isNeeded){this._hide(!1);return}this._shouldBeVisible?this._reveal():this._hide(!0)}_reveal(){this._isVisible||(this._isVisible=!0,this._revealTimer.setIfNotSet(()=>{this._domNode?.setClassName(this._visibleClassName)},0))}_hide(t){this._revealTimer.cancel(),this._isVisible&&(this._isVisible=!1,this._domNode?.setClassName(this._invisibleClassName+(t?" fade":"")))}},m3=140,ym=class extends rc{constructor(t){super(),this._lazyRender=t.lazyRender,this._host=t.host,this._scrollable=t.scrollable,this._scrollByPage=t.scrollByPage,this._scrollbarState=t.scrollbarState,this._visibilityController=this._register(new f3(t.visibility,"visible scrollbar "+t.extraScrollbarClassName,"invisible scrollbar "+t.extraScrollbarClassName)),this._visibilityController.setIsNeeded(this._scrollbarState.isNeeded()),this._pointerMoveMonitor=this._register(new bm),this._shouldRender=!0,this.domNode=wr(document.createElement("div")),this.domNode.setAttribute("role","presentation"),this.domNode.setAttribute("aria-hidden","true"),this._visibilityController.setDomNode(this.domNode),this.domNode.setPosition("absolute"),this._register(ye(this.domNode.domNode,ht.POINTER_DOWN,e=>this._domNodePointerDown(e)))}_createArrow(t){let e=this._register(new a3(t));this.domNode.domNode.appendChild(e.bgDomNode),this.domNode.domNode.appendChild(e.domNode)}_createSlider(t,e,s,i){this.slider=wr(document.createElement("div")),this.slider.setClassName("slider"),this.slider.setPosition("absolute"),this.slider.setTop(t),this.slider.setLeft(e),typeof s=="number"&&this.slider.setWidth(s),typeof i=="number"&&this.slider.setHeight(i),this.slider.setLayerHinting(!0),this.slider.setContain("strict"),this.domNode.domNode.appendChild(this.slider.domNode),this._register(ye(this.slider.domNode,ht.POINTER_DOWN,n=>{n.button===0&&(n.preventDefault(),this._sliderPointerDown(n))})),this.onclick(this.slider.domNode,n=>{n.leftButton&&n.stopPropagation()})}_onElementSize(t){return this._scrollbarState.setVisibleSize(t)&&(this._visibilityController.setIsNeeded(this._scrollbarState.isNeeded()),this._shouldRender=!0,this._lazyRender||this.render()),this._shouldRender}_onElementScrollSize(t){return this._scrollbarState.setScrollSize(t)&&(this._visibilityController.setIsNeeded(this._scrollbarState.isNeeded()),this._shouldRender=!0,this._lazyRender||this.render()),this._shouldRender}_onElementScrollPosition(t){return this._scrollbarState.setScrollPosition(t)&&(this._visibilityController.setIsNeeded(this._scrollbarState.isNeeded()),this._shouldRender=!0,this._lazyRender||this.render()),this._shouldRender}beginReveal(){this._visibilityController.setShouldBeVisible(!0)}beginHide(){this._visibilityController.setShouldBeVisible(!1)}render(){this._shouldRender&&(this._shouldRender=!1,this._renderDomNode(this._scrollbarState.getRectangleLargeSize(),this._scrollbarState.getRectangleSmallSize()),this._updateSlider(this._scrollbarState.getSliderSize(),this._scrollbarState.getArrowSize()+this._scrollbarState.getSliderPosition()))}_domNodePointerDown(t){t.target===this.domNode.domNode&&this._onPointerDown(t)}delegatePointerDown(t){let e=this.domNode.domNode.getClientRects()[0].top,s=e+this._scrollbarState.getSliderPosition(),i=e+this._scrollbarState.getSliderPosition()+this._scrollbarState.getSliderSize(),n=this._sliderPointerPosition(t);s<=n&&n<=i?t.button===0&&(t.preventDefault(),this._sliderPointerDown(t)):this._onPointerDown(t)}_onPointerDown(t){let e,s;if(t.target===this.domNode.domNode&&typeof t.offsetX=="number"&&typeof t.offsetY=="number")e=t.offsetX,s=t.offsetY;else{let n=i3(this.domNode.domNode);e=t.pageX-n.left,s=t.pageY-n.top}let i=this._pointerDownRelativePosition(e,s);this._setDesiredScrollPositionNow(this._scrollByPage?this._scrollbarState.getDesiredScrollPositionFromOffsetPaged(i):this._scrollbarState.getDesiredScrollPositionFromOffset(i)),t.button===0&&(t.preventDefault(),this._sliderPointerDown(t))}_sliderPointerDown(t){if(!t.target||!(t.target instanceof Element))return;let e=this._sliderPointerPosition(t),s=this._sliderOrthogonalPointerPosition(t),i=this._scrollbarState.clone();this.slider.toggleClassName("active",!0),this._pointerMoveMonitor.startMonitoring(t.target,t.pointerId,t.buttons,n=>{let o=this._sliderOrthogonalPointerPosition(n),a=Math.abs(o-s);if(gm&&a>m3){this._setDesiredScrollPositionNow(i.getScrollPosition());return}let l=this._sliderPointerPosition(n)-e;this._setDesiredScrollPositionNow(i.getDesiredScrollPositionFromDelta(l))},()=>{this.slider.toggleClassName("active",!1),this._host.onDragEnd()}),this._host.onDragStart()}_setDesiredScrollPositionNow(t){let e={};this.writeScrollPosition(e,t),this._scrollable.setScrollPositionNow(e)}updateScrollbarSize(t){this._updateScrollbarSize(t),this._scrollbarState.setScrollbarSize(t),this._shouldRender=!0,this._lazyRender||this.render()}isNeeded(){return this._scrollbarState.isNeeded()}},Sm=class Oa{constructor(e,s,i,n,o,a){this._scrollbarSize=Math.round(s),this._oppositeScrollbarSize=Math.round(i),this._arrowSize=Math.round(e),this._visibleSize=n,this._scrollSize=o,this._scrollPosition=a,this._computedAvailableSize=0,this._computedIsNeeded=!1,this._computedSliderSize=0,this._computedSliderRatio=0,this._computedSliderPosition=0,this._refreshComputedValues()}clone(){return new Oa(this._arrowSize,this._scrollbarSize,this._oppositeScrollbarSize,this._visibleSize,this._scrollSize,this._scrollPosition)}setVisibleSize(e){let s=Math.round(e);return this._visibleSize!==s?(this._visibleSize=s,this._refreshComputedValues(),!0):!1}setScrollSize(e){let s=Math.round(e);return this._scrollSize!==s?(this._scrollSize=s,this._refreshComputedValues(),!0):!1}setScrollPosition(e){let s=Math.round(e);return this._scrollPosition!==s?(this._scrollPosition=s,this._refreshComputedValues(),!0):!1}setScrollbarSize(e){this._scrollbarSize=Math.round(e)}setOppositeScrollbarSize(e){this._oppositeScrollbarSize=Math.round(e)}static _computeValues(e,s,i,n,o){let a=Math.max(0,i-e),l=Math.max(0,a-2*s),c=n>0&&n>i;if(!c)return{computedAvailableSize:Math.round(a),computedIsNeeded:c,computedSliderSize:Math.round(l),computedSliderRatio:0,computedSliderPosition:0};let d=Math.round(Math.max(20,Math.floor(i*l/n))),u=(l-d)/(n-i),h=o*u;return{computedAvailableSize:Math.round(a),computedIsNeeded:c,computedSliderSize:Math.round(d),computedSliderRatio:u,computedSliderPosition:Math.round(h)}}_refreshComputedValues(){let e=Oa._computeValues(this._oppositeScrollbarSize,this._arrowSize,this._visibleSize,this._scrollSize,this._scrollPosition);this._computedAvailableSize=e.computedAvailableSize,this._computedIsNeeded=e.computedIsNeeded,this._computedSliderSize=e.computedSliderSize,this._computedSliderRatio=e.computedSliderRatio,this._computedSliderPosition=e.computedSliderPosition}getArrowSize(){return this._arrowSize}getScrollPosition(){return this._scrollPosition}getRectangleLargeSize(){return this._computedAvailableSize}getRectangleSmallSize(){return this._scrollbarSize}isNeeded(){return this._computedIsNeeded}getSliderSize(){return this._computedSliderSize}getSliderPosition(){return this._computedSliderPosition}getDesiredScrollPositionFromOffset(e){if(!this._computedIsNeeded)return 0;let s=e-this._arrowSize-this._computedSliderSize/2;return Math.round(s/this._computedSliderRatio)}getDesiredScrollPositionFromOffsetPaged(e){if(!this._computedIsNeeded)return 0;let s=e-this._arrowSize,i=this._scrollPosition;return s<this._computedSliderPosition?i-=this._visibleSize:i+=this._visibleSize,i}getDesiredScrollPositionFromDelta(e){if(!this._computedIsNeeded)return 0;let s=this._computedSliderPosition+e;return Math.round(s/this._computedSliderRatio)}},p3=class extends ym{constructor(t,e,s){let i=t.getScrollDimensions(),n=t.getCurrentScrollPosition();if(super({lazyRender:e.lazyRender,host:s,scrollbarState:new Sm(e.horizontalHasArrows?e.arrowSize:0,e.horizontal===2?0:e.horizontalScrollbarSize,e.vertical===2?0:e.verticalScrollbarSize,i.width,i.scrollWidth,n.scrollLeft),visibility:e.horizontal,extraScrollbarClassName:"horizontal",scrollable:t,scrollByPage:e.scrollByPage}),e.horizontalHasArrows)throw new Error("horizontalHasArrows is not supported in xterm.js");this._createSlider(Math.floor((e.horizontalScrollbarSize-e.horizontalSliderSize)/2),0,void 0,e.horizontalSliderSize)}_updateSlider(t,e){this.slider.setWidth(t),this.slider.setLeft(e)}_renderDomNode(t,e){this.domNode.setWidth(t),this.domNode.setHeight(e),this.domNode.setLeft(0),this.domNode.setBottom(0)}onDidScroll(t){return this._shouldRender=this._onElementScrollSize(t.scrollWidth)||this._shouldRender,this._shouldRender=this._onElementScrollPosition(t.scrollLeft)||this._shouldRender,this._shouldRender=this._onElementSize(t.width)||this._shouldRender,this._shouldRender}_pointerDownRelativePosition(t,e){return t}_sliderPointerPosition(t){return t.pageX}_sliderOrthogonalPointerPosition(t){return t.pageY}_updateScrollbarSize(t){this.slider.setHeight(t)}writeScrollPosition(t,e){t.scrollLeft=e}updateOptions(t){this.updateScrollbarSize(t.horizontal===2?0:t.horizontalScrollbarSize),this._scrollbarState.setOppositeScrollbarSize(t.vertical===2?0:t.verticalScrollbarSize),this._visibilityController.setVisibility(t.horizontal),this._scrollByPage=t.scrollByPage}},g3=class extends ym{constructor(t,e,s){let i=t.getScrollDimensions(),n=t.getCurrentScrollPosition();if(super({lazyRender:e.lazyRender,host:s,scrollbarState:new Sm(e.verticalHasArrows?e.arrowSize:0,e.vertical===2?0:e.verticalScrollbarSize,0,i.height,i.scrollHeight,n.scrollTop),visibility:e.vertical,extraScrollbarClassName:"vertical",scrollable:t,scrollByPage:e.scrollByPage}),e.verticalHasArrows)throw new Error("horizontalHasArrows is not supported in xterm.js");this._createSlider(0,Math.floor((e.verticalScrollbarSize-e.verticalSliderSize)/2),e.verticalSliderSize,void 0)}_updateSlider(t,e){this.slider.setHeight(t),this.slider.setTop(e)}_renderDomNode(t,e){this.domNode.setWidth(e),this.domNode.setHeight(t),this.domNode.setRight(0),this.domNode.setTop(0)}onDidScroll(t){return this._shouldRender=this._onElementScrollSize(t.scrollHeight)||this._shouldRender,this._shouldRender=this._onElementScrollPosition(t.scrollTop)||this._shouldRender,this._shouldRender=this._onElementSize(t.height)||this._shouldRender,this._shouldRender}_pointerDownRelativePosition(t,e){return e}_sliderPointerPosition(t){return t.pageY}_sliderOrthogonalPointerPosition(t){return t.pageX}_updateScrollbarSize(t){this.slider.setWidth(t)}writeScrollPosition(t,e){t.scrollTop=e}updateOptions(t){this.updateScrollbarSize(t.vertical===2?0:t.verticalScrollbarSize),this._scrollbarState.setOppositeScrollbarSize(0),this._visibilityController.setVisibility(t.vertical),this._scrollByPage=t.scrollByPage}},_3=500,Bd=50,x3=class{constructor(t,e,s){this.timestamp=t,this.deltaX=e,this.deltaY=s,this.score=0}},$a=class{constructor(){this._capacity=5,this._memory=[],this._front=-1,this._rear=-1}isPhysicalMouseWheel(){if(this._front===-1&&this._rear===-1)return!1;let e=1,s=0,i=1,n=this._rear;do{let o=n===this._front?e:Math.pow(2,-i);if(e-=o,s+=this._memory[n].score*o,n===this._front)break;n=(this._capacity+n-1)%this._capacity,i++}while(!0);return s<=.5}acceptStandardWheelEvent(e){if(ec){let s=ws(e.browserEvent),i=AC(s);this.accept(Date.now(),e.deltaX*i,e.deltaY*i)}else this.accept(Date.now(),e.deltaX,e.deltaY)}accept(e,s,i){let n=null,o=new x3(e,s,i);this._front===-1&&this._rear===-1?(this._memory[0]=o,this._front=0,this._rear=0):(n=this._memory[this._rear],this._rear=(this._rear+1)%this._capacity,this._rear===this._front&&(this._front=(this._front+1)%this._capacity),this._memory[this._rear]=o),o.score=this._computeScore(o,n)}_computeScore(e,s){if(Math.abs(e.deltaX)>0&&Math.abs(e.deltaY)>0)return 1;let i=.5;if((!this._isAlmostInt(e.deltaX)||!this._isAlmostInt(e.deltaY))&&(i+=.25),s){let n=Math.abs(e.deltaX),o=Math.abs(e.deltaY),a=Math.abs(s.deltaX),l=Math.abs(s.deltaY),c=Math.max(Math.min(n,a),1),d=Math.max(Math.min(o,l),1),u=Math.max(n,a),h=Math.max(o,l);u%c===0&&h%d===0&&(i-=.5)}return Math.min(Math.max(i,0),1)}_isAlmostInt(e){return Math.abs(Math.round(e)-e)<.01}};$a.INSTANCE=new $a;var v3=$a,b3=class extends rc{constructor(t,e,s){super(),this._onScroll=this._register(new re),this.onScroll=this._onScroll.event,this._onWillScroll=this._register(new re),this.onWillScroll=this._onWillScroll.event,this._options=S3(e),this._scrollable=s,this._register(this._scrollable.onScroll(n=>{this._onWillScroll.fire(n),this._onDidScroll(n),this._onScroll.fire(n)}));let i={onMouseWheel:n=>this._onMouseWheel(n),onDragStart:()=>this._onDragStart(),onDragEnd:()=>this._onDragEnd()};this._verticalScrollbar=this._register(new g3(this._scrollable,this._options,i)),this._horizontalScrollbar=this._register(new p3(this._scrollable,this._options,i)),this._domNode=document.createElement("div"),this._domNode.className="xterm-scrollable-element "+this._options.className,this._domNode.setAttribute("role","presentation"),this._domNode.style.position="relative",this._domNode.appendChild(t),this._domNode.appendChild(this._horizontalScrollbar.domNode.domNode),this._domNode.appendChild(this._verticalScrollbar.domNode.domNode),this._options.useShadows?(this._leftShadowDomNode=wr(document.createElement("div")),this._leftShadowDomNode.setClassName("shadow"),this._domNode.appendChild(this._leftShadowDomNode.domNode),this._topShadowDomNode=wr(document.createElement("div")),this._topShadowDomNode.setClassName("shadow"),this._domNode.appendChild(this._topShadowDomNode.domNode),this._topLeftShadowDomNode=wr(document.createElement("div")),this._topLeftShadowDomNode.setClassName("shadow"),this._domNode.appendChild(this._topLeftShadowDomNode.domNode)):(this._leftShadowDomNode=null,this._topShadowDomNode=null,this._topLeftShadowDomNode=null),this._listenOnDomNode=this._options.listenOnDomNode||this._domNode,this._mouseWheelToDispose=[],this._setListeningToMouseWheel(this._options.handleMouseWheel),this.onmouseover(this._listenOnDomNode,n=>this._onMouseOver(n)),this.onmouseleave(this._listenOnDomNode,n=>this._onMouseLeave(n)),this._hideTimeout=this._register(new sc),this._isDragging=!1,this._mouseIsOver=!1,this._shouldRender=!0,this._revealOnScroll=!0}get options(){return this._options}dispose(){this._mouseWheelToDispose=_i(this._mouseWheelToDispose),super.dispose()}getDomNode(){return this._domNode}getOverviewRulerLayoutInfo(){return{parent:this._domNode,insertBefore:this._verticalScrollbar.domNode.domNode}}delegateVerticalScrollbarPointerDown(t){this._verticalScrollbar.delegatePointerDown(t)}getScrollDimensions(){return this._scrollable.getScrollDimensions()}setScrollDimensions(t){this._scrollable.setScrollDimensions(t,!1)}updateClassName(t){this._options.className=t,As&&(this._options.className+=" mac"),this._domNode.className="xterm-scrollable-element "+this._options.className}updateOptions(t){typeof t.handleMouseWheel<"u"&&(this._options.handleMouseWheel=t.handleMouseWheel,this._setListeningToMouseWheel(this._options.handleMouseWheel)),typeof t.mouseWheelScrollSensitivity<"u"&&(this._options.mouseWheelScrollSensitivity=t.mouseWheelScrollSensitivity),typeof t.fastScrollSensitivity<"u"&&(this._options.fastScrollSensitivity=t.fastScrollSensitivity),typeof t.scrollPredominantAxis<"u"&&(this._options.scrollPredominantAxis=t.scrollPredominantAxis),typeof t.horizontal<"u"&&(this._options.horizontal=t.horizontal),typeof t.vertical<"u"&&(this._options.vertical=t.vertical),typeof t.horizontalScrollbarSize<"u"&&(this._options.horizontalScrollbarSize=t.horizontalScrollbarSize),typeof t.verticalScrollbarSize<"u"&&(this._options.verticalScrollbarSize=t.verticalScrollbarSize),typeof t.scrollByPage<"u"&&(this._options.scrollByPage=t.scrollByPage),this._horizontalScrollbar.updateOptions(this._options),this._verticalScrollbar.updateOptions(this._options),this._options.lazyRender||this._render()}setRevealOnScroll(t){this._revealOnScroll=t}delegateScrollFromMouseWheelEvent(t){this._onMouseWheel(new Id(t))}_setListeningToMouseWheel(t){if(this._mouseWheelToDispose.length>0!==t&&(this._mouseWheelToDispose=_i(this._mouseWheelToDispose),t)){let e=s=>{this._onMouseWheel(new Id(s))};this._mouseWheelToDispose.push(ye(this._listenOnDomNode,ht.MOUSE_WHEEL,e,{passive:!1}))}}_onMouseWheel(t){if(t.browserEvent?.defaultPrevented)return;let e=v3.INSTANCE;e.acceptStandardWheelEvent(t);let s=!1;if(t.deltaY||t.deltaX){let n=t.deltaY*this._options.mouseWheelScrollSensitivity,o=t.deltaX*this._options.mouseWheelScrollSensitivity;this._options.scrollPredominantAxis&&(this._options.scrollYToX&&o+n===0?o=n=0:Math.abs(n)>=Math.abs(o)?o=0:n=0),this._options.flipAxes&&([n,o]=[o,n]);let a=!As&&t.browserEvent&&t.browserEvent.shiftKey;(this._options.scrollYToX||a)&&!o&&(o=n,n=0),t.browserEvent&&t.browserEvent.altKey&&(o=o*this._options.fastScrollSensitivity,n=n*this._options.fastScrollSensitivity);let l=this._scrollable.getFutureScrollPosition(),c={};if(n){let d=Bd*n,u=l.scrollTop-(d<0?Math.floor(d):Math.ceil(d));this._verticalScrollbar.writeScrollPosition(c,u)}if(o){let d=Bd*o,u=l.scrollLeft-(d<0?Math.floor(d):Math.ceil(d));this._horizontalScrollbar.writeScrollPosition(c,u)}c=this._scrollable.validateScrollPosition(c),(l.scrollLeft!==c.scrollLeft||l.scrollTop!==c.scrollTop)&&(this._options.mouseWheelSmoothScroll&&e.isPhysicalMouseWheel()?this._scrollable.setScrollPositionSmooth(c):this._scrollable.setScrollPositionNow(c),s=!0)}let i=s;!i&&this._options.alwaysConsumeMouseWheel&&(i=!0),!i&&this._options.consumeMouseWheelIfScrollbarIsNeeded&&(this._verticalScrollbar.isNeeded()||this._horizontalScrollbar.isNeeded())&&(i=!0),i&&(t.preventDefault(),t.stopPropagation())}_onDidScroll(t){this._shouldRender=this._horizontalScrollbar.onDidScroll(t)||this._shouldRender,this._shouldRender=this._verticalScrollbar.onDidScroll(t)||this._shouldRender,this._options.useShadows&&(this._shouldRender=!0),this._revealOnScroll&&this._reveal(),this._options.lazyRender||this._render()}renderNow(){if(!this._options.lazyRender)throw new Error("Please use `lazyRender` together with `renderNow`!");this._render()}_render(){if(this._shouldRender&&(this._shouldRender=!1,this._horizontalScrollbar.render(),this._verticalScrollbar.render(),this._options.useShadows)){let t=this._scrollable.getCurrentScrollPosition(),e=t.scrollTop>0,s=t.scrollLeft>0,i=s?" left":"",n=e?" top":"",o=s||e?" top-left-corner":"";this._leftShadowDomNode.setClassName(`shadow${i}`),this._topShadowDomNode.setClassName(`shadow${n}`),this._topLeftShadowDomNode.setClassName(`shadow${o}${n}${i}`)}}_onDragStart(){this._isDragging=!0,this._reveal()}_onDragEnd(){this._isDragging=!1,this._hide()}_onMouseLeave(t){this._mouseIsOver=!1,this._hide()}_onMouseOver(t){this._mouseIsOver=!0,this._reveal()}_reveal(){this._verticalScrollbar.beginReveal(),this._horizontalScrollbar.beginReveal(),this._scheduleHide()}_hide(){!this._mouseIsOver&&!this._isDragging&&(this._verticalScrollbar.beginHide(),this._horizontalScrollbar.beginHide())}_scheduleHide(){!this._mouseIsOver&&!this._isDragging&&this._hideTimeout.cancelAndSet(()=>this._hide(),_3)}},y3=class extends b3{constructor(t,e,s){super(t,e,s)}setScrollPosition(t){t.reuseAnimation?this._scrollable.setScrollPositionSmooth(t,t.reuseAnimation):this._scrollable.setScrollPositionNow(t)}getScrollPosition(){return this._scrollable.getCurrentScrollPosition()}};function S3(t){let e={lazyRender:typeof t.lazyRender<"u"?t.lazyRender:!1,className:typeof t.className<"u"?t.className:"",useShadows:typeof t.useShadows<"u"?t.useShadows:!0,handleMouseWheel:typeof t.handleMouseWheel<"u"?t.handleMouseWheel:!0,flipAxes:typeof t.flipAxes<"u"?t.flipAxes:!1,consumeMouseWheelIfScrollbarIsNeeded:typeof t.consumeMouseWheelIfScrollbarIsNeeded<"u"?t.consumeMouseWheelIfScrollbarIsNeeded:!1,alwaysConsumeMouseWheel:typeof t.alwaysConsumeMouseWheel<"u"?t.alwaysConsumeMouseWheel:!1,scrollYToX:typeof t.scrollYToX<"u"?t.scrollYToX:!1,mouseWheelScrollSensitivity:typeof t.mouseWheelScrollSensitivity<"u"?t.mouseWheelScrollSensitivity:1,fastScrollSensitivity:typeof t.fastScrollSensitivity<"u"?t.fastScrollSensitivity:5,scrollPredominantAxis:typeof t.scrollPredominantAxis<"u"?t.scrollPredominantAxis:!0,mouseWheelSmoothScroll:typeof t.mouseWheelSmoothScroll<"u"?t.mouseWheelSmoothScroll:!0,arrowSize:typeof t.arrowSize<"u"?t.arrowSize:11,listenOnDomNode:typeof t.listenOnDomNode<"u"?t.listenOnDomNode:null,horizontal:typeof t.horizontal<"u"?t.horizontal:1,horizontalScrollbarSize:typeof t.horizontalScrollbarSize<"u"?t.horizontalScrollbarSize:10,horizontalSliderSize:typeof t.horizontalSliderSize<"u"?t.horizontalSliderSize:0,horizontalHasArrows:typeof t.horizontalHasArrows<"u"?t.horizontalHasArrows:!1,vertical:typeof t.vertical<"u"?t.vertical:1,verticalScrollbarSize:typeof t.verticalScrollbarSize<"u"?t.verticalScrollbarSize:10,verticalHasArrows:typeof t.verticalHasArrows<"u"?t.verticalHasArrows:!1,verticalSliderSize:typeof t.verticalSliderSize<"u"?t.verticalSliderSize:0,scrollByPage:typeof t.scrollByPage<"u"?t.scrollByPage:!1};return e.horizontalSliderSize=typeof t.horizontalSliderSize<"u"?t.horizontalSliderSize:e.horizontalScrollbarSize,e.verticalSliderSize=typeof t.verticalSliderSize<"u"?t.verticalSliderSize:e.verticalScrollbarSize,As&&(e.className+=" mac"),e}var za=class extends Ve{constructor(t,e,s,i,n,o,a,l){super(),this._bufferService=s,this._optionsService=a,this._renderService=l,this._onRequestScrollLines=this._register(new re),this.onRequestScrollLines=this._onRequestScrollLines.event,this._isSyncing=!1,this._isHandlingScroll=!1,this._suppressOnScrollHandler=!1;let c=this._register(new c3({forceIntegerValues:!1,smoothScrollDuration:this._optionsService.rawOptions.smoothScrollDuration,scheduleAtNextAnimationFrame:d=>ic(i.window,d)}));this._register(this._optionsService.onSpecificOptionChange("smoothScrollDuration",()=>{c.setSmoothScrollDuration(this._optionsService.rawOptions.smoothScrollDuration)})),this._scrollableElement=this._register(new y3(e,{vertical:1,horizontal:2,useShadows:!1,mouseWheelSmoothScroll:!0,...this._getChangeOptions()},c)),this._register(this._optionsService.onMultipleOptionChange(["scrollSensitivity","fastScrollSensitivity","overviewRuler"],()=>this._scrollableElement.updateOptions(this._getChangeOptions()))),this._register(n.onProtocolChange(d=>{this._scrollableElement.updateOptions({handleMouseWheel:!(d&16)})})),this._scrollableElement.setScrollDimensions({height:0,scrollHeight:0}),this._register(yt.runAndSubscribe(o.onChangeColors,()=>{this._scrollableElement.getDomNode().style.backgroundColor=o.colors.background.css})),t.appendChild(this._scrollableElement.getDomNode()),this._register(Fe(()=>this._scrollableElement.getDomNode().remove())),this._styleElement=i.mainDocument.createElement("style"),e.appendChild(this._styleElement),this._register(Fe(()=>this._styleElement.remove())),this._register(yt.runAndSubscribe(o.onChangeColors,()=>{this._styleElement.textContent=[".xterm .xterm-scrollable-element > .scrollbar > .slider {",` background: ${o.colors.scrollbarSliderBackground.css};`,"}",".xterm .xterm-scrollable-element > .scrollbar > .slider:hover {",` background: ${o.colors.scrollbarSliderHoverBackground.css};`,"}",".xterm .xterm-scrollable-element > .scrollbar > .slider.active {",` background: ${o.colors.scrollbarSliderActiveBackground.css};`,"}"].join(`
437
+ `)})),this._register(this._bufferService.onResize(()=>this.queueSync())),this._register(this._bufferService.buffers.onBufferActivate(()=>{this._latestYDisp=void 0,this.queueSync()})),this._register(this._bufferService.onScroll(()=>this._sync())),this._register(this._scrollableElement.onScroll(d=>this._handleScroll(d)))}scrollLines(t){let e=this._scrollableElement.getScrollPosition();this._scrollableElement.setScrollPosition({reuseAnimation:!0,scrollTop:e.scrollTop+t*this._renderService.dimensions.css.cell.height})}scrollToLine(t,e){e&&(this._latestYDisp=t),this._scrollableElement.setScrollPosition({reuseAnimation:!e,scrollTop:t*this._renderService.dimensions.css.cell.height})}_getChangeOptions(){return{mouseWheelScrollSensitivity:this._optionsService.rawOptions.scrollSensitivity,fastScrollSensitivity:this._optionsService.rawOptions.fastScrollSensitivity,verticalScrollbarSize:this._optionsService.rawOptions.overviewRuler?.width||14}}queueSync(t){t!==void 0&&(this._latestYDisp=t),this._queuedAnimationFrame===void 0&&(this._queuedAnimationFrame=this._renderService.addRefreshCallback(()=>{this._queuedAnimationFrame=void 0,this._sync(this._latestYDisp)}))}_sync(t=this._bufferService.buffer.ydisp){!this._renderService||this._isSyncing||(this._isSyncing=!0,this._suppressOnScrollHandler=!0,this._scrollableElement.setScrollDimensions({height:this._renderService.dimensions.css.canvas.height,scrollHeight:this._renderService.dimensions.css.cell.height*this._bufferService.buffer.lines.length}),this._suppressOnScrollHandler=!1,t!==this._latestYDisp&&this._scrollableElement.setScrollPosition({scrollTop:t*this._renderService.dimensions.css.cell.height}),this._isSyncing=!1)}_handleScroll(t){if(!this._renderService||this._isHandlingScroll||this._suppressOnScrollHandler)return;this._isHandlingScroll=!0;let e=Math.round(t.scrollTop/this._renderService.dimensions.css.cell.height),s=e-this._bufferService.buffer.ydisp;s!==0&&(this._latestYDisp=e,this._onRequestScrollLines.fire(s)),this._isHandlingScroll=!1}};za=Ye([ce(2,Lt),ce(3,Hs),ce(4,sm),ce(5,Xi),ce(6,Bt),ce(7,Ws)],za);var Fa=class extends Ve{constructor(t,e,s,i,n){super(),this._screenElement=t,this._bufferService=e,this._coreBrowserService=s,this._decorationService=i,this._renderService=n,this._decorationElements=new Map,this._altBufferIsActive=!1,this._dimensionsChanged=!1,this._container=document.createElement("div"),this._container.classList.add("xterm-decoration-container"),this._screenElement.appendChild(this._container),this._register(this._renderService.onRenderedViewportChange(()=>this._doRefreshDecorations())),this._register(this._renderService.onDimensionsChange(()=>{this._dimensionsChanged=!0,this._queueRefresh()})),this._register(this._coreBrowserService.onDprChange(()=>this._queueRefresh())),this._register(this._bufferService.buffers.onBufferActivate(()=>{this._altBufferIsActive=this._bufferService.buffer===this._bufferService.buffers.alt})),this._register(this._decorationService.onDecorationRegistered(()=>this._queueRefresh())),this._register(this._decorationService.onDecorationRemoved(o=>this._removeDecoration(o))),this._register(Fe(()=>{this._container.remove(),this._decorationElements.clear()}))}_queueRefresh(){this._animationFrame===void 0&&(this._animationFrame=this._renderService.addRefreshCallback(()=>{this._doRefreshDecorations(),this._animationFrame=void 0}))}_doRefreshDecorations(){for(let t of this._decorationService.decorations)this._renderDecoration(t);this._dimensionsChanged=!1}_renderDecoration(t){this._refreshStyle(t),this._dimensionsChanged&&this._refreshXPosition(t)}_createElement(t){let e=this._coreBrowserService.mainDocument.createElement("div");e.classList.add("xterm-decoration"),e.classList.toggle("xterm-decoration-top-layer",t?.options?.layer==="top"),e.style.width=`${Math.round((t.options.width||1)*this._renderService.dimensions.css.cell.width)}px`,e.style.height=`${(t.options.height||1)*this._renderService.dimensions.css.cell.height}px`,e.style.top=`${(t.marker.line-this._bufferService.buffers.active.ydisp)*this._renderService.dimensions.css.cell.height}px`,e.style.lineHeight=`${this._renderService.dimensions.css.cell.height}px`;let s=t.options.x??0;return s&&s>this._bufferService.cols&&(e.style.display="none"),this._refreshXPosition(t,e),e}_refreshStyle(t){let e=t.marker.line-this._bufferService.buffers.active.ydisp;if(e<0||e>=this._bufferService.rows)t.element&&(t.element.style.display="none",t.onRenderEmitter.fire(t.element));else{let s=this._decorationElements.get(t);s||(s=this._createElement(t),t.element=s,this._decorationElements.set(t,s),this._container.appendChild(s),t.onDispose(()=>{this._decorationElements.delete(t),s.remove()})),s.style.display=this._altBufferIsActive?"none":"block",this._altBufferIsActive||(s.style.width=`${Math.round((t.options.width||1)*this._renderService.dimensions.css.cell.width)}px`,s.style.height=`${(t.options.height||1)*this._renderService.dimensions.css.cell.height}px`,s.style.top=`${e*this._renderService.dimensions.css.cell.height}px`,s.style.lineHeight=`${this._renderService.dimensions.css.cell.height}px`),t.onRenderEmitter.fire(s)}}_refreshXPosition(t,e=t.element){if(!e)return;let s=t.options.x??0;(t.options.anchor||"left")==="right"?e.style.right=s?`${s*this._renderService.dimensions.css.cell.width}px`:"":e.style.left=s?`${s*this._renderService.dimensions.css.cell.width}px`:""}_removeDecoration(t){this._decorationElements.get(t)?.remove(),this._decorationElements.delete(t),t.dispose()}};Fa=Ye([ce(1,Lt),ce(2,Hs),ce(3,tn),ce(4,Ws)],Fa);var w3=class{constructor(){this._zones=[],this._zonePool=[],this._zonePoolIndex=0,this._linePadding={full:0,left:0,center:0,right:0}}get zones(){return this._zonePool.length=Math.min(this._zonePool.length,this._zones.length),this._zones}clear(){this._zones.length=0,this._zonePoolIndex=0}addDecoration(t){if(t.options.overviewRulerOptions){for(let e of this._zones)if(e.color===t.options.overviewRulerOptions.color&&e.position===t.options.overviewRulerOptions.position){if(this._lineIntersectsZone(e,t.marker.line))return;if(this._lineAdjacentToZone(e,t.marker.line,t.options.overviewRulerOptions.position)){this._addLineToZone(e,t.marker.line);return}}if(this._zonePoolIndex<this._zonePool.length){this._zonePool[this._zonePoolIndex].color=t.options.overviewRulerOptions.color,this._zonePool[this._zonePoolIndex].position=t.options.overviewRulerOptions.position,this._zonePool[this._zonePoolIndex].startBufferLine=t.marker.line,this._zonePool[this._zonePoolIndex].endBufferLine=t.marker.line,this._zones.push(this._zonePool[this._zonePoolIndex++]);return}this._zones.push({color:t.options.overviewRulerOptions.color,position:t.options.overviewRulerOptions.position,startBufferLine:t.marker.line,endBufferLine:t.marker.line}),this._zonePool.push(this._zones[this._zones.length-1]),this._zonePoolIndex++}}setPadding(t){this._linePadding=t}_lineIntersectsZone(t,e){return e>=t.startBufferLine&&e<=t.endBufferLine}_lineAdjacentToZone(t,e,s){return e>=t.startBufferLine-this._linePadding[s||"full"]&&e<=t.endBufferLine+this._linePadding[s||"full"]}_addLineToZone(t,e){t.startBufferLine=Math.min(t.startBufferLine,e),t.endBufferLine=Math.max(t.endBufferLine,e)}},xs={full:0,left:0,center:0,right:0},Ks={full:0,left:0,center:0,right:0},ir={full:0,left:0,center:0,right:0},Gn=class extends Ve{constructor(t,e,s,i,n,o,a,l){super(),this._viewportElement=t,this._screenElement=e,this._bufferService=s,this._decorationService=i,this._renderService=n,this._optionsService=o,this._themeService=a,this._coreBrowserService=l,this._colorZoneStore=new w3,this._shouldUpdateDimensions=!0,this._shouldUpdateAnchor=!0,this._lastKnownBufferLength=0,this._canvas=this._coreBrowserService.mainDocument.createElement("canvas"),this._canvas.classList.add("xterm-decoration-overview-ruler"),this._refreshCanvasDimensions(),this._viewportElement.parentElement?.insertBefore(this._canvas,this._viewportElement),this._register(Fe(()=>this._canvas?.remove()));let c=this._canvas.getContext("2d");if(c)this._ctx=c;else throw new Error("Ctx cannot be null");this._register(this._decorationService.onDecorationRegistered(()=>this._queueRefresh(void 0,!0))),this._register(this._decorationService.onDecorationRemoved(()=>this._queueRefresh(void 0,!0))),this._register(this._renderService.onRenderedViewportChange(()=>this._queueRefresh())),this._register(this._bufferService.buffers.onBufferActivate(()=>{this._canvas.style.display=this._bufferService.buffer===this._bufferService.buffers.alt?"none":"block"})),this._register(this._bufferService.onScroll(()=>{this._lastKnownBufferLength!==this._bufferService.buffers.normal.lines.length&&(this._refreshDrawHeightConstants(),this._refreshColorZonePadding())})),this._register(this._renderService.onRender(()=>{(!this._containerHeight||this._containerHeight!==this._screenElement.clientHeight)&&(this._queueRefresh(!0),this._containerHeight=this._screenElement.clientHeight)})),this._register(this._coreBrowserService.onDprChange(()=>this._queueRefresh(!0))),this._register(this._optionsService.onSpecificOptionChange("overviewRuler",()=>this._queueRefresh(!0))),this._register(this._themeService.onChangeColors(()=>this._queueRefresh())),this._queueRefresh(!0)}get _width(){return this._optionsService.options.overviewRuler?.width||0}_refreshDrawConstants(){let t=Math.floor((this._canvas.width-1)/3),e=Math.ceil((this._canvas.width-1)/3);Ks.full=this._canvas.width,Ks.left=t,Ks.center=e,Ks.right=t,this._refreshDrawHeightConstants(),ir.full=1,ir.left=1,ir.center=1+Ks.left,ir.right=1+Ks.left+Ks.center}_refreshDrawHeightConstants(){xs.full=Math.round(2*this._coreBrowserService.dpr);let t=this._canvas.height/this._bufferService.buffer.lines.length,e=Math.round(Math.max(Math.min(t,12),6)*this._coreBrowserService.dpr);xs.left=e,xs.center=e,xs.right=e}_refreshColorZonePadding(){this._colorZoneStore.setPadding({full:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*xs.full),left:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*xs.left),center:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*xs.center),right:Math.floor(this._bufferService.buffers.active.lines.length/(this._canvas.height-1)*xs.right)}),this._lastKnownBufferLength=this._bufferService.buffers.normal.lines.length}_refreshCanvasDimensions(){this._canvas.style.width=`${this._width}px`,this._canvas.width=Math.round(this._width*this._coreBrowserService.dpr),this._canvas.style.height=`${this._screenElement.clientHeight}px`,this._canvas.height=Math.round(this._screenElement.clientHeight*this._coreBrowserService.dpr),this._refreshDrawConstants(),this._refreshColorZonePadding()}_refreshDecorations(){this._shouldUpdateDimensions&&this._refreshCanvasDimensions(),this._ctx.clearRect(0,0,this._canvas.width,this._canvas.height),this._colorZoneStore.clear();for(let e of this._decorationService.decorations)this._colorZoneStore.addDecoration(e);this._ctx.lineWidth=1,this._renderRulerOutline();let t=this._colorZoneStore.zones;for(let e of t)e.position!=="full"&&this._renderColorZone(e);for(let e of t)e.position==="full"&&this._renderColorZone(e);this._shouldUpdateDimensions=!1,this._shouldUpdateAnchor=!1}_renderRulerOutline(){this._ctx.fillStyle=this._themeService.colors.overviewRulerBorder.css,this._ctx.fillRect(0,0,1,this._canvas.height),this._optionsService.rawOptions.overviewRuler.showTopBorder&&this._ctx.fillRect(1,0,this._canvas.width-1,1),this._optionsService.rawOptions.overviewRuler.showBottomBorder&&this._ctx.fillRect(1,this._canvas.height-1,this._canvas.width-1,this._canvas.height)}_renderColorZone(t){this._ctx.fillStyle=t.color,this._ctx.fillRect(ir[t.position||"full"],Math.round((this._canvas.height-1)*(t.startBufferLine/this._bufferService.buffers.active.lines.length)-xs[t.position||"full"]/2),Ks[t.position||"full"],Math.round((this._canvas.height-1)*((t.endBufferLine-t.startBufferLine)/this._bufferService.buffers.active.lines.length)+xs[t.position||"full"]))}_queueRefresh(t,e){this._shouldUpdateDimensions=t||this._shouldUpdateDimensions,this._shouldUpdateAnchor=e||this._shouldUpdateAnchor,this._animationFrame===void 0&&(this._animationFrame=this._coreBrowserService.window.requestAnimationFrame(()=>{this._refreshDecorations(),this._animationFrame=void 0}))}};Gn=Ye([ce(2,Lt),ce(3,tn),ce(4,Ws),ce(5,Bt),ce(6,Xi),ce(7,Hs)],Gn);var Z;(t=>(t.NUL="\0",t.SOH="",t.STX="",t.ETX="",t.EOT="",t.ENQ="",t.ACK="",t.BEL="\x07",t.BS="\b",t.HT=" ",t.LF=`
438
+ `,t.VT="\v",t.FF="\f",t.CR="\r",t.SO="",t.SI="",t.DLE="",t.DC1="",t.DC2="",t.DC3="",t.DC4="",t.NAK="",t.SYN="",t.ETB="",t.CAN="",t.EM="",t.SUB="",t.ESC="\x1B",t.FS="",t.GS="",t.RS="",t.US="",t.SP=" ",t.DEL=""))(Z||={});var Rn;(t=>(t.PAD="€",t.HOP="",t.BPH="‚",t.NBH="ƒ",t.IND="„",t.NEL="…",t.SSA="†",t.ESA="‡",t.HTS="ˆ",t.HTJ="‰",t.VTS="Š",t.PLD="‹",t.PLU="Œ",t.RI="",t.SS2="Ž",t.SS3="",t.DCS="",t.PU1="‘",t.PU2="’",t.STS="“",t.CCH="”",t.MW="•",t.SPA="–",t.EPA="—",t.SOS="˜",t.SGCI="™",t.SCI="š",t.CSI="›",t.ST="œ",t.OSC="",t.PM="ž",t.APC="Ÿ"))(Rn||={});var wm;(t=>t.ST=`${Z.ESC}\\`)(wm||={});var Ha=class{constructor(t,e,s,i,n,o){this._textarea=t,this._compositionView=e,this._bufferService=s,this._optionsService=i,this._coreService=n,this._renderService=o,this._isComposing=!1,this._isSendingComposition=!1,this._compositionPosition={start:0,end:0},this._dataAlreadySent=""}get isComposing(){return this._isComposing}compositionstart(){this._isComposing=!0,this._compositionPosition.start=this._textarea.value.length,this._compositionView.textContent="",this._dataAlreadySent="",this._compositionView.classList.add("active")}compositionupdate(t){this._compositionView.textContent=t.data,this.updateCompositionElements(),setTimeout(()=>{this._compositionPosition.end=this._textarea.value.length},0)}compositionend(){this._finalizeComposition(!0)}keydown(t){if(this._isComposing||this._isSendingComposition){if(t.keyCode===20||t.keyCode===229||t.keyCode===16||t.keyCode===17||t.keyCode===18)return!1;this._finalizeComposition(!1)}return t.keyCode===229?(this._handleAnyTextareaChanges(),!1):!0}_finalizeComposition(t){if(this._compositionView.classList.remove("active"),this._isComposing=!1,t){let e={start:this._compositionPosition.start,end:this._compositionPosition.end};this._isSendingComposition=!0,setTimeout(()=>{if(this._isSendingComposition){this._isSendingComposition=!1;let s;e.start+=this._dataAlreadySent.length,this._isComposing?s=this._textarea.value.substring(e.start,this._compositionPosition.start):s=this._textarea.value.substring(e.start),s.length>0&&this._coreService.triggerDataEvent(s,!0)}},0)}else{this._isSendingComposition=!1;let e=this._textarea.value.substring(this._compositionPosition.start,this._compositionPosition.end);this._coreService.triggerDataEvent(e,!0)}}_handleAnyTextareaChanges(){let t=this._textarea.value;setTimeout(()=>{if(!this._isComposing){let e=this._textarea.value,s=e.replace(t,"");this._dataAlreadySent=s,e.length>t.length?this._coreService.triggerDataEvent(s,!0):e.length<t.length?this._coreService.triggerDataEvent(`${Z.DEL}`,!0):e.length===t.length&&e!==t&&this._coreService.triggerDataEvent(e,!0)}},0)}updateCompositionElements(t){if(this._isComposing){if(this._bufferService.buffer.isCursorInViewport){let e=Math.min(this._bufferService.buffer.x,this._bufferService.cols-1),s=this._renderService.dimensions.css.cell.height,i=this._bufferService.buffer.y*this._renderService.dimensions.css.cell.height,n=e*this._renderService.dimensions.css.cell.width;this._compositionView.style.left=n+"px",this._compositionView.style.top=i+"px",this._compositionView.style.height=s+"px",this._compositionView.style.lineHeight=s+"px",this._compositionView.style.fontFamily=this._optionsService.rawOptions.fontFamily,this._compositionView.style.fontSize=this._optionsService.rawOptions.fontSize+"px";let o=this._compositionView.getBoundingClientRect();this._textarea.style.left=n+"px",this._textarea.style.top=i+"px",this._textarea.style.width=Math.max(o.width,1)+"px",this._textarea.style.height=Math.max(o.height,1)+"px",this._textarea.style.lineHeight=o.height+"px"}t||setTimeout(()=>this.updateCompositionElements(!0),0)}}};Ha=Ye([ce(2,Lt),ce(3,Bt),ce(4,Ci),ce(5,Ws)],Ha);var ft=0,mt=0,pt=0,Ge=0,Od={css:"#00000000",rgba:0},et;(t=>{function e(n,o,a,l){return l!==void 0?`#${di(n)}${di(o)}${di(a)}${di(l)}`:`#${di(n)}${di(o)}${di(a)}`}t.toCss=e;function s(n,o,a,l=255){return(n<<24|o<<16|a<<8|l)>>>0}t.toRgba=s;function i(n,o,a,l){return{css:t.toCss(n,o,a,l),rgba:t.toRgba(n,o,a,l)}}t.toColor=i})(et||={});var Le;(t=>{function e(c,d){if(Ge=(d.rgba&255)/255,Ge===1)return{css:d.css,rgba:d.rgba};let u=d.rgba>>24&255,h=d.rgba>>16&255,f=d.rgba>>8&255,m=c.rgba>>24&255,p=c.rgba>>16&255,g=c.rgba>>8&255;ft=m+Math.round((u-m)*Ge),mt=p+Math.round((h-p)*Ge),pt=g+Math.round((f-g)*Ge);let _=et.toCss(ft,mt,pt),v=et.toRgba(ft,mt,pt);return{css:_,rgba:v}}t.blend=e;function s(c){return(c.rgba&255)===255}t.isOpaque=s;function i(c,d,u){let h=Tn.ensureContrastRatio(c.rgba,d.rgba,u);if(h)return et.toColor(h>>24&255,h>>16&255,h>>8&255)}t.ensureContrastRatio=i;function n(c){let d=(c.rgba|255)>>>0;return[ft,mt,pt]=Tn.toChannels(d),{css:et.toCss(ft,mt,pt),rgba:d}}t.opaque=n;function o(c,d){return Ge=Math.round(d*255),[ft,mt,pt]=Tn.toChannels(c.rgba),{css:et.toCss(ft,mt,pt,Ge),rgba:et.toRgba(ft,mt,pt,Ge)}}t.opacity=o;function a(c,d){return Ge=c.rgba&255,o(c,Ge*d/255)}t.multiplyOpacity=a;function l(c){return[c.rgba>>24&255,c.rgba>>16&255,c.rgba>>8&255]}t.toColorRGB=l})(Le||={});var Ue;(t=>{let e,s;try{let n=document.createElement("canvas");n.width=1,n.height=1;let o=n.getContext("2d",{willReadFrequently:!0});o&&(e=o,e.globalCompositeOperation="copy",s=e.createLinearGradient(0,0,1,1))}catch{}function i(n){if(n.match(/#[\da-f]{3,8}/i))switch(n.length){case 4:return ft=parseInt(n.slice(1,2).repeat(2),16),mt=parseInt(n.slice(2,3).repeat(2),16),pt=parseInt(n.slice(3,4).repeat(2),16),et.toColor(ft,mt,pt);case 5:return ft=parseInt(n.slice(1,2).repeat(2),16),mt=parseInt(n.slice(2,3).repeat(2),16),pt=parseInt(n.slice(3,4).repeat(2),16),Ge=parseInt(n.slice(4,5).repeat(2),16),et.toColor(ft,mt,pt,Ge);case 7:return{css:n,rgba:(parseInt(n.slice(1),16)<<8|255)>>>0};case 9:return{css:n,rgba:parseInt(n.slice(1),16)>>>0}}let o=n.match(/rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(,\s*(0|1|\d?\.(\d+))\s*)?\)/);if(o)return ft=parseInt(o[1]),mt=parseInt(o[2]),pt=parseInt(o[3]),Ge=Math.round((o[5]===void 0?1:parseFloat(o[5]))*255),et.toColor(ft,mt,pt,Ge);if(!e||!s)throw new Error("css.toColor: Unsupported css format");if(e.fillStyle=s,e.fillStyle=n,typeof e.fillStyle!="string")throw new Error("css.toColor: Unsupported css format");if(e.fillRect(0,0,1,1),[ft,mt,pt,Ge]=e.getImageData(0,0,1,1).data,Ge!==255)throw new Error("css.toColor: Unsupported css format");return{rgba:et.toRgba(ft,mt,pt,Ge),css:n}}t.toColor=i})(Ue||={});var At;(t=>{function e(i){return s(i>>16&255,i>>8&255,i&255)}t.relativeLuminance=e;function s(i,n,o){let a=i/255,l=n/255,c=o/255,d=a<=.03928?a/12.92:Math.pow((a+.055)/1.055,2.4),u=l<=.03928?l/12.92:Math.pow((l+.055)/1.055,2.4),h=c<=.03928?c/12.92:Math.pow((c+.055)/1.055,2.4);return d*.2126+u*.7152+h*.0722}t.relativeLuminance2=s})(At||={});var Tn;(t=>{function e(a,l){if(Ge=(l&255)/255,Ge===1)return l;let c=l>>24&255,d=l>>16&255,u=l>>8&255,h=a>>24&255,f=a>>16&255,m=a>>8&255;return ft=h+Math.round((c-h)*Ge),mt=f+Math.round((d-f)*Ge),pt=m+Math.round((u-m)*Ge),et.toRgba(ft,mt,pt)}t.blend=e;function s(a,l,c){let d=At.relativeLuminance(a>>8),u=At.relativeLuminance(l>>8);if(Ls(d,u)<c){if(u<d){let m=i(a,l,c),p=Ls(d,At.relativeLuminance(m>>8));if(p<c){let g=n(a,l,c),_=Ls(d,At.relativeLuminance(g>>8));return p>_?m:g}return m}let h=n(a,l,c),f=Ls(d,At.relativeLuminance(h>>8));if(f<c){let m=i(a,l,c),p=Ls(d,At.relativeLuminance(m>>8));return f>p?h:m}return h}}t.ensureContrastRatio=s;function i(a,l,c){let d=a>>24&255,u=a>>16&255,h=a>>8&255,f=l>>24&255,m=l>>16&255,p=l>>8&255,g=Ls(At.relativeLuminance2(f,m,p),At.relativeLuminance2(d,u,h));for(;g<c&&(f>0||m>0||p>0);)f-=Math.max(0,Math.ceil(f*.1)),m-=Math.max(0,Math.ceil(m*.1)),p-=Math.max(0,Math.ceil(p*.1)),g=Ls(At.relativeLuminance2(f,m,p),At.relativeLuminance2(d,u,h));return(f<<24|m<<16|p<<8|255)>>>0}t.reduceLuminance=i;function n(a,l,c){let d=a>>24&255,u=a>>16&255,h=a>>8&255,f=l>>24&255,m=l>>16&255,p=l>>8&255,g=Ls(At.relativeLuminance2(f,m,p),At.relativeLuminance2(d,u,h));for(;g<c&&(f<255||m<255||p<255);)f=Math.min(255,f+Math.ceil((255-f)*.1)),m=Math.min(255,m+Math.ceil((255-m)*.1)),p=Math.min(255,p+Math.ceil((255-p)*.1)),g=Ls(At.relativeLuminance2(f,m,p),At.relativeLuminance2(d,u,h));return(f<<24|m<<16|p<<8|255)>>>0}t.increaseLuminance=n;function o(a){return[a>>24&255,a>>16&255,a>>8&255,a&255]}t.toChannels=o})(Tn||={});function di(t){let e=t.toString(16);return e.length<2?"0"+e:e}function Ls(t,e){return t<e?(e+.05)/(t+.05):(t+.05)/(e+.05)}var V3=class extends en{constructor(t,e,s){super(),this.content=0,this.combinedData="",this.fg=t.fg,this.bg=t.bg,this.combinedData=e,this._width=s}isCombined(){return 2097152}getWidth(){return this._width}getChars(){return this.combinedData}getCode(){return 2097151}setFromCharData(t){throw new Error("not implemented")}getAsCharData(){return[this.fg,this.getChars(),this.getWidth(),this.getCode()]}},Yn=class{constructor(t){this._bufferService=t,this._characterJoiners=[],this._nextCharacterJoinerId=0,this._workCell=new as}register(t){let e={id:this._nextCharacterJoinerId++,handler:t};return this._characterJoiners.push(e),e.id}deregister(t){for(let e=0;e<this._characterJoiners.length;e++)if(this._characterJoiners[e].id===t)return this._characterJoiners.splice(e,1),!0;return!1}getJoinedCharacters(t){if(this._characterJoiners.length===0)return[];let e=this._bufferService.buffer.lines.get(t);if(!e||e.length===0)return[];let s=[],i=e.translateToString(!0),n=0,o=0,a=0,l=e.getFg(0),c=e.getBg(0);for(let d=0;d<e.getTrimmedLength();d++)if(e.loadCell(d,this._workCell),this._workCell.getWidth()!==0){if(this._workCell.fg!==l||this._workCell.bg!==c){if(d-n>1){let u=this._getJoinedRanges(i,a,o,e,n);for(let h=0;h<u.length;h++)s.push(u[h])}n=d,a=o,l=this._workCell.fg,c=this._workCell.bg}o+=this._workCell.getChars().length||Xs.length}if(this._bufferService.cols-n>1){let d=this._getJoinedRanges(i,a,o,e,n);for(let u=0;u<d.length;u++)s.push(d[u])}return s}_getJoinedRanges(t,e,s,i,n){let o=t.substring(e,s),a=[];try{a=this._characterJoiners[0].handler(o)}catch(l){console.error(l)}for(let l=1;l<this._characterJoiners.length;l++)try{let c=this._characterJoiners[l].handler(o);for(let d=0;d<c.length;d++)Yn._mergeRanges(a,c[d])}catch(c){console.error(c)}return this._stringRangesToCellRanges(a,i,n),a}_stringRangesToCellRanges(t,e,s){let i=0,n=!1,o=0,a=t[i];if(a){for(let l=s;l<this._bufferService.cols;l++){let c=e.getWidth(l),d=e.getString(l).length||Xs.length;if(c!==0){if(!n&&a[0]<=o&&(a[0]=l,n=!0),a[1]<=o){if(a[1]=l,a=t[++i],!a)break;a[0]<=o?(a[0]=l,n=!0):n=!1}o+=d}}a&&(a[1]=this._bufferService.cols)}}static _mergeRanges(t,e){let s=!1;for(let i=0;i<t.length;i++){let n=t[i];if(s){if(e[1]<=n[0])return t[i-1][1]=e[1],t;if(e[1]<=n[1])return t[i-1][1]=Math.max(e[1],n[1]),t.splice(i,1),t;t.splice(i,1),i--}else{if(e[1]<=n[0])return t.splice(i,0,e),t;if(e[1]<=n[1])return n[0]=Math.min(e[0],n[0]),t;e[0]<n[1]&&(n[0]=Math.min(e[0],n[0]),s=!0);continue}}return s?t[t.length-1][1]=e[1]:t.push(e),t}};Yn=Ye([ce(0,Lt)],Yn);function C3(t){return 57508<=t&&t<=57558}function j3(t){return 9472<=t&&t<=9631}function k3(t){return C3(t)||j3(t)}function N3(){return{css:{canvas:pn(),cell:pn()},device:{canvas:pn(),cell:pn(),char:{width:0,height:0,left:0,top:0}}}}function pn(){return{width:0,height:0}}var Wa=class{constructor(t,e,s,i,n,o,a){this._document=t,this._characterJoinerService=e,this._optionsService=s,this._coreBrowserService=i,this._coreService=n,this._decorationService=o,this._themeService=a,this._workCell=new as,this._columnSelectMode=!1,this.defaultSpacing=0}handleSelectionChanged(t,e,s){this._selectionStart=t,this._selectionEnd=e,this._columnSelectMode=s}createRow(t,e,s,i,n,o,a,l,c,d,u){let h=[],f=this._characterJoinerService.getJoinedCharacters(e),m=this._themeService.colors,p=t.getNoBgTrimmedLength();s&&p<o+1&&(p=o+1);let g,_=0,v="",x=0,b=0,y=0,C=0,j=!1,V=0,w=!1,k=0,T=0,I=[],A=d!==-1&&u!==-1;for(let N=0;N<p;N++){t.loadCell(N,this._workCell);let E=this._workCell.getWidth();if(E===0)continue;let R=!1,M=N>=T,L=N,D=this._workCell;if(f.length>0&&N===f[0][0]&&M){let J=f.shift(),ie=this._isCellInSelection(J[0],e);for(x=J[0]+1;x<J[1];x++)M&&=ie===this._isCellInSelection(x,e);M&&=!s||o<J[0]||o>=J[1],M?(R=!0,D=new V3(this._workCell,t.translateToString(!0,J[0],J[1]),J[1]-J[0]),L=J[1]-1,E=D.getWidth()):T=J[1]}let P=this._isCellInSelection(N,e),O=s&&N===o,z=A&&N>=d&&N<=u,$=!1;this._decorationService.forEachDecorationAtCell(N,e,void 0,J=>{$=!0});let W=D.getChars()||Xs;if(W===" "&&(D.isUnderline()||D.isOverline())&&(W=" "),k=E*l-c.get(W,D.isBold(),D.isItalic()),!g)g=this._document.createElement("span");else if(_&&(P&&w||!P&&!w&&D.bg===b)&&(P&&w&&m.selectionForeground||D.fg===y)&&D.extended.ext===C&&z===j&&k===V&&!O&&!R&&!$&&M){D.isInvisible()?v+=Xs:v+=W,_++;continue}else _&&(g.textContent=v),g=this._document.createElement("span"),_=0,v="";if(b=D.bg,y=D.fg,C=D.extended.ext,j=z,V=k,w=P,R&&o>=N&&o<=L&&(o=N),!this._coreService.isCursorHidden&&O&&this._coreService.isCursorInitialized){if(I.push("xterm-cursor"),this._coreBrowserService.isFocused)a&&I.push("xterm-cursor-blink"),I.push(i==="bar"?"xterm-cursor-bar":i==="underline"?"xterm-cursor-underline":"xterm-cursor-block");else if(n)switch(n){case"outline":I.push("xterm-cursor-outline");break;case"block":I.push("xterm-cursor-block");break;case"bar":I.push("xterm-cursor-bar");break;case"underline":I.push("xterm-cursor-underline");break}}if(D.isBold()&&I.push("xterm-bold"),D.isItalic()&&I.push("xterm-italic"),D.isDim()&&I.push("xterm-dim"),D.isInvisible()?v=Xs:v=D.getChars()||Xs,D.isUnderline()&&(I.push(`xterm-underline-${D.extended.underlineStyle}`),v===" "&&(v=" "),!D.isUnderlineColorDefault()))if(D.isUnderlineColorRGB())g.style.textDecorationColor=`rgb(${en.toColorRGB(D.getUnderlineColor()).join(",")})`;else{let J=D.getUnderlineColor();this._optionsService.rawOptions.drawBoldTextInBrightColors&&D.isBold()&&J<8&&(J+=8),g.style.textDecorationColor=m.ansi[J].css}D.isOverline()&&(I.push("xterm-overline"),v===" "&&(v=" ")),D.isStrikethrough()&&I.push("xterm-strikethrough"),z&&(g.style.textDecoration="underline");let F=D.getFgColor(),G=D.getFgColorMode(),q=D.getBgColor(),H=D.getBgColorMode(),ee=!!D.isInverse();if(ee){let J=F;F=q,q=J;let ie=G;G=H,H=ie}let K,U,te=!1;this._decorationService.forEachDecorationAtCell(N,e,void 0,J=>{J.options.layer!=="top"&&te||(J.backgroundColorRGB&&(H=50331648,q=J.backgroundColorRGB.rgba>>8&16777215,K=J.backgroundColorRGB),J.foregroundColorRGB&&(G=50331648,F=J.foregroundColorRGB.rgba>>8&16777215,U=J.foregroundColorRGB),te=J.options.layer==="top")}),!te&&P&&(K=this._coreBrowserService.isFocused?m.selectionBackgroundOpaque:m.selectionInactiveBackgroundOpaque,q=K.rgba>>8&16777215,H=50331648,te=!0,m.selectionForeground&&(G=50331648,F=m.selectionForeground.rgba>>8&16777215,U=m.selectionForeground)),te&&I.push("xterm-decoration-top");let Y;switch(H){case 16777216:case 33554432:Y=m.ansi[q],I.push(`xterm-bg-${q}`);break;case 50331648:Y=et.toColor(q>>16,q>>8&255,q&255),this._addStyle(g,`background-color:#${$d((q>>>0).toString(16),"0",6)}`);break;default:ee?(Y=m.foreground,I.push("xterm-bg-257")):Y=m.background}switch(K||D.isDim()&&(K=Le.multiplyOpacity(Y,.5)),G){case 16777216:case 33554432:D.isBold()&&F<8&&this._optionsService.rawOptions.drawBoldTextInBrightColors&&(F+=8),this._applyMinimumContrast(g,Y,m.ansi[F],D,K,void 0)||I.push(`xterm-fg-${F}`);break;case 50331648:let J=et.toColor(F>>16&255,F>>8&255,F&255);this._applyMinimumContrast(g,Y,J,D,K,U)||this._addStyle(g,`color:#${$d(F.toString(16),"0",6)}`);break;default:this._applyMinimumContrast(g,Y,m.foreground,D,K,U)||ee&&I.push("xterm-fg-257")}I.length&&(g.className=I.join(" "),I.length=0),!O&&!R&&!$&&M?_++:g.textContent=v,k!==this.defaultSpacing&&(g.style.letterSpacing=`${k}px`),h.push(g),N=L}return g&&_&&(g.textContent=v),h}_applyMinimumContrast(t,e,s,i,n,o){if(this._optionsService.rawOptions.minimumContrastRatio===1||k3(i.getCode()))return!1;let a=this._getContrastCache(i),l;if(!n&&!o&&(l=a.getColor(e.rgba,s.rgba)),l===void 0){let c=this._optionsService.rawOptions.minimumContrastRatio/(i.isDim()?2:1);l=Le.ensureContrastRatio(n||e,o||s,c),a.setColor((n||e).rgba,(o||s).rgba,l??null)}return l?(this._addStyle(t,`color:${l.css}`),!0):!1}_getContrastCache(t){return t.isDim()?this._themeService.colors.halfContrastCache:this._themeService.colors.contrastCache}_addStyle(t,e){t.setAttribute("style",`${t.getAttribute("style")||""}${e};`)}_isCellInSelection(t,e){let s=this._selectionStart,i=this._selectionEnd;return!s||!i?!1:this._columnSelectMode?s[0]<=i[0]?t>=s[0]&&e>=s[1]&&t<i[0]&&e<=i[1]:t<s[0]&&e>=s[1]&&t>=i[0]&&e<=i[1]:e>s[1]&&e<i[1]||s[1]===i[1]&&e===s[1]&&t>=s[0]&&t<i[0]||s[1]<i[1]&&e===i[1]&&t<i[0]||s[1]<i[1]&&e===s[1]&&t>=s[0]}};Wa=Ye([ce(1,nm),ce(2,Bt),ce(3,Hs),ce(4,Ci),ce(5,tn),ce(6,Xi)],Wa);function $d(t,e,s){for(;t.length<s;)t=e+t;return t}var A3=class{constructor(t,e){this._flat=new Float32Array(256),this._font="",this._fontSize=0,this._weight="normal",this._weightBold="bold",this._measureElements=[],this._container=t.createElement("div"),this._container.classList.add("xterm-width-cache-measure-container"),this._container.setAttribute("aria-hidden","true"),this._container.style.whiteSpace="pre",this._container.style.fontKerning="none";let s=t.createElement("span");s.classList.add("xterm-char-measure-element");let i=t.createElement("span");i.classList.add("xterm-char-measure-element"),i.style.fontWeight="bold";let n=t.createElement("span");n.classList.add("xterm-char-measure-element"),n.style.fontStyle="italic";let o=t.createElement("span");o.classList.add("xterm-char-measure-element"),o.style.fontWeight="bold",o.style.fontStyle="italic",this._measureElements=[s,i,n,o],this._container.appendChild(s),this._container.appendChild(i),this._container.appendChild(n),this._container.appendChild(o),e.appendChild(this._container),this.clear()}dispose(){this._container.remove(),this._measureElements.length=0,this._holey=void 0}clear(){this._flat.fill(-9999),this._holey=new Map}setFont(t,e,s,i){t===this._font&&e===this._fontSize&&s===this._weight&&i===this._weightBold||(this._font=t,this._fontSize=e,this._weight=s,this._weightBold=i,this._container.style.fontFamily=this._font,this._container.style.fontSize=`${this._fontSize}px`,this._measureElements[0].style.fontWeight=`${s}`,this._measureElements[1].style.fontWeight=`${i}`,this._measureElements[2].style.fontWeight=`${s}`,this._measureElements[3].style.fontWeight=`${i}`,this.clear())}get(t,e,s){let i=0;if(!e&&!s&&t.length===1&&(i=t.charCodeAt(0))<256){if(this._flat[i]!==-9999)return this._flat[i];let a=this._measure(t,0);return a>0&&(this._flat[i]=a),a}let n=t;e&&(n+="B"),s&&(n+="I");let o=this._holey.get(n);if(o===void 0){let a=0;e&&(a|=1),s&&(a|=2),o=this._measure(t,a),o>0&&this._holey.set(n,o)}return o}_measure(t,e){let s=this._measureElements[e];return s.textContent=t.repeat(32),s.offsetWidth/32}},E3=class{constructor(){this.clear()}clear(){this.hasSelection=!1,this.columnSelectMode=!1,this.viewportStartRow=0,this.viewportEndRow=0,this.viewportCappedStartRow=0,this.viewportCappedEndRow=0,this.startCol=0,this.endCol=0,this.selectionStart=void 0,this.selectionEnd=void 0}update(t,e,s,i=!1){if(this.selectionStart=e,this.selectionEnd=s,!e||!s||e[0]===s[0]&&e[1]===s[1]){this.clear();return}let n=t.buffers.active.ydisp,o=e[1]-n,a=s[1]-n,l=Math.max(o,0),c=Math.min(a,t.rows-1);if(l>=t.rows||c<0){this.clear();return}this.hasSelection=!0,this.columnSelectMode=i,this.viewportStartRow=o,this.viewportEndRow=a,this.viewportCappedStartRow=l,this.viewportCappedEndRow=c,this.startCol=e[0],this.endCol=s[0]}isCellSelected(t,e,s){return this.hasSelection?(s-=t.buffer.active.viewportY,this.columnSelectMode?this.startCol<=this.endCol?e>=this.startCol&&s>=this.viewportCappedStartRow&&e<this.endCol&&s<=this.viewportCappedEndRow:e<this.startCol&&s>=this.viewportCappedStartRow&&e>=this.endCol&&s<=this.viewportCappedEndRow:s>this.viewportStartRow&&s<this.viewportEndRow||this.viewportStartRow===this.viewportEndRow&&s===this.viewportStartRow&&e>=this.startCol&&e<this.endCol||this.viewportStartRow<this.viewportEndRow&&s===this.viewportEndRow&&e<this.endCol||this.viewportStartRow<this.viewportEndRow&&s===this.viewportStartRow&&e>=this.startCol):!1}};function I3(){return new E3}var qo="xterm-dom-renderer-owner-",ss="xterm-rows",gn="xterm-fg-",zd="xterm-bg-",rr="xterm-focus",_n="xterm-selection",R3=1,Ua=class extends Ve{constructor(t,e,s,i,n,o,a,l,c,d,u,h,f,m){super(),this._terminal=t,this._document=e,this._element=s,this._screenElement=i,this._viewportElement=n,this._helperContainer=o,this._linkifier2=a,this._charSizeService=c,this._optionsService=d,this._bufferService=u,this._coreService=h,this._coreBrowserService=f,this._themeService=m,this._terminalClass=R3++,this._rowElements=[],this._selectionRenderModel=I3(),this.onRequestRedraw=this._register(new re).event,this._rowContainer=this._document.createElement("div"),this._rowContainer.classList.add(ss),this._rowContainer.style.lineHeight="normal",this._rowContainer.setAttribute("aria-hidden","true"),this._refreshRowElements(this._bufferService.cols,this._bufferService.rows),this._selectionContainer=this._document.createElement("div"),this._selectionContainer.classList.add(_n),this._selectionContainer.setAttribute("aria-hidden","true"),this.dimensions=N3(),this._updateDimensions(),this._register(this._optionsService.onOptionChange(()=>this._handleOptionsChanged())),this._register(this._themeService.onChangeColors(p=>this._injectCss(p))),this._injectCss(this._themeService.colors),this._rowFactory=l.createInstance(Wa,document),this._element.classList.add(qo+this._terminalClass),this._screenElement.appendChild(this._rowContainer),this._screenElement.appendChild(this._selectionContainer),this._register(this._linkifier2.onShowLinkUnderline(p=>this._handleLinkHover(p))),this._register(this._linkifier2.onHideLinkUnderline(p=>this._handleLinkLeave(p))),this._register(Fe(()=>{this._element.classList.remove(qo+this._terminalClass),this._rowContainer.remove(),this._selectionContainer.remove(),this._widthCache.dispose(),this._themeStyleElement.remove(),this._dimensionsStyleElement.remove()})),this._widthCache=new A3(this._document,this._helperContainer),this._widthCache.setFont(this._optionsService.rawOptions.fontFamily,this._optionsService.rawOptions.fontSize,this._optionsService.rawOptions.fontWeight,this._optionsService.rawOptions.fontWeightBold),this._setDefaultSpacing()}_updateDimensions(){let t=this._coreBrowserService.dpr;this.dimensions.device.char.width=this._charSizeService.width*t,this.dimensions.device.char.height=Math.ceil(this._charSizeService.height*t),this.dimensions.device.cell.width=this.dimensions.device.char.width+Math.round(this._optionsService.rawOptions.letterSpacing),this.dimensions.device.cell.height=Math.floor(this.dimensions.device.char.height*this._optionsService.rawOptions.lineHeight),this.dimensions.device.char.left=0,this.dimensions.device.char.top=0,this.dimensions.device.canvas.width=this.dimensions.device.cell.width*this._bufferService.cols,this.dimensions.device.canvas.height=this.dimensions.device.cell.height*this._bufferService.rows,this.dimensions.css.canvas.width=Math.round(this.dimensions.device.canvas.width/t),this.dimensions.css.canvas.height=Math.round(this.dimensions.device.canvas.height/t),this.dimensions.css.cell.width=this.dimensions.css.canvas.width/this._bufferService.cols,this.dimensions.css.cell.height=this.dimensions.css.canvas.height/this._bufferService.rows;for(let s of this._rowElements)s.style.width=`${this.dimensions.css.canvas.width}px`,s.style.height=`${this.dimensions.css.cell.height}px`,s.style.lineHeight=`${this.dimensions.css.cell.height}px`,s.style.overflow="hidden";this._dimensionsStyleElement||(this._dimensionsStyleElement=this._document.createElement("style"),this._screenElement.appendChild(this._dimensionsStyleElement));let e=`${this._terminalSelector} .${ss} span { display: inline-block; height: 100%; vertical-align: top;}`;this._dimensionsStyleElement.textContent=e,this._selectionContainer.style.height=this._viewportElement.style.height,this._screenElement.style.width=`${this.dimensions.css.canvas.width}px`,this._screenElement.style.height=`${this.dimensions.css.canvas.height}px`}_injectCss(t){this._themeStyleElement||(this._themeStyleElement=this._document.createElement("style"),this._screenElement.appendChild(this._themeStyleElement));let e=`${this._terminalSelector} .${ss} { pointer-events: none; color: ${t.foreground.css}; font-family: ${this._optionsService.rawOptions.fontFamily}; font-size: ${this._optionsService.rawOptions.fontSize}px; font-kerning: none; white-space: pre}`;e+=`${this._terminalSelector} .${ss} .xterm-dim { color: ${Le.multiplyOpacity(t.foreground,.5).css};}`,e+=`${this._terminalSelector} span:not(.xterm-bold) { font-weight: ${this._optionsService.rawOptions.fontWeight};}${this._terminalSelector} span.xterm-bold { font-weight: ${this._optionsService.rawOptions.fontWeightBold};}${this._terminalSelector} span.xterm-italic { font-style: italic;}`;let s=`blink_underline_${this._terminalClass}`,i=`blink_bar_${this._terminalClass}`,n=`blink_block_${this._terminalClass}`;e+=`@keyframes ${s} { 50% { border-bottom-style: hidden; }}`,e+=`@keyframes ${i} { 50% { box-shadow: none; }}`,e+=`@keyframes ${n} { 0% { background-color: ${t.cursor.css}; color: ${t.cursorAccent.css}; } 50% { background-color: inherit; color: ${t.cursor.css}; }}`,e+=`${this._terminalSelector} .${ss}.${rr} .xterm-cursor.xterm-cursor-blink.xterm-cursor-underline { animation: ${s} 1s step-end infinite;}${this._terminalSelector} .${ss}.${rr} .xterm-cursor.xterm-cursor-blink.xterm-cursor-bar { animation: ${i} 1s step-end infinite;}${this._terminalSelector} .${ss}.${rr} .xterm-cursor.xterm-cursor-blink.xterm-cursor-block { animation: ${n} 1s step-end infinite;}${this._terminalSelector} .${ss} .xterm-cursor.xterm-cursor-block { background-color: ${t.cursor.css}; color: ${t.cursorAccent.css};}${this._terminalSelector} .${ss} .xterm-cursor.xterm-cursor-block:not(.xterm-cursor-blink) { background-color: ${t.cursor.css} !important; color: ${t.cursorAccent.css} !important;}${this._terminalSelector} .${ss} .xterm-cursor.xterm-cursor-outline { outline: 1px solid ${t.cursor.css}; outline-offset: -1px;}${this._terminalSelector} .${ss} .xterm-cursor.xterm-cursor-bar { box-shadow: ${this._optionsService.rawOptions.cursorWidth}px 0 0 ${t.cursor.css} inset;}${this._terminalSelector} .${ss} .xterm-cursor.xterm-cursor-underline { border-bottom: 1px ${t.cursor.css}; border-bottom-style: solid; height: calc(100% - 1px);}`,e+=`${this._terminalSelector} .${_n} { position: absolute; top: 0; left: 0; z-index: 1; pointer-events: none;}${this._terminalSelector}.focus .${_n} div { position: absolute; background-color: ${t.selectionBackgroundOpaque.css};}${this._terminalSelector} .${_n} div { position: absolute; background-color: ${t.selectionInactiveBackgroundOpaque.css};}`;for(let[o,a]of t.ansi.entries())e+=`${this._terminalSelector} .${gn}${o} { color: ${a.css}; }${this._terminalSelector} .${gn}${o}.xterm-dim { color: ${Le.multiplyOpacity(a,.5).css}; }${this._terminalSelector} .${zd}${o} { background-color: ${a.css}; }`;e+=`${this._terminalSelector} .${gn}257 { color: ${Le.opaque(t.background).css}; }${this._terminalSelector} .${gn}257.xterm-dim { color: ${Le.multiplyOpacity(Le.opaque(t.background),.5).css}; }${this._terminalSelector} .${zd}257 { background-color: ${t.foreground.css}; }`,this._themeStyleElement.textContent=e}_setDefaultSpacing(){let t=this.dimensions.css.cell.width-this._widthCache.get("W",!1,!1);this._rowContainer.style.letterSpacing=`${t}px`,this._rowFactory.defaultSpacing=t}handleDevicePixelRatioChange(){this._updateDimensions(),this._widthCache.clear(),this._setDefaultSpacing()}_refreshRowElements(t,e){for(let s=this._rowElements.length;s<=e;s++){let i=this._document.createElement("div");this._rowContainer.appendChild(i),this._rowElements.push(i)}for(;this._rowElements.length>e;)this._rowContainer.removeChild(this._rowElements.pop())}handleResize(t,e){this._refreshRowElements(t,e),this._updateDimensions(),this.handleSelectionChanged(this._selectionRenderModel.selectionStart,this._selectionRenderModel.selectionEnd,this._selectionRenderModel.columnSelectMode)}handleCharSizeChanged(){this._updateDimensions(),this._widthCache.clear(),this._setDefaultSpacing()}handleBlur(){this._rowContainer.classList.remove(rr),this.renderRows(0,this._bufferService.rows-1)}handleFocus(){this._rowContainer.classList.add(rr),this.renderRows(this._bufferService.buffer.y,this._bufferService.buffer.y)}handleSelectionChanged(t,e,s){if(this._selectionContainer.replaceChildren(),this._rowFactory.handleSelectionChanged(t,e,s),this.renderRows(0,this._bufferService.rows-1),!t||!e||(this._selectionRenderModel.update(this._terminal,t,e,s),!this._selectionRenderModel.hasSelection))return;let i=this._selectionRenderModel.viewportStartRow,n=this._selectionRenderModel.viewportEndRow,o=this._selectionRenderModel.viewportCappedStartRow,a=this._selectionRenderModel.viewportCappedEndRow,l=this._document.createDocumentFragment();if(s){let c=t[0]>e[0];l.appendChild(this._createSelectionElement(o,c?e[0]:t[0],c?t[0]:e[0],a-o+1))}else{let c=i===o?t[0]:0,d=o===n?e[0]:this._bufferService.cols;l.appendChild(this._createSelectionElement(o,c,d));let u=a-o-1;if(l.appendChild(this._createSelectionElement(o+1,0,this._bufferService.cols,u)),o!==a){let h=n===a?e[0]:this._bufferService.cols;l.appendChild(this._createSelectionElement(a,0,h))}}this._selectionContainer.appendChild(l)}_createSelectionElement(t,e,s,i=1){let n=this._document.createElement("div"),o=e*this.dimensions.css.cell.width,a=this.dimensions.css.cell.width*(s-e);return o+a>this.dimensions.css.canvas.width&&(a=this.dimensions.css.canvas.width-o),n.style.height=`${i*this.dimensions.css.cell.height}px`,n.style.top=`${t*this.dimensions.css.cell.height}px`,n.style.left=`${o}px`,n.style.width=`${a}px`,n}handleCursorMove(){}_handleOptionsChanged(){this._updateDimensions(),this._injectCss(this._themeService.colors),this._widthCache.setFont(this._optionsService.rawOptions.fontFamily,this._optionsService.rawOptions.fontSize,this._optionsService.rawOptions.fontWeight,this._optionsService.rawOptions.fontWeightBold),this._setDefaultSpacing()}clear(){for(let t of this._rowElements)t.replaceChildren()}renderRows(t,e){let s=this._bufferService.buffer,i=s.ybase+s.y,n=Math.min(s.x,this._bufferService.cols-1),o=this._coreService.decPrivateModes.cursorBlink??this._optionsService.rawOptions.cursorBlink,a=this._coreService.decPrivateModes.cursorStyle??this._optionsService.rawOptions.cursorStyle,l=this._optionsService.rawOptions.cursorInactiveStyle;for(let c=t;c<=e;c++){let d=c+s.ydisp,u=this._rowElements[c],h=s.lines.get(d);if(!u||!h)break;u.replaceChildren(...this._rowFactory.createRow(h,d,d===i,a,l,n,o,this.dimensions.css.cell.width,this._widthCache,-1,-1))}}get _terminalSelector(){return`.${qo}${this._terminalClass}`}_handleLinkHover(t){this._setCellUnderline(t.x1,t.x2,t.y1,t.y2,t.cols,!0)}_handleLinkLeave(t){this._setCellUnderline(t.x1,t.x2,t.y1,t.y2,t.cols,!1)}_setCellUnderline(t,e,s,i,n,o){s<0&&(t=0),i<0&&(e=0);let a=this._bufferService.rows-1;s=Math.max(Math.min(s,a),0),i=Math.max(Math.min(i,a),0),n=Math.min(n,this._bufferService.cols);let l=this._bufferService.buffer,c=l.ybase+l.y,d=Math.min(l.x,n-1),u=this._optionsService.rawOptions.cursorBlink,h=this._optionsService.rawOptions.cursorStyle,f=this._optionsService.rawOptions.cursorInactiveStyle;for(let m=s;m<=i;++m){let p=m+l.ydisp,g=this._rowElements[m],_=l.lines.get(p);if(!g||!_)break;g.replaceChildren(...this._rowFactory.createRow(_,p,p===c,h,f,d,u,this.dimensions.css.cell.width,this._widthCache,o?m===s?t:0:-1,o?(m===i?e:n)-1:-1))}}};Ua=Ye([ce(7,Jl),ce(8,vo),ce(9,Bt),ce(10,Lt),ce(11,Ci),ce(12,Hs),ce(13,Xi)],Ua);var Ka=class extends Ve{constructor(t,e,s){super(),this._optionsService=s,this.width=0,this.height=0,this._onCharSizeChange=this._register(new re),this.onCharSizeChange=this._onCharSizeChange.event;try{this._measureStrategy=this._register(new D3(this._optionsService))}catch{this._measureStrategy=this._register(new T3(t,e,this._optionsService))}this._register(this._optionsService.onMultipleOptionChange(["fontFamily","fontSize"],()=>this.measure()))}get hasValidSize(){return this.width>0&&this.height>0}measure(){let t=this._measureStrategy.measure();(t.width!==this.width||t.height!==this.height)&&(this.width=t.width,this.height=t.height,this._onCharSizeChange.fire())}};Ka=Ye([ce(2,Bt)],Ka);var Vm=class extends Ve{constructor(){super(...arguments),this._result={width:0,height:0}}_validateAndSet(t,e){t!==void 0&&t>0&&e!==void 0&&e>0&&(this._result.width=t,this._result.height=e)}},T3=class extends Vm{constructor(t,e,s){super(),this._document=t,this._parentElement=e,this._optionsService=s,this._measureElement=this._document.createElement("span"),this._measureElement.classList.add("xterm-char-measure-element"),this._measureElement.textContent="W".repeat(32),this._measureElement.setAttribute("aria-hidden","true"),this._measureElement.style.whiteSpace="pre",this._measureElement.style.fontKerning="none",this._parentElement.appendChild(this._measureElement)}measure(){return this._measureElement.style.fontFamily=this._optionsService.rawOptions.fontFamily,this._measureElement.style.fontSize=`${this._optionsService.rawOptions.fontSize}px`,this._validateAndSet(Number(this._measureElement.offsetWidth)/32,Number(this._measureElement.offsetHeight)),this._result}},D3=class extends Vm{constructor(t){super(),this._optionsService=t,this._canvas=new OffscreenCanvas(100,100),this._ctx=this._canvas.getContext("2d");let e=this._ctx.measureText("W");if(!("width"in e&&"fontBoundingBoxAscent"in e&&"fontBoundingBoxDescent"in e))throw new Error("Required font metrics not supported")}measure(){this._ctx.font=`${this._optionsService.rawOptions.fontSize}px ${this._optionsService.rawOptions.fontFamily}`;let t=this._ctx.measureText("W");return this._validateAndSet(t.width,t.fontBoundingBoxAscent+t.fontBoundingBoxDescent),this._result}},M3=class extends Ve{constructor(t,e,s){super(),this._textarea=t,this._window=e,this.mainDocument=s,this._isFocused=!1,this._cachedIsFocused=void 0,this._screenDprMonitor=this._register(new P3(this._window)),this._onDprChange=this._register(new re),this.onDprChange=this._onDprChange.event,this._onWindowChange=this._register(new re),this.onWindowChange=this._onWindowChange.event,this._register(this.onWindowChange(i=>this._screenDprMonitor.setWindow(i))),this._register(yt.forward(this._screenDprMonitor.onDprChange,this._onDprChange)),this._register(ye(this._textarea,"focus",()=>this._isFocused=!0)),this._register(ye(this._textarea,"blur",()=>this._isFocused=!1))}get window(){return this._window}set window(t){this._window!==t&&(this._window=t,this._onWindowChange.fire(this._window))}get dpr(){return this.window.devicePixelRatio}get isFocused(){return this._cachedIsFocused===void 0&&(this._cachedIsFocused=this._isFocused&&this._textarea.ownerDocument.hasFocus(),queueMicrotask(()=>this._cachedIsFocused=void 0)),this._cachedIsFocused}},P3=class extends Ve{constructor(t){super(),this._parentWindow=t,this._windowResizeListener=this._register(new zi),this._onDprChange=this._register(new re),this.onDprChange=this._onDprChange.event,this._outerListener=()=>this._setDprAndFireIfDiffers(),this._currentDevicePixelRatio=this._parentWindow.devicePixelRatio,this._updateDpr(),this._setWindowResizeListener(),this._register(Fe(()=>this.clearListener()))}setWindow(t){this._parentWindow=t,this._setWindowResizeListener(),this._setDprAndFireIfDiffers()}_setWindowResizeListener(){this._windowResizeListener.value=ye(this._parentWindow,"resize",()=>this._setDprAndFireIfDiffers())}_setDprAndFireIfDiffers(){this._parentWindow.devicePixelRatio!==this._currentDevicePixelRatio&&this._onDprChange.fire(this._parentWindow.devicePixelRatio),this._updateDpr()}_updateDpr(){this._outerListener&&(this._resolutionMediaMatchList?.removeListener(this._outerListener),this._currentDevicePixelRatio=this._parentWindow.devicePixelRatio,this._resolutionMediaMatchList=this._parentWindow.matchMedia(`screen and (resolution: ${this._parentWindow.devicePixelRatio}dppx)`),this._resolutionMediaMatchList.addListener(this._outerListener))}clearListener(){!this._resolutionMediaMatchList||!this._outerListener||(this._resolutionMediaMatchList.removeListener(this._outerListener),this._resolutionMediaMatchList=void 0,this._outerListener=void 0)}},L3=class extends Ve{constructor(){super(),this.linkProviders=[],this._register(Fe(()=>this.linkProviders.length=0))}registerLinkProvider(t){return this.linkProviders.push(t),{dispose:()=>{let e=this.linkProviders.indexOf(t);e!==-1&&this.linkProviders.splice(e,1)}}}};function nc(t,e,s){let i=s.getBoundingClientRect(),n=t.getComputedStyle(s),o=parseInt(n.getPropertyValue("padding-left")),a=parseInt(n.getPropertyValue("padding-top"));return[e.clientX-i.left-o,e.clientY-i.top-a]}function B3(t,e,s,i,n,o,a,l,c){if(!o)return;let d=nc(t,e,s);if(d)return d[0]=Math.ceil((d[0]+(c?a/2:0))/a),d[1]=Math.ceil(d[1]/l),d[0]=Math.min(Math.max(d[0],1),i+(c?1:0)),d[1]=Math.min(Math.max(d[1],1),n),d}var qa=class{constructor(t,e){this._renderService=t,this._charSizeService=e}getCoords(t,e,s,i,n){return B3(window,t,e,s,i,this._charSizeService.hasValidSize,this._renderService.dimensions.css.cell.width,this._renderService.dimensions.css.cell.height,n)}getMouseReportCoords(t,e){let s=nc(window,t,e);if(this._charSizeService.hasValidSize)return s[0]=Math.min(Math.max(s[0],0),this._renderService.dimensions.css.canvas.width-1),s[1]=Math.min(Math.max(s[1],0),this._renderService.dimensions.css.canvas.height-1),{col:Math.floor(s[0]/this._renderService.dimensions.css.cell.width),row:Math.floor(s[1]/this._renderService.dimensions.css.cell.height),x:Math.floor(s[0]),y:Math.floor(s[1])}}};qa=Ye([ce(0,Ws),ce(1,vo)],qa);var O3=class{constructor(t,e){this._renderCallback=t,this._coreBrowserService=e,this._refreshCallbacks=[]}dispose(){this._animationFrame&&(this._coreBrowserService.window.cancelAnimationFrame(this._animationFrame),this._animationFrame=void 0)}addRefreshCallback(t){return this._refreshCallbacks.push(t),this._animationFrame||(this._animationFrame=this._coreBrowserService.window.requestAnimationFrame(()=>this._innerRefresh())),this._animationFrame}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,!this._animationFrame&&(this._animationFrame=this._coreBrowserService.window.requestAnimationFrame(()=>this._innerRefresh()))}_innerRefresh(){if(this._animationFrame=void 0,this._rowStart===void 0||this._rowEnd===void 0||this._rowCount===void 0){this._runRefreshCallbacks();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),this._runRefreshCallbacks()}_runRefreshCallbacks(){for(let t of this._refreshCallbacks)t(0);this._refreshCallbacks=[]}},Cm={};YV(Cm,{getSafariVersion:()=>z3,isChromeOS:()=>Am,isFirefox:()=>jm,isIpad:()=>F3,isIphone:()=>H3,isLegacyEdge:()=>$3,isLinux:()=>oc,isMac:()=>Xn,isNode:()=>bo,isSafari:()=>km,isWindows:()=>Nm});var bo=typeof process<"u"&&"title"in process,sn=bo?"node":navigator.userAgent,rn=bo?"node":navigator.platform,jm=sn.includes("Firefox"),$3=sn.includes("Edge"),km=/^((?!chrome|android).)*safari/i.test(sn);function z3(){if(!km)return 0;let t=sn.match(/Version\/(\d+)/);return t===null||t.length<2?0:parseInt(t[1])}var Xn=["Macintosh","MacIntel","MacPPC","Mac68K"].includes(rn),F3=rn==="iPad",H3=rn==="iPhone",Nm=["Windows","Win16","Win32","WinCE"].includes(rn),oc=rn.indexOf("Linux")>=0,Am=/\bCrOS\b/.test(sn),Em=class{constructor(){this._tasks=[],this._i=0}enqueue(t){this._tasks.push(t),this._start()}flush(){for(;this._i<this._tasks.length;)this._tasks[this._i]()||this._i++;this.clear()}clear(){this._idleCallback&&(this._cancelCallback(this._idleCallback),this._idleCallback=void 0),this._i=0,this._tasks.length=0}_start(){this._idleCallback||(this._idleCallback=this._requestCallback(this._process.bind(this)))}_process(t){this._idleCallback=void 0;let e=0,s=0,i=t.timeRemaining(),n=0;for(;this._i<this._tasks.length;){if(e=performance.now(),this._tasks[this._i]()||this._i++,e=Math.max(1,performance.now()-e),s=Math.max(e,s),n=t.timeRemaining(),s*1.5>n){i-e<-20&&console.warn(`task queue exceeded allotted deadline by ${Math.abs(Math.round(i-e))}ms`),this._start();return}i=n}this.clear()}},W3=class extends Em{_requestCallback(t){return setTimeout(()=>t(this._createDeadline(16)))}_cancelCallback(t){clearTimeout(t)}_createDeadline(t){let e=performance.now()+t;return{timeRemaining:()=>Math.max(0,e-performance.now())}}},U3=class extends Em{_requestCallback(t){return requestIdleCallback(t)}_cancelCallback(t){cancelIdleCallback(t)}},Jn=!bo&&"requestIdleCallback"in window?U3:W3,K3=class{constructor(){this._queue=new Jn}set(t){this._queue.clear(),this._queue.enqueue(t)}flush(){this._queue.flush()}},Ga=class extends Ve{constructor(t,e,s,i,n,o,a,l,c){super(),this._rowCount=t,this._optionsService=s,this._charSizeService=i,this._coreService=n,this._coreBrowserService=l,this._renderer=this._register(new zi),this._pausedResizeTask=new K3,this._observerDisposable=this._register(new zi),this._isPaused=!1,this._needsFullRefresh=!1,this._isNextRenderRedrawOnly=!0,this._needsSelectionRefresh=!1,this._canvasWidth=0,this._canvasHeight=0,this._selectionState={start:void 0,end:void 0,columnSelectMode:!1},this._onDimensionsChange=this._register(new re),this.onDimensionsChange=this._onDimensionsChange.event,this._onRenderedViewportChange=this._register(new re),this.onRenderedViewportChange=this._onRenderedViewportChange.event,this._onRender=this._register(new re),this.onRender=this._onRender.event,this._onRefreshRequest=this._register(new re),this.onRefreshRequest=this._onRefreshRequest.event,this._renderDebouncer=new O3((d,u)=>this._renderRows(d,u),this._coreBrowserService),this._register(this._renderDebouncer),this._syncOutputHandler=new q3(this._coreBrowserService,this._coreService,()=>this._fullRefresh()),this._register(Fe(()=>this._syncOutputHandler.dispose())),this._register(this._coreBrowserService.onDprChange(()=>this.handleDevicePixelRatioChange())),this._register(a.onResize(()=>this._fullRefresh())),this._register(a.buffers.onBufferActivate(()=>this._renderer.value?.clear())),this._register(this._optionsService.onOptionChange(()=>this._handleOptionsChanged())),this._register(this._charSizeService.onCharSizeChange(()=>this.handleCharSizeChanged())),this._register(o.onDecorationRegistered(()=>this._fullRefresh())),this._register(o.onDecorationRemoved(()=>this._fullRefresh())),this._register(this._optionsService.onMultipleOptionChange(["customGlyphs","drawBoldTextInBrightColors","letterSpacing","lineHeight","fontFamily","fontSize","fontWeight","fontWeightBold","minimumContrastRatio","rescaleOverlappingGlyphs"],()=>{this.clear(),this.handleResize(a.cols,a.rows),this._fullRefresh()})),this._register(this._optionsService.onMultipleOptionChange(["cursorBlink","cursorStyle"],()=>this.refreshRows(a.buffer.y,a.buffer.y,!0))),this._register(c.onChangeColors(()=>this._fullRefresh())),this._registerIntersectionObserver(this._coreBrowserService.window,e),this._register(this._coreBrowserService.onWindowChange(d=>this._registerIntersectionObserver(d,e)))}get dimensions(){return this._renderer.value.dimensions}_registerIntersectionObserver(t,e){if("IntersectionObserver"in t){let s=new t.IntersectionObserver(i=>this._handleIntersectionChange(i[i.length-1]),{threshold:0});s.observe(e),this._observerDisposable.value=Fe(()=>s.disconnect())}}_handleIntersectionChange(t){this._isPaused=t.isIntersecting===void 0?t.intersectionRatio===0:!t.isIntersecting,!this._isPaused&&!this._charSizeService.hasValidSize&&this._charSizeService.measure(),!this._isPaused&&this._needsFullRefresh&&(this._pausedResizeTask.flush(),this.refreshRows(0,this._rowCount-1),this._needsFullRefresh=!1)}refreshRows(t,e,s=!1){if(this._isPaused){this._needsFullRefresh=!0;return}if(this._coreService.decPrivateModes.synchronizedOutput){this._syncOutputHandler.bufferRows(t,e);return}let i=this._syncOutputHandler.flush();i&&(t=Math.min(t,i.start),e=Math.max(e,i.end)),s||(this._isNextRenderRedrawOnly=!1),this._renderDebouncer.refresh(t,e,this._rowCount)}_renderRows(t,e){if(this._renderer.value){if(this._coreService.decPrivateModes.synchronizedOutput){this._syncOutputHandler.bufferRows(t,e);return}t=Math.min(t,this._rowCount-1),e=Math.min(e,this._rowCount-1),this._renderer.value.renderRows(t,e),this._needsSelectionRefresh&&(this._renderer.value.handleSelectionChanged(this._selectionState.start,this._selectionState.end,this._selectionState.columnSelectMode),this._needsSelectionRefresh=!1),this._isNextRenderRedrawOnly||this._onRenderedViewportChange.fire({start:t,end:e}),this._onRender.fire({start:t,end:e}),this._isNextRenderRedrawOnly=!0}}resize(t,e){this._rowCount=e,this._fireOnCanvasResize()}_handleOptionsChanged(){this._renderer.value&&(this.refreshRows(0,this._rowCount-1),this._fireOnCanvasResize())}_fireOnCanvasResize(){this._renderer.value&&(this._renderer.value.dimensions.css.canvas.width===this._canvasWidth&&this._renderer.value.dimensions.css.canvas.height===this._canvasHeight||this._onDimensionsChange.fire(this._renderer.value.dimensions))}hasRenderer(){return!!this._renderer.value}setRenderer(t){this._renderer.value=t,this._renderer.value&&(this._renderer.value.onRequestRedraw(e=>this.refreshRows(e.start,e.end,!0)),this._needsSelectionRefresh=!0,this._fullRefresh())}addRefreshCallback(t){return this._renderDebouncer.addRefreshCallback(t)}_fullRefresh(){this._isPaused?this._needsFullRefresh=!0:this.refreshRows(0,this._rowCount-1)}clearTextureAtlas(){this._renderer.value&&(this._renderer.value.clearTextureAtlas?.(),this._fullRefresh())}handleDevicePixelRatioChange(){this._charSizeService.measure(),this._renderer.value&&(this._renderer.value.handleDevicePixelRatioChange(),this.refreshRows(0,this._rowCount-1))}handleResize(t,e){this._renderer.value&&(this._isPaused?this._pausedResizeTask.set(()=>this._renderer.value?.handleResize(t,e)):this._renderer.value.handleResize(t,e),this._fullRefresh())}handleCharSizeChanged(){this._renderer.value?.handleCharSizeChanged()}handleBlur(){this._renderer.value?.handleBlur()}handleFocus(){this._renderer.value?.handleFocus()}handleSelectionChanged(t,e,s){this._selectionState.start=t,this._selectionState.end=e,this._selectionState.columnSelectMode=s,this._renderer.value?.handleSelectionChanged(t,e,s)}handleCursorMove(){this._renderer.value?.handleCursorMove()}clear(){this._renderer.value?.clear()}};Ga=Ye([ce(2,Bt),ce(3,vo),ce(4,Ci),ce(5,tn),ce(6,Lt),ce(7,Hs),ce(8,Xi)],Ga);var q3=class{constructor(t,e,s){this._coreBrowserService=t,this._coreService=e,this._onTimeout=s,this._start=0,this._end=0,this._isBuffering=!1}bufferRows(t,e){this._isBuffering?(this._start=Math.min(this._start,t),this._end=Math.max(this._end,e)):(this._start=t,this._end=e,this._isBuffering=!0),this._timeout===void 0&&(this._timeout=this._coreBrowserService.window.setTimeout(()=>{this._timeout=void 0,this._coreService.decPrivateModes.synchronizedOutput=!1,this._onTimeout()},1e3))}flush(){if(this._timeout!==void 0&&(this._coreBrowserService.window.clearTimeout(this._timeout),this._timeout=void 0),!this._isBuffering)return;let t={start:this._start,end:this._end};return this._isBuffering=!1,t}dispose(){this._timeout!==void 0&&(this._coreBrowserService.window.clearTimeout(this._timeout),this._timeout=void 0)}};function G3(t,e,s,i){let n=s.buffer.x,o=s.buffer.y;if(!s.buffer.hasScrollback)return J3(n,o,t,e,s,i)+yo(o,e,s,i)+Q3(n,o,t,e,s,i);let a;if(o===e)return a=n>t?"D":"C",Pr(Math.abs(n-t),Mr(a,i));a=o>e?"D":"C";let l=Math.abs(o-e),c=X3(o>e?t:n,s)+(l-1)*s.cols+1+Y3(o>e?n:t);return Pr(c,Mr(a,i))}function Y3(t,e){return t-1}function X3(t,e){return e.cols-t}function J3(t,e,s,i,n,o){return yo(e,i,n,o).length===0?"":Pr(Rm(t,e,t,e-xi(e,n),!1,n).length,Mr("D",o))}function yo(t,e,s,i){let n=t-xi(t,s),o=e-xi(e,s),a=Math.abs(n-o)-Z3(t,e,s);return Pr(a,Mr(Im(t,e),i))}function Q3(t,e,s,i,n,o){let a;yo(e,i,n,o).length>0?a=i-xi(i,n):a=e;let l=i,c=ej(t,e,s,i,n,o);return Pr(Rm(t,a,s,l,c==="C",n).length,Mr(c,o))}function Z3(t,e,s){let i=0,n=t-xi(t,s),o=e-xi(e,s);for(let a=0;a<Math.abs(n-o);a++){let l=Im(t,e)==="A"?-1:1;s.buffer.lines.get(n+l*a)?.isWrapped&&i++}return i}function xi(t,e){let s=0,i=e.buffer.lines.get(t),n=i?.isWrapped;for(;n&&t>=0&&t<e.rows;)s++,i=e.buffer.lines.get(--t),n=i?.isWrapped;return s}function ej(t,e,s,i,n,o){let a;return yo(s,i,n,o).length>0?a=i-xi(i,n):a=e,t<s&&a<=i||t>=s&&a<i?"C":"D"}function Im(t,e){return t>e?"A":"B"}function Rm(t,e,s,i,n,o){let a=t,l=e,c="";for(;(a!==s||l!==i)&&l>=0&&l<o.buffer.lines.length;)a+=n?1:-1,n&&a>o.cols-1?(c+=o.buffer.translateBufferLineToString(l,!1,t,a),a=0,t=0,l++):!n&&a<0&&(c+=o.buffer.translateBufferLineToString(l,!1,0,t+1),a=o.cols-1,t=a,l--);return c+o.buffer.translateBufferLineToString(l,!1,t,a)}function Mr(t,e){let s=e?"O":"[";return Z.ESC+s+t}function Pr(t,e){t=Math.floor(t);let s="";for(let i=0;i<t;i++)s+=e;return s}var tj=class{constructor(t){this._bufferService=t,this.isSelectAllActive=!1,this.selectionStartLength=0}clearSelection(){this.selectionStart=void 0,this.selectionEnd=void 0,this.isSelectAllActive=!1,this.selectionStartLength=0}get finalSelectionStart(){return this.isSelectAllActive?[0,0]:!this.selectionEnd||!this.selectionStart?this.selectionStart:this.areSelectionValuesReversed()?this.selectionEnd:this.selectionStart}get finalSelectionEnd(){if(this.isSelectAllActive)return[this._bufferService.cols,this._bufferService.buffer.ybase+this._bufferService.rows-1];if(this.selectionStart){if(!this.selectionEnd||this.areSelectionValuesReversed()){let t=this.selectionStart[0]+this.selectionStartLength;return t>this._bufferService.cols?t%this._bufferService.cols===0?[this._bufferService.cols,this.selectionStart[1]+Math.floor(t/this._bufferService.cols)-1]:[t%this._bufferService.cols,this.selectionStart[1]+Math.floor(t/this._bufferService.cols)]:[t,this.selectionStart[1]]}if(this.selectionStartLength&&this.selectionEnd[1]===this.selectionStart[1]){let t=this.selectionStart[0]+this.selectionStartLength;return t>this._bufferService.cols?[t%this._bufferService.cols,this.selectionStart[1]+Math.floor(t/this._bufferService.cols)]:[Math.max(t,this.selectionEnd[0]),this.selectionEnd[1]]}return this.selectionEnd}}areSelectionValuesReversed(){let t=this.selectionStart,e=this.selectionEnd;return!t||!e?!1:t[1]>e[1]||t[1]===e[1]&&t[0]>e[0]}handleTrim(t){return this.selectionStart&&(this.selectionStart[1]-=t),this.selectionEnd&&(this.selectionEnd[1]-=t),this.selectionEnd&&this.selectionEnd[1]<0?(this.clearSelection(),!0):(this.selectionStart&&this.selectionStart[1]<0&&(this.selectionStart[1]=0),!1)}};function Fd(t,e){if(t.start.y>t.end.y)throw new Error(`Buffer range end (${t.end.x}, ${t.end.y}) cannot be before start (${t.start.x}, ${t.start.y})`);return e*(t.end.y-t.start.y)+(t.end.x-t.start.x+1)}var Go=50,sj=15,ij=50,rj=500,nj=" ",oj=new RegExp(nj,"g"),Ya=class extends Ve{constructor(t,e,s,i,n,o,a,l,c){super(),this._element=t,this._screenElement=e,this._linkifier=s,this._bufferService=i,this._coreService=n,this._mouseService=o,this._optionsService=a,this._renderService=l,this._coreBrowserService=c,this._dragScrollAmount=0,this._enabled=!0,this._workCell=new as,this._mouseDownTimeStamp=0,this._oldHasSelection=!1,this._oldSelectionStart=void 0,this._oldSelectionEnd=void 0,this._onLinuxMouseSelection=this._register(new re),this.onLinuxMouseSelection=this._onLinuxMouseSelection.event,this._onRedrawRequest=this._register(new re),this.onRequestRedraw=this._onRedrawRequest.event,this._onSelectionChange=this._register(new re),this.onSelectionChange=this._onSelectionChange.event,this._onRequestScrollLines=this._register(new re),this.onRequestScrollLines=this._onRequestScrollLines.event,this._mouseMoveListener=d=>this._handleMouseMove(d),this._mouseUpListener=d=>this._handleMouseUp(d),this._coreService.onUserInput(()=>{this.hasSelection&&this.clearSelection()}),this._trimListener=this._bufferService.buffer.lines.onTrim(d=>this._handleTrim(d)),this._register(this._bufferService.buffers.onBufferActivate(d=>this._handleBufferActivate(d))),this.enable(),this._model=new tj(this._bufferService),this._activeSelectionMode=0,this._register(Fe(()=>{this._removeMouseDownListeners()})),this._register(this._bufferService.onResize(d=>{d.rowsChanged&&this.clearSelection()}))}reset(){this.clearSelection()}disable(){this.clearSelection(),this._enabled=!1}enable(){this._enabled=!0}get selectionStart(){return this._model.finalSelectionStart}get selectionEnd(){return this._model.finalSelectionEnd}get hasSelection(){let t=this._model.finalSelectionStart,e=this._model.finalSelectionEnd;return!t||!e?!1:t[0]!==e[0]||t[1]!==e[1]}get selectionText(){let t=this._model.finalSelectionStart,e=this._model.finalSelectionEnd;if(!t||!e)return"";let s=this._bufferService.buffer,i=[];if(this._activeSelectionMode===3){if(t[0]===e[0])return"";let n=t[0]<e[0]?t[0]:e[0],o=t[0]<e[0]?e[0]:t[0];for(let a=t[1];a<=e[1];a++){let l=s.translateBufferLineToString(a,!0,n,o);i.push(l)}}else{let n=t[1]===e[1]?e[0]:void 0;i.push(s.translateBufferLineToString(t[1],!0,t[0],n));for(let o=t[1]+1;o<=e[1]-1;o++){let a=s.lines.get(o),l=s.translateBufferLineToString(o,!0);a?.isWrapped?i[i.length-1]+=l:i.push(l)}if(t[1]!==e[1]){let o=s.lines.get(e[1]),a=s.translateBufferLineToString(e[1],!0,0,e[0]);o&&o.isWrapped?i[i.length-1]+=a:i.push(a)}}return i.map(n=>n.replace(oj," ")).join(Nm?`\r
439
439
  `:`
440
- `)}clearSelection(){this._model.clearSelection(),this._removeMouseDownListeners(),this.refresh(),this._onSelectionChange.fire()}refresh(t){this._refreshAnimationFrame||(this._refreshAnimationFrame=this._coreBrowserService.window.requestAnimationFrame(()=>this._refresh())),oc&&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=Fd(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=nc(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,-Go),Go),e/=Go,e/Math.abs(e)+Math.round(e*(Z3-1)))}shouldForceSelection(t){return Xn?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(),ej)}_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&&!(Xn&&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<tj&&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=U3(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 n=t.loadCell(i,this._workCell).getChars().length;this._workCell.getWidth()===0?s--:n>1&&e!==i&&(s+=n-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 n=this._bufferService.buffer,o=n.lines.get(t[1]);if(!o)return;let a=n.translateBufferLineToString(t[1],!1),l=this._convertViewportColToCharacterIndex(o,t[0]),c=l,d=t[0]-l,u=0,h=0,f=0,m=0;if(a.charAt(l)===" "){for(;l>0&&a.charAt(l-1)===" ";)l--;for(;c<a.length&&a.charAt(c+1)===" ";)c++}else{let _=t[0],v=t[0];o.getWidth(_)===0&&(u++,_--),o.getWidth(v)===2&&(h++,v++);let x=o.getString(v).length;for(x>1&&(m+=x-1,c+=x-1);_>0&&l>0&&!this._isCharWordSeparator(o.loadCell(_-1,this._workCell));){o.loadCell(_-1,this._workCell);let b=this._workCell.getChars().length;this._workCell.getWidth()===0?(u++,_--):b>1&&(f+=b-1,l-=b-1),l--,_--}for(;v<o.length&&c+1<a.length&&!this._isCharWordSeparator(o.loadCell(v+1,this._workCell));){o.loadCell(v+1,this._workCell);let b=this._workCell.getChars().length;this._workCell.getWidth()===2?(h++,v++):b>1&&(m+=b-1,c+=b-1),c++,v++}}c++;let p=l+d-u+f,g=Math.min(this._bufferService.cols,c-l+u+h-f-m);if(!(!e&&a.slice(l,c).trim()==="")){if(s&&p===0&&o.getCodePoint(0)!==32){let _=n.lines.get(t[1]-1);if(_&&o.isWrapped&&_.getCodePoint(this._bufferService.cols-1)!==32){let v=this._getWordAt([this._bufferService.cols-1,t[1]-1],!1,!0,!1);if(v){let x=this._bufferService.cols-v.start;p-=x,g+=x}}}if(i&&p+g===this._bufferService.cols&&o.getCodePoint(this._bufferService.cols-1)!==32){let _=n.lines.get(t[1]+1);if(_?.isWrapped&&_.getCodePoint(0)!==32){let v=this._getWordAt([0,t[1]+1],!1,!1,!0);v&&(g+=v.length)}}return{start:p,length:g}}}_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=Fd(s,this._bufferService.cols)}};Ya=Ye([ce(3,Lt),ce(4,Ci),ce(5,Ql),ce(6,Bt),ce(7,Ws),ce(8,Hs)],Ya);var Hd=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={}}},Wd=class{constructor(){this._color=new Hd,this._css=new Hd}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()}},rt=Object.freeze((()=>{let t=[Ue.toColor("#2e3436"),Ue.toColor("#cc0000"),Ue.toColor("#4e9a06"),Ue.toColor("#c4a000"),Ue.toColor("#3465a4"),Ue.toColor("#75507b"),Ue.toColor("#06989a"),Ue.toColor("#d3d7cf"),Ue.toColor("#555753"),Ue.toColor("#ef2929"),Ue.toColor("#8ae234"),Ue.toColor("#fce94f"),Ue.toColor("#729fcf"),Ue.toColor("#ad7fa8"),Ue.toColor("#34e2e2"),Ue.toColor("#eeeeec")],e=[0,95,135,175,215,255];for(let s=0;s<216;s++){let i=e[s/36%6|0],n=e[s/6%6|0],o=e[s%6];t.push({css:et.toCss(i,n,o),rgba:et.toRgba(i,n,o)})}for(let s=0;s<24;s++){let i=8+s*10;t.push({css:et.toCss(i,i,i),rgba:et.toRgba(i,i,i)})}return t})()),hi=Ue.toColor("#ffffff"),hr=Ue.toColor("#000000"),Ud=Ue.toColor("#ffffff"),Kd=hr,nr={css:"rgba(255, 255, 255, 0.3)",rgba:4294967117},rj=hi,Xa=class extends Ve{constructor(t){super(),this._optionsService=t,this._contrastCache=new Wd,this._halfContrastCache=new Wd,this._onChangeColors=this._register(new re),this.onChangeColors=this._onChangeColors.event,this._colors={foreground:hi,background:hr,cursor:Ud,cursorAccent:Kd,selectionForeground:void 0,selectionBackgroundTransparent:nr,selectionBackgroundOpaque:Le.blend(hr,nr),selectionInactiveBackgroundTransparent:nr,selectionInactiveBackgroundOpaque:Le.blend(hr,nr),scrollbarSliderBackground:Le.opacity(hi,.2),scrollbarSliderHoverBackground:Le.opacity(hi,.4),scrollbarSliderActiveBackground:Le.opacity(hi,.5),overviewRulerBorder:hi,ansi:rt.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=Re(t.foreground,hi),e.background=Re(t.background,hr),e.cursor=Le.blend(e.background,Re(t.cursor,Ud)),e.cursorAccent=Le.blend(e.background,Re(t.cursorAccent,Kd)),e.selectionBackgroundTransparent=Re(t.selectionBackground,nr),e.selectionBackgroundOpaque=Le.blend(e.background,e.selectionBackgroundTransparent),e.selectionInactiveBackgroundTransparent=Re(t.selectionInactiveBackground,e.selectionBackgroundTransparent),e.selectionInactiveBackgroundOpaque=Le.blend(e.background,e.selectionInactiveBackgroundTransparent),e.selectionForeground=t.selectionForeground?Re(t.selectionForeground,Od):void 0,e.selectionForeground===Od&&(e.selectionForeground=void 0),Le.isOpaque(e.selectionBackgroundTransparent)&&(e.selectionBackgroundTransparent=Le.opacity(e.selectionBackgroundTransparent,.3)),Le.isOpaque(e.selectionInactiveBackgroundTransparent)&&(e.selectionInactiveBackgroundTransparent=Le.opacity(e.selectionInactiveBackgroundTransparent,.3)),e.scrollbarSliderBackground=Re(t.scrollbarSliderBackground,Le.opacity(e.foreground,.2)),e.scrollbarSliderHoverBackground=Re(t.scrollbarSliderHoverBackground,Le.opacity(e.foreground,.4)),e.scrollbarSliderActiveBackground=Re(t.scrollbarSliderActiveBackground,Le.opacity(e.foreground,.5)),e.overviewRulerBorder=Re(t.overviewRulerBorder,rj),e.ansi=rt.slice(),e.ansi[0]=Re(t.black,rt[0]),e.ansi[1]=Re(t.red,rt[1]),e.ansi[2]=Re(t.green,rt[2]),e.ansi[3]=Re(t.yellow,rt[3]),e.ansi[4]=Re(t.blue,rt[4]),e.ansi[5]=Re(t.magenta,rt[5]),e.ansi[6]=Re(t.cyan,rt[6]),e.ansi[7]=Re(t.white,rt[7]),e.ansi[8]=Re(t.brightBlack,rt[8]),e.ansi[9]=Re(t.brightRed,rt[9]),e.ansi[10]=Re(t.brightGreen,rt[10]),e.ansi[11]=Re(t.brightYellow,rt[11]),e.ansi[12]=Re(t.brightBlue,rt[12]),e.ansi[13]=Re(t.brightMagenta,rt[13]),e.ansi[14]=Re(t.brightCyan,rt[14]),e.ansi[15]=Re(t.brightWhite,rt[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]=Re(t.extendedAnsi[i],rt[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()}}};Xa=Ye([ce(0,Bt)],Xa);function Re(t,e){if(t!==void 0)try{return Ue.toColor(t)}catch{}return e}var nj=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)}},oj=class{constructor(){this._services=new nj,this._services.set(Jl,this)}setService(t,e){this._services.set(t,e)}getService(t){return this._services.get(t)}createInstance(t,...e){let s=ZV(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 n=s.length>0?s[0].index:e.length;if(e.length!==n)throw new Error(`[createInstance] First service dependency of ${t.name} at position ${n+1} conflicts with ${e.length} static arguments`);return new t(...e,...i)}},aj={trace:0,debug:1,info:2,warn:3,error:4,off:5},lj="xterm.js: ",Ja=class extends Ve{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=aj[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?"":lj)+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)}};Ja=Ye([ce(0,Bt)],Ja);var qd=class extends Ve{constructor(t){super(),this._maxLength=t,this.onDeleteEmitter=this._register(new re),this.onDelete=this.onDeleteEmitter.event,this.onInsertEmitter=this._register(new re),this.onInsert=this.onInsertEmitter.event,this.onTrimEmitter=this._register(new re),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 n=e-1;n>=0;n--)this.set(t+n+s,this.get(t+n));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}},we=3,Ze=Object.freeze(new en),xn=0,Yo=2,ur=class Rm{constructor(e,s,i=!1){this.isWrapped=i,this._combined={},this._extendedAttrs={},this._data=new Uint32Array(e*we);let n=s||as.fromCharData([0,Jf,1,0]);for(let o=0;o<e;++o)this.setCell(o,n);this.length=e}get(e){let s=this._data[e*we+0],i=s&2097151;return[this._data[e*we+1],s&2097152?this._combined[e]:i?Ys(i):"",s>>22,s&2097152?this._combined[e].charCodeAt(this._combined[e].length-1):i]}set(e,s){this._data[e*we+1]=s[0],s[1].length>1?(this._combined[e]=s[1],this._data[e*we+0]=e|2097152|s[2]<<22):this._data[e*we+0]=s[1].charCodeAt(0)|s[2]<<22}getWidth(e){return this._data[e*we+0]>>22}hasWidth(e){return this._data[e*we+0]&12582912}getFg(e){return this._data[e*we+1]}getBg(e){return this._data[e*we+2]}hasContent(e){return this._data[e*we+0]&4194303}getCodePoint(e){let s=this._data[e*we+0];return s&2097152?this._combined[e].charCodeAt(this._combined[e].length-1):s&2097151}isCombined(e){return this._data[e*we+0]&2097152}getString(e){let s=this._data[e*we+0];return s&2097152?this._combined[e]:s&2097151?Ys(s&2097151):""}isProtected(e){return this._data[e*we+2]&536870912}loadCell(e,s){return xn=e*we,s.content=this._data[xn+0],s.fg=this._data[xn+1],s.bg=this._data[xn+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*we+0]=s.content,this._data[e*we+1]=s.fg,this._data[e*we+2]=s.bg}setCellFromCodepoint(e,s,i,n){n.bg&268435456&&(this._extendedAttrs[e]=n.extended),this._data[e*we+0]=s|i<<22,this._data[e*we+1]=n.fg,this._data[e*we+2]=n.bg}addCodepointToCell(e,s,i){let n=this._data[e*we+0];n&2097152?this._combined[e]+=Ys(s):n&2097151?(this._combined[e]=Ys(n&2097151)+Ys(s),n&=-2097152,n|=2097152):n=s|1<<22,i&&(n&=-12582913,n|=i<<22),this._data[e*we+0]=n}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 n=new as;for(let o=this.length-e-s-1;o>=0;--o)this.setCell(e+s+o,this.loadCell(e+o,n));for(let o=0;o<s;++o)this.setCell(e+o,i)}else for(let n=e;n<this.length;++n)this.setCell(n,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 n=new as;for(let o=0;o<this.length-e-s;++o)this.setCell(e+o,this.loadCell(e+s+o,n));for(let o=this.length-s;o<this.length;++o)this.setCell(o,i)}else for(let n=e;n<this.length;++n)this.setCell(n,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,n=!1){if(n){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*Yo<this._data.buffer.byteLength;let i=e*we;if(e>this.length){if(this._data.buffer.byteLength>=i*4)this._data=new Uint32Array(this._data.buffer,0,i);else{let n=new Uint32Array(i);n.set(this._data),this._data=n}for(let n=this.length;n<e;++n)this.setCell(n,s)}else{this._data=this._data.subarray(0,i);let n=Object.keys(this._combined);for(let a=0;a<n.length;a++){let l=parseInt(n[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*Yo<this._data.buffer.byteLength}cleanupMemory(){if(this._data.length*4*Yo<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 Rm(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*we+0]&4194303)return e+(this._data[e*we+0]>>22);return 0}getNoBgTrimmedLength(){for(let e=this.length-1;e>=0;--e)if(this._data[e*we+0]&4194303||this._data[e*we+2]&50331648)return e+(this._data[e*we+0]>>22);return 0}copyCellsFrom(e,s,i,n,o){let a=e._data;if(o)for(let c=n-1;c>=0;c--){for(let d=0;d<we;d++)this._data[(i+c)*we+d]=a[(s+c)*we+d];a[(s+c)*we+2]&268435456&&(this._extendedAttrs[i+c]=e._extendedAttrs[s+c])}else for(let c=0;c<n;c++){for(let d=0;d<we;d++)this._data[(i+c)*we+d]=a[(s+c)*we+d];a[(s+c)*we+2]&268435456&&(this._extendedAttrs[i+c]=e._extendedAttrs[s+c])}let l=Object.keys(e._combined);for(let c=0;c<l.length;c++){let d=parseInt(l[c],10);d>=s&&(this._combined[d-s+i]=e._combined[d])}}translateToString(e,s,i,n){s=s??0,i=i??this.length,e&&(i=Math.min(i,this.getTrimmedLength())),n&&(n.length=0);let o="";for(;s<i;){let a=this._data[s*we+0],l=a&2097151,c=a&2097152?this._combined[s]:l?Ys(l):Xs;if(o+=c,n)for(let d=0;d<c.length;++d)n.push(s);s+=a>>22||1}return n&&n.push(s),o}};function cj(t,e,s,i,n,o){let a=[];for(let l=0;l<t.length-1;l++){let c=l,d=t.get(++c);if(!d.isWrapped)continue;let u=[t.get(l)];for(;c<t.length&&d.isWrapped;)u.push(d),d=t.get(++c);if(!o&&i>=l&&i<c){l+=u.length-1;continue}let h=0,f=Lr(u,h,e),m=1,p=0;for(;m<u.length;){let _=Lr(u,m,e),v=_-p,x=s-f,b=Math.min(v,x);u[h].copyCellsFrom(u[m],p,f,b,!1),f+=b,f===s&&(h++,f=0),p+=b,p===_&&(m++,p=0),f===0&&h!==0&&u[h-1].getWidth(s-1)===2&&(u[h].copyCellsFrom(u[h-1],s-1,f++,1,!1),u[h-1].setCell(s-1,n))}u[h].replaceCells(f,s,n);let g=0;for(let _=u.length-1;_>0&&(_>h||u[_].getTrimmedLength()===0);_--)g++;g>0&&(a.push(l+u.length-g),a.push(g)),l+=u.length-1}return a}function dj(t,e){let s=[],i=0,n=e[i],o=0;for(let a=0;a<t.length;a++)if(n===a){let l=e[++i];t.onDeleteEmitter.fire({index:a-o,amount:l}),a+=l-1,o+=l,n=e[++i]}else s.push(a);return{layout:s,countRemoved:o}}function hj(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 uj(t,e,s){let i=[],n=t.map((c,d)=>Lr(t,d,e)).reduce((c,d)=>c+d),o=0,a=0,l=0;for(;l<n;){if(n-l<s){i.push(n-l);break}o+=s;let c=Lr(t,a,e);o>c&&(o-=c,a++);let d=t[a].getWidth(o-1)===2;d&&o--;let u=d?s-1:s;i.push(u),l+=u}return i}function Lr(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,n=t[e+1].getWidth(0)===2;return i&&n?s-1:s}var Tm=class Dm{constructor(e){this.line=e,this.isDisposed=!1,this._disposables=[],this._id=Dm._nextId++,this._onDispose=this.register(new re),this.onDispose=this._onDispose.event}get id(){return this._id}dispose(){this.isDisposed||(this.isDisposed=!0,this.line=-1,this._onDispose.fire(),_i(this._disposables),this._disposables.length=0)}register(e){return this._disposables.push(e),e}};Tm._nextId=1;var fj=Tm,ct={},ui=ct.B;ct[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:"≥","{":"π","|":"≠","}":"£","~":"·"};ct.A={"#":"£"};ct.B=void 0;ct[4]={"#":"£","@":"¾","[":"ij","\\":"½","]":"|","{":"¨","|":"f","}":"¼","~":"´"};ct.C=ct[5]={"[":"Ä","\\":"Ö","]":"Å","^":"Ü","`":"é","{":"ä","|":"ö","}":"å","~":"ü"};ct.R={"#":"£","@":"à","[":"°","\\":"ç","]":"§","{":"é","|":"ù","}":"è","~":"¨"};ct.Q={"@":"à","[":"â","\\":"ç","]":"ê","^":"î","`":"ô","{":"é","|":"ù","}":"è","~":"û"};ct.K={"@":"§","[":"Ä","\\":"Ö","]":"Ü","{":"ä","|":"ö","}":"ü","~":"ß"};ct.Y={"#":"£","@":"§","[":"°","\\":"ç","]":"é","`":"ù","{":"à","|":"ò","}":"è","~":"ì"};ct.E=ct[6]={"@":"Ä","[":"Æ","\\":"Ø","]":"Å","^":"Ü","`":"ä","{":"æ","|":"ø","}":"å","~":"ü"};ct.Z={"#":"£","@":"§","[":"¡","\\":"Ñ","]":"¿","{":"°","|":"ñ","}":"ç"};ct.H=ct[7]={"@":"É","[":"Ä","\\":"Ö","]":"Å","^":"Ü","`":"é","{":"ä","|":"ö","}":"å","~":"ü"};ct["="]={"#":"ù","@":"à","[":"é","\\":"ç","]":"ê","^":"î",_:"è","`":"ô","{":"ä","|":"ö","}":"ü","~":"û"};var Gd=4294967295,Yd=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=Ze.clone(),this.savedCharset=ui,this.markers=[],this._nullCell=as.fromCharData([0,Jf,1,0]),this._whitespaceCell=as.fromCharData([0,Xs,1,32]),this._isClearing=!1,this._memoryCleanupQueue=new Jn,this._memoryCleanupPosition=0,this._cols=this._bufferService.cols,this._rows=this._bufferService.rows,this.lines=new qd(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 qn),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 qn),this._whitespaceCell}getBlankLine(t,e){return new ur(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>Gd?Gd:e}fillViewportRows(t){if(this.lines.length===0){t===void 0&&(t=Ze);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 qd(this._getCorrectBufferLength(this._rows)),this.scrollTop=0,this.scrollBottom=this._rows-1,this.setupTabStops()}resize(t,e){let s=this.getNullCell(Ze),i=0,n=this._getCorrectBufferLength(e);if(n>this.lines.maxLength&&(this.lines.maxLength=n),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 ur(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 ur(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(n<this.lines.maxLength){let a=this.lines.length-n;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=n}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=cj(this.lines,this._cols,t,this.ybase+this.y,this.getNullCell(Ze),s);if(i.length>0){let n=dj(this.lines,i);hj(this.lines,n.layout),this._reflowLargerAdjustViewport(t,e,n.countRemoved)}}_reflowLargerAdjustViewport(t,e,s){let i=this.getNullCell(Ze),n=s;for(;n-- >0;)this.ybase===0?(this.y>0&&this.y--,this.lines.length<e&&this.lines.push(new ur(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(Ze),n=[],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 c=[l];for(;l.isWrapped&&a>0;)l=this.lines.get(--a),c.unshift(l);if(!s){let b=this.ybase+this.y;if(b>=a&&b<a+c.length)continue}let d=c[c.length-1].getTrimmedLength(),u=uj(c,this._cols,t),h=u.length-c.length,f;this.ybase===0&&this.y!==this.lines.length-1?f=Math.max(0,this.y-this.lines.maxLength+h):f=Math.max(0,this.lines.length-this.lines.maxLength+h);let m=[];for(let b=0;b<h;b++){let y=this.getBlankLine(Ze,!0);m.push(y)}m.length>0&&(n.push({start:a+c.length+o,newLines:m}),o+=m.length),c.push(...m);let p=u.length-1,g=u[p];g===0&&(p--,g=u[p]);let _=c.length-h-1,v=d;for(;_>=0;){let b=Math.min(v,g);if(c[p]===void 0)break;if(c[p].copyCellsFrom(c[_],v-b,g-b,b,!0),g-=b,g===0&&(p--,g=u[p]),v-=b,v===0){_--;let y=Math.max(_,0);v=Lr(c,y,this._cols)}}for(let b=0;b<c.length;b++)u[b]<t&&c[b].setCell(u[b],i);let x=h-f;for(;x-- >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+h,this.ybase+e-1)}if(n.length>0){let a=[],l=[];for(let g=0;g<this.lines.length;g++)l.push(this.lines.get(g));let c=this.lines.length,d=c-1,u=0,h=n[u];this.lines.length=Math.min(this.lines.maxLength,this.lines.length+o);let f=0;for(let g=Math.min(this.lines.maxLength-1,c+o-1);g>=0;g--)if(h&&h.start>d+f){for(let _=h.newLines.length-1;_>=0;_--)this.lines.set(g--,h.newLines[_]);g++,a.push({index:d+1,amount:h.newLines.length}),f+=h.newLines.length,h=n[++u]}else this.lines.set(g,l[d--]);let m=0;for(let g=a.length-1;g>=0;g--)a[g].index+=m,this.lines.onInsertEmitter.fire(a[g]),m+=a[g].amount;let p=Math.max(0,c+o-this.lines.maxLength);p>0&&this.lines.onTrimEmitter.fire(p)}}translateBufferLineToString(t,e,s=0,i){let n=this.lines.get(t);return n?n.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 fj(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)}},mj=class extends Ve{constructor(t,e){super(),this._optionsService=t,this._bufferService=e,this._onBufferActivate=this._register(new re),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 Yd(!0,this._optionsService,this._bufferService),this._normal.fillViewportRows(),this._alt=new Yd(!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)}},Mm=2,Pm=1,Qa=class extends Ve{constructor(t){super(),this.isUserScrolling=!1,this._onResize=this._register(new re),this.onResize=this._onResize.event,this._onScroll=this._register(new re),this.onScroll=this._onScroll.event,this.cols=Math.max(t.rawOptions.cols||0,Mm),this.rows=Math.max(t.rawOptions.rows||0,Pm),this.buffers=this._register(new mj(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 n=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-n+1;s.lines.shiftElements(n+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))}};Qa=Ye([ce(0,Bt)],Qa);var Ni={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:Xn,windowOptions:{},windowsMode:!1,windowsPty:{},wordSeparator:" ()[]{}',\"`",altClickMovesCursor:!0,convertEol:!1,termName:"xterm",cancelEvents:!1,overviewRuler:{}},pj=["normal","bold","100","200","300","400","500","600","700","800","900"],gj=class extends Ve{constructor(t){super(),this._onOptionChange=this._register(new re),this.onOptionChange=this._onOptionChange.event;let e={...Ni};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(Fe(()=>{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 Ni))throw new Error(`No option with key "${s}"`);return this.rawOptions[s]},e=(s,i)=>{if(!(s in Ni))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=Ni[t]),!_j(e))throw new Error(`"${e}" is not a valid value for ${t}`);break;case"wordSeparator":e||(e=Ni[t]);break;case"fontWeight":case"fontWeightBold":if(typeof e=="number"&&1<=e&&e<=1e3)break;e=pj.includes(e)?e:Ni[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 _j(t){return t==="block"||t==="underline"||t==="bar"}function fr(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]&&fr(t[i],e-1);return s}var Xd=Object.freeze({insertMode:!1}),Jd=Object.freeze({applicationCursorKeys:!1,applicationKeypad:!1,bracketedPasteMode:!1,cursorBlink:void 0,cursorStyle:void 0,origin:!1,reverseWraparound:!1,sendFocus:!1,synchronizedOutput:!1,wraparound:!0}),Za=class extends Ve{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 re),this.onData=this._onData.event,this._onUserInput=this._register(new re),this.onUserInput=this._onUserInput.event,this._onBinary=this._register(new re),this.onBinary=this._onBinary.event,this._onRequestScrollToBottom=this._register(new re),this.onRequestScrollToBottom=this._onRequestScrollToBottom.event,this.modes=fr(Xd),this.decPrivateModes=fr(Jd)}reset(){this.modes=fr(Xd),this.decPrivateModes=fr(Jd)}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))}};Za=Ye([ce(0,Lt),ce(1,sm),ce(2,Bt)],Za);var Qd={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 Xo(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 Jo=String.fromCharCode,Zd={DEFAULT:t=>{let e=[Xo(t,!1)+32,t.col+32,t.row+32];return e[0]>255||e[1]>255||e[2]>255?"":`\x1B[M${Jo(e[0])}${Jo(e[1])}${Jo(e[2])}`},SGR:t=>{let e=t.action===0&&t.button!==4?"m":"M";return`\x1B[<${Xo(t,!0)};${t.col};${t.row}${e}`},SGR_PIXELS:t=>{let e=t.action===0&&t.button!==4?"m":"M";return`\x1B[<${Xo(t,!0)};${t.x};${t.y}${e}`}},el=class extends Ve{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 re),this.onProtocolChange=this._onProtocolChange.event;for(let i of Object.keys(Qd))this.addProtocol(i,Qd[i]);for(let i of Object.keys(Zd))this.addEncoding(i,Zd[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,n=this._applyScrollModifier(t.deltaY,t);return t.deltaMode===WheelEvent.DOM_DELTA_PIXEL?(n/=i+0,Math.abs(t.deltaY)<50&&(n*=.3),this._wheelPartialScroll+=n,n=Math.floor(Math.abs(this._wheelPartialScroll))*(this._wheelPartialScroll>0?1:-1),this._wheelPartialScroll%=1):t.deltaMode===WheelEvent.DOM_DELTA_PAGE&&(n*=this._bufferService.rows),n}_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)}};el=Ye([ce(0,Lt),ce(1,Ci),ce(2,Bt)],el);var Qo=[[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]],xj=[[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]],nt;function vj(t,e){let s=0,i=e.length-1,n;if(t<e[0][0]||t>e[i][1])return!1;for(;i>=s;)if(n=s+i>>1,t>e[n][1])s=n+1;else if(t<e[n][0])i=n-1;else return!0;return!1}var bj=class{constructor(){if(this.version="6",!nt){nt=new Uint8Array(65536),nt.fill(1),nt[0]=0,nt.fill(0,1,32),nt.fill(0,127,160),nt.fill(2,4352,4448),nt[9001]=2,nt[9002]=2,nt.fill(2,11904,42192),nt[12351]=1,nt.fill(2,44032,55204),nt.fill(2,63744,64256),nt.fill(2,65040,65050),nt.fill(2,65072,65136),nt.fill(2,65280,65377),nt.fill(2,65504,65511);for(let t=0;t<Qo.length;++t)nt.fill(0,Qo[t][0],Qo[t][1]+1)}}wcwidth(t){return t<32?0:t<127?1:t<65536?nt[t]:vj(t,xj)?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 n=mi.extractWidth(e);n===0?i=!1:n>s&&(s=n)}return mi.createPropertyValue(0,s,i)}},mi=class Dn{constructor(){this._providers=Object.create(null),this._active="",this._onChange=new re,this.onChange=this._onChange.event;let e=new bj;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,n=e.length;for(let o=0;o<n;++o){let a=e.charCodeAt(o);if(55296<=a&&a<=56319){if(++o>=n)return s+this.wcwidth(a);let d=e.charCodeAt(o);56320<=d&&d<=57343?a=(a-55296)*1024+d-56320+65536:s+=this.wcwidth(d)}let l=this.charProperties(a,i),c=Dn.extractWidth(l);Dn.extractShouldJoin(l)&&(c-=Dn.extractWidth(i)),s+=c,i=l}return s}charProperties(e,s){return this._activeProvider.charProperties(e,s)}},yj=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 eh(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 or=2147483647,Sj=256,Lm=class tl{constructor(e=32,s=32){if(this.maxLength=e,this.maxSubParamsLength=s,s>Sj)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 tl;if(!e.length)return s;for(let i=Array.isArray(e[0])?1:0;i<e.length;++i){let n=e[i];if(Array.isArray(n))for(let o=0;o<n.length;++o)s.addSubParam(n[o]);else s.addParam(n)}return s}clone(){let e=new tl(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,n=this._subParamsIdx[s]&255;n-i>0&&e.push(Array.prototype.slice.call(this._subParams,i,n))}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>or?or: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>or?or: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,n=this._subParamsIdx[s]&255;n-i>0&&(e[s]=this._subParams.slice(i,n))}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,n=i[s-1];i[s-1]=~n?Math.min(n*10+e,or):e}},ar=[],wj=class{constructor(){this._state=0,this._active=ar,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=ar}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=ar,this._id=-1,this._state=0}_start(){if(this._active=this._handlers[this._id]||ar,!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",xo(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,n=!1;if(this._stack.paused&&(i=this._stack.loopPosition-1,s=e,n=this._stack.fallThrough,this._stack.paused=!1),!n&&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=ar,this._id=-1,this._state=0}}},Yt=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+=xo(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}},lr=[],Vj=class{constructor(){this._handlers=Object.create(null),this._active=lr,this._ident=0,this._handlerFb=()=>{},this._stack={paused:!1,loopPosition:0,fallThrough:!1}}dispose(){this._handlers=Object.create(null),this._handlerFb=()=>{},this._active=lr}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=lr,this._ident=0}hook(t,e){if(this.reset(),this._ident=t,this._active=this._handlers[t]||lr,!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",xo(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,n=!1;if(this._stack.paused&&(i=this._stack.loopPosition-1,s=e,n=this._stack.fallThrough,this._stack.paused=!1),!n&&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=lr,this._ident=0}},mr=new Lm;mr.addParam(0);var th=class{constructor(t){this._handler=t,this._data="",this._params=mr,this._hitLimit=!1}hook(t){this._params=t.length>1||t.params[0]?t.clone():mr,this._data="",this._hitLimit=!1}put(t,e,s){this._hitLimit||(this._data+=xo(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=mr,this._data="",this._hitLimit=!1,s));return this._params=mr,this._data="",this._hitLimit=!1,e}},Cj=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 n=0;n<t.length;n++)this.table[e<<8|t[n]]=s<<4|i}},os=160,jj=(function(){let t=new Cj(4095),e=Array.apply(null,Array(256)).map((l,c)=>c),s=(l,c)=>e.slice(l,c),i=s(32,127),n=s(0,24);n.push(25),n.push.apply(n,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(n,0,3,0),t.addMany(n,1,3,1),t.add(127,1,0,1),t.addMany(n,8,0,8),t.addMany(n,3,3,3),t.add(127,3,0,3),t.addMany(n,4,3,4),t.add(127,4,0,4),t.addMany(n,6,3,6),t.addMany(n,5,3,5),t.add(127,5,0,5),t.addMany(n,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(n,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(n,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(n,11,0,11),t.addMany(s(32,128),11,0,11),t.addMany(s(28,32),11,0,11),t.addMany(n,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(n,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(n,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(os,0,2,0),t.add(os,8,5,8),t.add(os,6,0,6),t.add(os,11,0,11),t.add(os,13,13,13),t})(),kj=class extends Ve{constructor(t=jj){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 Lm,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(Fe(()=>{this._csiHandlers=Object.create(null),this._executeHandlers=Object.create(null),this._escHandlers=Object.create(null)})),this._oscParser=this._register(new wj),this._dcsParser=this._register(new Vj),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 n=0;n<t.intermediates.length;++n){let o=t.intermediates.charCodeAt(n);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 n=i.indexOf(e);n!==-1&&i.splice(n,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 n=i.indexOf(e);n!==-1&&i.splice(n,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,n){this._parseStack.state=t,this._parseStack.handlers=e,this._parseStack.handlerPos=s,this._parseStack.transition=i,this._parseStack.chunkPos=n}parse(t,e,s){let i=0,n=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,c=this._parseStack.handlerPos-1;switch(this._parseStack.state){case 3:if(s===!1&&c>-1){for(;c>=0&&(a=l[c](this._params),a!==!0);c--)if(a instanceof Promise)return this._parseStack.handlerPos=c,a}this._parseStack.handlers=[];break;case 4:if(s===!1&&c>-1){for(;c>=0&&(a=l[c](),a!==!0);c--)if(a instanceof Promise)return this._parseStack.handlerPos=c,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],n=this._transitions.table[this.currentState<<8|(i<160?i:os)],n>>4){case 2:for(let f=l+1;;++f){if(f>=e||(i=t[f])<32||i>126&&i<os){this._printHandler(t,l,f),l=f-1;break}if(++f>=e||(i=t[f])<32||i>126&&i<os){this._printHandler(t,l,f),l=f-1;break}if(++f>=e||(i=t[f])<32||i>126&&i<os){this._printHandler(t,l,f),l=f-1;break}if(++f>=e||(i=t[f])<32||i>126&&i<os){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 c=this._csiHandlers[this._collect<<8|i],d=c?c.length-1:-1;for(;d>=0&&(a=c[d](this._params),a!==!0);d--)if(a instanceof Promise)return this._preserveStack(3,c,d,n,l),a;d<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 u=this._escHandlers[this._collect<<8|i],h=u?u.length-1:-1;for(;h>=0&&(a=u[h](),a!==!0);h--)if(a instanceof Promise)return this._preserveStack(4,u,h,n,l),a;h<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<os){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,n,l),a;i===27&&(n|=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<os){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,n,l),a;i===27&&(n|=1),this._params.reset(),this._params.addParam(0),this._collect=0,this.precedingJoinState=0;break}this.currentState=n&15}}},Nj=/^([\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})$/,Aj=/^[\da-f]+$/;function sh(t){if(!t)return;let e=t.toLowerCase();if(e.indexOf("rgb:")===0){e=e.slice(4);let s=Nj.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),Aj.exec(e)&&[3,6,9,12].includes(e.length))){let s=e.length/3,i=[0,0,0];for(let n=0;n<3;++n){let o=parseInt(e.slice(s*n,s*n+s),16);i[n]=s===1?o<<4:s===2?o:s===3?o>>4:o>>8}return i}}function Zo(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 Ej(t,e=16){let[s,i,n]=t;return`rgb:${Zo(s,e)}/${Zo(i,e)}/${Zo(n,e)}`}var Ij={"(":0,")":1,"*":2,"+":3,"-":1,".":2},qs=131072,ih=10;function rh(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 nh=5e3,oh=0,Rj=class extends Ve{constructor(t,e,s,i,n,o,a,l,c=new kj){super(),this._bufferService=t,this._charsetService=e,this._coreService=s,this._logService=i,this._optionsService=n,this._oscLinkService=o,this._coreMouseService=a,this._unicodeService=l,this._parser=c,this._parseBuffer=new Uint32Array(4096),this._stringDecoder=new JV,this._utf8Decoder=new QV,this._windowTitle="",this._iconName="",this._windowTitleStack=[],this._iconNameStack=[],this._curAttrData=Ze.clone(),this._eraseAttrDataInternal=Ze.clone(),this._onRequestBell=this._register(new re),this.onRequestBell=this._onRequestBell.event,this._onRequestRefreshRows=this._register(new re),this.onRequestRefreshRows=this._onRequestRefreshRows.event,this._onRequestReset=this._register(new re),this.onRequestReset=this._onRequestReset.event,this._onRequestSendFocus=this._register(new re),this.onRequestSendFocus=this._onRequestSendFocus.event,this._onRequestSyncScrollBar=this._register(new re),this.onRequestSyncScrollBar=this._onRequestSyncScrollBar.event,this._onRequestWindowsOptionsReport=this._register(new re),this.onRequestWindowsOptionsReport=this._onRequestWindowsOptionsReport.event,this._onA11yChar=this._register(new re),this.onA11yChar=this._onA11yChar.event,this._onA11yTab=this._register(new re),this.onA11yTab=this._onA11yTab.event,this._onCursorMove=this._register(new re),this.onCursorMove=this._onCursorMove.event,this._onLineFeed=this._register(new re),this.onLineFeed=this._onLineFeed.event,this._onScroll=this._register(new re),this.onScroll=this._onScroll.event,this._onTitleChange=this._register(new re),this.onTitleChange=this._onTitleChange.event,this._onColor=this._register(new re),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 sl(this._bufferService),this._activeBuffer=this._bufferService.buffer,this._register(this._bufferService.buffers.onBufferActivate(d=>this._activeBuffer=d.activeBuffer)),this._parser.setCsiHandlerFallback((d,u)=>{this._logService.debug("Unknown CSI code: ",{identifier:this._parser.identToString(d),params:u.toArray()})}),this._parser.setEscHandlerFallback(d=>{this._logService.debug("Unknown ESC code: ",{identifier:this._parser.identToString(d)})}),this._parser.setExecuteHandlerFallback(d=>{this._logService.debug("Unknown EXECUTE code: ",{code:d})}),this._parser.setOscHandlerFallback((d,u,h)=>{this._logService.debug("Unknown OSC code: ",{identifier:d,action:u,data:h})}),this._parser.setDcsHandlerFallback((d,u,h)=>{u==="HOOK"&&(h=h.toArray()),this._logService.debug("Unknown DCS code: ",{identifier:this._parser.identToString(d),action:u,payload:h})}),this._parser.setPrintHandler((d,u,h)=>this.print(d,u,h)),this._parser.registerCsiHandler({final:"@"},d=>this.insertChars(d)),this._parser.registerCsiHandler({intermediates:" ",final:"@"},d=>this.scrollLeft(d)),this._parser.registerCsiHandler({final:"A"},d=>this.cursorUp(d)),this._parser.registerCsiHandler({intermediates:" ",final:"A"},d=>this.scrollRight(d)),this._parser.registerCsiHandler({final:"B"},d=>this.cursorDown(d)),this._parser.registerCsiHandler({final:"C"},d=>this.cursorForward(d)),this._parser.registerCsiHandler({final:"D"},d=>this.cursorBackward(d)),this._parser.registerCsiHandler({final:"E"},d=>this.cursorNextLine(d)),this._parser.registerCsiHandler({final:"F"},d=>this.cursorPrecedingLine(d)),this._parser.registerCsiHandler({final:"G"},d=>this.cursorCharAbsolute(d)),this._parser.registerCsiHandler({final:"H"},d=>this.cursorPosition(d)),this._parser.registerCsiHandler({final:"I"},d=>this.cursorForwardTab(d)),this._parser.registerCsiHandler({final:"J"},d=>this.eraseInDisplay(d,!1)),this._parser.registerCsiHandler({prefix:"?",final:"J"},d=>this.eraseInDisplay(d,!0)),this._parser.registerCsiHandler({final:"K"},d=>this.eraseInLine(d,!1)),this._parser.registerCsiHandler({prefix:"?",final:"K"},d=>this.eraseInLine(d,!0)),this._parser.registerCsiHandler({final:"L"},d=>this.insertLines(d)),this._parser.registerCsiHandler({final:"M"},d=>this.deleteLines(d)),this._parser.registerCsiHandler({final:"P"},d=>this.deleteChars(d)),this._parser.registerCsiHandler({final:"S"},d=>this.scrollUp(d)),this._parser.registerCsiHandler({final:"T"},d=>this.scrollDown(d)),this._parser.registerCsiHandler({final:"X"},d=>this.eraseChars(d)),this._parser.registerCsiHandler({final:"Z"},d=>this.cursorBackwardTab(d)),this._parser.registerCsiHandler({final:"`"},d=>this.charPosAbsolute(d)),this._parser.registerCsiHandler({final:"a"},d=>this.hPositionRelative(d)),this._parser.registerCsiHandler({final:"b"},d=>this.repeatPrecedingCharacter(d)),this._parser.registerCsiHandler({final:"c"},d=>this.sendDeviceAttributesPrimary(d)),this._parser.registerCsiHandler({prefix:">",final:"c"},d=>this.sendDeviceAttributesSecondary(d)),this._parser.registerCsiHandler({final:"d"},d=>this.linePosAbsolute(d)),this._parser.registerCsiHandler({final:"e"},d=>this.vPositionRelative(d)),this._parser.registerCsiHandler({final:"f"},d=>this.hVPosition(d)),this._parser.registerCsiHandler({final:"g"},d=>this.tabClear(d)),this._parser.registerCsiHandler({final:"h"},d=>this.setMode(d)),this._parser.registerCsiHandler({prefix:"?",final:"h"},d=>this.setModePrivate(d)),this._parser.registerCsiHandler({final:"l"},d=>this.resetMode(d)),this._parser.registerCsiHandler({prefix:"?",final:"l"},d=>this.resetModePrivate(d)),this._parser.registerCsiHandler({final:"m"},d=>this.charAttributes(d)),this._parser.registerCsiHandler({final:"n"},d=>this.deviceStatus(d)),this._parser.registerCsiHandler({prefix:"?",final:"n"},d=>this.deviceStatusPrivate(d)),this._parser.registerCsiHandler({intermediates:"!",final:"p"},d=>this.softReset(d)),this._parser.registerCsiHandler({intermediates:" ",final:"q"},d=>this.setCursorStyle(d)),this._parser.registerCsiHandler({final:"r"},d=>this.setScrollRegion(d)),this._parser.registerCsiHandler({final:"s"},d=>this.saveCursor(d)),this._parser.registerCsiHandler({final:"t"},d=>this.windowOptions(d)),this._parser.registerCsiHandler({final:"u"},d=>this.restoreCursor(d)),this._parser.registerCsiHandler({intermediates:"'",final:"}"},d=>this.insertColumns(d)),this._parser.registerCsiHandler({intermediates:"'",final:"~"},d=>this.deleteColumns(d)),this._parser.registerCsiHandler({intermediates:'"',final:"q"},d=>this.selectProtected(d)),this._parser.registerCsiHandler({intermediates:"$",final:"p"},d=>this.requestMode(d,!0)),this._parser.registerCsiHandler({prefix:"?",intermediates:"$",final:"p"},d=>this.requestMode(d,!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(Rn.IND,()=>this.index()),this._parser.setExecuteHandler(Rn.NEL,()=>this.nextLine()),this._parser.setExecuteHandler(Rn.HTS,()=>this.tabSet()),this._parser.registerOscHandler(0,new Yt(d=>(this.setTitle(d),this.setIconName(d),!0))),this._parser.registerOscHandler(1,new Yt(d=>this.setIconName(d))),this._parser.registerOscHandler(2,new Yt(d=>this.setTitle(d))),this._parser.registerOscHandler(4,new Yt(d=>this.setOrReportIndexedColor(d))),this._parser.registerOscHandler(8,new Yt(d=>this.setHyperlink(d))),this._parser.registerOscHandler(10,new Yt(d=>this.setOrReportFgColor(d))),this._parser.registerOscHandler(11,new Yt(d=>this.setOrReportBgColor(d))),this._parser.registerOscHandler(12,new Yt(d=>this.setOrReportCursorColor(d))),this._parser.registerOscHandler(104,new Yt(d=>this.restoreIndexedColor(d))),this._parser.registerOscHandler(110,new Yt(d=>this.restoreFgColor(d))),this._parser.registerOscHandler(111,new Yt(d=>this.restoreBgColor(d))),this._parser.registerOscHandler(112,new Yt(d=>this.restoreCursorColor(d))),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 d in ct)this._parser.registerEscHandler({intermediates:"(",final:d},()=>this.selectCharset("("+d)),this._parser.registerEscHandler({intermediates:")",final:d},()=>this.selectCharset(")"+d)),this._parser.registerEscHandler({intermediates:"*",final:d},()=>this.selectCharset("*"+d)),this._parser.registerEscHandler({intermediates:"+",final:d},()=>this.selectCharset("+"+d)),this._parser.registerEscHandler({intermediates:"-",final:d},()=>this.selectCharset("-"+d)),this._parser.registerEscHandler({intermediates:".",final:d},()=>this.selectCharset("."+d)),this._parser.registerEscHandler({intermediates:"/",final:d},()=>this.selectCharset("/"+d));this._parser.registerEscHandler({intermediates:"#",final:"8"},()=>this.screenAlignmentPattern()),this._parser.setErrorHandler(d=>(this._logService.error("Parsing error: ",d),d)),this._parser.registerDcsHandler({intermediates:"$",final:"q"},new th((d,u)=>this.requestStatusString(d,u)))}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"),nh))]).catch(e=>{if(e!=="#SLOW_TIMEOUT")throw e;console.warn(`async parser handler taking longer than ${nh} ms`)})}_getCurrentLinkId(){return this._curAttrData.extended.urlId}parse(t,e){let s,i=this._activeBuffer.x,n=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,n=this._parseStack.cursorStartY,this._parseStack.paused=!1,t.length>qs&&(o=this._parseStack.position+qs)}if(this._logService.logLevel<=1&&this._logService.debug(`parsing data ${typeof t=="string"?` "${t}"`:` "${Array.prototype.map.call(t,d=>String.fromCharCode(d)).join("")}"`}`),this._logService.logLevel===0&&this._logService.trace("parsing data (codes)",typeof t=="string"?t.split("").map(d=>d.charCodeAt(0)):t),this._parseBuffer.length<t.length&&this._parseBuffer.length<qs&&(this._parseBuffer=new Uint32Array(Math.min(t.length,qs))),a||this._dirtyRowTracker.clearRange(),t.length>qs)for(let d=o;d<t.length;d+=qs){let u=d+qs<t.length?d+qs:t.length,h=typeof t=="string"?this._stringDecoder.decode(t.substring(d,u),this._parseBuffer):this._utf8Decoder.decode(t.subarray(d,u),this._parseBuffer);if(s=this._parser.parse(this._parseBuffer,h))return this._preserveStack(i,n,h,d),this._logSlowResolvingAsync(s),s}else if(!a){let d=typeof t=="string"?this._stringDecoder.decode(t,this._parseBuffer):this._utf8Decoder.decode(t,this._parseBuffer);if(s=this._parser.parse(this._parseBuffer,d))return this._preserveStack(i,n,d,0),this._logSlowResolvingAsync(s),s}(this._activeBuffer.x!==i||this._activeBuffer.y!==n)&&this._onCursorMove.fire();let l=this._dirtyRowTracker.end+(this._bufferService.buffer.ybase-this._bufferService.buffer.ydisp),c=this._dirtyRowTracker.start+(this._bufferService.buffer.ybase-this._bufferService.buffer.ydisp);c<this._bufferService.rows&&this._onRequestRefreshRows.fire({start:Math.min(c,this._bufferService.rows-1),end:Math.min(l,this._bufferService.rows-1)})}print(t,e,s){let i,n,o=this._charsetService.charset,a=this._optionsService.rawOptions.screenReaderMode,l=this._bufferService.cols,c=this._coreService.decPrivateModes.wraparound,d=this._coreService.modes.insertMode,u=this._curAttrData,h=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);this._dirtyRowTracker.markDirty(this._activeBuffer.y),this._activeBuffer.x&&s-e>0&&h.getWidth(this._activeBuffer.x-1)===2&&h.setCellFromCodepoint(this._activeBuffer.x-1,0,1,u);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);n=mi.extractWidth(p);let g=mi.extractShouldJoin(p),_=g?mi.extractWidth(f):0;if(f=p,a&&this._onA11yChar.fire(Ys(i)),this._getCurrentLinkId()&&this._oscLinkService.addLineToLink(this._getCurrentLinkId(),this._activeBuffer.ybase+this._activeBuffer.y),this._activeBuffer.x+n-_>l){if(c){let v=h,x=this._activeBuffer.x-_;for(this._activeBuffer.x=_,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),h=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y),_>0&&h instanceof ur&&h.copyCellsFrom(v,x,0,_,!1);x<l;)v.setCellFromCodepoint(x++,0,1,u)}else if(this._activeBuffer.x=l-1,n===2)continue}if(g&&this._activeBuffer.x){let v=h.getWidth(this._activeBuffer.x-1)?1:2;h.addCodepointToCell(this._activeBuffer.x-v,i,n);for(let x=n-_;--x>=0;)h.setCellFromCodepoint(this._activeBuffer.x++,0,0,u);continue}if(d&&(h.insertCells(this._activeBuffer.x,n-_,this._activeBuffer.getNullCell(u)),h.getWidth(l-1)===2&&h.setCellFromCodepoint(l-1,0,1,u)),h.setCellFromCodepoint(this._activeBuffer.x++,i,n,u),n>0)for(;--n;)h.setCellFromCodepoint(this._activeBuffer.x++,0,0,u)}this._parser.precedingJoinState=f,this._activeBuffer.x<l&&s-e>0&&h.getWidth(this._activeBuffer.x)===0&&!h.hasContent(this._activeBuffer.x)&&h.setCellFromCodepoint(this._activeBuffer.x,0,1,u),this._dirtyRowTracker.markDirty(this._activeBuffer.y)}registerCsiHandler(t,e){return t.final==="t"&&!t.prefix&&!t.intermediates?this._parser.registerCsiHandler(t,s=>rh(s.params[0],this._optionsService.rawOptions.windowOptions)?e(s):!0):this._parser.registerCsiHandler(t,e)}registerDcsHandler(t,e){return this._parser.registerDcsHandler(t,new th(e))}registerEscHandler(t,e){return this._parser.registerEscHandler(t,e)}registerOscHandler(t,e){return this._parser.registerOscHandler(t,new Yt(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,n=!1){let o=this._activeBuffer.lines.get(this._activeBuffer.ybase+t);o.replaceCells(e,s,this._activeBuffer.getNullCell(this._eraseAttrData()),n),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,n=this._bufferService.rows-1+this._activeBuffer.ybase-i+1;for(;e--;)this._activeBuffer.lines.splice(n-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(Ze));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=mi.extractWidth(e),n=this._activeBuffer.x-i,o=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y).getString(n),a=new Uint32Array(o.length*s),l=0;for(let d=0;d<o.length;){let u=o.codePointAt(d)||0;a[l++]=u,d+=u>65535?2:1}let c=l;for(let d=1;d<s;++d)a.copyWithin(c,0,l),c+=l;return this.print(a,0,c),!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,ui),this._charsetService.setgCharset(1,ui),this._charsetService.setgCharset(2,ui),this._charsetService.setgCharset(3,ui);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;(g=>(g[g.NOT_RECOGNIZED=0]="NOT_RECOGNIZED",g[g.SET=1]="SET",g[g.RESET=2]="RESET",g[g.PERMANENTLY_SET=3]="PERMANENTLY_SET",g[g.PERMANENTLY_RESET=4]="PERMANENTLY_RESET"))(s||={});let i=this._coreService.decPrivateModes,{activeProtocol:n,activeEncoding:o}=this._coreMouseService,a=this._coreService,{buffers:l,cols:c}=this._bufferService,{active:d,alt:u}=l,h=this._optionsService.rawOptions,f=(g,_)=>(a.triggerDataEvent(`${Z.ESC}[${e?"":"?"}${g};${_}$y`),!0),m=g=>g?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(h.convertEol)):f(p,0):p===1?f(p,m(i.applicationCursorKeys)):p===3?f(p,h.windowOptions.setWinLines?c===80?2:c===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(n==="X10")):p===12?f(p,m(h.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(n==="VT200")):p===1002?f(p,m(n==="DRAG")):p===1003?f(p,m(n==="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(d===u)):p===2004?f(p,m(i.bracketedPasteMode)):p===2026?f(p,m(i.synchronizedOutput)):f(p,0)}_updateAttrColor(t,e,s,i,n){return e===2?(t|=50331648,t&=-16777216,t|=en.fromColorRGB([s,i,n])):e===5&&(t&=-50331904,t|=33554432|s&255),t}_extractColor(t,e,s){let i=[0,0,-1,0,0,0],n=0,o=0;do{if(i[o+n]=t.params[e+o],t.hasSubParams(e+o)){let a=t.getSubParams(e+o),l=0;do i[1]===5&&(n=1),i[o+l+1+n]=a[l];while(++l<a.length&&l+o+1+n<i.length);break}if(i[1]===5&&o+n>=2||i[1]===2&&o+n>=5)break;i[1]&&(n=1)}while(++o+e<t.length&&o+n<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=Ze.fg,t.bg=Ze.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 n=0;n<e;n++)s=t.params[n],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(n)?t.getSubParams(n)[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|=Ze.fg&16777215):s===49?(i.bg&=-67108864,i.bg|=Ze.bg&16777215):s===38||s===48||s===58?n+=this._extractColor(t,n,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|=Ze.fg&16777215,i.bg&=-67108864,i.bg|=Ze.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=Ze.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(!rh(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>ih&&this._windowTitleStack.shift()),(e===0||e===1)&&(this._iconNameStack.push(this._iconName),this._iconNameStack.length>ih&&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(),n=s.shift();if(/^\d+$/.exec(i)){let o=parseInt(i);if(ah(o))if(n==="?")e.push({type:0,index:o});else{let a=sh(n);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,n=s.findIndex(o=>o.startsWith("id="));return n!==-1&&(i=s[n].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 n=sh(s[i]);n&&this._onColor.fire([{type:1,index:this._specialColors[e],color:n}])}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 n=parseInt(s[i]);ah(n)&&e.push({type:2,index:n})}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,ui),!0}selectCharset(t){return t.length!==2?(this.selectDefaultCharset(),!0):(t[0]==="/"||this._charsetService.setgCharset(Ij[t[0]],ct[t[1]]||ui),!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=Ze.clone(),this._eraseAttrDataInternal=Ze.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 as;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,n=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}[n.cursorStyle]-(n.cursorBlink?1:0)} q`:"P0$r")}markRangeDirty(t,e){this._dirtyRowTracker.markRangeDirty(t,e)}},sl=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&&(oh=t,t=e,e=oh),t<this.start&&(this.start=t),e>this.end&&(this.end=e)}markAllDirty(){this.markRangeDirty(0,this._bufferService.rows-1)}};sl=Ye([ce(0,Lt)],sl);function ah(t){return 0<=t&&t<256}var Tj=5e7,lh=12,Dj=50,Mj=class extends Ve{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 re),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>Tj)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],n=this._action(i,e);if(n){let a=l=>performance.now()-s>=lh?setTimeout(()=>this._innerWrite(0,l)):this._innerWrite(s,l);n.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>=lh)break}this._writeBuffer.length>this._bufferOffset?(this._bufferOffset>Dj&&(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()}},il=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),c={data:t,id:this._nextId++,lines:[l]};return l.onDispose(()=>this._removeMarkerFromLink(c,l)),this._dataByLinkId.set(c.id,c),c.id}let s=t,i=this._getEntryIdKey(s),n=this._entriesWithId.get(i);if(n)return this.addLineToLink(n.id,e.ybase+e.y),n.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)))}};il=Ye([ce(0,Lt)],il);var ch=!1,Pj=class extends Ve{constructor(t){super(),this._windowsWrappingHeuristics=this._register(new zi),this._onBinary=this._register(new re),this.onBinary=this._onBinary.event,this._onData=this._register(new re),this.onData=this._onData.event,this._onLineFeed=this._register(new re),this.onLineFeed=this._onLineFeed.event,this._onResize=this._register(new re),this.onResize=this._onResize.event,this._onWriteParsed=this._register(new re),this.onWriteParsed=this._onWriteParsed.event,this._onScroll=this._register(new re),this._instantiationService=new oj,this.optionsService=this._register(new gj(t)),this._instantiationService.setService(Bt,this.optionsService),this._bufferService=this._register(this._instantiationService.createInstance(Qa)),this._instantiationService.setService(Lt,this._bufferService),this._logService=this._register(this._instantiationService.createInstance(Ja)),this._instantiationService.setService(sm,this._logService),this.coreService=this._register(this._instantiationService.createInstance(Za)),this._instantiationService.setService(Ci,this.coreService),this.coreMouseService=this._register(this._instantiationService.createInstance(el)),this._instantiationService.setService(tm,this.coreMouseService),this.unicodeService=this._register(this._instantiationService.createInstance(mi)),this._instantiationService.setService(sC,this.unicodeService),this._charsetService=this._instantiationService.createInstance(yj),this._instantiationService.setService(tC,this._charsetService),this._oscLinkService=this._instantiationService.createInstance(il),this._instantiationService.setService(im,this._oscLinkService),this._inputHandler=this._register(new Rj(this._bufferService,this._charsetService,this.coreService,this._logService,this.optionsService,this._oscLinkService,this.coreMouseService,this.unicodeService)),this._register(yt.forward(this._inputHandler.onLineFeed,this._onLineFeed)),this._register(this._inputHandler),this._register(yt.forward(this._bufferService.onResize,this._onResize)),this._register(yt.forward(this.coreService.onData,this._onData)),this._register(yt.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 Mj((e,s)=>this._inputHandler.parse(e,s))),this._register(yt.forward(this._writeBuffer.onWriteParsed,this._onWriteParsed))}get onScroll(){return this._onScrollApi||(this._onScrollApi=this._register(new re),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&&!ch&&(this._logService.warn("writeSync is unreliable and will be removed soon."),ch=!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,Mm),e=Math.max(e,Pm),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(eh.bind(null,this._bufferService))),t.push(this.registerCsiHandler({final:"H"},()=>(eh(this._bufferService),!1))),this._windowsWrappingHeuristics.value=Fe(()=>{for(let e of t)e.dispose()})}}},Lj={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 Bj(t,e,s,i){let n={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?n.key=Z.ESC+"OA":n.key=Z.ESC+"[A":t.key==="UIKeyInputLeftArrow"?e?n.key=Z.ESC+"OD":n.key=Z.ESC+"[D":t.key==="UIKeyInputRightArrow"?e?n.key=Z.ESC+"OC":n.key=Z.ESC+"[C":t.key==="UIKeyInputDownArrow"&&(e?n.key=Z.ESC+"OB":n.key=Z.ESC+"[B");break;case 8:n.key=t.ctrlKey?"\b":Z.DEL,t.altKey&&(n.key=Z.ESC+n.key);break;case 9:if(t.shiftKey){n.key=Z.ESC+"[Z";break}n.key=Z.HT,n.cancel=!0;break;case 13:n.key=t.altKey?Z.ESC+Z.CR:Z.CR,n.cancel=!0;break;case 27:n.key=Z.ESC,t.altKey&&(n.key=Z.ESC+Z.ESC),n.cancel=!0;break;case 37:if(t.metaKey)break;o?n.key=Z.ESC+"[1;"+(o+1)+"D":e?n.key=Z.ESC+"OD":n.key=Z.ESC+"[D";break;case 39:if(t.metaKey)break;o?n.key=Z.ESC+"[1;"+(o+1)+"C":e?n.key=Z.ESC+"OC":n.key=Z.ESC+"[C";break;case 38:if(t.metaKey)break;o?n.key=Z.ESC+"[1;"+(o+1)+"A":e?n.key=Z.ESC+"OA":n.key=Z.ESC+"[A";break;case 40:if(t.metaKey)break;o?n.key=Z.ESC+"[1;"+(o+1)+"B":e?n.key=Z.ESC+"OB":n.key=Z.ESC+"[B";break;case 45:!t.shiftKey&&!t.ctrlKey&&(n.key=Z.ESC+"[2~");break;case 46:o?n.key=Z.ESC+"[3;"+(o+1)+"~":n.key=Z.ESC+"[3~";break;case 36:o?n.key=Z.ESC+"[1;"+(o+1)+"H":e?n.key=Z.ESC+"OH":n.key=Z.ESC+"[H";break;case 35:o?n.key=Z.ESC+"[1;"+(o+1)+"F":e?n.key=Z.ESC+"OF":n.key=Z.ESC+"[F";break;case 33:t.shiftKey?n.type=2:t.ctrlKey?n.key=Z.ESC+"[5;"+(o+1)+"~":n.key=Z.ESC+"[5~";break;case 34:t.shiftKey?n.type=3:t.ctrlKey?n.key=Z.ESC+"[6;"+(o+1)+"~":n.key=Z.ESC+"[6~";break;case 112:o?n.key=Z.ESC+"[1;"+(o+1)+"P":n.key=Z.ESC+"OP";break;case 113:o?n.key=Z.ESC+"[1;"+(o+1)+"Q":n.key=Z.ESC+"OQ";break;case 114:o?n.key=Z.ESC+"[1;"+(o+1)+"R":n.key=Z.ESC+"OR";break;case 115:o?n.key=Z.ESC+"[1;"+(o+1)+"S":n.key=Z.ESC+"OS";break;case 116:o?n.key=Z.ESC+"[15;"+(o+1)+"~":n.key=Z.ESC+"[15~";break;case 117:o?n.key=Z.ESC+"[17;"+(o+1)+"~":n.key=Z.ESC+"[17~";break;case 118:o?n.key=Z.ESC+"[18;"+(o+1)+"~":n.key=Z.ESC+"[18~";break;case 119:o?n.key=Z.ESC+"[19;"+(o+1)+"~":n.key=Z.ESC+"[19~";break;case 120:o?n.key=Z.ESC+"[20;"+(o+1)+"~":n.key=Z.ESC+"[20~";break;case 121:o?n.key=Z.ESC+"[21;"+(o+1)+"~":n.key=Z.ESC+"[21~";break;case 122:o?n.key=Z.ESC+"[23;"+(o+1)+"~":n.key=Z.ESC+"[23~";break;case 123:o?n.key=Z.ESC+"[24;"+(o+1)+"~":n.key=Z.ESC+"[24~";break;default:if(t.ctrlKey&&!t.shiftKey&&!t.altKey&&!t.metaKey)t.keyCode>=65&&t.keyCode<=90?n.key=String.fromCharCode(t.keyCode-64):t.keyCode===32?n.key=Z.NUL:t.keyCode>=51&&t.keyCode<=55?n.key=String.fromCharCode(t.keyCode-51+27):t.keyCode===56?n.key=Z.DEL:t.keyCode===219?n.key=Z.ESC:t.keyCode===220?n.key=Z.FS:t.keyCode===221&&(n.key=Z.GS);else if((!s||i)&&t.altKey&&!t.metaKey){let a=Lj[t.keyCode]?.[t.shiftKey?1:0];if(a)n.key=Z.ESC+a;else if(t.keyCode>=65&&t.keyCode<=90){let l=t.ctrlKey?t.keyCode-64:t.keyCode+32,c=String.fromCharCode(l);t.shiftKey&&(c=c.toUpperCase()),n.key=Z.ESC+c}else if(t.keyCode===32)n.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()),n.key=Z.ESC+l,n.cancel=!0}}else s&&!t.altKey&&!t.ctrlKey&&!t.shiftKey&&t.metaKey?t.keyCode===65&&(n.type=1):t.key&&!t.ctrlKey&&!t.altKey&&!t.metaKey&&t.keyCode>=48&&t.key.length===1?n.key=t.key:t.key&&t.ctrlKey&&(t.key==="_"&&(n.key=Z.US),t.key==="@"&&(n.key=Z.NUL));break}return n}var Xe=0,Oj=class{constructor(t){this._getKey=t,this._array=[],this._insertedValues=[],this._flushInsertedTask=new Jn,this._isFlushingInserted=!1,this._deletedIndices=[],this._flushDeletedTask=new Jn,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((n,o)=>this._getKey(n)-this._getKey(o)),e=0,s=0,i=new Array(this._array.length+this._insertedValues.length);for(let n=0;n<i.length;n++)s>=this._array.length||this._getKey(t[e])<=this._getKey(this._array[s])?(i[n]=t[e],e++):i[n]=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||(Xe=this._search(e),Xe===-1)||this._getKey(this._array[Xe])!==e)return!1;do if(this._array[Xe]===t)return this._deletedIndices.length===0&&this._flushDeletedTask.enqueue(()=>this._flushDeleted()),this._deletedIndices.push(Xe),!0;while(++Xe<this._array.length&&this._getKey(this._array[Xe])===e);return!1}_flushDeleted(){this._isFlushingDeleted=!0;let t=this._deletedIndices.sort((n,o)=>n-o),e=0,s=new Array(this._array.length-t.length),i=0;for(let n=0;n<this._array.length;n++)t[e]===n?e++:s[i++]=this._array[n];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&&(Xe=this._search(t),!(Xe<0||Xe>=this._array.length)&&this._getKey(this._array[Xe])===t))do yield this._array[Xe];while(++Xe<this._array.length&&this._getKey(this._array[Xe])===t)}forEachByKey(t,e){if(this._flushCleanupInserted(),this._flushCleanupDeleted(),this._array.length!==0&&(Xe=this._search(t),!(Xe<0||Xe>=this._array.length)&&this._getKey(this._array[Xe])===t))do e(this._array[Xe]);while(++Xe<this._array.length&&this._getKey(this._array[Xe])===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,n=this._getKey(this._array[i]);if(n>t)s=i-1;else if(n<t)e=i+1;else{for(;i>0&&this._getKey(this._array[i-1])===t;)i--;return i}}return e}},ea=0,dh=0,$j=class extends Ve{constructor(){super(),this._decorations=new Oj(t=>t?.marker.line),this._onDecorationRegistered=this._register(new re),this.onDecorationRegistered=this._onDecorationRegistered.event,this._onDecorationRemoved=this._register(new re),this.onDecorationRemoved=this._onDecorationRemoved.event,this._register(Fe(()=>this.reset()))}get decorations(){return this._decorations.values()}registerDecoration(t){if(t.marker.isDisposed)return;let e=new zj(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,n=0;for(let o of this._decorations.getKeyIterator(e))i=o.options.x??0,n=i+(o.options.width??1),t>=i&&t<n&&(!s||(o.options.layer??"bottom")===s)&&(yield o)}forEachDecorationAtCell(t,e,s,i){this._decorations.forEachByKey(e,n=>{ea=n.options.x??0,dh=ea+(n.options.width??1),t>=ea&&t<dh&&(!s||(n.options.layer??"bottom")===s)&&i(n)})}},zj=class extends ti{constructor(t){super(),this.options=t,this.onRenderEmitter=this.add(new re),this.onRender=this.onRenderEmitter.event,this._onDispose=this.add(new re),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=Ue.toColor(this.options.backgroundColor):this._cachedBg=void 0),this._cachedBg}get foregroundColorRGB(){return this._cachedFg===null&&(this.options.foregroundColor?this._cachedFg=Ue.toColor(this.options.foregroundColor):this._cachedFg=void 0),this._cachedFg}dispose(){this._onDispose.fire(),super.dispose()}},Fj=1e3,Hj=class{constructor(t,e=Fj){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 n=i-this._lastRefreshMs,o=this._debounceThresholdMS-n;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)}},hh=20,Qn=class extends Ve{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 n=this._coreBrowserService.mainDocument;this._accessibilityContainer=n.createElement("div"),this._accessibilityContainer.classList.add("xterm-accessibility"),this._rowContainer=n.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=n.createElement("div"),this._liveRegion.classList.add("live-region"),this._liveRegion.setAttribute("aria-live","assertive"),this._accessibilityContainer.appendChild(this._liveRegion),this._liveRegionDebouncer=this._register(new Hj(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(`
440
+ `)}clearSelection(){this._model.clearSelection(),this._removeMouseDownListeners(),this.refresh(),this._onSelectionChange.fire()}refresh(t){this._refreshAnimationFrame||(this._refreshAnimationFrame=this._coreBrowserService.window.requestAnimationFrame(()=>this._refresh())),oc&&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=Fd(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=nc(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,-Go),Go),e/=Go,e/Math.abs(e)+Math.round(e*(sj-1)))}shouldForceSelection(t){return Xn?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(),ij)}_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&&!(Xn&&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<rj&&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=G3(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 n=t.loadCell(i,this._workCell).getChars().length;this._workCell.getWidth()===0?s--:n>1&&e!==i&&(s+=n-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 n=this._bufferService.buffer,o=n.lines.get(t[1]);if(!o)return;let a=n.translateBufferLineToString(t[1],!1),l=this._convertViewportColToCharacterIndex(o,t[0]),c=l,d=t[0]-l,u=0,h=0,f=0,m=0;if(a.charAt(l)===" "){for(;l>0&&a.charAt(l-1)===" ";)l--;for(;c<a.length&&a.charAt(c+1)===" ";)c++}else{let _=t[0],v=t[0];o.getWidth(_)===0&&(u++,_--),o.getWidth(v)===2&&(h++,v++);let x=o.getString(v).length;for(x>1&&(m+=x-1,c+=x-1);_>0&&l>0&&!this._isCharWordSeparator(o.loadCell(_-1,this._workCell));){o.loadCell(_-1,this._workCell);let b=this._workCell.getChars().length;this._workCell.getWidth()===0?(u++,_--):b>1&&(f+=b-1,l-=b-1),l--,_--}for(;v<o.length&&c+1<a.length&&!this._isCharWordSeparator(o.loadCell(v+1,this._workCell));){o.loadCell(v+1,this._workCell);let b=this._workCell.getChars().length;this._workCell.getWidth()===2?(h++,v++):b>1&&(m+=b-1,c+=b-1),c++,v++}}c++;let p=l+d-u+f,g=Math.min(this._bufferService.cols,c-l+u+h-f-m);if(!(!e&&a.slice(l,c).trim()==="")){if(s&&p===0&&o.getCodePoint(0)!==32){let _=n.lines.get(t[1]-1);if(_&&o.isWrapped&&_.getCodePoint(this._bufferService.cols-1)!==32){let v=this._getWordAt([this._bufferService.cols-1,t[1]-1],!1,!0,!1);if(v){let x=this._bufferService.cols-v.start;p-=x,g+=x}}}if(i&&p+g===this._bufferService.cols&&o.getCodePoint(this._bufferService.cols-1)!==32){let _=n.lines.get(t[1]+1);if(_?.isWrapped&&_.getCodePoint(0)!==32){let v=this._getWordAt([0,t[1]+1],!1,!1,!0);v&&(g+=v.length)}}return{start:p,length:g}}}_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=Fd(s,this._bufferService.cols)}};Ya=Ye([ce(3,Lt),ce(4,Ci),ce(5,Ql),ce(6,Bt),ce(7,Ws),ce(8,Hs)],Ya);var Hd=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={}}},Wd=class{constructor(){this._color=new Hd,this._css=new Hd}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()}},rt=Object.freeze((()=>{let t=[Ue.toColor("#2e3436"),Ue.toColor("#cc0000"),Ue.toColor("#4e9a06"),Ue.toColor("#c4a000"),Ue.toColor("#3465a4"),Ue.toColor("#75507b"),Ue.toColor("#06989a"),Ue.toColor("#d3d7cf"),Ue.toColor("#555753"),Ue.toColor("#ef2929"),Ue.toColor("#8ae234"),Ue.toColor("#fce94f"),Ue.toColor("#729fcf"),Ue.toColor("#ad7fa8"),Ue.toColor("#34e2e2"),Ue.toColor("#eeeeec")],e=[0,95,135,175,215,255];for(let s=0;s<216;s++){let i=e[s/36%6|0],n=e[s/6%6|0],o=e[s%6];t.push({css:et.toCss(i,n,o),rgba:et.toRgba(i,n,o)})}for(let s=0;s<24;s++){let i=8+s*10;t.push({css:et.toCss(i,i,i),rgba:et.toRgba(i,i,i)})}return t})()),hi=Ue.toColor("#ffffff"),hr=Ue.toColor("#000000"),Ud=Ue.toColor("#ffffff"),Kd=hr,nr={css:"rgba(255, 255, 255, 0.3)",rgba:4294967117},aj=hi,Xa=class extends Ve{constructor(t){super(),this._optionsService=t,this._contrastCache=new Wd,this._halfContrastCache=new Wd,this._onChangeColors=this._register(new re),this.onChangeColors=this._onChangeColors.event,this._colors={foreground:hi,background:hr,cursor:Ud,cursorAccent:Kd,selectionForeground:void 0,selectionBackgroundTransparent:nr,selectionBackgroundOpaque:Le.blend(hr,nr),selectionInactiveBackgroundTransparent:nr,selectionInactiveBackgroundOpaque:Le.blend(hr,nr),scrollbarSliderBackground:Le.opacity(hi,.2),scrollbarSliderHoverBackground:Le.opacity(hi,.4),scrollbarSliderActiveBackground:Le.opacity(hi,.5),overviewRulerBorder:hi,ansi:rt.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=Re(t.foreground,hi),e.background=Re(t.background,hr),e.cursor=Le.blend(e.background,Re(t.cursor,Ud)),e.cursorAccent=Le.blend(e.background,Re(t.cursorAccent,Kd)),e.selectionBackgroundTransparent=Re(t.selectionBackground,nr),e.selectionBackgroundOpaque=Le.blend(e.background,e.selectionBackgroundTransparent),e.selectionInactiveBackgroundTransparent=Re(t.selectionInactiveBackground,e.selectionBackgroundTransparent),e.selectionInactiveBackgroundOpaque=Le.blend(e.background,e.selectionInactiveBackgroundTransparent),e.selectionForeground=t.selectionForeground?Re(t.selectionForeground,Od):void 0,e.selectionForeground===Od&&(e.selectionForeground=void 0),Le.isOpaque(e.selectionBackgroundTransparent)&&(e.selectionBackgroundTransparent=Le.opacity(e.selectionBackgroundTransparent,.3)),Le.isOpaque(e.selectionInactiveBackgroundTransparent)&&(e.selectionInactiveBackgroundTransparent=Le.opacity(e.selectionInactiveBackgroundTransparent,.3)),e.scrollbarSliderBackground=Re(t.scrollbarSliderBackground,Le.opacity(e.foreground,.2)),e.scrollbarSliderHoverBackground=Re(t.scrollbarSliderHoverBackground,Le.opacity(e.foreground,.4)),e.scrollbarSliderActiveBackground=Re(t.scrollbarSliderActiveBackground,Le.opacity(e.foreground,.5)),e.overviewRulerBorder=Re(t.overviewRulerBorder,aj),e.ansi=rt.slice(),e.ansi[0]=Re(t.black,rt[0]),e.ansi[1]=Re(t.red,rt[1]),e.ansi[2]=Re(t.green,rt[2]),e.ansi[3]=Re(t.yellow,rt[3]),e.ansi[4]=Re(t.blue,rt[4]),e.ansi[5]=Re(t.magenta,rt[5]),e.ansi[6]=Re(t.cyan,rt[6]),e.ansi[7]=Re(t.white,rt[7]),e.ansi[8]=Re(t.brightBlack,rt[8]),e.ansi[9]=Re(t.brightRed,rt[9]),e.ansi[10]=Re(t.brightGreen,rt[10]),e.ansi[11]=Re(t.brightYellow,rt[11]),e.ansi[12]=Re(t.brightBlue,rt[12]),e.ansi[13]=Re(t.brightMagenta,rt[13]),e.ansi[14]=Re(t.brightCyan,rt[14]),e.ansi[15]=Re(t.brightWhite,rt[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]=Re(t.extendedAnsi[i],rt[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()}}};Xa=Ye([ce(0,Bt)],Xa);function Re(t,e){if(t!==void 0)try{return Ue.toColor(t)}catch{}return e}var lj=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)}},cj=class{constructor(){this._services=new lj,this._services.set(Jl,this)}setService(t,e){this._services.set(t,e)}getService(t){return this._services.get(t)}createInstance(t,...e){let s=sC(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 n=s.length>0?s[0].index:e.length;if(e.length!==n)throw new Error(`[createInstance] First service dependency of ${t.name} at position ${n+1} conflicts with ${e.length} static arguments`);return new t(...e,...i)}},dj={trace:0,debug:1,info:2,warn:3,error:4,off:5},hj="xterm.js: ",Ja=class extends Ve{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=dj[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?"":hj)+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)}};Ja=Ye([ce(0,Bt)],Ja);var qd=class extends Ve{constructor(t){super(),this._maxLength=t,this.onDeleteEmitter=this._register(new re),this.onDelete=this.onDeleteEmitter.event,this.onInsertEmitter=this._register(new re),this.onInsert=this.onInsertEmitter.event,this.onTrimEmitter=this._register(new re),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 n=e-1;n>=0;n--)this.set(t+n+s,this.get(t+n));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}},we=3,Ze=Object.freeze(new en),xn=0,Yo=2,ur=class Tm{constructor(e,s,i=!1){this.isWrapped=i,this._combined={},this._extendedAttrs={},this._data=new Uint32Array(e*we);let n=s||as.fromCharData([0,Qf,1,0]);for(let o=0;o<e;++o)this.setCell(o,n);this.length=e}get(e){let s=this._data[e*we+0],i=s&2097151;return[this._data[e*we+1],s&2097152?this._combined[e]:i?Ys(i):"",s>>22,s&2097152?this._combined[e].charCodeAt(this._combined[e].length-1):i]}set(e,s){this._data[e*we+1]=s[0],s[1].length>1?(this._combined[e]=s[1],this._data[e*we+0]=e|2097152|s[2]<<22):this._data[e*we+0]=s[1].charCodeAt(0)|s[2]<<22}getWidth(e){return this._data[e*we+0]>>22}hasWidth(e){return this._data[e*we+0]&12582912}getFg(e){return this._data[e*we+1]}getBg(e){return this._data[e*we+2]}hasContent(e){return this._data[e*we+0]&4194303}getCodePoint(e){let s=this._data[e*we+0];return s&2097152?this._combined[e].charCodeAt(this._combined[e].length-1):s&2097151}isCombined(e){return this._data[e*we+0]&2097152}getString(e){let s=this._data[e*we+0];return s&2097152?this._combined[e]:s&2097151?Ys(s&2097151):""}isProtected(e){return this._data[e*we+2]&536870912}loadCell(e,s){return xn=e*we,s.content=this._data[xn+0],s.fg=this._data[xn+1],s.bg=this._data[xn+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*we+0]=s.content,this._data[e*we+1]=s.fg,this._data[e*we+2]=s.bg}setCellFromCodepoint(e,s,i,n){n.bg&268435456&&(this._extendedAttrs[e]=n.extended),this._data[e*we+0]=s|i<<22,this._data[e*we+1]=n.fg,this._data[e*we+2]=n.bg}addCodepointToCell(e,s,i){let n=this._data[e*we+0];n&2097152?this._combined[e]+=Ys(s):n&2097151?(this._combined[e]=Ys(n&2097151)+Ys(s),n&=-2097152,n|=2097152):n=s|1<<22,i&&(n&=-12582913,n|=i<<22),this._data[e*we+0]=n}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 n=new as;for(let o=this.length-e-s-1;o>=0;--o)this.setCell(e+s+o,this.loadCell(e+o,n));for(let o=0;o<s;++o)this.setCell(e+o,i)}else for(let n=e;n<this.length;++n)this.setCell(n,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 n=new as;for(let o=0;o<this.length-e-s;++o)this.setCell(e+o,this.loadCell(e+s+o,n));for(let o=this.length-s;o<this.length;++o)this.setCell(o,i)}else for(let n=e;n<this.length;++n)this.setCell(n,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,n=!1){if(n){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*Yo<this._data.buffer.byteLength;let i=e*we;if(e>this.length){if(this._data.buffer.byteLength>=i*4)this._data=new Uint32Array(this._data.buffer,0,i);else{let n=new Uint32Array(i);n.set(this._data),this._data=n}for(let n=this.length;n<e;++n)this.setCell(n,s)}else{this._data=this._data.subarray(0,i);let n=Object.keys(this._combined);for(let a=0;a<n.length;a++){let l=parseInt(n[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*Yo<this._data.buffer.byteLength}cleanupMemory(){if(this._data.length*4*Yo<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 Tm(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*we+0]&4194303)return e+(this._data[e*we+0]>>22);return 0}getNoBgTrimmedLength(){for(let e=this.length-1;e>=0;--e)if(this._data[e*we+0]&4194303||this._data[e*we+2]&50331648)return e+(this._data[e*we+0]>>22);return 0}copyCellsFrom(e,s,i,n,o){let a=e._data;if(o)for(let c=n-1;c>=0;c--){for(let d=0;d<we;d++)this._data[(i+c)*we+d]=a[(s+c)*we+d];a[(s+c)*we+2]&268435456&&(this._extendedAttrs[i+c]=e._extendedAttrs[s+c])}else for(let c=0;c<n;c++){for(let d=0;d<we;d++)this._data[(i+c)*we+d]=a[(s+c)*we+d];a[(s+c)*we+2]&268435456&&(this._extendedAttrs[i+c]=e._extendedAttrs[s+c])}let l=Object.keys(e._combined);for(let c=0;c<l.length;c++){let d=parseInt(l[c],10);d>=s&&(this._combined[d-s+i]=e._combined[d])}}translateToString(e,s,i,n){s=s??0,i=i??this.length,e&&(i=Math.min(i,this.getTrimmedLength())),n&&(n.length=0);let o="";for(;s<i;){let a=this._data[s*we+0],l=a&2097151,c=a&2097152?this._combined[s]:l?Ys(l):Xs;if(o+=c,n)for(let d=0;d<c.length;++d)n.push(s);s+=a>>22||1}return n&&n.push(s),o}};function uj(t,e,s,i,n,o){let a=[];for(let l=0;l<t.length-1;l++){let c=l,d=t.get(++c);if(!d.isWrapped)continue;let u=[t.get(l)];for(;c<t.length&&d.isWrapped;)u.push(d),d=t.get(++c);if(!o&&i>=l&&i<c){l+=u.length-1;continue}let h=0,f=Lr(u,h,e),m=1,p=0;for(;m<u.length;){let _=Lr(u,m,e),v=_-p,x=s-f,b=Math.min(v,x);u[h].copyCellsFrom(u[m],p,f,b,!1),f+=b,f===s&&(h++,f=0),p+=b,p===_&&(m++,p=0),f===0&&h!==0&&u[h-1].getWidth(s-1)===2&&(u[h].copyCellsFrom(u[h-1],s-1,f++,1,!1),u[h-1].setCell(s-1,n))}u[h].replaceCells(f,s,n);let g=0;for(let _=u.length-1;_>0&&(_>h||u[_].getTrimmedLength()===0);_--)g++;g>0&&(a.push(l+u.length-g),a.push(g)),l+=u.length-1}return a}function fj(t,e){let s=[],i=0,n=e[i],o=0;for(let a=0;a<t.length;a++)if(n===a){let l=e[++i];t.onDeleteEmitter.fire({index:a-o,amount:l}),a+=l-1,o+=l,n=e[++i]}else s.push(a);return{layout:s,countRemoved:o}}function mj(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 pj(t,e,s){let i=[],n=t.map((c,d)=>Lr(t,d,e)).reduce((c,d)=>c+d),o=0,a=0,l=0;for(;l<n;){if(n-l<s){i.push(n-l);break}o+=s;let c=Lr(t,a,e);o>c&&(o-=c,a++);let d=t[a].getWidth(o-1)===2;d&&o--;let u=d?s-1:s;i.push(u),l+=u}return i}function Lr(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,n=t[e+1].getWidth(0)===2;return i&&n?s-1:s}var Dm=class Mm{constructor(e){this.line=e,this.isDisposed=!1,this._disposables=[],this._id=Mm._nextId++,this._onDispose=this.register(new re),this.onDispose=this._onDispose.event}get id(){return this._id}dispose(){this.isDisposed||(this.isDisposed=!0,this.line=-1,this._onDispose.fire(),_i(this._disposables),this._disposables.length=0)}register(e){return this._disposables.push(e),e}};Dm._nextId=1;var gj=Dm,ct={},ui=ct.B;ct[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:"≥","{":"π","|":"≠","}":"£","~":"·"};ct.A={"#":"£"};ct.B=void 0;ct[4]={"#":"£","@":"¾","[":"ij","\\":"½","]":"|","{":"¨","|":"f","}":"¼","~":"´"};ct.C=ct[5]={"[":"Ä","\\":"Ö","]":"Å","^":"Ü","`":"é","{":"ä","|":"ö","}":"å","~":"ü"};ct.R={"#":"£","@":"à","[":"°","\\":"ç","]":"§","{":"é","|":"ù","}":"è","~":"¨"};ct.Q={"@":"à","[":"â","\\":"ç","]":"ê","^":"î","`":"ô","{":"é","|":"ù","}":"è","~":"û"};ct.K={"@":"§","[":"Ä","\\":"Ö","]":"Ü","{":"ä","|":"ö","}":"ü","~":"ß"};ct.Y={"#":"£","@":"§","[":"°","\\":"ç","]":"é","`":"ù","{":"à","|":"ò","}":"è","~":"ì"};ct.E=ct[6]={"@":"Ä","[":"Æ","\\":"Ø","]":"Å","^":"Ü","`":"ä","{":"æ","|":"ø","}":"å","~":"ü"};ct.Z={"#":"£","@":"§","[":"¡","\\":"Ñ","]":"¿","{":"°","|":"ñ","}":"ç"};ct.H=ct[7]={"@":"É","[":"Ä","\\":"Ö","]":"Å","^":"Ü","`":"é","{":"ä","|":"ö","}":"å","~":"ü"};ct["="]={"#":"ù","@":"à","[":"é","\\":"ç","]":"ê","^":"î",_:"è","`":"ô","{":"ä","|":"ö","}":"ü","~":"û"};var Gd=4294967295,Yd=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=Ze.clone(),this.savedCharset=ui,this.markers=[],this._nullCell=as.fromCharData([0,Qf,1,0]),this._whitespaceCell=as.fromCharData([0,Xs,1,32]),this._isClearing=!1,this._memoryCleanupQueue=new Jn,this._memoryCleanupPosition=0,this._cols=this._bufferService.cols,this._rows=this._bufferService.rows,this.lines=new qd(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 qn),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 qn),this._whitespaceCell}getBlankLine(t,e){return new ur(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>Gd?Gd:e}fillViewportRows(t){if(this.lines.length===0){t===void 0&&(t=Ze);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 qd(this._getCorrectBufferLength(this._rows)),this.scrollTop=0,this.scrollBottom=this._rows-1,this.setupTabStops()}resize(t,e){let s=this.getNullCell(Ze),i=0,n=this._getCorrectBufferLength(e);if(n>this.lines.maxLength&&(this.lines.maxLength=n),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 ur(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 ur(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(n<this.lines.maxLength){let a=this.lines.length-n;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=n}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=uj(this.lines,this._cols,t,this.ybase+this.y,this.getNullCell(Ze),s);if(i.length>0){let n=fj(this.lines,i);mj(this.lines,n.layout),this._reflowLargerAdjustViewport(t,e,n.countRemoved)}}_reflowLargerAdjustViewport(t,e,s){let i=this.getNullCell(Ze),n=s;for(;n-- >0;)this.ybase===0?(this.y>0&&this.y--,this.lines.length<e&&this.lines.push(new ur(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(Ze),n=[],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 c=[l];for(;l.isWrapped&&a>0;)l=this.lines.get(--a),c.unshift(l);if(!s){let b=this.ybase+this.y;if(b>=a&&b<a+c.length)continue}let d=c[c.length-1].getTrimmedLength(),u=pj(c,this._cols,t),h=u.length-c.length,f;this.ybase===0&&this.y!==this.lines.length-1?f=Math.max(0,this.y-this.lines.maxLength+h):f=Math.max(0,this.lines.length-this.lines.maxLength+h);let m=[];for(let b=0;b<h;b++){let y=this.getBlankLine(Ze,!0);m.push(y)}m.length>0&&(n.push({start:a+c.length+o,newLines:m}),o+=m.length),c.push(...m);let p=u.length-1,g=u[p];g===0&&(p--,g=u[p]);let _=c.length-h-1,v=d;for(;_>=0;){let b=Math.min(v,g);if(c[p]===void 0)break;if(c[p].copyCellsFrom(c[_],v-b,g-b,b,!0),g-=b,g===0&&(p--,g=u[p]),v-=b,v===0){_--;let y=Math.max(_,0);v=Lr(c,y,this._cols)}}for(let b=0;b<c.length;b++)u[b]<t&&c[b].setCell(u[b],i);let x=h-f;for(;x-- >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+h,this.ybase+e-1)}if(n.length>0){let a=[],l=[];for(let g=0;g<this.lines.length;g++)l.push(this.lines.get(g));let c=this.lines.length,d=c-1,u=0,h=n[u];this.lines.length=Math.min(this.lines.maxLength,this.lines.length+o);let f=0;for(let g=Math.min(this.lines.maxLength-1,c+o-1);g>=0;g--)if(h&&h.start>d+f){for(let _=h.newLines.length-1;_>=0;_--)this.lines.set(g--,h.newLines[_]);g++,a.push({index:d+1,amount:h.newLines.length}),f+=h.newLines.length,h=n[++u]}else this.lines.set(g,l[d--]);let m=0;for(let g=a.length-1;g>=0;g--)a[g].index+=m,this.lines.onInsertEmitter.fire(a[g]),m+=a[g].amount;let p=Math.max(0,c+o-this.lines.maxLength);p>0&&this.lines.onTrimEmitter.fire(p)}}translateBufferLineToString(t,e,s=0,i){let n=this.lines.get(t);return n?n.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 gj(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)}},_j=class extends Ve{constructor(t,e){super(),this._optionsService=t,this._bufferService=e,this._onBufferActivate=this._register(new re),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 Yd(!0,this._optionsService,this._bufferService),this._normal.fillViewportRows(),this._alt=new Yd(!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)}},Pm=2,Lm=1,Qa=class extends Ve{constructor(t){super(),this.isUserScrolling=!1,this._onResize=this._register(new re),this.onResize=this._onResize.event,this._onScroll=this._register(new re),this.onScroll=this._onScroll.event,this.cols=Math.max(t.rawOptions.cols||0,Pm),this.rows=Math.max(t.rawOptions.rows||0,Lm),this.buffers=this._register(new _j(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 n=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-n+1;s.lines.shiftElements(n+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))}};Qa=Ye([ce(0,Bt)],Qa);var Ni={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:Xn,windowOptions:{},windowsMode:!1,windowsPty:{},wordSeparator:" ()[]{}',\"`",altClickMovesCursor:!0,convertEol:!1,termName:"xterm",cancelEvents:!1,overviewRuler:{}},xj=["normal","bold","100","200","300","400","500","600","700","800","900"],vj=class extends Ve{constructor(t){super(),this._onOptionChange=this._register(new re),this.onOptionChange=this._onOptionChange.event;let e={...Ni};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(Fe(()=>{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 Ni))throw new Error(`No option with key "${s}"`);return this.rawOptions[s]},e=(s,i)=>{if(!(s in Ni))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=Ni[t]),!bj(e))throw new Error(`"${e}" is not a valid value for ${t}`);break;case"wordSeparator":e||(e=Ni[t]);break;case"fontWeight":case"fontWeightBold":if(typeof e=="number"&&1<=e&&e<=1e3)break;e=xj.includes(e)?e:Ni[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 bj(t){return t==="block"||t==="underline"||t==="bar"}function fr(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]&&fr(t[i],e-1);return s}var Xd=Object.freeze({insertMode:!1}),Jd=Object.freeze({applicationCursorKeys:!1,applicationKeypad:!1,bracketedPasteMode:!1,cursorBlink:void 0,cursorStyle:void 0,origin:!1,reverseWraparound:!1,sendFocus:!1,synchronizedOutput:!1,wraparound:!0}),Za=class extends Ve{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 re),this.onData=this._onData.event,this._onUserInput=this._register(new re),this.onUserInput=this._onUserInput.event,this._onBinary=this._register(new re),this.onBinary=this._onBinary.event,this._onRequestScrollToBottom=this._register(new re),this.onRequestScrollToBottom=this._onRequestScrollToBottom.event,this.modes=fr(Xd),this.decPrivateModes=fr(Jd)}reset(){this.modes=fr(Xd),this.decPrivateModes=fr(Jd)}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))}};Za=Ye([ce(0,Lt),ce(1,im),ce(2,Bt)],Za);var Qd={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 Xo(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 Jo=String.fromCharCode,Zd={DEFAULT:t=>{let e=[Xo(t,!1)+32,t.col+32,t.row+32];return e[0]>255||e[1]>255||e[2]>255?"":`\x1B[M${Jo(e[0])}${Jo(e[1])}${Jo(e[2])}`},SGR:t=>{let e=t.action===0&&t.button!==4?"m":"M";return`\x1B[<${Xo(t,!0)};${t.col};${t.row}${e}`},SGR_PIXELS:t=>{let e=t.action===0&&t.button!==4?"m":"M";return`\x1B[<${Xo(t,!0)};${t.x};${t.y}${e}`}},el=class extends Ve{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 re),this.onProtocolChange=this._onProtocolChange.event;for(let i of Object.keys(Qd))this.addProtocol(i,Qd[i]);for(let i of Object.keys(Zd))this.addEncoding(i,Zd[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,n=this._applyScrollModifier(t.deltaY,t);return t.deltaMode===WheelEvent.DOM_DELTA_PIXEL?(n/=i+0,Math.abs(t.deltaY)<50&&(n*=.3),this._wheelPartialScroll+=n,n=Math.floor(Math.abs(this._wheelPartialScroll))*(this._wheelPartialScroll>0?1:-1),this._wheelPartialScroll%=1):t.deltaMode===WheelEvent.DOM_DELTA_PAGE&&(n*=this._bufferService.rows),n}_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)}};el=Ye([ce(0,Lt),ce(1,Ci),ce(2,Bt)],el);var Qo=[[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]],yj=[[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]],nt;function Sj(t,e){let s=0,i=e.length-1,n;if(t<e[0][0]||t>e[i][1])return!1;for(;i>=s;)if(n=s+i>>1,t>e[n][1])s=n+1;else if(t<e[n][0])i=n-1;else return!0;return!1}var wj=class{constructor(){if(this.version="6",!nt){nt=new Uint8Array(65536),nt.fill(1),nt[0]=0,nt.fill(0,1,32),nt.fill(0,127,160),nt.fill(2,4352,4448),nt[9001]=2,nt[9002]=2,nt.fill(2,11904,42192),nt[12351]=1,nt.fill(2,44032,55204),nt.fill(2,63744,64256),nt.fill(2,65040,65050),nt.fill(2,65072,65136),nt.fill(2,65280,65377),nt.fill(2,65504,65511);for(let t=0;t<Qo.length;++t)nt.fill(0,Qo[t][0],Qo[t][1]+1)}}wcwidth(t){return t<32?0:t<127?1:t<65536?nt[t]:Sj(t,yj)?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 n=mi.extractWidth(e);n===0?i=!1:n>s&&(s=n)}return mi.createPropertyValue(0,s,i)}},mi=class Dn{constructor(){this._providers=Object.create(null),this._active="",this._onChange=new re,this.onChange=this._onChange.event;let e=new wj;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,n=e.length;for(let o=0;o<n;++o){let a=e.charCodeAt(o);if(55296<=a&&a<=56319){if(++o>=n)return s+this.wcwidth(a);let d=e.charCodeAt(o);56320<=d&&d<=57343?a=(a-55296)*1024+d-56320+65536:s+=this.wcwidth(d)}let l=this.charProperties(a,i),c=Dn.extractWidth(l);Dn.extractShouldJoin(l)&&(c-=Dn.extractWidth(i)),s+=c,i=l}return s}charProperties(e,s){return this._activeProvider.charProperties(e,s)}},Vj=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 eh(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 or=2147483647,Cj=256,Bm=class tl{constructor(e=32,s=32){if(this.maxLength=e,this.maxSubParamsLength=s,s>Cj)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 tl;if(!e.length)return s;for(let i=Array.isArray(e[0])?1:0;i<e.length;++i){let n=e[i];if(Array.isArray(n))for(let o=0;o<n.length;++o)s.addSubParam(n[o]);else s.addParam(n)}return s}clone(){let e=new tl(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,n=this._subParamsIdx[s]&255;n-i>0&&e.push(Array.prototype.slice.call(this._subParams,i,n))}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>or?or: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>or?or: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,n=this._subParamsIdx[s]&255;n-i>0&&(e[s]=this._subParams.slice(i,n))}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,n=i[s-1];i[s-1]=~n?Math.min(n*10+e,or):e}},ar=[],jj=class{constructor(){this._state=0,this._active=ar,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=ar}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=ar,this._id=-1,this._state=0}_start(){if(this._active=this._handlers[this._id]||ar,!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",xo(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,n=!1;if(this._stack.paused&&(i=this._stack.loopPosition-1,s=e,n=this._stack.fallThrough,this._stack.paused=!1),!n&&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=ar,this._id=-1,this._state=0}}},Yt=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+=xo(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}},lr=[],kj=class{constructor(){this._handlers=Object.create(null),this._active=lr,this._ident=0,this._handlerFb=()=>{},this._stack={paused:!1,loopPosition:0,fallThrough:!1}}dispose(){this._handlers=Object.create(null),this._handlerFb=()=>{},this._active=lr}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=lr,this._ident=0}hook(t,e){if(this.reset(),this._ident=t,this._active=this._handlers[t]||lr,!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",xo(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,n=!1;if(this._stack.paused&&(i=this._stack.loopPosition-1,s=e,n=this._stack.fallThrough,this._stack.paused=!1),!n&&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=lr,this._ident=0}},mr=new Bm;mr.addParam(0);var th=class{constructor(t){this._handler=t,this._data="",this._params=mr,this._hitLimit=!1}hook(t){this._params=t.length>1||t.params[0]?t.clone():mr,this._data="",this._hitLimit=!1}put(t,e,s){this._hitLimit||(this._data+=xo(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=mr,this._data="",this._hitLimit=!1,s));return this._params=mr,this._data="",this._hitLimit=!1,e}},Nj=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 n=0;n<t.length;n++)this.table[e<<8|t[n]]=s<<4|i}},os=160,Aj=(function(){let t=new Nj(4095),e=Array.apply(null,Array(256)).map((l,c)=>c),s=(l,c)=>e.slice(l,c),i=s(32,127),n=s(0,24);n.push(25),n.push.apply(n,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(n,0,3,0),t.addMany(n,1,3,1),t.add(127,1,0,1),t.addMany(n,8,0,8),t.addMany(n,3,3,3),t.add(127,3,0,3),t.addMany(n,4,3,4),t.add(127,4,0,4),t.addMany(n,6,3,6),t.addMany(n,5,3,5),t.add(127,5,0,5),t.addMany(n,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(n,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(n,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(n,11,0,11),t.addMany(s(32,128),11,0,11),t.addMany(s(28,32),11,0,11),t.addMany(n,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(n,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(n,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(os,0,2,0),t.add(os,8,5,8),t.add(os,6,0,6),t.add(os,11,0,11),t.add(os,13,13,13),t})(),Ej=class extends Ve{constructor(t=Aj){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 Bm,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(Fe(()=>{this._csiHandlers=Object.create(null),this._executeHandlers=Object.create(null),this._escHandlers=Object.create(null)})),this._oscParser=this._register(new jj),this._dcsParser=this._register(new kj),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 n=0;n<t.intermediates.length;++n){let o=t.intermediates.charCodeAt(n);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 n=i.indexOf(e);n!==-1&&i.splice(n,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 n=i.indexOf(e);n!==-1&&i.splice(n,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,n){this._parseStack.state=t,this._parseStack.handlers=e,this._parseStack.handlerPos=s,this._parseStack.transition=i,this._parseStack.chunkPos=n}parse(t,e,s){let i=0,n=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,c=this._parseStack.handlerPos-1;switch(this._parseStack.state){case 3:if(s===!1&&c>-1){for(;c>=0&&(a=l[c](this._params),a!==!0);c--)if(a instanceof Promise)return this._parseStack.handlerPos=c,a}this._parseStack.handlers=[];break;case 4:if(s===!1&&c>-1){for(;c>=0&&(a=l[c](),a!==!0);c--)if(a instanceof Promise)return this._parseStack.handlerPos=c,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],n=this._transitions.table[this.currentState<<8|(i<160?i:os)],n>>4){case 2:for(let f=l+1;;++f){if(f>=e||(i=t[f])<32||i>126&&i<os){this._printHandler(t,l,f),l=f-1;break}if(++f>=e||(i=t[f])<32||i>126&&i<os){this._printHandler(t,l,f),l=f-1;break}if(++f>=e||(i=t[f])<32||i>126&&i<os){this._printHandler(t,l,f),l=f-1;break}if(++f>=e||(i=t[f])<32||i>126&&i<os){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 c=this._csiHandlers[this._collect<<8|i],d=c?c.length-1:-1;for(;d>=0&&(a=c[d](this._params),a!==!0);d--)if(a instanceof Promise)return this._preserveStack(3,c,d,n,l),a;d<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 u=this._escHandlers[this._collect<<8|i],h=u?u.length-1:-1;for(;h>=0&&(a=u[h](),a!==!0);h--)if(a instanceof Promise)return this._preserveStack(4,u,h,n,l),a;h<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<os){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,n,l),a;i===27&&(n|=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<os){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,n,l),a;i===27&&(n|=1),this._params.reset(),this._params.addParam(0),this._collect=0,this.precedingJoinState=0;break}this.currentState=n&15}}},Ij=/^([\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})$/,Rj=/^[\da-f]+$/;function sh(t){if(!t)return;let e=t.toLowerCase();if(e.indexOf("rgb:")===0){e=e.slice(4);let s=Ij.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),Rj.exec(e)&&[3,6,9,12].includes(e.length))){let s=e.length/3,i=[0,0,0];for(let n=0;n<3;++n){let o=parseInt(e.slice(s*n,s*n+s),16);i[n]=s===1?o<<4:s===2?o:s===3?o>>4:o>>8}return i}}function Zo(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 Tj(t,e=16){let[s,i,n]=t;return`rgb:${Zo(s,e)}/${Zo(i,e)}/${Zo(n,e)}`}var Dj={"(":0,")":1,"*":2,"+":3,"-":1,".":2},qs=131072,ih=10;function rh(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 nh=5e3,oh=0,Mj=class extends Ve{constructor(t,e,s,i,n,o,a,l,c=new Ej){super(),this._bufferService=t,this._charsetService=e,this._coreService=s,this._logService=i,this._optionsService=n,this._oscLinkService=o,this._coreMouseService=a,this._unicodeService=l,this._parser=c,this._parseBuffer=new Uint32Array(4096),this._stringDecoder=new eC,this._utf8Decoder=new tC,this._windowTitle="",this._iconName="",this._windowTitleStack=[],this._iconNameStack=[],this._curAttrData=Ze.clone(),this._eraseAttrDataInternal=Ze.clone(),this._onRequestBell=this._register(new re),this.onRequestBell=this._onRequestBell.event,this._onRequestRefreshRows=this._register(new re),this.onRequestRefreshRows=this._onRequestRefreshRows.event,this._onRequestReset=this._register(new re),this.onRequestReset=this._onRequestReset.event,this._onRequestSendFocus=this._register(new re),this.onRequestSendFocus=this._onRequestSendFocus.event,this._onRequestSyncScrollBar=this._register(new re),this.onRequestSyncScrollBar=this._onRequestSyncScrollBar.event,this._onRequestWindowsOptionsReport=this._register(new re),this.onRequestWindowsOptionsReport=this._onRequestWindowsOptionsReport.event,this._onA11yChar=this._register(new re),this.onA11yChar=this._onA11yChar.event,this._onA11yTab=this._register(new re),this.onA11yTab=this._onA11yTab.event,this._onCursorMove=this._register(new re),this.onCursorMove=this._onCursorMove.event,this._onLineFeed=this._register(new re),this.onLineFeed=this._onLineFeed.event,this._onScroll=this._register(new re),this.onScroll=this._onScroll.event,this._onTitleChange=this._register(new re),this.onTitleChange=this._onTitleChange.event,this._onColor=this._register(new re),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 sl(this._bufferService),this._activeBuffer=this._bufferService.buffer,this._register(this._bufferService.buffers.onBufferActivate(d=>this._activeBuffer=d.activeBuffer)),this._parser.setCsiHandlerFallback((d,u)=>{this._logService.debug("Unknown CSI code: ",{identifier:this._parser.identToString(d),params:u.toArray()})}),this._parser.setEscHandlerFallback(d=>{this._logService.debug("Unknown ESC code: ",{identifier:this._parser.identToString(d)})}),this._parser.setExecuteHandlerFallback(d=>{this._logService.debug("Unknown EXECUTE code: ",{code:d})}),this._parser.setOscHandlerFallback((d,u,h)=>{this._logService.debug("Unknown OSC code: ",{identifier:d,action:u,data:h})}),this._parser.setDcsHandlerFallback((d,u,h)=>{u==="HOOK"&&(h=h.toArray()),this._logService.debug("Unknown DCS code: ",{identifier:this._parser.identToString(d),action:u,payload:h})}),this._parser.setPrintHandler((d,u,h)=>this.print(d,u,h)),this._parser.registerCsiHandler({final:"@"},d=>this.insertChars(d)),this._parser.registerCsiHandler({intermediates:" ",final:"@"},d=>this.scrollLeft(d)),this._parser.registerCsiHandler({final:"A"},d=>this.cursorUp(d)),this._parser.registerCsiHandler({intermediates:" ",final:"A"},d=>this.scrollRight(d)),this._parser.registerCsiHandler({final:"B"},d=>this.cursorDown(d)),this._parser.registerCsiHandler({final:"C"},d=>this.cursorForward(d)),this._parser.registerCsiHandler({final:"D"},d=>this.cursorBackward(d)),this._parser.registerCsiHandler({final:"E"},d=>this.cursorNextLine(d)),this._parser.registerCsiHandler({final:"F"},d=>this.cursorPrecedingLine(d)),this._parser.registerCsiHandler({final:"G"},d=>this.cursorCharAbsolute(d)),this._parser.registerCsiHandler({final:"H"},d=>this.cursorPosition(d)),this._parser.registerCsiHandler({final:"I"},d=>this.cursorForwardTab(d)),this._parser.registerCsiHandler({final:"J"},d=>this.eraseInDisplay(d,!1)),this._parser.registerCsiHandler({prefix:"?",final:"J"},d=>this.eraseInDisplay(d,!0)),this._parser.registerCsiHandler({final:"K"},d=>this.eraseInLine(d,!1)),this._parser.registerCsiHandler({prefix:"?",final:"K"},d=>this.eraseInLine(d,!0)),this._parser.registerCsiHandler({final:"L"},d=>this.insertLines(d)),this._parser.registerCsiHandler({final:"M"},d=>this.deleteLines(d)),this._parser.registerCsiHandler({final:"P"},d=>this.deleteChars(d)),this._parser.registerCsiHandler({final:"S"},d=>this.scrollUp(d)),this._parser.registerCsiHandler({final:"T"},d=>this.scrollDown(d)),this._parser.registerCsiHandler({final:"X"},d=>this.eraseChars(d)),this._parser.registerCsiHandler({final:"Z"},d=>this.cursorBackwardTab(d)),this._parser.registerCsiHandler({final:"`"},d=>this.charPosAbsolute(d)),this._parser.registerCsiHandler({final:"a"},d=>this.hPositionRelative(d)),this._parser.registerCsiHandler({final:"b"},d=>this.repeatPrecedingCharacter(d)),this._parser.registerCsiHandler({final:"c"},d=>this.sendDeviceAttributesPrimary(d)),this._parser.registerCsiHandler({prefix:">",final:"c"},d=>this.sendDeviceAttributesSecondary(d)),this._parser.registerCsiHandler({final:"d"},d=>this.linePosAbsolute(d)),this._parser.registerCsiHandler({final:"e"},d=>this.vPositionRelative(d)),this._parser.registerCsiHandler({final:"f"},d=>this.hVPosition(d)),this._parser.registerCsiHandler({final:"g"},d=>this.tabClear(d)),this._parser.registerCsiHandler({final:"h"},d=>this.setMode(d)),this._parser.registerCsiHandler({prefix:"?",final:"h"},d=>this.setModePrivate(d)),this._parser.registerCsiHandler({final:"l"},d=>this.resetMode(d)),this._parser.registerCsiHandler({prefix:"?",final:"l"},d=>this.resetModePrivate(d)),this._parser.registerCsiHandler({final:"m"},d=>this.charAttributes(d)),this._parser.registerCsiHandler({final:"n"},d=>this.deviceStatus(d)),this._parser.registerCsiHandler({prefix:"?",final:"n"},d=>this.deviceStatusPrivate(d)),this._parser.registerCsiHandler({intermediates:"!",final:"p"},d=>this.softReset(d)),this._parser.registerCsiHandler({intermediates:" ",final:"q"},d=>this.setCursorStyle(d)),this._parser.registerCsiHandler({final:"r"},d=>this.setScrollRegion(d)),this._parser.registerCsiHandler({final:"s"},d=>this.saveCursor(d)),this._parser.registerCsiHandler({final:"t"},d=>this.windowOptions(d)),this._parser.registerCsiHandler({final:"u"},d=>this.restoreCursor(d)),this._parser.registerCsiHandler({intermediates:"'",final:"}"},d=>this.insertColumns(d)),this._parser.registerCsiHandler({intermediates:"'",final:"~"},d=>this.deleteColumns(d)),this._parser.registerCsiHandler({intermediates:'"',final:"q"},d=>this.selectProtected(d)),this._parser.registerCsiHandler({intermediates:"$",final:"p"},d=>this.requestMode(d,!0)),this._parser.registerCsiHandler({prefix:"?",intermediates:"$",final:"p"},d=>this.requestMode(d,!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(Rn.IND,()=>this.index()),this._parser.setExecuteHandler(Rn.NEL,()=>this.nextLine()),this._parser.setExecuteHandler(Rn.HTS,()=>this.tabSet()),this._parser.registerOscHandler(0,new Yt(d=>(this.setTitle(d),this.setIconName(d),!0))),this._parser.registerOscHandler(1,new Yt(d=>this.setIconName(d))),this._parser.registerOscHandler(2,new Yt(d=>this.setTitle(d))),this._parser.registerOscHandler(4,new Yt(d=>this.setOrReportIndexedColor(d))),this._parser.registerOscHandler(8,new Yt(d=>this.setHyperlink(d))),this._parser.registerOscHandler(10,new Yt(d=>this.setOrReportFgColor(d))),this._parser.registerOscHandler(11,new Yt(d=>this.setOrReportBgColor(d))),this._parser.registerOscHandler(12,new Yt(d=>this.setOrReportCursorColor(d))),this._parser.registerOscHandler(104,new Yt(d=>this.restoreIndexedColor(d))),this._parser.registerOscHandler(110,new Yt(d=>this.restoreFgColor(d))),this._parser.registerOscHandler(111,new Yt(d=>this.restoreBgColor(d))),this._parser.registerOscHandler(112,new Yt(d=>this.restoreCursorColor(d))),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 d in ct)this._parser.registerEscHandler({intermediates:"(",final:d},()=>this.selectCharset("("+d)),this._parser.registerEscHandler({intermediates:")",final:d},()=>this.selectCharset(")"+d)),this._parser.registerEscHandler({intermediates:"*",final:d},()=>this.selectCharset("*"+d)),this._parser.registerEscHandler({intermediates:"+",final:d},()=>this.selectCharset("+"+d)),this._parser.registerEscHandler({intermediates:"-",final:d},()=>this.selectCharset("-"+d)),this._parser.registerEscHandler({intermediates:".",final:d},()=>this.selectCharset("."+d)),this._parser.registerEscHandler({intermediates:"/",final:d},()=>this.selectCharset("/"+d));this._parser.registerEscHandler({intermediates:"#",final:"8"},()=>this.screenAlignmentPattern()),this._parser.setErrorHandler(d=>(this._logService.error("Parsing error: ",d),d)),this._parser.registerDcsHandler({intermediates:"$",final:"q"},new th((d,u)=>this.requestStatusString(d,u)))}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"),nh))]).catch(e=>{if(e!=="#SLOW_TIMEOUT")throw e;console.warn(`async parser handler taking longer than ${nh} ms`)})}_getCurrentLinkId(){return this._curAttrData.extended.urlId}parse(t,e){let s,i=this._activeBuffer.x,n=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,n=this._parseStack.cursorStartY,this._parseStack.paused=!1,t.length>qs&&(o=this._parseStack.position+qs)}if(this._logService.logLevel<=1&&this._logService.debug(`parsing data ${typeof t=="string"?` "${t}"`:` "${Array.prototype.map.call(t,d=>String.fromCharCode(d)).join("")}"`}`),this._logService.logLevel===0&&this._logService.trace("parsing data (codes)",typeof t=="string"?t.split("").map(d=>d.charCodeAt(0)):t),this._parseBuffer.length<t.length&&this._parseBuffer.length<qs&&(this._parseBuffer=new Uint32Array(Math.min(t.length,qs))),a||this._dirtyRowTracker.clearRange(),t.length>qs)for(let d=o;d<t.length;d+=qs){let u=d+qs<t.length?d+qs:t.length,h=typeof t=="string"?this._stringDecoder.decode(t.substring(d,u),this._parseBuffer):this._utf8Decoder.decode(t.subarray(d,u),this._parseBuffer);if(s=this._parser.parse(this._parseBuffer,h))return this._preserveStack(i,n,h,d),this._logSlowResolvingAsync(s),s}else if(!a){let d=typeof t=="string"?this._stringDecoder.decode(t,this._parseBuffer):this._utf8Decoder.decode(t,this._parseBuffer);if(s=this._parser.parse(this._parseBuffer,d))return this._preserveStack(i,n,d,0),this._logSlowResolvingAsync(s),s}(this._activeBuffer.x!==i||this._activeBuffer.y!==n)&&this._onCursorMove.fire();let l=this._dirtyRowTracker.end+(this._bufferService.buffer.ybase-this._bufferService.buffer.ydisp),c=this._dirtyRowTracker.start+(this._bufferService.buffer.ybase-this._bufferService.buffer.ydisp);c<this._bufferService.rows&&this._onRequestRefreshRows.fire({start:Math.min(c,this._bufferService.rows-1),end:Math.min(l,this._bufferService.rows-1)})}print(t,e,s){let i,n,o=this._charsetService.charset,a=this._optionsService.rawOptions.screenReaderMode,l=this._bufferService.cols,c=this._coreService.decPrivateModes.wraparound,d=this._coreService.modes.insertMode,u=this._curAttrData,h=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y);this._dirtyRowTracker.markDirty(this._activeBuffer.y),this._activeBuffer.x&&s-e>0&&h.getWidth(this._activeBuffer.x-1)===2&&h.setCellFromCodepoint(this._activeBuffer.x-1,0,1,u);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);n=mi.extractWidth(p);let g=mi.extractShouldJoin(p),_=g?mi.extractWidth(f):0;if(f=p,a&&this._onA11yChar.fire(Ys(i)),this._getCurrentLinkId()&&this._oscLinkService.addLineToLink(this._getCurrentLinkId(),this._activeBuffer.ybase+this._activeBuffer.y),this._activeBuffer.x+n-_>l){if(c){let v=h,x=this._activeBuffer.x-_;for(this._activeBuffer.x=_,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),h=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y),_>0&&h instanceof ur&&h.copyCellsFrom(v,x,0,_,!1);x<l;)v.setCellFromCodepoint(x++,0,1,u)}else if(this._activeBuffer.x=l-1,n===2)continue}if(g&&this._activeBuffer.x){let v=h.getWidth(this._activeBuffer.x-1)?1:2;h.addCodepointToCell(this._activeBuffer.x-v,i,n);for(let x=n-_;--x>=0;)h.setCellFromCodepoint(this._activeBuffer.x++,0,0,u);continue}if(d&&(h.insertCells(this._activeBuffer.x,n-_,this._activeBuffer.getNullCell(u)),h.getWidth(l-1)===2&&h.setCellFromCodepoint(l-1,0,1,u)),h.setCellFromCodepoint(this._activeBuffer.x++,i,n,u),n>0)for(;--n;)h.setCellFromCodepoint(this._activeBuffer.x++,0,0,u)}this._parser.precedingJoinState=f,this._activeBuffer.x<l&&s-e>0&&h.getWidth(this._activeBuffer.x)===0&&!h.hasContent(this._activeBuffer.x)&&h.setCellFromCodepoint(this._activeBuffer.x,0,1,u),this._dirtyRowTracker.markDirty(this._activeBuffer.y)}registerCsiHandler(t,e){return t.final==="t"&&!t.prefix&&!t.intermediates?this._parser.registerCsiHandler(t,s=>rh(s.params[0],this._optionsService.rawOptions.windowOptions)?e(s):!0):this._parser.registerCsiHandler(t,e)}registerDcsHandler(t,e){return this._parser.registerDcsHandler(t,new th(e))}registerEscHandler(t,e){return this._parser.registerEscHandler(t,e)}registerOscHandler(t,e){return this._parser.registerOscHandler(t,new Yt(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,n=!1){let o=this._activeBuffer.lines.get(this._activeBuffer.ybase+t);o.replaceCells(e,s,this._activeBuffer.getNullCell(this._eraseAttrData()),n),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,n=this._bufferService.rows-1+this._activeBuffer.ybase-i+1;for(;e--;)this._activeBuffer.lines.splice(n-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(Ze));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=mi.extractWidth(e),n=this._activeBuffer.x-i,o=this._activeBuffer.lines.get(this._activeBuffer.ybase+this._activeBuffer.y).getString(n),a=new Uint32Array(o.length*s),l=0;for(let d=0;d<o.length;){let u=o.codePointAt(d)||0;a[l++]=u,d+=u>65535?2:1}let c=l;for(let d=1;d<s;++d)a.copyWithin(c,0,l),c+=l;return this.print(a,0,c),!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,ui),this._charsetService.setgCharset(1,ui),this._charsetService.setgCharset(2,ui),this._charsetService.setgCharset(3,ui);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;(g=>(g[g.NOT_RECOGNIZED=0]="NOT_RECOGNIZED",g[g.SET=1]="SET",g[g.RESET=2]="RESET",g[g.PERMANENTLY_SET=3]="PERMANENTLY_SET",g[g.PERMANENTLY_RESET=4]="PERMANENTLY_RESET"))(s||={});let i=this._coreService.decPrivateModes,{activeProtocol:n,activeEncoding:o}=this._coreMouseService,a=this._coreService,{buffers:l,cols:c}=this._bufferService,{active:d,alt:u}=l,h=this._optionsService.rawOptions,f=(g,_)=>(a.triggerDataEvent(`${Z.ESC}[${e?"":"?"}${g};${_}$y`),!0),m=g=>g?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(h.convertEol)):f(p,0):p===1?f(p,m(i.applicationCursorKeys)):p===3?f(p,h.windowOptions.setWinLines?c===80?2:c===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(n==="X10")):p===12?f(p,m(h.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(n==="VT200")):p===1002?f(p,m(n==="DRAG")):p===1003?f(p,m(n==="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(d===u)):p===2004?f(p,m(i.bracketedPasteMode)):p===2026?f(p,m(i.synchronizedOutput)):f(p,0)}_updateAttrColor(t,e,s,i,n){return e===2?(t|=50331648,t&=-16777216,t|=en.fromColorRGB([s,i,n])):e===5&&(t&=-50331904,t|=33554432|s&255),t}_extractColor(t,e,s){let i=[0,0,-1,0,0,0],n=0,o=0;do{if(i[o+n]=t.params[e+o],t.hasSubParams(e+o)){let a=t.getSubParams(e+o),l=0;do i[1]===5&&(n=1),i[o+l+1+n]=a[l];while(++l<a.length&&l+o+1+n<i.length);break}if(i[1]===5&&o+n>=2||i[1]===2&&o+n>=5)break;i[1]&&(n=1)}while(++o+e<t.length&&o+n<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=Ze.fg,t.bg=Ze.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 n=0;n<e;n++)s=t.params[n],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(n)?t.getSubParams(n)[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|=Ze.fg&16777215):s===49?(i.bg&=-67108864,i.bg|=Ze.bg&16777215):s===38||s===48||s===58?n+=this._extractColor(t,n,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|=Ze.fg&16777215,i.bg&=-67108864,i.bg|=Ze.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=Ze.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(!rh(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>ih&&this._windowTitleStack.shift()),(e===0||e===1)&&(this._iconNameStack.push(this._iconName),this._iconNameStack.length>ih&&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(),n=s.shift();if(/^\d+$/.exec(i)){let o=parseInt(i);if(ah(o))if(n==="?")e.push({type:0,index:o});else{let a=sh(n);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,n=s.findIndex(o=>o.startsWith("id="));return n!==-1&&(i=s[n].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 n=sh(s[i]);n&&this._onColor.fire([{type:1,index:this._specialColors[e],color:n}])}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 n=parseInt(s[i]);ah(n)&&e.push({type:2,index:n})}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,ui),!0}selectCharset(t){return t.length!==2?(this.selectDefaultCharset(),!0):(t[0]==="/"||this._charsetService.setgCharset(Dj[t[0]],ct[t[1]]||ui),!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=Ze.clone(),this._eraseAttrDataInternal=Ze.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 as;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,n=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}[n.cursorStyle]-(n.cursorBlink?1:0)} q`:"P0$r")}markRangeDirty(t,e){this._dirtyRowTracker.markRangeDirty(t,e)}},sl=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&&(oh=t,t=e,e=oh),t<this.start&&(this.start=t),e>this.end&&(this.end=e)}markAllDirty(){this.markRangeDirty(0,this._bufferService.rows-1)}};sl=Ye([ce(0,Lt)],sl);function ah(t){return 0<=t&&t<256}var Pj=5e7,lh=12,Lj=50,Bj=class extends Ve{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 re),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>Pj)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],n=this._action(i,e);if(n){let a=l=>performance.now()-s>=lh?setTimeout(()=>this._innerWrite(0,l)):this._innerWrite(s,l);n.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>=lh)break}this._writeBuffer.length>this._bufferOffset?(this._bufferOffset>Lj&&(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()}},il=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),c={data:t,id:this._nextId++,lines:[l]};return l.onDispose(()=>this._removeMarkerFromLink(c,l)),this._dataByLinkId.set(c.id,c),c.id}let s=t,i=this._getEntryIdKey(s),n=this._entriesWithId.get(i);if(n)return this.addLineToLink(n.id,e.ybase+e.y),n.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)))}};il=Ye([ce(0,Lt)],il);var ch=!1,Oj=class extends Ve{constructor(t){super(),this._windowsWrappingHeuristics=this._register(new zi),this._onBinary=this._register(new re),this.onBinary=this._onBinary.event,this._onData=this._register(new re),this.onData=this._onData.event,this._onLineFeed=this._register(new re),this.onLineFeed=this._onLineFeed.event,this._onResize=this._register(new re),this.onResize=this._onResize.event,this._onWriteParsed=this._register(new re),this.onWriteParsed=this._onWriteParsed.event,this._onScroll=this._register(new re),this._instantiationService=new cj,this.optionsService=this._register(new vj(t)),this._instantiationService.setService(Bt,this.optionsService),this._bufferService=this._register(this._instantiationService.createInstance(Qa)),this._instantiationService.setService(Lt,this._bufferService),this._logService=this._register(this._instantiationService.createInstance(Ja)),this._instantiationService.setService(im,this._logService),this.coreService=this._register(this._instantiationService.createInstance(Za)),this._instantiationService.setService(Ci,this.coreService),this.coreMouseService=this._register(this._instantiationService.createInstance(el)),this._instantiationService.setService(sm,this.coreMouseService),this.unicodeService=this._register(this._instantiationService.createInstance(mi)),this._instantiationService.setService(nC,this.unicodeService),this._charsetService=this._instantiationService.createInstance(Vj),this._instantiationService.setService(rC,this._charsetService),this._oscLinkService=this._instantiationService.createInstance(il),this._instantiationService.setService(rm,this._oscLinkService),this._inputHandler=this._register(new Mj(this._bufferService,this._charsetService,this.coreService,this._logService,this.optionsService,this._oscLinkService,this.coreMouseService,this.unicodeService)),this._register(yt.forward(this._inputHandler.onLineFeed,this._onLineFeed)),this._register(this._inputHandler),this._register(yt.forward(this._bufferService.onResize,this._onResize)),this._register(yt.forward(this.coreService.onData,this._onData)),this._register(yt.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 Bj((e,s)=>this._inputHandler.parse(e,s))),this._register(yt.forward(this._writeBuffer.onWriteParsed,this._onWriteParsed))}get onScroll(){return this._onScrollApi||(this._onScrollApi=this._register(new re),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&&!ch&&(this._logService.warn("writeSync is unreliable and will be removed soon."),ch=!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,Pm),e=Math.max(e,Lm),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(eh.bind(null,this._bufferService))),t.push(this.registerCsiHandler({final:"H"},()=>(eh(this._bufferService),!1))),this._windowsWrappingHeuristics.value=Fe(()=>{for(let e of t)e.dispose()})}}},$j={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 zj(t,e,s,i){let n={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?n.key=Z.ESC+"OA":n.key=Z.ESC+"[A":t.key==="UIKeyInputLeftArrow"?e?n.key=Z.ESC+"OD":n.key=Z.ESC+"[D":t.key==="UIKeyInputRightArrow"?e?n.key=Z.ESC+"OC":n.key=Z.ESC+"[C":t.key==="UIKeyInputDownArrow"&&(e?n.key=Z.ESC+"OB":n.key=Z.ESC+"[B");break;case 8:n.key=t.ctrlKey?"\b":Z.DEL,t.altKey&&(n.key=Z.ESC+n.key);break;case 9:if(t.shiftKey){n.key=Z.ESC+"[Z";break}n.key=Z.HT,n.cancel=!0;break;case 13:n.key=t.altKey?Z.ESC+Z.CR:Z.CR,n.cancel=!0;break;case 27:n.key=Z.ESC,t.altKey&&(n.key=Z.ESC+Z.ESC),n.cancel=!0;break;case 37:if(t.metaKey)break;o?n.key=Z.ESC+"[1;"+(o+1)+"D":e?n.key=Z.ESC+"OD":n.key=Z.ESC+"[D";break;case 39:if(t.metaKey)break;o?n.key=Z.ESC+"[1;"+(o+1)+"C":e?n.key=Z.ESC+"OC":n.key=Z.ESC+"[C";break;case 38:if(t.metaKey)break;o?n.key=Z.ESC+"[1;"+(o+1)+"A":e?n.key=Z.ESC+"OA":n.key=Z.ESC+"[A";break;case 40:if(t.metaKey)break;o?n.key=Z.ESC+"[1;"+(o+1)+"B":e?n.key=Z.ESC+"OB":n.key=Z.ESC+"[B";break;case 45:!t.shiftKey&&!t.ctrlKey&&(n.key=Z.ESC+"[2~");break;case 46:o?n.key=Z.ESC+"[3;"+(o+1)+"~":n.key=Z.ESC+"[3~";break;case 36:o?n.key=Z.ESC+"[1;"+(o+1)+"H":e?n.key=Z.ESC+"OH":n.key=Z.ESC+"[H";break;case 35:o?n.key=Z.ESC+"[1;"+(o+1)+"F":e?n.key=Z.ESC+"OF":n.key=Z.ESC+"[F";break;case 33:t.shiftKey?n.type=2:t.ctrlKey?n.key=Z.ESC+"[5;"+(o+1)+"~":n.key=Z.ESC+"[5~";break;case 34:t.shiftKey?n.type=3:t.ctrlKey?n.key=Z.ESC+"[6;"+(o+1)+"~":n.key=Z.ESC+"[6~";break;case 112:o?n.key=Z.ESC+"[1;"+(o+1)+"P":n.key=Z.ESC+"OP";break;case 113:o?n.key=Z.ESC+"[1;"+(o+1)+"Q":n.key=Z.ESC+"OQ";break;case 114:o?n.key=Z.ESC+"[1;"+(o+1)+"R":n.key=Z.ESC+"OR";break;case 115:o?n.key=Z.ESC+"[1;"+(o+1)+"S":n.key=Z.ESC+"OS";break;case 116:o?n.key=Z.ESC+"[15;"+(o+1)+"~":n.key=Z.ESC+"[15~";break;case 117:o?n.key=Z.ESC+"[17;"+(o+1)+"~":n.key=Z.ESC+"[17~";break;case 118:o?n.key=Z.ESC+"[18;"+(o+1)+"~":n.key=Z.ESC+"[18~";break;case 119:o?n.key=Z.ESC+"[19;"+(o+1)+"~":n.key=Z.ESC+"[19~";break;case 120:o?n.key=Z.ESC+"[20;"+(o+1)+"~":n.key=Z.ESC+"[20~";break;case 121:o?n.key=Z.ESC+"[21;"+(o+1)+"~":n.key=Z.ESC+"[21~";break;case 122:o?n.key=Z.ESC+"[23;"+(o+1)+"~":n.key=Z.ESC+"[23~";break;case 123:o?n.key=Z.ESC+"[24;"+(o+1)+"~":n.key=Z.ESC+"[24~";break;default:if(t.ctrlKey&&!t.shiftKey&&!t.altKey&&!t.metaKey)t.keyCode>=65&&t.keyCode<=90?n.key=String.fromCharCode(t.keyCode-64):t.keyCode===32?n.key=Z.NUL:t.keyCode>=51&&t.keyCode<=55?n.key=String.fromCharCode(t.keyCode-51+27):t.keyCode===56?n.key=Z.DEL:t.keyCode===219?n.key=Z.ESC:t.keyCode===220?n.key=Z.FS:t.keyCode===221&&(n.key=Z.GS);else if((!s||i)&&t.altKey&&!t.metaKey){let a=$j[t.keyCode]?.[t.shiftKey?1:0];if(a)n.key=Z.ESC+a;else if(t.keyCode>=65&&t.keyCode<=90){let l=t.ctrlKey?t.keyCode-64:t.keyCode+32,c=String.fromCharCode(l);t.shiftKey&&(c=c.toUpperCase()),n.key=Z.ESC+c}else if(t.keyCode===32)n.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()),n.key=Z.ESC+l,n.cancel=!0}}else s&&!t.altKey&&!t.ctrlKey&&!t.shiftKey&&t.metaKey?t.keyCode===65&&(n.type=1):t.key&&!t.ctrlKey&&!t.altKey&&!t.metaKey&&t.keyCode>=48&&t.key.length===1?n.key=t.key:t.key&&t.ctrlKey&&(t.key==="_"&&(n.key=Z.US),t.key==="@"&&(n.key=Z.NUL));break}return n}var Xe=0,Fj=class{constructor(t){this._getKey=t,this._array=[],this._insertedValues=[],this._flushInsertedTask=new Jn,this._isFlushingInserted=!1,this._deletedIndices=[],this._flushDeletedTask=new Jn,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((n,o)=>this._getKey(n)-this._getKey(o)),e=0,s=0,i=new Array(this._array.length+this._insertedValues.length);for(let n=0;n<i.length;n++)s>=this._array.length||this._getKey(t[e])<=this._getKey(this._array[s])?(i[n]=t[e],e++):i[n]=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||(Xe=this._search(e),Xe===-1)||this._getKey(this._array[Xe])!==e)return!1;do if(this._array[Xe]===t)return this._deletedIndices.length===0&&this._flushDeletedTask.enqueue(()=>this._flushDeleted()),this._deletedIndices.push(Xe),!0;while(++Xe<this._array.length&&this._getKey(this._array[Xe])===e);return!1}_flushDeleted(){this._isFlushingDeleted=!0;let t=this._deletedIndices.sort((n,o)=>n-o),e=0,s=new Array(this._array.length-t.length),i=0;for(let n=0;n<this._array.length;n++)t[e]===n?e++:s[i++]=this._array[n];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&&(Xe=this._search(t),!(Xe<0||Xe>=this._array.length)&&this._getKey(this._array[Xe])===t))do yield this._array[Xe];while(++Xe<this._array.length&&this._getKey(this._array[Xe])===t)}forEachByKey(t,e){if(this._flushCleanupInserted(),this._flushCleanupDeleted(),this._array.length!==0&&(Xe=this._search(t),!(Xe<0||Xe>=this._array.length)&&this._getKey(this._array[Xe])===t))do e(this._array[Xe]);while(++Xe<this._array.length&&this._getKey(this._array[Xe])===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,n=this._getKey(this._array[i]);if(n>t)s=i-1;else if(n<t)e=i+1;else{for(;i>0&&this._getKey(this._array[i-1])===t;)i--;return i}}return e}},ea=0,dh=0,Hj=class extends Ve{constructor(){super(),this._decorations=new Fj(t=>t?.marker.line),this._onDecorationRegistered=this._register(new re),this.onDecorationRegistered=this._onDecorationRegistered.event,this._onDecorationRemoved=this._register(new re),this.onDecorationRemoved=this._onDecorationRemoved.event,this._register(Fe(()=>this.reset()))}get decorations(){return this._decorations.values()}registerDecoration(t){if(t.marker.isDisposed)return;let e=new Wj(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,n=0;for(let o of this._decorations.getKeyIterator(e))i=o.options.x??0,n=i+(o.options.width??1),t>=i&&t<n&&(!s||(o.options.layer??"bottom")===s)&&(yield o)}forEachDecorationAtCell(t,e,s,i){this._decorations.forEachByKey(e,n=>{ea=n.options.x??0,dh=ea+(n.options.width??1),t>=ea&&t<dh&&(!s||(n.options.layer??"bottom")===s)&&i(n)})}},Wj=class extends ti{constructor(t){super(),this.options=t,this.onRenderEmitter=this.add(new re),this.onRender=this.onRenderEmitter.event,this._onDispose=this.add(new re),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=Ue.toColor(this.options.backgroundColor):this._cachedBg=void 0),this._cachedBg}get foregroundColorRGB(){return this._cachedFg===null&&(this.options.foregroundColor?this._cachedFg=Ue.toColor(this.options.foregroundColor):this._cachedFg=void 0),this._cachedFg}dispose(){this._onDispose.fire(),super.dispose()}},Uj=1e3,Kj=class{constructor(t,e=Uj){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 n=i-this._lastRefreshMs,o=this._debounceThresholdMS-n;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)}},hh=20,Qn=class extends Ve{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 n=this._coreBrowserService.mainDocument;this._accessibilityContainer=n.createElement("div"),this._accessibilityContainer.classList.add("xterm-accessibility"),this._rowContainer=n.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=n.createElement("div"),this._liveRegion.classList.add("live-region"),this._liveRegion.setAttribute("aria-live","assertive"),this._accessibilityContainer.appendChild(this._liveRegion),this._liveRegionDebouncer=this._register(new Kj(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(`
441
441
  `))),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(ye(n,"selectionchange",()=>this._handleSelectionChange())),this._register(this._coreBrowserService.onDprChange(()=>this._refreshRowsDimensions())),this._refreshRowsDimensions(),this._refreshRows(),this._register(Fe(()=>{this._accessibilityContainer.remove(),this._rowElements.length=0}))}_handleTab(t){for(let e=0;e<t;e++)this._handleChar(" ")}_handleChar(t){this._liveRegionLineCount<hh+1&&(this._charsToConsume.length>0?this._charsToConsume.shift()!==t&&(this._charsToAnnounce+=t):this._charsToAnnounce+=t,t===`
442
- `&&(this._liveRegionLineCount++,this._liveRegionLineCount===hh+1&&(this._liveRegion.textContent+=wa.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 n=t;n<=e;n++){let o=s.lines.get(s.ydisp+n),a=[],l=o?.translateToString(!0,void 0,void 0,a)||"",c=(s.ydisp+n+1).toString(),d=this._rowElements[n];d&&(l.length===0?(d.textContent=" ",this._rowColumns.set(d,[0,1])):(d.textContent=l,this._rowColumns.set(d,a)),d.setAttribute("aria-posinset",c),d.setAttribute("aria-setsize",i),this._alignRowWidth(d))}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],n=s.getAttribute("aria-posinset"),o=e===0?"1":`${this._terminal.buffer.lines.length}`;if(n===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 c=this._createAccessibilityTreeNode();this._rowElements.unshift(c),this._rowContainer.insertAdjacentElement("afterbegin",c)}else{let c=this._createAccessibilityTreeNode();this._rowElements.push(c),this._rowContainer.appendChild(c)}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 n=({node:l,offset:c})=>{let d=l instanceof Text?l.parentNode:l,u=parseInt(d?.getAttribute("aria-posinset"),10)-1;if(isNaN(u))return console.warn("row is invalid. Race condition?"),null;let h=this._rowColumns.get(d);if(!h)return console.warn("columns is null. Race condition?"),null;let f=c<h.length?h[c]:h.slice(-1)[0]+1;return f>=this._terminal.cols&&(++u,f=0),{row:u,column:f}},o=n(e),a=n(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})`}};Qn=Ye([ce(1,Jl),ce(2,Hs),ce(3,Ws)],Qn);var rl=class extends Ve{constructor(t,e,s,i,n){super(),this._element=t,this._mouseService=e,this._renderService=s,this._bufferService=i,this._linkProviderService=n,this._linkCacheDisposables=[],this._isMouseOut=!0,this._wasResized=!1,this._activeLine=-1,this._onShowLinkUnderline=this._register(new re),this.onShowLinkUnderline=this._onShowLinkUnderline.event,this._onHideLinkUnderline=this._register(new re),this.onHideLinkUnderline=this._onHideLinkUnderline.event,this._register(Fe(()=>{_i(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(ye(this._element,"mouseleave",()=>{this._isMouseOut=!0,this._clearCurrentLink()})),this._register(ye(this._element,"mousemove",this._handleMouseMove.bind(this))),this._register(ye(this._element,"mousedown",this._handleMouseDown.bind(this))),this._register(ye(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 n=s[i];if(n.classList.contains("xterm"))break;if(n.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(n=>{n.link.dispose&&n.link.dispose()})}),this._activeProviderReplies=new Map,this._activeLine=t.y);let s=!1;for(let[i,n]of this._linkProviderService.linkProviders.entries())e?this._activeProviderReplies?.get(i)&&(s=this._checkLinkProviderResult(i,t,s)):n.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 n=e.get(i);if(n)for(let o=0;o<n.length;o++){let a=n[o],l=a.link.range.start.y<t?0:a.link.range.start.x,c=a.link.range.end.y>t?this._bufferService.cols:a.link.range.end.x;for(let d=l;d<=c;d++){if(s.has(d)){n.splice(o--,1);break}s.add(d)}}}}_checkLinkProviderResult(t,e,s){if(!this._activeProviderReplies)return s;let i=this._activeProviderReplies.get(t),n=!1;for(let o=0;o<t;o++)(!this._activeProviderReplies.has(o)||this._activeProviderReplies.get(o))&&(n=!0);if(!n&&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&&Wj(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,_i(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,n=this._bufferService.buffer.ydisp+1+s.end;if(this._currentLink.link.range.start.y>=i&&this._currentLink.link.range.end.y<=n&&(this._clearCurrentLink(i,n),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,n=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(n)}_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,n=e.y*this._bufferService.cols+e.x;return s<=n&&n<=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,n){return{x1:t,y1:e,x2:s,y2:i,cols:this._bufferService.cols,fg:n}}};rl=Ye([ce(1,Ql),ce(2,Ws),ce(3,Lt),ce(4,nm)],rl);function Wj(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 Uj=class extends Pj{constructor(t={}){super(t),this._linkifier=this._register(new zi),this.browser=Vm,this._keyDownHandled=!1,this._keyDownSeen=!1,this._keyPressHandled=!1,this._unprocessedDeadKey=!1,this._accessibilityManager=this._register(new zi),this._onCursorMove=this._register(new re),this.onCursorMove=this._onCursorMove.event,this._onKey=this._register(new re),this.onKey=this._onKey.event,this._onRender=this._register(new re),this.onRender=this._onRender.event,this._onSelectionChange=this._register(new re),this.onSelectionChange=this._onSelectionChange.event,this._onTitleChange=this._register(new re),this.onTitleChange=this._onTitleChange.event,this._onBell=this._register(new re),this.onBell=this._onBell.event,this._onFocus=this._register(new re),this._onBlur=this._register(new re),this._onA11yCharEmitter=this._register(new re),this._onA11yTabEmitter=this._register(new re),this._onWillOpen=this._register(new re),this._setup(),this._decorationService=this._instantiationService.createInstance($j),this._instantiationService.setService(tn,this._decorationService),this._linkProviderService=this._instantiationService.createInstance(D3),this._instantiationService.setService(nm,this._linkProviderService),this._linkProviderService.registerLinkProvider(this._instantiationService.createInstance(Ca)),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(yt.forward(this._inputHandler.onCursorMove,this._onCursorMove)),this._register(yt.forward(this._inputHandler.onTitleChange,this._onTitleChange)),this._register(yt.forward(this._inputHandler.onA11yChar,this._onA11yCharEmitter)),this._register(yt.forward(this._inputHandler.onA11yTab,this._onA11yTabEmitter)),this._register(this._bufferService.onResize(e=>this._afterResize(e.cols,e.rows))),this._register(Fe(()=>{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 n=Le.toColorRGB(s==="ansi"?this._themeService.colors.ansi[e.index]:this._themeService.colors[s]);this.coreService.triggerDataEvent(`${Z.ESC}]${i};${Ej(n)}${Sm.ST}`);break;case 1:if(s==="ansi")this._themeService.modifyColors(o=>o.ansi[e.index]=et.toColor(...e.color));else{let o=s;this._themeService.modifyColors(a=>a[o]=et.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(Qn,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,n=e.getWidth(s),o=this._renderService.dimensions.css.cell.width*n,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(ye(this.element,"copy",e=>{this.hasSelection()&&YV(e,this._selectionService)}));let t=e=>XV(e,this.textarea,this.coreService,this.optionsService);this._register(ye(this.textarea,"paste",t)),this._register(ye(this.element,"paste",t)),Cm?this._register(ye(this.element,"mousedown",e=>{e.button===2&&yd(e,this.textarea,this.screenElement,this._selectionService,this.options.rightClickSelectsWord)})):this._register(ye(this.element,"contextmenu",e=>{yd(e,this.textarea,this.screenElement,this._selectionService,this.options.rightClickSelectsWord)})),oc&&this._register(ye(this.element,"auxclick",e=>{e.button===1&&Xf(e,this.textarea,this.screenElement)}))}_bindKeys(){this._register(ye(this.textarea,"keyup",t=>this._keyUp(t),!0)),this._register(ye(this.textarea,"keydown",t=>this._keyDown(t),!0)),this._register(ye(this.textarea,"keypress",t=>this._keyPress(t),!0)),this._register(ye(this.textarea,"compositionstart",()=>this._compositionHelper.compositionstart())),this._register(ye(this.textarea,"compositionupdate",t=>this._compositionHelper.compositionupdate(t))),this._register(ye(this.textarea,"compositionend",()=>this._compositionHelper.compositionend())),this._register(ye(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(ye(this.screenElement,"mousemove",n=>this.updateCursorStyle(n))),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",Sa.get()),Nm||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(R3,this.textarea,t.ownerDocument.defaultView??window,this._document??typeof window<"u"?window.document:null)),this._instantiationService.setService(Hs,this._coreBrowserService),this._register(ye(this.textarea,"focus",n=>this._handleTextAreaFocus(n))),this._register(ye(this.textarea,"blur",()=>this._handleTextAreaBlur())),this._helperContainer.appendChild(this.textarea),this._charSizeService=this._instantiationService.createInstance(Ka,this._document,this._helperContainer),this._instantiationService.setService(vo,this._charSizeService),this._themeService=this._instantiationService.createInstance(Xa),this._instantiationService.setService(Xi,this._themeService),this._characterJoinerService=this._instantiationService.createInstance(Yn),this._instantiationService.setService(rm,this._characterJoinerService),this._renderService=this._register(this._instantiationService.createInstance(Ga,this.rows,this.screenElement)),this._instantiationService.setService(Ws,this._renderService),this._register(this._renderService.onRenderedViewportChange(n=>this._onRender.fire(n))),this.onResize(n=>this._renderService.resize(n.cols,n.rows)),this._compositionView=this._document.createElement("div"),this._compositionView.classList.add("composition-view"),this._compositionHelper=this._instantiationService.createInstance(Ha,this.textarea,this._compositionView),this._helperContainer.appendChild(this._compositionView),this._mouseService=this._instantiationService.createInstance(qa),this._instantiationService.setService(Ql,this._mouseService);let i=this._linkifier.value=this._register(this._instantiationService.createInstance(rl,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(za,this.element,this.screenElement)),this._register(this._viewport.onRequestScrollLines(n=>{super.scrollLines(n,!1),this.refresh(0,this.rows-1)})),this._selectionService=this._register(this._instantiationService.createInstance(Ya,this.element,this.screenElement,i)),this._instantiationService.setService(rC,this._selectionService),this._register(this._selectionService.onRequestScrollLines(n=>this.scrollLines(n.amount,n.suppressScrollEvent))),this._register(this._selectionService.onSelectionChange(()=>this._onSelectionChange.fire())),this._register(this._selectionService.onRequestRedraw(n=>this._renderService.handleSelectionChanged(n.start,n.end,n.columnSelectMode))),this._register(this._selectionService.onLinuxMouseSelection(n=>{this.textarea.value=n,this.textarea.focus(),this.textarea.select()})),this._register(yt.any(this._onScroll.event,this._inputHandler.onScroll)(()=>{this._selectionService.refresh(),this._viewport?.queueSync()})),this._register(this._instantiationService.createInstance(Fa,this.screenElement)),this._register(ye(this.element,"mousedown",n=>this._selectionService.handleMouseDown(n))),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(Qn,this)),this._register(this.optionsService.onSpecificOptionChange("screenReaderMode",n=>this._handleScreenReaderModeOptionChange(n))),this.options.overviewRuler.width&&(this._overviewRulerRenderer=this._register(this._instantiationService.createInstance(Gn,this._viewportElement,this.screenElement))),this.optionsService.onSpecificOptionChange("overviewRuler",n=>{!this._overviewRulerRenderer&&n&&this._viewportElement&&this.screenElement&&(this._overviewRulerRenderer=this._register(this._instantiationService.createInstance(Gn,this._viewportElement,this.screenElement)))}),this._charSizeService.measure(),this.refresh(0,this.rows-1),this._initGlobal(),this.bindMouse()}_createRenderer(){return this._instantiationService.createInstance(Ua,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,c;switch(o.overrideType||o.type){case"mousemove":c=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":c=0,l=o.button<3?o.button:3;break;case"mousedown":c=1,l=o.button<3?o.button:3;break;case"wheel":if(t._customWheelEventHandler&&t._customWheelEventHandler(o)===!1)return!1;let d=o.deltaY;if(d===0||t.coreMouseService.consumeWheelEvent(o,t._renderService?.dimensions?.device?.cell?.height,t._coreBrowserService?.dpr)===0)return!1;c=d<0?0:1,l=4;break;default:return!1}return c===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:c,ctrl:o.ctrlKey,alt:o.altKey,shift:o.shiftKey})}let i={mouseup:null,wheel:null,mousedrag:null,mousemove:null},n={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",n.mousemove),i.mousemove=n.mousemove):(e.removeEventListener("mousemove",i.mousemove),i.mousemove=null),o&16?i.wheel||(e.addEventListener("wheel",n.wheel,{passive:!1}),i.wheel=n.wheel):(e.removeEventListener("wheel",i.wheel),i.wheel=null),o&2?i.mouseup||(i.mouseup=n.mouseup):(this._document.removeEventListener("mouseup",i.mouseup),i.mouseup=null),o&4?i.mousedrag||(i.mousedrag=n.mousedrag):(this._document.removeEventListener("mousemove",i.mousedrag),i.mousedrag=null)})),this.coreMouseService.activeProtocol=this.coreMouseService.activeProtocol,this._register(ye(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(ye(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){Yf(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=Bj(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)&&(Kj(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(Ze));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),n=this._renderService.dimensions.css.cell.height.toFixed(0);this.coreService.triggerDataEvent(`${Z.ESC}[6;${n};${i}t`);break}}cancel(t,e){if(!(!this.options.cancelEvents&&!e))return t.preventDefault(),t.stopPropagation(),!1}};function Kj(t){return t.keyCode===16||t.keyCode===17||t.keyCode===18}var qj=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)}},Gj=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 as)}translateToString(t,e,s){return this._line.translateToString(t,e,s)}},uh=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 Gj(e)}getNullCell(){return new as}},Yj=class extends Ve{constructor(t){super(),this._core=t,this._onBufferChange=this._register(new re),this.onBufferChange=this._onBufferChange.event,this._normal=new uh(this._core.buffers.normal,"normal"),this._alternate=new uh(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)}},Xj=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)}},Jj=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}},Qj=["cols","rows"],vs=0,Zj=class extends Ve{constructor(t){super(),this._core=this._register(new Uj(t)),this._addonManager=this._register(new qj),this._publicOptions={...this._core.options};let e=i=>this._core.options[i],s=(i,n)=>{this._checkReadonlyOptions(i),this._core.options[i]=n};for(let i in this._core.options){let n={get:e.bind(this,i),set:s.bind(this,i)};Object.defineProperty(this._publicOptions,i,n)}}_checkReadonlyOptions(t){if(Qj.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 Xj(this._core)),this._parser}get unicode(){return this._checkProposedApi(),new Jj(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 Yj(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
443
- `,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 Sa.get()},set promptLabel(t){Sa.set(t)},get tooMuchOutput(){return wa.get()},set tooMuchOutput(t){wa.set(t)}}}_verifyIntegers(...t){for(vs of t)if(vs===1/0||isNaN(vs)||vs%1!==0)throw new Error("This API only accepts integers")}_verifyPositiveIntegers(...t){for(vs of t)if(vs&&(vs===1/0||isNaN(vs)||vs%1!==0||vs<0))throw new Error("This API only accepts positive integers")}};var e5=2,t5=1,s5=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")),n=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,c=a.right+a.left,d=i-l,u=n-c-e;return{cols:Math.max(e5,Math.floor(u/t.css.cell.width)),rows:Math.max(t5,Math.floor(d/t.css.cell.height))}}};function i5({onReady:t,onSelectionChange:e,initialData:s,className:i}){const n=S.useRef(null),o=S.useRef(null),a=S.useRef(e);return a.current=e,S.useEffect(()=>{const l=n.current;if(!l)return;const c=getComputedStyle(document.documentElement),d=p=>c.getPropertyValue(p).trim()||void 0,u=new Zj({allowTransparency:!1,fontFamily:d("--font-mono")||"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",fontSize:12.5,lineHeight:1.5,scrollback:5e3,cursorBlink:!1,disableStdin:!0,theme:{background:d("--sidebar")||d("--card")||d("--background")||"#1e1e1e",cursor:"transparent",foreground:d("--foreground")||"#d4d4d4",selectionBackground:d("--accent"),selectionForeground:d("--accent-foreground"),black:d("--muted"),red:d("--destructive"),green:d("--success"),yellow:d("--warning"),blue:d("--chart-1"),magenta:d("--chart-3"),cyan:d("--chart-5"),white:d("--foreground"),brightBlack:d("--muted-foreground"),brightRed:d("--destructive"),brightGreen:d("--success"),brightYellow:d("--warning"),brightBlue:d("--chart-1"),brightMagenta:d("--chart-3"),brightCyan:d("--chart-5"),brightWhite:d("--foreground")}}),h=new s5;u.loadAddon(h),u.open(l),h.fit(),s&&u.write(s),o.current=u,t?.(u);const f=u.onSelectionChange(()=>{const p=!!u.getSelection();a.current?.(p,()=>u.getSelection())}),m=new ResizeObserver(()=>{h.fit()});return m.observe(l),()=>{f.dispose(),m.disconnect(),o.current=null,u.dispose()}},[]),r.jsx("div",{ref:n,className:X("overflow-hidden bg-sidebar px-4 py-3 [&_.xterm]:h-full [&_.xterm-screen]:min-h-full [&_.xterm-viewport]:overscroll-contain",i)})}function r5(){const t=B.c(2),s=ac()?.entity;let i;return t[0]!==s?(i=Fs(s),t[0]=s,t[1]=i):i=t[1],i}const n5={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"}},o5=["dev","start"];function fh(t){return t?.previewUrl?t.previewUrl.replace(/\/$/,""):null}function a5({daemonOpen:t=!1}){const{org:e}=be(),s=ac(),i=Mt(),{data:n}=St.useSession(),{currentBranch:o,setCurrentTaskBranch:a}=es(),l=n?.user?.id,c=s?.entity?.metadata,d=l&&o?c?.vmMap?.[l]?.[o]:void 0,u=d&&o?{previewUrl:d.previewUrl,vmId:d.vmId,branch:o,runnerKind:d.runnerKind}:null,[h,f]=S.useState(null),[m,p]=S.useState(""),[g,_]=S.useState(""),[v,x]=S.useState(!1),[b,y]=S.useState(new Set),C=S.useRef(!1),j=S.useRef(Date.now()),[V,w]=S.useState("setup"),[k,T]=S.useState([]),I=S.useRef(new Map),{sendMessage:A}=Zn(),{setChatOpen:N}=zr(),[E,R]=S.useState(!1),M=S.useRef(null),L=Q=>{w(Q),R(!1),M.current=null},D=(Q,ae,Se)=>{Q===V&&(R(ae),M.current=ae?Se:null)},P=()=>{const Q=M.current?.();if(!Q)return;N(!0),A({parts:[{type:"text",text:`<server-logs>
442
+ `&&(this._liveRegionLineCount++,this._liveRegionLineCount===hh+1&&(this._liveRegion.textContent+=wa.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 n=t;n<=e;n++){let o=s.lines.get(s.ydisp+n),a=[],l=o?.translateToString(!0,void 0,void 0,a)||"",c=(s.ydisp+n+1).toString(),d=this._rowElements[n];d&&(l.length===0?(d.textContent=" ",this._rowColumns.set(d,[0,1])):(d.textContent=l,this._rowColumns.set(d,a)),d.setAttribute("aria-posinset",c),d.setAttribute("aria-setsize",i),this._alignRowWidth(d))}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],n=s.getAttribute("aria-posinset"),o=e===0?"1":`${this._terminal.buffer.lines.length}`;if(n===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 c=this._createAccessibilityTreeNode();this._rowElements.unshift(c),this._rowContainer.insertAdjacentElement("afterbegin",c)}else{let c=this._createAccessibilityTreeNode();this._rowElements.push(c),this._rowContainer.appendChild(c)}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 n=({node:l,offset:c})=>{let d=l instanceof Text?l.parentNode:l,u=parseInt(d?.getAttribute("aria-posinset"),10)-1;if(isNaN(u))return console.warn("row is invalid. Race condition?"),null;let h=this._rowColumns.get(d);if(!h)return console.warn("columns is null. Race condition?"),null;let f=c<h.length?h[c]:h.slice(-1)[0]+1;return f>=this._terminal.cols&&(++u,f=0),{row:u,column:f}},o=n(e),a=n(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})`}};Qn=Ye([ce(1,Jl),ce(2,Hs),ce(3,Ws)],Qn);var rl=class extends Ve{constructor(t,e,s,i,n){super(),this._element=t,this._mouseService=e,this._renderService=s,this._bufferService=i,this._linkProviderService=n,this._linkCacheDisposables=[],this._isMouseOut=!0,this._wasResized=!1,this._activeLine=-1,this._onShowLinkUnderline=this._register(new re),this.onShowLinkUnderline=this._onShowLinkUnderline.event,this._onHideLinkUnderline=this._register(new re),this.onHideLinkUnderline=this._onHideLinkUnderline.event,this._register(Fe(()=>{_i(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(ye(this._element,"mouseleave",()=>{this._isMouseOut=!0,this._clearCurrentLink()})),this._register(ye(this._element,"mousemove",this._handleMouseMove.bind(this))),this._register(ye(this._element,"mousedown",this._handleMouseDown.bind(this))),this._register(ye(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 n=s[i];if(n.classList.contains("xterm"))break;if(n.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(n=>{n.link.dispose&&n.link.dispose()})}),this._activeProviderReplies=new Map,this._activeLine=t.y);let s=!1;for(let[i,n]of this._linkProviderService.linkProviders.entries())e?this._activeProviderReplies?.get(i)&&(s=this._checkLinkProviderResult(i,t,s)):n.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 n=e.get(i);if(n)for(let o=0;o<n.length;o++){let a=n[o],l=a.link.range.start.y<t?0:a.link.range.start.x,c=a.link.range.end.y>t?this._bufferService.cols:a.link.range.end.x;for(let d=l;d<=c;d++){if(s.has(d)){n.splice(o--,1);break}s.add(d)}}}}_checkLinkProviderResult(t,e,s){if(!this._activeProviderReplies)return s;let i=this._activeProviderReplies.get(t),n=!1;for(let o=0;o<t;o++)(!this._activeProviderReplies.has(o)||this._activeProviderReplies.get(o))&&(n=!0);if(!n&&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&&qj(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,_i(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,n=this._bufferService.buffer.ydisp+1+s.end;if(this._currentLink.link.range.start.y>=i&&this._currentLink.link.range.end.y<=n&&(this._clearCurrentLink(i,n),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,n=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(n)}_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,n=e.y*this._bufferService.cols+e.x;return s<=n&&n<=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,n){return{x1:t,y1:e,x2:s,y2:i,cols:this._bufferService.cols,fg:n}}};rl=Ye([ce(1,Ql),ce(2,Ws),ce(3,Lt),ce(4,om)],rl);function qj(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 Gj=class extends Oj{constructor(t={}){super(t),this._linkifier=this._register(new zi),this.browser=Cm,this._keyDownHandled=!1,this._keyDownSeen=!1,this._keyPressHandled=!1,this._unprocessedDeadKey=!1,this._accessibilityManager=this._register(new zi),this._onCursorMove=this._register(new re),this.onCursorMove=this._onCursorMove.event,this._onKey=this._register(new re),this.onKey=this._onKey.event,this._onRender=this._register(new re),this.onRender=this._onRender.event,this._onSelectionChange=this._register(new re),this.onSelectionChange=this._onSelectionChange.event,this._onTitleChange=this._register(new re),this.onTitleChange=this._onTitleChange.event,this._onBell=this._register(new re),this.onBell=this._onBell.event,this._onFocus=this._register(new re),this._onBlur=this._register(new re),this._onA11yCharEmitter=this._register(new re),this._onA11yTabEmitter=this._register(new re),this._onWillOpen=this._register(new re),this._setup(),this._decorationService=this._instantiationService.createInstance(Hj),this._instantiationService.setService(tn,this._decorationService),this._linkProviderService=this._instantiationService.createInstance(L3),this._instantiationService.setService(om,this._linkProviderService),this._linkProviderService.registerLinkProvider(this._instantiationService.createInstance(Ca)),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(yt.forward(this._inputHandler.onCursorMove,this._onCursorMove)),this._register(yt.forward(this._inputHandler.onTitleChange,this._onTitleChange)),this._register(yt.forward(this._inputHandler.onA11yChar,this._onA11yCharEmitter)),this._register(yt.forward(this._inputHandler.onA11yTab,this._onA11yTabEmitter)),this._register(this._bufferService.onResize(e=>this._afterResize(e.cols,e.rows))),this._register(Fe(()=>{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 n=Le.toColorRGB(s==="ansi"?this._themeService.colors.ansi[e.index]:this._themeService.colors[s]);this.coreService.triggerDataEvent(`${Z.ESC}]${i};${Tj(n)}${wm.ST}`);break;case 1:if(s==="ansi")this._themeService.modifyColors(o=>o.ansi[e.index]=et.toColor(...e.color));else{let o=s;this._themeService.modifyColors(a=>a[o]=et.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(Qn,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,n=e.getWidth(s),o=this._renderService.dimensions.css.cell.width*n,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(ye(this.element,"copy",e=>{this.hasSelection()&&QV(e,this._selectionService)}));let t=e=>ZV(e,this.textarea,this.coreService,this.optionsService);this._register(ye(this.textarea,"paste",t)),this._register(ye(this.element,"paste",t)),jm?this._register(ye(this.element,"mousedown",e=>{e.button===2&&yd(e,this.textarea,this.screenElement,this._selectionService,this.options.rightClickSelectsWord)})):this._register(ye(this.element,"contextmenu",e=>{yd(e,this.textarea,this.screenElement,this._selectionService,this.options.rightClickSelectsWord)})),oc&&this._register(ye(this.element,"auxclick",e=>{e.button===1&&Jf(e,this.textarea,this.screenElement)}))}_bindKeys(){this._register(ye(this.textarea,"keyup",t=>this._keyUp(t),!0)),this._register(ye(this.textarea,"keydown",t=>this._keyDown(t),!0)),this._register(ye(this.textarea,"keypress",t=>this._keyPress(t),!0)),this._register(ye(this.textarea,"compositionstart",()=>this._compositionHelper.compositionstart())),this._register(ye(this.textarea,"compositionupdate",t=>this._compositionHelper.compositionupdate(t))),this._register(ye(this.textarea,"compositionend",()=>this._compositionHelper.compositionend())),this._register(ye(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(ye(this.screenElement,"mousemove",n=>this.updateCursorStyle(n))),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",Sa.get()),Am||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(M3,this.textarea,t.ownerDocument.defaultView??window,this._document??typeof window<"u"?window.document:null)),this._instantiationService.setService(Hs,this._coreBrowserService),this._register(ye(this.textarea,"focus",n=>this._handleTextAreaFocus(n))),this._register(ye(this.textarea,"blur",()=>this._handleTextAreaBlur())),this._helperContainer.appendChild(this.textarea),this._charSizeService=this._instantiationService.createInstance(Ka,this._document,this._helperContainer),this._instantiationService.setService(vo,this._charSizeService),this._themeService=this._instantiationService.createInstance(Xa),this._instantiationService.setService(Xi,this._themeService),this._characterJoinerService=this._instantiationService.createInstance(Yn),this._instantiationService.setService(nm,this._characterJoinerService),this._renderService=this._register(this._instantiationService.createInstance(Ga,this.rows,this.screenElement)),this._instantiationService.setService(Ws,this._renderService),this._register(this._renderService.onRenderedViewportChange(n=>this._onRender.fire(n))),this.onResize(n=>this._renderService.resize(n.cols,n.rows)),this._compositionView=this._document.createElement("div"),this._compositionView.classList.add("composition-view"),this._compositionHelper=this._instantiationService.createInstance(Ha,this.textarea,this._compositionView),this._helperContainer.appendChild(this._compositionView),this._mouseService=this._instantiationService.createInstance(qa),this._instantiationService.setService(Ql,this._mouseService);let i=this._linkifier.value=this._register(this._instantiationService.createInstance(rl,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(za,this.element,this.screenElement)),this._register(this._viewport.onRequestScrollLines(n=>{super.scrollLines(n,!1),this.refresh(0,this.rows-1)})),this._selectionService=this._register(this._instantiationService.createInstance(Ya,this.element,this.screenElement,i)),this._instantiationService.setService(aC,this._selectionService),this._register(this._selectionService.onRequestScrollLines(n=>this.scrollLines(n.amount,n.suppressScrollEvent))),this._register(this._selectionService.onSelectionChange(()=>this._onSelectionChange.fire())),this._register(this._selectionService.onRequestRedraw(n=>this._renderService.handleSelectionChanged(n.start,n.end,n.columnSelectMode))),this._register(this._selectionService.onLinuxMouseSelection(n=>{this.textarea.value=n,this.textarea.focus(),this.textarea.select()})),this._register(yt.any(this._onScroll.event,this._inputHandler.onScroll)(()=>{this._selectionService.refresh(),this._viewport?.queueSync()})),this._register(this._instantiationService.createInstance(Fa,this.screenElement)),this._register(ye(this.element,"mousedown",n=>this._selectionService.handleMouseDown(n))),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(Qn,this)),this._register(this.optionsService.onSpecificOptionChange("screenReaderMode",n=>this._handleScreenReaderModeOptionChange(n))),this.options.overviewRuler.width&&(this._overviewRulerRenderer=this._register(this._instantiationService.createInstance(Gn,this._viewportElement,this.screenElement))),this.optionsService.onSpecificOptionChange("overviewRuler",n=>{!this._overviewRulerRenderer&&n&&this._viewportElement&&this.screenElement&&(this._overviewRulerRenderer=this._register(this._instantiationService.createInstance(Gn,this._viewportElement,this.screenElement)))}),this._charSizeService.measure(),this.refresh(0,this.rows-1),this._initGlobal(),this.bindMouse()}_createRenderer(){return this._instantiationService.createInstance(Ua,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,c;switch(o.overrideType||o.type){case"mousemove":c=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":c=0,l=o.button<3?o.button:3;break;case"mousedown":c=1,l=o.button<3?o.button:3;break;case"wheel":if(t._customWheelEventHandler&&t._customWheelEventHandler(o)===!1)return!1;let d=o.deltaY;if(d===0||t.coreMouseService.consumeWheelEvent(o,t._renderService?.dimensions?.device?.cell?.height,t._coreBrowserService?.dpr)===0)return!1;c=d<0?0:1,l=4;break;default:return!1}return c===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:c,ctrl:o.ctrlKey,alt:o.altKey,shift:o.shiftKey})}let i={mouseup:null,wheel:null,mousedrag:null,mousemove:null},n={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",n.mousemove),i.mousemove=n.mousemove):(e.removeEventListener("mousemove",i.mousemove),i.mousemove=null),o&16?i.wheel||(e.addEventListener("wheel",n.wheel,{passive:!1}),i.wheel=n.wheel):(e.removeEventListener("wheel",i.wheel),i.wheel=null),o&2?i.mouseup||(i.mouseup=n.mouseup):(this._document.removeEventListener("mouseup",i.mouseup),i.mouseup=null),o&4?i.mousedrag||(i.mousedrag=n.mousedrag):(this._document.removeEventListener("mousemove",i.mousedrag),i.mousedrag=null)})),this.coreMouseService.activeProtocol=this.coreMouseService.activeProtocol,this._register(ye(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(ye(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){Xf(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=zj(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)&&(Yj(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(Ze));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),n=this._renderService.dimensions.css.cell.height.toFixed(0);this.coreService.triggerDataEvent(`${Z.ESC}[6;${n};${i}t`);break}}cancel(t,e){if(!(!this.options.cancelEvents&&!e))return t.preventDefault(),t.stopPropagation(),!1}};function Yj(t){return t.keyCode===16||t.keyCode===17||t.keyCode===18}var Xj=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)}},Jj=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 as)}translateToString(t,e,s){return this._line.translateToString(t,e,s)}},uh=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 Jj(e)}getNullCell(){return new as}},Qj=class extends Ve{constructor(t){super(),this._core=t,this._onBufferChange=this._register(new re),this.onBufferChange=this._onBufferChange.event,this._normal=new uh(this._core.buffers.normal,"normal"),this._alternate=new uh(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)}},Zj=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)}},e5=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}},t5=["cols","rows"],vs=0,s5=class extends Ve{constructor(t){super(),this._core=this._register(new Gj(t)),this._addonManager=this._register(new Xj),this._publicOptions={...this._core.options};let e=i=>this._core.options[i],s=(i,n)=>{this._checkReadonlyOptions(i),this._core.options[i]=n};for(let i in this._core.options){let n={get:e.bind(this,i),set:s.bind(this,i)};Object.defineProperty(this._publicOptions,i,n)}}_checkReadonlyOptions(t){if(t5.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 Zj(this._core)),this._parser}get unicode(){return this._checkProposedApi(),new e5(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 Qj(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
443
+ `,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 Sa.get()},set promptLabel(t){Sa.set(t)},get tooMuchOutput(){return wa.get()},set tooMuchOutput(t){wa.set(t)}}}_verifyIntegers(...t){for(vs of t)if(vs===1/0||isNaN(vs)||vs%1!==0)throw new Error("This API only accepts integers")}_verifyPositiveIntegers(...t){for(vs of t)if(vs&&(vs===1/0||isNaN(vs)||vs%1!==0||vs<0))throw new Error("This API only accepts positive integers")}};var i5=2,r5=1,n5=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")),n=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,c=a.right+a.left,d=i-l,u=n-c-e;return{cols:Math.max(i5,Math.floor(u/t.css.cell.width)),rows:Math.max(r5,Math.floor(d/t.css.cell.height))}}};function o5({onReady:t,onSelectionChange:e,initialData:s,className:i}){const n=S.useRef(null),o=S.useRef(null),a=S.useRef(e);return a.current=e,S.useEffect(()=>{const l=n.current;if(!l)return;const c=getComputedStyle(document.documentElement),d=p=>c.getPropertyValue(p).trim()||void 0,u=new s5({allowTransparency:!1,fontFamily:d("--font-mono")||"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",fontSize:12.5,lineHeight:1.5,scrollback:5e3,cursorBlink:!1,disableStdin:!0,theme:{background:d("--sidebar")||d("--card")||d("--background")||"#1e1e1e",cursor:"transparent",foreground:d("--foreground")||"#d4d4d4",selectionBackground:d("--accent"),selectionForeground:d("--accent-foreground"),black:d("--muted"),red:d("--destructive"),green:d("--success"),yellow:d("--warning"),blue:d("--chart-1"),magenta:d("--chart-3"),cyan:d("--chart-5"),white:d("--foreground"),brightBlack:d("--muted-foreground"),brightRed:d("--destructive"),brightGreen:d("--success"),brightYellow:d("--warning"),brightBlue:d("--chart-1"),brightMagenta:d("--chart-3"),brightCyan:d("--chart-5"),brightWhite:d("--foreground")}}),h=new n5;u.loadAddon(h),u.open(l),h.fit(),s&&u.write(s),o.current=u,t?.(u);const f=u.onSelectionChange(()=>{const p=!!u.getSelection();a.current?.(p,()=>u.getSelection())}),m=new ResizeObserver(()=>{h.fit()});return m.observe(l),()=>{f.dispose(),m.disconnect(),o.current=null,u.dispose()}},[]),r.jsx("div",{ref:n,className:X("overflow-hidden bg-sidebar px-4 py-3 [&_.xterm]:h-full [&_.xterm-screen]:min-h-full [&_.xterm-viewport]:overscroll-contain",i)})}function a5(){const t=B.c(2),s=ac()?.entity;let i;return t[0]!==s?(i=Fs(s),t[0]=s,t[1]=i):i=t[1],i}const l5={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"}},c5=["dev","start"];function fh(t){return t?.previewUrl?t.previewUrl.replace(/\/$/,""):null}function d5({daemonOpen:t=!1}){const{org:e}=be(),s=ac(),i=Mt(),{data:n}=St.useSession(),{currentBranch:o,setCurrentTaskBranch:a}=es(),l=n?.user?.id,c=s?.entity?.metadata,d=l&&o?c?.vmMap?.[l]?.[o]:void 0,u=d&&o?{previewUrl:d.previewUrl,vmId:d.vmId,branch:o,runnerKind:d.runnerKind}:null,[h,f]=S.useState(null),[m,p]=S.useState(""),[g,_]=S.useState(""),[v,x]=S.useState(!1),[b,y]=S.useState(new Set),C=S.useRef(!1),j=S.useRef(Date.now()),[V,w]=S.useState("setup"),[k,T]=S.useState([]),I=S.useRef(new Map),{sendMessage:A}=Zn(),{setChatOpen:N}=zr(),[E,R]=S.useState(!1),M=S.useRef(null),L=Q=>{w(Q),R(!1),M.current=null},D=(Q,ae,Se)=>{Q===V&&(R(ae),M.current=ae?Se:null)},P=()=>{const Q=M.current?.();if(!Q)return;N(!0),A({parts:[{type:"text",text:`<server-logs>
444
444
  ${Q}
445
- </server-logs>`}]}),I.current.get(V)?.clearSelection()},O=Me({connectionId:Wt,orgId:e.id}),z=(Q,ae)=>{const Se=I.current.get(Q);Se&&Se.write(ae)},$=Yi();AV(z);const W=SS(s?.entity?.id,o??void 0),F=$.suspended?"suspended":u?"running":W?"creating":"idle",G=h??F;S.useEffect(()=>{h==="creating"&&F==="running"&&f(null),h==="stopping"&&F==="idle"&&f(null)},[F,h]);const q=ql(O),{mutate:H,isPending:ee}=q,K=s?.entity?.id,U=$.notFound?d?.vmId??null:null,te=S.useRef(null);S.useEffect(()=>{if(!U||!K||ee||te.current===U)return;te.current=U;const Q={virtualMcpId:K};o&&(Q.branch=o),H(Q,{onError:ae=>{console.error("[env] reprovision VM_START failed",ae)}})},[U,K,o,ee,H]);const Y=S.useRef(!1);S.useEffect(()=>{if($.scripts.length>0&&!Y.current){Y.current=!0;for(const Q of o5)if($.scripts.includes(Q)){T([Q]),L(Q);break}}},[$.scripts]);const J=async(Q,ae)=>{const Se=await O.callTool({name:Q,arguments:ae}),Ne=Se.content;if(Ne?.[0]?.text?.startsWith("Error:"))throw new Error(Ne[0].text);return Se.structuredContent??Se},ie=async Q=>{if(!(v||!u)){x(!0);try{const ae=fh(d);if(!ae)throw new Error("No VM");const Se=await fetch(`${ae}/_decopilot_vm/exec/${Q}`,{method:"POST"});if(!Se.ok)throw new Error(`Exec failed: ${Se.statusText}`);y(Ne=>{const Be=new Set(Ne);return Be.delete(Q),Be})}finally{x(!1)}}},ue=async Q=>{if(!(v||!u)){x(!0);try{const ae=fh(d);if(!ae)throw new Error("No VM");const Se=await fetch(`${ae}/_decopilot_vm/kill/${Q}`,{method:"POST"});if(!Se.ok)throw new Error(`Kill failed: ${Se.statusText}`);y(Ne=>new Set(Ne).add(Q))}finally{x(!1)}}},de=Q=>{k.includes(Q)||T(ae=>[...ae,Q]),L(Q),ie(Q)},xe=async()=>{if(!C.current){C.current=!0,j.current=Date.now(),f("creating"),p("Connecting..."),_(""),Y.current=!1,T([]),L("setup");try{if(!s?.entity)throw new Error("No virtual MCP context");const Q={virtualMcpId:s.entity.id};o&&(Q.branch=o);const ae=await J("VM_START",Q);if(!ae.vmId||!ae.branch)throw new Error("Invalid VM response — missing fields");o||a(ae.branch),p(""),bn(i)}catch(Q){f("error"),_(Q instanceof Error?Q.message:"Failed to start VM")}finally{C.current=!1}}},oe=async()=>{const Q=u?.branch??o;f("stopping");const ae=s?.entity?.id;if(ae&&Q)try{await O.callTool({name:"VM_DELETE",arguments:{virtualMcpId:ae,branch:Q}})}catch{}bn(i)},he=r5();if(!he)return null;const me=s?.entity?.metadata?.runtime,fe="__none__",le=Object.keys(n5),ve=async(Q,ae)=>{if(s?.entity)try{await O.callTool({name:"COLLECTION_VIRTUAL_MCP_UPDATE",arguments:{id:s.entity.id,data:{metadata:{runtime:{...me,[Q]:ae}}}}}),bn(i)}catch{ge.error("Failed to update setting")}};if(G==="idle"||G==="stopping"){const Q=G==="stopping";return r.jsx("div",{className:"flex flex-col items-center justify-center w-full h-full p-6",children:r.jsxs("div",{className:"flex flex-col gap-4 w-full max-w-xs",children:[r.jsxs("a",{href:`https://github.com/${he.owner}/${he.name}`,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-3 p-4 rounded-lg border border-border hover:bg-accent/50 transition-colors",children:[r.jsx(uu,{size:24}),r.jsxs("div",{className:"flex flex-col gap-0.5 min-w-0 flex-1",children:[r.jsxs("span",{className:"text-sm font-medium truncate",children:[he.owner,"/",he.name]}),r.jsxs("span",{className:"text-xs text-muted-foreground truncate",children:["github.com/",he.owner,"/",he.name]})]}),r.jsx(Vi,{size:14,className:"text-muted-foreground shrink-0"})]}),r.jsxs("div",{className:"flex flex-wrap items-end justify-between gap-2 w-full",children:[r.jsxs("div",{className:"flex flex-col gap-1",children:[r.jsx(vr,{htmlFor:"env-runtime",className:"text-xs font-medium",children:"Runtime"}),r.jsxs(Qs,{value:me?.selected??fe,onValueChange:ae=>ve("selected",ae===fe?null:ae),children:[r.jsx(Zs,{id:"env-runtime",className:"w-28",children:r.jsx(ei,{placeholder:"None"})}),r.jsxs(Js,{children:[r.jsx(Ht,{value:fe,children:"None"}),le.map(ae=>r.jsx(Ht,{value:ae,children:ae},ae))]})]})]}),r.jsxs("div",{className:"flex flex-col gap-1",children:[r.jsx(vr,{htmlFor:"env-port",className:"text-xs font-medium",children:"Port"}),r.jsx(bt,{id:"env-port",placeholder:"3000",className:"w-20 h-8",defaultValue:me?.port??"",onBlur:ae=>ve("port",ae.target.value||null)})]}),r.jsxs(ne,{onClick:xe,disabled:Q,children:[Q?r.jsx(Ee,{size:14,className:"animate-spin"}):r.jsx(Cn,{size:14}),Q?"Stopping...":"Run"]})]})]})})}if(G==="creating")return r.jsxs("div",{className:"flex flex-col items-center justify-center w-full h-full gap-4",children:[r.jsx(Ee,{size:24,className:"animate-spin text-muted-foreground"}),r.jsx("p",{className:"text-sm text-muted-foreground",children:m}),r.jsx(qp,{since:j.current})]});if(G==="error")return r.jsx(qf,{errorMsg:g,onRetry:xe});if(G==="suspended")return r.jsx(Kf,{onResume:xe});const Ce=["setup",...k,...t?["daemon"]:[]],Te=$.scripts.filter(Q=>!k.includes(Q));return r.jsx("div",{className:"flex flex-col w-full h-full",children:r.jsxs("div",{className:"flex flex-col h-full",children:[r.jsxs("div",{className:"flex h-12 items-center border-b border-border px-2 shrink-0",children:[Ce.map(Q=>r.jsx("button",{type:"button",onClick:()=>L(Q),className:X("flex items-center h-full px-3 text-sm whitespace-nowrap border-b-2 mb-[-1px] capitalize transition-all hover:text-foreground",V===Q?"text-foreground border-primary":"text-muted-foreground border-transparent"),children:Q},Q)),Te.length>0&&r.jsxs(js,{children:[r.jsx(ks,{asChild:!0,children:r.jsx("button",{type:"button",className:"flex items-center h-full px-2 text-muted-foreground hover:text-foreground transition-colors",children:r.jsx(Qt,{size:14})})}),r.jsx(Ns,{align:"start",children:Te.map(Q=>r.jsx(ot,{onClick:()=>de(Q),children:Q},Q))})]}),r.jsx("div",{className:"flex-1 flex justify-center",children:u?.vmId&&r.jsxs("div",{className:"flex items-center",children:[r.jsxs(it,{children:[r.jsx(tt,{asChild:!0,children:r.jsx("button",{type:"button",className:"shrink-0 rounded-l bg-muted px-1.5 py-0.5 text-[10px] font-mono text-muted-foreground cursor-pointer hover:bg-accent hover:text-foreground transition-colors border-r border-border/50",onClick:()=>navigator.clipboard.writeText(u?.vmId??""),children:u.vmId})}),r.jsx(st,{side:"bottom",children:"Copy VM ID"})]}),r.jsxs(js,{children:[r.jsx(ks,{asChild:!0,children:r.jsx("button",{type:"button",className:"shrink-0 self-stretch rounded-r bg-muted px-0.5 text-[10px] text-muted-foreground cursor-pointer hover:bg-accent hover:text-foreground transition-colors",children:r.jsx(kr,{size:10})})}),r.jsx(Ns,{align:"center",children:r.jsxs(ot,{onClick:oe,children:[r.jsx(gc,{size:12}),"Stop Server"]})})]})]})}),r.jsxs("div",{className:"flex items-center gap-1",children:[E&&r.jsxs("button",{type:"button",onClick:P,className:"flex items-center gap-1 rounded-md border border-border px-2 py-1 text-xs font-medium text-muted-foreground hover:text-foreground hover:bg-muted transition-colors",children:[r.jsx(kg,{size:12}),"Add to chat"]}),V!=="setup"&&V!=="daemon"&&k.includes(V)&&(()=>{const Q=$.activeProcesses.includes(V)&&!b.has(V);return r.jsxs("div",{className:"flex items-center",children:[r.jsxs("button",{type:"button",disabled:v,onClick:()=>ie(V),className:X("flex items-center gap-1 border border-border px-2 py-1 text-xs font-medium text-muted-foreground hover:text-foreground hover:bg-muted transition-colors disabled:opacity-50",Q?"rounded-l-md border-r-0":"rounded-md"),children:[v?r.jsx(Ee,{size:12,className:"animate-spin"}):r.jsx(Cn,{size:12}),v?"Running...":Q?"Restart":"Run"]}),Q&&r.jsxs(js,{children:[r.jsx(ks,{asChild:!0,children:r.jsx("button",{type:"button",disabled:v,className:"flex items-center self-stretch rounded-r-md border border-border px-1 text-xs text-muted-foreground hover:text-foreground hover:bg-muted transition-colors disabled:opacity-50",children:r.jsx(kr,{size:12})})}),r.jsx(Ns,{align:"end",children:r.jsxs(ot,{onClick:()=>ue(V),children:[r.jsx(gc,{size:12}),"Stop Process"]})})]})]})})()]})]}),r.jsx("div",{className:"flex-1 overflow-hidden",children:Ce.map(Q=>r.jsx("div",{className:X("h-full",V===Q?"block":"hidden"),children:$.hasData(Q)||Q==="setup"||Q==="daemon"?r.jsx(i5,{onReady:ae=>{I.current.set(Q,ae)},onSelectionChange:(ae,Se)=>D(Q,ae,Se),initialData:$.getBuffer(Q),className:"h-full"}):r.jsx(Oi,{className:"h-full",image:null,title:`Script "${Q}" not running`,description:`Click Run to start "${Q}".`,actions:r.jsxs(ne,{variant:"outline",size:"sm",disabled:v,onClick:()=>ie(Q),children:[v?r.jsx(Ee,{size:14,className:"animate-spin"}):r.jsx(Cn,{size:14}),"Run"]})})},Q))})]})})}function l5(t){const e=B.c(2),{virtualMcpId:s}=t,i=ts(s);if(!(i?Fs(i):null)){let a;return e[0]===Symbol.for("react.memo_cache_sentinel")?(a=r.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-2 text-center text-sm text-muted-foreground p-6",children:[r.jsx(ri,{size:24,className:"text-muted-foreground/60"}),r.jsx("div",{children:"No repository connected."}),r.jsx("div",{className:"text-xs text-muted-foreground/80",children:"Connect a GitHub repository from the Connections tab to enable Env."})]}),e[0]=a):a=e[0],a}let o;return e[1]===Symbol.for("react.memo_cache_sentinel")?(o=r.jsx(a5,{}),e[1]=o):o=e[1],o}function Vr(t){const e=t.trim().split(/\s+/);return e.length!==5?!1:e.every(s=>/^[\d*/,-]+$/.test(s))}function c5(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 n=e.match(/^0\s+0\s+\*\/(\d+)\s+\*\s+\*$/);if(n){const l=parseInt(n[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"),c=(o[1]??"0").padStart(2,"0");return`Every day at ${l}:${c} UTC`}const a=e.match(/^(\d+)\s+(\d+)\s+\*\s+\*\s+(\d)$/);if(a){const c=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][parseInt(a[3]??"0")]??"day",d=(a[2]??"0").padStart(2,"0"),u=(a[1]??"0").padStart(2,"0");return`Every ${c} at ${d}:${u} UTC`}return t}function d5(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 h5(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 n=e.match(/^0\s+0\s+\*\/(\d+)\s+\*\s+\*$/);if(n){const o=parseInt(n[1]);return o%7===0?{count:o/7,unit:"weeks"}:{count:o,unit:"days"}}return null}function u5(t,e){return e===1?{minutes:"minute",hours:"hour",days:"day",weeks:"week"}[t]??t:t}const f5=[{label:"Minute",cron:"* * * * *"},{label:"Hour",cron:"0 * * * *"},{label:"Day",cron:"0 0 * * *"},{label:"Week",cron:"0 0 * * 1"}];function m5(t){const e=B.c(33),{automationId:s,open:i,onOpenChange:n,onCustomSelect:o,onEventSelect:a}=t,{triggerAdd:l}=Yr(),[c,d]=S.useState(!1),u=i??c;let h;e[0]!==n?(h=I=>{n?n(I):d(I)},e[0]=n,e[1]=h):h=e[1];const f=h;let m;e[2]!==l||e[3]!==s||e[4]!==f?(m=async I=>{try{await l.mutateAsync({automation_id:s,type:"cron",cron_expression:I}),ge.success("Starter added"),f(!1)}catch(A){const N=A,E=N instanceof Error?N.message:"Failed to add starter";ge.error(E)}},e[2]=l,e[3]=s,e[4]=f,e[5]=m):m=e[5];const p=m;let g;e[6]===Symbol.for("react.memo_cache_sentinel")?(g=r.jsx(ks,{asChild:!0,children:r.jsxs(ne,{variant:"outline",size:"sm",children:[r.jsx(Qt,{size:14}),"Add Starter"]})}),e[6]=g):g=e[6];let _;e[7]===Symbol.for("react.memo_cache_sentinel")?(_=r.jsxs(Bh,{className:"gap-2.5",children:[r.jsx(_r,{size:14,className:"text-muted-foreground shrink-0"}),"Every..."]}),e[7]=_):_=e[7];let v;e[8]!==l||e[9]!==p?(v=f5.map(I=>r.jsxs(ot,{className:"gap-2.5",onSelect:()=>p(I.cron),disabled:l.isPending,children:[r.jsx(_r,{size:14,className:"text-muted-foreground shrink-0"}),"Every ",I.label]},I.cron)),e[8]=l,e[9]=p,e[10]=v):v=e[10];let x;e[11]!==v?(x=r.jsxs(Sn,{children:[_,r.jsx(wn,{className:"w-[160px]",children:v})]}),e[11]=v,e[12]=x):x=e[12];let b;e[13]!==f||e[14]!==o?(b=()=>{f(!1),o?.()},e[13]=f,e[14]=o,e[15]=b):b=e[15];let y;e[16]===Symbol.for("react.memo_cache_sentinel")?(y=r.jsx(_r,{size:14,className:"text-muted-foreground shrink-0"}),e[16]=y):y=e[16];let C;e[17]!==b?(C=r.jsxs(ot,{className:"gap-2.5",onSelect:b,children:[y,"Custom (cron)"]}),e[17]=b,e[18]=C):C=e[18];let j;e[19]!==f||e[20]!==a?(j=()=>{f(!1),a?.()},e[19]=f,e[20]=a,e[21]=j):j=e[21];let V;e[22]===Symbol.for("react.memo_cache_sentinel")?(V=r.jsx($i,{size:14,className:"text-muted-foreground shrink-0"}),e[22]=V):V=e[22];let w;e[23]!==j?(w=r.jsxs(ot,{className:"gap-2.5",onSelect:j,children:[V,"Event"]}),e[23]=j,e[24]=w):w=e[24];let k;e[25]!==w||e[26]!==x||e[27]!==C?(k=r.jsxs(Ns,{align:"end",className:"w-[200px]",children:[x,C,w]}),e[25]=w,e[26]=x,e[27]=C,e[28]=k):k=e[28];let T;return e[29]!==f||e[30]!==u||e[31]!==k?(T=r.jsxs(js,{open:u,onOpenChange:f,children:[g,k]}),e[29]=f,e[30]=u,e[31]=k,e[32]=T):T=e[32],T}function p5(t){const e=B.c(60),{trigger:s,automationId:i,connectionName:n}=t,{triggerAdd:o,triggerRemove:a}=Yr(),[l,c]=S.useState(!1);let d;e[0]!==s.cron_expression?(d=s.cron_expression?h5(s.cron_expression):null,e[0]=s.cron_expression,e[1]=d):d=e[1];const u=d,[h,f]=S.useState(u?.count??1),[m,p]=S.useState(!1),[g,_]=S.useState(s.cron_expression??""),v=a.isPending||o.isPending,x=s.type==="cron";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}),ge.success("Starter removed")}catch{ge.error("Failed to remove starter")}c(!1)},e[2]=i,e[3]=a,e[4]=s.id,e[5]=b):b=e[5];const y=b;let C;e[6]!==o||e[7]!==i||e[8]!==g||e[9]!==a||e[10]!==s.cron_expression||e[11]!==s.id?(C=async()=>{const z=g.trim();if(!z||!Vr(z)||z===s.cron_expression){p(!1),_(s.cron_expression??"");return}try{await o.mutateAsync({automation_id:i,type:"cron",cron_expression:z}),await a.mutateAsync({trigger_id:s.id,automation_id:i}),p(!1)}catch{ge.error("Failed to update starter"),_(s.cron_expression??""),p(!1)}},e[6]=o,e[7]=i,e[8]=g,e[9]=a,e[10]=s.cron_expression,e[11]=s.id,e[12]=C):C=e[12];const j=C;let V;e[13]!==o||e[14]!==i||e[15]!==u||e[16]!==a||e[17]!==s.cron_expression||e[18]!==s.id?(V=async z=>{if(!u)return;const $=Math.max(1,z),W=d5($,u.unit);if(W!==s.cron_expression)try{await o.mutateAsync({automation_id:i,type:"cron",cron_expression:W}),await a.mutateAsync({trigger_id:s.id,automation_id:i})}catch{ge.error("Failed to update starter"),f(u.count)}},e[13]=o,e[14]=i,e[15]=u,e[16]=a,e[17]=s.cron_expression,e[18]=s.id,e[19]=V):V=e[19];const w=V;let k;e[20]!==x?(k=x?r.jsx(_r,{size:14,className:"text-muted-foreground shrink-0"}):r.jsx($i,{size:14,className:"text-muted-foreground shrink-0"}),e[20]=x,e[21]=k):k=e[21];let T;e[22]!==n||e[23]!==h||e[24]!==g||e[25]!==w||e[26]!==j||e[27]!==u||e[28]!==x||e[29]!==m||e[30]!==v||e[31]!==s.cron_expression||e[32]!==s.event_type||e[33]!==s.params?(T=u&&x?r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"text-sm text-muted-foreground",children:"Every"}),r.jsx("input",{type:"number",min:1,value:h,onChange:z=>f(parseInt(z.target.value)||1),onBlur:()=>w(h),onKeyDown:z=>{z.key==="Enter"&&z.target.blur(),z.key==="Escape"&&f(u.count)},disabled:v,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"}),r.jsx("span",{className:"text-sm",children:u5(u.unit,h)})]}):x&&m?r.jsxs(r.Fragment,{children:[r.jsx("input",{type:"text",value:g,onChange:z=>_(z.target.value),onBlur:j,onKeyDown:z=>{z.key==="Enter"&&z.target.blur(),z.key==="Escape"&&(p(!1),_(s.cron_expression??""))},className:"flex-1 text-sm font-mono bg-transparent outline-none",autoFocus:!0}),g&&!Vr(g)&&r.jsx("span",{className:"text-xs text-muted-foreground/60 shrink-0",children:"invalid"})]}):r.jsxs("div",{className:"flex flex-col gap-0.5 flex-1 min-w-0",children:[r.jsx("span",{className:"text-sm font-mono text-xs text-muted-foreground truncate",children:x?c5(s.cron_expression??""):`${s.event_type}${n?` · ${n}`:""}`}),!x&&s.params&&Object.keys(s.params).length>0&&r.jsx("span",{className:"text-xs text-muted-foreground/60 truncate",children:Object.entries(s.params).map(g5).join(", ")})]}),e[22]=n,e[23]=h,e[24]=g,e[25]=w,e[26]=j,e[27]=u,e[28]=x,e[29]=m,e[30]=v,e[31]=s.cron_expression,e[32]=s.event_type,e[33]=s.params,e[34]=T):T=e[34];let I;e[35]!==v?(I=v&&r.jsx(Ee,{size:13,className:"animate-spin text-muted-foreground"}),e[35]=v,e[36]=I):I=e[36];let A;e[37]!==u||e[38]!==x||e[39]!==m||e[40]!==s.cron_expression?(A=x&&!u&&!m&&r.jsx(ne,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 opacity-0 group-hover:opacity-100 transition-opacity",onClick:()=>{_(s.cron_expression??""),p(!0)},children:r.jsx(Ng,{size:13,className:"text-muted-foreground"})}),e[37]=u,e[38]=x,e[39]=m,e[40]=s.cron_expression,e[41]=A):A=e[41];let N;e[42]===Symbol.for("react.memo_cache_sentinel")?(N=r.jsx(ne,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 opacity-0 group-hover:opacity-100 transition-opacity",onClick:()=>c(!0),children:r.jsx(ii,{size:13,className:"text-muted-foreground"})}),e[42]=N):N=e[42];let E;e[43]!==I||e[44]!==A?(E=r.jsxs("div",{className:"ml-auto flex items-center gap-1",children:[I,A,N]}),e[43]=I,e[44]=A,e[45]=E):E=e[45];let R;e[46]!==E||e[47]!==k||e[48]!==T?(R=r.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-2.5 rounded-lg border border-border bg-background group",children:[k,T,E]}),e[46]=E,e[47]=k,e[48]=T,e[49]=R):R=e[49];let M;e[50]===Symbol.for("react.memo_cache_sentinel")?(M=r.jsxs(kl,{children:[r.jsx(Nl,{children:"Remove Starter"}),r.jsx(Al,{children:"Are you sure you want to remove this starter?"})]}),e[50]=M):M=e[50];let L;e[51]===Symbol.for("react.memo_cache_sentinel")?(L=r.jsx(Cl,{children:"Cancel"}),e[51]=L):L=e[51];let D;e[52]!==y?(D=r.jsxs(jl,{children:[M,r.jsxs(El,{children:[L,r.jsx(bu,{onClick:y,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Remove"})]})]}),e[52]=y,e[53]=D):D=e[53];let P;e[54]!==l||e[55]!==D?(P=r.jsx(Il,{open:l,onOpenChange:c,children:D}),e[54]=l,e[55]=D,e[56]=P):P=e[56];let O;return e[57]!==R||e[58]!==P?(O=r.jsxs(r.Fragment,{children:[R,P]}),e[57]=R,e[58]=P,e[59]=O):O=e[59],O}function g5(t){const[e,s]=t;return`${e}: ${s}`}function _5(t){const e=B.c(55),{automationId:s,onDone:i}=t;let n;e[0]===Symbol.for("react.memo_cache_sentinel")?(n={binding:"TRIGGER"},e[0]=n):n=e[0];const o=Wr(n),[a,l]=S.useState(),[c,d]=S.useState();let u;e[1]===Symbol.for("react.memo_cache_sentinel")?(u={},e[1]=u):u=e[1];const[h,f]=S.useState(u),{triggerAdd:m}=Yr(),{data:p,isLoading:g}=D_(a);let _,v,x,b,y,C;if(e[2]!==m||e[3]!==s||e[4]!==a||e[5]!==c||e[6]!==g||e[7]!==i||e[8]!==h||e[9]!==o||e[10]!==p){const w=p?.find(D=>D.type===c);let k;e[17]!==m||e[18]!==s||e[19]!==a||e[20]!==c||e[21]!==i||e[22]!==h?(k=async()=>{if(!(!a||!c))try{await m.mutateAsync({automation_id:s,type:"event",event_type:c,connection_id:a,params:h}),se("automation_trigger_added",{automation_id:s,trigger_type:"event",connection_id:a,event_type:c}),ge.success("Event trigger added"),i()}catch{ge.error("Failed to add event trigger")}},e[17]=m,e[18]=s,e[19]=a,e[20]=c,e[21]=i,e[22]=h,e[23]=k):k=e[23],_=k,v="flex flex-col gap-3 px-3 py-3 rounded-lg border border-border bg-background";let T,I;e[24]===Symbol.for("react.memo_cache_sentinel")?(I=r.jsx($i,{size:14,className:"text-muted-foreground shrink-0"}),T=r.jsx("span",{className:"text-sm font-medium",children:"Event trigger"}),e[24]=T,e[25]=I):(T=e[24],I=e[25]);let A;e[26]===Symbol.for("react.memo_cache_sentinel")?(A=r.jsx(ii,{size:13}),e[26]=A):A=e[26],e[27]!==i?(x=r.jsxs("div",{className:"flex items-center gap-2",children:[I,T,r.jsx("button",{type:"button",className:"ml-auto shrink-0 p-0.5 rounded text-muted-foreground hover:text-foreground",onClick:i,children:A})]}),e[27]=i,e[28]=x):x=e[28];const N=a??"";let E;e[29]===Symbol.for("react.memo_cache_sentinel")?(E=D=>{l(D),d(void 0),f({})},e[29]=E):E=e[29];let R;e[30]===Symbol.for("react.memo_cache_sentinel")?(R=r.jsx(Zs,{className:"w-full",children:r.jsx(ei,{placeholder:"Select connection..."})}),e[30]=R):R=e[30];let M;e[31]!==o?(M=o.length===0?r.jsx("div",{className:"px-2 py-3 text-center text-xs text-muted-foreground",children:"No connections with trigger support"}):o.map(b5),e[31]=o,e[32]=M):M=e[32];let L;e[33]!==M?(L=r.jsx(Js,{children:M}),e[33]=M,e[34]=L):L=e[34],e[35]!==N||e[36]!==L?(b=r.jsxs(Qs,{value:N,onValueChange:E,children:[R,L]}),e[35]=N,e[36]=L,e[37]=b):b=e[37],e[38]!==a||e[39]!==c||e[40]!==g||e[41]!==p?(y=a&&r.jsxs(Qs,{value:c??"",onValueChange:D=>{d(D),f({})},children:[r.jsx(Zs,{className:"w-full",children:g?r.jsxs("span",{className:"flex items-center gap-2 text-muted-foreground",children:[r.jsx(Ee,{size:13,className:"animate-spin"}),"Loading events..."]}):r.jsx(ei,{placeholder:"Select event type...",children:c??"Select event type..."})}),r.jsx(Js,{children:p?.map(v5)})]}),e[38]=a,e[39]=c,e[40]=g,e[41]=p,e[42]=y):y=e[42],C=w?.paramsSchema&&Object.keys(w.paramsSchema).length>0&&r.jsx("div",{className:"flex flex-col gap-2",children:Object.entries(w.paramsSchema).map(D=>{const[P,O]=D;return r.jsxs("div",{className:"flex flex-col gap-1",children:[r.jsxs("label",{className:"text-xs text-muted-foreground",children:[P,O.description&&r.jsxs("span",{className:"text-muted-foreground/60",children:[" ","— ",O.description]})]}),O.enum?r.jsxs(Qs,{value:h[P]??"",onValueChange:z=>f($=>({...$,[P]:z})),children:[r.jsx(Zs,{className:"w-full",children:r.jsx(ei,{placeholder:`Select ${P}...`})}),r.jsx(Js,{children:O.enum.map(x5)})]}):r.jsx("input",{type:"text",value:h[P]??"",onChange:z=>f($=>({...$,[P]:z.target.value})),placeholder:O.description??P,className:"text-sm border border-border rounded-md bg-background px-2 py-1.5 focus:outline-none focus:ring-1 focus:ring-ring"})]},P)})}),e[2]=m,e[3]=s,e[4]=a,e[5]=c,e[6]=g,e[7]=i,e[8]=h,e[9]=o,e[10]=p,e[11]=_,e[12]=v,e[13]=x,e[14]=b,e[15]=y,e[16]=C}else _=e[11],v=e[12],x=e[13],b=e[14],y=e[15],C=e[16];let j;e[43]!==m||e[44]!==a||e[45]!==c||e[46]!==_?(j=a&&c&&r.jsx(ne,{size:"sm",onClick:_,disabled:m.isPending,children:m.isPending?r.jsx(Ee,{size:13,className:"animate-spin"}):"Add trigger"}),e[43]=m,e[44]=a,e[45]=c,e[46]=_,e[47]=j):j=e[47];let V;return e[48]!==v||e[49]!==x||e[50]!==b||e[51]!==y||e[52]!==C||e[53]!==j?(V=r.jsxs("div",{className:v,children:[x,b,y,C,j]}),e[48]=v,e[49]=x,e[50]=b,e[51]=y,e[52]=C,e[53]=j,e[54]=V):V=e[54],V}function x5(t){return r.jsx(Ht,{value:t,children:t},t)}function v5(t){return r.jsx(Ht,{value:t.type,children:r.jsxs("div",{className:"flex flex-col",children:[r.jsx("span",{children:t.type}),r.jsx("span",{className:"text-xs text-muted-foreground",children:t.description})]})},t.type)}function b5(t){return r.jsx(Ht,{value:t.id,children:t.title},t.id)}function y5({automationId:t,automation:e,virtualMcpId:s,onBack:i,onDelete:n}){const o=e.agent?.id??s,{org:a}=be(),{update:l,triggerAdd:c}=Yr(),d=Wr(),u=new Map(d.map(oe=>[oe.id,oe.title])),{createTaskWithMessage:h}=es(),{setModel:f,credentialId:m,selectedModel:p,setChatMode:g}=ni(),[_,v]=Wi(),x=e.messages?.[0]?.metadata?.tiptapDoc??void 0,[b,y]=S.useState(x),[C,j]=S.useState(!1),[V,w]=S.useState(!1),[k,T]=S.useState(""),[I,A]=S.useState(!1),N=S.useRef(!1),E=S.useRef(null),R=S.useRef(!1),M=()=>{const he=cc(b).filter(me=>me.type==="text").map(me=>me.text).join(`
445
+ </server-logs>`}]}),I.current.get(V)?.clearSelection()},O=Me({connectionId:Wt,orgId:e.id}),z=(Q,ae)=>{const Se=I.current.get(Q);Se&&Se.write(ae)},$=Yi();RV(z);const W=CS(s?.entity?.id,o??void 0),F=$.suspended?"suspended":u?"running":W?"creating":"idle",G=h??F;S.useEffect(()=>{h==="creating"&&F==="running"&&f(null),h==="stopping"&&F==="idle"&&f(null)},[F,h]);const q=ql(O),{mutate:H,isPending:ee}=q,K=s?.entity?.id,U=$.notFound?d?.vmId??null:null,te=S.useRef(null);S.useEffect(()=>{if(!U||!K||ee||te.current===U)return;te.current=U;const Q={virtualMcpId:K};o&&(Q.branch=o),H(Q,{onError:ae=>{console.error("[env] reprovision VM_START failed",ae)}})},[U,K,o,ee,H]);const Y=S.useRef(!1);S.useEffect(()=>{if($.scripts.length>0&&!Y.current){Y.current=!0;for(const Q of c5)if($.scripts.includes(Q)){T([Q]),L(Q);break}}},[$.scripts]);const J=async(Q,ae)=>{const Se=await O.callTool({name:Q,arguments:ae}),Ne=Se.content;if(Ne?.[0]?.text?.startsWith("Error:"))throw new Error(Ne[0].text);return Se.structuredContent??Se},ie=async Q=>{if(!(v||!u)){x(!0);try{const ae=fh(d);if(!ae)throw new Error("No VM");const Se=await fetch(`${ae}/_decopilot_vm/exec/${Q}`,{method:"POST"});if(!Se.ok)throw new Error(`Exec failed: ${Se.statusText}`);y(Ne=>{const Be=new Set(Ne);return Be.delete(Q),Be})}finally{x(!1)}}},ue=async Q=>{if(!(v||!u)){x(!0);try{const ae=fh(d);if(!ae)throw new Error("No VM");const Se=await fetch(`${ae}/_decopilot_vm/kill/${Q}`,{method:"POST"});if(!Se.ok)throw new Error(`Kill failed: ${Se.statusText}`);y(Ne=>new Set(Ne).add(Q))}finally{x(!1)}}},de=Q=>{k.includes(Q)||T(ae=>[...ae,Q]),L(Q),ie(Q)},xe=async()=>{if(!C.current){C.current=!0,j.current=Date.now(),f("creating"),p("Connecting..."),_(""),Y.current=!1,T([]),L("setup");try{if(!s?.entity)throw new Error("No virtual MCP context");const Q={virtualMcpId:s.entity.id};o&&(Q.branch=o);const ae=await J("VM_START",Q);if(!ae.vmId||!ae.branch)throw new Error("Invalid VM response — missing fields");o||a(ae.branch),p(""),bn(i)}catch(Q){f("error"),_(Q instanceof Error?Q.message:"Failed to start VM")}finally{C.current=!1}}},oe=async()=>{const Q=u?.branch??o;f("stopping");const ae=s?.entity?.id;if(ae&&Q)try{await O.callTool({name:"VM_DELETE",arguments:{virtualMcpId:ae,branch:Q}})}catch{}bn(i)},he=a5();if(!he)return null;const me=s?.entity?.metadata?.runtime,fe="__none__",le=Object.keys(l5),ve=async(Q,ae)=>{if(s?.entity)try{await O.callTool({name:"COLLECTION_VIRTUAL_MCP_UPDATE",arguments:{id:s.entity.id,data:{metadata:{runtime:{...me,[Q]:ae}}}}}),bn(i)}catch{pe.error("Failed to update setting")}};if(G==="idle"||G==="stopping"){const Q=G==="stopping";return r.jsx("div",{className:"flex flex-col items-center justify-center w-full h-full p-6",children:r.jsxs("div",{className:"flex flex-col gap-4 w-full max-w-xs",children:[r.jsxs("a",{href:`https://github.com/${he.owner}/${he.name}`,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-3 p-4 rounded-lg border border-border hover:bg-accent/50 transition-colors",children:[r.jsx(fu,{size:24}),r.jsxs("div",{className:"flex flex-col gap-0.5 min-w-0 flex-1",children:[r.jsxs("span",{className:"text-sm font-medium truncate",children:[he.owner,"/",he.name]}),r.jsxs("span",{className:"text-xs text-muted-foreground truncate",children:["github.com/",he.owner,"/",he.name]})]}),r.jsx(Vi,{size:14,className:"text-muted-foreground shrink-0"})]}),r.jsxs("div",{className:"flex flex-wrap items-end justify-between gap-2 w-full",children:[r.jsxs("div",{className:"flex flex-col gap-1",children:[r.jsx(vr,{htmlFor:"env-runtime",className:"text-xs font-medium",children:"Runtime"}),r.jsxs(Qs,{value:me?.selected??fe,onValueChange:ae=>ve("selected",ae===fe?null:ae),children:[r.jsx(Zs,{id:"env-runtime",className:"w-28",children:r.jsx(ei,{placeholder:"None"})}),r.jsxs(Js,{children:[r.jsx(Ht,{value:fe,children:"None"}),le.map(ae=>r.jsx(Ht,{value:ae,children:ae},ae))]})]})]}),r.jsxs("div",{className:"flex flex-col gap-1",children:[r.jsx(vr,{htmlFor:"env-port",className:"text-xs font-medium",children:"Port"}),r.jsx(bt,{id:"env-port",placeholder:"3000",className:"w-20 h-8",defaultValue:me?.port??"",onBlur:ae=>ve("port",ae.target.value||null)})]}),r.jsxs(ne,{onClick:xe,disabled:Q,children:[Q?r.jsx(Ee,{size:14,className:"animate-spin"}):r.jsx(Cn,{size:14}),Q?"Stopping...":"Run"]})]})]})})}if(G==="creating")return r.jsxs("div",{className:"flex flex-col items-center justify-center w-full h-full gap-4",children:[r.jsx(Ee,{size:24,className:"animate-spin text-muted-foreground"}),r.jsx("p",{className:"text-sm text-muted-foreground",children:m}),r.jsx(Gp,{since:j.current})]});if(G==="error")return r.jsx(Gf,{errorMsg:g,onRetry:xe});if(G==="suspended")return r.jsx(qf,{onResume:xe});const Ce=["setup",...k,...t?["daemon"]:[]],Te=$.scripts.filter(Q=>!k.includes(Q));return r.jsx("div",{className:"flex flex-col w-full h-full",children:r.jsxs("div",{className:"flex flex-col h-full",children:[r.jsxs("div",{className:"flex h-12 items-center border-b border-border px-2 shrink-0",children:[Ce.map(Q=>r.jsx("button",{type:"button",onClick:()=>L(Q),className:X("flex items-center h-full px-3 text-sm whitespace-nowrap border-b-2 mb-[-1px] capitalize transition-all hover:text-foreground",V===Q?"text-foreground border-primary":"text-muted-foreground border-transparent"),children:Q},Q)),Te.length>0&&r.jsxs(js,{children:[r.jsx(ks,{asChild:!0,children:r.jsx("button",{type:"button",className:"flex items-center h-full px-2 text-muted-foreground hover:text-foreground transition-colors",children:r.jsx(Qt,{size:14})})}),r.jsx(Ns,{align:"start",children:Te.map(Q=>r.jsx(ot,{onClick:()=>de(Q),children:Q},Q))})]}),r.jsx("div",{className:"flex-1 flex justify-center",children:u?.vmId&&r.jsxs("div",{className:"flex items-center",children:[r.jsxs(it,{children:[r.jsx(tt,{asChild:!0,children:r.jsx("button",{type:"button",className:"shrink-0 rounded-l bg-muted px-1.5 py-0.5 text-[10px] font-mono text-muted-foreground cursor-pointer hover:bg-accent hover:text-foreground transition-colors border-r border-border/50",onClick:()=>navigator.clipboard.writeText(u?.vmId??""),children:u.vmId})}),r.jsx(st,{side:"bottom",children:"Copy VM ID"})]}),r.jsxs(js,{children:[r.jsx(ks,{asChild:!0,children:r.jsx("button",{type:"button",className:"shrink-0 self-stretch rounded-r bg-muted px-0.5 text-[10px] text-muted-foreground cursor-pointer hover:bg-accent hover:text-foreground transition-colors",children:r.jsx(kr,{size:10})})}),r.jsx(Ns,{align:"center",children:r.jsxs(ot,{onClick:oe,children:[r.jsx(gc,{size:12}),"Stop Server"]})})]})]})}),r.jsxs("div",{className:"flex items-center gap-1",children:[E&&r.jsxs("button",{type:"button",onClick:P,className:"flex items-center gap-1 rounded-md border border-border px-2 py-1 text-xs font-medium text-muted-foreground hover:text-foreground hover:bg-muted transition-colors",children:[r.jsx(Ng,{size:12}),"Add to chat"]}),V!=="setup"&&V!=="daemon"&&k.includes(V)&&(()=>{const Q=$.activeProcesses.includes(V)&&!b.has(V);return r.jsxs("div",{className:"flex items-center",children:[r.jsxs("button",{type:"button",disabled:v,onClick:()=>ie(V),className:X("flex items-center gap-1 border border-border px-2 py-1 text-xs font-medium text-muted-foreground hover:text-foreground hover:bg-muted transition-colors disabled:opacity-50",Q?"rounded-l-md border-r-0":"rounded-md"),children:[v?r.jsx(Ee,{size:12,className:"animate-spin"}):r.jsx(Cn,{size:12}),v?"Running...":Q?"Restart":"Run"]}),Q&&r.jsxs(js,{children:[r.jsx(ks,{asChild:!0,children:r.jsx("button",{type:"button",disabled:v,className:"flex items-center self-stretch rounded-r-md border border-border px-1 text-xs text-muted-foreground hover:text-foreground hover:bg-muted transition-colors disabled:opacity-50",children:r.jsx(kr,{size:12})})}),r.jsx(Ns,{align:"end",children:r.jsxs(ot,{onClick:()=>ue(V),children:[r.jsx(gc,{size:12}),"Stop Process"]})})]})]})})()]})]}),r.jsx("div",{className:"flex-1 overflow-hidden",children:Ce.map(Q=>r.jsx("div",{className:X("h-full",V===Q?"block":"hidden"),children:$.hasData(Q)||Q==="setup"||Q==="daemon"?r.jsx(o5,{onReady:ae=>{I.current.set(Q,ae)},onSelectionChange:(ae,Se)=>D(Q,ae,Se),initialData:$.getBuffer(Q),className:"h-full"}):r.jsx(Oi,{className:"h-full",image:null,title:`Script "${Q}" not running`,description:`Click Run to start "${Q}".`,actions:r.jsxs(ne,{variant:"outline",size:"sm",disabled:v,onClick:()=>ie(Q),children:[v?r.jsx(Ee,{size:14,className:"animate-spin"}):r.jsx(Cn,{size:14}),"Run"]})})},Q))})]})})}function h5(t){const e=B.c(2),{virtualMcpId:s}=t,i=ts(s);if(!(i?Fs(i):null)){let a;return e[0]===Symbol.for("react.memo_cache_sentinel")?(a=r.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-2 text-center text-sm text-muted-foreground p-6",children:[r.jsx(ri,{size:24,className:"text-muted-foreground/60"}),r.jsx("div",{children:"No repository connected."}),r.jsx("div",{className:"text-xs text-muted-foreground/80",children:"Connect a GitHub repository from the Connections tab to enable Env."})]}),e[0]=a):a=e[0],a}let o;return e[1]===Symbol.for("react.memo_cache_sentinel")?(o=r.jsx(d5,{}),e[1]=o):o=e[1],o}function Vr(t){const e=t.trim().split(/\s+/);return e.length!==5?!1:e.every(s=>/^[\d*/,-]+$/.test(s))}function u5(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 n=e.match(/^0\s+0\s+\*\/(\d+)\s+\*\s+\*$/);if(n){const l=parseInt(n[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"),c=(o[1]??"0").padStart(2,"0");return`Every day at ${l}:${c} UTC`}const a=e.match(/^(\d+)\s+(\d+)\s+\*\s+\*\s+(\d)$/);if(a){const c=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][parseInt(a[3]??"0")]??"day",d=(a[2]??"0").padStart(2,"0"),u=(a[1]??"0").padStart(2,"0");return`Every ${c} at ${d}:${u} UTC`}return t}function f5(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 m5(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 n=e.match(/^0\s+0\s+\*\/(\d+)\s+\*\s+\*$/);if(n){const o=parseInt(n[1]);return o%7===0?{count:o/7,unit:"weeks"}:{count:o,unit:"days"}}return null}function p5(t,e){return e===1?{minutes:"minute",hours:"hour",days:"day",weeks:"week"}[t]??t:t}const g5=[{label:"Minute",cron:"* * * * *"},{label:"Hour",cron:"0 * * * *"},{label:"Day",cron:"0 0 * * *"},{label:"Week",cron:"0 0 * * 1"}];function _5(t){const e=B.c(33),{automationId:s,open:i,onOpenChange:n,onCustomSelect:o,onEventSelect:a}=t,{triggerAdd:l}=Yr(),[c,d]=S.useState(!1),u=i??c;let h;e[0]!==n?(h=I=>{n?n(I):d(I)},e[0]=n,e[1]=h):h=e[1];const f=h;let m;e[2]!==l||e[3]!==s||e[4]!==f?(m=async I=>{try{await l.mutateAsync({automation_id:s,type:"cron",cron_expression:I}),pe.success("Starter added"),f(!1)}catch(A){const N=A,E=N instanceof Error?N.message:"Failed to add starter";pe.error(E)}},e[2]=l,e[3]=s,e[4]=f,e[5]=m):m=e[5];const p=m;let g;e[6]===Symbol.for("react.memo_cache_sentinel")?(g=r.jsx(ks,{asChild:!0,children:r.jsxs(ne,{variant:"outline",size:"sm",children:[r.jsx(Qt,{size:14}),"Add Starter"]})}),e[6]=g):g=e[6];let _;e[7]===Symbol.for("react.memo_cache_sentinel")?(_=r.jsxs(Bh,{className:"gap-2.5",children:[r.jsx(_r,{size:14,className:"text-muted-foreground shrink-0"}),"Every..."]}),e[7]=_):_=e[7];let v;e[8]!==l||e[9]!==p?(v=g5.map(I=>r.jsxs(ot,{className:"gap-2.5",onSelect:()=>p(I.cron),disabled:l.isPending,children:[r.jsx(_r,{size:14,className:"text-muted-foreground shrink-0"}),"Every ",I.label]},I.cron)),e[8]=l,e[9]=p,e[10]=v):v=e[10];let x;e[11]!==v?(x=r.jsxs(Sn,{children:[_,r.jsx(wn,{className:"w-[160px]",children:v})]}),e[11]=v,e[12]=x):x=e[12];let b;e[13]!==f||e[14]!==o?(b=()=>{f(!1),o?.()},e[13]=f,e[14]=o,e[15]=b):b=e[15];let y;e[16]===Symbol.for("react.memo_cache_sentinel")?(y=r.jsx(_r,{size:14,className:"text-muted-foreground shrink-0"}),e[16]=y):y=e[16];let C;e[17]!==b?(C=r.jsxs(ot,{className:"gap-2.5",onSelect:b,children:[y,"Custom (cron)"]}),e[17]=b,e[18]=C):C=e[18];let j;e[19]!==f||e[20]!==a?(j=()=>{f(!1),a?.()},e[19]=f,e[20]=a,e[21]=j):j=e[21];let V;e[22]===Symbol.for("react.memo_cache_sentinel")?(V=r.jsx($i,{size:14,className:"text-muted-foreground shrink-0"}),e[22]=V):V=e[22];let w;e[23]!==j?(w=r.jsxs(ot,{className:"gap-2.5",onSelect:j,children:[V,"Event"]}),e[23]=j,e[24]=w):w=e[24];let k;e[25]!==w||e[26]!==x||e[27]!==C?(k=r.jsxs(Ns,{align:"end",className:"w-[200px]",children:[x,C,w]}),e[25]=w,e[26]=x,e[27]=C,e[28]=k):k=e[28];let T;return e[29]!==f||e[30]!==u||e[31]!==k?(T=r.jsxs(js,{open:u,onOpenChange:f,children:[g,k]}),e[29]=f,e[30]=u,e[31]=k,e[32]=T):T=e[32],T}function x5(t){const e=B.c(60),{trigger:s,automationId:i,connectionName:n}=t,{triggerAdd:o,triggerRemove:a}=Yr(),[l,c]=S.useState(!1);let d;e[0]!==s.cron_expression?(d=s.cron_expression?m5(s.cron_expression):null,e[0]=s.cron_expression,e[1]=d):d=e[1];const u=d,[h,f]=S.useState(u?.count??1),[m,p]=S.useState(!1),[g,_]=S.useState(s.cron_expression??""),v=a.isPending||o.isPending,x=s.type==="cron";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}),pe.success("Starter removed")}catch{pe.error("Failed to remove starter")}c(!1)},e[2]=i,e[3]=a,e[4]=s.id,e[5]=b):b=e[5];const y=b;let C;e[6]!==o||e[7]!==i||e[8]!==g||e[9]!==a||e[10]!==s.cron_expression||e[11]!==s.id?(C=async()=>{const z=g.trim();if(!z||!Vr(z)||z===s.cron_expression){p(!1),_(s.cron_expression??"");return}try{await o.mutateAsync({automation_id:i,type:"cron",cron_expression:z}),await a.mutateAsync({trigger_id:s.id,automation_id:i}),p(!1)}catch{pe.error("Failed to update starter"),_(s.cron_expression??""),p(!1)}},e[6]=o,e[7]=i,e[8]=g,e[9]=a,e[10]=s.cron_expression,e[11]=s.id,e[12]=C):C=e[12];const j=C;let V;e[13]!==o||e[14]!==i||e[15]!==u||e[16]!==a||e[17]!==s.cron_expression||e[18]!==s.id?(V=async z=>{if(!u)return;const $=Math.max(1,z),W=f5($,u.unit);if(W!==s.cron_expression)try{await o.mutateAsync({automation_id:i,type:"cron",cron_expression:W}),await a.mutateAsync({trigger_id:s.id,automation_id:i})}catch{pe.error("Failed to update starter"),f(u.count)}},e[13]=o,e[14]=i,e[15]=u,e[16]=a,e[17]=s.cron_expression,e[18]=s.id,e[19]=V):V=e[19];const w=V;let k;e[20]!==x?(k=x?r.jsx(_r,{size:14,className:"text-muted-foreground shrink-0"}):r.jsx($i,{size:14,className:"text-muted-foreground shrink-0"}),e[20]=x,e[21]=k):k=e[21];let T;e[22]!==n||e[23]!==h||e[24]!==g||e[25]!==w||e[26]!==j||e[27]!==u||e[28]!==x||e[29]!==m||e[30]!==v||e[31]!==s.cron_expression||e[32]!==s.event_type||e[33]!==s.params?(T=u&&x?r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"text-sm text-muted-foreground",children:"Every"}),r.jsx("input",{type:"number",min:1,value:h,onChange:z=>f(parseInt(z.target.value)||1),onBlur:()=>w(h),onKeyDown:z=>{z.key==="Enter"&&z.target.blur(),z.key==="Escape"&&f(u.count)},disabled:v,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"}),r.jsx("span",{className:"text-sm",children:p5(u.unit,h)})]}):x&&m?r.jsxs(r.Fragment,{children:[r.jsx("input",{type:"text",value:g,onChange:z=>_(z.target.value),onBlur:j,onKeyDown:z=>{z.key==="Enter"&&z.target.blur(),z.key==="Escape"&&(p(!1),_(s.cron_expression??""))},className:"flex-1 text-sm font-mono bg-transparent outline-none",autoFocus:!0}),g&&!Vr(g)&&r.jsx("span",{className:"text-xs text-muted-foreground/60 shrink-0",children:"invalid"})]}):r.jsxs("div",{className:"flex flex-col gap-0.5 flex-1 min-w-0",children:[r.jsx("span",{className:"text-sm font-mono text-xs text-muted-foreground truncate",children:x?u5(s.cron_expression??""):`${s.event_type}${n?` · ${n}`:""}`}),!x&&s.params&&Object.keys(s.params).length>0&&r.jsx("span",{className:"text-xs text-muted-foreground/60 truncate",children:Object.entries(s.params).map(v5).join(", ")})]}),e[22]=n,e[23]=h,e[24]=g,e[25]=w,e[26]=j,e[27]=u,e[28]=x,e[29]=m,e[30]=v,e[31]=s.cron_expression,e[32]=s.event_type,e[33]=s.params,e[34]=T):T=e[34];let I;e[35]!==v?(I=v&&r.jsx(Ee,{size:13,className:"animate-spin text-muted-foreground"}),e[35]=v,e[36]=I):I=e[36];let A;e[37]!==u||e[38]!==x||e[39]!==m||e[40]!==s.cron_expression?(A=x&&!u&&!m&&r.jsx(ne,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 opacity-0 group-hover:opacity-100 transition-opacity",onClick:()=>{_(s.cron_expression??""),p(!0)},children:r.jsx(Ag,{size:13,className:"text-muted-foreground"})}),e[37]=u,e[38]=x,e[39]=m,e[40]=s.cron_expression,e[41]=A):A=e[41];let N;e[42]===Symbol.for("react.memo_cache_sentinel")?(N=r.jsx(ne,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 opacity-0 group-hover:opacity-100 transition-opacity",onClick:()=>c(!0),children:r.jsx(ii,{size:13,className:"text-muted-foreground"})}),e[42]=N):N=e[42];let E;e[43]!==I||e[44]!==A?(E=r.jsxs("div",{className:"ml-auto flex items-center gap-1",children:[I,A,N]}),e[43]=I,e[44]=A,e[45]=E):E=e[45];let R;e[46]!==E||e[47]!==k||e[48]!==T?(R=r.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-2.5 rounded-lg border border-border bg-background group",children:[k,T,E]}),e[46]=E,e[47]=k,e[48]=T,e[49]=R):R=e[49];let M;e[50]===Symbol.for("react.memo_cache_sentinel")?(M=r.jsxs(kl,{children:[r.jsx(Nl,{children:"Remove Starter"}),r.jsx(Al,{children:"Are you sure you want to remove this starter?"})]}),e[50]=M):M=e[50];let L;e[51]===Symbol.for("react.memo_cache_sentinel")?(L=r.jsx(Cl,{children:"Cancel"}),e[51]=L):L=e[51];let D;e[52]!==y?(D=r.jsxs(jl,{children:[M,r.jsxs(El,{children:[L,r.jsx(yu,{onClick:y,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Remove"})]})]}),e[52]=y,e[53]=D):D=e[53];let P;e[54]!==l||e[55]!==D?(P=r.jsx(Il,{open:l,onOpenChange:c,children:D}),e[54]=l,e[55]=D,e[56]=P):P=e[56];let O;return e[57]!==R||e[58]!==P?(O=r.jsxs(r.Fragment,{children:[R,P]}),e[57]=R,e[58]=P,e[59]=O):O=e[59],O}function v5(t){const[e,s]=t;return`${e}: ${s}`}function b5(t){const e=B.c(55),{automationId:s,onDone:i}=t;let n;e[0]===Symbol.for("react.memo_cache_sentinel")?(n={binding:"TRIGGER"},e[0]=n):n=e[0];const o=Wr(n),[a,l]=S.useState(),[c,d]=S.useState();let u;e[1]===Symbol.for("react.memo_cache_sentinel")?(u={},e[1]=u):u=e[1];const[h,f]=S.useState(u),{triggerAdd:m}=Yr(),{data:p,isLoading:g}=L_(a);let _,v,x,b,y,C;if(e[2]!==m||e[3]!==s||e[4]!==a||e[5]!==c||e[6]!==g||e[7]!==i||e[8]!==h||e[9]!==o||e[10]!==p){const w=p?.find(D=>D.type===c);let k;e[17]!==m||e[18]!==s||e[19]!==a||e[20]!==c||e[21]!==i||e[22]!==h?(k=async()=>{if(!(!a||!c))try{await m.mutateAsync({automation_id:s,type:"event",event_type:c,connection_id:a,params:h}),se("automation_trigger_added",{automation_id:s,trigger_type:"event",connection_id:a,event_type:c}),pe.success("Event trigger added"),i()}catch{pe.error("Failed to add event trigger")}},e[17]=m,e[18]=s,e[19]=a,e[20]=c,e[21]=i,e[22]=h,e[23]=k):k=e[23],_=k,v="flex flex-col gap-3 px-3 py-3 rounded-lg border border-border bg-background";let T,I;e[24]===Symbol.for("react.memo_cache_sentinel")?(I=r.jsx($i,{size:14,className:"text-muted-foreground shrink-0"}),T=r.jsx("span",{className:"text-sm font-medium",children:"Event trigger"}),e[24]=T,e[25]=I):(T=e[24],I=e[25]);let A;e[26]===Symbol.for("react.memo_cache_sentinel")?(A=r.jsx(ii,{size:13}),e[26]=A):A=e[26],e[27]!==i?(x=r.jsxs("div",{className:"flex items-center gap-2",children:[I,T,r.jsx("button",{type:"button",className:"ml-auto shrink-0 p-0.5 rounded text-muted-foreground hover:text-foreground",onClick:i,children:A})]}),e[27]=i,e[28]=x):x=e[28];const N=a??"";let E;e[29]===Symbol.for("react.memo_cache_sentinel")?(E=D=>{l(D),d(void 0),f({})},e[29]=E):E=e[29];let R;e[30]===Symbol.for("react.memo_cache_sentinel")?(R=r.jsx(Zs,{className:"w-full",children:r.jsx(ei,{placeholder:"Select connection..."})}),e[30]=R):R=e[30];let M;e[31]!==o?(M=o.length===0?r.jsx("div",{className:"px-2 py-3 text-center text-xs text-muted-foreground",children:"No connections with trigger support"}):o.map(w5),e[31]=o,e[32]=M):M=e[32];let L;e[33]!==M?(L=r.jsx(Js,{children:M}),e[33]=M,e[34]=L):L=e[34],e[35]!==N||e[36]!==L?(b=r.jsxs(Qs,{value:N,onValueChange:E,children:[R,L]}),e[35]=N,e[36]=L,e[37]=b):b=e[37],e[38]!==a||e[39]!==c||e[40]!==g||e[41]!==p?(y=a&&r.jsxs(Qs,{value:c??"",onValueChange:D=>{d(D),f({})},children:[r.jsx(Zs,{className:"w-full",children:g?r.jsxs("span",{className:"flex items-center gap-2 text-muted-foreground",children:[r.jsx(Ee,{size:13,className:"animate-spin"}),"Loading events..."]}):r.jsx(ei,{placeholder:"Select event type...",children:c??"Select event type..."})}),r.jsx(Js,{children:p?.map(S5)})]}),e[38]=a,e[39]=c,e[40]=g,e[41]=p,e[42]=y):y=e[42],C=w?.paramsSchema&&Object.keys(w.paramsSchema).length>0&&r.jsx("div",{className:"flex flex-col gap-2",children:Object.entries(w.paramsSchema).map(D=>{const[P,O]=D;return r.jsxs("div",{className:"flex flex-col gap-1",children:[r.jsxs("label",{className:"text-xs text-muted-foreground",children:[P,O.description&&r.jsxs("span",{className:"text-muted-foreground/60",children:[" ","— ",O.description]})]}),O.enum?r.jsxs(Qs,{value:h[P]??"",onValueChange:z=>f($=>({...$,[P]:z})),children:[r.jsx(Zs,{className:"w-full",children:r.jsx(ei,{placeholder:`Select ${P}...`})}),r.jsx(Js,{children:O.enum.map(y5)})]}):r.jsx("input",{type:"text",value:h[P]??"",onChange:z=>f($=>({...$,[P]:z.target.value})),placeholder:O.description??P,className:"text-sm border border-border rounded-md bg-background px-2 py-1.5 focus:outline-none focus:ring-1 focus:ring-ring"})]},P)})}),e[2]=m,e[3]=s,e[4]=a,e[5]=c,e[6]=g,e[7]=i,e[8]=h,e[9]=o,e[10]=p,e[11]=_,e[12]=v,e[13]=x,e[14]=b,e[15]=y,e[16]=C}else _=e[11],v=e[12],x=e[13],b=e[14],y=e[15],C=e[16];let j;e[43]!==m||e[44]!==a||e[45]!==c||e[46]!==_?(j=a&&c&&r.jsx(ne,{size:"sm",onClick:_,disabled:m.isPending,children:m.isPending?r.jsx(Ee,{size:13,className:"animate-spin"}):"Add trigger"}),e[43]=m,e[44]=a,e[45]=c,e[46]=_,e[47]=j):j=e[47];let V;return e[48]!==v||e[49]!==x||e[50]!==b||e[51]!==y||e[52]!==C||e[53]!==j?(V=r.jsxs("div",{className:v,children:[x,b,y,C,j]}),e[48]=v,e[49]=x,e[50]=b,e[51]=y,e[52]=C,e[53]=j,e[54]=V):V=e[54],V}function y5(t){return r.jsx(Ht,{value:t,children:t},t)}function S5(t){return r.jsx(Ht,{value:t.type,children:r.jsxs("div",{className:"flex flex-col",children:[r.jsx("span",{children:t.type}),r.jsx("span",{className:"text-xs text-muted-foreground",children:t.description})]})},t.type)}function w5(t){return r.jsx(Ht,{value:t.id,children:t.title},t.id)}function V5({automationId:t,automation:e,virtualMcpId:s,onBack:i,onDelete:n}){const o=e.agent?.id??s,{org:a}=be(),{update:l,triggerAdd:c}=Yr(),d=Wr(),u=new Map(d.map(oe=>[oe.id,oe.title])),{createTaskWithMessage:h}=es(),{setModel:f,credentialId:m,selectedModel:p,setChatMode:g}=ni(),[_,v]=Wi(),x=e.messages?.[0]?.metadata?.tiptapDoc??void 0,[b,y]=S.useState(x),[C,j]=S.useState(!1),[V,w]=S.useState(!1),[k,T]=S.useState(""),[I,A]=S.useState(!1),N=S.useRef(!1),E=S.useRef(null),R=S.useRef(!1),M=()=>{const he=cc(b).filter(me=>me.type==="text").map(me=>me.text).join(`
446
446
  `);he.trim()&&(te(),se("automation_improve_clicked",{automation_id:t,agent_id:o,instructions_length:he.length}),g("plan"),h({virtualMcpId:hl(a.id),message:{parts:[{type:"text",text:`/writing-prompts for automation with id ${t}. The current message is
447
447
 
448
448
  <message>
449
449
  ${he}
450
- </message>`}]}}))},L=e.models?.credentialId||m||"",D=e.models?.thinking?.id||p?.modelId||"",P=Hi({defaultValues:{name:e.name,active:e.active,credential_id:L,model_id:D}}),O=P.watch("active"),z=P.watch("credential_id"),$=P.watch("model_id"),{models:W,isLoading:F}=tu(z||void 0),G=W.find(oe=>oe.modelId===$)??null,q=S.useRef(null),H=S.useRef(new Set),ee=S.useRef(0),K=S.useRef(null),U=3e4,te=()=>{K.current&&(clearTimeout(K.current),K.current=null),q.current!==null&&(se("automation_updated",{automation_id:t,agent_id:o,fields:Array.from(H.current),save_count:ee.current,edit_duration_ms:Date.now()-q.current}),q.current=null,H.current=new Set,ee.current=0)},Y=async()=>{if(!(Object.keys(P.formState.dirtyFields).length>0)&&!R.current)return!0;const he=Object.keys(P.formState.dirtyFields),me=R.current;R.current=!1;const fe=P.getValues();try{const le=fe.credential_id&&fe.model_id?fe.credential_id:"",ve=fe.credential_id&&fe.model_id?fe.model_id:"",Ce={id:t,name:fe.name,active:fe.active,agent:{id:o},models:{credentialId:le,thinking:{id:ve}},messages:Ep(b),temperature:0};await l.mutateAsync(Ce),q.current===null&&(q.current=Date.now());for(const Te of he)H.current.add(Te);return me&&H.current.add("messages"),ee.current+=1,K.current&&clearTimeout(K.current),K.current=setTimeout(te,U),P.reset({...fe,credential_id:le,model_id:ve}),!0}catch{return R.current=!0,!1}},J=()=>{E.current&&clearTimeout(E.current),E.current=setTimeout(()=>{Y()},1e3)},ie=async()=>(E.current&&clearTimeout(E.current),Y()),ue=oe=>{if(y(oe),!N.current){N.current=!0;return}R.current=!0,J()},de=S.useRef(!1);de.current||(de.current=!0,P.watch(()=>{J()}));const xe=async()=>{se("automation_test_clicked",{automation_id:t,agent_id:o});const oe=await ie();if(te(),!oe)return;if(!b){ge.error("No instructions configured for this automation");return}G&&z&&f({...G,keyId:z}),v({..._,toolApprovalLevel:"auto"});const he=cc(b);h({message:{tiptapDoc:b,parts:he},virtualMcpId:o||void 0})};return r.jsxs(r.Fragment,{children:[i&&r.jsx("div",{className:"flex items-center pb-4 shrink-0",children:r.jsxs(ne,{variant:"ghost",size:"sm",onClick:i,children:[r.jsx(xl,{size:14}),"Back to list"]})}),r.jsxs("div",{className:"flex flex-col gap-8",children:[r.jsxs("div",{className:"flex flex-col gap-1.5",children:[r.jsxs("div",{className:"flex items-center justify-between gap-4",children:[r.jsx(bt,{...P.register("name"),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"}}),n&&r.jsx(ne,{variant:"ghost",size:"icon",className:"text-muted-foreground hover:text-destructive shrink-0",onClick:n,children:r.jsx(ha,{size:14})})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(Ai,{control:P.control,name:"active",render:({field:oe})=>r.jsx(da,{checked:oe.value,onCheckedChange:he=>{oe.onChange(he),setTimeout(()=>ie(),0)},className:"cursor-pointer"})}),r.jsx("span",{className:"text-sm text-muted-foreground",children:O?"Active":"Inactive"}),r.jsx("span",{className:"text-muted-foreground/50 text-sm",children:"·"}),r.jsx(T_,{id:e.created_by,size:"2xs",className:"text-sm text-muted-foreground"})]})]}),r.jsxs("div",{className:"flex flex-col gap-2.5",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-xs font-semibold text-muted-foreground/60",children:"Starter"}),r.jsx(m5,{automationId:t,open:C,onOpenChange:j,onCustomSelect:()=>{w(!0),A(!1),T("")},onEventSelect:()=>{A(!0),w(!1)}})]}),e.triggers.length===0&&!V?r.jsx("div",{className:"rounded-lg border border-dashed border-border px-4 py-6 text-center",children:r.jsxs("p",{className:"text-sm text-muted-foreground",children:["When should this automation run?"," ",r.jsx("button",{type:"button",className:"text-foreground underline underline-offset-2 cursor-pointer hover:text-foreground/80 transition-colors",onClick:()=>j(!0),children:"Add a starter"})," ","to get going."]})}):r.jsx("div",{className:"flex flex-col gap-2",children:e.triggers.map(oe=>r.jsx(p5,{trigger:oe,automationId:t,connectionName:oe.connection_id?u.get(oe.connection_id):void 0},oe.id))}),V&&r.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-2.5 rounded-lg border border-border bg-background group",children:[r.jsx(_r,{size:14,className:"text-muted-foreground shrink-0"}),r.jsx("input",{type:"text",value:k,onChange:oe=>T(oe.target.value),onBlur:async()=>{const oe=k.trim();if(!(!oe||!Vr(oe)))try{await c.mutateAsync({automation_id:t,type:"cron",cron_expression:oe}),se("automation_trigger_added",{automation_id:t,trigger_type:"cron"}),ge.success("Starter added"),w(!1),T("")}catch{ge.error("Failed to add starter")}},onKeyDown:async oe=>{const he=k.trim();oe.key==="Enter"&&he&&Vr(he)&&oe.target.blur(),oe.key==="Escape"&&(w(!1),T(""))},placeholder:"0 9 * * 1-5",className:"flex-1 text-sm font-mono bg-transparent outline-none placeholder:text-muted-foreground/40",autoFocus:!0}),k&&!Vr(k)&&r.jsx("span",{className:"text-xs text-muted-foreground/60 shrink-0",children:"invalid"}),c.isPending&&r.jsx(Ee,{size:13,className:"animate-spin text-muted-foreground shrink-0"}),r.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:()=>{w(!1),T("")},children:r.jsx(ii,{size:13})})]}),I&&r.jsx(S.Suspense,{fallback:r.jsxs("div",{className:"flex items-center gap-2 px-3 py-3 rounded-lg border border-border bg-background",children:[r.jsx(Ee,{size:13,className:"animate-spin text-muted-foreground"}),r.jsx("span",{className:"text-sm text-muted-foreground",children:"Loading connections..."})]}),children:r.jsx(_5,{automationId:t,onDone:()=>A(!1)})})]}),r.jsxs("div",{className:"flex flex-col gap-2.5",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-xs font-semibold text-muted-foreground/60",children:"Instructions"}),r.jsxs(ne,{variant:"outline",size:"sm",className:"h-7 gap-1.5 px-2 text-xs",disabled:!b,onClick:M,children:[r.jsx(_l,{size:13}),"Improve"]})]}),r.jsx(Hu,{tiptapDoc:b,setTiptapDoc:ue,placeholder:"What should this automation do?",children:r.jsxs("div",{className:"rounded-xl border border-border min-h-[120px] flex flex-col",children:[r.jsx(Wu,{virtualMcpId:o||null,className:"max-h-[45vh]"}),r.jsxs("div",{className:"flex items-center justify-end gap-1.5 p-2.5",children:[r.jsx(su,{model:G,isLoading:F,credentialId:z||null,onCredentialChange:oe=>{P.setValue("credential_id",oe??"",{shouldDirty:!0}),P.setValue("model_id","",{shouldDirty:!0})},onModelChange:oe=>P.setValue("model_id",oe.modelId,{shouldDirty:!0}),placeholder:"Model"}),r.jsxs(it,{children:[r.jsx(tt,{asChild:!0,children:r.jsxs(ne,{type:"button",variant:"default",className:"h-8 gap-1.5 rounded-md px-3 text-sm font-medium",onClick:xe,disabled:!o,children:[r.jsx(Fh,{size:16}),"Test"]})}),r.jsx(st,{children:"Test Automation"})]})]})]})})]})]})]})}function S5(t){const e=B.c(6),{tabId:s,virtualMcpId:i}=t;let n;e[0]!==s?(n=Ih(s),e[0]=s,e[1]=n):n=e[1];const o=n;if(!o)return null;let a;e[2]===Symbol.for("react.memo_cache_sentinel")?(a=r.jsx("div",{className:"flex-1 flex items-center justify-center",children:r.jsx(Ee,{size:20,className:"animate-spin text-muted-foreground"})}),e[2]=a):a=e[2];let l;return e[3]!==o.id||e[4]!==i?(l=r.jsx(hs,{children:r.jsx(hs.Content,{children:r.jsx(hs.Body,{children:r.jsx(S.Suspense,{fallback:a,children:r.jsx(w5,{id:o.id,virtualMcpId:i})})})})}),e[3]=o.id,e[4]=i,e[5]=l):l=e[5],l}function w5(t){const e=B.c(9),{id:s,virtualMcpId:i}=t,n=Ke(),{data:o,isLoading:a}=M_(s);let l;e[0]!==n?(l=()=>n({to:".",search:V5,replace:!0}),e[0]=n,e[1]=l):l=e[1];const c=l;if(a){let u;return e[2]===Symbol.for("react.memo_cache_sentinel")?(u=r.jsx("div",{className:"flex-1 flex items-center justify-center",children:r.jsx(Ee,{size:20,className:"animate-spin text-muted-foreground"})}),e[2]=u):u=e[2],u}if(!o){let u;return e[3]===Symbol.for("react.memo_cache_sentinel")?(u=r.jsx("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:"Automation not found"}),e[3]=u):u=e[3],u}let d;return e[4]!==o||e[5]!==s||e[6]!==c||e[7]!==i?(d=r.jsx(y5,{automationId:s,automation:o,virtualMcpId:i,onBack:c}),e[4]=o,e[5]=s,e[6]=c,e[7]=i,e[8]=d):d=e[8],d}function V5(t){return{...t,main:"automations"}}function C5(t){const e=B.c(19),{virtualMcpId:s}=t,i=Ke(),{data:n}=P_(s),o=n===void 0?[]:n,{create:a}=Yr(),[l,c]=S.useState(""),d=l.toLowerCase(),u=o.filter(k=>k.name.toLowerCase().includes(d));let h;e[0]!==i?(h=k=>i({to:".",search:T=>({...T,main:"automation:"+k}),replace:!0}),e[0]=i,e[1]=h):h=e[1];const f=h,m=async()=>{if(a.isPending)return;se("automation_new_clicked",{virtual_mcp_id:s,existing_count:o.length});const k=await a.mutateAsync(B_(s));f(k.id)},p=hs,g=hs,_=hs;let v;e[2]===Symbol.for("react.memo_cache_sentinel")?(v=r.jsx(Qt,{size:14}),e[2]=v):v=e[2];let x;e[3]!==a.isPending||e[4]!==m?(x=r.jsx(hs.Title,{actions:r.jsxs(ne,{size:"sm",onClick:m,disabled:a.isPending,children:[v,"New automation"]}),children:"Automations"}),e[3]=a.isPending,e[4]=m,e[5]=x):x=e[5];const b=o.length>0&&r.jsx(O_,{value:l,onChange:c,placeholder:"Search automations...",className:"w-full md:w-[375px]"});let y;e[6]!==x||e[7]!==b?(y=r.jsxs("div",{className:"flex flex-col gap-6",children:[x,b]}),e[6]=x,e[7]=b,e[8]=y):y=e[8];const C=o.length===0?r.jsx("div",{className:"flex items-center justify-center py-20",children:r.jsx(Oi,{image:r.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:r.jsxs(ne,{size:"sm",onClick:m,disabled:a.isPending,children:[r.jsx(Qt,{size:14}),"New automation"]})})}):u.length===0?r.jsx("div",{className:"flex items-center justify-center py-20",children:r.jsx(Oi,{image:r.jsx($i,{size:48,className:"text-muted-foreground"}),title:"No automations found",description:`No automations match "${l}"`})}):r.jsx("div",{className:"mt-6 rounded-xl border border-border overflow-hidden",children:u.map(k=>r.jsx(L_,{automation:k,onClick:()=>f(k.id)},k.id))});let j;e[9]!==_.Body||e[10]!==y||e[11]!==C?(j=r.jsxs(_.Body,{children:[y,C]}),e[9]=_.Body,e[10]=y,e[11]=C,e[12]=j):j=e[12];let V;e[13]!==j||e[14]!==g.Content?(V=r.jsx(g.Content,{children:j}),e[13]=j,e[14]=g.Content,e[15]=V):V=e[15];let w;return e[16]!==p||e[17]!==V?(w=r.jsx(p,{children:V}),e[16]=p,e[17]=V,e[18]=w):w=e[18],w}function j5(t){const e=B.c(3),{virtualMcpId:s}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=r.jsx("div",{className:"flex-1 flex items-center justify-center",children:r.jsx(Ee,{size:20,className:"animate-spin text-muted-foreground"})}),e[0]=i):i=e[0];let n;return e[1]!==s?(n=r.jsx(S.Suspense,{fallback:i,children:r.jsx(C5,{virtualMcpId:s})}),e[1]=s,e[2]=n):n=e[2],n}const mh=S.lazy(()=>Cp(()=>import("./project-app-view-CLbmaYfp.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])).then(t=>({default:t.AppViewContent})));function k5(t){const e=B.c(35),{taskId:s,virtualMcpId:i}=t;let n;e[0]!==s||e[1]!==i?(n={virtualMcpId:i,taskId:s},e[0]=s,e[1]=i,e[2]=n):n=e[2];const{activeTab:o,layoutTabs:a,automationTabParsed:l}=$f(n);if(Gp(o)){let m;return e[3]!==i?(m=r.jsx(_d,{virtualMcpId:i}),e[3]=i,e[4]=m):m=e[4],m}if(o==="git"){let m;return e[5]!==i?(m=r.jsx(fV,{virtualMcpId:i}),e[5]=i,e[6]=m):m=e[6],m}if(o==="automations"){let m;return e[7]!==i?(m=r.jsx(j5,{virtualMcpId:i}),e[7]=i,e[8]=m):m=e[8],m}if(o==="env"){let m;return e[9]!==i?(m=r.jsx(l5,{virtualMcpId:i}),e[9]=i,e[10]=m):m=e[10],m}if(o==="preview"){let m;return e[11]!==i?(m=r.jsx(WV,{virtualMcpId:i}),e[11]=i,e[12]=m):m=e[12],m}if(l){let m;return e[13]!==o||e[14]!==i?(m=r.jsx(S5,{tabId:o,virtualMcpId:i}),e[13]=o,e[14]=i,e[15]=m):m=e[15],m}let c;e[16]!==o?(c=Yp(o),e[16]=o,e[17]=c):c=e[17];const d=c;if(d){let m;e[18]===Symbol.for("react.memo_cache_sentinel")?(m=r.jsx("div",{className:"flex-1 flex items-center justify-center",children:r.jsx(Ee,{size:20,className:"animate-spin text-muted-foreground"})}),e[18]=m):m=e[18];let p;return e[19]!==o||e[20]!==d.connectionId||e[21]!==d.toolName?(p=r.jsx(S.Suspense,{fallback:m,children:r.jsx(mh,{connectionId:d.connectionId,toolName:d.toolName},o)}),e[19]=o,e[20]=d.connectionId,e[21]=d.toolName,e[22]=p):p=e[22],p}let u;if(e[23]!==o||e[24]!==a){let m;e[26]!==o?(m=p=>p.id===o,e[26]=o,e[27]=m):m=e[27],u=a.find(m),e[23]=o,e[24]=a,e[25]=u}else u=e[25];const h=u;if(h){let m;e[28]===Symbol.for("react.memo_cache_sentinel")?(m=r.jsx("div",{className:"flex-1 flex items-center justify-center",children:r.jsx(Ee,{size:20,className:"animate-spin text-muted-foreground"})}),e[28]=m):m=e[28];let p;return e[29]!==o||e[30]!==h.id||e[31]!==h.view.appId?(p=r.jsx(S.Suspense,{fallback:m,children:r.jsx(mh,{connectionId:h.view.appId,toolName:h.id},o)}),e[29]=o,e[30]=h.id,e[31]=h.view.appId,e[32]=p):p=e[32],p}let f;return e[33]!==i?(f=r.jsx(_d,{virtualMcpId:i}),e[33]=i,e[34]=f):f=e[34],f}function N5(t){const e=B.c(7),{children:s,defaultSize:i}=t,[,n]=S.useTransition();let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=ol.decoChatPanelWidth(),e[0]=o):o=e[0];const[a,l]=nl(o,45),c=i>0&&i<100?a:i;let d;e[1]!==l?(d=f=>n(()=>{f>0&&f<100&&l(f)}),e[1]=l,e[2]=d):d=e[2];const u=d;let h;return e[3]!==s||e[4]!==c||e[5]!==u?(h=r.jsx(iu,{defaultSize:c,minSize:20,collapsible:!0,collapsedSize:0,className:"min-w-0 overflow-hidden bg-sidebar",onResize:u,order:1,children:s}),e[3]=s,e[4]=c,e[5]=u,e[6]=h):h=e[6],h}function A5(t){const e=B.c(31),{virtualMcpId:s,taskId:i,chatOpen:n,mainOpen:o,variant:a,chatContent:l}=t;let c;e[0]!==n||e[1]!==o?(c=ud(n,o),e[0]=n,e[1]=o,e[2]=c):c=e[2];const d=c;let u;e[3]===Symbol.for("react.memo_cache_sentinel")?(u=ol.decoChatPanelWidth(),e[3]=u):u=e[3];const[h]=nl(u,45),f=S.useRef(null);let m,p;e[4]!==n||e[5]!==o||e[6]!==h?(m=()=>{const I=f.current;if(!I)return;const A=ud(n,o),N=A.chat>0&&A.chat<100?h:A.chat,E=A.chat>0&&A.chat<100?100-h:A.main;I.setLayout([N,E])},p=[n,o,h],e[4]=n,e[5]=o,e[6]=h,e[7]=m,e[8]=p):(m=e[7],p=e[8]),S.useEffect(m,p);const g=`${s}-${i}`;let _;e[9]===Symbol.for("react.memo_cache_sentinel")?(_={overflow:"visible"},e[9]=_):_=e[9];let v;e[10]!==l||e[11]!==a?(v=l??r.jsx(Ku,{variant:a}),e[10]=l,e[11]=a,e[12]=v):v=e[12];let x;e[13]!==v?(x=r.jsx("div",{className:"h-full p-0.5 pt-0.25",children:r.jsx("div",{className:"h-full bg-background rounded-[0.75rem] overflow-hidden card-shadow",children:v})}),e[13]=v,e[14]=x):x=e[14];let b;e[15]!==d.chat||e[16]!==x?(b=r.jsx(N5,{defaultSize:d.chat,children:x}),e[15]=d.chat,e[16]=x,e[17]=b):b=e[17];let y;e[18]===Symbol.for("react.memo_cache_sentinel")?(y=r.jsx(Kg,{className:"bg-sidebar"}),e[18]=y):y=e[18];const C=d.main;let j;e[19]===Symbol.for("react.memo_cache_sentinel")?(j={overflow:"visible"},e[19]=j):j=e[19];let V;e[20]===Symbol.for("react.memo_cache_sentinel")?(V=X("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[20]=V):V=e[20];let w;e[21]!==i||e[22]!==s?(w=r.jsx("div",{className:"h-full p-0.5 pt-0.25",children:r.jsx("div",{className:V,children:r.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:r.jsx(k5,{taskId:i,virtualMcpId:s})})})}),e[21]=i,e[22]=s,e[23]=w):w=e[23];let k;e[24]!==d.main||e[25]!==w?(k=r.jsx(iu,{className:"min-w-0 flex flex-col",order:2,defaultSize:C,style:j,collapsible:!0,collapsedSize:0,minSize:20,children:w}),e[24]=d.main,e[25]=w,e[26]=k):k=e[26];let T;return e[27]!==k||e[28]!==g||e[29]!==b?(T=r.jsxs(qg,{ref:f,direction:"horizontal",className:"flex-1 min-h-0 pb-1 pr-1 pl-0 pt-0",style:_,children:[b,y,k]},g),e[27]=k,e[28]=g,e[29]=b,e[30]=T):T=e[30],T}const ta="flex size-7 shrink-0 items-center justify-center rounded-md transition-colors",ph="bg-sidebar-accent text-sidebar-foreground",sa="text-sidebar-foreground/60 hover:bg-sidebar-accent hover:text-sidebar-foreground";function E5(t){const e=B.c(38),{isDecopilot:s,chatOpen:i,toggleChat:n,onNewTask:o}=t,{tasksOpen:a,toggleTasks:l}=Bf(),c=!!o;let d;e[0]!==a||e[1]!==l?(d=()=>{se("agent_toolbar_toggled",{button:"tasks",next_state:a?"closed":"open"}),l()},e[0]=a,e[1]=l,e[2]=d):d=e[2];const u=a?ph:sa;let h;e[3]!==u?(h=X(ta,u),e[3]=u,e[4]=h):h=e[4];let f;e[5]===Symbol.for("react.memo_cache_sentinel")?(f=r.jsx(Eg,{size:16}),e[5]=f):f=e[5];let m;e[6]!==d||e[7]!==h||e[8]!==a?(m=r.jsx(tt,{asChild:!0,children:r.jsx("button",{type:"button",onClick:d,"aria-pressed":a,className:h,children:f})}),e[6]=d,e[7]=h,e[8]=a,e[9]=m):m=e[9];let p;e[10]===Symbol.for("react.memo_cache_sentinel")?(p=r.jsx(st,{side:"bottom",children:"Tasks"}),e[10]=p):p=e[10];let g;e[11]!==m?(g=r.jsxs(it,{delayDuration:300,children:[m,p]}),e[11]=m,e[12]=g):g=e[12];let _;e[13]!==i||e[14]!==s||e[15]!==n?(_=!s&&r.jsxs(it,{delayDuration:300,children:[r.jsx(tt,{asChild:!0,children:r.jsx("button",{type:"button",onClick:()=>{se("agent_toolbar_toggled",{button:"chat",next_state:i?"closed":"open"}),n()},"aria-pressed":i,className:X(ta,i?ph:sa),children:r.jsx(Ag,{size:16})})}),r.jsx(st,{side:"bottom",children:"Chat"})]}),e[13]=i,e[14]=s,e[15]=n,e[16]=_):_=e[16];const v=c?"grid-cols-[1fr]":"grid-cols-[0fr]";let x;e[17]!==v?(x=X("grid transition-[grid-template-columns] duration-200 ease-[var(--ease-out-quart)]",v),e[17]=v,e[18]=x):x=e[18];const b=!c,y=c?0:-1,C=!c,j=c?"translate-x-0 opacity-100":"-translate-x-2 opacity-0";let V;e[19]!==j?(V=X(ta,sa,"transition-[transform,opacity] duration-200 ease-[var(--ease-out-quart)] will-change-transform",j),e[19]=j,e[20]=V):V=e[20];let w;e[21]===Symbol.for("react.memo_cache_sentinel")?(w=r.jsx(pl,{size:16}),e[21]=w):w=e[21];let k;e[22]!==o||e[23]!==b||e[24]!==y||e[25]!==C||e[26]!==V?(k=r.jsx(tt,{asChild:!0,children:r.jsx("button",{type:"button",onClick:o,disabled:b,tabIndex:y,"aria-hidden":C,className:V,children:w})}),e[22]=o,e[23]=b,e[24]=y,e[25]=C,e[26]=V,e[27]=k):k=e[27];let T;e[28]===Symbol.for("react.memo_cache_sentinel")?(T=r.jsx(st,{side:"bottom",children:"New task"}),e[28]=T):T=e[28];let I;e[29]!==k?(I=r.jsx("div",{className:"overflow-hidden",children:r.jsxs(it,{delayDuration:300,children:[k,T]})}),e[29]=k,e[30]=I):I=e[30];let A;e[31]!==x||e[32]!==I?(A=r.jsx("div",{className:x,children:I}),e[31]=x,e[32]=I,e[33]=A):A=e[33];let N;return e[34]!==A||e[35]!==g||e[36]!==_?(N=r.jsxs(r.Fragment,{children:[g,_,A]}),e[34]=A,e[35]=g,e[36]=_,e[37]=N):N=e[37],N}function I5(t,e,s){if(t.length<=s)return{visible:t,overflow:[]};const i=t.slice(0,s),n=t.slice(s);if(e==null)return{visible:i,overflow:n};if(i.some(h=>h.id===e))return{visible:i,overflow:n};const a=n.findIndex(h=>h.id===e);if(a===-1)return{visible:i,overflow:n};const l=i[i.length-1],c=n[a],d=[...i.slice(0,-1),c],u=[l,...n.slice(0,a),...n.slice(a+1)];return{visible:d,overflow:u}}function R5(t){const e=B.c(13),{title:s,icon:i,active:n,onClick:o}=t,a=n?"bg-sidebar-accent text-sidebar-foreground":"text-sidebar-foreground/60 hover:bg-sidebar-accent hover:text-sidebar-foreground";let l;e[0]!==a?(l=X("shrink-0 flex items-center gap-1.5 h-8 rounded-md px-2","[transition:background-color_180ms_ease,color_180ms_ease]",a),e[0]=a,e[1]=l):l=e[1];let c;e[2]!==i?(c=r.jsx("span",{className:"flex size-5 items-center justify-center shrink-0",children:r.jsx(T5,{icon:i})}),e[2]=i,e[3]=c):c=e[3];let d;e[4]!==s?(d=r.jsx("span",{className:"whitespace-nowrap text-sm font-medium leading-none",children:s}),e[4]=s,e[5]=d):d=e[5];let u;return e[6]!==n||e[7]!==o||e[8]!==l||e[9]!==c||e[10]!==d||e[11]!==s?(u=r.jsxs("button",{type:"button",onClick:o,"aria-pressed":n,"aria-label":s,className:l,children:[c,d]}),e[6]=n,e[7]=o,e[8]=l,e[9]=c,e[10]=d,e[11]=s,e[12]=u):u=e[12],u}function T5(t){const e=B.c(5),{icon:s}=t;if(s.kind==="component"){const{Component:n}=s;let o;return e[0]!==n?(o=r.jsx(n,{className:"size-4"}),e[0]=n,e[1]=o):o=e[1],o}if(s.kind==="url"){let n;return e[2]!==s.src?(n=r.jsx("img",{src:s.src,alt:"",className:"size-4 rounded-sm object-cover"}),e[2]=s.src,e[3]=n):n=e[3],n}let i;return e[4]===Symbol.for("react.memo_cache_sentinel")?(i=r.jsx(Yh,{className:"size-4"}),e[4]=i):i=e[4],i}function D5(t){const e=B.c(13),{overflow:s,onSelect:i}=t,[n,o]=S.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 c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c=r.jsx(oi,{asChild:!0,children:r.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:r.jsx(Kh,{className:"size-4"})})}),e[2]=c):c=e[2];let d;if(e[3]!==l||e[4]!==s){let f;e[6]!==l?(f=m=>r.jsx("li",{children:r.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:[r.jsx("span",{className:"flex size-5 items-center justify-center shrink-0",children:r.jsx(M5,{icon:m.icon})}),r.jsx("span",{className:"truncate",children:m.title})]})},m.id),e[6]=l,e[7]=f):f=e[7],d=s.map(f),e[3]=l,e[4]=s,e[5]=d}else d=e[5];let u;e[8]!==d?(u=r.jsx(ai,{align:"end",className:"w-56 p-1",children:r.jsx("ul",{className:"flex flex-col",children:d})}),e[8]=d,e[9]=u):u=e[9];let h;return e[10]!==n||e[11]!==u?(h=r.jsxs(li,{open:n,onOpenChange:o,children:[c,u]}),e[10]=n,e[11]=u,e[12]=h):h=e[12],h}function M5(t){const e=B.c(5),{icon:s}=t;if(s.kind==="component"){const{Component:n}=s;let o;return e[0]!==n?(o=r.jsx(n,{className:"size-4"}),e[0]=n,e[1]=o):o=e[1],o}if(s.kind==="url"){let n;return e[2]!==s.src?(n=r.jsx("img",{src:s.src,alt:"",className:"size-4 rounded-sm object-cover"}),e[2]=s.src,e[3]=n):n=e[3],n}let i;return e[4]===Symbol.for("react.memo_cache_sentinel")?(i=r.jsx(Yh,{className:"size-4"}),e[4]=i):i=e[4],i}const P5=6;function L5(t){const e=B.c(20),{virtualMcpId:s,taskId:i}=t,n=Ke();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:c,setActiveTab:d}=$f(o);let u,h,f,m;if(e[3]!==l||e[4]!==c||e[5]!==n||e[6]!==d||e[7]!==a||e[8]!==s){const _=Xp({activeTab:l,mainOpen:c}),v=j=>j.id==="automations"?_:c&&j.id===l,b=a.find(j=>v(j))?.id??null,{visible:y,overflow:C}=I5(a,b,P5);h=C,u=j=>{const V=a.find(k=>k.id===j),w=b===j&&c;if(se("main_panel_tab_clicked",{virtual_mcp_id:s,tab_id:j,tab_kind:V?.kind??null,was_active:w}),j==="automations"){const k=Jp({activeTab:l,mainOpen:c});n({to:".",search:T=>({...T,main:k}),replace:!0});return}d(j)},f="flex items-center min-w-0 ml-auto gap-0.5",m=y.map(j=>r.jsx(R5,{title:j.title,icon:j.icon,active:v(j),onClick:()=>u(j.id)},j.id)),e[3]=l,e[4]=c,e[5]=n,e[6]=d,e[7]=a,e[8]=s,e[9]=u,e[10]=h,e[11]=f,e[12]=m}else u=e[9],h=e[10],f=e[11],m=e[12];let p;e[13]!==u||e[14]!==h?(p=h.length>0&&r.jsx(D5,{overflow:h,onSelect:u}),e[13]=u,e[14]=h,e[15]=p):p=e[15];let g;return e[16]!==f||e[17]!==m||e[18]!==p?(g=r.jsxs("div",{className:f,children:[m,p]}),e[16]=f,e[17]=m,e[18]=p,e[19]=g):g=e[19],g}function B5(t){const e=B.c(12);let s,i,n,o;e[0]!==t?({className:s,orientation:n,decorative:o,...i}=t,e[0]=t,e[1]=s,e[2]=i,e[3]=n,e[4]=o):(s=e[1],i=e[2],n=e[3],o=e[4]);const a=n===void 0?"horizontal":n,l=o===void 0?!0:o;let c;e[5]!==s?(c=X("bg-border shrink-0 data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-px",s),e[5]=s,e[6]=c):c=e[6];let d;return e[7]!==l||e[8]!==a||e[9]!==i||e[10]!==c?(d=r.jsx(jp,{"data-slot":"separator-root",decorative:l,orientation:a,className:c,...i}),e[7]=l,e[8]=a,e[9]=i,e[10]=c,e[11]=d):d=e[11],d}function O5(t){const e=B.c(20),{prNumber:s,disabled:i,send:n}=t;let o;e[0]!==s||e[1]!==n?(o=()=>n(sV({prNumber:s})),e[0]=s,e[1]=n,e[2]=o):o=e[2];const a=o;let l;e[3]!==s||e[4]!==n?(l=()=>n(tV({prNumber:s})),e[3]=s,e[4]=n,e[5]=l):l=e[5];const c=l;let d;e[6]!==i||e[7]!==a?(d=r.jsx(ne,{size:"sm",className:"rounded-r-none border-r border-primary-foreground/20",disabled:i,onClick:a,children:"Publish"}),e[6]=i,e[7]=a,e[8]=d):d=e[8];let u;e[9]===Symbol.for("react.memo_cache_sentinel")?(u=r.jsx(kr,{className:"h-3.5 w-3.5"}),e[9]=u):u=e[9];let h;e[10]!==i?(h=r.jsx(ks,{asChild:!0,children:r.jsx(ne,{size:"sm",className:"rounded-l-none px-2",disabled:i,"aria-label":"More actions",children:u})}),e[10]=i,e[11]=h):h=e[11];let f;e[12]!==c?(f=r.jsx(Ns,{align:"end",children:r.jsx(ot,{onClick:c,children:"Review"})}),e[12]=c,e[13]=f):f=e[13];let m;e[14]!==h||e[15]!==f?(m=r.jsxs(js,{children:[h,f]}),e[14]=h,e[15]=f,e[16]=m):m=e[16];let p;return e[17]!==d||e[18]!==m?(p=r.jsxs("div",{className:"inline-flex items-stretch rounded-md",children:[d,m]}),e[17]=d,e[18]=m,e[19]=p):p=e[19],p}const $5=new Set(["failure","timed_out","cancelled","action_required"]);function z5(t){return t.status==="completed"&&$5.has(t.conclusion)}function F5(t){return t.status==="queued"||t.status==="in_progress"}function H5(t){const{branchStatus:e,pr:s,checks:i,reviews:n}=t;if(!e)return null;if(e.workingTreeDirty||e.unpushed>0)return{label:"Save changes",action:"commit-and-push"};if(s?.merged)return!!e.headSha&&!!s.headSha&&e.headSha!==s.headSha?{label:"Submit for review",action:"create-pr"}:null;if(e.aheadOfBase>0){if(s&&s.state==="closed"&&!s.merged)return{label:"Reopen",action:"reopen"};if(!s)return{label:"Submit for review",action:"create-pr"};if((n?.mergeableState??"unknown")==="dirty")return{label:`Sync with ${s.base}`,action:"rebase"};const l=i.filter(z5).map(c=>c.name);return l.length>0?{label:"Fix tests",action:"fix-checks",meta:{failingChecks:l}}:i.some(F5)?{label:"Running tests…",disabled:!0}:n?.draft?{label:"Mark ready",action:"mark-ready"}:(n?.unresolvedConversations??0)>0?{label:"Address feedback",action:"resolve-comments"}:n?.missingRequiredApprovals?{label:"Awaiting review",disabled:!0}:{label:"Publish",action:"merge-split"}}return null}function W5(){return Yi().branchStatus}const U5=6e4,K5=3e4;function q5(t){const e=B.c(11);let s;e[0]!==t.connectionId||e[1]!==t.orgId?(s={connectionId:t.connectionId,orgId:t.orgId},e[0]=t.connectionId,e[1]=t.orgId,e[2]=s):s=e[2];const i=Me(s),n=t.prNumber??0;let o;e[3]!==t.owner||e[4]!==t.repo||e[5]!==n?(o={method:"get",owner:t.owner,repo:t.repo,pullNumber:n},e[3]=t.owner,e[4]=t.repo,e[5]=n,e[6]=o):o=e[6];const a=!!t.prNumber;let l;return e[7]!==i||e[8]!==o||e[9]!==a?(l={client:i,toolName:"pull_request_read",toolArguments:o,enabled:a,refetchInterval:U5,refetchIntervalInBackground:!1,staleTime:K5,select:G5},e[7]=i,e[8]=o,e[9]=a,e[10]=l):l=e[10],wi(l)}function G5(t){const e=Zr(t);if(!e)return null;const s=e.mergeable_state??"unknown",i=!!(e.draft??!1),n=Number(e.review_comments??0),o=s==="blocked"&&n>0?n:0;return{draft:i,mergeableState:s,unresolvedConversations:o,missingRequiredApprovals:s==="blocked"&&o===0}}function Y5(t){const e=B.c(38),{virtualMcpId:s}=t,{org:i}=be(),n=ts(s),{currentBranch:o}=es(),a=Zn(),l=n?.metadata?.githubRepo??null,c=W5(),d=l?.connectionId??"",u=l?.owner??"",h=l?.name??"",f=o??null;let m;e[0]!==i.id||e[1]!==d||e[2]!==u||e[3]!==h||e[4]!==f?(m={orgId:i.id,connectionId:d,owner:u,repo:h,branch:f},e[0]=i.id,e[1]=d,e[2]=u,e[3]=h,e[4]=f,e[5]=m):m=e[5];const g=Ff(m).data??null,_=l?.connectionId??"",v=l?.owner??"",x=l?.name??"",b=g&&g.state==="open"?g.number:null;let y;e[6]!==i.id||e[7]!==_||e[8]!==v||e[9]!==x||e[10]!==b?(y={orgId:i.id,connectionId:_,owner:v,repo:x,prNumber:b},e[6]=i.id,e[7]=_,e[8]=v,e[9]=x,e[10]=b,e[11]=y):y=e[11];const C=Wf(y),j=l?.connectionId??"",V=l?.owner??"",w=l?.name??"",k=g&&g.state==="open"?g.number:null;let T;e[12]!==i.id||e[13]!==j||e[14]!==V||e[15]!==w||e[16]!==k?(T={orgId:i.id,connectionId:j,owner:V,repo:w,prNumber:k},e[12]=i.id,e[13]=j,e[14]=V,e[15]=w,e[16]=k,e[17]=T):T=e[17];const I=q5(T);if(!l?.connectionId||!o)return null;let A;e[18]!==c||e[19]!==C.data||e[20]!==g||e[21]!==I.data?(A=H5({branchStatus:c,pr:g,checks:C.data??[],reviews:I.data??null}),e[18]=c,e[19]=C.data,e[20]=g,e[21]=I.data,e[22]=A):A=e[22];const N=A;if(!N)return null;let E;e[23]!==a?(E=$=>a.sendMessage({parts:[{type:"text",text:$}]}),e[23]=a,e[24]=E):E=e[24];const R=E,M=a.isStreaming;let L;e[25]!==o||e[26]!==N||e[27]!==M||e[28]!==g||e[29]!==R?(L=$=>{if(!M)switch($){case"commit-and-push":{R(qw({branch:o}));return}case"create-pr":{R(Gw({branch:o}));return}case"reopen":{g&&R(Yw({prNumber:g.number}));return}case"rebase":{R(Xw({branch:o}));return}case"fix-checks":{g&&R(Qw({prNumber:g.number,failingChecks:N.meta?.failingChecks??[]}));return}case"mark-ready":{g&&R(Zw({prNumber:g.number}));return}case"resolve-comments":{g&&R(eV({prNumber:g.number}));return}case"merge-split":return}},e[25]=o,e[26]=N,e[27]=M,e[28]=g,e[29]=R,e[30]=L):L=e[30];const D=L;let P;e[31]===Symbol.for("react.memo_cache_sentinel")?(P=r.jsx(B5,{orientation:"vertical",className:"mx-2 data-[orientation=vertical]:h-5"}),e[31]=P):P=e[31];const O=g?.number;let z;return e[32]!==N||e[33]!==M||e[34]!==D||e[35]!==R||e[36]!==O?(z=r.jsxs(r.Fragment,{children:[P,r.jsx(X5,{button:N,isStreaming:M,onActivate:D,prNumber:O,send:R})]}),e[32]=N,e[33]=M,e[34]=D,e[35]=R,e[36]=O,e[37]=z):z=e[37],z}function X5(t){const e=B.c(18),{button:s,isStreaming:i}=t,n=!!s.disabled||i,o=i?"Chat is running":null;if(s.action==="merge-split"&&t.prNumber!=null){let u;e[0]!==n||e[1]!==t.prNumber||e[2]!==t.send?(u=r.jsx(O5,{prNumber:t.prNumber,disabled:n,send:t.send}),e[0]=n,e[1]=t.prNumber,e[2]=t.send,e[3]=u):u=e[3];let h;return e[4]!==u||e[5]!==o?(h=r.jsx(gh,{label:o,children:u}),e[4]=u,e[5]=o,e[6]=h):h=e[6],h}const a=s.disabled?"outline":"default";let l;e[7]!==s.action||e[8]!==t?(l=()=>t.onActivate(s.action),e[7]=s.action,e[8]=t,e[9]=l):l=e[9];let c;e[10]!==s.label||e[11]!==n||e[12]!==a||e[13]!==l?(c=r.jsx(ne,{size:"sm",variant:a,disabled:n,onClick:l,children:s.label}),e[10]=s.label,e[11]=n,e[12]=a,e[13]=l,e[14]=c):c=e[14];let d;return e[15]!==c||e[16]!==o?(d=r.jsx(gh,{label:o,children:c}),e[15]=c,e[16]=o,e[17]=d):d=e[17],d}function gh(t){const e=B.c(9),{label:s,children:i}=t;if(!s){let l;return e[0]!==i?(l=r.jsx(r.Fragment,{children:i}),e[0]=i,e[1]=l):l=e[1],l}let n;e[2]!==i?(n=r.jsx(tt,{asChild:!0,children:r.jsx("span",{children:i})}),e[2]=i,e[3]=n):n=e[3];let o;e[4]!==s?(o=r.jsx(st,{children:s}),e[4]=s,e[5]=o):o=e[5];let a;return e[6]!==n||e[7]!==o?(a=r.jsx(Mi,{children:r.jsxs(it,{children:[n,o]})}),e[6]=n,e[7]=o,e[8]=a):a=e[8],a}function J5(t){const e=B.c(2),{virtualMcp:s}=t;if(!!!(s.metadata?.githubRepo??null)?.connectionId)return null;let o;return e[0]!==s.id?(o=r.jsx(ze.Right,{children:r.jsx(Y5,{virtualMcpId:s.id})}),e[0]=s.id,e[1]=o):o=e[1],o}const Ii=S.createContext(null);function ac(){return S.use(Ii)}function _h(t){const e=B.c(8),{children:s,variant:i}=t,{taskId:n}=es();let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=r.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]=o):o=e[0];let a;e[1]===Symbol.for("react.memo_cache_sentinel")?(a=r.jsx(De.Skeleton,{}),e[1]=a):a=e[1];let l;e[2]!==s||e[3]!==i?(l=s??r.jsx(Ku,{variant:i}),e[2]=s,e[3]=i,e[4]=l):l=e[4];let c;return e[5]!==l||e[6]!==n?(c=r.jsx(Cs,{fallback:o,children:r.jsx(S.Suspense,{fallback:a,children:r.jsx(De.ActiveTaskProvider,{taskId:n,children:l})})}),e[5]=l,e[6]=n,e[7]=c):c=e[7],c}function xh(t){const e=B.c(3),{onNewTaskRef:s,createNewTask:i}=t;let n;return e[0]!==i||e[1]!==s?(n=()=>(s.current=i,()=>{s.current=null}),e[0]=i,e[1]=s,e[2]=n):n=e[2],S.useLayoutEffect(n),null}function Q5(t){const e=B.c(3),{onOpenSidebar:s}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=r.jsx(Tg,{size:20}),e[0]=i):i=e[0];let n;return e[1]!==s?(n=r.jsx("div",{className:"shrink-0 flex items-center justify-between px-3 h-12 bg-background border-b border-border",children:r.jsx("button",{type:"button",onClick:s,className:"flex size-8 items-center justify-center rounded-md text-foreground/60 hover:bg-accent hover:text-foreground transition-colors","aria-label":"Open menu",children:i})}),e[1]=s,e[2]=n):n=e[2],n}function vh(t){const e=B.c(16),{virtualMcpId:s,hasActiveGithubRepo:i,vmMap:n,children:o}=t,{org:a}=be(),{currentBranch:l}=es(),{data:c}=St.useSession(),d=c?.user?.id,u=d&&l?n?.[d]?.[l]??null:null;let h;e[0]!==u?(h=u?.previewUrl?u.previewUrl.replace(/\/$/,""):null,e[0]=u,e[1]=h):h=e[1];const f=h;let m;e[2]!==a.id?(m={connectionId:Wt,orgId:a.id},e[2]=a.id,e[3]=m):m=e[3];const p=Me(m),{mutate:g}=ql(p);let _;e[4]===Symbol.for("react.memo_cache_sentinel")?(_=new Set,e[4]=_):_=e[4];const v=S.useRef(_);let x,b;e[5]!==l||e[6]!==i||e[7]!==g||e[8]!==d||e[9]!==s||e[10]!==n?(x=()=>{i&&d&&l&&(n?.[d]?.[l]||v.current.has(l)||(v.current.add(l),g({virtualMcpId:s,branch:l},{onError:Z5})))},b=[i,d,l,n,s,g],e[5]=l,e[6]=i,e[7]=g,e[8]=d,e[9]=s,e[10]=n,e[11]=x,e[12]=b):(x=e[11],b=e[12]),S.useEffect(x,b);let y;return e[13]!==o||e[14]!==f?(y=r.jsx(NV,{daemonBaseUrl:f,children:o}),e[13]=o,e[14]=f,e[15]=y):y=e[15],y}function Z5(t){console.error("[auto-start-vm] failed:",t)}function bh(){const t=B.c(106),e=Rs(),s=Ke(),{org:i}=be(),n=AS()?.tasksOpen??!1;N_(i.id);let o;t[0]===Symbol.for("react.memo_cache_sentinel")?(o={strict:!1},t[0]=o):o=t[0];const a=$r(o),l=a.org??"";let c;t[1]===Symbol.for("react.memo_cache_sentinel")?(c={strict:!1},t[1]=c):c=t[1];const d=vi(c);let u;t[2]!==i.id||t[3]!==d.virtualmcpid?(u=d.virtualmcpid??io(i.id).id,t[2]=i.id,t[3]=d.virtualmcpid,t[4]=u):u=t[4];const h=u;let f;t[5]!==i.id?(f=hl(i.id),t[5]=i.id,t[6]=f):f=t[6];const m=h===f,p=!m,g=F_(a.taskId??"",h),_=ts(h),v=_?.metadata?.ui?.layout??null;let x;t[7]!==v?(x=v?{defaultMainView:v.defaultMainView??null,chatDefaultOpen:v.chatDefaultOpen??null}:null,t[7]=v,t[8]=x):x=t[8];const b=x;let y;t[9]!==_?(y=_&&Fs(_),t[9]=_,t[10]=y):y=t[10];const C=!!y;let j;t[11]!==p||t[12]!==l||t[13]!==h?(j={virtualMcpId:h,orgSlug:l,isAgentRoute:p},t[11]=p,t[12]=l,t[13]=h,t[14]=j):j=t[14];const V=jS(b,j),{setOpenMobile:w,openMobile:k}=qr(),T=w,I=S.useRef(null);let A,N;t[15]===Symbol.for("react.memo_cache_sentinel")?(A=()=>{const K=U=>{Ph(U)&&U.shiftKey&&U.code==="KeyS"&&!U.repeat&&(U.preventDefault(),I.current?.())};return document.addEventListener("keydown",K),()=>document.removeEventListener("keydown",K)},N=[],t[15]=A,t[16]=N):(A=t[15],N=t[16]),S.useEffect(A,N);const E=h;let R;t[17]!==_||t[18]!==h?(R={virtualMcpId:h,entity:_},t[17]=_,t[18]=h,t[19]=R):R=t[19];const M=R;if(g.status==="creating"||g.status==="loading"){let K;t[20]===Symbol.for("react.memo_cache_sentinel")?(K=r.jsx("div",{className:"flex-1 min-h-0 pr-1.5 pb-1.5 overflow-hidden",children:r.jsxs("div",{className:"flex h-full items-center justify-center bg-background card-shadow rounded-[0.75rem] text-sm text-muted-foreground",children:[r.jsx(Ee,{className:"size-4 animate-spin mr-2"}),"Creating task…"]})}),t[20]=K):K=t[20];let U;return t[21]!==M?(U=r.jsx(Ii,{value:M,children:K}),t[21]=M,t[22]=U):U=t[22],U}if(g.status==="error"){let K;t[23]===Symbol.for("react.memo_cache_sentinel")?(K=r.jsx("div",{className:"font-medium",children:"Task unavailable"}),t[23]=K):K=t[23];let U;t[24]!==g.error.message?(U=r.jsx("div",{className:"flex-1 min-h-0 pr-1.5 pb-1.5 overflow-hidden",children:r.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:[K,r.jsx("div",{className:"text-muted-foreground",children:g.error.message})]})}),t[24]=g.error.message,t[25]=U):U=t[25];let te;return t[26]!==M||t[27]!==U?(te=r.jsx(Ii,{value:M,children:U}),t[26]=M,t[27]=U,t[28]=te):te=t[28],te}if(!_){let K;t[29]===Symbol.for("react.memo_cache_sentinel")?(K=r.jsx(ri,{size:48,className:"text-muted-foreground"}),t[29]=K):K=t[29];const U=`The agent "${h}" does not exist in this organization.`;let te;t[30]!==s||t[31]!==l?(te=r.jsx(ne,{variant:"outline",onClick:()=>s({to:"/$org",params:{org:l}}),children:"Go to organization home"}),t[30]=s,t[31]=l,t[32]=te):te=t[32];let Y;t[33]!==U||t[34]!==te?(Y=r.jsx("div",{className:"flex-1 min-h-0 pr-1.5 pb-1.5 overflow-hidden",children:r.jsx("div",{className:"flex flex-col h-full bg-background overflow-hidden card-shadow rounded-[0.75rem]",children:r.jsx(Oi,{image:K,title:"Agent not found",description:U,actions:te})})}),t[33]=U,t[34]=te,t[35]=Y):Y=t[35];let J;return t[36]!==M||t[37]!==Y?(J=r.jsx(Ii,{value:M,children:Y}),t[36]=M,t[37]=Y,t[38]=J):J=t[38],J}if(e){let K;t[39]===Symbol.for("react.memo_cache_sentinel")?(K=r.jsx(S_,{className:"sr-only",children:"Navigation"}),t[39]=K):K=t[39];let U;t[40]!==T?(U=r.jsx("div",{className:"w-14 shrink-0 bg-sidebar flex flex-col items-center border-r border-border overflow-y-auto group/sidebar","data-state":"collapsed",children:r.jsx(vS,{onClose:()=>T(!1)})}),t[40]=T,t[41]=U):U=t[41];let te;t[42]===Symbol.for("react.memo_cache_sentinel")?(te=r.jsx("div",{className:"flex-1 min-w-0 overflow-hidden",children:r.jsx(Yu,{})}),t[42]=te):te=t[42];let Y;t[43]!==U?(Y=r.jsxs(w_,{side:"left",hideCloseButton:!0,className:"w-[calc(100vw-3rem)] sm:max-w-md! p-0",children:[K,r.jsxs("div",{className:"flex h-full",children:[U,te]})]}),t[43]=U,t[44]=Y):Y=t[44];let J;t[45]!==k||t[46]!==T||t[47]!==Y?(J=r.jsx(V_,{open:k,onOpenChange:T,children:Y}),t[45]=k,t[46]=T,t[47]=Y,t[48]=J):J=t[48];const ie=J,ue=_?.metadata?.vmMap;let de;t[49]!==V.createNewTask?(de=r.jsx(xh,{onNewTaskRef:I,createNewTask:V.createNewTask}),t[49]=V.createNewTask,t[50]=de):de=t[50];let xe;t[51]!==T?(xe=r.jsx(Q5,{onOpenSidebar:()=>T(!0)}),t[51]=T,t[52]=xe):xe=t[52];const oe=m?"home":void 0;let he;t[53]!==oe?(he=r.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:r.jsx(_h,{variant:oe})}),t[53]=oe,t[54]=he):he=t[54];let me;t[55]!==C||t[56]!==ie||t[57]!==ue||t[58]!==de||t[59]!==xe||t[60]!==he||t[61]!==h?(me=r.jsxs(vh,{virtualMcpId:h,hasActiveGithubRepo:C,vmMap:ue,children:[de,xe,he,ie]}),t[55]=C,t[56]=ie,t[57]=ue,t[58]=de,t[59]=xe,t[60]=he,t[61]=h,t[62]=me):me=t[62];let fe;t[63]!==E||t[64]!==me?(fe=r.jsx("div",{className:"flex flex-col flex-1 bg-background min-h-0",children:r.jsx(De.Provider,{virtualMcpId:E,children:me},E)}),t[63]=E,t[64]=me,t[65]=fe):fe=t[65];let le;return t[66]!==M||t[67]!==fe?(le=r.jsx(Ii,{value:M,children:fe}),t[66]=M,t[67]=fe,t[68]=le):le=t[68],le}const L=n?void 0:V.createNewTask;let D;t[69]!==m||t[70]!==V.chatOpen||t[71]!==V.toggleChat||t[72]!==L?(D=r.jsx(ze.Toggles,{children:r.jsx(E5,{isDecopilot:m,chatOpen:V.chatOpen,toggleChat:V.toggleChat,onNewTask:L})}),t[69]=m,t[70]=V.chatOpen,t[71]=V.toggleChat,t[72]=L,t[73]=D):D=t[73];let P;t[74]!==m||t[75]!==V.taskId||t[76]!==h?(P=!m&&r.jsx(ze.Tabs,{children:r.jsx(L5,{virtualMcpId:h,taskId:V.taskId})}),t[74]=m,t[75]=V.taskId,t[76]=h,t[77]=P):P=t[77];const O=_?.metadata?.vmMap;let z;t[78]!==_||t[79]!==m?(z=!m&&r.jsx(J5,{virtualMcp:_}),t[78]=_,t[79]=m,t[80]=z):z=t[80];let $;t[81]!==V.createNewTask?($=r.jsx(xh,{onNewTaskRef:I,createNewTask:V.createNewTask}),t[81]=V.createNewTask,t[82]=$):$=t[82];const W=m?"home":void 0;let F;t[83]!==W?(F=r.jsx(_h,{variant:W}),t[83]=W,t[84]=F):F=t[84];let G;t[85]!==V.chatOpen||t[86]!==V.mainOpen||t[87]!==V.taskId||t[88]!==F||t[89]!==h?(G=r.jsx(A5,{virtualMcpId:h,taskId:V.taskId,chatOpen:V.chatOpen,mainOpen:V.mainOpen,chatContent:F}),t[85]=V.chatOpen,t[86]=V.mainOpen,t[87]=V.taskId,t[88]=F,t[89]=h,t[90]=G):G=t[90];let q;t[91]!==C||t[92]!==O||t[93]!==z||t[94]!==$||t[95]!==G||t[96]!==h?(q=r.jsxs(vh,{virtualMcpId:h,hasActiveGithubRepo:C,vmMap:O,children:[z,$,G]}),t[91]=C,t[92]=O,t[93]=z,t[94]=$,t[95]=G,t[96]=h,t[97]=q):q=t[97];let H;t[98]!==E||t[99]!==P||t[100]!==q?(H=r.jsxs(De.Provider,{virtualMcpId:E,children:[P,q]},E),t[98]=E,t[99]=P,t[100]=q,t[101]=H):H=t[101];let ee;return t[102]!==M||t[103]!==D||t[104]!==H?(ee=r.jsxs(Ii,{value:M,children:[D,H]}),t[102]=M,t[103]=D,t[104]=H,t[105]=ee):ee=t[105],ee}function q4(){const t=B.c(5),e=Rs();let s;t[0]===Symbol.for("react.memo_cache_sentinel")?(s={"--sidebar-width-icon":"3.5rem"},t[0]=s):s=t[0];let i;t[1]===Symbol.for("react.memo_cache_sentinel")?(i=r.jsx(xS,{}),t[1]=i):i=t[1];let n;t[2]===Symbol.for("react.memo_cache_sentinel")?(n={background:"transparent",containerType:"inline-size"},t[2]=n):n=t[2];let o;return t[3]!==e?(o=r.jsx(v_,{defaultOpen:!1,children:r.jsx("div",{className:"flex flex-col h-dvh overflow-hidden",children:r.jsxs(b_,{className:"flex-1 bg-sidebar",style:s,children:[i,r.jsx(y_,{className:"flex flex-col",style:n,children:e?r.jsx(S.Suspense,{fallback:r.jsx("div",{className:"flex-1 flex items-center justify-center",children:r.jsx(Ee,{size:20,className:"animate-spin text-muted-foreground"})}),children:r.jsx(bh,{})}):r.jsx(S.Suspense,{fallback:r.jsx("div",{className:"flex-1 flex items-center justify-center",children:r.jsx(Ee,{size:20,className:"animate-spin text-muted-foreground"})}),children:r.jsx(kS,{children:r.jsxs(ze,{children:[r.jsxs(ze.Header,{children:[r.jsxs(ze.LeftColumn,{children:[r.jsx(ze.Nav,{}),r.jsx(ze.TogglesSlot,{})]}),r.jsx(ze.CenterSlot,{}),r.jsxs(ze.RightColumn,{children:[r.jsx(ze.TabsSlot,{}),r.jsx(ze.RightSlot,{})]})]}),r.jsxs("div",{className:"flex-1 min-h-0 flex flex-row",children:[r.jsx(KS,{}),r.jsx("div",{className:"flex-1 min-w-0 flex flex-col",children:r.jsx(S.Suspense,{fallback:r.jsx("div",{className:"flex-1 flex items-center justify-center",children:r.jsx(Ee,{size:20,className:"animate-spin text-muted-foreground"})}),children:r.jsx(bh,{})})})]})]})})})})]})})}),t[3]=e,t[4]=o):o=t[4],o}export{q4 as default,ac as useInsetContext};
450
+ </message>`}]}}))},L=e.models?.credentialId||m||"",D=e.models?.thinking?.id||p?.modelId||"",P=Hi({defaultValues:{name:e.name,active:e.active,credential_id:L,model_id:D}}),O=P.watch("active"),z=P.watch("credential_id"),$=P.watch("model_id"),{models:W,isLoading:F}=tu(z||void 0),G=W.find(oe=>oe.modelId===$)??null,q=S.useRef(null),H=S.useRef(new Set),ee=S.useRef(0),K=S.useRef(null),U=3e4,te=()=>{K.current&&(clearTimeout(K.current),K.current=null),q.current!==null&&(se("automation_updated",{automation_id:t,agent_id:o,fields:Array.from(H.current),save_count:ee.current,edit_duration_ms:Date.now()-q.current}),q.current=null,H.current=new Set,ee.current=0)},Y=async()=>{if(!(Object.keys(P.formState.dirtyFields).length>0)&&!R.current)return!0;const he=Object.keys(P.formState.dirtyFields),me=R.current;R.current=!1;const fe=P.getValues();try{const le=fe.credential_id&&fe.model_id?fe.credential_id:"",ve=fe.credential_id&&fe.model_id?fe.model_id:"",Ce={id:t,name:fe.name,active:fe.active,agent:{id:o},models:{credentialId:le,thinking:{id:ve}},messages:Ip(b),temperature:0};await l.mutateAsync(Ce),q.current===null&&(q.current=Date.now());for(const Te of he)H.current.add(Te);return me&&H.current.add("messages"),ee.current+=1,K.current&&clearTimeout(K.current),K.current=setTimeout(te,U),P.reset({...fe,credential_id:le,model_id:ve}),!0}catch{return R.current=!0,!1}},J=()=>{E.current&&clearTimeout(E.current),E.current=setTimeout(()=>{Y()},1e3)},ie=async()=>(E.current&&clearTimeout(E.current),Y()),ue=oe=>{if(y(oe),!N.current){N.current=!0;return}R.current=!0,J()},de=S.useRef(!1);de.current||(de.current=!0,P.watch(()=>{J()}));const xe=async()=>{se("automation_test_clicked",{automation_id:t,agent_id:o});const oe=await ie();if(te(),!oe)return;if(!b){pe.error("No instructions configured for this automation");return}G&&z&&f({...G,keyId:z}),v({..._,toolApprovalLevel:"auto"});const he=cc(b);h({message:{tiptapDoc:b,parts:he},virtualMcpId:o||void 0})};return r.jsxs(r.Fragment,{children:[i&&r.jsx("div",{className:"flex items-center pb-4 shrink-0",children:r.jsxs(ne,{variant:"ghost",size:"sm",onClick:i,children:[r.jsx(xl,{size:14}),"Back to list"]})}),r.jsxs("div",{className:"flex flex-col gap-8",children:[r.jsxs("div",{className:"flex flex-col gap-1.5",children:[r.jsxs("div",{className:"flex items-center justify-between gap-4",children:[r.jsx(bt,{...P.register("name"),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"}}),n&&r.jsx(ne,{variant:"ghost",size:"icon",className:"text-muted-foreground hover:text-destructive shrink-0",onClick:n,children:r.jsx(ha,{size:14})})]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(Ai,{control:P.control,name:"active",render:({field:oe})=>r.jsx(da,{checked:oe.value,onCheckedChange:he=>{oe.onChange(he),setTimeout(()=>ie(),0)},className:"cursor-pointer"})}),r.jsx("span",{className:"text-sm text-muted-foreground",children:O?"Active":"Inactive"}),r.jsx("span",{className:"text-muted-foreground/50 text-sm",children:"·"}),r.jsx(P_,{id:e.created_by,size:"2xs",className:"text-sm text-muted-foreground"})]})]}),r.jsxs("div",{className:"flex flex-col gap-2.5",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-xs font-semibold text-muted-foreground/60",children:"Starter"}),r.jsx(_5,{automationId:t,open:C,onOpenChange:j,onCustomSelect:()=>{w(!0),A(!1),T("")},onEventSelect:()=>{A(!0),w(!1)}})]}),e.triggers.length===0&&!V?r.jsx("div",{className:"rounded-lg border border-dashed border-border px-4 py-6 text-center",children:r.jsxs("p",{className:"text-sm text-muted-foreground",children:["When should this automation run?"," ",r.jsx("button",{type:"button",className:"text-foreground underline underline-offset-2 cursor-pointer hover:text-foreground/80 transition-colors",onClick:()=>j(!0),children:"Add a starter"})," ","to get going."]})}):r.jsx("div",{className:"flex flex-col gap-2",children:e.triggers.map(oe=>r.jsx(x5,{trigger:oe,automationId:t,connectionName:oe.connection_id?u.get(oe.connection_id):void 0},oe.id))}),V&&r.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-2.5 rounded-lg border border-border bg-background group",children:[r.jsx(_r,{size:14,className:"text-muted-foreground shrink-0"}),r.jsx("input",{type:"text",value:k,onChange:oe=>T(oe.target.value),onBlur:async()=>{const oe=k.trim();if(!(!oe||!Vr(oe)))try{await c.mutateAsync({automation_id:t,type:"cron",cron_expression:oe}),se("automation_trigger_added",{automation_id:t,trigger_type:"cron"}),pe.success("Starter added"),w(!1),T("")}catch{pe.error("Failed to add starter")}},onKeyDown:async oe=>{const he=k.trim();oe.key==="Enter"&&he&&Vr(he)&&oe.target.blur(),oe.key==="Escape"&&(w(!1),T(""))},placeholder:"0 9 * * 1-5",className:"flex-1 text-sm font-mono bg-transparent outline-none placeholder:text-muted-foreground/40",autoFocus:!0}),k&&!Vr(k)&&r.jsx("span",{className:"text-xs text-muted-foreground/60 shrink-0",children:"invalid"}),c.isPending&&r.jsx(Ee,{size:13,className:"animate-spin text-muted-foreground shrink-0"}),r.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:()=>{w(!1),T("")},children:r.jsx(ii,{size:13})})]}),I&&r.jsx(S.Suspense,{fallback:r.jsxs("div",{className:"flex items-center gap-2 px-3 py-3 rounded-lg border border-border bg-background",children:[r.jsx(Ee,{size:13,className:"animate-spin text-muted-foreground"}),r.jsx("span",{className:"text-sm text-muted-foreground",children:"Loading connections..."})]}),children:r.jsx(b5,{automationId:t,onDone:()=>A(!1)})})]}),r.jsxs("div",{className:"flex flex-col gap-2.5",children:[r.jsxs("div",{className:"flex items-center justify-between",children:[r.jsx("span",{className:"text-xs font-semibold text-muted-foreground/60",children:"Instructions"}),r.jsxs(ne,{variant:"outline",size:"sm",className:"h-7 gap-1.5 px-2 text-xs",disabled:!b,onClick:M,children:[r.jsx(_l,{size:13}),"Improve"]})]}),r.jsx(Wu,{tiptapDoc:b,setTiptapDoc:ue,placeholder:"What should this automation do?",children:r.jsxs("div",{className:"rounded-xl border border-border min-h-[120px] flex flex-col",children:[r.jsx(Uu,{virtualMcpId:o||null,className:"max-h-[45vh]"}),r.jsxs("div",{className:"flex items-center justify-end gap-1.5 p-2.5",children:[r.jsx(iu,{model:G,isLoading:F,credentialId:z||null,onCredentialChange:oe=>{P.setValue("credential_id",oe??"",{shouldDirty:!0}),P.setValue("model_id","",{shouldDirty:!0})},onModelChange:oe=>P.setValue("model_id",oe.modelId,{shouldDirty:!0}),placeholder:"Model"}),r.jsxs(it,{children:[r.jsx(tt,{asChild:!0,children:r.jsxs(ne,{type:"button",variant:"default",className:"h-8 gap-1.5 rounded-md px-3 text-sm font-medium",onClick:xe,disabled:!o,children:[r.jsx(Fh,{size:16}),"Test"]})}),r.jsx(st,{children:"Test Automation"})]})]})]})})]})]})]})}function C5(t){const e=B.c(6),{tabId:s,virtualMcpId:i}=t;let n;e[0]!==s?(n=Ih(s),e[0]=s,e[1]=n):n=e[1];const o=n;if(!o)return null;let a;e[2]===Symbol.for("react.memo_cache_sentinel")?(a=r.jsx("div",{className:"flex-1 flex items-center justify-center",children:r.jsx(Ee,{size:20,className:"animate-spin text-muted-foreground"})}),e[2]=a):a=e[2];let l;return e[3]!==o.id||e[4]!==i?(l=r.jsx(hs,{children:r.jsx(hs.Content,{children:r.jsx(hs.Body,{children:r.jsx(S.Suspense,{fallback:a,children:r.jsx(j5,{id:o.id,virtualMcpId:i})})})})}),e[3]=o.id,e[4]=i,e[5]=l):l=e[5],l}function j5(t){const e=B.c(9),{id:s,virtualMcpId:i}=t,n=Ke(),{data:o,isLoading:a}=B_(s);let l;e[0]!==n?(l=()=>n({to:".",search:k5,replace:!0}),e[0]=n,e[1]=l):l=e[1];const c=l;if(a){let u;return e[2]===Symbol.for("react.memo_cache_sentinel")?(u=r.jsx("div",{className:"flex-1 flex items-center justify-center",children:r.jsx(Ee,{size:20,className:"animate-spin text-muted-foreground"})}),e[2]=u):u=e[2],u}if(!o){let u;return e[3]===Symbol.for("react.memo_cache_sentinel")?(u=r.jsx("div",{className:"flex-1 flex items-center justify-center text-sm text-muted-foreground",children:"Automation not found"}),e[3]=u):u=e[3],u}let d;return e[4]!==o||e[5]!==s||e[6]!==c||e[7]!==i?(d=r.jsx(V5,{automationId:s,automation:o,virtualMcpId:i,onBack:c}),e[4]=o,e[5]=s,e[6]=c,e[7]=i,e[8]=d):d=e[8],d}function k5(t){return{...t,main:"automations"}}function N5(t){const e=B.c(19),{virtualMcpId:s}=t,i=Ke(),{data:n}=O_(s),o=n===void 0?[]:n,{create:a}=Yr(),[l,c]=S.useState(""),d=l.toLowerCase(),u=o.filter(k=>k.name.toLowerCase().includes(d));let h;e[0]!==i?(h=k=>i({to:".",search:T=>({...T,main:"automation:"+k}),replace:!0}),e[0]=i,e[1]=h):h=e[1];const f=h,m=async()=>{if(a.isPending)return;se("automation_new_clicked",{virtual_mcp_id:s,existing_count:o.length});const k=await a.mutateAsync(z_(s));f(k.id)},p=hs,g=hs,_=hs;let v;e[2]===Symbol.for("react.memo_cache_sentinel")?(v=r.jsx(Qt,{size:14}),e[2]=v):v=e[2];let x;e[3]!==a.isPending||e[4]!==m?(x=r.jsx(hs.Title,{actions:r.jsxs(ne,{size:"sm",onClick:m,disabled:a.isPending,children:[v,"New automation"]}),children:"Automations"}),e[3]=a.isPending,e[4]=m,e[5]=x):x=e[5];const b=o.length>0&&r.jsx(F_,{value:l,onChange:c,placeholder:"Search automations...",className:"w-full md:w-[375px]"});let y;e[6]!==x||e[7]!==b?(y=r.jsxs("div",{className:"flex flex-col gap-6",children:[x,b]}),e[6]=x,e[7]=b,e[8]=y):y=e[8];const C=o.length===0?r.jsx("div",{className:"flex items-center justify-center py-20",children:r.jsx(Oi,{image:r.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:r.jsxs(ne,{size:"sm",onClick:m,disabled:a.isPending,children:[r.jsx(Qt,{size:14}),"New automation"]})})}):u.length===0?r.jsx("div",{className:"flex items-center justify-center py-20",children:r.jsx(Oi,{image:r.jsx($i,{size:48,className:"text-muted-foreground"}),title:"No automations found",description:`No automations match "${l}"`})}):r.jsx("div",{className:"mt-6 rounded-xl border border-border overflow-hidden",children:u.map(k=>r.jsx($_,{automation:k,onClick:()=>f(k.id)},k.id))});let j;e[9]!==_.Body||e[10]!==y||e[11]!==C?(j=r.jsxs(_.Body,{children:[y,C]}),e[9]=_.Body,e[10]=y,e[11]=C,e[12]=j):j=e[12];let V;e[13]!==j||e[14]!==g.Content?(V=r.jsx(g.Content,{children:j}),e[13]=j,e[14]=g.Content,e[15]=V):V=e[15];let w;return e[16]!==p||e[17]!==V?(w=r.jsx(p,{children:V}),e[16]=p,e[17]=V,e[18]=w):w=e[18],w}function A5(t){const e=B.c(3),{virtualMcpId:s}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=r.jsx("div",{className:"flex-1 flex items-center justify-center",children:r.jsx(Ee,{size:20,className:"animate-spin text-muted-foreground"})}),e[0]=i):i=e[0];let n;return e[1]!==s?(n=r.jsx(S.Suspense,{fallback:i,children:r.jsx(N5,{virtualMcpId:s})}),e[1]=s,e[2]=n):n=e[2],n}const mh=S.lazy(()=>jp(()=>import("./project-app-view-B_z1QorU.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])).then(t=>({default:t.AppViewContent})));function E5(t){const e=B.c(35),{taskId:s,virtualMcpId:i}=t;let n;e[0]!==s||e[1]!==i?(n={virtualMcpId:i,taskId:s},e[0]=s,e[1]=i,e[2]=n):n=e[2];const{activeTab:o,layoutTabs:a,automationTabParsed:l}=zf(n);if(Yp(o)){let m;return e[3]!==i?(m=r.jsx(_d,{virtualMcpId:i}),e[3]=i,e[4]=m):m=e[4],m}if(o==="git"){let m;return e[5]!==i?(m=r.jsx(gV,{virtualMcpId:i}),e[5]=i,e[6]=m):m=e[6],m}if(o==="automations"){let m;return e[7]!==i?(m=r.jsx(A5,{virtualMcpId:i}),e[7]=i,e[8]=m):m=e[8],m}if(o==="env"){let m;return e[9]!==i?(m=r.jsx(h5,{virtualMcpId:i}),e[9]=i,e[10]=m):m=e[10],m}if(o==="preview"){let m;return e[11]!==i?(m=r.jsx(qV,{virtualMcpId:i}),e[11]=i,e[12]=m):m=e[12],m}if(l){let m;return e[13]!==o||e[14]!==i?(m=r.jsx(C5,{tabId:o,virtualMcpId:i}),e[13]=o,e[14]=i,e[15]=m):m=e[15],m}let c;e[16]!==o?(c=Xp(o),e[16]=o,e[17]=c):c=e[17];const d=c;if(d){let m;e[18]===Symbol.for("react.memo_cache_sentinel")?(m=r.jsx("div",{className:"flex-1 flex items-center justify-center",children:r.jsx(Ee,{size:20,className:"animate-spin text-muted-foreground"})}),e[18]=m):m=e[18];let p;return e[19]!==o||e[20]!==d.connectionId||e[21]!==d.toolName?(p=r.jsx(S.Suspense,{fallback:m,children:r.jsx(mh,{connectionId:d.connectionId,toolName:d.toolName},o)}),e[19]=o,e[20]=d.connectionId,e[21]=d.toolName,e[22]=p):p=e[22],p}let u;if(e[23]!==o||e[24]!==a){let m;e[26]!==o?(m=p=>p.id===o,e[26]=o,e[27]=m):m=e[27],u=a.find(m),e[23]=o,e[24]=a,e[25]=u}else u=e[25];const h=u;if(h){let m;e[28]===Symbol.for("react.memo_cache_sentinel")?(m=r.jsx("div",{className:"flex-1 flex items-center justify-center",children:r.jsx(Ee,{size:20,className:"animate-spin text-muted-foreground"})}),e[28]=m):m=e[28];let p;return e[29]!==o||e[30]!==h.id||e[31]!==h.view.appId?(p=r.jsx(S.Suspense,{fallback:m,children:r.jsx(mh,{connectionId:h.view.appId,toolName:h.id},o)}),e[29]=o,e[30]=h.id,e[31]=h.view.appId,e[32]=p):p=e[32],p}let f;return e[33]!==i?(f=r.jsx(_d,{virtualMcpId:i}),e[33]=i,e[34]=f):f=e[34],f}function I5(t){const e=B.c(7),{children:s,defaultSize:i}=t,[,n]=S.useTransition();let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=ol.decoChatPanelWidth(),e[0]=o):o=e[0];const[a,l]=nl(o,45),c=i>0&&i<100?a:i;let d;e[1]!==l?(d=f=>n(()=>{f>0&&f<100&&l(f)}),e[1]=l,e[2]=d):d=e[2];const u=d;let h;return e[3]!==s||e[4]!==c||e[5]!==u?(h=r.jsx(ru,{defaultSize:c,minSize:20,collapsible:!0,collapsedSize:0,className:"min-w-0 overflow-hidden bg-sidebar",onResize:u,order:1,children:s}),e[3]=s,e[4]=c,e[5]=u,e[6]=h):h=e[6],h}function R5(t){const e=B.c(31),{virtualMcpId:s,taskId:i,chatOpen:n,mainOpen:o,variant:a,chatContent:l}=t;let c;e[0]!==n||e[1]!==o?(c=ud(n,o),e[0]=n,e[1]=o,e[2]=c):c=e[2];const d=c;let u;e[3]===Symbol.for("react.memo_cache_sentinel")?(u=ol.decoChatPanelWidth(),e[3]=u):u=e[3];const[h]=nl(u,45),f=S.useRef(null);let m,p;e[4]!==n||e[5]!==o||e[6]!==h?(m=()=>{const I=f.current;if(!I)return;const A=ud(n,o),N=A.chat>0&&A.chat<100?h:A.chat,E=A.chat>0&&A.chat<100?100-h:A.main;I.setLayout([N,E])},p=[n,o,h],e[4]=n,e[5]=o,e[6]=h,e[7]=m,e[8]=p):(m=e[7],p=e[8]),S.useEffect(m,p);const g=`${s}-${i}`;let _;e[9]===Symbol.for("react.memo_cache_sentinel")?(_={overflow:"visible"},e[9]=_):_=e[9];let v;e[10]!==l||e[11]!==a?(v=l??r.jsx(qu,{variant:a}),e[10]=l,e[11]=a,e[12]=v):v=e[12];let x;e[13]!==v?(x=r.jsx("div",{className:"h-full p-0.5 pt-0.25",children:r.jsx("div",{className:"h-full bg-background rounded-[0.75rem] overflow-hidden card-shadow",children:v})}),e[13]=v,e[14]=x):x=e[14];let b;e[15]!==d.chat||e[16]!==x?(b=r.jsx(I5,{defaultSize:d.chat,children:x}),e[15]=d.chat,e[16]=x,e[17]=b):b=e[17];let y;e[18]===Symbol.for("react.memo_cache_sentinel")?(y=r.jsx(Yg,{className:"bg-sidebar"}),e[18]=y):y=e[18];const C=d.main;let j;e[19]===Symbol.for("react.memo_cache_sentinel")?(j={overflow:"visible"},e[19]=j):j=e[19];let V;e[20]===Symbol.for("react.memo_cache_sentinel")?(V=X("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[20]=V):V=e[20];let w;e[21]!==i||e[22]!==s?(w=r.jsx("div",{className:"h-full p-0.5 pt-0.25",children:r.jsx("div",{className:V,children:r.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:r.jsx(E5,{taskId:i,virtualMcpId:s})})})}),e[21]=i,e[22]=s,e[23]=w):w=e[23];let k;e[24]!==d.main||e[25]!==w?(k=r.jsx(ru,{className:"min-w-0 flex flex-col",order:2,defaultSize:C,style:j,collapsible:!0,collapsedSize:0,minSize:20,children:w}),e[24]=d.main,e[25]=w,e[26]=k):k=e[26];let T;return e[27]!==k||e[28]!==g||e[29]!==b?(T=r.jsxs(Xg,{ref:f,direction:"horizontal",className:"flex-1 min-h-0 pb-1 pr-1 pl-0 pt-0",style:_,children:[b,y,k]},g),e[27]=k,e[28]=g,e[29]=b,e[30]=T):T=e[30],T}const ta="flex size-7 shrink-0 items-center justify-center rounded-md transition-colors",ph="bg-sidebar-accent text-sidebar-foreground",sa="text-sidebar-foreground/60 hover:bg-sidebar-accent hover:text-sidebar-foreground";function T5(t){const e=B.c(38),{isDecopilot:s,chatOpen:i,toggleChat:n,onNewTask:o}=t,{tasksOpen:a,toggleTasks:l}=Of(),c=!!o;let d;e[0]!==a||e[1]!==l?(d=()=>{se("agent_toolbar_toggled",{button:"tasks",next_state:a?"closed":"open"}),l()},e[0]=a,e[1]=l,e[2]=d):d=e[2];const u=a?ph:sa;let h;e[3]!==u?(h=X(ta,u),e[3]=u,e[4]=h):h=e[4];let f;e[5]===Symbol.for("react.memo_cache_sentinel")?(f=r.jsx(Ig,{size:16}),e[5]=f):f=e[5];let m;e[6]!==d||e[7]!==h||e[8]!==a?(m=r.jsx(tt,{asChild:!0,children:r.jsx("button",{type:"button",onClick:d,"aria-pressed":a,className:h,children:f})}),e[6]=d,e[7]=h,e[8]=a,e[9]=m):m=e[9];let p;e[10]===Symbol.for("react.memo_cache_sentinel")?(p=r.jsx(st,{side:"bottom",children:"Tasks"}),e[10]=p):p=e[10];let g;e[11]!==m?(g=r.jsxs(it,{delayDuration:300,children:[m,p]}),e[11]=m,e[12]=g):g=e[12];let _;e[13]!==i||e[14]!==s||e[15]!==n?(_=!s&&r.jsxs(it,{delayDuration:300,children:[r.jsx(tt,{asChild:!0,children:r.jsx("button",{type:"button",onClick:()=>{se("agent_toolbar_toggled",{button:"chat",next_state:i?"closed":"open"}),n()},"aria-pressed":i,className:X(ta,i?ph:sa),children:r.jsx(Eg,{size:16})})}),r.jsx(st,{side:"bottom",children:"Chat"})]}),e[13]=i,e[14]=s,e[15]=n,e[16]=_):_=e[16];const v=c?"grid-cols-[1fr]":"grid-cols-[0fr]";let x;e[17]!==v?(x=X("grid transition-[grid-template-columns] duration-200 ease-[var(--ease-out-quart)]",v),e[17]=v,e[18]=x):x=e[18];const b=!c,y=c?0:-1,C=!c,j=c?"translate-x-0 opacity-100":"-translate-x-2 opacity-0";let V;e[19]!==j?(V=X(ta,sa,"transition-[transform,opacity] duration-200 ease-[var(--ease-out-quart)] will-change-transform",j),e[19]=j,e[20]=V):V=e[20];let w;e[21]===Symbol.for("react.memo_cache_sentinel")?(w=r.jsx(pl,{size:16}),e[21]=w):w=e[21];let k;e[22]!==o||e[23]!==b||e[24]!==y||e[25]!==C||e[26]!==V?(k=r.jsx(tt,{asChild:!0,children:r.jsx("button",{type:"button",onClick:o,disabled:b,tabIndex:y,"aria-hidden":C,className:V,children:w})}),e[22]=o,e[23]=b,e[24]=y,e[25]=C,e[26]=V,e[27]=k):k=e[27];let T;e[28]===Symbol.for("react.memo_cache_sentinel")?(T=r.jsx(st,{side:"bottom",children:"New task"}),e[28]=T):T=e[28];let I;e[29]!==k?(I=r.jsx("div",{className:"overflow-hidden",children:r.jsxs(it,{delayDuration:300,children:[k,T]})}),e[29]=k,e[30]=I):I=e[30];let A;e[31]!==x||e[32]!==I?(A=r.jsx("div",{className:x,children:I}),e[31]=x,e[32]=I,e[33]=A):A=e[33];let N;return e[34]!==A||e[35]!==g||e[36]!==_?(N=r.jsxs(r.Fragment,{children:[g,_,A]}),e[34]=A,e[35]=g,e[36]=_,e[37]=N):N=e[37],N}function D5(t,e,s){if(t.length<=s)return{visible:t,overflow:[]};const i=t.slice(0,s),n=t.slice(s);if(e==null)return{visible:i,overflow:n};if(i.some(h=>h.id===e))return{visible:i,overflow:n};const a=n.findIndex(h=>h.id===e);if(a===-1)return{visible:i,overflow:n};const l=i[i.length-1],c=n[a],d=[...i.slice(0,-1),c],u=[l,...n.slice(0,a),...n.slice(a+1)];return{visible:d,overflow:u}}function M5(t){const e=B.c(13),{title:s,icon:i,active:n,onClick:o}=t,a=n?"bg-sidebar-accent text-sidebar-foreground":"text-sidebar-foreground/60 hover:bg-sidebar-accent hover:text-sidebar-foreground";let l;e[0]!==a?(l=X("shrink-0 flex items-center gap-1.5 h-8 rounded-md px-2","[transition:background-color_180ms_ease,color_180ms_ease]",a),e[0]=a,e[1]=l):l=e[1];let c;e[2]!==i?(c=r.jsx("span",{className:"flex size-5 items-center justify-center shrink-0",children:r.jsx(P5,{icon:i})}),e[2]=i,e[3]=c):c=e[3];let d;e[4]!==s?(d=r.jsx("span",{className:"whitespace-nowrap text-sm font-medium leading-none",children:s}),e[4]=s,e[5]=d):d=e[5];let u;return e[6]!==n||e[7]!==o||e[8]!==l||e[9]!==c||e[10]!==d||e[11]!==s?(u=r.jsxs("button",{type:"button",onClick:o,"aria-pressed":n,"aria-label":s,className:l,children:[c,d]}),e[6]=n,e[7]=o,e[8]=l,e[9]=c,e[10]=d,e[11]=s,e[12]=u):u=e[12],u}function P5(t){const e=B.c(5),{icon:s}=t;if(s.kind==="component"){const{Component:n}=s;let o;return e[0]!==n?(o=r.jsx(n,{className:"size-4"}),e[0]=n,e[1]=o):o=e[1],o}if(s.kind==="url"){let n;return e[2]!==s.src?(n=r.jsx("img",{src:s.src,alt:"",className:"size-4 rounded-sm object-cover"}),e[2]=s.src,e[3]=n):n=e[3],n}let i;return e[4]===Symbol.for("react.memo_cache_sentinel")?(i=r.jsx(Yh,{className:"size-4"}),e[4]=i):i=e[4],i}function L5(t){const e=B.c(13),{overflow:s,onSelect:i}=t,[n,o]=S.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 c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c=r.jsx(oi,{asChild:!0,children:r.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:r.jsx(Kh,{className:"size-4"})})}),e[2]=c):c=e[2];let d;if(e[3]!==l||e[4]!==s){let f;e[6]!==l?(f=m=>r.jsx("li",{children:r.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:[r.jsx("span",{className:"flex size-5 items-center justify-center shrink-0",children:r.jsx(B5,{icon:m.icon})}),r.jsx("span",{className:"truncate",children:m.title})]})},m.id),e[6]=l,e[7]=f):f=e[7],d=s.map(f),e[3]=l,e[4]=s,e[5]=d}else d=e[5];let u;e[8]!==d?(u=r.jsx(ai,{align:"end",className:"w-56 p-1",children:r.jsx("ul",{className:"flex flex-col",children:d})}),e[8]=d,e[9]=u):u=e[9];let h;return e[10]!==n||e[11]!==u?(h=r.jsxs(li,{open:n,onOpenChange:o,children:[c,u]}),e[10]=n,e[11]=u,e[12]=h):h=e[12],h}function B5(t){const e=B.c(5),{icon:s}=t;if(s.kind==="component"){const{Component:n}=s;let o;return e[0]!==n?(o=r.jsx(n,{className:"size-4"}),e[0]=n,e[1]=o):o=e[1],o}if(s.kind==="url"){let n;return e[2]!==s.src?(n=r.jsx("img",{src:s.src,alt:"",className:"size-4 rounded-sm object-cover"}),e[2]=s.src,e[3]=n):n=e[3],n}let i;return e[4]===Symbol.for("react.memo_cache_sentinel")?(i=r.jsx(Yh,{className:"size-4"}),e[4]=i):i=e[4],i}const O5=6;function $5(t){const e=B.c(20),{virtualMcpId:s,taskId:i}=t,n=Ke();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:c,setActiveTab:d}=zf(o);let u,h,f,m;if(e[3]!==l||e[4]!==c||e[5]!==n||e[6]!==d||e[7]!==a||e[8]!==s){const _=Jp({activeTab:l,mainOpen:c}),v=j=>j.id==="automations"?_:c&&j.id===l,b=a.find(j=>v(j))?.id??null,{visible:y,overflow:C}=D5(a,b,O5);h=C,u=j=>{const V=a.find(k=>k.id===j),w=b===j&&c;if(se("main_panel_tab_clicked",{virtual_mcp_id:s,tab_id:j,tab_kind:V?.kind??null,was_active:w}),j==="automations"){const k=Qp({activeTab:l,mainOpen:c});n({to:".",search:T=>({...T,main:k}),replace:!0});return}d(j)},f="flex items-center min-w-0 ml-auto gap-0.5",m=y.map(j=>r.jsx(M5,{title:j.title,icon:j.icon,active:v(j),onClick:()=>u(j.id)},j.id)),e[3]=l,e[4]=c,e[5]=n,e[6]=d,e[7]=a,e[8]=s,e[9]=u,e[10]=h,e[11]=f,e[12]=m}else u=e[9],h=e[10],f=e[11],m=e[12];let p;e[13]!==u||e[14]!==h?(p=h.length>0&&r.jsx(L5,{overflow:h,onSelect:u}),e[13]=u,e[14]=h,e[15]=p):p=e[15];let g;return e[16]!==f||e[17]!==m||e[18]!==p?(g=r.jsxs("div",{className:f,children:[m,p]}),e[16]=f,e[17]=m,e[18]=p,e[19]=g):g=e[19],g}function z5(t){const e=B.c(12);let s,i,n,o;e[0]!==t?({className:s,orientation:n,decorative:o,...i}=t,e[0]=t,e[1]=s,e[2]=i,e[3]=n,e[4]=o):(s=e[1],i=e[2],n=e[3],o=e[4]);const a=n===void 0?"horizontal":n,l=o===void 0?!0:o;let c;e[5]!==s?(c=X("bg-border shrink-0 data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-px",s),e[5]=s,e[6]=c):c=e[6];let d;return e[7]!==l||e[8]!==a||e[9]!==i||e[10]!==c?(d=r.jsx(kp,{"data-slot":"separator-root",decorative:l,orientation:a,className:c,...i}),e[7]=l,e[8]=a,e[9]=i,e[10]=c,e[11]=d):d=e[11],d}function F5(t){const e=B.c(20),{prNumber:s,disabled:i,send:n}=t;let o;e[0]!==s||e[1]!==n?(o=()=>n(nV({prNumber:s})),e[0]=s,e[1]=n,e[2]=o):o=e[2];const a=o;let l;e[3]!==s||e[4]!==n?(l=()=>n(rV({prNumber:s})),e[3]=s,e[4]=n,e[5]=l):l=e[5];const c=l;let d;e[6]!==i||e[7]!==a?(d=r.jsx(ne,{size:"sm",className:"rounded-r-none border-r border-primary-foreground/20",disabled:i,onClick:a,children:"Publish"}),e[6]=i,e[7]=a,e[8]=d):d=e[8];let u;e[9]===Symbol.for("react.memo_cache_sentinel")?(u=r.jsx(kr,{className:"h-3.5 w-3.5"}),e[9]=u):u=e[9];let h;e[10]!==i?(h=r.jsx(ks,{asChild:!0,children:r.jsx(ne,{size:"sm",className:"rounded-l-none px-2",disabled:i,"aria-label":"More actions",children:u})}),e[10]=i,e[11]=h):h=e[11];let f;e[12]!==c?(f=r.jsx(Ns,{align:"end",children:r.jsx(ot,{onClick:c,children:"Review"})}),e[12]=c,e[13]=f):f=e[13];let m;e[14]!==h||e[15]!==f?(m=r.jsxs(js,{children:[h,f]}),e[14]=h,e[15]=f,e[16]=m):m=e[16];let p;return e[17]!==d||e[18]!==m?(p=r.jsxs("div",{className:"inline-flex items-stretch rounded-md",children:[d,m]}),e[17]=d,e[18]=m,e[19]=p):p=e[19],p}const H5=new Set(["failure","timed_out","cancelled","action_required"]);function W5(t){return t.status==="completed"&&H5.has(t.conclusion)}function U5(t){return t.status==="queued"||t.status==="in_progress"}function K5(t){const{branchStatus:e,pr:s,checks:i,reviews:n}=t;if(!e)return null;if(e.workingTreeDirty||e.unpushed>0)return{label:"Save changes",action:"commit-and-push"};if(s?.merged)return!!e.headSha&&!!s.headSha&&e.headSha!==s.headSha?{label:"Submit for review",action:"create-pr"}:null;if(e.aheadOfBase>0){if(s&&s.state==="closed"&&!s.merged)return{label:"Reopen",action:"reopen"};if(!s)return{label:"Submit for review",action:"create-pr"};if((n?.mergeableState??"unknown")==="dirty")return{label:`Sync with ${s.base}`,action:"rebase"};const l=i.filter(W5).map(c=>c.name);return l.length>0?{label:"Fix tests",action:"fix-checks",meta:{failingChecks:l}}:i.some(U5)?{label:"Running tests…",disabled:!0}:n?.draft?{label:"Mark ready",action:"mark-ready"}:(n?.unresolvedConversations??0)>0?{label:"Address feedback",action:"resolve-comments"}:n?.missingRequiredApprovals?{label:"Awaiting review",disabled:!0}:{label:"Publish",action:"merge-split"}}return null}function q5(){return Yi().branchStatus}const G5=6e4,Y5=3e4;function X5(t){const e=B.c(11);let s;e[0]!==t.connectionId||e[1]!==t.orgId?(s={connectionId:t.connectionId,orgId:t.orgId},e[0]=t.connectionId,e[1]=t.orgId,e[2]=s):s=e[2];const i=Me(s),n=t.prNumber??0;let o;e[3]!==t.owner||e[4]!==t.repo||e[5]!==n?(o={method:"get",owner:t.owner,repo:t.repo,pullNumber:n},e[3]=t.owner,e[4]=t.repo,e[5]=n,e[6]=o):o=e[6];const a=!!t.prNumber;let l;return e[7]!==i||e[8]!==o||e[9]!==a?(l={client:i,toolName:"pull_request_read",toolArguments:o,enabled:a,refetchInterval:G5,refetchIntervalInBackground:!1,staleTime:Y5,select:J5},e[7]=i,e[8]=o,e[9]=a,e[10]=l):l=e[10],wi(l)}function J5(t){const e=Zr(t);if(!e)return null;const s=e.mergeable_state??"unknown",i=!!(e.draft??!1),n=Number(e.review_comments??0),o=s==="blocked"&&n>0?n:0;return{draft:i,mergeableState:s,unresolvedConversations:o,missingRequiredApprovals:s==="blocked"&&o===0}}function Q5(t){const e=B.c(38),{virtualMcpId:s}=t,{org:i}=be(),n=ts(s),{currentBranch:o}=es(),a=Zn(),l=n?.metadata?.githubRepo??null,c=q5(),d=l?.connectionId??"",u=l?.owner??"",h=l?.name??"",f=o??null;let m;e[0]!==i.id||e[1]!==d||e[2]!==u||e[3]!==h||e[4]!==f?(m={orgId:i.id,connectionId:d,owner:u,repo:h,branch:f},e[0]=i.id,e[1]=d,e[2]=u,e[3]=h,e[4]=f,e[5]=m):m=e[5];const g=Hf(m).data??null,_=l?.connectionId??"",v=l?.owner??"",x=l?.name??"",b=g&&g.state==="open"?g.number:null;let y;e[6]!==i.id||e[7]!==_||e[8]!==v||e[9]!==x||e[10]!==b?(y={orgId:i.id,connectionId:_,owner:v,repo:x,prNumber:b},e[6]=i.id,e[7]=_,e[8]=v,e[9]=x,e[10]=b,e[11]=y):y=e[11];const C=Uf(y),j=l?.connectionId??"",V=l?.owner??"",w=l?.name??"",k=g&&g.state==="open"?g.number:null;let T;e[12]!==i.id||e[13]!==j||e[14]!==V||e[15]!==w||e[16]!==k?(T={orgId:i.id,connectionId:j,owner:V,repo:w,prNumber:k},e[12]=i.id,e[13]=j,e[14]=V,e[15]=w,e[16]=k,e[17]=T):T=e[17];const I=X5(T);if(!l?.connectionId||!o)return null;let A;e[18]!==c||e[19]!==C.data||e[20]!==g||e[21]!==I.data?(A=K5({branchStatus:c,pr:g,checks:C.data??[],reviews:I.data??null}),e[18]=c,e[19]=C.data,e[20]=g,e[21]=I.data,e[22]=A):A=e[22];const N=A;if(!N)return null;let E;e[23]!==a?(E=$=>a.sendMessage({parts:[{type:"text",text:$}]}),e[23]=a,e[24]=E):E=e[24];const R=E,M=a.isStreaming;let L;e[25]!==o||e[26]!==N||e[27]!==M||e[28]!==g||e[29]!==R?(L=$=>{if(!M)switch($){case"commit-and-push":{R(Xw({branch:o}));return}case"create-pr":{R(Jw({branch:o}));return}case"reopen":{g&&R(Qw({prNumber:g.number}));return}case"rebase":{R(Zw({branch:o}));return}case"fix-checks":{g&&R(tV({prNumber:g.number,failingChecks:N.meta?.failingChecks??[]}));return}case"mark-ready":{g&&R(sV({prNumber:g.number}));return}case"resolve-comments":{g&&R(iV({prNumber:g.number}));return}case"merge-split":return}},e[25]=o,e[26]=N,e[27]=M,e[28]=g,e[29]=R,e[30]=L):L=e[30];const D=L;let P;e[31]===Symbol.for("react.memo_cache_sentinel")?(P=r.jsx(z5,{orientation:"vertical",className:"mx-2 data-[orientation=vertical]:h-5"}),e[31]=P):P=e[31];const O=g?.number;let z;return e[32]!==N||e[33]!==M||e[34]!==D||e[35]!==R||e[36]!==O?(z=r.jsxs(r.Fragment,{children:[P,r.jsx(Z5,{button:N,isStreaming:M,onActivate:D,prNumber:O,send:R})]}),e[32]=N,e[33]=M,e[34]=D,e[35]=R,e[36]=O,e[37]=z):z=e[37],z}function Z5(t){const e=B.c(18),{button:s,isStreaming:i}=t,n=!!s.disabled||i,o=i?"Chat is running":null;if(s.action==="merge-split"&&t.prNumber!=null){let u;e[0]!==n||e[1]!==t.prNumber||e[2]!==t.send?(u=r.jsx(F5,{prNumber:t.prNumber,disabled:n,send:t.send}),e[0]=n,e[1]=t.prNumber,e[2]=t.send,e[3]=u):u=e[3];let h;return e[4]!==u||e[5]!==o?(h=r.jsx(gh,{label:o,children:u}),e[4]=u,e[5]=o,e[6]=h):h=e[6],h}const a=s.disabled?"outline":"default";let l;e[7]!==s.action||e[8]!==t?(l=()=>t.onActivate(s.action),e[7]=s.action,e[8]=t,e[9]=l):l=e[9];let c;e[10]!==s.label||e[11]!==n||e[12]!==a||e[13]!==l?(c=r.jsx(ne,{size:"sm",variant:a,disabled:n,onClick:l,children:s.label}),e[10]=s.label,e[11]=n,e[12]=a,e[13]=l,e[14]=c):c=e[14];let d;return e[15]!==c||e[16]!==o?(d=r.jsx(gh,{label:o,children:c}),e[15]=c,e[16]=o,e[17]=d):d=e[17],d}function gh(t){const e=B.c(9),{label:s,children:i}=t;if(!s){let l;return e[0]!==i?(l=r.jsx(r.Fragment,{children:i}),e[0]=i,e[1]=l):l=e[1],l}let n;e[2]!==i?(n=r.jsx(tt,{asChild:!0,children:r.jsx("span",{children:i})}),e[2]=i,e[3]=n):n=e[3];let o;e[4]!==s?(o=r.jsx(st,{children:s}),e[4]=s,e[5]=o):o=e[5];let a;return e[6]!==n||e[7]!==o?(a=r.jsx(Mi,{children:r.jsxs(it,{children:[n,o]})}),e[6]=n,e[7]=o,e[8]=a):a=e[8],a}function ek(t){const e=B.c(2),{virtualMcp:s}=t;if(!!!(s.metadata?.githubRepo??null)?.connectionId)return null;let o;return e[0]!==s.id?(o=r.jsx(ze.Right,{children:r.jsx(Q5,{virtualMcpId:s.id})}),e[0]=s.id,e[1]=o):o=e[1],o}const Ii=S.createContext(null);function ac(){return S.use(Ii)}function _h(t){const e=B.c(8),{children:s,variant:i}=t,{taskId:n}=es();let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=r.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]=o):o=e[0];let a;e[1]===Symbol.for("react.memo_cache_sentinel")?(a=r.jsx(De.Skeleton,{}),e[1]=a):a=e[1];let l;e[2]!==s||e[3]!==i?(l=s??r.jsx(qu,{variant:i}),e[2]=s,e[3]=i,e[4]=l):l=e[4];let c;return e[5]!==l||e[6]!==n?(c=r.jsx(Cs,{fallback:o,children:r.jsx(S.Suspense,{fallback:a,children:r.jsx(De.ActiveTaskProvider,{taskId:n,children:l})})}),e[5]=l,e[6]=n,e[7]=c):c=e[7],c}function xh(t){const e=B.c(3),{onNewTaskRef:s,createNewTask:i}=t;let n;return e[0]!==i||e[1]!==s?(n=()=>(s.current=i,()=>{s.current=null}),e[0]=i,e[1]=s,e[2]=n):n=e[2],S.useLayoutEffect(n),null}function tk(t){const e=B.c(3),{onOpenSidebar:s}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=r.jsx(Dg,{size:20}),e[0]=i):i=e[0];let n;return e[1]!==s?(n=r.jsx("div",{className:"shrink-0 flex items-center justify-between px-3 h-12 bg-background border-b border-border",children:r.jsx("button",{type:"button",onClick:s,className:"flex size-8 items-center justify-center rounded-md text-foreground/60 hover:bg-accent hover:text-foreground transition-colors","aria-label":"Open menu",children:i})}),e[1]=s,e[2]=n):n=e[2],n}function vh(t){const e=B.c(16),{virtualMcpId:s,hasActiveGithubRepo:i,vmMap:n,children:o}=t,{org:a}=be(),{currentBranch:l}=es(),{data:c}=St.useSession(),d=c?.user?.id,u=d&&l?n?.[d]?.[l]??null:null;let h;e[0]!==u?(h=u?.previewUrl?u.previewUrl.replace(/\/$/,""):null,e[0]=u,e[1]=h):h=e[1];const f=h;let m;e[2]!==a.id?(m={connectionId:Wt,orgId:a.id},e[2]=a.id,e[3]=m):m=e[3];const p=Me(m),{mutate:g}=ql(p);let _;e[4]===Symbol.for("react.memo_cache_sentinel")?(_=new Set,e[4]=_):_=e[4];const v=S.useRef(_);let x,b;e[5]!==l||e[6]!==i||e[7]!==g||e[8]!==d||e[9]!==s||e[10]!==n?(x=()=>{i&&d&&l&&(n?.[d]?.[l]||v.current.has(l)||(v.current.add(l),g({virtualMcpId:s,branch:l},{onError:sk})))},b=[i,d,l,n,s,g],e[5]=l,e[6]=i,e[7]=g,e[8]=d,e[9]=s,e[10]=n,e[11]=x,e[12]=b):(x=e[11],b=e[12]),S.useEffect(x,b);let y;return e[13]!==o||e[14]!==f?(y=r.jsx(IV,{daemonBaseUrl:f,children:o}),e[13]=o,e[14]=f,e[15]=y):y=e[15],y}function sk(t){console.error("[auto-start-vm] failed:",t)}function bh(){const t=B.c(106),e=Rs(),s=Ke(),{org:i}=be(),n=RS()?.tasksOpen??!1;I_(i.id);let o;t[0]===Symbol.for("react.memo_cache_sentinel")?(o={strict:!1},t[0]=o):o=t[0];const a=$r(o),l=a.org??"";let c;t[1]===Symbol.for("react.memo_cache_sentinel")?(c={strict:!1},t[1]=c):c=t[1];const d=vi(c);let u;t[2]!==i.id||t[3]!==d.virtualmcpid?(u=d.virtualmcpid??io(i.id).id,t[2]=i.id,t[3]=d.virtualmcpid,t[4]=u):u=t[4];const h=u;let f;t[5]!==i.id?(f=hl(i.id),t[5]=i.id,t[6]=f):f=t[6];const m=h===f,p=!m,g=U_(a.taskId??"",h),_=ts(h),v=_?.metadata?.ui?.layout??null;let x;t[7]!==v?(x=v?{defaultMainView:v.defaultMainView??null,chatDefaultOpen:v.chatDefaultOpen??null}:null,t[7]=v,t[8]=x):x=t[8];const b=x;let y;t[9]!==_?(y=_&&Fs(_),t[9]=_,t[10]=y):y=t[10];const C=!!y;let j;t[11]!==p||t[12]!==l||t[13]!==h?(j={virtualMcpId:h,orgSlug:l,isAgentRoute:p},t[11]=p,t[12]=l,t[13]=h,t[14]=j):j=t[14];const V=AS(b,j),{setOpenMobile:w,openMobile:k}=qr(),T=w,I=S.useRef(null);let A,N;t[15]===Symbol.for("react.memo_cache_sentinel")?(A=()=>{const K=U=>{Ph(U)&&U.shiftKey&&U.code==="KeyS"&&!U.repeat&&(U.preventDefault(),I.current?.())};return document.addEventListener("keydown",K),()=>document.removeEventListener("keydown",K)},N=[],t[15]=A,t[16]=N):(A=t[15],N=t[16]),S.useEffect(A,N);const E=h;let R;t[17]!==_||t[18]!==h?(R={virtualMcpId:h,entity:_},t[17]=_,t[18]=h,t[19]=R):R=t[19];const M=R;if(g.status==="creating"||g.status==="loading"){let K;t[20]===Symbol.for("react.memo_cache_sentinel")?(K=r.jsx("div",{className:"flex-1 min-h-0 pr-1.5 pb-1.5 overflow-hidden",children:r.jsxs("div",{className:"flex h-full items-center justify-center bg-background card-shadow rounded-[0.75rem] text-sm text-muted-foreground",children:[r.jsx(Ee,{className:"size-4 animate-spin mr-2"}),"Creating task…"]})}),t[20]=K):K=t[20];let U;return t[21]!==M?(U=r.jsx(Ii,{value:M,children:K}),t[21]=M,t[22]=U):U=t[22],U}if(g.status==="error"){let K;t[23]===Symbol.for("react.memo_cache_sentinel")?(K=r.jsx("div",{className:"font-medium",children:"Task unavailable"}),t[23]=K):K=t[23];let U;t[24]!==g.error.message?(U=r.jsx("div",{className:"flex-1 min-h-0 pr-1.5 pb-1.5 overflow-hidden",children:r.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:[K,r.jsx("div",{className:"text-muted-foreground",children:g.error.message})]})}),t[24]=g.error.message,t[25]=U):U=t[25];let te;return t[26]!==M||t[27]!==U?(te=r.jsx(Ii,{value:M,children:U}),t[26]=M,t[27]=U,t[28]=te):te=t[28],te}if(!_){let K;t[29]===Symbol.for("react.memo_cache_sentinel")?(K=r.jsx(ri,{size:48,className:"text-muted-foreground"}),t[29]=K):K=t[29];const U=`The agent "${h}" does not exist in this organization.`;let te;t[30]!==s||t[31]!==l?(te=r.jsx(ne,{variant:"outline",onClick:()=>s({to:"/$org",params:{org:l}}),children:"Go to organization home"}),t[30]=s,t[31]=l,t[32]=te):te=t[32];let Y;t[33]!==U||t[34]!==te?(Y=r.jsx("div",{className:"flex-1 min-h-0 pr-1.5 pb-1.5 overflow-hidden",children:r.jsx("div",{className:"flex flex-col h-full bg-background overflow-hidden card-shadow rounded-[0.75rem]",children:r.jsx(Oi,{image:K,title:"Agent not found",description:U,actions:te})})}),t[33]=U,t[34]=te,t[35]=Y):Y=t[35];let J;return t[36]!==M||t[37]!==Y?(J=r.jsx(Ii,{value:M,children:Y}),t[36]=M,t[37]=Y,t[38]=J):J=t[38],J}if(e){let K;t[39]===Symbol.for("react.memo_cache_sentinel")?(K=r.jsx(C_,{className:"sr-only",children:"Navigation"}),t[39]=K):K=t[39];let U;t[40]!==T?(U=r.jsx("div",{className:"w-14 shrink-0 bg-sidebar flex flex-col items-center border-r border-border overflow-y-auto group/sidebar","data-state":"collapsed",children:r.jsx(SS,{onClose:()=>T(!1)})}),t[40]=T,t[41]=U):U=t[41];let te;t[42]===Symbol.for("react.memo_cache_sentinel")?(te=r.jsx("div",{className:"flex-1 min-w-0 overflow-hidden",children:r.jsx(Xu,{})}),t[42]=te):te=t[42];let Y;t[43]!==U?(Y=r.jsxs(j_,{side:"left",hideCloseButton:!0,className:"w-[calc(100vw-3rem)] sm:max-w-md! p-0",children:[K,r.jsxs("div",{className:"flex h-full",children:[U,te]})]}),t[43]=U,t[44]=Y):Y=t[44];let J;t[45]!==k||t[46]!==T||t[47]!==Y?(J=r.jsx(k_,{open:k,onOpenChange:T,children:Y}),t[45]=k,t[46]=T,t[47]=Y,t[48]=J):J=t[48];const ie=J,ue=_?.metadata?.vmMap;let de;t[49]!==V.createNewTask?(de=r.jsx(xh,{onNewTaskRef:I,createNewTask:V.createNewTask}),t[49]=V.createNewTask,t[50]=de):de=t[50];let xe;t[51]!==T?(xe=r.jsx(tk,{onOpenSidebar:()=>T(!0)}),t[51]=T,t[52]=xe):xe=t[52];const oe=m?"home":void 0;let he;t[53]!==oe?(he=r.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:r.jsx(_h,{variant:oe})}),t[53]=oe,t[54]=he):he=t[54];let me;t[55]!==C||t[56]!==ie||t[57]!==ue||t[58]!==de||t[59]!==xe||t[60]!==he||t[61]!==h?(me=r.jsxs(vh,{virtualMcpId:h,hasActiveGithubRepo:C,vmMap:ue,children:[de,xe,he,ie]}),t[55]=C,t[56]=ie,t[57]=ue,t[58]=de,t[59]=xe,t[60]=he,t[61]=h,t[62]=me):me=t[62];let fe;t[63]!==E||t[64]!==me?(fe=r.jsx("div",{className:"flex flex-col flex-1 bg-background min-h-0",children:r.jsx(De.Provider,{virtualMcpId:E,children:me},E)}),t[63]=E,t[64]=me,t[65]=fe):fe=t[65];let le;return t[66]!==M||t[67]!==fe?(le=r.jsx(Ii,{value:M,children:fe}),t[66]=M,t[67]=fe,t[68]=le):le=t[68],le}const L=n?void 0:V.createNewTask;let D;t[69]!==m||t[70]!==V.chatOpen||t[71]!==V.toggleChat||t[72]!==L?(D=r.jsx(ze.Toggles,{children:r.jsx(T5,{isDecopilot:m,chatOpen:V.chatOpen,toggleChat:V.toggleChat,onNewTask:L})}),t[69]=m,t[70]=V.chatOpen,t[71]=V.toggleChat,t[72]=L,t[73]=D):D=t[73];let P;t[74]!==m||t[75]!==V.taskId||t[76]!==h?(P=!m&&r.jsx(ze.Tabs,{children:r.jsx($5,{virtualMcpId:h,taskId:V.taskId})}),t[74]=m,t[75]=V.taskId,t[76]=h,t[77]=P):P=t[77];const O=_?.metadata?.vmMap;let z;t[78]!==_||t[79]!==m?(z=!m&&r.jsx(ek,{virtualMcp:_}),t[78]=_,t[79]=m,t[80]=z):z=t[80];let $;t[81]!==V.createNewTask?($=r.jsx(xh,{onNewTaskRef:I,createNewTask:V.createNewTask}),t[81]=V.createNewTask,t[82]=$):$=t[82];const W=m?"home":void 0;let F;t[83]!==W?(F=r.jsx(_h,{variant:W}),t[83]=W,t[84]=F):F=t[84];let G;t[85]!==V.chatOpen||t[86]!==V.mainOpen||t[87]!==V.taskId||t[88]!==F||t[89]!==h?(G=r.jsx(R5,{virtualMcpId:h,taskId:V.taskId,chatOpen:V.chatOpen,mainOpen:V.mainOpen,chatContent:F}),t[85]=V.chatOpen,t[86]=V.mainOpen,t[87]=V.taskId,t[88]=F,t[89]=h,t[90]=G):G=t[90];let q;t[91]!==C||t[92]!==O||t[93]!==z||t[94]!==$||t[95]!==G||t[96]!==h?(q=r.jsxs(vh,{virtualMcpId:h,hasActiveGithubRepo:C,vmMap:O,children:[z,$,G]}),t[91]=C,t[92]=O,t[93]=z,t[94]=$,t[95]=G,t[96]=h,t[97]=q):q=t[97];let H;t[98]!==E||t[99]!==P||t[100]!==q?(H=r.jsxs(De.Provider,{virtualMcpId:E,children:[P,q]},E),t[98]=E,t[99]=P,t[100]=q,t[101]=H):H=t[101];let ee;return t[102]!==M||t[103]!==D||t[104]!==H?(ee=r.jsxs(Ii,{value:M,children:[D,H]}),t[102]=M,t[103]=D,t[104]=H,t[105]=ee):ee=t[105],ee}function X4(){const t=B.c(5),e=Rs();let s;t[0]===Symbol.for("react.memo_cache_sentinel")?(s={"--sidebar-width-icon":"3.5rem"},t[0]=s):s=t[0];let i;t[1]===Symbol.for("react.memo_cache_sentinel")?(i=r.jsx(yS,{}),t[1]=i):i=t[1];let n;t[2]===Symbol.for("react.memo_cache_sentinel")?(n={background:"transparent",containerType:"inline-size"},t[2]=n):n=t[2];let o;return t[3]!==e?(o=r.jsx(S_,{defaultOpen:!1,children:r.jsx("div",{className:"flex flex-col h-dvh overflow-hidden",children:r.jsxs(w_,{className:"flex-1 bg-sidebar",style:s,children:[i,r.jsx(V_,{className:"flex flex-col",style:n,children:e?r.jsx(S.Suspense,{fallback:r.jsx("div",{className:"flex-1 flex items-center justify-center",children:r.jsx(Ee,{size:20,className:"animate-spin text-muted-foreground"})}),children:r.jsx(bh,{})}):r.jsx(S.Suspense,{fallback:r.jsx("div",{className:"flex-1 flex items-center justify-center",children:r.jsx(Ee,{size:20,className:"animate-spin text-muted-foreground"})}),children:r.jsx(ES,{children:r.jsxs(ze,{children:[r.jsxs(ze.Header,{children:[r.jsxs(ze.LeftColumn,{children:[r.jsx(ze.Nav,{}),r.jsx(ze.TogglesSlot,{})]}),r.jsx(ze.CenterSlot,{}),r.jsxs(ze.RightColumn,{children:[r.jsx(ze.TabsSlot,{}),r.jsx(ze.RightSlot,{})]})]}),r.jsxs("div",{className:"flex-1 min-h-0 flex flex-row",children:[r.jsx(YS,{}),r.jsx("div",{className:"flex-1 min-w-0 flex flex-col",children:r.jsx(S.Suspense,{fallback:r.jsx("div",{className:"flex-1 flex items-center justify-center",children:r.jsx(Ee,{size:20,className:"animate-spin text-muted-foreground"})}),children:r.jsx(bh,{})})})]})]})})})})]})})}),t[3]=e,t[4]=o):o=t[4],o}export{X4 as default,ac as useInsetContext};