opencode
opencode copied to clipboard
fix: merge auth methods from multiple plugins for the same provider
Fixes auth method conflicts when multiple plugins register for the same provider.
Problem
fromEntries()inprovider/auth.tsoverwrites duplicate provider keys (last plugin wins).find()in CLIauth.tsreturns only the first matching plugin- Plugins exporting aliases (e.g.,
GoogleOAuthPlugin = AntigravityCLIOAuthPlugin) get loaded twice
Solution
-
Plugin loader (
plugin/index.ts): Track called functions to skip aliased exports; store package name in_sourcefield -
Auth aggregation (
provider/auth.ts): ReplacefromEntries()with merge loop that accumulates methods from all plugins -
CLI auth (
cli/cmd/auth.ts): Aggregate methods from all matching plugins instead of using.find() -
Labeling: Non-native plugins show source in label (e.g., "Google API key (websearch-cited)"), except for generic "Manually enter API Key" which is the same as native fallback
Before
{ "google": [{ "type": "api", "label": "Google API key" }] }
After
{
"google": [
{ "type": "oauth", "label": "OAuth with Google (Antigravity) (antigravity)" },
{ "type": "api", "label": "Manually enter API Key" },
{ "type": "api", "label": "Google API key (websearch-cited)" }
]
}
Test Cases
- Single plugin per provider: works unchanged
- Multiple plugins, same provider: all methods merged
- Aliased exports: deduplicated (same function reference)
- Native plugins: no source suffix
- Non-native plugins: source suffix on distinctive methods
- Generic "Manually enter API Key": no suffix (same as native fallback)