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 — opencode: added logic to probe loaded models from lmstudio, ollama an… by goniz · Pull Request #11951 · anomalyco/opencode

opencode: added logic to probe loaded models from lmstudio, ollama an… #11951

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
goniz wants to merge 13 commits into anomalyco:models-endpoint from goniz:models-endpoint-pr

Uh oh!

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

Closed

opencode: added logic to probe loaded models from lmstudio, ollama an… #11951

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit Hold shift + click to select a range
9a47124
opencode: added logic to probe loaded models from lmstudio, ollama an…
goniz Jan 15, 2026
7cd5036
opencode: added local provider url detection
goniz Feb 3, 2026
d07ee24
fix: prevent authorization header from using dummy API key
goniz Feb 3, 2026
10ff727
opencode: initial integration of ProviderModelDetection and LocalProv…
goniz Feb 3, 2026
d54adfb
fix: normalize local provider base urls
goniz Feb 3, 2026
8c10e02
fix: set api id for detected models
goniz Feb 3, 2026
4e4d154
refactor: updated debug provider commands
goniz Feb 3, 2026
fd5aede
fix: comment out adding new models
goniz Feb 3, 2026
75ded5e
fix: prevent local provider detection from running on cloud providers
goniz Feb 3, 2026
2c215da
fix: correct command order and naming for provider commands
goniz Feb 3, 2026
ff2f866
fix: remove 'object' field from OpenAICompatibleResponse causing errors
goniz Feb 3, 2026
1cd128d
add vLLM local provider support
goniz Feb 12, 2026
04a3e4e
add local provider setup in auth login
goniz Feb 13, 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
Prev Previous commit
Next Next commit
opencode: added local provider url detection
  • Loading branch information

Uh oh!

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

@goniz
goniz committed Feb 3, 2026
commit 7cd5036ea23947e9d63e588181f81505242986ee

There are no files selected for viewing

