claude-usage-dashboard 1.5.7 → 1.5.9
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/public/js/app.js +6 -2
- package/server/routes/api.js +23 -1
package/package.json
CHANGED
package/public/js/app.js
CHANGED
|
@@ -74,9 +74,13 @@ async function loadQuota() {
|
|
|
74
74
|
if (window && sevenDay.utilization > 0) {
|
|
75
75
|
quotaWindowFrom = window.from;
|
|
76
76
|
quotaWindowTo = window.to;
|
|
77
|
+
// Use local date-only format (YYYY-MM-DD) to match the date picker's
|
|
78
|
+
// filtering — filterByDateRange treats date-only strings as local
|
|
79
|
+
// midnight boundaries, ensuring consistent results across all views.
|
|
80
|
+
const fmtD = d => `${d.getFullYear()}-${String(d.getMonth()+1).padStart(2,'0')}-${String(d.getDate()).padStart(2,'0')}`;
|
|
77
81
|
const cost7d = await fetchCost({
|
|
78
|
-
from: window.from
|
|
79
|
-
to: window.to
|
|
82
|
+
from: fmtD(window.from),
|
|
83
|
+
to: fmtD(window.to),
|
|
80
84
|
plan: state.plan.plan,
|
|
81
85
|
});
|
|
82
86
|
cost7dValue = cost7d.api_equivalent_cost_usd;
|
package/server/routes/api.js
CHANGED
|
@@ -6,7 +6,7 @@ import { filterByDateRange, autoGranularity, aggregateByTime, aggregateBySession
|
|
|
6
6
|
import { calculateRecordCost, PLAN_DEFAULTS } from '../pricing.js';
|
|
7
7
|
import { createQuotaFetcher } from '../quota.js';
|
|
8
8
|
import { getSubscriptionInfo } from '../credentials.js';
|
|
9
|
-
import { updateQuotaCycleSnapshot, loadQuotaCycles } from '../quota-cycles.js';
|
|
9
|
+
import { updateQuotaCycleSnapshot, loadQuotaCycles, computeCycleData } from '../quota-cycles.js';
|
|
10
10
|
|
|
11
11
|
export function createApiRouter(logBaseDir, options = {}) {
|
|
12
12
|
const router = Router();
|
|
@@ -146,6 +146,28 @@ export function createApiRouter(logBaseDir, options = {}) {
|
|
|
146
146
|
options.snapshotDir
|
|
147
147
|
);
|
|
148
148
|
if (data.currentCycle) {
|
|
149
|
+
// Recompute current cycle from parsed records — in sync mode this
|
|
150
|
+
// includes all machines' data, matching /api/cost and /api/usage.
|
|
151
|
+
// The snapshot's utilization % (from the quota API) is preserved.
|
|
152
|
+
// Convert UTC cycle dates to local date-only strings (YYYY-MM-DD) so
|
|
153
|
+
// filterByDateRange uses local midnight boundaries, matching the date
|
|
154
|
+
// picker's range that drives the summary cards and /api/cost.
|
|
155
|
+
const toLocalDate = (iso) => {
|
|
156
|
+
const d = new Date(iso);
|
|
157
|
+
return `${d.getFullYear()}-${String(d.getMonth()+1).padStart(2,'0')}-${String(d.getDate()).padStart(2,'0')}`;
|
|
158
|
+
};
|
|
159
|
+
const records = refreshRecords();
|
|
160
|
+
const cycleRecords = filterByDateRange(
|
|
161
|
+
records, toLocalDate(data.currentCycle.start), toLocalDate(data.currentCycle.resets_at)
|
|
162
|
+
);
|
|
163
|
+
const quotaShim = {
|
|
164
|
+
seven_day: { utilization: data.currentCycle.overall.utilization },
|
|
165
|
+
seven_day_opus: { utilization: data.currentCycle.models?.opus?.utilization || 0 },
|
|
166
|
+
seven_day_sonnet: { utilization: data.currentCycle.models?.sonnet?.utilization || 0 },
|
|
167
|
+
};
|
|
168
|
+
const fresh = computeCycleData(cycleRecords, quotaShim);
|
|
169
|
+
Object.assign(data.currentCycle, fresh);
|
|
170
|
+
|
|
149
171
|
const start = new Date(data.currentCycle.start);
|
|
150
172
|
const now = new Date();
|
|
151
173
|
data.currentCycle.daysElapsed = Math.round(((now - start) / (1000 * 60 * 60 * 24)) * 10) / 10;
|