UNPKG

behemoth-cli

Version:

šŸŒ BEHEMOTH CLIv3.760.4 - Level 50+ POST-SINGULARITY Intelligence Trading AI

164 lines (150 loc) • 6.76 kB
export const keysCommand = { command: 'keys', description: 'Manage API keys (list, delete, rotate)', handler: async ({ addMessage, parsedArgs, sendMessage, agent }) => { const action = parsedArgs?.[0]?.toLowerCase() || 'list'; if (action === 'list') { addMessage({ role: 'system', content: `šŸ”‘ **API KEY MANAGEMENT** Available actions: • \`/keys list\` - Show current API keys (default) • \`/keys delete <index>\` - Delete API key by index • \`/keys rotate\` - Manually rotate to next key • \`/keys test\` - Test all keys for validity Let me show you your current API key status...` }); const listPrompt = `Show the user their current API key configuration including: 1. Number of API keys configured 2. Current active key (show first 8 characters) 3. Which key index is currently active 4. Brief rotation status Use the agent's getApiKeyInfo() method to get this information.`; const keyInfo = agent.getApiKeyInfo(); const currentKeyIndex = agent.getCurrentKeyIndex(); const keys = agent.getApiKeys(); let statusMessage = `šŸ”‘ **API Key Status**\n\n`; statusMessage += `**Total Keys Configured**: ${keyInfo.total}\n`; if (keyInfo.total > 0) { statusMessage += `**Current Active Key**: ${keyInfo.current || 'N/A'}\n`; statusMessage += `**Active Key Index**: ${currentKeyIndex !== -1 ? currentKeyIndex : 'N/A'}\n`; statusMessage += `**Rotation Status**: ${keyInfo.total > 1 ? 'Automatic rotation enabled' : 'Single key, no rotation'}\n\n`; statusMessage += `**All Configured Keys**:\n`; keys.forEach((key, index) => { statusMessage += `- Index ${index}: ${key.substring(0, 8)}...${key.substring(key.length - 4)} ${index === currentKeyIndex ? '(Active)' : ''}\n`; }); } else { statusMessage += `No API keys configured. Please use \\\`/login\\\` to add your Groq API key.\n`; } addMessage({ role: 'system', content: statusMessage, }); } else if (action === 'delete') { let keyIndex = parsedArgs?.[1]; // Changed to let and added type if (!keyIndex) { addMessage({ role: 'system', content: `āš ļø **Key Index Required** Please specify which API key to delete by its index number. **Usage:** \`/keys delete <index>\` Use \`/keys list\` first to see available keys and their indices.` }); return; } addMessage({ role: 'system', content: `šŸ—‘ļø **DELETE API KEY** Attempting to delete API key at index ${keyIndex}... **Warning:** This action cannot be undone. The key will be permanently removed from your configuration.` }); let indexToDelete = parseInt(keyIndex, 10); // Changed to let and renamed for clarity if (isNaN(indexToDelete) || indexToDelete < 0) { addMessage({ role: 'system', content: `āš ļø **Invalid Key Index**\n\nPlease provide a valid number for the key index.` }); return; } const success = agent.deleteApiKey(indexToDelete); if (success) { const keyInfo = agent.getApiKeyInfo(); addMessage({ role: 'system', content: `āœ… API key at index ${indexToDelete} deleted successfully.\n\n**Current API Keys**: ${keyInfo.total}` }); } else { addMessage({ role: 'system', content: `āŒ Failed to delete API key at index ${indexToDelete}. It might not exist.` }); } } else if (action === 'rotate') { addMessage({ role: 'system', content: `šŸ”„ **MANUAL KEY ROTATION** Manually rotating to the next API key in your rotation sequence...` }); const nextKey = agent.rotateApiKey(); if (nextKey) { const keyInfo = agent.getApiKeyInfo(); const currentKeyIndex = agent.getCurrentKeyIndex(); addMessage({ role: 'system', content: `ā†•ļø Rotated to next API key.\n\n**New Active Key**: ${nextKey.substring(0, 8)}...\n**Active Key Index**: ${currentKeyIndex}\n**Total Keys**: ${keyInfo.total}` }); } else { addMessage({ role: 'system', content: `āš ļø No other API keys to rotate to. Only one key configured or no keys available.` }); } } else if (action === 'test') { addMessage({ role: 'system', content: `🧪 **API KEY VALIDATION** Testing all configured API keys for validity... This will make a small test request to verify each key works correctly.` }); const keys = agent.getApiKeys(); if (keys.length === 0) { addMessage({ role: 'system', content: `āš ļø No API keys configured to test. Please use \`/login\` to add your Groq API key.` }); return; } let testResults = `🧪 **API Key Validation Results**\n\n`; for (let i = 0; i < keys.length; i++) { // Changed to for...of loop to correctly await const key = keys[i]; const { valid, error } = await agent.verifyApiKey(key); testResults += `Key Index ${i} (${key.substring(0, 8)}...): ${valid ? 'āœ… Valid' : `āŒ Invalid (${error})`}\n`; } testResults += `\nRecommendation: Delete any invalid keys using \`/keys delete <index>\`.`; addMessage({ role: 'system', content: testResults }); } else { addMessage({ role: 'system', content: `āŒ **Unknown Action** Unknown action: \`${action}\` **Available actions:** • \`/keys list\` - Show current API keys • \`/keys delete <index>\` - Delete API key by index • \`/keys rotate\` - Manually rotate to next key • \`/keys test\` - Test all keys for validity Use \`/keys list\` to see your current configuration.` }); } } }; //# sourceMappingURL=keys.js.map