@troed/oc-ls-stats 1.0.4 → 1.0.17
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 +1 -1
- package/package.json +1 -4
- package/tui.tsx +21 -83
package/README.md
CHANGED
|
@@ -30,7 +30,7 @@ The plugin renders a single line in the session prompt right slot:
|
|
|
30
30
|
|
|
31
31
|
### Server Discovery
|
|
32
32
|
|
|
33
|
-
The plugin discovers the llama-server URL by reading the OpenCode configuration
|
|
33
|
+
The plugin discovers the llama-server URL by reading the OpenCode configuration via the TUI API and extracting `baseURL`/`base_url` fields from provider options whose name contains "llama" (but excludes providers whose name contains "ollama"). Falls back to `http://localhost:8080` if no matching provider is found.
|
|
34
34
|
|
|
35
35
|
### Slot Polling
|
|
36
36
|
|
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.0.
|
|
4
|
+
"version": "1.0.17",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
"./tui": {
|
|
@@ -16,8 +16,5 @@
|
|
|
16
16
|
"@opentui/core": "*",
|
|
17
17
|
"@opentui/solid": "*",
|
|
18
18
|
"solid-js": "*"
|
|
19
|
-
},
|
|
20
|
-
"dependencies": {
|
|
21
|
-
"@troed/oc-ls-stats": "https://registry.npmjs.org/@troed/oc-ls-stats/-/oc-ls-stats-1.0.3.tgz"
|
|
22
19
|
}
|
|
23
20
|
}
|
package/tui.tsx
CHANGED
|
@@ -49,70 +49,6 @@ function estimateStreamTokens(delta: string) {
|
|
|
49
49
|
return Math.max(1, Math.ceil(Buffer.byteLength(delta, "utf8") / 5))
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
function parseJSONC(text: string): unknown {
|
|
53
|
-
let result = ""
|
|
54
|
-
let inString = false
|
|
55
|
-
let escape = false
|
|
56
|
-
let i = 0
|
|
57
|
-
|
|
58
|
-
while (i < text.length) {
|
|
59
|
-
const ch = text[i]
|
|
60
|
-
|
|
61
|
-
if (escape) {
|
|
62
|
-
result += ch
|
|
63
|
-
escape = false
|
|
64
|
-
i++
|
|
65
|
-
continue
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (ch === "\\") {
|
|
69
|
-
result += ch
|
|
70
|
-
escape = true
|
|
71
|
-
i++
|
|
72
|
-
continue
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (ch === '"') {
|
|
76
|
-
result += ch
|
|
77
|
-
inString = !inString
|
|
78
|
-
i++
|
|
79
|
-
continue
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (inString) {
|
|
83
|
-
result += ch
|
|
84
|
-
i++
|
|
85
|
-
continue
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (ch === "/" && text[i + 1] === "/") {
|
|
89
|
-
while (i < text.length && text[i] !== "\n") i++
|
|
90
|
-
continue
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (ch === "/" && text[i + 1] === "*") {
|
|
94
|
-
i += 2
|
|
95
|
-
while (i < text.length - 1 && !(text[i] === "*" && text[i + 1] === "/")) i++
|
|
96
|
-
i += 2
|
|
97
|
-
result += " "
|
|
98
|
-
continue
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (ch === ",") {
|
|
102
|
-
const next = text.indexOf(/[\s}\]]/, i + 1)
|
|
103
|
-
if (next !== -1 && /[\s}\]]/.test(text[next])) {
|
|
104
|
-
i++
|
|
105
|
-
continue
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
result += ch
|
|
110
|
-
i++
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return JSON.parse(result)
|
|
114
|
-
}
|
|
115
|
-
|
|
116
52
|
function stripBaseUrlPath(baseURL: string): string {
|
|
117
53
|
try {
|
|
118
54
|
const url = new URL(baseURL)
|
|
@@ -129,12 +65,12 @@ function extractProviderUrls(config: unknown): string[] {
|
|
|
129
65
|
if (!provider || typeof provider !== "object") return []
|
|
130
66
|
|
|
131
67
|
const urls: string[] = []
|
|
132
|
-
for (const [
|
|
68
|
+
for (const [key, val] of Object.entries(provider as Record<string, unknown>)) {
|
|
133
69
|
if (val && typeof val === "object") {
|
|
134
70
|
const opts = (val as Record<string, unknown>).options
|
|
135
71
|
if (opts && typeof opts === "object") {
|
|
136
72
|
const baseURL = (opts as Record<string, unknown>).baseURL || (opts as Record<string, unknown>).base_url
|
|
137
|
-
if (typeof baseURL === "string" &&
|
|
73
|
+
if (typeof baseURL === "string" && key.toLowerCase().includes("llama") && !key.toLowerCase().includes("ollama")) {
|
|
138
74
|
urls.push(stripBaseUrlPath(baseURL))
|
|
139
75
|
}
|
|
140
76
|
}
|
|
@@ -145,13 +81,8 @@ function extractProviderUrls(config: unknown): string[] {
|
|
|
145
81
|
|
|
146
82
|
async function loadConfigUrls(api: Parameters<TuiPlugin>[0]): Promise<string[]> {
|
|
147
83
|
try {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
if (!resp.ok) return []
|
|
151
|
-
const text = await resp.text()
|
|
152
|
-
const config = parseJSONC(text)
|
|
153
|
-
return extractProviderUrls(config)
|
|
154
|
-
} catch {
|
|
84
|
+
return extractProviderUrls(api.state.config as unknown)
|
|
85
|
+
} catch (e) {
|
|
155
86
|
return []
|
|
156
87
|
}
|
|
157
88
|
}
|
|
@@ -280,7 +211,7 @@ const tui: TuiPlugin = async (api) => {
|
|
|
280
211
|
bump()
|
|
281
212
|
}
|
|
282
213
|
|
|
283
|
-
let llamaServerUrls: string[] = [
|
|
214
|
+
let llamaServerUrls: string[] = []
|
|
284
215
|
let llamaServerModel: string | undefined
|
|
285
216
|
|
|
286
217
|
const pollMetrics = async () => {
|
|
@@ -313,8 +244,9 @@ const tui: TuiPlugin = async (api) => {
|
|
|
313
244
|
continue
|
|
314
245
|
}
|
|
315
246
|
tracker.failure = null
|
|
247
|
+
bump()
|
|
316
248
|
|
|
317
|
-
|
|
249
|
+
|
|
318
250
|
|
|
319
251
|
for (const slot of slotList) {
|
|
320
252
|
if (slot?.is_processing) {
|
|
@@ -324,7 +256,13 @@ const tui: TuiPlugin = async (api) => {
|
|
|
324
256
|
|
|
325
257
|
for (const slotId of prevProcessingSlotIds) {
|
|
326
258
|
if (!currProcessingSlotIds.has(slotId)) {
|
|
327
|
-
|
|
259
|
+
const prev = tracker.prevNdBySlot[slotId]
|
|
260
|
+
if (prev) {
|
|
261
|
+
prev.hasIncreased = false
|
|
262
|
+
prev.baseline = 0
|
|
263
|
+
} else {
|
|
264
|
+
delete tracker.prevNdBySlot[slotId]
|
|
265
|
+
}
|
|
328
266
|
}
|
|
329
267
|
}
|
|
330
268
|
|
|
@@ -375,7 +313,7 @@ const tui: TuiPlugin = async (api) => {
|
|
|
375
313
|
tracker.prefillCapturedTokens = nt
|
|
376
314
|
tracker.prefillStartAt = now
|
|
377
315
|
tracker.lastPrefillRate = 0
|
|
378
|
-
|
|
316
|
+
|
|
379
317
|
}
|
|
380
318
|
} else {
|
|
381
319
|
if (tracker.isPrefilling) {
|
|
@@ -396,7 +334,7 @@ const tui: TuiPlugin = async (api) => {
|
|
|
396
334
|
const delta = nd - tracker.generatePrevNd
|
|
397
335
|
if (dt > 0 && delta > 0) {
|
|
398
336
|
tracker.lastGeneratedTps = delta / dt
|
|
399
|
-
|
|
337
|
+
|
|
400
338
|
}
|
|
401
339
|
tracker.generatePrevNd = nd
|
|
402
340
|
tracker.generateStartAt = now
|
|
@@ -405,7 +343,7 @@ const tui: TuiPlugin = async (api) => {
|
|
|
405
343
|
tracker.generatePrevNd = nd
|
|
406
344
|
tracker.generateStartAt = now
|
|
407
345
|
tracker.lastGeneratedTps = 0
|
|
408
|
-
|
|
346
|
+
|
|
409
347
|
}
|
|
410
348
|
} else {
|
|
411
349
|
if (tracker.isGenerating) {
|
|
@@ -414,7 +352,7 @@ const tui: TuiPlugin = async (api) => {
|
|
|
414
352
|
tracker.generateStartAt = 0
|
|
415
353
|
tracker.lastGeneratedTps = 0
|
|
416
354
|
genEnded = true
|
|
417
|
-
|
|
355
|
+
|
|
418
356
|
}
|
|
419
357
|
}
|
|
420
358
|
|
|
@@ -501,11 +439,11 @@ const tui: TuiPlugin = async (api) => {
|
|
|
501
439
|
})
|
|
502
440
|
|
|
503
441
|
try {
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
}
|
|
442
|
+
const configUrls = await loadConfigUrls(api)
|
|
443
|
+
llamaServerUrls = configUrls.length > 0 ? configUrls : ["http://localhost:8080"]
|
|
507
444
|
} catch (e) {
|
|
508
445
|
console.error("[oc-ls-stats] loadConfigUrls error:", e)
|
|
446
|
+
llamaServerUrls = ["http://localhost:8080"]
|
|
509
447
|
}
|
|
510
448
|
|
|
511
449
|
api.slots.register({
|