27 changes: 18 additions & 9 deletions 27 packages/opencode/src/cli/cmd/debug/provider.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,33 @@ export const ProviderCommand = cmd({
describe: "probe local LLM providers",
builder: (yargs) =>
yargs.command({
command: "probe <type> <url>",
command: "probe <url>",
describe: "probe a local provider for loaded models",
builder: (yargs) =>
yargs
.positional("type", {
describe: "provider type",
type: "string",
choices: Object.values(LocalProvider).filter((v) => typeof v === "string") as LocalProvider[],
})
.positional("url", {
describe: "provider URL",
type: "string",
}),
async handler(args) {
const type = args.type as LocalProvider
const url = args.url as string
const result = await LocalProvider.probe(type, url)
process.stdout.write(JSON.stringify(result, null, 2) + EOL)

const type = await LocalProvider.detect_provider(url);
if (!type) {
console.error(`No supported local provider detected at URL: ${url}`)
process.exit(1)
}

console.log(`Detected provider type: ${type} at URL: ${url}`)
const result = await LocalProvider.probe_provider(type, url)

if (result.length === 0) {
console.log("No loaded models found")
return
}

console.log(`Found ${result.length} loaded models:`)
console.log(JSON.stringify(result, null, 2))
},
}),
async handler() {},
Expand Down
41 changes: 36 additions & 5 deletions 41 packages/opencode/src/provider/local/index.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Log } from "../../util/log"
import { ollama_probe_loaded_models } from "./ollama"
import { lmstudio_probe_loaded_models } from "./lmstudio"
import { llamaccpp_probe_loaded_models } from "./llamacpp"
import { ollama_probe_loaded_models, ollama_detect_provider } from "./ollama"
import { lmstudio_probe_loaded_models, lmstudio_detect_provider } from "./lmstudio"
import { llamacpp_probe_loaded_models, llamacpp_detect_provider } from "./llamacpp"

export enum LocalProvider {
Ollama = "ollama",
Expand All @@ -19,16 +19,47 @@ export interface LocalModel {
export namespace LocalProvider {
const log = Log.create({ service: "localprovider" })

export async function probe(provider: LocalProvider, url: string): Promise<LocalModel[]> {
export async function detect_provider(url: string): Promise<LocalProvider | null> {
log.debug(`Detecting local provider at URL: ${url}`)

if (await ollama_detect_provider(url)) {
log.info(`Detected Ollama provider at URL: ${url}`)
return LocalProvider.Ollama
}

if (await lmstudio_detect_provider(url)) {
log.info(`Detected LMStudio provider at URL: ${url}`)
return LocalProvider.LMStudio
}

if (await llamacpp_detect_provider(url)) {
log.info(`Detected LlamaCPP provider at URL: ${url}`)
return LocalProvider.LlamaCPP
}

log.info(`No supported local provider detected at URL: ${url}`)
return null
}

export async function probe_provider(provider: LocalProvider, url: string): Promise<LocalModel[]> {
switch (provider) {
case LocalProvider.Ollama:
return await ollama_probe_loaded_models(url)
case LocalProvider.LMStudio:
return await lmstudio_probe_loaded_models(url)
case LocalProvider.LlamaCPP:
return await llamaccpp_probe_loaded_models(url)
return await llamacpp_probe_loaded_models(url)
default:
throw new Error(`Unsupported provider: ${provider}`)
}
}

export async function probe_url(url: string): Promise<[LocalProvider, LocalModel[]]> {
const provider = await detect_provider(url)
if (!provider) {
throw new Error(`No supported local provider detected at URL: ${url}`)
}

return [provider, await probe_provider(provider, url)]
}
}
57 changes: 36 additions & 21 deletions 57 packages/opencode/src/provider/local/llamacpp.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ export interface LlamaCppPropsResponse {
chat_template_caps?: Record<string, unknown>
}

function llamaccpp_base_url(url: string): string {
function llamacpp_base_url(url: string): string {
return url.replace(/\/$/, "")
}

function llamaccpp_tool_capable(caps?: Record<string, unknown>): boolean {
function llamacpp_tool_capable(caps?: Record<string, unknown>): boolean {
if (!caps) return false
const value = caps.supports_tool_calls
return value === true || value === "true"
}

function llamaccpp_context_from_meta(meta?: Record<string, unknown> | null): number {
function llamacpp_context_from_meta(meta?: Record<string, unknown> | null): number {
if (!meta) return 0
const ctxTrain = meta.n_ctx_train
if (typeof ctxTrain === "number" && ctxTrain > 0) return ctxTrain
Expand All @@ -56,15 +56,15 @@ function llamaccpp_context_from_meta(meta?: Record<string, unknown> | null): num
return 0
}

async function llamaccpp_fetch_models(url: string): Promise<LlamaCppModelsResponse | null> {
const endpoint = llamaccpp_base_url(url) + "/models"
async function llamacpp_fetch_models(url: string): Promise<LlamaCppModelsResponse | null> {
const endpoint = llamacpp_base_url(url) + "/models"
const res = await fetch(endpoint, { signal: AbortSignal.timeout(3000) })
if (!res.ok) return null
return res.json() as Promise<LlamaCppModelsResponse>
}

async function llamaccpp_fetch_v1_models(url: string): Promise<LlamaCppV1ModelsResponse> {
const endpoint = llamaccpp_base_url(url) + "/v1/models"
async function llamacpp_fetch_v1_models(url: string): Promise<LlamaCppV1ModelsResponse> {
const endpoint = llamacpp_base_url(url) + "/v1/models"
const res = await fetch(endpoint, { signal: AbortSignal.timeout(3000) })
if (!res.ok) {
const respText = await res.text()
Expand All @@ -74,8 +74,8 @@ async function llamaccpp_fetch_v1_models(url: string): Promise<LlamaCppV1ModelsR
return res.json() as Promise<LlamaCppV1ModelsResponse>
}

async function llamaccpp_fetch_props(url: string, model?: string): Promise<LlamaCppPropsResponse> {
const base = llamaccpp_base_url(url)
async function llamacpp_fetch_props(url: string, model?: string): Promise<LlamaCppPropsResponse> {
const base = llamacpp_base_url(url)
const query = model ? `?model=${encodeURIComponent(model)}` : ""
const endpoint = `${base}/props${query}`
const res = await fetch(endpoint, { signal: AbortSignal.timeout(3000) })
Expand All @@ -87,11 +87,11 @@ async function llamaccpp_fetch_props(url: string, model?: string): Promise<Llama
return res.json() as Promise<LlamaCppPropsResponse>
}

async function llamaccpp_model_from_props(url: string, id: string, model?: string): Promise<LocalModel> {
const props = await llamaccpp_fetch_props(url, model)
async function llamacpp_model_from_props(url: string, id: string, model?: string): Promise<LocalModel> {
const props = await llamacpp_fetch_props(url, model)
const context = props.default_generation_settings?.n_ctx ?? 0
const vision = props.modalities?.vision === true
const tool_call = llamaccpp_tool_capable(props.chat_template_caps)
const tool_call = llamacpp_tool_capable(props.chat_template_caps)

return {
id,
Expand All @@ -101,43 +101,58 @@ async function llamaccpp_model_from_props(url: string, id: string, model?: strin
}
}

async function llamaccpp_model_from_props_or_meta(
async function llamacpp_model_from_props_or_meta(
url: string,
id: string,
model: string | undefined,
meta?: Record<string, unknown> | null,
): Promise<LocalModel> {
return llamaccpp_model_from_props(url, id, model).catch(() => ({
return llamacpp_model_from_props(url, id, model).catch(() => ({
id,
context_length: llamaccpp_context_from_meta(meta),
context_length: llamacpp_context_from_meta(meta),
tool_call: false,
vision: false,
}))
}

export async function llamaccpp_probe_loaded_models(url: string): Promise<LocalModel[]> {
const models = await llamaccpp_fetch_models(url).catch(() => null)
export async function llamacpp_detect_provider(url: string): Promise<boolean> {
try {
const endpoint = llamacpp_base_url(url)
const res = await fetch(endpoint, { signal: AbortSignal.timeout(2000) })
if (!res.ok) {
return false
}

return res.headers.get("Server")?.toLowerCase() === "llama.cpp"
}
catch (e) {
return false
}
}

export async function llamacpp_probe_loaded_models(url: string): Promise<LocalModel[]> {
const models = await llamacpp_fetch_models(url).catch(() => null)
if (models) {
const items = models.data ?? []
const router = items.some((m) => m.status)
if (router) {
const loaded = items.filter((m) => m.status?.value === "loaded")
if (loaded.length === 0) return []
const v1 = await llamaccpp_fetch_v1_models(url).catch(() => ({ data: [] }) as LlamaCppV1ModelsResponse)
const v1 = await llamacpp_fetch_v1_models(url).catch(() => ({ data: [] }) as LlamaCppV1ModelsResponse)
const map = new Map(v1.data?.map((m) => [m.id, m.meta]) ?? [])
return Promise.all(
loaded.map((m) => {
const id = m.id
const meta = map.get(id) ?? null
return llamaccpp_model_from_props_or_meta(url, id, id, meta)
return llamacpp_model_from_props_or_meta(url, id, id, meta)
}),
)
}
}

const v1 = await llamaccpp_fetch_v1_models(url)
const v1 = await llamacpp_fetch_v1_models(url)
const v1items = v1.data ?? []
if (v1items.length === 0) return []

return Promise.all(v1items.map((m) => llamaccpp_model_from_props_or_meta(url, m.id, m.id, m.meta)))
return Promise.all(v1items.map((m) => llamacpp_model_from_props_or_meta(url, m.id, m.id, m.meta)))
}
22 changes: 22 additions & 0 deletions 22 packages/opencode/src/provider/local/lmstudio.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ca } from "zod/v4/locales"
import { type LocalModel } from "./index"

export interface LMStudioModel {
Expand All @@ -19,6 +20,27 @@ export interface LMStudioModelsResponse {
object: "list"
}

// Documented here: https://github.com/lmstudio-ai/lms/blob/main/src/createClient.ts#L18
interface LMStudioGreeting {
lmstudio: boolean
}

export async function lmstudio_detect_provider(url: string): Promise<boolean> {
try {
const endpoint = url.replace(/\/$/, "") + "/lmstudio-greeting"
const res = await fetch(endpoint, { signal: AbortSignal.timeout(2000) })
if (!res.ok) {
return false
}

const greeting = await res.json() as LMStudioGreeting
return greeting.lmstudio === true
}
catch (e) {
return false
}
}

export async function lmstudio_probe_loaded_models(url: string): Promise<LocalModel[]> {
const endpoint = url.replace(/\/$/, "") + "/api/v0/models"

Expand Down
15 changes: 15 additions & 0 deletions 15 packages/opencode/src/provider/local/ollama.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@ async function ollama_show_model(url: string, model: string): Promise<OllamaMode
return res.json() as Promise<OllamaModelShowResponse>
}

export async function ollama_detect_provider(url: string): Promise<boolean> {
const endpoint = url.replace(/\/$/, "") + "/"

try {
const res = await fetch(endpoint, { signal: AbortSignal.timeout(2000) })
if (!res.ok) {
return false
}

return await res.text() === "Ollama is running"
} catch (e) {
return false
}
}

export async function ollama_probe_loaded_models(url: string): Promise<LocalModel[]> {
const endpoint = url.replace(/\/$/, "") + "/api/ps"

Expand Down
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.