ccusage 0.6.1 → 0.7.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 +55 -22
- package/dist/calculate-cost.d.ts +2 -2
- package/dist/{data-loader-DP5qBPn6.js → data-loader-nOFcMg_V.js} +720 -171
- package/dist/data-loader-pCzn-ryX.d.ts +180 -0
- package/dist/data-loader.d.ts +3 -3
- package/dist/data-loader.js +5 -5
- package/dist/{debug-C_5Qx11m.js → debug-Bttss7TN.js} +42 -37
- package/dist/debug.js +5 -5
- package/dist/{dist-C0-Tf5eD.js → dist-BEQ1tJCL.js} +1 -18
- package/dist/{dist-LwbOR2Yw.js → dist-DAarI-SJ.js} +1 -1
- package/dist/{effect-WSjEuzC9-CJfWUy0j.js → effect-WSjEuzC9-ChJ5OQQf.js} +1 -1
- package/dist/{index-CISmcbXk-DCA05NUL.js → index-CISmcbXk-x9eVmhGM.js} +4 -4
- package/dist/index.js +84 -137
- package/dist/{logger-DsQC4OvA.js → logger-BPjA3VFO.js} +1 -1
- package/dist/logger.js +1 -1
- package/dist/{mcp-BQdv12mr.js → mcp-DCEVbd8C.js} +15 -9
- package/dist/mcp.d.ts +2 -2
- package/dist/mcp.js +6 -6
- package/dist/pricing-fetcher-CAeJvZnF.js +79 -0
- package/dist/{pricing-fetcher-CfEgfzSr.d.ts → pricing-fetcher-Dq-OLBp4.d.ts} +22 -10
- package/dist/pricing-fetcher.d.ts +2 -2
- package/dist/pricing-fetcher.js +4 -4
- package/dist/{sury-DmrZ3_Oj-CCL_DlTt.js → sury-DmrZ3_Oj-l0qqtY-f.js} +1 -1
- package/dist/valibot-CQk-M5rL-BNHzwpA0.js +10 -0
- package/dist/{zod-Db63SLXj-Dyc_OWjq.js → zod-Db63SLXj-N1oN-yiY.js} +1 -1
- package/package.json +1 -1
- package/dist/data-loader-VdEcqJHc.d.ts +0 -71
- package/dist/pricing-fetcher-BPUgMrB_.js +0 -60
- package/dist/valibot-CQk-M5rL-CkjrLVu1.js +0 -10
|
@@ -1567,14 +1567,26 @@ declare const ModelPricingSchema: ObjectSchema<{
|
|
|
1567
1567
|
readonly cache_read_input_token_cost: OptionalSchema<NumberSchema<undefined>, undefined>;
|
|
1568
1568
|
}, undefined>;
|
|
1569
1569
|
type ModelPricing = InferOutput<typeof ModelPricingSchema>;
|
|
1570
|
-
declare
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1570
|
+
declare class PricingFetcher implements Disposable {
|
|
1571
|
+
private cachedPricing;
|
|
1572
|
+
constructor();
|
|
1573
|
+
[Symbol.dispose](): void;
|
|
1574
|
+
clearCache(): void;
|
|
1575
|
+
private ensurePricingLoaded;
|
|
1576
|
+
fetchModelPricing(): Promise<Map<string, ModelPricing>>;
|
|
1577
|
+
getModelPricing(modelName: string): Promise<ModelPricing | null>;
|
|
1578
|
+
calculateCostFromTokens(tokens: {
|
|
1579
|
+
input_tokens: number;
|
|
1580
|
+
output_tokens: number;
|
|
1581
|
+
cache_creation_input_tokens?: number;
|
|
1582
|
+
cache_read_input_tokens?: number;
|
|
1583
|
+
}, modelName: string): Promise<number>;
|
|
1584
|
+
calculateCostFromPricing(tokens: {
|
|
1585
|
+
input_tokens: number;
|
|
1586
|
+
output_tokens: number;
|
|
1587
|
+
cache_creation_input_tokens?: number;
|
|
1588
|
+
cache_read_input_tokens?: number;
|
|
1589
|
+
}, pricing: ModelPricing): number;
|
|
1590
|
+
}
|
|
1579
1591
|
//#endregion
|
|
1580
|
-
export { ArraySchema, InferOutput, ModelPricing, NumberSchema, ObjectSchema, OptionalSchema, RegexAction, SchemaWithPipe, StringSchema
|
|
1592
|
+
export { ArraySchema, InferOutput, ModelPricing, NumberSchema, ObjectSchema, OptionalSchema, PricingFetcher, RegexAction, SchemaWithPipe, StringSchema };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ModelPricing,
|
|
2
|
-
export { ModelPricing,
|
|
1
|
+
import { ModelPricing, PricingFetcher } from "./pricing-fetcher-Dq-OLBp4.js";
|
|
2
|
+
export { ModelPricing, PricingFetcher };
|
package/dist/pricing-fetcher.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "./dist-
|
|
2
|
-
import "./logger-
|
|
3
|
-
import {
|
|
1
|
+
import "./dist-BEQ1tJCL.js";
|
|
2
|
+
import "./logger-BPjA3VFO.js";
|
|
3
|
+
import { PricingFetcher } from "./pricing-fetcher-CAeJvZnF.js";
|
|
4
4
|
|
|
5
|
-
export {
|
|
5
|
+
export { PricingFetcher };
|
|
@@ -0,0 +1,10 @@
|
|
|
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 };
|
package/package.json
CHANGED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { ArraySchema, InferOutput, ModelPricing, NumberSchema, ObjectSchema, OptionalSchema, RegexAction, SchemaWithPipe, StringSchema } from "./pricing-fetcher-CfEgfzSr.js";
|
|
2
|
-
|
|
3
|
-
//#region src/types.internal.d.ts
|
|
4
|
-
declare const CostModes: readonly ["auto", "calculate", "display"];
|
|
5
|
-
type CostMode = (typeof CostModes)[number];
|
|
6
|
-
declare const SortOrders: readonly ["desc", "asc"];
|
|
7
|
-
type SortOrder = (typeof SortOrders)[number];
|
|
8
|
-
//#endregion
|
|
9
|
-
//#region src/data-loader.d.ts
|
|
10
|
-
declare function getDefaultClaudePath(): string;
|
|
11
|
-
declare const UsageDataSchema: ObjectSchema<{
|
|
12
|
-
readonly timestamp: StringSchema<undefined>;
|
|
13
|
-
readonly version: OptionalSchema<StringSchema<undefined>, undefined>;
|
|
14
|
-
readonly message: ObjectSchema<{
|
|
15
|
-
readonly usage: ObjectSchema<{
|
|
16
|
-
readonly input_tokens: NumberSchema<undefined>;
|
|
17
|
-
readonly output_tokens: NumberSchema<undefined>;
|
|
18
|
-
readonly cache_creation_input_tokens: OptionalSchema<NumberSchema<undefined>, undefined>;
|
|
19
|
-
readonly cache_read_input_tokens: OptionalSchema<NumberSchema<undefined>, undefined>;
|
|
20
|
-
}, undefined>;
|
|
21
|
-
readonly model: OptionalSchema<StringSchema<undefined>, undefined>;
|
|
22
|
-
}, undefined>;
|
|
23
|
-
readonly costUSD: OptionalSchema<NumberSchema<undefined>, undefined>;
|
|
24
|
-
}, undefined>;
|
|
25
|
-
type UsageData = InferOutput<typeof UsageDataSchema>;
|
|
26
|
-
declare const DailyUsageSchema: ObjectSchema<{
|
|
27
|
-
readonly date: SchemaWithPipe<readonly [StringSchema<undefined>, RegexAction<string, undefined>]>;
|
|
28
|
-
readonly inputTokens: NumberSchema<undefined>;
|
|
29
|
-
readonly outputTokens: NumberSchema<undefined>;
|
|
30
|
-
readonly cacheCreationTokens: NumberSchema<undefined>;
|
|
31
|
-
readonly cacheReadTokens: NumberSchema<undefined>;
|
|
32
|
-
readonly totalCost: NumberSchema<undefined>;
|
|
33
|
-
}, undefined>;
|
|
34
|
-
type DailyUsage = InferOutput<typeof DailyUsageSchema>;
|
|
35
|
-
declare const SessionUsageSchema: ObjectSchema<{
|
|
36
|
-
readonly sessionId: StringSchema<undefined>;
|
|
37
|
-
readonly projectPath: StringSchema<undefined>;
|
|
38
|
-
readonly inputTokens: NumberSchema<undefined>;
|
|
39
|
-
readonly outputTokens: NumberSchema<undefined>;
|
|
40
|
-
readonly cacheCreationTokens: NumberSchema<undefined>;
|
|
41
|
-
readonly cacheReadTokens: NumberSchema<undefined>;
|
|
42
|
-
readonly totalCost: NumberSchema<undefined>;
|
|
43
|
-
readonly lastActivity: StringSchema<undefined>;
|
|
44
|
-
readonly versions: ArraySchema<StringSchema<undefined>, undefined>;
|
|
45
|
-
}, undefined>;
|
|
46
|
-
type SessionUsage = InferOutput<typeof SessionUsageSchema>;
|
|
47
|
-
declare const MonthlyUsageSchema: ObjectSchema<{
|
|
48
|
-
readonly month: SchemaWithPipe<readonly [StringSchema<undefined>, RegexAction<string, undefined>]>;
|
|
49
|
-
readonly inputTokens: NumberSchema<undefined>;
|
|
50
|
-
readonly outputTokens: NumberSchema<undefined>;
|
|
51
|
-
readonly cacheCreationTokens: NumberSchema<undefined>;
|
|
52
|
-
readonly cacheReadTokens: NumberSchema<undefined>;
|
|
53
|
-
readonly totalCost: NumberSchema<undefined>;
|
|
54
|
-
}, undefined>;
|
|
55
|
-
type MonthlyUsage = InferOutput<typeof MonthlyUsageSchema>;
|
|
56
|
-
declare function formatDate(dateStr: string): string;
|
|
57
|
-
declare function calculateCostForEntry(data: UsageData, mode: CostMode, modelPricing: Record<string, ModelPricing>): number;
|
|
58
|
-
type DateFilter = {
|
|
59
|
-
since?: string;
|
|
60
|
-
until?: string;
|
|
61
|
-
};
|
|
62
|
-
type LoadOptions = {
|
|
63
|
-
claudePath?: string;
|
|
64
|
-
mode?: CostMode;
|
|
65
|
-
order?: SortOrder;
|
|
66
|
-
} & DateFilter;
|
|
67
|
-
declare function loadDailyUsageData(options?: LoadOptions): Promise<DailyUsage[]>;
|
|
68
|
-
declare function loadSessionData(options?: LoadOptions): Promise<SessionUsage[]>;
|
|
69
|
-
declare function loadMonthlyUsageData(options?: LoadOptions): Promise<MonthlyUsage[]>;
|
|
70
|
-
//#endregion
|
|
71
|
-
export { DailyUsage, DailyUsageSchema, DateFilter, LoadOptions, MonthlyUsage, MonthlyUsageSchema, SessionUsage, SessionUsageSchema, UsageData, UsageDataSchema, calculateCostForEntry, formatDate, getDefaultClaudePath, loadDailyUsageData, loadMonthlyUsageData, loadSessionData };
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { number, object, optional, parse } from "./dist-C0-Tf5eD.js";
|
|
2
|
-
import { logger } from "./logger-DsQC4OvA.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
|
-
let cachedPricing = null;
|
|
13
|
-
function clearPricingCache() {
|
|
14
|
-
cachedPricing = null;
|
|
15
|
-
}
|
|
16
|
-
async function fetchModelPricing() {
|
|
17
|
-
if (cachedPricing != null) return cachedPricing;
|
|
18
|
-
try {
|
|
19
|
-
logger.warn("Fetching latest model pricing from LiteLLM...");
|
|
20
|
-
const response = await fetch(LITELLM_PRICING_URL);
|
|
21
|
-
if (!response.ok) throw new Error(`Failed to fetch pricing data: ${response.statusText}`);
|
|
22
|
-
const data = await response.json();
|
|
23
|
-
const pricing = {};
|
|
24
|
-
for (const [modelName, modelData] of Object.entries(data)) if (typeof modelData === "object" && modelData !== null) try {
|
|
25
|
-
const parsed = parse(ModelPricingSchema, modelData);
|
|
26
|
-
pricing[modelName] = parsed;
|
|
27
|
-
} catch {}
|
|
28
|
-
cachedPricing = pricing;
|
|
29
|
-
logger.info(`Loaded pricing for ${Object.keys(pricing).length} models`);
|
|
30
|
-
return pricing;
|
|
31
|
-
} catch (error) {
|
|
32
|
-
logger.error("Failed to fetch model pricing:", error);
|
|
33
|
-
throw new Error("Could not fetch model pricing data");
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
function getModelPricing(modelName, pricing) {
|
|
37
|
-
if (pricing[modelName] != null) return pricing[modelName];
|
|
38
|
-
const variations = [
|
|
39
|
-
modelName,
|
|
40
|
-
`anthropic/${modelName}`,
|
|
41
|
-
`claude-3-5-${modelName}`,
|
|
42
|
-
`claude-3-${modelName}`,
|
|
43
|
-
`claude-${modelName}`
|
|
44
|
-
];
|
|
45
|
-
for (const variant of variations) if (pricing[variant] != null) return pricing[variant];
|
|
46
|
-
const lowerModel = modelName.toLowerCase();
|
|
47
|
-
for (const [key, value] of Object.entries(pricing)) if (key.toLowerCase().includes(lowerModel) || lowerModel.includes(key.toLowerCase())) return value;
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
function calculateCostFromTokens(tokens, pricing) {
|
|
51
|
-
let cost = 0;
|
|
52
|
-
if (pricing.input_cost_per_token != null) cost += tokens.input_tokens * pricing.input_cost_per_token;
|
|
53
|
-
if (pricing.output_cost_per_token != null) cost += tokens.output_tokens * pricing.output_cost_per_token;
|
|
54
|
-
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;
|
|
55
|
-
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;
|
|
56
|
-
return cost;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
//#endregion
|
|
60
|
-
export { calculateCostFromTokens, clearPricingCache, fetchModelPricing, getModelPricing };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { tryImport } from "./index-CISmcbXk-DCA05NUL.js";
|
|
2
|
-
|
|
3
|
-
//#region node_modules/xsschema/dist/valibot-CQk-M5rL.js
|
|
4
|
-
const getToJsonSchemaFn = async () => {
|
|
5
|
-
const { toJsonSchema } = await tryImport(import("./dist-LwbOR2Yw.js"), "@valibot/to-json-schema");
|
|
6
|
-
return (schema) => toJsonSchema(schema);
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
//#endregion
|
|
10
|
-
export { getToJsonSchemaFn };
|