ccusage 15.9.5 → 15.9.7
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/dist/{_types-C0oFKDO-.js → _types-BbEk8t2a.js} +4 -1
- package/dist/calculate-cost.d.ts +2 -2
- package/dist/calculate-cost.js +1 -1
- package/dist/{data-loader-BPepPoPg.d.ts → data-loader-BJnD_oR3.d.ts} +2 -2
- package/dist/{data-loader-Plh5X-UR.js → data-loader-G78wtKpU.js} +24 -11
- package/dist/data-loader.d.ts +2 -2
- package/dist/data-loader.js +4 -4
- package/dist/{debug-C4f2zPfQ.js → debug-BFlA56YT.js} +3 -3
- package/dist/debug.js +5 -5
- package/dist/index.js +90 -84
- package/dist/{logger-dT_AJeHG.js → logger-CHezuMoN.js} +1 -1
- package/dist/logger.js +1 -1
- package/dist/{mcp-DfY3l9w7.js → mcp-BEHYXSQT.js} +4 -4
- package/dist/mcp.d.ts +2 -2
- package/dist/mcp.js +5 -5
- package/dist/{pricing-fetcher-B5m_kEpz.d.ts → pricing-fetcher-BgDfBZ05.d.ts} +16 -0
- package/dist/{pricing-fetcher-CTYPN13Y.js → pricing-fetcher-CLjmfFHB.js} +79 -22
- package/dist/pricing-fetcher.d.ts +1 -1
- package/dist/pricing-fetcher.js +3 -3
- package/package.json +1 -1
|
@@ -3027,7 +3027,10 @@ const CostModes = [
|
|
|
3027
3027
|
input_cost_per_token: numberType().optional(),
|
|
3028
3028
|
output_cost_per_token: numberType().optional(),
|
|
3029
3029
|
cache_creation_input_token_cost: numberType().optional(),
|
|
3030
|
-
cache_read_input_token_cost: numberType().optional()
|
|
3030
|
+
cache_read_input_token_cost: numberType().optional(),
|
|
3031
|
+
max_tokens: numberType().optional(),
|
|
3032
|
+
max_input_tokens: numberType().optional(),
|
|
3033
|
+
max_output_tokens: numberType().optional()
|
|
3031
3034
|
}), statuslineHookJsonSchema = objectType({
|
|
3032
3035
|
session_id: stringType(),
|
|
3033
3036
|
transcript_path: stringType(),
|
package/dist/calculate-cost.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "./pricing-fetcher-
|
|
2
|
-
import { DailyUsage, MonthlyUsage, SessionUsage, WeeklyUsage } from "./data-loader-
|
|
1
|
+
import "./pricing-fetcher-BgDfBZ05.js";
|
|
2
|
+
import { DailyUsage, MonthlyUsage, SessionUsage, WeeklyUsage } from "./data-loader-BJnD_oR3.js";
|
|
3
3
|
|
|
4
4
|
//#region src/_token-utils.d.ts
|
|
5
5
|
|
package/dist/calculate-cost.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { getTotalTokens } from "./_token-utils-WjkbrjKv.js";
|
|
2
|
-
import "./_types-
|
|
2
|
+
import "./_types-BbEk8t2a.js";
|
|
3
3
|
import { calculateTotals, createTotalsObject } from "./calculate-cost-BDqO4yWA.js";
|
|
4
4
|
export { calculateTotals, createTotalsObject, getTotalTokens };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Bucket, CostMode, PricingFetcher, SortOrder, TupleToUnion } from "./pricing-fetcher-
|
|
1
|
+
import { Bucket, CostMode, PricingFetcher, SortOrder, TupleToUnion } from "./pricing-fetcher-BgDfBZ05.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
|
|
4
4
|
//#region src/_consts.d.ts
|
|
@@ -789,7 +789,7 @@ declare function loadBucketUsageData(groupingFn: (data: DailyUsage) => Bucket, o
|
|
|
789
789
|
* @param transcriptPath - Path to the transcript JSONL file
|
|
790
790
|
* @returns Object with context tokens info or null if unavailable
|
|
791
791
|
*/
|
|
792
|
-
declare function calculateContextTokens(transcriptPath: string): Promise<{
|
|
792
|
+
declare function calculateContextTokens(transcriptPath: string, modelId?: string, offline?: boolean): Promise<{
|
|
793
793
|
inputTokens: number;
|
|
794
794
|
percentage: number;
|
|
795
795
|
contextLimit: number;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { CLAUDE_CONFIG_DIR_ENV, CLAUDE_PROJECTS_DIR_NAME,
|
|
1
|
+
import { CLAUDE_CONFIG_DIR_ENV, CLAUDE_PROJECTS_DIR_NAME, CONTEXT_LOW_THRESHOLD_ENV, CONTEXT_MEDIUM_THRESHOLD_ENV, DEFAULT_CLAUDE_CODE_PATH, DEFAULT_CLAUDE_CONFIG_PATH, DEFAULT_CONTEXT_USAGE_THRESHOLDS, DEFAULT_RECENT_DAYS, PricingFetcher, USAGE_DATA_GLOB_PATTERN, USER_HOME_DIR, __commonJSMin, __require, __toESM, isFailure, isPromise, isSuccess, require_usingCtx } from "./pricing-fetcher-CLjmfFHB.js";
|
|
2
2
|
import { getTotalTokens } from "./_token-utils-WjkbrjKv.js";
|
|
3
|
-
import { activityDateSchema, arrayType, booleanType, createBucket, createDailyDate, createMonthlyDate, createProjectPath, createSessionId, createWeeklyDate, dailyDateSchema, isoTimestampSchema, messageIdSchema, modelNameSchema, monthlyDateSchema, numberType, objectType, projectPathSchema, requestIdSchema, sessionIdSchema, stringType, unionType, versionSchema, weeklyDateSchema } from "./_types-
|
|
4
|
-
import { logger } from "./logger-
|
|
3
|
+
import { activityDateSchema, arrayType, booleanType, createBucket, createDailyDate, createMonthlyDate, createProjectPath, createSessionId, createWeeklyDate, dailyDateSchema, isoTimestampSchema, messageIdSchema, modelNameSchema, monthlyDateSchema, numberType, objectType, projectPathSchema, requestIdSchema, sessionIdSchema, stringType, unionType, versionSchema, weeklyDateSchema } from "./_types-BbEk8t2a.js";
|
|
4
|
+
import { logger } from "./logger-CHezuMoN.js";
|
|
5
5
|
import a, { readFile } from "node:fs/promises";
|
|
6
6
|
import path, { posix } from "node:path";
|
|
7
7
|
import process$1 from "node:process";
|
|
@@ -2624,7 +2624,7 @@ async function loadWeeklyUsageData(options) {
|
|
|
2624
2624
|
async function loadSessionUsageById(sessionId, options) {
|
|
2625
2625
|
try {
|
|
2626
2626
|
var _usingCtx4 = (0, import_usingCtx.default)();
|
|
2627
|
-
const claudePaths = getClaudePaths(), patterns = claudePaths.map((p) => path.join(p, "projects", "**", `${sessionId}.jsonl`)), jsonlFiles = await glob(patterns);
|
|
2627
|
+
const claudePaths = getClaudePaths(), patterns = claudePaths.map((p) => path.join(p, "projects", "**", `${sessionId}.jsonl`).replace(/\\/g, "/")), jsonlFiles = await glob(patterns);
|
|
2628
2628
|
if (jsonlFiles.length === 0) return null;
|
|
2629
2629
|
const file = jsonlFiles[0];
|
|
2630
2630
|
if (file == null) return null;
|
|
@@ -2669,7 +2669,7 @@ async function loadBucketUsageData(groupingFn, options) {
|
|
|
2669
2669
|
}
|
|
2670
2670
|
return sortByDate(buckets, (item) => item.bucket, options?.order);
|
|
2671
2671
|
}
|
|
2672
|
-
async function calculateContextTokens(transcriptPath) {
|
|
2672
|
+
async function calculateContextTokens(transcriptPath, modelId, offline = false) {
|
|
2673
2673
|
let content;
|
|
2674
2674
|
try {
|
|
2675
2675
|
content = await readFile(transcriptPath, "utf-8");
|
|
@@ -2685,11 +2685,24 @@ async function calculateContextTokens(transcriptPath) {
|
|
|
2685
2685
|
if (!result.success) continue;
|
|
2686
2686
|
const obj = result.data;
|
|
2687
2687
|
if (obj.type === "assistant" && obj.message != null && obj.message.usage != null && obj.message.usage.input_tokens != null) {
|
|
2688
|
-
const usage = obj.message.usage, inputTokens = usage.input_tokens + (usage.cache_creation_input_tokens ?? 0) + (usage.cache_read_input_tokens ?? 0)
|
|
2688
|
+
const usage = obj.message.usage, inputTokens = usage.input_tokens + (usage.cache_creation_input_tokens ?? 0) + (usage.cache_read_input_tokens ?? 0);
|
|
2689
|
+
let contextLimit = 2e5;
|
|
2690
|
+
if (modelId != null && modelId !== "") try {
|
|
2691
|
+
var _usingCtx5 = (0, import_usingCtx.default)();
|
|
2692
|
+
const fetcher = _usingCtx5.u(new PricingFetcher(offline)), contextLimitResult = await fetcher.getModelContextLimit(modelId);
|
|
2693
|
+
if (isSuccess(contextLimitResult) && contextLimitResult.value != null) contextLimit = contextLimitResult.value;
|
|
2694
|
+
else if (isSuccess(contextLimitResult)) logger.debug(`No context limit data available for model ${modelId} in LiteLLM`);
|
|
2695
|
+
else logger.debug(`Failed to get context limit for model ${modelId}: ${contextLimitResult.error.message}`);
|
|
2696
|
+
} catch (_) {
|
|
2697
|
+
_usingCtx5.e = _;
|
|
2698
|
+
} finally {
|
|
2699
|
+
_usingCtx5.d();
|
|
2700
|
+
}
|
|
2701
|
+
const percentage = Math.min(100, Math.max(0, Math.round(inputTokens / contextLimit * 100)));
|
|
2689
2702
|
return {
|
|
2690
2703
|
inputTokens,
|
|
2691
2704
|
percentage,
|
|
2692
|
-
contextLimit
|
|
2705
|
+
contextLimit
|
|
2693
2706
|
};
|
|
2694
2707
|
}
|
|
2695
2708
|
} catch {
|
|
@@ -2700,7 +2713,7 @@ async function calculateContextTokens(transcriptPath) {
|
|
|
2700
2713
|
}
|
|
2701
2714
|
async function loadSessionBlockData(options) {
|
|
2702
2715
|
try {
|
|
2703
|
-
var
|
|
2716
|
+
var _usingCtx6 = (0, import_usingCtx.default)();
|
|
2704
2717
|
const claudePaths = toArray(options?.claudePath ?? getClaudePaths()), allFiles = [];
|
|
2705
2718
|
for (const claudePath of claudePaths) {
|
|
2706
2719
|
const claudeDir = path.join(claudePath, CLAUDE_PROJECTS_DIR_NAME), files = await glob([USAGE_DATA_GLOB_PATTERN], {
|
|
@@ -2710,7 +2723,7 @@ async function loadSessionBlockData(options) {
|
|
|
2710
2723
|
allFiles.push(...files);
|
|
2711
2724
|
}
|
|
2712
2725
|
if (allFiles.length === 0) return [];
|
|
2713
|
-
const blocksFilteredFiles = filterByProject(allFiles, (filePath) => extractProjectFromPath(filePath), options?.project), sortedFiles = await sortFilesByTimestamp(blocksFilteredFiles), mode = options?.mode ?? "auto", fetcher =
|
|
2726
|
+
const blocksFilteredFiles = filterByProject(allFiles, (filePath) => extractProjectFromPath(filePath), options?.project), sortedFiles = await sortFilesByTimestamp(blocksFilteredFiles), mode = options?.mode ?? "auto", fetcher = _usingCtx6.u(mode === "display" ? null : new PricingFetcher(options?.offline)), processedHashes = /* @__PURE__ */ new Set(), allEntries = [];
|
|
2714
2727
|
for (const file of sortedFiles) {
|
|
2715
2728
|
const content = await readFile(file, "utf-8"), lines = content.trim().split("\n").filter((line) => line.length > 0);
|
|
2716
2729
|
for (const line of lines) try {
|
|
@@ -2743,9 +2756,9 @@ async function loadSessionBlockData(options) {
|
|
|
2743
2756
|
}) : blocks;
|
|
2744
2757
|
return sortByDate(dateFiltered, (block) => block.startTime, options?.order);
|
|
2745
2758
|
} catch (_) {
|
|
2746
|
-
|
|
2759
|
+
_usingCtx6.e = _;
|
|
2747
2760
|
} finally {
|
|
2748
|
-
|
|
2761
|
+
_usingCtx6.d();
|
|
2749
2762
|
}
|
|
2750
2763
|
}
|
|
2751
2764
|
export { DEFAULT_SESSION_DURATION_HOURS, bucketUsageSchema, calculateBurnRate, calculateContextTokens, calculateCostForEntry, createUniqueHash, dailyUsageSchema, extractProjectFromPath, filterRecentBlocks, formatDate, formatDateCompact, getClaudePaths, getContextUsageThresholds, getEarliestTimestamp, getUsageLimitResetTime, glob, globUsageFiles, identifySessionBlocks, loadBucketUsageData, loadDailyUsageData, loadMonthlyUsageData, loadSessionBlockData, loadSessionData, loadSessionUsageById, loadWeeklyUsageData, modelBreakdownSchema, monthlyUsageSchema, projectBlockUsage, sessionUsageSchema, sortFilesByTimestamp, transcriptMessageSchema, transcriptUsageSchema, uniq, unwrap, usageDataSchema, weeklyUsageSchema };
|
package/dist/data-loader.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "./pricing-fetcher-
|
|
2
|
-
import { BucketUsage, DailyUsage, DateFilter, GlobResult, LoadOptions, ModelBreakdown, MonthlyUsage, SessionUsage, UsageData, WeeklyUsage, bucketUsageSchema, calculateContextTokens, calculateCostForEntry, createUniqueHash, dailyUsageSchema, extractProjectFromPath, formatDate, formatDateCompact, getClaudePaths, getContextUsageThresholds, getEarliestTimestamp, getUsageLimitResetTime, globUsageFiles, loadBucketUsageData, loadDailyUsageData, loadMonthlyUsageData, loadSessionBlockData, loadSessionData, loadSessionUsageById, loadWeeklyUsageData, modelBreakdownSchema, monthlyUsageSchema, sessionUsageSchema, sortFilesByTimestamp, transcriptMessageSchema, transcriptUsageSchema, usageDataSchema, weeklyUsageSchema } from "./data-loader-
|
|
1
|
+
import "./pricing-fetcher-BgDfBZ05.js";
|
|
2
|
+
import { BucketUsage, DailyUsage, DateFilter, GlobResult, LoadOptions, ModelBreakdown, MonthlyUsage, SessionUsage, UsageData, WeeklyUsage, bucketUsageSchema, calculateContextTokens, calculateCostForEntry, createUniqueHash, dailyUsageSchema, extractProjectFromPath, formatDate, formatDateCompact, getClaudePaths, getContextUsageThresholds, getEarliestTimestamp, getUsageLimitResetTime, globUsageFiles, loadBucketUsageData, loadDailyUsageData, loadMonthlyUsageData, loadSessionBlockData, loadSessionData, loadSessionUsageById, loadWeeklyUsageData, modelBreakdownSchema, monthlyUsageSchema, sessionUsageSchema, sortFilesByTimestamp, transcriptMessageSchema, transcriptUsageSchema, usageDataSchema, weeklyUsageSchema } from "./data-loader-BJnD_oR3.js";
|
|
3
3
|
export { BucketUsage, DailyUsage, DateFilter, GlobResult, LoadOptions, ModelBreakdown, MonthlyUsage, SessionUsage, UsageData, WeeklyUsage, bucketUsageSchema, calculateContextTokens, calculateCostForEntry, createUniqueHash, dailyUsageSchema, extractProjectFromPath, formatDate, formatDateCompact, getClaudePaths, getContextUsageThresholds, getEarliestTimestamp, getUsageLimitResetTime, globUsageFiles, loadBucketUsageData, loadDailyUsageData, loadMonthlyUsageData, loadSessionBlockData, loadSessionData, loadSessionUsageById, loadWeeklyUsageData, modelBreakdownSchema, monthlyUsageSchema, sessionUsageSchema, sortFilesByTimestamp, transcriptMessageSchema, transcriptUsageSchema, usageDataSchema, weeklyUsageSchema };
|
package/dist/data-loader.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "./pricing-fetcher-
|
|
1
|
+
import "./pricing-fetcher-CLjmfFHB.js";
|
|
2
2
|
import "./_token-utils-WjkbrjKv.js";
|
|
3
|
-
import "./_types-
|
|
4
|
-
import { bucketUsageSchema, calculateContextTokens, calculateCostForEntry, createUniqueHash, dailyUsageSchema, extractProjectFromPath, formatDate, formatDateCompact, getClaudePaths, getContextUsageThresholds, getEarliestTimestamp, getUsageLimitResetTime, globUsageFiles, loadBucketUsageData, loadDailyUsageData, loadMonthlyUsageData, loadSessionBlockData, loadSessionData, loadSessionUsageById, loadWeeklyUsageData, modelBreakdownSchema, monthlyUsageSchema, sessionUsageSchema, sortFilesByTimestamp, transcriptMessageSchema, transcriptUsageSchema, usageDataSchema, weeklyUsageSchema } from "./data-loader-
|
|
5
|
-
import "./logger-
|
|
3
|
+
import "./_types-BbEk8t2a.js";
|
|
4
|
+
import { bucketUsageSchema, calculateContextTokens, calculateCostForEntry, createUniqueHash, dailyUsageSchema, extractProjectFromPath, formatDate, formatDateCompact, getClaudePaths, getContextUsageThresholds, getEarliestTimestamp, getUsageLimitResetTime, globUsageFiles, loadBucketUsageData, loadDailyUsageData, loadMonthlyUsageData, loadSessionBlockData, loadSessionData, loadSessionUsageById, loadWeeklyUsageData, modelBreakdownSchema, monthlyUsageSchema, sessionUsageSchema, sortFilesByTimestamp, transcriptMessageSchema, transcriptUsageSchema, usageDataSchema, weeklyUsageSchema } from "./data-loader-G78wtKpU.js";
|
|
5
|
+
import "./logger-CHezuMoN.js";
|
|
6
6
|
export { bucketUsageSchema, calculateContextTokens, calculateCostForEntry, createUniqueHash, dailyUsageSchema, extractProjectFromPath, formatDate, formatDateCompact, getClaudePaths, getContextUsageThresholds, getEarliestTimestamp, getUsageLimitResetTime, globUsageFiles, loadBucketUsageData, loadDailyUsageData, loadMonthlyUsageData, loadSessionBlockData, loadSessionData, loadSessionUsageById, loadWeeklyUsageData, modelBreakdownSchema, monthlyUsageSchema, sessionUsageSchema, sortFilesByTimestamp, transcriptMessageSchema, transcriptUsageSchema, usageDataSchema, weeklyUsageSchema };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { CLAUDE_PROJECTS_DIR_NAME, DEBUG_MATCH_THRESHOLD_PERCENT, PricingFetcher, USAGE_DATA_GLOB_PATTERN, __toESM, isFailure, require_usingCtx, try_ } from "./pricing-fetcher-
|
|
2
|
-
import { getClaudePaths, glob, unwrap, usageDataSchema } from "./data-loader-
|
|
3
|
-
import { logger } from "./logger-
|
|
1
|
+
import { CLAUDE_PROJECTS_DIR_NAME, DEBUG_MATCH_THRESHOLD_PERCENT, PricingFetcher, USAGE_DATA_GLOB_PATTERN, __toESM, isFailure, require_usingCtx, try_ } from "./pricing-fetcher-CLjmfFHB.js";
|
|
2
|
+
import { getClaudePaths, glob, unwrap, usageDataSchema } from "./data-loader-G78wtKpU.js";
|
|
3
|
+
import { logger } from "./logger-CHezuMoN.js";
|
|
4
4
|
import { readFile } from "node:fs/promises";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
var import_usingCtx = /* @__PURE__ */ __toESM(require_usingCtx(), 1);
|
package/dist/debug.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import "./pricing-fetcher-
|
|
1
|
+
import "./pricing-fetcher-CLjmfFHB.js";
|
|
2
2
|
import "./_token-utils-WjkbrjKv.js";
|
|
3
|
-
import "./_types-
|
|
4
|
-
import "./data-loader-
|
|
5
|
-
import "./logger-
|
|
6
|
-
import { detectMismatches, printMismatchReport } from "./debug-
|
|
3
|
+
import "./_types-BbEk8t2a.js";
|
|
4
|
+
import "./data-loader-G78wtKpU.js";
|
|
5
|
+
import "./logger-CHezuMoN.js";
|
|
6
|
+
import { detectMismatches, printMismatchReport } from "./debug-BFlA56YT.js";
|
|
7
7
|
export { detectMismatches, printMismatchReport };
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { BLOCKS_COMPACT_WIDTH_THRESHOLD, BLOCKS_DEFAULT_TERMINAL_WIDTH, BLOCKS_WARNING_THRESHOLD, BURN_RATE_THRESHOLDS, DEFAULT_RECENT_DAYS, DEFAULT_REFRESH_INTERVAL_SECONDS, MAX_REFRESH_INTERVAL_SECONDS, MCP_DEFAULT_PORT, MIN_REFRESH_INTERVAL_SECONDS, MIN_RENDER_INTERVAL_MS, PROJECT_ALIASES_ENV, PricingFetcher, WEEK_DAYS, __commonJSMin, __require, __toESM, isFailure, require_usingCtx, try_ } from "./pricing-fetcher-
|
|
2
|
+
import { BLOCKS_COMPACT_WIDTH_THRESHOLD, BLOCKS_DEFAULT_TERMINAL_WIDTH, BLOCKS_WARNING_THRESHOLD, BURN_RATE_THRESHOLDS, DEFAULT_RECENT_DAYS, DEFAULT_REFRESH_INTERVAL_SECONDS, MAX_REFRESH_INTERVAL_SECONDS, MCP_DEFAULT_PORT, MIN_REFRESH_INTERVAL_SECONDS, MIN_RENDER_INTERVAL_MS, PROJECT_ALIASES_ENV, PricingFetcher, WEEK_DAYS, __commonJSMin, __require, __toESM, inspectError, isFailure, map, pipe, require_usingCtx, try_ } from "./pricing-fetcher-CLjmfFHB.js";
|
|
3
3
|
import { getTotalTokens } from "./_token-utils-WjkbrjKv.js";
|
|
4
|
-
import { CostModes, SortOrders, filterDateSchema, statuslineHookJsonSchema } from "./_types-
|
|
4
|
+
import { CostModes, SortOrders, filterDateSchema, statuslineHookJsonSchema } from "./_types-BbEk8t2a.js";
|
|
5
5
|
import { calculateTotals, createTotalsObject } from "./calculate-cost-BDqO4yWA.js";
|
|
6
|
-
import { DEFAULT_SESSION_DURATION_HOURS, calculateBurnRate, calculateContextTokens, calculateCostForEntry, createUniqueHash, filterRecentBlocks, formatDateCompact, getClaudePaths, getContextUsageThresholds, getEarliestTimestamp, getUsageLimitResetTime, globUsageFiles, identifySessionBlocks, loadDailyUsageData, loadMonthlyUsageData, loadSessionBlockData, loadSessionData, loadSessionUsageById, loadWeeklyUsageData, projectBlockUsage, sortFilesByTimestamp, uniq, usageDataSchema } from "./data-loader-
|
|
7
|
-
import { description, log, logger, name, version } from "./logger-
|
|
8
|
-
import { detectMismatches, printMismatchReport } from "./debug-
|
|
9
|
-
import { createMcpHttpApp, createMcpServer, startMcpServerStdio } from "./mcp-
|
|
6
|
+
import { DEFAULT_SESSION_DURATION_HOURS, calculateBurnRate, calculateContextTokens, calculateCostForEntry, createUniqueHash, filterRecentBlocks, formatDateCompact, getClaudePaths, getContextUsageThresholds, getEarliestTimestamp, getUsageLimitResetTime, globUsageFiles, identifySessionBlocks, loadDailyUsageData, loadMonthlyUsageData, loadSessionBlockData, loadSessionData, loadSessionUsageById, loadWeeklyUsageData, projectBlockUsage, sortFilesByTimestamp, uniq, unwrap, usageDataSchema } from "./data-loader-G78wtKpU.js";
|
|
7
|
+
import { description, log, logger, name, version } from "./logger-CHezuMoN.js";
|
|
8
|
+
import { detectMismatches, printMismatchReport } from "./debug-BFlA56YT.js";
|
|
9
|
+
import { createMcpHttpApp, createMcpServer, startMcpServerStdio } from "./mcp-BEHYXSQT.js";
|
|
10
10
|
import a, { readFile } from "node:fs/promises";
|
|
11
11
|
import path from "node:path";
|
|
12
12
|
import process$1 from "node:process";
|
|
@@ -1893,15 +1893,15 @@ var require_debug$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1893
1893
|
} };
|
|
1894
1894
|
}), ret;
|
|
1895
1895
|
}
|
|
1896
|
-
var sequencer = function sequencer$1(map$
|
|
1896
|
+
var sequencer = function sequencer$1(map$2, str) {
|
|
1897
1897
|
var exploded = str.split("");
|
|
1898
|
-
return exploded = exploded.map(map$
|
|
1898
|
+
return exploded = exploded.map(map$2), exploded.join("");
|
|
1899
1899
|
};
|
|
1900
|
-
for (var map in colors$1.trap = require_trap(), colors$1.zalgo = require_zalgo(), colors$1.maps = {}, colors$1.maps.america = require_america()(colors$1), colors$1.maps.zebra = require_zebra()(colors$1), colors$1.maps.rainbow = require_rainbow()(colors$1), colors$1.maps.random = require_random()(colors$1), colors$1.maps) (function(map$
|
|
1901
|
-
colors$1[map$
|
|
1902
|
-
return sequencer(colors$1.maps[map$
|
|
1900
|
+
for (var map$1 in colors$1.trap = require_trap(), colors$1.zalgo = require_zalgo(), colors$1.maps = {}, colors$1.maps.america = require_america()(colors$1), colors$1.maps.zebra = require_zebra()(colors$1), colors$1.maps.rainbow = require_rainbow()(colors$1), colors$1.maps.random = require_random()(colors$1), colors$1.maps) (function(map$2) {
|
|
1901
|
+
colors$1[map$2] = function(str) {
|
|
1902
|
+
return sequencer(colors$1.maps[map$2], str);
|
|
1903
1903
|
};
|
|
1904
|
-
})(map);
|
|
1904
|
+
})(map$1);
|
|
1905
1905
|
defineProps(colors$1, init());
|
|
1906
1906
|
})), require_safe = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1907
1907
|
var colors = require_colors();
|
|
@@ -2558,10 +2558,10 @@ function delay(ms, options = {}) {
|
|
|
2558
2558
|
const { signal, persistent = true } = options;
|
|
2559
2559
|
return signal?.aborted ? Promise.reject(signal.reason) : new Promise((resolve, reject) => {
|
|
2560
2560
|
const abort = () => {
|
|
2561
|
-
clearTimeout(i), reject(signal?.reason);
|
|
2561
|
+
clearTimeout(+i), reject(signal?.reason);
|
|
2562
2562
|
}, done = () => {
|
|
2563
2563
|
signal?.removeEventListener("abort", abort), resolve();
|
|
2564
|
-
}, i =
|
|
2564
|
+
}, i = setArbitraryLengthTimeout(done, ms);
|
|
2565
2565
|
if (signal?.addEventListener("abort", abort, { once: true }), persistent === false) try {
|
|
2566
2566
|
Deno.unrefTimer(i);
|
|
2567
2567
|
} catch (error) {
|
|
@@ -2570,6 +2570,16 @@ function delay(ms, options = {}) {
|
|
|
2570
2570
|
}
|
|
2571
2571
|
});
|
|
2572
2572
|
}
|
|
2573
|
+
const I32_MAX = 2 ** 31 - 1;
|
|
2574
|
+
function setArbitraryLengthTimeout(callback, delay$1) {
|
|
2575
|
+
let currentDelay = delay$1 = Math.trunc(Math.max(delay$1, 0) || 0);
|
|
2576
|
+
const start = Date.now();
|
|
2577
|
+
let timeoutId;
|
|
2578
|
+
const queueTimeout = () => {
|
|
2579
|
+
currentDelay = delay$1 - (Date.now() - start), timeoutId = currentDelay > I32_MAX ? setTimeout(queueTimeout, I32_MAX) : setTimeout(callback, currentDelay);
|
|
2580
|
+
};
|
|
2581
|
+
return queueTimeout(), { valueOf: () => timeoutId };
|
|
2582
|
+
}
|
|
2573
2583
|
const isBrowser = globalThis.window?.document !== void 0, isNode = globalThis.process?.versions?.node !== void 0, isBun = globalThis.process?.versions?.bun !== void 0, isDeno = globalThis.Deno?.version?.deno !== void 0, isElectron = globalThis.process?.versions?.electron !== void 0, isJsDom = globalThis.navigator?.userAgent?.includes("jsdom") === true, isWebWorker = typeof WorkerGlobalScope !== "undefined" && globalThis instanceof WorkerGlobalScope, isDedicatedWorker = typeof DedicatedWorkerGlobalScope !== "undefined" && globalThis instanceof DedicatedWorkerGlobalScope, isSharedWorker = typeof SharedWorkerGlobalScope !== "undefined" && globalThis instanceof SharedWorkerGlobalScope, isServiceWorker = typeof ServiceWorkerGlobalScope !== "undefined" && globalThis instanceof ServiceWorkerGlobalScope, platform = globalThis.navigator?.userAgentData?.platform, isMacOs = platform === "macOS" || globalThis.navigator?.platform === "MacIntel" || globalThis.navigator?.userAgent?.includes(" Mac ") === true || globalThis.process?.platform === "darwin", isWindows$1 = platform === "Windows" || globalThis.navigator?.platform === "Win32" || globalThis.process?.platform === "win32", isLinux = platform === "Linux" || globalThis.navigator?.platform?.startsWith("Linux") === true || globalThis.navigator?.userAgent?.includes(" Linux ") === true || globalThis.process?.platform === "linux", isIos = platform === "iOS" || globalThis.navigator?.platform === "MacIntel" && globalThis.navigator?.maxTouchPoints > 1 || /iPad|iPhone|iPod/.test(globalThis.navigator?.platform), isAndroid = platform === "Android" || globalThis.navigator?.platform === "Android" || globalThis.navigator?.userAgent?.includes(" Android ") === true || globalThis.process?.platform === "android", ESC = "\x1B[", SEP = ";", isTerminalApp = !isBrowser && process$1.env.TERM_PROGRAM === "Apple_Terminal", isWindows = !isBrowser && process$1.platform === "win32", cwdFunction = isBrowser ? () => {
|
|
2574
2584
|
throw new Error("`process.cwd()` only works in Node.js, not the browser.");
|
|
2575
2585
|
} : process$1.cwd, cursorTo = (x, y) => {
|
|
@@ -3702,26 +3712,29 @@ var outgoingEnded = Symbol("outgoingEnded"), handleRequestError = () => new Resp
|
|
|
3702
3712
|
const resHeaderRecord = buildOutgoingHttpHeaders(res.headers);
|
|
3703
3713
|
if (res.body) {
|
|
3704
3714
|
const reader = res.body.getReader(), values = [];
|
|
3705
|
-
let done = false, currentReadPromise = void 0
|
|
3706
|
-
|
|
3707
|
-
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
|
|
3711
|
-
|
|
3712
|
-
|
|
3713
|
-
|
|
3714
|
-
|
|
3715
|
+
let done = false, currentReadPromise = void 0;
|
|
3716
|
+
if (resHeaderRecord["transfer-encoding"] !== "chunked") {
|
|
3717
|
+
let maxReadCount = 2;
|
|
3718
|
+
for (let i = 0; i < maxReadCount; i++) {
|
|
3719
|
+
currentReadPromise ||= reader.read();
|
|
3720
|
+
const chunk = await readWithoutBlocking(currentReadPromise).catch((e) => {
|
|
3721
|
+
console.error(e), done = true;
|
|
3722
|
+
});
|
|
3723
|
+
if (!chunk) {
|
|
3724
|
+
if (i === 1) {
|
|
3725
|
+
await new Promise((resolve) => setTimeout(resolve)), maxReadCount = 3;
|
|
3726
|
+
continue;
|
|
3727
|
+
}
|
|
3728
|
+
break;
|
|
3729
|
+
}
|
|
3730
|
+
if (currentReadPromise = void 0, chunk.value) values.push(chunk.value);
|
|
3731
|
+
if (chunk.done) {
|
|
3732
|
+
done = true;
|
|
3733
|
+
break;
|
|
3715
3734
|
}
|
|
3716
|
-
break;
|
|
3717
|
-
}
|
|
3718
|
-
if (currentReadPromise = void 0, chunk.value) values.push(chunk.value);
|
|
3719
|
-
if (chunk.done) {
|
|
3720
|
-
done = true;
|
|
3721
|
-
break;
|
|
3722
3735
|
}
|
|
3736
|
+
if (done && !("content-length" in resHeaderRecord)) resHeaderRecord["content-length"] = values.reduce((acc, value) => acc + value.length, 0);
|
|
3723
3737
|
}
|
|
3724
|
-
if (done && !("content-length" in resHeaderRecord)) resHeaderRecord["content-length"] = values.reduce((acc, value) => acc + value.length, 0);
|
|
3725
3738
|
if (outgoing.writeHead(res.status, resHeaderRecord), values.forEach((value) => {
|
|
3726
3739
|
outgoing.write(value);
|
|
3727
3740
|
}), done) outgoing.end();
|
|
@@ -4221,72 +4234,65 @@ const statuslineCommand = define({
|
|
|
4221
4234
|
if (!hookDataParseResult.success) log("❌ Invalid input format:", hookDataParseResult.error.message), process$1.exit(1);
|
|
4222
4235
|
const hookData = hookDataParseResult.data, claudePaths = getClaudePaths();
|
|
4223
4236
|
if (claudePaths.length === 0) log("❌ No Claude data directory found"), process$1.exit(1);
|
|
4224
|
-
const sessionId = hookData.session_id
|
|
4225
|
-
|
|
4226
|
-
try {
|
|
4227
|
-
const sessionData = await loadSessionUsageById(sessionId, {
|
|
4237
|
+
const sessionId = hookData.session_id, sessionCost = await pipe(try_({
|
|
4238
|
+
try: loadSessionUsageById(sessionId, {
|
|
4228
4239
|
mode: "auto",
|
|
4229
4240
|
offline: ctx.values.offline
|
|
4230
|
-
})
|
|
4231
|
-
|
|
4232
|
-
}
|
|
4233
|
-
|
|
4234
|
-
}
|
|
4235
|
-
const today = /* @__PURE__ */ new Date(), todayStr = today.toISOString().split("T")[0]?.replace(/-/g, "") ?? "";
|
|
4236
|
-
let todayCost = 0;
|
|
4237
|
-
try {
|
|
4238
|
-
const dailyData = await loadDailyUsageData({
|
|
4241
|
+
}),
|
|
4242
|
+
catch: (error) => error
|
|
4243
|
+
}), map((sessionCost$1) => sessionCost$1?.totalCost), inspectError((error) => logger.error("Failed to load session data:", error)), unwrap(void 0)), today = /* @__PURE__ */ new Date(), todayStr = today.toISOString().split("T")[0]?.replace(/-/g, "") ?? "", todayCost = await pipe(try_({
|
|
4244
|
+
try: loadDailyUsageData({
|
|
4239
4245
|
since: todayStr,
|
|
4240
4246
|
until: todayStr,
|
|
4241
4247
|
mode: "auto",
|
|
4242
4248
|
offline: ctx.values.offline
|
|
4243
|
-
})
|
|
4249
|
+
}),
|
|
4250
|
+
catch: (error) => error
|
|
4251
|
+
}), map((dailyData) => {
|
|
4244
4252
|
if (dailyData.length > 0) {
|
|
4245
4253
|
const totals = calculateTotals(dailyData);
|
|
4246
|
-
|
|
4254
|
+
return totals.totalCost;
|
|
4247
4255
|
}
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
let blockInfo = "", burnRateInfo = "";
|
|
4252
|
-
try {
|
|
4253
|
-
const blocks = await loadSessionBlockData({
|
|
4256
|
+
return 0;
|
|
4257
|
+
}), inspectError((error) => logger.error("Failed to load daily data:", error)), unwrap(0)), { blockInfo, burnRateInfo } = await pipe(try_({
|
|
4258
|
+
try: loadSessionBlockData({
|
|
4254
4259
|
mode: "auto",
|
|
4255
4260
|
offline: ctx.values.offline
|
|
4261
|
+
}),
|
|
4262
|
+
catch: (error) => error
|
|
4263
|
+
}), map((blocks) => {
|
|
4264
|
+
if (blocks.length === 0) return {
|
|
4265
|
+
blockInfo: "No active block",
|
|
4266
|
+
burnRateInfo: ""
|
|
4267
|
+
};
|
|
4268
|
+
const activeBlock = blocks.find((block) => {
|
|
4269
|
+
return !!block.isActive;
|
|
4256
4270
|
});
|
|
4257
|
-
if (
|
|
4258
|
-
|
|
4259
|
-
|
|
4260
|
-
return
|
|
4261
|
-
});
|
|
4262
|
-
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
|
|
4266
|
-
if (burnRate != null) {
|
|
4267
|
-
const costPerHour = burnRate.costPerHour, costPerHourStr = `${formatCurrency(costPerHour)}/hr`;
|
|
4268
|
-
let coloredBurnRate = costPerHourStr;
|
|
4269
|
-
if (burnRate.tokensPerMinuteForIndicator < 2e3) coloredBurnRate = import_picocolors$1.default.green(costPerHourStr);
|
|
4270
|
-
else if (burnRate.tokensPerMinuteForIndicator < 5e3) coloredBurnRate = import_picocolors$1.default.yellow(costPerHourStr);
|
|
4271
|
-
else coloredBurnRate = import_picocolors$1.default.red(costPerHourStr);
|
|
4272
|
-
burnRateInfo = ` | 🔥 ${coloredBurnRate}`;
|
|
4273
|
-
}
|
|
4274
|
-
} else blockInfo = "No active block";
|
|
4275
|
-
}
|
|
4276
|
-
} catch (error) {
|
|
4277
|
-
logger.error("Failed to load block data:", error), blockInfo = "No active block";
|
|
4278
|
-
}
|
|
4279
|
-
let contextInfo = "";
|
|
4280
|
-
try {
|
|
4281
|
-
const contextData = await calculateContextTokens(hookData.transcript_path);
|
|
4282
|
-
if (contextData != null) {
|
|
4283
|
-
const p$1 = contextData.percentage, thresholds = getContextUsageThresholds(), color = p$1 < thresholds.LOW ? import_picocolors$1.default.green : p$1 < thresholds.MEDIUM ? import_picocolors$1.default.yellow : import_picocolors$1.default.red, coloredPercentage = color(`${p$1}%`), tokenDisplay = contextData.inputTokens.toLocaleString();
|
|
4284
|
-
contextInfo = ` | 🧠 ${tokenDisplay} (${coloredPercentage})`;
|
|
4271
|
+
if (activeBlock != null) {
|
|
4272
|
+
const now = /* @__PURE__ */ new Date(), remaining = Math.round((activeBlock.endTime.getTime() - now.getTime()) / (1e3 * 60)), blockCost = activeBlock.costUSD, blockInfo$1 = `${formatCurrency(blockCost)} block (${formatRemainingTime(remaining)})`, burnRate = calculateBurnRate(activeBlock), burnRateInfo$1 = burnRate != null ? (() => {
|
|
4273
|
+
const costPerHour = burnRate.costPerHour, costPerHourStr = `${formatCurrency(costPerHour)}/hr`, coloredBurnRate = burnRate.tokensPerMinuteForIndicator < 2e3 ? import_picocolors$1.default.green(costPerHourStr) : burnRate.tokensPerMinuteForIndicator < 5e3 ? import_picocolors$1.default.yellow(costPerHourStr) : import_picocolors$1.default.red(costPerHourStr);
|
|
4274
|
+
return ` | 🔥 ${coloredBurnRate}`;
|
|
4275
|
+
})() : "";
|
|
4276
|
+
return {
|
|
4277
|
+
blockInfo: blockInfo$1,
|
|
4278
|
+
burnRateInfo: burnRateInfo$1
|
|
4279
|
+
};
|
|
4285
4280
|
}
|
|
4286
|
-
|
|
4287
|
-
|
|
4288
|
-
|
|
4289
|
-
|
|
4281
|
+
return {
|
|
4282
|
+
blockInfo: "No active block",
|
|
4283
|
+
burnRateInfo: ""
|
|
4284
|
+
};
|
|
4285
|
+
}), inspectError((error) => logger.error("Failed to load block data:", error)), unwrap({
|
|
4286
|
+
blockInfo: "No active block",
|
|
4287
|
+
burnRateInfo: ""
|
|
4288
|
+
})), contextInfo = await pipe(try_({
|
|
4289
|
+
try: calculateContextTokens(hookData.transcript_path, hookData.model.id, ctx.values.offline),
|
|
4290
|
+
catch: (error) => error
|
|
4291
|
+
}), inspectError((error) => logger.debug(`Failed to calculate context tokens: ${error instanceof Error ? error.message : String(error)}`)), map((ctx$1) => {
|
|
4292
|
+
if (ctx$1 == null) return void 0;
|
|
4293
|
+
const thresholds = getContextUsageThresholds(), color = ctx$1.percentage < thresholds.LOW ? import_picocolors$1.default.green : ctx$1.percentage < thresholds.MEDIUM ? import_picocolors$1.default.yellow : import_picocolors$1.default.red, coloredPercentage = color(`${ctx$1.percentage}%`), tokenDisplay = ctx$1.inputTokens.toLocaleString();
|
|
4294
|
+
return `${tokenDisplay} (${coloredPercentage})`;
|
|
4295
|
+
}), unwrap(void 0)), modelName = hookData.model.display_name, sessionDisplay = sessionCost != null ? formatCurrency(sessionCost) : "N/A", statusLine = `🤖 ${modelName} | 💰 ${sessionDisplay} session / ${formatCurrency(todayCost)} today / ${blockInfo}${burnRateInfo} | 🧠 ${contextInfo ?? "N/A"}`;
|
|
4290
4296
|
log(statusLine);
|
|
4291
4297
|
}
|
|
4292
4298
|
});
|
|
@@ -761,7 +761,7 @@ function _getDefaultLogLevel() {
|
|
|
761
761
|
return g ? LogLevels.debug : R ? LogLevels.warn : LogLevels.info;
|
|
762
762
|
}
|
|
763
763
|
const consola = createConsola$1();
|
|
764
|
-
var name = "ccusage", version = "15.9.
|
|
764
|
+
var name = "ccusage", version = "15.9.7", description = "Usage analysis tool for Claude Code";
|
|
765
765
|
const logger = consola.withTag(name);
|
|
766
766
|
if (process$1.env.LOG_LEVEL != null) {
|
|
767
767
|
const level = Number.parseInt(process$1.env.LOG_LEVEL, 10);
|
package/dist/logger.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { log, logger } from "./logger-
|
|
1
|
+
import { log, logger } from "./logger-CHezuMoN.js";
|
|
2
2
|
export { log, logger };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { __commonJSMin, __toESM, require_usingCtx } from "./pricing-fetcher-
|
|
1
|
+
import { __commonJSMin, __toESM, require_usingCtx } from "./pricing-fetcher-CLjmfFHB.js";
|
|
2
2
|
import { getTotalTokens } from "./_token-utils-WjkbrjKv.js";
|
|
3
|
-
import { ZodFirstPartyTypeKind, ZodOptional, ZodType, arrayType, booleanType, discriminatedUnionType, enumType, filterDateSchema, literalType, numberType, objectType, optionalType, recordType, stringType, unionType, unknownType } from "./_types-
|
|
3
|
+
import { ZodFirstPartyTypeKind, ZodOptional, ZodType, arrayType, booleanType, discriminatedUnionType, enumType, filterDateSchema, literalType, numberType, objectType, optionalType, recordType, stringType, unionType, unknownType } from "./_types-BbEk8t2a.js";
|
|
4
4
|
import { calculateTotals, createTotalsObject } from "./calculate-cost-BDqO4yWA.js";
|
|
5
|
-
import { getClaudePaths, loadDailyUsageData, loadMonthlyUsageData, loadSessionBlockData, loadSessionData } from "./data-loader-
|
|
6
|
-
import { name, version } from "./logger-
|
|
5
|
+
import { getClaudePaths, loadDailyUsageData, loadMonthlyUsageData, loadSessionBlockData, loadSessionData } from "./data-loader-G78wtKpU.js";
|
|
6
|
+
import { name, version } from "./logger-CHezuMoN.js";
|
|
7
7
|
import process from "node:process";
|
|
8
8
|
const LATEST_PROTOCOL_VERSION = "2025-06-18", SUPPORTED_PROTOCOL_VERSIONS = [
|
|
9
9
|
LATEST_PROTOCOL_VERSION,
|
package/dist/mcp.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "./pricing-fetcher-
|
|
2
|
-
import { LoadOptions } from "./data-loader-
|
|
1
|
+
import "./pricing-fetcher-BgDfBZ05.js";
|
|
2
|
+
import { LoadOptions } from "./data-loader-BJnD_oR3.js";
|
|
3
3
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
4
4
|
import { Hono } from "hono/tiny";
|
|
5
5
|
|
package/dist/mcp.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import "./pricing-fetcher-
|
|
1
|
+
import "./pricing-fetcher-CLjmfFHB.js";
|
|
2
2
|
import "./_token-utils-WjkbrjKv.js";
|
|
3
|
-
import "./_types-
|
|
3
|
+
import "./_types-BbEk8t2a.js";
|
|
4
4
|
import "./calculate-cost-BDqO4yWA.js";
|
|
5
|
-
import "./data-loader-
|
|
6
|
-
import "./logger-
|
|
7
|
-
import { createMcpHttpApp, createMcpServer, startMcpServerStdio } from "./mcp-
|
|
5
|
+
import "./data-loader-G78wtKpU.js";
|
|
6
|
+
import "./logger-CHezuMoN.js";
|
|
7
|
+
import { createMcpHttpApp, createMcpServer, startMcpServerStdio } from "./mcp-BEHYXSQT.js";
|
|
8
8
|
export { createMcpHttpApp, createMcpServer, startMcpServerStdio };
|
|
@@ -107,16 +107,26 @@ declare const modelPricingSchema: z.ZodObject<{
|
|
|
107
107
|
output_cost_per_token: z.ZodOptional<z.ZodNumber>;
|
|
108
108
|
cache_creation_input_token_cost: z.ZodOptional<z.ZodNumber>;
|
|
109
109
|
cache_read_input_token_cost: z.ZodOptional<z.ZodNumber>;
|
|
110
|
+
// Context window limits from LiteLLM data
|
|
111
|
+
max_tokens: z.ZodOptional<z.ZodNumber>;
|
|
112
|
+
max_input_tokens: z.ZodOptional<z.ZodNumber>;
|
|
113
|
+
max_output_tokens: z.ZodOptional<z.ZodNumber>;
|
|
110
114
|
}, "strip", z.ZodTypeAny, {
|
|
111
115
|
input_cost_per_token?: number | undefined;
|
|
112
116
|
output_cost_per_token?: number | undefined;
|
|
113
117
|
cache_creation_input_token_cost?: number | undefined;
|
|
114
118
|
cache_read_input_token_cost?: number | undefined;
|
|
119
|
+
max_tokens?: number | undefined;
|
|
120
|
+
max_input_tokens?: number | undefined;
|
|
121
|
+
max_output_tokens?: number | undefined;
|
|
115
122
|
}, {
|
|
116
123
|
input_cost_per_token?: number | undefined;
|
|
117
124
|
output_cost_per_token?: number | undefined;
|
|
118
125
|
cache_creation_input_token_cost?: number | undefined;
|
|
119
126
|
cache_read_input_token_cost?: number | undefined;
|
|
127
|
+
max_tokens?: number | undefined;
|
|
128
|
+
max_input_tokens?: number | undefined;
|
|
129
|
+
max_output_tokens?: number | undefined;
|
|
120
130
|
}>;
|
|
121
131
|
/**
|
|
122
132
|
* Type definition for model pricing information
|
|
@@ -166,6 +176,12 @@ declare class PricingFetcher implements Disposable {
|
|
|
166
176
|
* @returns Model pricing information or null if not found
|
|
167
177
|
*/
|
|
168
178
|
getModelPricing(modelName: string): Result.ResultAsync<ModelPricing | null, Error>;
|
|
179
|
+
/**
|
|
180
|
+
* Gets context window limit for a specific model from LiteLLM data
|
|
181
|
+
* @param modelName - The model name to get context limit for
|
|
182
|
+
* @returns The context limit in tokens, or null if not found
|
|
183
|
+
*/
|
|
184
|
+
getModelContextLimit(modelName: string): Result.ResultAsync<number | null, Error>;
|
|
169
185
|
/**
|
|
170
186
|
* Calculates the cost for given token usage and model
|
|
171
187
|
* @param tokens - Token usage breakdown
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { modelPricingSchema } from "./_types-
|
|
2
|
-
import { logger } from "./logger-
|
|
1
|
+
import { modelPricingSchema } from "./_types-BbEk8t2a.js";
|
|
2
|
+
import { logger } from "./logger-CHezuMoN.js";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import F, { homedir } from "node:os";
|
|
@@ -30,8 +30,9 @@ const isFailure = (result) => "Failure" === result.type, isPromise = (value) =>
|
|
|
30
30
|
};
|
|
31
31
|
return isPromise(result) ? result.then(apply) : apply(result);
|
|
32
32
|
}, isSuccess = (result) => "Success" === result.type, succeed = (...args) => {
|
|
33
|
+
if (args.length <= 0) return { type: "Success" };
|
|
33
34
|
const value = args[0];
|
|
34
|
-
return
|
|
35
|
+
return isPromise(value) ? value.then((value$1) => ({
|
|
35
36
|
type: "Success",
|
|
36
37
|
value: value$1
|
|
37
38
|
})) : {
|
|
@@ -39,8 +40,9 @@ const isFailure = (result) => "Failure" === result.type, isPromise = (value) =>
|
|
|
39
40
|
value
|
|
40
41
|
};
|
|
41
42
|
}, fail = (...args) => {
|
|
43
|
+
if (args.length <= 0) return { type: "Failure" };
|
|
42
44
|
const error = args[0];
|
|
43
|
-
return
|
|
45
|
+
return isPromise(error) ? error.then((error$1) => ({
|
|
44
46
|
type: "Failure",
|
|
45
47
|
error: error$1
|
|
46
48
|
})) : {
|
|
@@ -94,7 +96,7 @@ if (xdgConfig) xdgConfigDirectories.unshift(xdgConfig);
|
|
|
94
96
|
const LITELLM_PRICING_URL = "https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json", DEFAULT_RECENT_DAYS = 3, BLOCKS_WARNING_THRESHOLD = .8, BLOCKS_COMPACT_WIDTH_THRESHOLD = 120, BLOCKS_DEFAULT_TERMINAL_WIDTH = 120, DEBUG_MATCH_THRESHOLD_PERCENT = .1, USER_HOME_DIR = homedir(), XDG_CONFIG_DIR = xdgConfig ?? `${USER_HOME_DIR}/.config`, DEFAULT_CLAUDE_CODE_PATH = ".claude", DEFAULT_CLAUDE_CONFIG_PATH = `${XDG_CONFIG_DIR}/claude`, CLAUDE_CONFIG_DIR_ENV = "CLAUDE_CONFIG_DIR", PROJECT_ALIASES_ENV = "CCUSAGE_PROJECT_ALIASES", CLAUDE_PROJECTS_DIR_NAME = "projects", USAGE_DATA_GLOB_PATTERN = "**/*.jsonl", MCP_DEFAULT_PORT = 8080, DEFAULT_REFRESH_INTERVAL_SECONDS = 1, MIN_REFRESH_INTERVAL_SECONDS = 1, MAX_REFRESH_INTERVAL_SECONDS = 60, MIN_RENDER_INTERVAL_MS = 16, BURN_RATE_THRESHOLDS = {
|
|
95
97
|
HIGH: 1e3,
|
|
96
98
|
MODERATE: 500
|
|
97
|
-
},
|
|
99
|
+
}, DEFAULT_CONTEXT_USAGE_THRESHOLDS = {
|
|
98
100
|
LOW: 50,
|
|
99
101
|
MEDIUM: 80
|
|
100
102
|
}, CONTEXT_LOW_THRESHOLD_ENV = "CCUSAGE_CONTEXT_LOW_THRESHOLD", CONTEXT_MEDIUM_THRESHOLD_ENV = "CCUSAGE_CONTEXT_MEDIUM_THRESHOLD", WEEK_DAYS = [
|
|
@@ -181,97 +183,145 @@ var require_usingCtx = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
181
183
|
"input_cost_per_token": 25e-8,
|
|
182
184
|
"output_cost_per_token": 125e-8,
|
|
183
185
|
"cache_creation_input_token_cost": 3e-7,
|
|
184
|
-
"cache_read_input_token_cost": 3e-8
|
|
186
|
+
"cache_read_input_token_cost": 3e-8,
|
|
187
|
+
"max_tokens": 4096,
|
|
188
|
+
"max_input_tokens": 2e5,
|
|
189
|
+
"max_output_tokens": 4096
|
|
185
190
|
},
|
|
186
191
|
"claude-3-5-haiku-20241022": {
|
|
187
192
|
"input_cost_per_token": 8e-7,
|
|
188
193
|
"output_cost_per_token": 4e-6,
|
|
189
194
|
"cache_creation_input_token_cost": 1e-6,
|
|
190
|
-
"cache_read_input_token_cost": 8e-8
|
|
195
|
+
"cache_read_input_token_cost": 8e-8,
|
|
196
|
+
"max_tokens": 8192,
|
|
197
|
+
"max_input_tokens": 2e5,
|
|
198
|
+
"max_output_tokens": 8192
|
|
191
199
|
},
|
|
192
200
|
"claude-3-5-haiku-latest": {
|
|
193
201
|
"input_cost_per_token": 1e-6,
|
|
194
202
|
"output_cost_per_token": 5e-6,
|
|
195
203
|
"cache_creation_input_token_cost": 125e-8,
|
|
196
|
-
"cache_read_input_token_cost": 1e-7
|
|
204
|
+
"cache_read_input_token_cost": 1e-7,
|
|
205
|
+
"max_tokens": 8192,
|
|
206
|
+
"max_input_tokens": 2e5,
|
|
207
|
+
"max_output_tokens": 8192
|
|
197
208
|
},
|
|
198
209
|
"claude-3-opus-latest": {
|
|
199
210
|
"input_cost_per_token": 15e-6,
|
|
200
211
|
"output_cost_per_token": 75e-6,
|
|
201
212
|
"cache_creation_input_token_cost": 1875e-8,
|
|
202
|
-
"cache_read_input_token_cost": 15e-7
|
|
213
|
+
"cache_read_input_token_cost": 15e-7,
|
|
214
|
+
"max_tokens": 4096,
|
|
215
|
+
"max_input_tokens": 2e5,
|
|
216
|
+
"max_output_tokens": 4096
|
|
203
217
|
},
|
|
204
218
|
"claude-3-opus-20240229": {
|
|
205
219
|
"input_cost_per_token": 15e-6,
|
|
206
220
|
"output_cost_per_token": 75e-6,
|
|
207
221
|
"cache_creation_input_token_cost": 1875e-8,
|
|
208
|
-
"cache_read_input_token_cost": 15e-7
|
|
222
|
+
"cache_read_input_token_cost": 15e-7,
|
|
223
|
+
"max_tokens": 4096,
|
|
224
|
+
"max_input_tokens": 2e5,
|
|
225
|
+
"max_output_tokens": 4096
|
|
209
226
|
},
|
|
210
227
|
"claude-3-5-sonnet-latest": {
|
|
211
228
|
"input_cost_per_token": 3e-6,
|
|
212
229
|
"output_cost_per_token": 15e-6,
|
|
213
230
|
"cache_creation_input_token_cost": 375e-8,
|
|
214
|
-
"cache_read_input_token_cost": 3e-7
|
|
231
|
+
"cache_read_input_token_cost": 3e-7,
|
|
232
|
+
"max_tokens": 8192,
|
|
233
|
+
"max_input_tokens": 2e5,
|
|
234
|
+
"max_output_tokens": 8192
|
|
215
235
|
},
|
|
216
236
|
"claude-3-5-sonnet-20240620": {
|
|
217
237
|
"input_cost_per_token": 3e-6,
|
|
218
238
|
"output_cost_per_token": 15e-6,
|
|
219
239
|
"cache_creation_input_token_cost": 375e-8,
|
|
220
|
-
"cache_read_input_token_cost": 3e-7
|
|
240
|
+
"cache_read_input_token_cost": 3e-7,
|
|
241
|
+
"max_tokens": 8192,
|
|
242
|
+
"max_input_tokens": 2e5,
|
|
243
|
+
"max_output_tokens": 8192
|
|
221
244
|
},
|
|
222
245
|
"claude-opus-4-20250514": {
|
|
223
246
|
"input_cost_per_token": 15e-6,
|
|
224
247
|
"output_cost_per_token": 75e-6,
|
|
225
248
|
"cache_creation_input_token_cost": 1875e-8,
|
|
226
|
-
"cache_read_input_token_cost": 15e-7
|
|
249
|
+
"cache_read_input_token_cost": 15e-7,
|
|
250
|
+
"max_tokens": 32e3,
|
|
251
|
+
"max_input_tokens": 2e5,
|
|
252
|
+
"max_output_tokens": 32e3
|
|
227
253
|
},
|
|
228
254
|
"claude-opus-4-1": {
|
|
229
255
|
"input_cost_per_token": 15e-6,
|
|
230
256
|
"output_cost_per_token": 75e-6,
|
|
231
257
|
"cache_creation_input_token_cost": 1875e-8,
|
|
232
|
-
"cache_read_input_token_cost": 15e-7
|
|
258
|
+
"cache_read_input_token_cost": 15e-7,
|
|
259
|
+
"max_tokens": 32e3,
|
|
260
|
+
"max_input_tokens": 2e5,
|
|
261
|
+
"max_output_tokens": 32e3
|
|
233
262
|
},
|
|
234
263
|
"claude-opus-4-1-20250805": {
|
|
235
264
|
"input_cost_per_token": 15e-6,
|
|
236
265
|
"output_cost_per_token": 75e-6,
|
|
237
266
|
"cache_creation_input_token_cost": 1875e-8,
|
|
238
|
-
"cache_read_input_token_cost": 15e-7
|
|
267
|
+
"cache_read_input_token_cost": 15e-7,
|
|
268
|
+
"max_tokens": 32e3,
|
|
269
|
+
"max_input_tokens": 2e5,
|
|
270
|
+
"max_output_tokens": 32e3
|
|
239
271
|
},
|
|
240
272
|
"claude-sonnet-4-20250514": {
|
|
241
273
|
"input_cost_per_token": 3e-6,
|
|
242
274
|
"output_cost_per_token": 15e-6,
|
|
243
275
|
"cache_creation_input_token_cost": 375e-8,
|
|
244
|
-
"cache_read_input_token_cost": 3e-7
|
|
276
|
+
"cache_read_input_token_cost": 3e-7,
|
|
277
|
+
"max_tokens": 64e3,
|
|
278
|
+
"max_input_tokens": 2e5,
|
|
279
|
+
"max_output_tokens": 64e3
|
|
245
280
|
},
|
|
246
281
|
"claude-4-opus-20250514": {
|
|
247
282
|
"input_cost_per_token": 15e-6,
|
|
248
283
|
"output_cost_per_token": 75e-6,
|
|
249
284
|
"cache_creation_input_token_cost": 1875e-8,
|
|
250
|
-
"cache_read_input_token_cost": 15e-7
|
|
285
|
+
"cache_read_input_token_cost": 15e-7,
|
|
286
|
+
"max_tokens": 32e3,
|
|
287
|
+
"max_input_tokens": 2e5,
|
|
288
|
+
"max_output_tokens": 32e3
|
|
251
289
|
},
|
|
252
290
|
"claude-4-sonnet-20250514": {
|
|
253
291
|
"input_cost_per_token": 3e-6,
|
|
254
292
|
"output_cost_per_token": 15e-6,
|
|
255
293
|
"cache_creation_input_token_cost": 375e-8,
|
|
256
|
-
"cache_read_input_token_cost": 3e-7
|
|
294
|
+
"cache_read_input_token_cost": 3e-7,
|
|
295
|
+
"max_tokens": 64e3,
|
|
296
|
+
"max_input_tokens": 2e5,
|
|
297
|
+
"max_output_tokens": 64e3
|
|
257
298
|
},
|
|
258
299
|
"claude-3-7-sonnet-latest": {
|
|
259
300
|
"input_cost_per_token": 3e-6,
|
|
260
301
|
"output_cost_per_token": 15e-6,
|
|
261
302
|
"cache_creation_input_token_cost": 375e-8,
|
|
262
|
-
"cache_read_input_token_cost": 3e-7
|
|
303
|
+
"cache_read_input_token_cost": 3e-7,
|
|
304
|
+
"max_tokens": 128e3,
|
|
305
|
+
"max_input_tokens": 2e5,
|
|
306
|
+
"max_output_tokens": 128e3
|
|
263
307
|
},
|
|
264
308
|
"claude-3-7-sonnet-20250219": {
|
|
265
309
|
"input_cost_per_token": 3e-6,
|
|
266
310
|
"output_cost_per_token": 15e-6,
|
|
267
311
|
"cache_creation_input_token_cost": 375e-8,
|
|
268
|
-
"cache_read_input_token_cost": 3e-7
|
|
312
|
+
"cache_read_input_token_cost": 3e-7,
|
|
313
|
+
"max_tokens": 128e3,
|
|
314
|
+
"max_input_tokens": 2e5,
|
|
315
|
+
"max_output_tokens": 128e3
|
|
269
316
|
},
|
|
270
317
|
"claude-3-5-sonnet-20241022": {
|
|
271
318
|
"input_cost_per_token": 3e-6,
|
|
272
319
|
"output_cost_per_token": 15e-6,
|
|
273
320
|
"cache_creation_input_token_cost": 375e-8,
|
|
274
|
-
"cache_read_input_token_cost": 3e-7
|
|
321
|
+
"cache_read_input_token_cost": 3e-7,
|
|
322
|
+
"max_tokens": 8192,
|
|
323
|
+
"max_input_tokens": 2e5,
|
|
324
|
+
"max_output_tokens": 8192
|
|
275
325
|
}
|
|
276
326
|
}));
|
|
277
327
|
return this.cachedPricing = pricing, pricing;
|
|
@@ -330,6 +380,13 @@ var require_usingCtx = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
330
380
|
return null;
|
|
331
381
|
}));
|
|
332
382
|
}
|
|
383
|
+
async getModelContextLimit(modelName) {
|
|
384
|
+
return pipe(this.getModelPricing(modelName), map((pricing) => {
|
|
385
|
+
if (pricing == null) return null;
|
|
386
|
+
const contextLimit = pricing.max_input_tokens ?? pricing.max_tokens;
|
|
387
|
+
return contextLimit ?? null;
|
|
388
|
+
}));
|
|
389
|
+
}
|
|
333
390
|
async calculateCostFromTokens(tokens, modelName) {
|
|
334
391
|
return pipe(this.getModelPricing(modelName), map((pricing) => pricing == null ? 0 : this.calculateCostFromPricing(tokens, pricing)));
|
|
335
392
|
}
|
|
@@ -342,4 +399,4 @@ var require_usingCtx = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
342
399
|
return cost;
|
|
343
400
|
}
|
|
344
401
|
};
|
|
345
|
-
export { BLOCKS_COMPACT_WIDTH_THRESHOLD, BLOCKS_DEFAULT_TERMINAL_WIDTH, BLOCKS_WARNING_THRESHOLD, BURN_RATE_THRESHOLDS, CLAUDE_CONFIG_DIR_ENV, CLAUDE_PROJECTS_DIR_NAME,
|
|
402
|
+
export { BLOCKS_COMPACT_WIDTH_THRESHOLD, BLOCKS_DEFAULT_TERMINAL_WIDTH, BLOCKS_WARNING_THRESHOLD, BURN_RATE_THRESHOLDS, CLAUDE_CONFIG_DIR_ENV, CLAUDE_PROJECTS_DIR_NAME, CONTEXT_LOW_THRESHOLD_ENV, CONTEXT_MEDIUM_THRESHOLD_ENV, DEBUG_MATCH_THRESHOLD_PERCENT, DEFAULT_CLAUDE_CODE_PATH, DEFAULT_CLAUDE_CONFIG_PATH, DEFAULT_CONTEXT_USAGE_THRESHOLDS, DEFAULT_RECENT_DAYS, DEFAULT_REFRESH_INTERVAL_SECONDS, MAX_REFRESH_INTERVAL_SECONDS, MCP_DEFAULT_PORT, MIN_REFRESH_INTERVAL_SECONDS, MIN_RENDER_INTERVAL_MS, PROJECT_ALIASES_ENV, PricingFetcher, USAGE_DATA_GLOB_PATTERN, USER_HOME_DIR, WEEK_DAYS, __commonJSMin, __require, __toESM, inspectError, isFailure, isPromise, isSuccess, map, pipe, require_usingCtx, try_ };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { PricingFetcher } from "./pricing-fetcher-
|
|
1
|
+
import { PricingFetcher } from "./pricing-fetcher-BgDfBZ05.js";
|
|
2
2
|
export { PricingFetcher };
|
package/dist/pricing-fetcher.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PricingFetcher } from "./pricing-fetcher-
|
|
2
|
-
import "./_types-
|
|
3
|
-
import "./logger-
|
|
1
|
+
import { PricingFetcher } from "./pricing-fetcher-CLjmfFHB.js";
|
|
2
|
+
import "./_types-BbEk8t2a.js";
|
|
3
|
+
import "./logger-CHezuMoN.js";
|
|
4
4
|
export { PricingFetcher };
|