fix(opencode): patch apiKey from PRAGENT_MODEL_API_KEY at install_config
opencode's @ai-sdk/anthropic provider sends the config's apiKey as the x-api-key header. The committed opencode.json carries apiKey="ollama" (placeholder) so the repo can be public. When the headroom upstream switches to an auth-gated provider (e.g. MiniMax), the placeholder returns 'No credentials found'. install_config now also patches options.apiKey from PRAGENT_MODEL_API_KEY when set, mirroring the existing baseURL patching. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -406,7 +406,8 @@ def install_config(src: str, dst: str) -> bool:
|
||||
if not os.path.isfile(src):
|
||||
return False
|
||||
base_url = os.environ.get("PRAGENT_MODEL_BASE_URL", "").strip()
|
||||
if not base_url:
|
||||
api_key = os.environ.get("PRAGENT_MODEL_API_KEY", "").strip()
|
||||
if not base_url and not api_key:
|
||||
shutil.copy2(src, dst)
|
||||
return True
|
||||
try:
|
||||
@@ -414,7 +415,10 @@ def install_config(src: str, dst: str) -> bool:
|
||||
cfg = json.load(f)
|
||||
for prov in (cfg.get("provider") or {}).values():
|
||||
if isinstance(prov, dict) and isinstance(prov.get("options"), dict):
|
||||
prov["options"]["baseURL"] = base_url
|
||||
if base_url:
|
||||
prov["options"]["baseURL"] = base_url
|
||||
if api_key:
|
||||
prov["options"]["apiKey"] = api_key
|
||||
with open(dst, "w", encoding="utf-8") as f:
|
||||
json.dump(cfg, f, indent=2)
|
||||
except (OSError, ValueError, AttributeError):
|
||||
|
||||
Reference in New Issue
Block a user