@troed/oc-ls-stats 1.1.5 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/tui.tsx +48 -80
package/package.json
CHANGED
package/tui.tsx
CHANGED
|
@@ -1,19 +1,9 @@
|
|
|
1
1
|
/** @jsxImportSource @opentui/solid */
|
|
2
|
+
import type { TextRenderable } from "@opentui/core"
|
|
2
3
|
import type { TuiPlugin, TuiPluginModule } from "@opencode-ai/plugin/tui"
|
|
3
|
-
import {
|
|
4
|
-
import { appendFileSync } from "fs"
|
|
4
|
+
import { onCleanup } from "solid-js"
|
|
5
5
|
import { processPoll } from "./src/stats.ts"
|
|
6
6
|
|
|
7
|
-
const DEBUG_ENABLED = false
|
|
8
|
-
const DEBUG_LOG = "/tmp/oc-ls-stats-debug.log"
|
|
9
|
-
function debug(...args: unknown[]) {
|
|
10
|
-
if (!DEBUG_ENABLED) return
|
|
11
|
-
try {
|
|
12
|
-
const line = `${args.map(a => typeof a === "object" ? JSON.stringify(a) : String(a)).join(" ")}\n`
|
|
13
|
-
appendFileSync(DEBUG_LOG, line)
|
|
14
|
-
} catch {}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
7
|
type StreamSample = {
|
|
18
8
|
at: number
|
|
19
9
|
tokens: number
|
|
@@ -61,32 +51,23 @@ function stripBaseUrlPath(baseURL: string): string {
|
|
|
61
51
|
}
|
|
62
52
|
|
|
63
53
|
function extractProviderUrls(config: unknown): string[] {
|
|
64
|
-
if (!config || typeof config !== "object")
|
|
54
|
+
if (!config || typeof config !== "object") return []
|
|
65
55
|
const obj = config as Record<string, unknown>
|
|
66
56
|
const provider = obj.provider
|
|
67
|
-
if (!provider || typeof provider !== "object")
|
|
57
|
+
if (!provider || typeof provider !== "object") return []
|
|
68
58
|
|
|
69
59
|
const urls: string[] = []
|
|
70
|
-
let total = 0
|
|
71
|
-
let matched = 0
|
|
72
60
|
for (const [key, val] of Object.entries(provider as Record<string, unknown>)) {
|
|
73
|
-
total++
|
|
74
61
|
if (val && typeof val === "object") {
|
|
75
62
|
const opts = (val as Record<string, unknown>).options
|
|
76
63
|
if (opts && typeof opts === "object") {
|
|
77
64
|
const baseURL = (opts as Record<string, unknown>).baseURL || (opts as Record<string, unknown>).base_url
|
|
78
|
-
debug(`extractProviderUrls: provider="${key}" baseURL=${baseURL}`)
|
|
79
65
|
if (typeof baseURL === "string" && key.toLowerCase().includes("llama") && !key.toLowerCase().includes("ollama")) {
|
|
80
66
|
urls.push(stripBaseUrlPath(baseURL))
|
|
81
|
-
matched++
|
|
82
|
-
debug(`extractProviderUrls: MATCH provider="${key}" -> ${urls[urls.length-1]}`)
|
|
83
|
-
} else {
|
|
84
|
-
debug(`extractProviderUrls: SKIP provider="${key}" (llama=${key.toLowerCase().includes("llama")} ollama=${key.toLowerCase().includes("ollama")})`)
|
|
85
67
|
}
|
|
86
68
|
}
|
|
87
69
|
}
|
|
88
70
|
}
|
|
89
|
-
debug(`extractProviderUrls: total=${total} matched=${matched} urls=${JSON.stringify(urls)}`)
|
|
90
71
|
return urls
|
|
91
72
|
}
|
|
92
73
|
|
|
@@ -123,46 +104,46 @@ function SessionPromptRight(props: {
|
|
|
123
104
|
api: Parameters<TuiPlugin>[0]
|
|
124
105
|
sessionID: string
|
|
125
106
|
tracker: TrackerState
|
|
126
|
-
|
|
127
|
-
clock: () => number
|
|
107
|
+
subscribe: (listener: () => void) => () => void
|
|
128
108
|
}) {
|
|
129
|
-
|
|
130
|
-
props.version()
|
|
131
|
-
props.clock()
|
|
132
|
-
const rate = props.tracker.lastGeneratedTps
|
|
133
|
-
if (!Number.isFinite(rate) || rate <= 0) return undefined
|
|
134
|
-
return rate
|
|
135
|
-
})
|
|
109
|
+
let textRef: TextRenderable | undefined
|
|
136
110
|
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
return rate
|
|
143
|
-
})
|
|
111
|
+
const sync = () => {
|
|
112
|
+
if (!textRef) return
|
|
113
|
+
textRef.content = getStatusText()
|
|
114
|
+
props.api.renderer.requestRender()
|
|
115
|
+
}
|
|
144
116
|
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
117
|
+
const unsubscribe = props.subscribe(sync)
|
|
118
|
+
onCleanup(unsubscribe)
|
|
119
|
+
|
|
120
|
+
return (
|
|
121
|
+
<text
|
|
122
|
+
ref={(ref: TextRenderable) => {
|
|
123
|
+
textRef = ref
|
|
124
|
+
sync()
|
|
125
|
+
}}
|
|
126
|
+
fg={props.api.theme.current.textMuted}
|
|
127
|
+
>
|
|
128
|
+
{getStatusText()}
|
|
129
|
+
</text>
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
function getStatusText() {
|
|
133
|
+
const s = props.tracker
|
|
134
|
+
if (s.failure) {
|
|
135
|
+
return s.failure
|
|
154
136
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
137
|
+
const pp = s.isPrefilling && s.lastPrefillRate > 0 ? formatPps(s.lastPrefillRate) : undefined
|
|
138
|
+
const tps = s.isGenerating && s.lastGeneratedTps > 0 ? formatTps(s.lastGeneratedTps) : undefined
|
|
139
|
+
let result = "- tps (TG)"
|
|
140
|
+
if (s.isPrefilling && pp) {
|
|
141
|
+
result = `${pp} tps (PP)`
|
|
142
|
+
} else if (s.isGenerating && tps) {
|
|
143
|
+
result = `${tps} tps (TG)`
|
|
159
144
|
}
|
|
160
|
-
const result = `- tps (TG)`
|
|
161
|
-
debug(`UI_TEXT="${result}" isPrefilling=${props.tracker.isPrefilling} isGenerating=${props.tracker.isGenerating} failure=${props.tracker.failure} pp=${pp} tps=${tps}`)
|
|
162
145
|
return result
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
return <>{text() ? <text fg={props.api.theme.current.textMuted}>{text()}</text> : null}</>
|
|
146
|
+
}
|
|
166
147
|
}
|
|
167
148
|
|
|
168
149
|
const tui: TuiPlugin = async (api) => {
|
|
@@ -184,10 +165,11 @@ const tui: TuiPlugin = async (api) => {
|
|
|
184
165
|
prevPromptTokensBySlot: {},
|
|
185
166
|
failure: null,
|
|
186
167
|
}
|
|
187
|
-
const
|
|
188
|
-
const [clock, setClock] = createSignal(Date.now())
|
|
168
|
+
const listeners = new Set<() => void>()
|
|
189
169
|
|
|
190
|
-
const bump = () =>
|
|
170
|
+
const bump = () => {
|
|
171
|
+
for (const listener of listeners) listener()
|
|
172
|
+
}
|
|
191
173
|
|
|
192
174
|
const pruneSamples = (now = Date.now()) => {
|
|
193
175
|
let changed = false
|
|
@@ -247,13 +229,9 @@ const tui: TuiPlugin = async (api) => {
|
|
|
247
229
|
}
|
|
248
230
|
}
|
|
249
231
|
|
|
250
|
-
debug(`pollMetrics: urls=${JSON.stringify(llamaServerUrls)} model=${model}`)
|
|
251
232
|
for (const baseUrl of llamaServerUrls) {
|
|
252
|
-
debug(`pollMetrics: polling ${baseUrl}`)
|
|
253
233
|
const slots = await fetchSlots(baseUrl, model)
|
|
254
|
-
debug(`pollMetrics: ${baseUrl} response=${JSON.stringify(slots)}`)
|
|
255
234
|
const slotList = Array.isArray(slots) ? slots : slots ? Object.values(slots) : []
|
|
256
|
-
debug(`pollMetrics: ${baseUrl} slotList.length=${slotList.length}`)
|
|
257
235
|
if (slotList.length === 0) {
|
|
258
236
|
tracker.failure = "n/a"
|
|
259
237
|
bump()
|
|
@@ -264,19 +242,6 @@ const tui: TuiPlugin = async (api) => {
|
|
|
264
242
|
|
|
265
243
|
const result = processPoll(slotList, tracker)
|
|
266
244
|
bump()
|
|
267
|
-
|
|
268
|
-
if (result.isPrefilling) {
|
|
269
|
-
debug(`PP rate=${Math.round(result.lastPrefillRate)} tps`)
|
|
270
|
-
}
|
|
271
|
-
if (result.isGenerating) {
|
|
272
|
-
debug(`TG rate=${Math.round(result.lastGeneratedTps)} tps`)
|
|
273
|
-
}
|
|
274
|
-
if (result.ppEnded) {
|
|
275
|
-
debug(`PP ended rate=${Math.round(result.lastPrefillRate)} tps`)
|
|
276
|
-
}
|
|
277
|
-
if (result.tgEnded) {
|
|
278
|
-
debug(`TG ended rate=${Math.round(result.lastGeneratedTps)} tps`)
|
|
279
|
-
}
|
|
280
245
|
}
|
|
281
246
|
}
|
|
282
247
|
|
|
@@ -337,7 +302,6 @@ const tui: TuiPlugin = async (api) => {
|
|
|
337
302
|
})
|
|
338
303
|
|
|
339
304
|
const timer = setInterval(() => {
|
|
340
|
-
setClock(Date.now())
|
|
341
305
|
pruneSamples()
|
|
342
306
|
}, 1000)
|
|
343
307
|
|
|
@@ -364,8 +328,12 @@ const tui: TuiPlugin = async (api) => {
|
|
|
364
328
|
api.slots.register({
|
|
365
329
|
slots: {
|
|
366
330
|
session_prompt_right(_ctx, value) {
|
|
367
|
-
|
|
368
|
-
|
|
331
|
+
return <SessionPromptRight api={api} sessionID={value.session_id} tracker={tracker} subscribe={(listener) => {
|
|
332
|
+
listeners.add(listener)
|
|
333
|
+
return () => {
|
|
334
|
+
listeners.delete(listener)
|
|
335
|
+
}
|
|
336
|
+
}} />
|
|
369
337
|
},
|
|
370
338
|
},
|
|
371
339
|
})
|