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>
This commit is contained in:
co-authored by
Serhii Dziupin
parent
9cccc8d667
commit
321794a621
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
Reference in New Issue
Block a user