UNPKG

@light-merlin-dark/tok

Version:

Fast token estimation and cost calculation for enterprise LLMs with CLI and MCP support

85 lines (80 loc) 3.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.trackResetCommand = exports.trackSummaryCommand = void 0; const core_1 = require("../shared/core"); const common_1 = require("../common"); const index_1 = require("../../index"); const tracker_1 = require("../utils/tracker"); exports.trackSummaryCommand = (0, core_1.createCommand)({ description: 'Show cost tracking summary', help: ` Usage: tok track summary [options] Description: Displays a summary of all tracked token usage and costs for the current session. Options: --format <format> Output format: json, table, human (default: human) Examples: tok track summary tok track summary --format json tok track summary --format table `, options: [ { flag: 'format', description: 'Output format', type: 'string', default: 'human' } ], async execute(args, options) { const opts = options; const tracker = (0, tracker_1.getTracker)(); const summary = tracker.getSummary(); if (summary.models.length === 0) { common_1.logger.warn('No tracking data available. Use --track flag with estimate command.'); return { success: true, data: summary }; } if (opts.format === 'json') { (0, common_1.formatJson)(summary); } else if (opts.format === 'table') { (0, common_1.formatTable)(summary.modelBreakdown); console.log(`\nTotal Cost: ${index_1.CostCalculator.formatCost(summary.totalCost)}`); } else { console.log(''); (0, common_1.formatHuman)('Cost Tracking Summary', [ { label: 'Duration', value: `${summary.duration.toFixed(1)}s` }, { label: 'Total Cost', value: index_1.CostCalculator.formatCost(summary.totalCost) }, { label: 'Total Tokens', value: summary.totalTokens.prompt + summary.totalTokens.completion } ]); if (summary.modelBreakdown.length > 0) { console.log(''); common_1.logger.info('Model Breakdown:'); summary.modelBreakdown.forEach(item => { console.log(`\n${item.model}:`); console.log(` Tokens: ${item.tokens.prompt} prompt, ${item.tokens.completion} completion`); console.log(` Cost: ${index_1.CostCalculator.formatCost(item.cost.total)}`); }); } console.log(''); } return { success: true, data: summary }; } }); exports.trackResetCommand = (0, core_1.createCommand)({ description: 'Reset cost tracking data', help: ` Usage: tok track reset Description: Resets all cost tracking data for the current session. Examples: tok track reset `, async execute() { (0, tracker_1.resetTracker)(); common_1.logger.success('✓ Cost tracking data reset'); return { success: true }; } }); //# sourceMappingURL=track.js.map