@troed/oc-ls-stats 1.5.0 → 1.6.0

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.
Files changed (4) hide show
  1. package/README.md +10 -10
  2. package/package.json +1 -1
  3. package/src/stats.ts +26 -17
  4. package/tui.tsx +16 -15
package/README.md CHANGED
@@ -6,7 +6,7 @@ There are many plugins to show tokens per second, but the reason for this one is
6
6
 
7
7
  Another motivation was to display the data of interest, but in a non-intrusive way with no UI elements jumping around. This plugin thus only shows a single numeric value, tokens per second, with an indicator as to whether the model is currently doing prompt processing or inference (token generation).
8
8
 
9
- I'm using the llama-server /slots endpoint to get the needed data. Strata (a llama.cpp-derived server with its own HTTP layer) is also supported: it exposes live prefill/decode rates under /metrics, and the plugin detects it automatically. If you connect opencode to an unrelated provider the plugin will just display "-" since it's not getting any data to display.
9
+ I'm using the llama-server /slots endpoint to get the needed data. Strata (a llama.cpp-derived server with its own HTTP layer) and Basalt (a Strata fork) are also supported: they expose live prefill/decode rates under /metrics, and the plugin detects them automatically. If you connect opencode to an unrelated provider the plugin will just display "-" since it's not getting any data to display.
10
10
 
11
11
  Note: As explained in further detail below the data that's displayed has to be deduced from llama-server's output. Sometimes the plugin might display PP for prompt processing while in reality the model is doing TG. If additional developments are made to the llama-server output data the plugin might be able to discern between them in a better way, but I think is as good as it gets for now.
12
12
 
@@ -63,21 +63,21 @@ If your llama-server provider is named differently, configure the endpoint expli
63
63
 
64
64
  A `baseURL`-style value ending in `/v1` is also accepted.
65
65
 
66
- The plugin detects each server's type automatically by probing `GET /health`: a Strata server reports `"service": "strata"`. You can bypass detection when needed with a `serverType` option:
66
+ The plugin detects each server's type automatically by probing `GET /health`: a Strata server reports `"service": "strata"` and a Basalt server reports `"service": "basalt"`. You can bypass detection when needed with a `serverType` option:
67
67
 
68
68
  ```json
69
69
  {
70
70
  "plugin": [
71
- ["@troed/oc-ls-stats@latest", { "serverType": "strata" }]
71
+ ["@troed/oc-ls-stats@latest", { "serverType": "basalt" }]
72
72
  ]
73
73
  }
74
74
  ```
75
75
 
76
- `serverType` accepts `"llama"` or `"strata"`; omit it (or set `"auto"`) for automatic detection.
76
+ `serverType` accepts `"llama"`, `"strata"` or `"basalt"`; omit it (or set `"auto"`) for automatic detection.
77
77
 
78
78
  ### Slot Polling
79
79
 
80
- Every 500ms, the plugin polls each discovered server, always carrying the current session's model as `?model=<model>`. For a llama.cpp server it calls `GET /slots?model=<model>`; for a Strata server it calls `GET /health?model=<model>` (to identify the server) and `GET /metrics?model=<model>` (reading the `live` object). Plain llama.cpp and Strata servers ignore the extra parameter; a routing layer that dispatches by model (e.g. one fronting several nodes) uses it to forward the call to the backend serving that model. If the model cannot be discovered from the current route's session, the plugin polls without it — direct servers still answer, while a model-dispatched router rejects the bare call and the plugin shows `n/a`.
80
+ Every 500ms, the plugin polls each discovered server, always carrying the current session's model as `?model=<model>`. For a llama.cpp server it calls `GET /slots?model=<model>`; for a Strata or Basalt server it calls `GET /health?model=<model>` (to identify the server) and `GET /metrics?model=<model>` (reading the `live` object). Plain llama.cpp, Strata and Basalt servers ignore the extra parameter; a routing layer that dispatches by model (e.g. one fronting several nodes) uses it to forward the call to the backend serving that model. If the model cannot be discovered from the current route's session, the plugin polls without it — direct servers still answer, while a model-dispatched router rejects the bare call and the plugin shows `n/a`.
81
81
 
