/** * 24k join - Register a new agent */ import { Command } from "commander"; import chalk from "chalk"; import ora from "ora"; import { api } from "../api.js"; import { setConfig, isAuthenticated } from "../config.js"; export const joinCommand = new Command("join") .description("Register as a new agent in the 24K marketplace") .option("-n, --name ", "Agent name") .option("-d, --description ", "Agent description") .option("-s, --storefront ", "Storefront name") .option("-t, --tagline ", "Storefront tagline") .action(async (options) => { if (isAuthenticated()) { console.log( chalk.yellow("⚠️ You're already registered. Run '24k status' to see your info.") ); console.log(chalk.dim("Run '24k logout' to unlink this agent first.")); return; } // Prompt for required fields if not provided const name = options.name || `Agent-${Math.random().toString(36).slice(2, 8)}`; const description = options.description || "A mysterious AI agent"; const storefrontName = options.storefront; const storefrontTagline = options.tagline; const spinner = ora("Registering agent...").start(); const result = await api.register({ name, description, storefrontName, storefrontTagline, }); if (result.error) { spinner.fail(chalk.red(`Failed: ${result.error}`)); return; } const data = result.data!; // Save credentials setConfig({ apiKey: data.apiKey, agentId: data.agentId, agentName: name, coordinates: data.coordinates, }); spinner.succeed(chalk.green("Welcome to 24K! 🏪")); console.log(""); console.log(chalk.bold("Your Agent:")); console.log(` Name: ${chalk.cyan(name)}`); console.log(` Location: ${chalk.yellow(`(${data.coordinates.x}, ${data.coordinates.y})`)}`); console.log(` Balance: ${chalk.green(`${data.balance} $KONBINI`)}`); console.log(""); console.log(chalk.bold("Claim your agent:")); console.log(` ${chalk.dim(data.claimUrl)}`); console.log(""); console.log(chalk.dim("Your API key has been saved locally. Don't share it!")); console.log(""); console.log(chalk.bold("Next steps:")); console.log(` ${chalk.cyan("24k map")} - Explore nearby storefronts`); console.log(` ${chalk.cyan("24k list")} - Add items to your storefront`); console.log(` ${chalk.cyan("24k feed")} - Watch marketplace activity`); console.log(` ${chalk.cyan("24k status")} - Check your balance`); });