myrlin-workbook 0.9.1 → 0.9.2
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 +1 -1
- package/src/web/server.js +14 -3
package/package.json
CHANGED
package/src/web/server.js
CHANGED
|
@@ -2846,10 +2846,21 @@ app.get('/api/cost/dashboard', requireAuth, (req, res) => {
|
|
|
2846
2846
|
}
|
|
2847
2847
|
}
|
|
2848
2848
|
|
|
2849
|
-
//
|
|
2850
|
-
|
|
2849
|
+
// Apportion session cost to the period using per-message cost and
|
|
2850
|
+
// message timestamps, not the full session cost. This ensures "Last 24h"
|
|
2851
|
+
// only counts cost from messages sent in the last 24 hours, not the
|
|
2852
|
+
// entire lifetime of any session that was recently active.
|
|
2853
|
+
if (!cutoffDate) {
|
|
2851
2854
|
periodCost += sessionCost;
|
|
2852
|
-
} else if (
|
|
2855
|
+
} else if (samples && samples.length > 0 && costData.messageCount > 0) {
|
|
2856
|
+
const perMsgCost = sessionCost / costData.messageCount;
|
|
2857
|
+
let periodMessages = 0;
|
|
2858
|
+
for (const sample of samples) {
|
|
2859
|
+
if (sample.ts && sample.ts >= cutoffDate) periodMessages++;
|
|
2860
|
+
}
|
|
2861
|
+
periodCost += perMsgCost * periodMessages;
|
|
2862
|
+
} else if (costData.lastMessage && costData.lastMessage >= cutoffDate) {
|
|
2863
|
+
// Fallback: no timestamp samples available, use full cost
|
|
2853
2864
|
periodCost += sessionCost;
|
|
2854
2865
|
}
|
|
2855
2866
|
|