Skip to content

feat(plugin): add getAuth, route, model.select and AuthLoaderResult to plugin SDK#16941

Closed
vglafirov wants to merge 12 commits intoanomalyco:devfrom
vglafirov:vglafirov/plugin-sdk-extensions
Closed

feat(plugin): add getAuth, route, model.select and AuthLoaderResult to plugin SDK#16941
vglafirov wants to merge 12 commits intoanomalyco:devfrom
vglafirov:vglafirov/plugin-sdk-extensions

Conversation

@vglafirov
Copy link
Copy Markdown
Contributor

@vglafirov vglafirov commented Mar 10, 2026

Issue for this PR

Extends the plugin SDK to support plugins that need auth access, HTTP routes, and model sub-selection. Part of the work to extract GitLab DAP workflow model support into a standalone plugin, keeping opencode core free of provider-specific code.

Type of change

  • New feature

What does this PR do?

Adds four backward-compatible type extensions to the plugin SDK (packages/plugin/src/index.ts):

  1. getAuth? on PluginInput — lets plugins retrieve stored auth credentials (OAuth tokens, API keys) for a provider. Plugins previously had no way to access auth state.

  2. AuthLoaderResult type — replaces untyped Record<string, any> return of AuthHook.loader with a type that optionally includes getModel, so auth loaders can provide custom model creation logic.

  3. route hook on Hooks — accepts either (app) => void (existing) or { prefix: string; handler: (app) => void } (new). Object form lets plugins specify a URL prefix so routes mount at /plugin/<prefix>/.

  4. model.select hook on Hooks — called when a model is selected. Plugins can resolve sub-models (e.g. a workflow model needing further discovery). Takes { providerID, modelID }, mutates { subModel?, displayName? }.

Also excludes route from Plugin.trigger() type constraint in packages/opencode/src/plugin/index.ts since route can be an object, not a callable function.

All changes are additive — existing plugins compile and work without modification.

How did you verify your code works?

  • 34 new tests in test/plugin/hooks.test.ts (14 tests) and test/plugin/trigger.test.ts (6 tests) plus the existing 14 in test/cli/plugin-auth-picker.test.ts
  • Tests verify: type correctness, backward compatibility, trigger constraints, hook chaining, optional getAuth, both route forms
  • bun turbo typecheck --filter=@opencode-ai/plugin passes
  • bun turbo typecheck --filter=opencode has no new errors (only pre-existing effect/account module errors on dev)
  • bun test test/plugin/ — 34 pass, 0 fail

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

…o plugin SDK

- Add optional getAuth to PluginInput for plugin auth credential access
- Add route hook (object form with prefix) for plugin HTTP routes
- Add model.select hook for sub-model resolution (e.g. workflow models)
- Add AuthLoaderResult type with optional getModel for auth loaders
- Exclude route from trigger type constraint (not a callable hook)
- Add tests for all new types and trigger constraints

All additions are backward-compatible with existing plugins.
@github-actions github-actions bot added needs:compliance This means the issue will auto-close after 2 hours. contributor labels Mar 10, 2026
@vglafirov vglafirov changed the title feat(plugin): add getAuth, route, model.select and AuthLoaderResult t… feat(plugin): add getAuth, route, model.select and AuthLoaderResult to plugin SDK Mar 10, 2026
@github-actions github-actions bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Mar 10, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@vglafirov vglafirov closed this Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant