ccusage 0.7.0 → 9.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.
- package/README.md +34 -14
- package/dist/calculate-cost.d.ts +2 -2
- package/dist/chunk-BLXvPPr8.js +30 -0
- package/dist/{data-loader-nOFcMg_V.js → data-loader-Ca8k_uX0.js} +301 -293
- package/dist/{data-loader-pCzn-ryX.d.ts → data-loader-OGaMjZTD.d.ts} +24 -80
- package/dist/data-loader.d.ts +3 -3
- package/dist/data-loader.js +5 -5
- package/dist/{debug-Bttss7TN.js → debug-zCcXwR8p.js} +5 -4
- package/dist/debug.js +5 -5
- package/dist/{dist-DAarI-SJ.js → dist-BZzwBtZs.js} +1 -1
- package/dist/{effect-WSjEuzC9-ChJ5OQQf.js → effect-WSjEuzC9-DHMVzzyB.js} +1 -1
- package/dist/{esm-Dqsc1zmX.js → esm-BU3FhOe-.js} +1 -1
- package/dist/{index-CISmcbXk-x9eVmhGM.js → index-CISmcbXk-CW1Gj6Ab.js} +5 -5
- package/dist/index.js +204 -1765
- package/dist/{logger-BPjA3VFO.js → logger-DKw-DPXD.js} +5 -5
- package/dist/logger.js +1 -1
- package/dist/{mcp-DCEVbd8C.js → mcp-BRFYI5rd.js} +44 -52
- package/dist/mcp.d.ts +2 -2
- package/dist/mcp.js +7 -7
- package/dist/{pricing-fetcher-Dq-OLBp4.d.ts → pricing-fetcher-BkSZh4lR.d.ts} +83 -3
- package/dist/pricing-fetcher-BlxDpqFj.js +205 -0
- package/dist/pricing-fetcher.d.ts +2 -2
- package/dist/pricing-fetcher.js +3 -3
- package/dist/{prompt-DljZqwMa.js → prompt-DtZgx4wU.js} +2 -2
- package/dist/{sury-DmrZ3_Oj-l0qqtY-f.js → sury-DmrZ3_Oj-Cpjsc2Lm.js} +1 -1
- package/dist/utils.table-DRzF8vZJ.js +1838 -0
- package/dist/utils.table.d.ts +24 -0
- package/dist/utils.table.js +3 -0
- package/dist/valibot-CQk-M5rL-BcaCeUrF.js +10 -0
- package/dist/{zod-Db63SLXj-N1oN-yiY.js → zod-Db63SLXj-BIXn64AP.js} +3 -3
- package/package.json +2 -1
- package/dist/pricing-fetcher-CAeJvZnF.js +0 -79
- package/dist/valibot-CQk-M5rL-BNHzwpA0.js +0 -10
- /package/dist/{arktype-C-GObzDh-Bx7Fdrqj.js → arktype-C-GObzDh-CNoBqQrr.js} +0 -0
- /package/dist/{core-B0ovMhJe.js → core-DHCbAXJf.js} +0 -0
- /package/dist/{dist-BEQ1tJCL.js → dist-DCvt9hEv.js} +0 -0
- /package/dist/{types-DS8M8QF_.js → types-BlyCnKwN.js} +0 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region src/utils.table.d.ts
|
|
2
|
+
type TableRow = (string | number)[];
|
|
3
|
+
type TableOptions = {
|
|
4
|
+
head: string[];
|
|
5
|
+
colAligns?: ('left' | 'right' | 'center')[];
|
|
6
|
+
style?: {
|
|
7
|
+
head?: string[];
|
|
8
|
+
};
|
|
9
|
+
dateFormatter?: (dateStr: string) => string;
|
|
10
|
+
};
|
|
11
|
+
declare class ResponsiveTable {
|
|
12
|
+
private head;
|
|
13
|
+
private rows;
|
|
14
|
+
private colAligns;
|
|
15
|
+
private style?;
|
|
16
|
+
private dateFormatter?;
|
|
17
|
+
constructor(options: TableOptions);
|
|
18
|
+
push(row: TableRow): void;
|
|
19
|
+
toString(): string;
|
|
20
|
+
private isSeparatorRow;
|
|
21
|
+
private isDateString;
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { ResponsiveTable };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { tryImport } from "./index-CISmcbXk-CW1Gj6Ab.js";
|
|
2
|
+
|
|
3
|
+
//#region node_modules/xsschema/dist/valibot-CQk-M5rL.js
|
|
4
|
+
const getToJsonSchemaFn = async () => {
|
|
5
|
+
const { toJsonSchema } = await tryImport(import("./dist-BZzwBtZs.js"), "@valibot/to-json-schema");
|
|
6
|
+
return (schema) => toJsonSchema(schema);
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
//#endregion
|
|
10
|
+
export { getToJsonSchemaFn };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { missingDependenciesUrl } from "./index-CISmcbXk-
|
|
1
|
+
import { missingDependenciesUrl } from "./index-CISmcbXk-CW1Gj6Ab.js";
|
|
2
2
|
|
|
3
3
|
//#region node_modules/xsschema/dist/zod-Db63SLXj.js
|
|
4
4
|
const getToJsonSchemaFn = async () => {
|
|
@@ -9,13 +9,13 @@ const getToJsonSchemaFn = async () => {
|
|
|
9
9
|
throw new Error(`xsschema: Missing zod v3 dependencies "zod-to-json-schema". see ${missingDependenciesUrl}`);
|
|
10
10
|
};
|
|
11
11
|
try {
|
|
12
|
-
const { toJSONSchema } = await import("./core-
|
|
12
|
+
const { toJSONSchema } = await import("./core-DHCbAXJf.js");
|
|
13
13
|
zodV4toJSONSchema = toJSONSchema;
|
|
14
14
|
} catch (err) {
|
|
15
15
|
if (err instanceof Error) console.error(err.message);
|
|
16
16
|
}
|
|
17
17
|
try {
|
|
18
|
-
const { zodToJsonSchema } = await import("./esm-
|
|
18
|
+
const { zodToJsonSchema } = await import("./esm-BU3FhOe-.js");
|
|
19
19
|
zodV3ToJSONSchema = zodToJsonSchema;
|
|
20
20
|
} catch (err) {
|
|
21
21
|
if (err instanceof Error) console.error(err.message);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ccusage",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "9.0.0",
|
|
5
5
|
"description": "Usage analysis tool for Claude Code",
|
|
6
6
|
"author": "ryoppippi",
|
|
7
7
|
"license": "MIT",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"./logger": "./dist/logger.js",
|
|
23
23
|
"./mcp": "./dist/mcp.js",
|
|
24
24
|
"./pricing-fetcher": "./dist/pricing-fetcher.js",
|
|
25
|
+
"./utils.table": "./dist/utils.table.js",
|
|
25
26
|
"./package.json": "./package.json"
|
|
26
27
|
},
|
|
27
28
|
"main": "./dist/index.js",
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { number, object, optional, safeParse } from "./dist-BEQ1tJCL.js";
|
|
2
|
-
import { logger } from "./logger-BPjA3VFO.js";
|
|
3
|
-
|
|
4
|
-
//#region src/pricing-fetcher.ts
|
|
5
|
-
const ModelPricingSchema = object({
|
|
6
|
-
input_cost_per_token: optional(number()),
|
|
7
|
-
output_cost_per_token: optional(number()),
|
|
8
|
-
cache_creation_input_token_cost: optional(number()),
|
|
9
|
-
cache_read_input_token_cost: optional(number())
|
|
10
|
-
});
|
|
11
|
-
const LITELLM_PRICING_URL = "https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json";
|
|
12
|
-
var PricingFetcher = class {
|
|
13
|
-
cachedPricing = null;
|
|
14
|
-
constructor() {}
|
|
15
|
-
[Symbol.dispose]() {
|
|
16
|
-
this.clearCache();
|
|
17
|
-
}
|
|
18
|
-
clearCache() {
|
|
19
|
-
this.cachedPricing = null;
|
|
20
|
-
}
|
|
21
|
-
async ensurePricingLoaded() {
|
|
22
|
-
if (this.cachedPricing != null) return this.cachedPricing;
|
|
23
|
-
try {
|
|
24
|
-
logger.warn("Fetching latest model pricing from LiteLLM...");
|
|
25
|
-
const response = await fetch(LITELLM_PRICING_URL);
|
|
26
|
-
if (!response.ok) throw new Error(`Failed to fetch pricing data: ${response.statusText}`);
|
|
27
|
-
const data = await response.json();
|
|
28
|
-
const pricing = /* @__PURE__ */ new Map();
|
|
29
|
-
for (const [modelName, modelData] of Object.entries(data)) if (typeof modelData === "object" && modelData !== null) {
|
|
30
|
-
const parsed = safeParse(ModelPricingSchema, modelData);
|
|
31
|
-
if (parsed.success) pricing.set(modelName, parsed.output);
|
|
32
|
-
}
|
|
33
|
-
this.cachedPricing = pricing;
|
|
34
|
-
logger.info(`Loaded pricing for ${pricing.size} models`);
|
|
35
|
-
return pricing;
|
|
36
|
-
} catch (error) {
|
|
37
|
-
logger.error("Failed to fetch model pricing:", error);
|
|
38
|
-
throw new Error("Could not fetch model pricing data");
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
async fetchModelPricing() {
|
|
42
|
-
return this.ensurePricingLoaded();
|
|
43
|
-
}
|
|
44
|
-
async getModelPricing(modelName) {
|
|
45
|
-
const pricing = await this.ensurePricingLoaded();
|
|
46
|
-
const directMatch = pricing.get(modelName);
|
|
47
|
-
if (directMatch != null) return directMatch;
|
|
48
|
-
const variations = [
|
|
49
|
-
modelName,
|
|
50
|
-
`anthropic/${modelName}`,
|
|
51
|
-
`claude-3-5-${modelName}`,
|
|
52
|
-
`claude-3-${modelName}`,
|
|
53
|
-
`claude-${modelName}`
|
|
54
|
-
];
|
|
55
|
-
for (const variant of variations) {
|
|
56
|
-
const match = pricing.get(variant);
|
|
57
|
-
if (match != null) return match;
|
|
58
|
-
}
|
|
59
|
-
const lowerModel = modelName.toLowerCase();
|
|
60
|
-
for (const [key, value] of pricing) if (key.toLowerCase().includes(lowerModel) || lowerModel.includes(key.toLowerCase())) return value;
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
async calculateCostFromTokens(tokens, modelName) {
|
|
64
|
-
const pricing = await this.getModelPricing(modelName);
|
|
65
|
-
if (pricing == null) return 0;
|
|
66
|
-
return this.calculateCostFromPricing(tokens, pricing);
|
|
67
|
-
}
|
|
68
|
-
calculateCostFromPricing(tokens, pricing) {
|
|
69
|
-
let cost = 0;
|
|
70
|
-
if (pricing.input_cost_per_token != null) cost += tokens.input_tokens * pricing.input_cost_per_token;
|
|
71
|
-
if (pricing.output_cost_per_token != null) cost += tokens.output_tokens * pricing.output_cost_per_token;
|
|
72
|
-
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;
|
|
73
|
-
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;
|
|
74
|
-
return cost;
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
//#endregion
|
|
79
|
-
export { PricingFetcher };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { tryImport } from "./index-CISmcbXk-x9eVmhGM.js";
|
|
2
|
-
|
|
3
|
-
//#region node_modules/xsschema/dist/valibot-CQk-M5rL.js
|
|
4
|
-
const getToJsonSchemaFn = async () => {
|
|
5
|
-
const { toJsonSchema } = await tryImport(import("./dist-DAarI-SJ.js"), "@valibot/to-json-schema");
|
|
6
|
-
return (schema) => toJsonSchema(schema);
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
//#endregion
|
|
10
|
-
export { getToJsonSchemaFn };
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|