Repository navigation
Conversation
Route each OpenCode Go model to the API protocol serving it (OpenAI chat completions, Anthropic messages, or OpenAI responses) by delegating to the existing provider adapters, refresh the model-to-protocol mapping from GET /models metadata, and send a per-conversation x-opencode-session header with a stable fallback. Register the provider in the manager and add the WebUI config template, provider icon, selector ordering and i18n descriptions.
Contributor
There was a problem hiding this comment.
Hey - I've found 3 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="astrbot/core/provider/sources/opencode_go_source.py" line_range="283" />
<code_context>
+ self.provider_config.get("api_base") or OPENCODE_GO_API_BASE
+ ).rstrip("/")
+ try:
+ headers = build_provider_headers(self.provider_config.get("custom_headers"))
+ async with create_proxy_client(
+ "OpenCodeGo",
</code_context>
<issue_to_address>
**Live models stay unavailable**
When the gateway requires bearer authentication for GET /models, `get_models` omits the configured provider API key from its custom-header-only request, so the gateway rejects it and the exception handler returns only seeded models; callers cannot discover live models or refresh protocol mappings.
Add the configured API key as a bearer Authorization header to the `/models` request.
</issue_to_address>
### Comment 2
<location path="astrbot/core/provider/sources/opencode_go_source.py" line_range="214" />
<code_context>
+ **(delegate_config.get("custom_headers") or {}),
+ # The Anthropic SDK only sends x-api-key; the gateway expects
+ # the same bearer token as the other protocols.
+ "Authorization": f"Bearer {self.get_current_key()}",
+ }
+ self._anthropic = _OpenCodeAnthropic(
</code_context>
<issue_to_address>
**Rotated keys fail Anthropic requests**
When the active API key changes after the Anthropic delegate is created, `_get_anthropic` snapshots `get_current_key()` in the delegate’s Authorization header, so later Anthropic requests keep using the old key and fail authentication.
Update the Anthropic delegate’s Authorization header to use the current API key when the active key changes.
</issue_to_address>
### Comment 3
<location path="astrbot/core/provider/sources/opencode_go_source.py" line_range="217-218" />
<code_context>
+ "Authorization": f"Bearer {self.get_current_key()}",
+ }
+ self._anthropic = _OpenCodeAnthropic(
+ delegate_config, self._provider_settings
+ )
+ return self._anthropic
+
</code_context>
<issue_to_address>
**Delegate clients remain open**
When the provider is terminated after either delegate has been initialized, the inherited `ProviderOpenAIOfficial.terminate` closes only the outer client, leaving the Anthropic and Responses delegate clients open and leaking their HTTP resources.
Override `terminate` to close the clients created by both delegates as well as the outer client.
Also at `astrbot/core/provider/sources/opencode_go_source.py:229-230`.
</issue_to_address>Sourcery assessment
Approval pending. 3 findings to address first.
Blocking findings: astrbot/core/provider/sources/opencode_go_source.py:283, astrbot/core/provider/sources/opencode_go_source.py:214, astrbot/core/provider/sources/opencode_go_source.py:218
- Authenticate GET /models with the configured bearer key so live models and protocol mappings can be refreshed - Inject the current bearer key per request on protocol delegates so key rotation is picked up (covers Anthropic and Responses delegates) - Close both protocol delegate clients in terminate() so provider removal does not leak HTTP resources
This branch has not been deployed
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.
Summary
Test plan
Summary by Sourcery
Add OpenCode Go as a configurable multi-protocol provider source.
New Features:
Enhancements:
Chores: