Repository navigation
feat: configure OpenAI-compatible model providers (on top of the audit) - #2
Conversation
The packaged OpenCode 2.4.1 web interface has no provider screen, so there was no way to point the service at a model without shelling into the container. Add a Configure Model Providers action that writes provider entries into OpenCode's own config on the main volume, and keeps each provider's API key on the startos volume, passed to the server as OPENCODE_KEY_<ID>.
MattDHill
left a comment
There was a problem hiding this comment.
Thanks — #1 is merged (with a merge commit, so this PR's diff is now just the provider feature), and we're following your order: this one next, then #3.
Connecting a self-hosted endpoint without a shell is worth having. The upstream catalog has no entry that takes your own vLLM or Ollama URL on the LAN. The change needs these fixes first:
1. The served 2.4.1 web app does have a provider screen. We ran the pinned image (2.4.1@sha256:10e340e3…) and pulled the UI bundle opencode serve serves. Settings → Providers is in it, registered as one of the server tabs (providers, models, extensions, projects, workspaces) alongside the "Connect an integration" dialog. /api/integration lists 334 hosted providers, OpenRouter, Anthropic, OpenAI and LM Studio among them. OpenCode also works with no provider at all: its default opencode/big-pickle model needs no key, and we had the agent write a file into a project with nothing configured. What did you see when you looked for the screen? Your verification notes say you drove the package through start-cli only.
So the docs should say: hosted providers connect in Settings → Providers, and this action is for OpenAI-compatible endpoints the catalog can't reach. Please change these lines:
- instructions step 4 ("Before OpenCode can answer anything it needs a model to use")
- the instructions limitation "The web app in this version has no provider screen"
- the README's "It is the only way to connect a model: the packaged OpenCode web interface has no provider screen of its own", and the same claim in its install section
2. Please don't reintroduce what #1 removed.
- The README says "pinned to a released tag" again, but the Dockerfile pins the tag and digest.
- "Nothing upstream is disabled or skipped" contradicts the disabled self-updater.
- "A
warningis shown before it runs" restates action metadata the OS already reports. - The instructions parenthetical "(enable an address there if none is enabled yet)" explains StartOS rather than this package.
- In
AGENTS.md: the "Working here" block is generic to every package, the port bullet is moot (it's one constant), and the image-pin bullet duplicatesUPDATING.md. The packaging guide asksAGENTS.mdfor only what README and instructions can't say. New bullets for this feature are welcome in that form.
3. Have the action manage only the providers it creates. Each save rebuilds the whole providers map and model from the form, so it also overwrites entries the user or OpenCode wrote:
- A provider added by hand without
settings.baseURL(any catalog provider) prefills an empty Base URL, which is required, so the form can't be saved at all. - A key written directly into the config (
settings.apiKey: "sk-…") prefills blank, since it isn't inproviderKeys, and saving deletes it. - Saving with no Default ticked clears a
modelset to anything else.
Scoping the action to entries using @opencode/ai/providers/openai-compatible, and touching model only when it names one of them, closes all three.
4. Comments. Several new ones are paragraphs explaining the reasoning (opencode.json.ts, store.json.ts, main.ts, utils.ts, the action). Please cut each to the one fact the code can't show, or drop it; the reasoning belongs in the PR body. #1 did the same trim on the existing files.
Once this is revised we'll build and test it on a box. #3 can then be rebased onto it. We'll review its CA work separately.
Addresses the review on #2. - The action now owns only the providers it wrote: the `opencode.json` entries carrying `package: @opencode/ai/providers/openai-compatible`. It prefills and rebuilds those, and copies every other entry — and a `model` that names none of them — through untouched. `model` is now changed only when a Default is set or when it names a managed provider this save removes, so saving with nothing ticked no longer clears a model set to something else. - Docs: the served 2.4.1 web app does have Settings → Providers (the catalog lists 334 providers, and OpenCode ships a free default model). Restore the audit's step 4 and correct the "no provider screen" claims in `instructions.md` and `README.md`: hosted providers connect in the app, and this action is for OpenAI-compatible endpoints the catalog cannot reach. - Restore claims #1 had already removed: the image is pinned by tag and digest; drop "nothing upstream is disabled or skipped" (the self-updater is off), the warning restatement, and the StartOS address parenthetical. - Trim AGENTS.md to rules: drop the generic "Working here" block, the port bullet, and the image-pin bullet, and add the scoping rule for the action. - Cut the new comments to one fact each.
|
Thanks — you're right on the substance. Answering your question directly first: we never looked at the served UI. Our verification notes came from driving the package through
So the claim was wrong. Fixed and pushed as
|
MattDHill
left a comment
There was a problem hiding this comment.
Thanks, this addresses everything. We tested 48b957f on a StartOS 0.4.3 box (x86_64), installed as an update over the released 2.4.1:0:
- Update: a session created on
2.4.1:0survived the update to2.4.1:1. No task was raised and the service stayed running. - Scoping: we hand-wrote an unmanaged provider (no
baseURL), amodelofopencode/big-pickle, and an unrelated key intoopencode.json. The form's prefill left the unmanaged entry out. Saving a managed provider kept all three hand edits, and the API key went only tostore.json, referenced as{env:OPENCODE_KEY_ZEN}. - Key delivery: the running server carried
OPENCODE_KEY_ZEN, and/api/providerlisted the provider. - Real use: with the action's provider set as Default, a new session ran on it end to end. We pointed it at OpenCode's own OpenAI-compatible endpoint with the key
public, and the reply came back fromzen/big-pickle. - Removal: an empty form removed the managed entry, its key, and the
modelthat named it. The unmanaged entry and the other key stayed, the variable left the server's environment after the restart, and health stayed green with clean logs.
A few small things to pick up when you rebase #3; none blocks this:
- README § Tasks has gone back to "most plausibly a restore that brought back
mainwithout thestartosvolume". Both volumes are always backed up together, so #1's wording ("It returns only ifstore.jsonloses the password") is the accurate one. - The provider explanation appears three times in instructions: step 4, the new section, and a Limitations bullet. The same goes for the README's Limitations. It isn't a limitation, so the bullets can go.
- An ID that collides with an unmanaged entry (say
openrouter, hand-added) gets silently turned into a managed one on save. Rejecting an ID that matches an unmanaged entry would prevent that. - A hand-written OpenAI-compatible entry with a literal
settings.apiKeynow counts as managed. Its key prefills blank, so a save deletes it. Prefilling fromsettings.apiKeywhen it isn't an{env:…}reference would carry it over intoproviderKeys.
On #3, once it's rebased on this, the open items are:
v2_4_1_1.tsisn't needed (it carries no migration);- the CA mount path doesn't need to be keyed by the certificate's hash, since a change read with
.const()already restarts the daemon; - the README's CA-action section is missing the when/cost/repeat-safety notes;
- the manifest comment about the CA subtree needs a rewrite.
helix-white
left a comment
There was a problem hiding this comment.
Reviewed 48b957f. Requesting changes for one additional compatibility problem:
P2 — Read OpenCode's supported configuration format (startos/fileModels/opencode.json.ts). The pinned 2.4.1 loader accepts comments and trailing commas in opencode.json, not just in .jsonc files. SDK 4.1.0's FileHelper.json calls JSON.parse. An existing, valid OpenCode configuration containing either therefore prevents the new action's form from opening. The proposal uses the same JSONC parser as upstream through FileHelper.raw, retains unknown fields, and rejects malformed input rather than saving a partial parse.
The proposal also closes the two ownership holes already identified in Matt's review:
- A submitted ID matching an unmanaged entry overwrites that entry and changes its provider package. Reject that collision inside the config update, before changing either file.
- A hand-written compatible provider's literal
settings.apiKeyprefills blank and is deleted on save. Prefill the literal key, including when it supersedes an older stored key, then move it intoproviderKeyson save.
It includes the previously noted restore-wording and duplicate-limitations cleanup, accurate ownership/JSONC documentation, and trimmed commentary. It leaves #3's CA, alias, and default-selection work alone. Please also update this PR's opening description: it still claims the web app has no provider screen, contrary to the corrected docs and discussion.
The reviewed head merges cleanly with master; all three current CI checks passed. This was a code-only review: I did not build, typecheck, lint, or test the proposal. Please verify a commented/trailing-comma config, an unmanaged-ID collision with neither file changed, and a literal-key round trip when adopting it.
Proposed changes: 48b957f...proposal/2
To adopt the proposal, cherry-pick it onto your branch rather than merging or pulling it, so the PR's head stays your own commit:
git fetch https://github.com/Start9-Community/opencode-startos.git proposal/2
git cherry-pick 48b957fe3b57aeaee30fd12e925aeda792c2561f..FETCH_HEADIf your branch has moved since 48b957f, resolve any conflicts the cherry-pick reports, or apply the changes your own way. Then push and say so in a comment.
Helix-Harness: pi
Helix-Model: openai-codex/gpt-6.1-sol
Helix-Harness: pi Helix-Model: openai-codex/gpt-6.1-sol
Helix-Harness: claude-code Helix-Model: claude-opus-5-5
helix-white
left a comment
There was a problem hiding this comment.
Re-reviewed 3cac22f. It is the earlier proposal as adopted, plus a reworded comment and Prettier's parentheses, and it merges cleanly with master. Nobody has run that proposal yet, so before the verdict I checked it against the pinned sources:
- JSONC. OpenCode 2.4.1 parses its config with the same call (
parse(text, errors, { allowTrailingComma: true })), and it too rejects an empty or malformed file. The README states that saving drops comments. - Nested update. SDK 4.1.0 queues file locks per path and rejects only a nested mutation of the same file, so the
store.jsonupdate inside theopencode.jsonupdate takes its own lock. Nothing else writesopencode.json, so the lock order cannot invert. The nested write runs inside the outer callback's 5-second deadline. - Bundling. Under
ncc,jsonc-parserresolves to its UMD build. I read the bundledjavascript/index.jsin this run's x86_64 artifact: the wrapper'srequireparameter is gone and each./impl/*import is__nccwpck_require__(<id>), so the module loads.
I'm requesting changes for one defect you can reach from the form alone, plus two hand-edit losses in the same code:
- Default can't be turned off. When
modelnames a managed provider that stays in the form, un-ticking its Default leavesmodelunchanged, because the save dropsmodelonly when that provider is removed. Reopening the form shows the toggle on again, and new sessions keep starting on that model. The proposal dropsmodelwhenever it names a managed entry and no toggle is on. That is the rule from Matt's first review ("touchingmodelonly when it names one of them"), and the oneAGENTS.mdrecords. OpenCode then falls back to its own choice, as it does out of the box (Model.default()takes the first available text model). Amodelnaming anything else is still left alone.shownModelis now read from the final value. - Any save replaces a hand-set default that isn't the provider's first model. Default always writes the first listed model, but the prefill lists models in file order. So
model: "vllm/qwen", withvllmlistingglm, qwen, opens with Default on, and an unchanged save (say, while adding another provider) switches the default tovllm/glm. The prefill now lists the current default model first. - A key reference on a hand-written compatible entry is deleted. The prefill blanks any
settings.apiKeycontaining{env:or{file:, so a hand-written"{file:~/.secrets/vllm-key}"is deleted on save and the provider loses its auth. The prefill now blanks only the action's own{env:OPENCODE_KEY_<ID>}, which it still reads back fromstore.json, and shows anything else as written. On save, an{env:…}or{file:…}key goes back into the entry verbatim and stays out ofproviderKeys; OpenCode resolves it itself.
The README (What it changes, Repeat safety) and the instructions are updated to match. The proposal adds no strings, so i18n is unchanged.
Please also update the PR description, as asked last round. It still says the web app has no provider screen, and its verification section describes 797e954. This doesn't block the PR, but a squash merge that uses the description would put that text into history.
This was a code-only review: I did not build, typecheck, lint, or run the proposal. I checked new lines against Prettier's 80 columns by hand. When adopting it, please run tsc and Prettier, and exercise:
- Default on, reopen, turn it off, save:
modelis dropped and the form reopens with Default off. - A hand-set
modelnaming a provider's second model survives an unchanged save. - A hand-written compatible entry with
"apiKey": "{file:…}"keeps it after a save, andstore.jsonholds no key for it.
Proposed changes: 3cac22f...proposal/2
To adopt the proposal, cherry-pick it onto your branch rather than merging or pulling it, so the PR's head stays your own commit:
git fetch https://github.com/Start9-Community/opencode-startos.git proposal/2
git cherry-pick 3cac22ff1f36e5b109076d11aa36bb9d2a9caf34..FETCH_HEAD
If your branch has moved since 3cac22f, resolve any conflicts the cherry-pick reports, or apply the changes your own way. Then push and say so in a comment.
Helix-Harness: claude-code
Helix-Model: claude-opus-5-5
|
Thanks — adopted the proposal. Cherry-picked Verified on a StartOS 0.4.2 box with the CI-built
@MattDHill — your four small items (README § Tasks wording, the repeated provider explanation, the ID collision, the literal key) are all in the proposal and verified above. Your #3 list — drop |
MattDHill
left a comment
There was a problem hiding this comment.
Approving 3cac22f. We ran the same three cases on our box (a commented config with trailing commas, the ID collision with neither file changed, the literal-key round trip with a prompt through that provider), and both arches built in CI. Thanks for turning these rounds around so quickly.
Merging #2 as is. Start9 is taking this review's three fixes (proposal/2) in its own follow-up PR, so nothing more is needed from the submitter here.
|
Merged — thank you, and sorry for the number of rounds. Each time you did exactly what we asked, and each review turned up something we should have caught the round before. That's on our side, not yours. helix-white's last review found three more edge cases:
Two were already in the code we approved, and the third came from our own proposal. We're fixing all three ourselves in a follow-up PR against For #3, rebase onto |
What this adds
OpenCode's own web app connects hosted providers under Settings → Providers — its catalog lists 334 (OpenRouter, Anthropic, OpenAI, LM Studio among them) — and answers out of the box on a free
opencodemodel. What the packaged 2.4.1 build could not do without a shell is connect an OpenAI-compatible endpoint the catalog has no entry for: a self-hosted vLLM, LM Studio, or Ollama server on the LAN. This adds a Configure Model Providers action for exactly that.For each provider the action writes an entry into OpenCode's own config (
main/.config/opencode/opencode.json, on themainvolume) and keeps the API key on thestartosvolume, handed to the server as anOPENCODE_KEY_<ID>environment variable and referenced from the config as{env:OPENCODE_KEY_<ID>}— so no secret is written to the config file. The config file is hot-reloaded by OpenCode, so a provider-only change needs no restart; a new or changed key restarts the daemon so the variable is picked up.It is layered on top of
chore/community-audit(#1), so it inherits the digest pin and thepackageRepomove and adds only the feature:startos/actions/configureProviders.ts— one repeatable provider list (id, name, base URL, optional masked key, models, default toggle)startos/fileModels/opencode.json.ts— a tolerant JSONC model of OpenCode's own config (comments and trailing commas accepted, unknown keys preserved)startos/fileModels/store.json.ts— addsproviderKeysstartos/main.ts— injects each stored key asOPENCODE_KEY_<ID>, reactivelystartos/utils.ts,startos/actions/index.ts, i18n in 5 locales, README / instructions / AGENTSBumps
2.4.1:0→2.4.1:1. No migration — the change is an added optional key.Ownership
The action owns only the entries it writes — those carrying
package: @opencode/ai/providers/openai-compatible. It prefills and rebuilds those, keeps every otherprovidersentry verbatim, and touchesmodelonly when this save sets a Default or when it names a managed provider this save removes. A submitted ID that collides with an unmanaged entry is rejected before either file changes. A hand-written compatible entry's literalsettings.apiKeyis prefilled and moved intoproviderKeyson save.Correcting the earlier provider claim
An earlier revision of this PR — and of #1's provider lines — claimed the served 2.4.1 UI had no provider screen. That was wrong: we had only driven the package through
start-cliand inferred the UI from upstream rather than from the running app. The served bundle does carry Settings → Providers (/api/integration= 334 providers;/api/modelshows the free default). The docs now say hosted providers connect in the app, and this action is for OpenAI-compatible endpoints the catalog cannot reach.Verification
Adopted helix-white's
proposal/2(JSONC parsing viaFileHelper.raw, ID-collision rejection, literal-key carry-over, doc cleanup) by cherry-pick, plus two small deltas: a Prettier paren in the prefill ternary, and one stale code comment reworded.Installed the CI-built
x86_64package (2.4.1:1) on a StartOS 0.4.2 box, over data preserved from the released build, and drove the action throughstart-cli:opencode.jsonwith comments and trailing commas (a file plainJSON.parserejects) plus one managed and one unmanaged provider. The action's prefill read it (get-inputreturned the managed entry with its literal key) and a save rewrote the file as JSON — the form opens.openrouter, an unmanaged entry, failed withProvider ID "openrouter" belongs to a provider configured outside this action. Choose another ID., and bothopencode.jsonandstore.jsonwere byte-for-byte unchanged.settings.apiKey: "sk-…"prefilled that literal; on save the config became{env:OPENCODE_KEY_LAB}, the literal moved intostore.json → providerKeys, the unmanaged entry and amodelofopencode/big-picklewere preserved, and the running daemon carriedOPENCODE_KEY_LAB.theme,autoupdate) all behave as intended.tsc --noEmitand Prettier are clean; both arches build in CI.