ccusage 11.0.1 → 12.0.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.
Files changed (35) hide show
  1. package/dist/calculate-cost-D3IraeGW.js +1 -4
  2. package/dist/calculate-cost.d.ts +2 -2
  3. package/dist/calculate-cost.js +1 -2
  4. package/dist/data-loader-CBwn9vk0.d.ts +464 -0
  5. package/dist/{data-loader-BzOeJe6y.js → data-loader-rsgRy-no.js} +139 -261
  6. package/dist/data-loader.d.ts +2 -2
  7. package/dist/data-loader.js +4 -6
  8. package/dist/{debug-CjjJciy1.js → debug-BhnEVNbA.js} +6 -11
  9. package/dist/debug.js +5 -7
  10. package/dist/index.js +444 -203
  11. package/dist/{logger-E_Utl_fr.js → logger-CTFDCX5W.js} +3 -22
  12. package/dist/logger.js +2 -3
  13. package/dist/mcp-Cg5potQX.js +20889 -0
  14. package/dist/mcp.d.ts +30 -6
  15. package/dist/mcp.js +5 -9
  16. package/dist/{types-5-VF7WcO.js → pricing-fetcher-3m6_Ejp8.js} +341 -22
  17. package/dist/pricing-fetcher-BkOpRIdx.d.ts +188 -0
  18. package/dist/pricing-fetcher.d.ts +1 -1
  19. package/dist/pricing-fetcher.js +3 -5
  20. package/dist/{prompt-CUbwSrjo.js → prompt-E8j7mEMw.js} +1 -5
  21. package/package.json +1 -1
  22. package/dist/arktype-C-GObzDh-Bx7Fdrqj.js +0 -5
  23. package/dist/core-eFvU0K4V.js +0 -698
  24. package/dist/data-loader-dbZm5kOW.d.ts +0 -247
  25. package/dist/dist-Cb1UHXV5.js +0 -469
  26. package/dist/dist-DCvt9hEv.js +0 -383
  27. package/dist/effect-WSjEuzC9-CZCpOgOT.js +0 -10
  28. package/dist/esm-D74K9ESq.js +0 -1090
  29. package/dist/index-CISmcbXk-DpuCarFe.js +0 -23
  30. package/dist/mcp-SPAE-cNK.js +0 -37610
  31. package/dist/pricing-fetcher-BtW4MVG7.js +0 -360
  32. package/dist/pricing-fetcher-DHaTs-k2.d.ts +0 -1737
  33. package/dist/sury-DmrZ3_Oj-Lq7x0IZW.js +0 -10
  34. package/dist/valibot-CQk-M5rL-btpzU8Qa.js +0 -10
  35. package/dist/zod-Db63SLXj-BqWqpKnQ.js +0 -30
