storyforge 0.4.13 → 0.4.14
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.
|
@@ -172,34 +172,63 @@ async function gatherCliUsage() {
|
|
|
172
172
|
else lines.push(...parsed);
|
|
173
173
|
}
|
|
174
174
|
const now = Date.now();
|
|
175
|
+
const cutoff5h = now - 5 * 60 * 60 * 1e3;
|
|
175
176
|
const cutoff24h = now - 24 * 60 * 60 * 1e3;
|
|
177
|
+
const cutoff7d = now - 7 * 24 * 60 * 60 * 1e3;
|
|
176
178
|
const startToday = startOfTodayMs(now);
|
|
179
|
+
const messageCounts = { last5h: 0, last24h: 0, last7d: 0, today: 0, lifetime: 0 };
|
|
177
180
|
const buckets = {
|
|
181
|
+
last5h: {},
|
|
178
182
|
last24h: {},
|
|
183
|
+
last7d: {},
|
|
179
184
|
today: {},
|
|
180
185
|
lifetime: {}
|
|
181
186
|
};
|
|
182
187
|
for (const ln of lines) {
|
|
183
188
|
addUsage(buckets.lifetime, ln.model, ln.delta);
|
|
184
|
-
|
|
185
|
-
if (ln.ts >=
|
|
189
|
+
messageCounts.lifetime++;
|
|
190
|
+
if (ln.ts >= cutoff7d) {
|
|
191
|
+
addUsage(buckets.last7d, ln.model, ln.delta);
|
|
192
|
+
messageCounts.last7d++;
|
|
193
|
+
}
|
|
194
|
+
if (ln.ts >= cutoff24h) {
|
|
195
|
+
addUsage(buckets.last24h, ln.model, ln.delta);
|
|
196
|
+
messageCounts.last24h++;
|
|
197
|
+
}
|
|
198
|
+
if (ln.ts >= cutoff5h) {
|
|
199
|
+
addUsage(buckets.last5h, ln.model, ln.delta);
|
|
200
|
+
messageCounts.last5h++;
|
|
201
|
+
}
|
|
202
|
+
if (ln.ts >= startToday) {
|
|
203
|
+
addUsage(buckets.today, ln.model, ln.delta);
|
|
204
|
+
messageCounts.today++;
|
|
205
|
+
}
|
|
186
206
|
}
|
|
187
207
|
function finalise(rec) {
|
|
188
208
|
return Object.values(rec).map(recompute).sort((a, b) => b.costUsd - a.costUsd);
|
|
189
209
|
}
|
|
210
|
+
const last5h = finalise(buckets.last5h);
|
|
190
211
|
const last24h = finalise(buckets.last24h);
|
|
212
|
+
const last7d = finalise(buckets.last7d);
|
|
191
213
|
const today = finalise(buckets.today);
|
|
192
214
|
const lifetime = finalise(buckets.lifetime);
|
|
193
|
-
function sum(rows) {
|
|
215
|
+
function sum(rows, messages) {
|
|
194
216
|
return {
|
|
195
217
|
tokens: rows.reduce((s, r) => s + r.inputTokens + r.cachedReadTokens + r.cacheCreateTokens + r.outputTokens, 0),
|
|
196
|
-
costUsd: rows.reduce((s, r) => s + r.costUsd, 0)
|
|
218
|
+
costUsd: rows.reduce((s, r) => s + r.costUsd, 0),
|
|
219
|
+
messages
|
|
197
220
|
};
|
|
198
221
|
}
|
|
199
222
|
return {
|
|
200
223
|
generatedAt: new Date(now).toISOString(),
|
|
201
|
-
windows: { last24h, today, lifetime },
|
|
202
|
-
totals: {
|
|
224
|
+
windows: { last5h, last24h, last7d, today, lifetime },
|
|
225
|
+
totals: {
|
|
226
|
+
last5h: sum(last5h, messageCounts.last5h),
|
|
227
|
+
last24h: sum(last24h, messageCounts.last24h),
|
|
228
|
+
last7d: sum(last7d, messageCounts.last7d),
|
|
229
|
+
today: sum(today, messageCounts.today),
|
|
230
|
+
lifetime: sum(lifetime, messageCounts.lifetime)
|
|
231
|
+
},
|
|
203
232
|
sources: { claudeFiles: claudeFiles.length, codexFiles: codexFiles.length, skipped }
|
|
204
233
|
};
|
|
205
234
|
}
|
package/dist/index.js
CHANGED
|
@@ -866,7 +866,7 @@ async function devCommand(options) {
|
|
|
866
866
|
const pathname = url.pathname;
|
|
867
867
|
if (pathname === "/api/cli-usage") {
|
|
868
868
|
try {
|
|
869
|
-
const { gatherCliUsage } = await import("./cli-usage-
|
|
869
|
+
const { gatherCliUsage } = await import("./cli-usage-OFFQXJQN.js");
|
|
870
870
|
const report = await gatherCliUsage();
|
|
871
871
|
res.writeHead(200, { ...CORS_HEADERS, "Content-Type": "application/json" });
|
|
872
872
|
res.end(JSON.stringify(report));
|