codex-multi-auth 2.3.0-beta.0 → 2.3.0-beta.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 (470) hide show
  1. package/.codex-plugin/plugin.json +1 -1
  2. package/README.md +4 -3
  3. package/config/schema/config.schema.json +268 -21
  4. package/dist/index.js +0 -1
  5. package/dist/lib/account-policy.js +0 -1
  6. package/dist/lib/accounts/rate-limits.js +0 -1
  7. package/dist/lib/accounts.d.ts +3 -8
  8. package/dist/lib/accounts.d.ts.map +1 -1
  9. package/dist/lib/accounts.js +2 -3
  10. package/dist/lib/audit.js +0 -1
  11. package/dist/lib/auth/auth.js +0 -1
  12. package/dist/lib/auth/browser.js +0 -1
  13. package/dist/lib/auth/device-auth.js +0 -1
  14. package/dist/lib/auth/index.js +0 -1
  15. package/dist/lib/auth/org-override.js +0 -1
  16. package/dist/lib/auth/server.js +0 -1
  17. package/dist/lib/auth/token-utils.js +0 -1
  18. package/dist/lib/auth-rate-limit.js +0 -1
  19. package/dist/lib/budget-guard.js +0 -1
  20. package/dist/lib/capability-policy.js +0 -1
  21. package/dist/lib/circuit-breaker.js +0 -1
  22. package/dist/lib/cli.js +1 -2
  23. package/dist/lib/codex-cli/index.js +0 -1
  24. package/dist/lib/codex-cli/observability.js +0 -1
  25. package/dist/lib/codex-cli/state.js +0 -1
  26. package/dist/lib/codex-cli/sync.d.ts +2 -2
  27. package/dist/lib/codex-cli/sync.d.ts.map +1 -1
  28. package/dist/lib/codex-cli/sync.js +1 -2
  29. package/dist/lib/codex-cli/writer.js +0 -1
  30. package/dist/lib/codex-manager/account-credentials.d.ts +13 -0
  31. package/dist/lib/codex-manager/account-credentials.d.ts.map +1 -0
  32. package/dist/lib/codex-manager/account-credentials.js +55 -0
  33. package/dist/lib/codex-manager/account-manager-commands.js +0 -1
  34. package/dist/lib/codex-manager/account-pool-write.d.ts +95 -0
  35. package/dist/lib/codex-manager/account-pool-write.d.ts.map +1 -0
  36. package/dist/lib/codex-manager/account-pool-write.js +165 -0
  37. package/dist/lib/codex-manager/account-pool-write.js.map +1 -0
  38. package/dist/lib/codex-manager/backend-category-entry.js +0 -1
  39. package/dist/lib/codex-manager/backend-category-helpers.js +0 -1
  40. package/dist/lib/codex-manager/backend-category-prompt.js +0 -1
  41. package/dist/lib/codex-manager/backend-settings-controller.js +0 -1
  42. package/dist/lib/codex-manager/backend-settings-entry.js +0 -1
  43. package/dist/lib/codex-manager/backend-settings-helpers.js +0 -1
  44. package/dist/lib/codex-manager/backend-settings-prompt.js +0 -1
  45. package/dist/lib/codex-manager/backend-settings-schema.js +0 -1
  46. package/dist/lib/codex-manager/behavior-settings-panel.d.ts +1 -1
  47. package/dist/lib/codex-manager/behavior-settings-panel.d.ts.map +1 -1
  48. package/dist/lib/codex-manager/behavior-settings-panel.js +0 -1
  49. package/dist/lib/codex-manager/commands/account.js +0 -1
  50. package/dist/lib/codex-manager/commands/best.d.ts +8 -0
  51. package/dist/lib/codex-manager/commands/best.d.ts.map +1 -1
  52. package/dist/lib/codex-manager/commands/best.js +64 -1
  53. package/dist/lib/codex-manager/commands/bridge.js +0 -1
  54. package/dist/lib/codex-manager/commands/budget.js +0 -1
  55. package/dist/lib/codex-manager/commands/check.js +0 -1
  56. package/dist/lib/codex-manager/commands/config-explain.js +0 -1
  57. package/dist/lib/codex-manager/commands/debug-bundle.js +0 -1
  58. package/dist/lib/codex-manager/commands/forecast.js +0 -1
  59. package/dist/lib/codex-manager/commands/init-config.js +0 -1
  60. package/dist/lib/codex-manager/commands/integrations.js +0 -1
  61. package/dist/lib/codex-manager/commands/models.js +0 -1
  62. package/dist/lib/codex-manager/commands/monitor.js +0 -1
  63. package/dist/lib/codex-manager/commands/report.js +0 -1
  64. package/dist/lib/codex-manager/commands/rotation.d.ts.map +1 -1
  65. package/dist/lib/codex-manager/commands/rotation.js +1 -4
  66. package/dist/lib/codex-manager/commands/status.js +0 -1
  67. package/dist/lib/codex-manager/commands/switch.js +0 -1
  68. package/dist/lib/codex-manager/commands/uninstall.d.ts.map +1 -1
  69. package/dist/lib/codex-manager/commands/uninstall.js +2 -33
  70. package/dist/lib/codex-manager/commands/unpin.js +0 -1
  71. package/dist/lib/codex-manager/commands/usage.js +0 -1
  72. package/dist/lib/codex-manager/commands/verify.js +0 -1
  73. package/dist/lib/codex-manager/commands/why-selected.js +0 -1
  74. package/dist/lib/codex-manager/commands/workspace.js +0 -1
  75. package/dist/lib/codex-manager/dashboard-display-panel.d.ts +1 -1
  76. package/dist/lib/codex-manager/dashboard-display-panel.d.ts.map +1 -1
  77. package/dist/lib/codex-manager/dashboard-display-panel.js +0 -1
  78. package/dist/lib/codex-manager/dashboard-formatters.js +0 -1
  79. package/dist/lib/codex-manager/dashboard-settings-controller.js +0 -1
  80. package/dist/lib/codex-manager/dashboard-settings-data.js +0 -1
  81. package/dist/lib/codex-manager/dashboard-settings-entry.js +0 -1
  82. package/dist/lib/codex-manager/experimental-settings-entry.js +0 -1
  83. package/dist/lib/codex-manager/experimental-settings-prompt.js +0 -1
  84. package/dist/lib/codex-manager/experimental-settings-schema.js +1 -2
  85. package/dist/lib/codex-manager/experimental-sync-target-entry.js +0 -1
  86. package/dist/lib/codex-manager/experimental-sync-target.js +0 -1
  87. package/dist/lib/codex-manager/forecast-report-commands.js +0 -1
  88. package/dist/lib/codex-manager/forecast-report-shared.d.ts +2 -2
  89. package/dist/lib/codex-manager/forecast-report-shared.d.ts.map +1 -1
  90. package/dist/lib/codex-manager/forecast-report-shared.js +5 -21
  91. package/dist/lib/codex-manager/formatters/account-formatters.d.ts +11 -0
  92. package/dist/lib/codex-manager/formatters/account-formatters.d.ts.map +1 -0
  93. package/dist/lib/codex-manager/formatters/account-formatters.js +79 -0
  94. package/dist/lib/codex-manager/formatters/index.d.ts +5 -0
  95. package/dist/lib/codex-manager/formatters/index.d.ts.map +1 -0
  96. package/dist/lib/codex-manager/formatters/index.js +4 -0
  97. package/dist/lib/codex-manager/formatters/model-formatters.d.ts +12 -0
  98. package/dist/lib/codex-manager/formatters/model-formatters.d.ts.map +1 -0
  99. package/dist/lib/codex-manager/formatters/model-formatters.js +23 -0
  100. package/dist/lib/codex-manager/formatters/quota-formatters.d.ts +11 -0
  101. package/dist/lib/codex-manager/formatters/quota-formatters.d.ts.map +1 -0
  102. package/dist/lib/codex-manager/formatters/quota-formatters.js +104 -0
  103. package/dist/lib/codex-manager/formatters/text-style.d.ts +14 -0
  104. package/dist/lib/codex-manager/formatters/text-style.d.ts.map +1 -0
  105. package/dist/lib/codex-manager/formatters/text-style.js +111 -0
  106. package/dist/lib/codex-manager/health-check.d.ts +14 -0
  107. package/dist/lib/codex-manager/health-check.d.ts.map +1 -0
  108. package/dist/lib/codex-manager/health-check.js +278 -0
  109. package/dist/lib/codex-manager/help.js +0 -1
  110. package/dist/lib/codex-manager/login-action-panel.d.ts +4 -0
  111. package/dist/lib/codex-manager/login-action-panel.d.ts.map +1 -0
  112. package/dist/lib/codex-manager/login-action-panel.js +238 -0
  113. package/dist/lib/codex-manager/login-flow.d.ts +17 -0
  114. package/dist/lib/codex-manager/login-flow.d.ts.map +1 -0
  115. package/dist/lib/codex-manager/login-flow.js +387 -0
  116. package/dist/lib/codex-manager/login-menu-actions.d.ts +20 -0
  117. package/dist/lib/codex-manager/login-menu-actions.d.ts.map +1 -0
  118. package/dist/lib/codex-manager/login-menu-actions.js +303 -0
  119. package/dist/lib/codex-manager/login-menu-data.d.ts +19 -0
  120. package/dist/lib/codex-manager/login-menu-data.d.ts.map +1 -0
  121. package/dist/lib/codex-manager/login-menu-data.js +378 -0
  122. package/dist/lib/codex-manager/login-oauth.d.ts +55 -0
  123. package/dist/lib/codex-manager/login-oauth.d.ts.map +1 -0
  124. package/dist/lib/codex-manager/login-oauth.js +345 -0
  125. package/dist/lib/codex-manager/manual-callback.d.ts +33 -0
  126. package/dist/lib/codex-manager/manual-callback.d.ts.map +1 -0
  127. package/dist/lib/codex-manager/manual-callback.js +30 -0
  128. package/dist/lib/codex-manager/manual-callback.js.map +1 -0
  129. package/dist/lib/codex-manager/persist-selected-account.d.ts +24 -0
  130. package/dist/lib/codex-manager/persist-selected-account.d.ts.map +1 -0
  131. package/dist/lib/codex-manager/persist-selected-account.js +107 -0
  132. package/dist/lib/codex-manager/quota-cache-helpers.d.ts +18 -0
  133. package/dist/lib/codex-manager/quota-cache-helpers.d.ts.map +1 -0
  134. package/dist/lib/codex-manager/quota-cache-helpers.js +112 -0
  135. package/dist/lib/codex-manager/rate-limit-markers.js +0 -1
  136. package/dist/lib/codex-manager/repair-commands.js +0 -1
  137. package/dist/lib/codex-manager/settings-hub/backend.js +1 -2
  138. package/dist/lib/codex-manager/settings-hub/dashboard.js +1 -2
  139. package/dist/lib/codex-manager/settings-hub/experimental.js +1 -2
  140. package/dist/lib/codex-manager/settings-hub/index.js +1 -2
  141. package/dist/lib/codex-manager/settings-hub/shared.js +0 -1
  142. package/dist/lib/codex-manager/settings-hub-entry.js +0 -1
  143. package/dist/lib/codex-manager/settings-hub-menu.js +0 -1
  144. package/dist/lib/codex-manager/settings-hub-prompt.js +0 -1
  145. package/dist/lib/codex-manager/settings-hub.js +0 -1
  146. package/dist/lib/codex-manager/settings-panels.js +0 -1
  147. package/dist/lib/codex-manager/settings-persist-utils.js +0 -1
  148. package/dist/lib/codex-manager/settings-preview.js +0 -1
  149. package/dist/lib/codex-manager/settings-write-queue.js +0 -1
  150. package/dist/lib/codex-manager/statusline-order.js +0 -1
  151. package/dist/lib/codex-manager/statusline-settings-panel.d.ts +1 -1
  152. package/dist/lib/codex-manager/statusline-settings-panel.d.ts.map +1 -1
  153. package/dist/lib/codex-manager/statusline-settings-panel.js +0 -1
  154. package/dist/lib/codex-manager/theme-settings-panel.d.ts +1 -1
  155. package/dist/lib/codex-manager/theme-settings-panel.d.ts.map +1 -1
  156. package/dist/lib/codex-manager/theme-settings-panel.js +0 -1
  157. package/dist/lib/codex-manager/unified-settings-controller.js +0 -1
  158. package/dist/lib/codex-manager/unified-settings-entry.js +0 -1
  159. package/dist/lib/codex-manager.d.ts +2 -4
  160. package/dist/lib/codex-manager.d.ts.map +1 -1
  161. package/dist/lib/codex-manager.js +219 -2578
  162. package/dist/lib/codex-manager.js.map +1 -1
  163. package/dist/lib/config-schema.d.ts +32 -0
  164. package/dist/lib/config-schema.d.ts.map +1 -0
  165. package/dist/lib/config-schema.js +96 -0
  166. package/dist/lib/config.d.ts.map +1 -1
  167. package/dist/lib/config.js +60 -104
  168. package/dist/lib/constants.js +0 -1
  169. package/dist/lib/context-overflow.js +0 -1
  170. package/dist/lib/dashboard-settings.js +0 -1
  171. package/dist/lib/entitlement-cache.js +0 -1
  172. package/dist/lib/env-parsing.js +0 -1
  173. package/dist/lib/errors.js +0 -1
  174. package/dist/lib/forecast.js +0 -1
  175. package/dist/lib/fs-retry.d.ts +46 -0
  176. package/dist/lib/fs-retry.d.ts.map +1 -1
  177. package/dist/lib/fs-retry.js +74 -6
  178. package/dist/lib/health.js +0 -1
  179. package/dist/lib/index.js +0 -1
  180. package/dist/lib/integration-generators.js +0 -1
  181. package/dist/lib/live-account-sync.js +0 -1
  182. package/dist/lib/local-bridge.js +0 -1
  183. package/dist/lib/local-client-tokens.js +0 -1
  184. package/dist/lib/logger.js +0 -1
  185. package/dist/lib/model-capability-matrix.js +0 -1
  186. package/dist/lib/named-backup-export.js +0 -1
  187. package/dist/lib/oc-chatgpt-import-adapter.js +0 -1
  188. package/dist/lib/oc-chatgpt-orchestrator.js +0 -1
  189. package/dist/lib/oc-chatgpt-target-detection.js +0 -1
  190. package/dist/lib/parallel-probe.js +0 -1
  191. package/dist/lib/policy/runtime-policy.js +0 -1
  192. package/dist/lib/preemptive-quota-scheduler.js +0 -1
  193. package/dist/lib/proactive-refresh.js +0 -1
  194. package/dist/lib/prompts/codex-host-bridge.js +0 -1
  195. package/dist/lib/prompts/codex.d.ts +3 -11
  196. package/dist/lib/prompts/codex.d.ts.map +1 -1
  197. package/dist/lib/prompts/codex.js +4 -12
  198. package/dist/lib/prompts/fetch-utils.js +0 -1
  199. package/dist/lib/prompts/host-codex-prompt.js +0 -1
  200. package/dist/lib/quota-cache.d.ts.map +1 -1
  201. package/dist/lib/quota-cache.js +15 -43
  202. package/dist/lib/quota-probe.js +0 -1
  203. package/dist/lib/quota-readiness.js +0 -1
  204. package/dist/lib/recovery/constants.js +0 -1
  205. package/dist/lib/recovery/index.js +0 -1
  206. package/dist/lib/recovery/storage.d.ts.map +1 -1
  207. package/dist/lib/recovery/storage.js +30 -51
  208. package/dist/lib/recovery/storage.js.map +1 -1
  209. package/dist/lib/recovery/types.js +0 -1
  210. package/dist/lib/recovery.js +0 -1
  211. package/dist/lib/refresh-guardian.js +0 -1
  212. package/dist/lib/refresh-lease.d.ts.map +1 -1
  213. package/dist/lib/refresh-lease.js +1 -4
  214. package/dist/lib/refresh-queue.js +0 -1
  215. package/dist/lib/request/error-classification.d.ts +75 -0
  216. package/dist/lib/request/error-classification.d.ts.map +1 -0
  217. package/dist/lib/request/error-classification.js +295 -0
  218. package/dist/lib/request/failover-config.js +0 -1
  219. package/dist/lib/request/failure-policy.js +0 -1
  220. package/dist/lib/request/fetch-helpers.d.ts +10 -114
  221. package/dist/lib/request/fetch-helpers.d.ts.map +1 -1
  222. package/dist/lib/request/fetch-helpers.js +7 -589
  223. package/dist/lib/request/headers.d.ts +33 -0
  224. package/dist/lib/request/headers.d.ts.map +1 -0
  225. package/dist/lib/request/headers.js +64 -0
  226. package/dist/lib/request/helpers/input-utils.js +0 -1
  227. package/dist/lib/request/helpers/model-map.d.ts +10 -0
  228. package/dist/lib/request/helpers/model-map.d.ts.map +1 -1
  229. package/dist/lib/request/helpers/model-map.js +11 -1
  230. package/dist/lib/request/helpers/tool-utils.js +0 -1
  231. package/dist/lib/request/index.js +0 -1
  232. package/dist/lib/request/rate-limit-backoff.js +0 -1
  233. package/dist/lib/request/rate-limit-decision.d.ts +28 -0
  234. package/dist/lib/request/rate-limit-decision.d.ts.map +1 -0
  235. package/dist/lib/request/rate-limit-decision.js +191 -0
  236. package/dist/lib/request/request-attempt-budget.js +0 -1
  237. package/dist/lib/request/request-init.js +0 -1
  238. package/dist/lib/request/request-resilience.js +0 -1
  239. package/dist/lib/request/request-transformer.js +0 -1
  240. package/dist/lib/request/response-compaction.js +0 -1
  241. package/dist/lib/request/response-handler.js +0 -1
  242. package/dist/lib/request/response-metadata.js +0 -1
  243. package/dist/lib/request/stream-failover-runtime.d.ts +8 -0
  244. package/dist/lib/request/stream-failover-runtime.d.ts.map +1 -0
  245. package/dist/lib/request/stream-failover-runtime.js +149 -0
  246. package/dist/lib/request/stream-failover.js +0 -1
  247. package/dist/lib/request/token-refresh.d.ts +30 -0
  248. package/dist/lib/request/token-refresh.d.ts.map +1 -0
  249. package/dist/lib/request/token-refresh.js +116 -0
  250. package/dist/lib/request/url-rewriting.d.ts +24 -0
  251. package/dist/lib/request/url-rewriting.d.ts.map +1 -0
  252. package/dist/lib/request/url-rewriting.js +153 -0
  253. package/dist/lib/request/wait-utils.js +0 -1
  254. package/dist/lib/rotation.d.ts +1 -1
  255. package/dist/lib/rotation.d.ts.map +1 -1
  256. package/dist/lib/rotation.js +0 -1
  257. package/dist/lib/routing-mutex.js +0 -1
  258. package/dist/lib/routing-profiles.js +0 -1
  259. package/dist/lib/runtime/account-check-helpers.js +0 -1
  260. package/dist/lib/runtime/account-check-types.js +0 -1
  261. package/dist/lib/runtime/account-check.js +0 -1
  262. package/dist/lib/runtime/account-health-check.js +0 -1
  263. package/dist/lib/runtime/account-manager-cache-entry.js +0 -1
  264. package/dist/lib/runtime/account-manager-cache.js +0 -1
  265. package/dist/lib/runtime/account-pool.js +0 -1
  266. package/dist/lib/runtime/account-scope.js +0 -1
  267. package/dist/lib/runtime/account-select-event.js +0 -1
  268. package/dist/lib/runtime/account-selection.js +0 -1
  269. package/dist/lib/runtime/account-state.js +0 -1
  270. package/dist/lib/runtime/account-status.js +0 -1
  271. package/dist/lib/runtime/account-storage-scope-entry.js +0 -1
  272. package/dist/lib/runtime/app-bind.js +0 -1
  273. package/dist/lib/runtime/auth-facade.js +0 -1
  274. package/dist/lib/runtime/browser-oauth-flow.js +0 -1
  275. package/dist/lib/runtime/capability-boost.js +0 -1
  276. package/dist/lib/runtime/config-toml.js +0 -1
  277. package/dist/lib/runtime/event-handler.js +0 -1
  278. package/dist/lib/runtime/first-run.d.ts +80 -0
  279. package/dist/lib/runtime/first-run.d.ts.map +1 -0
  280. package/dist/lib/runtime/first-run.js +327 -0
  281. package/dist/lib/runtime/flagged-verify-types.js +0 -1
  282. package/dist/lib/runtime/hydrate-emails.js +0 -1
  283. package/dist/lib/runtime/live-sync-entry.js +0 -1
  284. package/dist/lib/runtime/live-sync.js +0 -1
  285. package/dist/lib/runtime/loader-setup.js +0 -1
  286. package/dist/lib/runtime/login-menu-accounts.js +0 -1
  287. package/dist/lib/runtime/manual-oauth-flow.js +0 -1
  288. package/dist/lib/runtime/oauth-browser-flow.js +0 -1
  289. package/dist/lib/runtime/preemptive-quota.js +0 -1
  290. package/dist/lib/runtime/quota-headers.js +0 -1
  291. package/dist/lib/runtime/quota-probe.js +0 -1
  292. package/dist/lib/runtime/quota-settings.js +0 -1
  293. package/dist/lib/runtime/refresh-guardian-entry.js +0 -1
  294. package/dist/lib/runtime/refresh-guardian.js +0 -1
  295. package/dist/lib/runtime/request-init.js +0 -1
  296. package/dist/lib/runtime/rotation-account-selection.d.ts +38 -0
  297. package/dist/lib/runtime/rotation-account-selection.d.ts.map +1 -0
  298. package/dist/lib/runtime/rotation-account-selection.js +172 -0
  299. package/dist/lib/runtime/rotation-proxy-state.d.ts +54 -0
  300. package/dist/lib/runtime/rotation-proxy-state.d.ts.map +1 -0
  301. package/dist/lib/runtime/rotation-proxy-state.js +56 -0
  302. package/dist/lib/runtime/rotation-server-types.d.ts +57 -0
  303. package/dist/lib/runtime/rotation-server-types.d.ts.map +1 -0
  304. package/dist/lib/runtime/rotation-server-types.js +1 -0
  305. package/dist/lib/runtime/rotation-storage-meta.d.ts +40 -0
  306. package/dist/lib/runtime/rotation-storage-meta.d.ts.map +1 -0
  307. package/dist/lib/runtime/rotation-storage-meta.js +143 -0
  308. package/dist/lib/runtime/rotation-token-refresh.d.ts +25 -0
  309. package/dist/lib/runtime/rotation-token-refresh.d.ts.map +1 -0
  310. package/dist/lib/runtime/rotation-token-refresh.js +99 -0
  311. package/dist/lib/runtime/runtime-current-account.d.ts.map +1 -1
  312. package/dist/lib/runtime/runtime-current-account.js +1 -4
  313. package/dist/lib/runtime/runtime-observability.js +0 -1
  314. package/dist/lib/runtime/runtime-services.js +0 -1
  315. package/dist/lib/runtime/session-affinity-entry.js +0 -1
  316. package/dist/lib/runtime/session-affinity.js +0 -1
  317. package/dist/lib/runtime/session-recovery.js +0 -1
  318. package/dist/lib/runtime/status-marker.js +0 -1
  319. package/dist/lib/runtime/storage-scope.js +0 -1
  320. package/dist/lib/runtime/toast.js +0 -1
  321. package/dist/lib/runtime/ui-runtime-entry.js +0 -1
  322. package/dist/lib/runtime/ui-runtime.js +0 -1
  323. package/dist/lib/runtime/verify-flagged.js +0 -1
  324. package/dist/lib/runtime-constants.js +0 -1
  325. package/dist/lib/runtime-paths.js +0 -1
  326. package/dist/lib/runtime-rotation-proxy.d.ts +7 -124
  327. package/dist/lib/runtime-rotation-proxy.d.ts.map +1 -1
  328. package/dist/lib/runtime-rotation-proxy.js +614 -1353
  329. package/dist/lib/schemas.d.ts +3 -3
  330. package/dist/lib/schemas.js +1 -2
  331. package/dist/lib/session-affinity.js +0 -1
  332. package/dist/lib/shutdown.js +0 -1
  333. package/dist/lib/storage/account-clear-entry.js +0 -1
  334. package/dist/lib/storage/account-clear.js +0 -1
  335. package/dist/lib/storage/account-match-utils.js +0 -1
  336. package/dist/lib/storage/account-persistence.d.ts +1 -1
  337. package/dist/lib/storage/account-persistence.d.ts.map +1 -1
  338. package/dist/lib/storage/account-persistence.js +0 -1
  339. package/dist/lib/storage/account-port.d.ts +1 -1
  340. package/dist/lib/storage/account-port.d.ts.map +1 -1
  341. package/dist/lib/storage/account-port.js +0 -1
  342. package/dist/lib/storage/account-save-entry.d.ts +1 -1
  343. package/dist/lib/storage/account-save-entry.d.ts.map +1 -1
  344. package/dist/lib/storage/account-save-entry.js +0 -1
  345. package/dist/lib/storage/account-save.d.ts +1 -1
  346. package/dist/lib/storage/account-save.d.ts.map +1 -1
  347. package/dist/lib/storage/account-save.js +0 -1
  348. package/dist/lib/storage/account-snapshot.js +0 -1
  349. package/dist/lib/storage/backup-metadata-builder.d.ts +1 -1
  350. package/dist/lib/storage/backup-metadata-builder.d.ts.map +1 -1
  351. package/dist/lib/storage/backup-metadata-builder.js +0 -1
  352. package/dist/lib/storage/backup-metadata.d.ts +13 -0
  353. package/dist/lib/storage/backup-metadata.d.ts.map +1 -1
  354. package/dist/lib/storage/backup-metadata.js +0 -1
  355. package/dist/lib/storage/backup-paths.js +0 -1
  356. package/dist/lib/storage/backup-restore.d.ts +1 -1
  357. package/dist/lib/storage/backup-restore.d.ts.map +1 -1
  358. package/dist/lib/storage/backup-restore.js +0 -1
  359. package/dist/lib/storage/cache-artifacts.js +0 -1
  360. package/dist/lib/storage/error-hints.js +0 -1
  361. package/dist/lib/storage/file-paths.js +0 -1
  362. package/dist/lib/storage/fixture-guards.d.ts +1 -1
  363. package/dist/lib/storage/fixture-guards.d.ts.map +1 -1
  364. package/dist/lib/storage/fixture-guards.js +0 -1
  365. package/dist/lib/storage/flagged-entry.js +0 -1
  366. package/dist/lib/storage/flagged-load-entry.d.ts +1 -1
  367. package/dist/lib/storage/flagged-load-entry.d.ts.map +1 -1
  368. package/dist/lib/storage/flagged-load-entry.js +0 -1
  369. package/dist/lib/storage/flagged-save-entry.d.ts +1 -1
  370. package/dist/lib/storage/flagged-save-entry.d.ts.map +1 -1
  371. package/dist/lib/storage/flagged-save-entry.js +0 -1
  372. package/dist/lib/storage/flagged-storage-file.d.ts +1 -1
  373. package/dist/lib/storage/flagged-storage-file.d.ts.map +1 -1
  374. package/dist/lib/storage/flagged-storage-file.js +0 -1
  375. package/dist/lib/storage/flagged-storage-io.d.ts +1 -1
  376. package/dist/lib/storage/flagged-storage-io.d.ts.map +1 -1
  377. package/dist/lib/storage/flagged-storage-io.js +0 -1
  378. package/dist/lib/storage/flagged-storage.d.ts +1 -1
  379. package/dist/lib/storage/flagged-storage.d.ts.map +1 -1
  380. package/dist/lib/storage/flagged-storage.js +15 -2
  381. package/dist/lib/storage/flagged-storage.js.map +1 -1
  382. package/dist/lib/storage/gitignore.js +0 -1
  383. package/dist/lib/storage/hash.js +0 -1
  384. package/dist/lib/storage/health.js +0 -1
  385. package/dist/lib/storage/identity.js +0 -1
  386. package/dist/lib/storage/import-export.d.ts +1 -1
  387. package/dist/lib/storage/import-export.d.ts.map +1 -1
  388. package/dist/lib/storage/import-export.js +0 -1
  389. package/dist/lib/storage/metadata-section.js +0 -1
  390. package/dist/lib/storage/migrations.d.ts +5 -48
  391. package/dist/lib/storage/migrations.d.ts.map +1 -1
  392. package/dist/lib/storage/migrations.js +5 -2
  393. package/dist/lib/storage/named-backup-entry.js +0 -1
  394. package/dist/lib/storage/named-backups-entry.d.ts +1 -1
  395. package/dist/lib/storage/named-backups-entry.d.ts.map +1 -1
  396. package/dist/lib/storage/named-backups-entry.js +0 -1
  397. package/dist/lib/storage/named-backups.js +0 -1
  398. package/dist/lib/storage/path-state.js +0 -1
  399. package/dist/lib/storage/paths.js +0 -1
  400. package/dist/lib/storage/project-migration.d.ts +1 -1
  401. package/dist/lib/storage/project-migration.d.ts.map +1 -1
  402. package/dist/lib/storage/project-migration.js +0 -1
  403. package/dist/lib/storage/public-types.d.ts +70 -0
  404. package/dist/lib/storage/public-types.d.ts.map +1 -0
  405. package/dist/lib/storage/public-types.js +6 -0
  406. package/dist/lib/storage/record-utils.js +0 -1
  407. package/dist/lib/storage/restore-assessment.d.ts +1 -1
  408. package/dist/lib/storage/restore-assessment.d.ts.map +1 -1
  409. package/dist/lib/storage/restore-assessment.js +0 -1
  410. package/dist/lib/storage/restore-backup-entry.d.ts +1 -1
  411. package/dist/lib/storage/restore-backup-entry.d.ts.map +1 -1
  412. package/dist/lib/storage/restore-backup-entry.js +0 -1
  413. package/dist/lib/storage/restore-metadata.d.ts +1 -1
  414. package/dist/lib/storage/restore-metadata.d.ts.map +1 -1
  415. package/dist/lib/storage/restore-metadata.js +0 -1
  416. package/dist/lib/storage/restore.d.ts +1 -1
  417. package/dist/lib/storage/restore.d.ts.map +1 -1
  418. package/dist/lib/storage/restore.js +0 -1
  419. package/dist/lib/storage/save-retry.d.ts +10 -0
  420. package/dist/lib/storage/save-retry.d.ts.map +1 -0
  421. package/dist/lib/storage/save-retry.js +26 -0
  422. package/dist/lib/storage/snapshot-inspectors.d.ts +1 -1
  423. package/dist/lib/storage/snapshot-inspectors.d.ts.map +1 -1
  424. package/dist/lib/storage/snapshot-inspectors.js +0 -1
  425. package/dist/lib/storage/storage-parser.d.ts +1 -1
  426. package/dist/lib/storage/storage-parser.d.ts.map +1 -1
  427. package/dist/lib/storage/storage-parser.js +0 -1
  428. package/dist/lib/storage/transactions.d.ts +1 -1
  429. package/dist/lib/storage/transactions.d.ts.map +1 -1
  430. package/dist/lib/storage/transactions.js +0 -1
  431. package/dist/lib/storage.d.ts +3 -24
  432. package/dist/lib/storage.d.ts.map +1 -1
  433. package/dist/lib/storage.js +17 -32
  434. package/dist/lib/table-formatter.js +0 -1
  435. package/dist/lib/tools/hashline-tools.js +0 -1
  436. package/dist/lib/types.js +0 -1
  437. package/dist/lib/ui/ansi.js +0 -1
  438. package/dist/lib/ui/auth-menu-builder.d.ts +89 -0
  439. package/dist/lib/ui/auth-menu-builder.d.ts.map +1 -0
  440. package/dist/lib/ui/auth-menu-builder.js +350 -0
  441. package/dist/lib/ui/auth-menu.d.ts +2 -76
  442. package/dist/lib/ui/auth-menu.d.ts.map +1 -1
  443. package/dist/lib/ui/auth-menu.js +3 -349
  444. package/dist/lib/ui/confirm.js +0 -1
  445. package/dist/lib/ui/copy.d.ts +2 -0
  446. package/dist/lib/ui/copy.d.ts.map +1 -1
  447. package/dist/lib/ui/copy.js +2 -0
  448. package/dist/lib/ui/copy.js.map +1 -1
  449. package/dist/lib/ui/display-width.js +0 -1
  450. package/dist/lib/ui/format.js +0 -1
  451. package/dist/lib/ui/index.d.ts +10 -0
  452. package/dist/lib/ui/index.d.ts.map +1 -0
  453. package/dist/lib/ui/index.js +9 -0
  454. package/dist/lib/ui/runtime.js +0 -1
  455. package/dist/lib/ui/select.js +0 -1
  456. package/dist/lib/ui/theme.js +0 -1
  457. package/dist/lib/ui/ui-copy.d.ts +159 -0
  458. package/dist/lib/ui/ui-copy.d.ts.map +1 -0
  459. package/dist/lib/ui/ui-copy.js +163 -0
  460. package/dist/lib/unified-settings.js +0 -1
  461. package/dist/lib/update-notice.js +0 -1
  462. package/dist/lib/usage/index.js +0 -1
  463. package/dist/lib/usage/ledger.js +0 -1
  464. package/dist/lib/usage/pricing.js +0 -1
  465. package/dist/lib/usage/redaction.js +0 -1
  466. package/dist/lib/usage/types.js +0 -1
  467. package/dist/lib/utils.js +0 -1
  468. package/package.json +8 -8
  469. package/scripts/postinstall.js +34 -265
  470. package/scripts/preuninstall.js +2 -2
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Header construction helpers for the custom fetch implementation
3
+ * Extracted from fetch-helpers.ts (audit roadmap §4.1.2); fetch-helpers.ts
4
+ * re-exports the public symbols so existing importers are unchanged.
5
+ */
6
+ import { logWarn } from "../logger.js";
7
+ import { isRecord } from "../utils.js";
8
+ import { OPENAI_HEADERS, OPENAI_HEADER_VALUES } from "../constants.js";
9
+ const CREATE_CODEX_HEADERS_PARAM_KEYS = new Set(["init", "accountId", "accessToken", "opts"]);
10
+ function isCreateCodexHeadersNamedParams(value) {
11
+ if (!isRecord(value))
12
+ return false;
13
+ if (typeof value.accountId !== "string" || typeof value.accessToken !== "string")
14
+ return false;
15
+ return Object.keys(value).every((key) => CREATE_CODEX_HEADERS_PARAM_KEYS.has(key));
16
+ }
17
+ export function createCodexHeaders(initOrParams, accountId, accessToken, opts) {
18
+ const useNamedParams = typeof accountId === "undefined" &&
19
+ typeof accessToken === "undefined" &&
20
+ isCreateCodexHeadersNamedParams(initOrParams);
21
+ const namedParams = useNamedParams
22
+ ? initOrParams
23
+ : null;
24
+ const resolvedInit = useNamedParams
25
+ ? namedParams?.init
26
+ : initOrParams;
27
+ const resolvedAccountId = useNamedParams ? namedParams?.accountId : accountId;
28
+ const resolvedAccessToken = useNamedParams ? namedParams?.accessToken : accessToken;
29
+ const resolvedOpts = useNamedParams ? namedParams?.opts : opts;
30
+ if (!resolvedAccountId || !resolvedAccessToken) {
31
+ throw new TypeError("createCodexHeaders requires accountId and accessToken");
32
+ }
33
+ const headers = new Headers(resolvedInit?.headers ?? {});
34
+ headers.delete("x-api-key"); // Remove any existing API key
35
+ headers.set("Authorization", `Bearer ${resolvedAccessToken}`);
36
+ headers.set(OPENAI_HEADERS.ACCOUNT_ID, resolvedAccountId);
37
+ headers.set(OPENAI_HEADERS.BETA, OPENAI_HEADER_VALUES.BETA_RESPONSES);
38
+ headers.set(OPENAI_HEADERS.ORIGINATOR, OPENAI_HEADER_VALUES.ORIGINATOR_CODEX);
39
+ const cacheKey = resolvedOpts?.promptCacheKey;
40
+ if (cacheKey) {
41
+ headers.set(OPENAI_HEADERS.CONVERSATION_ID, cacheKey);
42
+ headers.set(OPENAI_HEADERS.SESSION_ID, cacheKey);
43
+ }
44
+ else {
45
+ headers.delete(OPENAI_HEADERS.CONVERSATION_ID);
46
+ headers.delete(OPENAI_HEADERS.SESSION_ID);
47
+ }
48
+ headers.set("accept", "text/event-stream");
49
+ return headers;
50
+ }
51
+ /**
52
+ * Log RFC 8594 Deprecation/Sunset headers if present. Shared by the success and
53
+ * error response handlers so a sunset notice is surfaced regardless of status
54
+ * (request-01).
55
+ *
56
+ * @internal Exported only for sibling lib/request modules; import via fetch-helpers.ts elsewhere.
57
+ */
58
+ export function logDeprecationHeaders(response) {
59
+ const deprecation = response.headers.get("Deprecation");
60
+ const sunset = response.headers.get("Sunset");
61
+ if (deprecation || sunset) {
62
+ logWarn(`API deprecation notice`, { deprecation, sunset });
63
+ }
64
+ }
@@ -211,4 +211,3 @@ export const injectMissingToolOutputs = (input) => {
211
211
  }
