feat: detect llama-server from resolved provider list

This commit is contained in:
Troed Sångberg
2026-08-21 12:21:46 +02:00
parent 0ecafb8d8a
commit f49caf05cd
2 changed files with 99 additions and 27 deletions
+25 -3
View File
@@ -241,7 +241,27 @@ export function extractProviderUrls(config: unknown): string[] {
return urls
}
export function resolveServerUrls(options: unknown, config: unknown): string[] {
export function extractProviderUrlsFromList(providers: unknown): string[] {
if (!Array.isArray(providers)) return []
const urls: string[] = []
for (const entry of providers) {
if (!entry || typeof entry !== "object") continue
const provider = entry as Record<string, unknown>
const id = typeof provider.id === "string" ? provider.id.toLowerCase() : ""
const name = typeof provider.name === "string" ? provider.name.toLowerCase() : ""
const hay = `${id} ${name}`
if (!hay.includes("llama") || hay.includes("ollama")) continue
const opts = provider.options
if (!opts || typeof opts !== "object") continue
const baseURL = (opts as Record<string, unknown>).baseURL || (opts as Record<string, unknown>).base_url
if (typeof baseURL === "string") {
urls.push(stripBaseUrlPath(baseURL))
}
}
return urls
}
export function resolveServerUrls(options: unknown, providers: unknown, config: unknown): string[] {
const opts = options && typeof options === "object" ? (options as Record<string, unknown>) : undefined
const server = opts?.server
const explicit = typeof server === "string" && server.trim() !== "" ? stripBaseUrlPath(server) : undefined
@@ -251,6 +271,8 @@ export function resolveServerUrls(options: unknown, config: unknown): string[] {
if (server !== undefined) {
console.warn("[oc-ls-stats] ignoring invalid 'server' plugin option, falling back to provider detection")
}
const detected = extractProviderUrls(config)
return detected.length > 0 ? detected : ["http://localhost:8080"]
const detected = extractProviderUrlsFromList(providers)
if (detected.length > 0) return detected
const legacy = extractProviderUrls(config)
return legacy.length > 0 ? legacy : ["http://localhost:8080"]
}