82
82
  When a server returns an error (e.g. HTTP 502) or is unreachable, the plugin backs off with an exponentially increasing delay per server (1s, 2s, 4s, ...) capped at 10s, with a small random jitter to stagger multiple servers. Backoff resets as soon as the server responds successfully again.
83
83
 
@@ -118,17 +118,17 @@ During generation, the plugin calculates the instantaneous token generation rate
118
118
 
119
119
  Slot reuse is tracked via `generateSlotId` to detect when a new generation starts on a different slot.
120
120
 
121
- ### Strata Support
121
+ ### Strata and Basalt Support
122
122
 
123
- Strata is a llama.cpp-derived server with its own Python HTTP layer. Its `/slots` route is a minimal llama-server compatibility stub (`id`, `n_ctx`, `is_processing` only) with no `next_token`, `id_task`, or `n_prompt_tokens`, so the delta-based classification above cannot produce a rate against it.
123
+ Strata is a llama.cpp-derived server with its own Python HTTP layer. Basalt is a fork of Strata with the same stats surface. Their `/slots` route is a minimal llama-server compatibility stub (`id`, `n_ctx`, `is_processing` only) with no `next_token`, `id_task`, or `n_prompt_tokens`, so the delta-based classification above cannot produce a rate against them.
124
124
 
125
- Strata instead reports the live rates directly in `GET /metrics`, under `live`:
125
+ Both instead report the live rates directly in `GET /metrics`, under `live`:
126
126
 
127
- - `state` — `reading` (prompt processing), `generating`, `idle`, or `unloaded`
127
+ - `state` — `reading` (prompt processing), `generating`, `idle`, or `unloaded`; Basalt also reports `loading` and `asleep`
128
128
  - `prefill_tok_s_mean` — prompt processing rate while `reading` (PP)
129
129
  - `tok_s` — instantaneous decode rate while `generating` (TG)
130
130
 
131
- The plugin detects Strata per server URL from `GET /health` (`service: "strata"`) and maps these fields straight onto the display, so PP/TG are shown without delta estimation. Detection is cached per URL, and servers of both kinds can be polled side by side. Like the `/slots` requests, the plugin sends no API key; if Strata is configured to require one, it cannot read the stats.
131
+ The plugin detects them per server URL from `GET /health` (`service: "strata"` or `service: "basalt"`) and maps these fields straight onto the display, so PP/TG are shown without delta estimation. Detection is cached per URL, and servers of all kinds can be polled side by side. Like the `/slots` requests, the plugin sends no API key; if Strata or Basalt is configured to require one, it cannot read the stats.
132
132
 
133
133
  ## Limitations
134
134
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@troed/oc-ls-stats",
4
- "version": "1.5.0",
4
+ "version": "1.6.0",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "tui.tsx",
package/src/stats.ts CHANGED
@@ -309,23 +309,30 @@ export function selectSessionUrls(
309
309
  return []
310
310
  }
311
311
 
312
- // --- Strata adapter ---------------------------------------------------------
313
- // Strata is a llama.cpp-derived server whose HTTP layer is Python. Its /slots
314
- // route is a minimal compatibility stub, but /metrics.live carries the live
315
- // rates directly: prefill_tok_s_mean while reading, tok_s while generating.
312
+ // --- Live-metrics adapter ---------------------------------------------------
313
+ // Strata is a llama.cpp-derived server whose HTTP layer is Python; Basalt is a
314
+ // fork of Strata. Both expose a minimal /slots compatibility stub, but
315
+ // /metrics.live carries the live rates directly: prefill_tok_s_mean while
316
+ // reading, tok_s while generating.
316
317
 
