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,360 +0,0 @@
1
- import { number, object, optional, pipe, regex, safeParse, string } from "./dist-DCvt9hEv.js";
2
- import { logger } from "./logger-E_Utl_fr.js";
3
- import { createRequire } from "node:module";
4
-
5
- //#region rolldown:runtime
6
- var __create = Object.create;
7
- var __defProp = Object.defineProperty;
8
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
9
- var __getOwnPropNames = Object.getOwnPropertyNames;
10
- var __getProtoOf = Object.getPrototypeOf;
11
- var __hasOwnProp = Object.prototype.hasOwnProperty;
12
- var __commonJS = (cb, mod) => function() {
13
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
14
- };
15
- var __copyProps = (to, from, except, desc) => {
16
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
17
- key = keys[i];
18
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
19
- get: ((k) => from[k]).bind(null, key),
20
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
21
- });
22
- }
23
- return to;
24
- };
25
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
26
- value: mod,
27
- enumerable: true
28
- }) : target, mod));
29
- var __require = /* @__PURE__ */ createRequire(import.meta.url);
30
-
31
- //#endregion
32
- //#region src/consts.internal.ts
33
- /**
34
- * URL for LiteLLM's model pricing and context window data
35
- */
36
- const LITELLM_PRICING_URL = "https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json";
37
-
38
- //#endregion
39
- //#region src/types.internal.ts
40
- /**
41
- * Valibot schema for validating date strings in YYYYMMDD format
42
- */
43
- const dateSchema = pipe(string(), regex(/^\d{8}$/, "Date must be in YYYYMMDD format"));
44
- /**
45
- * Available cost calculation modes
46
- * - auto: Use pre-calculated costs when available, otherwise calculate from tokens
47
- * - calculate: Always calculate costs from token counts using model pricing
48
- * - display: Always use pre-calculated costs, show 0 for missing costs
49
- */
50
- const CostModes = [
51
- "auto",
52
- "calculate",
53
- "display"
54
- ];
55
- /**
56
- * Available sort orders for data presentation
57
- */
58
- const SortOrders = ["desc", "asc"];
59
- /**
60
- * Valibot schema for model pricing information from LiteLLM
61
- */
62
- const modelPricingSchema = object({
63
- input_cost_per_token: optional(number()),
64
- output_cost_per_token: optional(number()),
65
- cache_creation_input_token_cost: optional(number()),
66
- cache_read_input_token_cost: optional(number())
67
- });
68
-
69
- //#endregion
70
- //#region node_modules/rolldown/node_modules/@oxc-project/runtime/src/helpers/usingCtx.js
71
- var require_usingCtx = __commonJS({ "node_modules/rolldown/node_modules/@oxc-project/runtime/src/helpers/usingCtx.js"(exports, module) {
72
- function _usingCtx() {
73
- var r = "function" == typeof SuppressedError ? SuppressedError : function(r$1, e$1) {
74
- var n$1 = Error();
75
- return n$1.name = "SuppressedError", n$1.error = r$1, n$1.suppressed = e$1, n$1;
76
- }, e = {}, n = [];
77
- function using(r$1, e$1) {
78
- if (null != e$1) {
79
- if (Object(e$1) !== e$1) throw new TypeError("using declarations can only be used with objects, functions, null, or undefined.");
80
- if (r$1) var o = e$1[Symbol.asyncDispose || Symbol["for"]("Symbol.asyncDispose")];
81
- if (void 0 === o && (o = e$1[Symbol.dispose || Symbol["for"]("Symbol.dispose")], r$1)) var t = o;
82
- if ("function" != typeof o) throw new TypeError("Object is not disposable.");
83
- t && (o = function o$1() {
84
- try {
85
- t.call(e$1);
86
- } catch (r$2) {
87
- return Promise.reject(r$2);
88
- }
89
- }), n.push({
90
- v: e$1,
91
- d: o,
92
- a: r$1
93
- });
94
- } else r$1 && n.push({
95
- d: e$1,
96
- a: r$1
97
- });
98
- return e$1;
99
- }
100
- return {
101
- e,
102
- u: using.bind(null, !1),
103
- a: using.bind(null, !0),
104
- d: function d() {
105
- var o, t = this.e, s = 0;
106
- function next() {
107
- for (; o = n.pop();) try {
108
- if (!o.a && 1 === s) return s = 0, n.push(o), Promise.resolve().then(next);
109
- if (o.d) {
110
- var r$1 = o.d.call(o.v);
111
- if (o.a) return s |= 2, Promise.resolve(r$1).then(next, err);
112
- } else s |= 1;
113
- } catch (r$2) {
114
- return err(r$2);
115
- }
116
- if (1 === s) return t !== e ? Promise.reject(t) : Promise.resolve();
117
- if (t !== e) throw t;
118
- }
119
- function err(n$1) {
120
- return t = t !== e ? new r(n$1, t) : n$1, next();
121
- }
122
- return next();
123
- }
124
- };
125
- }
126
- module.exports = _usingCtx, module.exports.__esModule = true, module.exports["default"] = module.exports;
127
- } });
128
-
129
- //#endregion
130
- //#region src/pricing-fetcher.ts
131
- var import_usingCtx = __toESM(require_usingCtx(), 1);
132
- /**
133
- * Fetches and caches model pricing information from LiteLLM
134
- * Implements Disposable pattern for automatic resource cleanup
135
- */
136
- var PricingFetcher = class {
137
- cachedPricing = null;
138
- offline;
139
- /**
140
- * Creates a new PricingFetcher instance
141
- * @param offline - Whether to use pre-fetched pricing data instead of fetching from API
142
- */
143
- constructor(offline = false) {
144
- this.offline = offline;
145
- }
146
- /**
147
- * Implements Disposable interface for automatic cleanup
148
- */
149
- [Symbol.dispose]() {
150
- this.clearCache();
151
- }
152
- /**
153
- * Clears the cached pricing data
154
- */
155
- clearCache() {
156
- this.cachedPricing = null;
157
- }
158
- /**
159
- * Ensures pricing data is loaded, either from cache or by fetching
160
- * @returns Map of model names to pricing information
161
- */
162
- async ensurePricingLoaded() {
163
- if (this.cachedPricing != null) return this.cachedPricing;
164
- if (this.offline) {
165
- const pricing = new Map(Object.entries({
166
- "claude-instant-1": {
167
- "input_cost_per_token": 163e-8,
168
- "output_cost_per_token": 551e-8
169
- },
170
- "claude-instant-1.2": {
171
- "input_cost_per_token": 163e-9,
172
- "output_cost_per_token": 551e-9
173
- },
174
- "claude-2": {
175
- "input_cost_per_token": 8e-6,
176
- "output_cost_per_token": 24e-6
177
- },
178
- "claude-2.1": {
179
- "input_cost_per_token": 8e-6,
180
- "output_cost_per_token": 24e-6
181
- },
182
- "claude-3-haiku-20240307": {
183
- "input_cost_per_token": 25e-8,
184
- "output_cost_per_token": 125e-8,
185
- "cache_creation_input_token_cost": 3e-7,
186
- "cache_read_input_token_cost": 3e-8
187
- },
188
- "claude-3-5-haiku-20241022": {
189
- "input_cost_per_token": 8e-7,
190
- "output_cost_per_token": 4e-6,
191
- "cache_creation_input_token_cost": 1e-6,
192
- "cache_read_input_token_cost": 8e-8
193
- },
194
- "claude-3-5-haiku-latest": {
195
- "input_cost_per_token": 1e-6,
196
- "output_cost_per_token": 5e-6,
197
- "cache_creation_input_token_cost": 125e-8,
198
- "cache_read_input_token_cost": 1e-7
199
- },
200
- "claude-3-opus-latest": {
201
- "input_cost_per_token": 15e-6,
202
- "output_cost_per_token": 75e-6,
203
- "cache_creation_input_token_cost": 1875e-8,
204
- "cache_read_input_token_cost": 15e-7
205
- },
206
- "claude-3-opus-20240229": {
207
- "input_cost_per_token": 15e-6,
208
- "output_cost_per_token": 75e-6,
209
- "cache_creation_input_token_cost": 1875e-8,
210
- "cache_read_input_token_cost": 15e-7
211
- },
212
- "claude-3-sonnet-20240229": {
213
- "input_cost_per_token": 3e-6,
214
- "output_cost_per_token": 15e-6
215
- },
216
- "claude-3-5-sonnet-latest": {
217
- "input_cost_per_token": 3e-6,
218
- "output_cost_per_token": 15e-6,
219
- "cache_creation_input_token_cost": 375e-8,
220
- "cache_read_input_token_cost": 3e-7
221
- },
222
- "claude-3-5-sonnet-20240620": {
223
- "input_cost_per_token": 3e-6,
224
- "output_cost_per_token": 15e-6,
225
- "cache_creation_input_token_cost": 375e-8,
226
- "cache_read_input_token_cost": 3e-7
227
- },
228
- "claude-opus-4-20250514": {
229
- "input_cost_per_token": 15e-6,
230
- "output_cost_per_token": 75e-6,
231
- "cache_creation_input_token_cost": 1875e-8,
232
- "cache_read_input_token_cost": 15e-7
233
- },
234
- "claude-sonnet-4-20250514": {
235
- "input_cost_per_token": 3e-6,
236
- "output_cost_per_token": 15e-6,
237
- "cache_creation_input_token_cost": 375e-8,
238
- "cache_read_input_token_cost": 3e-7
239
- },
240
- "claude-4-opus-20250514": {
241
- "input_cost_per_token": 15e-6,
242
- "output_cost_per_token": 75e-6,
243
- "cache_creation_input_token_cost": 1875e-8,
244
- "cache_read_input_token_cost": 15e-7
245
- },
246
- "claude-4-sonnet-20250514": {
247
- "input_cost_per_token": 3e-6,
248
- "output_cost_per_token": 15e-6,
249
- "cache_creation_input_token_cost": 375e-8,
250
- "cache_read_input_token_cost": 3e-7
251
- },
252
- "claude-3-7-sonnet-latest": {
253
- "input_cost_per_token": 3e-6,
254
- "output_cost_per_token": 15e-6,
255
- "cache_creation_input_token_cost": 375e-8,
256
- "cache_read_input_token_cost": 3e-7
257
- },
258
- "claude-3-7-sonnet-20250219": {
259
- "input_cost_per_token": 3e-6,
260
- "output_cost_per_token": 15e-6,
261
- "cache_creation_input_token_cost": 375e-8,
262
- "cache_read_input_token_cost": 3e-7
263
- },
264
- "claude-3-5-sonnet-20241022": {
265
- "input_cost_per_token": 3e-6,
266
- "output_cost_per_token": 15e-6,
267
- "cache_creation_input_token_cost": 375e-8,
268
- "cache_read_input_token_cost": 3e-7
269
- }
270
- }));
271
- this.cachedPricing = pricing;
272
- return pricing;
273
- }
274
- try {
275
- logger.warn("Fetching latest model pricing from LiteLLM...");
276
- const response = await fetch(LITELLM_PRICING_URL);
277
- if (!response.ok) throw new Error(`Failed to fetch pricing data: ${response.statusText}`);
278
- const data = await response.json();
279
- const pricing = /* @__PURE__ */ new Map();
280
- for (const [modelName, modelData] of Object.entries(data)) if (typeof modelData === "object" && modelData !== null) {
281
- const parsed = safeParse(modelPricingSchema, modelData);
282
- if (parsed.success) pricing.set(modelName, parsed.output);
283
- }
284
- this.cachedPricing = pricing;
285
- logger.info(`Loaded pricing for ${pricing.size} models`);
286
- return pricing;
287
- } catch (error) {
288
- logger.error("Failed to fetch model pricing:", error);
289
- throw new Error("Could not fetch model pricing data");
290
- }
291
- }
292
- /**
293
- * Fetches all available model pricing data
294
- * @returns Map of model names to pricing information
295
- */
296
- async fetchModelPricing() {
297
- return this.ensurePricingLoaded();
298
- }
299
- /**
300
- * Gets pricing information for a specific model with fallback matching
301
- * Tries exact match first, then provider prefixes, then partial matches
302
- * @param modelName - Name of the model to get pricing for
303
- * @returns Model pricing information or null if not found
304
- */
305
- async getModelPricing(modelName) {
306
- const pricing = await this.ensurePricingLoaded();
307
- const directMatch = pricing.get(modelName);
308
- if (directMatch != null) return directMatch;
309
- const variations = [
310
- modelName,
311
- `anthropic/${modelName}`,
312
- `claude-3-5-${modelName}`,
313
- `claude-3-${modelName}`,
314
- `claude-${modelName}`
315
- ];
316
- for (const variant of variations) {
317
- const match = pricing.get(variant);
318
- if (match != null) return match;
319
- }
320
- const lowerModel = modelName.toLowerCase();
321
- for (const [key, value] of pricing) if (key.toLowerCase().includes(lowerModel) || lowerModel.includes(key.toLowerCase())) return value;
322
- return null;
323
- }
324
- /**
325
- * Calculates the cost for given token usage and model
326
- * @param tokens - Token usage breakdown
327
- * @param tokens.input_tokens - Number of input tokens
328
- * @param tokens.output_tokens - Number of output tokens
329
- * @param tokens.cache_creation_input_tokens - Number of cache creation tokens
330
- * @param tokens.cache_read_input_tokens - Number of cache read tokens
331
- * @param modelName - Name of the model used
332
- * @returns Total cost in USD
333
- */
334
- async calculateCostFromTokens(tokens, modelName) {
335
- const pricing = await this.getModelPricing(modelName);
336
- if (pricing == null) return 0;
337
- return this.calculateCostFromPricing(tokens, pricing);
338
- }
339
- /**
340
- * Calculates cost from token usage and pricing information
341
- * @param tokens - Token usage breakdown
342
- * @param tokens.input_tokens - Number of input tokens
343
- * @param tokens.output_tokens - Number of output tokens
344
- * @param tokens.cache_creation_input_tokens - Number of cache creation tokens
345
- * @param tokens.cache_read_input_tokens - Number of cache read tokens
346
- * @param pricing - Model pricing rates
347
- * @returns Total cost in USD
348
- */
349
- calculateCostFromPricing(tokens, pricing) {
350
- let cost = 0;
351
- if (pricing.input_cost_per_token != null) cost += tokens.input_tokens * pricing.input_cost_per_token;
352
- if (pricing.output_cost_per_token != null) cost += tokens.output_tokens * pricing.output_cost_per_token;
353
- if (tokens.cache_creation_input_tokens != null && pricing.cache_creation_input_token_cost != null) cost += tokens.cache_creation_input_tokens * pricing.cache_creation_input_token_cost;
354
- if (tokens.cache_read_input_tokens != null && pricing.cache_read_input_token_cost != null) cost += tokens.cache_read_input_tokens * pricing.cache_read_input_token_cost;
355
- return cost;
356
- }
357
- };
358
-
359
- //#endregion
360
- export { CostModes, PricingFetcher, SortOrders, __commonJS, __require, __toESM, dateSchema, require_usingCtx };