UNPKG

plazbot-cli

Version:
116 lines (115 loc) 5.02 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.createCommand = void 0; const commander_1 = require("commander"); const plazbot_1 = require("plazbot"); const credentials_1 = require("../../utils/credentials"); const logger_1 = require("../../utils/logger"); const ui_1 = require("../../utils/ui"); const wizard_1 = require("./wizard"); const promises_1 = __importDefault(require("fs/promises")); exports.createCommand = new commander_1.Command('create') .description('Crea un nuevo agente de IA (wizard interactivo o archivo JSON)') .argument('[configPath]', 'Ruta al archivo de configuracion JSON (opcional)') .option('--dev', 'Usar ambiente de desarrollo', false) .action(async (configPath, options) => { try { const credentials = await (0, credentials_1.getStoredCredentials)(); const agent = new plazbot_1.Agent({ workspaceId: credentials.workspace, apiKey: credentials.apiKey, zone: credentials.zone, ...(options.dev && { customUrl: "http://localhost:5090" }) }); let agentConfig; if (configPath) { // Modo archivo: leer JSON try { const fileContent = await promises_1.default.readFile(configPath, 'utf-8'); agentConfig = JSON.parse(fileContent); } catch (error) { const errorMessage = error instanceof Error ? error.message : 'Error desconocido'; throw new Error(`Error al leer el archivo de configuracion: ${errorMessage}`); } logger_1.logger.title('Creando agente desde archivo'); logger_1.logger.json(agentConfig); } else { // Modo wizard interactivo agentConfig = await (0, wizard_1.runAgentWizard)(credentials.zone); const inquirer = await Promise.resolve().then(() => __importStar(require('inquirer'))); const { confirm } = await inquirer.default.prompt([{ type: 'confirm', name: 'confirm', message: 'Crear el agente con esta configuracion?', default: true, }]); if (!confirm) { logger_1.logger.warning('Creacion cancelada'); return; } } const spinner = (0, ui_1.createSpinner)('Creando agente...'); spinner.start(); const result = await agent.addAgent(agentConfig); spinner.succeed('Agente creado exitosamente'); logger_1.logger.title('Detalles del agente'); if (result.agentId) { logger_1.logger.label('ID', result.agentId); } if (agentConfig.name) { logger_1.logger.label('Nombre', agentConfig.name); } logger_1.logger.label('Tool Calling', agentConfig.useToolCalling ? 'Activado' : 'Desactivado'); if (agentConfig.channels && agentConfig.channels.length > 0) { logger_1.logger.label('WhatsApp', agentConfig.channels[0].key); } console.log(); logger_1.logger.dim('Siguiente paso: plazbot agent chat -a ' + (result.agentId || '<agentId>')); if (options.dev) { logger_1.logger.warning('Ambiente: desarrollo'); } } catch (error) { const message = error instanceof Error ? error.message : 'Error desconocido al crear el agente'; logger_1.logger.error(message); process.exit(1); } });