From 1be68ed36212da730bcbb109c8315ba89e547fec Mon Sep 17 00:00:00 2001 From: Matt Hill <9935159+MattDHill@users.noreply.github.com> Date: Sat, 28 Nov 2026 12:49:43 -0700 Subject: [PATCH 1/2] feat: connect Ollama, vLLM and llama.cpp on the same server - Connect Local Models action: opt in to each installed backend; each becomes an optional dependency while connected and installed - main.ts resolves each backend's bridge address and its public credentials reactively and hands OpenCode the providers in OPENCODE_CONFIG_CONTENT, never in opencode.json - Ollama goes through OpenCode's built-in Ollama provider for live model discovery; vLLM serves the model it publishes, with tool calling on; llama.cpp is one model that llama-server answers with whatever it serves - a `mounts` volume, not backed up, holds the backends' mounted public volumes - Configure Model Providers reserves the ids ollama, vllm and llama-cpp - README, instructions and release notes cover the integrations Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 5 + README.md | 98 +++++++++--- instructions.md | 34 ++++- package-lock.json | 171 ++++++++++++++++++++- package.json | 5 +- startos/actions/configureProviders.ts | 12 +- startos/actions/connectLocalModels.ts | 62 ++++++++ startos/actions/index.ts | 2 + startos/dependencies.ts | 27 ++++ startos/fileModels/store.json.ts | 2 + startos/i18n/dictionaries/default.ts | 8 +- startos/i18n/dictionaries/translations.ts | 32 +++- startos/localModels.ts | 174 ++++++++++++++++++++++ startos/main.ts | 9 ++ startos/manifest/index.ts | 3 +- startos/versions/current.ts | 10 +- 16 files changed, 609 insertions(+), 45 deletions(-) create mode 100644 startos/actions/connectLocalModels.ts create mode 100644 startos/localModels.ts diff --git a/AGENTS.md b/AGENTS.md index 69f4316..eecb9c9 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -21,3 +21,8 @@ bare clone with no workspace, the full guide is at - NODE_EXTRA_CA_CERTS -dependencies: none + - OPENCODE_CONFIG_CONTENT +dependencies: [ollama, vllm, llama-cpp] # all optional interfaces: ui: { type: ui, port: 4096 } actions: - set-admin-password - configure-providers - configure-provider-ca + - connect-local-models tasks: - { action: set-admin-password, severity: critical } health_checks: diff --git a/instructions.md b/instructions.md index 2ead80f..899c3dc 100644 --- a/instructions.md +++ b/instructions.md @@ -32,9 +32,11 @@ StartOS server. You use it from a browser: 4. Choose a model. Out of the box OpenCode uses a free model hosted by OpenCode, so your prompts and code are sent to OpenCode's servers. To use a hosted provider instead, open **Settings → Providers** in the web app and connect it - (an API key, or your OpenCode Console account). For an OpenAI-compatible - endpoint the app's catalog cannot reach — your own vLLM, LM Studio, or Ollama - server — run the **Configure Model Providers** action from StartOS; see + (an API key, or your OpenCode Console account). To keep everything on your + server, install Ollama, vLLM, or llama.cpp from the Start9 registry and run + **Connect Local Models** — see + [Using models on this server](#using-models-on-this-server). For any other + OpenAI-compatible endpoint, run **Configure Model Providers**; see [Connecting a model provider](#connecting-a-model-provider). 5. Back on the home screen, click **Add project** and choose a folder to work in. Pick a folder inside your home directory (`~/…`, shown as `root` when you @@ -55,15 +57,33 @@ open past sessions, and change settings from the sidebar. The same address also serves the HTTP API under `/api/*`, if you want to drive the server from your own scripts. +### Using models on this server + +Install **Ollama**, **vLLM**, or **llama.cpp** on this server and give it a +model the way its own instructions describe. Then run **Connect Local Models** +in OpenCode, check the services to connect, and save. OpenCode restarts, and +their models appear in its model list: + +- **Ollama** — every model you have pulled, kept up to date as you pull more. +- **vLLM** — the model vLLM is serving. Change it with vLLM's **Set Model**, and + OpenCode follows. +- **llama.cpp** — one entry, **llama.cpp**, which uses whatever model + llama.cpp's **Set Model** chose. + +A service has to be running for its models to work. Run **Connect Local +Models** again and uncheck a service to disconnect it. Your prompts and code +stay on your server. + ### Connecting a model provider Hosted providers connect inside the web app, under **Settings → Providers**. The **Configure Model Providers** action is for an OpenAI-compatible endpoint the -app's catalog has no entry for — a vLLM, LM Studio, or Ollama server on your -network. Run it from StartOS; each entry asks for: +app's catalog has no entry for — a vLLM, LM Studio, or Ollama server elsewhere +on your network. Run it from StartOS; each entry asks for: -- **ID** — a short name used to identify the provider (`vllm`). Lowercase - letters, digits, and dashes. +- **ID** — a short name used to identify the provider (`lab`). Lowercase + letters, digits, and dashes. `ollama`, `vllm`, and `llama-cpp` are reserved + for **Connect Local Models**. - **Name** — how the provider appears in OpenCode's model list (`Lab vLLM`). - **Base URL** — the endpoint's API root, including `/v1`, for example `http://192.168.1.50:8000/v1`. diff --git a/package-lock.json b/package-lock.json index 5913b16..5ee6448 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,7 +7,10 @@ "name": "opencode-startos", "dependencies": { "@start9labs/start-sdk": "4.1.0", - "jsonc-parser": "3.3.1" + "jsonc-parser": "3.3.1", + "llama-cpp-startos": "github:Start9Labs/llama-cpp-startos#next", + "ollama-startos": "github:Start9Labs/ollama-startos#next", + "vllm-startos": "github:Start9Labs/vllm-startos#next" } }, "node_modules/@eslint-community/eslint-utils": { @@ -285,6 +288,154 @@ "zod": "4.6.7" } }, + "node_modules/@start9labs/start-sdk/node_modules/@start9labs/start-core": { + "inBundle": true, + "license": "MIT", + "dependencies": { + "@iarna/toml": "^3.0.0", + "@noble/curves": "^1.9.7", + "@noble/hashes": "^1.8.0", + "deep-equality-data-structures": "^2.0.0", + "isomorphic-fetch": "^3.0.0", + "mime": "^4.1.0", + "yaml": "^2.8.3", + "zod": "4.6.7" + } + }, + "node_modules/@start9labs/start-sdk/node_modules/@start9labs/start-core/node_modules/@iarna/toml": { + "version": "3.0.0", + "inBundle": true, + "license": "ISC" + }, + "node_modules/@start9labs/start-sdk/node_modules/@start9labs/start-core/node_modules/@noble/curves": { + "version": "1.9.7", + "inBundle": true, + "license": "MIT", + "dependencies": { + "@noble/hashes": "1.8.0" + }, + "engines": { + "node": "^14.21.3 || >=16" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/@start9labs/start-sdk/node_modules/@start9labs/start-core/node_modules/@noble/hashes": { + "version": "1.8.0", + "inBundle": true, + "license": "MIT", + "engines": { + "node": "^14.21.3 || >=16" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/@start9labs/start-sdk/node_modules/@start9labs/start-core/node_modules/deep-equality-data-structures": { + "version": "2.0.0", + "inBundle": true, + "license": "MIT", + "dependencies": { + "object-hash": "^3.0.0" + } + }, + "node_modules/@start9labs/start-sdk/node_modules/@start9labs/start-core/node_modules/isomorphic-fetch": { + "version": "3.0.0", + "inBundle": true, + "license": "MIT", + "dependencies": { + "node-fetch": "^2.6.1", + "whatwg-fetch": "^3.4.1" + } + }, + "node_modules/@start9labs/start-sdk/node_modules/@start9labs/start-core/node_modules/mime": { + "version": "4.1.1", + "funding": [ + "https://github.com/sponsors/broofa" + ], + "inBundle": true, + "license": "MIT", + "bin": { + "mime": "bin/cli.js" + }, + "engines": { + "node": ">=16" + } + }, + "node_modules/@start9labs/start-sdk/node_modules/@start9labs/start-core/node_modules/node-fetch": { + "version": "2.7.0", + "inBundle": true, + "license": "MIT", + "dependencies": { + "whatwg-url": "^5.0.0" + }, + "engines": { + "node": "4.x || >=6.0.0" + }, + "peerDependencies": { + "encoding": "^0.1.0" + }, + "peerDependenciesMeta": { + "encoding": { + "optional": true + } + } + }, + "node_modules/@start9labs/start-sdk/node_modules/@start9labs/start-core/node_modules/object-hash": { + "version": "3.0.0", + "inBundle": true, + "license": "MIT", + "engines": { + "node": ">= 6" + } + }, + "node_modules/@start9labs/start-sdk/node_modules/@start9labs/start-core/node_modules/tr46": { + "version": "0.0.3", + "inBundle": true, + "license": "MIT" + }, + "node_modules/@start9labs/start-sdk/node_modules/@start9labs/start-core/node_modules/webidl-conversions": { + "version": "3.0.1", + "inBundle": true, + "license": "BSD-2-Clause" + }, + "node_modules/@start9labs/start-sdk/node_modules/@start9labs/start-core/node_modules/whatwg-fetch": { + "version": "3.6.20", + "inBundle": true, + "license": "MIT" + }, + "node_modules/@start9labs/start-sdk/node_modules/@start9labs/start-core/node_modules/whatwg-url": { + "version": "5.0.0", + "inBundle": true, + "license": "MIT", + "dependencies": { + "tr46": "~0.0.3", + "webidl-conversions": "^3.0.0" + } + }, + "node_modules/@start9labs/start-sdk/node_modules/@start9labs/start-core/node_modules/yaml": { + "version": "2.9.1", + "inBundle": true, + "license": "ISC", + "bin": { + "yaml": "bin.mjs" + }, + "engines": { + "node": ">= 14.6" + }, + "funding": { + "url": "https://github.com/sponsors/eemeli" + } + }, + "node_modules/@start9labs/start-sdk/node_modules/@start9labs/start-core/node_modules/zod": { + "version": "4.6.7", + "inBundle": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/colinhacks" + } + }, "node_modules/@types/estree": { "version": "1.0.10", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.10.tgz", @@ -1235,6 +1386,12 @@ "node": ">= 0.8.0" } }, + "node_modules/llama-cpp-startos": { + "resolved": "git+ssh://git@github.com/Start9Labs/llama-cpp-startos.git#1e0265881d8fb48830df5c60d2ac909a336ec7c9", + "dependencies": { + "@start9labs/start-sdk": "4.1.0" + } + }, "node_modules/locate-path": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", @@ -1324,6 +1481,12 @@ "node": ">= 6" } }, + "node_modules/ollama-startos": { + "resolved": "git+ssh://git@github.com/Start9Labs/ollama-startos.git#0c165e6192b7b036498d2e7b262750dcf2ea2628", + "dependencies": { + "@start9labs/start-sdk": "4.1.0" + } + }, "node_modules/optionator": { "version": "0.9.4", "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.4.tgz", @@ -1639,6 +1802,12 @@ "punycode": "^2.1.0" } }, + "node_modules/vllm-startos": { + "resolved": "git+ssh://git@github.com/Start9Labs/vllm-startos.git#8f957d46f73324faace208ef964176ebe21fc8a9", + "dependencies": { + "@start9labs/start-sdk": "4.1.0" + } + }, "node_modules/webidl-conversions": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", diff --git a/package.json b/package.json index ba339ce..dd3799f 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,10 @@ "name": "opencode-startos", "dependencies": { "@start9labs/start-sdk": "4.1.0", - "jsonc-parser": "3.3.1" + "jsonc-parser": "3.3.1", + "llama-cpp-startos": "github:Start9Labs/llama-cpp-startos#next", + "ollama-startos": "github:Start9Labs/ollama-startos#next", + "vllm-startos": "github:Start9Labs/vllm-startos#next" }, "overrides": { "@start9labs/start-sdk": "$@start9labs/start-sdk" diff --git a/startos/actions/configureProviders.ts b/startos/actions/configureProviders.ts index b1a703f..9db8c32 100644 --- a/startos/actions/configureProviders.ts +++ b/startos/actions/configureProviders.ts @@ -1,6 +1,7 @@ import { opencodeJson } from '../fileModels/opencode.json' import { storeJson } from '../fileModels/store.json' import { i18n } from '../i18n' +import { localBackendIds } from '../localModels' import { sdk } from '../sdk' import { openAiCompatiblePackage, providerKeyEnvVar } from '../utils' @@ -40,7 +41,7 @@ const providerShape = InputSpec.of({ id: Value.text({ name: i18n('ID'), description: i18n( - 'A short identifier for this provider, used to select it. Lowercase letters, digits, and dashes, for example `vllm`.', + 'A short identifier for this provider, used to select it. Lowercase letters, digits, and dashes, for example `lab`.', ), required: true, default: null, @@ -190,6 +191,15 @@ export const configureProviders = sdk.Action.withInput( if (input.providers.filter((provider) => provider.isDefault).length > 1) { throw new Error(i18n('Select only one default provider.')) } + const reserved = input.providers.find((p) => localBackendIds.includes(p.id)) + if (reserved) { + throw new Error( + i18n( + 'Provider ID "${id}" is reserved for the Connect Local Models action. Choose another ID.', + { id: reserved.id }, + ), + ) + } const providerKeys = Object.fromEntries( input.providers .filter((provider) => provider.apiKey && !isReference(provider.apiKey)) diff --git a/startos/actions/connectLocalModels.ts b/startos/actions/connectLocalModels.ts new file mode 100644 index 0000000..84006d3 --- /dev/null +++ b/startos/actions/connectLocalModels.ts @@ -0,0 +1,62 @@ +import { storeJson } from '../fileModels/store.json' +import { i18n } from '../i18n' +import { localBackends } from '../localModels' +import { sdk } from '../sdk' + +const { InputSpec, Value } = sdk + +export const connectLocalModels = sdk.Action.withInput( + // id + 'connect-local-models', + + // metadata + { + name: i18n('Connect Local Models'), + description: i18n( + 'Connect OpenCode to the Ollama, vLLM, or llama.cpp service on this server, so their models appear in OpenCode.', + ), + warning: null, + allowedStatuses: 'any', + group: null, + visibility: 'enabled', + }, + + // input spec + InputSpec.of({ + backends: Value.dynamicMultiselect(async ({ effects, prefill }) => { + const installed = await effects.getInstalledPackages() + const values = Object.fromEntries( + localBackends + .filter((b) => installed.includes(b.id)) + .map((b) => [b.id, b.title]), + ) + const prior = (prefill as { backends?: string[] } | null)?.backends ?? [] + return { + name: i18n('Services'), + description: i18n( + 'The model services installed on this server. Checking one connects it; unchecking it disconnects it.', + ), + values, + default: prior.filter((id) => id in values), + } + }), + }), + + // prefill + async ({ effects }) => ({ + backends: (await storeJson.read((s) => s.localBackends).once()) ?? [], + }), + + // execution + async ({ effects, input }) => { + await storeJson.merge(effects, { localBackends: input.backends }) + return { + version: '1', + title: i18n('Connect Local Models'), + message: i18n( + 'Saved. OpenCode restarts, and the connected services’ models appear in its model list once each service is running.', + ), + result: null, + } + }, +) diff --git a/startos/actions/index.ts b/startos/actions/index.ts index c544393..2601925 100644 --- a/startos/actions/index.ts +++ b/startos/actions/index.ts @@ -1,9 +1,11 @@ import { configureProviderCa } from './configureProviderCa' import { sdk } from '../sdk' import { configureProviders } from './configureProviders' +import { connectLocalModels } from './connectLocalModels' import { setAdminPassword } from './setAdminPassword' export const actions = sdk.Actions.of() .addAction(setAdminPassword) .addAction(configureProviders) .addAction(configureProviderCa) + .addAction(connectLocalModels) diff --git a/startos/dependencies.ts b/startos/dependencies.ts index b97fd7a..1d88847 100644 --- a/startos/dependencies.ts +++ b/startos/dependencies.ts @@ -1,3 +1,30 @@ +import { storeJson } from './fileModels/store.json' +import { bridgeAddress, localBackends } from './localModels' import { sdk } from './sdk' +const dependency = (backend: (typeof localBackends)[number]) => { + const { id, title, icon, versionRange } = backend + return sdk.Dependency.optional(id, { + description: { + en_US: `Optional: serve local models to OpenCode through ${title}. Connect it with the Connect Local Models action.`, + es_ES: `Opcional: sirve modelos locales a OpenCode mediante ${title}. Conéctalo con la acción Conectar modelos locales.`, + de_DE: `Optional: lokale Modelle über ${title} für OpenCode bereitstellen. Mit der Aktion „Lokale Modelle verbinden“ verbinden.`, + pl_PL: `Opcjonalnie: udostępniaj OpenCode lokalne modele przez ${title}. Połącz akcją Połącz modele lokalne.`, + fr_FR: `Optionnel : servez des modèles locaux à OpenCode via ${title}. Connectez-le avec l’action Connecter des modèles locaux.`, + }, + metadata: { title, icon }, + versionRange, + kind: 'running', + healthChecks: ['primary'], + // Connected and installed: an uninstalled backend resolves no address. + enabled: async ({ effects }) => + ( + (await storeJson.read((s) => s.localBackends).const(effects)) ?? [] + ).includes(id) && (await bridgeAddress(effects, backend)) !== null, + }) +} + export const dependencies = sdk.Dependencies.of() + .addDependency(dependency(localBackends[0])) + .addDependency(dependency(localBackends[1])) + .addDependency(dependency(localBackends[2])) diff --git a/startos/fileModels/store.json.ts b/startos/fileModels/store.json.ts index 534a43b..8d23e99 100644 --- a/startos/fileModels/store.json.ts +++ b/startos/fileModels/store.json.ts @@ -6,6 +6,8 @@ const shape = z.looseObject({ // API keys for the providers the Configure Model Providers action writes, keyed // by provider id; `main.ts` passes each to the server as `OPENCODE_KEY_`. providerKeys: z.record(z.string(), z.unknown()).optional().catch(undefined), + // The local-model backends Connect Local Models connected, by package id. + localBackends: z.array(z.string()).optional().catch(undefined), }) export const storeJson = FileHelper.json( diff --git a/startos/i18n/dictionaries/default.ts b/startos/i18n/dictionaries/default.ts index ecbe108..f968c36 100644 --- a/startos/i18n/dictionaries/default.ts +++ b/startos/i18n/dictionaries/default.ts @@ -27,7 +27,7 @@ const dict = { Providers: 14, 'One entry per endpoint. Remove an entry to disconnect that provider.': 15, ID: 16, - 'A short identifier for this provider, used to select it. Lowercase letters, digits, and dashes, for example `vllm`.': 17, + 'A short identifier for this provider, used to select it. Lowercase letters, digits, and dashes, for example `lab`.': 17, 'Lowercase letters, digits, and dashes, starting with a letter or digit': 18, Name: 19, 'How the provider is named in the OpenCode model list, for example `Lab vLLM`.': 20, @@ -54,6 +54,12 @@ const dict = { 'Select only one default provider.': 41, 'Paste one public PEM CA certificate.': 42, 'This certificate is not a CA.': 43, + 'Provider ID "${id}" is reserved for the Connect Local Models action. Choose another ID.': 44, + 'Connect Local Models': 45, + 'Connect OpenCode to the Ollama, vLLM, or llama.cpp service on this server, so their models appear in OpenCode.': 46, + Services: 47, + 'The model services installed on this server. Checking one connects it; unchecking it disconnects it.': 48, + 'Saved. OpenCode restarts, and the connected services’ models appear in its model list once each service is running.': 49, } as const /** diff --git a/startos/i18n/dictionaries/translations.ts b/startos/i18n/dictionaries/translations.ts index fcb59dc..7302504 100644 --- a/startos/i18n/dictionaries/translations.ts +++ b/startos/i18n/dictionaries/translations.ts @@ -19,7 +19,7 @@ export default { 14: 'Proveedores', 15: 'Una entrada por endpoint. Elimina una entrada para desconectar ese proveedor.', 16: 'ID', - 17: 'Un identificador corto para este proveedor, usado para seleccionarlo. Letras minúsculas, dígitos y guiones, por ejemplo `vllm`.', + 17: 'Un identificador corto para este proveedor, usado para seleccionarlo. Letras minúsculas, dígitos y guiones, por ejemplo `lab`.', 18: 'Letras minúsculas, dígitos y guiones, empezando por una letra o un dígito', 19: 'Nombre', 20: 'Cómo se nombra el proveedor en la lista de modelos de OpenCode, por ejemplo `Lab vLLM`.', @@ -46,6 +46,12 @@ export default { 41: 'Selecciona solo un proveedor predeterminado.', 42: 'Pega un certificado de CA público en formato PEM.', 43: 'Este certificado no es una CA.', + 44: 'El ID de proveedor "${id}" está reservado para la acción Conectar modelos locales. Elige otro ID.', + 45: 'Conectar modelos locales', + 46: 'Conecta OpenCode al servicio Ollama, vLLM o llama.cpp de este servidor para que sus modelos aparezcan en OpenCode.', + 47: 'Servicios', + 48: 'Los servicios de modelos instalados en este servidor. Marca uno para conectarlo; desmárcalo para desconectarlo.', + 49: 'Guardado. OpenCode se reinicia y los modelos de los servicios conectados aparecen en su lista de modelos cuando cada servicio está en ejecución.', }, de_DE: { 0: 'Weboberfläche', @@ -65,7 +71,7 @@ export default { 14: 'Anbieter', 15: 'Ein Eintrag pro Endpunkt. Entfernen Sie einen Eintrag, um diesen Anbieter zu trennen.', 16: 'ID', - 17: 'Eine kurze Kennung für diesen Anbieter, mit der er ausgewählt wird. Kleinbuchstaben, Ziffern und Bindestriche, zum Beispiel `vllm`.', + 17: 'Eine kurze Kennung für diesen Anbieter, mit der er ausgewählt wird. Kleinbuchstaben, Ziffern und Bindestriche, zum Beispiel `lab`.', 18: 'Kleinbuchstaben, Ziffern und Bindestriche, beginnend mit einem Buchstaben oder einer Ziffer', 19: 'Name', 20: 'Wie der Anbieter in der Modellliste von OpenCode heißt, zum Beispiel `Lab vLLM`.', @@ -92,6 +98,12 @@ export default { 41: 'Wählen Sie nur einen Standardanbieter.', 42: 'Fügen Sie ein öffentliches CA-Zertifikat (PEM) ein.', 43: 'Dieses Zertifikat ist keine CA.', + 44: 'Die Anbieter-ID „${id}“ ist für die Aktion „Lokale Modelle verbinden“ reserviert. Wählen Sie eine andere ID.', + 45: 'Lokale Modelle verbinden', + 46: 'Verbindet OpenCode mit dem Ollama-, vLLM- oder llama.cpp-Dienst auf diesem Server, damit dessen Modelle in OpenCode erscheinen.', + 47: 'Dienste', + 48: 'Die auf diesem Server installierten Modelldienste. Anhaken verbindet einen Dienst, Abhaken trennt ihn.', + 49: 'Gespeichert. OpenCode startet neu, und die Modelle der verbundenen Dienste erscheinen in seiner Modellliste, sobald der jeweilige Dienst läuft.', }, pl_PL: { 0: 'Interfejs webowy', @@ -111,7 +123,7 @@ export default { 14: 'Dostawcy', 15: 'Jeden wpis na endpoint. Usuń wpis, aby odłączyć tego dostawcę.', 16: 'Identyfikator', - 17: 'Krótki identyfikator tego dostawcy, używany do jego wyboru. Małe litery, cyfry i myślniki, na przykład `vllm`.', + 17: 'Krótki identyfikator tego dostawcy, używany do jego wyboru. Małe litery, cyfry i myślniki, na przykład `lab`.', 18: 'Małe litery, cyfry i myślniki, zaczynając od litery lub cyfry', 19: 'Nazwa', 20: 'Jak dostawca jest nazwany na liście modeli OpenCode, na przykład `Lab vLLM`.', @@ -138,6 +150,12 @@ export default { 41: 'Wybierz tylko jednego dostawcę domyślnego.', 42: 'Wklej publiczny certyfikat CA w formacie PEM.', 43: 'Ten certyfikat nie jest CA.', + 44: 'Identyfikator dostawcy „${id}” jest zarezerwowany dla akcji Połącz modele lokalne. Wybierz inny identyfikator.', + 45: 'Połącz modele lokalne', + 46: 'Łączy OpenCode z usługą Ollama, vLLM lub llama.cpp na tym serwerze, aby jej modele pojawiły się w OpenCode.', + 47: 'Usługi', + 48: 'Usługi modeli zainstalowane na tym serwerze. Zaznacz, aby połączyć; odznacz, aby rozłączyć.', + 49: 'Zapisano. OpenCode uruchamia się ponownie, a modele połączonych usług pojawiają się na jego liście modeli, gdy dana usługa działa.', }, fr_FR: { 0: 'Interface web', @@ -157,7 +175,7 @@ export default { 14: 'Fournisseurs', 15: 'Une entrée par point de terminaison. Supprimez une entrée pour déconnecter ce fournisseur.', 16: 'Identifiant', - 17: 'Un identifiant court pour ce fournisseur, utilisé pour le sélectionner. Lettres minuscules, chiffres et tirets, par exemple `vllm`.', + 17: 'Un identifiant court pour ce fournisseur, utilisé pour le sélectionner. Lettres minuscules, chiffres et tirets, par exemple `lab`.', 18: 'Lettres minuscules, chiffres et tirets, commençant par une lettre ou un chiffre', 19: 'Nom', 20: "Le nom du fournisseur dans la liste des modèles d'OpenCode, par exemple `Lab vLLM`.", @@ -184,5 +202,11 @@ export default { 41: 'Sélectionnez un seul fournisseur par défaut.', 42: 'Collez un certificat d’autorité publique au format PEM.', 43: 'Ce certificat n’est pas une autorité de certification.', + 44: 'L’identifiant de fournisseur « ${id} » est réservé à l’action Connecter des modèles locaux. Choisissez un autre identifiant.', + 45: 'Connecter des modèles locaux', + 46: 'Connecte OpenCode au service Ollama, vLLM ou llama.cpp de ce serveur pour que ses modèles apparaissent dans OpenCode.', + 47: 'Services', + 48: 'Les services de modèles installés sur ce serveur. Cochez-en un pour le connecter, décochez-le pour le déconnecter.', + 49: 'Enregistré. OpenCode redémarre, et les modèles des services connectés apparaissent dans sa liste dès que chaque service est en cours d’exécution.', }, } satisfies Record diff --git a/startos/localModels.ts b/startos/localModels.ts new file mode 100644 index 0000000..54d9de3 --- /dev/null +++ b/startos/localModels.ts @@ -0,0 +1,174 @@ +import * as fs from 'node:fs/promises' +import { FileHelper, T, z } from '@start9labs/start-sdk' +import { + apiKeyHostId as llamaCppHostId, + apiPort as llamaCppPort, +} from 'llama-cpp-startos/startos/utils' +import { + apiHostId as ollamaHostId, + port as ollamaPort, +} from 'ollama-startos/startos/utils' +import { + apiHostId as vllmHostId, + apiPort as vllmPort, +} from 'vllm-startos/startos/utils' +import { sdk } from './sdk' +import { openAiCompatiblePackage } from './utils' + +type Credentials = { apiKey?: string; model?: string } + +type LocalBackend = { + id: string + title: string + icon: string + hostId: string + internalPort: number + versionRange: string + // Whether the backend publishes `credentials.json` on its `public` volume. + publishesCredentials: boolean + // OpenCode's `providers.` entry, or `null` while it can't be served yet. + provider: (baseURL: string, credentials: Credentials) => object | null +} + +export const localBackends = [ + { + id: 'ollama', + icon: 'https://raw.githubusercontent.com/Start9Labs/ollama-startos/master/icon.svg', + title: 'Ollama', + hostId: ollamaHostId, + internalPort: ollamaPort, + versionRange: '>=0.31.2:2', + publishesCredentials: false, + // OpenCode's built-in Ollama provider discovers the models itself. + provider: (baseURL) => ({ settings: { baseURL } }), + }, + { + id: 'vllm', + icon: 'https://raw.githubusercontent.com/Start9Labs/vllm-startos/master/icon.svg', + title: 'vLLM', + hostId: vllmHostId, + internalPort: vllmPort, + // First release publishing the served model name. + versionRange: '>=0.33.0:1', + publishesCredentials: true, + provider: (baseURL, { apiKey, model }) => + apiKey && model + ? { + name: 'vLLM', + package: openAiCompatiblePackage, + settings: { baseURL, apiKey }, + // OpenCode's built-in vLLM provider marks discovered models + // tool-less; every vLLM preset serves with a tool-call parser. + models: { [model]: { name: model, capabilities: { tools: true } } }, + } + : null, + }, + { + id: 'llama-cpp', + icon: 'https://raw.githubusercontent.com/Start9Labs/llama-cpp-startos/master/icon.png', + title: 'llama.cpp', + hostId: llamaCppHostId, + internalPort: llamaCppPort, + // First release with the Bearer-gated API host and a published key. + versionRange: '>=11960:1', + publishesCredentials: true, + // llama-server serves one model and answers whatever model name it is sent. + provider: (baseURL, { apiKey }) => + apiKey + ? { + name: 'llama.cpp', + package: openAiCompatiblePackage, + settings: { baseURL, apiKey }, + models: { [llamaCppModelId]: { name: 'llama.cpp' } }, + } + : null, + }, +] as const satisfies readonly LocalBackend[] + +export const llamaCppModelId = 'current' + +export type LocalBackendId = (typeof localBackends)[number]['id'] + +export const localBackendIds: readonly string[] = localBackends.map((b) => b.id) + +const credentialsFile = (id: string) => + FileHelper.json( + `${sdk.volumes.mounts.subpath(id)}/credentials.json`, + z.looseObject({ + apiKey: z.string().optional().catch(undefined), + model: z.string().optional().catch(undefined), + }), + ) + +// The bridge address each backend's `public` volume was mounted for. +const mountedFor = new Map() + +async function readCredentials( + effects: T.Effects, + id: string, + bridgeAddress: string | null, +): Promise { + const hasPublicVolume = await sdk + .getServiceManifest( + effects, + id, + (m) => m?.volumes.includes('public') ?? false, + ) + .const() + if (!bridgeAddress || !hasPublicVolume) { + mountedFor.delete(id) + return {} + } + try { + if (mountedFor.get(id) !== bridgeAddress) { + const location = sdk.volumes.mounts.subpath(id) + await fs.mkdir(location, { recursive: true }) + await sdk.mount(effects, { + location, + target: { + packageId: id, + volumeId: 'public', + subpath: null, + readonly: true, + idmap: [], + }, + }) + mountedFor.set(id, bridgeAddress) + } + return (await credentialsFile(id).read().const(effects)) ?? {} + } catch { + return {} + } +} + +export const bridgeAddress = ( + effects: T.Effects, + b: (typeof localBackends)[number], +) => + sdk.host + .getBridgeAddress(effects, { + packageId: b.id, + hostId: b.hostId, + internalPort: b.internalPort, + ssl: false, + }) + .const() + +// OpenCode `providers` entries for the connected backends that can be served now. +export async function localProviders( + effects: T.Effects, + connected: readonly string[], +): Promise> { + const providers: Record = {} + for (const b of localBackends) { + if (!connected.includes(b.id)) continue + const address = await bridgeAddress(effects, b) + const credentials = b.publishesCredentials + ? await readCredentials(effects, b.id, address) + : {} + if (!address) continue + const provider = b.provider(`http://${address}/v1`, credentials) + if (provider) providers[b.id] = provider + } + return providers +} diff --git a/startos/main.ts b/startos/main.ts index afa9278..26b2603 100644 --- a/startos/main.ts +++ b/startos/main.ts @@ -6,6 +6,7 @@ import { } from './fileModels/providerCa' import { storeJson } from './fileModels/store.json' import { i18n } from './i18n' +import { localProviders } from './localModels' import { sdk } from './sdk' import { providerKeyEnvVar, uiPort } from './utils' @@ -30,6 +31,11 @@ export const main = sdk.setupMain(async ({ effects }) => { .map(([id, key]) => [providerKeyEnvVar(id), key]), ) + const providers = await localProviders( + effects, + (await storeJson.read((s) => s.localBackends).const(effects)) ?? [], + ) + let mounts = sdk.Mounts.of().mountVolume({ volumeId: 'main', subpath: null, @@ -67,6 +73,9 @@ export const main = sdk.setupMain(async ({ effects }) => { OPENCODE_DISABLE_AUTOUPDATE: '1', ...(extraCaPath && { NODE_EXTRA_CA_CERTS: extraCaPath }), ...providerEnv, + ...(Object.keys(providers).length > 0 && { + OPENCODE_CONFIG_CONTENT: JSON.stringify({ providers }), + }), }, }, ready: { diff --git a/startos/manifest/index.ts b/startos/manifest/index.ts index fa7ca2f..19492b8 100644 --- a/startos/manifest/index.ts +++ b/startos/manifest/index.ts @@ -12,7 +12,8 @@ export const manifest = setupManifest({ description: { short, long }, // `startos` holds secrets (the login password and provider API keys) and the // optional public CA; only the CA subtree is mounted into the container, read-only. - volumes: ['main', 'startos'], + // `mounts` holds local-model backends' public volumes and is never backed up. + volumes: ['main', 'startos', 'mounts'], images: { opencode: { source: { dockerBuild: {} }, diff --git a/startos/versions/current.ts b/startos/versions/current.ts index d367a47..b509cb6 100644 --- a/startos/versions/current.ts +++ b/startos/versions/current.ts @@ -4,15 +4,15 @@ export const current = VersionInfo.of({ version: '2.4.1:2', releaseNotes: { en_US: - 'Add private provider CA trust and keep existing model aliases when configuring providers.', + "Initial release of OpenCode for StartOS. Use models served by Ollama, vLLM, or llama.cpp on the same server with the Connect Local Models action, add any other OpenAI-compatible endpoint with Configure Model Providers, and trust a private provider's certificate authority with Configure Provider CA.", es_ES: - 'Permite confiar en una CA privada y conserva los alias de modelos al configurar proveedores.', + 'Primera versión de OpenCode para StartOS. Usa modelos servidos por Ollama, vLLM o llama.cpp en el mismo servidor con la acción Conectar modelos locales, añade cualquier otro endpoint compatible con OpenAI con Configurar proveedores de modelos y confía en la autoridad de certificación de un proveedor privado con Configurar CA del proveedor.', de_DE: - 'Unterstützt private Zertifizierungsstellen und behält vorhandene Modellaliase beim Konfigurieren der Anbieter bei.', + 'Erstveröffentlichung von OpenCode für StartOS. Nutzen Sie Modelle von Ollama, vLLM oder llama.cpp auf demselben Server mit der Aktion „Lokale Modelle verbinden“, fügen Sie mit „Modellanbieter konfigurieren“ jeden anderen OpenAI-kompatiblen Endpunkt hinzu und vertrauen Sie mit „Anbieter-CA konfigurieren“ der Zertifizierungsstelle eines privaten Anbieters.', pl_PL: - 'Dodaje obsługę prywatnego CA i zachowuje istniejące aliasy modeli podczas konfigurowania dostawców.', + 'Pierwsze wydanie OpenCode dla StartOS. Korzystaj z modeli udostępnianych przez Ollama, vLLM lub llama.cpp na tym samym serwerze dzięki akcji Połącz modele lokalne, dodawaj dowolny inny punkt końcowy zgodny z OpenAI akcją Konfiguruj dostawców modeli i zaufaj urzędowi certyfikacji prywatnego dostawcy akcją Konfiguracja CA dostawcy.', fr_FR: - 'Ajoute la prise en charge des AC privées et conserve les alias de modèles lors de la configuration des fournisseurs.', + 'Première version d’OpenCode pour StartOS. Utilisez les modèles servis par Ollama, vLLM ou llama.cpp sur le même serveur avec l’action Connecter des modèles locaux, ajoutez tout autre point d’accès compatible OpenAI avec Configurer les fournisseurs de modèles, et faites confiance à l’autorité de certification d’un fournisseur privé avec Configurer l’autorité de certification.', }, migrations: { up: async ({ effects }) => {}, From 453f158dd61f7c15629bd47deb8e3585f3875027 Mon Sep 17 00:00:00 2001 From: Matt Hill <9935159+MattDHill@users.noreply.github.com> Date: Sat, 28 Nov 2026 12:58:08 -0700 Subject: [PATCH 2/2] fix: remount after reconnect, refuse provider-id collisions, keep old backends visible - drop a disconnected backend's cached mount, so reconnecting after a reinstall reads the new credentials - Connect Local Models refuses a backend whose id is already a provider in opencode.json - a connected backend counts as a dependency while it is installed, so an incompatible version shows its warning Co-Authored-By: helix-white Co-Authored-By: Claude Opus 5.5 --- README.md | 9 +++++++-- instructions.md | 5 +++++ startos/actions/connectLocalModels.ts | 12 ++++++++++++ startos/dependencies.ts | 7 ++++--- startos/i18n/dictionaries/default.ts | 1 + startos/i18n/dictionaries/translations.ts | 4 ++++ startos/localModels.ts | 6 +++++- 7 files changed, 38 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 202b164..f8c9ce3 100644 --- a/README.md +++ b/README.md @@ -109,8 +109,10 @@ JSON without its comments or formatting. ## Dependencies Three optional dependencies, each enabled while **Connect Local Models** has it -connected and it is installed; uninstalling one disables it. All three must be running with their `primary` health check -passing. +connected and it is installed; uninstalling one disables it. Each connected +service must meet its version requirement and be running with its `primary` +health check passing. An installed service with no API binding still appears +as a dependency, so an older release surfaces an update requirement. | Dependency | Reached at | Read from its `public` volume | OpenCode provider id | | ----------- | --------------------------------------------- | ----------------------------- | -------------------- | @@ -244,6 +246,9 @@ warning, and status gating; what follows is what the metadata cannot express. - **Cost.** Seconds, and OpenCode restarts. - **Repeat safety.** Repeatable. The form lists only the services installed now, prefilled with the connected ones; the saved list replaces the previous one. + A selected service whose provider id already exists in `opencode.json` is + rejected without saving. Rename or remove that provider first; OpenCode + overlays same-id providers rather than replacing their models and settings. - **Outputs.** None. The provider ids `ollama`, `vllm` and `llama-cpp` are reserved for these diff --git a/instructions.md b/instructions.md index 899c3dc..3a75af2 100644 --- a/instructions.md +++ b/instructions.md @@ -74,6 +74,11 @@ A service has to be running for its models to work. Run **Connect Local Models** again and uncheck a service to disconnect it. Your prompts and code stay on your server. +If an existing provider uses the id `ollama`, `vllm`, or `llama-cpp`, rename +or remove it before connecting that local service. For a provider added with +**Configure Model Providers**, change its **ID** there and save first. A +provider configured directly in `opencode.json` must be changed there. + ### Connecting a model provider Hosted providers connect inside the web app, under **Settings → Providers**. The diff --git a/startos/actions/connectLocalModels.ts b/startos/actions/connectLocalModels.ts index 84006d3..cd7a657 100644 --- a/startos/actions/connectLocalModels.ts +++ b/startos/actions/connectLocalModels.ts @@ -1,3 +1,4 @@ +import { opencodeJson } from '../fileModels/opencode.json' import { storeJson } from '../fileModels/store.json' import { i18n } from '../i18n' import { localBackends } from '../localModels' @@ -49,6 +50,17 @@ export const connectLocalModels = sdk.Action.withInput( // execution async ({ effects, input }) => { + const providers = (await opencodeJson.read((c) => c.providers).once()) ?? {} + // OpenCode overlays same-ID providers, retaining their models and settings. + const collision = input.backends.find((id) => Object.hasOwn(providers, id)) + if (collision) { + throw new Error( + i18n( + 'Provider ID "${id}" is already configured in opencode.json. Rename or remove it before connecting this local service.', + { id: collision }, + ), + ) + } await storeJson.merge(effects, { localBackends: input.backends }) return { version: '1', diff --git a/startos/dependencies.ts b/startos/dependencies.ts index 1d88847..6c72045 100644 --- a/startos/dependencies.ts +++ b/startos/dependencies.ts @@ -1,5 +1,5 @@ import { storeJson } from './fileModels/store.json' -import { bridgeAddress, localBackends } from './localModels' +import { localBackends } from './localModels' import { sdk } from './sdk' const dependency = (backend: (typeof localBackends)[number]) => { @@ -16,11 +16,12 @@ const dependency = (backend: (typeof localBackends)[number]) => { versionRange, kind: 'running', healthChecks: ['primary'], - // Connected and installed: an uninstalled backend resolves no address. + // Installed backends remain dependencies before their API binding exists. enabled: async ({ effects }) => ( (await storeJson.read((s) => s.localBackends).const(effects)) ?? [] - ).includes(id) && (await bridgeAddress(effects, backend)) !== null, + ).includes(id) && + (await sdk.getServiceManifest(effects, id, (m) => m !== null).const()), }) } diff --git a/startos/i18n/dictionaries/default.ts b/startos/i18n/dictionaries/default.ts index f968c36..d580598 100644 --- a/startos/i18n/dictionaries/default.ts +++ b/startos/i18n/dictionaries/default.ts @@ -60,6 +60,7 @@ const dict = { Services: 47, 'The model services installed on this server. Checking one connects it; unchecking it disconnects it.': 48, 'Saved. OpenCode restarts, and the connected services’ models appear in its model list once each service is running.': 49, + 'Provider ID "${id}" is already configured in opencode.json. Rename or remove it before connecting this local service.': 50, } as const /** diff --git a/startos/i18n/dictionaries/translations.ts b/startos/i18n/dictionaries/translations.ts index 7302504..4615cc3 100644 --- a/startos/i18n/dictionaries/translations.ts +++ b/startos/i18n/dictionaries/translations.ts @@ -52,6 +52,7 @@ export default { 47: 'Servicios', 48: 'Los servicios de modelos instalados en este servidor. Marca uno para conectarlo; desmárcalo para desconectarlo.', 49: 'Guardado. OpenCode se reinicia y los modelos de los servicios conectados aparecen en su lista de modelos cuando cada servicio está en ejecución.', + 50: 'El ID de proveedor "${id}" ya está configurado en opencode.json. Cámbiale el nombre o elimínalo antes de conectar este servicio local.', }, de_DE: { 0: 'Weboberfläche', @@ -104,6 +105,7 @@ export default { 47: 'Dienste', 48: 'Die auf diesem Server installierten Modelldienste. Anhaken verbindet einen Dienst, Abhaken trennt ihn.', 49: 'Gespeichert. OpenCode startet neu, und die Modelle der verbundenen Dienste erscheinen in seiner Modellliste, sobald der jeweilige Dienst läuft.', + 50: 'Die Anbieter-ID „${id}“ ist bereits in opencode.json konfiguriert. Benennen Sie sie um oder entfernen Sie sie, bevor Sie diesen lokalen Dienst verbinden.', }, pl_PL: { 0: 'Interfejs webowy', @@ -156,6 +158,7 @@ export default { 47: 'Usługi', 48: 'Usługi modeli zainstalowane na tym serwerze. Zaznacz, aby połączyć; odznacz, aby rozłączyć.', 49: 'Zapisano. OpenCode uruchamia się ponownie, a modele połączonych usług pojawiają się na jego liście modeli, gdy dana usługa działa.', + 50: 'Identyfikator dostawcy „${id}” jest już skonfigurowany w opencode.json. Zmień go lub usuń przed połączeniem tej lokalnej usługi.', }, fr_FR: { 0: 'Interface web', @@ -208,5 +211,6 @@ export default { 47: 'Services', 48: 'Les services de modèles installés sur ce serveur. Cochez-en un pour le connecter, décochez-le pour le déconnecter.', 49: 'Enregistré. OpenCode redémarre, et les modèles des services connectés apparaissent dans sa liste dès que chaque service est en cours d’exécution.', + 50: 'L’identifiant de fournisseur « ${id} » est déjà configuré dans opencode.json. Renommez-le ou supprimez-le avant de connecter ce service local.', }, } satisfies Record diff --git a/startos/localModels.ts b/startos/localModels.ts index 54d9de3..9f466c6 100644 --- a/startos/localModels.ts +++ b/startos/localModels.ts @@ -161,7 +161,11 @@ export async function localProviders( ): Promise> { const providers: Record = {} for (const b of localBackends) { - if (!connected.includes(b.id)) continue + if (!connected.includes(b.id)) { + // Reconnection must remount after an unwatched uninstall. + mountedFor.delete(b.id) + continue + } const address = await bridgeAddress(effects, b) const credentials = b.publishesCredentials ? await readCredentials(effects, b.id, address)