opencode-codex-auth-rotation 1.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 (95) hide show
  1. package/LICENSE +37 -0
  2. package/README.md +170 -0
  3. package/assets/codex-auth.schema.json +26 -0
  4. package/assets/opencode-logo-ornate-dark.svg +18 -0
  5. package/assets/readme-hero.svg +31 -0
  6. package/config/README.md +103 -0
  7. package/config/minimal-opencode.json +12 -0
  8. package/config/opencode-legacy.json +571 -0
  9. package/config/opencode-modern.json +239 -0
  10. package/dist/index.d.ts +42 -0
  11. package/dist/index.d.ts.map +1 -0
  12. package/dist/index.js +299 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/lib/auth/auth.d.ts +43 -0
  15. package/dist/lib/auth/auth.d.ts.map +1 -0
  16. package/dist/lib/auth/auth.js +163 -0
  17. package/dist/lib/auth/auth.js.map +1 -0
  18. package/dist/lib/auth/browser.d.ts +17 -0
  19. package/dist/lib/auth/browser.d.ts.map +1 -0
  20. package/dist/lib/auth/browser.js +76 -0
  21. package/dist/lib/auth/browser.js.map +1 -0
  22. package/dist/lib/auth/server.d.ts +10 -0
  23. package/dist/lib/auth/server.d.ts.map +1 -0
  24. package/dist/lib/auth/server.js +78 -0
  25. package/dist/lib/auth/server.js.map +1 -0
  26. package/dist/lib/config.d.ts +33 -0
  27. package/dist/lib/config.d.ts.map +1 -0
  28. package/dist/lib/config.js +84 -0
  29. package/dist/lib/config.js.map +1 -0
  30. package/dist/lib/constants.d.ts +67 -0
  31. package/dist/lib/constants.d.ts.map +1 -0
  32. package/dist/lib/constants.js +67 -0
  33. package/dist/lib/constants.js.map +1 -0
  34. package/dist/lib/logger.d.ts +21 -0
  35. package/dist/lib/logger.d.ts.map +1 -0
  36. package/dist/lib/logger.js +77 -0
  37. package/dist/lib/logger.js.map +1 -0
  38. package/dist/lib/oauth-success.html +712 -0
  39. package/dist/lib/prompts/codex-opencode-bridge.d.ts +19 -0
  40. package/dist/lib/prompts/codex-opencode-bridge.d.ts.map +1 -0
  41. package/dist/lib/prompts/codex-opencode-bridge.js +152 -0
  42. package/dist/lib/prompts/codex-opencode-bridge.js.map +1 -0
  43. package/dist/lib/prompts/codex.d.ts +27 -0
  44. package/dist/lib/prompts/codex.d.ts.map +1 -0
  45. package/dist/lib/prompts/codex.js +241 -0
  46. package/dist/lib/prompts/codex.js.map +1 -0
  47. package/dist/lib/prompts/opencode-codex.d.ts +21 -0
  48. package/dist/lib/prompts/opencode-codex.d.ts.map +1 -0
  49. package/dist/lib/prompts/opencode-codex.js +91 -0
  50. package/dist/lib/prompts/opencode-codex.js.map +1 -0
  51. package/dist/lib/request/fetch-helpers.d.ts +73 -0
  52. package/dist/lib/request/fetch-helpers.d.ts.map +1 -0
  53. package/dist/lib/request/fetch-helpers.js +221 -0
  54. package/dist/lib/request/fetch-helpers.js.map +1 -0
  55. package/dist/lib/request/helpers/input-utils.d.ts +6 -0
  56. package/dist/lib/request/helpers/input-utils.d.ts.map +1 -0
  57. package/dist/lib/request/helpers/input-utils.js +174 -0
  58. package/dist/lib/request/helpers/input-utils.js.map +1 -0
  59. package/dist/lib/request/helpers/model-map.d.ts +28 -0
  60. package/dist/lib/request/helpers/model-map.d.ts.map +1 -0
  61. package/dist/lib/request/helpers/model-map.js +109 -0
  62. package/dist/lib/request/helpers/model-map.js.map +1 -0
  63. package/dist/lib/request/request-transformer.d.ts +93 -0
  64. package/dist/lib/request/request-transformer.d.ts.map +1 -0
  65. package/dist/lib/request/request-transformer.js +403 -0
  66. package/dist/lib/request/request-transformer.js.map +1 -0
  67. package/dist/lib/request/response-handler.d.ts +14 -0
  68. package/dist/lib/request/response-handler.d.ts.map +1 -0
  69. package/dist/lib/request/response-handler.js +88 -0
  70. package/dist/lib/request/response-handler.js.map +1 -0
  71. package/dist/lib/types.d.ts +184 -0
  72. package/dist/lib/types.d.ts.map +1 -0
  73. package/dist/lib/types.js +2 -0
  74. package/dist/lib/types.js.map +1 -0
  75. package/dist/src/plugin/accounts.d.ts +21 -0
  76. package/dist/src/plugin/accounts.d.ts.map +1 -0
  77. package/dist/src/plugin/accounts.js +53 -0
  78. package/dist/src/plugin/accounts.js.map +1 -0
  79. package/dist/src/plugin/config/schema.d.ts +38 -0
  80. package/dist/src/plugin/config/schema.d.ts.map +1 -0
  81. package/dist/src/plugin/config/schema.js +32 -0
  82. package/dist/src/plugin/config/schema.js.map +1 -0
  83. package/dist/src/plugin/storage.d.ts +15 -0
  84. package/dist/src/plugin/storage.d.ts.map +1 -0
  85. package/dist/src/plugin/storage.js +38 -0
  86. package/dist/src/plugin/storage.js.map +1 -0
  87. package/dist/src/plugin/usage.d.ts +9 -0
  88. package/dist/src/plugin/usage.d.ts.map +1 -0
  89. package/dist/src/plugin/usage.js +76 -0
  90. package/dist/src/plugin/usage.js.map +1 -0
  91. package/package.json +74 -0
  92. package/scripts/check-usage.ts +92 -0
  93. package/scripts/install-opencode-codex-auth.js +430 -0
  94. package/scripts/test-all-models.sh +259 -0
  95. package/scripts/validate-model-map.sh +97 -0
