opencode icon indicating copy to clipboard operation
opencode copied to clipboard

fix: merge auth methods from multiple plugins for the same provider

Open Davincible opened this issue 2 weeks ago • 0 comments

Fixes auth method conflicts when multiple plugins register for the same provider.

Problem

  • fromEntries() in provider/auth.ts overwrites duplicate provider keys (last plugin wins)
  • .find() in CLI auth.ts returns only the first matching plugin
  • Plugins exporting aliases (e.g., GoogleOAuthPlugin = AntigravityCLIOAuthPlugin) get loaded twice

Solution

  1. Plugin loader (plugin/index.ts): Track called functions to skip aliased exports; store package name in _source field

  2. Auth aggregation (provider/auth.ts): Replace fromEntries() with merge loop that accumulates methods from all plugins

  3. CLI auth (cli/cmd/auth.ts): Aggregate methods from all matching plugins instead of using .find()

  4. 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)

Davincible avatar Dec 27 '25 19:12 Davincible