ccusage 16.2.0 → 16.2.1
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/README.md +1 -0
- package/dist/calculate-cost.d.ts +2 -2
- package/dist/{data-loader-DewcQaMm.d.ts → data-loader-D1FVB4Lp.d.ts} +7 -21
- package/dist/{data-loader-C7KK9Yu0.js → data-loader-DzuyD9Va.js} +148 -214
- package/dist/data-loader.d.ts +3 -3
- package/dist/data-loader.js +4 -4
- package/dist/{debug-BOv8jTQu.js → debug-CWK-ECNy.js} +3 -3
- package/dist/debug.js +4 -4
- package/dist/index.js +260 -377
- package/dist/{logger-DKCIi_ai.js → logger-Cl0x4-O7.js} +1 -1
- package/dist/logger.js +1 -1
- package/dist/{mcp-DDHqWuGb.js → mcp-CzT8_3kj.js} +4 -4
- package/dist/mcp.d.ts +2 -2
- package/dist/mcp.js +4 -4
- package/dist/{pricing-fetcher-BgDfBZ05.d.ts → pricing-fetcher-DK8lcI1w.d.ts} +1 -1
- package/dist/{pricing-fetcher-CoBMgxFA.js → pricing-fetcher-_ZIEzYHY.js} +3 -3
- package/dist/pricing-fetcher.d.ts +1 -1
- package/dist/pricing-fetcher.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
</div>
|
|
5
5
|
|
|
6
6
|
<p align="center">
|
|
7
|
+
<a href="https://socket.dev/api/npm/package/ccusage"><img src="https://socket.dev/api/badge/npm/package/ccusage" alt="Socket Badge" /></a>
|
|
7
8
|
<a href="https://npmjs.com/package/ccusage"><img src="https://img.shields.io/npm/v/ccusage?color=yellow" alt="npm version" /></a>
|
|
8
9
|
<a href="https://tanstack.com/stats/npm?packageGroups=%5B%7B%22packages%22:%5B%7B%22name%22:%22ccusage%22%7D%5D%7D%5D&range=30-days&transform=none&binType=daily&showDataMode=all&height=400"><img src="https://img.shields.io/npm/dy/ccusage" alt="NPM Downloads" /></a>
|
|
9
10
|
<a href="https://packagephobia.com/result?p=ccusage"><img src="https://packagephobia.com/badge?p=ccusage" alt="install size" /></a>
|
package/dist/calculate-cost.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import
|
|
1
|
+
import { DailyUsage, MonthlyUsage, SessionUsage, WeeklyUsage } from "./data-loader-D1FVB4Lp.js";
|
|
2
|
+
import "./pricing-fetcher-DK8lcI1w.js";
|
|
3
3
|
|
|
4
4
|
//#region src/_token-utils.d.ts
|
|
5
5
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Bucket, CostMode, PricingFetcher, SortOrder
|
|
1
|
+
import { Bucket, CostMode, PricingFetcher, SortOrder } from "./pricing-fetcher-DK8lcI1w.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
|
|
4
4
|
//#region src/_consts.d.ts
|
|
@@ -8,8 +8,11 @@ import { z } from "zod";
|
|
|
8
8
|
*/
|
|
9
9
|
declare const WEEK_DAYS: readonly ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"];
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
12
|
-
|
|
11
|
+
* Week day names type
|
|
12
|
+
*/
|
|
13
|
+
type WeekDay = typeof WEEK_DAYS[number];
|
|
14
|
+
/**
|
|
15
|
+
* Day of week as number (0 = Sunday, 1 = Monday, ..., 6 = Saturday)
|
|
13
16
|
*/
|
|
14
17
|
//#endregion
|
|
15
18
|
//#region src/_session-blocks.d.ts
|
|
@@ -658,22 +661,6 @@ declare const bucketUsageSchema: z.ZodObject<{
|
|
|
658
661
|
* Type definition for bucket usage aggregation
|
|
659
662
|
*/
|
|
660
663
|
type BucketUsage = z.infer<typeof bucketUsageSchema>;
|
|
661
|
-
/**
|
|
662
|
-
* Formats a date string to YYYY-MM-DD format
|
|
663
|
-
* @param dateStr - Input date string
|
|
664
|
-
* @param timezone - Optional timezone to use for formatting
|
|
665
|
-
* @param locale - Optional locale to use for formatting (defaults to 'en-CA' for YYYY-MM-DD format)
|
|
666
|
-
* @returns Formatted date string in YYYY-MM-DD format
|
|
667
|
-
*/
|
|
668
|
-
declare function formatDate(dateStr: string, timezone?: string, locale?: string): string;
|
|
669
|
-
/**
|
|
670
|
-
* Formats a date string to compact format with year on first line and month-day on second
|
|
671
|
-
* @param dateStr - Input date string
|
|
672
|
-
* @param timezone - Timezone to use for formatting (pass undefined to use system timezone)
|
|
673
|
-
* @param locale - Locale to use for formatting
|
|
674
|
-
* @returns Formatted date string with newline separator (YYYY\nMM-DD)
|
|
675
|
-
*/
|
|
676
|
-
declare function formatDateCompact(dateStr: string, timezone: string | undefined, locale: string): string;
|
|
677
664
|
/**
|
|
678
665
|
* Create a unique identifier for deduplication using message ID and request ID
|
|
679
666
|
*/
|
|
@@ -722,7 +709,6 @@ type DateFilter = {
|
|
|
722
709
|
since?: string; // YYYYMMDD format
|
|
723
710
|
until?: string; // YYYYMMDD format
|
|
724
711
|
};
|
|
725
|
-
type WeekDay = TupleToUnion<typeof WEEK_DAYS>;
|
|
726
712
|
/**
|
|
727
713
|
* Configuration options for loading usage data
|
|
728
714
|
*/
|
|
@@ -796,4 +782,4 @@ declare function calculateContextTokens(transcriptPath: string, modelId?: string
|
|
|
796
782
|
*/
|
|
797
783
|
declare function loadSessionBlockData(options?: LoadOptions): Promise<SessionBlock[]>;
|
|
798
784
|
//#endregion
|
|
799
|
-
export { BucketUsage, DailyUsage, DateFilter, GlobResult, LoadOptions, ModelBreakdown, MonthlyUsage, SessionUsage, UsageData, WeeklyUsage, bucketUsageSchema, calculateContextTokens, calculateCostForEntry, createUniqueHash, dailyUsageSchema, extractProjectFromPath,
|
|
785
|
+
export { BucketUsage, DailyUsage, DateFilter, GlobResult, LoadOptions, ModelBreakdown, MonthlyUsage, SessionUsage, UsageData, WeeklyUsage, bucketUsageSchema, calculateContextTokens, calculateCostForEntry, createUniqueHash, dailyUsageSchema, extractProjectFromPath, getClaudePaths, getEarliestTimestamp, getUsageLimitResetTime, globUsageFiles, loadBucketUsageData, loadDailyUsageData, loadMonthlyUsageData, loadSessionBlockData, loadSessionData, loadSessionUsageById, loadWeeklyUsageData, modelBreakdownSchema, monthlyUsageSchema, sessionUsageSchema, sortFilesByTimestamp, transcriptMessageSchema, transcriptUsageSchema, usageDataSchema, weeklyUsageSchema };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { CLAUDE_CONFIG_DIR_ENV, CLAUDE_PROJECTS_DIR_NAME, DEFAULT_CLAUDE_CODE_PATH, DEFAULT_CLAUDE_CONFIG_PATH, DEFAULT_RECENT_DAYS, PricingFetcher, USAGE_DATA_GLOB_PATTERN, USER_HOME_DIR, __commonJSMin, __require, __toESM, isFailure, isPromise, isSuccess, require_usingCtx } from "./pricing-fetcher-
|
|
1
|
+
import { CLAUDE_CONFIG_DIR_ENV, CLAUDE_PROJECTS_DIR_NAME, DEFAULT_CLAUDE_CODE_PATH, DEFAULT_CLAUDE_CONFIG_PATH, DEFAULT_LOCALE, DEFAULT_RECENT_DAYS, PricingFetcher, USAGE_DATA_GLOB_PATTERN, USER_HOME_DIR, __commonJSMin, __require, __toESM, isFailure, isPromise, isSuccess, map, pipe, require_usingCtx, try_ } from "./pricing-fetcher-_ZIEzYHY.js";
|
|
2
2
|
import { getTotalTokens } from "./_token-utils-WjkbrjKv.js";
|
|
3
3
|
import { activityDateSchema, arrayType, booleanType, createBucket, createDailyDate, createMonthlyDate, createProjectPath, createSessionId, createWeeklyDate, dailyDateSchema, isoTimestampSchema, messageIdSchema, modelNameSchema, monthlyDateSchema, numberType, objectType, projectPathSchema, requestIdSchema, sessionIdSchema, stringType, unionType, versionSchema, weeklyDateSchema } from "./_types-DIdtMJ6V.js";
|
|
4
|
-
import { logger } from "./logger-
|
|
5
|
-
import a, { readFile } from "node:fs/promises";
|
|
4
|
+
import { logger } from "./logger-Cl0x4-O7.js";
|
|
5
|
+
import a, { readFile, stat } from "node:fs/promises";
|
|
6
6
|
import path, { posix } from "node:path";
|
|
7
7
|
import process$1 from "node:process";
|
|
8
8
|
import b from "node:fs";
|
|
@@ -10,83 +10,7 @@ import F from "node:os";
|
|
|
10
10
|
function toArray(array) {
|
|
11
11
|
return array = array ?? [], Array.isArray(array) ? array : [array];
|
|
12
12
|
}
|
|
13
|
-
const VOID = Symbol("p-void")
|
|
14
|
-
function isString(x) {
|
|
15
|
-
return typeof x === "string";
|
|
16
|
-
}
|
|
17
|
-
function isRecord(x) {
|
|
18
|
-
return x != null && !Array.isArray(x) && typeof x === "object";
|
|
19
|
-
}
|
|
20
|
-
const defaultThreshold = 20;
|
|
21
|
-
function inspect(value, options = {}) {
|
|
22
|
-
if (value === null) return "null";
|
|
23
|
-
if (Array.isArray(value)) return inspectArray(value, options);
|
|
24
|
-
switch (typeof value) {
|
|
25
|
-
case "string": return JSON.stringify(value);
|
|
26
|
-
case "bigint": return `${value}n`;
|
|
27
|
-
case "object": return value.constructor?.name === "Object" ? inspectRecord(value, options) : value.constructor?.name;
|
|
28
|
-
case "function": return value.name || "(anonymous)";
|
|
29
|
-
}
|
|
30
|
-
return value?.toString() ?? "undefined";
|
|
31
|
-
}
|
|
32
|
-
function inspectArray(value, options) {
|
|
33
|
-
const { threshold = defaultThreshold } = options, vs = value.map((v$1) => inspect(v$1, options)), s = vs.join(", ");
|
|
34
|
-
if (s.length <= threshold) return `[${s}]`;
|
|
35
|
-
const m$1 = vs.join(",\n");
|
|
36
|
-
return `[\n${indent(2, m$1)}\n]`;
|
|
37
|
-
}
|
|
38
|
-
function inspectRecord(value, options) {
|
|
39
|
-
const { threshold = defaultThreshold } = options, vs = [...Object.keys(value), ...Object.getOwnPropertySymbols(value)].map((k$1) => `${k$1.toString()}: ${inspect(value[k$1], options)}`), s = vs.join(", ");
|
|
40
|
-
if (s.length <= threshold) return `{${s}}`;
|
|
41
|
-
const m$1 = vs.join(",\n");
|
|
42
|
-
return `{\n${indent(2, m$1)}\n}`;
|
|
43
|
-
}
|
|
44
|
-
function indent(level, text) {
|
|
45
|
-
const prefix = " ".repeat(level);
|
|
46
|
-
return text.split("\n").map((line) => `${prefix}${line}`).join("\n");
|
|
47
|
-
}
|
|
48
|
-
function rewriteName(fn, name, ...args) {
|
|
49
|
-
let cachedName;
|
|
50
|
-
return Object.defineProperties(fn, { name: { get: () => {
|
|
51
|
-
return cachedName || (cachedName = `${name}(${args.map((v$1) => inspect(v$1)).join(", ")})`, cachedName);
|
|
52
|
-
} } });
|
|
53
|
-
}
|
|
54
|
-
function annotate(fn, name, value) {
|
|
55
|
-
return Object.defineProperties(fn, { [name]: { value } });
|
|
56
|
-
}
|
|
57
|
-
function hasAnnotation(fn, name) {
|
|
58
|
-
return !!fn[name];
|
|
59
|
-
}
|
|
60
|
-
function isObjectOf(predObj) {
|
|
61
|
-
const preds = [...Object.keys(predObj), ...Object.getOwnPropertySymbols(predObj)].map((k$1) => [k$1, predObj[k$1]]), pred = rewriteName((x) => {
|
|
62
|
-
return isObject$1(x) ? preds.every(([k$1, pred$1]) => pred$1(x[k$1])) : false;
|
|
63
|
-
}, "isObjectOf", predObj);
|
|
64
|
-
return annotate(pred, "predObj", predObj);
|
|
65
|
-
}
|
|
66
|
-
function isObject$1(x) {
|
|
67
|
-
return !(x == null || typeof x !== "object" && typeof x !== "function" || Array.isArray(x));
|
|
68
|
-
}
|
|
69
|
-
function asOptional(pred) {
|
|
70
|
-
return hasAnnotation(pred, "optional") ? pred : rewriteName(annotate((x) => x === void 0 || pred(x), "optional", pred), "asOptional", pred);
|
|
71
|
-
}
|
|
72
|
-
const isErrorObject = isObjectOf({
|
|
73
|
-
proto: isString,
|
|
74
|
-
name: isString,
|
|
75
|
-
message: isString,
|
|
76
|
-
stack: asOptional(isString),
|
|
77
|
-
attributes: isRecord
|
|
78
|
-
});
|
|
79
|
-
var UnreachableError = class UnreachableError extends Error {
|
|
80
|
-
args;
|
|
81
|
-
constructor(args) {
|
|
82
|
-
if (super(`unreachable: ${args}`), Error.captureStackTrace) Error.captureStackTrace(this, UnreachableError);
|
|
83
|
-
this.name = this.constructor.name, this.args = args;
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
function unreachable(...args) {
|
|
87
|
-
throw new UnreachableError(args);
|
|
88
|
-
}
|
|
89
|
-
const isResult = (result) => "object" == typeof result && null !== result && "type" in result && ("Success" === result.type && "value" in result || "Failure" === result.type && "error" in result), unwrap = (...args) => {
|
|
13
|
+
const VOID = Symbol("p-void"), isResult = (result) => "object" == typeof result && null !== result && "type" in result && ("Success" === result.type && "value" in result || "Failure" === result.type && "error" in result), unwrap = (...args) => {
|
|
90
14
|
const firstArgument = args[0];
|
|
91
15
|
if (isResult(firstArgument) || isPromise(firstArgument)) {
|
|
92
16
|
const result = firstArgument, hasDefault$1 = 2 === args.length, defaultValue$1 = hasDefault$1 ? args[1] : void 0, apply = (r) => {
|
|
@@ -122,82 +46,7 @@ function groupBy(arr, getKeyFromItem) {
|
|
|
122
46
|
function uniq(arr) {
|
|
123
47
|
return Array.from(new Set(arr));
|
|
124
48
|
}
|
|
125
|
-
var
|
|
126
|
-
return function(a$1, b$1, order) {
|
|
127
|
-
return comparer(a$1, b$1, order) * order;
|
|
128
|
-
};
|
|
129
|
-
}, throwInvalidConfigErrorIfTrue = function(condition, context) {
|
|
130
|
-
if (condition) throw Error("Invalid sort config: " + context);
|
|
131
|
-
}, unpackObjectSorter = function(sortByObj) {
|
|
132
|
-
var _a = sortByObj || {}, asc = _a.asc, desc = _a.desc, order = asc ? 1 : -1, sortBy = asc || desc;
|
|
133
|
-
throwInvalidConfigErrorIfTrue(!sortBy, "Expected `asc` or `desc` property"), throwInvalidConfigErrorIfTrue(asc && desc, "Ambiguous object with `asc` and `desc` config properties");
|
|
134
|
-
var comparer = sortByObj.comparer && castComparer(sortByObj.comparer);
|
|
135
|
-
return {
|
|
136
|
-
order,
|
|
137
|
-
sortBy,
|
|
138
|
-
comparer
|
|
139
|
-
};
|
|
140
|
-
}, multiPropertySorterProvider = function(defaultComparer$1) {
|
|
141
|
-
return function multiPropertySorter(sortBy, sortByArr, depth$1, order, comparer, a$1, b$1) {
|
|
142
|
-
var valA, valB;
|
|
143
|
-
if (typeof sortBy === "string") valA = a$1[sortBy], valB = b$1[sortBy];
|
|
144
|
-
else if (typeof sortBy === "function") valA = sortBy(a$1), valB = sortBy(b$1);
|
|
145
|
-
else {
|
|
146
|
-
var objectSorterConfig = unpackObjectSorter(sortBy);
|
|
147
|
-
return multiPropertySorter(objectSorterConfig.sortBy, sortByArr, depth$1, objectSorterConfig.order, objectSorterConfig.comparer || defaultComparer$1, a$1, b$1);
|
|
148
|
-
}
|
|
149
|
-
var equality = comparer(valA, valB, order);
|
|
150
|
-
return (equality === 0 || valA == null && valB == null) && sortByArr.length > depth$1 ? multiPropertySorter(sortByArr[depth$1], sortByArr, depth$1 + 1, order, comparer, a$1, b$1) : equality;
|
|
151
|
-
};
|
|
152
|
-
};
|
|
153
|
-
function getSortStrategy(sortBy, comparer, order) {
|
|
154
|
-
if (sortBy === void 0 || sortBy === true) return function(a$1, b$1) {
|
|
155
|
-
return comparer(a$1, b$1, order);
|
|
156
|
-
};
|
|
157
|
-
if (typeof sortBy === "string") return throwInvalidConfigErrorIfTrue(sortBy.includes("."), "String syntax not allowed for nested properties."), function(a$1, b$1) {
|
|
158
|
-
return comparer(a$1[sortBy], b$1[sortBy], order);
|
|
159
|
-
};
|
|
160
|
-
if (typeof sortBy === "function") return function(a$1, b$1) {
|
|
161
|
-
return comparer(sortBy(a$1), sortBy(b$1), order);
|
|
162
|
-
};
|
|
163
|
-
if (Array.isArray(sortBy)) {
|
|
164
|
-
var multiPropSorter_1 = multiPropertySorterProvider(comparer);
|
|
165
|
-
return function(a$1, b$1) {
|
|
166
|
-
return multiPropSorter_1(sortBy[0], sortBy, 1, order, comparer, a$1, b$1);
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
var objectSorterConfig = unpackObjectSorter(sortBy);
|
|
170
|
-
return getSortStrategy(objectSorterConfig.sortBy, objectSorterConfig.comparer || comparer, objectSorterConfig.order);
|
|
171
|
-
}
|
|
172
|
-
var sortArray = function(order, ctx, sortBy, comparer) {
|
|
173
|
-
var _a;
|
|
174
|
-
if (!Array.isArray(ctx)) return ctx;
|
|
175
|
-
if (Array.isArray(sortBy) && sortBy.length < 2) _a = sortBy, sortBy = _a[0];
|
|
176
|
-
return ctx.sort(getSortStrategy(sortBy, comparer, order));
|
|
177
|
-
};
|
|
178
|
-
function createNewSortInstance(opts) {
|
|
179
|
-
var comparer = castComparer(opts.comparer);
|
|
180
|
-
return function(arrayToSort) {
|
|
181
|
-
var ctx = Array.isArray(arrayToSort) && !opts.inPlaceSorting ? arrayToSort.slice() : arrayToSort;
|
|
182
|
-
return {
|
|
183
|
-
asc: function(sortBy) {
|
|
184
|
-
return sortArray(1, ctx, sortBy, comparer);
|
|
185
|
-
},
|
|
186
|
-
desc: function(sortBy) {
|
|
187
|
-
return sortArray(-1, ctx, sortBy, comparer);
|
|
188
|
-
},
|
|
189
|
-
by: function(sortBy) {
|
|
190
|
-
return sortArray(1, ctx, sortBy, comparer);
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
var defaultComparer = function(a$1, b$1, order) {
|
|
196
|
-
return a$1 == null ? order : b$1 == null ? -order : typeof a$1 === typeof b$1 ? a$1 < b$1 ? -1 : a$1 > b$1 ? 1 : 0 : typeof a$1 < typeof b$1 ? -1 : 1;
|
|
197
|
-
}, sort = createNewSortInstance({ comparer: defaultComparer }), inPlaceSort = createNewSortInstance({
|
|
198
|
-
comparer: defaultComparer,
|
|
199
|
-
inPlaceSorting: true
|
|
200
|
-
}), d = Object.defineProperty, n = (s, t) => d(s, "name", {
|
|
49
|
+
var d = Object.defineProperty, n = (s, t) => d(s, "name", {
|
|
201
50
|
value: t,
|
|
202
51
|
configurable: !0
|
|
203
52
|
});
|
|
@@ -2059,6 +1908,145 @@ async function glob(patternsOrOptions, options) {
|
|
|
2059
1908
|
} : patternsOrOptions, cwd = opts.cwd ? path.resolve(opts.cwd).replace(BACKSLASHES, "/") : process.cwd().replace(BACKSLASHES, "/");
|
|
2060
1909
|
return crawl(opts, cwd, false);
|
|
2061
1910
|
}
|
|
1911
|
+
var castComparer = function(comparer) {
|
|
1912
|
+
return function(a$1, b$1, order) {
|
|
1913
|
+
return comparer(a$1, b$1, order) * order;
|
|
1914
|
+
};
|
|
1915
|
+
}, throwInvalidConfigErrorIfTrue = function(condition, context) {
|
|
1916
|
+
if (condition) throw Error("Invalid sort config: " + context);
|
|
1917
|
+
}, unpackObjectSorter = function(sortByObj) {
|
|
1918
|
+
var _a = sortByObj || {}, asc = _a.asc, desc = _a.desc, order = asc ? 1 : -1, sortBy = asc || desc;
|
|
1919
|
+
throwInvalidConfigErrorIfTrue(!sortBy, "Expected `asc` or `desc` property"), throwInvalidConfigErrorIfTrue(asc && desc, "Ambiguous object with `asc` and `desc` config properties");
|
|
1920
|
+
var comparer = sortByObj.comparer && castComparer(sortByObj.comparer);
|
|
1921
|
+
return {
|
|
1922
|
+
order,
|
|
1923
|
+
sortBy,
|
|
1924
|
+
comparer
|
|
1925
|
+
};
|
|
1926
|
+
}, multiPropertySorterProvider = function(defaultComparer$1) {
|
|
1927
|
+
return function multiPropertySorter(sortBy, sortByArr, depth$1, order, comparer, a$1, b$1) {
|
|
1928
|
+
var valA, valB;
|
|
1929
|
+
if (typeof sortBy === "string") valA = a$1[sortBy], valB = b$1[sortBy];
|
|
1930
|
+
else if (typeof sortBy === "function") valA = sortBy(a$1), valB = sortBy(b$1);
|
|
1931
|
+
else {
|
|
1932
|
+
var objectSorterConfig = unpackObjectSorter(sortBy);
|
|
1933
|
+
return multiPropertySorter(objectSorterConfig.sortBy, sortByArr, depth$1, objectSorterConfig.order, objectSorterConfig.comparer || defaultComparer$1, a$1, b$1);
|
|
1934
|
+
}
|
|
1935
|
+
var equality = comparer(valA, valB, order);
|
|
1936
|
+
return (equality === 0 || valA == null && valB == null) && sortByArr.length > depth$1 ? multiPropertySorter(sortByArr[depth$1], sortByArr, depth$1 + 1, order, comparer, a$1, b$1) : equality;
|
|
1937
|
+
};
|
|
1938
|
+
};
|
|
1939
|
+
function getSortStrategy(sortBy, comparer, order) {
|
|
1940
|
+
if (sortBy === void 0 || sortBy === true) return function(a$1, b$1) {
|
|
1941
|
+
return comparer(a$1, b$1, order);
|
|
1942
|
+
};
|
|
1943
|
+
if (typeof sortBy === "string") return throwInvalidConfigErrorIfTrue(sortBy.includes("."), "String syntax not allowed for nested properties."), function(a$1, b$1) {
|
|
1944
|
+
return comparer(a$1[sortBy], b$1[sortBy], order);
|
|
1945
|
+
};
|
|
1946
|
+
if (typeof sortBy === "function") return function(a$1, b$1) {
|
|
1947
|
+
return comparer(sortBy(a$1), sortBy(b$1), order);
|
|
1948
|
+
};
|
|
1949
|
+
if (Array.isArray(sortBy)) {
|
|
1950
|
+
var multiPropSorter_1 = multiPropertySorterProvider(comparer);
|
|
1951
|
+
return function(a$1, b$1) {
|
|
1952
|
+
return multiPropSorter_1(sortBy[0], sortBy, 1, order, comparer, a$1, b$1);
|
|
1953
|
+
};
|
|
1954
|
+
}
|
|
1955
|
+
var objectSorterConfig = unpackObjectSorter(sortBy);
|
|
1956
|
+
return getSortStrategy(objectSorterConfig.sortBy, objectSorterConfig.comparer || comparer, objectSorterConfig.order);
|
|
1957
|
+
}
|
|
1958
|
+
var sortArray = function(order, ctx, sortBy, comparer) {
|
|
1959
|
+
var _a;
|
|
1960
|
+
if (!Array.isArray(ctx)) return ctx;
|
|
1961
|
+
if (Array.isArray(sortBy) && sortBy.length < 2) _a = sortBy, sortBy = _a[0];
|
|
1962
|
+
return ctx.sort(getSortStrategy(sortBy, comparer, order));
|
|
1963
|
+
};
|
|
1964
|
+
function createNewSortInstance(opts) {
|
|
1965
|
+
var comparer = castComparer(opts.comparer);
|
|
1966
|
+
return function(arrayToSort) {
|
|
1967
|
+
var ctx = Array.isArray(arrayToSort) && !opts.inPlaceSorting ? arrayToSort.slice() : arrayToSort;
|
|
1968
|
+
return {
|
|
1969
|
+
asc: function(sortBy) {
|
|
1970
|
+
return sortArray(1, ctx, sortBy, comparer);
|
|
1971
|
+
},
|
|
1972
|
+
desc: function(sortBy) {
|
|
1973
|
+
return sortArray(-1, ctx, sortBy, comparer);
|
|
1974
|
+
},
|
|
1975
|
+
by: function(sortBy) {
|
|
1976
|
+
return sortArray(1, ctx, sortBy, comparer);
|
|
1977
|
+
}
|
|
1978
|
+
};
|
|
1979
|
+
};
|
|
1980
|
+
}
|
|
1981
|
+
var defaultComparer = function(a$1, b$1, order) {
|
|
1982
|
+
return a$1 == null ? order : b$1 == null ? -order : typeof a$1 === typeof b$1 ? a$1 < b$1 ? -1 : a$1 > b$1 ? 1 : 0 : typeof a$1 < typeof b$1 ? -1 : 1;
|
|
1983
|
+
}, sort = createNewSortInstance({ comparer: defaultComparer }), inPlaceSort = createNewSortInstance({
|
|
1984
|
+
comparer: defaultComparer,
|
|
1985
|
+
inPlaceSorting: true
|
|
1986
|
+
}), import_usingCtx$1 = /* @__PURE__ */ __toESM(require_usingCtx(), 1);
|
|
1987
|
+
function unreachable(value) {
|
|
1988
|
+
throw new Error(`Unreachable code reached with value: ${value}`);
|
|
1989
|
+
}
|
|
1990
|
+
async function getFileModifiedTime(filePath) {
|
|
1991
|
+
return pipe(try_({
|
|
1992
|
+
try: stat(filePath),
|
|
1993
|
+
catch: (error) => error
|
|
1994
|
+
}), map((stats) => stats.mtime.getTime()), unwrap(0));
|
|
1995
|
+
}
|
|
1996
|
+
function createDateFormatter(timezone, locale) {
|
|
1997
|
+
return new Intl.DateTimeFormat(locale, {
|
|
1998
|
+
year: "numeric",
|
|
1999
|
+
month: "2-digit",
|
|
2000
|
+
day: "2-digit",
|
|
2001
|
+
timeZone: timezone
|
|
2002
|
+
});
|
|
2003
|
+
}
|
|
2004
|
+
function createDatePartsFormatter(timezone, locale) {
|
|
2005
|
+
return new Intl.DateTimeFormat(locale, {
|
|
2006
|
+
year: "numeric",
|
|
2007
|
+
month: "2-digit",
|
|
2008
|
+
day: "2-digit",
|
|
2009
|
+
timeZone: timezone
|
|
2010
|
+
});
|
|
2011
|
+
}
|
|
2012
|
+
function formatDate(dateStr, timezone, locale) {
|
|
2013
|
+
const date = new Date(dateStr), formatter = createDateFormatter(timezone, locale ?? DEFAULT_LOCALE);
|
|
2014
|
+
return formatter.format(date);
|
|
2015
|
+
}
|
|
2016
|
+
function formatDateCompact(dateStr, timezone, locale) {
|
|
2017
|
+
const parseResult = dailyDateSchema.safeParse(dateStr), date = parseResult.success ? timezone != null ? /* @__PURE__ */ new Date(`${dateStr}T00:00:00Z`) : /* @__PURE__ */ new Date(`${dateStr}T00:00:00`) : new Date(dateStr), formatter = createDatePartsFormatter(timezone, locale), parts = formatter.formatToParts(date), year = parts.find((p) => p.type === "year")?.value ?? "", month = parts.find((p) => p.type === "month")?.value ?? "", day = parts.find((p) => p.type === "day")?.value ?? "";
|
|
2018
|
+
return `${year}\n${month}-${day}`;
|
|
2019
|
+
}
|
|
2020
|
+
function sortByDate(items, getDate, order = "desc") {
|
|
2021
|
+
const sorted = sort(items);
|
|
2022
|
+
switch (order) {
|
|
2023
|
+
case "desc": return sorted.desc((item) => new Date(getDate(item)).getTime());
|
|
2024
|
+
case "asc": return sorted.asc((item) => new Date(getDate(item)).getTime());
|
|
2025
|
+
default: unreachable(order);
|
|
2026
|
+
}
|
|
2027
|
+
}
|
|
2028
|
+
function filterByDateRange(items, getDate, since, until) {
|
|
2029
|
+
return since == null && until == null ? items : items.filter((item) => {
|
|
2030
|
+
const dateStr = getDate(item).substring(0, 10).replace(/-/g, "");
|
|
2031
|
+
return !(since != null && dateStr < since || until != null && dateStr > until);
|
|
2032
|
+
});
|
|
2033
|
+
}
|
|
2034
|
+
function getDateWeek(date, startDay) {
|
|
2035
|
+
const d$1 = new Date(date), day = d$1.getDay(), shift = (day - startDay + 7) % 7;
|
|
2036
|
+
return d$1.setDate(d$1.getDate() - shift), createWeeklyDate(d$1.toISOString().substring(0, 10));
|
|
2037
|
+
}
|
|
2038
|
+
function getDayNumber(day) {
|
|
2039
|
+
const dayMap = {
|
|
2040
|
+
sunday: 0,
|
|
2041
|
+
monday: 1,
|
|
2042
|
+
tuesday: 2,
|
|
2043
|
+
wednesday: 3,
|
|
2044
|
+
thursday: 4,
|
|
2045
|
+
friday: 5,
|
|
2046
|
+
saturday: 6
|
|
2047
|
+
};
|
|
2048
|
+
return dayMap[day];
|
|
2049
|
+
}
|
|
2062
2050
|
const DEFAULT_SESSION_DURATION_HOURS = 5;
|
|
2063
2051
|
function floorToHour(timestamp) {
|
|
2064
2052
|
const floored = new Date(timestamp);
|
|
@@ -2363,12 +2351,6 @@ function calculateTotals(entries, getUsage, getCost) {
|
|
|
2363
2351
|
totalCost: 0
|
|
2364
2352
|
});
|
|
2365
2353
|
}
|
|
2366
|
-
function filterByDateRange(items, getDate, since, until) {
|
|
2367
|
-
return since == null && until == null ? items : items.filter((item) => {
|
|
2368
|
-
const dateStr = getDate(item).substring(0, 10).replace(/-/g, "");
|
|
2369
|
-
return !(since != null && dateStr < since || until != null && dateStr > until);
|
|
2370
|
-
});
|
|
2371
|
-
}
|
|
2372
2354
|
function filterByProject(items, getProject, projectFilter) {
|
|
2373
2355
|
return projectFilter == null ? items : items.filter((item) => {
|
|
2374
2356
|
const projectName = getProject(item);
|
|
@@ -2384,38 +2366,6 @@ function markAsProcessed(uniqueHash, processedHashes) {
|
|
|
2384
2366
|
function extractUniqueModels(entries, getModel) {
|
|
2385
2367
|
return uniq(entries.map(getModel).filter((m$1) => m$1 != null && m$1 !== "<synthetic>"));
|
|
2386
2368
|
}
|
|
2387
|
-
function createDateFormatter(timezone, locale) {
|
|
2388
|
-
return new Intl.DateTimeFormat(locale, {
|
|
2389
|
-
year: "numeric",
|
|
2390
|
-
month: "2-digit",
|
|
2391
|
-
day: "2-digit",
|
|
2392
|
-
timeZone: timezone
|
|
2393
|
-
});
|
|
2394
|
-
}
|
|
2395
|
-
function createDatePartsFormatter(timezone, locale) {
|
|
2396
|
-
return new Intl.DateTimeFormat(locale, {
|
|
2397
|
-
year: "numeric",
|
|
2398
|
-
month: "2-digit",
|
|
2399
|
-
day: "2-digit",
|
|
2400
|
-
timeZone: timezone
|
|
2401
|
-
});
|
|
2402
|
-
}
|
|
2403
|
-
function formatDate(dateStr, timezone, locale) {
|
|
2404
|
-
const date = new Date(dateStr), formatter = createDateFormatter(timezone, locale ?? "en-CA");
|
|
2405
|
-
return formatter.format(date);
|
|
2406
|
-
}
|
|
2407
|
-
function formatDateCompact(dateStr, timezone, locale) {
|
|
2408
|
-
const parseResult = dailyDateSchema.safeParse(dateStr), date = parseResult.success ? timezone != null ? /* @__PURE__ */ new Date(`${dateStr}T00:00:00Z`) : /* @__PURE__ */ new Date(`${dateStr}T00:00:00`) : new Date(dateStr), formatter = createDatePartsFormatter(timezone, locale), parts = formatter.formatToParts(date), year = parts.find((p) => p.type === "year")?.value ?? "", month = parts.find((p) => p.type === "month")?.value ?? "", day = parts.find((p) => p.type === "day")?.value ?? "";
|
|
2409
|
-
return `${year}\n${month}-${day}`;
|
|
2410
|
-
}
|
|
2411
|
-
function sortByDate(items, getDate, order = "desc") {
|
|
2412
|
-
const sorted = sort(items);
|
|
2413
|
-
switch (order) {
|
|
2414
|
-
case "desc": return sorted.desc((item) => new Date(getDate(item)).getTime());
|
|
2415
|
-
case "asc": return sorted.asc((item) => new Date(getDate(item)).getTime());
|
|
2416
|
-
default: unreachable(order);
|
|
2417
|
-
}
|
|
2418
|
-
}
|
|
2419
2369
|
function createUniqueHash(data) {
|
|
2420
2370
|
const messageId = data.message.id, requestId = data.requestId;
|
|
2421
2371
|
return messageId == null || requestId == null ? null : `${messageId}:${requestId}`;
|
|
@@ -2496,7 +2446,7 @@ async function loadDailyUsageData(options) {
|
|
|
2496
2446
|
const data = result.data, uniqueHash = createUniqueHash(data);
|
|
2497
2447
|
if (isDuplicateEntry(uniqueHash, processedHashes)) continue;
|
|
2498
2448
|
markAsProcessed(uniqueHash, processedHashes);
|
|
2499
|
-
const date = formatDate(data.timestamp, options?.timezone,
|
|
2449
|
+
const date = formatDate(data.timestamp, options?.timezone, DEFAULT_LOCALE), cost = fetcher != null ? await calculateCostForEntry(data, mode, fetcher) : data.costUSD ?? 0, project = extractProjectFromPath(file);
|
|
2500
2450
|
allEntries.push({
|
|
2501
2451
|
data,
|
|
2502
2452
|
date,
|
|
@@ -2562,7 +2512,7 @@ async function loadSessionData(options) {
|
|
|
2562
2512
|
sessionId: createSessionId(latestEntry.sessionId),
|
|
2563
2513
|
projectPath: createProjectPath(latestEntry.projectPath),
|
|
2564
2514
|
...totals,
|
|
2565
|
-
lastActivity: formatDate(latestEntry.timestamp, options?.timezone,
|
|
2515
|
+
lastActivity: formatDate(latestEntry.timestamp, options?.timezone, DEFAULT_LOCALE),
|
|
2566
2516
|
versions: uniq(versions).sort(),
|
|
2567
2517
|
modelsUsed,
|
|
2568
2518
|
modelBreakdowns
|
|
@@ -2581,22 +2531,6 @@ async function loadMonthlyUsageData(options) {
|
|
|
2581
2531
|
...rest
|
|
2582
2532
|
})));
|
|
2583
2533
|
}
|
|
2584
|
-
function getDateWeek(date, startDay) {
|
|
2585
|
-
const d$1 = new Date(date), day = d$1.getDay(), shift = (day - startDay + 7) % 7;
|
|
2586
|
-
return d$1.setDate(d$1.getDate() - shift), createWeeklyDate(d$1.toISOString().substring(0, 10));
|
|
2587
|
-
}
|
|
2588
|
-
function getDayNumber(day) {
|
|
2589
|
-
const dayMap = {
|
|
2590
|
-
sunday: 0,
|
|
2591
|
-
monday: 1,
|
|
2592
|
-
tuesday: 2,
|
|
2593
|
-
wednesday: 3,
|
|
2594
|
-
thursday: 4,
|
|
2595
|
-
friday: 5,
|
|
2596
|
-
saturday: 6
|
|
2597
|
-
};
|
|
2598
|
-
return dayMap[day];
|
|
2599
|
-
}
|
|
2600
2534
|
async function loadWeeklyUsageData(options) {
|
|
2601
2535
|
const startDay = options?.startOfWeek != null ? getDayNumber(options.startOfWeek) : getDayNumber("sunday");
|
|
2602
2536
|
return loadBucketUsageData((data) => getDateWeek(new Date(data.date), startDay), options).then((usages) => usages.map(({ bucket,...rest }) => ({
|
|
@@ -2734,7 +2668,7 @@ async function loadSessionBlockData(options) {
|
|
|
2734
2668
|
}
|
|
2735
2669
|
}
|
|
2736
2670
|
const blocks = identifySessionBlocks(allEntries, options?.sessionDurationHours), dateFiltered = options?.since != null && options.since !== "" || options?.until != null && options.until !== "" ? blocks.filter((block) => {
|
|
2737
|
-
const blockDateStr = formatDate(block.startTime.toISOString(), options?.timezone,
|
|
2671
|
+
const blockDateStr = formatDate(block.startTime.toISOString(), options?.timezone, DEFAULT_LOCALE).replace(/-/g, "");
|
|
2738
2672
|
return !(options.since != null && options.since !== "" && blockDateStr < options.since || options.until != null && options.until !== "" && blockDateStr > options.until);
|
|
2739
2673
|
}) : blocks;
|
|
2740
2674
|
return sortByDate(dateFiltered, (block) => block.startTime, options?.order);
|
|
@@ -2744,4 +2678,4 @@ async function loadSessionBlockData(options) {
|
|
|
2744
2678
|
_usingCtx6.d();
|
|
2745
2679
|
}
|
|
2746
2680
|
}
|
|
2747
|
-
export { DEFAULT_SESSION_DURATION_HOURS, bucketUsageSchema, calculateBurnRate, calculateContextTokens, calculateCostForEntry, createUniqueHash, dailyUsageSchema, extractProjectFromPath, filterRecentBlocks,
|
|
2681
|
+
export { DEFAULT_SESSION_DURATION_HOURS, bucketUsageSchema, calculateBurnRate, calculateContextTokens, calculateCostForEntry, createUniqueHash, dailyUsageSchema, extractProjectFromPath, filterRecentBlocks, formatDateCompact, getClaudePaths, getEarliestTimestamp, getFileModifiedTime, getUsageLimitResetTime, glob, globUsageFiles, identifySessionBlocks, loadBucketUsageData, loadDailyUsageData, loadMonthlyUsageData, loadSessionBlockData, loadSessionData, loadSessionUsageById, loadWeeklyUsageData, modelBreakdownSchema, monthlyUsageSchema, projectBlockUsage, sessionUsageSchema, sortFilesByTimestamp, toArray, transcriptMessageSchema, transcriptUsageSchema, uniq, unreachable, unwrap, usageDataSchema, weeklyUsageSchema };
|
package/dist/data-loader.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import
|
|
3
|
-
export { BucketUsage, DailyUsage, DateFilter, GlobResult, LoadOptions, ModelBreakdown, MonthlyUsage, SessionUsage, UsageData, WeeklyUsage, bucketUsageSchema, calculateContextTokens, calculateCostForEntry, createUniqueHash, dailyUsageSchema, extractProjectFromPath,
|
|
1
|
+
import { BucketUsage, DailyUsage, DateFilter, GlobResult, LoadOptions, ModelBreakdown, MonthlyUsage, SessionUsage, UsageData, WeeklyUsage, bucketUsageSchema, calculateContextTokens, calculateCostForEntry, createUniqueHash, dailyUsageSchema, extractProjectFromPath, getClaudePaths, getEarliestTimestamp, getUsageLimitResetTime, globUsageFiles, loadBucketUsageData, loadDailyUsageData, loadMonthlyUsageData, loadSessionBlockData, loadSessionData, loadSessionUsageById, loadWeeklyUsageData, modelBreakdownSchema, monthlyUsageSchema, sessionUsageSchema, sortFilesByTimestamp, transcriptMessageSchema, transcriptUsageSchema, usageDataSchema, weeklyUsageSchema } from "./data-loader-D1FVB4Lp.js";
|
|
2
|
+
import "./pricing-fetcher-DK8lcI1w.js";
|
|
3
|
+
export { BucketUsage, DailyUsage, DateFilter, GlobResult, LoadOptions, ModelBreakdown, MonthlyUsage, SessionUsage, UsageData, WeeklyUsage, bucketUsageSchema, calculateContextTokens, calculateCostForEntry, createUniqueHash, dailyUsageSchema, extractProjectFromPath, getClaudePaths, getEarliestTimestamp, getUsageLimitResetTime, globUsageFiles, loadBucketUsageData, loadDailyUsageData, loadMonthlyUsageData, loadSessionBlockData, loadSessionData, loadSessionUsageById, loadWeeklyUsageData, modelBreakdownSchema, monthlyUsageSchema, sessionUsageSchema, sortFilesByTimestamp, transcriptMessageSchema, transcriptUsageSchema, usageDataSchema, weeklyUsageSchema };
|
package/dist/data-loader.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "./pricing-fetcher-
|
|
1
|
+
import "./pricing-fetcher-_ZIEzYHY.js";
|
|
2
2
|
import "./_token-utils-WjkbrjKv.js";
|
|
3
3
|
import "./_types-DIdtMJ6V.js";
|
|
4
|
-
import { bucketUsageSchema, calculateContextTokens, calculateCostForEntry, createUniqueHash, dailyUsageSchema, extractProjectFromPath,
|
|
5
|
-
import "./logger-
|
|
6
|
-
export { bucketUsageSchema, calculateContextTokens, calculateCostForEntry, createUniqueHash, dailyUsageSchema, extractProjectFromPath,
|
|
4
|
+
import { bucketUsageSchema, calculateContextTokens, calculateCostForEntry, createUniqueHash, dailyUsageSchema, extractProjectFromPath, getClaudePaths, getEarliestTimestamp, getUsageLimitResetTime, globUsageFiles, loadBucketUsageData, loadDailyUsageData, loadMonthlyUsageData, loadSessionBlockData, loadSessionData, loadSessionUsageById, loadWeeklyUsageData, modelBreakdownSchema, monthlyUsageSchema, sessionUsageSchema, sortFilesByTimestamp, transcriptMessageSchema, transcriptUsageSchema, usageDataSchema, weeklyUsageSchema } from "./data-loader-DzuyD9Va.js";
|
|
5
|
+
import "./logger-Cl0x4-O7.js";
|
|
6
|
+
export { bucketUsageSchema, calculateContextTokens, calculateCostForEntry, createUniqueHash, dailyUsageSchema, extractProjectFromPath, getClaudePaths, getEarliestTimestamp, getUsageLimitResetTime, globUsageFiles, loadBucketUsageData, loadDailyUsageData, loadMonthlyUsageData, loadSessionBlockData, loadSessionData, loadSessionUsageById, loadWeeklyUsageData, modelBreakdownSchema, monthlyUsageSchema, sessionUsageSchema, sortFilesByTimestamp, transcriptMessageSchema, transcriptUsageSchema, usageDataSchema, weeklyUsageSchema };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { CLAUDE_PROJECTS_DIR_NAME, DEBUG_MATCH_THRESHOLD_PERCENT, PricingFetcher, USAGE_DATA_GLOB_PATTERN, __toESM, isFailure, require_usingCtx, try_ } from "./pricing-fetcher-
|
|
2
|
-
import { getClaudePaths, glob, unwrap, usageDataSchema } from "./data-loader-
|
|
3
|
-
import { logger } from "./logger-
|
|
1
|
+
import { CLAUDE_PROJECTS_DIR_NAME, DEBUG_MATCH_THRESHOLD_PERCENT, PricingFetcher, USAGE_DATA_GLOB_PATTERN, __toESM, isFailure, require_usingCtx, try_ } from "./pricing-fetcher-_ZIEzYHY.js";
|
|
2
|
+
import { getClaudePaths, glob, unwrap, usageDataSchema } from "./data-loader-DzuyD9Va.js";
|
|
3
|
+
import { logger } from "./logger-Cl0x4-O7.js";
|
|
4
4
|
import { readFile } from "node:fs/promises";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
var import_usingCtx = /* @__PURE__ */ __toESM(require_usingCtx(), 1);
|
package/dist/debug.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import "./pricing-fetcher-
|
|
1
|
+
import "./pricing-fetcher-_ZIEzYHY.js";
|
|
2
2
|
import "./_token-utils-WjkbrjKv.js";
|
|
3
3
|
import "./_types-DIdtMJ6V.js";
|
|
4
|
-
import "./data-loader-
|
|
5
|
-
import "./logger-
|
|
6
|
-
import { detectMismatches, printMismatchReport } from "./debug-
|
|
4
|
+
import "./data-loader-DzuyD9Va.js";
|
|
5
|
+
import "./logger-Cl0x4-O7.js";
|
|
6
|
+
import { detectMismatches, printMismatchReport } from "./debug-CWK-ECNy.js";
|
|
7
7
|
export { detectMismatches, printMismatchReport };
|