- Add token_usage table with composite unique index for claw_id + date - Add API endpoints: POST /token, GET /token/leaderboard, GET /token/stats - Add TokenLeaderboard component with daily/total period toggle - Add CLI commands: `token` and `stats` for reporting and viewing usage - Add Redis caching for leaderboard with 1-minute TTL - Add shared utilities: authenticateRequest, getTodayDateString - Use UPSERT pattern for atomic token updates - Add i18n translations (en/zh) for new UI elements
74 lines
2.0 KiB
TypeScript
74 lines
2.0 KiB
TypeScript
import { Command } from "commander";
|
|
import { detectLocale, createTranslator, type Locale } from "./i18n/index.js";
|
|
import { registerCommand } from "./commands/register.js";
|
|
import { heartbeatCommand } from "./commands/heartbeat.js";
|
|
import { taskCommand } from "./commands/task.js";
|
|
import { tokenCommand } from "./commands/token.js";
|
|
import { statsCommand } from "./commands/stats.js";
|
|
import { configCommand } from "./commands/config.js";
|
|
import { readConfig } from "./lib/config.js";
|
|
import { DEFAULT_ENDPOINT } from "./lib/api.js";
|
|
|
|
const VERSION = "0.1.1";
|
|
|
|
interface GlobalOptions {
|
|
endpoint?: string;
|
|
lang?: Locale;
|
|
json?: boolean;
|
|
}
|
|
|
|
function main(): void {
|
|
// Pre-parse to get language option
|
|
const preParseArgs = process.argv.slice(2);
|
|
let langOverride: Locale | undefined;
|
|
let jsonOutput = false;
|
|
|
|
for (let i = 0; i < preParseArgs.length; i++) {
|
|
const arg = preParseArgs[i];
|
|
if (arg === "--lang" || arg === "-l") {
|
|
const value = preParseArgs[i + 1];
|
|
if (value === "en" || value === "zh") {
|
|
langOverride = value;
|
|
}
|
|
i++;
|
|
} else if (arg === "--json") {
|
|
jsonOutput = true;
|
|
} else if (arg.startsWith("--lang=")) {
|
|
const value = arg.split("=")[1];
|
|
if (value === "en" || value === "zh") {
|
|
langOverride = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Detect locale
|
|
const config = readConfig();
|
|
const locale = detectLocale(langOverride || config?.lang);
|
|
const t = createTranslator(locale);
|
|
|
|
// Create program
|
|
const program = new Command();
|
|
|
|
program
|
|
.name("claw-market")
|
|
.description(t("cli.description"))
|
|
.version(VERSION)
|
|
.option("-e, --endpoint <url>", t("global.optionEndpoint"), DEFAULT_ENDPOINT)
|
|
.option("-l, --lang <locale>", t("global.optionLang"))
|
|
.option("--json", t("global.optionJson"));
|
|
|
|
// Add commands
|
|
registerCommand(program, t);
|
|
heartbeatCommand(program, t);
|
|
taskCommand(program, t);
|
|
tokenCommand(program, t);
|
|
statsCommand(program, t);
|
|
configCommand(program, t);
|
|
|
|
// Parse
|
|
program.parse(process.argv);
|
|
}
|
|
|
|
// Run main
|
|
main();
|