212
212
  return result;
213
213
  };
214
- //# sourceMappingURL=input-utils.js.map
@@ -8,6 +8,16 @@
8
8
  */
9
9
  export type ModelReasoningEffort = "none" | "minimal" | "low" | "medium" | "high" | "xhigh";
10
10
  export type PromptModelFamily = "gpt-5-codex" | "codex-max" | "codex" | "gpt-5.2" | "gpt-5.1";
11
+ /**
12
+ * Model family type for prompt selection
13
+ * Maps to different system prompts in the Codex CLI
14
+ */
15
+ export type ModelFamily = PromptModelFamily;
16
+ /**
17
+ * All supported model families
18
+ * Used for per-family account rotation and rate limit tracking
19
+ */
20
+ export declare const MODEL_FAMILIES: readonly ModelFamily[];
11
21
  export interface ModelCapabilities {
12
22
  toolSearch: boolean;
13
23
  computerUse: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"model-map.d.ts","sourceRoot":"","sources":["../../../../lib/request/helpers/model-map.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,MAAM,oBAAoB,GAC7B,MAAM,GACN,SAAS,GACT,KAAK,GACL,QAAQ,GACR,MAAM,GACN,OAAO,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAC1B,aAAa,GACb,WAAW,GACX,OAAO,GACP,SAAS,GACT,SAAS,CAAC;AAEb,MAAM,WAAW,iBAAiB;IACjC,UAAU,EAAE,OAAO,CAAC;IACpB,WAAW,EAAE,OAAO,CAAC;IACrB,UAAU,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,YAAY;IAC5B,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,iBAAiB,CAAC;IAChC,sBAAsB,EAAE,oBAAoB,CAAC;IAC7C,yBAAyB,EAAE,SAAS,oBAAoB,EAAE,CAAC;IAC3D,YAAY,EAAE,iBAAiB,CAAC;CAChC;AA6CD,eAAO,MAAM,mBAAmB,kBAAkB,CAAC;AACnD,eAAO,MAAM,aAAa,YAAY,CAAC;AAKvC,eAAO,MAAM,uBAAuB,kFAM1B,CAAC;AA4CX;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAqF9C,CAAC;AAEX,QAAA,MAAM,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,CAAC;AAoE7C,OAAO,EAAE,SAAS,EAAE,CAAC;AA6IrB;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAQtE;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAsBxE;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,YAAY,CAavE;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,iBAAiB,CAEjF;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAErD"}
1
+ {"version":3,"file":"model-map.d.ts","sourceRoot":"","sources":["../../../../lib/request/helpers/model-map.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,MAAM,oBAAoB,GAC7B,MAAM,GACN,SAAS,GACT,KAAK,GACL,QAAQ,GACR,MAAM,GACN,OAAO,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAC1B,aAAa,GACb,WAAW,GACX,OAAO,GACP,SAAS,GACT,SAAS,CAAC;AAEb;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,iBAAiB,CAAC;AAE5C;;;GAGG;AACH,eAAO,MAAM,cAAc,EAAE,SAAS,WAAW,EAMvC,CAAC;AAEX,MAAM,WAAW,iBAAiB;IACjC,UAAU,EAAE,OAAO,CAAC;IACpB,WAAW,EAAE,OAAO,CAAC;IACrB,UAAU,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,YAAY;IAC5B,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,iBAAiB,CAAC;IAChC,sBAAsB,EAAE,oBAAoB,CAAC;IAC7C,yBAAyB,EAAE,SAAS,oBAAoB,EAAE,CAAC;IAC3D,YAAY,EAAE,iBAAiB,CAAC;CAChC;AA6CD,eAAO,MAAM,mBAAmB,kBAAkB,CAAC;AACnD,eAAO,MAAM,aAAa,YAAY,CAAC;AAKvC,eAAO,MAAM,uBAAuB,kFAM1B,CAAC;AA4CX;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAqF9C,CAAC;AAEX,QAAA,MAAM,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,CAAC;AAoE7C,OAAO,EAAE,SAAS,EAAE,CAAC;AA6IrB;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAQtE;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAsBxE;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,YAAY,CAavE;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,iBAAiB,CAEjF;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAErD"}
@@ -6,6 +6,17 @@
6
6
  * tool-surface metadata so routing logic stays consistent across the request
7
7
  * transformer, prompt selection, and CLI diagnostics.
8
8
  */
9
+ /**
10
+ * All supported model families
11
+ * Used for per-family account rotation and rate limit tracking
12
+ */
13
+ export const MODEL_FAMILIES = [
14
+ "gpt-5-codex",
15
+ "codex-max",
16
+ "codex",
17
+ "gpt-5.2",
18
+ "gpt-5.1",
19
+ ];
9
20
  const REASONING_VARIANTS = [
10
21
  "none",
11
22
  "minimal",
@@ -403,4 +414,3 @@ export function getModelCapabilities(model) {
403
414
  export function isKnownModel(modelId) {
404
415
  return getNormalizedModel(modelId) !== undefined;
405
416
  }
406
- //# sourceMappingURL=model-map.js.map
@@ -157,4 +157,3 @@ function cleanupSchema(schema) {
157
157
  cleanupSchema(schema.items);
158
158
  }
159
159
  }
160
- //# sourceMappingURL=tool-utils.js.map
@@ -2,4 +2,3 @@ export * from "./failure-policy.js";
2
2
  export * from "./fetch-helpers.js";
3
3
  export * from "./rate-limit-backoff.js";
4
4
  export * from "./request-transformer.js";
5
- //# sourceMappingURL=index.js.map
@@ -186,4 +186,3 @@ export function getRateLimitBackoffWithReason(accountIndexOrParams, quotaKey, se
186
186
  reason: resolvedReason,
187
187
  };
188
188
  }
189
- //# sourceMappingURL=rate-limit-backoff.js.map
@@ -0,0 +1,28 @@
1
+ import type { ExhaustionReason } from "../runtime/rotation-server-types.js";
2
+ import type { TokenResult } from "../types.js";
3
+ export declare function isTokenInvalidationError(bodyText: string): boolean;
4
+ export declare function isTokenRefreshRetryable(result: Extract<TokenResult, {
5
+ type: "failed";
6
+ }>): boolean;
7
+ export declare function parseRetryAfterHeaderMs(headers: Headers, now: number): number | null;
8
+ export declare function parseRetryAfterBodyMs(bodyText: string, now: number): number | null;
9
+ export declare function buildTokenInvalidationBody(upstreamBodyText: string): string;
10
+ export declare function extractErrorCodeFromBody(bodyText: string): string | null;
11
+ export declare function getQuotaNearExhaustionWaitMs(headers: Headers, remainingThreshold: number, now: number): number;
12
+ export declare function normalizeExhaustionStatus(reason: ExhaustionReason): number;
13
+ /**
14
+ * Build the JSON `error` body for a pinned-account 503 response. Extracted so
15
+ * the null-reason desync path (`reason: null`, no parenthetical in `message`)
16
+ * can be unit-tested without standing up a full proxy. The shape mirrors
17
+ * `writePoolExhausted` so consumers can handle both 503 codes uniformly. See
18
+ * issue #486.
19
+ */
20
+ export interface PinnedUnavailableErrorBody {
21
+ message: string;
22
+ code: "codex_pinned_account_unavailable";
23
+ pinnedAccountIndex: number | null;
24
+ reason: string | null;
25
+ account_skip_reasons: Record<string, string>;
26
+ }
27
+ export declare function buildPinnedUnavailableErrorBody(pinnedIndex: number | null | undefined, accountSkipReasons: ReadonlyMap<number, string>): PinnedUnavailableErrorBody;
28
+ //# sourceMappingURL=rate-limit-decision.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rate-limit-decision.d.ts","sourceRoot":"","sources":["../../../lib/request/rate-limit-decision.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAe/C,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAGlE;AAED,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,OAAO,CAAC,WAAW,EAAE;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC,GAAG,OAAO,CAWjG;AAED,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAapF;AAED,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAoBlF;AAYD,wBAAgB,0BAA0B,CAAC,gBAAgB,EAAE,MAAM,GAAG,MAAM,CAuB3E;AAED,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAkBxE;AA0BD,wBAAgB,4BAA4B,CAC3C,OAAO,EAAE,OAAO,EAChB,kBAAkB,EAAE,MAAM,EAC1B,GAAG,EAAE,MAAM,GACT,MAAM,CAUR;AAED,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,gBAAgB,GAAG,MAAM,CAE1E;AAED;;;;;;GAMG;AACH,MAAM,WAAW,0BAA0B;IAC1C,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,kCAAkC,CAAC;IACzC,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,oBAAoB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC7C;AAED,wBAAgB,+BAA+B,CAC9C,WAAW,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACtC,kBAAkB,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GAC7C,0BAA0B,CA0B5B"}
@@ -0,0 +1,191 @@
1
+ import { HTTP_STATUS } from "../constants.js";
2
+ import { isRecord } from "../utils.js";
3
+ // Phrases observed in upstream 401 response bodies when OpenAI/Microsoft has
4
+ // explicitly revoked an OAuth token (as opposed to a generic expired-token 401
5
+ // that can be retried after a refresh). Matching is case-insensitive substring.
6
+ // If anti-abuse detection triggers different wording in production, add the new
7
+ // phrase here and record the source provider and date. See issue #495.
8
+ const TOKEN_INVALIDATION_PHRASES = [
9
+ "invalidated oauth token",
10
+ "authentication token has been invalidated",
11
+ "oauth token has been invalidated",
12
+ "token has been invalidated",
13
+ ];
14
+ export function isTokenInvalidationError(bodyText) {
15
+ const lower = bodyText.toLowerCase();
16
+ return TOKEN_INVALIDATION_PHRASES.some((phrase) => lower.includes(phrase));
17
+ }
18
+ export function isTokenRefreshRetryable(result) {
19
+ if (result.reason === "network_error" || result.reason === "unknown")
20
+ return true;
21
+ if (result.reason === "invalid_response")
22
+ return true;
23
+ if (result.reason === "http_error") {
24
+ return !(result.statusCode === HTTP_STATUS.BAD_REQUEST ||
25
+ result.statusCode === HTTP_STATUS.UNAUTHORIZED ||
26
+ result.statusCode === HTTP_STATUS.FORBIDDEN);
27
+ }
28
+ return false;
29
+ }
30
+ export function parseRetryAfterHeaderMs(headers, now) {
31
+ const retryAfterMs = headers.get("retry-after-ms");
32
+ if (retryAfterMs) {
33
+ const parsed = Number.parseInt(retryAfterMs, 10);
34
+ if (Number.isFinite(parsed) && parsed > 0)
35
+ return parsed;
36
+ }
37
+ const retryAfter = headers.get("retry-after");
38
+ if (!retryAfter)
39
+ return null;
40
+ const asSeconds = Number.parseInt(retryAfter, 10);
41
+ if (Number.isFinite(asSeconds) && asSeconds > 0)
42
+ return asSeconds * 1000;
43
+ const asDate = Date.parse(retryAfter);
44
+ if (Number.isFinite(asDate) && asDate > now)
45
+ return asDate - now;
46
+ return null;
47
+ }
48
+ export function parseRetryAfterBodyMs(bodyText, now) {
49
+ if (!bodyText.trim())
50
+ return null;
51
+ try {
52
+ const parsed = JSON.parse(bodyText);
53
+ if (!isRecord(parsed) || !isRecord(parsed.error))
54
+ return null;
55
+ const retryAfterMs = Number(parsed.error.retry_after_ms);
56
+ if (Number.isFinite(retryAfterMs) && retryAfterMs > 0)
57
+ return retryAfterMs;
58
+ const retryAfterSeconds = Number(parsed.error.retry_after);
59
+ if (Number.isFinite(retryAfterSeconds) && retryAfterSeconds > 0) {
60
+ return retryAfterSeconds * 1000;
61
+ }
62
+ const resetAtRaw = Number(parsed.error.resets_at ?? parsed.error.reset_at);
63
+ if (Number.isFinite(resetAtRaw) && resetAtRaw > 0) {
64
+ const resetAtMs = resetAtRaw < 10_000_000_000 ? resetAtRaw * 1000 : resetAtRaw;
65
+ if (resetAtMs > now)
66
+ return resetAtMs - now;
67
+ }
68
+ }
69
+ catch {
70
+ return null;
71
+ }
72
+ return null;
73
+ }
74
+ const TOKEN_INVALIDATED_CODE = "token_invalidated";
75
+ const TOKEN_INVALIDATED_FALLBACK_MESSAGE = "OAuth token has been invalidated. Please re-login.";
76
+ // Both invalidation exit paths (refresh-failure and upstream-401) must hand the
77
+ // client the same machine-readable shape — { error: { message, code:
78
+ // "token_invalidated" } } — so a consumer keying off error.code behaves
79
+ // identically regardless of which vector fired. The upstream forwards a raw body
80
+ // with no guaranteed code, so we wrap it here while preserving its human-readable
81
+ // message when one is present.
82
+ export function buildTokenInvalidationBody(upstreamBodyText) {
83
+ let message = TOKEN_INVALIDATED_FALLBACK_MESSAGE;
84
+ const trimmed = upstreamBodyText.trim();
85
+ if (trimmed) {
86
+ try {
87
+ const parsed = JSON.parse(trimmed);
88
+ if (isRecord(parsed)) {
89
+ const direct = parsed.message;
90
+ if (typeof direct === "string" && direct.trim()) {
91
+ message = direct.trim();
92
+ }
93
+ else if (isRecord(parsed.error)) {
94
+ const nested = parsed.error.message;
95
+ if (typeof nested === "string" && nested.trim()) {
96
+ message = nested.trim();
97
+ }
98
+ }
99
+ }
100
+ }
101
+ catch {
102
+ // Non-JSON upstream body (e.g. HTML error page): keep the stable fallback
103
+ // message rather than echoing markup back to the client.
104
+ }
105
+ }
106
+ return JSON.stringify({ error: { message, code: TOKEN_INVALIDATED_CODE } });
107
+ }
108
+ export function extractErrorCodeFromBody(bodyText) {
109
+ if (!bodyText.trim())
110
+ return null;
111
+ try {
112
+ const parsed = JSON.parse(bodyText);
113
+ if (!isRecord(parsed))
114
+ return null;
115
+ const directCode = parsed.code;
116
+ if (typeof directCode === "string" && directCode.trim()) {
117
+ return directCode.trim();
118
+ }
119
+ const maybeError = parsed.error;
120
+ if (!isRecord(maybeError))
121
+ return null;
122
+ const nestedCode = maybeError.code;
123
+ return typeof nestedCode === "string" && nestedCode.trim()
124
+ ? nestedCode.trim()
125
+ : null;
126
+ }
127
+ catch {
128
+ return null;
129
+ }
130
+ }
131
+ function getQuotaWindowWaitMs(headers, prefix, now) {
132
+ const resetAfterSeconds = Number.parseInt(headers.get(`${prefix}-reset-after-seconds`) ?? "", 10);
133
+ if (Number.isFinite(resetAfterSeconds) && resetAfterSeconds > 0) {
134
+ return resetAfterSeconds * 1000;
135
+ }
136
+ const resetAtRaw = headers.get(`${prefix}-reset-at`);
137
+ if (!resetAtRaw)
138
+ return 0;
139
+ const trimmed = resetAtRaw.trim();
140
+ let resetAtMs = 0;
141
+ if (/^\d+$/.test(trimmed)) {
142
+ const parsed = Number.parseInt(trimmed, 10);
143
+ if (Number.isFinite(parsed) && parsed > 0) {
144
+ resetAtMs = parsed < 10_000_000_000 ? parsed * 1000 : parsed;
145
+ }
146
+ }
147
+ else {
148
+ const parsedDate = Date.parse(trimmed);
149
+ if (Number.isFinite(parsedDate))
150
+ resetAtMs = parsedDate;
151
+ }
152
+ return resetAtMs > now ? resetAtMs - now : 0;
153
+ }
154
+ export function getQuotaNearExhaustionWaitMs(headers, remainingThreshold, now) {
155
+ const usedThreshold = 100 - Math.max(0, Math.min(100, remainingThreshold));
156
+ const candidates = [];
157
+ for (const prefix of ["x-codex-primary", "x-codex-secondary"]) {
158
+ const used = Number(headers.get(`${prefix}-used-percent`) ?? "");
159
+ if (!Number.isFinite(used) || used < usedThreshold)
160
+ continue;
161
+ const waitMs = getQuotaWindowWaitMs(headers, prefix, now);
162
+ if (waitMs > 0)
163
+ candidates.push(waitMs);
164
+ }
165
+ return candidates.length > 0 ? Math.max(...candidates) : 0;
166
+ }
167
+ export function normalizeExhaustionStatus(reason) {
168
+ return reason === "rate-limit" ? HTTP_STATUS.TOO_MANY_REQUESTS : 503;
169
+ }
170
+ export function buildPinnedUnavailableErrorBody(pinnedIndex, accountSkipReasons) {
171
+ const normalizedPinnedIndex = typeof pinnedIndex === "number" ? pinnedIndex : null;
172
+ const skipReason = normalizedPinnedIndex !== null
173
+ ? accountSkipReasons.get(normalizedPinnedIndex) ?? null
174
+ : null;
175
+ const reasonSuffix = skipReason ? ` (${skipReason})` : "";
176
+ // On the desync path the pin index is unknown (null); claiming "account 1"
177
+ // there would contradict the machine-readable pinnedAccountIndex: null.
178
+ const accountPhrase = normalizedPinnedIndex === null
179
+ ? "The pinned account"
180
+ : `Pinned account ${normalizedPinnedIndex + 1}`;
181
+ return {
182
+ message: `${accountPhrase} is currently unavailable${reasonSuffix}; run \`codex-multi-auth status\` for details, or \`codex-multi-auth unpin\` to allow rotation.`,
183
+ code: "codex_pinned_account_unavailable",
184
+ pinnedAccountIndex: normalizedPinnedIndex,
185
+ reason: skipReason,
186
+ account_skip_reasons: Object.fromEntries([...accountSkipReasons.entries()].map(([index, reason]) => [
187
+ String(index),
188
+ reason,
189
+ ])),
190
+ };
191
+ }
@@ -46,4 +46,3 @@ export function buildStreamFailoverCandidateOrder(primaryIndex, accountIndices)
46
46
  }
47
47
  return order;
48
48
  }
