Files
openchamber/packages/web/server/lib/opencode/provider-env-aliases.js
T
Cursor AgentandSerhii Dziupin 321794a621 Mirror Google API key env aliases into managed OpenCode.
OpenCode can mark Google connected via GEMINI_API_KEY while the Generative AI
SDK only reads GOOGLE_GENERATIVE_AI_API_KEY, so chat asked for a key that was
already present. Alias unset sibling names on managed launch for web and VS Code.

Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com>
2026-08-03 13:18:27 +00:00

36 lines
989 B
JavaScript

/**
* Normalize provider credential env aliases for managed OpenCode.
*
* OpenCode may mark a provider as connected when any listed env key is present
* (e.g. GEMINI_API_KEY), while the upstream AI SDK only reads a different name
* (GOOGLE_GENERATIVE_AI_API_KEY). Mirror known aliases so chat works without
* forcing the user to paste the same key again in Settings.
*/
const GOOGLE_API_KEY_ALIASES = [
'GOOGLE_GENERATIVE_AI_API_KEY',
'GOOGLE_API_KEY',
'GEMINI_API_KEY',
];
export function applyProviderEnvAliases(env) {
if (!env || typeof env !== 'object') {
return {};
}
const next = { ...env };
const googleValue = GOOGLE_API_KEY_ALIASES
.map((key) => next[key])
.find((value) => typeof value === 'string' && value.trim().length > 0);
if (googleValue) {
for (const key of GOOGLE_API_KEY_ALIASES) {
if (typeof next[key] !== 'string' || next[key].trim().length === 0) {
next[key] = googleValue;
}
}
}
return next;
}