GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(provider): native lm studio auto-discovery by Aarogaming · Pull Request #20524 · anomalyco/opencode

feat(provider): native lm studio auto-discovery #20524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Aarogaming wants to merge 4 commits into anomalyco:dev from Aarogaming:feat/lm-studio-provider

Uh oh!

There was an error while loading. Please reload this page.

Closed

feat(provider): native lm studio auto-discovery #20524

Changes from 1 commit
Commits
Show all changes
4 commits
Select commit Hold shift + click to select a range
cc49be0
feat: native LM Studio support with dynamic model discovery
Aarogaming Mar 28, 2026
fb7aa6a
fix: unescape template literals in provider.ts
Aarogaming Mar 29, 2026
d380394
fix(ci): disable E2E paid requirement for PR forks
Aarogaming Apr 1, 2026
3e1f798
fix(ci): sync test.yml with dev to remove e2e paid requirement
Aarogaming Apr 2, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view
Next Next commit
feat: native LM Studio support with dynamic model discovery
  • Loading branch information

Uh oh!

There was an error while loading. Please reload this page.

@Aarogaming
Aarogaming committed Mar 29, 2026
commit cc49be0b1e9af48fe9c72f68faa8a339ef446522

There are no files selected for viewing

71 changes: 71 additions & 0 deletions 71 packages/opencode/src/provider/provider.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export namespace Provider {
"@ai-sdk/vercel": createVercel,
"gitlab-ai-provider": createGitLab,
"@ai-sdk/github-copilot": createGitHubCopilotOpenAICompatible,
"lmstudio": createOpenAICompatible,
}

type CustomModelLoader = (sdk: any, modelID: string, options?: Record<string, any>) => Promise<any>
Expand All @@ -154,6 +155,76 @@ export namespace Provider {
}

const CUSTOM_LOADERS: Record<string, CustomLoader> = {
async lmstudio() {
const baseURL = Env.get("LM_STUDIO_URL") || "http://127.0.0.1:1234/v1"
return {
autoload: true,
Comment thread
Comment on lines +160 to +161

Copilot AI Apr 1, 2026

Copy link

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

autoload: true here enables the LM Studio provider unconditionally whenever it exists in the models.dev database, even when the local LM Studio server isn’t running (in which case discoverModels() returns {}). That can expose non-functional models in the UI and lead to confusing runtime errors. Consider making autoload conditional on a quick reachability check / successful discovery (or only autoload after discovery yields at least one model).

Suggested change
return {
autoload: true,
// Determine whether LM Studio is reachable and has at least one model.
let autoload = false
try {
const res = await fetch(`${baseURL}/models`)
if (res.ok) {
const data = (await res.json()) as any
const hasModels = Array.isArray(data?.data) && data.data.length > 0
autoload = hasModels
}
} catch {
autoload = false
}
return {
autoload,

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Copilot uses AI. Check for mistakes.
options: { baseURL, apiKey: "lm-studio" },
async discoverModels() {
try {
const res = await fetch(`${baseURL}/models`)
Comment thread

Copilot AI Apr 1, 2026

Copy link

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fetch(${baseURL}/models) has no timeout/abort signal. If LM Studio is bound but slow/hung, provider initialization could block state loading indefinitely. Consider adding an AbortSignal.timeout(...) (and handling abort) to keep startup responsive.

Suggested change
const res = await fetch(`${baseURL}/models`)
const timeoutSignal =
typeof AbortSignal !== "undefined" && "timeout" in AbortSignal
? AbortSignal.timeout(5000)
: undefined
const res = await fetch(
`${baseURL}/models`,
timeoutSignal ? { signal: timeoutSignal } : undefined
)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Copilot uses AI. Check for mistakes.
if (!res.ok) return {}
Comment thread
Comment on lines +163 to +166

Copilot AI Apr 1, 2026

Copy link

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discoverModels() is wired into CUSTOM_LOADERS, but provider state currently only invokes discoveryLoaders[...]() for GitLab. As-is, LM Studio models returned here will never be merged into providers["lmstudio"].models, so the advertised auto-discovery won’t actually surface any models. Consider generalizing the discovery step to run for any provider with a discoverModels loader (and merge results) before the empty-models filter, or add an explicit LM Studio discovery/merge like the GitLab block.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Copilot uses AI. Check for mistakes.
const data = await res.json() as any
const models: Record<string, any> = {}
for (const m of (data.data || [])) {
if (m.id.includes("embedding")) continue // skip embeddings

const prettyName = m.id.split("/").pop() || m.id

models[`lmstudio/${m.id}`] = {
Comment thread

Copilot AI Apr 1, 2026

Copy link

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The discovered models map uses keys like lmstudio/${m.id} but sets providerID: "lmstudio". Provider model maps elsewhere use unprefixed model IDs as keys (the provider already scopes them), and parseModel() splits provider/model strings. With the current key format, model lookup/selection is likely to break (especially when m.id already contains /). Use m.id as the map key (scoped by provider) and keep the model id consistent with that key.

Suggested change
models[`lmstudio/${m.id}`] = {
models[m.id] = {

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Copilot uses AI. Check for mistakes.
id: m.id,
name: \`LM Studio: \${prettyName}\`,
providerID: "lmstudio",
family: "lmstudio-local",
api: {
id: m.id,
url: baseURL,
npm: "@ai-sdk/openai-compatible",
},
status: "active",
headers: {},
options: {},
cost: {
input: 0,
output: 0,
cache: { read: 0, write: 0 },
},
limit: {
context: 32000,
output: 4096,
},
capabilities: {
temperature: true,
reasoning: false,
attachment: false,
toolcall: true,
interleaved: false,
input: {
text: true,
audio: false,
image: false,
video: false,
pdf: false,
},
output: {
text: true,
audio: false,
image: false,
video: false,
pdf: false,
},
},
release_date: "2025-01-01",
variants: {},
}
}
return models
} catch (e) {
return {} // Return empty if LM Studio is not currently running
}
}
}
},
async anthropic() {
return {
autoload: false,
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.