49
- //# sourceMappingURL=request-attempt-budget.js.map
@@ -47,4 +47,3 @@ export async function parseRequestBodyFromInit(body, logWarn) {
47
47
  }
48
48
  return {};
49
49
  }
50
- //# sourceMappingURL=request-init.js.map
@@ -77,4 +77,3 @@ export function resetRequestResilienceStateForTests() {
77
77
  clearPoolExhaustionCooldown();
78
78
  clearServerBurstCooldown();
79
79
  }
80
- //# sourceMappingURL=request-resilience.js.map
@@ -852,4 +852,3 @@ export async function transformRequestBody(bodyOrParams, codexInstructions, user
852
852
  body.max_completion_tokens = undefined;
853
853
  return body;
854
854
  }
855
- //# sourceMappingURL=request-transformer.js.map
@@ -121,4 +121,3 @@ export async function applyResponseCompaction(params) {
121
121
  cleanup();
122
122
  }
123
123
  }
124
- //# sourceMappingURL=response-compaction.js.map
@@ -765,4 +765,3 @@ export function attachResponseIdCapture(response, headers, onResponseId) {
765
765
  headers,
766
766
  });
767
767
  }
768
- //# sourceMappingURL=response-handler.js.map
@@ -58,4 +58,3 @@ export function sanitizeResponseHeadersForLog(headers) {
58
58
  }
