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
@@ -2,556 +2,21 @@
2
2
  * Helper functions for the custom fetch implementation
3
3
  * These functions break down the complex fetch logic into manageable, testable units
4
4
  */
5
- import { ProxyAgent } from "undici";
6
- import { queuedRefresh } from "../refresh-queue.js";
7
5
  import { logRequest, logError, logWarn } from "../logger.js";
8
6
  import { getCodexInstructions, getModelFamily } from "../prompts/codex.js";
9
7
  import { transformRequestBody, normalizeModel, resolveFastSessionInputTrimPlan, } from "./request-transformer.js";
10
8
  import { attachResponseIdCapture, convertSseToJson, ensureContentType, } from "./response-handler.js";
11
- import { registerCleanup } from "../shutdown.js";
12
- import { CodexAuthError } from "../errors.js";
13
9
  import { isRecord } from "../utils.js";
14
- import { CODEX_BASE_URL, HTTP_STATUS, OPENAI_HEADERS, OPENAI_HEADER_VALUES, URL_PATHS, ERROR_MESSAGES, LOG_STAGES, } from "../constants.js";
15
- const CODEX_BASE_URL_OBJECT = new URL(CODEX_BASE_URL);
16
- const CODEX_BASE_PATH_PREFIX = CODEX_BASE_URL_OBJECT.pathname.endsWith("/")
17
- ? CODEX_BASE_URL_OBJECT.pathname.slice(0, -1)
18
- : CODEX_BASE_URL_OBJECT.pathname;
19
- const CHATGPT_CODEX_UNSUPPORTED_MODEL_CODE = "model_not_supported_with_chatgpt_account";
20
- const CHATGPT_CODEX_UNSUPPORTED_MODEL_PATTERN = /model is not supported when using codex with a chatgpt account/i;
21
- const NORMALIZED_UNSUPPORTED_MODEL_PATTERN = /the model ['"]([^'"]+)['"] is not currently available for this chatgpt account/i;
22
- const MODEL_ACCESS_DENIED_PATTERN = /the model [`'"]([^`'"]+)[`'"] does not exist or you do not have access to it/i;
10
+ import { HTTP_STATUS, ERROR_MESSAGES, LOG_STAGES, } from "../constants.js";
11
+ import { CHATGPT_CODEX_UNSUPPORTED_MODEL_CODE, createEntitlementErrorResponse, extractUnsupportedCodexModelFromText, isEntitlementError, isUnsupportedCodexModelForChatGpt, } from "./error-classification.js";
12
+ import { logDeprecationHeaders } from "./headers.js";
13
+ export { shouldRefreshToken, refreshAndUpdateToken } from "./token-refresh.js";
14
+ export { DEFAULT_UNSUPPORTED_CODEX_FALLBACK_CHAIN, extractUnsupportedCodexModelFromText, getUnsupportedCodexModelInfo, resolveUnsupportedCodexFallbackModel, shouldFallbackToGpt52OnUnsupportedGpt53, isEntitlementError, isWorkspaceDisabledError, createEntitlementErrorResponse, } from "./error-classification.js";
15
+ export { extractRequestUrl, rewriteUrlForCodex, resolveProxyUrlForRequest, closeSharedProxyDispatchers, applyProxyCompatibleInit, } from "./url-rewriting.js";
16
+ export { createCodexHeaders } from "./headers.js";
23
17
  const MAX_RATE_LIMIT_DELAY_MS = 7 * 24 * 60 * 60 * 1000;
24
18
  const RETRY_AFTER_DURATION_PATTERN = /\b(?:try|retry)\s+again\s+in\s+(\d+)\s*(second|minute|hour|day)s?\b/i;
25
19
  const RETRY_AFTER_CLOCK_TIME_PATTERN = /\b(?:try|retry)\s+again\s+at\s+(\d{1,2})(?::(\d{2}))?\s*(am|pm)\b/i;
26
- const CREATE_CODEX_HEADERS_PARAM_KEYS = new Set(["init", "accountId", "accessToken", "opts"]);
27
- const DEFAULT_PROXY_PORTS = {
28
- "http:": 80,
29
- "https:": 443,
30
- };
31
- const sharedProxyDispatchers = new Map();
32
- export const DEFAULT_UNSUPPORTED_CODEX_FALLBACK_CHAIN = {
33
- "gpt-5": ["gpt-5.5"],
34
- "gpt-5-pro": ["gpt-5.5-pro"],
35
- "gpt-5-chat-latest": ["gpt-5.5"],
36
- "gpt-5.5": ["gpt-5.4"],
37
- "gpt-5.5-pro": ["gpt-5.4"],
38
- "gpt-5.5-2026-04-23": ["gpt-5.4"],
39
- "gpt-5.5-pro-2026-04-23": ["gpt-5.4"],
40
- "gpt-5.5-20260423": ["gpt-5.4"],
41
- "gpt-5.5-pro-20260423": ["gpt-5.4"],
42
- "gpt-5.3-codex-spark": ["gpt-5.3-codex", "gpt-5.2-codex"],
43
- "gpt-5.3-codex": ["gpt-5.2-codex"],
44
- "codex-max": ["gpt-5.3-codex"],
45
- "gpt-5.1-codex-max": ["gpt-5.3-codex"],
46
- "codex-mini-latest": ["gpt-5.3-codex"],
47
- "gpt-5-codex-mini": ["gpt-5.3-codex"],
48
- "gpt-5.1-codex-mini": ["gpt-5.3-codex"],
49
- "gpt-5-codex": ["gpt-5.3-codex", "gpt-5.2-codex"],
50
- "gpt-5.2-codex": ["gpt-5.3-codex"],
51
- "gpt-5.1-codex": ["gpt-5.3-codex"],
52
- };
53
- function canonicalizeModelName(model) {
54
- if (!model)
55
- return undefined;
56
- const trimmed = model.trim().toLowerCase();
57
- if (!trimmed)
58
- return undefined;
59
- const stripped = trimmed.includes("/")
60
- ? (trimmed.split("/").pop() ?? trimmed)
61
- : trimmed;
62
- return stripped.replace(/-(none|minimal|low|medium|high|xhigh)$/i, "");
63
- }
64
- function normalizeFallbackChain(customChain) {
65
- const normalized = {};
66
- for (const [key, values] of Object.entries(DEFAULT_UNSUPPORTED_CODEX_FALLBACK_CHAIN)) {
67
- const normalizedKey = canonicalizeModelName(key);
68
- if (!normalizedKey)
69
- continue;
70
- normalized[normalizedKey] = values
71
- .map((value) => canonicalizeModelName(value))
72
- .filter((value) => !!value);
73
- }
74
- if (!customChain) {
75
- return normalized;
76
- }
77
- for (const [key, values] of Object.entries(customChain)) {
78
- const normalizedKey = canonicalizeModelName(key);
79
- if (!normalizedKey || !Array.isArray(values))
80
- continue;
81
- const normalizedValues = values
82
- .map((value) => canonicalizeModelName(value))
83
- .filter((value) => !!value);
84
- if (normalizedValues.length > 0) {
85
- normalized[normalizedKey] = normalizedValues;
86
- }
87
- }
88
- return normalized;
89
- }
90
- export function extractUnsupportedCodexModelFromText(bodyText) {
91
- const directMatch = bodyText.match(/['"]([^'"]+)['"]\s+model is not supported when using codex with a chatgpt account/i);
92
- if (directMatch?.[1]) {
93
- return canonicalizeModelName(directMatch[1]);
94
- }
95
- const normalizedMatch = bodyText.match(NORMALIZED_UNSUPPORTED_MODEL_PATTERN);
96
- if (normalizedMatch?.[1]) {
97
- return canonicalizeModelName(normalizedMatch[1]);
98
- }
99
- const accessDeniedMatch = bodyText.match(MODEL_ACCESS_DENIED_PATTERN);
100
- if (accessDeniedMatch?.[1]) {
101
- return canonicalizeModelName(accessDeniedMatch[1]);
102
- }
103
- return undefined;
104
- }
105
- function isUnsupportedCodexModelForChatGpt(status, bodyText) {
106
- if (status !== HTTP_STATUS.BAD_REQUEST)
107
- return false;
108
- if (!bodyText)
109
- return false;
110
- return (CHATGPT_CODEX_UNSUPPORTED_MODEL_PATTERN.test(bodyText) ||
111
- NORMALIZED_UNSUPPORTED_MODEL_PATTERN.test(bodyText) ||
112
- MODEL_ACCESS_DENIED_PATTERN.test(bodyText));
113
- }
114
- export function getUnsupportedCodexModelInfo(errorBody) {
115
- if (!isRecord(errorBody)) {
116
- return { isUnsupported: false };
117
- }
118
- const maybeError = errorBody.error;
119
- if (!isRecord(maybeError)) {
120
- // Some upstreams (e.g. the Codex quota endpoint) return the flat
121
- // `{ "detail": "...model is not supported..." }` shape instead of the
122
- // nested `{ "error": { "message": "..." } }` envelope. Fall back to the
123
- // top-level `detail` string so model-fallback detection still works.
124
- const detail = typeof errorBody.detail === "string" ? errorBody.detail : undefined;
125
- if (!detail) {
126
- return { isUnsupported: false };
127
- }
128
- const isUnsupportedDetail = CHATGPT_CODEX_UNSUPPORTED_MODEL_PATTERN.test(detail) ||
129
- NORMALIZED_UNSUPPORTED_MODEL_PATTERN.test(detail) ||
130
- MODEL_ACCESS_DENIED_PATTERN.test(detail);
131
- if (!isUnsupportedDetail) {
132
- return { isUnsupported: false };
133
- }
134
- return {
135
- isUnsupported: true,
136
- message: detail,
137
- unsupportedModel: extractUnsupportedCodexModelFromText(detail) ?? undefined,
138
- };
139
- }
140
- const code = typeof maybeError.code === "string" ? maybeError.code : undefined;
141
- const message = typeof maybeError.message === "string" ? maybeError.message : undefined;
142
- const unsupportedModelFromPayload = typeof maybeError.unsupported_model === "string"
143
- ? maybeError.unsupported_model
144
- : undefined;
145
- const unsupportedModel = unsupportedModelFromPayload
146
- ? canonicalizeModelName(unsupportedModelFromPayload)
147
- : extractUnsupportedCodexModelFromText(message ?? "");
148
- const isUnsupported = code === CHATGPT_CODEX_UNSUPPORTED_MODEL_CODE ||
149
- (message
150
- ? CHATGPT_CODEX_UNSUPPORTED_MODEL_PATTERN.test(message) ||
151
- NORMALIZED_UNSUPPORTED_MODEL_PATTERN.test(message) ||
152
- MODEL_ACCESS_DENIED_PATTERN.test(message)
153
- : false);
154
- return {
155
- isUnsupported,
156
- code,
157
- message,
158
- unsupportedModel: unsupportedModel ?? undefined,
159
- };
160
- }
161
- export function resolveUnsupportedCodexFallbackModel(options) {
162
- if (!options.fallbackOnUnsupportedCodexModel)
163
- return undefined;
164
- const unsupported = getUnsupportedCodexModelInfo(options.errorBody);
165
- if (!unsupported.isUnsupported)
166
- return undefined;
167
- const requestedModel = canonicalizeModelName(options.requestedModel);
168
- const currentModel = requestedModel ?? unsupported.unsupportedModel;
169
- if (!currentModel)
170
- return undefined;
171
- const attempted = new Set();
172
- for (const model of options.attemptedModels ?? []) {
173
- const normalized = canonicalizeModelName(model);
174
- if (normalized)
175
- attempted.add(normalized);
176
- }
177
- const chain = normalizeFallbackChain(options.customChain);
178
- const targets = chain[currentModel] ?? [];
179
- if (targets.length === 0)
180
- return undefined;
181
- for (const target of targets) {
182
- if (!options.fallbackToGpt52OnUnsupportedGpt53 &&
183
- currentModel === "gpt-5.3-codex" &&
184
- target === "gpt-5.2-codex") {
185
- continue;
186
- }
187
- if (target === currentModel)
188
- continue;
189
- if (attempted.has(target))
190
- continue;
191
- return target;
192
- }
193
- return undefined;
194
- }
195
- /**
196
- * Returns true when the legacy `gpt-5.3-codex -> gpt-5.2-codex` edge is available.
197
- */
198
- export function shouldFallbackToGpt52OnUnsupportedGpt53(requestedModel, errorBody) {
199
- if (canonicalizeModelName(requestedModel) !== "gpt-5.3-codex") {
200
- return false;
201
- }
202
- return (resolveUnsupportedCodexFallbackModel({
203
- requestedModel,
204
- errorBody,
205
- // Probe whether the legacy gpt-5.2 edge is still active under current
206
- // policy/toggles when the current Codex model is blocked.
207
- attemptedModels: [],
208
- fallbackOnUnsupportedCodexModel: true,
209
- fallbackToGpt52OnUnsupportedGpt53: true,
210
- }) === "gpt-5.2-codex");
211
- }
212
- /**
213
- * Detects whether an error code or response body indicates an entitlement/subscription issue for Codex models.
214
- *
215
- * Entitlement errors signal that the requested feature is not included in the user's plan and should not be treated as rate limits.
216
- * This function is pure and safe to call concurrently; it performs no filesystem access (including on Windows) and does not read or redact tokens — callers must avoid passing sensitive credentials in `code` or `bodyText`.
217
- *
218
- * @param code - The error code string returned by the service
219
- * @param bodyText - The response body text to inspect for entitlement-related phrases
220
- * @returns `true` if the combined `code` or `bodyText` indicates an entitlement/subscription issue, `false` otherwise
221
- */
222
- export function isEntitlementError(code, bodyText) {
223
- const haystack = `${code} ${bodyText}`.toLowerCase();
224
- // "usage_not_included" means the subscription doesn't include this feature
225
- // This is different from "usage_limit_reached" which is a temporary quota limit
226
- return /usage_not_included|not.included.in.your.plan|subscription.does.not.include/i.test(haystack);
227
- }
228
- /**
229
- * Detects whether an error indicates the workspace/account has been disabled or expired.
230
- *
231
- * Workspace disabled errors signal that the current workspace is no longer accessible
232
- * (expired, disabled, or removed) and the plugin should automatically switch to another account.
233
- *
234
- * @param status - HTTP status code
235
- * @param code - The error code string returned by the service
236
- * @param bodyText - The response body text to inspect for workspace-related phrases
237
- * @returns `true` if the error indicates a disabled/expired workspace
238
- */
239
- export function isWorkspaceDisabledError(status, code, bodyText) {
240
- const normalizedCode = typeof code === "string" ? code.trim().toLowerCase() : "";
241
- if (status === 402) {
242
- const normalizedTokens = normalizedCode
243
- .split(/[^a-z0-9_]+/i)
244
- .map((token) => token.trim())
245
- .filter((token) => token.length > 0);
246
- return (normalizedTokens.includes("deactivated_workspace") ||
247
- /\bdeactivated_workspace\b/i.test(bodyText));
248
- }
249
- if (status !== 403) {
250
- return false;
251
- }
252
- const haystack = `${normalizedCode} ${bodyText}`.toLowerCase();
253
- const normalizedTokens = normalizedCode
254
- .split(/[^a-z0-9_]+/i)
255
- .map((token) => token.trim())
256
- .filter((token) => token.length > 0);
257
- const disabledPatterns = [
258
- /workspace.*(?:disabled|expired|deactivated|terminated)/i,
259
- /account\s+(?:has\s+been|is)\s+(?:disabled|expired|deactivated|terminated|closed)/i,
260
- /(?:workspace|org(?:anization)?).*no longer.*(?:active|available|valid)/i,
261
- /(?:workspace|org(?:anization)?).*has been.*(?:disabled|expired|closed)/i,
262
- /workspace.*(?:access|subscription).*expired/i,
263
- /org(?:anization)?.*(?:disabled|expired|inactive)/i,
264
- ];
265
- for (const pattern of disabledPatterns) {
266
- if (pattern.test(haystack)) {
267
- return true;
268
- }
269
- }
270
- const workspaceErrorCodes = new Set([
271
- "workspace_disabled",
272
- "workspace_expired",
273
- "workspace_terminated",
274
- "account_disabled",
275
- "account_expired",
276
- "organization_disabled",
277
- ]);
278
- if (workspaceErrorCodes.has(normalizedCode)) {
279
- return true;
280
- }
281
- return normalizedTokens.some((token) => workspaceErrorCodes.has(token));
282
- }
283
- /**
284
- * Constructs a standardized 403 entitlement error Response indicating the user lacks access to Codex models.
285
- *
286
- * This function returns a JSON Response with an `error` payload containing a user-facing message, a
287
- * `type` of `"entitlement_error"`, and a `code` of `"usage_not_included"`. The message suggests checking
288
- * account/workspace access and re-authenticating with `codex-multi-auth login`.
289
- *
290
- * Concurrency: stateless and safe to call concurrently from multiple threads or requests.
291
- * Windows filesystem behavior: none (function does not access the filesystem).
292
- * Token redaction: any tokens are not included in the generated payload; do not pass sensitive tokens in `_bodyText`.
293
- *
294
- * @param _bodyText - Original response body text (accepted for compatibility; ignored when building the response)
295
- * @returns A 403 Response with a JSON body describing the entitlement error and guidance for resolving it
296
- */
297
- export function createEntitlementErrorResponse(_bodyText) {
298
- const message = "This model is not included in your ChatGPT subscription. " +
299
- "Please check that your account or workspace has access to Codex models (Plus/Pro/Business/Enterprise). " +
300
- "If you recently subscribed or switched workspaces, try logging out and back in with `codex-multi-auth login`.";
301
- const payload = {
302
- error: {
303
- message,
304
- type: "entitlement_error",
305
- code: "usage_not_included",
306
- },
307
- };
308
- return new Response(JSON.stringify(payload), {
309
- status: 403, // Forbidden - not a rate limit
310
- statusText: "Forbidden",
311
- headers: { "content-type": "application/json; charset=utf-8" },
312
- });
313
- }
314
- function isCreateCodexHeadersNamedParams(value) {
315
- if (!isRecord(value))
316
- return false;
317
- if (typeof value.accountId !== "string" || typeof value.accessToken !== "string")
318
- return false;
319
- return Object.keys(value).every((key) => CREATE_CODEX_HEADERS_PARAM_KEYS.has(key));
320
- }
321
- /**
322
- * Determines if the current auth token needs to be refreshed
323
- * @param auth - Current authentication state
324
- * @returns True if token is expired or invalid
325
- */
326
- export function shouldRefreshToken(auth, skewMs = 0) {
327
- if (auth.type !== "oauth")
328
- return true;
329
- if (!auth.access)
330
- return true;
331
- const safeSkewMs = Math.max(0, Math.floor(skewMs));
332
- return auth.expires <= Date.now() + safeSkewMs;
333
- }
334
- function isRetryableRefreshFailure(result) {
335
- switch (result.reason) {
336
- case "network_error":
337
- case "unknown":
338
- case "invalid_response":
339
- return true;
340
- case "missing_refresh":
341
- return false;
342
- case "http_error":
343
- return !(result.statusCode === HTTP_STATUS.BAD_REQUEST ||
344
- result.statusCode === HTTP_STATUS.UNAUTHORIZED ||
345
- result.statusCode === HTTP_STATUS.FORBIDDEN);
346
- default:
347
- return false;
348
- }
349
- }
350
- function isRetryableAuthSetterError(error) {
351
- if (!error || typeof error !== "object") {
352
- return false;
353
- }
354
- const candidate = error;
355
- const code = typeof candidate.code === "string"
356
- ? candidate.code.toUpperCase()
357
- : undefined;
358
- if (code === "EAGAIN" || code === "EBUSY" || code === "EPERM") {
359
- return true;
360
- }
361
- if (candidate.status === HTTP_STATUS.TOO_MANY_REQUESTS) {
362
- return true;
363
- }
364
- if (candidate.cause && candidate.cause !== error) {
365
- return isRetryableAuthSetterError(candidate.cause);
366
- }
367
- return false;
368
- }
369
- /**
370
- * Refreshes the OAuth token and updates stored credentials
371
- * @param currentAuth - Current auth state
372
- * @param client - Codex client for updating stored credentials
373
- * @returns Updated auth (throws on failure)
374
- */
375
- export async function refreshAndUpdateToken(currentAuth, client) {
376
- const authSetter = client.auth;
377
- if (!authSetter || typeof authSetter.set !== "function") {
378
- throw new CodexAuthError(ERROR_MESSAGES.TOKEN_REFRESH_FAILED, {
379
- retryable: false,
380
- });
381
- }
382
- const refreshToken = currentAuth.type === "oauth" ? currentAuth.refresh : "";
383
- const refreshResult = await queuedRefresh(refreshToken);
384
- if (refreshResult.type === "failed") {
385
- throw new CodexAuthError(ERROR_MESSAGES.TOKEN_REFRESH_FAILED, {
386
- retryable: isRetryableRefreshFailure(refreshResult),
387
- context: {
388
- refreshFailureReason: refreshResult.reason,
389
- statusCode: refreshResult.statusCode,
390
- },
391
- });
392
- }
393
- try {
394
- await authSetter.set({
395
- path: { id: "openai" },
396
- body: {
397
- type: "oauth",
398
- access: refreshResult.access,
399
- refresh: refreshResult.refresh,
400
- expires: refreshResult.expires,
401
- multiAccount: true,
402
- },
403
- });
404
- }
405
- catch (error) {
406
- throw new CodexAuthError(ERROR_MESSAGES.TOKEN_REFRESH_FAILED, {
407
- retryable: isRetryableAuthSetterError(error),
408
- cause: error,
409
- });
410
- }
411
- // Update current auth reference if it's OAuth type
412
- if (currentAuth.type === "oauth") {
413
- currentAuth.access = refreshResult.access;
414
- currentAuth.refresh = refreshResult.refresh;
415
- currentAuth.expires = refreshResult.expires;
416
- }
417
- return currentAuth;
418
- }
419
- /**
420
- * Extracts URL string from various request input types
421
- * @param input - Request input (string, URL, or Request object)
422
- * @returns URL string
423
- */
424
- export function extractRequestUrl(input) {
425
- if (typeof input === "string")
426
- return input;
427
- if (input instanceof URL)
428
- return input.toString();
429
- return input.url;
430
- }
431
- /**
432
- * Rewrites OpenAI API URLs to Codex backend URLs
433
- * @param url - Original URL
434
- * @returns Rewritten URL for Codex backend
435
- */
436
- export function rewriteUrlForCodex(url) {
437
- const parsedUrl = new URL(url);
438
- const rewrittenPath = parsedUrl.pathname.includes(URL_PATHS.RESPONSES)
439
- ? parsedUrl.pathname.replace(URL_PATHS.RESPONSES, URL_PATHS.CODEX_RESPONSES)
440
- : parsedUrl.pathname;
441
- const normalizedPath = rewrittenPath === CODEX_BASE_PATH_PREFIX ||
442
- rewrittenPath.startsWith(`${CODEX_BASE_PATH_PREFIX}/`)
443
- ? rewrittenPath
444
- : `${CODEX_BASE_PATH_PREFIX}${rewrittenPath.startsWith("/") ? rewrittenPath : `/${rewrittenPath}`}`;
445
- parsedUrl.protocol = CODEX_BASE_URL_OBJECT.protocol;
446
- parsedUrl.username = "";
447
- parsedUrl.password = "";
448
- parsedUrl.host = CODEX_BASE_URL_OBJECT.host;
449
- parsedUrl.pathname = normalizedPath;
450
- return parsedUrl.toString();
451
- }
452
- function hasOwnEnvKey(env, key) {
453
- return Object.prototype.hasOwnProperty.call(env, key);
454
- }
455
- function resolveProxyEnvValue(env, lowerKey, upperKey) {
456
- if (hasOwnEnvKey(env, lowerKey)) {
457
- const value = env[lowerKey]?.trim();
458
- return value ? value : undefined;
459
- }
460
- const value = env[upperKey]?.trim();
461
- return value ? value : undefined;
462
- }
463
- function parseNoProxyEntries(noProxyValue) {
464
- return noProxyValue
465
- .split(/[,\s]/)
466
- .map((entry) => entry.trim())
467
- .filter(Boolean)
468
- .map((entry) => {
469
- const parsed = entry.match(/^(.+):(\d+)$/);
470
- const hostname = parsed?.[1] ?? entry;
471
- const portText = parsed?.[2];
472
- return {
473
- hostname: hostname.toLowerCase(),
474
- port: portText ? Number.parseInt(portText, 10) : 0,
475
- };
476
- });
477
- }
478
- function shouldBypassProxyForUrl(url, noProxyValue) {
479
- if (!noProxyValue)
480
- return false;
481
- if (noProxyValue === "*")
482
- return true;
483
- const hostname = url.host.replace(/:\d*$/, "").toLowerCase();
484
- const port = Number.parseInt(url.port, 10) || DEFAULT_PROXY_PORTS[url.protocol] || 0;
485
- for (const entry of parseNoProxyEntries(noProxyValue)) {
486
- if (entry.hostname === "*")
487
- return true;
488
- if (entry.port && entry.port !== port)
489
- continue;
490
- if (!/^[.*]/.test(entry.hostname)) {
491
- if (hostname === entry.hostname) {
492
- return true;
493
- }
494
- continue;
495
- }
496
- if (hostname.endsWith(entry.hostname.replace(/^\*/, ""))) {
497
- return true;
498
- }
499
- }
500
- return false;
501
- }
502
- export function resolveProxyUrlForRequest(url, env = process.env) {
503
- const parsed = new URL(url);
504
- if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
505
- return undefined;
506
- }
507
- const httpProxy = resolveProxyEnvValue(env, "http_proxy", "HTTP_PROXY");
508
- const httpsProxy = resolveProxyEnvValue(env, "https_proxy", "HTTPS_PROXY");
509
- if (!httpProxy && !httpsProxy) {
510
- return undefined;
511
- }
512
- const noProxy = resolveProxyEnvValue(env, "no_proxy", "NO_PROXY");
513
- if (shouldBypassProxyForUrl(parsed, noProxy)) {
514
- return undefined;
515
- }
516
- return parsed.protocol === "https:"
517
- ? (httpsProxy ?? httpProxy)
518
- : httpProxy;
519
- }
520
- function getSharedProxyDispatcher(proxyUrl) {
521
- const existing = sharedProxyDispatchers.get(proxyUrl);
522
- if (existing) {
523
- return existing;
524
- }
525
- const dispatcher = new ProxyAgent(proxyUrl);
526
- sharedProxyDispatchers.set(proxyUrl, dispatcher);
527
- return dispatcher;
528
- }
529
- export async function closeSharedProxyDispatchers() {
530
- while (sharedProxyDispatchers.size > 0) {
531
- const dispatchers = [...sharedProxyDispatchers.values()];
532
- sharedProxyDispatchers.clear();
533
- await Promise.allSettled(dispatchers.map(async (dispatcher) => {
534
- if (typeof dispatcher.close === "function") {
535
- await dispatcher.close();
536
- }
537
- }));
538
- }
539
- }
540
- registerCleanup(closeSharedProxyDispatchers);
541
- export function applyProxyCompatibleInit(url, init, env = process.env) {
542
- const resolvedInit = init ?? {};
543
- if (resolvedInit.dispatcher || resolvedInit.agent) {
544
- return resolvedInit;
545
- }
546
- const proxyUrl = resolveProxyUrlForRequest(url, env);
547
- if (!proxyUrl) {
548
- return resolvedInit;
549
- }
550
- return {
551
- ...resolvedInit,
552
- dispatcher: getSharedProxyDispatcher(proxyUrl),
553
- };
554
- }
555
20
  /**
556
21
  * Transforms request body and logs the transformation
557
22
  * Fetches model-specific Codex instructions based on the request model
@@ -634,57 +99,11 @@ export async function transformRequestForCodex(init, url, userConfig, codexMode
634
99
  return undefined;
635
100
  }
636
101
  }
637
- export function createCodexHeaders(initOrParams, accountId, accessToken, opts) {
638
- const useNamedParams = typeof accountId === "undefined" &&
639
- typeof accessToken === "undefined" &&
640
- isCreateCodexHeadersNamedParams(initOrParams);
641
- const namedParams = useNamedParams
642
- ? initOrParams
643
- : null;
644
- const resolvedInit = useNamedParams
645
- ? namedParams?.init
646
- : initOrParams;
647
- const resolvedAccountId = useNamedParams ? namedParams?.accountId : accountId;
648
- const resolvedAccessToken = useNamedParams ? namedParams?.accessToken : accessToken;
649
- const resolvedOpts = useNamedParams ? namedParams?.opts : opts;
650
- if (!resolvedAccountId || !resolvedAccessToken) {
651
- throw new TypeError("createCodexHeaders requires accountId and accessToken");
652
- }
653
- const headers = new Headers(resolvedInit?.headers ?? {});
654
- headers.delete("x-api-key"); // Remove any existing API key
655
- headers.set("Authorization", `Bearer ${resolvedAccessToken}`);
656
- headers.set(OPENAI_HEADERS.ACCOUNT_ID, resolvedAccountId);
657
- headers.set(OPENAI_HEADERS.BETA, OPENAI_HEADER_VALUES.BETA_RESPONSES);
658
- headers.set(OPENAI_HEADERS.ORIGINATOR, OPENAI_HEADER_VALUES.ORIGINATOR_CODEX);
659
- const cacheKey = resolvedOpts?.promptCacheKey;
660
- if (cacheKey) {
661
- headers.set(OPENAI_HEADERS.CONVERSATION_ID, cacheKey);
662
- headers.set(OPENAI_HEADERS.SESSION_ID, cacheKey);
663
- }
664
- else {
665
- headers.delete(OPENAI_HEADERS.CONVERSATION_ID);
666
- headers.delete(OPENAI_HEADERS.SESSION_ID);
667
- }
668
- headers.set("accept", "text/event-stream");
669
- return headers;
670
- }
671
102
  /**
672
103
  * Handles error responses from the Codex API
673
104
  * @param response - Error response from API
674
105
  * @returns Original response or mapped retryable response
675
106
  */
