@cortexkit/opencode-openai-auth 1.23.0 → 1.23.2

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 (234) hide show
  1. package/dist/bin.js +8 -8
  2. package/dist/{index-897br01q.js → index-49ncs7dr.js} +1 -1
  3. package/dist/{index-s7dwe5n8.js → index-by5wfvqm.js} +20 -20
  4. package/dist/{index-bbrpg1ms.js → index-drm4dk5y.js} +1 -1
  5. package/dist/index-nd2ks7er.js +2 -0
  6. package/dist/index-t876xhkr.js +60 -0
  7. package/dist/{index-fasy4end.js → index-td4g5dc9.js} +1 -1
  8. package/dist/{index-7hcv94as.js → index-v8w8j1wx.js} +1 -1
  9. package/dist/{index-r31f36mn.js → index-v8wrmhyp.js} +1 -1
  10. package/dist/{index-bpx4spyr.js → index-wjp3q15r.js} +1 -1
  11. package/dist/{index-f340dq90.js → index-x00sxt2w.js} +10 -10
  12. package/dist/index.d.ts +4 -3
  13. package/dist/index.js +1 -1
  14. package/dist/{runtime-layout-B07ApQZL.d.ts → internal-DacVgEWs.d.ts} +86 -663
  15. package/dist/rpc/port-file.js +1 -1
  16. package/dist/rpc/protocol.js +1 -1
  17. package/dist/rpc/rpc-client.js +1 -1
  18. package/dist/runtime-layout-Dcbj_Rq3.d.ts +650 -0
  19. package/dist/{sidebar-state--OTpRzFd.d.ts → sidebar-state-L--CdbLi.d.ts} +4 -15
  20. package/dist/sidebar-state.d.ts +1 -1
  21. package/dist/sidebar-state.js +1 -1
  22. package/dist/tui-preferences.js +1 -1
  23. package/dist/tui.d.ts +5 -2
  24. package/dist/v2/server.d.ts +2 -1
  25. package/dist/v2/server.js +4 -4
  26. package/package.json +6 -6
  27. package/src/tui-compiled/raw/shared/054118b2705fdc20-ansi.js +98 -0
  28. package/src/tui-compiled/raw/shared/0895e780489c494d-window.js +33 -0
  29. package/src/tui-compiled/raw/shared/0b7d24474e2f33e9-credential-redaction.js +424 -0
  30. package/src/tui-compiled/raw/shared/0c9533222cb4380c-namespace.js +224 -0
  31. package/src/tui-compiled/raw/shared/112607e46a5b5f58-accounts.js +393 -0
  32. package/src/tui-compiled/raw/shared/136fa4abe48ad69d-cachekeep.js +411 -0
  33. package/src/tui-compiled/raw/shared/1547bd74f4214d2d-index.js +28 -0
  34. package/src/tui-compiled/raw/shared/1567207f323dc733-codex-http.js +44 -0
  35. package/src/tui-compiled/raw/shared/15f402885cbb2fb3-envelope-loss.js +151 -0
  36. package/src/tui-compiled/raw/shared/18df43cab4563acf-families.js +149 -0
  37. package/src/tui-compiled/raw/shared/1a4c289eec261e04-codex-instructions.js +59 -0
  38. package/src/tui-compiled/raw/shared/1afd446e190ef85c-vault-messages.js +12 -0
  39. package/src/tui-compiled/raw/shared/1b06ec96856ff8b9-codex-endpoint.js +17 -0
  40. package/src/tui-compiled/raw/shared/1e2f1a89bb34a773-vault-adapter.js +110 -0
  41. package/src/tui-compiled/raw/shared/2194fb8e8b42d7d5-insula-quota.js +73 -0
  42. package/src/tui-compiled/raw/shared/22b2bce42f2d6806-handle.js +10 -0
  43. package/src/tui-compiled/raw/shared/2577ec69f9973ae9-quota-normalize.js +13 -14
  44. package/src/tui-compiled/raw/shared/26055d4e5ad5e71f-codex-request.js +198 -0
  45. package/src/tui-compiled/raw/shared/26b57ac4c3b0c3f6-unconfirmed-retain-counter.js +41 -0
  46. package/src/tui-compiled/raw/shared/2bb681e99c2721d7-registry.js +538 -0
  47. package/src/tui-compiled/raw/shared/2dce6e9613993329-quota-manager.js +13 -20
  48. package/src/tui-compiled/raw/shared/2ec33b3e2b8ac38a-terminal.js +168 -0
  49. package/src/tui-compiled/raw/shared/30bcca1d1b4240a0-pool-session-pins.js +32 -0
  50. package/src/tui-compiled/raw/shared/3af9a210aa2ccdf2-codex-call-status.js +21 -0
  51. package/src/tui-compiled/raw/shared/3b31b36bf0877602-wording.js +120 -0
  52. package/src/tui-compiled/raw/shared/3c4c1a2d3fc92726-failure.js +59 -0
  53. package/src/tui-compiled/raw/shared/3dfe71eec6e0487d-presets.js +240 -0
  54. package/src/tui-compiled/raw/shared/43de3a5c4845cfc1-pool-adapter.js +149 -0
  55. package/src/tui-compiled/raw/shared/49353b63a833c8fb-session-cache-policy.js +60 -0
  56. package/src/tui-compiled/raw/shared/4adf46e07e025363-axes.js +7 -0
  57. package/src/tui-compiled/raw/shared/4ba847b77580b1eb-confirm.js +21 -0
  58. package/src/tui-compiled/raw/shared/4d05c2d7a531aece-oauth.js +48 -36
  59. package/src/tui-compiled/raw/shared/5018d4665e969588-limit-policy.js +159 -0
  60. package/src/tui-compiled/raw/shared/595bdf3fff13ba79-limit-identity.js +49 -0
  61. package/src/tui-compiled/raw/shared/59def9e82b61204a-session-cache-activity.js +35 -0
  62. package/src/tui-compiled/raw/shared/5d806e1a305d14f5-commands.js +879 -0
  63. package/src/tui-compiled/raw/shared/5fc39320fa8bd3a0-limit-registry.js +473 -0
  64. package/src/tui-compiled/raw/shared/63c1ee7e70e85e8d-vault.js +1 -0
  65. package/src/tui-compiled/raw/shared/6545ab7f757314b7-refresh-all-quota.js +237 -0
  66. package/src/tui-compiled/raw/shared/66937534c260d20b-stable-json.js +11 -0
  67. package/src/tui-compiled/raw/shared/7056acef1b021f19-bridge.js +10 -0
  68. package/src/tui-compiled/raw/shared/72d2ca42883809b4-marker.js +107 -0
  69. package/src/tui-compiled/raw/shared/775431e21f469203-record.js +3 -0
  70. package/src/tui-compiled/raw/shared/799f3ade4efbd1ea-opencode-v1.js +47 -0
  71. package/src/tui-compiled/raw/shared/7b2a0471b29e4f5e-wake.js +47 -0
  72. package/src/tui-compiled/raw/shared/7b5d6afff4ff32b9-select.js +159 -0
  73. package/src/tui-compiled/raw/shared/7bf96bf4d9249b3d-vault-billing.js +108 -0
  74. package/src/tui-compiled/raw/shared/7c98bde36aad4819-input-transformations.js +34 -0
  75. package/src/tui-compiled/raw/shared/7fb0418303f20a10-index.js +3 -0
  76. package/src/tui-compiled/raw/shared/806e12ccbad34388-pi-wait.js +51 -0
  77. package/src/tui-compiled/raw/shared/81ae201b724cac14-menu.js +73 -0
  78. package/src/tui-compiled/raw/shared/8349ed25dc629e97-scope.js +10 -0
  79. package/src/tui-compiled/raw/shared/86da3379973780b9-limit-provenance.js +60 -0
  80. package/src/tui-compiled/raw/shared/8aba66ed486d30a7-decide.js +425 -0
  81. package/src/tui-compiled/raw/shared/8c0c8df25a5dca1f-manager.js +735 -0
  82. package/src/tui-compiled/raw/shared/8c42bbec02f59636-vault-routing.js +212 -0
  83. package/src/tui-compiled/raw/shared/8ca6175bfae53e13-envelope.js +123 -0
  84. package/src/tui-compiled/raw/shared/8d0245e41049d83f-header-classifier.js +121 -0
  85. package/src/tui-compiled/raw/shared/9c162809179c7560-login.js +89 -0
  86. package/src/tui-compiled/raw/shared/a1f495296a4b756f-frame-turn.js +72 -0
  87. package/src/tui-compiled/raw/shared/a37138dcbd893f55-hold-bounds.js +5 -0
  88. package/src/tui-compiled/raw/shared/aa7fb10d77a2cccd-vault-account-menu.js +133 -0
  89. package/src/tui-compiled/raw/shared/adc5eeb5a8d28280-persistence.js +9 -0
  90. package/src/tui-compiled/raw/shared/b301c79e6378d1fb-vault.js +678 -0
  91. package/src/tui-compiled/raw/shared/b3c11de5f36e617a-reset.js +44 -0
  92. package/src/tui-compiled/raw/shared/ba6535c610d1edb3-pool-source-state.js +100 -0
  93. package/src/tui-compiled/raw/shared/bd4aef685681048c-duration.js +20 -0
  94. package/src/tui-compiled/raw/shared/bd5977eca210d2b8-index.js +662 -0
  95. package/src/tui-compiled/raw/shared/bfc46d34f4c9db33-limit-recovery.js +127 -0
  96. package/src/tui-compiled/raw/shared/c66495424ad84aee-hold.js +25 -0
  97. package/src/tui-compiled/raw/shared/c6a67b836bd5afcd-vault-command-menu.js +300 -0
  98. package/src/tui-compiled/raw/shared/c9340fb545c4e5de-internal.js +73 -0
  99. package/src/tui-compiled/raw/shared/c954c6447b7b9b64-activity.js +52 -0
  100. package/src/tui-compiled/raw/shared/cba8b0aee46b8526-codex-lite.js +85 -0
  101. package/src/tui-compiled/raw/shared/cec39ccddab4fe9c-labels.js +11 -0
  102. package/src/tui-compiled/raw/shared/cef0f2346957e83c-index.js +552 -0
  103. package/src/tui-compiled/raw/shared/cf7dedf24f902d68-dump-size.js +41 -0
  104. package/src/tui-compiled/raw/shared/d422d6dbc4e35199-background-quota-refresh.js +107 -0
  105. package/src/tui-compiled/raw/shared/d5b268767d330507-doctor.js +81 -0
  106. package/src/tui-compiled/raw/shared/d7ac5ca41f49121b-index.js +12 -0
  107. package/src/tui-compiled/raw/shared/d7fa77560855dee2-jitter.js +9 -0
  108. package/src/tui-compiled/raw/shared/de7f7d8803624369-path.js +31 -0
  109. package/src/tui-compiled/raw/shared/df0bdc74fb0c0db0-limit-mark.js +27 -0
  110. package/src/tui-compiled/raw/shared/e26c2bb5722ab047-routing-hold.js +23 -0
  111. package/src/tui-compiled/raw/shared/e2ae081583adfce3-dump.js +80 -0
  112. package/src/tui-compiled/raw/shared/e44ba1b3a9903f5d-reset-credits.js +483 -0
  113. package/src/tui-compiled/raw/shared/e5229952fc12f647-codex-models.js +34 -0
  114. package/src/tui-compiled/raw/shared/e8fda84e90176436-uuid-v7.js +13 -0
  115. package/src/tui-compiled/raw/shared/ea56007991dbf068-terminal.js +19 -0
  116. package/src/tui-compiled/raw/shared/ec6f1d96e7d70174-quota-refusal.js +145 -0
  117. package/src/tui-compiled/raw/shared/f03d7b43a214a4a1-canonical-input.js +42 -0
  118. package/src/tui-compiled/raw/shared/f1012265b3a768c7-merge-laws.js +31 -0
  119. package/src/tui-compiled/raw/shared/f2ca864fe967415a-cache-policy.js +198 -0
  120. package/src/tui-compiled/raw/shared/f317a4740f9d76f8-identity.js +21 -0
  121. package/src/tui-compiled/raw/shared/f607353c4126272a-routing-wait.js +19 -0
  122. package/src/tui-compiled/raw/shared/f6189f5c9aee31eb-decision.js +55 -0
  123. package/src/tui-compiled/raw/shared/f6d728f5e601f98b-request-history.js +120 -0
  124. package/src/tui-compiled/raw/shared/f981e6b15fb76cdb-codex-body.js +28 -0
  125. package/src/tui-compiled/raw/shared/fda579e5a0a54165-codex-effort.js +60 -0
  126. package/src/tui-compiled/raw/sidebar-state.js +54 -4
  127. package/src/tui-compiled/raw/tui/v2-dialog.js +1 -1
  128. package/src/tui-compiled/raw/tui.tsx +27 -5
  129. package/src/tui-compiled/runtime/shared/054118b2705fdc20-ansi.js +98 -0
  130. package/src/tui-compiled/runtime/shared/0895e780489c494d-window.js +33 -0
  131. package/src/tui-compiled/runtime/shared/0b7d24474e2f33e9-credential-redaction.js +424 -0
  132. package/src/tui-compiled/runtime/shared/0c9533222cb4380c-namespace.js +224 -0
  133. package/src/tui-compiled/runtime/shared/112607e46a5b5f58-accounts.js +393 -0
  134. package/src/tui-compiled/runtime/shared/136fa4abe48ad69d-cachekeep.js +411 -0
  135. package/src/tui-compiled/runtime/shared/1547bd74f4214d2d-index.js +28 -0
  136. package/src/tui-compiled/runtime/shared/1567207f323dc733-codex-http.js +44 -0
  137. package/src/tui-compiled/runtime/shared/15f402885cbb2fb3-envelope-loss.js +151 -0
  138. package/src/tui-compiled/runtime/shared/18df43cab4563acf-families.js +149 -0
  139. package/src/tui-compiled/runtime/shared/1a4c289eec261e04-codex-instructions.js +59 -0
  140. package/src/tui-compiled/runtime/shared/1afd446e190ef85c-vault-messages.js +12 -0
  141. package/src/tui-compiled/runtime/shared/1b06ec96856ff8b9-codex-endpoint.js +17 -0
  142. package/src/tui-compiled/runtime/shared/1e2f1a89bb34a773-vault-adapter.js +110 -0
  143. package/src/tui-compiled/runtime/shared/2194fb8e8b42d7d5-insula-quota.js +73 -0
  144. package/src/tui-compiled/runtime/shared/22b2bce42f2d6806-handle.js +10 -0
  145. package/src/tui-compiled/runtime/shared/2577ec69f9973ae9-quota-normalize.js +13 -14
  146. package/src/tui-compiled/runtime/shared/26055d4e5ad5e71f-codex-request.js +198 -0
  147. package/src/tui-compiled/runtime/shared/26b57ac4c3b0c3f6-unconfirmed-retain-counter.js +41 -0
  148. package/src/tui-compiled/runtime/shared/2bb681e99c2721d7-registry.js +538 -0
  149. package/src/tui-compiled/runtime/shared/2dce6e9613993329-quota-manager.js +13 -20
  150. package/src/tui-compiled/runtime/shared/2ec33b3e2b8ac38a-terminal.js +168 -0
  151. package/src/tui-compiled/runtime/shared/30bcca1d1b4240a0-pool-session-pins.js +32 -0
  152. package/src/tui-compiled/runtime/shared/3af9a210aa2ccdf2-codex-call-status.js +21 -0
  153. package/src/tui-compiled/runtime/shared/3b31b36bf0877602-wording.js +120 -0
  154. package/src/tui-compiled/runtime/shared/3c4c1a2d3fc92726-failure.js +59 -0
  155. package/src/tui-compiled/runtime/shared/3dfe71eec6e0487d-presets.js +240 -0
  156. package/src/tui-compiled/runtime/shared/43de3a5c4845cfc1-pool-adapter.js +149 -0
  157. package/src/tui-compiled/runtime/shared/49353b63a833c8fb-session-cache-policy.js +60 -0
  158. package/src/tui-compiled/runtime/shared/4adf46e07e025363-axes.js +7 -0
  159. package/src/tui-compiled/runtime/shared/4ba847b77580b1eb-confirm.js +21 -0
  160. package/src/tui-compiled/runtime/shared/4d05c2d7a531aece-oauth.js +48 -36
  161. package/src/tui-compiled/runtime/shared/5018d4665e969588-limit-policy.js +159 -0
  162. package/src/tui-compiled/runtime/shared/595bdf3fff13ba79-limit-identity.js +49 -0
  163. package/src/tui-compiled/runtime/shared/59def9e82b61204a-session-cache-activity.js +35 -0
  164. package/src/tui-compiled/runtime/shared/5d806e1a305d14f5-commands.js +879 -0
  165. package/src/tui-compiled/runtime/shared/5fc39320fa8bd3a0-limit-registry.js +473 -0
  166. package/src/tui-compiled/runtime/shared/63c1ee7e70e85e8d-vault.js +1 -0
  167. package/src/tui-compiled/runtime/shared/6545ab7f757314b7-refresh-all-quota.js +237 -0
  168. package/src/tui-compiled/runtime/shared/66937534c260d20b-stable-json.js +11 -0
  169. package/src/tui-compiled/runtime/shared/7056acef1b021f19-bridge.js +10 -0
  170. package/src/tui-compiled/runtime/shared/72d2ca42883809b4-marker.js +107 -0
  171. package/src/tui-compiled/runtime/shared/775431e21f469203-record.js +3 -0
  172. package/src/tui-compiled/runtime/shared/799f3ade4efbd1ea-opencode-v1.js +47 -0
  173. package/src/tui-compiled/runtime/shared/7b2a0471b29e4f5e-wake.js +47 -0
  174. package/src/tui-compiled/runtime/shared/7b5d6afff4ff32b9-select.js +159 -0
  175. package/src/tui-compiled/runtime/shared/7bf96bf4d9249b3d-vault-billing.js +108 -0
  176. package/src/tui-compiled/runtime/shared/7c98bde36aad4819-input-transformations.js +34 -0
  177. package/src/tui-compiled/runtime/shared/7fb0418303f20a10-index.js +3 -0
  178. package/src/tui-compiled/runtime/shared/806e12ccbad34388-pi-wait.js +51 -0
  179. package/src/tui-compiled/runtime/shared/81ae201b724cac14-menu.js +73 -0
  180. package/src/tui-compiled/runtime/shared/8349ed25dc629e97-scope.js +10 -0
  181. package/src/tui-compiled/runtime/shared/86da3379973780b9-limit-provenance.js +60 -0
  182. package/src/tui-compiled/runtime/shared/8aba66ed486d30a7-decide.js +425 -0
  183. package/src/tui-compiled/runtime/shared/8c0c8df25a5dca1f-manager.js +735 -0
  184. package/src/tui-compiled/runtime/shared/8c42bbec02f59636-vault-routing.js +212 -0
  185. package/src/tui-compiled/runtime/shared/8ca6175bfae53e13-envelope.js +123 -0
  186. package/src/tui-compiled/runtime/shared/8d0245e41049d83f-header-classifier.js +121 -0
  187. package/src/tui-compiled/runtime/shared/9c162809179c7560-login.js +89 -0
  188. package/src/tui-compiled/runtime/shared/a1f495296a4b756f-frame-turn.js +72 -0
  189. package/src/tui-compiled/runtime/shared/a37138dcbd893f55-hold-bounds.js +5 -0
  190. package/src/tui-compiled/runtime/shared/aa7fb10d77a2cccd-vault-account-menu.js +133 -0
  191. package/src/tui-compiled/runtime/shared/adc5eeb5a8d28280-persistence.js +9 -0
  192. package/src/tui-compiled/runtime/shared/b301c79e6378d1fb-vault.js +678 -0
  193. package/src/tui-compiled/runtime/shared/b3c11de5f36e617a-reset.js +44 -0
  194. package/src/tui-compiled/runtime/shared/ba6535c610d1edb3-pool-source-state.js +100 -0
  195. package/src/tui-compiled/runtime/shared/bd4aef685681048c-duration.js +20 -0
  196. package/src/tui-compiled/runtime/shared/bd5977eca210d2b8-index.js +662 -0
  197. package/src/tui-compiled/runtime/shared/bfc46d34f4c9db33-limit-recovery.js +127 -0
  198. package/src/tui-compiled/runtime/shared/c66495424ad84aee-hold.js +25 -0
  199. package/src/tui-compiled/runtime/shared/c6a67b836bd5afcd-vault-command-menu.js +300 -0
  200. package/src/tui-compiled/runtime/shared/c9340fb545c4e5de-internal.js +73 -0
  201. package/src/tui-compiled/runtime/shared/c954c6447b7b9b64-activity.js +52 -0
  202. package/src/tui-compiled/runtime/shared/cba8b0aee46b8526-codex-lite.js +85 -0
  203. package/src/tui-compiled/runtime/shared/cec39ccddab4fe9c-labels.js +11 -0
  204. package/src/tui-compiled/runtime/shared/cef0f2346957e83c-index.js +552 -0
  205. package/src/tui-compiled/runtime/shared/cf7dedf24f902d68-dump-size.js +41 -0
  206. package/src/tui-compiled/runtime/shared/d422d6dbc4e35199-background-quota-refresh.js +107 -0
  207. package/src/tui-compiled/runtime/shared/d5b268767d330507-doctor.js +81 -0
  208. package/src/tui-compiled/runtime/shared/d7ac5ca41f49121b-index.js +12 -0
  209. package/src/tui-compiled/runtime/shared/d7fa77560855dee2-jitter.js +9 -0
  210. package/src/tui-compiled/runtime/shared/de7f7d8803624369-path.js +31 -0
  211. package/src/tui-compiled/runtime/shared/df0bdc74fb0c0db0-limit-mark.js +27 -0
  212. package/src/tui-compiled/runtime/shared/e26c2bb5722ab047-routing-hold.js +23 -0
  213. package/src/tui-compiled/runtime/shared/e2ae081583adfce3-dump.js +80 -0
  214. package/src/tui-compiled/runtime/shared/e44ba1b3a9903f5d-reset-credits.js +483 -0
  215. package/src/tui-compiled/runtime/shared/e5229952fc12f647-codex-models.js +34 -0
  216. package/src/tui-compiled/runtime/shared/e8fda84e90176436-uuid-v7.js +13 -0
  217. package/src/tui-compiled/runtime/shared/ea56007991dbf068-terminal.js +19 -0
  218. package/src/tui-compiled/runtime/shared/ec6f1d96e7d70174-quota-refusal.js +145 -0
  219. package/src/tui-compiled/runtime/shared/f03d7b43a214a4a1-canonical-input.js +42 -0
  220. package/src/tui-compiled/runtime/shared/f1012265b3a768c7-merge-laws.js +31 -0
  221. package/src/tui-compiled/runtime/shared/f2ca864fe967415a-cache-policy.js +198 -0
  222. package/src/tui-compiled/runtime/shared/f317a4740f9d76f8-identity.js +21 -0
  223. package/src/tui-compiled/runtime/shared/f607353c4126272a-routing-wait.js +19 -0
  224. package/src/tui-compiled/runtime/shared/f6189f5c9aee31eb-decision.js +55 -0
  225. package/src/tui-compiled/runtime/shared/f6d728f5e601f98b-request-history.js +120 -0
  226. package/src/tui-compiled/runtime/shared/f981e6b15fb76cdb-codex-body.js +28 -0
  227. package/src/tui-compiled/runtime/shared/fda579e5a0a54165-codex-effort.js +60 -0
  228. package/src/tui-compiled/runtime/sidebar-state.js +54 -4
  229. package/src/tui-compiled/runtime/tui/v2-dialog.js +1 -1
  230. package/src/tui-compiled/runtime/tui.js +11 -4
  231. package/dist/index-2z4dbnsf.js +0 -60
  232. package/dist/index-x25m9spd.js +0 -2
  233. package/dist/map-D5PHhv4z.d.ts +0 -72
  234. /package/dist/{index-sx9jjkry.js → index-4ktepxn1.js} +0 -0