59
59
  return sanitized;
60
60
  }
61
- //# sourceMappingURL=response-metadata.js.map
@@ -0,0 +1,8 @@
1
+ import type { ServerResponse } from "node:http";
2
+ import type { RuntimeRotationProxyStatus } from "../runtime/rotation-server-types.js";
3
+ export declare const HOP_BY_HOP_HEADERS: Set<string>;
4
+ export declare function responseHeadersForClient(upstreamHeaders: Headers): Record<string, string>;
5
+ export declare function withTimeout<T>(promise: Promise<T>, timeoutMs: number, onTimeout: () => void, message: string): Promise<T>;
6
+ export declare function readErrorBody(response: Response, timeoutMs: number, maxBytes?: number): Promise<string>;
7
+ export declare function forwardStreamingResponse(upstream: Response, res: ServerResponse, status: RuntimeRotationProxyStatus, onStreamError: () => void, streamStallTimeoutMs: number): Promise<boolean>;
8
+ //# sourceMappingURL=stream-failover-runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream-failover-runtime.d.ts","sourceRoot":"","sources":["../../../lib/request/stream-failover-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,qCAAqC,CAAC;AAEtF,eAAO,MAAM,kBAAkB,aAW7B,CAAC;AAWH,wBAAgB,wBAAwB,CAAC,eAAe,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAUzF;AAED,wBAAsB,WAAW,CAAC,CAAC,EAClC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EACnB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,IAAI,EACrB,OAAO,EAAE,MAAM,GACb,OAAO,CAAC,CAAC,CAAC,CAmBZ;AAED,wBAAsB,aAAa,CAClC,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,MAAM,EACjB,QAAQ,SAAc,GACpB,OAAO,CAAC,MAAM,CAAC,CAuDjB;AAED,wBAAsB,wBAAwB,CAC7C,QAAQ,EAAE,QAAQ,EAClB,GAAG,EAAE,cAAc,EACnB,MAAM,EAAE,0BAA0B,EAClC,aAAa,EAAE,MAAM,IAAI,EACzB,oBAAoB,EAAE,MAAM,GAC1B,OAAO,CAAC,OAAO,CAAC,CA0ClB"}
@@ -0,0 +1,149 @@
1
+ export const HOP_BY_HOP_HEADERS = new Set([
2
+ "connection",
3
+ "content-length",
4
+ "expect",
5
+ "keep-alive",
6
+ "proxy-authenticate",
7
+ "proxy-authorization",
8
+ "te",
9
+ "trailer",
10
+ "transfer-encoding",
11
+ "upgrade",
12
+ ]);
13
+ // Any header under this prefix carries account-identifying rotation metadata
14
+ // (index/label/email/id today) and must never reach the client; matching by
15
+ // prefix means a future header added under it is blocked by default instead
16
+ // of leaking until someone remembers to extend an allowlist.
17
+ const PRIVATE_CLIENT_RESPONSE_HEADER_PREFIX = "x-codex-multi-auth-account-";
18
+ const DECODED_UPSTREAM_RESPONSE_HEADERS = new Set([
19
+ // Node fetch returns decoded bytes while preserving the upstream encoding header.
20
+ "content-encoding",
21
+ ]);
22
+ export function responseHeadersForClient(upstreamHeaders) {
23
+ const headers = {};
24
+ for (const [key, value] of upstreamHeaders.entries()) {
25
+ const normalizedKey = key.toLowerCase();
26
+ if (HOP_BY_HOP_HEADERS.has(normalizedKey))
27
+ continue;
28
+ if (normalizedKey.startsWith(PRIVATE_CLIENT_RESPONSE_HEADER_PREFIX))
29
+ continue;
30
+ if (DECODED_UPSTREAM_RESPONSE_HEADERS.has(normalizedKey))
31
+ continue;
32
+ headers[key] = value;
33
+ }
34
+ return headers;
35
+ }
36
+ export async function withTimeout(promise, timeoutMs, onTimeout, message) {
37
+ let timeout;
38
+ try {
39
+ return await Promise.race([
40
+ promise,
41
+ new Promise((_resolve, reject) => {
42
+ timeout = setTimeout(() => {
43
+ // Reject BEFORE onTimeout: onTimeout side effects (e.g. cancelling a
44
+ // stream reader) can settle `promise` with a clean value, and a
45
+ // settlement enqueued ahead of this rejection would win the race —
46
+ // turning a stall into a silent success.
47
+ reject(new Error(message));
48
+ onTimeout();
49
+ }, Math.max(1, timeoutMs));
50
+ }),
51
+ ]);
52
+ }
53
+ finally {
54
+ if (timeout)
55
+ clearTimeout(timeout);
56
+ }
57
+ }
58
+ export async function readErrorBody(response, timeoutMs, maxBytes = 1024 * 1024) {
59
+ // The outbound fetch's abort timer is cleared once headers arrive, so a
60
+ // stalled error body would otherwise hang this handler forever (the success
61
+ // path is per-chunk stall-bounded; the error path was not). Read the body via
62
+ // a reader, bound it by an idle timeout AND a size cap, and cancel the stream
63
+ // on timeout/overflow so the socket is released.
64
+ const body = response.body;
65
+ if (!body || typeof body.getReader !== "function") {
66
+ // Fallback for impls without a streamable body: race text() against a timer.
67
+ try {
68
+ return await withTimeout(response.text(), timeoutMs, () => undefined, "error body stalled");
69
+ }
70
+ catch {
71
+ return "";
72
+ }
73
+ }
74
+ const reader = body.getReader();
75
+ const chunks = [];
76
+ let total = 0;
77
+ try {
78
+ for (;;) {
79
+ let idleTimer;
80
+ const idle = new Promise((_resolve, reject) => {
81
+ idleTimer = setTimeout(() => reject(new Error("error body stalled")), Math.max(1, timeoutMs));
82
+ });
83
+ let result;
84
+ try {
85
+ result = await Promise.race([reader.read(), idle]);
86
+ }
87
+ finally {
88
+ if (idleTimer)
89
+ clearTimeout(idleTimer);
90
+ }
91
+ if (result.done)
92
+ break;
93
+ if (result.value) {
94
+ total += result.value.byteLength;
95
+ if (total > maxBytes)
96
+ break; // cap: enough for diagnostics, no OOM
97
+ chunks.push(result.value);
98
+ }
99
+ }
100
+ }
101
+ catch {
102
+ // stalled or errored — fall through with whatever we have
103
+ }
104
+ finally {
105
+ await reader.cancel().catch(() => undefined);
106
+ }
107
+ try {
108
+ return Buffer.concat(chunks).toString("utf8");
109
+ }
110
+ catch {
111
+ return "";
112
+ }
113
+ }
114
+ export async function forwardStreamingResponse(upstream, res, status, onStreamError, streamStallTimeoutMs) {
115
+ status.streamsStarted += 1;
116
+ res.writeHead(upstream.status, responseHeadersForClient(upstream.headers));
117
+ if (!upstream.body) {
118
+ res.end();
119
+ return true;
120
+ }
121
+ const reader = upstream.body.getReader();
122
+ res.on("close", () => {
123
+ if (!res.writableEnded) {
124
+ void reader.cancel().catch(() => undefined);
125
+ }
126
+ });
127
+ try {
128
+ while (true) {
129
+ const { done, value } = await withTimeout(reader.read(), streamStallTimeoutMs, () => {
130
+ void reader.cancel().catch(() => undefined);
131
+ }, `upstream stream stalled after ${streamStallTimeoutMs}ms`);
132
+ if (done)
133
+ break;
134
+ if (value && value.byteLength > 0) {
135
+ res.write(Buffer.from(value));
136
+ }
137
+ }
138
+ res.end();
139
+ return true;
140
+ }
141
+ catch (error) {
142
+ status.lastError = error instanceof Error ? error.message : String(error);
143
+ onStreamError();
144
+ if (!res.destroyed) {
145
+ res.destroy(error instanceof Error ? error : undefined);
146
+ }
147
+ return false;
148
+ }
149
+ }
@@ -219,4 +219,3 @@ export function withStreamingFailover(initialResponse, getFallbackResponse, opti
219
219
  headers,
220
220
  });
