ccusage 11.0.2 → 12.1.0
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/dist/calculate-cost.d.ts +2 -2
- package/dist/{data-loader-B2EwZ_7B.js → data-loader-Bw3RIMwp.js} +81 -82
- package/dist/data-loader-CBwn9vk0.d.ts +464 -0
- package/dist/data-loader.d.ts +2 -2
- package/dist/data-loader.js +3 -4
- package/dist/{debug-D4Ka6IrY.js → debug-pK9in0EG.js} +5 -6
- package/dist/debug.js +4 -5
- package/dist/index.js +396 -19
- package/dist/{logger-DPEwxrOW.js → logger-D_tmxNpg.js} +2 -2
- package/dist/logger.js +1 -1
- package/dist/mcp-DysXlvnH.js +20322 -0
- package/dist/mcp.d.ts +30 -6
- package/dist/mcp.js +5 -8
- package/dist/pricing-fetcher-BkOpRIdx.d.ts +188 -0
- package/dist/{types-5-VF7WcO.js → pricing-fetcher-D-PICoFg.js} +341 -1
- package/dist/pricing-fetcher.d.ts +1 -1
- package/dist/pricing-fetcher.js +2 -3
- package/package.json +1 -1
- package/dist/arktype-C-GObzDh-Bx7Fdrqj.js +0 -2
- package/dist/core-eFvU0K4V.js +0 -689
- package/dist/data-loader-dbZm5kOW.d.ts +0 -247
- package/dist/dist-Cb1UHXV5.js +0 -465
- package/dist/dist-DCvt9hEv.js +0 -380
- package/dist/effect-WSjEuzC9-CZCpOgOT.js +0 -6
- package/dist/esm-D74K9ESq.js +0 -981
- package/dist/index-CISmcbXk-DpuCarFe.js +0 -20
- package/dist/mcp-CklIto13.js +0 -37030
- package/dist/pricing-fetcher-DDs53oR8.js +0 -342
- package/dist/pricing-fetcher-DHaTs-k2.d.ts +0 -1737
- package/dist/sury-DmrZ3_Oj-Lq7x0IZW.js +0 -6
- package/dist/valibot-CQk-M5rL-btpzU8Qa.js +0 -6
- package/dist/zod-Db63SLXj-BqWqpKnQ.js +0 -26
- /package/dist/{prompt-CUbwSrjo.js → prompt-E8j7mEMw.js} +0 -0
package/dist/calculate-cost.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "./pricing-fetcher-
|
|
2
|
-
import { DailyUsage, MonthlyUsage, SessionUsage } from "./data-loader-
|
|
1
|
+
import "./pricing-fetcher-BkOpRIdx.js";
|
|
2
|
+
import { DailyUsage, MonthlyUsage, SessionUsage } from "./data-loader-CBwn9vk0.js";
|
|
3
3
|
|
|
4
4
|
//#region src/calculate-cost.d.ts
|
|
5
5
|
/**
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { PricingFetcher, __commonJSMin, __require, __toESM, require_usingCtx } from "./pricing-fetcher-
|
|
2
|
-
import {
|
|
3
|
-
import { logger } from "./logger-DPEwxrOW.js";
|
|
1
|
+
import { PricingFetcher, __commonJSMin, __require, __toESM, arrayType, numberType, objectType, require_usingCtx, stringType } from "./pricing-fetcher-D-PICoFg.js";
|
|
2
|
+
import { logger } from "./logger-D_tmxNpg.js";
|
|
4
3
|
import a, { readFile } from "node:fs/promises";
|
|
5
4
|
import F, { homedir } from "node:os";
|
|
6
5
|
import path from "node:path";
|
|
@@ -2411,9 +2410,9 @@ var require_picomatch$1 = __commonJSMin((exports, module) => {
|
|
|
2411
2410
|
if (glob$1 === "" || typeof glob$1 !== "string" && !isState) throw new TypeError("Expected pattern to be a non-empty string");
|
|
2412
2411
|
const opts = options || {};
|
|
2413
2412
|
const posix$1 = opts.windows;
|
|
2414
|
-
const regex
|
|
2415
|
-
const state = regex
|
|
2416
|
-
delete regex
|
|
2413
|
+
const regex = isState ? picomatch$2.compileRe(glob$1, options) : picomatch$2.makeRe(glob$1, options, false, true);
|
|
2414
|
+
const state = regex.state;
|
|
2415
|
+
delete regex.state;
|
|
2417
2416
|
let isIgnored = () => false;
|
|
2418
2417
|
if (opts.ignore) {
|
|
2419
2418
|
const ignoreOpts = {
|
|
@@ -2425,14 +2424,14 @@ var require_picomatch$1 = __commonJSMin((exports, module) => {
|
|
|
2425
2424
|
isIgnored = picomatch$2(opts.ignore, ignoreOpts, returnState);
|
|
2426
2425
|
}
|
|
2427
2426
|
const matcher = (input, returnObject = false) => {
|
|
2428
|
-
const { isMatch, match, output } = picomatch$2.test(input, regex
|
|
2427
|
+
const { isMatch, match, output } = picomatch$2.test(input, regex, options, {
|
|
2429
2428
|
glob: glob$1,
|
|
2430
2429
|
posix: posix$1
|
|
2431
2430
|
});
|
|
2432
2431
|
const result = {
|
|
2433
2432
|
glob: glob$1,
|
|
2434
2433
|
state,
|
|
2435
|
-
regex
|
|
2434
|
+
regex,
|
|
2436
2435
|
posix: posix$1,
|
|
2437
2436
|
input,
|
|
2438
2437
|
output,
|
|
@@ -2471,7 +2470,7 @@ var require_picomatch$1 = __commonJSMin((exports, module) => {
|
|
|
2471
2470
|
* @return {Object} Returns an object with matching info.
|
|
2472
2471
|
* @api public
|
|
2473
2472
|
*/
|
|
2474
|
-
picomatch$2.test = (input, regex
|
|
2473
|
+
picomatch$2.test = (input, regex, options, { glob: glob$1, posix: posix$1 } = {}) => {
|
|
2475
2474
|
if (typeof input !== "string") throw new TypeError("Expected input to be a string");
|
|
2476
2475
|
if (input === "") return {
|
|
2477
2476
|
isMatch: false,
|
|
@@ -2485,8 +2484,8 @@ var require_picomatch$1 = __commonJSMin((exports, module) => {
|
|
|
2485
2484
|
output = format ? format(input) : input;
|
|
2486
2485
|
match = output === glob$1;
|
|
2487
2486
|
}
|
|
2488
|
-
if (match === false || opts.capture === true) if (opts.matchBase === true || opts.basename === true) match = picomatch$2.matchBase(input, regex
|
|
2489
|
-
else match = regex
|
|
2487
|
+
if (match === false || opts.capture === true) if (opts.matchBase === true || opts.basename === true) match = picomatch$2.matchBase(input, regex, options, posix$1);
|
|
2488
|
+
else match = regex.exec(output);
|
|
2490
2489
|
return {
|
|
2491
2490
|
isMatch: Boolean(match),
|
|
2492
2491
|
match,
|
|
@@ -2507,8 +2506,8 @@ var require_picomatch$1 = __commonJSMin((exports, module) => {
|
|
|
2507
2506
|
* @api public
|
|
2508
2507
|
*/
|
|
2509
2508
|
picomatch$2.matchBase = (input, glob$1, options) => {
|
|
2510
|
-
const regex
|
|
2511
|
-
return regex
|
|
2509
|
+
const regex = glob$1 instanceof RegExp ? glob$1 : picomatch$2.makeRe(glob$1, options);
|
|
2510
|
+
return regex.test(utils$1.basename(input));
|
|
2512
2511
|
};
|
|
2513
2512
|
/**
|
|
2514
2513
|
* Returns true if **any** of the given glob `patterns` match the specified `string`.
|
|
@@ -2592,9 +2591,9 @@ var require_picomatch$1 = __commonJSMin((exports, module) => {
|
|
|
2592
2591
|
const append = opts.contains ? "" : "$";
|
|
2593
2592
|
let source = `${prepend}(?:${state.output})${append}`;
|
|
2594
2593
|
if (state && state.negated === true) source = `^(?!${source}).*$`;
|
|
2595
|
-
const regex
|
|
2596
|
-
if (returnState === true) regex
|
|
2597
|
-
return regex
|
|
2594
|
+
const regex = picomatch$2.toRegex(source, options);
|
|
2595
|
+
if (returnState === true) regex.state = state;
|
|
2596
|
+
return regex;
|
|
2598
2597
|
};
|
|
2599
2598
|
/**
|
|
2600
2599
|
* Create a regular expression from a parsed glob pattern.
|
|
@@ -2810,7 +2809,7 @@ var require_builder = __commonJSMin((exports) => {
|
|
|
2810
2809
|
var require_types = __commonJSMin((exports) => {
|
|
2811
2810
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2812
2811
|
});
|
|
2813
|
-
var require_dist
|
|
2812
|
+
var require_dist = __commonJSMin((exports) => {
|
|
2814
2813
|
var __createBinding = Object.create ? function(o, m$1, k$1, k2) {
|
|
2815
2814
|
if (k2 === void 0) k2 = k$1;
|
|
2816
2815
|
var desc = Object.getOwnPropertyDescriptor(m$1, k$1);
|
|
@@ -2839,7 +2838,7 @@ var require_dist$1 = __commonJSMin((exports) => {
|
|
|
2839
2838
|
});
|
|
2840
2839
|
__exportStar(require_types(), exports);
|
|
2841
2840
|
});
|
|
2842
|
-
var import_dist = __toESM(require_dist
|
|
2841
|
+
var import_dist = __toESM(require_dist(), 1);
|
|
2843
2842
|
var import_picomatch = __toESM(require_picomatch(), 1);
|
|
2844
2843
|
const ONLY_PARENT_DIRECTORIES = /^(\/?\.\.)+$/;
|
|
2845
2844
|
function getPartialMatcher(patterns, options) {
|
|
@@ -2859,14 +2858,14 @@ function getPartialMatcher(patterns, options) {
|
|
|
2859
2858
|
if (inputParts[0] === ".." && ONLY_PARENT_DIRECTORIES.test(input)) return true;
|
|
2860
2859
|
for (let i = 0; i < patterns.length; i++) {
|
|
2861
2860
|
const patternParts = patternsParts[i];
|
|
2862
|
-
const regex
|
|
2861
|
+
const regex = regexes[i];
|
|
2863
2862
|
const inputPatternCount = inputParts.length;
|
|
2864
2863
|
const minParts = Math.min(inputPatternCount, patternParts.length);
|
|
2865
2864
|
let j$1 = 0;
|
|
2866
2865
|
while (j$1 < minParts) {
|
|
2867
2866
|
const part = patternParts[j$1];
|
|
2868
2867
|
if (part.includes("/")) return true;
|
|
2869
|
-
const match = regex
|
|
2868
|
+
const match = regex[j$1].test(inputParts[j$1]);
|
|
2870
2869
|
if (!match) break;
|
|
2871
2870
|
if (part === "**") return true;
|
|
2872
2871
|
j$1++;
|
|
@@ -3131,7 +3130,7 @@ function createBlock(startTime, entries, now, sessionDurationMs) {
|
|
|
3131
3130
|
tokenCounts.outputTokens += entry.usage.outputTokens;
|
|
3132
3131
|
tokenCounts.cacheCreationInputTokens += entry.usage.cacheCreationInputTokens;
|
|
3133
3132
|
tokenCounts.cacheReadInputTokens += entry.usage.cacheReadInputTokens;
|
|
3134
|
-
costUSD += entry.costUSD
|
|
3133
|
+
costUSD += entry.costUSD ?? 0;
|
|
3135
3134
|
modelsSet.add(entry.model);
|
|
3136
3135
|
}
|
|
3137
3136
|
return {
|
|
@@ -3255,76 +3254,76 @@ Please set CLAUDE_CONFIG_DIR to a valid path, or ensure ${DEFAULT_CLAUDE_CODE_PA
|
|
|
3255
3254
|
return envClaudeCodePath;
|
|
3256
3255
|
}
|
|
3257
3256
|
/**
|
|
3258
|
-
*
|
|
3257
|
+
* Zod schema for validating Claude usage data from JSONL files
|
|
3259
3258
|
*/
|
|
3260
|
-
const usageDataSchema =
|
|
3261
|
-
timestamp:
|
|
3262
|
-
version: optional(
|
|
3263
|
-
message:
|
|
3264
|
-
usage:
|
|
3265
|
-
input_tokens:
|
|
3266
|
-
output_tokens:
|
|
3267
|
-
cache_creation_input_tokens: optional(
|
|
3268
|
-
cache_read_input_tokens: optional(
|
|
3259
|
+
const usageDataSchema = objectType({
|
|
3260
|
+
timestamp: stringType(),
|
|
3261
|
+
version: stringType().optional(),
|
|
3262
|
+
message: objectType({
|
|
3263
|
+
usage: objectType({
|
|
3264
|
+
input_tokens: numberType(),
|
|
3265
|
+
output_tokens: numberType(),
|
|
3266
|
+
cache_creation_input_tokens: numberType().optional(),
|
|
3267
|
+
cache_read_input_tokens: numberType().optional()
|
|
3269
3268
|
}),
|
|
3270
|
-
model: optional(
|
|
3271
|
-
id: optional(
|
|
3269
|
+
model: stringType().optional(),
|
|
3270
|
+
id: stringType().optional()
|
|
3272
3271
|
}),
|
|
3273
|
-
costUSD: optional(
|
|
3274
|
-
requestId: optional(
|
|
3272
|
+
costUSD: numberType().optional(),
|
|
3273
|
+
requestId: stringType().optional()
|
|
3275
3274
|
});
|
|
3276
3275
|
/**
|
|
3277
|
-
*
|
|
3276
|
+
* Zod schema for model-specific usage breakdown data
|
|
3278
3277
|
*/
|
|
3279
|
-
const modelBreakdownSchema =
|
|
3280
|
-
modelName:
|
|
3281
|
-
inputTokens:
|
|
3282
|
-
outputTokens:
|
|
3283
|
-
cacheCreationTokens:
|
|
3284
|
-
cacheReadTokens:
|
|
3285
|
-
cost:
|
|
3278
|
+
const modelBreakdownSchema = objectType({
|
|
3279
|
+
modelName: stringType(),
|
|
3280
|
+
inputTokens: numberType(),
|
|
3281
|
+
outputTokens: numberType(),
|
|
3282
|
+
cacheCreationTokens: numberType(),
|
|
3283
|
+
cacheReadTokens: numberType(),
|
|
3284
|
+
cost: numberType()
|
|
3286
3285
|
});
|
|
3287
3286
|
/**
|
|
3288
|
-
*
|
|
3287
|
+
* Zod schema for daily usage aggregation data
|
|
3289
3288
|
*/
|
|
3290
|
-
const dailyUsageSchema =
|
|
3291
|
-
date:
|
|
3292
|
-
inputTokens:
|
|
3293
|
-
outputTokens:
|
|
3294
|
-
cacheCreationTokens:
|
|
3295
|
-
cacheReadTokens:
|
|
3296
|
-
totalCost:
|
|
3297
|
-
modelsUsed:
|
|
3298
|
-
modelBreakdowns:
|
|
3289
|
+
const dailyUsageSchema = objectType({
|
|
3290
|
+
date: stringType().regex(/^\d{4}-\d{2}-\d{2}$/),
|
|
3291
|
+
inputTokens: numberType(),
|
|
3292
|
+
outputTokens: numberType(),
|
|
3293
|
+
cacheCreationTokens: numberType(),
|
|
3294
|
+
cacheReadTokens: numberType(),
|
|
3295
|
+
totalCost: numberType(),
|
|
3296
|
+
modelsUsed: arrayType(stringType()),
|
|
3297
|
+
modelBreakdowns: arrayType(modelBreakdownSchema)
|
|
3299
3298
|
});
|
|
3300
3299
|
/**
|
|
3301
|
-
*
|
|
3300
|
+
* Zod schema for session-based usage aggregation data
|
|
3302
3301
|
*/
|
|
3303
|
-
const sessionUsageSchema =
|
|
3304
|
-
sessionId:
|
|
3305
|
-
projectPath:
|
|
3306
|
-
inputTokens:
|
|
3307
|
-
outputTokens:
|
|
3308
|
-
cacheCreationTokens:
|
|
3309
|
-
cacheReadTokens:
|
|
3310
|
-
totalCost:
|
|
3311
|
-
lastActivity:
|
|
3312
|
-
versions:
|
|
3313
|
-
modelsUsed:
|
|
3314
|
-
modelBreakdowns:
|
|
3302
|
+
const sessionUsageSchema = objectType({
|
|
3303
|
+
sessionId: stringType(),
|
|
3304
|
+
projectPath: stringType(),
|
|
3305
|
+
inputTokens: numberType(),
|
|
3306
|
+
outputTokens: numberType(),
|
|
3307
|
+
cacheCreationTokens: numberType(),
|
|
3308
|
+
cacheReadTokens: numberType(),
|
|
3309
|
+
totalCost: numberType(),
|
|
3310
|
+
lastActivity: stringType(),
|
|
3311
|
+
versions: arrayType(stringType()),
|
|
3312
|
+
modelsUsed: arrayType(stringType()),
|
|
3313
|
+
modelBreakdowns: arrayType(modelBreakdownSchema)
|
|
3315
3314
|
});
|
|
3316
3315
|
/**
|
|
3317
|
-
*
|
|
3316
|
+
* Zod schema for monthly usage aggregation data
|
|
3318
3317
|
*/
|
|
3319
|
-
const monthlyUsageSchema =
|
|
3320
|
-
month:
|
|
3321
|
-
inputTokens:
|
|
3322
|
-
outputTokens:
|
|
3323
|
-
cacheCreationTokens:
|
|
3324
|
-
cacheReadTokens:
|
|
3325
|
-
totalCost:
|
|
3326
|
-
modelsUsed:
|
|
3327
|
-
modelBreakdowns:
|
|
3318
|
+
const monthlyUsageSchema = objectType({
|
|
3319
|
+
month: stringType().regex(/^\d{4}-\d{2}$/),
|
|
3320
|
+
inputTokens: numberType(),
|
|
3321
|
+
outputTokens: numberType(),
|
|
3322
|
+
cacheCreationTokens: numberType(),
|
|
3323
|
+
cacheReadTokens: numberType(),
|
|
3324
|
+
totalCost: numberType(),
|
|
3325
|
+
modelsUsed: arrayType(stringType()),
|
|
3326
|
+
modelBreakdowns: arrayType(modelBreakdownSchema)
|
|
3328
3327
|
});
|
|
3329
3328
|
/**
|
|
3330
3329
|
* Aggregates token counts and costs by model name
|
|
@@ -3582,9 +3581,9 @@ async function loadDailyUsageData(options) {
|
|
|
3582
3581
|
const lines = content.trim().split("\n").filter((line) => line.length > 0);
|
|
3583
3582
|
for (const line of lines) try {
|
|
3584
3583
|
const parsed = JSON.parse(line);
|
|
3585
|
-
const result = safeParse(
|
|
3584
|
+
const result = usageDataSchema.safeParse(parsed);
|
|
3586
3585
|
if (!result.success) continue;
|
|
3587
|
-
const data = result.
|
|
3586
|
+
const data = result.data;
|
|
3588
3587
|
const uniqueHash = createUniqueHash(data);
|
|
3589
3588
|
if (isDuplicateEntry(uniqueHash, processedHashes)) continue;
|
|
3590
3589
|
markAsProcessed(uniqueHash, processedHashes);
|
|
@@ -3651,9 +3650,9 @@ async function loadSessionData(options) {
|
|
|
3651
3650
|
const lines = content.trim().split("\n").filter((line) => line.length > 0);
|
|
3652
3651
|
for (const line of lines) try {
|
|
3653
3652
|
const parsed = JSON.parse(line);
|
|
3654
|
-
const result = safeParse(
|
|
3653
|
+
const result = usageDataSchema.safeParse(parsed);
|
|
3655
3654
|
if (!result.success) continue;
|
|
3656
|
-
const data = result.
|
|
3655
|
+
const data = result.data;
|
|
3657
3656
|
const uniqueHash = createUniqueHash(data);
|
|
3658
3657
|
if (isDuplicateEntry(uniqueHash, processedHashes)) continue;
|
|
3659
3658
|
markAsProcessed(uniqueHash, processedHashes);
|
|
@@ -3767,9 +3766,9 @@ async function loadSessionBlockData(options) {
|
|
|
3767
3766
|
const lines = content.trim().split("\n").filter((line) => line.length > 0);
|
|
3768
3767
|
for (const line of lines) try {
|
|
3769
3768
|
const parsed = JSON.parse(line);
|
|
3770
|
-
const result = safeParse(
|
|
3769
|
+
const result = usageDataSchema.safeParse(parsed);
|
|
3771
3770
|
if (!result.success) continue;
|
|
3772
|
-
const data = result.
|
|
3771
|
+
const data = result.data;
|
|
3773
3772
|
const uniqueHash = createUniqueHash(data);
|
|
3774
3773
|
if (isDuplicateEntry(uniqueHash, processedHashes)) continue;
|
|
3775
3774
|
markAsProcessed(uniqueHash, processedHashes);
|