mirror of
https://git.sync.wtf/troed/oc-ls-stats.git
synced 2026-08-31 09:43:38 +03:00
feat: detect llama-server from resolved provider list
This commit is contained in:
+25
-3
@@ -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"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user