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
package/dist/mcp.d.ts CHANGED
@@ -1,13 +1,37 @@
1
- import "./pricing-fetcher-DHaTs-k2.js";
2
- import { LoadOptions } from "./data-loader-dbZm5kOW.js";
3
- import { FastMCP } from "fastmcp";
1
+ import "./pricing-fetcher-BkOpRIdx.js";
2
+ import { LoadOptions } from "./data-loader-CBwn9vk0.js";
3
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
4
+ import { Hono } from "hono";
4
5
 
5
6
  //#region src/mcp.d.ts
7
+
6
8
  /**
7
- * Creates a FastMCP server with tools for showing usage reports.
9
+ * Creates an MCP server with tools for showing usage reports.
10
+ * Registers tools for daily, session, monthly, and blocks usage data.
11
+ *
12
+ * @param options - Configuration options for the MCP server
13
+ * @param options.claudePath - Path to Claude's data directory
14
+ * @returns Configured MCP server instance with registered tools
8
15
  */
9
16
  declare function createMcpServer({
10
17
  claudePath
11
- }?: LoadOptions): FastMCP;
18
+ }?: LoadOptions): McpServer;
19
+ /**
20
+ * Start the MCP server with stdio transport.
21
+ * Used for traditional MCP client connections via standard input/output.
22
+ *
23
+ * @param server - The MCP server instance to start
24
+ */
25
+ declare function startMcpServerStdio(server: McpServer): Promise<void>;
26
+ /**
27
+ * Create Hono app for MCP HTTP server.
28
+ * Provides HTTP transport support for MCP protocol using Hono framework.
29
+ * Handles POST requests for MCP communication and returns appropriate errors for other methods.
30
+ *
31
+ * @param options - Configuration options for the MCP server
32
+ * @param options.claudePath - Path to Claude's data directory
33
+ * @returns Configured Hono application for HTTP MCP transport
34
+ */
35
+ declare function createMcpHttpApp(options?: LoadOptions): Hono;
12
36
  //#endregion
13
- export { createMcpServer };
37
+ export { createMcpHttpApp, createMcpServer, startMcpServerStdio };
package/dist/mcp.js CHANGED
@@ -1,9 +1,5 @@
1
- import "./pricing-fetcher-BtW4MVG7.js";
2
- import "./data-loader-BzOeJe6y.js";
3
- import "./dist-DCvt9hEv.js";
4
- import "./logger-E_Utl_fr.js";
5
- import "./types-5-VF7WcO.js";
6
- import { createMcpServer } from "./mcp-SPAE-cNK.js";
7
- import "./index-CISmcbXk-DpuCarFe.js";
8
-
9
- export { createMcpServer };
1
+ import "./pricing-fetcher-3m6_Ejp8.js";
2
+ import "./data-loader-rsgRy-no.js";
3
+ import "./logger-CTFDCX5W.js";
4
+ import { createMcpHttpApp, createMcpServer, startMcpServerStdio } from "./mcp-Cg5potQX.js";
5
+ export { createMcpHttpApp, createMcpServer, startMcpServerStdio };
@@ -1,4 +1,27 @@
1
- //#region node_modules/zod/dist/esm/v3/helpers/util.js
1
+ import { logger } from "./logger-CTFDCX5W.js";
2
+ import { createRequire } from "node:module";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
12
+ key = keys[i];
13
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
21
+ value: mod,
22
+ enumerable: true
23
+ }) : target, mod));
24
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
2
25
  var util;
