@oh-my-pi/omp-stats 13.7.0 → 13.7.3
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 +3 -3
- package/src/parser.ts +31 -6
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@oh-my-pi/omp-stats",
|
|
4
|
-
"version": "13.7.
|
|
4
|
+
"version": "13.7.3",
|
|
5
5
|
"description": "Local observability dashboard for pi AI usage statistics",
|
|
6
6
|
"homepage": "https://github.com/can1357/oh-my-pi",
|
|
7
7
|
"author": "Can Boluk",
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"build": "bun run build.ts"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@oh-my-pi/pi-ai": "13.7.
|
|
37
|
-
"@oh-my-pi/pi-utils": "13.7.
|
|
36
|
+
"@oh-my-pi/pi-ai": "13.7.3",
|
|
37
|
+
"@oh-my-pi/pi-utils": "13.7.3",
|
|
38
38
|
"@tailwindcss/node": "^4.2",
|
|
39
39
|
"chart.js": "^4.5",
|
|
40
40
|
"date-fns": "^4.1",
|
package/src/parser.ts
CHANGED
|
@@ -49,6 +49,33 @@ function extractStats(sessionFile: string, folder: string, entry: SessionMessage
|
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
const LF = 0x0a;
|
|
53
|
+
|
|
54
|
+
function parseSessionEntriesLenient(bytes: Uint8Array): { entries: SessionEntry[]; read: number } {
|
|
55
|
+
const entries: SessionEntry[] = [];
|
|
56
|
+
let cursor = 0;
|
|
57
|
+
|
|
58
|
+
while (cursor < bytes.length) {
|
|
59
|
+
const { values, error, read, done } = Bun.JSONL.parseChunk(bytes, cursor, bytes.length);
|
|
60
|
+
if (values.length > 0) {
|
|
61
|
+
entries.push(...(values as SessionEntry[]));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (error) {
|
|
65
|
+
const nextNewline = bytes.indexOf(LF, Math.max(read, cursor));
|
|
66
|
+
if (nextNewline === -1) break;
|
|
67
|
+
cursor = nextNewline + 1;
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (read <= cursor) break;
|
|
72
|
+
cursor = read;
|
|
73
|
+
if (done) break;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return { entries, read: cursor };
|
|
77
|
+
}
|
|
78
|
+
|
|
52
79
|
/**
|
|
53
80
|
* Parse a session file and extract all assistant message stats.
|
|
54
81
|
* Uses incremental reading with offset tracking.
|
|
@@ -69,10 +96,7 @@ export async function parseSessionFile(
|
|
|
69
96
|
const stats: MessageStats[] = [];
|
|
70
97
|
const start = Math.max(0, Math.min(fromOffset, bytes.length));
|
|
71
98
|
const unprocessed = bytes.subarray(start);
|
|
72
|
-
const {
|
|
73
|
-
if (error) throw error;
|
|
74
|
-
const entries = values as SessionEntry[];
|
|
75
|
-
|
|
99
|
+
const { entries, read } = parseSessionEntriesLenient(unprocessed);
|
|
76
100
|
for (const entry of entries) {
|
|
77
101
|
if (isAssistantMessage(entry)) {
|
|
78
102
|
const msgStats = extractStats(sessionPath, folder, entry);
|
|
@@ -127,14 +151,15 @@ export async function listAllSessionFiles(): Promise<string[]> {
|
|
|
127
151
|
* Find a specific entry in a session file.
|
|
128
152
|
*/
|
|
129
153
|
export async function getSessionEntry(sessionPath: string, entryId: string): Promise<SessionEntry | null> {
|
|
130
|
-
let
|
|
154
|
+
let bytes: Uint8Array;
|
|
131
155
|
try {
|
|
132
|
-
|
|
156
|
+
bytes = await Bun.file(sessionPath).bytes();
|
|
133
157
|
} catch (err) {
|
|
134
158
|
if (isEnoent(err)) return null;
|
|
135
159
|
throw err;
|
|
136
160
|
}
|
|
137
161
|
|
|
162
|
+
const { entries } = parseSessionEntriesLenient(bytes);
|
|
138
163
|
for (const entry of entries) {
|
|
139
164
|
if ("id" in entry && entry.id === entryId) {
|
|
140
165
|
return entry;
|