@@ -1,2 +0,0 @@
1
- import{ge as NZ,he as PZ,je as g,ke as WZ,le as HZ,pe as d,qg as _Z,ug as TZ,wg as RZ}from"./index-f340dq90.js";import{Eg as XZ,Jg as VZ,Kg as YZ,Mg as y,Og as x}from"./index-897br01q.js";import{th as OZ}from"./index-fasy4end.js";import{Ah as A,Bh as JZ,uh as b,vh as $Z}from"./index-sx9jjkry.js";import{createHash as cZ}from"node:crypto";import{constants as oZ,copyFileSync as aZ,mkdirSync as iZ,statSync as sZ}from"node:fs";import{readFile as nZ}from"node:fs/promises";import{homedir as eZ,tmpdir as tZ}from"node:os";import{dirname as Z0,join as h}from"node:path";import{chmod as dZ,mkdir as lZ}from"node:fs/promises";import{dirname as ZZ}from"node:path";function k(Z){let{path:$,defaultValue:X,normalize:J}=Z,V=Promise.resolve(),Y=(B)=>{if(B==="")return X;try{return J(JSON.parse(B))}catch{return X}},G=async()=>{try{if(b)await A(ZZ($),Z.secureDir??!0);return await JZ($,b)}catch(B){if(B.code==="ENOENT")return"";throw B}},z=async()=>{try{return Y(await G())}catch(B){if(B instanceof $Z)throw B;return X}},L=(B,D)=>{let N=V.then(B).then((P)=>D?.onResult?.(P));return V=N.catch(()=>{}),N},U={...x.sidebar,name:Z.lockName??x.sidebar.name,timeoutMs:Z.timeoutMs??x.sidebar.timeoutMs},K=async(B,D,N)=>{await XZ($,D,{serialize:JSON.stringify,beforeRename:async()=>{await N?.beforeCommit?.(),await B.assertOwned()}}),await N?.afterRename?.();try{return await B.assertOwned(),!0}catch(P){if(P instanceof YZ)return!1;throw P}},Q=async(B,D,N)=>{Z.logger?.warn("sidebar lock lost after rename; repairing write",{path:$});try{let P=await y($,U,async(W)=>{let H=B(await z(),D);if(H===void 0)return"skipped";return await K(W,H,N)?"written":"lost-again"});if(P==="lost-again")Z.logger?.warn("sidebar repair lost its lock after rename",{path:$});return{status:"lost-after-rename",repair:P}}catch(P){if(!(P instanceof VZ))throw P;return Z.logger?.warn("sidebar repair lock unavailable; repair skipped",{path:$}),{status:"lost-after-rename",repair:"lock-unavailable"}}},j=async(B,D)=>{let N=D,P=ZZ($),W=Z.secureDir??!0;if(b)await A(P,W);else if(await lZ(P,{recursive:!0,mode:448}),W)await dZ(P,448).catch((F)=>{Z.logger?.warn("sidebar directory permission remediation failed",{error:F instanceof Error?F.message:String(F)})});let H=await y($,U,async(F)=>{let s=async(C)=>({value:C,held:await K(F,C,N)});for(let C=0;C<3;C+=1){let e=await G(),t=B(Y(e));if(t===void 0)return;if(C===0)await N?.beforeRecheck?.();if(await G()!==e)continue;return await s(t)}let n=B(await z());return n===void 0?void 0:await s(n)});if(H===void 0)return{status:"skipped"};if(H.held)return{status:"written"};let i=D?.repair??Z.repair;if(!i)return Z.logger?.warn("sidebar lock lost after rename; write not repaired",{path:$}),{status:"lost-after-rename",repair:"none"};return await Q(i,H.value,N)};return{read:z,write:(B,D)=>L(()=>j(()=>B,D),D),update:(B,D)=>L(()=>j(B,D),D)}}function v0(Z){let $=Z?.credits;if($===null||typeof $!=="object")return;let{hasCredits:X,unlimited:J,balance:V}=$;if(typeof X!=="boolean"||typeof J!=="boolean")return;return WZ({hasCredits:X,unlimited:J,...typeof V==="number"?{balance:V}:{}})}function f0(Z,$=Date.now()){if(!xZ(Z,$))return!1;if(bZ(Z,$))return!1;return RZ(Z?.credits,$)}var l=["primary","secondary"],uZ={primary:300,secondary:10080};function rZ(Z,$){return NZ({scope:"all",label:$,windowMinutes:Z})}function S0(Z){if(!Z)return[];let $=[];for(let X of l){let J=Z[X];if(!J)continue;let V=J.windowMinutes,Y=V!==void 0&&Number.isFinite(V)&&V>0?V:uZ[X];$.push({key:X,label:rZ(V,X),window:J,windowMs:Y*60000})}return $}var M=OZ("sidebar"),$0="OPENCODE_OPENAI_AUTH_SIDEBAR_STATE_FILE";function CZ(){let Z=process.env.XDG_STATE_HOME||h(eZ(),".local","state");return h(Z,"cortexkit","openai-auth","sidebar-state.json")}var FZ=h(tZ(),"opencode-openai-auth","sidebar-state.json");function g0(Z){FZ=Z,p.clear()}var J0=/^[a-f0-9]{64}$/,u=604800000,MZ=256,EZ=3600000;function T(Z){return cZ("sha256").update(Z).digest("hex")}function X0(Z){return typeof Z==="number"&&Number.isFinite(Z)&&Z>=0?Z:void 0}function qZ(Z){let $=X0(Z);return $!==void 0?{resetCredits:$}:{}}function V0(Z){if(Z===null||typeof Z!=="object"||Array.isArray(Z))return;let $={};for(let[X,J]of Object.entries(Z)){if(J===null||typeof J!=="object"||Array.isArray(J))continue;let V=J;if(typeof V.activeId!=="string"||typeof V.route!=="string"||typeof V.updatedAt!=="number"||!Number.isFinite(V.updatedAt))continue;$[X]={activeId:V.activeId,route:V.route,updatedAt:V.updatedAt}}return Object.keys($).length>0?$:void 0}function Y0(Z){if(Z===null||typeof Z!=="object"||Array.isArray(Z))return;let $={};for(let[X,J]of Object.entries(Z)){if(!J0.test(X)||J===null||typeof J!=="object"||Array.isArray(J))continue;let V=J;if(typeof V.accountId!=="string"||V.accountId.length===0||typeof V.assignedAt!=="number"||!Number.isFinite(V.assignedAt)||V.assignedAt<0||typeof V.lastSeenAt!=="number"||!Number.isFinite(V.lastSeenAt)||V.lastSeenAt<0||typeof V.inputBytes!=="number"||!Number.isFinite(V.inputBytes)||V.inputBytes<0)continue;let Y=V.quotaCheckedAt;if(Y!==void 0&&(typeof Y!=="number"||!Number.isFinite(Y)||Y<0))continue;let G=V.wireAccountId;$[X]={accountId:V.accountId,assignedAt:V.assignedAt,lastSeenAt:V.lastSeenAt,inputBytes:V.inputBytes,...Y===void 0?{}:{quotaCheckedAt:Y},...typeof G==="string"?{wireAccountId:G}:{}}}return Object.keys($).length>0?$:void 0}function O(){let Z=process.env[$0];if(Z)return Z;let $=CZ();if(!p.has($))p.add($),z0($,FZ);return $}var p=new Set;function z0(Z,$){try{iZ(Z0(Z),{recursive:!0,mode:448}),aZ($,Z,oZ.COPYFILE_EXCL)}catch{}}var q={main:{quota:null,killed:!1},fallbacks:[],activeId:void 0,route:"main",lastUpdated:0};function S(Z){if(Z===null||typeof Z!=="object"||Array.isArray(Z))return q;let $=Z,X=$.main,J;if(X!==null&&typeof X==="object"&&!Array.isArray(X)){let j=X;J={quota:"quota"in j?j.quota:null,killed:typeof j.killed==="boolean"?j.killed:!1,...typeof j.mainAccountId==="string"?{mainAccountId:j.mainAccountId}:{},...typeof j.quotaBackedOff==="boolean"?{quotaBackedOff:j.quotaBackedOff}:{},...typeof j.quotaBackoffUntil==="number"?{quotaBackoffUntil:j.quotaBackoffUntil}:{},...typeof j.refreshBackedOff==="boolean"?{refreshBackedOff:j.refreshBackedOff}:{},...typeof j.refreshBackoffUntil==="number"?{refreshBackoffUntil:j.refreshBackoffUntil}:{},...qZ(j.resetCredits)}}else J={quota:null,killed:!1};let V=zZ($.fallbacks),Y=Array.isArray($.vaultAccounts)?zZ($.vaultAccounts):void 0,G=typeof $.activeId==="string"?$.activeId:void 0,z=typeof $.route==="string"?$.route:q.route,L=typeof $.lastUpdated==="number"?$.lastUpdated:0,U=typeof $.planType==="string"?$.planType:void 0,K=V0($.activeRouting),Q=Y0($.stickyAssignments);return{main:J,fallbacks:V,activeId:G,route:z,lastUpdated:L,...K!==void 0?{activeRouting:K}:{},...Q!==void 0?{stickyAssignments:Q}:{},...U!==void 0?{planType:U}:{},...$.accountPool===!0?{accountPool:!0}:{},...Y!==void 0?{vaultAccounts:Y}:{},...typeof $.vaultDiscovered==="boolean"?{vaultDiscovered:$.vaultDiscovered}:{}}}function zZ(Z){if(!Array.isArray(Z))return[];return Z.filter(($)=>$!==null&&typeof $==="object"&&!Array.isArray($)&&typeof $.id==="string").map(($)=>({id:$.id,...typeof $.credentialId==="string"?{credentialId:$.credentialId}:{},label:typeof $.label==="string"?$.label:void 0,...typeof $.accountId==="string"?{accountId:$.accountId}:{},quota:"quota"in $?$.quota:null,killed:typeof $.killed==="boolean"?$.killed:!1,enabled:typeof $.enabled==="boolean"?$.enabled:!0,...typeof $.routable==="boolean"?{routable:$.routable}:{},...["needs sign-in","turned off in vault","unavailable"].includes($.vaultState)?{vaultState:$.vaultState}:{},...qZ($.resetCredits)}))}function r(Z){return[...Z.fallbacks,...Z.vaultAccounts??[]]}async function G0(Z=O()){try{let $=await nZ(Z,"utf8");return S(JSON.parse($))}catch{return q}}var K0=3600000,GZ=128;function IZ(Z,$,X=Date.now()){if(!(Z.updatedAt>=X-K0&&Z.updatedAt<=X))return!1;if($===void 0)return!0;return Z.activeId==="main"||$.some((V)=>V.enabled!==!1&&V.routable!==!1&&V.killed!==!0&&V.id===Z.activeId)}function bZ(Z,$=Date.now()){let X=Z?.spendControl;if(X?.reached!==!0||typeof X.resetsAt!=="string")return;let J=Date.parse(X.resetsAt);if(!Number.isFinite(J)||J<=$)return;return{resetsAt:X.resetsAt,resetAtMs:J}}function xZ(Z,$=Date.now()){let X;for(let V of l){let Y=Z?.[V];if(typeof Y?.resetsAt!=="string"||!Number.isFinite(Y.usedPercent)||Y.usedPercent<100)continue;let G=Date.parse(Y.resetsAt);if(!Number.isFinite(G)||G<=$)continue;if(!X||G<X.resetAtMs)X={resetsAt:Y.resetsAt,resetAtMs:G}}let J=bZ(Z,$);if(J&&(!X||J.resetAtMs<X.resetAtMs))X=J;return X}function E(Z,$=Date.now()){return xZ(Z,$)!==void 0}function j0(Z,$,X=Date.now()){if(!$||Z.route!=="sticky-balanced")return;let J=Z.stickyAssignments?.[T($)];if(!J||J.lastSeenAt<X-u)return;if(J.accountId==="main"&&Z.vaultAccounts===void 0)return Z.main?.killed||E(Z.main?.quota,X)?void 0:"main";let V=r(Z).find((Y)=>Y.id===J.accountId);if(!V||V.enabled===!1||V.routable===!1||V.killed===!0||E(V.quota,X))return;return V.id}function d0(Z,$,X=Date.now()){if(!$){if(Z.vaultAccounts===void 0)return{activeId:Z.activeId??"main",route:Z.route};let K=Z.vaultAccounts.find((Q)=>Q.id===Z.activeId&&Q.enabled&&Q.routable!==!1&&!Q.killed);if(K&&!E(K.quota,X))return{activeId:K.id,route:Z.route}}let J=$?Z.activeRouting?.[$]:void 0,V=r(Z),Y=J?.activeId==="main"?Z.main.quota:V.find((K)=>K.id===J?.activeId)?.quota;if(J&&(Z.vaultAccounts===void 0||J.activeId.startsWith("vault:"))&&IZ(J,V,X)&&!E(Y,X))return{activeId:J.activeId,route:J.route};let G=j0(Z,$,X);if(G)return{activeId:G,route:Z.route};let z=Z.vaultAccounts!==void 0,L=(z?c(Z):Z.fallbacks).filter((K)=>K.enabled&&K.routable!==!1&&!K.killed),U=L.find((K)=>!E(K.quota,X))??L[0];return{activeId:z?U?.id??"vault":Z.route==="fallback-first"&&U?U.id:"main",route:Z.route}}function c(Z){let $=Z.vaultAccounts??[],X=new Map($.map((J)=>[J.id,J]));return d($.map((J)=>J.id),gZ(Z),_Z($)??"").flatMap((J)=>{let V=X.get(J);return V?[V]:[]})}function vZ(Z,$,X=Date.now(),J){if(!Z)return;let V=Object.entries(Z).filter(([G,z])=>G!==J&&IZ(z,$,X)),Y=V.length<=GZ?V:V.sort((G,z)=>z[1].updatedAt-G[1].updatedAt).slice(0,GZ);return Y.length>0?Object.fromEntries(Y):void 0}function I(Z,$,X=Date.now(),J){if(!Z)return;let V=0,Y=0,G=0,z=[];for(let[U,K]of Object.entries(Z)){if(U===J){G+=1;continue}if(K.lastSeenAt<X-u){Y+=1;continue}if($!==void 0&&!$.has(K.accountId)){V+=1;continue}z.push([U,K])}let L=V+Y+G;if(L>0)M.debug("pruned sticky assignments",{pid:process.pid,removed:L,reasons:{"account-not-in-roster":V,expired:Y,"explicit-removal":G}});return z.length>0?Object.fromEntries(z):void 0}function fZ(Z,$){let X=Object.keys(Z).length-MZ;if(X<=0)return Z;let J=new Set(Object.entries(Z).filter(([V])=>V!==$).sort(([V,Y],[G,z])=>Y.lastSeenAt-z.lastSeenAt||V.localeCompare(G)).slice(0,X).map(([V])=>V));return Object.fromEntries(Object.entries(Z).filter(([V])=>!J.has(V)))}function SZ(Z,$){if(Z===$)return!0;if(!Z||!$)return!1;let X=Object.entries(Z);if(X.length!==Object.keys($).length)return!1;return X.every(([J,V])=>Object.is($[J],V))}function AZ(Z,$,X,J){return Z!==void 0&&$.has(Z.accountId)&&!X.has(Z.accountId)&&Z.lastSeenAt>=J-u}function yZ(Z,$,X,J){return $>Z.inputBytes||X-Z.lastSeenAt>=EZ||Z.wireAccountId===void 0&&J!==void 0}function kZ(Z,$){return typeof Z.wireAccountId==="string"&&typeof $==="string"&&Z.wireAccountId!==$}function L0(Z){let $=new Map(Z),X={get size(){return $.size},has:(J)=>$.has(J),get:(J)=>$.get(J),entries:()=>$.entries(),keys:()=>$.keys(),values:()=>$.values(),forEach:(J,V)=>{$.forEach((Y,G)=>{J.call(V,Y,G,X)})},[Symbol.iterator]:()=>$[Symbol.iterator]()};return Object.freeze(X)}function B0(Z,$,X){let J=new Map;for(let[V,Y]of Object.entries(Z??{})){if(V===X)continue;if(Y.quotaCheckedAt!==$[Y.accountId])continue;J.set(Y.accountId,(J.get(Y.accountId)??0)+Y.inputBytes)}return L0(J)}function o(Z){if(Z===void 0)return;return new Set(["main",...Z.filter(($)=>$.enabled!==!1&&$.killed!==!0).map(($)=>$.id)])}var m=Promise.resolve();function _(Z){let $=m.then(Z);return m=$.catch(()=>{}),$}var KZ=new Map;function a(Z){let $=KZ.get(Z);if(!$)$=k({path:Z,defaultValue:q,normalize:S,secureDir:Z===CZ(),logger:M}),KZ.set(Z,$);return $}var w=new Set;async function wZ(Z,$){try{await $}catch(X){let J={pid:process.pid,error:X instanceof Error?X.message:String(X)};if(w.has(Z))M.debug("sidebar write failed again",J);else w.add(Z),M.warn("sidebar write failed",J);throw X}if(w.delete(Z))M.info("sidebar write recovered",{pid:process.pid})}function l0(Z,$=O()){return _(()=>wZ($,a($).write(S(Z))))}function U0(Z){return a(Z).read()}function R(Z,$,X){let J=Symbol("sidebar authority changed");return wZ(Z,a(Z).update((V)=>{if(X?.canWrite&&!X.canWrite())return;let Y=$(V);if(Y===void 0)return;if(X?.vaultMode===!1)Y.vaultAccounts=void 0,Y.vaultDiscovered=void 0;if(X?.vaultMode??Y.vaultAccounts!==void 0)Y.activeId=Y.activeId?.startsWith("vault:")?Y.activeId:void 0,Y.activeRouting=Object.fromEntries(Object.entries(Y.activeRouting??{}).filter(([,G])=>G.activeId.startsWith("vault:"))),Y.stickyAssignments=Object.fromEntries(Object.entries(Y.stickyAssignments??{}).filter(([,G])=>G.accountId.startsWith("vault:")&&!Y.vaultAccounts?.some((z)=>z.id===G.accountId&&z.killed)));return S(Y)},{beforeRecheck:async(...V)=>{if(await X?.beforeRecheck?.(...V),X?.canWrite&&!X.canWrite())throw J}}).catch((V)=>{if(V!==J)throw V}))}function v(Z){let $;for(let X of[Z?.primary?.checkedAt,Z?.secondary?.checkedAt,Z?.checkedAt])if(typeof X==="number"&&Number.isFinite(X))$=$===void 0?X:Math.max($,X);return $}function jZ(Z,$){let X=v(Z),J=v($);if(J!==void 0&&(X===void 0||J>X))return $;return Z}function LZ(Z,$){return Z!==void 0&&$!==void 0&&Z===$}function f(Z,$){let X=Z?.checkedAt;if(typeof X==="number"&&Number.isFinite(X))return X;if(typeof $==="number"&&Number.isFinite($))return $;return}function BZ(Z,$,X,J,V){if(Z&&$){let Y=f(Z,J),G=f($,V);if(G!==void 0&&(Y===void 0||G>Y))return $;return Z}return X?$:Z}function UZ(Z,$){if(Z.spendControl!==void 0)return Z.spendControl;if(Z.spendControlCleared===!0)return;return $.spendControl}function Q0(Z,$){if(!Z||!$)return Z??$;let X=(J)=>typeof J.checkedAt==="number"&&Number.isFinite(J.checkedAt)?J.checkedAt:Number.NEGATIVE_INFINITY;return X($)>X(Z)?$:Z}function QZ(Z,$){if(!Z)return $;if(!$)return Z;let X=v(Z),J=v($),V=J!==void 0&&(X===void 0||J>X),Y=BZ(Z.primary,$.primary,V,Z.checkedAt,$.checkedAt),G=BZ(Z.secondary,$.secondary,V,Z.checkedAt,$.checkedAt),z=V?UZ($,Z):UZ(Z,$),L=z===void 0&&(Z.spendControlCleared===!0||$.spendControlCleared===!0),U=Q0(Z.credits,$.credits),K;for(let N of[f(Y),f(G)])if(N!==void 0)K=K===void 0?N:Math.max(K,N);let{spendControl:Q,spendControlCleared:j,credits:B,...D}=Z;return{...D,primary:Y,secondary:G,...z!==void 0?{spendControl:z}:{},...L?{spendControlCleared:!0}:{},...U!==void 0?{credits:U}:{},checkedAt:K??Z.checkedAt}}function u0(Z,$=O(),X){return _(async()=>{await R($,(J)=>{let V=new Map(J.fallbacks.map((K)=>[K.id,K])),Y=Z.vaultAccounts!==void 0,G=LZ(Z.main.mainAccountId,J.main.mainAccountId),z=G?QZ(Z.main.quota,J.main.quota):jZ(Z.main.quota,J.main.quota),L=Date.now(),U=I(J.stickyAssignments,Y?void 0:o(r(Z)),L);return{...J,...Z,main:Y?Z.main:{...Z.main,quota:z,mainAccountId:G?Z.main.mainAccountId:z===J.main.quota&&z!==Z.main.quota?J.main.mainAccountId:Z.main.mainAccountId},fallbacks:Y?Z.fallbacks:Z.fallbacks.map((K)=>{let Q=V.get(K.id),j=LZ(K.accountId,Q?.accountId),B=j?QZ(K.quota,Q?.quota??null):jZ(K.quota,Q?.quota??null);return{...K,quota:B,accountId:j?K.accountId:B===Q?.quota&&B!==K.quota?Q?.accountId:K.accountId}}),activeId:J.activeId,activeRouting:J.activeRouting,stickyAssignments:U,lastUpdated:Math.max(L,J.lastUpdated+1),accountPool:Z.accountPool===!0?!0:void 0,vaultAccounts:Z.vaultAccounts,vaultDiscovered:Z.vaultDiscovered}},X)})}function r0(Z,$,X=O(),J){return _(async()=>{await R(X,(V)=>{let Y=vZ({...V.activeRouting,[Z.sessionId]:{activeId:Z.activeId,route:Z.route,updatedAt:Z.updatedAt}},$,Date.now()),G=I(V.stickyAssignments,J?.vaultMode??V.vaultAccounts!==void 0?void 0:o($),Date.now());return{...V,activeId:Z.activeId,route:Z.route,activeRouting:Y,stickyAssignments:G,lastUpdated:Math.max(Date.now(),V.lastUpdated+1)}},J)})}function c0(Z,$=O(),X){return _(async()=>{await R($,(J)=>({...J,activeId:Z.activeId,route:Z.route,lastUpdated:Math.max(Date.now(),J.lastUpdated+1)}),X)})}function o0(Z,$,X=O(),J){return _(async()=>{await R(X,(V)=>{let Y=Date.now(),G=vZ(V.activeRouting,$,Y,Z),z=I(V.stickyAssignments,J?.vaultMode??V.vaultAccounts!==void 0?void 0:o($),Y,T(Z));return{...V,activeRouting:G,stickyAssignments:z,lastUpdated:Math.max(Date.now(),V.lastUpdated+1)}},J)})}function hZ(Z,$){return AZ(Z,new Set($.validPinnedAccountIds),new Set($.excludeAccountIds),$.now)&&!kZ(Z,$.wireAccountIdByAccount?.[Z.accountId])&&!yZ(Z,$.requestBytes,$.now,$.wireAccountIdByAccount?.[Z.accountId])}function pZ(Z,$){let X=T($.sessionId),J=new Set($.validPinnedAccountIds),V=new Set($.excludeAccountIds),Y=I(Z.stickyAssignments,J,$.now),G=!SZ(Z.stickyAssignments,Y),z=Y?.[X],L=z!==void 0&&kZ(z,$.wireAccountIdByAccount?.[z.accountId]);if(AZ(z,J,V,$.now)&&!L){let Q=yZ(z,$.requestBytes,$.now,$.wireAccountIdByAccount?.[z.accountId]),j=Q?{...z,inputBytes:Math.max(z.inputBytes,$.requestBytes),...z.wireAccountId===void 0&&$.wireAccountIdByAccount?.[z.accountId]!==void 0?{wireAccountId:$.wireAccountIdByAccount?.[z.accountId]}:{},...$.now-z.lastSeenAt>=EZ?{lastSeenAt:$.now}:{}}:z;if(!G&&!Q)return{assignment:j,next:void 0};return{assignment:j,next:{...Z,stickyAssignments:{...Y,[X]:j},lastUpdated:Math.max($.now,Z.lastUpdated+1)}}}let U=$.choose(B0(Y,$.quotaCheckedAtByAccount,L?X:void 0));if(!U){if(!G)return{assignment:void 0,next:void 0};return{assignment:void 0,next:{...Z,stickyAssignments:Y,lastUpdated:Math.max($.now,Z.lastUpdated+1)}}}let K={accountId:U.accountId,assignedAt:$.now,lastSeenAt:$.now,inputBytes:$.requestBytes,...U.quotaCheckedAt===void 0?{}:{quotaCheckedAt:U.quotaCheckedAt},...$.wireAccountIdByAccount?.[U.accountId]===void 0?{}:{wireAccountId:$.wireAccountIdByAccount?.[U.accountId]}};return{assignment:K,next:{...Z,stickyAssignments:fZ({...Y,[X]:K},X),lastUpdated:Math.max($.now,Z.lastUpdated+1)}}}async function a0(Z,$=O(),X){let J=T(Z.sessionId),V=(await U0($)).stickyAssignments?.[J];if(hZ(V,Z))return V;let Y;return await _(async()=>{await R($,(G)=>{let z=pZ(G,Z);return Y=z.assignment,z.next},X)}),Y}function i0(Z,$){let X=Z.stickyAssignments?.[T($.sessionId)];if(hZ(X,$))return{assignment:X,next:void 0};return pZ(Z,$)}function s0(Z,$=O(),X){let J=T(Z.sessionId),V=new Set(Z.validPinnedAccountIds);return _(async()=>{await R($,(Y)=>{let G=Date.now(),z=I(Y.stickyAssignments,X?.vaultMode??Y.vaultAccounts!==void 0?void 0:V,G),L=z?.[J];if(L&&L.assignedAt>Z.assignment.assignedAt){if(SZ(Y.stickyAssignments,z))return;return{...Y,stickyAssignments:z,lastUpdated:Math.max(G,Y.lastUpdated+1)}}let K=L!==void 0&&L.accountId===Z.assignment.accountId&&L.assignedAt===Z.assignment.assignedAt?{...Z.assignment,inputBytes:Math.max(L.inputBytes,Z.assignment.inputBytes),lastSeenAt:Math.max(L.lastSeenAt,Z.assignment.lastSeenAt)}:Z.assignment;return{...Y,stickyAssignments:fZ({...z,[J]:K},J),lastUpdated:Math.max(G,Y.lastUpdated+1)}},X)})}async function n0(Z,$=O()){let X=T(Z),J=!1;return await _(async()=>{await R($,(V)=>{let Y=V.stickyAssignments;if(Y?.[X]===void 0){J=!1;return}J=!0;let{[X]:G,...z}=Y;return{...V,...Object.keys(z).length>0?{stickyAssignments:z}:{stickyAssignments:void 0},lastUpdated:Math.max(Date.now(),V.lastUpdated+1)}})}),J}function e0(){return m}var D0=500;function N0(Z,$,X){return new Promise((J,V)=>{let Y=setTimeout(()=>J(X()),$);Y.unref?.(),Z.then((G)=>{clearTimeout(Y),J(G)},(G)=>{clearTimeout(Y),V(G)})})}function t0(Z,$={}){let X=$.readBudgetMs??D0,J,V,Y=()=>{try{let z=sZ(Z);return`${z.ino}:${z.size}:${z.mtimeMs}`}catch{return}},G=(z)=>{if(V&&V.key===z)return V.promise;let L=Date.now(),U=G0(Z).then((j)=>{if(!J||J.readAt<=L)J={state:j,readAt:L,key:z};return{state:j,readAt:L}}),K={key:z,promise:U};V=K;let Q=()=>{if(V===K)V=void 0};return U.then(Q,Q),U};return{get(){let z=Y();if(J&&J.key===z)return Promise.resolve({state:J.state,readAt:J.readAt});return N0(G(z),X,()=>J?{state:J.state,readAt:J.readAt}:{state:q,readAt:0})},read(){return G(Y())},refreshInBackground(){let z=Y();if(J?.key===z)return;G(z)}}}function Z1(Z,$,X){let J={assignment:X};Z.delete($),Z.set($,J);while(Z.size>MZ){let V=Z.keys().next().value;if(V===void 0)break;Z.delete(V)}return J}function $1(Z,$){if($.size===0)return Z.state;let X={...Z.state.stickyAssignments},J=!1;for(let[V,Y]of $){if(Y.persistedAt!==void 0&&Z.readAt>Y.persistedAt){$.delete(V);continue}X[V]=Y.assignment,J=!0}if(!J)return Z.state;return{...Z.state,stickyAssignments:X}}function J1(Z){let $=Z.retryDelayMs??500,X=Z.maxRetryDelayMs??30000,J=new Map,V=new Map,Y=new Set,G=0,z=$,L,U=!1,K=()=>{if(L||U||V.size===0)return;L=setTimeout(()=>{L=void 0;let j=[...V];V.clear(),z=Math.min(z*2,X);for(let[B,D]of j){let N=J.get(B);if(N!==void 0)Q(B,D.label,D.write,N)}},z),L.unref?.()},Q=(j,B,D,N)=>{let P;try{P=D()}catch(W){P=Promise.reject(W)}P.then(()=>{if(J.get(j)!==N)return;if(J.delete(j),Y.delete(j))Z.logger.info("sidebar bookkeeping write recovered",{pid:process.pid,write:B});if(Y.size===0)z=$;Z.onWritten?.()},(W)=>{if(J.get(j)!==N)return;let H={pid:process.pid,write:B,error:W instanceof Error?W.message:String(W)};if(U){J.delete(j),Z.logger.debug("sidebar bookkeeping write dropped",H);return}if(Y.has(j))Z.logger.debug("sidebar bookkeeping write failed again",H);else Y.add(j),Z.logger.warn("sidebar bookkeeping write failed; retrying in the background",H);V.set(j,{label:B,write:D}),K()})};return{enqueue(j,B,D){G+=1,J.set(j,G),V.delete(j),Q(j,B,D,G)},cancel(j){J.delete(j),V.delete(j),Y.delete(j)},stop(){if(U=!0,L)clearTimeout(L);L=void 0,V.clear()}}}function P0(Z){let $=Z.activeId;if(Z.vaultAccounts!==void 0){let X=c(Z).filter((V)=>V.enabled&&V.routable!==!1),J=X.find((V)=>V.id===$)??X[0];return J?{id:J.id,name:J.label??J.id,quota:J.quota,killed:J.killed}:{id:"vault",name:"vault",quota:null,killed:!1}}if($&&$!=="main"){let X=Z.fallbacks.find((J)=>J.enabled&&J.id===$);if(X)return{id:X.id,name:X.label??X.id,quota:X.quota,killed:X.killed}}return{id:"main",name:"main",quota:Z.main.quota,killed:Z.main.killed}}function mZ(Z,$=Date.now()){if(!Z)return;return HZ({limits:l.flatMap((X)=>{let J=Z[X];return J?[{kind:"reading",scope:"all",label:X,usedPercent:J.usedPercent,checkedAt:J.checkedAt??Z.checkedAt??$,windowMinutes:J.windowMinutes,resetsAt:J.resetsAt}]:[]}),...Z.spendControl?{budget:{...Z.spendControl,kind:"reading",checkedAt:Z.checkedAt??$}}:{}})}function X1(Z,$=Date.now()){let X=Z?.primary?.usedPercent??null,J=Z?.secondary?.usedPercent??null,V=mZ(Z,$);return{primaryUsedPercent:X,secondaryUsedPercent:J,text:!V||V.limits.length===0&&!V.budget?null:g(V,{now:$,form:"compact"})}}function gZ(Z){return Z.route==="sticky-balanced"?"roster":TZ(Z.route)}function V1(Z,$={}){let X=$.now??Date.now(),J=P0(Z).id;return(Z.vaultAccounts!==void 0?c(Z).map((Y)=>({id:Y.id,name:Y.label??Y.id,quota:Y.quota,killed:Y.killed})):W0(Z,J,$.showFallbacks??!0)).map((Y)=>{let G=mZ(Y.quota,X),z=G&&(G.limits.length>0||G.budget)?G:void 0;return{id:Y.id,name:Y.name,killed:Y.killed,active:Y.id===J,stale:z?PZ(z,{now:X}):!1,text:z?g(z,{now:X,form:"narrow"}):null}})}function W0(Z,$,X){let J=[{id:"main",name:"main",quota:Z.main.quota,killed:Z.main.killed},...Z.fallbacks.filter((Y)=>Y.enabled&&(X||Y.id===$)).map((Y)=>({id:Y.id,name:Y.label??Y.id,quota:Y.quota,killed:Y.killed}))],V=new Map(J.map((Y)=>[Y.id,Y]));return d(J.map((Y)=>Y.id),gZ(Z),"main").flatMap((Y)=>{let G=V.get(Y);return G?[G]:[]})}function DZ(Z){let $=globalThis.Bun;return $?.stringWidth?$.stringWidth(Z):Array.from(Z).length}function Y1(Z,$){if(DZ(Z)<=$)return Z;if($<1)return"";let X="",J=0;for(let V of Z){let Y=DZ(V);if(J+Y>$-1)break;X+=V,J+=Y}return`${X}…`}var H0=300000,O0=0.01,_0=1;function z1(Z,$,X){if(!Z.resetsAt)return null;let J=new Date(Z.resetsAt).getTime();if(!Number.isFinite(J))return null;let V=J-$,Y=X-V;if(Y<H0)return null;if(Y<$*O0)return null;if(Y>=$)return null;let G=Z.usedPercent,z=Math.min(Math.max(Y/$*100,0),100),L=G-z,U=Math.abs(L)<_0?"on-pace":L>0?"deficit":"reserve",K=null;if(G>0){let Q=Y*100/G,j=V+Q;if(j<J)K=new Date(j).toISOString()}return{pacePercent:z,deltaPercent:L,state:U,runsOutAt:K}}
2
- export{v0 as ld,f0 as md,rZ as nd,S0 as od,g0 as pd,u as qd,MZ as rd,T as sd,O as td,q as ud,S as vd,G0 as wd,K0 as xd,GZ as yd,IZ as zd,bZ as Ad,xZ as Bd,E as Cd,j0 as Dd,d0 as Ed,vZ as Fd,I as Gd,l0 as Hd,u0 as Id,r0 as Jd,c0 as Kd,o0 as Ld,pZ as Md,a0 as Nd,i0 as Od,s0 as Pd,n0 as Qd,e0 as Rd,D0 as Sd,N0 as Td,t0 as Ud,Z1 as Vd,$1 as Wd,J1 as Xd,P0 as Yd,mZ as Zd,X1 as _d,V1 as $d,DZ as ae,Y1 as be,z1 as ce};
@@ -1,72 +0,0 @@
1
- interface QuotaReadingEntry {
2
- scope: string;
3
- label: string;
4
- kind: 'reading';
5
- checkedAt: number;
6
- usedPercent: number;
7
- /** ISO timestamp at which the window resets, as the provider reported it. */
8
- resetsAt?: string;
9
- /** Window length in minutes, when the provider reported one. */
10
- windowMinutes?: number;
11
- }
12
- interface QuotaRetiredEntry {
13
- scope: string;
14
- label: string;
15
- kind: 'retired';
16
- retiredAt: number;
17
- }
18
- interface QuotaAbsentEntry {
19
- scope: string;
20
- label: string;
21
- kind: 'absent';
22
- checkedAt: number;
23
- }
24
- type QuotaEntry = QuotaReadingEntry | QuotaRetiredEntry | QuotaAbsentEntry;
25
- interface CreditBudgetReading {
26
- kind: 'reading';
27
- checkedAt: number;
28
- /** The provider's own verdict that the budget is spent. */
29
- reached: boolean;
30
- remainingPercent?: number;
31
- usedPercent?: number;
32
- resetsAt?: string;
33
- limit?: number;
34
- used?: number;
35
- remaining?: number;
36
- unit?: string;
37
- }
38
- interface CreditBudgetCleared {
39
- kind: 'cleared';
40
- checkedAt: number;
41
- }
42
- type CreditBudgetEntry = CreditBudgetReading | CreditBudgetCleared;
43
- interface QuotaCounter {
44
- value: number;
45
- checkedAt: number;
46
- }
47
- /**
48
- * Prepaid credits a provider account holds beside its rate-limit windows (for
49
- * example a ChatGPT workspace's credits, which keep requests working after a
50
- * window is used up). This is a state, not a count or the spend budget: the
51
- * account has credits or not, they may be unlimited, and the provider may
52
- * report a balance. It carries its own observation time.
53
- */
54
- interface QuotaCredits {
55
- hasCredits: boolean;
56
- unlimited: boolean;
57
- /** The balance the provider reported, when it reported one. */
58
- balance?: number;
59
- /** The provider's verdict that the overage allowance is used up. */
60
- overageLimitReached?: boolean;
61
- checkedAt: number;
62
- }
63
- interface QuotaMap {
64
- limits: QuotaEntry[];
65
- /** Absent means no observation has reported on the budget yet. */
66
- budget?: CreditBudgetEntry;
67
- /** Provider-named counts, each with its own observation time. */
68
- counters?: Record<string, QuotaCounter>;
69
- /** Absent means no observation has reported on prepaid credits yet. */
70
- credits?: QuotaCredits;
71
- }
72
- export { QuotaCredits as n, QuotaMap as r, QuotaCounter as t };
File without changes