3
26
  (function(util$1) {
4
27
  util$1.assertEqual = (_) => {};
@@ -95,9 +118,6 @@ const getParsedType = (data) => {
95
118
  default: return ZodParsedType.unknown;
96
119
  }
97
120
  };
98
-
99
- //#endregion
100
- //#region node_modules/zod/dist/esm/v3/ZodError.js
101
121
  const ZodIssueCode = util.arrayToEnum([
102
122
  "invalid_type",
103
123
  "invalid_literal",
@@ -196,9 +216,6 @@ ZodError.create = (issues) => {
196
216
  const error = new ZodError(issues);
197
217
  return error;
198
218
  };
199
-
200
- //#endregion
201
- //#region node_modules/zod/dist/esm/v3/locales/en.js
202
219
  const errorMap = (issue, _ctx) => {
203
220
  let message;
204
221
  switch (issue.code) {
@@ -274,16 +291,10 @@ const errorMap = (issue, _ctx) => {
274
291
  return { message };
275
292
  };
276
293
  var en_default = errorMap;
277
-
278
- //#endregion
279
- //#region node_modules/zod/dist/esm/v3/errors.js
280
294
  let overrideErrorMap = en_default;
281
295
  function getErrorMap() {
282
296
  return overrideErrorMap;
283
297
  }
284
-
285
- //#endregion
286
- //#region node_modules/zod/dist/esm/v3/helpers/parseUtil.js
287
298
  const makeIssue = (params) => {
288
299
  const { data, path, errorMaps, issueData } = params;
289
300
  const fullPath = [...path, ...issueData.path || []];
@@ -386,17 +397,11 @@ const isAborted = (x) => x.status === "aborted";
386
397
  const isDirty = (x) => x.status === "dirty";
387
398
  const isValid = (x) => x.status === "valid";
388
399
  const isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
389
-
390
- //#endregion
391
- //#region node_modules/zod/dist/esm/v3/helpers/errorUtil.js
392
400
  var errorUtil;
393
401
  (function(errorUtil$1) {
394
402
  errorUtil$1.errToObj = (message) => typeof message === "string" ? { message } : message || {};
395
403
  errorUtil$1.toString = (message) => typeof message === "string" ? message : message?.message;
396
404
  })(errorUtil || (errorUtil = {}));
397
-
398
- //#endregion
399
- //#region node_modules/zod/dist/esm/v3/types.js
400
405
  var ParseInputLazyPath = class {
401
406
  constructor(parent, value, path, key) {
402
407
  this._cachedPath = [];
@@ -3581,6 +3586,320 @@ const optionalType = ZodOptional.create;
3581
3586
  const nullableType = ZodNullable.create;
3582
3587
  const preprocessType = ZodEffects.createWithPreprocess;
3583
3588
  const pipelineType = ZodPipeline.create;
3584
-
3585
- //#endregion
3586
- export { ZodFirstPartyTypeKind, ZodOptional, anyType, arrayType, booleanType, discriminatedUnionType, enumType, literalType, numberType, objectType, optionalType, recordType, stringType, unionType, unknownType };
3589
+ /**
3590
+ * URL for LiteLLM's model pricing and context window data
3591
+ */
3592
+ const LITELLM_PRICING_URL = "https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json";
3593
+ /**
3594
+ * Zod schema for validating date strings in YYYYMMDD format
3595
+ */
3596
+ const dateSchema = stringType().regex(/^\d{8}$/, "Date must be in YYYYMMDD format");
3597
+ /**
3598
+ * Available cost calculation modes
3599
+ * - auto: Use pre-calculated costs when available, otherwise calculate from tokens
3600
+ * - calculate: Always calculate costs from token counts using model pricing
3601
+ * - display: Always use pre-calculated costs, show 0 for missing costs
3602
+ */
3603
+ const CostModes = [
3604
+ "auto",
3605
+ "calculate",
3606
+ "display"
3607
+ ];
3608
+ /**
3609
+ * Available sort orders for data presentation
3610
+ */
3611
+ const SortOrders = ["desc", "asc"];
3612
+ /**
3613
+ * Zod schema for model pricing information from LiteLLM
3614
+ */
3615
+ const modelPricingSchema = objectType({
3616
+ input_cost_per_token: numberType().optional(),
3617
+ output_cost_per_token: numberType().optional(),
3618
+ cache_creation_input_token_cost: numberType().optional(),
3619
+ cache_read_input_token_cost: numberType().optional()
3620
+ });
3621
+ var require_usingCtx = __commonJSMin((exports, module) => {
3622
+ function _usingCtx() {
3623
+ var r = "function" == typeof SuppressedError ? SuppressedError : function(r$1, e$1) {
3624
+ var n$1 = Error();
3625
+ return n$1.name = "SuppressedError", n$1.error = r$1, n$1.suppressed = e$1, n$1;
3626
+ }, e = {}, n = [];
3627
+ function using(r$1, e$1) {
3628
+ if (null != e$1) {
3629
+ if (Object(e$1) !== e$1) throw new TypeError("using declarations can only be used with objects, functions, null, or undefined.");
3630
+ if (r$1) var o = e$1[Symbol.asyncDispose || Symbol["for"]("Symbol.asyncDispose")];
3631
+ if (void 0 === o && (o = e$1[Symbol.dispose || Symbol["for"]("Symbol.dispose")], r$1)) var t = o;
3632
+ if ("function" != typeof o) throw new TypeError("Object is not disposable.");
3633
+ t && (o = function o$1() {
3634
+ try {
3635
+ t.call(e$1);
3636
+ } catch (r$2) {
3637
+ return Promise.reject(r$2);
3638
+ }
3639
+ }), n.push({
3640
+ v: e$1,
3641
+ d: o,
3642
+ a: r$1
3643
+ });
3644
+ } else r$1 && n.push({
3645
+ d: e$1,
3646
+ a: r$1
3647
+ });
3648
+ return e$1;
3649
+ }
3650
+ return {
3651
+ e,
3652
+ u: using.bind(null, !1),
3653
+ a: using.bind(null, !0),
3654
+ d: function d() {
3655
+ var o, t = this.e, s = 0;
3656
+ function next() {
3657
+ for (; o = n.pop();) try {
3658
+ if (!o.a && 1 === s) return s = 0, n.push(o), Promise.resolve().then(next);
3659
+ if (o.d) {
3660
+ var r$1 = o.d.call(o.v);
3661
+ if (o.a) return s |= 2, Promise.resolve(r$1).then(next, err);
3662
+ } else s |= 1;
3663
+ } catch (r$2) {
3664
+ return err(r$2);
3665
+ }
3666
+ if (1 === s) return t !== e ? Promise.reject(t) : Promise.resolve();
3667
+ if (t !== e) throw t;
3668
+ }
3669
+ function err(n$1) {
3670
+ return t = t !== e ? new r(n$1, t) : n$1, next();
3671
+ }
3672
+ return next();
3673
+ }
3674
+ };
3675
+ }
3676
+ module.exports = _usingCtx, module.exports.__esModule = true, module.exports["default"] = module.exports;
3677
+ });
3678
+ var import_usingCtx = __toESM(require_usingCtx(), 1);
3679
+ /**
3680
+ * Fetches and caches model pricing information from LiteLLM
3681
+ * Implements Disposable pattern for automatic resource cleanup
3682
+ */
3683
+ var PricingFetcher = class {
3684
+ cachedPricing = null;
3685
+ offline;
3686
+ /**
3687
+ * Creates a new PricingFetcher instance
3688
+ * @param offline - Whether to use pre-fetched pricing data instead of fetching from API
3689
+ */
3690
+ constructor(offline = false) {
3691
+ this.offline = offline;
3692
+ }
3693
+ /**
3694
+ * Implements Disposable interface for automatic cleanup
3695
+ */
3696
+ [Symbol.dispose]() {
3697
+ this.clearCache();
3698
+ }
3699
+ /**
3700
+ * Clears the cached pricing data
3701
+ */
3702
+ clearCache() {
3703
+ this.cachedPricing = null;
3704
+ }
3705
+ /**
3706
+ * Ensures pricing data is loaded, either from cache or by fetching
3707
+ * @returns Map of model names to pricing information
3708
+ */
3709
+ async ensurePricingLoaded() {
3710
+ if (this.cachedPricing != null) return this.cachedPricing;
3711
+ if (this.offline) {
3712
+ const pricing = new Map(Object.entries({
3713
+ "claude-instant-1": {
3714
+ "input_cost_per_token": 163e-8,
3715
+ "output_cost_per_token": 551e-8
3716
+ },
3717
+ "claude-instant-1.2": {
3718
+ "input_cost_per_token": 163e-9,
3719
+ "output_cost_per_token": 551e-9
3720
+ },
3721
+ "claude-2": {
3722
+ "input_cost_per_token": 8e-6,
3723
+ "output_cost_per_token": 24e-6
3724
+ },
3725
+ "claude-2.1": {
3726
+ "input_cost_per_token": 8e-6,
3727
+ "output_cost_per_token": 24e-6
3728
+ },
3729
+ "claude-3-haiku-20240307": {
3730
+ "input_cost_per_token": 25e-8,
3731
+ "output_cost_per_token": 125e-8,
3732
+ "cache_creation_input_token_cost": 3e-7,
3733
+ "cache_read_input_token_cost": 3e-8
3734
+ },
3735
+ "claude-3-5-haiku-20241022": {
3736
+ "input_cost_per_token": 8e-7,
3737
+ "output_cost_per_token": 4e-6,
3738
+ "cache_creation_input_token_cost": 1e-6,
3739
+ "cache_read_input_token_cost": 8e-8
3740
+ },
3741
+ "claude-3-5-haiku-latest": {
3742
+ "input_cost_per_token": 1e-6,
3743
+ "output_cost_per_token": 5e-6,
3744
+ "cache_creation_input_token_cost": 125e-8,
3745
+ "cache_read_input_token_cost": 1e-7
3746
+ },
3747
+ "claude-3-opus-latest": {
3748
+ "input_cost_per_token": 15e-6,
3749
+ "output_cost_per_token": 75e-6,
3750
+ "cache_creation_input_token_cost": 1875e-8,
3751
+ "cache_read_input_token_cost": 15e-7
3752
+ },
3753
+ "claude-3-opus-20240229": {
3754
+ "input_cost_per_token": 15e-6,
3755
+ "output_cost_per_token": 75e-6,
3756
+ "cache_creation_input_token_cost": 1875e-8,
3757
+ "cache_read_input_token_cost": 15e-7
3758
+ },
3759
+ "claude-3-sonnet-20240229": {
3760
+ "input_cost_per_token": 3e-6,
3761
+ "output_cost_per_token": 15e-6
3762
+ },
3763
+ "claude-3-5-sonnet-latest": {
3764
+ "input_cost_per_token": 3e-6,
3765
+ "output_cost_per_token": 15e-6,
3766
+ "cache_creation_input_token_cost": 375e-8,
3767
+ "cache_read_input_token_cost": 3e-7
3768
+ },
3769
+ "claude-3-5-sonnet-20240620": {
3770
+ "input_cost_per_token": 3e-6,
3771
+ "output_cost_per_token": 15e-6,
3772
+ "cache_creation_input_token_cost": 375e-8,
3773
+ "cache_read_input_token_cost": 3e-7
3774
+ },
3775
+ "claude-opus-4-20250514": {
3776
+ "input_cost_per_token": 15e-6,
3777
+ "output_cost_per_token": 75e-6,
3778
+ "cache_creation_input_token_cost": 1875e-8,
3779
+ "cache_read_input_token_cost": 15e-7
3780
+ },
3781
+ "claude-sonnet-4-20250514": {
3782
+ "input_cost_per_token": 3e-6,
3783
+ "output_cost_per_token": 15e-6,
3784
+ "cache_creation_input_token_cost": 375e-8,
3785
+ "cache_read_input_token_cost": 3e-7
3786
+ },
3787
+ "claude-4-opus-20250514": {
3788
+ "input_cost_per_token": 15e-6,
3789
+ "output_cost_per_token": 75e-6,
3790
+ "cache_creation_input_token_cost": 1875e-8,
3791
+ "cache_read_input_token_cost": 15e-7
3792
+ },
3793
+ "claude-4-sonnet-20250514": {
3794
+ "input_cost_per_token": 3e-6,
3795
+ "output_cost_per_token": 15e-6,
3796
+ "cache_creation_input_token_cost": 375e-8,
3797
+ "cache_read_input_token_cost": 3e-7
3798
+ },
3799
+ "claude-3-7-sonnet-latest": {
3800
+ "input_cost_per_token": 3e-6,
3801
+ "output_cost_per_token": 15e-6,
3802
+ "cache_creation_input_token_cost": 375e-8,
3803
+ "cache_read_input_token_cost": 3e-7
3804
+ },
3805
+ "claude-3-7-sonnet-20250219": {
3806
+ "input_cost_per_token": 3e-6,
3807
+ "output_cost_per_token": 15e-6,
3808
+ "cache_creation_input_token_cost": 375e-8,
3809
+ "cache_read_input_token_cost": 3e-7
3810
+ },
3811
+ "claude-3-5-sonnet-20241022": {
3812
+ "input_cost_per_token": 3e-6,
3813
+ "output_cost_per_token": 15e-6,
3814
+ "cache_creation_input_token_cost": 375e-8,
3815
+ "cache_read_input_token_cost": 3e-7
3816
+ }
3817
+ }));
3818
+ this.cachedPricing = pricing;
3819
+ return pricing;
3820
+ }
3821
+ try {
3822
+ logger.warn("Fetching latest model pricing from LiteLLM...");
3823
+ const response = await fetch(LITELLM_PRICING_URL);
3824
+ if (!response.ok) throw new Error(`Failed to fetch pricing data: ${response.statusText}`);
3825
+ const data = await response.json();
3826
+ const pricing = /* @__PURE__ */ new Map();
3827
+ for (const [modelName, modelData] of Object.entries(data)) if (typeof modelData === "object" && modelData !== null) {
3828
+ const parsed = modelPricingSchema.safeParse(modelData);
3829
+ if (parsed.success) pricing.set(modelName, parsed.data);
3830
+ }
3831
+ this.cachedPricing = pricing;
3832
+ logger.info(`Loaded pricing for ${pricing.size} models`);
3833
+ return pricing;
3834
+ } catch (error) {
3835
+ logger.error("Failed to fetch model pricing:", error);
3836
+ throw new Error("Could not fetch model pricing data");
3837
+ }
3838
+ }
3839
+ /**
3840
+ * Fetches all available model pricing data
3841
+ * @returns Map of model names to pricing information
3842
+ */
3843
+ async fetchModelPricing() {
3844
+ return this.ensurePricingLoaded();
3845
+ }
3846
+ /**
3847
+ * Gets pricing information for a specific model with fallback matching
3848
+ * Tries exact match first, then provider prefixes, then partial matches
3849
+ * @param modelName - Name of the model to get pricing for
3850
+ * @returns Model pricing information or null if not found
3851
+ */
3852
+ async getModelPricing(modelName) {
3853
+ const pricing = await this.ensurePricingLoaded();
3854
+ const directMatch = pricing.get(modelName);
3855
+ if (directMatch != null) return directMatch;
3856
+ const variations = [
3857
+ modelName,
3858
+ `anthropic/${modelName}`,
3859
+ `claude-3-5-${modelName}`,
3860
+ `claude-3-${modelName}`,
3861
+ `claude-${modelName}`
3862
+ ];
3863
+ for (const variant of variations) {
3864
+ const match = pricing.get(variant);
3865
+ if (match != null) return match;
3866
+ }
3867
+ const lowerModel = modelName.toLowerCase();
3868
+ for (const [key, value] of pricing) if (key.toLowerCase().includes(lowerModel) || lowerModel.includes(key.toLowerCase())) return value;
3869
+ return null;
3870
+ }
3871
+ /**
3872
+ * Calculates the cost for given token usage and model
3873
+ * @param tokens - Token usage breakdown
3874
+ * @param tokens.input_tokens - Number of input tokens
3875
+ * @param tokens.output_tokens - Number of output tokens
3876
+ * @param tokens.cache_creation_input_tokens - Number of cache creation tokens
3877
+ * @param tokens.cache_read_input_tokens - Number of cache read tokens
3878
+ * @param modelName - Name of the model used
3879
+ * @returns Total cost in USD
3880
+ */
3881
+ async calculateCostFromTokens(tokens, modelName) {
3882
+ const pricing = await this.getModelPricing(modelName);
3883
+ if (pricing == null) return 0;
3884
+ return this.calculateCostFromPricing(tokens, pricing);
3885
+ }
3886
+ /**
3887
+ * Calculates cost from token usage and pricing information
3888
+ * @param tokens - Token usage breakdown
3889
+ * @param tokens.input_tokens - Number of input tokens
3890
+ * @param tokens.output_tokens - Number of output tokens
3891
+ * @param tokens.cache_creation_input_tokens - Number of cache creation tokens
3892
+ * @param tokens.cache_read_input_tokens - Number of cache read tokens
3893
+ * @param pricing - Model pricing rates
3894
+ * @returns Total cost in USD
3895
+ */
3896
+ calculateCostFromPricing(tokens, pricing) {
3897
+ let cost = 0;
3898
+ if (pricing.input_cost_per_token != null) cost += tokens.input_tokens * pricing.input_cost_per_token;
3899
+ if (pricing.output_cost_per_token != null) cost += tokens.output_tokens * pricing.output_cost_per_token;
3900
+ 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;
3901
+ 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;
3902
+ return cost;
3903
+ }
3904
+ };
3905
+ export { CostModes, PricingFetcher, SortOrders, ZodFirstPartyTypeKind, ZodOptional, ZodType, __commonJSMin, __require, __toESM, arrayType, booleanType, dateSchema, discriminatedUnionType, enumType, literalType, numberType, objectType, optionalType, recordType, require_usingCtx, stringType, unionType, unknownType };
@@ -0,0 +1,188 @@
1
+ import { z } from "zod";
2
+
3
+ //#region node_modules/type-fest/source/observable-like.d.ts
4
+ declare global {
5
+ // eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
6
+ interface SymbolConstructor {
7
+ readonly observable: symbol;
8
+ }
9
+ }
10
+
11
+ /**
12
+ @remarks
13
+ The TC39 observable proposal defines a `closed` property, but some implementations (such as xstream) do not as of 10/08/2021.
14
+ As well, some guidance on making an `Observable` to not include `closed` property.
15
+ @see https://github.com/tc39/proposal-observable/blob/master/src/Observable.js#L129-L130
16
+ @see https://github.com/staltz/xstream/blob/6c22580c1d84d69773ee4b0905df44ad464955b3/src/index.ts#L79-L85
17
+ @see https://github.com/benlesh/symbol-observable#making-an-object-observable
18
+
19
+ @category Observable
20
+ */
21
+
22
+ //#endregion
23
+ //#region node_modules/type-fest/source/tuple-to-union.d.ts
24
+ /**
25
+ Convert a tuple/array into a union type of its elements.
26
+
27
+ This can be useful when you have a fixed set of allowed values and want a type defining only the allowed values, but do not want to repeat yourself.
28
+
29
+ @example
30
+ ```
31
+ import type {TupleToUnion} from 'type-fest';
32
+
33
+ const destinations = ['a', 'b', 'c'] as const;
34
+
35
+ type Destination = TupleToUnion<typeof destinations>;
36
+ //=> 'a' | 'b' | 'c'
37
+
38
+ function verifyDestination(destination: unknown): destination is Destination {
39
+ return destinations.includes(destination as any);
40
+ }
41
+
42
+ type RequestBody = {
43
+ deliverTo: Destination;
44
+ };
45
+
46
+ function verifyRequestBody(body: unknown): body is RequestBody {
47
+ const deliverTo = (body as any).deliverTo;
48
+ return typeof body === 'object' && body !== null && verifyDestination(deliverTo);
49
+ }
50
+ ```
51
+
52
+ Alternatively, you may use `typeof destinations[number]`. If `destinations` is a tuple, there is no difference. However if `destinations` is a string, the resulting type will the union of the characters in the string. Other types of `destinations` may result in a compile error. In comparison, TupleToUnion will return `never` if a tuple is not provided.
53
+
54
+ @example
55
+ ```
56
+ const destinations = ['a', 'b', 'c'] as const;
57
+
58
+ type Destination = typeof destinations[number];
59
+ //=> 'a' | 'b' | 'c'
60
+
61
+ const erroringType = new Set(['a', 'b', 'c']);
62
+
63
+ type ErroringType = typeof erroringType[number];
64
+ //=> Type 'Set<string>' has no matching index signature for type 'number'. ts(2537)
65
+
66
+ const numberBool: { [n: number]: boolean } = { 1: true };
67
+
68
+ type NumberBool = typeof numberBool[number];
69
+ //=> boolean
70
+ ```
71
+
72
+ @category Array
73
+ */
74
+ type TupleToUnion<ArrayType> = ArrayType extends readonly unknown[] ? ArrayType[number] : never;
75
+ //#endregion
76
+ //#region src/types.internal.d.ts
77
+ /**
78
+ * Available cost calculation modes
79
+ * - auto: Use pre-calculated costs when available, otherwise calculate from tokens
80
+ * - calculate: Always calculate costs from token counts using model pricing
81
+ * - display: Always use pre-calculated costs, show 0 for missing costs
82
+ */
83
+ declare const CostModes: readonly ["auto", "calculate", "display"];
84
+ /**
85
+ * Union type for cost calculation modes
86
+ */
87
+ type CostMode = TupleToUnion<typeof CostModes>;
88
+ /**
89
+ * Available sort orders for data presentation
90
+ */
91
+ declare const SortOrders: readonly ["desc", "asc"];
92
+ /**
93
+ * Union type for sort order options
94
+ */
95
+ type SortOrder = TupleToUnion<typeof SortOrders>;
96
+ /**
97
+ * Zod schema for model pricing information from LiteLLM
98
+ */
99
+ declare const modelPricingSchema: z.ZodObject<{
100
+ input_cost_per_token: z.ZodOptional<z.ZodNumber>;
101
+ output_cost_per_token: z.ZodOptional<z.ZodNumber>;
102
+ cache_creation_input_token_cost: z.ZodOptional<z.ZodNumber>;
103
+ cache_read_input_token_cost: z.ZodOptional<z.ZodNumber>;
104
+ }, "strip", z.ZodTypeAny, {
105
+ input_cost_per_token?: number | undefined;
106
+ output_cost_per_token?: number | undefined;
107
+ cache_creation_input_token_cost?: number | undefined;
108
+ cache_read_input_token_cost?: number | undefined;
109
+ }, {
110
+ input_cost_per_token?: number | undefined;
111
+ output_cost_per_token?: number | undefined;
112
+ cache_creation_input_token_cost?: number | undefined;
113
+ cache_read_input_token_cost?: number | undefined;
114
+ }>;
115
+ /**
116
+ * Type definition for model pricing information
117
+ */
118
+ type ModelPricing = z.infer<typeof modelPricingSchema>;
119
+ //#endregion
120
+ //#region src/pricing-fetcher.d.ts
121
+ /**
122
+ * Fetches and caches model pricing information from LiteLLM
123
+ * Implements Disposable pattern for automatic resource cleanup
124
+ */
125
+ declare class PricingFetcher implements Disposable {
126
+ private cachedPricing;
127
+ private readonly offline;
128
+ /**
129
+ * Creates a new PricingFetcher instance
130
+ * @param offline - Whether to use pre-fetched pricing data instead of fetching from API
131
+ */
132
+ constructor(offline?: boolean);
133
+ /**
134
+ * Implements Disposable interface for automatic cleanup
135
+ */
136
+ [Symbol.dispose](): void;
137
+ /**
138
+ * Clears the cached pricing data
139
+ */
140
+ clearCache(): void;
141
+ private ensurePricingLoaded;
142
+ /**
143
+ * Fetches all available model pricing data
144
+ * @returns Map of model names to pricing information
145
+ */
146
+ fetchModelPricing(): Promise<Map<string, ModelPricing>>;
147
+ /**
148
+ * Gets pricing information for a specific model with fallback matching
149
+ * Tries exact match first, then provider prefixes, then partial matches
150
+ * @param modelName - Name of the model to get pricing for
151
+ * @returns Model pricing information or null if not found
152
+ */
153
+ getModelPricing(modelName: string): Promise<ModelPricing | null>;
154
+ /**
155
+ * Calculates the cost for given token usage and model
156
+ * @param tokens - Token usage breakdown
157
+ * @param tokens.input_tokens - Number of input tokens
158
+ * @param tokens.output_tokens - Number of output tokens
159
+ * @param tokens.cache_creation_input_tokens - Number of cache creation tokens
160
+ * @param tokens.cache_read_input_tokens - Number of cache read tokens
161
+ * @param modelName - Name of the model used
162
+ * @returns Total cost in USD
163
+ */
164
+ calculateCostFromTokens(tokens: {
165
+ input_tokens: number;
166
+ output_tokens: number;
167
+ cache_creation_input_tokens?: number;
168
+ cache_read_input_tokens?: number;
169
+ }, modelName: string): Promise<number>;
170
+ /**
171
+ * Calculates cost from token usage and pricing information
172
+ * @param tokens - Token usage breakdown
173
+ * @param tokens.input_tokens - Number of input tokens
174
+ * @param tokens.output_tokens - Number of output tokens
175
+ * @param tokens.cache_creation_input_tokens - Number of cache creation tokens
176
+ * @param tokens.cache_read_input_tokens - Number of cache read tokens
177
+ * @param pricing - Model pricing rates
178
+ * @returns Total cost in USD
179
+ */
180
+ calculateCostFromPricing(tokens: {
181
+ input_tokens: number;
182
+ output_tokens: number;
183
+ cache_creation_input_tokens?: number;
184
+ cache_read_input_tokens?: number;
185
+ }, pricing: ModelPricing): number;
186
+ }
187
+ //#endregion
188
+ export { CostMode, PricingFetcher, SortOrder };
@@ -1,2 +1,2 @@
1
- import { PricingFetcher } from "./pricing-fetcher-DHaTs-k2.js";
1
+ import { PricingFetcher } from "./pricing-fetcher-BkOpRIdx.js";
2
2
  export { PricingFetcher };
@@ -1,5 +1,3 @@
1
- import { PricingFetcher } from "./pricing-fetcher-BtW4MVG7.js";
2
- import "./dist-DCvt9hEv.js";
3
- import "./logger-E_Utl_fr.js";
4
-
5
- export { PricingFetcher };
1
+ import { PricingFetcher } from "./pricing-fetcher-3m6_Ejp8.js";
2
+ import "./logger-CTFDCX5W.js";
3
+ export { PricingFetcher };
@@ -1,8 +1,6 @@
1
1
  import process$1, { stdin, stdout } from "node:process";
2
2
  import { WriteStream } from "node:tty";
3
3
  import f from "node:readline";
4
-
5
- //#region node_modules/consola/dist/chunks/prompt.mjs
6
4
  function getDefaultExportFromCjs(x$1) {
7
5
  return x$1 && x$1.__esModule && Object.prototype.hasOwnProperty.call(x$1, "default") ? x$1["default"] : x$1;
8
6
  }
@@ -847,6 +845,4 @@ async function prompt(message, opts = {}) {
847
845
  }).then(handleCancel);
848
846
  throw new Error(`Unknown prompt type: ${opts.type}`);
849
847
  }
850
-
851
- //#endregion
852
- export { prompt };
848
+ export { prompt };