codex-multi-auth 2.1.13-beta.1 → 2.1.13-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 (48) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +415 -415
  3. package/assets/codex-multi-auth-icon.svg +39 -39
  4. package/assets/readme-hero.svg +31 -31
  5. package/config/README.md +29 -29
  6. package/config/codex-legacy.json +571 -571
  7. package/config/codex-modern.json +258 -258
  8. package/config/minimal-codex.json +15 -15
  9. package/config/schema/config.schema.json +20 -20
  10. package/dist/lib/config.d.ts +26 -0
  11. package/dist/lib/config.d.ts.map +1 -1
  12. package/dist/lib/config.js +42 -0
  13. package/dist/lib/config.js.map +1 -1
  14. package/dist/lib/context-overflow.js +10 -10
  15. package/dist/lib/oauth-success.html +125 -125
  16. package/dist/lib/prompts/codex-host-bridge.js +138 -138
  17. package/dist/lib/prompts/codex.js +79 -79
  18. package/dist/lib/runtime-rotation-proxy.d.ts +2 -0
  19. package/dist/lib/runtime-rotation-proxy.d.ts.map +1 -1
  20. package/dist/lib/runtime-rotation-proxy.js +136 -8
  21. package/dist/lib/runtime-rotation-proxy.js.map +1 -1
  22. package/dist/lib/schemas.d.ts +2 -0
  23. package/dist/lib/schemas.d.ts.map +1 -1
  24. package/dist/lib/schemas.js +2 -0
  25. package/dist/lib/schemas.js.map +1 -1
  26. package/node_modules/@codex-ai/plugin/dist/index.d.ts +2 -2
  27. package/node_modules/@codex-ai/plugin/dist/index.js +2 -2
  28. package/node_modules/@codex-ai/plugin/dist/tool.d.ts +42 -42
  29. package/node_modules/@codex-ai/plugin/dist/tool.js +29 -29
  30. package/node_modules/@codex-ai/plugin/package.json +9 -9
  31. package/package.json +193 -193
  32. package/scripts/codex-app-launcher.js +653 -653
  33. package/scripts/codex-app-router.js +322 -322
  34. package/scripts/codex-bin-resolver.js +254 -254
  35. package/scripts/codex-multi-auth.js +59 -59
  36. package/scripts/codex-routing.js +56 -56
  37. package/scripts/codex.js +4275 -4275
  38. package/scripts/install-codex-auth-utils.js +206 -206
  39. package/scripts/postinstall.js +343 -343
  40. package/scripts/preuninstall.js +254 -254
  41. package/vendor/codex-ai-plugin/dist/index.d.ts +2 -2
  42. package/vendor/codex-ai-plugin/dist/index.js +2 -2
  43. package/vendor/codex-ai-plugin/dist/tool.d.ts +42 -42
  44. package/vendor/codex-ai-plugin/dist/tool.js +29 -29
  45. package/vendor/codex-ai-plugin/package.json +9 -9
  46. package/vendor/codex-ai-sdk/dist/index.d.ts +4 -4
  47. package/vendor/codex-ai-sdk/dist/index.js +2 -2
  48. package/vendor/codex-ai-sdk/package.json +8 -8
