@troed/oc-ls-stats 1.0.17 → 1.0.18
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/README.md +21 -12
- package/package.json +1 -1
- package/tui.tsx +30 -17
package/README.md
CHANGED
|
@@ -16,6 +16,22 @@ I made this for my own usage. If you find it useful as well I'm just happy.
|
|
|
16
16
|
|
|
17
17
|
_thanks to Tarquinen for their [oc-tps](https://github.com/Tarquinen/oc-tps), which I used as a base although I guess most of the code has now been replaced_
|
|
18
18
|
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
opencode plugin @troed/oc-ls-stats@latest --global
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Requires `opencode` `1.3.14` or newer.
|
|
26
|
+
|
|
27
|
+
TUI plugins are loaded from `~/.config/opencode/tui.json`, which after installation should look like this:
|
|
28
|
+
|
|
29
|
+
```json
|
|
30
|
+
{
|
|
31
|
+
"plugin": ["@troed/oc-ls-stats@latest"]
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
19
35
|
## Display Format
|
|
20
36
|
|
|
21
37
|
The plugin renders a single line in the session prompt right slot:
|
|
@@ -23,7 +39,8 @@ The plugin renders a single line in the session prompt right slot:
|
|
|
23
39
|
```
|
|
24
40
|
1247 tps (PP) -- during prefill
|
|
25
41
|
25 tps (TG) -- during generation
|
|
26
|
-
- tps (TG)
|
|
42
|
+
- tps (TG) -- idle
|
|
43
|
+
n/a -- unable to reach llama-server
|
|
27
44
|
```
|
|
28
45
|
|
|
29
46
|
## Detection and Calculation
|
|
@@ -88,19 +105,11 @@ The following changes to the `/slots` endpoint would improve the plugin's functi
|
|
|
88
105
|
|
|
89
106
|
5. **Model-agnostic slot data**: The `/slots` endpoint requires a model parameter. Returning all slots without model filtering, or supporting `*` as a wildcard, would simplify discovery when multiple models are loaded.
|
|
90
107
|
|
|
91
|
-
##
|
|
92
|
-
|
|
93
|
-
```bash
|
|
94
|
-
opencode plugin @troed/oc-ls-stats@latest --global
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
Requires `opencode` `1.3.14` or newer.
|
|
108
|
+
## Source code repo
|
|
98
109
|
|
|
99
|
-
|
|
110
|
+
For known issues, posting new ones, forking or contributing:
|
|
100
111
|
|
|
101
|
-
|
|
102
|
-
{"plugin": ["@troed/oc-ls-stats@latest"]}
|
|
103
|
-
```
|
|
112
|
+
https://codeberg.org/troed/oc-ls-stats
|
|
104
113
|
|
|
105
114
|
## Debug Logging
|
|
106
115
|
|
package/package.json
CHANGED
package/tui.tsx
CHANGED
|
@@ -3,7 +3,7 @@ import type { TuiPlugin, TuiPluginModule } from "@opencode-ai/plugin/tui"
|
|
|
3
3
|
import { createMemo, createSignal } from "solid-js"
|
|
4
4
|
import { appendFileSync } from "fs"
|
|
5
5
|
|
|
6
|
-
const DEBUG_ENABLED =
|
|
6
|
+
const DEBUG_ENABLED = true
|
|
7
7
|
const DEBUG_LOG = "/tmp/oc-ls-stats-debug.log"
|
|
8
8
|
function debug(...args: unknown[]) {
|
|
9
9
|
if (!DEBUG_ENABLED) return
|
|
@@ -28,7 +28,7 @@ type MessageTiming = {
|
|
|
28
28
|
lastTokenAt?: number
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
type TrackerState = {
|
|
31
|
+
type TrackerState = {
|
|
32
32
|
streamSamplesBySession: Record<string, StreamSample[]>
|
|
33
33
|
messageTimingByID: Record<string, MessageTiming>
|
|
34
34
|
lastPrefillRate: number
|
|
@@ -41,7 +41,7 @@ type TrackerState = {
|
|
|
41
41
|
generateSlotId: number | null
|
|
42
42
|
generatePrevNd: number
|
|
43
43
|
generateStartAt: number
|
|
44
|
-
prevNdBySlot: Record<number, { baseline: number; hasIncreased: boolean }>
|
|
44
|
+
prevNdBySlot: Record<number, { baseline: number; hasIncreased: boolean; idTask: number }>
|
|
45
45
|
failure: string | null
|
|
46
46
|
}
|
|
47
47
|
|
|
@@ -59,23 +59,32 @@ function stripBaseUrlPath(baseURL: string): string {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
function extractProviderUrls(config: unknown): string[] {
|
|
62
|
-
if (!config || typeof config !== "object") return []
|
|
62
|
+
if (!config || typeof config !== "object") { debug("extractProviderUrls: config is null/undefined or not object"); return [] }
|
|
63
63
|
const obj = config as Record<string, unknown>
|
|
64
64
|
const provider = obj.provider
|
|
65
|
-
if (!provider || typeof provider !== "object") return []
|
|
65
|
+
if (!provider || typeof provider !== "object") { debug("extractProviderUrls: no provider in config"); return [] }
|
|
66
66
|
|
|
67
67
|
const urls: string[] = []
|
|
68
|
+
let total = 0
|
|
69
|
+
let matched = 0
|
|
68
70
|
for (const [key, val] of Object.entries(provider as Record<string, unknown>)) {
|
|
71
|
+
total++
|
|
69
72
|
if (val && typeof val === "object") {
|
|
70
73
|
const opts = (val as Record<string, unknown>).options
|
|
71
74
|
if (opts && typeof opts === "object") {
|
|
72
75
|
const baseURL = (opts as Record<string, unknown>).baseURL || (opts as Record<string, unknown>).base_url
|
|
76
|
+
debug(`extractProviderUrls: provider="${key}" baseURL=${baseURL}`)
|
|
73
77
|
if (typeof baseURL === "string" && key.toLowerCase().includes("llama") && !key.toLowerCase().includes("ollama")) {
|
|
74
78
|
urls.push(stripBaseUrlPath(baseURL))
|
|
79
|
+
matched++
|
|
80
|
+
debug(`extractProviderUrls: MATCH provider="${key}" -> ${urls[urls.length-1]}`)
|
|
81
|
+
} else {
|
|
82
|
+
debug(`extractProviderUrls: SKIP provider="${key}" (llama=${key.toLowerCase().includes("llama")} ollama=${key.toLowerCase().includes("ollama")})`)
|
|
75
83
|
}
|
|
76
84
|
}
|
|
77
85
|
}
|
|
78
86
|
}
|
|
87
|
+
debug(`extractProviderUrls: total=${total} matched=${matched} urls=${JSON.stringify(urls)}`)
|
|
79
88
|
return urls
|
|
80
89
|
}
|
|
81
90
|
|
|
@@ -235,9 +244,13 @@ const tui: TuiPlugin = async (api) => {
|
|
|
235
244
|
const prevProcessingSlotIds = new Set(Object.keys(tracker.prevNdBySlot).map(Number))
|
|
236
245
|
const currProcessingSlotIds = new Set<number>()
|
|
237
246
|
|
|
247
|
+
debug(`pollMetrics: urls=${JSON.stringify(llamaServerUrls)} model=${model}`)
|
|
238
248
|
for (const baseUrl of llamaServerUrls) {
|
|
249
|
+
debug(`pollMetrics: polling ${baseUrl}`)
|
|
239
250
|
const slots = await fetchSlots(baseUrl, model)
|
|
251
|
+
debug(`pollMetrics: ${baseUrl} response=${JSON.stringify(slots)?.slice(0, 500)}`)
|
|
240
252
|
const slotList = Array.isArray(slots) ? slots : slots ? Object.values(slots) : []
|
|
253
|
+
debug(`pollMetrics: ${baseUrl} slotList.length=${slotList.length}`)
|
|
241
254
|
if (slotList.length === 0) {
|
|
242
255
|
tracker.failure = "n/a"
|
|
243
256
|
bump()
|
|
@@ -256,13 +269,7 @@ const tui: TuiPlugin = async (api) => {
|
|
|
256
269
|
|
|
257
270
|
for (const slotId of prevProcessingSlotIds) {
|
|
258
271
|
if (!currProcessingSlotIds.has(slotId)) {
|
|
259
|
-
|
|
260
|
-
if (prev) {
|
|
261
|
-
prev.hasIncreased = false
|
|
262
|
-
prev.baseline = 0
|
|
263
|
-
} else {
|
|
264
|
-
delete tracker.prevNdBySlot[slotId]
|
|
265
|
-
}
|
|
272
|
+
delete tracker.prevNdBySlot[slotId]
|
|
266
273
|
}
|
|
267
274
|
}
|
|
268
275
|
|
|
@@ -272,15 +279,20 @@ const tui: TuiPlugin = async (api) => {
|
|
|
272
279
|
if (!slot?.is_processing) continue
|
|
273
280
|
const slotId = slot.id
|
|
274
281
|
const nd = slot.next_token?.[0]?.n_decoded ?? 0
|
|
282
|
+
const idTask = slot.id_task ?? 0
|
|
275
283
|
const entry = tracker.prevNdBySlot[slotId]
|
|
276
|
-
const baseline = entry?.baseline
|
|
277
|
-
const hasIncreased = entry?.hasIncreased
|
|
284
|
+
const baseline = entry?.idTask === idTask ? entry.baseline : nd
|
|
285
|
+
const hasIncreased = entry?.idTask === idTask ? entry.hasIncreased : false
|
|
286
|
+
|
|
287
|
+
if (entry && entry.idTask !== idTask) {
|
|
288
|
+
debug(`slot ${slotId} id_task changed from ${entry.idTask} to ${idTask}, resetting state`)
|
|
289
|
+
}
|
|
278
290
|
|
|
279
291
|
if (!hasIncreased && nd <= baseline) {
|
|
280
292
|
prefillSlot = slot
|
|
281
293
|
break
|
|
282
294
|
} else if (nd > baseline) {
|
|
283
|
-
tracker.prevNdBySlot[slotId] = { baseline, hasIncreased: true }
|
|
295
|
+
tracker.prevNdBySlot[slotId] = { baseline, hasIncreased: true, idTask }
|
|
284
296
|
generateSlot = slot
|
|
285
297
|
}
|
|
286
298
|
}
|
|
@@ -289,9 +301,10 @@ const tui: TuiPlugin = async (api) => {
|
|
|
289
301
|
if (slot?.is_processing) {
|
|
290
302
|
const slotId = slot.id
|
|
291
303
|
const nd = slot.next_token?.[0]?.n_decoded ?? 0
|
|
304
|
+
const idTask = slot.id_task ?? 0
|
|
292
305
|
const entry = tracker.prevNdBySlot[slotId]
|
|
293
|
-
if (entry === undefined) {
|
|
294
|
-
tracker.prevNdBySlot[slotId] = { baseline: nd, hasIncreased: false }
|
|
306
|
+
if (entry === undefined || entry.idTask !== idTask) {
|
|
307
|
+
tracker.prevNdBySlot[slotId] = { baseline: nd, hasIncreased: false, idTask }
|
|
295
308
|
}
|
|
296
309
|
}
|
|
297
310
|
}
|