Add OpenCode provider with Go/Zen selector and session routing - #112
Open
wch wants to merge 3 commits into
Open
Conversation
OpenCode's hosted services (Go at opencode.ai/zen/go/v1, Zen at opencode.ai/zen/v1) reject inference requests without a stable conversation session header and ask clients for a product User-Agent (posit-dev/assistant#2384). - ChatRequestMetadata (root-exported) adds optional rootConversationId alongside sessionId; sessionId keeps feeding the Posit AI Pass Session-Id header and the prompt_cache_key projection unchanged. - New internal opencode-request-headers module privately owns the endpoint literals, route matching (exact host, Go/Zen roots, HTTPS default port), and header merging. OpenAIClient and AnthropicClient apply it per request on the resolved URL: the generated x-opencode-session wins over static custom-header workarounds, a user's static header is never stripped on non-matching routes, and nothing is generated without root metadata. - Matching discovery requests carry the host User-Agent (never a session header) via a new optional createCachedModelFetcher userAgent. - OpenAI/OpenAI-compatible/Anthropic registrars and factories (built-in and custom) accept an optional host User-Agent; an explicit custom User-Agent always wins. ProviderRegistrationConfig gains providerUserAgent, distinct from the Posit AI Pass userAgent so hosts can preserve that legacy identity. Wire regressions (failing before implementation) cover both endpoints, all three protocols, concurrent conversations, per-request endpoint overrides in both directions, lookalike hosts, mixed-case header collisions on both merge paths, and discovery.
Promote the OpenCode endpoint literals to ai-config exports (OPENCODE_GO_BASE_URL / OPENCODE_ZEN_BASE_URL) so the catalog's connection defaults and the bridge's header-policy matcher share one source of truth. - ai-config: opencode-go/opencode-zen built-in ids, openai client kind, base-URL connection defaults, base-only schema sections, and a probe-verified capability helper (2026-09-09 probes: Chat Completions is the only working inference route; /responses 500s, so no model carries an openai-responses stamp and unknown ids fall back to the client constructor default). - ai-credentials: OPENCODE_GO_API_KEY / OPENCODE_ZEN_API_KEY scrubbed env descriptors. - bridge: opencode-provider module (cached /models fetcher + OpenAI client factory with apiMode completions, both consuming the resolved credentials.baseUrl so configured overrides reach discovery and chat), registered for both ids with the host providerUserAgent.
Replace the opencode-go/opencode-zen built-in IDs with a single opencode
ID. The product choice persists as a scalar providers.opencode.product
field (go|zen, default zen) via a canonical per-provider scalar-field
schema mechanism, and resolves to the product endpoint once at catalog
build (explicit baseUrl > product selection > zen default).
ai-config owns an effective-product projection (opencodeProduct) with a
precedence-complete control state (editable | product-enforced |
base-url-override{source}) derived from per-field provenance; inertness
is authorship-based. The catalog watcher signature includes the
descriptor so product-only edits reach live hosts.
The bridge collapses to one registration and keys the discovery cache
on the resolved baseUrl so a product switch refetches the catalog.
Single credential env var: OPENCODE_API_KEY.
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.
Adds OpenCode support to the provider infrastructure in three parts:
opencodeprovider whoseproductsetting (goorzen, defaultzen) resolves to the corresponding endpoint at catalog build. One workspace key works for both products, and the per-product env vars collapse toOPENCODE_API_KEY.An explicit
baseUrlstill wins over the product default. Resolution also derives an effective-product projection (editable / product-enforced / base-url-override) for hosts to consume, and the configuration watch signature fires on product-only edits so live changes reach running hosts without a restart.The companion monorepo PR consumes these changes through the updated submodule pin.