317
- export type ServerType = "llama" | "strata"
318
+ export type ServerType = "llama" | "strata" | "basalt"
318
319
 
319
320
  /** Returns the explicit server type from the plugin option, or undefined for auto. */
320
321
  export function serverTypeOverride(value: unknown): ServerType | undefined {
321
- if (value === "llama" || value === "strata") return value
322
+ if (value === "llama" || value === "strata" || value === "basalt") return value
322
323
  return undefined
323
324
  }
324
325
 
325
- /** True when a parsed /health body identifies the server as Strata. */
326
- export function isStrataHealth(health: unknown): boolean {
327
- if (!health || typeof health !== "object") return false
328
- return (health as Record<string, unknown>).service === "strata"
326
+ /**
327
+ * Identify a server from its parsed /health body. Strata and Basalt both report
328
+ * their own `service`; anything else is treated as a plain llama.cpp server.
329
+ */
330
+ export function serverTypeFromHealth(health: unknown): ServerType {
331
+ if (!health || typeof health !== "object") return "llama"
332
+ const service = (health as Record<string, unknown>).service
333
+ if (service === "strata") return "strata"
334
+ if (service === "basalt") return "basalt"
335
+ return "llama"
329
336
  }
330
337
 
331
338
  function finiteOrZero(value: unknown): number {
@@ -333,11 +340,12 @@ function finiteOrZero(value: unknown): number {
333
340
  }
334
341
 
335
342
  /**
336
- * Map a Strata `/metrics.live` object onto the shared tracker. Strata reports
337
- * the rates itself, so no delta classification is needed: `state` says which
338
- * phase is active and `prefill_tok_s_mean` / `tok_s` carry the rate.
343
+ * Map a Strata or Basalt `/metrics.live` object onto the shared tracker. Both
344
+ * report the rates themselves, so no delta classification is needed: `state`
345
+ * says which phase is active and `prefill_tok_s_mean` / `tok_s` carry the rate.
346
+ * Basalt adds `loading` and `asleep` states; any non-active state clears them.
339
347
  */
340
- export function mapStrataLive(live: unknown, tracker: TrackerState): void {
348
+ export function mapLiveMetrics(live: unknown, tracker: TrackerState): void {
341
349
  const l = live && typeof live === "object" ? (live as Record<string, unknown>) : {}
342
350
  const state = typeof l.state === "string" ? l.state : ""
343
351
 
@@ -376,8 +384,8 @@ export function mapStrataLive(live: unknown, tracker: TrackerState): void {
376
384
  // --- Model-scoped stats URLs ------------------------------------------------
377
385
  // Stats are requested with the session's model so a routing layer that
378
386
  // dispatches by model (a LAN router in front of several nodes) can forward the
379
- // call to the right backend. Plain llama.cpp / Strata servers ignore the extra
380
- // query parameter.
387
+ // call to the right backend. Plain llama.cpp / Strata / Basalt servers ignore
388
+ // the extra query parameter.
381
389
 
382
390
  /** Build a stats URL, adding the model as `?model=` when one is known. */
383
391
  export function statsUrl(baseUrl: string, path: string, model?: string): string {
@@ -387,7 +395,8 @@ export function statsUrl(baseUrl: string, path: string, model?: string): string
387
395
  /**
388
396
  * Cache key for the detected server kind. One URL can front different backends
389
397
  * per model (e.g. a router), so the model belongs in the key: the same conduct
390
- * URL may be a Strata node for one model and a llama.cpp node for another.
398
+ * URL may be a Strata or Basalt node for one model and a llama.cpp node for
399
+ * another.
391
400
  */
392
401
  export function serverKindKey(baseUrl: string, model?: string): string {
393
402
  return `${baseUrl}\u0000${model ?? ""}`
package/tui.tsx CHANGED
@@ -8,8 +8,8 @@ import {
8
8
  resolveServerUrls,
9
9
  selectSessionUrls,
10
10
  serverTypeOverride,
11
- isStrataHealth,
12
- mapStrataLive,
11
+ serverTypeFromHealth,
12
+ mapLiveMetrics,
13
13
  statsUrl,
14
14
  serverKindKey,
15
15
  type ServerType,
@@ -74,11 +74,12 @@ async function fetchHealth(baseUrl: string, model?: string): Promise<unknown | n
74
74
  }
75
75
  }
76
76
 
77
- // Strata reports the live rates under /metrics.live (prefill_tok_s_mean while
78
- // reading, tok_s while generating) rather than in the minimal /slots stub. The
79
- // model is passed so a routing layer in front of the backend can forward the
80
- // call; plain llama.cpp / Strata servers ignore the parameter.
81
- async function fetchStrataLive(baseUrl: string, model?: string): Promise<unknown | null> {
77
+ // Strata and Basalt report the live rates under /metrics.live
78
+ // (prefill_tok_s_mean while reading, tok_s while generating) rather than in
79
+ // the minimal /slots stub. The model is passed so a routing layer in front of
80
+ // the backend can forward the call; plain llama.cpp / Strata / Basalt servers
81
+ // ignore the parameter.
82
+ async function fetchLiveMetrics(baseUrl: string, model?: string): Promise<unknown | null> {
82
83
  try {
83
84
  const resp = await fetch(statsUrl(baseUrl, "/metrics", model))
84
85
  if (!resp.ok) return null
@@ -225,7 +226,7 @@ const tui: TuiPlugin = async (api, options) => {
225
226
  if (cached) return cached
226
227
  const health = await fetchHealth(baseUrl, model)
227
228
  if (health != null) {
228
- const kind = isStrataHealth(health) ? "strata" : "llama"
229
+ const kind = serverTypeFromHealth(health)
229
230
  serverKindByUrl.set(key, kind)
230
231
  return kind
231
232
  }
@@ -275,15 +276,15 @@ const tui: TuiPlugin = async (api, options) => {
275
276
  continue
276
277
  }
277
278
 
278
- if ((await resolveServerKind(baseUrl, model)) === "strata") {
279
- const live = await fetchStrataLive(baseUrl, model)
279
+ if ((await resolveServerKind(baseUrl, model)) !== "llama") {
280
+ const live = await fetchLiveMetrics(baseUrl, model)
280
281
  if (live == null) {
281
282
  noteServerFailure(baseUrl)
282
283
  continue
283
284
  }
284
285
  backoffByUrl.delete(baseUrl)
285
286
  tracker.failure = null
286
- mapStrataLive(live, tracker)
287
+ mapLiveMetrics(live, tracker)
287
288
  bump()
288
289
  continue
289
290
  }
@@ -515,7 +516,7 @@ const v2Setup = async (context: any) => {
515
516
  if (cached) return cached
516
517
  const health = await fetchHealth(baseUrl, model)
517
518
  if (health != null) {
518
- const kind = isStrataHealth(health) ? "strata" : "llama"
519
+ const kind = serverTypeFromHealth(health)
519
520
  serverKindByUrl.set(key, kind)
520
521
  return kind
521
522
  }
@@ -570,15 +571,15 @@ const v2Setup = async (context: any) => {
570
571
  continue
571
572
  }
572
573
 
573
- if ((await resolveServerKind(baseUrl, model)) === "strata") {
574
- const live = await fetchStrataLive(baseUrl, model)
574
+ if ((await resolveServerKind(baseUrl, model)) !== "llama") {
575
+ const live = await fetchLiveMetrics(baseUrl, model)
575
576
  if (live == null) {
576
577
  noteServerFailure(baseUrl)
577
578
  continue
578
579
  }
579
580
  backoffByUrl.delete(baseUrl)
580
581
  tracker.failure = null
581
- mapStrataLive(live, tracker)
582
+ mapLiveMetrics(live, tracker)
582
583
  bump()
583
584
  continue
584
585
  }