@troed/oc-ls-stats 1.6.0 → 1.6.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/README.md +2 -2
- package/package.json +1 -1
- package/src/stats.ts +58 -0
- package/tui.tsx +17 -20
package/README.md
CHANGED
|
@@ -77,7 +77,7 @@ The plugin detects each server's type automatically by probing `GET /health`: a
|
|
|
77
77
|
|
|
78
78
|
### Slot Polling
|
|
79
79
|
|
|
80
|
-
Every 500ms, the plugin polls each discovered server, always carrying the
|
|
80
|
+
Every 500ms, the plugin polls each discovered server, always carrying the selected model as `?model=<model>` — the prompt's live selection, falling back to the session record. 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 no model is known yet, 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
|
|
|
@@ -128,7 +128,7 @@ Both instead report the live rates directly in `GET /metrics`, under `live`:
|
|
|
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 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
|
|
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 model for a short TTL (10 s), and a failed `/metrics` read drops the cached kind immediately: a router that swaps the backend behind a stable URL (for example a conduct/bazinga profile swap between Basalt and llama.cpp) is re-detected instead of leaving the plugin polling the wrong endpoint. 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
package/src/stats.ts
CHANGED
|
@@ -401,3 +401,61 @@ export function statsUrl(baseUrl: string, path: string, model?: string): string
|
|
|
401
401
|
export function serverKindKey(baseUrl: string, model?: string): string {
|
|
402
402
|
return `${baseUrl}\u0000${model ?? ""}`
|
|
403
403
|
}
|
|
404
|
+
|
|
405
|
+
// --- Server-kind cache ------------------------------------------------------
|
|
406
|
+
// A routing layer (conduct) answers /health for whichever backend it currently
|
|
407
|
+
// has loaded, not per model, so the kind behind a stable URL changes when the
|
|
408
|
+
// router swaps backends (a bazinga basalt -> llama flavor swap). The cache must
|
|
409
|
+
// therefore expire, and a failed backend-specific probe must invalidate it, or
|
|
410
|
+
// the plugin keeps calling /metrics on a llama server and shows n/a.
|
|
411
|
+
|
|
412
|
+
export const SERVER_KIND_TTL_MS = 10_000
|
|
413
|
+
|
|
414
|
+
export class ServerKindCache {
|
|
415
|
+
private readonly entries = new Map<string, { kind: ServerType; at: number }>()
|
|
416
|
+
|
|
417
|
+
constructor(private readonly ttlMs: number = SERVER_KIND_TTL_MS) {}
|
|
418
|
+
|
|
419
|
+
/** Drop a cached kind so the next resolve probes /health again. */
|
|
420
|
+
invalidate(baseUrl: string, model?: string): void {
|
|
421
|
+
this.entries.delete(serverKindKey(baseUrl, model))
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Return the cached kind while it is fresh, else probe. An unavailable
|
|
426
|
+
* /health is reported as "llama" (the historical fallback) and not cached,
|
|
427
|
+
* so a later probe can still identify a Strata or Basalt server.
|
|
428
|
+
*/
|
|
429
|
+
async resolve(
|
|
430
|
+
baseUrl: string,
|
|
431
|
+
model: string | undefined,
|
|
432
|
+
probe: () => Promise<ServerType | null>,
|
|
433
|
+
now: number = Date.now(),
|
|
434
|
+
): Promise<ServerType> {
|
|
435
|
+
const key = serverKindKey(baseUrl, model)
|
|
436
|
+
const cached = this.entries.get(key)
|
|
437
|
+
if (cached && now - cached.at < this.ttlMs) return cached.kind
|
|
438
|
+
const kind = await probe()
|
|
439
|
+
if (kind == null) return "llama"
|
|
440
|
+
this.entries.set(key, { kind, at: now })
|
|
441
|
+
return kind
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
export interface PollModel {
|
|
446
|
+
id: string
|
|
447
|
+
providerID?: string
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* The model to poll for. The prompt's live selection changes before the
|
|
452
|
+
* session record does, so prefer it and fall back to the session's model.
|
|
453
|
+
*/
|
|
454
|
+
export function selectPollModel(
|
|
455
|
+
prompt: { modelID: string; providerID: string } | undefined,
|
|
456
|
+
session: { id: string; providerID: string } | undefined,
|
|
457
|
+
): PollModel | undefined {
|
|
458
|
+
if (prompt && prompt.modelID) return { id: prompt.modelID, providerID: prompt.providerID }
|
|
459
|
+
if (session && session.id) return { id: session.id, providerID: session.providerID }
|
|
460
|
+
return undefined
|
|
461
|
+
}
|
package/tui.tsx
CHANGED
|
@@ -12,6 +12,8 @@ import {
|
|
|
12
12
|
mapLiveMetrics,
|
|
13
13
|
statsUrl,
|
|
14
14
|
serverKindKey,
|
|
15
|
+
ServerKindCache,
|
|
16
|
+
selectPollModel,
|
|
15
17
|
type ServerType,
|
|
16
18
|
} from "./src/stats.ts"
|
|
17
19
|
|
|
@@ -506,21 +508,15 @@ const v2Setup = async (context: any) => {
|
|
|
506
508
|
let llamaServerUrls: string[] = []
|
|
507
509
|
let providerList: unknown[] = []
|
|
508
510
|
const backoffByUrl = new Map<string, { failures: number; nextRetryAt: number }>()
|
|
509
|
-
const
|
|
511
|
+
const serverKindCache = new ServerKindCache()
|
|
510
512
|
const forcedServerType = serverTypeOverride((context.options as Record<string, unknown> | undefined)?.serverType)
|
|
511
513
|
|
|
512
514
|
const resolveServerKind = async (baseUrl: string, model?: string): Promise<ServerType> => {
|
|
513
515
|
if (forcedServerType) return forcedServerType
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
if (health != null) {
|
|
519
|
-
const kind = serverTypeFromHealth(health)
|
|
520
|
-
serverKindByUrl.set(key, kind)
|
|
521
|
-
return kind
|
|
522
|
-
}
|
|
523
|
-
return "llama"
|
|
516
|
+
return serverKindCache.resolve(baseUrl, model, async () => {
|
|
517
|
+
const health = await fetchHealth(baseUrl, model)
|
|
518
|
+
return health == null ? null : serverTypeFromHealth(health)
|
|
519
|
+
})
|
|
524
520
|
}
|
|
525
521
|
|
|
526
522
|
const noteServerFailure = (baseUrl: string) => {
|
|
@@ -545,16 +541,13 @@ const v2Setup = async (context: any) => {
|
|
|
545
541
|
const pollMetrics = async () => {
|
|
546
542
|
if (!llamaServerUrls.length) return
|
|
547
543
|
|
|
548
|
-
let model: string | undefined
|
|
549
|
-
let sessionProviderId: string | undefined
|
|
550
544
|
const routeSessionID = currentSessionID()
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
}
|
|
545
|
+
const route = context.ui.router.current?.()
|
|
546
|
+
const promptModel = route?.sessionID ? context.ui.model?.current?.() : undefined
|
|
547
|
+
const session = routeSessionID ? context.data.session.get(routeSessionID) : undefined
|
|
548
|
+
const selected = selectPollModel(promptModel, session?.model)
|
|
549
|
+
const model = selected?.id
|
|
550
|
+
const sessionProviderId = selected?.providerID
|
|
558
551
|
|
|
559
552
|
const activeUrls = selectSessionUrls(llamaServerUrls, providerList, sessionProviderId)
|
|
560
553
|
if (!activeUrls.length) {
|
|
@@ -574,6 +567,10 @@ const v2Setup = async (context: any) => {
|
|
|
574
567
|
if ((await resolveServerKind(baseUrl, model)) !== "llama") {
|
|
575
568
|
const live = await fetchLiveMetrics(baseUrl, model)
|
|
576
569
|
if (live == null) {
|
|
570
|
+
// A router can swap the backend behind this URL (a bazinga flavor
|
|
571
|
+
// swap), and /health then reports the new one. Drop the cached kind
|
|
572
|
+
// so the next poll re-detects instead of polling /metrics forever.
|
|
573
|
+
serverKindCache.invalidate(baseUrl, model)
|
|
577
574
|
noteServerFailure(baseUrl)
|
|
578
575
|
continue
|
|
579
576
|
}
|