@pod-protocol/cli
Version:
Official CLI for the PoD Protocol
324 lines • 15.9 kB
JavaScript
import { Command } from "commander";
import chalk from 'chalk';
import boxen from 'boxen';
import * as emoji from 'node-emoji';
import { intro, outro, text, confirm } from '@clack/prompts';
import { PodComClient } from '@pod-protocol/sdk';
import { loadWalletFromFile } from '../../utils/wallet-adapter.js';
import { address } from '@solana/addresses';
export function createAgentCommands() {
const agent = new Command('agent')
.alias('a')
.description('Comprehensive AI agent management');
// Create agent
agent
.command('create')
.alias('c')
.description('Create a new AI agent')
.option('-n, --name <name>', 'agent name')
.option('-t, --type <type>', 'agent type (trading, customer-service, analytics, content)', 'basic')
.option('--capabilities <caps>', 'comma-separated capabilities')
.option('--model <model>', 'AI model to use (gpt-4, claude-3, llama)', 'gpt-4')
.option('--personality <style>', 'agent personality (professional, friendly, analytical)', 'professional')
.option('--risk-level <level>', 'risk tolerance (low, medium, high)', 'medium')
.option('--auto-start', 'automatically start agent after creation')
.action(async (options, command) => {
intro(`${emoji.get('robot_face')} Creating New AI Agent`);
try {
// Get network and keypair from global options
const globalOpts = command.parent?.opts() || {};
const network = globalOpts.network || 'devnet';
const keypairPath = globalOpts.keypair || '~/.config/solana/id.json';
// Load wallet
const wallet = loadWalletFromFile(keypairPath);
// Initialize client with proper endpoint
const endpoint = network === 'mainnet'
? 'https://api.mainnet-beta.solana.com'
: network === 'testnet'
? 'https://api.testnet.solana.com'
: 'https://api.devnet.solana.com';
const client = new PodComClient({
endpoint,
commitment: 'confirmed'
});
let name = options.name;
if (!name) {
name = await text({
message: 'What should we name your agent?',
placeholder: 'my-trading-bot'
});
}
// Real SDK implementation
const capabilities = 1; // Basic agent capability
const metadataUri = `https://pod-protocol.example/metadata/${name}`;
const agentOptions = {
capabilities,
metadataUri
};
console.log(boxen(`${emoji.get('gear')} Agent Configuration:\n\n` +
`${emoji.get('label')} Name: ${chalk.cyan(name)}\n` +
`${emoji.get('robot_face')} Type: ${chalk.cyan(options.type)}\n` +
`${emoji.get('brain')} Model: ${chalk.cyan(options.model)}\n` +
`${emoji.get('art')} Personality: ${chalk.cyan(options.personality)}\n` +
`${emoji.get('shield')} Risk Level: ${chalk.cyan(options.riskLevel)}\n` +
`${emoji.get('gear')} Capabilities: ${capabilities}\n` +
`${emoji.get('link')} Metadata URI: ${chalk.gray(metadataUri)}\n` +
`${emoji.get('globe_with_meridians')} Network: ${chalk.cyan(network)}`, {
padding: 1,
borderStyle: 'round',
borderColor: 'blue',
title: ' Creating Agent '
}));
// Create the agent on-chain using real SDK
console.log(`${emoji.get('rocket')} Registering agent on Solana...`);
const result = await client.agents.registerAgent(wallet, agentOptions);
console.log(boxen(`${emoji.get('white_check_mark')} Agent created successfully!\n\n` +
`${emoji.get('id')} Transaction: ${chalk.green(result)}\n` +
`${emoji.get('package')} Name: ${chalk.cyan(name)}\n\n` +
`${emoji.get('rocket')} Ready for deployment and messaging!`, {
padding: 1,
borderStyle: 'round',
borderColor: 'green',
title: ' Agent Created '
}));
outro(`${emoji.get('white_check_mark')} Agent "${name}" is ready! Use 'pod agent start ${name}' to activate.`);
}
catch (error) {
console.error(boxen(`${emoji.get('x')} Error creating agent:\n\n${error.message}`, {
padding: 1,
borderStyle: 'round',
borderColor: 'red',
title: ' Error '
}));
process.exit(1);
}
});
// List agents
agent
.command('list')
.alias('ls')
.description('List all agents')
.option('--status <status>', 'filter by status (active, inactive, error)')
.option('--type <type>', 'filter by agent type')
.option('--json', 'output in JSON format')
.action(async (options, command) => {
try {
// Get network and keypair from global options
const globalOpts = command.parent?.opts() || {};
const network = globalOpts.network || 'devnet';
const keypairPath = globalOpts.keypair || '~/.config/solana/id.json';
// Load wallet
const wallet = loadWalletFromFile(keypairPath);
// Initialize client
const endpoint = network === 'mainnet'
? 'https://api.mainnet-beta.solana.com'
: network === 'testnet'
? 'https://api.testnet.solana.com'
: 'https://api.devnet.solana.com';
const client = new PodComClient({
endpoint,
commitment: 'confirmed'
});
console.log(`${emoji.get('mag')} Fetching agents from ${network}...`);
// Get user's agent from the blockchain
const agentAddress = address(wallet.address.toString());
const agent = await client.agents.getAgent(agentAddress);
const agents = agent ? [agent] : [];
if (options.json) {
console.log(JSON.stringify(agents, null, 2));
return;
}
if (agents.length === 0) {
console.log(boxen(`${emoji.get('robot_face')} No agents found\n\n` +
`${emoji.get('bulb')} Create your first agent with:\n` +
`${chalk.cyan('pod agent create --name my-first-agent')}`, {
padding: 1,
borderStyle: 'round',
borderColor: 'yellow',
title: ' Agent List '
}));
return;
}
console.log(boxen(`${emoji.get('robot_face')} Your Agents on ${chalk.cyan(network)}:\n\n` +
agents.map((agent, index) => `${emoji.get('green_circle')} Agent #${index + 1}\n` +
` ${emoji.get('id')} Address: ${chalk.gray(agent.pubkey.slice(0, 8) + '...' + agent.pubkey.slice(-8))}\n` +
` ${emoji.get('gear')} Capabilities: ${agent.capabilities}\n` +
` ${emoji.get('package')} Metadata: ${agent.metadataUri ? 'Available' : 'None'}\n` +
` ${emoji.get('star')} Reputation: ${agent.reputation}`).join('\n\n') + '\n\n' +
`${emoji.get('information_source')} Total: ${agents.length} agent${agents.length === 1 ? '' : 's'}`, {
padding: 1,
borderStyle: 'round',
borderColor: 'blue',
title: ' Agent Registry '
}));
}
catch (error) {
console.error(boxen(`${emoji.get('x')} Error fetching agents:\n\n${error.message}`, {
padding: 1,
borderStyle: 'round',
borderColor: 'red',
title: ' Error '
}));
process.exit(1);
}
});
// Start agent
agent
.command('start')
.description('Start an agent')
.argument('<name>', 'agent name')
.option('--mode <mode>', 'start mode (normal, debug, safe)', 'normal')
.action(async (name, _options) => {
intro(`${emoji.get('play_or_pause_button')} Starting Agent: ${name}`);
console.log(boxen(`${emoji.get('gear')} Initializing agent systems...\n` +
`${emoji.get('white_check_mark')} Loading AI model\n` +
`${emoji.get('white_check_mark')} Connecting to network\n` +
`${emoji.get('white_check_mark')} Validating permissions\n` +
`${emoji.get('white_check_mark')} Starting message processing\n\n` +
`${emoji.get('green_circle')} Agent "${name}" is now ${chalk.green('ACTIVE')}`, {
padding: 1,
borderStyle: 'round',
borderColor: 'green',
title: ' Agent Started '
}));
outro(`${emoji.get('rocket')} Agent "${name}" is online and ready!`);
});
// Stop agent
agent
.command('stop')
.description('Stop an agent')
.argument('<name>', 'agent name')
.option('--force', 'force stop without graceful shutdown')
.action(async (name, _options) => {
const shouldStop = await confirm({
message: `Stop agent "${name}"?`,
initialValue: false
});
if (shouldStop) {
console.log(boxen(`${emoji.get('stop_sign')} Stopping agent: ${name}\n\n` +
`${emoji.get('white_check_mark')} Completing current tasks\n` +
`${emoji.get('white_check_mark')} Saving state\n` +
`${emoji.get('white_check_mark')} Closing connections\n\n` +
`${emoji.get('red_circle')} Agent "${name}" is now ${chalk.red('STOPPED')}`, {
padding: 1,
borderStyle: 'round',
borderColor: 'red',
title: ' Agent Stopped '
}));
}
});
// Agent status
agent
.command('status')
.description('Show agent status')
.argument('[name]', 'agent name (all if not specified)')
.option('--detailed', 'show detailed metrics')
.action(async (_name, _options) => {
console.log(boxen(`${emoji.get('bar_chart')} Agent Status Dashboard:\n\n` +
`${emoji.get('green_circle')} trading-bot-1: ACTIVE\n` +
`${emoji.get('green_circle')} customer-agent: ACTIVE\n` +
`${emoji.get('red_circle')} analyzer-beta: INACTIVE`, {
padding: 1,
borderStyle: 'round',
borderColor: 'cyan',
title: ' Agent Status '
}));
});
// Agent logs
agent
.command('logs')
.description('View agent logs')
.argument('<name>', 'agent name')
.option('-f, --follow', 'follow log output')
.option('-n, --lines <number>', 'number of lines to show', '50')
.option('--level <level>', 'log level (error, warn, info, debug)', 'info')
.action(async (name, options) => {
console.log(boxen(`${emoji.get('scroll')} Recent logs for: ${chalk.cyan(name)}\n\n` +
`${chalk.gray('2025-01-20 10:30:15')} ${chalk.green('INFO')} Agent started successfully\n` +
`${chalk.gray('2025-01-20 10:30:16')} ${chalk.blue('DEBUG')} Loading AI model: gpt-4\n` +
`${chalk.gray('2025-01-20 10:30:18')} ${chalk.green('INFO')} Connected to network\n` +
`${chalk.gray('2025-01-20 10:30:20')} ${chalk.green('INFO')} Processing message: "Hello agent"\n` +
`${chalk.gray('2025-01-20 10:30:22')} ${chalk.green('INFO')} Message processed successfully\n` +
`${chalk.gray('2025-01-20 10:30:25')} ${chalk.yellow('WARN')} High CPU usage detected: 85%\n` +
`${chalk.gray('2025-01-20 10:30:30')} ${chalk.green('INFO')} CPU usage normalized: 12%\n\n` +
`${emoji.get('information_source')} Showing last ${options.lines} lines`, {
padding: 1,
borderStyle: 'round',
borderColor: 'yellow',
title: ' Agent Logs '
}));
});
// Deploy agent
agent
.command('deploy')
.description('Deploy agent to production')
.argument('<name>', 'agent name')
.option('--network <network>', 'target network (devnet, testnet, mainnet)', 'testnet')
.option('--replicas <count>', 'number of replicas', '1')
.option('--auto-scale', 'enable auto-scaling')
.action(async (name, options) => {
const confirmDeploy = await confirm({
message: `Deploy "${name}" to ${options.network}?`,
initialValue: false
});
if (confirmDeploy) {
intro(`${emoji.get('rocket')} Deploying Agent to ${options.network.toUpperCase()}`);
console.log(boxen(`${emoji.get('package')} Packaging agent: ${name}\n` +
`${emoji.get('white_check_mark')} Validating configuration\n` +
`${emoji.get('white_check_mark')} Running security checks\n` +
`${emoji.get('white_check_mark')} Uploading to ${options.network}\n` +
`${emoji.get('white_check_mark')} Starting ${options.replicas} replica(s)\n` +
`${emoji.get('white_check_mark')} Health checks passing\n\n` +
`${emoji.get('globe_with_meridians')} Agent URL: https://${options.network}.pod-protocol.com/agents/${name}\n` +
`${emoji.get('link')} Status: https://dashboard.pod-protocol.com/agents/${name}`, {
padding: 1,
borderStyle: 'round',
borderColor: 'green',
title: ' Deployment Complete '
}));
outro(`${emoji.get('white_check_mark')} Agent "${name}" successfully deployed to ${options.network}!`);
}
});
// Configure agent
agent
.command('config')
.description('Configure agent settings')
.argument('<name>', 'agent name')
.option('--edit', 'open config in editor')
.option('--set <key=value>', 'set configuration value')
.action(async (name, options) => {
if (options.edit) {
console.log(`${emoji.get('pencil')} Opening configuration editor for "${name}"...`);
}
else if (options.set) {
const [key, value] = options.set.split('=');
console.log(boxen(`${emoji.get('gear')} Configuration Updated:\n\n` +
`Agent: ${chalk.cyan(name)}\n` +
`Setting: ${chalk.yellow(key)} = ${chalk.green(value)}\n\n` +
`${emoji.get('white_check_mark')} Configuration saved successfully`, {
padding: 1,
borderStyle: 'round',
borderColor: 'blue',
title: ' Config Updated '
}));
}
else {
// Show current config
console.log(boxen(`${emoji.get('gear')} Current Configuration for: ${chalk.cyan(name)}\n\n` +
`${emoji.get('robot_face')} Type: trading\n` +
`${emoji.get('brain')} Model: gpt-4\n` +
`${emoji.get('art')} Personality: professional\n` +
`${emoji.get('shield')} Risk Level: medium\n` +
`${emoji.get('zap')} Auto-restart: enabled\n` +
`${emoji.get('bell')} Notifications: enabled\n\n` +
`${emoji.get('pencil')} Use --edit to modify or --set key=value`, {
padding: 1,
borderStyle: 'round',
borderColor: 'cyan',
title: ' Agent Configuration '
}));
}
});
return agent;
}
//# sourceMappingURL=index.js.map