opencode-openai-codex-auth-multi 4.3.0-multiaccount.1 → 4.3.1
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.
- package/LICENSE +37 -37
- package/README.md +461 -79
- package/assets/opencode-logo-ornate-dark.svg +18 -18
- package/assets/readme-hero.svg +31 -31
- package/config/README.md +98 -98
- package/config/minimal-opencode.json +11 -11
- package/config/opencode-legacy.json +568 -568
- package/config/opencode-modern.json +236 -236
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +368 -133
- package/dist/index.js.map +1 -1
- package/dist/lib/accounts.d.ts +78 -11
- package/dist/lib/accounts.d.ts.map +1 -1
- package/dist/lib/accounts.js +303 -66
- package/dist/lib/accounts.js.map +1 -1
- package/dist/lib/auth/auth.d.ts.map +1 -1
- package/dist/lib/auth/auth.js +19 -12
- package/dist/lib/auth/auth.js.map +1 -1
- package/dist/lib/auth/browser.d.ts.map +1 -1
- package/dist/lib/auth/browser.js +9 -2
- package/dist/lib/auth/browser.js.map +1 -1
- package/dist/lib/auth/server.d.ts.map +1 -1
- package/dist/lib/auth/server.js +11 -4
- package/dist/lib/auth/server.js.map +1 -1
- package/dist/lib/cli.d.ts +1 -0
- package/dist/lib/cli.d.ts.map +1 -1
- package/dist/lib/cli.js +10 -6
- package/dist/lib/cli.js.map +1 -1
- package/dist/lib/config.d.ts +5 -7
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +49 -6
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/constants.d.ts +7 -0
- package/dist/lib/constants.d.ts.map +1 -1
- package/dist/lib/constants.js +7 -0
- package/dist/lib/constants.js.map +1 -1
- package/dist/lib/index.d.ts +13 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +13 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/oauth-success.html +712 -712
- package/dist/lib/prompts/codex-opencode-bridge.js +121 -121
- package/dist/lib/prompts/codex.d.ts +5 -0
- package/dist/lib/prompts/codex.d.ts.map +1 -1
- package/dist/lib/prompts/codex.js +114 -93
- package/dist/lib/prompts/codex.js.map +1 -1
- package/dist/lib/request/fetch-helpers.d.ts +2 -3
- package/dist/lib/request/fetch-helpers.d.ts.map +1 -1
- package/dist/lib/request/fetch-helpers.js +24 -27
- package/dist/lib/request/fetch-helpers.js.map +1 -1
- package/dist/lib/request/rate-limit-backoff.d.ts +13 -0
- package/dist/lib/request/rate-limit-backoff.d.ts.map +1 -0
- package/dist/lib/request/rate-limit-backoff.js +54 -0
- package/dist/lib/request/rate-limit-backoff.js.map +1 -0
- package/dist/lib/request/request-transformer.d.ts.map +1 -1
- package/dist/lib/request/request-transformer.js +3 -2
- package/dist/lib/request/request-transformer.js.map +1 -1
- package/dist/lib/request/response-handler.js +1 -1
- package/dist/lib/request/response-handler.js.map +1 -1
- package/dist/lib/storage.d.ts +72 -4
- package/dist/lib/storage.d.ts.map +1 -1
- package/dist/lib/storage.js +189 -19
- package/dist/lib/storage.js.map +1 -1
- package/dist/lib/types.d.ts +37 -1
- package/dist/lib/types.d.ts.map +1 -1
- package/package.json +85 -71
- package/scripts/install-opencode-codex-auth.js +191 -191
- package/scripts/test-all-models.sh +258 -258
- package/scripts/validate-model-map.sh +97 -97
|
@@ -1,193 +1,193 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import { existsSync } from "node:fs";
|
|
4
|
-
import { readFile, writeFile, mkdir, copyFile, rm } from "node:fs/promises";
|
|
5
|
-
import { fileURLToPath } from "node:url";
|
|
6
|
-
import { dirname, join, resolve } from "node:path";
|
|
7
|
-
import { homedir } from "node:os";
|
|
8
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
4
|
+
import { readFile, writeFile, mkdir, copyFile, rm } from "node:fs/promises";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { dirname, join, resolve } from "node:path";
|
|
7
|
+
import { homedir } from "node:os";
|
|
8
|
+
|
|
9
9
|
const PLUGIN_NAME = "opencode-openai-codex-auth-multi";
|
|
10
10
|
|
|
11
|
-
const args = new Set(process.argv.slice(2));
|
|
12
|
-
|
|
13
|
-
if (args.has("--help") || args.has("-h")) {
|
|
14
|
-
console.log(`Usage: ${PLUGIN_NAME} [--modern|--legacy] [--dry-run] [--no-cache-clear]\n\n` +
|
|
15
|
-
"Default behavior:\n" +
|
|
16
|
-
" - Installs/updates global config at ~/.config/opencode/opencode.json\n" +
|
|
17
|
-
" - Uses modern config (variants) by default\n" +
|
|
18
|
-
" - Ensures plugin is unpinned (latest)\n" +
|
|
19
|
-
" - Clears OpenCode plugin cache\n\n" +
|
|
20
|
-
"Options:\n" +
|
|
21
|
-
" --modern Force modern config (default)\n" +
|
|
22
|
-
" --legacy Use legacy config (older OpenCode versions)\n" +
|
|
23
|
-
" --dry-run Show actions without writing\n" +
|
|
24
|
-
" --no-cache-clear Skip clearing OpenCode cache\n"
|
|
25
|
-
);
|
|
26
|
-
process.exit(0);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const useLegacy = args.has("--legacy");
|
|
30
|
-
const useModern = args.has("--modern") || !useLegacy;
|
|
31
|
-
const dryRun = args.has("--dry-run");
|
|
32
|
-
const skipCacheClear = args.has("--no-cache-clear");
|
|
33
|
-
|
|
34
|
-
const scriptDir = dirname(fileURLToPath(import.meta.url));
|
|
35
|
-
const repoRoot = resolve(scriptDir, "..");
|
|
36
|
-
const templatePath = join(
|
|
37
|
-
repoRoot,
|
|
38
|
-
"config",
|
|
39
|
-
useLegacy ? "opencode-legacy.json" : "opencode-modern.json"
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
const configDir = join(homedir(), ".config", "opencode");
|
|
43
|
-
const configPath = join(configDir, "opencode.json");
|
|
44
|
-
const cacheDir = join(homedir(), ".cache", "opencode");
|
|
45
|
-
const cacheNodeModules = join(cacheDir, "node_modules", PLUGIN_NAME);
|
|
46
|
-
const cacheBunLock = join(cacheDir, "bun.lock");
|
|
47
|
-
const cachePackageJson = join(cacheDir, "package.json");
|
|
48
|
-
|
|
49
|
-
function log(message) {
|
|
50
|
-
console.log(message);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function normalizePluginList(list) {
|
|
54
|
-
const entries = Array.isArray(list) ? list.filter(Boolean) : [];
|
|
55
|
-
const filtered = entries.filter((entry) => {
|
|
56
|
-
if (typeof entry !== "string") return true;
|
|
57
|
-
return entry !== PLUGIN_NAME && !entry.startsWith(`${PLUGIN_NAME}@`);
|
|
58
|
-
});
|
|
59
|
-
return [...filtered, PLUGIN_NAME];
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function formatJson(obj) {
|
|
63
|
-
return `${JSON.stringify(obj, null, 2)}\n`;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
async function readJson(filePath) {
|
|
67
|
-
const content = await readFile(filePath, "utf-8");
|
|
68
|
-
return JSON.parse(content);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
async function backupConfig(sourcePath) {
|
|
72
|
-
const timestamp = new Date()
|
|
73
|
-
.toISOString()
|
|
74
|
-
.replace(/[:.]/g, "-")
|
|
75
|
-
.replace("T", "_")
|
|
76
|
-
.replace("Z", "");
|
|
77
|
-
const backupPath = `${sourcePath}.bak-${timestamp}`;
|
|
78
|
-
if (!dryRun) {
|
|
79
|
-
await copyFile(sourcePath, backupPath);
|
|
80
|
-
}
|
|
81
|
-
return backupPath;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
async function removePluginFromCachePackage() {
|
|
85
|
-
if (!existsSync(cachePackageJson)) {
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
let cacheData;
|
|
90
|
-
try {
|
|
91
|
-
cacheData = await readJson(cachePackageJson);
|
|
92
|
-
} catch (error) {
|
|
93
|
-
log(`Warning: Could not parse ${cachePackageJson} (${error}). Skipping.`);
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const sections = [
|
|
98
|
-
"dependencies",
|
|
99
|
-
"devDependencies",
|
|
100
|
-
"peerDependencies",
|
|
101
|
-
"optionalDependencies",
|
|
102
|
-
];
|
|
103
|
-
|
|
104
|
-
let changed = false;
|
|
105
|
-
for (const section of sections) {
|
|
106
|
-
const deps = cacheData?.[section];
|
|
107
|
-
if (deps && typeof deps === "object" && PLUGIN_NAME in deps) {
|
|
108
|
-
delete deps[PLUGIN_NAME];
|
|
109
|
-
changed = true;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
if (!changed) {
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (dryRun) {
|
|
118
|
-
log(`[dry-run] Would update ${cachePackageJson} to remove ${PLUGIN_NAME}`);
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
await writeFile(cachePackageJson, formatJson(cacheData), "utf-8");
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
async function clearCache() {
|
|
126
|
-
if (skipCacheClear) {
|
|
127
|
-
log("Skipping cache clear (--no-cache-clear).");
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
if (dryRun) {
|
|
132
|
-
log(`[dry-run] Would remove ${cacheNodeModules}`);
|
|
133
|
-
log(`[dry-run] Would remove ${cacheBunLock}`);
|
|
134
|
-
} else {
|
|
135
|
-
await rm(cacheNodeModules, { recursive: true, force: true });
|
|
136
|
-
await rm(cacheBunLock, { force: true });
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
await removePluginFromCachePackage();
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
async function main() {
|
|
143
|
-
if (!existsSync(templatePath)) {
|
|
144
|
-
throw new Error(`Config template not found at ${templatePath}`);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
const template = await readJson(templatePath);
|
|
148
|
-
template.plugin = [PLUGIN_NAME];
|
|
149
|
-
|
|
150
|
-
let nextConfig = template;
|
|
151
|
-
if (existsSync(configPath)) {
|
|
152
|
-
const backupPath = await backupConfig(configPath);
|
|
153
|
-
log(`${dryRun ? "[dry-run] Would create backup" : "Backup created"}: ${backupPath}`);
|
|
154
|
-
|
|
155
|
-
try {
|
|
156
|
-
const existing = await readJson(configPath);
|
|
157
|
-
const merged = { ...existing };
|
|
158
|
-
merged.plugin = normalizePluginList(existing.plugin);
|
|
159
|
-
const provider = (existing.provider && typeof existing.provider === "object")
|
|
160
|
-
? { ...existing.provider }
|
|
161
|
-
: {};
|
|
162
|
-
provider.openai = template.provider.openai;
|
|
163
|
-
merged.provider = provider;
|
|
164
|
-
nextConfig = merged;
|
|
165
|
-
} catch (error) {
|
|
166
|
-
log(`Warning: Could not parse existing config (${error}). Replacing with template.`);
|
|
167
|
-
nextConfig = template;
|
|
168
|
-
}
|
|
169
|
-
} else {
|
|
170
|
-
log("No existing config found. Creating new global config.");
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
if (dryRun) {
|
|
174
|
-
log(`[dry-run] Would write ${configPath} using ${useLegacy ? "legacy" : "modern"} config`);
|
|
175
|
-
} else {
|
|
176
|
-
await mkdir(configDir, { recursive: true });
|
|
177
|
-
await writeFile(configPath, formatJson(nextConfig), "utf-8");
|
|
178
|
-
log(`Wrote ${configPath} (${useLegacy ? "legacy" : "modern"} config)`);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
await clearCache();
|
|
182
|
-
|
|
183
|
-
log("\nDone. Restart OpenCode to (re)install the plugin.");
|
|
184
|
-
log("Example: opencode");
|
|
185
|
-
if (useLegacy) {
|
|
186
|
-
log("Note: Legacy config requires OpenCode v1.0.209 or older.");
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
main().catch((error) => {
|
|
191
|
-
console.error(`Installer failed: ${error instanceof Error ? error.message : error}`);
|
|
192
|
-
process.exit(1);
|
|
193
|
-
});
|
|
11
|
+
const args = new Set(process.argv.slice(2));
|
|
12
|
+
|
|
13
|
+
if (args.has("--help") || args.has("-h")) {
|
|
14
|
+
console.log(`Usage: ${PLUGIN_NAME} [--modern|--legacy] [--dry-run] [--no-cache-clear]\n\n` +
|
|
15
|
+
"Default behavior:\n" +
|
|
16
|
+
" - Installs/updates global config at ~/.config/opencode/opencode.json\n" +
|
|
17
|
+
" - Uses modern config (variants) by default\n" +
|
|
18
|
+
" - Ensures plugin is unpinned (latest)\n" +
|
|
19
|
+
" - Clears OpenCode plugin cache\n\n" +
|
|
20
|
+
"Options:\n" +
|
|
21
|
+
" --modern Force modern config (default)\n" +
|
|
22
|
+
" --legacy Use legacy config (older OpenCode versions)\n" +
|
|
23
|
+
" --dry-run Show actions without writing\n" +
|
|
24
|
+
" --no-cache-clear Skip clearing OpenCode cache\n"
|
|
25
|
+
);
|
|
26
|
+
process.exit(0);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const useLegacy = args.has("--legacy");
|
|
30
|
+
const useModern = args.has("--modern") || !useLegacy;
|
|
31
|
+
const dryRun = args.has("--dry-run");
|
|
32
|
+
const skipCacheClear = args.has("--no-cache-clear");
|
|
33
|
+
|
|
34
|
+
const scriptDir = dirname(fileURLToPath(import.meta.url));
|
|
35
|
+
const repoRoot = resolve(scriptDir, "..");
|
|
36
|
+
const templatePath = join(
|
|
37
|
+
repoRoot,
|
|
38
|
+
"config",
|
|
39
|
+
useLegacy ? "opencode-legacy.json" : "opencode-modern.json"
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
const configDir = join(homedir(), ".config", "opencode");
|
|
43
|
+
const configPath = join(configDir, "opencode.json");
|
|
44
|
+
const cacheDir = join(homedir(), ".cache", "opencode");
|
|
45
|
+
const cacheNodeModules = join(cacheDir, "node_modules", PLUGIN_NAME);
|
|
46
|
+
const cacheBunLock = join(cacheDir, "bun.lock");
|
|
47
|
+
const cachePackageJson = join(cacheDir, "package.json");
|
|
48
|
+
|
|
49
|
+
function log(message) {
|
|
50
|
+
console.log(message);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function normalizePluginList(list) {
|
|
54
|
+
const entries = Array.isArray(list) ? list.filter(Boolean) : [];
|
|
55
|
+
const filtered = entries.filter((entry) => {
|
|
56
|
+
if (typeof entry !== "string") return true;
|
|
57
|
+
return entry !== PLUGIN_NAME && !entry.startsWith(`${PLUGIN_NAME}@`);
|
|
58
|
+
});
|
|
59
|
+
return [...filtered, PLUGIN_NAME];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function formatJson(obj) {
|
|
63
|
+
return `${JSON.stringify(obj, null, 2)}\n`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async function readJson(filePath) {
|
|
67
|
+
const content = await readFile(filePath, "utf-8");
|
|
68
|
+
return JSON.parse(content);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async function backupConfig(sourcePath) {
|
|
72
|
+
const timestamp = new Date()
|
|
73
|
+
.toISOString()
|
|
74
|
+
.replace(/[:.]/g, "-")
|
|
75
|
+
.replace("T", "_")
|
|
76
|
+
.replace("Z", "");
|
|
77
|
+
const backupPath = `${sourcePath}.bak-${timestamp}`;
|
|
78
|
+
if (!dryRun) {
|
|
79
|
+
await copyFile(sourcePath, backupPath);
|
|
80
|
+
}
|
|
81
|
+
return backupPath;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async function removePluginFromCachePackage() {
|
|
85
|
+
if (!existsSync(cachePackageJson)) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
let cacheData;
|
|
90
|
+
try {
|
|
91
|
+
cacheData = await readJson(cachePackageJson);
|
|
92
|
+
} catch (error) {
|
|
93
|
+
log(`Warning: Could not parse ${cachePackageJson} (${error}). Skipping.`);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const sections = [
|
|
98
|
+
"dependencies",
|
|
99
|
+
"devDependencies",
|
|
100
|
+
"peerDependencies",
|
|
101
|
+
"optionalDependencies",
|
|
102
|
+
];
|
|
103
|
+
|
|
104
|
+
let changed = false;
|
|
105
|
+
for (const section of sections) {
|
|
106
|
+
const deps = cacheData?.[section];
|
|
107
|
+
if (deps && typeof deps === "object" && PLUGIN_NAME in deps) {
|
|
108
|
+
delete deps[PLUGIN_NAME];
|
|
109
|
+
changed = true;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (!changed) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (dryRun) {
|
|
118
|
+
log(`[dry-run] Would update ${cachePackageJson} to remove ${PLUGIN_NAME}`);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
await writeFile(cachePackageJson, formatJson(cacheData), "utf-8");
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
async function clearCache() {
|
|
126
|
+
if (skipCacheClear) {
|
|
127
|
+
log("Skipping cache clear (--no-cache-clear).");
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (dryRun) {
|
|
132
|
+
log(`[dry-run] Would remove ${cacheNodeModules}`);
|
|
133
|
+
log(`[dry-run] Would remove ${cacheBunLock}`);
|
|
134
|
+
} else {
|
|
135
|
+
await rm(cacheNodeModules, { recursive: true, force: true });
|
|
136
|
+
await rm(cacheBunLock, { force: true });
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
await removePluginFromCachePackage();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
async function main() {
|
|
143
|
+
if (!existsSync(templatePath)) {
|
|
144
|
+
throw new Error(`Config template not found at ${templatePath}`);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const template = await readJson(templatePath);
|
|
148
|
+
template.plugin = [PLUGIN_NAME];
|
|
149
|
+
|
|
150
|
+
let nextConfig = template;
|
|
151
|
+
if (existsSync(configPath)) {
|
|
152
|
+
const backupPath = await backupConfig(configPath);
|
|
153
|
+
log(`${dryRun ? "[dry-run] Would create backup" : "Backup created"}: ${backupPath}`);
|
|
154
|
+
|
|
155
|
+
try {
|
|
156
|
+
const existing = await readJson(configPath);
|
|
157
|
+
const merged = { ...existing };
|
|
158
|
+
merged.plugin = normalizePluginList(existing.plugin);
|
|
159
|
+
const provider = (existing.provider && typeof existing.provider === "object")
|
|
160
|
+
? { ...existing.provider }
|
|
161
|
+
: {};
|
|
162
|
+
provider.openai = template.provider.openai;
|
|
163
|
+
merged.provider = provider;
|
|
164
|
+
nextConfig = merged;
|
|
165
|
+
} catch (error) {
|
|
166
|
+
log(`Warning: Could not parse existing config (${error}). Replacing with template.`);
|
|
167
|
+
nextConfig = template;
|
|
168
|
+
}
|
|
169
|
+
} else {
|
|
170
|
+
log("No existing config found. Creating new global config.");
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (dryRun) {
|
|
174
|
+
log(`[dry-run] Would write ${configPath} using ${useLegacy ? "legacy" : "modern"} config`);
|
|
175
|
+
} else {
|
|
176
|
+
await mkdir(configDir, { recursive: true });
|
|
177
|
+
await writeFile(configPath, formatJson(nextConfig), "utf-8");
|
|
178
|
+
log(`Wrote ${configPath} (${useLegacy ? "legacy" : "modern"} config)`);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
await clearCache();
|
|
182
|
+
|
|
183
|
+
log("\nDone. Restart OpenCode to (re)install the plugin.");
|
|
184
|
+
log("Example: opencode");
|
|
185
|
+
if (useLegacy) {
|
|
186
|
+
log("Note: Legacy config requires OpenCode v1.0.209 or older.");
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
main().catch((error) => {
|
|
191
|
+
console.error(`Installer failed: ${error instanceof Error ? error.message : error}`);
|
|
192
|
+
process.exit(1);
|
|
193
|
+
});
|