676
- /**
677
- * Log RFC 8594 Deprecation/Sunset headers if present. Shared by the success and
678
- * error response handlers so a sunset notice is surfaced regardless of status
679
- * (request-01).
680
- */
681
- function logDeprecationHeaders(response) {
682
- const deprecation = response.headers.get("Deprecation");
683
- const sunset = response.headers.get("Sunset");
684
- if (deprecation || sunset) {
685
- logWarn(`API deprecation notice`, { deprecation, sunset });
686
- }
687
- }
688
107
  export async function handleErrorResponse(response, options) {
689
108
  // request-01: deprecation/sunset headers (RFC 8594) were logged only on the
690
109
  // success path. Upstream often attaches them to error responses too (e.g. a
@@ -1104,4 +523,3 @@ function extractErrorDiagnostics(response, options) {
1104
523
  }
1105
524
  return Object.keys(diagnostics).length > 0 ? diagnostics : undefined;
1106
525
  }
1107
- //# sourceMappingURL=fetch-helpers.js.map
@@ -0,0 +1,33 @@
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
+ export interface CreateCodexHeadersOptions {
7
+ model?: string;
8
+ promptCacheKey?: string;
9
+ }
10
+ export interface CreateCodexHeadersParams {
11
+ init?: RequestInit;
12
+ accountId: string;
13
+ accessToken: string;
14
+ opts?: CreateCodexHeadersOptions;
15
+ }
16
+ /**
17
+ * Creates headers for Codex API requests
18
+ * @param init - Request init options
19
+ * @param accountId - ChatGPT account ID
20
+ * @param accessToken - OAuth access token
21
+ * @returns Headers object with all required Codex headers
22
+ */
23
+ export declare function createCodexHeaders(params: CreateCodexHeadersParams): Headers;
24
+ export declare function createCodexHeaders(init: RequestInit | undefined, accountId: string, accessToken: string, opts?: CreateCodexHeadersOptions): Headers;
25
+ /**
26
+ * Log RFC 8594 Deprecation/Sunset headers if present. Shared by the success and
27
+ * error response handlers so a sunset notice is surfaced regardless of status
28
+ * (request-01).
29
+ *
30
+ * @internal Exported only for sibling lib/request modules; import via fetch-helpers.ts elsewhere.
31
+ */
32
+ export declare function logDeprecationHeaders(response: Response): void;
33
+ //# sourceMappingURL=headers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"headers.d.ts","sourceRoot":"","sources":["../../../lib/request/headers.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAQH,MAAM,WAAW,yBAAyB;IACzC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,wBAAwB;IACxC,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,yBAAyB,CAAC;CACjC;AAQD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CACjC,MAAM,EAAE,wBAAwB,GAC9B,OAAO,CAAC;AACX,wBAAgB,kBAAkB,CAC9B,IAAI,EAAE,WAAW,GAAG,SAAS,EAC7B,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EACnB,IAAI,CAAC,EAAE,yBAAyB,GACjC,OAAO,CAAC;AA0CX;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAM9D"}