@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
@@ -0,0 +1,425 @@
1
+ import { MAX_SAME_ACCOUNT_HOLD_MS } from "./c66495424ad84aee-hold.js";
2
+ import { holdDelayMs } from "./d7fa77560855dee2-jitter.js";
3
+ import { isRequestExcluded, REQUEST_EXCLUSION_EFFECTS, reduceRequestHistory, sameAccount, } from "./f6d728f5e601f98b-request-history.js";
4
+ import { terminalRefusalDecision, terminalWaitDisabled } from "./2ec33b3e2b8ac38a-terminal.js";
5
+ import { liftedWindowsForWake, waitCheckpoint } from "./7b2a0471b29e4f5e-wake.js";
6
+ function finiteFuture(value, now) {
7
+ return value !== undefined && Number.isFinite(value) && value > now;
8
+ }
9
+ function continuationRetry(facts, axes) {
10
+ return axes.execution === 'engine' && facts.phase === 'after-limit'
11
+ ? 'veto'
12
+ : 'leave';
13
+ }
14
+ function refusal(facts, axes, history, reason, metadata) {
15
+ const terminal = metadata && terminalRefusalDecision(facts, axes, history, metadata);
16
+ if (terminal)
17
+ return terminal;
18
+ const policy = axes.refusals[reason][facts.host];
19
+ return {
20
+ action: 'refuse',
21
+ reason,
22
+ family: metadata?.family ?? policy.family,
23
+ messageKey: metadata?.messageKey ?? policy.messageKey,
24
+ retryable: metadata?.retryable ?? policy.retryable,
25
+ hostRetry: metadata?.hostRetry ?? policy.hostRetry,
26
+ history,
27
+ ...(metadata?.retryAfterMs === undefined
28
+ ? {}
29
+ : { retryAfterMs: metadata.retryAfterMs }),
30
+ ...(metadata?.resetAt === undefined ? {} : { resetAt: metadata.resetAt }),
31
+ };
32
+ }
33
+ function hold(facts, axes, history, current, windows) {
34
+ const bound = facts.hold;
35
+ if (axes.shortLimit.holdBound === 'disabled' ||
36
+ (facts.host === 'opencode2' &&
37
+ (facts.hostPhase !== 'retry' ||
38
+ facts.remainingRetries === undefined ||
39
+ !(facts.remainingRetries >= 1))) ||
40
+ !current?.admitted ||
41
+ !bound ||
42
+ bound.maxWaitMs <= 0 ||
43
+ Number.isNaN(bound.maxWaitMs) ||
44
+ !Number.isFinite(bound.cacheExpiresAt) ||
45
+ (bound.maxDelayMs !== undefined &&
46
+ (!Number.isFinite(bound.maxDelayMs) || bound.maxDelayMs < 0)) ||
47
+ !windows.length ||
48
+ windows.some((window) => !finiteFuture(window.resetAt, facts.now)))
49
+ return undefined;
50
+ const resetAt = Math.max(...windows.map((window) => window.resetAt));
51
+ const delayMs = axes.shortLimit.jitter === 'session-sha256'
52
+ ? holdDelayMs(facts.sessionId, resetAt - facts.now)
53
+ : resetAt - facts.now;
54
+ const target = facts.now + delayMs;
55
+ if (!Number.isFinite(target) ||
56
+ target > Math.min(bound.cacheExpiresAt, facts.now + bound.maxWaitMs) ||
57
+ (facts.host === 'opencode2' && delayMs > MAX_SAME_ACCOUNT_HOLD_MS) ||
58
+ (bound.maxDelayMs !== undefined && delayMs > bound.maxDelayMs))
59
+ return undefined;
60
+ return {
61
+ action: 'hold',
62
+ account: current.account,
63
+ delayMs,
64
+ retryAfterMs: delayMs,
65
+ target,
66
+ checkpoint: waitCheckpoint(current.account, facts.now, windows),
67
+ reason: 'confirmed-limit',
68
+ retryable: true,
69
+ hostRetry: facts.phase === 'pre-send' ? 'leave' : continuationRetry(facts, axes),
70
+ history,
71
+ };
72
+ }
73
+ function poolWait(facts, axes, history, candidates) {
74
+ const policy = axes.poolWaiting;
75
+ if (policy.kind === 'off' || !candidates.length)
76
+ return undefined;
77
+ history = reduceRequestHistory(history, {
78
+ type: 'blocked',
79
+ clockNow: facts.clockNow,
80
+ });
81
+ const times = candidates
82
+ .map((candidate) => {
83
+ const blockers = candidate.blockers.filter((blocker) => !(blocker.kind === 'soft' &&
84
+ candidates.length === 1 &&
85
+ policy.singleEligibleSoftExemption));
86
+ if (blockers.some((blocker) => !finiteFuture(blocker.until, facts.now)))
87
+ return undefined;
88
+ return blockers.length
89
+ ? {
90
+ candidate,
91
+ time: Math.max(...blockers.map((blocker) => blocker.until)),
92
+ }
93
+ : undefined;
94
+ })
95
+ .filter((entry) => entry !== undefined);
96
+ const earliest = times.reduce((best, entry) => (!best || entry.time < best.time ? entry : best), undefined);
97
+ const proposed = earliest
98
+ ? earliest.time - facts.now
99
+ : candidates.some((candidate) => candidate.blockers.some((blocker) => blocker.kind !== 'soft'))
100
+ ? policy.hardFallbackMs
101
+ : undefined;
102
+ const budget = facts.poolWaitBudgetMs ?? policy.budgetMs;
103
+ const elapsed = facts.clockNow - (history.blockedSince ?? facts.clockNow);
104
+ if (budget > 0 &&
105
+ (elapsed >= budget || (proposed !== undefined && proposed > budget)))
106
+ return refusal(facts, axes, history, 'quota', facts.terminal);
107
+ const remaining = policy.requestDeadlineMs - (facts.clockNow - history.requestStartedAt);
108
+ if (remaining <= 0)
109
+ return refusal(facts, axes, history, 'incomplete');
110
+ if (proposed === undefined)
111
+ return refusal(facts, axes, history, 'quota', facts.terminal);
112
+ const delayMs = Math.min(proposed, remaining, budget > 0 ? budget - elapsed : Number.POSITIVE_INFINITY);
113
+ const waitedAccount = earliest?.candidate ?? candidates[0];
114
+ if (!waitedAccount)
115
+ return undefined;
116
+ return {
117
+ action: 'wait-then-reselect',
118
+ delayMs,
119
+ target: facts.now + delayMs,
120
+ checkpoint: waitCheckpoint(waitedAccount.account, facts.now, waitedAccount.confirmedBlockers ?? []),
121
+ reason: 'pool-blocked',
122
+ retryable: true,
123
+ hostRetry: continuationRetry(facts, axes),
124
+ history,
125
+ };
126
+ }
127
+ /** The caller supplies clocks, admission, delivery ownership and parsed evidence. */
128
+ export function decideAfterLimit(facts, axes) {
129
+ let history = facts.history;
130
+ const pass = (reason, retryable = facts.phase === 'pre-send'
131
+ ? true
132
+ : (facts.failureRetryable ?? true), hostRetry = 'leave') => ({
133
+ action: 'pass',
134
+ reason,
135
+ retryable,
136
+ hostRetry,
137
+ history,
138
+ });
139
+ if (facts.phase === 'after-limit' &&
140
+ facts.host === 'opencode2' &&
141
+ (!facts.delivery.owned || !facts.delivery.attributable))
142
+ return pass('not-owned');
143
+ const status = facts.status ?? facts.signal?.status;
144
+ if (facts.phase === 'after-limit' && facts.attempted)
145
+ history = reduceRequestHistory(history, {
146
+ type: 'response',
147
+ account: facts.attempted,
148
+ scope: facts.requestScope,
149
+ status,
150
+ kind: axes.terminalStatusHistory?.paymentBalance &&
151
+ facts.signalApplicable !== false &&
152
+ facts.signal &&
153
+ sameAccount(facts.signal.account, facts.attempted)
154
+ ? facts.signal.kind
155
+ : undefined,
156
+ });
157
+ if (facts.phase === 'after-limit' && !facts.delivery.replayable)
158
+ return pass('unsafe-output', false, 'veto');
159
+ const admitted = facts.candidates.filter((candidate) => candidate.admitted);
160
+ const candidates = admitted.filter((candidate) => !isRequestExcluded(history, candidate.account, facts.requestScope));
161
+ const current = candidates.find((candidate) => facts.attempted && sameAccount(candidate.account, facts.attempted));
162
+ const signal = facts.signalApplicable !== false &&
163
+ facts.signal &&
164
+ facts.attempted &&
165
+ sameAccount(facts.signal.account, facts.attempted)
166
+ ? facts.signal
167
+ : undefined;
168
+ if (axes.requestExclusion === 'on' &&
169
+ signal?.kind === 'model-unavailable' &&
170
+ current) {
171
+ return {
172
+ action: 'exclude-for-request',
173
+ account: current.account,
174
+ scope: facts.requestScope,
175
+ effects: REQUEST_EXCLUSION_EFFECTS,
176
+ reason: 'model-unavailable',
177
+ retryable: true,
178
+ hostRetry: continuationRetry(facts, axes),
179
+ history,
180
+ };
181
+ }
182
+ if (admitted.length && !candidates.length)
183
+ return refusal(facts, axes, history, 'model-unavailable');
184
+ if (facts.host === 'opencode2' &&
185
+ facts.hostPhase === 'retry' &&
186
+ axes.execution === 'host' &&
187
+ facts.remainingRetries !== undefined &&
188
+ facts.remainingRetries < 1) {
189
+ return facts.terminal &&
190
+ (facts.terminal.retryable === false ||
191
+ terminalWaitDisabled(facts.terminal, axes, facts.now))
192
+ ? refusal(facts, axes, history, facts.terminal.reason, facts.terminal)
193
+ : pass('host-retries-exhausted');
194
+ }
195
+ if (facts.wake && facts.phase === 'pre-send') {
196
+ const wake = facts.wake;
197
+ const held = candidates.find((candidate) => sameAccount(candidate.account, wake.checkpoint.accountKey));
198
+ const windows = held?.confirmedBlockers ??
199
+ (held && signal && sameAccount(signal.account, held.account)
200
+ ? signal.windows
201
+ : []);
202
+ const liftedWindows = held
203
+ ? liftedWindowsForWake(wake, held.account, windows, facts.now)
204
+ : [];
205
+ const bound = facts.hold;
206
+ const cacheValid = wake.kind === 'terminal' ||
207
+ (bound !== undefined &&
208
+ Number.isFinite(bound.cacheExpiresAt) &&
209
+ facts.now <= bound.cacheExpiresAt &&
210
+ wake.target <= bound.cacheExpiresAt &&
211
+ bound.maxWaitMs > 0 &&
212
+ wake.target - wake.checkpoint.decidedAt <= bound.maxWaitMs);
213
+ if (held &&
214
+ Number.isFinite(wake.target) &&
215
+ wake.target >= wake.checkpoint.decidedAt &&
216
+ facts.now >= wake.target &&
217
+ cacheValid &&
218
+ held.blockers.every((blocker) => blocker.until !== undefined &&
219
+ Number.isFinite(blocker.until) &&
220
+ blocker.until <= facts.now) &&
221
+ (held.ready || windows.some((window) => window.confirmed)) &&
222
+ windows
223
+ .filter((window) => window.confirmed)
224
+ .every((window) => liftedWindows.includes(window.window))) {
225
+ return {
226
+ action: 'retain',
227
+ account: held.account,
228
+ liftedWindows,
229
+ reason: 'wait-elapsed',
230
+ retryable: true,
231
+ hostRetry: 'leave',
232
+ history: reduceRequestHistory(history, { type: 'selected' }),
233
+ };
234
+ }
235
+ }
236
+ if (facts.credentialRecovery && current) {
237
+ return {
238
+ action: 'retain',
239
+ account: current.account,
240
+ reason: 'credential-recovery',
241
+ ...(facts.credentialRecovery.retryMs === undefined
242
+ ? {}
243
+ : { retryMs: facts.credentialRecovery.retryMs }),
244
+ retryable: true,
245
+ hostRetry: continuationRetry(facts, axes),
246
+ history,
247
+ };
248
+ }
249
+ // Supplying the count opts into the turn-scoped rule across all hosts;
250
+ // callers without it keep their existing host-specific unknown-limit policy.
251
+ const retainLimit = axes.unconfirmedRetainLimit;
252
+ const retainCount = facts.unconfirmedRetainCount;
253
+ const counted = status === 429 && retainLimit !== undefined && retainCount !== undefined;
254
+ const advance = axes.advance[facts.host];
255
+ if (facts.phase === 'after-limit' &&
256
+ axes.terminalStatusHistory?.paymentBalance &&
257
+ (signal?.kind === 'payment-cap' ||
258
+ (status === 402 && signal?.kind !== 'payment-balance')))
259
+ return pass('unhandled-failure');
260
+ if (facts.phase === 'after-limit' &&
261
+ !signal &&
262
+ !counted &&
263
+ !facts.terminal &&
264
+ (advance.attributedLimitOnly ||
265
+ status === undefined ||
266
+ !advance.statuses.includes(status)))
267
+ return pass('unhandled-failure');
268
+ const selected = candidates.find((candidate) => facts.selection &&
269
+ sameAccount(candidate.account, facts.selection.account) &&
270
+ candidate.placementEligible);
271
+ const selectedReady = selected &&
272
+ (selected.ready ||
273
+ (axes.poolWaiting.kind === 'earliest' &&
274
+ axes.poolWaiting.singleEligibleSoftExemption &&
275
+ candidates.length === 1 &&
276
+ selected.blockers.length > 0 &&
277
+ selected.blockers.every((blocker) => blocker.kind === 'soft')));
278
+ const alternative = selectedReady &&
279
+ (!facts.attempted || !sameAccount(selected.account, facts.attempted))
280
+ ? selected
281
+ : undefined;
282
+ const reroute = (candidate, reason = 'ready-alternative') => ({
283
+ action: 'reroute',
284
+ account: candidate.account,
285
+ pin: facts.selection?.pin ?? 'preserve',
286
+ reason,
287
+ retryable: true,
288
+ hostRetry: continuationRetry(facts, axes),
289
+ history: reduceRequestHistory(history, { type: 'selected' }),
290
+ });
291
+ // Before the first send there is no attempted account or response signal;
292
+ // the retained selection can still have confirmed blockers worth waiting for.
293
+ const holdCandidate = facts.phase === 'pre-send'
294
+ ? (current ??
295
+ candidates.find((candidate) => facts.selection &&
296
+ sameAccount(candidate.account, facts.selection.account)))
297
+ : current;
298
+ const windows = (holdCandidate?.confirmedBlockers ??
299
+ (facts.phase === 'after-limit' ? signal?.windows : undefined) ??
300
+ []).filter((window) => window.confirmed);
301
+ if (windows.length) {
302
+ if (axes.shortLimit.preference === 'ready-alternative-first' && alternative)
303
+ return reroute(alternative);
304
+ const held = hold(facts, axes, history, holdCandidate, windows);
305
+ if (held)
306
+ return held;
307
+ }
308
+ const unknown = axes.unknown[facts.host];
309
+ const unconfirmed = facts.phase === 'after-limit' &&
310
+ !windows.length &&
311
+ (status === 429 ||
312
+ signal?.kind === 'rate-limit' ||
313
+ signal?.kind === 'quota-exhausted' ||
314
+ signal?.kind === 'capacity');
315
+ const retainLimitReached = counted && retainCount >= retainLimit;
316
+ if (unconfirmed &&
317
+ current &&
318
+ (unknown.affinity === 'always' || facts.affinity === 'sticky')) {
319
+ if (counted && retainLimitReached) {
320
+ if (alternative)
321
+ return reroute(alternative, 'unconfirmed-retry-limit');
322
+ // With no ready replacement, use the ordinary exhausted-pool outcome.
323
+ }
324
+ else if (counted || unknown.action === 'retain') {
325
+ const hints = [
326
+ ...(facts.retryHintsMs ?? []),
327
+ signal?.retryAfterMs,
328
+ ].filter((hint) => hint !== undefined && Number.isFinite(hint) && (counted || hint >= 0));
329
+ return {
330
+ action: 'retain',
331
+ account: current.account,
332
+ reason: 'unconfirmed-limit',
333
+ ...(counted
334
+ ? {
335
+ retryMs: Math.min(60_000, ...hints.map((hint) => Math.max(0, hint))),
336
+ incrementUnconfirmedRetain: true,
337
+ }
338
+ : unknown.hint === 'minimum'
339
+ ? { retryMs: Math.min(unknown.defaultMs, ...hints) }
340
+ : {}),
341
+ retryable: true,
342
+ hostRetry: continuationRetry(facts, axes),
343
+ history,
344
+ };
345
+ }
346
+ else if (unknown.action === 'pass')
347
+ return pass('unconfirmed-limit');
348
+ }
349
+ if (alternative)
350
+ return reroute(alternative);
351
+ if (facts.phase === 'pre-send' && selectedReady)
352
+ return reroute(selected);
353
+ if (facts.host === 'opencode2' &&
354
+ facts.hostPhase === 'request' &&
355
+ axes.markedPool.requestEscape === 'ignore-timed-marks-if-all-marked' &&
356
+ selected &&
357
+ candidates.every((candidate) => !candidate.ready) &&
358
+ candidates.every((candidate) => candidate.blockers.length > 0 &&
359
+ candidate.blockers.every((blocker) => blocker.kind === 'hard')))
360
+ return reroute(selected);
361
+ const waited = poolWait(facts, axes, history, candidates);
362
+ if (waited)
363
+ return waited;
364
+ if (facts.phase === 'pre-send' && !candidates.length)
365
+ return refusal(facts, axes, history, facts.terminal?.reason ?? 'auth', facts.terminal);
366
+ if (facts.host === 'opencode2' &&
367
+ facts.hostPhase === 'retry' &&
368
+ !facts.terminal) {
369
+ if (axes.markedPool.retryExhaustion === 'host-delay')
370
+ return pass('host-delay');
371
+ if (axes.markedPool.retryExhaustion === 'same-host-delay' && current)
372
+ return {
373
+ action: 'retain',
374
+ account: current.account,
375
+ reason: 'host-delay',
376
+ retryable: true,
377
+ hostRetry: 'leave',
378
+ history,
379
+ };
380
+ }
381
+ if (axes.terminalPolicy === 'status-history' &&
382
+ axes.terminalStatusHistory &&
383
+ facts.host !== 'opencode2' &&
384
+ !facts.terminal) {
385
+ const allMarked = facts.phase === 'pre-send' &&
386
+ candidates.length > 0 &&
387
+ candidates.every((candidate) => !candidate.ready);
388
+ const eligible = candidates.filter((candidate) => candidate.placementEligible);
389
+ const allBalance = facts.phase === 'pre-send' &&
390
+ axes.terminalStatusHistory.paymentBalance &&
391
+ eligible.length > 0 &&
392
+ eligible.every((candidate) => !candidate.ready &&
393
+ candidate.blockers.length > 0 &&
394
+ candidate.blockers.every((blocker) => blocker.cause === 'payment-balance' &&
395
+ finiteFuture(blocker.until, facts.now)));
396
+ if (allBalance ||
397
+ allMarked ||
398
+ (status === 401 && history.saw429) ||
399
+ (axes.terminalStatusHistory.paymentBalance &&
400
+ history.saw429 &&
401
+ history.sawPaymentBalance)) {
402
+ const deadlines = (allBalance ? eligible : candidates)
403
+ .flatMap((candidate) => candidate.blockers.map((blocker) => blocker.until))
404
+ .filter((until) => finiteFuture(until, facts.now));
405
+ return refusal(facts, axes, history, 'quota', {
406
+ source: 'pool',
407
+ reason: 'quota',
408
+ ...(allBalance ? axes.terminalStatusHistory.paymentBalance : {}),
409
+ retryAfterMs: deadlines.length
410
+ ? Math.max(axes.terminalStatusHistory.minRetryMs, Math.min(...deadlines) - facts.now)
411
+ : axes.terminalStatusHistory.defaultRetryMs,
412
+ });
413
+ }
414
+ return pass('original-response');
415
+ }
416
+ if (facts.terminal)
417
+ return refusal(facts, axes, history, facts.terminal.reason, facts.terminal);
418
+ if (signal?.kind === 'auth' || signal?.kind === 'account-access')
419
+ return refusal(facts, axes, history, 'auth');
420
+ if (signal ||
421
+ status === 429 ||
422
+ candidates.some((candidate) => candidate.blockers.length))
423
+ return refusal(facts, axes, history, 'quota');
424
+ return pass('no-override');
425
+ }