@oh-my-pi/omp-stats 8.5.0 → 8.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.
- package/package.json +2 -2
- package/src/parser.ts +9 -21
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oh-my-pi/omp-stats",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.6.0",
|
|
4
4
|
"description": "Local observability dashboard for pi AI usage statistics",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"directory": "packages/stats"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@oh-my-pi/pi-ai": "8.
|
|
51
|
+
"@oh-my-pi/pi-ai": "8.6.0",
|
|
52
52
|
"date-fns": "^4.1.0",
|
|
53
53
|
"lucide-react": "^0.563.0",
|
|
54
54
|
"react": "^19.2.3",
|
package/src/parser.ts
CHANGED
|
@@ -17,20 +17,6 @@ function extractFolderFromPath(sessionPath: string): string {
|
|
|
17
17
|
return dir.replace(/^--/, "/").replace(/--/g, "/");
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
/**
|
|
21
|
-
* Parse a single JSONL line into a session entry.
|
|
22
|
-
*/
|
|
23
|
-
function parseLine(line: string): SessionEntry | null {
|
|
24
|
-
const trimmed = line.trim();
|
|
25
|
-
if (!trimmed) return null;
|
|
26
|
-
|
|
27
|
-
try {
|
|
28
|
-
return JSON.parse(trimmed) as SessionEntry;
|
|
29
|
-
} catch {
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
20
|
/**
|
|
35
21
|
* Check if an entry is an assistant message.
|
|
36
22
|
*/
|
|
@@ -78,21 +64,24 @@ export async function parseSessionFile(
|
|
|
78
64
|
}
|
|
79
65
|
|
|
80
66
|
const text = await file.text();
|
|
67
|
+
const entries = Bun.JSONL.parse(text) as SessionEntry[];
|
|
81
68
|
const lines = text.split("\n");
|
|
82
69
|
const folder = extractFolderFromPath(sessionPath);
|
|
83
70
|
const stats: MessageStats[] = [];
|
|
84
71
|
|
|
85
72
|
let currentOffset = 0;
|
|
73
|
+
let entryIndex = 0;
|
|
86
74
|
for (const line of lines) {
|
|
87
75
|
const lineLength = line.length + 1; // +1 for newline
|
|
88
|
-
if (
|
|
89
|
-
const entry =
|
|
90
|
-
if (entry && isAssistantMessage(entry)) {
|
|
76
|
+
if (line.trim()) {
|
|
77
|
+
const entry = entries[entryIndex];
|
|
78
|
+
if (currentOffset >= fromOffset && entry && isAssistantMessage(entry)) {
|
|
91
79
|
const msgStats = extractStats(sessionPath, folder, entry);
|
|
92
80
|
if (msgStats) {
|
|
93
81
|
stats.push(msgStats);
|
|
94
82
|
}
|
|
95
83
|
}
|
|
84
|
+
entryIndex += 1;
|
|
96
85
|
}
|
|
97
86
|
currentOffset += lineLength;
|
|
98
87
|
}
|
|
@@ -154,11 +143,10 @@ export async function getSessionEntry(sessionPath: string, entryId: string): Pro
|
|
|
154
143
|
if (!(await file.exists())) return null;
|
|
155
144
|
|
|
156
145
|
const text = await file.text();
|
|
157
|
-
const
|
|
146
|
+
const entries = Bun.JSONL.parse(text) as SessionEntry[];
|
|
158
147
|
|
|
159
|
-
for (const
|
|
160
|
-
|
|
161
|
-
if (entry && "id" in entry && entry.id === entryId) {
|
|
148
|
+
for (const entry of entries) {
|
|
149
|
+
if ("id" in entry && entry.id === entryId) {
|
|
162
150
|
return entry;
|
|
163
151
|
}
|
|
164
152
|
}
|