@p4code/cli 0.9.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (183) hide show
  1. package/dist/bin.mjs +1 -1
  2. package/dist/{binCli-k72_SR2Z.mjs → binCli-B8_9WRM7.mjs} +10 -3
  3. package/dist/client/.vite/manifest.json +1120 -1120
  4. package/dist/client/assets/{2NI2N5EU-DPAxyySd.js → 2NI2N5EU-Cc9Gs6p1.js} +2 -2
  5. package/dist/client/assets/{4UO7MD6I-C0aflwpw.js → 4UO7MD6I--tXEX5R9.js} +2 -2
  6. package/dist/client/assets/{5B3SVYGG-hhn6T1ru.js → 5B3SVYGG-CPRAqyzZ.js} +2 -2
  7. package/dist/client/assets/{5GK6JWQ2-BQ0OdoZ6.js → 5GK6JWQ2-OC2-LRPx.js} +2 -2
  8. package/dist/client/assets/{5N7A7DKN-BR8rdHwZ.js → 5N7A7DKN-BUa1-OZ6.js} +2 -2
  9. package/dist/client/assets/{5OC2THR4-DVDBlcjJ.js → 5OC2THR4-DKcwc3u1.js} +2 -2
  10. package/dist/client/assets/{5S6HY5KT-CjtOXys8.js → 5S6HY5KT-Dqth6iG8.js} +2 -2
  11. package/dist/client/assets/{6IMQ5BUJ-Bpy1Geo9.js → 6IMQ5BUJ-DmEcg0r1.js} +2 -2
  12. package/dist/client/assets/{6OLKWJ4F-D2naWV4i.js → 6OLKWJ4F-W-G6qP3r.js} +2 -2
  13. package/dist/client/assets/{74OO7NKP-CceNos-7.js → 74OO7NKP-u02yiNi7.js} +2 -2
  14. package/dist/client/assets/{75O6YZUN-CnXm_L8w.js → 75O6YZUN-xx4y2KbP.js} +2 -2
  15. package/dist/client/assets/{77XECAW3-ECBcD47O.js → 77XECAW3-SIARa2Fi.js} +2 -2
  16. package/dist/client/assets/{ABYRPUBD-B4F4wZam.js → ABYRPUBD-B_0r9NT4.js} +2 -2
  17. package/dist/client/assets/{AuthSurfaceShell-DR9yRrzS.js → AuthSurfaceShell-DPlJfFlL.js} +2 -2
  18. package/dist/client/assets/{BB2UYUI2-Cae7rC8c.js → BB2UYUI2-CujjjZN9.js} +2 -2
  19. package/dist/client/assets/{BUM34MOA-DBDboDOb.js → BUM34MOA-NuuTH6rj.js} +2 -2
  20. package/dist/client/assets/{CEQABKGZ-C6UutqUy.js → CEQABKGZ-DDaGayTm.js} +2 -2
  21. package/dist/client/assets/{CXAC5362-BnZlf1Fg.js → CXAC5362-CB6ETtV8.js} +2 -2
  22. package/dist/client/assets/{ChatGptUsageButton-3K5PpaVk.js → ChatGptUsageButton-DqJ-vZMe.js} +2 -2
  23. package/dist/client/assets/{ChatMarkdown-EK5C8Dje.js → ChatMarkdown-C94Vrzqf.js} +5 -5
  24. package/dist/client/assets/{CodexSetupSection.logic-BepCZ25p.js → CodexSetupSection.logic-DOe05Yxb.js} +2 -2
  25. package/dist/client/assets/{CommandBlock-C967hvdK.js → CommandBlock-BUY_4yYG.js} +2 -2
  26. package/dist/client/assets/{ComposerPromptEditor-kPs79YCA.js → ComposerPromptEditor-BXlsIVOQ.js} +4 -4
  27. package/dist/client/assets/{ConnectionDiagnosisDetails-B5VXf5lv.js → ConnectionDiagnosisDetails-DoemNrMF.js} +2 -2
  28. package/dist/client/assets/{DRLTVNUE-Du8kYl_L.js → DRLTVNUE-D0oW6kzx.js} +2 -2
  29. package/dist/client/assets/{DYY6UVD2-DxjEuWNy.js → DYY6UVD2-DBOhEG0-.js} +2 -2
  30. package/dist/client/assets/{DevicePanel-YEBH-Vqd.js → DevicePanel-B5VTFku5.js} +2 -2
  31. package/dist/client/assets/{DeviceSetup-CAlj40rJ.js → DeviceSetup-C7hesHao.js} +2 -2
  32. package/dist/client/assets/{DiffCommentAnnotation-BOk2MTlv.js → DiffCommentAnnotation-DDYXWdY5.js} +2 -2
  33. package/dist/client/assets/{DiffFileTree-Dg3cvfi5.js → DiffFileTree-SBs4YWHB.js} +2 -2
  34. package/dist/client/assets/{DiffPanel-fTHMPAQJ.js → DiffPanel-Cd7uZSwI.js} +2 -2
  35. package/dist/client/assets/{DiffWorkerPoolProvider-CqmToECA.js → DiffWorkerPoolProvider-elvn0oLt.js} +2 -2
  36. package/dist/client/assets/{EmbeddedDesign-BXKBSCcw.js → EmbeddedDesign-BDMR5UJo.js} +2 -2
  37. package/dist/client/assets/{FNOVOB4O-BeMBYVRF.js → FNOVOB4O-C55ATzH6.js} +2 -2
  38. package/dist/client/assets/{FileDiff-DW1zPAn5.js → FileDiff-DpQM5r9o.js} +2 -2
  39. package/dist/client/assets/{FilePreviewPanel-CTTCKfik.js → FilePreviewPanel-DWeewVws.js} +2 -2
  40. package/dist/client/assets/{FoldedSettingsSection-ClboCRR4.js → FoldedSettingsSection-KMTLX6MR.js} +2 -2
  41. package/dist/client/assets/{HDGCDEEZ-DtsLNbcM.js → HDGCDEEZ-BhXkP8CI.js} +2 -2
  42. package/dist/client/assets/{HSJLKHB7-Cj1_K-Mg.js → HSJLKHB7-ad9jby8d.js} +2 -2
  43. package/dist/client/assets/JZOYTAAL-CifPXszn.js +1 -0
  44. package/dist/client/assets/{K3MD6TGW-SNOidZ8r.js → K3MD6TGW-CG-BXshu.js} +2 -2
  45. package/dist/client/assets/{K7RP3OMA-CpajkG5B.js → K7RP3OMA-Dvs72E71.js} +2 -2
  46. package/dist/client/assets/{LHDIQX7Q-CAyO0Nv9.js → LHDIQX7Q-DBbVLdBb.js} +2 -2
  47. package/dist/client/assets/{LUXOKEGN-Dp60gO-M.js → LUXOKEGN-B8HcSY56.js} +2 -2
  48. package/dist/client/assets/{MathTypeset-DG9QDH3a.js → MathTypeset-D0cDlCZy.js} +2 -2
  49. package/dist/client/assets/{N3JZAHOW-CPZZhC9o.js → N3JZAHOW-BXwh9_vP.js} +2 -2
  50. package/dist/client/assets/{NUIALGQ3-Bapg3pv1.js → NUIALGQ3-ClxnUm8B.js} +2 -2
  51. package/dist/client/assets/{NoProjectsHero-DunzHVd0.js → NoProjectsHero-Bn4v5ofT.js} +2 -2
  52. package/dist/client/assets/{O65XPQGZ-BmLVfB2-.js → O65XPQGZ-BEEpAP2l.js} +2 -2
  53. package/dist/client/assets/{O7XIQ6OM-BzZlSmaP.js → O7XIQ6OM-CkSDwviv.js} +2 -2
  54. package/dist/client/assets/{OFQON5FD-Ciy1Dfj8.js → OFQON5FD-4EbpxjZS.js} +2 -2
  55. package/dist/client/assets/{P4ConnectAccountPages-DO-fCpTN.js → P4ConnectAccountPages-DgxvyIGG.js} +2 -2
  56. package/dist/client/assets/{P4ConnectSidebarSignIn-7hkM7xr7.js → P4ConnectSidebarSignIn-Bn9hP_6_.js} +2 -2
  57. package/dist/client/assets/{PJQHF43J-CTTmTIhc.js → PJQHF43J-D_j27v4O.js} +2 -2
  58. package/dist/client/assets/{PanelLayoutControls-clP6N7xc.js → PanelLayoutControls-BHEJEPDp.js} +4 -4
  59. package/dist/client/assets/{PierreEntryIcon-wm-IkF2y.js → PierreEntryIcon-BCv2OXDn.js} +2 -2
  60. package/dist/client/assets/{PreviewPanel-fTwWXayK.js → PreviewPanel-D3CQGyTY.js} +2 -2
  61. package/dist/client/assets/{ProjectDefaultsSettings-DABlQCRQ.js → ProjectDefaultsSettings-CqigWqDQ.js} +2 -2
  62. package/dist/client/assets/{ProjectFavicon-zExdjKgc.js → ProjectFavicon-BzkwZEKX.js} +3 -3
  63. package/dist/client/assets/{ProjectIconPickerDialog-D4Br81iW.js → ProjectIconPickerDialog-Bl7a1F6c.js} +2 -2
  64. package/dist/client/assets/{ProviderAuthTerminal-Gf_5AaPE.js → ProviderAuthTerminal-BxyDTl04.js} +2 -2
  65. package/dist/client/assets/{ProviderModelPicker-DrfK42fH.js → ProviderModelPicker-BjWN45iR.js} +2 -2
  66. package/dist/client/assets/{ProviderSettingsForm-CXVYrIzw.js → ProviderSettingsForm-9qRf6JzH.js} +2 -2
  67. package/dist/client/assets/{PullRequestCodeTab-DaXxo4Bs.js → PullRequestCodeTab-2fq1MIQq.js} +2 -2
  68. package/dist/client/assets/{RHNBAITX-DKMeuR6R.js → RHNBAITX-DaSH9fj2.js} +2 -2
  69. package/dist/client/assets/{ReadOnlySourcePreview-DPJWK3HJ.js → ReadOnlySourcePreview-CUL87R5C.js} +2 -2
  70. package/dist/client/assets/{RenderErrorBoundary-BI5KBtsb.js → RenderErrorBoundary-CEX4aXRH.js} +2 -2
  71. package/dist/client/assets/{SLD4V6NK-CR4aIcpx.js → SLD4V6NK-BPOaMXu1.js} +2 -2
  72. package/dist/client/assets/{ScheduledTasksSettings-CTHyd4UX.js → ScheduledTasksSettings-BEw_vC1N.js} +2 -2
  73. package/dist/client/assets/{ScopedSwitch-De6GoQiO.js → ScopedSwitch-DPPAQKgb.js} +2 -2
  74. package/dist/client/assets/{SettingsPanels-D6e2byZQ.js → SettingsPanels-wkOx3NMK.js} +2 -2
  75. package/dist/client/assets/{SettingsPanels.logic-BSXSdFru.js → SettingsPanels.logic-BwMoKlP_.js} +2 -2
  76. package/dist/client/assets/{SettingsScopeNotice-MbxDDMZ9.js → SettingsScopeNotice-5BIXPKKZ.js} +2 -2
  77. package/dist/client/assets/{SidebarStageBackdrop-B0F--sat.js → SidebarStageBackdrop-Cc8Os5aB.js} +2 -2
  78. package/dist/client/assets/{T3PCR2KE-C0_7R2Oa.js → T3PCR2KE-DF_ihTb_.js} +2 -2
  79. package/dist/client/assets/{TKWO2OVW-DqJmzuhq.js → TKWO2OVW-BpYa7JbN.js} +2 -2
  80. package/dist/client/assets/{TSHNXIZL-CmCl4WMk.js → TSHNXIZL-icuUBQJZ.js} +2 -2
  81. package/dist/client/assets/{ThemeEditorPanel-IhSXPcO9.js → ThemeEditorPanel-K5Z_cKr_.js} +2 -2
  82. package/dist/client/assets/{ThreadTerminalDrawer-DnOstFPr.js → ThreadTerminalDrawer-BEzEKbGr.js} +2 -2
  83. package/dist/client/assets/{UQJE5E4I-U1f_Qxq0.js → UQJE5E4I-jTtBmXGD.js} +2 -2
  84. package/dist/client/assets/{USNYFO5S-BFU1s0-x.js → USNYFO5S-COMhBWxE.js} +2 -2
  85. package/dist/client/assets/{Virtualizer-CI2uidEs.js → Virtualizer-3W_tqqHL.js} +2 -2
  86. package/dist/client/assets/{WEVWDWVA-DVuH1I8D.js → WEVWDWVA-DoGSbgZU.js} +2 -2
  87. package/dist/client/assets/{X5RFHQXM-DhiPjZ2I.js → X5RFHQXM-pFbOarC5.js} +2 -2
  88. package/dist/client/assets/{X62E3GBT-BoEmDIYA.js → X62E3GBT-CSXB08Iw.js} +2 -2
  89. package/dist/client/assets/{XBNEOJTC-ACchb7zJ.js → XBNEOJTC-CvXlFTiB.js} +2 -2
  90. package/dist/client/assets/{YHV2MVVZ-WIW1NclZ.js → YHV2MVVZ-BxyA2-Iu.js} +2 -2
  91. package/dist/client/assets/{YURCZMG2-D8PyipKA.js → YURCZMG2-WkhL6rVs.js} +2 -2
  92. package/dist/client/assets/{YVG2LODB-BQvBC9bF.js → YVG2LODB-BlCOW5Bm.js} +2 -2
  93. package/dist/client/assets/{_chat-DDGjgFMR.js → _chat-B72aqP_1.js} +14 -14
  94. package/dist/client/assets/{_chat.design-DjIqnlVZ.js → _chat.design-BzS-6FDR.js} +2 -2
  95. package/dist/client/assets/{_chat.index-Dku1iZH1.js → _chat.index-DyO0DElX.js} +2 -2
  96. package/dist/client/assets/{_chat.new-8-cjg5K7.js → _chat.new-Dy39C0PE.js} +2 -2
  97. package/dist/client/assets/{_chat.pull-requests-DVfSewSZ.js → _chat.pull-requests-Bzb1CyG6.js} +2 -2
  98. package/dist/client/assets/{assetUrls-BOJMUK_1.js → assetUrls-DSeSTRY1.js} +2 -2
  99. package/dist/client/assets/{assets-6zZLBDZw.js → assets-B_r3wLhD.js} +2 -2
  100. package/dist/client/assets/{browserHistoryStore-TJXTYA-V.js → browserHistoryStore-BG8TrOnZ.js} +2 -2
  101. package/dist/client/assets/{browserLinkTarget-DRbX4L_9.js → browserLinkTarget-jRu1-WRM.js} +2 -2
  102. package/dist/client/assets/{connect-Dp9BB7ev.js → connect-a25FIa26.js} +2 -2
  103. package/dist/client/assets/{connect-agent-DkbIqI-8.js → connect-agent-C1UODlly.js} +2 -2
  104. package/dist/client/assets/{design-Dn5DzqF2.js → design-C7HRMO73.js} +2 -2
  105. package/dist/client/assets/{device-dylO5xoO.js → device-BNK9g-io.js} +2 -2
  106. package/dist/client/assets/{diffRendering-MXukhqw1.js → diffRendering-UEl_19xa.js} +2 -2
  107. package/dist/client/assets/{dist-ceTe_mn7.js → dist-ATiHSdUa.js} +2 -2
  108. package/dist/client/assets/{duoViewer-C0aL6Kyr.js → duoViewer-C7BduYuF.js} +2 -2
  109. package/dist/client/assets/{dynamic-DTzzXo3L.js → dynamic-CFqi-4NG.js} +2 -2
  110. package/dist/client/assets/{embeddedScripts-DcWCyBxX.js → embeddedScripts-BNfDELW_.js} +2 -2
  111. package/dist/client/assets/{entities-eRiwvW2F.js → entities-pafv-XUM.js} +2 -2
  112. package/dist/client/assets/{fileLinks-CYejoXPq.js → fileLinks-pJLWwULO.js} +2 -2
  113. package/dist/client/assets/{fileTreeExpansion-wG1G7D6R.js → fileTreeExpansion-CXgwpUPc.js} +2 -2
  114. package/dist/client/assets/{getDiffFileInput-CzeweGHs.js → getDiffFileInput-eTK8du_O.js} +2 -2
  115. package/dist/client/assets/{guideRunStore-DAYN2Zd7.js → guideRunStore-83fw4RPw.js} +2 -2
  116. package/dist/client/assets/{index-DA9og9YW.js → index-C0oEvzQc.js} +3 -3
  117. package/dist/client/assets/{lazy-Ccs3klKO.js → lazy-B292152Q.js} +4 -4
  118. package/dist/client/assets/{linkedPrompt-BJh0Yqud.js → linkedPrompt-BOQDb8-o.js} +2 -2
  119. package/dist/client/assets/{main-DleJeMZO.js → main-Cywp3EWc.js} +7 -7
  120. package/dist/client/assets/{mediaReference-BbSbhpkR.js → mediaReference-onv8z3Oz.js} +2 -2
  121. package/dist/client/assets/{mediaSource-B_75uvyp.js → mediaSource-BhEv5iyl.js} +2 -2
  122. package/dist/client/assets/{onboarding-1Zg3fM0A.js → onboarding-y217_KQL.js} +2 -2
  123. package/dist/client/assets/{openFileInPreview-CiPuDrfB.js → openFileInPreview-DeuqxJFn.js} +2 -2
  124. package/dist/client/assets/{p4ProjectFile-BVKW5TIA.js → p4ProjectFile-BuzidL5M.js} +2 -2
  125. package/dist/client/assets/{pair-DUv1mY4i.js → pair-BjRq2ZHP.js} +2 -2
  126. package/dist/client/assets/{phoneViewer-CStYy_tX.js → phoneViewer-DYOR2qAi.js} +2 -2
  127. package/dist/client/assets/{pierre-icons-D3vWvKqU.js → pierre-icons-BDVVO9cA.js} +2 -2
  128. package/dist/client/assets/{preview-ipLyyv_l.js → preview-BoTHkmVi.js} +2 -2
  129. package/dist/client/assets/{primary-CMBPxKMH.js → primary-DiwDV4KJ.js} +2 -2
  130. package/dist/client/assets/{primaryCloudLinkState-CER468V5.js → primaryCloudLinkState-BgmcA0C5.js} +2 -2
  131. package/dist/client/assets/{projectFilesQueryState-D4FdR3Xm.js → projectFilesQueryState-C_yH-05-.js} +2 -2
  132. package/dist/client/assets/{projectScriptEditor-4wQTbXvz.js → projectScriptEditor-Cu65VaAw.js} +2 -2
  133. package/dist/client/assets/{providerSkills-D3rxPB_g.js → providerSkills-CgtkB3rc.js} +2 -2
  134. package/dist/client/assets/{pullRequestDetail.logic-Bkh57WzV.js → pullRequestDetail.logic-FUlKz34F.js} +2 -2
  135. package/dist/client/assets/{pullRequests-DggtcbhA.js → pullRequests-C8-SkuQU.js} +2 -2
  136. package/dist/client/assets/{queries-DJfKGsHe.js → queries-BZGM6AjA.js} +2 -2
  137. package/dist/client/assets/{renderScheduler-BgGYA97h.js → renderScheduler-CGMZZETC.js} +2 -2
  138. package/dist/client/assets/{runtime-BOlBBevr.js → runtime-BBIAfWJY.js} +3 -3
  139. package/dist/client/assets/{runtime-CeFhsGnm.js → runtime-CABaKt1A.js} +3 -3
  140. package/dist/client/assets/{scheduledTasksSettings.logic-BpOBCcOk.js → scheduledTasksSettings.logic-DFlgKyt2.js} +2 -2
  141. package/dist/client/assets/{server-DvWrfyUO.js → server-mIR8e8Vz.js} +2 -2
  142. package/dist/client/assets/{session-D3gY-tOR.js → session-BlCBDyVn.js} +2 -2
  143. package/dist/client/assets/{session-logic-OeNFZd_V.js → session-logic-CwBN7BBv.js} +2 -2
  144. package/dist/client/assets/{settings-C6gUwixG.js → settings-fTPmNkCr.js} +2 -2
  145. package/dist/client/assets/{settings.appearance-BdGq8dkT.js → settings.appearance-D96WohbH.js} +2 -2
  146. package/dist/client/assets/settings.archived-CnXEwX0Z.js +2 -0
  147. package/dist/client/assets/{settings.computer-use-DTAvnNqQ.js → settings.computer-use-DZTx8sD-.js} +2 -2
  148. package/dist/client/assets/{settings.connections-CZD-0BNX.js → settings.connections-Rl7zwQ75.js} +2 -2
  149. package/dist/client/assets/{settings.data-controls-CTVHY8Rd.js → settings.data-controls-DuyfuMcN.js} +2 -2
  150. package/dist/client/assets/{settings.decisions-D3zMITNw.js → settings.decisions-eRAu1hqY.js} +2 -2
  151. package/dist/client/assets/{settings.designs-DWeI1d2s.js → settings.designs-C0RxEgfD.js} +2 -2
  152. package/dist/client/assets/{settings.diagnostics-CqC6fhz6.js → settings.diagnostics-BDo1Ma1e.js} +2 -2
  153. package/dist/client/assets/{settings.general-BDEcQVI4.js → settings.general-CpbG8_Ml.js} +2 -2
  154. package/dist/client/assets/{settings.integrations-BmqNoylk.js → settings.integrations-CujbsXfc.js} +2 -2
  155. package/dist/client/assets/{settings.keybindings-Mt7J5TKC.js → settings.keybindings-CQ5xk9v3.js} +2 -2
  156. package/dist/client/assets/{settings.open-source-licenses-Dvex7Jce.js → settings.open-source-licenses-DIBdHSDB.js} +2 -2
  157. package/dist/client/assets/{settings.plugins-BAFed2wY.js → settings.plugins-BbsrwhRq.js} +2 -2
  158. package/dist/client/assets/{settings.projects-DhuXD_vx.js → settings.projects-BeNHSNe9.js} +3 -3
  159. package/dist/client/assets/{settings.providers-D_-kNRqH.js → settings.providers-DQT6izvS.js} +3 -3
  160. package/dist/client/assets/{settings.scheduled-tasks-Z4aprmEO.js → settings.scheduled-tasks-vKCtN-OC.js} +2 -2
  161. package/dist/client/assets/{settings.snap-shot-o0bdbS5t.js → settings.snap-shot-DgPUS-Zo.js} +2 -2
  162. package/dist/client/assets/{settings.source-control-CwJzBnSu.js → settings.source-control-B87geXn3.js} +2 -2
  163. package/dist/client/assets/{settings.storage-B4ahmlhx.js → settings.storage-BYfdzwhk.js} +2 -2
  164. package/dist/client/assets/{settingsLayout-DrhqvTJ8.js → settingsLayout-vgYGia0Q.js} +2 -2
  165. package/dist/client/assets/{sidebarProjectGrouping-DDt6qTcu.js → sidebarProjectGrouping-DaMfJpqc.js} +2 -2
  166. package/dist/client/assets/{sourceControl-Dqo9EYNC.js → sourceControl-CcPqr0UX.js} +2 -2
  167. package/dist/client/assets/{sourceControlClients-DGnHi6Rd.js → sourceControlClients-DtjbXUDt.js} +2 -2
  168. package/dist/client/assets/{terminalSessions-BykgTNwT.js → terminalSessions-0YYscaVr.js} +2 -2
  169. package/dist/client/assets/{toast-C61oyZY1.js → toast-D26NINYU.js} +2 -2
  170. package/dist/client/assets/{uiStateStore-DL8OsPjd.js → uiStateStore-CKKy2mq4.js} +2 -2
  171. package/dist/client/assets/{usage-DATBL2Du.js → usage-BDFFNkIV.js} +2 -2
  172. package/dist/client/assets/{use-atom-command-Bt7x9oO0.js → use-atom-command-C4y634Qy.js} +2 -2
  173. package/dist/client/assets/{useHandleNewThread-BOKOo2wA.js → useHandleNewThread-C7ynA68A.js} +2 -2
  174. package/dist/client/assets/{useP4ConnectAuthPrompt-D63n-MFC.js → useP4ConnectAuthPrompt-5uCMQUT1.js} +2 -2
  175. package/dist/client/assets/{usePullRequestActions-D53oZord.js → usePullRequestActions-cmzmOrJ-.js} +2 -2
  176. package/dist/client/assets/{useScopedModelAvailability-CeAUx0qZ.js → useScopedModelAvailability-kczZtr1M.js} +2 -2
  177. package/dist/client/assets/{useSettings-VTow9ZEM.js → useSettings-CHt2_4He.js} +2 -2
  178. package/dist/client/assets/{vcsRefInvalidation-B2f3qDSR.js → vcsRefInvalidation-CytQodoP.js} +2 -2
  179. package/dist/client/assets/{welcome-CQgOocvj.js → welcome-pbssrwWd.js} +2 -2
  180. package/dist/client/index.html +1 -1
  181. package/package.json +1 -1
  182. package/dist/client/assets/JZOYTAAL-BrzaFmLe.js +0 -1
  183. package/dist/client/assets/settings.archived-DobN7ZtC.js +0 -2
@@ -1,2 +1,2 @@
1
- import{a as e,t}from"./react-DH3P2YXY.js";import{n,t as r}from"./jsx-runtime-BnjsACtP.js";import{$n as i,Ad as a,Eb as o,Hy as s,Ld as c,M_ as l,Nb as u,Os as d,Xn as f,Xy as p,Yn as m,Yp as h,Zo as g,_m as _,ar as v,as as y,dr as b,fr as x,im as S,js as C,ks as w,ob as T,ps as E,qf as D,rh as O,rl as k,rs as A,sv as j,t as M,tE as N,tr as ee,ts as P,ur as F}from"./utils-CBe1bHL7.js";import{B as I,L,W as R,q as z}from"./runtime-CeFhsGnm.js";import{a as B,c as V,o as te,s as ne,t as re}from"./select-Cbpdz6n3.js";import{t as ie}from"./useNavigateBack-CwjQ4iuL.js";import{nt as ae}from"./useSettings-VTow9ZEM.js";import{f as oe,s as se}from"./server-DvWrfyUO.js";import{n as H,t as U}from"./session-D3gY-tOR.js";import{t as ce}from"./use-atom-command-Bt7x9oO0.js";import{a as le,c as ue,d as W,f as G,i as de,l as K,n as fe,o as pe,r as q,s as J,t as Y,u as me}from"./usageFormat-D5Mz5ugL.js";import{t as he}from"./env-wK1YYxA8.js";import{a as ge,n as _e,t as ve}from"./tooltip-ChmjT8Ns.js";import{t as X}from"./skeleton-CFtayHTe.js";import{n as ye,t as be}from"./toggle-group-yF5GZ53o.js";import{t as xe}from"./input-DXGWoa4O.js";import{t as Se}from"./scroll-area-CQNIjQ8U.js";import{a as Ce,c as we,i as Te,o as Ee,r as De,s as Oe,t as ke}from"./dialog-_vbB7RKH.js";import{o as Ae}from"./sidebar-BhJqncti.js";import{t as je}from"./observeResize-DzSkewug.js";import{y as Me}from"./keybindings-DAHl8jIl.js";import{i as Ne,o as Pe,t as Fe}from"./popover-CogH2zM4.js";import{S as Ie,n as Le,t as Re}from"./ChatGptUsageButton-3K5PpaVk.js";import{t as ze}from"./WorkspacePageContainer-MDWEFwmu.js";import{n as Be,r as Ve,t as He}from"./usageShortcuts-mAekk3eG.js";import{Cr as Ue,Er as We,Tr as Ge,ii as Ke,sa as qe,va as Je,wr as Ye,xo as Xe}from"./main-DleJeMZO.js";import{t as Ze}from"./WorkspacePageHeader-CNcKDaqG.js";import{i as Qe,n as $e,r as et,t as tt}from"./WorkspaceBreadcrumb-Dr-p0Dtn.js";import{t as nt}from"./usageAccess-kgUHYKOw.js";var Z=e(t(),1),Q=n(),rt=o(z);function it(e,t){return e?.sources.some(e=>e.action===`enableCursorKeychain`)===!0&&t?.some(e=>e.driver===`cursor`&&e.status===`ready`)===!0}function at(e){return e.some(e=>e.summary?.sources.some(e=>e.fingerprint.provider===`cursor`&&e.fingerprint.hostId===`cursor.com`))?[]:e.filter(e=>e.needsCursorKeychainAccess)}var ot=new Map,st=new Map;async function ct(e,t,n=!1,r=!1){let i=st.get(e);if(i!==void 0){if(r){try{await i}catch{}return ct(e,t,!1,!0)}return n?void 0:await i}let a=ot.get(e)??0;if(n&&Date.now()<a)return;let o=Promise.resolve().then(t).finally(()=>{st.delete(e),ot.set(e,Date.now()+3e5)});return st.set(e,o),await o}async function lt({registry:e,server:t,presentations:n,environmentIds:r,input:i}){await Promise.all(r.map(async r=>{let a=t.usageSummary({environmentId:r,input:i}),o=n.presentationAtom(r),s=new AbortController,c=()=>{e.get(o)?.connection.phase!==`connected`&&s.abort()},l=e.subscribe(o,c);c();try{let n=await I(e,t.refreshUsageRates,{environmentId:r,input:{}},{reportFailure:!1}),i=n._tag===`Failure`&&rt(R(n));if(e.refresh(a),i||s.signal.aborted)return;await L(e,a,{reportFailure:!1,signal:s.signal})}finally{l()}}))}function ut(e,t=!1){let{summary:n}=e;if(!e.isConnected||e.error!==null)return{phase:`inactive`};if(n===null)return{phase:`loading`};if(t)return{phase:`stale`};if(!e.isPending)return{phase:`ready`};let r=[...new Set(n.sources.flatMap(e=>e.refreshing?[e.fingerprint.provider]:[]))];return r.length>0?{phase:`partway`,providers:r}:{phase:`stale`}}function dt(e,t){return e.length===1?`Updating ${t(e[0])}…`:`Updating ${e.length} providers…`}function ft(e,t=!1){let n=new Set,r=!1;for(let i of e){let e=ut(i,t);if((e.phase===`loading`||e.phase===`stale`)&&(r=!0),e.phase===`partway`)for(let t of e.providers)n.add(t)}return{partial:r||n.size>0,everyProvider:r,providers:n}}function pt(e){return e.records>0&&e.unpricedRecords>=e.records}function mt(e){return[e.hostId,e.provider,e.resolvedHomePath,e.volumeId].join(` `)}function ht(e,t){let n=e.sources.filter(e=>e.fingerprint.provider===t.fingerprint.provider);return e.buckets.filter(e=>e.provider===t.fingerprint.provider&&(e.sourcePath===t.fingerprint.resolvedHomePath||e.sourcePath===void 0&&n.length===1))}function gt(e){return JSON.stringify([e.day,e.hourStart??null,e.provider,e.model])}function _t(e){let t=new Map,n=new Map,r=new Map,i=new Map,a=new Map,o=[],s=[...e].sort((e,t)=>(Date.parse(t.summary.readAt)||0)-(Date.parse(e.summary.readAt)||0)||e.environmentId.localeCompare(t.environmentId));for(let e of[`ok`,`partial`,`failed`])for(let r of s)for(let i of r.summary.sources){if(i.status!==e)continue;let s=mt(i.fingerprint);if(t.has(s)){o.push(`${r.label}: ${i.fingerprint.resolvedHomePath}`);continue}t.set(s,r.environmentId),n.set(s,{environment:r,source:i}),a.set(s,i.distinctSessions)}for(let e of s)for(let t of e.summary.sources){if(t.status!==`partial`)continue;let o=mt(t.fingerprint),s=n.get(o);if(s?.source.status!==`ok`||Date.parse(e.summary.readAt)<=Date.parse(s.environment.summary.readAt))continue;let c=r.get(o);c===void 0&&(c=new Set(ht(s.environment.summary,s.source).map(gt)),r.set(o,c));let l=i.get(e.environmentId)??new Set,u=!1;for(let n of ht(e.summary,t)){let e=gt(n);c.has(e)||(c.add(e),l.add(n),u=!0)}u&&(i.set(e.environmentId,l),a.set(o,Math.max(a.get(o)??0,t.distinctSessions)))}return{ownerByFingerprint:t,supplementalBucketsByEnvironment:i,sessionsByFingerprint:a,duplicates:o}}function vt(e,t,n,r){let i=new Set,a=new Set,o=new Map;for(let n of e.summary.sources){if(n.status===`missing`)continue;let s=mt(n.fingerprint);if(t.get(s)===e.environmentId){let e=n.fingerprint.provider;i.add(e),a.add(`${e}\u0000${n.fingerprint.resolvedHomePath}`),o.set(e,(o.get(e)??0)+(r.get(s)??n.distinctSessions))}}return{buckets:e.summary.buckets.filter(e=>n.has(e)||(e.sourcePath===void 0?i.has(e.provider):a.has(`${e.provider}\u0000${e.sourcePath}`))),sessionsByProvider:o}}function yt(e){return e.totals.uncachedInputTokens+e.totals.cachedInputTokens+e.totals.cacheCreationTokens+e.totals.outputTokens}function bt(e,t){return e>=4&&e<=t}var xt={costUsd:0,uncachedInputTokens:0,cachedInputTokens:0,cacheCreationTokens:0,outputTokens:0,reasoningTokens:0,totalTokens:0,records:0,sessions:0,providers:[],models:[],daily:[],hourly:[],costQuality:{providerReportedShare:0,modelPricedShare:0,unpricedShare:0,cacheSavingsUsd:0},categoryCost:{input:0,cacheRead:0,cacheWrite:0,output:0,unsplit:0},speedCost:{standard:0,fast:0,ultrafast:0,premium:0},duplicateSources:[],contributingEnvironments:[],contractMismatches:[]};function St(e,t){if(e.length===0)return xt;let n=[],r=[];for(let i of e)bt(i.summary.contractVersion,t)?n.push(i):r.push({environmentId:i.environmentId,direction:i.summary.contractVersion<t?`serverBehind`:`clientBehind`,contractVersion:i.summary.contractVersion});let{ownerByFingerprint:i,supplementalBucketsByEnvironment:a,sessionsByFingerprint:o,duplicates:s}=_t(n),c=0,l=0,u=0,d=0,f=0,p=0,m=0,h=0,g=0,_=0,v=0,y={input:0,cacheRead:0,cacheWrite:0,output:0},b={fast:0,ultrafast:0,premium:0},x=new Map,S=new Map,C=new Map,w=new Map,T=[];for(let e of n){let{buckets:t,sessionsByProvider:n}=vt(e,i,a.get(e.environmentId)??new Set,o);t.length>0&&T.push(e.environmentId);for(let[e,t]of n){if(h+=t,t===0)continue;let n=x.get(e)??{costUsd:0,totalTokens:0,records:0,sessions:0};n.sessions+=t,x.set(e,n)}for(let e of t){let t=yt(e);c+=e.costUsd,g+=e.cacheSavingsUsd,l+=e.totals.uncachedInputTokens,u+=e.totals.cachedInputTokens,d+=e.totals.cacheCreationTokens,f+=e.totals.outputTokens,p+=e.totals.reasoningTokens,m+=e.records,v+=e.unpricedRecords,e.costSource===`providerReported`&&(_+=e.records),e.categoryCostUsd!==void 0&&(y.input+=e.categoryCostUsd.input,y.cacheRead+=e.categoryCostUsd.cacheRead,y.cacheWrite+=e.categoryCostUsd.cacheWrite,y.output+=e.categoryCostUsd.output),b.fast+=e.fastCostUsd??0,b.ultrafast+=e.ultrafastCostUsd??0,b.premium+=e.speedPremiumUsd??0;let n=x.get(e.provider)??{costUsd:0,totalTokens:0,records:0,sessions:0};n.costUsd+=e.costUsd,n.totalTokens+=t,n.records+=e.records,x.set(e.provider,n);let r=`${e.provider} ${e.model}`,i=S.get(r)??{provider:e.provider,costUsd:0,totalTokens:0,tokens:{uncachedInputTokens:0,cachedInputTokens:0,cacheCreationTokens:0,outputTokens:0,reasoningTokens:0},records:0,unpricedRecords:0,unpricedTokens:0};i.costUsd+=e.costUsd,i.totalTokens+=t,i.tokens={uncachedInputTokens:i.tokens.uncachedInputTokens+e.totals.uncachedInputTokens,cachedInputTokens:i.tokens.cachedInputTokens+e.totals.cachedInputTokens,cacheCreationTokens:i.tokens.cacheCreationTokens+e.totals.cacheCreationTokens,outputTokens:i.tokens.outputTokens+e.totals.outputTokens,reasoningTokens:i.tokens.reasoningTokens+e.totals.reasoningTokens},i.records+=e.records,i.unpricedRecords+=e.unpricedRecords,e.records>0&&(i.unpricedTokens+=t*e.unpricedRecords/e.records),S.set(r,i);let a=C.get(e.day)??{costUsd:0,totalTokens:0,byProvider:new Map};a.costUsd+=e.costUsd,a.totalTokens+=t;let o=a.byProvider.get(e.provider)??{costUsd:0,totalTokens:0};if(o.costUsd+=e.costUsd,o.totalTokens+=t,a.byProvider.set(e.provider,o),C.set(e.day,a),e.hourStart!==void 0){let n=w.get(e.hourStart)??{day:e.day,hourStart:e.hourStart,costUsd:0,totalTokens:0,byProvider:new Map};n.costUsd+=e.costUsd,n.totalTokens+=t;let r=n.byProvider.get(e.provider)??{costUsd:0,totalTokens:0};r.costUsd+=e.costUsd,r.totalTokens+=t,n.byProvider.set(e.provider,r),w.set(e.hourStart,n)}}}let E=l+u+d+f,D=[...x.entries()].map(([e,t])=>({provider:e,costUsd:t.costUsd,totalTokens:t.totalTokens,records:t.records,sessions:t.sessions,costShare:c===0?0:t.costUsd/c,tokenShare:E===0?0:t.totalTokens/E})).sort((e,t)=>t.costUsd-e.costUsd),O=[...S.entries()].map(([e,t])=>({model:e.slice(e.indexOf(` `)+1),provider:t.provider,costUsd:t.costUsd,totalTokens:t.totalTokens,tokens:t.tokens,records:t.records,unpricedRecords:t.unpricedRecords,unpricedTokens:t.unpricedTokens,costShare:c===0?0:t.costUsd/c,tokenShare:E===0?0:t.totalTokens/E})).sort((e,t)=>t.costUsd-e.costUsd||t.totalTokens-e.totalTokens),k=[...C.entries()].map(([e,t])=>({day:e,costUsd:t.costUsd,totalTokens:t.totalTokens,byProvider:t.byProvider})).sort((e,t)=>e.day.localeCompare(t.day)),A=[...w.values()].sort((e,t)=>e.hourStart.localeCompare(t.hourStart));return{costUsd:c,uncachedInputTokens:l,cachedInputTokens:u,cacheCreationTokens:d,outputTokens:f,reasoningTokens:p,totalTokens:E,records:m,sessions:h,providers:D,models:O,daily:k,hourly:A,costQuality:{providerReportedShare:m===0?0:_/m,unpricedShare:m===0?0:v/m,modelPricedShare:m===0?0:(m-_-v)/m,cacheSavingsUsd:g},categoryCost:{...y,unsplit:Math.max(0,c-y.input-y.cacheRead-y.cacheWrite-y.output)},speedCost:{...b,standard:Math.max(0,c-b.fast-b.ultrafast)},duplicateSources:s,contributingEnvironments:T,contractMismatches:r}}var Ct=A(e=>y(t=>{let n=JSON.parse(e),r=t(ae.presentationsAtom),i=[];for(let[e,a]of r){let r=a.connection.phase===`connected`,o=t(U.sessionStateAtom(e)),s=nt({connectionPhase:a.connection.phase,session:N(d(o)),hasSessionError:o._tag===`Failure`});if(!s.canReadDiagnostics){i.push({environmentId:e,label:a.entry.target.label,isConnected:r,...s,summary:null,needsCursorKeychainAccess:!1});continue}let c=t(oe.usageSummary({environmentId:e,input:n})),l=N(d(c));i.push({environmentId:e,label:a.entry.target.label,isPending:c.waiting,canReadDiagnostics:!0,isConnected:r,error:c._tag===`Failure`?`This environment could not report usage.`:null,summary:l,needsCursorKeychainAccess:it(l,t(oe.providersValueAtom(e)))})}return i}).pipe(E(`web-usage:window:${e}`)));function wt(e,t){return St(e.flatMap(({environmentId:e,label:n,summary:r})=>r===null?[]:[{environmentId:e,label:n,summary:t===void 0?r:{...r,buckets:r.buckets.filter(t)}}]),6)}var Tt=new Set;function Et(e,t){return t.size===0?e:e.map(e=>e.summary===null?e:{...e,summary:{...e.summary,buckets:e.summary.buckets.filter(e=>!t.has(e.provider)),sources:e.summary.sources.filter(e=>!t.has(e.fingerprint.provider))}})}function Dt(e,t,n){let r=(0,Q.c)(36),i=t===void 0?null:t,a=n===void 0?Tt:n,o;r[0]!==e.resolution||r[1]!==e.sinceDay||r[2]!==e.sinceTime||r[3]!==e.timeZone||r[4]!==e.untilDay||r[5]!==e.untilTime?(o=JSON.stringify({sinceDay:e.sinceDay,untilDay:e.untilDay,timeZone:e.timeZone,resolution:e.resolution,sinceTime:e.sinceTime,untilTime:e.untilTime}),r[0]=e.resolution,r[1]=e.sinceDay,r[2]=e.sinceTime,r[3]=e.timeZone,r[4]=e.untilDay,r[5]=e.untilTime,r[6]=o):o=r[6];let s=o,c;r[7]===s?c=r[8]:(c=Ct(s),r[7]=s,r[8]=c);let l=P(c),u;r[9]!==l||r[10]!==i?(u=i===null?l:l.filter(e=>i.has(e.environmentId)),r[9]=l,r[10]=i,r[11]=u):u=r[11];let d=u,f;r[12]!==d||r[13]!==s?(f=e=>lt({registry:g,server:oe,presentations:ae,environmentIds:d.filter(jt).map(At),input:e??JSON.parse(s)}),r[12]=d,r[13]=s,r[14]=f):f=r[14];let p=f,m;r[15]!==a||r[16]!==d?(m=wt(Et(d,a)),r[15]=a,r[16]=d,r[17]=m):m=r[17];let h=m,_;r[18]===d?_=r[19]:(_=d.filter(kt),r[18]=d,r[19]=_);let v=_.length,y;r[20]===d?y=r[21]:(y=d.filter(Ot),r[20]=d,r[21]=y);let b=y.length,x=v===0&&b>0,[S,C]=(0,Z.useState)(null);v>0&&(S?.merged!==h||S.window!==e||S.selection!==i||S.hidden!==a)&&C({window:e,merged:h,selection:i,hidden:a});let w=S?.selection===i&&S.hidden===a?S:null,T;r[22]!==v||r[23]!==e||r[24]!==x||r[25]!==w||r[26]!==h?(T=v>0?{window:e,merged:h}:w??(x?null:{window:e,merged:h}),r[22]=v,r[23]=e,r[24]=x,r[25]=w,r[26]=h,r[27]=T):T=r[27];let E=T,D=v>0&&b>0,O;return r[28]!==l||r[29]!==x||r[30]!==h||r[31]!==p||r[32]!==d||r[33]!==E||r[34]!==D?(O={merged:h,environments:l,selectedEnvironments:d,isPending:x,shown:E,isPartial:D,refresh:p},r[28]=l,r[29]=x,r[30]=h,r[31]=p,r[32]=d,r[33]=E,r[34]=D,r[35]=O):O=r[35],O}function Ot(e){return e.summary===null&&e.error===null}function kt(e){return e.summary!==null}function At(e){let{environmentId:t}=e;return t}function jt(e){return e.canReadDiagnostics&&H(e.environmentId,`diagnostics:read`)}var $=e(r(),1);function Mt(e){let t=(0,Q.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=M(`w-full caption-bottom text-xs`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,$.jsx)(`div`,{"data-slot":`table-container`,className:`relative w-full overflow-x-auto`,children:(0,$.jsx)(`table`,{"data-slot":`table`,className:i,...r})}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function Nt(e){let t=(0,Q.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=M(`[&_tr]:border-b`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,$.jsx)(`thead`,{"data-slot":`table-header`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function Pt(e){let t=(0,Q.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=M(`[&_tr:last-child]:border-0`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,$.jsx)(`tbody`,{"data-slot":`table-body`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function Ft(e){let t=(0,Q.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=M(`border-b transition-colors hover:bg-muted/50 has-aria-expanded:bg-muted/50 data-[state=selected]:bg-muted`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,$.jsx)(`tr`,{"data-slot":`table-row`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function It(e){let t=(0,Q.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=M(`h-10 px-2 text-left align-middle font-medium whitespace-nowrap text-foreground [&:has([role=checkbox])]:pr-0`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,$.jsx)(`th`,{"data-slot":`table-head`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function Lt(e){let t=(0,Q.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=M(`p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,$.jsx)(`td`,{"data-slot":`table-cell`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}var Rt=[{key:`inputCostPerMillionTokens`,label:`Input`,optional:!1},{key:`outputCostPerMillionTokens`,label:`Output`,optional:!1},{key:`cacheReadCostPerMillionTokens`,label:`Cache read`,optional:!0},{key:`cacheWriteCostPerMillionTokens`,label:`Cache write`,optional:!0}];function zt(e=``,t){return{model:e,inputCostPerMillionTokens:t?.inputCostPerMillionTokens.toString()??``,outputCostPerMillionTokens:t?.outputCostPerMillionTokens.toString()??``,cacheReadCostPerMillionTokens:t?.cacheReadCostPerMillionTokens?.toString()??``,cacheWriteCostPerMillionTokens:t?.cacheWriteCostPerMillionTokens?.toString()??``}}function Bt(e){let t=e.model.trim();if(t.length===0)return null;let n={};for(let t of Rt){let r=e[t.key].trim();if(r===``){if(t.optional)continue;return null}if(!/^(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i.test(r))return null;let i=Number(r);if(!Number.isFinite(i)||i<0)return null;n[t.key]=i}return n.inputCostPerMillionTokens===void 0||n.outputCostPerMillionTokens===void 0?null:{model:t,price:{inputCostPerMillionTokens:n.inputCostPerMillionTokens,outputCostPerMillionTokens:n.outputCostPerMillionTokens,...n.cacheReadCostPerMillionTokens===void 0?{}:{cacheReadCostPerMillionTokens:n.cacheReadCostPerMillionTokens},...n.cacheWriteCostPerMillionTokens===void 0?{}:{cacheWriteCostPerMillionTokens:n.cacheWriteCostPerMillionTokens}}}}function Vt(e){return e.isNew&&e.model.trim()===``&&(e.alias??``).trim()===``&&Object.values(e.values).every(e=>e.trim()===``)}function Ht(e,t){return e.prices&&Object.hasOwn(e.prices,t)?e.prices[t]:void 0}function Ut(e,t){return e.aliases&&Object.hasOwn(e.aliases,t)?e.aliases[t]:void 0}function Wt(e,t){if(e.some(e=>e.aliases===null))return{value:``,placeholder:`Unavailable`};let n=e.map(e=>Ut(e,t)??``);return n.some(e=>e!==n[0])?{value:``,placeholder:`Mixed`}:{value:n[0]??``,placeholder:`None`}}function Gt(e,t,n){let r=Rt.find(e=>e.key===n).optional,i=e.map(e=>Ht(e,t)?zt(t,Ht(e,t))[n]:null);return e.some(e=>e.prices===null)?{value:``,placeholder:`Unavailable`}:i.some(e=>e!==i[0])?{value:``,placeholder:`Mixed`}:{value:i[0]??``,placeholder:i[0]===null?`Automatic`:r?`Input rate`:`0.00`}}function Kt(e,t){let n=[],r=new Map;for(let i of t){if(Vt(i))continue;let t=i.model.trim(),a=Ut(e,t);if(i.removed){Ht(e,t)&&n.push({model:t,price:null}),a!==void 0&&n.push({model:t,alias:null});continue}let o=(i.alias??a??``).trim();if(o!==``){t===``?r.set(i.id,`Enter a model ID.`):o===t?r.set(i.id,`Map to a different model.`):(o!==a&&n.push({model:t,alias:o}),Ht(e,t)&&n.push({model:t,price:null}));continue}if(a!==void 0&&(n.push({model:t,alias:null}),!Ht(e,t)&&Object.values(i.values).every(e=>e.trim()===``)))continue;let s=zt(t,Ht(e,t)),c={...s,...i.values},l=Bt(c);if(l===null){let n=Rt.find(e=>!e.optional&&c[e.key].trim()===``);r.set(i.id,t===``?`Enter a model ID.`:n?`${n.label} is required on ${e.label}.`:`Use non-negative numbers for prices.`);continue}let u=zt(t,l.price);Rt.some(e=>s[e.key]!==u[e.key])&&n.push(l)}return{changes:n,errors:r}}function qt(e,t){return new Map(e.filter(e=>e.unavailable===null&&e.prices!==null).flatMap(e=>[...Kt(e,t).errors]))}async function Jt(e){await Promise.all(e.targets.map(async t=>{let n,r=e.changes.get(t.environmentId)??[],i=r.flatMap(e=>`price`in e?[[e.model,e.price]]:[]),a=r.flatMap(e=>`alias`in e?[[e.model,e.alias]]:[]);if(t.unavailable!==null)n={status:`failed`,error:t.unavailable};else if(a.length>0&&t.aliases===null)n={status:`failed`,error:`Update server to map models`};else try{n=(r.length===0?{_tag:`Success`}:await e.write({environmentId:t.environmentId,input:{patch:{...i.length>0?{usagePriceOverrides:Object.fromEntries(i)}:{},...a.length>0?{usageModelAliases:Object.fromEntries(a)}:{}}}}))._tag===`Success`?{status:`saved`}:{status:`failed`,error:`Could not save. Try again.`}}catch{n={status:`failed`,error:`Could not save. Try again.`}}e.onResult(t.environmentId,n)}))}var Yt=y(e=>[...e(ae.presentationsAtom)].map(([t,n])=>{let r=e(oe.settingsValueAtom(t)),i=e(U.sessionStateAtom(t)),a=N(d(i)),o=i._tag===`Failure`?`denied`:a===null?i.waiting?`pending`:`denied`:j(a,`settings:write`)?`granted`:`denied`;return{environmentId:t,label:n.entry.target.label,prices:r?.usagePriceOverrides??null,aliases:n.serverConfig?.environment.capabilities.usageModelAliases===!0?r?.usageModelAliases??null:null,unavailable:n.connection.phase===`connected`?r===null?`Prices not loaded`:n.serverConfig?.environment.capabilities.usagePriceOverrides===!0?o===`pending`?`Checking permissions…`:o===`denied`?`Read-only access`:null:`Update server to edit prices`:`Offline`}}));function Xt(e){let t=(0,Q.c)(119),{usage:n,initialSelectedEnvironmentIds:r,initialModel:i,onOpenChange:o}=e,s=P(Yt),[c,l]=(0,Z.useState)(r),u;if(t[0]!==s||t[1]!==c){let e;t[3]===c?e=t[4]:(e=e=>c===null||c.has(e.environmentId),t[3]=c,t[4]=e),u=s.filter(e),t[0]=s,t[1]=c,t[2]=u}else u=t[2];let d=u,p;t[5]!==i||t[6]!==d?(p=()=>i===void 0||d.some(e=>Object.hasOwn(e.prices??{},i)||Object.hasOwn(e.aliases??{},i))?[]:[{id:`new:initial`,model:i,isNew:!0,values:{}}],t[5]=i,t[6]=d,t[7]=p):p=t[7];let[g,_]=(0,Z.useState)(p),[y,x]=(0,Z.useState)(!1),[C,w]=(0,Z.useState)(null),T=(0,Z.useRef)(null),E=(0,Z.useRef)(0),D;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(D={reportFailure:!1},t[8]=D):D=t[8];let k=ce(oe.updateSettings,D),A,j,N,I,L,R,z,B,V,te,ne,re,ie,ae,se;if(t[9]!==C||t[10]!==g||t[11]!==s||t[12]!==o||t[13]!==y||t[14]!==d||t[15]!==c||t[16]!==k||t[17]!==n){let e=[...new Set(d.flatMap(mn))].sort(),r;t[33]===d?r=t[34]:(r=e=>d.some(t=>t.environmentId===e.environmentId),t[33]=d,t[34]=r);let i=[...new Set([...e,...n.filter(r).flatMap(fn)])].sort(),u;t[35]===g?u=t[36]:(u=new Set(g.filter(dn).map(un)),t[35]=g,t[36]=u);let p=u,D;t[37]!==C||t[38]!==p?(D=e=>C===null||!p.has(e),t[37]=C,t[38]=p,t[39]=D):D=t[39];let P=[...e.filter(D).map(e=>g.find(t=>t.id===`model:${e}`)??{id:`model:${e}`,model:e,isNew:!1,values:{}}),...g.filter(ln)],oe=g.filter(cn);R=qt(d,oe);for(let t of oe)t.isNew&&(t.model.trim()===``?R.set(t.id,`Enter a model ID.`):C===null&&(e.includes(t.model.trim())||g.some(e=>e.id!==t.id&&e.model.trim()===t.model.trim()))&&R.set(t.id,`This model already has a row. Edit its prices there.`));z=C?.destinations.filter(e=>C.results.get(e.environmentId)?.status===`failed`)??[];let U=y||z.length>0;B=oe.length>0,I=d.length===1?d[0].label:`${d.length} environments`;let ce=c===null?`All environments`:I,le;t[40]===Symbol.for(`react.memo_cache_sentinel`)?(le=()=>{_([]),w(null)},t[40]=le):le=t[40],L=le;let ue;t[41]===Symbol.for(`react.memo_cache_sentinel`)?(ue=e=>{l(e),w(null)},t[41]=ue):ue=t[41];let W=ue,G;t[42]===Symbol.for(`react.memo_cache_sentinel`)?(G=e=>{_(t=>t.some(t=>t.id===e.id)?t.map(t=>t.id===e.id?e:t):[...t,e]),w(null)},t[42]=G):G=t[42];let de=G,K=sn,fe;t[43]===Symbol.for(`react.memo_cache_sentinel`)?(fe=e=>{!e.isNew&&Object.keys(e.values).length===0&&e.alias===void 0?_(t=>t.filter(t=>t.id!==e.id)):de(e)},t[43]=fe):fe=t[43];let pe=fe,q;t[44]===d?q=t[45]:(q=(e,t,n)=>{let r={...e.values,[t]:n},i=Gt(d,e.model,t);K(e,i,n)&&delete r[t],pe({...e,values:r})},t[44]=d,t[45]=q);let J=q,Y;t[46]===d?Y=t[47]:(Y=(e,t)=>{let{alias:n,...r}=e,i=Wt(d,e.model);pe(K(e,i,t)?r:{...r,alias:t})},t[46]=d,t[47]=Y);let me=Y;V=async e=>{let t=e!==void 0&&e;if(y)return;let n=t?z:d,r=t&&C?C.drafts:oe;if(n.length===0||r.length===0)return;let i=n.map(e=>s.find(t=>t.environmentId===e.environmentId)??{...e,prices:null,aliases:null,unavailable:`Environment removed`}),a=new Map(i.map(e=>[e.environmentId,Kt(e,r)]));x(!0),w(e=>({drafts:r,destinations:t&&e?e.destinations:i,results:new Map([...t&&e?e.results:[],...i.map(on)])}));let o=!1;await Jt({targets:i.map(e=>({...e,unavailable:e.unavailable??[...a.get(e.environmentId).errors.values()][0]??null})),changes:new Map([...a].map(an)),write:async e=>H(e.environmentId,`settings:write`)?k(e):{_tag:`Failure`},onResult:(e,t)=>{t.status===`failed`&&(o=!0),w(n=>n===null?null:{...n,results:new Map(n.results).set(e,t)})}}),x(!1),o||_([])},N=ke,ae=!0,t[48]!==o||t[49]!==y?(se=e=>{y||o(e)},t[48]=o,t[49]=y,t[50]=se):se=t[50],j=Oe,re=`max-w-4xl`,t[51]===Symbol.for(`react.memo_cache_sentinel`)?(ie=(0,$.jsxs)(Ce,{children:[(0,$.jsx)(we,{children:`Custom model prices`}),(0,$.jsx)(De,{children:`Prices and mappings apply to all past and future usage on the environments you select.`})]}),t[51]=ie):ie=t[51],A=Ee;let he;t[52]===Symbol.for(`react.memo_cache_sentinel`)?(he=(0,$.jsx)(qe,{id:`usage-prices-apply-label`,className:`shrink-0`,children:`Apply to`}),t[52]=he):he=t[52];let X;t[53]===Symbol.for(`react.memo_cache_sentinel`)?(X=(0,$.jsx)(b,{variant:`outline`,size:`sm`,className:`min-w-0`}),t[53]=X):X=t[53];let ye=y||B,be;t[54]===ce?be=t[55]:(be=(0,$.jsx)(`span`,{id:`usage-prices-selection`,className:`truncate`,children:ce}),t[54]=ce,t[55]=be);let Se;t[56]===Symbol.for(`react.memo_cache_sentinel`)?(Se=(0,$.jsx)(a,{className:`size-3.5 shrink-0`,"aria-hidden":!0}),t[56]=Se):Se=t[56];let Te;t[57]!==ye||t[58]!==be?(Te=(0,$.jsxs)(F,{render:X,"aria-labelledby":`usage-prices-apply-label usage-prices-selection`,disabled:ye,children:[be,Se]}),t[57]=ye,t[58]=be,t[59]=Te):Te=t[59];let Ae=c===null,je;t[60]===Symbol.for(`react.memo_cache_sentinel`)?(je=e=>W(e?null:new Set),t[60]=je):je=t[60];let Me;t[61]===Ae?Me=t[62]:(Me=(0,$.jsx)(f,{checked:Ae,closeOnClick:!1,onCheckedChange:je,children:`All environments`}),t[61]=Ae,t[62]=Me);let Ne;t[63]===Symbol.for(`react.memo_cache_sentinel`)?(Ne=(0,$.jsx)(v,{}),t[63]=Ne):Ne=t[63];let Pe;if(t[64]!==s||t[65]!==d||t[66]!==c){let e;t[68]!==s.length||t[69]!==d||t[70]!==c?(e=e=>(0,$.jsx)(f,{checked:c===null||c.has(e.environmentId),closeOnClick:!1,onCheckedChange:t=>{let n=new Set(d.map(rn));t?n.add(e.environmentId):n.delete(e.environmentId),W(n.size===s.length?null:n)},children:(0,$.jsxs)(`span`,{className:`flex min-w-0 items-center gap-3`,children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.label}),e.unavailable?(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.unavailable}):null]})},e.environmentId),t[68]=s.length,t[69]=d,t[70]=c,t[71]=e):e=t[71],Pe=s.map(e),t[64]=s,t[65]=d,t[66]=c,t[67]=Pe}else Pe=t[67];let Fe;t[72]!==Me||t[73]!==Pe?(Fe=(0,$.jsxs)(ee,{align:`start`,children:[Me,Ne,Pe]}),t[72]=Me,t[73]=Pe,t[74]=Fe):Fe=t[74];let Ie;t[75]!==Te||t[76]!==Fe?(Ie=(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[he,(0,$.jsxs)(m,{children:[Te,Fe]})]}),t[75]=Te,t[76]=Fe,t[77]=Ie):Ie=t[77];let Le;t[78]===Symbol.for(`react.memo_cache_sentinel`)?(Le=(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`USD / million tokens`}),t[78]=Le):Le=t[78],t[79]===Ie?te=t[80]:(te=(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[Ie,Le]}),t[79]=Ie,t[80]=te),ne=d.length===0?(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:s.length===0?`Connect an environment to set model prices.`:`Select an environment to see and change its model prices.`}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`min-w-0 overflow-hidden rounded-lg border border-border`,children:(0,$.jsxs)(Mt,{className:`min-w-180 table-fixed`,"aria-label":`Custom model prices`,children:[(0,$.jsxs)(`colgroup`,{children:[(0,$.jsx)(`col`,{className:`w-[22%]`}),(0,$.jsx)(`col`,{className:`w-[18%]`}),Rt.map(nn),(0,$.jsx)(`col`,{className:`w-10`})]}),(0,$.jsx)(Nt,{children:(0,$.jsxs)(Ft,{children:[(0,$.jsx)(It,{children:`Model ID`}),(0,$.jsx)(It,{children:`Map to`}),Rt.map(tn),(0,$.jsx)(It,{children:(0,$.jsx)(b,{size:`icon-xs`,variant:`ghost`,"aria-label":`Add model price`,disabled:U,onClick:()=>{E.current+=1;let e=`new:${E.current}`;T.current=e,de({id:e,model:``,isNew:!0,values:{}})},children:(0,$.jsx)(h,{"aria-hidden":!0})})})]})}),(0,$.jsx)(Pt,{children:P.length===0?(0,$.jsx)(Ft,{children:(0,$.jsx)(Lt,{colSpan:7,className:`text-center whitespace-normal`,children:(0,$.jsx)(`p`,{className:`py-6 text-muted-foreground`,children:d.some(en)?`Some environment prices are unavailable.`:`No custom prices or mappings. Add a row to set one.`})})}):P.map(e=>{let t=Wt(d,e.model),n=(e.alias??t.value).trim();return(0,$.jsxs)(Ft,{"data-row-id":e.id,children:[(0,$.jsxs)(Lt,{className:`whitespace-normal`,children:[e.isNew?(0,$.jsx)(xe,{size:`compact`,value:e.model,ref:t=>{t&&T.current===e.id&&(t.focus(),T.current=null)},"aria-label":`New model ID`,"aria-invalid":e.model.trim()!==``&&R.has(e.id)||void 0,list:`usage-price-models`,placeholder:`Model ID`,autoComplete:`off`,spellCheck:!1,disabled:U,onChange:t=>de({...e,model:t.target.value})}):(0,$.jsx)(`span`,{className:M(`block break-all`,e.removed&&`text-muted-foreground line-through`),children:e.model}),R.has(e.id)&&(e.model.trim()!==``||Object.values(e.values).some($t))?(0,$.jsx)(`p`,{role:`alert`,className:`mt-1 text-xs text-destructive`,children:R.get(e.id)}):null]}),e.removed?(0,$.jsx)(Lt,{colSpan:5,children:(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:`Automatic pricing after saving`})}):(0,$.jsx)(Lt,{children:(0,$.jsx)(xe,{size:`compact`,value:e.alias??t.value,"aria-label":`Map ${e.model||`new model`} to model`,list:`usage-alias-models`,placeholder:e.isNew?`Optional`:t.placeholder,autoComplete:`off`,spellCheck:!1,disabled:U,onChange:t=>me(e,t.target.value)})}),e.removed?null:n===``?Rt.map(t=>{let n=Gt(d,e.model,t.key);return(0,$.jsx)(Lt,{children:(0,$.jsx)(xe,{size:`compact`,inputMode:`decimal`,"aria-label":`${t.label} price for ${e.model||`new model`}`,value:e.values[t.key]??(e.isNew?``:n.value),placeholder:e.isNew?t.optional?`Input rate`:`0.00`:n.placeholder,autoComplete:`off`,disabled:U,font:`mono`,onChange:n=>J(e,t.key,n.target.value)})},t.key)}):(0,$.jsx)(Lt,{colSpan:4,className:`whitespace-normal`,children:(0,$.jsxs)(`span`,{className:`break-all text-muted-foreground`,children:[`Counted as `,n]})}),(0,$.jsx)(Lt,{children:(0,$.jsxs)(ve,{children:[(0,$.jsx)(ge,{render:(0,$.jsx)(b,{size:`icon-xs`,variant:`ghost`}),disabled:U,"aria-label":e.removed?`Undo reset for ${e.model}`:e.isNew?`Remove new model`:`Reset price for ${e.model} to automatic`,onClick:()=>{e.isNew?_(t=>t.filter(t=>t.id!==e.id)):e.removed?pe({...e,removed:!1}):de({...e,removed:!0})},children:e.isNew?(0,$.jsx)(O,{"aria-hidden":!0}):(0,$.jsx)(S,{"aria-hidden":!0})}),(0,$.jsx)(_e,{children:e.removed?`Undo reset`:e.isNew?`Remove row`:`Reset to automatic`})]})})]},e.id)})})]})}),(0,$.jsx)(`datalist`,{id:`usage-price-models`,children:i.filter(t=>!e.includes(t)).map(Qt)}),(0,$.jsx)(`datalist`,{id:`usage-alias-models`,children:i.filter(e=>d.every(t=>!Object.hasOwn(t.aliases??{},e))).map(Zt)}),(0,$.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Blank cache rates use the input price. Enter 0 for free tokens. A mapped model’s usage counts as the model it maps to.`,d.length>1?` Mixed cells keep each environment’s rate until you edit them.`:``]})]}),t[9]=C,t[10]=g,t[11]=s,t[12]=o,t[13]=y,t[14]=d,t[15]=c,t[16]=k,t[17]=n,t[18]=A,t[19]=j,t[20]=N,t[21]=I,t[22]=L,t[23]=R,t[24]=z,t[25]=B,t[26]=V,t[27]=te,t[28]=ne,t[29]=re,t[30]=ie,t[31]=ae,t[32]=se}else A=t[18],j=t[19],N=t[20],I=t[21],L=t[22],R=t[23],z=t[24],B=t[25],V=t[26],te=t[27],ne=t[28],re=t[29],ie=t[30],ae=t[31],se=t[32];let U;t[81]===C?U=t[82]:(U=C?(0,$.jsx)(`div`,{role:`status`,className:`grid gap-1 text-xs`,children:C.destinations.map(e=>{let t=C.results.get(e.environmentId);return(0,$.jsxs)(`div`,{className:`flex justify-between gap-3`,children:[(0,$.jsx)(`span`,{className:`truncate text-muted-foreground`,children:e.label}),(0,$.jsx)(`span`,{className:t?.status===`failed`?`text-right text-destructive`:`text-muted-foreground`,children:t?.status===`failed`?`Not saved · ${t.error}`:t?.status===`saved`?`Saved`:`Saving…`})]},e.environmentId)})}):null,t[81]=C,t[82]=U);let le;t[83]!==A||t[84]!==U||t[85]!==te||t[86]!==ne?(le=(0,$.jsxs)(A,{children:[te,ne,U]}),t[83]=A,t[84]=U,t[85]=te,t[86]=ne,t[87]=le):le=t[87];let ue=B?`Changes apply to ${I}`:``,W;t[88]===ue?W=t[89]:(W=(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:ue}),t[88]=ue,t[89]=W);let G;t[90]!==L||t[91]!==z.length||t[92]!==B||t[93]!==y?(G=B?(0,$.jsx)(b,{variant:`ghost`,disabled:y,onClick:L,children:z.length>0?`Discard pending changes`:`Discard changes`}):null,t[90]=L,t[91]=z.length,t[92]=B,t[93]=y,t[94]=G):G=t[94];let de=y||!B&&z.length===0||z.length===0&&(R.size>0||d.length===0),K;t[95]!==z.length||t[96]!==V?(K=()=>void V(z.length>0),t[95]=z.length,t[96]=V,t[97]=K):K=t[97];let fe=y?`Saving…`:z.length>0?`Retry failed saves`:`Save changes`,pe;t[98]!==de||t[99]!==K||t[100]!==fe?(pe=(0,$.jsx)(b,{disabled:de,onClick:K,children:fe}),t[98]=de,t[99]=K,t[100]=fe,t[101]=pe):pe=t[101];let q;t[102]!==G||t[103]!==pe?(q=(0,$.jsxs)(`div`,{className:`flex w-full flex-wrap justify-end gap-2 sm:w-auto`,children:[G,pe]}),t[102]=G,t[103]=pe,t[104]=q):q=t[104];let J;t[105]!==W||t[106]!==q?(J=(0,$.jsxs)(Te,{variant:`bare`,className:`items-center sm:justify-between`,children:[W,q]}),t[105]=W,t[106]=q,t[107]=J):J=t[107];let Y;t[108]!==j||t[109]!==le||t[110]!==J||t[111]!==re||t[112]!==ie?(Y=(0,$.jsxs)(j,{className:re,children:[ie,le,J]}),t[108]=j,t[109]=le,t[110]=J,t[111]=re,t[112]=ie,t[113]=Y):Y=t[113];let me;return t[114]!==N||t[115]!==Y||t[116]!==ae||t[117]!==se?(me=(0,$.jsx)(N,{open:ae,onOpenChange:se,children:Y}),t[114]=N,t[115]=Y,t[116]=ae,t[117]=se,t[118]=me):me=t[118],me}function Zt(e){return(0,$.jsx)(`option`,{value:e},e)}function Qt(e){return(0,$.jsx)(`option`,{value:e},e)}function $t(e){return e!==``}function en(e){return e.prices===null}function tn(e){return(0,$.jsx)(It,{children:e.label},e.key)}function nn(e){return(0,$.jsx)(`col`,{},e.key)}function rn(e){return e.environmentId}function an(e){let[t,n]=e;return[t,n.changes]}function on(e){return[e.environmentId,{status:`saving`}]}function sn(e,t,n){return!e.isNew&&t.placeholder!==`Mixed`&&t.placeholder!==`Unavailable`&&n===t.value}function cn(e){return!Vt(e)}function ln(e){return e.isNew}function un(e){return e.model.trim()}function dn(e){return e.isNew}function fn(e){return e.summary?.buckets.map(pn)??[]}function pn(e){return e.model}function mn(e){return[...Object.keys(e.prices??{}),...Object.keys(e.aliases??{})]}var hn=960,gn=260,_n=4,vn=8,yn=new Set;function bn(e,t,n){let r=e?.byProvider.get(t);return r===void 0?0:n===`tokens`?r.totalTokens:r.costUsd}function xn(e,t,n){return e.map(e=>{let r=t.get(e),i=Ye.map(e=>({provider:e,value:bn(r,e,n)}));return{bands:i,total:i.reduce((e,t)=>e+t.value,0)}})}function Sn(e){let t=e.length;if(t<2)return[0];let n=[];for(let r=0;r<t-1;r+=1){let t=(e[r+1]?.x??0)-(e[r]?.x??0),i=(e[r+1]?.y??0)-(e[r]?.y??0);n.push(t===0?0:i/t)}let r=Array.from({length:t},()=>0);r[0]=n[0]??0,r[t-1]=n[t-2]??0;for(let e=1;e<t-1;e+=1){let t=n[e-1]??0,i=n[e]??0;r[e]=t*i<=0?0:(t+i)/2}for(let e=0;e<t-1;e+=1){let t=n[e]??0;if(t===0){r[e]=0,r[e+1]=0;continue}let i=(r[e]??0)/t,a=(r[e+1]??0)/t,o=i*i+a*a;if(o>9){let n=3/Math.sqrt(o);r[e]=n*i*t,r[e+1]=n*a*t}}return r}function Cn(e){if(e.length<2)return[];let t=Sn(e),n=[];for(let r=0;r<e.length-1;r+=1){let i=e[r],a=e[r+1];if(i===void 0||a===void 0)continue;let o=a.x-i.x;n.push({from:i,c1:{x:i.x+o/3,y:i.y+(t[r]??0)*o/3},c2:{x:a.x-o/3,y:a.y-(t[r+1]??0)*o/3},to:a})}return n}function wn(e){let t=e[0];if(t===void 0)return``;let n=`M${t.from.x.toFixed(2)},${t.from.y.toFixed(2)}`;for(let t of e)n+=` C${t.c1.x.toFixed(2)},${t.c1.y.toFixed(2)} ${t.c2.x.toFixed(2)},${t.c2.y.toFixed(2)} ${t.to.x.toFixed(2)},${t.to.y.toFixed(2)}`;return n}function Tn(e){return e===``?``:`${e} L${hn},${gn} L0,${gn} Z`}function En(e,t){if(e<=0)return{max:0,ticks:[0]};let n=e/t,r=10**Math.floor(Math.log10(n)),i=n/r,a=(i>5?10:i>2?5:i>1?2:1)*r,o=Math.ceil(e/a)*a,s=[];for(let e=0;e<=o+a*1e-6;e+=a)s.push(e);return{max:o,ticks:s}}var Dn=Array.from({length:5},(e,t)=>t);function On(e,t){let n=e.reduce((e,t)=>t.bands.reduce((e,t)=>Math.max(e,t.value),e),0);return n===0&&t.size>0?{max:_n,ticks:Dn,labeled:!1}:{...En(n,_n),labeled:!0}}function kn(e,t){return t===0?gn:gn-e/t*252}function An(e,t,n,r,i){let a=xn(e,t,n),o=On(a,i),s=e.length<2?0:hn/(e.length-1);return{columns:a,scale:o,stepX:s,paths:r.map(e=>{let t=Ye.indexOf(e),n=wn(Cn(a.map((e,n)=>({x:n*s,y:kn(e.bands[t]?.value??0,o.max)}))));return{provider:e,loading:i.has(e),total:a.reduce((e,n)=>e+(n.bands[t]?.value??0),0),line:n,area:Tn(n)}}).toSorted((e,t)=>t.total-e.total)}}function jn(e){let t=(0,Q.c)(97),{providers:n,loadingProviders:r,days:i,daily:a,hours:o,hourly:s,metric:c,referenceTime:l,resolution:u,timeZone:d}=e,f=r===void 0?yn:r,p=u===`hour`?o:i,m;t[0]!==a||t[1]!==s||t[2]!==u?(m=u===`hour`?new Map(s.map(Pn)):new Map(a.map(Nn)),t[0]=a,t[1]=s,t[2]=u,t[3]=m):m=t[3];let h=m,[g,_]=(0,Z.useState)(null),v=(0,Z.useRef)(null),y=(0,Z.useRef)(null),b=(0,Z.useRef)(null),x;t[4]!==h||t[5]!==f||t[6]!==c||t[7]!==p||t[8]!==n?(x=An(p,h,c,n,f),t[4]=h,t[5]=f,t[6]=c,t[7]=p,t[8]=n,t[9]=x):x=t[9];let{columns:S,scale:C,paths:w,stepX:T}=x,E;t[10]===C.max?E=t[11]:(E=e=>kn(e,C.max),t[10]=C.max,t[11]=E);let D=E,O=Mn,k=c===`tokens`?K:W,A;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(A=()=>{let e=v.current,t=y.current,n=b.current;if(e===null||t===null||n===null)return;let r=t.offsetWidth,i=t.offsetHeight,a=e.clientWidth,o=e.clientHeight,s=n.x+12+r<=a?n.x+12:n.x-12-r,c=n.y+12+i<=o?n.y+12:n.y-12-i,l=Math.min(Math.max(0,s),Math.max(0,a-r)),u=Math.min(Math.max(0,c),Math.max(0,o-i));e.style.setProperty(`--usage-tooltip-left`,`${l}px`),e.style.setProperty(`--usage-tooltip-top`,`${u}px`)},t[12]=A):A=t[12];let j=A,N,ee;t[13]===g?(N=t[14],ee=t[15]):(N=()=>{if(g===null)return;j();let e=v.current,t=y.current;if(e!==null&&t!==null)return je([e,t],j)},ee=[g,j],t[13]=g,t[14]=N,t[15]=ee),(0,Z.useLayoutEffect)(N,ee);let P;t[16]===p.length?P=t[17]:(P=e=>{let t=v.current;if(t===null||p.length===0)return;let n=t.getBoundingClientRect();if(n.width===0)return;let r=Math.min(n.width,Math.max(0,e.clientX-n.left)),i=Math.min(n.height,Math.max(0,e.clientY-n.top)),a=r/n.width,o=Math.round(a*(p.length-1));b.current={x:r,y:i},j(),_(Math.min(p.length-1,Math.max(0,o)))},t[16]=p.length,t[17]=P);let F=P,I=g===null?void 0:p[g],L=g===null?void 0:S[g],R;if(t[18]!==f||t[19]!==n){let e;t[21]===f?e=t[22]:(e=e=>f.has(e),t[21]=f,t[22]=e),R=n.some(e),t[18]=f,t[19]=n,t[20]=R}else R=t[20];let z=R,B;t[23]!==u||t[24]!==d?(B=e=>u===`hour`?pe(e,d):le(e),t[23]=u,t[24]=d,t[25]=B):B=t[25];let V=B,te;t[26]!==V||t[27]!==l||t[28]!==u||t[29]!==d?(te=e=>u===`hour`&&l!==void 0?ue(e,l,d):V(e),t[26]=V,t[27]=l,t[28]=u,t[29]=d,t[30]=te):te=t[30];let ne=te,re;t[31]!==k||t[32]!==C.labeled||t[33]!==C.ticks||t[34]!==D?(re=C.labeled?C.ticks.map(e=>(0,$.jsx)(`span`,{className:`absolute right-0 -translate-y-1/2 text-3xs text-muted-foreground tabular-nums`,style:{top:`${D(e)/gn*100}%`},children:e===0?`0`:k(e)},e)):null,t[31]=k,t[32]=C.labeled,t[33]=C.ticks,t[34]=D,t[35]=re):re=t[35];let ie;t[36]===re?ie=t[37]:(ie=(0,$.jsx)(`div`,{className:`relative h-56 w-14 shrink-0`,children:re}),t[36]=re,t[37]=ie);let ae;t[38]===Symbol.for(`react.memo_cache_sentinel`)?(ae=()=>{b.current=null,_(null)},t[38]=ae):ae=t[38];let oe=`${u===`hour`?`Hourly`:`Daily`} ${c===`tokens`?`processed tokens`:`cost`} by provider`,se;if(t[39]!==C.ticks||t[40]!==D){let e;t[42]===D?e=t[43]:(e=e=>{let t=D(e);return(0,$.jsx)(`line`,{x1:0,x2:hn,y1:t,y2:t,stroke:`currentColor`,strokeWidth:1,className:`text-border`,vectorEffect:`non-scaling-stroke`},e)},t[42]=D,t[43]=e),se=C.ticks.map(e),t[39]=C.ticks,t[40]=D,t[41]=se}else se=t[41];let H;if(t[44]!==w){let e;t[46]===Symbol.for(`react.memo_cache_sentinel`)?(e=e=>{let{provider:t,loading:n,area:r}=e;return(0,$.jsx)(`path`,{d:r,className:O(n),fill:Ge[t].color,fillOpacity:.12},t)},t[46]=e):e=t[46],H=w.map(e),t[44]=w,t[45]=H}else H=t[45];let U;if(t[47]!==w){let e;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(e=e=>{let{provider:t,loading:n,line:r}=e;return(0,$.jsx)(`path`,{d:r,className:O(n),fill:`none`,stroke:Ge[t].color,strokeWidth:2,vectorEffect:`non-scaling-stroke`},t)},t[49]=e):e=t[49],U=w.map(e),t[47]=w,t[48]=U}else U=t[48];let ce;t[50]!==g||t[51]!==T?(ce=g===null?null:(0,$.jsx)(`line`,{x1:g*T,x2:g*T,y1:vn,y2:gn,stroke:`currentColor`,strokeWidth:1,className:`text-muted-foreground`,vectorEffect:`non-scaling-stroke`}),t[50]=g,t[51]=T,t[52]=ce):ce=t[52];let G;t[53]!==oe||t[54]!==se||t[55]!==H||t[56]!==U||t[57]!==ce?(G=(0,$.jsxs)(`svg`,{className:`h-full w-full`,viewBox:`0 0 ${hn} ${gn}`,preserveAspectRatio:`none`,role:`img`,"aria-label":oe,children:[se,H,U,ce]}),t[53]=oe,t[54]=se,t[55]=H,t[56]=U,t[57]=ce,t[58]=G):G=t[58];let de;t[59]!==k||t[60]!==ne||t[61]!==L?.bands||t[62]!==L?.total||t[63]!==I||t[64]!==f||t[65]!==z||t[66]!==n?(de=I===void 0?null:(0,$.jsxs)(`div`,{ref:y,className:`surface-glass pointer-events-none absolute z-10 min-w-36 max-w-full rounded-xl border border-border/50 px-2.5 py-2 text-xs shadow-lg`,style:{left:`var(--usage-tooltip-left, 0px)`,top:`var(--usage-tooltip-top, 0px)`},children:[(0,$.jsx)(`div`,{className:`mb-1 text-muted-foreground`,children:ne(I)}),n.map(e=>{let{label:t,driverKind:n}=Ge[e];return(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,$.jsx)(Le,{driverKind:n,displayName:t,iconClassName:`size-3`}),t]}),(0,$.jsx)(`span`,{className:M(`tabular-nums`,f.has(e)?`text-muted-foreground`:`text-foreground`),children:k(L?.bands.find(t=>t.provider===e)?.value??0)})]},e)}),(0,$.jsxs)(`div`,{className:`mt-1 flex items-center justify-between gap-3 border-t border-border pt-1`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:`Total`}),(0,$.jsx)(`span`,{className:M(`tabular-nums`,z?`text-muted-foreground`:`text-foreground`),children:k(L?.total??0)})]})]}),t[59]=k,t[60]=ne,t[61]=L?.bands,t[62]=L?.total,t[63]=I,t[64]=f,t[65]=z,t[66]=n,t[67]=de):de=t[67];let fe;t[68]!==F||t[69]!==G||t[70]!==de?(fe=(0,$.jsxs)(`div`,{ref:v,className:`relative h-56 flex-1`,onMouseMove:F,onMouseLeave:ae,children:[G,de]}),t[68]=F,t[69]=G,t[70]=de,t[71]=fe):fe=t[71];let q;t[72]!==ie||t[73]!==fe?(q=(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[ie,fe]}),t[72]=ie,t[73]=fe,t[74]=q):q=t[74];let J;t[75]!==V||t[76]!==p[0]?(J=p[0]===void 0?``:V(p[0]),t[75]=V,t[76]=p[0],t[77]=J):J=t[77];let Y;t[78]===J?Y=t[79]:(Y=(0,$.jsx)(`span`,{children:J}),t[78]=J,t[79]=Y);let me;t[80]!==V||t[81]!==p?(me=p[Math.floor(p.length/2)]===void 0?``:V(p[Math.floor(p.length/2)]??``),t[80]=V,t[81]=p,t[82]=me):me=t[82];let he;t[83]===me?he=t[84]:(he=(0,$.jsx)(`span`,{children:me}),t[83]=me,t[84]=he);let ge;t[85]!==V||t[86]!==p?(ge=p[p.length-1]===void 0?``:V(p[p.length-1]??``),t[85]=V,t[86]=p,t[87]=ge):ge=t[87];let _e;t[88]===ge?_e=t[89]:(_e=(0,$.jsx)(`span`,{children:ge}),t[88]=ge,t[89]=_e);let ve;t[90]!==Y||t[91]!==he||t[92]!==_e?(ve=(0,$.jsxs)(`div`,{className:`flex justify-between pl-16 text-3xs text-muted-foreground uppercase`,children:[Y,he,_e]}),t[90]=Y,t[91]=he,t[92]=_e,t[93]=ve):ve=t[93];let X;return t[94]!==q||t[95]!==ve?(X=(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[q,ve]}),t[94]=q,t[95]=ve,t[96]=X):X=t[96],X}function Mn(e){return M(`transition-opacity`,e&&`opacity-40 delay-150`)}function Nn(e){return[e.day,e]}function Pn(e){return[e.hourStart,e]}function Fn(e){let t=(0,Q.c)(30),{label:n,segments:r,format:i,aside:a}=e,o,s,c,l,u,d;if(t[0]!==a||t[1]!==i||t[2]!==n||t[3]!==r){d=Symbol.for(`react.early_return_sentinel`);bb0:{let e=r.filter(Ln),f=e.reduce(In,0);if(f<=0){d=null;break bb0}c=`flex min-w-0 flex-col gap-2.5`;let p;t[10]===n?p=t[11]:(p=(0,$.jsx)(`h3`,{className:`text-sm font-medium text-foreground`,children:n}),t[10]=n,t[11]=p),t[12]!==a||t[13]!==p?(l=(0,$.jsxs)(`div`,{className:`flex items-baseline justify-between gap-3`,children:[p,a]}),t[12]=a,t[13]=p,t[14]=l):l=t[14];let m;t[15]===i?m=t[16]:(m=e=>`${e.label} ${i(e.value)}`,t[15]=i,t[16]=m);let h;t[17]!==i||t[18]!==f?(h=e=>(0,$.jsxs)(ve,{children:[(0,$.jsx)(ge,{render:(0,$.jsx)(`div`,{className:`h-full min-w-1 rounded-xs first:rounded-l-full last:rounded-r-full`,style:{flex:`${e.value} 1 0`,backgroundColor:e.color}})}),(0,$.jsxs)(_e,{children:[e.label,` · `,i(e.value),` · `,J(e.value/f)]})]},e.label),t[17]=i,t[18]=f,t[19]=h):h=t[19],u=(0,$.jsx)(`div`,{role:`img`,"aria-label":`${n}: ${e.map(m).join(`, `)}`,className:`flex h-2 gap-0.5`,children:e.map(h)}),o=`flex flex-wrap gap-x-4 gap-y-1 text-xs`;let g;t[20]===i?g=t[21]:(g=e=>(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`span`,{"aria-hidden":!0,className:`size-2 rounded-xs`,style:{backgroundColor:e.color}}),(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:e.label}),(0,$.jsx)(`span`,{className:`text-foreground tabular-nums`,children:i(e.value)})]},e.label),t[20]=i,t[21]=g),s=e.map(g)}t[0]=a,t[1]=i,t[2]=n,t[3]=r,t[4]=o,t[5]=s,t[6]=c,t[7]=l,t[8]=u,t[9]=d}else o=t[4],s=t[5],c=t[6],l=t[7],u=t[8],d=t[9];if(d!==Symbol.for(`react.early_return_sentinel`))return d;let f;t[22]!==o||t[23]!==s?(f=(0,$.jsx)(`div`,{className:o,children:s}),t[22]=o,t[23]=s,t[24]=f):f=t[24];let p;return t[25]!==c||t[26]!==l||t[27]!==u||t[28]!==f?(p=(0,$.jsxs)(`div`,{className:c,children:[l,u,f]}),t[25]=c,t[26]=l,t[27]=u,t[28]=f,t[29]=p):p=t[29],p}function In(e,t){return e+t.value}function Ln(e){return e.value>0}function Rn(e){return e.toSorted((e,t)=>t.totalTokens-e.totalTokens||t.costUsd-e.costUsd)}function zn(e,t){return t===`tokens`?e.tokenShare:pt(e)?null:e.costShare}function Bn({tokens:e}){let t=e.uncachedInputTokens+e.cachedInputTokens+e.cacheCreationTokens;return t===0?null:e.cachedInputTokens/t}function Vn(e){let t=e.totalTokens-e.unpricedTokens;return t<=0||pt(e)?null:e.costUsd/t*1e6}var Hn=e=>`color-mix(in oklab, var(--foreground) ${e}%, var(--background))`,Un={input:Hn(60),cacheRead:Hn(30),cacheWrite:Hn(72),output:Hn(100),other:Hn(44)};function Wn(e){return[{label:`Input`,value:e.input,color:Un.input},{label:`Cache read`,value:e.cacheRead,color:Un.cacheRead},{label:`Cache write`,value:e.cacheWrite,color:Un.cacheWrite},{label:`Output`,value:e.output,color:Un.output},{label:`Other`,value:e.unsplit>=.005?e.unsplit:0,color:Un.other}]}function Gn(e){return[{label:`Input`,value:e.uncachedInputTokens,color:Un.input},{label:`Cache read`,value:e.cachedInputTokens,color:Un.cacheRead},{label:`Cache write`,value:e.cacheCreationTokens,color:Un.cacheWrite},{label:`Output`,value:e.outputTokens,color:Un.output}]}function Kn(e){return[{label:`Standard`,value:e.standard,color:Hn(34)},{label:`Fast`,value:e.fast,color:Hn(66)},{label:`Ultrafast`,value:e.ultrafast,color:Hn(100)}]}function qn(e){let t=(0,Q.c)(80),{model:n,environments:r,metric:i,chartWindow:a,onSetPrice:o,onClose:s}=e,c;t[0]!==n.model||t[1]!==n.provider?(c=e=>e.provider===n.provider&&e.model===n.model,t[0]=n.model,t[1]=n.provider,t[2]=c):c=t[2];let l;t[3]!==r||t[4]!==c?(l=wt(r,c),t[3]=r,t[4]=c,t[5]=l):l=t[5];let u=l,d;t[6]===n.provider?d=t[7]:(d=[n.provider],t[6]=n.provider,t[7]=d);let f=d,p=Ge[n.provider],m;t[8]===n?m=t[9]:(m=pt(n),t[8]=n,t[9]=m);let h=m,g;if(t[10]!==h||t[11]!==n){let e=Bn(n),r=Vn(n),i;t[13]!==h||t[14]!==n.costUsd?(i=h?`Unpriced`:W(n.costUsd),t[13]=h,t[14]=n.costUsd,t[15]=i):i=t[15];let a;t[16]===i?a=t[17]:(a={label:`Cost`,value:i},t[16]=i,t[17]=a);let o;t[18]===n.totalTokens?o=t[19]:(o=K(n.totalTokens),t[18]=n.totalTokens,t[19]=o);let s;t[20]===o?s=t[21]:(s={label:`Tokens`,value:o},t[20]=o,t[21]=s),g=[a,s,r===null?null:{label:`Per 1M tokens`,value:W(r)},e===null?null:{label:`Cache hit`,value:J(e)}].filter(Yn),t[10]=h,t[11]=n,t[12]=g}else g=t[12];let _=g,v;t[22]===s?v=t[23]:(v=e=>{e||s()},t[22]=s,t[23]=v);let y;t[24]!==p.driverKind||t[25]!==p.label?(y=(0,$.jsx)(Le,{driverKind:p.driverKind,displayName:p.label,iconClassName:`size-5`}),t[24]=p.driverKind,t[25]=p.label,t[26]=y):y=t[26];let x;t[27]===n.model?x=t[28]:(x=(0,$.jsx)(we,{children:n.model}),t[27]=n.model,t[28]=x);let S;t[29]!==y||t[30]!==x?(S=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[y,x]}),t[29]=y,t[30]=x,t[31]=S):S=t[31];let C;t[32]!==h||t[33]!==n.costShare?(C=h?``:` · ${J(n.costShare)} of cost`,t[32]=h,t[33]=n.costShare,t[34]=C):C=t[34];let w;t[35]!==p.label||t[36]!==C?(w=(0,$.jsxs)(De,{children:[p.label,C]}),t[35]=p.label,t[36]=C,t[37]=w):w=t[37];let T;t[38]!==w||t[39]!==S?(T=(0,$.jsxs)(Ce,{children:[S,w]}),t[38]=w,t[39]=S,t[40]=T):T=t[40];let E;t[41]===_?E=t[42]:(E=(0,$.jsx)(`div`,{className:`grid grid-cols-2 gap-x-6 gap-y-4 sm:grid-cols-4`,children:_.map(Jn)}),t[41]=_,t[42]=E);let D=h?`tokens`:i,O;t[43]!==a.days||t[44]!==a.hours||t[45]!==a.referenceTime||t[46]!==a.resolution||t[47]!==a.timeZone||t[48]!==f||t[49]!==D||t[50]!==u.daily||t[51]!==u.hourly?(O=(0,$.jsx)(jn,{providers:f,days:a.days,daily:u.daily,hours:a.hours,hourly:u.hourly,metric:D,referenceTime:a.referenceTime,resolution:a.resolution,timeZone:a.timeZone}),t[43]=a.days,t[44]=a.hours,t[45]=a.referenceTime,t[46]=a.resolution,t[47]=a.timeZone,t[48]=f,t[49]=D,t[50]=u.daily,t[51]=u.hourly,t[52]=O):O=t[52];let k;t[53]!==h||t[54]!==u.categoryCost?(k=h?null:(0,$.jsx)(Fn,{label:`Cost by type`,segments:Wn(u.categoryCost),format:W}),t[53]=h,t[54]=u.categoryCost,t[55]=k):k=t[55];let A;t[56]===n.tokens?A=t[57]:(A=Gn(n.tokens),t[56]=n.tokens,t[57]=A);let j;t[58]===A?j=t[59]:(j=(0,$.jsx)(Fn,{label:`Tokens by type`,segments:A,format:K}),t[58]=A,t[59]=j);let M;t[60]===u.speedCost?M=t[61]:(M=u.speedCost.fast+u.speedCost.ultrafast>0?(0,$.jsx)(Fn,{label:`Cost by speed`,segments:Kn(u.speedCost),format:W,aside:(0,$.jsx)(Xn,{premiumUsd:u.speedCost.premium})}):null,t[60]=u.speedCost,t[61]=M);let N;t[62]!==k||t[63]!==j||t[64]!==M?(N=(0,$.jsxs)(`div`,{className:`grid gap-x-10 gap-y-8 sm:grid-cols-2`,children:[k,j,M]}),t[62]=k,t[63]=j,t[64]=M,t[65]=N):N=t[65];let ee;t[66]!==E||t[67]!==O||t[68]!==N?(ee=(0,$.jsx)(Ee,{children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[E,O,N]})}),t[66]=E,t[67]=O,t[68]=N,t[69]=ee):ee=t[69];let P;t[70]!==n.unpricedTokens||t[71]!==o?(P=n.unpricedTokens>0?(0,$.jsxs)(Te,{variant:`bare`,className:`items-center sm:justify-between`,children:[(0,$.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[K(n.unpricedTokens),` tokens have no known price`]}),(0,$.jsx)(b,{onClick:o,children:`Set price`})]}):null,t[70]=n.unpricedTokens,t[71]=o,t[72]=P):P=t[72];let F;t[73]!==T||t[74]!==ee||t[75]!==P?(F=(0,$.jsxs)(Oe,{className:`max-w-3xl`,children:[T,ee,P]}),t[73]=T,t[74]=ee,t[75]=P,t[76]=F):F=t[76];let I;return t[77]!==F||t[78]!==v?(I=(0,$.jsx)(ke,{open:!0,onOpenChange:v,children:F}),t[77]=F,t[78]=v,t[79]=I):I=t[79],I}function Jn(e){return(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-0.5`,children:[(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.label}),(0,$.jsx)(`span`,{className:`text-2xl font-semibold text-foreground`,children:e.value})]},e.label)}function Yn(e){return e!==null}function Xn(e){let t=(0,Q.c)(4),{premiumUsd:n}=e,r;t[0]===n?r=t[1]:(r=W(n),t[0]=n,t[1]=r);let i;return t[2]===r?i=t[3]:(i=(0,$.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`Premium `,(0,$.jsx)(`span`,{className:`text-foreground tabular-nums`,children:r})]}),t[2]=r,t[3]=i),i}var Zn=`p4code:usage-page-preferences:v1`,Qn=T({metric:p([`cost`,`tokens`,`limits`]),windowDays:p([1,7,30,90]),hiddenProviders:u(s(k))}),$n={metric:`limits`,windowDays:30};function er(){try{return w(Zn,Qn)??$n}catch(e){return console.error(`Could not read Usage page preferences.`,e),$n}}function tr(e){try{C(Zn,e,Qn)}catch(e){console.error(`Could not save Usage page preferences.`,e)}}function nr(e){return He.some(t=>t.value===e)}function rr(e){return Be.some(t=>t.days===e)}var ir=e=>Ge[e].label;function ar(){let[e,t]=(0,Z.useState)(er);ie();let n=P(se),r=e=>{let t=Me(n,e.command,{context:{usagePageOpen:!0}});return t?`${e.label} (${t})`:e.label},[i,a]=(0,Z.useState)(()=>({days:e.windowDays,window:G(e.windowDays,void 0,e.windowDays===1?`hour`:`day`)})),o=e.metric,s=o===`limits`,[c,l]=(0,Z.useState)(!1),[u,d]=(0,Z.useState)(()=>Date.now()),f=(0,Z.useRef)(!1),[p,m]=(0,Z.useState)(`model`),[h,g]=(0,Z.useState)(null),[_,v]=(0,Z.useState)(null),[y,S]=(0,Z.useState)(null),C=(0,Z.useMemo)(()=>new Set(e.hiddenProviders),[e.hiddenProviders]),{days:w,window:T}=i,E=w===1,{merged:O,environments:k,selectedEnvironments:A,shown:j,isPartial:N,refresh:ee}=Dt(T,y,C),F=j?.merged??O,I=j?.window??T,L=I.resolution===`hour`,R=c&&!s,z=j!==null&&j.window!==T,H=(0,Z.useMemo)(()=>{if(z)return{partial:!0,everyProvider:!0,providers:new Set};let e=ft(A,R),t=new Set([...e.providers].filter(e=>!C.has(e)));return{partial:e.everyProvider||t.size>0,everyProvider:e.everyProvider,providers:t}},[z,R,A,C]),U=e=>H.everyProvider||H.providers.has(e),ue=P(ae.presentationsAtom),me=(0,Z.useMemo)(()=>new Map([...ue].filter(([,e])=>e.entry.enabled&&e.entry.unsupportedReason===void 0)),[ue]),ge=C.has(`cursor`)?[]:at(A),_e=[...new Set(A.flatMap(e=>e.summary?.sources.flatMap(e=>e.message&&!e.action&&!C.has(e.fingerprint.provider)&&(e.status===`partial`||e.status===`failed`||e.fingerprint.provider===`cursor`)?[e.message]:[])??[]))],ve=ce(oe.refreshProviders,{reportFailure:!1}),X=A.some(e=>e.canReadDiagnostics),xe=(0,Z.useMemo)(()=>Y(I.sinceDay,I.untilDay),[I.sinceDay,I.untilDay]),Ce=(0,Z.useMemo)(()=>I.sinceTime===void 0||I.untilTime===void 0?[]:fe(I.sinceTime,I.untilTime),[I.sinceTime,I.untilTime]),we=(0,Z.useMemo)(()=>(L?F.hourly:F.daily).toReversed(),[L,F.daily,F.hourly]),Te=(0,Z.useMemo)(()=>p===`model`&&o===`tokens`?Rn(F.models):F.models,[p,F.models,o]),Ee=(0,Z.useMemo)(()=>We(F.providers),[F.providers]),De=(0,Z.useMemo)(()=>Ye.filter(e=>Ee.includes(e)||H.providers.has(e)),[H.providers,Ee]),Oe=(0,Z.useMemo)(()=>new Set(De.filter(e=>H.everyProvider||H.providers.has(e))),[De,H.everyProvider,H.providers]),ke=_===null?void 0:F.models.find(e=>`${e.provider}:${e.model}`===_),je=Te.reduce((e,t)=>Math.max(e,o===`tokens`?t.totalTokens:t.costUsd),0),Le=De.map(e=>({kind:`usage`,provider:e})),qe=Math.max(De.indexOf(`codex`),De.indexOf(`claude`))+1;Le.splice(qe,0,...ge.map(e=>({kind:`enable`,environment:e})));let Qe=`${60/(De.length+2)}%`,nt=n=>{let r={...e,...n};t(r),tr(r)},Q=e=>{rr(e)&&(nt({windowDays:e}),a({days:e,window:G(e,void 0,e===1?`hour`:`day`)}))},rt=e=>{e===`limits`&&d(Date.now()),nt({metric:e})},it=async(e=!1,t=!1)=>{try{await Promise.all(Array.from(me,([n,r])=>{if((y===null||y.has(n))&&r.connection.phase===`connected`&&r.serverConfig!==null)return ct(n,()=>ve({environmentId:n,input:{}}),e,t)}))}finally{d(Date.now())}},ot=(0,Z.useEffectEvent)(e=>{if(e.defaultPrevented||e.repeat||e.isComposing||Ke()||Je())return;let t=Ve(e,n),r=He.find(e=>e.command===t),i=Be.find(e=>e.command===t);(r||i)&&(e.preventDefault(),e.stopPropagation(),r&&rt(r.value),i&&!s&&Q(i.days))});(0,Z.useEffect)(()=>(globalThis.window.addEventListener(`keydown`,ot,!0),()=>globalThis.window.removeEventListener(`keydown`,ot,!0)),[]);let st=()=>{if(f.current)return;if(s){f.current=!0,l(!0),it().finally(()=>{f.current=!1,l(!1)});return}let e=G(w,void 0,E?`hour`:`day`);(e.sinceDay!==T.sinceDay||e.untilDay!==T.untilDay||e.sinceTime!==T.sinceTime||e.untilTime!==T.untilTime)&&a({days:w,window:e}),f.current=!0,l(!0),ee(e).finally(()=>{f.current=!1,l(!1)})},lt=[...me].filter(([e,t])=>t.connection.phase===`connected`&&t.serverConfig!==null&&(y===null||y.has(e))).map(([e])=>e).sort().join(`,`),ut=(0,Z.useEffectEvent)(()=>{it(!0)});(0,Z.useEffect)(()=>{s&&lt&&ut()},[s,lt]);let dt=L&&I.sinceTime!==void 0&&I.untilTime!==void 0?`${de(I.sinceTime,I.timeZone)} to ${de(I.untilTime,I.timeZone)}`:`${le(I.sinceDay)} to ${le(I.untilDay)}`,mt=(0,$.jsxs)(`div`,{className:`grid w-full min-w-0 grid-cols-[minmax(0,1fr)_auto] items-center gap-x-3 py-2 xl:flex`,children:[(0,$.jsxs)(tt,{ariaLabel:`Usage breadcrumb`,className:`min-w-0`,children:[(0,$.jsx)($e,{children:(0,$.jsx)(`h1`,{children:`Usage`})}),(0,$.jsx)(et,{}),(0,$.jsx)($e,{className:`min-w-10 shrink`,children:(0,$.jsx)(vr,{environments:k,selectedEnvironments:A,selectedEnvironmentIds:y,onSelectionChange:S,showUsageStatus:!s,refreshing:R,isPartial:N,duplicateSources:F.duplicateSources,contractMismatches:F.contractMismatches,onOpenModelPrices:()=>g({})})}),(0,$.jsx)(et,{}),(0,$.jsx)($e,{current:!0,className:`min-w-10`,children:(0,$.jsx)(xr,{hiddenProviders:C,onChange:e=>nt({hiddenProviders:e})})})]}),s?null:(0,$.jsx)(`span`,{className:`hidden min-w-0 truncate text-xs text-muted-foreground 2xl:block`,children:dt}),(0,$.jsxs)(`div`,{className:`ms-auto hidden min-w-0 items-center justify-end gap-2 xl:flex`,children:[(0,$.jsx)(ye,{"aria-label":`Usage metric`,variant:`segmented`,value:[o],onValueChange:e=>{let t=e[0];nr(t)&&rt(t)},children:He.map(e=>(0,$.jsx)(be,{value:e.value,title:r(e),children:e.label},e.value))}),(0,$.jsx)(ye,{"aria-label":`Usage period`,variant:`segmented`,value:[String(w)],disabled:s,onValueChange:e=>{let t=e[0];t&&Q(Number(t))},children:Be.map(e=>(0,$.jsx)(be,{value:String(e.days),title:r(e),children:e.label},e.days))}),(0,$.jsx)(b,{onClick:st,"aria-label":s?`Refresh limits`:`Refresh usage`,"aria-busy":c,disabled:c||!s&&!X,size:`icon-sm`,variant:`ghost`,children:(0,$.jsx)(Xe,{size:`sm`,refreshing:c})})]}),(0,$.jsxs)(`div`,{className:`ms-auto flex min-w-0 items-center justify-end gap-1 xl:hidden`,children:[(0,$.jsxs)(re,{value:o,onValueChange:e=>{nr(e)&&rt(e)},children:[(0,$.jsx)(ne,{"aria-label":`Usage metric`,size:`compact`,variant:`ghost`,className:`w-auto min-w-0`,children:(0,$.jsx)(V,{children:He.find(e=>e.value===o)?.label})}),(0,$.jsx)(te,{align:`end`,alignItemWithTrigger:!1,children:He.map(e=>(0,$.jsx)(B,{value:e.value,title:r(e),children:e.label},e.value))})]}),(0,$.jsxs)(re,{value:String(w),disabled:s,onValueChange:e=>Q(Number(e)),children:[(0,$.jsx)(ne,{"aria-label":`Usage period`,size:`compact`,variant:`ghost`,className:`w-auto min-w-0`,children:(0,$.jsx)(V,{children:Be.find(e=>e.days===w)?.label})}),(0,$.jsx)(te,{align:`end`,alignItemWithTrigger:!1,children:Be.map(e=>(0,$.jsx)(B,{value:String(e.days),title:r(e),children:e.label},e.days))})]}),(0,$.jsx)(b,{onClick:st,"aria-label":s?`Refresh limits`:`Refresh usage`,"aria-busy":c,disabled:c||!s&&!X,size:`icon-sm`,variant:`ghost`,children:(0,$.jsx)(Xe,{size:`sm`,refreshing:c})})]})]});return(0,$.jsxs)(Ae,{className:`h-dvh min-h-0 overflow-hidden overscroll-y-none isolate`,children:[(0,$.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col bg-background text-foreground`,children:[(0,$.jsx)(Ze,{electron:he,children:mt}),(0,$.jsx)(Se,{className:`min-h-0 flex-1`,children:(0,$.jsx)(ze,{width:`wide`,children:A.length===0?(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:k.length===0?`Connect an environment to see ${s?`limits`:`usage`}.`:`Select an environment to see ${s?`limits`:`usage`}.`}):s?(0,$.jsx)(Ue,{selectedEnvironmentIds:y,hiddenProviders:C,now:u,cursorPrompt:ge.length>0?(0,$.jsx)(lr,{environments:ge,onEnabled:()=>{ee(),it(!1,!0)}}):null}):j===null?(0,$.jsx)(Sr,{}):X?(0,$.jsxs)(`div`,{"aria-busy":H.partial,className:`flex flex-col gap-6`,children:[_e.map(e=>(0,$.jsx)(`p`,{className:`mb-4 text-sm text-muted-foreground`,children:e},e)),(0,$.jsxs)(`section`,{className:`grid gap-6 lg:grid-cols-[minmax(0,18rem)_minmax(0,1fr)]`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-5`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`span`,{className:M(`text-4xl font-semibold text-foreground tabular-nums`,dr(H.partial)),children:o===`cost`?W(F.costUsd):K(F.totalTokens)}),(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-xs text-muted-foreground`,children:[(0,$.jsxs)(`span`,{children:[(0,$.jsxs)(`span`,{className:dr(H.partial),children:[q(F.sessions),` sessions`]}),o===`cost`&&` · API estimate`]}),o===`cost`&&F.costQuality.unpricedShare>0&&(0,$.jsxs)(Fe,{children:[(0,$.jsx)(Pe,{openOnHover:!0,render:(0,$.jsx)(x,{tone:`muted`}),"aria-label":`Unpriced usage details`,children:(0,$.jsx)(D,{className:`size-3`,"aria-hidden":!0})}),(0,$.jsxs)(Ne,{side:`top`,tooltipStyle:!0,children:[`API estimate excludes`,` `,J(F.costQuality.unpricedShare),` unpriced records.`]})]})]})]}),!C.has(`codex`)&&[...me].some(([e,t])=>(y===null||y.has(e))&&t.serverConfig?.providers.some(Ie))?(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 text-xs text-muted-foreground`,children:[(0,$.jsx)(`span`,{children:`ChatGPT shared usage`}),(0,$.jsx)(Re,{size:`xs`})]}):null,Le.map(e=>{if(e.kind===`enable`)return(0,$.jsx)(cr,{environmentId:e.environment.environmentId,label:e.environment.label,showEnvironment:A.length>1,onEnabled:()=>{ee(),it(!1,!0)}},`enable:${e.environment.environmentId}`);let t=e.provider,n=F.providers.find(e=>e.provider===t),r=o===`cost`?n?.costShare??0:n?.tokenShare??0,i=n?.sessions??0,a=`${q(i)} ${i===1?`session`:`sessions`}`,s=U(t),c=s&&!Ee.includes(t);return(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsxs)(`div`,{className:`flex items-baseline justify-between gap-4`,children:[(0,$.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2 text-sm text-foreground`,children:[(0,$.jsx)(`span`,{"aria-hidden":!0,className:`size-2 shrink-0 rounded-full`,style:{backgroundColor:Ge[t].color}}),(0,$.jsx)(ur,{provider:t,className:`size-4`}),(0,$.jsxs)(`span`,{className:`flex min-w-0 items-baseline gap-1.5`,children:[(0,$.jsx)(`span`,{className:`truncate`,children:Ge[t].label}),(0,$.jsx)(`span`,{className:M(`shrink-0 whitespace-nowrap text-2xs text-muted-foreground tabular-nums`,dr(s),c&&`invisible`),children:a})]})]}),(0,$.jsx)(`span`,{className:M(`shrink-0 text-sm font-medium text-foreground tabular-nums`,dr(s)),children:c?`—`:o===`cost`?W(n?.costUsd??0):K(n?.totalTokens??0)})]}),(0,$.jsx)(`span`,{className:M(`text-xs text-muted-foreground`,dr(s),c&&`invisible`),children:o===`cost`?`${J(r)} of cost · ${K(n?.totalTokens??0)} tokens`:`${J(r)} of tokens · ${W(n?.costUsd??0)}`})]},t)})]}),(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3`,children:[(0,$.jsxs)(`h2`,{className:`text-sm font-medium text-foreground`,children:[L?`Hourly`:`Daily`,` `,o===`tokens`?`processed tokens`:`cost`]}),(0,$.jsx)(jn,{providers:De,loadingProviders:Oe,days:xe,daily:F.daily,hours:Ce,hourly:F.hourly,metric:o,referenceTime:I.untilTime,resolution:L?`hour`:`day`,timeZone:I.timeZone})]})]}),(0,$.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,$.jsx)(`h2`,{className:`text-sm font-medium text-foreground`,children:`Totals`}),(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-6 gap-y-4 py-1 md:grid-cols-5`,children:[(0,$.jsx)(fr,{loading:H.partial,label:`Processed tokens`,value:K(F.totalTokens)}),(0,$.jsx)(fr,{loading:H.partial,label:`Cached input`,value:K(F.cachedInputTokens)}),(0,$.jsx)(fr,{loading:H.partial,label:`Uncached input`,value:K(F.uncachedInputTokens)}),(0,$.jsx)(fr,{loading:H.partial,label:`Output`,value:K(F.outputTokens)}),(0,$.jsx)(fr,{loading:H.partial,label:`Cache savings`,value:W(F.costQuality.cacheSavingsUsd)})]})]}),F.totalTokens>0?(0,$.jsx)(`section`,{className:M(`grid gap-x-12 gap-y-8 lg:grid-cols-2`,dr(H.partial)),children:o===`tokens`?(0,$.jsx)(Fn,{label:`Tokens by type`,segments:Gn(F),format:K}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Fn,{label:`Cost by type`,segments:Wn(F.categoryCost),format:W}),F.speedCost.fast+F.speedCost.ultrafast>0?(0,$.jsx)(Fn,{label:`Cost by speed`,segments:Kn(F.speedCost),format:W,aside:(0,$.jsx)(Xn,{premiumUsd:F.speedCost.premium})}):null]})}):null,(0,$.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsx)(`h2`,{className:`text-sm font-medium text-foreground`,children:`Breakdown`}),(0,$.jsx)(ye,{"aria-label":`Usage breakdown`,variant:`segmented`,value:[p],onValueChange:e=>{let t=e[0];(t===`model`||t===`time`)&&m(t)},children:[{value:`model`,label:`Model`},{value:`time`,label:L?`Hour`:`Day`}].map(e=>(0,$.jsx)(be,{value:e.value,children:e.label},e.value))})]}),p===`model`?(0,$.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{className:`border-b border-border text-right text-xs text-muted-foreground`,children:[(0,$.jsx)(`th`,{className:`py-2 pr-3 text-left font-normal`,children:`#`}),(0,$.jsx)(`th`,{className:`w-full py-2 text-left font-normal`,children:`Model`}),(0,$.jsx)(`th`,{className:`py-2 pl-6 font-normal`,children:`Cost`}),(0,$.jsx)(`th`,{className:`hidden py-2 pl-6 font-normal sm:table-cell`,children:`Share`}),(0,$.jsx)(`th`,{className:`py-2 pl-6 font-normal`,children:`Tokens`})]})}),(0,$.jsx)(`tbody`,{children:Te.length===0?(0,$.jsx)(`tr`,{children:(0,$.jsx)(`td`,{colSpan:5,className:`py-6 text-center text-muted-foreground`,children:`No activity in this window.`})}):Te.map((e,t)=>{let n=`${e.provider}:${e.model}`,r=o===`tokens`?e.totalTokens:e.costUsd,i=zn(e,o===`tokens`?`tokens`:`cost`),a=dr(U(e.provider));return(0,$.jsxs)(`tr`,{className:`relative border-b border-border/50 text-right whitespace-nowrap text-muted-foreground tabular-nums transition-colors hover:bg-muted/50 has-focus-visible:bg-muted/50`,children:[(0,$.jsx)(`td`,{className:`py-2.5 pr-3 text-left text-xs`,children:t+1}),(0,$.jsxs)(`td`,{className:`py-2.5 text-left whitespace-normal`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>v(n),className:`flex items-center gap-2 text-left text-foreground outline-none after:absolute after:inset-0`,children:[(0,$.jsx)(ur,{provider:e.provider,className:`size-3.5`}),e.model]}),(0,$.jsx)(`div`,{"aria-hidden":!0,className:M(`mt-1.5 h-0.5 max-w-48`,a),children:(0,$.jsx)(`div`,{className:`h-full rounded-full`,style:{width:r>0&&je>0?`max(0.5rem, ${r/je*100}%)`:0,backgroundColor:Ge[e.provider].color}})})]}),(0,$.jsx)(`td`,{className:M(`py-2.5 pl-6 text-foreground`,a),children:pt(e)?(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:`Unpriced`}):W(e.costUsd)}),(0,$.jsx)(`td`,{className:M(`hidden py-2.5 pl-6 sm:table-cell`,a),children:i===null?``:J(i)}),(0,$.jsx)(`td`,{className:M(`py-2.5 pl-6`,a),children:K(e.totalTokens)})]},n)})})]}):(0,$.jsxs)(`table`,{className:`w-full table-fixed text-sm`,children:[(0,$.jsxs)(`colgroup`,{children:[(0,$.jsx)(`col`,{className:`w-2/5`}),De.map(e=>(0,$.jsx)(`col`,{style:{width:Qe}},e)),(0,$.jsx)(`col`,{style:{width:Qe}}),(0,$.jsx)(`col`,{style:{width:Qe}})]}),(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{className:`border-b border-border text-left text-xs text-muted-foreground`,children:[(0,$.jsx)(`th`,{className:`py-2 font-normal`,children:L?`Hour`:`Day`}),De.map(e=>(0,$.jsx)(`th`,{className:`py-2 text-right font-normal`,children:Ge[e].label},e)),(0,$.jsx)(`th`,{className:`py-2 text-right font-normal`,children:`Total`}),(0,$.jsx)(`th`,{className:`py-2 text-right font-normal`,children:`Tokens`})]})}),(0,$.jsx)(`tbody`,{children:we.length===0?(0,$.jsx)(`tr`,{children:(0,$.jsx)(`td`,{colSpan:De.length+3,className:`py-6 text-center text-muted-foreground`,children:`No activity in this window.`})}):we.map(e=>(0,$.jsxs)(`tr`,{className:`border-b border-border/50 transition-colors hover:bg-muted/50`,children:[(0,$.jsx)(`td`,{className:`py-2 text-foreground`,children:`hourStart`in e?pe(e.hourStart,I.timeZone):le(e.day)}),De.map(t=>(0,$.jsx)(`td`,{className:M(`py-2 text-right text-muted-foreground tabular-nums`,dr(U(t))),children:W(e.byProvider.get(t)?.costUsd??0)},t)),(0,$.jsx)(`td`,{className:M(`py-2 text-right text-foreground tabular-nums`,dr(H.partial)),children:W(e.costUsd)}),(0,$.jsx)(`td`,{className:M(`py-2 text-right text-muted-foreground tabular-nums`,dr(H.partial)),children:K(e.totalTokens)})]},`hourStart`in e?e.hourStart:e.day))})]})]})]}):(0,$.jsx)(`div`,{className:`space-y-2 py-12 text-center text-sm text-muted-foreground`,children:A.map(e=>(0,$.jsxs)(`p`,{children:[A.length>1?`${e.label}: `:null,e.error]},e.environmentId))})})})]}),ke!==void 0&&!s?(0,$.jsx)(qn,{model:ke,environments:A,metric:o===`tokens`?`tokens`:`cost`,chartWindow:{days:xe,hours:Ce,resolution:L?`hour`:`day`,timeZone:I.timeZone,referenceTime:I.untilTime},onSetPrice:()=>{v(null),g({model:ke.model})},onClose:()=>v(null)}):null,h?(0,$.jsx)(Xt,{usage:k,initialSelectedEnvironmentIds:y,initialModel:h.model,onOpenChange:e=>{e||g(null)}}):null]})}var or=`Requires access to your Cursor login in macOS Keychain.`;function sr({environmentId:e,label:t,onEnabled:n,tooltip:r,buttonText:i=`Enable`}){let a=ce(oe.updateSettings,{label:`enable Cursor account usage`}),[o,s]=(0,Z.useState)(!1),c=async()=>{s(!0);try{(await a({environmentId:e,input:{patch:{cursorKeychainUsageEnabled:!0}}}))._tag===`Success`&&n()}finally{s(!1)}},l=r?(0,$.jsx)(x,{disabled:o,"aria-busy":o,"aria-label":`Enable Cursor usage from ${t}`,onClick:()=>void c(),children:i}):(0,$.jsx)(b,{size:`sm`,variant:`outline`,disabled:o,"aria-busy":o,"aria-label":`Enable Cursor usage from ${t}`,onClick:()=>void c(),children:i});return r?(0,$.jsxs)(ve,{children:[(0,$.jsx)(ge,{render:l}),(0,$.jsx)(_e,{children:or})]}):l}function cr(e){let t=(0,Q.c)(11),{environmentId:n,label:r,showEnvironment:i,onEnabled:a}=e,o,s;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,$.jsx)(`span`,{"aria-hidden":!0,className:`size-2 shrink-0 rounded-full`,style:{backgroundColor:Ge.cursor.color}}),s=(0,$.jsx)(ur,{provider:`cursor`,className:`size-4`}),t[0]=o,t[1]=s):(o=t[0],s=t[1]);let c=i?` · ${r}`:``,l;t[2]===c?l=t[3]:(l=(0,$.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2 text-sm text-foreground`,children:[o,s,(0,$.jsxs)(`span`,{className:`truncate`,children:[`Cursor`,c]})]}),t[2]=c,t[3]=l);let u;t[4]!==n||t[5]!==r||t[6]!==a?(u=(0,$.jsx)(sr,{environmentId:n,label:r,onEnabled:a,tooltip:!0}),t[4]=n,t[5]=r,t[6]=a,t[7]=u):u=t[7];let d;return t[8]!==l||t[9]!==u?(d=(0,$.jsxs)(`div`,{className:`flex min-w-0 items-baseline justify-between gap-4 text-sm`,children:[l,u]}),t[8]=l,t[9]=u,t[10]=d):d=t[10],d}function lr(e){let t=(0,Q.c)(10),{environments:n,onEnabled:r}=e,i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,$.jsxs)(`h2`,{className:`flex items-center gap-2 text-sm font-medium text-foreground`,children:[(0,$.jsx)(Le,{driverKind:l.make(`cursor`),displayName:`Cursor`,indicatorBackground:`var(--background)`,className:`size-5`,iconClassName:`size-4 text-foreground/80`}),`Cursor`]}),t[0]=i):i=t[0];let a;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:or}),t[1]=a):a=t[1];let o;if(t[2]!==n||t[3]!==r){let e;t[5]!==n.length||t[6]!==r?(e=e=>(0,$.jsx)(sr,{environmentId:e.environmentId,label:e.label,buttonText:n.length>1?`Enable on ${e.label}`:`Enable`,onEnabled:r,tooltip:!1},e.environmentId),t[5]=n.length,t[6]=r,t[7]=e):e=t[7],o=n.map(e),t[2]=n,t[3]=r,t[4]=o}else o=t[4];let s;return t[8]===o?s=t[9]:(s=(0,$.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[i,(0,$.jsxs)(`div`,{className:`flex flex-col items-start gap-3 rounded-lg border border-border/60 p-4`,children:[a,(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:o})]})]}),t[8]=o,t[9]=s),s}function ur(e){let t=(0,Q.c)(4),{provider:n,className:r}=e,i=Ge[n],a;return t[0]!==r||t[1]!==i.driverKind||t[2]!==i.label?(a=(0,$.jsx)(Le,{driverKind:i.driverKind,displayName:i.label,iconClassName:r}),t[0]=r,t[1]=i.driverKind,t[2]=i.label,t[3]=a):a=t[3],a}function dr(e){return M(`transition-opacity`,e&&`opacity-40 delay-150`)}function fr(e){let t=(0,Q.c)(10),{label:n,value:r,loading:i}=e,a;t[0]===n?a=t[1]:(a=(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:n}),t[0]=n,t[1]=a);let o;t[2]===i?o=t[3]:(o=M(`text-base font-medium text-foreground tabular-nums`,dr(i)),t[2]=i,t[3]=o);let s;t[4]!==o||t[5]!==r?(s=(0,$.jsx)(`span`,{className:o,children:r}),t[4]=o,t[5]=r,t[6]=s):s=t[6];let c;return t[7]!==a||t[8]!==s?(c=(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-0.5`,children:[a,s]}),t[7]=a,t[8]=s,t[9]=c):c=t[9],c}function pr(e){let t=(0,Q.c)(14),{environments:n,duplicateSources:r,contractMismatches:i}=e,a,o,s,c;if(t[0]!==i||t[1]!==r||t[2]!==n){c=Symbol.for(`react.early_return_sentinel`);bb0:{let e=n.filter(_r),t=new Map(i.map(gr)),l=n.flatMap(e=>{let n=t.get(e.environmentId);return n===void 0?[]:[{environment:e,mismatch:n}]});if(e.length===0&&l.length===0&&r.length===0){c=null;break bb0}a=`flex flex-col gap-1 border-t border-border px-2 py-2 text-xs text-muted-foreground`,o=e.map(hr),s=l.map(mr)}t[0]=i,t[1]=r,t[2]=n,t[3]=a,t[4]=o,t[5]=s,t[6]=c}else a=t[3],o=t[4],s=t[5],c=t[6];if(c!==Symbol.for(`react.early_return_sentinel`))return c;let l;t[7]===r?l=t[8]:(l=r.length>0?(0,$.jsxs)(`span`,{children:[`Counted once across environments sharing a transcript directory:`,` `,r.join(`, `)]}):null,t[7]=r,t[8]=l);let u;return t[9]!==a||t[10]!==o||t[11]!==s||t[12]!==l?(u=(0,$.jsxs)(`div`,{className:a,children:[o,s,l]}),t[9]=a,t[10]=o,t[11]=s,t[12]=l,t[13]=u):u=t[13],u}function mr(e){let{environment:t,mismatch:n}=e;return(0,$.jsx)(`span`,{children:me(t.label,n)},t.environmentId)}function hr(e){return(0,$.jsxs)(`span`,{children:[e.label,`: `,e.error]},e.label)}function gr(e){return[e.environmentId,e]}function _r(e){return e.error!==null}function vr(e){let t=(0,Q.c)(56),{environments:n,selectedEnvironments:r,selectedEnvironmentIds:o,onSelectionChange:s,showUsageStatus:l,refreshing:u,isPartial:d,duplicateSources:p,contractMismatches:h,onOpenModelPrices:g}=e,y=o===null,b=y?`All environments`:r.length===1?r[0].label:`${r.length} environments`,S;t[0]!==h||t[1]!==r?(S=r.some(br)||h.length>0,t[0]=h,t[1]=r,t[2]=S):S=t[2];let C=S,w;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(w=(0,$.jsx)(x,{}),t[3]=w):w=t[3];let T;t[4]===b?T=t[5]:(T=(0,$.jsx)(Qe,{children:b}),t[4]=b,t[5]=T);let E;t[6]!==C||t[7]!==l?(E=(0,$.jsx)(`span`,{className:`flex size-3.5 shrink-0 items-center justify-center text-muted-foreground`,children:l&&C?(0,$.jsx)(c,{className:`size-3.5 text-warning-foreground`,"aria-label":`Some environments could not report usage`}):(0,$.jsx)(a,{className:`size-3.5 opacity-0 transition-opacity group-hover/usage-environment:opacity-100 group-focus-visible/usage-environment:opacity-100 group-data-popup-open/usage-environment:opacity-100`,"aria-hidden":!0})}),t[6]=C,t[7]=l,t[8]=E):E=t[8];let D;t[9]!==T||t[10]!==E?(D=(0,$.jsxs)(F,{render:w,className:`group/usage-environment min-w-0 max-w-full`,children:[T,E]}),t[9]=T,t[10]=E,t[11]=D):D=t[11];let O;t[12]===s?O=t[13]:(O=e=>s(e?null:new Set),t[12]=s,t[13]=O);let k;t[14]!==y||t[15]!==O?(k=(0,$.jsx)(f,{checked:y,closeOnClick:!1,onCheckedChange:O,children:`All environments`}),t[14]=y,t[15]=O,t[16]=k):k=t[16];let A;t[17]===Symbol.for(`react.memo_cache_sentinel`)?(A=(0,$.jsx)(v,{}),t[17]=A):A=t[17];let j;if(t[18]!==n||t[19]!==s||t[20]!==u||t[21]!==o||t[22]!==r||t[23]!==l){let e;t[25]!==n.length||t[26]!==s||t[27]!==u||t[28]!==o||t[29]!==r||t[30]!==l?(e=e=>{let t=o===null||o.has(e.environmentId),i=ut(e,u),a=e.error===null?e.summary!==null&&!bt(e.summary.contractVersion,6)?`Update required`:e.isConnected?i.phase===`loading`?`Scanning…`:i.phase===`stale`?`Refreshing…`:i.phase===`partway`?dt(i.providers,ir):`Ready`:`Connecting…`:`Unavailable`;return(0,$.jsx)(f,{checked:t,closeOnClick:!1,onCheckedChange:t=>{let i=new Set(r.map(yr));t?i.add(e.environmentId):i.delete(e.environmentId),s(i.size===n.length?null:i)},children:(0,$.jsxs)(`span`,{className:`flex min-w-0 items-center gap-3`,children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.label}),l?(0,$.jsx)(`span`,{className:M(`shrink-0 text-xs text-muted-foreground`,e.error!==null&&`text-destructive`),children:a}):null]})},e.environmentId)},t[25]=n.length,t[26]=s,t[27]=u,t[28]=o,t[29]=r,t[30]=l,t[31]=e):e=t[31],j=n.map(e),t[18]=n,t[19]=s,t[20]=u,t[21]=o,t[22]=r,t[23]=l,t[24]=j}else j=t[24];let N;t[32]===n.length?N=t[33]:(N=n.length===0?(0,$.jsx)(`p`,{className:`px-2 py-2 text-xs text-muted-foreground`,children:`No environments connected.`}):null,t[32]=n.length,t[33]=N);let P;t[34]!==d||t[35]!==l?(P=l&&d?(0,$.jsx)(`p`,{className:`px-2 py-2 text-xs text-muted-foreground`,children:`Totals are partial while selected environments scan.`}):null,t[34]=d,t[35]=l,t[36]=P):P=t[36];let I;t[37]!==h||t[38]!==p||t[39]!==r||t[40]!==l?(I=l?(0,$.jsx)(pr,{environments:r,duplicateSources:p,contractMismatches:h}):null,t[37]=h,t[38]=p,t[39]=r,t[40]=l,t[41]=I):I=t[41];let L;t[42]===Symbol.for(`react.memo_cache_sentinel`)?(L=(0,$.jsx)(v,{}),t[42]=L):L=t[42];let R;t[43]===Symbol.for(`react.memo_cache_sentinel`)?(R=(0,$.jsx)(_,{"aria-hidden":!0}),t[43]=R):R=t[43];let z;t[44]===g?z=t[45]:(z=(0,$.jsxs)(i,{onClick:g,children:[R,`Model prices`]}),t[44]=g,t[45]=z);let B;t[46]!==N||t[47]!==P||t[48]!==I||t[49]!==z||t[50]!==k||t[51]!==j?(B=(0,$.jsxs)(ee,{align:`start`,children:[k,A,j,N,P,I,L,z]}),t[46]=N,t[47]=P,t[48]=I,t[49]=z,t[50]=k,t[51]=j,t[52]=B):B=t[52];let V;return t[53]!==B||t[54]!==D?(V=(0,$.jsxs)(m,{children:[D,B]}),t[53]=B,t[54]=D,t[55]=V):V=t[55],V}function yr(e){return e.environmentId}function br(e){return e.error!==null}function xr(e){let t=(0,Q.c)(23),{hiddenProviders:n,onChange:r}=e,i;t[0]===n?i=t[1]:(i=Ye.filter(e=>!n.has(e)),t[0]=n,t[1]=i);let o=i,s=o.length===Ye.length?`All providers`:o.length===0?`No providers`:o.length===1?Ge[o[0]].label:`${o.length} providers`,c;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,$.jsx)(x,{}),t[2]=c):c=t[2];let l;t[3]===s?l=t[4]:(l=(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:s}),t[3]=s,t[4]=l);let u;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,$.jsx)(a,{className:`size-3.5 shrink-0 text-muted-foreground opacity-0 transition-opacity group-hover/usage-provider:opacity-100 group-focus-visible/usage-provider:opacity-100 group-data-popup-open/usage-provider:opacity-100`,"aria-hidden":!0}),t[5]=u):u=t[5];let d;t[6]===l?d=t[7]:(d=(0,$.jsxs)(F,{render:c,className:`group/usage-provider min-w-0 max-w-full`,children:[l,u]}),t[6]=l,t[7]=d);let p=n.size===0,h;t[8]===r?h=t[9]:(h=e=>r(e?[]:Ye),t[8]=r,t[9]=h);let g;t[10]!==p||t[11]!==h?(g=(0,$.jsx)(f,{checked:p,closeOnClick:!1,onCheckedChange:h,children:`All providers`}),t[10]=p,t[11]=h,t[12]=g):g=t[12];let _;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,$.jsx)(v,{}),t[13]=_):_=t[13];let y;t[14]!==n||t[15]!==r?(y=Ye.map(e=>(0,$.jsx)(f,{checked:!n.has(e),closeOnClick:!1,onCheckedChange:t=>r(Ye.filter(r=>r===e?!t:n.has(r))),children:(0,$.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,$.jsx)(ur,{provider:e,className:`size-3.5`}),(0,$.jsx)(`span`,{className:`truncate`,children:Ge[e].label})]})},e)),t[14]=n,t[15]=r,t[16]=y):y=t[16];let b;t[17]!==y||t[18]!==g?(b=(0,$.jsxs)(ee,{align:`start`,children:[g,_,y]}),t[17]=y,t[18]=g,t[19]=b):b=t[19];let S;return t[20]!==b||t[21]!==d?(S=(0,$.jsxs)(m,{children:[d,b]}),t[20]=b,t[21]=d,t[22]=S):S=t[22],S}function Sr(){let e=(0,Q.c)(7),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(X,{className:`h-10 w-36`}),(0,$.jsx)(X,{className:`h-4 w-32`})]}),Ye.map(Cr)]}),e[0]=t):t=e[0];let n;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,$.jsx)(X,{className:`h-5 w-24`}),e[1]=n):n=e[1];let r;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,$.jsxs)(`section`,{className:`grid gap-6 lg:grid-cols-[minmax(0,18rem)_minmax(0,1fr)]`,children:[t,(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[n,(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(X,{className:`ml-16 h-56`}),(0,$.jsx)(X,{className:`ml-16 h-4`})]})]})]}),e[2]=r):r=e[2];let i;e[3]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,$.jsx)(`h2`,{className:`text-sm font-medium text-foreground`,children:`Totals`}),e[3]=i):i=e[3];let a;e[4]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[i,(0,$.jsx)(wr,{labels:[`Processed tokens`,`Cached input`,`Uncached input`,`Output`,`Cache savings`]})]}),e[4]=a):a=e[4];let o;e[5]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,$.jsx)(`section`,{className:`grid gap-x-12 gap-y-8 lg:grid-cols-2`,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-2.5`,children:[(0,$.jsx)(X,{className:`h-5 w-28`}),(0,$.jsx)(X,{className:`h-2`}),(0,$.jsx)(X,{className:`h-4 w-72`})]})}),e[5]=o):o=e[5];let s;return e[6]===Symbol.for(`react.memo_cache_sentinel`)?(s=(0,$.jsxs)($.Fragment,{children:[r,a,o,(0,$.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsx)(`h2`,{className:`text-sm font-medium text-foreground`,children:`Breakdown`}),(0,$.jsx)(X,{shape:`card`,className:`h-7 w-28`})]}),(0,$.jsx)(X,{className:`h-44`})]})]}),e[6]=s):s=e[6],s}function Cr(e){return(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsxs)(`div`,{className:`flex min-h-5 items-center justify-between gap-4`,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{shape:`pill`,className:`size-2 shrink-0`}),(0,$.jsx)(X,{shape:`pill`,className:`size-4 shrink-0`}),(0,$.jsx)(X,{className:`h-3.5 w-20`})]}),(0,$.jsx)(X,{className:`h-3.5 w-14`})]}),(0,$.jsx)(X,{className:`h-4 w-36`})]},e)}function wr(e){let t=(0,Q.c)(4),{labels:n}=e,r;t[0]===n?r=t[1]:(r=n.map(Tr),t[0]=n,t[1]=r);let i;return t[2]===r?i=t[3]:(i=(0,$.jsx)(`div`,{className:`grid grid-cols-2 gap-x-6 gap-y-4 py-1 md:grid-cols-5`,children:r}),t[2]=r,t[3]=i),i}function Tr(e){return(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e}),(0,$.jsx)(X,{className:`h-6 w-16`})]},e)}var Er=ar;export{Er as component};
2
- //# sourceMappingURL=usage-DATBL2Du.js.map
1
+ import{a as e,t}from"./react-DH3P2YXY.js";import{n,t as r}from"./jsx-runtime-BnjsACtP.js";import{$n as i,Ad as a,Eb as o,Hy as s,Ld as c,M_ as l,Nb as u,Os as d,Xn as f,Xy as p,Yn as m,Yp as h,Zo as g,_m as _,ar as v,as as y,dr as b,fr as x,im as S,js as C,ks as w,ob as T,ps as E,qf as D,rh as O,rl as k,rs as A,sv as j,t as M,tE as N,tr as ee,ts as P,ur as F}from"./utils-CBe1bHL7.js";import{B as I,L,W as R,q as z}from"./runtime-CABaKt1A.js";import{a as B,c as V,o as te,s as ne,t as re}from"./select-Cbpdz6n3.js";import{t as ie}from"./useNavigateBack-CwjQ4iuL.js";import{nt as ae}from"./useSettings-CHt2_4He.js";import{f as oe,s as se}from"./server-mIR8e8Vz.js";import{n as H,t as U}from"./session-BlCBDyVn.js";import{t as ce}from"./use-atom-command-C4y634Qy.js";import{a as le,c as ue,d as W,f as G,i as de,l as K,n as fe,o as pe,r as q,s as J,t as Y,u as me}from"./usageFormat-D5Mz5ugL.js";import{t as he}from"./env-wK1YYxA8.js";import{a as ge,n as _e,t as ve}from"./tooltip-ChmjT8Ns.js";import{t as X}from"./skeleton-CFtayHTe.js";import{n as ye,t as be}from"./toggle-group-yF5GZ53o.js";import{t as xe}from"./input-DXGWoa4O.js";import{t as Se}from"./scroll-area-CQNIjQ8U.js";import{a as Ce,c as we,i as Te,o as Ee,r as De,s as Oe,t as ke}from"./dialog-_vbB7RKH.js";import{o as Ae}from"./sidebar-BhJqncti.js";import{t as je}from"./observeResize-DzSkewug.js";import{y as Me}from"./keybindings-DAHl8jIl.js";import{i as Ne,o as Pe,t as Fe}from"./popover-CogH2zM4.js";import{S as Ie,n as Le,t as Re}from"./ChatGptUsageButton-DqJ-vZMe.js";import{t as ze}from"./WorkspacePageContainer-MDWEFwmu.js";import{n as Be,r as Ve,t as He}from"./usageShortcuts-mAekk3eG.js";import{Cr as Ue,Er as We,Tr as Ge,ii as Ke,sa as qe,va as Je,wr as Ye,xo as Xe}from"./main-Cywp3EWc.js";import{t as Ze}from"./WorkspacePageHeader-CNcKDaqG.js";import{i as Qe,n as $e,r as et,t as tt}from"./WorkspaceBreadcrumb-Dr-p0Dtn.js";import{t as nt}from"./usageAccess-kgUHYKOw.js";var Z=e(t(),1),Q=n(),rt=o(z);function it(e,t){return e?.sources.some(e=>e.action===`enableCursorKeychain`)===!0&&t?.some(e=>e.driver===`cursor`&&e.status===`ready`)===!0}function at(e){return e.some(e=>e.summary?.sources.some(e=>e.fingerprint.provider===`cursor`&&e.fingerprint.hostId===`cursor.com`))?[]:e.filter(e=>e.needsCursorKeychainAccess)}var ot=new Map,st=new Map;async function ct(e,t,n=!1,r=!1){let i=st.get(e);if(i!==void 0){if(r){try{await i}catch{}return ct(e,t,!1,!0)}return n?void 0:await i}let a=ot.get(e)??0;if(n&&Date.now()<a)return;let o=Promise.resolve().then(t).finally(()=>{st.delete(e),ot.set(e,Date.now()+3e5)});return st.set(e,o),await o}async function lt({registry:e,server:t,presentations:n,environmentIds:r,input:i}){await Promise.all(r.map(async r=>{let a=t.usageSummary({environmentId:r,input:i}),o=n.presentationAtom(r),s=new AbortController,c=()=>{e.get(o)?.connection.phase!==`connected`&&s.abort()},l=e.subscribe(o,c);c();try{let n=await I(e,t.refreshUsageRates,{environmentId:r,input:{}},{reportFailure:!1}),i=n._tag===`Failure`&&rt(R(n));if(e.refresh(a),i||s.signal.aborted)return;await L(e,a,{reportFailure:!1,signal:s.signal})}finally{l()}}))}function ut(e,t=!1){let{summary:n}=e;if(!e.isConnected||e.error!==null)return{phase:`inactive`};if(n===null)return{phase:`loading`};if(t)return{phase:`stale`};if(!e.isPending)return{phase:`ready`};let r=[...new Set(n.sources.flatMap(e=>e.refreshing?[e.fingerprint.provider]:[]))];return r.length>0?{phase:`partway`,providers:r}:{phase:`stale`}}function dt(e,t){return e.length===1?`Updating ${t(e[0])}…`:`Updating ${e.length} providers…`}function ft(e,t=!1){let n=new Set,r=!1;for(let i of e){let e=ut(i,t);if((e.phase===`loading`||e.phase===`stale`)&&(r=!0),e.phase===`partway`)for(let t of e.providers)n.add(t)}return{partial:r||n.size>0,everyProvider:r,providers:n}}function pt(e){return e.records>0&&e.unpricedRecords>=e.records}function mt(e){return[e.hostId,e.provider,e.resolvedHomePath,e.volumeId].join(` `)}function ht(e,t){let n=e.sources.filter(e=>e.fingerprint.provider===t.fingerprint.provider);return e.buckets.filter(e=>e.provider===t.fingerprint.provider&&(e.sourcePath===t.fingerprint.resolvedHomePath||e.sourcePath===void 0&&n.length===1))}function gt(e){return JSON.stringify([e.day,e.hourStart??null,e.provider,e.model])}function _t(e){let t=new Map,n=new Map,r=new Map,i=new Map,a=new Map,o=[],s=[...e].sort((e,t)=>(Date.parse(t.summary.readAt)||0)-(Date.parse(e.summary.readAt)||0)||e.environmentId.localeCompare(t.environmentId));for(let e of[`ok`,`partial`,`failed`])for(let r of s)for(let i of r.summary.sources){if(i.status!==e)continue;let s=mt(i.fingerprint);if(t.has(s)){o.push(`${r.label}: ${i.fingerprint.resolvedHomePath}`);continue}t.set(s,r.environmentId),n.set(s,{environment:r,source:i}),a.set(s,i.distinctSessions)}for(let e of s)for(let t of e.summary.sources){if(t.status!==`partial`)continue;let o=mt(t.fingerprint),s=n.get(o);if(s?.source.status!==`ok`||Date.parse(e.summary.readAt)<=Date.parse(s.environment.summary.readAt))continue;let c=r.get(o);c===void 0&&(c=new Set(ht(s.environment.summary,s.source).map(gt)),r.set(o,c));let l=i.get(e.environmentId)??new Set,u=!1;for(let n of ht(e.summary,t)){let e=gt(n);c.has(e)||(c.add(e),l.add(n),u=!0)}u&&(i.set(e.environmentId,l),a.set(o,Math.max(a.get(o)??0,t.distinctSessions)))}return{ownerByFingerprint:t,supplementalBucketsByEnvironment:i,sessionsByFingerprint:a,duplicates:o}}function vt(e,t,n,r){let i=new Set,a=new Set,o=new Map;for(let n of e.summary.sources){if(n.status===`missing`)continue;let s=mt(n.fingerprint);if(t.get(s)===e.environmentId){let e=n.fingerprint.provider;i.add(e),a.add(`${e}\u0000${n.fingerprint.resolvedHomePath}`),o.set(e,(o.get(e)??0)+(r.get(s)??n.distinctSessions))}}return{buckets:e.summary.buckets.filter(e=>n.has(e)||(e.sourcePath===void 0?i.has(e.provider):a.has(`${e.provider}\u0000${e.sourcePath}`))),sessionsByProvider:o}}function yt(e){return e.totals.uncachedInputTokens+e.totals.cachedInputTokens+e.totals.cacheCreationTokens+e.totals.outputTokens}function bt(e,t){return e>=4&&e<=t}var xt={costUsd:0,uncachedInputTokens:0,cachedInputTokens:0,cacheCreationTokens:0,outputTokens:0,reasoningTokens:0,totalTokens:0,records:0,sessions:0,providers:[],models:[],daily:[],hourly:[],costQuality:{providerReportedShare:0,modelPricedShare:0,unpricedShare:0,cacheSavingsUsd:0},categoryCost:{input:0,cacheRead:0,cacheWrite:0,output:0,unsplit:0},speedCost:{standard:0,fast:0,ultrafast:0,premium:0},duplicateSources:[],contributingEnvironments:[],contractMismatches:[]};function St(e,t){if(e.length===0)return xt;let n=[],r=[];for(let i of e)bt(i.summary.contractVersion,t)?n.push(i):r.push({environmentId:i.environmentId,direction:i.summary.contractVersion<t?`serverBehind`:`clientBehind`,contractVersion:i.summary.contractVersion});let{ownerByFingerprint:i,supplementalBucketsByEnvironment:a,sessionsByFingerprint:o,duplicates:s}=_t(n),c=0,l=0,u=0,d=0,f=0,p=0,m=0,h=0,g=0,_=0,v=0,y={input:0,cacheRead:0,cacheWrite:0,output:0},b={fast:0,ultrafast:0,premium:0},x=new Map,S=new Map,C=new Map,w=new Map,T=[];for(let e of n){let{buckets:t,sessionsByProvider:n}=vt(e,i,a.get(e.environmentId)??new Set,o);t.length>0&&T.push(e.environmentId);for(let[e,t]of n){if(h+=t,t===0)continue;let n=x.get(e)??{costUsd:0,totalTokens:0,records:0,sessions:0};n.sessions+=t,x.set(e,n)}for(let e of t){let t=yt(e);c+=e.costUsd,g+=e.cacheSavingsUsd,l+=e.totals.uncachedInputTokens,u+=e.totals.cachedInputTokens,d+=e.totals.cacheCreationTokens,f+=e.totals.outputTokens,p+=e.totals.reasoningTokens,m+=e.records,v+=e.unpricedRecords,e.costSource===`providerReported`&&(_+=e.records),e.categoryCostUsd!==void 0&&(y.input+=e.categoryCostUsd.input,y.cacheRead+=e.categoryCostUsd.cacheRead,y.cacheWrite+=e.categoryCostUsd.cacheWrite,y.output+=e.categoryCostUsd.output),b.fast+=e.fastCostUsd??0,b.ultrafast+=e.ultrafastCostUsd??0,b.premium+=e.speedPremiumUsd??0;let n=x.get(e.provider)??{costUsd:0,totalTokens:0,records:0,sessions:0};n.costUsd+=e.costUsd,n.totalTokens+=t,n.records+=e.records,x.set(e.provider,n);let r=`${e.provider} ${e.model}`,i=S.get(r)??{provider:e.provider,costUsd:0,totalTokens:0,tokens:{uncachedInputTokens:0,cachedInputTokens:0,cacheCreationTokens:0,outputTokens:0,reasoningTokens:0},records:0,unpricedRecords:0,unpricedTokens:0};i.costUsd+=e.costUsd,i.totalTokens+=t,i.tokens={uncachedInputTokens:i.tokens.uncachedInputTokens+e.totals.uncachedInputTokens,cachedInputTokens:i.tokens.cachedInputTokens+e.totals.cachedInputTokens,cacheCreationTokens:i.tokens.cacheCreationTokens+e.totals.cacheCreationTokens,outputTokens:i.tokens.outputTokens+e.totals.outputTokens,reasoningTokens:i.tokens.reasoningTokens+e.totals.reasoningTokens},i.records+=e.records,i.unpricedRecords+=e.unpricedRecords,e.records>0&&(i.unpricedTokens+=t*e.unpricedRecords/e.records),S.set(r,i);let a=C.get(e.day)??{costUsd:0,totalTokens:0,byProvider:new Map};a.costUsd+=e.costUsd,a.totalTokens+=t;let o=a.byProvider.get(e.provider)??{costUsd:0,totalTokens:0};if(o.costUsd+=e.costUsd,o.totalTokens+=t,a.byProvider.set(e.provider,o),C.set(e.day,a),e.hourStart!==void 0){let n=w.get(e.hourStart)??{day:e.day,hourStart:e.hourStart,costUsd:0,totalTokens:0,byProvider:new Map};n.costUsd+=e.costUsd,n.totalTokens+=t;let r=n.byProvider.get(e.provider)??{costUsd:0,totalTokens:0};r.costUsd+=e.costUsd,r.totalTokens+=t,n.byProvider.set(e.provider,r),w.set(e.hourStart,n)}}}let E=l+u+d+f,D=[...x.entries()].map(([e,t])=>({provider:e,costUsd:t.costUsd,totalTokens:t.totalTokens,records:t.records,sessions:t.sessions,costShare:c===0?0:t.costUsd/c,tokenShare:E===0?0:t.totalTokens/E})).sort((e,t)=>t.costUsd-e.costUsd),O=[...S.entries()].map(([e,t])=>({model:e.slice(e.indexOf(` `)+1),provider:t.provider,costUsd:t.costUsd,totalTokens:t.totalTokens,tokens:t.tokens,records:t.records,unpricedRecords:t.unpricedRecords,unpricedTokens:t.unpricedTokens,costShare:c===0?0:t.costUsd/c,tokenShare:E===0?0:t.totalTokens/E})).sort((e,t)=>t.costUsd-e.costUsd||t.totalTokens-e.totalTokens),k=[...C.entries()].map(([e,t])=>({day:e,costUsd:t.costUsd,totalTokens:t.totalTokens,byProvider:t.byProvider})).sort((e,t)=>e.day.localeCompare(t.day)),A=[...w.values()].sort((e,t)=>e.hourStart.localeCompare(t.hourStart));return{costUsd:c,uncachedInputTokens:l,cachedInputTokens:u,cacheCreationTokens:d,outputTokens:f,reasoningTokens:p,totalTokens:E,records:m,sessions:h,providers:D,models:O,daily:k,hourly:A,costQuality:{providerReportedShare:m===0?0:_/m,unpricedShare:m===0?0:v/m,modelPricedShare:m===0?0:(m-_-v)/m,cacheSavingsUsd:g},categoryCost:{...y,unsplit:Math.max(0,c-y.input-y.cacheRead-y.cacheWrite-y.output)},speedCost:{...b,standard:Math.max(0,c-b.fast-b.ultrafast)},duplicateSources:s,contributingEnvironments:T,contractMismatches:r}}var Ct=A(e=>y(t=>{let n=JSON.parse(e),r=t(ae.presentationsAtom),i=[];for(let[e,a]of r){let r=a.connection.phase===`connected`,o=t(U.sessionStateAtom(e)),s=nt({connectionPhase:a.connection.phase,session:N(d(o)),hasSessionError:o._tag===`Failure`});if(!s.canReadDiagnostics){i.push({environmentId:e,label:a.entry.target.label,isConnected:r,...s,summary:null,needsCursorKeychainAccess:!1});continue}let c=t(oe.usageSummary({environmentId:e,input:n})),l=N(d(c));i.push({environmentId:e,label:a.entry.target.label,isPending:c.waiting,canReadDiagnostics:!0,isConnected:r,error:c._tag===`Failure`?`This environment could not report usage.`:null,summary:l,needsCursorKeychainAccess:it(l,t(oe.providersValueAtom(e)))})}return i}).pipe(E(`web-usage:window:${e}`)));function wt(e,t){return St(e.flatMap(({environmentId:e,label:n,summary:r})=>r===null?[]:[{environmentId:e,label:n,summary:t===void 0?r:{...r,buckets:r.buckets.filter(t)}}]),6)}var Tt=new Set;function Et(e,t){return t.size===0?e:e.map(e=>e.summary===null?e:{...e,summary:{...e.summary,buckets:e.summary.buckets.filter(e=>!t.has(e.provider)),sources:e.summary.sources.filter(e=>!t.has(e.fingerprint.provider))}})}function Dt(e,t,n){let r=(0,Q.c)(36),i=t===void 0?null:t,a=n===void 0?Tt:n,o;r[0]!==e.resolution||r[1]!==e.sinceDay||r[2]!==e.sinceTime||r[3]!==e.timeZone||r[4]!==e.untilDay||r[5]!==e.untilTime?(o=JSON.stringify({sinceDay:e.sinceDay,untilDay:e.untilDay,timeZone:e.timeZone,resolution:e.resolution,sinceTime:e.sinceTime,untilTime:e.untilTime}),r[0]=e.resolution,r[1]=e.sinceDay,r[2]=e.sinceTime,r[3]=e.timeZone,r[4]=e.untilDay,r[5]=e.untilTime,r[6]=o):o=r[6];let s=o,c;r[7]===s?c=r[8]:(c=Ct(s),r[7]=s,r[8]=c);let l=P(c),u;r[9]!==l||r[10]!==i?(u=i===null?l:l.filter(e=>i.has(e.environmentId)),r[9]=l,r[10]=i,r[11]=u):u=r[11];let d=u,f;r[12]!==d||r[13]!==s?(f=e=>lt({registry:g,server:oe,presentations:ae,environmentIds:d.filter(jt).map(At),input:e??JSON.parse(s)}),r[12]=d,r[13]=s,r[14]=f):f=r[14];let p=f,m;r[15]!==a||r[16]!==d?(m=wt(Et(d,a)),r[15]=a,r[16]=d,r[17]=m):m=r[17];let h=m,_;r[18]===d?_=r[19]:(_=d.filter(kt),r[18]=d,r[19]=_);let v=_.length,y;r[20]===d?y=r[21]:(y=d.filter(Ot),r[20]=d,r[21]=y);let b=y.length,x=v===0&&b>0,[S,C]=(0,Z.useState)(null);v>0&&(S?.merged!==h||S.window!==e||S.selection!==i||S.hidden!==a)&&C({window:e,merged:h,selection:i,hidden:a});let w=S?.selection===i&&S.hidden===a?S:null,T;r[22]!==v||r[23]!==e||r[24]!==x||r[25]!==w||r[26]!==h?(T=v>0?{window:e,merged:h}:w??(x?null:{window:e,merged:h}),r[22]=v,r[23]=e,r[24]=x,r[25]=w,r[26]=h,r[27]=T):T=r[27];let E=T,D=v>0&&b>0,O;return r[28]!==l||r[29]!==x||r[30]!==h||r[31]!==p||r[32]!==d||r[33]!==E||r[34]!==D?(O={merged:h,environments:l,selectedEnvironments:d,isPending:x,shown:E,isPartial:D,refresh:p},r[28]=l,r[29]=x,r[30]=h,r[31]=p,r[32]=d,r[33]=E,r[34]=D,r[35]=O):O=r[35],O}function Ot(e){return e.summary===null&&e.error===null}function kt(e){return e.summary!==null}function At(e){let{environmentId:t}=e;return t}function jt(e){return e.canReadDiagnostics&&H(e.environmentId,`diagnostics:read`)}var $=e(r(),1);function Mt(e){let t=(0,Q.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=M(`w-full caption-bottom text-xs`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,$.jsx)(`div`,{"data-slot":`table-container`,className:`relative w-full overflow-x-auto`,children:(0,$.jsx)(`table`,{"data-slot":`table`,className:i,...r})}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function Nt(e){let t=(0,Q.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=M(`[&_tr]:border-b`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,$.jsx)(`thead`,{"data-slot":`table-header`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function Pt(e){let t=(0,Q.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=M(`[&_tr:last-child]:border-0`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,$.jsx)(`tbody`,{"data-slot":`table-body`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function Ft(e){let t=(0,Q.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=M(`border-b transition-colors hover:bg-muted/50 has-aria-expanded:bg-muted/50 data-[state=selected]:bg-muted`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,$.jsx)(`tr`,{"data-slot":`table-row`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function It(e){let t=(0,Q.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=M(`h-10 px-2 text-left align-middle font-medium whitespace-nowrap text-foreground [&:has([role=checkbox])]:pr-0`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,$.jsx)(`th`,{"data-slot":`table-head`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}function Lt(e){let t=(0,Q.c)(8),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=M(`p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0`,n),t[3]=n,t[4]=i);let a;return t[5]!==r||t[6]!==i?(a=(0,$.jsx)(`td`,{"data-slot":`table-cell`,className:i,...r}),t[5]=r,t[6]=i,t[7]=a):a=t[7],a}var Rt=[{key:`inputCostPerMillionTokens`,label:`Input`,optional:!1},{key:`outputCostPerMillionTokens`,label:`Output`,optional:!1},{key:`cacheReadCostPerMillionTokens`,label:`Cache read`,optional:!0},{key:`cacheWriteCostPerMillionTokens`,label:`Cache write`,optional:!0}];function zt(e=``,t){return{model:e,inputCostPerMillionTokens:t?.inputCostPerMillionTokens.toString()??``,outputCostPerMillionTokens:t?.outputCostPerMillionTokens.toString()??``,cacheReadCostPerMillionTokens:t?.cacheReadCostPerMillionTokens?.toString()??``,cacheWriteCostPerMillionTokens:t?.cacheWriteCostPerMillionTokens?.toString()??``}}function Bt(e){let t=e.model.trim();if(t.length===0)return null;let n={};for(let t of Rt){let r=e[t.key].trim();if(r===``){if(t.optional)continue;return null}if(!/^(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i.test(r))return null;let i=Number(r);if(!Number.isFinite(i)||i<0)return null;n[t.key]=i}return n.inputCostPerMillionTokens===void 0||n.outputCostPerMillionTokens===void 0?null:{model:t,price:{inputCostPerMillionTokens:n.inputCostPerMillionTokens,outputCostPerMillionTokens:n.outputCostPerMillionTokens,...n.cacheReadCostPerMillionTokens===void 0?{}:{cacheReadCostPerMillionTokens:n.cacheReadCostPerMillionTokens},...n.cacheWriteCostPerMillionTokens===void 0?{}:{cacheWriteCostPerMillionTokens:n.cacheWriteCostPerMillionTokens}}}}function Vt(e){return e.isNew&&e.model.trim()===``&&(e.alias??``).trim()===``&&Object.values(e.values).every(e=>e.trim()===``)}function Ht(e,t){return e.prices&&Object.hasOwn(e.prices,t)?e.prices[t]:void 0}function Ut(e,t){return e.aliases&&Object.hasOwn(e.aliases,t)?e.aliases[t]:void 0}function Wt(e,t){if(e.some(e=>e.aliases===null))return{value:``,placeholder:`Unavailable`};let n=e.map(e=>Ut(e,t)??``);return n.some(e=>e!==n[0])?{value:``,placeholder:`Mixed`}:{value:n[0]??``,placeholder:`None`}}function Gt(e,t,n){let r=Rt.find(e=>e.key===n).optional,i=e.map(e=>Ht(e,t)?zt(t,Ht(e,t))[n]:null);return e.some(e=>e.prices===null)?{value:``,placeholder:`Unavailable`}:i.some(e=>e!==i[0])?{value:``,placeholder:`Mixed`}:{value:i[0]??``,placeholder:i[0]===null?`Automatic`:r?`Input rate`:`0.00`}}function Kt(e,t){let n=[],r=new Map;for(let i of t){if(Vt(i))continue;let t=i.model.trim(),a=Ut(e,t);if(i.removed){Ht(e,t)&&n.push({model:t,price:null}),a!==void 0&&n.push({model:t,alias:null});continue}let o=(i.alias??a??``).trim();if(o!==``){t===``?r.set(i.id,`Enter a model ID.`):o===t?r.set(i.id,`Map to a different model.`):(o!==a&&n.push({model:t,alias:o}),Ht(e,t)&&n.push({model:t,price:null}));continue}if(a!==void 0&&(n.push({model:t,alias:null}),!Ht(e,t)&&Object.values(i.values).every(e=>e.trim()===``)))continue;let s=zt(t,Ht(e,t)),c={...s,...i.values},l=Bt(c);if(l===null){let n=Rt.find(e=>!e.optional&&c[e.key].trim()===``);r.set(i.id,t===``?`Enter a model ID.`:n?`${n.label} is required on ${e.label}.`:`Use non-negative numbers for prices.`);continue}let u=zt(t,l.price);Rt.some(e=>s[e.key]!==u[e.key])&&n.push(l)}return{changes:n,errors:r}}function qt(e,t){return new Map(e.filter(e=>e.unavailable===null&&e.prices!==null).flatMap(e=>[...Kt(e,t).errors]))}async function Jt(e){await Promise.all(e.targets.map(async t=>{let n,r=e.changes.get(t.environmentId)??[],i=r.flatMap(e=>`price`in e?[[e.model,e.price]]:[]),a=r.flatMap(e=>`alias`in e?[[e.model,e.alias]]:[]);if(t.unavailable!==null)n={status:`failed`,error:t.unavailable};else if(a.length>0&&t.aliases===null)n={status:`failed`,error:`Update server to map models`};else try{n=(r.length===0?{_tag:`Success`}:await e.write({environmentId:t.environmentId,input:{patch:{...i.length>0?{usagePriceOverrides:Object.fromEntries(i)}:{},...a.length>0?{usageModelAliases:Object.fromEntries(a)}:{}}}}))._tag===`Success`?{status:`saved`}:{status:`failed`,error:`Could not save. Try again.`}}catch{n={status:`failed`,error:`Could not save. Try again.`}}e.onResult(t.environmentId,n)}))}var Yt=y(e=>[...e(ae.presentationsAtom)].map(([t,n])=>{let r=e(oe.settingsValueAtom(t)),i=e(U.sessionStateAtom(t)),a=N(d(i)),o=i._tag===`Failure`?`denied`:a===null?i.waiting?`pending`:`denied`:j(a,`settings:write`)?`granted`:`denied`;return{environmentId:t,label:n.entry.target.label,prices:r?.usagePriceOverrides??null,aliases:n.serverConfig?.environment.capabilities.usageModelAliases===!0?r?.usageModelAliases??null:null,unavailable:n.connection.phase===`connected`?r===null?`Prices not loaded`:n.serverConfig?.environment.capabilities.usagePriceOverrides===!0?o===`pending`?`Checking permissions…`:o===`denied`?`Read-only access`:null:`Update server to edit prices`:`Offline`}}));function Xt(e){let t=(0,Q.c)(119),{usage:n,initialSelectedEnvironmentIds:r,initialModel:i,onOpenChange:o}=e,s=P(Yt),[c,l]=(0,Z.useState)(r),u;if(t[0]!==s||t[1]!==c){let e;t[3]===c?e=t[4]:(e=e=>c===null||c.has(e.environmentId),t[3]=c,t[4]=e),u=s.filter(e),t[0]=s,t[1]=c,t[2]=u}else u=t[2];let d=u,p;t[5]!==i||t[6]!==d?(p=()=>i===void 0||d.some(e=>Object.hasOwn(e.prices??{},i)||Object.hasOwn(e.aliases??{},i))?[]:[{id:`new:initial`,model:i,isNew:!0,values:{}}],t[5]=i,t[6]=d,t[7]=p):p=t[7];let[g,_]=(0,Z.useState)(p),[y,x]=(0,Z.useState)(!1),[C,w]=(0,Z.useState)(null),T=(0,Z.useRef)(null),E=(0,Z.useRef)(0),D;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(D={reportFailure:!1},t[8]=D):D=t[8];let k=ce(oe.updateSettings,D),A,j,N,I,L,R,z,B,V,te,ne,re,ie,ae,se;if(t[9]!==C||t[10]!==g||t[11]!==s||t[12]!==o||t[13]!==y||t[14]!==d||t[15]!==c||t[16]!==k||t[17]!==n){let e=[...new Set(d.flatMap(mn))].sort(),r;t[33]===d?r=t[34]:(r=e=>d.some(t=>t.environmentId===e.environmentId),t[33]=d,t[34]=r);let i=[...new Set([...e,...n.filter(r).flatMap(fn)])].sort(),u;t[35]===g?u=t[36]:(u=new Set(g.filter(dn).map(un)),t[35]=g,t[36]=u);let p=u,D;t[37]!==C||t[38]!==p?(D=e=>C===null||!p.has(e),t[37]=C,t[38]=p,t[39]=D):D=t[39];let P=[...e.filter(D).map(e=>g.find(t=>t.id===`model:${e}`)??{id:`model:${e}`,model:e,isNew:!1,values:{}}),...g.filter(ln)],oe=g.filter(cn);R=qt(d,oe);for(let t of oe)t.isNew&&(t.model.trim()===``?R.set(t.id,`Enter a model ID.`):C===null&&(e.includes(t.model.trim())||g.some(e=>e.id!==t.id&&e.model.trim()===t.model.trim()))&&R.set(t.id,`This model already has a row. Edit its prices there.`));z=C?.destinations.filter(e=>C.results.get(e.environmentId)?.status===`failed`)??[];let U=y||z.length>0;B=oe.length>0,I=d.length===1?d[0].label:`${d.length} environments`;let ce=c===null?`All environments`:I,le;t[40]===Symbol.for(`react.memo_cache_sentinel`)?(le=()=>{_([]),w(null)},t[40]=le):le=t[40],L=le;let ue;t[41]===Symbol.for(`react.memo_cache_sentinel`)?(ue=e=>{l(e),w(null)},t[41]=ue):ue=t[41];let W=ue,G;t[42]===Symbol.for(`react.memo_cache_sentinel`)?(G=e=>{_(t=>t.some(t=>t.id===e.id)?t.map(t=>t.id===e.id?e:t):[...t,e]),w(null)},t[42]=G):G=t[42];let de=G,K=sn,fe;t[43]===Symbol.for(`react.memo_cache_sentinel`)?(fe=e=>{!e.isNew&&Object.keys(e.values).length===0&&e.alias===void 0?_(t=>t.filter(t=>t.id!==e.id)):de(e)},t[43]=fe):fe=t[43];let pe=fe,q;t[44]===d?q=t[45]:(q=(e,t,n)=>{let r={...e.values,[t]:n},i=Gt(d,e.model,t);K(e,i,n)&&delete r[t],pe({...e,values:r})},t[44]=d,t[45]=q);let J=q,Y;t[46]===d?Y=t[47]:(Y=(e,t)=>{let{alias:n,...r}=e,i=Wt(d,e.model);pe(K(e,i,t)?r:{...r,alias:t})},t[46]=d,t[47]=Y);let me=Y;V=async e=>{let t=e!==void 0&&e;if(y)return;let n=t?z:d,r=t&&C?C.drafts:oe;if(n.length===0||r.length===0)return;let i=n.map(e=>s.find(t=>t.environmentId===e.environmentId)??{...e,prices:null,aliases:null,unavailable:`Environment removed`}),a=new Map(i.map(e=>[e.environmentId,Kt(e,r)]));x(!0),w(e=>({drafts:r,destinations:t&&e?e.destinations:i,results:new Map([...t&&e?e.results:[],...i.map(on)])}));let o=!1;await Jt({targets:i.map(e=>({...e,unavailable:e.unavailable??[...a.get(e.environmentId).errors.values()][0]??null})),changes:new Map([...a].map(an)),write:async e=>H(e.environmentId,`settings:write`)?k(e):{_tag:`Failure`},onResult:(e,t)=>{t.status===`failed`&&(o=!0),w(n=>n===null?null:{...n,results:new Map(n.results).set(e,t)})}}),x(!1),o||_([])},N=ke,ae=!0,t[48]!==o||t[49]!==y?(se=e=>{y||o(e)},t[48]=o,t[49]=y,t[50]=se):se=t[50],j=Oe,re=`max-w-4xl`,t[51]===Symbol.for(`react.memo_cache_sentinel`)?(ie=(0,$.jsxs)(Ce,{children:[(0,$.jsx)(we,{children:`Custom model prices`}),(0,$.jsx)(De,{children:`Prices and mappings apply to all past and future usage on the environments you select.`})]}),t[51]=ie):ie=t[51],A=Ee;let he;t[52]===Symbol.for(`react.memo_cache_sentinel`)?(he=(0,$.jsx)(qe,{id:`usage-prices-apply-label`,className:`shrink-0`,children:`Apply to`}),t[52]=he):he=t[52];let X;t[53]===Symbol.for(`react.memo_cache_sentinel`)?(X=(0,$.jsx)(b,{variant:`outline`,size:`sm`,className:`min-w-0`}),t[53]=X):X=t[53];let ye=y||B,be;t[54]===ce?be=t[55]:(be=(0,$.jsx)(`span`,{id:`usage-prices-selection`,className:`truncate`,children:ce}),t[54]=ce,t[55]=be);let Se;t[56]===Symbol.for(`react.memo_cache_sentinel`)?(Se=(0,$.jsx)(a,{className:`size-3.5 shrink-0`,"aria-hidden":!0}),t[56]=Se):Se=t[56];let Te;t[57]!==ye||t[58]!==be?(Te=(0,$.jsxs)(F,{render:X,"aria-labelledby":`usage-prices-apply-label usage-prices-selection`,disabled:ye,children:[be,Se]}),t[57]=ye,t[58]=be,t[59]=Te):Te=t[59];let Ae=c===null,je;t[60]===Symbol.for(`react.memo_cache_sentinel`)?(je=e=>W(e?null:new Set),t[60]=je):je=t[60];let Me;t[61]===Ae?Me=t[62]:(Me=(0,$.jsx)(f,{checked:Ae,closeOnClick:!1,onCheckedChange:je,children:`All environments`}),t[61]=Ae,t[62]=Me);let Ne;t[63]===Symbol.for(`react.memo_cache_sentinel`)?(Ne=(0,$.jsx)(v,{}),t[63]=Ne):Ne=t[63];let Pe;if(t[64]!==s||t[65]!==d||t[66]!==c){let e;t[68]!==s.length||t[69]!==d||t[70]!==c?(e=e=>(0,$.jsx)(f,{checked:c===null||c.has(e.environmentId),closeOnClick:!1,onCheckedChange:t=>{let n=new Set(d.map(rn));t?n.add(e.environmentId):n.delete(e.environmentId),W(n.size===s.length?null:n)},children:(0,$.jsxs)(`span`,{className:`flex min-w-0 items-center gap-3`,children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.label}),e.unavailable?(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.unavailable}):null]})},e.environmentId),t[68]=s.length,t[69]=d,t[70]=c,t[71]=e):e=t[71],Pe=s.map(e),t[64]=s,t[65]=d,t[66]=c,t[67]=Pe}else Pe=t[67];let Fe;t[72]!==Me||t[73]!==Pe?(Fe=(0,$.jsxs)(ee,{align:`start`,children:[Me,Ne,Pe]}),t[72]=Me,t[73]=Pe,t[74]=Fe):Fe=t[74];let Ie;t[75]!==Te||t[76]!==Fe?(Ie=(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[he,(0,$.jsxs)(m,{children:[Te,Fe]})]}),t[75]=Te,t[76]=Fe,t[77]=Ie):Ie=t[77];let Le;t[78]===Symbol.for(`react.memo_cache_sentinel`)?(Le=(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`USD / million tokens`}),t[78]=Le):Le=t[78],t[79]===Ie?te=t[80]:(te=(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[Ie,Le]}),t[79]=Ie,t[80]=te),ne=d.length===0?(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:s.length===0?`Connect an environment to set model prices.`:`Select an environment to see and change its model prices.`}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`min-w-0 overflow-hidden rounded-lg border border-border`,children:(0,$.jsxs)(Mt,{className:`min-w-180 table-fixed`,"aria-label":`Custom model prices`,children:[(0,$.jsxs)(`colgroup`,{children:[(0,$.jsx)(`col`,{className:`w-[22%]`}),(0,$.jsx)(`col`,{className:`w-[18%]`}),Rt.map(nn),(0,$.jsx)(`col`,{className:`w-10`})]}),(0,$.jsx)(Nt,{children:(0,$.jsxs)(Ft,{children:[(0,$.jsx)(It,{children:`Model ID`}),(0,$.jsx)(It,{children:`Map to`}),Rt.map(tn),(0,$.jsx)(It,{children:(0,$.jsx)(b,{size:`icon-xs`,variant:`ghost`,"aria-label":`Add model price`,disabled:U,onClick:()=>{E.current+=1;let e=`new:${E.current}`;T.current=e,de({id:e,model:``,isNew:!0,values:{}})},children:(0,$.jsx)(h,{"aria-hidden":!0})})})]})}),(0,$.jsx)(Pt,{children:P.length===0?(0,$.jsx)(Ft,{children:(0,$.jsx)(Lt,{colSpan:7,className:`text-center whitespace-normal`,children:(0,$.jsx)(`p`,{className:`py-6 text-muted-foreground`,children:d.some(en)?`Some environment prices are unavailable.`:`No custom prices or mappings. Add a row to set one.`})})}):P.map(e=>{let t=Wt(d,e.model),n=(e.alias??t.value).trim();return(0,$.jsxs)(Ft,{"data-row-id":e.id,children:[(0,$.jsxs)(Lt,{className:`whitespace-normal`,children:[e.isNew?(0,$.jsx)(xe,{size:`compact`,value:e.model,ref:t=>{t&&T.current===e.id&&(t.focus(),T.current=null)},"aria-label":`New model ID`,"aria-invalid":e.model.trim()!==``&&R.has(e.id)||void 0,list:`usage-price-models`,placeholder:`Model ID`,autoComplete:`off`,spellCheck:!1,disabled:U,onChange:t=>de({...e,model:t.target.value})}):(0,$.jsx)(`span`,{className:M(`block break-all`,e.removed&&`text-muted-foreground line-through`),children:e.model}),R.has(e.id)&&(e.model.trim()!==``||Object.values(e.values).some($t))?(0,$.jsx)(`p`,{role:`alert`,className:`mt-1 text-xs text-destructive`,children:R.get(e.id)}):null]}),e.removed?(0,$.jsx)(Lt,{colSpan:5,children:(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:`Automatic pricing after saving`})}):(0,$.jsx)(Lt,{children:(0,$.jsx)(xe,{size:`compact`,value:e.alias??t.value,"aria-label":`Map ${e.model||`new model`} to model`,list:`usage-alias-models`,placeholder:e.isNew?`Optional`:t.placeholder,autoComplete:`off`,spellCheck:!1,disabled:U,onChange:t=>me(e,t.target.value)})}),e.removed?null:n===``?Rt.map(t=>{let n=Gt(d,e.model,t.key);return(0,$.jsx)(Lt,{children:(0,$.jsx)(xe,{size:`compact`,inputMode:`decimal`,"aria-label":`${t.label} price for ${e.model||`new model`}`,value:e.values[t.key]??(e.isNew?``:n.value),placeholder:e.isNew?t.optional?`Input rate`:`0.00`:n.placeholder,autoComplete:`off`,disabled:U,font:`mono`,onChange:n=>J(e,t.key,n.target.value)})},t.key)}):(0,$.jsx)(Lt,{colSpan:4,className:`whitespace-normal`,children:(0,$.jsxs)(`span`,{className:`break-all text-muted-foreground`,children:[`Counted as `,n]})}),(0,$.jsx)(Lt,{children:(0,$.jsxs)(ve,{children:[(0,$.jsx)(ge,{render:(0,$.jsx)(b,{size:`icon-xs`,variant:`ghost`}),disabled:U,"aria-label":e.removed?`Undo reset for ${e.model}`:e.isNew?`Remove new model`:`Reset price for ${e.model} to automatic`,onClick:()=>{e.isNew?_(t=>t.filter(t=>t.id!==e.id)):e.removed?pe({...e,removed:!1}):de({...e,removed:!0})},children:e.isNew?(0,$.jsx)(O,{"aria-hidden":!0}):(0,$.jsx)(S,{"aria-hidden":!0})}),(0,$.jsx)(_e,{children:e.removed?`Undo reset`:e.isNew?`Remove row`:`Reset to automatic`})]})})]},e.id)})})]})}),(0,$.jsx)(`datalist`,{id:`usage-price-models`,children:i.filter(t=>!e.includes(t)).map(Qt)}),(0,$.jsx)(`datalist`,{id:`usage-alias-models`,children:i.filter(e=>d.every(t=>!Object.hasOwn(t.aliases??{},e))).map(Zt)}),(0,$.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Blank cache rates use the input price. Enter 0 for free tokens. A mapped model’s usage counts as the model it maps to.`,d.length>1?` Mixed cells keep each environment’s rate until you edit them.`:``]})]}),t[9]=C,t[10]=g,t[11]=s,t[12]=o,t[13]=y,t[14]=d,t[15]=c,t[16]=k,t[17]=n,t[18]=A,t[19]=j,t[20]=N,t[21]=I,t[22]=L,t[23]=R,t[24]=z,t[25]=B,t[26]=V,t[27]=te,t[28]=ne,t[29]=re,t[30]=ie,t[31]=ae,t[32]=se}else A=t[18],j=t[19],N=t[20],I=t[21],L=t[22],R=t[23],z=t[24],B=t[25],V=t[26],te=t[27],ne=t[28],re=t[29],ie=t[30],ae=t[31],se=t[32];let U;t[81]===C?U=t[82]:(U=C?(0,$.jsx)(`div`,{role:`status`,className:`grid gap-1 text-xs`,children:C.destinations.map(e=>{let t=C.results.get(e.environmentId);return(0,$.jsxs)(`div`,{className:`flex justify-between gap-3`,children:[(0,$.jsx)(`span`,{className:`truncate text-muted-foreground`,children:e.label}),(0,$.jsx)(`span`,{className:t?.status===`failed`?`text-right text-destructive`:`text-muted-foreground`,children:t?.status===`failed`?`Not saved · ${t.error}`:t?.status===`saved`?`Saved`:`Saving…`})]},e.environmentId)})}):null,t[81]=C,t[82]=U);let le;t[83]!==A||t[84]!==U||t[85]!==te||t[86]!==ne?(le=(0,$.jsxs)(A,{children:[te,ne,U]}),t[83]=A,t[84]=U,t[85]=te,t[86]=ne,t[87]=le):le=t[87];let ue=B?`Changes apply to ${I}`:``,W;t[88]===ue?W=t[89]:(W=(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:ue}),t[88]=ue,t[89]=W);let G;t[90]!==L||t[91]!==z.length||t[92]!==B||t[93]!==y?(G=B?(0,$.jsx)(b,{variant:`ghost`,disabled:y,onClick:L,children:z.length>0?`Discard pending changes`:`Discard changes`}):null,t[90]=L,t[91]=z.length,t[92]=B,t[93]=y,t[94]=G):G=t[94];let de=y||!B&&z.length===0||z.length===0&&(R.size>0||d.length===0),K;t[95]!==z.length||t[96]!==V?(K=()=>void V(z.length>0),t[95]=z.length,t[96]=V,t[97]=K):K=t[97];let fe=y?`Saving…`:z.length>0?`Retry failed saves`:`Save changes`,pe;t[98]!==de||t[99]!==K||t[100]!==fe?(pe=(0,$.jsx)(b,{disabled:de,onClick:K,children:fe}),t[98]=de,t[99]=K,t[100]=fe,t[101]=pe):pe=t[101];let q;t[102]!==G||t[103]!==pe?(q=(0,$.jsxs)(`div`,{className:`flex w-full flex-wrap justify-end gap-2 sm:w-auto`,children:[G,pe]}),t[102]=G,t[103]=pe,t[104]=q):q=t[104];let J;t[105]!==W||t[106]!==q?(J=(0,$.jsxs)(Te,{variant:`bare`,className:`items-center sm:justify-between`,children:[W,q]}),t[105]=W,t[106]=q,t[107]=J):J=t[107];let Y;t[108]!==j||t[109]!==le||t[110]!==J||t[111]!==re||t[112]!==ie?(Y=(0,$.jsxs)(j,{className:re,children:[ie,le,J]}),t[108]=j,t[109]=le,t[110]=J,t[111]=re,t[112]=ie,t[113]=Y):Y=t[113];let me;return t[114]!==N||t[115]!==Y||t[116]!==ae||t[117]!==se?(me=(0,$.jsx)(N,{open:ae,onOpenChange:se,children:Y}),t[114]=N,t[115]=Y,t[116]=ae,t[117]=se,t[118]=me):me=t[118],me}function Zt(e){return(0,$.jsx)(`option`,{value:e},e)}function Qt(e){return(0,$.jsx)(`option`,{value:e},e)}function $t(e){return e!==``}function en(e){return e.prices===null}function tn(e){return(0,$.jsx)(It,{children:e.label},e.key)}function nn(e){return(0,$.jsx)(`col`,{},e.key)}function rn(e){return e.environmentId}function an(e){let[t,n]=e;return[t,n.changes]}function on(e){return[e.environmentId,{status:`saving`}]}function sn(e,t,n){return!e.isNew&&t.placeholder!==`Mixed`&&t.placeholder!==`Unavailable`&&n===t.value}function cn(e){return!Vt(e)}function ln(e){return e.isNew}function un(e){return e.model.trim()}function dn(e){return e.isNew}function fn(e){return e.summary?.buckets.map(pn)??[]}function pn(e){return e.model}function mn(e){return[...Object.keys(e.prices??{}),...Object.keys(e.aliases??{})]}var hn=960,gn=260,_n=4,vn=8,yn=new Set;function bn(e,t,n){let r=e?.byProvider.get(t);return r===void 0?0:n===`tokens`?r.totalTokens:r.costUsd}function xn(e,t,n){return e.map(e=>{let r=t.get(e),i=Ye.map(e=>({provider:e,value:bn(r,e,n)}));return{bands:i,total:i.reduce((e,t)=>e+t.value,0)}})}function Sn(e){let t=e.length;if(t<2)return[0];let n=[];for(let r=0;r<t-1;r+=1){let t=(e[r+1]?.x??0)-(e[r]?.x??0),i=(e[r+1]?.y??0)-(e[r]?.y??0);n.push(t===0?0:i/t)}let r=Array.from({length:t},()=>0);r[0]=n[0]??0,r[t-1]=n[t-2]??0;for(let e=1;e<t-1;e+=1){let t=n[e-1]??0,i=n[e]??0;r[e]=t*i<=0?0:(t+i)/2}for(let e=0;e<t-1;e+=1){let t=n[e]??0;if(t===0){r[e]=0,r[e+1]=0;continue}let i=(r[e]??0)/t,a=(r[e+1]??0)/t,o=i*i+a*a;if(o>9){let n=3/Math.sqrt(o);r[e]=n*i*t,r[e+1]=n*a*t}}return r}function Cn(e){if(e.length<2)return[];let t=Sn(e),n=[];for(let r=0;r<e.length-1;r+=1){let i=e[r],a=e[r+1];if(i===void 0||a===void 0)continue;let o=a.x-i.x;n.push({from:i,c1:{x:i.x+o/3,y:i.y+(t[r]??0)*o/3},c2:{x:a.x-o/3,y:a.y-(t[r+1]??0)*o/3},to:a})}return n}function wn(e){let t=e[0];if(t===void 0)return``;let n=`M${t.from.x.toFixed(2)},${t.from.y.toFixed(2)}`;for(let t of e)n+=` C${t.c1.x.toFixed(2)},${t.c1.y.toFixed(2)} ${t.c2.x.toFixed(2)},${t.c2.y.toFixed(2)} ${t.to.x.toFixed(2)},${t.to.y.toFixed(2)}`;return n}function Tn(e){return e===``?``:`${e} L${hn},${gn} L0,${gn} Z`}function En(e,t){if(e<=0)return{max:0,ticks:[0]};let n=e/t,r=10**Math.floor(Math.log10(n)),i=n/r,a=(i>5?10:i>2?5:i>1?2:1)*r,o=Math.ceil(e/a)*a,s=[];for(let e=0;e<=o+a*1e-6;e+=a)s.push(e);return{max:o,ticks:s}}var Dn=Array.from({length:5},(e,t)=>t);function On(e,t){let n=e.reduce((e,t)=>t.bands.reduce((e,t)=>Math.max(e,t.value),e),0);return n===0&&t.size>0?{max:_n,ticks:Dn,labeled:!1}:{...En(n,_n),labeled:!0}}function kn(e,t){return t===0?gn:gn-e/t*252}function An(e,t,n,r,i){let a=xn(e,t,n),o=On(a,i),s=e.length<2?0:hn/(e.length-1);return{columns:a,scale:o,stepX:s,paths:r.map(e=>{let t=Ye.indexOf(e),n=wn(Cn(a.map((e,n)=>({x:n*s,y:kn(e.bands[t]?.value??0,o.max)}))));return{provider:e,loading:i.has(e),total:a.reduce((e,n)=>e+(n.bands[t]?.value??0),0),line:n,area:Tn(n)}}).toSorted((e,t)=>t.total-e.total)}}function jn(e){let t=(0,Q.c)(97),{providers:n,loadingProviders:r,days:i,daily:a,hours:o,hourly:s,metric:c,referenceTime:l,resolution:u,timeZone:d}=e,f=r===void 0?yn:r,p=u===`hour`?o:i,m;t[0]!==a||t[1]!==s||t[2]!==u?(m=u===`hour`?new Map(s.map(Pn)):new Map(a.map(Nn)),t[0]=a,t[1]=s,t[2]=u,t[3]=m):m=t[3];let h=m,[g,_]=(0,Z.useState)(null),v=(0,Z.useRef)(null),y=(0,Z.useRef)(null),b=(0,Z.useRef)(null),x;t[4]!==h||t[5]!==f||t[6]!==c||t[7]!==p||t[8]!==n?(x=An(p,h,c,n,f),t[4]=h,t[5]=f,t[6]=c,t[7]=p,t[8]=n,t[9]=x):x=t[9];let{columns:S,scale:C,paths:w,stepX:T}=x,E;t[10]===C.max?E=t[11]:(E=e=>kn(e,C.max),t[10]=C.max,t[11]=E);let D=E,O=Mn,k=c===`tokens`?K:W,A;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(A=()=>{let e=v.current,t=y.current,n=b.current;if(e===null||t===null||n===null)return;let r=t.offsetWidth,i=t.offsetHeight,a=e.clientWidth,o=e.clientHeight,s=n.x+12+r<=a?n.x+12:n.x-12-r,c=n.y+12+i<=o?n.y+12:n.y-12-i,l=Math.min(Math.max(0,s),Math.max(0,a-r)),u=Math.min(Math.max(0,c),Math.max(0,o-i));e.style.setProperty(`--usage-tooltip-left`,`${l}px`),e.style.setProperty(`--usage-tooltip-top`,`${u}px`)},t[12]=A):A=t[12];let j=A,N,ee;t[13]===g?(N=t[14],ee=t[15]):(N=()=>{if(g===null)return;j();let e=v.current,t=y.current;if(e!==null&&t!==null)return je([e,t],j)},ee=[g,j],t[13]=g,t[14]=N,t[15]=ee),(0,Z.useLayoutEffect)(N,ee);let P;t[16]===p.length?P=t[17]:(P=e=>{let t=v.current;if(t===null||p.length===0)return;let n=t.getBoundingClientRect();if(n.width===0)return;let r=Math.min(n.width,Math.max(0,e.clientX-n.left)),i=Math.min(n.height,Math.max(0,e.clientY-n.top)),a=r/n.width,o=Math.round(a*(p.length-1));b.current={x:r,y:i},j(),_(Math.min(p.length-1,Math.max(0,o)))},t[16]=p.length,t[17]=P);let F=P,I=g===null?void 0:p[g],L=g===null?void 0:S[g],R;if(t[18]!==f||t[19]!==n){let e;t[21]===f?e=t[22]:(e=e=>f.has(e),t[21]=f,t[22]=e),R=n.some(e),t[18]=f,t[19]=n,t[20]=R}else R=t[20];let z=R,B;t[23]!==u||t[24]!==d?(B=e=>u===`hour`?pe(e,d):le(e),t[23]=u,t[24]=d,t[25]=B):B=t[25];let V=B,te;t[26]!==V||t[27]!==l||t[28]!==u||t[29]!==d?(te=e=>u===`hour`&&l!==void 0?ue(e,l,d):V(e),t[26]=V,t[27]=l,t[28]=u,t[29]=d,t[30]=te):te=t[30];let ne=te,re;t[31]!==k||t[32]!==C.labeled||t[33]!==C.ticks||t[34]!==D?(re=C.labeled?C.ticks.map(e=>(0,$.jsx)(`span`,{className:`absolute right-0 -translate-y-1/2 text-3xs text-muted-foreground tabular-nums`,style:{top:`${D(e)/gn*100}%`},children:e===0?`0`:k(e)},e)):null,t[31]=k,t[32]=C.labeled,t[33]=C.ticks,t[34]=D,t[35]=re):re=t[35];let ie;t[36]===re?ie=t[37]:(ie=(0,$.jsx)(`div`,{className:`relative h-56 w-14 shrink-0`,children:re}),t[36]=re,t[37]=ie);let ae;t[38]===Symbol.for(`react.memo_cache_sentinel`)?(ae=()=>{b.current=null,_(null)},t[38]=ae):ae=t[38];let oe=`${u===`hour`?`Hourly`:`Daily`} ${c===`tokens`?`processed tokens`:`cost`} by provider`,se;if(t[39]!==C.ticks||t[40]!==D){let e;t[42]===D?e=t[43]:(e=e=>{let t=D(e);return(0,$.jsx)(`line`,{x1:0,x2:hn,y1:t,y2:t,stroke:`currentColor`,strokeWidth:1,className:`text-border`,vectorEffect:`non-scaling-stroke`},e)},t[42]=D,t[43]=e),se=C.ticks.map(e),t[39]=C.ticks,t[40]=D,t[41]=se}else se=t[41];let H;if(t[44]!==w){let e;t[46]===Symbol.for(`react.memo_cache_sentinel`)?(e=e=>{let{provider:t,loading:n,area:r}=e;return(0,$.jsx)(`path`,{d:r,className:O(n),fill:Ge[t].color,fillOpacity:.12},t)},t[46]=e):e=t[46],H=w.map(e),t[44]=w,t[45]=H}else H=t[45];let U;if(t[47]!==w){let e;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(e=e=>{let{provider:t,loading:n,line:r}=e;return(0,$.jsx)(`path`,{d:r,className:O(n),fill:`none`,stroke:Ge[t].color,strokeWidth:2,vectorEffect:`non-scaling-stroke`},t)},t[49]=e):e=t[49],U=w.map(e),t[47]=w,t[48]=U}else U=t[48];let ce;t[50]!==g||t[51]!==T?(ce=g===null?null:(0,$.jsx)(`line`,{x1:g*T,x2:g*T,y1:vn,y2:gn,stroke:`currentColor`,strokeWidth:1,className:`text-muted-foreground`,vectorEffect:`non-scaling-stroke`}),t[50]=g,t[51]=T,t[52]=ce):ce=t[52];let G;t[53]!==oe||t[54]!==se||t[55]!==H||t[56]!==U||t[57]!==ce?(G=(0,$.jsxs)(`svg`,{className:`h-full w-full`,viewBox:`0 0 ${hn} ${gn}`,preserveAspectRatio:`none`,role:`img`,"aria-label":oe,children:[se,H,U,ce]}),t[53]=oe,t[54]=se,t[55]=H,t[56]=U,t[57]=ce,t[58]=G):G=t[58];let de;t[59]!==k||t[60]!==ne||t[61]!==L?.bands||t[62]!==L?.total||t[63]!==I||t[64]!==f||t[65]!==z||t[66]!==n?(de=I===void 0?null:(0,$.jsxs)(`div`,{ref:y,className:`surface-glass pointer-events-none absolute z-10 min-w-36 max-w-full rounded-xl border border-border/50 px-2.5 py-2 text-xs shadow-lg`,style:{left:`var(--usage-tooltip-left, 0px)`,top:`var(--usage-tooltip-top, 0px)`},children:[(0,$.jsx)(`div`,{className:`mb-1 text-muted-foreground`,children:ne(I)}),n.map(e=>{let{label:t,driverKind:n}=Ge[e];return(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,$.jsx)(Le,{driverKind:n,displayName:t,iconClassName:`size-3`}),t]}),(0,$.jsx)(`span`,{className:M(`tabular-nums`,f.has(e)?`text-muted-foreground`:`text-foreground`),children:k(L?.bands.find(t=>t.provider===e)?.value??0)})]},e)}),(0,$.jsxs)(`div`,{className:`mt-1 flex items-center justify-between gap-3 border-t border-border pt-1`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:`Total`}),(0,$.jsx)(`span`,{className:M(`tabular-nums`,z?`text-muted-foreground`:`text-foreground`),children:k(L?.total??0)})]})]}),t[59]=k,t[60]=ne,t[61]=L?.bands,t[62]=L?.total,t[63]=I,t[64]=f,t[65]=z,t[66]=n,t[67]=de):de=t[67];let fe;t[68]!==F||t[69]!==G||t[70]!==de?(fe=(0,$.jsxs)(`div`,{ref:v,className:`relative h-56 flex-1`,onMouseMove:F,onMouseLeave:ae,children:[G,de]}),t[68]=F,t[69]=G,t[70]=de,t[71]=fe):fe=t[71];let q;t[72]!==ie||t[73]!==fe?(q=(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[ie,fe]}),t[72]=ie,t[73]=fe,t[74]=q):q=t[74];let J;t[75]!==V||t[76]!==p[0]?(J=p[0]===void 0?``:V(p[0]),t[75]=V,t[76]=p[0],t[77]=J):J=t[77];let Y;t[78]===J?Y=t[79]:(Y=(0,$.jsx)(`span`,{children:J}),t[78]=J,t[79]=Y);let me;t[80]!==V||t[81]!==p?(me=p[Math.floor(p.length/2)]===void 0?``:V(p[Math.floor(p.length/2)]??``),t[80]=V,t[81]=p,t[82]=me):me=t[82];let he;t[83]===me?he=t[84]:(he=(0,$.jsx)(`span`,{children:me}),t[83]=me,t[84]=he);let ge;t[85]!==V||t[86]!==p?(ge=p[p.length-1]===void 0?``:V(p[p.length-1]??``),t[85]=V,t[86]=p,t[87]=ge):ge=t[87];let _e;t[88]===ge?_e=t[89]:(_e=(0,$.jsx)(`span`,{children:ge}),t[88]=ge,t[89]=_e);let ve;t[90]!==Y||t[91]!==he||t[92]!==_e?(ve=(0,$.jsxs)(`div`,{className:`flex justify-between pl-16 text-3xs text-muted-foreground uppercase`,children:[Y,he,_e]}),t[90]=Y,t[91]=he,t[92]=_e,t[93]=ve):ve=t[93];let X;return t[94]!==q||t[95]!==ve?(X=(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[q,ve]}),t[94]=q,t[95]=ve,t[96]=X):X=t[96],X}function Mn(e){return M(`transition-opacity`,e&&`opacity-40 delay-150`)}function Nn(e){return[e.day,e]}function Pn(e){return[e.hourStart,e]}function Fn(e){let t=(0,Q.c)(30),{label:n,segments:r,format:i,aside:a}=e,o,s,c,l,u,d;if(t[0]!==a||t[1]!==i||t[2]!==n||t[3]!==r){d=Symbol.for(`react.early_return_sentinel`);bb0:{let e=r.filter(Ln),f=e.reduce(In,0);if(f<=0){d=null;break bb0}c=`flex min-w-0 flex-col gap-2.5`;let p;t[10]===n?p=t[11]:(p=(0,$.jsx)(`h3`,{className:`text-sm font-medium text-foreground`,children:n}),t[10]=n,t[11]=p),t[12]!==a||t[13]!==p?(l=(0,$.jsxs)(`div`,{className:`flex items-baseline justify-between gap-3`,children:[p,a]}),t[12]=a,t[13]=p,t[14]=l):l=t[14];let m;t[15]===i?m=t[16]:(m=e=>`${e.label} ${i(e.value)}`,t[15]=i,t[16]=m);let h;t[17]!==i||t[18]!==f?(h=e=>(0,$.jsxs)(ve,{children:[(0,$.jsx)(ge,{render:(0,$.jsx)(`div`,{className:`h-full min-w-1 rounded-xs first:rounded-l-full last:rounded-r-full`,style:{flex:`${e.value} 1 0`,backgroundColor:e.color}})}),(0,$.jsxs)(_e,{children:[e.label,` · `,i(e.value),` · `,J(e.value/f)]})]},e.label),t[17]=i,t[18]=f,t[19]=h):h=t[19],u=(0,$.jsx)(`div`,{role:`img`,"aria-label":`${n}: ${e.map(m).join(`, `)}`,className:`flex h-2 gap-0.5`,children:e.map(h)}),o=`flex flex-wrap gap-x-4 gap-y-1 text-xs`;let g;t[20]===i?g=t[21]:(g=e=>(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`span`,{"aria-hidden":!0,className:`size-2 rounded-xs`,style:{backgroundColor:e.color}}),(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:e.label}),(0,$.jsx)(`span`,{className:`text-foreground tabular-nums`,children:i(e.value)})]},e.label),t[20]=i,t[21]=g),s=e.map(g)}t[0]=a,t[1]=i,t[2]=n,t[3]=r,t[4]=o,t[5]=s,t[6]=c,t[7]=l,t[8]=u,t[9]=d}else o=t[4],s=t[5],c=t[6],l=t[7],u=t[8],d=t[9];if(d!==Symbol.for(`react.early_return_sentinel`))return d;let f;t[22]!==o||t[23]!==s?(f=(0,$.jsx)(`div`,{className:o,children:s}),t[22]=o,t[23]=s,t[24]=f):f=t[24];let p;return t[25]!==c||t[26]!==l||t[27]!==u||t[28]!==f?(p=(0,$.jsxs)(`div`,{className:c,children:[l,u,f]}),t[25]=c,t[26]=l,t[27]=u,t[28]=f,t[29]=p):p=t[29],p}function In(e,t){return e+t.value}function Ln(e){return e.value>0}function Rn(e){return e.toSorted((e,t)=>t.totalTokens-e.totalTokens||t.costUsd-e.costUsd)}function zn(e,t){return t===`tokens`?e.tokenShare:pt(e)?null:e.costShare}function Bn({tokens:e}){let t=e.uncachedInputTokens+e.cachedInputTokens+e.cacheCreationTokens;return t===0?null:e.cachedInputTokens/t}function Vn(e){let t=e.totalTokens-e.unpricedTokens;return t<=0||pt(e)?null:e.costUsd/t*1e6}var Hn=e=>`color-mix(in oklab, var(--foreground) ${e}%, var(--background))`,Un={input:Hn(60),cacheRead:Hn(30),cacheWrite:Hn(72),output:Hn(100),other:Hn(44)};function Wn(e){return[{label:`Input`,value:e.input,color:Un.input},{label:`Cache read`,value:e.cacheRead,color:Un.cacheRead},{label:`Cache write`,value:e.cacheWrite,color:Un.cacheWrite},{label:`Output`,value:e.output,color:Un.output},{label:`Other`,value:e.unsplit>=.005?e.unsplit:0,color:Un.other}]}function Gn(e){return[{label:`Input`,value:e.uncachedInputTokens,color:Un.input},{label:`Cache read`,value:e.cachedInputTokens,color:Un.cacheRead},{label:`Cache write`,value:e.cacheCreationTokens,color:Un.cacheWrite},{label:`Output`,value:e.outputTokens,color:Un.output}]}function Kn(e){return[{label:`Standard`,value:e.standard,color:Hn(34)},{label:`Fast`,value:e.fast,color:Hn(66)},{label:`Ultrafast`,value:e.ultrafast,color:Hn(100)}]}function qn(e){let t=(0,Q.c)(80),{model:n,environments:r,metric:i,chartWindow:a,onSetPrice:o,onClose:s}=e,c;t[0]!==n.model||t[1]!==n.provider?(c=e=>e.provider===n.provider&&e.model===n.model,t[0]=n.model,t[1]=n.provider,t[2]=c):c=t[2];let l;t[3]!==r||t[4]!==c?(l=wt(r,c),t[3]=r,t[4]=c,t[5]=l):l=t[5];let u=l,d;t[6]===n.provider?d=t[7]:(d=[n.provider],t[6]=n.provider,t[7]=d);let f=d,p=Ge[n.provider],m;t[8]===n?m=t[9]:(m=pt(n),t[8]=n,t[9]=m);let h=m,g;if(t[10]!==h||t[11]!==n){let e=Bn(n),r=Vn(n),i;t[13]!==h||t[14]!==n.costUsd?(i=h?`Unpriced`:W(n.costUsd),t[13]=h,t[14]=n.costUsd,t[15]=i):i=t[15];let a;t[16]===i?a=t[17]:(a={label:`Cost`,value:i},t[16]=i,t[17]=a);let o;t[18]===n.totalTokens?o=t[19]:(o=K(n.totalTokens),t[18]=n.totalTokens,t[19]=o);let s;t[20]===o?s=t[21]:(s={label:`Tokens`,value:o},t[20]=o,t[21]=s),g=[a,s,r===null?null:{label:`Per 1M tokens`,value:W(r)},e===null?null:{label:`Cache hit`,value:J(e)}].filter(Yn),t[10]=h,t[11]=n,t[12]=g}else g=t[12];let _=g,v;t[22]===s?v=t[23]:(v=e=>{e||s()},t[22]=s,t[23]=v);let y;t[24]!==p.driverKind||t[25]!==p.label?(y=(0,$.jsx)(Le,{driverKind:p.driverKind,displayName:p.label,iconClassName:`size-5`}),t[24]=p.driverKind,t[25]=p.label,t[26]=y):y=t[26];let x;t[27]===n.model?x=t[28]:(x=(0,$.jsx)(we,{children:n.model}),t[27]=n.model,t[28]=x);let S;t[29]!==y||t[30]!==x?(S=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[y,x]}),t[29]=y,t[30]=x,t[31]=S):S=t[31];let C;t[32]!==h||t[33]!==n.costShare?(C=h?``:` · ${J(n.costShare)} of cost`,t[32]=h,t[33]=n.costShare,t[34]=C):C=t[34];let w;t[35]!==p.label||t[36]!==C?(w=(0,$.jsxs)(De,{children:[p.label,C]}),t[35]=p.label,t[36]=C,t[37]=w):w=t[37];let T;t[38]!==w||t[39]!==S?(T=(0,$.jsxs)(Ce,{children:[S,w]}),t[38]=w,t[39]=S,t[40]=T):T=t[40];let E;t[41]===_?E=t[42]:(E=(0,$.jsx)(`div`,{className:`grid grid-cols-2 gap-x-6 gap-y-4 sm:grid-cols-4`,children:_.map(Jn)}),t[41]=_,t[42]=E);let D=h?`tokens`:i,O;t[43]!==a.days||t[44]!==a.hours||t[45]!==a.referenceTime||t[46]!==a.resolution||t[47]!==a.timeZone||t[48]!==f||t[49]!==D||t[50]!==u.daily||t[51]!==u.hourly?(O=(0,$.jsx)(jn,{providers:f,days:a.days,daily:u.daily,hours:a.hours,hourly:u.hourly,metric:D,referenceTime:a.referenceTime,resolution:a.resolution,timeZone:a.timeZone}),t[43]=a.days,t[44]=a.hours,t[45]=a.referenceTime,t[46]=a.resolution,t[47]=a.timeZone,t[48]=f,t[49]=D,t[50]=u.daily,t[51]=u.hourly,t[52]=O):O=t[52];let k;t[53]!==h||t[54]!==u.categoryCost?(k=h?null:(0,$.jsx)(Fn,{label:`Cost by type`,segments:Wn(u.categoryCost),format:W}),t[53]=h,t[54]=u.categoryCost,t[55]=k):k=t[55];let A;t[56]===n.tokens?A=t[57]:(A=Gn(n.tokens),t[56]=n.tokens,t[57]=A);let j;t[58]===A?j=t[59]:(j=(0,$.jsx)(Fn,{label:`Tokens by type`,segments:A,format:K}),t[58]=A,t[59]=j);let M;t[60]===u.speedCost?M=t[61]:(M=u.speedCost.fast+u.speedCost.ultrafast>0?(0,$.jsx)(Fn,{label:`Cost by speed`,segments:Kn(u.speedCost),format:W,aside:(0,$.jsx)(Xn,{premiumUsd:u.speedCost.premium})}):null,t[60]=u.speedCost,t[61]=M);let N;t[62]!==k||t[63]!==j||t[64]!==M?(N=(0,$.jsxs)(`div`,{className:`grid gap-x-10 gap-y-8 sm:grid-cols-2`,children:[k,j,M]}),t[62]=k,t[63]=j,t[64]=M,t[65]=N):N=t[65];let ee;t[66]!==E||t[67]!==O||t[68]!==N?(ee=(0,$.jsx)(Ee,{children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-8`,children:[E,O,N]})}),t[66]=E,t[67]=O,t[68]=N,t[69]=ee):ee=t[69];let P;t[70]!==n.unpricedTokens||t[71]!==o?(P=n.unpricedTokens>0?(0,$.jsxs)(Te,{variant:`bare`,className:`items-center sm:justify-between`,children:[(0,$.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[K(n.unpricedTokens),` tokens have no known price`]}),(0,$.jsx)(b,{onClick:o,children:`Set price`})]}):null,t[70]=n.unpricedTokens,t[71]=o,t[72]=P):P=t[72];let F;t[73]!==T||t[74]!==ee||t[75]!==P?(F=(0,$.jsxs)(Oe,{className:`max-w-3xl`,children:[T,ee,P]}),t[73]=T,t[74]=ee,t[75]=P,t[76]=F):F=t[76];let I;return t[77]!==F||t[78]!==v?(I=(0,$.jsx)(ke,{open:!0,onOpenChange:v,children:F}),t[77]=F,t[78]=v,t[79]=I):I=t[79],I}function Jn(e){return(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-0.5`,children:[(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.label}),(0,$.jsx)(`span`,{className:`text-2xl font-semibold text-foreground`,children:e.value})]},e.label)}function Yn(e){return e!==null}function Xn(e){let t=(0,Q.c)(4),{premiumUsd:n}=e,r;t[0]===n?r=t[1]:(r=W(n),t[0]=n,t[1]=r);let i;return t[2]===r?i=t[3]:(i=(0,$.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`Premium `,(0,$.jsx)(`span`,{className:`text-foreground tabular-nums`,children:r})]}),t[2]=r,t[3]=i),i}var Zn=`p4code:usage-page-preferences:v1`,Qn=T({metric:p([`cost`,`tokens`,`limits`]),windowDays:p([1,7,30,90]),hiddenProviders:u(s(k))}),$n={metric:`limits`,windowDays:30};function er(){try{return w(Zn,Qn)??$n}catch(e){return console.error(`Could not read Usage page preferences.`,e),$n}}function tr(e){try{C(Zn,e,Qn)}catch(e){console.error(`Could not save Usage page preferences.`,e)}}function nr(e){return He.some(t=>t.value===e)}function rr(e){return Be.some(t=>t.days===e)}var ir=e=>Ge[e].label;function ar(){let[e,t]=(0,Z.useState)(er);ie();let n=P(se),r=e=>{let t=Me(n,e.command,{context:{usagePageOpen:!0}});return t?`${e.label} (${t})`:e.label},[i,a]=(0,Z.useState)(()=>({days:e.windowDays,window:G(e.windowDays,void 0,e.windowDays===1?`hour`:`day`)})),o=e.metric,s=o===`limits`,[c,l]=(0,Z.useState)(!1),[u,d]=(0,Z.useState)(()=>Date.now()),f=(0,Z.useRef)(!1),[p,m]=(0,Z.useState)(`model`),[h,g]=(0,Z.useState)(null),[_,v]=(0,Z.useState)(null),[y,S]=(0,Z.useState)(null),C=(0,Z.useMemo)(()=>new Set(e.hiddenProviders),[e.hiddenProviders]),{days:w,window:T}=i,E=w===1,{merged:O,environments:k,selectedEnvironments:A,shown:j,isPartial:N,refresh:ee}=Dt(T,y,C),F=j?.merged??O,I=j?.window??T,L=I.resolution===`hour`,R=c&&!s,z=j!==null&&j.window!==T,H=(0,Z.useMemo)(()=>{if(z)return{partial:!0,everyProvider:!0,providers:new Set};let e=ft(A,R),t=new Set([...e.providers].filter(e=>!C.has(e)));return{partial:e.everyProvider||t.size>0,everyProvider:e.everyProvider,providers:t}},[z,R,A,C]),U=e=>H.everyProvider||H.providers.has(e),ue=P(ae.presentationsAtom),me=(0,Z.useMemo)(()=>new Map([...ue].filter(([,e])=>e.entry.enabled&&e.entry.unsupportedReason===void 0)),[ue]),ge=C.has(`cursor`)?[]:at(A),_e=[...new Set(A.flatMap(e=>e.summary?.sources.flatMap(e=>e.message&&!e.action&&!C.has(e.fingerprint.provider)&&(e.status===`partial`||e.status===`failed`||e.fingerprint.provider===`cursor`)?[e.message]:[])??[]))],ve=ce(oe.refreshProviders,{reportFailure:!1}),X=A.some(e=>e.canReadDiagnostics),xe=(0,Z.useMemo)(()=>Y(I.sinceDay,I.untilDay),[I.sinceDay,I.untilDay]),Ce=(0,Z.useMemo)(()=>I.sinceTime===void 0||I.untilTime===void 0?[]:fe(I.sinceTime,I.untilTime),[I.sinceTime,I.untilTime]),we=(0,Z.useMemo)(()=>(L?F.hourly:F.daily).toReversed(),[L,F.daily,F.hourly]),Te=(0,Z.useMemo)(()=>p===`model`&&o===`tokens`?Rn(F.models):F.models,[p,F.models,o]),Ee=(0,Z.useMemo)(()=>We(F.providers),[F.providers]),De=(0,Z.useMemo)(()=>Ye.filter(e=>Ee.includes(e)||H.providers.has(e)),[H.providers,Ee]),Oe=(0,Z.useMemo)(()=>new Set(De.filter(e=>H.everyProvider||H.providers.has(e))),[De,H.everyProvider,H.providers]),ke=_===null?void 0:F.models.find(e=>`${e.provider}:${e.model}`===_),je=Te.reduce((e,t)=>Math.max(e,o===`tokens`?t.totalTokens:t.costUsd),0),Le=De.map(e=>({kind:`usage`,provider:e})),qe=Math.max(De.indexOf(`codex`),De.indexOf(`claude`))+1;Le.splice(qe,0,...ge.map(e=>({kind:`enable`,environment:e})));let Qe=`${60/(De.length+2)}%`,nt=n=>{let r={...e,...n};t(r),tr(r)},Q=e=>{rr(e)&&(nt({windowDays:e}),a({days:e,window:G(e,void 0,e===1?`hour`:`day`)}))},rt=e=>{e===`limits`&&d(Date.now()),nt({metric:e})},it=async(e=!1,t=!1)=>{try{await Promise.all(Array.from(me,([n,r])=>{if((y===null||y.has(n))&&r.connection.phase===`connected`&&r.serverConfig!==null)return ct(n,()=>ve({environmentId:n,input:{}}),e,t)}))}finally{d(Date.now())}},ot=(0,Z.useEffectEvent)(e=>{if(e.defaultPrevented||e.repeat||e.isComposing||Ke()||Je())return;let t=Ve(e,n),r=He.find(e=>e.command===t),i=Be.find(e=>e.command===t);(r||i)&&(e.preventDefault(),e.stopPropagation(),r&&rt(r.value),i&&!s&&Q(i.days))});(0,Z.useEffect)(()=>(globalThis.window.addEventListener(`keydown`,ot,!0),()=>globalThis.window.removeEventListener(`keydown`,ot,!0)),[]);let st=()=>{if(f.current)return;if(s){f.current=!0,l(!0),it().finally(()=>{f.current=!1,l(!1)});return}let e=G(w,void 0,E?`hour`:`day`);(e.sinceDay!==T.sinceDay||e.untilDay!==T.untilDay||e.sinceTime!==T.sinceTime||e.untilTime!==T.untilTime)&&a({days:w,window:e}),f.current=!0,l(!0),ee(e).finally(()=>{f.current=!1,l(!1)})},lt=[...me].filter(([e,t])=>t.connection.phase===`connected`&&t.serverConfig!==null&&(y===null||y.has(e))).map(([e])=>e).sort().join(`,`),ut=(0,Z.useEffectEvent)(()=>{it(!0)});(0,Z.useEffect)(()=>{s&&lt&&ut()},[s,lt]);let dt=L&&I.sinceTime!==void 0&&I.untilTime!==void 0?`${de(I.sinceTime,I.timeZone)} to ${de(I.untilTime,I.timeZone)}`:`${le(I.sinceDay)} to ${le(I.untilDay)}`,mt=(0,$.jsxs)(`div`,{className:`grid w-full min-w-0 grid-cols-[minmax(0,1fr)_auto] items-center gap-x-3 py-2 xl:flex`,children:[(0,$.jsxs)(tt,{ariaLabel:`Usage breadcrumb`,className:`min-w-0`,children:[(0,$.jsx)($e,{children:(0,$.jsx)(`h1`,{children:`Usage`})}),(0,$.jsx)(et,{}),(0,$.jsx)($e,{className:`min-w-10 shrink`,children:(0,$.jsx)(vr,{environments:k,selectedEnvironments:A,selectedEnvironmentIds:y,onSelectionChange:S,showUsageStatus:!s,refreshing:R,isPartial:N,duplicateSources:F.duplicateSources,contractMismatches:F.contractMismatches,onOpenModelPrices:()=>g({})})}),(0,$.jsx)(et,{}),(0,$.jsx)($e,{current:!0,className:`min-w-10`,children:(0,$.jsx)(xr,{hiddenProviders:C,onChange:e=>nt({hiddenProviders:e})})})]}),s?null:(0,$.jsx)(`span`,{className:`hidden min-w-0 truncate text-xs text-muted-foreground 2xl:block`,children:dt}),(0,$.jsxs)(`div`,{className:`ms-auto hidden min-w-0 items-center justify-end gap-2 xl:flex`,children:[(0,$.jsx)(ye,{"aria-label":`Usage metric`,variant:`segmented`,value:[o],onValueChange:e=>{let t=e[0];nr(t)&&rt(t)},children:He.map(e=>(0,$.jsx)(be,{value:e.value,title:r(e),children:e.label},e.value))}),(0,$.jsx)(ye,{"aria-label":`Usage period`,variant:`segmented`,value:[String(w)],disabled:s,onValueChange:e=>{let t=e[0];t&&Q(Number(t))},children:Be.map(e=>(0,$.jsx)(be,{value:String(e.days),title:r(e),children:e.label},e.days))}),(0,$.jsx)(b,{onClick:st,"aria-label":s?`Refresh limits`:`Refresh usage`,"aria-busy":c,disabled:c||!s&&!X,size:`icon-sm`,variant:`ghost`,children:(0,$.jsx)(Xe,{size:`sm`,refreshing:c})})]}),(0,$.jsxs)(`div`,{className:`ms-auto flex min-w-0 items-center justify-end gap-1 xl:hidden`,children:[(0,$.jsxs)(re,{value:o,onValueChange:e=>{nr(e)&&rt(e)},children:[(0,$.jsx)(ne,{"aria-label":`Usage metric`,size:`compact`,variant:`ghost`,className:`w-auto min-w-0`,children:(0,$.jsx)(V,{children:He.find(e=>e.value===o)?.label})}),(0,$.jsx)(te,{align:`end`,alignItemWithTrigger:!1,children:He.map(e=>(0,$.jsx)(B,{value:e.value,title:r(e),children:e.label},e.value))})]}),(0,$.jsxs)(re,{value:String(w),disabled:s,onValueChange:e=>Q(Number(e)),children:[(0,$.jsx)(ne,{"aria-label":`Usage period`,size:`compact`,variant:`ghost`,className:`w-auto min-w-0`,children:(0,$.jsx)(V,{children:Be.find(e=>e.days===w)?.label})}),(0,$.jsx)(te,{align:`end`,alignItemWithTrigger:!1,children:Be.map(e=>(0,$.jsx)(B,{value:String(e.days),title:r(e),children:e.label},e.days))})]}),(0,$.jsx)(b,{onClick:st,"aria-label":s?`Refresh limits`:`Refresh usage`,"aria-busy":c,disabled:c||!s&&!X,size:`icon-sm`,variant:`ghost`,children:(0,$.jsx)(Xe,{size:`sm`,refreshing:c})})]})]});return(0,$.jsxs)(Ae,{className:`h-dvh min-h-0 overflow-hidden overscroll-y-none isolate`,children:[(0,$.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col bg-background text-foreground`,children:[(0,$.jsx)(Ze,{electron:he,children:mt}),(0,$.jsx)(Se,{className:`min-h-0 flex-1`,children:(0,$.jsx)(ze,{width:`wide`,children:A.length===0?(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:k.length===0?`Connect an environment to see ${s?`limits`:`usage`}.`:`Select an environment to see ${s?`limits`:`usage`}.`}):s?(0,$.jsx)(Ue,{selectedEnvironmentIds:y,hiddenProviders:C,now:u,cursorPrompt:ge.length>0?(0,$.jsx)(lr,{environments:ge,onEnabled:()=>{ee(),it(!1,!0)}}):null}):j===null?(0,$.jsx)(Sr,{}):X?(0,$.jsxs)(`div`,{"aria-busy":H.partial,className:`flex flex-col gap-6`,children:[_e.map(e=>(0,$.jsx)(`p`,{className:`mb-4 text-sm text-muted-foreground`,children:e},e)),(0,$.jsxs)(`section`,{className:`grid gap-6 lg:grid-cols-[minmax(0,18rem)_minmax(0,1fr)]`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-5`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`span`,{className:M(`text-4xl font-semibold text-foreground tabular-nums`,dr(H.partial)),children:o===`cost`?W(F.costUsd):K(F.totalTokens)}),(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-xs text-muted-foreground`,children:[(0,$.jsxs)(`span`,{children:[(0,$.jsxs)(`span`,{className:dr(H.partial),children:[q(F.sessions),` sessions`]}),o===`cost`&&` · API estimate`]}),o===`cost`&&F.costQuality.unpricedShare>0&&(0,$.jsxs)(Fe,{children:[(0,$.jsx)(Pe,{openOnHover:!0,render:(0,$.jsx)(x,{tone:`muted`}),"aria-label":`Unpriced usage details`,children:(0,$.jsx)(D,{className:`size-3`,"aria-hidden":!0})}),(0,$.jsxs)(Ne,{side:`top`,tooltipStyle:!0,children:[`API estimate excludes`,` `,J(F.costQuality.unpricedShare),` unpriced records.`]})]})]})]}),!C.has(`codex`)&&[...me].some(([e,t])=>(y===null||y.has(e))&&t.serverConfig?.providers.some(Ie))?(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 text-xs text-muted-foreground`,children:[(0,$.jsx)(`span`,{children:`ChatGPT shared usage`}),(0,$.jsx)(Re,{size:`xs`})]}):null,Le.map(e=>{if(e.kind===`enable`)return(0,$.jsx)(cr,{environmentId:e.environment.environmentId,label:e.environment.label,showEnvironment:A.length>1,onEnabled:()=>{ee(),it(!1,!0)}},`enable:${e.environment.environmentId}`);let t=e.provider,n=F.providers.find(e=>e.provider===t),r=o===`cost`?n?.costShare??0:n?.tokenShare??0,i=n?.sessions??0,a=`${q(i)} ${i===1?`session`:`sessions`}`,s=U(t),c=s&&!Ee.includes(t);return(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsxs)(`div`,{className:`flex items-baseline justify-between gap-4`,children:[(0,$.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2 text-sm text-foreground`,children:[(0,$.jsx)(`span`,{"aria-hidden":!0,className:`size-2 shrink-0 rounded-full`,style:{backgroundColor:Ge[t].color}}),(0,$.jsx)(ur,{provider:t,className:`size-4`}),(0,$.jsxs)(`span`,{className:`flex min-w-0 items-baseline gap-1.5`,children:[(0,$.jsx)(`span`,{className:`truncate`,children:Ge[t].label}),(0,$.jsx)(`span`,{className:M(`shrink-0 whitespace-nowrap text-2xs text-muted-foreground tabular-nums`,dr(s),c&&`invisible`),children:a})]})]}),(0,$.jsx)(`span`,{className:M(`shrink-0 text-sm font-medium text-foreground tabular-nums`,dr(s)),children:c?`—`:o===`cost`?W(n?.costUsd??0):K(n?.totalTokens??0)})]}),(0,$.jsx)(`span`,{className:M(`text-xs text-muted-foreground`,dr(s),c&&`invisible`),children:o===`cost`?`${J(r)} of cost · ${K(n?.totalTokens??0)} tokens`:`${J(r)} of tokens · ${W(n?.costUsd??0)}`})]},t)})]}),(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3`,children:[(0,$.jsxs)(`h2`,{className:`text-sm font-medium text-foreground`,children:[L?`Hourly`:`Daily`,` `,o===`tokens`?`processed tokens`:`cost`]}),(0,$.jsx)(jn,{providers:De,loadingProviders:Oe,days:xe,daily:F.daily,hours:Ce,hourly:F.hourly,metric:o,referenceTime:I.untilTime,resolution:L?`hour`:`day`,timeZone:I.timeZone})]})]}),(0,$.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[(0,$.jsx)(`h2`,{className:`text-sm font-medium text-foreground`,children:`Totals`}),(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-6 gap-y-4 py-1 md:grid-cols-5`,children:[(0,$.jsx)(fr,{loading:H.partial,label:`Processed tokens`,value:K(F.totalTokens)}),(0,$.jsx)(fr,{loading:H.partial,label:`Cached input`,value:K(F.cachedInputTokens)}),(0,$.jsx)(fr,{loading:H.partial,label:`Uncached input`,value:K(F.uncachedInputTokens)}),(0,$.jsx)(fr,{loading:H.partial,label:`Output`,value:K(F.outputTokens)}),(0,$.jsx)(fr,{loading:H.partial,label:`Cache savings`,value:W(F.costQuality.cacheSavingsUsd)})]})]}),F.totalTokens>0?(0,$.jsx)(`section`,{className:M(`grid gap-x-12 gap-y-8 lg:grid-cols-2`,dr(H.partial)),children:o===`tokens`?(0,$.jsx)(Fn,{label:`Tokens by type`,segments:Gn(F),format:K}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Fn,{label:`Cost by type`,segments:Wn(F.categoryCost),format:W}),F.speedCost.fast+F.speedCost.ultrafast>0?(0,$.jsx)(Fn,{label:`Cost by speed`,segments:Kn(F.speedCost),format:W,aside:(0,$.jsx)(Xn,{premiumUsd:F.speedCost.premium})}):null]})}):null,(0,$.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsx)(`h2`,{className:`text-sm font-medium text-foreground`,children:`Breakdown`}),(0,$.jsx)(ye,{"aria-label":`Usage breakdown`,variant:`segmented`,value:[p],onValueChange:e=>{let t=e[0];(t===`model`||t===`time`)&&m(t)},children:[{value:`model`,label:`Model`},{value:`time`,label:L?`Hour`:`Day`}].map(e=>(0,$.jsx)(be,{value:e.value,children:e.label},e.value))})]}),p===`model`?(0,$.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{className:`border-b border-border text-right text-xs text-muted-foreground`,children:[(0,$.jsx)(`th`,{className:`py-2 pr-3 text-left font-normal`,children:`#`}),(0,$.jsx)(`th`,{className:`w-full py-2 text-left font-normal`,children:`Model`}),(0,$.jsx)(`th`,{className:`py-2 pl-6 font-normal`,children:`Cost`}),(0,$.jsx)(`th`,{className:`hidden py-2 pl-6 font-normal sm:table-cell`,children:`Share`}),(0,$.jsx)(`th`,{className:`py-2 pl-6 font-normal`,children:`Tokens`})]})}),(0,$.jsx)(`tbody`,{children:Te.length===0?(0,$.jsx)(`tr`,{children:(0,$.jsx)(`td`,{colSpan:5,className:`py-6 text-center text-muted-foreground`,children:`No activity in this window.`})}):Te.map((e,t)=>{let n=`${e.provider}:${e.model}`,r=o===`tokens`?e.totalTokens:e.costUsd,i=zn(e,o===`tokens`?`tokens`:`cost`),a=dr(U(e.provider));return(0,$.jsxs)(`tr`,{className:`relative border-b border-border/50 text-right whitespace-nowrap text-muted-foreground tabular-nums transition-colors hover:bg-muted/50 has-focus-visible:bg-muted/50`,children:[(0,$.jsx)(`td`,{className:`py-2.5 pr-3 text-left text-xs`,children:t+1}),(0,$.jsxs)(`td`,{className:`py-2.5 text-left whitespace-normal`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>v(n),className:`flex items-center gap-2 text-left text-foreground outline-none after:absolute after:inset-0`,children:[(0,$.jsx)(ur,{provider:e.provider,className:`size-3.5`}),e.model]}),(0,$.jsx)(`div`,{"aria-hidden":!0,className:M(`mt-1.5 h-0.5 max-w-48`,a),children:(0,$.jsx)(`div`,{className:`h-full rounded-full`,style:{width:r>0&&je>0?`max(0.5rem, ${r/je*100}%)`:0,backgroundColor:Ge[e.provider].color}})})]}),(0,$.jsx)(`td`,{className:M(`py-2.5 pl-6 text-foreground`,a),children:pt(e)?(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:`Unpriced`}):W(e.costUsd)}),(0,$.jsx)(`td`,{className:M(`hidden py-2.5 pl-6 sm:table-cell`,a),children:i===null?``:J(i)}),(0,$.jsx)(`td`,{className:M(`py-2.5 pl-6`,a),children:K(e.totalTokens)})]},n)})})]}):(0,$.jsxs)(`table`,{className:`w-full table-fixed text-sm`,children:[(0,$.jsxs)(`colgroup`,{children:[(0,$.jsx)(`col`,{className:`w-2/5`}),De.map(e=>(0,$.jsx)(`col`,{style:{width:Qe}},e)),(0,$.jsx)(`col`,{style:{width:Qe}}),(0,$.jsx)(`col`,{style:{width:Qe}})]}),(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{className:`border-b border-border text-left text-xs text-muted-foreground`,children:[(0,$.jsx)(`th`,{className:`py-2 font-normal`,children:L?`Hour`:`Day`}),De.map(e=>(0,$.jsx)(`th`,{className:`py-2 text-right font-normal`,children:Ge[e].label},e)),(0,$.jsx)(`th`,{className:`py-2 text-right font-normal`,children:`Total`}),(0,$.jsx)(`th`,{className:`py-2 text-right font-normal`,children:`Tokens`})]})}),(0,$.jsx)(`tbody`,{children:we.length===0?(0,$.jsx)(`tr`,{children:(0,$.jsx)(`td`,{colSpan:De.length+3,className:`py-6 text-center text-muted-foreground`,children:`No activity in this window.`})}):we.map(e=>(0,$.jsxs)(`tr`,{className:`border-b border-border/50 transition-colors hover:bg-muted/50`,children:[(0,$.jsx)(`td`,{className:`py-2 text-foreground`,children:`hourStart`in e?pe(e.hourStart,I.timeZone):le(e.day)}),De.map(t=>(0,$.jsx)(`td`,{className:M(`py-2 text-right text-muted-foreground tabular-nums`,dr(U(t))),children:W(e.byProvider.get(t)?.costUsd??0)},t)),(0,$.jsx)(`td`,{className:M(`py-2 text-right text-foreground tabular-nums`,dr(H.partial)),children:W(e.costUsd)}),(0,$.jsx)(`td`,{className:M(`py-2 text-right text-muted-foreground tabular-nums`,dr(H.partial)),children:K(e.totalTokens)})]},`hourStart`in e?e.hourStart:e.day))})]})]})]}):(0,$.jsx)(`div`,{className:`space-y-2 py-12 text-center text-sm text-muted-foreground`,children:A.map(e=>(0,$.jsxs)(`p`,{children:[A.length>1?`${e.label}: `:null,e.error]},e.environmentId))})})})]}),ke!==void 0&&!s?(0,$.jsx)(qn,{model:ke,environments:A,metric:o===`tokens`?`tokens`:`cost`,chartWindow:{days:xe,hours:Ce,resolution:L?`hour`:`day`,timeZone:I.timeZone,referenceTime:I.untilTime},onSetPrice:()=>{v(null),g({model:ke.model})},onClose:()=>v(null)}):null,h?(0,$.jsx)(Xt,{usage:k,initialSelectedEnvironmentIds:y,initialModel:h.model,onOpenChange:e=>{e||g(null)}}):null]})}var or=`Requires access to your Cursor login in macOS Keychain.`;function sr({environmentId:e,label:t,onEnabled:n,tooltip:r,buttonText:i=`Enable`}){let a=ce(oe.updateSettings,{label:`enable Cursor account usage`}),[o,s]=(0,Z.useState)(!1),c=async()=>{s(!0);try{(await a({environmentId:e,input:{patch:{cursorKeychainUsageEnabled:!0}}}))._tag===`Success`&&n()}finally{s(!1)}},l=r?(0,$.jsx)(x,{disabled:o,"aria-busy":o,"aria-label":`Enable Cursor usage from ${t}`,onClick:()=>void c(),children:i}):(0,$.jsx)(b,{size:`sm`,variant:`outline`,disabled:o,"aria-busy":o,"aria-label":`Enable Cursor usage from ${t}`,onClick:()=>void c(),children:i});return r?(0,$.jsxs)(ve,{children:[(0,$.jsx)(ge,{render:l}),(0,$.jsx)(_e,{children:or})]}):l}function cr(e){let t=(0,Q.c)(11),{environmentId:n,label:r,showEnvironment:i,onEnabled:a}=e,o,s;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,$.jsx)(`span`,{"aria-hidden":!0,className:`size-2 shrink-0 rounded-full`,style:{backgroundColor:Ge.cursor.color}}),s=(0,$.jsx)(ur,{provider:`cursor`,className:`size-4`}),t[0]=o,t[1]=s):(o=t[0],s=t[1]);let c=i?` · ${r}`:``,l;t[2]===c?l=t[3]:(l=(0,$.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2 text-sm text-foreground`,children:[o,s,(0,$.jsxs)(`span`,{className:`truncate`,children:[`Cursor`,c]})]}),t[2]=c,t[3]=l);let u;t[4]!==n||t[5]!==r||t[6]!==a?(u=(0,$.jsx)(sr,{environmentId:n,label:r,onEnabled:a,tooltip:!0}),t[4]=n,t[5]=r,t[6]=a,t[7]=u):u=t[7];let d;return t[8]!==l||t[9]!==u?(d=(0,$.jsxs)(`div`,{className:`flex min-w-0 items-baseline justify-between gap-4 text-sm`,children:[l,u]}),t[8]=l,t[9]=u,t[10]=d):d=t[10],d}function lr(e){let t=(0,Q.c)(10),{environments:n,onEnabled:r}=e,i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,$.jsxs)(`h2`,{className:`flex items-center gap-2 text-sm font-medium text-foreground`,children:[(0,$.jsx)(Le,{driverKind:l.make(`cursor`),displayName:`Cursor`,indicatorBackground:`var(--background)`,className:`size-5`,iconClassName:`size-4 text-foreground/80`}),`Cursor`]}),t[0]=i):i=t[0];let a;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:or}),t[1]=a):a=t[1];let o;if(t[2]!==n||t[3]!==r){let e;t[5]!==n.length||t[6]!==r?(e=e=>(0,$.jsx)(sr,{environmentId:e.environmentId,label:e.label,buttonText:n.length>1?`Enable on ${e.label}`:`Enable`,onEnabled:r,tooltip:!1},e.environmentId),t[5]=n.length,t[6]=r,t[7]=e):e=t[7],o=n.map(e),t[2]=n,t[3]=r,t[4]=o}else o=t[4];let s;return t[8]===o?s=t[9]:(s=(0,$.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[i,(0,$.jsxs)(`div`,{className:`flex flex-col items-start gap-3 rounded-lg border border-border/60 p-4`,children:[a,(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:o})]})]}),t[8]=o,t[9]=s),s}function ur(e){let t=(0,Q.c)(4),{provider:n,className:r}=e,i=Ge[n],a;return t[0]!==r||t[1]!==i.driverKind||t[2]!==i.label?(a=(0,$.jsx)(Le,{driverKind:i.driverKind,displayName:i.label,iconClassName:r}),t[0]=r,t[1]=i.driverKind,t[2]=i.label,t[3]=a):a=t[3],a}function dr(e){return M(`transition-opacity`,e&&`opacity-40 delay-150`)}function fr(e){let t=(0,Q.c)(10),{label:n,value:r,loading:i}=e,a;t[0]===n?a=t[1]:(a=(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:n}),t[0]=n,t[1]=a);let o;t[2]===i?o=t[3]:(o=M(`text-base font-medium text-foreground tabular-nums`,dr(i)),t[2]=i,t[3]=o);let s;t[4]!==o||t[5]!==r?(s=(0,$.jsx)(`span`,{className:o,children:r}),t[4]=o,t[5]=r,t[6]=s):s=t[6];let c;return t[7]!==a||t[8]!==s?(c=(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-0.5`,children:[a,s]}),t[7]=a,t[8]=s,t[9]=c):c=t[9],c}function pr(e){let t=(0,Q.c)(14),{environments:n,duplicateSources:r,contractMismatches:i}=e,a,o,s,c;if(t[0]!==i||t[1]!==r||t[2]!==n){c=Symbol.for(`react.early_return_sentinel`);bb0:{let e=n.filter(_r),t=new Map(i.map(gr)),l=n.flatMap(e=>{let n=t.get(e.environmentId);return n===void 0?[]:[{environment:e,mismatch:n}]});if(e.length===0&&l.length===0&&r.length===0){c=null;break bb0}a=`flex flex-col gap-1 border-t border-border px-2 py-2 text-xs text-muted-foreground`,o=e.map(hr),s=l.map(mr)}t[0]=i,t[1]=r,t[2]=n,t[3]=a,t[4]=o,t[5]=s,t[6]=c}else a=t[3],o=t[4],s=t[5],c=t[6];if(c!==Symbol.for(`react.early_return_sentinel`))return c;let l;t[7]===r?l=t[8]:(l=r.length>0?(0,$.jsxs)(`span`,{children:[`Counted once across environments sharing a transcript directory:`,` `,r.join(`, `)]}):null,t[7]=r,t[8]=l);let u;return t[9]!==a||t[10]!==o||t[11]!==s||t[12]!==l?(u=(0,$.jsxs)(`div`,{className:a,children:[o,s,l]}),t[9]=a,t[10]=o,t[11]=s,t[12]=l,t[13]=u):u=t[13],u}function mr(e){let{environment:t,mismatch:n}=e;return(0,$.jsx)(`span`,{children:me(t.label,n)},t.environmentId)}function hr(e){return(0,$.jsxs)(`span`,{children:[e.label,`: `,e.error]},e.label)}function gr(e){return[e.environmentId,e]}function _r(e){return e.error!==null}function vr(e){let t=(0,Q.c)(56),{environments:n,selectedEnvironments:r,selectedEnvironmentIds:o,onSelectionChange:s,showUsageStatus:l,refreshing:u,isPartial:d,duplicateSources:p,contractMismatches:h,onOpenModelPrices:g}=e,y=o===null,b=y?`All environments`:r.length===1?r[0].label:`${r.length} environments`,S;t[0]!==h||t[1]!==r?(S=r.some(br)||h.length>0,t[0]=h,t[1]=r,t[2]=S):S=t[2];let C=S,w;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(w=(0,$.jsx)(x,{}),t[3]=w):w=t[3];let T;t[4]===b?T=t[5]:(T=(0,$.jsx)(Qe,{children:b}),t[4]=b,t[5]=T);let E;t[6]!==C||t[7]!==l?(E=(0,$.jsx)(`span`,{className:`flex size-3.5 shrink-0 items-center justify-center text-muted-foreground`,children:l&&C?(0,$.jsx)(c,{className:`size-3.5 text-warning-foreground`,"aria-label":`Some environments could not report usage`}):(0,$.jsx)(a,{className:`size-3.5 opacity-0 transition-opacity group-hover/usage-environment:opacity-100 group-focus-visible/usage-environment:opacity-100 group-data-popup-open/usage-environment:opacity-100`,"aria-hidden":!0})}),t[6]=C,t[7]=l,t[8]=E):E=t[8];let D;t[9]!==T||t[10]!==E?(D=(0,$.jsxs)(F,{render:w,className:`group/usage-environment min-w-0 max-w-full`,children:[T,E]}),t[9]=T,t[10]=E,t[11]=D):D=t[11];let O;t[12]===s?O=t[13]:(O=e=>s(e?null:new Set),t[12]=s,t[13]=O);let k;t[14]!==y||t[15]!==O?(k=(0,$.jsx)(f,{checked:y,closeOnClick:!1,onCheckedChange:O,children:`All environments`}),t[14]=y,t[15]=O,t[16]=k):k=t[16];let A;t[17]===Symbol.for(`react.memo_cache_sentinel`)?(A=(0,$.jsx)(v,{}),t[17]=A):A=t[17];let j;if(t[18]!==n||t[19]!==s||t[20]!==u||t[21]!==o||t[22]!==r||t[23]!==l){let e;t[25]!==n.length||t[26]!==s||t[27]!==u||t[28]!==o||t[29]!==r||t[30]!==l?(e=e=>{let t=o===null||o.has(e.environmentId),i=ut(e,u),a=e.error===null?e.summary!==null&&!bt(e.summary.contractVersion,6)?`Update required`:e.isConnected?i.phase===`loading`?`Scanning…`:i.phase===`stale`?`Refreshing…`:i.phase===`partway`?dt(i.providers,ir):`Ready`:`Connecting…`:`Unavailable`;return(0,$.jsx)(f,{checked:t,closeOnClick:!1,onCheckedChange:t=>{let i=new Set(r.map(yr));t?i.add(e.environmentId):i.delete(e.environmentId),s(i.size===n.length?null:i)},children:(0,$.jsxs)(`span`,{className:`flex min-w-0 items-center gap-3`,children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.label}),l?(0,$.jsx)(`span`,{className:M(`shrink-0 text-xs text-muted-foreground`,e.error!==null&&`text-destructive`),children:a}):null]})},e.environmentId)},t[25]=n.length,t[26]=s,t[27]=u,t[28]=o,t[29]=r,t[30]=l,t[31]=e):e=t[31],j=n.map(e),t[18]=n,t[19]=s,t[20]=u,t[21]=o,t[22]=r,t[23]=l,t[24]=j}else j=t[24];let N;t[32]===n.length?N=t[33]:(N=n.length===0?(0,$.jsx)(`p`,{className:`px-2 py-2 text-xs text-muted-foreground`,children:`No environments connected.`}):null,t[32]=n.length,t[33]=N);let P;t[34]!==d||t[35]!==l?(P=l&&d?(0,$.jsx)(`p`,{className:`px-2 py-2 text-xs text-muted-foreground`,children:`Totals are partial while selected environments scan.`}):null,t[34]=d,t[35]=l,t[36]=P):P=t[36];let I;t[37]!==h||t[38]!==p||t[39]!==r||t[40]!==l?(I=l?(0,$.jsx)(pr,{environments:r,duplicateSources:p,contractMismatches:h}):null,t[37]=h,t[38]=p,t[39]=r,t[40]=l,t[41]=I):I=t[41];let L;t[42]===Symbol.for(`react.memo_cache_sentinel`)?(L=(0,$.jsx)(v,{}),t[42]=L):L=t[42];let R;t[43]===Symbol.for(`react.memo_cache_sentinel`)?(R=(0,$.jsx)(_,{"aria-hidden":!0}),t[43]=R):R=t[43];let z;t[44]===g?z=t[45]:(z=(0,$.jsxs)(i,{onClick:g,children:[R,`Model prices`]}),t[44]=g,t[45]=z);let B;t[46]!==N||t[47]!==P||t[48]!==I||t[49]!==z||t[50]!==k||t[51]!==j?(B=(0,$.jsxs)(ee,{align:`start`,children:[k,A,j,N,P,I,L,z]}),t[46]=N,t[47]=P,t[48]=I,t[49]=z,t[50]=k,t[51]=j,t[52]=B):B=t[52];let V;return t[53]!==B||t[54]!==D?(V=(0,$.jsxs)(m,{children:[D,B]}),t[53]=B,t[54]=D,t[55]=V):V=t[55],V}function yr(e){return e.environmentId}function br(e){return e.error!==null}function xr(e){let t=(0,Q.c)(23),{hiddenProviders:n,onChange:r}=e,i;t[0]===n?i=t[1]:(i=Ye.filter(e=>!n.has(e)),t[0]=n,t[1]=i);let o=i,s=o.length===Ye.length?`All providers`:o.length===0?`No providers`:o.length===1?Ge[o[0]].label:`${o.length} providers`,c;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,$.jsx)(x,{}),t[2]=c):c=t[2];let l;t[3]===s?l=t[4]:(l=(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:s}),t[3]=s,t[4]=l);let u;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,$.jsx)(a,{className:`size-3.5 shrink-0 text-muted-foreground opacity-0 transition-opacity group-hover/usage-provider:opacity-100 group-focus-visible/usage-provider:opacity-100 group-data-popup-open/usage-provider:opacity-100`,"aria-hidden":!0}),t[5]=u):u=t[5];let d;t[6]===l?d=t[7]:(d=(0,$.jsxs)(F,{render:c,className:`group/usage-provider min-w-0 max-w-full`,children:[l,u]}),t[6]=l,t[7]=d);let p=n.size===0,h;t[8]===r?h=t[9]:(h=e=>r(e?[]:Ye),t[8]=r,t[9]=h);let g;t[10]!==p||t[11]!==h?(g=(0,$.jsx)(f,{checked:p,closeOnClick:!1,onCheckedChange:h,children:`All providers`}),t[10]=p,t[11]=h,t[12]=g):g=t[12];let _;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,$.jsx)(v,{}),t[13]=_):_=t[13];let y;t[14]!==n||t[15]!==r?(y=Ye.map(e=>(0,$.jsx)(f,{checked:!n.has(e),closeOnClick:!1,onCheckedChange:t=>r(Ye.filter(r=>r===e?!t:n.has(r))),children:(0,$.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,$.jsx)(ur,{provider:e,className:`size-3.5`}),(0,$.jsx)(`span`,{className:`truncate`,children:Ge[e].label})]})},e)),t[14]=n,t[15]=r,t[16]=y):y=t[16];let b;t[17]!==y||t[18]!==g?(b=(0,$.jsxs)(ee,{align:`start`,children:[g,_,y]}),t[17]=y,t[18]=g,t[19]=b):b=t[19];let S;return t[20]!==b||t[21]!==d?(S=(0,$.jsxs)(m,{children:[d,b]}),t[20]=b,t[21]=d,t[22]=S):S=t[22],S}function Sr(){let e=(0,Q.c)(7),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(X,{className:`h-10 w-36`}),(0,$.jsx)(X,{className:`h-4 w-32`})]}),Ye.map(Cr)]}),e[0]=t):t=e[0];let n;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,$.jsx)(X,{className:`h-5 w-24`}),e[1]=n):n=e[1];let r;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,$.jsxs)(`section`,{className:`grid gap-6 lg:grid-cols-[minmax(0,18rem)_minmax(0,1fr)]`,children:[t,(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[n,(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(X,{className:`ml-16 h-56`}),(0,$.jsx)(X,{className:`ml-16 h-4`})]})]})]}),e[2]=r):r=e[2];let i;e[3]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,$.jsx)(`h2`,{className:`text-sm font-medium text-foreground`,children:`Totals`}),e[3]=i):i=e[3];let a;e[4]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,$.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[i,(0,$.jsx)(wr,{labels:[`Processed tokens`,`Cached input`,`Uncached input`,`Output`,`Cache savings`]})]}),e[4]=a):a=e[4];let o;e[5]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,$.jsx)(`section`,{className:`grid gap-x-12 gap-y-8 lg:grid-cols-2`,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-2.5`,children:[(0,$.jsx)(X,{className:`h-5 w-28`}),(0,$.jsx)(X,{className:`h-2`}),(0,$.jsx)(X,{className:`h-4 w-72`})]})}),e[5]=o):o=e[5];let s;return e[6]===Symbol.for(`react.memo_cache_sentinel`)?(s=(0,$.jsxs)($.Fragment,{children:[r,a,o,(0,$.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsx)(`h2`,{className:`text-sm font-medium text-foreground`,children:`Breakdown`}),(0,$.jsx)(X,{shape:`card`,className:`h-7 w-28`})]}),(0,$.jsx)(X,{className:`h-44`})]})]}),e[6]=s):s=e[6],s}function Cr(e){return(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsxs)(`div`,{className:`flex min-h-5 items-center justify-between gap-4`,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(X,{shape:`pill`,className:`size-2 shrink-0`}),(0,$.jsx)(X,{shape:`pill`,className:`size-4 shrink-0`}),(0,$.jsx)(X,{className:`h-3.5 w-20`})]}),(0,$.jsx)(X,{className:`h-3.5 w-14`})]}),(0,$.jsx)(X,{className:`h-4 w-36`})]},e)}function wr(e){let t=(0,Q.c)(4),{labels:n}=e,r;t[0]===n?r=t[1]:(r=n.map(Tr),t[0]=n,t[1]=r);let i;return t[2]===r?i=t[3]:(i=(0,$.jsx)(`div`,{className:`grid grid-cols-2 gap-x-6 gap-y-4 py-1 md:grid-cols-5`,children:r}),t[2]=r,t[3]=i),i}function Tr(e){return(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e}),(0,$.jsx)(X,{className:`h-6 w-16`})]},e)}var Er=ar;export{Er as component};
2
+ //# sourceMappingURL=usage-BDFFNkIV.js.map
@@ -1,2 +1,2 @@
1
- import{a as e,t}from"./react-DH3P2YXY.js";import{n}from"./jsx-runtime-BnjsACtP.js";import{ns as r}from"./utils-CBe1bHL7.js";import{B as i}from"./runtime-CeFhsGnm.js";var a=n(),o=e(t(),1);function s(e,t){let n=(0,a.c)(6),s=(0,o.useContext)(r),c=typeof t==`string`?t:t?.label??e.label,l=typeof t==`string`?!0:t?.reportFailure??!0,u=typeof t==`string`?!0:t?.reportDefect??!0,d;return n[0]!==e||n[1]!==c||n[2]!==s||n[3]!==u||n[4]!==l?(d=t=>i(s,e,t,{label:c,reportFailure:l,reportDefect:u}),n[0]=e,n[1]=c,n[2]=s,n[3]=u,n[4]=l,n[5]=d):d=n[5],d}export{s as t};
2
- //# sourceMappingURL=use-atom-command-Bt7x9oO0.js.map
1
+ import{a as e,t}from"./react-DH3P2YXY.js";import{n}from"./jsx-runtime-BnjsACtP.js";import{ns as r}from"./utils-CBe1bHL7.js";import{B as i}from"./runtime-CABaKt1A.js";var a=n(),o=e(t(),1);function s(e,t){let n=(0,a.c)(6),s=(0,o.useContext)(r),c=typeof t==`string`?t:t?.label??e.label,l=typeof t==`string`?!0:t?.reportFailure??!0,u=typeof t==`string`?!0:t?.reportDefect??!0,d;return n[0]!==e||n[1]!==c||n[2]!==s||n[3]!==u||n[4]!==l?(d=t=>i(s,e,t,{label:c,reportFailure:l,reportDefect:u}),n[0]=e,n[1]=c,n[2]=s,n[3]=u,n[4]=l,n[5]=d):d=n[5],d}export{s as t};
2
+ //# sourceMappingURL=use-atom-command-C4y634Qy.js.map
@@ -1,2 +1,2 @@
1
- import{a as e,t}from"./react-DH3P2YXY.js";import{n}from"./jsx-runtime-BnjsACtP.js";import{$s as r,C as i,D as a,Oh as o,Qs as s,Zo as c,Zs as l,c as u,cl as d,g as f,i as p,s as m,ts as h}from"./utils-CBe1bHL7.js";import{L as g,R as _}from"./runtime-CeFhsGnm.js";import{d as ee,f as te,k as v,m as ne,p as y,w as b}from"./entities-eRiwvW2F.js";import{in as x,it as S,pn as C}from"./runtime-BOlBBevr.js";import{a as w,t as T}from"./useParams-C5D_t-0u.js";import{d as E}from"./toast-C61oyZY1.js";import{s as D}from"./useSettings-VTow9ZEM.js";import{n as O}from"./server-DvWrfyUO.js";import{p as re}from"./session-logic-OeNFZd_V.js";import{a as k,i as A,n as j,o as M}from"./threadSort-Bd2rijEy.js";import{c as N,r as P}from"./projectFilesQueryState-D4FdR3Xm.js";import{d as F,f as ie,i as ae,r as oe,s as se,t as I}from"./p4ProjectFile-BVKW5TIA.js";import{r as L,t as R}from"./uiStateStore-DL8OsPjd.js";var z=e(t(),1),B=n(),V=`[data-thread-item], [data-thread-selection-safe]`,H=3,U=160;function W(e){let t=(0,B.c)(6),[n,r]=z.useState(null),[i,a]=z.useState(e),o,s;t[0]!==e||t[1]!==n?(o=()=>{if(e){a(!0);return}if(n===null)return;if(typeof IntersectionObserver>`u`){a(!0);return}let t=n.closest(`[data-slot="scroll-area-viewport"]`),r=new IntersectionObserver(e=>{let[t]=e;return a(t?.isIntersecting===!0)},{root:t,rootMargin:`${U}px 0px`});return r.observe(n),()=>r.disconnect()},s=[e,n],t[0]=e,t[1]=n,t[2]=o,t[3]=s):(o=t[2],s=t[3]),z.useEffect(o,s);let c=e||i,l;return t[4]===c?l=t[5]:(l={leaseLiveStatus:c,rowRef:r},t[4]=c,t[5]=l),l}function G(e,t){let n=z.useRef(null);return e!==null&&t!==null&&(n.current={key:e,value:t}),t===null?e!==null&&n.current?.key===e?n.current.value:null:t}function K(e,t,n,r){let i=e.indexOf(t),a=e.indexOf(n);return i===-1||a===-1?[]:e.slice(Math.min(i,a),Math.max(i,a)+1).filter(r)}async function q(e){let t=new Set,n=null;for(let r of e.entries){let i=await e.delete(r,t);if(i!==null){if(i._tag===`Failure`){if(_(i))break;n??=i;continue}t.add(r.threadKey)}}return{deletedThreadKeys:t,firstFailure:n}}async function J(e){let t=[],n=[];for(let r of e.entries){let i=!1,a=await e.archive(r,()=>{i=!0});if((i||a._tag===`Success`)&&t.push(r.threadKey),a._tag===`Success`)continue;let o=a;if(i){n.push(o);continue}return{archivedThreadKeys:t,mutationFailure:o,followupFailures:n}}return{archivedThreadKeys:t,mutationFailure:null,followupFailures:n}}function Y(e){return[{id:`mark-unread`,label:`Mark unread (${e.count})`},{id:`archive`,label:`Archive (${e.count})`,disabled:e.hasRunningThread},{id:`delete`,label:`Delete (${e.count})`,destructive:!0}]}function X(e){return e.lineage.relationshipToParent===`subagent`}function ce(e,t){let n=S(e);return e.filter(e=>e.archivedAt===null&&!X(e)&&n(e)&&(t===null||t.has(`${e.environmentId}:${e.projectId}`)))}var le={"Pending Approval":5,"Awaiting Input":4,Working:3,Connecting:3,Waiting:2.5,"Plan Ready":2,Completed:1};function ue(e){let t=e.setTimeoutFn??globalThis.setTimeout,n=e.clearTimeoutFn??globalThis.clearTimeout,r=!1,i=null,a=()=>{i!==null&&(n(i),i=null)};return{sync:n=>{if(!n){a(),r&&(r=!1,e.onVisibilityChange(!1));return}r||i!==null||(i=t(()=>{i=null,r=!0,e.onVisibilityChange(!0)},e.delayMs))},dispose:()=>{a()}}}function de(){let e=(0,B.c)(5),[t,n]=z.useState(!1),r=z.useRef(null),i,a;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=()=>{let e=ue({delayMs:200,onVisibilityChange:e=>{n(e)},setTimeoutFn:window.setTimeout.bind(window),clearTimeoutFn:window.clearTimeout.bind(window)});return r.current=e,()=>{e.dispose(),r.current=null}},a=[],e[0]=i,e[1]=a):(i=e[0],a=e[1]),z.useEffect(i,a);let o;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(o=e=>{r.current?.sync(e)},e[2]=o):o=e[2];let s=o,c;return e[3]===t?c=e[4]:(c={showThreadJumpHints:t,updateThreadJumpHintsVisibility:s},e[3]=t,e[4]=c),c}function fe(e,t){return e===void 0?t:e??void 0}function pe(e){if(!e.latestRun?.completedAt)return!1;let t=Date.parse(e.latestRun.completedAt);if(Number.isNaN(t)||!e.lastVisitedAt)return!1;let n=Date.parse(e.lastVisitedAt);return Number.isNaN(n)?!0:t>n}function me(e){return e===null||!e.closest(V)}function he(e){return e>1}function ge(e,t){return e===null||!(`closest`in e)||typeof e.closest!=`function`?null:e.closest(t)}function _e(e){return typeof e!=`object`||!e?!1:ge(e,`a[href]`)!==null||ge(`parentElement`in e&&e.parentElement!==null&&typeof e.parentElement==`object`?e.parentElement:null,`a[href]`)!==null}function ve(e){let{getId:t,getPreferenceIds:n,items:r,preferredIds:i}=e;if(i.length===0)return[...r];let a=new Map;for(let[e,i]of r.entries()){let r=n?.(i)??[t(i)];for(let t of new Set(r)){let n=a.get(t);n?n.push(e):a.set(t,[e])}}let o=new Set,s=i.flatMap(e=>{let t=a.get(e)?.find(e=>!o.has(e));return t===void 0?[]:(o.add(t),[r[t]])}),c=r.filter((e,t)=>!o.has(t));return[...s,...c]}function ye(e,t=H){return e.slice(0,Math.max(0,t))}function be(e){let{currentThreadId:t,direction:n,threadIds:r}=e;if(r.length===0)return null;if(t===null)return n===`previous`?r.at(-1)??null:r[0]??null;let i=r.indexOf(t);return i===-1?null:n===`previous`?i>0?r[i-1]??null:null:i<r.length-1?r[i+1]??null:null}function xe(e){return e.button===2||e.isMac&&e.button===0&&e.ctrlKey}function Se(e){return e.hasPendingApprovals||e.pendingSubagentRequest===`approval`?`approval`:e.hasPendingUserInput||e.pendingSubagentRequest===`user_input`?`input`:e.runtime!==null&&[`preparing`,`queued`,`starting`,`running`,`waiting`].includes(e.runtime.status)?`working`:e.runtime?.status===`idle`?`waiting`:e.runtime?.status===`failed`?e.runtime.lastErrorClass===`usage_limit`?`limited`:`failed`:`ready`}function Ce(e,t){let n=k(e,t),r=n.filter(e=>e.pinnedAt!=null);return r.length===0?n:[...A(r),...n.filter(e=>e.pinnedAt==null)]}function we(e,t){let n=u(t);if(n.length===0)return!1;let r=u(C(e).join(` `));return n.split(` `).every(e=>r.includes(e))}function Te(e){let{thread:t}=e;return t.hasPendingApprovals||t.pendingSubagentRequest===`approval`?{label:`Pending Approval`,colorClass:`text-amber-600 dark:text-amber-300/90`,dotClass:`bg-amber-500 dark:bg-amber-300/90`,pulse:!1}:t.hasPendingUserInput||t.pendingSubagentRequest===`user_input`?{label:`Awaiting Input`,colorClass:`text-indigo-600 dark:text-indigo-300/90`,dotClass:`bg-indigo-500 dark:bg-indigo-300/90`,pulse:!1}:t.runtime?.status===`running`||t.runtime?.status===`waiting`?{label:`Working`,colorClass:`text-sky-600 dark:text-sky-300/80`,dotClass:`bg-sky-500 dark:bg-sky-300/80`,pulse:!0}:t.runtime?.status===`preparing`||t.runtime?.status===`starting`||t.runtime?.status===`queued`?{label:`Connecting`,colorClass:`text-sky-600 dark:text-sky-300/80`,dotClass:`bg-sky-500 dark:bg-sky-300/80`,pulse:!0}:x(t.pendingBackgroundTasks??[])?{label:`Waiting`,colorClass:`text-sidebar-muted-foreground`,dotClass:`bg-sidebar-muted-foreground`,pulse:!1}:!t.hasPendingUserInput&&t.interactionMode===`plan`&&re(t.latestRun,t.runtime)&&t.hasActionableProposedPlan?{label:`Plan Ready`,colorClass:`text-violet-600 dark:text-violet-300/90`,dotClass:`bg-violet-500 dark:bg-violet-300/90`,pulse:!1}:pe(t)?{label:`Completed`,colorClass:`text-emerald-600 dark:text-emerald-300/90`,dotClass:`bg-emerald-500 dark:bg-emerald-300/90`,pulse:!1}:null}function Ee(e){let t=null;for(let n of e)n!==null&&(t===null||le[n.label]>le[t.label])&&(t=n);return t}function De(e,t){return t.projectExpanded?t.isThreadListExpanded||e.length<=t.previewCount?e:e.slice(0,t.previewCount):[]}function Oe(e){let{deletedThreadId:t,deletedThreadIds:n,sortOrder:r,threads:i}=e,a=i.find(e=>e.id===t);return a?k(i.filter(e=>e.projectId===a.projectId&&e.id!==t&&!n?.has(e.id)),r)[0]?.id??null:null}function ke(e,t,n){return t.length>0?t.reduce((e,t)=>Math.max(e,j(t,n)),-1/0):n===`created_at`?M(e.createdAt)??-1/0:M(e.updatedAt??e.createdAt)??-1/0}function Z(e,t,n,r){return t===`manual`?[...e]:e.map(e=>({project:e,timestamp:ke(e,n(e),t)})).sort((e,t)=>(t.timestamp===e.timestamp?0:t.timestamp>e.timestamp?1:-1)||r(e.project,t.project)).map(({project:e})=>e)}function Ae(e,t,n){let r=new Map;for(let e of t){let t=r.get(e.projectId)??[];t.push(e),r.set(e.projectId,t)}return Z(e,n,e=>r.get(e.id)??[],(e,t)=>e.title.localeCompare(t.title)||e.id.localeCompare(t.id))}function je(e,t,n){let r=new Map(e.flatMap(e=>e.memberProjectRefs.map(t=>[`${t.environmentId}\0${t.projectId}`,e.projectKey]))),i=new Map;for(let e of t){if(e.archivedAt!==null)continue;let t=r.get(`${e.environmentId}\0${e.projectId}`);if(!t)continue;let n=i.get(t);n?n.push(e):i.set(t,[e])}return Z(e,n,e=>i.get(e.projectKey)??[],(e,t)=>e.title.localeCompare(t.title)||e.projectKey.localeCompare(t.projectKey))}function Me(e,t,n){return je(e,ce(t,null),n)}function Ne(e,t,n){let r=(e,t)=>`${e}\u0000${t}`,i=new Map;for(let e of t){if(e.archivedAt!==null)continue;let t=r(e.environmentId,e.projectId),n=i.get(t)??[];n.push(e),i.set(t,n)}return Z(e,n,e=>i.get(r(e.environmentId,e.id))??[],(e,t)=>e.title.localeCompare(t.title)||e.environmentId.localeCompare(t.environmentId)||e.id.localeCompare(t.id))}function Q(e){return e.envMode!==`local`&&e.newWorktreesStartFromOrigin}function Pe(e){return e.projectDefaultSelection??(e.carrySourceDraftId===e.destinationDraftId?null:e.carrySelection)}function Fe(e){let t=e?.activeProvider;return e?.modelSelectionExplicit===!0&&t!=null&&e.modelSelectionByProvider[t]!==void 0}function Ie(e){return e.activeThread?l(e.activeThread.environmentId,e.activeThread.projectId):e.activeDraftThread?l(e.activeDraftThread.environmentId,e.activeDraftThread.projectId):e.defaultProjectRef}async function Le(e){let t=Ie(e);return t?(await e.handleNewThread(t),!0):!1}async function Re(e,t){let n=await g(c,P(e,t,d),{reportDefect:!1,reportFailure:!1}),r=N(e,t,d,N(e,t,n._tag===`Success`?n.value.relativePath:d,n._tag===`Success`?n.value:null));return r===null||r.truncated?null:I(r.contents)}function $(e){return{...e?.branch===void 0?{}:{branch:e.branch},...e?.worktreePath===void 0?{}:{worktreePath:e.worktreePath},...e?.envMode===void 0?{}:{envMode:e.envMode},...e?.startFromOrigin===void 0?{}:{startFromOrigin:e.startFromOrigin}}}function ze(){let e=(0,B.c)(7),t=h(O),n=D(ie),c=w(),l;e[0]===c.state.matches?l=e[1]:(l=()=>{let e=c.state.matches[c.state.matches.length-1]?.params??{};return E(e)},e[0]=c.state.matches,e[1]=l);let u=l,d;return e[2]!==t||e[3]!==u||e[4]!==n||e[5]!==c?(d=(e,l)=>{let d=te(),h=t.get(e.environmentId)?.settings??o,{getComposerDraft:g,getDraftSessionByLogicalProjectKey:_,getDraftSession:v,getDraftThread:b,applyStickyState:x,setDraftThreadContext:S,setLogicalProjectDraftThreadId:C,setModelSelection:w}=a.getState(),T=c.state.location.href,E=()=>c.state.location.href!==T,D=u(),O=D?.kind===`server`?y(D.threadRef):null,re=D?.kind===`draft`?v(D.draftId):null,k=D?g(D.kind===`server`?D.threadRef:D.draftId):null,A=k?.activeProvider??null,j=(A?k?.modelSelectionByProvider[A]??null:null)??O?.modelSelection??null,M=k?.interactionMode??O?.interactionMode??re?.interactionMode??null,N=d.find(t=>t.id===e.projectId&&t.environmentId===e.environmentId),P=()=>E()||N!==void 0&&ee(e)===null,F=ae(h,N?.id??null,N),ie=F.settings.defaultModelSelection,I=F.settings.defaultRuntimeMode,L=e=>Pe({projectDefaultSelection:ie??null,carrySelection:j,carrySourceDraftId:D?.kind===`draft`?D.draftId:null,destinationDraftId:e}),R=async()=>{let n=N!==void 0&&F.settings.defaultThreadEnvMode===null?await Re(N.environmentId,N.workspaceRoot):null;return oe({projectSettings:ae(h,N?.id??null,N,n),workspaceRoot:N?.workspaceRoot??null,newProjectsRoot:t.get(e.environmentId)?.newProjectsRoot,projectHasThreads:ne().some(t=>t.environmentId===e.environmentId&&t.projectId===e.projectId)})},z=N?se(N,n):r(e),B=l?.branch!==void 0,V=l?.worktreePath!==void 0,H=l?.envMode!==void 0,U=l?.startFromOrigin!==void 0,W=_(z),G=W?s(W.environmentId,W.threadId):null,K=W!==null&&W.promotedTo==null&&G!==null&&y(G)===null?W:null;G&&K===null&&i(G);let q=K&&!f(g(K.draftId))?K:null,J=D?D.kind===`server`?b(D.threadRef):v(D.draftId):null;if(q)return(async()=>{let t=D?.kind===`draft`&&D.draftId===q.draftId,n=B||V||H||U,r=null;if(n)r=$(l);else if(!t){let e=await R();if(P())return null;let t=u(),n=t?.kind===`draft`&&t.draftId===q.draftId,i=G!==null&&y(G)!==null,a=_(z)?.draftId!==q.draftId,o=f(g(q.draftId));if(n||i||a||o)return null;r={branch:null,worktreePath:null,envMode:e,startFromOrigin:Q({envMode:e,newWorktreesStartFromOrigin:F.settings.newWorktreesStartFromOrigin})}}if(r&&S(q.draftId,{...r,...t?{}:{runtimeMode:I},...M?{interactionMode:M}:{}}),!Fe(g(q.draftId))){x(q.draftId);let e=L(q.draftId);e&&w(q.draftId,e,{replaceOptions:!0})}C(z,e,q.draftId,{threadId:q.threadId,...r,...t?{}:{runtimeMode:I},...M?{interactionMode:M}:{}});let i={draftId:q.draftId,threadId:q.threadId},a=u();return a?.kind===`draft`&&a.draftId===q.draftId||await c.navigate({to:`/draft/$draftId`,params:{draftId:q.draftId},replace:l?.replace??!1}),i})();if(J&&D?.kind===`draft`&&J.logicalProjectKey===z&&J.promotedTo==null&&!f(g(D.draftId)))return(B||V||H||U)&&S(D.draftId,$(l)),C(z,e,D.draftId,{threadId:J.threadId,createdAt:J.createdAt,runtimeMode:J.runtimeMode,interactionMode:J.interactionMode,...$(l)}),Promise.resolve({draftId:D.draftId,threadId:J.threadId});let Y=p(),X=m(),ce=new Date().toISOString();return(async()=>{let t=l?.envMode??await R();if(P())return null;let n=_(z);if(n&&n.draftId!==W?.draftId&&y(s(n.environmentId,n.threadId))===null)return C(z,e,n.draftId,{threadId:n.threadId,createdAt:n.createdAt,runtimeMode:n.runtimeMode,interactionMode:n.interactionMode,...$(l)}),await c.navigate({to:`/draft/$draftId`,params:{draftId:n.draftId},replace:l?.replace??!1}),{draftId:n.draftId,threadId:n.threadId};C(z,e,Y,{threadId:X,createdAt:ce,branch:l?.branch??null,worktreePath:l?.worktreePath??null,envMode:t,startFromOrigin:l?.startFromOrigin??Q({envMode:t,newWorktreesStartFromOrigin:F.settings.newWorktreesStartFromOrigin}),runtimeMode:I,...M?{interactionMode:M}:{}}),x(Y);let r=L(Y);return r&&w(Y,r,{replaceOptions:!0}),await c.navigate({to:`/draft/$draftId`,params:{draftId:Y},replace:l?.replace??!1}),{draftId:Y,threadId:X}})()},e[2]=t,e[3]=u,e[4]=n,e[5]=c,e[6]=d):d=e[6],d}function Be(){let e=(0,B.c)(16),t=L(We),n;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(n={strict:!1,select:Ue},e[0]=n):n=e[0];let r=T(n),i=r?.kind===`server`?r.threadRef:null,o=r?.kind===`draft`?r.draftId:null,s=v(i),c=a(He),u;e[1]!==c||e[2]!==r?(u=()=>r?r.kind===`server`?c(r.threadRef):a.getState().getDraftSession(r.draftId):null,e[1]=c,e[2]=r,e[3]=u):u=e[3];let d=a(u),f=b(),p;e[4]!==t||e[5]!==f?(p=ve({items:f,preferredIds:t,getId:F,getPreferenceIds:Ve}),e[4]=t,e[5]=f,e[6]=p):p=e[6];let m=p,h=ze(),g;e[7]===m[0]?g=e[8]:(g=m[0]?l(m[0].environmentId,m[0].id):null,e[7]=m[0],e[8]=g);let _;return e[9]!==d||e[10]!==s||e[11]!==h||e[12]!==o||e[13]!==i||e[14]!==g?(_={activeDraftThread:d,activeThread:s,defaultProjectRef:g,handleNewThread:h,routeDraftId:o,routeThreadRef:i},e[9]=d,e[10]=s,e[11]=h,e[12]=o,e[13]=i,e[14]=g,e[15]=_):_=e[15],_}function Ve(e){return[F(e),R(e.workspaceRoot)]}function He(e){return e.getDraftThread}function Ue(e){return E(e)}function We(e){return e.projectOrder}export{G as A,Te as C,Ne as D,Ae as E,de as M,Me as O,fe as S,je as T,be as _,Ie as a,K as b,Y as c,ye as d,xe as f,we as g,ve as h,Q as i,W as j,Ce as k,q as l,he as m,ze as n,Le as o,_e as p,Fe as r,J as s,Be as t,Oe as u,Ee as v,me as w,Se as x,De as y};
2
- //# sourceMappingURL=useHandleNewThread-BOKOo2wA.js.map
1
+ import{a as e,t}from"./react-DH3P2YXY.js";import{n}from"./jsx-runtime-BnjsACtP.js";import{$s as r,C as i,D as a,Oh as o,Qs as s,Zo as c,Zs as l,c as u,cl as d,g as f,i as p,s as m,ts as h}from"./utils-CBe1bHL7.js";import{L as g,R as _}from"./runtime-CABaKt1A.js";import{d as ee,f as te,k as v,m as ne,p as y,w as b}from"./entities-pafv-XUM.js";import{in as x,it as S,pn as C}from"./runtime-BBIAfWJY.js";import{a as w,t as T}from"./useParams-C5D_t-0u.js";import{d as E}from"./toast-D26NINYU.js";import{s as D}from"./useSettings-CHt2_4He.js";import{n as O}from"./server-mIR8e8Vz.js";import{p as re}from"./session-logic-CwBN7BBv.js";import{a as k,i as A,n as j,o as M}from"./threadSort-Bd2rijEy.js";import{c as N,r as P}from"./projectFilesQueryState-C_yH-05-.js";import{d as F,f as ie,i as ae,r as oe,s as se,t as I}from"./p4ProjectFile-BuzidL5M.js";import{r as L,t as R}from"./uiStateStore-CKKy2mq4.js";var z=e(t(),1),B=n(),V=`[data-thread-item], [data-thread-selection-safe]`,H=3,U=160;function W(e){let t=(0,B.c)(6),[n,r]=z.useState(null),[i,a]=z.useState(e),o,s;t[0]!==e||t[1]!==n?(o=()=>{if(e){a(!0);return}if(n===null)return;if(typeof IntersectionObserver>`u`){a(!0);return}let t=n.closest(`[data-slot="scroll-area-viewport"]`),r=new IntersectionObserver(e=>{let[t]=e;return a(t?.isIntersecting===!0)},{root:t,rootMargin:`${U}px 0px`});return r.observe(n),()=>r.disconnect()},s=[e,n],t[0]=e,t[1]=n,t[2]=o,t[3]=s):(o=t[2],s=t[3]),z.useEffect(o,s);let c=e||i,l;return t[4]===c?l=t[5]:(l={leaseLiveStatus:c,rowRef:r},t[4]=c,t[5]=l),l}function G(e,t){let n=z.useRef(null);return e!==null&&t!==null&&(n.current={key:e,value:t}),t===null?e!==null&&n.current?.key===e?n.current.value:null:t}function K(e,t,n,r){let i=e.indexOf(t),a=e.indexOf(n);return i===-1||a===-1?[]:e.slice(Math.min(i,a),Math.max(i,a)+1).filter(r)}async function q(e){let t=new Set,n=null;for(let r of e.entries){let i=await e.delete(r,t);if(i!==null){if(i._tag===`Failure`){if(_(i))break;n??=i;continue}t.add(r.threadKey)}}return{deletedThreadKeys:t,firstFailure:n}}async function J(e){let t=[],n=[];for(let r of e.entries){let i=!1,a=await e.archive(r,()=>{i=!0});if((i||a._tag===`Success`)&&t.push(r.threadKey),a._tag===`Success`)continue;let o=a;if(i){n.push(o);continue}return{archivedThreadKeys:t,mutationFailure:o,followupFailures:n}}return{archivedThreadKeys:t,mutationFailure:null,followupFailures:n}}function Y(e){return[{id:`mark-unread`,label:`Mark unread (${e.count})`},{id:`archive`,label:`Archive (${e.count})`,disabled:e.hasRunningThread},{id:`delete`,label:`Delete (${e.count})`,destructive:!0}]}function X(e){return e.lineage.relationshipToParent===`subagent`}function ce(e,t){let n=S(e);return e.filter(e=>e.archivedAt===null&&!X(e)&&n(e)&&(t===null||t.has(`${e.environmentId}:${e.projectId}`)))}var le={"Pending Approval":5,"Awaiting Input":4,Working:3,Connecting:3,Waiting:2.5,"Plan Ready":2,Completed:1};function ue(e){let t=e.setTimeoutFn??globalThis.setTimeout,n=e.clearTimeoutFn??globalThis.clearTimeout,r=!1,i=null,a=()=>{i!==null&&(n(i),i=null)};return{sync:n=>{if(!n){a(),r&&(r=!1,e.onVisibilityChange(!1));return}r||i!==null||(i=t(()=>{i=null,r=!0,e.onVisibilityChange(!0)},e.delayMs))},dispose:()=>{a()}}}function de(){let e=(0,B.c)(5),[t,n]=z.useState(!1),r=z.useRef(null),i,a;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=()=>{let e=ue({delayMs:200,onVisibilityChange:e=>{n(e)},setTimeoutFn:window.setTimeout.bind(window),clearTimeoutFn:window.clearTimeout.bind(window)});return r.current=e,()=>{e.dispose(),r.current=null}},a=[],e[0]=i,e[1]=a):(i=e[0],a=e[1]),z.useEffect(i,a);let o;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(o=e=>{r.current?.sync(e)},e[2]=o):o=e[2];let s=o,c;return e[3]===t?c=e[4]:(c={showThreadJumpHints:t,updateThreadJumpHintsVisibility:s},e[3]=t,e[4]=c),c}function fe(e,t){return e===void 0?t:e??void 0}function pe(e){if(!e.latestRun?.completedAt)return!1;let t=Date.parse(e.latestRun.completedAt);if(Number.isNaN(t)||!e.lastVisitedAt)return!1;let n=Date.parse(e.lastVisitedAt);return Number.isNaN(n)?!0:t>n}function me(e){return e===null||!e.closest(V)}function he(e){return e>1}function ge(e,t){return e===null||!(`closest`in e)||typeof e.closest!=`function`?null:e.closest(t)}function _e(e){return typeof e!=`object`||!e?!1:ge(e,`a[href]`)!==null||ge(`parentElement`in e&&e.parentElement!==null&&typeof e.parentElement==`object`?e.parentElement:null,`a[href]`)!==null}function ve(e){let{getId:t,getPreferenceIds:n,items:r,preferredIds:i}=e;if(i.length===0)return[...r];let a=new Map;for(let[e,i]of r.entries()){let r=n?.(i)??[t(i)];for(let t of new Set(r)){let n=a.get(t);n?n.push(e):a.set(t,[e])}}let o=new Set,s=i.flatMap(e=>{let t=a.get(e)?.find(e=>!o.has(e));return t===void 0?[]:(o.add(t),[r[t]])}),c=r.filter((e,t)=>!o.has(t));return[...s,...c]}function ye(e,t=H){return e.slice(0,Math.max(0,t))}function be(e){let{currentThreadId:t,direction:n,threadIds:r}=e;if(r.length===0)return null;if(t===null)return n===`previous`?r.at(-1)??null:r[0]??null;let i=r.indexOf(t);return i===-1?null:n===`previous`?i>0?r[i-1]??null:null:i<r.length-1?r[i+1]??null:null}function xe(e){return e.button===2||e.isMac&&e.button===0&&e.ctrlKey}function Se(e){return e.hasPendingApprovals||e.pendingSubagentRequest===`approval`?`approval`:e.hasPendingUserInput||e.pendingSubagentRequest===`user_input`?`input`:e.runtime!==null&&[`preparing`,`queued`,`starting`,`running`,`waiting`].includes(e.runtime.status)?`working`:e.runtime?.status===`idle`?`waiting`:e.runtime?.status===`failed`?e.runtime.lastErrorClass===`usage_limit`?`limited`:`failed`:`ready`}function Ce(e,t){let n=k(e,t),r=n.filter(e=>e.pinnedAt!=null);return r.length===0?n:[...A(r),...n.filter(e=>e.pinnedAt==null)]}function we(e,t){let n=u(t);if(n.length===0)return!1;let r=u(C(e).join(` `));return n.split(` `).every(e=>r.includes(e))}function Te(e){let{thread:t}=e;return t.hasPendingApprovals||t.pendingSubagentRequest===`approval`?{label:`Pending Approval`,colorClass:`text-amber-600 dark:text-amber-300/90`,dotClass:`bg-amber-500 dark:bg-amber-300/90`,pulse:!1}:t.hasPendingUserInput||t.pendingSubagentRequest===`user_input`?{label:`Awaiting Input`,colorClass:`text-indigo-600 dark:text-indigo-300/90`,dotClass:`bg-indigo-500 dark:bg-indigo-300/90`,pulse:!1}:t.runtime?.status===`running`||t.runtime?.status===`waiting`?{label:`Working`,colorClass:`text-sky-600 dark:text-sky-300/80`,dotClass:`bg-sky-500 dark:bg-sky-300/80`,pulse:!0}:t.runtime?.status===`preparing`||t.runtime?.status===`starting`||t.runtime?.status===`queued`?{label:`Connecting`,colorClass:`text-sky-600 dark:text-sky-300/80`,dotClass:`bg-sky-500 dark:bg-sky-300/80`,pulse:!0}:x(t.pendingBackgroundTasks??[])?{label:`Waiting`,colorClass:`text-sidebar-muted-foreground`,dotClass:`bg-sidebar-muted-foreground`,pulse:!1}:!t.hasPendingUserInput&&t.interactionMode===`plan`&&re(t.latestRun,t.runtime)&&t.hasActionableProposedPlan?{label:`Plan Ready`,colorClass:`text-violet-600 dark:text-violet-300/90`,dotClass:`bg-violet-500 dark:bg-violet-300/90`,pulse:!1}:pe(t)?{label:`Completed`,colorClass:`text-emerald-600 dark:text-emerald-300/90`,dotClass:`bg-emerald-500 dark:bg-emerald-300/90`,pulse:!1}:null}function Ee(e){let t=null;for(let n of e)n!==null&&(t===null||le[n.label]>le[t.label])&&(t=n);return t}function De(e,t){return t.projectExpanded?t.isThreadListExpanded||e.length<=t.previewCount?e:e.slice(0,t.previewCount):[]}function Oe(e){let{deletedThreadId:t,deletedThreadIds:n,sortOrder:r,threads:i}=e,a=i.find(e=>e.id===t);return a?k(i.filter(e=>e.projectId===a.projectId&&e.id!==t&&!n?.has(e.id)),r)[0]?.id??null:null}function ke(e,t,n){return t.length>0?t.reduce((e,t)=>Math.max(e,j(t,n)),-1/0):n===`created_at`?M(e.createdAt)??-1/0:M(e.updatedAt??e.createdAt)??-1/0}function Z(e,t,n,r){return t===`manual`?[...e]:e.map(e=>({project:e,timestamp:ke(e,n(e),t)})).sort((e,t)=>(t.timestamp===e.timestamp?0:t.timestamp>e.timestamp?1:-1)||r(e.project,t.project)).map(({project:e})=>e)}function Ae(e,t,n){let r=new Map;for(let e of t){let t=r.get(e.projectId)??[];t.push(e),r.set(e.projectId,t)}return Z(e,n,e=>r.get(e.id)??[],(e,t)=>e.title.localeCompare(t.title)||e.id.localeCompare(t.id))}function je(e,t,n){let r=new Map(e.flatMap(e=>e.memberProjectRefs.map(t=>[`${t.environmentId}\0${t.projectId}`,e.projectKey]))),i=new Map;for(let e of t){if(e.archivedAt!==null)continue;let t=r.get(`${e.environmentId}\0${e.projectId}`);if(!t)continue;let n=i.get(t);n?n.push(e):i.set(t,[e])}return Z(e,n,e=>i.get(e.projectKey)??[],(e,t)=>e.title.localeCompare(t.title)||e.projectKey.localeCompare(t.projectKey))}function Me(e,t,n){return je(e,ce(t,null),n)}function Ne(e,t,n){let r=(e,t)=>`${e}\u0000${t}`,i=new Map;for(let e of t){if(e.archivedAt!==null)continue;let t=r(e.environmentId,e.projectId),n=i.get(t)??[];n.push(e),i.set(t,n)}return Z(e,n,e=>i.get(r(e.environmentId,e.id))??[],(e,t)=>e.title.localeCompare(t.title)||e.environmentId.localeCompare(t.environmentId)||e.id.localeCompare(t.id))}function Q(e){return e.envMode!==`local`&&e.newWorktreesStartFromOrigin}function Pe(e){return e.projectDefaultSelection??(e.carrySourceDraftId===e.destinationDraftId?null:e.carrySelection)}function Fe(e){let t=e?.activeProvider;return e?.modelSelectionExplicit===!0&&t!=null&&e.modelSelectionByProvider[t]!==void 0}function Ie(e){return e.activeThread?l(e.activeThread.environmentId,e.activeThread.projectId):e.activeDraftThread?l(e.activeDraftThread.environmentId,e.activeDraftThread.projectId):e.defaultProjectRef}async function Le(e){let t=Ie(e);return t?(await e.handleNewThread(t),!0):!1}async function Re(e,t){let n=await g(c,P(e,t,d),{reportDefect:!1,reportFailure:!1}),r=N(e,t,d,N(e,t,n._tag===`Success`?n.value.relativePath:d,n._tag===`Success`?n.value:null));return r===null||r.truncated?null:I(r.contents)}function $(e){return{...e?.branch===void 0?{}:{branch:e.branch},...e?.worktreePath===void 0?{}:{worktreePath:e.worktreePath},...e?.envMode===void 0?{}:{envMode:e.envMode},...e?.startFromOrigin===void 0?{}:{startFromOrigin:e.startFromOrigin}}}function ze(){let e=(0,B.c)(7),t=h(O),n=D(ie),c=w(),l;e[0]===c.state.matches?l=e[1]:(l=()=>{let e=c.state.matches[c.state.matches.length-1]?.params??{};return E(e)},e[0]=c.state.matches,e[1]=l);let u=l,d;return e[2]!==t||e[3]!==u||e[4]!==n||e[5]!==c?(d=(e,l)=>{let d=te(),h=t.get(e.environmentId)?.settings??o,{getComposerDraft:g,getDraftSessionByLogicalProjectKey:_,getDraftSession:v,getDraftThread:b,applyStickyState:x,setDraftThreadContext:S,setLogicalProjectDraftThreadId:C,setModelSelection:w}=a.getState(),T=c.state.location.href,E=()=>c.state.location.href!==T,D=u(),O=D?.kind===`server`?y(D.threadRef):null,re=D?.kind===`draft`?v(D.draftId):null,k=D?g(D.kind===`server`?D.threadRef:D.draftId):null,A=k?.activeProvider??null,j=(A?k?.modelSelectionByProvider[A]??null:null)??O?.modelSelection??null,M=k?.interactionMode??O?.interactionMode??re?.interactionMode??null,N=d.find(t=>t.id===e.projectId&&t.environmentId===e.environmentId),P=()=>E()||N!==void 0&&ee(e)===null,F=ae(h,N?.id??null,N),ie=F.settings.defaultModelSelection,I=F.settings.defaultRuntimeMode,L=e=>Pe({projectDefaultSelection:ie??null,carrySelection:j,carrySourceDraftId:D?.kind===`draft`?D.draftId:null,destinationDraftId:e}),R=async()=>{let n=N!==void 0&&F.settings.defaultThreadEnvMode===null?await Re(N.environmentId,N.workspaceRoot):null;return oe({projectSettings:ae(h,N?.id??null,N,n),workspaceRoot:N?.workspaceRoot??null,newProjectsRoot:t.get(e.environmentId)?.newProjectsRoot,projectHasThreads:ne().some(t=>t.environmentId===e.environmentId&&t.projectId===e.projectId)})},z=N?se(N,n):r(e),B=l?.branch!==void 0,V=l?.worktreePath!==void 0,H=l?.envMode!==void 0,U=l?.startFromOrigin!==void 0,W=_(z),G=W?s(W.environmentId,W.threadId):null,K=W!==null&&W.promotedTo==null&&G!==null&&y(G)===null?W:null;G&&K===null&&i(G);let q=K&&!f(g(K.draftId))?K:null,J=D?D.kind===`server`?b(D.threadRef):v(D.draftId):null;if(q)return(async()=>{let t=D?.kind===`draft`&&D.draftId===q.draftId,n=B||V||H||U,r=null;if(n)r=$(l);else if(!t){let e=await R();if(P())return null;let t=u(),n=t?.kind===`draft`&&t.draftId===q.draftId,i=G!==null&&y(G)!==null,a=_(z)?.draftId!==q.draftId,o=f(g(q.draftId));if(n||i||a||o)return null;r={branch:null,worktreePath:null,envMode:e,startFromOrigin:Q({envMode:e,newWorktreesStartFromOrigin:F.settings.newWorktreesStartFromOrigin})}}if(r&&S(q.draftId,{...r,...t?{}:{runtimeMode:I},...M?{interactionMode:M}:{}}),!Fe(g(q.draftId))){x(q.draftId);let e=L(q.draftId);e&&w(q.draftId,e,{replaceOptions:!0})}C(z,e,q.draftId,{threadId:q.threadId,...r,...t?{}:{runtimeMode:I},...M?{interactionMode:M}:{}});let i={draftId:q.draftId,threadId:q.threadId},a=u();return a?.kind===`draft`&&a.draftId===q.draftId||await c.navigate({to:`/draft/$draftId`,params:{draftId:q.draftId},replace:l?.replace??!1}),i})();if(J&&D?.kind===`draft`&&J.logicalProjectKey===z&&J.promotedTo==null&&!f(g(D.draftId)))return(B||V||H||U)&&S(D.draftId,$(l)),C(z,e,D.draftId,{threadId:J.threadId,createdAt:J.createdAt,runtimeMode:J.runtimeMode,interactionMode:J.interactionMode,...$(l)}),Promise.resolve({draftId:D.draftId,threadId:J.threadId});let Y=p(),X=m(),ce=new Date().toISOString();return(async()=>{let t=l?.envMode??await R();if(P())return null;let n=_(z);if(n&&n.draftId!==W?.draftId&&y(s(n.environmentId,n.threadId))===null)return C(z,e,n.draftId,{threadId:n.threadId,createdAt:n.createdAt,runtimeMode:n.runtimeMode,interactionMode:n.interactionMode,...$(l)}),await c.navigate({to:`/draft/$draftId`,params:{draftId:n.draftId},replace:l?.replace??!1}),{draftId:n.draftId,threadId:n.threadId};C(z,e,Y,{threadId:X,createdAt:ce,branch:l?.branch??null,worktreePath:l?.worktreePath??null,envMode:t,startFromOrigin:l?.startFromOrigin??Q({envMode:t,newWorktreesStartFromOrigin:F.settings.newWorktreesStartFromOrigin}),runtimeMode:I,...M?{interactionMode:M}:{}}),x(Y);let r=L(Y);return r&&w(Y,r,{replaceOptions:!0}),await c.navigate({to:`/draft/$draftId`,params:{draftId:Y},replace:l?.replace??!1}),{draftId:Y,threadId:X}})()},e[2]=t,e[3]=u,e[4]=n,e[5]=c,e[6]=d):d=e[6],d}function Be(){let e=(0,B.c)(16),t=L(We),n;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(n={strict:!1,select:Ue},e[0]=n):n=e[0];let r=T(n),i=r?.kind===`server`?r.threadRef:null,o=r?.kind===`draft`?r.draftId:null,s=v(i),c=a(He),u;e[1]!==c||e[2]!==r?(u=()=>r?r.kind===`server`?c(r.threadRef):a.getState().getDraftSession(r.draftId):null,e[1]=c,e[2]=r,e[3]=u):u=e[3];let d=a(u),f=b(),p;e[4]!==t||e[5]!==f?(p=ve({items:f,preferredIds:t,getId:F,getPreferenceIds:Ve}),e[4]=t,e[5]=f,e[6]=p):p=e[6];let m=p,h=ze(),g;e[7]===m[0]?g=e[8]:(g=m[0]?l(m[0].environmentId,m[0].id):null,e[7]=m[0],e[8]=g);let _;return e[9]!==d||e[10]!==s||e[11]!==h||e[12]!==o||e[13]!==i||e[14]!==g?(_={activeDraftThread:d,activeThread:s,defaultProjectRef:g,handleNewThread:h,routeDraftId:o,routeThreadRef:i},e[9]=d,e[10]=s,e[11]=h,e[12]=o,e[13]=i,e[14]=g,e[15]=_):_=e[15],_}function Ve(e){return[F(e),R(e.workspaceRoot)]}function He(e){return e.getDraftThread}function Ue(e){return E(e)}function We(e){return e.projectOrder}export{G as A,Te as C,Ne as D,Ae as E,de as M,Me as O,fe as S,je as T,be as _,Ie as a,K as b,Y as c,ye as d,xe as f,we as g,ve as h,Q as i,W as j,Ce as k,q as l,he as m,ze as n,Le as o,_e as p,Fe as r,J as s,Be as t,Oe as u,Ee as v,me as w,Se as x,De as y};
2
+ //# sourceMappingURL=useHandleNewThread-C7ynA68A.js.map
@@ -1,2 +1,2 @@
1
- import{n as e}from"./jsx-runtime-BnjsACtP.js";import{t}from"./env-wK1YYxA8.js";import{i as n}from"./dist-ceTe_mn7.js";import{t as r}from"./authRedirect-DWE5a_T9.js";var i=e();function a(){let e=(0,i.c)(2),a=n(),o;return e[0]===a?o=e[1]:(o={authPrompt:null,openAuthPrompt:()=>{a.openSignIn(r(window.location.href,t))}},e[0]=a,e[1]=o),o}export{a as t};
2
- //# sourceMappingURL=useP4ConnectAuthPrompt-D63n-MFC.js.map
1
+ import{n as e}from"./jsx-runtime-BnjsACtP.js";import{t}from"./env-wK1YYxA8.js";import{i as n}from"./dist-ATiHSdUa.js";import{t as r}from"./authRedirect-DWE5a_T9.js";var i=e();function a(){let e=(0,i.c)(2),a=n(),o;return e[0]===a?o=e[1]:(o={authPrompt:null,openAuthPrompt:()=>{a.openSignIn(r(window.location.href,t))}},e[0]=a,e[1]=o),o}export{a as t};
2
+ //# sourceMappingURL=useP4ConnectAuthPrompt-5uCMQUT1.js.map
@@ -1,3 +1,3 @@
1
- import{a as e,t}from"./react-DH3P2YXY.js";import{n}from"./jsx-runtime-BnjsACtP.js";import{D as r,Os as i,Pw as a,Ts as o,Uc as s,Zo as c,Zs as l,av as u,bs as d,ev as f,q_ as p,tE as m,ts as h}from"./utils-CBe1bHL7.js";import{M as g,N as _,W as v}from"./runtime-CeFhsGnm.js";import{a as y,i as b}from"./vcsRefInvalidation-B2f3qDSR.js";import{w as ee}from"./entities-eRiwvW2F.js";import{t as te}from"./runtime-BOlBBevr.js";import{i as x}from"./toast-C61oyZY1.js";import{D as S,d as C,s as w}from"./useSettings-VTow9ZEM.js";import{i as T,n as E}from"./session-D3gY-tOR.js";import{n as D}from"./query-B3Zo1YOE.js";import{t as O}from"./use-atom-command-Bt7x9oO0.js";import{d as k,l as A,u as j}from"./queries-DJfKGsHe.js";import{t as M}from"./sourceControl-Dqo9EYNC.js";import{C as N,r as P}from"./pullRequests-DggtcbhA.js";import{R as F,b as ne,y as re}from"./pullRequestDetail.logic-Bkh57WzV.js";import{n as ie}from"./useHandleNewThread-BOKOo2wA.js";import{c as ae,f as I,i as L,s as R}from"./p4ProjectFile-BVKW5TIA.js";import{t as z}from"./sidebarProjectGrouping-DDt6qTcu.js";var B=e(t(),1),V=n();function H(e){return{pullRequestResolution:_(e,{label:`environment-data:git:resolve-pull-request`,tag:s.gitResolvePullRequest}),preparePullRequestThread:g(e,{label:`environment-data:git:prepare-pull-request-thread`,tag:s.gitPreparePullRequestThread,scheduler:y,concurrency:b})}}var U=H(te),W={init:`init`,pull:`pull`,publishRepository:`publish_repository`,runStackedAction:`run_change_request`,preparePullRequestThread:`prepare_pull_request_thread`};function G(e){let t=T(e.scope.environmentId,f),n=W[e.kind],r=h(A.stateAtom(e.scope)),i=r.operation===n,s=(0,B.useCallback)(()=>{A.resetError(c,e.scope,n)},[e.scope,n]),l=(0,B.useCallback)(async(...t)=>{if(e.scope.environmentId===null||!E(e.scope.environmentId,`source-control:write`))return d(a(new u({requiredScope:f,message:`This connection cannot change source control.`})));let r=async()=>{let n=await e.action(...t);return o(n)&&e.onSuccess?.(),n};return e.managedExternally===!0?r():A.track(c,e.scope,{operation:n,label:e.label},r)},[e.action,e.label,e.managedExternally,e.onSuccess,e.scope,n]);return{isAllowed:t,error:i?r.error:null,isPending:i&&r.isRunning,resetError:s,run:l}}function K(e){return e.environmentId===null||e.cwd===null?null:{environmentId:e.environmentId,cwd:e.cwd}}function q(e,t){let n=(0,V.c)(6),r;n[0]===e?r=n[1]:(r=A.stateAtom(e),n[0]=e,n[1]=r);let i=h(r),a;return n[2]!==t||n[3]!==i.isRunning||n[4]!==i.operation?(a=i.isRunning&&i.operation!==null&&t.some(e=>W[e]===i.operation),n[2]=t,n[3]=i.isRunning,n[4]=i.operation,n[5]=a):a=n[5],a}function J(e){let t=(0,V.c)(7),n;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(n={reportFailure:!1},t[0]=n):n=t[0];let r=O(j.init,n),i;t[1]!==r||t[2]!==e?(i=async()=>{let t=K(e);return t===null?d(a(new k({operation:`init`,environmentId:e.environmentId,cwd:e.cwd}))):r({environmentId:t.environmentId,input:{cwd:t.cwd}})},t[1]=r,t[2]=e,t[3]=i):i=t[3];let o=i,s;return t[4]!==o||t[5]!==e?(s={kind:`init`,label:`Initializing repository`,scope:e,action:o},t[4]=o,t[5]=e,t[6]=s):s=t[6],G(s)}function oe(e){let t=(0,V.c)(11),n;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(n={reportFailure:!1},t[0]=n):n=t[0];let r=O(j.pull,n),i;t[1]!==e.cwd||t[2]!==e.environmentId?(i=e.environmentId!==null&&e.cwd!==null?j.status({environmentId:e.environmentId,input:{cwd:e.cwd}}):null,t[1]=e.cwd,t[2]=e.environmentId,t[3]=i):i=t[3];let o=D(i),s;t[4]!==r||t[5]!==e?(s=async()=>{let t=K(e);return t===null?d(a(new k({operation:`pull`,environmentId:e.environmentId,cwd:e.cwd}))):r({environmentId:t.environmentId,input:{cwd:t.cwd}})},t[4]=r,t[5]=e,t[6]=s):s=t[6];let c=s,l;return t[7]!==c||t[8]!==e||t[9]!==o.refresh?(l={kind:`pull`,label:`Pulling latest changes...`,scope:e,action:c,onSuccess:o.refresh},t[7]=c,t[8]=e,t[9]=o.refresh,t[10]=l):l=t[10],G(l)}function se(e){let t=(0,V.c)(13),n;t[0]===e?n=t[1]:(n=A.runStackedAction(e),t[0]=e,t[1]=n);let r;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(r={reportFailure:!1},t[2]=r):r=t[2];let i=O(n,r),o;t[3]!==e.cwd||t[4]!==e.environmentId?(o=e.environmentId!==null&&e.cwd!==null?j.status({environmentId:e.environmentId,input:{cwd:e.cwd}}):null,t[3]=e.cwd,t[4]=e.environmentId,t[5]=o):o=t[5];let s=D(o),c;t[6]!==i||t[7]!==e?(c=async t=>K(e)===null?d(a(new k({operation:`run_change_request`,environmentId:e.environmentId,cwd:e.cwd}))):i(t),t[6]=i,t[7]=e,t[8]=c):c=t[8];let l=c,u;return t[9]!==l||t[10]!==e||t[11]!==s.refresh?(u={kind:`runStackedAction`,label:`Running source control action`,scope:e,action:l,onSuccess:s.refresh,managedExternally:!0},t[9]=l,t[10]=e,t[11]=s.refresh,t[12]=u):u=t[12],G(u)}function ce(e){let t=(0,V.c)(11),n;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(n={reportFailure:!1},t[0]=n):n=t[0];let r=O(M.publishRepository,n),i;t[1]!==e.cwd||t[2]!==e.environmentId?(i=e.environmentId!==null&&e.cwd!==null?j.status({environmentId:e.environmentId,input:{cwd:e.cwd}}):null,t[1]=e.cwd,t[2]=e.environmentId,t[3]=i):i=t[3];let o=D(i),s;t[4]!==r||t[5]!==e?(s=async t=>{let n=K(e);return n===null?d(a(new k({operation:`publish_repository`,environmentId:e.environmentId,cwd:e.cwd}))):r({environmentId:n.environmentId,input:{cwd:n.cwd,...t}})},t[4]=r,t[5]=e,t[6]=s):s=t[6];let c=s,l;return t[7]!==c||t[8]!==e||t[9]!==o.refresh?(l={kind:`publishRepository`,label:`Publishing repository`,scope:e,action:c,onSuccess:o.refresh},t[7]=c,t[8]=e,t[9]=o.refresh,t[10]=l):l=t[10],G(l)}function Y(e){let t=(0,V.c)(7),n;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(n={reportFailure:!1},t[0]=n):n=t[0];let r=O(U.preparePullRequestThread,n),i;t[1]!==r||t[2]!==e?(i=async t=>{let n=K(e);return n===null?d(a(new k({operation:`prepare_pull_request_thread`,environmentId:e.environmentId,cwd:e.cwd}))):t.mode===`worktree`&&t.threadId!==void 0&&!E(n.environmentId,`orchestration:operate`)?d(a(new u({requiredScope:p,message:`This connection cannot change threads.`}))):r({environmentId:n.environmentId,input:{cwd:n.cwd,reference:t.reference,mode:t.mode,...t.threadId?{threadId:t.threadId}:{}}})},t[1]=r,t[2]=e,t[3]=i):i=t[3];let o=i,s;return t[4]!==o||t[5]!==e?(s={kind:`preparePullRequestThread`,label:`Preparing pull request thread`,scope:e,action:o},t[4]=o,t[5]=e,t[6]=s):s=t[6],G(s)}function X(e){return e.environmentId===null||e.cwd===null||e.reference===null?null:m(i(c.get(U.pullRequestResolution({environmentId:e.environmentId,input:{cwd:e.cwd,reference:e.reference}}))))}function le(e){let t=(0,V.c)(12),n;t[0]!==e.cwd||t[1]!==e.environmentId||t[2]!==e.reference?(n=e.environmentId!==null&&e.cwd!==null&&e.reference!==null?U.pullRequestResolution({environmentId:e.environmentId,input:{cwd:e.cwd,reference:e.reference}}):null,t[0]=e.cwd,t[1]=e.environmentId,t[2]=e.reference,t[3]=n):n=t[3];let r=D(n),i;t[4]===e?i=t[5]:(i=X(e),t[4]=e,t[5]=i);let a=i,o=r.data??a,s=r.isPending&&a===null,c;return t[6]!==r.error||t[7]!==r.isPending||t[8]!==r.refresh||t[9]!==o||t[10]!==s?(c={data:o,error:r.error,isPending:s,isFetching:r.isPending,refresh:r.refresh},t[6]=r.error,t[7]=r.isPending,t[8]=r.refresh,t[9]=o,t[10]=s,t[11]=c):c=t[11],c}function ue(e,t){let n=(0,V.c)(10),r;n[0]===t?r=n[1]:(r=e=>L(e,t).settings.pullRequestMergeMethod,n[0]=t,n[1]=r);let i=C(e,r),a=w(de),o=w(I),s=ee(),c=S(),l;return n[2]!==e||n[3]!==o||n[4]!==a||n[5]!==c||n[6]!==i||n[7]!==t||n[8]!==s?(l=()=>{if(i!=null)return i;if(Object.keys(a).length===0)return;let n=s.find(n=>n.environmentId===e&&n.id===t);if(!n)return;let r=z({projects:s,settings:o,primaryEnvironmentId:c}).get(ae(n))??R(n,o);return a[r]},n[2]=e,n[3]=o,n[4]=a,n[5]=c,n[6]=i,n[7]=t,n[8]=s,n[9]=l):l=n[9],l}function de(e){return e.pullRequestMergeMethodOverrides}var fe={merge:`Merge requested`,ready:`Marked ready for review`,draft:`Converted to draft`,close:`Pull request closed`,reopen:`Pull request reopened`,"update-branch":`Branch updated with the base branch`,"enable-auto-merge":`Auto-merge enabled`,"disable-auto-merge":`Auto-merge disabled`,revert:`Revert pull request opened`,"delete-branch":`Branch deleted`,"approve-workflows":`Workflows approved`},pe={merge:`Could not merge this pull request`,ready:`Could not mark this ready for review`,draft:`Could not convert this to a draft`,close:`Could not close this pull request`,reopen:`Could not reopen this pull request`,"update-branch":`Could not update this branch`,"enable-auto-merge":`Could not enable auto-merge`,"disable-auto-merge":`Could not disable auto-merge`,revert:`Could not open a revert pull request`,"delete-branch":`Could not delete this branch`,"approve-workflows":`Could not approve workflows`},Z={merge:`The host refused the merge. Check that you have write access, that the checks it requires have passed, and that the branch is not conflicting.`,ready:`The host refused it. Check that you have write access to this repository.`,draft:`The host refused it. Check that you have write access to this repository.`,close:`The host refused it. Check that you have write access, or that you opened it.`,reopen:`The host refused it. Check that you have write access, and that the branch still exists.`,"update-branch":`The host refused it. Check that you have write access, and that the base branch has not diverged in a way the host cannot merge.`,"enable-auto-merge":`The host refused it. Check that auto-merge is enabled for this repository and that you have write access.`,"disable-auto-merge":`The host refused it. Check that you have write access to this repository.`,revert:`The host refused it. Check that you have write access and that this pull request was merged on the host.`,"delete-branch":`The host refused it. Check that you have write access to the source repository and that the branch has not moved since this page loaded.`,"approve-workflows":`The host refused it. Check that you have Actions write access and that these workflow runs are still awaiting approval.`};function me({environmentId:e,reference:t,onSuccess:n,resolveMergeMethod:r}){let i=O(P.runAction,{reportFailure:!1}),[a,o]=(0,B.useState)(!1),s=(0,B.useRef)(!1);return{actionPending:a,perform:async(a,c)=>{if(!(s.current||t===null)){s.current=!0,o(!0);try{let o=await i({environmentId:e,input:{...t,action:a,...c?{mergeMethod:c}:r?{resolveMergeMethod:r}:{}}});if(o._tag===`Failure`)throw v(o);x.add({type:`success`,title:fe[a]}),n?.(a)}catch(e){x.add({type:`error`,title:pe[a],description:F(e,Z[a])})}finally{s.current=!1,o(!1)}}}}}function Q(e){let t=O(P.runAction,{reportFailure:!1}),n=(0,B.useRef)(new Set),[r,i]=(0,B.useState)(()=>new Set);return{close:(0,B.useCallback)(async r=>{let a=r.filter(e=>{let t=N(e);return e.state!==`open`||n.current.has(t)?!1:(n.current.add(t),!0)});if(a.length===0)return;i(new Set(n.current));let o=0,s=[];await Promise.all(a.map(async r=>{try{let n=await t({environmentId:r.environmentId,input:{projectId:r.projectId,host:r.host,repository:r.repository,number:r.number,action:`close`}});if(n._tag===`Failure`)throw v(n);o++,e(r)}catch(e){s.push(`#${r.number}: ${F(e,Z.close)}`)}finally{n.current.delete(N(r)),i(new Set(n.current))}})),x.add({type:s.length>0?`error`:`success`,title:s.length>0?`Closed ${o} of ${a.length} pull requests`:`Closed ${o} pull request${o===1?``:`s`}`,...s.length>0?{description:s.slice(0,3).join(`
1
+ import{a as e,t}from"./react-DH3P2YXY.js";import{n}from"./jsx-runtime-BnjsACtP.js";import{D as r,Os as i,Pw as a,Ts as o,Uc as s,Zo as c,Zs as l,av as u,bs as d,ev as f,q_ as p,tE as m,ts as h}from"./utils-CBe1bHL7.js";import{M as g,N as _,W as v}from"./runtime-CABaKt1A.js";import{a as y,i as b}from"./vcsRefInvalidation-CytQodoP.js";import{w as ee}from"./entities-pafv-XUM.js";import{t as te}from"./runtime-BBIAfWJY.js";import{i as x}from"./toast-D26NINYU.js";import{D as S,d as C,s as w}from"./useSettings-CHt2_4He.js";import{i as T,n as E}from"./session-BlCBDyVn.js";import{n as D}from"./query-B3Zo1YOE.js";import{t as O}from"./use-atom-command-C4y634Qy.js";import{d as k,l as A,u as j}from"./queries-BZGM6AjA.js";import{t as M}from"./sourceControl-CcPqr0UX.js";import{C as N,r as P}from"./pullRequests-C8-SkuQU.js";import{R as F,b as ne,y as re}from"./pullRequestDetail.logic-FUlKz34F.js";import{n as ie}from"./useHandleNewThread-C7ynA68A.js";import{c as ae,f as I,i as L,s as R}from"./p4ProjectFile-BuzidL5M.js";import{t as z}from"./sidebarProjectGrouping-DaMfJpqc.js";var B=e(t(),1),V=n();function H(e){return{pullRequestResolution:_(e,{label:`environment-data:git:resolve-pull-request`,tag:s.gitResolvePullRequest}),preparePullRequestThread:g(e,{label:`environment-data:git:prepare-pull-request-thread`,tag:s.gitPreparePullRequestThread,scheduler:y,concurrency:b})}}var U=H(te),W={init:`init`,pull:`pull`,publishRepository:`publish_repository`,runStackedAction:`run_change_request`,preparePullRequestThread:`prepare_pull_request_thread`};function G(e){let t=T(e.scope.environmentId,f),n=W[e.kind],r=h(A.stateAtom(e.scope)),i=r.operation===n,s=(0,B.useCallback)(()=>{A.resetError(c,e.scope,n)},[e.scope,n]),l=(0,B.useCallback)(async(...t)=>{if(e.scope.environmentId===null||!E(e.scope.environmentId,`source-control:write`))return d(a(new u({requiredScope:f,message:`This connection cannot change source control.`})));let r=async()=>{let n=await e.action(...t);return o(n)&&e.onSuccess?.(),n};return e.managedExternally===!0?r():A.track(c,e.scope,{operation:n,label:e.label},r)},[e.action,e.label,e.managedExternally,e.onSuccess,e.scope,n]);return{isAllowed:t,error:i?r.error:null,isPending:i&&r.isRunning,resetError:s,run:l}}function K(e){return e.environmentId===null||e.cwd===null?null:{environmentId:e.environmentId,cwd:e.cwd}}function q(e,t){let n=(0,V.c)(6),r;n[0]===e?r=n[1]:(r=A.stateAtom(e),n[0]=e,n[1]=r);let i=h(r),a;return n[2]!==t||n[3]!==i.isRunning||n[4]!==i.operation?(a=i.isRunning&&i.operation!==null&&t.some(e=>W[e]===i.operation),n[2]=t,n[3]=i.isRunning,n[4]=i.operation,n[5]=a):a=n[5],a}function J(e){let t=(0,V.c)(7),n;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(n={reportFailure:!1},t[0]=n):n=t[0];let r=O(j.init,n),i;t[1]!==r||t[2]!==e?(i=async()=>{let t=K(e);return t===null?d(a(new k({operation:`init`,environmentId:e.environmentId,cwd:e.cwd}))):r({environmentId:t.environmentId,input:{cwd:t.cwd}})},t[1]=r,t[2]=e,t[3]=i):i=t[3];let o=i,s;return t[4]!==o||t[5]!==e?(s={kind:`init`,label:`Initializing repository`,scope:e,action:o},t[4]=o,t[5]=e,t[6]=s):s=t[6],G(s)}function oe(e){let t=(0,V.c)(11),n;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(n={reportFailure:!1},t[0]=n):n=t[0];let r=O(j.pull,n),i;t[1]!==e.cwd||t[2]!==e.environmentId?(i=e.environmentId!==null&&e.cwd!==null?j.status({environmentId:e.environmentId,input:{cwd:e.cwd}}):null,t[1]=e.cwd,t[2]=e.environmentId,t[3]=i):i=t[3];let o=D(i),s;t[4]!==r||t[5]!==e?(s=async()=>{let t=K(e);return t===null?d(a(new k({operation:`pull`,environmentId:e.environmentId,cwd:e.cwd}))):r({environmentId:t.environmentId,input:{cwd:t.cwd}})},t[4]=r,t[5]=e,t[6]=s):s=t[6];let c=s,l;return t[7]!==c||t[8]!==e||t[9]!==o.refresh?(l={kind:`pull`,label:`Pulling latest changes...`,scope:e,action:c,onSuccess:o.refresh},t[7]=c,t[8]=e,t[9]=o.refresh,t[10]=l):l=t[10],G(l)}function se(e){let t=(0,V.c)(13),n;t[0]===e?n=t[1]:(n=A.runStackedAction(e),t[0]=e,t[1]=n);let r;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(r={reportFailure:!1},t[2]=r):r=t[2];let i=O(n,r),o;t[3]!==e.cwd||t[4]!==e.environmentId?(o=e.environmentId!==null&&e.cwd!==null?j.status({environmentId:e.environmentId,input:{cwd:e.cwd}}):null,t[3]=e.cwd,t[4]=e.environmentId,t[5]=o):o=t[5];let s=D(o),c;t[6]!==i||t[7]!==e?(c=async t=>K(e)===null?d(a(new k({operation:`run_change_request`,environmentId:e.environmentId,cwd:e.cwd}))):i(t),t[6]=i,t[7]=e,t[8]=c):c=t[8];let l=c,u;return t[9]!==l||t[10]!==e||t[11]!==s.refresh?(u={kind:`runStackedAction`,label:`Running source control action`,scope:e,action:l,onSuccess:s.refresh,managedExternally:!0},t[9]=l,t[10]=e,t[11]=s.refresh,t[12]=u):u=t[12],G(u)}function ce(e){let t=(0,V.c)(11),n;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(n={reportFailure:!1},t[0]=n):n=t[0];let r=O(M.publishRepository,n),i;t[1]!==e.cwd||t[2]!==e.environmentId?(i=e.environmentId!==null&&e.cwd!==null?j.status({environmentId:e.environmentId,input:{cwd:e.cwd}}):null,t[1]=e.cwd,t[2]=e.environmentId,t[3]=i):i=t[3];let o=D(i),s;t[4]!==r||t[5]!==e?(s=async t=>{let n=K(e);return n===null?d(a(new k({operation:`publish_repository`,environmentId:e.environmentId,cwd:e.cwd}))):r({environmentId:n.environmentId,input:{cwd:n.cwd,...t}})},t[4]=r,t[5]=e,t[6]=s):s=t[6];let c=s,l;return t[7]!==c||t[8]!==e||t[9]!==o.refresh?(l={kind:`publishRepository`,label:`Publishing repository`,scope:e,action:c,onSuccess:o.refresh},t[7]=c,t[8]=e,t[9]=o.refresh,t[10]=l):l=t[10],G(l)}function Y(e){let t=(0,V.c)(7),n;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(n={reportFailure:!1},t[0]=n):n=t[0];let r=O(U.preparePullRequestThread,n),i;t[1]!==r||t[2]!==e?(i=async t=>{let n=K(e);return n===null?d(a(new k({operation:`prepare_pull_request_thread`,environmentId:e.environmentId,cwd:e.cwd}))):t.mode===`worktree`&&t.threadId!==void 0&&!E(n.environmentId,`orchestration:operate`)?d(a(new u({requiredScope:p,message:`This connection cannot change threads.`}))):r({environmentId:n.environmentId,input:{cwd:n.cwd,reference:t.reference,mode:t.mode,...t.threadId?{threadId:t.threadId}:{}}})},t[1]=r,t[2]=e,t[3]=i):i=t[3];let o=i,s;return t[4]!==o||t[5]!==e?(s={kind:`preparePullRequestThread`,label:`Preparing pull request thread`,scope:e,action:o},t[4]=o,t[5]=e,t[6]=s):s=t[6],G(s)}function X(e){return e.environmentId===null||e.cwd===null||e.reference===null?null:m(i(c.get(U.pullRequestResolution({environmentId:e.environmentId,input:{cwd:e.cwd,reference:e.reference}}))))}function le(e){let t=(0,V.c)(12),n;t[0]!==e.cwd||t[1]!==e.environmentId||t[2]!==e.reference?(n=e.environmentId!==null&&e.cwd!==null&&e.reference!==null?U.pullRequestResolution({environmentId:e.environmentId,input:{cwd:e.cwd,reference:e.reference}}):null,t[0]=e.cwd,t[1]=e.environmentId,t[2]=e.reference,t[3]=n):n=t[3];let r=D(n),i;t[4]===e?i=t[5]:(i=X(e),t[4]=e,t[5]=i);let a=i,o=r.data??a,s=r.isPending&&a===null,c;return t[6]!==r.error||t[7]!==r.isPending||t[8]!==r.refresh||t[9]!==o||t[10]!==s?(c={data:o,error:r.error,isPending:s,isFetching:r.isPending,refresh:r.refresh},t[6]=r.error,t[7]=r.isPending,t[8]=r.refresh,t[9]=o,t[10]=s,t[11]=c):c=t[11],c}function ue(e,t){let n=(0,V.c)(10),r;n[0]===t?r=n[1]:(r=e=>L(e,t).settings.pullRequestMergeMethod,n[0]=t,n[1]=r);let i=C(e,r),a=w(de),o=w(I),s=ee(),c=S(),l;return n[2]!==e||n[3]!==o||n[4]!==a||n[5]!==c||n[6]!==i||n[7]!==t||n[8]!==s?(l=()=>{if(i!=null)return i;if(Object.keys(a).length===0)return;let n=s.find(n=>n.environmentId===e&&n.id===t);if(!n)return;let r=z({projects:s,settings:o,primaryEnvironmentId:c}).get(ae(n))??R(n,o);return a[r]},n[2]=e,n[3]=o,n[4]=a,n[5]=c,n[6]=i,n[7]=t,n[8]=s,n[9]=l):l=n[9],l}function de(e){return e.pullRequestMergeMethodOverrides}var fe={merge:`Merge requested`,ready:`Marked ready for review`,draft:`Converted to draft`,close:`Pull request closed`,reopen:`Pull request reopened`,"update-branch":`Branch updated with the base branch`,"enable-auto-merge":`Auto-merge enabled`,"disable-auto-merge":`Auto-merge disabled`,revert:`Revert pull request opened`,"delete-branch":`Branch deleted`,"approve-workflows":`Workflows approved`},pe={merge:`Could not merge this pull request`,ready:`Could not mark this ready for review`,draft:`Could not convert this to a draft`,close:`Could not close this pull request`,reopen:`Could not reopen this pull request`,"update-branch":`Could not update this branch`,"enable-auto-merge":`Could not enable auto-merge`,"disable-auto-merge":`Could not disable auto-merge`,revert:`Could not open a revert pull request`,"delete-branch":`Could not delete this branch`,"approve-workflows":`Could not approve workflows`},Z={merge:`The host refused the merge. Check that you have write access, that the checks it requires have passed, and that the branch is not conflicting.`,ready:`The host refused it. Check that you have write access to this repository.`,draft:`The host refused it. Check that you have write access to this repository.`,close:`The host refused it. Check that you have write access, or that you opened it.`,reopen:`The host refused it. Check that you have write access, and that the branch still exists.`,"update-branch":`The host refused it. Check that you have write access, and that the base branch has not diverged in a way the host cannot merge.`,"enable-auto-merge":`The host refused it. Check that auto-merge is enabled for this repository and that you have write access.`,"disable-auto-merge":`The host refused it. Check that you have write access to this repository.`,revert:`The host refused it. Check that you have write access and that this pull request was merged on the host.`,"delete-branch":`The host refused it. Check that you have write access to the source repository and that the branch has not moved since this page loaded.`,"approve-workflows":`The host refused it. Check that you have Actions write access and that these workflow runs are still awaiting approval.`};function me({environmentId:e,reference:t,onSuccess:n,resolveMergeMethod:r}){let i=O(P.runAction,{reportFailure:!1}),[a,o]=(0,B.useState)(!1),s=(0,B.useRef)(!1);return{actionPending:a,perform:async(a,c)=>{if(!(s.current||t===null)){s.current=!0,o(!0);try{let o=await i({environmentId:e,input:{...t,action:a,...c?{mergeMethod:c}:r?{resolveMergeMethod:r}:{}}});if(o._tag===`Failure`)throw v(o);x.add({type:`success`,title:fe[a]}),n?.(a)}catch(e){x.add({type:`error`,title:pe[a],description:F(e,Z[a])})}finally{s.current=!1,o(!1)}}}}}function Q(e){let t=O(P.runAction,{reportFailure:!1}),n=(0,B.useRef)(new Set),[r,i]=(0,B.useState)(()=>new Set);return{close:(0,B.useCallback)(async r=>{let a=r.filter(e=>{let t=N(e);return e.state!==`open`||n.current.has(t)?!1:(n.current.add(t),!0)});if(a.length===0)return;i(new Set(n.current));let o=0,s=[];await Promise.all(a.map(async r=>{try{let n=await t({environmentId:r.environmentId,input:{projectId:r.projectId,host:r.host,repository:r.repository,number:r.number,action:`close`}});if(n._tag===`Failure`)throw v(n);o++,e(r)}catch(e){s.push(`#${r.number}: ${F(e,Z.close)}`)}finally{n.current.delete(N(r)),i(new Set(n.current))}})),x.add({type:s.length>0?`error`:`success`,title:s.length>0?`Closed ${o} of ${a.length} pull requests`:`Closed ${o} pull request${o===1?``:`s`}`,...s.length>0?{description:s.slice(0,3).join(`
2
2
  `)}:{}})},[e,t]),closingKeys:r}}var $=new Map;function he(e){let t=(0,V.c)(21),{environmentId:n,detail:i}=e,a=ie(),o=i?.workspaceRoot??null,s;t[0]!==n||t[1]!==o?(s={environmentId:n,cwd:o},t[0]=n,t[1]=o,t[2]=s):s=t[2];let c=Y(s),[u,d]=(0,B.useState)(null),f;t[3]===a?f=t[4]:(f=async(e,t,n)=>{let i=n??await a(e).then(xe,be);if(i===null)return null;let o=r.getState();if(t===null)return i;let s=o.getComposerDraft(i.draftId),c=s?.reviewComments??[],l=re({prompt:s?.prompt??``,lastHandoffPrompt:$.get(i.draftId)},t.prompt);return $.set(i.draftId,t.prompt),o.setPrompt(i.draftId,l),o.setReviewComments(i.draftId,ne(c,t.reviewComments??[])),i},t[3]=a,t[4]=f);let p=f,m;t[5]!==i||t[6]!==n||t[7]!==u||t[8]!==p?(m=async(e,t)=>{if(!i||u!==null)return;d(e);let r=l(n,i.projectId),a=await p(r,t);if(d(null),a===null){x.add({type:`error`,title:`Could not open a thread`,description:`Try again from the project, or open a thread first.`});return}x.add({type:`success`,title:`Asked in a thread`,description:t.prompt.length>0?`The question is in the composer — read it over, then send.`:`The pull request is in the composer — type your question, then send.`})},t[5]=i,t[6]=n,t[7]=u,t[8]=p,t[9]=m):m=t[9];let h=m,g;t[10]!==i||t[11]!==n||t[12]!==u||t[13]!==a||t[14]!==p||t[15]!==c?(g=async(e,t,r)=>{let o=r===void 0?`worktree`:r;if(!i||u!==null)return;d(e);let s=x.add({type:`loading`,title:`Preparing the pull request checkout...`}),f=l(n,i.projectId),m=await a(f).then(ye,ve);if(m===null){d(null),x.update(s,{type:`error`,title:`Could not open a thread for the checkout`,description:`Try again from the project, or open a thread first.`});return}let h=await c.run({reference:i.url,mode:o,threadId:m.threadId});if(h._tag===`Failure`){d(null);let e=c.error instanceof Error?c.error.message:null;x.update(s,{type:`error`,title:`Could not prepare the pull request checkout`,...e?{description:e}:{}});return}if(!await a(f,{branch:h.value.branch,worktreePath:h.value.worktreePath,envMode:h.value.worktreePath===null?`local`:`worktree`}).then(_e,ge)){d(null),x.update(s,{type:`error`,title:`Checked out, but the thread stayed where it was`,description:`The checkout is ready on \`${h.value.branch}\`. Point a thread at it from the branch picker, then ask again.`});return}d(null);let g={type:`warning`,title:`Checked out, but not on the latest commits`,description:`The checkout could not be moved onto the pull request's latest commits, so the code there is older than the pull request. Uncommitted work or local commits keep it where it is.`};if(t===null){x.update(s,h.value.isOnPullRequestHead?{type:`success`,title:o===`local`?`Checked out here`:`Checked out`,description:o===`local`?`This repository is on the pull request's branch, with a thread open on it.`:`The pull request is in its own worktree, with a thread open on it.`}:g);return}await p(f,t,m),x.update(s,h.value.isOnPullRequestHead?{type:`success`,title:`Checkout ready`,description:`The task is in the composer — read it over, then send.`}:g)},t[10]=i,t[11]=n,t[12]=u,t[13]=a,t[14]=p,t[15]=c,t[16]=g):g=t[16];let _=g,v;return t[17]!==u||t[18]!==h||t[19]!==_?(v={handoff:u,startAsk:h,startHandoff:_},t[17]=u,t[18]=h,t[19]=_,t[20]=v):v=t[20],v}function ge(){return!1}function _e(e){return e!==null}function ve(){return null}function ye(e){return e}function be(){return null}function xe(e){return e}export{X as a,le as c,J as d,oe as f,he as i,q as l,Q as n,se as o,ue as r,Y as s,me as t,ce as u};
3
- //# sourceMappingURL=usePullRequestActions-D53oZord.js.map
3
+ //# sourceMappingURL=usePullRequestActions-cmzmOrJ-.js.map
@@ -1,2 +1,2 @@
1
- import{n as e}from"./jsx-runtime-BnjsACtP.js";import{Ht as t,Nt as n,Vt as r}from"./utils-CBe1bHL7.js";import{T as i,i as a}from"./useSettings-VTow9ZEM.js";import{V as o}from"./settingsLayout-DrhqvTJ8.js";var s=e();function c(e,c){let l=(0,s.c)(5),{targets:u}=o(),{environments:d}=i(),f;return l[0]!==c||l[1]!==d||l[2]!==e||l[3]!==u?(f=(i,o)=>{let s=c.find(e=>e.instanceId===i);for(let c of u){let l=d.find(e=>e.environmentId===c.environmentId),u=l?.serverConfig;if(!u)continue;let f=r(t(u.providers),c.settings,c.projectId).find(e=>e.instanceId===i),p=n(a(c.settings,e),u.providers).get(i);if(!f?.enabled||!f.isAvailable||f.driverKind!==s?.driverKind||!p?.some(e=>e.slug===o&&!e.isUnavailable))return`This model is unavailable on ${l?.label??`a selected environment`}. Select that environment to choose its model separately.`}return null},l[0]=c,l[1]=d,l[2]=e,l[3]=u,l[4]=f):f=l[4],f}export{c as t};
2
- //# sourceMappingURL=useScopedModelAvailability-CeAUx0qZ.js.map
1
+ import{n as e}from"./jsx-runtime-BnjsACtP.js";import{Ht as t,Nt as n,Vt as r}from"./utils-CBe1bHL7.js";import{T as i,i as a}from"./useSettings-CHt2_4He.js";import{V as o}from"./settingsLayout-vgYGia0Q.js";var s=e();function c(e,c){let l=(0,s.c)(5),{targets:u}=o(),{environments:d}=i(),f;return l[0]!==c||l[1]!==d||l[2]!==e||l[3]!==u?(f=(i,o)=>{let s=c.find(e=>e.instanceId===i);for(let c of u){let l=d.find(e=>e.environmentId===c.environmentId),u=l?.serverConfig;if(!u)continue;let f=r(t(u.providers),c.settings,c.projectId).find(e=>e.instanceId===i),p=n(a(c.settings,e),u.providers).get(i);if(!f?.enabled||!f.isAvailable||f.driverKind!==s?.driverKind||!p?.some(e=>e.slug===o&&!e.isUnavailable))return`This model is unavailable on ${l?.label??`a selected environment`}. Select that environment to choose its model separately.`}return null},l[0]=c,l[1]=d,l[2]=e,l[3]=u,l[4]=f):f=l[4],f}export{c as t};
2
+ //# sourceMappingURL=useScopedModelAvailability-kczZtr1M.js.map