@@ -0,0 +1,239 @@
1
+ {
2
+ "$schema": "https://opencode.ai/config.json",
3
+ "plugin": [
4
+ "opencode-openai-codex-auth"
5
+ ],
6
+ "provider": {
7
+ "openai": {
8
+ "options": {
9
+ "reasoningEffort": "medium",
10
+ "reasoningSummary": "auto",
11
+ "textVerbosity": "medium",
12
+ "include": [
13
+ "reasoning.encrypted_content"
14
+ ],
15
+ "store": false
16
+ },
17
+ "models": {
18
+ "gpt-5.2": {
19
+ "name": "GPT 5.2 (OAuth)",
20
+ "limit": {
21
+ "context": 272000,
22
+ "output": 128000
23
+ },
24
+ "modalities": {
25
+ "input": [
26
+ "text",
27
+ "image"
28
+ ],
29
+ "output": [
30
+ "text"
31
+ ]
32
+ },
33
+ "variants": {
34
+ "none": {
35
+ "reasoningEffort": "none",
36
+ "reasoningSummary": "auto",
37
+ "textVerbosity": "medium"
38
+ },
39
+ "low": {
40
+ "reasoningEffort": "low",
41
+ "reasoningSummary": "auto",
42
+ "textVerbosity": "medium"
43
+ },
44
+ "medium": {
45
+ "reasoningEffort": "medium",
46
+ "reasoningSummary": "auto",
47
+ "textVerbosity": "medium"
48
+ },
49
+ "high": {
50
+ "reasoningEffort": "high",
51
+ "reasoningSummary": "detailed",
52
+ "textVerbosity": "medium"
53
+ },
54
+ "xhigh": {
55
+ "reasoningEffort": "xhigh",
56
+ "reasoningSummary": "detailed",
57
+ "textVerbosity": "medium"
58
+ }
59
+ }
60
+ },
61
+ "gpt-5.2-codex": {
62
+ "name": "GPT 5.2 Codex (OAuth)",
63
+ "limit": {
64
+ "context": 272000,
65
+ "output": 128000
66
+ },
67
+ "modalities": {
68
+ "input": [
69
+ "text",
70
+ "image"
71
+ ],
72
+ "output": [
73
+ "text"
74
+ ]
75
+ },
76
+ "variants": {
77
+ "low": {
78
+ "reasoningEffort": "low",
79
+ "reasoningSummary": "auto",
80
+ "textVerbosity": "medium"
81
+ },
82
+ "medium": {
83
+ "reasoningEffort": "medium",
84
+ "reasoningSummary": "auto",
85
+ "textVerbosity": "medium"
86
+ },
87
+ "high": {
88
+ "reasoningEffort": "high",
89
+ "reasoningSummary": "detailed",
90
+ "textVerbosity": "medium"
91
+ },
92
+ "xhigh": {
93
+ "reasoningEffort": "xhigh",
94
+ "reasoningSummary": "detailed",
95
+ "textVerbosity": "medium"
96
+ }
97
+ }
98
+ },
99
+ "gpt-5.1-codex-max": {
100
+ "name": "GPT 5.1 Codex Max (OAuth)",
101
+ "limit": {
102
+ "context": 272000,
103
+ "output": 128000
104
+ },
105
+ "modalities": {
106
+ "input": [
107
+ "text",
108
+ "image"
109
+ ],
110
+ "output": [
111
+ "text"
112
+ ]
113
+ },
114
+ "variants": {
115
+ "low": {
116
+ "reasoningEffort": "low",
117
+ "reasoningSummary": "detailed",
118
+ "textVerbosity": "medium"
119
+ },
120
+ "medium": {
121
+ "reasoningEffort": "medium",
122
+ "reasoningSummary": "detailed",
123
+ "textVerbosity": "medium"
124
+ },
125
+ "high": {
126
+ "reasoningEffort": "high",
127
+ "reasoningSummary": "detailed",
128
+ "textVerbosity": "medium"
129
+ },
130
+ "xhigh": {
131
+ "reasoningEffort": "xhigh",
132
+ "reasoningSummary": "detailed",
133
+ "textVerbosity": "medium"
134
+ }
135
+ }
136
+ },
137
+ "gpt-5.1-codex": {
138
+ "name": "GPT 5.1 Codex (OAuth)",
139
+ "limit": {
140
+ "context": 272000,
141
+ "output": 128000
142
+ },
143
+ "modalities": {
144
+ "input": [
145
+ "text",
146
+ "image"
147
+ ],
148
+ "output": [
149
+ "text"
150
+ ]
151
+ },
152
+ "variants": {
153
+ "low": {
154
+ "reasoningEffort": "low",
155
+ "reasoningSummary": "auto",
156
+ "textVerbosity": "medium"
157
+ },
158
+ "medium": {
159
+ "reasoningEffort": "medium",
160
+ "reasoningSummary": "auto",
161
+ "textVerbosity": "medium"
162
+ },
163
+ "high": {
164
+ "reasoningEffort": "high",
165
+ "reasoningSummary": "detailed",
166
+ "textVerbosity": "medium"
167
+ }
168
+ }
169
+ },
170
+ "gpt-5.1-codex-mini": {
171
+ "name": "GPT 5.1 Codex Mini (OAuth)",
172
+ "limit": {
173
+ "context": 272000,
174
+ "output": 128000
175
+ },
176
+ "modalities": {
177
+ "input": [
178
+ "text",
179
+ "image"
180
+ ],
181
+ "output": [
182
+ "text"
183
+ ]
184
+ },
185
+ "variants": {
186
+ "medium": {
187
+ "reasoningEffort": "medium",
188
+ "reasoningSummary": "auto",
189
+ "textVerbosity": "medium"
190
+ },
191
+ "high": {
192
+ "reasoningEffort": "high",
193
+ "reasoningSummary": "detailed",
194
+ "textVerbosity": "medium"
195
+ }
196
+ }
197
+ },
198
+ "gpt-5.1": {
199
+ "name": "GPT 5.1 (OAuth)",
200
+ "limit": {
201
+ "context": 272000,
202
+ "output": 128000
203
+ },
204
+ "modalities": {
205
+ "input": [
206
+ "text",
207
+ "image"
208
+ ],
209
+ "output": [
210
+ "text"
211
+ ]
212
+ },
213
+ "variants": {
214
+ "none": {
215
+ "reasoningEffort": "none",
216
+ "reasoningSummary": "auto",
217
+ "textVerbosity": "medium"
218
+ },
219
+ "low": {
220
+ "reasoningEffort": "low",
221
+ "reasoningSummary": "auto",
222
+ "textVerbosity": "low"
223
+ },
224
+ "medium": {
225
+ "reasoningEffort": "medium",
226
+ "reasoningSummary": "auto",
227
+ "textVerbosity": "medium"
228
+ },
229
+ "high": {
230
+ "reasoningEffort": "high",
231
+ "reasoningSummary": "detailed",
232
+ "textVerbosity": "high"
233
+ }
234
+ }
235
+ }
236
+ }
237
+ }
238
+ }
239
+ }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * OpenAI ChatGPT (Codex) OAuth Authentication Plugin for opencode
3
+ *
4
+ * COMPLIANCE NOTICE:
5
+ * This plugin uses OpenAI's official OAuth authentication flow (the same method
6
+ * used by OpenAI's official Codex CLI at https://github.com/openai/codex).
7
+ *
8
+ * INTENDED USE: Personal development and coding assistance with your own
9
+ * ChatGPT Plus/Pro subscription.
10
+ *
11
+ * NOT INTENDED FOR: Commercial resale, multi-user services, high-volume
12
+ * automated extraction, or any use that violates OpenAI's Terms of Service.
13
+ *
14
+ * Users are responsible for ensuring their usage complies with:
15
+ * - OpenAI Terms of Use: https://openai.com/policies/terms-of-use/
16
+ * - OpenAI Usage Policies: https://openai.com/policies/usage-policies/
17
+ *
18
+ * For production applications, use the OpenAI Platform API: https://platform.openai.com/
19
+ *
20
+ * @license MIT with Usage Disclaimer (see LICENSE file)
21
+ * @author numman-ali
22
+ * @repository https://github.com/numman-ali/opencode-openai-codex-auth
23
+ */
24
+ import type { Plugin } from "@opencode-ai/plugin";
25
+ /**
26
+ * OpenAI Codex OAuth authentication plugin for opencode
27
+ *
28
+ * This plugin enables opencode to use OpenAI's Codex backend via ChatGPT Plus/Pro
29
+ * OAuth authentication, allowing users to leverage their ChatGPT subscription
30
+ * instead of OpenAI Platform API credits.
31
+ *
32
+ * @example
33
+ * ```json
34
+ * {
35
+ * "plugin": ["opencode-openai-codex-auth"],
36
+ * "model": "openai/gpt-5-codex"
37
+ * }
38
+ * ```
39
+ */
40
+ export declare const OpenAIAuthPlugin: Plugin;
41
+ export default OpenAIAuthPlugin;
42
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAe,MAAM,qBAAqB,CAAC;AA2C/D;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,gBAAgB,EAAE,MAmU9B,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,299 @@
1
+ /**
2
+ * OpenAI ChatGPT (Codex) OAuth Authentication Plugin for opencode
3
+ *
4
+ * COMPLIANCE NOTICE:
5
+ * This plugin uses OpenAI's official OAuth authentication flow (the same method
6
+ * used by OpenAI's official Codex CLI at https://github.com/openai/codex).
7
+ *
8
+ * INTENDED USE: Personal development and coding assistance with your own
9
+ * ChatGPT Plus/Pro subscription.
10
+ *
11
+ * NOT INTENDED FOR: Commercial resale, multi-user services, high-volume
12
+ * automated extraction, or any use that violates OpenAI's Terms of Service.
13
+ *
14
+ * Users are responsible for ensuring their usage complies with:
15
+ * - OpenAI Terms of Use: https://openai.com/policies/terms-of-use/
16
+ * - OpenAI Usage Policies: https://openai.com/policies/usage-policies/
17
+ *
18
+ * For production applications, use the OpenAI Platform API: https://platform.openai.com/
19
+ *
20
+ * @license MIT with Usage Disclaimer (see LICENSE file)
21
+ * @author numman-ali
22
+ * @repository https://github.com/numman-ali/opencode-openai-codex-auth
23
+ */
24
+ import { createAuthorizationFlow, decodeJWT, exchangeAuthorizationCode, parseAuthorizationInput, REDIRECT_URI, } from "./lib/auth/auth.js";
25
+ import { openBrowserUrl } from "./lib/auth/browser.js";
26
+ import { startLocalOAuthServer } from "./lib/auth/server.js";
27
+ import { getCodexMode, getStrategy, getPidOffset, loadPluginConfig } from "./lib/config.js";
28
+ import { AUTH_LABELS, CODEX_BASE_URL, DUMMY_API_KEY, ERROR_MESSAGES, JWT_CLAIM_PATH, LOG_STAGES, PLUGIN_NAME, PROVIDER_ID, } from "./lib/constants.js";
29
+ import { logRequest, logDebug } from "./lib/logger.js";
30
+ import { createCodexHeaders, extractRequestUrl, handleErrorResponse, handleSuccessResponse, refreshAndUpdateToken, rewriteUrlForCodex, shouldRefreshToken, transformRequestForCodex, } from "./lib/request/fetch-helpers.js";
31
+ import { AccountManager } from "./src/plugin/accounts.js";
32
+ import { loadAccounts, saveAccounts } from "./src/plugin/storage.js";
33
+ import { fetchUsageBackground, loadUsageCache, saveUsageCache, selectAccountByUsage, } from "./src/plugin/usage.js";
34
+ /**
35
+ * OpenAI Codex OAuth authentication plugin for opencode
36
+ *
37
+ * This plugin enables opencode to use OpenAI's Codex backend via ChatGPT Plus/Pro
38
+ * OAuth authentication, allowing users to leverage their ChatGPT subscription
39
+ * instead of OpenAI Platform API credits.
40
+ *
41
+ * @example
42
+ * ```json
43
+ * {
44
+ * "plugin": ["opencode-openai-codex-auth"],
45
+ * "model": "openai/gpt-5-codex"
46
+ * }
47
+ * ```
48
+ */
49
+ export const OpenAIAuthPlugin = async ({ client }) => {
50
+ const buildManualOAuthFlow = (pkce, url) => ({
51
+ url,
52
+ method: "code",
53
+ instructions: AUTH_LABELS.INSTRUCTIONS_MANUAL,
54
+ callback: async (input) => {
55
+ const parsed = parseAuthorizationInput(input);
56
+ if (!parsed.code) {
57
+ return { type: "failed" };
58
+ }
59
+ const tokens = await exchangeAuthorizationCode(parsed.code, pkce.verifier, REDIRECT_URI);
60
+ return tokens?.type === "success" ? tokens : { type: "failed" };
61
+ },
62
+ });
63
+ return {
64
+ auth: {
65
+ provider: PROVIDER_ID,
66
+ /**
67
+ * Loader function that configures OAuth authentication and request handling
68
+ *
69
+ * This function:
70
+ * 1. Validates OAuth authentication
71
+ * 2. Extracts ChatGPT account ID from access token
72
+ * 3. Loads user configuration from opencode.json
73
+ * 4. Fetches Codex system instructions from GitHub (cached)
74
+ * 5. Returns SDK configuration with custom fetch implementation
75
+ *
76
+ * @param getAuth - Function to retrieve current auth state
77
+ * @param provider - Provider configuration from opencode.json
78
+ * @returns SDK configuration object or empty object for non-OAuth auth
79
+ */
80
+ async loader(getAuth, provider) {
81
+ const auth = await getAuth();
82
+ // Only handle OAuth auth type, skip API key auth
83
+ if (auth.type !== "oauth") {
84
+ return {};
85
+ }
86
+ // Extract ChatGPT account ID from JWT access token
87
+ const decoded = decodeJWT(auth.access);
88
+ const accountId = decoded?.[JWT_CLAIM_PATH]?.chatgpt_account_id;
89
+ if (!accountId) {
90
+ logDebug(`[${PLUGIN_NAME}] ${ERROR_MESSAGES.NO_ACCOUNT_ID} (skipping plugin)`);
91
+ return {};
92
+ }
93
+ // Extract user configuration (global + per-model options)
94
+ const providerConfig = provider;
95
+ const userConfig = {
96
+ global: providerConfig?.options || {},
97
+ models: providerConfig?.models || {},
98
+ };
99
+ // Load plugin configuration and determine CODEX_MODE
100
+ // Priority: CODEX_MODE env var > config file > default (true)
101
+ const pluginConfig = loadPluginConfig();
102
+ const codexMode = getCodexMode(pluginConfig);
103
+ // Initialize AccountManager with current OAuth account
104
+ const accountManager = new AccountManager();
105
+ const storedAccounts = await loadAccounts();
106
+ const pid = process.pid;
107
+ const usageCache = loadUsageCache(pid) ?? { accounts: {} };
108
+ // 사용량 캐시를 프로세스 단위로 초기화합니다.
109
+ saveUsageCache(pid, usageCache);
110
+ // Strategy state - initialized once per session
111
+ const strategy = getStrategy(pluginConfig);
112
+ const pidOffsetEnabled = getPidOffset(pluginConfig);
113
+ // Current account index for sticky strategy (module-level state)
114
+ let currentAccountIndex = null;
115
+ let pidOffsetApplied = false;
116
+ // Add current OAuth account first
117
+ accountManager.addAccount({
118
+ id: accountId,
119
+ email: decoded?.email || "",
120
+ accessToken: auth.access,
121
+ refreshToken: auth.refresh,
122
+ chatgptAccountId: accountId,
123
+ enabled: true,
124
+ });
125
+ // Add previously stored accounts (excluding current to avoid duplicates)
126
+ for (const account of storedAccounts) {
127
+ if (account.id !== accountId) {
128
+ accountManager.addAccount(account);
129
+ }
130
+ }
131
+ logDebug(`[${PLUGIN_NAME}] Loaded ${accountManager.getAccountCount()} account(s)`);
132
+ // Return SDK configuration
133
+ return {
134
+ apiKey: DUMMY_API_KEY,
135
+ baseURL: CODEX_BASE_URL,
136
+ /**
137
+ * Custom fetch implementation for Codex API
138
+ *
139
+ * Handles:
140
+ * - Token refresh when expired
141
+ * - URL rewriting for Codex backend
142
+ * - Request body transformation
143
+ * - OAuth header injection
144
+ * - SSE to JSON conversion for non-tool requests
145
+ * - Error handling and logging
146
+ *
147
+ * @param input - Request URL or Request object
148
+ * @param init - Request options
149
+ * @returns Response from Codex API
150
+ */
151
+ async fetch(input, init) {
152
+ const MAX_RETRIES = accountManager.getAccountCount();
153
+ let lastError = null;
154
+ for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
155
+ let currentAuth = await getAuth();
156
+ // 사용 가능한 계정 목록을 안전하게 조회합니다.
157
+ const accounts = (accountManager
158
+ .getAvailableAccounts?.() ?? []);
159
+ // Strategy-based account selection
160
+ let selectedIndex;
161
+ if (strategy === "round-robin") {
162
+ selectedIndex = selectAccountByUsage(accounts, usageCache);
163
+ }
164
+ else {
165
+ if (currentAccountIndex === null || currentAccountIndex >= accounts.length) {
166
+ selectedIndex = selectAccountByUsage(accounts, usageCache);
167
+ if (pidOffsetEnabled && !pidOffsetApplied && accounts.length > 1) {
168
+ selectedIndex = (selectedIndex + (process.pid % accounts.length)) % accounts.length;
169
+ pidOffsetApplied = true;
170
+ }
171
+ currentAccountIndex = selectedIndex;
172
+ }
173
+ else {
174
+ selectedIndex = currentAccountIndex;
175
+ }
176
+ }
177
+ logDebug(`[${PLUGIN_NAME}] Strategy: ${strategy}, Selected account index: ${selectedIndex}`);
178
+ const currentAccount = accounts[selectedIndex] ?? null;
179
+ if (!currentAccount) {
180
+ throw new Error("No available Codex accounts");
181
+ }
182
+ if (shouldRefreshToken(currentAuth)) {
183
+ currentAuth = await refreshAndUpdateToken(currentAuth, client);
184
+ if (currentAuth.type === "oauth") {
185
+ currentAccount.accessToken = currentAuth.access;
186
+ currentAccount.refreshToken = currentAuth.refresh;
187
+ }
188
+ }
189
+ const originalUrl = extractRequestUrl(input);
190
+ const url = rewriteUrlForCodex(originalUrl);
191
+ const originalBody = init?.body ? JSON.parse(init.body) : {};
192
+ const isStreaming = originalBody.stream === true;
193
+ const transformation = await transformRequestForCodex(init, url, userConfig, codexMode);
194
+ const requestInit = transformation?.updatedInit ?? init;
195
+ const headers = createCodexHeaders(requestInit, currentAccount.chatgptAccountId, currentAccount.accessToken, {
196
+ model: transformation?.body.model,
197
+ promptCacheKey: transformation?.body?.prompt_cache_key,
198
+ });
199
+ const response = await fetch(url, {
200
+ ...requestInit,
201
+ headers,
202
+ });
203
+ logRequest(LOG_STAGES.RESPONSE, {
204
+ status: response.status,
205
+ ok: response.ok,
206
+ statusText: response.statusText,
207
+ headers: Object.fromEntries(response.headers.entries()),
208
+ });
209
+ if (response.status === 429) {
210
+ const retryAfter = response.headers.get("retry-after");
211
+ const resetTime = retryAfter
212
+ ? Date.now() + parseInt(retryAfter, 10) * 1000
213
+ : Date.now() + 60000;
214
+ accountManager.updateRateLimitResetTime(currentAccount.id, resetTime);
215
+ accountManager.rotateAccount();
216
+ if (strategy === "sticky") {
217
+ currentAccountIndex = null;
218
+ }
219
+ await saveAccounts(accountManager["accounts"] || []);
220
+ if (attempt < MAX_RETRIES - 1) {
221
+ logDebug(`[${PLUGIN_NAME}] 429 rate limit, rotating to next account`);
222
+ continue;
223
+ }
224
+ lastError = new Error("All accounts are rate-limited");
225
+ break;
226
+ }
227
+ if (!response.ok) {
228
+ return await handleErrorResponse(response);
229
+ }
230
+ const successResponse = await handleSuccessResponse(response, isStreaming);
231
+ // 성공 응답 후 백그라운드에서 사용량 캐시를 갱신합니다.
232
+ fetchUsageBackground(currentAccount.accessToken, currentAccount.id, pid);
233
+ return successResponse;
234
+ }
235
+ throw lastError || new Error("All retry attempts failed");
236
+ },
237
+ };
238
+ },
239
+ methods: [
240
+ {
241
+ label: AUTH_LABELS.OAUTH,
242
+ type: "oauth",
243
+ /**
244
+ * OAuth authorization flow
245
+ *
246
+ * Steps:
247
+ * 1. Generate PKCE challenge and state for security
248
+ * 2. Start local OAuth callback server on port 1455
249
+ * 3. Open browser to OpenAI authorization page
250
+ * 4. Wait for user to complete login
251
+ * 5. Exchange authorization code for tokens
252
+ *
253
+ * @returns Authorization flow configuration
254
+ */
255
+ authorize: async () => {
256
+ const { pkce, state, url } = await createAuthorizationFlow();
257
+ const serverInfo = await startLocalOAuthServer({ state });
258
+ // Attempt to open browser automatically
259
+ openBrowserUrl(url);
260
+ if (!serverInfo.ready) {
261
+ serverInfo.close();
262
+ return buildManualOAuthFlow(pkce, url);
263
+ }
264
+ return {
265
+ url,
266
+ method: "auto",
267
+ instructions: AUTH_LABELS.INSTRUCTIONS,
268
+ callback: async () => {
269
+ const result = await serverInfo.waitForCode(state);
270
+ serverInfo.close();
271
+ if (!result) {
272
+ return { type: "failed" };
273
+ }
274
+ const tokens = await exchangeAuthorizationCode(result.code, pkce.verifier, REDIRECT_URI);
275
+ return tokens?.type === "success"
276
+ ? tokens
277
+ : { type: "failed" };
278
+ },
279
+ };
280
+ },
281
+ },
282
+ {
283
+ label: AUTH_LABELS.OAUTH_MANUAL,
284
+ type: "oauth",
285
+ authorize: async () => {
286
+ const { pkce, url } = await createAuthorizationFlow();
287
+ return buildManualOAuthFlow(pkce, url);
288
+ },
289
+ },
290
+ {
291
+ label: AUTH_LABELS.API_KEY,
292
+ type: "api",
293
+ },
294
+ ],
295
+ },
296
+ };
297
+ };
298
+ export default OpenAIAuthPlugin;
299
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AA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,MAAM,MAAM,GAAG,MAAM,yBAAyB,CAC7C,MAAM,CAAC,IAAI,EACX,IAAI,CAAC,QAAQ,EACb,YAAY,CACZ,CAAC;gCAEF,OAAO,MAAM,EAAE,IAAI,KAAK,SAAS;oCAChC,CAAC,CAAC,MAAM;oCACR,CAAC,CAAC,EAAE,IAAI,EAAE,QAAiB,EAAE,CAAC;4BAChC,CAAC;yBACD,CAAC;oBACH,CAAC;iBACA;gBACD;oBACC,KAAK,EAAE,WAAW,CAAC,YAAY;oBAC/B,IAAI,EAAE,OAAgB;oBACtB,SAAS,EAAE,KAAK,IAAI,EAAE;wBACrB,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,MAAM,uBAAuB,EAAE,CAAC;wBACtD,OAAO,oBAAoB,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;oBACxC,CAAC;iBACD;gBACD;oBACC,KAAK,EAAE,WAAW,CAAC,OAAO;oBAC1B,IAAI,EAAE,KAAc;iBACpB;aACF;SACD;KACD,CAAC;AACH,CAAC,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
@@ -0,0 +1,43 @@
1
+ import type { AuthorizationFlow, TokenResult, ParsedAuthInput, JWTPayload } from "../types.js";
2
+ export declare const CLIENT_ID = "app_EMoamEEZ73f0CkXaXp7hrann";
3
+ export declare const AUTHORIZE_URL = "https://auth.openai.com/oauth/authorize";
4
+ export declare const TOKEN_URL = "https://auth.openai.com/oauth/token";
5
+ export declare const REDIRECT_URI = "http://localhost:1455/auth/callback";
6
+ export declare const SCOPE = "openid profile email offline_access";
7
+ /**
8
+ * Generate a random state value for OAuth flow
9
+ * @returns Random hex string
10
+ */
11
+ export declare function createState(): string;
12
+ /**
13
+ * Parse authorization code and state from user input
14
+ * @param input - User input (URL, code#state, or just code)
15
+ * @returns Parsed authorization data
16
+ */
17
+ export declare function parseAuthorizationInput(input: string): ParsedAuthInput;
18
+ /**
19
+ * Exchange authorization code for access and refresh tokens
20
+ * @param code - Authorization code from OAuth flow
21
+ * @param verifier - PKCE verifier
22
+ * @param redirectUri - OAuth redirect URI
23
+ * @returns Token result
24
+ */
25
+ export declare function exchangeAuthorizationCode(code: string, verifier: string, redirectUri?: string): Promise<TokenResult>;
26
+ /**
27
+ * Decode a JWT token to extract payload
28
+ * @param token - JWT token to decode
29
+ * @returns Decoded payload or null if invalid
30
+ */
31
+ export declare function decodeJWT(token: string): JWTPayload | null;
32
+ /**
33
+ * Refresh access token using refresh token
34
+ * @param refreshToken - Refresh token
35
+ * @returns Token result
36
+ */
37
+ export declare function refreshAccessToken(refreshToken: string): Promise<TokenResult>;
38
+ /**
39
+ * Create OAuth authorization flow
40
+ * @returns Authorization flow details
41
+ */
42
+ export declare function createAuthorizationFlow(): Promise<AuthorizationFlow>;
43
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../lib/auth/auth.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAY,iBAAiB,EAAE,WAAW,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzG,eAAO,MAAM,SAAS,iCAAiC,CAAC;AACxD,eAAO,MAAM,aAAa,4CAA4C,CAAC;AACvE,eAAO,MAAM,SAAS,wCAAwC,CAAC;AAC/D,eAAO,MAAM,YAAY,wCAAwC,CAAC;AAClE,eAAO,MAAM,KAAK,wCAAwC,CAAC;AAE3D;;;GAGG;AACH,wBAAgB,WAAW,IAAI,MAAM,CAEpC;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG,eAAe,CAwBtE;AAED;;;;;;GAMG;AACH,wBAAsB,yBAAyB,CAC9C,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,WAAW,GAAE,MAAqB,GAChC,OAAO,CAAC,WAAW,CAAC,CAoCtB;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI,CAU1D;AAED;;;;GAIG;AACH,wBAAsB,kBAAkB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAkDnF;AAED;;;GAGG;AACH,wBAAsB,uBAAuB,IAAI,OAAO,CAAC,iBAAiB,CAAC,CAiB1E"}