mirror of
https://git.sync.wtf/troed/oc-ls-stats.git
synced 2026-08-31 09:43:38 +03:00
feat: read explicit server endpoint from plugin options
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
import type { TextRenderable } from "@opentui/core"
|
||||
import type { TuiPlugin, TuiPluginModule } from "@opencode-ai/plugin/tui"
|
||||
import { onCleanup } from "solid-js"
|
||||
import { backoffDelayMs, processPoll } from "./src/stats.ts"
|
||||
import { backoffDelayMs, processPoll, resolveServerUrls } from "./src/stats.ts"
|
||||
|
||||
type StreamSample = {
|
||||
at: number
|
||||
@@ -43,44 +43,6 @@ function estimateStreamTokens(delta: string) {
|
||||
return Math.max(1, Math.ceil(Buffer.byteLength(delta, "utf8") / 5))
|
||||
}
|
||||
|
||||
function stripBaseUrlPath(baseURL: string): string {
|
||||
try {
|
||||
const url = new URL(baseURL)
|
||||
return `${url.origin}`
|
||||
} catch {
|
||||
return baseURL.replace(/\/v1(\/.*)?$/, "").replace(/\/$/, "") || baseURL
|
||||
}
|
||||
}
|
||||
|
||||
function extractProviderUrls(config: unknown): string[] {
|
||||
if (!config || typeof config !== "object") return []
|
||||
const obj = config as Record<string, unknown>
|
||||
const provider = obj.provider
|
||||
if (!provider || typeof provider !== "object") return []
|
||||
|
||||
const urls: string[] = []
|
||||
for (const [key, val] of Object.entries(provider as Record<string, unknown>)) {
|
||||
if (val && typeof val === "object") {
|
||||
const opts = (val as Record<string, unknown>).options
|
||||
if (opts && typeof opts === "object") {
|
||||
const baseURL = (opts as Record<string, unknown>).baseURL || (opts as Record<string, unknown>).base_url
|
||||
if (typeof baseURL === "string" && key.toLowerCase().includes("llama") && !key.toLowerCase().includes("ollama")) {
|
||||
urls.push(stripBaseUrlPath(baseURL))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return urls
|
||||
}
|
||||
|
||||
async function loadConfigUrls(api: Parameters<TuiPlugin>[0]): Promise<string[]> {
|
||||
try {
|
||||
return extractProviderUrls(api.state.config as unknown)
|
||||
} catch (e) {
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchSlots(baseUrl: string, model?: string): Promise<unknown | null> {
|
||||
try {
|
||||
const url = model ? `${baseUrl}/slots?model=${encodeURIComponent(model)}` : `${baseUrl}/slots`
|
||||
@@ -148,7 +110,7 @@ function SessionPromptRight(props: {
|
||||
}
|
||||
}
|
||||
|
||||
const tui: TuiPlugin = async (api) => {
|
||||
const tui: TuiPlugin = async (api, options) => {
|
||||
console.log("[oc-ls-stats] TUI plugin loaded!")
|
||||
const tracker: TrackerState = {
|
||||
streamSamplesBySession: {},
|
||||
@@ -343,10 +305,9 @@ const tui: TuiPlugin = async (api) => {
|
||||
})
|
||||
|
||||
try {
|
||||
const configUrls = await loadConfigUrls(api)
|
||||
llamaServerUrls = configUrls.length > 0 ? configUrls : ["http://localhost:8080"]
|
||||
llamaServerUrls = resolveServerUrls(options, api.state.config)
|
||||
} catch (e) {
|
||||
console.error("[oc-ls-stats] loadConfigUrls error:", e)
|
||||
console.error("[oc-ls-stats] resolveServerUrls error:", e)
|
||||
llamaServerUrls = ["http://localhost:8080"]
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user