opencode-studio-server 1.3.1 → 1.3.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/index.js +8 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1227,11 +1227,18 @@ app.get('/api/usage', async (req, res) => {
|
|
|
1227
1227
|
const stats = { totalCost: 0, totalTokens: 0, byModel: {}, byTime: {}, byProject: {} };
|
|
1228
1228
|
const seen = new Set();
|
|
1229
1229
|
const now = Date.now();
|
|
1230
|
+
const from = Number(req.query.from || 0);
|
|
1231
|
+
const to = Number(req.query.to || 0);
|
|
1230
1232
|
let min = 0;
|
|
1233
|
+
let max = 0;
|
|
1231
1234
|
if (range === '24h') min = now - 86400000;
|
|
1232
1235
|
else if (range === '7d') min = now - 604800000;
|
|
1233
1236
|
else if (range === '30d') min = now - 2592000000;
|
|
1237
|
+
else if (range === '3m') min = now - 7776000000;
|
|
1238
|
+
else if (range === '6m') min = now - 15552000000;
|
|
1234
1239
|
else if (range === '1y') min = now - 31536000000;
|
|
1240
|
+
if (from) min = from;
|
|
1241
|
+
if (to) max = to;
|
|
1235
1242
|
|
|
1236
1243
|
const sessionDirs = await fs.promises.readdir(md);
|
|
1237
1244
|
await Promise.all(sessionDirs.map(async s => {
|
|
@@ -1252,6 +1259,7 @@ app.get('/api/usage', async (req, res) => {
|
|
|
1252
1259
|
const pid = pmap.get(s)?.id || 'unknown';
|
|
1253
1260
|
if (fid && fid !== 'all' && pid !== fid) continue;
|
|
1254
1261
|
if (min > 0 && msg.time.created < min) continue;
|
|
1262
|
+
if (max > 0 && msg.time.created > max) continue;
|
|
1255
1263
|
|
|
1256
1264
|
if (msg.role === 'assistant' && msg.tokens) {
|
|
1257
1265
|
const c = msg.cost || 0, it = msg.tokens.input || 0, ot = msg.tokens.output || 0, t = it + ot;
|