Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

feat: add an lmstudioBacked marker so harness wrappers can run on LM Studio (#6309)

[._.]/ Adam Eivy66266411e6e4
diff --git a/client/src/components/quotaBurn/JobRow.jsx b/client/src/components/quotaBurn/JobRow.jsx
index 90650d9bde..0aef8e4721 100644
--- a/client/src/components/quotaBurn/JobRow.jsx
+++ b/client/src/components/quotaBurn/JobRow.jsx
@@ -72,7 +72,8 @@ export default function JobRow({
// Resolve the provider for this family/job to provide model options and effort support
const familyProviders = (catalog.providers || []).filter((provider) =>
provider?.enabled !== false &&
- provider?.ollamaBacked !== true && provider?.mtplxBacked !== true &&
+ provider?.ollamaBacked !== true && provider?.lmstudioBacked !== true &&
+ provider?.mtplxBacked !== true &&
provider?.llamaBacked !== true && provider?.vllmBacked !== true &&
provider?.sglangBacked !== true &&
(provider?.type === 'cli' || provider?.type === 'tui') &&
diff --git a/client/src/utils/providers.js b/client/src/utils/providers.js
index d12f2f6160..8d90968054 100644
--- a/client/src/utils/providers.js
+++ b/client/src/utils/providers.js
@@ -443,8 +443,8 @@ const codexEffortLevelsForModel = (model) => CODEX_ULTRA_MODELS.has(String(model
/**
* True when an OpenCode process provider runs against one of the local
- * OpenAI-compatible backends (Ollama / MTPLX / llama.cpp / vLLM) or a hosted
- * gateway (OrcaRouter / OpenRouter)
+ * OpenAI-compatible backends (Ollama / LM Studio / MTPLX / llama.cpp / vLLM) or
+ * a hosted gateway (OrcaRouter / OpenRouter)
* rather than a vendor cloud model. MIRROR of `isOpencodeProvider(p) &&
* getOpencodeLocalProviderNamespace(p)` in server/lib/providerModels.js, which
* is exactly what gates the effort ladder there — so a backend marker missing
@@ -911,7 +911,7 @@ export const isToolUseModel = (id) =>
* @returns {{toolCapable:boolean}|null}
*/
export const localToolUseHint = (id, provider, toolUseIdsByProvider = null) =>
- (localBackendForProvider(provider) || isOllamaBackedProvider(provider) || provider?.mtplxBacked === true || provider?.llamaBacked === true || provider?.vllmBacked === true || provider?.sglangBacked === true)
+ (localBackendForProvider(provider) || isOllamaBackedProvider(provider) || provider?.lmstudioBacked === true || provider?.mtplxBacked === true || provider?.llamaBacked === true || provider?.vllmBacked === true || provider?.sglangBacked === true)
&& typeof id === 'string' && id.length > 0
? { toolCapable: toolUseIdsByProvider?.[provider?.id]?.has(id) === true || isToolUseModel(id) }
: null;
@@ -1580,7 +1580,12 @@ export const isClaudeCommandProvider = (provider) => commandBasename(provider?.c
*/
export const generationControlsFor = (provider) => {
const gateway = isGatewayBackedProvider(provider);
+ // LM Studio forwards temperature/top_p like any OpenAI-compatible endpoint,
+ // but reasoning there belongs to the LOADED model instance — see
+ // THINKING_STYLE.lmstudio on the server, which resolves to no toggle.
+ const lmstudio = provider?.lmstudioBacked === true;
const local = isOllamaBackedProvider(provider)
+ || lmstudio
|| provider?.llamaBacked === true
|| provider?.mtplxBacked === true
|| provider?.vllmBacked === true
@@ -1601,7 +1606,8 @@ export const generationControlsFor = (provider) => {
? { temperature: false, topP: false, thinking: true }
: null;
}
- return { temperature: true, topP: true, thinking: !gateway };
+ // LM Studio joins the gateways in having no forwardable thinking signal.
+ return { temperature: true, topP: true, thinking: !gateway && !lmstudio };
};
// Environment variables whose names are conventionally credentials. The
diff --git a/client/src/utils/providers.test.js b/client/src/utils/providers.test.js
index b38210ce01..8715a2a7af 100644
--- a/client/src/utils/providers.test.js
+++ b/client/src/utils/providers.test.js
@@ -165,6 +165,7 @@ describe('effortLevelsForProvider (server mirror)', () => {
['OpenCode MTPLX', { id: 'opencode-mtplx', command: 'opencode', mtplxBacked: true }, ['low', 'medium', 'high']],
['OpenCode vLLM TUI', { id: 'opencode-vllm-tui', command: 'opencode', vllmBacked: true }, ['low', 'medium', 'high']],
['OpenCode SGLang TUI', { id: 'opencode-sglang-tui', command: 'opencode', sglangBacked: true }, ['low', 'medium', 'high']],
+ ['OpenCode LM Studio', { id: 'opencode-lmstudio', command: 'opencode', lmstudioBacked: true }, ['low', 'medium', 'high']],
['OpenCode with no local backend', { id: 'opencode', command: 'opencode' }, null],
// grok DOES have an effort control (`--reasoning-effort`, aliased `--effort`);
// its ladder stops at xhigh, which is why it is not simply CLAUDE's.
@@ -209,6 +210,11 @@ describe('generationControlsFor', () => {
// nothing reads. Sampling was never forwardable on a Claude harness either,
// which would have left the block rendering one inert select.
['Claude SGLang TUI', { id: 'claude-sglang-tui', command: 'claude', sglangBacked: true }, null],
+ // LM Studio forwards temperature/top_p like any OpenAI-compatible endpoint,
+ // but reasoning is a property of the LOADED model instance there — no
+ // per-request field carries it, so the toggle would pin a value nothing
+ // reads (THINKING_STYLE.lmstudio is null on the server).
+ ['OpenCode LM Studio', { id: 'opencode-lmstudio', command: 'opencode', lmstudioBacked: true }, { temperature: true, topP: true, thinking: false }],
['native Ollama API', { id: 'ollama', type: 'api', endpoint: 'http://localhost:11434/v1' }, { temperature: true, topP: true, thinking: true }],
// OrcaRouter proxies cloud models that own their own reasoning switch.
['OpenCode OrcaRouter', { id: 'opencode-orcarouter', command: 'opencode', orcarouterBacked: true }, { temperature: true, topP: true, thinking: false }],
@@ -1206,6 +1212,7 @@ describe('supportsModelRefresh', () => {
'cursor-cli',
'cursor-tui', 'grok', 'lmstudio', 'mtplx', 'nvidia-kimi', 'ollama',
'opencode-llama-tui',
+ 'opencode-lmstudio', 'opencode-lmstudio-tui',
'opencode-mtplx', 'opencode-mtplx-tui', 'opencode-ollama',
'opencode-ollama-tui', 'opencode-openrouter', 'opencode-openrouter-tui',
'opencode-orcarouter', 'opencode-orcarouter-tui',
diff --git a/data.reference/providers.json b/data.reference/providers.json
index 22099cf112..ae8b4238b5 100644
--- a/data.reference/providers.json
+++ b/data.reference/providers.json
@@ -217,6 +217,40 @@
"secretEnvVars": [],
"tuiPromptDelayMs": 2500
},
+ "opencode-lmstudio": {
+ "id": "opencode-lmstudio",
+ "name": "OpenCode LM Studio (local model)",
+ "type": "cli",
+ "command": "opencode",
+ "args": ["run"],
+ "models": [],
+ "defaultModel": null,
+ "lmstudioBacked": true,
+ "timeout": 600000,
+ "enabled": false,
+ "envVars": {
+ "OPENCODE_CONFIG_CONTENT": "{\"permission\":\"allow\",\"provider\":{\"lmstudio\":{\"npm\":\"@ai-sdk/openai-compatible\",\"name\":\"LM Studio (local)\",\"options\":{\"baseURL\":\"http://localhost:1234/v1\"}}}}"
+ },
+ "secretEnvVars": [],
+ "headlessArgs": []
+ },
+ "opencode-lmstudio-tui": {
+ "id": "opencode-lmstudio-tui",
+ "name": "OpenCode LM Studio TUI (local model)",
+ "type": "tui",
+ "command": "opencode",
+ "args": [],
+ "models": [],
+ "defaultModel": null,
+ "lmstudioBacked": true,
+ "timeout": 600000,
+ "enabled": false,
+ "envVars": {
+ "OPENCODE_CONFIG_CONTENT": "{\"permission\":\"allow\",\"provider\":{\"lmstudio\":{\"npm\":\"@ai-sdk/openai-compatible\",\"name\":\"LM Studio (local)\",\"options\":{\"baseURL\":\"http://localhost:1234/v1\"}}}}"
+ },
+ "secretEnvVars": [],
+ "tuiPromptDelayMs": 2500
+ },
"opencode-mtplx": {
"id": "opencode-mtplx",
"name": "OpenCode MTPLX (local MTP)",
diff --git a/scripts/migrations/346-opencode-lmstudio-providers.js b/scripts/migrations/346-opencode-lmstudio-providers.js
new file mode 100644
index 0000000000..5f3d304414
--- /dev/null
+++ b/scripts/migrations/346-opencode-lmstudio-providers.js
@@ -0,0 +1,70 @@
+/**
+ * Ship disabled OpenCode LM Studio provider presets to existing installs.
+ *
+ * LM Studio was the one local backend PortOS already managed (`lmStudioManager.js`,
+ * the `lmstudio` API record, its Models → LLMs tab) that no coding harness could
+ * be pointed at: the OpenCode wrappers key on a `*Backed` marker, and there was
+ * no `lmstudioBacked`. These two presets are what makes the new marker reachable
+ * — a headless `cli` twin and the attachable `tui` that CoS agent tasks run in.
+ *
+ * Both presets are DISABLED and this migration installs nothing: it does not
+ * start LM Studio, download a model, or contact the endpoint. `models` ships
+ * EMPTY and `defaultModel` null — LM Studio serves whatever the operator has
+ * downloaded, so the list is filled by an explicit refresh (the `lmstudio` row
+ * in `server/lib/aiToolkit/internal/modelFetchers.js`), never guessed here.
+ *
+ * No API preset: `lmstudio` already exists as one. And no `numCtx` pin, unlike
+ * the Ollama presets — LM Studio fixes a model's context window when the
+ * instance is LOADED, so a stored window would be a value nothing reads (see the
+ * `lmstudio` row in `server/lib/localProviderRuntime.js` for why PortOS does no
+ * pre-spawn preparation for this backend).
+ *
+ * An install that already owns one of these ids is left untouched, so a user who
+ * renamed or disabled the row keeps their record.
+ *
+ * Kept in lockstep with data.reference/providers.json and
+ * server/lib/aiToolkit/defaults/providers.sample.json. These frozen literals are
+ * the historical upgrade payload; later default changes require a new migration
+ * rather than rewriting this record.
+ */
+
+import { makeProviderSeedMigration } from './_lib.js';
+
+const OPENCODE_CONFIG_CONTENT = '{"permission":"allow","provider":{"lmstudio":{"npm":"@ai-sdk/openai-compatible","name":"LM Studio (local)","options":{"baseURL":"http://localhost:1234/v1"}}}}';
+
+const OPENCODE_LMSTUDIO_CLI = {
+ id: 'opencode-lmstudio',
+ name: 'OpenCode LM Studio (local model)',
+ type: 'cli',
+ command: 'opencode',
+ args: ['run'],
+ models: [],
+ defaultModel: null,
+ lmstudioBacked: true,
+ timeout: 600000,
+ enabled: false,
+ envVars: { OPENCODE_CONFIG_CONTENT },
+ secretEnvVars: [],
+ headlessArgs: [],
+};
+
+const OPENCODE_LMSTUDIO_TUI = {
+ id: 'opencode-lmstudio-tui',
+ name: 'OpenCode LM Studio TUI (local model)',
+ type: 'tui',
+ command: 'opencode',
+ args: [],
+ models: [],
+ defaultModel: null,
+ lmstudioBacked: true,
+ timeout: 600000,
+ enabled: false,
+ envVars: { OPENCODE_CONFIG_CONTENT },
+ secretEnvVars: [],
+ tuiPromptDelayMs: 2500,
+};
+
+export default makeProviderSeedMigration({
+ label: 'OpenCode LM Studio (local model)',
+ defs: [OPENCODE_LMSTUDIO_CLI, OPENCODE_LMSTUDIO_TUI],
+});
diff --git a/scripts/migrations/346-opencode-lmstudio-providers.test.js b/scripts/migrations/346-opencode-lmstudio-providers.test.js
new file mode 100644
index 0000000000..7cd7b85383
--- /dev/null
+++ b/scripts/migrations/346-opencode-lmstudio-providers.test.js
@@ -0,0 +1,95 @@
+import { describe, it, expect, beforeEach, afterEach } from 'vitest';
+import { mkdtempSync, rmSync, writeFileSync, readFileSync, mkdirSync, existsSync } from 'fs';
+import { tmpdir } from 'os';
+import { join } from 'path';
+
+import migration from './346-opencode-lmstudio-providers.js';
+
+const writeJson = (path, value) => writeFileSync(path, JSON.stringify(value, null, 2) + '\n');
+const readJson = (path) => JSON.parse(readFileSync(path, 'utf-8'));
+
+describe('migration 346 — OpenCode LM Studio providers', () => {
+ let rootDir;
+ let providersPath;
+
+ beforeEach(() => {
+ rootDir = mkdtempSync(join(tmpdir(), 'migration-346-'));
+ mkdirSync(join(rootDir, 'data'), { recursive: true });
+ providersPath = join(rootDir, 'data/providers.json');
+ });
+
+ afterEach(() => rmSync(rootDir, { recursive: true, force: true }));
+
+ it('adds both OpenCode LM Studio presets, disabled, without changing the active provider', async () => {
+ writeJson(providersPath, {
+ activeProvider: 'claude-code',
+ providers: { 'claude-code': { id: 'claude-code', type: 'cli', command: 'claude' } },
+ });
+
+ await migration.up({ rootDir });
+ const out = readJson(providersPath);
+
+ expect(out.providers['opencode-lmstudio']).toMatchObject({
+ name: 'OpenCode LM Studio (local model)',
+ type: 'cli',
+ command: 'opencode',
+ models: [],
+ defaultModel: null,
+ lmstudioBacked: true,
+ enabled: false,
+ });
+ expect(out.providers['opencode-lmstudio-tui']).toMatchObject({
+ type: 'tui',
+ lmstudioBacked: true,
+ enabled: false,
+ tuiPromptDelayMs: 2500,
+ });
+ expect(out.activeProvider).toBe('claude-code');
+ });
+
+ it('declares the lmstudio namespace at the local server in the OpenCode config', async () => {
+ writeJson(providersPath, { providers: {} });
+ await migration.up({ rootDir });
+
+ for (const id of ['opencode-lmstudio', 'opencode-lmstudio-tui']) {
+ const config = JSON.parse(readJson(providersPath).providers[id].envVars.OPENCODE_CONFIG_CONTENT);
+ expect(config.provider.lmstudio.options.baseURL).toBe('http://localhost:1234/v1');
+ }
+ });
+
+ it('pins no numCtx or thinking default — both are load-time choices in LM Studio', async () => {
+ writeJson(providersPath, { providers: {} });
+ await migration.up({ rootDir });
+ const out = readJson(providersPath);
+
+ for (const id of ['opencode-lmstudio', 'opencode-lmstudio-tui']) {
+ expect(out.providers[id].numCtx).toBeUndefined();
+ expect(out.providers[id].thinking).toBeUndefined();
+ }
+ });
+
+ it('is a no-op on a second run and never resurrects a renamed or disabled row', async () => {
+ const customized = {
+ id: 'opencode-lmstudio-tui',
+ name: 'My LM Studio TUI',
+ type: 'tui',
+ command: 'opencode',
+ lmstudioBacked: true,
+ enabled: false,
+ };
+ writeJson(providersPath, { providers: { 'opencode-lmstudio-tui': customized } });
+
+ await migration.up({ rootDir });
+ const first = readJson(providersPath);
+ expect(first.providers['opencode-lmstudio-tui']).toEqual(customized);
+ expect(first.providers['opencode-lmstudio']).toBeDefined();
+
+ await migration.up({ rootDir });
+ expect(readJson(providersPath)).toEqual(first);
+ });
+
+ it('skips an install that has no provider file rather than creating one', async () => {
+ await migration.up({ rootDir });
+ expect(existsSync(providersPath)).toBe(false);
+ });
+});
diff --git a/server/lib/aiToolkit/defaults/providers.sample.json b/server/lib/aiToolkit/defaults/providers.sample.json
index a75de034fa..24e934c983 100644
--- a/server/lib/aiToolkit/defaults/providers.sample.json
+++ b/server/lib/aiToolkit/defaults/providers.sample.json
@@ -114,6 +114,40 @@
"secretEnvVars": [],
"tuiPromptDelayMs": 2500
},
+ "opencode-lmstudio": {
+ "id": "opencode-lmstudio",
+ "name": "OpenCode LM Studio (local model)",
+ "type": "cli",
+ "command": "opencode",
+ "args": ["run"],
+ "models": [],
+ "defaultModel": null,
+ "lmstudioBacked": true,
+ "timeout": 600000,
+ "enabled": false,
+ "envVars": {
+ "OPENCODE_CONFIG_CONTENT": "{\"permission\":\"allow\",\"provider\":{\"lmstudio\":{\"npm\":\"@ai-sdk/openai-compatible\",\"name\":\"LM Studio (local)\",\"options\":{\"baseURL\":\"http://localhost:1234/v1\"}}}}"
+ },
+ "secretEnvVars": [],
+ "headlessArgs": []
+ },
+ "opencode-lmstudio-tui": {
+ "id": "opencode-lmstudio-tui",
+ "name": "OpenCode LM Studio TUI (local model)",
+ "type": "tui",
+ "command": "opencode",
+ "args": [],
+ "models": [],
+ "defaultModel": null,
+ "lmstudioBacked": true,
+ "timeout": 600000,
+ "enabled": false,
+ "envVars": {
+ "OPENCODE_CONFIG_CONTENT": "{\"permission\":\"allow\",\"provider\":{\"lmstudio\":{\"npm\":\"@ai-sdk/openai-compatible\",\"name\":\"LM Studio (local)\",\"options\":{\"baseURL\":\"http://localhost:1234/v1\"}}}}"
+ },
+ "secretEnvVars": [],
+ "tuiPromptDelayMs": 2500
+ },
"opencode-mtplx": {
"id": "opencode-mtplx",
"name": "OpenCode MTPLX (local MTP)",
diff --git a/server/lib/aiToolkit/internal/generationOptions.js b/server/lib/aiToolkit/internal/generationOptions.js
index f92dfda243..0419f1499e 100644
--- a/server/lib/aiToolkit/internal/generationOptions.js
+++ b/server/lib/aiToolkit/internal/generationOptions.js
@@ -28,12 +28,14 @@ const finiteNumber = (value, min, max) => {
* top_p with it, which is how the vLLM providers shipped with every generation
* control silently discarded on the OpenCode side (#4765).
*
- * @param {{temperature?:unknown, topP?:unknown, thinking?:unknown, llamaBacked?:boolean, mtplxBacked?:boolean, vllmBacked?:boolean, sglangBacked?:boolean}|null|undefined} provider
+ * @param {{temperature?:unknown, topP?:unknown, thinking?:unknown, lmstudioBacked?:boolean, llamaBacked?:boolean, mtplxBacked?:boolean, vllmBacked?:boolean, sglangBacked?:boolean}|null|undefined} provider
* @returns {{temperature?:number, top_p?:number, think?:boolean, chat_template_kwargs?:{enable_thinking:boolean}}}
*/
export function apiGenerationOptions(provider) {
const ollama = isOllamaBackedProvider(provider);
+ const lmstudio = provider?.lmstudioBacked === true;
if (!ollama
+ && !lmstudio
&& provider?.llamaBacked !== true
&& provider?.mtplxBacked !== true
&& provider?.vllmBacked !== true
@@ -46,8 +48,11 @@ export function apiGenerationOptions(provider) {
...(temperature === undefined ? {} : { temperature }),
...(topP === undefined ? {} : { top_p: topP }),
// Ollama takes its own native `think` boolean; llama.cpp / MTPLX / vLLM /
- // SGLang route the toggle through the chat template instead.
- ...(typeof provider.thinking !== 'boolean'
+ // SGLang route the toggle through the chat template instead. LM Studio takes
+ // neither — reasoning there is a property of the LOADED model instance, so
+ // a stored `thinking` would be a field nothing reads (`THINKING_STYLE` in
+ // ../../opencodeConfig.js says the same for its OpenCode wrappers).
+ ...(typeof provider.thinking !== 'boolean' || lmstudio
? {}
: ollama
? { think: provider.thinking }
diff --git a/server/lib/aiToolkit/internal/generationOptions.test.js b/server/lib/aiToolkit/internal/generationOptions.test.js
new file mode 100644
index 0000000000..84f59458fc
--- /dev/null
+++ b/server/lib/aiToolkit/internal/generationOptions.test.js
@@ -0,0 +1,29 @@
+import { describe, it, expect } from 'vitest';
+import { apiGenerationOptions } from './generationOptions.js';
+
+// The request body PortOS attaches for a locally-backed API run. Which fields
+// ride along is per-backend and silent when wrong: a field the daemon does not
+// read is simply ignored, so the stored control looks honoured while nothing
+// changes. Pin the two rules that are not obvious from the shape.
+describe('apiGenerationOptions', () => {
+ it('sends nothing at all for a cloud provider', () => {
+ expect(apiGenerationOptions({ temperature: 0.7, thinking: true })).toEqual({});
+ });
+
+ it('routes the thinking toggle by backend — native on Ollama, chat template elsewhere', () => {
+ expect(apiGenerationOptions({ ollamaBacked: true, thinking: false }))
+ .toEqual({ temperature: 0.6, think: false });
+ expect(apiGenerationOptions({ sglangBacked: true, temperature: 0.4, thinking: true }))
+ .toEqual({ temperature: 0.4, chat_template_kwargs: { enable_thinking: true } });
+ });
+
+ it('forwards sampling to LM Studio but never a thinking field', () => {
+ // LM Studio picks reasoning when the model INSTANCE is loaded; its
+ // OpenAI-compatible endpoint documents no per-request field for it, so a
+ // stored `thinking` must not be dressed up as one the daemon reads.
+ expect(apiGenerationOptions({ lmstudioBacked: true, temperature: 0.4, topP: 0.9, thinking: true }))
+ .toEqual({ temperature: 0.4, top_p: 0.9 });
+ // ...and unlike Ollama it gets no seeded temperature default either.
+ expect(apiGenerationOptions({ lmstudioBacked: true })).toEqual({});
+ });
+});
diff --git a/server/lib/aiToolkit/internal/modelFetchers.js b/server/lib/aiToolkit/internal/modelFetchers.js
index 60fb0edcf2..2264f62734 100644
--- a/server/lib/aiToolkit/internal/modelFetchers.js
+++ b/server/lib/aiToolkit/internal/modelFetchers.js
@@ -62,6 +62,18 @@ export const MODEL_FETCHERS = [
tuiMatch: (p) => isOllamaBackedProvider(p),
fetch: '_fetchOllamaToolCapableModels',
},
+ {
+ key: 'lmstudio',
+ // LM Studio publishes the models it has downloaded through the same
+ // OpenAI-compatible `/v1/models` contract as every other local daemon here,
+ // so an `lmstudioBacked` harness wrapper probes that endpoint rather than
+ // running `opencode models` / `codex` (which would inventory the harness).
+ // It authenticates nothing on loopback, so the wrapper's `apiKey` is blank
+ // and `_refreshAPIProviderModels` simply omits the Bearer header.
+ cliMatch: (p) => p?.lmstudioBacked === true,
+ tuiMatch: (p) => p?.lmstudioBacked === true,
+ fetch: '_fetchLmstudioModels',
+ },
{
key: 'mtplx',
// MTPLX exposes the selected native-MTP model through its OpenAI-compatible
diff --git a/server/lib/aiToolkit/internal/modelFetchers.test.js b/server/lib/aiToolkit/internal/modelFetchers.test.js
index e5c4e8ef6e..1ff5ac14b7 100644
--- a/server/lib/aiToolkit/internal/modelFetchers.test.js
+++ b/server/lib/aiToolkit/internal/modelFetchers.test.js
@@ -37,6 +37,10 @@ const SHIPPED_REFRESHABLE = [
// that, and Models → Harnesses ("Refresh models") is where it comes from.
'opencode-zen',
'opencode-vllm', 'opencode-vllm-tui',
+ // LM Studio publishes its downloaded catalog on the same OpenAI-compatible
+ // `/v1/models` endpoint the bare `lmstudio` API record already refreshes from,
+ // so the `lmstudioBacked` wrappers refresh through it too.
+ 'opencode-lmstudio', 'opencode-lmstudio-tui',
// SGLang publishes its served catalog through the same OpenAI-compatible
// `/v1/models` contract as the vLLM pair, so its wrappers refresh too.
'opencode-sglang', 'opencode-sglang-tui',
diff --git a/server/lib/aiToolkit/providers.js b/server/lib/aiToolkit/providers.js
index e36708a280..65130d7d32 100644
--- a/server/lib/aiToolkit/providers.js
+++ b/server/lib/aiToolkit/providers.js
@@ -675,6 +675,10 @@ export function createProviderService(config = {}) {
// MTPLX's native MTP runtime is a separate local OpenAI-compatible
// backend. Preserve this marker so OpenCode receives the `mtplx/`
// namespace and model refresh probes its local endpoint.
+ // LM Studio is a local backend PortOS already manages; preserve the
+ // marker so OpenCode receives the `lmstudio/` namespace and model
+ // refresh probes the LM Studio server rather than the harness.
+ ...(providerData.lmstudioBacked === true ? { lmstudioBacked: true } : {}),
...(providerData.mtplxBacked === true ? { mtplxBacked: true } : {}),
...(providerData.llamaBacked === true ? { llamaBacked: true } : {}),
// The local vLLM container is a third distinct local backend: preserve
@@ -1209,6 +1213,15 @@ export function createProviderService(config = {}) {
return this._refreshAPIProviderModels(provider);
},
+ /**
+ * Fetch the downloaded catalog from the local LM Studio server for its
+ * harness wrappers. Refresh-only, like every other local fetcher here: it
+ * never starts LM Studio, downloads a model, or issues a completion.
+ */
+ async _fetchLmstudioModels(provider) {
+ return this._refreshAPIProviderModels(provider);
+ },
+
/** Fetch the llama-server catalog for OpenCode llama CLI/TUI wrappers. */
async _fetchLlamaModels(provider) {
return this._refreshAPIProviderModels(provider);
diff --git a/server/lib/aiToolkit/providers.test.js b/server/lib/aiToolkit/providers.test.js
index 36ed17e3e3..6e8dbe3824 100644
--- a/server/lib/aiToolkit/providers.test.js
+++ b/server/lib/aiToolkit/providers.test.js
@@ -45,6 +45,18 @@ describe('Provider Service', () => {
expect(provider).toMatchObject({ temperature: 0.6, thinking: false });
});
+ it('preserves the lmstudioBacked marker through creation', async () => {
+ // `createProvider` has an EXPLICIT field list (unlike `updateProvider`'s
+ // spread), so a backend marker it does not name is silently dropped — the
+ // record then resolves no namespace, OpenCode falls through to its own
+ // built-in provider, and model refresh probes the harness instead of the
+ // LM Studio server.
+ const provider = await providerService.createProvider({
+ name: 'Local LM Studio', type: 'cli', command: 'opencode', lmstudioBacked: true,
+ });
+ expect(provider.lmstudioBacked).toBe(true);
+ });
+
it('should get all providers', async () => {
await providerService.createProvider({
name: 'Test Provider 1',
diff --git a/server/lib/aiToolkit/validation.js b/server/lib/aiToolkit/validation.js
index f42d0eaeb6..c6132330cb 100644
--- a/server/lib/aiToolkit/validation.js
+++ b/server/lib/aiToolkit/validation.js
@@ -147,6 +147,13 @@ export const providerSchema = z.object({
// local Ollama daemon — the "Claude Ollama" pattern. Drives model refresh to
// pull tool-use-capable Ollama models instead of the static Anthropic list.
ollamaBacked: z.boolean().optional(),
+ // Marks a harness wrapper (OpenCode, and Codex via its native `--oss
+ // --local-provider lmstudio`) whose backend is the LM Studio server on this
+ // machine. Distinct from `ollamaBacked`: a different daemon, a different port,
+ // and — unlike Ollama — a context window that is fixed when the model is
+ // LOADED rather than settable per request, so PortOS prepares nothing before a
+ // spawn (see `localRuntimeNamespace` in ../providerModels.js).
+ lmstudioBacked: z.boolean().optional(),
// Marks an OpenCode CLI/TUI wrapper for a separately started MTPLX native-MTP
// server. This is intentionally distinct from `ollamaBacked`: model weights
// and runtime protocol configuration are not interchangeable.
diff --git a/server/lib/cliChildEnv.js b/server/lib/cliChildEnv.js
index 7a37dcabe7..ec3f2384b9 100644
--- a/server/lib/cliChildEnv.js
+++ b/server/lib/cliChildEnv.js
@@ -164,7 +164,7 @@ function claudeLocalEnvDefaults(provider) {
* @param {object} options
* @param {object|null} [options.before] - layered first, so `provider.envVars`
* overrides it (forgeTokenEnv, claudeSettingsEnv).
- * @param {{command?:string, envVars?:object, models?:string[], defaultModel?:string|null, ollamaBacked?:boolean, mtplxBacked?:boolean, llamaBacked?:boolean, vllmBacked?:boolean, sglangBacked?:boolean, gatewayBacked?:string, orcarouterBacked?:boolean, thinking?:boolean}|null} [options.provider]
+ * @param {{command?:string, envVars?:object, models?:string[], defaultModel?:string|null, ollamaBacked?:boolean, lmstudioBacked?:boolean, mtplxBacked?:boolean, llamaBacked?:boolean, vllmBacked?:boolean, sglangBacked?:boolean, gatewayBacked?:string, orcarouterBacked?:boolean, thinking?:boolean}|null} [options.provider]
* @param {string|null} [options.model] - the model being run this invocation,
* unioned into the OpenCode declared-models map. Omit when the site has no
* per-call model — `provider.defaultModel` is always declared regardless.
diff --git a/server/lib/cliChildEnv.test.js b/server/lib/cliChildEnv.test.js
index e053ad4c01..9d0c33ec0e 100644
--- a/server/lib/cliChildEnv.test.js
+++ b/server/lib/cliChildEnv.test.js
@@ -510,7 +510,7 @@ describe('composeProviderEnv — delta for sites that do not spawn directly', ()
it('widens the Claude output ceiling for any LOCAL backend, never a hosted one', () => {
const forClaude = (extra) => composeProviderEnv({ provider: { command: 'claude', envVars: {}, ...extra } });
- for (const marker of ['ollamaBacked', 'sglangBacked', 'llamaBacked', 'mtplxBacked', 'vllmBacked']) {
+ for (const marker of ['ollamaBacked', 'lmstudioBacked', 'sglangBacked', 'llamaBacked', 'mtplxBacked', 'vllmBacked']) {
expect(forClaude({ [marker]: true }).CLAUDE_CODE_MAX_OUTPUT_TOKENS, marker).toBe('65536');
}
// OrcaRouter is a hosted gateway whose upstream models own their own output
diff --git a/server/lib/localProviderRuntime.js b/server/lib/localProviderRuntime.js
index a722d575cc..ae9346c3ff 100644
--- a/server/lib/localProviderRuntime.js
+++ b/server/lib/localProviderRuntime.js
@@ -76,8 +76,7 @@ export function localBackendForProvider(provider) {
* `defaultBaseUrl` is read from `opencodeConfig.js`'s provider table rather than
* re-typed: that table is what a spawned OpenCode actually talks to when the
* provider stores no config of its own, so a second copy here would eventually
- * probe a port nothing is on and call a working setup broken. LM Studio has no
- * row there (nothing spawns OpenCode against it), so it carries its own.
+ * probe a port nothing is on and call a working setup broken.
*
* `manageUrl` is the client route that installs/starts it — the Models → LLMs
* page owns every one of these flows, so an unmet requirement links there
@@ -131,10 +130,18 @@ export const LOCAL_RUNTIMES = Object.freeze({
id: 'lmstudio',
label: 'LM Studio',
command: 'lms',
- defaultBaseUrl: 'http://localhost:1234/v1',
+ defaultBaseUrl: opencodeLocalBaseUrl('lmstudio'),
manageUrl: '/models/llms',
docsUrl: 'https://lmstudio.ai/download',
modelsHint: 'Download a model in LM Studio and start its local server.',
+ // No pre-spawn context preparation, unlike Ollama's
+ // `ensureOllamaAgentContext`: LM Studio fixes a model's context length when
+ // the instance is LOADED, and the only lever PortOS holds is
+ // `lmStudioManager.loadModelWithArgs`, which UNLOADS whatever the user has
+ // resident and cold-loads the weights again. Paying that on every agent
+ // spawn — and evicting a model the operator loaded in the app — is worse
+ // than honouring the window they chose, so an `lmstudioBacked` provider's
+ // `numCtx` is set where the model is loaded, not here.
}),
vllm: Object.freeze({
id: 'vllm',
diff --git a/server/lib/localProviderRuntime.test.js b/server/lib/localProviderRuntime.test.js
index bf49755770..eef38e4673 100644
--- a/server/lib/localProviderRuntime.test.js
+++ b/server/lib/localProviderRuntime.test.js
@@ -62,6 +62,10 @@ describe('localRuntimeKind', () => {
expect(localRuntimeKind({ command: 'opencode', ollamaBacked: true })).toBe('ollama');
// claude-ollama is not an OpenCode provider but is still Ollama-backed.
expect(localRuntimeKind({ command: 'claude', ollamaBacked: true })).toBe('ollama');
+ // The marker is what makes a RENAMED LM Studio wrapper still resolve. The
+ // name/endpoint fallback below would miss this record entirely — it carries
+ // neither an `lmstudio` id/name nor a :1234 endpoint of its own.
+ expect(localRuntimeKind({ command: 'opencode', name: 'Coding box', lmstudioBacked: true })).toBe('lmstudio');
});
it('treats OrcaRouter as remote, not a local daemon', () => {
@@ -191,6 +195,7 @@ describe('localRuntimeForProvider', () => {
expect(LOCAL_RUNTIMES.llama.defaultBaseUrl).toBe(opencodeLocalBaseUrl('llama'));
expect(LOCAL_RUNTIMES.ollama.defaultBaseUrl).toBe(opencodeLocalBaseUrl('ollama'));
expect(LOCAL_RUNTIMES.mtplx.defaultBaseUrl).toBe(opencodeLocalBaseUrl('mtplx'));
+ expect(LOCAL_RUNTIMES.lmstudio.defaultBaseUrl).toBe(opencodeLocalBaseUrl('lmstudio'));
expect(LOCAL_RUNTIMES.vllm.defaultBaseUrl).toBe(opencodeLocalBaseUrl('vllm'));
expect(LOCAL_RUNTIMES.slotstream.defaultBaseUrl).toBe(`http://127.0.0.1:${PORTS.SLOTSTREAM}/v1`);
expect(LOCAL_RUNTIMES.slotstream.defaultBaseUrl).not.toMatch(/11434/);
diff --git a/server/lib/modelPricing.js b/server/lib/modelPricing.js
index 7a19beb301..5f74a4e153 100644
--- a/server/lib/modelPricing.js
+++ b/server/lib/modelPricing.js
@@ -319,7 +319,7 @@ export function isFreeProvider(providerOrId) {
if (providerOrId == null) return false;
if (typeof providerOrId === 'string') return FREE_ID.test(providerOrId);
const p = providerOrId;
- if (p.ollamaBacked === true || p.mtplxBacked === true || p.llamaBacked === true || p.vllmBacked === true || p.sglangBacked === true) return true;
+ if (p.ollamaBacked === true || p.lmstudioBacked === true || p.mtplxBacked === true || p.llamaBacked === true || p.vllmBacked === true || p.sglangBacked === true) return true;
if (FREE_ID.test(p.id || '') || FREE_ID.test(p.command || '')) return true;
if (typeof p.endpoint === 'string' && LOCALHOST_ENDPOINT.test(p.endpoint.trim())) return true;
return false;
diff --git a/server/lib/opencodeConfig.js b/server/lib/opencodeConfig.js
index b5be495257..41571f2d9e 100644
--- a/server/lib/opencodeConfig.js
+++ b/server/lib/opencodeConfig.js
@@ -61,6 +61,13 @@ const OPENCODE_LOCAL_BASE_PROVIDERS = {
name: 'Ollama (local)',
options: { baseURL: 'http://localhost:11434/v1' },
},
+ lmstudio: {
+ npm: '@ai-sdk/openai-compatible',
+ name: 'LM Studio (local)',
+ // LM Studio's own app default, not a PortOS-assigned port — it is not in
+ // `PORTS` for the same reason 11434 (Ollama) is not.
+ options: { baseURL: 'http://localhost:1234/v1' },
+ },
mtplx: {
npm: '@ai-sdk/openai-compatible',
name: 'MTPLX (local MTP)',
@@ -96,7 +103,7 @@ const OPENCODE_LOCAL_BASE_PROVIDERS = {
* — what a spawned OpenCode talks to when the provider stores no config of its
* own. Read by `lib/localProviderRuntime.js` so the readiness probe and the
* spawn agree on the endpoint instead of keeping two copies of these ports.
- * @param {'ollama'|'mtplx'|'llama'|'vllm'|'sglang'|string} providerKey
+ * @param {'ollama'|'lmstudio'|'mtplx'|'llama'|'vllm'|'sglang'|string} providerKey
* @returns {string|null}
*/
export const opencodeLocalBaseUrl = (providerKey) =>
@@ -167,6 +174,13 @@ export function toBareModelIds(models, providerKey = 'ollama') {
*/
const THINKING_STYLE = {
ollama: 'think',
+ // LM Studio exposes reasoning as a LOAD-TIME property of the model instance
+ // chosen in the app (or through `lms load`), not as a per-request field its
+ // OpenAI-compatible endpoint documents. Offering a toggle here would pin a
+ // value nothing reads — the same reason the gateways get `null` below. The
+ // temperature/top_p controls above it are ordinary OpenAI fields and do
+ // forward.
+ lmstudio: null,
mtplx: 'chatTemplate',
llama: 'chatTemplate',
// vLLM routes it through the chat template exactly as MTPLX and llama.cpp do
@@ -466,7 +480,7 @@ export function buildOpencodeConfigContent(models, base = null, providerKey = 'o
* model, and the model being run this invocation — so whichever namespaced
* `--model` the spawner passes is always accepted.
*
- * @param {{command?:string, ollamaBacked?:boolean, mtplxBacked?:boolean, llamaBacked?:boolean, vllmBacked?:boolean, sglangBacked?:boolean, gatewayBacked?:string, orcarouterBacked?:boolean, models?:string[], defaultModel?:string|null, apiKey?:string, orcarouterApiKey?:string, envVars?:object}} provider
+ * @param {{command?:string, ollamaBacked?:boolean, lmstudioBacked?:boolean, mtplxBacked?:boolean, llamaBacked?:boolean, vllmBacked?:boolean, sglangBacked?:boolean, gatewayBacked?:string, orcarouterBacked?:boolean, models?:string[], defaultModel?:string|null, apiKey?:string, orcarouterApiKey?:string, envVars?:object}} provider
* @param {string|null|undefined} model - the model being run (may differ from defaultModel)
* @param {{safetyProfile?:string|null}} [options] - a `no-tool` public-review
* profile applies `hardenOpencodeConfigForNoTool`, which IS OpenCode's
diff --git a/server/lib/opencodeConfig.test.js b/server/lib/opencodeConfig.test.js
index 645710e5d0..74bfab5d7c 100644
--- a/server/lib/opencodeConfig.test.js
+++ b/server/lib/opencodeConfig.test.js
@@ -392,12 +392,12 @@ describe('buildOpencodeEnvVars', () => {
// every generation control silently discarded (#4765). Walk LOCAL_RUNTIMES so a
// seventh runtime cannot land with the same hole.
describe('every OpenCode-reachable local runtime forwards generation controls', () => {
- // LM Studio is skipped deliberately — nothing spawns OpenCode against it, so
+ // Slotstream is skipped deliberately — nothing spawns OpenCode against it, so
// it has no provider entry (and no base URL) in opencodeConfig's table.
const opencodeRuntimes = Object.keys(LOCAL_RUNTIMES).filter((id) => opencodeLocalBaseUrl(id));
it('actually walks the runtimes (a degenerate filter would pass vacuously)', () => {
- expect(opencodeRuntimes).toEqual(expect.arrayContaining(['vllm', 'sglang']));
+ expect(opencodeRuntimes).toEqual(expect.arrayContaining(['vllm', 'sglang', 'lmstudio']));
expect(opencodeRuntimes.length).toBeGreaterThanOrEqual(5);
});
@@ -407,6 +407,27 @@ describe('every OpenCode-reachable local runtime forwards generation controls',
});
});
+describe('LM Studio OpenCode config', () => {
+ it('declares the lmstudio namespace at the local server', () => {
+ const result = buildOpencodeEnvVars(
+ { command: 'opencode', lmstudioBacked: true, models: ['qwen3-coder-30b'] },
+ 'qwen3-coder-30b',
+ );
+ const config = JSON.parse(result.OPENCODE_CONFIG_CONTENT);
+ expect(config.provider.lmstudio.options.baseURL).toBe('http://localhost:1234/v1');
+ expect(config.provider.lmstudio.models['qwen3-coder-30b']).toEqual({ name: 'qwen3-coder-30b', tool_call: true });
+ });
+
+ it('forwards sampling but never a thinking toggle — reasoning is a load-time choice', () => {
+ // LM Studio's OpenAI-compatible endpoint documents no per-request reasoning
+ // field: the instance is loaded with (or without) it in the app. A toggle
+ // here would pin a value nothing reads, so THINKING_STYLE.lmstudio is null —
+ // which must still leave temperature/topP/effort forwarding, the #4765 hole.
+ expect(buildAgentGeneration({ temperature: 0.7, topP: 0.9, thinking: true, effort: 'high' }, 'lmstudio'))
+ .toEqual({ temperature: 0.7, topP: 0.9, reasoningEffort: 'high' });
+ });
+});
+
describe('SGLang OpenCode config', () => {
it('declares the sglang namespace at the loopback container endpoint', () => {
const result = buildOpencodeEnvVars(
diff --git a/server/lib/processEnv.js b/server/lib/processEnv.js
index e87d20694c..7491757685 100644
--- a/server/lib/processEnv.js
+++ b/server/lib/processEnv.js
@@ -65,7 +65,7 @@ const CLI_PROVIDER_AUTH_RULES = Object.freeze({
cursor: { keys: ['CURSOR_API_KEY'], prefixes: [] },
});
-const LOCAL_PROVIDER_MARKERS = ['ollamaBacked', 'mtplxBacked', 'llamaBacked', 'vllmBacked', 'sglangBacked'];
+const LOCAL_PROVIDER_MARKERS = ['ollamaBacked', 'lmstudioBacked', 'mtplxBacked', 'llamaBacked', 'vllmBacked', 'sglangBacked'];
/**
* Build the non-secret provider metadata needed to classify ambient CLI auth
diff --git a/server/lib/providerFamilies.js b/server/lib/providerFamilies.js
index 94355aeb03..bcf2e3f79c 100644
--- a/server/lib/providerFamilies.js
+++ b/server/lib/providerFamilies.js
@@ -57,6 +57,6 @@ export const familyLabel = (id) => PROVIDER_FAMILIES.find((f) => f.id === id)?.l
* provider's spend to the subscription that actually covered it.
*/
export function familyForProvider(provider) {
- if (!provider || provider.ollamaBacked === true || provider.mtplxBacked === true || provider.llamaBacked === true || provider.vllmBacked === true || provider.sglangBacked === true) return null;
+ if (!provider || provider.ollamaBacked === true || provider.lmstudioBacked === true || provider.mtplxBacked === true || provider.llamaBacked === true || provider.vllmBacked === true || provider.sglangBacked === true) return null;
return PROVIDER_FAMILIES.find((f) => f.matches(provider))?.id ?? null;
}
diff --git a/server/lib/providerModels.js b/server/lib/providerModels.js
index 6e92640d56..93c0086abd 100644
--- a/server/lib/providerModels.js
+++ b/server/lib/providerModels.js
@@ -640,7 +640,7 @@ export const OPENCODE_BUILD_AGENT = 'build';
* already-qualified id (`openai/gpt-4o`, `anthropic/claude-sonnet`), and blindly
* prefixing `ollama/` would route it to the wrong backend. No-op for
* non-local / non-OpenCode providers and empty models.
- * @param {{command?:string, ollamaBacked?:boolean, mtplxBacked?:boolean, llamaBacked?:boolean, vllmBacked?:boolean, sglangBacked?:boolean, orcarouterBacked?:boolean}} provider
+ * @param {{command?:string, ollamaBacked?:boolean, lmstudioBacked?:boolean, mtplxBacked?:boolean, llamaBacked?:boolean, vllmBacked?:boolean, sglangBacked?:boolean, orcarouterBacked?:boolean}} provider
* @param {string|null|undefined} model
* @returns {string|null|undefined}
*/
@@ -667,11 +667,12 @@ export function prefixOpencodeModel(provider, model) {
* opted into one. Structural markers avoid deriving a backend from an editable
* display name or endpoint and preserve the legacy Ollama outcome if a malformed
* record carries both markers.
- * @param {{ollamaBacked?:boolean, mtplxBacked?:boolean, llamaBacked?:boolean, vllmBacked?:boolean, sglangBacked?:boolean, gatewayBacked?:string, orcarouterBacked?:boolean}|null|undefined} provider
- * @returns {'ollama'|'mtplx'|'llama'|'vllm'|'sglang'|string|null}
+ * @param {{ollamaBacked?:boolean, lmstudioBacked?:boolean, mtplxBacked?:boolean, llamaBacked?:boolean, vllmBacked?:boolean, sglangBacked?:boolean, gatewayBacked?:string, orcarouterBacked?:boolean}|null|undefined} provider
+ * @returns {'ollama'|'lmstudio'|'mtplx'|'llama'|'vllm'|'sglang'|string|null}
*/
export function getOpencodeLocalProviderNamespace(provider) {
if (provider?.ollamaBacked === true) return 'ollama';
+ if (provider?.lmstudioBacked === true) return 'lmstudio';
if (provider?.mtplxBacked === true) return 'mtplx';
if (provider?.llamaBacked === true) return 'llama';
if (provider?.vllmBacked === true) return 'vllm';
@@ -696,7 +697,7 @@ export function getOpencodeLocalProviderNamespace(provider) {
* it wraps.
*
* @param {object|null|undefined} provider
- * @returns {'ollama'|'mtplx'|'llama'|'vllm'|'sglang'|null}
+ * @returns {'ollama'|'lmstudio'|'mtplx'|'llama'|'vllm'|'sglang'|null}
*/
export function localRuntimeNamespace(provider) {
const namespace = getOpencodeLocalProviderNamespace(provider);
diff --git a/server/lib/providerModels.test.js b/server/lib/providerModels.test.js
index 85a4da11ce..33ed64ad60 100644
--- a/server/lib/providerModels.test.js
+++ b/server/lib/providerModels.test.js
@@ -196,6 +196,7 @@ describe('providerModels', () => {
it('uses explicit markers and keeps Ollama as the malformed dual-marker fallback', () => {
expect(getOpencodeLocalProviderNamespace({ ollamaBacked: true })).toBe('ollama');
expect(getOpencodeLocalProviderNamespace({ mtplxBacked: true })).toBe('mtplx');
+ expect(getOpencodeLocalProviderNamespace({ lmstudioBacked: true })).toBe('lmstudio');
expect(getOpencodeLocalProviderNamespace({ vllmBacked: true })).toBe('vllm');
expect(getOpencodeLocalProviderNamespace({ llamaBacked: true })).toBe('llama');
expect(getOpencodeLocalProviderNamespace({ orcarouterBacked: true })).toBe('orcarouter');
diff --git a/server/lib/systemCapabilities.js b/server/lib/systemCapabilities.js
index 2312f05f76..9c405ebf2e 100644
--- a/server/lib/systemCapabilities.js
+++ b/server/lib/systemCapabilities.js
@@ -104,6 +104,7 @@ const providerRuntimeRequirements = Object.freeze({
});
const localProvider = (provider) => provider?.ollamaBacked
+ || provider?.lmstudioBacked
|| provider?.llamaBacked
|| provider?.mtplxBacked
|| provider?.vllmBacked
diff --git a/server/lib/validation.js b/server/lib/validation.js
index 4715e5dd00..070aea0c1c 100644
--- a/server/lib/validation.js
+++ b/server/lib/validation.js
@@ -496,6 +496,10 @@ export const providerSchema = z.object({
defaultModel: z.string().nullable().optional(),
timeout: z.number().int().min(AI_RUN_TIMEOUT_MIN_MS).max(AI_RUN_TIMEOUT_MAX_MS).optional(),
enabled: z.boolean().optional(),
+ // Marks a harness wrapper whose backend is the LM Studio server on this
+ // machine. Unlike the containers below, its context window and reasoning are
+ // chosen when the model instance is LOADED, so PortOS forwards neither.
+ lmstudioBacked: z.boolean().optional(),
// Kept in schema parity with aiToolkit's provider schema. Marks OpenCode
// wrappers for a separately started local MTPLX native-MTP server.
mtplxBacked: z.boolean().optional(),
diff --git a/server/services/providerUsage.js b/server/services/providerUsage.js
index 66491f092a..08538d6e65 100644
--- a/server/services/providerUsage.js
+++ b/server/services/providerUsage.js
@@ -639,7 +639,7 @@ const FAMILIES = PROVIDER_FAMILIES.map((family) => ({ ...family, fetch: FAMILY_F
* wrapper its family's card).
*/
export function resolveEnabledFamilies(providers) {
- const enabled = (providers || []).filter((p) => p?.enabled && p.ollamaBacked !== true && p.mtplxBacked !== true && p.llamaBacked !== true && p.vllmBacked !== true && p.sglangBacked !== true);
+ const enabled = (providers || []).filter((p) => p?.enabled && p.ollamaBacked !== true && p.lmstudioBacked !== true && p.mtplxBacked !== true && p.llamaBacked !== true && p.vllmBacked !== true && p.sglangBacked !== true);
return FAMILIES.filter((family) => enabled.some((p) => family.matches(p)));
}
@@ -704,7 +704,7 @@ export async function getProviderQuotas({ wait = WAIT.CACHED, family = null } =
async function readProviderQuotas({ wait, family }) {
const result = await getAllProviders();
const providers = Array.isArray(result) ? result : (result?.providers || []);
- const enabled = providers.filter((p) => p?.enabled && p.ollamaBacked !== true && p.mtplxBacked !== true && p.llamaBacked !== true && p.vllmBacked !== true && p.sglangBacked !== true);
+ const enabled = providers.filter((p) => p?.enabled && p.ollamaBacked !== true && p.lmstudioBacked !== true && p.mtplxBacked !== true && p.llamaBacked !== true && p.vllmBacked !== true && p.sglangBacked !== true);
const families = resolveEnabledFamilies(providers).filter((f) => !family || f.id === family);
const familyCards = await Promise.all(families.map((f) =>
fetchFamilyQuota(f, { wait, providers: enabled.filter((p) => f.matches(p)) })));
diff --git a/server/services/quotaBurnJobs/providerPick.js b/server/services/quotaBurnJobs/providerPick.js
index 0c75055d07..8061f5a734 100644
--- a/server/services/quotaBurnJobs/providerPick.js
+++ b/server/services/quotaBurnJobs/providerPick.js
@@ -40,7 +40,7 @@ import { commandBasename } from '../../lib/providerModels.js';
*/
export function providerForFamily(providers, { familyId, providerId, prefer = 'tui' }) {
const available = (providers || []).filter((provider) =>
- provider?.enabled && provider.ollamaBacked !== true && provider.mtplxBacked !== true && provider.llamaBacked !== true && provider.vllmBacked !== true && provider.sglangBacked !== true
+ provider?.enabled && provider.ollamaBacked !== true && provider.lmstudioBacked !== true && provider.mtplxBacked !== true && provider.llamaBacked !== true && provider.vllmBacked !== true && provider.sglangBacked !== true
&& (provider.type === 'cli' || provider.type === 'tui'));
if (providerId) return available.find((provider) => provider.id === providerId) || null;
const inFamily = available.filter((provider) => matchesFamily(provider, familyId));
diff --git a/server/services/quotaBurnJobs/providerPick.test.js b/server/services/quotaBurnJobs/providerPick.test.js
index 5b8ecb2c6d..365c0f2b00 100644
--- a/server/services/quotaBurnJobs/providerPick.test.js
+++ b/server/services/quotaBurnJobs/providerPick.test.js
@@ -65,6 +65,7 @@ describe('providerForFamily', () => {
const providers = [
{ id: 'claude-ollama-tui', type: 'tui', enabled: true, ollamaBacked: true },
{ id: 'opencode-mtplx-tui', type: 'tui', enabled: true, mtplxBacked: true },
+ { id: 'opencode-lmstudio-tui', type: 'tui', enabled: true, lmstudioBacked: true },
{ id: 'claude-code-tui', type: 'tui', enabled: true },
{ id: 'claude-code', type: 'cli', enabled: true },
];
@@ -72,6 +73,7 @@ describe('providerForFamily', () => {
// Not even by explicit pin — it cannot do the one thing the job is for.
expect(providerForFamily(providers, { familyId: 'claude', providerId: 'claude-ollama-tui' })).toBeNull();
expect(providerForFamily(providers, { familyId: 'claude', providerId: 'opencode-mtplx-tui' })).toBeNull();
+ expect(providerForFamily(providers, { familyId: 'opencode', providerId: 'opencode-lmstudio-tui' })).toBeNull();
expect(providerForFamily([providers[0]], { familyId: 'claude' })).toBeNull();
});
});