fix(codex): add env_key to custom provider + model_catalog_json for picker
- Add env_key = "OPENAI_API_KEY" to [model_providers.custom] in PS1 fallback templates (fixes 401 Unauthorized on machines without Python 3.11+) - Add model_catalog_json config + model_catalog.json file generation (fixes empty model picker — all 4 models now visible in interactive mode) - Both fixes applied in: codex_patcher.py, ucodex_install.ps1, ucodex_update.ps1 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -44,6 +44,7 @@ RESET = "\033[0m"
|
||||
# Managed config keys (we update these, preserve everything else)
|
||||
MANAGED_TOP_KEYS = {
|
||||
"model", "model_reasoning_effort", "model_provider",
|
||||
"model_catalog_json",
|
||||
"approval_policy", "sandbox_mode",
|
||||
"check_for_update_on_startup", "forced_login_method",
|
||||
}
|
||||
@@ -163,6 +164,14 @@ def generate_config_toml(existing, config):
|
||||
lines.append(f'model = "{config["model"]}"')
|
||||
lines.append(f'model_reasoning_effort = "{config.get("model_reasoning_effort", "high")}"')
|
||||
lines.append('model_provider = "custom"')
|
||||
|
||||
# Model catalog path (for model picker)
|
||||
codex_dir = os.path.join(os.path.expanduser("~"), ".codex")
|
||||
catalog_path = os.path.join(codex_dir, "model_catalog.json")
|
||||
# Use forward slashes for cross-platform TOML compatibility
|
||||
catalog_path_toml = catalog_path.replace("\\", "/")
|
||||
lines.append(f'model_catalog_json = "{catalog_path_toml}"')
|
||||
|
||||
lines.append(f'approval_policy = "{config.get("approval_policy", "never")}"')
|
||||
lines.append(f'sandbox_mode = "{config.get("sandbox_mode", "danger-full-access")}"')
|
||||
lines.append(f'check_for_update_on_startup = {toml_value(config.get("check_for_update", False))}')
|
||||
@@ -464,6 +473,21 @@ def apply_all_patches(config, home_dir=None):
|
||||
# Backup before any changes
|
||||
backup_file(config_path)
|
||||
|
||||
# Generate model catalog JSON for model picker
|
||||
catalog_path = os.path.join(codex_dir, "model_catalog.json")
|
||||
models = config.get("models", [config["model"]])
|
||||
catalog_entries = []
|
||||
for m in models:
|
||||
catalog_entries.append({
|
||||
"id": m,
|
||||
"object": "model",
|
||||
"created": 1700000000,
|
||||
"owned_by": "system"
|
||||
})
|
||||
with open(catalog_path, "w", encoding="utf-8") as f:
|
||||
json.dump(catalog_entries, f, indent=2)
|
||||
print(f" {'[OK]':>8} Catalog: {catalog_path} ({len(models)} models)")
|
||||
|
||||
# Generate new config.toml (merge)
|
||||
new_content = generate_config_toml(existing, config)
|
||||
|
||||
@@ -574,6 +598,13 @@ def patch_user(user_home, config):
|
||||
existing = read_toml(config_path)
|
||||
backup_file(config_path)
|
||||
|
||||
# Generate model catalog
|
||||
catalog_path = os.path.join(codex_dir, "model_catalog.json")
|
||||
models = config.get("models", [config["model"]])
|
||||
catalog_entries = [{"id": m, "object": "model", "created": 1700000000, "owned_by": "system"} for m in models]
|
||||
with open(catalog_path, "w", encoding="utf-8") as f:
|
||||
json.dump(catalog_entries, f, indent=2)
|
||||
|
||||
new_content = generate_config_toml(existing, config)
|
||||
with open(config_path, "w", encoding="utf-8") as f:
|
||||
f.write(new_content)
|
||||
|
||||
Reference in New Issue
Block a user