From f4d2cb6e1766a2e4ba5a0a920f161a41f1cddee9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Troed=20S=C3=A5ngberg?= Date: Fri, 21 Aug 2026 11:16:22 +0200 Subject: [PATCH] feat: read explicit server endpoint from plugin options --- tui.tsx | 47 ++++------------------------------------------- 1 file changed, 4 insertions(+), 43 deletions(-) diff --git a/tui.tsx b/tui.tsx index 47268db..1a6179a 100644 --- a/tui.tsx +++ b/tui.tsx @@ -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 - const provider = obj.provider - if (!provider || typeof provider !== "object") return [] - - const urls: string[] = [] - for (const [key, val] of Object.entries(provider as Record)) { - if (val && typeof val === "object") { - const opts = (val as Record).options - if (opts && typeof opts === "object") { - const baseURL = (opts as Record).baseURL || (opts as Record).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[0]): Promise { - try { - return extractProviderUrls(api.state.config as unknown) - } catch (e) { - return [] - } -} - async function fetchSlots(baseUrl: string, model?: string): Promise { 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"] }