plazbot-cli
Version:
CLI para Plazbot SDK
175 lines (158 loc) • 6.97 kB
text/typescript
import { Command } from 'commander';
import { Agent } from 'plazbot';
import { getStoredCredentials } from '../../utils/credentials';
import { logger } from '../../utils/logger';
import { AgentCommandOptions } from '../../types/agent';
export const getCommand = new Command('get')
.description('Obtiene información detallada de un agente específico')
.argument('<agentId>', 'ID del agente a consultar')
.option('--dev', 'Usar ambiente de desarrollo', false)
.action(async (agentId: string, options: AgentCommandOptions) => {
try {
// Obtener credenciales guardadas
const credentials = await getStoredCredentials();
// Crear instancia del agente con las credenciales guardadas
const agent = new Agent({
workspaceId: credentials.workspace,
apiKey: credentials.apiKey,
zone: credentials.zone,
...(options.dev && { customUrl: "http://localhost:5090" })
});
// Obtener detalles del agente
const agentDetails = await agent.getAgentById({ id: agentId });
const agentData = agentDetails.agent;
logger.info('\nDetalles del Agente:');
logger.doubleDivider();
// Información básica
logger.info('Información Básica:');
logger.divider();
logger.info(`ID: ${agentData.id}`);
logger.info(`Nombre: ${agentData.name}`);
logger.info(`Descripción: ${agentData.description}`);
logger.info(`Estado: ${agentData.enable ? '✅ Activo' : '❌ Inactivo'}`);
logger.info(`Zona: ${agentData.zone}`);
logger.info(`Buffer: ${agentData.buffer}`);
logger.info(`Color: ${agentData.color}`);
logger.info(`Pregunta inicial: ${agentData.question}`);
logger.info(`Zona horaria: ${agentData.timezone}`);
logger.info(`Mostrar en chat: ${agentData.showInChat ? 'Sí' : 'No'}`);
// Tags
if (agentData.tags && agentData.tags.length > 0) {
logger.info(`\nTags: ${agentData.tags.join(', ')}`);
}
// Ejemplos
if (agentData.examples && agentData.examples.length > 0) {
logger.info('\nEjemplos:');
logger.divider();
agentData.examples.forEach((example: { value: string; color: string }) => {
logger.info(`- ${example.value} (${example.color})`);
});
}
// Instrucciones
if (agentData.instructions) {
logger.info('\nInstrucciones:');
logger.divider();
const instructions = agentData.instructions;
logger.info(`Tono: ${instructions.tone}`);
logger.info(`Estilo: ${instructions.style}`);
logger.info(`Personalidad: ${instructions.personality}`);
logger.info(`Objetivo: ${instructions.objective}`);
logger.info(`Idioma: ${instructions.language}`);
logger.info(`Emojis: ${instructions.emojis ? 'Sí' : 'No'}`);
logger.info(`Formato preferido: ${instructions.preferredFormat}`);
logger.info(`Máximo de palabras: ${instructions.maxWords}`);
if (instructions.avoidTopics) {
logger.info(`Temas a evitar: ${instructions.avoidTopics.join(', ')}`);
}
logger.info(`Responder solo si sabe: ${instructions.respondOnlyIfKnows ? 'Sí' : 'No'}`);
logger.info(`Mantener tono entre mensajes: ${instructions.maintainToneBetweenMessages ? 'Sí' : 'No'}`);
logger.info(`Saludo: ${instructions.greeting}`);
}
// Persona
if (agentData.person) {
logger.info('\nPersona:');
logger.divider();
const person = agentData.person;
logger.info(`Nombre: ${person.name}`);
logger.info(`Rol: ${person.role}`);
logger.info(`Habla en primera persona: ${person.speaksInFirstPerson ? 'Sí' : 'No'}`);
logger.info(`Es humano: ${person.isHuman ? 'Sí' : 'No'}`);
}
// Fallbacks
if (agentData.fallbacks) {
logger.info('\nFallbacks:');
logger.divider();
const fallbacks = agentData.fallbacks;
logger.info(`Sin respuesta: ${fallbacks.noAnswer}`);
logger.info(`Error de servicio: ${fallbacks.serviceError}`);
logger.info(`No entiende: ${fallbacks.doNotUnderstand}`);
}
// Reglas
if (agentData.rules) {
logger.info('\nReglas:');
logger.divider();
const rules = agentData.rules;
logger.info(`No mencionar precios: ${rules.doNotMentionPrices ? 'Sí' : 'No'}`);
logger.info(`No diagnosticar: ${rules.doNotDiagnose ? 'Sí' : 'No'}`);
if (rules.doNotRespondOutsideHours) {
logger.info(`Horario de atención: ${rules.doNotRespondOutsideHours}`);
}
}
// Servicios
if (agentData.services && agentData.services.length > 0) {
logger.info('\nServicios:');
logger.divider();
agentData.services.forEach((service: any, index: number) => {
logger.info(`\nServicio ${index + 1}:`);
logger.info(`Intent: ${service.intent}`);
logger.info(`Referencia: ${service.reference}`);
logger.info(`Habilitado: ${service.enabled ? 'Sí' : 'No'}`);
logger.info(`Método: ${service.method}`);
logger.info(`Endpoint: ${service.endpoint}`);
if (service.requiredFields) {
logger.info('Campos requeridos:');
service.requiredFields.forEach((field: any) => {
logger.info(` - ${field.name} (${field.type}): ${field.description}`);
});
}
});
}
// Acciones
if (agentData.actions && agentData.actions.length > 0) {
logger.info('\nAcciones:');
logger.divider();
agentData.actions.forEach((action: any, index: number) => {
logger.info(`\nAcción ${index + 1}:`);
logger.info(`Intent: ${action.intent}`);
logger.info(`Referencia: ${action.reference}`);
logger.info(`Habilitado: ${action.enabled ? 'Sí' : 'No'}`);
if (action.tags) {
logger.info(`Tags: ${action.tags.join(', ')}`);
}
logger.info(`Mensaje de respuesta: ${action.responseMessage}`);
if (action.action) {
logger.info('Sub-acciones:');
action.action.forEach((subAction: any) => {
logger.info(` - ${subAction.type}: ${subAction.value}`);
});
}
});
}
// Canales
if (agentData.channels && agentData.channels.length > 0) {
logger.info('\nCanales:');
logger.divider();
agentData.channels.forEach((channel: { channel: string; key: string }) => {
logger.info(`${channel.channel}: ${channel.key}`);
});
}
logger.doubleDivider();
if (options.dev) {
logger.warning('Ambiente: desarrollo');
}
} catch (error) {
const message = error instanceof Error ? error.message : 'Error desconocido al obtener el agente';
logger.error(message);
process.exit(1);
}
});