@@ -1,247 +0,0 @@
1
- import { ArraySchema, CostMode, InferOutput, NumberSchema, ObjectSchema, OptionalSchema, PricingFetcher, RegexAction, SchemaWithPipe, SortOrder, StringSchema } from "./pricing-fetcher-DHaTs-k2.js";
2
-
3
- //#region src/session-blocks.internal.d.ts
4
-
5
- /**
6
- * Represents a single usage data entry loaded from JSONL files
7
- */
8
- type LoadedUsageEntry = {
9
- timestamp: Date;
10
- usage: {
11
- inputTokens: number;
12
- outputTokens: number;
13
- cacheCreationInputTokens: number;
14
- cacheReadInputTokens: number;
15
- };
16
- costUSD: number | null;
17
- model: string;
18
- version?: string;
19
- };
20
- /**
21
- * Aggregated token counts for different token types
22
- */
23
- type TokenCounts = {
24
- inputTokens: number;
25
- outputTokens: number;
26
- cacheCreationInputTokens: number;
27
- cacheReadInputTokens: number;
28
- };
29
- /**
30
- * Represents a session block (typically 5-hour billing period) with usage data
31
- */
32
- type SessionBlock = {
33
- id: string; // ISO string of block start time
34
- startTime: Date;
35
- endTime: Date; // startTime + 5 hours (for normal blocks) or gap end time (for gap blocks)
36
- actualEndTime?: Date; // Last activity in block
37
- isActive: boolean;
38
- isGap?: boolean; // True if this is a gap block
39
- entries: LoadedUsageEntry[];
40
- tokenCounts: TokenCounts;
41
- costUSD: number;
42
- models: string[];
43
- };
44
- /**
45
- * Represents usage burn rate calculations
46
- */
47
- //#endregion
48
- //#region src/data-loader.d.ts
49
- /**
50
- * Default path for Claude data directory
51
- * Uses environment variable CLAUDE_CONFIG_DIR if set, otherwise defaults to ~/.claude
52
- */
53
- declare function getDefaultClaudePath(): string;
54
- /**
55
- * Valibot schema for validating Claude usage data from JSONL files
56
- */
57
- declare const usageDataSchema: ObjectSchema<{
58
- readonly timestamp: StringSchema<undefined>;
59
- readonly version: OptionalSchema<StringSchema<undefined>, undefined>;
60
- readonly message: ObjectSchema<{
61
- readonly usage: ObjectSchema<{
62
- readonly input_tokens: NumberSchema<undefined>;
63
- readonly output_tokens: NumberSchema<undefined>;
64
- readonly cache_creation_input_tokens: OptionalSchema<NumberSchema<undefined>, undefined>;
65
- readonly cache_read_input_tokens: OptionalSchema<NumberSchema<undefined>, undefined>;
66
- }, undefined>;
67
- readonly model: OptionalSchema<StringSchema<undefined>, undefined>;
68
- readonly id: OptionalSchema<StringSchema<undefined>, undefined>;
69
- }, undefined>;
70
- readonly costUSD: OptionalSchema<NumberSchema<undefined>, undefined>;
71
- readonly requestId: OptionalSchema<StringSchema<undefined>, undefined>;
72
- }, undefined>;
73
- /**
74
- * Type definition for Claude usage data entries from JSONL files
75
- */
76
- type UsageData = InferOutput<typeof usageDataSchema>;
77
- /**
78
- * Valibot schema for model-specific usage breakdown data
79
- */
80
- declare const modelBreakdownSchema: ObjectSchema<{
81
- readonly modelName: StringSchema<undefined>;
82
- readonly inputTokens: NumberSchema<undefined>;
83
- readonly outputTokens: NumberSchema<undefined>;
84
- readonly cacheCreationTokens: NumberSchema<undefined>;
85
- readonly cacheReadTokens: NumberSchema<undefined>;
86
- readonly cost: NumberSchema<undefined>;
87
- }, undefined>;
88
- /**
89
- * Type definition for model-specific usage breakdown
90
- */
91
- type ModelBreakdown = InferOutput<typeof modelBreakdownSchema>;
92
- /**
93
- * Valibot schema for daily usage aggregation data
94
- */
95
- declare const dailyUsageSchema: ObjectSchema<{
96
- readonly date: SchemaWithPipe<readonly [StringSchema<undefined>, RegexAction<string, undefined>]>;
97
- readonly inputTokens: NumberSchema<undefined>;
98
- readonly outputTokens: NumberSchema<undefined>;
99
- readonly cacheCreationTokens: NumberSchema<undefined>;
100
- readonly cacheReadTokens: NumberSchema<undefined>;
101
- readonly totalCost: NumberSchema<undefined>;
102
- readonly modelsUsed: ArraySchema<StringSchema<undefined>, undefined>;
103
- readonly modelBreakdowns: ArraySchema<ObjectSchema<{
104
- readonly modelName: StringSchema<undefined>;
105
- readonly inputTokens: NumberSchema<undefined>;
106
- readonly outputTokens: NumberSchema<undefined>;
107
- readonly cacheCreationTokens: NumberSchema<undefined>;
108
- readonly cacheReadTokens: NumberSchema<undefined>;
109
- readonly cost: NumberSchema<undefined>;
110
- }, undefined>, undefined>;
111
- }, undefined>;
112
- /**
113
- * Type definition for daily usage aggregation
114
- */
115
- type DailyUsage = InferOutput<typeof dailyUsageSchema>;
116
- /**
117
- * Valibot schema for session-based usage aggregation data
118
- */
119
- declare const sessionUsageSchema: ObjectSchema<{
120
- readonly sessionId: StringSchema<undefined>;
121
- readonly projectPath: StringSchema<undefined>;
122
- readonly inputTokens: NumberSchema<undefined>;
123
- readonly outputTokens: NumberSchema<undefined>;
124
- readonly cacheCreationTokens: NumberSchema<undefined>;
125
- readonly cacheReadTokens: NumberSchema<undefined>;
126
- readonly totalCost: NumberSchema<undefined>;
127
- readonly lastActivity: StringSchema<undefined>;
128
- readonly versions: ArraySchema<StringSchema<undefined>, undefined>;
129
- readonly modelsUsed: ArraySchema<StringSchema<undefined>, undefined>;
130
- readonly modelBreakdowns: ArraySchema<ObjectSchema<{
131
- readonly modelName: StringSchema<undefined>;
132
- readonly inputTokens: NumberSchema<undefined>;
133
- readonly outputTokens: NumberSchema<undefined>;
134
- readonly cacheCreationTokens: NumberSchema<undefined>;
135
- readonly cacheReadTokens: NumberSchema<undefined>;
136
- readonly cost: NumberSchema<undefined>;
137
- }, undefined>, undefined>;
138
- }, undefined>;
139
- /**
140
- * Type definition for session-based usage aggregation
141
- */
142
- type SessionUsage = InferOutput<typeof sessionUsageSchema>;
143
- /**
144
- * Valibot schema for monthly usage aggregation data
145
- */
146
- declare const monthlyUsageSchema: ObjectSchema<{
147
- readonly month: SchemaWithPipe<readonly [StringSchema<undefined>, RegexAction<string, undefined>]>;
148
- readonly inputTokens: NumberSchema<undefined>;
149
- readonly outputTokens: NumberSchema<undefined>;
150
- readonly cacheCreationTokens: NumberSchema<undefined>;
151
- readonly cacheReadTokens: NumberSchema<undefined>;
152
- readonly totalCost: NumberSchema<undefined>;
153
- readonly modelsUsed: ArraySchema<StringSchema<undefined>, undefined>;
154
- readonly modelBreakdowns: ArraySchema<ObjectSchema<{
155
- readonly modelName: StringSchema<undefined>;
156
- readonly inputTokens: NumberSchema<undefined>;
157
- readonly outputTokens: NumberSchema<undefined>;
158
- readonly cacheCreationTokens: NumberSchema<undefined>;
159
- readonly cacheReadTokens: NumberSchema<undefined>;
160
- readonly cost: NumberSchema<undefined>;
161
- }, undefined>, undefined>;
162
- }, undefined>;
163
- /**
164
- * Type definition for monthly usage aggregation
165
- */
166
- type MonthlyUsage = InferOutput<typeof monthlyUsageSchema>;
167
- /**
168
- * Formats a date string to YYYY-MM-DD format
169
- * @param dateStr - Input date string
170
- * @returns Formatted date string in YYYY-MM-DD format
171
- */
172
- declare function formatDate(dateStr: string): string;
173
- /**
174
- * Formats a date string to compact format with year on first line and month-day on second
175
- * @param dateStr - Input date string
176
- * @returns Formatted date string with newline separator (YYYY\nMM-DD)
177
- */
178
- declare function formatDateCompact(dateStr: string): string;
179
- /**
180
- * Create a unique identifier for deduplication using message ID and request ID
181
- */
182
- declare function createUniqueHash(data: UsageData): string | null;
183
- /**
184
- * Extract the earliest timestamp from a JSONL file
185
- * Scans through the file until it finds a valid timestamp
186
- */
187
- declare function getEarliestTimestamp(filePath: string): Promise<Date | null>;
188
- /**
189
- * Sort files by their earliest timestamp
190
- * Files without valid timestamps are placed at the end
191
- */
192
- declare function sortFilesByTimestamp(files: string[]): Promise<string[]>;
193
- /**
194
- * Calculates cost for a single usage data entry based on the specified cost calculation mode
195
- * @param data - Usage data entry
196
- * @param mode - Cost calculation mode (auto, calculate, or display)
197
- * @param fetcher - Pricing fetcher instance for calculating costs from tokens
198
- * @returns Calculated cost in USD
199
- */
200
- declare function calculateCostForEntry(data: UsageData, mode: CostMode, fetcher: PricingFetcher): Promise<number>;
201
- /**
202
- * Date range filter for limiting usage data by date
203
- */
204
- type DateFilter = {
205
- since?: string; // YYYYMMDD format
206
- until?: string; // YYYYMMDD format
207
- };
208
- /**
209
- * Configuration options for loading usage data
210
- */
211
- type LoadOptions = {
212
- claudePath?: string; // Custom path to Claude data directory
213
- mode?: CostMode; // Cost calculation mode
214
- order?: SortOrder; // Sort order for dates
215
- offline?: boolean; // Use offline mode for pricing
216
- sessionDurationHours?: number; // Session block duration in hours
217
- } & DateFilter;
218
- /**
219
- * Loads and aggregates Claude usage data by day
220
- * Processes all JSONL files in the Claude projects directory and groups usage by date
221
- * @param options - Optional configuration for loading and filtering data
222
- * @returns Array of daily usage summaries sorted by date
223
- */
224
- declare function loadDailyUsageData(options?: LoadOptions): Promise<DailyUsage[]>;
225
- /**
226
- * Loads and aggregates Claude usage data by session
227
- * Groups usage data by project path and session ID based on file structure
228
- * @param options - Optional configuration for loading and filtering data
229
- * @returns Array of session usage summaries sorted by last activity
230
- */
231
- declare function loadSessionData(options?: LoadOptions): Promise<SessionUsage[]>;
232
- /**
233
- * Loads and aggregates Claude usage data by month
234
- * Uses daily usage data as the source and groups by month
235
- * @param options - Optional configuration for loading and filtering data
236
- * @returns Array of monthly usage summaries sorted by month
237
- */
238
- declare function loadMonthlyUsageData(options?: LoadOptions): Promise<MonthlyUsage[]>;
239
- /**
240
- * Loads usage data and organizes it into session blocks (typically 5-hour billing periods)
241
- * Processes all usage data and groups it into time-based blocks for billing analysis
242
- * @param options - Optional configuration including session duration and filtering
243
- * @returns Array of session blocks with usage and cost information
244
- */
245
- declare function loadSessionBlockData(options?: LoadOptions): Promise<SessionBlock[]>;
246
- //#endregion
247
- export { DailyUsage, DateFilter, LoadOptions, ModelBreakdown, MonthlyUsage, SessionUsage, UsageData, calculateCostForEntry, createUniqueHash, dailyUsageSchema, formatDate, formatDateCompact, getDefaultClaudePath, getEarliestTimestamp, loadDailyUsageData, loadMonthlyUsageData, loadSessionBlockData, loadSessionData, modelBreakdownSchema, monthlyUsageSchema, sessionUsageSchema, sortFilesByTimestamp, usageDataSchema };