UNPKG

plazbot-cli

Version:
138 lines (119 loc) 5.53 kB
import { Command } from 'commander'; import { Agent } from 'plazbot'; import inquirer from 'inquirer'; import { getStoredCredentials } from '../../utils/credentials'; import { logger } from '../../utils/logger'; import { createSpinner, theme, section, kvPair } from '../../utils/ui'; import { AgentCommandOptions } from '../../types/agent'; const setGroup = new Command('set') .description('Configurar rapidamente propiedades del agente'); // Set greeting setGroup.command('greeting') .description('Cambiar el saludo del agente') .argument('<agentId>', 'ID del agente') .argument('<greeting>', 'Nuevo saludo') .option('--dev', 'Usar ambiente de desarrollo', false) .action(async (agentId: string, greeting: string, options: AgentCommandOptions) => { try { const credentials = await getStoredCredentials(); const agent = new Agent({ workspaceId: credentials.workspace, apiKey: credentials.apiKey, zone: credentials.zone, ...(options.dev && { customUrl: "http://localhost:5090" }) }); const spinner = createSpinner('Actualizando saludo...'); spinner.start(); await agent.setGreeting(agentId, greeting); spinner.succeed('Saludo actualizado'); logger.label('Nuevo saludo', greeting); } catch (error) { const message = error instanceof Error ? error.message : 'Error desconocido'; logger.error(message); process.exit(1); } }); // Set instructions (wizard) setGroup.command('instructions') .description('Configurar instrucciones del agente') .argument('<agentId>', 'ID del agente') .option('--dev', 'Usar ambiente de desarrollo', false) .action(async (agentId: string, options: AgentCommandOptions) => { try { const credentials = await getStoredCredentials(); const agent = new Agent({ workspaceId: credentials.workspace, apiKey: credentials.apiKey, zone: credentials.zone, ...(options.dev && { customUrl: "http://localhost:5090" }) }); // Cargar instrucciones actuales const loadSpinner = createSpinner('Cargando...'); loadSpinner.start(); const agentData = await agent.getAgentById({ id: agentId }); loadSpinner.stop(); const current = agentData.instructions || {}; console.log(section('Instrucciones - ' + (agentData.name || agentId))); const answers = await (inquirer as any).prompt([ { type: 'list', name: 'tone', message: 'Tono:', choices: ['profesional', 'amigable', 'formal', 'casual', 'tecnico', 'empatico'], default: current.tone || 'profesional' }, { type: 'list', name: 'style', message: 'Estilo:', choices: ['conciso', 'detallado', 'conversacional', 'directo'], default: current.style || 'conciso' }, { type: 'input', name: 'personality', message: 'Personalidad:', default: current.personality || '' }, { type: 'input', name: 'objective', message: 'Objetivo:', default: current.objective || '' }, { type: 'list', name: 'language', message: 'Idioma:', choices: ['Espanol', 'English', 'Portugues'], default: current.language || 'Espanol' }, { type: 'confirm', name: 'useEmojis', message: 'Usar emojis?', default: current.useEmojis === 'si' }, ]); const instructions = { ...current, tone: answers.tone, style: answers.style, personality: answers.personality, objective: answers.objective, language: answers.language, useEmojis: answers.useEmojis ? 'si' : 'no', }; const spinner = createSpinner('Guardando instrucciones...'); spinner.start(); await agent.setInstructions(agentId, instructions); spinner.succeed('Instrucciones actualizadas'); } catch (error) { const message = error instanceof Error ? error.message : 'Error desconocido'; logger.error(message); process.exit(1); } }); // Set persona (wizard) setGroup.command('persona') .description('Configurar la persona del agente') .argument('<agentId>', 'ID del agente') .option('--dev', 'Usar ambiente de desarrollo', false) .action(async (agentId: string, options: AgentCommandOptions) => { try { const credentials = await getStoredCredentials(); const agent = new Agent({ workspaceId: credentials.workspace, apiKey: credentials.apiKey, zone: credentials.zone, ...(options.dev && { customUrl: "http://localhost:5090" }) }); const loadSpinner = createSpinner('Cargando...'); loadSpinner.start(); const agentData = await agent.getAgentById({ id: agentId }); loadSpinner.stop(); const current = agentData.person || {}; console.log(section('Persona - ' + (agentData.name || agentId))); const answers = await (inquirer as any).prompt([ { type: 'input', name: 'name', message: 'Nombre del personaje:', default: current.name || '' }, { type: 'input', name: 'role', message: 'Rol:', default: current.role || '' }, { type: 'confirm', name: 'firstPerson', message: 'Hablar en primera persona?', default: current.firstPerson !== false }, ]); const spinner = createSpinner('Guardando persona...'); spinner.start(); await agent.setPersona(agentId, answers); spinner.succeed('Persona actualizada'); } catch (error) { const message = error instanceof Error ? error.message : 'Error desconocido'; logger.error(message); process.exit(1); } }); export const setCommand = setGroup;