221
221
  }
222
- //# sourceMappingURL=stream-failover.js.map
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Token refresh helpers for the custom fetch implementation
3
+ * Extracted from fetch-helpers.ts (audit roadmap §4.1.2); fetch-helpers.ts
4
+ * re-exports the public symbols so existing importers are unchanged.
5
+ */
6
+ import type { Auth, CodexClient } from "@codex-ai/sdk";
7
+ /**
8
+ * Determines if the current auth token needs to be refreshed
9
+ * @param auth - Current authentication state
10
+ * @returns True if token is expired or invalid
11
+ */
12
+ export declare function shouldRefreshToken(auth: Auth, skewMs?: number): boolean;
13
+ /**
14
+ * Refreshes the OAuth token and updates stored credentials
15
+ *
16
+ * Mutation contract: on success the passed `currentAuth` object is updated
17
+ * IN PLACE (access/refresh/expires) after the persistence await, and the same
18
+ * reference is returned. Same-account refreshes are serialized by
19
+ * `queuedRefresh`, so two concurrent calls for one account coalesce rather
20
+ * than race; callers must still not share one Auth object across calls for
21
+ * DIFFERENT accounts, and must not read token fields from a shared reference
22
+ * while a refresh for it is in flight (the window between the persistence
23
+ * await and the mutation block exposes the pre-refresh values).
24
+ *
25
+ * @param currentAuth - Current auth state
26
+ * @param client - Codex client for updating stored credentials
27
+ * @returns Updated auth (throws on failure)
28
+ */
29
+ export declare function refreshAndUpdateToken(currentAuth: Auth, client: CodexClient): Promise<Auth>;
30
+ //# sourceMappingURL=token-refresh.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"token-refresh.d.ts","sourceRoot":"","sources":["../../../lib/request/token-refresh.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAqBvD;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,SAAI,GAAG,OAAO,CAMlE;AAoDD;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,qBAAqB,CAC1C,WAAW,EAAE,IAAI,EACjB,MAAM,EAAE,WAAW,GACjB,OAAO,CAAC,IAAI,CAAC,CA+Cf"}