oc-codex-multi-auth 6.0.0

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 (248) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +162 -0
  3. package/assets/opencode-logo-ornate-dark.svg +18 -0
  4. package/assets/readme-hero.svg +31 -0
  5. package/config/README.md +96 -0
  6. package/config/minimal-opencode.json +13 -0
  7. package/config/opencode-legacy.json +871 -0
  8. package/config/opencode-modern.json +358 -0
  9. package/dist/index.d.ts +45 -0
  10. package/dist/index.d.ts.map +1 -0
  11. package/dist/index.js +5008 -0
  12. package/dist/index.js.map +1 -0
  13. package/dist/lib/accounts/rate-limits.d.ts +22 -0
  14. package/dist/lib/accounts/rate-limits.d.ts.map +1 -0
  15. package/dist/lib/accounts/rate-limits.js +63 -0
  16. package/dist/lib/accounts/rate-limits.js.map +1 -0
  17. package/dist/lib/accounts.d.ts +134 -0
  18. package/dist/lib/accounts.d.ts.map +1 -0
  19. package/dist/lib/accounts.js +795 -0
  20. package/dist/lib/accounts.js.map +1 -0
  21. package/dist/lib/audit.d.ts +45 -0
  22. package/dist/lib/audit.d.ts.map +1 -0
  23. package/dist/lib/audit.js +154 -0
  24. package/dist/lib/audit.js.map +1 -0
  25. package/dist/lib/auth/auth.d.ts +51 -0
  26. package/dist/lib/auth/auth.d.ts.map +1 -0
  27. package/dist/lib/auth/auth.js +191 -0
  28. package/dist/lib/auth/auth.js.map +1 -0
  29. package/dist/lib/auth/browser.d.ts +17 -0
  30. package/dist/lib/auth/browser.d.ts.map +1 -0
  31. package/dist/lib/auth/browser.js +90 -0
  32. package/dist/lib/auth/browser.js.map +1 -0
  33. package/dist/lib/auth/device-code.d.ts +28 -0
  34. package/dist/lib/auth/device-code.d.ts.map +1 -0
  35. package/dist/lib/auth/device-code.js +215 -0
  36. package/dist/lib/auth/device-code.js.map +1 -0
  37. package/dist/lib/auth/login-runner.d.ts +55 -0
  38. package/dist/lib/auth/login-runner.d.ts.map +1 -0
  39. package/dist/lib/auth/login-runner.js +631 -0
  40. package/dist/lib/auth/login-runner.js.map +1 -0
  41. package/dist/lib/auth/server.d.ts +10 -0
  42. package/dist/lib/auth/server.d.ts.map +1 -0
  43. package/dist/lib/auth/server.js +98 -0
  44. package/dist/lib/auth/server.js.map +1 -0
  45. package/dist/lib/auth/token-utils.d.ts +60 -0
  46. package/dist/lib/auth/token-utils.d.ts.map +1 -0
  47. package/dist/lib/auth/token-utils.js +416 -0
  48. package/dist/lib/auth/token-utils.js.map +1 -0
  49. package/dist/lib/auth-rate-limit.d.ts +20 -0
  50. package/dist/lib/auth-rate-limit.d.ts.map +1 -0
  51. package/dist/lib/auth-rate-limit.js +91 -0
  52. package/dist/lib/auth-rate-limit.js.map +1 -0
  53. package/dist/lib/auto-update-checker.d.ts +10 -0
  54. package/dist/lib/auto-update-checker.d.ts.map +1 -0
  55. package/dist/lib/auto-update-checker.js +129 -0
  56. package/dist/lib/auto-update-checker.js.map +1 -0
  57. package/dist/lib/circuit-breaker.d.ts +34 -0
  58. package/dist/lib/circuit-breaker.d.ts.map +1 -0
  59. package/dist/lib/circuit-breaker.js +124 -0
  60. package/dist/lib/circuit-breaker.js.map +1 -0
  61. package/dist/lib/cli.d.ts +46 -0
  62. package/dist/lib/cli.d.ts.map +1 -0
  63. package/dist/lib/cli.js +192 -0
  64. package/dist/lib/cli.js.map +1 -0
  65. package/dist/lib/config.d.ts +42 -0
  66. package/dist/lib/config.d.ts.map +1 -0
  67. package/dist/lib/config.js +314 -0
  68. package/dist/lib/config.js.map +1 -0
  69. package/dist/lib/constants.d.ts +90 -0
  70. package/dist/lib/constants.d.ts.map +1 -0
  71. package/dist/lib/constants.js +90 -0
  72. package/dist/lib/constants.js.map +1 -0
  73. package/dist/lib/context-overflow.d.ts +27 -0
  74. package/dist/lib/context-overflow.d.ts.map +1 -0
  75. package/dist/lib/context-overflow.js +124 -0
  76. package/dist/lib/context-overflow.js.map +1 -0
  77. package/dist/lib/errors.d.ts +113 -0
  78. package/dist/lib/errors.d.ts.map +1 -0
  79. package/dist/lib/errors.js +103 -0
  80. package/dist/lib/errors.js.map +1 -0
  81. package/dist/lib/health.d.ts +33 -0
  82. package/dist/lib/health.d.ts.map +1 -0
  83. package/dist/lib/health.js +70 -0
  84. package/dist/lib/health.js.map +1 -0
  85. package/dist/lib/index.d.ts +20 -0
  86. package/dist/lib/index.d.ts.map +1 -0
  87. package/dist/lib/index.js +20 -0
  88. package/dist/lib/index.js.map +1 -0
  89. package/dist/lib/logger.d.ts +40 -0
  90. package/dist/lib/logger.d.ts.map +1 -0
  91. package/dist/lib/logger.js +337 -0
  92. package/dist/lib/logger.js.map +1 -0
  93. package/dist/lib/oauth-success.html +712 -0
  94. package/dist/lib/parallel-probe.d.ts +28 -0
  95. package/dist/lib/parallel-probe.d.ts.map +1 -0
  96. package/dist/lib/parallel-probe.js +97 -0
  97. package/dist/lib/parallel-probe.js.map +1 -0
  98. package/dist/lib/proactive-refresh.d.ts +67 -0
  99. package/dist/lib/proactive-refresh.d.ts.map +1 -0
  100. package/dist/lib/proactive-refresh.js +161 -0
  101. package/dist/lib/proactive-refresh.js.map +1 -0
  102. package/dist/lib/prompts/codex-opencode-bridge.d.ts +20 -0
  103. package/dist/lib/prompts/codex-opencode-bridge.d.ts.map +1 -0
  104. package/dist/lib/prompts/codex-opencode-bridge.js +126 -0
  105. package/dist/lib/prompts/codex-opencode-bridge.js.map +1 -0
  106. package/dist/lib/prompts/codex.d.ts +41 -0
  107. package/dist/lib/prompts/codex.d.ts.map +1 -0
  108. package/dist/lib/prompts/codex.js +400 -0
  109. package/dist/lib/prompts/codex.js.map +1 -0
  110. package/dist/lib/prompts/opencode-codex.d.ts +25 -0
  111. package/dist/lib/prompts/opencode-codex.d.ts.map +1 -0
  112. package/dist/lib/prompts/opencode-codex.js +223 -0
  113. package/dist/lib/prompts/opencode-codex.js.map +1 -0
  114. package/dist/lib/recovery/constants.d.ts +12 -0
  115. package/dist/lib/recovery/constants.d.ts.map +1 -0
  116. package/dist/lib/recovery/constants.js +25 -0
  117. package/dist/lib/recovery/constants.js.map +1 -0
  118. package/dist/lib/recovery/index.d.ts +12 -0
  119. package/dist/lib/recovery/index.d.ts.map +1 -0
  120. package/dist/lib/recovery/index.js +12 -0
  121. package/dist/lib/recovery/index.js.map +1 -0
  122. package/dist/lib/recovery/storage.d.ts +24 -0
  123. package/dist/lib/recovery/storage.d.ts.map +1 -0
  124. package/dist/lib/recovery/storage.js +362 -0
  125. package/dist/lib/recovery/storage.js.map +1 -0
  126. package/dist/lib/recovery/types.d.ts +116 -0
  127. package/dist/lib/recovery/types.d.ts.map +1 -0
  128. package/dist/lib/recovery/types.js +7 -0
  129. package/dist/lib/recovery/types.js.map +1 -0
  130. package/dist/lib/recovery.d.ts +31 -0
  131. package/dist/lib/recovery.d.ts.map +1 -0
  132. package/dist/lib/recovery.js +313 -0
  133. package/dist/lib/recovery.js.map +1 -0
  134. package/dist/lib/refresh-queue.d.ts +131 -0
  135. package/dist/lib/refresh-queue.d.ts.map +1 -0
  136. package/dist/lib/refresh-queue.js +297 -0
  137. package/dist/lib/refresh-queue.js.map +1 -0
  138. package/dist/lib/request/fetch-helpers.d.ts +142 -0
  139. package/dist/lib/request/fetch-helpers.d.ts.map +1 -0
  140. package/dist/lib/request/fetch-helpers.js +749 -0
  141. package/dist/lib/request/fetch-helpers.js.map +1 -0
  142. package/dist/lib/request/helpers/input-utils.d.ts +7 -0
  143. package/dist/lib/request/helpers/input-utils.d.ts.map +1 -0
  144. package/dist/lib/request/helpers/input-utils.js +214 -0
  145. package/dist/lib/request/helpers/input-utils.js.map +1 -0
  146. package/dist/lib/request/helpers/model-map.d.ts +22 -0
  147. package/dist/lib/request/helpers/model-map.d.ts.map +1 -0
  148. package/dist/lib/request/helpers/model-map.js +183 -0
  149. package/dist/lib/request/helpers/model-map.js.map +1 -0
  150. package/dist/lib/request/helpers/tool-utils.d.ts +29 -0
  151. package/dist/lib/request/helpers/tool-utils.d.ts.map +1 -0
  152. package/dist/lib/request/helpers/tool-utils.js +117 -0
  153. package/dist/lib/request/helpers/tool-utils.js.map +1 -0
  154. package/dist/lib/request/rate-limit-backoff.d.ts +17 -0
  155. package/dist/lib/request/rate-limit-backoff.d.ts.map +1 -0
  156. package/dist/lib/request/rate-limit-backoff.js +83 -0
  157. package/dist/lib/request/rate-limit-backoff.js.map +1 -0
  158. package/dist/lib/request/request-transformer.d.ts +107 -0
  159. package/dist/lib/request/request-transformer.d.ts.map +1 -0
  160. package/dist/lib/request/request-transformer.js +930 -0
  161. package/dist/lib/request/request-transformer.js.map +1 -0
  162. package/dist/lib/request/response-handler.d.ts +23 -0
  163. package/dist/lib/request/response-handler.d.ts.map +1 -0
  164. package/dist/lib/request/response-handler.js +245 -0
  165. package/dist/lib/request/response-handler.js.map +1 -0
  166. package/dist/lib/request/retry-budget.d.ts +19 -0
  167. package/dist/lib/request/retry-budget.d.ts.map +1 -0
  168. package/dist/lib/request/retry-budget.js +99 -0
  169. package/dist/lib/request/retry-budget.js.map +1 -0
  170. package/dist/lib/rotation.d.ts +130 -0
  171. package/dist/lib/rotation.d.ts.map +1 -0
  172. package/dist/lib/rotation.js +301 -0
  173. package/dist/lib/rotation.js.map +1 -0
  174. package/dist/lib/runtime-contracts.d.ts +16 -0
  175. package/dist/lib/runtime-contracts.d.ts.map +1 -0
  176. package/dist/lib/runtime-contracts.js +24 -0
  177. package/dist/lib/runtime-contracts.js.map +1 -0
  178. package/dist/lib/schemas.d.ts +457 -0
  179. package/dist/lib/schemas.d.ts.map +1 -0
  180. package/dist/lib/schemas.js +283 -0
  181. package/dist/lib/schemas.js.map +1 -0
  182. package/dist/lib/shutdown.d.ts +7 -0
  183. package/dist/lib/shutdown.d.ts.map +1 -0
  184. package/dist/lib/shutdown.js +43 -0
  185. package/dist/lib/shutdown.js.map +1 -0
  186. package/dist/lib/storage/migrations.d.ts +65 -0
  187. package/dist/lib/storage/migrations.d.ts.map +1 -0
  188. package/dist/lib/storage/migrations.js +44 -0
  189. package/dist/lib/storage/migrations.js.map +1 -0
  190. package/dist/lib/storage/paths.d.ts +16 -0
  191. package/dist/lib/storage/paths.d.ts.map +1 -0
  192. package/dist/lib/storage/paths.js +92 -0
  193. package/dist/lib/storage/paths.js.map +1 -0
  194. package/dist/lib/storage.d.ts +157 -0
  195. package/dist/lib/storage.d.ts.map +1 -0
  196. package/dist/lib/storage.js +1169 -0
  197. package/dist/lib/storage.js.map +1 -0
  198. package/dist/lib/table-formatter.d.ts +32 -0
  199. package/dist/lib/table-formatter.d.ts.map +1 -0
  200. package/dist/lib/table-formatter.js +44 -0
  201. package/dist/lib/table-formatter.js.map +1 -0
  202. package/dist/lib/types.d.ts +131 -0
  203. package/dist/lib/types.d.ts.map +1 -0
  204. package/dist/lib/types.js +2 -0
  205. package/dist/lib/types.js.map +1 -0
  206. package/dist/lib/ui/ansi.d.ts +22 -0
  207. package/dist/lib/ui/ansi.d.ts.map +1 -0
  208. package/dist/lib/ui/ansi.js +38 -0
  209. package/dist/lib/ui/ansi.js.map +1 -0
  210. package/dist/lib/ui/auth-menu.d.ts +39 -0
  211. package/dist/lib/ui/auth-menu.d.ts.map +1 -0
  212. package/dist/lib/ui/auth-menu.js +186 -0
  213. package/dist/lib/ui/auth-menu.js.map +1 -0
  214. package/dist/lib/ui/beginner.d.ts +62 -0
  215. package/dist/lib/ui/beginner.d.ts.map +1 -0
  216. package/dist/lib/ui/beginner.js +259 -0
  217. package/dist/lib/ui/beginner.js.map +1 -0
  218. package/dist/lib/ui/confirm.d.ts +2 -0
  219. package/dist/lib/ui/confirm.d.ts.map +1 -0
  220. package/dist/lib/ui/confirm.js +21 -0
  221. package/dist/lib/ui/confirm.js.map +1 -0
  222. package/dist/lib/ui/format.d.ts +9 -0
  223. package/dist/lib/ui/format.d.ts.map +1 -0
  224. package/dist/lib/ui/format.js +49 -0
  225. package/dist/lib/ui/format.js.map +1 -0
  226. package/dist/lib/ui/runtime.d.ts +11 -0
  227. package/dist/lib/ui/runtime.d.ts.map +1 -0
  228. package/dist/lib/ui/runtime.js +31 -0
  229. package/dist/lib/ui/runtime.js.map +1 -0
  230. package/dist/lib/ui/select.d.ts +20 -0
  231. package/dist/lib/ui/select.d.ts.map +1 -0
  232. package/dist/lib/ui/select.js +343 -0
  233. package/dist/lib/ui/select.js.map +1 -0
  234. package/dist/lib/ui/theme.d.ts +34 -0
  235. package/dist/lib/ui/theme.d.ts.map +1 -0
  236. package/dist/lib/ui/theme.js +84 -0
  237. package/dist/lib/ui/theme.js.map +1 -0
  238. package/dist/lib/utils.d.ts +29 -0
  239. package/dist/lib/utils.d.ts.map +1 -0
  240. package/dist/lib/utils.js +54 -0
  241. package/dist/lib/utils.js.map +1 -0
  242. package/package.json +113 -0
  243. package/scripts/audit-dev-allowlist.js +114 -0
  244. package/scripts/copy-oauth-success.js +37 -0
  245. package/scripts/install-oc-codex-multi-auth-core.js +381 -0
  246. package/scripts/install-oc-codex-multi-auth.js +15 -0
  247. package/scripts/test-all-models.sh +260 -0
  248. package/scripts/validate-model-map.sh +97 -0
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Constants used throughout the plugin
3
+ * Centralized for easy maintenance and configuration
4
+ */
5
+ /** Published package identifier used across runtime messages and install flows */
6
+ export declare const PACKAGE_NAME = "oc-codex-multi-auth";
7
+ /** Previous published package identifier kept for installer and storage migration */
8
+ export declare const LEGACY_PACKAGE_NAME = "oc-chatgpt-multi-auth";
9
+ /** Plugin identifier for logging and error messages */
10
+ export declare const PLUGIN_NAME = "oc-codex-multi-auth";
11
+ /** Storage file names for active and legacy account data */
12
+ export declare const ACCOUNTS_FILE_NAME = "oc-codex-multi-auth-accounts.json";
13
+ export declare const LEGACY_ACCOUNTS_FILE_NAME = "openai-codex-accounts.json";
14
+ export declare const FLAGGED_ACCOUNTS_FILE_NAME = "oc-codex-multi-auth-flagged-accounts.json";
15
+ export declare const LEGACY_FLAGGED_ACCOUNTS_FILE_NAME = "openai-codex-flagged-accounts.json";
16
+ export declare const LEGACY_BLOCKED_ACCOUNTS_FILE_NAME = "openai-codex-blocked-accounts.json";
17
+ /** Base URL for ChatGPT backend API */
18
+ export declare const CODEX_BASE_URL = "https://chatgpt.com/backend-api";
19
+ /** Dummy API key used for OpenAI SDK (actual auth via OAuth) */
20
+ export declare const DUMMY_API_KEY = "chatgpt-oauth";
21
+ /** Provider ID for UI display - shows under "OpenAI" in auth dropdown */
22
+ export declare const PROVIDER_ID = "openai";
23
+ /** HTTP Status Codes */
24
+ export declare const HTTP_STATUS: {
25
+ readonly BAD_REQUEST: 400;
26
+ readonly OK: 200;
27
+ readonly FORBIDDEN: 403;
28
+ readonly UNAUTHORIZED: 401;
29
+ readonly NOT_FOUND: 404;
30
+ readonly TOO_MANY_REQUESTS: 429;
31
+ };
32
+ /** OpenAI-specific headers */
33
+ export declare const OPENAI_HEADERS: {
34
+ readonly BETA: "OpenAI-Beta";
35
+ readonly ACCOUNT_ID: "chatgpt-account-id";
36
+ readonly ORGANIZATION_ID: "openai-organization";
37
+ readonly ORIGINATOR: "originator";
38
+ readonly SESSION_ID: "session_id";
39
+ readonly CONVERSATION_ID: "conversation_id";
40
+ };
41
+ /** OpenAI-specific header values */
42
+ export declare const OPENAI_HEADER_VALUES: {
43
+ readonly BETA_RESPONSES: "responses=experimental";
44
+ readonly ORIGINATOR_CODEX: "codex_cli_rs";
45
+ };
46
+ /** URL path segments */
47
+ export declare const URL_PATHS: {
48
+ readonly RESPONSES: "/responses";
49
+ readonly CODEX_RESPONSES: "/codex/responses";
50
+ };
51
+ /** JWT claim path for ChatGPT account ID */
52
+ export declare const JWT_CLAIM_PATH: "https://api.openai.com/auth";
53
+ /** Error messages */
54
+ export declare const ERROR_MESSAGES: {
55
+ readonly NO_ACCOUNT_ID: "Failed to extract accountId from token";
56
+ readonly TOKEN_REFRESH_FAILED: "Failed to refresh token, authentication required";
57
+ readonly REQUEST_PARSE_ERROR: "Error parsing request";
58
+ };
59
+ /** Log stages for request logging */
60
+ export declare const LOG_STAGES: {
61
+ readonly BEFORE_TRANSFORM: "before-transform";
62
+ readonly AFTER_TRANSFORM: "after-transform";
63
+ readonly RESPONSE: "response";
64
+ readonly ERROR_RESPONSE: "error-response";
65
+ };
66
+ /** Platform-specific browser opener commands */
67
+ export declare const PLATFORM_OPENERS: {
68
+ readonly darwin: "open";
69
+ readonly win32: "start";
70
+ readonly linux: "xdg-open";
71
+ };
72
+ /** OAuth authorization labels */
73
+ export declare const AUTH_LABELS: {
74
+ readonly OAUTH: "Codex OAuth (ChatGPT Plus/Pro)";
75
+ readonly OAUTH_DEVICE_CODE: "Codex OAuth (Device Code)";
76
+ readonly OAUTH_MANUAL: "Codex OAuth (Manual URL Paste)";
77
+ readonly API_KEY: "Manual API Key (Advanced)";
78
+ readonly INSTRUCTIONS: "A browser window should open. If it doesn't, copy the URL and open it manually.";
79
+ readonly INSTRUCTIONS_MANUAL: "After logging in, copy the full redirect URL and paste it here.";
80
+ };
81
+ /** Multi-account configuration */
82
+ export declare const ACCOUNT_LIMITS: {
83
+ /** Maximum number of OAuth accounts that can be registered */
84
+ readonly MAX_ACCOUNTS: 20;
85
+ /** Cooldown period (ms) after auth failure before retrying account */
86
+ readonly AUTH_FAILURE_COOLDOWN_MS: 30000;
87
+ /** Number of consecutive auth failures before auto-removing account */
88
+ readonly MAX_AUTH_FAILURES_BEFORE_REMOVAL: 3;
89
+ };
90
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../lib/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,kFAAkF;AAClF,eAAO,MAAM,YAAY,wBAAwB,CAAC;AAElD,qFAAqF;AACrF,eAAO,MAAM,mBAAmB,0BAA0B,CAAC;AAE3D,uDAAuD;AACvD,eAAO,MAAM,WAAW,wBAAe,CAAC;AAExC,4DAA4D;AAC5D,eAAO,MAAM,kBAAkB,sCAAsC,CAAC;AACtE,eAAO,MAAM,yBAAyB,+BAA+B,CAAC;AACtE,eAAO,MAAM,0BAA0B,8CAA8C,CAAC;AACtF,eAAO,MAAM,iCAAiC,uCAAuC,CAAC;AACtF,eAAO,MAAM,iCAAiC,uCAAuC,CAAC;AAEtF,uCAAuC;AACvC,eAAO,MAAM,cAAc,oCAAoC,CAAC;AAEhE,gEAAgE;AAChE,eAAO,MAAM,aAAa,kBAAkB,CAAC;AAE7C,yEAAyE;AACzE,eAAO,MAAM,WAAW,WAAW,CAAC;AAEpC,wBAAwB;AACxB,eAAO,MAAM,WAAW;;;;;;;CAOd,CAAC;AAEX,8BAA8B;AAC9B,eAAO,MAAM,cAAc;;;;;;;CAOjB,CAAC;AAEX,oCAAoC;AACpC,eAAO,MAAM,oBAAoB;;;CAGvB,CAAC;AAEX,wBAAwB;AACxB,eAAO,MAAM,SAAS;;;CAGZ,CAAC;AAEX,4CAA4C;AAC5C,eAAO,MAAM,cAAc,EAAG,6BAAsC,CAAC;AAErE,qBAAqB;AACrB,eAAO,MAAM,cAAc;;;;CAIjB,CAAC;AAEX,qCAAqC;AACrC,eAAO,MAAM,UAAU;;;;;CAKb,CAAC;AAEX,gDAAgD;AAChD,eAAO,MAAM,gBAAgB;;;;CAInB,CAAC;AAEX,iCAAiC;AACjC,eAAO,MAAM,WAAW;;;;;;;CASd,CAAC;AAEX,kCAAkC;AAClC,eAAO,MAAM,cAAc;IAC1B,8DAA8D;;IAE9D,sEAAsE;;IAEtE,uEAAuE;;CAE9D,CAAC"}
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Constants used throughout the plugin
3
+ * Centralized for easy maintenance and configuration
4
+ */
5
+ /** Published package identifier used across runtime messages and install flows */
6
+ export const PACKAGE_NAME = "oc-codex-multi-auth";
7
+ /** Previous published package identifier kept for installer and storage migration */
8
+ export const LEGACY_PACKAGE_NAME = "oc-chatgpt-multi-auth";
9
+ /** Plugin identifier for logging and error messages */
10
+ export const PLUGIN_NAME = PACKAGE_NAME;
11
+ /** Storage file names for active and legacy account data */
12
+ export const ACCOUNTS_FILE_NAME = "oc-codex-multi-auth-accounts.json";
13
+ export const LEGACY_ACCOUNTS_FILE_NAME = "openai-codex-accounts.json";
14
+ export const FLAGGED_ACCOUNTS_FILE_NAME = "oc-codex-multi-auth-flagged-accounts.json";
15
+ export const LEGACY_FLAGGED_ACCOUNTS_FILE_NAME = "openai-codex-flagged-accounts.json";
16
+ export const LEGACY_BLOCKED_ACCOUNTS_FILE_NAME = "openai-codex-blocked-accounts.json";
17
+ /** Base URL for ChatGPT backend API */
18
+ export const CODEX_BASE_URL = "https://chatgpt.com/backend-api";
19
+ /** Dummy API key used for OpenAI SDK (actual auth via OAuth) */
20
+ export const DUMMY_API_KEY = "chatgpt-oauth";
21
+ /** Provider ID for UI display - shows under "OpenAI" in auth dropdown */
22
+ export const PROVIDER_ID = "openai";
23
+ /** HTTP Status Codes */
24
+ export const HTTP_STATUS = {
25
+ BAD_REQUEST: 400,
26
+ OK: 200,
27
+ FORBIDDEN: 403,
28
+ UNAUTHORIZED: 401,
29
+ NOT_FOUND: 404,
30
+ TOO_MANY_REQUESTS: 429,
31
+ };
32
+ /** OpenAI-specific headers */
33
+ export const OPENAI_HEADERS = {
34
+ BETA: "OpenAI-Beta",
35
+ ACCOUNT_ID: "chatgpt-account-id",
36
+ ORGANIZATION_ID: "openai-organization",
37
+ ORIGINATOR: "originator",
38
+ SESSION_ID: "session_id",
39
+ CONVERSATION_ID: "conversation_id",
40
+ };
41
+ /** OpenAI-specific header values */
42
+ export const OPENAI_HEADER_VALUES = {
43
+ BETA_RESPONSES: "responses=experimental",
44
+ ORIGINATOR_CODEX: "codex_cli_rs",
45
+ };
46
+ /** URL path segments */
47
+ export const URL_PATHS = {
48
+ RESPONSES: "/responses",
49
+ CODEX_RESPONSES: "/codex/responses",
50
+ };
51
+ /** JWT claim path for ChatGPT account ID */
52
+ export const JWT_CLAIM_PATH = "https://api.openai.com/auth";
53
+ /** Error messages */
54
+ export const ERROR_MESSAGES = {
55
+ NO_ACCOUNT_ID: "Failed to extract accountId from token",
56
+ TOKEN_REFRESH_FAILED: "Failed to refresh token, authentication required",
57
+ REQUEST_PARSE_ERROR: "Error parsing request",
58
+ };
59
+ /** Log stages for request logging */
60
+ export const LOG_STAGES = {
61
+ BEFORE_TRANSFORM: "before-transform",
62
+ AFTER_TRANSFORM: "after-transform",
63
+ RESPONSE: "response",
64
+ ERROR_RESPONSE: "error-response",
65
+ };
66
+ /** Platform-specific browser opener commands */
67
+ export const PLATFORM_OPENERS = {
68
+ darwin: "open",
69
+ win32: "start",
70
+ linux: "xdg-open",
71
+ };
72
+ /** OAuth authorization labels */
73
+ export const AUTH_LABELS = {
74
+ OAUTH: "Codex OAuth (ChatGPT Plus/Pro)",
75
+ OAUTH_DEVICE_CODE: "Codex OAuth (Device Code)",
76
+ OAUTH_MANUAL: "Codex OAuth (Manual URL Paste)",
77
+ API_KEY: "Manual API Key (Advanced)",
78
+ INSTRUCTIONS: "A browser window should open. If it doesn't, copy the URL and open it manually.",
79
+ INSTRUCTIONS_MANUAL: "After logging in, copy the full redirect URL and paste it here.",
80
+ };
81
+ /** Multi-account configuration */
82
+ export const ACCOUNT_LIMITS = {
83
+ /** Maximum number of OAuth accounts that can be registered */
84
+ MAX_ACCOUNTS: 20,
85
+ /** Cooldown period (ms) after auth failure before retrying account */
86
+ AUTH_FAILURE_COOLDOWN_MS: 30_000,
87
+ /** Number of consecutive auth failures before auto-removing account */
88
+ MAX_AUTH_FAILURES_BEFORE_REMOVAL: 3,
89
+ };
90
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../lib/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,kFAAkF;AAClF,MAAM,CAAC,MAAM,YAAY,GAAG,qBAAqB,CAAC;AAElD,qFAAqF;AACrF,MAAM,CAAC,MAAM,mBAAmB,GAAG,uBAAuB,CAAC;AAE3D,uDAAuD;AACvD,MAAM,CAAC,MAAM,WAA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AACrB,MAAM,CAAC,MAAM,cAAc,GAAG;IAC7B,aAAa,EAAE,wCAAwC;IACvD,oBAAoB,EAAE,kDAAkD;IACxE,mBAAmB,EAAE,uBAAuB;CACnC,CAAC;AAEX,qCAAqC;AACrC,MAAM,CAAC,MAAM,UAAU,GAAG;IACzB,gBAAgB,EAAE,kBAAkB;IACpC,eAAe,EAAE,iBAAiB;IAClC,QAAQ,EAAE,UAAU;IACpB,cAAc,EAAE,gBAAgB;CACvB,CAAC;AAEX,gDAAgD;AAChD,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC/B,MAAM,EAAE,MAAM;IACd,KAAK,EAAE,OAAO;IACd,KAAK,EAAE,UAAU;CACR,CAAC;AAEX,iCAAiC;AACjC,MAAM,CAAC,MAAM,WAAW,GAAG;IAC1B,KAAK,EAAE,gCAAgC;IACvC,iBAAiB,EAAE,2BAA2B;IAC9C,YAAY,EAAE,gCAAgC;IAC9C,OAAO,EAAE,2BAA2B;IACpC,YAAY,EACX,iFAAiF;IAClF,mBAAmB,EAClB,iEAAiE;CACzD,CAAC;AAEX,kCAAkC;AAClC,MAAM,CAAC,MAAM,cAAc,GAAG;IAC7B,8DAA8D;IAC9D,YAAY,EAAE,EAAE;IAChB,sEAAsE;IACtE,wBAAwB,EAAE,MAAM;IAChC,uEAAuE;IACvE,gCAAgC,EAAE,CAAC;CAC1B,CAAC"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Context Overflow Handler
3
+ *
4
+ * Handles "Prompt too long" / context length exceeded errors by returning
5
+ * a synthetic SSE response that advises the user to use /compact or /clear.
6
+ * This prevents the OpenCode session from getting locked on 400 errors.
7
+ */
8
+ /**
9
+ * Check if an error body indicates context overflow
10
+ */
11
+ export declare function isContextOverflowError(status: number, bodyText: string): boolean;
12
+ /**
13
+ * Creates a synthetic SSE response for context overflow errors.
14
+ * This returns a 200 OK with the error message as assistant text,
15
+ * preventing the session from getting locked.
16
+ */
17
+ export declare function createContextOverflowResponse(model?: string): Response;
18
+ /**
19
+ * Check response for context overflow and return synthetic response if needed
20
+ */
21
+ export declare function handleContextOverflow(response: Response, model?: string): Promise<{
22
+ handled: true;
23
+ response: Response;
24
+ } | {
25
+ handled: false;
26
+ }>;
27
+ //# sourceMappingURL=context-overflow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-overflow.d.ts","sourceRoot":"","sources":["../../lib/context-overflow.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAiBH;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAMhF;AAiBD;;;;GAIG;AACH,wBAAgB,6BAA6B,CAAC,KAAK,GAAE,MAAkB,GAAG,QAAQ,CAyDjF;AAED;;GAEG;AACH,wBAAsB,qBAAqB,CACzC,QAAQ,EAAE,QAAQ,EAClB,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,QAAQ,EAAE,QAAQ,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,KAAK,CAAA;CAAE,CAAC,CAmBrE"}
@@ -0,0 +1,124 @@
1
+ /**
2
+ * Context Overflow Handler
3
+ *
4
+ * Handles "Prompt too long" / context length exceeded errors by returning
5
+ * a synthetic SSE response that advises the user to use /compact or /clear.
6
+ * This prevents the OpenCode session from getting locked on 400 errors.
7
+ */
8
+ import { logDebug } from "./logger.js";
9
+ /**
10
+ * Error patterns that indicate context overflow
11
+ */
12
+ const CONTEXT_OVERFLOW_PATTERNS = [
13
+ "prompt is too long",
14
+ "prompt_too_long",
15
+ "context length exceeded",
16
+ "context_length_exceeded",
17
+ "maximum context length",
18
+ "token limit exceeded",
19
+ "too many tokens",
20
+ ];
21
+ /**
22
+ * Check if an error body indicates context overflow
23
+ */
24
+ export function isContextOverflowError(status, bodyText) {
25
+ if (status !== 400)
26
+ return false;
27
+ if (!bodyText)
28
+ return false;
29
+ const lowerBody = bodyText.toLowerCase();
30
+ return CONTEXT_OVERFLOW_PATTERNS.some(pattern => lowerBody.includes(pattern));
31
+ }
32
+ /**
33
+ * The message shown to users when context overflow occurs
34
+ */
35
+ const CONTEXT_OVERFLOW_MESSAGE = `[Plugin Notice] Context is too long for this model.
36
+
37
+ Please use one of these commands to reduce context size:
38
+
39
+ • **/compact** - Compress conversation history (recommended)
40
+ • **/clear** - Start fresh with empty context
41
+ • **/undo** - Remove recent messages
42
+
43
+ Then retry your request.
44
+
45
+ Alternatively, you can switch to a model with a larger context window.`;
46
+ /**
47
+ * Creates a synthetic SSE response for context overflow errors.
48
+ * This returns a 200 OK with the error message as assistant text,
49
+ * preventing the session from getting locked.
50
+ */
51
+ export function createContextOverflowResponse(model = "unknown") {
52
+ const messageId = `msg_synthetic_overflow_${Date.now()}`;
53
+ const events = [];
54
+ // message_start
55
+ events.push(`event: message_start\ndata: ${JSON.stringify({
56
+ type: "message_start",
57
+ message: {
58
+ id: messageId,
59
+ type: "message",
60
+ role: "assistant",
61
+ content: [],
62
+ model,
63
+ usage: { input_tokens: 0, output_tokens: 0 },
64
+ },
65
+ })}\n\n`);
66
+ // content_block_start
67
+ events.push(`event: content_block_start\ndata: ${JSON.stringify({
68
+ type: "content_block_start",
69
+ index: 0,
70
+ content_block: { type: "text", text: "" },
71
+ })}\n\n`);
72
+ // content_block_delta (the actual message)
73
+ events.push(`event: content_block_delta\ndata: ${JSON.stringify({
74
+ type: "content_block_delta",
75
+ index: 0,
76
+ delta: { type: "text_delta", text: CONTEXT_OVERFLOW_MESSAGE },
77
+ })}\n\n`);
78
+ // content_block_stop
79
+ events.push(`event: content_block_stop\ndata: ${JSON.stringify({
80
+ type: "content_block_stop",
81
+ index: 0,
82
+ })}\n\n`);
83
+ // message_delta (end_turn)
84
+ events.push(`event: message_delta\ndata: ${JSON.stringify({
85
+ type: "message_delta",
86
+ delta: { stop_reason: "end_turn" },
87
+ usage: { output_tokens: 0 },
88
+ })}\n\n`);
89
+ // message_stop
90
+ events.push(`event: message_stop\ndata: ${JSON.stringify({
91
+ type: "message_stop",
92
+ })}\n\n`);
93
+ return new Response(events.join(""), {
94
+ status: 200,
95
+ headers: {
96
+ "Content-Type": "text/event-stream",
97
+ "X-Codex-Plugin-Synthetic": "true",
98
+ "X-Codex-Plugin-Error-Type": "context_overflow",
99
+ },
100
+ });
101
+ }
102
+ /**
103
+ * Check response for context overflow and return synthetic response if needed
104
+ */
105
+ export async function handleContextOverflow(response, model) {
106
+ if (response.status !== 400) {
107
+ return { handled: false };
108
+ }
109
+ try {
110
+ const bodyText = await response.clone().text();
111
+ if (isContextOverflowError(response.status, bodyText)) {
112
+ logDebug("Context overflow detected, returning synthetic response");
113
+ return {
114
+ handled: true,
115
+ response: createContextOverflowResponse(model),
116
+ };
117
+ }
118
+ }
119
+ catch {
120
+ // Ignore read errors
121
+ }
122
+ return { handled: false };
123
+ }
124
+ //# sourceMappingURL=context-overflow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-overflow.js","sourceRoot":"","sources":["../../lib/context-overflow.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC;;GAEG;AACH,MAAM,yBAAyB,GAAG;IAChC,oBAAoB;IACpB,iBAAiB;IACjB,yBAAyB;IACzB,yBAAyB;IACzB,wBAAwB;IACxB,sBAAsB;IACtB,iBAAiB;CAClB,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,sBAAsB,CAAC,MAAc,EAAE,QAAgB;IACrE,IAAI,MAAM,KAAK,GAAG;QAAE,OAAO,KAAK,CAAC;IACjC,IAAI,CAAC,QAAQ;QAAE,OAAO,KAAK,CAAC;IAE5B,MAAM,SAAS,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;IACzC,OAAO,yBAAyB,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;AAChF,CAA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+ * Provides structured error types with codes, causes, and context.
4
+ */
5
+ /**
6
+ * Error codes for categorizing errors.
7
+ */
8
+ export declare const ErrorCode: {
9
+ readonly NETWORK_ERROR: "CODEX_NETWORK_ERROR";
10
+ readonly API_ERROR: "CODEX_API_ERROR";
11
+ readonly AUTH_ERROR: "CODEX_AUTH_ERROR";
12
+ readonly VALIDATION_ERROR: "CODEX_VALIDATION_ERROR";
13
+ readonly RATE_LIMIT: "CODEX_RATE_LIMIT";
14
+ readonly TIMEOUT: "CODEX_TIMEOUT";
15
+ };
16
+ export type ErrorCodeType = (typeof ErrorCode)[keyof typeof ErrorCode];
17
+ /**
18
+ * Options for creating a CodexError.
19
+ */
20
+ export interface CodexErrorOptions {
21
+ code?: string;
22
+ cause?: unknown;
23
+ context?: Record<string, unknown>;
24
+ }
25
+ /**
26
+ * Base error class for all Codex plugin errors.
27
+ * Supports error chaining via `cause` and arbitrary context data.
28
+ */
29
+ export declare class CodexError extends Error {
30
+ readonly name: string;
31
+ readonly code: string;
32
+ readonly context?: Record<string, unknown>;
33
+ constructor(message: string, options?: CodexErrorOptions);
34
+ }
35
+ /**
36
+ * Options for creating a CodexApiError.
37
+ */
38
+ export interface CodexApiErrorOptions extends CodexErrorOptions {
39
+ status: number;
40
+ headers?: Record<string, string>;
41
+ }
42
+ /**
43
+ * Error for HTTP/API response errors.
44
+ */
45
+ export declare class CodexApiError extends CodexError {
46
+ readonly name = "CodexApiError";
47
+ readonly status: number;
48
+ readonly headers?: Record<string, string>;
49
+ constructor(message: string, options: CodexApiErrorOptions);
50
+ }
51
+ /**
52
+ * Options for creating a CodexAuthError.
53
+ */
54
+ export interface CodexAuthErrorOptions extends CodexErrorOptions {
55
+ accountId?: string;
56
+ retryable?: boolean;
57
+ }
58
+ /**
59
+ * Error for authentication failures.
60
+ */
61
+ export declare class CodexAuthError extends CodexError {
62
+ readonly name = "CodexAuthError";
63
+ readonly accountId?: string;
64
+ readonly retryable: boolean;
65
+ constructor(message: string, options?: CodexAuthErrorOptions);
66
+ }
67
+ /**
68
+ * Options for creating a CodexNetworkError.
69
+ */
70
+ export interface CodexNetworkErrorOptions extends CodexErrorOptions {
71
+ retryable?: boolean;
72
+ }
73
+ /**
74
+ * Error for network/connection failures.
75
+ */
76
+ export declare class CodexNetworkError extends CodexError {
77
+ readonly name = "CodexNetworkError";
78
+ readonly retryable: boolean;
79
+ constructor(message: string, options?: CodexNetworkErrorOptions);
80
+ }
81
+ /**
82
+ * Options for creating a CodexValidationError.
83
+ */
84
+ export interface CodexValidationErrorOptions extends CodexErrorOptions {
85
+ field?: string;
86
+ expected?: string;
87
+ }
88
+ /**
89
+ * Error for input validation failures.
90
+ */
91
+ export declare class CodexValidationError extends CodexError {
92
+ readonly name = "CodexValidationError";
93
+ readonly field?: string;
94
+ readonly expected?: string;
95
+ constructor(message: string, options?: CodexValidationErrorOptions);
96
+ }
97
+ /**
98
+ * Options for creating a CodexRateLimitError.
99
+ */
100
+ export interface CodexRateLimitErrorOptions extends CodexErrorOptions {
101
+ retryAfterMs?: number;
102
+ accountId?: string;
103
+ }
104
+ /**
105
+ * Error for rate limit exceeded.
106
+ */
107
+ export declare class CodexRateLimitError extends CodexError {
108
+ readonly name = "CodexRateLimitError";
109
+ readonly retryAfterMs?: number;
110
+ readonly accountId?: string;
111
+ constructor(message: string, options?: CodexRateLimitErrorOptions);
112
+ }
113
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../lib/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,eAAO,MAAM,SAAS;;;;;;;CAOZ,CAAC;AAEX,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,SAAS,CAAC,CAAC,MAAM,OAAO,SAAS,CAAC,CAAC;AAEvE;;GAEG;AACH,MAAM,WAAW,iBAAiB;IACjC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,OAAO,CAAC;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,qBAAa,iBAAkB,SAAQ,UAAU;IAChD,SAAkB,IAAI,uBAAuB;IAC7C,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;gBAEhB,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,wBAAwB;CAO/D;AAED;;GAEG;AACH,MAAM,WAAW,2BAA4B,SAAQ,iBAAiB;IACrE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,UAAU;IACnD,SAAkB,IAAI,0BAA0B;IAChD,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;gBAEf,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,2BAA2B;CAQlE;AAED;;GAEG;AACH,MAAM,WAAW,0BAA2B,SAAQ,iBAAiB;IACpE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,UAAU;IAClD,SAAkB,IAAI,yBAAyB;IAC/C,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;gBAEhB,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,0BAA0B;CAKjE"}
@@ -0,0 +1,103 @@
1
+ /**
2
+ * Typed error hierarchy for the Codex plugin.
3
+ * Provides structured error types with codes, causes, and context.
4
+ */
5
+ /**
6
+ * Error codes for categorizing errors.
7
+ */
8
+ export const ErrorCode = {
9
+ NETWORK_ERROR: "CODEX_NETWORK_ERROR",
10
+ API_ERROR: "CODEX_API_ERROR",
11
+ AUTH_ERROR: "CODEX_AUTH_ERROR",
12
+ VALIDATION_ERROR: "CODEX_VALIDATION_ERROR",
13
+ RATE_LIMIT: "CODEX_RATE_LIMIT",
14
+ TIMEOUT: "CODEX_TIMEOUT",
15
+ };
16
+ /**
17
+ * Base error class for all Codex plugin errors.
18
+ * Supports error chaining via `cause` and arbitrary context data.
19
+ */
20
+ export class CodexError extends Error {
21
+ name = "CodexError";
22
+ code;
23
+ context;
24
+ constructor(message, options) {
25
+ super(message, { cause: options?.cause });
26
+ this.code = options?.code ?? ErrorCode.API_ERROR;
27
+ this.context = options?.context;
28
+ // istanbul ignore next -- Error.captureStackTrace always exists in Node.js
29
+ if (Error.captureStackTrace) {
30
+ Error.captureStackTrace(this, this.constructor);
31
+ }
32
+ }
33
+ }
34
+ /**
35
+ * Error for HTTP/API response errors.
36
+ */
37
+ export class CodexApiError extends CodexError {
38
+ name = "CodexApiError";
39
+ status;
40
+ headers;
41
+ constructor(message, options) {
42
+ super(message, { ...options, code: options.code ?? ErrorCode.API_ERROR });
43
+ this.status = options.status;
44
+ this.headers = options.headers;
45
+ }
46
+ }
47
+ /**
48
+ * Error for authentication failures.
49
+ */
50
+ export class CodexAuthError extends CodexError {
51
+ name = "CodexAuthError";
52
+ accountId;
53
+ retryable;
54
+ constructor(message, options) {
55
+ super(message, { ...options, code: options?.code ?? ErrorCode.AUTH_ERROR });
56
+ this.accountId = options?.accountId;
57
+ this.retryable = options?.retryable ?? false;
58
+ }
59
+ }
60
+ /**
61
+ * Error for network/connection failures.
62
+ */
63
+ export class CodexNetworkError extends CodexError {
64
+ name = "CodexNetworkError";
65
+ retryable;
66
+ constructor(message, options) {
67
+ super(message, {
68
+ ...options,
69
+ code: options?.code ?? ErrorCode.NETWORK_ERROR,
70
+ });
71
+ this.retryable = options?.retryable ?? true;
72
+ }
73
+ }
74
+ /**
75
+ * Error for input validation failures.
76
+ */
77
+ export class CodexValidationError extends CodexError {
78
+ name = "CodexValidationError";
79
+ field;
80
+ expected;
81
+ constructor(message, options) {
82
+ super(message, {
83
+ ...options,
84
+ code: options?.code ?? ErrorCode.VALIDATION_ERROR,
85
+ });
86
+ this.field = options?.field;
87
+ this.expected = options?.expected;
88
+ }
89
+ }
90
+ /**
91
+ * Error for rate limit exceeded.
92
+ */
93
+ export class CodexRateLimitError extends CodexError {
94
+ name = "CodexRateLimitError";
95
+ retryAfterMs;
96
+ accountId;
97
+ constructor(message, options) {
98
+ super(message, { ...options, code: options?.code ?? ErrorCode.RATE_LIMIT });
99
+ this.retryAfterMs = options?.retryAfterMs;
100
+ this.accountId = options?.accountId;
101
+ }
102
+ }
103
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../lib/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG;IACxB,aAAa,EAAE,qBAAqB;IACpC,SAAS,EAAE,iBAAiB;IAC5B,UAAU,EAAE,kBAAkB;IAC9B,gBAAgB,EAAE,wBAAwB;IAC1C,UAAU,EAAE,kBAAkB;IAC9B,OAAO,EAAE,eAAe;CACf,CAAC;AAaX;;;GAGG;AACH,MAAM,OAAO,UAAW,SAAQ,KAAK;IAClB,IAAI,GAAW,YAAY,CAAC;IACrC,IAAI,CAAS;IACb,OAAO,CAA2B;IAE3C,YAAY,OAAe,EAAE,OAA2B;QACvD,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;QAC1C,IAAI,CAAC,IAAI,GAAG,OAAO,EAAE,IAAI,IAAI,SAAS,CAAC,SAAS,CAAC;QACjD,IAAI,CAAC,OAAO,GAAG,OAAO,EAAE,OAAO,CAAC;QAEhC,2EAA2E;QAC3E,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;YAC7B,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QACjD,CAAC;IACF,CAAC;CACD;AAUD;;GAEG;AACH,MAAM,OAAO,aAAc,SAAQ,UAAU;IAC1B,IAAI,GAAG,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AAe,EAAE,OAAqC;QACjE,KAAK,CAAC,OAAO,EAAE;YACd,GAAG,OAAO;YACV,IAAI,EAAE,OAAO,EAAE,IAAI,IAAI,SAAS,CAAC,gBAAgB;SACjD,CAAC,CAAC;QACH,IAAI,CAAC,KAAK,GAAG,OAAO,EAAE,KAAK,CAAC;QAC5B,IAAI,CAAC,QAAQ,GAAG,OAAO,EAAE,QAAQ,CAAC;IACnC,CAAC;CACD;AAUD;;GAEG;AACH,MAAM,OAAO,mBAAoB,SAAQ,UAAU;IAChC,IAAI,GAAG,qBAAqB,CAAC;IACtC,YAAY,CAAU;IACtB,SAAS,CAAU;IAE5B,YAAY,OAAe,EAAE,OAAoC;QAChE,KAAK,CAAC,OAAO,EAAE,EAAE,GAAG,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,IAAI,SAAS,CAAC,UAAU,EAAE,CAAC,CAAC;QAC5E,IAAI,CAAC,YAAY,GAAG,OAAO,EAAE,YAAY,CAAC;QAC1C,IAAI,CAAC,SAAS,GAAG,OAAO,EAAE,SAAS,CAAC;IACrC,CAAC;CACD"}
@@ -0,0 +1,33 @@
1
+ import { type CircuitState } from "./circuit-breaker.js";
2
+ export interface AccountHealth {
3
+ index: number;
4
+ email?: string;
5
+ accountId?: string;
6
+ health: number;
7
+ isRateLimited: boolean;
8
+ isCoolingDown: boolean;
9
+ cooldownReason?: string;
10
+ lastUsed?: number;
11
+ circuitState: CircuitState;
12
+ }
13
+ export interface PluginHealth {
14
+ status: "healthy" | "degraded" | "unhealthy";
15
+ accountCount: number;
16
+ healthyAccountCount: number;
17
+ rateLimitedCount: number;
18
+ coolingDownCount: number;
19
+ accounts: AccountHealth[];
20
+ timestamp: number;
21
+ }
22
+ export declare function getAccountHealth(accounts: Array<{
23
+ index: number;
24
+ email?: string;
25
+ accountId?: string;
26
+ health: number;
27
+ rateLimitedUntil?: number;
28
+ cooldownUntil?: number;
29
+ cooldownReason?: string;
30
+ lastUsedAt?: number;
31
+ }>, now?: number): PluginHealth;
32
+ export declare function formatHealthReport(health: PluginHealth): string;
33
+ //# sourceMappingURL=health.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../../lib/health.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAE5E,MAAM,WAAW,aAAa;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,OAAO,CAAC;IACvB,aAAa,EAAE,OAAO,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,YAAY,CAAC;CAC3B;AAED,MAAM,WAAW,YAAY;IAC5B,MAAM,EAAE,SAAS,GAAG,UAAU,GAAG,WAAW,CAAC;IAC7C,YAAY,EAAE,MAAM,CAAC;IACrB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,gBAAgB,EAAE,MAAM,CAAC;IACzB,gBAAgB,EAAE,MAAM,CAAC;IACzB,QAAQ,EAAE,aAAa,EAAE,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;CAClB;AAED,wBAAgB,gBAAgB,CAC/B,QAAQ,EAAE,KAAK,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC,EACF,GAAG,SAAa,GACd,YAAY,CA2Cd;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CA4B/D"}