opencode-openai-codex-auth-multi 4.3.0-multiaccount.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 -0
- package/README.md +107 -0
- package/assets/opencode-logo-ornate-dark.svg +18 -0
- package/assets/readme-hero.svg +31 -0
- package/config/README.md +110 -0
- package/config/minimal-opencode.json +13 -0
- package/config/opencode-legacy.json +572 -0
- package/config/opencode-modern.json +240 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +666 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/accounts.d.ts +48 -0
- package/dist/lib/accounts.d.ts.map +1 -0
- package/dist/lib/accounts.js +282 -0
- package/dist/lib/accounts.js.map +1 -0
- package/dist/lib/auth/auth.d.ts +43 -0
- package/dist/lib/auth/auth.d.ts.map +1 -0
- package/dist/lib/auth/auth.js +163 -0
- package/dist/lib/auth/auth.js.map +1 -0
- package/dist/lib/auth/browser.d.ts +17 -0
- package/dist/lib/auth/browser.d.ts.map +1 -0
- package/dist/lib/auth/browser.js +76 -0
- package/dist/lib/auth/browser.js.map +1 -0
- package/dist/lib/auth/server.d.ts +10 -0
- package/dist/lib/auth/server.d.ts.map +1 -0
- package/dist/lib/auth/server.js +78 -0
- package/dist/lib/auth/server.js.map +1 -0
- package/dist/lib/cli.d.ts +8 -0
- package/dist/lib/cli.d.ts.map +1 -0
- package/dist/lib/cli.js +44 -0
- package/dist/lib/cli.js.map +1 -0
- package/dist/lib/config.d.ts +17 -0
- package/dist/lib/config.d.ts.map +1 -0
- package/dist/lib/config.js +51 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/constants.d.ts +67 -0
- package/dist/lib/constants.d.ts.map +1 -0
- package/dist/lib/constants.js +67 -0
- package/dist/lib/constants.js.map +1 -0
- package/dist/lib/logger.d.ts +26 -0
- package/dist/lib/logger.d.ts.map +1 -0
- package/dist/lib/logger.js +110 -0
- package/dist/lib/logger.js.map +1 -0
- package/dist/lib/oauth-success.html +712 -0
- package/dist/lib/prompts/codex-opencode-bridge.d.ts +19 -0
- package/dist/lib/prompts/codex-opencode-bridge.d.ts.map +1 -0
- package/dist/lib/prompts/codex-opencode-bridge.js +152 -0
- package/dist/lib/prompts/codex-opencode-bridge.js.map +1 -0
- package/dist/lib/prompts/codex.d.ts +27 -0
- package/dist/lib/prompts/codex.d.ts.map +1 -0
- package/dist/lib/prompts/codex.js +241 -0
- package/dist/lib/prompts/codex.js.map +1 -0
- package/dist/lib/prompts/opencode-codex.d.ts +21 -0
- package/dist/lib/prompts/opencode-codex.d.ts.map +1 -0
- package/dist/lib/prompts/opencode-codex.js +91 -0
- package/dist/lib/prompts/opencode-codex.js.map +1 -0
- package/dist/lib/request/fetch-helpers.d.ts +81 -0
- package/dist/lib/request/fetch-helpers.d.ts.map +1 -0
- package/dist/lib/request/fetch-helpers.js +321 -0
- package/dist/lib/request/fetch-helpers.js.map +1 -0
- package/dist/lib/request/helpers/input-utils.d.ts +6 -0
- package/dist/lib/request/helpers/input-utils.d.ts.map +1 -0
- package/dist/lib/request/helpers/input-utils.js +174 -0
- package/dist/lib/request/helpers/input-utils.js.map +1 -0
- package/dist/lib/request/helpers/model-map.d.ts +28 -0
- package/dist/lib/request/helpers/model-map.d.ts.map +1 -0
- package/dist/lib/request/helpers/model-map.js +109 -0
- package/dist/lib/request/helpers/model-map.js.map +1 -0
- package/dist/lib/request/request-transformer.d.ts +93 -0
- package/dist/lib/request/request-transformer.d.ts.map +1 -0
- package/dist/lib/request/request-transformer.js +403 -0
- package/dist/lib/request/request-transformer.js.map +1 -0
- package/dist/lib/request/response-handler.d.ts +14 -0
- package/dist/lib/request/response-handler.d.ts.map +1 -0
- package/dist/lib/request/response-handler.js +90 -0
- package/dist/lib/request/response-handler.js.map +1 -0
- package/dist/lib/storage.d.ts +23 -0
- package/dist/lib/storage.d.ts.map +1 -0
- package/dist/lib/storage.js +153 -0
- package/dist/lib/storage.js.map +1 -0
- package/dist/lib/types.d.ts +170 -0
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/lib/types.js +2 -0
- package/dist/lib/types.js.map +1 -0
- package/package.json +71 -0
- package/scripts/copy-oauth-success.js +37 -0
- package/scripts/install-opencode-codex-auth.js +193 -0
- package/scripts/test-all-models.sh +260 -0
- package/scripts/validate-model-map.sh +97 -0
|
@@ -0,0 +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
|
+
|
|
9
|
+
const PLUGIN_NAME = "opencode-openai-codex-auth-multi";
|
|
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
|
+
});
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# Test All Models - Verify API Configuration
|
|
4
|
+
# This script tests all model configurations and verifies the actual API requests
|
|
5
|
+
|
|
6
|
+
set -e
|
|
7
|
+
|
|
8
|
+
# Colors for output
|
|
9
|
+
RED='\033[0;31m'
|
|
10
|
+
GREEN='\033[0;32m'
|
|
11
|
+
YELLOW='\033[1;33m'
|
|
12
|
+
BLUE='\033[0;34m'
|
|
13
|
+
NC='\033[0m' # No Color
|
|
14
|
+
|
|
15
|
+
# Paths
|
|
16
|
+
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
17
|
+
OPENCODE_JSON="${REPO_DIR}/opencode.json"
|
|
18
|
+
LOG_DIR="${HOME}/.opencode/logs/codex-plugin"
|
|
19
|
+
RESULTS_FILE="${REPO_DIR}/test-results.md"
|
|
20
|
+
|
|
21
|
+
# Test counter
|
|
22
|
+
TOTAL_TESTS=0
|
|
23
|
+
PASSED_TESTS=0
|
|
24
|
+
FAILED_TESTS=0
|
|
25
|
+
|
|
26
|
+
echo -e "${BLUE}════════════════════════════════════════════════════════════════${NC}"
|
|
27
|
+
echo -e "${BLUE} Model Configuration Verification Test Suite${NC}"
|
|
28
|
+
echo -e "${BLUE}════════════════════════════════════════════════════════════════${NC}"
|
|
29
|
+
echo ""
|
|
30
|
+
|
|
31
|
+
# Kill any running OpenCode server processes to force fresh plugin load
|
|
32
|
+
echo "Killing OpenCode server processes..."
|
|
33
|
+
pkill -f "opencode" 2>/dev/null || true
|
|
34
|
+
sleep 2
|
|
35
|
+
echo "✓ OpenCode servers stopped"
|
|
36
|
+
echo ""
|
|
37
|
+
|
|
38
|
+
# Initialize results file
|
|
39
|
+
cat > "${RESULTS_FILE}" << 'EOF'
|
|
40
|
+
# Model Configuration Verification Results
|
|
41
|
+
|
|
42
|
+
**Test Date:** $(date)
|
|
43
|
+
**Test Directory:** Repository local config
|
|
44
|
+
|
|
45
|
+
## Results Summary
|
|
46
|
+
|
|
47
|
+
| Model | Normalized | Family | Effort | Summary | Verbosity | Include | Status |
|
|
48
|
+
|-------|------------|--------|--------|---------|-----------|---------|--------|
|
|
49
|
+
EOF
|
|
50
|
+
|
|
51
|
+
# Function: Run a test for a specific model
|
|
52
|
+
test_model() {
|
|
53
|
+
local model_name="$1"
|
|
54
|
+
local expected_normalized="$2"
|
|
55
|
+
local expected_family="$3"
|
|
56
|
+
local expected_effort="$4"
|
|
57
|
+
local expected_summary="$5"
|
|
58
|
+
local expected_verbosity="$6"
|
|
59
|
+
|
|
60
|
+
((TOTAL_TESTS++))
|
|
61
|
+
|
|
62
|
+
echo -e "${YELLOW}Testing model: ${model_name}${NC}"
|
|
63
|
+
|
|
64
|
+
# Clear previous logs
|
|
65
|
+
rm -rf "${LOG_DIR}"/*
|
|
66
|
+
|
|
67
|
+
# Run opencode
|
|
68
|
+
cd "${REPO_DIR}"
|
|
69
|
+
if ENABLE_PLUGIN_REQUEST_LOGGING=1 DEBUG_CODEX_PLUGIN=1 opencode run "write hello to test-${TOTAL_TESTS}.txt" --model="openai/${model_name}" > /dev/null 2>&1; then
|
|
70
|
+
echo -e "${GREEN} ✓ Command executed successfully${NC}"
|
|
71
|
+
else
|
|
72
|
+
echo -e "${RED} ✗ Command failed${NC}"
|
|
73
|
+
echo "| ${model_name} | N/A | N/A | N/A | N/A | N/A | ❌ FAILED |" >> "${RESULTS_FILE}"
|
|
74
|
+
((FAILED_TESTS++))
|
|
75
|
+
return 1
|
|
76
|
+
fi
|
|
77
|
+
|
|
78
|
+
# Find the after-transform log file that matches the expected model
|
|
79
|
+
# (opencode may use multiple models per session - e.g., nano for titles)
|
|
80
|
+
local log_file=""
|
|
81
|
+
for f in $(find "${LOG_DIR}" -name "*-after-transform.json" -type f -print0 | xargs -0 ls -t); do
|
|
82
|
+
local orig_model=$(jq -r '.originalModel // ""' "$f" 2>/dev/null)
|
|
83
|
+
if [ "${orig_model}" = "${model_name}" ]; then
|
|
84
|
+
log_file="$f"
|
|
85
|
+
break
|
|
86
|
+
fi
|
|
87
|
+
done
|
|
88
|
+
|
|
89
|
+
if [ -z "${log_file}" ] || [ ! -f "${log_file}" ]; then
|
|
90
|
+
echo -e "${RED} ✗ Log file not found for model ${model_name}${NC}"
|
|
91
|
+
echo "| ${model_name} | N/A | N/A | N/A | N/A | N/A | ❌ NO LOG |" >> "${RESULTS_FILE}"
|
|
92
|
+
((FAILED_TESTS++))
|
|
93
|
+
return 1
|
|
94
|
+
fi
|
|
95
|
+
|
|
96
|
+
# Parse log file with jq
|
|
97
|
+
local actual_normalized=$(jq -r '.normalizedModel // "N/A"' "${log_file}")
|
|
98
|
+
local actual_family=$(jq -r '.modelFamily // "N/A"' "${log_file}")
|
|
99
|
+
local actual_effort=$(jq -r '.reasoning.effort // "N/A"' "${log_file}")
|
|
100
|
+
local actual_summary=$(jq -r '.reasoning.summary // "N/A"' "${log_file}")
|
|
101
|
+
local actual_verbosity=$(jq -r '.body.text.verbosity // "N/A"' "${log_file}")
|
|
102
|
+
local actual_include=$(jq -r '.include[0] // "N/A"' "${log_file}")
|
|
103
|
+
|
|
104
|
+
echo " Actual: model=${actual_normalized}, family=${actual_family}, effort=${actual_effort}, summary=${actual_summary}, verbosity=${actual_verbosity}"
|
|
105
|
+
echo " Expected: model=${expected_normalized}, family=${expected_family}, effort=${expected_effort}, summary=${expected_summary}, verbosity=${expected_verbosity}"
|
|
106
|
+
|
|
107
|
+
# Verify values
|
|
108
|
+
local status="✅ PASS"
|
|
109
|
+
if [ "${actual_normalized}" != "${expected_normalized}" ] || \
|
|
110
|
+
[ "${actual_family}" != "${expected_family}" ] || \
|
|
111
|
+
[ "${actual_effort}" != "${expected_effort}" ] || \
|
|
112
|
+
[ "${actual_summary}" != "${expected_summary}" ] || \
|
|
113
|
+
[ "${actual_verbosity}" != "${expected_verbosity}" ]; then
|
|
114
|
+
status="❌ FAIL"
|
|
115
|
+
((FAILED_TESTS++))
|
|
116
|
+
echo -e "${RED} ✗ Verification failed${NC}"
|
|
117
|
+
else
|
|
118
|
+
((PASSED_TESTS++))
|
|
119
|
+
echo -e "${GREEN} ✓ Verification passed${NC}"
|
|
120
|
+
fi
|
|
121
|
+
|
|
122
|
+
# Add to results
|
|
123
|
+
echo "| ${model_name} | ${actual_normalized} | ${actual_family} | ${actual_effort} | ${actual_summary} | ${actual_verbosity} | ${actual_include} | ${status} |" >> "${RESULTS_FILE}"
|
|
124
|
+
|
|
125
|
+
# Cleanup
|
|
126
|
+
rm -f "${REPO_DIR}/test-${TOTAL_TESTS}.txt"
|
|
127
|
+
|
|
128
|
+
echo ""
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
# Function: Update opencode.json with config
|
|
132
|
+
update_config() {
|
|
133
|
+
local config_type="$1"
|
|
134
|
+
|
|
135
|
+
echo -e "${BLUE}─────────────────────────────────────────────────────────────────${NC}"
|
|
136
|
+
echo -e "${BLUE}Scenario: ${config_type}${NC}"
|
|
137
|
+
echo -e "${BLUE}─────────────────────────────────────────────────────────────────${NC}"
|
|
138
|
+
echo ""
|
|
139
|
+
|
|
140
|
+
case "${config_type}" in
|
|
141
|
+
"legacy")
|
|
142
|
+
cat "${REPO_DIR}/config/opencode-legacy.json" > "${OPENCODE_JSON}"
|
|
143
|
+
echo "✓ Updated opencode.json with legacy config (GPT 5.x)"
|
|
144
|
+
;;
|
|
145
|
+
"minimal")
|
|
146
|
+
cat "${REPO_DIR}/config/minimal-opencode.json" > "${OPENCODE_JSON}"
|
|
147
|
+
echo "✓ Updated opencode.json with minimal config"
|
|
148
|
+
;;
|
|
149
|
+
esac
|
|
150
|
+
|
|
151
|
+
# Replace npm package with local dist for testing
|
|
152
|
+
sed -i.bak -E 's|"opencode-openai-codex-auth-multi(@[^"]*)?"|"file://'"${REPO_DIR}"'/dist"|' "${OPENCODE_JSON}"
|
|
153
|
+
|
|
154
|
+
rm -f "${OPENCODE_JSON}.bak"
|
|
155
|
+
echo "✓ Using local dist for plugin"
|
|
156
|
+
|
|
157
|
+
echo ""
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
# ============================================================================
|
|
161
|
+
# Scenario 1: Legacy Config - GPT 5.x Model Family
|
|
162
|
+
# ============================================================================
|
|
163
|
+
update_config "legacy"
|
|
164
|
+
|
|
165
|
+
# GPT 5.1 Codex presets
|
|
166
|
+
test_model "gpt-5.1-codex-low" "gpt-5.1-codex" "codex" "low" "auto" "medium"
|
|
167
|
+
test_model "gpt-5.1-codex-medium" "gpt-5.1-codex" "codex" "medium" "auto" "medium"
|
|
168
|
+
test_model "gpt-5.1-codex-high" "gpt-5.1-codex" "codex" "high" "detailed" "medium"
|
|
169
|
+
test_model "gpt-5.1-codex-max-low" "gpt-5.1-codex-max" "codex-max" "low" "detailed" "medium"
|
|
170
|
+
test_model "gpt-5.1-codex-max-medium" "gpt-5.1-codex-max" "codex-max" "medium" "detailed" "medium"
|
|
171
|
+
test_model "gpt-5.1-codex-max-high" "gpt-5.1-codex-max" "codex-max" "high" "detailed" "medium"
|
|
172
|
+
test_model "gpt-5.1-codex-max-xhigh" "gpt-5.1-codex-max" "codex-max" "xhigh" "detailed" "medium"
|
|
173
|
+
|
|
174
|
+
# GPT 5.2 presets (supports none/low/medium/high/xhigh per OpenAI API docs)
|
|
175
|
+
test_model "gpt-5.2-none" "gpt-5.2" "gpt-5.2" "none" "auto" "medium"
|
|
176
|
+
test_model "gpt-5.2-low" "gpt-5.2" "gpt-5.2" "low" "auto" "medium"
|
|
177
|
+
test_model "gpt-5.2-medium" "gpt-5.2" "gpt-5.2" "medium" "auto" "medium"
|
|
178
|
+
test_model "gpt-5.2-high" "gpt-5.2" "gpt-5.2" "high" "detailed" "medium"
|
|
179
|
+
test_model "gpt-5.2-xhigh" "gpt-5.2" "gpt-5.2" "xhigh" "detailed" "medium"
|
|
180
|
+
|
|
181
|
+
# GPT 5.2 Codex presets
|
|
182
|
+
test_model "gpt-5.2-codex-low" "gpt-5.2-codex" "gpt-5.2-codex" "low" "auto" "medium"
|
|
183
|
+
test_model "gpt-5.2-codex-medium" "gpt-5.2-codex" "gpt-5.2-codex" "medium" "auto" "medium"
|
|
184
|
+
test_model "gpt-5.2-codex-high" "gpt-5.2-codex" "gpt-5.2-codex" "high" "detailed" "medium"
|
|
185
|
+
test_model "gpt-5.2-codex-xhigh" "gpt-5.2-codex" "gpt-5.2-codex" "xhigh" "detailed" "medium"
|
|
186
|
+
|
|
187
|
+
# GPT 5.1 Codex Mini presets (medium/high only)
|
|
188
|
+
test_model "gpt-5.1-codex-mini-medium" "gpt-5.1-codex-mini" "codex" "medium" "auto" "medium"
|
|
189
|
+
test_model "gpt-5.1-codex-mini-high" "gpt-5.1-codex-mini" "codex" "high" "detailed" "medium"
|
|
190
|
+
|
|
191
|
+
# GPT 5.1 general-purpose presets (supports none/low/medium/high per OpenAI API docs)
|
|
192
|
+
test_model "gpt-5.1-none" "gpt-5.1" "gpt-5.1" "none" "auto" "medium"
|
|
193
|
+
test_model "gpt-5.1-low" "gpt-5.1" "gpt-5.1" "low" "auto" "low"
|
|
194
|
+
test_model "gpt-5.1-medium" "gpt-5.1" "gpt-5.1" "medium" "auto" "medium"
|
|
195
|
+
test_model "gpt-5.1-high" "gpt-5.1" "gpt-5.1" "high" "detailed" "high"
|
|
196
|
+
|
|
197
|
+
# # ============================================================================
|
|
198
|
+
# # Scenario 2: Minimal Config - Default Models (No Custom Config)
|
|
199
|
+
# # ============================================================================
|
|
200
|
+
# update_config "minimal"
|
|
201
|
+
|
|
202
|
+
# test_model "gpt-5" "gpt-5" "medium" "auto" "medium"
|
|
203
|
+
# test_model "gpt-5-codex" "gpt-5-codex" "medium" "auto" "medium"
|
|
204
|
+
# test_model "gpt-5-mini" "gpt-5" "minimal" "auto" "medium"
|
|
205
|
+
# test_model "gpt-5-nano" "gpt-5" "minimal" "auto" "medium"
|
|
206
|
+
|
|
207
|
+
# ============================================================================
|
|
208
|
+
# Scenario 3: Backwards Compatibility
|
|
209
|
+
# ============================================================================
|
|
210
|
+
# update_config "backwards-compat"
|
|
211
|
+
|
|
212
|
+
# # GPT 5 Codex presets
|
|
213
|
+
# test_model "gpt-5-codex-low" "gpt-5-codex" "low" "auto" "medium"
|
|
214
|
+
# test_model "gpt-5-codex-medium" "gpt-5-codex" "medium" "auto" "medium"
|
|
215
|
+
# test_model "gpt-5-codex-high" "gpt-5-codex" "high" "detailed" "medium"
|
|
216
|
+
|
|
217
|
+
# GPT 5 Codex Mini presets
|
|
218
|
+
# test_model "gpt-5-codex-mini" "codex-mini-latest" "medium" "auto" "medium"
|
|
219
|
+
# test_model "gpt-5-codex-mini-medium" "codex-mini-latest" "medium" "auto" "medium"
|
|
220
|
+
# test_model "gpt-5-codex-mini-high" "codex-mini-latest" "high" "detailed" "medium"
|
|
221
|
+
|
|
222
|
+
# GPT 5 general-purpose presets
|
|
223
|
+
# test_model "gpt-5" "gpt-5" "medium" "auto" "medium"
|
|
224
|
+
# test_model "gpt-5-medium" "gpt-5" "medium" "auto" "medium"
|
|
225
|
+
# test_model "gpt-5-high" "gpt-5" "high" "detailed" "high"
|
|
226
|
+
# test_model "gpt-5-mini" "gpt-5" "minimal" "auto" "medium"
|
|
227
|
+
|
|
228
|
+
# ============================================================================
|
|
229
|
+
# Summary
|
|
230
|
+
# ============================================================================
|
|
231
|
+
echo -e "${BLUE}════════════════════════════════════════════════════════════════${NC}"
|
|
232
|
+
echo -e "${BLUE} Test Results Summary${NC}"
|
|
233
|
+
echo -e "${BLUE}════════════════════════════════════════════════════════════════${NC}"
|
|
234
|
+
echo ""
|
|
235
|
+
echo -e "Total Tests: ${TOTAL_TESTS}"
|
|
236
|
+
echo -e "${GREEN}Passed: ${PASSED_TESTS}${NC}"
|
|
237
|
+
if [ ${FAILED_TESTS} -gt 0 ]; then
|
|
238
|
+
echo -e "${RED}Failed: ${FAILED_TESTS}${NC}"
|
|
239
|
+
else
|
|
240
|
+
echo -e "Failed: ${FAILED_TESTS}"
|
|
241
|
+
fi
|
|
242
|
+
echo ""
|
|
243
|
+
echo -e "Results saved to: ${RESULTS_FILE} (will be removed)"
|
|
244
|
+
echo ""
|
|
245
|
+
|
|
246
|
+
# Restore original config
|
|
247
|
+
if [ -f "${REPO_DIR}/config/opencode-legacy.json" ]; then
|
|
248
|
+
cat "${REPO_DIR}/config/opencode-legacy.json" > "${OPENCODE_JSON}"
|
|
249
|
+
echo "✓ Restored original legacy config to opencode.json"
|
|
250
|
+
fi
|
|
251
|
+
|
|
252
|
+
# Cleanup results file to avoid polluting the repo
|
|
253
|
+
rm -f "${RESULTS_FILE}"
|
|
254
|
+
|
|
255
|
+
# Exit with appropriate code
|
|
256
|
+
if [ ${FAILED_TESTS} -gt 0 ]; then
|
|
257
|
+
exit 1
|
|
258
|
+
else
|
|
259
|
+
exit 0
|
|
260
|
+
fi
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# Simple Model Map Validation Script
|
|
4
|
+
# Tests that OpenCode correctly uses models from config
|
|
5
|
+
|
|
6
|
+
set -e
|
|
7
|
+
|
|
8
|
+
# Colors
|
|
9
|
+
GREEN='\033[0;32m'
|
|
10
|
+
RED='\033[0;31m'
|
|
11
|
+
YELLOW='\033[1;33m'
|
|
12
|
+
BLUE='\033[0;34m'
|
|
13
|
+
NC='\033[0m'
|
|
14
|
+
|
|
15
|
+
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
16
|
+
LOG_DIR="${HOME}/.opencode/logs/codex-plugin"
|
|
17
|
+
|
|
18
|
+
echo -e "${BLUE}════════════════════════════════════════════${NC}"
|
|
19
|
+
echo -e "${BLUE} Model Map Validation${NC}"
|
|
20
|
+
echo -e "${BLUE}════════════════════════════════════════════${NC}"
|
|
21
|
+
echo ""
|
|
22
|
+
|
|
23
|
+
# Test 1: Model that IS in the config (should work)
|
|
24
|
+
echo -e "${YELLOW}Test 1: Model IN config (gpt-5.1-codex-low)${NC}"
|
|
25
|
+
rm -rf "${LOG_DIR}"/*
|
|
26
|
+
|
|
27
|
+
cd "${REPO_DIR}"
|
|
28
|
+
if ENABLE_PLUGIN_REQUEST_LOGGING=1 opencode run "say hello" --model="openai/gpt-5.1-codex-low" > /dev/null 2>&1; then
|
|
29
|
+
# Check the log - find the one for gpt-5.1-codex-low specifically
|
|
30
|
+
log_file=$(find "${LOG_DIR}" -name "*-after-transform.json" -exec grep -l "gpt-5.1-codex-low" {} \; | head -n 1)
|
|
31
|
+
|
|
32
|
+
if [ -f "${log_file}" ]; then
|
|
33
|
+
original=$(jq -r '.originalModel // "N/A"' "${log_file}")
|
|
34
|
+
normalized=$(jq -r '.normalizedModel // "N/A"' "${log_file}")
|
|
35
|
+
|
|
36
|
+
echo -e " Original: ${original}"
|
|
37
|
+
echo -e " Normalized: ${normalized}"
|
|
38
|
+
|
|
39
|
+
if [ "${normalized}" == "gpt-5.1-codex" ]; then
|
|
40
|
+
echo -e " ${GREEN}✓ PASS - Correctly normalized to gpt-5.1-codex${NC}"
|
|
41
|
+
else
|
|
42
|
+
echo -e " ${RED}✗ FAIL - Expected gpt-5.1-codex, got ${normalized}${NC}"
|
|
43
|
+
exit 1
|
|
44
|
+
fi
|
|
45
|
+
else
|
|
46
|
+
echo -e " ${RED}✗ FAIL - No log file found${NC}"
|
|
47
|
+
exit 1
|
|
48
|
+
fi
|
|
49
|
+
else
|
|
50
|
+
echo -e " ${RED}✗ FAIL - Command failed${NC}"
|
|
51
|
+
exit 1
|
|
52
|
+
fi
|
|
53
|
+
|
|
54
|
+
echo ""
|
|
55
|
+
|
|
56
|
+
# Test 2: Model that is NOT in the config (should error or use fallback)
|
|
57
|
+
echo -e "${YELLOW}Test 2: Model NOT in config (fake-model-xyz)${NC}"
|
|
58
|
+
rm -rf "${LOG_DIR}"/*
|
|
59
|
+
|
|
60
|
+
if ENABLE_PLUGIN_REQUEST_LOGGING=1 opencode run "write test" --model="openai/fake-model-xyz" > /dev/null 2>&1; then
|
|
61
|
+
log_file=$(find "${LOG_DIR}" -name "*-after-transform.json" | head -n 1)
|
|
62
|
+
|
|
63
|
+
if [ -f "${log_file}" ]; then
|
|
64
|
+
original=$(jq -r '.originalModel // "N/A"' "${log_file}")
|
|
65
|
+
normalized=$(jq -r '.normalizedModel // "N/A"' "${log_file}")
|
|
66
|
+
|
|
67
|
+
echo -e " Original: ${original}"
|
|
68
|
+
echo -e " Normalized: ${normalized}"
|
|
69
|
+
echo -e " ${GREEN}✓ Command succeeded (using fallback: ${normalized})${NC}"
|
|
70
|
+
else
|
|
71
|
+
echo -e " ${YELLOW}⚠ No log file (expected - model not in config)${NC}"
|
|
72
|
+
fi
|
|
73
|
+
else
|
|
74
|
+
echo -e " ${YELLOW}⚠ Command failed (expected - model not in config)${NC}"
|
|
75
|
+
fi
|
|
76
|
+
|
|
77
|
+
echo ""
|
|
78
|
+
|
|
79
|
+
# Test 3: Verify config location
|
|
80
|
+
echo -e "${YELLOW}Test 3: Verify config file location${NC}"
|
|
81
|
+
if [ -f "${REPO_DIR}/opencode.json" ]; then
|
|
82
|
+
plugin_path=$(jq -r '.plugin[0]' "${REPO_DIR}/opencode.json")
|
|
83
|
+
model_count=$(jq '.provider.openai.models | length' "${REPO_DIR}/opencode.json")
|
|
84
|
+
|
|
85
|
+
echo -e " Config file: ${REPO_DIR}/opencode.json"
|
|
86
|
+
echo -e " Plugin path: ${plugin_path}"
|
|
87
|
+
echo -e " Models defined: ${model_count}"
|
|
88
|
+
echo -e " ${GREEN}✓ Config file found and valid${NC}"
|
|
89
|
+
else
|
|
90
|
+
echo -e " ${RED}✗ No opencode.json in repo directory${NC}"
|
|
91
|
+
exit 1
|
|
92
|
+
fi
|
|
93
|
+
|
|
94
|
+
echo ""
|
|
95
|
+
echo -e "${GREEN}════════════════════════════════════════════${NC}"
|
|
96
|
+
echo -e "${GREEN} All validation tests passed!${NC}"
|
|
97
|
+
echo -e "${GREEN}════════════════════════════════════════════${NC}"
|