feat(plugin): add request-scoped chat.model hook - #40188
Open
millsydotdev wants to merge 1 commit into
Open
Conversation
This was referenced Aug 2, 2026
Author
|
This is a first-contributor PR from a fork, so the typecheck/test/nix-eval workflows are waiting for maintainer approval before they run (status: action_required). Everything they check has been verified locally:
Could someone approve the workflow runs? Happy to adjust anything on review. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes:
Addresses / partially addresses:
Type of change
What does this PR do?
Adds a request-scoped
chat.modelplugin hook that fires before provider/model/auth resolution. A plugin can replace the model for a single request without changing the session's selected model. Enables per-task routing (local vs cloud, fast vs heavy) without session mutation.This is a rework of the earlier #30457 implementation against the current dev API (
provider.getModelwithProviderV2.ID/ModelV2.ID,SessionV1.User, currentllm.tsstructure). Thechat.modelhook type is added to@opencode-ai/plugin; the LLM run path triggers it and resolves the routed model via the provider service;chat.headersand downstream hooks see the routed model; logs includeroutedFrom+reasonfor observability.No models are hardcoded anywhere. The hook output must reference models from the user.s provider configuration.
How did you verify your code works?
packages/opencode/test/session/llm.test.ts: noop route keeps the original model, routing replaces the model for the request, and the hook receives session/agent/message context. Full file: 31 pass / 0 fail.bun run typecheck: 30/30 packages pass.bun run lint: no new issues in changed files (the repo's single pre-existing lint error is inpackages/app/test-browser/prompt-persistence.test.ts, untouched).chat.modelexample added to the plugins docs (config/env-driven, no hardcoded models).Screenshots / recordings
n/a
Checklist