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.
@@ -1,5 +1,5 @@
1
- import "./pricing-fetcher-DHaTs-k2.js";
2
- import { DailyUsage, MonthlyUsage, SessionUsage } from "./data-loader-dbZm5kOW.js";
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-DDs53oR8.js";
2
- import { array, number, object, optional, pipe, regex, safeParse, string } from "./dist-DCvt9hEv.js";
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$1 = isState ? picomatch$2.compileRe(glob$1, options) : picomatch$2.makeRe(glob$1, options, false, true);
2415
- const state = regex$1.state;
2416
- delete regex$1.state;
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$1, options, {
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: regex$1,
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$1, options, { glob: glob$1, posix: posix$1 } = {}) => {
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$1, options, posix$1);
2489
- else match = regex$1.exec(output);
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$1 = glob$1 instanceof RegExp ? glob$1 : picomatch$2.makeRe(glob$1, options);
2511
- return regex$1.test(utils$1.basename(input));
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$1 = picomatch$2.toRegex(source, options);
2596
- if (returnState === true) regex$1.state = state;
2597
- return regex$1;
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$1 = __commonJSMin((exports) => {
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$1(), 1);
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$1 = regexes[i];
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$1[j$1].test(inputParts[j$1]);
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 != null ? entry.costUSD : 0;
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
- * Valibot schema for validating Claude usage data from JSONL files
3257
+ * Zod schema for validating Claude usage data from JSONL files
3259
3258
  */
3260
- const usageDataSchema = object({
3261
- timestamp: string(),
3262
- version: optional(string()),
3263
- message: object({
3264
- usage: object({
3265
- input_tokens: number(),
3266
- output_tokens: number(),
3267
- cache_creation_input_tokens: optional(number()),
3268
- cache_read_input_tokens: optional(number())
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(string()),
3271
- id: optional(string())
3269
+ model: stringType().optional(),
3270
+ id: stringType().optional()
3272
3271
  }),
3273
- costUSD: optional(number()),
3274
- requestId: optional(string())
3272
+ costUSD: numberType().optional(),
3273
+ requestId: stringType().optional()
3275
3274
  });
3276
3275
  /**
3277
- * Valibot schema for model-specific usage breakdown data
3276
+ * Zod schema for model-specific usage breakdown data
3278
3277
  */
3279
- const modelBreakdownSchema = object({
3280
- modelName: string(),
3281
- inputTokens: number(),
3282
- outputTokens: number(),
3283
- cacheCreationTokens: number(),
3284
- cacheReadTokens: number(),
3285
- cost: number()
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
- * Valibot schema for daily usage aggregation data
3287
+ * Zod schema for daily usage aggregation data
3289
3288
  */
3290
- const dailyUsageSchema = object({
3291
- date: pipe(string(), regex(/^\d{4}-\d{2}-\d{2}$/)),
3292
- inputTokens: number(),
3293
- outputTokens: number(),
3294
- cacheCreationTokens: number(),
3295
- cacheReadTokens: number(),
3296
- totalCost: number(),
3297
- modelsUsed: array(string()),
3298
- modelBreakdowns: array(modelBreakdownSchema)
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
- * Valibot schema for session-based usage aggregation data
3300
+ * Zod schema for session-based usage aggregation data
3302
3301
  */
3303
- const sessionUsageSchema = object({
3304
- sessionId: string(),
3305
- projectPath: string(),
3306
- inputTokens: number(),
3307
- outputTokens: number(),
3308
- cacheCreationTokens: number(),
3309
- cacheReadTokens: number(),
3310
- totalCost: number(),
3311
- lastActivity: string(),
3312
- versions: array(string()),
3313
- modelsUsed: array(string()),
3314
- modelBreakdowns: array(modelBreakdownSchema)
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
- * Valibot schema for monthly usage aggregation data
3316
+ * Zod schema for monthly usage aggregation data
3318
3317
  */
3319
- const monthlyUsageSchema = object({
3320
- month: pipe(string(), regex(/^\d{4}-\d{2}$/)),
3321
- inputTokens: number(),
3322
- outputTokens: number(),
3323
- cacheCreationTokens: number(),
3324
- cacheReadTokens: number(),
3325
- totalCost: number(),
3326
- modelsUsed: array(string()),
3327
- modelBreakdowns: array(modelBreakdownSchema)
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(usageDataSchema, parsed);
3584
+ const result = usageDataSchema.safeParse(parsed);
3586
3585
  if (!result.success) continue;
3587
- const data = result.output;
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(usageDataSchema, parsed);
3653
+ const result = usageDataSchema.safeParse(parsed);
3655
3654
  if (!result.success) continue;
3656
- const data = result.output;
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(usageDataSchema, parsed);
3769
+ const result = usageDataSchema.safeParse(parsed);
3771
3770
  if (!result.success) continue;
3772
- const data = result.output;
3771
+ const data = result.data;
3773
3772
  const uniqueHash = createUniqueHash(data);
3774
3773
  if (isDuplicateEntry(uniqueHash, processedHashes)) continue;
3775
3774
  markAsProcessed(uniqueHash, processedHashes);