@@ -1,206 +1,206 @@
1
- // @ts-check
2
-
3
- import { rename as fsRename } from "node:fs/promises";
4
- import { homedir } from "node:os";
5
- import { join } from "node:path";
6
- import process from "node:process";
7
-
8
- const PLUGIN_NAME = "codex-multi-auth";
9
-
10
- const TRUE_VALUES = new Set(["1", "true", "yes"]);
11
- const FALSE_VALUES = new Set(["0", "false", "no"]);
12
- const CI_ENV_KEYS = [
13
- "CI",
14
- "GITHUB_ACTIONS",
15
- "GITLAB_CI",
16
- "CIRCLECI",
17
- "BUILDKITE",
18
- "TF_BUILD",
19
- "TEAMCITY_VERSION",
20
- "JENKINS_URL",
21
- "TRAVIS",
22
- "APPVEYOR",
23
- "BITBUCKET_BUILD_NUMBER",
24
- ];
25
-
26
- /** @param {string | undefined} value */
27
- function readOptionalBooleanValue(value) {
28
- if (value === undefined || value.trim().length === 0) return null;
29
- const normalized = value.trim().toLowerCase();
30
- if (TRUE_VALUES.has(normalized)) return true;
31
- if (FALSE_VALUES.has(normalized)) return false;
32
- return null;
33
- }
34
-
35
- /** @param {NodeJS.ProcessEnv} env @param {string} key */
36
- function isEnabledEnvFlag(env, key) {
37
- const value = env[key];
38
- if (value === undefined || value.trim().length === 0) return false;
39
- return readOptionalBooleanValue(value) !== false;
40
- }
41
-
42
- /** @param {NodeJS.ProcessEnv} [env] */
43
- export function isCiEnvironment(env = process.env) {
44
- if (readOptionalBooleanValue(env.npm_config_ignore_scripts) === true) return true;
45
- return CI_ENV_KEYS.some((key) => isEnabledEnvFlag(env, key));
46
- }
47
- export const FILE_RETRY_CODES = new Set([
48
- "EBUSY",
49
- "EPERM",
50
- "EAGAIN",
51
- "ENOTEMPTY",
52
- "EACCES",
53
- ]);
54
- export const FILE_RETRY_MAX_ATTEMPTS = 6;
55
- export const FILE_RETRY_BASE_DELAY_MS = 25;
56
- export const FILE_RETRY_JITTER_MS = 20;
57
-
58
- /**
59
- * @param {NodeJS.Platform} [platform]
60
- * @param {NodeJS.ProcessEnv} [env]
61
- * @param {string} [home]
62
- */
63
- export function resolveInstallPaths(
64
- platform = process.platform,
65
- env = process.env,
66
- home = homedir(),
67
- ) {
68
- const isWindows = platform === "win32";
69
- const appData = (env.APPDATA ?? "").trim();
70
- const localAppData = (env.LOCALAPPDATA ?? appData).trim();
71
- const configBase = isWindows
72
- ? appData || join(home, "AppData", "Roaming")
73
- : join(home, ".config");
74
- const cacheBase = isWindows
75
- ? localAppData || join(home, "AppData", "Local")
76
- : join(home, ".cache");
77
- const configDir = join(configBase, "Codex");
78
- const configPath = join(configDir, "Codex.json");
79
- const cacheDir = join(cacheBase, "Codex");
80
- return {
81
- configDir,
82
- configPath,
83
- cacheDir,
84
- cacheNodeModules: join(cacheDir, "node_modules", PLUGIN_NAME),
85
- cacheBunLock: join(cacheDir, "bun.lock"),
86
- cachePackageJson: join(cacheDir, "package.json"),
87
- };
88
- }
89
-
90
- /** @param {unknown} list */
91
- export function removePluginFromList(list) {
92
- const entries = Array.isArray(list) ? list.filter(Boolean) : [];
93
- return entries.filter((entry) => {
94
- if (typeof entry !== "string") return true;
95
- return entry !== PLUGIN_NAME && !entry.startsWith(`${PLUGIN_NAME}@`);
96
- });
97
- }
98
-
99
- /** @param {unknown} list */
100
- export function normalizePluginList(list) {
101
- const entries = Array.isArray(list) ? list.filter(Boolean) : [];
102
- const filtered = entries.filter((entry) => {
103
- if (typeof entry !== "string") return true;
104
- return entry !== PLUGIN_NAME && !entry.startsWith(`${PLUGIN_NAME}@`);
105
- });
106
- const deduped = [];
107
- const seen = new Set();
108
- for (const entry of filtered) {
109
- const key =
110
- typeof entry === "string" ? `s:${entry}` : `j:${JSON.stringify(entry)}`;
111
- if (seen.has(key)) continue;
112
- seen.add(key);
113
- deduped.push(entry);
114
- }
115
- return [...deduped, PLUGIN_NAME];
116
- }
117
-
118
- /** @param {number} ms */
119
- function sleep(ms) {
120
- // Keep this helper local so installer scripts remain standalone and do not depend on lib/.
121
- return new Promise((resolve) => {
122
- setTimeout(resolve, ms);
123
- });
124
- }
125
-
126
- /** @param {unknown} error */
127
- function shouldRetryFileOperation(error) {
128
- const fileError = /** @type {NodeJS.ErrnoException | undefined} */ (error);
129
- return (
130
- fileError instanceof Error &&
131
- typeof fileError.code === "string" &&
132
- FILE_RETRY_CODES.has(fileError.code)
133
- );
134
- }
135
-
136
- /** @template T @param {() => Promise<T>} operation */
137
- export async function withFileOperationRetry(operation) {
138
- for (let attempt = 1; ; attempt += 1) {
139
- try {
140
- return await operation();
141
- } catch (error) {
142
- if (
143
- !shouldRetryFileOperation(error) ||
144
- attempt >= FILE_RETRY_MAX_ATTEMPTS
145
- ) {
146
- throw error;
147
- }
148
-
149
- const jitter = Math.floor(Math.random() * FILE_RETRY_JITTER_MS);
150
- const delayMs = FILE_RETRY_BASE_DELAY_MS * 2 ** (attempt - 1) + jitter;
151
- await sleep(delayMs);
152
- }
153
- }
154
- }
155
-
156
- /**
157
- * @param {string} sourcePath
158
- * @param {string} targetPath
159
- * @param {{
160
- * rename?: (sourcePath: string, targetPath: string) => Promise<void>,
161
- * log?: (message: string) => void,
162
- * maxRetries?: number,
163
- * baseDelayMs?: number,
164
- * jitterMs?: number,
165
- * random?: () => number,
166
- * sleep?: (ms: number) => Promise<void>,
167
- * }} [options]
168
- */
169
- export async function renameWithRetry(sourcePath, targetPath, options = {}) {
170
- const {
171
- rename = fsRename,
172
- log = () => {},
173
- maxRetries = FILE_RETRY_MAX_ATTEMPTS,
174
- baseDelayMs = FILE_RETRY_BASE_DELAY_MS,
175
- jitterMs = FILE_RETRY_JITTER_MS,
176
- random = Math.random,
177
- sleep: sleepImpl = sleep,
178
- } = options;
179
-
180
- if (!Number.isInteger(maxRetries) || maxRetries < 1) {
181
- throw new RangeError("maxRetries must be an integer >= 1");
182
- }
183
-
184
- for (let attempt = 0; attempt < maxRetries; attempt += 1) {
185
- try {
186
- await rename(sourcePath, targetPath);
187
- return;
188
- } catch (error) {
189
- const code =
190
- error && typeof error === "object" && "code" in error
191
- ? error.code
192
- : undefined;
193
- const isRetryable =
194
- typeof code === "string" && FILE_RETRY_CODES.has(code);
195
- if (!isRetryable || attempt === maxRetries - 1) {
196
- throw error;
197
- }
198
- const delayMs =
199
- baseDelayMs * 2 ** attempt + Math.floor(random() * jitterMs);
200
- log(
201
- `Retrying atomic rename (${attempt + 1}/${maxRetries}) code=${code ?? "unknown"} source=${sourcePath} target=${targetPath} delayMs=${delayMs}`,
202
- );
203
- await sleepImpl(delayMs);
204
- }
205
- }
206
- }
1
+ // @ts-check
2
+
3
+ import { rename as fsRename } from "node:fs/promises";
4
+ import { homedir } from "node:os";
5
+ import { join } from "node:path";
6
+ import process from "node:process";
7
+
8
+ const PLUGIN_NAME = "codex-multi-auth";
9
+
10
+ const TRUE_VALUES = new Set(["1", "true", "yes"]);
11
+ const FALSE_VALUES = new Set(["0", "false", "no"]);
12
+ const CI_ENV_KEYS = [
13
+ "CI",
14
+ "GITHUB_ACTIONS",
15
+ "GITLAB_CI",
16
+ "CIRCLECI",
17
+ "BUILDKITE",
18
+ "TF_BUILD",
19
+ "TEAMCITY_VERSION",
20
+ "JENKINS_URL",
21
+ "TRAVIS",
22
+ "APPVEYOR",
23
+ "BITBUCKET_BUILD_NUMBER",
24
+ ];
25
+
26
+ /** @param {string | undefined} value */
27
+ function readOptionalBooleanValue(value) {
28
+ if (value === undefined || value.trim().length === 0) return null;
29
+ const normalized = value.trim().toLowerCase();
30
+ if (TRUE_VALUES.has(normalized)) return true;
31
+ if (FALSE_VALUES.has(normalized)) return false;
32
+ return null;
33
+ }
34
+
35
+ /** @param {NodeJS.ProcessEnv} env @param {string} key */
36
+ function isEnabledEnvFlag(env, key) {
37
+ const value = env[key];
38
+ if (value === undefined || value.trim().length === 0) return false;
39
+ return readOptionalBooleanValue(value) !== false;
40
+ }
41
+
42
+ /** @param {NodeJS.ProcessEnv} [env] */
43
+ export function isCiEnvironment(env = process.env) {
44
+ if (readOptionalBooleanValue(env.npm_config_ignore_scripts) === true) return true;
45
+ return CI_ENV_KEYS.some((key) => isEnabledEnvFlag(env, key));
46
+ }
47
+ export const FILE_RETRY_CODES = new Set([
48
+ "EBUSY",
49
+ "EPERM",
50
+ "EAGAIN",
51
+ "ENOTEMPTY",
52
+ "EACCES",
53
+ ]);
54
+ export const FILE_RETRY_MAX_ATTEMPTS = 6;
55
+ export const FILE_RETRY_BASE_DELAY_MS = 25;
56
+ export const FILE_RETRY_JITTER_MS = 20;
57
+
58
+ /**
59
+ * @param {NodeJS.Platform} [platform]
60
+ * @param {NodeJS.ProcessEnv} [env]
61
+ * @param {string} [home]
62
+ */
63
+ export function resolveInstallPaths(
64
+ platform = process.platform,
65
+ env = process.env,
66
+ home = homedir(),
67
+ ) {
68
+ const isWindows = platform === "win32";
69
+ const appData = (env.APPDATA ?? "").trim();
70
+ const localAppData = (env.LOCALAPPDATA ?? appData).trim();
71
+ const configBase = isWindows
72
+ ? appData || join(home, "AppData", "Roaming")
73
+ : join(home, ".config");
74
+ const cacheBase = isWindows
75
+ ? localAppData || join(home, "AppData", "Local")
76
+ : join(home, ".cache");
77
+ const configDir = join(configBase, "Codex");
78
+ const configPath = join(configDir, "Codex.json");
79
+ const cacheDir = join(cacheBase, "Codex");
80
+ return {
81
+ configDir,
82
+ configPath,
83
+ cacheDir,
84
+ cacheNodeModules: join(cacheDir, "node_modules", PLUGIN_NAME),
85
+ cacheBunLock: join(cacheDir, "bun.lock"),
86
+ cachePackageJson: join(cacheDir, "package.json"),
87
+ };
88
+ }
89
+
90
+ /** @param {unknown} list */
91
+ export function removePluginFromList(list) {
92
+ const entries = Array.isArray(list) ? list.filter(Boolean) : [];
93
+ return entries.filter((entry) => {
94
+ if (typeof entry !== "string") return true;
95
+ return entry !== PLUGIN_NAME && !entry.startsWith(`${PLUGIN_NAME}@`);
96
+ });
97
+ }
98
+
99
+ /** @param {unknown} list */
100
+ export function normalizePluginList(list) {
101
+ const entries = Array.isArray(list) ? list.filter(Boolean) : [];
102
+ const filtered = entries.filter((entry) => {
103
+ if (typeof entry !== "string") return true;
104
+ return entry !== PLUGIN_NAME && !entry.startsWith(`${PLUGIN_NAME}@`);
105
+ });
106
+ const deduped = [];
107
+ const seen = new Set();
108
+ for (const entry of filtered) {
109
+ const key =
110
+ typeof entry === "string" ? `s:${entry}` : `j:${JSON.stringify(entry)}`;
111
+ if (seen.has(key)) continue;
112
+ seen.add(key);
113
+ deduped.push(entry);
114
+ }
115
+ return [...deduped, PLUGIN_NAME];
116
+ }
117
+
118
+ /** @param {number} ms */
119
+ function sleep(ms) {
120
+ // Keep this helper local so installer scripts remain standalone and do not depend on lib/.
121
+ return new Promise((resolve) => {
122
+ setTimeout(resolve, ms);
123
+ });
124
+ }
125
+
126
+ /** @param {unknown} error */
127
+ function shouldRetryFileOperation(error) {
128
+ const fileError = /** @type {NodeJS.ErrnoException | undefined} */ (error);
129
+ return (
130
+ fileError instanceof Error &&
131
+ typeof fileError.code === "string" &&
132
+ FILE_RETRY_CODES.has(fileError.code)
133
+ );
134
+ }
135
+
136
+ /** @template T @param {() => Promise<T>} operation */
137
+ export async function withFileOperationRetry(operation) {
138
+ for (let attempt = 1; ; attempt += 1) {
139
+ try {
140
+ return await operation();
141
+ } catch (error) {
142
+ if (
143
+ !shouldRetryFileOperation(error) ||
144
+ attempt >= FILE_RETRY_MAX_ATTEMPTS
145
+ ) {
146
+ throw error;
147
+ }
148
+
149
+ const jitter = Math.floor(Math.random() * FILE_RETRY_JITTER_MS);
150
+ const delayMs = FILE_RETRY_BASE_DELAY_MS * 2 ** (attempt - 1) + jitter;
151
+ await sleep(delayMs);
152
+ }
153
+ }
154
+ }
155
+
156
+ /**
157
+ * @param {string} sourcePath
158
+ * @param {string} targetPath
159
+ * @param {{
160
+ * rename?: (sourcePath: string, targetPath: string) => Promise<void>,
161
+ * log?: (message: string) => void,
162
+ * maxRetries?: number,
163
+ * baseDelayMs?: number,
164
+ * jitterMs?: number,
165
+ * random?: () => number,
166
+ * sleep?: (ms: number) => Promise<void>,
167
+ * }} [options]
168
+ */
169
+ export async function renameWithRetry(sourcePath, targetPath, options = {}) {
170
+ const {
171
+ rename = fsRename,
172
+ log = () => {},
173
+ maxRetries = FILE_RETRY_MAX_ATTEMPTS,
174
+ baseDelayMs = FILE_RETRY_BASE_DELAY_MS,
175
+ jitterMs = FILE_RETRY_JITTER_MS,
176
+ random = Math.random,
177
+ sleep: sleepImpl = sleep,
178
+ } = options;
179
+
180
+ if (!Number.isInteger(maxRetries) || maxRetries < 1) {
181
+ throw new RangeError("maxRetries must be an integer >= 1");
182
+ }
183
+
184
+ for (let attempt = 0; attempt < maxRetries; attempt += 1) {
185
+ try {
186
+ await rename(sourcePath, targetPath);
187
+ return;
188
+ } catch (error) {
189
+ const code =
190
+ error && typeof error === "object" && "code" in error
191
+ ? error.code
192
+ : undefined;
193
+ const isRetryable =
194
+ typeof code === "string" && FILE_RETRY_CODES.has(code);
195
+ if (!isRetryable || attempt === maxRetries - 1) {
196
+ throw error;
197
+ }
198
+ const delayMs =
199
+ baseDelayMs * 2 ** attempt + Math.floor(random() * jitterMs);
200
+ log(
201
+ `Retrying atomic rename (${attempt + 1}/${maxRetries}) code=${code ?? "unknown"} source=${sourcePath} target=${targetPath} delayMs=${delayMs}`,
202
+ );
203
+ await sleepImpl(delayMs);
204
+ }
205
+ }
206
+ }