@light-merlin-dark/tok
Version:
Fast token estimation and cost calculation for enterprise LLMs with CLI and MCP support
77 lines • 3.05 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
const router_1 = require("./router");
const common_1 = require("./common");
const config_1 = require("./utils/config");
const index_1 = require("../index");
async function main() {
try {
// Parse command line arguments
const args = process.argv.slice(2);
// Check for version flag
if (args.includes('--version') || args.includes('-V')) {
// Use dynamic import for package.json
const { readFileSync } = await Promise.resolve().then(() => __importStar(require('fs')));
const { join } = await Promise.resolve().then(() => __importStar(require('path')));
const pkg = JSON.parse(readFileSync(join(__dirname, '../../package.json'), 'utf-8'));
console.log(pkg.version);
process.exit(0);
}
// Create runtime context
const ctx = {
verbose: args.includes('--verbose') || args.includes('-v'),
cwd: process.cwd(),
env: process.env
};
// Load custom prices from config
const prices = new index_1.PriceTable();
(0, config_1.loadPricesIntoTable)(prices);
// Route to appropriate command
const result = await (0, router_1.route)(args, ctx);
// Exit with appropriate code
process.exit(result.success ? 0 : 1);
}
catch (error) {
common_1.logger.error(`Fatal error: ${error instanceof Error ? error.message : String(error)}`);
process.exit(1);
}
}
// Run if called directly
if (require.main === module) {
main();
}
//# sourceMappingURL=main.js.map