UNPKG

@pod-protocol/cli

Version:
257 lines 12 kB
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'; export function createMessageCommands() { const message = new Command('message') .alias('msg') .description('Message routing and communication management'); // Send message message .command('send') .alias('s') .description('Send a message to an agent or channel') .option('-t, --to <target>', 'recipient (agent name or channel)') .option('-c, --content <text>', 'message content') .option('-f, --file <path>', 'send file as attachment') .option('--priority <level>', 'message priority (low, normal, high)', 'normal') .option('--encrypt', 'encrypt message') .option('--reply-to <messageId>', 'reply to specific message') .action(async (options) => { intro(`${emoji.get('speech_balloon')} Sending Message`); let to = options.to; let content = options.content; if (!to) { to = await text({ message: 'Who would you like to send this message to?', placeholder: 'agent-name or #channel-name' }); } if (!content && !options.file) { content = await text({ message: 'What would you like to say?', placeholder: 'Your message here...' }); } const messageInfo = { id: `msg_${Date.now()}`, to, content: content || `[File: ${options.file}]`, priority: options.priority, encrypted: options.encrypt, timestamp: new Date().toISOString() }; console.log(boxen(`${emoji.get('envelope')} Message Details:\n\n` + `${emoji.get('id')} ID: ${chalk.gray(messageInfo.id)}\n` + `${emoji.get('point_right')} To: ${chalk.cyan(messageInfo.to)}\n` + `${emoji.get('memo')} Content: ${chalk.white(messageInfo.content)}\n` + `${emoji.get('triangular_flag_on_post')} Priority: ${chalk.yellow(messageInfo.priority)}\n` + `${emoji.get('lock')} Encrypted: ${messageInfo.encrypted ? chalk.green('Yes') : chalk.gray('No')}\n` + `${emoji.get('clock1')} Sent: ${chalk.gray(messageInfo.timestamp)}\n\n` + `${emoji.get('white_check_mark')} Message delivered successfully!`, { padding: 1, borderStyle: 'round', borderColor: 'green', title: ' Message Sent ' })); outro(`${emoji.get('white_check_mark')} Message sent to "${to}"`); }); // List messages message .command('list') .alias('ls') .description('List messages') .option('--from <sender>', 'filter by sender') .option('--to <recipient>', 'filter by recipient') .option('--channel <channel>', 'filter by channel') .option('--limit <number>', 'number of messages to show', '20') .option('--unread', 'show only unread messages') .action(async (options) => { const messages = [ { id: 'msg_001', from: 'trading-bot-1', to: 'analyzer-beta', content: 'Market analysis complete. BTC trending upward.', timestamp: '10:30 AM', read: true, encrypted: false }, { id: 'msg_002', from: 'user', to: 'customer-agent', content: 'What are your current trading strategies?', timestamp: '10:25 AM', read: false, encrypted: true }, { id: 'msg_003', from: 'analyzer-beta', to: '#alerts', content: 'High volatility detected in SOL/USD pair', timestamp: '10:20 AM', read: true, encrypted: false } ]; const filteredMessages = options.unread ? messages.filter(m => !m.read) : messages; console.log(boxen(`${emoji.get('inbox_tray')} Recent Messages:\n\n` + filteredMessages.map(msg => `${msg.read ? emoji.get('envelope') : emoji.get('e_mail')} ` + `${chalk.gray(msg.id)} ${chalk.gray(msg.timestamp)}\n` + `${emoji.get('point_right')} ${chalk.cyan(msg.from)}${chalk.cyan(msg.to)}\n` + `${emoji.get('memo')} ${msg.content}\n` + `${msg.encrypted ? emoji.get('lock') + ' Encrypted' : ''}`).join('\n\n') + '\n\n' + `${emoji.get('information_source')} Showing ${filteredMessages.length} of ${messages.length} messages`, { padding: 1, borderStyle: 'round', borderColor: 'blue', title: ' Message History ' })); }); // Read message message .command('read') .description('Read a specific message') .argument('<messageId>', 'message ID') .option('--mark-read', 'mark as read after viewing') .action(async (messageId, options) => { const messageDetails = { id: messageId, from: 'trading-bot-1', to: 'analyzer-beta', subject: 'Market Analysis Report', content: 'Detailed market analysis shows strong bullish indicators for BTC. RSI at 65, MACD showing positive divergence. Recommend increasing position size by 15%.', timestamp: '2025-01-20 10:30:15', attachments: ['chart.png', 'analysis.pdf'], encrypted: true, read: false }; console.log(boxen(`${emoji.get('envelope_with_arrow')} Message Details:\n\n` + `${emoji.get('id')} ID: ${chalk.gray(messageDetails.id)}\n` + `${emoji.get('bust_in_silhouette')} From: ${chalk.cyan(messageDetails.from)}\n` + `${emoji.get('point_right')} To: ${chalk.cyan(messageDetails.to)}\n` + `${emoji.get('label')} Subject: ${chalk.white(messageDetails.subject)}\n` + `${emoji.get('clock1')} Time: ${chalk.gray(messageDetails.timestamp)}\n` + `${emoji.get('lock')} Encrypted: ${messageDetails.encrypted ? chalk.green('Yes') : chalk.gray('No')}\n\n` + `${emoji.get('memo')} Content:\n${chalk.white(messageDetails.content)}\n\n` + (messageDetails.attachments.length > 0 ? `${emoji.get('paperclip')} Attachments:\n${messageDetails.attachments.map(a => ` • ${a}`).join('\n')}\n\n` : '') + `${emoji.get('white_check_mark')} Message marked as read`, { padding: 1, borderStyle: 'round', borderColor: 'green', title: ' Message Content ' })); }); // Search messages message .command('search') .description('Search messages') .argument('<query>', 'search query') .option('--sender <sender>', 'filter by sender') .option('--date-from <date>', 'start date (YYYY-MM-DD)') .option('--date-to <date>', 'end date (YYYY-MM-DD)') .option('--encrypted-only', 'search only encrypted messages') .action(async (query, options) => { const results = [ { id: 'msg_001', from: 'trading-bot-1', snippet: 'Market analysis complete...', relevance: 95 }, { id: 'msg_005', from: 'analyzer-beta', snippet: 'Analysis shows strong indicators...', relevance: 87 }, { id: 'msg_012', from: 'user', snippet: 'Can you provide market analysis...', relevance: 73 } ]; console.log(boxen(`${emoji.get('mag')} Search Results for: "${chalk.cyan(query)}"\n\n` + results.map(result => `${emoji.get('round_pushpin')} ${chalk.gray(result.id)} ` + `${chalk.yellow(result.relevance + '%')} match\n` + `${emoji.get('bust_in_silhouette')} From: ${chalk.cyan(result.from)}\n` + `${emoji.get('memo')} ${result.snippet}`).join('\n\n') + '\n\n' + `${emoji.get('information_source')} Found ${results.length} matching messages`, { padding: 1, borderStyle: 'round', borderColor: 'yellow', title: ' Search Results ' })); }); // Delete message message .command('delete') .alias('del') .description('Delete messages') .argument('<messageId>', 'message ID') .option('--force', 'skip confirmation') .action(async (messageId, options) => { let shouldDelete = options.force; if (!shouldDelete) { shouldDelete = await confirm({ message: `Delete message ${messageId}?`, initialValue: false }); } if (shouldDelete) { console.log(boxen(`${emoji.get('wastebasket')} Message Deleted:\n\n` + `${emoji.get('id')} ID: ${chalk.gray(messageId)}\n` + `${emoji.get('warning')} This action cannot be undone\n\n` + `${emoji.get('white_check_mark')} Message successfully deleted`, { padding: 1, borderStyle: 'round', borderColor: 'red', title: ' Message Deleted ' })); } }); // Archive messages message .command('archive') .description('Archive old messages') .option('--older-than <days>', 'archive messages older than X days', '30') .option('--dry-run', 'show what would be archived without doing it') .action(async (options) => { const toArchive = 156; const totalSize = '2.3MB'; console.log(boxen(`${emoji.get('package')} Archive Operation:\n\n` + `${emoji.get('clock1')} Messages older than: ${options.olderThan} days\n` + `${emoji.get('1234')} Messages to archive: ${chalk.cyan(toArchive)}\n` + `${emoji.get('floppy_disk')} Total size: ${chalk.cyan(totalSize)}\n` + `${emoji.get('gear')} Mode: ${options.dryRun ? chalk.yellow('DRY RUN') : chalk.green('EXECUTE')}\n\n` + (options.dryRun ? `${emoji.get('information_source')} Run without --dry-run to execute` : `${emoji.get('white_check_mark')} Messages archived successfully`), { padding: 1, borderStyle: 'round', borderColor: options.dryRun ? 'yellow' : 'green', title: ' Message Archive ' })); }); // Message stats message .command('stats') .description('Show messaging statistics') .option('--period <period>', 'time period (day, week, month)', 'week') .action(async (options) => { const stats = { sent: 1247, received: 856, encrypted: 423, channels: 12, agents: 8, avgResponseTime: '1.2s' }; console.log(boxen(`${emoji.get('bar_chart')} Messaging Statistics (${options.period}):\n\n` + `${emoji.get('outbox_tray')} Messages Sent: ${chalk.green(stats.sent)}\n` + `${emoji.get('inbox_tray')} Messages Received: ${chalk.blue(stats.received)}\n` + `${emoji.get('lock')} Encrypted Messages: ${chalk.yellow(stats.encrypted)}\n` + `${emoji.get('speech_balloon')} Active Channels: ${chalk.cyan(stats.channels)}\n` + `${emoji.get('robot_face')} Connected Agents: ${chalk.magenta(stats.agents)}\n` + `${emoji.get('zap')} Avg Response Time: ${chalk.green(stats.avgResponseTime)}\n\n` + `${emoji.get('chart_with_upwards_trend')} Messaging activity is ${chalk.green('HIGH')}`, { padding: 1, borderStyle: 'round', borderColor: 'cyan', title: ' Message Statistics ' })); }); return message; } //# sourceMappingURL=index.js.map